Merge branch 'MDL-70795' of git://github.com/paulholden/moodle
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Report builder related settings.
|
||||
*
|
||||
* @package core_reportbuilder
|
||||
* @copyright 2021 David Matamoros <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use core_admin\local\externalpage\accesscallback;
|
||||
use core_reportbuilder\permission;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die;
|
||||
|
||||
/** @var admin_root $ADMIN */
|
||||
$ADMIN->add('reports', new admin_category('reportbuilder', new lang_string('reportbuilder', 'core_reportbuilder')));
|
||||
|
||||
$ADMIN->add(
|
||||
'reportbuilder', new accesscallback(
|
||||
'customreports',
|
||||
get_string('customreports', 'core_reportbuilder'),
|
||||
(new moodle_url('/reportbuilder/index.php'))->out(),
|
||||
static function(accesscallback $accesscallback): bool {
|
||||
return permission::can_view_reports_list();
|
||||
}
|
||||
)
|
||||
);
|
||||
@@ -23,16 +23,60 @@
|
||||
*/
|
||||
|
||||
$string['actions'] = 'Actions';
|
||||
$string['addcolumn'] = 'Add column \'{$a}\'';
|
||||
$string['aggregatecolumn'] = 'Aggregate column \'{$a}\'';
|
||||
$string['aggregationavg'] = 'Average';
|
||||
$string['aggregationcount'] = 'Count';
|
||||
$string['aggregationcountdistinct'] = 'Count distinct';
|
||||
$string['aggregationgroupconcat'] = 'Comma separated values';
|
||||
$string['aggregationgroupconcatdistinct'] = 'Comma separated distinct values';
|
||||
$string['aggregationmax'] = 'Maximum';
|
||||
$string['aggregationmin'] = 'Minimum';
|
||||
$string['aggregationnone'] = 'No aggregation';
|
||||
$string['aggregationpercent'] = 'Percentage';
|
||||
$string['aggregationsum'] = 'Sum';
|
||||
$string['apply'] = 'Apply';
|
||||
$string['columnadded'] = 'Added column \'{$a}\'';
|
||||
$string['columnaggregated'] = 'Aggregated column \'{$a}\'';
|
||||
$string['columndeleted'] = 'Deleted column \'{$a}\'';
|
||||
$string['columnmoved'] = 'Moved column \'{$a}\'';
|
||||
$string['columnsortdirectionasc'] = 'Sort column \'{$a}\' ascending';
|
||||
$string['columnsortdirectiondesc'] = 'Sort column \'{$a}\' descending';
|
||||
$string['columnsortdisable'] = 'Disable sorting for column \'{$a}\'';
|
||||
$string['columnsortenable'] = 'Enable sorting for column \'{$a}\'';
|
||||
$string['columnsortupdated'] = 'Updated sorting for column \'{$a}\'';
|
||||
$string['conditionadded'] = 'Added condition \'{$a}\'';
|
||||
$string['conditiondeleted'] = 'Deleted condition \'{$a}\'';
|
||||
$string['conditionmoved'] = 'Moved condition \'{$a}\'';
|
||||
$string['conditions'] = 'Conditions';
|
||||
$string['conditions_help'] = 'Report conditions allow you to limit which data is displayed when the report is viewed. Users viewing the report cannot override these condition values.';
|
||||
$string['conditionsapplied'] = 'Conditions applied';
|
||||
$string['conditionsreset'] = 'Conditions reset';
|
||||
$string['coursefullnamewithlink'] = 'Course full name with link';
|
||||
$string['courseidnumberewithlink'] = 'Course ID number with link';
|
||||
$string['courseshortnamewithlink'] = 'Course short name with link';
|
||||
$string['customfieldcolumn'] = '{$a}';
|
||||
$string['customreports'] = 'Custom reports';
|
||||
$string['deletecolumn'] = 'Delete column \'{$a}\'';
|
||||
$string['deletecolumnconfirm'] = 'Are you sure you want to delete the column \'{$a}\'?';
|
||||
$string['deletecondition'] = 'Delete condition \'{$a}\'';
|
||||
$string['deleteconditionconfirm'] = 'Are you sure you want to delete the condition \'{$a}\'?';
|
||||
$string['deletefilter'] = 'Delete filter \'{$a}\'';
|
||||
$string['deletefilterconfirm'] = 'Are you sure you want to delete the filter \'{$a}\'?';
|
||||
$string['deletereport'] = 'Delete report';
|
||||
$string['deletereportconfirm'] = 'Are you sure you want to delete the report \'{$a}\' and all associated data?';
|
||||
$string['editdetails'] = 'Edit details';
|
||||
$string['editreportcontent'] = 'Edit report content';
|
||||
$string['editreportdetails'] = 'Edit report details';
|
||||
$string['editreportname'] = 'Edit report name';
|
||||
$string['entitycourse'] = 'Course';
|
||||
$string['entityuser'] = 'User';
|
||||
$string['errorreportaccess'] = 'You can not view this report';
|
||||
$string['errorreportcreate'] = 'You can not create a new report';
|
||||
$string['errorreportedit'] = 'You can not edit this report';
|
||||
$string['errorreportview'] = 'You can not view this report';
|
||||
$string['errorsourceinvalid'] = 'Could not find valid report source';
|
||||
$string['errorsourceunavailable'] = 'Report source is not available';
|
||||
$string['filteradded'] = 'Added filter \'{$a}\'';
|
||||
$string['filtercontains'] = 'Contains';
|
||||
$string['filterdatecurrent'] = 'Current';
|
||||
$string['filterdatedays'] = 'day(s)';
|
||||
@@ -46,6 +90,7 @@ $string['filterdateseconds'] = 'second(s)';
|
||||
$string['filterdateto'] = 'Date to';
|
||||
$string['filterdateweeks'] = 'week(s)';
|
||||
$string['filterdateyears'] = 'year(s)';
|
||||
$string['filterdeleted'] = 'Deleted filter \'{$a}\'';
|
||||
$string['filterdoesnotcontain'] = 'Does not contain';
|
||||
$string['filterdurationunit'] = '{$a} unit';
|
||||
$string['filterendswith'] = 'Ends with';
|
||||
@@ -61,19 +106,61 @@ $string['filterisequalto'] = 'Is equal to';
|
||||
$string['filterisnotempty'] = 'Is not empty';
|
||||
$string['filterisnotequalto'] = 'Is not equal to';
|
||||
$string['filterlessthan'] = 'Less than';
|
||||
$string['filtermoved'] = 'Moved filter \'{$a}\'';
|
||||
$string['filterrange'] = 'Range';
|
||||
$string['filtersapplied'] = 'Filters applied';
|
||||
$string['filtersappliedx'] = 'Filters ({$a})';
|
||||
$string['filters'] = 'Filters';
|
||||
$string['filters_help'] = 'Report filters allow users viewing the report to further limit the data being displayed, by selecting their own values for each filter. Filter values are stored on a per-user basis.';
|
||||
$string['filtersreset'] = 'Filters reset';
|
||||
$string['filterstartswith'] = 'Starts with';
|
||||
$string['includedefaultsetup'] = 'Include default setup';
|
||||
$string['includedefaultsetup_help'] = 'Populate report with default layout as defined by the selected source. These include pre-defined columns, filters and conditions.';
|
||||
$string['movecolumn'] = 'Move column \'{$a}\'';
|
||||
$string['movecondition'] = 'Move condition \'{$a}\'';
|
||||
$string['movefilter'] = 'Move filter \'{$a}\'';
|
||||
$string['movesorting'] = 'Move sorting for column \'{$a}\'';
|
||||
$string['newreport'] = 'New report';
|
||||
$string['noconditions'] = 'There are no conditions selected';
|
||||
$string['nofilters'] = 'There are no filters selected';
|
||||
$string['nosortablecolumns'] = 'There are no sortable columns';
|
||||
$string['privacy:metadata:column'] = 'Report column definitions';
|
||||
$string['privacy:metadata:column:uniqueidentifier'] = 'Unique identifier of the column';
|
||||
$string['privacy:metadata:column:usercreated'] = 'The ID of the user who created the column';
|
||||
$string['privacy:metadata:column:usermodified'] = 'The ID of the user who last modified the column';
|
||||
$string['privacy:metadata:filter'] = 'Report filter definitions';
|
||||
$string['privacy:metadata:filter:uniqueidentifier'] = 'Unique identifier of the filter';
|
||||
$string['privacy:metadata:filter:usercreated'] = 'The ID of the user who created the filter';
|
||||
$string['privacy:metadata:filter:usermodified'] = 'The ID of the user who last modified the filter';
|
||||
$string['privacy:metadata:preference:reportfilter'] = 'Stored report filter values';
|
||||
$string['privacy:metadata:report'] = 'Report definitions';
|
||||
$string['privacy:metadata:report:name'] = 'The name of the report';
|
||||
$string['privacy:metadata:report:usercreated'] = 'The ID of the user who created the report';
|
||||
$string['privacy:metadata:report:usermodified'] = 'The ID of the user who last modified the report';
|
||||
$string['renamecolumn'] = 'Rename column \'{$a}\'';
|
||||
$string['renamefilter'] = 'Rename filter \'{$a}\'';
|
||||
$string['reportbuilder'] = 'Report builder';
|
||||
$string['reportcreated'] = 'Report created';
|
||||
$string['reportdeleted'] = 'Report deleted';
|
||||
$string['reportsettingstoggle'] = 'Show/hide settings sidebar';
|
||||
$string['reportsource'] = 'Report source';
|
||||
$string['reportsource_help'] = 'The report source defines where the data for the report will come from';
|
||||
$string['reportupdated'] = 'Report updated';
|
||||
$string['resetall'] = 'Reset all';
|
||||
$string['selectacondition'] = 'Select a condition';
|
||||
$string['selectafilter'] = 'Select a filter';
|
||||
$string['selectareportsource'] = 'Select a report source';
|
||||
$string['selectcourses'] = 'Select courses';
|
||||
$string['showhide'] = 'Show/hide \'{$a}\'';
|
||||
$string['sorting'] = 'Sorting';
|
||||
$string['sorting_help'] = 'Define the default sort order of the columns added to the report. Users can choose their own table sorting preferences, but will fallback to the defaults provided here.';
|
||||
$string['switchedit'] = 'Switch to edit mode';
|
||||
$string['switchpreview'] = 'Switch to preview mode';
|
||||
$string['timeadded'] = 'Time added';
|
||||
$string['timecreated'] = 'Time created';
|
||||
$string['timemodified'] = 'Time modified';
|
||||
$string['userfullnamewithlink'] = 'Full name with link';
|
||||
$string['userfullnamewithpicture'] = 'Full name with picture';
|
||||
$string['userfullnamewithpicturelink'] = 'Full name with picture and link';
|
||||
$string['usermodified'] = 'Modified by';
|
||||
$string['userpicture'] = 'User picture';
|
||||
|
||||
@@ -371,6 +371,9 @@ $string['rating:rate'] = 'Add ratings to items';
|
||||
$string['rating:view'] = 'View the total rating you received';
|
||||
$string['rating:viewany'] = 'View total ratings that anyone received';
|
||||
$string['rating:viewall'] = 'View all raw ratings given by individuals';
|
||||
$string['reportbuilder:edit'] = 'Create/edit custom reports';
|
||||
$string['reportbuilder:editall'] = 'Create/edit all custom reports';
|
||||
$string['reportbuilder:view'] = 'View custom reports';
|
||||
$string['resetrole'] = 'Reset';
|
||||
$string['resettingrole'] = 'Resetting role \'{$a}\'';
|
||||
$string['restore:configure'] = 'Configure restore options';
|
||||
|
||||
@@ -2627,4 +2627,31 @@ $capabilities = array(
|
||||
'coursecreator' => CAP_ALLOW,
|
||||
]
|
||||
],
|
||||
|
||||
// Allow users to view custom reports.
|
||||
'moodle/reportbuilder:view' => [
|
||||
'captype' => 'read',
|
||||
'contextlevel' => CONTEXT_SYSTEM,
|
||||
'archetypes' => [
|
||||
'user' => CAP_ALLOW,
|
||||
],
|
||||
],
|
||||
|
||||
// Allow users to create/edit their own custom reports.
|
||||
'moodle/reportbuilder:edit' => [
|
||||
'captype' => 'write',
|
||||
'riskbitmap' => RISK_PERSONAL,
|
||||
'contextlevel' => CONTEXT_SYSTEM,
|
||||
'archetypes' => [
|
||||
'manager' => CAP_ALLOW,
|
||||
],
|
||||
],
|
||||
|
||||
// Allow users to create/edit all custom reports.
|
||||
'moodle/reportbuilder:editall' => [
|
||||
'captype' => 'write',
|
||||
'riskbitmap' => RISK_PERSONAL,
|
||||
'contextlevel' => CONTEXT_SYSTEM,
|
||||
'archetypes' => [],
|
||||
],
|
||||
);
|
||||
|
||||
+46
-1
@@ -1,5 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<XMLDB PATH="lib/db" VERSION="20211005" COMMENT="XMLDB file for core Moodle tables"
|
||||
<XMLDB PATH="lib/db" VERSION="20211008" COMMENT="XMLDB file for core Moodle tables"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:noNamespaceSchemaLocation="../../lib/xmldb/xmldb.xsd"
|
||||
>
|
||||
@@ -4382,8 +4382,10 @@
|
||||
<TABLE NAME="reportbuilder_report" COMMENT="Table to represent a report">
|
||||
<FIELDS>
|
||||
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true"/>
|
||||
<FIELD NAME="name" TYPE="char" LENGTH="255" NOTNULL="false" SEQUENCE="false"/>
|
||||
<FIELD NAME="source" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false"/>
|
||||
<FIELD NAME="type" TYPE="int" LENGTH="2" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
|
||||
<FIELD NAME="conditiondata" TYPE="text" NOTNULL="false" SEQUENCE="false"/>
|
||||
<FIELD NAME="contextid" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false"/>
|
||||
<FIELD NAME="component" TYPE="char" LENGTH="100" NOTNULL="true" SEQUENCE="false"/>
|
||||
<FIELD NAME="area" TYPE="char" LENGTH="100" NOTNULL="true" SEQUENCE="false"/>
|
||||
@@ -4400,5 +4402,48 @@
|
||||
<KEY NAME="contextid" TYPE="foreign" FIELDS="contextid" REFTABLE="context" REFFIELDS="id"/>
|
||||
</KEYS>
|
||||
</TABLE>
|
||||
<TABLE NAME="reportbuilder_column" COMMENT="Table to represent a report column">
|
||||
<FIELDS>
|
||||
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true"/>
|
||||
<FIELD NAME="reportid" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
|
||||
<FIELD NAME="uniqueidentifier" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false"/>
|
||||
<FIELD NAME="aggregation" TYPE="char" LENGTH="32" NOTNULL="false" SEQUENCE="false"/>
|
||||
<FIELD NAME="heading" TYPE="char" LENGTH="255" NOTNULL="false" SEQUENCE="false"/>
|
||||
<FIELD NAME="columnorder" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false"/>
|
||||
<FIELD NAME="sortenabled" TYPE="int" LENGTH="1" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
|
||||
<FIELD NAME="sortdirection" TYPE="int" LENGTH="1" NOTNULL="true" SEQUENCE="false"/>
|
||||
<FIELD NAME="sortorder" TYPE="int" LENGTH="10" NOTNULL="false" SEQUENCE="false"/>
|
||||
<FIELD NAME="usercreated" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
|
||||
<FIELD NAME="usermodified" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
|
||||
<FIELD NAME="timecreated" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
|
||||
<FIELD NAME="timemodified" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
|
||||
</FIELDS>
|
||||
<KEYS>
|
||||
<KEY NAME="primary" TYPE="primary" FIELDS="id"/>
|
||||
<KEY NAME="reportid" TYPE="foreign" FIELDS="reportid" REFTABLE="reportbuilder_report" REFFIELDS="id"/>
|
||||
<KEY NAME="usercreated" TYPE="foreign" FIELDS="usercreated" REFTABLE="user" REFFIELDS="id"/>
|
||||
<KEY NAME="usermodified" TYPE="foreign" FIELDS="usermodified" REFTABLE="user" REFFIELDS="id"/>
|
||||
</KEYS>
|
||||
</TABLE>
|
||||
<TABLE NAME="reportbuilder_filter" COMMENT="Table to represent a report filter/condition">
|
||||
<FIELDS>
|
||||
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true"/>
|
||||
<FIELD NAME="reportid" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
|
||||
<FIELD NAME="uniqueidentifier" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false"/>
|
||||
<FIELD NAME="heading" TYPE="char" LENGTH="255" NOTNULL="false" SEQUENCE="false"/>
|
||||
<FIELD NAME="iscondition" TYPE="int" LENGTH="1" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
|
||||
<FIELD NAME="filterorder" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false"/>
|
||||
<FIELD NAME="usercreated" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
|
||||
<FIELD NAME="usermodified" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
|
||||
<FIELD NAME="timecreated" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
|
||||
<FIELD NAME="timemodified" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
|
||||
</FIELDS>
|
||||
<KEYS>
|
||||
<KEY NAME="primary" TYPE="primary" FIELDS="id"/>
|
||||
<KEY NAME="reportid" TYPE="foreign" FIELDS="reportid" REFTABLE="reportbuilder_report" REFFIELDS="id"/>
|
||||
<KEY NAME="usercreated" TYPE="foreign" FIELDS="usercreated" REFTABLE="user" REFFIELDS="id"/>
|
||||
<KEY NAME="usermodified" TYPE="foreign" FIELDS="usermodified" REFTABLE="user" REFFIELDS="id"/>
|
||||
</KEYS>
|
||||
</TABLE>
|
||||
</TABLES>
|
||||
</XMLDB>
|
||||
|
||||
@@ -2798,6 +2798,90 @@ $functions = array(
|
||||
'type' => 'write',
|
||||
'ajax' => true,
|
||||
],
|
||||
'core_reportbuilder_reports_delete' => [
|
||||
'classname' => 'core_reportbuilder\external\reports\delete',
|
||||
'description' => 'Delete report',
|
||||
'type' => 'write',
|
||||
'ajax' => true,
|
||||
],
|
||||
'core_reportbuilder_reports_get' => [
|
||||
'classname' => 'core_reportbuilder\external\reports\get',
|
||||
'description' => 'Get custom report',
|
||||
'type' => 'read',
|
||||
'ajax' => true,
|
||||
],
|
||||
'core_reportbuilder_columns_add' => [
|
||||
'classname' => 'core_reportbuilder\external\columns\add',
|
||||
'description' => 'Add column to report',
|
||||
'type' => 'write',
|
||||
'ajax' => true,
|
||||
],
|
||||
'core_reportbuilder_columns_delete' => [
|
||||
'classname' => 'core_reportbuilder\external\columns\delete',
|
||||
'description' => 'Delete column from report',
|
||||
'type' => 'write',
|
||||
'ajax' => true,
|
||||
],
|
||||
'core_reportbuilder_columns_reorder' => [
|
||||
'classname' => 'core_reportbuilder\external\columns\reorder',
|
||||
'description' => 'Re-order column within report',
|
||||
'type' => 'write',
|
||||
'ajax' => true,
|
||||
],
|
||||
'core_reportbuilder_columns_sort_reorder' => [
|
||||
'classname' => 'core_reportbuilder\external\columns\sort\reorder',
|
||||
'description' => 'Re-order column sorting within report',
|
||||
'type' => 'write',
|
||||
'ajax' => true,
|
||||
],
|
||||
'core_reportbuilder_columns_sort_toggle' => [
|
||||
'classname' => 'core_reportbuilder\external\columns\sort\toggle',
|
||||
'description' => 'Toggle sorting of column within report',
|
||||
'type' => 'write',
|
||||
'ajax' => true,
|
||||
],
|
||||
'core_reportbuilder_conditions_add' => [
|
||||
'classname' => 'core_reportbuilder\external\conditions\add',
|
||||
'description' => 'Add condition to report',
|
||||
'type' => 'write',
|
||||
'ajax' => true,
|
||||
],
|
||||
'core_reportbuilder_conditions_delete' => [
|
||||
'classname' => 'core_reportbuilder\external\conditions\delete',
|
||||
'description' => 'Delete condition from report',
|
||||
'type' => 'write',
|
||||
'ajax' => true,
|
||||
],
|
||||
'core_reportbuilder_conditions_reorder' => [
|
||||
'classname' => 'core_reportbuilder\external\conditions\reorder',
|
||||
'description' => 'Re-order condition within report',
|
||||
'type' => 'write',
|
||||
'ajax' => true,
|
||||
],
|
||||
'core_reportbuilder_conditions_reset' => [
|
||||
'classname' => 'core_reportbuilder\external\conditions\reset',
|
||||
'description' => 'Reset conditions for given report',
|
||||
'type' => 'write',
|
||||
'ajax' => true,
|
||||
],
|
||||
'core_reportbuilder_filters_add' => [
|
||||
'classname' => 'core_reportbuilder\external\filters\add',
|
||||
'description' => 'Add filter to report',
|
||||
'type' => 'write',
|
||||
'ajax' => true,
|
||||
],
|
||||
'core_reportbuilder_filters_delete' => [
|
||||
'classname' => 'core_reportbuilder\external\filters\delete',
|
||||
'description' => 'Delete filter from report',
|
||||
'type' => 'write',
|
||||
'ajax' => true,
|
||||
],
|
||||
'core_reportbuilder_filters_reorder' => [
|
||||
'classname' => 'core_reportbuilder\external\filters\reorder',
|
||||
'description' => 'Re-order filter within report',
|
||||
'type' => 'write',
|
||||
'ajax' => true,
|
||||
],
|
||||
);
|
||||
|
||||
$services = array(
|
||||
|
||||
@@ -2936,5 +2936,79 @@ function xmldb_main_upgrade($oldversion) {
|
||||
upgrade_main_savepoint(true, 2021100600.04);
|
||||
}
|
||||
|
||||
if ($oldversion < 2021101900.01) {
|
||||
$table = new xmldb_table('reportbuilder_report');
|
||||
|
||||
// Define field name to be added to reportbuilder_report.
|
||||
$field = new xmldb_field('name', XMLDB_TYPE_CHAR, '255', null, null, null, null, 'id');
|
||||
if (!$dbman->field_exists($table, $field)) {
|
||||
$dbman->add_field($table, $field);
|
||||
}
|
||||
|
||||
// Define field conditiondata to be added to reportbuilder_report.
|
||||
$field = new xmldb_field('conditiondata', XMLDB_TYPE_TEXT, null, null, null, null, null, 'type');
|
||||
if (!$dbman->field_exists($table, $field)) {
|
||||
$dbman->add_field($table, $field);
|
||||
}
|
||||
|
||||
// Define table reportbuilder_column to be created.
|
||||
$table = new xmldb_table('reportbuilder_column');
|
||||
|
||||
// Adding fields to table reportbuilder_column.
|
||||
$table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
|
||||
$table->add_field('reportid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0');
|
||||
$table->add_field('uniqueidentifier', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null);
|
||||
$table->add_field('aggregation', XMLDB_TYPE_CHAR, '32', null, null, null, null);
|
||||
$table->add_field('heading', XMLDB_TYPE_CHAR, '255', null, null, null, null);
|
||||
$table->add_field('columnorder', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
|
||||
$table->add_field('sortenabled', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, '0');
|
||||
$table->add_field('sortdirection', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, null);
|
||||
$table->add_field('sortorder', XMLDB_TYPE_INTEGER, '10', null, null, null, null);
|
||||
$table->add_field('usercreated', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0');
|
||||
$table->add_field('usermodified', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0');
|
||||
$table->add_field('timecreated', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0');
|
||||
$table->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0');
|
||||
|
||||
// Adding keys to table reportbuilder_column.
|
||||
$table->add_key('primary', XMLDB_KEY_PRIMARY, ['id']);
|
||||
$table->add_key('reportid', XMLDB_KEY_FOREIGN, ['reportid'], 'reportbuilder_report', ['id']);
|
||||
$table->add_key('usercreated', XMLDB_KEY_FOREIGN, ['usercreated'], 'user', ['id']);
|
||||
$table->add_key('usermodified', XMLDB_KEY_FOREIGN, ['usermodified'], 'user', ['id']);
|
||||
|
||||
// Conditionally launch create table for reportbuilder_column.
|
||||
if (!$dbman->table_exists($table)) {
|
||||
$dbman->create_table($table);
|
||||
}
|
||||
|
||||
// Define table reportbuilder_filter to be created.
|
||||
$table = new xmldb_table('reportbuilder_filter');
|
||||
|
||||
// Adding fields to table reportbuilder_filter.
|
||||
$table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
|
||||
$table->add_field('reportid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0');
|
||||
$table->add_field('uniqueidentifier', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null);
|
||||
$table->add_field('heading', XMLDB_TYPE_CHAR, '255', null, null, null, null);
|
||||
$table->add_field('iscondition', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, '0');
|
||||
$table->add_field('filterorder', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
|
||||
$table->add_field('usercreated', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0');
|
||||
$table->add_field('usermodified', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0');
|
||||
$table->add_field('timecreated', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0');
|
||||
$table->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0');
|
||||
|
||||
// Adding keys to table reportbuilder_filter.
|
||||
$table->add_key('primary', XMLDB_KEY_PRIMARY, ['id']);
|
||||
$table->add_key('reportid', XMLDB_KEY_FOREIGN, ['reportid'], 'reportbuilder_report', ['id']);
|
||||
$table->add_key('usercreated', XMLDB_KEY_FOREIGN, ['usercreated'], 'user', ['id']);
|
||||
$table->add_key('usermodified', XMLDB_KEY_FOREIGN, ['usermodified'], 'user', ['id']);
|
||||
|
||||
// Conditionally launch create table for reportbuilder_filter.
|
||||
if (!$dbman->table_exists($table)) {
|
||||
$dbman->create_table($table);
|
||||
}
|
||||
|
||||
// Main savepoint reached.
|
||||
upgrade_main_savepoint(true, 2021101900.01);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
function _typeof(a){"@babel/helpers - typeof";if("function"==typeof Symbol&&"symbol"==typeof Symbol.iterator){_typeof=function(a){return typeof a}}else{_typeof=function(a){return a&&"function"==typeof Symbol&&a.constructor===Symbol&&a!==Symbol.prototype?"symbol":typeof a}}return _typeof(a)}define ("core_reportbuilder/editor",["exports","core/inplace_editable","core/notification","core/pending","core/templates","core_reportbuilder/local/selectors","core_reportbuilder/local/editor/columns","core_reportbuilder/local/editor/conditions","core_reportbuilder/local/editor/filters","core_reportbuilder/local/editor/sorting","core_reportbuilder/local/repository/reports"],function(a,b,c,d,e,f,g,h,i,j,k){"use strict";Object.defineProperty(a,"__esModule",{value:!0});a.init=void 0;c=n(c);d=n(d);e=n(e);f=m(f);function l(){if("function"!=typeof WeakMap)return null;var a=new WeakMap;l=function(){return a};return a}function m(a){if(a&&a.__esModule){return a}if(null===a||"object"!==_typeof(a)&&"function"!=typeof a){return{default:a}}var b=l();if(b&&b.has(a)){return b.get(a)}var c={},d=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var e in a){if(Object.prototype.hasOwnProperty.call(a,e)){var f=d?Object.getOwnPropertyDescriptor(a,e):null;if(f&&(f.get||f.set)){Object.defineProperty(c,e,f)}else{c[e]=a[e]}}}c.default=a;if(b){b.set(a,c)}return c}function n(a){return a&&a.__esModule?a:{default:a}}var o=!1,p=function(){var a=document.querySelector(f.regions.report);(0,g.init)(a,o);(0,h.init)(a,o);(0,i.init)(a,o);(0,j.init)(a,o);if(o){return}document.addEventListener("click",function(b){var g=b.target.closest(f.actions.toggleEditPreview);if(g){b.preventDefault();var h=new d.default("core_reportbuilder/reports:get"),i="1"!==g.dataset.editMode,j="";(0,k.getReport)(a.dataset.reportId,i).then(function(a){j=a.javascript;return e.default.render("core_reportbuilder/custom_report",a)}).then(function(b,c){return e.default.replaceNodeContents(a,b,c+j)}).then(function(){return h.resolve()}).catch(c.default.exception)}});o=!0};a.init=p});
|
||||
//# sourceMappingURL=editor.min.js.map
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"sources":["../src/editor.js"],"names":["initialized","init","reportElement","document","querySelector","reportSelectors","regions","report","addEventListener","event","toggleEditViewMode","target","closest","actions","toggleEditPreview","preventDefault","pendingPromise","Pending","toggledEditMode","dataset","editMode","customjs","reportId","then","response","javascript","Templates","render","html","js","replaceNodeContents","resolve","catch","Notification","exception"],"mappings":"6rBAwBA,a,+DAGA,OACA,OACA,OACA,O,4lBAOIA,CAAAA,CAAW,G,CAKFC,CAAI,CAAG,UAAM,CACtB,GAAMC,CAAAA,CAAa,CAAGC,QAAQ,CAACC,aAAT,CAAuBC,CAAe,CAACC,OAAhB,CAAwBC,MAA/C,CAAtB,CAEA,WAAkBL,CAAlB,CAAiCF,CAAjC,EACA,WAAqBE,CAArB,CAAoCF,CAApC,EACA,WAAkBE,CAAlB,CAAiCF,CAAjC,EACA,WAAkBE,CAAlB,CAAiCF,CAAjC,EAGA,GAAIA,CAAJ,CAAiB,CACb,MACH,CAGDG,QAAQ,CAACK,gBAAT,CAA0B,OAA1B,CAAmC,SAAAC,CAAK,CAAI,CAGxC,GAAMC,CAAAA,CAAkB,CAAGD,CAAK,CAACE,MAAN,CAAaC,OAAb,CAAqBP,CAAe,CAACQ,OAAhB,CAAwBC,iBAA7C,CAA3B,CACA,GAAIJ,CAAJ,CAAwB,CACpBD,CAAK,CAACM,cAAN,GADoB,GAGdC,CAAAA,CAAc,CAAG,GAAIC,UAAJ,CAAY,gCAAZ,CAHH,CAIdC,CAAe,CAA2C,GAAxC,GAAAR,CAAkB,CAACS,OAAnB,CAA2BC,QAJ/B,CAMhBC,CAAQ,CAAG,EANK,CAQpB,gBAAUnB,CAAa,CAACiB,OAAd,CAAsBG,QAAhC,CAA0CJ,CAA1C,EACKK,IADL,CACU,SAAAC,CAAQ,CAAI,CACdH,CAAQ,CAAGG,CAAQ,CAACC,UAApB,CACA,MAAOC,WAAUC,MAAV,CAAiB,kCAAjB,CAAqDH,CAArD,CACV,CAJL,EAKKD,IALL,CAKU,SAACK,CAAD,CAAOC,CAAP,CAAc,CAChB,MAAOH,WAAUI,mBAAV,CAA8B5B,CAA9B,CAA6C0B,CAA7C,CAAmDC,CAAE,CAAGR,CAAxD,CACV,CAPL,EAQKE,IARL,CAQU,iBAAMP,CAAAA,CAAc,CAACe,OAAf,EAAN,CARV,EASKC,KATL,CASWC,UAAaC,SATxB,CAUH,CACJ,CAvBD,EAyBAlC,CAAW,GACd,C","sourcesContent":["// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see <http://www.gnu.org/licenses/>.\n\n/**\n * Report builder editor\n *\n * @module core_reportbuilder/editor\n * @package core_reportbuilder\n * @copyright 2021 David Matamoros <[email protected]>\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\n\"use strict\";\n\nimport 'core/inplace_editable';\nimport Notification from 'core/notification';\nimport Pending from 'core/pending';\nimport Templates from 'core/templates';\nimport * as reportSelectors from 'core_reportbuilder/local/selectors';\nimport {init as columnsEditorInit} from 'core_reportbuilder/local/editor/columns';\nimport {init as conditionsEditorInit} from 'core_reportbuilder/local/editor/conditions';\nimport {init as filtersEditorInit} from 'core_reportbuilder/local/editor/filters';\nimport {init as sortingEditorInit} from 'core_reportbuilder/local/editor/sorting';\nimport {getReport} from 'core_reportbuilder/local/repository/reports';\n\nlet initialized = false;\n\n/**\n * Initialise editor and all it's modules\n */\nexport const init = () => {\n const reportElement = document.querySelector(reportSelectors.regions.report);\n\n columnsEditorInit(reportElement, initialized);\n conditionsEditorInit(reportElement, initialized);\n filtersEditorInit(reportElement, initialized);\n sortingEditorInit(reportElement, initialized);\n\n // Ensure we only add our listeners once (can be called multiple times by mustache template).\n if (initialized) {\n return;\n }\n\n // Add event handlers to generic report editor elements.\n document.addEventListener('click', event => {\n\n // Toggle between edit and preview mode.\n const toggleEditViewMode = event.target.closest(reportSelectors.actions.toggleEditPreview);\n if (toggleEditViewMode) {\n event.preventDefault();\n\n const pendingPromise = new Pending('core_reportbuilder/reports:get');\n const toggledEditMode = toggleEditViewMode.dataset.editMode !== \"1\";\n\n let customjs = '';\n\n getReport(reportElement.dataset.reportId, toggledEditMode)\n .then(response => {\n customjs = response.javascript;\n return Templates.render('core_reportbuilder/custom_report', response);\n })\n .then((html, js) => {\n return Templates.replaceNodeContents(reportElement, html, js + customjs);\n })\n .then(() => pendingPromise.resolve())\n .catch(Notification.exception);\n }\n });\n\n initialized = true;\n};\n"],"file":"editor.min.js"}
|
||||
+1
-1
@@ -1,2 +1,2 @@
|
||||
function _typeof(a){"@babel/helpers - typeof";if("function"==typeof Symbol&&"symbol"==typeof Symbol.iterator){_typeof=function(a){return typeof a}}else{_typeof=function(a){return a&&"function"==typeof Symbol&&a.constructor===Symbol&&a!==Symbol.prototype?"symbol":typeof a}}return _typeof(a)}define ("core_reportbuilder/filters",["exports","core/event_dispatcher","core/fragment","core/notification","core/pending","core/str","core/templates","core/toast","core_form/dynamicform","core_reportbuilder/local/events","core_reportbuilder/local/selectors","core_reportbuilder/local/repository/filters"],function(a,b,c,d,e,f,g,h,i,j,k,l){"use strict";Object.defineProperty(a,"__esModule",{value:!0});a.init=void 0;d=o(d);e=o(e);g=o(g);i=o(i);j=n(j);k=n(k);function m(){if("function"!=typeof WeakMap)return null;var a=new WeakMap;m=function(){return a};return a}function n(a){if(a&&a.__esModule){return a}if(null===a||"object"!==_typeof(a)&&"function"!=typeof a){return{default:a}}var b=m();if(b&&b.has(a)){return b.get(a)}var c={},d=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var e in a){if(Object.prototype.hasOwnProperty.call(a,e)){var f=d?Object.getOwnPropertyDescriptor(a,e):null;if(f&&(f.get||f.set)){Object.defineProperty(c,e,f)}else{c[e]=a[e]}}}c.default=a;if(b){b.set(a,c)}return c}function o(a){return a&&a.__esModule?a:{default:a}}function p(a,b,c,d,e,f,g){try{var h=a[f](g),i=h.value}catch(a){c(a);return}if(h.done){b(i)}else{Promise.resolve(i).then(d,e)}}function q(a){return function(){var b=this,c=arguments;return new Promise(function(d,e){var h=a.apply(b,c);function f(a){p(h,d,e,f,g,"next",a)}function g(a){p(h,d,e,f,g,"throw",a)}f(void 0)})}}var r=function(){var a=q(regeneratorRuntime.mark(function a(b,c){var d;return regeneratorRuntime.wrap(function(a){while(1){switch(a.prev=a.next){case 0:d=b.querySelector(k.regions.filterButtonLabel);if(!(0<c)){a.next=7;break}a.next=4;return(0,f.get_string)("filtersappliedx","core_reportbuilder",c);case 4:d.textContent=a.sent;a.next=10;break;case 7:a.next=9;return(0,f.get_string)("filters","moodle");case 9:d.textContent=a.sent;case 10:case"end":return a.stop();}}},a)}));return function(){return a.apply(this,arguments)}}(),s=function(a,m){var n=document.querySelector(k.forSystemReport(a)),o=n.querySelector(k.regions.filtersForm),p=new i.default(o,"\\core_reportbuilder\\form\\filter");p.addEventListener(p.events.FORM_SUBMITTED,function(a){a.preventDefault();(0,b.dispatchEvent)(j.tableReload,{},n);r(n,a.detail);(0,f.get_string)("filtersapplied","core_reportbuilder").then(h.add).catch(d.default.exception)});p.addEventListener(p.events.NOSUBMIT_BUTTON_PRESSED,function(i){i.preventDefault();var k=new e.default("core_reportbuilder/filters:reset");(0,l.reset)(a).then(function(){return(0,f.get_string)("filtersreset","core_reportbuilder")}).then(h.add).then(function(){return(0,c.loadFragment)("core_reportbuilder","filters_form",m,{reportid:a,parameters:n.dataset.parameter})}).then(function(a,c){g.default.replaceNodeContents(o,a,c);(0,b.dispatchEvent)(j.tableReload,{},n);r(n,0);return k.resolve()}).catch(d.default.exception)});document.querySelector("#region-main").style.overflowX="visible"};a.init=s});
|
||||
function _typeof(a){"@babel/helpers - typeof";if("function"==typeof Symbol&&"symbol"==typeof Symbol.iterator){_typeof=function(a){return typeof a}}else{_typeof=function(a){return a&&"function"==typeof Symbol&&a.constructor===Symbol&&a!==Symbol.prototype?"symbol":typeof a}}return _typeof(a)}define ("core_reportbuilder/filters",["exports","core/event_dispatcher","core/fragment","core/notification","core/pending","core/str","core/templates","core/toast","core_form/dynamicform","core_reportbuilder/local/events","core_reportbuilder/local/selectors","core_reportbuilder/local/repository/filters"],function(a,b,c,d,e,f,g,h,i,j,k,l){"use strict";Object.defineProperty(a,"__esModule",{value:!0});a.init=void 0;d=o(d);e=o(e);g=o(g);i=o(i);j=n(j);k=n(k);function m(){if("function"!=typeof WeakMap)return null;var a=new WeakMap;m=function(){return a};return a}function n(a){if(a&&a.__esModule){return a}if(null===a||"object"!==_typeof(a)&&"function"!=typeof a){return{default:a}}var b=m();if(b&&b.has(a)){return b.get(a)}var c={},d=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var e in a){if(Object.prototype.hasOwnProperty.call(a,e)){var f=d?Object.getOwnPropertyDescriptor(a,e):null;if(f&&(f.get||f.set)){Object.defineProperty(c,e,f)}else{c[e]=a[e]}}}c.default=a;if(b){b.set(a,c)}return c}function o(a){return a&&a.__esModule?a:{default:a}}function p(a,b,c,d,e,f,g){try{var h=a[f](g),i=h.value}catch(a){c(a);return}if(h.done){b(i)}else{Promise.resolve(i).then(d,e)}}function q(a){return function(){var b=this,c=arguments;return new Promise(function(d,e){var h=a.apply(b,c);function f(a){p(h,d,e,f,g,"next",a)}function g(a){p(h,d,e,f,g,"throw",a)}f(void 0)})}}var r=function(){var a=q(regeneratorRuntime.mark(function a(b,c){var d;return regeneratorRuntime.wrap(function(a){while(1){switch(a.prev=a.next){case 0:d=b.querySelector(k.regions.filterButtonLabel);if(!(0<c)){a.next=7;break}a.next=4;return(0,f.get_string)("filtersappliedx","core_reportbuilder",c);case 4:d.textContent=a.sent;a.next=10;break;case 7:a.next=9;return(0,f.get_string)("filters","moodle");case 9:d.textContent=a.sent;case 10:case"end":return a.stop();}}},a)}));return function(){return a.apply(this,arguments)}}(),s=function(a,m){var n=document.querySelector(k.forReport(a)),o=n.querySelector(k.regions.filtersForm),p=new i.default(o,"\\core_reportbuilder\\form\\filter");p.addEventListener(p.events.FORM_SUBMITTED,function(a){a.preventDefault();(0,b.dispatchEvent)(j.tableReload,{},n);r(n,a.detail);(0,f.get_string)("filtersapplied","core_reportbuilder").then(h.add).catch(d.default.exception)});p.addEventListener(p.events.NOSUBMIT_BUTTON_PRESSED,function(i){i.preventDefault();var k=new e.default("core_reportbuilder/filters:reset");(0,l.resetFilters)(a).then(function(){return(0,f.get_string)("filtersreset","core_reportbuilder")}).then(h.add).then(function(){return(0,c.loadFragment)("core_reportbuilder","filters_form",m,{reportid:a,parameters:n.dataset.parameter})}).then(function(a,c){g.default.replaceNodeContents(o,a,c);(0,b.dispatchEvent)(j.tableReload,{},n);r(n,0);return k.resolve()}).catch(d.default.exception)});document.querySelector("#region-main").style.overflowX="visible"};a.init=s});
|
||||
//# sourceMappingURL=filters.min.js.map
|
||||
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -0,0 +1,2 @@
|
||||
function _typeof(a){"@babel/helpers - typeof";if("function"==typeof Symbol&&"symbol"==typeof Symbol.iterator){_typeof=function(a){return typeof a}}else{_typeof=function(a){return a&&"function"==typeof Symbol&&a.constructor===Symbol&&a!==Symbol.prototype?"symbol":typeof a}}return _typeof(a)}define ("core_reportbuilder/local/editor/filters",["exports","jquery","core/event_dispatcher","core/inplace_editable","core/notification","core/pending","core/sortable_list","core/str","core/templates","core/toast","core_reportbuilder/local/events","core_reportbuilder/local/selectors","core_reportbuilder/local/repository/filters"],function(a,b,c,d,e,f,g,h,i,j,k,l,m){"use strict";Object.defineProperty(a,"__esModule",{value:!0});a.init=void 0;b=p(b);e=p(e);f=p(f);g=p(g);i=p(i);k=o(k);l=o(l);function n(){if("function"!=typeof WeakMap)return null;var a=new WeakMap;n=function(){return a};return a}function o(a){if(a&&a.__esModule){return a}if(null===a||"object"!==_typeof(a)&&"function"!=typeof a){return{default:a}}var b=n();if(b&&b.has(a)){return b.get(a)}var c={},d=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var e in a){if(Object.prototype.hasOwnProperty.call(a,e)){var f=d?Object.getOwnPropertyDescriptor(a,e):null;if(f&&(f.get||f.set)){Object.defineProperty(c,e,f)}else{c[e]=a[e]}}}c.default=a;if(b){b.set(a,c)}return c}function p(a){return a&&a.__esModule?a:{default:a}}function q(a,b){return v(a)||u(a,b)||s(a,b)||r()}function r(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function s(a,b){if(!a)return;if("string"==typeof a)return t(a,b);var c=Object.prototype.toString.call(a).slice(8,-1);if("Object"===c&&a.constructor)c=a.constructor.name;if("Map"===c||"Set"===c)return Array.from(c);if("Arguments"===c||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(c))return t(a,b)}function t(a,b){if(null==b||b>a.length)b=a.length;for(var c=0,d=Array(b);c<b;c++){d[c]=a[c]}return d}function u(a,b){if("undefined"==typeof Symbol||!(Symbol.iterator in Object(a)))return;var c=[],d=!0,e=!1,f=void 0;try{for(var g=a[Symbol.iterator](),h;!(d=(h=g.next()).done);d=!0){c.push(h.value);if(b&&c.length===b)break}}catch(a){e=!0;f=a}finally{try{if(!d&&null!=g["return"])g["return"]()}finally{if(e)throw f}}return c}function v(a){if(Array.isArray(a))return a}var w=function(a,b){var c=new f.default("core_reportbuilder/filters:reload"),d=a.querySelector(l.regions.settingsFilters);return i.default.renderForPromise("core_reportbuilder/local/settings/filters",{filters:b}).then(function(a){var b=a.html,e=a.js;i.default.replaceNode(d,b,e);return c.resolve()})},x=function(a,d){if(d){return}a.addEventListener("click",function(b){var d=b.target.closest(l.actions.reportAddFilter);if(d){b.preventDefault();if("0"===d.value){return}var o=new f.default("core_reportbuilder/filters:add");(0,m.addFilter)(a.dataset.reportId,d.value).then(function(b){return w(a,b)}).then(function(){return(0,h.get_string)("filteradded","core_reportbuilder",d.options[d.selectedIndex].text)}).then(j.add).then(function(){return o.resolve()}).catch(e.default.exception)}var g=b.target.closest(l.actions.reportRemoveFilter);if(g){b.preventDefault();var i=g.closest(l.regions.activeFilter),n=i.dataset.filterName;(0,h.get_strings)([{key:"deletefilter",component:"core_reportbuilder",param:n},{key:"deletefilterconfirm",component:"core_reportbuilder",param:n},{key:"delete",component:"moodle"}]).then(function(b){var d=q(b,3),g=d[0],l=d[1],o=d[2];e.default.confirm(g,l,o,null,function(){var b=new f.default("core_reportbuilder/filters:remove");(0,m.deleteFilter)(a.dataset.reportId,i.dataset.filterId).then(function(b){return w(a,b)}).then(function(){return(0,h.get_string)("filterdeleted","core_reportbuilder",n)}).then(j.add).then(function(){(0,c.dispatchEvent)(k.tableReload,{},a);return b.resolve()}).catch(e.default.exception)})}).catch(e.default.exception)}});var i=new g.default("".concat(l.regions.activeFilters," ul"),{isHorizontal:!1});i.getElementName=function(a){return Promise.resolve(a.data("filterName"))};(0,b.default)(a).on(g.default.EVENTS.DROP,"li[data-filter-id]",function(b,c){if(c.positionChanged){var d=new f.default("core_reportbuilder/filters:reorder"),g=c.element.data("filterId"),i=c.element.data("filterPosition"),k=c.targetNextElement.data("filterPosition")||c.element.siblings().length+2;if(k>i){k--}(0,m.reorderFilter)(a.dataset.reportId,g,k).then(function(b){return w(a,b)}).then(function(){return(0,h.get_string)("filtermoved","core_reportbuilder",c.element.data("filterName"))}).then(j.add).then(function(){return d.resolve()}).catch(e.default.exception)}})};a.init=x});
|
||||
//# sourceMappingURL=filters.min.js.map
|
||||
File diff suppressed because one or more lines are too long
@@ -0,0 +1,2 @@
|
||||
function _typeof(a){"@babel/helpers - typeof";if("function"==typeof Symbol&&"symbol"==typeof Symbol.iterator){_typeof=function(a){return typeof a}}else{_typeof=function(a){return a&&"function"==typeof Symbol&&a.constructor===Symbol&&a!==Symbol.prototype?"symbol":typeof a}}return _typeof(a)}define ("core_reportbuilder/local/editor/sorting",["exports","jquery","core/inplace_editable","core/notification","core/pending","core/pubsub","core/sortable_list","core/str","core/toast","core_reportbuilder/local/selectors","core_reportbuilder/local/repository/sorting","core/templates","core/event_dispatcher","core_reportbuilder/local/events"],function(a,b,c,d,e,f,g,h,i,j,k,l,m,n){"use strict";Object.defineProperty(a,"__esModule",{value:!0});a.init=void 0;b=q(b);d=q(d);e=q(e);g=q(g);j=p(j);l=q(l);n=p(n);function o(){if("function"!=typeof WeakMap)return null;var a=new WeakMap;o=function(){return a};return a}function p(a){if(a&&a.__esModule){return a}if(null===a||"object"!==_typeof(a)&&"function"!=typeof a){return{default:a}}var b=o();if(b&&b.has(a)){return b.get(a)}var c={},d=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var e in a){if(Object.prototype.hasOwnProperty.call(a,e)){var f=d?Object.getOwnPropertyDescriptor(a,e):null;if(f&&(f.get||f.set)){Object.defineProperty(c,e,f)}else{c[e]=a[e]}}}c.default=a;if(b){b.set(a,c)}return c}function q(a){return a&&a.__esModule?a:{default:a}}var r={ASCENDING:4,DESCENDING:3},s=function(a){var b=new e.default("core_reportbuilder/sorting:reload"),c=document.querySelector(j.regions.settingsSorting);return l.default.renderForPromise("core_reportbuilder/local/settings/sorting",{sorting:a}).then(function(a){var d=a.html,e=a.js;l.default.replaceNode(c,d,e);return b.resolve()})},t=function(a,b,c,d){var e=a.dataset.reportId,f=b.closest("li"),g=f.dataset.columnSortId,j=f.dataset.columnSortName;return(0,k.toggleColumnSorting)(e,g,c,d).then(s).then(function(){return(0,h.get_string)("columnsortupdated","core_reportbuilder",j)}).then(i.add).then(function(){(0,m.dispatchEvent)(n.tableReload,{},a);return null})},u=function(a,c){if(c){return}(0,f.subscribe)(n.publish.reportColumnsUpdated,function(a){return s(a).catch(d.default.exception)});a.addEventListener("click",function(b){var c=b.target.closest(j.actions.reportToggleColumnSort);if(c){b.preventDefault();var f=new e.default("core_reportbuilder/sorting:toggle"),g=parseInt(c.closest("li").dataset.columnSortDirection);t(a,c,c.checked,g).then(function(){return f.resolve()}).catch(d.default.exception)}var h=b.target.closest(j.actions.reportToggleColumnSortDirection);if(h){b.preventDefault();var i=new e.default("core_reportbuilder/sorting:direction"),k=h.closest("li"),l=k.dataset.columnSortEnabled,m=parseInt(k.dataset.columnSortDirection);if(m===r.ASCENDING){m=r.DESCENDING}else if(m===r.DESCENDING){m=r.ASCENDING}t(a,h,l,m).then(function(){return i.resolve()}).catch(d.default.exception)}});var l=new g.default("".concat(j.regions.settingsSorting," ul"),{isHorizontal:!1});l.getElementName=function(a){return Promise.resolve(a.data("columnSortName"))};(0,b.default)(a).on(g.default.EVENTS.DROP,"li[data-column-sort-id]",function(b,c){if(c.positionChanged){var f=new e.default("core_reportbuilder/sorting:reorder"),g=c.element.data("columnSortId"),j=c.element.data("columnSortPosition"),l=c.targetNextElement.data("columnSortPosition")||c.element.siblings().length+2;if(l>j){l--}(0,k.reorderColumnSorting)(a.dataset.reportId,g,l).then(s).then(function(){return(0,h.get_string)("columnsortupdated","core_reportbuilder",c.element.data("columnSortName"))}).then(i.add).then(function(){(0,m.dispatchEvent)(n.tableReload,{},a);return null}).then(function(){return f.resolve()}).catch(d.default.exception)}})};a.init=u});
|
||||
//# sourceMappingURL=sorting.min.js.map
|
||||
File diff suppressed because one or more lines are too long
+1
-1
@@ -1,2 +1,2 @@
|
||||
define ("core_reportbuilder/local/events",["exports"],function(a){"use strict";Object.defineProperty(a,"__esModule",{value:!0});a.default=void 0;a.default={tableReload:"core_reportbuilder_table_reload"};return a.default});
|
||||
define ("core_reportbuilder/local/events",["exports"],function(a){"use strict";Object.defineProperty(a,"__esModule",{value:!0});a.default=void 0;a.default={tableReload:"core_reportbuilder_table_reload",publish:{reportColumnsUpdated:"core_reportbuilder_report_columns_updated"}};return a.default});
|
||||
//# sourceMappingURL=events.min.js.map
|
||||
|
||||
@@ -1 +1 @@
|
||||
{"version":3,"sources":["../../src/local/events.js"],"names":["tableReload"],"mappings":"2JA6Be,CAeXA,WAAW,CAAE,iCAfF,C","sourcesContent":["// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see <http://www.gnu.org/licenses/>.\n\n/**\n * Report builder events\n *\n * @module core_reportbuilder/local/events\n * @copyright 2021 Paul Holden <[email protected]>\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\n/**\n * Events for the Report builder subsystem\n *\n * @constant\n * @property {String} tableReload See {@link event:tableReload}\n */\nexport default {\n /**\n * Trigger table reloading\n *\n * @event tableReload\n * @type {CustomEvent}\n * @property {object} detail\n * @property {Boolean} detail.preservePagination Whether current pagination should be preserved (default false)\n *\n * @example <caption>Triggering table reload</caption>\n * import {dispatchEvent} from 'core/event_dispatcher';\n * import * as reportEvents from 'core_reportbuilder/local/events';\n *\n * dispatchEvent(reportEvents.tableReload, {}, document.querySelector(...));\n */\n tableReload: 'core_reportbuilder_table_reload',\n};\n"],"file":"events.min.js"}
|
||||
{"version":3,"sources":["../../src/local/events.js"],"names":["tableReload","publish","reportColumnsUpdated"],"mappings":"2JA6Be,CAeXA,WAAW,CAAE,iCAfF,CAgBXC,OAAO,CAAE,CACLC,oBAAoB,CAAE,2CADjB,CAhBE,C","sourcesContent":["// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see <http://www.gnu.org/licenses/>.\n\n/**\n * Report builder events\n *\n * @module core_reportbuilder/local/events\n * @copyright 2021 Paul Holden <[email protected]>\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\n/**\n * Events for the Report builder subsystem\n *\n * @constant\n * @property {String} tableReload See {@link event:tableReload}\n */\nexport default {\n /**\n * Trigger table reloading\n *\n * @event tableReload\n * @type {CustomEvent}\n * @property {object} detail\n * @property {Boolean} detail.preservePagination Whether current pagination should be preserved (default false)\n *\n * @example <caption>Triggering table reload</caption>\n * import {dispatchEvent} from 'core/event_dispatcher';\n * import * as reportEvents from 'core_reportbuilder/local/events';\n *\n * dispatchEvent(reportEvents.tableReload, {}, document.querySelector(...));\n */\n tableReload: 'core_reportbuilder_table_reload',\n publish: {\n reportColumnsUpdated: 'core_reportbuilder_report_columns_updated',\n },\n};\n"],"file":"events.min.js"}
|
||||
@@ -0,0 +1,2 @@
|
||||
define ("core_reportbuilder/local/repository/columns",["exports","core/ajax"],function(a,b){"use strict";Object.defineProperty(a,"__esModule",{value:!0});a.reorderColumn=a.deleteColumn=a.addColumn=void 0;b=function(a){return a&&a.__esModule?a:{default:a}}(b);var c=function(a,c){return b.default.call([{methodname:"core_reportbuilder_columns_add",args:{reportid:a,uniqueidentifier:c}}])[0]};a.addColumn=c;var d=function(a,c){return b.default.call([{methodname:"core_reportbuilder_columns_delete",args:{reportid:a,columnid:c}}])[0]};a.deleteColumn=d;var e=function(a,c,d){return b.default.call([{methodname:"core_reportbuilder_columns_reorder",args:{reportid:a,columnid:c,position:d}}])[0]};a.reorderColumn=e});
|
||||
//# sourceMappingURL=columns.min.js.map
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"sources":["../../../src/local/repository/columns.js"],"names":["addColumn","reportId","uniqueIdentifier","Ajax","call","methodname","args","reportid","uniqueidentifier","deleteColumn","columnId","columnid","reorderColumn","position"],"mappings":"4MAwBA,uDASO,GAAMA,CAAAA,CAAS,CAAG,SAACC,CAAD,CAAWC,CAAX,CAAgC,CAMrD,MAAOC,WAAKC,IAAL,CAAU,CALD,CACZC,UAAU,CAAE,gCADA,CAEZC,IAAI,CAAE,CAACC,QAAQ,CAAEN,CAAX,CAAqBO,gBAAgB,CAAEN,CAAvC,CAFM,CAKC,CAAV,EAAqB,CAArB,CACV,CAPM,C,cAgBA,GAAMO,CAAAA,CAAY,CAAG,SAACR,CAAD,CAAWS,CAAX,CAAwB,CAMhD,MAAOP,WAAKC,IAAL,CAAU,CALD,CACZC,UAAU,CAAE,mCADA,CAEZC,IAAI,CAAE,CAACC,QAAQ,CAAEN,CAAX,CAAqBU,QAAQ,CAAED,CAA/B,CAFM,CAKC,CAAV,EAAqB,CAArB,CACV,CAPM,C,iBAiBA,GAAME,CAAAA,CAAa,CAAG,SAACX,CAAD,CAAWS,CAAX,CAAqBG,CAArB,CAAkC,CAM3D,MAAOV,WAAKC,IAAL,CAAU,CALD,CACZC,UAAU,CAAE,oCADA,CAEZC,IAAI,CAAE,CAACC,QAAQ,CAAEN,CAAX,CAAqBU,QAAQ,CAAED,CAA/B,CAAyCG,QAAQ,CAAEA,CAAnD,CAFM,CAKC,CAAV,EAAqB,CAArB,CACV,CAPM,C","sourcesContent":["// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see <http://www.gnu.org/licenses/>.\n\n/**\n * Module to handle column AJAX requests\n *\n * @module core_reportbuilder/local/repository/columns\n * @package core_reportbuilder\n * @copyright 2021 Paul Holden <[email protected]>\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nimport Ajax from 'core/ajax';\n\n/**\n * Add column to given report\n *\n * @param {Number} reportId\n * @param {String} uniqueIdentifier\n * @return {Promise}\n */\nexport const addColumn = (reportId, uniqueIdentifier) => {\n const request = {\n methodname: 'core_reportbuilder_columns_add',\n args: {reportid: reportId, uniqueidentifier: uniqueIdentifier}\n };\n\n return Ajax.call([request])[0];\n};\n\n/**\n * Remove column from given report\n *\n * @param {Number} reportId\n * @param {Number} columnId\n * @return {Promise}\n */\nexport const deleteColumn = (reportId, columnId) => {\n const request = {\n methodname: 'core_reportbuilder_columns_delete',\n args: {reportid: reportId, columnid: columnId}\n };\n\n return Ajax.call([request])[0];\n};\n\n/**\n * Re-order column within a report\n *\n * @param {Number} reportId\n * @param {Number} columnId\n * @param {Number} position\n * @return {Promise}\n */\nexport const reorderColumn = (reportId, columnId, position) => {\n const request = {\n methodname: 'core_reportbuilder_columns_reorder',\n args: {reportid: reportId, columnid: columnId, position: position}\n };\n\n return Ajax.call([request])[0];\n};\n"],"file":"columns.min.js"}
|
||||
@@ -0,0 +1,2 @@
|
||||
define ("core_reportbuilder/local/repository/conditions",["exports","core/ajax"],function(a,b){"use strict";Object.defineProperty(a,"__esModule",{value:!0});a.reorderCondition=a.deleteCondition=a.addCondition=a.resetConditions=void 0;b=function(a){return a&&a.__esModule?a:{default:a}}(b);var c=function(a){return b.default.call([{methodname:"core_reportbuilder_conditions_reset",args:{reportid:a}}])[0]};a.resetConditions=c;var d=function(a,c){return b.default.call([{methodname:"core_reportbuilder_conditions_add",args:{reportid:a,uniqueidentifier:c}}])[0]};a.addCondition=d;var e=function(a,c){return b.default.call([{methodname:"core_reportbuilder_conditions_delete",args:{reportid:a,conditionid:c}}])[0]};a.deleteCondition=e;var f=function(a,c,d){return b.default.call([{methodname:"core_reportbuilder_conditions_reorder",args:{reportid:a,conditionid:c,position:d}}])[0]};a.reorderCondition=f});
|
||||
//# sourceMappingURL=conditions.min.js.map
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"sources":["../../../src/local/repository/conditions.js"],"names":["resetConditions","reportId","Ajax","call","methodname","args","reportid","addCondition","uniqueIdentifier","uniqueidentifier","deleteCondition","conditionId","conditionid","reorderCondition","position"],"mappings":"0OAwBA,uDAQO,GAAMA,CAAAA,CAAe,CAAG,SAAAC,CAAQ,CAAI,CAMvC,MAAOC,WAAKC,IAAL,CAAU,CALD,CACZC,UAAU,CAAE,qCADA,CAEZC,IAAI,CAAE,CAACC,QAAQ,CAAEL,CAAX,CAFM,CAKC,CAAV,EAAqB,CAArB,CACV,CAPM,C,oBAgBA,GAAMM,CAAAA,CAAY,CAAG,SAACN,CAAD,CAAWO,CAAX,CAAgC,CAMxD,MAAON,WAAKC,IAAL,CAAU,CALD,CACZC,UAAU,CAAE,mCADA,CAEZC,IAAI,CAAE,CAACC,QAAQ,CAAEL,CAAX,CAAqBQ,gBAAgB,CAAED,CAAvC,CAFM,CAKC,CAAV,EAAqB,CAArB,CACV,CAPM,C,iBAgBA,GAAME,CAAAA,CAAe,CAAG,SAACT,CAAD,CAAWU,CAAX,CAA2B,CAMtD,MAAOT,WAAKC,IAAL,CAAU,CALD,CACZC,UAAU,CAAE,sCADA,CAEZC,IAAI,CAAE,CAACC,QAAQ,CAAEL,CAAX,CAAqBW,WAAW,CAAED,CAAlC,CAFM,CAKC,CAAV,EAAqB,CAArB,CACV,CAPM,C,oBAiBA,GAAME,CAAAA,CAAgB,CAAG,SAACZ,CAAD,CAAWU,CAAX,CAAwBG,CAAxB,CAAqC,CAMjE,MAAOZ,WAAKC,IAAL,CAAU,CALD,CACZC,UAAU,CAAE,uCADA,CAEZC,IAAI,CAAE,CAACC,QAAQ,CAAEL,CAAX,CAAqBW,WAAW,CAAED,CAAlC,CAA+CG,QAAQ,CAAEA,CAAzD,CAFM,CAKC,CAAV,EAAqB,CAArB,CACV,CAPM,C","sourcesContent":["// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see <http://www.gnu.org/licenses/>.\n\n/**\n * Module to handle condition AJAX requests\n *\n * @module core_reportbuilder/local/repository/conditions\n * @package core_reportbuilder\n * @copyright 2021 Paul Holden <[email protected]>\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nimport Ajax from 'core/ajax';\n\n/**\n * Reset all conditions for given report\n *\n * @param {Number} reportId\n * @return {Promise}\n */\nexport const resetConditions = reportId => {\n const request = {\n methodname: 'core_reportbuilder_conditions_reset',\n args: {reportid: reportId}\n };\n\n return Ajax.call([request])[0];\n};\n\n/**\n * Add condition to given report\n *\n * @param {Number} reportId\n * @param {String} uniqueIdentifier\n * @return {Promise}\n */\nexport const addCondition = (reportId, uniqueIdentifier) => {\n const request = {\n methodname: 'core_reportbuilder_conditions_add',\n args: {reportid: reportId, uniqueidentifier: uniqueIdentifier}\n };\n\n return Ajax.call([request])[0];\n};\n\n/**\n * Remove condition from given report\n *\n * @param {Number} reportId\n * @param {Number} conditionId\n * @return {Promise}\n */\nexport const deleteCondition = (reportId, conditionId) => {\n const request = {\n methodname: 'core_reportbuilder_conditions_delete',\n args: {reportid: reportId, conditionid: conditionId}\n };\n\n return Ajax.call([request])[0];\n};\n\n/**\n * Reorder a condition in a given report\n *\n * @param {Number} reportId\n * @param {Number} conditionId\n * @param {Number} position\n * @return {Promise}\n */\nexport const reorderCondition = (reportId, conditionId, position) => {\n const request = {\n methodname: 'core_reportbuilder_conditions_reorder',\n args: {reportid: reportId, conditionid: conditionId, position: position}\n };\n\n return Ajax.call([request])[0];\n};\n"],"file":"conditions.min.js"}
|
||||
+1
-1
@@ -1,2 +1,2 @@
|
||||
define ("core_reportbuilder/local/repository/filters",["exports","core/ajax"],function(a,b){"use strict";Object.defineProperty(a,"__esModule",{value:!0});a.reset=void 0;b=function(a){return a&&a.__esModule?a:{default:a}}(b);var c=function(a){return b.default.call([{methodname:"core_reportbuilder_filters_reset",args:{reportid:a}}])[0]};a.reset=c});
|
||||
define ("core_reportbuilder/local/repository/filters",["exports","core/ajax"],function(a,b){"use strict";Object.defineProperty(a,"__esModule",{value:!0});a.reorderFilter=a.deleteFilter=a.addFilter=a.resetFilters=void 0;b=function(a){return a&&a.__esModule?a:{default:a}}(b);var c=function(a){return b.default.call([{methodname:"core_reportbuilder_filters_reset",args:{reportid:a}}])[0]};a.resetFilters=c;var d=function(a,c){return b.default.call([{methodname:"core_reportbuilder_filters_add",args:{reportid:a,uniqueidentifier:c}}])[0]};a.addFilter=d;var e=function(a,c){return b.default.call([{methodname:"core_reportbuilder_filters_delete",args:{reportid:a,filterid:c}}])[0]};a.deleteFilter=e;var f=function(a,c,d){return b.default.call([{methodname:"core_reportbuilder_filters_reorder",args:{reportid:a,filterid:c,position:d}}])[0]};a.reorderFilter=f});
|
||||
//# sourceMappingURL=filters.min.js.map
|
||||
|
||||
@@ -1 +1 @@
|
||||
{"version":3,"sources":["../../../src/local/repository/filters.js"],"names":["reset","reportId","Ajax","call","methodname","args","reportid"],"mappings":"yKAuBA,uDASO,GAAMA,CAAAA,CAAK,CAAG,SAAAC,CAAQ,CAAI,CAM7B,MAAOC,WAAKC,IAAL,CAAU,CALD,CACZC,UAAU,CAAE,kCADA,CAEZC,IAAI,CAAE,CAACC,QAAQ,CAAEL,CAAX,CAFM,CAKC,CAAV,EAAqB,CAArB,CACV,CAPM,C","sourcesContent":["// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see <http://www.gnu.org/licenses/>.\n\n/**\n * Module to handle filter AJAX requests\n *\n * @module core_reportbuilder/local/repository/filters\n * @copyright 2021 Paul Holden <[email protected]>\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nimport Ajax from 'core/ajax';\n\n/**\n * Reset all filters for given report\n *\n * @method\n * @param {Number} reportId\n * @return {Promise}\n */\nexport const reset = reportId => {\n const request = {\n methodname: 'core_reportbuilder_filters_reset',\n args: {reportid: reportId}\n };\n\n return Ajax.call([request])[0];\n};\n"],"file":"filters.min.js"}
|
||||
{"version":3,"sources":["../../../src/local/repository/filters.js"],"names":["resetFilters","reportId","Ajax","call","methodname","args","reportid","addFilter","uniqueIdentifier","uniqueidentifier","deleteFilter","filterId","filterid","reorderFilter","position"],"mappings":"2NAuBA,uDASO,GAAMA,CAAAA,CAAY,CAAG,SAAAC,CAAQ,CAAI,CAMpC,MAAOC,WAAKC,IAAL,CAAU,CALD,CACZC,UAAU,CAAE,kCADA,CAEZC,IAAI,CAAE,CAACC,QAAQ,CAAEL,CAAX,CAFM,CAKC,CAAV,EAAqB,CAArB,CACV,CAPM,C,iBAgBA,GAAMM,CAAAA,CAAS,CAAG,SAACN,CAAD,CAAWO,CAAX,CAAgC,CAMrD,MAAON,WAAKC,IAAL,CAAU,CALD,CACZC,UAAU,CAAE,gCADA,CAEZC,IAAI,CAAE,CAACC,QAAQ,CAAEL,CAAX,CAAqBQ,gBAAgB,CAAED,CAAvC,CAFM,CAKC,CAAV,EAAqB,CAArB,CACV,CAPM,C,cAgBA,GAAME,CAAAA,CAAY,CAAG,SAACT,CAAD,CAAWU,CAAX,CAAwB,CAMhD,MAAOT,WAAKC,IAAL,CAAU,CALD,CACZC,UAAU,CAAE,mCADA,CAEZC,IAAI,CAAE,CAACC,QAAQ,CAAEL,CAAX,CAAqBW,QAAQ,CAAED,CAA/B,CAFM,CAKC,CAAV,EAAqB,CAArB,CACV,CAPM,C,iBAiBA,GAAME,CAAAA,CAAa,CAAG,SAACZ,CAAD,CAAWU,CAAX,CAAqBG,CAArB,CAAkC,CAM3D,MAAOZ,WAAKC,IAAL,CAAU,CALD,CACZC,UAAU,CAAE,oCADA,CAEZC,IAAI,CAAE,CAACC,QAAQ,CAAEL,CAAX,CAAqBW,QAAQ,CAAED,CAA/B,CAAyCG,QAAQ,CAAEA,CAAnD,CAFM,CAKC,CAAV,EAAqB,CAArB,CACV,CAPM,C","sourcesContent":["// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see <http://www.gnu.org/licenses/>.\n\n/**\n * Module to handle filter AJAX requests\n *\n * @module core_reportbuilder/local/repository/filters\n * @copyright 2021 Paul Holden <[email protected]>\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nimport Ajax from 'core/ajax';\n\n/**\n * Reset all filters for given report\n *\n * @method\n * @param {Number} reportId\n * @return {Promise}\n */\nexport const resetFilters = reportId => {\n const request = {\n methodname: 'core_reportbuilder_filters_reset',\n args: {reportid: reportId}\n };\n\n return Ajax.call([request])[0];\n};\n\n/**\n * Add a filter to the given report\n *\n * @param {Number} reportId\n * @param {String} uniqueIdentifier\n * @return {Promise}\n */\nexport const addFilter = (reportId, uniqueIdentifier) => {\n const request = {\n methodname: 'core_reportbuilder_filters_add',\n args: {reportid: reportId, uniqueidentifier: uniqueIdentifier}\n };\n\n return Ajax.call([request])[0];\n};\n\n/**\n * Remove filter from given report\n *\n * @param {Number} reportId\n * @param {Number} filterId\n * @return {Promise}\n */\nexport const deleteFilter = (reportId, filterId) => {\n const request = {\n methodname: 'core_reportbuilder_filters_delete',\n args: {reportid: reportId, filterid: filterId}\n };\n\n return Ajax.call([request])[0];\n};\n\n/**\n * Reorder a filter in a given report\n *\n * @param {Number} reportId\n * @param {Number} filterId\n * @param {Number} position\n * @return {Promise}\n */\nexport const reorderFilter = (reportId, filterId, position) => {\n const request = {\n methodname: 'core_reportbuilder_filters_reorder',\n args: {reportid: reportId, filterid: filterId, position: position}\n };\n\n return Ajax.call([request])[0];\n};\n"],"file":"filters.min.js"}
|
||||
@@ -0,0 +1,2 @@
|
||||
define ("core_reportbuilder/local/repository/modals",["exports","core_form/modalform","core/str"],function(a,b,c){"use strict";Object.defineProperty(a,"__esModule",{value:!0});a.createReportModal=void 0;b=function(a){return a&&a.__esModule?a:{default:a}}(b);var d=function(a,d){var e=2<arguments.length&&arguments[2]!==void 0?arguments[2]:0;return new b.default({modalConfig:{title:d},formClass:"core_reportbuilder\\form\\report",args:{id:e},saveButtonText:(0,c.get_string)("save","moodle"),returnFocus:a})};a.createReportModal=d});
|
||||
//# sourceMappingURL=modals.min.js.map
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"sources":["../../../src/local/repository/modals.js"],"names":["createReportModal","triggerElement","modalTitle","reportId","ModalForm","modalConfig","title","formClass","args","id","saveButtonText","returnFocus"],"mappings":"2MAwBA,uDAWO,GAAMA,CAAAA,CAAiB,CAAG,SAACC,CAAD,CAAiBC,CAAjB,CAA8C,IAAjBC,CAAAA,CAAiB,wDAAN,CAAM,CAC3E,MAAO,IAAIC,UAAJ,CAAc,CACjBC,WAAW,CAAE,CACTC,KAAK,CAAEJ,CADE,CADI,CAIjBK,SAAS,CAAE,kCAJM,CAKjBC,IAAI,CAAE,CACFC,EAAE,CAAEN,CADF,CALW,CAQjBO,cAAc,CAAE,iBAAU,MAAV,CAAkB,QAAlB,CARC,CASjBC,WAAW,CAAEV,CATI,CAAd,CAWV,CAZM,C","sourcesContent":["// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see <http://www.gnu.org/licenses/>.\n\n/**\n * Module to handle modal form requests\n *\n * @module core_reportbuilder/local/repository/modals\n * @package core_reportbuilder\n * @copyright 2021 David Matamoros <[email protected]>\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nimport ModalForm from 'core_form/modalform';\nimport {get_string as getString} from 'core/str';\n\n/**\n * Open the New Report modal form\n *\n * @param {EventTarget} triggerElement\n * @param {Promise} modalTitle\n * @param {Number} reportId\n * @return {ModalForm}\n */\nexport const createReportModal = (triggerElement, modalTitle, reportId = 0) => {\n return new ModalForm({\n modalConfig: {\n title: modalTitle,\n },\n formClass: 'core_reportbuilder\\\\form\\\\report',\n args: {\n id: reportId,\n },\n saveButtonText: getString('save', 'moodle'),\n returnFocus: triggerElement,\n });\n};\n"],"file":"modals.min.js"}
|
||||
@@ -0,0 +1,2 @@
|
||||
define ("core_reportbuilder/local/repository/reports",["exports","core/ajax"],function(a,b){"use strict";Object.defineProperty(a,"__esModule",{value:!0});a.getReport=a.deleteReport=void 0;b=function(a){return a&&a.__esModule?a:{default:a}}(b);var c=function(a){return b.default.call([{methodname:"core_reportbuilder_reports_delete",args:{reportid:a}}])[0]};a.deleteReport=c;var d=function(a,c){return b.default.call([{methodname:"core_reportbuilder_reports_get",args:{reportid:a,editmode:c}}])[0]};a.getReport=d});
|
||||
//# sourceMappingURL=reports.min.js.map
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"sources":["../../../src/local/repository/reports.js"],"names":["deleteReport","reportId","Ajax","call","methodname","args","reportid","getReport","editMode","editmode"],"mappings":"4LAwBA,uDAQO,GAAMA,CAAAA,CAAY,CAAG,SAAAC,CAAQ,CAAI,CAMpC,MAAOC,WAAKC,IAAL,CAAU,CALD,CACZC,UAAU,CAAE,mCADA,CAEZC,IAAI,CAAE,CAACC,QAAQ,CAAEL,CAAX,CAFM,CAKC,CAAV,EAAqB,CAArB,CACV,CAPM,C,iBAgBA,GAAMM,CAAAA,CAAS,CAAG,SAACN,CAAD,CAAWO,CAAX,CAAwB,CAM7C,MAAON,WAAKC,IAAL,CAAU,CALD,CACZC,UAAU,CAAE,gCADA,CAEZC,IAAI,CAAE,CAACC,QAAQ,CAAEL,CAAX,CAAqBQ,QAAQ,CAAED,CAA/B,CAFM,CAKC,CAAV,EAAqB,CAArB,CACV,CAPM,C","sourcesContent":["// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see <http://www.gnu.org/licenses/>.\n\n/**\n * Module to handle report AJAX requests\n *\n * @module core_reportbuilder/local/repository/reports\n * @package core_reportbuilder\n * @copyright 2021 Paul Holden <[email protected]>\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nimport Ajax from 'core/ajax';\n\n/**\n * Delete given report\n *\n * @param {Number} reportId\n * @return {Promise}\n */\nexport const deleteReport = reportId => {\n const request = {\n methodname: 'core_reportbuilder_reports_delete',\n args: {reportid: reportId}\n };\n\n return Ajax.call([request])[0];\n};\n\n/**\n * Get report content\n *\n * @param {Number} reportId\n * @param {Boolean} editMode\n * @return {Promise}\n */\nexport const getReport = (reportId, editMode) => {\n const request = {\n methodname: 'core_reportbuilder_reports_get',\n args: {reportid: reportId, editmode: editMode}\n };\n\n return Ajax.call([request])[0];\n};\n"],"file":"reports.min.js"}
|
||||
@@ -0,0 +1,2 @@
|
||||
define ("core_reportbuilder/local/repository/sorting",["exports","core/ajax"],function(a,b){"use strict";Object.defineProperty(a,"__esModule",{value:!0});a.toggleColumnSorting=a.reorderColumnSorting=void 0;b=function(a){return a&&a.__esModule?a:{default:a}}(b);var c=function(a,c,d){return b.default.call([{methodname:"core_reportbuilder_columns_sort_reorder",args:{reportid:a,columnid:c,position:d}}])[0]};a.reorderColumnSorting=c;var d=function(a,c,d,e){return b.default.call([{methodname:"core_reportbuilder_columns_sort_toggle",args:{reportid:a,columnid:c,enabled:d,direction:e}}])[0]};a.toggleColumnSorting=d});
|
||||
//# sourceMappingURL=sorting.min.js.map
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"sources":["../../../src/local/repository/sorting.js"],"names":["reorderColumnSorting","reportId","columnId","position","Ajax","call","methodname","args","reportid","columnid","toggleColumnSorting","enabled","direction"],"mappings":"8MAwBA,uDAUO,GAAMA,CAAAA,CAAoB,CAAG,SAACC,CAAD,CAAWC,CAAX,CAAqBC,CAArB,CAAkC,CAMlE,MAAOC,WAAKC,IAAL,CAAU,CALD,CACZC,UAAU,CAAE,yCADA,CAEZC,IAAI,CAAE,CAACC,QAAQ,CAAEP,CAAX,CAAqBQ,QAAQ,CAAEP,CAA/B,CAAyCC,QAAQ,CAAEA,CAAnD,CAFM,CAKC,CAAV,EAAqB,CAArB,CACV,CAPM,C,yBAkBA,GAAMO,CAAAA,CAAmB,CAAG,SAACT,CAAD,CAAWC,CAAX,CAAqBS,CAArB,CAA8BC,CAA9B,CAA4C,CAM3E,MAAOR,WAAKC,IAAL,CAAU,CALD,CACZC,UAAU,CAAE,wCADA,CAEZC,IAAI,CAAE,CAACC,QAAQ,CAAEP,CAAX,CAAqBQ,QAAQ,CAAEP,CAA/B,CAAyCS,OAAO,CAAEA,CAAlD,CAA2DC,SAAS,CAAEA,CAAtE,CAFM,CAKC,CAAV,EAAqB,CAArB,CACV,CAPM,C","sourcesContent":["// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see <http://www.gnu.org/licenses/>.\n\n/**\n * Module to handle column AJAX requests\n *\n * @module core_reportbuilder/local/repository/sorting\n * @package core_reportbuilder\n * @copyright 2021 David Matamoros <[email protected]>\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nimport Ajax from 'core/ajax';\n\n/**\n * Re-order sort column position\n *\n * @param {Number} reportId\n * @param {Number} columnId\n * @param {Number} position\n * @return {Promise}\n */\nexport const reorderColumnSorting = (reportId, columnId, position) => {\n const request = {\n methodname: 'core_reportbuilder_columns_sort_reorder',\n args: {reportid: reportId, columnid: columnId, position: position}\n };\n\n return Ajax.call([request])[0];\n};\n\n/**\n * Enables/disabled sorting on column\n *\n * @param {Number} reportId\n * @param {Number} columnId\n * @param {Boolean} enabled\n * @param {Number} direction\n * @return {Promise}\n */\nexport const toggleColumnSorting = (reportId, columnId, enabled, direction) => {\n const request = {\n methodname: 'core_reportbuilder_columns_sort_toggle',\n args: {reportid: reportId, columnid: columnId, enabled: enabled, direction: direction}\n };\n\n return Ajax.call([request])[0];\n};\n"],"file":"sorting.min.js"}
|
||||
+1
-1
@@ -1,2 +1,2 @@
|
||||
define ("core_reportbuilder/local/selectors",["exports"],function(a){"use strict";Object.defineProperty(a,"__esModule",{value:!0});a.default=void 0;var b={regions:{systemReport:"[data-region=\"core_reportbuilder/system-report\"]",filterButtonLabel:"[data-region=\"filter-button-label\"]",filtersForm:"[data-region=\"filters-form\"]"},actions:{reportActionPopup:"[data-action=\"report-action-popup\"]"}};b.forSystemReport=function(a){return"".concat(b.regions.systemReport,"[data-reportid=\"").concat(a,"\"]")};a.default=b;return a.default});
|
||||
define ("core_reportbuilder/local/selectors",["exports"],function(a){"use strict";Object.defineProperty(a,"__esModule",{value:!0});a.default=void 0;var b={regions:{report:"[data-region=\"core_reportbuilder/report\"]",reportTable:"[data-region=\"reportbuilder-table\"]",columnHeader:"[data-region=\"column-header\"]",filterButtonLabel:"[data-region=\"filter-button-label\"]",filtersForm:"[data-region=\"filters-form\"]",sidebarMenu:"[data-region=\"sidebar-menu\"]",sidebarCard:"[data-region=\"sidebar-card\"]",settingsConditions:"[data-region=\"settings-conditions\"]",activeConditions:"[data-region=\"active-conditions\"]",activeCondition:"[data-region=\"active-condition\"]",settingsFilters:"[data-region=\"settings-filters\"]",activeFilters:"[data-region=\"active-filters\"]",activeFilter:"[data-region=\"active-filter\"]",settingsSorting:"[data-region=\"settings-sorting\"]"},actions:{reportActionPopup:"[data-action=\"report-action-popup\"]",reportCreate:"[data-action=\"report-create\"]",reportEdit:"[data-action=\"report-edit\"]",reportDelete:"[data-action=\"report-delete\"]",reportAddColumn:"[data-action=\"report-add-column\"]",reportRemoveColumn:"[data-action=\"report-remove-column\"]",reportAddCondition:"[data-action=\"report-add-condition\"]",reportRemoveCondition:"[data-action=\"report-remove-condition\"]",reportAddFilter:"[data-action=\"report-add-filter\"]",reportRemoveFilter:"[data-action=\"report-remove-filter\"]",reportToggleColumnSort:"[data-action=\"report-toggle-column-sorting\"]",reportToggleColumnSortDirection:"[data-action=\"report-toggle-sort-direction\"]",sidebarSearch:"[data-action=\"sidebar-search\"]",toggleEditPreview:"[data-action=\"toggle-edit-preview\"]"}};b.forReport=function(a){return"".concat(b.regions.report,"[data-report-id=\"").concat(a,"\"]")};a.default=b;return a.default});
|
||||
//# sourceMappingURL=selectors.min.js.map
|
||||
|
||||
@@ -1 +1 @@
|
||||
{"version":3,"sources":["../../src/local/selectors.js"],"names":["SELECTORS","regions","systemReport","filterButtonLabel","filtersForm","actions","reportActionPopup","forSystemReport","reportId"],"mappings":"oJA+BA,GAAMA,CAAAA,CAAS,CAAG,CACdC,OAAO,CAAE,CACLC,YAAY,CAAE,oDADT,CAELC,iBAAiB,CAAE,uCAFd,CAGLC,WAAW,CAAE,gCAHR,CADK,CAMdC,OAAO,CAAE,CACLC,iBAAiB,CAAE,uCADd,CANK,CAAlB,CAkBAN,CAAS,CAACO,eAAV,CAA4B,SAAAC,CAAQ,kBAAOR,CAAS,CAACC,OAAV,CAAkBC,YAAzB,6BAAwDM,CAAxD,QAApC,C,UAEeR,C","sourcesContent":["// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see <http://www.gnu.org/licenses/>.\n\n/**\n * Report builder selectors\n *\n * @module core_reportbuilder/local/selectors\n * @copyright 2021 Paul Holden <[email protected]>\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\n/**\n * Selectors for the Report builder subsystem\n *\n * @property {Object} regions\n * @property {String} regions.systemReport System report page region\n * @property {String} regions.filterButtonLabel Filters form toggle region\n * @property {String} regions.filtersForm Filters form page region\n */\nconst SELECTORS = {\n regions: {\n systemReport: '[data-region=\"core_reportbuilder/system-report\"]',\n filterButtonLabel: '[data-region=\"filter-button-label\"]',\n filtersForm: '[data-region=\"filters-form\"]',\n },\n actions: {\n reportActionPopup: '[data-action=\"report-action-popup\"]',\n }\n};\n\n/**\n * Selector for given report\n *\n * @method forSystemReport\n * @param {Number} reportId\n * @return {String}\n */\nSELECTORS.forSystemReport = reportId => `${SELECTORS.regions.systemReport}[data-reportid=\"${reportId}\"]`;\n\nexport default SELECTORS;\n"],"file":"selectors.min.js"}
|
||||
{"version":3,"sources":["../../src/local/selectors.js"],"names":["SELECTORS","regions","report","reportTable","columnHeader","filterButtonLabel","filtersForm","sidebarMenu","sidebarCard","settingsConditions","activeConditions","activeCondition","settingsFilters","activeFilters","activeFilter","settingsSorting","actions","reportActionPopup","reportCreate","reportEdit","reportDelete","reportAddColumn","reportRemoveColumn","reportAddCondition","reportRemoveCondition","reportAddFilter","reportRemoveFilter","reportToggleColumnSort","reportToggleColumnSortDirection","sidebarSearch","toggleEditPreview","forReport","reportId"],"mappings":"oJA+BA,GAAMA,CAAAA,CAAS,CAAG,CACdC,OAAO,CAAE,CACLC,MAAM,CAAE,6CADH,CAELC,WAAW,CAAE,uCAFR,CAGLC,YAAY,CAAE,iCAHT,CAILC,iBAAiB,CAAE,uCAJd,CAKLC,WAAW,CAAE,gCALR,CAMLC,WAAW,CAAE,gCANR,CAOLC,WAAW,CAAE,gCAPR,CAQLC,kBAAkB,CAAE,uCARf,CASLC,gBAAgB,CAAE,qCATb,CAULC,eAAe,CAAE,oCAVZ,CAWLC,eAAe,CAAE,oCAXZ,CAYLC,aAAa,CAAE,kCAZV,CAaLC,YAAY,CAAE,iCAbT,CAcLC,eAAe,CAAE,oCAdZ,CADK,CAiBdC,OAAO,CAAE,CACLC,iBAAiB,CAAE,uCADd,CAELC,YAAY,CAAE,iCAFT,CAGLC,UAAU,CAAE,+BAHP,CAILC,YAAY,CAAE,iCAJT,CAKLC,eAAe,CAAE,qCALZ,CAMLC,kBAAkB,CAAE,wCANf,CAOLC,kBAAkB,CAAE,wCAPf,CAQLC,qBAAqB,CAAE,2CARlB,CASLC,eAAe,CAAE,qCATZ,CAULC,kBAAkB,CAAE,wCAVf,CAWLC,sBAAsB,CAAE,gDAXnB,CAYLC,+BAA+B,CAAE,gDAZ5B,CAaLC,aAAa,CAAE,kCAbV,CAcLC,iBAAiB,CAAE,uCAdd,CAjBK,CAAlB,CA0CA9B,CAAS,CAAC+B,SAAV,CAAsB,SAAAC,CAAQ,kBAAOhC,CAAS,CAACC,OAAV,CAAkBC,MAAzB,8BAAmD8B,CAAnD,QAA9B,C,UAEehC,C","sourcesContent":["// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see <http://www.gnu.org/licenses/>.\n\n/**\n * Report builder selectors\n *\n * @module core_reportbuilder/local/selectors\n * @copyright 2021 Paul Holden <[email protected]>\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\n/**\n * Selectors for the Report builder subsystem\n *\n * @property {Object} regions\n * @property {String} regions.systemReport System report page region\n * @property {String} regions.filterButtonLabel Filters form toggle region\n * @property {String} regions.filtersForm Filters form page region\n */\nconst SELECTORS = {\n regions: {\n report: '[data-region=\"core_reportbuilder/report\"]',\n reportTable: '[data-region=\"reportbuilder-table\"]',\n columnHeader: '[data-region=\"column-header\"]',\n filterButtonLabel: '[data-region=\"filter-button-label\"]',\n filtersForm: '[data-region=\"filters-form\"]',\n sidebarMenu: '[data-region=\"sidebar-menu\"]',\n sidebarCard: '[data-region=\"sidebar-card\"]',\n settingsConditions: '[data-region=\"settings-conditions\"]',\n activeConditions: '[data-region=\"active-conditions\"]',\n activeCondition: '[data-region=\"active-condition\"]',\n settingsFilters: '[data-region=\"settings-filters\"]',\n activeFilters: '[data-region=\"active-filters\"]',\n activeFilter: '[data-region=\"active-filter\"]',\n settingsSorting: '[data-region=\"settings-sorting\"]',\n },\n actions: {\n reportActionPopup: '[data-action=\"report-action-popup\"]',\n reportCreate: '[data-action=\"report-create\"]',\n reportEdit: '[data-action=\"report-edit\"]',\n reportDelete: '[data-action=\"report-delete\"]',\n reportAddColumn: '[data-action=\"report-add-column\"]',\n reportRemoveColumn: '[data-action=\"report-remove-column\"]',\n reportAddCondition: '[data-action=\"report-add-condition\"]',\n reportRemoveCondition: '[data-action=\"report-remove-condition\"]',\n reportAddFilter: '[data-action=\"report-add-filter\"]',\n reportRemoveFilter: '[data-action=\"report-remove-filter\"]',\n reportToggleColumnSort: '[data-action=\"report-toggle-column-sorting\"]',\n reportToggleColumnSortDirection: '[data-action=\"report-toggle-sort-direction\"]',\n sidebarSearch: '[data-action=\"sidebar-search\"]',\n toggleEditPreview: '[data-action=\"toggle-edit-preview\"]',\n },\n};\n\n/**\n * Selector for given report\n *\n * @method forReport\n * @param {Number} reportId\n * @return {String}\n */\nSELECTORS.forReport = reportId => `${SELECTORS.regions.report}[data-report-id=\"${reportId}\"]`;\n\nexport default SELECTORS;\n"],"file":"selectors.min.js"}
|
||||
+1
-1
@@ -1,2 +1,2 @@
|
||||
function _typeof(a){"@babel/helpers - typeof";if("function"==typeof Symbol&&"symbol"==typeof Symbol.iterator){_typeof=function(a){return typeof a}}else{_typeof=function(a){return a&&"function"==typeof Symbol&&a.constructor===Symbol&&a!==Symbol.prototype?"symbol":typeof a}}return _typeof(a)}define ("core_reportbuilder/report",["exports","core_reportbuilder/local/events","core_reportbuilder/local/selectors","core_table/dynamic","core_table/local/dynamic/selectors"],function(a,b,c,d,e){"use strict";Object.defineProperty(a,"__esModule",{value:!0});a.init=void 0;b=g(b);c=g(c);e=g(e);function f(){if("function"!=typeof WeakMap)return null;var a=new WeakMap;f=function(){return a};return a}function g(a){if(a&&a.__esModule){return a}if(null===a||"object"!==_typeof(a)&&"function"!=typeof a){return{default:a}}var b=f();if(b&&b.has(a)){return b.get(a)}var c={},d=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var e in a){if(Object.prototype.hasOwnProperty.call(a,e)){var g=d?Object.getOwnPropertyDescriptor(a,e):null;if(g&&(g.get||g.set)){Object.defineProperty(c,e,g)}else{c[e]=a[e]}}}c.default=a;if(b){b.set(a,c)}return c}function h(a,b,c,d,e,f,g){try{var h=a[f](g),i=h.value}catch(a){c(a);return}if(h.done){b(i)}else{Promise.resolve(i).then(d,e)}}function i(a){return function(){var b=this,c=arguments;return new Promise(function(d,e){var i=a.apply(b,c);function f(a){h(i,d,e,f,g,"next",a)}function g(a){h(i,d,e,f,g,"throw",a)}f(void 0)})}}var j=function(a){document.addEventListener(b.tableReload,function(){var b=i(regeneratorRuntime.mark(function b(f){var g,h,i,j;return regeneratorRuntime.wrap(function(b){while(1){switch(b.prev=b.next){case 0:h=f.target.closest(c.forSystemReport(a));if(!(null===h)){b.next=3;break}return b.abrupt("return");case 3:i=h.querySelector(e.main.region);j=(null===(g=f.detail)||void 0===g?void 0:g.preservePagination)?null:1;b.next=7;return(0,d.setPageNumber)(i,j,!1).then(d.refreshTableContent);case 7:case"end":return b.stop();}}},b)}));return function(){return b.apply(this,arguments)}}());document.addEventListener("click",function(a){var b=a.target.closest(c.actions.reportActionPopup);if(null===b){return}a.preventDefault();var d=JSON.parse(b.dataset.popupAction);window.openpopup(a,d.jsfunctionargs)})};a.init=j});
|
||||
function _typeof(a){"@babel/helpers - typeof";if("function"==typeof Symbol&&"symbol"==typeof Symbol.iterator){_typeof=function(a){return typeof a}}else{_typeof=function(a){return a&&"function"==typeof Symbol&&a.constructor===Symbol&&a!==Symbol.prototype?"symbol":typeof a}}return _typeof(a)}define ("core_reportbuilder/report",["exports","core_reportbuilder/local/events","core_reportbuilder/local/selectors","core_table/dynamic","core_table/local/dynamic/selectors"],function(a,b,c,d,e){"use strict";Object.defineProperty(a,"__esModule",{value:!0});a.init=void 0;b=g(b);c=g(c);e=g(e);function f(){if("function"!=typeof WeakMap)return null;var a=new WeakMap;f=function(){return a};return a}function g(a){if(a&&a.__esModule){return a}if(null===a||"object"!==_typeof(a)&&"function"!=typeof a){return{default:a}}var b=f();if(b&&b.has(a)){return b.get(a)}var c={},d=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var e in a){if(Object.prototype.hasOwnProperty.call(a,e)){var g=d?Object.getOwnPropertyDescriptor(a,e):null;if(g&&(g.get||g.set)){Object.defineProperty(c,e,g)}else{c[e]=a[e]}}}c.default=a;if(b){b.set(a,c)}return c}function h(a,b,c,d,e,f,g){try{var h=a[f](g),i=h.value}catch(a){c(a);return}if(h.done){b(i)}else{Promise.resolve(i).then(d,e)}}function i(a){return function(){var b=this,c=arguments;return new Promise(function(d,e){var i=a.apply(b,c);function f(a){h(i,d,e,f,g,"next",a)}function g(a){h(i,d,e,f,g,"throw",a)}f(void 0)})}}var j=!1,k=function(){if(j){return}document.addEventListener(b.tableReload,function(){var a=i(regeneratorRuntime.mark(function a(b){var f,g,h,i;return regeneratorRuntime.wrap(function(a){while(1){switch(a.prev=a.next){case 0:g=b.target.closest(c.regions.report);if(!(null===g)){a.next=3;break}return a.abrupt("return");case 3:h=g.querySelector(e.main.region);i=(null===(f=b.detail)||void 0===f?void 0:f.preservePagination)?null:1;a.next=7;return(0,d.setPageNumber)(h,i,!1).then(d.refreshTableContent);case 7:case"end":return a.stop();}}},a)}));return function(){return a.apply(this,arguments)}}());document.addEventListener("click",function(a){var b=a.target.closest(c.actions.reportActionPopup);if(null===b){return}a.preventDefault();var d=JSON.parse(b.dataset.popupAction);window.openpopup(a,d.jsfunctionargs)});j=!0};a.init=k});
|
||||
//# sourceMappingURL=report.min.js.map
|
||||
|
||||
@@ -1 +1 @@
|
||||
{"version":3,"sources":["../src/report.js"],"names":["init","reportId","document","addEventListener","reportEvents","tableReload","event","triggerElement","target","closest","reportSelectors","forSystemReport","tableRoot","querySelector","tableSelectors","main","region","pageNumber","detail","preservePagination","then","refreshTableContent","reportActionPopup","actions","preventDefault","popupAction","JSON","parse","dataset","window","openpopup","jsfunctionargs"],"mappings":"ojBAuBA,OACA,OAEA,O,q2BAQO,GAAMA,CAAAA,CAAI,CAAG,SAAAC,CAAQ,CAAI,CAE5BC,QAAQ,CAACC,gBAAT,CAA0BC,CAAY,CAACC,WAAvC,4CAAoD,WAAMC,CAAN,+FAC1CC,CAD0C,CACzBD,CAAK,CAACE,MAAN,CAAaC,OAAb,CAAqBC,CAAe,CAACC,eAAhB,CAAgCV,CAAhC,CAArB,CADyB,MAEzB,IAAnB,GAAAM,CAF4C,mDAM1CK,CAN0C,CAM9BL,CAAc,CAACM,aAAf,CAA6BC,CAAc,CAACC,IAAf,CAAoBC,MAAjD,CAN8B,CAO1CC,CAP0C,CAO7B,WAAAX,CAAK,CAACY,MAAN,uBAAcC,kBAAd,EAAmC,IAAnC,CAA0C,CAPb,gBAS1C,oBAAcP,CAAd,CAAyBK,CAAzB,KACDG,IADC,CACIC,qBADJ,CAT0C,yCAApD,yDAcAnB,QAAQ,CAACC,gBAAT,CAA0B,OAA1B,CAAmC,SAAAG,CAAK,CAAI,CACxC,GAAMgB,CAAAA,CAAiB,CAAGhB,CAAK,CAACE,MAAN,CAAaC,OAAb,CAAqBC,CAAe,CAACa,OAAhB,CAAwBD,iBAA7C,CAA1B,CACA,GAA0B,IAAtB,GAAAA,CAAJ,CAAgC,CAC5B,MACH,CACDhB,CAAK,CAACkB,cAAN,GACA,GAAMC,CAAAA,CAAW,CAAGC,IAAI,CAACC,KAAL,CAAWL,CAAiB,CAACM,OAAlB,CAA0BH,WAArC,CAApB,CACAI,MAAM,CAACC,SAAP,CAAiBxB,CAAjB,CAAwBmB,CAAW,CAACM,cAApC,CACH,CARD,CASH,CAzBM,C","sourcesContent":["// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see <http://www.gnu.org/licenses/>.\n\n/**\n * Report builder report management\n *\n * @module core_reportbuilder/report\n * @copyright 2021 Paul Holden <[email protected]>\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nimport * as reportEvents from 'core_reportbuilder/local/events';\nimport * as reportSelectors from 'core_reportbuilder/local/selectors';\nimport {setPageNumber, refreshTableContent} from 'core_table/dynamic';\nimport * as tableSelectors from 'core_table/local/dynamic/selectors';\n\n/**\n * Initialise module for given report\n *\n * @method\n * @param {Number} reportId\n */\nexport const init = reportId => {\n // Listen for the table reload event.\n document.addEventListener(reportEvents.tableReload, async(event) => {\n const triggerElement = event.target.closest(reportSelectors.forSystemReport(reportId));\n if (triggerElement === null) {\n return;\n }\n\n const tableRoot = triggerElement.querySelector(tableSelectors.main.region);\n const pageNumber = event.detail?.preservePagination ? null : 1;\n\n await setPageNumber(tableRoot, pageNumber, false)\n .then(refreshTableContent);\n });\n\n // Listen for trigger popup events.\n document.addEventListener('click', event => {\n const reportActionPopup = event.target.closest(reportSelectors.actions.reportActionPopup);\n if (reportActionPopup === null) {\n return;\n }\n event.preventDefault();\n const popupAction = JSON.parse(reportActionPopup.dataset.popupAction);\n window.openpopup(event, popupAction.jsfunctionargs);\n });\n};\n"],"file":"report.min.js"}
|
||||
{"version":3,"sources":["../src/report.js"],"names":["initialized","init","document","addEventListener","reportEvents","tableReload","event","reportElement","target","closest","reportSelectors","regions","report","tableRoot","querySelector","tableSelectors","main","region","pageNumber","detail","preservePagination","then","refreshTableContent","reportActionPopup","actions","preventDefault","popupAction","JSON","parse","dataset","window","openpopup","jsfunctionargs"],"mappings":"ojBAuBA,OACA,OAEA,O,w2BAEIA,CAAAA,CAAW,G,CAOFC,CAAI,CAAG,UAAM,CAEtB,GAAID,CAAJ,CAAiB,CAEb,MACH,CAGDE,QAAQ,CAACC,gBAAT,CAA0BC,CAAY,CAACC,WAAvC,4CAAoD,WAAMC,CAAN,+FAC1CC,CAD0C,CAC1BD,CAAK,CAACE,MAAN,CAAaC,OAAb,CAAqBC,CAAe,CAACC,OAAhB,CAAwBC,MAA7C,CAD0B,MAE1B,IAAlB,GAAAL,CAF4C,mDAM1CM,CAN0C,CAM9BN,CAAa,CAACO,aAAd,CAA4BC,CAAc,CAACC,IAAf,CAAoBC,MAAhD,CAN8B,CAO1CC,CAP0C,CAO7B,WAAAZ,CAAK,CAACa,MAAN,uBAAcC,kBAAd,EAAmC,IAAnC,CAA0C,CAPb,gBAS1C,oBAAcP,CAAd,CAAyBK,CAAzB,KACDG,IADC,CACIC,qBADJ,CAT0C,yCAApD,yDAcApB,QAAQ,CAACC,gBAAT,CAA0B,OAA1B,CAAmC,SAAAG,CAAK,CAAI,CACxC,GAAMiB,CAAAA,CAAiB,CAAGjB,CAAK,CAACE,MAAN,CAAaC,OAAb,CAAqBC,CAAe,CAACc,OAAhB,CAAwBD,iBAA7C,CAA1B,CACA,GAA0B,IAAtB,GAAAA,CAAJ,CAAgC,CAC5B,MACH,CACDjB,CAAK,CAACmB,cAAN,GACA,GAAMC,CAAAA,CAAW,CAAGC,IAAI,CAACC,KAAL,CAAWL,CAAiB,CAACM,OAAlB,CAA0BH,WAArC,CAApB,CACAI,MAAM,CAACC,SAAP,CAAiBzB,CAAjB,CAAwBoB,CAAW,CAACM,cAApC,CACH,CARD,EAUAhC,CAAW,GACd,C","sourcesContent":["// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see <http://www.gnu.org/licenses/>.\n\n/**\n * Report builder report management\n *\n * @module core_reportbuilder/report\n * @copyright 2021 Paul Holden <[email protected]>\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nimport * as reportEvents from 'core_reportbuilder/local/events';\nimport * as reportSelectors from 'core_reportbuilder/local/selectors';\nimport {setPageNumber, refreshTableContent} from 'core_table/dynamic';\nimport * as tableSelectors from 'core_table/local/dynamic/selectors';\n\nlet initialized = false;\n\n/**\n * Initialise module for given report\n *\n * @method\n */\nexport const init = () => {\n\n if (initialized) {\n // We already added the event listeners (can be called multiple times by mustache template).\n return;\n }\n\n // Listen for the table reload event.\n document.addEventListener(reportEvents.tableReload, async(event) => {\n const reportElement = event.target.closest(reportSelectors.regions.report);\n if (reportElement === null) {\n return;\n }\n\n const tableRoot = reportElement.querySelector(tableSelectors.main.region);\n const pageNumber = event.detail?.preservePagination ? null : 1;\n\n await setPageNumber(tableRoot, pageNumber, false)\n .then(refreshTableContent);\n });\n\n // Listen for trigger popup events.\n document.addEventListener('click', event => {\n const reportActionPopup = event.target.closest(reportSelectors.actions.reportActionPopup);\n if (reportActionPopup === null) {\n return;\n }\n event.preventDefault();\n const popupAction = JSON.parse(reportActionPopup.dataset.popupAction);\n window.openpopup(event, popupAction.jsfunctionargs);\n });\n\n initialized = true;\n};\n"],"file":"report.min.js"}
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
function _typeof(a){"@babel/helpers - typeof";if("function"==typeof Symbol&&"symbol"==typeof Symbol.iterator){_typeof=function(a){return typeof a}}else{_typeof=function(a){return a&&"function"==typeof Symbol&&a.constructor===Symbol&&a!==Symbol.prototype?"symbol":typeof a}}return _typeof(a)}define ("core_reportbuilder/reports_list",["exports","core/event_dispatcher","core/notification","core/pending","core/str","core/toast","core_reportbuilder/local/events","core_reportbuilder/local/selectors","core_reportbuilder/local/repository/reports","core_reportbuilder/local/repository/modals"],function(a,b,c,d,e,f,g,h,i,j){"use strict";Object.defineProperty(a,"__esModule",{value:!0});a.init=void 0;c=m(c);d=m(d);g=l(g);h=l(h);function k(){if("function"!=typeof WeakMap)return null;var a=new WeakMap;k=function(){return a};return a}function l(a){if(a&&a.__esModule){return a}if(null===a||"object"!==_typeof(a)&&"function"!=typeof a){return{default:a}}var b=k();if(b&&b.has(a)){return b.get(a)}var c={},d=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var e in a){if(Object.prototype.hasOwnProperty.call(a,e)){var f=d?Object.getOwnPropertyDescriptor(a,e):null;if(f&&(f.get||f.set)){Object.defineProperty(c,e,f)}else{c[e]=a[e]}}}c.default=a;if(b){b.set(a,c)}return c}function m(a){return a&&a.__esModule?a:{default:a}}function n(a,b){return s(a)||r(a,b)||p(a,b)||o()}function o(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function p(a,b){if(!a)return;if("string"==typeof a)return q(a,b);var c=Object.prototype.toString.call(a).slice(8,-1);if("Object"===c&&a.constructor)c=a.constructor.name;if("Map"===c||"Set"===c)return Array.from(c);if("Arguments"===c||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(c))return q(a,b)}function q(a,b){if(null==b||b>a.length)b=a.length;for(var c=0,d=Array(b);c<b;c++){d[c]=a[c]}return d}function r(a,b){if("undefined"==typeof Symbol||!(Symbol.iterator in Object(a)))return;var c=[],d=!0,e=!1,f=void 0;try{for(var g=a[Symbol.iterator](),h;!(d=(h=g.next()).done);d=!0){c.push(h.value);if(b&&c.length===b)break}}catch(a){e=!0;f=a}finally{try{if(!d&&null!=g["return"])g["return"]()}finally{if(e)throw f}}return c}function s(a){if(Array.isArray(a))return a}a.init=function init(){document.addEventListener("click",function(a){var k=a.target.closest(h.actions.reportCreate);if(k){a.preventDefault();var o=(0,j.createReportModal)(a.target,(0,e.get_string)("newreport","core_reportbuilder"));o.addEventListener(o.events.FORM_SUBMITTED,function(a){window.location.href=a.detail});o.show()}var l=a.target.closest(h.actions.reportEdit);if(l){a.preventDefault();var p=(0,j.createReportModal)(a.target,(0,e.get_string)("editreportdetails","core_reportbuilder"),l.dataset.reportId);p.addEventListener(p.events.FORM_SUBMITTED,function(){var d=a.target.closest(h.regions.report);(0,e.get_string)("reportupdated","core_reportbuilder").then(f.add).then(function(){(0,b.dispatchEvent)(g.tableReload,{preservePagination:!0},d)}).catch(c.default.exception)});p.show()}var m=a.target.closest(h.actions.reportDelete);if(m){a.preventDefault();(0,e.get_strings)([{key:"deletereport",component:"core_reportbuilder"},{key:"deletereportconfirm",component:"core_reportbuilder",param:m.dataset.reportName},{key:"delete",component:"moodle"}]).then(function(j){var k=n(j,3),l=k[0],o=k[1],p=k[2];c.default.confirm(l,o,p,null,function(){var j=new d.default("core_reportbuilder/reports:delete"),k=a.target.closest(h.regions.report);(0,i.deleteReport)(m.dataset.reportId).then(function(){return(0,e.get_string)("reportdeleted","core_reportbuilder")}).then(f.add).then(function(){j.resolve();(0,b.dispatchEvent)(g.tableReload,{preservePagination:!0},k)}).catch(c.default.exception)})}).catch(c.default.exception)}})}});
|
||||
//# sourceMappingURL=reports_list.min.js.map
|
||||
File diff suppressed because one or more lines are too long
+2
@@ -0,0 +1,2 @@
|
||||
function _typeof(a){"@babel/helpers - typeof";if("function"==typeof Symbol&&"symbol"==typeof Symbol.iterator){_typeof=function(a){return typeof a}}else{_typeof=function(a){return a&&"function"==typeof Symbol&&a.constructor===Symbol&&a!==Symbol.prototype?"symbol":typeof a}}return _typeof(a)}define ("core_reportbuilder/sidebar",["exports","core/pending","core/utils","core_reportbuilder/local/selectors"],function(a,b,c,d){"use strict";Object.defineProperty(a,"__esModule",{value:!0});a.init=void 0;b=function(a){return a&&a.__esModule?a:{default:a}}(b);d=f(d);function e(){if("function"!=typeof WeakMap)return null;var a=new WeakMap;e=function(){return a};return a}function f(a){if(a&&a.__esModule){return a}if(null===a||"object"!==_typeof(a)&&"function"!=typeof a){return{default:a}}var b=e();if(b&&b.has(a)){return b.get(a)}var c={},d=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var f in a){if(Object.prototype.hasOwnProperty.call(a,f)){var g=d?Object.getOwnPropertyDescriptor(a,f):null;if(g&&(g.get||g.set)){Object.defineProperty(c,f,g)}else{c[f]=a[f]}}}c.default=a;if(b){b.set(a,c)}return c}var g={EXPANDED:"show",COLLAPSED:"collapsed",SHOW:"d-flex",HIDE:"d-none"},h=function(a,c){var e=new b.default("core_reportbuilder/sidebar:cardFilter"),f=c.querySelectorAll(d.regions.sidebarCard),h=c.querySelectorAll(".list-group-item"),j=a.target.value.toLowerCase();h.forEach(function(a){var b=a.dataset.name.toLowerCase();if(b.includes(j)){a.classList.replace(g.HIDE,g.SHOW)}else{a.classList.replace(g.SHOW,g.HIDE)}});f.forEach(function(a){if(0<a.querySelectorAll(".".concat(g.SHOW)).length){a.classList.remove(g.HIDE);i(a)}else{a.classList.add(g.HIDE)}});e.resolve()},i=function(a){var b=a.querySelector("[data-toggle=\"collapse\"]");if(b.classList.contains(g.COLLAPSED)){b.classList.remove(g.COLLAPSED);b.setAttribute("aria-expanded","true");var c=a.querySelector(b.dataset.target);c.classList.add(g.EXPANDED)}},j=function(){var a=document.querySelector(d.regions.sidebarMenu),e=a.querySelector(d.actions.sidebarSearch);e.addEventListener("keyup",function(d){var e=new b.default("core_reportbuilder/sidebar:keyup");(0,c.debounce)(h,250)(d,a);setTimeout(function(){e.resolve()},250)})};a.init=j});
|
||||
//# sourceMappingURL=sidebar.min.js.map
|
||||
File diff suppressed because one or more lines are too long
@@ -0,0 +1,83 @@
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Report builder editor
|
||||
*
|
||||
* @module core_reportbuilder/editor
|
||||
* @package core_reportbuilder
|
||||
* @copyright 2021 David Matamoros <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
import 'core/inplace_editable';
|
||||
import Notification from 'core/notification';
|
||||
import Pending from 'core/pending';
|
||||
import Templates from 'core/templates';
|
||||
import * as reportSelectors from 'core_reportbuilder/local/selectors';
|
||||
import {init as columnsEditorInit} from 'core_reportbuilder/local/editor/columns';
|
||||
import {init as conditionsEditorInit} from 'core_reportbuilder/local/editor/conditions';
|
||||
import {init as filtersEditorInit} from 'core_reportbuilder/local/editor/filters';
|
||||
import {init as sortingEditorInit} from 'core_reportbuilder/local/editor/sorting';
|
||||
import {getReport} from 'core_reportbuilder/local/repository/reports';
|
||||
|
||||
let initialized = false;
|
||||
|
||||
/**
|
||||
* Initialise editor and all it's modules
|
||||
*/
|
||||
export const init = () => {
|
||||
const reportElement = document.querySelector(reportSelectors.regions.report);
|
||||
|
||||
columnsEditorInit(reportElement, initialized);
|
||||
conditionsEditorInit(reportElement, initialized);
|
||||
filtersEditorInit(reportElement, initialized);
|
||||
sortingEditorInit(reportElement, initialized);
|
||||
|
||||
// Ensure we only add our listeners once (can be called multiple times by mustache template).
|
||||
if (initialized) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Add event handlers to generic report editor elements.
|
||||
document.addEventListener('click', event => {
|
||||
|
||||
// Toggle between edit and preview mode.
|
||||
const toggleEditViewMode = event.target.closest(reportSelectors.actions.toggleEditPreview);
|
||||
if (toggleEditViewMode) {
|
||||
event.preventDefault();
|
||||
|
||||
const pendingPromise = new Pending('core_reportbuilder/reports:get');
|
||||
const toggledEditMode = toggleEditViewMode.dataset.editMode !== "1";
|
||||
|
||||
let customjs = '';
|
||||
|
||||
getReport(reportElement.dataset.reportId, toggledEditMode)
|
||||
.then(response => {
|
||||
customjs = response.javascript;
|
||||
return Templates.render('core_reportbuilder/custom_report', response);
|
||||
})
|
||||
.then((html, js) => {
|
||||
return Templates.replaceNodeContents(reportElement, html, js + customjs);
|
||||
})
|
||||
.then(() => pendingPromise.resolve())
|
||||
.catch(Notification.exception);
|
||||
}
|
||||
});
|
||||
|
||||
initialized = true;
|
||||
};
|
||||
@@ -31,7 +31,7 @@ import {add as addToast} from 'core/toast';
|
||||
import DynamicForm from 'core_form/dynamicform';
|
||||
import * as reportEvents from 'core_reportbuilder/local/events';
|
||||
import * as reportSelectors from 'core_reportbuilder/local/selectors';
|
||||
import {reset as resetFilters} from 'core_reportbuilder/local/repository/filters';
|
||||
import {resetFilters} from 'core_reportbuilder/local/repository/filters';
|
||||
|
||||
/**
|
||||
* Update filter button text to indicate applied filter count
|
||||
@@ -57,7 +57,7 @@ const setFilterButtonCount = async(reportElement, filterCount) => {
|
||||
* @param {Number} contextId
|
||||
*/
|
||||
export const init = (reportId, contextId) => {
|
||||
const reportElement = document.querySelector(reportSelectors.forSystemReport(reportId));
|
||||
const reportElement = document.querySelector(reportSelectors.forReport(reportId));
|
||||
const filterFormContainer = reportElement.querySelector(reportSelectors.regions.filtersForm);
|
||||
const filterForm = new DynamicForm(filterFormContainer, '\\core_reportbuilder\\form\\filter');
|
||||
|
||||
|
||||
@@ -0,0 +1,163 @@
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Report builder columns editor
|
||||
*
|
||||
* @module core_reportbuilder/local/editor/columns
|
||||
* @package core_reportbuilder
|
||||
* @copyright 2021 Paul Holden <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
import $ from 'jquery';
|
||||
import {dispatchEvent} from 'core/event_dispatcher';
|
||||
import 'core/inplace_editable';
|
||||
import {eventTypes as inplaceEditableEvents} from 'core/local/inplace_editable/events';
|
||||
import Notification from 'core/notification';
|
||||
import Pending from 'core/pending';
|
||||
import {publish} from 'core/pubsub';
|
||||
import SortableList from 'core/sortable_list';
|
||||
import {get_string as getString, get_strings as getStrings} from 'core/str';
|
||||
import {add as addToast} from 'core/toast';
|
||||
import * as reportEvents from 'core_reportbuilder/local/events';
|
||||
import * as reportSelectors from 'core_reportbuilder/local/selectors';
|
||||
import {addColumn, deleteColumn, reorderColumn} from 'core_reportbuilder/local/repository/columns';
|
||||
|
||||
/**
|
||||
* Initialise module
|
||||
*
|
||||
* @param {Element} reportElement
|
||||
* @param {Boolean} initialized Ensure we only add our listeners once
|
||||
*/
|
||||
export const init = (reportElement, initialized) => {
|
||||
if (initialized) {
|
||||
return;
|
||||
}
|
||||
|
||||
reportElement.addEventListener('click', event => {
|
||||
|
||||
// Add column to report.
|
||||
const reportAddColumn = event.target.closest(reportSelectors.actions.reportAddColumn);
|
||||
if (reportAddColumn) {
|
||||
event.preventDefault();
|
||||
|
||||
const pendingPromise = new Pending('core_reportbuilder/columns:add');
|
||||
|
||||
addColumn(reportElement.dataset.reportId, reportAddColumn.dataset.uniqueIdentifier)
|
||||
.then(data => publish(reportEvents.publish.reportColumnsUpdated, data))
|
||||
.then(() => getString('columnadded', 'core_reportbuilder', reportAddColumn.dataset.name))
|
||||
.then(addToast)
|
||||
.then(() => {
|
||||
dispatchEvent(reportEvents.tableReload, {preservePagination: true}, reportElement);
|
||||
return pendingPromise.resolve();
|
||||
})
|
||||
.catch(Notification.exception);
|
||||
}
|
||||
|
||||
// Remove column from report.
|
||||
const reportRemoveColumn = event.target.closest(reportSelectors.actions.reportRemoveColumn);
|
||||
if (reportRemoveColumn) {
|
||||
event.preventDefault();
|
||||
|
||||
const columnHeader = reportRemoveColumn.closest(reportSelectors.regions.columnHeader);
|
||||
const columnName = columnHeader.dataset.columnName;
|
||||
|
||||
getStrings([
|
||||
{key: 'deletecolumn', component: 'core_reportbuilder', param: columnName},
|
||||
{key: 'deletecolumnconfirm', component: 'core_reportbuilder', param: columnName},
|
||||
{key: 'delete', component: 'moodle'},
|
||||
]).then(([confirmTitle, confirmText, confirmButton]) => {
|
||||
Notification.confirm(confirmTitle, confirmText, confirmButton, null, () => {
|
||||
const pendingPromise = new Pending('core_reportbuilder/columns:remove');
|
||||
|
||||
deleteColumn(reportElement.dataset.reportId, columnHeader.dataset.columnId)
|
||||
.then(data => publish(reportEvents.publish.reportColumnsUpdated, data))
|
||||
.then(() => getString('columndeleted', 'core_reportbuilder', columnName))
|
||||
.then(addToast)
|
||||
.then(() => {
|
||||
dispatchEvent(reportEvents.tableReload, {preservePagination: true}, reportElement);
|
||||
return pendingPromise.resolve();
|
||||
})
|
||||
.catch(Notification.exception);
|
||||
});
|
||||
return;
|
||||
}).catch(Notification.exception);
|
||||
}
|
||||
});
|
||||
|
||||
// Initialize sortable list to handle column moving (note JQuery dependency, see MDL-72293 for resolution).
|
||||
var columnSortableList = new SortableList(`${reportSelectors.regions.reportTable} thead tr`, {isHorizontal: true});
|
||||
columnSortableList.getElementName = element => Promise.resolve(element.data('columnName'));
|
||||
|
||||
$(reportElement).on(SortableList.EVENTS.DRAG, 'th[data-column-id]', (event, info) => {
|
||||
const columnPosition = info.element.data('columnPosition');
|
||||
const targetColumnPosition = info.targetNextElement.data('columnPosition');
|
||||
|
||||
$(reportElement).find('tbody tr').each(function() {
|
||||
const cell = $(this).children(`td.c${columnPosition - 1}`)[0];
|
||||
if (targetColumnPosition) {
|
||||
var beforeCell = $(this).children(`td.c${targetColumnPosition - 1}`)[0];
|
||||
this.insertBefore(cell, beforeCell);
|
||||
} else {
|
||||
this.appendChild(cell);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
$(reportElement).on(SortableList.EVENTS.DROP, 'th[data-column-id]', (event, info) => {
|
||||
if (info.positionChanged) {
|
||||
const pendingPromise = new Pending('core_reportbuilder/columns:reorder');
|
||||
|
||||
const columnId = info.element.data('columnId');
|
||||
const columnName = info.element.data('columnName');
|
||||
const columnPosition = info.element.data('columnPosition');
|
||||
|
||||
// Select target position, if moving to the end then count number of element siblings.
|
||||
let targetColumnPosition = info.targetNextElement.data('columnPosition') || info.element.siblings().length + 2;
|
||||
if (targetColumnPosition > columnPosition) {
|
||||
targetColumnPosition--;
|
||||
}
|
||||
|
||||
reorderColumn(reportElement.dataset.reportId, columnId, targetColumnPosition)
|
||||
.then(() => getString('columnmoved', 'core_reportbuilder', columnName))
|
||||
.then(addToast)
|
||||
.then(() => {
|
||||
dispatchEvent(reportEvents.tableReload, {preservePagination: true}, reportElement);
|
||||
return pendingPromise.resolve();
|
||||
})
|
||||
.catch(Notification.exception);
|
||||
}
|
||||
});
|
||||
|
||||
// Initialize inplace editable listeners for column aggregation.
|
||||
reportElement.addEventListener(inplaceEditableEvents.elementUpdated, event => {
|
||||
|
||||
const columnAggregation = event.target.closest('[data-itemtype="columnaggregation"]');
|
||||
if (columnAggregation) {
|
||||
const columnHeader = columnAggregation.closest(reportSelectors.regions.columnHeader);
|
||||
|
||||
getString('columnaggregated', 'core_reportbuilder', columnHeader.dataset.columnName)
|
||||
.then(addToast)
|
||||
.then(() => {
|
||||
dispatchEvent(reportEvents.tableReload, {}, reportElement);
|
||||
return;
|
||||
})
|
||||
.catch(Notification.exception);
|
||||
}
|
||||
});
|
||||
};
|
||||
@@ -0,0 +1,197 @@
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Report builder conditions editor
|
||||
*
|
||||
* @module core_reportbuilder/local/editor/conditions
|
||||
* @package core_reportbuilder
|
||||
* @copyright 2021 Paul Holden <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
import $ from 'jquery';
|
||||
import {dispatchEvent} from 'core/event_dispatcher';
|
||||
import 'core/inplace_editable';
|
||||
import Notification from 'core/notification';
|
||||
import Pending from 'core/pending';
|
||||
import SortableList from 'core/sortable_list';
|
||||
import {get_string as getString, get_strings as getStrings} from 'core/str';
|
||||
import Templates from 'core/templates';
|
||||
import {add as addToast} from 'core/toast';
|
||||
import DynamicForm from 'core_form/dynamicform';
|
||||
import * as reportEvents from 'core_reportbuilder/local/events';
|
||||
import * as reportSelectors from 'core_reportbuilder/local/selectors';
|
||||
import {addCondition, deleteCondition, reorderCondition, resetConditions} from 'core_reportbuilder/local/repository/conditions';
|
||||
|
||||
/**
|
||||
* Reload conditions settings region
|
||||
*
|
||||
* @param {Element} reportElement
|
||||
* @param {Object} templateContext
|
||||
* @return {Promise}
|
||||
*/
|
||||
const reloadSettingsConditionsRegion = (reportElement, templateContext) => {
|
||||
const pendingPromise = new Pending('core_reportbuilder/conditions:reload');
|
||||
const settingsConditionsRegion = reportElement.querySelector(reportSelectors.regions.settingsConditions);
|
||||
|
||||
return Templates.renderForPromise('core_reportbuilder/local/settings/conditions', {conditions: templateContext})
|
||||
.then(({html, js}) => {
|
||||
Templates.replaceNode(settingsConditionsRegion, html, js + templateContext.javascript);
|
||||
initConditionsForm(reportElement);
|
||||
return pendingPromise.resolve();
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Initialise conditions form, must be called on each init because the form container is re-created when switching editor modes
|
||||
*
|
||||
* @param {Element} reportElement
|
||||
*/
|
||||
const initConditionsForm = reportElement => {
|
||||
// Handle dynamic conditions form.
|
||||
const conditionFormContainer = reportElement.querySelector(reportSelectors.regions.settingsConditions);
|
||||
const conditionForm = new DynamicForm(conditionFormContainer, '\\core_reportbuilder\\form\\condition');
|
||||
|
||||
// Submit report conditions.
|
||||
conditionForm.addEventListener(conditionForm.events.FORM_SUBMITTED, event => {
|
||||
event.preventDefault();
|
||||
|
||||
getString('conditionsapplied', 'core_reportbuilder')
|
||||
.then(addToast)
|
||||
.catch(Notification.exception);
|
||||
|
||||
// After the form has been submitted, we should trigger report table reload.
|
||||
dispatchEvent(reportEvents.tableReload, {}, reportElement);
|
||||
});
|
||||
|
||||
// Reset report conditions.
|
||||
conditionForm.addEventListener(conditionForm.events.NOSUBMIT_BUTTON_PRESSED, event => {
|
||||
event.preventDefault();
|
||||
|
||||
const pendingPromise = new Pending('core_reportbuilder/conditions:reset');
|
||||
|
||||
resetConditions(reportElement.dataset.reportId)
|
||||
.then(data => reloadSettingsConditionsRegion(reportElement, data))
|
||||
.then(() => getString('conditionsreset', 'core_reportbuilder'))
|
||||
.then(addToast)
|
||||
.then(() => {
|
||||
dispatchEvent(reportEvents.tableReload, {}, reportElement);
|
||||
return pendingPromise.resolve();
|
||||
})
|
||||
.catch(Notification.exception);
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Initialise module
|
||||
*
|
||||
* @param {Element} reportElement
|
||||
* @param {Boolean} initialized Ensure we only add our listeners once
|
||||
*/
|
||||
export const init = (reportElement, initialized) => {
|
||||
initConditionsForm(reportElement);
|
||||
if (initialized) {
|
||||
return;
|
||||
}
|
||||
|
||||
reportElement.addEventListener('click', event => {
|
||||
|
||||
// Add condition to report.
|
||||
const reportAddCondition = event.target.closest(reportSelectors.actions.reportAddCondition);
|
||||
if (reportAddCondition) {
|
||||
event.preventDefault();
|
||||
|
||||
// Check if dropdown is closed with no condition selected.
|
||||
if (reportAddCondition.value === '0') {
|
||||
return;
|
||||
}
|
||||
|
||||
const pendingPromise = new Pending('core_reportbuilder/conditions:add');
|
||||
|
||||
addCondition(reportElement.dataset.reportId, reportAddCondition.value)
|
||||
.then(data => reloadSettingsConditionsRegion(reportElement, data))
|
||||
.then(() => getString('conditionadded', 'core_reportbuilder',
|
||||
reportAddCondition.options[reportAddCondition.selectedIndex].text))
|
||||
.then(addToast)
|
||||
.then(() => {
|
||||
dispatchEvent(reportEvents.tableReload, {}, reportElement);
|
||||
return pendingPromise.resolve();
|
||||
})
|
||||
.catch(Notification.exception);
|
||||
}
|
||||
|
||||
// Remove condition from report.
|
||||
const reportRemoveCondition = event.target.closest(reportSelectors.actions.reportRemoveCondition);
|
||||
if (reportRemoveCondition) {
|
||||
event.preventDefault();
|
||||
|
||||
const conditionContainer = reportRemoveCondition.closest(reportSelectors.regions.activeCondition);
|
||||
const conditionName = conditionContainer.dataset.conditionName;
|
||||
|
||||
getStrings([
|
||||
{key: 'deletecondition', component: 'core_reportbuilder', param: conditionName},
|
||||
{key: 'deleteconditionconfirm', component: 'core_reportbuilder', param: conditionName},
|
||||
{key: 'delete', component: 'moodle'},
|
||||
]).then(([confirmTitle, confirmText, confirmButton]) => {
|
||||
Notification.confirm(confirmTitle, confirmText, confirmButton, null, () => {
|
||||
const pendingPromise = new Pending('core_reportbuilder/conditions:remove');
|
||||
|
||||
deleteCondition(reportElement.dataset.reportId, conditionContainer.dataset.conditionId)
|
||||
.then(data => reloadSettingsConditionsRegion(reportElement, data))
|
||||
.then(() => getString('conditiondeleted', 'core_reportbuilder', conditionName))
|
||||
.then(addToast)
|
||||
.then(() => {
|
||||
dispatchEvent(reportEvents.tableReload, {}, reportElement);
|
||||
return pendingPromise.resolve();
|
||||
})
|
||||
.catch(Notification.exception);
|
||||
});
|
||||
return;
|
||||
}).catch(Notification.exception);
|
||||
}
|
||||
});
|
||||
|
||||
// Initialize sortable list to handle active conditions moving (note JQuery dependency, see MDL-72293 for resolution).
|
||||
var activeConditionsSortableList = new SortableList(`${reportSelectors.regions.activeConditions}`,
|
||||
{isHorizontal: false});
|
||||
activeConditionsSortableList.getElementName = element => Promise.resolve(element.data('conditionName'));
|
||||
|
||||
$(reportElement).on(SortableList.EVENTS.DROP, reportSelectors.regions.activeCondition, (event, info) => {
|
||||
if (info.positionChanged) {
|
||||
const pendingPromise = new Pending('core_reportbuilder/conditions:reorder');
|
||||
const conditionId = info.element.data('conditionId');
|
||||
const conditionPosition = info.element.data('conditionPosition');
|
||||
|
||||
// Select target position, if moving to the end then count number of element siblings.
|
||||
let targetConditionPosition = info.targetNextElement.data('conditionPosition') || info.element.siblings().length + 2;
|
||||
if (targetConditionPosition > conditionPosition) {
|
||||
targetConditionPosition--;
|
||||
}
|
||||
|
||||
reorderCondition(reportElement.dataset.reportId, conditionId, targetConditionPosition)
|
||||
.then(data => reloadSettingsConditionsRegion(reportElement, data))
|
||||
.then(() => getString('conditionmoved', 'core_reportbuilder', info.element.data('conditionName')))
|
||||
.then(addToast)
|
||||
.then(() => {
|
||||
dispatchEvent(reportEvents.tableReload, {}, reportElement);
|
||||
return pendingPromise.resolve();
|
||||
})
|
||||
.catch(Notification.exception);
|
||||
}
|
||||
});
|
||||
};
|
||||
@@ -0,0 +1,147 @@
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Report builder filters editor
|
||||
*
|
||||
* @module core_reportbuilder/local/editor/filters
|
||||
* @package core_reportbuilder
|
||||
* @copyright 2021 David Matamoros <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
import $ from 'jquery';
|
||||
import {dispatchEvent} from 'core/event_dispatcher';
|
||||
import 'core/inplace_editable';
|
||||
import Notification from 'core/notification';
|
||||
import Pending from 'core/pending';
|
||||
import SortableList from 'core/sortable_list';
|
||||
import {get_string as getString, get_strings as getStrings} from 'core/str';
|
||||
import Templates from 'core/templates';
|
||||
import {add as addToast} from 'core/toast';
|
||||
import * as reportEvents from 'core_reportbuilder/local/events';
|
||||
import * as reportSelectors from 'core_reportbuilder/local/selectors';
|
||||
import {addFilter, deleteFilter, reorderFilter} from 'core_reportbuilder/local/repository/filters';
|
||||
|
||||
/**
|
||||
* Reload filters settings region
|
||||
*
|
||||
* @param {Element} reportElement
|
||||
* @param {Object} templateContext
|
||||
* @return {Promise}
|
||||
*/
|
||||
const reloadSettingsFiltersRegion = (reportElement, templateContext) => {
|
||||
const pendingPromise = new Pending('core_reportbuilder/filters:reload');
|
||||
const settingsFiltersRegion = reportElement.querySelector(reportSelectors.regions.settingsFilters);
|
||||
|
||||
return Templates.renderForPromise('core_reportbuilder/local/settings/filters', {filters: templateContext})
|
||||
.then(({html, js}) => {
|
||||
Templates.replaceNode(settingsFiltersRegion, html, js);
|
||||
return pendingPromise.resolve();
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Initialise module
|
||||
*
|
||||
* @param {Element} reportElement
|
||||
* @param {Boolean} initialized Ensure we only add our listeners once
|
||||
*/
|
||||
export const init = (reportElement, initialized) => {
|
||||
if (initialized) {
|
||||
return;
|
||||
}
|
||||
|
||||
reportElement.addEventListener('click', event => {
|
||||
|
||||
// Add filter to report.
|
||||
const reportAddFilter = event.target.closest(reportSelectors.actions.reportAddFilter);
|
||||
if (reportAddFilter) {
|
||||
event.preventDefault();
|
||||
|
||||
// Check if dropdown is closed with no filter selected.
|
||||
if (reportAddFilter.value === '0') {
|
||||
return;
|
||||
}
|
||||
|
||||
const pendingPromise = new Pending('core_reportbuilder/filters:add');
|
||||
|
||||
addFilter(reportElement.dataset.reportId, reportAddFilter.value)
|
||||
.then(data => reloadSettingsFiltersRegion(reportElement, data))
|
||||
.then(() => getString('filteradded', 'core_reportbuilder',
|
||||
reportAddFilter.options[reportAddFilter.selectedIndex].text))
|
||||
.then(addToast)
|
||||
.then(() => pendingPromise.resolve())
|
||||
.catch(Notification.exception);
|
||||
}
|
||||
|
||||
// Remove filter from report.
|
||||
const reportRemoveFilter = event.target.closest(reportSelectors.actions.reportRemoveFilter);
|
||||
if (reportRemoveFilter) {
|
||||
event.preventDefault();
|
||||
|
||||
const filterContainer = reportRemoveFilter.closest(reportSelectors.regions.activeFilter);
|
||||
const filterName = filterContainer.dataset.filterName;
|
||||
|
||||
getStrings([
|
||||
{key: 'deletefilter', component: 'core_reportbuilder', param: filterName},
|
||||
{key: 'deletefilterconfirm', component: 'core_reportbuilder', param: filterName},
|
||||
{key: 'delete', component: 'moodle'},
|
||||
]).then(([confirmTitle, confirmText, confirmButton]) => {
|
||||
Notification.confirm(confirmTitle, confirmText, confirmButton, null, () => {
|
||||
const pendingPromise = new Pending('core_reportbuilder/filters:remove');
|
||||
|
||||
deleteFilter(reportElement.dataset.reportId, filterContainer.dataset.filterId)
|
||||
.then(data => reloadSettingsFiltersRegion(reportElement, data))
|
||||
.then(() => getString('filterdeleted', 'core_reportbuilder', filterName))
|
||||
.then(addToast)
|
||||
.then(() => {
|
||||
dispatchEvent(reportEvents.tableReload, {}, reportElement);
|
||||
return pendingPromise.resolve();
|
||||
})
|
||||
.catch(Notification.exception);
|
||||
});
|
||||
return;
|
||||
}).catch(Notification.exception);
|
||||
}
|
||||
});
|
||||
|
||||
// Initialize sortable list to handle active filters moving (note JQuery dependency, see MDL-72293 for resolution).
|
||||
var activeFiltersSortableList = new SortableList(`${reportSelectors.regions.activeFilters} ul`, {isHorizontal: false});
|
||||
activeFiltersSortableList.getElementName = element => Promise.resolve(element.data('filterName'));
|
||||
|
||||
$(reportElement).on(SortableList.EVENTS.DROP, 'li[data-filter-id]', (event, info) => {
|
||||
if (info.positionChanged) {
|
||||
const pendingPromise = new Pending('core_reportbuilder/filters:reorder');
|
||||
const filterId = info.element.data('filterId');
|
||||
const filterPosition = info.element.data('filterPosition');
|
||||
|
||||
// Select target position, if moving to the end then count number of element siblings.
|
||||
let targetFilterPosition = info.targetNextElement.data('filterPosition') || info.element.siblings().length + 2;
|
||||
if (targetFilterPosition > filterPosition) {
|
||||
targetFilterPosition--;
|
||||
}
|
||||
|
||||
reorderFilter(reportElement.dataset.reportId, filterId, targetFilterPosition)
|
||||
.then(data => reloadSettingsFiltersRegion(reportElement, data))
|
||||
.then(() => getString('filtermoved', 'core_reportbuilder', info.element.data('filterName')))
|
||||
.then(addToast)
|
||||
.then(() => pendingPromise.resolve())
|
||||
.catch(Notification.exception);
|
||||
}
|
||||
});
|
||||
};
|
||||
@@ -0,0 +1,170 @@
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Report builder columns sorting editor
|
||||
*
|
||||
* @module core_reportbuilder/local/editor/sorting
|
||||
* @package core_reportbuilder
|
||||
* @copyright 2021 David Matamoros <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
import $ from 'jquery';
|
||||
import 'core/inplace_editable';
|
||||
import Notification from 'core/notification';
|
||||
import Pending from 'core/pending';
|
||||
import {subscribe} from 'core/pubsub';
|
||||
import SortableList from 'core/sortable_list';
|
||||
import {get_string as getString} from 'core/str';
|
||||
import {add as addToast} from 'core/toast';
|
||||
import * as reportSelectors from 'core_reportbuilder/local/selectors';
|
||||
import {reorderColumnSorting, toggleColumnSorting} from 'core_reportbuilder/local/repository/sorting';
|
||||
import Templates from 'core/templates';
|
||||
import {dispatchEvent} from 'core/event_dispatcher';
|
||||
import * as reportEvents from 'core_reportbuilder/local/events';
|
||||
|
||||
// These constants match PHP consts SORT_ASC, SORT_DESC.
|
||||
const SORTORDER = {
|
||||
ASCENDING: 4,
|
||||
DESCENDING: 3,
|
||||
};
|
||||
|
||||
/**
|
||||
* Reload sorting settings region
|
||||
*
|
||||
* @param {Object} context
|
||||
* @return {Promise}
|
||||
*/
|
||||
const reloadSettingsSortingRegion = context => {
|
||||
const pendingPromise = new Pending('core_reportbuilder/sorting:reload');
|
||||
const settingsSortingRegion = document.querySelector(reportSelectors.regions.settingsSorting);
|
||||
|
||||
return Templates.renderForPromise('core_reportbuilder/local/settings/sorting', {sorting: context})
|
||||
.then(({html, js}) => {
|
||||
Templates.replaceNode(settingsSortingRegion, html, js);
|
||||
return pendingPromise.resolve();
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Updates column sorting
|
||||
*
|
||||
* @param {Element} reportElement
|
||||
* @param {Element} element
|
||||
* @param {Number} sortenabled
|
||||
* @param {Number} sortdirection
|
||||
* @return {Promise}
|
||||
*/
|
||||
const updateSorting = (reportElement, element, sortenabled, sortdirection) => {
|
||||
const reportId = reportElement.dataset.reportId;
|
||||
const listElement = element.closest('li');
|
||||
const columnId = listElement.dataset.columnSortId;
|
||||
const columnName = listElement.dataset.columnSortName;
|
||||
|
||||
return toggleColumnSorting(reportId, columnId, sortenabled, sortdirection)
|
||||
.then(reloadSettingsSortingRegion)
|
||||
.then(() => getString('columnsortupdated', 'core_reportbuilder', columnName))
|
||||
.then(addToast)
|
||||
.then(() => {
|
||||
dispatchEvent(reportEvents.tableReload, {}, reportElement);
|
||||
return null;
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Initialise module
|
||||
*
|
||||
* @param {Element} reportElement
|
||||
* @param {Boolean} initialized Ensure we only add our listeners once
|
||||
*/
|
||||
export const init = (reportElement, initialized) => {
|
||||
if (initialized) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Update sorting region each time report columns are updated (added or removed).
|
||||
subscribe(reportEvents.publish.reportColumnsUpdated, data => reloadSettingsSortingRegion(data)
|
||||
.catch(Notification.exception)
|
||||
);
|
||||
|
||||
reportElement.addEventListener('click', event => {
|
||||
|
||||
// Enable/disable sorting on columns.
|
||||
const toggleSorting = event.target.closest(reportSelectors.actions.reportToggleColumnSort);
|
||||
if (toggleSorting) {
|
||||
event.preventDefault();
|
||||
|
||||
const pendingPromise = new Pending('core_reportbuilder/sorting:toggle');
|
||||
const sortdirection = parseInt(toggleSorting.closest('li').dataset.columnSortDirection);
|
||||
|
||||
updateSorting(reportElement, toggleSorting, toggleSorting.checked, sortdirection)
|
||||
.then(() => pendingPromise.resolve())
|
||||
.catch(Notification.exception);
|
||||
}
|
||||
|
||||
// Change column sort direction.
|
||||
const toggleSortDirection = event.target.closest(reportSelectors.actions.reportToggleColumnSortDirection);
|
||||
if (toggleSortDirection) {
|
||||
event.preventDefault();
|
||||
|
||||
const pendingPromise = new Pending('core_reportbuilder/sorting:direction');
|
||||
const listElement = toggleSortDirection.closest('li');
|
||||
const sortenabled = listElement.dataset.columnSortEnabled;
|
||||
|
||||
let sortdirection = parseInt(listElement.dataset.columnSortDirection);
|
||||
if (sortdirection === SORTORDER.ASCENDING) {
|
||||
sortdirection = SORTORDER.DESCENDING;
|
||||
} else if (sortdirection === SORTORDER.DESCENDING) {
|
||||
sortdirection = SORTORDER.ASCENDING;
|
||||
}
|
||||
|
||||
updateSorting(reportElement, toggleSortDirection, sortenabled, sortdirection)
|
||||
.then(() => pendingPromise.resolve())
|
||||
.catch(Notification.exception);
|
||||
}
|
||||
});
|
||||
|
||||
// Initialize sortable list to handle column sorting moving (note JQuery dependency, see MDL-72293 for resolution).
|
||||
var columnsSortingSortableList = new SortableList(`${reportSelectors.regions.settingsSorting} ul`, {isHorizontal: false});
|
||||
columnsSortingSortableList.getElementName = element => Promise.resolve(element.data('columnSortName'));
|
||||
|
||||
$(reportElement).on(SortableList.EVENTS.DROP, 'li[data-column-sort-id]', (event, info) => {
|
||||
if (info.positionChanged) {
|
||||
const pendingPromise = new Pending('core_reportbuilder/sorting:reorder');
|
||||
const columnId = info.element.data('columnSortId');
|
||||
const columnPosition = info.element.data('columnSortPosition');
|
||||
|
||||
// Select target position, if moving to the end then count number of element siblings.
|
||||
let targetColumnSortPosition = info.targetNextElement.data('columnSortPosition') || info.element.siblings().length + 2;
|
||||
if (targetColumnSortPosition > columnPosition) {
|
||||
targetColumnSortPosition--;
|
||||
}
|
||||
|
||||
reorderColumnSorting(reportElement.dataset.reportId, columnId, targetColumnSortPosition)
|
||||
.then(reloadSettingsSortingRegion)
|
||||
.then(() => getString('columnsortupdated', 'core_reportbuilder', info.element.data('columnSortName')))
|
||||
.then(addToast)
|
||||
.then(() => {
|
||||
dispatchEvent(reportEvents.tableReload, {}, reportElement);
|
||||
return null;
|
||||
})
|
||||
.then(() => pendingPromise.resolve())
|
||||
.catch(Notification.exception);
|
||||
}
|
||||
});
|
||||
};
|
||||
@@ -43,4 +43,7 @@ export default {
|
||||
* dispatchEvent(reportEvents.tableReload, {}, document.querySelector(...));
|
||||
*/
|
||||
tableReload: 'core_reportbuilder_table_reload',
|
||||
publish: {
|
||||
reportColumnsUpdated: 'core_reportbuilder_report_columns_updated',
|
||||
},
|
||||
};
|
||||
|
||||
@@ -0,0 +1,74 @@
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Module to handle column AJAX requests
|
||||
*
|
||||
* @module core_reportbuilder/local/repository/columns
|
||||
* @package core_reportbuilder
|
||||
* @copyright 2021 Paul Holden <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
import Ajax from 'core/ajax';
|
||||
|
||||
/**
|
||||
* Add column to given report
|
||||
*
|
||||
* @param {Number} reportId
|
||||
* @param {String} uniqueIdentifier
|
||||
* @return {Promise}
|
||||
*/
|
||||
export const addColumn = (reportId, uniqueIdentifier) => {
|
||||
const request = {
|
||||
methodname: 'core_reportbuilder_columns_add',
|
||||
args: {reportid: reportId, uniqueidentifier: uniqueIdentifier}
|
||||
};
|
||||
|
||||
return Ajax.call([request])[0];
|
||||
};
|
||||
|
||||
/**
|
||||
* Remove column from given report
|
||||
*
|
||||
* @param {Number} reportId
|
||||
* @param {Number} columnId
|
||||
* @return {Promise}
|
||||
*/
|
||||
export const deleteColumn = (reportId, columnId) => {
|
||||
const request = {
|
||||
methodname: 'core_reportbuilder_columns_delete',
|
||||
args: {reportid: reportId, columnid: columnId}
|
||||
};
|
||||
|
||||
return Ajax.call([request])[0];
|
||||
};
|
||||
|
||||
/**
|
||||
* Re-order column within a report
|
||||
*
|
||||
* @param {Number} reportId
|
||||
* @param {Number} columnId
|
||||
* @param {Number} position
|
||||
* @return {Promise}
|
||||
*/
|
||||
export const reorderColumn = (reportId, columnId, position) => {
|
||||
const request = {
|
||||
methodname: 'core_reportbuilder_columns_reorder',
|
||||
args: {reportid: reportId, columnid: columnId, position: position}
|
||||
};
|
||||
|
||||
return Ajax.call([request])[0];
|
||||
};
|
||||
@@ -0,0 +1,89 @@
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Module to handle condition AJAX requests
|
||||
*
|
||||
* @module core_reportbuilder/local/repository/conditions
|
||||
* @package core_reportbuilder
|
||||
* @copyright 2021 Paul Holden <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
import Ajax from 'core/ajax';
|
||||
|
||||
/**
|
||||
* Reset all conditions for given report
|
||||
*
|
||||
* @param {Number} reportId
|
||||
* @return {Promise}
|
||||
*/
|
||||
export const resetConditions = reportId => {
|
||||
const request = {
|
||||
methodname: 'core_reportbuilder_conditions_reset',
|
||||
args: {reportid: reportId}
|
||||
};
|
||||
|
||||
return Ajax.call([request])[0];
|
||||
};
|
||||
|
||||
/**
|
||||
* Add condition to given report
|
||||
*
|
||||
* @param {Number} reportId
|
||||
* @param {String} uniqueIdentifier
|
||||
* @return {Promise}
|
||||
*/
|
||||
export const addCondition = (reportId, uniqueIdentifier) => {
|
||||
const request = {
|
||||
methodname: 'core_reportbuilder_conditions_add',
|
||||
args: {reportid: reportId, uniqueidentifier: uniqueIdentifier}
|
||||
};
|
||||
|
||||
return Ajax.call([request])[0];
|
||||
};
|
||||
|
||||
/**
|
||||
* Remove condition from given report
|
||||
*
|
||||
* @param {Number} reportId
|
||||
* @param {Number} conditionId
|
||||
* @return {Promise}
|
||||
*/
|
||||
export const deleteCondition = (reportId, conditionId) => {
|
||||
const request = {
|
||||
methodname: 'core_reportbuilder_conditions_delete',
|
||||
args: {reportid: reportId, conditionid: conditionId}
|
||||
};
|
||||
|
||||
return Ajax.call([request])[0];
|
||||
};
|
||||
|
||||
/**
|
||||
* Reorder a condition in a given report
|
||||
*
|
||||
* @param {Number} reportId
|
||||
* @param {Number} conditionId
|
||||
* @param {Number} position
|
||||
* @return {Promise}
|
||||
*/
|
||||
export const reorderCondition = (reportId, conditionId, position) => {
|
||||
const request = {
|
||||
methodname: 'core_reportbuilder_conditions_reorder',
|
||||
args: {reportid: reportId, conditionid: conditionId, position: position}
|
||||
};
|
||||
|
||||
return Ajax.call([request])[0];
|
||||
};
|
||||
@@ -30,7 +30,7 @@ import Ajax from 'core/ajax';
|
||||
* @param {Number} reportId
|
||||
* @return {Promise}
|
||||
*/
|
||||
export const reset = reportId => {
|
||||
export const resetFilters = reportId => {
|
||||
const request = {
|
||||
methodname: 'core_reportbuilder_filters_reset',
|
||||
args: {reportid: reportId}
|
||||
@@ -38,3 +38,52 @@ export const reset = reportId => {
|
||||
|
||||
return Ajax.call([request])[0];
|
||||
};
|
||||
|
||||
/**
|
||||
* Add a filter to the given report
|
||||
*
|
||||
* @param {Number} reportId
|
||||
* @param {String} uniqueIdentifier
|
||||
* @return {Promise}
|
||||
*/
|
||||
export const addFilter = (reportId, uniqueIdentifier) => {
|
||||
const request = {
|
||||
methodname: 'core_reportbuilder_filters_add',
|
||||
args: {reportid: reportId, uniqueidentifier: uniqueIdentifier}
|
||||
};
|
||||
|
||||
return Ajax.call([request])[0];
|
||||
};
|
||||
|
||||
/**
|
||||
* Remove filter from given report
|
||||
*
|
||||
* @param {Number} reportId
|
||||
* @param {Number} filterId
|
||||
* @return {Promise}
|
||||
*/
|
||||
export const deleteFilter = (reportId, filterId) => {
|
||||
const request = {
|
||||
methodname: 'core_reportbuilder_filters_delete',
|
||||
args: {reportid: reportId, filterid: filterId}
|
||||
};
|
||||
|
||||
return Ajax.call([request])[0];
|
||||
};
|
||||
|
||||
/**
|
||||
* Reorder a filter in a given report
|
||||
*
|
||||
* @param {Number} reportId
|
||||
* @param {Number} filterId
|
||||
* @param {Number} position
|
||||
* @return {Promise}
|
||||
*/
|
||||
export const reorderFilter = (reportId, filterId, position) => {
|
||||
const request = {
|
||||
methodname: 'core_reportbuilder_filters_reorder',
|
||||
args: {reportid: reportId, filterid: filterId, position: position}
|
||||
};
|
||||
|
||||
return Ajax.call([request])[0];
|
||||
};
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Module to handle modal form requests
|
||||
*
|
||||
* @module core_reportbuilder/local/repository/modals
|
||||
* @package core_reportbuilder
|
||||
* @copyright 2021 David Matamoros <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
import ModalForm from 'core_form/modalform';
|
||||
import {get_string as getString} from 'core/str';
|
||||
|
||||
/**
|
||||
* Open the New Report modal form
|
||||
*
|
||||
* @param {EventTarget} triggerElement
|
||||
* @param {Promise} modalTitle
|
||||
* @param {Number} reportId
|
||||
* @return {ModalForm}
|
||||
*/
|
||||
export const createReportModal = (triggerElement, modalTitle, reportId = 0) => {
|
||||
return new ModalForm({
|
||||
modalConfig: {
|
||||
title: modalTitle,
|
||||
},
|
||||
formClass: 'core_reportbuilder\\form\\report',
|
||||
args: {
|
||||
id: reportId,
|
||||
},
|
||||
saveButtonText: getString('save', 'moodle'),
|
||||
returnFocus: triggerElement,
|
||||
});
|
||||
};
|
||||
@@ -0,0 +1,56 @@
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Module to handle report AJAX requests
|
||||
*
|
||||
* @module core_reportbuilder/local/repository/reports
|
||||
* @package core_reportbuilder
|
||||
* @copyright 2021 Paul Holden <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
import Ajax from 'core/ajax';
|
||||
|
||||
/**
|
||||
* Delete given report
|
||||
*
|
||||
* @param {Number} reportId
|
||||
* @return {Promise}
|
||||
*/
|
||||
export const deleteReport = reportId => {
|
||||
const request = {
|
||||
methodname: 'core_reportbuilder_reports_delete',
|
||||
args: {reportid: reportId}
|
||||
};
|
||||
|
||||
return Ajax.call([request])[0];
|
||||
};
|
||||
|
||||
/**
|
||||
* Get report content
|
||||
*
|
||||
* @param {Number} reportId
|
||||
* @param {Boolean} editMode
|
||||
* @return {Promise}
|
||||
*/
|
||||
export const getReport = (reportId, editMode) => {
|
||||
const request = {
|
||||
methodname: 'core_reportbuilder_reports_get',
|
||||
args: {reportid: reportId, editmode: editMode}
|
||||
};
|
||||
|
||||
return Ajax.call([request])[0];
|
||||
};
|
||||
@@ -0,0 +1,60 @@
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Module to handle column AJAX requests
|
||||
*
|
||||
* @module core_reportbuilder/local/repository/sorting
|
||||
* @package core_reportbuilder
|
||||
* @copyright 2021 David Matamoros <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
import Ajax from 'core/ajax';
|
||||
|
||||
/**
|
||||
* Re-order sort column position
|
||||
*
|
||||
* @param {Number} reportId
|
||||
* @param {Number} columnId
|
||||
* @param {Number} position
|
||||
* @return {Promise}
|
||||
*/
|
||||
export const reorderColumnSorting = (reportId, columnId, position) => {
|
||||
const request = {
|
||||
methodname: 'core_reportbuilder_columns_sort_reorder',
|
||||
args: {reportid: reportId, columnid: columnId, position: position}
|
||||
};
|
||||
|
||||
return Ajax.call([request])[0];
|
||||
};
|
||||
|
||||
/**
|
||||
* Enables/disabled sorting on column
|
||||
*
|
||||
* @param {Number} reportId
|
||||
* @param {Number} columnId
|
||||
* @param {Boolean} enabled
|
||||
* @param {Number} direction
|
||||
* @return {Promise}
|
||||
*/
|
||||
export const toggleColumnSorting = (reportId, columnId, enabled, direction) => {
|
||||
const request = {
|
||||
methodname: 'core_reportbuilder_columns_sort_toggle',
|
||||
args: {reportid: reportId, columnid: columnId, enabled: enabled, direction: direction}
|
||||
};
|
||||
|
||||
return Ajax.call([request])[0];
|
||||
};
|
||||
@@ -31,22 +31,46 @@
|
||||
*/
|
||||
const SELECTORS = {
|
||||
regions: {
|
||||
systemReport: '[data-region="core_reportbuilder/system-report"]',
|
||||
report: '[data-region="core_reportbuilder/report"]',
|
||||
reportTable: '[data-region="reportbuilder-table"]',
|
||||
columnHeader: '[data-region="column-header"]',
|
||||
filterButtonLabel: '[data-region="filter-button-label"]',
|
||||
filtersForm: '[data-region="filters-form"]',
|
||||
sidebarMenu: '[data-region="sidebar-menu"]',
|
||||
sidebarCard: '[data-region="sidebar-card"]',
|
||||
settingsConditions: '[data-region="settings-conditions"]',
|
||||
activeConditions: '[data-region="active-conditions"]',
|
||||
activeCondition: '[data-region="active-condition"]',
|
||||
settingsFilters: '[data-region="settings-filters"]',
|
||||
activeFilters: '[data-region="active-filters"]',
|
||||
activeFilter: '[data-region="active-filter"]',
|
||||
settingsSorting: '[data-region="settings-sorting"]',
|
||||
},
|
||||
actions: {
|
||||
reportActionPopup: '[data-action="report-action-popup"]',
|
||||
}
|
||||
reportCreate: '[data-action="report-create"]',
|
||||
reportEdit: '[data-action="report-edit"]',
|
||||
reportDelete: '[data-action="report-delete"]',
|
||||
reportAddColumn: '[data-action="report-add-column"]',
|
||||
reportRemoveColumn: '[data-action="report-remove-column"]',
|
||||
reportAddCondition: '[data-action="report-add-condition"]',
|
||||
reportRemoveCondition: '[data-action="report-remove-condition"]',
|
||||
reportAddFilter: '[data-action="report-add-filter"]',
|
||||
reportRemoveFilter: '[data-action="report-remove-filter"]',
|
||||
reportToggleColumnSort: '[data-action="report-toggle-column-sorting"]',
|
||||
reportToggleColumnSortDirection: '[data-action="report-toggle-sort-direction"]',
|
||||
sidebarSearch: '[data-action="sidebar-search"]',
|
||||
toggleEditPreview: '[data-action="toggle-edit-preview"]',
|
||||
},
|
||||
};
|
||||
|
||||
/**
|
||||
* Selector for given report
|
||||
*
|
||||
* @method forSystemReport
|
||||
* @method forReport
|
||||
* @param {Number} reportId
|
||||
* @return {String}
|
||||
*/
|
||||
SELECTORS.forSystemReport = reportId => `${SELECTORS.regions.systemReport}[data-reportid="${reportId}"]`;
|
||||
SELECTORS.forReport = reportId => `${SELECTORS.regions.report}[data-report-id="${reportId}"]`;
|
||||
|
||||
export default SELECTORS;
|
||||
|
||||
@@ -26,21 +26,28 @@ import * as reportSelectors from 'core_reportbuilder/local/selectors';
|
||||
import {setPageNumber, refreshTableContent} from 'core_table/dynamic';
|
||||
import * as tableSelectors from 'core_table/local/dynamic/selectors';
|
||||
|
||||
let initialized = false;
|
||||
|
||||
/**
|
||||
* Initialise module for given report
|
||||
*
|
||||
* @method
|
||||
* @param {Number} reportId
|
||||
*/
|
||||
export const init = reportId => {
|
||||
export const init = () => {
|
||||
|
||||
if (initialized) {
|
||||
// We already added the event listeners (can be called multiple times by mustache template).
|
||||
return;
|
||||
}
|
||||
|
||||
// Listen for the table reload event.
|
||||
document.addEventListener(reportEvents.tableReload, async(event) => {
|
||||
const triggerElement = event.target.closest(reportSelectors.forSystemReport(reportId));
|
||||
if (triggerElement === null) {
|
||||
const reportElement = event.target.closest(reportSelectors.regions.report);
|
||||
if (reportElement === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
const tableRoot = triggerElement.querySelector(tableSelectors.main.region);
|
||||
const tableRoot = reportElement.querySelector(tableSelectors.main.region);
|
||||
const pageNumber = event.detail?.preservePagination ? null : 1;
|
||||
|
||||
await setPageNumber(tableRoot, pageNumber, false)
|
||||
@@ -57,4 +64,6 @@ export const init = reportId => {
|
||||
const popupAction = JSON.parse(reportActionPopup.dataset.popupAction);
|
||||
window.openpopup(event, popupAction.jsfunctionargs);
|
||||
});
|
||||
|
||||
initialized = true;
|
||||
};
|
||||
|
||||
@@ -0,0 +1,104 @@
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Report builder reports list management
|
||||
*
|
||||
* @module core_reportbuilder/reports_list
|
||||
* @package core_reportbuilder
|
||||
* @copyright 2021 David Matamoros <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
import {dispatchEvent} from 'core/event_dispatcher';
|
||||
import Notification from 'core/notification';
|
||||
import Pending from 'core/pending';
|
||||
import {get_string as getString, get_strings as getStrings} from 'core/str';
|
||||
import {add as addToast} from 'core/toast';
|
||||
import * as reportEvents from 'core_reportbuilder/local/events';
|
||||
import * as reportSelectors from 'core_reportbuilder/local/selectors';
|
||||
import {deleteReport} from 'core_reportbuilder/local/repository/reports';
|
||||
import {createReportModal} from 'core_reportbuilder/local/repository/modals';
|
||||
|
||||
/**
|
||||
* Initialise module
|
||||
*/
|
||||
export const init = () => {
|
||||
document.addEventListener('click', event => {
|
||||
const reportCreate = event.target.closest(reportSelectors.actions.reportCreate);
|
||||
if (reportCreate) {
|
||||
event.preventDefault();
|
||||
|
||||
// Redirect user to editing interface for the report after submission.
|
||||
const reportModal = createReportModal(event.target, getString('newreport', 'core_reportbuilder'));
|
||||
reportModal.addEventListener(reportModal.events.FORM_SUBMITTED, event => {
|
||||
window.location.href = event.detail;
|
||||
});
|
||||
|
||||
reportModal.show();
|
||||
}
|
||||
|
||||
const reportEdit = event.target.closest(reportSelectors.actions.reportEdit);
|
||||
if (reportEdit) {
|
||||
event.preventDefault();
|
||||
|
||||
// Reload current report page after submission.
|
||||
const reportModal = createReportModal(event.target, getString('editreportdetails', 'core_reportbuilder'),
|
||||
reportEdit.dataset.reportId);
|
||||
reportModal.addEventListener(reportModal.events.FORM_SUBMITTED, () => {
|
||||
const reportElement = event.target.closest(reportSelectors.regions.report);
|
||||
|
||||
getString('reportupdated', 'core_reportbuilder')
|
||||
.then(addToast)
|
||||
.then(() => {
|
||||
dispatchEvent(reportEvents.tableReload, {preservePagination: true}, reportElement);
|
||||
return;
|
||||
})
|
||||
.catch(Notification.exception);
|
||||
});
|
||||
|
||||
reportModal.show();
|
||||
}
|
||||
|
||||
const reportDelete = event.target.closest(reportSelectors.actions.reportDelete);
|
||||
if (reportDelete) {
|
||||
event.preventDefault();
|
||||
|
||||
getStrings([
|
||||
{key: 'deletereport', component: 'core_reportbuilder'},
|
||||
{key: 'deletereportconfirm', component: 'core_reportbuilder', param: reportDelete.dataset.reportName},
|
||||
{key: 'delete', component: 'moodle'},
|
||||
]).then(([confirmTitle, confirmText, confirmButton]) => {
|
||||
Notification.confirm(confirmTitle, confirmText, confirmButton, null, () => {
|
||||
const pendingPromise = new Pending('core_reportbuilder/reports:delete');
|
||||
const reportElement = event.target.closest(reportSelectors.regions.report);
|
||||
|
||||
deleteReport(reportDelete.dataset.reportId)
|
||||
.then(() => getString('reportdeleted', 'core_reportbuilder'))
|
||||
.then(addToast)
|
||||
.then(() => {
|
||||
pendingPromise.resolve();
|
||||
dispatchEvent(reportEvents.tableReload, {preservePagination: true}, reportElement);
|
||||
return;
|
||||
})
|
||||
.catch(Notification.exception);
|
||||
});
|
||||
return;
|
||||
}).catch(Notification.exception);
|
||||
}
|
||||
});
|
||||
};
|
||||
@@ -0,0 +1,106 @@
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Report builder sidebar component
|
||||
*
|
||||
* @module core_reportbuilder/sidebar
|
||||
* @package core_reportbuilder
|
||||
* @copyright 2021 Paul Holden <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
import Pending from 'core/pending';
|
||||
import {debounce} from 'core/utils';
|
||||
import * as reportSelectors from 'core_reportbuilder/local/selectors';
|
||||
|
||||
const DEBOUNCE_TIMER = 250;
|
||||
|
||||
const CLASSES = {
|
||||
EXPANDED: 'show',
|
||||
COLLAPSED: 'collapsed',
|
||||
SHOW: 'd-flex',
|
||||
HIDE: 'd-none',
|
||||
};
|
||||
|
||||
/**
|
||||
* Initialise module
|
||||
*
|
||||
* @param {Event} event
|
||||
* @param {Element} sidebarMenu
|
||||
*/
|
||||
const sidebarCardFilter = (event, sidebarMenu) => {
|
||||
const pendingPromise = new Pending('core_reportbuilder/sidebar:cardFilter');
|
||||
|
||||
const sidebarCards = sidebarMenu.querySelectorAll(reportSelectors.regions.sidebarCard);
|
||||
const sidebarItems = sidebarMenu.querySelectorAll('.list-group-item');
|
||||
const searchTerm = event.target.value.toLowerCase();
|
||||
|
||||
// Toggle items according to match against search term.
|
||||
sidebarItems.forEach(item => {
|
||||
let itemName = item.dataset.name.toLowerCase();
|
||||
if (itemName.includes(searchTerm)) {
|
||||
item.classList.replace(CLASSES.HIDE, CLASSES.SHOW);
|
||||
} else {
|
||||
item.classList.replace(CLASSES.SHOW, CLASSES.HIDE);
|
||||
}
|
||||
});
|
||||
|
||||
// Toggle cards according to whether they have any visible items.
|
||||
sidebarCards.forEach(card => {
|
||||
if (card.querySelectorAll(`.${CLASSES.SHOW}`).length > 0) {
|
||||
card.classList.remove(CLASSES.HIDE);
|
||||
expandCard(card);
|
||||
} else {
|
||||
card.classList.add(CLASSES.HIDE);
|
||||
}
|
||||
});
|
||||
|
||||
pendingPromise.resolve();
|
||||
};
|
||||
|
||||
/**
|
||||
* Show a collapsed card.
|
||||
* This function simulates the behaviour of JQuery show method on a collapsible element.
|
||||
*
|
||||
* @param {Element} card
|
||||
*/
|
||||
const expandCard = (card) => {
|
||||
let cardButton = card.querySelector('[data-toggle="collapse"]');
|
||||
if (cardButton.classList.contains(CLASSES.COLLAPSED)) {
|
||||
cardButton.classList.remove(CLASSES.COLLAPSED);
|
||||
cardButton.setAttribute('aria-expanded', "true");
|
||||
let cardContent = card.querySelector(cardButton.dataset.target);
|
||||
cardContent.classList.add(CLASSES.EXPANDED);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Initialise module
|
||||
*/
|
||||
export const init = () => {
|
||||
const sidebarMenu = document.querySelector(reportSelectors.regions.sidebarMenu);
|
||||
const sidebarSearch = sidebarMenu.querySelector(reportSelectors.actions.sidebarSearch);
|
||||
|
||||
// Debounce the event listener to allow the user to finish typing.
|
||||
sidebarSearch.addEventListener('keyup', event => {
|
||||
const pendingPromise = new Pending('core_reportbuilder/sidebar:keyup');
|
||||
|
||||
debounce(sidebarCardFilter, DEBOUNCE_TIMER)(event, sidebarMenu);
|
||||
setTimeout(() => {
|
||||
pendingPromise.resolve();
|
||||
}, DEBOUNCE_TIMER);
|
||||
});
|
||||
};
|
||||
@@ -0,0 +1,244 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace core_reportbuilder;
|
||||
|
||||
use coding_exception;
|
||||
use core_reportbuilder\local\helpers\report;
|
||||
use core_reportbuilder\local\models\filter as filter_model;
|
||||
use core_reportbuilder\local\report\base;
|
||||
use core_reportbuilder\local\report\column;
|
||||
use core_reportbuilder\local\report\filter;
|
||||
|
||||
/**
|
||||
* Class datasource
|
||||
*
|
||||
* @package core_reportbuilder
|
||||
* @copyright 2021 David Matamoros <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
abstract class datasource extends base {
|
||||
|
||||
/**
|
||||
* Return user friendly name of the datasource
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
abstract public static function get_name(): string;
|
||||
|
||||
/**
|
||||
* Add columns from the given entity name to be available to use in a custom report
|
||||
*
|
||||
* @param string $entityname
|
||||
* @param array $include Include only these columns, if omitted then include all
|
||||
* @param array $exclude Exclude these columns, if omitted then exclude none
|
||||
* @throws coding_exception If both $include and $exclude are non-empty
|
||||
*/
|
||||
final protected function add_columns_from_entity(string $entityname, array $include = [], array $exclude = []): void {
|
||||
if (!empty($include) && !empty($exclude)) {
|
||||
throw new coding_exception('Cannot specify columns to include and exclude simultaneously');
|
||||
}
|
||||
|
||||
$entity = $this->get_entity($entityname);
|
||||
|
||||
// Retrieve filtered columns from entity, respecting given $include/$exclude parameters.
|
||||
$columns = array_filter($entity->get_columns(), static function(column $column) use ($include, $exclude): bool {
|
||||
if (!empty($include)) {
|
||||
return in_array($column->get_name(), $include);
|
||||
}
|
||||
|
||||
if (!empty($exclude)) {
|
||||
return !in_array($column->get_name(), $exclude);
|
||||
}
|
||||
|
||||
return true;
|
||||
});
|
||||
|
||||
foreach ($columns as $column) {
|
||||
$this->add_column($column);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add default datasource columns to the report
|
||||
*
|
||||
* This method is optional and can be called when the report is created to add the default columns defined in the
|
||||
* selected datasource.
|
||||
*/
|
||||
public function add_default_columns(): void {
|
||||
$reportid = $this->get_report_persistent()->get('id');
|
||||
$columnidentifiers = $this->get_default_columns();
|
||||
foreach ($columnidentifiers as $uniqueidentifier) {
|
||||
report::add_report_column($reportid, $uniqueidentifier);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the columns that will be added to the report once is created
|
||||
*
|
||||
* @return string[]
|
||||
*/
|
||||
abstract public function get_default_columns(): array;
|
||||
|
||||
/**
|
||||
* Add filters from the given entity name to be available to use in a custom report
|
||||
*
|
||||
* @param string $entityname
|
||||
* @param array $include Include only these filters, if omitted then include all
|
||||
* @param array $exclude Exclude these filters, if omitted then exclude none
|
||||
* @throws coding_exception If both $include and $exclude are non-empty
|
||||
*/
|
||||
final protected function add_filters_from_entity(string $entityname, array $include = [], array $exclude = []): void {
|
||||
if (!empty($include) && !empty($exclude)) {
|
||||
throw new coding_exception('Cannot specify filters to include and exclude simultaneously');
|
||||
}
|
||||
|
||||
$entity = $this->get_entity($entityname);
|
||||
|
||||
// Retrieve filtered filters from entity, respecting given $include/$exclude parameters.
|
||||
$filters = array_filter($entity->get_filters(), static function(filter $filter) use ($include, $exclude): bool {
|
||||
if (!empty($include)) {
|
||||
return in_array($filter->get_name(), $include);
|
||||
}
|
||||
|
||||
if (!empty($exclude)) {
|
||||
return !in_array($filter->get_name(), $exclude);
|
||||
}
|
||||
|
||||
return true;
|
||||
});
|
||||
|
||||
foreach ($filters as $filter) {
|
||||
$this->add_filter($filter);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add default datasource filters to the report
|
||||
*
|
||||
* This method is optional and can be called when the report is created to add the default filters defined in the
|
||||
* selected datasource.
|
||||
*/
|
||||
public function add_default_filters(): void {
|
||||
$reportid = $this->get_report_persistent()->get('id');
|
||||
$filteridentifiers = $this->get_default_filters();
|
||||
foreach ($filteridentifiers as $uniqueidentifier) {
|
||||
report::add_report_filter($reportid, $uniqueidentifier);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the filters that will be added to the report once is created
|
||||
*
|
||||
* @return string[]
|
||||
*/
|
||||
abstract public function get_default_filters(): array;
|
||||
|
||||
/**
|
||||
* Return all configured report filters
|
||||
*
|
||||
* @return filter[]
|
||||
*/
|
||||
public function get_active_filters(): array {
|
||||
$filters = [];
|
||||
|
||||
$activefilters = filter_model::get_filter_records($this->get_report_persistent()->get('id'), 'filterorder');
|
||||
foreach ($activefilters as $filter) {
|
||||
$instance = $this->get_filter($filter->get('uniqueidentifier'));
|
||||
if ($instance !== null && $instance->get_is_available()) {
|
||||
$filters[$instance->get_unique_identifier()] = $instance
|
||||
->set_persistent($filter);
|
||||
}
|
||||
}
|
||||
|
||||
return $filters;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add conditions from the given entity name to be available to use in a custom report
|
||||
*
|
||||
* @param string $entityname
|
||||
* @param array $include Include only these conditions, if omitted then include all
|
||||
* @param array $exclude Exclude these conditions, if omitted then exclude none
|
||||
* @throws coding_exception If both $include and $exclude are non-empty
|
||||
*/
|
||||
final protected function add_conditions_from_entity(string $entityname, array $include = [], array $exclude = []): void {
|
||||
if (!empty($include) && !empty($exclude)) {
|
||||
throw new coding_exception('Cannot specify conditions to include and exclude simultaneously');
|
||||
}
|
||||
|
||||
$entity = $this->get_entity($entityname);
|
||||
|
||||
// Retrieve filtered conditions from entity, respecting given $include/$exclude parameters.
|
||||
$conditions = array_filter($entity->get_conditions(), static function(filter $condition) use ($include, $exclude): bool {
|
||||
if (!empty($include)) {
|
||||
return in_array($condition->get_name(), $include);
|
||||
}
|
||||
|
||||
if (!empty($exclude)) {
|
||||
return !in_array($condition->get_name(), $exclude);
|
||||
}
|
||||
|
||||
return true;
|
||||
});
|
||||
|
||||
foreach ($conditions as $condition) {
|
||||
$this->add_condition($condition);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add default datasource conditions to the report
|
||||
*
|
||||
* This method is optional and can be called when the report is created to add the default conditions defined in the
|
||||
* selected datasource.
|
||||
*/
|
||||
public function add_default_conditions(): void {
|
||||
$reportid = $this->get_report_persistent()->get('id');
|
||||
$conditionidentifiers = $this->get_default_conditions();
|
||||
foreach ($conditionidentifiers as $uniqueidentifier) {
|
||||
report::add_report_condition($reportid, $uniqueidentifier);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the conditions that will be added to the report once is created
|
||||
*
|
||||
* @return string[]
|
||||
*/
|
||||
abstract public function get_default_conditions(): array;
|
||||
|
||||
/**
|
||||
* Return all configured report conditions
|
||||
*
|
||||
* @return filter[]
|
||||
*/
|
||||
public function get_active_conditions(): array {
|
||||
$conditions = [];
|
||||
|
||||
$activeconditions = filter_model::get_condition_records($this->get_report_persistent()->get('id'), 'filterorder');
|
||||
foreach ($activeconditions as $condition) {
|
||||
$instance = $this->get_condition($condition->get('uniqueidentifier'));
|
||||
if ($instance !== null && $instance->get_is_available()) {
|
||||
$conditions[$instance->get_unique_identifier()] = $instance;
|
||||
}
|
||||
}
|
||||
|
||||
return $conditions;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace core_reportbuilder\event;
|
||||
|
||||
use core\event\base;
|
||||
use core_reportbuilder\local\models\report;
|
||||
use moodle_url;
|
||||
|
||||
/**
|
||||
* Report builder custom report created event class.
|
||||
*
|
||||
* @package core_reportbuilder
|
||||
* @copyright 2021 David Matamoros <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*
|
||||
* @property-read array $other {
|
||||
* Extra information about the event.
|
||||
*
|
||||
* - string name: The name of the report
|
||||
* - string source: The report source class
|
||||
* }
|
||||
*/
|
||||
class report_created extends base {
|
||||
|
||||
/**
|
||||
* Initialise the event data.
|
||||
*/
|
||||
protected function init() {
|
||||
$this->data['objecttable'] = report::TABLE;
|
||||
$this->data['crud'] = 'c';
|
||||
$this->data['edulevel'] = self::LEVEL_OTHER;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an instance from a report object
|
||||
*
|
||||
* @param report $report
|
||||
* @return self
|
||||
*/
|
||||
public static function create_from_object(report $report): self {
|
||||
$eventparams = [
|
||||
'context' => $report->get_context(),
|
||||
'objectid' => $report->get('id'),
|
||||
'other' => [
|
||||
'name' => $report->get('name'),
|
||||
'source' => $report->get('source'),
|
||||
]
|
||||
];
|
||||
$event = self::create($eventparams);
|
||||
$event->add_record_snapshot($event->objecttable, $report->to_record());
|
||||
return $event;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns localised general event name.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function get_name() {
|
||||
return get_string('reportcreated', 'core_reportbuilder');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns non-localised description of what happened.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_description() {
|
||||
return "The user with id '$this->userid' created the custom report with id '$this->objectid'.";
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns relevant URL.
|
||||
*
|
||||
* @return moodle_url
|
||||
*/
|
||||
public function get_url(): moodle_url {
|
||||
return new moodle_url('/reportbuilder/edit.php', ['id' => $this->objectid]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace core_reportbuilder\event;
|
||||
|
||||
use core\event\base;
|
||||
use core_reportbuilder\local\models\report;
|
||||
|
||||
/**
|
||||
* Report builder custom report deleted event class.
|
||||
*
|
||||
* @package core_reportbuilder
|
||||
* @copyright 2021 David Matamoros <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*
|
||||
* @property-read array $other {
|
||||
* Extra information about the event.
|
||||
*
|
||||
* - string name: The name of the report
|
||||
* - string source: The report source class
|
||||
* }
|
||||
*/
|
||||
class report_deleted extends base {
|
||||
|
||||
/**
|
||||
* Initialise the event data.
|
||||
*/
|
||||
protected function init() {
|
||||
$this->data['objecttable'] = report::TABLE;
|
||||
$this->data['crud'] = 'd';
|
||||
$this->data['edulevel'] = self::LEVEL_OTHER;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an instance from a report object
|
||||
*
|
||||
* @param report $report
|
||||
* @return self
|
||||
*/
|
||||
public static function create_from_object(report $report): self {
|
||||
$eventparams = [
|
||||
'context' => $report->get_context(),
|
||||
'objectid' => $report->get('id'),
|
||||
'other' => [
|
||||
'name' => $report->get('name'),
|
||||
'source' => $report->get('source'),
|
||||
]
|
||||
];
|
||||
$event = self::create($eventparams);
|
||||
$event->add_record_snapshot($event->objecttable, $report->to_record());
|
||||
return $event;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns localised general event name.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function get_name() {
|
||||
return get_string('reportdeleted', 'core_reportbuilder');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns non-localised description of what happened.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_description() {
|
||||
return "The user with id '$this->userid' deleted the custom report with id '$this->objectid'.";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace core_reportbuilder\event;
|
||||
|
||||
use core\event\base;
|
||||
use core_reportbuilder\local\models\report;
|
||||
use moodle_url;
|
||||
|
||||
/**
|
||||
* Report builder custom report updated event class.
|
||||
*
|
||||
* @package core_reportbuilder
|
||||
* @copyright 2021 David Matamoros <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*
|
||||
* @property-read array $other {
|
||||
* Extra information about the event.
|
||||
*
|
||||
* - string name: The name of the report
|
||||
* - string source: The report source class
|
||||
* }
|
||||
*/
|
||||
class report_updated extends base {
|
||||
|
||||
/**
|
||||
* Initialise the event data.
|
||||
*/
|
||||
protected function init() {
|
||||
$this->data['objecttable'] = report::TABLE;
|
||||
$this->data['crud'] = 'u';
|
||||
$this->data['edulevel'] = self::LEVEL_OTHER;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an instance from a report object
|
||||
*
|
||||
* @param report $report
|
||||
* @return self
|
||||
*/
|
||||
public static function create_from_object(report $report): self {
|
||||
$eventparams = [
|
||||
'context' => $report->get_context(),
|
||||
'objectid' => $report->get('id'),
|
||||
'other' => [
|
||||
'name' => $report->get('name'),
|
||||
'source' => $report->get('source'),
|
||||
]
|
||||
];
|
||||
$event = self::create($eventparams);
|
||||
$event->add_record_snapshot($event->objecttable, $report->to_record());
|
||||
return $event;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns localised general event name.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function get_name() {
|
||||
return get_string('reportupdated', 'core_reportbuilder');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns non-localised description of what happened.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_description() {
|
||||
return "The user with id '$this->userid' updated the custom report with id '$this->objectid'.";
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns relevant URL.
|
||||
*
|
||||
* @return moodle_url
|
||||
*/
|
||||
public function get_url(): moodle_url {
|
||||
return new moodle_url('/reportbuilder/edit.php', ['id' => $this->objectid]);
|
||||
}
|
||||
}
|
||||
+96
@@ -0,0 +1,96 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace core_reportbuilder\external\columns;
|
||||
|
||||
use core_reportbuilder\external\custom_report_columns_sorting_exporter;
|
||||
use external_api;
|
||||
use external_function_parameters;
|
||||
use external_single_structure;
|
||||
use external_value;
|
||||
use core_reportbuilder\manager;
|
||||
use core_reportbuilder\permission;
|
||||
use core_reportbuilder\local\helpers\report;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
global $CFG;
|
||||
require_once("{$CFG->libdir}/externallib.php");
|
||||
|
||||
/**
|
||||
* External method for adding report columns
|
||||
*
|
||||
* @package core_reportbuilder
|
||||
* @copyright 2021 Paul Holden <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class add extends external_api {
|
||||
|
||||
/**
|
||||
* External method parameters
|
||||
*
|
||||
* @return external_function_parameters
|
||||
*/
|
||||
public static function execute_parameters(): external_function_parameters {
|
||||
return new external_function_parameters([
|
||||
'reportid' => new external_value(PARAM_INT, 'Report ID'),
|
||||
'uniqueidentifier' => new external_value(PARAM_RAW, 'Unique identifier of the column'),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* External method execution
|
||||
*
|
||||
* @param int $reportid
|
||||
* @param string $uniqueidentifier
|
||||
* @return array
|
||||
*/
|
||||
public static function execute(int $reportid, string $uniqueidentifier): array {
|
||||
global $PAGE;
|
||||
|
||||
[
|
||||
'reportid' => $reportid,
|
||||
'uniqueidentifier' => $uniqueidentifier,
|
||||
] = self::validate_parameters(self::execute_parameters(), [
|
||||
'reportid' => $reportid,
|
||||
'uniqueidentifier' => $uniqueidentifier,
|
||||
]);
|
||||
|
||||
$report = manager::get_report_from_id($reportid);
|
||||
|
||||
self::validate_context($report->get_context());
|
||||
permission::require_can_edit_report($report->get_report_persistent());
|
||||
|
||||
report::add_report_column($reportid, $uniqueidentifier);
|
||||
|
||||
$exporter = new custom_report_columns_sorting_exporter(null, [
|
||||
'report' => $report,
|
||||
]);
|
||||
|
||||
return (array) $exporter->export($PAGE->get_renderer('core'));
|
||||
}
|
||||
|
||||
/**
|
||||
* External method return value
|
||||
*
|
||||
* @return external_single_structure
|
||||
*/
|
||||
public static function execute_returns(): external_single_structure {
|
||||
return custom_report_columns_sorting_exporter::get_read_structure();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace core_reportbuilder\external\columns;
|
||||
|
||||
use core_reportbuilder\external\custom_report_columns_sorting_exporter;
|
||||
use external_api;
|
||||
use external_function_parameters;
|
||||
use external_single_structure;
|
||||
use external_value;
|
||||
use core_reportbuilder\manager;
|
||||
use core_reportbuilder\permission;
|
||||
use core_reportbuilder\local\helpers\report;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
global $CFG;
|
||||
require_once("{$CFG->libdir}/externallib.php");
|
||||
|
||||
/**
|
||||
* External method for deleting report columns
|
||||
*
|
||||
* @package core_reportbuilder
|
||||
* @copyright 2021 Paul Holden <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class delete extends external_api {
|
||||
|
||||
/**
|
||||
* External method parameters
|
||||
*
|
||||
* @return external_function_parameters
|
||||
*/
|
||||
public static function execute_parameters(): external_function_parameters {
|
||||
return new external_function_parameters([
|
||||
'reportid' => new external_value(PARAM_INT, 'Report ID'),
|
||||
'columnid' => new external_value(PARAM_INT, 'Column ID'),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* External method execution
|
||||
*
|
||||
* @param int $reportid
|
||||
* @param int $columnid
|
||||
* @return array
|
||||
*/
|
||||
public static function execute(int $reportid, int $columnid): array {
|
||||
global $PAGE;
|
||||
|
||||
[
|
||||
'reportid' => $reportid,
|
||||
'columnid' => $columnid,
|
||||
] = self::validate_parameters(self::execute_parameters(), [
|
||||
'reportid' => $reportid,
|
||||
'columnid' => $columnid,
|
||||
]);
|
||||
|
||||
$report = manager::get_report_from_id($reportid);
|
||||
|
||||
self::validate_context($report->get_context());
|
||||
permission::require_can_edit_report($report->get_report_persistent());
|
||||
|
||||
report::delete_report_column($reportid, $columnid);
|
||||
|
||||
$exporter = new custom_report_columns_sorting_exporter(null, [
|
||||
'report' => $report,
|
||||
]);
|
||||
|
||||
return (array) $exporter->export($PAGE->get_renderer('core'));
|
||||
}
|
||||
|
||||
/**
|
||||
* External method return value
|
||||
*
|
||||
* @return external_single_structure
|
||||
*/
|
||||
public static function execute_returns(): external_single_structure {
|
||||
return custom_report_columns_sorting_exporter::get_read_structure();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace core_reportbuilder\external\columns;
|
||||
|
||||
use external_api;
|
||||
use external_function_parameters;
|
||||
use external_value;
|
||||
use core_reportbuilder\manager;
|
||||
use core_reportbuilder\permission;
|
||||
use core_reportbuilder\local\helpers\report;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
global $CFG;
|
||||
require_once("{$CFG->libdir}/externallib.php");
|
||||
|
||||
/**
|
||||
* External method for re-ordering report columns
|
||||
*
|
||||
* @package core_reportbuilder
|
||||
* @copyright 2021 Paul Holden <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class reorder extends external_api {
|
||||
|
||||
/**
|
||||
* External method parameters
|
||||
*
|
||||
* @return external_function_parameters
|
||||
*/
|
||||
public static function execute_parameters(): external_function_parameters {
|
||||
return new external_function_parameters([
|
||||
'reportid' => new external_value(PARAM_INT, 'Report ID'),
|
||||
'columnid' => new external_value(PARAM_INT, 'Column ID'),
|
||||
'position' => new external_value(PARAM_INT, 'New column position')
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* External method execution
|
||||
*
|
||||
* @param int $reportid
|
||||
* @param int $columnid
|
||||
* @param int $position
|
||||
* @return bool
|
||||
*/
|
||||
public static function execute(int $reportid, int $columnid, int $position): bool {
|
||||
[
|
||||
'reportid' => $reportid,
|
||||
'columnid' => $columnid,
|
||||
'position' => $position,
|
||||
] = self::validate_parameters(self::execute_parameters(), [
|
||||
'reportid' => $reportid,
|
||||
'columnid' => $columnid,
|
||||
'position' => $position,
|
||||
]);
|
||||
|
||||
$report = manager::get_report_from_id($reportid);
|
||||
|
||||
self::validate_context($report->get_context());
|
||||
permission::require_can_edit_report($report->get_report_persistent());
|
||||
|
||||
return report::reorder_report_column($reportid, $columnid, $position);
|
||||
}
|
||||
|
||||
/**
|
||||
* External method return value
|
||||
*
|
||||
* @return external_value
|
||||
*/
|
||||
public static function execute_returns(): external_value {
|
||||
return new external_value(PARAM_BOOL, 'Success');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace core_reportbuilder\external\columns\sort;
|
||||
|
||||
use external_api;
|
||||
use external_function_parameters;
|
||||
use external_single_structure;
|
||||
use external_value;
|
||||
use core_reportbuilder\manager;
|
||||
use core_reportbuilder\permission;
|
||||
use core_reportbuilder\local\helpers\report;
|
||||
use core_reportbuilder\external\custom_report_columns_sorting_exporter;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
global $CFG;
|
||||
require_once("{$CFG->libdir}/externallib.php");
|
||||
|
||||
/**
|
||||
* External method for re-ordering report column sorting
|
||||
*
|
||||
* @package core_reportbuilder
|
||||
* @copyright 2021 Paul Holden <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class reorder extends external_api {
|
||||
|
||||
/**
|
||||
* External method parameters
|
||||
*
|
||||
* @return external_function_parameters
|
||||
*/
|
||||
public static function execute_parameters(): external_function_parameters {
|
||||
return new external_function_parameters([
|
||||
'reportid' => new external_value(PARAM_INT, 'Report ID'),
|
||||
'columnid' => new external_value(PARAM_INT, 'Column ID'),
|
||||
'position' => new external_value(PARAM_INT, 'New column sort position'),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* External method execution
|
||||
*
|
||||
* @param int $reportid
|
||||
* @param int $columnid
|
||||
* @param int $position
|
||||
* @return array
|
||||
*/
|
||||
public static function execute(int $reportid, int $columnid, int $position): array {
|
||||
global $PAGE;
|
||||
|
||||
[
|
||||
'reportid' => $reportid,
|
||||
'columnid' => $columnid,
|
||||
'position' => $position,
|
||||
] = self::validate_parameters(self::execute_parameters(), [
|
||||
'reportid' => $reportid,
|
||||
'columnid' => $columnid,
|
||||
'position' => $position,
|
||||
]);
|
||||
|
||||
$report = manager::get_report_from_id($reportid);
|
||||
|
||||
self::validate_context($report->get_context());
|
||||
permission::require_can_edit_report($report->get_report_persistent());
|
||||
|
||||
report::reorder_report_column_sorting($reportid, $columnid, $position);
|
||||
|
||||
$exporter = new custom_report_columns_sorting_exporter(null, [
|
||||
'report' => $report,
|
||||
]);
|
||||
|
||||
return (array) $exporter->export($PAGE->get_renderer('core'));
|
||||
}
|
||||
|
||||
/**
|
||||
* External method return value
|
||||
*
|
||||
* @return external_single_structure
|
||||
*/
|
||||
public static function execute_returns(): external_single_structure {
|
||||
return custom_report_columns_sorting_exporter::get_read_structure();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,104 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace core_reportbuilder\external\columns\sort;
|
||||
|
||||
use external_api;
|
||||
use external_function_parameters;
|
||||
use external_single_structure;
|
||||
use external_value;
|
||||
use core_reportbuilder\manager;
|
||||
use core_reportbuilder\permission;
|
||||
use core_reportbuilder\local\helpers\report;
|
||||
use core_reportbuilder\external\custom_report_columns_sorting_exporter;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
global $CFG;
|
||||
require_once("{$CFG->libdir}/externallib.php");
|
||||
|
||||
/**
|
||||
* External method for toggling report column sorting
|
||||
*
|
||||
* @package core_reportbuilder
|
||||
* @copyright 2021 Paul Holden <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class toggle extends external_api {
|
||||
|
||||
/**
|
||||
* External method parameters
|
||||
*
|
||||
* @return external_function_parameters
|
||||
*/
|
||||
public static function execute_parameters(): external_function_parameters {
|
||||
return new external_function_parameters([
|
||||
'reportid' => new external_value(PARAM_INT, 'Report ID'),
|
||||
'columnid' => new external_value(PARAM_INT, 'Column ID'),
|
||||
'enabled' => new external_value(PARAM_BOOL, 'Sort enabled'),
|
||||
'direction' => new external_value(PARAM_INT, 'Sort direction', VALUE_DEFAULT, SORT_ASC),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* External method execution
|
||||
*
|
||||
* @param int $reportid
|
||||
* @param int $columnid
|
||||
* @param bool $enabled
|
||||
* @param int $direction
|
||||
* @return array
|
||||
*/
|
||||
public static function execute(int $reportid, int $columnid, bool $enabled, int $direction = SORT_ASC): array {
|
||||
global $PAGE;
|
||||
|
||||
[
|
||||
'reportid' => $reportid,
|
||||
'columnid' => $columnid,
|
||||
'enabled' => $enabled,
|
||||
'direction' => $direction,
|
||||
] = self::validate_parameters(self::execute_parameters(), [
|
||||
'reportid' => $reportid,
|
||||
'columnid' => $columnid,
|
||||
'enabled' => $enabled,
|
||||
'direction' => $direction,
|
||||
]);
|
||||
|
||||
$report = manager::get_report_from_id($reportid);
|
||||
|
||||
self::validate_context($report->get_context());
|
||||
permission::require_can_edit_report($report->get_report_persistent());
|
||||
|
||||
report::toggle_report_column_sorting($reportid, $columnid, $enabled, $direction);
|
||||
|
||||
$exporter = new custom_report_columns_sorting_exporter(null, [
|
||||
'report' => $report,
|
||||
]);
|
||||
|
||||
return (array) $exporter->export($PAGE->get_renderer('core'));
|
||||
}
|
||||
|
||||
/**
|
||||
* External method return value
|
||||
*
|
||||
* @return external_single_structure
|
||||
*/
|
||||
public static function execute_returns(): external_single_structure {
|
||||
return custom_report_columns_sorting_exporter::get_read_structure();
|
||||
}
|
||||
}
|
||||
+102
@@ -0,0 +1,102 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace core_reportbuilder\external\conditions;
|
||||
|
||||
use external_api;
|
||||
use external_function_parameters;
|
||||
use external_single_structure;
|
||||
use external_value;
|
||||
use core_reportbuilder\manager;
|
||||
use core_reportbuilder\permission;
|
||||
use core_reportbuilder\external\custom_report_conditions_exporter;
|
||||
use core_reportbuilder\local\helpers\report;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
global $CFG;
|
||||
require_once("{$CFG->libdir}/externallib.php");
|
||||
|
||||
/**
|
||||
* External method for adding report conditions
|
||||
*
|
||||
* @package core_reportbuilder
|
||||
* @copyright 2021 Paul Holden <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class add extends external_api {
|
||||
|
||||
/**
|
||||
* External method parameters
|
||||
*
|
||||
* @return external_function_parameters
|
||||
*/
|
||||
public static function execute_parameters(): external_function_parameters {
|
||||
return new external_function_parameters([
|
||||
'reportid' => new external_value(PARAM_INT, 'Report ID'),
|
||||
'uniqueidentifier' => new external_value(PARAM_RAW, 'Unique identifier of the condition'),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* External method execution
|
||||
*
|
||||
* @param int $reportid
|
||||
* @param string $uniqueidentifier
|
||||
* @return array
|
||||
*/
|
||||
public static function execute(int $reportid, string $uniqueidentifier): array {
|
||||
global $PAGE, $OUTPUT;
|
||||
|
||||
[
|
||||
'reportid' => $reportid,
|
||||
'uniqueidentifier' => $uniqueidentifier,
|
||||
] = self::validate_parameters(self::execute_parameters(), [
|
||||
'reportid' => $reportid,
|
||||
'uniqueidentifier' => $uniqueidentifier,
|
||||
]);
|
||||
|
||||
$report = manager::get_report_from_id($reportid);
|
||||
|
||||
self::validate_context($report->get_context());
|
||||
permission::require_can_edit_report($report->get_report_persistent());
|
||||
|
||||
report::add_report_condition($reportid, $uniqueidentifier);
|
||||
|
||||
// Set current URL and force bootstrap_renderer to initiate moodle page.
|
||||
$PAGE->set_url('/');
|
||||
$OUTPUT->header();
|
||||
$PAGE->start_collecting_javascript_requirements();
|
||||
|
||||
$exporter = new custom_report_conditions_exporter(null, ['report' => $report]);
|
||||
|
||||
$export = $exporter->export($PAGE->get_renderer('core'));
|
||||
$export->javascript = $PAGE->requires->get_end_code();
|
||||
|
||||
return (array) $export;
|
||||
}
|
||||
|
||||
/**
|
||||
* External method return value
|
||||
*
|
||||
* @return external_value
|
||||
*/
|
||||
public static function execute_returns(): external_single_structure {
|
||||
return custom_report_conditions_exporter::get_read_structure();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace core_reportbuilder\external\conditions;
|
||||
|
||||
use external_api;
|
||||
use external_function_parameters;
|
||||
use external_single_structure;
|
||||
use external_value;
|
||||
use core_reportbuilder\manager;
|
||||
use core_reportbuilder\permission;
|
||||
use core_reportbuilder\external\custom_report_conditions_exporter;
|
||||
use core_reportbuilder\local\helpers\report;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
global $CFG;
|
||||
require_once("{$CFG->libdir}/externallib.php");
|
||||
|
||||
/**
|
||||
* External method for deleting report conditions
|
||||
*
|
||||
* @package core_reportbuilder
|
||||
* @copyright 2021 Paul Holden <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class delete extends external_api {
|
||||
|
||||
/**
|
||||
* External method parameters
|
||||
*
|
||||
* @return external_function_parameters
|
||||
*/
|
||||
public static function execute_parameters(): external_function_parameters {
|
||||
return new external_function_parameters([
|
||||
'reportid' => new external_value(PARAM_INT, 'Report ID'),
|
||||
'conditionid' => new external_value(PARAM_INT, 'Condition ID'),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* External method execution
|
||||
*
|
||||
* @param int $reportid
|
||||
* @param int $conditionid
|
||||
* @return array
|
||||
*/
|
||||
public static function execute(int $reportid, int $conditionid): array {
|
||||
global $PAGE, $OUTPUT;
|
||||
|
||||
[
|
||||
'reportid' => $reportid,
|
||||
'conditionid' => $conditionid,
|
||||
] = self::validate_parameters(self::execute_parameters(), [
|
||||
'reportid' => $reportid,
|
||||
'conditionid' => $conditionid,
|
||||
]);
|
||||
|
||||
$report = manager::get_report_from_id($reportid);
|
||||
|
||||
self::validate_context($report->get_context());
|
||||
permission::require_can_edit_report($report->get_report_persistent());
|
||||
|
||||
report::delete_report_condition($reportid, $conditionid);
|
||||
|
||||
// Set current URL and force bootstrap_renderer to initiate moodle page.
|
||||
$PAGE->set_url('/');
|
||||
$OUTPUT->header();
|
||||
$PAGE->start_collecting_javascript_requirements();
|
||||
|
||||
$exporter = new custom_report_conditions_exporter(null, ['report' => $report]);
|
||||
|
||||
$export = $exporter->export($PAGE->get_renderer('core'));
|
||||
$export->javascript = $PAGE->requires->get_end_code();
|
||||
|
||||
return (array) $export;
|
||||
}
|
||||
|
||||
/**
|
||||
* External method return value
|
||||
*
|
||||
* @return external_value
|
||||
*/
|
||||
public static function execute_returns(): external_single_structure {
|
||||
return custom_report_conditions_exporter::get_read_structure();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,106 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace core_reportbuilder\external\conditions;
|
||||
|
||||
use external_api;
|
||||
use external_function_parameters;
|
||||
use external_single_structure;
|
||||
use external_value;
|
||||
use core_reportbuilder\manager;
|
||||
use core_reportbuilder\permission;
|
||||
use core_reportbuilder\external\custom_report_conditions_exporter;
|
||||
use core_reportbuilder\local\helpers\report;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
global $CFG;
|
||||
require_once("{$CFG->libdir}/externallib.php");
|
||||
|
||||
/**
|
||||
* External method for re-ordering report conditions
|
||||
*
|
||||
* @package core_reportbuilder
|
||||
* @copyright 2021 Paul Holden <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class reorder extends external_api {
|
||||
|
||||
/**
|
||||
* External method parameters
|
||||
*
|
||||
* @return external_function_parameters
|
||||
*/
|
||||
public static function execute_parameters(): external_function_parameters {
|
||||
return new external_function_parameters([
|
||||
'reportid' => new external_value(PARAM_INT, 'Report ID'),
|
||||
'conditionid' => new external_value(PARAM_INT, 'Condition ID'),
|
||||
'position' => new external_value(PARAM_INT, 'New condition position')
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* External method execution
|
||||
*
|
||||
* @param int $reportid
|
||||
* @param int $conditionid
|
||||
* @param int $position
|
||||
* @return array
|
||||
*/
|
||||
public static function execute(int $reportid, int $conditionid, int $position): array {
|
||||
global $PAGE, $OUTPUT;
|
||||
|
||||
[
|
||||
'reportid' => $reportid,
|
||||
'conditionid' => $conditionid,
|
||||
'position' => $position,
|
||||
] = self::validate_parameters(self::execute_parameters(), [
|
||||
'reportid' => $reportid,
|
||||
'conditionid' => $conditionid,
|
||||
'position' => $position,
|
||||
]);
|
||||
|
||||
$report = manager::get_report_from_id($reportid);
|
||||
|
||||
self::validate_context($report->get_context());
|
||||
permission::require_can_edit_report($report->get_report_persistent());
|
||||
|
||||
report::reorder_report_condition($reportid, $conditionid, $position);
|
||||
|
||||
// Set current URL and force bootstrap_renderer to initiate moodle page.
|
||||
$PAGE->set_url('/');
|
||||
$OUTPUT->header();
|
||||
$PAGE->start_collecting_javascript_requirements();
|
||||
|
||||
$exporter = new custom_report_conditions_exporter(null, ['report' => $report]);
|
||||
|
||||
$export = $exporter->export($PAGE->get_renderer('core'));
|
||||
$export->javascript = $PAGE->requires->get_end_code();
|
||||
|
||||
return (array) $export;
|
||||
}
|
||||
|
||||
/**
|
||||
* External method return value
|
||||
*
|
||||
* @return external_value
|
||||
*/
|
||||
public static function execute_returns(): external_single_structure {
|
||||
return custom_report_conditions_exporter::get_read_structure();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace core_reportbuilder\external\conditions;
|
||||
|
||||
use external_api;
|
||||
use external_function_parameters;
|
||||
use external_single_structure;
|
||||
use external_value;
|
||||
use core_reportbuilder\manager;
|
||||
use core_reportbuilder\permission;
|
||||
use core_reportbuilder\external\custom_report_conditions_exporter;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
global $CFG;
|
||||
require_once("{$CFG->libdir}/externallib.php");
|
||||
|
||||
/**
|
||||
* External method for resetting report conditions
|
||||
*
|
||||
* @package core_reportbuilder
|
||||
* @copyright 2021 Paul Holden <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class reset extends external_api {
|
||||
|
||||
/**
|
||||
* External method parameters
|
||||
*
|
||||
* @return external_function_parameters
|
||||
*/
|
||||
public static function execute_parameters(): external_function_parameters {
|
||||
return new external_function_parameters([
|
||||
'reportid' => new external_value(PARAM_INT, 'Report ID'),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* External method execution
|
||||
*
|
||||
* @param int $reportid
|
||||
* @return array
|
||||
*/
|
||||
public static function execute(int $reportid): array {
|
||||
global $PAGE, $OUTPUT;
|
||||
|
||||
[
|
||||
'reportid' => $reportid,
|
||||
] = self::validate_parameters(self::execute_parameters(), [
|
||||
'reportid' => $reportid,
|
||||
]);
|
||||
|
||||
$report = manager::get_report_from_id($reportid);
|
||||
|
||||
self::validate_context($report->get_context());
|
||||
permission::require_can_edit_report($report->get_report_persistent());
|
||||
|
||||
$report->set_condition_values([]);
|
||||
|
||||
// Set current URL and force bootstrap_renderer to initiate moodle page.
|
||||
$PAGE->set_url('/');
|
||||
$OUTPUT->header();
|
||||
$PAGE->start_collecting_javascript_requirements();
|
||||
|
||||
$exporter = new custom_report_conditions_exporter(null, ['report' => $report]);
|
||||
|
||||
$export = $exporter->export($PAGE->get_renderer('core'));
|
||||
$export->javascript = $PAGE->requires->get_end_code();
|
||||
|
||||
return (array) $export;
|
||||
}
|
||||
|
||||
/**
|
||||
* External method return value
|
||||
*
|
||||
* @return external_value
|
||||
*/
|
||||
public static function execute_returns(): external_single_structure {
|
||||
return custom_report_conditions_exporter::get_read_structure();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,131 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace core_reportbuilder\external;
|
||||
|
||||
use pix_icon;
|
||||
use renderer_base;
|
||||
use core\external\exporter;
|
||||
use core_reportbuilder\local\models\column;
|
||||
use core_reportbuilder\local\report\base;
|
||||
|
||||
/**
|
||||
* Custom report columns sorting exporter class
|
||||
*
|
||||
* @package core_reportbuilder
|
||||
* @copyright 2021 David Matamoros <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class custom_report_columns_sorting_exporter extends exporter {
|
||||
|
||||
/**
|
||||
* Return a list of objects that are related to the exporter
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected static function define_related(): array {
|
||||
return [
|
||||
'report' => base::class,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the list of additional properties for read structure and export
|
||||
*
|
||||
* @return array[]
|
||||
*/
|
||||
protected static function define_other_properties(): array {
|
||||
return [
|
||||
'hassortablecolumns' => [
|
||||
'type' => PARAM_BOOL,
|
||||
],
|
||||
'sortablecolumns' => [
|
||||
'type' => [
|
||||
'id' => ['type' => PARAM_INT],
|
||||
'title' => ['type' => PARAM_TEXT],
|
||||
'heading' => ['type' => PARAM_TEXT],
|
||||
'sortdirection' => ['type' => PARAM_INT],
|
||||
'sortenabled' => ['type' => PARAM_INT],
|
||||
'sortorder' => ['type' => PARAM_INT],
|
||||
'sorticon' => [
|
||||
'type' => [
|
||||
'key' => ['type' => PARAM_RAW],
|
||||
'component' => ['type' => PARAM_COMPONENT],
|
||||
'title' => ['type' => PARAM_NOTAGS],
|
||||
],
|
||||
],
|
||||
'movetitle' => ['type' => PARAM_TEXT],
|
||||
'sortenabledtitle' => ['type' => PARAM_TEXT],
|
||||
],
|
||||
'optional' => true,
|
||||
'multiple' => true,
|
||||
],
|
||||
'helpicon' => [
|
||||
'type' => PARAM_RAW,
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the additional values to inject while exporting
|
||||
*
|
||||
* @param renderer_base $output
|
||||
* @return array
|
||||
*/
|
||||
protected function get_other_values(renderer_base $output): array {
|
||||
/** @var base $report */
|
||||
$report = $this->related['report'];
|
||||
|
||||
$reportid = $report->get_report_persistent()->get('id');
|
||||
$activecolumns = column::get_records(['reportid' => $reportid], 'sortorder');
|
||||
$sortablecolumns = array_filter($activecolumns, function(column $persistent) use($report) {
|
||||
$column = $report->get_column($persistent->get('uniqueidentifier'));
|
||||
return $column && $column->get_is_sortable();
|
||||
});
|
||||
|
||||
$sortablecolumns = array_map(function(column $persistent) use ($report) {
|
||||
$columntitle = $report->get_column($persistent->get('uniqueidentifier'))->get_title();
|
||||
$columnheading = $persistent->get('heading') ?: $columntitle;
|
||||
|
||||
$columnsortascending = ($persistent->get('sortdirection') == SORT_ASC);
|
||||
$sortenabledtitle = $persistent->get('sortenabled') ? 'columnsortdisable' : 'columnsortenable';
|
||||
$sortdirectiontitle = $columnsortascending ? 'columnsortdirectiondesc' : 'columnsortdirectionasc';
|
||||
|
||||
$icon = $columnsortascending ? 't/uplong' : 't/downlong';
|
||||
$sorticon = new pix_icon($icon, get_string($sortdirectiontitle, 'core_reportbuilder', $columntitle));
|
||||
|
||||
return [
|
||||
'id' => $persistent->get('id'),
|
||||
'title' => $columntitle,
|
||||
'heading' => $columnheading,
|
||||
'sortdirection' => $persistent->get('sortdirection'),
|
||||
'sortenabled' => (int)$persistent->get('sortenabled'),
|
||||
'sortorder' => $persistent->get('sortorder'),
|
||||
'sorticon' => $sorticon->export_for_pix(),
|
||||
'movetitle' => get_string('movesorting', 'core_reportbuilder', $columntitle),
|
||||
'sortenabledtitle' => get_string($sortenabledtitle, 'core_reportbuilder', $columntitle),
|
||||
];
|
||||
}, $sortablecolumns);
|
||||
|
||||
return [
|
||||
'hassortablecolumns' => !empty($sortablecolumns),
|
||||
'sortablecolumns' => array_values($sortablecolumns),
|
||||
'helpicon' => $output->help_icon('sorting', 'core_reportbuilder'),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,151 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace core_reportbuilder\external;
|
||||
|
||||
use renderer_base;
|
||||
use core\external\exporter;
|
||||
use core_reportbuilder\form\condition;
|
||||
use core_reportbuilder\local\report\base;
|
||||
use core_reportbuilder\local\models\filter;
|
||||
|
||||
/**
|
||||
* Custom report conditions exporter class
|
||||
*
|
||||
* @package core_reportbuilder
|
||||
* @copyright 2021 Paul Holden <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class custom_report_conditions_exporter extends exporter {
|
||||
|
||||
/**
|
||||
* Return a list of objects that are related to the exporter
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected static function define_related(): array {
|
||||
return [
|
||||
'report' => base::class,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the list of additional properties for read structure and export
|
||||
*
|
||||
* @return array[]
|
||||
*/
|
||||
protected static function define_other_properties(): array {
|
||||
return [
|
||||
'hasavailableconditions' => [
|
||||
'type' => PARAM_BOOL,
|
||||
],
|
||||
'availableconditions' => [
|
||||
'type' => [
|
||||
'optiongroup' => [
|
||||
'type' => [
|
||||
'text' => ['type' => PARAM_TEXT],
|
||||
'values' => [
|
||||
'type' => [
|
||||
'value' => ['type' => PARAM_TEXT],
|
||||
'visiblename' => ['type' => PARAM_TEXT],
|
||||
],
|
||||
'multiple' => true,
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
'multiple' => true,
|
||||
'optional' => true
|
||||
],
|
||||
'hasactiveconditions' => [
|
||||
'type' => PARAM_BOOL,
|
||||
],
|
||||
'activeconditionsform' => [
|
||||
'type' => PARAM_RAW,
|
||||
'optional' => true,
|
||||
],
|
||||
'helpicon' => [
|
||||
'type' => PARAM_RAW,
|
||||
'optional' => true,
|
||||
],
|
||||
'javascript' => [
|
||||
'type' => PARAM_RAW,
|
||||
'optional' => true,
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the additional values to inject while exporting
|
||||
*
|
||||
* @param renderer_base $output
|
||||
* @return array
|
||||
*/
|
||||
protected function get_other_values(renderer_base $output): array {
|
||||
/** @var base $report */
|
||||
$report = $this->related['report'];
|
||||
$reportid = $report->get_report_persistent()->get('id');
|
||||
|
||||
// Current condition instances contained in the report.
|
||||
$conditioninstances = filter::get_condition_records($reportid, 'filterorder');
|
||||
$conditionidentifiers = array_map(static function(filter $condition): string {
|
||||
return $condition->get('uniqueidentifier');
|
||||
}, $conditioninstances);
|
||||
|
||||
$availableconditions = [];
|
||||
|
||||
// Populate available conditions.
|
||||
foreach ($report->get_conditions() as $condition) {
|
||||
if (in_array($condition->get_unique_identifier(), $conditionidentifiers)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$entityname = $condition->get_entity_name();
|
||||
if (!array_key_exists($entityname, $availableconditions)) {
|
||||
$availableconditions[$entityname] = [
|
||||
'optiongroup' => [
|
||||
'text' => $report->get_entity_title($entityname)->out(),
|
||||
'values' => [],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
$availableconditions[$entityname]['optiongroup']['values'][] = [
|
||||
'value' => $condition->get_unique_identifier(),
|
||||
'visiblename' => $condition->get_header(),
|
||||
];
|
||||
}
|
||||
|
||||
// Generate filters form if report contains any filters.
|
||||
$conditionspresent = !empty($conditioninstances);
|
||||
if ($conditionspresent) {
|
||||
$conditionsform = new condition(null, null, 'post', '', [], true, [
|
||||
'reportid' => $reportid,
|
||||
]);
|
||||
$conditionsform->set_data_for_dynamic_submission();
|
||||
}
|
||||
|
||||
return [
|
||||
'hasavailableconditions' => !empty($availableconditions),
|
||||
'availableconditions' => array_values($availableconditions),
|
||||
'hasactiveconditions' => $conditionspresent,
|
||||
'activeconditionsform' => $conditionspresent ? $conditionsform->render() : '',
|
||||
'helpicon' => $output->help_icon('conditions', 'core_reportbuilder'),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,181 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace core_reportbuilder\external;
|
||||
|
||||
use renderer_base;
|
||||
use core\persistent;
|
||||
use core\external\persistent_exporter;
|
||||
use core_reportbuilder\manager;
|
||||
use core_reportbuilder\datasource;
|
||||
use core_reportbuilder\form\filter as form_filter;
|
||||
use core_reportbuilder\local\models\report;
|
||||
use core_reportbuilder\table\custom_report_table;
|
||||
use core_reportbuilder\table\custom_report_table_filterset;
|
||||
use core_reportbuilder\table\custom_report_table_view;
|
||||
use core_reportbuilder\table\custom_report_table_view_filterset;
|
||||
use core_reportbuilder\local\helpers\report as report_helper;
|
||||
|
||||
/**
|
||||
* Custom report exporter class
|
||||
*
|
||||
* @package core_reportbuilder
|
||||
* @copyright 2021 David Matamoros <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class custom_report_exporter extends persistent_exporter {
|
||||
|
||||
/** @var report The persistent object we will export. */
|
||||
protected $persistent = null;
|
||||
|
||||
/** @var bool */
|
||||
protected $editmode;
|
||||
|
||||
/** @var bool $showeditbutton When showing the report on view.php the Edit button has to be hidden */
|
||||
protected $showeditbutton;
|
||||
|
||||
/** @var string */
|
||||
protected $download;
|
||||
|
||||
/**
|
||||
* report_exporter constructor.
|
||||
*
|
||||
* @param persistent $persistent
|
||||
* @param array $related
|
||||
* @param bool $editmode
|
||||
* @param bool $showeditbutton
|
||||
* @param string $download
|
||||
*/
|
||||
public function __construct(persistent $persistent, array $related = [], bool $editmode = true,
|
||||
bool $showeditbutton = true, string $download = '') {
|
||||
|
||||
parent::__construct($persistent, $related);
|
||||
$this->editmode = $editmode;
|
||||
$this->showeditbutton = $showeditbutton;
|
||||
$this->download = $download;
|
||||
}
|
||||
/**
|
||||
* Return the name of the class we are exporting
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected static function define_class(): string {
|
||||
return report::class;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a list of objects that are related to the persistent
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected static function define_related(): array {
|
||||
return [
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a list of additional properties used only for display
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected static function define_other_properties(): array {
|
||||
return [
|
||||
'table' => ['type' => PARAM_RAW],
|
||||
'sidebarmenucards' => ['type' => custom_report_menu_cards_exporter::read_properties_definition()],
|
||||
'conditions' => ['type' => custom_report_conditions_exporter::read_properties_definition()],
|
||||
'filters' => ['type' => custom_report_filters_exporter::read_properties_definition()],
|
||||
'sorting' => ['type' => custom_report_columns_sorting_exporter::read_properties_definition()],
|
||||
'filtersapplied' => ['type' => PARAM_INT],
|
||||
'filtersform' => [
|
||||
'type' => PARAM_RAW,
|
||||
'optional' => true,
|
||||
],
|
||||
'editmode' => ['type' => PARAM_INT],
|
||||
'showeditbutton' => ['type' => PARAM_BOOL],
|
||||
'javascript' => ['type' => PARAM_RAW],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get additional values to inject while exporting
|
||||
*
|
||||
* @param renderer_base $output
|
||||
* @return array
|
||||
*/
|
||||
protected function get_other_values(renderer_base $output): array {
|
||||
$filtersform = '';
|
||||
$menucards = [];
|
||||
|
||||
if ($this->editmode) {
|
||||
$table = custom_report_table::create($this->persistent->get('id'));
|
||||
$table->set_filterset(new custom_report_table_filterset());
|
||||
} else {
|
||||
$table = custom_report_table_view::create($this->persistent->get('id'), $this->download);
|
||||
$table->set_filterset(new custom_report_table_view_filterset());
|
||||
|
||||
// Generate filters form if report contains any filters.
|
||||
$source = $this->persistent->get('source');
|
||||
/** @var datasource $datasource */
|
||||
$datasource = new $source($this->persistent);
|
||||
|
||||
if (!empty($datasource->get_active_filters())) {
|
||||
$filtersform = $this->generate_filters_form()->render();
|
||||
}
|
||||
}
|
||||
|
||||
$report = manager::get_report_from_persistent($this->persistent);
|
||||
|
||||
$conditionsexporter = new custom_report_conditions_exporter(null, ['report' => $report]);
|
||||
$filtersexporter = new custom_report_filters_exporter(null, ['report' => $report]);
|
||||
$sortingexporter = new custom_report_columns_sorting_exporter(null, ['report' => $report]);
|
||||
if ($this->editmode) {
|
||||
$menucardexporter = new custom_report_menu_cards_exporter(null, [
|
||||
'menucards' => report_helper::get_available_columns($report->get_report_persistent())
|
||||
]);
|
||||
$menucards = (array) $menucardexporter->export($output);
|
||||
}
|
||||
|
||||
return [
|
||||
'table' => $output->render($table),
|
||||
'sidebarmenucards' => $menucards,
|
||||
'conditions' => (array) $conditionsexporter->export($output),
|
||||
'filters' => (array) $filtersexporter->export($output),
|
||||
'sorting' => (array) $sortingexporter->export($output),
|
||||
'filtersapplied' => $report->get_applied_filter_count(),
|
||||
'filtersform' => $filtersform,
|
||||
'editmode' => (int)$this->editmode,
|
||||
'showeditbutton' => $this->showeditbutton,
|
||||
'javascript' => '',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate filters form for the report
|
||||
*
|
||||
* @return form_filter
|
||||
*/
|
||||
private function generate_filters_form(): form_filter {
|
||||
$filtersform = new form_filter(null, null, 'post', '', [], true, [
|
||||
'reportid' => $this->persistent->get('id'),
|
||||
'parameters' => json_encode([]),
|
||||
]);
|
||||
$filtersform->set_data_for_dynamic_submission();
|
||||
|
||||
return $filtersform;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,162 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace core_reportbuilder\external;
|
||||
|
||||
use renderer_base;
|
||||
use core\external\exporter;
|
||||
use core_reportbuilder\local\report\base;
|
||||
use core_reportbuilder\local\models\filter;
|
||||
use core_reportbuilder\output\filter_heading_editable;
|
||||
|
||||
/**
|
||||
* Custom report filters exporter class
|
||||
*
|
||||
* @package core_reportbuilder
|
||||
* @copyright 2021 Paul Holden <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class custom_report_filters_exporter extends exporter {
|
||||
|
||||
/**
|
||||
* Return a list of objects that are related to the exporter
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected static function define_related(): array {
|
||||
return [
|
||||
'report' => base::class,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the list of additional properties for read structure and export
|
||||
*
|
||||
* @return array[]
|
||||
*/
|
||||
protected static function define_other_properties(): array {
|
||||
return [
|
||||
'hasavailablefilters' => [
|
||||
'type' => PARAM_BOOL,
|
||||
],
|
||||
'availablefilters' => [
|
||||
'type' => [
|
||||
'optiongroup' => [
|
||||
'type' => [
|
||||
'text' => ['type' => PARAM_TEXT],
|
||||
'values' => [
|
||||
'type' => [
|
||||
'value' => ['type' => PARAM_TEXT],
|
||||
'visiblename' => ['type' => PARAM_TEXT],
|
||||
],
|
||||
'multiple' => true,
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
'multiple' => true,
|
||||
'optional' => true
|
||||
],
|
||||
'hasactivefilters' => [
|
||||
'type' => PARAM_BOOL,
|
||||
],
|
||||
'activefilters' => [
|
||||
'type' => [
|
||||
'id' => ['type' => PARAM_INT],
|
||||
'heading' => ['type' => PARAM_TEXT],
|
||||
'headingeditable' => ['type' => PARAM_RAW],
|
||||
'sortorder' => ['type' => PARAM_INT],
|
||||
'movetitle' => ['type' => PARAM_TEXT],
|
||||
'entityname' => ['type' => PARAM_TEXT],
|
||||
],
|
||||
'multiple' => true,
|
||||
'optional' => true
|
||||
],
|
||||
'helpicon' => [
|
||||
'type' => PARAM_RAW,
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the additional values to inject while exporting
|
||||
*
|
||||
* @param renderer_base $output
|
||||
* @return array
|
||||
*/
|
||||
protected function get_other_values(renderer_base $output): array {
|
||||
/** @var base $report */
|
||||
$report = $this->related['report'];
|
||||
|
||||
// Current filter instances contained in the report.
|
||||
$filterinstances = filter::get_filter_records($report->get_report_persistent()->get('id'), 'filterorder');
|
||||
$filteridentifiers = array_map(static function(filter $filter): string {
|
||||
return $filter->get('uniqueidentifier');
|
||||
}, $filterinstances);
|
||||
|
||||
$availablefilters = $activefilters = [];
|
||||
|
||||
// Populate available filters.
|
||||
foreach ($report->get_filters() as $filter) {
|
||||
if (in_array($filter->get_unique_identifier(), $filteridentifiers)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$entityname = $filter->get_entity_name();
|
||||
if (!array_key_exists($entityname, $availablefilters)) {
|
||||
$availablefilters[$entityname] = [
|
||||
'optiongroup' => [
|
||||
'text' => $report->get_entity_title($entityname)->out(),
|
||||
'values' => [],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
$availablefilters[$entityname]['optiongroup']['values'][] = [
|
||||
'value' => $filter->get_unique_identifier(),
|
||||
'visiblename' => $filter->get_header(),
|
||||
];
|
||||
}
|
||||
|
||||
// Populate active filters.
|
||||
foreach ($filterinstances as $filter) {
|
||||
$editable = new filter_heading_editable($filter->get('id'));
|
||||
|
||||
$filterinstance = $report->get_filter($filter->get('uniqueidentifier'));
|
||||
$entityname = $filterinstance->get_entity_name();
|
||||
$displayvalue = $filterinstance->get_header();
|
||||
|
||||
$activefilters[] = [
|
||||
'id' => $filter->get('id'),
|
||||
'entityname' => $report->get_entity_title($entityname)->out(),
|
||||
'heading' => $displayvalue,
|
||||
'headingeditable' => $editable->render($output),
|
||||
'sortorder' => $filter->get('filterorder'),
|
||||
'movetitle' => get_string('movefilter', 'core_reportbuilder', $displayvalue),
|
||||
];
|
||||
}
|
||||
|
||||
return [
|
||||
'hasavailablefilters' => !empty($availablefilters),
|
||||
'availablefilters' => array_values($availablefilters),
|
||||
'hasactivefilters' => !empty($activefilters),
|
||||
'activefilters' => $activefilters,
|
||||
'helpicon' => $output->help_icon('filters', 'core_reportbuilder'),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace core_reportbuilder\external;
|
||||
|
||||
use renderer_base;
|
||||
use core\external\exporter;
|
||||
|
||||
/**
|
||||
* Custom report menu cards exporter class
|
||||
*
|
||||
* @package core_reportbuilder
|
||||
* @copyright 2021 David Matamoros <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class custom_report_menu_cards_exporter extends exporter {
|
||||
|
||||
/**
|
||||
* Return a list of objects that are related to the exporter
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected static function define_related(): array {
|
||||
return [
|
||||
'menucards' => 'array[]',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the list of additional properties for read structure and export
|
||||
*
|
||||
* @return array[]
|
||||
*/
|
||||
protected static function define_other_properties(): array {
|
||||
return [
|
||||
'menucards' => [
|
||||
'type' => [
|
||||
'name' => [
|
||||
'type' => PARAM_TEXT,
|
||||
'optional' => true,
|
||||
],
|
||||
'key' => [
|
||||
'type' => PARAM_TEXT,
|
||||
'optional' => true,
|
||||
],
|
||||
'items' => [
|
||||
'type' => [
|
||||
'name' => [
|
||||
'type' => PARAM_TEXT,
|
||||
],
|
||||
'identifier' => [
|
||||
'type' => PARAM_TEXT,
|
||||
],
|
||||
'title' => [
|
||||
'type' => PARAM_TEXT,
|
||||
],
|
||||
'action' => [
|
||||
'type' => PARAM_TEXT,
|
||||
],
|
||||
],
|
||||
'optional' => true,
|
||||
'multiple' => true,
|
||||
],
|
||||
],
|
||||
'optional' => true,
|
||||
'multiple' => true,
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the additional values to inject while exporting
|
||||
*
|
||||
* @param renderer_base $output
|
||||
* @return array
|
||||
*/
|
||||
protected function get_other_values(renderer_base $output): array {
|
||||
return [
|
||||
'menucards' => $this->related['menucards']
|
||||
];
|
||||
}
|
||||
}
|
||||
+96
@@ -0,0 +1,96 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace core_reportbuilder\external\filters;
|
||||
|
||||
use external_api;
|
||||
use external_function_parameters;
|
||||
use external_single_structure;
|
||||
use external_value;
|
||||
use core_reportbuilder\manager;
|
||||
use core_reportbuilder\permission;
|
||||
use core_reportbuilder\external\custom_report_filters_exporter;
|
||||
use core_reportbuilder\local\helpers\report;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
global $CFG;
|
||||
require_once("{$CFG->libdir}/externallib.php");
|
||||
|
||||
/**
|
||||
* External method for adding report filters
|
||||
*
|
||||
* @package core_reportbuilder
|
||||
* @copyright 2021 Paul Holden <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class add extends external_api {
|
||||
|
||||
/**
|
||||
* External method parameters
|
||||
*
|
||||
* @return external_function_parameters
|
||||
*/
|
||||
public static function execute_parameters(): external_function_parameters {
|
||||
return new external_function_parameters([
|
||||
'reportid' => new external_value(PARAM_INT, 'Report ID'),
|
||||
'uniqueidentifier' => new external_value(PARAM_RAW, 'Unique identifier of the filter'),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* External method execution
|
||||
*
|
||||
* @param int $reportid
|
||||
* @param string $uniqueidentifier
|
||||
* @return array
|
||||
*/
|
||||
public static function execute(int $reportid, string $uniqueidentifier): array {
|
||||
global $PAGE;
|
||||
|
||||
[
|
||||
'reportid' => $reportid,
|
||||
'uniqueidentifier' => $uniqueidentifier,
|
||||
] = self::validate_parameters(self::execute_parameters(), [
|
||||
'reportid' => $reportid,
|
||||
'uniqueidentifier' => $uniqueidentifier,
|
||||
]);
|
||||
|
||||
$report = manager::get_report_from_id($reportid);
|
||||
|
||||
self::validate_context($report->get_context());
|
||||
permission::require_can_edit_report($report->get_report_persistent());
|
||||
|
||||
report::add_report_filter($reportid, $uniqueidentifier);
|
||||
|
||||
$exporter = new custom_report_filters_exporter(null, [
|
||||
'report' => $report,
|
||||
]);
|
||||
|
||||
return (array) $exporter->export($PAGE->get_renderer('core'));
|
||||
}
|
||||
|
||||
/**
|
||||
* External method return value
|
||||
*
|
||||
* @return external_single_structure
|
||||
*/
|
||||
public static function execute_returns(): external_single_structure {
|
||||
return custom_report_filters_exporter::get_read_structure();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace core_reportbuilder\external\filters;
|
||||
|
||||
use external_api;
|
||||
use external_function_parameters;
|
||||
use external_single_structure;
|
||||
use external_value;
|
||||
use core_reportbuilder\manager;
|
||||
use core_reportbuilder\permission;
|
||||
use core_reportbuilder\external\custom_report_filters_exporter;
|
||||
use core_reportbuilder\local\helpers\report;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
global $CFG;
|
||||
require_once("{$CFG->libdir}/externallib.php");
|
||||
|
||||
/**
|
||||
* External method for deleting report filters
|
||||
*
|
||||
* @package core_reportbuilder
|
||||
* @copyright 2021 Paul Holden <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class delete extends external_api {
|
||||
|
||||
/**
|
||||
* External method parameters
|
||||
*
|
||||
* @return external_function_parameters
|
||||
*/
|
||||
public static function execute_parameters(): external_function_parameters {
|
||||
return new external_function_parameters([
|
||||
'reportid' => new external_value(PARAM_INT, 'Report ID'),
|
||||
'filterid' => new external_value(PARAM_INT, 'Filter ID'),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* External method execution
|
||||
*
|
||||
* @param int $reportid
|
||||
* @param int $filterid
|
||||
* @return array
|
||||
*/
|
||||
public static function execute(int $reportid, int $filterid): array {
|
||||
global $PAGE;
|
||||
|
||||
[
|
||||
'reportid' => $reportid,
|
||||
'filterid' => $filterid,
|
||||
] = self::validate_parameters(self::execute_parameters(), [
|
||||
'reportid' => $reportid,
|
||||
'filterid' => $filterid,
|
||||
]);
|
||||
|
||||
$report = manager::get_report_from_id($reportid);
|
||||
|
||||
self::validate_context($report->get_context());
|
||||
permission::require_can_edit_report($report->get_report_persistent());
|
||||
|
||||
report::delete_report_filter($reportid, $filterid);
|
||||
|
||||
$exporter = new custom_report_filters_exporter(null, [
|
||||
'report' => $report,
|
||||
]);
|
||||
|
||||
return (array) $exporter->export($PAGE->get_renderer('core'));
|
||||
}
|
||||
|
||||
/**
|
||||
* External method return value
|
||||
*
|
||||
* @return external_single_structure
|
||||
*/
|
||||
public static function execute_returns(): external_single_structure {
|
||||
return custom_report_filters_exporter::get_read_structure();
|
||||
}
|
||||
}
|
||||
+100
@@ -0,0 +1,100 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace core_reportbuilder\external\filters;
|
||||
|
||||
use external_api;
|
||||
use external_function_parameters;
|
||||
use external_single_structure;
|
||||
use external_value;
|
||||
use core_reportbuilder\manager;
|
||||
use core_reportbuilder\permission;
|
||||
use core_reportbuilder\external\custom_report_filters_exporter;
|
||||
use core_reportbuilder\local\helpers\report;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
global $CFG;
|
||||
require_once("{$CFG->libdir}/externallib.php");
|
||||
|
||||
/**
|
||||
* External method for re-ordering report filters
|
||||
*
|
||||
* @package core_reportbuilder
|
||||
* @copyright 2021 Paul Holden <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class reorder extends external_api {
|
||||
|
||||
/**
|
||||
* External method parameters
|
||||
*
|
||||
* @return external_function_parameters
|
||||
*/
|
||||
public static function execute_parameters(): external_function_parameters {
|
||||
return new external_function_parameters([
|
||||
'reportid' => new external_value(PARAM_INT, 'Report ID'),
|
||||
'filterid' => new external_value(PARAM_INT, 'Filter ID'),
|
||||
'position' => new external_value(PARAM_INT, 'New filter position')
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* External method execution
|
||||
*
|
||||
* @param int $reportid
|
||||
* @param int $filterid
|
||||
* @param int $position
|
||||
* @return array
|
||||
*/
|
||||
public static function execute(int $reportid, int $filterid, int $position): array {
|
||||
global $PAGE;
|
||||
|
||||
[
|
||||
'reportid' => $reportid,
|
||||
'filterid' => $filterid,
|
||||
'position' => $position,
|
||||
] = self::validate_parameters(self::execute_parameters(), [
|
||||
'reportid' => $reportid,
|
||||
'filterid' => $filterid,
|
||||
'position' => $position,
|
||||
]);
|
||||
|
||||
$report = manager::get_report_from_id($reportid);
|
||||
|
||||
self::validate_context($report->get_context());
|
||||
permission::require_can_edit_report($report->get_report_persistent());
|
||||
|
||||
report::reorder_report_filter($reportid, $filterid, $position);
|
||||
|
||||
$exporter = new custom_report_filters_exporter(null, [
|
||||
'report' => $report,
|
||||
]);
|
||||
|
||||
return (array) $exporter->export($PAGE->get_renderer('core'));
|
||||
}
|
||||
|
||||
/**
|
||||
* External method return value
|
||||
*
|
||||
* @return external_single_structure
|
||||
*/
|
||||
public static function execute_returns(): external_single_structure {
|
||||
return custom_report_filters_exporter::get_read_structure();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace core_reportbuilder\external\reports;
|
||||
|
||||
use external_api;
|
||||
use external_function_parameters;
|
||||
use external_value;
|
||||
use core_reportbuilder\permission;
|
||||
use core_reportbuilder\local\helpers\report;
|
||||
use core_reportbuilder\local\models\report as report_model;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
global $CFG;
|
||||
require_once("{$CFG->libdir}/externallib.php");
|
||||
|
||||
/**
|
||||
* External method for deleting reports
|
||||
*
|
||||
* @package core_reportbuilder
|
||||
* @copyright 2021 Paul Holden <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class delete extends external_api {
|
||||
|
||||
/**
|
||||
* External method parameters
|
||||
*
|
||||
* @return external_function_parameters
|
||||
*/
|
||||
public static function execute_parameters(): external_function_parameters {
|
||||
return new external_function_parameters([
|
||||
'reportid' => new external_value(PARAM_INT, 'Report ID'),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* External method execution
|
||||
*
|
||||
* @param int $reportid
|
||||
* @return bool
|
||||
*/
|
||||
public static function execute(int $reportid): bool {
|
||||
[
|
||||
'reportid' => $reportid,
|
||||
] = self::validate_parameters(self::execute_parameters(), [
|
||||
'reportid' => $reportid,
|
||||
]);
|
||||
|
||||
// Load the report model for deletion. Note we don't use the manager class because it validates the report source,
|
||||
// and we want user to be able to delete report, even if it's no longer associated with a valid source.
|
||||
$report = new report_model($reportid);
|
||||
|
||||
self::validate_context($report->get_context());
|
||||
permission::require_can_edit_report($report);
|
||||
|
||||
return report::delete_report($reportid);
|
||||
}
|
||||
|
||||
/**
|
||||
* External method return value
|
||||
*
|
||||
* @return external_value
|
||||
*/
|
||||
public static function execute_returns(): external_value {
|
||||
return new external_value(PARAM_BOOL, 'Success');
|
||||
}
|
||||
}
|
||||
+104
@@ -0,0 +1,104 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace core_reportbuilder\external\reports;
|
||||
|
||||
use external_api;
|
||||
use external_value;
|
||||
use external_single_structure;
|
||||
use external_function_parameters;
|
||||
use core_reportbuilder\manager;
|
||||
use core_reportbuilder\permission;
|
||||
use core_reportbuilder\output\custom_report;
|
||||
use core_reportbuilder\external\custom_report_exporter;
|
||||
use moodle_url;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
global $CFG;
|
||||
require_once("{$CFG->libdir}/externallib.php");
|
||||
|
||||
/**
|
||||
* External method for getting a custom report
|
||||
*
|
||||
* @package core_reportbuilder
|
||||
* @copyright 2021 David Matamoros <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class get extends external_api {
|
||||
|
||||
/**
|
||||
* External method parameters
|
||||
*
|
||||
* @return external_function_parameters
|
||||
*/
|
||||
public static function execute_parameters(): external_function_parameters {
|
||||
return new external_function_parameters([
|
||||
'reportid' => new external_value(PARAM_INT, 'Report ID'),
|
||||
'editmode' => new external_value(PARAM_BOOL, 'Whether editing mode is enabled', VALUE_DEFAULT, 0),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* External method execution
|
||||
*
|
||||
* @param int $reportid
|
||||
* @param bool $editmode
|
||||
* @return array
|
||||
*/
|
||||
public static function execute(int $reportid, bool $editmode): array {
|
||||
global $PAGE, $OUTPUT;
|
||||
|
||||
[
|
||||
'reportid' => $reportid,
|
||||
'editmode' => $editmode,
|
||||
] = self::validate_parameters(self::execute_parameters(), [
|
||||
'reportid' => $reportid,
|
||||
'editmode' => $editmode,
|
||||
]);
|
||||
|
||||
$report = manager::get_report_from_id($reportid);
|
||||
self::validate_context($report->get_context());
|
||||
|
||||
if ($editmode) {
|
||||
permission::require_can_edit_report($report->get_report_persistent());
|
||||
} else {
|
||||
permission::require_can_view_report($report->get_report_persistent());
|
||||
}
|
||||
|
||||
// Set current URL and force bootstrap_renderer to initiate moodle page.
|
||||
$PAGE->set_url(new moodle_url('/'));
|
||||
$OUTPUT->header();
|
||||
$PAGE->start_collecting_javascript_requirements();
|
||||
|
||||
$renderer = $PAGE->get_renderer('core_reportbuilder');
|
||||
$context = (new custom_report($report->get_report_persistent(), $editmode))->export_for_template($renderer);
|
||||
$context->javascript = $PAGE->requires->get_end_code();
|
||||
|
||||
return (array)$context;
|
||||
}
|
||||
|
||||
/**
|
||||
* External method return value
|
||||
*
|
||||
* @return external_single_structure
|
||||
*/
|
||||
public static function execute_returns(): external_single_structure {
|
||||
return custom_report_exporter::get_read_structure();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,159 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace core_reportbuilder\form;
|
||||
|
||||
use context;
|
||||
use moodle_url;
|
||||
use core_form\dynamic_form;
|
||||
use core_reportbuilder\manager;
|
||||
use core_reportbuilder\permission;
|
||||
use core_reportbuilder\local\report\base;
|
||||
use core_reportbuilder\local\models\filter;
|
||||
use core_reportbuilder\local\models\report;
|
||||
|
||||
/**
|
||||
* Dynamic condition form
|
||||
*
|
||||
* @package core_reportbuilder
|
||||
* @copyright 2021 Paul Holden <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class condition extends dynamic_form {
|
||||
|
||||
/**
|
||||
* Return instance of the report using the condition form
|
||||
*
|
||||
* @return base
|
||||
*/
|
||||
private function get_report(): base {
|
||||
$report = new report($this->optional_param('reportid', 0, PARAM_INT));
|
||||
$parameters = (array) json_decode($this->optional_param('parameters', '', PARAM_RAW));
|
||||
|
||||
return manager::get_report_from_persistent($report, $parameters);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the context for the form, it should be that of the system report itself
|
||||
*
|
||||
* @return context
|
||||
*/
|
||||
protected function get_context_for_dynamic_submission(): context {
|
||||
return $this->get_report()->get_context();
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure current user is able to use this form
|
||||
*
|
||||
* A {@see \core_reportbuilder\report_access_exception} will be thrown if they can't
|
||||
*/
|
||||
protected function check_access_for_dynamic_submission(): void {
|
||||
permission::require_can_edit_report($this->get_report()->get_report_persistent());
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the form submission
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function process_dynamic_submission() {
|
||||
$values = $this->get_data();
|
||||
|
||||
// Remove some unneeded fields.
|
||||
unset($values->reportid, $values->parameters);
|
||||
|
||||
return $this->get_report()->set_condition_values((array) $values);
|
||||
}
|
||||
|
||||
/**
|
||||
* Load in existing data as form defaults
|
||||
*/
|
||||
public function set_data_for_dynamic_submission(): void {
|
||||
$defaults = [
|
||||
'reportid' => $this->optional_param('reportid', 0, PARAM_INT),
|
||||
'parameters' => $this->optional_param('parameters', 0, PARAM_RAW),
|
||||
];
|
||||
|
||||
$this->set_data(array_merge($defaults, $this->get_report()->get_condition_values()));
|
||||
}
|
||||
|
||||
/**
|
||||
* URL of the page using this form
|
||||
*
|
||||
* @return moodle_url
|
||||
*/
|
||||
protected function get_page_url_for_dynamic_submission(): moodle_url {
|
||||
return new moodle_url('/');
|
||||
}
|
||||
|
||||
/**
|
||||
* Condition form definition
|
||||
*/
|
||||
protected function definition() {
|
||||
global $OUTPUT;
|
||||
|
||||
$mform = $this->_form;
|
||||
|
||||
$mform->addElement('hidden', 'reportid');
|
||||
$mform->setType('reportid', PARAM_INT);
|
||||
|
||||
$mform->addElement('hidden', 'parameters');
|
||||
$mform->setType('parameters', PARAM_RAW);
|
||||
|
||||
// Wrap the form elements inside an outer container, as drag/drop requires draggable elements to be immediate
|
||||
// descendants of said container. Note this is identified by it's data-region property in the editor module.
|
||||
$mform->addElement('html', '<div class="list-group mt-2" data-region="active-conditions">');
|
||||
|
||||
// Allow each condition instance to add itself to this form, wrapping each inside custom header/footer template.
|
||||
$conditioninstances = $this->get_report()->get_condition_instances();
|
||||
|
||||
$conditions = filter::get_condition_records($this->get_report()->get_report_persistent()->get('id'), 'filterorder');
|
||||
foreach ($conditions as $condition) {
|
||||
$conditioninstance = $conditioninstances[$condition->get('uniqueidentifier')];
|
||||
|
||||
$entityname = $conditioninstance->get_entity_name();
|
||||
$displayvalue = $conditioninstance->get_header();
|
||||
|
||||
$mform->addElement('html', $OUTPUT->render_from_template('core_reportbuilder/local/conditions/header', [
|
||||
'id' => $condition->get('id'),
|
||||
'entityname' => $this->get_report()->get_entity_title($entityname),
|
||||
'heading' => $displayvalue,
|
||||
'sortorder' => $condition->get('filterorder'),
|
||||
'movetitle' => get_string('movecondition', 'core_reportbuilder', $displayvalue),
|
||||
]));
|
||||
|
||||
$conditioninstance->setup_form($mform);
|
||||
$mform->addElement('html', $OUTPUT->render_from_template('core_reportbuilder/local/conditions/footer', []));
|
||||
}
|
||||
$mform->addElement('html', '</div>');
|
||||
$this->set_display_vertical();
|
||||
|
||||
// We'll add a second submit button to the form that will be used to reset current report conditions.
|
||||
$mform->registerNoSubmitButton('resetconditions');
|
||||
|
||||
$buttons = [];
|
||||
$buttons[] = $mform->createElement('submit', 'submitbutton', get_string('apply', 'core_reportbuilder'));
|
||||
$buttons[] = $mform->createElement('submit', 'resetconditions', get_string('resetall', 'core_reportbuilder'),
|
||||
null, null, ['customclassoverride' => 'btn-link']);
|
||||
|
||||
$mform->addGroup($buttons, 'buttonar', '', [' '], false);
|
||||
$mform->closeHeaderBefore('buttonar');
|
||||
|
||||
$mform->disable_form_change_checker();
|
||||
}
|
||||
}
|
||||
@@ -19,11 +19,13 @@ declare(strict_types=1);
|
||||
namespace core_reportbuilder\form;
|
||||
|
||||
use context;
|
||||
use core_reportbuilder\local\report\base;
|
||||
use core_reportbuilder\permission;
|
||||
use moodle_url;
|
||||
use core_form\dynamic_form;
|
||||
use core_reportbuilder\manager;
|
||||
use core_reportbuilder\system_report;
|
||||
use core_reportbuilder\local\models\report;
|
||||
use core_reportbuilder\local\models\filter as filter_model;
|
||||
|
||||
/**
|
||||
* Dynamic filter form
|
||||
@@ -37,16 +39,13 @@ class filter extends dynamic_form {
|
||||
/**
|
||||
* Return instance of the system report using the filter form
|
||||
*
|
||||
* @return system_report
|
||||
* @return base
|
||||
*/
|
||||
private function get_system_report(): system_report {
|
||||
$report = new report($this->optional_param('reportid', 0, PARAM_INT));
|
||||
private function get_report(): base {
|
||||
$reportpersistent = new report($this->optional_param('reportid', 0, PARAM_INT));
|
||||
$parameters = (array) json_decode($this->optional_param('parameters', '', PARAM_RAW));
|
||||
|
||||
/** @var system_report $systemreport */
|
||||
$systemreport = manager::get_report_from_persistent($report, $parameters);
|
||||
|
||||
return $systemreport;
|
||||
return manager::get_report_from_persistent($reportpersistent, $parameters);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -55,7 +54,7 @@ class filter extends dynamic_form {
|
||||
* @return context
|
||||
*/
|
||||
protected function get_context_for_dynamic_submission(): context {
|
||||
return ($this->get_system_report())->get_context();
|
||||
return ($this->get_report())->get_context();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -64,7 +63,12 @@ class filter extends dynamic_form {
|
||||
* A {@see \core_reportbuilder\report_access_exception} will be thrown if they can't
|
||||
*/
|
||||
protected function check_access_for_dynamic_submission(): void {
|
||||
$this->get_system_report()->require_can_view();
|
||||
$reportpersistent = $this->get_report()->get_report_persistent();
|
||||
if ($reportpersistent->get('type') === base::TYPE_CUSTOM_REPORT) {
|
||||
permission::require_can_view_report($reportpersistent);
|
||||
} else {
|
||||
$this->get_report()->require_can_view();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -77,9 +81,9 @@ class filter extends dynamic_form {
|
||||
|
||||
// Remove some unneeded fields, apply filters.
|
||||
unset($values->reportid, $values->parameters);
|
||||
$this->get_system_report()->set_filter_values((array) $values);
|
||||
$this->get_report()->set_filter_values((array) $values);
|
||||
|
||||
return $this->get_system_report()->get_applied_filter_count();
|
||||
return $this->get_report()->get_applied_filter_count();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -91,7 +95,7 @@ class filter extends dynamic_form {
|
||||
'parameters' => $this->optional_param('parameters', 0, PARAM_RAW),
|
||||
];
|
||||
|
||||
$this->set_data(array_merge($defaults, $this->get_system_report()->get_filter_values()));
|
||||
$this->set_data(array_merge($defaults, $this->get_report()->get_filter_values()));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -118,9 +122,17 @@ class filter extends dynamic_form {
|
||||
$mform->setType('parameters', PARAM_RAW);
|
||||
|
||||
// Allow each filter instance to add itself to this form, wrapping each inside custom header/footer template.
|
||||
foreach ($this->get_system_report()->get_filter_instances() as $filterinstance) {
|
||||
$filterinstances = $this->get_report()->get_filter_instances();
|
||||
foreach ($filterinstances as $filterinstance) {
|
||||
// Check if filter has a custom header set.
|
||||
if ($filterinstance->get_filter_persistent() && !empty($filterinstance->get_filter_persistent()->get('heading'))) {
|
||||
$header = $filterinstance->get_filter_persistent()->get('heading');
|
||||
} else {
|
||||
$header = $filterinstance->get_header();
|
||||
}
|
||||
|
||||
$mform->addElement('html', $OUTPUT->render_from_template('core_reportbuilder/local/filters/header', [
|
||||
'name' => $filterinstance->get_header(),
|
||||
'name' => $header,
|
||||
]));
|
||||
|
||||
$filterinstance->setup_form($mform);
|
||||
|
||||
@@ -0,0 +1,150 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace core_reportbuilder\form;
|
||||
|
||||
use context;
|
||||
use context_system;
|
||||
use core_reportbuilder\permission;
|
||||
use moodle_url;
|
||||
use core_form\dynamic_form;
|
||||
use core_reportbuilder\datasource;
|
||||
use core_reportbuilder\manager;
|
||||
use core_reportbuilder\local\helpers\report as reporthelper;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
global $CFG;
|
||||
require_once("$CFG->libdir/formslib.php");
|
||||
|
||||
/**
|
||||
* Report details form
|
||||
*
|
||||
* @package core_reportbuilder
|
||||
* @copyright 2021 David Matamoros <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class report extends dynamic_form {
|
||||
|
||||
/**
|
||||
* Return instance of the custom report we are editing, or null when creating a new report
|
||||
*
|
||||
* @return datasource|null
|
||||
*/
|
||||
protected function get_custom_report(): ?datasource {
|
||||
if ($reportid = $this->optional_param('id', 0, PARAM_INT)) {
|
||||
/** @var datasource $customreport */
|
||||
$customreport = manager::get_report_from_id($reportid);
|
||||
|
||||
return $customreport;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the context for the form, it should be that of the custom report itself, or system when creating a new report
|
||||
*
|
||||
* @return context
|
||||
*/
|
||||
public function get_context_for_dynamic_submission(): context {
|
||||
if ($report = $this->get_custom_report()) {
|
||||
return $report->get_context();
|
||||
} else {
|
||||
return context_system::instance();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure current user is able to use this form
|
||||
*
|
||||
* A {@see \core_reportbuilder\report_access_exception} will be thrown if they can't
|
||||
*/
|
||||
protected function check_access_for_dynamic_submission(): void {
|
||||
$report = $this->get_custom_report();
|
||||
|
||||
if ($report) {
|
||||
permission::require_can_edit_report($report->get_report_persistent());
|
||||
} else {
|
||||
permission::require_can_create_report();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Form definition
|
||||
*/
|
||||
public function definition() {
|
||||
$mform = $this->_form;
|
||||
|
||||
$mform->addElement('hidden', 'id');
|
||||
$mform->setType('id', PARAM_INT);
|
||||
|
||||
$mform->addElement('text', 'name', get_string('name'));
|
||||
$mform->setType('name', PARAM_TEXT);
|
||||
$mform->addRule('name', null, 'required', null, 'client');
|
||||
$mform->addRule('name', get_string('maximumchars', '', 255), 'maxlength', 255);
|
||||
|
||||
// Allow user to select report source if creating a new report.
|
||||
if (!$this->get_custom_report()) {
|
||||
$default = ['' => ['' => get_string('selectareportsource', 'core_reportbuilder')]];
|
||||
$mform->addElement('selectgroups', 'source', get_string('reportsource', 'core_reportbuilder'),
|
||||
array_merge($default, manager::get_report_datasources()));
|
||||
$mform->addRule('source', null, 'required', null, 'client');
|
||||
$mform->addHelpButton('source', 'reportsource', 'core_reportbuilder');
|
||||
|
||||
$mform->addElement('advcheckbox', 'includedefaultsetup', get_string('includedefaultsetup', 'core_reportbuilder'));
|
||||
$mform->setDefault('includedefaultsetup', 1);
|
||||
$mform->addHelpButton('includedefaultsetup', 'includedefaultsetup', 'core_reportbuilder');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the form submission
|
||||
*
|
||||
* @return string The URL to advance to upon completion
|
||||
*/
|
||||
public function process_dynamic_submission() {
|
||||
$data = $this->get_data();
|
||||
|
||||
if ($data->id) {
|
||||
$reportpersistent = reporthelper::update_report($data);
|
||||
} else {
|
||||
$reportpersistent = reporthelper::create_report($data, (bool)$data->includedefaultsetup);
|
||||
}
|
||||
|
||||
return (new moodle_url('/reportbuilder/edit.php', ['id' => $reportpersistent->get('id')]))->out(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Load in existing data as form defaults
|
||||
*/
|
||||
public function set_data_for_dynamic_submission(): void {
|
||||
if ($report = $this->get_custom_report()) {
|
||||
$this->set_data($report->get_report_persistent()->to_record());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* URL of the page using this form
|
||||
*
|
||||
* @return moodle_url
|
||||
*/
|
||||
public function get_page_url_for_dynamic_submission(): moodle_url {
|
||||
return new moodle_url('/reportbuilder/index.php');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace core_reportbuilder\local\aggregation;
|
||||
|
||||
use lang_string;
|
||||
use core_reportbuilder\local\report\column;
|
||||
|
||||
/**
|
||||
* Column average aggregation type
|
||||
*
|
||||
* @package core_reportbuilder
|
||||
* @copyright 2021 Paul Holden <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class avg extends base {
|
||||
|
||||
/**
|
||||
* Return aggregation name
|
||||
*
|
||||
* @return lang_string
|
||||
*/
|
||||
public static function get_name(): lang_string {
|
||||
return new lang_string('aggregationavg', 'core_reportbuilder');
|
||||
}
|
||||
|
||||
/**
|
||||
* This aggregation can be performed on all numeric columns
|
||||
*
|
||||
* @param int $columntype
|
||||
* @return bool
|
||||
*/
|
||||
public static function compatible(int $columntype): bool {
|
||||
return in_array($columntype, [
|
||||
column::TYPE_INTEGER,
|
||||
column::TYPE_FLOAT,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the aggregated field SQL
|
||||
*
|
||||
* @param string $field
|
||||
* @param int $columntype
|
||||
* @return string
|
||||
*/
|
||||
public static function get_field_sql(string $field, int $columntype): string {
|
||||
return "AVG(1.0 * {$field})";
|
||||
}
|
||||
|
||||
/**
|
||||
* Return formatted value for column when applying aggregation
|
||||
*
|
||||
* @param mixed $value
|
||||
* @param array $values
|
||||
* @param array $callbacks
|
||||
* @return mixed
|
||||
*/
|
||||
public static function format_value($value, array $values, array $callbacks) {
|
||||
return sprintf('%.1f', (float) reset($values));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace core_reportbuilder\local\aggregation;
|
||||
|
||||
use lang_string;
|
||||
use core_reportbuilder\local\report\column;
|
||||
|
||||
/**
|
||||
* Base class for column aggregation types
|
||||
*
|
||||
* @package core_reportbuilder
|
||||
* @copyright 2021 Paul Holden <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
abstract class base {
|
||||
|
||||
/**
|
||||
* Return the class name of the aggregation type
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
final public static function get_class_name(): string {
|
||||
$namespacedclass = explode('\\', get_called_class());
|
||||
|
||||
return end($namespacedclass);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the display name of the aggregation
|
||||
*
|
||||
* @return lang_string
|
||||
*/
|
||||
abstract public static function get_name(): lang_string;
|
||||
|
||||
/**
|
||||
* Whether the aggregation is compatible with the given column type
|
||||
*
|
||||
* @param int $columntype The type as defined by the {@see column::set_type} method
|
||||
* @return bool
|
||||
*/
|
||||
abstract public static function compatible(int $columntype): bool;
|
||||
|
||||
/**
|
||||
* Return the aggregated field SQL
|
||||
*
|
||||
* @param string $field
|
||||
* @param int $columntype
|
||||
* @return string
|
||||
*/
|
||||
abstract public static function get_field_sql(string $field, int $columntype): string;
|
||||
|
||||
/**
|
||||
* Return formatted value for column when applying aggregation
|
||||
*
|
||||
* @param mixed $value
|
||||
* @param array $values
|
||||
* @param array $callbacks
|
||||
* @return mixed
|
||||
*/
|
||||
abstract public static function format_value($value, array $values, array $callbacks);
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace core_reportbuilder\local\aggregation;
|
||||
|
||||
use lang_string;
|
||||
use core_reportbuilder\local\report\column;
|
||||
|
||||
/**
|
||||
* Column count aggregation type
|
||||
*
|
||||
* @package core_reportbuilder
|
||||
* @copyright 2021 Paul Holden <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class count extends base {
|
||||
|
||||
/**
|
||||
* Return aggregation name
|
||||
*
|
||||
* @return lang_string
|
||||
*/
|
||||
public static function get_name(): lang_string {
|
||||
return new lang_string('aggregationcount', 'core_reportbuilder');
|
||||
}
|
||||
|
||||
/**
|
||||
* This aggregation can be performed on all column types
|
||||
*
|
||||
* @param int $columntype
|
||||
* @return bool
|
||||
*/
|
||||
public static function compatible(int $columntype): bool {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the aggregated field SQL
|
||||
*
|
||||
* @param string $field
|
||||
* @param int $columntype
|
||||
* @return string
|
||||
*/
|
||||
public static function get_field_sql(string $field, int $columntype): string {
|
||||
global $DB;
|
||||
|
||||
if ($columntype === column::TYPE_LONGTEXT && $DB->get_dbfamily() === 'oracle') {
|
||||
$field = $DB->sql_compare_text($field, 255);
|
||||
}
|
||||
|
||||
return "COUNT({$field})";
|
||||
}
|
||||
|
||||
/**
|
||||
* Return formatted value for column when applying aggregation
|
||||
*
|
||||
* @param mixed $value
|
||||
* @param array $values
|
||||
* @param array $callbacks
|
||||
* @return mixed
|
||||
*/
|
||||
public static function format_value($value, array $values, array $callbacks) {
|
||||
return (int) reset($values);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace core_reportbuilder\local\aggregation;
|
||||
|
||||
use lang_string;
|
||||
use core_reportbuilder\local\report\column;
|
||||
|
||||
/**
|
||||
* Column count distinct aggregation type
|
||||
*
|
||||
* @package core_reportbuilder
|
||||
* @copyright 2021 Paul Holden <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class countdistinct extends base {
|
||||
|
||||
/**
|
||||
* Return aggregation name
|
||||
*
|
||||
* @return lang_string
|
||||
*/
|
||||
public static function get_name(): lang_string {
|
||||
return new lang_string('aggregationcountdistinct', 'core_reportbuilder');
|
||||
}
|
||||
|
||||
/**
|
||||
* This aggregation can be performed on all column types
|
||||
*
|
||||
* @param int $columntype
|
||||
* @return bool
|
||||
*/
|
||||
public static function compatible(int $columntype): bool {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the aggregated field SQL
|
||||
*
|
||||
* @param string $field
|
||||
* @param int $columntype
|
||||
* @return string
|
||||
*/
|
||||
public static function get_field_sql(string $field, int $columntype): string {
|
||||
global $DB;
|
||||
|
||||
if ($columntype === column::TYPE_LONGTEXT && $DB->get_dbfamily() === 'oracle') {
|
||||
$field = $DB->sql_compare_text($field, 255);
|
||||
}
|
||||
|
||||
return "COUNT(DISTINCT {$field})";
|
||||
}
|
||||
|
||||
/**
|
||||
* Return formatted value for column when applying aggregation
|
||||
*
|
||||
* @param mixed $value
|
||||
* @param array $values
|
||||
* @param array $callbacks
|
||||
* @return mixed
|
||||
*/
|
||||
public static function format_value($value, array $values, array $callbacks) {
|
||||
return (int) reset($values);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace core_reportbuilder\local\aggregation;
|
||||
|
||||
use lang_string;
|
||||
use core_reportbuilder\local\report\column;
|
||||
|
||||
/**
|
||||
* Column group concatenation aggregation type
|
||||
*
|
||||
* @package core_reportbuilder
|
||||
* @copyright 2021 Paul Holden <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class groupconcat extends base {
|
||||
|
||||
/**
|
||||
* Return aggregation name
|
||||
*
|
||||
* @return lang_string
|
||||
*/
|
||||
public static function get_name(): lang_string {
|
||||
return new lang_string('aggregationgroupconcat', 'core_reportbuilder');
|
||||
}
|
||||
|
||||
/**
|
||||
* This aggregation can be performed on all non-timestamp columns
|
||||
*
|
||||
* @param int $columntype
|
||||
* @return bool
|
||||
*/
|
||||
public static function compatible(int $columntype): bool {
|
||||
return !in_array($columntype, [
|
||||
column::TYPE_TIMESTAMP,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the aggregated field SQL
|
||||
*
|
||||
* @param string $field
|
||||
* @param int $columntype
|
||||
* @return string
|
||||
*/
|
||||
public static function get_field_sql(string $field, int $columntype): string {
|
||||
global $DB;
|
||||
|
||||
return $DB->sql_group_concat($field);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return formatted value for column when applying aggregation
|
||||
*
|
||||
* @param mixed $value
|
||||
* @param array $values
|
||||
* @param array $callbacks
|
||||
* @return mixed
|
||||
*/
|
||||
public static function format_value($value, array $values, array $callbacks) {
|
||||
return $value;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace core_reportbuilder\local\aggregation;
|
||||
|
||||
use lang_string;
|
||||
use core_reportbuilder\local\report\column;
|
||||
|
||||
/**
|
||||
* Column group concatenation distinct aggregation type
|
||||
*
|
||||
* @package core_reportbuilder
|
||||
* @copyright 2021 Paul Holden <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class groupconcatdistinct extends base {
|
||||
|
||||
/**
|
||||
* Return aggregation name
|
||||
*
|
||||
* @return lang_string
|
||||
*/
|
||||
public static function get_name(): lang_string {
|
||||
return new lang_string('aggregationgroupconcatdistinct', 'core_reportbuilder');
|
||||
}
|
||||
|
||||
/**
|
||||
* This aggregation can be performed on all non-timestamp columns in MySQL and Postgres only
|
||||
*
|
||||
* @param int $columntype
|
||||
* @return bool
|
||||
*/
|
||||
public static function compatible(int $columntype): bool {
|
||||
global $DB;
|
||||
|
||||
$dbsupportedtype = in_array($DB->get_dbfamily(), [
|
||||
'mysql',
|
||||
'postgres',
|
||||
]);
|
||||
|
||||
return $dbsupportedtype && !in_array($columntype, [
|
||||
column::TYPE_TIMESTAMP,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the aggregated field SQL
|
||||
*
|
||||
* @param string $field
|
||||
* @param int $columntype
|
||||
* @return string
|
||||
*/
|
||||
public static function get_field_sql(string $field, int $columntype): string {
|
||||
global $DB;
|
||||
|
||||
// DB limitations mean we only support MySQL and Postgres, and each handle it differently.
|
||||
if ($DB->get_dbfamily() === 'postgres') {
|
||||
return "STRING_AGG(DISTINCT CAST({$field} AS VARCHAR), ', ')";
|
||||
} else {
|
||||
return $DB->sql_group_concat("DISTINCT {$field}");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return formatted value for column when applying aggregation
|
||||
*
|
||||
* @param mixed $value
|
||||
* @param array $values
|
||||
* @param array $callbacks
|
||||
* @return mixed
|
||||
*/
|
||||
public static function format_value($value, array $values, array $callbacks) {
|
||||
return $value;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace core_reportbuilder\local\aggregation;
|
||||
|
||||
use lang_string;
|
||||
use core_reportbuilder\local\report\column;
|
||||
|
||||
/**
|
||||
* Column max aggregation type
|
||||
*
|
||||
* @package core_reportbuilder
|
||||
* @copyright 2021 Paul Holden <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class max extends base {
|
||||
|
||||
/**
|
||||
* Return aggregation name
|
||||
*
|
||||
* @return lang_string
|
||||
*/
|
||||
public static function get_name(): lang_string {
|
||||
return new lang_string('aggregationmax', 'core_reportbuilder');
|
||||
}
|
||||
|
||||
/**
|
||||
* This aggregation can be performed on all numeric/date/boolean types
|
||||
*
|
||||
* @param int $columntype
|
||||
* @return bool
|
||||
*/
|
||||
public static function compatible(int $columntype): bool {
|
||||
return in_array($columntype, [
|
||||
column::TYPE_INTEGER,
|
||||
column::TYPE_FLOAT,
|
||||
column::TYPE_TIMESTAMP,
|
||||
column::TYPE_BOOLEAN,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the aggregated field SQL
|
||||
*
|
||||
* @param string $field
|
||||
* @param int $columntype
|
||||
* @return string
|
||||
*/
|
||||
public static function get_field_sql(string $field, int $columntype): string {
|
||||
return "MAX({$field})";
|
||||
}
|
||||
|
||||
/**
|
||||
* Return formatted value for column when applying aggregation
|
||||
*
|
||||
* @param mixed $value
|
||||
* @param array $values
|
||||
* @param array $callbacks
|
||||
* @return mixed
|
||||
*/
|
||||
public static function format_value($value, array $values, array $callbacks) {
|
||||
foreach ($callbacks as $callback) {
|
||||
$value = ($callback[0])($value, (object) $values, $callback[1]);
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace core_reportbuilder\local\aggregation;
|
||||
|
||||
use lang_string;
|
||||
use core_reportbuilder\local\report\column;
|
||||
|
||||
/**
|
||||
* Column min aggregation type
|
||||
*
|
||||
* @package core_reportbuilder
|
||||
* @copyright 2021 Paul Holden <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class min extends base {
|
||||
|
||||
/**
|
||||
* Return aggregation name
|
||||
*
|
||||
* @return lang_string
|
||||
*/
|
||||
public static function get_name(): lang_string {
|
||||
return new lang_string('aggregationmin', 'core_reportbuilder');
|
||||
}
|
||||
|
||||
/**
|
||||
* This aggregation can be performed on all numeric/date/boolean types
|
||||
*
|
||||
* @param int $columntype
|
||||
* @return bool
|
||||
*/
|
||||
public static function compatible(int $columntype): bool {
|
||||
return in_array($columntype, [
|
||||
column::TYPE_INTEGER,
|
||||
column::TYPE_FLOAT,
|
||||
column::TYPE_TIMESTAMP,
|
||||
column::TYPE_BOOLEAN,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the aggregated field SQL
|
||||
*
|
||||
* @param string $field
|
||||
* @param int $columntype
|
||||
* @return string
|
||||
*/
|
||||
public static function get_field_sql(string $field, int $columntype): string {
|
||||
return "MIN({$field})";
|
||||
}
|
||||
|
||||
/**
|
||||
* Return formatted value for column when applying aggregation
|
||||
*
|
||||
* @param mixed $value
|
||||
* @param array $values
|
||||
* @param array $callbacks
|
||||
* @return mixed
|
||||
*/
|
||||
public static function format_value($value, array $values, array $callbacks) {
|
||||
foreach ($callbacks as $callback) {
|
||||
$value = ($callback[0])($value, (object) $values, $callback[1]);
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace core_reportbuilder\local\aggregation;
|
||||
|
||||
use lang_string;
|
||||
use core_reportbuilder\local\helpers\format;
|
||||
use core_reportbuilder\local\report\column;
|
||||
|
||||
/**
|
||||
* Column percent aggregation type
|
||||
*
|
||||
* @package core_reportbuilder
|
||||
* @copyright 2021 Paul Holden <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class percent extends base {
|
||||
|
||||
/**
|
||||
* Return aggregation name
|
||||
*
|
||||
* @return lang_string
|
||||
*/
|
||||
public static function get_name(): lang_string {
|
||||
return new lang_string('aggregationpercent', 'core_reportbuilder');
|
||||
}
|
||||
|
||||
/**
|
||||
* This aggregation can be performed on all boolean columns
|
||||
*
|
||||
* @param int $columntype
|
||||
* @return bool
|
||||
*/
|
||||
public static function compatible(int $columntype): bool {
|
||||
return in_array($columntype, [
|
||||
column::TYPE_BOOLEAN,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the aggregated field SQL
|
||||
*
|
||||
* @param string $field
|
||||
* @param int $columntype
|
||||
* @return string
|
||||
*/
|
||||
public static function get_field_sql(string $field, int $columntype): string {
|
||||
return "AVG(1.0 * {$field}) * 100.0";
|
||||
}
|
||||
|
||||
/**
|
||||
* Return formatted value for column when applying aggregation
|
||||
*
|
||||
* @param mixed $value
|
||||
* @param array $values
|
||||
* @param array $callbacks
|
||||
* @return mixed
|
||||
*/
|
||||
public static function format_value($value, array $values, array $callbacks) {
|
||||
return format::percent((float) reset($values));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace core_reportbuilder\local\aggregation;
|
||||
|
||||
use lang_string;
|
||||
use core_reportbuilder\local\report\column;
|
||||
|
||||
/**
|
||||
* Column sum aggregation type
|
||||
*
|
||||
* @package core_reportbuilder
|
||||
* @copyright 2021 Paul Holden <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class sum extends base {
|
||||
|
||||
/**
|
||||
* Return aggregation name
|
||||
*
|
||||
* @return lang_string
|
||||
*/
|
||||
public static function get_name(): lang_string {
|
||||
return new lang_string('aggregationsum', 'core_reportbuilder');
|
||||
}
|
||||
|
||||
/**
|
||||
* This aggregation can be performed on all numeric and boolean columns
|
||||
*
|
||||
* @param int $columntype
|
||||
* @return bool
|
||||
*/
|
||||
public static function compatible(int $columntype): bool {
|
||||
return in_array($columntype, [
|
||||
column::TYPE_INTEGER,
|
||||
column::TYPE_FLOAT,
|
||||
column::TYPE_BOOLEAN,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the aggregated field SQL
|
||||
*
|
||||
* @param string $field
|
||||
* @param int $columntype
|
||||
* @return string
|
||||
*/
|
||||
public static function get_field_sql(string $field, int $columntype): string {
|
||||
return "SUM({$field})";
|
||||
}
|
||||
|
||||
/**
|
||||
* Return formatted value for column when applying aggregation
|
||||
*
|
||||
* @param mixed $value
|
||||
* @param array $values
|
||||
* @param array $callbacks
|
||||
* @return mixed
|
||||
*/
|
||||
public static function format_value($value, array $values, array $callbacks) {
|
||||
return (int) reset($values);
|
||||
}
|
||||
}
|
||||
@@ -50,6 +50,9 @@ abstract class base {
|
||||
/** @var filter[] $filters List of filters for the entity */
|
||||
private $filters = [];
|
||||
|
||||
/** @var filter[] $conditions List of conditions for the entity */
|
||||
private $conditions = [];
|
||||
|
||||
/**
|
||||
* Database tables that this entity uses and their default aliases
|
||||
*
|
||||
@@ -240,7 +243,7 @@ abstract class base {
|
||||
* Add a filter to the entity
|
||||
*
|
||||
* @param filter $filter
|
||||
* @return $this
|
||||
* @return self
|
||||
*/
|
||||
final protected function add_filter(filter $filter): self {
|
||||
$this->filters[$filter->get_name()] = $filter;
|
||||
@@ -270,4 +273,39 @@ abstract class base {
|
||||
|
||||
return $this->filters[$name];
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a condition to the entity
|
||||
*
|
||||
* @param filter $condition
|
||||
* @return $this
|
||||
*/
|
||||
final protected function add_condition(filter $condition): self {
|
||||
$this->conditions[$condition->get_name()] = $condition;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns entity conditions
|
||||
*
|
||||
* @return filter[]
|
||||
*/
|
||||
final public function get_conditions(): array {
|
||||
return $this->conditions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an entity condition
|
||||
*
|
||||
* @param string $name
|
||||
* @return filter
|
||||
* @throws coding_exception For invalid condition name
|
||||
*/
|
||||
final public function get_condition(string $name): filter {
|
||||
if (!array_key_exists($name, $this->conditions)) {
|
||||
throw new coding_exception('Invalid condition name', $name);
|
||||
}
|
||||
|
||||
return $this->conditions[$name];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -80,6 +80,11 @@ class user extends base {
|
||||
$this->add_filter($filter);
|
||||
}
|
||||
|
||||
$conditions = array_merge($this->get_all_filters(), $userprofilefields->get_filters());
|
||||
foreach ($conditions as $condition) {
|
||||
$this->add_condition($condition);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
@@ -333,8 +338,6 @@ class user extends base {
|
||||
* @return filter[]
|
||||
*/
|
||||
protected function get_all_filters(): array {
|
||||
global $DB;
|
||||
|
||||
$filters = [];
|
||||
$tablealias = $this->get_table_alias('user');
|
||||
|
||||
|
||||
@@ -20,6 +20,7 @@ namespace core_reportbuilder\local\filters;
|
||||
|
||||
use MoodleQuickForm;
|
||||
use core_reportbuilder\local\report\filter;
|
||||
use core_reportbuilder\local\models\filter as filter_model;
|
||||
|
||||
/**
|
||||
* Base class for all report filters
|
||||
@@ -71,6 +72,26 @@ abstract class base {
|
||||
return $this->filter->get_header();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the filter's entity name
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
final public function get_entity_name(): string {
|
||||
return $this->filter->get_entity_name();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the filter persistent
|
||||
*
|
||||
* Note that filters for system reports don't store a persistent and will return null.
|
||||
*
|
||||
* @return filter_model|null
|
||||
*/
|
||||
final public function get_filter_persistent(): ?filter_model {
|
||||
return $this->filter->get_persistent();
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds filter-specific form elements
|
||||
*
|
||||
|
||||
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace core_reportbuilder\local\helpers;
|
||||
|
||||
use core_collator;
|
||||
use core_component;
|
||||
use core_reportbuilder\local\aggregation\base;
|
||||
|
||||
/**
|
||||
* Helper class for column aggregation related methods
|
||||
*
|
||||
* @package core_reportbuilder
|
||||
* @copyright 2021 Paul Holden <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class aggregation {
|
||||
|
||||
/**
|
||||
* Helper method to convert aggregation class name into fully qualified namespaced class
|
||||
*
|
||||
* @param string $aggregation
|
||||
* @return string
|
||||
*/
|
||||
public static function get_full_classpath(string $aggregation): string {
|
||||
return "\\core_reportbuilder\\local\\aggregation\\{$aggregation}";
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate whether given class is a valid aggregation type
|
||||
*
|
||||
* @param string $aggregationclass Fully qualified namespaced class, see {@see get_full_classpath} for converting value
|
||||
* stored in column persistent to full path
|
||||
* @return bool
|
||||
*/
|
||||
public static function valid(string $aggregationclass): bool {
|
||||
return class_exists($aggregationclass) && is_subclass_of($aggregationclass, base::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get available aggregation types for given column type
|
||||
*
|
||||
* @param int $columntype
|
||||
* @param array $exclude List of types to exclude, if omitted then include all available types
|
||||
* @return string[] Aggregation types indexed by [shortname => name]
|
||||
*/
|
||||
public static function get_column_aggregations(int $columntype, array $exclude = []): array {
|
||||
$types = [];
|
||||
|
||||
$classes = core_component::get_component_classes_in_namespace('core_reportbuilder', 'local\\aggregation');
|
||||
foreach ($classes as $class => $path) {
|
||||
/** @var base $aggregationclass */
|
||||
$aggregationclass = $class;
|
||||
if (static::valid($aggregationclass) && $aggregationclass::compatible($columntype) &&
|
||||
!in_array($aggregationclass::get_class_name(), $exclude)) {
|
||||
|
||||
$types[$aggregationclass::get_class_name()] = (string) $aggregationclass::get_name();
|
||||
}
|
||||
}
|
||||
|
||||
core_collator::asort($types, core_collator::SORT_STRING);
|
||||
|
||||
return $types;
|
||||
}
|
||||
}
|
||||
@@ -50,4 +50,14 @@ class format {
|
||||
public static function boolean_as_text(bool $value): string {
|
||||
return $value ? get_string('yes') : get_string('no');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns float value as a percentage
|
||||
*
|
||||
* @param float $value
|
||||
* @return string
|
||||
*/
|
||||
public static function percent(float $value): string {
|
||||
return sprintf('%.1f', $value) . '%';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,446 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace core_reportbuilder\local\helpers;
|
||||
|
||||
use stdClass;
|
||||
use invalid_parameter_exception;
|
||||
use core\persistent;
|
||||
use core_reportbuilder\datasource;
|
||||
use core_reportbuilder\manager;
|
||||
use core_reportbuilder\local\models\column;
|
||||
use core_reportbuilder\local\models\filter;
|
||||
use core_reportbuilder\local\models\report as report_model;
|
||||
|
||||
/**
|
||||
* Helper class for manipulating custom reports and their elements (columns, filters, conditions, etc)
|
||||
*
|
||||
* @package core_reportbuilder
|
||||
* @copyright 2021 Paul Holden <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class report {
|
||||
|
||||
/**
|
||||
* Create custom report
|
||||
*
|
||||
* @param stdClass $data
|
||||
* @param bool $default If $default is set to true it will populate report with default layout as defined by the selected
|
||||
* source. These include pre-defined columns, filters and conditions.
|
||||
* @return report_model
|
||||
*/
|
||||
public static function create_report(stdClass $data, bool $default = true): report_model {
|
||||
// TODO move this properties_definition validation into the persistents, or resolve MDL-71086.
|
||||
$data = (object) array_merge(array_intersect_key((array) $data, report_model::properties_definition()), [
|
||||
'type' => datasource::TYPE_CUSTOM_REPORT,
|
||||
]);
|
||||
|
||||
$reportpersistent = manager::create_report_persistent($data);
|
||||
|
||||
// Add datasource default columns, filters and conditions to the report.
|
||||
if ($default) {
|
||||
$source = $reportpersistent->get('source');
|
||||
/** @var datasource $datasource */
|
||||
$datasource = new $source($reportpersistent, []);
|
||||
$datasource->add_default_columns();
|
||||
$datasource->add_default_filters();
|
||||
$datasource->add_default_conditions();
|
||||
}
|
||||
|
||||
return $reportpersistent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update custom report
|
||||
*
|
||||
* @param stdClass $data
|
||||
* @return report_model
|
||||
*/
|
||||
public static function update_report(stdClass $data): report_model {
|
||||
$report = report_model::get_record(['id' => $data->id, 'type' => datasource::TYPE_CUSTOM_REPORT]);
|
||||
if ($report === false) {
|
||||
throw new invalid_parameter_exception('Invalid report');
|
||||
}
|
||||
|
||||
$report->set('name', $data->name)
|
||||
->update();
|
||||
|
||||
return $report;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete custom report
|
||||
*
|
||||
* @param int $reportid
|
||||
* @return bool
|
||||
* @throws invalid_parameter_exception
|
||||
*/
|
||||
public static function delete_report(int $reportid): bool {
|
||||
$report = report_model::get_record(['id' => $reportid, 'type' => datasource::TYPE_CUSTOM_REPORT]);
|
||||
if ($report === false) {
|
||||
throw new invalid_parameter_exception('Invalid report');
|
||||
}
|
||||
|
||||
return $report->delete();
|
||||
}
|
||||
|
||||
/**
|
||||
* Add given column to report
|
||||
*
|
||||
* @param int $reportid
|
||||
* @param string $uniqueidentifier
|
||||
* @return column
|
||||
* @throws invalid_parameter_exception
|
||||
*/
|
||||
public static function add_report_column(int $reportid, string $uniqueidentifier): column {
|
||||
$report = manager::get_report_from_id($reportid);
|
||||
|
||||
if (!array_key_exists($uniqueidentifier, $report->get_columns())) {
|
||||
throw new invalid_parameter_exception('Invalid column');
|
||||
}
|
||||
|
||||
$column = new column(0, (object) [
|
||||
'reportid' => $reportid,
|
||||
'uniqueidentifier' => $uniqueidentifier,
|
||||
'columnorder' => column::get_max_columnorder($reportid, 'columnorder') + 1,
|
||||
'sortorder' => column::get_max_columnorder($reportid, 'sortorder') + 1,
|
||||
]);
|
||||
|
||||
return $column->create();
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete given column from report
|
||||
*
|
||||
* @param int $reportid
|
||||
* @param int $columnid
|
||||
* @return bool
|
||||
* @throws invalid_parameter_exception
|
||||
*/
|
||||
public static function delete_report_column(int $reportid, int $columnid): bool {
|
||||
global $DB;
|
||||
|
||||
$column = column::get_record(['id' => $columnid, 'reportid' => $reportid]);
|
||||
if ($column === false) {
|
||||
throw new invalid_parameter_exception('Invalid column');
|
||||
}
|
||||
|
||||
// After deletion, re-index remaining report columns.
|
||||
if ($result = $column->delete()) {
|
||||
$sqlupdateorder = '
|
||||
UPDATE {' . column::TABLE . '}
|
||||
SET columnorder = columnorder - 1
|
||||
WHERE reportid = :reportid
|
||||
AND columnorder > :columnorder';
|
||||
|
||||
$DB->execute($sqlupdateorder, ['reportid' => $reportid, 'columnorder' => $column->get('columnorder')]);
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Re-order given column within a report
|
||||
*
|
||||
* @param int $reportid
|
||||
* @param int $columnid
|
||||
* @param int $position
|
||||
* @return bool
|
||||
* @throws invalid_parameter_exception
|
||||
*/
|
||||
public static function reorder_report_column(int $reportid, int $columnid, int $position): bool {
|
||||
$column = column::get_record(['id' => $columnid, 'reportid' => $reportid]);
|
||||
if ($column === false) {
|
||||
throw new invalid_parameter_exception('Invalid column');
|
||||
}
|
||||
|
||||
// Get the rest of the report columns, excluding the one we are moving.
|
||||
$columns = column::get_records_select('reportid = :reportid AND id <> :id', [
|
||||
'reportid' => $reportid,
|
||||
'id' => $columnid,
|
||||
], 'columnorder');
|
||||
|
||||
return static::reorder_persistents_by_field($column, $columns, $position, 'columnorder');
|
||||
}
|
||||
|
||||
/**
|
||||
* Re-order given column sorting within a report
|
||||
*
|
||||
* @param int $reportid
|
||||
* @param int $columnid
|
||||
* @param int $position
|
||||
* @return bool
|
||||
* @throws invalid_parameter_exception
|
||||
*/
|
||||
public static function reorder_report_column_sorting(int $reportid, int $columnid, int $position): bool {
|
||||
$column = column::get_record(['id' => $columnid, 'reportid' => $reportid]);
|
||||
if ($column === false) {
|
||||
throw new invalid_parameter_exception('Invalid column');
|
||||
}
|
||||
|
||||
// Get the rest of the report columns, excluding the one we are moving.
|
||||
$columns = column::get_records_select('reportid = :reportid AND id <> :id', [
|
||||
'reportid' => $reportid,
|
||||
'id' => $columnid,
|
||||
], 'sortorder');
|
||||
|
||||
return static::reorder_persistents_by_field($column, $columns, $position, 'sortorder');
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggle sorting options for given column within a report
|
||||
*
|
||||
* @param int $reportid
|
||||
* @param int $columnid
|
||||
* @param bool $enabled
|
||||
* @param int $direction
|
||||
* @return bool
|
||||
* @throws invalid_parameter_exception
|
||||
*/
|
||||
public static function toggle_report_column_sorting(int $reportid, int $columnid, bool $enabled,
|
||||
int $direction = SORT_ASC): bool {
|
||||
|
||||
$column = column::get_record(['id' => $columnid, 'reportid' => $reportid]);
|
||||
if ($column === false) {
|
||||
throw new invalid_parameter_exception('Invalid column');
|
||||
}
|
||||
|
||||
return $column
|
||||
->set('sortenabled', $enabled)
|
||||
->set('sortdirection', $direction)
|
||||
->update();
|
||||
}
|
||||
|
||||
/**
|
||||
* Add given condition to report
|
||||
*
|
||||
* @param int $reportid
|
||||
* @param string $uniqueidentifier
|
||||
* @return filter
|
||||
* @throws invalid_parameter_exception
|
||||
*/
|
||||
public static function add_report_condition(int $reportid, string $uniqueidentifier): filter {
|
||||
$report = manager::get_report_from_id($reportid);
|
||||
|
||||
if (!array_key_exists($uniqueidentifier, $report->get_conditions())) {
|
||||
throw new invalid_parameter_exception('Invalid condition');
|
||||
}
|
||||
|
||||
$condition = new filter(0, (object) [
|
||||
'reportid' => $reportid,
|
||||
'uniqueidentifier' => $uniqueidentifier,
|
||||
'iscondition' => true,
|
||||
'filterorder' => filter::get_max_filterorder($reportid, true) + 1,
|
||||
]);
|
||||
|
||||
return $condition->create();
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete given condition from report
|
||||
*
|
||||
* @param int $reportid
|
||||
* @param int $conditionid
|
||||
* @return bool
|
||||
* @throws invalid_parameter_exception
|
||||
*/
|
||||
public static function delete_report_condition(int $reportid, int $conditionid): bool {
|
||||
global $DB;
|
||||
|
||||
$condition = filter::get_condition_record($reportid, $conditionid);
|
||||
if ($condition === false) {
|
||||
throw new invalid_parameter_exception('Invalid condition');
|
||||
}
|
||||
|
||||
// After deletion, re-index remaining report conditions.
|
||||
if ($result = $condition->delete()) {
|
||||
$sqlupdateorder = '
|
||||
UPDATE {' . filter::TABLE . '}
|
||||
SET filterorder = filterorder - 1
|
||||
WHERE reportid = :reportid
|
||||
AND filterorder > :filterorder
|
||||
AND iscondition = 1';
|
||||
|
||||
$DB->execute($sqlupdateorder, ['reportid' => $reportid, 'filterorder' => $condition->get('filterorder')]);
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Re-order given condition within a report
|
||||
*
|
||||
* @param int $reportid
|
||||
* @param int $conditionid
|
||||
* @param int $position
|
||||
* @return bool
|
||||
* @throws invalid_parameter_exception
|
||||
*/
|
||||
public static function reorder_report_condition(int $reportid, int $conditionid, int $position): bool {
|
||||
$condition = filter::get_condition_record($reportid, $conditionid);
|
||||
if ($condition === false) {
|
||||
throw new invalid_parameter_exception('Invalid condition');
|
||||
}
|
||||
|
||||
// Get the rest of the report conditions, excluding the one we are moving.
|
||||
$conditions = filter::get_records_select('reportid = :reportid AND iscondition = 1 AND id <> :id', [
|
||||
'reportid' => $reportid,
|
||||
'id' => $conditionid,
|
||||
], 'filterorder');
|
||||
|
||||
return static::reorder_persistents_by_field($condition, $conditions, $position, 'filterorder');
|
||||
}
|
||||
|
||||
/**
|
||||
* Add given filter to report
|
||||
*
|
||||
* @param int $reportid
|
||||
* @param string $uniqueidentifier
|
||||
* @return filter
|
||||
* @throws invalid_parameter_exception
|
||||
*/
|
||||
public static function add_report_filter(int $reportid, string $uniqueidentifier): filter {
|
||||
$report = manager::get_report_from_id($reportid);
|
||||
|
||||
$reportfilters = $report->get_filters();
|
||||
if (!array_key_exists($uniqueidentifier, $reportfilters)) {
|
||||
throw new invalid_parameter_exception('Invalid filter');
|
||||
}
|
||||
|
||||
$filter = new filter(0, (object) [
|
||||
'reportid' => $reportid,
|
||||
'uniqueidentifier' => $uniqueidentifier,
|
||||
'filterorder' => filter::get_max_filterorder($reportid) + 1,
|
||||
]);
|
||||
|
||||
return $filter->create();
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete given filter from report
|
||||
*
|
||||
* @param int $reportid
|
||||
* @param int $filterid
|
||||
* @return bool
|
||||
* @throws invalid_parameter_exception
|
||||
*/
|
||||
public static function delete_report_filter(int $reportid, int $filterid): bool {
|
||||
global $DB;
|
||||
|
||||
$filter = filter::get_filter_record($reportid, $filterid);
|
||||
if ($filter === false) {
|
||||
throw new invalid_parameter_exception('Invalid filter');
|
||||
}
|
||||
|
||||
// After deletion, re-index remaining report filters.
|
||||
if ($result = $filter->delete()) {
|
||||
$sqlupdateorder = '
|
||||
UPDATE {' . filter::TABLE . '}
|
||||
SET filterorder = filterorder - 1
|
||||
WHERE reportid = :reportid
|
||||
AND filterorder > :filterorder
|
||||
AND iscondition = 0';
|
||||
|
||||
$DB->execute($sqlupdateorder, ['reportid' => $reportid, 'filterorder' => $filter->get('filterorder')]);
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Re-order given filter within a report
|
||||
*
|
||||
* @param int $reportid
|
||||
* @param int $filterid
|
||||
* @param int $position
|
||||
* @return bool
|
||||
* @throws invalid_parameter_exception
|
||||
*/
|
||||
public static function reorder_report_filter(int $reportid, int $filterid, int $position): bool {
|
||||
$filter = filter::get_filter_record($reportid, $filterid);
|
||||
if ($filter === false) {
|
||||
throw new invalid_parameter_exception('Invalid filter');
|
||||
}
|
||||
|
||||
// Get the rest of the report filters, excluding the one we are moving.
|
||||
$filters = filter::get_records_select('reportid = :reportid AND iscondition = 0 AND id <> :id', [
|
||||
'reportid' => $reportid,
|
||||
'id' => $filterid,
|
||||
], 'filterorder');
|
||||
|
||||
return static::reorder_persistents_by_field($filter, $filters, $position, 'filterorder');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get available columns for a given report
|
||||
*
|
||||
* @param report_model $persistent
|
||||
* @return array
|
||||
*/
|
||||
public static function get_available_columns(report_model $persistent) : array {
|
||||
$available = [];
|
||||
|
||||
$report = manager::get_report_from_persistent($persistent);
|
||||
|
||||
// Get current report columns.
|
||||
foreach ($report->get_columns() as $column) {
|
||||
$entityname = $column->get_entity_name();
|
||||
$entitytitle = $column->get_title();
|
||||
if (!array_key_exists($entityname, $available)) {
|
||||
$available[$entityname] = [
|
||||
'name' => (string) $report->get_entity_title($entityname),
|
||||
'key' => $entityname,
|
||||
'items' => [],
|
||||
];
|
||||
}
|
||||
|
||||
$available[$entityname]['items'][] = [
|
||||
'name' => $entitytitle,
|
||||
'identifier' => $column->get_unique_identifier(),
|
||||
'title' => get_string('addcolumn', 'core_reportbuilder', $entitytitle),
|
||||
'action' => 'report-add-column'
|
||||
];
|
||||
}
|
||||
|
||||
return array_values($available);
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method for re-ordering given persistents (columns, filters, etc)
|
||||
*
|
||||
* @param persistent $persistent The persistent we are moving
|
||||
* @param persistent[] $persistents The rest of the persistents
|
||||
* @param int $position
|
||||
* @param string $field The field we need to update
|
||||
* @return bool
|
||||
*/
|
||||
private static function reorder_persistents_by_field(persistent $persistent, array $persistents, int $position,
|
||||
string $field): bool {
|
||||
|
||||
// Splice into new position.
|
||||
array_splice($persistents, $position - 1, 0, [$persistent]);
|
||||
|
||||
$fieldorder = 1;
|
||||
foreach ($persistents as $persistent) {
|
||||
$persistent->set($field, $fieldorder++)
|
||||
->update();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user