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
/**
18
 * Form for editing block preferences.
19
 *
20
 * @package    block_dash
21
 * @copyright  2019 bdecent gmbh <https://bdecent.de>
22
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23
 */
24
 
25
namespace block_dash\local\data_source\form;
26
 
27
use block_dash\local\configuration\configuration;
28
 
29
defined('MOODLE_INTERNAL') || die('No direct access');
30
 
31
require_once($CFG->libdir . '/formslib.php');
32
 
33
/**
34
 * Form for editing block preferences.
35
 *
36
 * @package    block_dash
37
 * @copyright  2019 bdecent gmbh <https://bdecent.de>
38
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
39
 */
40
class preferences_form extends \moodleform {
41
 
42
    /** @var string General tab id. */
43
    const TAB_GENERAL = 'tabgeneral';
44
 
45
    /** @var string Preference modal fields tab. */
46
    const TAB_FIELDS = 'tabfields';
47
 
48
    /** @var string Preference modal Filters tab. */
49
    const TAB_FILTERS = 'tabfilters';
50
 
51
    /** @var string Preference modal Conditions tab. */
52
    const TAB_CONDITIONS = 'tabconditions';
53
 
54
    /** @var array List of tabs used in preference modal. */
55
    const TABS = [
56
        self::TAB_GENERAL,
57
        self::TAB_FIELDS,
58
        self::TAB_FILTERS,
59
        self::TAB_CONDITIONS,
60
    ];
61
 
62
    /**
63
     * Define form fields.
64
     *
65
     * @throws \coding_exception
66
     * @throws \dml_exception
67
     */
68
    protected function definition() {
69
        $block = $this->_customdata['block'];
70
 
71
        if (!isset($this->_customdata['tab'])) {
72
            $this->_customdata['tab'] = self::TABS[0];
73
        }
74
 
75
        $configuration = configuration::create_from_instance($block);
76
        if ($configuration->is_fully_configured()) {
77
            $configuration->get_data_source()->build_preferences_form($this, $this->_form);
78
        }
79
 
80
        $mform = $this->_form;
81
 
82
        if (empty($mform->_elements)) {
83
            $mform->addElement('html', '<p class="text-muted">' . get_string('nothingtodisplay') . '</p>');
84
        }
85
 
86
        $mform->addElement('html', '<hr>');
87
 
88
        // When two elements we need a group.
89
        $buttonarray = [];
90
        $buttonarray[] = &$mform->createElement('submit', 'submitbutton', get_string('savechanges'));
91
        $buttonarray[] = &$mform->createElement('button', 'cancelbutton', get_string('cancel'), ['data-action' => 'cancel']);
92
        $mform->addGroup($buttonarray, 'buttonar', '', [' '], false);
93
        $mform->closeHeaderBefore('buttonar');
94
    }
95
 
96
    /**
97
     * Get current tab of preferences form.
98
     */
99
    public function get_tab(): string {
100
        return $this->_customdata['tab'];
101
    }
102
}