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\Role; |
13
|
|
|
|
14
|
|
|
use Illuminate\Database\Eloquent\Relations; |
15
|
|
|
use Tinyissue\Model\User; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* RelationTrait is trait class containing the relationship methods for the Role model. |
19
|
|
|
* |
20
|
|
|
* @author Mohamed Alsharaf <[email protected]> |
21
|
|
|
* |
22
|
|
|
* @property static $this |
23
|
|
|
*/ |
24
|
|
|
trait RelationTrait |
25
|
|
|
{ |
26
|
|
|
/** |
27
|
|
|
* Role has many users (One-many relationship of User::role). |
28
|
|
|
* |
29
|
|
|
* @return Relations\HasMany |
30
|
|
|
*/ |
31
|
3 |
|
public function users() |
32
|
|
|
{ |
33
|
|
|
return $this |
34
|
3 |
|
->hasMany('Tinyissue\Model\User', 'role_id', 'id') |
35
|
3 |
|
->where('deleted', '=', User::NOT_DELETED_USERS) |
36
|
3 |
|
->orderBy('firstname', 'asc'); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Role has many users in a project_users. |
41
|
|
|
* |
42
|
|
|
* @return Relations\HasMany |
43
|
|
|
*/ |
44
|
|
|
public function projectUsers() |
45
|
|
|
{ |
46
|
|
|
return $this->hasMany('Tinyissue\Model\Project\User'); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Role has many role permission. |
51
|
|
|
* |
52
|
|
|
* @return Relations\BelongsToMany |
53
|
|
|
*/ |
54
|
|
|
public function permissions() |
55
|
|
|
{ |
56
|
|
|
return $this->belongsToMany( |
57
|
|
|
'\Tinyissue\Model\Permission', |
58
|
|
|
'roles_permissions', |
59
|
|
|
'role_id', |
60
|
|
|
'permission_id', |
61
|
|
|
'role_id' |
62
|
|
|
); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
abstract public function hasMany($related, $foreignKey = null, $localKey = null); |
66
|
|
|
abstract public function belongsToMany($related, $table = null, $foreignKey = null, $otherKey = null, $relation = null); |
67
|
|
|
} |
68
|
|
|
|