'duedate',
'allowsubmissionsfromdate',
'grade',
- 'timemodified'));
+ 'timemodified',
+ 'completionsubmit'));
$submissions = new backup_nested_element('submissions');
<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."/>
// 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;
}
$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';
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;
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;
+ }
+}
$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
$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);
$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)));
}
}
$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);
* @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);
$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))));
}
$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']);
+ }
}
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;