Proyectos de Subversion Moodle

Rev

Rev 1 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 1 Rev 1441
Línea 16... Línea 16...
16
 
16
 
Línea 17... Línea 17...
17
declare(strict_types=1);
17
declare(strict_types=1);
Línea 18... Línea -...
18
 
-
 
19
namespace core_role\reportbuilder\local\entities;
18
 
20
 
19
namespace core_role\reportbuilder\local\entities;
21
use context;
-
 
22
use context_helper;
20
 
23
use lang_string;
21
use core\{context, context_helper};
24
use stdClass;
22
use core\lang_string;
-
 
23
use core_reportbuilder\local\entities\base;
Línea 25... Línea 24...
25
use core_reportbuilder\local\entities\base;
24
use core_reportbuilder\local\filters\select;
26
use core_reportbuilder\local\filters\select;
25
use core_reportbuilder\local\report\{column, filter};
27
use core_reportbuilder\local\report\{column, filter};
26
use stdClass;
28
 
27
 
Línea 82... Línea 81...
82
     * Returns list of all available columns
81
     * Returns list of all available columns
83
     *
82
     *
84
     * @return column[]
83
     * @return column[]
85
     */
84
     */
86
    protected function get_all_columns(): array {
85
    protected function get_all_columns(): array {
87
        global $DB;
-
 
88
 
-
 
89
        $contextalias = $this->get_table_alias('context');
86
        $contextalias = $this->get_table_alias('context');
90
        $rolealias = $this->get_table_alias('role');
87
        $rolealias = $this->get_table_alias('role');
Línea 91... Línea 88...
91
 
88
 
92
        // Name column.
89
        // Name column.
93
        $columns[] = (new column(
90
        $columns[] = (new column(
94
            'name',
91
            'name',
95
            new lang_string('rolefullname', 'core_role'),
92
            new lang_string('rolefullname', 'core_role'),
96
            $this->get_entity_name()
93
            $this->get_entity_name()
97
        ))
94
        ))
98
            ->add_joins($this->get_joins())
-
 
99
            ->set_type(column::TYPE_TEXT)
95
            ->add_joins($this->get_joins())
100
            ->add_fields("{$rolealias}.name, {$rolealias}.shortname, {$rolealias}.id, {$contextalias}.id AS contextid")
96
            ->add_fields("{$rolealias}.name, {$rolealias}.shortname, {$rolealias}.id, {$contextalias}.id AS contextid")
101
            ->add_fields(context_helper::get_preload_record_columns_sql($contextalias))
97
            ->add_fields(context_helper::get_preload_record_columns_sql($contextalias))
102
            // The sorting is on name, unless empty (determined by single space - thanks Oracle) then we use shortname.
98
            // The sorting is on name, unless empty then we use shortname.
103
            ->set_is_sortable(true, [
99
            ->set_is_sortable(true, [
104
                "CASE WHEN " . $DB->sql_concat("{$rolealias}.name", "' '") . " = ' '
100
                "CASE WHEN COALESCE({$rolealias}.name, '') = ''
105
                      THEN {$rolealias}.shortname
101
                      THEN {$rolealias}.shortname
106
                      ELSE {$rolealias}.name
102
                      ELSE {$rolealias}.name
107
                 END",
103
                 END",
108
            ])
104
            ])
109
            ->set_callback(static function($name, stdClass $role): string {
105
            ->add_callback(static function(?string $name, stdClass $role): string {
110
                if ($name === null) {
106
                if ($name === null) {
111
                    return '';
107
                    return '';
Línea 112... Línea 108...
112
                }
108
                }
Línea 122... Línea 118...
122
            'originalname',
118
            'originalname',
123
            new lang_string('roleoriginalname', 'core_role'),
119
            new lang_string('roleoriginalname', 'core_role'),
124
            $this->get_entity_name()
120
            $this->get_entity_name()
125
        ))
121
        ))
126
            ->add_joins($this->get_joins())
122
            ->add_joins($this->get_joins())
127
            ->set_type(column::TYPE_TEXT)
-
 
128
            ->add_fields("{$rolealias}.name, {$rolealias}.shortname")
123
            ->add_fields("{$rolealias}.name, {$rolealias}.shortname")
129
            // The sorting is on name, unless empty (determined by single space - thanks Oracle) then we use shortname.
124
            // The sorting is on name, unless empty then we use shortname.
130
            ->set_is_sortable(true, [
125
            ->set_is_sortable(true, [
131
                "CASE WHEN " . $DB->sql_concat("{$rolealias}.name", "' '") . " = ' '
126
                "CASE WHEN COALESCE({$rolealias}.name, '') = ''
132
                      THEN {$rolealias}.shortname
127
                      THEN {$rolealias}.shortname
133
                      ELSE {$rolealias}.name
128
                      ELSE {$rolealias}.name
134
                 END",
129
                 END",
135
            ])
130
            ])
136
            ->set_callback(static function($name, stdClass $role): string {
131
            ->add_callback(fn(?string $name, stdClass $role) => match ($name) {
137
                if ($name === null) {
-
 
138
                    return '';
132
                null => '',
139
                }
-
 
140
 
-
 
141
                return role_get_name($role, null, ROLENAME_ORIGINAL);
133
                default => role_get_name($role, null, ROLENAME_ORIGINAL),
142
            });
134
            });
Línea 143... Línea 135...
143
 
135
 
144
        // Short name column.
136
        // Short name column.
145
        $columns[] = (new column(
137
        $columns[] = (new column(
146
            'shortname',
138
            'shortname',
147
            new lang_string('roleshortname', 'core_role'),
139
            new lang_string('roleshortname', 'core_role'),
148
            $this->get_entity_name()
140
            $this->get_entity_name()
149
        ))
141
        ))
-
 
142
            ->add_joins($this->get_joins())
150
            ->add_joins($this->get_joins())
143
            ->add_field("{$rolealias}.shortname")
-
 
144
            ->set_is_sortable(true);
-
 
145
 
-
 
146
        // Archetype column.
-
 
147
        $columns[] = (new column(
-
 
148
            'archetype',
-
 
149
            new lang_string('archetype', 'core_role'),
-
 
150
            $this->get_entity_name(),
-
 
151
        ))
151
            ->set_type(column::TYPE_TEXT)
152
            ->add_joins($this->get_joins())
-
 
153
            ->add_field("{$rolealias}.archetype")
-
 
154
            ->add_callback(fn(?string $archetype) => match ($archetype) {
-
 
155
                null => '',
-
 
156
                '' => get_string('none'),
-
 
157
                default => get_string("archetype{$archetype}", 'core_role'),
152
            ->add_fields("{$rolealias}.shortname")
158
            })
Línea 153... Línea 159...
153
            ->set_is_sortable(true);
159
            ->set_is_sortable(true);
154
 
-
 
155
        // Description column.
-
 
156
        $descriptionfieldsql = "{$rolealias}.description";
-
 
157
        if ($DB->get_dbfamily() === 'oracle') {
-
 
158
            $descriptionfieldsql = $DB->sql_order_by_text($descriptionfieldsql, 1024);
160
 
159
        }
161
        // Description column.
160
        $columns[] = (new column(
162
        $columns[] = (new column(
161
            'description',
163
            'description',
162
            new lang_string('description'),
164
            new lang_string('description'),
163
            $this->get_entity_name()
165
            $this->get_entity_name()
164
        ))
166
        ))
165
            ->add_joins($this->get_joins())
167
            ->add_joins($this->get_joins())
166
            ->set_type(column::TYPE_LONGTEXT)
168
            ->set_type(column::TYPE_LONGTEXT)
167
            ->add_field($descriptionfieldsql, 'description')
169
            ->add_fields("{$rolealias}.description, {$rolealias}.shortname")
168
            ->add_field("{$rolealias}.shortname")
-
 
169
            ->set_callback(static function($description, stdClass $role): string {
170
            ->set_is_sortable(true)
170
                if ($description === null) {
-
 
171
                    return '';
-
 
172
                }
171
            ->add_callback(fn(?string $description, stdClass $role) => match ($description) {
173
 
172
                null => '',
Línea 174... Línea 173...
174
                return role_get_description($role);
173
                default => role_get_description($role),
175
            });
174
            });
Línea 196... Línea 195...
196
            ->add_joins($this->get_joins())
195
            ->add_joins($this->get_joins())
197
            ->set_options_callback(static function(): array {
196
            ->set_options_callback(static function(): array {
198
                return role_get_names(null, ROLENAME_ORIGINAL, true);
197
                return role_get_names(null, ROLENAME_ORIGINAL, true);
199
            });
198
            });
Línea -... Línea 199...
-
 
199
 
-
 
200
        // Archetype filter.
-
 
201
        $filters[] = (new filter(
-
 
202
            select::class,
-
 
203
            'archetype',
-
 
204
            new lang_string('archetype', 'core_role'),
-
 
205
            $this->get_entity_name(),
-
 
206
            "{$rolealias}.archetype",
-
 
207
        ))
-
 
208
            ->add_joins($this->get_joins())
-
 
209
            ->set_options_callback(static function(): array {
-
 
210
                return array_map(
-
 
211
                    fn(string $archetype) => get_string("archetype{$archetype}", 'core_role'),
-
 
212
                    get_role_archetypes(),
-
 
213
                );
-
 
214
            });
200
 
215
 
201
        return $filters;
216
        return $filters;
202
    }
217
    }