public function settingsAfterLanguage() { if ($this->owner->{$this->settingsField} !== '' and $this->owner->{$this->settingsField} !== null) { $this->owner->{$this->settingsField} = json_decode($this->owner->{$this->settingsField}, true); } elseif ($this->module === false) { } else { $this->owner->{$this->settingsField} = ModulesModules::getDefaultSettings($this->module); } }
/** * Module name getter * * @param $namespace * @return string|bool */ public static function getModuleName($namespace) { foreach (ModulesModules::findAllActive() as $module) { $moduleClassPath = preg_replace('/[\\w]+$/', '', $module->class); if (strpos($namespace, $moduleClassPath) !== false) { return $module->name; } } return false; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = ModulesModules::find(); $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => ['order' => SORT_ASC]]]); $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(['module_id' => $this->module_id, 'isFrontend' => $this->isFrontend, 'isAdmin' => $this->isAdmin, 'order' => $this->order, 'status' => $this->status]); $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'class', $this->class])->andFilterWhere(['like', 'controllerNamespace', $this->controllerNamespace])->andFilterWhere(['like', 'viewPath', $this->viewPath])->andFilterWhere(['like', 'AdminControllerNamespace', $this->AdminControllerNamespace])->andFilterWhere(['like', 'AdminViewPath', $this->AdminViewPath])->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'icon', $this->icon])->andFilterWhere(['like', 'settings', $this->settings]); return $dataProvider; }
public function bootstrap($app) { /** * * @var Module $adminModule * @var \app\modules\user\Module $userModule * */ if ($app->hasModule('admin') && ($adminModule = $app->getModule('admin')) instanceof Module) { /** * автоматична загрузка модулів */ $adminModule->activeModules = ModulesModules::findAllActiveAdmin(); $modules_backend = []; $modules_frontend = []; foreach ($adminModule->activeModules as $name => $module) { if (class_exists($module->class)) { if ($module->isAdmin) { $class = new \ReflectionClass($module->class); $modules_backend[$name]['class'] = $module->class; if ($class->hasProperty('controllerNamespace') && $class->getStaticPropertyValue('controllerNamespace', '') != '') { $modules_backend[$name]['controllerNamespace'] = $class->getStaticPropertyValue('controllerNamespace'); } else { $modules_backend[$name]['controllerNamespace'] = 'app\\modules\\' . $module->name . '\\controllers\\backend'; } if ($class->hasProperty('viewPath') && $class->getStaticPropertyValue('viewPath', '') != '') { $modules_backend[$name]['viewPath'] = $class->getStaticPropertyValue('viewPath'); } else { $modules_backend[$name]['viewPath'] = '@app/modules/' . $module->name . '/views/backend'; } if ($class->hasProperty('urlRulesBackend')) { foreach ($class->getStaticPropertyValue('urlRulesBackend') as $k => $item) { $this->backendUrlRules[$k] = $item; } } if ($class->hasProperty('urlRulesFrontend')) { foreach ($class->getStaticPropertyValue('urlRulesFrontend') as $k => $item) { $this->frontendUrlRules[$k] = $item; } } if ($class->hasProperty('setAppComponents')) { foreach ($class->getStaticPropertyValue('setAppComponents') as $k => $item) { $this->setAppComponents[$k] = $item; } } if (isset($module->settings) and is_array($module->settings)) { $modules_backend[$name]['settings'] = $module->settings; } } if ($module->isFrontend) { $modules_frontend[$name]['class'] = $module->class; $modules_frontend[$name]['controllerNamespace'] = 'app\\modules\\' . $module->name . '\\controllers\\frontend'; $modules_frontend[$name]['viewPath'] = '@app/modules/' . $module->name . '/views/frontend'; if (isset($module->settings) and is_array($module->settings)) { $modules_frontend[$name]['settings'] = $module->settings; } } } } Yii::$app->setComponents($this->setAppComponents); Yii::$app->setModules($modules_frontend); $adminModule->setModules($modules_backend); Yii::setAlias('admin', '@app/modules/admin'); //print_r($adminModule->urlRules + $this->backendUrlRules); $configUrlRule = ['prefix' => $adminModule->urlPrefix, 'rules' => $adminModule->urlRules + $this->backendUrlRules]; if ($adminModule->urlPrefix != 'admin') { $configUrlRule['routePrefix'] = 'admin'; } $configUrlRule['class'] = 'yii\\web\\GroupUrlRule'; $rule = Yii::createObject($configUrlRule); $app->getUrlManager()->addRules([$rule], false); if (isset($this->backendUrlRules)) { $app->getUrlManager()->addRules($this->backendUrlRules, false); } if (isset($this->frontendUrlRules)) { $app->getUrlManager()->addRules($this->frontendUrlRules, false); } $rHostInfo = Url::home(true); if (!Yii::$app->user->isGuest && strpos(Yii::$app->request->absoluteUrl, $rHostInfo . 'admin') === false && strpos(Yii::$app->request->absoluteUrl, $rHostInfo . 'gii') === false && strpos(Yii::$app->request->absoluteUrl, $rHostInfo . 'debug') === false && !Yii::$app->request->isAjax && Yii::$app->getView()->adminPanel) { $app->on(Application::EVENT_BEFORE_REQUEST, function () use($app) { Yii::$app->getView()->bodyClass[] = 'oak-admin-bar'; $app->getView()->on(\yii\web\View::EVENT_BEGIN_BODY, [$this, 'renderToolbar']); }); } } }
/** * Finds the ModulesModules model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return ModulesModules the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = ModulesModules::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }