Path: blob/master/src/infrastructure/customfield/standard/PhabricatorStandardCustomFieldInt.php
12242 views
<?php12final class PhabricatorStandardCustomFieldInt3extends PhabricatorStandardCustomField {45public function getFieldType() {6return 'int';7}89public function buildFieldIndexes() {10$indexes = array();1112$value = $this->getFieldValue();13if (strlen($value)) {14$indexes[] = $this->newNumericIndex((int)$value);15}1617return $indexes;18}1920public function buildOrderIndex() {21return $this->newNumericIndex(0);22}2324public function getValueForStorage() {25$value = $this->getFieldValue();26if ($value !== null && strlen($value)) {27return $value;28} else {29return null;30}31}3233public function setValueFromStorage($value) {34if (strlen($value)) {35$value = (int)$value;36} else {37$value = null;38}39return $this->setFieldValue($value);40}4142public function readApplicationSearchValueFromRequest(43PhabricatorApplicationSearchEngine $engine,44AphrontRequest $request) {4546return $request->getStr($this->getFieldKey());47}4849public function applyApplicationSearchConstraintToQuery(50PhabricatorApplicationSearchEngine $engine,51PhabricatorCursorPagedPolicyAwareQuery $query,52$value) {5354if (strlen($value)) {55$query->withApplicationSearchContainsConstraint(56$this->newNumericIndex(null),57$value);58}59}6061public function appendToApplicationSearchForm(62PhabricatorApplicationSearchEngine $engine,63AphrontFormView $form,64$value) {6566$form->appendChild(67id(new AphrontFormTextControl())68->setLabel($this->getFieldName())69->setName($this->getFieldKey())70->setValue($value));71}7273public function validateApplicationTransactions(74PhabricatorApplicationTransactionEditor $editor,75$type,76array $xactions) {7778$errors = parent::validateApplicationTransactions(79$editor,80$type,81$xactions);8283foreach ($xactions as $xaction) {84$value = $xaction->getNewValue();85if (strlen($value)) {86if (!preg_match('/^-?\d+/', $value)) {87$errors[] = new PhabricatorApplicationTransactionValidationError(88$type,89pht('Invalid'),90pht('%s must be an integer.', $this->getFieldName()),91$xaction);92$this->setFieldError(pht('Invalid'));93}94}95}9697return $errors;98}99100public function getApplicationTransactionHasEffect(101PhabricatorApplicationTransaction $xaction) {102103$old = $xaction->getOldValue();104$new = $xaction->getNewValue();105if (!strlen($old) && strlen($new)) {106return true;107} else if (strlen($old) && !strlen($new)) {108return true;109} else {110return ((int)$old !== (int)$new);111}112}113114protected function getHTTPParameterType() {115return new AphrontIntHTTPParameterType();116}117118protected function newConduitSearchParameterType() {119return new ConduitIntParameterType();120}121122protected function newConduitEditParameterType() {123return new ConduitIntParameterType();124}125126protected function newExportFieldType() {127return new PhabricatorIntExportField();128}129130}131132133