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