Example #1
0
/**
 * Returns the current course info array.
 * Now if the course_code is given, the returned array gives info about that
 * particular course, not specially the current one.
 * @param int $id Numeric ID of the course
 * @return array The course info as an array formatted by api_format_course_array, including category.name
 */
function api_get_course_info_by_id($id = null)
{
    if (!empty($id)) {
        $id = intval($id);
        $course_table = Database::get_main_table(TABLE_MAIN_COURSE);
        $course_cat_table = Database::get_main_table(TABLE_MAIN_CATEGORY);
        $sql = "SELECT\n                    course.*,\n                    course_category.code faCode,\n                    course_category.name faName\n                FROM {$course_table}\n                LEFT JOIN {$course_cat_table}\n                ON course.category_code =  course_category.code\n                WHERE course.id = {$id}";
        $result = Database::query($sql);
        $_course = array();
        if (Database::num_rows($result) > 0) {
            $course_data = Database::fetch_array($result);
            $_course = api_format_course_array($course_data);
        }
        return $_course;
    }
    global $_course;
    if ($_course == '-1') {
        $_course = array();
    }
    return $_course;
}
Example #2
0
/**
 * Returns the current course info array.
 * Now if the course_code is given, the returned array gives info about that
 * particular course, not specially the current one.
 */
function api_get_course_info_by_id($id = null, $add_extra_values = false)
{
    if (!empty($id)) {
        $id = intval($id);
        $course_table = Database::get_main_table(TABLE_MAIN_COURSE);
        $course_cat_table = Database::get_main_table(TABLE_MAIN_CATEGORY);
        $sql = "SELECT course.*, course_category.code faCode, course_category.name faName\n                 FROM {$course_table}\n                 LEFT JOIN {$course_cat_table}\n                 ON course.category_code =  course_category.code\n                 WHERE course.id = {$id}";
        $result = Database::query($sql);
        $_course = array();
        if (Database::num_rows($result) > 0) {
            $course_data = Database::fetch_array($result);
            if ($add_extra_values) {
                $extra_field_values = new ExtraField('course');
                $course_data['extra_fields'] = $extra_field_values->get_handler_extra_data($course_data['code']);
            }
            $_course = api_format_course_array($course_data);
        }
        return $_course;
    }
    $_course = Session::read('_course');
    if ($_course == '-1') {
        $_course = array();
    }
    return $_course;
}