/**
  * Moves position of a category in list, with given offset
  * 
  * @access public
  * @param CMS_moduleCategory $siblingCategory 
  * @param integer $moveOffset values 1 or -1 expected
  * @return boolean true on succes, false on failure
  */
 static function moveCategoryOrder(&$siblingCategory, $moveOffset)
 {
     // Checks : pages must be CMS_moduleCategory and offset in (1, -1)
     if (!$siblingCategory instanceof CMS_moduleCategory) {
         CMS_grandFather::raiseError("Category to move not valid.");
         return false;
     }
     if (!SensitiveIO::isInSet($moveOffset, array(1, -1))) {
         CMS_grandFather::raiseError("Offset must be 1 or -1");
         return false;
     }
     // Find the siblings to switch order
     $parent = $siblingCategory->getParent();
     // Use this function to compact of siblings order
     if (!$parent instanceof CMS_moduleCategory || !CMS_moduleCategories_catalog::compactSiblingsOrder($parent->getID())) {
         CMS_grandFather::raiseError("Reordering siblings failed for category " . $parent->getID());
         return false;
     }
     $siblings = $parent->getSiblings();
     $sibling_to_move_left = false;
     $sibling_to_move_right = false;
     $lastSibling = false;
     foreach ($siblings as $aSibling) {
         if ($moveOffset == 1 && $lastSibling && $lastSibling->getID() == $siblingCategory->getID()) {
             $sibling_to_move_left = $aSibling;
             $sibling_to_move_right = $siblingCategory;
             break;
         }
         if ($moveOffset == -1 && $lastSibling && $aSibling->getID() == $siblingCategory->getID()) {
             $sibling_to_move_left = $siblingCategory;
             $sibling_to_move_right = $lastSibling;
             break;
         }
         $lastSibling = $aSibling;
     }
     if ($sibling_to_move_left && $sibling_to_move_right) {
         //move the siblings order
         $sql = "\n\t\t\t\tupdate\n\t\t\t\t\tmodulesCategories\n\t\t\t\tset\n\t\t\t\t\torder_mca=order_mca - 1\n\t\t\t\twhere\n\t\t\t\t\tid_mca='" . $sibling_to_move_left->getID() . "'\n\t\t\t";
         $q = new CMS_query($sql);
         $sql = "\n\t\t\t\tupdate\n\t\t\t\t\tmodulesCategories\n\t\t\t\tset\n\t\t\t\t\torder_mca=order_mca + 1\n\t\t\t\twhere\n\t\t\t\t\tid_mca='" . $sibling_to_move_right->getID() . "'\n\t\t\t";
         $q = new CMS_query($sql);
         //Clear polymod cache
         //CMS_cache::clearTypeCacheByMetas('polymod', array('module' => $sibling_to_move_right->getAttribute('moduleCodename')));
         CMS_cache::clearTypeCache('polymod');
         return true;
     } else {
         CMS_grandFather::raiseError("Move impossible (first or last sibling to move, or parent and sibling not related");
         return false;
     }
 }
 } else {
     // Parent category
     $parentCategory = CMS_moduleCategories_catalog::getById($parentId);
 }
 $parentCategory->setAttribute('language', $cms_language);
 //check mandatory fields
 if (!$defaultLabel) {
     $cms_message .= $cms_language->getMessage(MESSAGE_FORM_ERROR_MANDATORY_FIELDS);
     break;
 } else {
     // If insertion, must be saved once added to its parent
     $newParentCategory = CMS_moduleCategories_catalog::getById($parentId);
     if (!$newParentCategory->hasError()) {
         // Detach from current category
         $oldParentCategory = $item->getParent();
         if ($item->getID()) {
             if ($oldParentCategory->getID() != $newParentCategory->getID()) {
                 if (!CMS_moduleCategories_catalog::detachCategory($item)) {
                     $cms_message .= $cms_language->getMessage(MESSAGE_PAGE_ACTION_SAVE_ERROR);
                 }
                 // Attach to new category
                 if (!CMS_moduleCategories_catalog::attachCategory($item, $newParentCategory)) {
                     $cms_message .= $cms_language->getMessage(MESSAGE_PAGE_ACTION_SAVE_ERROR);
                 }
             }
         } else {
             // Attach to new category
             if (!CMS_moduleCategories_catalog::attachCategory($item, $newParentCategory)) {
                 $cms_message .= $cms_language->getMessage(MESSAGE_PAGE_ACTION_SAVE_ERROR);
             }
         }
示例#3
0
 /**
  * If module use CMS_moduleCategory, does it use it
  *
  * @param CMS_moduleCategory $category The to check useage by module
  * @return Boolean true/false
  * @access public
  */
 function isCategoryUsed($category)
 {
     static $moduleUseCategories, $moduleFieldsCategories;
     if (!isset($moduleUseCategories)) {
         $moduleUseCategories = CMS_poly_object_catalog::moduleHasCategories($this->_codename);
     }
     if (!$moduleUseCategories) {
         return false;
     }
     if (!isset($moduleFieldsCategories)) {
         $moduleFieldsCategories = array();
         //get all module objects fields which uses categories
         $moduleObjects = CMS_poly_object_catalog::getObjectsForModule($this->_codename);
         foreach ($moduleObjects as $object) {
             $moduleFieldsCategories = array_merge(CMS_poly_object_catalog::objectHasCategories($object->getID()), $moduleFieldsCategories);
         }
     }
     //then check for category value in this fields (edited)
     $sql = "select\n\t\t\t\t\tid\n\t\t\t\tfrom\n\t\t\t\t\tmod_subobject_integer_edited\n\t\t\t\twhere\n\t\t\t\t\tobjectFieldID in (" . implode(',', $moduleFieldsCategories) . ")\n\t\t\t\t\tand value = '" . $category->getID() . "'\n\t\t\t\t";
     $q = new CMS_query($sql);
     if ($q->getNumRows()) {
         return true;
     }
     //then check for category value in this fields (public)
     $sql = "select\n\t\t\t\t\tid\n\t\t\t\tfrom\n\t\t\t\t\tmod_subobject_integer_public\n\t\t\t\twhere\n\t\t\t\t\tobjectFieldID in (" . implode(',', $moduleFieldsCategories) . ")\n\t\t\t\t\tand value = '" . $category->getID() . "'\n\t\t\t\t";
     $q = new CMS_query($sql);
     return $q->getNumRows() ? true : false;
 }
示例#4
0
 /** 
  * Recursive function to build the categories tree.
  *
  * @param CMS_moduleCategory $category
  * @param integer $count, to determine category in-tree depth
  * @return string HTML formated
  */
 function build_category_tree_options($category, $count)
 {
     global $codename, $cms_language, $parentCategory, $cms_module, $cms_user, $catId;
     //if category is not itself (to avoid infinite loop in lineage)
     $a = array();
     if ($category->getID() != $catId) {
         $category->setAttribute('language', $cms_language);
         $label = htmlspecialchars($category->getLabel());
         if ($count >= 1) {
             $label = str_repeat(' ::', $count) . ' ' . $label;
         }
         $a[] = array($category->getID(), $label);
         $count++;
         $attrs = array("module" => $codename, "language" => $cms_language, "level" => $category->getID(), "root" => -1, "cms_user" => $cms_user, "clearanceLevel" => CLEARANCE_MODULE_MANAGE, "strict" => true);
         $siblings = CMS_module::getModuleCategories($attrs);
         if (sizeof($siblings)) {
             foreach ($siblings as $aSibling) {
                 $aSibling->setAttribute('language', $cms_language);
                 $a = array_merge($a, build_category_tree_options($aSibling, $count));
             }
         }
     }
     return $a;
 }