/**
  * Moves a cateogry from its parent to another
  * 
  * @access public
  * @param CMS_moduleCategory $category 
  * @param CMS_moduleCategory $parentCategory
  * @param integer $index : the new index for the new parent (if false, put the category at last position)
  * @return boolean true on success, false on failure
  */
 static function moveCategory(&$category, &$newParentCategory, $index = false)
 {
     if (!$newParentCategory instanceof CMS_moduleCategory) {
         CMS_grandFather::raiseError("Bad parent given, not a valid CMS_moduleCategory instance");
         return false;
     }
     if (!$category instanceof CMS_moduleCategory) {
         CMS_grandFather::raiseError("Bad category given, not a valid CMS_moduleCategory instance");
         return false;
     }
     if ($category->hasParent($newParentCategory) && $index === false) {
         CMS_grandFather::raiseError("Category is already child of new parent given");
         return false;
     }
     if ($category->hasParent($newParentCategory)) {
         //this is only a change of category index so  move category to new index
         return CMS_moduleCategories_catalog::moveCategoryIndex($category, $index);
     } else {
         $oldParentCategory = $category->getParent();
         if (CMS_moduleCategories_catalog::attachCategory($category, $newParentCategory)) {
             if (!CMS_moduleCategories_catalog::compactSiblingsOrder($oldParentCategory)) {
                 CMS_grandFather::raiseError("Cannot compact sibling order for parent category");
                 return false;
             }
             if (!$index) {
                 return true;
             } else {
                 //reload category
                 $category = new CMS_moduleCategory($category->getID());
                 //then move category to new index
                 return CMS_moduleCategories_catalog::moveCategoryIndex($category, $index);
             }
         } else {
             CMS_grandFather::raiseError("Movement failed for category " . $category->getID());
             return false;
         }
     }
 }