mirror of
https://github.com/moodle/moodle.git
synced 2025-04-21 16:32:18 +02:00
MDL-59624 mod_data: Return maxcount in WS mod_data_search_entries
This commit is contained in:
parent
16a68a2f76
commit
be4bdab78a
@ -807,7 +807,9 @@ class mod_data_external extends external_api {
|
||||
'entries' => new external_multiple_structure(
|
||||
record_exporter::get_read_structure()
|
||||
),
|
||||
'totalcount' => new external_value(PARAM_INT, 'Total count of records.'),
|
||||
'totalcount' => new external_value(PARAM_INT, 'Total count of records returned by the search.'),
|
||||
'maxcount' => new external_value(PARAM_INT, 'Total count of records that the user could see in the database
|
||||
(if all the search criterias were removed).', VALUE_OPTIONAL),
|
||||
'listviewcontents' => new external_value(PARAM_RAW, 'The list view contents as is rendered in the site.',
|
||||
VALUE_OPTIONAL),
|
||||
'warnings' => new external_warnings()
|
||||
|
@ -672,6 +672,7 @@ class mod_data_external_testcase extends externallib_advanced_testcase {
|
||||
$result = external_api::clean_returnvalue(mod_data_external::search_entries_returns(), $result);
|
||||
$this->assertCount(2, $result['entries']);
|
||||
$this->assertEquals(2, $result['totalcount']);
|
||||
$this->assertEquals(2, $result['maxcount']);
|
||||
|
||||
// Now as the other student I should receive my not approved entry. Apply ordering here.
|
||||
$this->setUser($this->student2);
|
||||
@ -679,6 +680,7 @@ class mod_data_external_testcase extends externallib_advanced_testcase {
|
||||
$result = external_api::clean_returnvalue(mod_data_external::search_entries_returns(), $result);
|
||||
$this->assertCount(3, $result['entries']);
|
||||
$this->assertEquals(3, $result['totalcount']);
|
||||
$this->assertEquals(3, $result['maxcount']);
|
||||
// The not approved one should be the first.
|
||||
$this->assertEquals($entry13, $result['entries'][0]['id']);
|
||||
|
||||
@ -688,6 +690,7 @@ class mod_data_external_testcase extends externallib_advanced_testcase {
|
||||
$result = external_api::clean_returnvalue(mod_data_external::search_entries_returns(), $result);
|
||||
$this->assertCount(1, $result['entries']);
|
||||
$this->assertEquals(1, $result['totalcount']);
|
||||
$this->assertEquals(1, $result['maxcount']);
|
||||
$this->assertEquals($this->student3->id, $result['entries'][0]['userid']);
|
||||
|
||||
// Same normal text search as teacher.
|
||||
@ -696,6 +699,7 @@ class mod_data_external_testcase extends externallib_advanced_testcase {
|
||||
$result = external_api::clean_returnvalue(mod_data_external::search_entries_returns(), $result);
|
||||
$this->assertCount(4, $result['entries']); // I can see all groups and non approved.
|
||||
$this->assertEquals(4, $result['totalcount']);
|
||||
$this->assertEquals(4, $result['maxcount']);
|
||||
|
||||
// Pagination.
|
||||
$this->setUser($this->teacher);
|
||||
@ -703,6 +707,7 @@ class mod_data_external_testcase extends externallib_advanced_testcase {
|
||||
$result = external_api::clean_returnvalue(mod_data_external::search_entries_returns(), $result);
|
||||
$this->assertCount(2, $result['entries']); // Only 2 per page.
|
||||
$this->assertEquals(4, $result['totalcount']);
|
||||
$this->assertEquals(4, $result['maxcount']);
|
||||
|
||||
// Now advanced search or not dinamic fields (user firstname for example).
|
||||
$this->setUser($this->student1);
|
||||
@ -713,6 +718,7 @@ class mod_data_external_testcase extends externallib_advanced_testcase {
|
||||
$result = external_api::clean_returnvalue(mod_data_external::search_entries_returns(), $result);
|
||||
$this->assertCount(1, $result['entries']);
|
||||
$this->assertEquals(1, $result['totalcount']);
|
||||
$this->assertEquals(2, $result['maxcount']);
|
||||
$this->assertEquals($this->student2->id, $result['entries'][0]['userid']); // I only found mine!
|
||||
|
||||
// Advanced search for fields.
|
||||
@ -724,6 +730,7 @@ class mod_data_external_testcase extends externallib_advanced_testcase {
|
||||
$result = external_api::clean_returnvalue(mod_data_external::search_entries_returns(), $result);
|
||||
$this->assertCount(2, $result['entries']); // Found two entries matching this.
|
||||
$this->assertEquals(2, $result['totalcount']);
|
||||
$this->assertEquals(2, $result['maxcount']);
|
||||
|
||||
// Combined search.
|
||||
$field2 = $DB->get_record('data_fields', array('type' => 'number'));
|
||||
@ -736,6 +743,7 @@ class mod_data_external_testcase extends externallib_advanced_testcase {
|
||||
$result = external_api::clean_returnvalue(mod_data_external::search_entries_returns(), $result);
|
||||
$this->assertCount(1, $result['entries']); // Only one matching everything.
|
||||
$this->assertEquals(1, $result['totalcount']);
|
||||
$this->assertEquals(2, $result['maxcount']);
|
||||
|
||||
// Combined search (no results).
|
||||
$field2 = $DB->get_record('data_fields', array('type' => 'number'));
|
||||
@ -747,6 +755,7 @@ class mod_data_external_testcase extends externallib_advanced_testcase {
|
||||
$result = external_api::clean_returnvalue(mod_data_external::search_entries_returns(), $result);
|
||||
$this->assertCount(0, $result['entries']); // Only one matching everything.
|
||||
$this->assertEquals(0, $result['totalcount']);
|
||||
$this->assertEquals(2, $result['maxcount']);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1,6 +1,10 @@
|
||||
This files describes API changes in /mod/data - plugins,
|
||||
information provided here is intended especially for developers.
|
||||
|
||||
=== 3.4 ===
|
||||
* External function mod_data_external::search_entries() now returns the maxcount field: Total count of records that the user could
|
||||
see in the database (if all the search criterias were removed).
|
||||
|
||||
=== 3.3.2 ===
|
||||
* data_refresh_events() Now takes two additional parameters to refine the update to a specific instance. This function
|
||||
now optionally takes the module instance object or ID, and the course module object or ID. Please try to send the full
|
||||
|
Loading…
x
Reference in New Issue
Block a user