|
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; |
|
13
|
|
|
|
|
14
|
|
|
use Illuminate\Database\Eloquent\Relations; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* RelationTrait is trait class containing the relationship methods for the Role model. |
|
18
|
|
|
* |
|
19
|
|
|
* @author Mohamed Alsharaf <[email protected]> |
|
20
|
|
|
* |
|
21
|
|
|
* @property static $this |
|
22
|
|
|
*/ |
|
23
|
|
View Code Duplication |
trait RoleRelations |
|
|
|
|
|
|
24
|
|
|
{ |
|
25
|
|
|
/** |
|
26
|
|
|
* Role has many users (One-many relationship of User::role). |
|
27
|
|
|
* |
|
28
|
|
|
* @return Relations\HasMany |
|
29
|
|
|
*/ |
|
30
|
|
|
public function users() |
|
31
|
|
|
{ |
|
32
|
|
|
return $this |
|
33
|
|
|
->hasMany('Tinyissue\Model\User', 'role_id', 'id') |
|
34
|
|
|
->where('deleted', '=', User::NOT_DELETED_USERS) |
|
35
|
|
|
->orderBy('firstname', 'asc'); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* Role has many users in a project_users. |
|
40
|
|
|
* |
|
41
|
|
|
* @return Relations\HasMany |
|
42
|
|
|
*/ |
|
43
|
|
|
public function projectUsers() |
|
44
|
|
|
{ |
|
45
|
|
|
return $this->hasMany('Tinyissue\Model\Project\User'); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* Role has many role permission. |
|
50
|
|
|
* |
|
51
|
|
|
* @return Relations\BelongsToMany |
|
52
|
|
|
*/ |
|
53
|
|
|
public function permissions() |
|
54
|
|
|
{ |
|
55
|
|
|
return $this->belongsToMany( |
|
56
|
|
|
'\Tinyissue\Model\Permission', |
|
57
|
|
|
'roles_permissions', |
|
58
|
|
|
'role_id', |
|
59
|
|
|
'permission_id', |
|
60
|
|
|
'role_id' |
|
61
|
|
|
); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
abstract public function hasMany($related, $foreignKey = null, $localKey = null); |
|
65
|
|
|
abstract public function belongsToMany($related, $table = null, $foreignKey = null, $otherKey = null, $relation = null); |
|
66
|
|
|
} |
|
67
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.