Differential D17066 Diff 41082 src/applications/differential/field/DifferentialReviewersCommitMessageField.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/differential/field/DifferentialReviewersCommitMessageField.php
| <?php | <?php | ||||
| final class DifferentialReviewersCommitMessageField | final class DifferentialReviewersCommitMessageField | ||||
| extends DifferentialCommitMessageField { | extends DifferentialCommitMessageField { | ||||
| const FIELDKEY = 'reviewerPHIDs'; | const FIELDKEY = 'reviewerPHIDs'; | ||||
| public function getFieldName() { | public function getFieldName() { | ||||
| return pht('Reviewers'); | return pht('Reviewers'); | ||||
| } | } | ||||
| public function getFieldOrder() { | |||||
| return 4000; | |||||
| } | |||||
| public function getFieldAliases() { | public function getFieldAliases() { | ||||
| return array( | return array( | ||||
| 'Reviewer', | 'Reviewer', | ||||
| ); | ); | ||||
| } | } | ||||
| public function parseFieldValue($value) { | public function parseFieldValue($value) { | ||||
| $results = $this->parseObjectList( | $results = $this->parseObjectList( | ||||
| $value, | $value, | ||||
| array( | array( | ||||
| PhabricatorPeopleUserPHIDType::TYPECONST, | PhabricatorPeopleUserPHIDType::TYPECONST, | ||||
| PhabricatorProjectProjectPHIDType::TYPECONST, | PhabricatorProjectProjectPHIDType::TYPECONST, | ||||
| PhabricatorOwnersPackagePHIDType::TYPECONST, | PhabricatorOwnersPackagePHIDType::TYPECONST, | ||||
| ), | ), | ||||
| false, | false, | ||||
| array('!')); | array('!')); | ||||
| return $this->flattenReviewers($results); | return $this->flattenReviewers($results); | ||||
| } | } | ||||
| public function readFieldValueFromConduit($value) { | |||||
| return $this->readStringListFieldValueFromConduit($value); | |||||
| } | |||||
| public function readFieldValueFromObject(DifferentialRevision $revision) { | |||||
| if (!$revision->getPHID()) { | |||||
| return array(); | |||||
| } | |||||
| $status_blocking = DifferentialReviewerStatus::STATUS_BLOCKING; | |||||
| $results = array(); | |||||
| foreach ($revision->getReviewerStatus() as $reviewer) { | |||||
| if ($reviewer->getStatus() == $status_blocking) { | |||||
| $suffixes = array('!' => '!'); | |||||
| } else { | |||||
| $suffixes = array(); | |||||
| } | |||||
| $results[] = array( | |||||
| 'phid' => $reviewer->getReviewerPHID(), | |||||
| 'suffixes' => $suffixes, | |||||
| ); | |||||
| } | |||||
| return $this->flattenReviewers($results); | |||||
| } | |||||
| public function renderFieldValue($value) { | |||||
| $value = $this->inflateReviewers($value); | |||||
| $phid_list = array(); | |||||
| $suffix_map = array(); | |||||
| foreach ($value as $reviewer) { | |||||
| $phid = $reviewer['phid']; | |||||
| $phid_list[] = $phid; | |||||
| if (isset($reviewer['suffixes']['!'])) { | |||||
| $suffix_map[$phid] = '!'; | |||||
| } | |||||
| } | |||||
| return $this->renderHandleList($phid_list, $suffix_map); | |||||
| } | |||||
| private function flattenReviewers(array $values) { | private function flattenReviewers(array $values) { | ||||
| // NOTE: For now, `arc` relies on this field returning only scalars, so we | // NOTE: For now, `arc` relies on this field returning only scalars, so we | ||||
| // need to reduce the results into scalars. See T10981. | // need to reduce the results into scalars. See T10981. | ||||
| $result = array(); | $result = array(); | ||||
| foreach ($values as $value) { | foreach ($values as $value) { | ||||
| $result[] = $value['phid'].implode('', array_keys($value['suffixes'])); | $result[] = $value['phid'].implode('', array_keys($value['suffixes'])); | ||||
| } | } | ||||
| Show All 25 Lines | |||||