|
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\Model; |
|
13
|
|
|
|
|
14
|
|
|
use Jitamin\Foundation\Database\Model; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* Transition. |
|
18
|
|
|
*/ |
|
19
|
|
|
class TransitionModel extends Model |
|
20
|
|
|
{ |
|
21
|
|
|
/** |
|
22
|
|
|
* SQL table name. |
|
23
|
|
|
* |
|
24
|
|
|
* @var string |
|
25
|
|
|
*/ |
|
26
|
|
|
const TABLE = 'transitions'; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* Save transition event. |
|
30
|
|
|
* |
|
31
|
|
|
* @param int $user_id |
|
32
|
|
|
* @param array $task_event |
|
33
|
|
|
* |
|
34
|
|
|
* @return bool |
|
35
|
|
|
*/ |
|
36
|
|
|
public function save($user_id, array $task_event) |
|
37
|
|
|
{ |
|
38
|
|
|
$time = time(); |
|
39
|
|
|
|
|
40
|
|
|
return $this->db->table(self::TABLE)->insert([ |
|
|
|
|
|
|
41
|
|
|
'user_id' => $user_id, |
|
42
|
|
|
'project_id' => $task_event['project_id'], |
|
43
|
|
|
'task_id' => $task_event['task_id'], |
|
44
|
|
|
'src_column_id' => $task_event['src_column_id'], |
|
45
|
|
|
'dst_column_id' => $task_event['dst_column_id'], |
|
46
|
|
|
'date' => $time, |
|
47
|
|
|
'time_spent' => $time - $task_event['date_moved'], |
|
48
|
|
|
]); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* Get time spent by task for each column. |
|
53
|
|
|
* |
|
54
|
|
|
* @param int $task_id |
|
55
|
|
|
* |
|
56
|
|
|
* @return array |
|
57
|
|
|
*/ |
|
58
|
|
|
public function getTimeSpentByTask($task_id) |
|
59
|
|
|
{ |
|
60
|
|
|
return $this->db |
|
|
|
|
|
|
61
|
|
|
->hashtable(self::TABLE) |
|
62
|
|
|
->groupBy('src_column_id') |
|
63
|
|
|
->eq('task_id', $task_id) |
|
64
|
|
|
->getAll('src_column_id', 'SUM(time_spent) AS time_spent'); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* Get all transitions by task. |
|
69
|
|
|
* |
|
70
|
|
|
* @param int $task_id |
|
71
|
|
|
* |
|
72
|
|
|
* @return array |
|
73
|
|
|
*/ |
|
74
|
|
|
public function getAllByTask($task_id) |
|
75
|
|
|
{ |
|
76
|
|
|
return $this->db->table(self::TABLE) |
|
|
|
|
|
|
77
|
|
|
->columns( |
|
78
|
|
|
'src.title as src_column', |
|
79
|
|
|
'dst.title as dst_column', |
|
80
|
|
|
UserModel::TABLE.'.name', |
|
81
|
|
|
UserModel::TABLE.'.username', |
|
82
|
|
|
self::TABLE.'.user_id', |
|
83
|
|
|
self::TABLE.'.date', |
|
84
|
|
|
self::TABLE.'.time_spent' |
|
85
|
|
|
) |
|
86
|
|
|
->eq('task_id', $task_id) |
|
87
|
|
|
->desc('date') |
|
88
|
|
|
->join(UserModel::TABLE, 'id', 'user_id') |
|
89
|
|
|
->join(ColumnModel::TABLE.' as src', 'id', 'src_column_id', self::TABLE, 'src') |
|
90
|
|
|
->join(ColumnModel::TABLE.' as dst', 'id', 'dst_column_id', self::TABLE, 'dst') |
|
91
|
|
|
->findAll(); |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
/** |
|
95
|
|
|
* Get all transitions by project. |
|
96
|
|
|
* |
|
97
|
|
|
* @param int $project_id |
|
98
|
|
|
* @param mixed $from Start date (timestamp or user formatted date) |
|
99
|
|
|
* @param mixed $to End date (timestamp or user formatted date) |
|
100
|
|
|
* |
|
101
|
|
|
* @return array |
|
102
|
|
|
*/ |
|
103
|
|
|
public function getAllByProjectAndDate($project_id, $from, $to) |
|
104
|
|
|
{ |
|
105
|
|
|
if (!is_numeric($from)) { |
|
106
|
|
|
$from = $this->dateParser->removeTimeFromTimestamp($this->dateParser->getTimestamp($from)); |
|
|
|
|
|
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
View Code Duplication |
if (!is_numeric($to)) { |
|
|
|
|
|
|
110
|
|
|
$to = $this->dateParser->removeTimeFromTimestamp(strtotime('+1 day', $this->dateParser->getTimestamp($to))); |
|
|
|
|
|
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
return $this->db->table(self::TABLE) |
|
|
|
|
|
|
114
|
|
|
->columns( |
|
115
|
|
|
TaskModel::TABLE.'.id', |
|
116
|
|
|
TaskModel::TABLE.'.title', |
|
117
|
|
|
'src.title as src_column', |
|
118
|
|
|
'dst.title as dst_column', |
|
119
|
|
|
UserModel::TABLE.'.name', |
|
120
|
|
|
UserModel::TABLE.'.username', |
|
121
|
|
|
self::TABLE.'.user_id', |
|
122
|
|
|
self::TABLE.'.date', |
|
123
|
|
|
self::TABLE.'.time_spent' |
|
124
|
|
|
) |
|
125
|
|
|
->gte('date', $from) |
|
126
|
|
|
->lte('date', $to) |
|
127
|
|
|
->eq(self::TABLE.'.project_id', $project_id) |
|
128
|
|
|
->desc('date') |
|
129
|
|
|
->desc(self::TABLE.'.id') |
|
130
|
|
|
->join(TaskModel::TABLE, 'id', 'task_id') |
|
131
|
|
|
->join(UserModel::TABLE, 'id', 'user_id') |
|
132
|
|
|
->join(ColumnModel::TABLE.' as src', 'id', 'src_column_id', self::TABLE, 'src') |
|
133
|
|
|
->join(ColumnModel::TABLE.' as dst', 'id', 'dst_column_id', self::TABLE, 'dst') |
|
134
|
|
|
->findAll(); |
|
135
|
|
|
} |
|
136
|
|
|
} |
|
137
|
|
|
|
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@propertyannotation 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.