/** * create recursively all categories as option of the select passed in parameter. * * @param HTML_QuickForm_Element $element * @param string $defaultCode the option value to select by default (used mainly for edition of courses) * @param string $parentCode the parent category of the categories added (default=null for root category) * @param string $padding the indent param (you shouldn't indicate something here) */ function setCategoriesInForm($element, $defaultCode = null, $parentCode = null, $padding = null) { $tbl_category = Database::get_main_table(TABLE_MAIN_CATEGORY); $conditions = null; $whereCondition = null; if (isMultipleUrlSupport()) { $table = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE_CATEGORY); $conditions = " INNER JOIN {$table} a ON (c.id = a.course_category_id)"; $whereCondition = " AND a.access_url_id = " . api_get_current_access_url_id(); } $sql = "SELECT code, name, auth_course_child, auth_cat_child\n FROM " . $tbl_category . " c\n {$conditions}\n WHERE parent_id " . (empty($parentCode) ? "IS NULL" : "='" . Database::escape_string($parentCode) . "'") . "\n {$whereCondition}\n ORDER BY name, code"; $res = Database::query($sql); while ($cat = Database::fetch_array($res, 'ASSOC')) { $params = $cat['auth_course_child'] == 'TRUE' ? '' : 'disabled'; $params .= $cat['code'] == $defaultCode ? ' selected' : ''; $option = $padding . ' ' . $cat['name'] . ' (' . $cat['code'] . ')'; $element->addOption($option, $cat['code'], $params); if ($cat['auth_cat_child'] == 'TRUE') { setCategoriesInForm($element, $defaultCode, $cat['code'], $padding . ' - '); } } }
/** * create recursively all categories as option of the select passed in parameter. * * @param HTML_QuickForm_Element $element * @param string $defaultCode the option value to select by default (used mainly for edition of courses) * @param string $parentCode the parent category of the categories added (default=null for root category) * @param string $padding the indent param (you shouldn't indicate something here) * @deprecated use the select_ajax solution see admin/course_edit.php */ public static function select_and_sort_categories($element, $defaultCode = null, $parentCode = null, $padding = null) { require_once api_get_path(LIBRARY_PATH) . 'course_category.lib.php'; setCategoriesInForm($element, $defaultCode, $parentCode, $padding); }