/** Tests for attempt deleted event */ public function test_attempt_deleted_event() { global $USER; $this->resetAfterTest(); scorm_insert_track(2, $this->eventscorm->id, 1, 4, 'cmi.core.score.raw', 10); $sink = $this->redirectEvents(); scorm_delete_attempt(2, $this->eventscorm, 4); $events = $sink->get_events(); $sink->close(); $event = reset($events); // Verify data. $this->assertCount(3, $events); $this->assertInstanceOf('\\mod_scorm\\event\\attempt_deleted', $event); $this->assertEquals($USER->id, $event->userid); $this->assertEquals(context_module::instance($this->eventcm->id), $event->get_context()); $this->assertEquals(4, $event->other['attemptid']); $this->assertEquals(2, $event->relateduserid); $expected = array($this->eventcourse->id, 'scorm', 'delete attempts', 'report.php?id=' . $this->eventcm->id, 4, $this->eventcm->id); $this->assertEventLegacyLogData($expected, $events[0]); $this->assertEventContextNotUsed($event); // Test event validations. $this->setExpectedException('coding_exception'); \mod_scorm\event\attempt_deleted::create(array('contextid' => 5, 'relateduserid' => 2)); $this->fail('event \\mod_scorm\\event\\attempt_deleted is not validating events properly'); }
/** * Delete Scorm tracks for selected users * * @param int $userid ID of User * @param stdClass $scorm Scorm object * @param int $attemptid user attempt that need to be deleted * * @return bool true suceeded */ function scorm_delete_attempt($userid, $scorm, $attemptid) { global $DB; $DB->delete_records('scorm_scoes_track', array('userid' => $userid, 'scormid' => $scorm->id, 'attempt' => $attemptid)); $cm = get_coursemodule_from_instance('scorm', $scorm->id); // Trigger instances list viewed event. $event = \mod_scorm\event\attempt_deleted::create(array( 'other' => array('attemptid' => $attemptid), 'context' => context_module::instance($cm->id), 'relateduserid' => $userid )); $event->add_record_snapshot('course_modules', $cm); $event->add_record_snapshot('scorm', $scorm); $event->trigger(); include_once('lib.php'); scorm_update_grades($scorm, $userid, true); return true; }