Add code to course search - refs BT#7142

1.9.x
Yannick Warnier 12 years ago
parent 7a20314f99
commit b159706e39
  1. 4
      main/inc/ajax/course.ajax.php
  2. 23
      main/inc/lib/course.lib.php

@ -60,7 +60,9 @@ switch ($action) {
1, //$orderby = 1,
'ASC',
-1,
$_REQUEST['q']
$_REQUEST['q'],
null,
true
);
$results = array();

@ -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 ";
}

Loading…
Cancel
Save