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 core_question\local\bank;
18
 
19
/**
20
 * Abstract class to define functionality shared by all pluggable components used in the question bank view.
21
 *
22
 * @package   core_question
23
 * @copyright 2023 onwards Catalyst IT EU {@link https://catalyst-eu.net}
24
 * @author    Mark Johnson <mark.johnson@catalyst-eu.net>
25
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
26
 */
27
abstract class view_component {
28
    /** @var int value we return from get_menu_position here. Subclasses should override this. */
29
    const MENU_POSITION_NOT_SET = 6666;
30
 
31
    /** @var view Question bank view. */
32
    protected $qbank;
33
 
34
    /**
35
     * Constructor.
36
     * @param view $qbank the question bank view we are helping to render.
37
     */
38
    public function __construct(view $qbank) {
39
        $this->qbank = $qbank;
40
        $this->init();
41
    }
42
 
43
    /**
44
     * A chance for subclasses to initialise themselves, for example to load lang strings,
45
     * without having to override the constructor.
46
     */
47
    protected function init(): void {
48
    }
49
 
50
    /**
51
     * Return an integer to indicate the desired position in the menu for this link, smaller at the top.
52
     *
53
     * The standard menu items in Moodle core return these numbers:
54
     * 100 preview_action
55
     * 200 edit_action
56
     * 250 copy_action
57
     * 300 tags_action
58
     * 400 delete_action
59
     * 500 history_action
60
     * 600 export_xml_action
61
     * (So, if you want your action at a particular place in the order, there should be space.)
62
     *
63
     * If two actions get the same order number, then the tie-break on the sort
64
     * is plugin name, then the order returned by get_question_actions for that plugin.
65
     *
66
     * @return int desired position. Smallest at the top.
67
     */
68
    public function get_menu_position(): int {
69
        // We return a big number by default, which is after all the standard core links,
70
        // so they go first. This should be overridden by all plugins, and not overriding will
71
        // generate a debugging warning from {@see \core_question\local\bank\view::init_question_actions()}.
72
        return self::MENU_POSITION_NOT_SET;
73
    }
74
 
75
    /**
76
     * Return an array 'table_alias' => 'JOIN clause' to bring in any data that
77
     * this feature requires.
78
     *
79
     * The return values for all the features will be checked. It is OK if two
80
     * features join in the same table with the same alias and identical JOIN clauses.
81
     * If two features try to use the same alias with different joins, you get an error.
82
     * Tables included by default are question (alias q) and those defined in {@see view::get_required_joins()}
83
     *
84
     * It is importnat that your join simply adds additional data (or NULLs) to the
85
     * existing rows of the query. It must not cause additional rows.
86
     *
87
     * @return string[] 'table_alias' => 'JOIN clause'
88
     */
89
    public function get_extra_joins(): array {
90
        return [];
91
    }
92
 
93
    /**
94
     * Use table alias 'q' for the question table, or one of the
95
     * ones from get_extra_joins. Every field requested must specify a table prefix.
96
     *
97
     * @return string[] fields required.
98
     */
99
    public function get_required_fields(): array {
100
        return [];
101
    }
102
}