Proyectos de Subversion Moodle

Rev

| 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',
71
            'createdby' => 2,
72
            'categoryid' => 1,
73
            'contextid' => 1,
74
            'status' => 'ready',
75
            'version' => 1,
76
            'versionid' => 1,
77
            'questionbankentryid' => 1,
78
            'name' => 'Lorem ipsum',
79
            'idnumber' => 123,
80
            'creatorfirstname' => 'Admin',
81
            'creatorlastname' => 'User',
82
            'timecreated' => 1691157311,
83
            'modifierfirstname' => 'Admin',
84
            'modifierlastname' => 'User',
85
            'timemodified' => 1691157311,
86
        ];
87
    }
88
 
89
    /**
90
     * Generate a preview of the question bank table with a single dummy question.
91
     *
92
     * @return string An HTML table containing the column headings and a single question row.
93
     */
94
    public function get_preview(): string {
95
        ob_start();
96
        $this->display_questions([$this->get_dummy_question()]);
97
        return ob_get_clean();
98
    }
99
}