/** * Simulate the twf/discuss.php web interface page: trigger events * * @param int $discussionid the discussion id * @return array of warnings and status result * @since Moodle 2.9 * @throws moodle_exception */ public static function view_twf_discussion($discussionid) { global $DB, $CFG; require_once $CFG->dirroot . "/mod/twf/lib.php"; $params = self::validate_parameters(self::view_twf_discussion_parameters(), array('discussionid' => $discussionid)); $warnings = array(); $discussion = $DB->get_record('twf_discussions', array('id' => $params['discussionid']), '*', MUST_EXIST); $twf = $DB->get_record('twf', array('id' => $discussion->twf), '*', MUST_EXIST); list($course, $cm) = get_course_and_cm_from_instance($twf, 'twf'); // Validate the module context. It checks everything that affects the module visibility (including groupings, etc..). $modcontext = context_module::instance($cm->id); self::validate_context($modcontext); require_capability('mod/twf:viewdiscussion', $modcontext, null, true, 'noviewdiscussionspermission', 'twf'); // Call the twf/lib API. twf_discussion_view($modcontext, $twf, $discussion); $result = array(); $result['status'] = true; $result['warnings'] = $warnings; return $result; }
} } $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); } $displaymode = get_user_preferences('twf_displaymode', $CFG->twf_displaymode); if ($parent) { // If flat AND parent, then force nested display this time if ($displaymode == FORUM_MODE_FLATOLDEST or $displaymode == FORUM_MODE_FLATNEWEST) { $displaymode = FORUM_MODE_NESTED; } } else { $parent = $discussion->firstpost; } if (!($post = twf_get_post_full($parent))) { print_error("notexists", 'twf', "{$CFG->wwwroot}/mod/twf/view.php?f={$twf->id}");
/** * Test twf_discussion_view. */ public function test_twf_discussion_view() { global $CFG, $USER; $this->resetAfterTest(); // Setup test data. $course = $this->getDataGenerator()->create_course(); $twf = $this->getDataGenerator()->create_module('twf', array('course' => $course->id)); $discussion = $this->create_single_discussion_with_replies($twf, $USER, 2); $context = context_module::instance($twf->cmid); $cm = get_coursemodule_from_instance('twf', $twf->id); // Trigger and capture the event. $sink = $this->redirectEvents(); $this->setAdminUser(); twf_discussion_view($context, $twf, $discussion); $events = $sink->get_events(); $this->assertCount(1, $events); $event = array_pop($events); // Checking that the event contains the expected values. $this->assertInstanceOf('\\mod_twf\\event\\discussion_viewed', $event); $this->assertEquals($context, $event->get_context()); $expected = array($course->id, 'twf', 'view discussion', "discuss.php?d={$discussion->id}", $discussion->id, $twf->cmid); $this->assertEventLegacyLogData($expected, $event); $this->assertEventContextNotUsed($event); $this->assertNotEmpty($event->get_name()); }