Path: blob/master/src/applications/badges/xaction/PhabricatorBadgesBadgeRevokeTransaction.php
12256 views
<?php12final class PhabricatorBadgesBadgeRevokeTransaction3extends PhabricatorBadgesBadgeTransactionType {45const TRANSACTIONTYPE = 'badge.revoke';67public function generateOldValue($object) {8return null;9}1011public function applyExternalEffects($object, $value) {12$awards = id(new PhabricatorBadgesAwardQuery())13->setViewer($this->getActor())14->withRecipientPHIDs($value)15->withBadgePHIDs(array($object->getPHID()))16->execute();17$awards = mpull($awards, null, 'getRecipientPHID');1819foreach ($value as $phid) {20$awards[$phid]->delete();21}22return;23}2425public function getTitle() {26$new = $this->getNewValue();27if (!is_array($new)) {28$new = array();29}30$handles = $this->renderHandleList($new);31return pht(32'%s revoked this badge from %s recipient(s): %s.',33$this->renderAuthor(),34new PhutilNumber(count($new)),35$handles);36}3738public function getTitleForFeed() {39$new = $this->getNewValue();40if (!is_array($new)) {41$new = array();42}43$handles = $this->renderHandleList($new);44return pht(45'%s revoked %s from %s recipient(s): %s.',46$this->renderAuthor(),47$this->renderObject(),48new PhutilNumber(count($new)),49$handles);50}5152public function getIcon() {53return 'fa-user-times';54}5556public function validateTransactions($object, array $xactions) {57$errors = array();5859foreach ($xactions as $xaction) {60$award_phids = $xaction->getNewValue();61if (!$award_phids) {62$errors[] = $this->newRequiredError(63pht('Recipient is required.'));64continue;65}6667foreach ($award_phids as $award_phid) {68$award = id(new PhabricatorBadgesAwardQuery())69->setViewer($this->getActor())70->withRecipientPHIDs(array($award_phid))71->withBadgePHIDs(array($object->getPHID()))72->executeOne();73if (!$award) {74$errors[] = $this->newInvalidError(75pht(76'Recipient PHID "%s" has not been awarded.',77$award_phid));78}79}80}8182return $errors;83}8485}868788