Ejemplo n.º 1
0
    $url->param('edit', $edit);
}
$PAGE->set_url($url);
$twf = $DB->get_record('twf', array('id' => $id), '*', MUST_EXIST);
$course = $DB->get_record('course', array('id' => $twf->course), '*', MUST_EXIST);
if (!($cm = get_coursemodule_from_instance('twf', $twf->id, $course->id))) {
    $cm->id = 0;
}
require_login($course, false, $cm);
$context = context_module::instance($cm->id);
if (!has_capability('mod/twf:viewsubscribers', $context)) {
    print_error('nopermissiontosubscribe', 'twf');
}
unset($SESSION->fromdiscussion);
$params = array('context' => $context, 'other' => array('twfid' => $twf->id));
$event = \mod_twf\event\subscribers_viewed::create($params);
$event->trigger();
$twfoutput = $PAGE->get_renderer('mod_twf');
$currentgroup = groups_get_activity_group($cm);
$options = array('twfid' => $twf->id, 'currentgroup' => $currentgroup, 'context' => $context);
$existingselector = new mod_twf_existing_subscriber_selector('existingsubscribers', $options);
$subscriberselector = new mod_twf_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');
    }
Ejemplo n.º 2
0
 /**
  *  Test the subscribers_viewed event.
  */
 public function test_subscribers_viewed()
 {
     // Setup test data.
     $course = $this->getDataGenerator()->create_course();
     $twf = $this->getDataGenerator()->create_module('twf', array('course' => $course->id));
     $context = context_module::instance($twf->cmid);
     $params = array('context' => $context, 'other' => array('twfid' => $twf->id));
     $event = \mod_twf\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_twf\\event\\subscribers_viewed', $event);
     $this->assertEquals($context, $event->get_context());
     $expected = array($course->id, 'twf', 'view subscribers', "subscribers.php?id={$twf->id}", $twf->id, $twf->cmid);
     $this->assertEventLegacyLogData($expected, $event);
     $this->assertEventContextNotUsed($event);
     $this->assertNotEmpty($event->get_name());
 }