Exemplo n.º 1
0
/**
 * Get course data to display
 */
function get_course_data($from, $number_of_items, $column, $direction)
{
    $course_table = Database::get_main_table(TABLE_MAIN_COURSE);
    $sql = "SELECT  code AS col0,\n                    title AS col1,\n                    code AS col2,\n                    course_language AS col3,\n                    category_code AS col4,\n                    subscribe AS col5,\n                    unsubscribe AS col6,\n                    code AS col7,\n                    visibility AS col8,\n                    directory as col9,\n                    visual_code\n    \t\tFROM {$course_table} course";
    if ((api_is_platform_admin() || api_is_session_admin()) && api_is_multiple_url_enabled() && api_get_current_access_url_id() != -1) {
        $access_url_rel_course_table = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE);
        $sql .= " INNER JOIN {$access_url_rel_course_table} url_rel_course ON (course.id = url_rel_course.c_id)";
    }
    if (isset($_GET['keyword'])) {
        $keyword = Database::escape_string(trim($_GET['keyword']));
        $sql .= " WHERE (title LIKE '%" . $keyword . "%' OR code LIKE '%" . $keyword . "%' OR visual_code LIKE '%" . $keyword . "%' ) ";
    } elseif (isset($_GET['keyword_code'])) {
        $keyword_code = Database::escape_string($_GET['keyword_code']);
        $keyword_title = Database::escape_string($_GET['keyword_title']);
        $keyword_category = Database::escape_string($_GET['keyword_category']);
        $keyword_language = Database::escape_string($_GET['keyword_language']);
        $keyword_visibility = Database::escape_string($_GET['keyword_visibility']);
        $keyword_subscribe = Database::escape_string($_GET['keyword_subscribe']);
        $keyword_unsubscribe = Database::escape_string($_GET['keyword_unsubscribe']);
        $sql .= " WHERE (code LIKE '%" . $keyword_code . "%' OR visual_code LIKE '%" . $keyword_code . "%') AND title LIKE '%" . $keyword_title . "%' AND category_code LIKE '%" . $keyword_category . "%'  AND course_language LIKE '%" . $keyword_language . "%'   AND visibility LIKE '%" . $keyword_visibility . "%'    AND subscribe LIKE '" . $keyword_subscribe . "'AND unsubscribe LIKE '" . $keyword_unsubscribe . "'";
    }
    // Adding the filter to see the user's only of the current access_url.
    if ((api_is_platform_admin() || api_is_session_admin()) && api_is_multiple_url_enabled() && api_get_current_access_url_id() != -1) {
        $sql .= " AND url_rel_course.access_url_id=" . api_get_current_access_url_id();
    }
    $sql .= " ORDER BY col{$column} {$direction} ";
    $sql .= " LIMIT {$from},{$number_of_items}";
    $res = Database::query($sql);
    $courses = array();
    while ($course = Database::fetch_array($res)) {
        // Place colour icons in front of courses.
        $show_visual_code = $course['visual_code'] != $course[2] ? Display::label($course['visual_code'], 'info') : null;
        $course[1] = get_course_visibility_icon($course[8]) . '<a href="' . api_get_path(WEB_COURSE_PATH) . $course[9] . '/index.php">' . $course[1] . '</a> ' . $show_visual_code;
        $course[5] = $course[5] == SUBSCRIBE_ALLOWED ? get_lang('Yes') : get_lang('No');
        $course[6] = $course[6] == UNSUBSCRIBE_ALLOWED ? get_lang('Yes') : get_lang('No');
        $course_rem = array($course[0], $course[1], $course[2], $course[3], $course[4], $course[5], $course[6], $course[7]);
        $courses[] = $course_rem;
    }
    return $courses;
}
Exemplo n.º 2
0
/**
 * Get course data to display filtered by session name
 * @param int $from
 * @param int $number_of_items
 * @param int $column
 * @param string $direction
 * @return array
 */
function get_course_data_by_session($from, $number_of_items, $column, $direction)
{
    $course_table = Database::get_main_table(TABLE_MAIN_COURSE);
    $session_rel_course = Database::get_main_table(TABLE_MAIN_SESSION_COURSE);
    $session = Database::get_main_table(TABLE_MAIN_SESSION);
    $sql = "SELECT  c.code AS col0,\n                    c.title AS col1,\n                    c.code AS col2,\n                    c.course_language AS col3,\n                    c.category_code AS col4,\n                    c.subscribe AS col5,\n                    c.unsubscribe AS col6,\n                    c.code AS col7,\n                    c.visibility AS col8,\n                    c.directory as col9,\n                    c.visual_code\n            FROM {$course_table} c\n            INNER JOIN {$session_rel_course} r ON c.code = r.course_code\n            INNER JOIN {$session} s ON r.id_session = s.id\n            ";
    if (isset($_GET['session_id']) && !empty($_GET['session_id'])) {
        $sessionId = intval($_GET['session_id']);
        $sql .= " WHERE s.id = " . $sessionId;
    }
    $sql .= " ORDER BY col{$column} {$direction} ";
    $sql .= " LIMIT {$from},{$number_of_items}";
    $res = Database::query($sql);
    $courses = array();
    while ($course = Database::fetch_array($res)) {
        // Place colour icons in front of courses.
        $show_visual_code = $course['visual_code'] != $course[2] ? Display::label($course['visual_code'], 'info') : null;
        $course[1] = get_course_visibility_icon($course[8]) . '<a href="' . api_get_path(WEB_COURSE_PATH) . $course[9] . '/index.php">' . $course[1] . '</a> ' . $show_visual_code;
        $course[5] = $course[5] == SUBSCRIBE_ALLOWED ? get_lang('Yes') : get_lang('No');
        $course[6] = $course[6] == UNSUBSCRIBE_ALLOWED ? get_lang('Yes') : get_lang('No');
        $course_rem = array($course[0], $course[1], $course[2], $course[3], $course[4], $course[5], $course[6], $course[7]);
        $courses[] = $course_rem;
    }
    return $courses;
}