[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

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

   1  <?php
   2  
   3  final class PhabricatorStandardCustomFieldInt
   4    extends PhabricatorStandardCustomField {
   5  
   6    public function getFieldType() {
   7      return 'int';
   8    }
   9  
  10    public function buildFieldIndexes() {
  11      $indexes = array();
  12  
  13      $value = $this->getFieldValue();
  14      if (strlen($value)) {
  15        $indexes[] = $this->newNumericIndex((int)$value);
  16      }
  17  
  18      return $indexes;
  19    }
  20  
  21    public function buildOrderIndex() {
  22      return $this->newNumericIndex(0);
  23    }
  24  
  25    public function getValueForStorage() {
  26      $value = $this->getFieldValue();
  27      if (strlen($value)) {
  28        return $value;
  29      } else {
  30        return null;
  31      }
  32    }
  33  
  34    public function setValueFromStorage($value) {
  35      if (strlen($value)) {
  36        $value = (int)$value;
  37      } else {
  38        $value = null;
  39      }
  40      return $this->setFieldValue($value);
  41    }
  42  
  43    public function readApplicationSearchValueFromRequest(
  44      PhabricatorApplicationSearchEngine $engine,
  45      AphrontRequest $request) {
  46  
  47      return $request->getStr($this->getFieldKey());
  48    }
  49  
  50    public function applyApplicationSearchConstraintToQuery(
  51      PhabricatorApplicationSearchEngine $engine,
  52      PhabricatorCursorPagedPolicyAwareQuery $query,
  53      $value) {
  54  
  55      if (strlen($value)) {
  56        $query->withApplicationSearchContainsConstraint(
  57          $this->newNumericIndex(null),
  58          $value);
  59      }
  60    }
  61  
  62    public function appendToApplicationSearchForm(
  63      PhabricatorApplicationSearchEngine $engine,
  64      AphrontFormView $form,
  65      $value,
  66      array $handles) {
  67  
  68      $form->appendChild(
  69        id(new AphrontFormTextControl())
  70          ->setLabel($this->getFieldName())
  71          ->setName($this->getFieldKey())
  72          ->setValue($value));
  73    }
  74  
  75    public function validateApplicationTransactions(
  76      PhabricatorApplicationTransactionEditor $editor,
  77      $type,
  78      array $xactions) {
  79  
  80      $errors = parent::validateApplicationTransactions(
  81        $editor,
  82        $type,
  83        $xactions);
  84  
  85      foreach ($xactions as $xaction) {
  86        $value = $xaction->getNewValue();
  87        if (strlen($value)) {
  88          if (!preg_match('/^-?\d+/', $value)) {
  89            $errors[] = new PhabricatorApplicationTransactionValidationError(
  90              $type,
  91              pht('Invalid'),
  92              pht('%s must be an integer.', $this->getFieldName()),
  93              $xaction);
  94            $this->setFieldError(pht('Invalid'));
  95          }
  96        }
  97      }
  98  
  99      return $errors;
 100    }
 101  
 102    public function getApplicationTransactionHasEffect(
 103      PhabricatorApplicationTransaction $xaction) {
 104  
 105      $old = $xaction->getOldValue();
 106      $new = $xaction->getNewValue();
 107      if (!strlen($old) && strlen($new)) {
 108        return true;
 109      } else if (strlen($old) && !strlen($new)) {
 110        return true;
 111      } else {
 112        return ((int)$old !== (int)$new);
 113      }
 114    }
 115  
 116  
 117  }


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