示例#1
0
 /**
  * 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_teamwork\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, 'teamwork', 'add submission', 'submission.php?cmid=' . $this->cm->id . '&id=' . $submissionid, $submissionid, $this->cm->id);
     $this->assertEventLegacyLogData($expected, $event);
     $this->assertEventContextNotUsed($event);
     $sink->close();
 }
示例#2
0
 // updated later
 $formdata->late = 0x0;
 // bit mask
 if (!empty($teamwork->submissionend) and $teamwork->submissionend < time()) {
     $formdata->late = $formdata->late | 0x1;
 }
 if ($teamwork->phase == teamwork::PHASE_ASSESSMENT) {
     $formdata->late = $formdata->late | 0x2;
 }
 // Event information.
 $params = array('context' => $teamwork->context, 'courseid' => $teamwork->course->id, 'other' => array('submissiontitle' => $formdata->title));
 $logdata = null;
 if (is_null($submission->id)) {
     $submission->id = $formdata->id = $DB->insert_record('teamwork_submissions', $formdata);
     $params['objectid'] = $submission->id;
     $event = \mod_teamwork\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', 'teamwork');
     }
 }
 $params['objectid'] = $submission->id;
 // save and relink embedded images and save attachments
 $formdata = file_postupdate_standard_editor($formdata, 'content', $contentopts, $teamwork->context, 'mod_teamwork', 'submission_content', $submission->id);
 $formdata = file_postupdate_standard_filemanager($formdata, 'attachment', $attachmentopts, $teamwork->context, 'mod_teamwork', '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)