Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
13 / 13
100.00% covered (success)
100.00%
3 / 3
CRAP
100.00% covered (success)
100.00%
1 / 1
DocMdpLevel
100.00% covered (success)
100.00%
13 / 13
100.00% covered (success)
100.00%
3 / 3
3
100.00% covered (success)
100.00%
1 / 1
 isCertifying
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getLabel
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
1 / 1
1
 getDescription
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3declare(strict_types=1);
4
5/**
6 * SPDX-FileCopyrightText: 2025 LibreCode coop and contributors
7 * SPDX-License-Identifier: AGPL-3.0-or-later
8 */
9
10namespace OCA\Libresign\Enum;
11
12use OCP\IL10N;
13
14enum DocMdpLevel: int {
15    case NOT_CERTIFIED = 0;
16    case CERTIFIED_NO_CHANGES_ALLOWED = 1;
17    case CERTIFIED_FORM_FILLING = 2;
18    case CERTIFIED_FORM_FILLING_AND_ANNOTATIONS = 3;
19
20    public function isCertifying(): bool {
21        return $this !== self::NOT_CERTIFIED;
22    }
23
24    public function getLabel(IL10N $l10n): string {
25        return match($this) {
26            // TRANSLATORS Short label for DocMDP level meaning the PDF is not certified. DocMDP is a PDF permission mechanism used with digital signatures.
27            self::NOT_CERTIFIED => $l10n->t('No certification'),
28            // TRANSLATORS Short label for strict DocMDP level where no edits are allowed after certification.
29            self::CERTIFIED_NO_CHANGES_ALLOWED => $l10n->t('No changes allowed'),
30            // TRANSLATORS Short label for DocMDP level that allows filling form fields after certification.
31            self::CERTIFIED_FORM_FILLING => $l10n->t('Form filling allowed'),
32            // TRANSLATORS Short label for DocMDP level that allows form filling and comments after certification.
33            self::CERTIFIED_FORM_FILLING_AND_ANNOTATIONS => $l10n->t('Form filling and commenting allowed'),
34        };
35    }
36
37    public function getDescription(IL10N $l10n): string {
38        return match($this) {
39            // TRANSLATORS Description of DocMDP behavior when the PDF is unsigned/un-certified. It warns that later edits will mark signatures as modified.
40            self::NOT_CERTIFIED => $l10n->t('The document is not certified; edits and new signatures are allowed, but any change will mark previous signatures as modified.'),
41            // TRANSLATORS Description of strict DocMDP behavior: any post-signature edit invalidates certification.
42            self::CERTIFIED_NO_CHANGES_ALLOWED => $l10n->t('After the first signature, no further edits or signatures are allowed; any change invalidates the certification.'),
43            // TRANSLATORS Description of DocMDP behavior allowing only form filling and extra signatures after the first signature.
44            self::CERTIFIED_FORM_FILLING => $l10n->t('After the first signature, only form filling and additional signatures are allowed; other changes invalidate the certification.'),
45            // TRANSLATORS Description of DocMDP behavior allowing form filling, comments, and extra signatures after certification.
46            self::CERTIFIED_FORM_FILLING_AND_ANNOTATIONS => $l10n->t('After the first signature, form filling, comments, and additional signatures are allowed; other changes invalidate the certification.'),
47        };
48    }
49}