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
declare(strict_types=1);
18
 
19
namespace core\output\dynamic_tabs;
20
 
1441 ariadna 21
use core\exception\moodle_exception;
22
use core\output\templatable;
1 efrain 23
 
24
/**
25
 * Class tab_base
26
 *
27
 * @package     core
28
 * @copyright   2018 Marina Glancy
29
 * @license     http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
30
 */
31
abstract class base implements templatable {
32
    /** @var array */
33
    protected $data;
34
 
35
    /**
36
     * tab constructor.
37
     *
38
     * @param array $data
39
     */
40
    final public function __construct(array $data) {
41
        $this->data = $data;
42
    }
43
 
44
    /**
45
     * HTML "id" attribute that should be used for this tab, by default the last part of class name
46
     *
47
     * @return string
48
     */
49
    public function get_tab_id(): string {
50
        $parts = preg_split('/\\\\/', static::class);
51
        return array_pop($parts);
52
    }
53
 
54
    /**
55
     * The label to be displayed on the tab
56
     *
57
     * @return string
58
     */
59
    abstract public function get_tab_label(): string;
60
 
61
    /**
62
     * Check permission of the current user to access this tab
63
     *
64
     * @return bool
65
     */
66
    abstract public function is_available(): bool;
67
 
68
    /**
69
     * Check that tab is accessible, throw exception otherwise - used from WS requesting tab contents
70
     *
71
     * @throws moodle_exception
72
     */
73
    final public function require_access() {
74
        if (!$this->is_available()) {
75
            throw new moodle_exception('nopermissiontoaccesspage', 'error');
76
        }
77
    }
78
 
79
    /**
80
     * Template to use to display tab contents
81
     *
82
     * @return string
83
     */
84
    abstract public function get_template(): string;
85
 
86
    /**
87
     * Return tab data attributes
88
     *
89
     * @return array
90
     */
91
    public function get_data(): array {
92
        return $this->data;
93
    }
94
 
95
    /**
96
     * Add custom data to the tab data attributes
97
     *
98
     * @param array $data
99
     */
100
    public function add_data(array $data): void {
101
        $this->data = array_merge($this->data, $data);
102
    }
103
}