diff --git a/ajax.php b/ajax.php
index 5f1a5ebd..ee8f86a0 100644
--- a/ajax.php
+++ b/ajax.php
@@ -870,6 +870,13 @@
if (($istutor && $submissionid != 0) ||
($USER->id == $turnitintooltwosubmission->userid && empty($turnitintooltwosubmission->submission_objectid))) {
$_SESSION["notice"] = $turnitintooltwosubmission->delete_submission();
+
+ // Update completion state
+ $course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST);
+ $completion = new completion_info($course);
+ if($completion->is_enabled($cm) && $turnitintooltwoassignment->turnitintooltwo->completionsubmit) {
+ $completion->update_state($cm,COMPLETION_INCOMPLETE, $turnitintooltwosubmission->userid);
+ }
}
exit();
break;
diff --git a/db/install.xml b/db/install.xml
index 265458fc..e191e1a1 100755
--- a/db/install.xml
+++ b/db/install.xml
@@ -16,8 +16,9 @@
-
-
+
+
+
diff --git a/db/upgrade.php b/db/upgrade.php
index 605b3f87..08f68f06 100755
--- a/db/upgrade.php
+++ b/db/upgrade.php
@@ -253,5 +253,13 @@ function xmldb_turnitintooltwo_upgrade($oldversion) {
}
}
+ if ($oldversion < 2018082802) {
+ $table = new xmldb_table('turnitintooltwo');
+ $field = new xmldb_field('completionsubmit', XMLDB_TYPE_INTEGER, '1', false, null, false, '0', 'portfolio');
+ if (!$dbman->field_exists($table, $field)) {
+ $dbman->add_field($table, $field);
+ }
+ }
+
return true;
}
\ No newline at end of file
diff --git a/lang/de/turnitintooltwo.php b/lang/de/turnitintooltwo.php
index c56ad404..9561a794 100644
--- a/lang/de/turnitintooltwo.php
+++ b/lang/de/turnitintooltwo.php
@@ -28,6 +28,9 @@
$string['ced'] = 'Enddatum für den Kurs';
$string['classcreationerror'] = 'Erstellen des Turnitin-Kurses fehlgeschlagen';
$string['classupdateerror'] = 'Daten des Turnitin-Kurses konnten nicht aktualisiert werden.';
+$string['completionsubmit'] = 'Teilnehmer/innen müssen ein oder mehrere Dokument hochladen um die Aufgabe abzuschließen';
+$string['completionsubmit_label'] = 'Abgabe notwendig';
+$string['completionsubmit_help'] = 'Die Aktivität wird als abgeschlossen betrachtet, wenn Teilnehmer/innen für alle Aufgabenteile ein Abgabe eingereicht haben.';
$string['configureerror'] = 'Sie müssen dieses Modul vollständig als Administrator konfigurieren, um es in einem Kurs benutzen zu können. Wenden Sie sich an Ihren Moodle-Administrator.';
$string['connecttest'] = 'Verbindung mit Turnitin testen';
$string['connecttestcommerror'] = 'Keine Verbindung mit Turnitin möglich. Überprüfen Sie Ihre API-URL-Einstellung.';
diff --git a/lang/en/turnitintooltwo.php b/lang/en/turnitintooltwo.php
index f3507840..16a554ab 100755
--- a/lang/en/turnitintooltwo.php
+++ b/lang/en/turnitintooltwo.php
@@ -28,6 +28,9 @@
$string['ced'] = 'Class End Date';
$string['classcreationerror'] = 'Turnitin Class creation failed';
$string['classupdateerror'] = 'Could not update Turnitin Class data';
+$string['completionsubmit'] = 'Student must submit to this activity to complete it';
+$string['completionsubmit_label'] = 'Require submission';
+$string['completionsubmit_help'] = 'The activity is considered complete when a student has successfully submitted a file(s) to all parts of the assignment.';
$string['configureerror'] = 'You must configure this module fully as Administrator before using it within a course. Please contact your Moodle administrator.';
$string['connecttest'] = 'Test Turnitin Connection';
$string['connecttestcommerror'] = 'Could not connect to Turnitin. Double check your API URL setting.';
diff --git a/lib.php b/lib.php
index b2a79eeb..1969f862 100755
--- a/lib.php
+++ b/lib.php
@@ -97,6 +97,7 @@ function turnitintooltwo_supports($feature) {
case FEATURE_GROUPMEMBERSONLY:
case FEATURE_MOD_INTRO:
case FEATURE_COMPLETION_TRACKS_VIEWS:
+ case FEATURE_COMPLETION_HAS_RULES:
case FEATURE_GRADE_HAS_GRADE:
case FEATURE_GRADE_OUTCOMES:
case FEATURE_BACKUP_MOODLE2:
@@ -1890,3 +1891,47 @@ function mod_turnitintooltwo_get_availability_status($data, $checkcapability = f
return array($open, $warnings);
}
+
+/**
+ * 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 turnitintooltwo_get_completion_state($course, $cm, $userid, $type) {
+ global $DB;
+
+ if (empty($turnitintooltwo = $DB->get_record("turnitintooltwo", array("id" => $cm->instance)))) {
+ throw new Exception("Can't find turnitintooltwo {$cm->instance}");
+ }
+
+ if($turnitintooltwo->completionsubmit == true) {
+ if (empty($turnitintooltwoassignment = new turnitintooltwo_assignment($turnitintooltwo->id, $turnitintooltwo))) {
+ return $type;
+ }
+
+ if (empty($parts = $turnitintooltwoassignment->get_parts())) {
+ return $type;
+ }
+
+ $result = $type;
+ $value = false;
+ $submissions = $turnitintooltwoassignment->get_user_submissions($userid, $turnitintooltwo->id);
+ if(!empty($submissions) && (count($submissions) == count($parts))){
+ $value = true;
+ }
+
+ if ($type == COMPLETION_AND) {
+ $result = $result && $value;
+ } else {
+ $result = $result || $value;
+ }
+ return $result;
+ } else {
+ return $type;
+ }
+}
\ No newline at end of file
diff --git a/mod_form.php b/mod_form.php
index bd03b22f..0a57a4f3 100755
--- a/mod_form.php
+++ b/mod_form.php
@@ -735,4 +735,28 @@ public static function populate_submitpapersto(stdClass $current) {
return $current;
}
+
+ /**
+ * Add any custom completion rules to the form.
+ *
+ * @return array Contains the names of the added form elements
+ */
+ public function add_completion_rules() {
+ $mform =& $this->_form;
+
+ $mform->addElement('advcheckbox', 'completionsubmit', get_string('completionsubmit_label', 'turnitintooltwo'), get_string('completionsubmit', 'turnitintooltwo'));
+ $mform->addHelpButton('completionsubmit', 'completionsubmit', 'turnitintooltwo');
+ $mform->setDefault('completionsubmit', 0);
+ return array('completionsubmit');
+ }
+
+ /**
+ * Determines if completion is enabled for this module.
+ *
+ * @param array $data
+ * @return bool
+ */
+ public function completion_rule_enabled($data) {
+ return !empty($data['completionsubmit']);
+ }
}
diff --git a/version.php b/version.php
index 54c95dca..c1697b5b 100644
--- a/version.php
+++ b/version.php
@@ -25,7 +25,7 @@
$plugin = new StdClass();
}
-$plugin->version = 2018082801;
+$plugin->version = 2018082802;
$plugin->release = "2.7+";
$plugin->requires = 2014051200;
$plugin->component = 'mod_turnitintooltwo';
diff --git a/view.php b/view.php
index 5d713621..96cbe564 100755
--- a/view.php
+++ b/view.php
@@ -357,6 +357,12 @@
}
$DB->update_record('turnitintooltwo_parts', $lockedpart);
+
+ // Update completion state
+ $completion = new completion_info($course);
+ if($completion->is_enabled($cm) && $turnitintooltwoassignment->turnitintooltwo->completionsubmit) {
+ $completion->update_state($cm,COMPLETION_COMPLETE, $post['studentsname']);
+ }
} else {
$do = "submission_failure";
}