Proyectos de Subversion Moodle

Rev

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

Rev 1 Rev 1441
Línea 25... Línea 25...
25
use stdClass;
25
use stdClass;
26
use core_reportbuilder\datasource;
26
use core_reportbuilder\datasource;
27
use core_reportbuilder\manager;
27
use core_reportbuilder\manager;
28
use core_reportbuilder\system_report;
28
use core_reportbuilder\system_report;
29
use core_reportbuilder\local\entities\user;
29
use core_reportbuilder\local\entities\user;
30
use core_reportbuilder\local\filters\date;
-
 
31
use core_reportbuilder\local\filters\tags;
-
 
32
use core_reportbuilder\local\filters\text;
-
 
33
use core_reportbuilder\local\filters\select;
30
use core_reportbuilder\local\filters\{boolean_select, date, tags, text, select};
34
use core_reportbuilder\local\helpers\audience;
31
use core_reportbuilder\local\helpers\{audience, custom_fields, format};
35
use core_reportbuilder\local\helpers\format;
-
 
36
use core_reportbuilder\local\report\action;
-
 
37
use core_reportbuilder\local\report\column;
-
 
38
use core_reportbuilder\local\report\filter;
32
use core_reportbuilder\local\report\{action, column, filter};
39
use core_reportbuilder\output\report_name_editable;
33
use core_reportbuilder\output\report_name_editable;
40
use core_reportbuilder\local\models\report;
34
use core_reportbuilder\local\models\report;
41
use core_reportbuilder\permission;
35
use core_reportbuilder\permission;
-
 
36
use core_tag\reportbuilder\local\entities\tag;
42
use core_tag_tag;
37
use core_tag_tag;
Línea 43... Línea 38...
43
 
38
 
44
/**
39
/**
45
 * Reports list
40
 * Reports list
Línea 74... Línea 69...
74
        $this->add_base_condition_sql($where, $params);
69
        $this->add_base_condition_sql($where, $params);
Línea 75... Línea 70...
75
 
70
 
76
        // Join user entity for "User modified" column.
71
        // Join user entity for "User modified" column.
77
        $entityuser = new user();
72
        $entityuser = new user();
78
        $entityuseralias = $entityuser->get_table_alias('user');
-
 
79
 
73
        $entityuseralias = $entityuser->get_table_alias('user');
80
        $this->add_entity($entityuser
74
        $this->add_entity($entityuser
81
            ->add_join("JOIN {user} {$entityuseralias} ON {$entityuseralias}.id = rb.usermodified")
75
            ->add_join("JOIN {user} {$entityuseralias} ON {$entityuseralias}.id = rb.usermodified")
Línea -... Línea 76...
-
 
76
        );
-
 
77
 
-
 
78
        // Join tag entity.
-
 
79
        $entitytag = new tag();
-
 
80
        $this->add_entity($entitytag
-
 
81
            ->add_joins($entitytag->get_tag_joins('core_reportbuilder', 'reportbuilder_report', 'rb.id'))
82
        );
82
        );
83
 
83
 
84
        // Define our internal entity for report elements.
84
        // Define our internal entity for report elements.
Línea 85... Línea 85...
85
        $this->annotate_entity($this->get_report_entity_name(),
85
        $this->annotate_entity($this->get_report_entity_name(),
Línea 113... Línea 113...
113
 
113
 
114
    /**
114
    /**
115
     * Add columns to report
115
     * Add columns to report
116
     */
116
     */
117
    protected function add_columns(): void {
-
 
118
        global $DB;
-
 
119
 
117
    protected function add_columns(): void {
Línea 120... Línea 118...
120
        $tablealias = $this->get_main_table_alias();
118
        $tablealias = $this->get_main_table_alias();
121
 
119
 
122
        // Report name column.
120
        // Report name column.
Línea 160... Línea 158...
160
 
158
 
161
                return call_user_func([$value, 'get_name']);
159
                return call_user_func([$value, 'get_name']);
162
            })
160
            })
