Proyectos de Subversion Moodle

Rev

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

Rev 1 Rev 1441
Línea 72... Línea 72...
72
    protected function get_default_entity_title(): lang_string {
72
    protected function get_default_entity_title(): lang_string {
73
        return new lang_string('entitycourse', 'core_reportbuilder');
73
        return new lang_string('entitycourse', 'core_reportbuilder');
74
    }
74
    }
Línea 75... Línea 75...
75
 
75
 
76
    /**
-
 
77
     * Get custom fields helper
-
 
78
     *
76
    /**
79
     * @return custom_fields
-
 
80
     */
-
 
81
    protected function get_custom_fields(): custom_fields {
-
 
82
        $customfields = new custom_fields($this->get_table_alias('course') . '.id', $this->get_entity_name(),
-
 
83
            'core_course', 'course');
-
 
84
        $customfields->add_joins($this->get_joins());
-
 
85
        return $customfields;
-
 
86
    }
-
 
87
 
-
 
88
    /**
-
 
89
     * Initialise the entity, adding all course and custom course fields
77
     * Initialise the entity
90
     *
78
     *
91
     * @return base
79
     * @return base
92
     */
80
     */
-
 
81
    public function initialise(): base {
-
 
82
        $tablealias = $this->get_table_alias('course');
93
    public function initialise(): base {
83
 
-
 
84
        $customfields = (new custom_fields(
-
 
85
            "{$tablealias}.id",
-
 
86
            $this->get_entity_name(),
-
 
87
            'core_course',
-
 
88
            'course',
-
 
89
        ))
Línea 94... Línea 90...
94
        $customfields = $this->get_custom_fields();
90
            ->add_joins($this->get_joins());
95
 
91
 
96
        $columns = array_merge($this->get_all_columns(), $customfields->get_columns());
92
        $columns = array_merge($this->get_all_columns(), $customfields->get_columns());
97
        foreach ($columns as $column) {
93
        foreach ($columns as $column) {
Línea -... Línea 94...
-
 
94
            $this->add_column($column);
98
            $this->add_column($column);
95
        }
99
        }
96
 
100
 
97
        // All the filters defined by the entity can also be used as conditions.
101
        $filters = array_merge($this->get_all_filters(), $customfields->get_filters());
98
        $filters = array_merge($this->get_all_filters(), $customfields->get_filters());
102
        foreach ($filters as $filter) {
99
        foreach ($filters as $filter) {
Línea 148... Línea 145...
148
            'timemodified' => new lang_string('timemodified', 'core_reportbuilder'),
145
            'timemodified' => new lang_string('timemodified', 'core_reportbuilder'),
149
        ];
146
        ];
150
    }
147
    }
Línea 151... Línea 148...
151
 
148
 
152
    /**
-
 
153
     * Check if this field is sortable
-
 
154
     *
-
 
155
     * @param string $fieldname
-
 
156
     * @return bool
-
 
157
     */
-
 
158
    protected function is_sortable(string $fieldname): bool {
-
 
159
        // Some columns can't be sorted, like longtext or images.
-
 
160
        $nonsortable = [
-
 
161
            'summary',
-
 
162
        ];
-
 
163
 
-
 
164
        return !in_array($fieldname, $nonsortable);
-
 
165
    }
-
 
166
 
-
 
