diff --git a/main/inc/ajax/course.ajax.php b/main/inc/ajax/course.ajax.php index 1c5eb6b2f2..d24148c7d4 100644 --- a/main/inc/ajax/course.ajax.php +++ b/main/inc/ajax/course.ajax.php @@ -60,7 +60,9 @@ switch ($action) { 1, //$orderby = 1, 'ASC', -1, - $_REQUEST['q'] + $_REQUEST['q'], + null, + true ); $results = array(); diff --git a/main/inc/lib/course.lib.php b/main/inc/lib/course.lib.php index fb904731c7..6248590e14 100644 --- a/main/inc/lib/course.lib.php +++ b/main/inc/lib/course.lib.php @@ -142,12 +142,14 @@ class CourseManager /** * Returns a list of courses. Should work with quickform syntax - * @param integer Offset (from the 7th = '6'). Optional. - * @param integer Number of results we want. Optional. - * @param string The column we want to order it by. Optional, defaults to first column. - * @param string The direction of the order (ASC or DESC). Optional, defaults to ASC. - * @param string The visibility of the course, or all by default. - * @param string If defined, only return results for which the course *title* begins with this string + * @param integer $from Offset (from the 7th = '6'). Optional. + * @param integer $howmany Number of results we want. Optional. + * @param string $orderby The column we want to order it by. Optional, defaults to first column. + * @param string $orderdirection The direction of the order (ASC or DESC). Optional, defaults to ASC. + * @param string $visibility The visibility of the course, or all by default. + * @param string $startwith If defined, only return results for which the course *title* begins with this string + * @param string $urlId The Access URL ID, if using multiple URLs + * @param string $alsoSearchCode An extension option to indicate that we also want to search for course codes (not *only* titles) * @return array */ public static function get_courses_list( @@ -157,7 +159,8 @@ class CourseManager $orderdirection = 'ASC', $visibility = -1, $startwith = '', - $urlId = null + $urlId = null, + $alsoSearchCode = false ) { $sql = "SELECT course.* FROM ".Database::get_main_table(TABLE_MAIN_COURSE)." course "; @@ -168,7 +171,11 @@ class CourseManager } if (!empty($startwith)) { - $sql .= "WHERE title LIKE '".Database::escape_string($startwith)."%' "; + $sql .= "WHERE (title LIKE '".Database::escape_string($startwith)."%' "; + if ($alsoSearchCode) { + $sql .= "OR code LIKE '".Database::escape_string($startwith)."%' "; + } + $sql .= ') '; if ($visibility !== -1 && $visibility == strval(intval($visibility))) { $sql .= " AND visibility = $visibility "; }