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_table\output;
18
 
19
/**
20
 * Holds all the information required to render a <table> by {@see core_renderer::table()}
21
 *
22
 * Example of usage:
23
 * $t = new html_table();
24
 * ... // set various properties of the object $t as described below
25
 * echo html_writer::table($t);
26
 *
27
 * @copyright 2009 David Mudrak <david.mudrak@gmail.com>
28
 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
29
 * @since Moodle 2.0
30
 * @package core_table
31
 * @category output
32
 */
33
class html_table {
34
    /**
35
     * @var string Value to use for the id attribute of the table
36
     */
37
    public $id = null;
38
 
39
    /**
40
     * @var array Attributes of HTML attributes for the <table> element
41
     */
42
    public $attributes = [];
43
 
44
    /**
45
     * @var array An array of headings. The n-th array item is used as a heading of the n-th column.
46
     * For more control over the rendering of the headers, an array of html_table_cell objects
47
     * can be passed instead of an array of strings.
48
     *
49
     * Example of usage:
50
     * $t->head = array('Student', 'Grade');
51
     */
52
    public $head;
53
 
54
    /**
55
     * @var array An array that can be used to make a heading span multiple columns.
56
     * In this example, {@see html_table:$data} is supposed to have three columns. For the first two columns,
57
     * the same heading is used. Therefore, {@see html_table::$head} should consist of two items.
58
     *
59
     * Example of usage:
60
     * $t->headspan = array(2,1);
61
     */
62
    public $headspan;
63
 
64
    /**
65
     * @var array An array of column alignments.
66
     * The value is used as CSS 'text-align' property. Therefore, possible
67
     * values are 'left', 'right', 'center' and 'justify'. Specify 'right' or 'left' from the perspective
68
     * of a left-to-right (LTR) language. For RTL, the values are flipped automatically.
69
     *
70
     * Examples of usage:
71
     * $t->align = array(null, 'right');
72
     * or
73
     * $t->align[1] = 'right';
74
     */
75
    public $align;
76
 
77
    /**
78
     * @var array The value is used as CSS 'size' property.
79
     *
80
     * Examples of usage:
81
     * $t->size = array('50%', '50%');
82
     * or
83
     * $t->size[1] = '120px';
84
     */
85
    public $size;
86
 
87
    /**
88
     * @var array An array of wrapping information.
89
     * The only possible value is 'nowrap' that sets the
90
     * CSS property 'white-space' to the value 'nowrap' in the given column.
91
     *
92
     * Example of usage:
93
     * $t->wrap = array(null, 'nowrap');
94
     */
95
    public $wrap;
96
 
97
    /**
98
     * @var array Array of arrays or html_table_row objects containing the data. Alternatively, if you have
99
     * $head specified, the string 'hr' (for horizontal ruler) can be used
100
     * instead of an array of cells data resulting in a divider rendered.
101
     *
102
     * Example of usage with array of arrays:
103
     * $row1 = array('Harry Potter', '76 %');
104
     * $row2 = array('Hermione Granger', '100 %');
105
     * $t->data = array($row1, $row2);
106
     *
107
     * Example with array of html_table_row objects: (used for more fine-grained control)
108
     * $cell1 = new html_table_cell();
109
     * $cell1->text = 'Harry Potter';
110
     * $cell1->colspan = 2;
111
     * $row1 = new html_table_row();
112
     * $row1->cells[] = $cell1;
113
     * $cell2 = new html_table_cell();
114
     * $cell2->text = 'Hermione Granger';
115
     * $cell3 = new html_table_cell();
116
     * $cell3->text = '100 %';
117
     * $row2 = new html_table_row();
118
     * $row2->cells = array($cell2, $cell3);
119
     * $t->data = array($row1, $row2);
120
     */
121
    public $data = [];
122
 
123
    /**
124
     * @var string Width of the table, percentage of the page preferred.
125
     * @deprecated since Moodle 2.0. Styling should be in the CSS.
126
     */
127
    public $width = null;
128
 
129
    /**
130
     * @var string Alignment for the whole table. Can be 'right', 'left' or 'center' (default).
131
     * @deprecated since Moodle 2.0. Styling should be in the CSS.
132
     */
133
    public $tablealign = null;
134
 
135
    /**
136
     * @var int Padding on each cell, in pixels
137
     * @deprecated since Moodle 2.0. Styling should be in the CSS.
138
     */
139
    public $cellpadding = null;
140
 
141
    /**
142
     * @var int Spacing between cells, in pixels
143
     * @deprecated since Moodle 2.0. Styling should be in the CSS.
144
     */
145
    public $cellspacing = null;
146
 
147
    /**
148
     * @var array Array of classes to add to particular rows, space-separated string.
149
     * Class 'lastrow' is added automatically for the last row in the table.
150
     *
151
     * Example of usage:
152
     * $t->rowclasses[9] = 'tenth'
153
     */
154
    public $rowclasses;
155
 
156
    /**
157
     * @var array An array of classes to add to every cell in a particular column,
158
     * space-separated string. Class 'cell' is added automatically by the renderer.
159
     * Classes 'c0' or 'c1' are added automatically for every odd or even column,
160
     * respectively. Class 'lastcol' is added automatically for all last cells
161
     * in a row.
162
     *
163
     * Example of usage:
164
     * $t->colclasses = array(null, 'grade');
165
     */
166
    public $colclasses;
167
 
168
    /**
169
     * @var string Description of the contents for screen readers.
170
     *
171
     * The "summary" attribute on the "table" element is not supported in HTML5.
172
     * Consider describing the structure of the table in a "caption" element or in a "figure" element containing the table;
173
     * or, simplify the structure of the table so that no description is needed.
174
     *
175
     * @deprecated since Moodle 3.9.
176
     */
177
    public $summary;
178
 
179
    /**
180
     * @var string Caption for the table, typically a title.
181
     *
182
     * Example of usage:
183
     * $t->caption = "TV Guide";
184
     */
185
    public $caption;
186
 
187
    /**
188
     * @var bool Whether to hide the table's caption from sighted users.
189
     *
190
     * Example of usage:
191
     * $t->caption = "TV Guide";
192
     * $t->captionhide = true;
193
     */
194
    public $captionhide = false;
195
 
196
    /** @var bool Whether to make the table to be scrolled horizontally with ease. Make table responsive across all viewports. */
197
    public $responsive = true;
198
 
199
    /** @var string class name to add to this html table. */
200
    public $class;
201
 
202
    /**
203
     * Constructor
204
     */
205
    public function __construct() {
206
        $this->attributes['class'] = '';
207
    }
208
}
209
 
210
// Alias this class to the old name.
211
// This file will be autoloaded by the legacyclasses autoload system.
212
// In future all uses of this class will be corrected and the legacy references will be removed.
213
class_alias(html_table::class, \html_table::class);