Exemple #1
0
 public function renderItem($navItemId, $appendix = null)
 {
     $model = NavItem::findOne($navItemId);
     if (!$model) {
         throw new NotFoundHttpException('The requested nav item could not found.');
     }
     Yii::$app->urlManager->contextNavItemId = $navItemId;
     Yii::$app->set('page', ['class' => 'cms\\components\\Page', 'model' => $model]);
     $event = new \cms\events\BeforeRenderEvent();
     foreach ($model->getNav()->getProperties() as $property) {
         $object = $model->getNav()->getProperty($property['var_name']);
         $object->trigger($object::EVENT_BEFORE_RENDER, $event);
         if (!$event->isValid) {
             Yii::$app->end();
         }
     }
     $typeModel = $model->getType();
     $typeModel->setOptions(['cmsControllerObject' => $this, 'navItemId' => $navItemId, 'restString' => $appendix]);
     $content = $typeModel->getContent();
     if ($this->view->title === null) {
         $this->view->title = $model->title;
     }
     $this->view->registerMetaTag(['name' => 'og:title', 'content' => $this->view->title], 'fbTitle');
     if (!empty($model->description)) {
         $this->view->registerMetaTag(['name' => 'description', 'content' => $model->description], 'metaDescription');
         $this->view->registerMetaTag(['name' => 'og:description', 'content' => $model->description], 'fbDescription');
     }
     if ($this->module->enableTagParsing) {
         $content = Parser::encode($content);
     }
     return $content;
 }
Exemple #2
0
 /**
  * Helper method to create a route based on the module name and the route and params.
  * 
  * @param string $moduleName The ID of the module, which should be found inside the nav items.
  * @param string $route      The route for the url rules
  * @param array  $params     The parameters for the url rule
  *
  * @throws Exception
  *
  * @return string
  *
  * @see \luya\helpers\Url::toModule()
  */
 public static function toModuleRoute($moduleName, $route, array $params = [])
 {
     $model = NavItem::findNavItem($moduleName);
     if ($model) {
         return static::toMenuItem($model['id'], $route, $params);
     }
     throw new Exception("The module route creation could not find the module '{$moduleName}', have you created a page with this module in this langauge context?");
 }
Exemple #3
0
 public function init()
 {
     foreach (\cmsadmin\models\NavItem::fromModule('gallery') as $item) {
         $this->_dropdown[] = ['value' => $item->id, 'label' => $item->title];
     }
     foreach (\galleryadmin\models\Album::find()->asArray()->all() as $item) {
         $this->_alben[] = ['value' => $item['id'], 'label' => $item['title']];
     }
 }
Exemple #4
0
 /**
  * returns all the PAGE type specific informations.
  */
 public function actionTypePageContainer($navItemId)
 {
     $navItem = NavItem::findOne($navItemId);
     $type = $navItem->getType();
     $layout = \cmsadmin\models\Layout::findOne($type->layout_id);
     if (!empty($layout)) {
         $layout->json_config = json_decode($layout->json_config, true);
     }
     return ['layout' => $layout, 'type_container' => $type];
 }
Exemple #5
0
 public function renderItem($navItemId, $appendix = null)
 {
     $model = NavItem::findOne($navItemId);
     $typeModel = $model->getType();
     $typeModel->setOptions(['navItemId' => $navItemId, 'restString' => $appendix]);
     $content = $typeModel->getContent();
     if ($this->view->title === null) {
         $this->view->title = $model->title;
     }
     return $content;
 }
