Page MenuHomec4science

DifferentialReviewersFieldSpecification.php
No OneTemporary

File Metadata

Created
Sat, Nov 16, 22:32

DifferentialReviewersFieldSpecification.php

<?php
/*
* Copyright 2011 Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
final class DifferentialReviewersFieldSpecification
extends DifferentialFieldSpecification {
private $reviewers;
private $error;
public function shouldAppearOnRevisionView() {
return true;
}
public function getRequiredHandlePHIDsForRevisionView() {
return $this->getReviewerPHIDs();
}
public function renderLabelForRevisionView() {
return 'Reviewers:';
}
public function renderValueForRevisionView() {
$reviewer_phids = $this->getReviewerPHIDs();
if (!$reviewer_phids) {
return '<em>None</em>';
}
$links = array();
foreach ($reviewer_phids as $reviewer_phid) {
$links[] = $this->getHandle($reviewer_phid)->renderLink();
}
return implode(', ', $links);
}
private function getReviewerPHIDs() {
$revision = $this->getRevision();
return $revision->getReviewers();
}
public function shouldAppearOnEdit() {
$this->reviewers = $this->getReviewerPHIDs();
return true;
}
public function getRequiredHandlePHIDsForRevisionEdit() {
return $this->reviewers;
}
public function setValueFromRequest(AphrontRequest $request) {
$this->reviewers = $request->getArr('reviewers');
return $this;
}
public function validateField() {
if (in_array($this->getUser()->getPHID(), $this->reviewers)) {
$this->error = 'Invalid';
throw new DifferentialFieldValidationException(
"You may not review your own revision!");
}
}
public function renderEditControl() {
$reviewer_map = array();
foreach ($this->reviewers as $phid) {
$reviewer_map[$phid] = $this->getHandle($phid)->getFullName();
}
return id(new AphrontFormTokenizerControl())
->setLabel('Reviewers')
->setName('reviewers')
->setDatasource('/typeahead/common/users/')
->setValue($reviewer_map)
->setError($this->error);
}
public function willWriteRevision(DifferentialRevisionEditor $editor) {
$editor->setReviewers($this->reviewers);
}
}

Event Timeline