// updated later $formdata->late = 0x0; // bit mask if (!empty($workshop->submissionend) and $workshop->submissionend < time()) { $formdata->late = $formdata->late | 0x1; } if ($workshop->phase == workshop::PHASE_ASSESSMENT) { $formdata->late = $formdata->late | 0x2; } // Event information. $params = array('context' => $workshop->context, 'courseid' => $workshop->course->id, 'other' => array('submissiontitle' => $formdata->title)); $logdata = null; if (is_null($submission->id)) { $submission->id = $formdata->id = $DB->insert_record('workshop_submissions', $formdata); $params['objectid'] = $submission->id; $event = \mod_workshop\event\submission_created::create($params); $event->trigger(); } else { if (empty($formdata->id) or empty($submission->id) or $formdata->id != $submission->id) { throw new moodle_exception('err_submissionid', 'workshop'); } } $params['objectid'] = $submission->id; // save and relink embedded images and save attachments $formdata = file_postupdate_standard_editor($formdata, 'content', $contentopts, $workshop->context, 'mod_workshop', 'submission_content', $submission->id); $formdata = file_postupdate_standard_filemanager($formdata, 'attachment', $attachmentopts, $workshop->context, 'mod_workshop', 'submission_attachment', $submission->id); if (empty($formdata->attachment)) { // explicit cast to zero integer $formdata->attachment = 0; } // store the updated values or re-save the new submission (re-saving needed because URLs are now rewritten)
/** * There is no api involved so the best we can do is test legacy data by triggering event manually. */ public function test_submission_created_event() { $this->resetAfterTest(); $this->setAdminUser(); $user = $this->getDataGenerator()->create_user(); $submissionid = 48; $event = \mod_workshop\event\submission_created::create(array('objectid' => $submissionid, 'context' => $this->context, 'courseid' => $this->course->id, 'relateduserid' => $user->id, 'other' => array('submissiontitle' => 'The submission title'))); // Trigger and capture the event. $sink = $this->redirectEvents(); $event->trigger(); $events = $sink->get_events(); $event = reset($events); // Check that the legacy log data is valid. $expected = array($this->course->id, 'workshop', 'add submission', 'submission.php?cmid=' . $this->cm->id . '&id=' . $submissionid, $submissionid, $this->cm->id); $this->assertEventLegacyLogData($expected, $event); $this->assertEventContextNotUsed($event); $sink->close(); }