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
 * Represents a predefined field that can be added to a data source.
19
 *
20
 * @package    block_dash
21
 * @copyright  2020 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\dash_framework\structure;
26
 
27
use block_dash\local\data_grid\field\attribute\field_attribute_interface;
28
use lang_string;
29
/**
30
 * Represents a predefined field that can be added to a data grid.
31
 *
32
 * @package block_dash
33
 */
34
interface field_interface {
35
 
36
    /**
37
     * Visible to user.
38
     */
39
    const VISIBILITY_VISIBLE = 1;
40
 
41
    /**
42
     * Not visible to user.
43
     */
44
    const VISIBILITY_HIDDEN = 0;
45
 
46
    /**
47
     * Value to display when empty or null.
48
     */
49
    const DEFAULT_EMPTY_VALUE = '-';
50
 
51
    /**
52
     * After records are relieved from database each field has a chance to transform the data.
53
     * Example: Convert unix timestamp into a human readable date format
54
     *
55
     * @param mixed $data Raw data associated with this field definition.
56
     * @param \stdClass $record Full record from database.
57
     * @return mixed
58
     */
59
    public function transform_data($data, \stdClass $record);
60
 
61
    // Region Property methods.
62
 
63
    /**
64
     * Get the column name of the field as it appears in the table (e.g. firstname).
65
     *
66
     * @return string
67
     */
68
    public function get_name(): string;
69
 
70
    /**
71
     * Get field alias for query.
72
     *
73
     * @return string
74
     */
75
    public function get_alias(): string;
76
 
77
    /**
78
     * Human readable name of field (e.g. Firstname).
79
     *
80
     * @return lang_string
81
     */
82
    public function get_title(): lang_string;
83
 
84
    /**
85
     * Override field title.
86
     *
87
     * @param lang_string $title
88
     */
89
    public function set_title(lang_string $title): void;
90
 
91
    /**
92
     * Get table this field belongs to.
93
     *
94
     * @return table
95
     */
96
    public function get_table(): table;
97
 
98
    /**
99
     * Get SQL select for this field, minus alias.
100
     *
101
     * @return string
102
     */
103
    public function get_select(): string;
104
 
105
    /**
106
     * Get field visibility.
107
     *
108
     * @return int
109
     */
110
    public function get_visibility();
111
 
112
    /**
113
     * Set field visibility.
114
     *
115
     * @param int $visibility
116
     */
117
    public function set_visibility($visibility);
118
 
119
    // Endregion.
120
 
121
    // Region Attributes.
122
 
123
    /**
124
     * Add attribute to this field definition.
125
     *
126
     * @param field_attribute_interface $attribute
127
     */
128
    public function add_attribute(field_attribute_interface $attribute);
129
 
130
    /**
131
     * Remove attribute to this field definition.
132
     *
133
     * @param field_attribute_interface $attribute
134
     */
135
    public function remove_attribute(field_attribute_interface $attribute);
136
 
137
    /**
138
     * Get all attributes associated with this field definition.
139
     *
140
     * @return field_attribute_interface[]
141
     */
142
    public function get_attributes();
143
 
144
    /**
145
     * Check if field has an attribute type.
146
     *
147
     * @param string $classname Full class path to attribute
148
     * @return bool
149
     */
150
    public function has_attribute($classname);
151
 
152
    // Endregion.
153
 
154
    // Region Options.
155
 
156
    /**
157
     * Get a single option.
158
     *
159
     * @param string $name
160
     * @return mixed|null
161
     */
162
    public function get_option($name);
163
 
164
    /**
165
     * Set option on field.
166
     *
167
     * @param string $name
168
     * @param string $value
169
     */
170
    public function set_option($name, $value);
171
 
172
    /**
173
     * Set options on field.
174
     *
175
     * @param array $options
176
     */
177
    public function set_options($options);
178
 
179
    /**
180
     * Get all options for this field.
181
     *
182
     * @return array
183
     */
184
    public function get_options();
185
 
186
    // Endregion.
187
 
188
    // Region Sorting.
189
 
190
    /**
191
     * Set if field should be sorted.
192
     *
193
     * @param bool $sort
194
     * @throws \Exception
195
     */
196
    public function set_sort($sort);
197
 
198
    /**
199
     * Is the field sorted.
200
     *
201
     * @return bool
202
     */
203
    public function get_sort();
204
 
205
    /**
206
     * Set direction sort should happen for this field.
207
     *
208
     * @param string $direction
209
     * @throws \Exception
210
     */
211
    public function set_sort_direction($direction);
212
 
213
    /**
214
     * Get sort direction.
215
     *
216
     * @return string
217
     */
218
    public function get_sort_direction();
219
 
220
    /**
221
     * Set optional sort select (ORDER BY <select>), useful for fields that can't sort based on their field name.
222
     *
223
     * @param string $select
224
     */
225
    public function set_sort_select($select);
226
 
227
    /**
228
     * Return select for ORDER BY.
229
     *
230
     * @return string
231
     */
232
    public function get_sort_select();
233
 
234
    // Endregion.
235
}