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
 * Field definitions.
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
defined('MOODLE_INTERNAL') || die();
26
 
27
global $DB;
28
 
29
$groupconcat = $DB->sql_group_concat('g200.id', ',');
30
 
31
$definitions = [
32
    [
33
        'name' => 'u_id',
34
        'select' => 'u.id',
35
        'title' => get_string('user') . ' ID',
36
        'attributes' => [
37
            [
38
                'type' => \block_dash\local\data_grid\field\attribute\identifier_attribute::class,
39
            ],
40
        ],
41
        'tables' => ['u'],
42
    ],
43
    [
44
        'name' => 'u_firstname',
45
        'select' => 'u.firstname',
46
        'title' => get_string('firstname'),
47
        'tables' => ['u'],
48
    ],
49
    [
50
        'name' => 'u_lastname',
51
        'select' => 'u.lastname',
52
        'title' => get_string('lastname'),
53
        'tables' => ['u'],
54
    ],
55
    [
56
        'name' => 'u_fullname',
57
        'select' => $DB->sql_concat_join("' '", ['u.firstname', 'u.lastname']),
58
        'title' => get_string('fullname'),
59
        'tables' => ['u'],
60
    ],
61
    [
62
        'name' => 'u_fullname_linked',
63
        'select' => $DB->sql_concat_join("' '", ['u.firstname', 'u.lastname']),
64
        'title' => get_string('fullnamelinked', 'block_dash'),
65
        'tables' => ['u'],
66
        'options' => ['supports_sorting' => false],
67
        'attributes' => [
68
            [
69
                'type' => \block_dash\local\data_grid\field\attribute\moodle_url_attribute::class,
70
                'options' => [
71
                    'url' => new moodle_url('/user/profile.php', ['id' => 'u_id']),
72
                ],
73
            ],
74
            [
75
                'type' => \block_dash\local\data_grid\field\attribute\link_attribute::class,
76
                'options' => [
77
                    'label_field' => 'u_fullname_linked',
78
                ],
79
            ],
80
        ],
81
    ],
82
    [
83
        'name' => 'u_email',
84
        'select' => 'u.email',
85
        'title' => get_string('email'),
86
        'tables' => ['u'],
87
    ],
88
    [
89
        'name' => 'u_username',
90
        'select' => 'u.username',
91
        'title' => get_string('username'),
92
        'tables' => ['u'],
93
    ],
94
    [
95
        'name' => 'u_idnumber',
96
        'select' => 'u.idnumber',
97
        'title' => get_string('idnumber'),
98
        'tables' => ['u'],
99
    ],
100
    [
101
        'name' => 'u_city',
102
        'select' => 'u.city',
103
        'title' => get_string('city'),
104
        'tables' => ['u'],
105
    ],
106
    [
107
        'name' => 'u_country',
108
        'select' => 'u.country',
109
        'title' => get_string('country'),
110
        'tables' => ['u'],
111
    ],
112
    [
113
        'name' => 'u_lastlogin',
114
        'select' => 'u.lastlogin',
115
        'title' => get_string('lastlogin'),
116
        'tables' => ['u'],
117
        'attributes' => [
118
            [
119
                'type' => \block_dash\local\data_grid\field\attribute\date_attribute::class,
120
            ],
121
        ],
122
    ],
123
    [
124
        'name' => 'u_department',
125
        'select' => 'u.department',
126
        'title' => get_string('department'),
127
        'tables' => ['u'],
128
    ],
129
    [
130
        'name' => 'u_institution',
131
        'select' => 'u.institution',
132
        'title' => get_string('institution'),
133
        'tables' => ['u'],
134
    ],
135
    [
136
        'name' => 'u_address',
137
        'select' => 'u.address',
138
        'title' => get_string('address'),
139
        'tables' => ['u'],
140
    ],
141
    [
142
        'name' => 'u_alternatename',
143
        'select' => 'u.alternatename',
144
        'title' => get_string('alternatename'),
145
        'tables' => ['u'],
146
    ],
147
    [
148
        'name' => 'u_firstaccess',
149
        'select' => 'u.firstaccess',
150
        'title' => get_string('firstaccess'),
151
        'tables' => ['u'],
152
        'attributes' => [
153
            [
154
                'type' => \block_dash\local\data_grid\field\attribute\date_attribute::class,
155
            ],
156
        ],
157
    ],
158
    [
159
        'name' => 'u_description',
160
        'select' => 'u.description',
161
        'title' => get_string('description'),
162
        'tables' => ['u'],
163
    ],
164
    [
165
        'name' => 'u_picture_url',
166
        'select' => 'u.id',
167
        'title' => get_string('pictureofuser') . ' URL',
168
        'tables' => ['u'],
169
        'attributes' => [
170
            [
171
                'type' => \block_dash\local\data_grid\field\attribute\image_url_attribute::class,
172
            ],
173
            [
174
                'type' => \block_dash\local\data_grid\field\attribute\user_image_url_attribute::class,
175
            ],
176
        ],
177
    ],
178
    [
179
        'name' => 'u_picture',
180
        'select' => 'u.id',
181
        'title' => get_string('pictureofuser'),
182
        'tables' => ['u'],
183
        'attributes' => [
184
            [
185
                'type' => \block_dash\local\data_grid\field\attribute\user_image_url_attribute::class,
186
            ],
187
            [
188
                'type' => \block_dash\local\data_grid\field\attribute\image_attribute::class,
189
                'options' => [
190
                    'title' => get_string('pictureofuser'),
191
                ],
192
            ],
193
        ],
194
    ],
195
    [
196
        'name' => 'u_picture_linked',
197
        'select' => 'u.id',
198
        'title' => get_string('pictureofuserlinked', 'block_dash'),
199
        'tables' => ['u'],
200
        'attributes' => [
201
            [
202
                'type' => \block_dash\local\data_grid\field\attribute\user_image_url_attribute::class,
203
            ],
204
            [
205
                'type' => \block_dash\local\data_grid\field\attribute\image_attribute::class,
206
                'options' => [
207
                    'title' => get_string('pictureofuser'),
208
                ],
209
            ],
210
            [
211
                'type' => \block_dash\local\data_grid\field\attribute\linked_data_attribute::class,
212
                'options' => [
213
                    'url' => new moodle_url('/user/profile.php', ['id' => 'u_id']),
214
                ],
215
            ],
216
        ],
217
    ],
218
    [
219
        'name' => 'u_profile_url',
220
        'select' => 'u.id',
221
        'title' => get_string('userprofileurl', 'block_dash'),
222
        'tables' => ['u'],
223
        'attributes' => [
224
            [
225
                'type' => \block_dash\local\data_grid\field\attribute\moodle_url_attribute::class,
226
                'options' => [
227
                    'url' => new moodle_url('/user/profile.php', ['id' => 'u_id']),
228
                ],
229
            ],
230
        ],
231
    ],
232
    [
233
        'name' => 'u_profile_link',
234
        'select' => 'u.id',
235
        'title' => get_string('userprofilelink', 'block_dash'),
236
        'tables' => ['u'],
237
        'attributes' => [
238
            [
239
                'type' => \block_dash\local\data_grid\field\attribute\moodle_url_attribute::class,
240
                'options' => [
241
                    'url' => new moodle_url('/user/profile.php', ['id' => 'u_id']),
242
                ],
243
            ],
244
            [
245
                'type' => \block_dash\local\data_grid\field\attribute\link_attribute::class,
246
                'options' => [
247
                    'label' => get_string('viewprofile'),
248
                ],
249
            ],
250
        ],
251
    ],
252
    [
253
        'name' => 'u_message_url',
254
        'select' => 'u.id',
255
        'title' => get_string('message', 'message') . ' URL',
256
        'tables' => ['u'],
257
        'attributes' => [
258
            [
259
                'type' => \block_dash\local\data_grid\field\attribute\moodle_url_attribute::class,
260
                'options' => [
261
                    'url' => new moodle_url('/message/index.php', ['id' => 'u_id']),
262
                ],
263
            ],
264
        ],
265
    ],
266
    [
267
        'name' => 'u_message_link',
268
        'select' => 'u.id',
269
        'title' => get_string('message', 'message'),
270
        'tables' => ['u'],
271
        'attributes' => [
272
            [
273
                'type' => \block_dash\local\data_grid\field\attribute\moodle_url_attribute::class,
274
                'options' => [
275
                    'url' => new moodle_url('/message/index.php', ['id' => 'u_id']),
276
                ],
277
            ],
278
            [
279
                'type' => \block_dash\local\data_grid\field\attribute\linked_icon_attribute::class,
280
                'options' => [
281
                    'icon' => 'i/email',
282
                    'title' => get_string('sendmessage', 'message'),
283
                ],
284
            ],
285
        ],
286
    ],
287
    [
288
        'name' => 'u_group_names',
289
        'select' => "(SELECT $groupconcat FROM {groups} g200
290
            JOIN {groups_members} gm200 ON gm200.groupid = g200.id WHERE gm200.userid = u.id)",
291
        'title' => get_string('group'),
292
        'tables' => ['u'],
293
        'attributes' => [
294
            [
295
                'type' => \block_dash\local\data_grid\field\attribute\rename_group_ids_attribute::class,
296
                'options' => [
297
                    'table' => 'groups',
298
                    'field' => 'name',
299
                    'delimiter' => ',', // Separator between each ID in SQL select.
300
                ],
301
            ],
302
        ],
303
    ],
304
];
305
 
306
require_once("$CFG->dirroot/user/profile/lib.php");
307
 
308
$i = 0;
309
foreach (profile_get_custom_fields() as $customfield) {
310
    $definitions[] = [
311
        'name' => 'u_pf_' . strtolower($customfield->shortname),
312
        'select' => "(SELECT profile$i.data FROM {user_info_data} profile$i
313
                      WHERE profile$i.userid = u.id AND profile$i.fieldid = $customfield->id)",
314
        'title' => format_string($customfield->name),
315
        'tables' => ['u'],
316
    ];
317
 
318
    $i++;
319
}
320
 
321
$definitions = array_merge($definitions, [
322
    [
323
        'name' => 'g_id',
324
        'select' => 'g.id',
325
        'title' => get_string('group') . ' ID',
326
        'tables' => ['g'],
327
        'attributes' => [
328
            [
329
                'type' => \block_dash\local\data_grid\field\attribute\identifier_attribute::class,
330
            ],
331
        ],
332
    ],
333
    [
334
        'name' => 'g_name',
335
        'select' => 'g.name',
336
        'title' => get_string('groupname', 'group'),
337
        'tables' => ['g'],
338
    ],
339
]);
340
 
341
return $definitions;