MDL-63660 tool_dataprivacy: Increase expected export file size
[moodle.git] / mod / scorm / renderer.php
blob4f5a2fa8c75f061aa1b6a248edbcb8fc7f1a775d
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.
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/>.
17 /**
18 * Defines the renderer for the scorm module.
20 * @package mod_scorm
21 * @copyright 2013 Dan Marsden
22 * @author Dan Marsden <dan@danmarsden.com>
23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
26 defined('MOODLE_INTERNAL') || die();
28 /**
29 * The renderer for the scorm module.
31 * @copyright 2013 Dan Marsden
32 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
34 class mod_scorm_renderer extends plugin_renderer_base {
35 public function view_user_heading($user, $course, $baseurl, $attempt, $attemptids) {
36 $output = '';
37 $output .= $this->box_start('generalbox boxaligncenter');
38 $output .= html_writer::start_tag('div', array('class' => 'mdl-align'));
39 $output .= $this->user_picture($user, array('courseid' => $course->id, 'link' => true));
40 $url = new moodle_url('/user/view.php', array('id' => $user->id, 'course' => $course->id));
41 $output .= html_writer::link($url, fullname($user));
42 $baseurl->param('attempt', '');
43 $pb = new mod_scorm_attempt_bar($attemptids, $attempt, $baseurl, 'attempt');
44 $output .= $this->render($pb);
45 $output .= html_writer::end_tag('div');
46 $output .= $this->box_end();
47 return $output;
49 /**
50 * scorm attempt bar renderer
52 * @param mod_scorm_attempt_bar $attemptbar
53 * @return string
55 protected function render_mod_scorm_attempt_bar(mod_scorm_attempt_bar $attemptbar) {
56 $output = '';
57 $attemptbar = clone($attemptbar);
58 $attemptbar->prepare($this, $this->page, $this->target);
60 if (count($attemptbar->attemptids) > 1) {
61 $output .= get_string('attempt', 'scorm') . ':';
63 if (!empty($attemptbar->previouslink)) {
64 $output .= '&#160;(' . $attemptbar->previouslink . ')&#160;';
67 foreach ($attemptbar->attemptlinks as $link) {
68 $output .= "&#160;&#160;$link";
71 if (!empty($attemptbar->nextlink)) {
72 $output .= '&#160;&#160;(' . $attemptbar->nextlink . ')';
76 return html_writer::tag('div', $output, array('class' => 'paging'));
81 /**
82 * Component representing a SCORM attempts bar.
84 * @copyright 2013 Dan Marsden
85 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
86 * @package mod_scorm
88 class mod_scorm_attempt_bar implements renderable {
90 /**
91 * @var array An array of the attemptids
93 public $attemptids;
95 /**
96 * @var int The attempt you are currently viewing.
98 public $attempt;
101 * @var string|moodle_url If this is a string then it is the url which will be appended with $pagevar,
102 * an equals sign and the attempt number.
103 * If this is a moodle_url object then the pagevar param will be replaced by
104 * the attempt no, for each attempt.
106 public $baseurl;
109 * @var string This is the variable name that you use for the attempt in your
110 * code (ie. 'tablepage', 'blogpage', etc)
112 public $pagevar;
115 * @var string A HTML link representing the "previous" attempt.
117 public $previouslink = null;
120 * @var string A HTML link representing the "next" attempt.
122 public $nextlink = null;
125 * @var array An array of strings. One of them is just a string: the current attempt
127 public $attemptlinks = array();
130 * Constructor mod_scorm_attempt_bar with only the required params.
132 * @param array $attemptids an array of attempts the user has made
133 * @param int $attempt The attempt you are currently viewing
134 * @param string|moodle_url $baseurl url of the current page, the $pagevar parameter is added
135 * @param string $pagevar name of page parameter that holds the attempt number
137 public function __construct($attemptids, $attempt, $baseurl, $pagevar = 'page') {
138 $this->attemptids = $attemptids;
139 $this->attempt = $attempt;
140 $this->baseurl = $baseurl;
141 $this->pagevar = $pagevar;
145 * Prepares the scorm attempt bar for output.
147 * This method validates the arguments set up for the scorm attempt bar and then
148 * produces fragments of HTML to assist display later on.
150 * @param renderer_base $output
151 * @param moodle_page $page
152 * @param string $target
153 * @throws coding_exception
155 public function prepare(renderer_base $output, moodle_page $page, $target) {
156 if (empty($this->attemptids)) {
157 throw new coding_exception('mod_scorm_attempt_bar requires a attemptids value.');
159 if (!isset($this->attempt) || is_null($this->attempt)) {
160 throw new coding_exception('mod_scorm_attempt_bar requires a attempt value.');
162 if (empty($this->baseurl)) {
163 throw new coding_exception('mod_scorm_attempt_bar requires a baseurl value.');
166 if (count($this->attemptids) > 1) {
167 $lastattempt = end($this->attemptids); // Get last attempt.
168 $firstattempt = reset($this->attemptids); // get first attempt.
170 $nextattempt = 0;
171 $prevattempt = null;
172 $previous = 0;
173 foreach ($this->attemptids as $attemptid) {
174 if ($this->attempt == $attemptid) {
175 $this->attemptlinks[] = $attemptid;
176 $prevattempt = $previous;
177 } else {
178 $attemptlink = html_writer::link(
179 new moodle_url($this->baseurl, array($this->pagevar => $attemptid)), $attemptid);
180 $this->attemptlinks[] = $attemptlink;
181 if (empty($nextattempt) && $prevattempt !== null) {
182 // Set the nextattempt var as we have set previous attempt earlier.
183 $nextattempt = $attemptid;
186 $previous = $attemptid; // Store this attempt as previous in case we need it.
189 if ($this->attempt != $firstattempt) {
190 $this->previouslink = html_writer::link(
191 new moodle_url($this->baseurl, array($this->pagevar => $prevattempt)),
192 get_string('previous'), array('class' => 'previous'));
195 if ($this->attempt != $lastattempt) {
196 $this->nextlink = html_writer::link(
197 new moodle_url($this->baseurl, array($this->pagevar => $nextattempt)),
198 get_string('next'), array('class' => 'next'));