|
|
|
@ -409,15 +409,22 @@ class CoursesAndSessionsCatalog |
|
|
|
|
* The search is done on the code, title and tutor field of the course table. |
|
|
|
|
* |
|
|
|
|
* @param string $categoryCode |
|
|
|
|
* @param string $keyword The string that the user submitted |
|
|
|
|
* @param string $keyword The string that the user submitted |
|
|
|
|
* @param array $limit |
|
|
|
|
* @param bool $justVisible search only on visible courses in the catalogue |
|
|
|
|
* @param bool $justVisible search only on visible courses in the catalogue |
|
|
|
|
* @param array $conditions |
|
|
|
|
* @param string $courseLanguageFilter search only courses in the indicated language |
|
|
|
|
* |
|
|
|
|
* @return array an array containing a list of all the courses matching the the search term |
|
|
|
|
*/ |
|
|
|
|
public static function searchCourses($categoryCode, $keyword, $limit, $justVisible = false, $conditions = []) |
|
|
|
|
{ |
|
|
|
|
public static function searchCourses( |
|
|
|
|
$categoryCode, |
|
|
|
|
$keyword, |
|
|
|
|
$limit, |
|
|
|
|
$justVisible = false, |
|
|
|
|
$conditions = [], |
|
|
|
|
$courseLanguageFilter = null |
|
|
|
|
) { |
|
|
|
|
$courseTable = Database::get_main_table(TABLE_MAIN_COURSE); |
|
|
|
|
$limitFilter = self::getLimitFilterFromArray($limit); |
|
|
|
|
$avoidCoursesCondition = self::getAvoidCourseCondition(); |
|
|
|
@ -427,6 +434,7 @@ class CoursesAndSessionsCatalog |
|
|
|
|
$categoryCode = Database::escape_string($categoryCode); |
|
|
|
|
|
|
|
|
|
$sqlInjectJoins = ''; |
|
|
|
|
$courseLanguageWhere = ''; |
|
|
|
|
$where = 'AND 1 = 1 '; |
|
|
|
|
$sqlInjectWhere = ''; |
|
|
|
|
$injectExtraFields = '1'; |
|
|
|
@ -438,6 +446,12 @@ class CoursesAndSessionsCatalog |
|
|
|
|
$injectExtraFields = rtrim($injectExtraFields, ', '); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// If have courseLanguageFilter, search for it |
|
|
|
|
if (!empty($courseLanguageFilter)) { |
|
|
|
|
$courseLanguageFilter = Database::escape_string($courseLanguageFilter); |
|
|
|
|
$courseLanguageWhere = "AND course.course_language = '$courseLanguageFilter'"; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$categoryFilter = ''; |
|
|
|
|
if ($categoryCode === 'ALL' || empty($categoryCode)) { |
|
|
|
|
// Nothing to do |
|
|
|
@ -459,6 +473,7 @@ class CoursesAndSessionsCatalog |
|
|
|
|
$where |
|
|
|
|
$categoryFilter |
|
|
|
|
$sqlInjectWhere |
|
|
|
|
$courseLanguageWhere |
|
|
|
|
$avoidCoursesCondition |
|
|
|
|
$visibilityCondition |
|
|
|
|
ORDER BY title, visual_code ASC |
|
|
|
@ -527,6 +542,9 @@ class CoursesAndSessionsCatalog |
|
|
|
|
$courseInfo['registration_code'] = !empty($courseInfo['registration_code']); |
|
|
|
|
$courseInfo['count_users'] = $countUsers; |
|
|
|
|
$courseInfo['count_connections'] = $connectionsLastMonth; |
|
|
|
|
$courseInfo['course_language'] = api_get_language_info( |
|
|
|
|
api_get_language_id($courseInfo['course_language']) |
|
|
|
|
)['original_name']; |
|
|
|
|
|
|
|
|
|
$courses[] = $courseInfo; |
|
|
|
|
} |
|
|
|
@ -622,12 +640,13 @@ class CoursesAndSessionsCatalog |
|
|
|
|
/** |
|
|
|
|
* Wrapper for self::searchCourses which locally sorts the results according to $sortKey. |
|
|
|
|
* |
|
|
|
|
* @param string $categoryCode can be 'ALL', 'NONE' or any existing course category code |
|
|
|
|
* @param string $keyword search pattern to be found in course code, title or tutor_name |
|
|
|
|
* @param array $limit associative array generated by \CoursesAndSessionsCatalog::getLimitArray() |
|
|
|
|
* @param bool $justVisible search only on visible courses in the catalogue |
|
|
|
|
* @param array $conditions associative array generated using \ExtraField::parseConditions |
|
|
|
|
* @param string[] $sortKeys a subset of the keys of the array returned by courseSortOptions() |
|
|
|
|
* @param string $categoryCode can be 'ALL', 'NONE' or any existing course category code |
|
|
|
|
* @param string $keyword search pattern to be found in course code, title or tutor_name |
|
|
|
|
* @param array $limit associative array generated by \CoursesAndSessionsCatalog::getLimitArray() |
|
|
|
|
* @param bool $justVisible search only on visible courses in the catalogue |
|
|
|
|
* @param array $conditions associative array generated using \ExtraField::parseConditions |
|
|
|
|
* @param string[] $sortKeys a subset of the keys of the array returned by courseSortOptions() |
|
|
|
|
* @param string $courseLanguageFilter search only courses in the indicated language |
|
|
|
|
* |
|
|
|
|
* @return array list of all the courses matching the the search term |
|
|
|
|
*/ |
|
|
|
@ -637,10 +656,11 @@ class CoursesAndSessionsCatalog |
|
|
|
|
$limit, |
|
|
|
|
$justVisible = false, |
|
|
|
|
$conditions = [], |
|
|
|
|
$sortKeys = [] |
|
|
|
|
$sortKeys = [], |
|
|
|
|
$courseLanguageFilter = null |
|
|
|
|
) { |
|
|
|
|
// Get ALL matching courses (no limit) |
|
|
|
|
$courses = self::searchCourses($categoryCode, $keyword, null, $justVisible, $conditions); |
|
|
|
|
$courses = self::searchCourses($categoryCode, $keyword, null, $justVisible, $conditions, $courseLanguageFilter); |
|
|
|
|
// Do we have extra fields to sort on ? |
|
|
|
|
$extraFieldsToSortOn = []; |
|
|
|
|
foreach (self::getCourseExtraFieldsAvailableForSorting() as $extraField) { |
|
|
|
@ -1987,10 +2007,21 @@ class CoursesAndSessionsCatalog |
|
|
|
|
['multiple' => true] |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
if (api_get_setting('show_different_course_language') === 'true') { |
|
|
|
|
$form->addSelectLanguage( |
|
|
|
|
'course_language', |
|
|
|
|
get_lang('Language'), |
|
|
|
|
['' => '--'], |
|
|
|
|
['style' => 'width:150px'] |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$sortKeys = isset($_REQUEST['sortKeys']) ? Security::remove_XSS($_REQUEST['sortKeys']) : ''; |
|
|
|
|
$languageSelect = isset($_REQUEST['course_language']) ? Security::remove_XSS($_REQUEST['course_language']) : ''; |
|
|
|
|
$defaults['sortKeys'] = $sortKeys; |
|
|
|
|
$defaults['search_term'] = $searchTerm; |
|
|
|
|
$defaults['category_code'] = $categoryCode; |
|
|
|
|
$defaults['course_language'] = $languageSelect; |
|
|
|
|
|
|
|
|
|
$conditions = []; |
|
|
|
|
$fields = []; |
|
|
|
@ -2010,6 +2041,7 @@ class CoursesAndSessionsCatalog |
|
|
|
|
$defaults['sortKeys'] = $sortKeys; |
|
|
|
|
$defaults['search_term'] = $searchTerm; |
|
|
|
|
$defaults['category_code'] = $categoryCode; |
|
|
|
|
$defaults['course_language'] = $languageSelect; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$courses = CoursesAndSessionsCatalog::searchAndSortCourses( |
|
|
|
@ -2018,14 +2050,16 @@ class CoursesAndSessionsCatalog |
|
|
|
|
self::getLimitArray(), |
|
|
|
|
true, |
|
|
|
|
$conditions, |
|
|
|
|
$sortKeySelect->getValue() |
|
|
|
|
$sortKeySelect->getValue(), |
|
|
|
|
$languageSelect |
|
|
|
|
); |
|
|
|
|
$countCoursesInCategory = CourseCategory::countCoursesInCategory( |
|
|
|
|
$categoryCode, |
|
|
|
|
$searchTerm, |
|
|
|
|
true, |
|
|
|
|
true, |
|
|
|
|
$conditions |
|
|
|
|
$conditions, |
|
|
|
|
$languageSelect |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|