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\Action; |
13
|
|
|
|
14
|
|
|
use Jitamin\Model\TaskModel; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Close automatically in a defined column after a certain amount of time. |
18
|
|
|
*/ |
19
|
|
View Code Duplication |
class TaskCloseNotMovedColumn extends Base |
|
|
|
|
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* Get automatic action description. |
23
|
|
|
* |
24
|
|
|
* @return string |
25
|
|
|
*/ |
26
|
|
|
public function getDescription() |
27
|
|
|
{ |
28
|
|
|
return t('Close a task in a specific column when not moved during a given period'); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Get the list of compatible events. |
33
|
|
|
* |
34
|
|
|
* @return array |
35
|
|
|
*/ |
36
|
|
|
public function getCompatibleEvents() |
37
|
|
|
{ |
38
|
|
|
return [TaskModel::EVENT_DAILY_CRONJOB]; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Get the required parameter for the action (defined by the user). |
43
|
|
|
* |
44
|
|
|
* @return array |
45
|
|
|
*/ |
46
|
|
|
public function getActionRequiredParameters() |
47
|
|
|
{ |
48
|
|
|
return [ |
49
|
|
|
'duration' => t('Duration in days'), |
50
|
|
|
'column_id' => t('Column'), |
51
|
|
|
]; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Get the required parameter for the event. |
56
|
|
|
* |
57
|
|
|
* @return string[] |
58
|
|
|
*/ |
59
|
|
|
public function getEventRequiredParameters() |
60
|
|
|
{ |
61
|
|
|
return ['tasks']; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Execute the action (close the task). |
66
|
|
|
* |
67
|
|
|
* @param array $data Event data dictionary |
68
|
|
|
* |
69
|
|
|
* @return bool True if the action was executed or false when not executed |
70
|
|
|
*/ |
71
|
|
|
public function doAction(array $data) |
72
|
|
|
{ |
73
|
|
|
$results = []; |
74
|
|
|
$max = $this->getParam('duration') * 86400; |
75
|
|
|
|
76
|
|
|
foreach ($data['tasks'] as $task) { |
77
|
|
|
$duration = time() - $task['date_moved']; |
78
|
|
|
|
79
|
|
|
if ($duration > $max && $task['column_id'] == $this->getParam('column_id')) { |
80
|
|
|
$results[] = $this->taskStatusModel->close($task['id']); |
|
|
|
|
81
|
|
|
} |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
return in_array(true, $results, true); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* Check if the event data meet the action condition. |
89
|
|
|
* |
90
|
|
|
* @param array $data Event data dictionary |
91
|
|
|
* |
92
|
|
|
* @return bool |
93
|
|
|
*/ |
94
|
|
|
public function hasRequiredCondition(array $data) |
95
|
|
|
{ |
96
|
|
|
return count($data['tasks']) > 0; |
97
|
|
|
} |
98
|
|
|
} |
99
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.