[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/infrastructure/customfield/standard/ -> PhabricatorStandardCustomFieldSelect.php (source)

   1  <?php
   2  
   3  final class PhabricatorStandardCustomFieldSelect
   4    extends PhabricatorStandardCustomField {
   5  
   6    public function getFieldType() {
   7      return 'select';
   8    }
   9  
  10    public function buildFieldIndexes() {
  11      $indexes = array();
  12  
  13      $value = $this->getFieldValue();
  14      if (strlen($value)) {
  15        $indexes[] = $this->newStringIndex($value);
  16      }
  17  
  18      return $indexes;
  19    }
  20  
  21    public function readApplicationSearchValueFromRequest(
  22      PhabricatorApplicationSearchEngine $engine,
  23      AphrontRequest $request) {
  24      return $request->getArr($this->getFieldKey());
  25    }
  26  
  27    public function applyApplicationSearchConstraintToQuery(
  28      PhabricatorApplicationSearchEngine $engine,
  29      PhabricatorCursorPagedPolicyAwareQuery $query,
  30      $value) {
  31      if ($value) {
  32        $query->withApplicationSearchContainsConstraint(
  33          $this->newStringIndex(null),
  34          $value);
  35      }
  36    }
  37  
  38    public function appendToApplicationSearchForm(
  39      PhabricatorApplicationSearchEngine $engine,
  40      AphrontFormView $form,
  41      $value,
  42      array $handles) {
  43  
  44      if (!is_array($value)) {
  45        $value = array();
  46      }
  47      $value = array_fuse($value);
  48  
  49      $control = id(new AphrontFormCheckboxControl())
  50        ->setLabel($this->getFieldName());
  51  
  52      foreach ($this->getOptions() as $name => $option) {
  53        $control->addCheckbox(
  54          $this->getFieldKey().'[]',
  55          $name,
  56          $option,
  57          isset($value[$name]));
  58      }
  59  
  60      $form->appendChild($control);
  61    }
  62  
  63    private function getOptions() {
  64      return $this->getFieldConfigValue('options', array());
  65    }
  66  
  67    public function renderEditControl(array $handles) {
  68      return id(new AphrontFormSelectControl())
  69        ->setLabel($this->getFieldName())
  70        ->setCaption($this->getCaption())
  71        ->setName($this->getFieldKey())
  72        ->setValue($this->getFieldValue())
  73        ->setOptions($this->getOptions());
  74    }
  75  
  76    public function renderPropertyViewValue(array $handles) {
  77      if (!strlen($this->getFieldValue())) {
  78        return null;
  79      }
  80      return idx($this->getOptions(), $this->getFieldValue());
  81    }
  82  
  83  
  84    public function getApplicationTransactionTitle(
  85      PhabricatorApplicationTransaction $xaction) {
  86      $author_phid = $xaction->getAuthorPHID();
  87      $old = $xaction->getOldValue();
  88      $new = $xaction->getNewValue();
  89  
  90      $old = idx($this->getOptions(), $old, $old);
  91      $new = idx($this->getOptions(), $new, $new);
  92  
  93      if (!$old) {
  94        return pht(
  95          '%s set %s to %s.',
  96          $xaction->renderHandleLink($author_phid),
  97          $this->getFieldName(),
  98          $new);
  99      } else if (!$new) {
 100        return pht(
 101          '%s removed %s.',
 102          $xaction->renderHandleLink($author_phid),
 103          $this->getFieldName());
 104      } else {
 105        return pht(
 106          '%s changed %s from %s to %s.',
 107          $xaction->renderHandleLink($author_phid),
 108          $this->getFieldName(),
 109          $old,
 110          $new);
 111      }
 112    }
 113  
 114  }


Generated: Sun Nov 30 09:20:46 2014 Cross-referenced by PHPXref 0.7.1