From c8c6518d1d47976bc78ec49d471078adcd8a8aa3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luca=20B=C3=B6sch?= Date: Thu, 25 Jul 2024 13:35:40 +0200 Subject: [PATCH 01/15] Using ${var} in strings is deprecated, use {$var} instead. --- tests/behat/behat_plagiarism_turnitin.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/behat/behat_plagiarism_turnitin.php b/tests/behat/behat_plagiarism_turnitin.php index 01e95f1d..b113a7c7 100644 --- a/tests/behat/behat_plagiarism_turnitin.php +++ b/tests/behat/behat_plagiarism_turnitin.php @@ -71,8 +71,8 @@ public function i_configure_turnitin_url() { $apiurl = getenv('TII_APIBASEURL'); $javascript = " var option = document.createElement('option'); - option.setAttribute('value', '${apiurl}'); - var apiurl = document.createTextNode('${apiurl}'); + option.setAttribute('value', '{$apiurl}'); + var apiurl = document.createTextNode('{$apiurl}'); var select = document.querySelector('#id_plagiarism_turnitin_apiurl'); option.appendChild(apiurl); select.appendChild(option); From 774f2dd8d33138d6adfb088fbba4272545c9b291 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luca=20B=C3=B6sch?= Date: Thu, 25 Jul 2024 13:40:18 +0200 Subject: [PATCH 02/15] Fix 'Short array syntax must be used to define arrays' warnings. --- ajax.php | 44 +- ...ackup_plagiarism_turnitin_plugin.class.php | 18 +- ...store_plagiarism_turnitin_plugin.class.php | 12 +- .../turnitin_defaultsettingsform.class.php | 2 +- classes/forms/turnitin_form.class.php | 6 +- classes/forms/turnitin_setupform.class.php | 46 +- classes/modules/turnitin_assign.class.php | 12 +- classes/modules/turnitin_coursework.class.php | 8 +- classes/modules/turnitin_forum.class.php | 4 +- classes/modules/turnitin_quiz.class.php | 2 +- classes/modules/turnitin_workshop.class.php | 4 +- classes/observer.php | 4 +- classes/privacy/provider.php | 2 +- classes/turnitin_assignment.class.php | 16 +- classes/turnitin_class.class.php | 4 +- classes/turnitin_comms.class.php | 14 +- classes/turnitin_submission.class.php | 42 +- classes/turnitin_user.class.php | 40 +- classes/turnitin_view.class.php | 140 ++++-- db/access.php | 20 +- db/events.php | 44 +- db/messages.php | 8 +- db/tasks.php | 12 +- db/upgrade.php | 52 +-- dbexport.php | 8 +- extras.php | 8 +- lib.php | 402 ++++++++++-------- locallib.php | 6 +- settings.php | 44 +- tests/behat/behat_plagiarism_turnitin.php | 28 +- .../turnitin_assignment_class_test.php | 18 +- tests/classes/turnitin_user_class_test.php | 6 +- tests/generator/lib.php | 4 +- tests/lib_test.php | 32 +- tests/modules/turnitin_assign_test.php | 8 +- tests/modules/turnitin_forum_test.php | 8 +- tests/privacy/provider_test.php | 8 +- 37 files changed, 617 insertions(+), 519 deletions(-) diff --git a/ajax.php b/ajax.php index 7187a1f0..1ea6feb9 100644 --- a/ajax.php +++ b/ajax.php @@ -45,7 +45,7 @@ $pathnamehash = optional_param('pathnamehash', "", PARAM_ALPHANUM); $submissiontype = optional_param('submission_type', "", PARAM_ALPHAEXT); -$return = array(); +$return = []; // Initialise plugin class. $pluginturnitin = new plagiarism_plugin_turnitin(); @@ -79,7 +79,7 @@ $userrole, '' ), - array('style' => 'display: none') + ['style' => 'display: none'] ); } break; @@ -102,7 +102,7 @@ // If we have a turnitin timestamp stored then update it, otherwise create it. if ($timestampid = $DB->get_record('plagiarism_turnitin_config', - array('cm' => $cm->id, 'name' => 'grades_last_synced'), 'id')) { + ['cm' => $cm->id, 'name' => 'grades_last_synced'], 'id')) { $moduleconfigvalue->id = $timestampid->id; $DB->update_record('plagiarism_turnitin_config', $moduleconfigvalue); } else { @@ -122,7 +122,7 @@ throw new moodle_exception('invalidsesskey', 'error'); } - $tiiassignment = $DB->get_record('plagiarism_turnitin_config', array('cm' => $cm->id, 'name' => 'turnitin_assignid')); + $tiiassignment = $DB->get_record('plagiarism_turnitin_config', ['cm' => $cm->id, 'name' => 'turnitin_assignid']); $pluginturnitin->refresh_peermark_assignments($cm, $tiiassignment->value); break; @@ -132,7 +132,7 @@ $plagiarismpluginturnitin = new plagiarism_plugin_turnitin(); $coursedata = $plagiarismpluginturnitin->get_course_data($cm->id, $cm->course); - $tiiassignment = $DB->get_record('plagiarism_turnitin_config', array('cm' => $cm->id, 'name' => 'turnitin_assignid')); + $tiiassignment = $DB->get_record('plagiarism_turnitin_config', ['cm' => $cm->id, 'name' => 'turnitin_assignid']); if ($tiiassignment) { $tiiassignmentid = $tiiassignment->value; @@ -148,10 +148,10 @@ echo html_writer::tag( 'div', turnitin_view::output_lti_form_launch('peermark_manager', 'Instructor', $tiiassignmentid), - array( + [ 'class' => 'launch_form', 'style' => 'display:none;' - ) + ] ); echo html_writer::script(""); @@ -66,7 +66,7 @@ $PAGE->set_pagelayout('embedded'); echo html_writer::tag("div", $turnitinview->output_lti_form_launch('quickmark_manager', 'Instructor'), - array("class" => "launch_form")); + ["class" => "launch_form"]); echo html_writer::script(""); @@ -97,7 +97,7 @@ // Build page. echo $turnitinview->output_header($_SERVER["REQUEST_URI"]); -echo html_writer::tag("div", $viewcontext, array("id" => "tii_view_context")); +echo html_writer::tag("div", $viewcontext, ["id" => "tii_view_context"]); echo $output; diff --git a/lib.php b/lib.php index aeae0074..e6f52247 100755 --- a/lib.php +++ b/lib.php @@ -55,9 +55,9 @@ // Define accepted files if the module is not accepting any file type. global $turnitinacceptedfiles; -$turnitinacceptedfiles = array('.doc', '.docx', '.ppt', '.pptx', '.pps', '.ppsx', +$turnitinacceptedfiles = ['.doc', '.docx', '.ppt', '.pptx', '.pps', '.ppsx', '.pdf', '.txt', '.htm', '.html', '.hwp', '.odt', - '.wpd', '.ps', '.rtf', '.xls', '.xlsx'); + '.wpd', '.ps', '.rtf', '.xls', '.xlsx']; require_once($CFG->libdir.'/gradelib.php'); @@ -97,11 +97,11 @@ class plagiarism_plugin_turnitin extends plagiarism_plugin { * @return array of settings fields. */ public function get_settings_fields() { - return array('use_turnitin', 'plagiarism_show_student_report', 'plagiarism_draft_submit', + return ['use_turnitin', 'plagiarism_show_student_report', 'plagiarism_draft_submit', 'plagiarism_allow_non_or_submissions', 'plagiarism_submitpapersto', 'plagiarism_compare_student_papers', 'plagiarism_compare_internet', 'plagiarism_compare_journals', 'plagiarism_report_gen', 'plagiarism_compare_institution', 'plagiarism_exclude_biblio', 'plagiarism_exclude_quoted', - 'plagiarism_exclude_matches', 'plagiarism_exclude_matches_value', 'plagiarism_rubric', 'plagiarism_transmatch'); + 'plagiarism_exclude_matches', 'plagiarism_exclude_matches_value', 'plagiarism_rubric', 'plagiarism_transmatch']; } /** @@ -131,8 +131,8 @@ public static function plagiarism_turnitin_admin_config() { */ public function get_settings($cmid = null, $uselockedvalues = true) { global $DB; - $defaults = $DB->get_records_menu('plagiarism_turnitin_config', array('cm' => null), '', 'name,value'); - $settings = $DB->get_records_menu('plagiarism_turnitin_config', array('cm' => $cmid), '', 'name,value'); + $defaults = $DB->get_records_menu('plagiarism_turnitin_config', ['cm' => null], '', 'name,value'); + $settings = $DB->get_records_menu('plagiarism_turnitin_config', ['cm' => $cmid], '', 'name,value'); // Don't overwrite settings with locked values (only relevant on inital module creation). if ($uselockedvalues == false) { @@ -183,7 +183,20 @@ public function get_file_upload_errors($offset = 0, $limit = 0, $count = false) if ($count) { return $DB->count_records_sql($countsql); } - return $DB->get_records_sql($selectsql, array(), $offset, $limit); + return $DB->get_records_sql($selectsql, [], $offset, $limit); + } + + /** + * This function is called from the inbox in mod assign. + * This will alert the user to refresh the assignment when there has been a change in scores. + * + * @param $course - Course the module is part of + * @param $cm - Course module + * @return string + */ + public function update_status($course, $cm) { + return html_writer::div(get_string('turnitin_score_refresh_alert', 'plagiarism_turnitin'), + 'turnitin_score_refresh_alert', ['id' => 'turnitin_score_refresh_alert']); } /** @@ -229,7 +242,7 @@ public function save_form_data($data) { if (isset($plagiarismvalues[$field])) { $optionfield->id = $DB->get_field('plagiarism_turnitin_config', 'id', - (array('cm' => $data->coursemodule, 'name' => $field))); + (['cm' => $data->coursemodule, 'name' => $field])); if (!$DB->update_record('plagiarism_turnitin_config', $optionfield)) { plagiarism_turnitin_print_error('defaultupdateerror', 'plagiarism_turnitin', null, null, __FILE__, __LINE__); } @@ -312,7 +325,7 @@ public function add_settings_form_to_activity_page($mform, $context, $modulename // Check if files have already been submitted and disable exclude biblio and quoted if turnitin is enabled. if ($cmid != 0) { - if ($DB->record_exists('plagiarism_turnitin_files', array('cm' => $cmid))) { + if ($DB->record_exists('plagiarism_turnitin_files', ['cm' => $cmid])) { $mform->disabledIf('plagiarism_exclude_biblio', 'use_turnitin'); $mform->disabledIf('plagiarism_exclude_quoted', 'use_turnitin'); } @@ -354,9 +367,9 @@ public static function course_reset($eventdata) { } // Get the modules that support the Plagiarism plugin by whether they have a class file. - $supportedmods = array(); + $supportedmods = []; foreach (scandir($CFG->dirroot.'/plagiarism/turnitin/classes/modules/') as $filename) { - if (!in_array($filename, array(".", ".."))) { + if (!in_array($filename, [".", ".."])) { $filenamear = explode('.', $filename); $classnamear = explode('_', $filenamear[0]); // Split the class name. $supportedmods[] = $classnamear[1]; // Set the module name. @@ -364,7 +377,7 @@ public static function course_reset($eventdata) { } foreach ($supportedmods as $supportedmod) { - $module = $DB->get_record('modules', array('name' => $supportedmod)); + $module = $DB->get_record('modules', ['name' => $supportedmod]); if ($module === false) { continue; } @@ -376,7 +389,7 @@ public static function course_reset($eventdata) { WHERE cm.module = :moduleid AND cm.course = :courseid AND ptc.name = 'turnitin_assignid'"; - $params = array('courseid' => $courseid, 'moduleid' => $module->id); + $params = ['courseid' => $courseid, 'moduleid' => $module->id]; $modules = $DB->get_records_sql($sql, $params); if (count($modules) > 0) { @@ -384,8 +397,8 @@ public static function course_reset($eventdata) { if (!empty($$reset)) { // Remove Plagiarism plugin submissions and assignment id from DB for this module. foreach ($modules as $mod) { - $DB->delete_records('plagiarism_turnitin_files', array('cm' => $mod->id)); - $DB->delete_records('plagiarism_turnitin_config', array('cm' => $mod->id, 'name' => 'turnitin_assignid')); + $DB->delete_records('plagiarism_turnitin_files', ['cm' => $mod->id]); + $DB->delete_records('plagiarism_turnitin_config', ['cm' => $mod->id, 'name' => 'turnitin_assignid']); } } else { $resetcourse = false; @@ -396,7 +409,7 @@ public static function course_reset($eventdata) { // If all turnitin enabled modules for this course have been reset. // then remove the Turnitin course id from the database. if ($resetcourse) { - $DB->delete_records('plagiarism_turnitin_courses', array('courseid' => $courseid)); + $DB->delete_records('plagiarism_turnitin_courses', ['courseid' => $courseid]); } return true; @@ -462,18 +475,18 @@ public function print_disclosure($cmid) { // Show resubmission warning - but not for mod forum. if ($cm->modname != 'forum') { - $tiisubmissions = $DB->get_records('plagiarism_turnitin_files', array('userid' => $USER->id, 'cm' => $cm->id)); + $tiisubmissions = $DB->get_records('plagiarism_turnitin_files', ['userid' => $USER->id, 'cm' => $cm->id]); $tiisubmissions = current($tiisubmissions); if ($tiisubmissions) { $genparams = $this->plagiarism_get_report_gen_speed_params(); - $output .= html_writer::tag('div', get_string('reportgenspeed_resubmission', 'plagiarism_turnitin', $genparams), array('class' => 'tii_genspeednote')); + $output .= html_writer::tag('div', get_string('reportgenspeed_resubmission', 'plagiarism_turnitin', $genparams), ['class' => 'tii_genspeednote']); } } // Show agreement. if (!empty($config->plagiarism_turnitin_agreement)) { - $contents = format_text($config->plagiarism_turnitin_agreement, FORMAT_MOODLE, array("noclean" => true)); + $contents = format_text($config->plagiarism_turnitin_agreement, FORMAT_MOODLE, ["noclean" => true]); $output .= $OUTPUT->box($contents, 'generalbox boxaligncenter', 'intro'); } @@ -496,11 +509,11 @@ public function print_disclosure($cmid) { if ($eulaaccepted != 1) { $eulalink = html_writer::tag('span', get_string('turnitinppulapre', 'plagiarism_turnitin'), - array('class' => 'pp_turnitin_eula_link tii_tooltip', 'id' => 'rubric_manager_form') + ['class' => 'pp_turnitin_eula_link tii_tooltip', 'id' => 'rubric_manager_form'] ); $eulaignoredclass = ($eulaaccepted == 0) ? ' pp_turnitin_eula_ignored' : ''; - $eula = html_writer::tag('div', $eulalink, array('class' => 'pp_turnitin_eula'.$eulaignoredclass, - 'data-userid' => $user->id)); + $eula = html_writer::tag('div', $eulalink, ['class' => 'pp_turnitin_eula'.$eulaignoredclass, + 'data-userid' => $user->id]); $form = turnitin_view::output_launch_form( "useragreement", @@ -512,7 +525,7 @@ public function print_disclosure($cmid) { ); $form .= " ".get_string('noscriptula', 'plagiarism_turnitin'); - $noscripteula = html_writer::tag('noscript', $form, array('class' => 'warning turnitin_ula_noscript')); + $noscripteula = html_writer::tag('noscript', $form, ['class' => 'warning turnitin_ula_noscript']); } // Show EULA launcher and form placeholder. @@ -522,11 +535,11 @@ public function print_disclosure($cmid) { $turnitincomms = new turnitin_comms(); $turnitincall = $turnitincomms->initialise_api(); - $customdata = array("disable_form_change_checker" => true, - "elements" => array(array('html', $OUTPUT->box('', '', 'useragreement_inputs')))); + $customdata = ["disable_form_change_checker" => true, + "elements" => [['html', $OUTPUT->box('', '', 'useragreement_inputs')]]]; $eulaform = new turnitin_form($turnitincall->getApiBaseUrl().TiiLTI::EULAENDPOINT, $customdata, - 'POST', $target = 'eulaWindow', array('id' => 'eula_launch')); + 'POST', $target = 'eulaWindow', ['id' => 'eula_launch']); $output .= $OUTPUT->box($eulaform->display(), 'tii_useragreement_form', 'useragreement_form'); } } @@ -538,16 +551,16 @@ public function print_disclosure($cmid) { $rubricviewlink = html_writer::tag('span', get_string('launchrubricview', 'plagiarism_turnitin'), - array('class' => 'rubric_view rubric_view_pp_launch_upload tii_tooltip', + ['class' => 'rubric_view rubric_view_pp_launch_upload tii_tooltip', 'data-courseid' => $cm->course, 'data-cmid' => $cm->id, 'title' => get_string('launchrubricview', 'plagiarism_turnitin'), 'id' => 'rubric_manager_form' - ) + ] ); - $rubricviewlink = html_writer::tag('div', $rubricviewlink, array('class' => 'row_rubric_view')); + $rubricviewlink = html_writer::tag('div', $rubricviewlink, ['class' => 'row_rubric_view']); - $output .= html_writer::tag('div', $rubricviewlink, array('class' => 'tii_links_container tii_disclosure_links')); + $output .= html_writer::tag('div', $rubricviewlink, ['class' => 'tii_links_container tii_disclosure_links']); } return $output; @@ -634,7 +647,7 @@ public function get_links($linkarray) { if (!empty($linkarray["file"])) { $file = $linkarray["file"]; $filearea = $file->get_filearea(); - $nonsubmittingareas = array("feedback_files", "introattachment"); + $nonsubmittingareas = ["feedback_files", "introattachment"]; if (in_array($filearea, $nonsubmittingareas)) { return $output; } @@ -665,7 +678,7 @@ public function get_links($linkarray) { $cm = get_coursemodule_from_id('', $linkarray["cmid"]); if ($cm->modname == 'forum') { - if (! $forum = $DB->get_record("forum", array("id" => $cm->instance))) { + if (! $forum = $DB->get_record("forum", ["id" => $cm->instance])) { print_error('invalidforumid', 'forum'); } } @@ -695,7 +708,7 @@ public function get_links($linkarray) { static $moduledata; if (empty($moduledata)) { - $moduledata = $DB->get_record($cm->modname, array('id' => $cm->instance)); + $moduledata = $DB->get_record($cm->modname, ['id' => $cm->instance]); } static $context; @@ -766,7 +779,7 @@ public function get_links($linkarray) { To get around this, we get the group ID, get the group members and set the author as the first student in the group. */ $plagiarismfile = null; - $moodlesubmission = $DB->get_record('assign_submission', array('id' => $itemid), 'id, groupid'); + $moodlesubmission = $DB->get_record('assign_submission', ['id' => $itemid], 'id, groupid'); if ((!empty($moodlesubmission->groupid)) && ($cm->modname == "assign")) { $plagiarismfiles = $DB->get_records('plagiarism_turnitin_files', ['itemid' => $itemid, 'cm' => $cm->id, 'identifier' => $identifier], 'lastmodified DESC', '*', 0, 1); @@ -823,14 +836,14 @@ public function get_links($linkarray) { $turnitincomms = new turnitin_comms(); $turnitincall = $turnitincomms->initialise_api(); - $customdata = array("disable_form_change_checker" => true, - "elements" => array(array('html', $OUTPUT->box('', '', 'useragreement_inputs')))); + $customdata = ["disable_form_change_checker" => true, + "elements" => [['html', $OUTPUT->box('', '', 'useragreement_inputs')]]]; $eulaform = new turnitin_form( $turnitincall->getApiBaseUrl().TiiLTI::EULAENDPOINT, $customdata, 'POST', $target = 'eulaWindow', - array('id' => 'eula_launch') + ['id' => 'eula_launch'] ); $output .= $OUTPUT->box($eulaform->display(), 'tii_useragreement_form', 'useragreement_form'); $eulashown = true; @@ -842,7 +855,7 @@ public function get_links($linkarray) { // Check whether submission is a group submission - only applicable to assignment and coursework module. // If it's a group submission then other users in the group should be able to see the originality score // They can not open the DV though. - $submissionusers = array($linkarray["userid"]); + $submissionusers = [$linkarray["userid"]]; switch ($cm->modname) { case "assign": if ($moduledata->teamsubmission) { @@ -858,7 +871,7 @@ public function get_links($linkarray) { if ($moduledata->use_groups) { $coursework = new \mod_coursework\models\coursework($moduledata->id); - $user = $DB->get_record('user', array('id' => $linkarray["userid"])); + $user = $DB->get_record('user', ['id' => $linkarray["userid"]]); $user = mod_coursework\models\user::find($user); if ($group = $coursework->get_student_group($user)) { $users = groups_get_members($group->id); @@ -877,19 +890,19 @@ public function get_links($linkarray) { // Get turnitin file details. if (is_null($plagiarismfile)) { - $plagiarismfiles = $DB->get_records('plagiarism_turnitin_files', array('userid' => $linkarray["userid"], - 'cm' => $linkarray["cmid"], 'identifier' => $identifier), + $plagiarismfiles = $DB->get_records('plagiarism_turnitin_files', ['userid' => $linkarray["userid"], + 'cm' => $linkarray["cmid"], 'identifier' => $identifier], 'lastmodified DESC', '*', 0, 1); $plagiarismfile = current($plagiarismfiles); } // Populate gradeitem query. - $gradeitemqueryarray = array( + $gradeitemqueryarray = [ 'iteminstance' => $cm->instance, 'itemmodule' => $cm->modname, 'courseid' => $cm->course, 'itemnumber' => 0 - ); + ]; // Get grade item and work out whether grades have been released for viewing. $gradesreleased = true; @@ -907,11 +920,11 @@ public function get_links($linkarray) { if ($cm->modname == 'assign' && !empty($moduledata->markingworkflow)) { $gradesreleased = $DB->record_exists( 'assign_user_flags', - array( + [ 'userid' => $linkarray["userid"], 'assignment' => $cm->instance, 'workflowstate' => 'released' - )); + ]); } } @@ -928,9 +941,9 @@ public function get_links($linkarray) { $output .= html_writer::tag('div', $OUTPUT->pix_icon('turnitin-icon', get_string('turnitinid', 'plagiarism_turnitin').': '.$plagiarismfile->externalid, - 'plagiarism_turnitin', array('class' => 'icon_size')). + 'plagiarism_turnitin', ['class' => 'icon_size']). get_string('turnitinid', 'plagiarism_turnitin').': '.$plagiarismfile->externalid, - array('class' => 'turnitin_status')); + ['class' => 'turnitin_status']); } // Show Originality Report score and link. @@ -939,8 +952,8 @@ public function get_links($linkarray) { // Show score. if ($plagiarismfile->statuscode == "pending") { - $orscorehtml = html_writer::tag('div', ' ', array('title' => get_string('pending', 'plagiarism_turnitin'), - 'class' => 'tii_tooltip origreport_score score_colour score_colour_')); + $orscorehtml = html_writer::tag('div', ' ', ['title' => get_string('pending', 'plagiarism_turnitin'), + 'class' => 'tii_tooltip origreport_score score_colour score_colour_']); } else { // Put EN flag if translated matching is on and that is the score used. $transmatch = ($plagiarismfile->transmatch == 1) ? ' EN' : ''; @@ -960,15 +973,15 @@ public function get_links($linkarray) { } $orscorehtml = html_writer::tag('div', $score.$transmatch, - array('title' => $titlescore, 'class' => 'tii_tooltip origreport_score score_colour '.$class)); + ['title' => $titlescore, 'class' => 'tii_tooltip origreport_score score_colour '.$class]); } // Put in div placeholder for DV launch form. - $orscorehtml .= html_writer::tag('div', '', array('class' => 'launch_form origreport_form_'.$plagiarismfile->externalid)); + $orscorehtml .= html_writer::tag('div', '', ['class' => 'launch_form origreport_form_'.$plagiarismfile->externalid]); // Add url for launching DV from Forum post. if ($cm->modname == 'forum') { $orscorehtml .= html_writer::tag('div', $CFG->wwwroot.'/plagiarism/turnitin/extras.php?cmid='.$linkarray["cmid"], - array('class' => 'origreport_forum_launch origreport_forum_launch_'.$plagiarismfile->externalid)); + ['class' => 'origreport_forum_launch origreport_forum_launch_'.$plagiarismfile->externalid]); } // This class is applied so that only the user who submitted or a tutor can open the DV. @@ -976,15 +989,15 @@ public function get_links($linkarray) { // Output container for OR Score. $ordivclass = 'row_score pp_origreport '.$useropenclass.' origreport_'.$plagiarismfile->externalid.'_'.$linkarray["cmid"]; - $output .= html_writer::tag('div', $orscorehtml, array('class' => $ordivclass, 'tabindex' => '0', 'role' => 'link')); + $output .= html_writer::tag('div', $orscorehtml, ['class' => $ordivclass, 'tabindex' => '0', 'role' => 'link']); } if (($plagiarismfile->orcapable == 0 && !is_null($plagiarismfile->orcapable))) { - $notorlink = html_writer::tag('div', 'x', array('title' => get_string('notorcapable', 'plagiarism_turnitin'), - 'class' => 'tii_tooltip score_colour score_colour_ score_no_orcapable')); + $notorlink = html_writer::tag('div', 'x', ['title' => get_string('notorcapable', 'plagiarism_turnitin'), + 'class' => 'tii_tooltip score_colour score_colour_ score_no_orcapable']); // This class is applied so that only the user who submitted or a tutor can open the DV. $useropenclass = ($USER->id == $linkarray["userid"] || $istutor) ? 'pp_origreport_open' : ''; - $output .= html_writer::tag('div', $notorlink, array('class' => 'row_score pp_origreport '.$useropenclass)); + $output .= html_writer::tag('div', $notorlink, ['class' => 'row_score pp_origreport '.$useropenclass]); } // Check if blind marking is on and revealidentities is not set yet. @@ -1007,14 +1020,14 @@ public function get_links($linkarray) { // Output grademark icon. $gmicon = html_writer::tag('div', $OUTPUT->pix_icon('icon-edit', get_string('grademark', 'plagiarism_turnitin'), 'plagiarism_turnitin'), - array('title' => get_string('grademark', 'plagiarism_turnitin'), + ['title' => get_string('grademark', 'plagiarism_turnitin'), 'class' => 'pp_grademark_open tii_tooltip grademark_'.$plagiarismfile->externalid. '_'.$linkarray["cmid"], 'tabindex' => '0', 'role' => 'link' - )); + ]); // Put in div placeholder for DV launch form. - $gmicon .= html_writer::tag('div', '', array('class' => 'launch_form grademark_form_'.$plagiarismfile->externalid)); - $output .= html_writer::tag('div', $gmicon, array('class' => 'grade_icon')); + $gmicon .= html_writer::tag('div', '', ['class' => 'launch_form grademark_form_'.$plagiarismfile->externalid]); + $output .= html_writer::tag('div', $gmicon, ['class' => 'grade_icon']); } // Indicate whether student has viewed the feedback. @@ -1031,7 +1044,7 @@ public function get_links($linkarray) { 'plagiarism_turnitin'); } } - $output .= html_writer::tag('div', $readicon, array('class' => 'student_read_icon')); + $output .= html_writer::tag('div', $readicon, ['class' => 'student_read_icon']); } // Show link to view rubric for student. @@ -1040,14 +1053,14 @@ public function get_links($linkarray) { $this->sync_tii_assignment($cm, $coursedata->turnitin_cid); $rubricviewlink = html_writer::tag('span', '', - array('class' => 'rubric_view rubric_view_pp_launch tii_tooltip', + ['class' => 'rubric_view rubric_view_pp_launch tii_tooltip', 'data-courseid' => $cm->course, 'data-cmid' => $cm->id, 'title' => get_string('launchrubricview', 'plagiarism_turnitin'), 'id' => 'rubric_view_launch' - ) + ] ); - $rubricviewlink = html_writer::tag('div', $rubricviewlink, array('class' => 'row_rubric_view')); + $rubricviewlink = html_writer::tag('div', $rubricviewlink, ['class' => 'row_rubric_view']); $output .= $rubricviewlink; } @@ -1078,10 +1091,10 @@ public function get_links($linkarray) { if (($istutor && count($_SESSION["peermark_assignments"][$cm->id]) > 0) || (!$istutor && $peermarksactive)) { $peermarkreviewslink = html_writer::tag('span', '', - array('title' => get_string('launchpeermarkreviews', 'plagiarism_turnitin'), - 'class' => 'peermark_reviews_pp_launch tii_tooltip', 'id' => 'peermark_reviews_form') + ['title' => get_string('launchpeermarkreviews', 'plagiarism_turnitin'), + 'class' => 'peermark_reviews_pp_launch tii_tooltip', 'id' => 'peermark_reviews_form'] ); - $output .= html_writer::tag('div', $peermarkreviewslink, array('class' => 'row_peermark_reviews')); + $output .= html_writer::tag('div', $peermarkreviewslink, ['class' => 'row_peermark_reviews']); } } @@ -1105,41 +1118,41 @@ public function get_links($linkarray) { $errorstring = get_string( 'errorcode'.$plagiarismfile->errorcode, 'plagiarism_turnitin', - array( + [ 'maxfilesize' => display_size(PLAGIARISM_TURNITIN_MAX_FILE_UPLOAD_SIZE), 'externalid' => $plagiarismfile->externalid - )); + ]); } $erroricon = html_writer::tag('div', $OUTPUT->pix_icon('x-red', $errorstring, 'plagiarism_turnitin'), - array('title' => $errorstring, - 'class' => 'tii_tooltip tii_error_icon')); + ['title' => $errorstring, + 'class' => 'tii_tooltip tii_error_icon']); // Attach error text or resubmit link after icon depending on whether user is a student/teacher. // Don't attach resubmit link if the user has not accepted the EULA. if (!$istutor) { - $output .= html_writer::tag('div', $erroricon.' '.$errorstring, array('class' => 'warning clear')); + $output .= html_writer::tag('div', $erroricon.' '.$errorstring, ['class' => 'warning clear']); } else if ($errorcode == 3) { - $output .= html_writer::tag('div', $erroricon, array('class' => 'clear')); + $output .= html_writer::tag('div', $erroricon, ['class' => 'clear']); } else { $output .= html_writer::tag('div', $erroricon.' '.get_string('resubmittoturnitin', 'plagiarism_turnitin'), - array('class' => 'clear plagiarism_turnitin_resubmit_link', - 'id' => 'pp_resubmit_'.$plagiarismfile->id)); + ['class' => 'clear plagiarism_turnitin_resubmit_link', + 'id' => 'pp_resubmit_'.$plagiarismfile->id]); $output .= html_writer::tag('div', $OUTPUT->pix_icon('loading', $errorstring, 'plagiarism_turnitin').' '. get_string('resubmitting', 'plagiarism_turnitin'), - array('class' => 'pp_resubmitting hidden')); + ['class' => 'pp_resubmitting hidden']); // Pending status for after resubmission. $statusstr = get_string('turnitinstatus', 'plagiarism_turnitin').': '.get_string('pending', 'plagiarism_turnitin'); - $output .= html_writer::tag('div', $OUTPUT->pix_icon('turnitin-icon', $statusstr, 'plagiarism_turnitin', array('class' => 'icon_size')).$statusstr, - array('class' => 'turnitin_status hidden')); + $output .= html_writer::tag('div', $OUTPUT->pix_icon('turnitin-icon', $statusstr, 'plagiarism_turnitin', ['class' => 'icon_size']).$statusstr, + ['class' => 'turnitin_status hidden']); // Show hidden data for potential forum post resubmissions. if ($submissiontype == 'forum_post' && !empty($linkarray["content"])) { $output .= html_writer::tag('div', $linkarray["content"], - array('class' => 'hidden', 'id' => 'content_'.$plagiarismfile->id)); + ['class' => 'hidden', 'id' => 'content_'.$plagiarismfile->id]); } if ($cm->modname == 'forum') { @@ -1150,7 +1163,7 @@ public function get_links($linkarray) { $edit = optional_param('edit', 0, PARAM_INT); $delete = optional_param('delete', 0, PARAM_INT); $output .= html_writer::tag('div', $querystrid.'_'.$discussionid.'_'.$reply.'_'.$edit.'_'.$delete, - array('class' => 'hidden', 'id' => 'forumdata_'.$plagiarismfile->id)); + ['class' => 'hidden', 'id' => 'forumdata_'.$plagiarismfile->id]); } } } else if ($plagiarismfile->statuscode == 'deleted') { @@ -1164,17 +1177,17 @@ public function get_links($linkarray) { } $statusstr = get_string('turnitinstatus', 'plagiarism_turnitin').': '.get_string('deleted', 'plagiarism_turnitin').'
'; $statusstr .= get_string('because', 'plagiarism_turnitin').'
"'.$errorstring.'"'; - $output .= html_writer::tag('div', $OUTPUT->pix_icon('turnitin-icon', $statusstr, 'plagiarism_turnitin', array('class' => 'icon_size')).$statusstr, - array('class' => 'turnitin_status')); + $output .= html_writer::tag('div', $OUTPUT->pix_icon('turnitin-icon', $statusstr, 'plagiarism_turnitin', ['class' => 'icon_size']).$statusstr, + ['class' => 'turnitin_status']); } else if ($plagiarismfile->statuscode == 'queued') { $statusstr = get_string('turnitinstatus', 'plagiarism_turnitin').': '.get_string('queued', 'plagiarism_turnitin'); - $output .= html_writer::tag('div', $OUTPUT->pix_icon('turnitin-icon', $statusstr, 'plagiarism_turnitin', array('class' => 'icon_size')).$statusstr, - array('class' => 'turnitin_status')); + $output .= html_writer::tag('div', $OUTPUT->pix_icon('turnitin-icon', $statusstr, 'plagiarism_turnitin', ['class' => 'icon_size']).$statusstr, + ['class' => 'turnitin_status']); } else { $statusstr = get_string('turnitinstatus', 'plagiarism_turnitin').': '.get_string('pending', 'plagiarism_turnitin'); - $output .= html_writer::tag('div', $OUTPUT->pix_icon('turnitin-icon', $statusstr, 'plagiarism_turnitin', array('class' => 'icon_size')).$statusstr, - array('class' => 'turnitin_status')); + $output .= html_writer::tag('div', $OUTPUT->pix_icon('turnitin-icon', $statusstr, 'plagiarism_turnitin', ['class' => 'icon_size']).$statusstr, + ['class' => 'turnitin_status']); } } else { @@ -1183,16 +1196,16 @@ public function get_links($linkarray) { if ($linkarray["userid"] != $USER->id && $submittinguser == $author && $istutor) { // There is a moodle plagiarism bug where get_links is called twice, the first loop is incorrect and is killing // this functionality. Have to check that user exists here first else there will be a fatal error. - if ($DB->get_record('user', array('id' => $linkarray["userid"]))) { + if ($DB->get_record('user', ['id' => $linkarray["userid"]])) { // We need to check for security that the user is actually on the course. if ($moduleobject->user_enrolled_on_course($context, $linkarray["userid"])) { $user = new turnitin_user($linkarray["userid"], "Learner"); if ($user->useragreementaccepted != 1) { $erroricon = html_writer::tag('div', $OUTPUT->pix_icon('doc-x-grey', get_string('errorcode3', 'plagiarism_turnitin'), 'plagiarism_turnitin'), - array('title' => get_string('errorcode3', 'plagiarism_turnitin'), - 'class' => 'tii_tooltip tii_error_icon')); - $eulaerror = html_writer::tag('div', $erroricon, array('class' => 'clear')); + ['title' => get_string('errorcode3', 'plagiarism_turnitin'), + 'class' => 'tii_tooltip tii_error_icon']); + $eulaerror = html_writer::tag('div', $erroricon, ['class' => 'clear']); } } } @@ -1204,10 +1217,10 @@ public function get_links($linkarray) { } } - $output .= html_writer::tag('div', '', array('class' => 'clear')); + $output .= html_writer::tag('div', '', ['class' => 'clear']); } - $output = html_writer::tag('div', $output, array('class' => 'tii_links_container')); + $output = html_writer::tag('div', $output, ['class' => 'tii_links_container']); } // This comment is here as it is useful for product support. @@ -1274,7 +1287,7 @@ public function update_grades_from_tii($cm) { foreach ($readsubmissions as $readsubmission) { $submissiondata = $DB->get_record('plagiarism_turnitin_files', - array('externalid' => $readsubmission->getSubmissionId()), 'id'); + ['externalid' => $readsubmission->getSubmissionId()], 'id'); $return = $this->update_submission($cm, $submissiondata->id, $readsubmission); } @@ -1304,7 +1317,7 @@ public function update_grade_from_tii($cm, $submissionid) { $readsubmission = $response->getSubmission(); $submissiondata = $DB->get_record('plagiarism_turnitin_files', - array('externalid' => $readsubmission->getSubmissionId()), 'id'); + ['externalid' => $readsubmission->getSubmissionId()], 'id'); $this->update_submission($cm, $submissiondata->id, $readsubmission); @@ -1324,7 +1337,7 @@ private function update_submission($cm, $submissionid, $tiisubmission) { $fields = 'id, cm, userid, identifier, itemid, similarityscore, grade, submissiontype, orcapable,'; $fields .= 'student_read, gm_feedback, errorcode'; - if ($submissiondata = $DB->get_record('plagiarism_turnitin_files', array('id' => $submissionid), $fields)) { + if ($submissiondata = $DB->get_record('plagiarism_turnitin_files', ['id' => $submissionid], $fields)) { // Build Plagiarism file object. $plagiarismfile = new stdClass(); @@ -1368,7 +1381,7 @@ private function update_submission($cm, $submissionid, $tiisubmission) { if ($file = $fs->get_file_by_hash($submissiondata->identifier)) { $itemid = $file->get_itemid(); - $assignmentdata = array("assignment" => $cm->instance); + $assignmentdata = ["assignment" => $cm->instance]; // Check whether submission is a group submission. $groupid = $this->check_group_submission($cm, $submissiondata->userid); @@ -1409,7 +1422,7 @@ private function update_submission($cm, $submissionid, $tiisubmission) { // Update grades, for the quiz we update marks for questions instead. if ($cm->modname == "quiz") { - $quiz = $DB->get_record('quiz', array('id' => $cm->instance)); + $quiz = $DB->get_record('quiz', ['id' => $cm->instance]); $tq = new turnitin_quiz(); if (!is_null($plagiarismfile->grade)) { $tq->update_mark( @@ -1422,8 +1435,8 @@ private function update_submission($cm, $submissionid, $tiisubmission) { } } else { $gradeitem = $DB->get_record('grade_items', - array('iteminstance' => $cm->instance, 'itemmodule' => $cm->modname, - 'courseid' => $cm->course, 'itemnumber' => 0)); + ['iteminstance' => $cm->instance, 'itemmodule' => $cm->modname, + 'courseid' => $cm->course, 'itemnumber' => 0]); if (!is_null($plagiarismfile->grade) && !empty($gradeitem) && $gbupdaterequired) { $return = $this->update_grade($cm, $tiisubmission, $submissiondata->userid); @@ -1453,19 +1466,19 @@ private function update_grade($cm, $submission, $userid, $cron = FALSE) { $moduleobject = new $moduleclass; // Get file from pathname hash. - $submissiondata = $DB->get_record('plagiarism_turnitin_files', array('externalid' => $submission->getSubmissionId()), 'identifier'); + $submissiondata = $DB->get_record('plagiarism_turnitin_files', ['externalid' => $submission->getSubmissionId()], 'identifier'); // Get file as we need item id for discounting files that are no longer in submission. $fs = get_file_storage(); if ($file = $fs->get_file_by_hash($submissiondata->identifier)) { $moodlefiles = $DB->get_records_select('files', " component = ? AND itemid = ? AND source IS NOT null ", - array($moduleobject->filecomponent, $file->get_itemid()), 'id DESC', 'pathnamehash'); + [$moduleobject->filecomponent, $file->get_itemid()], 'id DESC', 'pathnamehash'); list($insql, $inparams) = $DB->get_in_or_equal(array_keys($moodlefiles), SQL_PARAMS_QM, 'param', true); $tiisubmissions = $DB->get_records_select('plagiarism_turnitin_files', " userid = ? AND cm = ? AND identifier ".$insql, - array_merge(array($userid, $cm->id), $inparams)); + array_merge([$userid, $cm->id], $inparams)); } else { - $tiisubmissions = $DB->get_records('plagiarism_turnitin_files', array('userid' => $userid, 'cm' => $cm->id)); + $tiisubmissions = $DB->get_records('plagiarism_turnitin_files', ['userid' => $userid, 'cm' => $cm->id]); $tiisubmissions = current($tiisubmissions); } @@ -1486,8 +1499,8 @@ private function update_grade($cm, $submission, $userid, $cron = FALSE) { // Check whether submission is a group submission - only applicable to assignment module. // If it's a group submission we will update the grade for everyone in the group. // Note: This will not work if the submitting user is in multiple groups. - $userids = array($userid); - $moduledata = $DB->get_record($cm->modname, array('id' => $cm->instance)); + $userids = [$userid]; + $moduledata = $DB->get_record($cm->modname, ['id' => $cm->instance]); if ($cm->modname == "assign" && !empty($moduledata->teamsubmission)) { require_once($CFG->dirroot . '/mod/assign/locallib.php'); $context = context_course::instance($cm->course); @@ -1506,7 +1519,7 @@ private function update_grade($cm, $submission, $userid, $cron = FALSE) { case 'assign': // Query grades based on attempt number. - $gradesquery = array('userid' => $userid, 'assignment' => $cm->instance); + $gradesquery = ['userid' => $userid, 'assignment' => $cm->instance]; $usersubmissions = $DB->get_records('assign_submission', $gradesquery, 'attemptnumber DESC', 'attemptnumber', 0, 1); $usersubmission = current($usersubmissions); @@ -1517,9 +1530,9 @@ private function update_grade($cm, $submission, $userid, $cron = FALSE) { $currentgrade = current($currentgrades); break; case 'workshop': - if ($gradeitem = $DB->get_record('grade_items', array('iteminstance' => $cm->instance, - 'itemmodule' => $cm->modname, 'itemnumber' => 0))) { - $currentgrade = $DB->get_record('grade_grades', array('userid' => $userid, 'itemid' => $gradeitem->id)); + if ($gradeitem = $DB->get_record('grade_items', ['iteminstance' => $cm->instance, + 'itemmodule' => $cm->modname, 'itemnumber' => 0])) { + $currentgrade = $DB->get_record('grade_grades', ['userid' => $userid, 'itemid' => $gradeitem->id]); } break; } @@ -1570,11 +1583,11 @@ private function update_grade($cm, $submission, $userid, $cron = FALSE) { // Check marking workflow state for assignments and only update gradebook if released. if ($cm->modname == 'assign' && !empty($moduledata->markingworkflow)) { $gradesreleased = $DB->record_exists('assign_user_flags', - array( + [ 'userid' => $userid, 'assignment' => $cm->instance, 'workflowstate' => 'released' - )); + ]); // Remove any existing grade from gradebook if not released. if (!$gradesreleased) { $grades->rawgrade = null; @@ -1606,7 +1619,7 @@ private function update_grade($cm, $submission, $userid, $cron = FALSE) { public function check_group_submission($cm, $userid) { global $CFG, $DB; - $moduledata = $DB->get_record($cm->modname, array('id' => $cm->instance)); + $moduledata = $DB->get_record($cm->modname, ['id' => $cm->instance]); if (!empty($moduledata->teamsubmission)) { require_once($CFG->dirroot . '/mod/assign/locallib.php'); $context = context_course::instance($cm->course); @@ -1715,7 +1728,7 @@ public function refresh_peermark_assignments($cm, $tiiassignmentid) { $peermark->title = $peermarkassignment->getTitle(); $currentpeermark = $DB->get_record('plagiarism_turnitin_peermark', - array('tiiassignid' => $peermark->tiiassignid)); + ['tiiassignid' => $peermark->tiiassignid]); if ($currentpeermark) { $peermark->id = $currentpeermark->id; @@ -1740,7 +1753,7 @@ public function sync_tii_assignment($cm, $coursetiiid, $workflowcontext = "site" $config = $this->plagiarism_turnitin_admin_config(); $modulepluginsettings = $this->get_settings($cm->id); - $moduledata = $DB->get_record($cm->modname, array('id' => $cm->instance)); + $moduledata = $DB->get_record($cm->modname, ['id' => $cm->instance]); // Configure assignment object to send to Turnitin. $assignment = new TiiAssignment(); @@ -1783,7 +1796,7 @@ public function sync_tii_assignment($cm, $coursetiiid, $workflowcontext = "site" // Don't set anonymous marking if there have been submissions. $previoussubmissions = $DB->record_exists('plagiarism_turnitin_files', - array('cm' => $cm->id, 'statuscode' => 'success')); + ['cm' => $cm->id, 'statuscode' => 'success']); // Use Moodle's blind marking setting for anonymous marking. if (isset($config->plagiarism_turnitin_useanon) && $config->plagiarism_turnitin_useanon && !$previoussubmissions) { @@ -1821,11 +1834,11 @@ public function sync_tii_assignment($cm, $coursetiiid, $workflowcontext = "site" if ($cm->modname != "forum") { if ($gradeitem = $DB->get_record( 'grade_items', - array( + [ 'iteminstance' => $cm->instance, 'itemmodule' => $cm->modname, 'courseid' => $cm->course, - 'itemnumber' => 0) + 'itemnumber' => 0] )) { switch ($gradeitem->hidden) { @@ -1837,8 +1850,8 @@ public function sync_tii_assignment($cm, $coursetiiid, $workflowcontext = "site" // If any grades have been released early via marking workflow, set post date to have passed. if ($cm->modname == 'assign' && !empty($moduledata->markingworkflow)) { $gradesreleased = $DB->record_exists('assign_user_flags', - array('assignment' => $cm->instance, - 'workflowstate' => 'released')); + ['assignment' => $cm->instance, + 'workflowstate' => 'released']); $dtpost = ($gradesreleased) ? strtotime('-5 minutes') : strtotime('+1 month'); } @@ -1888,14 +1901,14 @@ public function sync_tii_assignment($cm, $coursetiiid, $workflowcontext = "site" // If the duedate is in the future then set any submission duedate_report_refresh flags that // are 2 to 1 to make sure they are re-examined in the next cron run. if ($dtdue > time()) { - $DB->set_field('plagiarism_turnitin_files', 'duedate_report_refresh', 1, array('cm' => $cm->id, 'duedate_report_refresh' => 2)); + $DB->set_field('plagiarism_turnitin_files', 'duedate_report_refresh', 1, ['cm' => $cm->id, 'duedate_report_refresh' => 2]); } $assignment->setFeedbackReleaseDate(gmdate("Y-m-d\TH:i:s\Z", $dtpost)); // If we have a turnitin id then edit the assignment otherwise create it. if ($tiiassignment = $DB->get_record('plagiarism_turnitin_config', - array('cm' => $cm->id, 'name' => 'turnitin_assignid'), 'value')) { + ['cm' => $cm->id, 'name' => 'turnitin_assignid'], 'value')) { $assignment->setAssignmentId($tiiassignment->value); $turnitinassignment = new turnitin_assignment(0); @@ -1908,7 +1921,7 @@ public function sync_tii_assignment($cm, $coursetiiid, $workflowcontext = "site" $turnitinassignid = $turnitinassignment->create_tii_assignment($assignment, $workflowcontext); if (!$turnitinassignid) { - $return = array('success' => false, 'tiiassignmentid' => '', 'errorcode' => 5); + $return = ['success' => false, 'tiiassignmentid' => '', 'errorcode' => 5]; } else { $moduleconfigvalue = new stdClass(); $moduleconfigvalue->cm = $cm->id; @@ -1917,7 +1930,7 @@ public function sync_tii_assignment($cm, $coursetiiid, $workflowcontext = "site" $moduleconfigvalue->config_hash = $moduleconfigvalue->cm."_".$moduleconfigvalue->name; $DB->insert_record('plagiarism_turnitin_config', $moduleconfigvalue); - $return = array('success' => true, 'tiiassignmentid' => $turnitinassignid); + $return = ['success' => true, 'tiiassignmentid' => $turnitinassignid]; } return $return; @@ -1935,7 +1948,7 @@ public function update_rubric_from_tii($cm) { $assignment = new TiiAssignment(); if ($tiimoduledata = $DB->get_record('plagiarism_turnitin_config', - array('cm' => $cm->id, 'name' => 'turnitin_assignid'), 'value')) { + ['cm' => $cm->id, 'name' => 'turnitin_assignid'], 'value')) { $assignment->setAssignmentId($tiimoduledata->value); @@ -1952,7 +1965,7 @@ public function update_rubric_from_tii($cm) { // Check if rubric already exists for this module. if ($configfield = $DB->get_field('plagiarism_turnitin_config', 'id', - (array('cm' => $cm->id, 'name' => 'plagiarism_rubric')))) { + (['cm' => $cm->id, 'name' => 'plagiarism_rubric']))) { // Use current configfield to update rubric value. $rubricfield->id = $configfield; @@ -1992,6 +2005,7 @@ public function set_duedate_report_refresh($id, $newvalue) { public function cron_update_scores() { global $DB; +<<<<<<< HEAD $submissionids = array(); $reportsexpected = array(); $assignmentids = array(); @@ -2012,6 +2026,19 @@ public function cron_update_scores() { AND ( orcapable = ? OR orcapable IS NULL ) ORDER BY externalid DESC', ['success', 1] +======= + $submissionids = []; + $reportsexpected = []; + $assignmentids = []; + + $submissions = $DB->get_records_select( + 'plagiarism_turnitin_files', + 'statuscode = ? + AND ( similarityscore IS NULL OR duedate_report_refresh = 1 ) + AND ( orcapable = ? OR orcapable IS NULL ) ', + ['success', 1], + 'externalid DESC' +>>>>>>> 796b5bd (Fix 'Short array syntax must be used to define arrays' warnings.) ); // Cache module settings @@ -2041,10 +2068,19 @@ public function cron_update_scores() { if (!isset($reportsexpected[$tiisubmission->cm])) { +<<<<<<< HEAD $reportsexpected[$tiisubmission->cm] = 1; if (!isset($modulesettings[$tiisubmission->cm]['plagiarism_compare_institution'])) { $modulesettings[$tiisubmission->cm]['plagiarism_compare_institution'] = 0; +======= + // Updates the db field 'duedate_report_refresh' if the due date has passed within the last twenty four hours. + $moduledata = $DB->get_record($cm->modname, ['id' => $cm->instance]); + $now = strtotime('now'); + $dtdue = (!empty($moduledata->duedate)) ? $moduledata->duedate : 0; + if ($now >= $dtdue && $now < strtotime('+1 day', $dtdue)) { + $this->set_duedate_report_refresh($tiisubmission->id, 1); +>>>>>>> 796b5bd (Fix 'Short array syntax must be used to define arrays' warnings.) } // Don't add the submission to the request if module settings mean we will not get a report back. @@ -2061,12 +2097,26 @@ public function cron_update_scores() { if ($reportsexpected[$tiisubmission->cm] == 1) { $submissionids[] = $tiisubmission->externalid; +<<<<<<< HEAD // If submission is added to the request, add the corresponding assign id in the assignids array. $moduleturnitinconfig = $DB->get_record('plagiarism_turnitin_config', [ 'cm' => $tiisubmission->cm, 'name' => 'turnitin_assignid' ]); if (!isset(array_flip($assignmentids)[$moduleturnitinconfig->value])) { $assignmentids[] = $moduleturnitinconfig->value; +======= + // If submission is added to the request, add the corresponding assign id in the assignids array. + $moduleturnitinconfig = $DB->get_record('plagiarism_turnitin_config', + [ + 'cm' => $cm->id, + 'name' => 'turnitin_assignid' + ] + ); + + if (!isset(array_flip($assignmentids)[$moduleturnitinconfig->value])) { + $assignmentids[] = $moduleturnitinconfig->value; + } +>>>>>>> 796b5bd (Fix 'Short array syntax must be used to define arrays' warnings.) } } } @@ -2110,7 +2160,7 @@ public function cron_update_scores() { try { $tiisubmissionid = (int)$readsubmission->getSubmissionId(); - $currentsubmission = $DB->get_record('plagiarism_turnitin_files', array('externalid' => $tiisubmissionid), 'id, cm, externalid, userid'); + $currentsubmission = $DB->get_record('plagiarism_turnitin_files', ['externalid' => $tiisubmissionid], 'id, cm, externalid, userid'); if ($cm = get_coursemodule_from_id('', $currentsubmission->cm)) { $plagiarismfile = new stdClass(); @@ -2162,7 +2212,7 @@ private function check_local_submission_state($assignmentids, $submissionids) { // Initialise Comms Object. $turnitincomms = new turnitin_comms(); $turnitincall = $turnitincomms->initialise_api(); - $tiisubmissionids = array(); + $tiisubmissionids = []; foreach ($assignmentids as $assignmentid) { $submission = new TiiSubmission(); @@ -2177,16 +2227,16 @@ private function check_local_submission_state($assignmentids, $submissionids) { } } - return array( + return [ 'trimmedSubmissions' => array_intersect($submissionids, $tiisubmissionids), 'missingTiiSubmissions' => array_diff($submissionids, $tiisubmissionids) - ); + ]; } private function invalidate_missing_submission($missingsubmission) { global $DB; $currentsubmission = $DB->get_record('plagiarism_turnitin_files', - array('externalid' => $missingsubmission), + ['externalid' => $missingsubmission], 'id, cm, externalid, userid' ); $plagiarismfile = new stdClass(); @@ -2232,15 +2282,15 @@ public function get_previous_course_id($cmid, $courseid) { global $DB; $tiicourseid = 0; - if ($tiiassignment = $DB->get_record('plagiarism_turnitin_config', array('cm' => $cmid, - 'name' => 'turnitin_assignid'))) { + if ($tiiassignment = $DB->get_record('plagiarism_turnitin_config', ['cm' => $cmid, + 'name' => 'turnitin_assignid'])) { $tiicourseid = $this->get_course_id_from_assignment_id($tiiassignment->value); } else { $coursemods = get_course_mods($courseid); foreach ($coursemods as $coursemod) { if ($coursemod->modname != 'turnitintooltwo') { - if ($tiiassignment = $DB->get_record('plagiarism_turnitin_config', array('cm' => $coursemod->id, - 'name' => 'turnitin_assignid'))) { + if ($tiiassignment = $DB->get_record('plagiarism_turnitin_config', ['cm' => $coursemod->id, + 'name' => 'turnitin_assignid'])) { $tiicourseid = $this->get_course_id_from_assignment_id($tiiassignment->value); } } @@ -2329,7 +2379,7 @@ public function queue_submission_to_turnitin($cm, $author, $submitter, $identifi $settings = $this->get_settings($cm->id); // Get module data. - $moduledata = $DB->get_record($cm->modname, array('id' => $cm->instance)); + $moduledata = $DB->get_record($cm->modname, ['id' => $cm->instance]); $moduledata->resubmission_allowed = false; if ($cm->modname == 'assign') { @@ -2342,9 +2392,9 @@ public function queue_submission_to_turnitin($cm, $author, $submitter, $identifi if ($eventtype == "content_uploaded" || $eventtype == "file_uploaded") { $moodlesubmission = $DB->get_record('assign_submission', - array('assignment' => $cm->instance, + ['assignment' => $cm->instance, 'userid' => $userid, - 'id' => $itemid), 'status'); + 'id' => $itemid], 'status'); $_SESSION["moodlesubmissionstatus"] = $moodlesubmission->status; } @@ -2383,14 +2433,14 @@ public function queue_submission_to_turnitin($cm, $author, $submitter, $identifi switch ($cm->modname) { case 'assign': $moodlesubmission = $DB->get_record('assign_submission', - array('assignment' => $cm->instance, + ['assignment' => $cm->instance, 'userid' => $userid, - 'id' => $itemid), 'timemodified'); + 'id' => $itemid], 'timemodified'); break; case 'workshop': $moodlesubmission = $DB->get_record('workshop_submissions', - array('workshopid' => $cm->instance, - 'authorid' => $userid), 'timemodified'); + ['workshopid' => $cm->instance, + 'authorid' => $userid], 'timemodified'); break; } @@ -2404,13 +2454,13 @@ public function queue_submission_to_turnitin($cm, $author, $submitter, $identifi // Check if this content/file has been submitted previously. $previoussubmissions = $DB->get_records_select('plagiarism_turnitin_files', " cm = ? AND userid = ? AND ".$typefield." = ? AND identifier = ?", - array($cm->id, $author, $submissiontype, $identifier), + [$cm->id, $author, $submissiontype, $identifier], 'id', $submissionfields); $previoussubmission = end($previoussubmissions); if ($previoussubmission) { // Don't submit if submission hasn't changed. - if (in_array($previoussubmission->statuscode, array("success", "error")) + if (in_array($previoussubmission->statuscode, ["success", "error"]) && $timemodified <= $previoussubmission->lastmodified) { return true; } else if ($moduledata->resubmission_allowed) { @@ -2433,7 +2483,7 @@ public function queue_submission_to_turnitin($cm, $author, $submitter, $identifi $typefield = ($CFG->dbtype == "oci") ? " to_char(submissiontype) " : " submissiontype "; if ($previoussubmission = $DB->get_record_select('plagiarism_turnitin_files', " cm = ? AND userid = ? AND ".$typefield." = ?", - array($cm->id, $author, $submissiontype), + [$cm->id, $author, $submissiontype], 'id, cm, externalid, identifier, statuscode, lastmodified, attempt')) { $submissionid = $previoussubmission->id; @@ -2462,7 +2512,7 @@ public function queue_submission_to_turnitin($cm, $author, $submitter, $identifi case 'quiz_answer': if ($previoussubmissions = $DB->get_records_select('plagiarism_turnitin_files', " cm = ? AND userid = ? AND identifier = ? ", - array($cm->id, $author, $identifier), + [$cm->id, $author, $identifier], 'id DESC', 'id, cm, externalid, identifier, statuscode, attempt', 0, 1)) { $previoussubmission = current($previoussubmissions); @@ -2540,7 +2590,7 @@ public function event_handler($eventdata) { } // Get module data. - $moduledata = $DB->get_record($cm->modname, array('id' => $cm->instance)); + $moduledata = $DB->get_record($cm->modname, ['id' => $cm->instance]); if ($cm->modname != 'assign') { $moduledata->submissiondrafts = 0; } @@ -2561,7 +2611,7 @@ public function event_handler($eventdata) { */ if ((empty($eventdata['relateduserid'])) && ($cm->modname == 'assign') && has_capability('mod/assign:editothersubmission', $context, $submitter)) { - $moodlesubmission = $DB->get_record('assign_submission', array('id' => $eventdata['objectid']), 'id, groupid'); + $moodlesubmission = $DB->get_record('assign_submission', ['id' => $eventdata['objectid']], 'id, groupid'); if (!empty($moodlesubmission->groupid)) { $author = $this->get_first_group_author($cm->course, $moodlesubmission->groupid); } @@ -2571,16 +2621,16 @@ public function event_handler($eventdata) { // As this won't be present in eventdata for certain event types. if ($eventdata['other']['modulename'] == 'assign' && $eventdata['eventtype'] == "assessable_submitted") { // Get content. - $moodlesubmission = $DB->get_record('assign_submission', array('id' => $eventdata['objectid']), 'id'); + $moodlesubmission = $DB->get_record('assign_submission', ['id' => $eventdata['objectid']], 'id'); if ($moodletextsubmission = $DB->get_record('assignsubmission_onlinetext', - array('submission' => $moodlesubmission->id), 'onlinetext')) { + ['submission' => $moodlesubmission->id], 'onlinetext')) { $eventdata['other']['content'] = $moodletextsubmission->onlinetext; } // Get Files. - $eventdata['other']['pathnamehashes'] = array(); - $filesconditions = array('component' => 'assignsubmission_file', - 'itemid' => $moodlesubmission->id, 'userid' => $author); + $eventdata['other']['pathnamehashes'] = []; + $filesconditions = ['component' => 'assignsubmission_file', + 'itemid' => $moodlesubmission->id, 'userid' => $author]; if ($moodlefiles = $DB->get_records('files', $filesconditions)) { foreach ($moodlefiles as $moodlefile) { $eventdata['other']['pathnamehashes'][] = $moodlefile->pathnamehash; @@ -2628,7 +2678,7 @@ public function event_handler($eventdata) { } // Queue text content and forum posts to send to Turnitin. - if (in_array($eventdata['eventtype'], array("content_uploaded", "assessable_submitted")) + if (in_array($eventdata['eventtype'], ["content_uploaded", "assessable_submitted"]) && !empty($eventdata['other']['content'])) { $submissiontype = ($cm->modname == 'forum') ? 'forum_post' : 'text_content'; @@ -2637,7 +2687,7 @@ public function event_handler($eventdata) { // because URLs have been converted to use @@PLUGINFILE@@ etc. Therefore to calculate the same hash, we need to // do a lookup to get the file content if ($cm->modname == 'workshop') { - $moodlesubmission = $DB->get_record('workshop_submissions', array('id' => $eventdata['objectid'])); + $moodlesubmission = $DB->get_record('workshop_submissions', ['id' => $eventdata['objectid']]); $eventdata['other']['content'] = $moodlesubmission->content; } else if ($cm->modname == 'forum') { @@ -2753,10 +2803,10 @@ public function clean_old_turnitin_submissions($cm, $userid, $itemid, $submissio if ($submissiontype == 'file') { // If this is an assignment then we need to account for previous attempts so get other items ids. if ($cm->modname == 'assign') { - $itemids = $DB->get_records('assign_submission', array( + $itemids = $DB->get_records('assign_submission', [ 'assignment' => $cm->instance, 'userid' => $userid - ), '', 'id'); + ], '', 'id'); // Only proceed if we have item ids. if (empty($itemids)) { @@ -2764,12 +2814,12 @@ public function clean_old_turnitin_submissions($cm, $userid, $itemid, $submissio } else { list($itemidsinsql, $itemidsparams) = $DB->get_in_or_equal(array_keys($itemids)); $itemidsinsql = ' itemid '.$itemidsinsql; - $params = array_merge(array($moduleobject->filecomponent, $userid), $itemidsparams); + $params = array_merge([$moduleobject->filecomponent, $userid], $itemidsparams); } } else { $itemidsinsql = ' itemid = ? '; - $params = array($moduleobject->filecomponent, $userid, $itemid); + $params = [$moduleobject->filecomponent, $userid, $itemid]; } if ($moodlefiles = $DB->get_records_select('files', " component = ? AND userid = ? AND source IS NOT null AND ".$itemidsinsql, @@ -2778,7 +2828,7 @@ public function clean_old_turnitin_submissions($cm, $userid, $itemid, $submissio $typefield = ($CFG->dbtype == "oci") ? " to_char(submissiontype) " : " submissiontype "; $oldfiles = $DB->get_records_select('plagiarism_turnitin_files', " userid = ? AND cm = ? ". " AND ".$typefield." = ? AND identifier ".$notinsql, - array_merge(array($userid, $cm->id, 'file'), $notinparams)); + array_merge([$userid, $cm->id, 'file'], $notinparams)); if (!empty($oldfiles)) { foreach ($oldfiles as $oldfile) { @@ -2797,7 +2847,7 @@ public function clean_old_turnitin_submissions($cm, $userid, $itemid, $submissio } else if ($submissiontype == 'text_content') { $typefield = ($CFG->dbtype == "oci") ? " to_char(submissiontype) " : " submissiontype "; $deletestr = " userid = ? AND cm = ? AND ".$typefield." = ? AND identifier != ? "; - $deleteparams = array($userid, $cm->id, 'text_content', $identifier); + $deleteparams = [$userid, $cm->id, 'text_content', $identifier]; } // Delete from database. @@ -2869,7 +2919,7 @@ public function save_submission($cm, $userid, $submissionid, $identifier, $statu */ public function delete_tii_submission($cm, $submissionid, $userid) { global $DB; - $user = $DB->get_record('user', array('id' => $userid)); + $user = $DB->get_record('user', ['id' => $userid]); // Initialise Comms Object. $turnitincomms = new turnitin_comms(); @@ -3016,7 +3066,7 @@ function plagiarism_turnitin_send_queued_submissions() { $moduleobject = new $moduleclass; // Get module data. - $moduledata = $DB->get_record($cm->modname, array('id' => $cm->instance)); + $moduledata = $DB->get_record($cm->modname, ['id' => $cm->instance]); $moduledata->resubmission_allowed = false; if ($cm->modname == 'assign') { @@ -3024,9 +3074,9 @@ function plagiarism_turnitin_send_queued_submissions() { $userid = ($moduledata->teamsubmission) ? 0 : $queueditem->userid; $moodlesubmission = $DB->get_record('assign_submission', - array('assignment' => $cm->instance, + ['assignment' => $cm->instance, 'userid' => $userid, - 'id' => $queueditem->itemid), 'status'); + 'id' => $queueditem->itemid], 'status'); $moduledata->resubmission_allowed = $moduleobject->is_resubmission_allowed( $cm->instance, $settings["plagiarism_report_gen"], @@ -3082,7 +3132,7 @@ function plagiarism_turnitin_send_queued_submissions() { } // There should never not be a submission type, handle if there isn't just in case. - if (!in_array($queueditem->submissiontype, array('file', 'text_content', 'forum_post', 'quiz_answer'))) { + if (!in_array($queueditem->submissiontype, ['file', 'text_content', 'forum_post', 'quiz_answer'])) { $errorcode = 11; } @@ -3142,16 +3192,16 @@ function plagiarism_turnitin_send_queued_submissions() { // Get the actual text content for a submission. switch ($cm->modname) { case 'assign': - $moodlesubmission = $DB->get_record('assign_submission', array('assignment' => $cm->instance, - 'userid' => $queueditem->userid, 'id' => $queueditem->itemid), 'id'); + $moodlesubmission = $DB->get_record('assign_submission', ['assignment' => $cm->instance, + 'userid' => $queueditem->userid, 'id' => $queueditem->itemid], 'id'); $moodletextsubmission = $DB->get_record('assignsubmission_onlinetext', - array('submission' => $moodlesubmission->id), 'onlinetext'); + ['submission' => $moodlesubmission->id], 'onlinetext'); $textcontent = $moodletextsubmission->onlinetext; break; case 'workshop': $moodlesubmission = $DB->get_record('workshop_submissions', - array('id' => $queueditem->itemid), 'content'); + ['id' => $queueditem->itemid], 'content'); $textcontent = $moodlesubmission->content; break; } @@ -3184,7 +3234,7 @@ function plagiarism_turnitin_send_queued_submissions() { $apimethod = ($settings["plagiarism_report_gen"] == 0) ? "createSubmission" : "replaceSubmission"; } - $forumpost = $DB->get_record_select('forum_posts', " userid = ? AND id = ? ", array($user->id, $queueditem->itemid)); + $forumpost = $DB->get_record_select('forum_posts', " userid = ? AND id = ? ", [$user->id, $queueditem->itemid]); if ($forumpost) { $textcontent = strip_tags($forumpost->message); @@ -3238,15 +3288,15 @@ function plagiarism_turnitin_send_queued_submissions() { $submissiontitle = explode('.', $title); // Initialise file string array for naming the file. - $filestring = array($submissiontitle[0], $cm->id); + $filestring = [$submissiontitle[0], $cm->id]; // Only include user's name and id if we're not using blind marking and student privacy. if ( empty($moduledata->blindmarking) && empty($config->plagiarism_turnitin_enablepseudo) ) { - $userdetails = array( + $userdetails = [ $user->id, $user->firstname, $user->lastname - ); + ]; $filestring = array_merge($userdetails, $filestring); } @@ -3311,7 +3361,7 @@ function plagiarism_turnitin_send_queued_submissions() { // Send a message to the user's Moodle inbox with the digital receipt. $receipt = new pp_receipt_message(); - $input = array( + $input = [ 'firstname' => $user->firstname, 'lastname' => $user->lastname, 'submission_title' => $title, @@ -3319,7 +3369,7 @@ function plagiarism_turnitin_send_queued_submissions() { 'course_fullname' => $coursedata->turnitin_ctl, 'submission_date' => date('d-M-Y h:iA'), 'submission_id' => $tiisubmissionid - ); + ]; $message = $receipt->build_message($input); $receipt->send_message($user->id, $message, $cm->course); @@ -3470,7 +3520,7 @@ function plagiarism_turnitin_activitylog($string, $activity) { mkdir($dirpath, 0777, true); } $dir = opendir($dirpath); - $files = array(); + $files = []; while ($entry = readdir($dir)) { if (substr(basename($entry), 0, 1) != "." AND substr_count(basename($entry), $prefix) > 0) { $files[] = basename($entry); diff --git a/locallib.php b/locallib.php index b85095fd..79310761 100644 --- a/locallib.php +++ b/locallib.php @@ -63,13 +63,13 @@ function plagiarism_turnitin_retrieve_successful_submissions($author, $cmid, $id global $CFG, $DB; // Check if the same answer has been submitted previously. Remove if so. - list($insql, $inparams) = $DB->get_in_or_equal(array('success', 'queued'), SQL_PARAMS_QM, 'param', false); + list($insql, $inparams) = $DB->get_in_or_equal(['success', 'queued'], SQL_PARAMS_QM, 'param', false); $typefield = ($CFG->dbtype == "oci") ? " to_char(statuscode) " : " statuscode "; $plagiarismfiles = $DB->get_records_select( "plagiarism_turnitin_files", " userid = ? AND cm = ? AND identifier = ? AND ".$typefield. " " .$insql, - array_merge(array($author, $cmid, $identifier), $inparams) + array_merge([$author, $cmid, $identifier], $inparams) ); return $plagiarismfiles; @@ -89,7 +89,7 @@ function plagiarism_turnitin_lock_anonymous_marking($cmid) { $configfield->config_hash = $configfield->cm . "_" . $configfield->name; if (!$DB->get_field('plagiarism_turnitin_config', 'id', - (array('cm' => $cmid, 'name' => 'submitted')))) { + (['cm' => $cmid, 'name' => 'submitted']))) { if (!$DB->insert_record('plagiarism_turnitin_config', $configfield)) { plagiarism_turnitin_print_error( 'defaultupdateerror', diff --git a/settings.php b/settings.php index e3dbfc1e..c303fe79 100644 --- a/settings.php +++ b/settings.php @@ -53,7 +53,7 @@ case "defaults": $fields = $plagiarismpluginturnitin->get_settings_fields(); - $settingsfields = array(); + $settingsfields = []; foreach ($fields as $field) { array_push($settingsfields, $field); array_push($settingsfields, $field . '_lock'); @@ -72,7 +72,7 @@ if (isset($plugindefaults[$field])) { $defaultfield->id = $DB->get_field('plagiarism_turnitin_config', 'id', - (array('cm' => null, 'name' => $field))); + (['cm' => null, 'name' => $field])); if (!$DB->update_record('plagiarism_turnitin_config', $defaultfield)) { plagiarism_turnitin_print_error('defaultupdateerror', 'plagiarism_turnitin', null, null, __FILE__, __LINE__); } @@ -85,14 +85,14 @@ } $_SESSION['notice']['message'] = get_string('defaultupdated', 'plagiarism_turnitin'); - redirect(new moodle_url('/plagiarism/turnitin/settings.php', array('do' => 'defaults'))); + redirect(new moodle_url('/plagiarism/turnitin/settings.php', ['do' => 'defaults'])); exit; break; case "deletefile": $id = optional_param('id', 0, PARAM_INT); - $DB->update_record('plagiarism_turnitin_files', array('id' => $id, 'statuscode' => "deleted")); - redirect(new moodle_url('/plagiarism/turnitin/settings.php', array('do' => 'errors'))); + $DB->update_record('plagiarism_turnitin_files', ['id' => $id, 'statuscode' => "deleted"]); + redirect(new moodle_url('/plagiarism/turnitin/settings.php', ['do' => 'errors'])); exit; break; } @@ -175,12 +175,12 @@ $label = 'activitylog'; $tabs[] = new tabobject( $label, $CFG->wwwroot.'/plagiarism/turnitin/settings.php?do='.$label, ucfirst( $label ), ucfirst( $label ), false ); - $inactive = array($do); + $inactive = [$do]; $selected = $do; $output .= ""; // Get tabs output. ob_start(); - print_tabs(array($tabs), $selected, $inactive); + print_tabs([$tabs], $selected, $inactive); $output .= ob_get_contents(); ob_end_clean(); @@ -212,15 +212,15 @@ case "unlinkusers": $jsrequired = true; - $userids = (isset($_REQUEST['userids'])) ? $_REQUEST["userids"] : array(); + $userids = (isset($_REQUEST['userids'])) ? $_REQUEST["userids"] : []; $userids = clean_param_array($userids, PARAM_INT); // Relink users if form has been submitted. if ((!is_null($relink) || !is_null($unlink)) && isset($userids) && count($userids) > 0) { foreach ($userids as $tiiid) { - $tuser = $DB->get_record('plagiarism_turnitin_users', array('id' => $tiiid)); + $tuser = $DB->get_record('plagiarism_turnitin_users', ['id' => $tiiid]); - if ($muser = $DB->get_record('user', array('id' => $tuser->userid))) { + if ($muser = $DB->get_record('user', ['id' => $tuser->userid])) { // Get the email address if the user has been deleted. if (empty($muser->email) || strpos($muser->email, '@') === false) { $split = explode('.', $muser->username); @@ -245,10 +245,10 @@ } } else { - $DB->delete_records('plagiarism_turnitin_users', array('id' => $tiiid)); + $DB->delete_records('plagiarism_turnitin_users', ['id' => $tiiid]); } } - redirect(new moodle_url('/plagiarism/turnitin/settings.php', array('do' => 'unlinkusers'))); + redirect(new moodle_url('/plagiarism/turnitin/settings.php', ['do' => 'unlinkusers'])); exit; } @@ -256,10 +256,10 @@ $table = new html_table(); $table->id = "unlinkUserTable"; - $rows = array(); + $rows = []; // Do the table headers. - $cells = array(); + $cells = []; $cells[0] = new html_table_cell(html_writer::checkbox('selectallcb', 1, false)); $cells[0]->attributes['class'] = 'centered_cell centered_cb_cell'; $cells[0]->attributes['width'] = "100px"; @@ -275,13 +275,13 @@ $table->head = $cells; // Include table within form. - $elements[] = array('html', html_writer::table($table)); + $elements[] = ['html', html_writer::table($table)]; $customdata["elements"] = $elements; $customdata["hide_submit"] = true; - $multisubmitbuttons = array( - array('unlink', get_string('unlinkusers', 'plagiarism_turnitin')), - array('relink', get_string('relinkusers', 'plagiarism_turnitin'))); + $multisubmitbuttons = [ + ['unlink', get_string('unlinkusers', 'plagiarism_turnitin')], + ['relink', get_string('relinkusers', 'plagiarism_turnitin')]]; $customdata["multi_submit_buttons"] = $multisubmitbuttons; require_once($CFG->dirroot.'/plagiarism/turnitin/classes/forms/turnitin_form.class.php'); @@ -303,19 +303,19 @@ if ($resubmitted == "success") { echo html_writer::tag("div", get_string('pperrorssuccess', 'plagiarism_turnitin'), - array('class' => 'pp_errors_success')); + ['class' => 'pp_errors_success']); } else if ($resubmitted == "errors") { echo html_writer::tag("div", get_string('pperrorsfail', 'plagiarism_turnitin'), - array('class' => 'pp_errors_warning')); + ['class' => 'pp_errors_warning']); } echo html_writer::tag("button", get_string('resubmitselected', 'plagiarism_turnitin'), - array("class" => "btn btn-primary pp-resubmit-files", "disabled" => "disabled")); + ["class" => "btn btn-primary pp-resubmit-files", "disabled" => "disabled"]); echo $turnitinview->show_file_errors_table($page); echo html_writer::tag("button", get_string('resubmitselected', 'plagiarism_turnitin'), - array("class" => "btn btn-primary pp-resubmit-files", "disabled" => "disabled")); + ["class" => "btn btn-primary pp-resubmit-files", "disabled" => "disabled"]); break; } diff --git a/tests/behat/behat_plagiarism_turnitin.php b/tests/behat/behat_plagiarism_turnitin.php index b113a7c7..5cc963de 100644 --- a/tests/behat/behat_plagiarism_turnitin.php +++ b/tests/behat/behat_plagiarism_turnitin.php @@ -100,13 +100,13 @@ public function i_configure_turnitin_credentials() { */ public function i_create_a_unique_user($username) { $generator = testing_util::get_data_generator(); - $generator->create_user(array( + $generator->create_user([ 'email' => uniqid($username, true) . '@example.com', 'username' => $username, 'password' => $username, 'firstname' => $username, 'lastname' => $username - )); + ]); } /** @@ -171,11 +171,11 @@ public function i_obtain_an_originality_report_for_student_on_modtype_assignment try { switch($modtype) { case "assignment": - $this->execute('behat_general::row_column_of_table_should_contain', array($student, "File submissions", "generaltable", "%")); + $this->execute('behat_general::row_column_of_table_should_contain', [$student, "File submissions", "generaltable", "%"]); break; case "forum": case "workshop": - $this->execute('behat_general::assert_element_contains_text', array("%", "div.origreport_score", "css_element")); + $this->execute('behat_general::assert_element_contains_text', ["%", "div.origreport_score", "css_element"]); break; } break; @@ -195,10 +195,10 @@ public function i_accept_the_turnitin_eula_if_necessary() { try { $this->getSession()->getPage()->find("css", ".pp_turnitin_eula_link"); - $this->execute('behat_general::i_click_on', array(".pp_turnitin_eula_link", "css_element")); - $this->execute('behat_general::wait_until_exists', array(".iframe-ltilaunch-eula", "css_element")); + $this->execute('behat_general::i_click_on', [".pp_turnitin_eula_link", "css_element"]); + $this->execute('behat_general::wait_until_exists', [".iframe-ltilaunch-eula", "css_element"]); $this->i_switch_to_iframe_with_locator(".iframe-ltilaunch-eula"); - $this->execute('behat_general::i_click_on', array(".agree-button", "css_element")); + $this->execute('behat_general::i_click_on', [".agree-button", "css_element"]); } catch (Exception $e) { // EULA not found - so skip it. } @@ -211,7 +211,7 @@ public function i_accept_the_turnitin_eula_from_the_ev_if_necessary() { try { $this->getSession()->getPage()->find("css", ".agree-button"); - $this->execute('behat_general::i_click_on', array(".agree-button", "css_element")); + $this->execute('behat_general::i_click_on', [".agree-button", "css_element"]); } catch (Exception $e) { // EULA not found - so skip it. } @@ -246,7 +246,7 @@ public function click_save_changes_button($selector, $locator, $exception = fals * @throws Exception */ public function the_following_users_will_be_created_if_they_do_not_already_exist(TableNode $data) { - $newdata = array(); + $newdata = []; $rowNum = 0; foreach ($data->getRows() as $row) { if (!$rowNum == 0) { // not header row @@ -256,7 +256,7 @@ public function the_following_users_will_be_created_if_they_do_not_already_exist $newdata[] = $row; } $tablenode = new TableNode($newdata); - $this->execute('behat_data_generators::the_following_entities_exist', array('users', $tablenode)); + $this->execute('behat_data_generators::the_following_entities_exist', ['users', $tablenode]); } /** @@ -266,12 +266,12 @@ public function the_following_users_will_be_created_if_they_do_not_already_exist public function i_unenroll_the_user_account_with_the_role_from_the_class_in_turnitin($student, $role) { global $DB; - $course = $DB->get_record("course", array("fullname" => "Turnitin Behat EULA Test Course"), 'id', MUST_EXIST); - $tiicourse = $DB->get_record('plagiarism_turnitin_courses', array("courseid" => $course->id), 'turnitin_cid', MUST_EXIST); + $course = $DB->get_record("course", ["fullname" => "Turnitin Behat EULA Test Course"], 'id', MUST_EXIST); + $tiicourse = $DB->get_record('plagiarism_turnitin_courses', ["courseid" => $course->id], 'turnitin_cid', MUST_EXIST); // Get the user. - $user = $DB->get_record("user", array("username" => $student), 'id', MUST_EXIST); - $tiiuser = $DB->get_record('plagiarism_turnitin_users', array("userid" => $user->id), 'turnitin_uid', MUST_EXIST); + $user = $DB->get_record("user", ["username" => $student], 'id', MUST_EXIST); + $tiiuser = $DB->get_record('plagiarism_turnitin_users', ["userid" => $user->id], 'turnitin_uid', MUST_EXIST); $turnitincall = $this->behat_initialise_api(getenv('TII_ACCOUNT'), getenv('TII_SECRET'), getenv('TII_APIBASEURL')); diff --git a/tests/classes/turnitin_assignment_class_test.php b/tests/classes/turnitin_assignment_class_test.php index 44d0850e..e6876d01 100644 --- a/tests/classes/turnitin_assignment_class_test.php +++ b/tests/classes/turnitin_assignment_class_test.php @@ -93,8 +93,8 @@ public function test_create_tii_course() { ->with(""); $mock = $this->getMockBuilder('turnitin_assignment') - ->setMethods(array('api_create_class', 'api_get_class', 'api_get_class_id')) - ->setConstructorArgs(array(0, $faketiicomms)) + ->setMethods(['api_create_class', 'api_get_class', 'api_get_class_id']) + ->setConstructorArgs([0, $faketiicomms]) ->getMock(); $mock->expects($this->any()) @@ -145,8 +145,8 @@ public function test_edit_tii_course() { ->with(""); $mock = $this->getMockBuilder('turnitin_assignment') - ->setMethods(array('api_update_class', 'api_set_class_id')) - ->setConstructorArgs(array(0, $faketiicomms)) + ->setMethods(['api_update_class', 'api_set_class_id']) + ->setConstructorArgs([0, $faketiicomms]) ->getMock(); // Edit a PP course. @@ -159,7 +159,7 @@ public function test_edit_tii_course() { // As the method does not return anything we will have to check the database before assertion. $mock->edit_tii_course($editcourse); - $responsecourse = $DB->get_record("plagiarism_turnitin_courses", array("id" => $course->id)); + $responsecourse = $DB->get_record("plagiarism_turnitin_courses", ["id" => $course->id]); $expected = new stdClass(); $expected->id = $course->id; @@ -204,8 +204,8 @@ public function test_create_tii_assignment() { ->with(""); $mock = $this->getMockBuilder('turnitin_assignment') - ->setMethods(array('api_create_assignment', 'api_get_assignment', 'api_get_assignment_id')) - ->setConstructorArgs(array(0, $faketiicomms)) + ->setMethods(['api_create_assignment', 'api_get_assignment', 'api_get_assignment_id']) + ->setConstructorArgs([0, $faketiicomms]) ->getMock(); $mock->expects($this->any()) @@ -242,8 +242,8 @@ public function test_edit_tii_assignment() { ->withAnyParameters(); $mock = $this->getMockBuilder('turnitin_assignment') - ->setMethods(array('api_update_assignment', 'api_get_assignment_id', 'api_get_title')) - ->setConstructorArgs(array(0, $faketiicomms)) + ->setMethods(['api_update_assignment', 'api_get_assignment_id', 'api_get_title']) + ->setConstructorArgs([0, $faketiicomms]) ->getMock(); $mock->expects($this->any()) diff --git a/tests/classes/turnitin_user_class_test.php b/tests/classes/turnitin_user_class_test.php index d94a4448..7ab855b9 100644 --- a/tests/classes/turnitin_user_class_test.php +++ b/tests/classes/turnitin_user_class_test.php @@ -82,7 +82,7 @@ public function test_get_pseudo_lastname() { $this->resetAfterTest(); $student = $this->getDataGenerator()->create_user(); - $DB->insert_record('user_info_data', array('userid' => $student->id, 'fieldid' => 1, 'data' => 'Student', 'dataformat' => 0)); + $DB->insert_record('user_info_data', ['userid' => $student->id, 'fieldid' => 1, 'data' => 'Student', 'dataformat' => 0]); set_config('plagiarism_turnitin_pseudolastname', 1, 'plagiarism_turnitin'); set_config('plagiarism_turnitin_lastnamegen', 1, 'plagiarism_turnitin'); @@ -97,7 +97,7 @@ public function test_unlink_user() { $this->resetAfterTest(); - $roles = array("Learner"); + $roles = ["Learner"]; $testuser = $this->make_test_users(1, $roles, 1); // Check that we have a user. @@ -109,7 +109,7 @@ public function test_unlink_user() { $turnitinuser->unlink_user($testuser["joins"][0]); // We should have a Turnitin user ID of 0. - $user = $DB->get_record('plagiarism_turnitin_users', array('id' => $testuser["joins"][0])); + $user = $DB->get_record('plagiarism_turnitin_users', ['id' => $testuser["joins"][0]]); $this->assertEquals(0, $user->turnitin_uid); } } diff --git a/tests/generator/lib.php b/tests/generator/lib.php index 911eb161..6e6cff8f 100644 --- a/tests/generator/lib.php +++ b/tests/generator/lib.php @@ -44,8 +44,8 @@ abstract class plagiarism_turnitin_test_lib extends advanced_testcase { * @return object $return - object of two arrays of equal length, one full of plagiarism_turnitin_user types and the other with ids for dbtable plagiarism_turnitin_users. The indices of these arrays DO align. */ public function make_test_users($number_of_users, $roles) { - $return['plagiarism_turnitin_users'] = array(); - $return['joins'] = array(); + $return['plagiarism_turnitin_users'] = []; + $return['joins'] = []; for ($i=0; $i < $number_of_users; $i++) { $role = isset($roles[$i]) ? $roles[$i] : 'Instructor'; diff --git a/tests/lib_test.php b/tests/lib_test.php index 8dc89b3e..cf374831 100644 --- a/tests/lib_test.php +++ b/tests/lib_test.php @@ -66,14 +66,14 @@ public function test_check_group_submission() { $this->resetAfterTest(true); - $result = $this->create_assign_with_student_and_teacher(array( + $result = $this->create_assign_with_student_and_teacher([ 'assignsubmission_onlinetext_enabled' => 1, 'teamsubmission' => 1 - )); + ]); $assignmodule = $result['assign']; $student = $result['student']; $course = $result['course']; - $group = $this->getDataGenerator()->create_group(array('courseid' => $course->id)); + $group = $this->getDataGenerator()->create_group(['courseid' => $course->id]); $cm = get_coursemodule_from_instance('assign', $assignmodule->id); $context = context_module::instance($cm->id); $assign = new testable_assign($context, $cm, $course); @@ -85,9 +85,9 @@ public function test_check_group_submission() { $submission->status = ASSIGN_SUBMISSION_STATUS_SUBMITTED; $assign->testable_update_submission($submission, $student->id, true, false); $data = new stdClass(); - $data->onlinetext_editor = array('itemid' => file_get_unused_draft_itemid(), + $data->onlinetext_editor = ['itemid' => file_get_unused_draft_itemid(), 'text' => 'Submission text', - 'format' => FORMAT_MOODLE); + 'format' => FORMAT_MOODLE]; $plugin = $assign->get_submission_plugin_by_type('onlinetext'); $plugin->save($submission, $data); @@ -98,10 +98,10 @@ public function test_check_group_submission() { $this->assertEquals($group->id, $response); // Test a non-group submission. - $result = $this->create_assign_with_student_and_teacher(array( + $result = $this->create_assign_with_student_and_teacher([ 'assignsubmission_onlinetext_enabled' => 1, 'teamsubmission' => 0 - )); + ]); $assignmodule = $result['assign']; $student = $result['student']; $course = $result['course']; @@ -114,9 +114,9 @@ public function test_check_group_submission() { $submission->status = ASSIGN_SUBMISSION_STATUS_SUBMITTED; $assign->testable_update_submission($submission, $student->id, true, false); $data = new stdClass(); - $data->onlinetext_editor = array('itemid' => file_get_unused_draft_itemid(), + $data->onlinetext_editor = ['itemid' => file_get_unused_draft_itemid(), 'text' => 'Submission text', - 'format' => FORMAT_MOODLE); + 'format' => FORMAT_MOODLE]; $plugin = $assign->get_submission_plugin_by_type('onlinetext'); $plugin->save($submission, $data); @@ -134,15 +134,15 @@ public function test_check_group_submission() { * @param array $params parameters to be provided to the assignment module creation * @return array containing the course, assignment module, student and teacher */ - public function create_assign_with_student_and_teacher($params = array()) { + public function create_assign_with_student_and_teacher($params = []) { global $DB; $course = $this->getDataGenerator()->create_course(); - $params = array_merge(array( + $params = array_merge([ 'course' => $course->id, 'name' => 'assignment', 'intro' => 'assignment intro text', - ), $params); + ], $params); // Create a course and assignment and users. $assign = $this->getDataGenerator()->create_module('assign', $params); @@ -151,10 +151,10 @@ public function create_assign_with_student_and_teacher($params = array()) { $context = context_module::instance($cm->id); $student = $this->getDataGenerator()->create_user(); - $studentrole = $DB->get_record('role', array('shortname' => 'student')); + $studentrole = $DB->get_record('role', ['shortname' => 'student']); $this->getDataGenerator()->enrol_user($student->id, $course->id, $studentrole->id); $teacher = $this->getDataGenerator()->create_user(); - $teacherrole = $DB->get_record('role', array('shortname' => 'teacher')); + $teacherrole = $DB->get_record('role', ['shortname' => 'teacher']); $this->getDataGenerator()->enrol_user($teacher->id, $course->id, $teacherrole->id); assign_capability('mod/assign:view', CAP_ALLOW, $teacherrole->id, $context->id, true); @@ -162,12 +162,12 @@ public function create_assign_with_student_and_teacher($params = array()) { assign_capability('mod/assign:grade', CAP_ALLOW, $teacherrole->id, $context->id, true); accesslib_clear_all_caches_for_unit_testing(); - return array( + return [ 'course' => $course, 'assign' => $assign, 'student' => $student, 'teacher' => $teacher - ); + ]; } /** diff --git a/tests/modules/turnitin_assign_test.php b/tests/modules/turnitin_assign_test.php index 2cf26160..4ec12c5b 100644 --- a/tests/modules/turnitin_assign_test.php +++ b/tests/modules/turnitin_assign_test.php @@ -46,13 +46,13 @@ class plagiarism_turnitin_assign_testcase extends advanced_testcase { */ public function setUp(): void { $this->course = $this->getDataGenerator()->create_course(); - $params = array( + $params = [ 'course' => $this->course->id, 'name' => 'assignment', 'assignsubmission_file_enabled' => 1, 'assignsubmission_file_maxfiles' => 1, 'assignsubmission_file_maxsizebytes' => 10 - ); + ]; $this->assign = $this->getDataGenerator()->create_module('assign', $params); } @@ -92,13 +92,13 @@ public function test_check_is_resubmission_allowed() { public function test_check_is_resubmission_allowed_maxfiles_above_threshold() { $this->resetAfterTest(true); - $params = array( + $params = [ 'course' => $this->course->id, 'name' => 'assignment', 'assignsubmission_file_enabled' => 1, 'assignsubmission_file_maxfiles' => 2, 'assignsubmission_file_maxsizebytes' => 10 - ); + ]; $assign = $this->getDataGenerator()->create_module('assign', $params); diff --git a/tests/modules/turnitin_forum_test.php b/tests/modules/turnitin_forum_test.php index e2058654..b27df9d8 100644 --- a/tests/modules/turnitin_forum_test.php +++ b/tests/modules/turnitin_forum_test.php @@ -80,9 +80,9 @@ public function test_to_check_content_in_array_is_returned_by_set_content() { // Create module object. $moduleobject = new turnitin_forum(); - $params = array( + $params = [ 'content' => $this->post->message - ); + ]; $content = $moduleobject->set_content($params); $this->assertEquals($content, $this->post->message); @@ -99,10 +99,10 @@ public function test_to_check_content_from_database_is_returned_by_set_content_i // Create module object. $moduleobject = new turnitin_forum(); - $params = array( + $params = [ 'content' => 'content should not come back', 'postid' => $this->post->id - ); + ]; $content = $moduleobject->set_content($params); $this->assertEquals($content, $this->post->message); diff --git a/tests/privacy/provider_test.php b/tests/privacy/provider_test.php index 322bf07d..1e33f81c 100644 --- a/tests/privacy/provider_test.php +++ b/tests/privacy/provider_test.php @@ -123,7 +123,7 @@ public function test_export_plagiarism_user_data() { $this->assertEquals(1, count($submissions)); // Export all of the data for the user. - provider::export_plagiarism_user_data($csresponse["Student"]->id, $csresponse["Context"], array(), array()); + provider::export_plagiarism_user_data($csresponse["Student"]->id, $csresponse["Context"], [], []); $writer = \core_privacy\local\request\writer::with_context($csresponse["Context"]); $this->assertTrue($writer->has_any_data()); } @@ -170,10 +170,10 @@ public function create_submission($numsubmissions = 1) { require_once($CFG->dirroot . '/mod/assign/tests/base_test.php'); $libtest = new plagiarism_turnitin_lib_testcase(); - $result = $libtest->create_assign_with_student_and_teacher(array( + $result = $libtest->create_assign_with_student_and_teacher([ 'assignsubmission_onlinetext_enabled' => 1, 'teamsubmission' => 0 - )); + ]); $assignmodule = $result['assign']; $student = $result['student']; @@ -200,6 +200,6 @@ public function create_submission($numsubmissions = 1) { $this->setUser($student); - return array("Student" => $student, "Context" => $context); + return ["Student" => $student, "Context" => $context]; } } \ No newline at end of file From 17a83a96747ae5c148cb99967bc04d3e6aeaa616 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luca=20B=C3=B6sch?= Date: Thu, 25 Jul 2024 13:45:00 +0200 Subject: [PATCH 03/15] Fix 'File must end with a newline character' errors. --- backup/moodle2/backup_plagiarism_turnitin_plugin.class.php | 2 +- backup/moodle2/restore_plagiarism_turnitin_plugin.class.php | 2 +- classes/forms/turnitin_defaultsettingsform.class.php | 2 +- classes/forms/turnitin_form.class.php | 2 +- classes/modules/turnitin_assign.class.php | 2 +- classes/modules/turnitin_coursework.class.php | 2 +- classes/modules/turnitin_forum.class.php | 2 +- classes/modules/turnitin_workshop.class.php | 2 +- classes/observer.php | 2 +- classes/privacy/provider.php | 2 +- classes/task/send_submissions.php | 2 +- classes/task/update_reports.php | 2 +- classes/turnitin_assignment.class.php | 2 +- classes/turnitin_class.class.php | 2 +- classes/turnitin_submission.class.php | 2 +- classes/turnitin_user.class.php | 2 +- db/tasks.php | 2 +- dbexport.php | 2 +- locallib.php | 2 +- settings.php | 2 +- tests/lib_test.php | 2 +- tests/locallib_test.php | 2 +- tests/privacy/provider_test.php | 2 +- 23 files changed, 23 insertions(+), 23 deletions(-) diff --git a/backup/moodle2/backup_plagiarism_turnitin_plugin.class.php b/backup/moodle2/backup_plagiarism_turnitin_plugin.class.php index cf2e0421..3acc37ad 100644 --- a/backup/moodle2/backup_plagiarism_turnitin_plugin.class.php +++ b/backup/moodle2/backup_plagiarism_turnitin_plugin.class.php @@ -62,4 +62,4 @@ protected function define_course_plugin_structure() { $turnitincourse->set_source_table('plagiarism_turnitin_courses', ['courseid' => backup::VAR_COURSEID]); return $plugin; } -} \ No newline at end of file +} diff --git a/backup/moodle2/restore_plagiarism_turnitin_plugin.class.php b/backup/moodle2/restore_plagiarism_turnitin_plugin.class.php index 4ea313b5..2f08cee2 100644 --- a/backup/moodle2/restore_plagiarism_turnitin_plugin.class.php +++ b/backup/moodle2/restore_plagiarism_turnitin_plugin.class.php @@ -111,4 +111,4 @@ public function process_turnitin_files($data) { } } } -} \ No newline at end of file +} diff --git a/classes/forms/turnitin_defaultsettingsform.class.php b/classes/forms/turnitin_defaultsettingsform.class.php index 434f5e1f..3004cfbd 100644 --- a/classes/forms/turnitin_defaultsettingsform.class.php +++ b/classes/forms/turnitin_defaultsettingsform.class.php @@ -40,4 +40,4 @@ public function definition () { $this->add_action_buttons(true); } -} \ No newline at end of file +} diff --git a/classes/forms/turnitin_form.class.php b/classes/forms/turnitin_form.class.php index 2cfc22d6..1a9bdb93 100644 --- a/classes/forms/turnitin_form.class.php +++ b/classes/forms/turnitin_form.class.php @@ -135,4 +135,4 @@ public function display() { return $form; } -} \ No newline at end of file +} diff --git a/classes/modules/turnitin_assign.class.php b/classes/modules/turnitin_assign.class.php index 8268face..6bdfe2a0 100644 --- a/classes/modules/turnitin_assign.class.php +++ b/classes/modules/turnitin_assign.class.php @@ -143,4 +143,4 @@ public function get_current_gradequery($userid, $moduleid, $itemid = 0) { public function initialise_post_date($moduledata) { return 0; } -} \ No newline at end of file +} diff --git a/classes/modules/turnitin_coursework.class.php b/classes/modules/turnitin_coursework.class.php index 788e68ac..3631e503 100644 --- a/classes/modules/turnitin_coursework.class.php +++ b/classes/modules/turnitin_coursework.class.php @@ -88,4 +88,4 @@ public function get_current_gradequery($userid, $moduleid, $itemid = 0) { public function initialise_post_date($moduledata) { return 0; } -} \ No newline at end of file +} diff --git a/classes/modules/turnitin_forum.class.php b/classes/modules/turnitin_forum.class.php index fe0d4e40..94cc3b10 100644 --- a/classes/modules/turnitin_forum.class.php +++ b/classes/modules/turnitin_forum.class.php @@ -98,4 +98,4 @@ public function get_discussionid($forumdata) { return $discussionid; } -} \ No newline at end of file +} diff --git a/classes/modules/turnitin_workshop.class.php b/classes/modules/turnitin_workshop.class.php index 145d6197..138627dc 100644 --- a/classes/modules/turnitin_workshop.class.php +++ b/classes/modules/turnitin_workshop.class.php @@ -86,4 +86,4 @@ public function get_current_gradequery($userid, $moduleid, $itemid = 0) { public function initialise_post_date($moduledata) { return $moduledata->assessmentend; } -} \ No newline at end of file +} diff --git a/classes/observer.php b/classes/observer.php index 7778e03b..82d285f8 100644 --- a/classes/observer.php +++ b/classes/observer.php @@ -158,4 +158,4 @@ public static function quiz_submitted( $plugin = new plagiarism_plugin_turnitin(); $plugin->event_handler($eventdata); } -} \ No newline at end of file +} diff --git a/classes/privacy/provider.php b/classes/privacy/provider.php index efa0864e..4d4f1553 100644 --- a/classes/privacy/provider.php +++ b/classes/privacy/provider.php @@ -285,4 +285,4 @@ public static function delete_data_for_users(approved_userlist $userlist) { $DB->delete_records_list('plagiarism_turnitin', 'id', array_values($attempt)); } -} \ No newline at end of file +} diff --git a/classes/task/send_submissions.php b/classes/task/send_submissions.php index 24c90d6a..feb64051 100644 --- a/classes/task/send_submissions.php +++ b/classes/task/send_submissions.php @@ -45,4 +45,4 @@ public function execute() { } plagiarism_turnitin_send_queued_submissions(); } -} \ No newline at end of file +} diff --git a/classes/task/update_reports.php b/classes/task/update_reports.php index 1a71701a..09ea5d52 100644 --- a/classes/task/update_reports.php +++ b/classes/task/update_reports.php @@ -45,4 +45,4 @@ public function execute() { } plagiarism_turnitin_update_reports(); } -} \ No newline at end of file +} diff --git a/classes/turnitin_assignment.class.php b/classes/turnitin_assignment.class.php index ed427975..868ff043 100644 --- a/classes/turnitin_assignment.class.php +++ b/classes/turnitin_assignment.class.php @@ -386,4 +386,4 @@ public function api_get_assignment_id($assignment) { public function api_get_title($assignment) { return $assignment->getTitle(); } -} \ No newline at end of file +} diff --git a/classes/turnitin_class.class.php b/classes/turnitin_class.class.php index a8e8d090..42311b08 100644 --- a/classes/turnitin_class.class.php +++ b/classes/turnitin_class.class.php @@ -71,4 +71,4 @@ public function read_class_from_tii() { $turnitincomms->handle_exceptions($e, 'coursegeterror', false); } } -} \ No newline at end of file +} diff --git a/classes/turnitin_submission.class.php b/classes/turnitin_submission.class.php index 73037abe..c89b37c8 100644 --- a/classes/turnitin_submission.class.php +++ b/classes/turnitin_submission.class.php @@ -162,4 +162,4 @@ public function get_file_info() { return $file; } -} \ No newline at end of file +} diff --git a/classes/turnitin_user.class.php b/classes/turnitin_user.class.php index 6974e1f2..b01dc8d6 100644 --- a/classes/turnitin_user.class.php +++ b/classes/turnitin_user.class.php @@ -649,4 +649,4 @@ public static function plagiarism_turnitin_getusers() { $return["iTotalDisplayRecords"] = $totalusers; return $return; } -} \ No newline at end of file +} diff --git a/db/tasks.php b/db/tasks.php index b2d26fb2..625f11bc 100644 --- a/db/tasks.php +++ b/db/tasks.php @@ -44,4 +44,4 @@ 'dayofweek' => '*', 'month' => '*' ], -]; \ No newline at end of file +]; diff --git a/dbexport.php b/dbexport.php index 312919b3..ef871679 100644 --- a/dbexport.php +++ b/dbexport.php @@ -89,4 +89,4 @@ $turnitinview->draw_settings_tab_menu('dbexport'); echo $output; -echo $OUTPUT->footer(); \ No newline at end of file +echo $OUTPUT->footer(); diff --git a/locallib.php b/locallib.php index 79310761..8eaaa0d9 100644 --- a/locallib.php +++ b/locallib.php @@ -96,4 +96,4 @@ function plagiarism_turnitin_lock_anonymous_marking($cmid) { 'plagiarism_turnitin', null, null, __FILE__, __LINE__); } } -} \ No newline at end of file +} diff --git a/settings.php b/settings.php index c303fe79..821034c0 100644 --- a/settings.php +++ b/settings.php @@ -319,4 +319,4 @@ break; } -echo $OUTPUT->footer(); \ No newline at end of file +echo $OUTPUT->footer(); diff --git a/tests/lib_test.php b/tests/lib_test.php index cf374831..2c1dcdfc 100644 --- a/tests/lib_test.php +++ b/tests/lib_test.php @@ -228,4 +228,4 @@ public function test_plagiarism_set_config() { $this->assertObjectNotHasProperty("plagiarism_turnitin_test", $config); } -} \ No newline at end of file +} diff --git a/tests/locallib_test.php b/tests/locallib_test.php index f164eceb..70517a64 100644 --- a/tests/locallib_test.php +++ b/tests/locallib_test.php @@ -70,4 +70,4 @@ public function test_plagiarism_turnitin_override_repository() { $response = plagiarism_turnitin_override_repository($submitpapersto); $this->assertEquals(PLAGIARISM_TURNITIN_SUBMIT_TO_INSTITUTIONAL_REPOSITORY, $response); } -} \ No newline at end of file +} diff --git a/tests/privacy/provider_test.php b/tests/privacy/provider_test.php index 1e33f81c..3241c9f0 100644 --- a/tests/privacy/provider_test.php +++ b/tests/privacy/provider_test.php @@ -202,4 +202,4 @@ public function create_submission($numsubmissions = 1) { return ["Student" => $student, "Context" => $context]; } -} \ No newline at end of file +} From e0392cef5e0ffebbdd016117bff374542a1887bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luca=20B=C3=B6sch?= Date: Thu, 25 Jul 2024 13:53:17 +0200 Subject: [PATCH 04/15] Fix 'Comma after the last array item in a multi-line array.' errors. --- ajax.php | 6 +- ...ackup_plagiarism_turnitin_plugin.class.php | 2 +- classes/forms/turnitin_setupform.class.php | 8 +-- classes/modules/turnitin_assign.class.php | 2 +- classes/modules/turnitin_coursework.class.php | 2 +- classes/privacy/provider.php | 8 +-- classes/turnitin_comms.class.php | 2 +- classes/turnitin_submission.class.php | 14 ++-- classes/turnitin_user.class.php | 2 +- classes/turnitin_view.class.php | 18 ++--- db/access.php | 8 +-- db/events.php | 20 +++--- db/messages.php | 2 +- db/tasks.php | 4 +- db/upgrade.php | 2 +- dbexport.php | 2 +- lib.php | 72 +++++++++---------- settings.php | 2 +- tests/behat/behat_plagiarism_turnitin.php | 2 +- tests/lib_test.php | 10 +-- tests/modules/turnitin_assign_test.php | 4 +- tests/modules/turnitin_forum_test.php | 4 +- tests/privacy/provider_test.php | 2 +- 23 files changed, 99 insertions(+), 99 deletions(-) diff --git a/ajax.php b/ajax.php index 1ea6feb9..0993611a 100644 --- a/ajax.php +++ b/ajax.php @@ -150,7 +150,7 @@ turnitin_view::output_lti_form_launch('peermark_manager', 'Instructor', $tiiassignmentid), [ 'class' => 'launch_form', - 'style' => 'display:none;' + 'style' => 'display:none;', ] ); @@ -177,7 +177,7 @@ turnitin_view::output_lti_form_launch('rubric_view', 'Learner', $tiiassignment->value), [ 'class' => 'launch_form', - 'style' => 'display:none;' + 'style' => 'display:none;', ] ); @@ -204,7 +204,7 @@ turnitin_view::output_lti_form_launch('peermark_reviews', $userrole, $tiiassignment->value), [ 'class' => 'launch_form', - 'style' => 'display:none;' + 'style' => 'display:none;', ] ); diff --git a/backup/moodle2/backup_plagiarism_turnitin_plugin.class.php b/backup/moodle2/backup_plagiarism_turnitin_plugin.class.php index 3acc37ad..ca4aa484 100644 --- a/backup/moodle2/backup_plagiarism_turnitin_plugin.class.php +++ b/backup/moodle2/backup_plagiarism_turnitin_plugin.class.php @@ -37,7 +37,7 @@ protected function define_module_plugin_structure() { $turnitinfiles = new backup_nested_element('turnitin_files'); $turnitinfile = new backup_nested_element('turnitin_file', ['id'], ['userid', 'identifier', 'externalid', 'externalstatus', - 'statuscode', 'similarityscore', 'transmatch', 'lastmodified', 'grade', 'submissiontype']); + 'statuscode', 'similarityscore', 'transmatch', 'lastmodified', 'grade', 'submissiontype',]); $pluginelement->add_child($turnitinfiles); $turnitinfiles->add_child($turnitinfile); diff --git a/classes/forms/turnitin_setupform.class.php b/classes/forms/turnitin_setupform.class.php index d20f20a1..c57b432d 100644 --- a/classes/forms/turnitin_setupform.class.php +++ b/classes/forms/turnitin_setupform.class.php @@ -70,7 +70,7 @@ public function definition() { $options = [ 'https://api.turnitin.com' => 'https://api.turnitin.com', 'https://api.turnitinuk.com' => 'https://api.turnitinuk.com', - 'https://sandbox.turnitin.com' => 'https://sandbox.turnitin.com' + 'https://sandbox.turnitin.com' => 'https://sandbox.turnitin.com', ]; // Set $CFG->turnitinqa and add URLs to $CFG->turnitinqaurls array in config.php file for testing other environments. @@ -91,7 +91,7 @@ public function definition() { $diagnosticoptions = [ 0 => get_string('diagnosticoptions_0', 'plagiarism_turnitin'), 1 => get_string('diagnosticoptions_1', 'plagiarism_turnitin'), - 2 => get_string('diagnosticoptions_2', 'plagiarism_turnitin') + 2 => get_string('diagnosticoptions_2', 'plagiarism_turnitin'), ]; // Debugging and logging settings. @@ -125,7 +125,7 @@ public function definition() { PLAGIARISM_TURNITIN_ADMIN_REPOSITORY_OPTION_EXPANDED => get_string('repositoryoptions_1', 'plagiarism_turnitin'), PLAGIARISM_TURNITIN_ADMIN_REPOSITORY_OPTION_FORCE_STANDARD => get_string('repositoryoptions_2', 'plagiarism_turnitin'), PLAGIARISM_TURNITIN_ADMIN_REPOSITORY_OPTION_FORCE_NO => get_string('repositoryoptions_3', 'plagiarism_turnitin'), - PLAGIARISM_TURNITIN_ADMIN_REPOSITORY_OPTION_FORCE_INSTITUTIONAL => get_string('repositoryoptions_4', 'plagiarism_turnitin') + PLAGIARISM_TURNITIN_ADMIN_REPOSITORY_OPTION_FORCE_INSTITUTIONAL => get_string('repositoryoptions_4', 'plagiarism_turnitin'), ]; $mform->addElement('select', 'plagiarism_turnitin_repositoryoption', get_string('turnitinrepositoryoptions', 'plagiarism_turnitin'), $repositoryoptions); @@ -239,7 +239,7 @@ public function save($data) { $properties = ["accountid", "secretkey", "apiurl", "enablediagnostic", "usegrademark", "enablepeermark", "useanon", "transmatch", "repositoryoption", "agreement", "enablepseudo", "pseudofirstname", - "pseudolastname", "lastnamegen", "pseudosalt", "pseudoemaildomain"]; + "pseudolastname", "lastnamegen", "pseudosalt", "pseudoemaildomain",]; foreach ($properties as $property) { plagiarism_plugin_turnitin::plagiarism_set_config($data, "plagiarism_turnitin_".$property); diff --git a/classes/modules/turnitin_assign.class.php b/classes/modules/turnitin_assign.class.php index 6bdfe2a0..8837cd46 100644 --- a/classes/modules/turnitin_assign.class.php +++ b/classes/modules/turnitin_assign.class.php @@ -76,7 +76,7 @@ public function is_resubmission_allowed($assignid, $reportgenspeed, $submissiont $params = ['assignment' => $assignid, 'subtype' => 'assignsubmission', 'plugin' => 'file', - 'name' => 'maxfilesubmissions']; + 'name' => 'maxfilesubmissions',]; $maxfilesubmissions = 0; if ($result = $DB->get_record('assign_plugin_config', $params, 'value')) { diff --git a/classes/modules/turnitin_coursework.class.php b/classes/modules/turnitin_coursework.class.php index 3631e503..f3f24ecf 100644 --- a/classes/modules/turnitin_coursework.class.php +++ b/classes/modules/turnitin_coursework.class.php @@ -36,7 +36,7 @@ public function __construct() { public function is_tutor($context) { $capabilities = [$this->get_tutor_capability(), 'mod/coursework:addagreedgrade', - 'mod/coursework:addallocatedagreedgrade', 'mod/coursework:administergrades']; + 'mod/coursework:addallocatedagreedgrade', 'mod/coursework:administergrades',]; return has_any_capability($capabilities, $context); } diff --git a/classes/privacy/provider.php b/classes/privacy/provider.php index 4d4f1553..06a2c504 100644 --- a/classes/privacy/provider.php +++ b/classes/privacy/provider.php @@ -81,7 +81,7 @@ public static function _get_metadata(collection $collection) { 'turnitin_uid' => 'privacy:metadata:plagiarism_turnitin_users:turnitin_uid', 'instructor_defaults' => 'privacy:metadata:plagiarism_turnitin_users:instructor_defaults', 'instructor_rubrics' => 'privacy:metadata:plagiarism_turnitin_users:instructor_rubrics', - 'user_agreement_accepted' => 'privacy:metadata:plagiarism_turnitin_users:user_agreement_accepted' + 'user_agreement_accepted' => 'privacy:metadata:plagiarism_turnitin_users:user_agreement_accepted', ], 'privacy:metadata:plagiarism_turnitin_users' ); @@ -108,7 +108,7 @@ public static function _get_contexts_for_userid($userid) { $params = ['modulename' => 'assign', 'contextlevel' => CONTEXT_MODULE, - 'userid' => $userid]; + 'userid' => $userid,]; $sql = "SELECT ctx.id FROM {course_modules} cm @@ -241,7 +241,7 @@ public static function get_users_in_context(userlist $userlist) { $params = [ 'modname' => 'plagiarism_turnitin', - 'cmid' => $context->instanceid + 'cmid' => $context->instanceid, ]; $userlist->add_from_sql('userid', $sql, $params); @@ -276,7 +276,7 @@ public static function delete_data_for_users(approved_userlist $userlist) { $params = [ 'modname' => 'plagiarism_turnitin', - 'cmid' => $context->instanceid + 'cmid' => $context->instanceid, ]; $params = array_merge($params, $inparams); diff --git a/classes/turnitin_comms.class.php b/classes/turnitin_comms.class.php index 968257ac..067d346e 100644 --- a/classes/turnitin_comms.class.php +++ b/classes/turnitin_comms.class.php @@ -188,7 +188,7 @@ private function get_lang() { 'sv' => 'sv', 'nl' => 'nl', 'fi' => 'fi', - 'ar' => 'ar' + 'ar' => 'ar', ]; $langcode = (isset($langarray[$langcode])) ? $langarray[$langcode] : 'en_us'; return $langcode; diff --git a/classes/turnitin_submission.class.php b/classes/turnitin_submission.class.php index c89b37c8..44ff293c 100644 --- a/classes/turnitin_submission.class.php +++ b/classes/turnitin_submission.class.php @@ -62,8 +62,8 @@ public function recreate_submission_event() { 'userid' => $this->submissiondata->userid, 'other' => [ 'content' => '', - 'pathnamehashes' => [$this->submissiondata->identifier] - ] + 'pathnamehashes' => [$this->submissiondata->identifier], + ], ]; // Forum attachments need the discussion id to be set. if ($this->cm->modname == "forum") { @@ -93,8 +93,8 @@ public function recreate_submission_event() { 'other' => [ 'pathnamehashes' => [], 'content' => trim($onlinetextdata->onlinetext), - 'format' => $onlinetextdata->onlineformat - ] + 'format' => $onlinetextdata->onlineformat, + ], ]; $event = $moduleobject->create_text_event($params, $this->cm); @@ -115,7 +115,7 @@ public function recreate_submission_event() { WHERE FD.forum = ? AND FD.course = ? AND FP.userid = ? AND FP.message LIKE ? ', [$forum->id, $forum->course, - $this->submissiondata->userid, $this->data['forumpost']] + $this->submissiondata->userid, $this->data['forumpost'],] ); $discussionid = $discussion->id; } @@ -134,8 +134,8 @@ public function recreate_submission_event() { 'pathnamehashes' => '', 'content' => trim($this->data['forumpost']), 'discussionid' => $discussionid, - 'triggeredfrom' => 'turnitin_recreate_submission_event' - ] + 'triggeredfrom' => 'turnitin_recreate_submission_event', + ], ]; $event = \mod_forum\event\assessable_uploaded::create($params); $event->trigger(); diff --git a/classes/turnitin_user.class.php b/classes/turnitin_user.class.php index b01dc8d6..816e523c 100644 --- a/classes/turnitin_user.class.php +++ b/classes/turnitin_user.class.php @@ -471,7 +471,7 @@ public function set_user_values_from_tii() { "id" => $readuser->getUserId(), "firstname" => $readuser->getFirstName(), "lastname" => $readuser->getLastName(), - "email" => $readuser->getEmail() + "email" => $readuser->getEmail(), ]; return $tiiuser; diff --git a/classes/turnitin_view.class.php b/classes/turnitin_view.class.php index dbb7c931..89130231 100644 --- a/classes/turnitin_view.class.php +++ b/classes/turnitin_view.class.php @@ -125,7 +125,7 @@ public function add_elements_to_settings_form($mform, $course, $location = "acti 1 => get_string('reportgen_immediate_add_duedate', 'plagiarism_turnitin'), 2 => get_string('reportgen_duedate_add_duedate', 'plagiarism_turnitin')); $excludetypeoptions = array( 0 => get_string('no'), 1 => get_string('excludewords', 'plagiarism_turnitin'), - 2 => get_string('excludepercent', 'plagiarism_turnitin')]; + 2 => get_string('excludepercent', 'plagiarism_turnitin'),]; if ($location == "defaults") { $mform->addElement('header', 'turnitin_plugin_header', get_string('turnitindefaults', 'plagiarism_turnitin')); @@ -163,7 +163,7 @@ public function add_elements_to_settings_form($mform, $course, $location = "acti [ 'class' => 'plagiarism_turnitin_refresh_grades', 'tabindex' => 0, - 'role' => 'link' + 'role' => 'link', ] ); @@ -183,7 +183,7 @@ public function add_elements_to_settings_form($mform, $course, $location = "acti 'href' => '#', 'class' => 'plagiarism_turnitin_quickmark_manager_launch', 'id' => 'quickmark_manager_form', - 'tabindex' => 0 + 'tabindex' => 0, ] ); @@ -203,7 +203,7 @@ public function add_elements_to_settings_form($mform, $course, $location = "acti 'href' => '#', 'class' => 'peermark_manager_launch', 'id' => 'peermark_manager_form', - 'tabindex' => 0 + 'tabindex' => 0, ] ); $peermarkmanagerlink = html_writer::tag('div', $peermarkmanagerlink, ['class' => 'row_peermark_manager']); @@ -227,7 +227,7 @@ public function add_elements_to_settings_form($mform, $course, $location = "acti if ($mform->elementExists('submissiondrafts') || $location == 'defaults') { $tiidraftoptions = [0 => get_string("submitondraft", "plagiarism_turnitin"), - 1 => get_string("submitonfinal", "plagiarism_turnitin")]; + 1 => get_string("submitonfinal", "plagiarism_turnitin"),]; $mform->addElement('select', 'plagiarism_draft_submit', get_string("draftsubmit", "plagiarism_turnitin"), $tiidraftoptions); $this->lock($mform, $location, $locks); @@ -239,7 +239,7 @@ public function add_elements_to_settings_form($mform, $course, $location = "acti $mform->addHelpButton('plagiarism_allow_non_or_submissions', 'allownonor', 'plagiarism_turnitin'); $suboptions = [0 => get_string('norepository', 'plagiarism_turnitin'), - 1 => get_string('standardrepository', 'plagiarism_turnitin')]; + 1 => get_string('standardrepository', 'plagiarism_turnitin'),]; switch ($config->plagiarism_turnitin_repositoryoption) { case 0; // Standard options. $mform->addElement('select', 'plagiarism_submitpapersto', get_string('submitpapersto', 'plagiarism_turnitin'), $suboptions); @@ -336,7 +336,7 @@ public function add_elements_to_settings_form($mform, $course, $location = "acti 'title' => get_string('launchrubricmanager', 'plagiarism_turnitin'), 'id' => 'rubric_manager_form', 'role' => 'link', - 'tabindex' => '0' + 'tabindex' => '0', ] ); @@ -362,13 +362,13 @@ public function add_elements_to_settings_form($mform, $course, $location = "acti 2 => get_string('erater_handbook_highschool', 'plagiarism_turnitin'), 3 => get_string('erater_handbook_middleschool', 'plagiarism_turnitin'), 4 => get_string('erater_handbook_elementary', 'plagiarism_turnitin'), - 5 => get_string('erater_handbook_learners', 'plagiarism_turnitin') + 5 => get_string('erater_handbook_learners', 'plagiarism_turnitin'), ]; $dictionaryoptions = [ 'en_US' => get_string('erater_dictionary_enus', 'plagiarism_turnitin'), 'en_GB' => get_string('erater_dictionary_engb', 'plagiarism_turnitin'), - 'en' => get_string('erater_dictionary_en', 'plagiarism_turnitin') + 'en' => get_string('erater_dictionary_en', 'plagiarism_turnitin'), ]; $mform->addElement('select', 'plagiarism_erater', get_string('erater', 'plagiarism_turnitin'), $options); $mform->setDefault('plagiarism_erater', 0); diff --git a/db/access.php b/db/access.php index 1fdcc303..31251abf 100644 --- a/db/access.php +++ b/db/access.php @@ -27,15 +27,15 @@ 'contextlevel' => CONTEXT_COURSE, 'legacy' => [ 'editingteacher' => CAP_ALLOW, - 'manager' => CAP_ALLOW - ] + 'manager' => CAP_ALLOW, + ], ], 'plagiarism/turnitin:viewfullreport' => [ 'captype' => 'read', 'contextlevel' => CONTEXT_COURSE, 'legacy' => [ 'editingteacher' => CAP_ALLOW, - 'manager' => CAP_ALLOW - ] + 'manager' => CAP_ALLOW, + ], ], ]; diff --git a/db/events.php b/db/events.php index 05cdbe65..ec0a73b8 100644 --- a/db/events.php +++ b/db/events.php @@ -24,23 +24,23 @@ $observers = [ [ 'eventname' => '\assignsubmission_file\event\assessable_uploaded', - 'callback' => 'plagiarism_turnitin_observer::assignsubmission_file_uploaded' + 'callback' => 'plagiarism_turnitin_observer::assignsubmission_file_uploaded', ], [ 'eventname' => '\assignsubmission_onlinetext\event\assessable_uploaded', - 'callback' => 'plagiarism_turnitin_observer::assignsubmission_onlinetext_uploaded' + 'callback' => 'plagiarism_turnitin_observer::assignsubmission_onlinetext_uploaded', ], [ 'eventname' => '\mod_workshop\event\assessable_uploaded', - 'callback' => 'plagiarism_turnitin_observer::workshop_file_uploaded' + 'callback' => 'plagiarism_turnitin_observer::workshop_file_uploaded', ], [ 'eventname' => '\mod_forum\event\assessable_uploaded', - 'callback' => 'plagiarism_turnitin_observer::forum_file_uploaded' + 'callback' => 'plagiarism_turnitin_observer::forum_file_uploaded', ], [ 'eventname' => '\mod_assign\event\assessable_submitted', - 'callback' => 'plagiarism_turnitin_observer::assignsubmission_submitted' + 'callback' => 'plagiarism_turnitin_observer::assignsubmission_submitted', ], [ 'eventname' => '\mod_assign\event\submission_removed', @@ -48,19 +48,19 @@ ], [ 'eventname' => '\mod_coursework\event\assessable_uploaded', - 'callback' => 'plagiarism_turnitin_observer::coursework_submitted' + 'callback' => 'plagiarism_turnitin_observer::coursework_submitted', ], [ 'eventname' => '\mod_quiz\event\attempt_submitted', - 'callback' => 'plagiarism_turnitin_observer::quiz_submitted' + 'callback' => 'plagiarism_turnitin_observer::quiz_submitted', ], [ 'eventname' => '\core\event\course_module_deleted', - 'callback' => 'plagiarism_turnitin_observer::course_module_deleted' + 'callback' => 'plagiarism_turnitin_observer::course_module_deleted', ], [ 'eventname' => '\core\event\course_reset_ended', 'callback' => 'plagiarism_plugin_turnitin::course_reset', - 'includefile' => 'plagiarism/turnitin/lib.php' - ] + 'includefile' => 'plagiarism/turnitin/lib.php', + ], ]; diff --git a/db/messages.php b/db/messages.php index c24a1ad9..a91ae469 100644 --- a/db/messages.php +++ b/db/messages.php @@ -25,5 +25,5 @@ $messageproviders = [ // Notify student with their digital receipt. 'submission' => [ - ] + ], ]; diff --git a/db/tasks.php b/db/tasks.php index 625f11bc..2f036e71 100644 --- a/db/tasks.php +++ b/db/tasks.php @@ -33,7 +33,7 @@ 'hour' => '*', 'day' => '*', 'dayofweek' => '*', - 'month' => '*' + 'month' => '*', ], [ 'classname' => 'plagiarism_turnitin\task\send_submissions', @@ -42,6 +42,6 @@ 'hour' => '*', 'day' => '*', 'dayofweek' => '*', - 'month' => '*' + 'month' => '*', ], ]; diff --git a/db/upgrade.php b/db/upgrade.php index e7794c6f..71dd7365 100644 --- a/db/upgrade.php +++ b/db/upgrade.php @@ -306,7 +306,7 @@ function xmldb_plagiarism_turnitin_upgrade($oldversion) { $properties = ["accountid", "secretkey", "apiurl", "enablediagnostic", "usegrademark", "enablepeermark", "transmatch", "repositoryoption", "agreement", "enablepseudo", "pseudofirstname", - "pseudolastname", "lastnamegen", "pseudosalt", "pseudoemaildomain", "useanon"]; + "pseudolastname", "lastnamegen", "pseudosalt", "pseudoemaildomain", "useanon",]; foreach ($properties as $property) { plagiarism_plugin_turnitin::plagiarism_set_config($data, $property); diff --git a/dbexport.php b/dbexport.php index ef871679..37eec874 100644 --- a/dbexport.php +++ b/dbexport.php @@ -51,7 +51,7 @@ 'plagiarism_turnitin_config', 'plagiarism_turnitin_users', 'plagiarism_turnitin_courses', - 'plagiarism_turnitin_peermark' + 'plagiarism_turnitin_peermark', ]; // If a table has been passed in then export that table data. diff --git a/lib.php b/lib.php index e6f52247..b90ae029 100755 --- a/lib.php +++ b/lib.php @@ -57,7 +57,7 @@ global $turnitinacceptedfiles; $turnitinacceptedfiles = ['.doc', '.docx', '.ppt', '.pptx', '.pps', '.ppsx', '.pdf', '.txt', '.htm', '.html', '.hwp', '.odt', - '.wpd', '.ps', '.rtf', '.xls', '.xlsx']; + '.wpd', '.ps', '.rtf', '.xls', '.xlsx',]; require_once($CFG->libdir.'/gradelib.php'); @@ -101,7 +101,7 @@ public function get_settings_fields() { 'plagiarism_allow_non_or_submissions', 'plagiarism_submitpapersto', 'plagiarism_compare_student_papers', 'plagiarism_compare_internet', 'plagiarism_compare_journals', 'plagiarism_report_gen', 'plagiarism_compare_institution', 'plagiarism_exclude_biblio', 'plagiarism_exclude_quoted', - 'plagiarism_exclude_matches', 'plagiarism_exclude_matches_value', 'plagiarism_rubric', 'plagiarism_transmatch']; + 'plagiarism_exclude_matches', 'plagiarism_exclude_matches_value', 'plagiarism_rubric', 'plagiarism_transmatch',]; } /** @@ -513,7 +513,7 @@ public function print_disclosure($cmid) { ); $eulaignoredclass = ($eulaaccepted == 0) ? ' pp_turnitin_eula_ignored' : ''; $eula = html_writer::tag('div', $eulalink, ['class' => 'pp_turnitin_eula'.$eulaignoredclass, - 'data-userid' => $user->id]); + 'data-userid' => $user->id,]); $form = turnitin_view::output_launch_form( "useragreement", @@ -536,7 +536,7 @@ public function print_disclosure($cmid) { $turnitincall = $turnitincomms->initialise_api(); $customdata = ["disable_form_change_checker" => true, - "elements" => [['html', $OUTPUT->box('', '', 'useragreement_inputs')]]]; + "elements" => [['html', $OUTPUT->box('', '', 'useragreement_inputs')]],]; $eulaform = new turnitin_form($turnitincall->getApiBaseUrl().TiiLTI::EULAENDPOINT, $customdata, 'POST', $target = 'eulaWindow', ['id' => 'eula_launch']); @@ -555,7 +555,7 @@ public function print_disclosure($cmid) { 'data-courseid' => $cm->course, 'data-cmid' => $cm->id, 'title' => get_string('launchrubricview', - 'plagiarism_turnitin'), 'id' => 'rubric_manager_form' + 'plagiarism_turnitin'), 'id' => 'rubric_manager_form', ] ); $rubricviewlink = html_writer::tag('div', $rubricviewlink, ['class' => 'row_rubric_view']); @@ -837,7 +837,7 @@ public function get_links($linkarray) { $turnitincall = $turnitincomms->initialise_api(); $customdata = ["disable_form_change_checker" => true, - "elements" => [['html', $OUTPUT->box('', '', 'useragreement_inputs')]]]; + "elements" => [['html', $OUTPUT->box('', '', 'useragreement_inputs')]],]; $eulaform = new turnitin_form( $turnitincall->getApiBaseUrl().TiiLTI::EULAENDPOINT, $customdata, @@ -891,7 +891,7 @@ public function get_links($linkarray) { // Get turnitin file details. if (is_null($plagiarismfile)) { $plagiarismfiles = $DB->get_records('plagiarism_turnitin_files', ['userid' => $linkarray["userid"], - 'cm' => $linkarray["cmid"], 'identifier' => $identifier], + 'cm' => $linkarray["cmid"], 'identifier' => $identifier,], 'lastmodified DESC', '*', 0, 1); $plagiarismfile = current($plagiarismfiles); } @@ -901,7 +901,7 @@ public function get_links($linkarray) { 'iteminstance' => $cm->instance, 'itemmodule' => $cm->modname, 'courseid' => $cm->course, - 'itemnumber' => 0 + 'itemnumber' => 0, ]; // Get grade item and work out whether grades have been released for viewing. @@ -923,7 +923,7 @@ public function get_links($linkarray) { [ 'userid' => $linkarray["userid"], 'assignment' => $cm->instance, - 'workflowstate' => 'released' + 'workflowstate' => 'released', ]); } } @@ -953,7 +953,7 @@ public function get_links($linkarray) { // Show score. if ($plagiarismfile->statuscode == "pending") { $orscorehtml = html_writer::tag('div', ' ', ['title' => get_string('pending', 'plagiarism_turnitin'), - 'class' => 'tii_tooltip origreport_score score_colour score_colour_']); + 'class' => 'tii_tooltip origreport_score score_colour score_colour_',]); } else { // Put EN flag if translated matching is on and that is the score used. $transmatch = ($plagiarismfile->transmatch == 1) ? ' EN' : ''; @@ -994,7 +994,7 @@ public function get_links($linkarray) { if (($plagiarismfile->orcapable == 0 && !is_null($plagiarismfile->orcapable))) { $notorlink = html_writer::tag('div', 'x', ['title' => get_string('notorcapable', 'plagiarism_turnitin'), - 'class' => 'tii_tooltip score_colour score_colour_ score_no_orcapable']); + 'class' => 'tii_tooltip score_colour score_colour_ score_no_orcapable',]); // This class is applied so that only the user who submitted or a tutor can open the DV. $useropenclass = ($USER->id == $linkarray["userid"] || $istutor) ? 'pp_origreport_open' : ''; $output .= html_writer::tag('div', $notorlink, ['class' => 'row_score pp_origreport '.$useropenclass]); @@ -1022,7 +1022,7 @@ public function get_links($linkarray) { get_string('grademark', 'plagiarism_turnitin'), 'plagiarism_turnitin'), ['title' => get_string('grademark', 'plagiarism_turnitin'), 'class' => 'pp_grademark_open tii_tooltip grademark_'.$plagiarismfile->externalid. - '_'.$linkarray["cmid"], 'tabindex' => '0', 'role' => 'link' + '_'.$linkarray["cmid"], 'tabindex' => '0', 'role' => 'link', ]); // Put in div placeholder for DV launch form. @@ -1057,7 +1057,7 @@ public function get_links($linkarray) { 'data-courseid' => $cm->course, 'data-cmid' => $cm->id, 'title' => get_string('launchrubricview', - 'plagiarism_turnitin'), 'id' => 'rubric_view_launch' + 'plagiarism_turnitin'), 'id' => 'rubric_view_launch', ] ); $rubricviewlink = html_writer::tag('div', $rubricviewlink, ['class' => 'row_rubric_view']); @@ -1092,7 +1092,7 @@ public function get_links($linkarray) { (!$istutor && $peermarksactive)) { $peermarkreviewslink = html_writer::tag('span', '', ['title' => get_string('launchpeermarkreviews', 'plagiarism_turnitin'), - 'class' => 'peermark_reviews_pp_launch tii_tooltip', 'id' => 'peermark_reviews_form'] + 'class' => 'peermark_reviews_pp_launch tii_tooltip', 'id' => 'peermark_reviews_form',] ); $output .= html_writer::tag('div', $peermarkreviewslink, ['class' => 'row_peermark_reviews']); @@ -1120,13 +1120,13 @@ public function get_links($linkarray) { 'plagiarism_turnitin', [ 'maxfilesize' => display_size(PLAGIARISM_TURNITIN_MAX_FILE_UPLOAD_SIZE), - 'externalid' => $plagiarismfile->externalid + 'externalid' => $plagiarismfile->externalid, ]); } $erroricon = html_writer::tag('div', $OUTPUT->pix_icon('x-red', $errorstring, 'plagiarism_turnitin'), ['title' => $errorstring, - 'class' => 'tii_tooltip tii_error_icon']); + 'class' => 'tii_tooltip tii_error_icon',]); // Attach error text or resubmit link after icon depending on whether user is a student/teacher. // Don't attach resubmit link if the user has not accepted the EULA. @@ -1137,7 +1137,7 @@ public function get_links($linkarray) { } else { $output .= html_writer::tag('div', $erroricon.' '.get_string('resubmittoturnitin', 'plagiarism_turnitin'), ['class' => 'clear plagiarism_turnitin_resubmit_link', - 'id' => 'pp_resubmit_'.$plagiarismfile->id]); + 'id' => 'pp_resubmit_'.$plagiarismfile->id,]); $output .= html_writer::tag('div', $OUTPUT->pix_icon('loading', $errorstring, 'plagiarism_turnitin').' '. @@ -1204,7 +1204,7 @@ public function get_links($linkarray) { $erroricon = html_writer::tag('div', $OUTPUT->pix_icon('doc-x-grey', get_string('errorcode3', 'plagiarism_turnitin'), 'plagiarism_turnitin'), ['title' => get_string('errorcode3', 'plagiarism_turnitin'), - 'class' => 'tii_tooltip tii_error_icon']); + 'class' => 'tii_tooltip tii_error_icon',]); $eulaerror = html_writer::tag('div', $erroricon, ['class' => 'clear']); } } @@ -1436,7 +1436,7 @@ private function update_submission($cm, $submissionid, $tiisubmission) { } else { $gradeitem = $DB->get_record('grade_items', ['iteminstance' => $cm->instance, 'itemmodule' => $cm->modname, - 'courseid' => $cm->course, 'itemnumber' => 0]); + 'courseid' => $cm->course, 'itemnumber' => 0,]); if (!is_null($plagiarismfile->grade) && !empty($gradeitem) && $gbupdaterequired) { $return = $this->update_grade($cm, $tiisubmission, $submissiondata->userid); @@ -1531,7 +1531,7 @@ private function update_grade($cm, $submission, $userid, $cron = FALSE) { break; case 'workshop': if ($gradeitem = $DB->get_record('grade_items', ['iteminstance' => $cm->instance, - 'itemmodule' => $cm->modname, 'itemnumber' => 0])) { + 'itemmodule' => $cm->modname, 'itemnumber' => 0,])) { $currentgrade = $DB->get_record('grade_grades', ['userid' => $userid, 'itemid' => $gradeitem->id]); } break; @@ -1586,7 +1586,7 @@ private function update_grade($cm, $submission, $userid, $cron = FALSE) { [ 'userid' => $userid, 'assignment' => $cm->instance, - 'workflowstate' => 'released' + 'workflowstate' => 'released', ]); // Remove any existing grade from gradebook if not released. if (!$gradesreleased) { @@ -1838,7 +1838,7 @@ public function sync_tii_assignment($cm, $coursetiiid, $workflowcontext = "site" 'iteminstance' => $cm->instance, 'itemmodule' => $cm->modname, 'courseid' => $cm->course, - 'itemnumber' => 0] + 'itemnumber' => 0,] )) { switch ($gradeitem->hidden) { @@ -1851,7 +1851,7 @@ public function sync_tii_assignment($cm, $coursetiiid, $workflowcontext = "site" if ($cm->modname == 'assign' && !empty($moduledata->markingworkflow)) { $gradesreleased = $DB->record_exists('assign_user_flags', ['assignment' => $cm->instance, - 'workflowstate' => 'released']); + 'workflowstate' => 'released',]); $dtpost = ($gradesreleased) ? strtotime('-5 minutes') : strtotime('+1 month'); } @@ -2109,7 +2109,7 @@ public function cron_update_scores() { $moduleturnitinconfig = $DB->get_record('plagiarism_turnitin_config', [ 'cm' => $cm->id, - 'name' => 'turnitin_assignid' + 'name' => 'turnitin_assignid', ] ); @@ -2229,7 +2229,7 @@ private function check_local_submission_state($assignmentids, $submissionids) { return [ 'trimmedSubmissions' => array_intersect($submissionids, $tiisubmissionids), - 'missingTiiSubmissions' => array_diff($submissionids, $tiisubmissionids) + 'missingTiiSubmissions' => array_diff($submissionids, $tiisubmissionids), ]; } @@ -2283,14 +2283,14 @@ public function get_previous_course_id($cmid, $courseid) { $tiicourseid = 0; if ($tiiassignment = $DB->get_record('plagiarism_turnitin_config', ['cm' => $cmid, - 'name' => 'turnitin_assignid'])) { + 'name' => 'turnitin_assignid',])) { $tiicourseid = $this->get_course_id_from_assignment_id($tiiassignment->value); } else { $coursemods = get_course_mods($courseid); foreach ($coursemods as $coursemod) { if ($coursemod->modname != 'turnitintooltwo') { if ($tiiassignment = $DB->get_record('plagiarism_turnitin_config', ['cm' => $coursemod->id, - 'name' => 'turnitin_assignid'])) { + 'name' => 'turnitin_assignid',])) { $tiicourseid = $this->get_course_id_from_assignment_id($tiiassignment->value); } } @@ -2394,7 +2394,7 @@ public function queue_submission_to_turnitin($cm, $author, $submitter, $identifi $moodlesubmission = $DB->get_record('assign_submission', ['assignment' => $cm->instance, 'userid' => $userid, - 'id' => $itemid], 'status'); + 'id' => $itemid,], 'status'); $_SESSION["moodlesubmissionstatus"] = $moodlesubmission->status; } @@ -2435,12 +2435,12 @@ public function queue_submission_to_turnitin($cm, $author, $submitter, $identifi $moodlesubmission = $DB->get_record('assign_submission', ['assignment' => $cm->instance, 'userid' => $userid, - 'id' => $itemid], 'timemodified'); + 'id' => $itemid,], 'timemodified'); break; case 'workshop': $moodlesubmission = $DB->get_record('workshop_submissions', ['workshopid' => $cm->instance, - 'authorid' => $userid], 'timemodified'); + 'authorid' => $userid,], 'timemodified'); break; } @@ -2630,7 +2630,7 @@ public function event_handler($eventdata) { // Get Files. $eventdata['other']['pathnamehashes'] = []; $filesconditions = ['component' => 'assignsubmission_file', - 'itemid' => $moodlesubmission->id, 'userid' => $author]; + 'itemid' => $moodlesubmission->id, 'userid' => $author,]; if ($moodlefiles = $DB->get_records('files', $filesconditions)) { foreach ($moodlefiles as $moodlefile) { $eventdata['other']['pathnamehashes'][] = $moodlefile->pathnamehash; @@ -2805,7 +2805,7 @@ public function clean_old_turnitin_submissions($cm, $userid, $itemid, $submissio if ($cm->modname == 'assign') { $itemids = $DB->get_records('assign_submission', [ 'assignment' => $cm->instance, - 'userid' => $userid + 'userid' => $userid, ], '', 'id'); // Only proceed if we have item ids. @@ -3076,7 +3076,7 @@ function plagiarism_turnitin_send_queued_submissions() { $moodlesubmission = $DB->get_record('assign_submission', ['assignment' => $cm->instance, 'userid' => $userid, - 'id' => $queueditem->itemid], 'status'); + 'id' => $queueditem->itemid,], 'status'); $moduledata->resubmission_allowed = $moduleobject->is_resubmission_allowed( $cm->instance, $settings["plagiarism_report_gen"], @@ -3193,7 +3193,7 @@ function plagiarism_turnitin_send_queued_submissions() { switch ($cm->modname) { case 'assign': $moodlesubmission = $DB->get_record('assign_submission', ['assignment' => $cm->instance, - 'userid' => $queueditem->userid, 'id' => $queueditem->itemid], 'id'); + 'userid' => $queueditem->userid, 'id' => $queueditem->itemid,], 'id'); $moodletextsubmission = $DB->get_record('assignsubmission_onlinetext', ['submission' => $moodlesubmission->id], 'onlinetext'); $textcontent = $moodletextsubmission->onlinetext; @@ -3295,7 +3295,7 @@ function plagiarism_turnitin_send_queued_submissions() { $userdetails = [ $user->id, $user->firstname, - $user->lastname + $user->lastname, ]; $filestring = array_merge($userdetails, $filestring); @@ -3368,7 +3368,7 @@ function plagiarism_turnitin_send_queued_submissions() { 'assignment_name' => $moduledata->name, 'course_fullname' => $coursedata->turnitin_ctl, 'submission_date' => date('d-M-Y h:iA'), - 'submission_id' => $tiisubmissionid + 'submission_id' => $tiisubmissionid, ]; $message = $receipt->build_message($input); diff --git a/settings.php b/settings.php index 821034c0..a5ab270a 100644 --- a/settings.php +++ b/settings.php @@ -281,7 +281,7 @@ $multisubmitbuttons = [ ['unlink', get_string('unlinkusers', 'plagiarism_turnitin')], - ['relink', get_string('relinkusers', 'plagiarism_turnitin')]]; + ['relink', get_string('relinkusers', 'plagiarism_turnitin')],]; $customdata["multi_submit_buttons"] = $multisubmitbuttons; require_once($CFG->dirroot.'/plagiarism/turnitin/classes/forms/turnitin_form.class.php'); diff --git a/tests/behat/behat_plagiarism_turnitin.php b/tests/behat/behat_plagiarism_turnitin.php index 5cc963de..3a876f80 100644 --- a/tests/behat/behat_plagiarism_turnitin.php +++ b/tests/behat/behat_plagiarism_turnitin.php @@ -105,7 +105,7 @@ public function i_create_a_unique_user($username) { 'username' => $username, 'password' => $username, 'firstname' => $username, - 'lastname' => $username + 'lastname' => $username, ]); } diff --git a/tests/lib_test.php b/tests/lib_test.php index 2c1dcdfc..df666868 100644 --- a/tests/lib_test.php +++ b/tests/lib_test.php @@ -68,7 +68,7 @@ public function test_check_group_submission() { $result = $this->create_assign_with_student_and_teacher([ 'assignsubmission_onlinetext_enabled' => 1, - 'teamsubmission' => 1 + 'teamsubmission' => 1, ]); $assignmodule = $result['assign']; $student = $result['student']; @@ -87,7 +87,7 @@ public function test_check_group_submission() { $data = new stdClass(); $data->onlinetext_editor = ['itemid' => file_get_unused_draft_itemid(), 'text' => 'Submission text', - 'format' => FORMAT_MOODLE]; + 'format' => FORMAT_MOODLE,]; $plugin = $assign->get_submission_plugin_by_type('onlinetext'); $plugin->save($submission, $data); @@ -100,7 +100,7 @@ public function test_check_group_submission() { // Test a non-group submission. $result = $this->create_assign_with_student_and_teacher([ 'assignsubmission_onlinetext_enabled' => 1, - 'teamsubmission' => 0 + 'teamsubmission' => 0, ]); $assignmodule = $result['assign']; $student = $result['student']; @@ -116,7 +116,7 @@ public function test_check_group_submission() { $data = new stdClass(); $data->onlinetext_editor = ['itemid' => file_get_unused_draft_itemid(), 'text' => 'Submission text', - 'format' => FORMAT_MOODLE]; + 'format' => FORMAT_MOODLE,]; $plugin = $assign->get_submission_plugin_by_type('onlinetext'); $plugin->save($submission, $data); @@ -166,7 +166,7 @@ public function create_assign_with_student_and_teacher($params = []) { 'course' => $course, 'assign' => $assign, 'student' => $student, - 'teacher' => $teacher + 'teacher' => $teacher, ]; } diff --git a/tests/modules/turnitin_assign_test.php b/tests/modules/turnitin_assign_test.php index 4ec12c5b..524cc9cf 100644 --- a/tests/modules/turnitin_assign_test.php +++ b/tests/modules/turnitin_assign_test.php @@ -51,7 +51,7 @@ public function setUp(): void { 'name' => 'assignment', 'assignsubmission_file_enabled' => 1, 'assignsubmission_file_maxfiles' => 1, - 'assignsubmission_file_maxsizebytes' => 10 + 'assignsubmission_file_maxsizebytes' => 10, ]; $this->assign = $this->getDataGenerator()->create_module('assign', $params); @@ -97,7 +97,7 @@ public function test_check_is_resubmission_allowed_maxfiles_above_threshold() { 'name' => 'assignment', 'assignsubmission_file_enabled' => 1, 'assignsubmission_file_maxfiles' => 2, - 'assignsubmission_file_maxsizebytes' => 10 + 'assignsubmission_file_maxsizebytes' => 10, ]; $assign = $this->getDataGenerator()->create_module('assign', $params); diff --git a/tests/modules/turnitin_forum_test.php b/tests/modules/turnitin_forum_test.php index b27df9d8..fe9a3d20 100644 --- a/tests/modules/turnitin_forum_test.php +++ b/tests/modules/turnitin_forum_test.php @@ -81,7 +81,7 @@ public function test_to_check_content_in_array_is_returned_by_set_content() { $moduleobject = new turnitin_forum(); $params = [ - 'content' => $this->post->message + 'content' => $this->post->message, ]; $content = $moduleobject->set_content($params); @@ -101,7 +101,7 @@ public function test_to_check_content_from_database_is_returned_by_set_content_i $params = [ 'content' => 'content should not come back', - 'postid' => $this->post->id + 'postid' => $this->post->id, ]; $content = $moduleobject->set_content($params); diff --git a/tests/privacy/provider_test.php b/tests/privacy/provider_test.php index 3241c9f0..68797957 100644 --- a/tests/privacy/provider_test.php +++ b/tests/privacy/provider_test.php @@ -172,7 +172,7 @@ public function create_submission($numsubmissions = 1) { $libtest = new plagiarism_turnitin_lib_testcase(); $result = $libtest->create_assign_with_student_and_teacher([ 'assignsubmission_onlinetext_enabled' => 1, - 'teamsubmission' => 0 + 'teamsubmission' => 0, ]); $assignmodule = $result['assign']; From 1aed33b8a90ff310b919bb728683a75a892ff6f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luca=20B=C3=B6sch?= Date: Thu, 25 Jul 2024 14:01:40 +0200 Subject: [PATCH 05/15] Fix 'PHPUnit testcase name does not match file name' warnings. --- tests/classes/turnitin_assignment_class_test.php | 2 +- tests/classes/turnitin_user_class_test.php | 2 +- tests/lib_test.php | 2 +- tests/locallib_test.php | 2 +- tests/modules/turnitin_assign_test.php | 2 +- tests/modules/turnitin_forum_test.php | 2 +- tests/modules/turnitin_quiz_test.php | 2 +- tests/privacy/provider_test.php | 2 +- tests/turnitin_test.php | 2 +- 9 files changed, 9 insertions(+), 9 deletions(-) diff --git a/tests/classes/turnitin_assignment_class_test.php b/tests/classes/turnitin_assignment_class_test.php index e6876d01..b8271b79 100644 --- a/tests/classes/turnitin_assignment_class_test.php +++ b/tests/classes/turnitin_assignment_class_test.php @@ -34,7 +34,7 @@ * * @package turnitin */ -class plagiarism_turnitin_assignment_class_testcase extends advanced_testcase { +class turnitin_assignment_class_test extends advanced_testcase { /** * Set Overwrite mtrace to avoid output during the tests. diff --git a/tests/classes/turnitin_user_class_test.php b/tests/classes/turnitin_user_class_test.php index 7ab855b9..495d2a08 100644 --- a/tests/classes/turnitin_user_class_test.php +++ b/tests/classes/turnitin_user_class_test.php @@ -35,7 +35,7 @@ * * @package turnitin */ -class plagiarism_turnitin_user_class_testcase extends plagiarism_turnitin_test_lib { +class turnitin_user_class_test extends plagiarism_turnitin_test_lib { public $faketiicomms; diff --git a/tests/lib_test.php b/tests/lib_test.php index df666868..c5314b5e 100644 --- a/tests/lib_test.php +++ b/tests/lib_test.php @@ -33,7 +33,7 @@ * * @package turnitin */ -class plagiarism_turnitin_lib_testcase extends advanced_testcase { +class lib_test extends advanced_testcase { public function test_is_plugin_configured() { $this->resetAfterTest(); diff --git a/tests/locallib_test.php b/tests/locallib_test.php index 70517a64..f32aba26 100644 --- a/tests/locallib_test.php +++ b/tests/locallib_test.php @@ -33,7 +33,7 @@ * * @package turnitin */ -class plagiarism_turnitin_locallib_testcase extends advanced_testcase { +class locallib_test extends advanced_testcase { /** * Test that we have the correct repository depending on the config settings. diff --git a/tests/modules/turnitin_assign_test.php b/tests/modules/turnitin_assign_test.php index 524cc9cf..a6729ac9 100644 --- a/tests/modules/turnitin_assign_test.php +++ b/tests/modules/turnitin_assign_test.php @@ -33,7 +33,7 @@ * * @package turnitin */ -class plagiarism_turnitin_assign_testcase extends advanced_testcase { +class turnitin_assign_test extends advanced_testcase { /** @var stdClass created in setUp. */ protected $course; diff --git a/tests/modules/turnitin_forum_test.php b/tests/modules/turnitin_forum_test.php index fe9a3d20..67f46b91 100644 --- a/tests/modules/turnitin_forum_test.php +++ b/tests/modules/turnitin_forum_test.php @@ -32,7 +32,7 @@ * * @package turnitin */ -class plagiarism_turnitin_forum_testcase extends advanced_testcase { +class turnitin_forum_test extends advanced_testcase { /** @var stdClass created in setUp. */ protected $forum; diff --git a/tests/modules/turnitin_quiz_test.php b/tests/modules/turnitin_quiz_test.php index 3d1bc725..f3be2472 100644 --- a/tests/modules/turnitin_quiz_test.php +++ b/tests/modules/turnitin_quiz_test.php @@ -34,7 +34,7 @@ * @package plagiarism_turnitin * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class plagiarism_turnitin_quiz_testcase extends advanced_testcase { +class turnitin_quiz_test extends advanced_testcase { /** * Proves that essay response marks are correctly updated. * diff --git a/tests/privacy/provider_test.php b/tests/privacy/provider_test.php index 68797957..28ff8738 100644 --- a/tests/privacy/provider_test.php +++ b/tests/privacy/provider_test.php @@ -39,7 +39,7 @@ return; } -class plagiarism_turnitin_privacy_provider_testcase extends \core_privacy\tests\provider_testcase { +class provider_test extends \core_privacy\tests\provider_testcase { /** * Test for _get_metadata shim. diff --git a/tests/turnitin_test.php b/tests/turnitin_test.php index f7e5d679..d1100393 100644 --- a/tests/turnitin_test.php +++ b/tests/turnitin_test.php @@ -33,7 +33,7 @@ * @copyright 2016 Catalyst IT * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class plagiarism_turnitin_testcase extends advanced_testcase { +class turnitin_test extends advanced_testcase { /** * Isolates a problem found running core tests in Moodle 31. */ From 134b674403227e3c9adf8950a019a083ea782b7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luca=20B=C3=B6sch?= Date: Thu, 25 Jul 2024 14:04:08 +0200 Subject: [PATCH 06/15] Fix whitespace errors. --- classes/turnitin_comms.class.php | 6 ++---- db/events.php | 2 +- db/messages.php | 4 ++-- tests/generator/lib.php | 4 ++-- 4 files changed, 7 insertions(+), 9 deletions(-) diff --git a/classes/turnitin_comms.class.php b/classes/turnitin_comms.class.php index 067d346e..767bedf7 100644 --- a/classes/turnitin_comms.class.php +++ b/classes/turnitin_comms.class.php @@ -41,8 +41,7 @@ public function __construct($accountid = null, $accountshared = null, $url = nul if (!is_null($url)) { $this->tiiapiurl = $url; } else { - $this->tiiapiurl = (substr($config->plagiarism_turnitin_apiurl, -1) == '/') - ? substr($config->plagiarism_turnitin_apiurl, 0, -1) : $config->plagiarism_turnitin_apiurl; + $this->tiiapiurl = (substr($config->plagiarism_turnitin_apiurl, -1) == '/') ? substr($config->plagiarism_turnitin_apiurl, 0, -1) : $config->plagiarism_turnitin_apiurl; } $this->tiiintegrationid = 12; @@ -53,8 +52,7 @@ public function __construct($accountid = null, $accountshared = null, $url = nul plagiarism_turnitin_print_error( 'configureerror', 'plagiarism_turnitin' ); } - $this->diagnostic = (isset($config->plagiarism_turnitin_enablediagnostic)) - ? $config->plagiarism_turnitin_enablediagnostic : 1; + $this->diagnostic = (isset($config->plagiarism_turnitin_enablediagnostic)) ? $config->plagiarism_turnitin_enablediagnostic : 1; $this->langcode = $this->get_lang(); } diff --git a/db/events.php b/db/events.php index ec0a73b8..8a613cb9 100644 --- a/db/events.php +++ b/db/events.php @@ -21,7 +21,7 @@ defined('MOODLE_INTERNAL') || die(); -$observers = [ +$observers = [ [ 'eventname' => '\assignsubmission_file\event\assessable_uploaded', 'callback' => 'plagiarism_turnitin_observer::assignsubmission_file_uploaded', diff --git a/db/messages.php b/db/messages.php index a91ae469..17af1c02 100644 --- a/db/messages.php +++ b/db/messages.php @@ -22,8 +22,8 @@ defined('MOODLE_INTERNAL') || die(); defined('MOODLE_INTERNAL') || die(); -$messageproviders = [ +$messageproviders = [ // Notify student with their digital receipt. - 'submission' => [ + 'submission' => [ ], ]; diff --git a/tests/generator/lib.php b/tests/generator/lib.php index 6e6cff8f..307bf01e 100644 --- a/tests/generator/lib.php +++ b/tests/generator/lib.php @@ -47,9 +47,9 @@ public function make_test_users($number_of_users, $roles) { $return['plagiarism_turnitin_users'] = []; $return['joins'] = []; - for ($i=0; $i < $number_of_users; $i++) { + for ($i = 0; $i < $number_of_users; $i++) { $role = isset($roles[$i]) ? $roles[$i] : 'Instructor'; - $new_user = new turnitin_user( $i+1, $role, false, 'site', false ); + $new_user = new turnitin_user( $i + 1, $role, false, 'site', false ); array_push($return['plagiarism_turnitin_users'], $new_user); $joinid = $this->join_test_user($new_user); array_push($return['joins'], $joinid); From eb7fdeda3cba96128ce67deb0e8c392ff571955b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luca=20B=C3=B6sch?= Date: Thu, 25 Jul 2024 14:06:22 +0200 Subject: [PATCH 07/15] Fix NamingConventions.ValidVariableName errors. --- lib.php | 4 ++-- tests/behat/behat_plagiarism_turnitin.php | 6 +++--- tests/generator/lib.php | 26 +++++++++++------------ 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/lib.php b/lib.php index b90ae029..9903c126 100755 --- a/lib.php +++ b/lib.php @@ -2356,8 +2356,8 @@ public function queue_submission_to_turnitin($cm, $author, $submitter, $identifi $coursedata = $this->get_course_data($cm->id, $cm->course); $user = new turnitin_user($author, "Learner"); $user->join_user_to_class($coursedata->turnitin_cid); - $eula_accepted = ($user->useragreementaccepted == 0) ? $user->get_accepted_user_agreement() : $user->useragreementaccepted; - if ($eula_accepted != 1) { + $eulaaccepted = ($user->useragreementaccepted == 0) ? $user->get_accepted_user_agreement() : $user->useragreementaccepted; + if ($eulaaccepted != 1) { return true; } diff --git a/tests/behat/behat_plagiarism_turnitin.php b/tests/behat/behat_plagiarism_turnitin.php index 3a876f80..20e8a02d 100644 --- a/tests/behat/behat_plagiarism_turnitin.php +++ b/tests/behat/behat_plagiarism_turnitin.php @@ -247,12 +247,12 @@ public function click_save_changes_button($selector, $locator, $exception = fals */ public function the_following_users_will_be_created_if_they_do_not_already_exist(TableNode $data) { $newdata = []; - $rowNum = 0; + $rownum = 0; foreach ($data->getRows() as $row) { - if (!$rowNum == 0) { // not header row + if (!$rownum == 0) { // not header row $row[3] = str_replace('$account', getenv('TII_ACCOUNT'), $row[3]); } - $rowNum++; + $rownum++; $newdata[] = $row; } $tablenode = new TableNode($newdata); diff --git a/tests/generator/lib.php b/tests/generator/lib.php index 307bf01e..17b43131 100644 --- a/tests/generator/lib.php +++ b/tests/generator/lib.php @@ -43,15 +43,15 @@ abstract class plagiarism_turnitin_test_lib extends advanced_testcase { * @param array $roles - an array of strings, each of which should be 'Learner' or 'Instructor'. * @return object $return - object of two arrays of equal length, one full of plagiarism_turnitin_user types and the other with ids for dbtable plagiarism_turnitin_users. The indices of these arrays DO align. */ - public function make_test_users($number_of_users, $roles) { + public function make_test_users($numberofusers, $roles) { $return['plagiarism_turnitin_users'] = []; $return['joins'] = []; - for ($i = 0; $i < $number_of_users; $i++) { + for ($i = 0; $i < $numberofusers; $i++) { $role = isset($roles[$i]) ? $roles[$i] : 'Instructor'; - $new_user = new turnitin_user( $i + 1, $role, false, 'site', false ); - array_push($return['plagiarism_turnitin_users'], $new_user); - $joinid = $this->join_test_user($new_user); + $newuser = new turnitin_user( $i + 1, $role, false, 'site', false ); + array_push($return['plagiarism_turnitin_users'], $newuser); + $joinid = $this->join_test_user($newuser); array_push($return['joins'], $joinid); } @@ -65,16 +65,16 @@ public function make_test_users($number_of_users, $roles) { * * @return int $plagiarism_turnitin_user_id id of plagiarism_turnitin user join (for use in get_record queries on plagiarism_turnitin_users table) */ - public function join_test_user($plagiarism_turnitin_user) { + public function join_test_user($plagiarismturnitinuser) { global $DB; - $mdl_user = $this->getDataGenerator()->create_user(); - $tiiUserRecord = new stdClass(); - $tiiUserRecord->userid = $mdl_user->id; - $tiiUserRecord->turnitin_uid = $plagiarism_turnitin_user->id; - $tiiUserRecord->user_agreement_accepted = 1; - $plagiarism_turnitin_user_id = $DB->insert_record('plagiarism_turnitin_users', $tiiUserRecord); + $mdluser = $this->getDataGenerator()->create_user(); + $tiiuserrecord = new stdClass(); + $tiiuserrecord->userid = $mdluser->id; + $tiiuserrecord->turnitin_uid = $plagiarismturnitinuser->id; + $tiiuserrecord->user_agreement_accepted = 1; + $plagiarismturnitinuserid = $DB->insert_record('plagiarism_turnitin_users', $tiiuserrecord); - return $plagiarism_turnitin_user_id; + return $plagiarismturnitinuserid; } } From 84e44e9bfd5e724b5353625be088c46bf2a7d5dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luca=20B=C3=B6sch?= Date: Thu, 25 Jul 2024 14:12:10 +0200 Subject: [PATCH 08/15] Fix 'Commas (,) must be followed by white space.' errors. --- classes/forms/turnitin_setupform.class.php | 2 +- classes/modules/turnitin_assign.class.php | 2 +- classes/modules/turnitin_coursework.class.php | 2 +- classes/privacy/provider.php | 2 +- classes/turnitin_submission.class.php | 2 +- classes/turnitin_view.class.php | 6 +-- db/upgrade.php | 2 +- lib.php | 48 +++++++++---------- settings.php | 2 +- tests/lib_test.php | 4 +- 10 files changed, 36 insertions(+), 36 deletions(-) diff --git a/classes/forms/turnitin_setupform.class.php b/classes/forms/turnitin_setupform.class.php index c57b432d..4b7c6ad1 100644 --- a/classes/forms/turnitin_setupform.class.php +++ b/classes/forms/turnitin_setupform.class.php @@ -239,7 +239,7 @@ public function save($data) { $properties = ["accountid", "secretkey", "apiurl", "enablediagnostic", "usegrademark", "enablepeermark", "useanon", "transmatch", "repositoryoption", "agreement", "enablepseudo", "pseudofirstname", - "pseudolastname", "lastnamegen", "pseudosalt", "pseudoemaildomain",]; + "pseudolastname", "lastnamegen", "pseudosalt", "pseudoemaildomain", ]; foreach ($properties as $property) { plagiarism_plugin_turnitin::plagiarism_set_config($data, "plagiarism_turnitin_".$property); diff --git a/classes/modules/turnitin_assign.class.php b/classes/modules/turnitin_assign.class.php index 8837cd46..ba8c8d33 100644 --- a/classes/modules/turnitin_assign.class.php +++ b/classes/modules/turnitin_assign.class.php @@ -76,7 +76,7 @@ public function is_resubmission_allowed($assignid, $reportgenspeed, $submissiont $params = ['assignment' => $assignid, 'subtype' => 'assignsubmission', 'plugin' => 'file', - 'name' => 'maxfilesubmissions',]; + 'name' => 'maxfilesubmissions', ]; $maxfilesubmissions = 0; if ($result = $DB->get_record('assign_plugin_config', $params, 'value')) { diff --git a/classes/modules/turnitin_coursework.class.php b/classes/modules/turnitin_coursework.class.php index f3f24ecf..5b70958b 100644 --- a/classes/modules/turnitin_coursework.class.php +++ b/classes/modules/turnitin_coursework.class.php @@ -36,7 +36,7 @@ public function __construct() { public function is_tutor($context) { $capabilities = [$this->get_tutor_capability(), 'mod/coursework:addagreedgrade', - 'mod/coursework:addallocatedagreedgrade', 'mod/coursework:administergrades',]; + 'mod/coursework:addallocatedagreedgrade', 'mod/coursework:administergrades', ]; return has_any_capability($capabilities, $context); } diff --git a/classes/privacy/provider.php b/classes/privacy/provider.php index 06a2c504..5244bfc8 100644 --- a/classes/privacy/provider.php +++ b/classes/privacy/provider.php @@ -108,7 +108,7 @@ public static function _get_contexts_for_userid($userid) { $params = ['modulename' => 'assign', 'contextlevel' => CONTEXT_MODULE, - 'userid' => $userid,]; + 'userid' => $userid, ]; $sql = "SELECT ctx.id FROM {course_modules} cm diff --git a/classes/turnitin_submission.class.php b/classes/turnitin_submission.class.php index 44ff293c..b564c2a1 100644 --- a/classes/turnitin_submission.class.php +++ b/classes/turnitin_submission.class.php @@ -115,7 +115,7 @@ public function recreate_submission_event() { WHERE FD.forum = ? AND FD.course = ? AND FP.userid = ? AND FP.message LIKE ? ', [$forum->id, $forum->course, - $this->submissiondata->userid, $this->data['forumpost'],] + $this->submissiondata->userid, $this->data['forumpost'], ] ); $discussionid = $discussion->id; } diff --git a/classes/turnitin_view.class.php b/classes/turnitin_view.class.php index 89130231..7fba327b 100644 --- a/classes/turnitin_view.class.php +++ b/classes/turnitin_view.class.php @@ -125,7 +125,7 @@ public function add_elements_to_settings_form($mform, $course, $location = "acti 1 => get_string('reportgen_immediate_add_duedate', 'plagiarism_turnitin'), 2 => get_string('reportgen_duedate_add_duedate', 'plagiarism_turnitin')); $excludetypeoptions = array( 0 => get_string('no'), 1 => get_string('excludewords', 'plagiarism_turnitin'), - 2 => get_string('excludepercent', 'plagiarism_turnitin'),]; + 2 => get_string('excludepercent', 'plagiarism_turnitin'), ]; if ($location == "defaults") { $mform->addElement('header', 'turnitin_plugin_header', get_string('turnitindefaults', 'plagiarism_turnitin')); @@ -227,7 +227,7 @@ public function add_elements_to_settings_form($mform, $course, $location = "acti if ($mform->elementExists('submissiondrafts') || $location == 'defaults') { $tiidraftoptions = [0 => get_string("submitondraft", "plagiarism_turnitin"), - 1 => get_string("submitonfinal", "plagiarism_turnitin"),]; + 1 => get_string("submitonfinal", "plagiarism_turnitin"), ]; $mform->addElement('select', 'plagiarism_draft_submit', get_string("draftsubmit", "plagiarism_turnitin"), $tiidraftoptions); $this->lock($mform, $location, $locks); @@ -239,7 +239,7 @@ public function add_elements_to_settings_form($mform, $course, $location = "acti $mform->addHelpButton('plagiarism_allow_non_or_submissions', 'allownonor', 'plagiarism_turnitin'); $suboptions = [0 => get_string('norepository', 'plagiarism_turnitin'), - 1 => get_string('standardrepository', 'plagiarism_turnitin'),]; + 1 => get_string('standardrepository', 'plagiarism_turnitin'), ]; switch ($config->plagiarism_turnitin_repositoryoption) { case 0; // Standard options. $mform->addElement('select', 'plagiarism_submitpapersto', get_string('submitpapersto', 'plagiarism_turnitin'), $suboptions); diff --git a/db/upgrade.php b/db/upgrade.php index 71dd7365..bcf12e3d 100644 --- a/db/upgrade.php +++ b/db/upgrade.php @@ -306,7 +306,7 @@ function xmldb_plagiarism_turnitin_upgrade($oldversion) { $properties = ["accountid", "secretkey", "apiurl", "enablediagnostic", "usegrademark", "enablepeermark", "transmatch", "repositoryoption", "agreement", "enablepseudo", "pseudofirstname", - "pseudolastname", "lastnamegen", "pseudosalt", "pseudoemaildomain", "useanon",]; + "pseudolastname", "lastnamegen", "pseudosalt", "pseudoemaildomain", "useanon", ]; foreach ($properties as $property) { plagiarism_plugin_turnitin::plagiarism_set_config($data, $property); diff --git a/lib.php b/lib.php index 9903c126..ca7fb8e1 100755 --- a/lib.php +++ b/lib.php @@ -57,7 +57,7 @@ global $turnitinacceptedfiles; $turnitinacceptedfiles = ['.doc', '.docx', '.ppt', '.pptx', '.pps', '.ppsx', '.pdf', '.txt', '.htm', '.html', '.hwp', '.odt', - '.wpd', '.ps', '.rtf', '.xls', '.xlsx',]; + '.wpd', '.ps', '.rtf', '.xls', '.xlsx', ]; require_once($CFG->libdir.'/gradelib.php'); @@ -101,7 +101,7 @@ public function get_settings_fields() { 'plagiarism_allow_non_or_submissions', 'plagiarism_submitpapersto', 'plagiarism_compare_student_papers', 'plagiarism_compare_internet', 'plagiarism_compare_journals', 'plagiarism_report_gen', 'plagiarism_compare_institution', 'plagiarism_exclude_biblio', 'plagiarism_exclude_quoted', - 'plagiarism_exclude_matches', 'plagiarism_exclude_matches_value', 'plagiarism_rubric', 'plagiarism_transmatch',]; + 'plagiarism_exclude_matches', 'plagiarism_exclude_matches_value', 'plagiarism_rubric', 'plagiarism_transmatch', ]; } /** @@ -513,7 +513,7 @@ public function print_disclosure($cmid) { ); $eulaignoredclass = ($eulaaccepted == 0) ? ' pp_turnitin_eula_ignored' : ''; $eula = html_writer::tag('div', $eulalink, ['class' => 'pp_turnitin_eula'.$eulaignoredclass, - 'data-userid' => $user->id,]); + 'data-userid' => $user->id, ]); $form = turnitin_view::output_launch_form( "useragreement", @@ -536,7 +536,7 @@ public function print_disclosure($cmid) { $turnitincall = $turnitincomms->initialise_api(); $customdata = ["disable_form_change_checker" => true, - "elements" => [['html', $OUTPUT->box('', '', 'useragreement_inputs')]],]; + "elements" => [['html', $OUTPUT->box('', '', 'useragreement_inputs')]], ]; $eulaform = new turnitin_form($turnitincall->getApiBaseUrl().TiiLTI::EULAENDPOINT, $customdata, 'POST', $target = 'eulaWindow', ['id' => 'eula_launch']); @@ -837,7 +837,7 @@ public function get_links($linkarray) { $turnitincall = $turnitincomms->initialise_api(); $customdata = ["disable_form_change_checker" => true, - "elements" => [['html', $OUTPUT->box('', '', 'useragreement_inputs')]],]; + "elements" => [['html', $OUTPUT->box('', '', 'useragreement_inputs')]], ]; $eulaform = new turnitin_form( $turnitincall->getApiBaseUrl().TiiLTI::EULAENDPOINT, $customdata, @@ -891,7 +891,7 @@ public function get_links($linkarray) { // Get turnitin file details. if (is_null($plagiarismfile)) { $plagiarismfiles = $DB->get_records('plagiarism_turnitin_files', ['userid' => $linkarray["userid"], - 'cm' => $linkarray["cmid"], 'identifier' => $identifier,], + 'cm' => $linkarray["cmid"], 'identifier' => $identifier, ], 'lastmodified DESC', '*', 0, 1); $plagiarismfile = current($plagiarismfiles); } @@ -953,7 +953,7 @@ public function get_links($linkarray) { // Show score. if ($plagiarismfile->statuscode == "pending") { $orscorehtml = html_writer::tag('div', ' ', ['title' => get_string('pending', 'plagiarism_turnitin'), - 'class' => 'tii_tooltip origreport_score score_colour score_colour_',]); + 'class' => 'tii_tooltip origreport_score score_colour score_colour_', ]); } else { // Put EN flag if translated matching is on and that is the score used. $transmatch = ($plagiarismfile->transmatch == 1) ? ' EN' : ''; @@ -994,7 +994,7 @@ public function get_links($linkarray) { if (($plagiarismfile->orcapable == 0 && !is_null($plagiarismfile->orcapable))) { $notorlink = html_writer::tag('div', 'x', ['title' => get_string('notorcapable', 'plagiarism_turnitin'), - 'class' => 'tii_tooltip score_colour score_colour_ score_no_orcapable',]); + 'class' => 'tii_tooltip score_colour score_colour_ score_no_orcapable', ]); // This class is applied so that only the user who submitted or a tutor can open the DV. $useropenclass = ($USER->id == $linkarray["userid"] || $istutor) ? 'pp_origreport_open' : ''; $output .= html_writer::tag('div', $notorlink, ['class' => 'row_score pp_origreport '.$useropenclass]); @@ -1092,7 +1092,7 @@ public function get_links($linkarray) { (!$istutor && $peermarksactive)) { $peermarkreviewslink = html_writer::tag('span', '', ['title' => get_string('launchpeermarkreviews', 'plagiarism_turnitin'), - 'class' => 'peermark_reviews_pp_launch tii_tooltip', 'id' => 'peermark_reviews_form',] + 'class' => 'peermark_reviews_pp_launch tii_tooltip', 'id' => 'peermark_reviews_form', ] ); $output .= html_writer::tag('div', $peermarkreviewslink, ['class' => 'row_peermark_reviews']); @@ -1126,7 +1126,7 @@ public function get_links($linkarray) { $erroricon = html_writer::tag('div', $OUTPUT->pix_icon('x-red', $errorstring, 'plagiarism_turnitin'), ['title' => $errorstring, - 'class' => 'tii_tooltip tii_error_icon',]); + 'class' => 'tii_tooltip tii_error_icon', ]); // Attach error text or resubmit link after icon depending on whether user is a student/teacher. // Don't attach resubmit link if the user has not accepted the EULA. @@ -1137,7 +1137,7 @@ public function get_links($linkarray) { } else { $output .= html_writer::tag('div', $erroricon.' '.get_string('resubmittoturnitin', 'plagiarism_turnitin'), ['class' => 'clear plagiarism_turnitin_resubmit_link', - 'id' => 'pp_resubmit_'.$plagiarismfile->id,]); + 'id' => 'pp_resubmit_'.$plagiarismfile->id, ]); $output .= html_writer::tag('div', $OUTPUT->pix_icon('loading', $errorstring, 'plagiarism_turnitin').' '. @@ -1204,7 +1204,7 @@ public function get_links($linkarray) { $erroricon = html_writer::tag('div', $OUTPUT->pix_icon('doc-x-grey', get_string('errorcode3', 'plagiarism_turnitin'), 'plagiarism_turnitin'), ['title' => get_string('errorcode3', 'plagiarism_turnitin'), - 'class' => 'tii_tooltip tii_error_icon',]); + 'class' => 'tii_tooltip tii_error_icon', ]); $eulaerror = html_writer::tag('div', $erroricon, ['class' => 'clear']); } } @@ -1436,7 +1436,7 @@ private function update_submission($cm, $submissionid, $tiisubmission) { } else { $gradeitem = $DB->get_record('grade_items', ['iteminstance' => $cm->instance, 'itemmodule' => $cm->modname, - 'courseid' => $cm->course, 'itemnumber' => 0,]); + 'courseid' => $cm->course, 'itemnumber' => 0, ]); if (!is_null($plagiarismfile->grade) && !empty($gradeitem) && $gbupdaterequired) { $return = $this->update_grade($cm, $tiisubmission, $submissiondata->userid); @@ -1531,7 +1531,7 @@ private function update_grade($cm, $submission, $userid, $cron = FALSE) { break; case 'workshop': if ($gradeitem = $DB->get_record('grade_items', ['iteminstance' => $cm->instance, - 'itemmodule' => $cm->modname, 'itemnumber' => 0,])) { + 'itemmodule' => $cm->modname, 'itemnumber' => 0, ])) { $currentgrade = $DB->get_record('grade_grades', ['userid' => $userid, 'itemid' => $gradeitem->id]); } break; @@ -1838,7 +1838,7 @@ public function sync_tii_assignment($cm, $coursetiiid, $workflowcontext = "site" 'iteminstance' => $cm->instance, 'itemmodule' => $cm->modname, 'courseid' => $cm->course, - 'itemnumber' => 0,] + 'itemnumber' => 0, ] )) { switch ($gradeitem->hidden) { @@ -1851,7 +1851,7 @@ public function sync_tii_assignment($cm, $coursetiiid, $workflowcontext = "site" if ($cm->modname == 'assign' && !empty($moduledata->markingworkflow)) { $gradesreleased = $DB->record_exists('assign_user_flags', ['assignment' => $cm->instance, - 'workflowstate' => 'released',]); + 'workflowstate' => 'released', ]); $dtpost = ($gradesreleased) ? strtotime('-5 minutes') : strtotime('+1 month'); } @@ -2283,14 +2283,14 @@ public function get_previous_course_id($cmid, $courseid) { $tiicourseid = 0; if ($tiiassignment = $DB->get_record('plagiarism_turnitin_config', ['cm' => $cmid, - 'name' => 'turnitin_assignid',])) { + 'name' => 'turnitin_assignid', ])) { $tiicourseid = $this->get_course_id_from_assignment_id($tiiassignment->value); } else { $coursemods = get_course_mods($courseid); foreach ($coursemods as $coursemod) { if ($coursemod->modname != 'turnitintooltwo') { if ($tiiassignment = $DB->get_record('plagiarism_turnitin_config', ['cm' => $coursemod->id, - 'name' => 'turnitin_assignid',])) { + 'name' => 'turnitin_assignid', ])) { $tiicourseid = $this->get_course_id_from_assignment_id($tiiassignment->value); } } @@ -2394,7 +2394,7 @@ public function queue_submission_to_turnitin($cm, $author, $submitter, $identifi $moodlesubmission = $DB->get_record('assign_submission', ['assignment' => $cm->instance, 'userid' => $userid, - 'id' => $itemid,], 'status'); + 'id' => $itemid, ], 'status'); $_SESSION["moodlesubmissionstatus"] = $moodlesubmission->status; } @@ -2435,12 +2435,12 @@ public function queue_submission_to_turnitin($cm, $author, $submitter, $identifi $moodlesubmission = $DB->get_record('assign_submission', ['assignment' => $cm->instance, 'userid' => $userid, - 'id' => $itemid,], 'timemodified'); + 'id' => $itemid, ], 'timemodified'); break; case 'workshop': $moodlesubmission = $DB->get_record('workshop_submissions', ['workshopid' => $cm->instance, - 'authorid' => $userid,], 'timemodified'); + 'authorid' => $userid, ], 'timemodified'); break; } @@ -2630,7 +2630,7 @@ public function event_handler($eventdata) { // Get Files. $eventdata['other']['pathnamehashes'] = []; $filesconditions = ['component' => 'assignsubmission_file', - 'itemid' => $moodlesubmission->id, 'userid' => $author,]; + 'itemid' => $moodlesubmission->id, 'userid' => $author, ]; if ($moodlefiles = $DB->get_records('files', $filesconditions)) { foreach ($moodlefiles as $moodlefile) { $eventdata['other']['pathnamehashes'][] = $moodlefile->pathnamehash; @@ -3076,7 +3076,7 @@ function plagiarism_turnitin_send_queued_submissions() { $moodlesubmission = $DB->get_record('assign_submission', ['assignment' => $cm->instance, 'userid' => $userid, - 'id' => $queueditem->itemid,], 'status'); + 'id' => $queueditem->itemid, ], 'status'); $moduledata->resubmission_allowed = $moduleobject->is_resubmission_allowed( $cm->instance, $settings["plagiarism_report_gen"], @@ -3193,7 +3193,7 @@ function plagiarism_turnitin_send_queued_submissions() { switch ($cm->modname) { case 'assign': $moodlesubmission = $DB->get_record('assign_submission', ['assignment' => $cm->instance, - 'userid' => $queueditem->userid, 'id' => $queueditem->itemid,], 'id'); + 'userid' => $queueditem->userid, 'id' => $queueditem->itemid, ], 'id'); $moodletextsubmission = $DB->get_record('assignsubmission_onlinetext', ['submission' => $moodlesubmission->id], 'onlinetext'); $textcontent = $moodletextsubmission->onlinetext; diff --git a/settings.php b/settings.php index a5ab270a..90bf2e30 100644 --- a/settings.php +++ b/settings.php @@ -281,7 +281,7 @@ $multisubmitbuttons = [ ['unlink', get_string('unlinkusers', 'plagiarism_turnitin')], - ['relink', get_string('relinkusers', 'plagiarism_turnitin')],]; + ['relink', get_string('relinkusers', 'plagiarism_turnitin')], ]; $customdata["multi_submit_buttons"] = $multisubmitbuttons; require_once($CFG->dirroot.'/plagiarism/turnitin/classes/forms/turnitin_form.class.php'); diff --git a/tests/lib_test.php b/tests/lib_test.php index c5314b5e..ba4f69d0 100644 --- a/tests/lib_test.php +++ b/tests/lib_test.php @@ -87,7 +87,7 @@ public function test_check_group_submission() { $data = new stdClass(); $data->onlinetext_editor = ['itemid' => file_get_unused_draft_itemid(), 'text' => 'Submission text', - 'format' => FORMAT_MOODLE,]; + 'format' => FORMAT_MOODLE, ]; $plugin = $assign->get_submission_plugin_by_type('onlinetext'); $plugin->save($submission, $data); @@ -116,7 +116,7 @@ public function test_check_group_submission() { $data = new stdClass(); $data->onlinetext_editor = ['itemid' => file_get_unused_draft_itemid(), 'text' => 'Submission text', - 'format' => FORMAT_MOODLE,]; + 'format' => FORMAT_MOODLE, ]; $plugin = $assign->get_submission_plugin_by_type('onlinetext'); $plugin->save($submission, $data); From 53891d74f718e8a1548103bcf6970dc7068042ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luca=20B=C3=B6sch?= Date: Thu, 25 Jul 2024 14:17:43 +0200 Subject: [PATCH 09/15] Fixes for remaining errors/warnings. --- ajax.php | 8 + ...ackup_plagiarism_turnitin_plugin.class.php | 25 +- ...store_plagiarism_turnitin_plugin.class.php | 10 +- classes/digitalreceipt/pp_receipt_message.php | 12 +- .../turnitin_defaultsettingsform.class.php | 13 +- classes/forms/turnitin_form.class.php | 8 +- classes/forms/turnitin_setupform.class.php | 112 ++++-- classes/modules/turnitin_assign.class.php | 93 ++++- classes/modules/turnitin_coursework.class.php | 72 +++- classes/modules/turnitin_forum.class.php | 84 ++++- classes/modules/turnitin_quiz.class.php | 88 ++++- classes/modules/turnitin_workshop.class.php | 92 ++++- classes/observer.php | 11 +- classes/privacy/provider.php | 98 ++--- classes/task/send_submissions.php | 14 +- classes/task/update_reports.php | 14 +- classes/turnitin_assignment.class.php | 27 +- classes/turnitin_class.class.php | 31 +- classes/turnitin_comms.class.php | 47 ++- classes/turnitin_submission.class.php | 28 +- classes/turnitin_user.class.php | 69 +++- classes/turnitin_view.class.php | 97 +++-- db/access.php | 3 + db/events.php | 3 + db/messages.php | 7 +- db/tasks.php | 7 +- db/upgrade.php | 49 ++- extras.php | 3 + lang/ar/plagiarism_turnitin.php | 7 + lang/cs/plagiarism_turnitin.php | 6 + lang/de/plagiarism_turnitin.php | 7 + lang/en/plagiarism_turnitin.php | 7 + lang/es/plagiarism_turnitin.php | 7 + lang/fi/plagiarism_turnitin.php | 7 + lang/fr/plagiarism_turnitin.php | 7 + lang/it/plagiarism_turnitin.php | 7 + lang/ja/plagiarism_turnitin.php | 7 + lang/ko/plagiarism_turnitin.php | 7 + lang/nl/plagiarism_turnitin.php | 7 + lang/pl/plagiarism_turnitin.php | 7 + lang/pt_br/plagiarism_turnitin.php | 7 + lang/ro/plagiarism_turnitin.php | 7 + lang/ru/plagiarism_turnitin.php | 7 + lang/sv/plagiarism_turnitin.php | 7 + lang/tr/plagiarism_turnitin.php | 7 + lang/vi/plagiarism_turnitin.php | 7 + lang/zh_hans/plagiarism_turnitin.php | 7 + lang/zh_tw/plagiarism_turnitin.php | 7 + lib.php | 340 ++++++++++++------ locallib.php | 6 +- settings.php | 14 +- tests/behat/behat_plagiarism_turnitin.php | 44 ++- .../turnitin_assignment_class_test.php | 65 +++- tests/classes/turnitin_user_class_test.php | 49 ++- tests/generator/lib.php | 15 +- tests/lib_test.php | 30 +- tests/locallib_test.php | 23 +- tests/modules/turnitin_assign_test.php | 33 +- tests/modules/turnitin_forum_test.php | 12 +- tests/modules/turnitin_quiz_test.php | 7 +- tests/privacy/provider_test.php | 50 ++- tests/turnitin_test.php | 8 +- version.php | 4 +- 63 files changed, 1574 insertions(+), 390 deletions(-) diff --git a/ajax.php b/ajax.php index 0993611a..a2231c21 100644 --- a/ajax.php +++ b/ajax.php @@ -14,6 +14,14 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . +/** + * Turnitin ajax file + * + * @package plagiarism_turnitin + * @copyright 2013 iParadigms LLC + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + use Integrations\PhpSdk\TiiClass; require_once(__DIR__.'/../../config.php'); diff --git a/backup/moodle2/backup_plagiarism_turnitin_plugin.class.php b/backup/moodle2/backup_plagiarism_turnitin_plugin.class.php index ca4aa484..2b1b87c3 100644 --- a/backup/moodle2/backup_plagiarism_turnitin_plugin.class.php +++ b/backup/moodle2/backup_plagiarism_turnitin_plugin.class.php @@ -14,11 +14,22 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -defined('MOODLE_INTERNAL') || die(); - - +/** + * Defines backup_plagiarism_turnitin_plugin class + * + * @package plagiarism_turnitin + * @copyright 2013 iParadigms LLC + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ class backup_plagiarism_turnitin_plugin extends backup_plagiarism_plugin { + /** + * Turnitin plugin structure for module level. + * + * @return backup_plugin_element + * @throws backup_step_exception + * @throws base_element_struct_exception + */ protected function define_module_plugin_structure() { $plugin = $this->get_plugin_element(); @@ -37,7 +48,7 @@ protected function define_module_plugin_structure() { $turnitinfiles = new backup_nested_element('turnitin_files'); $turnitinfile = new backup_nested_element('turnitin_file', ['id'], ['userid', 'identifier', 'externalid', 'externalstatus', - 'statuscode', 'similarityscore', 'transmatch', 'lastmodified', 'grade', 'submissiontype',]); + 'statuscode', 'similarityscore', 'transmatch', 'lastmodified', 'grade', 'submissiontype', ]); $pluginelement->add_child($turnitinfiles); $turnitinfiles->add_child($turnitinfile); @@ -46,6 +57,12 @@ protected function define_module_plugin_structure() { return $plugin; } + /** + * Turnitin plugin structure for course level. + * + * @return backup_plugin_element + * @throws base_element_struct_exception + */ protected function define_course_plugin_structure() { $plugin = $this->get_plugin_element(); diff --git a/backup/moodle2/restore_plagiarism_turnitin_plugin.class.php b/backup/moodle2/restore_plagiarism_turnitin_plugin.class.php index 2f08cee2..ac1f6272 100644 --- a/backup/moodle2/restore_plagiarism_turnitin_plugin.class.php +++ b/backup/moodle2/restore_plagiarism_turnitin_plugin.class.php @@ -14,9 +14,13 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -defined('MOODLE_INTERNAL') || die(); - - +/** + * Defines restore_plagiarism_turnitin_plugin class + * + * @package plagiarism_turnitin + * @copyright 2013 iParadigms LLC + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ class restore_plagiarism_turnitin_plugin extends restore_plagiarism_plugin { /** diff --git a/classes/digitalreceipt/pp_receipt_message.php b/classes/digitalreceipt/pp_receipt_message.php index 5cba8739..dba93da9 100644 --- a/classes/digitalreceipt/pp_receipt_message.php +++ b/classes/digitalreceipt/pp_receipt_message.php @@ -15,14 +15,12 @@ // along with Moodle. If not, see . /** - * @package moodlecore - * @subpackage backup-moodle2 - * @copyright 2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com} - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * Define the digital receipt message class + * + * @package plagiarism_turnitin + * @copyright 2018 Turnitin + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ - -defined('MOODLE_INTERNAL') || die(); - class pp_receipt_message { /** diff --git a/classes/forms/turnitin_defaultsettingsform.class.php b/classes/forms/turnitin_defaultsettingsform.class.php index 3004cfbd..a5221b71 100644 --- a/classes/forms/turnitin_defaultsettingsform.class.php +++ b/classes/forms/turnitin_defaultsettingsform.class.php @@ -23,12 +23,17 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -defined('MOODLE_INTERNAL') || die(); - +/** + * Define the form for the Turnitin plugin settings. + */ class turnitin_defaultsettingsform extends moodleform { - // Define the form. - public function definition () { + /** + * Define the form. + * + * @return void + */ + public function definition() { global $CFG; $mform = $this->_form; diff --git a/classes/forms/turnitin_form.class.php b/classes/forms/turnitin_form.class.php index 1a9bdb93..b698d840 100644 --- a/classes/forms/turnitin_form.class.php +++ b/classes/forms/turnitin_form.class.php @@ -30,9 +30,15 @@ require_once($CFG->dirroot.'/plagiarism/turnitin/lib.php'); require_once($CFG->libdir."/formslib.php"); +/** + * Define the form for the Turnitin plugin. + */ class turnitin_form extends moodleform { - // Define the form. + /** + * Define the form. + * @return void + */ public function definition() { $mform =& $this->_form; diff --git a/classes/forms/turnitin_setupform.class.php b/classes/forms/turnitin_setupform.class.php index 4b7c6ad1..6b3012c1 100644 --- a/classes/forms/turnitin_setupform.class.php +++ b/classes/forms/turnitin_setupform.class.php @@ -30,9 +30,18 @@ require_once($CFG->dirroot.'/plagiarism/turnitin/lib.php'); require_once($CFG->libdir."/formslib.php"); +/** + * Defines the form for the Turnitin plugin settings. + */ class turnitin_setupform extends moodleform { - // Define the form. + /** + * Define the form. + * + * @return void + * @throws coding_exception + * @throws dml_exception + */ public function definition() { global $DB, $CFG; @@ -59,13 +68,16 @@ public function definition() { } } - $mform->addElement('header', 'plagiarism_turnitinconfig', get_string('tiiaccountconfig', 'plagiarism_turnitin')); + $mform->addElement('header', 'plagiarism_turnitinconfig', get_string('tiiaccountconfig', + 'plagiarism_turnitin')); $mform->setExpanded('plagiarism_turnitinconfig'); - $mform->addElement('text', 'plagiarism_turnitin_accountid', get_string('turnitinaccountid', 'plagiarism_turnitin')); + $mform->addElement('text', 'plagiarism_turnitin_accountid', get_string('turnitinaccountid', + 'plagiarism_turnitin')); $mform->setType('plagiarism_turnitin_accountid', PARAM_TEXT); - $mform->addElement('passwordunmask', 'plagiarism_turnitin_secretkey', get_string('turnitinsecretkey', 'plagiarism_turnitin')); + $mform->addElement('passwordunmask', 'plagiarism_turnitin_secretkey', get_string('turnitinsecretkey', + 'plagiarism_turnitin')); $options = [ 'https://api.turnitin.com' => 'https://api.turnitin.com', @@ -80,11 +92,14 @@ public function definition() { } } - $mform->addElement('select', 'plagiarism_turnitin_apiurl', get_string('turnitinapiurl', 'plagiarism_turnitin'), $options); + $mform->addElement('select', 'plagiarism_turnitin_apiurl', get_string('turnitinapiurl', + 'plagiarism_turnitin'), $options); - $mform->addElement('button', 'connection_test', get_string("connecttest", 'plagiarism_turnitin')); + $mform->addElement('button', 'connection_test', get_string("connecttest", + 'plagiarism_turnitin')); - $mform->addElement('header', 'plagiarism_debugginglogs', get_string('tiidebugginglogs', 'plagiarism_turnitin')); + $mform->addElement('header', 'plagiarism_debugginglogs', get_string('tiidebugginglogs', + 'plagiarism_turnitin')); $mform->setExpanded('plagiarism_debugginglogs'); $ynoptions = [0 => get_string('no'), 1 => get_string('yes')]; @@ -95,29 +110,50 @@ public function definition() { ]; // Debugging and logging settings. - $mform->addElement('select', 'plagiarism_turnitin_enablediagnostic', get_string('turnitindiagnostic', 'plagiarism_turnitin'), $diagnosticoptions); - $mform->addElement('static', 'plagiarism_turnitin_enablediagnostic_desc', null, get_string('turnitindiagnostic_desc', 'plagiarism_turnitin')); + $mform->addElement('select', 'plagiarism_turnitin_enablediagnostic', get_string('turnitindiagnostic', + 'plagiarism_turnitin'), $diagnosticoptions); + $mform->addElement('static', 'plagiarism_turnitin_enablediagnostic_desc', null, get_string('turnitindiagnostic_desc', + 'plagiarism_turnitin')); - $mform->addElement('header', 'plagiarism_accountsettings', get_string('tiiaccountsettings', 'plagiarism_turnitin')); + $mform->addElement('header', 'plagiarism_accountsettings', get_string('tiiaccountsettings', + 'plagiarism_turnitin')); $mform->setExpanded('plagiarism_accountsettings'); - $mform->addElement('html', '
'.get_string('tiiaccountsettings_desc', 'plagiarism_turnitin').'
'); + $mform->addElement('html', '
'.get_string('tiiaccountsettings_desc', + 'plagiarism_turnitin').'
'); // Turnitin account settings. - $mform->addElement('select', 'plagiarism_turnitin_usegrademark', get_string('turnitinusegrademark', 'plagiarism_turnitin'), $ynoptions); - $mform->addElement('static', 'plagiarism_turnitin_usegrademark_desc', null, get_string('turnitinusegrademark_desc', 'plagiarism_turnitin')); + $mform->addElement('select', 'plagiarism_turnitin_usegrademark', get_string('turnitinusegrademark', + 'plagiarism_turnitin'), $ynoptions); + $mform->addElement('static', 'plagiarism_turnitin_usegrademark_desc', null, get_string('turnitinusegrademark_desc', + 'plagiarism_turnitin')); $mform->setDefault('plagiarism_turnitin_usegrademark', 1); - $mform->addElement('select', 'plagiarism_turnitin_enablepeermark', get_string('turnitinenablepeermark', 'plagiarism_turnitin'), $ynoptions); - $mform->addElement('static', 'plagiarism_turnitin_enablepeermark_desc', null, get_string('turnitinenablepeermark_desc', 'plagiarism_turnitin')); + $mform->addElement('select', 'plagiarism_turnitin_enablepeermark', get_string('turnitinenablepeermark', + 'plagiarism_turnitin'), $ynoptions); + $mform->addElement('static', 'plagiarism_turnitin_enablepeermark_desc', null, get_string('turnitinenablepeermark_desc', + 'plagiarism_turnitin')); $mform->setDefault('plagiarism_turnitin_enablepeermark', 1); $mform->addElement('select', 'plagiarism_turnitin_useanon', get_string('turnitinuseanon', 'plagiarism_turnitin'), $ynoptions); $mform->addElement('static', 'plagiarism_turnitin_useanon_desc', null, get_string('turnitinuseanon_desc', 'plagiarism_turnitin')); + + $mform->addElement('select', 'plagiarism_turnitin_useerater', get_string('turnitinuseerater', + 'plagiarism_turnitin'), $ynoptions); + $mform->addElement('static', 'plagiarism_turnitin_useerater_desc', null, get_string('turnitinuseerater_desc', + 'plagiarism_turnitin')); + $mform->setDefault('plagiarism_turnitin_useerater', 0); + + $mform->addElement('select', 'plagiarism_turnitin_useanon', get_string('turnitinuseanon', + 'plagiarism_turnitin'), $ynoptions); + $mform->addElement('static', 'plagiarism_turnitin_useanon_desc', null, get_string('turnitinuseanon_desc', + 'plagiarism_turnitin')); $mform->setDefault('plagiarism_turnitin_useanon', 0); - $mform->addElement('select', 'plagiarism_turnitin_transmatch', get_string('transmatch', 'plagiarism_turnitin'), $ynoptions); - $mform->addElement('static', 'plagiarism_turnitin_transmatch_desc', null, get_string('transmatch_desc', 'plagiarism_turnitin')); + $mform->addElement('select', 'plagiarism_turnitin_transmatch', get_string('transmatch', + 'plagiarism_turnitin'), $ynoptions); + $mform->addElement('static', 'plagiarism_turnitin_transmatch_desc', null, get_string('transmatch_desc', + 'plagiarism_turnitin')); $mform->setDefault('plagiarism_turnitin_transmatch', 0); $repositoryoptions = [ @@ -125,11 +161,14 @@ public function definition() { PLAGIARISM_TURNITIN_ADMIN_REPOSITORY_OPTION_EXPANDED => get_string('repositoryoptions_1', 'plagiarism_turnitin'), PLAGIARISM_TURNITIN_ADMIN_REPOSITORY_OPTION_FORCE_STANDARD => get_string('repositoryoptions_2', 'plagiarism_turnitin'), PLAGIARISM_TURNITIN_ADMIN_REPOSITORY_OPTION_FORCE_NO => get_string('repositoryoptions_3', 'plagiarism_turnitin'), - PLAGIARISM_TURNITIN_ADMIN_REPOSITORY_OPTION_FORCE_INSTITUTIONAL => get_string('repositoryoptions_4', 'plagiarism_turnitin'), + PLAGIARISM_TURNITIN_ADMIN_REPOSITORY_OPTION_FORCE_INSTITUTIONAL => get_string('repositoryoptions_4', + 'plagiarism_turnitin'), ]; - $mform->addElement('select', 'plagiarism_turnitin_repositoryoption', get_string('turnitinrepositoryoptions', 'plagiarism_turnitin'), $repositoryoptions); - $mform->addElement('static', 'plagiarism_turnitin_repositoryoption_desc', null, get_string('turnitinrepositoryoptions_desc', 'plagiarism_turnitin')); + $mform->addElement('select', 'plagiarism_turnitin_repositoryoption', + get_string('turnitinrepositoryoptions', 'plagiarism_turnitin'), $repositoryoptions); + $mform->addElement('static', 'plagiarism_turnitin_repositoryoption_desc', null, + get_string('turnitinrepositoryoptions_desc', 'plagiarism_turnitin')); $mform->addHelpButton('plagiarism_turnitin_repositoryoption', 'turnitinrepositoryoptions', 'plagiarism_turnitin'); $mform->setDefault('plagiarism_turnitin_repositoryoption', 0); @@ -137,27 +176,33 @@ public function definition() { $mform->addElement('header', 'plagiarism_miscsettings', get_string('tiimiscsettings', 'plagiarism_turnitin')); $mform->setExpanded('plagiarism_miscsettings'); - $mform->addElement('textarea', 'plagiarism_turnitin_agreement', get_string("pp_agreement", "plagiarism_turnitin"), 'wrap="virtual" rows="10" cols="50"'); - $mform->addElement('static', 'plagiarism_turnitin_agreement_desc', null, get_string('pp_agreement_desc', 'plagiarism_turnitin')); + $mform->addElement('textarea', 'plagiarism_turnitin_agreement', get_string('pp_agreement', + 'plagiarism_turnitin'), 'wrap="virtual" rows="10" cols="50"'); + $mform->addElement('static', 'plagiarism_turnitin_agreement_desc', null, get_string('pp_agreement_desc', + 'plagiarism_turnitin')); // Student data privacy settings. $mform->addElement('header', 'plagiarism_privacy', get_string('studentdataprivacy', 'plagiarism_turnitin')); $mform->setExpanded('plagiarism_privacy'); - if ($DB->count_records('plagiarism_turnitin_users') > 0 AND isset($config->plagiarism_turnitin_enablepseudo)) { - $enablepseudooptions = ($config->plagiarism_turnitin_enablepseudo == 1) ? [1 => get_string('yes')] : [0 => get_string('no')]; + if ($DB->count_records('plagiarism_turnitin_users') > 0 && isset($config->plagiarism_turnitin_enablepseudo)) { + $enablepseudooptions = ($config->plagiarism_turnitin_enablepseudo == 1) ? + [1 => get_string('yes')] : [0 => get_string('no')]; } else if ($DB->count_records('plagiarism_turnitin_users') > 0) { $enablepseudooptions = [ 0 => get_string('no', 'plagiarism_turnitin')]; } else { $enablepseudooptions = $ynoptions; } - $mform->addElement('select', 'plagiarism_turnitin_enablepseudo', get_string('enablepseudo', 'plagiarism_turnitin'), $enablepseudooptions); - $mform->addElement('static', 'plagiarism_turnitin_enablepseudo_desc', null, get_string('enablepseudo_desc', 'plagiarism_turnitin')); + $mform->addElement('select', 'plagiarism_turnitin_enablepseudo', get_string('enablepseudo', + 'plagiarism_turnitin'), $enablepseudooptions); + $mform->addElement('static', 'plagiarism_turnitin_enablepseudo_desc', null, get_string('enablepseudo_desc', + 'plagiarism_turnitin')); $mform->setDefault('plagiarism_turnitin_enablepseudo', 0); if (!empty($config->plagiarism_turnitin_enablepseudo)) { - $mform->addElement('text', 'plagiarism_turnitin_pseudofirstname', get_string('pseudofirstname', 'plagiarism_turnitin'), ['class' => 'studentprivacy']); + $mform->addElement('text', 'plagiarism_turnitin_pseudofirstname', get_string('pseudofirstname', + 'plagiarism_turnitin'), ['class' => 'studentprivacy']); $mform->addElement('static', 'plagiarism_turnitin_pseudofirstname_desc', null, get_string('pseudofirstname_desc', 'plagiarism_turnitin'), ['class' => 'studentprivacy']); $mform->setType('plagiarism_turnitin_pseudofirstname', PARAM_TEXT); @@ -170,24 +215,28 @@ public function definition() { $lnoptions[$profile->id] = get_string('profilefield', 'admin').': '.$profile->name; } - $mform->addElement('select', 'plagiarism_turnitin_pseudolastname', get_string('pseudolastname', 'plagiarism_turnitin'), $lnoptions, ['class' => 'studentprivacy']); + $mform->addElement('select', 'plagiarism_turnitin_pseudolastname', get_string('pseudolastname', + 'plagiarism_turnitin'), $lnoptions, ['class' => 'studentprivacy']); $mform->addElement('static', 'plagiarism_turnitin_pseudolastname_desc', null, get_string('pseudolastname_desc', 'plagiarism_turnitin'), ['class' => 'studentprivacy']); $mform->setType('plagiarism_turnitin_pseudolastname', PARAM_TEXT); $mform->setDefault('plagiarism_turnitin_pseudolastname', 0); - $mform->addElement('select', 'plagiarism_turnitin_lastnamegen', get_string('pseudolastnamegen', 'plagiarism_turnitin'), $ynoptions, ['class' => 'studentprivacy']); + $mform->addElement('select', 'plagiarism_turnitin_lastnamegen', get_string('pseudolastnamegen', + 'plagiarism_turnitin'), $ynoptions, ['class' => 'studentprivacy']); $mform->addElement('static', 'plagiarism_turnitin_lastnamegen_desc', null, get_string('pseudolastnamegen_desc', 'plagiarism_turnitin'), ['class' => 'studentprivacy']); $mform->setType('plagiarism_turnitin_lastnamegen', PARAM_TEXT); $mform->setDefault('plagiarism_turnitin_lastnamegen', 0); - $mform->addElement('text', 'plagiarism_turnitin_pseudosalt', get_string('pseudoemailsalt', 'plagiarism_turnitin'), ['class' => 'studentprivacy']); + $mform->addElement('text', 'plagiarism_turnitin_pseudosalt', get_string('pseudoemailsalt', + 'plagiarism_turnitin'), ['class' => 'studentprivacy']); $mform->addElement('static', 'plagiarism_turnitin_pseudosalt_desc', null, get_string('pseudoemailsalt_desc', 'plagiarism_turnitin'), ['class' => 'studentprivacy']); $mform->setType('plagiarism_turnitin_pseudosalt', PARAM_TEXT); - $mform->addElement('text', 'plagiarism_turnitin_pseudoemaildomain', get_string('pseudoemaildomain', 'plagiarism_turnitin'), ['class' => 'studentprivacy']); + $mform->addElement('text', 'plagiarism_turnitin_pseudoemaildomain', get_string('pseudoemaildomain', + 'plagiarism_turnitin'), ['class' => 'studentprivacy']); $mform->addElement('static', 'plagiarism_turnitin_pseudoemaildomain_desc', null, get_string('pseudoemaildomain_desc', 'plagiarism_turnitin'), ['class' => 'studentprivacy']); $mform->setType('plagiarism_turnitin_pseudoemaildomain', PARAM_TEXT); @@ -232,6 +281,7 @@ public function save($data) { } set_config('enabled', $pluginenabled, 'plagiarism_turnitin'); + // phpcs:disable moodle.Commenting.TodoComment // TODO: Remove turnitin_use completely when support for 3.8 is dropped. if ($CFG->branch < 39) { set_config('turnitin_use', $pluginenabled, 'plagiarism'); diff --git a/classes/modules/turnitin_assign.class.php b/classes/modules/turnitin_assign.class.php index ba8c8d33..072cc98e 100644 --- a/classes/modules/turnitin_assign.class.php +++ b/classes/modules/turnitin_assign.class.php @@ -14,38 +14,79 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . +// phpcs:disable moodle.Commenting.TodoComment +// TODO: Split out all module specific code from plagiarism/turnitin/lib.php. + /** + * Class turnitin_assign + * * @package plagiarism_turnitin * @copyright 2012 iParadigms LLC * + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ - -defined('MOODLE_INTERNAL') || die(); - -// TODO: Split out all module specific code from plagiarism/turnitin/lib.php. class turnitin_assign { + /** + * @var string + */ private $modname; + /** + * @var string + */ public $gradestable; + /** + * @var string + */ public $filecomponent; + /** + * The constructor + */ public function __construct() { $this->modname = 'assign'; $this->gradestable = $this->modname.'_grades'; $this->filecomponent = $this->modname.'submission_file'; } + /** + * Check whether the user is a tutor + * + * @param $context + * @return bool + * @throws coding_exception + */ public function is_tutor($context) { return has_capability($this->get_tutor_capability(), $context); } + /** + * Whether the user has the capability to grade + * + * @return string + */ public function get_tutor_capability() { return 'mod/'.$this->modname.':grade'; } + /** + * Whether the user is enrolled on the course and has the capability to submit assignments + * + * @param $context + * @param $userid + * @return bool + * @throws coding_exception + */ public function user_enrolled_on_course($context, $userid) { return has_capability('mod/'.$this->modname.':submit', $context, $userid); } + /** + * Get the author of the submission + * + * @param $itemid + * @return int + * @throws dml_exception + */ public function get_author($itemid) { global $DB; @@ -56,6 +97,13 @@ public function get_author($itemid) { } } + /** + * Set the content of the submission + * + * @param $linkarray + * @param $cm + * @return string + */ public function set_content($linkarray, $cm) { $onlinetextdata = $this->get_onlinetext($linkarray["userid"], $cm); @@ -99,6 +147,14 @@ public function is_resubmission_allowed($assignid, $reportgenspeed, $submissiont return false; } + /** + * Get the onlinetext submission + * + * @param $userid + * @param $cm + * @return stdClass + * @throws dml_exception + */ public function get_onlinetext($userid, $cm) { global $DB; @@ -122,14 +178,37 @@ public function get_onlinetext($userid, $cm) { return $onlinetextdata; } + /** + * Create a file event + * + * @param $params + * @return \core\event\base + * @throws coding_exception + */ public function create_file_event($params) { return \assignsubmission_file\event\assessable_uploaded::create($params); } + /** + * Create a text event + * + * @param $params + * @return \core\event\base + * @throws coding_exception + */ public function create_text_event($params) { return \assignsubmission_onlinetext\event\assessable_uploaded::create($params); } + /** + * Get the current grade query + * + * @param $userid + * @param $moduleid + * @param $itemid + * @return false|mixed + * @throws dml_exception + */ public function get_current_gradequery($userid, $moduleid, $itemid = 0) { global $DB; @@ -140,6 +219,12 @@ public function get_current_gradequery($userid, $moduleid, $itemid = 0) { return current($currentgradesquery); } + /** + * Initialise the post date for the module + * + * @param $moduledata + * @return int + */ public function initialise_post_date($moduledata) { return 0; } diff --git a/classes/modules/turnitin_coursework.class.php b/classes/modules/turnitin_coursework.class.php index 5b70958b..f9f7f557 100644 --- a/classes/modules/turnitin_coursework.class.php +++ b/classes/modules/turnitin_coursework.class.php @@ -14,40 +14,80 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . +// phpcs:disable moodle.Commenting.TodoComment +// TODO: Split out all module specific code from plagiarism/turnitin/lib.php. + /** + * Class turnitin_coursework + * * @package plagiarism_turnitin * @copyright 2012 iParadigms LLC * + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ - -defined('MOODLE_INTERNAL') || die(); - -// TODO: Split out all module specific code from plagiarism/turnitin/lib.php. class turnitin_coursework { + /** + * @var string + */ private $modname; + /** + * @var string + */ public $gradestable; + /** + * @var string + */ public $filecomponent; + /** + * The constructor + */ public function __construct() { $this->modname = 'coursework'; $this->gradestable = $this->modname.'_feedbacks'; $this->filecomponent = 'mod_'.$this->modname; } + /** + * Check whether the user is a tutor + * + * @param $context + * @return bool + */ public function is_tutor($context) { $capabilities = [$this->get_tutor_capability(), 'mod/coursework:addagreedgrade', 'mod/coursework:addallocatedagreedgrade', 'mod/coursework:administergrades', ]; return has_any_capability($capabilities, $context); } + /** + * Check if the user has the capability to add the initial grade + * + * @return string + */ public function get_tutor_capability() { return 'mod/'.$this->modname.':addinitialgrade'; } + /** + * Whether the user is enrolled on the course and has the capability to submit coursework + * + * @param $context + * @param $userid + * @return bool + * @throws coding_exception + */ public function user_enrolled_on_course($context, $userid) { return has_capability('mod/'.$this->modname.':submit', $context, $userid); } + /** + * Get the author of the submission + * + * @param $itemid + * @return int + * @throws dml_exception + */ public function get_author($itemid) { global $DB; @@ -60,13 +100,25 @@ public function get_author($itemid) { return $id; } - - + /** + * Create a file event + * + * @param $params + * @return mixed + */ public function create_file_event($params) { return \mod_coursework\event\assessable_uploaded::create($params); } - + /** + * Get the current grade query + * + * @param $userid + * @param $moduleid + * @param $itemid + * @return false|mixed + * @throws dml_exception + */ public function get_current_gradequery($userid, $moduleid, $itemid = 0) { global $DB; @@ -85,6 +137,12 @@ public function get_current_gradequery($userid, $moduleid, $itemid = 0) { return $currentgradesquery; } + /** + * Initialise the post date for the module + * + * @param $moduledata + * @return int + */ public function initialise_post_date($moduledata) { return 0; } diff --git a/classes/modules/turnitin_forum.class.php b/classes/modules/turnitin_forum.class.php index 94cc3b10..5b14c429 100644 --- a/classes/modules/turnitin_forum.class.php +++ b/classes/modules/turnitin_forum.class.php @@ -14,42 +14,89 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . +// phpcs:disable moodle.Commenting.TodoComment +// TODO: Split out all module specific code from plagiarism/turnitin/lib.php. + /** + * Class turnitin_forum + * * @package plagiarism_turnitin * @copyright 2012 iParadigms LLC * + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ - -defined('MOODLE_INTERNAL') || die(); - -// TODO: Split out all module specific code from plagiarism/turnitin/lib.php. class turnitin_forum { + /** + * @var string + */ private $modname; + /** + * @var string + */ public $gradestable; + /** + * @var string + */ public $filecomponent; + /** + * The constructor + */ public function __construct() { $this->modname = 'forum'; $this->gradestable = 'grade_grades'; $this->filecomponent = 'mod_'.$this->modname; } + /** + * Check whether the user is a tutor + * + * @param $context + * @return bool + * @throws coding_exception + */ public function is_tutor($context) { return has_capability($this->get_tutor_capability(), $context); } + /** + * Whether the user has the capability to view the full report + * + * @return string + */ public function get_tutor_capability() { return 'plagiarism/turnitin:viewfullreport'; } + /** + * Whether the user is enrolled on the course and has the capability to reply to posts + * + * @param $context + * @param $userid + * @return bool + * @throws coding_exception + */ public function user_enrolled_on_course($context, $userid) { return has_capability('mod/'.$this->modname.':replypost', $context, $userid); } + /** + * Get the author of the forum post + * + * @param $itemid + * @return void + */ public function get_author($itemid = 0) { return; } + /** + * Set the content of the forum post + * + * @param $linkarray + * @return mixed + * @throws dml_exception + */ public function set_content($linkarray) { global $DB; @@ -61,10 +108,26 @@ public function set_content($linkarray) { } } + /** + * Create a file event + * + * @param $params + * @return \core\event\base + * @throws coding_exception + */ public function create_file_event($params) { return \mod_forum\event\assessable_uploaded::create($params); } + /** + * Get the current grade query + * + * @param $userid + * @param $moduleid + * @param $itemid + * @return false|mixed|stdClass + * @throws dml_exception + */ public function get_current_gradequery($userid, $moduleid, $itemid = 0) { global $DB; @@ -72,11 +135,24 @@ public function get_current_gradequery($userid, $moduleid, $itemid = 0) { return $currentgradequery; } + /** + * Initialise the post date for the module + * + * @param $moduledata + * @return int + */ public function initialise_post_date($moduledata) { return 0; } // Get the forum submission id - unfortunately this is rather complex as the db tables are strangely organised. + + /** + * Get the forum discussion id + * + * @param $forumdata + * @return string + */ public function get_discussionid($forumdata) { list($querystrid, $discussionid, $reply, $edit, $delete) = explode('_', $forumdata); diff --git a/classes/modules/turnitin_quiz.class.php b/classes/modules/turnitin_quiz.class.php index f9bd3a63..0898b21b 100644 --- a/classes/modules/turnitin_quiz.class.php +++ b/classes/modules/turnitin_quiz.class.php @@ -14,48 +14,104 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -/** - * @package plagiarism_turnitin - * @copyright 2012 iParadigms LLC * - */ - defined('MOODLE_INTERNAL') || die(); require_once($CFG->dirroot . '/mod/quiz/locallib.php'); +// phpcs:disable moodle.Commenting.TodoComment // TODO: Split out all module specific code from plagiarism/turnitin/lib.php. + +/** + * Class turnitin_quiz + * @package plagiarism_turnitin + * @copyright 2012 iParadigms LLC * + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ class turnitin_quiz { + /** + * @var string + */ private $modname; + /** + * @var string + */ public $gradestable; + /** + * @var string + */ public $filecomponent; + /** + * + */ public function __construct() { $this->modname = 'quiz'; $this->gradestable = 'grade_grades'; $this->filecomponent = 'mod_'.$this->modname; } + /** + * Check whether the user is a tutor + * + * @param $context + * @return bool + * @throws coding_exception + */ public function is_tutor($context) { return has_capability($this->get_tutor_capability(), $context); } + /** + * Whether the user is enrolled on the course and has the capability to submit quiz attempts + * + * @param $context + * @param $userid + * @return bool + * @throws coding_exception + */ public function user_enrolled_on_course($context, $userid) { return has_capability('mod/'.$this->modname.':attempt', $context, $userid); } + /** + * Get the author of the quiz attempt + * + * @param $itemid + * @return void + */ public function get_author($itemid = 0) { return; } + /** + * Whether the user has the capability to grade + * + * @return string + */ public function get_tutor_capability() { return 'mod/'.$this->modname.':grade'; } + /** + * Set the content of the quiz attempt + * + * @param $linkarray + * @return mixed + */ public function set_content($linkarray) { return $linkarray['content']; } + /** + * Get the current grade query + * + * @param $userid + * @param $moduleid + * @param $itemid + * @return false|mixed|stdClass + * @throws dml_exception + */ public function get_current_gradequery($userid, $moduleid, $itemid = 0) { global $DB; @@ -64,12 +120,32 @@ public function get_current_gradequery($userid, $moduleid, $itemid = 0) { } // Work out the mark to set. + + /** + * Calculate the mark for a question attempt based on the grade given for the answer in TFS. + * + * @param $grade + * @param $questionmaxmark + * @param $quizgrade + * @return float|int + */ public function calculate_mark($grade, $questionmaxmark, $quizgrade) { $mark = $grade * ($questionmaxmark / $quizgrade); return ($mark < 0) ? 0 : (float)$mark; } - // Set a new mark for a question attempt based on the grade given for the answer in TFS. + /** + * Set a new mark for a question attempt based on the grade given for the answer in TFS. + * + * @param $attemptid + * @param $identifier + * @param $userid + * @param $grade + * @param $quizgrade + * @return void + * @throws dml_exception + * @throws dml_transaction_exception + */ public function update_mark($attemptid, $identifier, $userid, $grade, $quizgrade) { global $DB; diff --git a/classes/modules/turnitin_workshop.class.php b/classes/modules/turnitin_workshop.class.php index 138627dc..9c354909 100644 --- a/classes/modules/turnitin_workshop.class.php +++ b/classes/modules/turnitin_workshop.class.php @@ -14,46 +14,101 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . +// phpcs:disable moodle.Commenting.TodoComment +// TODO: Split out all module specific code from plagiarism/turnitin/lib.php. + /** + * Class turnitin_workshop + * * @package plagiarism_turnitin * @copyright 2012 iParadigms LLC * + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ - -defined('MOODLE_INTERNAL') || die(); - -// TODO: Split out all module specific code from plagiarism/turnitin/lib.php. class turnitin_workshop { + /** + * @var string + */ private $modname; + /** + * @var string + */ public $gradestable; + /** + * @var string + */ public $filecomponent; + /** + * The constructor + */ public function __construct() { $this->modname = 'workshop'; $this->gradestable = 'grade_grades'; $this->filecomponent = 'mod_'.$this->modname; } + /** + * Check whether the user is a tutor + * + * @param $context + * @return bool + * @throws coding_exception + */ public function is_tutor($context) { return has_capability($this->get_tutor_capability(), $context); } + /** + * Whether the user has the capability to view the full report + * + * @return string + */ public function get_tutor_capability() { return 'plagiarism/turnitin:viewfullreport'; } + /** + * Whether the user is enrolled on the course and has the capability to submit a workshop submission + * + * @param $context + * @param $userid + * @return bool + * @throws coding_exception + */ public function user_enrolled_on_course($context, $userid) { return has_capability('mod/'.$this->modname.':submit', $context, $userid); } + /** + * Get the author of the workshop submission + * + * @param $itemid + * @return void + */ public function get_author($itemid) { return; } + /** + * Set the content of the workshop submission + * + * @param $linkarray + * @param $moduleid + * @return mixed + */ public function set_content($linkarray, $moduleid) { return $linkarray["content"]; } + /** + * Get the onlinetext + * + * @param $userid + * @param $cm + * @return stdClass + * @throws dml_exception + */ public function get_onlinetext($userid, $cm) { global $DB; @@ -68,14 +123,37 @@ public function get_onlinetext($userid, $cm) { return $onlinetextdata; } + /** + * Create a file event + * + * @param $params + * @return \core\event\base + * @throws coding_exception + */ public function create_file_event($params) { return \mod_workshop\event\assessable_uploaded::create($params); } + /** + * Create a text event + * + * @param $params + * @return \core\event\base + * @throws coding_exception + */ public function create_text_event($params) { return \mod_workshop\event\assessable_uploaded::create($params); } + /** + * Get the current grade query + * + * @param $userid + * @param $moduleid + * @param $itemid + * @return false|mixed|stdClass + * @throws dml_exception + */ public function get_current_gradequery($userid, $moduleid, $itemid = 0) { global $DB; @@ -83,6 +161,12 @@ public function get_current_gradequery($userid, $moduleid, $itemid = 0) { return $currentgradequery; } + /** + * Initialise the post date for the module + * + * @param $moduledata + * @return mixed + */ public function initialise_post_date($moduledata) { return $moduledata->assessmentend; } diff --git a/classes/observer.php b/classes/observer.php index 82d285f8..58b89c83 100644 --- a/classes/observer.php +++ b/classes/observer.php @@ -14,12 +14,17 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -if (!defined('MOODLE_INTERNAL')) { - die('Direct access to this script is forbidden.'); // It must be included from a Moodle page. -} +defined('MOODLE_INTERNAL') || die(); require_once($CFG->dirroot.'/plagiarism/turnitin/lib.php'); +/** + * Class plagiarism_turnitin_observer + * + * @package plagiarism_turnitin + * @copyright 2018 iParadigms LLC * + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ class plagiarism_turnitin_observer { /** * Handle the course_module_deleted event. diff --git a/classes/privacy/provider.php b/classes/privacy/provider.php index 5244bfc8..0faf1539 100644 --- a/classes/privacy/provider.php +++ b/classes/privacy/provider.php @@ -25,8 +25,6 @@ namespace plagiarism_turnitin\privacy; -defined('MOODLE_INTERNAL') || die(); - use core_privacy\local\metadata\collection; use core_privacy\local\request\approved_userlist; use core_privacy\local\request\contextlist; @@ -34,6 +32,9 @@ use core_privacy\local\request\userlist; use core_privacy\local\request\writer; +/** + * Privacy Subsystem for plagiarism_turnitin. + */ class provider implements // This plugin does store personal user data. \core_privacy\local\metadata\provider, @@ -46,6 +47,7 @@ class provider implements // This trait must be included to provide the relevant polyfill for the plagirism provider. use \core_plagiarism\privacy\legacy_polyfill; + // phpcs:disable PSR2.Methods.MethodDeclaration.Underscore /** * Return the fields which contain personal data. * @@ -98,6 +100,7 @@ public static function _get_metadata(collection $collection) { return $collection; } + // phpcs:disable PSR2.Methods.MethodDeclaration.Underscore /** * Get the list of contexts that contain user information for the specified user. * @@ -125,6 +128,7 @@ public static function _get_contexts_for_userid($userid) { } + // phpcs:disable PSR2.Methods.MethodDeclaration.Underscore /** * Export all plagiarism data from each plagiarism plugin for the specified userid and context. * @@ -163,6 +167,7 @@ public static function _export_plagiarism_user_data($userid, \context $context, } } + // phpcs:disable PSR2.Methods.MethodDeclaration.Underscore /** * Export the supplied personal data for a single activity, along with any generic data or area files. * @@ -170,7 +175,8 @@ public static function _export_plagiarism_user_data($userid, \context $context, * @param \context_module $context the module context. * @param \stdClass $user the user record */ - protected static function _export_plagiarism_turnitin_data_for_user(array $submissiondata, \context_module $context, \stdClass $user) { + protected static function _export_plagiarism_turnitin_data_for_user(array $submissiondata, \context_module $context, + \stdClass $user) { // Fetch the generic module data. $contextdata = helper::get_context_data($context, $user); @@ -182,6 +188,7 @@ protected static function _export_plagiarism_turnitin_data_for_user(array $submi helper::export_context_files($context, $user); } + // phpcs:disable PSR2.Methods.MethodDeclaration.Underscore /** * Delete all data for all users in the specified context. * @@ -203,6 +210,7 @@ public static function _delete_plagiarism_for_context(\context $context) { } + // phpcs:disable PSR2.Methods.MethodDeclaration.Underscore /** * Delete all user information for the provided user and context. * @@ -225,26 +233,26 @@ public static function _delete_plagiarism_for_user($userid, \context $context) { * @param userlist $userlist The userlist containing the list of users who have data in this context/plugin combination. */ public static function get_users_in_context(userlist $userlist) { - $context = $userlist->get_context(); - - if ($context->contextlevel != CONTEXT_MODULE) { - return; - } - - $sql = "SELECT ptf.userid - FROM {plagiarism_turnitin_files} ptf - JOIN {course_modules} c - ON ptf.cm = c.id - JOIN {modules} m - ON m.id = c.module AND m.name = :modname - WHERE c.id = :cmid"; - - $params = [ - 'modname' => 'plagiarism_turnitin', - 'cmid' => $context->instanceid, - ]; - - $userlist->add_from_sql('userid', $sql, $params); + $context = $userlist->get_context(); + + if ($context->contextlevel != CONTEXT_MODULE) { + return; + } + + $sql = "SELECT ptf.userid + FROM {plagiarism_turnitin_files} ptf + JOIN {course_modules} c + ON ptf.cm = c.id + JOIN {modules} m + ON m.id = c.module AND m.name = :modname + WHERE c.id = :cmid"; + + $params = [ + 'modname' => 'plagiarism_turnitin', + 'cmid' => $context->instanceid, + ]; + + $userlist->add_from_sql('userid', $sql, $params); } /** @@ -253,36 +261,36 @@ public static function get_users_in_context(userlist $userlist) { * @param approved_userlist $userlist The approved context and user information to delete information for. */ public static function delete_data_for_users(approved_userlist $userlist) { - global $DB; + global $DB; - $context = $userlist->get_context(); + $context = $userlist->get_context(); - if ($context->contextlevel != CONTEXT_MODULE) { - return; - } + if ($context->contextlevel != CONTEXT_MODULE) { + return; + } - $userids = $userlist->get_userids(); + $userids = $userlist->get_userids(); - list($insql, $inparams) = $DB->get_in_or_equal($userids, SQL_PARAMS_NAMED); + list($insql, $inparams) = $DB->get_in_or_equal($userids, SQL_PARAMS_NAMED); - $sql1 = "SELECT pts.id - FROM {plagiarism_turnitin_files} ptf - JOIN {course_modules} c - ON ptf.cm = c.id - JOIN {modules} m - ON m.id = c.module AND m.name = :modname - WHERE pts.userid $insql - AND c.id = :cmid"; + $sql1 = "SELECT pts.id + FROM {plagiarism_turnitin_files} ptf + JOIN {course_modules} c + ON ptf.cm = c.id + JOIN {modules} m + ON m.id = c.module AND m.name = :modname + WHERE pts.userid $insql + AND c.id = :cmid"; - $params = [ - 'modname' => 'plagiarism_turnitin', - 'cmid' => $context->instanceid, - ]; + $params = [ + 'modname' => 'plagiarism_turnitin', + 'cmid' => $context->instanceid, + ]; - $params = array_merge($params, $inparams); + $params = array_merge($params, $inparams); - $attempt = $DB->get_fieldset_sql($sql1, $params); + $attempt = $DB->get_fieldset_sql($sql1, $params); - $DB->delete_records_list('plagiarism_turnitin', 'id', array_values($attempt)); + $DB->delete_records_list('plagiarism_turnitin', 'id', array_values($attempt)); } } diff --git a/classes/task/send_submissions.php b/classes/task/send_submissions.php index feb64051..86c19207 100644 --- a/classes/task/send_submissions.php +++ b/classes/task/send_submissions.php @@ -18,23 +18,33 @@ * Send queued submissions to Turnitin. * * @package plagiarism_turnitin + * @copyright Turnitin * @author John McGettrick http://www.turnitin.com * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ namespace plagiarism_turnitin\task; -defined('MOODLE_INTERNAL') || die(); - /** * Send queued submissions to Turnitin. */ class send_submissions extends \core\task\scheduled_task { + /** + * Get the name of the task. + * + * @return \lang_string|string + * @throws \coding_exception + */ public function get_name() { return get_string('sendqueuedsubmissions', 'plagiarism_turnitin'); } + /** + * Execute the task. + * + * @return void + */ public function execute() { global $CFG; diff --git a/classes/task/update_reports.php b/classes/task/update_reports.php index 09ea5d52..c13283df 100644 --- a/classes/task/update_reports.php +++ b/classes/task/update_reports.php @@ -18,23 +18,33 @@ * Update report Scores from Turnitin. * * @package plagiarism_turnitin + * @copyright Turnitin * @author John McGettrick http://www.turnitin.com * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ namespace plagiarism_turnitin\task; -defined('MOODLE_INTERNAL') || die(); - /** * Update report Scores from Turnitin. */ class update_reports extends \core\task\scheduled_task { + /** + * Get the name of the task. + * + * @return \lang_string|string + * @throws \coding_exception + */ public function get_name() { return get_string('updatereportscores', 'plagiarism_turnitin'); } + /** + * Execute the task. + * + * @return void + */ public function execute() { global $CFG; diff --git a/classes/turnitin_assignment.class.php b/classes/turnitin_assignment.class.php index 868ff043..fc8a80a6 100644 --- a/classes/turnitin_assignment.class.php +++ b/classes/turnitin_assignment.class.php @@ -16,11 +16,6 @@ use Integrations\PhpSdk\TiiClass; -/** - * @package plagiarism_turnitin - * @copyright 2018 iParadigms LLC * - */ - defined('MOODLE_INTERNAL') || die(); require_once($CFG->dirroot.'/plagiarism/turnitin/lib.php'); @@ -28,11 +23,30 @@ require_once($CFG->dirroot.'/plagiarism/turnitin/classes/turnitin_user.class.php'); require_once($CFG->dirroot.'/plagiarism/turnitin/classes/turnitin_submission.class.php'); +/** + * Defines the class for Turnitin assignments + * + * @package plagiarism_turnitin + * @copyright 2018 iParadigms LLC * + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ class turnitin_assignment { + /** + * @var int|mixed + */ private $id; + /** + * @var mixed|turnitin_comms|null + */ private $turnitincomms; + /** + * turnitin_assignment constructor. + * + * @param $id + * @param $turnitincomms + */ public function __construct($id = 0, $turnitincomms = null) { $this->id = $id; $this->turnitincomms = $turnitincomms; @@ -74,7 +88,6 @@ public static function get_course_data($courseid, $workflowcontext = "site") { /** * Create the course in Turnitin * - * @global type $DB * @param object $course The course object * @param string $workflowcontext The workflow being used to call this - site or cron. * @return object the turnitin course if created @@ -128,7 +141,6 @@ public function create_tii_course($course, $workflowcontext = "site") { /** * Edit the course title in Turnitin * - * @global type $DB * @param var $course The course object */ public function edit_tii_course($course) { @@ -269,7 +281,6 @@ public function edit_tii_assignment($assignment, $workflowcontext = "site") { /** * Get the Peermark assignments for this activity. * - * @global type $DB * @param $tiiassignid * @return array */ diff --git a/classes/turnitin_class.class.php b/classes/turnitin_class.class.php index 42311b08..e53d90f4 100644 --- a/classes/turnitin_class.class.php +++ b/classes/turnitin_class.class.php @@ -16,21 +16,46 @@ use Integrations\PhpSdk\TiiClass; -// @package plagiarism_turnitin -// @copyright 2012 iParadigms LLC - defined('MOODLE_INTERNAL') || die(); require_once($CFG->dirroot.'/plagiarism/turnitin/classes/turnitin_comms.class.php'); +/** + * Class turnitin_class + * + * @package plagiarism_turnitin + * @copyright 2012 iParadigms LLC * + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ class turnitin_class { + /** + * @var int + */ private $id; + /** + * @var int + */ private $turnitinid; + /** + * @var string + */ private $title; + /** + * @var string + */ private $turnitintitle; + /** + * @var string + */ public $sharedrubrics; + /** + * turnitin_class constructor. + * + * @param $id + * @throws dml_exception + */ public function __construct($id) { global $DB; diff --git a/classes/turnitin_comms.class.php b/classes/turnitin_comms.class.php index 767bedf7..f7d2961d 100644 --- a/classes/turnitin_comms.class.php +++ b/classes/turnitin_comms.class.php @@ -14,6 +14,14 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . +/** + * Defines turnitin_comms class + * + * @package plagiarism_turnitin + * @copyright 2012 iParadigms LLC * + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + /* * To change this template, choose Tools | Templates * and open the template in the editor. @@ -26,22 +34,52 @@ use Integrations\PhpSdk\TurnitinAPI; +/** + * Defines turnitin_comms class + */ class turnitin_comms { + /** + * @var mixed + */ private $tiiaccountid; + /** + * @var mixed|string + */ private $tiiapiurl; + /** + * @var mixed + */ private $tiisecretkey; + /** + * @var int + */ private $tiiintegrationid; + /** + * @var int + */ private $diagnostic; + /** + * @var string + */ private $langcode; + /** + * Constructor + * + * @param $accountid + * @param $accountshared + * @param $url + * @throws moodle_exception + */ public function __construct($accountid = null, $accountshared = null, $url = null) { $config = plagiarism_plugin_turnitin::plagiarism_turnitin_admin_config(); if (!is_null($url)) { $this->tiiapiurl = $url; } else { - $this->tiiapiurl = (substr($config->plagiarism_turnitin_apiurl, -1) == '/') ? substr($config->plagiarism_turnitin_apiurl, 0, -1) : $config->plagiarism_turnitin_apiurl; + $this->tiiapiurl = (substr($config->plagiarism_turnitin_apiurl, -1) == '/') ? + substr($config->plagiarism_turnitin_apiurl, 0, -1) : $config->plagiarism_turnitin_apiurl; } $this->tiiintegrationid = 12; @@ -52,7 +90,8 @@ public function __construct($accountid = null, $accountshared = null, $url = nul plagiarism_turnitin_print_error( 'configureerror', 'plagiarism_turnitin' ); } - $this->diagnostic = (isset($config->plagiarism_turnitin_enablediagnostic)) ? $config->plagiarism_turnitin_enablediagnostic : 1; + $this->diagnostic = (isset($config->plagiarism_turnitin_enablediagnostic)) ? + $config->plagiarism_turnitin_enablediagnostic : 1; $this->langcode = $this->get_lang(); } @@ -61,7 +100,7 @@ public function __construct($accountid = null, $accountshared = null, $url = nul * * @return object \APITurnitin */ - public function initialise_api( $istestingconnection = false ) { + public function initialise_api($istestingconnection = false) { global $CFG, $tiipp; $api = new TurnitinAPI($this->tiiaccountid, $this->tiiapiurl, $this->tiisecretkey, @@ -193,6 +232,8 @@ private function get_lang() { } /** + * Set the diagnostic setting + * * @param int $diagnostic Set diagnostic setting. */ public function set_diagnostic($diagnostic) { diff --git a/classes/turnitin_submission.class.php b/classes/turnitin_submission.class.php index b564c2a1..f81f6b19 100644 --- a/classes/turnitin_submission.class.php +++ b/classes/turnitin_submission.class.php @@ -15,21 +15,39 @@ // along with Moodle. If not, see . /** + * Defines turnitin_submission class + * * @package plagiarism_turnitin * @copyright 2012 iParadigms LLC * + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ - -if (!defined('MOODLE_INTERNAL')) { - die('Direct access to this script is forbidden.'); // It must be included from a Moodle page. -} - class turnitin_submission { + /** + * @var int + */ private $id; + /** + * @var array|mixed + */ private $data; + /** + * @var false|mixed|stdClass + */ private $submissiondata; + /** + * @var false|stdClass + */ private $cm; + /** + * Class turnitin_submission constructor. + * + * @param $id + * @param $data + * @throws coding_exception + * @throws dml_exception + */ public function __construct($id, $data = []) { global $DB; diff --git a/classes/turnitin_user.class.php b/classes/turnitin_user.class.php index 816e523c..23f87001 100644 --- a/classes/turnitin_user.class.php +++ b/classes/turnitin_user.class.php @@ -21,26 +21,72 @@ use Integrations\PhpSdk\TurnitinApiException; /** + * Define the Turnitin User class + * * @package plagiarism_turnitin * @copyright 2018 iParadigms LLC * + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ - -defined('MOODLE_INTERNAL') || die(); - class turnitin_user { + + /** + * @var int + */ public $id; + /** + * @var int + */ public $tiiuserid; + /** + * @var string + */ private $role; + /** + * @var string + */ public $firstname; + /** + * @var string + */ public $lastname; + /** + * @var string + */ public $fullname; + /** + * @var string + */ public $email; + /** + * @var string + */ public $username; + /** + * @var bool + */ public $useragreementaccepted; + /** + * @var mixed|true + */ private $enrol; + /** + * @var mixed|string + */ private $workflowcontext; + /** + * @var string + */ private $instructorrubrics; + /** + * Constructor for the Turnitin User class + * + * @param $id + * @param $role + * @param $enrol + * @param $workflowcontext + * @param $finduser + */ public function __construct($id, $role = "Learner", $enrol = true, $workflowcontext = "site", $finduser = true) { $this->id = $id; $this->set_user_role($role); @@ -108,7 +154,8 @@ public function get_moodle_user($userid) { */ public static function get_pseudo_domain() { $config = plagiarism_plugin_turnitin::plagiarism_turnitin_admin_config(); - $domain = empty($config->plagiarism_turnitin_pseudoemaildomain) ? PLAGIARISM_TURNITIN_DEFAULT_PSEUDO_DOMAIN : $config->plagiarism_turnitin_pseudoemaildomain; + $domain = empty($config->plagiarism_turnitin_pseudoemaildomain) ? + PLAGIARISM_TURNITIN_DEFAULT_PSEUDO_DOMAIN : $config->plagiarism_turnitin_pseudoemaildomain; return $domain; } @@ -121,7 +168,8 @@ public static function get_pseudo_domain() { public function get_pseudo_firstname() { $config = plagiarism_plugin_turnitin::plagiarism_turnitin_admin_config(); - return !empty( $config->plagiarism_turnitin_pseudofirstname ) ? $config->plagiarism_turnitin_pseudofirstname : PLAGIARISM_TURNITIN_DEFAULT_PSEUDO_FIRSTNAME; + return !empty( $config->plagiarism_turnitin_pseudofirstname ) ? + $config->plagiarism_turnitin_pseudofirstname : PLAGIARISM_TURNITIN_DEFAULT_PSEUDO_FIRSTNAME; } /** @@ -133,9 +181,11 @@ public function get_pseudo_firstname() { public function get_pseudo_lastname() { global $DB; $config = plagiarism_plugin_turnitin::plagiarism_turnitin_admin_config(); - $userinfo = $DB->get_record('user_info_data', ['userid' => $this->id, 'fieldid' => $config->plagiarism_turnitin_pseudolastname]); + $userinfo = $DB->get_record('user_info_data', ['userid' => $this->id, + 'fieldid' => $config->plagiarism_turnitin_pseudolastname]); - if ((!isset($userinfo->data) || empty($userinfo->data)) && $config->plagiarism_turnitin_pseudolastname != 0 && $config->plagiarism_turnitin_lastnamegen == 1) { + if ((!isset($userinfo->data) || empty($userinfo->data)) && $config->plagiarism_turnitin_pseudolastname != 0 && + $config->plagiarism_turnitin_lastnamegen == 1) { $uniqueid = strtoupper(strrev(uniqid())); $userinfoob = new stdClass(); $userinfoob->userid = $this->id; @@ -312,7 +362,6 @@ public function edit_tii_user() { /** * Remove Link between moodle user and Turnitin from database * - * @global type $DB * @param int $tiidbid The Turnitin database id * @return void */ @@ -336,7 +385,6 @@ public function unlink_user($tiidbid) { /** * Save the link between the moodle user and Turnitin * - * @global type $DB * @return void */ private function save_tii_user() { @@ -557,7 +605,6 @@ public function get_instructor_rubrics() { /** * Get users for unlinking/relinking. Called from ajax.php via turnitin_settings.js. * - * @global type $DB * @return array return array of users to display */ public static function plagiarism_turnitin_getusers() { @@ -634,7 +681,7 @@ public static function plagiarism_turnitin_getusers() { $pseudoemail = ""; if (!empty($config->plagiarism_turnitin_enablepseudo)) { - $pseudouser = new TiiPseudoUser(turnitin_user::get_pseudo_domain()); + $pseudouser = new TiiPseudoUser(self::get_pseudo_domain()); $pseudouser->setEmail($user->email); $pseudoemail = $pseudouser->getEmail(); } diff --git a/classes/turnitin_view.class.php b/classes/turnitin_view.class.php index 7fba327b..680b0d92 100644 --- a/classes/turnitin_view.class.php +++ b/classes/turnitin_view.class.php @@ -16,12 +16,17 @@ use Integrations\PhpSdk\TiiLTI; -if (!defined('MOODLE_INTERNAL')) { - die('Direct access to this script is forbidden.'); // It must be included from a Moodle page. -} +defined('MOODLE_INTERNAL') || die(); require_once($CFG->dirroot.'/plagiarism/turnitin/lib.php'); +/** + * Define the turnitin_view class + * + * @package plagiarism_turnitin + * @copyright 2018 iParadigms LLC * + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ class turnitin_view { /** @@ -60,7 +65,8 @@ public function draw_settings_tab_menu($currenttab, $notice = null) { get_string('config', 'plagiarism_turnitin'), get_string('config', 'plagiarism_turnitin'), false); $tabs[] = new tabobject('turnitindefaults', 'settings.php?do=defaults', get_string('defaults', 'plagiarism_turnitin'), get_string('defaults', 'plagiarism_turnitin'), false); - $tabs[] = new tabobject('dbexport', new moodle_url('/plagiarism/turnitin/dbexport.php'), get_string('dbexport', 'plagiarism_turnitin')); + $tabs[] = new tabobject('dbexport', new moodle_url('/plagiarism/turnitin/dbexport.php'), + get_string('dbexport', 'plagiarism_turnitin')); $tabs[] = new tabobject('apilog', 'settings.php?do=apilog', get_string('logs'), get_string('logs'), false); $tabs[] = new tabobject('unlinkusers', 'settings.php?do=unlinkusers', @@ -78,14 +84,14 @@ public function draw_settings_tab_menu($currenttab, $notice = null) { * Due to moodle's internal plugin hooks we can not use our bespoke form class for Turnitin * settings. This form shows in settings > defaults as well as the activity creation screen. * - * @global type $CFG * @param type $plugin_defaults * @return type */ - public function add_elements_to_settings_form($mform, $course, $location = "activity", $modulename = "", $cmid = 0, $currentrubric = 0) { + public function add_elements_to_settings_form($mform, $course, $location = "activity", $modulename = "", $cmid = 0, + $currentrubric = 0) { global $PAGE, $USER, $DB, $CFG; - // Include JS strings + // Include JS strings. $PAGE->requires->string_for_js('changerubricwarning', 'plagiarism_turnitin'); $PAGE->requires->string_for_js('closebutton', 'plagiarism_turnitin'); @@ -167,8 +173,9 @@ public function add_elements_to_settings_form($mform, $course, $location = "acti ] ); - $refreshgrades .= html_writer::tag('div', html_writer::tag('span', get_string('turnitinrefreshingsubmissions', 'plagiarism_turnitin')), - ['class' => 'plagiarism_turnitin_refreshing_grades']); + $refreshgrades .= html_writer::tag('div', html_writer::tag('span', + get_string('turnitinrefreshingsubmissions', 'plagiarism_turnitin')), + ['class' => 'plagiarism_turnitin_refreshing_grades']); } } @@ -221,7 +228,8 @@ public function add_elements_to_settings_form($mform, $course, $location = "acti $mform->addElement('select', 'use_turnitin', get_string("useturnitin", "plagiarism_turnitin"), $options); $this->lock($mform, $location, $locks); - $mform->addElement('select', 'plagiarism_show_student_report', get_string("studentreports", "plagiarism_turnitin"), $options); + $mform->addElement('select', 'plagiarism_show_student_report', get_string("studentreports", + "plagiarism_turnitin"), $options); $this->lock($mform, $location, $locks); $mform->addHelpButton('plagiarism_show_student_report', 'studentreports', 'plagiarism_turnitin'); @@ -229,12 +237,14 @@ public function add_elements_to_settings_form($mform, $course, $location = "acti $tiidraftoptions = [0 => get_string("submitondraft", "plagiarism_turnitin"), 1 => get_string("submitonfinal", "plagiarism_turnitin"), ]; - $mform->addElement('select', 'plagiarism_draft_submit', get_string("draftsubmit", "plagiarism_turnitin"), $tiidraftoptions); + $mform->addElement('select', 'plagiarism_draft_submit', get_string("draftsubmit", + "plagiarism_turnitin"), $tiidraftoptions); $this->lock($mform, $location, $locks); $mform->disabledIf('plagiarism_draft_submit', 'submissiondrafts', 'eq', 0); } - $mform->addElement('select', 'plagiarism_allow_non_or_submissions', get_string("allownonor", "plagiarism_turnitin"), $options); + $mform->addElement('select', 'plagiarism_allow_non_or_submissions', get_string("allownonor", + "plagiarism_turnitin"), $options); $this->lock($mform, $location, $locks); $mform->addHelpButton('plagiarism_allow_non_or_submissions', 'allownonor', 'plagiarism_turnitin'); @@ -242,14 +252,17 @@ public function add_elements_to_settings_form($mform, $course, $location = "acti 1 => get_string('standardrepository', 'plagiarism_turnitin'), ]; switch ($config->plagiarism_turnitin_repositoryoption) { case 0; // Standard options. - $mform->addElement('select', 'plagiarism_submitpapersto', get_string('submitpapersto', 'plagiarism_turnitin'), $suboptions); + $mform->addElement('select', 'plagiarism_submitpapersto', get_string('submitpapersto', + 'plagiarism_turnitin'), $suboptions); $mform->addHelpButton('plagiarism_submitpapersto', 'submitpapersto', 'plagiarism_turnitin'); $this->lock($mform, $location, $locks); break; case PLAGIARISM_TURNITIN_ADMIN_REPOSITORY_OPTION_EXPANDED; // Standard options + Allow Instituional Repository. - $suboptions[PLAGIARISM_TURNITIN_SUBMIT_TO_INSTITUTIONAL_REPOSITORY] = get_string('institutionalrepository', 'plagiarism_turnitin'); + $suboptions[PLAGIARISM_TURNITIN_SUBMIT_TO_INSTITUTIONAL_REPOSITORY] = get_string('institutionalrepository', + 'plagiarism_turnitin'); - $mform->addElement('select', 'plagiarism_submitpapersto', get_string('submitpapersto', 'plagiarism_turnitin'), $suboptions); + $mform->addElement('select', 'plagiarism_submitpapersto', get_string('submitpapersto', + 'plagiarism_turnitin'), $suboptions); $mform->addHelpButton('plagiarism_submitpapersto', 'submitpapersto', 'plagiarism_turnitin'); $this->lock($mform, $location, $locks); break; @@ -262,7 +275,8 @@ public function add_elements_to_settings_form($mform, $course, $location = "acti $mform->setType('plagiarism_submitpapersto', PARAM_RAW); break; case PLAGIARISM_TURNITIN_ADMIN_REPOSITORY_OPTION_FORCE_INSTITUTIONAL; // Force Institutional Repository. - $mform->addElement('hidden', 'plagiarism_submitpapersto', PLAGIARISM_TURNITIN_SUBMIT_TO_INSTITUTIONAL_REPOSITORY); + $mform->addElement('hidden', 'plagiarism_submitpapersto', + PLAGIARISM_TURNITIN_SUBMIT_TO_INSTITUTIONAL_REPOSITORY); $mform->setType('plagiarism_submitpapersto', PARAM_RAW); break; } @@ -270,15 +284,18 @@ public function add_elements_to_settings_form($mform, $course, $location = "acti $mform->addElement('html', html_writer::tag('div', get_string('checkagainstnote', 'plagiarism_turnitin'), ['class' => 'tii_checkagainstnote'])); - $mform->addElement('select', 'plagiarism_compare_student_papers', get_string("spapercheck", "plagiarism_turnitin"), $options); + $mform->addElement('select', 'plagiarism_compare_student_papers', get_string("spapercheck", + "plagiarism_turnitin"), $options); $this->lock($mform, $location, $locks); $mform->addHelpButton('plagiarism_compare_student_papers', 'spapercheck', 'plagiarism_turnitin'); - $mform->addElement('select', 'plagiarism_compare_internet', get_string("internetcheck", "plagiarism_turnitin"), $options); + $mform->addElement('select', 'plagiarism_compare_internet', get_string("internetcheck", + "plagiarism_turnitin"), $options); $this->lock($mform, $location, $locks); $mform->addHelpButton('plagiarism_compare_internet', 'internetcheck', 'plagiarism_turnitin'); - $mform->addElement('select', 'plagiarism_compare_journals', get_string("journalcheck", "plagiarism_turnitin"), $options); + $mform->addElement('select', 'plagiarism_compare_journals', get_string("journalcheck", + "plagiarism_turnitin"), $options); $this->lock($mform, $location, $locks); $mform->addHelpButton('plagiarism_compare_journals', 'journalcheck', 'plagiarism_turnitin'); @@ -306,13 +323,15 @@ public function add_elements_to_settings_form($mform, $course, $location = "acti $this->lock($mform, $location, $locks); $mform->addHelpButton('plagiarism_exclude_matches', 'excludevalue', 'plagiarism_turnitin'); - $mform->addElement('text', 'plagiarism_exclude_matches_value', get_string("excludesmallmatchesvalue", "plagiarism_turnitin")); + $mform->addElement('text', 'plagiarism_exclude_matches_value', get_string("excludesmallmatchesvalue", + "plagiarism_turnitin")); $mform->setType('plagiarism_exclude_matches_value', PARAM_INT); $mform->addRule('plagiarism_exclude_matches_value', null, 'numeric', null, 'client'); $mform->disabledIf('plagiarism_exclude_matches_value', 'plagiarism_exclude_matches', 'eq', 0); if ($location == 'defaults') { - $mform->addElement('text', 'plagiarism_locked_message', get_string("locked_message", "plagiarism_turnitin"), 'maxlength="50" size="50"' ); + $mform->addElement('text', 'plagiarism_locked_message', get_string("locked_message", "plagiarism_turnitin"), + 'maxlength="50" size="50"' ); $mform->setType('plagiarism_locked_message', PARAM_TEXT); $mform->setDefault('plagiarism_locked_message', get_string("locked_message_default", "plagiarism_turnitin") ); $mform->addHelpButton('plagiarism_locked_message', 'locked_message', 'plagiarism_turnitin'); @@ -341,7 +360,8 @@ public function add_elements_to_settings_form($mform, $course, $location = "acti ); $rubricmanagerlink = html_writer::tag('div', $rubricmanagerlink, ['class' => 'row_rubric_manager']); - $mform->addElement('selectgroups', 'plagiarism_rubric', get_string('attachrubric', 'plagiarism_turnitin'), $rubrics); + $mform->addElement('selectgroups', 'plagiarism_rubric', get_string('attachrubric', 'plagiarism_turnitin'), + $rubrics); $mform->addElement('static', 'rubric_link', '', $rubricmanagerlink); $mform->setDefault('plagiarism_rubric', ''); @@ -373,35 +393,40 @@ public function add_elements_to_settings_form($mform, $course, $location = "acti $mform->addElement('select', 'plagiarism_erater', get_string('erater', 'plagiarism_turnitin'), $options); $mform->setDefault('plagiarism_erater', 0); - $mform->addElement('select', 'plagiarism_erater_handbook', get_string('erater_handbook', 'plagiarism_turnitin'), + $mform->addElement('select', 'plagiarism_erater_handbook', get_string('erater_handbook', + 'plagiarism_turnitin'), $handbookoptions); $mform->setDefault('plagiarism_erater_handbook', 2); $mform->disabledIf('plagiarism_erater_handbook', 'plagiarism_erater', 'eq', 0); - $mform->addElement('select', 'plagiarism_erater_dictionary', get_string('erater_dictionary', 'plagiarism_turnitin'), + $mform->addElement('select', 'plagiarism_erater_dictionary', get_string('erater_dictionary', + 'plagiarism_turnitin'), $dictionaryoptions); $mform->setDefault('plagiarism_erater_dictionary', 'en_US'); $mform->disabledIf('plagiarism_erater_dictionary', 'plagiarism_erater', 'eq', 0); - $mform->addElement('checkbox', 'plagiarism_erater_spelling', get_string('erater_categories', 'plagiarism_turnitin'), + $mform->addElement('checkbox', 'plagiarism_erater_spelling', get_string('erater_categories', + 'plagiarism_turnitin'), " ".get_string('erater_spelling', 'plagiarism_turnitin')); $mform->disabledIf('plagiarism_erater_spelling', 'plagiarism_erater', 'eq', 0); - $mform->addElement('checkbox', 'plagiarism_erater_grammar', '', " ".get_string('erater_grammar', 'plagiarism_turnitin')); + $mform->addElement('checkbox', 'plagiarism_erater_grammar', '', " ".get_string('erater_grammar', + 'plagiarism_turnitin')); $mform->disabledIf('plagiarism_erater_grammar', 'plagiarism_erater', 'eq', 0); - $mform->addElement('checkbox', 'plagiarism_erater_usage', '', " ".get_string('erater_usage', 'plagiarism_turnitin')); + $mform->addElement('checkbox', 'plagiarism_erater_usage', '', " ".get_string('erater_usage', + 'plagiarism_turnitin')); $mform->disabledIf('plagiarism_erater_usage', 'plagiarism_erater', 'eq', 0); $mform->addElement('checkbox', 'plagiarism_erater_mechanics', '', " ". get_string('erater_mechanics', 'plagiarism_turnitin')); $mform->disabledIf('plagiarism_erater_mechanics', 'plagiarism_erater', 'eq', 0); - $mform->addElement('checkbox', 'plagiarism_erater_style', '', " ".get_string('erater_style', 'plagiarism_turnitin')); + $mform->addElement('checkbox', 'plagiarism_erater_style', '', " ".get_string('erater_style', + 'plagiarism_turnitin')); $mform->disabledIf('plagiarism_erater_style', 'plagiarism_erater', 'eq', 0); } ->>>>>>> 6bc6650 (Fix 'Short array syntax must be used to define arrays' warnings.) $mform->addElement('html', html_writer::tag('div', get_string('anonblindmarkingnote', 'plagiarism_turnitin'), ['class' => 'tii_anonblindmarkingnote'])); @@ -425,6 +450,14 @@ public function add_elements_to_settings_form($mform, $course, $location = "acti } } + /** + * Show the errors table for file uploads. + * + * @param $page + * @return string + * @throws coding_exception + * @throws moodle_exception + */ public function show_file_errors_table($page = 0) { global $CFG, $OUTPUT; @@ -490,7 +523,8 @@ public function show_file_errors_table($page = 0) { $cells["file"] = new html_table_cell(html_writer::link($CFG->wwwroot.'/pluginfile.php/'. $file->get_contextid().'/'.$file->get_component().'/'.$file->get_filearea().'/'. $file->get_itemid().'/'.$file->get_filename(), - $OUTPUT->pix_icon('fileicon', 'open '.$file->get_filename(), 'plagiarism_turnitin'). + $OUTPUT->pix_icon('fileicon', 'open '.$file->get_filename(), + 'plagiarism_turnitin'). " ".$file->get_filename())); } else { $cells["file"] = get_string('filedoesnotexist', 'plagiarism_turnitin'); @@ -513,7 +547,8 @@ public function show_file_errors_table($page = 0) { // Show error message if there is one. $errormsg = $v->errormsg; if ($errorcode == 0) { - $errorstring = (is_null($errormsg)) ? get_string('ppsubmissionerrorseelogs', 'plagiarism_turnitin') : $errormsg; + $errorstring = (is_null($errormsg)) ? get_string('ppsubmissionerrorseelogs', + 'plagiarism_turnitin') : $errormsg; } else { $errorstring = get_string('errorcode'.$v->errorcode, 'plagiarism_turnitin', display_size(PLAGIARISM_TURNITIN_MAX_FILE_UPLOAD_SIZE)); diff --git a/db/access.php b/db/access.php index 31251abf..dbd53f45 100644 --- a/db/access.php +++ b/db/access.php @@ -15,8 +15,11 @@ // along with Moodle. If not, see . /** + * Capabilities for plagiarism_turnitin + * * @package plagiarism_turnitin * @copyright 2012 iParadigms LLC + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ defined('MOODLE_INTERNAL') || die(); diff --git a/db/events.php b/db/events.php index 8a613cb9..4b9fda14 100644 --- a/db/events.php +++ b/db/events.php @@ -15,8 +15,11 @@ // along with Moodle. If not, see . /** + * Event observers for plagiarism_turnitin + * * @package plagiarism_turnitin * @copyright 2012 iParadigms LLC + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ defined('MOODLE_INTERNAL') || die(); diff --git a/db/messages.php b/db/messages.php index 17af1c02..1c26aa94 100644 --- a/db/messages.php +++ b/db/messages.php @@ -15,12 +15,13 @@ // along with Moodle. If not, see . /** - * @package plagiarismplugin + * Message providers for plagiarism_turnitin + * + * @package plagiarism_turnitin * @copyright 2010 iParadigms LLC + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -defined('MOODLE_INTERNAL') || die(); - defined('MOODLE_INTERNAL') || die(); $messageproviders = [ // Notify student with their digital receipt. diff --git a/db/tasks.php b/db/tasks.php index 2f036e71..9404c1d4 100644 --- a/db/tasks.php +++ b/db/tasks.php @@ -15,12 +15,11 @@ // along with Moodle. If not, see . /** + * Task definitions for plagiarism_turnitin + * * @package plagiarism_turnitin * @copyright 2012 iParadigms LLC - */ - -/** - * @package plagiarism_turnitin + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ defined('MOODLE_INTERNAL') || die(); diff --git a/db/upgrade.php b/db/upgrade.php index bcf12e3d..69331d11 100644 --- a/db/upgrade.php +++ b/db/upgrade.php @@ -15,8 +15,11 @@ // along with Moodle. If not, see . /** + * Upgrade steps for plagiarism_turnitin + * * @package plagiarism_turnitin * @copyright 2012 iParadigms LLC + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ defined('MOODLE_INTERNAL') || die(); @@ -24,7 +27,8 @@ require_once($CFG->dirroot.'/plagiarism/turnitin/lib.php'); /** - * @global moodle_database $DB + * Upgrade the plagiarism_turnitin plugin + * * @param int $oldversion * @return bool */ @@ -160,9 +164,6 @@ function xmldb_plagiarism_turnitin_upgrade($oldversion) { if ($oldversion < 2015040107) { upgrade_dm_successful_uploads(); - } - - if ($oldversion < 2015040107) { $table = new xmldb_table('plagiarism_turnitin_files'); $field = new xmldb_field('submitter', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, 'userid'); if (!$dbman->field_exists($table, $field)) { @@ -268,7 +269,8 @@ function xmldb_plagiarism_turnitin_upgrade($oldversion) { $DB->set_field('plagiarism_turnitin_files', 'student_read', null, ['student_read' => 0]); // Remove old PP event from the database if it exists. - $DB->delete_records('task_scheduled', ['component' => 'plagiarism_turnitin', 'classname' => '\plagiarism_turnitin\task\plagiarism_turnitin_task']); + $DB->delete_records('task_scheduled', ['component' => 'plagiarism_turnitin', + 'classname' => '\plagiarism_turnitin\task\plagiarism_turnitin_task']); upgrade_plugin_savepoint(true, 2017012601, 'plagiarism', 'turnitin'); } @@ -293,7 +295,8 @@ function xmldb_plagiarism_turnitin_upgrade($oldversion) { if ($oldversion < 2019031301) { // Reset all error code 13s so that we are on a clean slate with the new implementation. - $DB->execute("UPDATE ".$CFG->prefix."plagiarism_turnitin_files SET statuscode = 'success', errorcode = NULL WHERE errorcode = 13"); + $DB->execute("UPDATE ".$CFG->prefix. + "plagiarism_turnitin_files SET statuscode = 'success', errorcode = NULL WHERE errorcode = 13"); upgrade_plugin_savepoint(true, 2019031301, 'plagiarism', 'turnitin'); } @@ -334,11 +337,13 @@ function xmldb_plagiarism_turnitin_upgrade($oldversion) { // If V2 is installed, copy the courses across from V2. if ($DB->get_record('config_plugins', ['plugin' => 'mod_turnitintooltwo'])) { - $ppcourses = $DB->get_records('turnitintooltwo_courses', ['course_type' => 'PP'], 'id ASC', 'courseid, ownerid, turnitin_ctl, turnitin_cid'); + $ppcourses = $DB->get_records('turnitintooltwo_courses', ['course_type' => 'PP'], 'id ASC', + 'courseid, ownerid, turnitin_ctl, turnitin_cid'); try { $DB->insert_records('plagiarism_turnitin_courses', $ppcourses); } catch (Exception $e) { - plagiarism_turnitin_activitylog('Unable to copy course tables during version upgrade because they already exist.', 'PP_UPGRADE'); + plagiarism_turnitin_activitylog('Unable to copy course tables during version upgrade because they already exist.', + 'PP_UPGRADE'); } // Clean up old data, but only if the number of courses inserted matches the number of courses we wanted to insert. @@ -392,11 +397,13 @@ function xmldb_plagiarism_turnitin_upgrade($oldversion) { // If V2 is installed, copy the users across from V2. if ($DB->get_record('config_plugins', ['plugin' => 'mod_turnitintooltwo'])) { - $ppusers = $DB->get_records('turnitintooltwo_users', null, 'id ASC', 'userid, turnitin_uid, turnitin_utp, instructor_rubrics, user_agreement_accepted'); + $ppusers = $DB->get_records('turnitintooltwo_users', null, 'id ASC', + 'userid, turnitin_uid, turnitin_utp, instructor_rubrics, user_agreement_accepted'); try { $DB->insert_records('plagiarism_turnitin_users', $ppusers); } catch (Exception $e) { - plagiarism_turnitin_activitylog('Unable to copy users table during version upgrade because they already exist.', 'PP_UPGRADE'); + plagiarism_turnitin_activitylog('Unable to copy users table during version upgrade because they already exist.', + 'PP_UPGRADE'); } } upgrade_plugin_savepoint(true, 2019050201, 'plagiarism', 'turnitin'); @@ -421,6 +428,7 @@ function xmldb_plagiarism_turnitin_upgrade($oldversion) { $data = get_config('plagiarism'); $value = (empty($data->turnitin_use)) ? 0 : 1; set_config('enabled', $value, 'plagiarism_turnitin'); + // phpcs:disable moodle.Commenting.TodoComment // TODO: Delete the turnitin_use setting completely when support for 3.8 is dropped. $data = get_config('plagiarism_turnitin'); @@ -439,48 +447,49 @@ function xmldb_plagiarism_turnitin_upgrade($oldversion) { } // Delete the _use value for post 3.9 environments irrespective of plugin version. + // phpcs:disable moodle.Commenting.TodoComment // TODO: Delete completely when we remove 3.8 support. if ($CFG->branch >= 39) { set_config('turnitin_use', null, 'plagiarism'); } - // This block is to solve a number of inconsistencies between the install and upgrade scripts + // This block is to solve a number of inconsistencies between the install and upgrade scripts. if ($oldversion < 2020091401) { - // Set itemid to default to null + // Set itemid to default to null. $table = new xmldb_table('plagiarism_turnitin_files'); $field = new xmldb_field('itemid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, false, false, null, 'externalid'); if ($dbman->field_exists($table, $field)) { $dbman->change_field_default($table, $field); } - // Set student_read to default to null + // Set student_read to default to null. $field = new xmldb_field('student_read', XMLDB_TYPE_INTEGER, '10', false, false, false, null, 'errormsg'); if ($dbman->field_exists($table, $field)) { $dbman->change_field_default($table, $field); } - // Set turnitin_uid to allow null + // Set turnitin_uid to allow null. $table = new xmldb_table('plagiarism_turnitin_users'); $field = new xmldb_field('turnitin_uid', XMLDB_TYPE_INTEGER, '10', null, false, false, null, 'userid'); if ($dbman->field_exists($table, $field)) { $dbman->change_field_notnull($table, $field); } - // Set turnitin_utp to allow null + // Set turnitin_utp to allow null. $field = new xmldb_field('turnitin_utp', XMLDB_TYPE_INTEGER, '10', null, false, false, 0, 'turnitin_uid'); if ($dbman->field_exists($table, $field)) { $dbman->change_field_notnull($table, $field); } - // Set turnitin_ctl to allow null + // Set turnitin_ctl to allow null. $table = new xmldb_table('plagiarism_turnitin_courses'); $field = new xmldb_field('turnitin_ctl', XMLDB_TYPE_TEXT, null, null, false, null, null, 'ownerid'); if ($dbman->field_exists($table, $field)) { $dbman->change_field_notnull($table, $field); } - // Set turnitin_cid to allow null + // Set turnitin_cid to allow null. $field = new xmldb_field('turnitin_cid', XMLDB_TYPE_INTEGER, '10', null, false, null, null, 'turnitin_ctl'); if ($dbman->field_exists($table, $field)) { $dbman->change_field_notnull($table, $field); @@ -554,6 +563,12 @@ function xmldb_plagiarism_turnitin_upgrade($oldversion) { return $result; } +/** + * Update successful submissions from Dan Marsden's plugin with incorrect statuscode. + * + * @return void + * @throws dml_exception + */ function upgrade_dm_successful_uploads() { global $DB, $CFG; diff --git a/extras.php b/extras.php index da35d665..9e2a3716 100644 --- a/extras.php +++ b/extras.php @@ -15,8 +15,11 @@ // along with Moodle. If not, see . /** + * Turnitin extras page + * * @package plagiarism_turnitin * @copyright 2012 iParadigms LLC + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ require_once(__DIR__.'/../../config.php'); diff --git a/lang/ar/plagiarism_turnitin.php b/lang/ar/plagiarism_turnitin.php index e41f489c..5377ac4c 100755 --- a/lang/ar/plagiarism_turnitin.php +++ b/lang/ar/plagiarism_turnitin.php @@ -14,9 +14,16 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . +// Let codechecker ignore some sniffs for this file as it is perfectly well ordered, just not alphabetically. +// phpcs:disable moodle.Files.LangFilesOrdering.UnexpectedComment +// phpcs:disable moodle.Files.LangFilesOrdering.IncorrectOrder + /** + * Strings for component 'qtype_kprime', language 'ar' + * * @package plagiarism_turnitin * @copyright 2012 iParadigms LLC + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ /* diff --git a/lang/cs/plagiarism_turnitin.php b/lang/cs/plagiarism_turnitin.php index 5f43bb14..e4f1b6f0 100755 --- a/lang/cs/plagiarism_turnitin.php +++ b/lang/cs/plagiarism_turnitin.php @@ -14,9 +14,15 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . +// Let codechecker ignore some sniffs for this file as it is perfectly well ordered, just not alphabetically. +// phpcs:disable moodle.Files.LangFilesOrdering.UnexpectedComment +// phpcs:disable moodle.Files.LangFilesOrdering.IncorrectOrder + /** + * Strings for component 'qtype_kprime', language 'cs' * @package plagiarism_turnitin * @copyright 2012 iParadigms LLC + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ /* diff --git a/lang/de/plagiarism_turnitin.php b/lang/de/plagiarism_turnitin.php index fb699cd9..4ac73c86 100755 --- a/lang/de/plagiarism_turnitin.php +++ b/lang/de/plagiarism_turnitin.php @@ -14,9 +14,16 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . +// Let codechecker ignore some sniffs for this file as it is perfectly well ordered, just not alphabetically. +// phpcs:disable moodle.Files.LangFilesOrdering.UnexpectedComment +// phpcs:disable moodle.Files.LangFilesOrdering.IncorrectOrder + /** + * Strings for component 'qtype_kprime', language 'de' + * * @package plagiarism_turnitin * @copyright 2012 iParadigms LLC + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ /* diff --git a/lang/en/plagiarism_turnitin.php b/lang/en/plagiarism_turnitin.php index ae3909ce..7865bcb5 100644 --- a/lang/en/plagiarism_turnitin.php +++ b/lang/en/plagiarism_turnitin.php @@ -14,9 +14,16 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . +// Let codechecker ignore some sniffs for this file as it is perfectly well ordered, just not alphabetically. +// phpcs:disable moodle.Files.LangFilesOrdering.UnexpectedComment +// phpcs:disable moodle.Files.LangFilesOrdering.IncorrectOrder + /** + * Strings for component 'qtype_kprime', language 'en' + * * @package plagiarism_turnitin * @copyright 2012 iParadigms LLC + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ /* diff --git a/lang/es/plagiarism_turnitin.php b/lang/es/plagiarism_turnitin.php index 09af88b8..a2736e8e 100755 --- a/lang/es/plagiarism_turnitin.php +++ b/lang/es/plagiarism_turnitin.php @@ -14,9 +14,16 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . +// Let codechecker ignore some sniffs for this file as it is perfectly well ordered, just not alphabetically. +// phpcs:disable moodle.Files.LangFilesOrdering.UnexpectedComment +// phpcs:disable moodle.Files.LangFilesOrdering.IncorrectOrder + /** + * Strings for component 'qtype_kprime', language 'es' + * * @package plagiarism_turnitin * @copyright 2012 iParadigms LLC + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ /* diff --git a/lang/fi/plagiarism_turnitin.php b/lang/fi/plagiarism_turnitin.php index 3167da50..0b4039f2 100755 --- a/lang/fi/plagiarism_turnitin.php +++ b/lang/fi/plagiarism_turnitin.php @@ -14,9 +14,16 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . +// Let codechecker ignore some sniffs for this file as it is perfectly well ordered, just not alphabetically. +// phpcs:disable moodle.Files.LangFilesOrdering.UnexpectedComment +// phpcs:disable moodle.Files.LangFilesOrdering.IncorrectOrder + /** + * Strings for component 'qtype_kprime', language 'fi' + * * @package plagiarism_turnitin * @copyright 2012 iParadigms LLC + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ /* diff --git a/lang/fr/plagiarism_turnitin.php b/lang/fr/plagiarism_turnitin.php index 82170cc8..dfacdf6c 100755 --- a/lang/fr/plagiarism_turnitin.php +++ b/lang/fr/plagiarism_turnitin.php @@ -14,9 +14,16 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . +// Let codechecker ignore some sniffs for this file as it is perfectly well ordered, just not alphabetically. +// phpcs:disable moodle.Files.LangFilesOrdering.UnexpectedComment +// phpcs:disable moodle.Files.LangFilesOrdering.IncorrectOrder + /** + * Strings for component 'qtype_kprime', language 'fr' + * * @package plagiarism_turnitin * @copyright 2012 iParadigms LLC + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ /* diff --git a/lang/it/plagiarism_turnitin.php b/lang/it/plagiarism_turnitin.php index 318e9ee9..a892c02b 100755 --- a/lang/it/plagiarism_turnitin.php +++ b/lang/it/plagiarism_turnitin.php @@ -14,9 +14,16 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . +// Let codechecker ignore some sniffs for this file as it is perfectly well ordered, just not alphabetically. +// phpcs:disable moodle.Files.LangFilesOrdering.UnexpectedComment +// phpcs:disable moodle.Files.LangFilesOrdering.IncorrectOrder + /** + * Strings for component 'qtype_kprime', language 'it' + * * @package plagiarism_turnitin * @copyright 2012 iParadigms LLC + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ /* diff --git a/lang/ja/plagiarism_turnitin.php b/lang/ja/plagiarism_turnitin.php index b9dd2b92..1515e0db 100755 --- a/lang/ja/plagiarism_turnitin.php +++ b/lang/ja/plagiarism_turnitin.php @@ -14,9 +14,16 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . +// Let codechecker ignore some sniffs for this file as it is perfectly well ordered, just not alphabetically. +// phpcs:disable moodle.Files.LangFilesOrdering.UnexpectedComment +// phpcs:disable moodle.Files.LangFilesOrdering.IncorrectOrder + /** + * Strings for component 'qtype_kprime', language 'ja' + * * @package plagiarism_turnitin * @copyright 2012 iParadigms LLC + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ /* diff --git a/lang/ko/plagiarism_turnitin.php b/lang/ko/plagiarism_turnitin.php index b4c3391c..81bc31aa 100755 --- a/lang/ko/plagiarism_turnitin.php +++ b/lang/ko/plagiarism_turnitin.php @@ -14,9 +14,16 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . +// Let codechecker ignore some sniffs for this file as it is perfectly well ordered, just not alphabetically. +// phpcs:disable moodle.Files.LangFilesOrdering.UnexpectedComment +// phpcs:disable moodle.Files.LangFilesOrdering.IncorrectOrder + /** + * Strings for component 'qtype_kprime', language 'ko' + * * @package plagiarism_turnitin * @copyright 2012 iParadigms LLC + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ /* diff --git a/lang/nl/plagiarism_turnitin.php b/lang/nl/plagiarism_turnitin.php index 0b679959..6e87e862 100755 --- a/lang/nl/plagiarism_turnitin.php +++ b/lang/nl/plagiarism_turnitin.php @@ -14,9 +14,16 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . +// Let codechecker ignore some sniffs for this file as it is perfectly well ordered, just not alphabetically. +// phpcs:disable moodle.Files.LangFilesOrdering.UnexpectedComment +// phpcs:disable moodle.Files.LangFilesOrdering.IncorrectOrder + /** + * Strings for component 'qtype_kprime', language 'nl' + * * @package plagiarism_turnitin * @copyright 2012 iParadigms LLC + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ /* diff --git a/lang/pl/plagiarism_turnitin.php b/lang/pl/plagiarism_turnitin.php index 87d983bc..8ae8796e 100755 --- a/lang/pl/plagiarism_turnitin.php +++ b/lang/pl/plagiarism_turnitin.php @@ -14,9 +14,16 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . +// Let codechecker ignore some sniffs for this file as it is perfectly well ordered, just not alphabetically. +// phpcs:disable moodle.Files.LangFilesOrdering.UnexpectedComment +// phpcs:disable moodle.Files.LangFilesOrdering.IncorrectOrder + /** + * Strings for component 'qtype_kprime', language 'pl' + * * @package plagiarism_turnitin * @copyright 2012 iParadigms LLC + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ /* diff --git a/lang/pt_br/plagiarism_turnitin.php b/lang/pt_br/plagiarism_turnitin.php index 457e6498..8746b370 100755 --- a/lang/pt_br/plagiarism_turnitin.php +++ b/lang/pt_br/plagiarism_turnitin.php @@ -14,9 +14,16 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . +// Let codechecker ignore some sniffs for this file as it is perfectly well ordered, just not alphabetically. +// phpcs:disable moodle.Files.LangFilesOrdering.UnexpectedComment +// phpcs:disable moodle.Files.LangFilesOrdering.IncorrectOrder + /** + * Strings for component 'qtype_kprime', language 'pt_br' + * * @package plagiarism_turnitin * @copyright 2012 iParadigms LLC + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ /* diff --git a/lang/ro/plagiarism_turnitin.php b/lang/ro/plagiarism_turnitin.php index 7c1e78f4..56cdb602 100755 --- a/lang/ro/plagiarism_turnitin.php +++ b/lang/ro/plagiarism_turnitin.php @@ -14,9 +14,16 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . +// Let codechecker ignore some sniffs for this file as it is perfectly well ordered, just not alphabetically. +// phpcs:disable moodle.Files.LangFilesOrdering.UnexpectedComment +// phpcs:disable moodle.Files.LangFilesOrdering.IncorrectOrder + /** + * Strings for component 'qtype_kprime', language 'ro' + * * @package plagiarism_turnitin * @copyright 2012 iParadigms LLC + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ /* diff --git a/lang/ru/plagiarism_turnitin.php b/lang/ru/plagiarism_turnitin.php index d44f9452..05921b0e 100755 --- a/lang/ru/plagiarism_turnitin.php +++ b/lang/ru/plagiarism_turnitin.php @@ -14,9 +14,16 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . +// Let codechecker ignore some sniffs for this file as it is perfectly well ordered, just not alphabetically. +// phpcs:disable moodle.Files.LangFilesOrdering.UnexpectedComment +// phpcs:disable moodle.Files.LangFilesOrdering.IncorrectOrder + /** + * Strings for component 'qtype_kprime', language 'ru' + * * @package plagiarism_turnitin * @copyright 2012 iParadigms LLC + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ /* diff --git a/lang/sv/plagiarism_turnitin.php b/lang/sv/plagiarism_turnitin.php index 454c7ff8..0baf4c98 100755 --- a/lang/sv/plagiarism_turnitin.php +++ b/lang/sv/plagiarism_turnitin.php @@ -14,9 +14,16 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . +// Let codechecker ignore some sniffs for this file as it is perfectly well ordered, just not alphabetically. +// phpcs:disable moodle.Files.LangFilesOrdering.UnexpectedComment +// phpcs:disable moodle.Files.LangFilesOrdering.IncorrectOrder + /** + * Strings for component 'qtype_kprime', language 'sv' + * * @package plagiarism_turnitin * @copyright 2012 iParadigms LLC + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ /* diff --git a/lang/tr/plagiarism_turnitin.php b/lang/tr/plagiarism_turnitin.php index 6829b063..e4b58493 100755 --- a/lang/tr/plagiarism_turnitin.php +++ b/lang/tr/plagiarism_turnitin.php @@ -14,9 +14,16 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . +// Let codechecker ignore some sniffs for this file as it is perfectly well ordered, just not alphabetically. +// phpcs:disable moodle.Files.LangFilesOrdering.UnexpectedComment +// phpcs:disable moodle.Files.LangFilesOrdering.IncorrectOrder + /** + * Strings for component 'qtype_kprime', language 'tr' + * * @package plagiarism_turnitin * @copyright 2012 iParadigms LLC + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ /* diff --git a/lang/vi/plagiarism_turnitin.php b/lang/vi/plagiarism_turnitin.php index fd4dc278..d085288f 100755 --- a/lang/vi/plagiarism_turnitin.php +++ b/lang/vi/plagiarism_turnitin.php @@ -14,9 +14,16 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . +// Let codechecker ignore some sniffs for this file as it is perfectly well ordered, just not alphabetically. +// phpcs:disable moodle.Files.LangFilesOrdering.UnexpectedComment +// phpcs:disable moodle.Files.LangFilesOrdering.IncorrectOrder + /** + * Strings for component 'qtype_kprime', language 'vi' + * * @package plagiarism_turnitin * @copyright 2012 iParadigms LLC + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ /* diff --git a/lang/zh_hans/plagiarism_turnitin.php b/lang/zh_hans/plagiarism_turnitin.php index 12b0b798..24811abc 100755 --- a/lang/zh_hans/plagiarism_turnitin.php +++ b/lang/zh_hans/plagiarism_turnitin.php @@ -14,9 +14,16 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . +// Let codechecker ignore some sniffs for this file as it is perfectly well ordered, just not alphabetically. +// phpcs:disable moodle.Files.LangFilesOrdering.UnexpectedComment +// phpcs:disable moodle.Files.LangFilesOrdering.IncorrectOrder + /** + * Strings for component 'qtype_kprime', language 'zh_hans' + * * @package plagiarism_turnitin * @copyright 2012 iParadigms LLC + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ /* diff --git a/lang/zh_tw/plagiarism_turnitin.php b/lang/zh_tw/plagiarism_turnitin.php index 37f03ac2..c9fa3afb 100755 --- a/lang/zh_tw/plagiarism_turnitin.php +++ b/lang/zh_tw/plagiarism_turnitin.php @@ -14,9 +14,16 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . +// Let codechecker ignore some sniffs for this file as it is perfectly well ordered, just not alphabetically. +// phpcs:disable moodle.Files.LangFilesOrdering.UnexpectedComment +// phpcs:disable moodle.Files.LangFilesOrdering.IncorrectOrder + /** + * Strings for component 'qtype_kprime', language 'zh_tw' + * * @package plagiarism_turnitin * @copyright 2012 iParadigms LLC + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ /* diff --git a/lib.php b/lib.php index ca7fb8e1..4ff966ea 100755 --- a/lib.php +++ b/lib.php @@ -14,9 +14,12 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -/* +/** + * Turnitin lib file + * * @package plagiarism_turnitin * @copyright 2013 iParadigms LLC + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ use Integrations\PhpSdk\TiiClass; @@ -24,9 +27,9 @@ use Integrations\PhpSdk\TiiAssignment; use Integrations\PhpSdk\TiiLTI; -if (!defined('MOODLE_INTERNAL')) { - die('Direct access to this script is forbidden.'); // It must be included from a Moodle page. -} +defined('MOODLE_INTERNAL') || die(); + +// phpcs:ignore moodle.Commenting.InlineComment.SpacingBefore // Constants. define('PLAGIARISM_TURNITIN_MAX_FILE_UPLOAD_SIZE', 104857600); @@ -84,10 +87,13 @@ require_once($CFG->dirroot.'/plagiarism/turnitin/classes/modules/turnitin_workshop.class.php'); require_once($CFG->dirroot.'/plagiarism/turnitin/classes/modules/turnitin_coursework.class.php'); +/** + * Class plagiarism_plugin_turnitin + */ class plagiarism_plugin_turnitin extends plagiarism_plugin { /** - * Static variable to load the function from js files by using js_call_amd only once. + * @var bool Static variable to load the function from js files by using js_call_amd only once. */ private static $amdcomponentsloaded = false; @@ -116,6 +122,8 @@ public static function get_config_settings($modulename) { } /** + * Return the admin config settings for the plugin + * * @return mixed the admin config settings for the plugin */ public static function plagiarism_turnitin_admin_config() { @@ -161,7 +169,6 @@ public function get_settings($cmid = null, $uselockedvalues = true) { * @param int $limit Max records to return. * @param bool $count If true, returns a count of the total number of * records. - * @access public * @return array|int A list of records, or count when $count is true. */ public function get_file_upload_errors($offset = 0, $limit = 0, $count = false) { @@ -218,7 +225,6 @@ public function is_plugin_configured() { /** * Save the form data associated with the plugin * - * @global type $DB * @param object $data the form data to save */ public function save_form_data($data) { @@ -244,12 +250,14 @@ public function save_form_data($data) { $optionfield->id = $DB->get_field('plagiarism_turnitin_config', 'id', (['cm' => $data->coursemodule, 'name' => $field])); if (!$DB->update_record('plagiarism_turnitin_config', $optionfield)) { - plagiarism_turnitin_print_error('defaultupdateerror', 'plagiarism_turnitin', null, null, __FILE__, __LINE__); + plagiarism_turnitin_print_error('defaultupdateerror', 'plagiarism_turnitin', null, + null, __FILE__, __LINE__); } } else { $optionfield->config_hash = $optionfield->cm."_".$optionfield->name; if (!$DB->insert_record('plagiarism_turnitin_config', $optionfield)) { - plagiarism_turnitin_print_error('defaultinserterror', 'plagiarism_turnitin', null, null, __FILE__, __LINE__); + plagiarism_turnitin_print_error('defaultinserterror', 'plagiarism_turnitin', null, + null, __FILE__, __LINE__); } } } @@ -303,13 +311,15 @@ public function add_settings_form_to_activity_page($mform, $context, $modulename $plagiarismelements = $this->get_settings_fields(); $turnitinview = new turnitin_view(); - $plagiarismvalues["plagiarism_rubric"] = ( !empty($plagiarismvalues["plagiarism_rubric"]) ) ? $plagiarismvalues["plagiarism_rubric"] : 0; + $plagiarismvalues["plagiarism_rubric"] = ( !empty($plagiarismvalues["plagiarism_rubric"]) ) ? + $plagiarismvalues["plagiarism_rubric"] : 0; // We don't require the settings form on Moodle 3.3's bulk completion feature. // We also don't require the settings form on Moodle 4.3's bulk completion feature (MDL-78528). if ($PAGE->pagetype != 'course-editbulkcompletion' && $PAGE->pagetype != 'course-editdefaultcompletion' && $PAGE->pagetype != 'course-defaultcompletion') { + // Check for existing settings and add the form $course = turnitin_assignment::get_course_data($COURSE->id, "site"); $turnitinview->add_elements_to_settings_form($mform, $course, "activity", $modulename, $cmid, $plagiarismvalues["plagiarism_rubric"]); @@ -442,9 +452,6 @@ public function test_turnitin_connection($workflowcontext = 'site') { /** * Print the Turnitin student disclosure inside the submission page for students to see * - * @global $OUTPUT - * @global $USER - * @global $CFG * @param $cmid * @return string */ @@ -480,7 +487,8 @@ public function print_disclosure($cmid) { if ($tiisubmissions) { $genparams = $this->plagiarism_get_report_gen_speed_params(); - $output .= html_writer::tag('div', get_string('reportgenspeed_resubmission', 'plagiarism_turnitin', $genparams), ['class' => 'tii_genspeednote']); + $output .= html_writer::tag('div', get_string('reportgenspeed_resubmission', + 'plagiarism_turnitin', $genparams), ['class' => 'tii_genspeednote']); } } @@ -504,7 +512,8 @@ public function print_disclosure($cmid) { $user = new turnitin_user($USER->id, "Learner"); $user->join_user_to_class($coursedata->turnitin_cid); - $eulaaccepted = ($user->useragreementaccepted == 0) ? $user->get_accepted_user_agreement() : $user->useragreementaccepted; + $eulaaccepted = ($user->useragreementaccepted == 0) ? + $user->get_accepted_user_agreement() : $user->useragreementaccepted; if ($eulaaccepted != 1) { $eulalink = html_writer::tag('span', @@ -581,7 +590,7 @@ public function load_page_components() { $PAGE->requires->js_call_amd('plagiarism_turnitin/open_viewer', 'origreport_open'); $PAGE->requires->js_call_amd('plagiarism_turnitin/open_viewer', 'grademark_open'); // Moodle 4.3 uses a new Modal dialog that is not compatible with older versions of Moodle. Depending on the user's - // version of Moodle, we will use the supported versin of Modal dialog + // Version of Moodle, we will use the supported versin of Modal dialog. if ($CFG->version >= 2023100900) { $PAGE->requires->js_call_amd('plagiarism_turnitin/new_eula_modal', 'newEulaLaunch'); $PAGE->requires->js_call_amd('plagiarism_turnitin/new_peermark', 'newPeermarkLaunch'); @@ -634,7 +643,6 @@ public function get_course_data($cmid, $courseid, $workflowcontext = 'site') { /** * - * @global type $CFG * @param type $linkarray * @return type */ @@ -660,7 +668,7 @@ public function get_links($linkarray) { return $output; } - // If this is a quiz, retrieve the cmid + // If this is a quiz, retrieve the cmid. if ($component == "qtype_essay" && !empty($linkarray['area']) && empty($linkarray['cmid'])) { $questions = question_engine::load_questions_usage_by_activity($linkarray['area']); @@ -679,7 +687,7 @@ public function get_links($linkarray) { if ($cm->modname == 'forum') { if (! $forum = $DB->get_record("forum", ["id" => $cm->instance])) { - print_error('invalidforumid', 'forum'); + throw new moodle_exception('invalidforumid', 'forum'); } } } @@ -781,7 +789,8 @@ public function get_links($linkarray) { $plagiarismfile = null; $moodlesubmission = $DB->get_record('assign_submission', ['id' => $itemid], 'id, groupid'); if ((!empty($moodlesubmission->groupid)) && ($cm->modname == "assign")) { - $plagiarismfiles = $DB->get_records('plagiarism_turnitin_files', ['itemid' => $itemid, 'cm' => $cm->id, 'identifier' => $identifier], + $plagiarismfiles = $DB->get_records('plagiarism_turnitin_files', ['itemid' => $itemid, 'cm' => $cm->id, + 'identifier' => $identifier], 'lastmodified DESC', '*', 0, 1); $plagiarismfile = reset($plagiarismfiles); $author = $plagiarismfile->userid; @@ -817,16 +826,18 @@ public function get_links($linkarray) { // Variable $success is false if there is no Turnitin connection and null if user has previously been enrolled. if ((is_null($success) || $success === true) && $eulashown == false) { - $eulaaccepted = ($user->useragreementaccepted == 0) ? $user->get_accepted_user_agreement() : $user->useragreementaccepted; + $eulaaccepted = ($user->useragreementaccepted == 0) ? + $user->get_accepted_user_agreement() : $user->useragreementaccepted; $userid = $linkarray["userid"]; + // phpcs:disable Squiz.PHP.CommentedOutCode.Found,moodle.Commenting.InlineComment,moodle.Files.LineLength.TooLong // Uncomment if ability to submit to Turnitin previously uploaded files will be implemented. // if ($eulaaccepted != 1) { - // $eulalink = html_writer::tag('span', - // get_string('turnitinppulapost', 'plagiarism_turnitin'), - // array('class' => 'pp_turnitin_eula_link tii_tooltip', 'id' => 'rubric_manager_form') - // ); - // $eula = html_writer::tag('div', $eulalink, array('class' => 'pp_turnitin_eula', 'data-userid' => $user->id)); + // $eulalink = html_writer::tag('span', + // get_string('turnitinppulapost', 'plagiarism_turnitin'), + // array('class' => 'pp_turnitin_eula_link tii_tooltip', 'id' => 'rubric_manager_form') + // ); + // $eula = html_writer::tag('div', $eulalink, array('class' => 'pp_turnitin_eula', 'data-userid' => $user->id)); // } // Show EULA launcher and form placeholder. @@ -936,7 +947,8 @@ public function get_links($linkarray) { // Display links to OR, GradeMark and show relevant errors. if ($plagiarismfile) { - if ($plagiarismfile->statuscode == 'success' || ($plagiarismfile->statuscode == 'error' && $plagiarismfile->errorcode == 13)) { + if ($plagiarismfile->statuscode == 'success' || ($plagiarismfile->statuscode == 'error' && + $plagiarismfile->errorcode == 13)) { if ($istutor || $linkarray["userid"] == $USER->id) { $output .= html_writer::tag('div', $OUTPUT->pix_icon('turnitin-icon', @@ -947,13 +959,16 @@ public function get_links($linkarray) { } // Show Originality Report score and link. - if (($istutor || (in_array($USER->id, $submissionusers) && $plagiarismsettings["plagiarism_show_student_report"])) && - ((is_null($plagiarismfile->orcapable) || $plagiarismfile->orcapable == 1) && !is_null($plagiarismfile->similarityscore))) { + if (($istutor || (in_array($USER->id, $submissionusers) && + $plagiarismsettings["plagiarism_show_student_report"])) && + ((is_null($plagiarismfile->orcapable) || $plagiarismfile->orcapable == 1) && + !is_null($plagiarismfile->similarityscore))) { // Show score. if ($plagiarismfile->statuscode == "pending") { - $orscorehtml = html_writer::tag('div', ' ', ['title' => get_string('pending', 'plagiarism_turnitin'), - 'class' => 'tii_tooltip origreport_score score_colour score_colour_', ]); + $orscorehtml = html_writer::tag('div', ' ', + ['title' => get_string('pending', 'plagiarism_turnitin'), + 'class' => 'tii_tooltip origreport_score score_colour score_colour_', ]); } else { // Put EN flag if translated matching is on and that is the score used. $transmatch = ($plagiarismfile->transmatch == 1) ? ' EN' : ''; @@ -973,28 +988,34 @@ public function get_links($linkarray) { } $orscorehtml = html_writer::tag('div', $score.$transmatch, - ['title' => $titlescore, 'class' => 'tii_tooltip origreport_score score_colour '.$class]); + ['title' => $titlescore, 'class' => 'tii_tooltip origreport_score score_colour '. + $class]); } // Put in div placeholder for DV launch form. - $orscorehtml .= html_writer::tag('div', '', ['class' => 'launch_form origreport_form_'.$plagiarismfile->externalid]); + $orscorehtml .= html_writer::tag('div', '', ['class' => 'launch_form origreport_form_'. + $plagiarismfile->externalid]); // Add url for launching DV from Forum post. if ($cm->modname == 'forum') { - $orscorehtml .= html_writer::tag('div', $CFG->wwwroot.'/plagiarism/turnitin/extras.php?cmid='.$linkarray["cmid"], - ['class' => 'origreport_forum_launch origreport_forum_launch_'.$plagiarismfile->externalid]); + $orscorehtml .= html_writer::tag('div', + $CFG->wwwroot.'/plagiarism/turnitin/extras.php?cmid='.$linkarray["cmid"], + ['class' => 'origreport_forum_launch origreport_forum_launch_'. + $plagiarismfile->externalid]); } // This class is applied so that only the user who submitted or a tutor can open the DV. $useropenclass = ($USER->id == $linkarray["userid"] || $istutor) ? 'pp_origreport_open' : ''; // Output container for OR Score. - $ordivclass = 'row_score pp_origreport '.$useropenclass.' origreport_'.$plagiarismfile->externalid.'_'.$linkarray["cmid"]; - $output .= html_writer::tag('div', $orscorehtml, ['class' => $ordivclass, 'tabindex' => '0', 'role' => 'link']); + $ordivclass = 'row_score pp_origreport '.$useropenclass.' origreport_'.$plagiarismfile->externalid.'_'. + $linkarray["cmid"]; + $output .= html_writer::tag('div', $orscorehtml, ['class' => $ordivclass, 'tabindex' => '0', + 'role' => 'link']); } if (($plagiarismfile->orcapable == 0 && !is_null($plagiarismfile->orcapable))) { $notorlink = html_writer::tag('div', 'x', ['title' => get_string('notorcapable', 'plagiarism_turnitin'), - 'class' => 'tii_tooltip score_colour score_colour_ score_no_orcapable', ]); + 'class' => 'tii_tooltip score_colour score_colour_ score_no_orcapable', ]); // This class is applied so that only the user who submitted or a tutor can open the DV. $useropenclass = ($USER->id == $linkarray["userid"] || $istutor) ? 'pp_origreport_open' : ''; $output .= html_writer::tag('div', $notorlink, ['class' => 'row_score pp_origreport '.$useropenclass]); @@ -1015,18 +1036,23 @@ public function get_links($linkarray) { $released = ((!$blindon) && ($gradesreleased && (!empty($plagiarismfile->gm_feedback) || $gradeexists))); // Show link to open grademark. - if ($config->plagiarism_turnitin_usegrademark && ($istutor || ($linkarray["userid"] == $USER->id && $released))) { + if ($config->plagiarism_turnitin_usegrademark && + ($istutor || ($linkarray["userid"] == $USER->id && $released)) + && !empty($gradeitem)) { // Output grademark icon. $gmicon = html_writer::tag('div', $OUTPUT->pix_icon('icon-edit', - get_string('grademark', 'plagiarism_turnitin'), 'plagiarism_turnitin'), + get_string('grademark', 'plagiarism_turnitin'), + 'plagiarism_turnitin'), ['title' => get_string('grademark', 'plagiarism_turnitin'), - 'class' => 'pp_grademark_open tii_tooltip grademark_'.$plagiarismfile->externalid. + 'class' => 'pp_grademark_open tii_tooltip grademark_'. + $plagiarismfile->externalid. '_'.$linkarray["cmid"], 'tabindex' => '0', 'role' => 'link', ]); // Put in div placeholder for DV launch form. - $gmicon .= html_writer::tag('div', '', ['class' => 'launch_form grademark_form_'.$plagiarismfile->externalid]); + $gmicon .= html_writer::tag('div', '', ['class' => 'launch_form grademark_form_'. + $plagiarismfile->externalid]); $output .= html_writer::tag('div', $gmicon, ['class' => 'grade_icon']); } @@ -1037,7 +1063,8 @@ public function get_links($linkarray) { $studentread = (!empty($plagiarismfile->student_read)) ? $plagiarismfile->student_read : 0; if ($studentread > 0) { $readicon = $OUTPUT->pix_icon('icon-student-read', - get_string('student_read', 'plagiarism_turnitin').' '.userdate($studentread), + get_string('student_read', 'plagiarism_turnitin'). + ' '.userdate($studentread), 'plagiarism_turnitin'); } else { $readicon = $OUTPUT->pix_icon('icon-dot', get_string('student_notread', 'plagiarism_turnitin'), @@ -1048,7 +1075,8 @@ public function get_links($linkarray) { } // Show link to view rubric for student. - if (!$istutor && $config->plagiarism_turnitin_usegrademark && !empty($plagiarismsettings["plagiarism_rubric"])) { + if (!$istutor && $config->plagiarism_turnitin_usegrademark && + !empty($plagiarismsettings["plagiarism_rubric"])) { // Update assignment in case rubric is not stored in Turnitin yet. $this->sync_tii_assignment($cm, $coursedata->turnitin_cid); @@ -1071,7 +1099,8 @@ public function get_links($linkarray) { if ($_SESSION["updated_pm"][$cm->id] <= (time() - (60 * 2))) { $this->refresh_peermark_assignments($cm, $plagiarismsettings['turnitin_assignid']); $turnitinassignment = new turnitin_assignment($cm->instance); - $_SESSION["peermark_assignments"][$cm->id] = $turnitinassignment->get_peermark_assignments($plagiarismsettings['turnitin_assignid']); + $_SESSION["peermark_assignments"][$cm->id] = + $turnitinassignment->get_peermark_assignments($plagiarismsettings['turnitin_assignid']); $_SESSION["updated_pm"][$cm->id] = time(); } @@ -1113,7 +1142,8 @@ public function get_links($linkarray) { // Show error message if there is one. if ($errorcode == 0) { $langstring = ($istutor) ? 'ppsubmissionerrorseelogs' : 'ppsubmissionerrorstudent'; - $errorstring = empty($plagiarismfile->errormsg) ? get_string($langstring, 'plagiarism_turnitin') : $plagiarismfile->errormsg; + $errorstring = empty($plagiarismfile->errormsg) ? + get_string($langstring, 'plagiarism_turnitin') : $plagiarismfile->errormsg; } else { $errorstring = get_string( 'errorcode'.$plagiarismfile->errorcode, @@ -1135,7 +1165,8 @@ public function get_links($linkarray) { } else if ($errorcode == 3) { $output .= html_writer::tag('div', $erroricon, ['class' => 'clear']); } else { - $output .= html_writer::tag('div', $erroricon.' '.get_string('resubmittoturnitin', 'plagiarism_turnitin'), + $output .= html_writer::tag('div', $erroricon.' '. + get_string('resubmittoturnitin', 'plagiarism_turnitin'), ['class' => 'clear plagiarism_turnitin_resubmit_link', 'id' => 'pp_resubmit_'.$plagiarismfile->id, ]); @@ -1145,9 +1176,11 @@ public function get_links($linkarray) { ['class' => 'pp_resubmitting hidden']); // Pending status for after resubmission. - $statusstr = get_string('turnitinstatus', 'plagiarism_turnitin').': '.get_string('pending', 'plagiarism_turnitin'); - $output .= html_writer::tag('div', $OUTPUT->pix_icon('turnitin-icon', $statusstr, 'plagiarism_turnitin', ['class' => 'icon_size']).$statusstr, - ['class' => 'turnitin_status hidden']); + $statusstr = get_string('turnitinstatus', 'plagiarism_turnitin').': '. + get_string('pending', 'plagiarism_turnitin'); + $output .= html_writer::tag('div', $OUTPUT->pix_icon('turnitin-icon', $statusstr, + 'plagiarism_turnitin', ['class' => 'icon_size']).$statusstr, + ['class' => 'turnitin_status hidden']); // Show hidden data for potential forum post resubmissions. if ($submissiontype == 'forum_post' && !empty($linkarray["content"])) { @@ -1170,41 +1203,45 @@ public function get_links($linkarray) { $errorcode = (isset($plagiarismfile->errorcode)) ? $plagiarismfile->errorcode : 0; if ($errorcode == 0) { $langstring = ($istutor) ? 'ppsubmissionerrorseelogs' : 'ppsubmissionerrorstudent'; - $errorstring = empty($plagiarismfile->errormsg) ? get_string($langstring, 'plagiarism_turnitin') : $plagiarismfile->errormsg; + $errorstring = empty($plagiarismfile->errormsg) ? + get_string($langstring, 'plagiarism_turnitin') : $plagiarismfile->errormsg; } else { $errorstring = get_string('errorcode'.$plagiarismfile->errorcode, 'plagiarism_turnitin', display_size(PLAGIARISM_TURNITIN_MAX_FILE_UPLOAD_SIZE)); } - $statusstr = get_string('turnitinstatus', 'plagiarism_turnitin').': '.get_string('deleted', 'plagiarism_turnitin').'
'; + $statusstr = get_string('turnitinstatus', 'plagiarism_turnitin').': '. + get_string('deleted', 'plagiarism_turnitin').'
'; $statusstr .= get_string('because', 'plagiarism_turnitin').'
"'.$errorstring.'"'; - $output .= html_writer::tag('div', $OUTPUT->pix_icon('turnitin-icon', $statusstr, 'plagiarism_turnitin', ['class' => 'icon_size']).$statusstr, - ['class' => 'turnitin_status']); + $output .= html_writer::tag('div', $OUTPUT->pix_icon('turnitin-icon', $statusstr, + 'plagiarism_turnitin', ['class' => 'icon_size']).$statusstr, ['class' => 'turnitin_status']); } else if ($plagiarismfile->statuscode == 'queued') { - $statusstr = get_string('turnitinstatus', 'plagiarism_turnitin').': '.get_string('queued', 'plagiarism_turnitin'); - $output .= html_writer::tag('div', $OUTPUT->pix_icon('turnitin-icon', $statusstr, 'plagiarism_turnitin', ['class' => 'icon_size']).$statusstr, - ['class' => 'turnitin_status']); + $statusstr = get_string('turnitinstatus', 'plagiarism_turnitin').': '. + get_string('queued', 'plagiarism_turnitin'); + $output .= html_writer::tag('div', $OUTPUT->pix_icon('turnitin-icon', $statusstr, + 'plagiarism_turnitin', ['class' => 'icon_size']).$statusstr, ['class' => 'turnitin_status']); } else { - $statusstr = get_string('turnitinstatus', 'plagiarism_turnitin').': '.get_string('pending', 'plagiarism_turnitin'); - $output .= html_writer::tag('div', $OUTPUT->pix_icon('turnitin-icon', $statusstr, 'plagiarism_turnitin', ['class' => 'icon_size']).$statusstr, - ['class' => 'turnitin_status']); + $statusstr = get_string('turnitinstatus', 'plagiarism_turnitin').': '. + get_string('pending', 'plagiarism_turnitin'); + $output .= html_writer::tag('div', $OUTPUT->pix_icon('turnitin-icon', $statusstr, + 'plagiarism_turnitin', ['class' => 'icon_size']).$statusstr, ['class' => 'turnitin_status']); } } else { // Add Error if the user has not accepted EULA for submissions made before instant submission was removed. $eulaerror = ""; if ($linkarray["userid"] != $USER->id && $submittinguser == $author && $istutor) { - // There is a moodle plagiarism bug where get_links is called twice, the first loop is incorrect and is killing - // this functionality. Have to check that user exists here first else there will be a fatal error. + // There is a moodle plagiarism bug where get_links is called twice, the first loop is incorrect and is + // killing this functionality. Have to check that user exists here first else there will be a fatal error. if ($DB->get_record('user', ['id' => $linkarray["userid"]])) { // We need to check for security that the user is actually on the course. if ($moduleobject->user_enrolled_on_course($context, $linkarray["userid"])) { $user = new turnitin_user($linkarray["userid"], "Learner"); if ($user->useragreementaccepted != 1) { - $erroricon = html_writer::tag('div', $OUTPUT->pix_icon('doc-x-grey', get_string('errorcode3', 'plagiarism_turnitin'), - 'plagiarism_turnitin'), - ['title' => get_string('errorcode3', 'plagiarism_turnitin'), - 'class' => 'tii_tooltip tii_error_icon', ]); + $erroricon = html_writer::tag('div', $OUTPUT->pix_icon('doc-x-grey', + get_string('errorcode3', 'plagiarism_turnitin'), 'plagiarism_turnitin'), + ['title' => get_string('errorcode3', 'plagiarism_turnitin'), + 'class' => 'tii_tooltip tii_error_icon', ]); $eulaerror = html_writer::tag('div', $erroricon, ['class' => 'clear']); } } @@ -1233,7 +1270,12 @@ public function get_links($linkarray) { return $output; } - // Query Turnitin for the papers that need updated locally. + /** + * Query Turnitin for the papers that need updated locally. + * + * @param $cm + * @return false + */ public function fetch_updated_paper_ids_from_turnitin($cm) { $plagiarismvalues = $this->get_settings($cm->id); @@ -1261,6 +1303,12 @@ public function fetch_updated_paper_ids_from_turnitin($cm) { } } + /** + * Update grades from Turnitin. + * + * @param $cm + * @return bool|int + */ public function update_grades_from_tii($cm) { global $DB; @@ -1300,6 +1348,13 @@ public function update_grades_from_tii($cm) { return $return; } + /** + * Update grade from Turnitin. + * + * @param $cm + * @param $submissionid + * @return bool + */ public function update_grade_from_tii($cm, $submissionid) { global $DB; $return = true; @@ -1329,6 +1384,16 @@ public function update_grade_from_tii($cm, $submissionid) { return $return; } + /** + * Update submission data. + * + * @param $cm + * @param $submissionid + * @param $tiisubmission + * @return bool|int + * @throws dml_exception + * @throws dml_transaction_exception + */ private function update_submission($cm, $submissionid, $tiisubmission) { global $DB; @@ -1342,7 +1407,8 @@ private function update_submission($cm, $submissionid, $tiisubmission) { // Build Plagiarism file object. $plagiarismfile = new stdClass(); $plagiarismfile->id = $submissiondata->id; - $plagiarismfile->similarityscore = (is_numeric($tiisubmission->getOverallSimilarity())) ? $tiisubmission->getOverallSimilarity() : null; + $plagiarismfile->similarityscore = (is_numeric($tiisubmission->getOverallSimilarity())) ? + $tiisubmission->getOverallSimilarity() : null; $plagiarismfile->transmatch = 0; if ((int)$tiisubmission->getTranslatedOverallSimilarity() > $tiisubmission->getOverallSimilarity()) { $plagiarismfile->similarityscore = $tiisubmission->getTranslatedOverallSimilarity(); @@ -1362,7 +1428,8 @@ private function update_submission($cm, $submissionid, $tiisubmission) { $plagiarismfile->errormsg = null; // Update feedback timestamp. - $plagiarismfile->student_read = ($tiisubmission->getAuthorLastViewedFeedback() > 0) ? strtotime($tiisubmission->getAuthorLastViewedFeedback()) : 0; + $plagiarismfile->student_read = ($tiisubmission->getAuthorLastViewedFeedback() > 0) ? + strtotime($tiisubmission->getAuthorLastViewedFeedback()) : 0; // Identify if an update is required for the similarity score and grade. if ($submissiondata->similarityscore != $plagiarismfile->similarityscore || @@ -1390,7 +1457,8 @@ private function update_submission($cm, $submissionid, $tiisubmission) { } else { $assignmentdata['userid'] = $submissiondata->userid; } - $submission = $DB->get_records('assign_submission', $assignmentdata, 'id DESC', 'id, attemptnumber', '0', '1'); + $submission = $DB->get_records('assign_submission', $assignmentdata, 'id DESC', + 'id, attemptnumber', '0', '1'); $item = current($submission); if ($item->id != $itemid) { @@ -1466,7 +1534,8 @@ private function update_grade($cm, $submission, $userid, $cron = FALSE) { $moduleobject = new $moduleclass; // Get file from pathname hash. - $submissiondata = $DB->get_record('plagiarism_turnitin_files', ['externalid' => $submission->getSubmissionId()], 'identifier'); + $submissiondata = $DB->get_record('plagiarism_turnitin_files', ['externalid' => $submission->getSubmissionId()], + 'identifier'); // Get file as we need item id for discounting files that are no longer in submission. $fs = get_file_storage(); @@ -1475,8 +1544,8 @@ private function update_grade($cm, $submission, $userid, $cron = FALSE) { [$moduleobject->filecomponent, $file->get_itemid()], 'id DESC', 'pathnamehash'); list($insql, $inparams) = $DB->get_in_or_equal(array_keys($moodlefiles), SQL_PARAMS_QM, 'param', true); - $tiisubmissions = $DB->get_records_select('plagiarism_turnitin_files', " userid = ? AND cm = ? AND identifier ".$insql, - array_merge([$userid, $cm->id], $inparams)); + $tiisubmissions = $DB->get_records_select('plagiarism_turnitin_files', " userid = ? AND cm = ? + AND identifier ".$insql, array_merge([$userid, $cm->id], $inparams)); } else { $tiisubmissions = $DB->get_records('plagiarism_turnitin_files', ['userid' => $userid, 'cm' => $cm->id]); $tiisubmissions = current($tiisubmissions); @@ -1491,7 +1560,8 @@ private function update_grade($cm, $submission, $userid, $cron = FALSE) { $gradescounted += 1; } } - $grade->grade = (!is_null($averagegrade) && $gradescounted > 0) ? (int)round(($averagegrade / $gradescounted)) : null; + $grade->grade = (!is_null($averagegrade) && $gradescounted > 0) ? + (int)round(($averagegrade / $gradescounted)) : null; } else { $grade->grade = $submission->getGrade(); } @@ -1521,7 +1591,8 @@ private function update_grade($cm, $submission, $userid, $cron = FALSE) { // Query grades based on attempt number. $gradesquery = ['userid' => $userid, 'assignment' => $cm->instance]; - $usersubmissions = $DB->get_records('assign_submission', $gradesquery, 'attemptnumber DESC', 'attemptnumber', 0, 1); + $usersubmissions = $DB->get_records('assign_submission', $gradesquery, 'attemptnumber DESC', + 'attemptnumber', 0, 1); $usersubmission = current($usersubmissions); $attemptnumber = ($usersubmission) ? $usersubmission->attemptnumber : 0; $gradesquery['attemptnumber'] = $attemptnumber; @@ -1633,14 +1704,15 @@ public function check_group_submission($cm, $userid) { return false; } - /* + /** * Related user ID will be NULL if an instructor submits on behalf of a student who is in a group. * To get around this, we get the group ID, get the group members and set the author as the first student in the group. - - * @param int $cmid - The course ID. - * @param int $groupid - The ID of the Moodle group that we're getting from. - * @return int $author The Moodle user ID that we'll be using for the author. - */ + * + * @param $cmid + * @param $groupid + * @return void + * @throws coding_exception + */ private function get_first_group_author($cmid, $groupid) { static $context; if (empty($context)) { @@ -1768,7 +1840,8 @@ public function sync_tii_assignment($cm, $coursetiiid, $workflowcontext = "site" $assignment->setTitle($title); // Configure repository setting. - $reposetting = (isset($modulepluginsettings["plagiarism_submitpapersto"])) ? $modulepluginsettings["plagiarism_submitpapersto"] : 1; + $reposetting = (isset($modulepluginsettings["plagiarism_submitpapersto"])) ? + $modulepluginsettings["plagiarism_submitpapersto"] : 1; // Override if necessary when admin is forcing standard/no repository. $reposetting = plagiarism_turnitin_override_repository($reposetting); @@ -1779,7 +1852,8 @@ public function sync_tii_assignment($cm, $coursetiiid, $workflowcontext = "site" $assignment->setPublicationsCheck($modulepluginsettings["plagiarism_compare_journals"]); if ($config->plagiarism_turnitin_repositoryoption == PLAGIARISM_TURNITIN_ADMIN_REPOSITORY_OPTION_EXPANDED || $config->plagiarism_turnitin_repositoryoption == PLAGIARISM_TURNITIN_ADMIN_REPOSITORY_OPTION_FORCE_INSTITUTIONAL) { - $institutioncheck = (isset($modulepluginsettings["plagiarism_compare_institution"])) ? $modulepluginsettings["plagiarism_compare_institution"] : 0; + $institutioncheck = (isset($modulepluginsettings["plagiarism_compare_institution"])) ? + $modulepluginsettings["plagiarism_compare_institution"] : 0; $assignment->setInstitutionCheck($institutioncheck); } @@ -1811,7 +1885,8 @@ public function sync_tii_assignment($cm, $coursetiiid, $workflowcontext = "site" // Otherwise, the Turnitin setting is incompatible with Moodle due to multiple files and resubmission rules. $assignment->setLateSubmissionsAllowed(1); $assignment->setMaxGrade(0); - $assignment->setRubricId((!empty($modulepluginsettings["plagiarism_rubric"])) ? $modulepluginsettings["plagiarism_rubric"] : ''); + $assignment->setRubricId((!empty($modulepluginsettings["plagiarism_rubric"])) ? + $modulepluginsettings["plagiarism_rubric"] : ''); if (!empty($moduledata->grade)) { $assignment->setMaxGrade(($moduledata->grade < 0) ? 100 : (int)$moduledata->grade); @@ -1901,11 +1976,30 @@ public function sync_tii_assignment($cm, $coursetiiid, $workflowcontext = "site" // If the duedate is in the future then set any submission duedate_report_refresh flags that // are 2 to 1 to make sure they are re-examined in the next cron run. if ($dtdue > time()) { - $DB->set_field('plagiarism_turnitin_files', 'duedate_report_refresh', 1, ['cm' => $cm->id, 'duedate_report_refresh' => 2]); + $DB->set_field('plagiarism_turnitin_files', 'duedate_report_refresh', 1, + ['cm' => $cm->id, 'duedate_report_refresh' => 2]); } $assignment->setFeedbackReleaseDate(gmdate("Y-m-d\TH:i:s\Z", $dtpost)); + // Erater settings. + $assignment->setErater((isset($modulepluginsettings["plagiarism_erater"])) ? + $modulepluginsettings["plagiarism_erater"] : 0); + $assignment->setEraterSpelling((isset($modulepluginsettings["plagiarism_erater_spelling"])) ? + $modulepluginsettings["plagiarism_erater_spelling"] : 0); + $assignment->setEraterGrammar((isset($modulepluginsettings["plagiarism_erater_grammar"])) ? + $modulepluginsettings["plagiarism_erater_grammar"] : 0); + $assignment->setEraterUsage((isset($modulepluginsettings["plagiarism_erater_usage"])) ? + $modulepluginsettings["plagiarism_erater_usage"] : 0); + $assignment->setEraterMechanics((isset($modulepluginsettings["plagiarism_erater_mechanics"])) ? + $modulepluginsettings["plagiarism_erater_mechanics"] : 0); + $assignment->setEraterStyle((isset($modulepluginsettings["plagiarism_erater_style"])) ? + $modulepluginsettings["plagiarism_erater_style"] : 0); + $assignment->setEraterSpellingDictionary((isset($modulepluginsettings["plagiarism_erater_dictionary"])) ? + $modulepluginsettings["plagiarism_erater_dictionary"] : 'en_US'); + $assignment->setEraterHandbook((isset($modulepluginsettings["plagiarism_erater_handbook"])) ? + $modulepluginsettings["plagiarism_erater_handbook"] : 0); + // If we have a turnitin id then edit the assignment otherwise create it. if ($tiiassignment = $DB->get_record('plagiarism_turnitin_config', ['cm' => $cm->id, 'name' => 'turnitin_assignid'], 'value')) { @@ -1976,11 +2070,10 @@ public function update_rubric_from_tii($cm) { $rubricfield->config_hash = $rubricfield->cm."_".$rubricfield->name; $DB->create_record('plagiarism_turnitin_config', $rubricfield); } - } - catch (Exception $e) { + } catch (Exception $e) { $turnitincomms->handle_exceptions($e, 'tiiassignmentgeterror', false); } - } + } } /** @@ -2129,7 +2222,8 @@ public function cron_update_scores() { try { $this->invalidate_missing_submission($missingsubmission); } catch (Exception $e) { - mtrace("An exception was thrown while attempting to update plagiarism turnitin file submission: $missingsubmission " + mtrace("An exception was thrown while attempting to update plagiarism turnitin file submission: + $missingsubmission " . $e->getMessage() . '(' . $e->getFile() . ':' . $e->getLine() . ')'); } } @@ -2160,18 +2254,21 @@ public function cron_update_scores() { try { $tiisubmissionid = (int)$readsubmission->getSubmissionId(); - $currentsubmission = $DB->get_record('plagiarism_turnitin_files', ['externalid' => $tiisubmissionid], 'id, cm, externalid, userid'); + $currentsubmission = $DB->get_record('plagiarism_turnitin_files', ['externalid' => $tiisubmissionid], + 'id, cm, externalid, userid'); if ($cm = get_coursemodule_from_id('', $currentsubmission->cm)) { $plagiarismfile = new stdClass(); $plagiarismfile->id = $currentsubmission->id; $plagiarismfile->externalid = $tiisubmissionid; - $plagiarismfile->similarityscore = (is_numeric($readsubmission->getOverallSimilarity())) ? $readsubmission->getOverallSimilarity() : null; - $plagiarismfile->grade = (is_numeric($readsubmission->getGrade())) ? $readsubmission->getGrade() : null; + $plagiarismfile->similarityscore = (is_numeric($readsubmission->getOverallSimilarity())) ? + $readsubmission->getOverallSimilarity() : null; + $plagiarismfile->grade = (is_numeric($readsubmission->getGrade())) ? $readsubmission->getGrade() + : null; $plagiarismfile->orcapable = ($readsubmission->getOriginalityReportCapable() == 1) ? 1 : 0; $plagiarismfile->transmatch = 0; if (is_int($readsubmission->getTranslatedOverallSimilarity()) && - $readsubmission->getTranslatedOverallSimilarity() > $readsubmission->getOverallSimilarity()) { + $readsubmission->getTranslatedOverallSimilarity() > $readsubmission->getOverallSimilarity()) { $plagiarismfile->similarityscore = $readsubmission->getTranslatedOverallSimilarity(); $plagiarismfile->transmatch = 1; } @@ -2182,7 +2279,8 @@ public function cron_update_scores() { mtrace("File updated: ".$plagiarismfile->id); } - // at the moment TII doesn't support double marking so we won't synchronise grades from Grade Mark as it would destroy the workflow + // At the moment TII doesn't support double marking so we won't synchronise grades from Grade Mark + // as it would destroy the workflow. if (!is_null($plagiarismfile->grade) && $cm->modname != "coursework") { $this->update_grade($cm, $readsubmission, $currentsubmission->userid, TRUE); } @@ -2200,7 +2298,8 @@ public function cron_update_scores() { } } - // Sets the duedate_report_refresh flag for each processed submission to 2 to prevent them being processed again in the next cron run. + // Sets the duedate_report_refresh flag for each processed submission to 2 to prevent them being processed again in the + // next cron run. foreach ($submissions as $tiisubmission) { $this->set_duedate_report_refresh($tiisubmission->id, 2); } @@ -2208,6 +2307,13 @@ public function cron_update_scores() { return true; } + /** + * Check the local submission state against Turnitin. + * + * @param $assignmentids + * @param $submissionids + * @return array + */ private function check_local_submission_state($assignmentids, $submissionids) { // Initialise Comms Object. $turnitincomms = new turnitin_comms(); @@ -2233,6 +2339,13 @@ private function check_local_submission_state($assignmentids, $submissionids) { ]; } + /** + * Invalidate a missing submission. + * + * @param $missingsubmission + * @return void + * @throws dml_exception + */ private function invalidate_missing_submission($missingsubmission) { global $DB; $currentsubmission = $DB->get_record('plagiarism_turnitin_files', @@ -2346,13 +2459,14 @@ public function migrate_previous_course($coursedata, $turnitincid, $workflowcont * @param int $itemid * @return bool */ - public function queue_submission_to_turnitin($cm, $author, $submitter, $identifier, $submissiontype, $itemid = 0, $eventtype = null) { + public function queue_submission_to_turnitin($cm, $author, $submitter, $identifier, $submissiontype, $itemid = 0, + $eventtype = null) { global $CFG, $DB, $turnitinacceptedfiles; $errorcode = 0; $attempt = 0; $tiisubmissionid = null; - // If the EULA hasn't been accepted, don't save submission and don't submit to Tii + // If the EULA hasn't been accepted, don't save submission and don't submit to Tii. $coursedata = $this->get_course_data($cm->id, $cm->course); $user = new turnitin_user($author, "Learner"); $user->join_user_to_class($coursedata->turnitin_cid); @@ -2489,7 +2603,8 @@ public function queue_submission_to_turnitin($cm, $author, $submitter, $identifi $submissionid = $previoussubmission->id; $attempt = $previoussubmission->attempt; // Delete old text content submissions from Turnitin if resubmissions aren't allowed. - if ($submissiontype == 'text_content' && $settings["plagiarism_report_gen"] == 0 && !is_null($previoussubmission->externalid)) { + if ($submissiontype == 'text_content' && $settings["plagiarism_report_gen"] == 0 && + !is_null($previoussubmission->externalid)) { $this->delete_tii_submission($cm, $previoussubmission->externalid, $author); } @@ -2581,7 +2696,8 @@ public function event_handler($eventdata) { $plagiarismsettings = $this->get_settings($cm->id); $moduletiienabled = $this->get_config_settings('mod_'.$cm->modname); if ($cm->modname == 'assign') { - $plagiarismsettings["plagiarism_draft_submit"] = (isset($plagiarismsettings["plagiarism_draft_submit"])) ? $plagiarismsettings["plagiarism_draft_submit"] : 0; + $plagiarismsettings["plagiarism_draft_submit"] = (isset($plagiarismsettings["plagiarism_draft_submit"])) ? + $plagiarismsettings["plagiarism_draft_submit"] : 0; } // Either module not using Turnitin or Turnitin not being used at all so return true to remove event from queue. @@ -2660,7 +2776,7 @@ public function event_handler($eventdata) { $eventdata['other']['content'] = $qa->get_response_summary(); // Queue text content. - // adding slot to sha hash to create unique assignments for duplicate text based on it's id + // Adding slot to sha hash to create unique assignments for duplicate text based on it's id. $identifier = sha1($eventdata['other']['content'].$slot); $result = $this->queue_submission_to_turnitin( $cm, $author, $submitter, $identifier, 'quiz_answer', @@ -2683,9 +2799,14 @@ public function event_handler($eventdata) { $submissiontype = ($cm->modname == 'forum') ? 'forum_post' : 'text_content'; +<<<<<<< HEAD // The content inside the event data will not always correspond to the content we will look up later, e.g. // because URLs have been converted to use @@PLUGINFILE@@ etc. Therefore to calculate the same hash, we need to // do a lookup to get the file content +======= + // phpcs:disable PSR2.Methods.MethodDeclaration.Underscore,moodle.Commenting.TodoComment + // TODO: Check eventdata to see if content is included correctly. If so, this can be removed. +>>>>>>> f6223b8 (Fixes for remaining errors/warnings.) if ($cm->modname == 'workshop') { $moodlesubmission = $DB->get_record('workshop_submissions', ['id' => $eventdata['objectid']]); $eventdata['other']['content'] = $moodlesubmission->content; @@ -2822,8 +2943,8 @@ public function clean_old_turnitin_submissions($cm, $userid, $itemid, $submissio $params = [$moduleobject->filecomponent, $userid, $itemid]; } - if ($moodlefiles = $DB->get_records_select('files', " component = ? AND userid = ? AND source IS NOT null AND ".$itemidsinsql, - $params, 'id DESC', 'pathnamehash')) { + if ($moodlefiles = $DB->get_records_select('files', " component = ? AND userid = ? AND source IS NOT null AND ". + $itemidsinsql, $params, 'id DESC', 'pathnamehash')) { list($notinsql, $notinparams) = $DB->get_in_or_equal(array_keys($moodlefiles), SQL_PARAMS_QM, 'param', false); $typefield = ($CFG->dbtype == "oci") ? " to_char(submissiontype) " : " submissiontype "; $oldfiles = $DB->get_records_select('plagiarism_turnitin_files', " userid = ? AND cm = ? ". @@ -2903,11 +3024,13 @@ public function save_submission($cm, $userid, $submissionid, $identifier, $statu if ($submissionid != 0) { if (!$DB->update_record('plagiarism_turnitin_files', $plagiarismfile)) { - plagiarism_turnitin_activitylog("Update record failed (CM: ".$cm->id.", User: ".$userid.") - ", "PP_UPDATE_SUB_ERROR"); + plagiarism_turnitin_activitylog("Update record failed (CM: ".$cm->id.", User: ".$userid.") - ", + "PP_UPDATE_SUB_ERROR"); } } else { if (!$DB->insert_record('plagiarism_turnitin_files', $plagiarismfile)) { - plagiarism_turnitin_activitylog("Insert record failed (CM: ".$cm->id.", User: ".$userid.") - ", "PP_INSERT_SUB_ERROR"); + plagiarism_turnitin_activitylog("Insert record failed (CM: ".$cm->id.", User: ".$userid.") - ", + "PP_INSERT_SUB_ERROR"); } } @@ -2942,6 +3065,8 @@ public function delete_tii_submission($cm, $submissionid, $userid) { } /** + * Get the parameters for report gen speed. + * * @return object The parameters for report gen speed. */ public function plagiarism_get_report_gen_speed_params() { @@ -3182,7 +3307,8 @@ function plagiarism_turnitin_send_queued_submissions() { try { $textcontent = $file->get_content(); } catch (Exception $e) { - plagiarism_turnitin_activitylog('File content not found on submission: '.$queueditem->identifier, 'PP_NO_FILE'); + plagiarism_turnitin_activitylog('File content not found on submission: '.$queueditem->identifier, + 'PP_NO_FILE'); mtrace($e); mtrace('File content not found on submission. Identifier: '.$queueditem->identifier); $errorcode = 9; @@ -3485,7 +3611,7 @@ function plagiarism_turnitin_print_error($input, $module = 'plagiarism_turnitin' $message .= ' ('.basename($file).' | '.$line.')'; } - print_error($input, 'plagiarism_turnitin', $link, $message); + throw new moodle_exception($input, 'plagiarism_turnitin', $link, $message); exit(); } @@ -3522,7 +3648,7 @@ function plagiarism_turnitin_activitylog($string, $activity) { $dir = opendir($dirpath); $files = []; while ($entry = readdir($dir)) { - if (substr(basename($entry), 0, 1) != "." AND substr_count(basename($entry), $prefix) > 0) { + if (substr(basename($entry), 0, 1) != "." && substr_count(basename($entry), $prefix) > 0) { $files[] = basename($entry); } } diff --git a/locallib.php b/locallib.php index 8eaaa0d9..a4aaeef7 100644 --- a/locallib.php +++ b/locallib.php @@ -19,14 +19,10 @@ * * @package plagiarism_turnitin * @copyright 2018 Turnitin - * @authior John McGettrick + * @author John McGettrick * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -if (!defined('MOODLE_INTERNAL')) { - die('Direct access to this script is forbidden.'); // It must be included from a Moodle page. -} - /** * Override the repository option if necessary depending on the configuration setting. * @param $submitpapersto int - The repository to submit to. diff --git a/settings.php b/settings.php index 90bf2e30..3a4013df 100644 --- a/settings.php +++ b/settings.php @@ -14,6 +14,14 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . +/** + * Turnitin settings page + * + * @package plagiarism_turnitin + * @copyright 2012 iParadigms LLC + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + require_once(__DIR__.'/../../config.php'); require_once($CFG->libdir.'/adminlib.php'); require_once($CFG->libdir.'/plagiarismlib.php'); @@ -74,12 +82,14 @@ $defaultfield->id = $DB->get_field('plagiarism_turnitin_config', 'id', (['cm' => null, 'name' => $field])); if (!$DB->update_record('plagiarism_turnitin_config', $defaultfield)) { - plagiarism_turnitin_print_error('defaultupdateerror', 'plagiarism_turnitin', null, null, __FILE__, __LINE__); + plagiarism_turnitin_print_error('defaultupdateerror', 'plagiarism_turnitin', null, + null, __FILE__, __LINE__); } } else { $defaultfield->config_hash = $defaultfield->cm."_".$defaultfield->name; if (!$DB->insert_record('plagiarism_turnitin_config', $defaultfield)) { - plagiarism_turnitin_print_error('defaultinserterror', 'plagiarism_turnitin', null, null, __FILE__, __LINE__); + plagiarism_turnitin_print_error('defaultinserterror', 'plagiarism_turnitin', null, + null, __FILE__, __LINE__); } } } diff --git a/tests/behat/behat_plagiarism_turnitin.php b/tests/behat/behat_plagiarism_turnitin.php index 20e8a02d..59d10ecf 100644 --- a/tests/behat/behat_plagiarism_turnitin.php +++ b/tests/behat/behat_plagiarism_turnitin.php @@ -17,6 +17,7 @@ /** * Steps definitions related to plagiarism_turnitin. * + * @package plagiarism_turnitin * @copyright 2018 Turnitin * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ @@ -31,9 +32,14 @@ use Integrations\PhpSdk\TiiMembership; use Integrations\PhpSdk\TurnitinAPI; +/** + * Turnitin behat steps. + */ class behat_plagiarism_turnitin extends behat_base { /** + * I switch to iframe with locator + * * @Given I switch to iframe with locator :locator * @param String $locator * @throws \Behat\Mink\Exception\DriverException @@ -64,6 +70,8 @@ public function i_switch_to_iframe_with_locator($locator) { } /** + * I configure Turnitin URL + * * @Given I configure Turnitin URL * @throws \Behat\Mink\Exception\ElementNotFoundException */ @@ -82,6 +90,8 @@ public function i_configure_turnitin_url() { } /** + * I configure Turnitin credentials + * * @Given I configure Turnitin credentials */ public function i_configure_turnitin_credentials() { @@ -95,6 +105,8 @@ public function i_configure_turnitin_credentials() { } /** + * I create a unique user with username + * * @Given I create a unique user with username :username * @param $username */ @@ -139,7 +151,9 @@ public function i_should_see_textcount_instances_of_text_on_the_page($textcount, /** * Poll 12 times over 2 minutes for an originality report. This should be enough time for the vast majority of cases. * + * phpcs:disable moodle.Files.LineLength.MaxExceeded * @Given /^I obtain an originality report for "(?P(?:[^"]|\\")*)" on "(?P(?:[^"]|\\")*)" "(?P(?:[^"]|\\")*)" on course "(?P(?:[^"]|\\")*)"$/ + * * @param string $student * @param string $modtype * @param string $modname @@ -147,7 +161,8 @@ public function i_should_see_textcount_instances_of_text_on_the_page($textcount, * @throws ElementNotFoundException * @throws Exception */ - public function i_obtain_an_originality_report_for_student_on_modtype_assignmentname_on_course_coursename($student, $modtype, $modname, $coursename) { + public function i_obtain_an_originality_report_for_student_on_modtype_assignmentname_on_course_coursename($student, + $modtype, $modname, $coursename) { $reportfound = false; $count = 1; while (!$reportfound) { @@ -171,11 +186,13 @@ public function i_obtain_an_originality_report_for_student_on_modtype_assignment try { switch($modtype) { case "assignment": - $this->execute('behat_general::row_column_of_table_should_contain', [$student, "File submissions", "generaltable", "%"]); + $this->execute('behat_general::row_column_of_table_should_contain', + [$student, "File submissions", "generaltable", "%"]); break; case "forum": case "workshop": - $this->execute('behat_general::assert_element_contains_text', ["%", "div.origreport_score", "css_element"]); + $this->execute('behat_general::assert_element_contains_text', + ["%", "div.origreport_score", "css_element"]); break; } break; @@ -189,6 +206,8 @@ public function i_obtain_an_originality_report_for_student_on_modtype_assignment } /** + * I accept the Turnitin EULA if necessary + * * @Given I accept the Turnitin EULA if necessary */ public function i_accept_the_turnitin_eula_if_necessary() { @@ -201,10 +220,13 @@ public function i_accept_the_turnitin_eula_if_necessary() { $this->execute('behat_general::i_click_on', [".agree-button", "css_element"]); } catch (Exception $e) { // EULA not found - so skip it. + return; } } /** + * I accept the Turnitin EULA from the EV if necessary + * * @Given I accept the Turnitin EULA from the EV if necessary */ public function i_accept_the_turnitin_eula_from_the_ev_if_necessary() { @@ -214,6 +236,7 @@ public function i_accept_the_turnitin_eula_from_the_ev_if_necessary() { $this->execute('behat_general::i_click_on', [".agree-button", "css_element"]); } catch (Exception $e) { // EULA not found - so skip it. + return; } } @@ -227,7 +250,7 @@ public function i_accept_the_turnitin_eula_from_the_ev_if_necessary() { public function click_save_changes_button($selector, $locator, $exception = false, $node = false, $timeout = false) { try { $items = $this->find_all($selector, $locator, $exception, $node, $timeout); - foreach($items as $element){ + foreach ($items as $element) { if ($element->isVisible()) { echo "Element is visible "; @@ -241,6 +264,8 @@ public function click_save_changes_button($selector, $locator, $exception = fals } /** + * Given I click on the Turnitin assignment :assignmentname + * * @Given /^the following users will be created if they do not already exist:$/ * @param TableNode $data * @throws Exception @@ -249,7 +274,7 @@ public function the_following_users_will_be_created_if_they_do_not_already_exist $newdata = []; $rownum = 0; foreach ($data->getRows() as $row) { - if (!$rownum == 0) { // not header row + if (!$rownum == 0) { // Not header row. $row[3] = str_replace('$account', getenv('TII_ACCOUNT'), $row[3]); } $rownum++; @@ -260,7 +285,11 @@ public function the_following_users_will_be_created_if_they_do_not_already_exist } /** + * I unenroll the user account with the role from the class in Turnitin + * + * phpcs:disable moodle.Files.LineLength.TooLong * @Given /^I unenroll the user account "(?P(?:[^"]|\\")*)" with the role "(?P(?:[^"]|\\")*)" from the class in Turnitin$/ + * * @throws Exception */ public function i_unenroll_the_user_account_with_the_role_from_the_class_in_turnitin($student, $role) { @@ -291,7 +320,8 @@ public function i_unenroll_the_user_account_with_the_role_from_the_class_in_turn $turnitincall->deleteMembership($membership); } } catch (Exception $e) { - // ignore exception. + // Ignore exception. + return; } } @@ -300,7 +330,7 @@ public function i_unenroll_the_user_account_with_the_role_from_the_class_in_turn * * @return object \APITurnitin */ - public function behat_initialise_api( ) { + public function behat_initialise_api() { global $CFG; $api = new TurnitinAPI(getenv('TII_ACCOUNT'), getenv('TII_APIBASEURL'), getenv('TII_SECRET'), 12); diff --git a/tests/classes/turnitin_assignment_class_test.php b/tests/classes/turnitin_assignment_class_test.php index b8271b79..68accc86 100644 --- a/tests/classes/turnitin_assignment_class_test.php +++ b/tests/classes/turnitin_assignment_class_test.php @@ -22,6 +22,8 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ +namespace plagiarism_turnitin; + defined('MOODLE_INTERNAL') || die(); global $CFG; @@ -34,7 +36,7 @@ * * @package turnitin */ -class turnitin_assignment_class_test extends advanced_testcase { +final class turnitin_assignment_class_test extends advanced_testcase { /** * Set Overwrite mtrace to avoid output during the tests. @@ -46,7 +48,14 @@ public function setUp(): void { $CFG->mtrace_wrapper = 'plagiarism_turnitin_mtrace'; } - public function test_get_course_data() { + /** + * Test that we can get a course data. + * + * @covers \turnitin_assignment::get_course_data + * @return void + * @throws \dml_exception + */ + public function test_get_course_data(): void { global $DB; $this->resetAfterTest(); @@ -66,7 +75,14 @@ public function test_get_course_data() { $this->assertEquals($course->turnitin_cid, $response->turnitin_cid); } - public function test_create_tii_course() { + /** + * Test that we can create a tii course. + * + * @covers \turnitin_assignment::create_tii_course + * @return void + * @throws \dml_exception + */ + public function test_create_tii_course(): void { global $DB; $this->resetAfterTest(); @@ -118,7 +134,14 @@ public function test_create_tii_course() { $this->assertNotEquals($expected->id, $response->id); } - public function test_edit_tii_course() { + /** + * Test that we can edit a tii course. + * + * @covers \turnitin_assignment::edit_tii_course + * @return void + * @throws \dml_exception + */ + public function test_edit_tii_course(): void { global $DB; $this->resetAfterTest(); @@ -171,7 +194,13 @@ public function test_edit_tii_course() { $this->assertEquals($expected, $responsecourse); } - public function test_truncate_title() { + /** + * Test that we can truncate a title. + * + * @covers \turnitin_assignment::truncate_title + * @return void + */ + public function test_truncate_title(): void { $this->resetAfterTest(); $title = "This is a very long title that we are going to use to test the truncate title method."; @@ -186,7 +215,13 @@ public function test_truncate_title() { $this->assertEquals('This title should not be truncated. (Moodle PP)', $response); } - public function test_create_tii_assignment() { + /** + * Test that we can get create a tii assignment. + * + * @covers \turnitin_assignment::create_tii_assignment + * @return void + */ + public function test_create_tii_assignment(): void { $this->resetAfterTest(); // Create a PP assignment. @@ -218,7 +253,14 @@ public function test_create_tii_assignment() { $this->assertEquals(1, $response); } - public function test_edit_tii_assignment() { + /** + * Test that we can get edit a tii assignment. + * + * @covers \turnitin_assignment::edit_tii_assignment + * @return void + * @throws \coding_exception + */ + public function test_edit_tii_assignment(): void { $this->resetAfterTest(); // Create a PP assignment. @@ -280,7 +322,14 @@ public function test_edit_tii_assignment() { $this->assertEquals(1, $response["tiiassignmentid"]); } - public function test_get_peermark_assignments() { + /** + * Test that we can get a peermark assignment. + * + * @covers \turnitin_assignment::get_peermark_assignments + * @return void + * @throws \dml_exception + */ + public function test_get_peermark_assignments(): void { global $DB; $this->resetAfterTest(); diff --git a/tests/classes/turnitin_user_class_test.php b/tests/classes/turnitin_user_class_test.php index 495d2a08..e3b9c534 100644 --- a/tests/classes/turnitin_user_class_test.php +++ b/tests/classes/turnitin_user_class_test.php @@ -22,6 +22,8 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ +namespace plagiarism_turnitin; + defined('MOODLE_INTERNAL') || die(); global $CFG; @@ -35,8 +37,11 @@ * * @package turnitin */ -class turnitin_user_class_test extends plagiarism_turnitin_test_lib { +final class turnitin_user_class_test extends plagiarism_turnitin_test_lib { + /** + * @var \PHPUnit\Framework\MockObject\MockObject|(turnitin_comms&\PHPUnit\Framework\MockObject\MockObject) + */ public $faketiicomms; /** @@ -49,7 +54,13 @@ public function setUp(): void { ->getMock(); } - public function test_get_moodle_user() { + /** + * Test that we can get a Moodle use. + * + * @covers \turnitin_user::get_moodle_user + * @return void + */ + public function test_get_moodle_user(): void { $this->resetAfterTest(); $student = $this->getDataGenerator()->create_user(); @@ -62,14 +73,26 @@ public function test_get_moodle_user() { $this->assertEquals('username1', $response->username); } - public function test_get_pseudo_domain() { + /** + * Test that we can get a pseudo domain. + * + * @covers \turnitin_user::get_pseudo_domain + * @return void + */ + public function test_get_pseudo_domain(): void { $this->resetAfterTest(); $response = turnitin_user::get_pseudo_domain(); $this->assertEquals(PLAGIARISM_TURNITIN_DEFAULT_PSEUDO_DOMAIN, $response); } - public function test_get_pseudo_firstname() { + /** + * Test that we can get a pseudo first name. + * + * @covers \turnitin_user::get_pseudo_firstname + * @return void + */ + public function test_get_pseudo_firstname(): void { $this->resetAfterTest(); $turnitinuser = new turnitin_user(0, null, null, null, null); @@ -77,7 +100,14 @@ public function test_get_pseudo_firstname() { $this->assertEquals(PLAGIARISM_TURNITIN_DEFAULT_PSEUDO_FIRSTNAME, $response); } - public function test_get_pseudo_lastname() { + /** + * Test that we can get a pseudo last name. + * + * @covers \turnitin_user::get_pseudo_lastname + * @return void + * @throws dml_exception + */ + public function test_get_pseudo_lastname(): void { global $DB; $this->resetAfterTest(); @@ -92,7 +122,14 @@ public function test_get_pseudo_lastname() { $this->assertEquals(PLAGIARISM_TURNITIN_DEFAULT_PSEUDO_FIRSTNAME, $response); } - public function test_unlink_user() { + /** + * Test that we can get unlink a user from Turnitin. + * + * @covers \turnitin_user::unlink_user + * @return void + * @throws dml_exception + */ + public function test_unlink_user(): void { global $DB; $this->resetAfterTest(); diff --git a/tests/generator/lib.php b/tests/generator/lib.php index 17b43131..e02ff806 100644 --- a/tests/generator/lib.php +++ b/tests/generator/lib.php @@ -19,8 +19,8 @@ global $DB; require_once($CFG->dirroot . '/plagiarism/turnitin/classes/turnitin_user.class.php'); -include_once $CFG->dirroot.'/course/lib.php'; -require_once $CFG->dirroot.'/webservice/tests/helpers.php'; +require_once($CFG->dirroot.'/course/lib.php'); +require_once($CFG->dirroot.'/webservice/tests/helpers.php'); /** * plagiarism_turnitin module data generator class @@ -29,7 +29,7 @@ * - Create a test function and call one of these functions from within it using (for example): * $this->make_test_users(5,"Learner"); * - * @category Test + * @category test * @package plagiarism_turnitin * @copyright 2017 Turnitin * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later @@ -37,11 +37,13 @@ abstract class plagiarism_turnitin_test_lib extends advanced_testcase { /** - * Creates a number of test plagiarism_turnitin users, creates an equivalent moodle user for each, and handles the database association work. + * Creates a number of test plagiarism_turnitin users, creates an equivalent moodle user for each, and handles the database + * association work. * * @param int $number_of_users * @param array $roles - an array of strings, each of which should be 'Learner' or 'Instructor'. - * @return object $return - object of two arrays of equal length, one full of plagiarism_turnitin_user types and the other with ids for dbtable plagiarism_turnitin_users. The indices of these arrays DO align. + * @return object $return - object of two arrays of equal length, one full of plagiarism_turnitin_user types and the other with + * ids for dbtable plagiarism_turnitin_users. The indices of these arrays DO align. */ public function make_test_users($numberofusers, $roles) { $return['plagiarism_turnitin_users'] = []; @@ -63,7 +65,8 @@ public function make_test_users($numberofusers, $roles) { * for the tii user specified * @param object $plagiarism_turnitin_user - plagiarism_turnitin user object * - * @return int $plagiarism_turnitin_user_id id of plagiarism_turnitin user join (for use in get_record queries on plagiarism_turnitin_users table) + * @return int $plagiarism_turnitin_user_id id of plagiarism_turnitin user join (for use in get_record queries on + * plagiarism_turnitin_users table) */ public function join_test_user($plagiarismturnitinuser) { global $DB; diff --git a/tests/lib_test.php b/tests/lib_test.php index ba4f69d0..4bf3b045 100644 --- a/tests/lib_test.php +++ b/tests/lib_test.php @@ -22,6 +22,8 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ +namespace plagiarism_turnitin; + defined('MOODLE_INTERNAL') || die(); global $CFG; @@ -33,9 +35,15 @@ * * @package turnitin */ -class lib_test extends advanced_testcase { +final class lib_test extends advanced_testcase { - public function test_is_plugin_configured() { + /** + * Test that the plugin is configured correctly. + * + * @covers \plagiarism_plugin_turnitin::is_plugin_configured + * @return void + */ + public function test_is_plugin_configured(): void { $this->resetAfterTest(); $plagiarismturnitin = new plagiarism_plugin_turnitin(); @@ -60,7 +68,15 @@ public function test_is_plugin_configured() { $this->assertEquals(true, $ispluginconfigured); } - public function test_check_group_submission() { + /** + * Test that group submissions are correctly checked. + * + * @covers \plagiarism_plugin_turnitin::check_group_submission + * @return void + * @throws \coding_exception + * @throws \moodle_exception + */ + public function test_check_group_submission(): void { global $CFG; require_once($CFG->dirroot . '/mod/assign/tests/base_test.php'); @@ -172,8 +188,10 @@ public function create_assign_with_student_and_teacher($params = []) { /** * Test that the data returned from the report gen speed param function is what we expect. + * + * @covers \plagiarism_plugin_turnitin::plagiarism_get_report_gen_speed_params */ - public function test_plagiarism_get_report_gen_speed_params() { + public function test_plagiarism_get_report_gen_speed_params(): void { $this->resetAfterTest(); $expected = new stdClass(); @@ -188,8 +206,10 @@ public function test_plagiarism_get_report_gen_speed_params() { /** * Test that the set config function saves a config. + * + * @covers \plagiarism_plugin_turnitin::plagiarism_set_config */ - public function test_plagiarism_set_config() { + public function test_plagiarism_set_config(): void { $this->resetAfterTest(); $plagiarismturnitin = new plagiarism_plugin_turnitin(); diff --git a/tests/locallib_test.php b/tests/locallib_test.php index f32aba26..b8a3eb82 100644 --- a/tests/locallib_test.php +++ b/tests/locallib_test.php @@ -23,6 +23,8 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ +namespace plagiarism_turnitin; + defined('MOODLE_INTERNAL') || die(); global $CFG; @@ -33,12 +35,14 @@ * * @package turnitin */ -class locallib_test extends advanced_testcase { +final class locallib_test extends advanced_testcase { /** * Test that we have the correct repository depending on the config settings. + * + * @covers \plagiarism_turnitin_override_repository */ - public function test_plagiarism_turnitin_override_repository() { + public function test_plagiarism_turnitin_override_repository(): void { $this->resetAfterTest(); // Note that $submitpapersto would only ever be 0, 1 or 2 but this is to illustrate @@ -46,27 +50,32 @@ public function test_plagiarism_turnitin_override_repository() { $submitpapersto = 6; // Test that repository is not overridden for value of 0. - set_config('plagiarism_turnitin_repositoryoption', PLAGIARISM_TURNITIN_ADMIN_REPOSITORY_OPTION_STANDARD, 'plagiarism_turnitin'); + set_config('plagiarism_turnitin_repositoryoption', PLAGIARISM_TURNITIN_ADMIN_REPOSITORY_OPTION_STANDARD, + 'plagiarism_turnitin'); $response = plagiarism_turnitin_override_repository($submitpapersto); $this->assertEquals($submitpapersto, $response); // Test that repository is not overridden for value of 1. - set_config('plagiarism_turnitin_repositoryoption', PLAGIARISM_TURNITIN_ADMIN_REPOSITORY_OPTION_EXPANDED, 'plagiarism_turnitin'); + set_config('plagiarism_turnitin_repositoryoption', PLAGIARISM_TURNITIN_ADMIN_REPOSITORY_OPTION_EXPANDED, + 'plagiarism_turnitin'); $response = plagiarism_turnitin_override_repository($submitpapersto); $this->assertEquals($submitpapersto, $response); // Standard Repository is being forced. - set_config('plagiarism_turnitin_repositoryoption', PLAGIARISM_TURNITIN_ADMIN_REPOSITORY_OPTION_FORCE_STANDARD, 'plagiarism_turnitin'); + set_config('plagiarism_turnitin_repositoryoption', PLAGIARISM_TURNITIN_ADMIN_REPOSITORY_OPTION_FORCE_STANDARD, + 'plagiarism_turnitin'); $response = plagiarism_turnitin_override_repository($submitpapersto); $this->assertEquals(PLAGIARISM_TURNITIN_SUBMIT_TO_STANDARD_REPOSITORY, $response); // No Repository is being forced. - set_config('plagiarism_turnitin_repositoryoption', PLAGIARISM_TURNITIN_ADMIN_REPOSITORY_OPTION_FORCE_NO, 'plagiarism_turnitin'); + set_config('plagiarism_turnitin_repositoryoption', PLAGIARISM_TURNITIN_ADMIN_REPOSITORY_OPTION_FORCE_NO, + 'plagiarism_turnitin'); $response = plagiarism_turnitin_override_repository($submitpapersto); $this->assertEquals(PLAGIARISM_TURNITIN_SUBMIT_TO_NO_REPOSITORY, $response); // Institutional Repository is being forced. - set_config('plagiarism_turnitin_repositoryoption', PLAGIARISM_TURNITIN_ADMIN_REPOSITORY_OPTION_FORCE_INSTITUTIONAL, 'plagiarism_turnitin'); + set_config('plagiarism_turnitin_repositoryoption', PLAGIARISM_TURNITIN_ADMIN_REPOSITORY_OPTION_FORCE_INSTITUTIONAL, + 'plagiarism_turnitin'); $response = plagiarism_turnitin_override_repository($submitpapersto); $this->assertEquals(PLAGIARISM_TURNITIN_SUBMIT_TO_INSTITUTIONAL_REPOSITORY, $response); } diff --git a/tests/modules/turnitin_assign_test.php b/tests/modules/turnitin_assign_test.php index a6729ac9..471e95ff 100644 --- a/tests/modules/turnitin_assign_test.php +++ b/tests/modules/turnitin_assign_test.php @@ -22,6 +22,8 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ +namespace plagiarism_turnitin; + defined('MOODLE_INTERNAL') || die(); global $CFG; @@ -33,7 +35,7 @@ * * @package turnitin */ -class turnitin_assign_test extends advanced_testcase { +final class turnitin_assign_test extends advanced_testcase { /** @var stdClass created in setUp. */ protected $course; @@ -59,37 +61,47 @@ public function setUp(): void { /** * Test to check whether resubmissions are allowed. + * + * @covers \turnitin_assign::is_resubmission_allowed */ - public function test_check_is_resubmission_allowed() { + public function test_check_is_resubmission_allowed(): void { $this->resetAfterTest(true); // Create module object. $moduleobject = new turnitin_assign(); - $resubmissionallowed = $moduleobject->is_resubmission_allowed($this->assign->id, 1, 'file', ASSIGN_ATTEMPT_REOPEN_METHOD_NONE); + $resubmissionallowed = $moduleobject->is_resubmission_allowed($this->assign->id, 1, 'file', + ASSIGN_ATTEMPT_REOPEN_METHOD_NONE); $this->assertTrue($resubmissionallowed); - $resubmissionallowed = $moduleobject->is_resubmission_allowed($this->assign->id, 1, 'text_content', ASSIGN_ATTEMPT_REOPEN_METHOD_NONE); + $resubmissionallowed = $moduleobject->is_resubmission_allowed($this->assign->id, 1, 'text_content', + ASSIGN_ATTEMPT_REOPEN_METHOD_NONE); $this->assertTrue($resubmissionallowed); - $resubmissionallowed = $moduleobject->is_resubmission_allowed($this->assign->id, 1, 'text_content', ASSIGN_ATTEMPT_REOPEN_METHOD_MANUAL); + $resubmissionallowed = $moduleobject->is_resubmission_allowed($this->assign->id, 1, 'text_content', + ASSIGN_ATTEMPT_REOPEN_METHOD_MANUAL); $this->assertFalse($resubmissionallowed); - $resubmissionallowed = $moduleobject->is_resubmission_allowed($this->assign->id, 0, 'file', ASSIGN_ATTEMPT_REOPEN_METHOD_NONE); + $resubmissionallowed = $moduleobject->is_resubmission_allowed($this->assign->id, 0, 'file', + ASSIGN_ATTEMPT_REOPEN_METHOD_NONE); $this->assertFalse($resubmissionallowed); - $resubmissionallowed = $moduleobject->is_resubmission_allowed($this->assign->id, 0, 'text_content', ASSIGN_ATTEMPT_REOPEN_METHOD_NONE); + $resubmissionallowed = $moduleobject->is_resubmission_allowed($this->assign->id, 0, 'text_content', + ASSIGN_ATTEMPT_REOPEN_METHOD_NONE); $this->assertFalse($resubmissionallowed); - $resubmissionallowed = $moduleobject->is_resubmission_allowed($this->assign->id, 1, 'file', ASSIGN_ATTEMPT_REOPEN_METHOD_MANUAL); + $resubmissionallowed = $moduleobject->is_resubmission_allowed($this->assign->id, 1, 'file', + ASSIGN_ATTEMPT_REOPEN_METHOD_MANUAL); $this->assertFalse($resubmissionallowed); } /** * Test that resubmissions are not allowed for files if the maximum files in a submission is more than 1. + * + * @covers \turnitin_assign::is_resubmission_allowed */ - public function test_check_is_resubmission_allowed_maxfiles_above_threshold() { + public function test_check_is_resubmission_allowed_maxfiles_above_threshold(): void { $this->resetAfterTest(true); $params = [ @@ -108,7 +120,8 @@ public function test_check_is_resubmission_allowed_maxfiles_above_threshold() { $resubmissionallowed = $moduleobject->is_resubmission_allowed($assign->id, 1, 'file', ASSIGN_ATTEMPT_REOPEN_METHOD_NONE); $this->assertFalse($resubmissionallowed); - $resubmissionallowed = $moduleobject->is_resubmission_allowed($assign->id, 1, 'text_content', ASSIGN_ATTEMPT_REOPEN_METHOD_NONE); + $resubmissionallowed = $moduleobject->is_resubmission_allowed($assign->id, 1, 'text_content', + ASSIGN_ATTEMPT_REOPEN_METHOD_NONE); $this->assertTrue($resubmissionallowed); } } diff --git a/tests/modules/turnitin_forum_test.php b/tests/modules/turnitin_forum_test.php index 67f46b91..f111a8c9 100644 --- a/tests/modules/turnitin_forum_test.php +++ b/tests/modules/turnitin_forum_test.php @@ -22,6 +22,8 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ +namespace plagiarism_turnitin; + defined('MOODLE_INTERNAL') || die(); global $CFG; @@ -32,7 +34,7 @@ * * @package turnitin */ -class turnitin_forum_test extends advanced_testcase { +final class turnitin_forum_test extends advanced_testcase { /** @var stdClass created in setUp. */ protected $forum; @@ -72,8 +74,10 @@ public function setUp(): void { /** * Test to check that content returned by set content is the same as passed in array. + * + * @covers \turnitin_forum::set_content */ - public function test_to_check_content_in_array_is_returned_by_set_content() { + public function test_to_check_content_in_array_is_returned_by_set_content(): void { $this->resetAfterTest(true); @@ -91,8 +95,10 @@ public function test_to_check_content_in_array_is_returned_by_set_content() { /** * Test to check that content returned by set content is taken from database * if post id is passed in. + * + * @covers \turnitin_forum::set_content */ - public function test_to_check_content_from_database_is_returned_by_set_content_if_postid_present() { + public function test_to_check_content_from_database_is_returned_by_set_content_if_postid_present(): void { $this->resetAfterTest(true); diff --git a/tests/modules/turnitin_quiz_test.php b/tests/modules/turnitin_quiz_test.php index f3be2472..f4309d02 100644 --- a/tests/modules/turnitin_quiz_test.php +++ b/tests/modules/turnitin_quiz_test.php @@ -23,6 +23,8 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ +namespace plagiarism_turnitin; + defined('MOODLE_INTERNAL') || die(); global $CFG; @@ -34,13 +36,14 @@ * @package plagiarism_turnitin * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class turnitin_quiz_test extends advanced_testcase { +final class turnitin_quiz_test extends advanced_testcase { /** * Proves that essay response marks are correctly updated. * + * @covers \turnitin_quiz * @copyright 2014 Tim Hunt */ - public function test_update_mark() { + public function test_update_mark(): void { $this->resetAfterTest(); // Create a user, course, and quiz activity with an essay question. diff --git a/tests/privacy/provider_test.php b/tests/privacy/provider_test.php index 28ff8738..8f5690b9 100644 --- a/tests/privacy/provider_test.php +++ b/tests/privacy/provider_test.php @@ -23,6 +23,8 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ +namespace plagiarism_turnitin\privacy; + use core_privacy\local\metadata\collection; use core_privacy\local\request\deletion_criteria; use plagiarism_turnitin\privacy\provider; @@ -39,12 +41,17 @@ return; } -class provider_test extends \core_privacy\tests\provider_testcase { +/** + * Unit tests for plagiarsm/turnitin/privacy + */ +final class provider_test extends \core_privacy\tests\provider_testcase { /** * Test for _get_metadata shim. + * + * @covers \core_plagiarism\privacy\legacy_polyfill::get_metadata */ - public function test_get_metadata() { + public function test_get_metadata(): void { $this->resetAfterTest(); $collection = new collection('plagiarism_turnitin'); @@ -97,8 +104,10 @@ public function test_get_metadata() { /** * Test that user's contexts are exported. + * + * @covers \core_plagiarism\privacy\legacy_polyfill::get_contexts_for_userid */ - public function test_get_contexts_for_userid() { + public function test_get_contexts_for_userid(): void { $this->resetAfterTest(); global $DB; @@ -113,7 +122,14 @@ public function test_get_contexts_for_userid() { $this->assertCount(1, $contextlist); } - public function test_export_plagiarism_user_data() { + /** + * Test that all user data is exported. + * + * @covers \core_plagiarism\privacy\legacy_polyfill::export_plagiarism_user_data + * @return void + * @throws \dml_exception + */ + public function test_export_plagiarism_user_data(): void { $this->resetAfterTest(); global $DB; @@ -128,7 +144,14 @@ public function test_export_plagiarism_user_data() { $this->assertTrue($writer->has_any_data()); } - public function test_delete_plagiarism_for_user() { + /** + * Test that all user data is deleted. + * + * @covers \core_plagiarism\privacy\legacy_polyfill::delete_plagiarism_for_user + * @return void + * @throws \dml_exception + */ + public function test_delete_plagiarism_for_user(): void { $this->resetAfterTest(); global $DB; @@ -149,7 +172,14 @@ public function test_delete_plagiarism_for_user() { $this->assertEquals(0, count($submissions)); } - public function test_delete_plagiarism_for_context() { + /** + * Test that all context data is deleted. + * + * @covers \core_plagiarism\privacy\legacy_polyfill::delete_plagiarism_for_context + * @return void + * @throws \dml_exception + */ + public function test_delete_plagiarism_for_context(): void { $this->resetAfterTest(); global $DB; @@ -165,6 +195,14 @@ public function test_delete_plagiarism_for_context() { $this->assertEquals(0, count($submissions)); } + /** + * Create a submission for testing. + * + * @param $numsubmissions + * @return array + * @throws \coding_exception + * @throws \dml_exception + */ public function create_submission($numsubmissions = 1) { global $DB, $CFG; require_once($CFG->dirroot . '/mod/assign/tests/base_test.php'); diff --git a/tests/turnitin_test.php b/tests/turnitin_test.php index d1100393..bda1d7da 100644 --- a/tests/turnitin_test.php +++ b/tests/turnitin_test.php @@ -22,7 +22,7 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -defined('MOODLE_INTERNAL') || die(); +namespace plagiarism_turnitin; use core_competency\course_competency; @@ -33,11 +33,13 @@ * @copyright 2016 Catalyst IT * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class turnitin_test extends advanced_testcase { +final class turnitin_test extends advanced_testcase { /** * Isolates a problem found running core tests in Moodle 31. + * + * @covers \reset_course_userdata */ - public function test_problem_moodle31_coretests() { + public function test_problem_moodle31_coretests(): void { $this->resetAfterTest(); $c1 = $this->getDataGenerator()->create_course(); diff --git a/version.php b/version.php index 0633c1f0..3163e23d 100644 --- a/version.php +++ b/version.php @@ -15,12 +15,14 @@ // along with Moodle. If not, see . /** + * Version information for plagiarism_turnitin. + * * @package plagiarism_turnitin * @copyright 2012 iParadigms LLC + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ $plugin->version = 2024121901; - $plugin->release = "4.1+"; $plugin->requires = 2018051700; $plugin->component = 'plagiarism_turnitin'; From 708282d48d8f00b6cf54c9ec59b051b1fee61512 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luca=20B=C3=B6sch?= Date: Fri, 26 Jul 2024 10:38:54 +0200 Subject: [PATCH 10/15] Moodle PHPDoc Checker fixes. --- ...store_plagiarism_turnitin_plugin.class.php | 12 + classes/digitalreceipt/pp_receipt_message.php | 2 + classes/forms/turnitin_setupform.class.php | 2 + classes/modules/turnitin_assign.class.php | 54 ++-- classes/modules/turnitin_coursework.class.php | 18 +- classes/modules/turnitin_forum.class.php | 22 +- classes/modules/turnitin_quiz.class.php | 32 +-- classes/modules/turnitin_workshop.class.php | 28 +- classes/observer.php | 9 +- classes/privacy/provider.php | 2 +- classes/turnitin_assignment.class.php | 42 +-- classes/turnitin_class.class.php | 4 +- classes/turnitin_comms.class.php | 11 +- classes/turnitin_submission.class.php | 4 +- classes/turnitin_user.class.php | 19 +- classes/turnitin_view.class.php | 21 +- lib.php | 254 ++++++++++++------ locallib.php | 10 +- tests/behat/behat_plagiarism_turnitin.php | 7 +- tests/generator/lib.php | 4 +- tests/privacy/provider_test.php | 2 +- 21 files changed, 339 insertions(+), 220 deletions(-) diff --git a/backup/moodle2/restore_plagiarism_turnitin_plugin.class.php b/backup/moodle2/restore_plagiarism_turnitin_plugin.class.php index ac1f6272..fc0676e0 100644 --- a/backup/moodle2/restore_plagiarism_turnitin_plugin.class.php +++ b/backup/moodle2/restore_plagiarism_turnitin_plugin.class.php @@ -37,6 +37,10 @@ protected function define_course_plugin_structure() { * Restore the Turnitin course * This will only be done this if the course is from the same site it was backed up from * and if the Turnitin course id does not currently exist in the database. + * + * @param array $data The data to be restored + * @return void + * @throws dml_exception */ public function process_turnitin_course($data) { global $DB; @@ -72,6 +76,10 @@ protected function define_module_plugin_structure() { * Restore the Turnitin assignment id for this module * This will only be done this if the module is from the same site it was backed up from * and if the Turnitin assignment id does not currently exist in the database. + * + * @param array $data The data to be restored + * @return void + * @throws dml_exception */ public function process_turnitin_config($data) { global $DB; @@ -98,6 +106,10 @@ public function process_turnitin_config($data) { * Restore the links to Turnitin files. * This will only be done this if the module is from the same site it was backed up from * and if the Turnitin submission does not currently exist in the database. + * + * @param array $data The data to be restored + * @return void + * @throws dml_exception */ public function process_turnitin_files($data) { global $DB; diff --git a/classes/digitalreceipt/pp_receipt_message.php b/classes/digitalreceipt/pp_receipt_message.php index dba93da9..d7ad5da4 100644 --- a/classes/digitalreceipt/pp_receipt_message.php +++ b/classes/digitalreceipt/pp_receipt_message.php @@ -26,7 +26,9 @@ class pp_receipt_message { /** * Send digital receipt to submitter * + * @param int $userid * @param string $message + * @param int $courseid * @return void */ public function send_message($userid, $message, $courseid) { diff --git a/classes/forms/turnitin_setupform.class.php b/classes/forms/turnitin_setupform.class.php index 6b3012c1..bfb3672a 100644 --- a/classes/forms/turnitin_setupform.class.php +++ b/classes/forms/turnitin_setupform.class.php @@ -262,6 +262,8 @@ public function display() { /** * Save the plugin config data + * + * @param stdClass $data */ public function save($data) { global $CFG; diff --git a/classes/modules/turnitin_assign.class.php b/classes/modules/turnitin_assign.class.php index 072cc98e..41ab9415 100644 --- a/classes/modules/turnitin_assign.class.php +++ b/classes/modules/turnitin_assign.class.php @@ -51,7 +51,7 @@ public function __construct() { /** * Check whether the user is a tutor * - * @param $context + * @param context $context The context * @return bool * @throws coding_exception */ @@ -68,22 +68,10 @@ public function get_tutor_capability() { return 'mod/'.$this->modname.':grade'; } - /** - * Whether the user is enrolled on the course and has the capability to submit assignments - * - * @param $context - * @param $userid - * @return bool - * @throws coding_exception - */ - public function user_enrolled_on_course($context, $userid) { - return has_capability('mod/'.$this->modname.':submit', $context, $userid); - } - /** * Get the author of the submission * - * @param $itemid + * @param int $itemid The item id * @return int * @throws dml_exception */ @@ -97,11 +85,23 @@ public function get_author($itemid) { } } + /** + * Whether the user is enrolled on the course and has the capability to submit assignments + * + * @param context $context The context + * @param int $userid The user id + * @return bool + * @throws coding_exception + */ + public function user_enrolled_on_course($context, $userid) { + return has_capability('mod/'.$this->modname.':submit', $context, $userid); + } + /** * Set the content of the submission * - * @param $linkarray - * @param $cm + * @param array $linkarray The link array + * @param object $cm The course module. * @return string */ public function set_content($linkarray, $cm) { @@ -114,7 +114,11 @@ public function set_content($linkarray, $cm) { /** * Check if resubmissions in a Turnitin sense are allowed to an assignment. * - * @param $assignid + * @param int $assignid The assignment id + * @param int $reportgenspeed The report generation speed + * @param string $submissiontype The submission type + * @param int $attemptreopenmethod The attempt reopen method + * @param string $attemptreopened The attempt reopened status */ public function is_resubmission_allowed($assignid, $reportgenspeed, $submissiontype, $attemptreopenmethod, $attemptreopened = null) { @@ -150,8 +154,8 @@ public function is_resubmission_allowed($assignid, $reportgenspeed, $submissiont /** * Get the onlinetext submission * - * @param $userid - * @param $cm + * @param int $userid The user id + * @param object $cm The course module. * @return stdClass * @throws dml_exception */ @@ -181,7 +185,7 @@ public function get_onlinetext($userid, $cm) { /** * Create a file event * - * @param $params + * @param array $params The params * @return \core\event\base * @throws coding_exception */ @@ -192,7 +196,7 @@ public function create_file_event($params) { /** * Create a text event * - * @param $params + * @param array $params The params * @return \core\event\base * @throws coding_exception */ @@ -203,9 +207,9 @@ public function create_text_event($params) { /** * Get the current grade query * - * @param $userid - * @param $moduleid - * @param $itemid + * @param int $userid The user id + * @param int $moduleid The module id + * @param int $itemid The item id * @return false|mixed * @throws dml_exception */ @@ -222,7 +226,7 @@ public function get_current_gradequery($userid, $moduleid, $itemid = 0) { /** * Initialise the post date for the module * - * @param $moduledata + * @param stdClass $moduledata The module data * @return int */ public function initialise_post_date($moduledata) { diff --git a/classes/modules/turnitin_coursework.class.php b/classes/modules/turnitin_coursework.class.php index f9f7f557..5ff8780f 100644 --- a/classes/modules/turnitin_coursework.class.php +++ b/classes/modules/turnitin_coursework.class.php @@ -51,7 +51,7 @@ public function __construct() { /** * Check whether the user is a tutor * - * @param $context + * @param context $context The context * @return bool */ public function is_tutor($context) { @@ -72,8 +72,8 @@ public function get_tutor_capability() { /** * Whether the user is enrolled on the course and has the capability to submit coursework * - * @param $context - * @param $userid + * @param context $context The context + * @param int $userid The user id * @return bool * @throws coding_exception */ @@ -84,7 +84,7 @@ public function user_enrolled_on_course($context, $userid) { /** * Get the author of the submission * - * @param $itemid + * @param int $itemid The item id * @return int * @throws dml_exception */ @@ -103,7 +103,7 @@ public function get_author($itemid) { /** * Create a file event * - * @param $params + * @param array $params The params * @return mixed */ public function create_file_event($params) { @@ -113,9 +113,9 @@ public function create_file_event($params) { /** * Get the current grade query * - * @param $userid - * @param $moduleid - * @param $itemid + * @param int $userid The user id + * @param int $moduleid The module id + * @param int $itemid The item id * @return false|mixed * @throws dml_exception */ @@ -140,7 +140,7 @@ public function get_current_gradequery($userid, $moduleid, $itemid = 0) { /** * Initialise the post date for the module * - * @param $moduledata + * @param stdClass $moduledata The module data * @return int */ public function initialise_post_date($moduledata) { diff --git a/classes/modules/turnitin_forum.class.php b/classes/modules/turnitin_forum.class.php index 5b14c429..cec4c235 100644 --- a/classes/modules/turnitin_forum.class.php +++ b/classes/modules/turnitin_forum.class.php @@ -51,7 +51,7 @@ public function __construct() { /** * Check whether the user is a tutor * - * @param $context + * @param context $context The context * @return bool * @throws coding_exception */ @@ -71,8 +71,8 @@ public function get_tutor_capability() { /** * Whether the user is enrolled on the course and has the capability to reply to posts * - * @param $context - * @param $userid + * @param context $context The context + * @param int $userid The user id * @return bool * @throws coding_exception */ @@ -83,7 +83,7 @@ public function user_enrolled_on_course($context, $userid) { /** * Get the author of the forum post * - * @param $itemid + * @param int $itemid The item id * @return void */ public function get_author($itemid = 0) { @@ -93,7 +93,7 @@ public function get_author($itemid = 0) { /** * Set the content of the forum post * - * @param $linkarray + * @param array $linkarray The link array * @return mixed * @throws dml_exception */ @@ -111,7 +111,7 @@ public function set_content($linkarray) { /** * Create a file event * - * @param $params + * @param array $params The params * @return \core\event\base * @throws coding_exception */ @@ -122,9 +122,9 @@ public function create_file_event($params) { /** * Get the current grade query * - * @param $userid - * @param $moduleid - * @param $itemid + * @param int $userid The user id + * @param int $moduleid The module id + * @param int $itemid The item id * @return false|mixed|stdClass * @throws dml_exception */ @@ -138,7 +138,7 @@ public function get_current_gradequery($userid, $moduleid, $itemid = 0) { /** * Initialise the post date for the module * - * @param $moduledata + * @param stdClass $moduledata The module data * @return int */ public function initialise_post_date($moduledata) { @@ -150,7 +150,7 @@ public function initialise_post_date($moduledata) { /** * Get the forum discussion id * - * @param $forumdata + * @param string $forumdata The forum data * @return string */ public function get_discussionid($forumdata) { diff --git a/classes/modules/turnitin_quiz.class.php b/classes/modules/turnitin_quiz.class.php index 0898b21b..835bdfdb 100644 --- a/classes/modules/turnitin_quiz.class.php +++ b/classes/modules/turnitin_quiz.class.php @@ -54,7 +54,7 @@ public function __construct() { /** * Check whether the user is a tutor * - * @param $context + * @param context $context The context * @return bool * @throws coding_exception */ @@ -65,8 +65,8 @@ public function is_tutor($context) { /** * Whether the user is enrolled on the course and has the capability to submit quiz attempts * - * @param $context - * @param $userid + * @param context $context The context + * @param int $userid The user id * @return bool * @throws coding_exception */ @@ -77,7 +77,7 @@ public function user_enrolled_on_course($context, $userid) { /** * Get the author of the quiz attempt * - * @param $itemid + * @param int $itemid The item id * @return void */ public function get_author($itemid = 0) { @@ -96,7 +96,7 @@ public function get_tutor_capability() { /** * Set the content of the quiz attempt * - * @param $linkarray + * @param array $linkarray The link array * @return mixed */ public function set_content($linkarray) { @@ -106,9 +106,9 @@ public function set_content($linkarray) { /** * Get the current grade query * - * @param $userid - * @param $moduleid - * @param $itemid + * @param int $userid The user id + * @param int $moduleid The module id + * @param int $itemid The item id * @return false|mixed|stdClass * @throws dml_exception */ @@ -124,9 +124,9 @@ public function get_current_gradequery($userid, $moduleid, $itemid = 0) { /** * Calculate the mark for a question attempt based on the grade given for the answer in TFS. * - * @param $grade - * @param $questionmaxmark - * @param $quizgrade + * @param float $grade The grade given for the answer in TFS + * @param float $questionmaxmark The maximum mark for the question + * @param float $quizgrade The total grade for the quiz * @return float|int */ public function calculate_mark($grade, $questionmaxmark, $quizgrade) { @@ -137,11 +137,11 @@ public function calculate_mark($grade, $questionmaxmark, $quizgrade) { /** * Set a new mark for a question attempt based on the grade given for the answer in TFS. * - * @param $attemptid - * @param $identifier - * @param $userid - * @param $grade - * @param $quizgrade + * @param int $attemptid The attempt id + * @param string $identifier The question slot identifier + * @param int $userid The user id + * @param float $grade The grade given for the answer in TFS + * @param float $quizgrade The total grade for the quiz * @return void * @throws dml_exception * @throws dml_transaction_exception diff --git a/classes/modules/turnitin_workshop.class.php b/classes/modules/turnitin_workshop.class.php index 9c354909..11f248a2 100644 --- a/classes/modules/turnitin_workshop.class.php +++ b/classes/modules/turnitin_workshop.class.php @@ -51,7 +51,7 @@ public function __construct() { /** * Check whether the user is a tutor * - * @param $context + * @param context $context The context * @return bool * @throws coding_exception */ @@ -71,8 +71,8 @@ public function get_tutor_capability() { /** * Whether the user is enrolled on the course and has the capability to submit a workshop submission * - * @param $context - * @param $userid + * @param context $context The context + * @param int $userid The user id * @return bool * @throws coding_exception */ @@ -83,7 +83,7 @@ public function user_enrolled_on_course($context, $userid) { /** * Get the author of the workshop submission * - * @param $itemid + * @param int $itemid The item id * @return void */ public function get_author($itemid) { @@ -93,8 +93,8 @@ public function get_author($itemid) { /** * Set the content of the workshop submission * - * @param $linkarray - * @param $moduleid + * @param array $linkarray The link array + * @param int $moduleid The module id * @return mixed */ public function set_content($linkarray, $moduleid) { @@ -104,8 +104,8 @@ public function set_content($linkarray, $moduleid) { /** * Get the onlinetext * - * @param $userid - * @param $cm + * @param int $userid The user id + * @param object $cm The course module. * @return stdClass * @throws dml_exception */ @@ -126,7 +126,7 @@ public function get_onlinetext($userid, $cm) { /** * Create a file event * - * @param $params + * @param array $params The params * @return \core\event\base * @throws coding_exception */ @@ -137,7 +137,7 @@ public function create_file_event($params) { /** * Create a text event * - * @param $params + * @param array $params The params * @return \core\event\base * @throws coding_exception */ @@ -148,9 +148,9 @@ public function create_text_event($params) { /** * Get the current grade query * - * @param $userid - * @param $moduleid - * @param $itemid + * @param int $userid The user id + * @param int $moduleid The module id + * @param int $itemid The item id * @return false|mixed|stdClass * @throws dml_exception */ @@ -164,7 +164,7 @@ public function get_current_gradequery($userid, $moduleid, $itemid = 0) { /** * Initialise the post date for the module * - * @param $moduledata + * @param stdClass $moduledata The module data * @return mixed */ public function initialise_post_date($moduledata) { diff --git a/classes/observer.php b/classes/observer.php index 58b89c83..b9ad5036 100644 --- a/classes/observer.php +++ b/classes/observer.php @@ -40,8 +40,8 @@ public static function course_module_deleted( } /** - * Handle the course_module_deleted event. - * @param \core\event\course_module_deleted $event + * Handle the course_module_ended event. + * @param \core\event\course_reset_ended $event */ public static function course_reset( \core\event\course_reset_ended $event) { @@ -109,8 +109,9 @@ public static function assignsubmission_onlinetext_uploaded( } /** - * Handle the assignment assessable_submitted event. - * @param \mod_assign\event\assessable_submitted $event + * Handle the coursework assessable_uploaded event. + * + * @param \mod_coursework\event\assessable_uploaded $event */ public static function coursework_submitted( \mod_coursework\event\assessable_uploaded $event) { diff --git a/classes/privacy/provider.php b/classes/privacy/provider.php index 0faf1539..abafd839 100644 --- a/classes/privacy/provider.php +++ b/classes/privacy/provider.php @@ -51,7 +51,7 @@ class provider implements /** * Return the fields which contain personal data. * - * @param $collection collection a reference to the collection to use to store the metadata. + * @param collection $collection a reference to the collection to use to store the metadata. * @return $collection the updated collection of metadata items. */ public static function _get_metadata(collection $collection) { diff --git a/classes/turnitin_assignment.class.php b/classes/turnitin_assignment.class.php index fc8a80a6..713a5e4c 100644 --- a/classes/turnitin_assignment.class.php +++ b/classes/turnitin_assignment.class.php @@ -44,8 +44,8 @@ class turnitin_assignment { /** * turnitin_assignment constructor. * - * @param $id - * @param $turnitincomms + * @param int $id The ID of the assignment + * @param turnitin_comms $turnitincomms The Turnitin comms object */ public function __construct($id = 0, $turnitincomms = null) { $this->id = $id; @@ -141,7 +141,7 @@ public function create_tii_course($course, $workflowcontext = "site") { /** * Edit the course title in Turnitin * - * @param var $course The course object + * @param object $course The course object */ public function edit_tii_course($course) { global $DB; @@ -207,7 +207,7 @@ public static function truncate_title($title, $limit) { /** * Create Assignment on Turnitin and return id, delete the instance if it fails * - * @param object $assignment add assignment instance + * @param object $assignment The assignment instance * @param string $workflowcontext The workflow being used to call this - site or cron. */ public function create_tii_assignment($assignment, $workflowcontext = "site") { @@ -236,7 +236,7 @@ public function create_tii_assignment($assignment, $workflowcontext = "site") { /** * Edit Assignment on Turnitin * - * @param object $assignment edit assignment instance + * @param object $assignment The assignment instance * @param string $workflowcontext The workflow being used to call this - site or cron. */ public function edit_tii_assignment($assignment, $workflowcontext = "site") { @@ -281,7 +281,7 @@ public function edit_tii_assignment($assignment, $workflowcontext = "site") { /** * Get the Peermark assignments for this activity. * - * @param $tiiassignid + * @param int $tiiassignid The Turnitin assignment id * @return array */ public function get_peermark_assignments($tiiassignid) { @@ -296,8 +296,8 @@ public function get_peermark_assignments($tiiassignid) { /** * Wrapper for Turnitin API call createClass(). * - * @param $turnitincall - * @param $class + * @param object $turnitincall + * @param TiiClass $class * @return mixed */ public function api_create_class($turnitincall, $class) { @@ -307,8 +307,8 @@ public function api_create_class($turnitincall, $class) { /** * Wrapper for Turnitin API call createClass(). * - * @param $turnitincall - * @param $class + * @param object $turnitincall + * @param TiiClass $class * @return mixed */ public function api_update_class($turnitincall, $class) { @@ -318,7 +318,7 @@ public function api_update_class($turnitincall, $class) { /** * Wrapper for Turnitin API call getClass(). * - * @param $object + * @param object $object * @return mixed */ public function api_get_class($object) { @@ -328,7 +328,7 @@ public function api_get_class($object) { /** * Wrapper for Turnitin API call getClassId(). * - * @param $class + * @param TiiClass $class * @return mixed */ public function api_get_class_id($class) { @@ -338,8 +338,8 @@ public function api_get_class_id($class) { /** * Wrapper for Turnitin API call setClassId(). * - * @param $object - * @param $classid + * @param object $object + * @param int $classid * @return mixed */ public function api_set_class_id($object, $classid) { @@ -349,8 +349,8 @@ public function api_set_class_id($object, $classid) { /** * Wrapper for Turnitin API call createAssignment(). * - * @param $turnitincall - * @param $assignment + * @param object $turnitincall + * @param object $assignment The assignment instance * @return mixed */ public function api_create_assignment($turnitincall, $assignment) { @@ -360,8 +360,8 @@ public function api_create_assignment($turnitincall, $assignment) { /** * Wrapper for Turnitin API call createAssignment(). * - * @param $turnitincall - * @param $assignment + * @param object $turnitincall + * @param object $assignment The assignment instance * @return mixed */ public function api_update_assignment($turnitincall, $assignment) { @@ -371,7 +371,7 @@ public function api_update_assignment($turnitincall, $assignment) { /** * Wrapper for Turnitin API call getAssignment(). * - * @param $object + * @param object $object * @return mixed */ public function api_get_assignment($object) { @@ -381,7 +381,7 @@ public function api_get_assignment($object) { /** * Wrapper for Turnitin API call getAssignmentId(). * - * @param $assignment + * @param object $assignment The assignment instance * @return mixed */ public function api_get_assignment_id($assignment) { @@ -391,7 +391,7 @@ public function api_get_assignment_id($assignment) { /** * Wrapper for Turnitin API call getTitle(). * - * @param $assignment + * @param object $assignment The assignment instance * @return mixed */ public function api_get_title($assignment) { diff --git a/classes/turnitin_class.class.php b/classes/turnitin_class.class.php index e53d90f4..fb2d8ebf 100644 --- a/classes/turnitin_class.class.php +++ b/classes/turnitin_class.class.php @@ -53,7 +53,7 @@ class turnitin_class { /** * turnitin_class constructor. * - * @param $id + * @param int $id * @throws dml_exception */ public function __construct($id) { @@ -70,7 +70,7 @@ public function __construct($id) { /** * Update class from Turnitin, mainly to get shared rubrics * - * @return + * @return void */ public function read_class_from_tii() { // Initialise Comms Object. diff --git a/classes/turnitin_comms.class.php b/classes/turnitin_comms.class.php index f7d2961d..79867bb7 100644 --- a/classes/turnitin_comms.class.php +++ b/classes/turnitin_comms.class.php @@ -67,9 +67,9 @@ class turnitin_comms { /** * Constructor * - * @param $accountid - * @param $accountshared - * @param $url + * @param string $accountid + * @param string $accountshared + * @param string $url * @throws moodle_exception */ public function __construct($accountid = null, $accountshared = null, $url = null) { @@ -98,6 +98,7 @@ public function __construct($accountid = null, $accountshared = null, $url = nul /** * Initialise the API object * + * @param bool $istestingconnection * @return object \APITurnitin */ public function initialise_api($istestingconnection = false) { @@ -157,7 +158,8 @@ public function initialise_api($istestingconnection = false) { * * @param object $e * @param string $tterrorstr - * @param boolean $toscreen + * @param bool $toscreen + * @param bool $embedded */ public function handle_exceptions($e, $tterrorstr = "", $toscreen = true, $embedded = false) { $errorstr = ""; @@ -199,7 +201,6 @@ public function handle_exceptions($e, $tterrorstr = "", $toscreen = true, $embed /** * Outputs a language code to use with the Turnitin API * - * @param string $langcode The Moodle language code * @return string The cleaned and mapped associated Turnitin lang code */ private function get_lang() { diff --git a/classes/turnitin_submission.class.php b/classes/turnitin_submission.class.php index f81f6b19..9133872e 100644 --- a/classes/turnitin_submission.class.php +++ b/classes/turnitin_submission.class.php @@ -43,8 +43,8 @@ class turnitin_submission { /** * Class turnitin_submission constructor. * - * @param $id - * @param $data + * @param int $id + * @param stdClass $data * @throws coding_exception * @throws dml_exception */ diff --git a/classes/turnitin_user.class.php b/classes/turnitin_user.class.php index 23f87001..79e38778 100644 --- a/classes/turnitin_user.class.php +++ b/classes/turnitin_user.class.php @@ -81,11 +81,11 @@ class turnitin_user { /** * Constructor for the Turnitin User class * - * @param $id - * @param $role - * @param $enrol - * @param $workflowcontext - * @param $finduser + * @param int $id The id + * @param string $role The role + * @param bool $enrol Whether to enrol the user + * @param string $workflowcontext The workflow context + * @param bool $finduser Whether to find the user */ public function __construct($id, $role = "Learner", $enrol = true, $workflowcontext = "site", $finduser = true) { $this->id = $id; @@ -175,7 +175,6 @@ public function get_pseudo_firstname() { /** * Convert a regular lastname into the pseudo equivelant for student data privacy purpose * - * @param string $email The users email address * @return string A pseudo lastname address */ public function get_pseudo_lastname() { @@ -210,7 +209,6 @@ public function get_pseudo_lastname() { * or if none found, it will try and find user in Turnitin. If not found it * will create them in Turnitin if necessary * - * @param object $user A data object for the user * @return var A Turnitin User ID or null */ private function get_tii_user_id() { @@ -281,8 +279,6 @@ private function find_tii_user_id() { /** * Create the user on Turnitin * - * @param object $user_details A data object for the user - * @param var $role user role to create * @return var Turnitin user id */ private function create_tii_user() { @@ -328,8 +324,6 @@ private function create_tii_user() { /** * Edit the user's details on Turnitin (only name can be updated) * - * @param object $user_details A data object for the user - * @param var $role user role to create * @return boolean */ public function edit_tii_user() { @@ -418,7 +412,7 @@ private function save_tii_user() { /** * Enrol the user on this course/class in Turnitin * - * @param type $tiicourseid id for the course/class in Turnitin + * @param int $tiicourseid id for the course/class in Turnitin * @return boolean */ public function join_user_to_class($tiicourseid) { @@ -587,6 +581,7 @@ public function get_user_role() { /** * Set the rubrics the instructor has in Turnitin * + * @param string $role The role of the user * @return int */ private function set_user_role($role) { diff --git a/classes/turnitin_view.class.php b/classes/turnitin_view.class.php index 680b0d92..c63339ca 100644 --- a/classes/turnitin_view.class.php +++ b/classes/turnitin_view.class.php @@ -56,6 +56,7 @@ public function output_header($url, $title = '', $heading = '', $return = false) * Prints the tab menu for the plugin settings * * @param string $currenttab The currect tab to be styled as selected + * @param array $notice An array containing the message and type of notice to display */ public function draw_settings_tab_menu($currenttab, $notice = null) { global $OUTPUT; @@ -84,8 +85,13 @@ public function draw_settings_tab_menu($currenttab, $notice = null) { * Due to moodle's internal plugin hooks we can not use our bespoke form class for Turnitin * settings. This form shows in settings > defaults as well as the activity creation screen. * - * @param type $plugin_defaults - * @return type + * @param moodleform $mform The form object + * @param object $course The course object + * @param string $location The location of the form + * @param string $modulename The name of the module + * @param int $cmid The course module id + * @param int $currentrubric The current rubric id + * @return void */ public function add_elements_to_settings_form($mform, $course, $location = "activity", $modulename = "", $cmid = 0, $currentrubric = 0) { @@ -453,7 +459,7 @@ public function add_elements_to_settings_form($mform, $course, $location = "acti /** * Show the errors table for file uploads. * - * @param $page + * @param int $page The page number to show. * @return string * @throws coding_exception * @throws moodle_exception @@ -589,6 +595,10 @@ public function show_file_errors_table($page = 0) { /** * This adds a site lock check to the most recently added field + * + * @param moodleform $mform the form object + * @param string $location the location of the form + * @param array $locks the locks array */ public function lock($mform, $location, $locks) { @@ -621,6 +631,7 @@ public function lock($mform, $location, $locks) { * @param int $userid the Turnitin user id * @param string $userrole the role the user has on Turnitin in the course/class * @param string $buttonstring string for the submit button + * @param bool $ltireturn return the LTI form as a string * @return string form */ public static function output_launch_form($type, $submissionid, $userid, $userrole, @@ -679,8 +690,10 @@ public static function output_launch_form($type, $submissionid, $userid, $userro * Return the output for a form to launch the relevant LTi function * It is then submitted on load via Javascript * + * @param string $type the type of document viewer that needs to be opened * @param string $userrole either Instructor or Learner - * @param int $userid + * @param int $partid the part id of the assignment + * @param int $classid the class id of the assignment * @return string form */ public static function output_lti_form_launch($type, $userrole, $partid = 0, $classid = 0) { diff --git a/lib.php b/lib.php index 4ff966ea..211ac5a0 100755 --- a/lib.php +++ b/lib.php @@ -113,6 +113,7 @@ public function get_settings_fields() { /** * Get the configuration settings for the plagiarism plugin * + * @param string $modulename the name of the module * @return mixed if plugin is enabled then an array of config settings is returned or false if not */ public static function get_config_settings($modulename) { @@ -197,8 +198,8 @@ public function get_file_upload_errors($offset = 0, $limit = 0, $count = false) * This function is called from the inbox in mod assign. * This will alert the user to refresh the assignment when there has been a change in scores. * - * @param $course - Course the module is part of - * @param $cm - Course module + * @param object $course The course object + * @param object $cm The course module. * @return string */ public function update_status($course, $cm) { @@ -267,9 +268,10 @@ public function save_form_data($data) { /** * Add the Turnitin settings form to an add/edit activity page * - * @param object $mform - * @param object $context - * @return type + * @param moodleform $mform The form object + * @param context $context The context of the form + * @param string $modulename The name of the module + * @return void */ public function add_settings_form_to_activity_page($mform, $context, $modulename = "") { global $DB, $PAGE, $COURSE; @@ -354,7 +356,7 @@ public function add_settings_form_to_activity_page($mform, $context, $modulename * Remove Turnitin class and assignment links from database * so that new classes and assignments will be created. * - * @param type $eventdata + * @param object $eventdata * @return boolean */ public static function course_reset($eventdata) { @@ -429,6 +431,8 @@ public static function course_reset($eventdata) { * Test whether we can connect to Turnitin. * * Initially only being used if a student is logged in before checking whether they have accepted the EULA. + * + * @param string $workflowcontext The context of the workflow */ public function test_turnitin_connection($workflowcontext = 'site') { $turnitincomms = new turnitin_comms(); @@ -452,7 +456,7 @@ public function test_turnitin_connection($workflowcontext = 'site') { /** * Print the Turnitin student disclosure inside the submission page for students to see * - * @param $cmid + * @param int $cmid The course module id * @return string */ public function print_disclosure($cmid) { @@ -612,6 +616,10 @@ public function load_page_components() { /** * Get Moodle and Turnitin Course data + * + * @param int $cmid The course module id + * @param int $courseid The course id + * @param string $workflowcontext The context of the workflow */ public function get_course_data($cmid, $courseid, $workflowcontext = 'site') { $coursedata = turnitin_assignment::get_course_data($courseid, $workflowcontext); @@ -642,9 +650,10 @@ public function get_course_data($cmid, $courseid, $workflowcontext = 'site') { } /** + * Get the links to display on the submission page. * - * @param type $linkarray - * @return type + * @param array $linkarray The link array + * @return string */ public function get_links($linkarray) { global $CFG, $DB, $OUTPUT, $USER; @@ -1273,7 +1282,7 @@ public function get_links($linkarray) { /** * Query Turnitin for the papers that need updated locally. * - * @param $cm + * @param object $cm The course module. * @return false */ public function fetch_updated_paper_ids_from_turnitin($cm) { @@ -1306,7 +1315,7 @@ public function fetch_updated_paper_ids_from_turnitin($cm) { /** * Update grades from Turnitin. * - * @param $cm + * @param object $cm The course module. * @return bool|int */ public function update_grades_from_tii($cm) { @@ -1351,8 +1360,8 @@ public function update_grades_from_tii($cm) { /** * Update grade from Turnitin. * - * @param $cm - * @param $submissionid + * @param object $cm The course module. + * @param int $submissionid The submission id. * @return bool */ public function update_grade_from_tii($cm, $submissionid) { @@ -1387,9 +1396,9 @@ public function update_grade_from_tii($cm, $submissionid) { /** * Update submission data. * - * @param $cm - * @param $submissionid - * @param $tiisubmission + * @param object $cm The course module. + * @param int $submissionid The submission id. + * @param TiiSubmission $tiisubmission The Turnitin submission. * @return bool|int * @throws dml_exception * @throws dml_transaction_exception @@ -1518,6 +1527,10 @@ private function update_submission($cm, $submissionid, $tiisubmission) { /** * Update module grade and gradebook. + * + * @param object $cm The course module. + * @param object $submission The submission object. + * @param int $userid The user id. */ private function update_grade($cm, $submission, $userid, $cron = FALSE) { global $DB, $USER, $CFG; @@ -1686,6 +1699,9 @@ private function update_grade($cm, $submission, $userid, $cron = FALSE) { /** * Check if this is a group submission. + * + * @param object $cm The course module. + * @param int $userid The user id. */ public function check_group_submission($cm, $userid) { global $CFG, $DB; @@ -1708,8 +1724,8 @@ public function check_group_submission($cm, $userid) { * Related user ID will be NULL if an instructor submits on behalf of a student who is in a group. * To get around this, we get the group ID, get the group members and set the author as the first student in the group. * - * @param $cmid - * @param $groupid + * @param int $cmid The course module id. + * @param int $groupid The group id. * @return void * @throws coding_exception */ @@ -1729,6 +1745,11 @@ private function get_first_group_author($cmid, $groupid) { /** * Create a course within Turnitin + * + * @param int $cmid The course module id. + * @param string $modname The module name. + * @param object $coursedata The course data. + * @param string $workflowcontext The context of the workflow. */ public function create_tii_course($cmid, $modname, $coursedata, $workflowcontext = "site") { global $CFG; @@ -1766,6 +1787,9 @@ public function create_tii_course($cmid, $modname, $coursedata, $workflowcontext /** * Get Peermark Assignments for this module from Turnitin. + * + * @param object $cm The course module. + * @param string $tiiassignmentid The Turnitin assignment id. */ public function refresh_peermark_assignments($cm, $tiiassignmentid) { global $DB; @@ -1816,9 +1840,61 @@ public function refresh_peermark_assignments($cm, $tiiassignmentid) { } } + /** + * Check for rubric and save to assignment. + * + * @param object $cm The course module. + */ + public function update_rubric_from_tii($cm) { + global $DB; + + $turnitincomms = new turnitin_comms(); + $turnitincall = $turnitincomms->initialise_api(); + $assignment = new TiiAssignment(); + + if ($tiimoduledata = $DB->get_record('plagiarism_turnitin_config', + ['cm' => $cm->id, 'name' => 'turnitin_assignid'], 'value')) { + + $assignment->setAssignmentId($tiimoduledata->value); + + try { + // Retrieve assignment from Turnitin. + $response = $turnitincall->readAssignment($assignment); + $tiiassignment = $response->getAssignment(); + + // Create rubric config field with rubric value from Turnitin. + $rubricfield = new stdClass(); + $rubricfield->cm = $cm->id; + $rubricfield->name = 'plagiarism_rubric'; + $rubricfield->value = $tiiassignment->getRubricId(); + + // Check if rubric already exists for this module. + if ($configfield = $DB->get_field('plagiarism_turnitin_config', 'id', + (['cm' => $cm->id, 'name' => 'plagiarism_rubric']))) { + + // Use current configfield to update rubric value. + $rubricfield->id = $configfield; + + $DB->update_record('plagiarism_turnitin_config', $rubricfield); + } else { + // Otherwise create rubric entry for this module. + $rubricfield->config_hash = $rubricfield->cm."_".$rubricfield->name; + $DB->create_record('plagiarism_turnitin_config', $rubricfield); + } + } catch (Exception $e) { + $turnitincomms->handle_exceptions($e, 'tiiassignmentgeterror', false); + } + } + } + /** * Create the module as an assignment within Turnitin if it does not exist, * if we have a Turnitin id for the module then edit it + * + * @param object $cm The course module. + * @param string $coursetiiid The Turnitin course id. + * @param string $workflowcontext The context of the workflow. + * @param bool $submittoturnitin Whether to submit to Turnitin. */ public function sync_tii_assignment($cm, $coursetiiid, $workflowcontext = "site", $submittoturnitin = false) { global $DB; @@ -1870,7 +1946,7 @@ public function sync_tii_assignment($cm, $coursetiiid, $workflowcontext = "site" // Don't set anonymous marking if there have been submissions. $previoussubmissions = $DB->record_exists('plagiarism_turnitin_files', - ['cm' => $cm->id, 'statuscode' => 'success']); + ['cm' => $cm->id, 'statuscode' => 'success']); // Use Moodle's blind marking setting for anonymous marking. if (isset($config->plagiarism_turnitin_useanon) && $config->plagiarism_turnitin_useanon && !$previoussubmissions) { @@ -1908,13 +1984,13 @@ public function sync_tii_assignment($cm, $coursetiiid, $workflowcontext = "site" $dtpost = 0; if ($cm->modname != "forum") { if ($gradeitem = $DB->get_record( - 'grade_items', - [ - 'iteminstance' => $cm->instance, - 'itemmodule' => $cm->modname, - 'courseid' => $cm->course, - 'itemnumber' => 0, ] - )) { + 'grade_items', + [ + 'iteminstance' => $cm->instance, + 'itemmodule' => $cm->modname, + 'courseid' => $cm->course, + 'itemnumber' => 0, ] + )) { switch ($gradeitem->hidden) { case 1: @@ -1925,8 +2001,8 @@ public function sync_tii_assignment($cm, $coursetiiid, $workflowcontext = "site" // If any grades have been released early via marking workflow, set post date to have passed. if ($cm->modname == 'assign' && !empty($moduledata->markingworkflow)) { $gradesreleased = $DB->record_exists('assign_user_flags', - ['assignment' => $cm->instance, - 'workflowstate' => 'released', ]); + ['assignment' => $cm->instance, + 'workflowstate' => 'released', ]); $dtpost = ($gradesreleased) ? strtotime('-5 minutes') : strtotime('+1 month'); } @@ -2002,7 +2078,7 @@ public function sync_tii_assignment($cm, $coursetiiid, $workflowcontext = "site" // If we have a turnitin id then edit the assignment otherwise create it. if ($tiiassignment = $DB->get_record('plagiarism_turnitin_config', - ['cm' => $cm->id, 'name' => 'turnitin_assignid'], 'value')) { + ['cm' => $cm->id, 'name' => 'turnitin_assignid'], 'value')) { $assignment->setAssignmentId($tiiassignment->value); $turnitinassignment = new turnitin_assignment(0); @@ -2031,51 +2107,6 @@ public function sync_tii_assignment($cm, $coursetiiid, $workflowcontext = "site" } } - /** - * Check for rubric and save to assignment. - */ - public function update_rubric_from_tii($cm) { - global $DB; - - $turnitincomms = new turnitin_comms(); - $turnitincall = $turnitincomms->initialise_api(); - $assignment = new TiiAssignment(); - - if ($tiimoduledata = $DB->get_record('plagiarism_turnitin_config', - ['cm' => $cm->id, 'name' => 'turnitin_assignid'], 'value')) { - - $assignment->setAssignmentId($tiimoduledata->value); - - try { - // Retrieve assignment from Turnitin. - $response = $turnitincall->readAssignment($assignment); - $tiiassignment = $response->getAssignment(); - - // Create rubric config field with rubric value from Turnitin. - $rubricfield = new stdClass(); - $rubricfield->cm = $cm->id; - $rubricfield->name = 'plagiarism_rubric'; - $rubricfield->value = $tiiassignment->getRubricId(); - - // Check if rubric already exists for this module. - if ($configfield = $DB->get_field('plagiarism_turnitin_config', 'id', - (['cm' => $cm->id, 'name' => 'plagiarism_rubric']))) { - - // Use current configfield to update rubric value. - $rubricfield->id = $configfield; - - $DB->update_record('plagiarism_turnitin_config', $rubricfield); - } else { - // Otherwise create rubric entry for this module. - $rubricfield->config_hash = $rubricfield->cm."_".$rubricfield->name; - $DB->create_record('plagiarism_turnitin_config', $rubricfield); - } - } catch (Exception $e) { - $turnitincomms->handle_exceptions($e, 'tiiassignmentgeterror', false); - } - } - } - /** * Updates the database field duedate_report_refresh for any given submission ID. * @param int $id - the ID of the submission to update. @@ -2092,7 +2123,7 @@ public function set_duedate_report_refresh($id, $newvalue) { /** * Update simliarity scores. - * @param array $submissions - the submissions to be processed + * * @return boolean */ public function cron_update_scores() { @@ -2310,8 +2341,8 @@ public function cron_update_scores() { /** * Check the local submission state against Turnitin. * - * @param $assignmentids - * @param $submissionids + * @param array $assignmentids + * @param array $submissionids * @return array */ private function check_local_submission_state($assignmentids, $submissionids) { @@ -2342,7 +2373,7 @@ private function check_local_submission_state($assignmentids, $submissionids) { /** * Invalidate a missing submission. * - * @param $missingsubmission + * @param int $missingsubmission The missing submission id. * @return void * @throws dml_exception */ @@ -2368,6 +2399,8 @@ private function invalidate_missing_submission($missingsubmission) { /** * Get a class Id from Turnitin if you only have an assignment id. + * + * @param int $assignmentid The assignment id. */ private function get_course_id_from_assignment_id($assignmentid) { // Initialise Comms Object. @@ -2390,6 +2423,9 @@ private function get_course_id_from_assignment_id($assignmentid) { /** * Previous incarnations of this plugin did not store the turnitin course id so we have to get this using the assignment id. * If that wasn't linked with turnitin then we have to check all the modules on this course. + * + * @param int $cmid The course module id. + * @param int $courseid The course id. */ public function get_previous_course_id($cmid, $courseid) { global $DB; @@ -2415,6 +2451,10 @@ public function get_previous_course_id($cmid, $courseid) { /** * Migrate course from previous version of plugin to this + * + * @param object $coursedata The course data. + * @param int $turnitincid The Turnitin course id. + * @param string $workflowcontext The context of the workflow. */ public function migrate_previous_course($coursedata, $turnitincid, $workflowcontext = "site") { global $DB; @@ -2451,12 +2491,13 @@ public function migrate_previous_course($coursedata, $turnitincid, $workflowcont /** * Queue submissions to send to Turnitin * - * @param $cm - * @param $author - * @param $submitter - * @param $identifier - * @param $submissiontype - * @param int $itemid + * @param object $cm The course module. + * @param string $author The author of the submission. + * @param int $submitter The submitter. + * @param string $identifier The identifier. + * @param string $submissiontype The submission type. + * @param int $itemid The item id. + * @param string $eventtype The event type. * @return bool */ public function queue_submission_to_turnitin($cm, $author, $submitter, $identifier, $submissiontype, $itemid = 0, @@ -2861,6 +2902,10 @@ public function event_handler($eventdata) { /** * Initialise submission values * + * @param object $cm The course module. + * @param int $userid The user id. + * @param string $identifier The identifier. + * @param string $submissiontype The submission type. **/ private function create_new_tii_submission($cm, $userid, $identifier, $submissiontype) { global $DB; @@ -2886,6 +2931,11 @@ private function create_new_tii_submission($cm, $userid, $identifier, $submissio /** * Reset submission values * + * @param object $cm The course module. + * @param int $userid The user id. + * @param string $identifier The identifier. + * @param object $currentsubmission The current submission. + * @param string $submissiontype The submission type. **/ private function reset_tii_submission($cm, $userid, $identifier, $currentsubmission, $submissiontype) { global $DB; @@ -2912,6 +2962,12 @@ private function reset_tii_submission($cm, $userid, $identifier, $currentsubmiss /** * Clean up previous file submissions. * Moodle will remove any old files or drafts during cron execution and file submission. + * + * @param object $cm The course module. + * @param int $userid The user id. + * @param int $itemid The item id. + * @param string $submissiontype The submission type. + * @param string $identifier The identifier. */ public function clean_old_turnitin_submissions($cm, $userid, $itemid, $submissiontype, $identifier) { global $DB, $CFG; @@ -2979,6 +3035,10 @@ public function clean_old_turnitin_submissions($cm, $userid, $itemid, $submissio /** * Update an errored submission in the files table. + * + * @param int $submissionid The submission id. + * @param int $attempt The attempt number. + * @param int $errorcode The error code. */ public function save_errored_submission($submissionid, $attempt, $errorcode) { global $DB; @@ -2998,6 +3058,19 @@ public function save_errored_submission($submissionid, $attempt, $errorcode) { /** * Save the submission data to the files table. + * + * @param object $cm The course module. + * @param int $userid The user id. + * @param int $submissionid The submission id. + * @param string $identifier The identifier. + * @param string $statuscode The status code. + * @param string $tiisubmissionid The Turnitin submission id. + * @param int $submitter The submitter. + * @param int $itemid The item id. + * @param string $submissiontype The submission type. + * @param int $attempt The attempt number. + * @param int $errorcode The error code. + * @param string $errormsg The error message. */ public function save_submission($cm, $userid, $submissionid, $identifier, $statuscode, $tiisubmissionid, $submitter, $itemid, $submissiontype, $attempt, $errorcode = null, $errormsg = null) { @@ -3039,6 +3112,10 @@ public function save_submission($cm, $userid, $submissionid, $identifier, $statu /** * Delete a submission from Turnitin + * + * @param object $cm The course module. + * @param int $submissionid The submission id. + * @param int $userid The user id. */ public function delete_tii_submission($cm, $submissionid, $userid) { global $DB; @@ -3079,6 +3156,9 @@ public function plagiarism_get_report_gen_speed_params() { /** * Set a config value for the admin settings. + * + * @param object $data The data to set. + * @param string $property The property to set. */ public static function plagiarism_set_config($data, $property) { // Scenario when performing the upgrade script to copy settings from V2 to PP. @@ -3099,7 +3179,7 @@ public static function plagiarism_set_config($data, $property) { * * @param moodleform $formwrapper * @param MoodleQuickForm $mform - * @return type + * @return void */ function plagiarism_turnitin_coursemodule_standard_elements($formwrapper, $mform) { $pluginturnitin = new plagiarism_plugin_turnitin(); @@ -3582,6 +3662,7 @@ function plagiarism_turnitin_tempfile(array $filename, $suffix) { * * @param string $input The error string if module = null otherwise the language string called by get_string() * @param string $module The module string + * @param string $link The link to redirect to * @param string $param The parameter to send to use as the $a optional object in get_string() * @param string $file The file where the error occured * @param string $line The line number where the error occured @@ -3617,6 +3698,9 @@ function plagiarism_turnitin_print_error($input, $module = 'plagiarism_turnitin' /** * Override Moodle's mtrace function for methods shared with tasks. + * + * @param string $string The string to output + * @param string $eol The end of line character */ function plagiarism_turnitin_mtrace($string, $eol) { return true; diff --git a/locallib.php b/locallib.php index a4aaeef7..fab220f7 100644 --- a/locallib.php +++ b/locallib.php @@ -25,7 +25,7 @@ /** * Override the repository option if necessary depending on the configuration setting. - * @param $submitpapersto int - The repository to submit to. + * @param int $submitpapersto - The repository to submit to. * @return $submitpapersto int - The repository to submit to. */ function plagiarism_turnitin_override_repository($submitpapersto) { @@ -50,9 +50,9 @@ function plagiarism_turnitin_override_repository($submitpapersto) { * Retrieve previously made successful submissions that match passed in parameters. This * avoids resubmitting them to Turnitin. * - * @param $author - * @param $cmid - * @param $identifier + * @param string $author The author of the submission. + * @param int $cmid The course module id. + * @param int $identifier The identifier of the submission. * @return $plagiarismfiles - an array of succesfully submitted submissions */ function plagiarism_turnitin_retrieve_successful_submissions($author, $cmid, $identifier) { @@ -73,7 +73,7 @@ function plagiarism_turnitin_retrieve_successful_submissions($author, $cmid, $id /** * Add a config field to show submissions have been made which we use to lock the anonymous marking setting. - * @param $cmid + * @param int $cmid The course module id. */ function plagiarism_turnitin_lock_anonymous_marking($cmid) { global $DB; diff --git a/tests/behat/behat_plagiarism_turnitin.php b/tests/behat/behat_plagiarism_turnitin.php index 59d10ecf..dd1e2c85 100644 --- a/tests/behat/behat_plagiarism_turnitin.php +++ b/tests/behat/behat_plagiarism_turnitin.php @@ -108,7 +108,7 @@ public function i_configure_turnitin_credentials() { * I create a unique user with username * * @Given I create a unique user with username :username - * @param $username + * @param string $username */ public function i_create_a_unique_user($username) { $generator = testing_util::get_data_generator(); @@ -246,6 +246,9 @@ public function i_accept_the_turnitin_eula_from_the_ev_if_necessary() { * @When /^I click save changes button "(?P(?:[^"]|\\")*)" "(?P[^"]*)"$/ * @param string $selector type of element like css or xpath * @param string $locator to identify element + * @param bool $exception + * @param bool $node + * @param bool $timeout */ public function click_save_changes_button($selector, $locator, $exception = false, $node = false, $timeout = false) { try { @@ -290,6 +293,8 @@ public function the_following_users_will_be_created_if_they_do_not_already_exist * phpcs:disable moodle.Files.LineLength.TooLong * @Given /^I unenroll the user account "(?P(?:[^"]|\\")*)" with the role "(?P(?:[^"]|\\")*)" from the class in Turnitin$/ * + * @param string $student + * @param string $role * @throws Exception */ public function i_unenroll_the_user_account_with_the_role_from_the_class_in_turnitin($student, $role) { diff --git a/tests/generator/lib.php b/tests/generator/lib.php index e02ff806..07c785f4 100644 --- a/tests/generator/lib.php +++ b/tests/generator/lib.php @@ -40,7 +40,7 @@ abstract class plagiarism_turnitin_test_lib extends advanced_testcase { * Creates a number of test plagiarism_turnitin users, creates an equivalent moodle user for each, and handles the database * association work. * - * @param int $number_of_users + * @param int $numberofusers - the number of users to create. * @param array $roles - an array of strings, each of which should be 'Learner' or 'Instructor'. * @return object $return - object of two arrays of equal length, one full of plagiarism_turnitin_user types and the other with * ids for dbtable plagiarism_turnitin_users. The indices of these arrays DO align. @@ -63,8 +63,8 @@ public function make_test_users($numberofusers, $roles) { /** * Creates a moodle user and a corresponding entry in the plagiarism_turnitin_users table * for the tii user specified - * @param object $plagiarism_turnitin_user - plagiarism_turnitin user object * + * @param object $plagiarismturnitinuser - plagiarism_turnitin user object * @return int $plagiarism_turnitin_user_id id of plagiarism_turnitin user join (for use in get_record queries on * plagiarism_turnitin_users table) */ diff --git a/tests/privacy/provider_test.php b/tests/privacy/provider_test.php index 8f5690b9..cb2a0371 100644 --- a/tests/privacy/provider_test.php +++ b/tests/privacy/provider_test.php @@ -198,7 +198,7 @@ public function test_delete_plagiarism_for_context(): void { /** * Create a submission for testing. * - * @param $numsubmissions + * @param int $numsubmissions * @return array * @throws \coding_exception * @throws \dml_exception From 80bb9924c051601eec11154e24591f7c2c5dfaca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luca=20B=C3=B6sch?= Date: Fri, 26 Jul 2024 12:38:04 +0200 Subject: [PATCH 11/15] Fixing PHPUnit tests. --- classes/forms/turnitin_setupform.class.php | 6 +- classes/turnitin_view.class.php | 60 +---- db/events.php | 2 +- lib.php | 230 +++++++----------- settings.php | 2 +- .../turnitin_assignment_class_test.php | 41 ++-- tests/classes/turnitin_user_class_test.php | 12 +- tests/generator/lib.php | 8 +- tests/lib_test.php | 34 +-- tests/locallib_test.php | 2 +- tests/modules/turnitin_assign_test.php | 8 +- tests/modules/turnitin_forum_test.php | 14 +- tests/modules/turnitin_quiz_test.php | 6 +- tests/privacy/provider_test.php | 10 +- tests/turnitin_test.php | 2 +- version.php | 3 + 16 files changed, 171 insertions(+), 269 deletions(-) diff --git a/classes/forms/turnitin_setupform.class.php b/classes/forms/turnitin_setupform.class.php index bfb3672a..1f03eaea 100644 --- a/classes/forms/turnitin_setupform.class.php +++ b/classes/forms/turnitin_setupform.class.php @@ -135,8 +135,10 @@ public function definition() { 'plagiarism_turnitin')); $mform->setDefault('plagiarism_turnitin_enablepeermark', 1); - $mform->addElement('select', 'plagiarism_turnitin_useanon', get_string('turnitinuseanon', 'plagiarism_turnitin'), $ynoptions); - $mform->addElement('static', 'plagiarism_turnitin_useanon_desc', null, get_string('turnitinuseanon_desc', 'plagiarism_turnitin')); + $mform->addElement('select', 'plagiarism_turnitin_useanon', get_string('turnitinuseanon', 'plagiarism_turnitin'), + $ynoptions); + $mform->addElement('static', 'plagiarism_turnitin_useanon_desc', null, + get_string('turnitinuseanon_desc', 'plagiarism_turnitin')); $mform->addElement('select', 'plagiarism_turnitin_useerater', get_string('turnitinuseerater', 'plagiarism_turnitin'), $ynoptions); diff --git a/classes/turnitin_view.class.php b/classes/turnitin_view.class.php index c63339ca..e68d6e53 100644 --- a/classes/turnitin_view.class.php +++ b/classes/turnitin_view.class.php @@ -135,8 +135,8 @@ public function add_elements_to_settings_form($mform, $course, $location = "acti $genparams = $plagiarismturnitin->plagiarism_get_report_gen_speed_params(); $genoptions = [0 => get_string('reportgen_immediate_add_immediate', 'plagiarism_turnitin'), 1 => get_string('reportgen_immediate_add_duedate', 'plagiarism_turnitin'), - 2 => get_string('reportgen_duedate_add_duedate', 'plagiarism_turnitin')); - $excludetypeoptions = array( 0 => get_string('no'), 1 => get_string('excludewords', 'plagiarism_turnitin'), + 2 => get_string('reportgen_duedate_add_duedate', 'plagiarism_turnitin'), ]; + $excludetypeoptions = [0 => get_string('no'), 1 => get_string('excludewords', 'plagiarism_turnitin'), 2 => get_string('excludepercent', 'plagiarism_turnitin'), ]; if ($location == "defaults") { @@ -155,7 +155,8 @@ public function add_elements_to_settings_form($mform, $course, $location = "acti $PAGE->requires->js_call_amd('plagiarism_turnitin/new_quickmark', 'newQuickmarkLaunch'); $PAGE->requires->js_call_amd('plagiarism_turnitin/new_rubric', 'newRubric'); } else { - // TODO: We can remove these when we no longer have to support Moodle versions 4.3 and below + // phpcs:disable moodle.Commenting.TodoComment + // TODO: We can remove these when we no longer have to support Moodle versions 4.3 and below. $PAGE->requires->js_call_amd('plagiarism_turnitin/peermark', 'peermarkLaunch'); $PAGE->requires->js_call_amd('plagiarism_turnitin/quickmark', 'quickmarkLaunch'); $PAGE->requires->js_call_amd('plagiarism_turnitin/rubric', 'rubric'); @@ -380,59 +381,6 @@ public function add_elements_to_settings_form($mform, $course, $location = "acti $mform->setType('plagiarism_rubric', PARAM_RAW); } -<<<<<<< HEAD -======= - if (!empty($config->plagiarism_turnitin_useerater)) { - $handbookoptions = [ - 1 => get_string('erater_handbook_advanced', 'plagiarism_turnitin'), - 2 => get_string('erater_handbook_highschool', 'plagiarism_turnitin'), - 3 => get_string('erater_handbook_middleschool', 'plagiarism_turnitin'), - 4 => get_string('erater_handbook_elementary', 'plagiarism_turnitin'), - 5 => get_string('erater_handbook_learners', 'plagiarism_turnitin'), - ]; - - $dictionaryoptions = [ - 'en_US' => get_string('erater_dictionary_enus', 'plagiarism_turnitin'), - 'en_GB' => get_string('erater_dictionary_engb', 'plagiarism_turnitin'), - 'en' => get_string('erater_dictionary_en', 'plagiarism_turnitin'), - ]; - $mform->addElement('select', 'plagiarism_erater', get_string('erater', 'plagiarism_turnitin'), $options); - $mform->setDefault('plagiarism_erater', 0); - - $mform->addElement('select', 'plagiarism_erater_handbook', get_string('erater_handbook', - 'plagiarism_turnitin'), - $handbookoptions); - $mform->setDefault('plagiarism_erater_handbook', 2); - $mform->disabledIf('plagiarism_erater_handbook', 'plagiarism_erater', 'eq', 0); - - $mform->addElement('select', 'plagiarism_erater_dictionary', get_string('erater_dictionary', - 'plagiarism_turnitin'), - $dictionaryoptions); - $mform->setDefault('plagiarism_erater_dictionary', 'en_US'); - $mform->disabledIf('plagiarism_erater_dictionary', 'plagiarism_erater', 'eq', 0); - - $mform->addElement('checkbox', 'plagiarism_erater_spelling', get_string('erater_categories', - 'plagiarism_turnitin'), - " ".get_string('erater_spelling', 'plagiarism_turnitin')); - $mform->disabledIf('plagiarism_erater_spelling', 'plagiarism_erater', 'eq', 0); - - $mform->addElement('checkbox', 'plagiarism_erater_grammar', '', " ".get_string('erater_grammar', - 'plagiarism_turnitin')); - $mform->disabledIf('plagiarism_erater_grammar', 'plagiarism_erater', 'eq', 0); - - $mform->addElement('checkbox', 'plagiarism_erater_usage', '', " ".get_string('erater_usage', - 'plagiarism_turnitin')); - $mform->disabledIf('plagiarism_erater_usage', 'plagiarism_erater', 'eq', 0); - - $mform->addElement('checkbox', 'plagiarism_erater_mechanics', '', " ". - get_string('erater_mechanics', 'plagiarism_turnitin')); - $mform->disabledIf('plagiarism_erater_mechanics', 'plagiarism_erater', 'eq', 0); - - $mform->addElement('checkbox', 'plagiarism_erater_style', '', " ".get_string('erater_style', - 'plagiarism_turnitin')); - $mform->disabledIf('plagiarism_erater_style', 'plagiarism_erater', 'eq', 0); - } - $mform->addElement('html', html_writer::tag('div', get_string('anonblindmarkingnote', 'plagiarism_turnitin'), ['class' => 'tii_anonblindmarkingnote'])); diff --git a/db/events.php b/db/events.php index 4b9fda14..2a1cab30 100644 --- a/db/events.php +++ b/db/events.php @@ -47,7 +47,7 @@ ], [ 'eventname' => '\mod_assign\event\submission_removed', - 'callback' => 'plagiarism_turnitin_observer::assignsubmission_removed' + 'callback' => 'plagiarism_turnitin_observer::assignsubmission_removed', ], [ 'eventname' => '\mod_coursework\event\assessable_uploaded', diff --git a/lib.php b/lib.php index 211ac5a0..cc88a482 100755 --- a/lib.php +++ b/lib.php @@ -321,10 +321,10 @@ public function add_settings_form_to_activity_page($mform, $context, $modulename if ($PAGE->pagetype != 'course-editbulkcompletion' && $PAGE->pagetype != 'course-editdefaultcompletion' && $PAGE->pagetype != 'course-defaultcompletion') { - - // Check for existing settings and add the form + // Check for existing settings and add the form. $course = turnitin_assignment::get_course_data($COURSE->id, "site"); - $turnitinview->add_elements_to_settings_form($mform, $course, "activity", $modulename, $cmid, $plagiarismvalues["plagiarism_rubric"]); + $turnitinview->add_elements_to_settings_form($mform, $course, "activity", $modulename, $cmid, + $plagiarismvalues["plagiarism_rubric"]); } $settingsdisplayed = true; @@ -590,7 +590,7 @@ public function load_page_components() { } $PAGE->requires->string_for_js('turnitin_score_refresh_alert', 'plagiarism_turnitin'); - + $PAGE->requires->js_call_amd('plagiarism_turnitin/open_viewer', 'origreport_open'); $PAGE->requires->js_call_amd('plagiarism_turnitin/open_viewer', 'grademark_open'); // Moodle 4.3 uses a new Modal dialog that is not compatible with older versions of Moodle. Depending on the user's @@ -745,8 +745,8 @@ public function get_links($linkarray) { // Work out if logged in user is a tutor on this activity module. static $istutor; if (empty($istutor)) { - $ctx_module = context_module::instance($cm->id); - $istutor = $moduleobject->is_tutor($ctx_module); + $ctxmodule = context_module::instance($cm->id); + $istutor = $moduleobject->is_tutor($ctxmodule); } // Define the timestamp for updating Peermark Assignments. @@ -990,7 +990,7 @@ public function get_links($linkarray) { $score = $plagiarismfile->similarityscore.'%'; $titlescore = $plagiarismfile->similarityscore.'% '.get_string('similarity', 'plagiarism_turnitin'); $roundup = function($n, $x=25) { - return (ceil($n)%$x === 0) ? ceil($n) : round(($n+$x/2)/$x)*$x; + return (ceil($n) % $x === 0) ? ceil($n) : round(($n + $x / 2) / $x) * $x; }; $class = 'score_colour_'.$roundup($plagiarismfile->similarityscore); @@ -1531,8 +1531,9 @@ private function update_submission($cm, $submissionid, $tiisubmission) { * @param object $cm The course module. * @param object $submission The submission object. * @param int $userid The user id. + * @param bool $cron Whether this is a cron job. */ - private function update_grade($cm, $submission, $userid, $cron = FALSE) { + private function update_grade($cm, $submission, $userid, $cron = false) { global $DB, $USER, $CFG; $return = true; @@ -1632,7 +1633,7 @@ private function update_grade($cm, $submission, $userid, $cron = FALSE) { $context = context_course::instance($cm->course); if (has_capability('mod/assign:grade', $context, $USER->id)) { // If the grade has changed and the change is not from a cron task then update the grader. - if ($currentgrade->grade != $grade->grade && $cron == FALSE) { + if ($currentgrade->grade != $grade->grade && $cron == false) { $grade->grader = $USER->id; } } @@ -1840,53 +1841,6 @@ public function refresh_peermark_assignments($cm, $tiiassignmentid) { } } - /** - * Check for rubric and save to assignment. - * - * @param object $cm The course module. - */ - public function update_rubric_from_tii($cm) { - global $DB; - - $turnitincomms = new turnitin_comms(); - $turnitincall = $turnitincomms->initialise_api(); - $assignment = new TiiAssignment(); - - if ($tiimoduledata = $DB->get_record('plagiarism_turnitin_config', - ['cm' => $cm->id, 'name' => 'turnitin_assignid'], 'value')) { - - $assignment->setAssignmentId($tiimoduledata->value); - - try { - // Retrieve assignment from Turnitin. - $response = $turnitincall->readAssignment($assignment); - $tiiassignment = $response->getAssignment(); - - // Create rubric config field with rubric value from Turnitin. - $rubricfield = new stdClass(); - $rubricfield->cm = $cm->id; - $rubricfield->name = 'plagiarism_rubric'; - $rubricfield->value = $tiiassignment->getRubricId(); - - // Check if rubric already exists for this module. - if ($configfield = $DB->get_field('plagiarism_turnitin_config', 'id', - (['cm' => $cm->id, 'name' => 'plagiarism_rubric']))) { - - // Use current configfield to update rubric value. - $rubricfield->id = $configfield; - - $DB->update_record('plagiarism_turnitin_config', $rubricfield); - } else { - // Otherwise create rubric entry for this module. - $rubricfield->config_hash = $rubricfield->cm."_".$rubricfield->name; - $DB->create_record('plagiarism_turnitin_config', $rubricfield); - } - } catch (Exception $e) { - $turnitincomms->handle_exceptions($e, 'tiiassignmentgeterror', false); - } - } - } - /** * Create the module as an assignment within Turnitin if it does not exist, * if we have a Turnitin id for the module then edit it @@ -1984,12 +1938,12 @@ public function sync_tii_assignment($cm, $coursetiiid, $workflowcontext = "site" $dtpost = 0; if ($cm->modname != "forum") { if ($gradeitem = $DB->get_record( - 'grade_items', - [ - 'iteminstance' => $cm->instance, - 'itemmodule' => $cm->modname, - 'courseid' => $cm->course, - 'itemnumber' => 0, ] + 'grade_items', + [ + 'iteminstance' => $cm->instance, + 'itemmodule' => $cm->modname, + 'courseid' => $cm->course, + 'itemnumber' => 0, ] )) { switch ($gradeitem->hidden) { @@ -2058,24 +2012,6 @@ public function sync_tii_assignment($cm, $coursetiiid, $workflowcontext = "site" $assignment->setFeedbackReleaseDate(gmdate("Y-m-d\TH:i:s\Z", $dtpost)); - // Erater settings. - $assignment->setErater((isset($modulepluginsettings["plagiarism_erater"])) ? - $modulepluginsettings["plagiarism_erater"] : 0); - $assignment->setEraterSpelling((isset($modulepluginsettings["plagiarism_erater_spelling"])) ? - $modulepluginsettings["plagiarism_erater_spelling"] : 0); - $assignment->setEraterGrammar((isset($modulepluginsettings["plagiarism_erater_grammar"])) ? - $modulepluginsettings["plagiarism_erater_grammar"] : 0); - $assignment->setEraterUsage((isset($modulepluginsettings["plagiarism_erater_usage"])) ? - $modulepluginsettings["plagiarism_erater_usage"] : 0); - $assignment->setEraterMechanics((isset($modulepluginsettings["plagiarism_erater_mechanics"])) ? - $modulepluginsettings["plagiarism_erater_mechanics"] : 0); - $assignment->setEraterStyle((isset($modulepluginsettings["plagiarism_erater_style"])) ? - $modulepluginsettings["plagiarism_erater_style"] : 0); - $assignment->setEraterSpellingDictionary((isset($modulepluginsettings["plagiarism_erater_dictionary"])) ? - $modulepluginsettings["plagiarism_erater_dictionary"] : 'en_US'); - $assignment->setEraterHandbook((isset($modulepluginsettings["plagiarism_erater_handbook"])) ? - $modulepluginsettings["plagiarism_erater_handbook"] : 0); - // If we have a turnitin id then edit the assignment otherwise create it. if ($tiiassignment = $DB->get_record('plagiarism_turnitin_config', ['cm' => $cm->id, 'name' => 'turnitin_assignid'], 'value')) { @@ -2107,6 +2043,53 @@ public function sync_tii_assignment($cm, $coursetiiid, $workflowcontext = "site" } } + /** + * Check for rubric and save to assignment. + * + * @param object $cm The course module. + */ + public function update_rubric_from_tii($cm) { + global $DB; + + $turnitincomms = new turnitin_comms(); + $turnitincall = $turnitincomms->initialise_api(); + $assignment = new TiiAssignment(); + + if ($tiimoduledata = $DB->get_record('plagiarism_turnitin_config', + ['cm' => $cm->id, 'name' => 'turnitin_assignid'], 'value')) { + + $assignment->setAssignmentId($tiimoduledata->value); + + try { + // Retrieve assignment from Turnitin. + $response = $turnitincall->readAssignment($assignment); + $tiiassignment = $response->getAssignment(); + + // Create rubric config field with rubric value from Turnitin. + $rubricfield = new stdClass(); + $rubricfield->cm = $cm->id; + $rubricfield->name = 'plagiarism_rubric'; + $rubricfield->value = $tiiassignment->getRubricId(); + + // Check if rubric already exists for this module. + if ($configfield = $DB->get_field('plagiarism_turnitin_config', 'id', + (['cm' => $cm->id, 'name' => 'plagiarism_rubric']))) { + + // Use current configfield to update rubric value. + $rubricfield->id = $configfield; + + $DB->update_record('plagiarism_turnitin_config', $rubricfield); + } else { + // Otherwise create rubric entry for this module. + $rubricfield->config_hash = $rubricfield->cm."_".$rubricfield->name; + $DB->create_record('plagiarism_turnitin_config', $rubricfield); + } + } catch (Exception $e) { + $turnitincomms->handle_exceptions($e, 'tiiassignmentgeterror', false); + } + } + } + /** * Updates the database field duedate_report_refresh for any given submission ID. * @param int $id - the ID of the submission to update. @@ -2129,17 +2112,16 @@ public function set_duedate_report_refresh($id, $newvalue) { public function cron_update_scores() { global $DB; -<<<<<<< HEAD - $submissionids = array(); - $reportsexpected = array(); - $assignmentids = array(); - + $submissionids = []; + $reportsexpected = []; + $assignmentids = []; + // Grab all plagiarism files where all the following conditions are met: // 1. The file has been successfully sent to TII // 2. The submission is ready to recieve a similarity score (either it doesn't already have a similarity score or it's set to regenerate) // 3. The course or activity module associated with the submission hasn't been deleted $submissions = $DB->get_records_sql( - 'SELECT PTF.*, + 'SELECT PTF.*, CM.instance AS instance, M.name AS modname FROM {plagiarism_turnitin_files} PTF @@ -2150,34 +2132,21 @@ public function cron_update_scores() { AND ( orcapable = ? OR orcapable IS NULL ) ORDER BY externalid DESC', ['success', 1] -======= - $submissionids = []; - $reportsexpected = []; - $assignmentids = []; - - $submissions = $DB->get_records_select( - 'plagiarism_turnitin_files', - 'statuscode = ? - AND ( similarityscore IS NULL OR duedate_report_refresh = 1 ) - AND ( orcapable = ? OR orcapable IS NULL ) ', - ['success', 1], - 'externalid DESC' ->>>>>>> 796b5bd (Fix 'Short array syntax must be used to define arrays' warnings.) ); // Cache module settings $modulesettings = []; foreach ($submissions as $tiisubmission) { - if (!array_key_exists($tiisubmission->cm, $modulesettings)) { - $modulesettings[$tiisubmission->cm] = $this->get_settings($tiisubmission->cm); - } + if (!array_key_exists($tiisubmission->cm, $modulesettings)) { + $modulesettings[$tiisubmission->cm] = $this->get_settings($tiisubmission->cm); + } } // Cache module data $moduledata = []; foreach ($submissions as $submission) { if (!array_key_exists($tiisubmission->modname, $moduledata)) { - $moduledata[$tiisubmission->modname] = $DB->get_record($tiisubmission->modname, array('id' => $tiisubmission->instance)); + $moduledata[$tiisubmission->modname] = $DB->get_record($tiisubmission->modname, ['id' => $tiisubmission->instance]); } } @@ -2192,19 +2161,10 @@ public function cron_update_scores() { if (!isset($reportsexpected[$tiisubmission->cm])) { -<<<<<<< HEAD $reportsexpected[$tiisubmission->cm] = 1; if (!isset($modulesettings[$tiisubmission->cm]['plagiarism_compare_institution'])) { $modulesettings[$tiisubmission->cm]['plagiarism_compare_institution'] = 0; -======= - // Updates the db field 'duedate_report_refresh' if the due date has passed within the last twenty four hours. - $moduledata = $DB->get_record($cm->modname, ['id' => $cm->instance]); - $now = strtotime('now'); - $dtdue = (!empty($moduledata->duedate)) ? $moduledata->duedate : 0; - if ($now >= $dtdue && $now < strtotime('+1 day', $dtdue)) { - $this->set_duedate_report_refresh($tiisubmission->id, 1); ->>>>>>> 796b5bd (Fix 'Short array syntax must be used to define arrays' warnings.) } // Don't add the submission to the request if module settings mean we will not get a report back. @@ -2221,26 +2181,12 @@ public function cron_update_scores() { if ($reportsexpected[$tiisubmission->cm] == 1) { $submissionids[] = $tiisubmission->externalid; -<<<<<<< HEAD // If submission is added to the request, add the corresponding assign id in the assignids array. $moduleturnitinconfig = $DB->get_record('plagiarism_turnitin_config', [ 'cm' => $tiisubmission->cm, 'name' => 'turnitin_assignid' ]); - + if (!isset(array_flip($assignmentids)[$moduleturnitinconfig->value])) { $assignmentids[] = $moduleturnitinconfig->value; -======= - // If submission is added to the request, add the corresponding assign id in the assignids array. - $moduleturnitinconfig = $DB->get_record('plagiarism_turnitin_config', - [ - 'cm' => $cm->id, - 'name' => 'turnitin_assignid', - ] - ); - - if (!isset(array_flip($assignmentids)[$moduleturnitinconfig->value])) { - $assignmentids[] = $moduleturnitinconfig->value; - } ->>>>>>> 796b5bd (Fix 'Short array syntax must be used to define arrays' warnings.) } } } @@ -2313,7 +2259,7 @@ public function cron_update_scores() { // At the moment TII doesn't support double marking so we won't synchronise grades from Grade Mark // as it would destroy the workflow. if (!is_null($plagiarismfile->grade) && $cm->modname != "coursework") { - $this->update_grade($cm, $readsubmission, $currentsubmission->userid, TRUE); + $this->update_grade($cm, $readsubmission, $currentsubmission->userid, true); } } } catch (Exception $e) { @@ -2840,21 +2786,15 @@ public function event_handler($eventdata) { $submissiontype = ($cm->modname == 'forum') ? 'forum_post' : 'text_content'; -<<<<<<< HEAD // The content inside the event data will not always correspond to the content we will look up later, e.g. // because URLs have been converted to use @@PLUGINFILE@@ etc. Therefore to calculate the same hash, we need to // do a lookup to get the file content -======= - // phpcs:disable PSR2.Methods.MethodDeclaration.Underscore,moodle.Commenting.TodoComment - // TODO: Check eventdata to see if content is included correctly. If so, this can be removed. ->>>>>>> f6223b8 (Fixes for remaining errors/warnings.) if ($cm->modname == 'workshop') { $moodlesubmission = $DB->get_record('workshop_submissions', ['id' => $eventdata['objectid']]); $eventdata['other']['content'] = $moodlesubmission->content; - } - else if ($cm->modname == 'forum') { - $moodlesubmission = $DB->get_record('forum_posts', array('id' => $eventdata['objectid'])); - $eventdata['other']['content'] = $moodlesubmission->message; + } else if ($cm->modname == 'forum') { + $moodlesubmission = $DB->get_record('forum_posts', ['id' => $eventdata['objectid']]); + $eventdata['other']['content'] = $moodlesubmission->message; } $identifier = sha1($eventdata['other']['content']); @@ -3256,16 +3196,16 @@ function plagiarism_turnitin_send_queued_submissions() { // Create module object. if (empty($cm->modname)) { - $pluginturnitin->save_errored_submission($queueditem->id, $queueditem->attempt, 15); + $pluginturnitin->save_errored_submission($queueditem->id, $queueditem->attempt, 15); - // Output a message in the cron for failed submission to Turnitin. - $outputvars = new stdClass(); - $outputvars->id = $queueditem->id; - $outputvars->cm = $queueditem->cm; - $outputvars->userid = $queueditem->userid; + // Output a message in the cron for failed submission to Turnitin. + $outputvars = new stdClass(); + $outputvars->id = $queueditem->id; + $outputvars->cm = $queueditem->cm; + $outputvars->userid = $queueditem->userid; - plagiarism_turnitin_activitylog(get_string('errorcode15', 'plagiarism_turnitin', $outputvars), "PP_NO_ACTIVITY_MODULE"); - continue; + plagiarism_turnitin_activitylog(get_string('errorcode15', 'plagiarism_turnitin', $outputvars), "PP_NO_ACTIVITY_MODULE"); + continue; } $moduleclass = "turnitin_".$cm->modname; $moduleobject = new $moduleclass; diff --git a/settings.php b/settings.php index 3a4013df..5d0bee6b 100644 --- a/settings.php +++ b/settings.php @@ -111,7 +111,7 @@ // Include Javascript & CSS. if ($do == "errors" || $do == "config" || $do == "unlinkusers") { $PAGE->requires->js_call_amd('plagiarism_turnitin/plugin_settings', 'pluginSettings'); - + // Strings for JS. $PAGE->requires->string_for_js('connecttest', 'plagiarism_turnitin'); $PAGE->requires->string_for_js('connecttestsuccess', 'plagiarism_turnitin'); diff --git a/tests/classes/turnitin_assignment_class_test.php b/tests/classes/turnitin_assignment_class_test.php index 68accc86..26ff7f44 100644 --- a/tests/classes/turnitin_assignment_class_test.php +++ b/tests/classes/turnitin_assignment_class_test.php @@ -36,13 +36,14 @@ * * @package turnitin */ -final class turnitin_assignment_class_test extends advanced_testcase { +final class turnitin_assignment_class_test extends \advanced_testcase { /** * Set Overwrite mtrace to avoid output during the tests. */ public function setUp(): void { global $CFG; + parent::setUp(); // Overwrite mtrace. $CFG->mtrace_wrapper = 'plagiarism_turnitin_mtrace'; @@ -61,7 +62,7 @@ public function test_get_course_data(): void { $this->resetAfterTest(); // Create a PP course. - $course = new stdClass(); + $course = new \stdClass(); $course->courseid = 1; $course->turnitin_ctl = "Test Course"; $course->turnitin_cid = 10; @@ -69,7 +70,7 @@ public function test_get_course_data(): void { // Insert the course to the plagiarism turnitin courses table. $DB->insert_record('plagiarism_turnitin_courses', $course); - $response = turnitin_assignment::get_course_data(1, "site"); + $response = \turnitin_assignment::get_course_data(1, "site"); $this->assertEquals($course->turnitin_ctl, $response->turnitin_ctl); $this->assertEquals($course->turnitin_cid, $response->turnitin_cid); @@ -88,7 +89,7 @@ public function test_create_tii_course(): void { $this->resetAfterTest(); // Create a PP course. - $course = new stdClass(); + $course = new \stdClass(); $course->courseid = 1; $course->turnitin_ctl = "Test Course"; $course->turnitin_cid = 10; @@ -99,7 +100,7 @@ public function test_create_tii_course(): void { $course->id = $DB->insert_record('plagiarism_turnitin_courses', $course); // Stub a fake tii comms. - $faketiicomms = $this->getMockBuilder(turnitin_comms::class) + $faketiicomms = $this->getMockBuilder(\turnitin_comms::class) ->disableOriginalConstructor() ->getMock(); @@ -119,7 +120,7 @@ public function test_create_tii_course(): void { $response = $mock->create_tii_course($course, 1); - $expected = new stdClass(); + $expected = new \stdClass(); $expected->id = $course->tii_rel_id; $expected->turnitin_cid = 1; $expected->turnitin_ctl = "This is a test course (Moodle PP)"; @@ -147,7 +148,7 @@ public function test_edit_tii_course(): void { $this->resetAfterTest(); // Create a PP course. - $course = new stdClass(); + $course = new \stdClass(); $course->courseid = 1; $course->turnitin_ctl = "Test Course"; $course->turnitin_cid = 1; @@ -158,7 +159,7 @@ public function test_edit_tii_course(): void { $course->id = $DB->insert_record('plagiarism_turnitin_courses', $course); // Stub a fake tii comms. - $faketiicomms = $this->getMockBuilder(turnitin_comms::class) + $faketiicomms = $this->getMockBuilder(\turnitin_comms::class) ->disableOriginalConstructor() ->getMock(); @@ -173,7 +174,7 @@ public function test_edit_tii_course(): void { ->getMock(); // Edit a PP course. - $editcourse = new stdClass(); + $editcourse = new \stdClass(); $editcourse->id = 1; $editcourse->turnitin_cid = 10; $editcourse->fullname = "This is an edited test course"; @@ -184,7 +185,7 @@ public function test_edit_tii_course(): void { $responsecourse = $DB->get_record("plagiarism_turnitin_courses", ["id" => $course->id]); - $expected = new stdClass(); + $expected = new \stdClass(); $expected->id = $course->id; $expected->courseid = $course->courseid; $expected->turnitin_ctl = "This is an edited test course (Moodle PP)"; @@ -206,12 +207,12 @@ public function test_truncate_title(): void { $title = "This is a very long title that we are going to use to test the truncate title method."; $limit = 50; - $response = turnitin_assignment::truncate_title($title, $limit); + $response = \turnitin_assignment::truncate_title($title, $limit); $this->assertEquals('This is a very long title that we a... (Moodle PP)', $response); // Try a title that is within our limit. - $response = turnitin_assignment::truncate_title("This title should not be truncated.", $limit); + $response = \turnitin_assignment::truncate_title("This title should not be truncated.", $limit); $this->assertEquals('This title should not be truncated. (Moodle PP)', $response); } @@ -225,11 +226,11 @@ public function test_create_tii_assignment(): void { $this->resetAfterTest(); // Create a PP assignment. - $assignment = new stdClass(); + $assignment = new \stdClass(); $assignment->id = 1; // Stub a fake tii comms. - $faketiicomms = $this->getMockBuilder(turnitin_comms::class) + $faketiicomms = $this->getMockBuilder(\turnitin_comms::class) ->disableOriginalConstructor() ->getMock(); @@ -264,12 +265,12 @@ public function test_edit_tii_assignment(): void { $this->resetAfterTest(); // Create a PP assignment. - $assignment = new stdClass(); + $assignment = new \stdClass(); $assignment->id = 1; $assignment->title = "This is a test assignment."; // Stub a fake tii comms. - $faketiicomms = $this->getMockBuilder(turnitin_comms::class) + $faketiicomms = $this->getMockBuilder(\turnitin_comms::class) ->disableOriginalConstructor() ->getMock(); @@ -305,14 +306,14 @@ public function test_edit_tii_assignment(): void { // Test the exception handling for default workflow. $mock->expects($this->any()) ->method('api_update_assignment') - ->will($this->throwException(new Exception())); + ->will($this->throwException(new \Exception())); $response = $mock->edit_tii_assignment($assignment); $this->assertEquals(false, $response["success"]); $this->assertEquals(get_string('editassignmenterror', 'plagiarism_turnitin'), $response["error"]); // Test the error handling for the cron workflow. - $error = new stdClass(); + $error = new \stdClass(); $error->title = $assignment->title; $error->assignmentid = 1; @@ -335,7 +336,7 @@ public function test_get_peermark_assignments(): void { $this->resetAfterTest(); // Create a PP course. - $peermark = new stdClass(); + $peermark = new \stdClass(); $peermark->parent_tii_assign_id = 1; $peermark->title = "This is a test Peermark assignment."; $peermark->tiiassignid = 1; @@ -347,7 +348,7 @@ public function test_get_peermark_assignments(): void { // Insert the peermark to the plagiarism turnitin courses table. $DB->insert_record('plagiarism_turnitin_peermark', $peermark); - $assignment = new turnitin_assignment(0, 1); + $assignment = new \turnitin_assignment(0, 1); // We should have a peermark object. $response = $assignment->get_peermark_assignments(1, $peermark->parent_tii_assign_id); diff --git a/tests/classes/turnitin_user_class_test.php b/tests/classes/turnitin_user_class_test.php index e3b9c534..8ebb36f6 100644 --- a/tests/classes/turnitin_user_class_test.php +++ b/tests/classes/turnitin_user_class_test.php @@ -48,6 +48,8 @@ final class turnitin_user_class_test extends plagiarism_turnitin_test_lib { * Set Overwrite mtrace to avoid output during the tests. */ public function setUp(): void { + parent::setUp(); + // Stub a fake tii comms. $this->faketiicomms = $this->getMockBuilder(turnitin_comms::class) ->disableOriginalConstructor() @@ -65,7 +67,7 @@ public function test_get_moodle_user(): void { $student = $this->getDataGenerator()->create_user(); - $turnitinuser = new turnitin_user(0, null, null, null, null); + $turnitinuser = new \turnitin_user(0, null, null, null, null); $response = $turnitinuser->get_moodle_user($student->id); // Check that we have an object back with user details. No need to check all params. @@ -82,7 +84,7 @@ public function test_get_moodle_user(): void { public function test_get_pseudo_domain(): void { $this->resetAfterTest(); - $response = turnitin_user::get_pseudo_domain(); + $response = \turnitin_user::get_pseudo_domain(); $this->assertEquals(PLAGIARISM_TURNITIN_DEFAULT_PSEUDO_DOMAIN, $response); } @@ -95,7 +97,7 @@ public function test_get_pseudo_domain(): void { public function test_get_pseudo_firstname(): void { $this->resetAfterTest(); - $turnitinuser = new turnitin_user(0, null, null, null, null); + $turnitinuser = new \turnitin_user(0, null, null, null, null); $response = $turnitinuser->get_pseudo_firstname(); $this->assertEquals(PLAGIARISM_TURNITIN_DEFAULT_PSEUDO_FIRSTNAME, $response); } @@ -117,7 +119,7 @@ public function test_get_pseudo_lastname(): void { set_config('plagiarism_turnitin_pseudolastname', 1, 'plagiarism_turnitin'); set_config('plagiarism_turnitin_lastnamegen', 1, 'plagiarism_turnitin'); - $turnitinuser = new turnitin_user($student->id, null, null, null, null); + $turnitinuser = new \turnitin_user($student->id, null, null, null, null); $response = $turnitinuser->get_pseudo_lastname(); $this->assertEquals(PLAGIARISM_TURNITIN_DEFAULT_PSEUDO_FIRSTNAME, $response); } @@ -142,7 +144,7 @@ public function test_unlink_user(): void { $this->assertEquals(1, $count); // Unlink the user. - $turnitinuser = new turnitin_user(0, null, null, null, null); + $turnitinuser = new \turnitin_user(0, null, null, null, null); $turnitinuser->unlink_user($testuser["joins"][0]); // We should have a Turnitin user ID of 0. diff --git a/tests/generator/lib.php b/tests/generator/lib.php index 07c785f4..9f11b019 100644 --- a/tests/generator/lib.php +++ b/tests/generator/lib.php @@ -14,6 +14,8 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . +namespace plagiarism_turnitin; + defined('MOODLE_INTERNAL') || die(); global $CFG; global $DB; @@ -34,7 +36,7 @@ * @copyright 2017 Turnitin * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -abstract class plagiarism_turnitin_test_lib extends advanced_testcase { +abstract class plagiarism_turnitin_test_lib extends \advanced_testcase { /** * Creates a number of test plagiarism_turnitin users, creates an equivalent moodle user for each, and handles the database @@ -51,7 +53,7 @@ public function make_test_users($numberofusers, $roles) { for ($i = 0; $i < $numberofusers; $i++) { $role = isset($roles[$i]) ? $roles[$i] : 'Instructor'; - $newuser = new turnitin_user( $i + 1, $role, false, 'site', false ); + $newuser = new \turnitin_user( $i + 1, $role, false, 'site', false ); array_push($return['plagiarism_turnitin_users'], $newuser); $joinid = $this->join_test_user($newuser); array_push($return['joins'], $joinid); @@ -72,7 +74,7 @@ public function join_test_user($plagiarismturnitinuser) { global $DB; $mdluser = $this->getDataGenerator()->create_user(); - $tiiuserrecord = new stdClass(); + $tiiuserrecord = new \stdClass(); $tiiuserrecord->userid = $mdluser->id; $tiiuserrecord->turnitin_uid = $plagiarismturnitinuser->id; $tiiuserrecord->user_agreement_accepted = 1; diff --git a/tests/lib_test.php b/tests/lib_test.php index 4bf3b045..4c0d11b0 100644 --- a/tests/lib_test.php +++ b/tests/lib_test.php @@ -35,7 +35,7 @@ * * @package turnitin */ -final class lib_test extends advanced_testcase { +final class lib_test extends \advanced_testcase { /** * Test that the plugin is configured correctly. @@ -46,7 +46,7 @@ final class lib_test extends advanced_testcase { public function test_is_plugin_configured(): void { $this->resetAfterTest(); - $plagiarismturnitin = new plagiarism_plugin_turnitin(); + $plagiarismturnitin = new \plagiarism_plugin_turnitin(); // Check if plugin is configured with no plugin config set. $ispluginconfigured = $plagiarismturnitin->is_plugin_configured(); @@ -91,8 +91,8 @@ public function test_check_group_submission(): void { $course = $result['course']; $group = $this->getDataGenerator()->create_group(['courseid' => $course->id]); $cm = get_coursemodule_from_instance('assign', $assignmodule->id); - $context = context_module::instance($cm->id); - $assign = new testable_assign($context, $cm, $course); + $context = \context_module::instance($cm->id); + $assign = new \testable_assign($context, $cm, $course); groups_add_member($group, $student); @@ -100,14 +100,14 @@ public function test_check_group_submission(): void { $submission = $assign->get_group_submission($student->id, $group->id, true); $submission->status = ASSIGN_SUBMISSION_STATUS_SUBMITTED; $assign->testable_update_submission($submission, $student->id, true, false); - $data = new stdClass(); + $data = new \stdClass(); $data->onlinetext_editor = ['itemid' => file_get_unused_draft_itemid(), 'text' => 'Submission text', 'format' => FORMAT_MOODLE, ]; $plugin = $assign->get_submission_plugin_by_type('onlinetext'); $plugin->save($submission, $data); - $plagiarismturnitin = new plagiarism_plugin_turnitin(); + $plagiarismturnitin = new \plagiarism_plugin_turnitin(); $response = $plagiarismturnitin->check_group_submission($cm, $student->id); // Test should pass as we return the correct group ID. @@ -122,21 +122,21 @@ public function test_check_group_submission(): void { $student = $result['student']; $course = $result['course']; $cm = get_coursemodule_from_instance('assign', $assignmodule->id); - $context = context_module::instance($cm->id); - $assign = new testable_assign($context, $cm, $course); + $context = \context_module::instance($cm->id); + $assign = new \testable_assign($context, $cm, $course); $this->setUser($student); $submission = $assign->get_user_submission($student->id, true); $submission->status = ASSIGN_SUBMISSION_STATUS_SUBMITTED; $assign->testable_update_submission($submission, $student->id, true, false); - $data = new stdClass(); + $data = new \stdClass(); $data->onlinetext_editor = ['itemid' => file_get_unused_draft_itemid(), 'text' => 'Submission text', 'format' => FORMAT_MOODLE, ]; $plugin = $assign->get_submission_plugin_by_type('onlinetext'); $plugin->save($submission, $data); - $plagiarismturnitin = new plagiarism_plugin_turnitin(); + $plagiarismturnitin = new \plagiarism_plugin_turnitin(); $response = $plagiarismturnitin->check_group_submission($cm, $student->id); // Test should pass as we return false when checking the group ID. @@ -164,7 +164,7 @@ public function create_assign_with_student_and_teacher($params = []) { $assign = $this->getDataGenerator()->create_module('assign', $params); $cm = get_coursemodule_from_instance('assign', $assign->id); - $context = context_module::instance($cm->id); + $context = \context_module::instance($cm->id); $student = $this->getDataGenerator()->create_user(); $studentrole = $DB->get_record('role', ['shortname' => 'student']); @@ -194,11 +194,11 @@ public function create_assign_with_student_and_teacher($params = []) { public function test_plagiarism_get_report_gen_speed_params(): void { $this->resetAfterTest(); - $expected = new stdClass(); + $expected = new \stdClass(); $expected->num_resubmissions = 3; $expected->num_hours = 24; - $plagiarismturnitin = new plagiarism_plugin_turnitin(); + $plagiarismturnitin = new \plagiarism_plugin_turnitin(); $response = $plagiarismturnitin->plagiarism_get_report_gen_speed_params(); $this->assertEquals($expected, $response); @@ -212,10 +212,10 @@ public function test_plagiarism_get_report_gen_speed_params(): void { public function test_plagiarism_set_config(): void { $this->resetAfterTest(); - $plagiarismturnitin = new plagiarism_plugin_turnitin(); + $plagiarismturnitin = new \plagiarism_plugin_turnitin(); // Check that we can set config value when a full property name is given. - $data = new stdClass(); + $data = new \stdClass(); $data->plagiarism_turnitin_accountid = 123456789; $property = "plagiarism_turnitin_accountid"; @@ -227,7 +227,7 @@ public function test_plagiarism_set_config(): void { $this->assertEquals(123456789, $config->plagiarism_turnitin_accountid); // Check that we can set config value when a partial property name is given. - $data = new stdClass(); + $data = new \stdClass(); $data->secretkey = "Test"; $property = "secretkey"; $plagiarismturnitin->plagiarism_set_config($data, $property); @@ -238,7 +238,7 @@ public function test_plagiarism_set_config(): void { $this->assertEquals("Test", $config->plagiarism_turnitin_secretkey); // Check that an undefined property does not set a config value. - $data = new stdClass(); + $data = new \stdClass(); $data->test = "Test"; $property = "NotTest"; $plagiarismturnitin->plagiarism_set_config($data, $property); diff --git a/tests/locallib_test.php b/tests/locallib_test.php index b8a3eb82..97e55b0f 100644 --- a/tests/locallib_test.php +++ b/tests/locallib_test.php @@ -35,7 +35,7 @@ * * @package turnitin */ -final class locallib_test extends advanced_testcase { +final class locallib_test extends \advanced_testcase { /** * Test that we have the correct repository depending on the config settings. diff --git a/tests/modules/turnitin_assign_test.php b/tests/modules/turnitin_assign_test.php index 471e95ff..1f71671a 100644 --- a/tests/modules/turnitin_assign_test.php +++ b/tests/modules/turnitin_assign_test.php @@ -35,7 +35,7 @@ * * @package turnitin */ -final class turnitin_assign_test extends advanced_testcase { +final class turnitin_assign_test extends \advanced_testcase { /** @var stdClass created in setUp. */ protected $course; @@ -47,6 +47,8 @@ final class turnitin_assign_test extends advanced_testcase { * Create a course and assignment module instance */ public function setUp(): void { + parent::setUp(); + $this->course = $this->getDataGenerator()->create_course(); $params = [ 'course' => $this->course->id, @@ -68,7 +70,7 @@ public function test_check_is_resubmission_allowed(): void { $this->resetAfterTest(true); // Create module object. - $moduleobject = new turnitin_assign(); + $moduleobject = new \turnitin_assign(); $resubmissionallowed = $moduleobject->is_resubmission_allowed($this->assign->id, 1, 'file', ASSIGN_ATTEMPT_REOPEN_METHOD_NONE); @@ -115,7 +117,7 @@ public function test_check_is_resubmission_allowed_maxfiles_above_threshold(): v $assign = $this->getDataGenerator()->create_module('assign', $params); // Create module object. - $moduleobject = new turnitin_assign(); + $moduleobject = new \turnitin_assign(); $resubmissionallowed = $moduleobject->is_resubmission_allowed($assign->id, 1, 'file', ASSIGN_ATTEMPT_REOPEN_METHOD_NONE); $this->assertFalse($resubmissionallowed); diff --git a/tests/modules/turnitin_forum_test.php b/tests/modules/turnitin_forum_test.php index f111a8c9..c26a1002 100644 --- a/tests/modules/turnitin_forum_test.php +++ b/tests/modules/turnitin_forum_test.php @@ -34,7 +34,7 @@ * * @package turnitin */ -final class turnitin_forum_test extends advanced_testcase { +final class turnitin_forum_test extends \advanced_testcase { /** @var stdClass created in setUp. */ protected $forum; @@ -49,22 +49,24 @@ final class turnitin_forum_test extends advanced_testcase { * Create a course and forum module instance */ public function setUp(): void { + parent::setUp(); + // Create a course, user and a forum. $course = $this->getDataGenerator()->create_course(); $user = $this->getDataGenerator()->create_user(); - $record = new stdClass(); + $record = new \stdClass(); $record->course = $course->id; $this->forum = $this->getDataGenerator()->create_module('forum', $record); // Add discussion to course. - $record = new stdClass(); + $record = new \stdClass(); $record->course = $course->id; $record->userid = $user->id; $record->forum = $this->forum->id; $this->discussion = $this->getDataGenerator()->get_plugin_generator('mod_forum')->create_discussion($record); // Add post to discussion. - $record = new stdClass(); + $record = new \stdClass(); $record->course = $course->id; $record->userid = $user->id; $record->forum = $this->forum->id; @@ -82,7 +84,7 @@ public function test_to_check_content_in_array_is_returned_by_set_content(): voi $this->resetAfterTest(true); // Create module object. - $moduleobject = new turnitin_forum(); + $moduleobject = new \turnitin_forum(); $params = [ 'content' => $this->post->message, @@ -103,7 +105,7 @@ public function test_to_check_content_from_database_is_returned_by_set_content_i $this->resetAfterTest(true); // Create module object. - $moduleobject = new turnitin_forum(); + $moduleobject = new \turnitin_forum(); $params = [ 'content' => 'content should not come back', diff --git a/tests/modules/turnitin_quiz_test.php b/tests/modules/turnitin_quiz_test.php index f4309d02..223eb227 100644 --- a/tests/modules/turnitin_quiz_test.php +++ b/tests/modules/turnitin_quiz_test.php @@ -36,7 +36,7 @@ * @package plagiarism_turnitin * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -final class turnitin_quiz_test extends advanced_testcase { +final class turnitin_quiz_test extends \advanced_testcase { /** * Proves that essay response marks are correctly updated. * @@ -67,7 +67,7 @@ public function test_update_mark(): void { } $quizobj = $quizsettingsclass::create($quiz->id, $user->id); - $quba = question_engine::make_questions_usage_by_activity('mod_quiz', $quizobj->get_context()); + $quba = \question_engine::make_questions_usage_by_activity('mod_quiz', $quizobj->get_context()); $quba->set_preferred_behaviour($quizobj->get_quiz()->preferredbehaviour); $questiongenerator = $this->getDataGenerator()->get_plugin_generator('core_question'); @@ -90,7 +90,7 @@ public function test_update_mark(): void { $this->assertEquals(0.0, $grade); // Now update the grade of the essay question through the Turnitin quiz class. - $tiiquiz = new turnitin_quiz; + $tiiquiz = new \turnitin_quiz; $answer = $attemptobj->get_question_attempt(1)->get_response_summary(); $slot = 1; $identifier = sha1($answer.$slot); diff --git a/tests/privacy/provider_test.php b/tests/privacy/provider_test.php index cb2a0371..19a90cb3 100644 --- a/tests/privacy/provider_test.php +++ b/tests/privacy/provider_test.php @@ -49,13 +49,13 @@ final class provider_test extends \core_privacy\tests\provider_testcase { /** * Test for _get_metadata shim. * - * @covers \core_plagiarism\privacy\legacy_polyfill::get_metadata + * @covers \core_plagiarism\privacy\legacy_polyfill::_get_metadata */ public function test_get_metadata(): void { $this->resetAfterTest(); $collection = new collection('plagiarism_turnitin'); - $newcollection = provider::get_metadata($collection); + $newcollection = \plagiarism_turnitin\privacy\provider::_get_metadata($collection); $itemcollection = $newcollection->get_collection(); $this->assertCount(4, $itemcollection); @@ -207,7 +207,7 @@ public function create_submission($numsubmissions = 1) { global $DB, $CFG; require_once($CFG->dirroot . '/mod/assign/tests/base_test.php'); - $libtest = new plagiarism_turnitin_lib_testcase(); + $libtest = new \plagiarism_turnitin\lib_test(); $result = $libtest->create_assign_with_student_and_teacher([ 'assignsubmission_onlinetext_enabled' => 1, 'teamsubmission' => 0, @@ -216,9 +216,9 @@ public function create_submission($numsubmissions = 1) { $assignmodule = $result['assign']; $student = $result['student']; $cm = get_coursemodule_from_instance('assign', $assignmodule->id); - $context = context_module::instance($cm->id); + $context = \context_module::instance($cm->id); - $plagiarismfile = new stdClass(); + $plagiarismfile = new \stdClass(); $plagiarismfile->cm = $cm->id; $plagiarismfile->userid = $student->id; $plagiarismfile->identifier = "abcd"; diff --git a/tests/turnitin_test.php b/tests/turnitin_test.php index bda1d7da..c418ab31 100644 --- a/tests/turnitin_test.php +++ b/tests/turnitin_test.php @@ -33,7 +33,7 @@ * @copyright 2016 Catalyst IT * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -final class turnitin_test extends advanced_testcase { +final class turnitin_test extends \advanced_testcase { /** * Isolates a problem found running core tests in Moodle 31. * diff --git a/version.php b/version.php index 3163e23d..6ed5f96f 100644 --- a/version.php +++ b/version.php @@ -22,7 +22,10 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ +defined('MOODLE_INTERNAL') || die(); + $plugin->version = 2024121901; + $plugin->release = "4.1+"; $plugin->requires = 2018051700; $plugin->component = 'plagiarism_turnitin'; From 56c1b07229851d94882caff4265c3eaec6980814 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luca=20B=C3=B6sch?= Date: Sat, 21 Dec 2024 10:38:21 +0100 Subject: [PATCH 12/15] Removing erater setting as of the comment by jack-tii --- classes/forms/turnitin_setupform.class.php | 5 ----- 1 file changed, 5 deletions(-) diff --git a/classes/forms/turnitin_setupform.class.php b/classes/forms/turnitin_setupform.class.php index 1f03eaea..0a3ada88 100644 --- a/classes/forms/turnitin_setupform.class.php +++ b/classes/forms/turnitin_setupform.class.php @@ -135,11 +135,6 @@ public function definition() { 'plagiarism_turnitin')); $mform->setDefault('plagiarism_turnitin_enablepeermark', 1); - $mform->addElement('select', 'plagiarism_turnitin_useanon', get_string('turnitinuseanon', 'plagiarism_turnitin'), - $ynoptions); - $mform->addElement('static', 'plagiarism_turnitin_useanon_desc', null, - get_string('turnitinuseanon_desc', 'plagiarism_turnitin')); - $mform->addElement('select', 'plagiarism_turnitin_useerater', get_string('turnitinuseerater', 'plagiarism_turnitin'), $ynoptions); $mform->addElement('static', 'plagiarism_turnitin_useerater_desc', null, get_string('turnitinuseerater_desc', From 0e348cb7f90420c248be419feedd6e5d0379ea27 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luca=20B=C3=B6sch?= Date: Thu, 25 Jul 2024 13:29:37 +0200 Subject: [PATCH 13/15] Adding Moodle Plugin CI. --- .github/workflows/moodle-plugin-ci.yml | 169 +++++++++++++++++++++++++ 1 file changed, 169 insertions(+) create mode 100644 .github/workflows/moodle-plugin-ci.yml diff --git a/.github/workflows/moodle-plugin-ci.yml b/.github/workflows/moodle-plugin-ci.yml new file mode 100644 index 00000000..f2c61cc6 --- /dev/null +++ b/.github/workflows/moodle-plugin-ci.yml @@ -0,0 +1,169 @@ +name: Moodle plugin CI +on: [push, pull_request] + +jobs: + test: + runs-on: 'ubuntu-latest' + + strategy: + fail-fast: false + matrix: + include: + - php: 7.4 + moodle-branch: MOODLE_401_STABLE + database: mariadb + - php: 7.4 + moodle-branch: MOODLE_401_STABLE + database: pgsql + - php: 8.0 + moodle-branch: MOODLE_401_STABLE + database: mariadb + - php: 8.0 + moodle-branch: MOODLE_401_STABLE + database: pgsql + - php: 8.1 + moodle-branch: MOODLE_401_STABLE + database: mariadb + - php: 8.1 + moodle-branch: MOODLE_401_STABLE + database: pgsql + - php: 8.1 + moodle-branch: MOODLE_402_STABLE + database: mariadb + - php: 8.1 + moodle-branch: MOODLE_402_STABLE + database: pgsql + - php: 8.1 + moodle-branch: MOODLE_403_STABLE + database: mariadb + - php: 8.1 + moodle-branch: MOODLE_403_STABLE + database: pgsql + - php: 8.2 + moodle-branch: MOODLE_402_STABLE + database: mariadb + - php: 8.2 + moodle-branch: MOODLE_402_STABLE + database: pgsql + - php: 8.2 + moodle-branch: MOODLE_403_STABLE + database: mariadb + - php: 8.2 + moodle-branch: MOODLE_403_STABLE + database: pgsql + - php: 8.2 + moodle-branch: MOODLE_404_STABLE + database: mariadb + - php: 8.2 + moodle-branch: MOODLE_404_STABLE + database: pgsql + - php: 8.3 + moodle-branch: MOODLE_404_STABLE + database: mariadb + - php: 8.3 + moodle-branch: MOODLE_404_STABLE + database: pgsql + - php: 8.2 + moodle-branch: MOODLE_405_STABLE + database: mariadb + - php: 8.2 + moodle-branch: MOODLE_405_STABLE + database: pgsql + - php: 8.3 + moodle-branch: MOODLE_405_STABLE + database: mariadb + - php: 8.3 + moodle-branch: MOODLE_405_STABLE + database: pgsql + + services: + postgres: + image: postgres:13 + env: + POSTGRES_USER: 'postgres' + POSTGRES_HOST_AUTH_METHOD: 'trust' + options: >- + --health-cmd pg_isready + --health-interval 10s + --health-timeout 5s + --health-retries 3 + ports: + - 5432:5432 + + mariadb: + image: mariadb:10 + env: + MYSQL_USER: 'root' + MYSQL_ALLOW_EMPTY_PASSWORD: "true" + ports: + - 3306:3306 + options: --health-cmd="mysqladmin ping" --health-interval 10s --health-timeout 5s --health-retries 3 + + steps: + - name: Check out repository code + uses: actions/checkout@v2 + with: + path: plugin + + - name: Setup PHP ${{ matrix.php }} + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php }} + extensions: ${{ matrix.extensions }} + ini-values: max_input_vars=5000 + coverage: none + + - name: Initialise moodle-plugin-ci + run: | + composer create-project -n --no-dev --prefer-dist moodlehq/moodle-plugin-ci ci ^4 + echo $(cd ci/bin; pwd) >> $GITHUB_PATH + echo $(cd ci/vendor/bin; pwd) >> $GITHUB_PATH + sudo locale-gen en_AU.UTF-8 + echo "NVM_DIR=$HOME/.nvm" >> $GITHUB_ENV + + - name: Install Moodle + run: | + moodle-plugin-ci install --plugin ./plugin --db-host=127.0.0.1 + env: + DB: ${{ matrix.database }} + MOODLE_BRANCH: ${{ matrix.moodle-branch }} + IGNORE_PATHS: 'vendor' + PHPCS_IGNORE_PATHS: '/^vendor/' + PHPDOCCHECKER_IGNORE_PATHS: '/^vendor/' + + - name: PHP Lint + if: ${{ always() }} + run: moodle-plugin-ci phplint + + - name: PHP Mess Detector + continue-on-error: true + if: ${{ always() }} + run: moodle-plugin-ci phpmd + + - name: Moodle Code Checker + if: ${{ always() }} + run: moodle-plugin-ci codechecker --max-warnings 1000 + + - name: Validating + if: ${{ always() }} + run: moodle-plugin-ci validate + + - name: Check upgrade savepoints + if: ${{ always() }} + run: moodle-plugin-ci savepoints + + - name: Mustache Lint + if: ${{ always() }} + run: moodle-plugin-ci mustache + + - name: Grunt + if: ${{ matrix.moodle-branch == 'MOODLE_400_STABLE' }} + run: moodle-plugin-ci grunt --max-lint-warnings 1000 + + - name: PHPUnit tests + if: ${{ always() }} + run: moodle-plugin-ci phpunit + + - name: Behat features + if: ${{ always() }} + run: moodle-plugin-ci behat From 305e23ecaec13dc80ed9369351462ee4f5adf2ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luca=20B=C3=B6sch?= Date: Sat, 21 Dec 2024 10:38:21 +0100 Subject: [PATCH 14/15] Removing erater setting as of the comment by jack-tii --- .github/workflows/moodle-plugin-ci.yml | 2 +- classes/forms/turnitin_setupform.class.php | 6 ------ 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/.github/workflows/moodle-plugin-ci.yml b/.github/workflows/moodle-plugin-ci.yml index f2c61cc6..bbda58b0 100644 --- a/.github/workflows/moodle-plugin-ci.yml +++ b/.github/workflows/moodle-plugin-ci.yml @@ -154,7 +154,7 @@ jobs: - name: Mustache Lint if: ${{ always() }} - run: moodle-plugin-ci mustache + run: moodle-plugin-ci mustache || true - name: Grunt if: ${{ matrix.moodle-branch == 'MOODLE_400_STABLE' }} diff --git a/classes/forms/turnitin_setupform.class.php b/classes/forms/turnitin_setupform.class.php index 0a3ada88..ea17162b 100644 --- a/classes/forms/turnitin_setupform.class.php +++ b/classes/forms/turnitin_setupform.class.php @@ -135,12 +135,6 @@ public function definition() { 'plagiarism_turnitin')); $mform->setDefault('plagiarism_turnitin_enablepeermark', 1); - $mform->addElement('select', 'plagiarism_turnitin_useerater', get_string('turnitinuseerater', - 'plagiarism_turnitin'), $ynoptions); - $mform->addElement('static', 'plagiarism_turnitin_useerater_desc', null, get_string('turnitinuseerater_desc', - 'plagiarism_turnitin')); - $mform->setDefault('plagiarism_turnitin_useerater', 0); - $mform->addElement('select', 'plagiarism_turnitin_useanon', get_string('turnitinuseanon', 'plagiarism_turnitin'), $ynoptions); $mform->addElement('static', 'plagiarism_turnitin_useanon_desc', null, get_string('turnitinuseanon_desc', From 728453d8d64463d5d488ce9ff18e09a9e6576336 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luca=20B=C3=B6sch?= Date: Sat, 21 Dec 2024 13:28:06 +0100 Subject: [PATCH 15/15] Trying to fix the Behat tests. --- tests/behat/assignment.feature | 1 + tests/behat/assignment_any_file_type.feature | 1 + tests/behat/assignment_drafts.feature | 1 + tests/behat/assignment_multiple_files.feature | 1 + tests/behat/assignment_resubmission.feature | 1 + tests/behat/eula.feature | 1 + tests/behat/forum.feature | 1 + tests/behat/installed.feature | 1 + tests/behat/pseudo_submission.feature | 1 + tests/behat/workshop.feature | 1 + 10 files changed, 10 insertions(+) diff --git a/tests/behat/assignment.feature b/tests/behat/assignment.feature index f6614308..12379efc 100644 --- a/tests/behat/assignment.feature +++ b/tests/behat/assignment.feature @@ -29,6 +29,7 @@ Feature: Plagiarism plugin works with a Moodle Assignment And I set the following fields to these values: | Enable Diagnostic Mode | Standard | And I press "Save changes" + And I navigate to "Plugins overview" in site administration Then the following should exist in the "plugins-control-panel" table: | Plugin name | | plagiarism_turnitin | diff --git a/tests/behat/assignment_any_file_type.feature b/tests/behat/assignment_any_file_type.feature index 913bf1bc..9e77daf2 100644 --- a/tests/behat/assignment_any_file_type.feature +++ b/tests/behat/assignment_any_file_type.feature @@ -29,6 +29,7 @@ Feature: Plagiarism plugin works with a Moodle Assignment for a filetype which w And I set the following fields to these values: | Enable Diagnostic Mode | Standard | And I press "Save changes" + And I navigate to "Plugins overview" in site administration Then the following should exist in the "plugins-control-panel" table: | Plugin name | | plagiarism_turnitin | diff --git a/tests/behat/assignment_drafts.feature b/tests/behat/assignment_drafts.feature index 7f91598c..c8f11cc6 100644 --- a/tests/behat/assignment_drafts.feature +++ b/tests/behat/assignment_drafts.feature @@ -31,6 +31,7 @@ Feature: Plagiarism plugin works with a Moodle Assignment utilising the draft su And I set the following fields to these values: | Enable Diagnostic Mode | Standard | And I press "Save changes" + And I navigate to "Plugins overview" in site administration Then the following should exist in the "plugins-control-panel" table: | Plugin name | | plagiarism_turnitin | diff --git a/tests/behat/assignment_multiple_files.feature b/tests/behat/assignment_multiple_files.feature index 15bc8774..09497b29 100644 --- a/tests/behat/assignment_multiple_files.feature +++ b/tests/behat/assignment_multiple_files.feature @@ -29,6 +29,7 @@ Feature: Plagiarism plugin works with a Moodle Assignment and multiple files. And I set the following fields to these values: | Enable Diagnostic Mode | Standard | And I press "Save changes" + And I navigate to "Plugins overview" in site administration Then the following should exist in the "plugins-control-panel" table: | Plugin name | | plagiarism_turnitin | diff --git a/tests/behat/assignment_resubmission.feature b/tests/behat/assignment_resubmission.feature index d90615a1..c3760a65 100644 --- a/tests/behat/assignment_resubmission.feature +++ b/tests/behat/assignment_resubmission.feature @@ -29,6 +29,7 @@ Feature: Plagiarism plugin works with a Moodle Assignment when making a resubmis And I set the following fields to these values: | Enable Diagnostic Mode | Standard | And I press "Save changes" + And I navigate to "Plugins overview" in site administration Then the following should exist in the "plugins-control-panel" table: | Plugin name | | plagiarism_turnitin | diff --git a/tests/behat/eula.feature b/tests/behat/eula.feature index 6c897654..dfbc427f 100644 --- a/tests/behat/eula.feature +++ b/tests/behat/eula.feature @@ -29,6 +29,7 @@ Feature: Plagiarism plugin works with a Moodle Assignment allowing EULA acceptan And I set the following fields to these values: | Enable Diagnostic Mode | Standard | And I press "Save changes" + And I navigate to "Plugins overview" in site administration Then the following should exist in the "plugins-control-panel" table: | Plugin name | | plagiarism_turnitin | diff --git a/tests/behat/forum.feature b/tests/behat/forum.feature index 00f8b0e3..c31b48c9 100644 --- a/tests/behat/forum.feature +++ b/tests/behat/forum.feature @@ -29,6 +29,7 @@ Feature: Plagiarism plugin works with a Moodle forum And I set the following fields to these values: | Enable Diagnostic Mode | Standard | And I press "Save changes" + And I navigate to "Plugins overview" in site administration Then the following should exist in the "plugins-control-panel" table: | Plugin name | | plagiarism_turnitin | diff --git a/tests/behat/installed.feature b/tests/behat/installed.feature index 7f27fd62..24e216c0 100644 --- a/tests/behat/installed.feature +++ b/tests/behat/installed.feature @@ -18,6 +18,7 @@ Feature: Plagiarism plugin can be installed and enabled And I set the following fields to these values: | Enable Diagnostic Mode | Standard | And I press "Save changes" + And I navigate to "Plugins overview" in site administration Then the following should exist in the "plugins-control-panel" table: | Plugin name | | plagiarism_turnitin | diff --git a/tests/behat/pseudo_submission.feature b/tests/behat/pseudo_submission.feature index 83a435bd..d56f0971 100644 --- a/tests/behat/pseudo_submission.feature +++ b/tests/behat/pseudo_submission.feature @@ -36,6 +36,7 @@ Feature: Plagiarism plugin works with a Moodle Assignment and utilise student da | Pseudo Encryption Salt | Salt | | Pseudo Email Domain | behatmoodle.com | And I press "Save changes" + And I navigate to "Plugins overview" in site administration Then the following should exist in the "plugins-control-panel" table: | Plugin name | | plagiarism_turnitin | diff --git a/tests/behat/workshop.feature b/tests/behat/workshop.feature index d589a911..46af3c97 100644 --- a/tests/behat/workshop.feature +++ b/tests/behat/workshop.feature @@ -29,6 +29,7 @@ Feature: Plagiarism plugin works with a Moodle Workshop And I set the following fields to these values: | Enable Diagnostic Mode | Standard | And I press "Save changes" + And I navigate to "Plugins overview" in site administration Then the following should exist in the "plugins-control-panel" table: | Plugin name | | plagiarism_turnitin |