Skip to content

Commit

Permalink
Courses: Fix special course showing only in the same URL see BT#18323
Browse files Browse the repository at this point in the history
  • Loading branch information
jmontoyaa committed Jan 28, 2021
1 parent 58837fc commit 820ceca
Showing 1 changed file with 10 additions and 13 deletions.
23 changes: 10 additions & 13 deletions main/inc/lib/course.lib.php
Expand Up @@ -2989,7 +2989,6 @@ public static function email_to_tutor($user_id, $courseId, $send_to_tutor_also =
*/
public static function get_special_course_list()
{
$courseTable = Database::get_main_table(TABLE_MAIN_COURSE);
$tbl_course_field = Database::get_main_table(TABLE_EXTRA_FIELD);
$tbl_course_field_value = Database::get_main_table(TABLE_EXTRA_FIELD_VALUES);
$tbl_url_course = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE);
Expand All @@ -3000,8 +2999,7 @@ public static function get_special_course_list()

// Get special course field
$sql = "SELECT id FROM $tbl_course_field
WHERE extra_field_type = $extraFieldType AND
variable = 'special_course'";
WHERE extra_field_type = $extraFieldType AND variable = 'special_course'";
$result = Database::query($sql);

if (Database::num_rows($result) > 0) {
Expand All @@ -3010,28 +3008,27 @@ public static function get_special_course_list()
// Note: The value is better indexed as string, so
// using '1' instead of integer is more efficient
$sql = "SELECT DISTINCT(item_id) as cid
FROM $tbl_course_field_value
WHERE field_id = ".$row['id']." AND value = '1'";
FROM $tbl_course_field_value
WHERE field_id = ".$row['id']." AND value = '1'";
$result = Database::query($sql);
while ($row = Database::fetch_assoc($result)) {
$courseList[] = $row['cid'];
}
if (count($courseList) < 1) {
return $courseList;
if (empty($courseList)) {
return [];
}
if (api_get_multiple_access_url()) {
//we filter the courses by the active URL
$coursesSelect = '';
if (count($courseList) == 1) {
if (count($courseList) === 1) {
$coursesSelect = $courseList[0];
} else {
$coursesSelect = implode(',', $courseList);
}
$access_url_id = api_get_current_access_url_id();
if ($access_url_id != -1) {
$urlId = api_get_current_access_url_id();
if ($urlId != -1) {
$courseList = [];
$sql = "SELECT c_id FROM $tbl_url_course
WHERE access_url_id = $access_url_id
AND c_id IN ($coursesSelect)";
WHERE access_url_id = $urlId AND c_id IN ($coursesSelect)";
$result = Database::query($sql);
while ($row = Database::fetch_assoc($result)) {
$courseList[] = $row['c_id'];
Expand Down

0 comments on commit 820ceca

Please sign in to comment.