public function actionIndex($slug, $languageSlug = null)
 {
     /**
      * @var Page $page
      */
     $pageClass = Module::getInstance()->pageModelClass;
     $page = $pageClass::findBySlug($slug);
     $language = null;
     if ($languageSlug) {
         $language = I18N::getLanguageBySlug($languageSlug);
     }
     if (!$language) {
         $language = I18N::getCurrentLanguage();
     }
     Yii::$app->language = $language['locale'];
     if (!$page) {
         throw new NotFoundHttpException(Yii::t('maddoger/website', 'Page not found.'));
     }
     $page->setLanguage($language['locale']);
     if (!$page->hasTranslation() && $page->default_language) {
         $page->setLanguage($page->default_language);
     }
     if (!$page->hasTranslation()) {
         throw new NotFoundHttpException(Yii::t('maddoger/website', 'Page not found.'));
     }
     switch ($page->status) {
         case Page::STATUS_ACTIVE:
             break;
         case Page::STATUS_AUTH_ONLY:
             if (Yii::$app->user->getIsGuest()) {
                 throw new ForbiddenHttpException(Yii::t('maddoger/website', 'You must be authenticated to view this page.'));
             }
             break;
         case Page::STATUS_HIDDEN:
             if (!Yii::$app->user->getIsGuest() && Yii::$app->user->can('website.page.viewHiddenPages')) {
                 break;
             }
             throw new NotFoundHttpException(Yii::t('maddoger/website', 'Page not found.'));
         default:
             throw new NotFoundHttpException(Yii::t('maddoger/website', 'Page not found.'));
     }
     if ($page->layout !== null && !empty($page->layout)) {
         $this->layout = $page->layout;
     } else {
         /**
          * @var $this->module Module
          */
         $this->layout = Module::getInstance()->getConfiguration()->defaultLayout ?: null;
     }
     return $this->render(Module::getInstance()->pageView, ['model' => $page]);
 }
 public function actionIndex()
 {
     $model = Config::getConfig(Module::className());
     if ($model->load(Yii::$app->request->post())) {
         //$validate = $model->validate();
         foreach (I18N::getAvailableLanguages() as $language) {
             $modelI18n = $model->getTranslation($language['locale']);
             $modelI18n->load(Yii::$app->request->post());
         }
         if ($model->save()) {
             Yii::$app->session->addFlash('success', Yii::t('maddoger/website', 'Saved.'));
             return $this->refresh();
         }
     }
     return $this->render('index', ['model' => $model]);
 }
Example #3
0
 /**
  * @return string
  * @throws ErrorException
  */
 public function run()
 {
     /**
      * @var PageModel $page
      */
     if (!Module::getInstance()) {
         if (!Yii::$app->getModule($this->moduleId)) {
             throw new ErrorException('Module "' . $this->moduleId . '" not found.');
         }
     }
     $pageClass = Module::getInstance()->pageModelClass;
     if (is_int($this->page)) {
         $page = $pageClass::findOne($this->page);
     } elseif (is_string($this->page)) {
         $page = $pageClass::findBySlug($this->page);
     } else {
         throw new InvalidParamException('Invalid page identifier.');
     }
     $language = $this->language;
     if ($language) {
         if (!is_array($language)) {
             $language = I18N::getLanguageByLocale($language);
         }
     } else {
         $language = I18N::getCurrentLanguage();
     }
     if (!$page) {
         return null;
     }
     $page->setLanguage($language['locale']);
     if (!$page->hasTranslation() && $page->default_language) {
         $page->setLanguage($page->default_language);
     }
     if (!$page->hasTranslation()) {
         return null;
     }
     $content = $this->view ? $this->render($this->view, ['model' => $page]) : $page->text;
     if ($this->title) {
         $options = $this->titleOptions;
         $tag = ArrayHelper::remove($options, 'tag', 'h2');
         $content = Html::tag($tag, is_string($this->title) ? $this->title : $page->title, $options) . $content;
     }
     $options = $this->options;
     $tag = ArrayHelper::remove($options, 'tag', 'div');
     return Html::tag($tag, $content, $options);
 }
 public function run()
 {
     /**
      * @var Page $page
      */
     if (!Module::getInstance()) {
         if (!Yii::$app->getModule($this->moduleId)) {
             throw new ErrorException('Module "' . $this->moduleId . '" not found.');
         }
     }
     $pageClass = Module::getInstance()->pageModelClass;
     if (is_int($this->page)) {
         $page = $pageClass::findOne($this->page);
     } elseif (is_string($this->page)) {
         $page = $pageClass::findBySlug($this->page);
     } else {
         throw new InvalidParamException('Invalid page identifier.');
     }
     $language = $this->language;
     if ($language) {
         if (!is_array($language)) {
             $language = I18N::getLanguageByLocale($language);
         }
     } else {
         $language = I18N::getCurrentLanguage();
     }
     Yii::$app->language = $language['locale'];
     if (!$page) {
         throw new NotFoundHttpException(Yii::t('maddoger/website', 'Page not found.'));
     }
     $page->setLanguage($language['locale']);
     if (!$page->hasTranslation() && $page->default_language) {
         $page->setLanguage($page->default_language);
     }
     if (!$page->hasTranslation()) {
         throw new NotFoundHttpException(Yii::t('maddoger/website', 'Page not found.'));
     }
     switch ($page->status) {
         case Page::STATUS_ACTIVE:
             break;
         case Page::STATUS_AUTH_ONLY:
             if (Yii::$app->user->getIsGuest()) {
                 throw new ForbiddenHttpException(Yii::t('maddoger/website', 'You must be authenticated to view this page.'));
             }
             break;
         case Page::STATUS_HIDDEN:
             if (!Yii::$app->user->getIsGuest() && Yii::$app->user->can('website.page.viewHiddenPages')) {
                 break;
             }
             throw new NotFoundHttpException(Yii::t('maddoger/website', 'Page not found.'));
         default:
             throw new NotFoundHttpException(Yii::t('maddoger/website', 'Page not found.'));
     }
     if ($page->layout !== null && !empty($page->layout)) {
         $this->controller->layout = $page->layout;
     } else {
         /**
          * @var $this ->module WebsiteModule
          */
         if (Module::getInstance()->config->defaultLayout) {
             $this->controller->layout = Module::getInstance()->config->defaultLayout;
         }
     }
     return $this->controller->render($this->view ?: Module::getInstance()->pageView, ['model' => $page]);
 }