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
/**
18
 * H5P activity results report.
19
 *
20
 * @package    mod_h5pactivity
21
 * @since      Moodle 3.9
22
 * @copyright  2020 Ferran Recio <ferran@moodle.com>
23
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
24
 */
25
 
26
namespace mod_h5pactivity\local\report;
27
 
28
use mod_h5pactivity\local\report;
29
use mod_h5pactivity\local\manager;
30
use mod_h5pactivity\local\attempt;
31
use mod_h5pactivity\output\reportresults;
32
use stdClass;
33
 
34
/**
35
 * Class  H5P activity results report.
36
 *
37
 * @package    mod_h5pactivity
38
 * @since      Moodle 3.9
39
 * @copyright  2020 Ferran Recio <ferran@moodle.com>
40
 */
41
class results implements report {
42
 
43
    /** @var manager the H5P activity manager instance. */
44
    private $manager;
45
 
46
    /** @var stdClass the user record. */
47
    private $user;
48
 
49
    /** @var attempt the h5pactivity attempt to show. */
50
    private $attempt;
51
 
52
    /**
53
     * Create a new participants report.
54
     *
55
     * @param manager $manager h5pactivity manager object
56
     * @param stdClass $user user record
57
     * @param attempt $attempt attempt object
58
     */
59
    public function __construct(manager $manager, stdClass $user, attempt $attempt) {
60
        $this->manager = $manager;
61
        $this->user = $user;
62
        $this->attempt = $attempt;
63
    }
64
 
65
    /**
66
     * Return the report user record.
67
     *
68
     * @return stdClass|null a user or null
69
     */
70
    public function get_user(): ?stdClass {
71
        return $this->user;
72
    }
73
 
74
    /**
75
     * Return the report attempt object.
76
     *
77
     * Attempts report has no specific attempt.
78
     *
79
     * @return attempt|null the attempt object or null
80
     */
81
    public function get_attempt(): ?attempt {
82
        return $this->attempt;
83
    }
84
 
85
    /**
86
     * Print the report.
87
     */
88
    public function print(): void {
89
        global $OUTPUT;
90
 
91
        $manager = $this->manager;
92
        $attempt = $this->attempt;
93
        $cm = $manager->get_coursemodule();
94
 
95
        $widget = new reportresults($attempt, $this->user, $cm->course);
96
        echo $OUTPUT->render($widget);
97
    }
98
 
99
    /**
100
     * Get the export data form this report.
101
     *
102
     * This method is used to render the report in mobile.
103
     */
104
    public function export_data_for_external(): stdClass {
105
        global $PAGE;
106
 
107
        $manager = $this->manager;
108
        $attempt = $this->attempt;
109
        $cm = $manager->get_coursemodule();
110
 
111
        $widget = new reportresults($attempt, $this->user, $cm->course);
112
        return $widget->export_for_template($PAGE->get_renderer('core'));
113
    }
114
}