/** * Return a given category lineage * * @param array $values : parameters values array(parameterName => parameterValue) in : * category : the category id * @param multidimentionnal array $tags : xml2Array content of atm-function tag * ... {id} ... {label} ... * @return string : the category * @access public */ function category($values, $tags) { global $cms_language; $return = ""; if (!sensitiveIO::isPositiveInteger($values['category'])) { $this->raiseError("Category value parameter must be a valid category ID : " . $values['category']); return false; } if (!isset($tags[0]['textnode'])) { $this->raiseError("atm-function tag must have a content"); return false; } $params = $this->getParamsValues(); $category = new CMS_moduleCategory($values['category']); if ($category->hasError()) { $this->raiseError("Category " . $values['category'] . " has an error ..."); return false; } $replace = array('{id}' => $values['category'], '{label}' => $category->getLabel($cms_language), '{description}' => $category->getDescription($cms_language)); $xml2Array = new CMS_XML2Array(); $xml = $xml2Array->toXML($tags); $return .= str_replace(array_keys($replace), $replace, $xml); return $return; }
/** * Import module from given array datas * * @param array $data The module datas to import * @param array $params The import parameters. * array( * module => false|true : the module to create categories (required) * create => false|true : create missing objects (default : true) * update => false|true : update existing objects (default : true) * files => false|true : use files from PATH_TMP_FS (default : true) * ) * @param CMS_language $cms_language The CMS_langage to use * @param array $idsRelation : Reference : The relations between import datas ids and real imported ids * @param string $infos : Reference : The import infos returned * @return boolean : true on success, false on failure * @access public */ static function fromArray($data, $params, $cms_language, &$idsRelation, &$infos) { if (!isset($params['module'])) { $infos .= 'Error : missing module codename for categories importation ...' . "\n"; return false; } $module = CMS_modulesCatalog::getByCodename($params['module']); if ($module->hasError()) { $infos .= 'Error : invalid module for categories importation : ' . $params['module'] . "\n"; return false; } $return = true; foreach ($data as $categoryDatas) { $importType = ''; if (isset($categoryDatas['uuid']) && ($id = CMS_moduleCategories_catalog::categoryExists($params['module'], $categoryDatas['uuid']))) { //category already exist : load it if we can update it if (!isset($params['update']) || $params['update'] == true) { $category = CMS_moduleCategories_catalog::getByID($id); $importType = ' (Update)'; } } else { //create new category if we can if (!isset($params['create']) || $params['create'] == true) { //if category to create has parent, try to get it if (isset($categoryDatas['parent']) && $categoryDatas['parent']) { //check for uuid translation if (isset($idsRelation['categories-uuid'][$categoryDatas['parent']])) { $categoryDatas['parent'] = $idsRelation['categories-uuid'][$categoryDatas['parent']]; } //parent already exist : load it $parentId = CMS_moduleCategories_catalog::categoryExists($params['module'], $categoryDatas['parent']); } if (isset($categoryDatas['root']) && $categoryDatas['root']) { //check for uuid translation if (isset($idsRelation['categories-uuid'][$categoryDatas['root']])) { $categoryDatas['root'] = $idsRelation['categories-uuid'][$categoryDatas['root']]; } //root already exist : load it $rootId = CMS_moduleCategories_catalog::categoryExists($params['module'], $categoryDatas['root']); } //create category $category = new CMS_moduleCategory(0, $cms_language); $importType = ' (Creation)'; //set module $category->setAttribute('moduleCodename', $params['module']); if (isset($rootId)) { $category->setAttribute('rootID', $rootId); } if (isset($parentId)) { $category->setAttribute('parentID', $parentId); } } } if (isset($category)) { if ($category->fromArray($categoryDatas, $params, $cms_language, $idsRelation, $infos)) { $return &= true; $infos .= 'Category "' . $category->getLabel($cms_language) . '" successfully imported' . $importType . "\n"; } else { $return = false; $infos .= 'Error during import of category ' . $categoryDatas['id'] . $importType . "\n"; } } } return $return; }
/** * 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; }
/** * Get parent category to this one * * @access public * @return CMS_moduleCategory */ function getParent() { if (sensitiveIO::isPositiveInteger($this->_parentID)) { return CMS_moduleCategories_catalog::getById($this->_parentID); } else { $parent = new CMS_moduleCategory(0); $parent->setAttribute('moduleCodename', $this->_moduleCodename); return $parent; } }
$father = new CMS_moduleCategory($category->getAttribute('parentID')); if (CMS_moduleCategories_catalog::detachCategory($category)) { $cms_message = $cms_language->getMessage(MESSAGE_ACTION_OPERATION_DONE); $content = array('success' => true); } else { $cms_message = $cms_language->getMessage(MESSAGE_PAGE_ACTION_DELETE_ERROR); } } else { $cms_message = $cms_language->getMessage(MESSAGE_PAGE_ACTION_ERROR_PROTECTED); $category->raiseError('Error during modification of category ' . $category->getID() . '. Category is protected.'); } break; case 'move': $category = new CMS_moduleCategory($categoryId); if (!$category->isProtected()) { $newParent = new CMS_moduleCategory($newParentId); if (!$newParentId) { $newParent->setAttribute('moduleCodename', $codename); } $index++; //+1 because interface start index to 0 and system start it to 1 if (CMS_moduleCategories_catalog::moveCategory($category, $newParent, $index)) { $content = array('success' => true); } else { $cms_message = $cms_language->getMessage(MESSAGE_ERROR_CATEGORY_MOVE); } } else { $cms_message = $cms_language->getMessage(MESSAGE_PAGE_ACTION_ERROR_PROTECTED); $category->raiseError('Error during modification of category ' . $category->getID() . '. Category is protected.'); } break;
/** * 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; }