public function actionLoad() { $home_base_path = Yii::$app->params['home_base_path']; $ext_base_path = EXT_BASE_PATH; $modules = \Yii::$app->getModules(); $data_modules_paths = array(); $plugin_array = array(); foreach ($modules as $key => $value) { $obj = \Yii::$app->getModule($key); $data_modules_paths[] = $obj->controllerNamespace; $plugin_array[$obj->controllerNamespace] = $key; } $fileType = 'Controller.php'; $baseController = 'yii\\web\\Controller'; $dirName = array('common', 'backend', 'frontend'); $dirName = array_merge($data_modules_paths, $dirName); $cList = array(); $allFunctionList = array(); foreach ($dirName as $key => $value) { $pos = strpos($value, "controllers"); $dirCon = str_replace('\\', DS, $value); if ($pos == false && file_exists($home_base_path . $dirCon . DS . 'controllers')) { $cList['home'][$value] = scandir($home_base_path . $dirCon . DS . 'controllers'); } elseif ($pos == true && file_exists($home_base_path . $dirCon)) { $cList['plugin'][$value] = scandir($home_base_path . $dirCon); } } $parentMethodList = get_class_methods($baseController); //echo "<pre>"; //print_r(\yii\helpers\Inflector::camel2id($cList['plugin']['vendor\codefire\cfusermgmt\controllers'][3]));die; // print_r($parentMethodList);die; $actionList = array(); $i = 0; foreach ($cList as $key => $value) { if ($value) { foreach ($value as $key0 => $value0) { if ($value0) { foreach ($value0 as $key1 => $value1) { if (substr($value1, -14) == $fileType) { $value1 = substr($value1, 0, -4); if ($key != 'home') { $classFullName = $key0 . '\\' . $value1; } else { $classFullName = $key0 . '\\controllers\\' . $value1; } //echo $classFullName; $controllerName = substr($value1, 0, -10); $currentList = get_class_methods($classFullName); if ($currentList && $parentMethodList) { $newList = array_diff($currentList, $parentMethodList); } else { $newList = array(); } $methodList = array(); foreach ($newList as $key2 => $value2) { $methodList[] = substr($value2, 6); if ($key != 'home') { $allFunctionList[$i]['name'] = $plugin_array[$key0] . ':' . \yii\helpers\Inflector::camel2id($controllerName) . ':' . substr($value2, 6); } else { $allFunctionList[$i]['name'] = $key0 . ':' . \yii\helpers\Inflector::camel2id($controllerName) . ':' . substr($value2, 6); } $allFunctionList[$i]['type'] = 2; $allFunctionList[$i]['description'] = 'Allow call to ' . $controllerName . ' ' . substr($value2, 6) . ''; $i++; } $actionList[$key0][$controllerName] = $methodList; } } } } } } $allEntries = AuthItem::find()->where("name like '%:%'")->all(); $entryOld = []; foreach ($allEntries as $entry) { $entryOld[] = $entry->name; } $entryNew = []; foreach ($allFunctionList as $fun) { $entryNew[] = $fun["name"]; } $deletedMethods = array_diff($entryOld, $entryNew); AuthItem::deleteAll(["name" => $deletedMethods]); foreach ($allFunctionList as $key => $value) { $AuthItem = AuthItem::findOne(['name' => $value['name']]); if (!$AuthItem) { $AuthItem = new AuthItem(); $AuthItem->name = $value['name']; $AuthItem->type = 2; $AuthItem->description = $value['description']; $AuthItem->save(); } } return $this->render('group-permission', ['allFunctionList' => $allFunctionList]); }
public function actionDeleteRole() { $name = $_POST['id']; if (Yii::$app->request->isAjax) { Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; if (strtolower($name) == strtolower(SUPER_ADMIN_ROLE_NAME)) { return ['status' => 'blocked', 'message' => 'This role can never be deleted as it is SuperAdmin(' . SUPER_ADMIN_ROLE_NAME . ')']; } if (isset($_POST['confirmed']) && !empty($_POST['confirmed'])) { $model = AuthItem::findOne($name); if (isset($model) && !empty($model)) { return $model->deleteAll(['name' => $model->name]) ? ['status' => 'success', 'recordDeleted' => DELETED] : ['status' => 'failure']; } } else { $modelChildren = AuthItemChild::getAllChildren($name); $modelParent = AuthItemChild::getAllParent($name); if (count($modelParent) != 0 || count($modelChildren) != 0) { return ['status' => 'staged', 'childOrParent' => true, 'children' => count($modelChildren), 'parent' => count($modelParent)]; } else { return ['status' => 'staged', 'childOrParent' => false]; } } } }