$rsstitle = format_string($course->shortname, true, array('context' => context_course::instance($course->id))) . ': ' . format_string($twf->name); rss_add_http_header($context, 'mod_twf', $twf, $rsstitle); } /// Print header. $PAGE->set_title($twf->name); $PAGE->add_body_class('twftype-' . $twf->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/twf:viewdiscussion', $context)) { notice(get_string('noviewdiscussionspermission', 'twf')); } // Mark viewed and trigger the course_module_viewed event. twf_view($twf, $course, $cm, $context); echo $OUTPUT->header(); echo $OUTPUT->heading(format_string($twf->name), 2); if (!empty($twf->intro) && $twf->type != 'single' && $twf->type != 'teacher') { echo $OUTPUT->box(format_module_intro('twf', $twf, $cm->id), 'generalbox', 'intro'); } /// find out current groups mode groups_print_activity_menu($cm, $CFG->wwwroot . '/mod/twf/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 twf, we need to print the display // mode control. if ($twf->type == 'single') { $discussion = NULL; $discussions = $DB->get_records('twf_discussions', array('twf' => $twf->id), 'timemodified ASC');
/** * Simulate the twf/view.php web interface page: trigger events, completion, etc... * * @param int $twfid the twf instance id * @return array of warnings and status result * @since Moodle 2.9 * @throws moodle_exception */ public static function view_twf($twfid) { global $DB, $CFG; require_once $CFG->dirroot . "/mod/twf/lib.php"; $params = self::validate_parameters(self::view_twf_parameters(), array('twfid' => $twfid)); $warnings = array(); // Request and permission validation. $twf = $DB->get_record('twf', array('id' => $params['twfid']), 'id', MUST_EXIST); list($course, $cm) = get_course_and_cm_from_instance($twf, 'twf'); $context = context_module::instance($cm->id); self::validate_context($context); require_capability('mod/twf:viewdiscussion', $context, null, true, 'noviewdiscussionspermission', 'twf'); // Call the twf/lib API. twf_view($twf, $course, $cm, $context); $result = array(); $result['status'] = true; $result['warnings'] = $warnings; return $result; }
public function test_twf_view() { global $CFG; $CFG->enablecompletion = 1; $this->resetAfterTest(); // Setup test data. $course = $this->getDataGenerator()->create_course(array('enablecompletion' => 1)); $twf = $this->getDataGenerator()->create_module('twf', array('course' => $course->id), array('completion' => 2, 'completionview' => 1)); $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_view($twf, $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_twf\\event\\course_module_viewed', $event); $this->assertEquals($context, $event->get_context()); $url = new \moodle_url('/mod/twf/view.php', array('f' => $twf->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); }