Exemple #6
0
 /**
  * if the module could not be found (not registered in the cms) the method returns the provided module name.
  * 
  * returns only ONE even if there are more! not good structure inside the cms?
  * 
  * @param string $moduleName
  * @return url
  */
 public static function toModule($moduleName)
 {
     $model = NavItem::find()->leftJoin('cms_nav_item_module', 'nav_item_type_id=cms_nav_item_module.id')->where(['nav_item_type' => 2, 'cms_nav_item_module.module_name' => $moduleName])->asArray()->one();
     if ($model) {
         $link = Yii::$app->links->findOneByArguments(['id' => $model['id']]);
         if ($link) {
             return $link['full_url'];
         }
     }
     return $moduleName;
 }
 public function actionIndex($itemId)
 {
     if (Yii::$app->adminuser->isGuest) {
         throw new ForbiddenHttpException('Unable to see the preview page, session expired or not logged in.');
     }
     $langShortCode = NavItem::findOne($itemId)->lang->short_code;
     Yii::$app->composition['langShortCode'] = $langShortCode;
     $item = Yii::$app->menu->find()->where(['id' => $itemId])->with('hidden')->lang($langShortCode)->one();
     if (!$item) {
         throw new NotFoundHttpException("Unable to find item id {$itemId}");
     }
     return $this->render('index', ['pageContent' => $this->renderItem($itemId)]);
 }
 /**
  * Get full constructed of a nav item.
  *
  * @param $navId
  * @return string Path
  */
 public function actionGetNavItemPath($navId)
 {
     $data = "";
     $node = NavItem::find()->where(['nav_id' => $navId])->one();
     if ($node) {
         $data .= $node->title;
         $parentNavId = $navId;
         while ($parentNavId != 0) {
             $parentNavId = Nav::findOne($parentNavId)->parent_nav_id;
             if ($parentNavId != 0) {
                 $node = NavItem::find()->where(['nav_id' => $parentNavId])->one();
                 if ($parentNavId) {
                     $data = $node->title . '/' . $data;
                 }
             }
         }
     }
     return $data;
 }
Exemple #9
0
 public function init()
 {
     foreach (\cmsadmin\models\NavItem::fromModule('news') as $item) {
         $this->_dropdown[] = ['value' => $item->id, 'label' => $item->title];
     }
 }
Exemple #10
0
 public function actionDelete($navId)
 {
     $model = \cmsadmin\models\Nav::find()->where(['id' => $navId])->one();
     if ($model) {
         Yii::$app->menu->flushCache();
         // check for internal redirects
         $redirectResult = false;
         $redirects = NavItemRedirect::find()->where(['value' => $navId])->asArray()->all();
         foreach ($redirects as $redirect) {
             $navItem = NavItem::find()->where(['nav_item_type' => 3, 'nav_item_type_id' => $redirect['id']])->one();
             $redirectResult = empty(Nav::find()->where(['id' => $navItem->nav_id, 'is_deleted' => 0])->one()) ? $redirectResult : true;
         }
         if ($redirectResult) {
             Yii::$app->response->statusCode = 417;
             return;
         }
         $model->is_deleted = 1;
         foreach (NavItem::find()->where(['nav_id' => $navId])->all() as $navItem) {
             $navItem->setAttribute('alias', date('Y-m-d-H-i') . '-' . $navItem->alias);
             $navItem->update(false);
         }
         return $model->update(false);
     }
 }
Exemple #11
0
 public function createRedirectItem($navId, $langId, $title, $alias, $redirectType, $redirectTypeValue, $description)
 {
     $_errors = [];
     $navItem = new NavItem();
     $navItem->parent_nav_id = self::findOne($navId)->parent_nav_id;
     $navItemRedirect = new \cmsadmin\models\NavItemRedirect();
     $navItem->attributes = ['nav_id' => $navId, 'lang_id' => $langId, 'title' => $title, 'alias' => $alias, 'description' => $description, 'nav_item_type' => 3];
     $navItemRedirect->attributes = ['type' => $redirectType, 'value' => $redirectTypeValue];
     if (!$navItem->validate()) {
         $_errors = ArrayHelper::merge($navItem->getErrors(), $_errors);
     }
     if (!$navItemRedirect->validate()) {
         $_errors = ArrayHelper::merge($navItemRedirect->getErrors(), $_errors);
     }
     if (!empty($_errors)) {
         return $_errors;
     }
     $navItemRedirect->save();
     $navItem->nav_item_type_id = $navItemRedirect->id;
     $navItemId = $navItem->save();
     return $navItemId;
 }
Exemple #12
0
 public function getNavItems()
 {
     return $this->hasMany(\cmsadmin\models\NavItem::className(), ['nav_id' => 'id']);
 }
Exemple #13
0
 public function actionDelete($navId)
 {
     $model = \cmsadmin\models\Nav::find()->where(['id' => $navId])->one();
     if ($model) {
         $model->is_deleted = 1;
         foreach (NavItem::find()->where(['nav_id' => $navId])->all() as $navItem) {
             $navItem->setAttribute('alias', date('Y-m-d-H-i') . '-' . $navItem->alias);
             $navItem->update(false);
         }
         return $model->update(false);
     }
 }