Example #1
5
 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 init()
 {
     foreach (NavItem::fromModule('gallery') as $item) {
         $this->_dropdown[] = ['value' => $item->id, 'label' => $item->title];
     }
     foreach (Album::find()->asArray()->all() as $item) {
         $this->_alben[] = ['value' => $item['id'], 'label' => $item['title']];
     }
 }
 public function testFieldSelectionBasicInjector()
 {
     $block = new Block();
     $injector = new ActiveQueryCheckboxInjector(['query' => NavItem::find()->select(['title']), 'varName' => 'test', 'varLabel' => 'test label', 'context' => $block]);
     $injector->setup();
     $vars = $block->getConfigVarsExport();
     $v = $vars[0];
     $this->assertSame('test', $v['var']);
     $this->assertSame('test label', $v['label']);
     $items = $v['options']['items'];
     $this->assertNotEmpty(count($items));
     $item1 = $v['options']['items'][0];
     $this->assertSame('Homepage', $item1['label']);
 }
 public function actionVersions()
 {
     if (Config::has('luya_cmsadmin_updater_versions')) {
         return $this->outputError("You already have run the version updater, so your system should be up-to-date already.");
     }
     echo $this->outputInfo("Starting VERSIONS updater");
     foreach (NavItem::find()->all() as $item) {
         if ($item->nav_item_type !== NavItem::TYPE_PAGE) {
             echo $this->output('- Skip "' . $item->title . '" as its not a page type (module or redirect)');
             continue;
         }
         $typeModel = $item->getType();
         $typeModel->updateAttributes(['nav_item_id' => $item->id, 'timestamp_create' => $item->timestamp_create, 'create_user_id' => $item->create_user_id, 'version_alias' => Module::VERSION_INIT_LABEL]);
         $this->outputSuccess('- updated: ' . $item->title);
     }
     Config::set('luya_cmsadmin_updater_versions', time());
     return $this->outputSuccess('We have successfully updated your version index.');
 }
Example #6
0
 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 . ")";
         }
     }
 }
Example #7
0
 /**
  * Render the NavItem content and set several view specific data.
  *
  * @param integer $navItemId
  * @param string $appendix
  * @param boolean|integer $setNavItemTypeId To get the content of a version this parameter will change the database value from the nav item Model
  * to this provided value
  *
  * @throws NotFoundHttpException
  * @throws MethodNotAllowedHttpException
  */
 public function renderItem($navItemId, $appendix = null, $setNavItemTypeId = false)
 {
     $model = NavItem::find()->where(['id' => $navItemId])->with('nav')->one();
     if (!$model) {
         throw new NotFoundHttpException('The requested nav item could not found.');
     }
     Yii::$app->urlManager->contextNavItemId = $navItemId;
     Yii::$app->set('page', ['class' => 'luya\\cms\\frontend\\components\\Page', 'model' => $model]);
     $currentMenu = Yii::$app->menu->current;
     $event = new BeforeRenderEvent();
     $event->menu = $currentMenu;
     foreach ($model->nav->getProperties() as $property) {
         $object = $property->getObject();
         $object->trigger($object::EVENT_BEFORE_RENDER, $event);
         if (!$event->isValid) {
             throw new MethodNotAllowedHttpException('Your are not allowed to see this page.');
             return Yii::$app->end();
         }
     }
     if ($setNavItemTypeId !== false && !empty($setNavItemTypeId)) {
         $model->nav_item_type_id = $setNavItemTypeId;
     }
     $typeModel = $model->getType();
     if (!$typeModel) {
         throw new NotFoundHttpException("The requestd nav item could not be found with the paired type, maybe this version does not exists for this Type.");
     }
     $typeModel->setOptions(['navItemId' => $navItemId, 'restString' => $appendix]);
     $content = $typeModel->getContent();
     if ($content instanceof Response) {
         return Yii::$app->end(0, $content);
     }
     // it seems to be a json response as it is an array
     if (is_array($content)) {
         return $content;
     }
     // https://github.com/luyadev/luya/issues/863 - if context controller is not false and the layout variable is not empty, the layout file will be displayed
     // as its already renderd by the module controller itself.
     if ($typeModel->controller !== false && !empty($typeModel->controller->layout)) {
         $this->layout = false;
     }
     if ($this->view->title === null) {
         if (empty($model->title_tag)) {
             $this->view->title = $model->title;
         } else {
             $this->view->title = $model->title_tag;
         }
     }
     $this->view->registerMetaTag(['name' => 'og:title', 'content' => $this->view->title], 'fbTitle');
     $this->view->registerMetaTag(['name' => 'og:type', 'content' => 'website'], 'ogType');
     if (!empty($model->description)) {
         $this->view->registerMetaTag(['name' => 'description', 'content' => $model->description], 'metaDescription');
         $this->view->registerMetaTag(['name' => 'og:description', 'content' => $model->description], 'fbDescription');
     }
     if (!empty($model->keywords)) {
         $this->view->registerMetaTag(['name' => 'keywords', 'content' => implode(", ", $currentMenu->keywords)], 'metyKeywords');
     }
     if ($this->module->enableTagParsing) {
         $content = TagParser::convert($content);
     }
     if (Yii::$app->has('adminuser') && !Yii::$app->adminuser->isGuest && $this->module->overlayToolbar === true) {
         $this->view->registerCssFile('https://fonts.googleapis.com/icon?family=Material+Icons');
         $this->getView()->on(View::EVENT_BEGIN_BODY, [$this, 'renderToolbar'], ['content' => $content]);
     }
     return $content;
 }
Example #8
0
 public function init()
 {
     foreach (NavItem::fromModule('news') as $item) {
         $this->_dropdown[] = ['value' => $item->id, 'label' => $item->title];
     }
 }
 public function actionDelete($navId)
 {
     $model = 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);
     }
 }
Example #10
0
 /**
  * Get the corresponding nav item type for this type object
  */
 public function getNavItem()
 {
     return $this->hasOne(NavItem::className(), ['nav_item_type_id' => 'id'])->where(['nav_item_type' => static::getNummericType()]);
 }
Example #11
0
 /**
  *
  * @param unknown $navId
  * @param unknown $langId
  * @param unknown $title
  * @param unknown $alias
  * @param unknown $redirectType The type of redirect (1 = page, 2 = URL, 3 = Link to File)
  * @param unknown $redirectTypeValue Depending on the type (1 = cms_nav.id, 2 = http://luya.io)
  * @param unknown $description
  * @return boolean
  */
 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 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;
 }
Example #12
0
 /**
  * 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);
 }
 /**
  * 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;
 }