|
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
|
|
|
use Jitamin\Foundation\Security\Role; |
|
16
|
|
|
use Jitamin\Foundation\Security\Token; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* Project model. |
|
20
|
|
|
*/ |
|
21
|
|
|
class ProjectModel extends Model |
|
22
|
|
|
{ |
|
23
|
|
|
/** |
|
24
|
|
|
* SQL table name for projects. |
|
25
|
|
|
* |
|
26
|
|
|
* @var string |
|
27
|
|
|
*/ |
|
28
|
|
|
const TABLE = 'projects'; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* Value for active project. |
|
32
|
|
|
* |
|
33
|
|
|
* @var int |
|
34
|
|
|
*/ |
|
35
|
|
|
const ACTIVE = 1; |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* Value for inactive project. |
|
39
|
|
|
* |
|
40
|
|
|
* @var int |
|
41
|
|
|
*/ |
|
42
|
|
|
const INACTIVE = 0; |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* Value for private project. |
|
46
|
|
|
* |
|
47
|
|
|
* @var int |
|
48
|
|
|
*/ |
|
49
|
|
|
const TYPE_PRIVATE = 1; |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* Value for team project. |
|
53
|
|
|
* |
|
54
|
|
|
* @var int |
|
55
|
|
|
*/ |
|
56
|
|
|
const TYPE_TEAM = 0; |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* Get a project by the id. |
|
60
|
|
|
* |
|
61
|
|
|
* @param int $project_id Project id |
|
62
|
|
|
* |
|
63
|
|
|
* @return array |
|
64
|
|
|
*/ |
|
65
|
|
|
public function getById($project_id) |
|
66
|
|
|
{ |
|
67
|
|
|
return $this->db->table(self::TABLE)->eq('id', $project_id)->findOne(); |
|
|
|
|
|
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* Get a project by id with owner name. |
|
72
|
|
|
* |
|
73
|
|
|
* @param int $project_id Project id |
|
74
|
|
|
* |
|
75
|
|
|
* @return array |
|
76
|
|
|
*/ |
|
77
|
|
View Code Duplication |
public function getByIdWithOwner($project_id) |
|
|
|
|
|
|
78
|
|
|
{ |
|
79
|
|
|
return $this->db->table(self::TABLE) |
|
|
|
|
|
|
80
|
|
|
->columns(self::TABLE.'.*', UserModel::TABLE.'.username AS owner_username', UserModel::TABLE.'.name AS owner_name') |
|
81
|
|
|
->eq(self::TABLE.'.id', $project_id) |
|
82
|
|
|
->join(UserModel::TABLE, 'id', 'owner_id') |
|
83
|
|
|
->findOne(); |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
/** |
|
87
|
|
|
* Get a project by the name. |
|
88
|
|
|
* |
|
89
|
|
|
* @param string $name Project name |
|
90
|
|
|
* |
|
91
|
|
|
* @return array |
|
92
|
|
|
*/ |
|
93
|
|
|
public function getByName($name) |
|
94
|
|
|
{ |
|
95
|
|
|
return $this->db->table(self::TABLE)->eq('name', $name)->findOne(); |
|
|
|
|
|
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
/** |
|
99
|
|
|
* Get a project by the identifier (code). |
|
100
|
|
|
* |
|
101
|
|
|
* @param string $identifier |
|
102
|
|
|
* |
|
103
|
|
|
* @return array|bool |
|
104
|
|
|
*/ |
|
105
|
|
|
public function getByIdentifier($identifier) |
|
106
|
|
|
{ |
|
107
|
|
|
if (empty($identifier)) { |
|
108
|
|
|
return false; |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
return $this->db->table(self::TABLE)->eq('identifier', strtoupper($identifier))->findOne(); |
|
|
|
|
|
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
/** |
|
115
|
|
|
* Fetch project data by using the token. |
|
116
|
|
|
* |
|
117
|
|
|
* @param string $token Token |
|
118
|
|
|
* |
|
119
|
|
|
* @return array|bool |
|
120
|
|
|
*/ |
|
121
|
|
View Code Duplication |
public function getByToken($token) |
|
|
|
|
|
|
122
|
|
|
{ |
|
123
|
|
|
if (empty($token)) { |
|
124
|
|
|
return false; |
|
125
|
|
|
} |
|
126
|
|
|
|
|
127
|
|
|
return $this->db->table(self::TABLE)->eq('token', $token)->eq('is_public', 1)->findOne(); |
|
|
|
|
|
|
128
|
|
|
} |
|
129
|
|
|
|
|
130
|
|
|
/** |
|
131
|
|
|
* Return the first project from the database (no sorting). |
|
132
|
|
|
* |
|
133
|
|
|
* @return array |
|
134
|
|
|
*/ |
|
135
|
|
|
public function getFirst() |
|
136
|
|
|
{ |
|
137
|
|
|
return $this->db->table(self::TABLE)->findOne(); |
|
|
|
|
|
|
138
|
|
|
} |
|
139
|
|
|
|
|
140
|
|
|
/** |
|
141
|
|
|
* Return true if the project is private. |
|
142
|
|
|
* |
|
143
|
|
|
* @param int $project_id Project id |
|
144
|
|
|
* |
|
145
|
|
|
* @return bool |
|
146
|
|
|
*/ |
|
147
|
|
|
public function isPrivate($project_id) |
|
148
|
|
|
{ |
|
149
|
|
|
return $this->db->table(self::TABLE)->eq('id', $project_id)->eq('is_private', 1)->exists(); |
|
|
|
|
|
|
150
|
|
|
} |
|
151
|
|
|
|
|
152
|
|
|
/** |
|
153
|
|
|
* Get all projects. |
|
154
|
|
|
* |
|
155
|
|
|
* @return array |
|
156
|
|
|
*/ |
|
157
|
|
|
public function getAll() |
|
158
|
|
|
{ |
|
159
|
|
|
return $this->db->table(self::TABLE)->asc('name')->findAll(); |
|
|
|
|
|
|
160
|
|
|
} |
|
161
|
|
|
|
|
162
|
|
|
/** |
|
163
|
|
|
* Get all projects with given Ids. |
|
164
|
|
|
* |
|
165
|
|
|
* @param int[] $project_ids |
|
166
|
|
|
* |
|
167
|
|
|
* @return array |
|
168
|
|
|
*/ |
|
169
|
|
|
public function getAllByIds(array $project_ids) |
|
170
|
|
|
{ |
|
171
|
|
|
if (empty($project_ids)) { |
|
172
|
|
|
return []; |
|
173
|
|
|
} |
|
174
|
|
|
|
|
175
|
|
|
return $this->db->table(self::TABLE)->in('id', $project_ids)->asc('name')->findAll(); |
|
|
|
|
|
|
176
|
|
|
} |
|
177
|
|
|
|
|
178
|
|
|
/** |
|
179
|
|
|
* Get all project ids. |
|
180
|
|
|
* |
|
181
|
|
|
* @return array |
|
182
|
|
|
*/ |
|
183
|
|
|
public function getAllIds() |
|
184
|
|
|
{ |
|
185
|
|
|
return $this->db->table(self::TABLE)->asc('name')->findAllByColumn('id'); |
|
|
|
|
|
|
186
|
|
|
} |
|
187
|
|
|
|
|
188
|
|
|
/** |
|
189
|
|
|
* Return the list of all projects. |
|
190
|
|
|
* |
|
191
|
|
|
* @param bool $prepend If true, prepend to the list the value 'None' |
|
192
|
|
|
* |
|
193
|
|
|
* @return array |
|
194
|
|
|
*/ |
|
195
|
|
|
public function getList($prepend = true) |
|
196
|
|
|
{ |
|
197
|
|
|
if ($prepend) { |
|
198
|
|
|
return [t('None')] + $this->db->hashtable(self::TABLE)->asc('name')->getAll('id', 'name'); |
|
|
|
|
|
|
199
|
|
|
} |
|
200
|
|
|
|
|
201
|
|
|
return $this->db->hashtable(self::TABLE)->asc('name')->getAll('id', 'name'); |
|
|
|
|
|
|
202
|
|
|
} |
|
203
|
|
|
|
|
204
|
|
|
/** |
|
205
|
|
|
* Get all projects with all its data for a given status. |
|
206
|
|
|
* |
|
207
|
|
|
* @param int $status Project status: self::ACTIVE or self:INACTIVE |
|
208
|
|
|
* |
|
209
|
|
|
* @return array |
|
210
|
|
|
*/ |
|
211
|
|
|
public function getAllByStatus($status) |
|
212
|
|
|
{ |
|
213
|
|
|
return $this->db |
|
|
|
|
|
|
214
|
|
|
->table(self::TABLE) |
|
215
|
|
|
->asc('name') |
|
216
|
|
|
->eq('is_active', $status) |
|
217
|
|
|
->findAll(); |
|
218
|
|
|
} |
|
219
|
|
|
|
|
220
|
|
|
/** |
|
221
|
|
|
* Get a list of project by status. |
|
222
|
|
|
* |
|
223
|
|
|
* @param int $status Project status: self::ACTIVE or self:INACTIVE |
|
224
|
|
|
* |
|
225
|
|
|
* @return array |
|
226
|
|
|
*/ |
|
227
|
|
|
public function getListByStatus($status) |
|
228
|
|
|
{ |
|
229
|
|
|
return $this->db |
|
|
|
|
|
|
230
|
|
|
->hashtable(self::TABLE) |
|
231
|
|
|
->asc('name') |
|
232
|
|
|
->eq('is_active', $status) |
|
233
|
|
|
->getAll('id', 'name'); |
|
234
|
|
|
} |
|
235
|
|
|
|
|
236
|
|
|
/** |
|
237
|
|
|
* Return the number of projects by status. |
|
238
|
|
|
* |
|
239
|
|
|
* @param int $status Status: self::ACTIVE or self:INACTIVE |
|
240
|
|
|
* |
|
241
|
|
|
* @return int |
|
242
|
|
|
*/ |
|
243
|
|
|
public function countByStatus($status) |
|
244
|
|
|
{ |
|
245
|
|
|
return $this->db |
|
|
|
|
|
|
246
|
|
|
->table(self::TABLE) |
|
247
|
|
|
->eq('is_active', $status) |
|
248
|
|
|
->count(); |
|
249
|
|
|
} |
|
250
|
|
|
|
|
251
|
|
|
/** |
|
252
|
|
|
* Gather some task metrics for a given project. |
|
253
|
|
|
* |
|
254
|
|
|
* @param int $project_id Project id |
|
255
|
|
|
* |
|
256
|
|
|
* @return array |
|
257
|
|
|
*/ |
|
258
|
|
|
public function getTaskStats($project_id) |
|
259
|
|
|
{ |
|
260
|
|
|
$stats = []; |
|
261
|
|
|
$stats['nb_active_tasks'] = 0; |
|
262
|
|
|
$columns = $this->columnModel->getAll($project_id); |
|
|
|
|
|
|
263
|
|
|
$column_stats = $this->boardModel->getColumnStats($project_id); |
|
|
|
|
|
|
264
|
|
|
|
|
265
|
|
View Code Duplication |
foreach ($columns as &$column) { |
|
|
|
|
|
|
266
|
|
|
$column['nb_active_tasks'] = isset($column_stats[$column['id']]) ? $column_stats[$column['id']] : 0; |
|
267
|
|
|
$stats['nb_active_tasks'] += $column['nb_active_tasks']; |
|
268
|
|
|
} |
|
269
|
|
|
|
|
270
|
|
|
$stats['columns'] = $columns; |
|
271
|
|
|
$stats['nb_tasks'] = $this->taskFinderModel->countByProjectId($project_id); |
|
|
|
|
|
|
272
|
|
|
$stats['nb_inactive_tasks'] = $stats['nb_tasks'] - $stats['nb_active_tasks']; |
|
273
|
|
|
|
|
274
|
|
|
return $stats; |
|
275
|
|
|
} |
|
276
|
|
|
|
|
277
|
|
|
/** |
|
278
|
|
|
* Get stats for each column of a project. |
|
279
|
|
|
* |
|
280
|
|
|
* @param array $project |
|
281
|
|
|
* |
|
282
|
|
|
* @return array |
|
283
|
|
|
*/ |
|
284
|
|
|
public function getColumnStats(array &$project) |
|
285
|
|
|
{ |
|
286
|
|
|
$project['columns'] = $this->columnModel->getAll($project['id']); |
|
|
|
|
|
|
287
|
|
|
$project['nb_active_tasks'] = 0; |
|
288
|
|
|
$stats = $this->boardModel->getColumnStats($project['id']); |
|
|
|
|
|
|
289
|
|
|
|
|
290
|
|
View Code Duplication |
foreach ($project['columns'] as &$column) { |
|
|
|
|
|
|
291
|
|
|
$column['nb_tasks'] = isset($stats[$column['id']]) ? $stats[$column['id']] : 0; |
|
292
|
|
|
$project['nb_active_tasks'] += $column['nb_tasks']; |
|
293
|
|
|
} |
|
294
|
|
|
|
|
295
|
|
|
return $project; |
|
296
|
|
|
} |
|
297
|
|
|
|
|
298
|
|
|
/** |
|
299
|
|
|
* Apply column stats to a collection of projects (filter callback). |
|
300
|
|
|
* |
|
301
|
|
|
* @param array $projects |
|
302
|
|
|
* |
|
303
|
|
|
* @return array |
|
304
|
|
|
*/ |
|
305
|
|
|
public function applyColumnStats(array $projects) |
|
306
|
|
|
{ |
|
307
|
|
|
foreach ($projects as &$project) { |
|
308
|
|
|
$this->getColumnStats($project); |
|
309
|
|
|
} |
|
310
|
|
|
|
|
311
|
|
|
return $projects; |
|
312
|
|
|
} |
|
313
|
|
|
|
|
314
|
|
|
/** |
|
315
|
|
|
* Get project summary for a list of project. |
|
316
|
|
|
* |
|
317
|
|
|
* @param array $project_ids List of project id |
|
318
|
|
|
* |
|
319
|
|
|
* @return \PicoDb\Table |
|
320
|
|
|
*/ |
|
321
|
|
|
public function getQueryColumnStats(array $project_ids) |
|
322
|
|
|
{ |
|
323
|
|
|
if (empty($project_ids)) { |
|
324
|
|
|
return $this->db->table(self::TABLE)->eq(self::TABLE.'.id', 0); |
|
|
|
|
|
|
325
|
|
|
} |
|
326
|
|
|
|
|
327
|
|
|
return $this->db |
|
|
|
|
|
|
328
|
|
|
->table(self::TABLE) |
|
329
|
|
|
->columns(self::TABLE.'.*', UserModel::TABLE.'.username AS owner_username', UserModel::TABLE.'.name AS owner_name') |
|
330
|
|
|
->join(UserModel::TABLE, 'id', 'owner_id') |
|
331
|
|
|
->in(self::TABLE.'.id', $project_ids) |
|
332
|
|
|
->callback([$this, 'applyColumnStats']); |
|
333
|
|
|
} |
|
334
|
|
|
|
|
335
|
|
|
/** |
|
336
|
|
|
* Create a project. |
|
337
|
|
|
* |
|
338
|
|
|
* @param array $values Form values |
|
339
|
|
|
* @param int $user_id User who create the project |
|
340
|
|
|
* @param bool $add_user Automatically add the user |
|
341
|
|
|
* |
|
342
|
|
|
* @return int Project id |
|
343
|
|
|
*/ |
|
344
|
|
|
public function create(array $values, $user_id = 0, $add_user = false) |
|
345
|
|
|
{ |
|
346
|
|
|
$this->db->startTransaction(); |
|
|
|
|
|
|
347
|
|
|
|
|
348
|
|
|
$values['token'] = ''; |
|
349
|
|
|
$values['last_modified'] = time(); |
|
350
|
|
|
$values['is_private'] = empty($values['is_private']) ? 0 : 1; |
|
351
|
|
|
$values['owner_id'] = $user_id; |
|
352
|
|
|
|
|
353
|
|
|
if (!empty($values['identifier'])) { |
|
354
|
|
|
$values['identifier'] = strtoupper($values['identifier']); |
|
355
|
|
|
} |
|
356
|
|
|
|
|
357
|
|
|
$this->helper->model->convertIntegerFields($values, ['priority_default', 'priority_start', 'priority_end']); |
|
|
|
|
|
|
358
|
|
|
|
|
359
|
|
|
if (!$this->db->table(self::TABLE)->save($values)) { |
|
|
|
|
|
|
360
|
|
|
$this->db->cancelTransaction(); |
|
|
|
|
|
|
361
|
|
|
|
|
362
|
|
|
return false; |
|
363
|
|
|
} |
|
364
|
|
|
|
|
365
|
|
|
$project_id = $this->db->getLastId(); |
|
|
|
|
|
|
366
|
|
|
|
|
367
|
|
|
if (!$this->boardModel->create($project_id, $this->boardModel->getUserColumns())) { |
|
|
|
|
|
|
368
|
|
|
$this->db->cancelTransaction(); |
|
|
|
|
|
|
369
|
|
|
|
|
370
|
|
|
return false; |
|
371
|
|
|
} |
|
372
|
|
|
|
|
373
|
|
|
if ($add_user && $user_id) { |
|
374
|
|
|
$this->projectUserRoleModel->addUser($project_id, $user_id, Role::PROJECT_MANAGER); |
|
|
|
|
|
|
375
|
|
|
} |
|
376
|
|
|
|
|
377
|
|
|
$this->categoryModel->createDefaultCategories($project_id); |
|
|
|
|
|
|
378
|
|
|
|
|
379
|
|
|
$this->db->closeTransaction(); |
|
|
|
|
|
|
380
|
|
|
|
|
381
|
|
|
return (int) $project_id; |
|
382
|
|
|
} |
|
383
|
|
|
|
|
384
|
|
|
/** |
|
385
|
|
|
* Check if the project have been modified. |
|
386
|
|
|
* |
|
387
|
|
|
* @param int $project_id Project id |
|
388
|
|
|
* @param int $timestamp Timestamp |
|
389
|
|
|
* |
|
390
|
|
|
* @return bool |
|
391
|
|
|
*/ |
|
392
|
|
|
public function isModifiedSince($project_id, $timestamp) |
|
393
|
|
|
{ |
|
394
|
|
|
return (bool) $this->db->table(self::TABLE) |
|
|
|
|
|
|
395
|
|
|
->eq('id', $project_id) |
|
396
|
|
|
->gt('last_modified', $timestamp) |
|
397
|
|
|
->count(); |
|
398
|
|
|
} |
|
399
|
|
|
|
|
400
|
|
|
/** |
|
401
|
|
|
* Update modification date. |
|
402
|
|
|
* |
|
403
|
|
|
* @param int $project_id Project id |
|
404
|
|
|
* |
|
405
|
|
|
* @return bool |
|
406
|
|
|
*/ |
|
407
|
|
|
public function updateModificationDate($project_id) |
|
408
|
|
|
{ |
|
409
|
|
|
return $this->db->table(self::TABLE)->eq('id', $project_id)->update([ |
|
|
|
|
|
|
410
|
|
|
'last_modified' => time(), |
|
411
|
|
|
]); |
|
412
|
|
|
} |
|
413
|
|
|
|
|
414
|
|
|
/** |
|
415
|
|
|
* Update a project. |
|
416
|
|
|
* |
|
417
|
|
|
* @param array $values Form values |
|
418
|
|
|
* |
|
419
|
|
|
* @return bool |
|
420
|
|
|
*/ |
|
421
|
|
|
public function update(array $values) |
|
422
|
|
|
{ |
|
423
|
|
|
if (!empty($values['identifier'])) { |
|
424
|
|
|
$values['identifier'] = strtoupper($values['identifier']); |
|
425
|
|
|
} |
|
426
|
|
|
|
|
427
|
|
View Code Duplication |
if (!empty($values['start_date'])) { |
|
|
|
|
|
|
428
|
|
|
$values['start_date'] = $this->dateParser->getIsoDate($values['start_date']); |
|
|
|
|
|
|
429
|
|
|
} |
|
430
|
|
|
|
|
431
|
|
View Code Duplication |
if (!empty($values['end_date'])) { |
|
|
|
|
|
|
432
|
|
|
$values['end_date'] = $this->dateParser->getIsoDate($values['end_date']); |
|
|
|
|
|
|
433
|
|
|
} |
|
434
|
|
|
|
|
435
|
|
|
$this->helper->model->convertIntegerFields($values, ['priority_default', 'priority_start', 'priority_end']); |
|
|
|
|
|
|
436
|
|
|
|
|
437
|
|
|
return $this->exists($values['id']) && |
|
438
|
|
|
$this->db->table(self::TABLE)->eq('id', $values['id'])->save($values); |
|
|
|
|
|
|
439
|
|
|
} |
|
440
|
|
|
|
|
441
|
|
|
/** |
|
442
|
|
|
* Remove a project. |
|
443
|
|
|
* |
|
444
|
|
|
* @param int $project_id Project id |
|
445
|
|
|
* |
|
446
|
|
|
* @return bool |
|
447
|
|
|
*/ |
|
448
|
|
|
public function remove($project_id) |
|
449
|
|
|
{ |
|
450
|
|
|
return $this->db->table(self::TABLE)->eq('id', $project_id)->remove(); |
|
|
|
|
|
|
451
|
|
|
} |
|
452
|
|
|
|
|
453
|
|
|
/** |
|
454
|
|
|
* Return true if the project exists. |
|
455
|
|
|
* |
|
456
|
|
|
* @param int $project_id Project id |
|
457
|
|
|
* |
|
458
|
|
|
* @return bool |
|
459
|
|
|
*/ |
|
460
|
|
|
public function exists($project_id) |
|
461
|
|
|
{ |
|
462
|
|
|
return $this->db->table(self::TABLE)->eq('id', $project_id)->exists(); |
|
|
|
|
|
|
463
|
|
|
} |
|
464
|
|
|
|
|
465
|
|
|
/** |
|
466
|
|
|
* Enable a project. |
|
467
|
|
|
* |
|
468
|
|
|
* @param int $project_id Project id |
|
469
|
|
|
* |
|
470
|
|
|
* @return bool |
|
471
|
|
|
*/ |
|
472
|
|
View Code Duplication |
public function enable($project_id) |
|
|
|
|
|
|
473
|
|
|
{ |
|
474
|
|
|
return $this->exists($project_id) && |
|
475
|
|
|
$this->db |
|
|
|
|
|
|
476
|
|
|
->table(self::TABLE) |
|
477
|
|
|
->eq('id', $project_id) |
|
478
|
|
|
->update(['is_active' => 1]); |
|
479
|
|
|
} |
|
480
|
|
|
|
|
481
|
|
|
/** |
|
482
|
|
|
* Disable a project. |
|
483
|
|
|
* |
|
484
|
|
|
* @param int $project_id Project id |
|
485
|
|
|
* |
|
486
|
|
|
* @return bool |
|
487
|
|
|
*/ |
|
488
|
|
View Code Duplication |
public function disable($project_id) |
|
|
|
|
|
|
489
|
|
|
{ |
|
490
|
|
|
return $this->exists($project_id) && |
|
491
|
|
|
$this->db |
|
|
|
|
|
|
492
|
|
|
->table(self::TABLE) |
|
493
|
|
|
->eq('id', $project_id) |
|
494
|
|
|
->update(['is_active' => 0]); |
|
495
|
|
|
} |
|
496
|
|
|
|
|
497
|
|
|
/** |
|
498
|
|
|
* Enable public access for a project. |
|
499
|
|
|
* |
|
500
|
|
|
* @param int $project_id Project id |
|
501
|
|
|
* |
|
502
|
|
|
* @return bool |
|
503
|
|
|
*/ |
|
504
|
|
View Code Duplication |
public function enablePublicAccess($project_id) |
|
|
|
|
|
|
505
|
|
|
{ |
|
506
|
|
|
return $this->exists($project_id) && |
|
507
|
|
|
$this->db |
|
|
|
|
|
|
508
|
|
|
->table(self::TABLE) |
|
509
|
|
|
->eq('id', $project_id) |
|
510
|
|
|
->save(['is_public' => 1, 'token' => Token::getToken()]); |
|
511
|
|
|
} |
|
512
|
|
|
|
|
513
|
|
|
/** |
|
514
|
|
|
* Disable public access for a project. |
|
515
|
|
|
* |
|
516
|
|
|
* @param int $project_id Project id |
|
517
|
|
|
* |
|
518
|
|
|
* @return bool |
|
519
|
|
|
*/ |
|
520
|
|
View Code Duplication |
public function disablePublicAccess($project_id) |
|
|
|
|
|
|
521
|
|
|
{ |
|
522
|
|
|
return $this->exists($project_id) && |
|
523
|
|
|
$this->db |
|
|
|
|
|
|
524
|
|
|
->table(self::TABLE) |
|
525
|
|
|
->eq('id', $project_id) |
|
526
|
|
|
->save(['is_public' => 0, 'token' => '']); |
|
527
|
|
|
} |
|
528
|
|
|
|
|
529
|
|
|
/** |
|
530
|
|
|
* Get available views. |
|
531
|
|
|
* |
|
532
|
|
|
* @param bool $prepend Prepend a default value |
|
533
|
|
|
* |
|
534
|
|
|
* @return array |
|
535
|
|
|
*/ |
|
536
|
|
|
public function getViews($prepend = false) |
|
537
|
|
|
{ |
|
538
|
|
|
// Sorted by value |
|
539
|
|
|
$views = [ |
|
540
|
|
|
'overview' => t('Overview'), |
|
541
|
|
|
'board' => t('Board'), |
|
542
|
|
|
'calendar' => t('Calendar'), |
|
543
|
|
|
'list' => t('List'), |
|
544
|
|
|
'gantt' => t('Gantt'), |
|
545
|
|
|
]; |
|
546
|
|
|
|
|
547
|
|
|
if ($prepend) { |
|
548
|
|
|
return ['' => t('Use default view')] + $views; |
|
549
|
|
|
} |
|
550
|
|
|
|
|
551
|
|
|
return $views; |
|
552
|
|
|
} |
|
553
|
|
|
} |
|
554
|
|
|
|
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.