Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 44 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
| SignRequest | |
0.00% |
0 / 44 |
|
0.00% |
0 / 3 |
72 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| parse | |
0.00% |
0 / 39 |
|
0.00% |
0 / 1 |
20 | |||
| getParsedSubject | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
12 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | /** |
| 5 | * SPDX-FileCopyrightText: 2020-2024 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 SignRequest 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 (!in_array($event->getSubject(), ['new_sign_request', 'update_sign_request'])) { |
| 38 | throw new UnknownActivityException('subject'); |
| 39 | } |
| 40 | |
| 41 | $this->definitions->definitions['sign-request'] = [ |
| 42 | 'author' => 'LibreSign', |
| 43 | 'since' => '28.0.0', |
| 44 | 'parameters' => [ |
| 45 | 'id' => [ |
| 46 | 'since' => '28.0.0', |
| 47 | 'required' => true, |
| 48 | 'description' => 'The id of SignRequest object', |
| 49 | 'example' => '12345', |
| 50 | ], |
| 51 | 'name' => [ |
| 52 | 'since' => '28.0.0', |
| 53 | 'required' => true, |
| 54 | 'description' => 'The display name of signer', |
| 55 | 'example' => 'John Doe', |
| 56 | ], |
| 57 | ], |
| 58 | ]; |
| 59 | |
| 60 | if ($this->activityManager->getRequirePNG()) { |
| 61 | $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath(Application::APP_ID, 'app-dark.png'))); |
| 62 | } else { |
| 63 | $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath(Application::APP_ID, 'app-dark.svg'))); |
| 64 | } |
| 65 | |
| 66 | $l = $this->languageFactory->get(Application::APP_ID, $language); |
| 67 | $parameters = $event->getSubjectParameters(); |
| 68 | |
| 69 | $subject = $this->getParsedSubject($l, $event->getSubject()); |
| 70 | $event->setParsedSubject( |
| 71 | str_replace( |
| 72 | ['{from}', '{file}'], |
| 73 | [ |
| 74 | $parameters['from']['name'], |
| 75 | $parameters['file']['name'], |
| 76 | ], |
| 77 | $subject |
| 78 | )) |
| 79 | ->setRichSubject($subject, $parameters); |
| 80 | |
| 81 | return $event; |
| 82 | } |
| 83 | |
| 84 | private function getParsedSubject(\OCP\IL10N $l, string $subject) { |
| 85 | if ($subject === 'new_sign_request') { |
| 86 | // TRANSLATORS Activity message shown to a signer. {from} is the requester name and {file} is the document filename. |
| 87 | return $l->t('{from} requested your signature on {file}'); |
| 88 | } elseif ($subject === 'update_sign_request') { |
| 89 | // TRANSLATORS Activity message shown when an existing signature request was updated. {from} is the requester name and {file} is the document filename. |
| 90 | return $l->t('{from} updated the signature request for {file}'); |
| 91 | } |
| 92 | } |
| 93 | } |