1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of Jitamin. |
5
|
|
|
* |
6
|
|
|
* Copyright (C) Jitamin Team |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Jitamin\Validator; |
13
|
|
|
|
14
|
|
|
use SimpleValidator\Validator; |
15
|
|
|
use SimpleValidator\Validators; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Task Validator. |
19
|
|
|
*/ |
20
|
|
|
class TaskValidator extends BaseValidator |
21
|
|
|
{ |
22
|
|
|
/** |
23
|
|
|
* Common validation rules. |
24
|
|
|
* |
25
|
|
|
* @return array |
26
|
|
|
*/ |
27
|
|
|
private function commonValidationRules() |
28
|
|
|
{ |
29
|
|
|
return [ |
30
|
|
|
new Validators\Integer('id', t('This value must be an integer')), |
31
|
|
|
new Validators\Integer('project_id', t('This value must be an integer')), |
32
|
|
|
new Validators\Integer('column_id', t('This value must be an integer')), |
33
|
|
|
new Validators\Integer('owner_id', t('This value must be an integer')), |
34
|
|
|
new Validators\Integer('creator_id', t('This value must be an integer')), |
35
|
|
|
new Validators\Integer('score', t('This value must be an integer')), |
36
|
|
|
new Validators\Range('score', t('This value must be in the range %d to %d', -2147483647, 2147483647), -2147483647, 2147483647), |
37
|
|
|
new Validators\Integer('category_id', t('This value must be an integer')), |
38
|
|
|
new Validators\Integer('swimlane_id', t('This value must be an integer')), |
39
|
|
|
new Validators\Integer('recurrence_child', t('This value must be an integer')), |
40
|
|
|
new Validators\Integer('recurrence_parent', t('This value must be an integer')), |
41
|
|
|
new Validators\Integer('recurrence_factor', t('This value must be an integer')), |
42
|
|
|
new Validators\Integer('recurrence_timeframe', t('This value must be an integer')), |
43
|
|
|
new Validators\Integer('recurrence_basedate', t('This value must be an integer')), |
44
|
|
|
new Validators\Integer('recurrence_trigger', t('This value must be an integer')), |
45
|
|
|
new Validators\Integer('recurrence_status', t('This value must be an integer')), |
46
|
|
|
new Validators\Integer('priority', t('This value must be an integer')), |
47
|
|
|
new Validators\MaxLength('title', t('The maximum length is %d characters', 200), 200), |
48
|
|
|
new Validators\MaxLength('reference', t('The maximum length is %d characters', 50), 50), |
49
|
|
|
new Validators\Date('date_due', t('Invalid date'), $this->dateParser->getParserFormats()), |
|
|
|
|
50
|
|
|
new Validators\Date('date_started', t('Invalid date'), $this->dateParser->getParserFormats()), |
|
|
|
|
51
|
|
|
new Validators\Numeric('time_spent', t('This value must be numeric')), |
52
|
|
|
new Validators\Numeric('time_estimated', t('This value must be numeric')), |
53
|
|
|
]; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Validate task creation. |
58
|
|
|
* |
59
|
|
|
* @param array $values Form values |
60
|
|
|
* |
61
|
|
|
* @return array $valid, $errors [0] = Success or not, [1] = List of errors |
62
|
|
|
*/ |
63
|
|
|
public function validateCreation(array $values) |
64
|
|
|
{ |
65
|
|
|
$rules = [ |
66
|
|
|
new Validators\Required('project_id', t('The project is required')), |
67
|
|
|
new Validators\Required('title', t('The title is required')), |
68
|
|
|
]; |
69
|
|
|
|
70
|
|
|
$v = new Validator($values, array_merge($rules, $this->commonValidationRules())); |
71
|
|
|
|
72
|
|
|
return [ |
73
|
|
|
$v->execute(), |
74
|
|
|
$v->getErrors(), |
75
|
|
|
]; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* Validate task creation. |
80
|
|
|
* |
81
|
|
|
* @param array $values Form values |
82
|
|
|
* |
83
|
|
|
* @return array $valid, $errors [0] = Success or not, [1] = List of errors |
84
|
|
|
*/ |
85
|
|
|
public function validateBulkCreation(array $values) |
86
|
|
|
{ |
87
|
|
|
$rules = [ |
88
|
|
|
new Validators\Required('project_id', t('The project is required')), |
89
|
|
|
new Validators\Required('tasks', t('Field required')), |
90
|
|
|
new Validators\Required('column_id', t('Field required')), |
91
|
|
|
new Validators\Required('swimlane_id', t('Field required')), |
92
|
|
|
new Validators\Integer('category_id', t('This value must be an integer')), |
93
|
|
|
new Validators\Integer('swimlane_id', t('This value must be an integer')), |
94
|
|
|
]; |
95
|
|
|
|
96
|
|
|
$v = new Validator($values, array_merge($rules, $this->commonValidationRules())); |
97
|
|
|
|
98
|
|
|
return [ |
99
|
|
|
$v->execute(), |
100
|
|
|
$v->getErrors(), |
101
|
|
|
]; |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* Validate edit recurrence. |
106
|
|
|
* |
107
|
|
|
* @param array $values Form values |
108
|
|
|
* |
109
|
|
|
* @return array $valid, $errors [0] = Success or not, [1] = List of errors |
110
|
|
|
*/ |
111
|
|
|
public function validateEditRecurrence(array $values) |
112
|
|
|
{ |
113
|
|
|
$rules = [ |
114
|
|
|
new Validators\Required('id', t('The id is required')), |
115
|
|
|
]; |
116
|
|
|
|
117
|
|
|
$v = new Validator($values, array_merge($rules, $this->commonValidationRules())); |
118
|
|
|
|
119
|
|
|
return [ |
120
|
|
|
$v->execute(), |
121
|
|
|
$v->getErrors(), |
122
|
|
|
]; |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
/** |
126
|
|
|
* Validate task modification (form). |
127
|
|
|
* |
128
|
|
|
* @param array $values Form values |
129
|
|
|
* |
130
|
|
|
* @return array $valid, $errors [0] = Success or not, [1] = List of errors |
131
|
|
|
*/ |
132
|
|
|
public function validateModification(array $values) |
133
|
|
|
{ |
134
|
|
|
$rules = [ |
135
|
|
|
new Validators\Required('id', t('The id is required')), |
136
|
|
|
new Validators\Required('title', t('The title is required')), |
137
|
|
|
]; |
138
|
|
|
|
139
|
|
|
$v = new Validator($values, array_merge($rules, $this->commonValidationRules())); |
140
|
|
|
|
141
|
|
|
return [ |
142
|
|
|
$v->execute(), |
143
|
|
|
$v->getErrors(), |
144
|
|
|
]; |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
/** |
148
|
|
|
* Validate task modification (Api). |
149
|
|
|
* |
150
|
|
|
* @param array $values Form values |
151
|
|
|
* |
152
|
|
|
* @return array $valid, $errors [0] = Success or not, [1] = List of errors |
153
|
|
|
*/ |
154
|
|
|
public function validateApiModification(array $values) |
155
|
|
|
{ |
156
|
|
|
$rules = [ |
157
|
|
|
new Validators\Required('id', t('The id is required')), |
158
|
|
|
]; |
159
|
|
|
|
160
|
|
|
$v = new Validator($values, array_merge($rules, $this->commonValidationRules())); |
161
|
|
|
|
162
|
|
|
return [ |
163
|
|
|
$v->execute(), |
164
|
|
|
$v->getErrors(), |
165
|
|
|
]; |
166
|
|
|
} |
167
|
|
|
|
168
|
|
|
/** |
169
|
|
|
* Validate project modification. |
170
|
|
|
* |
171
|
|
|
* @param array $values Form values |
172
|
|
|
* |
173
|
|
|
* @return array $valid, $errors [0] = Success or not, [1] = List of errors |
174
|
|
|
*/ |
175
|
|
|
public function validateProjectModification(array $values) |
176
|
|
|
{ |
177
|
|
|
$rules = [ |
178
|
|
|
new Validators\Required('id', t('The id is required')), |
179
|
|
|
new Validators\Required('project_id', t('The project is required')), |
180
|
|
|
]; |
181
|
|
|
|
182
|
|
|
$v = new Validator($values, array_merge($rules, $this->commonValidationRules())); |
183
|
|
|
|
184
|
|
|
return [ |
185
|
|
|
$v->execute(), |
186
|
|
|
$v->getErrors(), |
187
|
|
|
]; |
188
|
|
|
} |
189
|
|
|
|
190
|
|
|
/** |
191
|
|
|
* Validate time tracking modification (form). |
192
|
|
|
* |
193
|
|
|
* @param array $values Form values |
194
|
|
|
* |
195
|
|
|
* @return array $valid, $errors [0] = Success or not, [1] = List of errors |
196
|
|
|
*/ |
197
|
|
|
public function validateTimeModification(array $values) |
198
|
|
|
{ |
199
|
|
|
$rules = [ |
200
|
|
|
new Validators\Required('id', t('The id is required')), |
201
|
|
|
]; |
202
|
|
|
|
203
|
|
|
$v = new Validator($values, array_merge($rules, $this->commonValidationRules())); |
204
|
|
|
|
205
|
|
|
return [ |
206
|
|
|
$v->execute(), |
207
|
|
|
$v->getErrors(), |
208
|
|
|
]; |
209
|
|
|
} |
210
|
|
|
} |
211
|
|
|
|
Since your code implements the magic getter
_get
, this function will be called for any read access on an undefined variable. You can add the@property
annotation to your class or interface to document the existence of this variable.If the property has read access only, you can use the @property-read annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.