MDL-61135 mod_quiz: move fragment_view functions to custom_view class
[moodle.git] / mod / quiz / classes / question / bank / fragment_view.php
blob45e3b54a50bb185cf214066d54fcba813e9aee52
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.
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/>.
17 /**
18 * Defines the custom question bank view used in the question bank modal.
20 * @package mod_quiz
21 * @category question
22 * @copyright 2018 Ryan Wyllie <ryan@moodle.com>
23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
26 namespace mod_quiz\question\bank;
27 defined('MOODLE_INTERNAL') || die();
30 /**
31 * Subclass to customise the view of the question bank for a fragment.
33 * This view is to be used when returning the question bank as part of
34 * a fragment.
36 * @copyright 2018 Ryan Wyllie <ryan@moodle.com>
37 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
39 class fragment_view extends custom_view {
40 /**
41 * Override the base implementation in \core_question\bank\view
42 * because we don't want to print the headers in the fragment
43 * for the modal.
45 protected function display_question_bank_header() {
48 /**
49 * Override the base implementation in \core_question\bank\view
50 * because we don't want it to read from the $_POST global variables
51 * for the sort parameters since they are not present in a fragment.
53 * Unfortunately the best we can do is to look at the URL for
54 * those parameters (only marginally better really).
56 protected function init_sort_from_params() {
57 $this->sort = [];
58 for ($i = 1; $i <= self::MAX_SORTS; $i++) {
59 if (!$sort = $this->baseurl->param('qbs' . $i)) {
60 break;
62 // Work out the appropriate order.
63 $order = 1;
64 if ($sort[0] == '-') {
65 $order = -1;
66 $sort = substr($sort, 1);
67 if (!$sort) {
68 break;
71 // Deal with subsorts.
72 list($colname, $subsort) = $this->parse_subsort($sort);
73 $this->requiredcolumns[$colname] = $this->get_column_type($colname);
74 $this->sort[$sort] = $order;