Permalink
Browse files

MDL-31341: Add custom completion rule to assignment: 'submit'

  • Loading branch information...
1 parent e4945f5 commit 79ed4d8475c79e8eefce33d114d4e27c6932efce Damyon Wiese committed Aug 16, 2012
@@ -55,7 +55,8 @@ protected function define_structure() {
'duedate',
'allowsubmissionsfromdate',
'grade',
- 'timemodified'));
+ 'timemodified',
+ 'completionsubmit'));
$submissions = new backup_nested_element('submissions');
@@ -21,7 +21,8 @@
<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"/>
+ <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"/>
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id" COMMENT="The unique id for this assignment instance."/>
@@ -64,6 +64,20 @@ function xmldb_assign_upgrade($oldversion) {
// Assign savepoint reached.
upgrade_mod_savepoint(true, 2012071800, 'assign');
}
+ if ($oldversion < 2012081600) {
+
+ // Define field sendlatenotifications to be added to assign
+ $table = new xmldb_table('assign');
+ $field = new xmldb_field('completionsubmit', XMLDB_TYPE_INTEGER, '2', null, XMLDB_NOTNULL, null, '0', 'timemodified');
+
+ // Conditionally launch add field sendlatenotifications
+ if (!$dbman->field_exists($table, $field)) {
+ $dbman->add_field($table, $field);
+ }
+
+ // Assign savepoint reached.
+ upgrade_mod_savepoint(true, 2012081600, 'assign');
+ }
return true;
}
@@ -66,6 +66,7 @@
$string['batchoperationunlock'] = 'unlock submissions';
$string['batchoperationreverttodraft'] = 'revert submissions to draft';
$string['comment'] = 'Comment';
+$string['completionsubmit'] = 'Student must submit to this activity to complete it';
$string['conversionexception'] = 'Could not convert assignment. Exception was: {$a}.';
$string['configshowrecentsubmissions'] = 'Everyone can see notifications of submissions in recent activity reports.';
$string['confirmsubmission'] = 'Are you sure you want to submit your work for grading? You will not be able to make any more changes';
View
@@ -83,6 +83,7 @@ function assign_supports($feature) {
case FEATURE_GROUPMEMBERSONLY: return true;
case FEATURE_MOD_INTRO: return true;
case FEATURE_COMPLETION_TRACKS_VIEWS: return true;
+ case FEATURE_COMPLETION_HAS_RULES: return true;
case FEATURE_GRADE_HAS_GRADE: return true;
case FEATURE_GRADE_OUTCOMES: return true;
case FEATURE_BACKUP_MOODLE2: return true;
@@ -936,3 +937,29 @@ function assign_user_outline($course, $user, $coursemodule, $assignment) {
return $result;
}
+
+/**
+ * Obtains the automatic completion state for this module based on any conditions
+ * in assign settings.
+ *
+ * @param object $course Course
+ * @param object $cm Course-module
+ * @param int $userid User ID
+ * @param bool $type Type of comparison (or/and; can be used as return value if no conditions)
+ * @return bool True if completed, false if not, $type if conditions not set.
+ */
+function assign_get_completion_state($course,$cm,$userid,$type) {
+ global $CFG,$DB;
+ require_once($CFG->dirroot . '/mod/assign/locallib.php');
+
+ $assign = new assign(null, $cm, $course);
+
+ // If completion option is enabled, evaluate it and return true/false
+ if($assign->get_instance()->completionsubmit) {
+ $submission = $DB->get_record('assign_submission', array('assignment'=>$assign->get_instance()->id, 'userid'=>$userid), '*', IGNORE_MISSING);
+ return $submission && $submission->status == ASSIGN_SUBMISSION_STATUS_SUBMITTED;
+ } else {
+ // Completion option is not enabled so just return $type
+ return $type;
+ }
+}
@@ -417,6 +417,7 @@ public function add_instance(stdClass $formdata, $callplugins) {
$update->duedate = $formdata->duedate;
$update->allowsubmissionsfromdate = $formdata->allowsubmissionsfromdate;
$update->grade = $formdata->grade;
+ $update->completionsubmit = $formdata->completionsubmit;
$returnid = $DB->insert_record('assign', $update);
$this->instance = $DB->get_record('assign', array('id'=>$returnid), '*', MUST_EXIST);
// cache the course record
@@ -636,6 +637,7 @@ public function update_instance($formdata) {
$update->duedate = $formdata->duedate;
$update->allowsubmissionsfromdate = $formdata->allowsubmissionsfromdate;
$update->grade = $formdata->grade;
+ $update->completionsubmit = $formdata->completionsubmit;
$result = $DB->update_record('assign', $update);
$this->instance = $DB->get_record('assign', array('id'=>$update->id), '*', MUST_EXIST);
@@ -2561,6 +2563,11 @@ private function process_submit_for_grading($mform) {
$submission->status = ASSIGN_SUBMISSION_STATUS_SUBMITTED;
$this->update_submission($submission);
+ $completion = new completion_info($this->get_course());
+ if ($completion->is_enabled($this->get_course_module()) && $this->get_instance()->completionsubmit) {
+ $completion->update_state($this->get_course_module(), COMPLETION_COMPLETE, $USER->id);
+ }
+
if (isset($data->submissionstatement)) {
$this->add_to_log('submission statement accepted', get_string('submissionstatementacceptedlog', 'mod_assign', fullname($USER)));
}
@@ -2838,6 +2845,15 @@ private function process_save_submission(&$mform) {
}
$this->add_to_log('submit', $this->format_submission_for_log($submission));
+ $complete = COMPLETION_INCOMPLETE;
+ if ($submission->status == ASSIGN_SUBMISSION_STATUS_SUBMITTED) {
+ $complete = COMPLETION_COMPLETE;
+ }
+ $completion = new completion_info($this->get_course());
+ if ($completion->is_enabled($this->get_course_module()) && $this->get_instance()->completionsubmit) {
+ $completion->update_state($this->get_course_module(), $complete, $USER->id);
+ }
+
if (!$this->get_instance()->submissiondrafts) {
$this->notify_student_submission_receipt($submission);
$this->notify_graders($submission);
@@ -3140,7 +3156,7 @@ public function add_submission_form_elements(MoodleQuickForm $mform, stdClass $d
* @return void
*/
private function process_revert_to_draft($userid = 0) {
- global $USER, $DB;
+ global $DB;
// Need grade permission
require_capability('mod/assign:grade', $this->context);
@@ -3163,6 +3179,10 @@ private function process_revert_to_draft($userid = 0) {
$user = $DB->get_record('user', array('id' => $userid), '*', MUST_EXIST);
+ $completion = new completion_info($this->get_course());
+ if ($completion->is_enabled($this->get_course_module()) && $this->get_instance()->completionsubmit) {
+ $completion->update_state($this->get_course_module(), COMPLETION_INCOMPLETE, $userid);
+ }
$this->add_to_log('revert submission to draft', get_string('reverttodraftforstudent', 'assign', array('id'=>$user->id, 'fullname'=>fullname($user))));
}
@@ -161,5 +161,15 @@ function data_preprocessing(&$defaultvalues) {
$assignment->plugin_data_preprocessing($defaultvalues);
}
+ function add_completion_rules() {
+ $mform =& $this->_form;
+
+ $mform->addElement('checkbox', 'completionsubmit', '', get_string('completionsubmit', 'assign'));
+ return array('completionsubmit');
+ }
+
+ function completion_rule_enabled($data) {
+ return !empty($data['completionsubmit']);
+ }
}
@@ -25,7 +25,7 @@
defined('MOODLE_INTERNAL') || die();
$module->component = 'mod_assign'; // Full name of the plugin (used for diagnostics)
-$module->version = 2012071800; // The current module version (Date: YYYYMMDDXX)
+$module->version = 2012081600; // The current module version (Date: YYYYMMDDXX)
$module->requires = 2012061700; // Requires this Moodle version
$module->cron = 60;

0 comments on commit 79ed4d8

Please sign in to comment.