Exemplo n.º 1
0
 /**
  * insert data
  */
 public function insertData_10()
 {
     $objArray = array();
     $objArray[] = array('id' => 1, 'parent_id' => 0, 'is_locked' => 1, 'is_leaf' => 0, 'value' => '', 'sort_value' => 1, 'name' => '__SYSTEM__', 'display_name' => '', 'display_desc' => '', 'path' => '/__SYSTEM__', 'ipath' => '/1', 'status' => 'A');
     $objArray[] = array('id' => 2, 'parent_id' => 1, 'is_locked' => 0, 'is_leaf' => 0, 'value' => '', 'sort_value' => 2, 'name' => 'Modules', 'display_name' => $this->makeDisplayName($this->__('Modules')), 'display_desc' => $this->makeDisplayDesc(), 'path' => '/__SYSTEM__/Modules', 'ipath' => '/1/2', 'status' => 'A');
     $objArray[] = array('id' => 3, 'parent_id' => 1, 'is_locked' => 0, 'is_leaf' => 0, 'value' => '', 'sort_value' => 3, 'name' => 'General', 'display_name' => $this->makeDisplayName($this->__('General')), 'display_desc' => $this->makeDisplayDesc(), 'path' => '/__SYSTEM__/General', 'ipath' => '/1/3', 'status' => 'A');
     $objArray[] = array('id' => 4, 'parent_id' => 3, 'is_locked' => 0, 'is_leaf' => 0, 'value' => '', 'sort_value' => 4, 'name' => 'YesNo', 'display_name' => $this->makeDisplayName($this->__('Yes/No')), 'display_desc' => $this->makeDisplayDesc(), 'path' => '/__SYSTEM__/General/YesNo', 'ipath' => '/1/3/4', 'status' => 'A');
     $objArray[] = array('id' => 5, 'parent_id' => 4, 'is_locked' => 0, 'is_leaf' => 1, 'value' => 'Y', 'sort_value' => 5, 'name' => '1 - Yes', 'display_name' => '', 'display_desc' => '', 'path' => '/__SYSTEM__/General/YesNo/1 - Yes', 'ipath' => '/1/3/4/5', 'status' => 'A', '__ATTRIBUTES__' => array('code' => 'Y'));
     $objArray[] = array('id' => 6, 'parent_id' => 4, 'is_locked' => 0, 'is_leaf' => 1, 'value' => 'N', 'sort_value' => 6, 'name' => '2 - No', 'display_name' => '', 'display_desc' => '', 'path' => '/__SYSTEM__/General/YesNo/2 - No', 'ipath' => '/1/3/4/6', 'status' => 'A', '__ATTRIBUTES__' => array('code' => 'N'));
     $objArray[] = array('id' => 10, 'parent_id' => 3, 'is_locked' => 0, 'is_leaf' => 0, 'value' => '', 'sort_value' => 10, 'name' => 'Publication Status (extended)', 'display_name' => $this->makeDisplayName($this->__('Publication status (extended)')), 'display_desc' => $this->makeDisplayDesc(), 'path' => '/__SYSTEM__/General/Publication Status Extended', 'ipath' => '/1/3/10', 'status' => 'A');
     $objArray[] = array('id' => 11, 'parent_id' => 10, 'is_locked' => 0, 'is_leaf' => 1, 'value' => 'P', 'sort_value' => 11, 'name' => 'Pending', 'display_name' => $this->makeDisplayName($this->__('Pending')), 'display_desc' => $this->makeDisplayDesc(), 'path' => '/__SYSTEM__/General/Publication Status Extended/Pending', 'ipath' => '/1/3/10/11', 'status' => 'A', '__ATTRIBUTES__' => array('code' => 'P'));
     $objArray[] = array('id' => 12, 'parent_id' => 10, 'is_locked' => 0, 'is_leaf' => 1, 'value' => 'C', 'sort_value' => 12, 'name' => 'Checked', 'display_name' => $this->makeDisplayName($this->__('Checked')), 'display_desc' => $this->makeDisplayDesc(), 'path' => '/__SYSTEM__/General/Publication Status Extended/Checked', 'ipath' => '/1/3/10/12', 'status' => 'A', '__ATTRIBUTES__' => array('code' => 'C'));
     $objArray[] = array('id' => 13, 'parent_id' => 10, 'is_locked' => 0, 'is_leaf' => 1, 'value' => 'A', 'sort_value' => 13, 'name' => 'Approved', 'display_name' => $this->makeDisplayName($this->__('Approved')), 'display_desc' => $this->makeDisplayDesc(), 'path' => '/__SYSTEM__/General/Publication Status Extended/Approved', 'ipath' => '/1/3/10/13', 'status' => 'A', '__ATTRIBUTES__' => array('code' => 'A'));
     $objArray[] = array('id' => 14, 'parent_id' => 10, 'is_locked' => 0, 'is_leaf' => 1, 'value' => 'O', 'sort_value' => 14, 'name' => 'On-line', 'display_name' => $this->makeDisplayName($this->__('On-line')), 'display_desc' => $this->makeDisplayDesc(), 'path' => '/__SYSTEM__/General/Publication Status Extended/Online', 'ipath' => '/1/3/10/14', 'status' => 'A', '__ATTRIBUTES__' => array('code' => 'O'));
     $objArray[] = array('id' => 15, 'parent_id' => 10, 'is_locked' => 0, 'is_leaf' => 1, 'value' => 'R', 'sort_value' => 15, 'name' => 'Rejected', 'display_name' => $this->makeDisplayName($this->__('Rejected')), 'display_desc' => $this->makeDisplayDesc(), 'path' => '/__SYSTEM__/General/Publication Status Extended/Rejected', 'ipath' => '/1/3/10/15', 'status' => 'A', '__ATTRIBUTES__' => array('code' => 'R'));
     $objArray[] = array('id' => 16, 'parent_id' => 3, 'is_locked' => 0, 'is_leaf' => 0, 'value' => '', 'sort_value' => 16, 'name' => 'Gender', 'display_name' => $this->makeDisplayName($this->__('Gender')), 'display_desc' => $this->makeDisplayDesc(), 'path' => '/__SYSTEM__/General/Gender', 'ipath' => '/1/3/16', 'status' => 'A');
     $objArray[] = array('id' => 17, 'parent_id' => 16, 'is_locked' => 0, 'is_leaf' => 1, 'value' => 'M', 'sort_value' => 17, 'name' => 'Male', 'display_name' => $this->makeDisplayName($this->__('Male')), 'display_desc' => $this->makeDisplayDesc(), 'path' => '/__SYSTEM__/General/Gender/Male', 'ipath' => '/1/3/16/17', 'status' => 'A', '__ATTRIBUTES__' => array('code' => 'M'));
     $objArray[] = array('id' => 18, 'parent_id' => 16, 'is_locked' => 0, 'is_leaf' => 1, 'value' => 'F', 'sort_value' => 18, 'name' => 'Female', 'display_name' => $this->makeDisplayName($this->__('Female')), 'display_desc' => $this->makeDisplayDesc(), 'path' => '/__SYSTEM__/General/Gender/Female', 'ipath' => '/1/3/16/18', 'status' => 'A', '__ATTRIBUTES__' => array('code' => 'F'));
     $objArray[] = array('id' => 19, 'parent_id' => 3, 'is_locked' => 0, 'is_leaf' => 0, 'sort_value' => 19, 'value' => '', 'name' => 'Title', 'display_name' => $this->makeDisplayName($this->__('Title')), 'display_desc' => $this->makeDisplayDesc(), 'path' => '/__SYSTEM__/General/Title', 'ipath' => '/1/3/19', 'status' => 'A');
     $objArray[] = array('id' => 20, 'parent_id' => 19, 'is_locked' => 0, 'is_leaf' => 1, 'value' => 'Mr', 'sort_value' => 20, 'name' => 'Mr', 'display_name' => $this->makeDisplayName($this->__('Mr.')), 'display_desc' => $this->makeDisplayDesc(), 'path' => '/__SYSTEM__/General/Title/Mr', 'ipath' => '/1/3/19/20', 'status' => 'A');
     $objArray[] = array('id' => 21, 'parent_id' => 19, 'is_locked' => 0, 'is_leaf' => 1, 'value' => 'Mrs', 'sort_value' => 21, 'name' => 'Mrs', 'display_name' => $this->makeDisplayName($this->__('Mrs.')), 'display_desc' => $this->makeDisplayDesc(), 'path' => '/__SYSTEM__/General/Title/Mrs', 'ipath' => '/1/3/19/21', 'status' => 'A');
     $objArray[] = array('id' => 22, 'parent_id' => 19, 'is_locked' => 0, 'is_leaf' => 1, 'value' => 'Ms', 'sort_value' => 22, 'name' => 'Ms', 'display_name' => $this->makeDisplayName($this->__('Ms.')), 'display_desc' => $this->makeDisplayDesc(), 'path' => '/__SYSTEM__/General/Title/Ms', 'ipath' => '/1/3/19/22', 'status' => 'A');
     $objArray[] = array('id' => 23, 'parent_id' => 19, 'is_locked' => 0, 'is_leaf' => 1, 'value' => 'Miss', 'sort_value' => 23, 'name' => 'Miss', 'display_name' => $this->makeDisplayName($this->__('Miss')), 'display_desc' => $this->makeDisplayDesc(), 'path' => '/__SYSTEM__/General/Title/Miss', 'ipath' => '/1/3/19/23', 'status' => 'A');
     $objArray[] = array('id' => 24, 'parent_id' => 19, 'is_locked' => 0, 'is_leaf' => 1, 'value' => 'Dr', 'sort_value' => 24, 'name' => 'Dr', 'display_name' => $this->makeDisplayName($this->__('Dr.')), 'display_desc' => $this->makeDisplayDesc(), 'path' => '/__SYSTEM__/General/Title/Dr', 'ipath' => '/1/3/19/24', 'status' => 'A');
     $objArray[] = array('id' => 25, 'parent_id' => 3, 'is_locked' => 0, 'is_leaf' => 0, 'value' => '', 'sort_value' => 25, 'name' => 'ActiveStatus', 'display_name' => $this->makeDisplayName($this->__('Activity status')), 'display_desc' => $this->makeDisplayDesc(), 'path' => '/__SYSTEM__/General/ActiveStatus', 'ipath' => '/1/3/25', 'status' => 'A');
     $objArray[] = array('id' => 26, 'parent_id' => 25, 'is_locked' => 0, 'is_leaf' => 1, 'value' => 'A', 'sort_value' => 26, 'name' => 'Active', 'display_name' => $this->makeDisplayName($this->__('Active')), 'display_desc' => $this->makeDisplayDesc(), 'path' => '/__SYSTEM__/General/ActiveStatus/Active', 'ipath' => '/1/3/25/26', 'status' => 'A', '__ATTRIBUTES__' => array('code' => 'A'));
     $objArray[] = array('id' => 27, 'parent_id' => 25, 'is_locked' => 0, 'is_leaf' => 1, 'value' => 'I', 'sort_value' => 27, 'name' => 'Inactive', 'display_name' => $this->makeDisplayName($this->__('Inactive')), 'display_desc' => $this->makeDisplayDesc(), 'path' => '/__SYSTEM__/General/ActiveStatus/Inactive', 'ipath' => '/1/3/25/27', 'status' => 'A', '__ATTRIBUTES__' => array('code' => 'I'));
     $objArray[] = array('id' => 28, 'parent_id' => 3, 'is_locked' => 0, 'is_leaf' => 0, 'value' => '', 'sort_value' => 28, 'name' => 'Publication status (basic)', 'display_name' => $this->makeDisplayName($this->__('Publication status (basic)')), 'display_desc' => $this->makeDisplayDesc(), 'path' => '/__SYSTEM__/General/Publication Status Basic', 'ipath' => '/1/3/28', 'status' => 'A');
     $objArray[] = array('id' => 29, 'parent_id' => 28, 'is_locked' => 0, 'is_leaf' => 1, 'value' => 'P', 'sort_value' => 29, 'name' => 'Pending', 'display_name' => $this->makeDisplayName($this->__('Pending')), 'display_desc' => $this->makeDisplayDesc(), 'path' => '/__SYSTEM__/General/Publication Status Basic/Pending', 'ipath' => '/1/3/28/29', 'status' => 'A', '__ATTRIBUTES__' => array('code' => 'P'));
     $objArray[] = array('id' => 30, 'parent_id' => 28, 'is_locked' => 0, 'is_leaf' => 1, 'value' => 'A', 'sort_value' => 30, 'name' => 'Approved', 'display_name' => $this->makeDisplayName($this->__('Approved')), 'display_desc' => $this->makeDisplayDesc(), 'path' => '/__SYSTEM__/General/Publication Status Basic/Approved', 'ipath' => '/1/3/28/30', 'status' => 'A', '__ATTRIBUTES__' => array('code' => 'A'));
     $objArray[] = array('id' => 31, 'parent_id' => 1, 'is_locked' => 0, 'is_leaf' => 0, 'value' => '', 'sort_value' => 31, 'name' => 'Users', 'display_name' => $this->makeDisplayName($this->__('Users')), 'display_desc' => $this->makeDisplayDesc(), 'path' => '/__SYSTEM__/Users', 'ipath' => '/1/31', 'status' => 'A');
     $objArray[] = array('id' => 32, 'parent_id' => 2, 'is_locked' => 0, 'is_leaf' => 0, 'value' => '', 'sort_value' => 32, 'name' => 'Global', 'display_name' => $this->makeDisplayName($this->__('Global')), 'display_desc' => $this->makeDisplayDesc(), 'path' => '/__SYSTEM__/Modules/Global', 'ipath' => '/1/2/32', 'status' => 'A');
     $objArray[] = array('id' => 33, 'parent_id' => 32, 'is_locked' => 0, 'is_leaf' => 1, 'value' => '', 'sort_value' => 33, 'name' => 'Blogging', 'display_name' => $this->makeDisplayName($this->__('Blogging')), 'display_desc' => $this->makeDisplayDesc(), 'path' => '/__SYSTEM__/Modules/Global/Blogging', 'ipath' => '/1/2/32/33', 'status' => 'A');
     $objArray[] = array('id' => 34, 'parent_id' => 32, 'is_locked' => 0, 'is_leaf' => 1, 'value' => '', 'sort_value' => 34, 'name' => 'Music and audio', 'display_name' => $this->makeDisplayName($this->__('Music and audio')), 'display_desc' => $this->makeDisplayDesc(), 'path' => '/__SYSTEM__/Modules/Global/MusicAndAudio', 'ipath' => '/1/2/32/34', 'status' => 'A');
     $objArray[] = array('id' => 35, 'parent_id' => 32, 'is_locked' => 0, 'is_leaf' => 1, 'value' => '', 'sort_value' => 35, 'name' => 'Art and photography', 'display_name' => $this->makeDisplayName($this->__('Art and photography')), 'display_desc' => $this->makeDisplayDesc(), 'path' => '/__SYSTEM__/Modules/Global/ArtAndPhotography', 'ipath' => '/1/2/32/35', 'status' => 'A');
     $objArray[] = array('id' => 36, 'parent_id' => 32, 'is_locked' => 0, 'is_leaf' => 1, 'value' => '', 'sort_value' => 36, 'name' => 'Writing and thinking', 'display_name' => $this->makeDisplayName($this->__('Writing and thinking')), 'display_desc' => $this->makeDisplayDesc(), 'path' => '/__SYSTEM__/Modules/Global/WritingAndThinking', 'ipath' => '/1/2/32/36', 'status' => 'A');
     $objArray[] = array('id' => 37, 'parent_id' => 32, 'is_locked' => 0, 'is_leaf' => 1, 'value' => '', 'sort_value' => 37, 'name' => 'Communications and media', 'display_name' => $this->makeDisplayName($this->__('Communications and media')), 'display_desc' => $this->makeDisplayDesc(), 'path' => '/__SYSTEM__/Modules/Global/CommunicationsAndMedia', 'ipath' => '/1/2/32/37', 'status' => 'A');
     $objArray[] = array('id' => 38, 'parent_id' => 32, 'is_locked' => 0, 'is_leaf' => 1, 'value' => '', 'sort_value' => 38, 'name' => 'Travel and culture', 'display_name' => $this->makeDisplayName($this->__('Travel and culture')), 'display_desc' => $this->makeDisplayDesc(), 'path' => '/__SYSTEM__/Modules/Global/TravelAndCulture', 'ipath' => '/1/2/32/38', 'status' => 'A');
     $objArray[] = array('id' => 39, 'parent_id' => 32, 'is_locked' => 0, 'is_leaf' => 1, 'value' => '', 'sort_value' => 39, 'name' => 'Science and technology', 'display_name' => $this->makeDisplayName($this->__('Science and technology')), 'display_desc' => $this->makeDisplayDesc(), 'path' => '/__SYSTEM__/Modules/Global/ScienceAndTechnology', 'ipath' => '/1/2/32/39', 'status' => 'A');
     $objArray[] = array('id' => 40, 'parent_id' => 32, 'is_locked' => 0, 'is_leaf' => 1, 'value' => '', 'sort_value' => 40, 'name' => 'Sport and activities', 'display_name' => $this->makeDisplayName($this->__('Sport and activities')), 'display_desc' => $this->makeDisplayDesc(), 'path' => '/__SYSTEM__/Modules/Global/SportAndActivities', 'ipath' => '/1/2/32/40', 'status' => 'A');
     $objArray[] = array('id' => 41, 'parent_id' => 32, 'is_locked' => 0, 'is_leaf' => 1, 'value' => '', 'sort_value' => 41, 'name' => 'Business and work', 'display_name' => $this->makeDisplayName($this->__('Business and work')), 'display_desc' => $this->makeDisplayDesc(), 'path' => '/__SYSTEM__/Modules/Global/BusinessAndWork', 'ipath' => '/1/2/32/41', 'status' => 'A');
     foreach ($objArray as $obj) {
         $category = new \Zikula\Core\Doctrine\Entity\Category();
         if ($obj['parent_id'] == 0) {
             $obj['parent'] = null;
         } else {
             $obj['parent'] = $this->entityManager->getReference('Zikula\\Core\\Doctrine\\Entity\\Category', $obj['parent_id']);
         }
         unset($obj['parent_id']);
         if (isset($obj['__ATTRIBUTES__'])) {
             $attributes = $obj['__ATTRIBUTES__'];
             unset($obj['__ATTRIBUTES__']);
         }
         $category->merge($obj);
         $this->entityManager->persist($category);
         $this->entityManager->flush();
         if (isset($attributes)) {
             foreach ($attributes as $attrib_key => $attrib_name) {
                 $category->setAttribute($attrib_name, $attrib_key);
             }
         }
     }
     $this->entityManager->flush();
 }
