@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

at upstream/main 145 lines 3.9 kB view raw
1<?php 2 3final 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 (phutil_nonempty_scalar($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 $is_nonempty = phutil_string_cast($value) !== ''; 28 if ($is_nonempty) { 29 return $value; 30 } else { 31 return null; 32 } 33 } 34 35 public function setValueFromStorage($value) { 36 if (phutil_nonempty_scalar($value)) { 37 $value = (int)$value; 38 } else { 39 $value = null; 40 } 41 return $this->setFieldValue($value); 42 } 43 44 public function readApplicationSearchValueFromRequest( 45 PhabricatorApplicationSearchEngine $engine, 46 AphrontRequest $request) { 47 48 return $request->getStr($this->getFieldKey()); 49 } 50 51 /** 52 * Apply an application search constraint to a query. 53 * If you have a field of type integer, and a value (or an array of values), 54 * the result set will be limited to the rows with these values. 55 * @param PhabricatorApplicationSearchEngine $engine 56 * @param PhabricatorCursorPagedPolicyAwareQuery $query 57 * @param mixed $value Single value or array of values (IN query). 58 */ 59 public function applyApplicationSearchConstraintToQuery( 60 PhabricatorApplicationSearchEngine $engine, 61 PhabricatorCursorPagedPolicyAwareQuery $query, 62 $value) { 63 64 // The basic use case is with a single value. 65 // The backend really works with an array. So also array allowed. 66 if (is_array($value) || phutil_nonempty_scalar($value)) { 67 $value = (array)$value; 68 if ($value) { 69 $query->withApplicationSearchContainsConstraint( 70 $this->newNumericIndex(null), 71 $value); 72 } 73 } 74 } 75 76 public function appendToApplicationSearchForm( 77 PhabricatorApplicationSearchEngine $engine, 78 AphrontFormView $form, 79 $value) { 80 81 $form->appendChild( 82 id(new AphrontFormTextControl()) 83 ->setLabel($this->getFieldName()) 84 ->setName($this->getFieldKey()) 85 ->setValue($value)); 86 } 87 88 public function validateApplicationTransactions( 89 PhabricatorApplicationTransactionEditor $editor, 90 $type, 91 array $xactions) { 92 93 $errors = parent::validateApplicationTransactions( 94 $editor, 95 $type, 96 $xactions); 97 98 foreach ($xactions as $xaction) { 99 $value = $xaction->getNewValue(); 100 if (phutil_nonempty_scalar($value)) { 101 if (!preg_match('/^-?\d+/', $value)) { 102 $errors[] = new PhabricatorApplicationTransactionValidationError( 103 $type, 104 pht('Invalid'), 105 pht('%s must be an integer.', $this->getFieldName()), 106 $xaction); 107 $this->setFieldError(pht('Invalid')); 108 } 109 } 110 } 111 112 return $errors; 113 } 114 115 public function getApplicationTransactionHasEffect( 116 PhabricatorApplicationTransaction $xaction) { 117 118 $old = $xaction->getOldValue(); 119 $new = $xaction->getNewValue(); 120 if (!phutil_nonempty_scalar($old) && phutil_nonempty_scalar($new)) { 121 return true; 122 } else if (phutil_nonempty_scalar($old) && !phutil_nonempty_scalar($new)) { 123 return true; 124 } else { 125 return ((int)$old !== (int)$new); 126 } 127 } 128 129 protected function getHTTPParameterType() { 130 return new AphrontIntHTTPParameterType(); 131 } 132 133 protected function newConduitSearchParameterType() { 134 return new ConduitIntParameterType(); 135 } 136 137 protected function newConduitEditParameterType() { 138 return new ConduitIntParameterType(); 139 } 140 141 protected function newExportFieldType() { 142 return new PhabricatorIntExportField(); 143 } 144 145}