Skip to content

Commit

Permalink
Merge branch 'MDL-59627-master' of git://github.com/jleyva/moodle
Browse files Browse the repository at this point in the history
  • Loading branch information
danpoltawski committed Jul 31, 2017
2 parents 6cc8b0a + 6cf2ab7 commit 396b97b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
4 changes: 3 additions & 1 deletion mod/data/locallib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
14 changes: 13 additions & 1 deletion mod/data/tests/externallib_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -666,8 +666,20 @@ public function test_search_entries() {
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']);
Expand Down

0 comments on commit 396b97b

Please sign in to comment.