Ejemplo n.º 1
0
 public function setPosition(BlockPositionEntity $position = null)
 {
     if ($this->position !== null) {
         $this->position->removePlacement($this);
     }
     if ($position !== null) {
         $position->addPlacement($this);
     }
     $this->position = $position;
     return $this;
 }
Ejemplo n.º 2
0
 /**
  * Create a new position or edit an existing position.
  *
  * @Route("/edit/{pid}", requirements={"pid" = "^[1-9]\d*$"})
  * @Theme("admin")
  * @Template
  *
  * @param BlockPositionEntity $positionEntity
  * @return \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response
  */
 public function editAction(BlockPositionEntity $positionEntity)
 {
     if (!$this->hasPermission('ZikulaBlocksModule::', '::', ACCESS_ADMIN)) {
         throw new AccessDeniedException();
     }
     $allBlocks = $this->getDoctrine()->getManager()->getRepository('ZikulaBlocksModule:BlockEntity')->findAll();
     $assignedBlocks = [];
     foreach ($positionEntity->getPlacements() as $blockPlacement) {
         $bid = $blockPlacement->getBlock()->getBid();
         foreach ($allBlocks as $key => $allblock) {
             if ($allblock->getBid() == $bid) {
                 unset($allBlocks[$key]);
             }
         }
         $assignedBlocks[] = $blockPlacement->getBlock();
     }
     return ['position' => $positionEntity, 'positionChoices' => $this->getDoctrine()->getRepository('ZikulaBlocksModule:BlockPositionEntity')->getPositionChoiceArray(), 'assignedblocks' => $assignedBlocks, 'unassignedblocks' => $allBlocks];
 }
Ejemplo n.º 3
0
 /**
  * @Route("/delete/{pid}", requirements={"pid" = "^[1-9]\d*$"})
  * @Theme("admin")
  * @Template
  *
  * Delete a position.
  *
  * @param Request $request
  * @param BlockPositionEntity $positionEntity
  * @return \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response
  */
 public function deleteAction(Request $request, BlockPositionEntity $positionEntity)
 {
     if (!$this->hasPermission('ZikulaBlocksModule::position', $positionEntity->getName() . '::' . $positionEntity->getPid(), ACCESS_DELETE)) {
         throw new AccessDeniedException();
     }
     $form = $this->createFormBuilder()->add('delete', 'Symfony\\Component\\Form\\Extension\\Core\\Type\\SubmitType', ['label' => 'Delete'])->add('cancel', 'Symfony\\Component\\Form\\Extension\\Core\\Type\\SubmitType', ['label' => 'Cancel'])->getForm();
     $form->handleRequest($request);
     if ($form->isValid()) {
         if ($form->get('delete')->isClicked()) {
             $em = $this->getDoctrine()->getManager();
             $em->remove($positionEntity);
             $em->flush();
             $this->addFlash('status', __('Done! Position deleted.'));
         }
         if ($form->get('cancel')->isClicked()) {
             $this->addFlash('status', __('Operation cancelled.'));
         }
         return $this->redirect($this->generateUrl('zikulablocksmodule_admin_view'));
     }
     return ['form' => $form->createView(), 'position' => $positionEntity];
 }
Ejemplo n.º 4
0
 /**
  * Create a block position.
  *
  * @param string[] $args {
  *      @type string $name        name of the position
  *      @type string $description description of the position
  *                        </ul>
  *
  * @return int|bool position 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 position
  * @throws \RuntimeException Thrown if a block position with the same name already exists
  */
 public function createposition($args)
 {
     // Argument check
     if (!isset($args['name']) || !strlen($args['name']) || !isset($args['description'])) {
         throw new \InvalidArgumentException(__('Invalid arguments array received'));
     }
     // Security check
     if (!System::isInstalling() && !SecurityUtil::checkPermission('ZikulaBlocksModule::position', "{$args['name']}::", ACCESS_ADD)) {
         throw new AccessDeniedException();
     }
     $positions = ModUtil::apiFunc('ZikulaBlocksModule', 'user', 'getallpositions');
     if (isset($positions) && is_array($positions)) {
         foreach ($positions as $position) {
             if ($position['name'] == $args['name']) {
                 throw new \RuntimeException($this->__('Error! There is already a block position with the name you entered.'));
             }
         }
     }
     $item = new BlockPositionEntity();
     $item->merge($args);
     $this->entityManager->persist($item);
     $this->entityManager->flush();
     // Return the id of the newly created item to the calling process
     return $item['pid'];
 }