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\User; |
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 User 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
|
|
|
* @method Relations\BelongsTo belongsTo($related, $foreignKey = null, $otherKey = null, $relation = null) |
25
|
|
|
*/ |
26
|
|
|
trait RelationTrait |
27
|
|
|
{ |
28
|
|
|
/** |
29
|
|
|
* A user has one role (inverse relationship of Role::users). |
30
|
|
|
* |
31
|
|
|
* @return Relations\BelongsTo |
32
|
|
|
*/ |
33
|
29 |
|
public function role() |
34
|
|
|
{ |
35
|
29 |
|
return $this->belongsTo('Tinyissue\Model\Role', 'role_id'); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* User has many comments (One-many relationship of Comment::user). |
40
|
|
|
* |
41
|
|
|
* @return Relations\HasMany |
42
|
|
|
*/ |
43
|
|
|
public function comments() |
44
|
|
|
{ |
45
|
|
|
return $this->hasMany('Tinyissue\Model\Project\Issue\Comment', 'created_by', 'id'); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Returns issues created by the user. |
50
|
|
|
* |
51
|
|
|
* @return Relations\HasMany |
52
|
|
|
*/ |
53
|
2 |
|
public function issuesCreatedBy() |
54
|
|
|
{ |
55
|
2 |
|
return $this->hasMany('Tinyissue\Model\Project\Issue', 'created_by'); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* Returns issues closed by the user. |
60
|
|
|
* |
61
|
|
|
* @return Relations\HasMany |
62
|
|
|
*/ |
63
|
|
|
public function issuesClosedBy() |
64
|
|
|
{ |
65
|
|
|
return $this->hasMany('Tinyissue\Model\Project\Issue', 'closed_by'); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* Returns issues updated by the user. |
70
|
|
|
* |
71
|
|
|
* @return Relations\HasMany |
72
|
|
|
*/ |
73
|
|
|
public function issuesUpdatedBy() |
74
|
|
|
{ |
75
|
|
|
return $this->hasMany('Tinyissue\Model\Project\Issue', 'updated_by'); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* User has many attachments (One-many relationship of Attachment::user). |
80
|
|
|
* |
81
|
|
|
* @return Relations\HasMany |
82
|
|
|
*/ |
83
|
|
|
public function attachments() |
84
|
|
|
{ |
85
|
|
|
return $this->hasMany('Tinyissue\Model\Project\Issue\Attachment', 'uploaded_by'); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* Returns all projects the user can access. |
90
|
|
|
* |
91
|
|
|
* @param int $status |
92
|
|
|
* |
93
|
|
|
* @return Relations\HasMany |
94
|
|
|
*/ |
95
|
30 |
|
public function projects($status = Project::STATUS_OPEN) |
96
|
|
|
{ |
97
|
|
|
return $this |
98
|
30 |
|
->belongsToMany('Tinyissue\Model\Project', 'projects_users') |
99
|
30 |
|
->where('status', '=', $status) |
100
|
30 |
|
->orderBy('name'); |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* User has many issues assigned to (One-many relationship of Issue::assigned). |
105
|
|
|
* |
106
|
|
|
* @return Relations\HasMany |
107
|
|
|
*/ |
108
|
19 |
|
public function issues() |
109
|
|
|
{ |
110
|
19 |
|
return $this->hasMany('Tinyissue\Model\Project\Issue', 'assigned_to'); |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* Returns all permission for the user. |
115
|
|
|
* |
116
|
|
|
* @return Relations\HasMany |
117
|
|
|
*/ |
118
|
60 |
|
public function permissions() |
119
|
|
|
{ |
120
|
60 |
|
return $this->hasMany('\Tinyissue\Model\Role\Permission', 'role_id', 'role_id'); |
121
|
|
|
} |
122
|
|
|
} |
123
|
|
|
|