2 // This file is part of Moodle - http://moodle.org/
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.
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/>.
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\output\inplace_editable
;
28 use core_reportbuilder\form\audience
;
29 use core_reportbuilder\form\filter
;
30 use core_reportbuilder\local\helpers\audience
as audience_helper
;
31 use core_reportbuilder\local\models\report
;
32 use core_tag\output\
{tagfeed
, tagindex
};
35 * Return the filters form fragment
37 * @param array $params
40 function core_reportbuilder_output_fragment_filters_form(array $params): string {
41 $filtersform = new filter(null, null, 'post', '', [], true, [
42 'reportid' => $params['reportid'],
43 'parameters' => $params['parameters'],
46 $filtersform->set_data_for_dynamic_submission();
48 return $filtersform->render();
52 * Return the audience form fragment
54 * @param array $params
57 function core_reportbuilder_output_fragment_audience_form(array $params): string {
60 $audienceform = new audience(null, null, 'post', '', [], true, [
61 'reportid' => $params['reportid'],
62 'classname' => $params['classname'],
64 $audienceform->set_data_for_dynamic_submission();
68 'heading' => $params['title'],
69 'headingeditable' => $params['title'],
70 'form' => $audienceform->render(),
73 'showormessage' => $params['showormessage'],
76 $renderer = $PAGE->get_renderer('core_reportbuilder');
77 return $renderer->render_from_template('core_reportbuilder/local/audience/form', $context);
81 * Callback to return tagged reports
83 * @param core_tag_tag $tag
84 * @param bool $exclusivemode
85 * @param int|null $fromcontextid
86 * @param int|null $contextid
87 * @param bool $recurse
91 function core_reportbuilder_get_tagged_reports(
93 bool $exclusivemode = false,
94 ?
int $fromcontextid = 0,
101 // Limit the returned list to those reports the current user can access.
102 [$where, $params] = audience_helper
::user_reports_list_access_sql('it');
104 $tagcount = $tag->count_tagged_items('core_reportbuilder', 'reportbuilder_report', $where, $params);
105 $perpage = $exclusivemode ?
20 : 5;
106 $pagecount = ceil($tagcount / $perpage);
111 $tagfeed = new tagfeed();
113 $pixicon = new pix_icon('i/report', new lang_string('customreport', 'core_reportbuilder'));
115 $reports = $tag->get_tagged_items('core_reportbuilder', 'reportbuilder_report', $page * $perpage, $perpage,
117 foreach ($reports as $report) {
119 $OUTPUT->render($pixicon),
121 new moodle_url('/reportbuilder/view.php', ['id' => $report->id
]),
122 (new report(0, $report))->get_formatted_name(),
127 $content = $OUTPUT->render_from_template('core_tag/tagfeed', $tagfeed->export_for_template($OUTPUT));
130 return new tagindex($tag, 'core_reportbuilder', 'reportbuilder_report', $content, $exclusivemode, $fromcontextid,
131 $contextid, $recurse, $page, $pagecount);
135 * Plugin inplace editable implementation
137 * @param string $itemtype
139 * @param string $newvalue
140 * @return inplace_editable|null
142 function core_reportbuilder_inplace_editable(string $itemtype, int $itemid, string $newvalue): ?inplace_editable
{
145 return \core_reportbuilder\output\report_name_editable
::update($itemid, $newvalue);
147 case 'columnheading':
148 return \core_reportbuilder\output\column_heading_editable
::update($itemid, $newvalue);
150 case 'columnaggregation':
151 return \core_reportbuilder\output\column_aggregation_editable
::update($itemid, $newvalue);
153 case 'filterheading':
154 return \core_reportbuilder\output\filter_heading_editable
::update($itemid, $newvalue);
156 case 'audienceheading':
157 return \core_reportbuilder\output\audience_heading_editable
::update($itemid, $newvalue);
160 return \core_reportbuilder\output\schedule_name_editable
::update($itemid, $newvalue);