/**
  * Return things to the renderer.
  *
  * @return int the course id
  */
 public function get_course_id()
 {
     return $this->assignment->get_course()->id;
 }
示例#2
0
文件: ajax.php 项目: janeklb/moodle
use assignfeedback_editpdf\document_services;
use assignfeedback_editpdf\page_editor;
use assignfeedback_editpdf\comments_quick_list;
define('AJAX_SCRIPT', true);
require '../../../../config.php';
require_once $CFG->dirroot . '/mod/assign/locallib.php';
require_sesskey();
$action = optional_param('action', '', PARAM_ALPHANUM);
$assignmentid = required_param('assignmentid', PARAM_INT);
$userid = required_param('userid', PARAM_INT);
$attemptnumber = required_param('attemptnumber', PARAM_INT);
$readonly = optional_param('readonly', false, PARAM_BOOL);
$cm = \get_coursemodule_from_instance('assign', $assignmentid, 0, false, MUST_EXIST);
$context = \context_module::instance($cm->id);
$assignment = new \assign($context, null, null);
require_login($assignment->get_course(), false, $cm);
if (!$assignment->can_view_submission($userid)) {
    print_error('nopermission');
}
if ($action == 'loadallpages') {
    $draft = true;
    if (!has_capability('mod/assign:grade', $context)) {
        $draft = false;
        $readonly = true;
        // A student always sees the readonly version.
        require_capability('mod/assign:submit', $context);
    }
    // Whoever is viewing the readonly version should not use the drafts, but the actual annotations.
    if ($readonly) {
        $draft = false;
    }
示例#3
0
 /**
  * Called to define this moodle form
  *
  * @return void
  */
 public function definition()
 {
     global $CFG, $DB, $PAGE;
     $mform = $this->_form;
     $mform->addElement('header', 'general', get_string('general', 'form'));
     $mform->addElement('text', 'name', get_string('assignmentname', 'assign'), array('size' => '64'));
     if (!empty($CFG->formatstringstriptags)) {
         $mform->setType('name', PARAM_TEXT);
     } else {
         $mform->setType('name', PARAM_CLEANHTML);
     }
     $mform->addRule('name', null, 'required', null, 'client');
     $mform->addRule('name', get_string('maximumchars', '', 255), 'maxlength', 255, 'client');
     $this->add_intro_editor(true, get_string('description', 'assign'));
     $ctx = null;
     if ($this->current && $this->current->coursemodule) {
         $cm = get_coursemodule_from_instance('assign', $this->current->id, 0, false, MUST_EXIST);
         $ctx = context_module::instance($cm->id);
     }
     $assignment = new assign($ctx, null, null);
     if ($this->current && $this->current->course) {
         if (!$ctx) {
             $ctx = context_course::instance($this->current->course);
         }
         $course = $DB->get_record('course', array('id' => $this->current->course), '*', MUST_EXIST);
         $assignment->set_course($course);
     }
     $config = get_config('assign');
     $mform->addElement('header', 'availability', get_string('availability', 'assign'));
     $mform->setExpanded('availability', true);
     $name = get_string('allowsubmissionsfromdate', 'assign');
     $options = array('optional' => true);
     $mform->addElement('date_time_selector', 'allowsubmissionsfromdate', $name, $options);
     $mform->addHelpButton('allowsubmissionsfromdate', 'allowsubmissionsfromdate', 'assign');
     $name = get_string('duedate', 'assign');
     $mform->addElement('date_time_selector', 'duedate', $name, array('optional' => true));
     $mform->addHelpButton('duedate', 'duedate', 'assign');
     $name = get_string('cutoffdate', 'assign');
     $mform->addElement('date_time_selector', 'cutoffdate', $name, array('optional' => true));
     $mform->addHelpButton('cutoffdate', 'cutoffdate', 'assign');
     $name = get_string('alwaysshowdescription', 'assign');
     $mform->addElement('checkbox', 'alwaysshowdescription', $name);
     $mform->addHelpButton('alwaysshowdescription', 'alwaysshowdescription', 'assign');
     $mform->disabledIf('alwaysshowdescription', 'allowsubmissionsfromdate[enabled]', 'notchecked');
     $assignment->add_all_plugin_settings($mform);
     $mform->addElement('header', 'submissionsettings', get_string('submissionsettings', 'assign'));
     $name = get_string('submissiondrafts', 'assign');
     $mform->addElement('selectyesno', 'submissiondrafts', $name);
     $mform->addHelpButton('submissiondrafts', 'submissiondrafts', 'assign');
     $name = get_string('requiresubmissionstatement', 'assign');
     $mform->addElement('selectyesno', 'requiresubmissionstatement', $name);
     $mform->addHelpButton('requiresubmissionstatement', 'requiresubmissionstatement', 'assign');
     $mform->setType('requiresubmissionstatement', PARAM_BOOL);
     $options = array(ASSIGN_ATTEMPT_REOPEN_METHOD_NONE => get_string('attemptreopenmethod_none', 'mod_assign'), ASSIGN_ATTEMPT_REOPEN_METHOD_MANUAL => get_string('attemptreopenmethod_manual', 'mod_assign'), ASSIGN_ATTEMPT_REOPEN_METHOD_UNTILPASS => get_string('attemptreopenmethod_untilpass', 'mod_assign'));
     $mform->addElement('select', 'attemptreopenmethod', get_string('attemptreopenmethod', 'mod_assign'), $options);
     $mform->addHelpButton('attemptreopenmethod', 'attemptreopenmethod', 'mod_assign');
     $options = array(ASSIGN_UNLIMITED_ATTEMPTS => get_string('unlimitedattempts', 'mod_assign'));
     $options += array_combine(range(1, 30), range(1, 30));
     $mform->addElement('select', 'maxattempts', get_string('maxattempts', 'mod_assign'), $options);
     $mform->addHelpButton('maxattempts', 'maxattempts', 'assign');
     $mform->disabledIf('maxattempts', 'attemptreopenmethod', 'eq', ASSIGN_ATTEMPT_REOPEN_METHOD_NONE);
     $mform->addElement('header', 'groupsubmissionsettings', get_string('groupsubmissionsettings', 'assign'));
     $name = get_string('teamsubmission', 'assign');
     $mform->addElement('selectyesno', 'teamsubmission', $name);
     $mform->addHelpButton('teamsubmission', 'teamsubmission', 'assign');
     if ($assignment->has_submissions_or_grades()) {
         $mform->freeze('teamsubmission');
     }
     $name = get_string('requireallteammemberssubmit', 'assign');
     $mform->addElement('selectyesno', 'requireallteammemberssubmit', $name);
     $mform->addHelpButton('requireallteammemberssubmit', 'requireallteammemberssubmit', 'assign');
     $mform->disabledIf('requireallteammemberssubmit', 'teamsubmission', 'eq', 0);
     $mform->disabledIf('requireallteammemberssubmit', 'submissiondrafts', 'eq', 0);
     $groupings = groups_get_all_groupings($assignment->get_course()->id);
     $options = array();
     $options[0] = get_string('none');
     foreach ($groupings as $grouping) {
         $options[$grouping->id] = $grouping->name;
     }
     $name = get_string('teamsubmissiongroupingid', 'assign');
     $mform->addElement('select', 'teamsubmissiongroupingid', $name, $options);
     $mform->addHelpButton('teamsubmissiongroupingid', 'teamsubmissiongroupingid', 'assign');
     $mform->disabledIf('teamsubmissiongroupingid', 'teamsubmission', 'eq', 0);
     if ($assignment->has_submissions_or_grades()) {
         $mform->freeze('teamsubmissiongroupingid');
     }
     $mform->addElement('header', 'notifications', get_string('notifications', 'assign'));
     $name = get_string('sendnotifications', 'assign');
     $mform->addElement('selectyesno', 'sendnotifications', $name);
     $mform->addHelpButton('sendnotifications', 'sendnotifications', 'assign');
     $name = get_string('sendlatenotifications', 'assign');
     $mform->addElement('selectyesno', 'sendlatenotifications', $name);
     $mform->addHelpButton('sendlatenotifications', 'sendlatenotifications', 'assign');
     $mform->disabledIf('sendlatenotifications', 'sendnotifications', 'eq', 1);
     $name = get_string('sendstudentnotificationsdefault', 'assign');
     $mform->addElement('selectyesno', 'sendstudentnotifications', $name);
     $mform->addHelpButton('sendstudentnotifications', 'sendstudentnotificationsdefault', 'assign');
     // Plagiarism enabling form.
     if (!empty($CFG->enableplagiarism)) {
         require_once $CFG->libdir . '/plagiarismlib.php';
         plagiarism_get_form_elements_module($mform, $ctx->get_course_context(), 'mod_assign');
     }
     $this->standard_grading_coursemodule_elements();
     $name = get_string('blindmarking', 'assign');
     $mform->addElement('selectyesno', 'blindmarking', $name);
     $mform->addHelpButton('blindmarking', 'blindmarking', 'assign');
     if ($assignment->has_submissions_or_grades()) {
         $mform->freeze('blindmarking');
     }
     $name = get_string('markingworkflow', 'assign');
     $mform->addElement('selectyesno', 'markingworkflow', $name);
     $mform->addHelpButton('markingworkflow', 'markingworkflow', 'assign');
     $name = get_string('markingallocation', 'assign');
     $mform->addElement('selectyesno', 'markingallocation', $name);
     $mform->addHelpButton('markingallocation', 'markingallocation', 'assign');
     $mform->disabledIf('markingallocation', 'markingworkflow', 'eq', 0);
     $this->standard_coursemodule_elements();
     $this->apply_admin_defaults();
     $this->add_action_buttons();
     // Add warning popup/noscript tag, if grades are changed by user.
     $hasgrade = false;
     if (!empty($this->_instance)) {
         $hasgrade = $DB->record_exists_select('assign_grades', 'assignment = ? AND grade <> -1', array($this->_instance));
     }
     if ($mform->elementExists('grade') && $hasgrade) {
         $module = array('name' => 'mod_assign', 'fullpath' => '/mod/assign/module.js', 'requires' => array('node', 'event'), 'strings' => array(array('changegradewarning', 'mod_assign')));
         $PAGE->requires->js_init_call('M.mod_assign.init_grade_change', null, false, $module);
         // Add noscript tag in case.
         $noscriptwarning = $mform->createElement('static', 'warning', null, html_writer::tag('noscript', get_string('changegradewarning', 'mod_assign')));
         $mform->insertElementBefore($noscriptwarning, 'grade');
     }
 }
示例#4
0
    /**
     * Called to define this moodle form
     *
     * @return void
     */
    function definition() {
        global $CFG, $DB, $PAGE;
        $mform = $this->_form;

        $mform->addElement('header', 'general', get_string('general', 'form'));

        $mform->addElement('text', 'name', get_string('assignmentname', 'assign'), array('size'=>'64'));
        if (!empty($CFG->formatstringstriptags)) {
            $mform->setType('name', PARAM_TEXT);
        } else {
            $mform->setType('name', PARAM_CLEANHTML);
        }
        $mform->addRule('name', null, 'required', null, 'client');

        $this->add_intro_editor(true, get_string('description', 'assign'));

        $ctx = null;
        if ($this->current && $this->current->coursemodule) {
            $cm = get_coursemodule_from_instance('assign', $this->current->id, 0, false, MUST_EXIST);
            $ctx = context_module::instance($cm->id);
        }
        $assignment = new assign($ctx, null, null);
        if ($this->current && $this->current->course) {
            if (!$ctx) {
                $ctx = context_course::instance($this->current->course);
            }
            $assignment->set_course($DB->get_record('course', array('id'=>$this->current->course), '*', MUST_EXIST));
        }

        $config = get_config('assign');

        $mform->addElement('header', 'general', get_string('settings', 'assign'));
        $mform->addElement('date_time_selector', 'allowsubmissionsfromdate', get_string('allowsubmissionsfromdate', 'assign'), array('optional'=>true));
        $mform->addHelpButton('allowsubmissionsfromdate', 'allowsubmissionsfromdate', 'assign');
        $mform->setDefault('allowsubmissionsfromdate', time());
        $mform->addElement('date_time_selector', 'duedate', get_string('duedate', 'assign'), array('optional'=>true));
        $mform->addHelpButton('duedate', 'duedate', 'assign');
        $mform->setDefault('duedate', time()+7*24*3600);
        $mform->addElement('date_time_selector', 'cutoffdate', get_string('cutoffdate', 'assign'), array('optional'=>true));
        $mform->addHelpButton('cutoffdate', 'cutoffdate', 'assign');
        $mform->setDefault('cutoffdate', time()+7*24*3600);
        $mform->addElement('selectyesno', 'alwaysshowdescription', get_string('alwaysshowdescription', 'assign'));
        $mform->addHelpButton('alwaysshowdescription', 'alwaysshowdescription', 'assign');
        $mform->setDefault('alwaysshowdescription', 1);
        $mform->addElement('selectyesno', 'submissiondrafts', get_string('submissiondrafts', 'assign'));
        $mform->addHelpButton('submissiondrafts', 'submissiondrafts', 'assign');
        $mform->setDefault('submissiondrafts', 0);
        // submission statement
        if (empty($config->requiresubmissionstatement)) {
            $mform->addElement('selectyesno', 'requiresubmissionstatement', get_string('requiresubmissionstatement', 'assign'));
            $mform->setDefault('requiresubmissionstatement', 0);
            $mform->addHelpButton('requiresubmissionstatement', 'requiresubmissionstatement', 'assign');
        } else {
            $mform->addElement('hidden', 'requiresubmissionstatement', 1);
        }

        $mform->addElement('selectyesno', 'sendnotifications', get_string('sendnotifications', 'assign'));
        $mform->addHelpButton('sendnotifications', 'sendnotifications', 'assign');
        $mform->setDefault('sendnotifications', 1);
        $mform->addElement('selectyesno', 'sendlatenotifications', get_string('sendlatenotifications', 'assign'));
        $mform->addHelpButton('sendlatenotifications', 'sendlatenotifications', 'assign');
        $mform->setDefault('sendlatenotifications', 1);
        $mform->disabledIf('sendlatenotifications', 'sendnotifications', 'eq', 1);
        $mform->addElement('selectyesno', 'teamsubmission', get_string('teamsubmission', 'assign'));
        $mform->addHelpButton('teamsubmission', 'teamsubmission', 'assign');
        $mform->setDefault('teamsubmission', 0);
        $mform->addElement('selectyesno', 'requireallteammemberssubmit', get_string('requireallteammemberssubmit', 'assign'));
        $mform->addHelpButton('requireallteammemberssubmit', 'requireallteammemberssubmit', 'assign');
        $mform->setDefault('requireallteammemberssubmit', 0);
        $mform->disabledIf('requireallteammemberssubmit', 'teamsubmission', 'eq', 0);
        $mform->disabledIf('requireallteammemberssubmit', 'submissiondrafts', 'eq', 0);

        $groupings = groups_get_all_groupings($assignment->get_course()->id);
        $options = array();
        $options[0] = get_string('none');
        foreach ($groupings as $grouping) {
            $options[$grouping->id] = $grouping->name;
        }
        $mform->addElement('select', 'teamsubmissiongroupingid', get_string('teamsubmissiongroupingid', 'assign'), $options);
        $mform->addHelpButton('teamsubmissiongroupingid', 'teamsubmissiongroupingid', 'assign');
        $mform->setDefault('teamsubmissiongroupingid', 0);
        $mform->disabledIf('teamsubmissiongroupingid', 'teamsubmission', 'eq', 0);

        $mform->addElement('selectyesno', 'blindmarking', get_string('blindmarking', 'assign'));
        $mform->addHelpButton('blindmarking', 'blindmarking', 'assign');
        $mform->setDefault('blindmarking', 0);
        if ($assignment->has_submissions_or_grades() ) {
            $mform->freeze('blindmarking');
        }


        // plagiarism enabling form
        if (!empty($CFG->enableplagiarism)) {
            /** Include plagiarismlib.php */
            require_once($CFG->libdir . '/plagiarismlib.php');
            plagiarism_get_form_elements_module($mform, $ctx->get_course_context(), 'mod_assign');
        }

        $assignment->add_all_plugin_settings($mform);
        $this->standard_grading_coursemodule_elements();
        $this->standard_coursemodule_elements();

        $this->add_action_buttons();

        // Add warning popup/noscript tag, if grades are changed by user.
        if ($mform->elementExists('grade') && !empty($this->_instance) && $DB->record_exists_select('assign_grades', 'assignment = ? AND grade <> -1', array($this->_instance))) {
            $module = array(
                'name' => 'mod_assign',
                'fullpath' => '/mod/assign/module.js',
                'requires' => array('node', 'event'),
                'strings' => array(array('changegradewarning', 'mod_assign'))
                );
            $PAGE->requires->js_init_call('M.mod_assign.init_grade_change', null, false, $module);

            // Add noscript tag in case
            $noscriptwarning = $mform->createElement('static', 'warning', null,  html_writer::tag('noscript', get_string('changegradewarning', 'mod_assign')));
            $mform->insertElementBefore($noscriptwarning, 'grade');
        }
    }
function plagiarism_urkund_check_group($plagiarismfile)
{
    global $DB, $CFG;
    require_once "{$CFG->dirroot}/mod/assign/locallib.php";
    $modulecontext = context_module::instance($plagiarismfile->cm);
    $assign = new assign($modulecontext, false, false);
    if (!empty($assign->get_instance()->teamsubmission)) {
        mtrace("URKUND fileid:" . $plagiarismfile->id . " Group submission detected.");
        $mygroups = groups_get_user_groups($assign->get_course()->id, $plagiarismfile->userid);
        if (count($mygroups) == 1) {
            $groupid = reset($mygroups)[0];
            // Only users with single groups are supported - otherwise just use the normal userid on this record.
            // Get all users from this group.
            $userids = array();
            $users = groups_get_members($groupid, 'u.id');
            foreach ($users as $u) {
                $userids[] = $u->id;
            }
            if (!empty($userids)) {
                // Find the earliest plagiarism record for this cm with any of these users.
                $sql = 'cm = ? AND userid IN (' . implode(',', $userids) . ')';
                $previousfiles = $DB->get_records_select('plagiarism_urkund_files', $sql, array($plagiarismfile->cm), 'id');
                $sanitycheckusers = 10;
                // Search through this number of users to find a valid previous submission.
                $i = 0;
                foreach ($previousfiles as $pf) {
                    if ($pf->userid == $plagiarismfile->userid) {
                        return $plagiarismfile;
                    }
                    // Sanity Check to make sure the user isn't in multiple groups.
                    $pfgroups = groups_get_user_groups($assign->get_course()->id, $pf->userid);
                    if (count($pfgroups) == 1) {
                        // This user made the first valid submission so use their id when sending the file.
                        $plagiarismfile->userid = $pf->userid;
                        mtrace("URKUND: Group submission by newuser, modify to use original userid:" . $pf->userid . " id:" . $plagiarismfile->id);
                        return $plagiarismfile;
                    }
                    if ($i >= $sanitycheckusers) {
                        // Don't cause a massive loop here and break at a sensible limit.
                        return $plagiarismfile;
                    }
                    $i++;
                }
            }
        }
    }
    return $plagiarismfile;
}
 /**
  * Generic handler function for all events - triggers sending of files.
  * @return boolean
  */
 public function event_handler($eventdata)
 {
     global $DB, $CFG;
     $supportedevents = urkund_supported_events();
     if (!in_array($eventdata->eventtype, $supportedevents)) {
         return true;
         // Don't need to handle this event.
     }
     $plagiarismsettings = $this->get_settings();
     if (!$plagiarismsettings) {
         return true;
     }
     $cmid = !empty($eventdata->cm->id) ? $eventdata->cm->id : $eventdata->cmid;
     $plagiarismvalues = $DB->get_records_menu('plagiarism_urkund_config', array('cm' => $cmid), '', 'name, value');
     if (empty($plagiarismvalues['use_urkund'])) {
         // Urkund not in use for this cm - return.
         return true;
     }
     // Check if the module associated with this event still exists.
     if (!$DB->record_exists('course_modules', array('id' => $eventdata->cmid))) {
         return true;
     }
     if ($eventdata->eventtype == 'files_done' || $eventdata->eventtype == 'content_done' || $eventdata->eventtype == 'assessable_submitted' && $eventdata->params['submission_editable'] == false) {
         // Assignment-specific functionality:
         // This is a 'finalize' event. No files from this event itself,
         // but need to check if files from previous events need to be submitted for processing.
         mtrace("finalise");
         $result = true;
         if (isset($plagiarismvalues['urkund_draft_submit']) && $plagiarismvalues['urkund_draft_submit'] == PLAGIARISM_URKUND_DRAFTSUBMIT_FINAL) {
             // Any files attached to previous events were not submitted.
             // These files are now finalized, and should be submitted for processing.
             if ($eventdata->modulename == 'assignment') {
                 // Hack to include filelib so that file_storage class is available.
                 require_once "{$CFG->dirroot}/mod/assignment/lib.php";
                 // We need to get a list of files attached to this assignment and put them in an array, so that
                 // we can submit each of them for processing.
                 $assignmentbase = new assignment_base($cmid);
                 $submission = $assignmentbase->get_submission($eventdata->userid);
                 $modulecontext = context_module::instance($eventdata->cmid);
                 $fs = get_file_storage();
                 if ($files = $fs->get_area_files($modulecontext->id, 'mod_assignment', 'submission', $submission->id, "timemodified", false)) {
                     foreach ($files as $file) {
                         $sendresult = urkund_send_file($cmid, $eventdata->userid, $file, $plagiarismsettings);
                         $result = $result && $sendresult;
                     }
                 }
             } else {
                 if ($eventdata->modulename == 'assign') {
                     require_once "{$CFG->dirroot}/mod/assign/locallib.php";
                     require_once "{$CFG->dirroot}/mod/assign/submission/file/locallib.php";
                     $modulecontext = context_module::instance($eventdata->cmid);
                     $fs = get_file_storage();
                     if ($files = $fs->get_area_files($modulecontext->id, 'assignsubmission_file', ASSIGNSUBMISSION_FILE_FILEAREA, $eventdata->itemid, "id", false)) {
                         foreach ($files as $file) {
                             $sendresult = urkund_send_file($cmid, $eventdata->userid, $file, $plagiarismsettings);
                             $result = $result && $sendresult;
                         }
                     }
                     $submission = $DB->get_record('assignsubmission_onlinetext', array('submission' => $eventdata->itemid));
                     if (!empty($submission)) {
                         $eventdata->content = trim(format_text($submission->onlinetext, $submission->onlineformat, array('context' => $modulecontext)));
                         $file = urkund_create_temp_file($cmid, $eventdata);
                         $sendresult = urkund_send_file($cmid, $eventdata->userid, $file, $plagiarismsettings);
                         $result = $result && $sendresult;
                         unlink($file->filepath);
                         // Delete temp file.
                     }
                 }
             }
         }
         return $result;
     }
     if (isset($plagiarismvalues['urkund_draft_submit']) && $plagiarismvalues['urkund_draft_submit'] == PLAGIARISM_URKUND_DRAFTSUBMIT_FINAL) {
         // Assignment-specific functionality:
         // Files should only be sent for checking once "finalized".
         return true;
     }
     // Text is attached.
     $result = true;
     if (!empty($eventdata->content)) {
         $file = urkund_create_temp_file($cmid, $eventdata);
         $sendresult = urkund_send_file($cmid, $eventdata->userid, $file, $plagiarismsettings);
         $result = $result && $sendresult;
         unlink($file->filepath);
         // Delete temp file.
     }
     // Normal situation: 1 or more assessable files attached to event, ready to be checked.
     if (!empty($eventdata->pathnamehashes)) {
         foreach ($eventdata->pathnamehashes as $hash) {
             $fs = get_file_storage();
             $efile = $fs->get_file_by_hash($hash);
             if (empty($efile)) {
                 mtrace("nofilefound!");
                 continue;
             } else {
                 if ($efile->get_filename() === '.') {
                     // This 'file' is actually a directory - nothing to submit.
                     continue;
                 }
             }
             // Check if assign group submission is being used.
             if ($eventdata->modulename == 'assign') {
                 require_once "{$CFG->dirroot}/mod/assign/locallib.php";
                 $modulecontext = context_module::instance($eventdata->cmid);
                 $assign = new assign($modulecontext, false, false);
                 if (!empty($assign->get_instance()->teamsubmission)) {
                     $mygroups = groups_get_user_groups($assign->get_course()->id, $eventdata->userid);
                     if (count($mygroups) == 1) {
                         $groupid = reset($mygroups)[0];
                         // Only users with single groups are supported - otherwise just use the normal userid on this record.
                         // Get all users from this group.
                         $userids = array();
                         $users = groups_get_members($groupid, 'u.id');
                         foreach ($users as $u) {
                             $userids[] = $u->id;
                         }
                         // Find the earliest plagiarism record for this cm with any of these users.
                         $sql = 'cm = ? AND userid IN (' . implode(',', $userids) . ')';
                         $previousfiles = $DB->get_records_select('plagiarism_urkund_files', $sql, array($eventdata->cmid), 'id');
                         $sanitycheckusers = 10;
                         // Search through this number of users to find a valid previous submission.
                         $i = 0;
                         foreach ($previousfiles as $pf) {
                             if ($pf->userid == $eventdata->userid) {
                                 break;
                                 // The submission comes from this user so break.
                             }
                             // Sanity Check to make sure the user isn't in multiple groups.
                             $pfgroups = groups_get_user_groups($assign->get_course()->id, $pf->userid);
                             if (count($pfgroups) == 1) {
                                 // This user made the first valid submission so use their id when sending the file.
                                 $eventdata->userid = $pf->userid;
                                 break;
                             }
                             if ($i >= $sanitycheckusers) {
                                 // don't cause a massive loop here and break at a sensible limit.
                                 break;
                             }
                             $i++;
                         }
                     }
                 }
             }
             $sendresult = urkund_send_file($cmid, $eventdata->userid, $efile, $plagiarismsettings);
             $result = $result && $sendresult;
         }
     }
     return $result;
 }