예제 #1
0
 /**
  *  Test the subscribers_viewed event.
  */
 public function test_subscribers_viewed()
 {
     // Setup test data.
     $course = $this->getDataGenerator()->create_course();
     $anonforum = $this->getDataGenerator()->create_module('anonforum', array('course' => $course->id));
     $context = context_module::instance($anonforum->cmid);
     $params = array('context' => $context, 'other' => array('anonforumid' => $anonforum->id));
     $event = \mod_anonforum\event\subscribers_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_anonforum\\event\\subscribers_viewed', $event);
     $this->assertEquals($context, $event->get_context());
     $expected = array($course->id, 'anonforum', 'view subscribers', "subscribers.php?id={$anonforum->id}", $anonforum->id, $anonforum->cmid);
     $this->assertEventLegacyLogData($expected, $event);
     $this->assertEventContextNotUsed($event);
     $this->assertNotEmpty($event->get_name());
 }
예제 #2
0
}
$PAGE->set_url($url);
$anonforum = $DB->get_record('anonforum', array('id' => $id), '*', MUST_EXIST);
$course = $DB->get_record('course', array('id' => $anonforum->course), '*', MUST_EXIST);
if (!($cm = get_coursemodule_from_instance('anonforum', $anonforum->id, $course->id))) {
    $cm->id = 0;
}
require_login($course, false, $cm);
$context = context_module::instance($cm->id);
if (!has_capability('mod/anonforum:viewsubscribers', $context)) {
    print_error('nopermissiontosubscribe', 'anonforum');
}
unset($SESSION->fromdiscussion);
if (empty($anonforum->anonymous)) {
    $params = array('context' => $context, 'anonymous' => 1, 'other' => array('anonforumid' => $anonforum->id));
    $event = \mod_anonforum\event\subscribers_viewed::create($params);
    $event->trigger();
}
$anonforumoutput = $PAGE->get_renderer('mod_anonforum');
$currentgroup = groups_get_activity_group($cm);
$options = array('anonforumid' => $anonforum->id, 'currentgroup' => $currentgroup, 'context' => $context);
$existingselector = new anonforum_existing_subscriber_selector('existingsubscribers', $options);
$subscriberselector = new anonforum_potential_subscriber_selector('potentialsubscribers', $options);
$subscriberselector->set_existing_subscribers($existingselector->find_users(''));
if (data_submitted()) {
    require_sesskey();
    $subscribe = (bool) optional_param('subscribe', false, PARAM_RAW);
    $unsubscribe = (bool) optional_param('unsubscribe', false, PARAM_RAW);
    // It has to be one or the other, not both or neither.
    if (!($subscribe xor $unsubscribe)) {
        print_error('invalidaction');