Exemplo n.º 1
0
 /**
  * Module name getter
  *
  * @param $namespace
  * @return string|bool
  */
 public static function getModuleName($namespace)
 {
     foreach (ModuleModel::findAllActive() as $module) {
         $moduleClassPath = preg_replace('/[\\w]+$/', '', $module->class);
         if (strpos($namespace, $moduleClassPath) !== false) {
             return $module->name;
         }
     }
     return false;
 }
Exemplo n.º 2
0
 public function init()
 {
     parent::init();
     if (Yii::$app->cache === null) {
         throw new \yii\web\ServerErrorHttpException('Please configure Cache component.');
     }
     $this->activeModules = Module::findAllActive();
     $modules = [];
     foreach ($this->activeModules as $name => $module) {
         $modules[$name]['class'] = $module->class;
         if (is_array($module->settings)) {
             $modules[$name]['settings'] = $module->settings;
         }
     }
     $this->setModules($modules);
     define('IS_ROOT', !Yii::$app->user->isGuest && Yii::$app->user->identity->isRoot());
     define('LIVE_EDIT', !Yii::$app->user->isGuest && Yii::$app->session->get('easyii_live_edit'));
 }
Exemplo n.º 3
0
 public function actionClearModuleSettings()
 {
     $activedModules = \yii\easyii\models\Module::findAllActive();
     $language = Data::getLocale();
     foreach (glob(Yii::getAlias('@easyii') . DIRECTORY_SEPARATOR . 'modules/*') as $module) {
         $moduleName = basename($module);
         $moduleClass = 'yii\\easyii\\modules\\' . $moduleName . '\\' . ucfirst($moduleName) . 'Module';
         $moduleConfig = $moduleClass::$installConfig;
         $installedModule = $activedModules[$moduleName];
         $module = Module::findOne($installedModule->module_id);
         $module->title = !empty($moduleConfig['title'][$language]) ? $moduleConfig['title'][$language] : $moduleConfig['title']['en'];
         $module->settings = Yii::createObject($moduleClass, [$moduleName])->settings;
         $module->order_num = $moduleConfig['order_num'];
         $module->icon = $moduleConfig['icon'];
         $module->status = Module::STATUS_ON;
         $module->save();
     }
     return $this->back();
 }
Exemplo n.º 4
0
 public function init()
 {
     parent::init();
     if (Yii::$app->cache === null) {
         throw new \yii\web\ServerErrorHttpException('Please configure Cache component.');
     }
     $this->activeModules = Module::findAllActive();
     $modules = [];
     foreach ($this->activeModules as $name => $module) {
         $modules[$name]['class'] = $module->class;
         if (isset($this->moduleSettings[$name]) && is_array($this->moduleSettings[$name])) {
             foreach ($this->moduleSettings[$name] as $param => $value) {
                 $module->settings[$param] = $value;
             }
         }
         if (is_array($module->settings)) {
             $modules[$name]['settings'] = $module->settings;
         }
         if (isset($this->modules[$name])) {
             foreach ($this->modules[$name] as $param => $value) {
                 if (isset($modules[$name][$param]) && is_array($modules[$name][$param])) {
                     $modules[$name][$param] = ArrayHelper::merge($modules[$name][$param], $value);
                 } else {
                     $modules[$name][$param] = $value;
                 }
             }
             unset($this->modules[$name]);
         }
     }
     $this->setModules($modules);
     if (Yii::$app instanceof \yii\web\Application) {
         $this->webInit();
     } else {
         if (Yii::$app instanceof \yii\console\Application) {
             $this->consoleInit();
         }
     }
 }