Exemplo n.º 1
0
 /**
  * Register module categories.
  *
  * @param array $catregs The array of category map data objects.
  *
  * @return boolean
  */
 public static function registerModuleCategories($catregs)
 {
     if (!$catregs) {
         return false;
     }
     $em = \ServiceUtil::get('doctrine.entitymanager');
     foreach ($catregs as $catreg) {
         if ($catreg['id']) {
             $entity = $em->getRepository('ZikulaCategoriesModule:CategoryRegistryEntity')->find($catreg['id']);
         } else {
             $entity = new CategoryRegistryEntity();
         }
         $entity->merge($catreg);
         $em->persist($entity);
     }
     $em->flush();
     return true;
 }
Exemplo n.º 2
0
 /**
  * @Route("/editregistry")
  * @Method("GET")
  * 
  * edit category registry
  * 
  * @param Request $request
  *
  * @return Response symfony response object
  *
  * @throws AccessDeniedException Thrown if the user doesn't have permission to administrate the module
  */
 public function editregistryAction(Request $request)
 {
     if (!SecurityUtil::checkPermission('ZikulaCategoriesModule::', '::', ACCESS_ADMIN)) {
         throw new AccessDeniedException();
     }
     $root_id = $request->get('dr', 1);
     $id = $request->get('id', 0);
     $obj = new CategoryRegistryEntity();
     $category_registry = $request->query->get('category_registry', null);
     if ($category_registry) {
         $obj->merge($category_registry);
         $obj = $obj->toArray();
     }
     $registries = $this->entityManager->getRepository('ZikulaCategoriesModule:CategoryRegistryEntity')->findBy(array(), array('modname' => 'ASC', 'property' => 'ASC'));
     $this->view->assign('objectArray', $registries)->assign('newobj', $obj)->assign('root_id', $root_id)->assign('id', $id);
     return $this->response($this->view->fetch('Admin/registry_edit.tpl'));
 }
Exemplo n.º 3
0
 /**
  * @Route("/editregistry")
  * @Method("POST")
  *
  * edit category registry
  *
  * @return RedirectResponse
  *
  * @throws AccessDeniedException Thrown if the user doesn't have admin permissions over the module
  */
 public function editregistryAction()
 {
     $this->checkCsrfToken();
     if (!SecurityUtil::checkPermission('ZikulaCategoriesModule::', '::', ACCESS_ADMIN)) {
         throw new AccessDeniedException();
     }
     // delete registry
     if ($this->request->request->get('mode', null) == 'delete') {
         $id = $this->request->get('id', 0);
         $obj = $this->entityManager->find('ZikulaCategoriesModule:CategoryRegistryEntity', $id);
         $this->entityManager->remove($obj);
         $this->entityManager->flush();
         $this->request->getSession()->getFlashBag()->add('status', __('Done! Deleted the category registry entry.'));
         return new RedirectResponse($this->get('router')->generate('zikulacategoriesmodule_admin_editregistry', array(), RouterInterface::ABSOLUTE_URL));
     }
     $args = array();
     if (!$this->request->request->get('category_submit', null)) {
         // got here through selector auto-submit
         $data = $this->request->request->get('category_registry', null);
         $args['category_registry'] = $data;
         return new RedirectResponse($this->get('router')->generate('zikulacategoriesmodule_admin_editregistry', $args, RouterInterface::ABSOLUTE_URL));
     }
     // get data from post
     $data = $this->request->request->get('category_registry', null);
     // do some validation
     $valid = true;
     if (empty($data['modname'])) {
         $this->request->getSession()->getFlashBag()->add('error', __('Error! You did not select a module.'));
         $valid = false;
     }
     if (empty($data['entityname'])) {
         $this->request->getSession()->getFlashBag()->add('error', __('Error! You did not select an entity.'));
         $valid = false;
     }
     if (empty($data['property'])) {
         $this->request->getSession()->getFlashBag()->add('error', __('Error! You did not enter a property name.'));
         $valid = false;
     }
     if ((int) $data['category_id'] == 0) {
         $this->request->getSession()->getFlashBag()->add('error', __('Error! You did not select a category.'));
         $valid = false;
     }
     if (!$valid) {
         return new RedirectResponse($this->get('router')->generate('zikulacategoriesmodule_admin_editregistry', array(), RouterInterface::ABSOLUTE_URL));
     }
     if (isset($data['id']) && (int) $data['id'] > 0) {
         // update existing registry
         $obj = $this->entityManager->find('ZikulaCategoriesModule:CategoryRegistryEntity', $data['id']);
     } else {
         // create new registry
         $obj = new CategoryRegistryEntity();
     }
     $obj->merge($data);
     $this->entityManager->persist($obj);
     $this->entityManager->flush();
     $this->request->getSession()->getFlashBag()->add('status', __('Done! Saved the category registry entry.'));
     return new RedirectResponse($this->get('router')->generate('zikulacategoriesmodule_admin_editregistry', array(), RouterInterface::ABSOLUTE_URL));
 }