示例#1
0
 /**
  * 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;
     }
 }
 /**
  * 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;
 }
示例#3
0
 /**
  * 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;
     }
 }