mirror of
https://github.com/moodle/moodle.git
synced 2025-08-05 00:46:50 +02:00
MDL-57822 mod_feedback: New WS mod_feedback_get_non_respondents
This commit is contained in:
parent
52f57996f4
commit
bb66bc4a89
4 changed files with 165 additions and 1 deletions
|
@ -959,4 +959,101 @@ class mod_feedback_external extends external_api {
|
|||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Describes the parameters for get_non_respondents.
|
||||
*
|
||||
* @return external_function_parameters
|
||||
* @since Moodle 3.3
|
||||
*/
|
||||
public static function get_non_respondents_parameters() {
|
||||
return new external_function_parameters (
|
||||
array(
|
||||
'feedbackid' => new external_value(PARAM_INT, 'Feedback instance id'),
|
||||
'groupid' => new external_value(PARAM_INT, 'Group id, 0 means that the function will determine the user group.',
|
||||
VALUE_DEFAULT, 0),
|
||||
'sort' => new external_value(PARAM_ALPHA, 'Sort param, must be firstname, lastname or lastaccess (default).',
|
||||
VALUE_DEFAULT, 'lastaccess'),
|
||||
'page' => new external_value(PARAM_INT, 'The page of records to return.', VALUE_DEFAULT, 0),
|
||||
'perpage' => new external_value(PARAM_INT, 'The number of records to return per page.', VALUE_DEFAULT, 0),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves a list of students who didn't submit the feedback.
|
||||
*
|
||||
* @param int $feedbackid feedback instance id
|
||||
* @param int $groupid Group id, 0 means that the function will determine the user group'
|
||||
* @param str $sort sort param, must be firstname, lastname or lastaccess (default)
|
||||
* @param int $page the page of records to return
|
||||
* @param int $perpage the number of records to return per page
|
||||
* @return array of warnings and users ids
|
||||
* @since Moodle 3.3
|
||||
*/
|
||||
public static function get_non_respondents($feedbackid, $groupid = 0, $sort = 'lastaccess', $page = 0, $perpage = 0) {
|
||||
|
||||
$params = array('feedbackid' => $feedbackid, 'groupid' => $groupid, 'sort' => $sort, 'page' => $page, 'perpage' => $perpage);
|
||||
$params = self::validate_parameters(self::get_non_respondents_parameters(), $params);
|
||||
$warnings = $itemsdata = array();
|
||||
|
||||
list($feedback, $course, $cm, $context) = self::validate_feedback($params['feedbackid']);
|
||||
|
||||
// Check permissions.
|
||||
require_capability('mod/feedback:viewreports', $context);
|
||||
|
||||
if (!empty($params['groupid'])) {
|
||||
$groupid = $params['groupid'];
|
||||
// Determine is the group is visible to user.
|
||||
if (!groups_group_visible($groupid, $course, $cm)) {
|
||||
throw new moodle_exception('notingroup');
|
||||
}
|
||||
} else {
|
||||
// Check to see if groups are being used here.
|
||||
if ($groupmode = groups_get_activity_groupmode($cm)) {
|
||||
$groupid = groups_get_activity_group($cm);
|
||||
// Determine is the group is visible to user (this is particullary for the group 0 -> all groups).
|
||||
if (!groups_group_visible($groupid, $course, $cm)) {
|
||||
throw new moodle_exception('notingroup');
|
||||
}
|
||||
} else {
|
||||
$groupid = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if ($params['sort'] !== 'firstname' && $params['sort'] !== 'lastname' && $params['sort'] !== 'lastaccess') {
|
||||
throw new invalid_parameter_exception('Invalid sort param, must be firstname, lastname or lastaccess.');
|
||||
}
|
||||
$params['sort'] = 'u.' . $params['sort'];
|
||||
|
||||
// Check if we are page filtering.
|
||||
if ($params['page'] == 0 && $params['perpage'] == 0) {
|
||||
$params['page'] = false;
|
||||
$params['perpage'] = false;
|
||||
}
|
||||
$users = feedback_get_incomplete_users($cm, $groupid, $params['sort'], $params['page'], $params['perpage']);
|
||||
|
||||
$result = array(
|
||||
'users' => $users,
|
||||
'warnings' => $warnings
|
||||
);
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Describes the get_non_respondents return value.
|
||||
*
|
||||
* @return external_single_structure
|
||||
* @since Moodle 3.3
|
||||
*/
|
||||
public static function get_non_respondents_returns() {
|
||||
return new external_single_structure(
|
||||
array(
|
||||
'users' => new external_multiple_structure(
|
||||
new external_value(PARAM_INT, 'The user id')
|
||||
),
|
||||
'warnings' => new external_warnings(),
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -117,4 +117,12 @@ $functions = array(
|
|||
'capabilities' => 'mod/feedback:view',
|
||||
'services' => array(MOODLE_OFFICIAL_MOBILE_SERVICE)
|
||||
),
|
||||
'mod_feedback_get_non_respondents' => array(
|
||||
'classname' => 'mod_feedback_external',
|
||||
'methodname' => 'get_non_respondents',
|
||||
'description' => 'Retrieves a list of students who didn\'t submit the feedback.',
|
||||
'type' => 'read',
|
||||
'capabilities' => 'mod/feedback:viewreports',
|
||||
'services' => array(MOODLE_OFFICIAL_MOBILE_SERVICE)
|
||||
),
|
||||
);
|
||||
|
|
|
@ -664,4 +664,63 @@ class mod_feedback_external_testcase extends externallib_advanced_testcase {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test get_non_respondents (student trying to get this information).
|
||||
*/
|
||||
public function test_get_non_respondents_no_permissions() {
|
||||
$this->setUser($this->student);
|
||||
$this->setExpectedException('moodle_exception');
|
||||
mod_feedback_external::get_non_respondents($this->feedback->id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test get_non_respondents.
|
||||
*/
|
||||
public function test_get_non_respondents() {
|
||||
// Create another student.
|
||||
$anotherstudent = self::getDataGenerator()->create_user();
|
||||
$this->getDataGenerator()->enrol_user($anotherstudent->id, $this->course->id, $this->studentrole->id, 'manual');
|
||||
$this->setUser($anotherstudent);
|
||||
|
||||
// Test user with full capabilities.
|
||||
$this->setUser($this->student);
|
||||
|
||||
// Create a very simple feedback.
|
||||
$feedbackgenerator = $this->getDataGenerator()->get_plugin_generator('mod_feedback');
|
||||
$numericitem = $feedbackgenerator->create_item_numeric($this->feedback);
|
||||
|
||||
$pagedata = [
|
||||
['name' => $numericitem->typ .'_'. $numericitem->id, 'value' => 5],
|
||||
];
|
||||
|
||||
// Process the feedback, there is only one page so the feedback will be completed.
|
||||
$result = mod_feedback_external::process_page($this->feedback->id, 0, $pagedata);
|
||||
$result = external_api::clean_returnvalue(mod_feedback_external::process_page_returns(), $result);
|
||||
$this->assertTrue($result['completed']);
|
||||
|
||||
// Retrieve the non-respondent users.
|
||||
$this->setUser($this->teacher);
|
||||
$result = mod_feedback_external::get_non_respondents($this->feedback->id);
|
||||
$result = external_api::clean_returnvalue(mod_feedback_external::get_non_respondents_returns(), $result);
|
||||
$this->assertCount(0, $result['warnings']);
|
||||
$this->assertCount(1, $result['users']);
|
||||
$this->assertEquals($anotherstudent->id, $result['users'][0]);
|
||||
|
||||
// Create another student.
|
||||
$anotherstudent2 = self::getDataGenerator()->create_user();
|
||||
$this->getDataGenerator()->enrol_user($anotherstudent2->id, $this->course->id, $this->studentrole->id, 'manual');
|
||||
$this->setUser($anotherstudent2);
|
||||
$this->setUser($this->teacher);
|
||||
$result = mod_feedback_external::get_non_respondents($this->feedback->id);
|
||||
$result = external_api::clean_returnvalue(mod_feedback_external::get_non_respondents_returns(), $result);
|
||||
$this->assertCount(0, $result['warnings']);
|
||||
$this->assertCount(2, $result['users']);
|
||||
|
||||
// Test pagination.
|
||||
$result = mod_feedback_external::get_non_respondents($this->feedback->id, 0, 'lastaccess', 0, 1);
|
||||
$result = external_api::clean_returnvalue(mod_feedback_external::get_non_respondents_returns(), $result);
|
||||
$this->assertCount(0, $result['warnings']);
|
||||
$this->assertCount(1, $result['users']);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
$plugin->version = 2016120511; // The current module version (Date: YYYYMMDDXX)
|
||||
$plugin->version = 2016120512; // The current module version (Date: YYYYMMDDXX)
|
||||
$plugin->requires = 2016112900; // Requires this Moodle version
|
||||
$plugin->component = 'mod_feedback'; // Full name of the plugin (used for diagnostics)
|
||||
$plugin->cron = 0;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue