File manager - Edit - /home/u466501803/domains/qurdis.my.id/public_html/reportbuilder.zip
Back
PK a<�\���w� � lib.phpnu �[��� <?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/>. /** * Callback methods for reportbuilder component * * @package core_reportbuilder * @copyright 2021 Paul Holden <paulh@moodle.com> * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ declare(strict_types=1); use core\output\inplace_editable; use core_reportbuilder\form\audience; use core_reportbuilder\form\filter; use core_reportbuilder\local\helpers\audience as audience_helper; use core_reportbuilder\local\models\report; use core_tag\output\{tagfeed, tagindex}; /** * Return the filters form fragment * * @param array $params * @return string */ function core_reportbuilder_output_fragment_filters_form(array $params): string { $filtersform = new filter(null, null, 'post', '', [], true, [ 'reportid' => $params['reportid'], 'parameters' => $params['parameters'], ]); $filtersform->set_data_for_dynamic_submission(); return $filtersform->render(); } /** * Return the audience form fragment * * @param array $params * @return string */ function core_reportbuilder_output_fragment_audience_form(array $params): string { global $PAGE; $audienceform = new audience(null, null, 'post', '', [], true, [ 'reportid' => $params['reportid'], 'classname' => $params['classname'], ]); $audienceform->set_data_for_dynamic_submission(); $context = [ 'instanceid' => 0, 'heading' => $params['title'], 'headingeditable' => $params['title'], 'form' => $audienceform->render(), 'canedit' => true, 'candelete' => true, 'showormessage' => $params['showormessage'], ]; $renderer = $PAGE->get_renderer('core_reportbuilder'); return $renderer->render_from_template('core_reportbuilder/local/audience/form', $context); } /** * Callback to return tagged reports * * @param core_tag_tag $tag * @param bool $exclusivemode * @param int|null $fromcontextid * @param int|null $contextid * @param bool $recurse * @param int $page * @return tagindex */ function core_reportbuilder_get_tagged_reports( core_tag_tag $tag, bool $exclusivemode = false, ?int $fromcontextid = 0, ?int $contextid = 0, bool $recurse = true, int $page = 0, ): tagindex { global $OUTPUT; // Limit the returned list to those reports the current user can access. [$where, $params] = audience_helper::user_reports_list_access_sql('it'); $tagcount = $tag->count_tagged_items('core_reportbuilder', 'reportbuilder_report', $where, $params); $perpage = $exclusivemode ? 20 : 5; $pagecount = ceil($tagcount / $perpage); $content = ''; if ($tagcount > 0) { $tagfeed = new tagfeed(); $pixicon = new pix_icon('i/report', new lang_string('customreport', 'core_reportbuilder')); $reports = $tag->get_tagged_items('core_reportbuilder', 'reportbuilder_report', $page * $perpage, $perpage, $where, $params); foreach ($reports as $report) { $tagfeed->add( $OUTPUT->render($pixicon), html_writer::link( new moodle_url('/reportbuilder/view.php', ['id' => $report->id]), (new report(0, $report))->get_formatted_name(), ), ); } $content = $OUTPUT->render_from_template('core_tag/tagfeed', $tagfeed->export_for_template($OUTPUT)); } return new tagindex($tag, 'core_reportbuilder', 'reportbuilder_report', $content, $exclusivemode, $fromcontextid, $contextid, $recurse, $page, $pagecount); } /** * Plugin inplace editable implementation * * @param string $itemtype * @param int $itemid * @param string $newvalue * @return inplace_editable|null */ function core_reportbuilder_inplace_editable(string $itemtype, int $itemid, string $newvalue): ?inplace_editable { switch ($itemtype) { case 'reportname': return \core_reportbuilder\output\report_name_editable::update($itemid, $newvalue); case 'columnheading': return \core_reportbuilder\output\column_heading_editable::update($itemid, $newvalue); case 'columnaggregation': return \core_reportbuilder\output\column_aggregation_editable::update($itemid, $newvalue); case 'filterheading': return \core_reportbuilder\output\filter_heading_editable::update($itemid, $newvalue); case 'audienceheading': return \core_reportbuilder\output\audience_heading_editable::update($itemid, $newvalue); case 'schedulename': return \core_reportbuilder\output\schedule_name_editable::update($itemid, $newvalue); } return null; } PK a<�\���Ť � classes/permission.phpnu �[��� <?php // This file is part of Moodle - http://moodle.org/ // // Moodle is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // // Moodle is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with Moodle. If not, see <http://www.gnu.org/licenses/>. declare(strict_types=1); namespace core_reportbuilder; use context; use context_system; use core_reportbuilder\exception\report_access_exception; use core_reportbuilder\local\helpers\audience; use core_reportbuilder\local\models\report; use core_reportbuilder\local\report\base; /** * Report permission 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 permission { /** * Require given user can view reports list * * @param int|null $userid User ID to check, or the current user if omitted * @param context|null $context * @throws report_access_exception */ public static function require_can_view_reports_list(?int $userid = null, ?context $context = null): void { if (!static::can_view_reports_list($userid, $context)) { throw new report_access_exception(); } } /** * Whether given user can view reports list * * @param int|null $userid User ID to check, or the current user if omitted * @param context|null $context * @return bool */ public static function can_view_reports_list(?int $userid = null, ?context $context = null): bool { global $CFG; if ($context === null) { $context = context_system::instance(); } return !empty($CFG->enablecustomreports) && has_any_capability([ 'moodle/reportbuilder:edit', 'moodle/reportbuilder:editall', 'moodle/reportbuilder:view', 'moodle/reportbuilder:viewall', ], $context, $userid); } /** * Require given user can view report * * @param report $report * @param int|null $userid User ID to check, or the current user if omitted * @throws report_access_exception */ public static function require_can_view_report(report $report, ?int $userid = null): void { if (!static::can_view_report($report, $userid)) { throw new report_access_exception('errorreportview'); } } /** * Whether given user can view report * * @param report $report * @param int|null $userid User ID to check, or the current user if omitted * @return bool */ public static function can_view_report(report $report, ?int $userid = null): bool { if (!static::can_view_reports_list($userid, $report->get_context())) { return false; } if (has_capability('moodle/reportbuilder:viewall', $report->get_context(), $userid)) { return true; } if (self::can_edit_report($report, $userid)) { return true; } $reports = audience::user_reports_list($userid); return in_array($report->get('id'), $reports); } /** * Require given user can edit report * * @param report $report * @param int|null $userid User ID to check, or the current user if omitted * @throws report_access_exception */ public static function require_can_edit_report(report $report, ?int $userid = null): void { if (!static::can_edit_report($report, $userid)) { throw new report_access_exception('errorreportedit'); } } /** * Whether given user can edit report * * @param report $report * @param int|null $userid User ID to check, or the current user if omitted * @return bool */ public static function can_edit_report(report $report, ?int $userid = null): bool { global $CFG, $USER; if (empty($CFG->enablecustomreports)) { return false; } // We can only edit custom reports. if ($report->get('type') !== base::TYPE_CUSTOM_REPORT) { return false; } // To edit their own reports, users must have either of the 'edit' or 'editall' capabilities. For reports belonging // to other users, they must have the specific 'editall' capability. $userid = $userid ?: (int) $USER->id; if ($report->get('usercreated') === $userid) { return has_any_capability([ 'moodle/reportbuilder:edit', 'moodle/reportbuilder:editall', ], $report->get_context(), $userid); } else { return has_capability('moodle/reportbuilder:editall', $report->get_context(), $userid); } } /** * Whether given user can create a new report * * @param int|null $userid User ID to check, or the current user if omitted * @param context|null $context * @return bool */ public static function can_create_report(?int $userid = null, ?context $context = null): bool { global $CFG; if ($context === null) { $context = context_system::instance(); } return !empty($CFG->enablecustomreports) && has_any_capability([ 'moodle/reportbuilder:edit', 'moodle/reportbuilder:editall', ], $context, $userid) && !manager::report_limit_reached(); } /** * Require given user can create a new report * * @param int|null $userid User ID to check, or the current user if omitted * @param context|null $context * @throws report_access_exception */ public static function require_can_create_report(?int $userid = null, ?context $context = null): void { if (!static::can_create_report($userid, $context)) { throw new report_access_exception('errorreportcreate'); } } } PK a<�\�!�LB B : classes/external/custom_report_audience_cards_exporter.phpnu �[��� <?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), ]; } } PK a<�\8�4�� � + classes/external/systemreports/retrieve.phpnu �[��� <?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(), ]); } } PK a<�\��~�� � + classes/external/systemreports/can_view.phpnu �[��� <?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\exception\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); } } PK a<�\�q� � % classes/external/audiences/delete.phpnu �[��� <?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_external\external_api; use core_external\external_value; use core_external\external_function_parameters; use core_reportbuilder\local\helpers\audience; 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()); return audience::delete_report_audience($reportid, $instanceid); } /** * 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); } } PK a<�\e8�x� � 0 classes/external/system_report_data_exporter.phpnu �[��� <?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), ]; } } PK a<�\V�t~ ~ 8 classes/external/custom_report_column_cards_exporter.phpnu �[��� <?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), ]; } } PK a<�\�M��� � % classes/external/reports/retrieve.phpnu �[��� <?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(), ]); } } PK a<�\qO(�� � ! classes/external/reports/view.phpnu �[��� <?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(), ]); } } PK a<�\���E E classes/external/reports/get.phpnu �[��� <?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(); } } PK a<�\S���a a $ classes/external/reports/listing.phpnu �[��� <?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(), ]); } } PK a<�\F�o # classes/external/reports/delete.phpnu �[��� <?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'); } } PK a<�\ �� � % classes/external/schedules/toggle.phpnu �[��� <?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); } } PK a<�\TR� % classes/external/schedules/delete.phpnu �[��� <?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); } } PK a<�\MU��� � # classes/external/schedules/send.phpnu �[��� <?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); } } PK a<�\�'�� � classes/external/columns/add.phpnu �[��� <?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(); } } PK a<�\_g�IZ Z % classes/external/columns/sort/get.phpnu �[��� <?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(); } } PK a<�\kx-C C ( classes/external/columns/sort/toggle.phpnu �[��� <?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(); } } PK a<�\^y�b b ) classes/external/columns/sort/reorder.phpnu �[��� <?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(); } } PK a<�\�T�t t # classes/external/columns/delete.phpnu �[��� <?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(); } } PK a<�\v`G� � $ classes/external/columns/reorder.phpnu �[��� <?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'); } } PK a<�\3;[� � # classes/external/conditions/add.phpnu �[��� <?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(); } } PK a<�\ ɮy y % classes/external/conditions/reset.phpnu �[��� <?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(); } } PK a<�\�FTu� � &