Proyectos de Subversion Moodle

Rev

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

Rev 1 Rev 1441
Línea 24... Línea 24...
24
use html_writer;
24
use html_writer;
25
use moodle_exception;
25
use moodle_exception;
26
use stdClass;
26
use stdClass;
27
use core_reportbuilder\{manager, system_report};
27
use core_reportbuilder\{manager, system_report};
28
use core_reportbuilder\local\models\report;
28
use core_reportbuilder\local\models\report;
-
 
29
use core_reportbuilder\local\report\column;
Línea 29... Línea 30...
29
 
30
 
30
/**
31
/**
31
 * System report dynamic table class
32
 * System report dynamic table class
32
 *
33
 *
Línea 79... Línea 80...
79
 
80
 
80
        // TODO: can probably be removed pending MDL-72974.
81
        // TODO: can probably be removed pending MDL-72974.
Línea 81... Línea 82...
81
        $PAGE->set_context($this->persistent->get_context());
82
        $PAGE->set_context($this->persistent->get_context());
-
 
83
 
82
 
84
        $fields = $this->report->get_base_fields();
83
        $fields = $this->report->get_base_fields();
85
        $groupby = [];
84
        $maintable = $this->report->get_main_table();
86
        $maintable = $this->report->get_main_table();
85
        $maintablealias = $this->report->get_main_table_alias();
87
        $maintablealias = $this->report->get_main_table_alias();
Línea 98... Línea 100...
98
        if ($this->is_downloading()) {
100
        if ($this->is_downloading()) {
99
            $columns = array_diff_key($columns,
101
            $columns = array_diff_key($columns,
100
                array_flip($this->report->get_exclude_columns_for_download()));
102
                array_flip($this->report->get_exclude_columns_for_download()));
101
        }
103
        }
Línea -... Línea 104...
-
 
104
 
-
 
105
        // If we are aggregating any columns, we should group by the remaining ones.
-
 
106
        $aggregatedcolumns = array_filter($columns, fn(column $column): bool => !empty($column->get_aggregation()));
-
 
107
        $hasaggregatedcolumns = !empty($aggregatedcolumns);
-
 
108
        if ($hasaggregatedcolumns) {
-
 
109
            $groupby = $fields;
-
 
110
        }
102
 
111
 
Línea 103... Línea 112...
103
        $columnheaders = $columnsattributes = [];
112
        $columnheaders = $columnattributes = $columnicons = [];
104
 
113
 
105
        // Check whether report has checkbox toggle defined, note that select all is excluded during download.
114
        // Check whether report has checkbox toggle defined, note that select all is excluded during download.
106
        if (($checkbox = $this->report->get_checkbox_toggleall(true)) && !$this->is_downloading()) {
115
        if (($checkbox = $this->report->get_checkbox_toggleall(true)) && !$this->is_downloading()) {
Línea 117... Línea 126...
117
            // Specify whether column should behave as a user fullname column unless the column has a custom title set.
126
            // Specify whether column should behave as a user fullname column unless the column has a custom title set.
118
            if (preg_match('/^user:fullname.*$/', $column->get_unique_identifier()) && !$column->has_custom_title()) {
127
            if (preg_match('/^user:fullname.*$/', $column->get_unique_identifier()) && !$column->has_custom_title()) {
119
                $this->userfullnamecolumns[] = $column->get_column_alias();
128
                $this->userfullnamecolumns[] = $column->get_column_alias();
120
            }
129
            }
Línea -... Línea 130...
-
 
130
 
-
 
131
            // We need to determine for each column whether we should group by its fields, to support aggregation.
-
 
132
            $columnaggregation = $column->get_aggregation();
-
 
133
            if ($hasaggregatedcolumns && (empty($columnaggregation) || $columnaggregation::column_groupby())) {
-
 
134
                $groupby = array_merge($groupby, $column->get_groupby_sql());
-
 
135
            }
121
 
136
 
122
            // Add each columns fields, joins and params to our report.
137
            // Add each columns fields, joins and params to our report.
123
            $fields = array_merge($fields, $column->get_fields());
138
            $fields = array_merge($fields, $column->get_fields());
124
            $joins = array_merge($joins, $column->get_joins());
139
            $joins = array_merge($joins, $column->get_joins());
Línea 125... Línea 140...
125
            $params = array_merge($params, $column->get_params());
140
            $params = array_merge($params, $column->get_params());
126
 
141
 
127
            // Disable sorting for some columns.
142
            // Disable sorting for some columns.
128
            if (!$column->get_is_sortable()) {
143
            if (!$column->get_is_sortable()) {
Línea 129... Línea 144...
129
                $this->no_sorting($column->get_column_alias());
144
                $this->no_sorting($column->get_column_alias());
130
            }
145
            }
-
 
146
 
131
 
147
            // Generate column attributes/icons for the table.
Línea 132... Línea 148...
132
            // Generate column attributes to be included in each cell.
148
            $columnattributes[$column->get_column_alias()] = $column->get_attributes();
133
            $columnsattributes[$column->get_column_alias()] = $column->get_attributes();
149
            $columnicons[] = $column->get_help_icon();
134
        }
150
        }
135
 
151
 
136
        // If the report has any actions then append appropriate column, note that actions are excluded during download.
152
        // If the report has any actions then append appropriate column, note that actions are excluded during download.
137
        if ($this->report->has_actions() && !$this->is_downloading()) {
153
        if ($this->report->has_actions() && !$this->is_downloading()) {
138
            $columnheaders['actions'] = html_writer::tag('span', get_string('actions', 'core_reportbuilder'), [
154
            $columnheaders['actions'] = html_writer::tag('span', get_string('actions', 'core_reportbuilder'), [
Línea 139... Línea 155...
139
                'class' => 'sr-only',
155
                'class' => 'visually-hidden',
140
            ]);
156
            ]);
Línea 141... Línea 157...
141
            $this->no_sorting('actions');
157
            $this->no_sorting('actions');
142
        }
158
        }
-
 
159
 
Línea 143... Línea 160...
143
 
160
        $this->define_columns(array_keys($columnheaders));
144
        $this->define_columns(array_keys($columnheaders));
161
        $this->define_headers(array_values($columnheaders));
145
        $this->define_headers(array_values($columnheaders));
162
 
146
 
163
        // Add column attributes/icons to the table.
Línea 158... Línea 175...
158
        $this->pageable(true);
175
        $this->pageable(true);
159
        $this->set_default_per_page($this->report->get_default_per_page());
176
        $this->set_default_per_page($this->report->get_default_per_page());
Línea 160... Línea 177...
160
 
177
 
161
        // Initialise table SQL properties.
178
        // Initialise table SQL properties.
162
        $fieldsql = implode(', ', $fields);
179
        $fieldsql = implode(', ', $fields);
163
        $this->init_sql($fieldsql, "{{$maintable}} {$maintablealias}", $joins, $where, $params);
180
        $this->init_sql($fieldsql, "{{$maintable}} {$maintablealias}", $joins, $where, $params, $groupby);
Línea 164... Línea 181...
164
    }
181
    }
165
 
182
 
166
    /**
183
    /**
Línea 240... Línea 257...
240
     */
