2014-02-21 20:54:32 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
final class DifferentialReviewersField
|
|
|
|
extends DifferentialCoreCustomField {
|
|
|
|
|
|
|
|
public function getFieldKey() {
|
|
|
|
return 'differential:reviewers';
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getFieldName() {
|
|
|
|
return pht('Reviewers');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getFieldDescription() {
|
|
|
|
return pht('Manage reviewers.');
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function readValueFromRevision(
|
|
|
|
DifferentialRevision $revision) {
|
2017-03-20 23:04:23 +01:00
|
|
|
return $revision->getReviewers();
|
2014-02-21 20:54:32 +01:00
|
|
|
}
|
|
|
|
|
2014-02-26 23:46:18 +01:00
|
|
|
public function shouldAppearInPropertyView() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function renderPropertyViewLabel() {
|
|
|
|
return $this->getFieldName();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getRequiredHandlePHIDsForPropertyView() {
|
|
|
|
return mpull($this->getUserReviewers(), 'getReviewerPHID');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function renderPropertyViewValue(array $handles) {
|
|
|
|
$reviewers = $this->getUserReviewers();
|
|
|
|
if (!$reviewers) {
|
|
|
|
return phutil_tag('em', array(), pht('None'));
|
|
|
|
}
|
|
|
|
|
|
|
|
$view = id(new DifferentialReviewersView())
|
|
|
|
->setUser($this->getViewer())
|
|
|
|
->setReviewers($reviewers)
|
|
|
|
->setHandles($handles);
|
|
|
|
|
2017-03-20 20:35:30 +01:00
|
|
|
$diff = $this->getActiveDiff();
|
|
|
|
if ($diff) {
|
|
|
|
$view->setActiveDiff($diff);
|
|
|
|
}
|
2014-02-26 23:46:18 +01:00
|
|
|
|
|
|
|
return $view;
|
|
|
|
}
|
|
|
|
|
|
|
|
private function getUserReviewers() {
|
|
|
|
$reviewers = array();
|
2017-03-20 23:04:23 +01:00
|
|
|
foreach ($this->getObject()->getReviewers() as $reviewer) {
|
2014-02-26 23:46:18 +01:00
|
|
|
if ($reviewer->isUser()) {
|
|
|
|
$reviewers[] = $reviewer;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $reviewers;
|
|
|
|
}
|
2014-03-08 02:05:00 +01:00
|
|
|
|
2014-07-02 13:58:51 +02:00
|
|
|
public function getRequiredHandlePHIDsForRevisionHeaderWarnings() {
|
|
|
|
return mpull($this->getValue(), 'getReviewerPHID');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getWarningsForRevisionHeader(array $handles) {
|
|
|
|
$revision = $this->getObject();
|
|
|
|
|
2017-08-04 14:29:49 +02:00
|
|
|
if (!$revision->isNeedsReview()) {
|
2014-07-02 13:58:51 +02:00
|
|
|
return array();
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach ($this->getValue() as $reviewer) {
|
|
|
|
if (!$handles[$reviewer->getReviewerPHID()]->isDisabled()) {
|
|
|
|
return array();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$warnings = array();
|
|
|
|
if ($this->getValue()) {
|
|
|
|
$warnings[] = pht(
|
|
|
|
'This revision needs review, but all specified reviewers are '.
|
|
|
|
'disabled or inactive.');
|
|
|
|
} else {
|
|
|
|
$warnings[] = pht(
|
|
|
|
'This revision needs review, but there are no reviewers specified.');
|
|
|
|
}
|
|
|
|
|
|
|
|
return $warnings;
|
|
|
|
}
|
2014-03-12 14:04:30 +01:00
|
|
|
|
2014-02-21 20:54:32 +01:00
|
|
|
}
|