|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the 2amigos/yii2-usuario project. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) 2amigOS! <http://2amigos.us/> |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view |
|
9
|
|
|
* the LICENSE file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace Da\User\Search; |
|
13
|
|
|
|
|
14
|
|
|
use Da\User\Traits\AuthManagerAwareTrait; |
|
15
|
|
|
use Da\User\Traits\ContainerAwareTrait; |
|
16
|
|
|
use yii\base\Model; |
|
17
|
|
|
use yii\data\ArrayDataProvider; |
|
18
|
|
|
use yii\db\Query; |
|
19
|
|
|
|
|
20
|
|
|
abstract class AbstractAuthItemSearch extends Model |
|
21
|
|
|
{ |
|
22
|
|
|
use AuthManagerAwareTrait; |
|
23
|
|
|
use ContainerAwareTrait; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* @var string |
|
27
|
|
|
*/ |
|
28
|
|
|
public $name; |
|
29
|
|
|
/** |
|
30
|
|
|
* @var string |
|
31
|
|
|
*/ |
|
32
|
|
|
public $description; |
|
33
|
|
|
/** |
|
34
|
|
|
* @var string |
|
35
|
|
|
*/ |
|
36
|
|
|
public $rule_name; |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* @return int |
|
40
|
|
|
*/ |
|
41
|
|
|
abstract public function getType(); |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* @return array |
|
45
|
|
|
*/ |
|
46
|
|
|
public function scenarios() |
|
47
|
|
|
{ |
|
48
|
|
|
return [ |
|
49
|
|
|
'default' => ['name', 'description', 'rule_name'], |
|
50
|
|
|
]; |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
public function search($params = []) |
|
54
|
|
|
{ |
|
55
|
|
|
/** @var ArrayDataProvider $dataProvider */ |
|
56
|
|
|
$dataProvider = $this->make(ArrayDataProvider::class); |
|
57
|
|
|
|
|
58
|
|
|
$query = (new Query()) |
|
59
|
|
|
->select(['name', 'description', 'rule_name']) |
|
60
|
|
|
->andWhere(['type' => $this->getType()]) |
|
61
|
|
|
->from($this->getAuthManager()->itemTable); |
|
|
|
|
|
|
62
|
|
|
|
|
63
|
|
|
if ($this->load($params) && $this->validate()) { |
|
64
|
|
|
$query |
|
65
|
|
|
->andFilterWhere(['like', 'name', $this->name]) |
|
66
|
|
|
->andFilterWhere(['like', 'description', $this->description]) |
|
67
|
|
|
->andFilterWhere(['like', 'rule_name', $this->rule_name]); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
$dataProvider->allModels = $query->all($this->getAuthManager()->db); |
|
|
|
|
|
|
71
|
|
|
|
|
72
|
|
|
return $dataProvider; |
|
73
|
|
|
} |
|
74
|
|
|
} |
|
75
|
|
|
|
If you access a property on an interface, you most likely code against a concrete implementation of the interface.
Available Fixes
Adding an additional type check:
Changing the type hint: