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
 * Class abstract_data_source.
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
namespace block_dash\local\dash_framework\structure;
26
 
27
use block_dash\local\data_grid\field\attribute\date_attribute;
28
use block_dash\local\data_grid\field\attribute\identifier_attribute;
29
use block_dash\local\data_grid\field\attribute\image_attribute;
30
use block_dash\local\data_grid\field\attribute\image_url_attribute;
31
use block_dash\local\data_grid\field\attribute\link_attribute;
32
use block_dash\local\data_grid\field\attribute\linked_data_attribute;
33
use block_dash\local\data_grid\field\attribute\linked_icon_attribute;
34
use block_dash\local\data_grid\field\attribute\moodle_url_attribute;
35
use block_dash\local\data_grid\field\attribute\rename_group_ids_attribute;
36
use block_dash\local\data_grid\field\attribute\user_image_url_attribute;
37
use block_dash\local\data_grid\field\attribute\bool_attribute;
38
use lang_string;
39
use moodle_url;
40
 
41
/**
42
 * Class abstract_data_source.
43
 *
44
 * @package block_dash
45
 */
46
class user_table extends table {
47
 
48
    /**
49
     * Build a new table.
50
     */
51
    public function __construct() {
52
        parent::__construct('user', 'u');
53
    }
54
 
55
    /**
56
     * Get human readable title for table.
57
     *
58
     * @return string
59
     */
60
    public function get_title(): string {
61
        return get_string('users');
62
    }
63
 
64
    /**
65
     * Get fields and its definition for user table.
66
     * @return field_interface[]
67
     */
68
    public function get_fields(): array {
69
        global $DB, $CFG;
70
        $groupconcat = $DB->sql_group_concat('g200.id', ',');
71
        $fields = [
72
            new field('id', new lang_string('user'), $this, null, [
73
                new identifier_attribute(),
74
            ]),
75
            new field('firstname', new lang_string('firstname'), $this),
76
            new field('lastname', new lang_string('lastname'), $this),
77
            new field('fullname', new lang_string('fullname'), $this, $DB->sql_concat_join("' '", ['u.firstname', 'u.lastname'])),
78
            new field('fullname_linked', new lang_string('fullnamelinked', 'block_dash'),
79
                $this, $DB->sql_concat_join("' '", ['u.firstname', 'u.lastname']), [
80
                    new moodle_url_attribute(['url' => new moodle_url('/user/profile.php', ['id' => 'u_id'])]),
81
                    new link_attribute(['label_field' => 'u_fullname_linked']),
82
                ],
83
                ['supports_sorting' => false]
84
            ),
85
            new field('email', new lang_string('email'), $this),
86
            new field('username', new lang_string('username'), $this),
87
            new field('idnumber', new lang_string('idnumber'), $this),
88
            new field('city', new lang_string('city'), $this),
89
            new field('country', new lang_string('country'), $this),
90
            new field('lastlogin', new lang_string('lastlogin'), $this, null, [
91
                new date_attribute(),
92
            ]),
93
            new field('department', new lang_string('department'), $this),
94
            new field('institution', new lang_string('institution'), $this),
95
            new field('address', new lang_string('address'), $this),
96
            new field('alternatename', new lang_string('alternatename'), $this),
97
            new field('firstaccess', new lang_string('firstaccess'), $this, null, [
98
                new date_attribute(),
99
            ]),
100
            new field('description', new lang_string('description'), $this),
101
            new field('picture_url', new lang_string('pictureofuserurl', 'block_dash'), $this, 'u.id', [
102
                new image_url_attribute(),
103
                new user_image_url_attribute(),
104
            ]),
105
            new field('picture', new lang_string('pictureofuser'), $this, 'u.id', [
106
                new user_image_url_attribute(),
107
                new image_attribute(['title' => new lang_string('pictureofuser')]),
108
            ]),
109
            new field('picture_linked', new lang_string('pictureofuserlinked', 'block_dash'), $this, 'u.id', [
110
                new user_image_url_attribute(),
111
                new image_attribute(['title' => new lang_string('pictureofuser')]),
112
                new linked_data_attribute(['url' => new moodle_url('/user/profile.php', ['id' => 'u_id'])]),
113
            ]),
114
            new field('profile_url', new lang_string('userprofileurl', 'block_dash'), $this, 'u.id', [
115
                new moodle_url_attribute(['url' => new moodle_url('/user/profile.php', ['id' => 'u_id'])]),
116
            ]),
117
            new field('profile_link', new lang_string('userprofilelink', 'block_dash'), $this, 'u.id', [
118
                new moodle_url_attribute(['url' => new moodle_url('/user/profile.php', ['id' => 'u_id'])]),
119
                new link_attribute(['label' => new lang_string('viewprofile')]),
120
            ]),
121
            new field('message_url', new lang_string('messageurl', 'block_dash'), $this, 'u.id', [
122
                new moodle_url_attribute(['url' => new moodle_url('/message/index.php', ['id' => 'u_id'])]),
123
            ]),
124
            new field('message_link', new lang_string('message', 'message'), $this, 'u.id', [
125
                new moodle_url_attribute(['url' => new moodle_url('/message/index.php', ['id' => 'u_id'])]),
126
                new linked_icon_attribute([
127
                    'icon' => 'i/email',
128
                    'title' => get_string('sendmessage', 'message'),
129
                ]),
130
            ]),
131
            new field('group_names', new lang_string('group'), $this, [
132
                'select' => "(SELECT $groupconcat FROM {groups} g200
133
                            JOIN {groups_members} gm200 ON gm200.groupid = g200.id WHERE gm200.userid = u.id)",
134
            ], [
135
                new rename_group_ids_attribute([
136
                    'table' => 'groups',
137
                    'field' => 'name',
138
                    'delimiter' => ',', // Separator between each ID in SQL select.
139
                ]),
140
            ], [], field_interface::VISIBILITY_VISIBLE, ''),
141
        ];
142
 
143
        require_once("$CFG->dirroot/user/profile/lib.php");
144
 
145
        $i = 0;
146
        foreach (profile_get_custom_fields() as $customfield) {
147
            $name = 'pf_' . strtolower($customfield->shortname);
148
            $profileattributes = [];
149
 
150
            switch ($customfield->datatype) {
151
                case 'checkbox':
152
                    $profileattributes[] = new bool_attribute();
153
                    break;
154
                case 'datetime':
155
                    $profileattributes[] = new date_attribute();
156
                    break;
157
                case 'textarea':
158
                    break;
159
            }
160
 
161
            $fields[] = new field(
162
                $name,
163
                new lang_string('customfield', 'block_dash', ['name' => format_string($customfield->name)]),
164
                $this,
165
                "(SELECT profile$i.data FROM {user_info_data} profile$i
166
                      WHERE profile$i.userid = u.id AND profile$i.fieldid = $customfield->id)",
167
                $profileattributes, [], field_interface::VISIBILITY_VISIBLE , '',
168
            );
169
 
170
            $i++;
171
        }
172
 
173
        return $fields;
174
    }
175
}