public function actionIndex() { $lang = new Lang(); $lang->scenario = 'restcreate'; $lang->attributes = ['name' => 'Deutsch', 'short_code' => 'de', 'is_default' => 0]; $lang->save(false); foreach ($this->pages as $d) { $model = new Nav(); $navItemId = $model->createPage($d['parent'], 1, 1, $d['title'], $d['alias'], 1, 'Description of ' . $d['title']); if ($navItemId) { $item = NavItem::findOne(['alias' => $d['alias']]); if ($item) { $item->nav->updateAttributes(['is_offline' => 0, 'is_hidden' => 0]); } } } foreach ($this->redirects as $redir) { $model = new Nav(); $redirItemId = $model->createRedirect($redir['parent'], 1, 1, $redir['title'], $redir['alias'], $redir['type'], $redir['typeValue'], 'Description of ' . $redir['title']); if ($redirItemId) { $item = NavItem::findOne(['alias' => $redir['alias']]); if ($item) { $item->nav->updateAttributes(['is_offline' => 0, 'is_hidden' => 0]); } } } }
public function actionIndex($itemId, $version = false) { if (Yii::$app->adminuser->isGuest) { throw new ForbiddenHttpException('Unable to see the preview page, session expired or not logged in.'); } $navItem = NavItem::findOne($itemId); if (!$navItem) { throw new NotFoundHttpException("The requested nav item with id {$itemId} does not exist."); } $langShortCode = $navItem->lang->short_code; Yii::$app->composition['langShortCode'] = $langShortCode; $item = Yii::$app->menu->find()->where(['id' => $itemId])->with('hidden')->lang($langShortCode)->one(); // this item is still offline so we have to inject and fake it with the inject api if (!$item) { // create new item to inject $inject = new InjectItem(['id' => $itemId, 'navId' => $navItem->nav->id, 'childOf' => Yii::$app->menu->home->id, 'title' => $navItem->title, 'alias' => $navItem->alias, 'isHidden' => true]); // inject item into menu component Yii::$app->menu->injectItem($inject); // find the inject menu item $item = Yii::$app->menu->find()->where(['id' => $inject->id])->with('hidden')->lang($langShortCode)->one(); // something really went wrong while finding injected item if (!$item) { throw new NotFoundHttpException("Unable to find the preview for this ID, maybe the page is still Offline?"); } } // set the current item, as it would be resolved wrong from the url manager / request path Yii::$app->menu->current = $item; return $this->renderContent($this->renderItem($itemId, null, $version)); }
public function getRowDescriber() { if (!empty($this->row_id)) { switch ($this->table_name) { case "nav": return Nav::findOne($this->row_id)->activeLanguageItem->title; case "nav_item": return NavItem::findOne($this->row_id)->title; case "cms_nav_item_page_block_item": $block = NavItemPageBlockItem::findOne($this->row_id); if (!$block || $block->block == null) { $arr = $this->getMessageArray(); if (!empty($arr) && isset($arr['blockName'])) { return $arr['blockName'] . " ({$arr['pageTitle']})"; } else { return; } } return $block->block->getNameForLog() . " (" . $block->droppedPageTitle . ")"; } } }
/** * * @param unknown $parentNavId * @param unknown $navContainerId * @param unknown $langId * @param unknown $title * @param unknown $alias * @param unknown $description * @param unknown $fromDraftNavId * @param string $isDraft * @return boolean */ public function createPageFromDraft($parentNavId, $navContainerId, $langId, $title, $alias, $description, $fromDraftNavId, $isDraft = false) { if (!$isDraft && empty($isDraft) && !is_numeric($isDraft)) { $isDraft = 0; } $errors = []; // nav $nav = $this; $nav->attributes = ['parent_nav_id' => $parentNavId, 'nav_container_id' => $navContainerId, 'is_hidden' => 1, 'is_offline' => 1, 'is_draft' => $isDraft]; // nav item $navItem = new NavItem(); $navItem->parent_nav_id = $parentNavId; $navItem->attributes = ['lang_id' => $langId, 'title' => $title, 'alias' => $alias, 'description' => $description, 'nav_item_type' => 1]; if (!$nav->validate()) { $errors = ArrayHelper::merge($nav->getErrors(), $errors); } if (!$navItem->validate()) { $errors = ArrayHelper::merge($navItem->getErrors(), $errors); } if (!empty($errors)) { return $errors; } // get draft nav item data $draftNavItem = NavItem::findOne(['nav_id' => $fromDraftNavId]); $navItemPageId = $draftNavItem->type->id; $layoutId = $draftNavItem->type->layout_id; $pageBlocks = NavItemPageBlockItem::findAll(['nav_item_page_id' => $navItemPageId]); // proceed save process $nav->save(); $navItemPage = new NavItemPage(); $navItemPage->layout_id = $layoutId; $navItemPage->timestamp_create = time(); $navItemPage->version_alias = Module::VERSION_INIT_LABEL; $navItemPage->create_user_id = Module::getAuthorUserId(); $navItemPage->nav_item_id = 0; if (!$navItemPage->validate()) { return $navItemPage->getErrors(); } $navItemPage->save(); foreach ($pageBlocks as $block) { $i = new NavItemPageBlockItem(); $i->attributes = $block->toArray(); $i->nav_item_page_id = $navItemPage->id; $i->insert(); } $navItem->nav_id = $nav->id; $navItem->nav_item_type_id = $navItemPage->id; $navItem->save(); $navItemPage->updateAttributes(['nav_item_id' => $navItem->id]); return true; }
/** * This method is used to force the parent nav item for the corresponding page item. The default * implemenation `getNavItem` works the invert way. * * @return \luya\cms\models\NavItem */ public function getForceNavItem() { return NavItem::findOne($this->nav_item_id); }
/** * returns all the PAGE type specific informations. */ public function actionTypePageContainer($navItemId) { $navItem = NavItem::findOne($navItemId); $type = $navItem->getType(); $layout = Layout::findOne($type->layout_id); if (!empty($layout)) { $layout->json_config = json_decode($layout->json_config, true); } return ['layout' => $layout, 'type_container' => $type]; }