Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds completion state for submissions #480

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions ajax.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 3 additions & 2 deletions db/install.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@
<FIELD NAME="defaultdtdue" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="false" DEFAULT="0" SEQUENCE="false" PREVIOUS="defaultdtstart" NEXT="defaultdtpost"/>
<FIELD NAME="defaultdtpost" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="false" DEFAULT="0" SEQUENCE="false" PREVIOUS="defaultdtdue" NEXT="anon"/>
<FIELD NAME="anon" TYPE="int" LENGTH="1" NOTNULL="false" UNSIGNED="false" DEFAULT="0" SEQUENCE="false" PREVIOUS="defaultdtpost" NEXT="submitted"/>
<FIELD NAME="submitted" TYPE="int" LENGTH="1" NOTNULL="false" UNSIGNED="false" DEFAULT="0" SEQUENCE="false" PREVIOUS="anon" NEXT="portfolio"/>
<FIELD NAME="portfolio" TYPE="int" LENGTH="1" NOTNULL="false" UNSIGNED="false" DEFAULT="0" SEQUENCE="false" PREVIOUS="submitted" NEXT="allowlate"/>
<FIELD NAME="submitted" TYPE="int" LENGTH="1" NOTNULL="false" UNSIGNED="false" DEFAULT="0" SEQUENCE="false" PREVIOUS="anon" NEXT="completionsubmit"/>
<FIELD NAME="completionsubmit" TYPE="int" LENGTH="2" NOTNULL="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="submitted" NEXT="portfolio"/>
<FIELD NAME="portfolio" TYPE="int" LENGTH="1" NOTNULL="false" UNSIGNED="false" DEFAULT="0" SEQUENCE="false" PREVIOUS="completionsubmit" NEXT="allowlate"/>
<FIELD NAME="allowlate" TYPE="int" LENGTH="1" NOTNULL="true" UNSIGNED="false" DEFAULT="0" SEQUENCE="false" PREVIOUS="portfolio" NEXT="reportgenspeed"/>
<FIELD NAME="reportgenspeed" TYPE="int" LENGTH="1" NOTNULL="true" UNSIGNED="false" DEFAULT="0" SEQUENCE="false" PREVIOUS="allowlate" NEXT="submitpapersto"/>
<FIELD NAME="submitpapersto" TYPE="int" LENGTH="1" NOTNULL="true" UNSIGNED="false" DEFAULT="0" SEQUENCE="false" PREVIOUS="reportgenspeed" NEXT="spapercheck"/>
Expand Down
8 changes: 8 additions & 0 deletions db/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
3 changes: 3 additions & 0 deletions lang/de/turnitintooltwo.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.';
Expand Down
3 changes: 3 additions & 0 deletions lang/en/turnitintooltwo.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.';
Expand Down
45 changes: 45 additions & 0 deletions lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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;
}
}
24 changes: 24 additions & 0 deletions mod_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
}
}
2 changes: 1 addition & 1 deletion version.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
$plugin = new StdClass();
}

$plugin->version = 2018082801;
$plugin->version = 2018082802;
$plugin->release = "2.7+";
$plugin->requires = 2014051200;
$plugin->component = 'mod_turnitintooltwo';
Expand Down
6 changes: 6 additions & 0 deletions view.php
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
Expand Down