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_quiz\output;
18
 
19
use core\output\named_templatable;
20
use mod_quiz\quiz_attempt;
21
use renderable;
22
use renderer_base;
23
 
24
/**
25
 * Display summary information about a list of attempts.
26
 *
27
 * This is used on the front page of the quiz (view.php).
28
 *
29
 * @package mod_quiz
30
 * @copyright 2024 The Open University
31
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
32
 */
33
class list_of_attempts implements renderable, named_templatable {
34
 
35
    /** @var int time to consider as now. */
36
    protected int $timenow;
37
 
38
    /** @var quiz_attempt[] The list of attempts to summarise. */
39
    protected array $attempts = [];
40
 
41
    /**
42
     * Constructor.
43
     *
44
     * @param int $timenow time that is now.
45
     */
46
    public function __construct(int $timenow) {
47
        $this->timenow = $timenow;
48
    }
49
 
50
    /**
51
     * Add an event to the list.
52
     *
53
     * @param quiz_attempt $attemptobj
54
     */
55
    public function add_attempt(quiz_attempt $attemptobj): void {
56
        $this->attempts[] = $attemptobj;
57
    }
58
 
59
    public function export_for_template(renderer_base $output): array {
60
 
61
        $templatecontext = [
62
            'hasattempts' => !empty($this->attempts),
63
            'attempts' => [],
64
        ];
65
 
66
        foreach ($this->attempts as $attemptobj) {
67
            $displayoptions = $attemptobj->get_display_options(true);
68
            $templatecontext['attempts'][] = (object) [
69
                'name' => get_string('attempt', 'mod_quiz', $attemptobj->get_attempt_number()),
70
                'summarydata' => attempt_summary_information::create_for_attempt(
71
                        $attemptobj, $displayoptions)->export_for_template($output),
72
                'reviewlink' => $attemptobj->get_access_manager($this->timenow)->make_review_link(
73
                        $attemptobj->get_attempt(), $displayoptions, $output),
74
            ];
75
        }
76
 
77
        return $templatecontext;
78
    }
79
 
80
    public function get_template_name(\renderer_base $renderer): string {
81
        // Only reason we are forced to implement this is that we want the quiz renderer
82
        // passed to export_for_template, not a core_renderer.
83
        return 'mod_quiz/list_of_attempts';
84
    }
85
}