Example #1
0
 /**
  * Test discussion_viewed event.
  */
 public function test_discussion_viewed()
 {
     // Setup test data.
     $course = $this->getDataGenerator()->create_course();
     $twf = $this->getDataGenerator()->create_module('twf', array('course' => $course->id));
     $user = $this->getDataGenerator()->create_user();
     // Add a discussion.
     $record = array();
     $record['course'] = $course->id;
     $record['twf'] = $twf->id;
     $record['userid'] = $user->id;
     $discussion = $this->getDataGenerator()->get_plugin_generator('mod_twf')->create_discussion($record);
     $context = context_module::instance($twf->cmid);
     $params = array('context' => $context, 'objectid' => $discussion->id);
     $event = \mod_twf\event\discussion_viewed::create($params);
     // Trigger and capture the event.
     $sink = $this->redirectEvents();
     $event->trigger();
     $events = $sink->get_events();
     $this->assertCount(1, $events);
     $event = reset($events);
     // Checking that the event contains the expected values.
     $this->assertInstanceOf('\\mod_twf\\event\\discussion_viewed', $event);
     $this->assertEquals($context, $event->get_context());
     $expected = array($course->id, 'twf', 'view discussion', "discuss.php?d={$discussion->id}", $discussion->id, $twf->cmid);
     $this->assertEventLegacyLogData($expected, $event);
     $this->assertEventContextNotUsed($event);
     $this->assertNotEmpty($event->get_name());
 }
Example #2
0
/**
 * Trigger the discussion viewed event
 *
 * @param  stdClass $modcontext module context object
 * @param  stdClass $twf      twf object
 * @param  stdClass $discussion discussion object
 * @since Moodle 2.9
 */
function twf_discussion_view($modcontext, $twf, $discussion)
{
    $params = array('context' => $modcontext, 'objectid' => $discussion->id);
    $event = \mod_twf\event\discussion_viewed::create($params);
    $event->add_record_snapshot('twf_discussions', $discussion);
    $event->add_record_snapshot('twf', $twf);
    $event->trigger();
}