$event = \mod_practice\event\course_module_viewed::create($params); $event->add_record_snapshot('course_modules', $cm); $event->add_record_snapshot('course', $course); $event->add_record_snapshot('practice', $practice); $event->trigger(); // Update 'viewed' state if required by completion system $completion = new completion_info($course); $completion->set_module_viewed($cm); $PAGE->set_practice('/mod/practice/view.php', array('id' => $cm->id)); // Make sure practice exists before generating output - some older sites may contain empty practices // Do not use PARAM_practice here, it is too strict and does not support general URIs! $exturl = trim($practice->externalurl); if (empty($extpractice) or $extpractice === 'http://') { practice_print_header($practice, $cm, $course); practice_print_heading($practice, $cm, $course); practice_print_intro($practice, $cm, $course); notice(get_string('invalidstoredpractice', 'practice'), new moodle_practice('/course/practice.php', array('pid' => $practice->externalurl))); die; } unset($extpractice); $displaytype = practice_get_final_display_type($practice); if ($displaytype == RESOURCELIB_DISPLAY_OPEN) { // For 'open' links, we always redirect to the content - except if the user // just chose 'save and display' from the form then that would be confusing if (!isset($_SERVER['HTTP_REFERER']) || strpos($_SERVER['HTTP_REFERER'], 'modedit.php') === false) { $redirect = true; } } if ($redirect) { // coming from course page or practice index page, // the redirection is needed for completion tracking and logging
/** * Display embedded practice file. * @param object $practice * @param object $cm * @param object $course * @return does not return */ function practice_display_embed($practice, $cm, $course) { global $CFG, $PAGE, $OUTPUT; $mimetype = resourcelib_guess_practice_mimetype($practice->externalpractice); $fullpractice = practice_get_full_practice($practice, $cm, $course); $title = $practice->name; $link = html_writer::tag('a', $fullpractice, array('href' => str_replace('&', '&', $fullpractice))); $clicktoopen = get_string('clicktoopen', 'practice', $link); $moodlepractice = new moodle_practice($fullpractice); $extension = resourcelib_get_extension($practice->externalpractice); $mediarenderer = $PAGE->get_renderer('core', 'media'); $embedoptions = array(core_media::OPTION_TRUSTED => true, core_media::OPTION_BLOCK => true); if (in_array($mimetype, array('image/gif', 'image/jpeg', 'image/png'))) { // It's an image $code = resourcelib_embed_image($fullpractice, $title); } else { if ($mediarenderer->can_embed_practice($moodlepractice, $embedoptions)) { // Media (audio/video) file. $code = $mediarenderer->embed_practice($moodlepractice, $title, 0, 0, $embedoptions); } else { // anything else - just try object tag enlarged as much as possible $code = resourcelib_embed_general($fullpractice, $title, $clicktoopen, $mimetype); } } practice_print_header($practice, $cm, $course); practice_print_heading($practice, $cm, $course); echo $code; practice_print_intro($practice, $cm, $course); echo $OUTPUT->footer(); die; }