Add parameter to CourseManager::getCourseVisibilitySQLCondition() to avoid showing hidden and closed courses in catalogues - refs GH#1683 fixes #1683

remotes/angel/1.11.x
Yannick Warnier 8 years ago
parent 0e995fd8ba
commit 313f2d81fb
  1. 2
      main/inc/lib/auth.lib.php
  2. 12
      main/inc/lib/course.lib.php
  3. 4
      main/inc/lib/course_category.lib.php

@ -434,7 +434,7 @@ class Auth
$without_special_courses = ' AND course.code NOT IN (' . implode(',', $special_course_list) . ')';
}
$visibilityCondition = $justVisible ? CourseManager::getCourseVisibilitySQLCondition('course') : '';
$visibilityCondition = $justVisible ? CourseManager::getCourseVisibilitySQLCondition('course', true) : '';
$search_term_safe = Database::escape_string($search_term);
$sql_find = "SELECT * FROM $courseTable

@ -4913,14 +4913,18 @@ class CourseManager
/**
* Returns the SQL conditions to filter course only visible by the user in the catalogue
*
* @param $courseTableAlias Alias of the course table
* @param string $courseTableAlias Alias of the course table
* @param bool $hideClosed Whether to hide closed and hidden courses
* @return string SQL conditions
*/
public static function getCourseVisibilitySQLCondition($courseTableAlias) {
public static function getCourseVisibilitySQLCondition($courseTableAlias, $hideClosed = false) {
$visibilityCondition = '';
$hidePrivate = api_get_setting('course_catalog_hide_private');
if ($hidePrivate === 'true') {
$visibilityCondition = ' AND '.$courseTableAlias.'.visibility <> 1';
$visibilityCondition .= ' AND '.$courseTableAlias.'.visibility <> '.COURSE_VISIBILITY_REGISTERED;
}
if ($hideClosed) {
$visibilityCondition .= ' AND ' . $courseTableAlias . '.visibility NOT IN (' . COURSE_VISIBILITY_CLOSED .','. COURSE_VISIBILITY_HIDDEN .')';
}
// Check if course have users allowed to see it in the catalogue, then show only if current user is allowed to see it
@ -4960,7 +4964,7 @@ class CourseManager
$withoutSpecialCourses = ' AND c.id NOT IN ("' . implode('","', $specialCourseList) . '")';
}
$visibilityCondition = self::getCourseVisibilitySQLCondition('c');
$visibilityCondition = self::getCourseVisibilitySQLCondition('c', true);
if (!empty($accessUrlId) && $accessUrlId == intval($accessUrlId)) {
$sql = "SELECT count(c.id) FROM $tableCourse c, $tableCourseRelAccessUrl u

@ -598,7 +598,7 @@ class CourseCategory
$without_special_courses = ' AND course.id NOT IN ("'.implode('","', $specialCourseList).'")';
}
$visibilityCondition = CourseManager::getCourseVisibilitySQLCondition('course');
$visibilityCondition = CourseManager::getCourseVisibilitySQLCondition('course', true);
$categoryFilter = '';
if ($categoryCode === 'ALL') {
@ -663,7 +663,7 @@ class CourseCategory
if (!empty($specialCourseList)) {
$without_special_courses = ' AND course.id NOT IN ("'.implode('","', $specialCourseList).'")';
}
$visibilityCondition = CourseManager::getCourseVisibilitySQLCondition("course");
$visibilityCondition = CourseManager::getCourseVisibilitySQLCondition('course', true);
if (!empty($random_value)) {
$random_value = intval($random_value);

Loading…
Cancel
Save