Ejemplo n.º 1
0
 public function saveAction()
 {
     $this->checkAjaxToken();
     $mode = $this->request->request->get('mode', 'new');
     $accessLevel = $mode == 'edit' ? ACCESS_EDIT : ACCESS_ADD;
     $this->throwForbiddenUnless(SecurityUtil::checkPermission('Categories::', '::', $accessLevel));
     // get data from post
     $data = $this->request->request->get('category', null);
     if (!isset($data['is_locked'])) {
         $data['is_locked'] = 0;
     }
     if (!isset($data['is_leaf'])) {
         $data['is_leaf'] = 0;
     }
     if (!isset($data['status'])) {
         $data['status'] = 'I';
     }
     $valid = \CategoriesModule\GenericUtil::validateCategoryData($data);
     if (!$valid) {
         $args = array('cid' => isset($data['cid']) ? $data['cid'] : 0, 'parent' => $data['parent_id'], 'mode' => $mode);
         return $this->editAction($args);
     }
     // process name
     $data['name'] = \CategoriesModule\GenericUtil::processCategoryName($data['name']);
     // process parent
     $data['parent'] = \CategoriesModule\GenericUtil::processCategoryParent($data['parent_id']);
     unset($data['parent_id']);
     // process display names
     $data['display_name'] = \CategoriesModule\GenericUtil::processCategoryDisplayName($data['display_name'], $data['name']);
     // save category
     if ($mode == 'edit') {
         $category = $this->entityManager->find('Zikula\\Core\\Doctrine\\Entity\\Category', $data['id']);
     } else {
         $category = new \Zikula\Core\Doctrine\Entity\Category();
     }
     $prevCategoryName = $category['name'];
     $category->merge($data);
     $this->entityManager->persist($category);
     $this->entityManager->flush();
     // process path and ipath
     $category['path'] = \CategoriesModule\GenericUtil::processCategoryPath($data['parent']['path'], $category['name']);
     $category['ipath'] = \CategoriesModule\GenericUtil::processCategoryIPath($data['parent']['ipath'], $category['id']);
     // process category attributes
     $attrib_names = $this->request->request->get('attribute_name', array());
     $attrib_values = $this->request->request->get('attribute_value', array());
     \CategoriesModule\GenericUtil::processCategoryAttributes($category, $attrib_names, $attrib_values);
     $this->entityManager->flush();
     // since a name change will change the object path, we must rebuild it here
     if ($prevCategoryName != $category['name']) {
         CategoryUtil::rebuildPaths('path', 'name', $category['id']);
     }
     $categories = CategoryUtil::getSubCategories($category['id'], true, true, true, true, true);
     $options = array('nullParent' => $category['parent']->getId(), 'withWraper' => false);
     $node = CategoryUtil::getCategoryTreeJS((array) $categories, true, true, $options);
     $leafStatus = array('leaf' => array(), 'noleaf' => array());
     foreach ($categories as $c) {
         if ($c['is_leaf']) {
             $leafStatus['leaf'][] = $c['id'];
         } else {
             $leafStatus['noleaf'][] = $c['id'];
         }
     }
     $result = array('action' => $mode == 'edit' ? 'edit' : 'add', 'cid' => $category['id'], 'parent' => $category['parent']->getId(), 'node' => $node, 'leafstatus' => $leafStatus, 'result' => true);
     return new AjaxResponse($result);
 }
Ejemplo n.º 2
0
 /**
  * create category
  */
 public function newcatAction()
 {
     $this->checkCsrfToken();
     if (!SecurityUtil::checkPermission('Categories::', '::', ACCESS_ADD)) {
         throw new \Zikula\Framework\Exception\ForbiddenException();
     }
     // get data from post
     $data = $this->request->request->get('category', null);
     $valid = \CategoriesModule\GenericUtil::validateCategoryData($data);
     if (!$valid) {
         return $this->redirect(ModUtil::url('Categories', 'admin', 'newcat'));
     }
     // process name
     $data['name'] = \CategoriesModule\GenericUtil::processCategoryName($data['name']);
     // process parent
     $data['parent'] = \CategoriesModule\GenericUtil::processCategoryParent($data['parent_id']);
     unset($data['parent_id']);
     // process display names
     $data['display_name'] = \CategoriesModule\GenericUtil::processCategoryDisplayName($data['display_name'], $data['name']);
     // save category
     $category = new \Zikula\Core\Doctrine\Entity\Category();
     $category->merge($data);
     $this->entityManager->persist($category);
     $this->entityManager->flush();
     // process path and ipath
     $category['path'] = \CategoriesModule\GenericUtil::processCategoryPath($data['parent']['path'], $category['name']);
     $category['ipath'] = \CategoriesModule\GenericUtil::processCategoryIPath($data['parent']['ipath'], $category['id']);
     // process category attributes
     $attrib_names = $this->request->request->get('attribute_name', array());
     $attrib_values = $this->request->request->get('attribute_value', array());
     \CategoriesModule\GenericUtil::processCategoryAttributes($category, $attrib_names, $attrib_values);
     $this->entityManager->flush();
     $msg = __f('Done! Inserted the %s category.', $category['name']);
     LogUtil::registerStatus($msg);
     return $this->redirect(ModUtil::url('Categories', 'admin', 'view') . '#top');
 }
Ejemplo n.º 3
0
 /**
  * create category
  */
 public function newcatAction()
 {
     $this->checkCsrfToken();
     if (!SecurityUtil::checkPermission('Categories::', '::', ACCESS_ADD)) {
         throw new \Zikula\Framework\Exception\ForbiddenException();
     }
     $dr = (int) $this->request->request->get('dr', 0);
     $url = System::serverGetVar('HTTP_REFERER');
     if (!$dr) {
         return LogUtil::registerError($this->__('Error! The document root is invalid.'), null, $url);
     }
     // get data from post
     $data = $this->request->request->get('category', null);
     $valid = \CategoriesModule\GenericUtil::validateCategoryData($data);
     if (!$valid) {
         return $this->redirect(ModUtil::url('Categories', 'user', 'edit', array('dr' => $dr)));
     }
     // process name
     $data['name'] = \CategoriesModule\GenericUtil::processCategoryName($data['name']);
     // process parent
     $data['parent'] = \CategoriesModule\GenericUtil::processCategoryParent($data['parent_id']);
     unset($data['parent_id']);
     // process display names
     $data['display_name'] = \CategoriesModule\GenericUtil::processCategoryDisplayName($data['display_name'], $data['name']);
     // process sort value
     $data['sort_value'] = 0;
     // save category
     $category = new \Zikula\Core\Doctrine\Entity\Category();
     $category->merge($data);
     $this->entityManager->persist($category);
     $this->entityManager->flush();
     // process path and ipath
     $category['path'] = \CategoriesModule\GenericUtil::processCategoryPath($data['parent']['path'], $category['name']);
     $category['ipath'] = \CategoriesModule\GenericUtil::processCategoryIPath($data['parent']['ipath'], $category['id']);
     // process category attributes
     $attrib_names = $this->request->request->get('attribute_name', array());
     $attrib_values = $this->request->request->get('attribute_value', array());
     \CategoriesModule\GenericUtil::processCategoryAttributes($category, $attrib_names, $attrib_values);
     $this->entityManager->flush();
     $msg = $this->__f('Done! Inserted the %s category.', $data['name']);
     LogUtil::registerStatus($msg);
     return $this->redirect($url);
 }