/** * 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; }
/** * 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; }
/** * 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; }