257
     */
241
    private function format_row_actions(stdClass $row): string {
258
    private function format_row_actions(stdClass $row): string {
242
        global $OUTPUT;
259
        global $OUTPUT;
Línea 243... Línea 260...
243
 
260
 
-
 
261
        $menu = new action_menu();
244
        $menu = new action_menu();
262
        $menu->set_menu_trigger(
-
 
263
            $OUTPUT->pix_icon('i/menu', get_string('actions', 'core_reportbuilder')),
-
 
264
            'btn btn-icon d-flex no-caret',
Línea 245... Línea 265...
245
        $menu->set_menu_trigger($OUTPUT->pix_icon('a/setting', get_string('actions', 'core_reportbuilder')));
265
        );
246
 
266
 
247
        $actions = array_filter($this->report->get_actions(), function($action) use ($row) {
267
        $actions = array_filter($this->report->get_actions(), function($action) use ($row) {
248
            // Only return dividers and action items who can be displayed for current users.
268
            // Only return dividers and action items who can be displayed for current users.
Línea 297... Línea 317...
297
            );
317
            );
298
        }
318
        }
Línea 299... Línea 319...
299
 
319
 
300
        return '';
320
        return '';
-
 
321
    }
-
 
322
 
-
 
323
    /**
-
 
324
     * Check if the user has the capability to access this table.
-
 
325
     *
-
 
326
     * @return bool Return true if capability check passed.
-
 
327
     */
-
 
328
    public function has_capability(): bool {
-
 
329
        try {
-
 
330
            $this->report->require_can_view();
-
 
331
            return true;
-
 
332
        } catch (\core_reportbuilder\exception\report_access_exception $e) {
-
 
333
            return false;
-
 
334
        }
301
    }
335
    }