Differences Between: [Versions 400 and 401] [Versions 400 and 402] [Versions 400 and 403]
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 declare(strict_types=1); 18 19 namespace core_reportbuilder\external; 20 21 use core\external\persistent_exporter; 22 use core_table\local\filter\integer_filter; 23 use core_table\local\filter\string_filter; 24 use core_reportbuilder\form\filter; 25 use core_reportbuilder\local\models\report; 26 use core_reportbuilder\local\report\base; 27 use core_reportbuilder\table\system_report_table; 28 use core_reportbuilder\table\system_report_table_filterset; 29 use renderer_base; 30 31 /** 32 * Report exporter class 33 * 34 * @package core_reportbuilder 35 * @copyright 2020 Paul Holden <paulh@moodle.com> 36 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 37 */ 38 class system_report_exporter extends persistent_exporter { 39 40 /** 41 * Return the name of the class we are exporting 42 * 43 * @return string 44 */ 45 protected static function define_class(): string { 46 return report::class; 47 } 48 49 /** 50 * Return a list of objects that are related to the persistent 51 * 52 * @return array 53 */ 54 protected static function define_related(): array { 55 return [ 56 'source' => base::class, 57 'parameters' => 'string', 58 ]; 59 } 60 61 /** 62 * Return a list of additional properties used only for display 63 * 64 * @return array 65 */ 66 protected static function define_other_properties(): array { 67 return [ 68 'table' => ['type' => PARAM_RAW], 69 'parameters' => ['type' => PARAM_RAW], 70 'filterspresent' => ['type' => PARAM_BOOL], 71 'filtersapplied' => ['type' => PARAM_INT], 72 'filtersform' => [ 73 'type' => PARAM_RAW, 74 'optional' => true, 75 ], 76 ]; 77 } 78 79 /** 80 * Get additional values to inject while exporting 81 * 82 * @uses \core_reportbuilder\output\renderer::render_system_report_table() 83 * 84 * @param renderer_base $output 85 * @return array 86 */ 87 protected function get_other_values(renderer_base $output): array { 88 /** @var base $source */ 89 $source = $this->related['source']; 90 91 /** @var string $parameters */ 92 $parameters = $this->related['parameters']; 93 94 /** @var int $reportid */ 95 $reportid = $this->persistent->get('id'); 96 97 // We store the report ID and parameters within the table filterset so that they are available between AJAX requests. 98 $filterset = new system_report_table_filterset(); 99 $filterset->add_filter(new integer_filter('reportid', null, [$reportid])); 100 $filterset->add_filter(new string_filter('parameters', null, [$parameters])); 101 102 $table = system_report_table::create($reportid, (array) json_decode($parameters, true)); 103 $table->set_filterset($filterset); 104 105 // Generate filters form if report contains any filters. 106 $filterspresent = !empty($source->get_active_filters()); 107 if ($filterspresent) { 108 $filtersform = new filter(null, null, 'post', '', [], true, [ 109 'reportid' => $reportid, 110 'parameters' => $parameters, 111 ]); 112 $filtersform->set_data_for_dynamic_submission(); 113 } 114 115 return [ 116 'table' => $output->render($table), 117 'parameters' => $parameters, 118 'filterspresent' => $filterspresent, 119 'filtersapplied' => $source->get_applied_filter_count(), 120 'filtersform' => $filterspresent ? $filtersform->render() : '', 121 ]; 122 } 123 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body