Proyectos de Subversion Moodle

Rev

Rev 1 | | Comparar con el anterior | 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 qbank_columnsortorder\local\bank;
18
 
19
use core_question\local\bank\view;
20
use qbank_columnsortorder\column_manager;
21
 
22
/**
23
 * Custom view for displaying a preview of the question bank
24
 *
25
 * @package   qbank_columnsortorder
26
 * @copyright 2023 onwards Catalyst IT EU {@link https://catalyst-eu.net}
27
 * @author    Mark Johnson <mark.johnson@catalyst-eu.net>
28
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
29
 */
30
class preview_view extends view {
31
    /**
32
     * Use global settings for the column manager.
33
     *
34
     * @return void
35
     */
36
    protected function init_column_manager(): void {
37
        $this->columnmanager = new column_manager(true);
38
    }
39
 
40
    /**
41
     * Prints the table row with the preview data for each column.
42
     *
43
     * @param \stdClass $question
44
     * @param int $rowcount
45
     */
46
    public function print_table_row($question, $rowcount): void {
47
        $rowclasses = implode(' ', $this->get_row_classes($question, $rowcount));
48
        $attributes = [];
49
        if ($rowclasses) {
50
            $attributes['class'] = $rowclasses;
51
        }
52
        echo \html_writer::start_tag('tr', $attributes);
53
        foreach ($this->visiblecolumns as $column) {
54
            $column->display_preview($question, $rowclasses);
55
        }
56
        echo \html_writer::end_tag('tr');
57
        foreach ($this->extrarows as $row) {
58
            $row->display_preview($question, $rowclasses);
59
        }
60
    }
61
 
62
    /**
63
     * Get a dummy question containing valid data for the default question fields.
64
     *
65
     * @return \stdClass
66
     */
67
    protected function get_dummy_question(): \stdClass {
68
        return (object)[
69
            'id' => 1,
70
            'qtype' => 'truefalse',
1441 ariadna 71
            'questiontext' => 'Is the moon made of cheese?',
72
            'questiontextformat' => FORMAT_PLAIN,
1 efrain 73
            'createdby' => 2,
74
            'categoryid' => 1,
75
            'contextid' => 1,
76
            'status' => 'ready',
77
            'version' => 1,
78
            'versionid' => 1,
79
            'questionbankentryid' => 1,
80
            'name' => 'Lorem ipsum',
81
            'idnumber' => 123,
82
            'creatorfirstname' => 'Admin',
83
            'creatorlastname' => 'User',
84
            'timecreated' => 1691157311,
85
            'modifierfirstname' => 'Admin',
86
            'modifierlastname' => 'User',
87
            'timemodified' => 1691157311,
1441 ariadna 88
            'isdummy' => true,
1 efrain 89
        ];
90
    }
91
 
92
    /**
93
     * Generate a preview of the question bank table with a single dummy question.
94
     *
95
     * @return string An HTML table containing the column headings and a single question row.
96
     */
97
    public function get_preview(): string {
98
        ob_start();
99
        $this->display_questions([$this->get_dummy_question()]);
100
        return ob_get_clean();
101
    }
102
}