167
    /**
149
    /**
168
     * Return appropriate column type for given user field
150
     * Return appropriate column type for given user field
169
     *
151
     *
170
     * @param string $coursefield
152
     * @param string $coursefield
171
     * @return int
153
     * @return int
Línea 185... Línea 167...
185
                $fieldtype = column::TYPE_TIMESTAMP;
167
                $fieldtype = column::TYPE_TIMESTAMP;
186
                break;
168
                break;
187
            case 'summary':
169
            case 'summary':
188
                $fieldtype = column::TYPE_LONGTEXT;
170
                $fieldtype = column::TYPE_LONGTEXT;
189
                break;
171
                break;
190
            case 'groupmode':
-
 
191
                $fieldtype = column::TYPE_INTEGER;
-
 
192
                break;
-
 
193
            case 'calendartype':
-
 
194
            case 'idnumber':
-
 
195
            case 'format':
-
 
196
            case 'fullname':
-
 
197
            case 'lang':
-
 
198
            case 'shortname':
-
 
199
            case 'theme':
-
 
200
            default:
172
            default:
201
                $fieldtype = column::TYPE_TEXT;
173
                $fieldtype = column::TYPE_TEXT;
202
                break;
174
                break;
203
        }
175
        }
Línea 220... Línea 192...
220
     * These are all the columns available to use in any report that uses this entity.
192
     * These are all the columns available to use in any report that uses this entity.
221
     *
193
     *
222
     * @return column[]
194
     * @return column[]
223
     */
195
     */
224
    protected function get_all_columns(): array {
196
    protected function get_all_columns(): array {
225
        global $DB;
-
 
226
 
-
 
227
        $coursefields = $this->get_course_fields();
197
        $coursefields = $this->get_course_fields();
228
        $tablealias = $this->get_table_alias('course');
198
        $tablealias = $this->get_table_alias('course');
229
        $contexttablealias = $this->get_table_alias('context');
199
        $contexttablealias = $this->get_table_alias('context');
Línea 230... Línea 200...
230
 
200
 
Línea 263... Línea 233...
263
 
233
 
264
            $columns[] = $column;
234
            $columns[] = $column;
Línea 265... Línea 235...
265
        }
235
        }
266
 
-
 
