Skip to content

Commit

Permalink
MDL-31288: New feature: Assignment submission statements
Browse files Browse the repository at this point in the history
  • Loading branch information
Damyon Wiese committed Jul 27, 2012
1 parent 55a568f commit 94f2690
Show file tree
Hide file tree
Showing 12 changed files with 231 additions and 47 deletions.
3 changes: 2 additions & 1 deletion mod/assign/db/install.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
<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"/>
<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"/>
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id" COMMENT="The unique id for this assignment instance."/>
Expand Down
26 changes: 14 additions & 12 deletions mod/assign/db/log.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,24 @@
defined('MOODLE_INTERNAL') || die();

$logs = array(
array('module'=>'assign', 'action'=>'view', 'mtable'=>'assign', 'field'=>'name'),
array('module'=>'assign', 'action'=>'add', 'mtable'=>'assign', 'field'=>'name'),
array('module'=>'assign', 'action'=>'delete mod', 'mtable'=>'assign', 'field'=>'name'),
array('module'=>'assign', 'action'=>'download all submissions', 'mtable'=>'assign', 'field'=>'name'),
array('module'=>'assign', 'action'=>'grade submission', 'mtable'=>'assign', 'field'=>'name'),
array('module'=>'assign', 'action'=>'lock submission', 'mtable'=>'assign', 'field'=>'name'),
array('module'=>'assign', 'action'=>'revert submission to draft', 'mtable'=>'assign', 'field'=>'name'),
array('module'=>'assign', 'action'=>'submission statement accepted', 'mtable'=>'assign', 'field'=>'name'),
array('module'=>'assign', 'action'=>'submit', 'mtable'=>'assign', 'field'=>'name'),
array('module'=>'assign', 'action'=>'submit for grading', 'mtable'=>'assign', 'field'=>'name'),
array('module'=>'assign', 'action'=>'unlock submission', 'mtable'=>'assign', 'field'=>'name'),
array('module'=>'assign', 'action'=>'update', 'mtable'=>'assign', 'field'=>'name'),
array('module'=>'assign', 'action'=>'view submission', 'mtable'=>'assign', 'field'=>'name'),
array('module'=>'assign', 'action'=>'view feedback', 'mtable'=>'assign', 'field'=>'name'),
array('module'=>'assign', 'action'=>'upload', 'mtable'=>'assign', 'field'=>'name'),
array('module'=>'assign', 'action'=>'download all submissions', 'mtable'=>'assign', 'field'=>'name'),
array('module'=>'assign', 'action'=>'view', 'mtable'=>'assign', 'field'=>'name'),
array('module'=>'assign', 'action'=>'view all', 'mtable'=>'course', 'field'=>'fullname'),
array('module'=>'assign', 'action'=>'view confirm submit assignment form', 'mtable'=>'assign', 'field'=>'name'),
array('module'=>'assign', 'action'=>'view grading form', 'mtable'=>'assign', 'field'=>'name'),
array('module'=>'assign', 'action'=>'delete mod', 'mtable'=>'assign', 'field'=>'name'),
array('module'=>'assign', 'action'=>'view submission', 'mtable'=>'assign', 'field'=>'name'),
array('module'=>'assign', 'action'=>'view submission grading table', 'mtable'=>'assign', 'field'=>'name'),
array('module'=>'assign', 'action'=>'view submit assignment form', 'mtable'=>'assign', 'field'=>'name'),
array('module'=>'assign', 'action'=>'submit for grading', 'mtable'=>'assign', 'field'=>'name'),
array('module'=>'assign', 'action'=>'submit', 'mtable'=>'assign', 'field'=>'name'),
array('module'=>'assign', 'action'=>'revert submission to draft', 'mtable'=>'assign', 'field'=>'name'),
array('module'=>'assign', 'action'=>'lock submission', 'mtable'=>'assign', 'field'=>'name'),
array('module'=>'assign', 'action'=>'unlock submission', 'mtable'=>'assign', 'field'=>'name'),
array('module'=>'assign', 'action'=>'grade submission', 'mtable'=>'assign', 'field'=>'name'),
array('module'=>'assign', 'action'=>'view all', 'mtable'=>'course', 'field'=>'fullname'),
array('module'=>'assign', 'action'=>'view feedback', 'mtable'=>'assign', 'field'=>'name'),
);
14 changes: 14 additions & 0 deletions mod/assign/db/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,20 @@ function xmldb_assign_upgrade($oldversion) {
// Assign savepoint reached.
upgrade_mod_savepoint(true, 2012051700, 'assign');
}
if ($oldversion < 2012071800) {

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

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

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

// Moodle v2.3.0 release upgrade line
// Put any upgrade step following this
Expand Down
5 changes: 5 additions & 0 deletions mod/assign/lang/en/assign.php
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,8 @@
$string['quickgradingresult'] = 'Quick grading';
$string['quickgradingchangessaved'] = 'The grade changes were saved';
$string['quickgrading_help'] = 'Quick grading allows you to assign grades (and outcomes) directly in the submissions table. Quick grading is not compatible with advanced grading and is not recommended when there are multiple markers.';
$string['requiresubmissionstatement'] = 'Require that students accept the submission statement';
$string['requiresubmissionstatement_help'] = 'Require that students accept the submission statement for all assignment submissions for this entire Moodle installation. If this setting is not enabled, then submission statements can be enabled or disabled in the settings for each assignment.';
$string['reverttodraftforstudent'] = 'Revert submission to draft for student: (id={$a->id}, fullname={$a->fullname}).';
$string['reverttodraft'] = 'Revert the submission to draft status.';
$string['reverttodraftshort'] = 'Revert the submission to draft';
Expand Down Expand Up @@ -228,6 +230,9 @@
$string['submissionsnotgraded'] = 'Submissions not graded: {$a}';
$string['submissionsclosed'] = 'Submissions closed';
$string['submissionsettings'] = 'Submission settings';
$string['submissionstatement'] = 'Submission statement';
$string['submissionstatement_help'] = 'Assignment submission confirmation statement';
$string['submissionstatementacceptedlog'] = 'Submission statement accepted by user {$a}';
$string['submissionstatus_draft'] = 'Draft (not submitted)';
$string['submissionstatusheading'] = 'Submission status';
$string['submissionstatus_marked'] = 'Graded';
Expand Down
120 changes: 98 additions & 22 deletions mod/assign/locallib.php
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,10 @@ public function view($action='') {
$this->process_unlock();
$action = 'grading';
} else if ($action == 'confirmsubmit') {
$this->process_submit_for_grading();
$action = 'submit';
if ($this->process_submit_for_grading($mform)) {
$action = 'view';
}
// save and show next button
} else if ($action == 'batchgradingoperation') {
$this->process_batch_grading_operation();
Expand Down Expand Up @@ -374,7 +377,7 @@ public function view($action='') {
} else if ($action == 'downloadall') {
$o .= $this->download_submissions();
} else if ($action == 'submit') {
$o .= $this->check_submit_for_grading();
$o .= $this->check_submit_for_grading($mform);
} else {
$o .= $this->view_submission_page();
}
Expand Down Expand Up @@ -408,6 +411,7 @@ public function add_instance(stdClass $formdata, $callplugins) {
$update->alwaysshowdescription = $formdata->alwaysshowdescription;
$update->preventlatesubmissions = $formdata->preventlatesubmissions;
$update->submissiondrafts = $formdata->submissiondrafts;
$update->requiresubmissionstatement = $formdata->requiresubmissionstatement;
$update->sendnotifications = $formdata->sendnotifications;
$update->sendlatenotifications = $formdata->sendlatenotifications;
$update->duedate = $formdata->duedate;
Expand Down Expand Up @@ -626,6 +630,7 @@ public function update_instance($formdata) {
$update->alwaysshowdescription = $formdata->alwaysshowdescription;
$update->preventlatesubmissions = $formdata->preventlatesubmissions;
$update->submissiondrafts = $formdata->submissiondrafts;
$update->requiresubmissionstatement = $formdata->requiresubmissionstatement;
$update->sendnotifications = $formdata->sendnotifications;
$update->sendlatenotifications = $formdata->sendlatenotifications;
$update->duedate = $formdata->duedate;
Expand Down Expand Up @@ -1973,10 +1978,14 @@ private function process_batch_grading_operation() {

/**
* Ask the user to confirm they want to submit their work for grading
* @param $mform moodleform - null unless form validation has failed
* @return string
*/
private function check_submit_for_grading() {
global $USER;
private function check_submit_for_grading($mform) {
global $USER, $CFG;

require_once($CFG->dirroot . '/mod/assign/submissionconfirmform.php');

// Check that all of the submission plugins are ready for this submission
$notifications = array();
$submission = $this->get_user_submission($USER->id, false);
Expand All @@ -1990,10 +1999,29 @@ private function check_submit_for_grading() {
}
}

$data = new stdClass();
$adminconfig = $this->get_admin_config();
$requiresubmissionstatement = !empty($adminconfig->requiresubmissionstatement) ||
$this->get_instance()->requiresubmissionstatement;

$submissionstatement = '';
if (!empty($adminconfig->submissionstatement)) {
$submissionstatement = $adminconfig->submissionstatement;
}

if ($mform == null) {
$mform = new mod_assign_confirm_submission_form(null, array($requiresubmissionstatement,
$submissionstatement,
$this->get_course_module()->id,
$data));
}
$o = '';
$o .= $this->output->header();
$o .= $this->output->render(new assign_submit_for_grading_page($notifications, $this->get_course_module()->id));
$o .= $this->output->render(new assign_submit_for_grading_page($notifications, $this->get_course_module()->id, $mform));
$o .= $this->view_footer();

$this->add_to_log('view confirm submit assignment form', get_string('viewownsubmissionform', 'assign'));

return $o;
}

Expand Down Expand Up @@ -2455,7 +2483,7 @@ private function notify_student_submission_receipt(stdClass $submission) {
global $DB;

$adminconfig = $this->get_admin_config();
if (!$adminconfig->submissionreceipts) {
if (empty($adminconfig->submissionreceipts)) {
// No need to do anything
return;
}
Expand Down Expand Up @@ -2490,29 +2518,58 @@ private function notify_graders(stdClass $submission) {
/**
* assignment submission is processed before grading
*
* @return void
* @param $mform If validation failed when submitting this form - this is the moodleform - it can be null
* @return bool Return false if the validation fails. This affects which page is displayed next.
*/
private function process_submit_for_grading() {
global $USER;
private function process_submit_for_grading($mform) {
global $USER, $CFG;

// Need submit permission to submit an assignment
require_capability('mod/assign:submit', $this->context);
require_once($CFG->dirroot . '/mod/assign/submissionconfirmform.php');
require_sesskey();

$submission = $this->get_user_submission($USER->id,true);
if ($submission->status != ASSIGN_SUBMISSION_STATUS_SUBMITTED) {
// Give each submission plugin a chance to process the submission
$plugins = $this->get_submission_plugins();
foreach ($plugins as $plugin) {
$plugin->submit_for_grading();
$data = new stdClass();
$adminconfig = $this->get_admin_config();
$requiresubmissionstatement = !empty($adminconfig->requiresubmissionstatement) ||
$this->get_instance()->requiresubmissionstatement;

$submissionstatement = '';
if (!empty($adminconfig->submissionstatement)) {
$submissionstatement = $adminconfig->submissionstatement;
}

if ($mform == null) {
$mform = new mod_assign_confirm_submission_form(null, array($requiresubmissionstatement,
$submissionstatement,
$this->get_course_module()->id,
$data));
}

$data = $mform->get_data();
if (!$mform->is_cancelled()) {
if ($mform->get_data() == false) {
return false;
}
$submission = $this->get_user_submission($USER->id,true);
if ($submission->status != ASSIGN_SUBMISSION_STATUS_SUBMITTED) {
// Give each submission plugin a chance to process the submission
$plugins = $this->get_submission_plugins();
foreach ($plugins as $plugin) {
$plugin->submit_for_grading();
}

$submission->status = ASSIGN_SUBMISSION_STATUS_SUBMITTED;
$this->update_submission($submission);
$this->add_to_log('submit for grading', $this->format_submission_for_log($submission));
$this->notify_graders($submission);
$this->notify_student_submission_receipt($submission);
$submission->status = ASSIGN_SUBMISSION_STATUS_SUBMITTED;
$this->update_submission($submission);
if (isset($data->submissionstatement)) {
$this->add_to_log('submission statement accepted', get_string('submissionstatementacceptedlog', 'mod_assign', fullname($USER)));
}
$this->add_to_log('submit for grading', $this->format_submission_for_log($submission));
$this->notify_graders($submission);
$this->notify_student_submission_receipt($submission);
}
}
return true;
}

/**
Expand Down Expand Up @@ -2776,6 +2833,9 @@ private function process_save_submission(&$mform) {
$this->update_submission($submission);

// Logging
if (isset($data->submissionstatement)) {
$this->add_to_log('submission statement accepted', get_string('submissionstatementacceptedlog', 'mod_assign', fullname($USER)));
}
$this->add_to_log('submit', $this->format_submission_for_log($submission));

if (!$this->get_instance()->submissiondrafts) {
Expand Down Expand Up @@ -3040,10 +3100,26 @@ public function is_any_submission_plugin_enabled() {
public function add_submission_form_elements(MoodleQuickForm $mform, stdClass $data) {
global $USER;

// online text submissions

$submission = $this->get_user_submission($USER->id, false);

// submission statement
$adminconfig = $this->get_admin_config();

$requiresubmissionstatement = !empty($adminconfig->requiresubmissionstatement) ||
$this->get_instance()->requiresubmissionstatement;

$draftsenabled = $this->get_instance()->submissiondrafts;

if ($requiresubmissionstatement && !$draftsenabled) {

$submissionstatement = '';
if (!empty($adminconfig->submissionstatement)) {
$submissionstatement = $adminconfig->submissionstatement;
}
$mform->addElement('checkbox', 'submissionstatement', '', '&nbsp;' . $submissionstatement);
$mform->addRule('submissionstatement', get_string('required'), 'required', null, 'client');
}

$this->add_plugin_submission_elements($submission, $mform, $data);

// hidden params
Expand Down
11 changes: 11 additions & 0 deletions mod/assign/mod_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ function definition() {
$assignment->set_course($DB->get_record('course', array('id'=>$this->current->course), '*', MUST_EXIST));
}

$config = get_config('assign');

$mform->addElement('header', 'general', get_string('settings', 'assign'));
$mform->addElement('date_time_selector', 'allowsubmissionsfromdate', get_string('allowsubmissionsfromdate', 'assign'), array('optional'=>true));
$mform->addHelpButton('allowsubmissionsfromdate', 'allowsubmissionsfromdate', 'assign');
Expand All @@ -89,6 +91,15 @@ function definition() {
$mform->addElement('selectyesno', 'submissiondrafts', get_string('submissiondrafts', 'assign'));
$mform->addHelpButton('submissiondrafts', 'submissiondrafts', 'assign');
$mform->setDefault('submissiondrafts', 0);
// submission statement
if (!empty($config->requiresubmissionstatement)) {
$mform->addElement('selectyesno', 'requiresubmissionstatement', get_string('requiresubmissionstatement', 'assign'));
$mform->setDefault('requiresubmissionstatement', !empty($config->submissionstatement));
$mform->addHelpButton('requiresubmissionstatement', 'requiresubmissionstatement', 'assign');
} else {
$mform->addElement('hidden', 'requiresubmissionstatement', 1);
}

$mform->addElement('selectyesno', 'sendnotifications', get_string('sendnotifications', 'assign'));
$mform->addHelpButton('sendnotifications', 'sendnotifications', 'assign');
$mform->setDefault('sendnotifications', 1);
Expand Down
5 changes: 4 additions & 1 deletion mod/assign/renderable.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,18 @@ class assign_submit_for_grading_page implements renderable {
var $notifications = array();
/** @var int $coursemoduleid */
var $coursemoduleid = 0;
/** @var moodleform $confirmform */
var $confirmform = null;

/**
* Constructor
* @param string $notifications - Any mesages to display
* @param int $coursemoduleid
*/
public function __construct($notifications, $coursemoduleid) {
public function __construct($notifications, $coursemoduleid, $confirmform) {
$this->notifications = $notifications;
$this->coursemoduleid = $coursemoduleid;
$this->confirmform = $confirmform;
}

}
Expand Down
7 changes: 2 additions & 5 deletions mod/assign/renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -168,11 +168,8 @@ public function render_assign_submit_for_grading_page($page) {

$o .= $this->output->continue_button($cancelurl);
} else {
// All submission plugins ready - confirm the student really does want to submit for marking
$continueurl = new moodle_url('/mod/assign/view.php', array('id' => $page->coursemoduleid,
'action' => 'confirmsubmit',
'sesskey' => sesskey()));
$o .= $this->output->confirm(get_string('confirmsubmission', 'mod_assign'), $continueurl, $cancelurl);
// All submission plugins ready - show the confirmation form (may contain submission statement)
$o .= $this->moodleform($page->confirmform);
}
$o .= $this->output->container_end();

Expand Down
Loading

0 comments on commit 94f2690

Please sign in to comment.