Remove product literal strings in "pht()", part 25
[phabricator.git] / src / applications / releeph / field / specification / ReleephIntentFieldSpecification.php
blob833dce0b3986dc88f45daad85df7e0f910ee6bee
1 <?php
3 final class ReleephIntentFieldSpecification
4 extends ReleephFieldSpecification {
6 public function getFieldKey() {
7 return 'intent';
10 public function getName() {
11 return pht('Intent');
14 public function getRequiredHandlePHIDsForPropertyView() {
15 $pull = $this->getReleephRequest();
16 $intents = $pull->getUserIntents();
17 return array_keys($intents);
20 public function renderPropertyViewValue(array $handles) {
21 $pull = $this->getReleephRequest();
23 $intents = $pull->getUserIntents();
24 $product = $this->getReleephProject();
26 if (!$intents) {
27 return null;
30 $pushers = array();
31 $others = array();
33 foreach ($intents as $phid => $intent) {
34 if ($product->isAuthoritativePHID($phid)) {
35 $pushers[$phid] = $intent;
36 } else {
37 $others[$phid] = $intent;
41 $intents = $pushers + $others;
43 $view = id(new PHUIStatusListView());
44 foreach ($intents as $phid => $intent) {
45 switch ($intent) {
46 case ReleephRequest::INTENT_WANT:
47 $icon = PHUIStatusItemView::ICON_ACCEPT;
48 $color = 'green';
49 $label = pht('Want');
50 break;
51 case ReleephRequest::INTENT_PASS:
52 $icon = PHUIStatusItemView::ICON_REJECT;
53 $color = 'red';
54 $label = pht('Pass');
55 break;
56 default:
57 $icon = PHUIStatusItemView::ICON_QUESTION;
58 $color = 'bluegrey';
59 $label = pht('Unknown Intent (%s)', $intent);
60 break;
63 $target = $handles[$phid]->renderLink();
64 if ($product->isAuthoritativePHID($phid)) {
65 $target = phutil_tag('strong', array(), $target);
68 $view->addItem(
69 id(new PHUIStatusItemView())
70 ->setIcon($icon, $color, $label)
71 ->setTarget($target));
74 return $view;
77 public function shouldAppearOnCommitMessage() {
78 return true;
81 public function shouldAppearOnRevertMessage() {
82 return true;
85 public function renderLabelForCommitMessage() {
86 return pht('Approved By');
89 public function renderLabelForRevertMessage() {
90 return pht('Rejected By');
93 public function renderValueForCommitMessage() {
94 return $this->renderIntentsForCommitMessage(ReleephRequest::INTENT_WANT);
97 public function renderValueForRevertMessage() {
98 return $this->renderIntentsForCommitMessage(ReleephRequest::INTENT_PASS);
101 private function renderIntentsForCommitMessage($print_intent) {
102 $intents = $this->getReleephRequest()->getUserIntents();
104 $requestor = $this->getReleephRequest()->getRequestUserPHID();
105 $pusher_phids = $this->getReleephProject()->getPushers();
107 $phids = array_unique($pusher_phids + array_keys($intents));
108 $handles = id(new PhabricatorHandleQuery())
109 ->setViewer($this->getUser())
110 ->withPHIDs($phids)
111 ->execute();
113 $tokens = array();
114 foreach ($phids as $phid) {
115 $intent = idx($intents, $phid);
116 if ($intent == $print_intent) {
117 $name = $handles[$phid]->getName();
118 $is_pusher = in_array($phid, $pusher_phids);
119 $is_requestor = $phid == $requestor;
121 if ($is_pusher) {
122 if ($is_requestor) {
123 $token = pht('%s (pusher and requestor)', $name);
124 } else {
125 $token = "{$name} (pusher)";
127 } else {
128 if ($is_requestor) {
129 $token = pht('%s (requestor)', $name);
130 } else {
131 $token = $name;
135 $tokens[] = $token;
139 return implode(', ', $tokens);