mirror of
https://github.com/moodle/moodle.git
synced 2025-04-21 00:12:56 +02:00
Merge branch 'wip-MDL-38147-master' of git://github.com/marinaglancy/moodle
This commit is contained in:
commit
604a8ed4e5
@ -123,7 +123,7 @@ class coursecat implements renderable, cacheable_object, IteratorAggregate {
|
||||
if (array_key_exists($name, self::$coursecatfields)) {
|
||||
if ($this->$name === false) {
|
||||
// property was not retrieved from DB, retrieve all not retrieved fields
|
||||
$notretrievedfields = array_diff(self::$coursecatfields, array_filter(self::$coursecatfields));
|
||||
$notretrievedfields = array_diff_key(self::$coursecatfields, array_filter(self::$coursecatfields));
|
||||
$record = $DB->get_record('course_categories', array('id' => $this->id),
|
||||
join(',', array_keys($notretrievedfields)), MUST_EXIST);
|
||||
foreach ($record as $key => $value) {
|
||||
@ -737,7 +737,7 @@ class coursecat implements renderable, cacheable_object, IteratorAggregate {
|
||||
$fields[] = 'c.summary';
|
||||
$fields[] = 'c.summaryformat';
|
||||
} else {
|
||||
$fields[] = $DB->sql_length('c.summary'). ' hassummary';
|
||||
$fields[] = $DB->sql_substr('c.summary', 1, 1). ' hassummary';
|
||||
}
|
||||
$sql = "SELECT ". join(',', $fields). ", $ctxselect
|
||||
FROM {course} c
|
||||
@ -749,6 +749,9 @@ class coursecat implements renderable, cacheable_object, IteratorAggregate {
|
||||
if ($checkvisibility) {
|
||||
// Loop through all records and make sure we only return the courses accessible by user.
|
||||
foreach ($list as $course) {
|
||||
if (isset($list[$course->id]->hassummary)) {
|
||||
$list[$course->id]->hassummary = strlen($list[$course->id]->hassummary) > 0;
|
||||
}
|
||||
if (empty($course->visible)) {
|
||||
// load context only if we need to check capability
|
||||
context_helper::preload_from_record($course);
|
||||
|
@ -405,17 +405,25 @@ class coursecatlib_testcase extends advanced_testcase {
|
||||
// search courses
|
||||
|
||||
// search by text
|
||||
$res = coursecat::search_courses(array('search' => 'Test'));
|
||||
$this->assertEquals(array($c4->id, $c3->id, $c1->id, $c8->id, $c5->id), array_keys($res));
|
||||
$this->assertEquals(5, coursecat::search_courses_count(array('search' => 'Test')));
|
||||
|
||||
// search by text with specified offset and limit
|
||||
$options = array('sort' => array('fullname' => 1), 'offset' => 1, 'limit' => 2);
|
||||
$res = coursecat::search_courses(array('search' => 'Test'), $options);
|
||||
$this->assertEquals(array($c4->id, $c5->id), array_keys($res));
|
||||
$this->assertEquals(5, coursecat::search_courses_count(array('search' => 'Test'), $options));
|
||||
|
||||
// IMPORTANT: the tests below may fail on some databases
|
||||
// case-insensitive search
|
||||
$res = coursecat::search_courses(array('search' => 'test'));
|
||||
$this->assertEquals(array($c4->id, $c3->id, $c1->id, $c8->id, $c5->id), array_keys($res));
|
||||
$this->assertEquals(5, coursecat::search_courses_count(array('search' => 'test')));
|
||||
|
||||
// non-latin language search
|
||||
$res = coursecat::search_courses(array('search' => 'Математика'));
|
||||
$this->assertEquals(array($c3->id, $c6->id), array_keys($res));
|
||||
$this->assertEquals(2, coursecat::search_courses_count(array('search' => 'Математика'), array()));
|
||||
|
||||
$options = array('sort' => array('fullname' => 1), 'offset' => 1, 'limit' => 2);
|
||||
$res = coursecat::search_courses(array('search' => 'test'), $options);
|
||||
$this->assertEquals(array($c4->id, $c5->id), array_keys($res));
|
||||
$this->assertEquals(5, coursecat::search_courses_count(array('search' => 'test'), $options));
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user