-
Notifications
You must be signed in to change notification settings - Fork 140
/
Copy pathRole.php
62 lines (54 loc) · 1.37 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
57
58
59
60
61
62
<?php
/*
* This file is part of the Dektrium project.
*
* (c) Dektrium project <http://github.com/dektrium>
*
* For the full copyright and license information, please view the LICENSE.md
* file that was distributed with this source code.
*/
namespace dektrium\rbac\models;
use yii\rbac\Item;
/**
* @author Dmitry Erofeev <[email protected]>
*/
class Role extends AuthItem
{
/**
* @inheritdoc
*/
public function getUnassignedItems()
{
$data = [];
$items = $this->manager->getItems(null, $this->item !== null ? [$this->item->name] : []);
if ($this->item === null) {
foreach ($items as $item) {
$data[$item->name] = $this->formatName($item);
}
} else {
foreach ($items as $item) {
if ($this->manager->canAddChild($this->item, $item)) {
$data[$item->name] = $this->formatName($item);
}
}
}
return $data;
}
/**
* Formats name.
*
* @param Item $item
* @return string
*/
protected function formatName(Item $item)
{
return empty($item->description) ? $item->name : $item->name . ' (' . $item->description . ')';
}
/**
* @inheritdoc
*/
protected function createItem($name)
{
return $this->manager->createRole($name);
}
}