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 SubtaskStatusModel. |
18
|
|
|
*/ |
19
|
|
|
class SubtaskStatusModel extends Model |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* Get the subtask in progress for this user. |
23
|
|
|
* |
24
|
|
|
* @param int $user_id |
25
|
|
|
* |
26
|
|
|
* @return array |
27
|
|
|
*/ |
28
|
|
|
public function getSubtaskInProgress($user_id) |
29
|
|
|
{ |
30
|
|
|
return $this->db->table(SubtaskModel::TABLE) |
|
|
|
|
31
|
|
|
->eq('status', SubtaskModel::STATUS_INPROGRESS) |
32
|
|
|
->eq('user_id', $user_id) |
33
|
|
|
->findOne(); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Return true if the user have a subtask in progress. |
38
|
|
|
* |
39
|
|
|
* @param int $user_id |
40
|
|
|
* |
41
|
|
|
* @return bool |
42
|
|
|
*/ |
43
|
|
|
public function hasSubtaskInProgress($user_id) |
44
|
|
|
{ |
45
|
|
|
return $this->settingModel->get('subtask_restriction') == 1 && |
|
|
|
|
46
|
|
|
$this->db->table(SubtaskModel::TABLE) |
|
|
|
|
47
|
|
|
->eq('status', SubtaskModel::STATUS_INPROGRESS) |
48
|
|
|
->eq('user_id', $user_id) |
49
|
|
|
->exists(); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* Change the status of subtask. |
54
|
|
|
* |
55
|
|
|
* @param int $subtask_id |
56
|
|
|
* |
57
|
|
|
* @return bool|int |
58
|
|
|
*/ |
59
|
|
|
public function toggleStatus($subtask_id) |
60
|
|
|
{ |
61
|
|
|
$subtask = $this->subtaskModel->getById($subtask_id); |
|
|
|
|
62
|
|
|
$status = ($subtask['status'] + 1) % 3; |
63
|
|
|
|
64
|
|
|
$values = [ |
65
|
|
|
'id' => $subtask['id'], |
66
|
|
|
'status' => $status, |
67
|
|
|
'task_id' => $subtask['task_id'], |
68
|
|
|
]; |
69
|
|
|
|
70
|
|
|
if (empty($subtask['user_id']) && $this->userSession->isLogged()) { |
|
|
|
|
71
|
|
|
$values['user_id'] = $this->userSession->getId(); |
|
|
|
|
72
|
|
|
$subtask['user_id'] = $values['user_id']; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
$this->subtaskTimeTrackingModel->toggleTimer($subtask_id, $subtask['user_id'], $status); |
|
|
|
|
76
|
|
|
|
77
|
|
|
return $this->subtaskModel->update($values) ? $status : false; |
|
|
|
|
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* Close all subtasks of a task. |
82
|
|
|
* |
83
|
|
|
* @param int $task_id |
84
|
|
|
* |
85
|
|
|
* @return bool |
86
|
|
|
*/ |
87
|
|
|
public function closeAll($task_id) |
88
|
|
|
{ |
89
|
|
|
return $this->db |
|
|
|
|
90
|
|
|
->table(SubtaskModel::TABLE) |
91
|
|
|
->eq('task_id', $task_id) |
92
|
|
|
->update(['status' => SubtaskModel::STATUS_DONE]); |
93
|
|
|
} |
94
|
|
|
} |
95
|
|
|
|
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.