From aa44efdf0bbaad1cb8c106ed51477b48fd31f871 Mon Sep 17 00:00:00 2001 From: Jane Adelmann Date: Thu, 12 Oct 2023 16:37:14 +0300 Subject: [PATCH] v 3.14.5 add new option and fix quiz --- form/plagiarism_pchkorg_setup_form.php | 8 ++++++++ lang/en/plagiarism_pchkorg.php | 1 + lib.php | 20 ++++++++++++++++---- version.php | 4 ++-- 4 files changed, 27 insertions(+), 6 deletions(-) diff --git a/form/plagiarism_pchkorg_setup_form.php b/form/plagiarism_pchkorg_setup_form.php index 8767b15..93602ae 100644 --- a/form/plagiarism_pchkorg_setup_form.php +++ b/form/plagiarism_pchkorg_setup_form.php @@ -86,6 +86,14 @@ class plagiarism_pchkorg_setup_form extends moodleform { array(get_string('no'), get_string('yes')) ); + $mform->addElement( + 'select', + 'pchkorg_enabled_by_default', + get_string('pchkorg:enabledbydefault', 'plagiarism_pchkorg'), + array(get_string('no'), get_string('yes')) + ); + $mform->setDefault('pchkorg_enabled_by_default', '1'); + $this->add_action_buttons(true); } diff --git a/lang/en/plagiarism_pchkorg.php b/lang/en/plagiarism_pchkorg.php index 4e6184c..5d4c2ed 100644 --- a/lang/en/plagiarism_pchkorg.php +++ b/lang/en/plagiarism_pchkorg.php @@ -97,3 +97,4 @@ $string['pchkorg_label_queued'] = 'In queue'; $string['pchkorg:enable'] = 'Allow to enable/disable PlagiarismCheck.org inside an activity'; $string['pchkorg:viewsimilarity'] = 'Allow to view similarity value from PlagiarismCheck.org'; $string['pchkorg:changeminpercentfilter'] = 'Allow changing "Exclude sources below X% similarity"'; +$string['pchkorg:enabledbydefault'] = 'Enable PlagiarismCheck in Activities by default'; \ No newline at end of file diff --git a/lib.php b/lib.php index a3d036d..becc841 100644 --- a/lib.php +++ b/lib.php @@ -97,7 +97,13 @@ function plagiarism_pchkorg_coursemodule_standard_elements($formwrapper, $mform) if (null === $cm) { if (!isset($exportedvalues['pchkorg_module_use']) || is_null($exportedvalues['pchkorg_module_use'])) { - $mform->setDefault('pchkorg_module_use', '1'); + $enabledbydefault = $pchkorgconfigmodel->get_system_config('pchkorg_enabled_by_default'); + if ('1' === $enabledbydefault || null === $enabledbydefault) { + $mform->setDefault('pchkorg_module_use', '1'); + } + if ('0' === $enabledbydefault) { + $mform->setDefault('pchkorg_module_use', '0'); + } } } else { $records = $DB->get_records('plagiarism_pchkorg_config', array( @@ -284,7 +290,11 @@ class plagiarism_plugin_pchkorg extends plagiarism_plugin { $isdebugenabled = $pchkorgconfigmodel->get_system_config('pchkorg_enable_debug') === '1'; $apiprovider = new plagiarism_pchkorg_api_provider($apitoken); - $cmid = $linkarray['cmid']; + $cmid = null; + if (array_key_exists('cmid', $linkarray)) { + $cmid = $linkarray['cmid']; + } + if (array_key_exists('file', $linkarray)) { $file = $linkarray['file']; } else { @@ -1159,11 +1169,13 @@ display: inline-block;" if ($cm->modname === 'quiz') { if ($filedb->fileid === null) { + $questionanswers = $DB->get_records_sql( "SELECT {question_attempts}.responsesummary " ." FROM {question_attempts} " - ." INNER JOIN {question} on {question}.id = {question_attempts}.questionid " - ." WHERE {question_attempts}.questionusageid = ? AND {question}.qtype = 'essay' ", array( + ." INNER JOIN {question} on {question}.id = {question_attempts}.questionid " + ." INNER JOIN {quiz_attempts} on {quiz_attempts}.uniqueid = {question_attempts}.questionusageid " + ." WHERE {quiz_attempts}.id= ? AND {question}.qtype = 'essay' ", array( $filedb->itemid ) ); diff --git a/version.php b/version.php index c400936..7adc2b8 100644 --- a/version.php +++ b/version.php @@ -26,9 +26,9 @@ defined('MOODLE_INTERNAL') || die(); if (!isset($plugin)) { $plugin = new stdClass(); } -$plugin->version = 2023070415; +$plugin->version = 2023101216; $plugin->requires = 2020061501; // Requires Moodle 3.9 . -$plugin->release = 'v3.14.4'; +$plugin->release = 'v3.14.5'; $plugin->component = 'plagiarism_pchkorg'; $plugin->maturity = MATURITY_STABLE; $plugin->dependencies = array(