Generate file attachment transactions for explicit Remarkup attachments on common...
[phabricator.git] / src / applications / differential / view / DifferentialReviewersView.php
blobad6bf1462b7657cc6e3173fa1340f1751d0e8e21
1 <?php
3 final class DifferentialReviewersView extends AphrontView {
5 private $reviewers;
6 private $handles;
7 private $diff;
9 public function setReviewers(array $reviewers) {
10 assert_instances_of($reviewers, 'DifferentialReviewer');
11 $this->reviewers = $reviewers;
12 return $this;
15 public function setHandles(array $handles) {
16 assert_instances_of($handles, 'PhabricatorObjectHandle');
17 $this->handles = $handles;
18 return $this;
21 public function setActiveDiff(DifferentialDiff $diff) {
22 $this->diff = $diff;
23 return $this;
26 public function render() {
27 $viewer = $this->getUser();
28 $reviewers = $this->reviewers;
29 $diff = $this->diff;
30 $handles = $this->handles;
32 $view = new PHUIStatusListView();
34 // Move resigned reviewers to the bottom.
35 $head = array();
36 $tail = array();
37 foreach ($reviewers as $key => $reviewer) {
38 if ($reviewer->isResigned()) {
39 $tail[$key] = $reviewer;
40 } else {
41 $head[$key] = $reviewer;
45 PhabricatorPolicyFilterSet::loadHandleViewCapabilities(
46 $viewer,
47 $handles,
48 array($diff));
50 $reviewers = $head + $tail;
51 foreach ($reviewers as $reviewer) {
52 $phid = $reviewer->getReviewerPHID();
53 $handle = $handles[$phid];
55 $action_phid = $reviewer->getLastActionDiffPHID();
56 $is_current_action = $this->isCurrent($action_phid);
57 $is_voided = (bool)$reviewer->getVoidedPHID();
59 $comment_phid = $reviewer->getLastCommentDiffPHID();
60 $is_current_comment = $this->isCurrent($comment_phid);
62 $item = new PHUIStatusItemView();
64 $item->setHighlighted($reviewer->hasAuthority($viewer));
66 // If someone other than the reviewer acted on the reviewer's behalf,
67 // show who is responsible for the current state. This is usually a
68 // user accepting for a package or project.
69 $authority_phid = $reviewer->getLastActorPHID();
70 if ($authority_phid && ($authority_phid !== $phid)) {
71 $authority_name = $viewer->renderHandle($authority_phid)
72 ->setAsText(true);
73 } else {
74 $authority_name = null;
77 switch ($reviewer->getReviewerStatus()) {
78 case DifferentialReviewerStatus::STATUS_ADDED:
79 if ($comment_phid) {
80 if ($is_current_comment) {
81 $icon = 'fa-comment';
82 $color = 'blue';
83 $label = pht('Commented');
84 } else {
85 $icon = 'fa-comment-o';
86 $color = 'bluegrey';
87 $label = pht('Commented Previously');
89 } else {
90 $icon = PHUIStatusItemView::ICON_OPEN;
91 $color = 'bluegrey';
92 $label = pht('Review Requested');
94 break;
96 case DifferentialReviewerStatus::STATUS_ACCEPTED:
97 if ($is_current_action && !$is_voided) {
98 $icon = PHUIStatusItemView::ICON_ACCEPT;
99 $color = 'green';
100 if ($authority_name !== null) {
101 $label = pht('Accepted (by %s)', $authority_name);
102 } else {
103 $label = pht('Accepted');
105 } else {
106 $icon = 'fa-check-circle-o';
107 $color = 'bluegrey';
109 if (!$is_current_action && $is_voided) {
110 // The reviewer accepted the revision, but later the author
111 // used "Request Review" to request an updated review.
112 $label = pht('Accepted Earlier');
113 } else if ($authority_name !== null) {
114 $label = pht('Accepted Prior Diff (by %s)', $authority_name);
115 } else {
116 $label = pht('Accepted Prior Diff');
119 break;
121 case DifferentialReviewerStatus::STATUS_REJECTED:
122 if ($is_current_action) {
123 $icon = PHUIStatusItemView::ICON_REJECT;
124 $color = 'red';
125 if ($authority_name !== null) {
126 $label = pht('Requested Changes (by %s)', $authority_name);
127 } else {
128 $label = pht('Requested Changes');
130 } else {
131 $icon = 'fa-times-circle-o';
132 $color = 'red';
133 if ($authority_name !== null) {
134 $label = pht(
135 'Requested Changes to Prior Diff (by %s)',
136 $authority_name);
137 } else {
138 $label = pht('Requested Changes to Prior Diff');
141 break;
143 case DifferentialReviewerStatus::STATUS_BLOCKING:
144 $icon = PHUIStatusItemView::ICON_MINUS;
145 $color = 'red';
146 $label = pht('Blocking Review');
147 break;
149 case DifferentialReviewerStatus::STATUS_RESIGNED:
150 $icon = 'fa-times';
151 $color = 'grey';
152 $label = pht('Resigned');
153 break;
155 default:
156 $icon = PHUIStatusItemView::ICON_QUESTION;
157 $color = 'bluegrey';
158 $label = pht('Unknown ("%s")', $reviewer->getReviewerStatus());
159 break;
163 $item->setIcon($icon, $color, $label);
164 $item->setTarget(
165 $handle->renderHovercardLink(
166 null,
167 $diff->getPHID()));
169 if ($reviewer->isPackage()) {
170 if (!$reviewer->getChangesets()) {
171 $item->setNote(pht('(Owns No Changed Paths)'));
175 if ($handle->hasCapabilities()) {
176 if (!$handle->hasViewCapability($diff)) {
177 $item
178 ->setIcon('fa-eye-slash', 'red')
179 ->setNote(pht('No View Permission'))
180 ->setIsExiled(true);
184 $view->addItem($item);
187 return $view;
190 private function isCurrent($action_phid) {
191 if (!$this->diff) {
192 return true;
195 if (!$action_phid) {
196 return true;
199 $diff_phid = $this->diff->getPHID();
200 if (!$diff_phid) {
201 return true;
204 if ($diff_phid == $action_phid) {
205 return true;
208 return false;