mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-27 17:22:42 +01:00
161ebad56d
Summary: Ref T9964. Three goals here: - Make it easier to supply Conduit documentation. - Make automatic documentation for `*.edit` endpoints more complete, particularly for custom fields. - Allow type resolution via Conduit types, so you can pass `["alincoln"]` to "subscribers" instead of needing to use PHIDs. Test Plan: - Viewed and used all search and edit endpoints, including custom fields. - Used parameter type resolution to set subscribers to user "dog" instead of "PHID-USER-whatever". - Viewed HTTP parameter documentation. Reviewers: chad Reviewed By: chad Maniphest Tasks: T9964 Differential Revision: https://secure.phabricator.com/D14796
127 lines
2.9 KiB
PHP
127 lines
2.9 KiB
PHP
<?php
|
|
|
|
final class PhabricatorStandardCustomFieldInt
|
|
extends PhabricatorStandardCustomField {
|
|
|
|
public function getFieldType() {
|
|
return 'int';
|
|
}
|
|
|
|
public function buildFieldIndexes() {
|
|
$indexes = array();
|
|
|
|
$value = $this->getFieldValue();
|
|
if (strlen($value)) {
|
|
$indexes[] = $this->newNumericIndex((int)$value);
|
|
}
|
|
|
|
return $indexes;
|
|
}
|
|
|
|
public function buildOrderIndex() {
|
|
return $this->newNumericIndex(0);
|
|
}
|
|
|
|
public function getValueForStorage() {
|
|
$value = $this->getFieldValue();
|
|
if (strlen($value)) {
|
|
return $value;
|
|
} else {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
public function setValueFromStorage($value) {
|
|
if (strlen($value)) {
|
|
$value = (int)$value;
|
|
} else {
|
|
$value = null;
|
|
}
|
|
return $this->setFieldValue($value);
|
|
}
|
|
|
|
public function readApplicationSearchValueFromRequest(
|
|
PhabricatorApplicationSearchEngine $engine,
|
|
AphrontRequest $request) {
|
|
|
|
return $request->getStr($this->getFieldKey());
|
|
}
|
|
|
|
public function applyApplicationSearchConstraintToQuery(
|
|
PhabricatorApplicationSearchEngine $engine,
|
|
PhabricatorCursorPagedPolicyAwareQuery $query,
|
|
$value) {
|
|
|
|
if (strlen($value)) {
|
|
$query->withApplicationSearchContainsConstraint(
|
|
$this->newNumericIndex(null),
|
|
$value);
|
|
}
|
|
}
|
|
|
|
public function appendToApplicationSearchForm(
|
|
PhabricatorApplicationSearchEngine $engine,
|
|
AphrontFormView $form,
|
|
$value) {
|
|
|
|
$form->appendChild(
|
|
id(new AphrontFormTextControl())
|
|
->setLabel($this->getFieldName())
|
|
->setName($this->getFieldKey())
|
|
->setValue($value));
|
|
}
|
|
|
|
public function validateApplicationTransactions(
|
|
PhabricatorApplicationTransactionEditor $editor,
|
|
$type,
|
|
array $xactions) {
|
|
|
|
$errors = parent::validateApplicationTransactions(
|
|
$editor,
|
|
$type,
|
|
$xactions);
|
|
|
|
foreach ($xactions as $xaction) {
|
|
$value = $xaction->getNewValue();
|
|
if (strlen($value)) {
|
|
if (!preg_match('/^-?\d+/', $value)) {
|
|
$errors[] = new PhabricatorApplicationTransactionValidationError(
|
|
$type,
|
|
pht('Invalid'),
|
|
pht('%s must be an integer.', $this->getFieldName()),
|
|
$xaction);
|
|
$this->setFieldError(pht('Invalid'));
|
|
}
|
|
}
|
|
}
|
|
|
|
return $errors;
|
|
}
|
|
|
|
public function getApplicationTransactionHasEffect(
|
|
PhabricatorApplicationTransaction $xaction) {
|
|
|
|
$old = $xaction->getOldValue();
|
|
$new = $xaction->getNewValue();
|
|
if (!strlen($old) && strlen($new)) {
|
|
return true;
|
|
} else if (strlen($old) && !strlen($new)) {
|
|
return true;
|
|
} else {
|
|
return ((int)$old !== (int)$new);
|
|
}
|
|
}
|
|
|
|
protected function getHTTPParameterType() {
|
|
return new AphrontIntHTTPParameterType();
|
|
}
|
|
|
|
protected function newConduitSearchParameterType() {
|
|
return new ConduitIntParameterType();
|
|
}
|
|
|
|
protected function newConduitEditParameterType() {
|
|
return new ConduitIntParameterType();
|
|
}
|
|
|
|
}
|