Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/legalpad/xaction/LegalpadDocumentRequireSignatureTransaction.php
13464 views
1
<?php
2
3
final class LegalpadDocumentRequireSignatureTransaction
4
extends LegalpadDocumentTransactionType {
5
6
const TRANSACTIONTYPE = 'legalpad:require-signature';
7
8
public function generateOldValue($object) {
9
return (int)$object->getRequireSignature();
10
}
11
12
public function applyInternalEffects($object, $value) {
13
$object->setRequireSignature((int)$value);
14
}
15
16
public function applyExternalEffects($object, $value) {
17
if ($value) {
18
$session = new PhabricatorAuthSession();
19
queryfx(
20
$session->establishConnection('w'),
21
'UPDATE %T SET signedLegalpadDocuments = 0',
22
$session->getTableName());
23
}
24
}
25
26
public function getTitle() {
27
$new = $this->getNewValue();
28
29
if ($new) {
30
return pht(
31
'%s set the document to require signatures.',
32
$this->renderAuthor());
33
} else {
34
return pht(
35
'%s set the document to not require signatures.',
36
$this->renderAuthor());
37
}
38
}
39
40
public function getTitleForFeed() {
41
$new = $this->getNewValue();
42
if ($new) {
43
return pht(
44
'%s set the document %s to require signatures.',
45
$this->renderAuthor(),
46
$this->renderObject());
47
} else {
48
return pht(
49
'%s set the document %s to not require signatures.',
50
$this->renderAuthor(),
51
$this->renderObject());
52
}
53
}
54
55
public function validateTransactions($object, array $xactions) {
56
$errors = array();
57
58
$old = (bool)$object->getRequireSignature();
59
foreach ($xactions as $xaction) {
60
$new = (bool)$xaction->getNewValue();
61
62
if ($old === $new) {
63
continue;
64
}
65
66
$is_admin = $this->getActor()->getIsAdmin();
67
if (!$is_admin) {
68
$errors[] = $this->newInvalidError(
69
pht(
70
'Only administrators may change whether a document '.
71
'requires a signature.'),
72
$xaction);
73
}
74
}
75
76
return $errors;
77
}
78
79
public function getIcon() {
80
return 'fa-pencil-square';
81
}
82
83
}
84
85