Remove product literal strings in "pht()", part 18
[phabricator.git] / src / applications / badges / xaction / PhabricatorBadgesBadgeRevokeTransaction.php
blobb028038f3f07c322eca8a8fc1fc6e682cae1fd19
1 <?php
3 final class PhabricatorBadgesBadgeRevokeTransaction
4 extends PhabricatorBadgesBadgeTransactionType {
6 const TRANSACTIONTYPE = 'badge.revoke';
8 public function generateOldValue($object) {
9 return null;
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');
20 foreach ($value as $phid) {
21 $awards[$phid]->delete();
23 return;
26 public function getTitle() {
27 $new = $this->getNewValue();
28 if (!is_array($new)) {
29 $new = array();
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);
39 public function getTitleForFeed() {
40 $new = $this->getNewValue();
41 if (!is_array($new)) {
42 $new = array();
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);
53 public function getIcon() {
54 return 'fa-user-times';
57 public function validateTransactions($object, array $xactions) {
58 $errors = array();
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;
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));
83 return $errors;