diff --git a/classes/observer.php b/classes/observer.php
index 12ed4cb..0530c12 100644
--- a/classes/observer.php
+++ b/classes/observer.php
@@ -85,4 +85,32 @@ class plagiarism_pchkorg_observer {
$plugin = new plagiarism_plugin_pchkorg();
$plugin->event_handler($eventdata);
}
+
+ /**
+ * Handle the quiz attempt_submitted event.
+ * @param \mod_quiz\event\attempt_submitted $event
+ */
+ public static function quiz_submitted(
+ \mod_quiz\event\attempt_submitted $event) {
+ $eventdata = $event->get_data();
+ $eventdata['eventtype'] = 'quiz_submitted';
+ $eventdata['other']['modulename'] = 'quiz';
+
+ $plugin = new plagiarism_plugin_pchkorg();
+ $plugin->event_handler($eventdata);
+ }
+
+ /**
+ * Handle the quiz attempt_updated event.
+ * @param \mod_quiz\event\attempt_updated $event
+ */
+ public static function quiz_updated(
+ \mod_quiz\event\attempt_submitted $event) {
+ $eventdata = $event->get_data();
+ $eventdata['eventtype'] = 'quiz_submitted';
+ $eventdata['other']['modulename'] = 'quiz';
+
+ $plugin = new plagiarism_plugin_pchkorg();
+ $plugin->event_handler($eventdata);
+ }
}
diff --git a/classes/plagiarism_pchkorg_api_provider.php b/classes/plagiarism_pchkorg_api_provider.php
index 89e686c..3d3a484 100644
--- a/classes/plagiarism_pchkorg_api_provider.php
+++ b/classes/plagiarism_pchkorg_api_provider.php
@@ -78,6 +78,61 @@ class plagiarism_pchkorg_api_provider {
$this->endpoint = $endpoint;
}
+ /**
+ * Send text for originality check.
+ *
+ * @param $authorhash
+ * @param $cousereid
+ * @param $assignmentid
+ * @param $assignmentname
+ * @param $submissionid
+ * @param $attachmentid
+ * @param $content
+ * @param $mime
+ * @param $filename
+ *
+ * @return |null
+ */
+ public function general_send_check(
+ $authorhash,
+ $cousereid,
+ $assignmentid,
+ $assignmentname,
+ $submissionid,
+ $attachmentid,
+ $content,
+ $mime,
+ $filename,
+ $filters = array()
+ ) {
+ if ($this->is_group_token()) {
+ return $this->send_group_text(
+ $authorhash,
+ $cousereid,
+ $assignmentid,
+ $assignmentname,
+ $submissionid,
+ $attachmentid,
+ $content,
+ $mime,
+ $filename,
+ $filters
+ );
+ } else {
+ return $this->send_text(
+ $cousereid,
+ $assignmentid,
+ $assignmentname,
+ $submissionid,
+ $attachmentid,
+ $content,
+ $mime,
+ $filename,
+ $filters
+ );
+ }
+ }
+
/**
* Send text for originality check.
*
diff --git a/classes/task/send_submissions.php b/classes/task/send_submissions.php
index 5575634..c989c7d 100644
--- a/classes/task/send_submissions.php
+++ b/classes/task/send_submissions.php
@@ -26,7 +26,7 @@ namespace plagiarism_pchkorg\task;
defined('MOODLE_INTERNAL') || die();
/**
- * Send queued submissions to Turnitin.
+ * Send queued submissions.
*/
class send_submissions extends \core\task\scheduled_task {
diff --git a/classes/task/update_reports.php b/classes/task/update_reports.php
index 49881a5..108775d 100644
--- a/classes/task/update_reports.php
+++ b/classes/task/update_reports.php
@@ -26,7 +26,7 @@ namespace plagiarism_pchkorg\task;
defined('MOODLE_INTERNAL') || die();
/**
- * Update report Scores from Turnitin.
+ * Update report.
*/
class update_reports extends \core\task\scheduled_task {
diff --git a/db/events.php b/db/events.php
index 3a763a6..47e21ea 100644
--- a/db/events.php
+++ b/db/events.php
@@ -40,4 +40,12 @@ $observers = array (
'eventname' => '\core\event\course_module_deleted',
'callback' => 'plagiarism_pchkorg_observer::course_module_deleted'
),
+ array(
+ 'eventname' => '\mod_quiz\event\attempt_submitted',
+ 'callback' => 'plagiarism_pchkorg_observer::quiz_submitted',
+ ),
+ array(
+ 'eventname' => '\mod_quiz\event\attempt_updated',
+ 'callback' => 'plagiarism_pchkorg_observer::quiz_updated',
+ )
);
diff --git a/form/plagiarism_pchkorg_setup_form.php b/form/plagiarism_pchkorg_setup_form.php
index 0d8bd73..801c3a8 100644
--- a/form/plagiarism_pchkorg_setup_form.php
+++ b/form/plagiarism_pchkorg_setup_form.php
@@ -68,6 +68,13 @@ class plagiarism_pchkorg_setup_form extends moodleform {
$mform->addRule('pchkorg_min_percent', get_string('pchkorg_min_percent_range', 'plagiarism_pchkorg'), 'check_pchkorg_min_percent');
$mform->setType('pchkorg_min_percent', PARAM_INT);
+ $mform->addElement(
+ 'select',
+ 'pchkorg_enable_quiz',
+ get_string('pchkorg_enable_quiz', 'plagiarism_pchkorg'),
+ array(get_string('no'), get_string('yes'))
+ );
+
$this->add_action_buttons(true);
}
diff --git a/lang/en/plagiarism_pchkorg.php b/lang/en/plagiarism_pchkorg.php
index f09034d..09f88c4 100644
--- a/lang/en/plagiarism_pchkorg.php
+++ b/lang/en/plagiarism_pchkorg.php
@@ -42,6 +42,7 @@ $string['pchkorg_min_percent_range'] = 'Must be between 0 and 99';
$string['pchkorg_exclude_self_plagiarism'] = 'Exclude self-plagiarism';
$string['pchkorg_include_referenced'] = 'Include References';
$string['pchkorg_include_citation'] = 'Include Quotes';
+$string['pchkorg_enable_quiz'] = 'Enable Quiz';
$string['pchkorg_disclosure'] = 'Submission will be sent to PlagiarismCheck.org for check.
By submitting assignment I agree with Terms & Conditions
diff --git a/lib.php b/lib.php
index 1156527..d3b1de6 100644
--- a/lib.php
+++ b/lib.php
@@ -39,10 +39,141 @@ function pchkorg_check_pchkorg_min_percent($value)
return 0 <= $value && $value < 100;
}
+function plagiarism_pchkorg_coursemodule_standard_elements($formwrapper, $mform)
+{
+ $context = context_course::instance($formwrapper->get_course()->id);
+ $modulename = $formwrapper->get_current()->modulename;
+ $allowedmodules = array('assign', 'mod_assign');
+ if (!$context || !isset($modulename)) {
+ return;
+ }
+ global $DB;
+
+ $pchkorgconfigmodel = new plagiarism_pchkorg_config_model();
+
+ $config = $pchkorgconfigmodel->get_system_config('pchkorg_use');
+ $isquizenabled = '1' === $pchkorgconfigmodel->get_system_config('pchkorg_enable_quiz');
+ $enabled = has_capability(capability::ENABLE, $context);
+ if ($isquizenabled) {
+ $allowedmodules[] = 'quiz';
+ }
+ if ('1' == $config && $enabled) {
+ if (!in_array($modulename, $allowedmodules, true)) {
+ return;
+ }
+ $defaultcmid = null;
+ $cm = optional_param('update', $defaultcmid, PARAM_INT);
+ $minpercent = $pchkorgconfigmodel->get_system_config('pchkorg_min_percent');
+
+ if (!isset($mform->exportValues()['pchkorg_exclude_self_plagiarism'])
+ || is_null($mform->exportValues()['pchkorg_exclude_self_plagiarism'])) {
+ $mform->setDefault('pchkorg_exclude_self_plagiarism', 1);
+ }
+ if (!isset($mform->exportValues()['pchkorg_include_referenced'])
+ || is_null($mform->exportValues()['pchkorg_include_referenced'])) {
+ $mform->setDefault('pchkorg_include_referenced', 0);
+ }
+ if (!isset($mform->exportValues()['pchkorg_include_citation'])
+ || is_null($mform->exportValues()['pchkorg_include_citation'])) {
+ $mform->setDefault('pchkorg_include_citation', 0);
+ }
+
+ if (null === $cm) {
+ if (!isset($mform->exportValues()['pchkorg_module_use'])
+ || is_null($mform->exportValues()['pchkorg_module_use'])) {
+ $mform->setDefault('pchkorg_module_use', '1');
+ }
+ } else {
+ $records = $DB->get_records('plagiarism_pchkorg_config', array(
+ 'cm' => $cm,
+ ));
+ if (!empty($records)) {
+ foreach ($records as $record) {
+ $mform->setDefault($record->name, $record->value);
+ }
+ }
+ }
+ $mform->addElement(
+ 'header',
+ 'plagiarism_pchkorg',
+ get_string('pluginname', 'plagiarism_pchkorg')
+ );
+ $mform->addElement(
+ 'select',
+ 'pchkorg_module_use',
+ get_string('pchkorg_module_use', 'plagiarism_pchkorg'),
+ array(get_string('no'), get_string('yes'))
+ );
+ $mform->addHelpButton('pchkorg_module_use', 'pchkorg_module_use', 'plagiarism_pchkorg');
+
+ $canchangeminpercent = has_capability(capability::CHANGE_MIN_PERCENT_FILTER, $context);
+ if ($canchangeminpercent) {
+ $dissabledattribute = '';
+ } else {
+ $dissabledattribute = 'disabled="disabled"';
+ }
+ $mform->registerRule(
+ 'check_pchkorg_min_percent',
+ 'callback',
+ 'pchkorg_check_pchkorg_min_percent'
+ );
+ $label = get_string('pchkorg_min_percent', 'plagiarism_pchkorg');
+ if (!empty($minpercent)) {
+ $label = \str_replace('X%', $minpercent . '%', $label);
+ }
+
+ $mform->addElement(
+ 'text',
+ 'pchkorg_min_percent',
+ $label,
+ $dissabledattribute
+ );
+ $mform->addHelpButton('pchkorg_min_percent', 'pchkorg_min_percent', 'plagiarism_pchkorg');
+ $mform->addRule('pchkorg_min_percent', null, 'text', null, 'client');
+ $mform->addRule(
+ 'pchkorg_min_percent',
+ get_string('pchkorg_min_percent_range', 'plagiarism_pchkorg'),
+ 'check_pchkorg_min_percent'
+ );
+ $mform->setType('pchkorg_min_percent', PARAM_INT);
+
+ $mform->addElement(
+ 'select',
+ 'pchkorg_exclude_self_plagiarism',
+ get_string('pchkorg_exclude_self_plagiarism', 'plagiarism_pchkorg'),
+ array(get_string('no'), get_string('yes'))
+ );
+
+ $mform->addElement(
+ 'select',
+ 'pchkorg_include_referenced',
+ get_string('pchkorg_include_referenced', 'plagiarism_pchkorg'),
+ array(get_string('no'), get_string('yes'))
+ );
+
+ $mform->addElement(
+ 'select',
+ 'pchkorg_include_citation',
+ get_string('pchkorg_include_citation', 'plagiarism_pchkorg'),
+ array(get_string('no'), get_string('yes'))
+ );
+ }
+}
+
+function plagiarism_pchkorg_coursemodule_edit_post_actions($data, $course)
+{
+
+}
+
+
+
+
/**
* Class plagiarism_plugin_pchkorg
*/
class plagiarism_plugin_pchkorg extends plagiarism_plugin {
+
+
/**
* hook to allow plagiarism specific information to be displayed beside a submission.
*
@@ -51,8 +182,7 @@ class plagiarism_plugin_pchkorg extends plagiarism_plugin {
*
*/
public function get_links($linkarray) {
-
- global $DB, $USER;
+ global $DB, $USER, $PAGE;
$pchkorgconfigmodel = new plagiarism_pchkorg_config_model();
$apitoken = $pchkorgconfigmodel->get_system_config('pchkorg_token');
@@ -78,6 +208,17 @@ class plagiarism_plugin_pchkorg extends plagiarism_plugin {
}
$context = null;
+
+ $component = !empty($linkarray['component']) ? $linkarray['component'] : '';
+ if ($cmid === null && $component == 'qtype_essay' && !empty($linkarray['area'])) {
+ $questions = question_engine::load_questions_usage_by_activity($linkarray['area']);
+
+ $context = $questions->get_owning_context();
+ if ($cmid === null && $context->contextlevel == CONTEXT_MODULE) {
+ $cmid = $context->instanceid;
+ }
+ }
+
if (!empty($cmid)) {
$context = context_module::instance($cmid);// Get context of course.
}
@@ -96,6 +237,7 @@ class plagiarism_plugin_pchkorg extends plagiarism_plugin {
return '';
}
+
// Only for some type of account, method will call a remote HTTP API.
// The API will be called only once, because result is static.
// Also, there is timeout 2 seconds for response.
@@ -132,7 +274,6 @@ class plagiarism_plugin_pchkorg extends plagiarism_plugin {
if ($filerecord->state == 5) {
$action = $apiprovider->get_report_action($filerecord->textid);
$reporttoken = $apiprovider->generate_api_token();
- $formid = 'plagiarism_pchkorg_report_id_' . $filerecord->id;
$score = $filerecord->score;
$title = sprintf(get_string('pchkorg_label_title', 'plagiarism_pchkorg'),
$filerecord->textid,
@@ -146,6 +287,31 @@ class plagiarism_plugin_pchkorg extends plagiarism_plugin {
} else {
$color = '#f04343';
}
+ $PAGE->requires->js_amd_inline("
+window.plagiarism_check_full_report = function (action, token) {
+ const form = document.createElement('form');
+ const element1 = document.createElement('input');
+ const element2 = document.createElement('input');
+
+ form.method = 'POST';
+ form.target = '_blank';
+ form.action = action;
+
+ element1.value = 'moodle';
+ element1.name = 'lms-type';
+ element1.type = 'hidden';
+ form.appendChild(element1);
+
+ element2.value = token;
+ element2.name = 'token';
+ element2.type = 'hidden';
+ form.appendChild(element2);
+
+ document.body.appendChild(form);
+
+ form.submit();
+};
+ ");
return '
+ onclick="window.plagiarism_check_full_report(\''.$action.'\', \''.$reporttoken.'\'); return false;">
' . $label . '
-