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\Traits\Project; |
13
|
|
|
|
14
|
|
|
use Illuminate\Database\Eloquent\Relations; |
15
|
|
|
use Tinyissue\Model\Project; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* RelationTrait is trait class containing the relationship methods for the Project model. |
19
|
|
|
* |
20
|
|
|
* @author Mohamed Alsharaf <[email protected]> |
21
|
|
|
* |
22
|
|
|
* @method Relations\HasMany hasMany($related, $foreignKey = null, $localKey = null) |
23
|
|
|
* @method Relations\BelongsToMany belongsToMany($related, $table = null, $foreignKey = null, $otherKey = null, $relation = null) |
24
|
|
|
*/ |
25
|
|
|
trait RelationTrait |
26
|
|
|
{ |
27
|
|
|
/** |
28
|
|
|
* Returns all issues related to project. |
29
|
|
|
* |
30
|
|
|
* @return Relations\HasMany |
31
|
|
|
*/ |
32
|
11 |
|
public function issues() |
33
|
|
|
{ |
34
|
11 |
|
return $this->hasMany('Tinyissue\Model\Project\Issue', 'project_id'); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Returns issues in the project with user details eager loaded. |
39
|
|
|
* |
40
|
|
|
* @return Relations\HasMany |
41
|
|
|
*/ |
42
|
|
|
public function issuesByUser() |
43
|
|
|
{ |
44
|
|
|
return $this->hasMany('Tinyissue\Model\Project\Issue', 'project_id')->with('user')->get(); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Returns all users assigned in the current project. |
49
|
|
|
* |
50
|
|
|
* @return Relations\BelongsToMany |
51
|
|
|
*/ |
52
|
39 |
|
public function users() |
53
|
|
|
{ |
54
|
39 |
|
return $this->belongsToMany('\Tinyissue\Model\User', 'projects_users', 'project_id', 'user_id'); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* Return a user that is member of a project. |
59
|
|
|
* |
60
|
|
|
* @param int $userId |
61
|
|
|
* |
62
|
|
|
* @return Relations\BelongsToMany |
63
|
|
|
*/ |
64
|
8 |
|
public function user($userId) |
65
|
|
|
{ |
66
|
8 |
|
return $this->users()->where('user_id', '=', (int) $userId); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* Project has many project users. |
71
|
|
|
* |
72
|
|
|
* @return Relations\HasMany |
73
|
|
|
*/ |
74
|
25 |
|
public function projectUsers() |
75
|
|
|
{ |
76
|
25 |
|
return $this->hasMany('Tinyissue\Model\Project\User', 'project_id'); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* Returns project activities. |
81
|
|
|
* |
82
|
|
|
* @return Relations\HasMany |
83
|
|
|
*/ |
84
|
11 |
|
public function activities() |
85
|
|
|
{ |
86
|
11 |
|
return $this->hasMany('Tinyissue\Model\User\Activity', 'parent_id'); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* Returns notes in the project. |
91
|
|
|
* |
92
|
|
|
* @return Relations\HasMany |
93
|
|
|
*/ |
94
|
20 |
|
public function notes() |
95
|
|
|
{ |
96
|
20 |
|
return $this->hasMany('Tinyissue\Model\Project\Note', 'project_id'); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* Project have many kanban tags. |
101
|
|
|
* |
102
|
|
|
* @return Relations\BelongsToMany |
103
|
|
|
*/ |
104
|
2 |
|
public function kanbanTags() |
105
|
|
|
{ |
106
|
2 |
|
return $this->belongsToMany('Tinyissue\Model\Tag', 'projects_kanban_tags', 'project_id', 'tag_id')->orderBy('position'); |
107
|
|
|
} |
108
|
|
|
} |
109
|
|
|
|