Exemplo n.º 2
0
 /**
  * Copy Categories by Path (recursive copy).
  *
  * @param string  $apath        The path to copy from.
  * @param integer $newparent_id The categoryID of the new parent category.
  * @param string  $field        The field to use for the path reference (optional) (default='ipath').
  * @param boolean $includeRoot  Whether or not to also move the root folder (optional) (default=true).
  *
  * @return true or false.
  */
 public static function copyCategoriesByPath($apath, $newparent_id, $field = 'ipath', $includeRoot = true)
 {
     if (!$apath || !$newparent_id) {
         return false;
     }
     $cats = self::getSubCategoriesByPath($apath, 'ipath', $field, true, true);
     $newParentCats = self::getSubCategories($newparent_id, true, true, true, true, true);
     $newParent = $newParentCats[0];
     if (!$newParent || !$cats) {
         return false;
     }
     $currentPaths = array();
     foreach ($newParentCats as $p) {
         $currentPaths[] = $p['path_relative'];
     }
     // need to make sure that after copying categories will have unique paths
     foreach ($cats as $k => $cat) {
         if ($includeRoot) {
             // root node is included - just check path uniqueness for root
             // subnodes will inherit it's name in paths
             $catBasePath = $newParent['path_relative'] . '/';
             if ($k === 0 && in_array($catBasePath . $cats[0]['name'], $currentPaths)) {
                 // path is not unique - add arbitrary " Copy" suffix to category name
                 $cats[0]['name'] .= ' ' . __('Copy');
                 if (in_array($catBasePath . $cats[0]['name'], $currentPaths)) {
                     // if there is already such name
                     // find first free name by adding number at the end
                     $i = 1;
                     $name = $cats[0]['name'];
                     while (in_array($catBasePath . $name, $currentPaths)) {
                         $name = $cats[0]['name'] . ' ' . $i++;
                     }
                     $cats[0]['name'] = $name;
                 }
             }
         } elseif ($k !== 0) {
             // root node is excluded - need to check each subnode if it's path will be unique
             // follow the same routin that for the root node
             $catPath = explode('/', $cat['path_relative']);
             array_shift($catPath);
             array_pop($catPath);
             $catBasePath = $newParent['path_relative'] . '/' . implode('/', $catPath);
             if (in_array($catBasePath . $cats[$k]['name'], $currentPaths)) {
                 $cats[$k]['name'] .= ' ' . __('Copy');
                 if (in_array($catBasePath . $cats[$k]['name'], $currentPaths)) {
                     $i = 1;
                     $name = $cats[$k]['name'];
                     while (in_array($catBasePath . $name, $currentPaths)) {
                         $name = $cats[$k]['name'] . ' ' . $i++;
                     }
                     $cats[$k]['name'] = $name;
                 }
             }
         }
     }
     $em = \ServiceUtil::get('doctrine')->getManager();
     $oldToNewID = array();
     $oldToNewID[$cats[0]['parent']['id']] = $em->getReference('Zikula\\Core\\Doctrine\\Entity\\Category', $newParent['id']);
     // since array_shift() resets numeric array indexes, we remove the leading element like this
     if (!$includeRoot) {
         foreach ($cats as $k => $v) {
             if (isset($v['ipath']) && $v['ipath'] == $apath) {
                 unset($cats[$k]);
             }
         }
     }
     $ak = array_keys($cats);
     foreach ($ak as $v) {
         $cat = $cats[$v];
         // unset some variables
         unset($cat['parent_id']);
         unset($cat['accessible']);
         unset($cat['path_relative']);
         unset($cat['ipath_relative']);
         $oldID = $cat['id'];
         $cat['id'] = '';
         $cat['parent'] = isset($oldToNewID[$cat['parent']['id']]) ? $oldToNewID[$cat['parent']['id']] : $em->getReference('Zikula\\Core\\Doctrine\\Entity\\Category', $newParent['id']);
         $catObj = new Zikula\Core\Doctrine\Entity\Category();
         $catObj->merge($cat);
         $em->persist($catObj);
         $em->flush();
         $oldToNewID[$oldID] = $em->getReference('Zikula\\Core\\Doctrine\\Entity\\Category', $catObj['id']);
     }
     $em->flush();
     // rebuild iPath since now we have all new PathIDs
     self::rebuildPaths('ipath', 'id');
     // rebuild also paths since names could be changed
     self::rebuildPaths();
     return true;
 }
 /**
  * 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');
 }
Exemplo n.º 4
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);
 }
Exemplo n.º 5
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);
 }
Exemplo n.º 6
0
 /**
  * edit categories for the currently logged in user
  */
 public function edituserAction()
 {
     if (!SecurityUtil::checkPermission('Categories::category', '::', ACCESS_EDIT)) {
         throw new \Zikula\Framework\Exception\ForbiddenException();
     }
     if (!UserUtil::isLoggedIn()) {
         return LogUtil::registerError($this->__('Error! Editing mode for user-owned categories is only available to users who have logged-in.'));
     }
     $allowUserEdit = $this->getVar('allowusercatedit', 0);
     if (!$allowUserEdit) {
         return LogUtil::registerError($this->__('Error! User-owned category editing has not been enabled. This feature can be enabled by the site administrator.'));
     }
     $userRoot = $this->getVar('userrootcat', 0);
     if (!$userRoot) {
         return LogUtil::registerError($this->__('Error! Could not determine the user root node.'));
     }
     $userRootCat = CategoryUtil::getCategoryByPath($userRoot);
     if (!$userRoot) {
         return LogUtil::registerError($this->__f('Error! The user root node seems to point towards an invalid category: %s.', $userRoot));
     }
     if ($userRootCat == 1) {
         return LogUtil::registerError($this->__("Error! The root directory cannot be modified in 'user' mode"));
     }
     $userCatName = $this->getusercategorynameAction();
     if (!$userCatName) {
         return LogUtil::registerError($this->__('Error! Cannot determine user category root node name.'));
     }
     $thisUserRootCatPath = $userRoot . '/' . $userCatName;
     $thisUserRootCat = CategoryUtil::getCategoryByPath($thisUserRootCatPath);
     $dr = null;
     if (!$thisUserRootCat) {
         $autoCreate = $this->getVar('autocreateusercat', 0);
         if (!$autoCreate) {
             return LogUtil::registerError($this->__("Error! The user root category node for this user does not exist, and the automatic creation flag (autocreate) has not been set."));
         }
         $installer = new Installer($this->getContainer());
         $cat = array('id' => '', 'parent' => $this->entityManager->getReference('Zikula\\Core\\Doctrine\\Entity\\Category', $userRootCat['id']), 'name' => $userCatName, 'display_name' => unserialize($installer->makeDisplayName($userCatName)), 'display_desc' => unserialize($installer->makeDisplayDesc()), 'path' => $thisUserRootCatPath, 'status' => 'A');
         $obj = new \Zikula\Core\Doctrine\Entity\Category();
         $obj->merge($cat);
         $this->entityManager->persist($obj);
         $this->entityManager->flush();
         // since the original insert can't construct the ipath (since
         // the insert id is not known yet) we update the object here
         $obj->setIPath($userRootCat['ipath'] . '/' . $obj['id']);
         $this->entityManager->flush();
         $dr = $obj->getID();
         $autoCreateDefaultUserCat = $this->getVar('autocreateuserdefaultcat', 0);
         if ($autoCreateDefaultUserCat) {
             $userdefaultcatname = $this->getVar('userdefaultcatname', $this->__('Default'));
             $cat = array('id' => '', 'parent' => $this->entityManager->getReference('Zikula\\Core\\Doctrine\\Entity\\Category', $dr), 'is_leaf' => 1, 'name' => $userdefaultcatname, 'sort_value' => 0, 'display_name' => unserialize($installer->makeDisplayName($userdefaultcatname)), 'display_desc' => unserialize($installer->makeDisplayDesc()), 'path' => $thisUserRootCatPath . '/' . $userdefaultcatname, 'status' => 'A');
             $obj2 = new \Zikula\Core\Doctrine\Entity\Category();
             $obj2->merge($cat);
             $this->entityManager->persist($obj2);
             $this->entityManager->flush();
             // since the original insert can't construct the ipath (since
             // the insert id is not known yet) we update the object here
             $obj2->setIPath($obj['ipath'] . '/' . $obj2['id']);
             $this->entityManager->flush();
         }
     } else {
         $dr = $thisUserRootCat['id'];
     }
     $url = ModUtil::url('Categories', 'user', 'edit', array('dr' => $dr));
     return $this->redirect($url);
 }
Exemplo n.º 7
0
 /**
  * Process the attributes of a category
  *
  * @param Zikula\Core\Doctrine\Entity\Category $category    The category to set the attributes for.
  * @param array $attrib_names                               The attribute names.
  * @param array $attrib_values                              The attribute values.
  *
  * @return none.
  */
 public static function processCategoryAttributes($category, $attrib_names, $attrib_values)
 {
     // delete attributes
     if (isset($category['attributes'])) {
         foreach ($category['attributes'] as $attribute) {
             if (!in_array($attribute['name'], $attrib_names)) {
                 $category->delAttribute($attribute['name']);
             }
         }
     }
     // add/update attributes
     foreach ($attrib_names as $attrib_key => $attrib_name) {
         if (!empty($attrib_name)) {
             $category->setAttribute($attrib_name, $attrib_values[$attrib_key]);
         }
     }
 }