Merge branch 'MDL-59627-master' of git://github.com/jleyva/moodle

This commit is contained in:
Dan Poltawski 2017-07-31 11:44:56 +01:00
commit 396b97b2fb
2 changed files with 16 additions and 2 deletions

View File

@ -1006,15 +1006,17 @@ function data_search_entries($data, $cm, $context, $mode, $currentgroup, $search
$recordids = data_get_all_recordids($data->id, $initialselect, $initialparams);
$newrecordids = data_get_advance_search_ids($recordids, $searcharray, $data->id);
$totalcount = count($newrecordids);
$selectdata = $where . $groupselect . $approveselect;
if (!empty($advanced)) {
$advancedsearchsql = data_get_advanced_search_sql($sort, $data, $newrecordids, $selectdata, $sortorder);
$sqlselect = $advancedsearchsql['sql'];
$allparams = array_merge($allparams, $advancedsearchsql['params']);
$totalcount = count($newrecordids);
} else {
$sqlselect = "SELECT $what $fromsql $sortorder";
$sqlcountselect = "SELECT $count $fromsql $sortorder";
$totalcount = $DB->count_records_sql($sqlcountselect, $allparams);
}
// Work out the paging numbers and counts.

View File

@ -666,8 +666,20 @@ class mod_data_external_testcase extends externallib_advanced_testcase {
global $DB;
list($entry11, $entry12, $entry13, $entry21) = self::populate_database_with_entries();
// First do a normal text search as student 1. I should see my two group entries.
$this->setUser($this->student1);
// Empty search, it should return all the visible entries.
$result = mod_data_external::search_entries($this->database->id, 0, false);
$result = external_api::clean_returnvalue(mod_data_external::search_entries_returns(), $result);
$this->assertCount(2, $result['entries']);
$this->assertEquals(2, $result['totalcount']);
// Search for something that does not exists.
$result = mod_data_external::search_entries($this->database->id, 0, false, 'abc');
$result = external_api::clean_returnvalue(mod_data_external::search_entries_returns(), $result);
$this->assertCount(0, $result['entries']);
$this->assertEquals(0, $result['totalcount']);
// Search by text matching all the entries.
$result = mod_data_external::search_entries($this->database->id, 0, false, 'text');
$result = external_api::clean_returnvalue(mod_data_external::search_entries_returns(), $result);
$this->assertCount(2, $result['entries']);