[ Index ] |
PHP Cross Reference of Phabricator |
[Summary view] [Print] [Text view]
1 <?php 2 3 final class ReleephIntentFieldSpecification 4 extends ReleephFieldSpecification { 5 6 public function getFieldKey() { 7 return 'intent'; 8 } 9 10 public function getName() { 11 return 'Intent'; 12 } 13 14 public function getRequiredHandlePHIDsForPropertyView() { 15 $pull = $this->getReleephRequest(); 16 $intents = $pull->getUserIntents(); 17 return array_keys($intents); 18 } 19 20 public function renderPropertyViewValue(array $handles) { 21 $pull = $this->getReleephRequest(); 22 23 $intents = $pull->getUserIntents(); 24 $product = $this->getReleephProject(); 25 26 if (!$intents) { 27 return null; 28 } 29 30 $pushers = array(); 31 $others = array(); 32 33 foreach ($intents as $phid => $intent) { 34 if ($product->isAuthoritativePHID($phid)) { 35 $pushers[$phid] = $intent; 36 } else { 37 $others[$phid] = $intent; 38 } 39 } 40 41 $intents = $pushers + $others; 42 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; 61 } 62 63 $target = $handles[$phid]->renderLink(); 64 if ($product->isAuthoritativePHID($phid)) { 65 $target = phutil_tag('strong', array(), $target); 66 } 67 68 $view->addItem( 69 id(new PHUIStatusItemView()) 70 ->setIcon($icon, $color, $label) 71 ->setTarget($target)); 72 } 73 74 return $view; 75 } 76 77 public function shouldAppearOnCommitMessage() { 78 return true; 79 } 80 81 public function shouldAppearOnRevertMessage() { 82 return true; 83 } 84 85 public function renderLabelForCommitMessage() { 86 return 'Approved By'; 87 } 88 89 public function renderLabelForRevertMessage() { 90 return 'Rejected By'; 91 } 92 93 public function renderValueForCommitMessage() { 94 return $this->renderIntentsForCommitMessage(ReleephRequest::INTENT_WANT); 95 } 96 97 public function renderValueForRevertMessage() { 98 return $this->renderIntentsForCommitMessage(ReleephRequest::INTENT_PASS); 99 } 100 101 private function renderIntentsForCommitMessage($print_intent) { 102 $intents = $this->getReleephRequest()->getUserIntents(); 103 104 $requestor = $this->getReleephRequest()->getRequestUserPHID(); 105 $pusher_phids = $this->getReleephProject()->getPushers(); 106 107 $phids = array_unique($pusher_phids + array_keys($intents)); 108 $handles = id(new PhabricatorHandleQuery()) 109 ->setViewer($this->getUser()) 110 ->withPHIDs($phids) 111 ->execute(); 112 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; 120 121 if ($is_pusher) { 122 if ($is_requestor) { 123 $token = "{$name} (pusher and requestor)"; 124 } else { 125 $token = "{$name} (pusher)"; 126 } 127 } else { 128 if ($is_requestor) { 129 $token = "{$name} (requestor)"; 130 } else { 131 $token = $name; 132 } 133 } 134 135 $tokens[] = $token; 136 } 137 } 138 139 return implode(', ', $tokens); 140 } 141 142 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Sun Nov 30 09:20:46 2014 | Cross-referenced by PHPXref 0.7.1 |