Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 58 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
| Signed | |
0.00% |
0 / 58 |
|
0.00% |
0 / 2 |
30 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| parse | |
0.00% |
0 / 57 |
|
0.00% |
0 / 1 |
20 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | /** |
| 5 | * SPDX-FileCopyrightText: 2025 LibreCode coop and contributors |
| 6 | * SPDX-License-Identifier: AGPL-3.0-or-later |
| 7 | */ |
| 8 | |
| 9 | namespace OCA\Libresign\Activity\Provider; |
| 10 | |
| 11 | use OCA\Libresign\AppInfo\Application; |
| 12 | use OCP\Activity\Exceptions\UnknownActivityException; |
| 13 | use OCP\Activity\IEvent; |
| 14 | use OCP\Activity\IManager; |
| 15 | use OCP\Activity\IProvider; |
| 16 | use OCP\IURLGenerator; |
| 17 | use OCP\IUserManager; |
| 18 | use OCP\L10N\IFactory; |
| 19 | use OCP\RichObjectStrings\Definitions; |
| 20 | |
| 21 | class Signed implements IProvider { |
| 22 | public function __construct( |
| 23 | protected IFactory $languageFactory, |
| 24 | protected IURLGenerator $url, |
| 25 | protected Definitions $definitions, |
| 26 | protected IManager $activityManager, |
| 27 | protected IUserManager $userManager, |
| 28 | ) { |
| 29 | } |
| 30 | |
| 31 | #[\Override] |
| 32 | public function parse($language, IEvent $event, ?IEvent $previousEvent = null): IEvent { |
| 33 | if ($event->getApp() !== Application::APP_ID) { |
| 34 | throw new UnknownActivityException('app'); |
| 35 | } |
| 36 | |
| 37 | if ($event->getSubject() !== 'file_signed') { |
| 38 | throw new UnknownActivityException('subject'); |
| 39 | } |
| 40 | |
| 41 | $this->definitions->definitions['sign-request'] = [ |
| 42 | 'author' => 'LibreSign', |
| 43 | 'since' => '30.0.0', |
| 44 | 'parameters' => [ |
| 45 | 'id' => [ |
| 46 | 'since' => '30.0.0', |
| 47 | 'required' => true, |
| 48 | 'description' => 'The id of SignRequest object', |
| 49 | 'example' => '12345', |
| 50 | ], |
| 51 | 'name' => [ |
| 52 | 'since' => '30.0.0', |
| 53 | 'required' => true, |
| 54 | 'description' => 'The display name of signer', |
| 55 | 'example' => 'John Doe', |
| 56 | ], |
| 57 | ], |
| 58 | ]; |
| 59 | $this->definitions->definitions['signer'] = [ |
| 60 | 'author' => 'LibreSign', |
| 61 | 'since' => '30.0.0', |
| 62 | 'parameters' => [ |
| 63 | 'id' => [ |
| 64 | 'since' => '30.0.0', |
| 65 | 'required' => true, |
| 66 | 'description' => 'The identify method id', |
| 67 | 'example' => '12345', |
| 68 | ], |
| 69 | 'name' => [ |
| 70 | 'since' => '30.0.0', |
| 71 | 'required' => true, |
| 72 | 'description' => 'The display name of signer', |
| 73 | 'example' => 'John Doe', |
| 74 | ], |
| 75 | ], |
| 76 | ]; |
| 77 | |
| 78 | if ($this->activityManager->getRequirePNG()) { |
| 79 | $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath(Application::APP_ID, 'app-dark.png'))); |
| 80 | } else { |
| 81 | $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath(Application::APP_ID, 'app-dark.svg'))); |
| 82 | } |
| 83 | |
| 84 | $l = $this->languageFactory->get(Application::APP_ID, $language); |
| 85 | $parameters = $event->getSubjectParameters(); |
| 86 | |
| 87 | // TRANSLATORS Activity message shown after a signer completes the document. {from} is the signer name and {file} is the document filename. |
| 88 | $subject = $l->t('{from} signed {file}'); |
| 89 | $event->setParsedSubject( |
| 90 | str_replace( |
| 91 | ['{from}', '{file}'], |
| 92 | [ |
| 93 | $parameters['from']['name'], |
| 94 | $parameters['file']['name'], |
| 95 | ], |
| 96 | $subject |
| 97 | )) |
| 98 | ->setRichSubject($subject, $parameters); |
| 99 | |
| 100 | return $event; |
| 101 | } |
| 102 | } |