Skip to content
Browse files

MDL-34131: Plagiarism API - add support for plagiarism api to new onl…

…ine assignment type
  • Loading branch information...
1 parent 55a568f commit 48e5aacbfa3eb6385c03a8c6e8f0d4ebdfb2683f @kanikagoyal kanikagoyal committed Jul 31, 2012
Showing with 30 additions and 4 deletions.
  1. +30 −4 mod/assign/submission/onlinetext/locallib.php
View
34 mod/assign/submission/onlinetext/locallib.php
@@ -113,20 +113,36 @@ private function get_edit_options() {
}
/**
- * Save data to the database
+ * Save data to the database and trigger plagiarism plugin, if enabled, to scan the uploaded content via events trigger
*
* @param stdClass $submission
* @param stdClass $data
* @return bool
*/
public function save(stdClass $submission, stdClass $data) {
- global $DB;
+ global $USER, $DB;
$editoroptions = $this->get_edit_options();
$data = file_postupdate_standard_editor($data, 'onlinetext', $editoroptions, $this->assignment->get_context(), 'assignsubmission_onlinetext', ASSIGNSUBMISSION_ONLINETEXT_FILEAREA, $submission->id);
$onlinetextsubmission = $this->get_onlinetext_submission($submission->id);
+
+ $fs = get_file_storage();
+ $files = $fs->get_area_files($this->assignment->get_context()->id, 'assignsubmission_onlinetext', ASSIGNSUBMISSION_ONLINETEXT_FILEAREA, $submission->id, "id", false);
+ // Let Moodle know that an assessable content was uploaded (eg for plagiarism detection)
+ $eventdata = new stdClass();
+ $eventdata->modulename = 'assign';
+ $eventdata->cmid = $this->assignment->get_course_module()->id;
+ $eventdata->itemid = $submission->id;
+ $eventdata->courseid = $this->assignment->get_course()->id;
+ $eventdata->userid = $USER->id;
+ $eventdata->content = trim(format_text($onlinetextsubmission->onlinetext, $onlinetextsubmission->onlineformat, array('context'=>$this->assignment->get_context())));
+ if ($files) {
+ $eventdata->pathnamehashes = array_keys($files);
+ }
+ events_trigger('assessable_content_uploaded', $eventdata);
+
if ($onlinetextsubmission) {
$onlinetextsubmission->onlinetext = $data->onlinetext;
@@ -194,6 +210,7 @@ public function get_editor_format($name, $submissionid) {
* @return string
*/
public function view_summary(stdClass $submission, & $showviewlink) {
+ global $CFG;
$onlinetextsubmission = $this->get_onlinetext_submission($submission->id);
// always show the view link
@@ -202,10 +219,19 @@ public function view_summary(stdClass $submission, & $showviewlink) {
if ($onlinetextsubmission) {
$text = format_text($onlinetextsubmission->onlinetext, $onlinetextsubmission->onlineformat, array('context'=>$this->assignment->get_context()));
$shorttext = shorten_text($text, 140);
+ $plagiarismlinks = '';
+ if (!empty($CFG->enableplagiarism)) {
+ require_once($CFG->libdir . '/plagiarismlib.php');
+ $plagiarismlinks .= plagiarism_get_links(array('userid' => $submission->userid,
+ 'content' => trim(format_text($onlinetextsubmission->onlinetext, $onlinetextsubmission->onlineformat, array('context'=>$this->assignment->get_context()))),
+ 'cmid' => $this->assignment->get_course_module()->id,
+ 'course' => $this->assignment->get_course()->id,
+ 'assignment' => $submission->assignment));
+ }
if ($text != $shorttext) {
- return $shorttext . get_string('numwords', 'assignsubmission_onlinetext', count_words($text));
+ return $shorttext . $plagiarismlinks . get_string('numwords', 'assignsubmission_onlinetext', count_words($text));
} else {
- return $shorttext;
+ return $shorttext . $plagiarismlinks;
}
}
return '';

0 comments on commit 48e5aac

Please sign in to comment.
Something went wrong with that request. Please try again.