|
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
|
|
|
* Class ColumnMoveRestrictionModel. |
|
18
|
|
|
*/ |
|
19
|
|
|
class ColumnMoveRestrictionModel extends Model |
|
20
|
|
|
{ |
|
21
|
|
|
/** |
|
22
|
|
|
* SQL table name. |
|
23
|
|
|
* |
|
24
|
|
|
* @var string |
|
25
|
|
|
*/ |
|
26
|
|
|
const TABLE = 'column_has_move_restrictions'; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* Fetch one restriction. |
|
30
|
|
|
* |
|
31
|
|
|
* @param int $project_id |
|
32
|
|
|
* @param int $restriction_id |
|
33
|
|
|
* |
|
34
|
|
|
* @return array|null |
|
35
|
|
|
*/ |
|
36
|
|
View Code Duplication |
public function getById($project_id, $restriction_id) |
|
|
|
|
|
|
37
|
|
|
{ |
|
38
|
|
|
return $this->db |
|
|
|
|
|
|
39
|
|
|
->table(self::TABLE) |
|
40
|
|
|
->columns( |
|
41
|
|
|
self::TABLE.'.restriction_id', |
|
42
|
|
|
self::TABLE.'.project_id', |
|
43
|
|
|
self::TABLE.'.role_id', |
|
44
|
|
|
self::TABLE.'.src_column_id', |
|
45
|
|
|
self::TABLE.'.dst_column_id', |
|
46
|
|
|
'pr.role', |
|
47
|
|
|
'sc.title as src_column_title', |
|
48
|
|
|
'dc.title as dst_column_title' |
|
49
|
|
|
) |
|
50
|
|
|
->left(ColumnModel::TABLE, 'sc', 'id', self::TABLE, 'src_column_id') |
|
51
|
|
|
->left(ColumnModel::TABLE, 'dc', 'id', self::TABLE, 'dst_column_id') |
|
52
|
|
|
->left(ProjectRoleModel::TABLE, 'pr', 'role_id', self::TABLE, 'role_id') |
|
53
|
|
|
->eq(self::TABLE.'.project_id', $project_id) |
|
54
|
|
|
->eq(self::TABLE.'.restriction_id', $restriction_id) |
|
55
|
|
|
->findOne(); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* Get all project column restrictions. |
|
60
|
|
|
* |
|
61
|
|
|
* @param int $project_id |
|
62
|
|
|
* |
|
63
|
|
|
* @return array |
|
64
|
|
|
*/ |
|
65
|
|
View Code Duplication |
public function getAll($project_id) |
|
|
|
|
|
|
66
|
|
|
{ |
|
67
|
|
|
return $this->db |
|
|
|
|
|
|
68
|
|
|
->table(self::TABLE) |
|
69
|
|
|
->columns( |
|
70
|
|
|
self::TABLE.'.restriction_id', |
|
71
|
|
|
self::TABLE.'.project_id', |
|
72
|
|
|
self::TABLE.'.role_id', |
|
73
|
|
|
self::TABLE.'.src_column_id', |
|
74
|
|
|
self::TABLE.'.dst_column_id', |
|
75
|
|
|
'pr.role', |
|
76
|
|
|
'sc.title as src_column_title', |
|
77
|
|
|
'dc.title as dst_column_title' |
|
78
|
|
|
) |
|
79
|
|
|
->left(ColumnModel::TABLE, 'sc', 'id', self::TABLE, 'src_column_id') |
|
80
|
|
|
->left(ColumnModel::TABLE, 'dc', 'id', self::TABLE, 'dst_column_id') |
|
81
|
|
|
->left(ProjectRoleModel::TABLE, 'pr', 'role_id', self::TABLE, 'role_id') |
|
82
|
|
|
->eq(self::TABLE.'.project_id', $project_id) |
|
83
|
|
|
->findAll(); |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
/** |
|
87
|
|
|
* Get all sortable column Ids. |
|
88
|
|
|
* |
|
89
|
|
|
* @param int $project_id |
|
90
|
|
|
* @param string $role |
|
91
|
|
|
* |
|
92
|
|
|
* @return array |
|
93
|
|
|
*/ |
|
94
|
|
|
public function getSortableColumns($project_id, $role) |
|
95
|
|
|
{ |
|
96
|
|
|
return $this->db |
|
|
|
|
|
|
97
|
|
|
->table(self::TABLE) |
|
98
|
|
|
->columns(self::TABLE.'.src_column_id', self::TABLE.'.dst_column_id') |
|
99
|
|
|
->left(ProjectRoleModel::TABLE, 'pr', 'role_id', self::TABLE, 'role_id') |
|
100
|
|
|
->eq(self::TABLE.'.project_id', $project_id) |
|
101
|
|
|
->eq('pr.role', $role) |
|
102
|
|
|
->findAll(); |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
/** |
|
106
|
|
|
* Create a new column restriction. |
|
107
|
|
|
* |
|
108
|
|
|
* @param int $project_id |
|
109
|
|
|
* @param int $role_id |
|
110
|
|
|
* @param int $src_column_id |
|
111
|
|
|
* @param int $dst_column_id |
|
112
|
|
|
* |
|
113
|
|
|
* @return bool|int |
|
114
|
|
|
*/ |
|
115
|
|
|
public function create($project_id, $role_id, $src_column_id, $dst_column_id) |
|
116
|
|
|
{ |
|
117
|
|
|
return $this->db |
|
|
|
|
|
|
118
|
|
|
->table(self::TABLE) |
|
119
|
|
|
->persist([ |
|
120
|
|
|
'project_id' => $project_id, |
|
121
|
|
|
'role_id' => $role_id, |
|
122
|
|
|
'src_column_id' => $src_column_id, |
|
123
|
|
|
'dst_column_id' => $dst_column_id, |
|
124
|
|
|
]); |
|
125
|
|
|
} |
|
126
|
|
|
|
|
127
|
|
|
/** |
|
128
|
|
|
* Remove a permission. |
|
129
|
|
|
* |
|
130
|
|
|
* @param int $restriction_id |
|
131
|
|
|
* |
|
132
|
|
|
* @return bool |
|
133
|
|
|
*/ |
|
134
|
|
|
public function remove($restriction_id) |
|
135
|
|
|
{ |
|
136
|
|
|
return $this->db->table(self::TABLE)->eq('restriction_id', $restriction_id)->remove(); |
|
|
|
|
|
|
137
|
|
|
} |
|
138
|
|
|
} |
|
139
|
|
|
|
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.