static function findRoleAlias($roleName = NULL) { if (empty($roleName)) { return null; } $roleAlias = \vendor\codefire\cfusermgmt\models\AuthItem::find()->where(["name" => $roleName, 'type' => TYPE_ROLE])->one(); return !empty($roleAlias) ? $roleAlias->role_alias : NULL; }
public function actionGetRolePermission() { $this->layout = false; $roleChild = array(); $mainChildAction = array(); $childChildAction = array(); $modules = \Yii::$app->getModules(); $plugin_array = array(); $like_array = array(); $i = 3; $query_like = ""; $plugin_primary_array = array(':name' => "common%", ':name1' => "frontend%", ':name2' => "backend%"); foreach ($modules as $key => $value) { $plugin_array[":name" . $i] = $key . '%'; $query_like .= " or name like :name" . $i; $i++; $mode_data_dynamic[$key] = $key; } $like_array = array_merge($plugin_primary_array, $plugin_array); if (Yii::$app->request->isAjax) { if (empty($_POST['controllerMode']) && empty($_POST['controller'])) { $AuthItemAction = AuthItem::find()->where(['type' => 2])->andWhere('name like :name or name like :name1 or name like :name2 or name like :name3' . $query_like, $like_array)->asArray()->all(); } else { if (!empty($_POST['controllerMode'])) { $condition = 'name like :name1 or name like :name2'; $conditions[':name1'] = "" . $_POST['controllerMode'] . "%"; $conditions[':name2'] = "cfusermgmt:" . $_POST['controllerMode'] . "%"; } if (!empty($_POST['controller'])) { if (strpos($_POST['controller'], "cfusermgmt:") === 0) { $_POST['controller'] = substr($_POST['controller'], strlen('cfusermgmt:')); } //echo $_POST['controller'];exit; $condition = 'name like :name3'; $conditions[':name3'] = "%" . $_POST['controller'] . "%"; } if (!empty($_POST['controllerMode']) && !empty($_POST['controller'])) { $condition = '(name like :name1 or name like :name2) and name like :name3'; } $AuthItemAction = AuthItem::find()->where(['type' => 2])->andWhere($condition, $conditions)->asArray()->all(); } if (!empty($_POST['id'])) { $queryData = AuthItem::find()->where(['type' => 1])->andWhere('name != :name', ['name' => $_POST['id']])->asArray()->all(); $queryData1 = AuthItemChild::find()->where(['parent' => $_POST['id']])->asArray()->all(); $roleChild = array(); $childData = AuthItemChild::getChild($_POST['id'], $childArray); if ($childData) { $roleChild = $childData; } if ($queryData) { $AuthItemRole = array(); foreach ($queryData as $key => $value) { $AuthItemRole[$value['name']] = $value['name']; } if ($queryData1) { foreach ($queryData1 as $key => $value) { if (!in_array($value['child'], $AuthItemRole)) { $mainChildAction[] = $value['child']; } } } } if ($roleChild || !empty($_POST['child'])) { if (!empty($_POST['child'])) { $roleChild = explode(',', $_POST['child']); } $queryData2 = AuthItemChild::find()->where(['parent' => $roleChild])->asArray()->all(); if ($queryData2) { foreach ($queryData2 as $key => $value) { // if (strpos($value['child'],':') !== false) { // $newVal = explode(':', $value['child']); // $value['child'] = $newVal[2]; // } $childChildAction[] = $value['child']; } } } } return $this->render('role-permission', ['allAuthItem' => $AuthItemAction, 'childChildAction' => $childChildAction, 'mainChildAction' => $mainChildAction]); } }