/** * Updates the block, according the page and language with the new repeated status * * @param array $block * @param int $idLanguage * @param int $idPage * @return boolean */ protected function updateBlock(array $block, $idLanguage, $idPage) { $block["LanguageId"] = $idLanguage; $block["PageId"] = $idPage; $className = $this->blockRepository->getRepositoryObjectClassName(); $modelObject = new $className(); $result = $this->blockRepository->setRepositoryObject($modelObject)->save($block); return $result; }
private function initBasePages($languages) { $templates = $this->theme->getTemplates(); foreach ($languages as $language) { $blocks = $this->blockRepository->retrieveContents(array(1, $language->getId()), 1); foreach ($templates as $template) { $this->pageBlocks->setBlocks($blocks); $this->pages['base'][] = $this->initPageTree($language, null, $template); } } }
protected function deleteChildren($prevSlotName) { $result = true; $blocks = $this->blocksRepository->retrieveContentsBySlotName($prevSlotName . '-%'); foreach ($blocks as $block) { $block->setToDelete(1); if (!$block->save()) { break; } } return $result; }
/** * Adds the page attributes when a new page is added, for each language of the site * * @param BeforeEditSeoCommitEvent $event * @return boolean * @throws InvalidArgumentException * @throws \Exception * * @api */ public function onBeforeEditSeoCommit(BeforeEditSeoCommitEvent $event) { if ($event->isAborted()) { return; } $values = $event->getValues(); if (!is_array($values)) { throw new InvalidArgumentException('exception_invalid_value_array_required'); } if (array_key_exists("oldPermalink", $values)) { $result = true; $alBlocks = $this->blockRepository->fromContent($values["oldPermalink"]); if (count($alBlocks) > 0) { try { $this->blockRepository->startTransaction(); foreach ($alBlocks as $alBlock) { $htmlContent = preg_replace('/' . $values["oldPermalink"] . '/s', $values["Permalink"], $alBlock->getContent()); $blockManager = $this->blocksFactory->createBlockManager($alBlock); $value = array('Content' => $htmlContent); $result = $blockManager->save($value); if (!$result) { break; } } if (false !== $result) { $this->blockRepository->commit(); return; } $this->blockRepository->rollBack(); $event->abort(); } catch (\Exception $e) { $event->abort(); if (isset($this->blockRepository) && $this->blockRepository !== null) { $this->blockRepository->rollBack(); } throw $e; } } } }
/** * Adjusts the blocks position on the slot, when a new block is added or a block is deleted. * * When in *add* mode, it creates a space between the adding block's position and * the blocks below, incrementing their position by one * * When in *del* mode, decrements by 1 the position of the blocks placed below the * removing block * * @param string $op The operation to do. It accepts add or del as valid values * @param array $managers An array of block managers * @throws \Exception * @return boolean */ protected function adjustPosition($op, array $managers) { if (count($managers) == 0) { return null; } $this->checkValidOperation($op); try { $result = null; $this->blockRepository->startTransaction(); foreach ($managers as $blockManager) { $block = $blockManager->get(); $contentPosition = $block->getContentPosition(); $position = $op == 'add' ? $contentPosition + 1 : $contentPosition - 1; $result = $this->blockRepository->setRepositoryObject($block)->save(array("ContentPosition" => $position)); if (false === $result) { break; } } if (false !== $result) { $this->blockRepository->commit(); return $result; } $this->blockRepository->rollBack(); return $result; } catch (\Exception $e) { $this->blockRepository->rollBack(); throw $e; } }
/** * {@inheritdoc} */ public function refresh($languageId, $pageId) { if (!is_numeric($languageId)) { throw new General\InvalidArgumentTypeException('exception_invalid_value_for_page_id'); } if (!is_numeric($pageId)) { throw new General\InvalidArgumentTypeException('exception_invalid_value_for_language_id'); } if ($languageId == $this->idLanguage && $pageId == $this->idPage) { return $this; } $this->idLanguage = $languageId; $this->idPage = $pageId; $this->alBlocks = $this->blockRepository->retrieveContents(array(1, $languageId), array(1, $pageId)); $this->arrangeBlocks(); return $this; }
/** * Clear the blocks from the whole slot managers managed by the template manager, * for a page identified by the required parameters * * @param int $languageId * @param int $pageId * @param boolean $skipRepeated * @return boolean * @throws \Exception * * @api */ public function clearPageBlocks($languageId, $pageId, $skipRepeated = true) { try { $this->blockRepository->startTransaction(); $pageBlocks = clone $this->pageBlocks; $this->pageBlocks->refresh($languageId, $pageId); $result = $this->clearBlocks($skipRepeated); $this->pageBlocks = $pageBlocks; if ($result !== false) { $this->blockRepository->commit(); return $result; } $this->blockRepository->rollBack(); return $result; } catch (\Exception $e) { $this->blockRepository->rollBack(); throw $e; } }
/** * Edits the current block object * * @param array $values An array where keys are the BlockField definition and values are the values to edit * @return boolean * @throws \RedKiteLabs\RedKiteCms\RedKiteCmsBundle\Core\Exception\Content\General\InvalidArgumentTypeException * * @api */ protected function edit(array $values) { $values = $this->dispatchBeforeOperationEvent('\\RedKiteLabs\\RedKiteCms\\RedKiteCmsBundle\\Core\\Event\\Content\\Block\\BeforeBlockEditingEvent', BlockEvents::BEFORE_EDIT_BLOCK, $values, 'exception_block_editing_aborted'); try { $this->validator->checkEmptyParams($values); // Edits the source content $this->blockRepository->startTransaction(); $this->blockRepository->setRepositoryObject($this->alBlock); $result = $this->blockRepository->save($values); if (false !== $result) { $this->blockRepository->commit(); $this->eventsHandler->createEvent(BlockEvents::AFTER_EDIT_BLOCK, '\\RedKiteLabs\\RedKiteCms\\RedKiteCmsBundle\\Core\\Event\\Content\\Block\\AfterBlockEditedEvent', array($this))->dispatch(); return $result; } $this->blockRepository->rollBack(); return $result; } catch (\Exception $e) { if (isset($this->blockRepository) && $this->blockRepository !== null) { $this->blockRepository->rollBack(); } throw $e; } }