Skip to content

Commit

Permalink
MDL-50524 mod_assign: preventsubmissionnotingroup for multiple groups
Browse files Browse the repository at this point in the history
When preventsubmissionnotingroup and a user is in multiple groups, display
relevant error messages to the user and teacher
  • Loading branch information
andrewhancox committed Sep 3, 2015
1 parent e28004e commit ee5d4ee
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 10 deletions.
3 changes: 2 additions & 1 deletion mod/assign/lang/en/assign.php
Expand Up @@ -278,6 +278,7 @@
$string['modulename_link'] = 'mod/assignment/view';
$string['modulenameplural'] = 'Assignments';
$string['moreusers'] = '{$a} more...';
$string['multipleteams'] = 'You\'re a member of multiple groups, please contact your teacher.';
$string['mysubmission'] = 'My submission: ';
$string['newsubmissions'] = 'Assignments submitted';
$string['noattempt'] = 'No attempt';
Expand Down Expand Up @@ -434,7 +435,7 @@
$string['textinstructions'] = 'Assignment instructions';
$string['timemodified'] = 'Last modified';
$string['timeremaining'] = 'Time remaining';
$string['ungroupedusers'] = 'The setting \'Require group to make submission\' is turned on and some users are not allocated to groups, this will prevent them from submitting assignments.';
$string['ungroupedusers'] = 'The setting \'Require group to make submission\' is turned on and some users are not allocated to groups or are allocated to multiple groups, this will prevent them from submitting assignments.';
$string['unlocksubmissionforstudent'] = 'Allow submissions for student: (id={$a->id}, fullname={$a->fullname}).';
$string['unlocksubmissions'] = 'Unlock submissions';
$string['unlimitedattempts'] = 'Unlimited';
Expand Down
27 changes: 23 additions & 4 deletions mod/assign/locallib.php
Expand Up @@ -146,6 +146,9 @@ class assign {
/** @var array cached list of user groups when team submissions are enabled. The cache key will be the user. */
private $usersubmissiongroups = array();

/** @var array cached list of user groups. The cache key will be the user. */
private $usergroups = array();

/**
* Constructor for the base assign class.
*
Expand Down Expand Up @@ -2301,8 +2304,7 @@ public function get_submission_group($userid) {
return $this->usersubmissiongroups[$userid];
}

$grouping = $this->get_instance()->teamsubmissiongroupingid;
$groups = groups_get_all_groups($this->get_course()->id, $userid, $grouping);
$groups = $this->get_all_groups($userid);
if (count($groups) != 1) {
$return = false;
} else {
Expand All @@ -2315,6 +2317,19 @@ public function get_submission_group($userid) {
return $return;
}

private function get_all_groups($userid) {
if (isset($this->usergroups[$userid])) {
return $this->usergroups[$userid];
}

$grouping = $this->get_instance()->teamsubmissiongroupingid;
$return = groups_get_all_groups($this->get_course()->id, $userid, $grouping);

$this->usergroups[$userid] = $return;

return $return;
}


/**
* Display the submission that is used by a plugin.
Expand Down Expand Up @@ -3033,6 +3048,7 @@ protected function view_single_grade_page($mform) {
}
$showedit = $this->submissions_open($userid) && ($this->is_any_submission_plugin_enabled());
$viewfullnames = has_capability('moodle/site:viewfullnames', $this->get_course_context());
$usergroups = $this->get_all_groups($user->id);

$submissionstatus = new assign_submission_status($instance->allowsubmissionsfromdate,
$instance->alwaysshowdescription,
Expand Down Expand Up @@ -3062,7 +3078,8 @@ protected function view_single_grade_page($mform) {
$instance->attemptreopenmethod,
$instance->maxattempts,
$this->get_grading_status($userid),
$instance->preventsubmissionnotingroup);
$instance->preventsubmissionnotingroup,
$usergroups);
$o .= $this->get_renderer()->render($submissionstatus);
}

Expand Down Expand Up @@ -3939,6 +3956,7 @@ public function view_student_summary($user, $showlinks) {
$viewfullnames = has_capability('moodle/site:viewfullnames', $this->get_course_context());

$gradingstatus = $this->get_grading_status($user->id);
$usergroups = $this->get_all_groups($user->id);
$submissionstatus = new assign_submission_status($instance->allowsubmissionsfromdate,
$instance->alwaysshowdescription,
$submission,
Expand Down Expand Up @@ -3967,7 +3985,8 @@ public function view_student_summary($user, $showlinks) {
$instance->attemptreopenmethod,
$instance->maxattempts,
$gradingstatus,
$instance->preventsubmissionnotingroup);
$instance->preventsubmissionnotingroup,
$usergroups);
if (has_capability('mod/assign:submit', $this->get_context(), $user)) {
$o .= $this->get_renderer()->render($submissionstatus);
}
Expand Down
7 changes: 6 additions & 1 deletion mod/assign/renderable.php
Expand Up @@ -388,6 +388,8 @@ class assign_submission_status implements renderable {
public $gradingstatus = '';
/** @var bool preventsubmissionnotingroup */
public $preventsubmissionnotingroup = 0;
/** @var array usergroups */
public $usergroups = array();


/**
Expand Down Expand Up @@ -422,6 +424,7 @@ class assign_submission_status implements renderable {
* @param int $maxattempts - How many attempts can a student make?
* @param string $gradingstatus - The submission status (ie. Graded, Not Released etc).
* @param bool $preventsubmissionnotingroup - Prevent submission if user is not in a group
* @param array $usergroups - Array containing all groups the user is assigned to
*/
public function __construct($allowsubmissionsfromdate,
$alwaysshowdescription,
Expand Down Expand Up @@ -451,7 +454,8 @@ public function __construct($allowsubmissionsfromdate,
$attemptreopenmethod,
$maxattempts,
$gradingstatus,
$preventsubmissionnotingroup) {
$preventsubmissionnotingroup,
$usergroups) {
$this->allowsubmissionsfromdate = $allowsubmissionsfromdate;
$this->alwaysshowdescription = $alwaysshowdescription;
$this->submission = $submission;
Expand Down Expand Up @@ -481,6 +485,7 @@ public function __construct($allowsubmissionsfromdate,
$this->maxattempts = $maxattempts;
$this->gradingstatus = $gradingstatus;
$this->preventsubmissionnotingroup = $preventsubmissionnotingroup;
$this->usergroups = $usergroups;
}
}

Expand Down
6 changes: 5 additions & 1 deletion mod/assign/renderer.php
Expand Up @@ -452,7 +452,11 @@ public function render_assign_submission_status(assign_submission_status $status
if ($group) {
$cell2 = new html_table_cell(format_string($group->name, false, $status->context));
} else if ($status->preventsubmissionnotingroup) {
$cell2 = new html_table_cell(get_string('noteam', 'assign'));
if (count($status->usergroups) == 0) {
$cell2 = new html_table_cell(get_string('noteam', 'assign'));
} else if (count($status->usergroups) > 1) {
$cell2 = new html_table_cell(get_string('multipleteams', 'assign'));
}
} else {
$cell2 = new html_table_cell(get_string('defaultteam', 'assign'));
}
Expand Down
31 changes: 28 additions & 3 deletions mod/assign/tests/behat/submit_without_group.feature
Expand Up @@ -9,19 +9,24 @@ Feature: Submit assignment without group
| fullname | shortname | category | groupmode |
| Course 1 | C1 | 0 | 1 |
| Course 2 | C2 | 0 | 1 |
| Course 3 | C3 | 0 | 1 |
And the following "activities" exist:
| activity | course | idnumber | name | intro | assignsubmission_onlinetext_enabled | preventsubmissionnotingroup | teamsubmission |
| assign | C1 | assign1 | Allow default group | Test assignment description | 1 | 0 | 1 |
| assign | C1 | assign2 | Require group membership | Test assignment description | 1 | 1 | 1 |
| assign | C2 | assign2 | Require group membership | Test assignment description | 1 | 1 | 1 |
| assign | C3 | assign2 | Require group membership | Test assignment description | 1 | 1 | 1 |
And the following "users" exist:
| username | firstname | lastname | email |
| teacher1 | Teacher | 1 | teacher1@example.com |
| student1 | Student | 1 | student1@example.com |
| student2 | Student | 2 | student2@example.com |
| student3 | Student | 3 | student3@example.com |
And the following "groups" exist:
| name | course | idnumber |
| Group 1 | C2 | G1 |
| Group 1 | C3 | G1 |
| Group 2 | C3 | G2 |
And the following "course enrolments" exist:
| user | course | role |
| teacher1 | C1 | editingteacher |
Expand All @@ -30,12 +35,20 @@ Feature: Submit assignment without group
| teacher1 | C2 | editingteacher |
| student1 | C2 | student |
| student2 | C2 | student |
| teacher1 | C3 | editingteacher |
| student3 | C3 | student |
And I log in as "teacher1"
And I follow "Course 2"
And I expand "Users" node
And I follow "Groups"
And I add "Student 1 (student1@example.com)" user to "Group 1" group members
And I add "Student 2 (student2@example.com)" user to "Group 1" group members
And I am on homepage
And I follow "Course 3"
And I expand "Users" node
And I follow "Groups"
And I add "Student 3 (student3@example.com)" user to "Group 1" group members
And I add "Student 3 (student3@example.com)" user to "Group 2" group members
And I log out
When I log in as "student1"
And I follow "Course 1"
Expand Down Expand Up @@ -80,7 +93,7 @@ Feature: Submit assignment without group
And I follow "Course 1"
And I follow "Allow default group"
And I should see "1" in the "Groups" "table_row"
And I should not see "The setting 'Require group to make submission' is turned on and some users are not allocated to groups, this will prevent them from submitting assignments."
And I should not see "The setting 'Require group to make submission' is turned on and some users are not allocated to groups or are allocated to multiple groups, this will prevent them from submitting assignments."
And I follow "View/grade all submissions"
And I should see "Default group" in the "Student 1" "table_row"
And I should see "Default group" in the "Student 2" "table_row"
Expand All @@ -90,7 +103,7 @@ Feature: Submit assignment without group
And I follow "Course 1"
And I follow "Require group membership"
And I should see "0" in the "Groups" "table_row"
And I should see "The setting 'Require group to make submission' is turned on and some users are not allocated to groups, this will prevent them from submitting assignments."
And I should see "The setting 'Require group to make submission' is turned on and some users are not allocated to groups or are allocated to multiple groups, this will prevent them from submitting assignments."
And I follow "View/grade all submissions"
And I should see "Default group" in the "Student 1" "table_row"
And I should see "Default group" in the "Student 2" "table_row"
Expand All @@ -100,9 +113,21 @@ Feature: Submit assignment without group
And I follow "Course 2"
And I follow "Require group membership"
And I should see "1" in the "Groups" "table_row"
And I should not see "The setting 'Require group to make submission' is turned on and some users are not allocated to groups, this will prevent them from submitting assignments."
And I should not see "The setting 'Require group to make submission' is turned on and some users are not allocated to groups or are allocated to multiple groups, this will prevent them from submitting assignments."
And I follow "View/grade all submissions"
And I should see "Group 1" in the "Student 1" "table_row"
And I should see "Group 1" in the "Student 2" "table_row"
And I should see "Submitted for grading" in the "Student 1" "table_row"
And I should see "Submitted for grading" in the "Student 2" "table_row"
And I log out
When I log in as "student3"
And I follow "Course 3"
And I follow "Require group membership"
Then I should see "You're a member of multiple groups, please contact your teacher."
And I should see "Nothing has been submitted for this assignment"
And I should not see "Add submission"
And I log out
And I log in as "teacher1"
And I follow "Course 1"
And I follow "Require group membership"
And I should see "The setting 'Require group to make submission' is turned on and some users are not allocated to groups or are allocated to multiple groups, this will prevent them from submitting assignments."

0 comments on commit ee5d4ee

Please sign in to comment.