forked from mdmsoft/yii2-admin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAuthItemSearch.php
69 lines (61 loc) · 1.35 KB
/
AuthItemSearch.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
63
64
65
66
67
68
69
<?php
namespace mdm\admin\models;
use Yii;
use yii\base\Model;
use yii\db\Query;
use yii\data\ActiveDataProvider;
use yii\data\ArrayDataProvider;
/**
* AuthItemSearch represents the model behind the search form about AuthItem.
*/
class AuthItemSearch extends Model
{
public $name;
public $type;
public $description;
public $biz_rule;
public $data;
public function rules()
{
return [
[['name', 'description',], 'safe'],
[['type'], 'integer'],
];
}
/**
* @inheritdoc
*/
public function attributeLabels()
{
return [
'name' => 'Name',
'type' => 'Type',
'description' => 'Description',
'biz_rule' => 'Biz Rule',
'data' => 'Data',
];
}
/**
*
* @param array $params
* @return \yii\data\ActiveDataProvider|\yii\data\ArrayDataProvider
*/
public function search($params)
{
/* @var \yii\rbac\Manager $authManager */
$authManager = Yii::$app->authManager;
$items = $authManager->getItems(null, $this->type);
if ($this->load($params) && $this->validate()) {
$items = array_filter($items, function($item) {
if (trim($this->name) === '') {
return true;
}
$search = strtolower($this->name);
return strpos(strtolower($item->name), $search) !== false or strpos(strtolower($item->description), $search) !== false;
});
}
return new ArrayDataProvider([
'allModels' => $items,
]);
}
}