init
This commit is contained in:
72
vendor/yii2mod/yii2-rbac/models/search/AssignmentSearch.php
vendored
Normal file
72
vendor/yii2mod/yii2-rbac/models/search/AssignmentSearch.php
vendored
Normal file
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
|
||||
namespace yii2mod\rbac\models\search;
|
||||
|
||||
use yii\base\Model;
|
||||
use yii\data\ActiveDataProvider;
|
||||
|
||||
/**
|
||||
* Class AssignmentSearch
|
||||
*
|
||||
* @package yii2mod\rbac\models\search
|
||||
*/
|
||||
class AssignmentSearch extends Model
|
||||
{
|
||||
/**
|
||||
* @var string user id
|
||||
*/
|
||||
public $id;
|
||||
|
||||
/**
|
||||
* @var string username
|
||||
*/
|
||||
public $username;
|
||||
|
||||
/**
|
||||
* @var int the default page size
|
||||
*/
|
||||
public $pageSize = 25;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
[['id', 'username'], 'safe'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates data provider instance with search query applied
|
||||
*
|
||||
* @param array $params
|
||||
* @param \yii\db\ActiveRecord $class
|
||||
* @param $idField
|
||||
* @param string $usernameField
|
||||
*
|
||||
* @return ActiveDataProvider
|
||||
*/
|
||||
public function search(array $params, $class, string $idField, string $usernameField): ActiveDataProvider
|
||||
{
|
||||
$query = $class::find();
|
||||
|
||||
$dataProvider = new ActiveDataProvider([
|
||||
'query' => $query,
|
||||
'pagination' => [
|
||||
'pageSize' => $this->pageSize,
|
||||
],
|
||||
]);
|
||||
|
||||
$this->load($params);
|
||||
|
||||
if (!$this->validate()) {
|
||||
return $dataProvider;
|
||||
}
|
||||
|
||||
$query->andFilterWhere([$idField => $this->id]);
|
||||
$query->andFilterWhere(['like', $usernameField, $this->username]);
|
||||
|
||||
return $dataProvider;
|
||||
}
|
||||
}
|
||||
108
vendor/yii2mod/yii2-rbac/models/search/AuthItemSearch.php
vendored
Normal file
108
vendor/yii2mod/yii2-rbac/models/search/AuthItemSearch.php
vendored
Normal file
@@ -0,0 +1,108 @@
|
||||
<?php
|
||||
|
||||
namespace yii2mod\rbac\models\search;
|
||||
|
||||
use dosamigos\arrayquery\ArrayQuery;
|
||||
use Yii;
|
||||
use yii\base\Model;
|
||||
use yii\data\ArrayDataProvider;
|
||||
use yii\rbac\Item;
|
||||
|
||||
/**
|
||||
* Class AuthItemSearch
|
||||
*
|
||||
* @package yii2mod\rbac\models\search
|
||||
*/
|
||||
class AuthItemSearch extends Model
|
||||
{
|
||||
/**
|
||||
* @var string auth item name
|
||||
*/
|
||||
public $name;
|
||||
|
||||
/**
|
||||
* @var int auth item type
|
||||
*/
|
||||
public $type;
|
||||
|
||||
/**
|
||||
* @var string auth item description
|
||||
*/
|
||||
public $description;
|
||||
|
||||
/**
|
||||
* @var string auth item rule name
|
||||
*/
|
||||
public $ruleName;
|
||||
|
||||
/**
|
||||
* @var int the default page size
|
||||
*/
|
||||
public $pageSize = 25;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
[['name', 'ruleName', 'description'], 'trim'],
|
||||
[['type'], 'integer'],
|
||||
[['name', 'ruleName', 'description'], 'safe'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function attributeLabels(): array
|
||||
{
|
||||
return [
|
||||
'name' => Yii::t('yii2mod.rbac', 'Name'),
|
||||
'type' => Yii::t('yii2mod.rbac', 'Type'),
|
||||
'description' => Yii::t('yii2mod.rbac', 'Description'),
|
||||
'rule' => Yii::t('yii2mod.rbac', 'Rule'),
|
||||
'data' => Yii::t('yii2mod.rbac', 'Data'),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates data provider instance with search query applied
|
||||
*
|
||||
* @param array $params
|
||||
*
|
||||
* @return \yii\data\ArrayDataProvider
|
||||
*/
|
||||
public function search(array $params): ArrayDataProvider
|
||||
{
|
||||
$authManager = Yii::$app->getAuthManager();
|
||||
|
||||
if ($this->type == Item::TYPE_ROLE) {
|
||||
$items = $authManager->getRoles();
|
||||
} else {
|
||||
$items = array_filter($authManager->getPermissions(), function ($item) {
|
||||
return strpos($item->name, '/') !== 0;
|
||||
});
|
||||
}
|
||||
|
||||
$query = new ArrayQuery($items);
|
||||
|
||||
$this->load($params);
|
||||
|
||||
if ($this->validate()) {
|
||||
$query->addCondition('name', $this->name ? "~{$this->name}" : null)
|
||||
->addCondition('ruleName', $this->ruleName ? "~{$this->ruleName}" : null)
|
||||
->addCondition('description', $this->description ? "~{$this->description}" : null);
|
||||
}
|
||||
|
||||
return new ArrayDataProvider([
|
||||
'allModels' => $query->find(),
|
||||
'sort' => [
|
||||
'attributes' => ['name'],
|
||||
],
|
||||
'pagination' => [
|
||||
'pageSize' => $this->pageSize,
|
||||
],
|
||||
]);
|
||||
}
|
||||
}
|
||||
63
vendor/yii2mod/yii2-rbac/models/search/BizRuleSearch.php
vendored
Normal file
63
vendor/yii2mod/yii2-rbac/models/search/BizRuleSearch.php
vendored
Normal file
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
namespace yii2mod\rbac\models\search;
|
||||
|
||||
use dosamigos\arrayquery\ArrayQuery;
|
||||
use Yii;
|
||||
use yii\base\Model;
|
||||
use yii\data\ArrayDataProvider;
|
||||
|
||||
/**
|
||||
* Class BizRuleSearch
|
||||
*
|
||||
* @package yii2mod\rbac\models\search
|
||||
*/
|
||||
class BizRuleSearch extends Model
|
||||
{
|
||||
/**
|
||||
* @var string name of the rule
|
||||
*/
|
||||
public $name;
|
||||
|
||||
/**
|
||||
* @var int the default page size
|
||||
*/
|
||||
public $pageSize = 25;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
['name', 'trim'],
|
||||
['name', 'safe'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates data provider instance with search query applied
|
||||
*
|
||||
* @param array $params
|
||||
*
|
||||
* @return ArrayDataProvider
|
||||
*/
|
||||
public function search(array $params): ArrayDataProvider
|
||||
{
|
||||
$query = new ArrayQuery(Yii::$app->authManager->getRules());
|
||||
|
||||
if ($this->load($params) && $this->validate()) {
|
||||
$query->addCondition('name', $this->name ? "~{$this->name}" : null);
|
||||
}
|
||||
|
||||
return new ArrayDataProvider([
|
||||
'allModels' => $query->find(),
|
||||
'sort' => [
|
||||
'attributes' => ['name'],
|
||||
],
|
||||
'pagination' => [
|
||||
'pageSize' => $this->pageSize,
|
||||
],
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user