Пример #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]);
             }
         }
     }
 }
Пример #2
0
 public function testFindContent()
 {
     $nav = Nav::findOne(1);
     /* @var $item \luya\cms\models\NavItem */
     $item = $nav->activeLanguageItem;
     $this->assertSame('Homepage', $item->title);
     $this->assertSame('homepage', $item->alias);
 }
Пример #3
0
 private static function getNavItems()
 {
     if (self::$_navItems === null) {
         $items = Nav::find()->select(['sort_index', 'id', 'parent_nav_id', 'is_deleted'])->where(['is_deleted' => 0])->orderBy(['sort_index' => SORT_ASC])->asArray()->all();
         return self::$_navItems = ArrayHelper::index($items, null, 'parent_nav_id');
     }
     return self::$_navItems;
 }
Пример #4
0
 /**
  * Get the content of Nav for the current active language with cmslayout or placeholder.
  *
  * @param string $value The value of the Nav ID e.g 1 (hover the cms menu to see the ID).
  * @param string|null $sub If null this parameter will be ignored otherwise its the name of the placeholder inside this cmslayout.
  * @return string The content rendered with the cmslayout, or if $sub is provided and not null with its placeholder name.
  * @see \luya\tag\TagInterface::parse()
  */
 public function parse($value, $sub)
 {
     $page = Nav::findOne($value);
     // verify if the page is of type content
     if ($page) {
         if ($page->activeLanguageItem->nav_item_type !== NavItem::TYPE_PAGE) {
             return null;
         }
         if (empty($sub)) {
             return $page->activeLanguageItem->getContent();
         } else {
             return $page->activeLanguageItem->type->renderPlaceholder($sub);
         }
     }
     return null;
 }
Пример #5
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 . ")";
         }
     }
 }
Пример #6
0
 /**
  * This method allows you the retrieve a property for an page property. If the property is not found false will be retunrend
  * otherwhise the property object itself will be returned (implements `\admin\base\Property`) so you can retrieve the value of the
  * property by calling your custom method or the default `getValue()` method.
  *
  * @param string $varName The variable name of the property defined inside of the property of the method `varName()`.
  * @since 1.0.0-beta8
  */
 public function getProperty($varName)
 {
     if ($this->_model === null) {
         $this->_model = Nav::findOne($this->navId);
     }
     if (empty($this->_model)) {
         throw new Exception('The model active record could not be found for the corresponding nav item. Maybe you have inconsistent Database data.');
     }
     return $this->_model->getProperty($varName);
 }
Пример #7
0
 public function actionCreateFromPage()
 {
     Yii::$app->menu->flushCache();
     $model = new Nav();
     $create = $model->createItemLanguageCopy($this->postArg('id'), $this->postArg('toLangId'), $this->postArg('title'), $this->postArg('alias'));
     if ($create !== true) {
         Yii::$app->response->statusCode = 422;
     }
     return $create;
 }
Пример #8
0
 /**
  * Get the related nav entry for this nav_item.
  *
  * @return ActiveQuery
  */
 public function getNav()
 {
     return $this->hasOne(Nav::className(), ['id' => 'nav_id']);
 }
Пример #9
0
 /**
  * Get Container name for a nav item.
  *
  * @param $navId
  * @return string Container name
  */
 public function actionGetNavContainerName($navId)
 {
     $nav = Nav::findOne($navId);
     if ($nav) {
         $navCoontainer = NavContainer::findOne($nav->nav_container_id);
         if ($navCoontainer) {
             return $navCoontainer->name;
         }
     }
     return "";
 }