Initial commit,修正
This commit is contained in:
+64
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
namespace mdm\admin\models\searchs;
|
||||
|
||||
use Yii;
|
||||
use yii\base\Model;
|
||||
use yii\data\ActiveDataProvider;
|
||||
|
||||
/**
|
||||
* AssignmentSearch represents the model behind the search form about Assignment.
|
||||
*
|
||||
* @author Misbahul D Munir <misbahuldmunir@gmail.com>
|
||||
* @since 1.0
|
||||
*/
|
||||
class Assignment extends Model
|
||||
{
|
||||
public $id;
|
||||
public $username;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
[['id', 'username'], 'safe'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function attributeLabels()
|
||||
{
|
||||
return [
|
||||
'id' => Yii::t('rbac-admin', 'ID'),
|
||||
'username' => Yii::t('rbac-admin', 'Username'),
|
||||
'name' => Yii::t('rbac-admin', 'Name'),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Create data provider for Assignment model.
|
||||
* @param array $params
|
||||
* @param \yii\db\ActiveRecord $class
|
||||
* @param string $usernameField
|
||||
* @return \yii\data\ActiveDataProvider
|
||||
*/
|
||||
public function search($params, $class, $usernameField)
|
||||
{
|
||||
$query = $class::find();
|
||||
$dataProvider = new ActiveDataProvider([
|
||||
'query' => $query,
|
||||
]);
|
||||
|
||||
if (!($this->load($params) && $this->validate())) {
|
||||
return $dataProvider;
|
||||
}
|
||||
|
||||
$query->andFilterWhere(['like', $usernameField, $this->username]);
|
||||
|
||||
return $dataProvider;
|
||||
}
|
||||
}
|
||||
+87
@@ -0,0 +1,87 @@
|
||||
<?php
|
||||
|
||||
namespace mdm\admin\models\searchs;
|
||||
|
||||
use Yii;
|
||||
use yii\base\Model;
|
||||
use yii\data\ArrayDataProvider;
|
||||
use yii\rbac\Item;
|
||||
|
||||
/**
|
||||
* AuthItemSearch represents the model behind the search form about AuthItem.
|
||||
*
|
||||
* @author Misbahul D Munir <misbahuldmunir@gmail.com>
|
||||
* @since 1.0
|
||||
*/
|
||||
class AuthItem extends Model
|
||||
{
|
||||
const TYPE_ROUTE = 101;
|
||||
|
||||
public $name;
|
||||
public $type;
|
||||
public $description;
|
||||
public $ruleName;
|
||||
public $data;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
[['name', 'ruleName', 'description'], 'safe'],
|
||||
[['type'], 'integer'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function attributeLabels()
|
||||
{
|
||||
return [
|
||||
'name' => Yii::t('rbac-admin', 'Name'),
|
||||
'item_name' => Yii::t('rbac-admin', 'Name'),
|
||||
'type' => Yii::t('rbac-admin', 'Type'),
|
||||
'description' => Yii::t('rbac-admin', 'Description'),
|
||||
'ruleName' => Yii::t('rbac-admin', 'Rule Name'),
|
||||
'data' => Yii::t('rbac-admin', 'Data'),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Search authitem
|
||||
* @param array $params
|
||||
* @return \yii\data\ActiveDataProvider|\yii\data\ArrayDataProvider
|
||||
*/
|
||||
public function search($params)
|
||||
{
|
||||
/* @var \yii\rbac\Manager $authManager */
|
||||
$authManager = Yii::$app->getAuthManager();
|
||||
if ($this->type == Item::TYPE_ROLE) {
|
||||
$items = $authManager->getRoles();
|
||||
} else {
|
||||
$items = array_filter($authManager->getPermissions(), function($item) {
|
||||
return $this->type == Item::TYPE_PERMISSION xor strncmp($item->name, '/', 1) === 0;
|
||||
});
|
||||
}
|
||||
$this->load($params);
|
||||
if ($this->validate()) {
|
||||
$search = empty($this->name) ? '' : strtolower(trim($this->name));
|
||||
$desc = empty($this->description) ? '' : strtolower(trim($this->description));
|
||||
$ruleName = $this->ruleName;
|
||||
foreach ($items as $name => $item) {
|
||||
$f = (empty($search) || strpos(strtolower($item->name), $search) !== false) &&
|
||||
(empty($desc) || strpos(strtolower($item->description), $desc) !== false) &&
|
||||
(empty($ruleName) || $item->ruleName == $ruleName);
|
||||
if (!$f) {
|
||||
unset($items[$name]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return new ArrayDataProvider([
|
||||
'allModels' => $items,
|
||||
]);
|
||||
}
|
||||
}
|
||||
+62
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
namespace mdm\admin\models\searchs;
|
||||
|
||||
use Yii;
|
||||
use yii\base\Model;
|
||||
use yii\data\ArrayDataProvider;
|
||||
use mdm\admin\models\BizRule as MBizRule;
|
||||
use mdm\admin\components\RouteRule;
|
||||
|
||||
/**
|
||||
* Description of BizRule
|
||||
*
|
||||
* @author Misbahul D Munir <misbahuldmunir@gmail.com>
|
||||
* @since 1.0
|
||||
*/
|
||||
class BizRule extends Model
|
||||
{
|
||||
/**
|
||||
* @var string name of the rule
|
||||
*/
|
||||
public $name;
|
||||
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
[['name'], 'safe']
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function attributeLabels()
|
||||
{
|
||||
return [
|
||||
'name' => Yii::t('rbac-admin', 'Name'),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Search BizRule
|
||||
* @param array $params
|
||||
* @return \yii\data\ActiveDataProvider|\yii\data\ArrayDataProvider
|
||||
*/
|
||||
public function search($params)
|
||||
{
|
||||
/* @var \yii\rbac\Manager $authManager */
|
||||
$authManager = Yii::$app->authManager;
|
||||
$models = [];
|
||||
$included = !($this->load($params) && $this->validate() && trim($this->name) !== '');
|
||||
foreach ($authManager->getRules() as $name => $item) {
|
||||
if ($name != RouteRule::RULE_NAME && ($included || stripos($item->name, $this->name) !== false)) {
|
||||
$models[$name] = new MBizRule($item);
|
||||
}
|
||||
}
|
||||
|
||||
return new ArrayDataProvider([
|
||||
'allModels' => $models,
|
||||
]);
|
||||
}
|
||||
}
|
||||
+84
@@ -0,0 +1,84 @@
|
||||
<?php
|
||||
|
||||
namespace mdm\admin\models\searchs;
|
||||
|
||||
use Yii;
|
||||
use yii\base\Model;
|
||||
use yii\data\ActiveDataProvider;
|
||||
use mdm\admin\models\Menu as MenuModel;
|
||||
|
||||
/**
|
||||
* Menu represents the model behind the search form about [[\mdm\admin\models\Menu]].
|
||||
*
|
||||
* @author Misbahul D Munir <misbahuldmunir@gmail.com>
|
||||
* @since 1.0
|
||||
*/
|
||||
class Menu extends MenuModel
|
||||
{
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
[['id', 'parent', 'order'], 'integer'],
|
||||
[['name', 'route', 'parent_name'], 'safe'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function scenarios()
|
||||
{
|
||||
// bypass scenarios() implementation in the parent class
|
||||
return Model::scenarios();
|
||||
}
|
||||
|
||||
/**
|
||||
* Searching menu
|
||||
* @param array $params
|
||||
* @return \yii\data\ActiveDataProvider
|
||||
*/
|
||||
public function search($params)
|
||||
{
|
||||
$query = MenuModel::find()
|
||||
->from(MenuModel::tableName() . ' t')
|
||||
->joinWith(['menuParent' => function ($q) {
|
||||
$q->from(MenuModel::tableName() . ' parent');
|
||||
}]);
|
||||
|
||||
$dataProvider = new ActiveDataProvider([
|
||||
'query' => $query
|
||||
]);
|
||||
|
||||
$sort = $dataProvider->getSort();
|
||||
$sort->attributes['menuParent.name'] = [
|
||||
'asc' => ['parent.name' => SORT_ASC],
|
||||
'desc' => ['parent.name' => SORT_DESC],
|
||||
'label' => 'parent',
|
||||
];
|
||||
$sort->attributes['order'] = [
|
||||
'asc' => ['parent.order' => SORT_ASC, 't.order' => SORT_ASC],
|
||||
'desc' => ['parent.order' => SORT_DESC, 't.order' => SORT_DESC],
|
||||
'label' => 'order',
|
||||
];
|
||||
$sort->defaultOrder = ['menuParent.name' => SORT_ASC];
|
||||
|
||||
if (!($this->load($params) && $this->validate())) {
|
||||
return $dataProvider;
|
||||
}
|
||||
|
||||
$query->andFilterWhere([
|
||||
't.id' => $this->id,
|
||||
't.parent' => $this->parent,
|
||||
]);
|
||||
|
||||
$query->andFilterWhere(['like', 'lower(t.name)', strtolower($this->name)])
|
||||
->andFilterWhere(['like', 't.route', $this->route])
|
||||
->andFilterWhere(['like', 'lower(parent.name)', strtolower($this->parent_name)]);
|
||||
|
||||
return $dataProvider;
|
||||
}
|
||||
}
|
||||
+71
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
|
||||
namespace mdm\admin\models\searchs;
|
||||
|
||||
use Yii;
|
||||
use yii\base\Model;
|
||||
use yii\data\ActiveDataProvider;
|
||||
use mdm\admin\models\User as UserModel;
|
||||
|
||||
/**
|
||||
* User represents the model behind the search form about `mdm\admin\models\User`.
|
||||
*/
|
||||
class User extends UserModel
|
||||
{
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
[['id', 'status', 'created_at', 'updated_at'], 'integer'],
|
||||
[['username', 'auth_key', 'password_hash', 'password_reset_token', 'email'], 'safe'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function scenarios()
|
||||
{
|
||||
// bypass scenarios() implementation in the parent class
|
||||
return Model::scenarios();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates data provider instance with search query applied
|
||||
*
|
||||
* @param array $params
|
||||
*
|
||||
* @return ActiveDataProvider
|
||||
*/
|
||||
public function search($params)
|
||||
{
|
||||
$query = UserModel::find();
|
||||
|
||||
$dataProvider = new ActiveDataProvider([
|
||||
'query' => $query,
|
||||
]);
|
||||
|
||||
$this->load($params);
|
||||
if (!$this->validate()) {
|
||||
$query->where('1=0');
|
||||
return $dataProvider;
|
||||
}
|
||||
|
||||
$query->andFilterWhere([
|
||||
'id' => $this->id,
|
||||
'status' => $this->status,
|
||||
'created_at' => $this->created_at,
|
||||
'updated_at' => $this->updated_at,
|
||||
]);
|
||||
|
||||
$query->andFilterWhere(['like', 'username', $this->username])
|
||||
->andFilterWhere(['like', 'auth_key', $this->auth_key])
|
||||
->andFilterWhere(['like', 'password_hash', $this->password_hash])
|
||||
->andFilterWhere(['like', 'password_reset_token', $this->password_reset_token])
|
||||
->andFilterWhere(['like', 'email', $this->email]);
|
||||
|
||||
return $dataProvider;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user