/** * 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; } }
/** * Removes the blocks placed on the current slot from the database * * @return null|boolean * @throws \Exception */ protected function deleteBlocks() { $blocks = $this->blockRepository->retrieveContentsBySlotName($this->slot->getSlotName()); if (count($blocks) <= 0) { return null; } try { $result = null; $this->blockRepository->startTransaction(); foreach ($blocks as $block) { $result = $this->blockRepository->setRepositoryObject($block)->delete(); if (!$result) { break; } } if ($result) { $this->blockRepository->commit(); } else { $this->blockRepository->rollBack(); } return $result; } catch (\Exception $e) { if (isset($this->blockRepository) && $this->blockRepository !== null) { $this->blockRepository->rollBack(); } throw $e; } }
/** * 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; } }
/** * 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; } } } }
/** * 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; } }