Skip to content

Commit

Permalink
MDL-72207 assign: Support all participants in get_submission_status WS
Browse files Browse the repository at this point in the history
  • Loading branch information
jleyva committed Aug 19, 2021
1 parent 036800d commit 5784c39
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
7 changes: 4 additions & 3 deletions mod/assign/externallib.php
Expand Up @@ -2316,7 +2316,7 @@ public static function get_submission_status_parameters() {
'assignid' => new external_value(PARAM_INT, 'assignment instance id'),
'userid' => new external_value(PARAM_INT, 'user id (empty for current user)', VALUE_DEFAULT, 0),
'groupid' => new external_value(PARAM_INT, 'filter by users in group (used for generating the grading summary).
Empty or 0 for all groups information.', VALUE_DEFAULT, 0),
0 for all groups information, any other empty value will calculate currrent group.', VALUE_DEFAULT, 0),
)
);
}
Expand Down Expand Up @@ -2368,8 +2368,9 @@ public static function get_submission_status($assignid, $userid = 0, $groupid =
throw new moodle_exception('notingroup');
}
} else {
// A null gorups means that following functions will calculate the current group.
$groupid = null;
// A null group means that following functions will calculate the current group.
// A groupid set to 0 means all groups.
$groupid = ($params['groupid'] == 0) ? 0 : null;
}
if ($assign->can_view_grades($groupid)) {
$gradingsummary = $assign->get_assign_grading_summary_renderable($groupid);
Expand Down
16 changes: 14 additions & 2 deletions mod/assign/tests/externallib_test.php
Expand Up @@ -2082,6 +2082,7 @@ public function test_get_submission_status_in_submission_status() {
* Test get_submission_status using the teacher role.
*/
public function test_get_submission_status_in_submission_status_for_teacher() {
global $DB;
$this->resetAfterTest(true);

list($assign, $instance, $student1, $student2, $teacher, $g1, $g2) = $this->create_submission_for_testing_status(true);
Expand Down Expand Up @@ -2115,11 +2116,22 @@ public function test_get_submission_status_in_submission_status_for_teacher() {
$this->assertEquals(0, $result['gradingsummary']['submissionssubmittedcount']); // G2 students didn't submit yet.
$this->assertEquals(0, $result['gradingsummary']['submissionsneedgradingcount']); // G2 students didn't submit yet.

// Should return also 1 participant if we allow the function to auto-select the group.
// Should not return information for all users (missing access to all groups capability for non-editing teacher).
$result = mod_assign_external::get_submission_status($assign->get_instance()->id);
$result = external_api::clean_returnvalue(mod_assign_external::get_submission_status_returns(), $result);
$this->assertCount(0, $result['warnings']);
$this->assertEquals(1, $result['gradingsummary']['participantcount']);
$this->assertFalse(isset($result['gradingsummary']));

// Should return all participants if we grant accessallgroups capability to the normal teacher role.
$context = context_course::instance($assign->get_instance()->course);
$teacherrole = $DB->get_record('role', array('shortname' => 'teacher'));
assign_capability('moodle/site:accessallgroups', CAP_ALLOW, $teacherrole->id, $context->id, true);
accesslib_clear_all_caches_for_unit_testing();

$result = mod_assign_external::get_submission_status($assign->get_instance()->id);
$result = external_api::clean_returnvalue(mod_assign_external::get_submission_status_returns(), $result);
$this->assertCount(0, $result['warnings']);
$this->assertEquals(2, $result['gradingsummary']['participantcount']);
$this->assertEquals(0, $result['gradingsummary']['submissiondraftscount']);
$this->assertEquals(1, $result['gradingsummary']['submissionssubmittedcount']); // One student from G1 submitted.
$this->assertEquals(1, $result['gradingsummary']['submissionsneedgradingcount']); // One student from G1 submitted.
Expand Down

0 comments on commit 5784c39

Please sign in to comment.