/** * 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; } }
switch ($action) { case 'save': $all_languages = CMS_languagesCatalog::getAllLanguages($codename); $parentId = sensitiveIO::request('parentId', 'sensitiveIO::isPositiveInteger'); $icon = sensitiveIO::request('icon'); $defaultLabel = sensitiveIO::request('label_' . $module->getDefaultLanguageCodename()); // Current category object to manipulate $item = new CMS_moduleCategory($categoryId); //check protected status $protected = sensitiveIO::request('protected') ? true : false; if (!$item->isProtected() || !$protected && $cms_user->hasAdminClearance(CLEARANCE_ADMINISTRATION_EDITVALIDATEALL)) { $item->setAttribute('language', $cms_language); $item->setAttribute('moduleCodename', $codename); $item->setProtected($protected); if (!$parentId) { $parentCategory = $item->getParent(); } 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();