Exemple #1
0
 /**
  * Simulate the forum/view.php web interface page: trigger events, completion, etc...
  *
  * @param int $forumid the forum instance id
  * @return array of warnings and status result
  * @since Moodle 2.9
  * @throws moodle_exception
  */
 public static function view_forum($forumid)
 {
     global $DB, $CFG;
     require_once $CFG->dirroot . "/mod/forum/lib.php";
     $params = self::validate_parameters(self::view_forum_parameters(), array('forumid' => $forumid));
     $warnings = array();
     // Request and permission validation.
     $forum = $DB->get_record('forum', array('id' => $params['forumid']), 'id', MUST_EXIST);
     list($course, $cm) = get_course_and_cm_from_instance($forum, 'forum');
     $context = context_module::instance($cm->id);
     self::validate_context($context);
     require_capability('mod/forum:viewdiscussion', $context, null, true, 'noviewdiscussionspermission', 'forum');
     // Call the forum/lib API.
     forum_view($forum, $course, $cm, $context);
     $result = array();
     $result['status'] = true;
     $result['warnings'] = $warnings;
     return $result;
 }
Exemple #2
0
 public function test_forum_view()
 {
     global $CFG;
     $CFG->enablecompletion = 1;
     $this->resetAfterTest();
     // Setup test data.
     $course = $this->getDataGenerator()->create_course(array('enablecompletion' => 1));
     $forum = $this->getDataGenerator()->create_module('forum', array('course' => $course->id), array('completion' => 2, 'completionview' => 1));
     $context = context_module::instance($forum->cmid);
     $cm = get_coursemodule_from_instance('forum', $forum->id);
     // Trigger and capture the event.
     $sink = $this->redirectEvents();
     $this->setAdminUser();
     forum_view($forum, $course, $cm, $context);
     $events = $sink->get_events();
     // 2 additional events thanks to completion.
     $this->assertCount(3, $events);
     $event = array_pop($events);
     // Checking that the event contains the expected values.
     $this->assertInstanceOf('\\mod_forum\\event\\course_module_viewed', $event);
     $this->assertEquals($context, $event->get_context());
     $url = new \moodle_url('/mod/forum/view.php', array('f' => $forum->id));
     $this->assertEquals($url, $event->get_url());
     $this->assertEventContextNotUsed($event);
     $this->assertNotEmpty($event->get_name());
     // Check completion status.
     $completion = new completion_info($course);
     $completiondata = $completion->get_data($cm);
     $this->assertEquals(1, $completiondata->completionstate);
 }
Exemple #3
0
    $rsstitle = format_string($course->shortname, true, array('context' => context_course::instance($course->id))) . ': ' . format_string($forum->name);
    rss_add_http_header($context, 'mod_forum', $forum, $rsstitle);
}
/// Print header.
$PAGE->set_title($forum->name);
$PAGE->add_body_class('forumtype-' . $forum->type);
$PAGE->set_heading($course->fullname);
/// Some capability checks.
if (empty($cm->visible) and !has_capability('moodle/course:viewhiddenactivities', $context)) {
    notice(get_string("activityiscurrentlyhidden"));
}
if (!has_capability('mod/forum:viewdiscussion', $context)) {
    notice(get_string('noviewdiscussionspermission', 'forum'));
}
// Mark viewed and trigger the course_module_viewed event.
forum_view($forum, $course, $cm, $context);
echo $OUTPUT->header();
echo $OUTPUT->heading(format_string($forum->name), 2);
if (!empty($forum->intro) && $forum->type != 'single' && $forum->type != 'teacher') {
    echo $OUTPUT->box(format_module_intro('forum', $forum, $cm->id), 'generalbox', 'intro');
}
/// find out current groups mode
groups_print_activity_menu($cm, $CFG->wwwroot . '/mod/forum/view.php?id=' . $cm->id);
$SESSION->fromdiscussion = qualified_me();
// Return here if we post or set subscription etc
/// Print settings and things across the top
// If it's a simple single discussion forum, we need to print the display
// mode control.
if ($forum->type == 'single') {
    $discussion = NULL;
    $discussions = $DB->get_records('forum_discussions', array('forum' => $forum->id), 'timemodified ASC');