Remove product literal strings in "pht()", part 6
[phabricator.git] / src / applications / badges / editor / PhabricatorBadgesEditor.php
blob785d8c989beb17190073eaaf432415b5868bb46f
1 <?php
3 final class PhabricatorBadgesEditor
4 extends PhabricatorApplicationTransactionEditor {
6 public function getEditorApplicationClass() {
7 return 'PhabricatorBadgesApplication';
10 public function getEditorObjectsDescription() {
11 return pht('Badges');
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() {
23 return true;
26 public function getTransactionTypes() {
27 $types = parent::getTransactionTypes();
28 $types[] = PhabricatorTransactions::TYPE_COMMENT;
29 $types[] = PhabricatorTransactions::TYPE_EDGE;
30 $types[] = PhabricatorTransactions::TYPE_EDIT_POLICY;
32 return $types;
35 protected function shouldSendMail(
36 PhabricatorLiskDAO $object,
37 array $xactions) {
38 return true;
41 public function getMailTagsMap() {
42 return array(
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,
54 array $xactions) {
55 return true;
58 protected function expandTransactions(
59 PhabricatorLiskDAO $object,
60 array $xactions) {
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()) {
69 if ($actor_phid) {
70 $results[] = id(new PhabricatorBadgesTransaction())
71 ->setTransactionType(PhabricatorTransactions::TYPE_SUBSCRIBERS)
72 ->setNewValue(
73 array(
74 '+' => array($actor_phid => $actor_phid),
75 ));
79 return $results;
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) {
97 return array(
98 $object->getCreatorPHID(),
99 $this->requireActor()->getPHID(),
103 protected function buildMailBody(
104 PhabricatorLiskDAO $object,
105 array $xactions) {
107 $body = parent::buildMailBody($object, $xactions);
109 $body->addLinkSection(
110 pht('BADGE DETAIL'),
111 PhabricatorEnv::getProductionURI('/badges/view/'.$object->getID().'/'));
112 return $body;
115 protected function getMailSubjectPrefix() {
116 return pht('[Badge]');
119 protected function applyFinalEffects(
120 PhabricatorLiskDAO $object,
121 array $xactions) {
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;
134 break;
135 default:
136 $clear_everything = true;
137 break;
141 if ($clear_everything) {
142 $awards = id(new PhabricatorBadgesAwardQuery())
143 ->setViewer($this->getActor())
144 ->withBadgePHIDs(array($badge_phid))
145 ->execute();
146 foreach ($awards as $award) {
147 $user_phids[] = $award->getRecipientPHID();
151 if ($user_phids) {
152 PhabricatorUserCache::clearCaches(
153 PhabricatorUserBadgesCacheType::KEY_BADGES,
154 $user_phids);
157 return $xactions;