|
@@ -2685,41 +2685,50 @@ class CourseManager
|
|
|
* @return array List of codes and db name
|
|
|
* @author isaac flores paz
|
|
|
*/
|
|
|
- public static function get_courses_list_by_user_id($user_id, $include_sessions = false, $adminGetsAllCourses = false)
|
|
|
- {
|
|
|
+ public static function get_courses_list_by_user_id(
|
|
|
+ $user_id,
|
|
|
+ $include_sessions = false,
|
|
|
+ $adminGetsAllCourses = false
|
|
|
+ ) {
|
|
|
$user_id = intval($user_id);
|
|
|
+ $urlId = api_get_current_access_url_id();
|
|
|
$course_list = array();
|
|
|
$codes = array();
|
|
|
+
|
|
|
$tbl_course = Database::get_main_table(TABLE_MAIN_COURSE);
|
|
|
$tbl_course_user = Database::get_main_table(TABLE_MAIN_COURSE_USER);
|
|
|
$tbl_user_course_category = Database::get_main_table(TABLE_USER_COURSE_CATEGORY);
|
|
|
+ $tableCourseUrl = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE);
|
|
|
$special_course_list = self::get_special_course_list();
|
|
|
-
|
|
|
if ($adminGetsAllCourses && UserManager::is_admin($user_id)) {
|
|
|
// get the whole courses list
|
|
|
$sql = "SELECT DISTINCT(course.code), course.id as real_id
|
|
|
- FROM $tbl_course course";
|
|
|
+ FROM $tbl_course course
|
|
|
+ INNER JOIN $tableCourseUrl url
|
|
|
+ ON (course.id = url.c_id)
|
|
|
+ WHERE url.access_url_id = $urlId
|
|
|
+ ";
|
|
|
} else {
|
|
|
$with_special_courses = $without_special_courses = '';
|
|
|
if (!empty($special_course_list)) {
|
|
|
$sc_string = '"' . implode('","', $special_course_list) . '"';
|
|
|
- $with_special_courses = ' course.id IN (' . $sc_string . ')';
|
|
|
+ $with_special_courses = ' AND course.id IN (' . $sc_string . ')';
|
|
|
$without_special_courses = ' AND course.id NOT IN (' . $sc_string . ')';
|
|
|
}
|
|
|
|
|
|
if (!empty($with_special_courses)) {
|
|
|
$sql = "SELECT DISTINCT(course.code), course.id as real_id
|
|
|
- FROM $tbl_course_user course_rel_user
|
|
|
- LEFT JOIN $tbl_course course
|
|
|
+ FROM $tbl_course_user course_rel_user
|
|
|
+ LEFT JOIN $tbl_course course
|
|
|
ON course.id = course_rel_user.c_id
|
|
|
LEFT JOIN $tbl_user_course_category user_course_category
|
|
|
ON course_rel_user.user_course_cat = user_course_category.id
|
|
|
- WHERE $with_special_courses
|
|
|
+ INNER JOIN $tableCourseUrl url
|
|
|
+ ON (course.id = url.c_id)
|
|
|
+ WHERE url.access_url_id = $urlId $with_special_courses
|
|
|
GROUP BY course.code
|
|
|
ORDER BY user_course_category.sort, course.title, course_rel_user.sort ASC
|
|
|
-
|
|
|
- ";
|
|
|
- //
|
|
|
+ ";
|
|
|
$rs_special_course = Database::query($sql);
|
|
|
if (Database::num_rows($rs_special_course) > 0) {
|
|
|
while ($result_row = Database::fetch_array($rs_special_course)) {
|
|
@@ -2734,8 +2743,14 @@ class CourseManager
|
|
|
// entries when a course is assigned to a HRD (DRH) as watcher
|
|
|
$sql = "SELECT DISTINCT(course.code), course.id as real_id
|
|
|
FROM $tbl_course course
|
|
|
- INNER JOIN $tbl_course_user cru ON course.id = cru.c_id
|
|
|
- WHERE cru.user_id='$user_id' $without_special_courses";
|
|
|
+ INNER JOIN $tbl_course_user cru
|
|
|
+ ON (course.id = cru.c_id)
|
|
|
+ INNER JOIN $tableCourseUrl url
|
|
|
+ ON (course.id = url.c_id)
|
|
|
+ WHERE
|
|
|
+ url.access_url_id = $urlId AND
|
|
|
+ cru.user_id = '$user_id'
|
|
|
+ $without_special_courses";
|
|
|
}
|
|
|
$result = Database::query($sql);
|
|
|
|
|
@@ -2749,7 +2764,7 @@ class CourseManager
|
|
|
if ($include_sessions === true) {
|
|
|
$sql = "SELECT DISTINCT(c.code), c.id as real_id
|
|
|
FROM " . Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER) . " s,
|
|
|
- " . Database::get_main_table(TABLE_MAIN_COURSE) . " c
|
|
|
+ $tbl_course c
|
|
|
WHERE user_id = $user_id AND s.c_id = c.id";
|
|
|
$r = Database::query($sql);
|
|
|
while ($row = Database::fetch_array($r, 'ASSOC')) {
|