Línea 163... Línea -...
163
        );
-
 
164
 
-
 
165
        // Tags column. TODO: Reuse tag entity column when MDL-76392 is integrated.
-
 
166
        $tagfieldconcatsql = $DB->sql_group_concat(
161
        );
167
            field: $DB->sql_concat_join("'|'", ['t.name', 't.rawname']),
-
 
168
            sort: 't.name',
162
 
169
        );
-
 
170
        $this->add_column((new column(
163
        // Tags column.
171
            'tags',
-
 
172
            new lang_string('tags'),
-
 
173
            $this->get_report_entity_name(),
164
        $this->add_column_from_entity('tag:namewithbadge')
174
        ))
-
 
175
            ->set_type(column::TYPE_TEXT)
-
 
176
            ->add_field("(
-
 
177
                SELECT {$tagfieldconcatsql}
-
 
178
                  FROM {tag_instance} ti
-
 
179
                  JOIN {tag} t ON t.id = ti.tagid
-
 
180
                 WHERE ti.component = 'core_reportbuilder' AND ti.itemtype = 'reportbuilder_report'
-
 
181
                   AND ti.itemid = {$tablealias}.id
-
 
182
            )", 'tags')
165
            ->set_title(new lang_string('tags'))
183
            ->set_is_sortable(true)
-
 
184
            ->set_is_available(core_tag_tag::is_enabled('core_reportbuilder', 'reportbuilder_report') === true)
-
 
185
            ->add_callback(static function(?string $tags): string {
-
 
186
                return implode(', ', array_map(static function(string $tag): string {
-
 
187
                    [$name, $rawname] = explode('|', $tag);
-
 
188
                    return core_tag_tag::make_display_name((object) [
-
 
189
                        'name' => $name,
-
 
190
                        'rawname' => $rawname,
-
 
191
                    ]);
-
 
192
                }, preg_split('/, /', (string) $tags, -1, PREG_SPLIT_NO_EMPTY)));
-
 
Línea 193... Línea 166...
193
            })
166
            ->set_aggregation('groupconcat')
194
        );
167
            ->set_is_available(core_tag_tag::is_enabled('core_reportbuilder', 'reportbuilder_report') === true);
195
 
168
 
196
        // Time created column.
169
        // Time created column.
Línea 251... Línea 224...
251
            ->set_options_callback(static function(): array {
224
            ->set_options_callback(static function(): array {
252
                return manager::get_report_datasources();
225
                return manager::get_report_datasources();
253
            })
226
            })
254
        );
227
        );
Línea -... Línea 228...
-
 
228
 
-
 
229
        // Schedules filter.
-
 
230
        $this->add_filter((new filter(
-
 
231
            boolean_select::class,
-
 
232
            'schedules',
-
 
233
            new lang_string('schedules', 'core_reportbuilder'),
-
 
234
            $this->get_report_entity_name(),
-
 
235
            "CASE WHEN EXISTS (SELECT 1 FROM {reportbuilder_schedule} WHERE reportid = {$tablealias}.id) THEN 1 ELSE 0 END"
-
 
236
        )));
255
 
237
 
256
        // Tags filter.
238
        // Tags filter.
257
        $this->add_filter((new filter(
239
        $this->add_filter((new filter(
258
            tags::class,
240
            tags::class,
259
            'tags',
241
            'tags',
Línea 277... Línea 259...
277
            "{$tablealias}.timecreated"
259
            "{$tablealias}.timecreated"
278
        ))
260
        ))
279
            ->set_limited_operators([
261
            ->set_limited_operators([
280
                date::DATE_ANY,
262
                date::DATE_ANY,
281
                date::DATE_RANGE,
263
                date::DATE_RANGE,
-
 
264
                date::DATE_BEFORE,
-
 
265
                date::DATE_LAST,
-
 
266
                date::DATE_CURRENT,
-
 
267
            ])
-
 
268
        );
-
 
269
 
-
 
270
        // Time modified filter.
-
 
271
        $this->add_filter((new filter(
-
 
272
            date::class,
-
 
273
            'timemodified',
-
 
274
            new lang_string('timemodified', 'core_reportbuilder'),
-
 
275
            $this->get_report_entity_name(),
-
 
276
            "{$tablealias}.timemodified",
-
 
277
        ))
-
 
278
            ->set_limited_operators([
-
 
279
                date::DATE_ANY,
-
 
280
                date::DATE_RANGE,
-
 
281
                date::DATE_BEFORE,
-
 
282
                date::DATE_LAST,
-
 
283
                date::DATE_CURRENT,
282
            ])
284
            ])
283
        );
285
        );
