3 final class PhabricatorBadgesEditor
4 extends PhabricatorApplicationTransactionEditor
{
6 public function getEditorApplicationClass() {
7 return 'PhabricatorBadgesApplication';
10 public function getEditorObjectsDescription() {
14 public function getCreateObjectTitle($author, $object) {
15 return pht('%s created this badge.', $author);
18 public function getCreateObjectTitleForFeed($author, $object) {
19 return pht('%s created %s.', $author, $object);
22 protected function supportsSearch() {
26 public function getTransactionTypes() {
27 $types = parent
::getTransactionTypes();
28 $types[] = PhabricatorTransactions
::TYPE_COMMENT
;
29 $types[] = PhabricatorTransactions
::TYPE_EDGE
;
30 $types[] = PhabricatorTransactions
::TYPE_EDIT_POLICY
;
35 protected function shouldSendMail(
36 PhabricatorLiskDAO
$object,
41 public function getMailTagsMap() {
43 PhabricatorBadgesTransaction
::MAILTAG_DETAILS
=>
44 pht('Someone changes the badge\'s details.'),
45 PhabricatorBadgesTransaction
::MAILTAG_COMMENT
=>
46 pht('Someone comments on a badge.'),
47 PhabricatorBadgesTransaction
::MAILTAG_OTHER
=>
48 pht('Other badge activity not listed above occurs.'),
52 protected function shouldPublishFeedStory(
53 PhabricatorLiskDAO
$object,
58 protected function expandTransactions(
59 PhabricatorLiskDAO
$object,
62 $actor = $this->getActor();
63 $actor_phid = $actor->getPHID();
65 $results = parent
::expandTransactions($object, $xactions);
67 // Automatically subscribe the author when they create a badge.
68 if ($this->getIsNewObject()) {
70 $results[] = id(new PhabricatorBadgesTransaction())
71 ->setTransactionType(PhabricatorTransactions
::TYPE_SUBSCRIBERS
)
74 '+' => array($actor_phid => $actor_phid),
82 protected function buildReplyHandler(PhabricatorLiskDAO
$object) {
83 return id(new PhabricatorBadgesReplyHandler())
84 ->setMailReceiver($object);
87 protected function buildMailTemplate(PhabricatorLiskDAO
$object) {
88 $name = $object->getName();
89 $id = $object->getID();
90 $subject = pht('Badge %d: %s', $id, $name);
92 return id(new PhabricatorMetaMTAMail())
93 ->setSubject($subject);
96 protected function getMailTo(PhabricatorLiskDAO
$object) {
98 $object->getCreatorPHID(),
99 $this->requireActor()->getPHID(),
103 protected function buildMailBody(
104 PhabricatorLiskDAO
$object,
107 $body = parent
::buildMailBody($object, $xactions);
109 $body->addLinkSection(
111 PhabricatorEnv
::getProductionURI('/badges/view/'.$object->getID().'/'));
115 protected function getMailSubjectPrefix() {
116 return pht('[Badge]');
119 protected function applyFinalEffects(
120 PhabricatorLiskDAO
$object,
123 $badge_phid = $object->getPHID();
124 $user_phids = array();
125 $clear_everything = false;
127 foreach ($xactions as $xaction) {
128 switch ($xaction->getTransactionType()) {
129 case PhabricatorBadgesBadgeAwardTransaction
::TRANSACTIONTYPE
:
130 case PhabricatorBadgesBadgeRevokeTransaction
::TRANSACTIONTYPE
:
131 foreach ($xaction->getNewValue() as $user_phid) {
132 $user_phids[] = $user_phid;
136 $clear_everything = true;
141 if ($clear_everything) {
142 $awards = id(new PhabricatorBadgesAwardQuery())
143 ->setViewer($this->getActor())
144 ->withBadgePHIDs(array($badge_phid))
146 foreach ($awards as $award) {
147 $user_phids[] = $award->getRecipientPHID();
152 PhabricatorUserCache
::clearCaches(
153 PhabricatorUserBadgesCacheType
::KEY_BADGES
,