Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/infrastructure/customfield/standard/PhabricatorStandardCustomFieldInt.php
12242 views
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 ($value !== null && 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
67
$form->appendChild(
68
id(new AphrontFormTextControl())
69
->setLabel($this->getFieldName())
70
->setName($this->getFieldKey())
71
->setValue($value));
72
}
73
74
public function validateApplicationTransactions(
75
PhabricatorApplicationTransactionEditor $editor,
76
$type,
77
array $xactions) {
78
79
$errors = parent::validateApplicationTransactions(
80
$editor,
81
$type,
82
$xactions);
83
84
foreach ($xactions as $xaction) {
85
$value = $xaction->getNewValue();
86
if (strlen($value)) {
87
if (!preg_match('/^-?\d+/', $value)) {
88
$errors[] = new PhabricatorApplicationTransactionValidationError(
89
$type,
90
pht('Invalid'),
91
pht('%s must be an integer.', $this->getFieldName()),
92
$xaction);
93
$this->setFieldError(pht('Invalid'));
94
}
95
}
96
}
97
98
return $errors;
99
}
100
101
public function getApplicationTransactionHasEffect(
102
PhabricatorApplicationTransaction $xaction) {
103
104
$old = $xaction->getOldValue();
105
$new = $xaction->getNewValue();
106
if (!strlen($old) && strlen($new)) {
107
return true;
108
} else if (strlen($old) && !strlen($new)) {
109
return true;
110
} else {
111
return ((int)$old !== (int)$new);
112
}
113
}
114
115
protected function getHTTPParameterType() {
116
return new AphrontIntHTTPParameterType();
117
}
118
119
protected function newConduitSearchParameterType() {
120
return new ConduitIntParameterType();
121
}
122
123
protected function newConduitEditParameterType() {
124
return new ConduitIntParameterType();
125
}
126
127
protected function newExportFieldType() {
128
return new PhabricatorIntExportField();
129
}
130
131
}
132
133