first commit

This commit is contained in:
CHIEFSOFT\ameye
2024-09-30 18:11:26 -04:00
commit e592ca6823
27270 changed files with 5002257 additions and 0 deletions
+90
View File
@@ -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\audiences;
use core_reportbuilder\local\audiences\base;
use core_external\external_api;
use core_external\external_value;
use core_external\external_function_parameters;
use core_reportbuilder\manager;
use core_reportbuilder\permission;
/**
* External method for deleting a report audience
*
* @package core_reportbuilder
* @copyright 2021 David Matamoros <davidmc@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class delete extends external_api {
/**
* Describes the parameters for get_users_courses.
*
* @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'),
'instanceid' => new external_value(PARAM_INT, 'Audience instance id'),
]
);
}
/**
* External function to delete a report audience instance.
*
* @param int $reportid
* @param int $instanceid
* @return bool
*/
public static function execute(int $reportid, int $instanceid): bool {
[
'reportid' => $reportid,
'instanceid' => $instanceid,
] = self::validate_parameters(self::execute_parameters(), [
'reportid' => $reportid,
'instanceid' => $instanceid,
]);
$report = manager::get_report_from_id($reportid);
self::validate_context($report->get_context());
permission::require_can_edit_report($report->get_report_persistent());
$baseinstance = base::instance($instanceid);
if ($baseinstance && $baseinstance->user_can_edit()) {
$persistent = $baseinstance->get_persistent();
$persistent->delete();
return true;
}
return false;
}
/**
* Describes the data returned from the external function.
*
* @return external_value
*/
public static function execute_returns(): external_value {
return new external_value(PARAM_BOOL, '', VALUE_REQUIRED);
}
}
+91
View File
@@ -0,0 +1,91 @@
<?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 core_external\external_api;
use core_external\external_value;
use core_external\external_single_structure;
use core_external\external_function_parameters;
use core_reportbuilder\manager;
use core_reportbuilder\permission;
use core_reportbuilder\local\helpers\report;
/**
* External method for adding report columns
*
* @package core_reportbuilder
* @copyright 2021 Paul Holden <paulh@moodle.com>
* @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();
}
}
+91
View File
@@ -0,0 +1,91 @@
<?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 core_external\external_api;
use core_external\external_value;
use core_external\external_single_structure;
use core_external\external_function_parameters;
use core_reportbuilder\manager;
use core_reportbuilder\permission;
use core_reportbuilder\local\helpers\report;
/**
* External method for deleting report columns
*
* @package core_reportbuilder
* @copyright 2021 Paul Holden <paulh@moodle.com>
* @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();
}
}
+85
View File
@@ -0,0 +1,85 @@
<?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_external\external_api;
use core_external\external_value;
use core_external\external_function_parameters;
use core_reportbuilder\manager;
use core_reportbuilder\permission;
use core_reportbuilder\local\helpers\report;
/**
* External method for re-ordering report columns
*
* @package core_reportbuilder
* @copyright 2021 Paul Holden <paulh@moodle.com>
* @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');
}
}
+84
View File
@@ -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\columns\sort;
use core_external\external_api;
use core_external\external_value;
use core_external\external_single_structure;
use core_external\external_function_parameters;
use core_reportbuilder\manager;
use core_reportbuilder\permission;
use core_reportbuilder\external\custom_report_columns_sorting_exporter;
/**
* External method for retrieving report column sorting
*
* @package core_reportbuilder
* @copyright 2021 Paul Holden <paulh@moodle.com>
* @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'),
]);
}
/**
* External method execution
*
* @param int $reportid
* @return array
*/
public static function execute(int $reportid): array {
global $PAGE;
[
'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());
$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();
}
}
+95
View File
@@ -0,0 +1,95 @@
<?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 core_external\external_api;
use core_external\external_value;
use core_external\external_single_structure;
use core_external\external_function_parameters;
use core_reportbuilder\manager;
use core_reportbuilder\permission;
use core_reportbuilder\local\helpers\report;
use core_reportbuilder\external\custom_report_columns_sorting_exporter;
/**
* External method for re-ordering report column sorting
*
* @package core_reportbuilder
* @copyright 2021 Paul Holden <paulh@moodle.com>
* @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();
}
}
+99
View File
@@ -0,0 +1,99 @@
<?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 core_external\external_api;
use core_external\external_value;
use core_external\external_single_structure;
use core_external\external_function_parameters;
use core_reportbuilder\manager;
use core_reportbuilder\permission;
use core_reportbuilder\local\helpers\report;
use core_reportbuilder\external\custom_report_columns_sorting_exporter;
/**
* External method for toggling report column sorting
*
* @package core_reportbuilder
* @copyright 2021 Paul Holden <paulh@moodle.com>
* @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();
}
}
+97
View File
@@ -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 core_external\external_api;
use core_external\external_value;
use core_external\external_single_structure;
use core_external\external_function_parameters;
use core_reportbuilder\manager;
use core_reportbuilder\permission;
use core_reportbuilder\external\custom_report_conditions_exporter;
use core_reportbuilder\local\helpers\report;
/**
* External method for adding report conditions
*
* @package core_reportbuilder
* @copyright 2021 Paul Holden <paulh@moodle.com>
* @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();
}
}
+97
View File
@@ -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 core_external\external_api;
use core_external\external_value;
use core_external\external_single_structure;
use core_external\external_function_parameters;
use core_reportbuilder\manager;
use core_reportbuilder\permission;
use core_reportbuilder\external\custom_report_conditions_exporter;
use core_reportbuilder\local\helpers\report;
/**
* External method for deleting report conditions
*
* @package core_reportbuilder
* @copyright 2021 Paul Holden <paulh@moodle.com>
* @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();
}
}
+101
View File
@@ -0,0 +1,101 @@
<?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 core_external\external_api;
use core_external\external_value;
use core_external\external_single_structure;
use core_external\external_function_parameters;
use core_reportbuilder\manager;
use core_reportbuilder\permission;
use core_reportbuilder\external\custom_report_conditions_exporter;
use core_reportbuilder\local\helpers\report;
/**
* External method for re-ordering report conditions
*
* @package core_reportbuilder
* @copyright 2021 Paul Holden <paulh@moodle.com>
* @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();
}
}
+92
View File
@@ -0,0 +1,92 @@
<?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 core_external\external_api;
use core_external\external_value;
use core_external\external_single_structure;
use core_external\external_function_parameters;
use core_reportbuilder\manager;
use core_reportbuilder\permission;
use core_reportbuilder\external\custom_report_conditions_exporter;
/**
* External method for resetting report conditions
*
* @package core_reportbuilder
* @copyright 2021 Paul Holden <paulh@moodle.com>
* @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,85 @@
<?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 core_collator;
use core_component;
use renderer_base;
use core_reportbuilder\local\audiences\base;
/**
* Custom report audience cards exporter class
*
* @package core_reportbuilder
* @copyright 2022 Paul Holden <paulh@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class custom_report_audience_cards_exporter extends custom_report_menu_cards_exporter {
/**
* Get the additional values to inject while exporting
*
* @param renderer_base $output
* @return array
*/
protected function get_other_values(renderer_base $output): array {
$menucards = [];
// Iterate over all audience types.
$audiences = core_component::get_component_classes_in_namespace(null, 'reportbuilder\\audience');
$audiencekeyindex = 0;
foreach ($audiences as $class => $path) {
if (is_subclass_of($class, base::class)) {
$audience = $class::instance();
if (!$audience->user_can_add()) {
continue;
}
// New menu card per component.
$componentname = $audience->get_component_displayname();
if (!array_key_exists($componentname, $menucards)) {
$menucards[$componentname] = [
'name' => $componentname,
'key' => 'index' . ++$audiencekeyindex,
'items' => [],
];
}
// Append menu card item per audience.
$menucards[$componentname]['items'][] = [
'name' => $audience->get_name(),
'identifier' => get_class($audience),
'title' => get_string('addaudience', 'core_reportbuilder', $audience->get_name()),
'action' => 'add-audience',
'disabled' => !$audience->is_available(),
];
}
}
// Order items in each menu card alphabetically.
array_walk($menucards, static function(array &$menucard): void {
core_collator::asort_array_of_arrays_by_key($menucard['items'], 'name');
$menucard['items'] = array_values($menucard['items']);
});
return [
'menucards' => array_values($menucards),
];
}
}
@@ -0,0 +1,88 @@
<?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\datasource;
use core_reportbuilder\form\card_view;
/**
* Custom report card view exporter class
*
* @package core_reportbuilder
* @copyright 2021 Mikel Martín <mikel@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class custom_report_card_view_exporter extends exporter {
/**
* Return a list of objects that are related to the exporter
*
* @return array
*/
protected static function define_related(): array {
return [
'report' => datasource::class,
];
}
/**
* Return the list of additional properties for read structure and export
*
* @return array[]
*/
protected static function define_other_properties(): array {
return [
'form' => [
'type' => PARAM_RAW,
],
'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 datasource $report */
$report = $this->related['report'];
$reportid = $report->get_report_persistent()->get('id');
$reportsettings = $report->get_settings_values();
$cardviewsettings = [
'showfirsttitle' => $reportsettings['cardview_showfirsttitle'] ?? 0,
'visiblecolumns' => $reportsettings['cardview_visiblecolumns'] ?? 1,
];
$cardviewform = new card_view(null, null, 'post', '', [], true,
array_merge(['reportid' => $reportid], $cardviewsettings));
$cardviewform->set_data_for_dynamic_submission();
return [
'form' => $cardviewform->render(),
'helpicon' => $output->help_icon('cardview', 'core_reportbuilder'),
];
}
}
@@ -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;
use renderer_base;
use core_reportbuilder\datasource;
/**
* Custom report column cards exporter class
*
* @package core_reportbuilder
* @copyright 2022 Paul Holden <paulh@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class custom_report_column_cards_exporter extends custom_report_menu_cards_exporter {
/**
* Return a list of objects that are related to the exporter
*
* @return array
*/
protected static function define_related(): array {
return [
'report' => datasource::class,
];
}
/**
* Get the additional values to inject while exporting
*
* @param renderer_base $output
* @return array
*/
protected function get_other_values(renderer_base $output): array {
/** @var datasource $report */
$report = $this->related['report'];
$menucards = [];
foreach ($report->get_columns() as $column) {
if ($column->get_is_deprecated()) {
continue;
}
// New menu card per entity.
$entityname = $column->get_entity_name();
if (!array_key_exists($entityname, $menucards)) {
$menucards[$entityname] = [
'name' => (string) $report->get_entity_title($entityname),
'key' => $entityname,
'items' => [],
];
}
// Append menu card item per column.
$menucards[$entityname]['items'][] = [
'name' => $column->get_title(),
'identifier' => $column->get_unique_identifier(),
'title' => get_string('addcolumn', 'core_reportbuilder', $column->get_title()),
'action' => 'report-add-column',
];
}
return [
'menucards' => array_values($menucards),
];
}
}
@@ -0,0 +1,133 @@
<?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 core_collator;
use pix_icon;
use renderer_base;
use core\external\exporter;
use core_reportbuilder\datasource;
use core_reportbuilder\local\report\column;
/**
* Custom report columns sorting exporter class
*
* @package core_reportbuilder
* @copyright 2021 David Matamoros <davidmc@moodle.com>
* @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' => datasource::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_BOOL],
'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],
],
'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 datasource $report */
$report = $this->related['report'];
// Filter/retrieve all "sortable" active columns.
$sortablecolumns = array_filter($report->get_active_columns(), function(column $column): bool {
return $column->get_is_sortable();
});
$sortablecolumns = array_map(function(column $column) use ($report): array {
$persistent = $column->get_persistent();
$columntitle = $column->get_title();
$columnheading = $persistent->get_formatted_heading($report->get_context());
$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 !== '' ? $columnheading : $columntitle,
'sortdirection' => $persistent->get('sortdirection'),
'sortenabled' => $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);
core_collator::asort_array_of_arrays_by_key($sortablecolumns, 'sortorder', core_collator::SORT_NUMERIC);
return [
'hassortablecolumns' => !empty($sortablecolumns),
'sortablecolumns' => array_values($sortablecolumns),
'helpicon' => $output->help_icon('sorting', 'core_reportbuilder'),
];
}
}
@@ -0,0 +1,149 @@
<?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\datasource;
use core_reportbuilder\form\condition;
use core_reportbuilder\local\report\filter;
/**
* Custom report conditions exporter class
*
* @package core_reportbuilder
* @copyright 2021 Paul Holden <paulh@moodle.com>
* @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' => datasource::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,
],
'hasactiveconditions' => [
'type' => PARAM_BOOL,
],
'activeconditionsform' => [
'type' => PARAM_RAW,
],
'helpicon' => [
'type' => PARAM_RAW,
],
'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 datasource $report */
$report = $this->related['report'];
// Current condition instances contained in the report.
$conditions = $report->get_active_conditions();
$conditionidentifiers = array_map(static function(filter $condition): string {
return $condition->get_unique_identifier();
}, $conditions);
$availableconditions = [];
// Populate available conditions.
foreach ($report->get_conditions() as $condition) {
// Conditions can only be added once per report, skip if it already exists.
if (in_array($condition->get_unique_identifier(), $conditionidentifiers) || $condition->get_is_deprecated()) {
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 conditions form if any present.
$conditionspresent = !empty($conditions);
if ($conditionspresent) {
$conditionsform = new condition(null, null, 'post', '', [], true, [
'reportid' => $report->get_report_persistent()->get('id'),
]);
$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,107 @@
<?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\datasource;
use core_reportbuilder\table\custom_report_table_view;
/**
* Custom report data exporter class
*
* @package core_reportbuilder
* @copyright 2022 Paul Holden <paulh@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class custom_report_data_exporter extends exporter {
/**
* Return a list of objects that are related to the exporter
*
* @return array
*/
protected static function define_related(): array {
return [
'report' => datasource::class,
'page' => 'int',
'perpage' => 'int',
];
}
/**
* Return the list of additional properties for read structure and export
*
* @return array[]
*/
protected static function define_other_properties(): array {
return [
'headers' => [
'type' => PARAM_RAW,
'multiple' => true,
],
'rows' => [
'type' => [
'columns' => [
'type' => PARAM_RAW,
'null' => NULL_ALLOWED,
'multiple' => true,
],
],
'multiple' => true,
],
'totalrowcount' => ['type' => PARAM_INT],
];
}
/**
* Get the additional values to inject while exporting
*
* @param renderer_base $output
* @return array
*/
protected function get_other_values(renderer_base $output): array {
global $DB;
/** @var datasource $report */
$report = $this->related['report'];
$table = custom_report_table_view::create($report->get_report_persistent()->get('id'));
$table->setup();
// Internally the current page is zero-based, but this method expects value plus one.
$table->set_page_number($this->related['page'] + 1);
$table->query_db($this->related['perpage'], false);
$tablerows = [];
foreach ($table->rawdata as $record) {
$tablerows[] = [
'columns' => array_values($table->format_row($record)),
];
}
$table->close_recordset();
return [
'headers' => $table->headers,
'rows' => $tablerows,
'totalrowcount' => $DB->count_records_sql($table->countsql, $table->countparams),
];
}
}
@@ -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\external;
use core_user;
use renderer_base;
use core\external\persistent_exporter;
use core_reportbuilder\datasource;
use core_reportbuilder\manager;
use core_reportbuilder\local\models\report;
use core_user\external\user_summary_exporter;
/**
* Custom report details exporter class
*
* @package core_reportbuilder
* @copyright 2022 Paul Holden <paulh@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class custom_report_details_exporter extends persistent_exporter {
/** @var report The persistent object we will export. */
protected $persistent = null;
/**
* Return the name of the class we are exporting
*
* @return string
*/
protected static function define_class(): string {
return report::class;
}
/**
* Return a list of additional properties used only for display
*
* @return array
*/
protected static function define_other_properties(): array {
return [
'sourcename' => [
'type' => PARAM_RAW,
'null' => NULL_ALLOWED,
],
'modifiedby' => ['type' => user_summary_exporter::read_properties_definition()],
];
}
/**
* Get additional values to inject while exporting
*
* @param renderer_base $output
* @return array
*/
protected function get_other_values(renderer_base $output): array {
$source = $this->persistent->get('source');
$usermodified = core_user::get_user($this->persistent->get('usermodified'));
return [
'sourcename' => manager::report_source_exists($source, datasource::class) ? $source::get_name() : null,
'modifiedby' => (new user_summary_exporter($usermodified))->export($output),
];
}
}
@@ -0,0 +1,216 @@
<?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_table\local\filter\integer_filter;
/**
* Custom report exporter class
*
* @package core_reportbuilder
* @copyright 2021 David Matamoros <davidmc@moodle.com>
* @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 string */
protected $download;
/**
* report_exporter constructor.
*
* @param persistent $persistent
* @param array $related
* @param bool $editmode
* @param string $download
*/
public function __construct(persistent $persistent, array $related = [], bool $editmode = true, string $download = '') {
parent::__construct($persistent, $related);
$this->editmode = $editmode;
$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 [
'pagesize' => 'int?',
];
}
/**
* Return a list of additional properties used only for display
*
* @return array
*/
protected static function define_other_properties(): array {
return [
'table' => ['type' => PARAM_RAW],
'filtersapplied' => ['type' => PARAM_INT],
'filterspresent' => ['type' => PARAM_BOOL],
'filtersform' => ['type' => PARAM_RAW],
'attributes' => [
'type' => [
'name' => ['type' => PARAM_TEXT],
'value' => ['type' => PARAM_TEXT]
],
'multiple' => true,
],
'classes' => ['type' => PARAM_TEXT],
'editmode' => ['type' => PARAM_BOOL],
'sidebarmenucards' => [
'type' => custom_report_column_cards_exporter::read_properties_definition(),
'optional' => true,
],
'conditions' => [
'type' => custom_report_conditions_exporter::read_properties_definition(),
'optional' => true,
],
'filters' => [
'type' => custom_report_filters_exporter::read_properties_definition(),
'optional' => true,
],
'sorting' => [
'type' => custom_report_columns_sorting_exporter::read_properties_definition(),
'optional' => true,
],
'cardview' => [
'type' => custom_report_card_view_exporter::read_properties_definition(),
'optional' => true,
],
'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 {
/** @var datasource $report */
$report = manager::get_report_from_persistent($this->persistent);
$filterspresent = false;
$filtersform = '';
$attributes = [];
if ($this->editmode) {
$table = custom_report_table::create($this->persistent->get('id'));
$table->set_filterset(new custom_report_table_filterset());
} else {
// We store the pagesize within the table filterset so that it's available between AJAX requests.
$filterset = new custom_report_table_view_filterset();
$filterset->add_filter(new integer_filter('pagesize', null, [$this->related['pagesize']]));
$table = custom_report_table_view::create($this->persistent->get('id'), $this->download);
$table->set_filterset($filterset);
// Generate filters form if report contains any filters.
$filterspresent = !empty($report->get_active_filters());
if ($filterspresent && empty($this->download)) {
$filtersform = $this->generate_filters_form()->render();
}
// Get the report classes and attributes.
$reportattributes = $report->get_attributes();
if (isset($reportattributes['class'])) {
$classes = $reportattributes['class'];
unset($reportattributes['class']);
}
$attributes = array_map(static function($key, $value): array {
return ['name' => $key, 'value' => $value];
}, array_keys($reportattributes), $reportattributes);
}
// If we are editing we need all this information for the template.
$editordata = [];
if ($this->editmode) {
$menucardsexporter = new custom_report_column_cards_exporter(null, ['report' => $report]);
$editordata['sidebarmenucards'] = (array) $menucardsexporter->export($output);
$conditionsexporter = new custom_report_conditions_exporter(null, ['report' => $report]);
$editordata['conditions'] = (array) $conditionsexporter->export($output);
$filtersexporter = new custom_report_filters_exporter(null, ['report' => $report]);
$editordata['filters'] = (array) $filtersexporter->export($output);
$sortingexporter = new custom_report_columns_sorting_exporter(null, ['report' => $report]);
$editordata['sorting'] = (array) $sortingexporter->export($output);
$cardviewexporter = new custom_report_card_view_exporter(null, ['report' => $report]);
$editordata['cardview'] = (array) $cardviewexporter->export($output);
}
return [
'table' => $output->render($table),
'filtersapplied' => $report->get_applied_filter_count(),
'filterspresent' => $filterspresent,
'filtersform' => $filtersform,
'attributes' => $attributes,
'classes' => $classes ?? '',
'editmode' => $this->editmode,
'javascript' => '',
] + $editordata;
}
/**
* 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,163 @@
<?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\datasource;
use core_reportbuilder\local\report\filter;
use core_reportbuilder\output\filter_heading_editable;
/**
* Custom report filters exporter class
*
* @package core_reportbuilder
* @copyright 2021 Paul Holden <paulh@moodle.com>
* @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' => datasource::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,
],
'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,
],
'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 datasource $report */
$report = $this->related['report'];
// Current filter instances contained in the report.
$filters = $report->get_active_filters();
$filteridentifiers = array_map(static function(filter $filter): string {
return $filter->get_unique_identifier();
}, $filters);
$availablefilters = $activefilters = [];
// Populate available filters.
foreach ($report->get_filters() as $filter) {
// Filters can only be added once per report, skip if it already exists.
if (in_array($filter->get_unique_identifier(), $filteridentifiers) || $filter->get_is_deprecated()) {
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.
$filterinstances = $report->get_filter_instances();
foreach ($filterinstances as $filterinstance) {
$persistent = $filterinstance->get_filter_persistent();
$entityname = $filterinstance->get_entity_name();
$displayvalue = $filterinstance->get_header();
$editable = new filter_heading_editable(0, $persistent);
$activefilters[] = [
'id' => $persistent->get('id'),
'entityname' => $report->get_entity_title($entityname)->out(),
'heading' => $displayvalue,
'headingeditable' => $editable->render($output),
'sortorder' => $persistent->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,76 @@
<?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 core\external\exporter;
/**
* Custom report menu cards exporter abstract class
*
* @package core_reportbuilder
* @copyright 2021 David Matamoros <davidmc@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
abstract class custom_report_menu_cards_exporter extends exporter {
/**
* 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,
],
'key' => [
'type' => PARAM_TEXT,
],
'items' => [
'type' => [
'name' => [
'type' => PARAM_TEXT,
],
'identifier' => [
'type' => PARAM_TEXT,
],
'title' => [
'type' => PARAM_TEXT,
],
'action' => [
'type' => PARAM_TEXT,
],
'disabled' => [
'type' => PARAM_BOOL,
'optional' => true,
'default' => false,
],
],
'optional' => true,
'multiple' => true,
],
],
'optional' => true,
'multiple' => true,
],
];
}
}
+91
View File
@@ -0,0 +1,91 @@
<?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 core_external\external_api;
use core_external\external_value;
use core_external\external_single_structure;
use core_external\external_function_parameters;
use core_reportbuilder\manager;
use core_reportbuilder\permission;
use core_reportbuilder\external\custom_report_filters_exporter;
use core_reportbuilder\local\helpers\report;
/**
* External method for adding report filters
*
* @package core_reportbuilder
* @copyright 2021 Paul Holden <paulh@moodle.com>
* @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();
}
}
+91
View File
@@ -0,0 +1,91 @@
<?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 core_external\external_api;
use core_external\external_value;
use core_external\external_single_structure;
use core_external\external_function_parameters;
use core_reportbuilder\manager;
use core_reportbuilder\permission;
use core_reportbuilder\external\custom_report_filters_exporter;
use core_reportbuilder\local\helpers\report;
/**
* External method for deleting report filters
*
* @package core_reportbuilder
* @copyright 2021 Paul Holden <paulh@moodle.com>
* @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();
}
}
+95
View File
@@ -0,0 +1,95 @@
<?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 core_external\external_api;
use core_external\external_value;
use core_external\external_single_structure;
use core_external\external_function_parameters;
use core_reportbuilder\manager;
use core_reportbuilder\permission;
use core_reportbuilder\external\custom_report_filters_exporter;
use core_reportbuilder\local\helpers\report;
/**
* External method for re-ordering report filters
*
* @package core_reportbuilder
* @copyright 2021 Paul Holden <paulh@moodle.com>
* @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();
}
}
+86
View File
@@ -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\external\filters;
use core_external\external_api;
use core_external\external_value;
use core_external\external_function_parameters;
use core_reportbuilder\manager;
use core_reportbuilder\permission;
use core_reportbuilder\local\helpers\user_filter_manager;
/**
* External method for resetting report filters
*
* @package core_reportbuilder
* @copyright 2021 Paul Holden <paulh@moodle.com>
* @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'),
'parameters' => new external_value(PARAM_RAW, 'JSON encoded report parameters', VALUE_DEFAULT, ''),
]);
}
/**
* External method execution
*
* @param int $reportid
* @param string $parameters JSON encoded parameters used to re-create the report, for instance for those reports that
* require parameters as part of their {@see \core_reportbuilder\system_report::can_view} implementation
* @return bool
*/
public static function execute(int $reportid, string $parameters = ''): bool {
[
'reportid' => $reportid,
'parameters' => $parameters,
] = self::validate_parameters(self::execute_parameters(), [
'reportid' => $reportid,
'parameters' => $parameters,
]);
$report = manager::get_report_from_id($reportid, (array) json_decode($parameters));
self::validate_context($report->get_context());
// System report permission is implicitly handled, we need to make sure custom report can be viewed.
$persistent = $report->get_report_persistent();
if ($persistent->get('type') === $report::TYPE_CUSTOM_REPORT) {
permission::require_can_view_report($persistent);
}
return user_filter_manager::reset_all($reportid);
}
/**
* External method return value
*
* @return external_value
*/
public static function execute_returns(): external_value {
return new external_value(PARAM_BOOL, 'Success');
}
}
+88
View File
@@ -0,0 +1,88 @@
<?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 core_external\external_api;
use core_external\external_value;
use core_external\external_function_parameters;
use core_reportbuilder\manager;
use core_reportbuilder\permission;
/**
* External method for setting report filter values
*
* @package core_reportbuilder
* @copyright 2022 Paul Holden <paulh@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class set 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'),
'parameters' => new external_value(PARAM_RAW, 'JSON encoded report parameters', VALUE_DEFAULT, ''),
'values' => new external_value(PARAM_RAW, 'JSON encoded filter values'),
]);
}
/**
* External method execution
*
* @param int $reportid
* @param string $parameters
* @param string $values
* @return bool
*/
public static function execute(int $reportid, string $parameters, string $values): bool {
[
'reportid' => $reportid,
'parameters' => $parameters,
'values' => $values,
] = self::validate_parameters(self::execute_parameters(), [
'reportid' => $reportid,
'parameters' => $parameters,
'values' => $values,
]);
$report = manager::get_report_from_id($reportid, (array) json_decode($parameters));
self::validate_context($report->get_context());
// System report permission is implicitly handled, we need to make sure custom report can be viewed.
$persistent = $report->get_report_persistent();
if ($persistent->get('type') === $report::TYPE_CUSTOM_REPORT) {
permission::require_can_view_report($persistent);
}
return $report->set_filter_values((array) json_decode($values));
}
/**
* External method return value
*
* @return external_value
*/
public static function execute_returns(): external_value {
return new external_value(PARAM_BOOL, 'Success');
}
}
+79
View File
@@ -0,0 +1,79 @@
<?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 core_external\external_api;
use core_external\external_value;
use core_external\external_function_parameters;
use core_reportbuilder\permission;
use core_reportbuilder\local\helpers\report;
use core_reportbuilder\local\models\report as report_model;
/**
* External method for deleting reports
*
* @package core_reportbuilder
* @copyright 2021 Paul Holden <paulh@moodle.com>
* @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');
}
}
+106
View File
@@ -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\reports;
use core_external\external_api;
use core_external\external_value;
use core_external\external_single_structure;
use core_external\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;
/**
* External method for getting a custom report
*
* @package core_reportbuilder
* @copyright 2021 David Matamoros <davidmc@moodle.com>
* @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),
'pagesize' => new external_value(PARAM_INT, 'Page size', VALUE_DEFAULT, 0),
]);
}
/**
* External method execution
*
* @param int $reportid
* @param bool $editmode
* @param int $pagesize
* @return array
*/
public static function execute(int $reportid, bool $editmode, int $pagesize = 0): array {
global $PAGE, $OUTPUT;
[
'reportid' => $reportid,
'editmode' => $editmode,
'pagesize' => $pagesize,
] = self::validate_parameters(self::execute_parameters(), [
'reportid' => $reportid,
'editmode' => $editmode,
'pagesize' => $pagesize,
]);
$report = manager::get_report_from_id($reportid);
if ($pagesize > 0) {
$report->set_default_per_page($pagesize);
}
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();
}
}
+108
View File
@@ -0,0 +1,108 @@
<?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 context_system;
use core_external\external_api;
use core_external\external_value;
use core_external\external_single_structure;
use core_external\external_multiple_structure;
use core_external\external_function_parameters;
use core_external\external_warnings;
use stdClass;
use core_reportbuilder\permission;
use core_reportbuilder\external\custom_report_details_exporter;
use core_reportbuilder\local\helpers\audience;
use core_reportbuilder\local\models\report;
/**
* External method for listing users' custom reports
*
* @package core_reportbuilder
* @copyright 2022 Paul Holden <paulh@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class listing extends external_api {
/**
* External method parameters
*
* @return external_function_parameters
*/
public static function execute_parameters(): external_function_parameters {
return new external_function_parameters([
'page' => new external_value(PARAM_INT, 'Page number', VALUE_DEFAULT, 0),
'perpage' => new external_value(PARAM_INT, 'Reports per page', VALUE_DEFAULT, 10),
]);
}
/**
* External method execution
*
* @param int $page
* @param int $perpage
* @return array
*/
public static function execute(int $page = 0, int $perpage = 10): array {
global $DB, $PAGE;
[
'page' => $page,
'perpage' => $perpage,
] = self::validate_parameters(self::execute_parameters(), [
'page' => $page,
'perpage' => $perpage,
]);
$context = context_system::instance();
self::validate_context($context);
permission::require_can_view_reports_list(null, $context);
// Filter list of reports by those the user can access.
[$where, $params] = audience::user_reports_list_access_sql('r');
$reports = $DB->get_records_sql("
SELECT r.*
FROM {" . report::TABLE . "} r
WHERE r.type = 0 AND {$where}
ORDER BY r.name, r.id", $params, $page * $perpage, $perpage);
$output = $PAGE->get_renderer('core');
return [
'reports' => array_map(static function(stdClass $report) use ($output): array {
$exporter = new custom_report_details_exporter(new report(0, $report));
return (array) $exporter->export($output);
}, $reports),
'warnings' => [],
];
}
/**
* External method return value
*
* @return external_single_structure
*/
public static function execute_returns(): external_single_structure {
return new external_single_structure([
'reports' => new external_multiple_structure(custom_report_details_exporter::get_read_structure()),
'warnings' => new external_warnings(),
]);
}
}
+102
View File
@@ -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\reports;
use core_reportbuilder\manager;
use core_external\external_api;
use core_external\external_value;
use core_external\external_single_structure;
use core_external\external_function_parameters;
use core_external\external_warnings;
use core_reportbuilder\permission;
use core_reportbuilder\external\{custom_report_data_exporter, custom_report_details_exporter};
/**
* External method for retrieving custom report content
*
* @package core_reportbuilder
* @copyright 2022 Paul Holden <paulh@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class retrieve 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'),
'page' => new external_value(PARAM_INT, 'Page number', VALUE_DEFAULT, 0),
'perpage' => new external_value(PARAM_INT, 'Reports per page', VALUE_DEFAULT, 10),
]);
}
/**
* External method execution
*
* @param int $reportid
* @param int $page
* @param int $perpage
* @return array
*/
public static function execute(int $reportid, int $page = 0, int $perpage = 10): array {
global $PAGE;
[
'reportid' => $reportid,
'page' => $page,
'perpage' => $perpage,
] = self::validate_parameters(self::execute_parameters(), [
'reportid' => $reportid,
'page' => $page,
'perpage' => $perpage,
]);
$report = manager::get_report_from_id($reportid);
self::validate_context($report->get_context());
$persistent = $report->get_report_persistent();
permission::require_can_view_report($persistent);
$output = $PAGE->get_renderer('core');
return [
'details' => (array) (new custom_report_details_exporter($persistent))->export($output),
'data' => (array) (new custom_report_data_exporter(null, [
'report' => $report, 'page' => $page, 'perpage' => $perpage,
]))->export($output),
'warnings' => [],
];
}
/**
* External method return value
*
* @return external_single_structure
*/
public static function execute_returns(): external_single_structure {
return new external_single_structure([
'details' => custom_report_details_exporter::get_read_structure(),
'data' => custom_report_data_exporter::get_read_structure(),
'warnings' => new external_warnings(),
]);
}
}
+89
View File
@@ -0,0 +1,89 @@
<?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 core_external\external_api;
use core_external\external_value;
use core_external\external_single_structure;
use core_external\external_function_parameters;
use core_external\external_warnings;
use core_reportbuilder\manager;
use core_reportbuilder\permission;
use core_reportbuilder\event\report_viewed;
/**
* External method to record the viewing of a report
*
* @package core_reportbuilder
* @copyright 2022 Paul Holden <paulh@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class view 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 {
[
'reportid' => $reportid,
] = self::validate_parameters(self::execute_parameters(), [
'reportid' => $reportid,
]);
$report = manager::get_report_from_id($reportid);
self::validate_context($report->get_context());
$persistent = $report->get_report_persistent();
permission::require_can_view_report($persistent);
// Trigger the report viewed event.
report_viewed::create_from_object($persistent)->trigger();
return [
'status' => true,
'warnings' => [],
];
}
/**
* External method return value
*
* @return external_single_structure
*/
public static function execute_returns(): external_single_structure {
return new external_single_structure([
'status' => new external_value(PARAM_BOOL, 'Success'),
'warnings' => new external_warnings(),
]);
}
}
+81
View File
@@ -0,0 +1,81 @@
<?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\schedules;
use core_external\external_api;
use core_external\external_value;
use core_external\external_function_parameters;
use core_reportbuilder\manager;
use core_reportbuilder\permission;
use core_reportbuilder\local\helpers\schedule;
/**
* External method for deleting report schedules
*
* @package core_reportbuilder
* @copyright 2021 Paul Holden <paulh@moodle.com>
* @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'),
'scheduleid' => new external_value(PARAM_INT, 'Schedule ID'),
]);
}
/**
* External method execution
*
* @param int $reportid
* @param int $scheduleid
* @return bool
*/
public static function execute(int $reportid, int $scheduleid): bool {
[
'reportid' => $reportid,
'scheduleid' => $scheduleid,
] = self::validate_parameters(self::execute_parameters(), [
'reportid' => $reportid,
'scheduleid' => $scheduleid,
]);
$report = manager::get_report_from_id($reportid);
self::validate_context($report->get_context());
permission::require_can_edit_report($report->get_report_persistent());
return schedule::delete_schedule($reportid, $scheduleid);
}
/**
* External method return value
*
* @return external_value
*/
public static function execute_returns(): external_value {
return new external_value(PARAM_BOOL);
}
}
+87
View File
@@ -0,0 +1,87 @@
<?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\schedules;
use core_external\external_api;
use core_external\external_value;
use core_external\external_function_parameters;
use core_reportbuilder\manager;
use core_reportbuilder\permission;
use core_reportbuilder\task\send_schedule;
/**
* External method for sending report schedules
*
* @package core_reportbuilder
* @copyright 2021 Paul Holden <paulh@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class send 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'),
'scheduleid' => new external_value(PARAM_INT, 'Schedule ID'),
]);
}
/**
* External method execution
*
* @param int $reportid
* @param int $scheduleid
* @return bool
*/
public static function execute(int $reportid, int $scheduleid): bool {
[
'reportid' => $reportid,
'scheduleid' => $scheduleid,
] = self::validate_parameters(self::execute_parameters(), [
'reportid' => $reportid,
'scheduleid' => $scheduleid,
]);
$report = manager::get_report_from_id($reportid);
self::validate_context($report->get_context());
permission::require_can_edit_report($report->get_report_persistent());
$sendschedule = new send_schedule();
$sendschedule->set_custom_data([
'reportid' => $reportid,
'scheduleid' => $scheduleid,
]);
return (bool) \core\task\manager::queue_adhoc_task($sendschedule);
}
/**
* External method return value
*
* @return external_value
*/
public static function execute_returns(): external_value {
return new external_value(PARAM_BOOL);
}
}
+85
View File
@@ -0,0 +1,85 @@
<?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\schedules;
use core_external\external_api;
use core_external\external_value;
use core_external\external_function_parameters;
use core_reportbuilder\manager;
use core_reportbuilder\permission;
use core_reportbuilder\local\helpers\schedule;
/**
* External method for toggling report schedules
*
* @package core_reportbuilder
* @copyright 2021 Paul Holden <paulh@moodle.com>
* @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'),
'scheduleid' => new external_value(PARAM_INT, 'Schedule ID'),
'enabled' => new external_value(PARAM_BOOL, 'Schedule enabled'),
]);
}
/**
* External method execution
*
* @param int $reportid
* @param int $scheduleid
* @param bool $enabled
* @return bool
*/
public static function execute(int $reportid, int $scheduleid, bool $enabled): bool {
[
'reportid' => $reportid,
'scheduleid' => $scheduleid,
'enabled' => $enabled,
] = self::validate_parameters(self::execute_parameters(), [
'reportid' => $reportid,
'scheduleid' => $scheduleid,
'enabled' => $enabled,
]);
$report = manager::get_report_from_id($reportid);
self::validate_context($report->get_context());
permission::require_can_edit_report($report->get_report_persistent());
return schedule::toggle_schedule($reportid, $scheduleid, $enabled);
}
/**
* External method return value
*
* @return external_value
*/
public static function execute_returns(): external_value {
return new external_value(PARAM_BOOL);
}
}
@@ -0,0 +1,115 @@
<?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\system_report;
use core_reportbuilder\table\system_report_table;
/**
* System report data exporter class
*
* @package core_reportbuilder
* @copyright 2023 Paul Holden <paulh@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class system_report_data_exporter extends exporter {
/**
* Return a list of objects that are related to the exporter
*
* @return array
*/
protected static function define_related(): array {
return [
'report' => system_report::class,
'page' => 'int',
'perpage' => 'int',
];
}
/**
* Return the list of additional properties for read structure and export
*
* @return array[]
*/
protected static function define_other_properties(): array {
return [
'headers' => [
'type' => PARAM_RAW,
'multiple' => true,
],
'rows' => [
'type' => [
'columns' => [
'type' => PARAM_RAW,
'null' => NULL_ALLOWED,
'multiple' => true,
],
],
'multiple' => true,
],
'totalrowcount' => ['type' => PARAM_INT],
];
}
/**
* Get the additional values to inject while exporting
*
* @param renderer_base $output
* @return array
*/
protected function get_other_values(renderer_base $output): array {
global $DB;
/** @var system_report $report */
$report = $this->related['report'];
$table = system_report_table::create($report->get_report_persistent()->get('id'), $report->get_parameters());
$table->guess_base_url();
$table->setup();
// Internally the current page is zero-based, but this method expects value plus one.
$table->set_page_number($this->related['page'] + 1);
$table->query_db($this->related['perpage'], false);
// Ensure we only return defined columns, excluding those such as "select all" and "actions".
$columnsbyalias = $report->get_active_columns_by_alias();
$tableheaders = array_combine(array_flip($table->columns), $table->headers);
$tableheaders = array_intersect_key($tableheaders, $columnsbyalias);
$tablerows = [];
foreach ($table->rawdata as $record) {
$columns = array_intersect_key($table->format_row($record), $columnsbyalias);
$tablerows[] = [
'columns' => array_values($columns),
];
}
$table->close_recordset();
return [
'headers' => array_values($tableheaders),
'rows' => $tablerows,
'totalrowcount' => $DB->count_records_sql($table->countsql, $table->countparams),
];
}
}
@@ -0,0 +1,141 @@
<?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 core\external\persistent_exporter;
use core_table\local\filter\integer_filter;
use core_table\local\filter\string_filter;
use core_reportbuilder\system_report;
use core_reportbuilder\form\filter;
use core_reportbuilder\local\models\report;
use core_reportbuilder\table\system_report_table;
use core_reportbuilder\table\system_report_table_filterset;
use renderer_base;
/**
* Report exporter class
*
* @package core_reportbuilder
* @copyright 2020 Paul Holden <paulh@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class system_report_exporter extends persistent_exporter {
/**
* 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 [
'source' => system_report::class,
'parameters' => 'string',
];
}
/**
* Return a list of additional properties used only for display
*
* @return array
*/
protected static function define_other_properties(): array {
return [
'table' => ['type' => PARAM_RAW],
'parameters' => ['type' => PARAM_RAW],
'filterspresent' => ['type' => PARAM_BOOL],
'filtersapplied' => ['type' => PARAM_INT],
'filtersform' => ['type' => PARAM_RAW],
'attributes' => [
'type' => [
'name' => ['type' => PARAM_TEXT],
'value' => ['type' => PARAM_TEXT]
],
'multiple' => true,
],
'classes' => ['type' => PARAM_TEXT],
];
}
/**
* Get additional values to inject while exporting
*
* @uses \core_reportbuilder\output\renderer::render_system_report_table()
*
* @param renderer_base $output
* @return array
*/
protected function get_other_values(renderer_base $output): array {
/** @var system_report $source */
$source = $this->related['source'];
/** @var string $parameters */
$parameters = $this->related['parameters'];
/** @var int $reportid */
$reportid = $this->persistent->get('id');
// We store the report ID and parameters within the table filterset so that they are available between AJAX requests.
$filterset = new system_report_table_filterset();
$filterset->add_filter(new integer_filter('reportid', null, [$reportid]));
$filterset->add_filter(new string_filter('parameters', null, [$parameters]));
$params = (array) json_decode($parameters, true);
$table = system_report_table::create($reportid, $params);
$table->set_filterset($filterset);
// Generate filters form if report uses the default form, and contains any filters.
$filterspresent = $source->get_filter_form_default() && !empty($source->get_active_filters());
if ($filterspresent && empty($params['download'])) {
$filtersform = new filter(null, null, 'post', '', [], true, [
'reportid' => $reportid,
'parameters' => $parameters,
]);
$filtersform->set_data_for_dynamic_submission();
}
// Get the report classes and attributes.
$sourceattributes = $source->get_attributes();
if (isset($sourceattributes['class'])) {
$classes = $sourceattributes['class'];
unset($sourceattributes['class']);
}
$attributes = array_map(static function($key, $value): array {
return ['name' => $key, 'value' => $value];
}, array_keys($sourceattributes), $sourceattributes);
return [
'table' => $output->render($table),
'parameters' => $parameters,
'filterspresent' => $filterspresent,
'filtersapplied' => $source->get_applied_filter_count(),
'filtersform' => $filterspresent ? $filtersform->render() : '',
'attributes' => $attributes,
'classes' => $classes ?? '',
];
}
}
@@ -0,0 +1,120 @@
<?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\systemreports;
use core_external\external_api;
use core_external\external_multiple_structure;
use core_external\external_single_structure;
use core_external\external_function_parameters;
use core_external\external_value;
use core_reportbuilder\report_access_exception;
use core_reportbuilder\system_report_factory;
/**
* External method for validating access to a system report
*
* @package core_reportbuilder
* @copyright 2023 Paul Holden <paulh@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class can_view extends external_api {
/**
* External method parameters
*
* @return external_function_parameters
*/
public static function execute_parameters(): external_function_parameters {
return new external_function_parameters([
'source' => new external_value(PARAM_RAW, 'Report class path'),
'context' => self::get_context_parameters(),
'component' => new external_value(PARAM_COMPONENT, 'Report component', VALUE_DEFAULT, ''),
'area' => new external_value(PARAM_AREA, 'Report area', VALUE_DEFAULT, ''),
'itemid' => new external_value(PARAM_INT, 'Report item ID', VALUE_DEFAULT, 0),
'parameters' => new external_multiple_structure(
new external_single_structure([
'name' => new external_value(PARAM_RAW),
'value' => new external_value(PARAM_RAW),
]),
'Report parameters', VALUE_DEFAULT, []
),
]);
}
/**
* External method execution
*
* @param string $source
* @param array $context
* @param string $component
* @param string $area
* @param int $itemid
* @param array[] $parameters
* @return bool
*/
public static function execute(
string $source,
array $context,
string $component = '',
string $area = '',
int $itemid = 0,
array $parameters = [],
): bool {
[
'source' => $source,
'context' => $context,
'component' => $component,
'area' => $area,
'itemid' => $itemid,
'parameters' => $parameters,
] = self::validate_parameters(self::execute_parameters(), [
'source' => $source,
'context' => $context,
'component' => $component,
'area' => $area,
'itemid' => $itemid,
'parameters' => $parameters,
]);
$context = self::get_context_from_params($context);
self::validate_context($context);
// Flatten the report parameters.
$parameters = array_combine(array_column($parameters, 'name'), array_column($parameters, 'value'));
try {
$report = system_report_factory::create($source, $context, $component, $area, $itemid, $parameters);
$report->require_can_view();
} catch (report_access_exception $exception) {
return false;
}
return true;
}
/**
* External method return value
*
* @return external_value
*/
public static function execute_returns(): external_value {
return new external_value(PARAM_BOOL);
}
}
@@ -0,0 +1,138 @@
<?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\systemreports;
use core_external\external_api;
use core_external\external_multiple_structure;
use core_external\external_single_structure;
use core_external\external_function_parameters;
use core_external\external_value;
use core_external\external_warnings;
use core_reportbuilder\system_report_factory;
use core_reportbuilder\external\system_report_data_exporter;
/**
* External method for retrieving system report content
*
* @package core_reportbuilder
* @copyright 2023 Paul Holden <paulh@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class retrieve extends external_api {
/**
* External method parameters
*
* @return external_function_parameters
*/
public static function execute_parameters(): external_function_parameters {
return new external_function_parameters([
'source' => new external_value(PARAM_RAW, 'Report class path'),
'context' => self::get_context_parameters(),
'component' => new external_value(PARAM_COMPONENT, 'Report component', VALUE_DEFAULT, ''),
'area' => new external_value(PARAM_AREA, 'Report area', VALUE_DEFAULT, ''),
'itemid' => new external_value(PARAM_INT, 'Report item ID', VALUE_DEFAULT, 0),
'parameters' => new external_multiple_structure(
new external_single_structure([
'name' => new external_value(PARAM_RAW),
'value' => new external_value(PARAM_RAW),
]),
'Report parameters', VALUE_DEFAULT, []
),
'page' => new external_value(PARAM_INT, 'Page number', VALUE_DEFAULT, 0),
'perpage' => new external_value(PARAM_INT, 'Reports per page', VALUE_DEFAULT, 10),
]);
}
/**
* External method execution
*
* @param string $source
* @param array $context
* @param string $component
* @param string $area
* @param int $itemid
* @param array[] $parameters
* @param int $page
* @param int $perpage
* @return array[]
*/
public static function execute(
string $source,
array $context,
string $component = '',
string $area = '',
int $itemid = 0,
array $parameters = [],
int $page = 0,
int $perpage = 10,
): array {
global $PAGE;
[
'source' => $source,
'context' => $context,
'component' => $component,
'area' => $area,
'itemid' => $itemid,
'parameters' => $parameters,
'page' => $page,
'perpage' => $perpage,
] = self::validate_parameters(self::execute_parameters(), [
'source' => $source,
'context' => $context,
'component' => $component,
'area' => $area,
'itemid' => $itemid,
'parameters' => $parameters,
'page' => $page,
'perpage' => $perpage,
]);
$context = self::get_context_from_params($context);
self::validate_context($context);
// Flatten the report parameters.
$parameters = array_combine(array_column($parameters, 'name'), array_column($parameters, 'value'));
$report = system_report_factory::create($source, $context, $component, $area, $itemid, $parameters);
$report->require_can_view();
$output = $PAGE->get_renderer('core');
return [
'data' => (array) (new system_report_data_exporter(null, [
'report' => $report, 'page' => $page, 'perpage' => $perpage,
]))->export($output),
'warnings' => [],
];
}
/**
* External method return value
*
* @return external_single_structure
*/
public static function execute_returns(): external_single_structure {
return new external_single_structure([
'data' => system_report_data_exporter::get_read_structure(),
'warnings' => new external_warnings(),
]);
}
}