/
Role.php
56 lines (44 loc) · 1.31 KB
/
Role.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?php
namespace Bazalt\Auth\Model;
use Bazalt\ORM;
class Role extends Base\Role
{
public static function create()
{
$role = new Role();
$role->system_acl = 0;
$role->description = '';
return $role;
}
public static function getUsersByRole($role)
{
$q = ORM::select('Bazalt\Auth\Model\User u')
->innerJoin('Bazalt\Auth\Model\RoleRefUser ref', array('user_id', 'u.id'))
->where('ref.role_id = ?', $role->id);
return $q->fetchAll();
}
public static function getGuestRoles()
{
$q = ORM::select('Bazalt\Auth\Model\Role r')
->where('is_guest = ?', 1);
return $q->fetchAll();
}
public static function getByName($name)
{
$q = ORM::select('Bazalt\\Auth\\Model\\Role r')
->where('title = ?', $name);
return $q->fetch();
}
public function getPermissions()
{
$q = ORM::select('Bazalt\\Auth\\Model\\Permission p', 'p.id')
->innerJoin('Bazalt\\Auth\\Model\\RoleRefPermission rp', ['permission_id', 'p.id'])
->where('rp.role_id = ?', $this->id);
return $q->fetchAll();
}
public function addPermission($id)
{
$perm = Permission::getById($id);
$this->Permissions->add($perm);
}
}