/** 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 array $attemptids list of attempts that need to be deleted * @param int $scorm instance * * return bool true deleted all responses, false failed deleting an attempt - stopped here */ function scorm_delete_responses($attemptids, $scorm) { if (!is_array($attemptids) || empty($attemptids)) { return false; } foreach ($attemptids as $num => $attemptid) { if (empty($attemptid)) { unset($attemptids[$num]); } } foreach ($attemptids as $attempt) { $keys = explode(':', $attempt); if (count($keys) == 2) { $userid = clean_param($keys[0], PARAM_INT); $attemptid = clean_param($keys[1], PARAM_INT); if (!$userid || !$attemptid || !scorm_delete_attempt($userid, $scorm, $attemptid)) { return false; } } else { return false; } } return true; }