1 | <?php |
||
13 | class Project extends Model |
||
14 | { |
||
15 | use HasUsers, HasStatus; |
||
16 | |||
17 | protected $table = 'projects'; |
||
18 | |||
19 | public $primaryKey = 'id'; |
||
20 | |||
21 | public $guarded = ['id']; |
||
22 | |||
23 | public $timestamps = true; |
||
24 | |||
25 | protected $dates = [ |
||
26 | 'started_at', |
||
27 | 'delivered_at', |
||
28 | 'expected_at', |
||
29 | ]; |
||
30 | |||
31 | protected $casts = [ |
||
32 | 'visible' => 'bool', |
||
33 | ]; |
||
34 | |||
35 | public function __construct(array $attributes = []) |
||
36 | { |
||
37 | parent::__construct($attributes); |
||
38 | } |
||
39 | |||
40 | public function owner() : BelongsTo |
||
41 | { |
||
42 | return $this->belongsTo(get_class(user_model())); |
||
43 | } |
||
44 | |||
45 | public function status() : BelongsTo |
||
46 | { |
||
47 | return $this->belongsTo(Status::class); |
||
48 | } |
||
49 | |||
50 | public function tasks() : MorphToMany |
||
51 | { |
||
52 | return $this->morphedByMany(Task::class, 'projectable'); |
||
53 | } |
||
54 | |||
55 | public function isVisible() : bool |
||
59 | |||
60 | public function isNotVisible() : bool |
||
64 | |||
65 | public function dueIn(string $format = 'days') : int |
||
83 | |||
84 | public function assignTask(Task $task) : void |
||
85 | { |
||
86 | $this->tasks()->save($task); |
||
87 | |||
90 | |||
91 | public function removeTask(Task $task) : void |
||
97 | |||
98 | public function hasTask(Task $task) : bool |
||
104 | |||
105 | /** |
||
106 | * Has the task got an expected target. |
||
107 | * |
||
108 | * @return bool |
||
109 | */ |
||
110 | public function hasDateTarget() : bool |
||
114 | |||
115 | /** |
||
116 | * Is the task still in process. |
||
117 | * |
||
118 | * @return bool |
||
119 | */ |
||
120 | public function isInProcess() : bool |
||
124 | |||
125 | /** |
||
126 | * Is the task not due yet. |
||
127 | * |
||
128 | * @return bool |
||
129 | */ |
||
130 | public function notDueYet() : bool |
||
134 | |||
135 | /** |
||
136 | * Is the task complete. |
||
137 | * |
||
138 | * @return bool |
||
139 | */ |
||
140 | public function completed() : bool |
||
150 | |||
151 | /** |
||
152 | * Was the task completed after the given deadline. |
||
153 | * |
||
154 | * @return bool |
||
155 | */ |
||
156 | public function completedAfterSchedule() : bool |
||
160 | |||
161 | /** |
||
162 | * Was the task completed before the given deadline. |
||
163 | * |
||
164 | * @return bool |
||
165 | */ |
||
166 | public function completedBeforeSchedule() : bool |
||
170 | |||
171 | /** |
||
172 | * Was the task completed before or on the given deadline. |
||
173 | * |
||
174 | * @return bool |
||
175 | */ |
||
176 | public function completedOnSchedule() : bool |
||
180 | |||
181 | /** |
||
182 | * Is the task overdue. |
||
183 | * |
||
184 | * @return bool |
||
185 | */ |
||
186 | public function isOverdue() : bool |
||
190 | |||
191 | /** |
||
192 | * Have all tasks been completed. |
||
193 | * |
||
194 | * @return bool |
||
195 | */ |
||
196 | public function completedAllTasks() : bool |
||
206 | } |
||
207 |