From deeb1db2203dfb65b394b2d69a0bcdaea4dc8779 Mon Sep 17 00:00:00 2001 From: Julio Montoya Date: Fri, 19 Feb 2021 14:55:09 +0100 Subject: [PATCH] Course category: Add $checkHidePrivate parameter BT#18434 Allow admin to see the count of private courses --- main/auth/courses.php | 1 + main/inc/lib/course_category.lib.php | 22 +++++++++++++++------- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/main/auth/courses.php b/main/auth/courses.php index 01f1fcda44..b76ed5abc1 100755 --- a/main/auth/courses.php +++ b/main/auth/courses.php @@ -284,6 +284,7 @@ switch ($action) { $categoryCode, $searchTerm, true, + true, $conditions ); } diff --git a/main/inc/lib/course_category.lib.php b/main/inc/lib/course_category.lib.php index ac9aac7efb..572ecb17bd 100755 --- a/main/inc/lib/course_category.lib.php +++ b/main/inc/lib/course_category.lib.php @@ -520,7 +520,7 @@ class CourseCategory $url ); - $countCourses = self::countCoursesInCategory($category['code'], null, false); + $countCourses = self::countCoursesInCategory($category['code'], null, false, false); $content = [ $title, @@ -596,8 +596,9 @@ class CourseCategory /** * @param string $category_code * @param string $keyword - * @paran bool $avoidCourses - * @paran array $conditions + * @param bool $avoidCourses + * @param bool $checkHidePrivate + * @param array $conditions * * @return int */ @@ -605,12 +606,20 @@ class CourseCategory $category_code = '', $keyword = '', $avoidCourses = true, + $checkHidePrivate = true, $conditions = [] ) { - return self::getCoursesInCategory($category_code, $keyword, $avoidCourses, $conditions, true); + return self::getCoursesInCategory( + $category_code, + $keyword, + $avoidCourses, + $checkHidePrivate, + $conditions, + true + ); } - public static function getCoursesInCategory($category_code = '', $keyword = '', $avoidCourses = true, $conditions = [], $getCount = false) + public static function getCoursesInCategory($category_code = '', $keyword = '', $avoidCourses = true, $checkHidePrivate = true, $conditions = [], $getCount = false) { $tbl_course = Database::get_main_table(TABLE_MAIN_COURSE); $categoryCode = Database::escape_string($category_code); @@ -620,8 +629,7 @@ class CourseCategory if ($avoidCourses) { $avoidCoursesCondition = CoursesAndSessionsCatalog::getAvoidCourseCondition(); } - - $visibilityCondition = CourseManager::getCourseVisibilitySQLCondition('course', true); + $visibilityCondition = CourseManager::getCourseVisibilitySQLCondition('course', true, $checkHidePrivate); $sqlInjectJoins = ''; $where = ' AND 1 = 1 ';