/**
  * Test the course_module_viewed event.
  */
 public function test_course_module_viewed()
 {
     // Setup test data.
     $course = $this->getDataGenerator()->create_course();
     $forum = $this->getDataGenerator()->create_module('hsuforum', array('course' => $course->id));
     $context = context_module::instance($forum->cmid);
     $params = array('context' => $context, 'objectid' => $forum->id);
     $event = \mod_hsuforum\event\course_module_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_hsuforum\\event\\course_module_viewed', $event);
     $this->assertEquals($context, $event->get_context());
     $expected = array($course->id, 'hsuforum', 'view forum', "view.php?f={$forum->id}", $forum->id, $forum->cmid);
     $this->assertEventLegacyLogData($expected, $event);
     $url = new \moodle_url('/mod/hsuforum/view.php', array('f' => $forum->id));
     $this->assertEquals($url, $event->get_url());
     $this->assertEventContextNotUsed($event);
     $this->assertNotEmpty($event->get_name());
 }
Пример #2
0
$PAGE->set_url($url);
$discussion = $DB->get_record('hsuforum_discussions', array('id' => $d), '*', MUST_EXIST);
$course = $DB->get_record('course', array('id' => $discussion->course), '*', MUST_EXIST);
$forum = $DB->get_record('hsuforum', array('id' => $discussion->forum), '*', MUST_EXIST);
$cm = get_coursemodule_from_instance('hsuforum', $forum->id, $course->id, false, MUST_EXIST);
require_course_login($course, true, $cm);
// move this down fix for MDL-6926
require_once $CFG->dirroot . '/mod/hsuforum/lib.php';
$modcontext = context_module::instance($cm->id);
require_capability('mod/hsuforum:viewdiscussion', $modcontext, NULL, true, 'noviewdiscussionspermission', 'hsuforum');
if ($forum->type == 'single') {
    // If we are viewing a simple single forum then we need to log forum as viewed.
    $completion = new \completion_info($course);
    $completion->set_module_viewed($cm);
    $params = array('context' => $modcontext, 'objectid' => $forum->id);
    $event = \mod_hsuforum\event\course_module_viewed::create($params);
    $event->add_record_snapshot('course_modules', $cm);
    $event->add_record_snapshot('course', $course);
    $event->add_record_snapshot('hsuforum', $forum);
    $event->trigger();
}
if (!empty($CFG->enablerssfeeds) && !empty($config->enablerssfeeds) && $forum->rsstype && $forum->rssarticles) {
    require_once "{$CFG->libdir}/rsslib.php";
    $rsstitle = format_string($course->shortname, true, array('context' => context_course::instance($course->id))) . ': ' . format_string($forum->name);
    rss_add_http_header($modcontext, 'mod_hsuforum', $forum, $rsstitle);
}
/// move discussion if requested
if ($move > 0 and confirm_sesskey()) {
    $return = $CFG->wwwroot . '/mod/hsuforum/discuss.php?d=' . $discussion->id;
    require_capability('mod/hsuforum:movediscussions', $modcontext);
    if ($forum->type == 'single') {
Пример #3
0
 /**
  * Render all discussions view, including add discussion button, etc...
  *
  * @param stdClass $forum - forum row
  * @return string
  */
 public function render_discussionsview($forum)
 {
     global $CFG, $DB, $PAGE, $SESSION;
     ob_start();
     // YAK! todo, fix this rubbish.
     require_once $CFG->dirroot . '/mod/hsuforum/lib.php';
     require_once $CFG->libdir . '/completionlib.php';
     require_once $CFG->libdir . '/accesslib.php';
     $output = '';
     $modinfo = get_fast_modinfo($forum->course);
     $forums = $modinfo->get_instances_of('hsuforum');
     if (!isset($forums[$forum->id])) {
         print_error('invalidcoursemodule');
     }
     $cm = $forums[$forum->id];
     $id = $cm->id;
     // Forum instance id (id in course modules table)
     $f = $forum->id;
     // Forum ID
     $config = get_config('hsuforum');
     if ($id) {
         if (!($course = $DB->get_record("course", array("id" => $cm->course)))) {
             print_error('coursemisconf');
         }
     } else {
         if ($f) {
             if (!($course = $DB->get_record("course", array("id" => $forum->course)))) {
                 print_error('coursemisconf');
             }
             // move require_course_login here to use forced language for course
             // fix for MDL-6926
             require_course_login($course, true, $cm);
         } else {
             print_error('missingparameter');
         }
     }
     $context = \context_module::instance($cm->id);
     if (!empty($CFG->enablerssfeeds) && !empty($config->enablerssfeeds) && $forum->rsstype && $forum->rssarticles) {
         require_once "{$CFG->libdir}/rsslib.php";
         $rsstitle = format_string($course->shortname, true, array('context' => \context_course::instance($course->id))) . ': ' . format_string($forum->name);
         rss_add_http_header($context, 'mod_hsuforum', $forum, $rsstitle);
     }
     // Mark viewed if required
     $completion = new \completion_info($course);
     $completion->set_module_viewed($cm);
     /// Some capability checks.
     if (empty($cm->visible) and !has_capability('moodle/course:viewhiddenactivities', $context)) {
         notice(get_string("activityiscurrentlyhidden"));
     }
     if (!has_capability('mod/hsuforum:viewdiscussion', $context)) {
         notice(get_string('noviewdiscussionspermission', 'hsuforum'));
     }
     $params = array('context' => $context, 'objectid' => $forum->id);
     $event = \mod_hsuforum\event\course_module_viewed::create($params);
     $event->add_record_snapshot('course_modules', $cm);
     $event->add_record_snapshot('course', $course);
     $event->add_record_snapshot('hsuforum', $forum);
     $event->trigger();
     if (!defined(AJAX_SCRIPT) || !AJAX_SCRIPT) {
         // Return here if we post or set subscription etc (but not if we are calling this via ajax).
         $SESSION->fromdiscussion = qualified_me();
     }
     $PAGE->requires->js_init_call('M.mod_hsuforum.init', null, false, $this->get_js_module());
     $output .= $this->svg_sprite();
     $this->view($course, $cm, $forum, $context);
     // Don't allow non logged in users, or guest to try to manage subscriptions.
     if (isloggedin() && !isguestuser()) {
         $url = new \moodle_url('/mod/hsuforum/index.php', ['id' => $course->id]);
         $manageforumsubscriptions = get_string('manageforumsubscriptions', 'mod_hsuforum');
         $output .= \html_writer::link($url, $manageforumsubscriptions);
     }
     $output = ob_get_contents() . $output;
     ob_end_clean();
     return $output;
 }