/** * Trigger the course module viewed event and update the module completion status. * * @param int $urlid the url instance id * @return array of warnings and status result * @since Moodle 3.0 * @throws moodle_exception */ public static function view_url($urlid) { global $DB, $CFG; require_once $CFG->dirroot . "/mod/url/lib.php"; $params = self::validate_parameters(self::view_url_parameters(), array('urlid' => $urlid)); $warnings = array(); // Request and permission validation. $url = $DB->get_record('url', array('id' => $params['urlid']), '*', MUST_EXIST); list($course, $cm) = get_course_and_cm_from_instance($url, 'url'); $context = context_module::instance($cm->id); self::validate_context($context); require_capability('mod/url:view', $context); // Call the url/lib API. url_view($url, $course, $cm, $context); $result = array(); $result['status'] = true; $result['warnings'] = $warnings; return $result; }
<div class="preview"> <img src="<?php echo $product->img; ?> " alt="preview"> <div class="controls row"> <div class="col-lg-5"> <a href="#" class="btn buy"> купить </a> </div> <div class="col-lg-5 col-lg-offset-2"> <a href="<?php echo url_view($product); ?> " class="btn more"> подробнее </a> </div> </div> </div> </div> <? endforeach; ?> </div> <? if(empty($products)): ?> <div> nothing to show... </div>
// URL instance id $redirect = optional_param('redirect', 0, PARAM_BOOL); if ($u) { // Two ways to specify the module $url = $DB->get_record('url', array('id' => $u), '*', MUST_EXIST); $cm = get_coursemodule_from_instance('url', $url->id, $url->course, false, MUST_EXIST); } else { $cm = get_coursemodule_from_id('url', $id, 0, false, MUST_EXIST); $url = $DB->get_record('url', array('id' => $cm->instance), '*', MUST_EXIST); } $course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST); require_course_login($course, true, $cm); $context = context_module::instance($cm->id); require_capability('mod/url:view', $context); // Completion and trigger events. url_view($url, $course, $cm, $context); $PAGE->set_url('/mod/url/view.php', array('id' => $cm->id)); // Make sure URL exists before generating output - some older sites may contain empty urls // Do not use PARAM_URL here, it is too strict and does not support general URIs! $exturl = trim($url->externalurl); if (empty($exturl) or $exturl === 'http://') { url_print_header($url, $cm, $course); url_print_heading($url, $cm, $course); url_print_intro($url, $cm, $course); notice(get_string('invalidstoredurl', 'url'), new moodle_url('/course/view.php', array('id' => $cm->course))); die; } unset($exturl); $displaytype = url_get_final_display_type($url); if ($displaytype == RESOURCELIB_DISPLAY_OPEN) { // For 'open' links, we always redirect to the content - except if the user
/** * Test url_view * @return void */ public function test_url_view() { global $CFG; $CFG->enablecompletion = 1; $this->resetAfterTest(); // Setup test data. $course = $this->getDataGenerator()->create_course(array('enablecompletion' => 1)); $url = $this->getDataGenerator()->create_module('url', array('course' => $course->id), array('completion' => 2, 'completionview' => 1)); $context = context_module::instance($url->cmid); $cm = get_coursemodule_from_instance('url', $url->id); // Trigger and capture the event. $sink = $this->redirectEvents(); $this->setAdminUser(); url_view($url, $course, $cm, $context); $events = $sink->get_events(); // 2 additional events thanks to completion. $this->assertCount(3, $events); $event = array_shift($events); // Checking that the event contains the expected values. $this->assertInstanceOf('\\mod_url\\event\\course_module_viewed', $event); $this->assertEquals($context, $event->get_context()); $url = new \moodle_url('/mod/url/view.php', array('id' => $cm->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); }