|
14 | 14 | // You should have received a copy of the GNU General Public License
|
15 | 15 | // along with Stack. If not, see <http://www.gnu.org/licenses/>.
|
16 | 16 |
|
17 |
| -/** |
18 |
| - * This script provides an index for running the question tests in bulk. |
19 |
| - * [A modified version of the script in qtype_stack with the same name.] |
20 |
| - * |
21 |
| - * @package qtype_coderunner |
22 |
| - * @copyright 2016, 2017 Richard Lobb, The University of Canterbury |
23 |
| - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
24 |
| - */ |
25 |
| - |
26 | 17 | require_once(__DIR__ . '/../../../config.php');
|
27 | 18 | require_once($CFG->libdir . '/questionlib.php');
|
28 | 19 |
|
|
51 | 42 | $contextname = $context->get_context_name(true, true);
|
52 | 43 | if ($contextname === "Question bank: System shared question bank") {
|
53 | 44 | $name = "$coursename: System shared question bank";
|
54 |
| - } else if (strpos($contextname, 'Quiz:') === 0) { // Quiz-specific question category. |
| 45 | + } else if (strpos($contextname, 'Quiz:') === 0) { |
55 | 46 | $name = "$coursename: $contextname";
|
56 | 47 | }
|
57 | 48 | $availablequestionsbycontext[$name] = [
|
|
65 | 56 | // Display.
|
66 | 57 | echo $OUTPUT->header();
|
67 | 58 |
|
| 59 | +// Add the configuration form |
| 60 | +echo <<<HTML |
| 61 | +<div class="bulk-test-config" style="margin-bottom: 20px; padding: 10px; background-color: #f5f5f5; border: 1px solid #ddd;"> |
| 62 | + <h3>Test Configuration</h3> |
| 63 | + <div style="margin-bottom: 10px; display: grid; grid-template-columns: auto 80px; gap: 10px; align-items: center; max-width: 240px;"> |
| 64 | + <label for="nruns">Number of runs:</label> |
| 65 | + <input type="number" id="nruns" value="{$nruns}" min="1" style="width: 80px;"> |
| 66 | + |
| 67 | + <label for="randomseed">Random seed:</label> |
| 68 | + <input type="number" id="randomseed" value="0" min="0" style="width: 80px;"> |
| 69 | + |
| 70 | + <label for="repeatrandomonly">Repeat random only:</label> |
| 71 | + <div> |
| 72 | + <input type="checkbox" id="repeatrandomonly" checked> |
| 73 | + </div> |
| 74 | + </div> |
| 75 | +</div> |
| 76 | +HTML; |
| 77 | + |
68 | 78 | // List all contexts available to the user.
|
69 | 79 | if (count($availablequestionsbycontext) == 0) {
|
70 | 80 | echo html_writer::tag('p', get_string('unauthorisedbulktest', 'qtype_coderunner'));
|
|
77 | 87 | foreach ($availablequestionsbycontext as $name => $info) {
|
78 | 88 | $contextid = $info['contextid'];
|
79 | 89 | $numcoderunnerquestions = $info['numquestions'];
|
80 |
| - // Random seed of zero means randomseed is not set. |
81 |
| - $urlargs = ['contextid' => $contextid, |
82 |
| - 'randomseed' => 0, |
83 |
| - 'repeatrandomonly' => 1, |
84 |
| - 'nruns' => $nruns]; |
85 | 90 |
|
86 |
| - $testallurl = new moodle_url('/question/type/coderunner/bulktest.php', $urlargs); |
87 | 91 | $testallstr = get_string('bulktestallincontext', 'qtype_coderunner');
|
88 | 92 | $testalltitledetails = ['title' => get_string('testalltitle', 'qtype_coderunner'), 'style' => $buttonstyle];
|
89 |
| - $testalllink = html_writer::link($testallurl, $testallstr, $testalltitledetails); |
| 93 | + $testallspan = html_writer::tag('span', $testallstr, |
| 94 | + ['class' => 'test-link', |
| 95 | + 'data-contextid' => $contextid, |
| 96 | + 'style' => $buttonstyle . ';cursor:pointer;']); |
90 | 97 |
|
91 | 98 | $expandlink = html_writer::link(
|
92 | 99 | '#expand',
|
93 | 100 | get_string('expand', 'qtype_coderunner'),
|
94 | 101 | ['class' => 'expander', 'title' => get_string('expandtitle', 'qtype_coderunner'), 'style' => $buttonstyle]
|
95 | 102 | );
|
96 |
| - $litext = $name . ' (' . $numcoderunnerquestions . ') ' . $testalllink . ' ' . $expandlink; |
97 |
| - if (strpos($name, 'Quiz:') === 0) { |
98 |
| - $class = 'bulktest coderunner context quiz'; |
99 |
| - } else { |
100 |
| - $class = 'bulktest coderunner context normal'; |
101 |
| - } |
102 |
| - |
| 103 | + |
| 104 | + $litext = $name . ' (' . $numcoderunnerquestions . ') ' . $testallspan . ' ' . $expandlink; |
| 105 | + |
103 | 106 | if (strpos($name, ": Quiz: ") === false) {
|
104 | 107 | $class = 'bulktest coderunner context normal';
|
105 | 108 | } else {
|
106 | 109 | $class = 'bulktest coderunner context quiz';
|
107 | 110 | }
|
| 111 | + |
108 | 112 | echo html_writer::start_tag('li', ['class' => $class]);
|
109 | 113 | echo $litext;
|
110 | 114 |
|
|
114 | 118 | $titledetails = ['title' => get_string('testallincategory', 'qtype_coderunner')];
|
115 | 119 | foreach ($categories as $cat) {
|
116 | 120 | if ($cat->count > 0) {
|
117 |
| - $urlargs = ['contextid' => $contextid, |
118 |
| - 'categoryid' => $cat->id, |
119 |
| - 'randomseed' => 0, |
120 |
| - 'repeatrandomonly' => 1, |
121 |
| - 'nruns' => $nruns]; |
122 |
| - $url = new moodle_url('/question/type/coderunner/bulktest.php', $urlargs); |
123 | 121 | $linktext = $cat->name . ' (' . $cat->count . ')';
|
124 |
| - $link = html_writer::link($url, $linktext, ['style' => $buttonstyle]); |
125 |
| - echo html_writer::tag('li', $link, $titledetails); |
| 122 | + $span = html_writer::tag('span', $linktext, |
| 123 | + ['class' => 'test-link', |
| 124 | + 'data-contextid' => $contextid, |
| 125 | + 'data-categoryid' => $cat->id, |
| 126 | + 'style' => $buttonstyle . ';cursor:pointer;']); |
| 127 | + echo html_writer::tag('li', $span, $titledetails); |
126 | 128 | }
|
127 | 129 | }
|
128 | 130 | echo html_writer::end_tag('ul');
|
|
142 | 144 | echo <<<SCRIPT_END
|
143 | 145 | <script>
|
144 | 146 | document.addEventListener("DOMContentLoaded", function(event) {
|
| 147 | + // Handle expandable sections |
145 | 148 | var expandables = document.getElementsByClassName('expandable');
|
146 | 149 | Array.from(expandables).forEach(function (expandable) {
|
147 | 150 | expandable.style.display = 'none';
|
148 | 151 | });
|
| 152 | + |
149 | 153 | var expanders = document.getElementsByClassName('expander');
|
150 | 154 | Array.from(expanders).forEach(function(expander) {
|
151 | 155 | expander.addEventListener('click', function(event) {
|
|
159 | 163 | }
|
160 | 164 | });
|
161 | 165 | });
|
| 166 | +
|
| 167 | + // Handle test links |
| 168 | + var testLinks = document.getElementsByClassName('test-link'); |
| 169 | + Array.from(testLinks).forEach(function(link) { |
| 170 | + link.addEventListener('click', function(event) { |
| 171 | + event.preventDefault(); |
| 172 | + |
| 173 | + // Get configuration values |
| 174 | + var nruns = document.getElementById('nruns').value; |
| 175 | + var randomseed = document.getElementById('randomseed').value; |
| 176 | + var repeatrandomonly = document.getElementById('repeatrandomonly').checked ? 1 : 0; |
| 177 | + |
| 178 | + // Build URL parameters |
| 179 | + var params = new URLSearchParams(); |
| 180 | + params.append('contextid', link.dataset.contextid); |
| 181 | + params.append('randomseed', randomseed); |
| 182 | + params.append('repeatrandomonly', repeatrandomonly); |
| 183 | + params.append('nruns', nruns); |
| 184 | + |
| 185 | + // Add category ID if present |
| 186 | + if (link.dataset.categoryid) { |
| 187 | + params.append('categoryid', link.dataset.categoryid); |
| 188 | + } |
| 189 | + |
| 190 | + // Construct and navigate to URL |
| 191 | + var url = M.cfg.wwwroot + '/question/type/coderunner/bulktest.php?' + params.toString(); |
| 192 | + window.location.href = url; |
| 193 | + }); |
| 194 | + }); |
162 | 195 | });
|
163 | 196 | </script>
|
164 | 197 | SCRIPT_END;
|
|
0 commit comments