Path: blob/master/src/applications/differential/view/DifferentialReviewersView.php
12256 views
<?php12final class DifferentialReviewersView extends AphrontView {34private $reviewers;5private $handles;6private $diff;78public function setReviewers(array $reviewers) {9assert_instances_of($reviewers, 'DifferentialReviewer');10$this->reviewers = $reviewers;11return $this;12}1314public function setHandles(array $handles) {15assert_instances_of($handles, 'PhabricatorObjectHandle');16$this->handles = $handles;17return $this;18}1920public function setActiveDiff(DifferentialDiff $diff) {21$this->diff = $diff;22return $this;23}2425public function render() {26$viewer = $this->getUser();27$reviewers = $this->reviewers;28$diff = $this->diff;29$handles = $this->handles;3031$view = new PHUIStatusListView();3233// Move resigned reviewers to the bottom.34$head = array();35$tail = array();36foreach ($reviewers as $key => $reviewer) {37if ($reviewer->isResigned()) {38$tail[$key] = $reviewer;39} else {40$head[$key] = $reviewer;41}42}4344PhabricatorPolicyFilterSet::loadHandleViewCapabilities(45$viewer,46$handles,47array($diff));4849$reviewers = $head + $tail;50foreach ($reviewers as $reviewer) {51$phid = $reviewer->getReviewerPHID();52$handle = $handles[$phid];5354$action_phid = $reviewer->getLastActionDiffPHID();55$is_current_action = $this->isCurrent($action_phid);56$is_voided = (bool)$reviewer->getVoidedPHID();5758$comment_phid = $reviewer->getLastCommentDiffPHID();59$is_current_comment = $this->isCurrent($comment_phid);6061$item = new PHUIStatusItemView();6263$item->setHighlighted($reviewer->hasAuthority($viewer));6465// If someone other than the reviewer acted on the reviewer's behalf,66// show who is responsible for the current state. This is usually a67// user accepting for a package or project.68$authority_phid = $reviewer->getLastActorPHID();69if ($authority_phid && ($authority_phid !== $phid)) {70$authority_name = $viewer->renderHandle($authority_phid)71->setAsText(true);72} else {73$authority_name = null;74}7576switch ($reviewer->getReviewerStatus()) {77case DifferentialReviewerStatus::STATUS_ADDED:78if ($comment_phid) {79if ($is_current_comment) {80$icon = 'fa-comment';81$color = 'blue';82$label = pht('Commented');83} else {84$icon = 'fa-comment-o';85$color = 'bluegrey';86$label = pht('Commented Previously');87}88} else {89$icon = PHUIStatusItemView::ICON_OPEN;90$color = 'bluegrey';91$label = pht('Review Requested');92}93break;9495case DifferentialReviewerStatus::STATUS_ACCEPTED:96if ($is_current_action && !$is_voided) {97$icon = PHUIStatusItemView::ICON_ACCEPT;98$color = 'green';99if ($authority_name !== null) {100$label = pht('Accepted (by %s)', $authority_name);101} else {102$label = pht('Accepted');103}104} else {105$icon = 'fa-check-circle-o';106$color = 'bluegrey';107108if (!$is_current_action && $is_voided) {109// The reviewer accepted the revision, but later the author110// used "Request Review" to request an updated review.111$label = pht('Accepted Earlier');112} else if ($authority_name !== null) {113$label = pht('Accepted Prior Diff (by %s)', $authority_name);114} else {115$label = pht('Accepted Prior Diff');116}117}118break;119120case DifferentialReviewerStatus::STATUS_REJECTED:121if ($is_current_action) {122$icon = PHUIStatusItemView::ICON_REJECT;123$color = 'red';124if ($authority_name !== null) {125$label = pht('Requested Changes (by %s)', $authority_name);126} else {127$label = pht('Requested Changes');128}129} else {130$icon = 'fa-times-circle-o';131$color = 'red';132if ($authority_name !== null) {133$label = pht(134'Requested Changes to Prior Diff (by %s)',135$authority_name);136} else {137$label = pht('Requested Changes to Prior Diff');138}139}140break;141142case DifferentialReviewerStatus::STATUS_BLOCKING:143$icon = PHUIStatusItemView::ICON_MINUS;144$color = 'red';145$label = pht('Blocking Review');146break;147148case DifferentialReviewerStatus::STATUS_RESIGNED:149$icon = 'fa-times';150$color = 'grey';151$label = pht('Resigned');152break;153154default:155$icon = PHUIStatusItemView::ICON_QUESTION;156$color = 'bluegrey';157$label = pht('Unknown ("%s")', $reviewer->getReviewerStatus());158break;159160}161162$item->setIcon($icon, $color, $label);163$item->setTarget(164$handle->renderHovercardLink(165null,166$diff->getPHID()));167168if ($reviewer->isPackage()) {169if (!$reviewer->getChangesets()) {170$item->setNote(pht('(Owns No Changed Paths)'));171}172}173174if ($handle->hasCapabilities()) {175if (!$handle->hasViewCapability($diff)) {176$item177->setIcon('fa-eye-slash', 'red')178->setNote(pht('No View Permission'))179->setIsExiled(true);180}181}182183$view->addItem($item);184}185186return $view;187}188189private function isCurrent($action_phid) {190if (!$this->diff) {191return true;192}193194if (!$action_phid) {195return true;196}197198$diff_phid = $this->diff->getPHID();199if (!$diff_phid) {200return true;201}202203if ($diff_phid == $action_phid) {204return true;205}206207return false;208}209210}211212213