-
 
286
 
-
 
287
        // User modified filter.
-
 
288
        $this->add_filter_from_entity('user:userselect')
-
 
289
            ->set_header(new lang_string('usermodified', 'reportbuilder'))
-
 
290
            ->set_is_available(has_capability('moodle/user:viewalldetails', $this->get_context()));
-
 
291
 
-
 
292
        // Custom fields filters.
-
 
293
        $customfields = new custom_fields(
-
 
294
            'rb.id',
-
 
295
            $this->get_report_entity_name(),
-
 
296
            'core_reportbuilder',
-
 
297
            'report',
-
 
298
        );
-
 
299
        foreach ($customfields->get_filters() as $filter) {
-
 
300
            $this->add_filter($filter);
-
 
301
        }
284
    }
302
    }
Línea 285... Línea 303...
285
 
303
 
286
    /**
304
    /**
287
     * Add actions to report
305
     * Add actions to report
Línea 301... Línea 319...
301
        );
319
        );
Línea 302... Línea 320...
302
 
320
 
303
        // Edit details action.
321
        // Edit details action.
304
        $this->add_action((new action(
322
        $this->add_action((new action(
305
            new moodle_url('#'),
323
            new moodle_url('#'),
306
            new pix_icon('t/edit', ''),
324
            new pix_icon('i/settings', ''),
307
            ['data-action' => 'report-edit', 'data-report-id' => ':id'],
325
            ['data-action' => 'report-edit', 'data-report-id' => ':id'],
308
            false,
326
            false,
309
            new lang_string('editreportdetails', 'core_reportbuilder')
327
            new lang_string('editreportdetails', 'core_reportbuilder')
310
        ))
328
        ))
Línea 325... Línea 343...
325
                // We check this only to give the action to editors, because normal users can just click on the report name.
343
                // We check this only to give the action to editors, because normal users can just click on the report name.
326
                return $this->report_source_valid($row->source) && permission::can_edit_report(new report(0, $row));
344
                return $this->report_source_valid($row->source) && permission::can_edit_report(new report(0, $row));
327
            })
345
            })
328
        );
346
        );
Línea -... Línea 347...
-
 
347
 
-
 
348
        // Duplicate action.
-
 
349
        $this->add_action((new action(
-
 
350
            new moodle_url('#'),
-
 
351
            new pix_icon('t/copy', ''),
-
 
352
            ['data-action' => 'report-duplicate', 'data-report-id' => ':id', 'data-report-name' => ':name'],
-
 
353
            false,
-
 
354
            new lang_string('duplicatereport', 'core_reportbuilder')
-
 
355
        ))
-
 
356
            ->add_callback(function(stdClass $row): bool {
-
 
357
 
-
 
358
                // Ensure data name attribute is properly formatted.
-
 
359
                $report = new report(0, $row);
-
 
360
                $row->name = $report->get_formatted_name();
-
 
361
 
-
 
362
                return $this->report_source_valid($row->source) && permission::can_duplicate_report($report);
-
 
363
            })
-
 
364
        );
329
 
365
 
330
        // Delete action.
366
        // Delete action.
331
        $this->add_action((new action(
367
        $this->add_action((new action(
332
            new moodle_url('#'),
368
            new moodle_url('#'),
333
            new pix_icon('t/delete', ''),
369
            new pix_icon('t/delete', ''),