Example #1
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->getusercategoryname();
     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_id' => $userRootCat['id'], 'name' => $userCatName, 'display_name' => unserialize($installer->makeDisplayName($userCatName)), 'display_desc' => unserialize($installer->makeDisplayDesc()), 'security_domain' => 'Categories::', 'path' => $thisUserRootCatPath, 'status' => 'A');
         $obj = new Category();
         $obj->setData($cat);
         $obj->insert();
         // since the original insert can't construct the ipath (since
         // the insert id is not known yet) we update the object here
         $obj->update();
         $dr = $obj->getID();
         $autoCreateDefaultUserCat = $this->getVar('autocreateuserdefaultcat', 0);
         if ($autoCreateDefaultUserCat) {
             $userdefaultcatname = $this->getVar('userdefaultcatname', $this->__('Default'));
             $cat = array('id' => '', 'parent_id' => $dr, 'name' => $userdefaultcatname, 'display_name' => unserialize($installer->makeDisplayName($userdefaultcatname)), 'display_desc' => unserialize($installer->makeDisplayDesc()), 'security_domain' => 'Categories::', 'path' => $thisUserRootCatPath . '/' . $userdefaultcatname, 'status' => 'A');
             $obj->setData($cat);
             $obj->insert();
             // since the original insert can't construct the ipath (since
             // the insert id is not known yet) we update the object here
             $obj->update();
         }
     } else {
         $dr = $thisUserRootCat['id'];
     }
     $url = ModUtil::url('Categories', 'user', 'edit', array('dr' => $dr));
     return $this->redirect($url);
 }