Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/badges/xaction/PhabricatorBadgesBadgeRevokeTransaction.php
12256 views
1
<?php
2
3
final class PhabricatorBadgesBadgeRevokeTransaction
4
extends PhabricatorBadgesBadgeTransactionType {
5
6
const TRANSACTIONTYPE = 'badge.revoke';
7
8
public function generateOldValue($object) {
9
return null;
10
}
11
12
public function applyExternalEffects($object, $value) {
13
$awards = id(new PhabricatorBadgesAwardQuery())
14
->setViewer($this->getActor())
15
->withRecipientPHIDs($value)
16
->withBadgePHIDs(array($object->getPHID()))
17
->execute();
18
$awards = mpull($awards, null, 'getRecipientPHID');
19
20
foreach ($value as $phid) {
21
$awards[$phid]->delete();
22
}
23
return;
24
}
25
26
public function getTitle() {
27
$new = $this->getNewValue();
28
if (!is_array($new)) {
29
$new = array();
30
}
31
$handles = $this->renderHandleList($new);
32
return pht(
33
'%s revoked this badge from %s recipient(s): %s.',
34
$this->renderAuthor(),
35
new PhutilNumber(count($new)),
36
$handles);
37
}
38
39
public function getTitleForFeed() {
40
$new = $this->getNewValue();
41
if (!is_array($new)) {
42
$new = array();
43
}
44
$handles = $this->renderHandleList($new);
45
return pht(
46
'%s revoked %s from %s recipient(s): %s.',
47
$this->renderAuthor(),
48
$this->renderObject(),
49
new PhutilNumber(count($new)),
50
$handles);
51
}
52
53
public function getIcon() {
54
return 'fa-user-times';
55
}
56
57
public function validateTransactions($object, array $xactions) {
58
$errors = array();
59
60
foreach ($xactions as $xaction) {
61
$award_phids = $xaction->getNewValue();
62
if (!$award_phids) {
63
$errors[] = $this->newRequiredError(
64
pht('Recipient is required.'));
65
continue;
66
}
67
68
foreach ($award_phids as $award_phid) {
69
$award = id(new PhabricatorBadgesAwardQuery())
70
->setViewer($this->getActor())
71
->withRecipientPHIDs(array($award_phid))
72
->withBadgePHIDs(array($object->getPHID()))
73
->executeOne();
74
if (!$award) {
75
$errors[] = $this->newInvalidError(
76
pht(
77
'Recipient PHID "%s" has not been awarded.',
78
$award_phid));
79
}
80
}
81
}
82
83
return $errors;
84
}
85
86
}
87
88