/** * Changeblockorder. * * @param blockorder array of sorted blocks (value = block id) * @param position int zone id * * @return mixed true or Ajax error */ public function changeblockorder() { $this->checkAjaxToken(); $this->throwForbiddenUnless(SecurityUtil::checkPermission('Blocks::', '::', ACCESS_ADMIN)); $blockorder = $this->request->request->get('blockorder'); $position = $this->request->request->get('position'); // remove all blocks from this position $entity = $this->name . '_Entity_BlockPlacement'; $dql = "DELETE FROM $entity p WHERE p.pid = {$position}"; $query = $this->entityManager->createQuery($dql); $query->getResult(); // add new block positions foreach ((array)$blockorder as $order => $bid) { $placement = new Blocks_Entity_BlockPlacement(); $placement->setPid($position); $placement->setBid($bid); $placement->setSortorder($order); $this->entityManager->persist($placement); } $this->entityManager->flush(); return new Zikula_Response_Ajax(array('result' => true)); }
/** * Create a new block. * * @param string $block ['title'] the title of the block. * @param string $block ['description'] the description of the block. * @param int $block ['mid'] the module ID of the block. * @param string $block ['language'] the language of the block. * @param int $block ['bkey'] the key of the block. * * @return mixed block Id on success, false on failure. */ public function create($args) { // Argument check if ((!isset($args['title'])) || (!isset($args['description'])) || (!isset($args['mid'])) || (!isset($args['language'])) || (!isset($args['collapsable'])) || (!isset($args['defaultstate'])) || (!isset($args['bkey']))) { return LogUtil::registerArgsError(); } // Security check if (!System::isInstalling() && !SecurityUtil::checkPermission('Blocks::', "$args[bkey]:$args[title]:", ACCESS_ADD)) { return LogUtil::registerPermissionError(); } // 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 Blocks_Entity_Block(); $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 Blocks_Entity_BlockPlacement(); $placement->setPid($position); $placement->setBid($item['bid']); $this->entityManager->persist($placement); } $this->entityManager->flush(); } return $item['bid']; }