1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Tinyissue package. |
5
|
|
|
* |
6
|
|
|
* (c) Mohamed Alsharaf <[email protected]> |
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 Tinyissue\Model\Project; |
13
|
|
|
|
14
|
|
|
use Illuminate\Database\Eloquent\Relations; |
15
|
|
|
use Tinyissue\Model; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* NoteRelations is trait class containing the relationship methods for the Project\Note model. |
19
|
|
|
* |
20
|
|
|
* @author Mohamed Alsharaf <[email protected]> |
21
|
|
|
* |
22
|
|
|
* @property static $this |
23
|
|
|
*/ |
24
|
|
|
trait NoteRelations |
25
|
|
|
{ |
26
|
|
|
/** |
27
|
|
|
* Note created by a user. |
28
|
|
|
* |
29
|
|
|
* @return Model\User |
30
|
|
|
*/ |
31
|
|
|
public function createdBy() |
32
|
|
|
{ |
33
|
|
|
return $this->belongsTo(Model\User::class, 'created_by'); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Note belong to a project. |
38
|
|
|
* |
39
|
|
|
* @return Model\Project |
40
|
|
|
*/ |
41
|
|
|
public function project() |
42
|
|
|
{ |
43
|
|
|
return $this->belongsTo(Model\Project::class, 'project_id'); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Note has a user activity record. |
48
|
|
|
* |
49
|
|
|
* @return Model\User\Activity |
50
|
|
|
*/ |
51
|
|
|
public function activity() |
52
|
|
|
{ |
53
|
|
|
return $this |
54
|
|
|
->hasOne(Model\User\Activity::class, 'action_id') |
55
|
|
|
->where('type_id', '=', Model\Activity::TYPE_NOTE); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* Note can have many messages queue. |
60
|
|
|
* |
61
|
|
|
* @return Model\Message\Queue |
62
|
|
|
*/ |
63
|
|
|
public function messagesQueue() |
64
|
|
|
{ |
65
|
|
|
return $this->morphMany(Model\Message\Queue::class, 'model'); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
abstract public function morphMany($related, $name, $type = null, $id = null, $localKey = null); |
69
|
|
|
|
70
|
|
|
abstract public function hasOne($related, $foreignKey = null, $localKey = null); |
71
|
|
|
|
72
|
|
|
abstract public function belongsTo($related, $foreignKey = null, $otherKey = null, $relation = null); |
73
|
|
|
} |
74
|
|
|
|