$course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST); require_login($course, false, $cm); if (isguestuser()) { print_error('guestsarenotallowed'); } $workshoprecord = $DB->get_record('workshop', array('id' => $cm->instance), '*', MUST_EXIST); $workshop = new workshop($workshoprecord, $cm, $course); $PAGE->set_url($workshop->submission_url(), array('cmid' => $cmid, 'id' => $id)); if ($edit) { $PAGE->url->param('edit', $edit); } if ($id) { // submission is specified $submission = $workshop->get_submission_by_id($id); $params = array('objectid' => $submission->id, 'context' => $workshop->context, 'courseid' => $workshop->course->id, 'relateduserid' => $submission->authorid, 'other' => array('workshopid' => $workshop->id)); $event = \mod_workshop\event\submission_viewed::create($params); $event->trigger(); } else { // no submission specified if (!($submission = $workshop->get_submission_by_author($USER->id))) { $submission = new stdclass(); $submission->id = null; $submission->authorid = $USER->id; $submission->example = 0; $submission->grade = null; $submission->gradeover = null; $submission->published = null; $submission->feedbackauthor = null; $submission->feedbackauthorformat = editors_get_preferred_format(); } }
/** * There is no api involved so the best we can do is test legacy data by triggering event manually. */ public function test_submission_viewed_event() { $this->resetAfterTest(); $this->setAdminUser(); $user = $this->getDataGenerator()->create_user(); $submissionid = 48; $event = \mod_workshop\event\submission_viewed::create(array('objectid' => $submissionid, 'context' => $this->context, 'courseid' => $this->course->id, 'relateduserid' => $user->id, 'other' => array('workshopid' => $this->workshop->id))); // 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', 'view submission', 'submission.php?cmid=' . $this->cm->id . '&id=' . $submissionid, $submissionid, $this->cm->id); $this->assertEventLegacyLogData($expected, $event); $this->assertEventContextNotUsed($event); $sink->close(); }