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
|
|
|
* Board model. |
18
|
|
|
*/ |
19
|
|
|
class BoardModel extends Model |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* Get Jitamin default columns. |
23
|
|
|
* |
24
|
|
|
* @return string[] |
25
|
|
|
*/ |
26
|
|
|
public function getDefaultColumns() |
27
|
|
|
{ |
28
|
|
|
return [t('Backlog'), t('Ready'), t('Work in progress'), t('Done')]; |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Get user default columns. |
33
|
|
|
* |
34
|
|
|
* @return array |
35
|
|
|
*/ |
36
|
|
|
public function getUserColumns() |
37
|
|
|
{ |
38
|
|
|
$column_names = explode(',', $this->settingModel->get('board_columns', implode(',', $this->getDefaultColumns()))); |
|
|
|
|
39
|
|
|
$columns = []; |
40
|
|
|
|
41
|
|
|
foreach ($column_names as $column_name) { |
42
|
|
|
$column_name = trim($column_name); |
43
|
|
|
|
44
|
|
|
if (!empty($column_name)) { |
45
|
|
|
$columns[] = ['title' => $column_name, 'task_limit' => 0, 'description' => '']; |
46
|
|
|
} |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
return $columns; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* Create a board with default columns, must be executed inside a transaction. |
54
|
|
|
* |
55
|
|
|
* @param int $project_id Project id |
56
|
|
|
* @param array $columns Column parameters [ 'title' => 'boo', 'task_limit' => 2 ... ] |
57
|
|
|
* |
58
|
|
|
* @return bool |
59
|
|
|
*/ |
60
|
|
|
public function create($project_id, array $columns) |
61
|
|
|
{ |
62
|
|
|
$position = 0; |
63
|
|
|
|
64
|
|
|
foreach ($columns as $column) { |
65
|
|
|
$values = [ |
66
|
|
|
'title' => $column['title'], |
67
|
|
|
'position' => ++$position, |
68
|
|
|
'project_id' => $project_id, |
69
|
|
|
'task_limit' => $column['task_limit'], |
70
|
|
|
'description' => $column['description'], |
71
|
|
|
]; |
72
|
|
|
|
73
|
|
|
if (!$this->db->table(ColumnModel::TABLE)->save($values)) { |
|
|
|
|
74
|
|
|
return false; |
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
return true; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* Copy board columns from a project to another one. |
83
|
|
|
* |
84
|
|
|
* @author Antonio Rabelo |
85
|
|
|
* |
86
|
|
|
* @param int $project_from Project Template |
87
|
|
|
* @param int $project_to Project that receives the copy |
88
|
|
|
* |
89
|
|
|
* @return bool |
90
|
|
|
*/ |
91
|
|
|
public function duplicate($project_from, $project_to) |
92
|
|
|
{ |
93
|
|
|
$columns = $this->db->table(ColumnModel::TABLE) |
|
|
|
|
94
|
|
|
->columns('title', 'task_limit', 'description') |
95
|
|
|
->eq('project_id', $project_from) |
96
|
|
|
->asc('position') |
97
|
|
|
->findAll(); |
98
|
|
|
|
99
|
|
|
return $this->boardModel->create($project_to, $columns); |
|
|
|
|
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* Get the total of tasks per column. |
104
|
|
|
* |
105
|
|
|
* @param int $project_id |
106
|
|
|
* @param bool $prepend Prepend default value |
107
|
|
|
* |
108
|
|
|
* @return array |
109
|
|
|
*/ |
110
|
|
|
public function getColumnStats($project_id, $prepend = false) |
111
|
|
|
{ |
112
|
|
|
$listing = $this->db |
|
|
|
|
113
|
|
|
->hashtable(TaskModel::TABLE) |
114
|
|
|
->eq('project_id', $project_id) |
115
|
|
|
->eq('is_active', 1) |
116
|
|
|
->groupBy('column_id') |
117
|
|
|
->getAll('column_id', 'COUNT(*) AS total'); |
118
|
|
|
|
119
|
|
|
return $prepend ? [-1 => t('All columns')] + $listing : $listing; |
120
|
|
|
} |
121
|
|
|
} |
122
|
|
|
|
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.