public function updateNotice() { $moduleName = \yii\easyii\components\Module::getModuleName(get_class($this->owner)); if ($module = Module::findOne(['name' => $moduleName])) { $module->notice = call_user_func($this->callback); $module->update(); } }
public function actionViewall() { Guestbook::updateAll(['new' => 0]); $module = \yii\easyii\models\Module::findOne(['name' => 'guestbook']); $module->notice = 0; $module->save(); $this->flash('success', Yii::t('easyii/guestbook', 'Guestbook updated')); return $this->back(); }
/** * 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; }
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')); }
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(); }
public function down() { $this->dropTable(models\Admin::tableName()); $this->dropTable(models\LoginForm::tableName()); $this->dropTable(models\Module::tableName()); $this->dropTable(models\Photo::tableName()); $this->dropTable(models\Setting::tableName()); $this->dropTable(Carousel::tableName()); $this->dropTable(Category::tableName()); $this->dropTable(Item::tableName()); $this->dropTable(Feedback::tableName()); $this->dropTable(File::tableName()); $this->dropTable(Album::tableName()); $this->dropTable(Guestbook::tableName()); $this->dropTable(News::tableName()); $this->dropTable(Page::tableName()); $this->dropTable(Subscriber::tableName()); $this->dropTable(History::tableName()); $this->dropTable(Text::tableName()); }
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(); } } }
private function installModules() { $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; $module = new Module(['name' => $moduleName, 'class' => $moduleClass, 'title' => !empty($moduleConfig['title'][$language]) ? $moduleConfig['title'][$language] : $moduleConfig['title']['en'], 'icon' => $moduleConfig['icon'], 'settings' => Yii::createObject($moduleClass, [$moduleName])->settings, 'order_num' => $moduleConfig['order_num'], 'status' => Module::STATUS_ON]); $module->save(); } }
public function actionDelete($id) { if ($model = Module::findOne($id)) { $model->delete(); } else { $this->error = Yii::t('easyii', 'Not found'); } return $this->formatResponse(Yii::t('easyii', 'Module deleted')); }
public function rules() { return [[['title', 'name'], 'required'], ['name', 'match', 'pattern' => '/^[\\w]+$/'], ['name', 'unique', 'targetClass' => Module::className()]]; }
public function down() { $this->dropTable(models\Admin::tableName()); $this->dropTable(models\LoginForm::tableName()); $this->dropTable(models\Module::tableName()); $this->dropTable(models\Photo::tableName()); $this->dropTable(models\Setting::tableName()); $this->dropTable(Carousel::tableName()); $this->dropTable(catalog\models\Category::tableName()); $this->dropTable(catalog\models\Item::tableName()); $this->dropTable(article\models\Category::tableName()); $this->dropTable(article\models\Item::tableName()); $this->dropTable(Feedback::tableName()); $this->dropTable(File::tableName()); $this->dropTable(gallery\models\Category::tableName()); $this->dropTable(Guestbook::tableName()); $this->dropTable(News::tableName()); $this->dropTable(Page::tableName()); $this->dropTable(Subscriber::tableName()); $this->dropTable(History::tableName()); $this->dropTable(Text::tableName()); $this->dropTable(Menu::tableName()); $this->dropTable(MenuItem::tableName()); }