Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1441 ariadna 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_block\output;
18
 
19
/**
20
 * This class represents how a block appears on a page.
21
 *
22
 * During output, each block instance is asked to return a block_contents object,
23
 * those are then passed to the $OUTPUT->block function for display.
24
 *
25
 * contents should probably be generated using a moodle_block_..._renderer.
26
 *
27
 * Other block-like things that need to appear on the page, for example the
28
 * add new block UI, are also represented as block_contents objects.
29
 *
30
 * @copyright 2009 Tim Hunt
31
 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
32
 * @since Moodle 2.0
33
 * @package core_block
34
 * @category output
35
 */
36
class block_contents {
37
    /** Used when the block cannot be collapsed **/
38
    const NOT_HIDEABLE = 0;
39
 
40
    /** Used when the block can be collapsed but currently is not **/
41
    const VISIBLE = 1;
42
 
43
    /** Used when the block has been collapsed **/
44
    const HIDDEN = 2;
45
 
46
    /**
47
     * @var int Used to set $skipid.
48
     */
49
    protected static $idcounter = 1;
50
 
51
    /**
52
     * @var int All the blocks (or things that look like blocks) printed on
53
     * a page are given a unique number that can be used to construct id="" attributes.
54
     * This is set automatically be the {@see prepare()} method.
55
     * Do not try to set it manually.
56
     */
57
    public $skipid;
58
 
59
    /**
60
     * @var int If this is the contents of a real block, this should be set
61
     * to the block_instance.id. Otherwise this should be set to 0.
62
     */
63
    public $blockinstanceid = 0;
64
 
65
    /**
66
     * @var int If this is a real block instance, and there is a corresponding
67
     * block_position.id for the block on this page, this should be set to that id.
68
     * Otherwise it should be 0.
69
     */
70
    public $blockpositionid = 0;
71
 
72
    /**
73
     * @var array An array of attribute => value pairs that are put on the outer div of this
74
     * block. {@see $id} and {@see $classes} attributes should be set separately.
75
     */
76
    public $attributes;
77
 
78
    /**
79
     * @var string The title of this block. If this came from user input, it should already
80
     * have had format_string() processing done on it. This will be output inside
81
     * <h2> tags. Please do not cause invalid XHTML.
82
     */
83
    public $title = '';
84
 
85
    /**
86
     * @var string The label to use when the block does not, or will not have a visible title.
87
     * You should never set this as well as title... it will just be ignored.
88
     */
89
    public $arialabel = '';
90
 
91
    /**
92
     * @var string HTML for the content
93
     */
94
    public $content = '';
95
 
96
    /**
97
     * @var array An alternative to $content, it you want a list of things with optional icons.
98
     */
99
    public $footer = '';
100
 
101
    /**
102
     * @var string Any small print that should appear under the block to explain
103
     * to the teacher about the block, for example 'This is a sticky block that was
104
     * added in the system context.'
105
     */
106
    public $annotation = '';
107
 
108
    /**
109
     * @var int One of the constants NOT_HIDEABLE, VISIBLE, HIDDEN. Whether
110
     * the user can toggle whether this block is visible.
111
     */
112
    public $collapsible = self::NOT_HIDEABLE;
113
 
114
    /**
115
     * Set this to true if the block is dockable.
116
     * @var bool
117
     */
118
    public $dockable = false;
119
 
120
    /**
121
     * @var array A (possibly empty) array of editing controls. Each element of
122
     * this array should be an array('url' => $url, 'icon' => $icon, 'caption' => $caption).
123
     * $icon is the icon name. Fed to $OUTPUT->image_url.
124
     */
125
    public $controls = [];
126
 
127
 
128
    /**
129
     * Create new instance of block content.
130
     *
131
     * @param null|array $attributes
132
     */
133
    public function __construct(?array $attributes = null) {
134
        $this->skipid = self::$idcounter;
135
        self::$idcounter += 1;
136
 
137
        if ($attributes) {
138
            // Standard block.
139
            $this->attributes = $attributes;
140
        } else {
141
            // Simple "fake" blocks used in some modules and "Add new block" block.
142
            $this->attributes = ['class' => 'block'];
143
        }
144
    }
145
 
146
    /**
147
     * Add html class to block
148
     *
149
     * @param string $class
150
     */
151
    public function add_class($class) {
152
        $this->attributes['class'] .= ' ' . $class;
153
    }
154
 
155
    /**
156
     * Check if the block is a fake block.
157
     *
158
     * @return boolean
159
     */
160
    public function is_fake() {
161
        return isset($this->attributes['data-block']) && $this->attributes['data-block'] == '_fake';
162
    }
163
}
164
 
165
// Alias this class to the old name.
166
// This file will be autoloaded by the legacyclasses autoload system.
167
// In future all uses of this class will be corrected and the legacy references will be removed.
168
class_alias(block_contents::class, \block_contents::class);