Ejemplo n.º 1
0
    // Delete the existing per-discussion subscriptions and replace them with the newly calculated ones.
    $DB->delete_records('twf_discussion_subs', array('discussion' => $discussion->id));
    $newdiscussion = clone $discussion;
    $newdiscussion->twf = $twfto->id;
    foreach ($subscriptionchanges as $userid => $preference) {
        if ($preference != \mod_twf\subscriptions::FORUM_DISCUSSION_UNSUBSCRIBED) {
            // Users must have viewdiscussion to a discussion.
            if (has_capability('mod/twf:viewdiscussion', $destinationctx, $userid)) {
                \mod_twf\subscriptions::subscribe_user_to_discussion($userid, $newdiscussion, $destinationctx);
            }
        } else {
            \mod_twf\subscriptions::unsubscribe_user_from_discussion($userid, $newdiscussion, $destinationctx);
        }
    }
    $params = array('context' => $destinationctx, 'objectid' => $discussion->id, 'other' => array('fromtwfid' => $twf->id, 'totwfid' => $twfto->id));
    $event = \mod_twf\event\discussion_moved::create($params);
    $event->add_record_snapshot('twf_discussions', $discussion);
    $event->add_record_snapshot('twf', $twf);
    $event->add_record_snapshot('twf', $twfto);
    $event->trigger();
    // Delete the RSS files for the 2 twfs to force regeneration of the feeds
    require_once $CFG->dirroot . '/mod/twf/rsslib.php';
    twf_rss_delete_file($twf);
    twf_rss_delete_file($twfto);
    redirect($return . '&moved=-1&sesskey=' . sesskey());
}
// Trigger discussion viewed event.
twf_discussion_view($modcontext, $twf, $discussion);
unset($SESSION->fromdiscussion);
if ($mode) {
    set_user_preference('twf_displaymode', $mode);
Ejemplo n.º 2
0
 /**
  * Test discussion_moved event.
  */
 public function test_discussion_moved()
 {
     // Setup test data.
     $course = $this->getDataGenerator()->create_course();
     $fromtwf = $this->getDataGenerator()->create_module('twf', array('course' => $course->id));
     $totwf = $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'] = $fromtwf->id;
     $record['userid'] = $user->id;
     $discussion = $this->getDataGenerator()->get_plugin_generator('mod_twf')->create_discussion($record);
     $context = context_module::instance($totwf->cmid);
     $params = array('context' => $context, 'objectid' => $discussion->id, 'other' => array('fromtwfid' => $fromtwf->id, 'totwfid' => $totwf->id));
     $event = \mod_twf\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_twf\\event\\discussion_moved', $event);
     $this->assertEquals($context, $event->get_context());
     $expected = array($course->id, 'twf', 'move discussion', "discuss.php?d={$discussion->id}", $discussion->id, $totwf->cmid);
     $this->assertEventLegacyLogData($expected, $event);
     $this->assertEventContextNotUsed($event);
     $this->assertNotEmpty($event->get_name());
 }