示例#1
0
文件: NavItem.php 项目: efueger/luya
 public function getType()
 {
     switch ($this->nav_item_type) {
         case self::TYPE_PAGE:
             return \cmsadmin\models\NavItemPage::findOne($this->nav_item_type_id);
             break;
         case self::TYPE_MODULE:
             return \cmsadmin\models\NavItemModule::findOne($this->nav_item_type_id);
             break;
     }
 }
示例#2
0
 public function getType()
 {
     switch ($this->nav_item_type) {
         case self::TYPE_PAGE:
             $object = NavItemPage::findOne($this->nav_item_type_id);
             break;
         case self::TYPE_MODULE:
             $object = NavItemModule::findOne($this->nav_item_type_id);
             break;
         case self::TYPE_REDIRECT:
             $object = NavItemRedirect::findOne($this->nav_item_type_id);
             break;
     }
     // assign the current context for an item type object.
     $object->setNavItem($this);
     return $object;
 }
示例#3
0
文件: NavItem.php 项目: aekkapun/luya
 /**
  *
  * Copy content of type cms_nav_item_page to a target nav item. This will create a new entry in cms_nav_item_page and for every used block a new entry in cms_nav_item_page_block_item
  *
  * @param $targetNavItem nav item object
  * @return bool
  */
 public function copyPageItem($targetNavItem)
 {
     if ($this->nav_item_type !== 1) {
         return false;
     }
     $sourcePageItem = NavItemPage::findOne($this->nav_item_type_id);
     if (!$sourcePageItem) {
         return false;
     }
     $pageItem = new NavItemPage();
     $pageItem->attributes = $sourcePageItem->toArray();
     if (!$pageItem->save()) {
         return false;
     }
     $targetNavItem->nav_item_type_id = $pageItem->id;
     if (!$targetNavItem->save()) {
         return false;
     }
     $pageBlocks = NavItemPageBlockItem::findAll(['nav_item_page_id' => $sourcePageItem->id]);
     foreach ($pageBlocks as $block) {
         $blockItem = new NavItemPageBlockItem();
         $blockItem->attributes = $block->toArray();
         $blockItem->nav_item_page_id = $pageItem->id;
         $blockItem->insert();
     }
     return true;
 }
示例#4
0
 /**
  *
  * Copy content of type cms_nav_item_page to a target nav item. This will create a new entry in cms_nav_item_page and for every used block a new entry in cms_nav_item_page_block_item
  *
  * @param $targetNavItem nav item object
  * @return bool
  */
 public function copyPageItem($targetNavItem)
 {
     if ($this->nav_item_type !== 1) {
         return false;
     }
     $sourcePageItem = NavItemPage::findOne($this->nav_item_type_id);
     if (!$sourcePageItem) {
         return false;
     }
     $pageItem = new NavItemPage();
     $pageItem->attributes = $sourcePageItem->toArray();
     if (!$pageItem->save()) {
         return false;
     }
     $targetNavItem->nav_item_type_id = $pageItem->id;
     if (!$targetNavItem->save()) {
         return false;
     }
     $pageBlocks = NavItemPageBlockItem::findAll(['nav_item_page_id' => $sourcePageItem->id]);
     $idLink = [];
     foreach ($pageBlocks as $block) {
         $blockItem = new NavItemPageBlockItem();
         $blockItem->attributes = $block->toArray();
         $blockItem->nav_item_page_id = $pageItem->id;
         $blockItem->insert();
         $idLink[$block->id] = $blockItem->id;
     }
     // check if prev_id is used, check if id is in set - get new id and set new prev_ids in copied items
     $newPageBlocks = NavItemPageBlockItem::findAll(['nav_item_page_id' => $pageItem->id]);
     foreach ($newPageBlocks as $block) {
         if ($block->prev_id) {
             if (isset($idLink[$block->prev_id])) {
                 $block->prev_id = $idLink[$block->prev_id];
             }
         }
         $block->update(false);
     }
     return true;
 }