示例#1
0
 public function actionIndex($callback, $id)
 {
     $model = NavItemPageBlockItem::findOne($id);
     $block = Block::objectId($model->block_id, $model->id, 'callback');
     $method = 'callback' . Inflector::id2camel($callback);
     return ObjectHelper::callMethodSanitizeArguments($block, $method, Yii::$app->request->get());
 }
示例#2
0
 public function actionCopyBlockFromStack()
 {
     $model = NavItemPageBlockItem::findOne(Yii::$app->request->post('copyBlockId', 0));
     if ($model) {
         $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];
 }
示例#3
0
文件: Block.php 项目: aekkapun/luya
 /**
  * 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();
 }
示例#4
0
 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());
 }
示例#5
0
 public function renderPlaceholder($navItemPageId, $placeholderVar, $prevId)
 {
     $string = '';
     foreach ($this->getPlaceholders($navItemPageId, $placeholderVar, $prevId) as $key => $placeholder) {
         $cacheKey = NavItemPageBlockItem::cacheName($placeholder['id']);
         $blockResponse = $this->getHasCache($cacheKey);
         if ($blockResponse === false) {
             // create block object
             $blockObject = Block::objectId($placeholder['block_id'], $placeholder['id'], 'frontend', $this->getNavItem());
             // see if its a valid block object
             if ($blockObject) {
                 if (count($blockObject->assets) > 0) {
                     $controllerObject = $this->getOption('cmsControllerObject');
                     if ($controllerObject) {
                         foreach ($blockObject->assets as $assetClassName) {
                             $controllerObject->registerAsset($assetClassName);
                         }
                     }
                 }
                 // insert var and cfg values from database
                 $blockObject->setVarValues($this->jsonToArray($placeholder['json_config_values']));
                 $blockObject->setCfgValues($this->jsonToArray($placeholder['json_config_cfg_values']));
                 // set env options from current object environment
                 foreach ($this->getOptions() as $optKey => $optValue) {
                     $blockObject->setEnvOption($optKey, $optValue);
                 }
                 // render sub placeholders and set into object
                 $insertedHolders = [];
                 foreach ($blockObject->getPlaceholders() as $item) {
                     $insertedHolders[$item['var']] = $this->renderPlaceholder($navItemPageId, $item['var'], $placeholder['id']);
                 }
                 $blockObject->setPlaceholderValues($insertedHolders);
                 // output buffer the rendered frontend string based on the current twig env
                 $blockResponse = $blockObject->renderFrontend($this->getTwig());
                 if ($blockObject->cacheEnabled) {
                     $this->setHasCache($cacheKey, $blockResponse, $blockObject->cacheExpiration);
                     //Yii::info($cacheKey . ": will be cached!");
                 } else {
                     //Yii::info($cacheKey. ": will NOT be cached!");
                 }
             }
         }
         $string .= $blockResponse;
     }
     return $string;
 }
 public function actionToggleBlockHidden($blockId, $hiddenState)
 {
     $block = NavItemPageBlockItem::findOne($blockId);
     if ($block) {
         $block->is_hidden = $hiddenState;
         return $block->update(false);
     }
     return false;
 }
示例#7
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;
 }
示例#8
0
文件: Nav.php 项目: aekkapun/luya
 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->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;
     return $navItem->save();
 }
示例#9
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;
 }
示例#10
0
 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();
         }
     }
 }