示例#1
0
    // Delete the existing per-discussion subscriptions and replace them with the newly calculated ones.
    $DB->delete_records('quora_discussion_subs', array('discussion' => $discussion->id));
    $newdiscussion = clone $discussion;
    $newdiscussion->quora = $quorato->id;
    foreach ($subscriptionchanges as $userid => $preference) {
        if ($preference != \mod_quora\subscriptions::FORUM_DISCUSSION_UNSUBSCRIBED) {
            // Users must have viewdiscussion to a discussion.
            if (has_capability('mod/quora:viewdiscussion', $destinationctx, $userid)) {
                \mod_quora\subscriptions::subscribe_user_to_discussion($userid, $newdiscussion, $destinationctx);
            }
        } else {
            \mod_quora\subscriptions::unsubscribe_user_from_discussion($userid, $newdiscussion, $destinationctx);
        }
    }
    $params = array('context' => $destinationctx, 'objectid' => $discussion->id, 'other' => array('fromquoraid' => $quora->id, 'toquoraid' => $quorato->id));
    $event = \mod_quora\event\discussion_moved::create($params);
    $event->add_record_snapshot('quora_discussions', $discussion);
    $event->add_record_snapshot('quora', $quora);
    $event->add_record_snapshot('quora', $quorato);
    $event->trigger();
    // Delete the RSS files for the 2 quoras to force regeneration of the feeds
    require_once $CFG->dirroot . '/mod/quora/rsslib.php';
    quora_rss_delete_file($quora);
    quora_rss_delete_file($quorato);
    redirect($return . '&moved=-1&sesskey=' . sesskey());
}
// Trigger discussion viewed event.
quora_discussion_view($modcontext, $quora, $discussion);
unset($SESSION->fromdiscussion);
if ($mode) {
    set_user_preference('quora_displaymode', $mode);
示例#2
0
 /**
  * Test discussion_moved event.
  */
 public function test_discussion_moved()
 {
     // Setup test data.
     $course = $this->getDataGenerator()->create_course();
     $fromquora = $this->getDataGenerator()->create_module('quora', array('course' => $course->id));
     $toquora = $this->getDataGenerator()->create_module('quora', array('course' => $course->id));
     $user = $this->getDataGenerator()->create_user();
     // Add a discussion.
     $record = array();
     $record['course'] = $course->id;
     $record['quora'] = $fromquora->id;
     $record['userid'] = $user->id;
     $discussion = $this->getDataGenerator()->get_plugin_generator('mod_quora')->create_discussion($record);
     $context = context_module::instance($toquora->cmid);
     $params = array('context' => $context, 'objectid' => $discussion->id, 'other' => array('fromquoraid' => $fromquora->id, 'toquoraid' => $toquora->id));
     $event = \mod_quora\event\discussion_moved::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\\discussion_moved', $event);
     $this->assertEquals($context, $event->get_context());
     $expected = array($course->id, 'quora', 'move discussion', "discuss.php?d={$discussion->id}", $discussion->id, $toquora->cmid);
     $this->assertEventLegacyLogData($expected, $event);
     $this->assertEventContextNotUsed($event);
     $this->assertNotEmpty($event->get_name());
 }