/** * Returns each category ID and label in a module given user can see * * @access public * @param CMS_language $cms_language, the language of the labels * @param boolean $restrictToUsedCat, restrict returned categories to used ones only (default false) * @return array(string) the statements or false if profile hasn't any access to any categories */ function getAllCategoriesAsArray($language = false, $restrictToUsedCat = false) { global $cms_user; $categories = CMS_moduleCategories_catalog::getAllCategoriesAsArray($cms_user, MOD_CMS_FORMS_CODENAME, $language); //pr($categories); if (!$restrictToUsedCat) { return $categories; } else { //Get all used categories IDS for this object field $usedCategories = CMS_forms_formularCategories::getAllUsedCategoriesForField($language); if (sizeof($usedCategories)) { //get all categories lineage $catArbo = CMS_moduleCategories_catalog::getViewvableCategoriesForProfile($cms_user, MOD_CMS_FORMS_CODENAME, true); //pr($catArbo); //need to remove all unused categories from list $categoriesToKeep = array(); foreach ($usedCategories as $catID) { $cats = explode(';', $catArbo[$catID]); foreach ($cats as $aCat) { $categoriesToKeep[$aCat] = $aCat; } } //pr($categoriesToKeep); //then remove unused categories from initial list foreach ($categories as $catID => $catLabel) { if (!isset($categoriesToKeep[$catID])) { unset($categories[$catID]); } } //pr($categories); return $categories; } else { //no categories used return array(); } } }