Permalink
Browse files

MDL-31295: Allow granting individual extension dates to students for …

…mod_assign
  • Loading branch information...
Damyon Wiese
Damyon Wiese committed Jun 8, 2012
1 parent 21a87e5 commit 9e795179ad2574c0e06b8f1763372abb6debaa60
@@ -48,11 +48,11 @@ protected function define_structure() {
'intro',
'introformat',
'alwaysshowdescription',
- 'preventlatesubmissions',
'submissiondrafts',
'sendnotifications',
'sendlatenotifications',
'duedate',
+ 'cutoffdate',
'allowsubmissionsfromdate',
'grade',
'timemodified',
@@ -75,7 +75,8 @@ protected function define_structure() {
'grader',
'grade',
'locked',
- 'mailed'));
+ 'mailed',
+ 'extensionduedate'));
$pluginconfigs = new backup_nested_element('plugin_configs');
@@ -74,6 +74,16 @@ protected function process_assign($data) {
$data->allowsubmissionsfromdate = $this->apply_date_offset($data->allowsubmissionsfromdate);
$data->duedate = $this->apply_date_offset($data->duedate);
+ if (!isset($data->cutoffdate)) {
+ $data->cutoffdate = 0;
+ }
+
+ if (!empty($data->preventlatesubmissions)) {
+ $data->cutoffdate = $data->duedate;
+ } else {
+ $data->cutoffdate = $this->apply_date_offset($data->cutoffdate);
+ }
+
$newitemid = $DB->insert_record('assign', $data);
@@ -121,6 +131,7 @@ protected function process_assign_grade($data) {
$data->timecreated = $this->apply_date_offset($data->timecreated);
$data->userid = $this->get_mappingid('user', $data->userid);
$data->grader = $this->get_mappingid('user', $data->grader);
+ $data->extensionduedate = $this->apply_date_offset($data->extensionduedate);
$newitemid = $DB->insert_record('assign_grades', $data);
View
@@ -81,6 +81,18 @@
),
'clonepermissionsfrom' => 'moodle/course:manageactivities'
),
+
+ 'mod/assign:grantextension' => array(
+ 'captype' => 'write',
+ 'contextlevel' => CONTEXT_MODULE,
+ 'archetypes' => array(
+ 'teacher' => CAP_ALLOW,
+ 'editingteacher' => CAP_ALLOW,
+ 'manager' => CAP_ALLOW
+ ),
+ 'clonepermissionsfrom' => 'gradereport/grader:view'
+ ),
+
);
View
15 mod/assign/db/install.xml 100644 → 100755
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" ?>
-<XMLDB PATH="mod/assign/db" VERSION="20120423" COMMENT="XMLDB file for Moodle mod/assign"
+<XMLDB PATH="mod/assign/db" VERSION="20120830" COMMENT="XMLDB file for Moodle mod/assign"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="../../../lib/xmldb/xmldb.xsd"
>
@@ -12,17 +12,17 @@
<FIELD NAME="intro" TYPE="text" NOTNULL="true" SEQUENCE="false" COMMENT="The description of the assignment. This field is used by feature MOD_INTRO." PREVIOUS="name" NEXT="introformat"/>
<FIELD NAME="introformat" TYPE="int" LENGTH="4" NOTNULL="true" DEFAULT="0" SEQUENCE="false" COMMENT="The format of the description field of the assignment. This field is used by feature MOD_INTRO." PREVIOUS="intro" NEXT="alwaysshowdescription"/>
<FIELD NAME="alwaysshowdescription" TYPE="int" LENGTH="2" NOTNULL="true" DEFAULT="0" SEQUENCE="false" COMMENT="If false the assignment intro will only be displayed after the allowsubmissionsfrom date. If true it will always be displayed." PREVIOUS="introformat" NEXT="nosubmissions"/>
- <FIELD NAME="nosubmissions" TYPE="int" LENGTH="2" NOTNULL="true" DEFAULT="0" SEQUENCE="false" COMMENT="This field is a cache for is_any_submission_plugin_enabled() which allows Moodle pages to distinguish offline assignment types without loading the assignment class." PREVIOUS="alwaysshowdescription" NEXT="preventlatesubmissions"/>
- <FIELD NAME="preventlatesubmissions" TYPE="int" LENGTH="2" NOTNULL="true" DEFAULT="0" SEQUENCE="false" COMMENT="If true, submissions will not be accepted past the due date." PREVIOUS="nosubmissions" NEXT="submissiondrafts"/>
- <FIELD NAME="submissiondrafts" TYPE="int" LENGTH="2" NOTNULL="true" DEFAULT="0" SEQUENCE="false" COMMENT="If true, assignment submissions will be considered drafts until the student clicks on the submit assignmnet button." PREVIOUS="preventlatesubmissions" NEXT="sendnotifications"/>
+ <FIELD NAME="nosubmissions" TYPE="int" LENGTH="2" NOTNULL="true" DEFAULT="0" SEQUENCE="false" COMMENT="This field is a cache for is_any_submission_plugin_enabled() which allows Moodle pages to distinguish offline assignment types without loading the assignment class." PREVIOUS="alwaysshowdescription" NEXT="submissiondrafts"/>
+ <FIELD NAME="submissiondrafts" TYPE="int" LENGTH="2" NOTNULL="true" DEFAULT="0" SEQUENCE="false" COMMENT="If true, assignment submissions will be considered drafts until the student clicks on the submit assignmnet button." PREVIOUS="nosubmissions" NEXT="sendnotifications"/>
<FIELD NAME="sendnotifications" TYPE="int" LENGTH="2" NOTNULL="true" DEFAULT="0" SEQUENCE="false" COMMENT="Allows the disabling of email notifications in the assign module." PREVIOUS="submissiondrafts" NEXT="sendlatenotifications"/>
<FIELD NAME="sendlatenotifications" TYPE="int" LENGTH="2" NOTNULL="true" DEFAULT="0" SEQUENCE="false" COMMENT="Allows separate enabling of notifications for late assignment submissions." PREVIOUS="sendnotifications" NEXT="duedate"/>
<FIELD NAME="duedate" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false" COMMENT="The due date for the assignment. Displayed to students." PREVIOUS="sendlatenotifications" NEXT="allowsubmissionsfromdate"/>
<FIELD NAME="allowsubmissionsfromdate" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false" COMMENT="If set, submissions will only be accepted after this date." PREVIOUS="duedate" NEXT="grade"/>
<FIELD NAME="grade" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false" COMMENT="The maximum grade for this assignment. Can be negative to indicate the use of a scale." PREVIOUS="allowsubmissionsfromdate" NEXT="timemodified"/>
<FIELD NAME="timemodified" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false" COMMENT="The time the settings for this assign module instance were last modified." PREVIOUS="grade" NEXT="requiresubmissionstatement"/>
<FIELD NAME="requiresubmissionstatement" TYPE="int" LENGTH="2" NOTNULL="true" DEFAULT="0" SEQUENCE="false" COMMENT="Forces the student to accept a submission statement when submitting an assignment" PREVIOUS="timemodified" NEXT="completionsubmit"/>
- <FIELD NAME="completionsubmit" TYPE="int" LENGTH="2" NOTNULL="true" DEFAULT="0" SEQUENCE="false" COMMENT="If this field is set to 1, then the activity will be automatically marked as 'complete' once the user submits their assignment." PREVIOUS="requiresubmissionstatement"/>
+ <FIELD NAME="completionsubmit" TYPE="int" LENGTH="2" NOTNULL="true" DEFAULT="0" SEQUENCE="false" COMMENT="If this field is set to 1, then the activity will be automatically marked as 'complete' once the user submits their assignment." PREVIOUS="requiresubmissionstatement" NEXT="cutoffdate"/>
+ <FIELD NAME="cutoffdate" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false" COMMENT="The final date after which submissions will no longer be accepted for this assignment without an extensions." PREVIOUS="completionsubmit"/>
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id" COMMENT="The unique id for this assignment instance."/>
@@ -58,7 +58,8 @@
<FIELD NAME="grader" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="timemodified" NEXT="grade"/>
<FIELD NAME="grade" TYPE="number" LENGTH="10" NOTNULL="false" DEFAULT="0" SEQUENCE="false" DECIMALS="5" COMMENT="The numerical grade for this assignment submission. Can be determined by scales/advancedgradingforms etc but will always be converted back to a floating point number." PREVIOUS="grader" NEXT="locked"/>
<FIELD NAME="locked" TYPE="int" LENGTH="1" NOTNULL="true" DEFAULT="0" SEQUENCE="false" COMMENT="A flag to prevent changes for a single student submission." PREVIOUS="grade" NEXT="mailed"/>
- <FIELD NAME="mailed" TYPE="int" LENGTH="1" NOTNULL="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="locked"/>
+ <FIELD NAME="mailed" TYPE="int" LENGTH="1" NOTNULL="true" DEFAULT="0" SEQUENCE="false" COMMENT="Has the student been sent a notification about this grade update?" PREVIOUS="locked" NEXT="extensionduedate"/>
+ <FIELD NAME="extensionduedate" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false" COMMENT="An extension date assigned to an individual student" PREVIOUS="mailed"/>
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id" COMMENT="The unique id for this grade." NEXT="assignment"/>
@@ -89,4 +90,4 @@
</INDEXES>
</TABLE>
</TABLES>
-</XMLDB>
+</XMLDB>
View
@@ -80,6 +80,45 @@ function xmldb_assign_upgrade($oldversion) {
upgrade_mod_savepoint(true, 2012081600, 'assign');
}
+ // Individual extension dates support.
+ if ($oldversion < 2012082100) {
+
+ // Define field sendlatenotifications to be added to assign.
+ $table = new xmldb_table('assign');
+ $field = new xmldb_field('cutoffdate', XMLDB_TYPE_INTEGER, '10', null,
+ XMLDB_NOTNULL, null, '0', 'completionsubmit');
+
+ // Conditionally launch add field sendlatenotifications.
+ if (!$dbman->field_exists($table, $field)) {
+ $dbman->add_field($table, $field);
+ }
+ // If prevent late is on - set cutoffdate to due date.
+
+ // Now remove the preventlatesubmissions column.
+ $field = new xmldb_field('preventlatesubmissions', XMLDB_TYPE_INTEGER, '2', null,
+ XMLDB_NOTNULL, null, '0', 'nosubmissions');
+ if ($dbman->field_exists($table, $field)) {
+ // Set the cutoffdate to the duedate if preventlatesubmissions was enabled.
+ $sql = 'UPDATE {assign} SET cutoffdate = duedate WHERE preventlatesubmissions = 1';
+ $DB->execute($sql);
+
+ $dbman->drop_field($table, $field);
+ }
+
+ // Define field extensionduedate to be added to assign_grades
+ $table = new xmldb_table('assign_grades');
+ $field = new xmldb_field('extensionduedate', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0', 'mailed');
+
+ // Conditionally launch add field extensionduedate
+ if (!$dbman->field_exists($table, $field)) {
+ $dbman->add_field($table, $field);
+ }
+
+ // Assign savepoint reached.
+ upgrade_mod_savepoint(true, 2012082100, 'assign');
+ }
+
+
return true;
}
@@ -0,0 +1,102 @@
+<?php
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
+
+/**
+ * This file contains the forms to create and edit an instance of this module
+ *
+ * @package mod_assign
+ * @copyright 2012 NetSpot {@link http://www.netspot.com.au}
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.');
+
+
+require_once($CFG->libdir.'/formslib.php');
+require_once($CFG->dirroot . '/mod/assign/locallib.php');
+
+/**
+ * Assignment extension dates form
+ *
+ * @package mod_assign
+ * @copyright 2012 NetSpot {@link http://www.netspot.com.au}
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+class mod_assign_extension_form extends moodleform {
+ /** @var array $instance - The data passed to this form */
+ private $instance;
+
+ /**
+ * Define the form - called by parent constructor
+ */
+ public function definition() {
+ $mform = $this->_form;
+
+ list($coursemoduleid, $userid, $batchusers, $instance, $data) = $this->_customdata;
+ // Instance variable is used by the form validation function.
+ $this->instance = $instance;
+
+ if ($batchusers) {
+ $listusersmessage = get_string('grantextensionforusers', 'assign', count(explode(',', $batchusers)));
+ $mform->addElement('static', 'applytoselectedusers', '', $listusersmessage);
+ }
+ if ($instance->allowsubmissionsfromdate) {
+ $mform->addElement('static', 'allowsubmissionsfromdate', get_string('allowsubmissionsfromdate', 'assign'),
+ userdate($instance->allowsubmissionsfromdate));
+ }
+ if ($instance->duedate) {
+ $mform->addElement('static', 'duedate', get_string('duedate', 'assign'), userdate($instance->duedate));
+ $finaldate = $instance->duedate;
+ }
+ if ($instance->cutoffdate) {
+ $mform->addElement('static', 'cutoffdate', get_string('cutoffdate', 'assign'), userdate($instance->cutoffdate));
+ $finaldate = $instance->cutoffdate;
+ }
+ $mform->addElement('date_time_selector', 'extensionduedate',
+ get_string('extensionduedate', 'assign'), array('optional'=>true));
+ $mform->setDefault('extensionduedate', $finaldate);
+ $mform->addElement('hidden', 'id', $coursemoduleid);
+ $mform->addElement('hidden', 'userid', $userid);
+ $mform->addElement('hidden', 'selectedusers', $batchusers);
+ $mform->addElement('hidden', 'action', 'saveextension');
+ $this->add_action_buttons(true, get_string('savechanges', 'assign'));
+
+ if ($data) {
+ $this->set_data($data);
+ }
+ }
+
+ /**
+ * Perform validation on the extension form
+ * @param array $data
+ * @param array $files
+ */
+ public function validation($data, $files) {
+ $errors = parent::validation($data, $files);
+ if ($this->instance->duedate && $data['extensionduedate']) {
+ if ($this->instance->duedate > $data['extensionduedate']) {
+ $errors['extensionduedate'] = get_string('extensionnotafterduedate', 'assign');
+ }
+ }
+ if ($this->instance->allowsubmissionsfromdate && $data['extensionduedate']) {
+ if ($this->instance->allowsubmissionsfromdate > $data['extensionduedate']) {
+ $errors['extensionduedate'] = get_string('extensionnotafterfromdate', 'assign');
+ }
+ }
+
+ return $errors;
+ }
+}
@@ -23,6 +23,7 @@
*/
$string['configmaxbytes'] = 'Maximum file size';
+$string['countfiles'] = '{$a} files';
$string['default'] = 'Enabled by default';
$string['default_help'] = 'If set, this feedback method will be enabled by default for all new assignments.';
$string['enabled'] = 'File feedback';
@@ -52,6 +52,9 @@ function definition() {
if ($instance['submissiondrafts']) {
$options['reverttodraft'] = get_string('reverttodraft', 'assign');
}
+ if ($instance['duedate']) {
+ $options['grantextension'] = get_string('grantextension', 'assign');
+ }
$mform->addElement('hidden', 'action', 'batchgradingoperation');
$mform->addElement('hidden', 'id', $instance['cm']);
$mform->addElement('hidden', 'selectedusers', '', array('class'=>'selectedusers'));
Oops, something went wrong.

0 comments on commit 9e79517

Please sign in to comment.