Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 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
namespace mod_scorm\output;
18
 
19
use renderable;
20
use renderer_base;
21
use templatable;
22
use moodle_url;
23
use url_select;
24
 
25
/**
26
 * Render HTML elements for tertiary nav for scorm.
27
 *
28
 * @package mod_scorm
29
 * @copyright 2021 Sujith Haridasan <sujith@moodle.com>
30
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
31
 */
32
class actionbar implements renderable, templatable {
33
    /** @var int */
34
    private $id;
35
 
36
    /** @var string */
37
    private $download;
38
 
39
    /** @var int */
40
    private $attemptsmode;
41
 
42
    /**
43
     * actionbar constructor.
44
     *
45
     * @param int $id The course module id.
46
     * @param bool $download Show download button or not.
47
     * @param int $attemptsmode attempts mode for scorm.
48
     */
49
    public function __construct(int $id, bool $download = false, int $attemptsmode = 0) {
50
        $this->id = $id;
51
        $this->download = $download;
52
        $this->attemptsmode = $attemptsmode;
53
    }
54
 
55
    /**
56
     * Provide data for the template
57
     *
58
     * @param renderer_base $output renderer_base object.
59
     * @return array data for the template
60
     */
61
    public function export_for_template(renderer_base $output): array {
62
        global $PAGE;
63
 
64
        $basicreportlink = new moodle_url('/mod/scorm/report.php', ['id' => $this->id, 'mode' => 'basic']);
65
        $graphreportlink = new moodle_url('/mod/scorm/report.php', ['id' => $this->id, 'mode' => 'graphs']);
66
        $interactionreportlink = new moodle_url('/mod/scorm/report.php', ['id' => $this->id, 'mode' => 'interactions']);
67
        $objectivesreportlink = new moodle_url('/mod/scorm/report.php', ['id' => $this->id, 'mode' => 'objectives']);
68
 
69
        $reportmenu = [
70
            $basicreportlink->out(false) => get_string('pluginname', 'scormreport_basic'),
71
            $graphreportlink->out(false) => get_string('pluginname', 'scormreport_graphs'),
72
            $interactionreportlink->out(false) => get_string('pluginname', 'scormreport_interactions'),
73
            $objectivesreportlink->out(false) => get_string('pluginname', 'scormreport_objectives'),
74
        ];
75
 
76
        $sesskey = sesskey();
77
        if ($this->download) {
78
            $mode = $PAGE->url->get_param('mode');
79
            if ($mode === 'basic') {
80
                $options = [
81
                    'id' => $this->id, 'mode' => $mode,
82
                    'attemptsmode' => $this->attemptsmode, 'sesskey' => $sesskey
83
                ];
84
            } else if ($mode === 'interactions') {
85
                $options = [
86
                    'id' => $this->id, 'mode' => $mode, 'qtext' => '0',
87
                    'resp' => '1', 'right' => '0', 'result' => '0',
88
                    'attemptsmode' => $this->attemptsmode, 'sesskey' => $sesskey
89
                ];
90
            } else if ($mode === 'objectives') {
91
                $options = [
92
                    'id' => $this->id, 'mode' => $mode,
93
                    'attemptsmode' => $this->attemptsmode, 'objectivescore' => '0',
94
                    'sesskey' => $sesskey
95
                ];
96
            }
97
 
98
            $options['download'] = 'ODS';
99
            $downloadodslink = new moodle_url($PAGE->url, $options);
100
 
101
            $options['download'] = 'Excel';
102
            $downloadexcellink = new moodle_url($PAGE->url, $options);
103
 
104
            $options['download'] = 'CSV';
105
            $downloadtextlink = new moodle_url($PAGE->url, $options);
106
        }
107
 
108
        $url = new moodle_url('/mod/scorm/report.php', $PAGE->url->remove_params('attemptsmode'));
109
        $urlselect = new url_select($reportmenu, $url->out(false), null, 'selectscormreports');
110
        $heading = $reportmenu[$url->out(false)] ?? null;
111
 
112
        $data = [
113
            'heading' => $heading,
114
            'scormreports' => $urlselect->export_for_template($output),
115
            'candownload' => $this->download,
116
            'downloadods' => ($this->download) ? $downloadodslink->out(false) : '',
117
            'downloadexcel' => ($this->download) ? $downloadexcellink->out(false) : '',
118
            'downloadtext' => ($this->download) ? $downloadtextlink->out(false) : ''
119
        ];
120
        return $data;
121
    }
122
}