Differences Between: [Versions 310 and 311] [Versions 310 and 400] [Versions 310 and 401] [Versions 310 and 402] [Versions 310 and 403] [Versions 39 and 310]
1 <?php 2 // This file is part of Moodle - http://moodle.org/ 3 // 4 // Moodle is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // Moodle is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU General Public License for more details. 13 // 14 // You should have received a copy of the GNU General Public License 15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 16 17 /** 18 * Prints an instance of mod_h5pactivity. 19 * 20 * @package mod_h5pactivity 21 * @copyright 2020 Ferran Recio <ferran@moodle.com> 22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 23 */ 24 25 use mod_h5pactivity\local\manager; 26 use mod_h5pactivity\event\report_viewed; 27 28 require(__DIR__.'/../../config.php'); 29 require_once (__DIR__.'/lib.php'); 30 31 $userid = optional_param('userid', null, PARAM_INT); 32 $attemptid = optional_param('attemptid', null, PARAM_INT); 33 34 // Attempts have only the instance id information but system events 35 // have only cmid. To prevent unnecesary db queries, this page accept both. 36 $id = optional_param('id', null, PARAM_INT); 37 if (empty($id)) { 38 $a = required_param('a', PARAM_INT); 39 list ($course, $cm) = get_course_and_cm_from_instance($a, 'h5pactivity'); 40 } else { 41 list ($course, $cm) = get_course_and_cm_from_cmid($id, 'h5pactivity'); 42 } 43 44 require_login($course, true, $cm); 45 46 $manager = manager::create_from_coursemodule($cm); 47 48 $report = $manager->get_report($userid, $attemptid); 49 if (!$report) { 50 print_error('permissiondenied'); 51 } 52 53 $user = $report->get_user(); 54 $attempt = $report->get_attempt(); 55 56 $moduleinstance = $manager->get_instance(); 57 58 $context = $manager->get_context(); 59 60 $params = ['a' => $cm->instance]; 61 if ($user) { 62 $params['userid'] = $user->id; 63 } 64 if ($attempt) { 65 $params['attemptid'] = $attempt->get_id(); 66 } 67 $PAGE->set_url('/mod/h5pactivity/report.php', $params); 68 69 // Trigger event. 70 $other = [ 71 'instanceid' => $params['a'], 72 'userid' => $params['userid'] ?? null, 73 'attemptid' => $params['attemptid'] ?? null, 74 ]; 75 $event = report_viewed::create([ 76 'objectid' => $moduleinstance->id, 77 'context' => $context, 78 'other' => $other, 79 ]); 80 $event->add_record_snapshot('course', $course); 81 $event->add_record_snapshot('h5pactivity', $moduleinstance); 82 $event->trigger(); 83 84 $shortname = format_string($course->shortname, true, ['context' => $context]); 85 $pagetitle = strip_tags($shortname.': '.format_string($moduleinstance->name)); 86 $PAGE->set_title(format_string($pagetitle)); 87 88 $navbar = []; 89 if ($manager->can_view_all_attempts()) { 90 // Report navbar have 3 levels for teachers: 91 // - Participants list 92 // - Participant attempts list 93 // - Individual attempt details. 94 $nav = [get_string('attempts', 'mod_h5pactivity'), null]; 95 if ($user) { 96 $nav[1] = new moodle_url('/mod/h5pactivity/report.php', ['a' => $cm->instance]); 97 $navbar[] = $nav; 98 99 $nav = [fullname($user), null]; 100 if ($attempt) { 101 $nav[1] = new moodle_url('/mod/h5pactivity/report.php', ['a' => $cm->instance, 'userid' => $user->id]); 102 } 103 } 104 $navbar[] = $nav; 105 } else { 106 // Report navbar have 2 levels for a regular participant: 107 // - My attempts 108 // - Individual attempt details. 109 $nav = [get_string('myattempts', 'mod_h5pactivity'), null]; 110 if ($attempt) { 111 $nav[1] = new moodle_url('/mod/h5pactivity/report.php', ['a' => $cm->instance]); 112 } 113 $navbar[] = $nav; 114 115 } 116 if ($attempt) { 117 $navbar[] = [get_string('attempt_number', 'mod_h5pactivity', $attempt->get_attempt()), null]; 118 } 119 foreach ($navbar as $nav) { 120 $PAGE->navbar->add($nav[0], $nav[1]); 121 } 122 123 $PAGE->set_heading(format_string($course->fullname)); 124 $PAGE->set_context($context); 125 126 echo $OUTPUT->header(); 127 128 echo $report->print(); 129 130 echo $OUTPUT->footer();
title
Description
Body
title
Description
Body
title
Description
Body
title
Body