/** * 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; }
$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; default: CMS_grandFather::raiseError('Unknown action to do ...');
/** * 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; } }
/** * 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; }