コード例 #1
0
 /**
  * view categories
  */
 public function view()
 {
     $root_id = FormUtil::getPassedValue('dr', 1);
     if (!SecurityUtil::checkPermission('Categories::category', "ID::{$root_id}", ACCESS_EDIT)) {
         return LogUtil::registerPermissionError();
     }
     if (!SecurityUtil::checkPermission('Categories::category', '::', ACCESS_EDIT)) {
         return LogUtil::registerPermissionError();
     }
     $cats = CategoryUtil::getSubCategories($root_id, true, true, true, true, true);
     $menuTxt = CategoryUtil::getCategoryTreeJS($cats, true, true);
     $this->view->assign('menuTxt', $menuTxt);
     return $this->view->fetch('categories_admin_view.tpl');
 }
コード例 #2
0
 public function save()
 {
     $this->checkAjaxToken();
     $mode = $this->request->getPost()->get('mode', 'new');
     $accessLevel = $mode == 'edit' ? ACCESS_EDIT : ACCESS_ADD;
     $this->throwForbiddenUnless(SecurityUtil::checkPermission('Categories::', '::', $accessLevel));
     $result = array();
     $cat = new Categories_DBObject_Category();
     $cat->getDataFromInput();
     if (!$cat->validate()) {
         $args = array('cid' => $cat->getDataField('id'), 'parent' => $cat->getDataField('parent_id'), 'mode' => $mode);
         return $this->edit($args);
     }
     $attributes = array();
     $values = $this->request->getPost()->get('attribute_value');
     foreach ($this->request->getPost()->get('attribute_name') as $index => $name) {
         if (!empty($name)) {
             $attributes[$name] = $values[$index];
         }
     }
     $cat->setDataField('__ATTRIBUTES__', $attributes);
     if ($mode == 'edit') {
         // retrieve old category from DB
         $category = $this->request->getPost()->get('category');
         $oldCat = new Categories_DBObject_Category(DBObject::GET_FROM_DB, $category['id']);
         // update new category data
         $cat->update();
         // since a name change will change the object path, we must rebuild it here
         if ($oldCat->getDataField('name') != $cat->getDataField('name')) {
             CategoryUtil::rebuildPaths('path', 'name', $cat->getDataField('id'));
         }
     } else {
         $cat->insert();
         // update new category data
         $cat->update();
     }
     $categories = CategoryUtil::getSubCategories($cat->getDataField('id'), true, true, true, true, true);
     $options = array('nullParent' => $cat->getDataField('parent_id'), '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' => $cat->getDataField('id'), 'parent' => $cat->getDataField('parent_id'), 'node' => $node, 'leafstatus' => $leafStatus, 'result' => true);
     return new Zikula_Response_Ajax($result);
 }