コード例 #1
0
 /**
  * initialise module
  *
  * @return bool true if successful, false otherwise
  */
 public function install()
 {
     // create tables
     $classes = array('Zikula\\CategoriesModule\\Entity\\CategoryEntity', 'Zikula\\CategoriesModule\\Entity\\CategoryAttributeEntity', 'Zikula\\CategoriesModule\\Entity\\CategoryRegistryEntity');
     try {
         DoctrineHelper::createSchema($this->entityManager, $classes);
     } catch (\Exception $e) {
         return false;
     }
     /**
      * This entity is only used to install the table and it
      * is @deprecated as of 1.4.0 because the Objectdata paradigm
      * is being removed at 2.0.0
      */
     try {
         DoctrineHelper::createSchema($this->entityManager, array('Zikula\\CategoriesModule\\Entity\\CategoriesMapobj'));
     } catch (\Exception $e) {
         return false;
     }
     /**
      * explicitly set admin as user to be set as `lu_uid` and `cr_uid` fields. Normally this would be taken care of
      * by the BlameListener but during installation from the CLI this listener is not available
      */
     $adminUserObj = $this->entityManager->getReference('ZikulaUsersModule:UserEntity', 2);
     // insert default data
     $this->insertData_10($adminUserObj);
     // Set autonumber to 10000 (for DB's that support autonumber fields)
     $cat = new CategoryEntity();
     $cat->setId(9999);
     $cat->setLu_uid($adminUserObj);
     $cat->setCr_uid($adminUserObj);
     $this->entityManager->persist($cat);
     $this->entityManager->flush();
     $this->entityManager->remove($cat);
     $this->entityManager->flush();
     // set module vars
     $this->setVar('userrootcat', '/__SYSTEM__/Users');
     $this->setVar('allowusercatedit', 0);
     $this->setVar('autocreateusercat', 0);
     $this->setVar('autocreateuserdefaultcat', 0);
     $this->setVar('userdefaultcatname', 'Default');
     // Initialisation successful
     return true;
 }
コード例 #2
0
 /**
  * @Route("/new")
  * @Method("POST")
  *
  * create category
  *
  * @return RedirectResponse
  *
  * @throws AccessDeniedException Thrown if the user doesn't have permission to add a category
  */
 public function newcatAction()
 {
     $this->checkCsrfToken();
     if (!SecurityUtil::checkPermission('ZikulaCategoriesModule::', '::', ACCESS_ADD)) {
         throw new AccessDeniedException();
     }
     // get data from post
     $data = $this->request->request->get('category', null);
     $valid = GenericUtil::validateCategoryData($data);
     if (!$valid) {
         return new RedirectResponse($this->get('router')->generate('zikulacategoriesmodule_admin_newcat', array(), RouterInterface::ABSOLUTE_URL));
     }
     // process name
     $data['name'] = GenericUtil::processCategoryName($data['name']);
     // process parent
     $data['parent'] = GenericUtil::processCategoryParent($data['parent_id']);
     unset($data['parent_id']);
     // process display names
     $data['display_name'] = GenericUtil::processCategoryDisplayName($data['display_name'], $data['name']);
     // save category
     $category = new CategoryEntity();
     $category->merge($data);
     $this->entityManager->persist($category);
     $this->entityManager->flush();
     // process path and ipath
     $category['path'] = GenericUtil::processCategoryPath($data['parent']['path'], $category['name']);
     $category['ipath'] = 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());
     GenericUtil::processCategoryAttributes($category, $attrib_names, $attrib_values);
     $this->entityManager->flush();
     $msg = __f('Done! Inserted the %s category.', $category['name']);
     $this->request->getSession()->getFlashBag()->add('status', $msg);
     return new RedirectResponse($this->get('router')->generate('zikulacategoriesmodule_admin_view', array(), RouterInterface::ABSOLUTE_URL) . '#top');
 }
コード例 #3
0
ファイル: GenericUtil.php プロジェクト: Silwereth/core
 /**
  * Process the attributes of a category
  *
  * @param \Zikula\CategoriesModule\Entity\CategoryEntity $category The category to set the attributes for.
  * @param array $attrib_names                                             The attribute names.
  * @param array $attrib_values                                            The attribute values.
  *
  * @return void
  */
 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]);
         }
     }
 }
コード例 #4
0
ファイル: CategoryUtil.php プロジェクト: Silwereth/core
 /**
  * create a JSON formatted object compatible with jsTree node structure for one category (includes children)
  *
  * @param \Zikula\CategoriesModule\Entity\CategoryEntity $category
  * @return array
  */
 public static function getJsTreeNodeFromCategory(\Zikula\CategoriesModule\Entity\CategoryEntity $category)
 {
     $lang = ZLanguage::getLanguageCode();
     return array('id' => 'node_' . $category->getId(), 'text' => $category->getDisplay_name($lang), 'icon' => $category->getIs_leaf() ? false : 'fa fa-folder', 'state' => array('open' => false, 'disabled' => false, 'selected' => false), 'children' => self::getJsTreeNodeFromCategoryArray($category->getChildren()), 'li_attr' => array('class' => $category->getStatus() == 'I' ? 'z-tree-unactive' : ''), 'a_attr' => array('title' => self::createTitleAttribute($category->toArray(), $category->getDisplay_name($lang), $lang)));
 }