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 mod_quiz\structure;
|
|
|
20 |
use renderable;
|
|
|
21 |
use renderer_base;
|
|
|
22 |
use templatable;
|
|
|
23 |
|
|
|
24 |
/**
|
|
|
25 |
* Represents the page where teachers can set up additional grade items.
|
|
|
26 |
*
|
|
|
27 |
* @package mod_quiz
|
|
|
28 |
* @category output
|
|
|
29 |
* @copyright 2023 The Open University
|
|
|
30 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
31 |
*/
|
|
|
32 |
class edit_grading_page implements renderable, templatable {
|
|
|
33 |
|
|
|
34 |
/**
|
|
|
35 |
* Constructor.
|
|
|
36 |
*
|
|
|
37 |
* @param structure $structure
|
|
|
38 |
*/
|
|
|
39 |
public function __construct(
|
|
|
40 |
|
|
|
41 |
/** @var structure structure of the quiz for which to display the grade edit page. */
|
|
|
42 |
protected readonly structure $structure,
|
|
|
43 |
|
|
|
44 |
) {
|
|
|
45 |
}
|
|
|
46 |
|
|
|
47 |
public function export_for_template(renderer_base $output) {
|
|
|
48 |
global $PAGE;
|
|
|
49 |
/** @var edit_renderer $editrenderer */
|
|
|
50 |
$editrenderer = $PAGE->get_renderer('mod_quiz', 'edit');
|
|
|
51 |
|
|
|
52 |
// Get the list of grade items, but to be the choices for a slot, and the list to be edited.
|
|
|
53 |
$gradeitemchoices = [
|
|
|
54 |
|
|
|
55 |
'id' => 0,
|
|
|
56 |
'choice' => get_string('gradeitemnoneselected', 'quiz'),
|
|
|
57 |
'isselected' => false,
|
|
|
58 |
],
|
|
|
59 |
];
|
|
|
60 |
$selectdgradeitemchoices = [];
|
|
|
61 |
$gradeitems = [];
|
|
|
62 |
foreach ($this->structure->get_grade_items() as $gradeitem) {
|
|
|
63 |
$gradeitem = clone($gradeitem);
|
|
|
64 |
unset($gradeitem->quizid);
|
|
|
65 |
$gradeitem->displayname = format_string($gradeitem->name);
|
|
|
66 |
$gradeitem->isused = $this->structure->is_grade_item_used($gradeitem->id);
|
|
|
67 |
$gradeitem->summarks = $gradeitem->isused ?
|
|
|
68 |
$this->structure->formatted_grade_item_sum_marks($gradeitem->id) :
|
|
|
69 |
'-';
|
|
|
70 |
|
|
|
71 |
$gradeitems[] = $gradeitem;
|
|
|
72 |
|
|
|
73 |
$gradeitemchoices[$gradeitem->id] = (object) [
|
|
|
74 |
'id' => $gradeitem->id,
|
|
|
75 |
'choice' => $gradeitem->displayname,
|
|
|
76 |
'isselected' => false,
|
|
|
77 |
];
|
|
|
78 |
$selectdgradeitemchoices[$gradeitem->id] = clone($gradeitemchoices[$gradeitem->id]);
|
|
|
79 |
$selectdgradeitemchoices[$gradeitem->id]->isselected = true;
|
|
|
80 |
}
|
|
|
81 |
|
|
|
82 |
// Get the list of quiz sections.
|
|
|
83 |
$sections = [];
|
|
|
84 |
foreach ($this->structure->get_sections() as $section) {
|
|
|
85 |
$sections[$section->id] = (object) [
|
|
|
86 |
'displayname' => $section->heading ? format_string($section->heading) : get_string('sectionnoname', 'quiz'),
|
|
|
87 |
'slots' => [],
|
|
|
88 |
];
|
|
|
89 |
}
|
|
|
90 |
|
|
|
91 |
// Add the relevant slots ot each section.
|
|
|
92 |
foreach ($this->structure->get_slots() as $slot) {
|
|
|
93 |
if (!$this->structure->is_real_question($slot->slot)) {
|
|
|
94 |
continue;
|
|
|
95 |
}
|
|
|
96 |
// Mark the right choice as selected.
|
|
|
97 |
$choices = $gradeitemchoices;
|
|
|
98 |
if ($slot->quizgradeitemid) {
|
|
|
99 |
$choices[$slot->quizgradeitemid] = $selectdgradeitemchoices[$slot->quizgradeitemid];
|
|
|
100 |
}
|
|
|
101 |
|
|
|
102 |
$sections[$slot->section->id]->slots[] = (object) [
|
|
|
103 |
'id' => $slot->id,
|
|
|
104 |
'displaynumber' => $this->structure->get_displayed_number_for_slot($slot->slot),
|
|
|
105 |
'displayname' => $editrenderer->get_question_name_for_slot(
|
|
|
106 |
$this->structure, $slot->slot, $PAGE->url),
|
|
|
107 |
'maxmark' => $this->structure->formatted_question_grade($slot->slot),
|
|
|
108 |
'choices' => array_values($choices),
|
|
|
109 |
];
|
|
|
110 |
}
|
|
|
111 |
|
|
|
112 |
return [
|
|
|
113 |
'quizid' => $this->structure->get_quizid(),
|
|
|
114 |
'hasgradeitems' => !empty($gradeitems),
|
|
|
115 |
'gradeitems' => $gradeitems,
|
|
|
116 |
'hasslots' => $this->structure->has_questions(),
|
|
|
117 |
'sections' => array_values($sections),
|
|
|
118 |
'hasmultiplesections' => count($sections) > 1,
|
|
|
119 |
'nogradeitems' => ['message' => get_string('gradeitemsnoneyet', 'quiz')],
|
|
|
120 |
'noslots' => ['message' => get_string('gradeitemnoslots', 'quiz')],
|
|
|
121 |
];
|
|
|
122 |
}
|
|
|
123 |
}
|