public function actionCopyBlockFromStack()
 {
     $model = NavItemPageBlockItem::findOne(Yii::$app->request->post('copyBlockId', 0));
     if ($model && Yii::$app->request->post('copyBlockId', 0) !== Yii::$app->request->post('prevId', false)) {
         $newModel = new NavItemPageBlockItem();
         $newModel->attributes = $model->toArray();
         $newModel->is_dirty = 0;
         $newModel->prev_id = Yii::$app->request->post('prevId', false);
         $newModel->placeholder_var = Yii::$app->request->post('placeholder_var', false);
         $newModel->sort_index = Yii::$app->request->post('sortIndex', false);
         $newModel->nav_item_page_id = Yii::$app->request->post('nav_item_page_id', false);
         if ($newModel->insert(false)) {
             $this->copySubBlocksTo(Yii::$app->request->post('copyBlockId', false), $newModel->id, $newModel->nav_item_page_id);
             return ['response' => true];
         }
     }
     return ['response' => false];
 }
Beispiel #2
0
 /**
  * Search for entries with cached block id in cms_nav_item_page_block_item and delete them
  */
 public function afterDelete()
 {
     if ($this->cachedDeletedId) {
         foreach (NavItemPageBlockItem::find()->where(['block_id' => $this->cachedDeletedId])->all() as $item) {
             $item->delete();
         }
     }
     parent::afterDelete();
 }
 public function actionIndex($callback, $id)
 {
     $model = NavItemPageBlockItem::findOne($id);
     if (!$model) {
         throw new Exception("Unable to find item id.");
     }
     $block = Block::objectId($model->block_id, $model->id, 'callback');
     if (!$block) {
         throw new Exception("Unable to find block object.");
     }
     return ObjectHelper::callMethodSanitizeArguments($block, 'callback' . Inflector::id2camel($callback), Yii::$app->request->get());
 }
Beispiel #4
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 . ")";
         }
     }
 }
 private function deleteAllSubBlocks($blockId)
 {
     if ($blockId) {
         $subBlocks = NavItemPageBlockItem::findAll(['prev_id' => $blockId]);
         foreach ($subBlocks as $block) {
             // check for attached sub blocks and start recursion
             $attachedBlocks = NavItemPageBlockItem::findAll(['prev_id' => $block->id]);
             if ($attachedBlocks) {
                 $this->deleteAllSubBlocks($block->id);
             }
             $block->delete();
         }
     }
 }
Beispiel #6
0
 /**
  *
  * @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;
 }
Beispiel #7
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();
     $pageItem->nav_item_id = $targetNavItem->id;
     if (!$pageItem->save()) {
         return false;
     }
     $targetNavItem->nav_item_type_id = $pageItem->id;
     if (!$targetNavItem->save()) {
         return false;
     }
     // @TODO replace with NavItemPage::copyBlocks($sourcePageItem->id, $pageItem->id);
     $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;
 }
 /**
  * Return all page block items for the current corresponding page. Not related to any sortings or placeholders.
  *
  * @return ActiveQuery
  */
 public function getNavItemPageBlockItems()
 {
     return $this->hasMany(NavItemPageBlockItem::className(), ['nav_item_page_id' => 'id']);
 }
 public function actionToggleBlockHidden($blockId, $hiddenState)
 {
     $block = NavItemPageBlockItem::findOne($blockId);
     if ($block) {
         $block->is_hidden = $hiddenState;
         return $block->update(false);
     }
     return false;
 }