MDL-72287 behat: Update behat tests
[moodle.git] / reportbuilder / lib.php
blobe5a19533caddb3ac6e96a6fcd8b1a90ecdd4758f
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.
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/>.
17 /**
18 * Callback methods for reportbuilder component
20 * @package core_reportbuilder
21 * @copyright 2021 Paul Holden <paulh@moodle.com>
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25 declare(strict_types=1);
27 use core_reportbuilder\form\audience;
28 use core_reportbuilder\form\filter;
30 /**
31 * Return the filters form fragment
33 * @param array $params
34 * @return string
36 function core_reportbuilder_output_fragment_filters_form(array $params): string {
37 $filtersform = new filter(null, null, 'post', '', [], true, [
38 'reportid' => $params['reportid'],
39 'parameters' => $params['parameters'],
40 ]);
42 $filtersform->set_data_for_dynamic_submission();
44 return $filtersform->render();
47 /**
48 * Return the audience form fragment
50 * @param array $params
51 * @return string
53 function core_reportbuilder_output_fragment_audience_form(array $params): string {
54 global $PAGE;
56 $audienceform = new audience(null, null, 'post', '', [], true, [
57 'reportid' => $params['reportid'],
58 'classname' => $params['classname'],
59 ]);
60 $audienceform->set_data_for_dynamic_submission();
62 $context = [
63 'instanceid' => 0,
64 'title' => $params['title'],
65 'form' => $audienceform->render(),
66 'canedit' => true,
67 'candelete' => true,
68 'showormessage' => $params['showormessage'],
71 $renderer = $PAGE->get_renderer('core_reportbuilder');
72 return $renderer->render_from_template('core_reportbuilder/local/audience/form', $context);
75 /**
76 * Plugin inplace editable implementation
78 * @param string $itemtype
79 * @param int $itemid
80 * @param string $newvalue
81 * @return \core\output\inplace_editable|bool
83 function core_reportbuilder_inplace_editable($itemtype, $itemid, $newvalue) {
84 $itemid = (int) $itemid;
86 switch ($itemtype) {
87 case 'reportname':
88 return \core_reportbuilder\output\report_name_editable::update($itemid, $newvalue);
90 case 'columnheading':
91 return \core_reportbuilder\output\column_heading_editable::update($itemid, $newvalue);
93 case 'columnaggregation':
94 return \core_reportbuilder\output\column_aggregation_editable::update($itemid, $newvalue);
96 case 'filterheading':
97 return \core_reportbuilder\output\filter_heading_editable::update($itemid, $newvalue);
99 default:
100 return false;