RoleModel::getName()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php namespace Anomaly\UsersModule\Role;
2
3
use Anomaly\Streams\Platform\Model\Users\UsersRolesEntryModel;
4
use Anomaly\UsersModule\Role\Contract\RoleInterface;
5
use Anomaly\UsersModule\User\UserCollection;
6
7
/**
8
 * Class RoleModel
9
 *
10
 * @link          http://pyrocms.com/
11
 * @author        PyroCMS, Inc. <[email protected]>
12
 * @author        Ryan Thompson <[email protected]>
13
 */
14
class RoleModel extends UsersRolesEntryModel implements RoleInterface
15
{
16
17
    /**
18
     * The cache minutes.
19
     *
20
     * @var int
21
     */
22
    protected $ttl = 99999;
23
24
    /**
25
     * Eager loaded relations.
26
     *
27
     * @var array
28
     */
29
    protected $with = [
30
        'translations',
31
    ];
32
33
    /**
34
     * Get the role slug.
35
     *
36
     * @return string
37
     */
38
    public function getSlug()
39
    {
40
        return $this->slug;
41
    }
42
43
    /**
44
     * Get the role name.
45
     *
46
     * @return string
47
     */
48
    public function getName()
49
    {
50
        return $this->name;
51
    }
52
53
    /**
54
     * Get the role's permissions.
55
     *
56
     * @return array
57
     */
58
    public function getPermissions()
59
    {
60
        return $this->permissions;
61
    }
62
63
    /**
64
     * Return if a role as access to a the permission.
65
     *
66
     * @param  string $permission
67
     * @return mixed
68
     */
69
    public function hasPermission($permission)
70
    {
71
        if ($this->getSlug() == 'admin') {
72
            return true;
73
        }
74
75
        if (!$this->getPermissions()) {
76
            return false;
77
        }
78
79
        if (in_array($permission, $this->getPermissions())) {
80
            return true;
81
        }
82
83
        return false;
84
    }
85
86
    /**
87
     * Get the related users.
88
     *
89
     * @return UserCollection
90
     */
91
    public function getUsers()
92
    {
93
        return $this->users;
94
    }
95
96
    /**
97
     * Return the users relation.
98
     *
99
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
100
     */
101
    public function users()
102
    {
103
        return $this->belongsToMany(
104
            'Anomaly\UsersModule\User\UserModel',
105
            'users_users_roles',
106
            'related_id',
107
            'entry_id'
108
        );
109
    }
110
}
111