267
        foreach ($coursefields as $coursefield => $coursefieldlang) {
-
 
268
            $columntype = $this->get_course_field_type($coursefield);
-
 
269
 
-
 
270
            $columnfieldsql = "{$tablealias}.{$coursefield}";
-
 
271
            if ($columntype === column::TYPE_LONGTEXT && $DB->get_dbfamily() === 'oracle') {
-
 
272
                $columnfieldsql = $DB->sql_order_by_text($columnfieldsql, 1024);
-
 
273
            }
236
 
274
 
237
        foreach ($coursefields as $coursefield => $coursefieldlang) {
275
            $column = (new column(
238
            $column = (new column(
276
                $coursefield,
239
                $coursefield,
277
                $coursefieldlang,
240
                $coursefieldlang,
278
                $this->get_entity_name()
241
                $this->get_entity_name()
279
            ))
242
            ))
280
                ->add_joins($this->get_joins())
243
                ->add_joins($this->get_joins())
281
                ->set_type($columntype)
244
                ->set_type($this->get_course_field_type($coursefield))
282
                ->add_field($columnfieldsql, $coursefield)
245
                ->add_field("{$tablealias}.{$coursefield}")
Línea 283... Línea 246...
283
                ->add_callback([$this, 'format'], $coursefield)
246
                ->add_callback([$this, 'format'], $coursefield)
284
                ->set_is_sortable($this->is_sortable($coursefield));
247
                ->set_is_sortable(true);
285
 
248
 
286
            // Join on the context table so that we can use it for formatting these columns later.
249
            // Join on the context table so that we can use it for formatting these columns later.
Línea 300... Línea 263...
300
     * Returns list of all available filters
263
     * Returns list of all available filters
301
     *
264
     *
302
     * @return array
265
     * @return array
303
     */
266
     */
304
    protected function get_all_filters(): array {
267
    protected function get_all_filters(): array {
305
        global $DB;
-
 
306
 
-
 
307
        $filters = [];
268
        $filters = [];
308
        $tablealias = $this->get_table_alias('course');
269
        $tablealias = $this->get_table_alias('course');
Línea 309... Línea 270...
309
 
270
 
310
        $fields = $this->get_course_fields();
271
        $fields = $this->get_course_fields();
311
        foreach ($fields as $field => $name) {
-
 
312
            $filterfieldsql = "{$tablealias}.{$field}";
-
 
313
            if ($this->get_course_field_type($field) === column::TYPE_LONGTEXT) {
-
 
314
                $filterfieldsql = $DB->sql_cast_to_char($filterfieldsql);
-
 
315
            }
-
 
316
 
272
        foreach ($fields as $field => $name) {
317
            $optionscallback = [static::class, 'get_options_for_' . $field];
273
            $optionscallback = [static::class, 'get_options_for_' . $field];
318
            if (is_callable($optionscallback)) {
274
            if (is_callable($optionscallback)) {
319
                $filterclass = select::class;
275
                $filterclass = select::class;
320
            } else if ($this->get_course_field_type($field) === column::TYPE_BOOLEAN) {
276
            } else if ($this->get_course_field_type($field) === column::TYPE_BOOLEAN) {
Línea 328... Línea 284...
328
            $filter = (new filter(
284
            $filter = (new filter(
329
                $filterclass,
285
                $filterclass,
330
                $field,
286
                $field,
331
                $name,
287
                $name,
332
                $this->get_entity_name(),
288
                $this->get_entity_name(),
333
                $filterfieldsql
289
                "{$tablealias}.{$field}"
334
            ))
290
            ))
335
                ->add_joins($this->get_joins());
291
                ->add_joins($this->get_joins());
Línea 336... Línea 292...
336
 
292
 
337
            // Populate filter options by callback, if available.
293
            // Populate filter options by callback, if available.
Línea 410... Línea 366...
410
     * List of options for the field theme.
366
     * List of options for the field theme.
411
     *
367
     *
412
     * @return array
368
     * @return array
413
     */
369
     */
414
    public static function get_options_for_theme(): array {
370
    public static function get_options_for_theme(): array {
415
        return array_map(
371
        return ['' => get_string('forceno')] + array_map(
416
            fn(theme_config $theme) => $theme->get_theme_name(),
372
            fn(theme_config $theme) => $theme->get_theme_name(),
417
            get_list_of_themes(),
373
            get_list_of_themes(),
418
        );
374
        );
419
    }
375
    }
Línea 422... Línea 378...
422
     * List of options for the field lang.
378
     * List of options for the field lang.
423
     *
379
     *
424
     * @return array
380
     * @return array
425
     */
381
     */
426
    public static function get_options_for_lang(): array {
382
    public static function get_options_for_lang(): array {
427
        return get_string_manager()->get_list_of_translations();
383
        return ['' => get_string('forceno')] + get_string_manager()->get_list_of_translations();
428
    }
384
    }
Línea 429... Línea 385...
429
 
385
 
430
    /**
386
    /**
431
     * List of options for the field.
387
     * List of options for the field.
432
     *
388
     *
433
     * @return array
389
     * @return array
434
     */
390
     */
435
    public static function get_options_for_calendartype(): array {
391
    public static function get_options_for_calendartype(): array {
436
        return \core_calendar\type_factory::get_list_of_calendar_types();
392
        return ['' => get_string('forceno')] + \core_calendar\type_factory::get_list_of_calendar_types();
Línea 437... Línea 393...
437
    }
393
    }
438
 
394
 
439
    /**
395
    /**
Línea 453... Línea 409...
453
            return format::boolean_as_text($value);
409
            return format::boolean_as_text($value);
454
        }
410
        }
Línea 455... Línea 411...
455
 
411
 
456
        // If the column has corresponding filter, determine the value from its options.
412
        // If the column has corresponding filter, determine the value from its options.
457
        $options = $this->get_options_for($fieldname);
413
        $options = $this->get_options_for($fieldname);
458
        if ($options !== null && array_key_exists($value, $options)) {
414
        if ($options !== null && $value !== null && array_key_exists($value, $options)) {
459
            return $options[$value];
415
            return $options[$value];
Línea 460... Línea 416...
460
        }
416
        }
461
 
417