forked from maths/moodle-qtype_stack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtodo.php
127 lines (113 loc) · 5.13 KB
/
todo.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
<?php
// This file is part of Stack - http://stack.maths.ed.ac.uk/
//
// Stack is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Stack is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Stack. If not, see <http://www.gnu.org/licenses/>.
/**
* This page lets the user find all questions in a course in which they are a techer
* which have a [[todo]] block. The questions are sorted by any tags they might have.
*
* @copyright 2024 University of Edinburgh
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require_once(__DIR__.'/../../../../config.php');
require_once($CFG->libdir . '/questionlib.php');
require_once(__DIR__ . '/../locallib.php');
require_once(__DIR__ . '/../stack/utils.class.php');
require_once(__DIR__ . '/../stack/bulktester.class.php');
// Get the parameters from the URL.
$context = context_system::instance();
$contextid = optional_param('contextid', $context->__get('id'), PARAM_INT);
$context = context::instance_by_id($contextid);
// Login and check permissions.
require_login();
$PAGE->set_url('/question/type/stack/todo.php');
$PAGE->set_context($context);
$title = stack_string('seetodolist');
$PAGE->set_title($title);
echo $OUTPUT->header();
echo $OUTPUT->heading($title);
echo html_writer::tag('p', stack_string('seetodolist_desc'));
echo html_writer::tag('p', stack_string('seetodolist_help'));
$bulktester = new stack_bulk_tester();
$tagsummary = [];
// Loop over all questions which this teache can edit.
foreach ($bulktester->get_num_stack_questions_by_context() as $contextid => $numstackquestions) {
$context = context::instance_by_id($contextid);
if (has_capability('moodle/question:editall', $context)) {
$categories = $bulktester->get_categories_for_context($context->id);
$questiontestsurl = new moodle_url('/question/type/stack/questiontestrun.php');
if ($context->contextlevel == CONTEXT_COURSE) {
$questiontestsurl->param('courseid', $context->instanceid);
} else if ($context->contextlevel == CONTEXT_MODULE) {
$questiontestsurl->param('cmid', $context->instanceid);
} else {
$questiontestsurl->param('courseid', SITEID);
}
foreach ($categories as $currentcategoryid => $nameandcount) {
core_php_time_limit::raise(60); // Prevent PHP timeouts.
$qtodos = [];
$questions = $bulktester->stack_questions_in_category_with_todo($currentcategoryid);
if (!$questions) {
continue;
}
foreach ($questions as $qid => $qname) {
$q = question_bank::load_question($qid);
list($hastodos, $tags) = $q->get_question_todos();
if ($hastodos) {
$preurl = qbank_previewquestion\helper::question_preview_url($qid,
null, null, null, null, $context);
$dashurl = html_writer::link(new moodle_url($questiontestsurl,
['questionid' => $qid]), $qname). ' ' .
$OUTPUT->action_icon($preurl, new pix_icon('t/preview', get_string('preview')));
// TODO: add in a direct edit URL.
$qtodos[] = ['qid' => $qid,
'qname' => $qname,
'tags' => $tags,
'dashurl' => $dashurl,
];
if ($tags !== []) {
foreach ($tags as $tag) {
if (array_key_exists($tag, $tagsummary)) {
$tagsummary[$tag][] = $dashurl;
} else {
$tagsummary[$tag] = [$dashurl];
}
}
}
}
}
if ($qtodos !== []) {
echo $OUTPUT->heading($context->get_context_name());
echo '<table><thead><tr><th>Question</th><th>Tags</th></thead><tbody>';
// Load the whole question, simpler to get the contexts correct that way.
foreach ($qtodos as $item) {
echo "<tr><td>" . $item['dashurl'] .
'</td><td>' . implode(', ', $item['tags']). '<td></tr>';
}
echo '</tbody></table>';
flush(); // Force output to prevent timeouts and to make progress clear.
}
}
}
}
if ($tagsummary !== []) {
echo "\n\n<hr />\n\n";
foreach ($tagsummary as $tagname => $tagurls) {
echo $OUTPUT->heading($tagname);
foreach ($tagurls as $dashurl) {
echo $dashurl . "\n<br >\n";
}
}
}
echo $OUTPUT->footer();