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\Helper; |
13
|
|
|
|
14
|
|
|
use Jitamin\Foundation\Base; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Task helpers. |
18
|
|
|
*/ |
19
|
|
|
class TaskHelper extends Base |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* Local cache for project columns. |
23
|
|
|
* |
24
|
|
|
* @var array |
25
|
|
|
*/ |
26
|
|
|
private $columns = []; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Get the color list. |
30
|
|
|
* |
31
|
|
|
* @return array |
32
|
|
|
*/ |
33
|
|
|
public function getColors() |
34
|
|
|
{ |
35
|
|
|
return $this->colorModel->getList(); |
|
|
|
|
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Return the list recurrence triggers. |
40
|
|
|
* |
41
|
|
|
* @return array |
42
|
|
|
*/ |
43
|
|
|
public function recurrenceTriggers() |
44
|
|
|
{ |
45
|
|
|
return $this->taskRecurrenceModel->getRecurrenceTriggerList(); |
|
|
|
|
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Return the list recurrence timeframes. |
50
|
|
|
* |
51
|
|
|
* @return array |
52
|
|
|
*/ |
53
|
|
|
public function recurrenceTimeframes() |
54
|
|
|
{ |
55
|
|
|
return $this->taskRecurrenceModel->getRecurrenceTimeframeList(); |
|
|
|
|
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* Return the list options to calculate recurrence due date. |
60
|
|
|
* |
61
|
|
|
* @return array |
62
|
|
|
*/ |
63
|
|
|
public function recurrenceBasedates() |
64
|
|
|
{ |
65
|
|
|
return $this->taskRecurrenceModel->getRecurrenceBasedateList(); |
|
|
|
|
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* Display a select field of title. |
70
|
|
|
* |
71
|
|
|
* @param array $values Form values |
72
|
|
|
* @param array $errors Form errors |
73
|
|
|
* |
74
|
|
|
* @return string |
75
|
|
|
*/ |
76
|
|
|
public function selectTitle(array $values, array $errors) |
77
|
|
|
{ |
78
|
|
|
$html = $this->helper->form->label(t('Title'), 'title'); |
|
|
|
|
79
|
|
|
$html .= $this->helper->form->text('title', $values, $errors, ['autofocus', 'required', 'maxlength="200"', 'tabindex="1"'], 'form-input-large'); |
|
|
|
|
80
|
|
|
|
81
|
|
|
return $html; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* Display a select field of description. |
86
|
|
|
* |
87
|
|
|
* @param array $values Form values |
88
|
|
|
* @param array $errors Form errors |
89
|
|
|
* |
90
|
|
|
* @return string |
91
|
|
|
*/ |
92
|
|
|
public function selectDescription(array $values, array $errors) |
93
|
|
|
{ |
94
|
|
|
$html = $this->helper->form->label(t('Description'), 'description'); |
|
|
|
|
95
|
|
|
$html .= $this->helper->form->textEditor('description', $values, $errors, ['tabindex' => 2, 'placeholder' => t('Please add descriptive text to help others better understand this task')]); |
|
|
|
|
96
|
|
|
|
97
|
|
|
return $html; |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* Display a select field of tags. |
102
|
|
|
* |
103
|
|
|
* @param array $values Form values |
|
|
|
|
104
|
|
|
* @param array $targs Form tags |
|
|
|
|
105
|
|
|
* |
106
|
|
|
* @return string |
107
|
|
|
*/ |
108
|
|
|
public function selectTags(array $project, array $tags = []) |
109
|
|
|
{ |
110
|
|
|
$options = $this->tagModel->getAssignableList($project['id']); |
|
|
|
|
111
|
|
|
|
112
|
|
|
$html = $this->helper->form->label(t('Tags'), 'tags[]'); |
|
|
|
|
113
|
|
|
$html .= '<input type="hidden" name="tags[]" value="">'; |
114
|
|
|
$html .= '<select name="tags[]" id="form-tags" class="tag-autocomplete" multiple>'; |
115
|
|
|
|
116
|
|
|
foreach ($options as $tag) { |
117
|
|
|
$html .= sprintf( |
118
|
|
|
'<option value="%s" %s>%s</option>', |
119
|
|
|
$this->helper->text->e($tag), |
|
|
|
|
120
|
|
|
in_array($tag, $tags) ? 'selected="selected"' : '', |
121
|
|
|
$this->helper->text->e($tag) |
|
|
|
|
122
|
|
|
); |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
$html .= '</select>'; |
126
|
|
|
|
127
|
|
|
return $html; |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
/** |
131
|
|
|
* Display a select field of color. |
132
|
|
|
* |
133
|
|
|
* @param array $values Form values |
134
|
|
|
* |
135
|
|
|
* @return string |
136
|
|
|
*/ |
137
|
|
|
public function selectColor(array $values) |
138
|
|
|
{ |
139
|
|
|
$colors = $this->colorModel->getList(); |
|
|
|
|
140
|
|
|
$html = $this->helper->form->label(t('Color'), 'color_id'); |
|
|
|
|
141
|
|
|
$html .= $this->helper->form->select('color_id', $colors, $values, [], [], 'color-picker'); |
|
|
|
|
142
|
|
|
|
143
|
|
|
return $html; |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
/** |
147
|
|
|
* Display a select field of project. |
148
|
|
|
* |
149
|
|
|
* @param array $projects |
150
|
|
|
* @param array $values Form values |
151
|
|
|
* @param array $errors Form errors |
152
|
|
|
* @param array $attributes |
153
|
|
|
* |
154
|
|
|
* @return string |
155
|
|
|
*/ |
156
|
|
|
public function selectProject(array $projects, array $values, array $errors = [], array $attributes = []) |
157
|
|
|
{ |
158
|
|
|
$attributes = array_merge(['tabindex="2"'], $attributes); |
159
|
|
|
|
160
|
|
|
$html = $this->helper->form->label(t('Project'), 'project_id'); |
|
|
|
|
161
|
|
|
$html .= $this->helper->form->select('project_id', $projects, $values, $errors, $attributes); |
|
|
|
|
162
|
|
|
|
163
|
|
|
return $html; |
164
|
|
|
} |
165
|
|
|
|
166
|
|
|
/** |
167
|
|
|
* Display a select field of assignee. |
168
|
|
|
* |
169
|
|
|
* @param array $users |
170
|
|
|
* @param array $values Form values |
171
|
|
|
* @param array $errors Form errors |
172
|
|
|
* @param array $attributes |
173
|
|
|
* |
174
|
|
|
* @return string |
175
|
|
|
*/ |
176
|
|
View Code Duplication |
public function selectAssignee(array $users, array $values, array $errors = [], array $attributes = []) |
|
|
|
|
177
|
|
|
{ |
178
|
|
|
$attributes = array_merge(['tabindex="3"'], $attributes); |
179
|
|
|
|
180
|
|
|
$html = $this->helper->form->label(t('Assignee'), 'owner_id'); |
|
|
|
|
181
|
|
|
$html .= $this->helper->form->select('owner_id', $users, $values, $errors, $attributes); |
|
|
|
|
182
|
|
|
$html .= ' '; |
183
|
|
|
$html .= '<small>'; |
184
|
|
|
$html .= '<a href="#" class="assign-me" data-target-id="form-owner_id" data-current-id="'.$this->userSession->getId().'" title="'.t('Assign to me').'">'.t('Me').'</a>'; |
|
|
|
|
185
|
|
|
$html .= '</small>'; |
186
|
|
|
|
187
|
|
|
return $html; |
188
|
|
|
} |
189
|
|
|
|
190
|
|
|
/** |
191
|
|
|
* Display a select field of category. |
192
|
|
|
* |
193
|
|
|
* @param array $categories |
194
|
|
|
* @param array $values Form values |
195
|
|
|
* @param array $errors Form errors |
196
|
|
|
* @param array $attributes |
197
|
|
|
* @param bool allow_one_item |
198
|
|
|
* |
199
|
|
|
* @return string |
200
|
|
|
*/ |
201
|
|
View Code Duplication |
public function selectCategory(array $categories, array $values, array $errors = [], array $attributes = [], $allow_one_item = false) |
|
|
|
|
202
|
|
|
{ |
203
|
|
|
$attributes = array_merge(['tabindex="4"'], $attributes); |
204
|
|
|
$html = ''; |
205
|
|
|
|
206
|
|
|
if (!(!$allow_one_item && count($categories) === 1 && key($categories) == 0)) { |
207
|
|
|
$html .= $this->helper->form->label(t('Category'), 'category_id'); |
|
|
|
|
208
|
|
|
$html .= $this->helper->form->select('category_id', $categories, $values, $errors, $attributes); |
|
|
|
|
209
|
|
|
} |
210
|
|
|
|
211
|
|
|
return $html; |
212
|
|
|
} |
213
|
|
|
|
214
|
|
|
/** |
215
|
|
|
* Display a select field of swimlane. |
216
|
|
|
* |
217
|
|
|
* @param array $swimlanes |
218
|
|
|
* @param array $values Form values |
219
|
|
|
* @param array $errors Form errors |
220
|
|
|
* @param array $attributes |
221
|
|
|
* |
222
|
|
|
* @return string |
223
|
|
|
*/ |
224
|
|
View Code Duplication |
public function selectSwimlane(array $swimlanes, array $values, array $errors = [], array $attributes = []) |
|
|
|
|
225
|
|
|
{ |
226
|
|
|
$attributes = array_merge(['tabindex="5"'], $attributes); |
227
|
|
|
$html = ''; |
228
|
|
|
|
229
|
|
|
if (!(count($swimlanes) === 1 && key($swimlanes) == 0)) { |
230
|
|
|
$html .= $this->helper->form->label(t('Swimlane'), 'swimlane_id'); |
|
|
|
|
231
|
|
|
$html .= $this->helper->form->select('swimlane_id', $swimlanes, $values, $errors, $attributes); |
|
|
|
|
232
|
|
|
} |
233
|
|
|
|
234
|
|
|
return $html; |
235
|
|
|
} |
236
|
|
|
|
237
|
|
|
/** |
238
|
|
|
* Display a select field of column. |
239
|
|
|
* |
240
|
|
|
* @param array $columns |
241
|
|
|
* @param array $values Form values |
242
|
|
|
* @param array $errors Form errors |
243
|
|
|
* @param array $attributes |
244
|
|
|
* |
245
|
|
|
* @return string |
246
|
|
|
*/ |
247
|
|
View Code Duplication |
public function selectColumn(array $columns, array $values, array $errors = [], array $attributes = []) |
|
|
|
|
248
|
|
|
{ |
249
|
|
|
$attributes = array_merge(['tabindex="6"'], $attributes); |
250
|
|
|
|
251
|
|
|
$html = $this->helper->form->label(t('Column'), 'column_id'); |
|
|
|
|
252
|
|
|
$html .= $this->helper->form->select('column_id', $columns, $values, $errors, $attributes); |
|
|
|
|
253
|
|
|
|
254
|
|
|
return $html; |
255
|
|
|
} |
256
|
|
|
|
257
|
|
|
/** |
258
|
|
|
* Display a select field of column. |
259
|
|
|
* |
260
|
|
|
* @param array $project |
261
|
|
|
* @param array $values Form values |
262
|
|
|
* |
263
|
|
|
* @return string |
264
|
|
|
*/ |
265
|
|
|
public function selectPriority(array $project, array $values) |
266
|
|
|
{ |
267
|
|
|
$html = ''; |
268
|
|
|
|
269
|
|
|
if ($project['priority_end'] != $project['priority_start']) { |
270
|
|
|
$range = range($project['priority_end'], $project['priority_start']); |
271
|
|
|
$options = array_combine($range, $range); |
272
|
|
|
array_walk($options, create_function('&$val', '$val = t(\'P\'.$val);')); |
|
|
|
|
273
|
|
|
$values += ['priority' => $project['priority_default']]; |
274
|
|
|
|
275
|
|
|
$html .= $this->helper->form->label(t('Priority'), 'priority'); |
|
|
|
|
276
|
|
|
$html .= $this->helper->form->select('priority', $options, $values, [], ['tabindex="7"'], 'priority-picker'); |
|
|
|
|
277
|
|
|
} |
278
|
|
|
|
279
|
|
|
return $html; |
280
|
|
|
} |
281
|
|
|
|
282
|
|
|
/** |
283
|
|
|
* Display a select field of score. |
284
|
|
|
* |
285
|
|
|
* @param array $values Form values |
286
|
|
|
* @param array $errors Form errors |
287
|
|
|
* @param array $attributes |
288
|
|
|
* |
289
|
|
|
* @return string |
290
|
|
|
*/ |
291
|
|
|
public function selectScore(array $values, array $errors = [], array $attributes = []) |
292
|
|
|
{ |
293
|
|
|
$attributes = array_merge(['tabindex="8"'], $attributes); |
294
|
|
|
|
295
|
|
|
$html = $this->helper->form->label(t('Complexity'), 'score'); |
|
|
|
|
296
|
|
|
$html .= $this->helper->form->number('score', $values, $errors, $attributes); |
|
|
|
|
297
|
|
|
|
298
|
|
|
return $html; |
299
|
|
|
} |
300
|
|
|
|
301
|
|
|
/** |
302
|
|
|
* Display a select field of reference. |
303
|
|
|
* |
304
|
|
|
* @param array $values Form values |
305
|
|
|
* @param array $errors Form errors |
306
|
|
|
* @param array $attributes |
307
|
|
|
* |
308
|
|
|
* @return string |
309
|
|
|
*/ |
310
|
|
View Code Duplication |
public function selectReference(array $values, array $errors = [], array $attributes = []) |
|
|
|
|
311
|
|
|
{ |
312
|
|
|
$attributes = array_merge(['tabindex="9"'], $attributes); |
313
|
|
|
|
314
|
|
|
$html = $this->helper->form->label(t('Reference'), 'reference'); |
|
|
|
|
315
|
|
|
$html .= $this->helper->form->text('reference', $values, $errors, $attributes, 'form-input-small'); |
|
|
|
|
316
|
|
|
|
317
|
|
|
return $html; |
318
|
|
|
} |
319
|
|
|
|
320
|
|
|
/** |
321
|
|
|
* Display a select field of time estimated. |
322
|
|
|
* |
323
|
|
|
* @param array $values Form values |
324
|
|
|
* @param array $errors Form errors |
325
|
|
|
* @param array $attributes |
326
|
|
|
* |
327
|
|
|
* @return string |
328
|
|
|
*/ |
329
|
|
View Code Duplication |
public function selectTimeEstimated(array $values, array $errors = [], array $attributes = []) |
|
|
|
|
330
|
|
|
{ |
331
|
|
|
$attributes = array_merge(['tabindex="10"'], $attributes); |
332
|
|
|
|
333
|
|
|
$html = $this->helper->form->label(t('Original estimate'), 'time_estimated'); |
|
|
|
|
334
|
|
|
$html .= $this->helper->form->numeric('time_estimated', $values, $errors, $attributes); |
|
|
|
|
335
|
|
|
$html .= ' '.t('hours'); |
336
|
|
|
|
337
|
|
|
return $html; |
338
|
|
|
} |
339
|
|
|
|
340
|
|
|
/** |
341
|
|
|
* Display a select field of time spent. |
342
|
|
|
* |
343
|
|
|
* @param array $values Form values |
344
|
|
|
* @param array $errors Form errors |
345
|
|
|
* @param array $attributes |
346
|
|
|
* |
347
|
|
|
* @return string |
348
|
|
|
*/ |
349
|
|
View Code Duplication |
public function selectTimeSpent(array $values, array $errors = [], array $attributes = []) |
|
|
|
|
350
|
|
|
{ |
351
|
|
|
$attributes = array_merge(['tabindex="11"'], $attributes); |
352
|
|
|
|
353
|
|
|
$html = $this->helper->form->label(t('Time spent'), 'time_spent'); |
|
|
|
|
354
|
|
|
$html .= $this->helper->form->numeric('time_spent', $values, $errors, $attributes); |
|
|
|
|
355
|
|
|
$html .= ' '.t('hours'); |
356
|
|
|
|
357
|
|
|
return $html; |
358
|
|
|
} |
359
|
|
|
|
360
|
|
|
/** |
361
|
|
|
* Display a select field of start date. |
362
|
|
|
* |
363
|
|
|
* @param array $values Form values |
364
|
|
|
* @param array $errors Form errors |
365
|
|
|
* @param array $attributes |
366
|
|
|
* |
367
|
|
|
* @return string |
368
|
|
|
*/ |
369
|
|
|
public function selectStartDate(array $values, array $errors = [], array $attributes = []) |
370
|
|
|
{ |
371
|
|
|
$attributes = array_merge(['tabindex="12"'], $attributes); |
372
|
|
|
|
373
|
|
|
return $this->helper->form->datetime(t('Start Date'), 'date_started', $values, $errors, $attributes); |
|
|
|
|
374
|
|
|
} |
375
|
|
|
|
376
|
|
|
/** |
377
|
|
|
* Display a select field of due date. |
378
|
|
|
* |
379
|
|
|
* @param array $values Form values |
380
|
|
|
* @param array $errors Form errors |
381
|
|
|
* @param array $attributes |
382
|
|
|
* |
383
|
|
|
* @return string |
384
|
|
|
*/ |
385
|
|
|
public function selectDueDate(array $values, array $errors = [], array $attributes = []) |
386
|
|
|
{ |
387
|
|
|
$attributes = array_merge(['tabindex="13"'], $attributes); |
388
|
|
|
|
389
|
|
|
return $this->helper->form->date(t('Due Date'), 'date_due', $values, $errors, $attributes); |
|
|
|
|
390
|
|
|
} |
391
|
|
|
|
392
|
|
|
/** |
393
|
|
|
* Display a select field of progress. |
394
|
|
|
* |
395
|
|
|
* @param array $values Form values |
396
|
|
|
* @param array $errors Form errors |
397
|
|
|
* @param array $attributes |
398
|
|
|
* |
399
|
|
|
* @return string |
400
|
|
|
*/ |
401
|
|
View Code Duplication |
public function selectProgress(array $values, array $errors = [], array $attributes = []) |
|
|
|
|
402
|
|
|
{ |
403
|
|
|
$attributes = array_merge(['tabindex="14"'], $attributes); |
404
|
|
|
|
405
|
|
|
$html = $this->helper->form->label(t('Progress'), 'progress'); |
|
|
|
|
406
|
|
|
$html .= $this->helper->form->number('progress', $values, $errors, $attributes); |
|
|
|
|
407
|
|
|
|
408
|
|
|
$html .= ' '; |
409
|
|
|
$html .= '<small>%</small>'; |
410
|
|
|
|
411
|
|
|
return $html; |
412
|
|
|
} |
413
|
|
|
|
414
|
|
|
/** |
415
|
|
|
* Format the priority. |
416
|
|
|
* |
417
|
|
|
* @param array $project |
418
|
|
|
* @param array $task |
419
|
|
|
* |
420
|
|
|
* @return string |
421
|
|
|
*/ |
422
|
|
|
public function formatPriority(array $project, array $task) |
423
|
|
|
{ |
424
|
|
|
$html = ''; |
425
|
|
|
|
426
|
|
|
if ($project['priority_end'] != $project['priority_start']) { |
427
|
|
|
$html .= '<span class="task-board-priority" title="'.t('Task priority').'">'; |
428
|
|
|
$html .= $task['priority'] = t('P'.$task['priority']); |
429
|
|
|
$html .= '</span>'; |
430
|
|
|
} |
431
|
|
|
|
432
|
|
|
return $html; |
433
|
|
|
} |
434
|
|
|
|
435
|
|
|
/** |
436
|
|
|
* Returns the task progress. |
437
|
|
|
* |
438
|
|
|
* @param array $task |
439
|
|
|
* |
440
|
|
|
* @return int |
441
|
|
|
*/ |
442
|
|
|
public function getProgress($task) |
443
|
|
|
{ |
444
|
|
View Code Duplication |
if (!isset($this->columns[$task['project_id']])) { |
|
|
|
|
445
|
|
|
$this->columns[$task['project_id']] = $this->columnModel->getList($task['project_id']); |
|
|
|
|
446
|
|
|
} |
447
|
|
|
|
448
|
|
|
return $this->taskModel->getProgress($task, $this->columns[$task['project_id']]); |
|
|
|
|
449
|
|
|
} |
450
|
|
|
} |
451
|
|
|
|
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.