Skip to content

Commit

Permalink
MDL-48159 mod_assign: Added setting preventsubmissionnotingroup
Browse files Browse the repository at this point in the history
If enabled a user will be unable to make a submission unless they are a
member of a group.
  • Loading branch information
andrewhancox committed Apr 7, 2015
1 parent beaceef commit e528997
Show file tree
Hide file tree
Showing 15 changed files with 274 additions and 38 deletions.
3 changes: 2 additions & 1 deletion mod/assign/backup/moodle2/backup_assign_stepslib.php
Expand Up @@ -67,7 +67,8 @@ protected function define_structure() {
'attemptreopenmethod',
'maxattempts',
'markingworkflow',
'markingallocation'));
'markingallocation',
'preventsubmissionnotingroup'));

$userflags = new backup_nested_element('userflags');

Expand Down
3 changes: 3 additions & 0 deletions mod/assign/backup/moodle2/restore_assign_stepslib.php
Expand Up @@ -110,6 +110,9 @@ protected function process_assign($data) {
if (!isset($data->markingallocation)) {
$data->markingallocation = 0;
}
if (!isset($data->preventsubmissionnotingroup)) {
$data->preventsubmissionnotingroup = 0;
}

if (!empty($data->preventlatesubmissions)) {
$data->cutoffdate = $data->duedate;
Expand Down
1 change: 1 addition & 0 deletions mod/assign/db/install.xml
Expand Up @@ -33,6 +33,7 @@
<FIELD NAME="markingworkflow" TYPE="int" LENGTH="2" NOTNULL="true" DEFAULT="0" SEQUENCE="false" COMMENT="If enabled, marking workflow features will be used in this assignment."/>
<FIELD NAME="markingallocation" TYPE="int" LENGTH="2" NOTNULL="true" DEFAULT="0" SEQUENCE="false" COMMENT="If enabled, marking allocation features will be used in this assignment"/>
<FIELD NAME="sendstudentnotifications" TYPE="int" LENGTH="2" NOTNULL="true" DEFAULT="1" SEQUENCE="false" COMMENT="Default for send student notifications checkbox when grading."/>
<FIELD NAME="preventsubmissionnotingroup" TYPE="int" LENGTH="2" NOTNULL="true" DEFAULT="0" SEQUENCE="false" COMMENT="If enabled a user will be unable to make a submission unless they are a member of a group."/>
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id" COMMENT="The unique id for this assignment instance."/>
Expand Down
22 changes: 22 additions & 0 deletions mod/assign/db/upgrade.php
Expand Up @@ -616,5 +616,27 @@ function xmldb_assign_upgrade($oldversion) {
upgrade_mod_savepoint(true, 2014122600, 'assign');
}

if ($oldversion < 2015022300) {

// Define field preventsubmissionnotingroup to be added to assign.
$table = new xmldb_table('assign');
$field = new xmldb_field('preventsubmissionnotingroup',
XMLDB_TYPE_INTEGER,
'2',
null,
XMLDB_NOTNULL,
null,
'0',
'sendstudentnotifications');

// Conditionally launch add field preventsubmissionnotingroup.
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}

// Assign savepoint reached.
upgrade_mod_savepoint(true, 2015022300, 'assign');
}

return true;
}
7 changes: 6 additions & 1 deletion mod/assign/gradingtable.php
Expand Up @@ -915,7 +915,12 @@ public function col_status(stdClass $row) {
$group = false;
$submission = false;
$this->get_group_and_submission($row->id, $group, $submission, -1);
if ($submission) {

if ($instance->teamsubmission && !$group && !$instance->preventsubmissionnotingroup) {
$group = true;
}

if ($group && $submission) {
$timesubmitted = $submission->timemodified;
$status = $submission->status;
} else {
Expand Down
4 changes: 4 additions & 0 deletions mod/assign/lang/en/assign.php
Expand Up @@ -289,6 +289,7 @@
$string['nosavebutnext'] = 'Next';
$string['nosubmission'] = 'Nothing has been submitted for this assignment';
$string['nosubmissionsacceptedafter'] = 'No submissions accepted after ';
$string['noteam'] = 'You\'re not a member of any group, please contact your teacher.';
$string['notgraded'] = 'Not graded';
$string['notgradedyet'] = 'Not graded yet';
$string['notsubmittedyet'] = 'Not submitted yet';
Expand All @@ -309,6 +310,8 @@
$string['participant'] = 'Participant';
$string['pluginadministration'] = 'Assignment administration';
$string['pluginname'] = 'Assignment';
$string['preventsubmissionnotingroup'] = 'Require group to make submission';
$string['preventsubmissionnotingroup_help'] = 'If enabled, users who are not members of a group will be unable to make submissions.';
$string['preventsubmissions'] = 'Prevent the user from making any more submissions to this assignment.';
$string['preventsubmissionsshort'] = 'Prevent submission changes';
$string['previous'] = 'Previous';
Expand Down Expand Up @@ -431,6 +434,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['unlocksubmissionforstudent'] = 'Allow submissions for student: (id={$a->id}, fullname={$a->fullname}).';
$string['unlocksubmissions'] = 'Unlock submissions';
$string['unlimitedattempts'] = 'Unlimited';
Expand Down
55 changes: 43 additions & 12 deletions mod/assign/locallib.php
Expand Up @@ -609,6 +609,9 @@ public function add_instance(stdClass $formdata, $callplugins) {
if (!empty($formdata->maxattempts)) {
$update->maxattempts = $formdata->maxattempts;
}
if (isset($formdata->preventsubmissionnotingroup)) {
$update->preventsubmissionnotingroup = $formdata->preventsubmissionnotingroup;
}
$update->markingworkflow = $formdata->markingworkflow;
$update->markingallocation = $formdata->markingallocation;
if (empty($update->markingworkflow)) { // If marking workflow is disabled, make sure allocation is disabled.
Expand Down Expand Up @@ -970,6 +973,9 @@ public function update_instance($formdata) {
if (!empty($formdata->maxattempts)) {
$update->maxattempts = $formdata->maxattempts;
}
if (isset($formdata->preventsubmissionnotingroup)) {
$update->preventsubmissionnotingroup = $formdata->preventsubmissionnotingroup;
}
$update->markingworkflow = $formdata->markingworkflow;
$update->markingallocation = $formdata->markingallocation;
if (empty($update->markingworkflow)) { // If marking workflow is disabled, make sure allocation is disabled.
Expand Down Expand Up @@ -1443,11 +1449,12 @@ public function count_teams($activitygroup = 0) {

// When a specific group is selected we don't count the default group users.
if ($activitygroup == 0) {

// See if there are any users in the default group.
$defaultusers = $this->get_submission_group_members(0, true);
if (count($defaultusers) > 0) {
$count += 1;
if (empty($this->get_instance()->preventsubmissionnotingroup)) {
// See if there are any users in the default group.
$defaultusers = $this->get_submission_group_members(0, true);
if (count($defaultusers) > 0) {
$count += 1;
}
}
}
} else {
Expand All @@ -1456,7 +1463,7 @@ public function count_teams($activitygroup = 0) {
foreach ($participants as $participant) {
if ($group = $this->get_submission_group($participant->id)) {
$groups[$group->id] = true;
} else {
} else if (empty($this->get_instance()->preventsubmissionnotingroup)) {
$groups[0] = true;
}
}
Expand Down Expand Up @@ -3054,7 +3061,8 @@ protected function view_single_grade_page($mform) {
'',
$instance->attemptreopenmethod,
$instance->maxattempts,
$this->get_grading_status($userid));
$this->get_grading_status($userid),
$instance->preventsubmissionnotingroup);
$o .= $this->get_renderer()->render($submissionstatus);
}

Expand Down Expand Up @@ -3465,6 +3473,9 @@ protected function view_edit_submission_page($mform, $notices) {
$userid = optional_param('userid', $USER->id, PARAM_INT);
$user = $DB->get_record('user', array('id'=>$userid), '*', MUST_EXIST);
if ($userid == $USER->id) {
if (!$this->can_edit_submission($userid, $USER->id)) {
print_error('nopermission');
}
// User is editing their own submission.
require_capability('mod/assign:submit', $this->context);
$title = get_string('editsubmission', 'assign');
Expand Down Expand Up @@ -3907,7 +3918,7 @@ public function view_student_summary($user, $showlinks) {
}

$showsubmit = ($showlinks && $this->submissions_open($user->id));
$showsubmit = ($showsubmit && $this->show_submit_button($submission, $teamsubmission));
$showsubmit = ($showsubmit && $this->show_submit_button($submission, $teamsubmission, $user->id));

$extensionduedate = null;
if ($flags) {
Expand Down Expand Up @@ -3943,7 +3954,8 @@ public function view_student_summary($user, $showlinks) {
$gradingcontrollerpreview,
$instance->attemptreopenmethod,
$instance->maxattempts,
$gradingstatus);
$gradingstatus,
$instance->preventsubmissionnotingroup);
if (has_capability('mod/assign:submit', $this->get_context(), $user)) {
$o .= $this->get_renderer()->render($submissionstatus);
}
Expand Down Expand Up @@ -4048,9 +4060,10 @@ public function view_student_summary($user, $showlinks) {
*
* @param stdClass $submission The users own submission record.
* @param stdClass $teamsubmission The users team submission record if there is one
* @param int $userid The user
* @return bool
*/
protected function show_submit_button($submission = null, $teamsubmission = null) {
protected function show_submit_button($submission = null, $teamsubmission = null, $userid = null) {
if ($teamsubmission) {
if ($teamsubmission->status === ASSIGN_SUBMISSION_STATUS_SUBMITTED) {
// The assignment submission has been completed.
Expand All @@ -4061,6 +4074,11 @@ protected function show_submit_button($submission = null, $teamsubmission = null
} else if ($submission && $submission->status === ASSIGN_SUBMISSION_STATUS_SUBMITTED) {
// The user has already clicked the submit button on the team submission.
return false;
} else if (
!empty($this->get_instance()->preventsubmissionnotingroup)
&& $this->get_submission_group($userid) == false
) {
return false;
}
} else if ($submission) {
if ($submission->status === ASSIGN_SUBMISSION_STATUS_SUBMITTED) {
Expand Down Expand Up @@ -4220,6 +4238,9 @@ protected function view_submission_page() {
$activitygroup = groups_get_activity_group($this->get_course_module());

if ($instance->teamsubmission) {
$defaultteammembers = $this->get_submission_group_members(0, true);
$warnofungroupedusers = (count($defaultteammembers) > 0 && $instance->preventsubmissionnotingroup);

$summary = new assign_grading_summary($this->count_teams($activitygroup),
$instance->submissiondrafts,
$this->count_submissions_with_status($draft),
Expand All @@ -4229,7 +4250,8 @@ protected function view_submission_page() {
$instance->duedate,
$this->get_course_module()->id,
$this->count_submissions_need_grading(),
$instance->teamsubmission);
$instance->teamsubmission,
$warnofungroupedusers);
$o .= $this->get_renderer()->render($summary);
} else {
// The active group has already been updated in groups_print_activity_menu().
Expand All @@ -4243,7 +4265,8 @@ protected function view_submission_page() {
$instance->duedate,
$this->get_course_module()->id,
$this->count_submissions_need_grading(),
$instance->teamsubmission);
$instance->teamsubmission,
false);
$o .= $this->get_renderer()->render($summary);
}
}
Expand Down Expand Up @@ -4584,6 +4607,14 @@ public function can_edit_submission($userid, $graderid = 0) {
$graderid = $USER->id;
}

$instance = $this->get_instance();
if ($userid == $graderid &&
$instance->teamsubmission &&
$instance->preventsubmissionnotingroup &&
$this->get_submission_group($userid) == false) {
return false;
}

if ($userid == $graderid &&
$this->submissions_open($userid) &&
has_capability('mod/assign:submit', $this->context, $graderid)) {
Expand Down
7 changes: 7 additions & 0 deletions mod/assign/mod_form.php
Expand Up @@ -138,6 +138,13 @@ public function definition() {
$mform->freeze('teamsubmission');
}

$name = get_string('preventsubmissionnotingroup', 'assign');
$mform->addElement('selectyesno', 'preventsubmissionnotingroup', $name);
$mform->addHelpButton('preventsubmissionnotingroup',
'preventsubmissionnotingroup',
'assign');
$mform->setType('preventsubmissionnotingroup', PARAM_BOOL);

$name = get_string('requireallteammemberssubmit', 'assign');
$mform->addElement('selectyesno', 'requireallteammemberssubmit', $name);
$mform->addHelpButton('requireallteammemberssubmit', 'requireallteammemberssubmit', 'assign');
Expand Down
13 changes: 11 additions & 2 deletions mod/assign/renderable.php
Expand Up @@ -386,6 +386,8 @@ class assign_submission_status implements renderable {
public $maxattempts = -1;
/** @var string gradingstatus */
public $gradingstatus = '';
/** @var bool preventsubmissionnotingroup */
public $preventsubmissionnotingroup = 0;


/**
Expand Down Expand Up @@ -419,6 +421,7 @@ class assign_submission_status implements renderable {
* @param string $attemptreopenmethod - The method of reopening student attempts.
* @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
*/
public function __construct($allowsubmissionsfromdate,
$alwaysshowdescription,
Expand Down Expand Up @@ -447,7 +450,8 @@ public function __construct($allowsubmissionsfromdate,
$gradingcontrollerpreview,
$attemptreopenmethod,
$maxattempts,
$gradingstatus) {
$gradingstatus,
$preventsubmissionnotingroup) {
$this->allowsubmissionsfromdate = $allowsubmissionsfromdate;
$this->alwaysshowdescription = $alwaysshowdescription;
$this->submission = $submission;
Expand Down Expand Up @@ -476,6 +480,7 @@ public function __construct($allowsubmissionsfromdate,
$this->attemptreopenmethod = $attemptreopenmethod;
$this->maxattempts = $maxattempts;
$this->gradingstatus = $gradingstatus;
$this->preventsubmissionnotingroup = $preventsubmissionnotingroup;
}
}

Expand Down Expand Up @@ -642,6 +647,8 @@ class assign_grading_summary implements renderable {
public $coursemoduleid = 0;
/** @var boolean teamsubmission - Are team submissions enabled for this assignment */
public $teamsubmission = false;
/** @var boolean warnofungroupedusers - Do we need to warn people that there are users without groups */
public $warnofungroupedusers = false;

/**
* constructor
Expand All @@ -666,7 +673,8 @@ public function __construct($participantcount,
$duedate,
$coursemoduleid,
$submissionsneedgradingcount,
$teamsubmission) {
$teamsubmission,
$warnofungroupedusers) {
$this->participantcount = $participantcount;
$this->submissiondraftsenabled = $submissiondraftsenabled;
$this->submissiondraftscount = $submissiondraftscount;
Expand All @@ -677,6 +685,7 @@ public function __construct($participantcount,
$this->coursemoduleid = $coursemoduleid;
$this->submissionsneedgradingcount = $submissionsneedgradingcount;
$this->teamsubmission = $teamsubmission;
$this->warnofungroupedusers = $warnofungroupedusers;
}
}

Expand Down

0 comments on commit e528997

Please sign in to comment.