Exemple #1
0
 /**
  * @Route("/changeorder", options={"expose"=true})
  * @Method("POST")
  * 
  * Changeblockorder.
  *
  * @param Request $request
  * 
  *  blockorder array of sorted blocks (value = block id)
  *  position int zone id
  *
  * @return AjaxResponse|ForbiddenResponse true or Ajax error
  */
 public function changeblockorderAction(Request $request)
 {
     $this->checkAjaxToken();
     if (!SecurityUtil::checkPermission('ZikulaBlocksModule::', '::', ACCESS_ADMIN)) {
         return new ForbiddenResponse($this->__('No permission for this action.'));
     }
     $blockorder = $request->request->get('blockorder', array());
     $position = $request->request->get('position');
     // remove all blocks from this position
     $query = $this->entityManager->createQueryBuilder()->delete()->from('ZikulaBlocksModule:BlockPlacementEntity', 'p')->where('p.pid = :pid')->setParameter('pid', $position)->getQuery();
     $query->getResult();
     // add new block positions
     foreach ((array) $blockorder as $order => $bid) {
         $placement = new BlockPlacementEntity();
         $placement->setPid($position);
         $placement->setBid($bid);
         $placement->setSortorder($order);
         $this->entityManager->persist($placement);
     }
     $this->entityManager->flush();
     return new AjaxResponse(array('result' => true));
 }
Exemple #2
0
 /**
  * Create a new block.
  *
  * @param mixed[] $args {
  *      @type string $title       the title of the block
  *      @type string $description the description of the block
  *      @type int    $mid         the module ID of the block
  *      @type string $language    the language of the block
  *      @type int    $bkey        the key of the block
  *
  * @return int|bool block id on success, false on failure.
  *
  * @throws \InvalidArgumentException Thrown if invalid parameters are received in $args
  * @throws AccessDeniedException Thrown if the user doesn't have permission to create the block
  */
 public function create($args)
 {
     // Argument check
     if (!isset($args['title']) || !isset($args['description']) || (!isset($args['mid']) || !is_numeric($args['mid'])) || !isset($args['language']) || !isset($args['collapsable']) || !isset($args['defaultstate']) || !isset($args['bkey'])) {
         throw new \InvalidArgumentException(__('Invalid arguments array received'));
     }
     // Security check
     if (!System::isInstalling() && !SecurityUtil::checkPermission('ZikulaBlocksModule::', "{$args['bkey']}:{$args['title']}:", ACCESS_ADD)) {
         throw new AccessDeniedException();
     }
     // optional arguments
     if (!isset($args['content']) || !is_string($args['content'])) {
         $args['content'] = '';
     }
     $block = array('title' => $args['title'], 'description' => $args['description'], 'language' => $args['language'], 'collapsable' => $args['collapsable'], 'mid' => $args['mid'], 'defaultstate' => $args['defaultstate'], 'bkey' => $args['bkey'], 'content' => $args['content']);
     $item = new BlockEntity();
     $item->merge($block);
     $this->entityManager->persist($item);
     $this->entityManager->flush();
     // insert block positions for this block
     if (isset($args['positions']) && is_array($args['positions'])) {
         foreach ($args['positions'] as $position) {
             $placement = new BlockPlacementEntity();
             $placement->setPid($position);
             $placement->setBid($item['bid']);
             $this->entityManager->persist($placement);
         }
         $this->entityManager->flush();
     }
     return $item['bid'];
 }