Example #1
0
 public function search($params)
 {
     $query = AuthItemChild::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     $query->andFilterWhere(['like', 'parent', $this->parent])->andFilterWhere(['like', 'child', $this->child]);
     return $dataProvider;
 }
Example #2
0
 public static function getRolesByPermission($permission)
 {
     $role = [''];
     $roles = AuthItemChild::find()->where(['child' => $permission])->all();
     if ($roles) {
         foreach ($roles as $r) {
             $role[] = $r->child;
         }
     }
     return $role;
 }
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = AuthItemChild::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['like', 'parent', $this->parent])->andFilterWhere(['like', 'child', $this->child]);
     return $dataProvider;
 }
 public function actionInit()
 {
     $auth = \Yii::$app->authManager;
     $auth->removeAll();
     //$arrPerm = [];
     $query = AuthItem::find()->where(['type' => 0]);
     $modelAuthItem = $query->all();
     foreach ($modelAuthItem as $obj) {
         $arrPerm[$obj->name] = $obj->description;
     }
     //$arrRole = [];
     $query = AuthItem::find()->where(['type' => 2]);
     $modelAuthItem = $query->all();
     foreach ($modelAuthItem as $obj) {
         $arrRole[$obj->name] = $obj->description;
     }
     $query = AuthItem::find()->where(['type' => 2]);
     $modelAuthItem = $query->all();
     //$arrRolePerm = [];
     foreach ($modelAuthItem as $obj) {
         $name = $obj->name;
         $query = AuthItemChild::find()->where(['parent' => $name]);
         $modelAuthItemChild = $query->all();
         foreach ($modelAuthItemChild as $objchild) {
             $arrRolePerm[$name][] = $objchild->child;
         }
     }
     $auth->removeAll();
     foreach ($arrPerm as $permName => $title) {
         $perm = $auth->createPermission($permName);
         $perm->description = $title;
         $auth->add($perm);
     }
     foreach ($arrRole as $roleName => $title) {
         $role = $auth->createRole($roleName);
         $role->description = $title;
         $auth->add($role);
         // assign role permission
         foreach ($arrRolePerm[$roleName] as $permName) {
             $perm = $auth->getPermission($permName);
             $auth->addChild($role, $perm);
         }
     }
 }
Example #5
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getAuthItemChildren()
 {
     return $this->hasMany(AuthItemChild::className(), ['child' => 'name']);
 }
 /**
  * Finds the AuthItem model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param string $id
  * @return AuthItemChild the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = AuthItemChild::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('Страница не найдена.');
     }
 }
Example #7
0
 /**
  * @inheritdoc
  */
 public function behaviors()
 {
     return ['access' => ['class' => AccessControl::className(), 'rules' => [['actions' => ['login', 'error'], 'allow' => true], ['actions' => ['logout'], 'allow' => true, 'roles' => ['@']], ['actions' => ['index'], 'allow' => true, 'roles' => AuthItemChild::getRolesByPermission('Администрирование: Главная')], ['actions' => ['setting'], 'allow' => true, 'roles' => AuthItemChild::getRolesByPermission('Администрирование: Настройки')], ['actions' => ['manager'], 'allow' => true, 'roles' => AuthItemChild::getRolesByPermission('Администрирование: Менеджер файлов')]]]];
 }
Example #8
0
 /**
  * 获取子级角色
  */
 public function getChildItems()
 {
     return $this->hasMany(AuthItemChild::className(), ['parent' => 'name']);
 }
 /**
  * Finds the AuthItemChild model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param string $parent
  * @param string $child
  * @return AuthItemChild the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($parent, $child)
 {
     if (($model = AuthItemChild::findOne(['parent' => $parent, 'child' => $child])) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
 public function behaviors()
 {
     return ['access' => ['class' => AccessControl::className(), 'rules' => [['actions' => ['index'], 'allow' => true, 'roles' => AuthItemChild::getRolesByPermission('Администрирование: Роли > Просмотр таблицы')], ['actions' => ['create'], 'allow' => true, 'roles' => AuthItemChild::getRolesByPermission('Администрирование: Роли > Создание')], ['actions' => ['update'], 'allow' => true, 'roles' => AuthItemChild::getRolesByPermission('Администрирование: Роли > Редактирование')], ['actions' => ['delete', 'multidelete'], 'allow' => true, 'roles' => AuthItemChild::getRolesByPermission('Администрирование: Роли > Удаление')]]]];
 }
 public function behaviors()
 {
     return ['access' => ['class' => AccessControl::className(), 'rules' => [['actions' => ['index'], 'allow' => true, 'roles' => AuthItemChild::getRolesByPermission('Администрирование: Документы > Поиск по документам')], ['actions' => ['create'], 'allow' => true, 'roles' => AuthItemChild::getRolesByPermission('Администрирование: Документы > Создание')], ['actions' => ['update', 'multipublicate', 'multiclose', 'ajaxoptions', 'ajaxoption', 'deleteimg', 'deletefield'], 'allow' => true, 'roles' => AuthItemChild::getRolesByPermission('Администрирование: Документы > Редактирование')], ['actions' => ['move'], 'allow' => true, 'roles' => AuthItemChild::getRolesByPermission('Администрирование: Документы > Перемещение')], ['actions' => ['delete', 'multidelete'], 'allow' => true, 'roles' => AuthItemChild::getRolesByPermission('Администрирование: Документы > Удаление')], ['actions' => ['view'], 'allow' => true, 'roles' => AuthItemChild::getRolesByPermission('Администрирование: Документы > Предварительный просмотр')]]]];
 }
Example #12
0
 public function behaviors()
 {
     return ['access' => ['class' => AccessControl::className(), 'rules' => [['actions' => ['create', 'update', 'delete', 'multidelete'], 'allow' => true, 'roles' => AuthItemChild::getRolesByPermission('Администрирование: Шаблоны > Редактирование')]]]];
 }
Example #13
0
 public function behaviors()
 {
     return ['access' => ['class' => AccessControl::className(), 'rules' => [['actions' => ['index'], 'allow' => true, 'roles' => AuthItemChild::getRolesByPermission('Администрирование: Дополнительные поля > Поиск')]]]];
 }