/** * Save the files and trigger plagiarism plugin, if enabled, * to scan the uploaded files via events trigger * * @param stdClass $submission * @param stdClass $data * @return bool */ public function save(stdClass $submission, stdClass $data) { global $USER, $DB; $fileoptions = $this->get_file_options(); $data = file_postupdate_standard_filemanager($data, 'files', $fileoptions, $this->assignment->get_context(), 'assignsubmission_file', ASSIGNSUBMISSION_FILE_FILEAREA, $submission->id); $filesubmission = $this->get_file_submission($submission->id); // Plagiarism code event trigger when files are uploaded. $fs = get_file_storage(); $files = $fs->get_area_files($this->assignment->get_context()->id, 'assignsubmission_file', ASSIGNSUBMISSION_FILE_FILEAREA, $submission->id, 'id', false); $count = $this->count_files($submission->id, ASSIGNSUBMISSION_FILE_FILEAREA); $params = array('context' => context_module::instance($this->assignment->get_course_module()->id), 'courseid' => $this->assignment->get_course()->id, 'objectid' => $submission->id, 'other' => array('content' => '', 'pathnamehashes' => array_keys($files))); if (!empty($submission->userid) && $submission->userid != $USER->id) { $params['relateduserid'] = $submission->userid; } $event = \assignsubmission_file\event\assessable_uploaded::create($params); $event->set_legacy_files($files); $event->trigger(); $groupname = null; $groupid = 0; // Get the group name as other fields are not transcribed in the logs and this information is important. if (empty($submission->userid) && !empty($submission->groupid)) { $groupname = $DB->get_field('groups', 'name', array('id' => $submission->groupid), '*', MUST_EXIST); $groupid = $submission->groupid; } else { $params['relateduserid'] = $submission->userid; } // Unset the objectid and other field from params for use in submission events. unset($params['objectid']); unset($params['other']); $params['other'] = array('submissionid' => $submission->id, 'submissionattempt' => $submission->attemptnumber, 'submissionstatus' => $submission->status, 'filesubmissioncount' => $count, 'groupid' => $groupid, 'groupname' => $groupname); if ($filesubmission) { $filesubmission->numfiles = $this->count_files($submission->id, ASSIGNSUBMISSION_FILE_FILEAREA); $updatestatus = $DB->update_record('assignsubmission_file', $filesubmission); $params['objectid'] = $filesubmission->id; $event = \assignsubmission_file\event\submission_updated::create($params); $event->set_assign($this->assignment); $event->trigger(); return $updatestatus; } else { $filesubmission = new stdClass(); $filesubmission->numfiles = $this->count_files($submission->id, ASSIGNSUBMISSION_FILE_FILEAREA); $filesubmission->submission = $submission->id; $filesubmission->assignment = $this->assignment->get_instance()->id; $filesubmission->id = $DB->insert_record('assignsubmission_file', $filesubmission); $params['objectid'] = $filesubmission->id; $event = \assignsubmission_file\event\submission_created::create($params); $event->set_assign($this->assignment); $event->trigger(); return $filesubmission->id > 0; } }
public function create_file_event($params) { return \assignsubmission_file\event\assessable_uploaded::create($params); }
/** * Save the files and trigger plagiarism plugin, if enabled, * to scan the uploaded files via events trigger * * @param stdClass $submission * @param stdClass $data * @return bool */ public function save(stdClass $submission, stdClass $data) { global $USER, $DB; $fileoptions = $this->get_file_options(); $data = file_postupdate_standard_filemanager($data, 'files', $fileoptions, $this->assignment->get_context(), 'assignsubmission_file', ASSIGNSUBMISSION_FILE_FILEAREA, $submission->id); $filesubmission = $this->get_file_submission($submission->id); // Plagiarism code event trigger when files are uploaded. $fs = get_file_storage(); $files = $fs->get_area_files($this->assignment->get_context()->id, 'assignsubmission_file', ASSIGNSUBMISSION_FILE_FILEAREA, $submission->id, 'id', false); $count = $this->count_files($submission->id, ASSIGNSUBMISSION_FILE_FILEAREA); $params = array('context' => context_module::instance($this->assignment->get_course_module()->id), 'objectid' => $submission->id, 'other' => array('content' => '', 'pathnamehashes' => array_keys($files))); $event = \assignsubmission_file\event\assessable_uploaded::create($params); $event->set_legacy_files($files); $event->trigger(); if ($filesubmission) { $filesubmission->numfiles = $this->count_files($submission->id, ASSIGNSUBMISSION_FILE_FILEAREA); return $DB->update_record('assignsubmission_file', $filesubmission); } else { $filesubmission = new stdClass(); $filesubmission->numfiles = $this->count_files($submission->id, ASSIGNSUBMISSION_FILE_FILEAREA); $filesubmission->submission = $submission->id; $filesubmission->assignment = $this->assignment->get_instance()->id; return $DB->insert_record('assignsubmission_file', $filesubmission) > 0; } }