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
@@ -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\output;
use core\output\inplace_editable;
use core_external\external_api;
use core_reportbuilder\permission;
use core_reportbuilder\local\audiences\base;
use core_reportbuilder\local\models\audience;
/**
* Audience heading editable component
*
* @package core_reportbuilder
* @copyright 2021 Paul Holden <paulh@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class audience_heading_editable extends inplace_editable {
/**
* Class constructor
*
* @param int $audienceid
* @param audience|null $audience
*/
public function __construct(int $audienceid, ?audience $audience = null) {
if ($audience === null) {
$audience = new audience($audienceid);
}
$report = $audience->get_report();
$editable = permission::can_edit_report($report);
$audienceinstance = base::instance(0, $audience->to_record());
// Use audience defined title if custom heading not set.
if ('' !== $value = (string) $audience->get('heading')) {
$displayvalue = $audience->get_formatted_heading($report->get_context());
} else {
$displayvalue = $value = $audienceinstance->get_name();
}
parent::__construct('core_reportbuilder', 'audienceheading', $audience->get('id'), $editable, $displayvalue, $value,
get_string('renameaudience', 'core_reportbuilder', $audienceinstance->get_name()));
}
/**
* Update audience persistent and return self, called from inplace_editable callback
*
* @param int $audienceid
* @param string $value
* @return self
*/
public static function update(int $audienceid, string $value): self {
$audience = new audience($audienceid);
$report = $audience->get_report();
external_api::validate_context($report->get_context());
permission::require_can_edit_report($report);
$value = clean_param($value, PARAM_TEXT);
$audience
->set('heading', $value)
->update();
return new self(0, $audience);
}
}
@@ -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\output;
use core\output\inplace_editable;
use core_external\external_api;
use core_reportbuilder\manager;
use core_reportbuilder\permission;
use core_reportbuilder\local\helpers\aggregation;
use core_reportbuilder\local\models\column;
/**
* Column aggregation editable component
*
* @package core_reportbuilder
* @copyright 2021 Paul Holden <paulh@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class column_aggregation_editable extends inplace_editable {
/**
* Class constructor
*
* @param int $columnid
* @param column|null $column
*/
public function __construct(int $columnid, ?column $column = null) {
if ($column === null) {
$column = new column($columnid);
}
$report = $column->get_report();
$editable = permission::can_edit_report($report);
$columninstance = manager::get_report_from_persistent($report)
->get_column($column->get('uniqueidentifier'));
$currentvalue = (string) $column->get('aggregation');
$editlabel = get_string('aggregatecolumn', 'core_reportbuilder', $columninstance->get_title());
parent::__construct('core_reportbuilder', 'columnaggregation', $column->get('id'), $editable, null, $currentvalue,
$editlabel, $editlabel);
// List of available aggregation methods for the column type, minus any specifically disabled.
$options = aggregation::get_column_aggregations($columninstance->get_type(),
$columninstance->get_disabled_aggregation());
$this->set_type_select(['' => get_string('aggregationnone', 'core_reportbuilder')] + $options);
}
/**
* Update column persistent and return self, called from inplace_editable callback
*
* @param int $columnid
* @param string $value
* @return self
*/
public static function update(int $columnid, string $value): self {
$column = new column($columnid);
$report = $column->get_report();
external_api::validate_context($report->get_context());
permission::require_can_edit_report($report);
$value = clean_param($value, PARAM_TEXT);
$column
->set('aggregation', $value)
->update();
return new self(0, $column);
}
}
@@ -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\output;
use core\output\inplace_editable;
use core_external\external_api;
use core_reportbuilder\manager;
use core_reportbuilder\permission;
use core_reportbuilder\local\models\column;
/**
* Column heading editable component
*
* @package core_reportbuilder
* @copyright 2021 Paul Holden <paulh@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class column_heading_editable extends inplace_editable {
/**
* Class constructor
*
* @param int $columnid
* @param column|null $column
*/
public function __construct(int $columnid, ?column $column = null) {
if ($column === null) {
$column = new column($columnid);
}
$report = $column->get_report();
$editable = permission::can_edit_report($report);
$columninstance = manager::get_report_from_persistent($report)
->get_column($column->get('uniqueidentifier'));
// Use column defined title if custom heading not set.
if ('' !== $value = (string) $column->get('heading')) {
$displayvalue = $column->get_formatted_heading($report->get_context());
} else {
$displayvalue = $value = $columninstance->get_title();
}
parent::__construct('core_reportbuilder', 'columnheading', $column->get('id'), $editable, $displayvalue, $value,
get_string('renamecolumn', 'core_reportbuilder', $columninstance->get_title()));
}
/**
* Update column persistent and return self, called from inplace_editable callback
*
* @param int $columnid
* @param string $value
* @return self
*/
public static function update(int $columnid, string $value): self {
$column = new column($columnid);
$report = $column->get_report();
external_api::validate_context($report->get_context());
permission::require_can_edit_report($report);
$value = clean_param($value, PARAM_TEXT);
$column
->set('heading', trim($value))
->update();
return new self(0, $column);
}
}
@@ -0,0 +1,75 @@
<?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\output;
use core_reportbuilder\manager;
use core_reportbuilder\external\custom_report_exporter;
use core_reportbuilder\local\models\report;
use renderable;
use renderer_base;
use stdClass;
use templatable;
/**
* Custom report output 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 implements renderable, templatable {
/** @var report $reportpersistent */
protected $persistent;
/** @var bool $editmode */
protected $editmode;
/** @var string $download */
protected $download;
/**
* Class constructor
*
* @param report $reportpersistent
* @param bool $editmode
* @param string $download
*/
public function __construct(report $reportpersistent, bool $editmode = true, string $download = '') {
$this->persistent = $reportpersistent;
$this->editmode = $editmode;
$this->download = $download;
}
/**
* Export report data suitable for a template
*
* @param renderer_base $output
* @return stdClass
*/
public function export_for_template(renderer_base $output): stdClass {
$report = manager::get_report_from_persistent($this->persistent);
$exporter = new custom_report_exporter($this->persistent, [
'pagesize' => $report->get_default_per_page(),
], $this->editmode, $this->download);
return $exporter->export($output);
}
}
@@ -0,0 +1,78 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
declare(strict_types=1);
namespace core_reportbuilder\output\dynamictabs;
use context_system;
use core\output\dynamic_tabs\base;
use core_reportbuilder\local\models\report;
use core_reportbuilder\local\systemreports\report_access_list;
use core_reportbuilder\permission;
use core_reportbuilder\system_report_factory;
use renderer_base;
/**
* Access dynamic tab
*
* @package core_reportbuilder
* @copyright 2021 David Matamoros <davidmc@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class access extends base {
/**
* Export this for use in a mustache template context.
*
* @param renderer_base $output
* @return array
*/
public function export_for_template(renderer_base $output): array {
$report = system_report_factory::create(report_access_list::class, context_system::instance(), '', '', 0,
['id' => $this->data['reportid']]);
$data['report'] = $report->output();
return $data;
}
/**
* The label to be displayed on the tab
*
* @return string
*/
public function get_tab_label(): string {
return get_string('access', 'core_reportbuilder');
}
/**
* Check permission of the current user to access this tab
*
* @return bool
*/
public function is_available(): bool {
$reportpersistent = new report((int)$this->data['reportid']);
return permission::can_edit_report($reportpersistent);
}
/**
* Template to use to display tab contents
*
* @return string
*/
public function get_template(): string {
return 'core_reportbuilder/local/dynamictabs/access';
}
}
@@ -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\output\dynamictabs;
use core\output\dynamic_tabs\base;
use core_reportbuilder\external\custom_report_audience_cards_exporter;
use core_reportbuilder\local\helpers\audience as audience_helper;
use core_reportbuilder\local\models\report;
use core_reportbuilder\output\audience_heading_editable;
use core_reportbuilder\permission;
use renderer_base;
/**
* Audience dynamic tab
*
* @package core_reportbuilder
* @copyright 2021 David Matamoros <davidmc@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class audience extends base {
/**
* Export this for use in a mustache template context.
*
* @param renderer_base $output
* @return array
*/
public function export_for_template(renderer_base $output): array {
$reportid = (int) $this->data['reportid'];
// Get all the audiences types to populate the left menu.
$menucardsexporter = new custom_report_audience_cards_exporter(null);
$menucards = (array) $menucardsexporter->export($output);
// Get all current audiences instances for this report.
$audienceinstances = $this->get_all_report_audiences($reportid);
return [
'tabheading' => get_string('audience', 'core_reportbuilder'),
'reportid' => $reportid,
'contextid' => (new report($reportid))->get('contextid'),
'sidebarmenucards' => $menucards,
'instances' => $audienceinstances,
'hasinstances' => !empty($audienceinstances),
];
}
/**
* The label to be displayed on the tab
*
* @return string
*/
public function get_tab_label(): string {
return get_string('audience', 'core_reportbuilder');
}
/**
* Check permission of the current user to access this tab
*
* @return bool
*/
public function is_available(): bool {
$reportpersistent = new report((int)$this->data['reportid']);
return permission::can_edit_report($reportpersistent);
}
/**
* Template to use to display tab contents
*
* @return string
*/
public function get_template(): string {
return 'core_reportbuilder/local/dynamictabs/audience';
}
/**
* Get all current audiences instances for this report.
*
* @param int $reportid
* @return array
*/
private function get_all_report_audiences(int $reportid): array {
global $PAGE;
$renderer = $PAGE->get_renderer('core');
$audienceinstances = [];
$showormessage = false;
// Retrieve list of audiences that are used in report schedules, to warn user when editing.
$scheduleaudiences = audience_helper::get_audiences_for_report_schedules($reportid);
$reportaudiences = audience_helper::get_base_records($reportid);
foreach ($reportaudiences as $reportaudience) {
$persistent = $reportaudience->get_persistent();
$canedit = $reportaudience->user_can_edit();
$editable = new audience_heading_editable(0, $persistent);
$audienceinstances[] = [
'instanceid' => $persistent->get('id'),
'description' => $reportaudience->get_description(),
'heading' => $reportaudience->get_name(),
'headingeditable' => $editable->render($renderer),
'editwarning' => in_array($persistent->get('id'), $scheduleaudiences) ?
get_string('audienceusedbyschedule', 'core_reportbuilder') : '',
'canedit' => $canedit,
'candelete' => $canedit,
'showormessage' => $showormessage,
];
$showormessage = true;
}
return $audienceinstances;
}
}
@@ -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\output\dynamictabs;
use core\output\dynamic_tabs\base;
use core_reportbuilder\local\models\report;
use core_reportbuilder\output\custom_report;
use core_reportbuilder\permission;
use renderer_base;
use stdClass;
/**
* Editor dynamic tab
*
* @package core_reportbuilder
* @copyright 2021 David Matamoros <davidmc@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class editor extends base {
/**
* Export this for use in a mustache template context.
*
* @param renderer_base $output
* @return stdClass
*/
public function export_for_template(renderer_base $output) {
global $PAGE;
/** @var \core_reportbuilder\output\renderer $renderer */
$renderer = $PAGE->get_renderer('core_reportbuilder');
$reportpersistent = new report((int)$this->data['reportid']);
return (new custom_report($reportpersistent))->export_for_template($renderer);
}
/**
* The label to be displayed on the tab
*
* @return string
*/
public function get_tab_label(): string {
return get_string('editor', 'core_reportbuilder');
}
/**
* Check permission of the current user to access this tab
*
* @return bool
*/
public function is_available(): bool {
$reportpersistent = new report((int)$this->data['reportid']);
return permission::can_edit_report($reportpersistent);
}
/**
* Template to use to display tab contents
*
* @return string
*/
public function get_template(): string {
return 'core_reportbuilder/local/dynamictabs/editor';
}
}
@@ -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\output\dynamictabs;
use context_system;
use renderer_base;
use core\output\dynamic_tabs\base;
use core_reportbuilder\permission;
use core_reportbuilder\system_report_factory;
use core_reportbuilder\local\models\report;
use core_reportbuilder\local\systemreports\report_schedules;
/**
* Schedules dynamic tab
*
* @package core_reportbuilder
* @copyright 2021 Paul Holden <paulh@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class schedules extends base {
/**
* Export this for use in a mustache template context
*
* @param renderer_base $output
* @return array
*/
public function export_for_template(renderer_base $output): array {
$report = system_report_factory::create(report_schedules::class, context_system::instance(), '', '', 0,
['reportid' => $this->data['reportid']]);
return [
'reportid' => $this->data['reportid'],
'report' => $report->output(),
];
}
/**
* The label to be displayed on the tab
*
* @return string
*/
public function get_tab_label(): string {
return get_string('schedules', 'core_reportbuilder');
}
/**
* Check permission of the current user to access this tab
*
* @return bool
*/
public function is_available(): bool {
return permission::can_edit_report(new report($this->data['reportid']));
}
/**
* Template to use to display tab contents
*
* @return string
*/
public function get_template(): string {
return 'core_reportbuilder/local/dynamictabs/schedules';
}
}
@@ -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\output;
use core\output\inplace_editable;
use core_external\external_api;
use core_reportbuilder\manager;
use core_reportbuilder\permission;
use core_reportbuilder\local\models\filter;
/**
* Filter heading editable component
*
* @package core_reportbuilder
* @copyright 2021 David Matamoros <davidmc@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class filter_heading_editable extends inplace_editable {
/**
* Class constructor
*
* @param int $filterid
* @param filter|null $filter
*/
public function __construct(int $filterid, ?filter $filter = null) {
if ($filter === null) {
$filter = new filter($filterid);
}
$report = $filter->get_report();
$editable = permission::can_edit_report($report);
$filterinstance = manager::get_report_from_persistent($report)
->get_filter($filter->get('uniqueidentifier'));
// Use filter defined header if custom heading not set.
if ('' !== $value = (string) $filter->get('heading')) {
$displayvalue = $filter->get_formatted_heading($report->get_context());
} else {
$displayvalue = $value = $filterinstance->get_header();
}
parent::__construct('core_reportbuilder', 'filterheading', $filter->get('id'), $editable, $displayvalue, $value,
get_string('renamefilter', 'core_reportbuilder', $filterinstance->get_header()));
}
/**
* Update filter persistent and return self, called from inplace_editable callback
*
* @param int $filterid
* @param string $value
* @return self
*/
public static function update(int $filterid, string $value): self {
$filter = new filter($filterid);
$report = $filter->get_report();
external_api::validate_context($report->get_context());
permission::require_can_edit_report($report);
$value = clean_param($value, PARAM_TEXT);
$filter
->set('heading', trim($value))
->update();
return new self(0, $filter);
}
}
+144
View File
@@ -0,0 +1,144 @@
<?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\output;
use html_writer;
use moodle_url;
use plugin_renderer_base;
use core_reportbuilder\table\custom_report_table;
use core_reportbuilder\table\custom_report_table_view;
use core_reportbuilder\table\system_report_table;
use core_reportbuilder\local\models\report;
/**
* Report renderer 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 renderer extends plugin_renderer_base {
/**
* Render a system report
*
* @param system_report $report
* @return string
*/
protected function render_system_report(system_report $report): string {
$context = $report->export_for_template($this);
return $this->render_from_template('core_reportbuilder/report', $context);
}
/**
* Render a system report table
*
* @param system_report_table $table
* @return string
*/
protected function render_system_report_table(system_report_table $table): string {
ob_start();
$table->out($table->get_default_per_page(), false);
$output = ob_get_contents();
ob_end_clean();
return $output;
}
/**
* Render a custom report
*
* @param custom_report $report
* @return string
*/
protected function render_custom_report(custom_report $report): string {
$context = $report->export_for_template($this);
return $this->render_from_template('core_reportbuilder/local/dynamictabs/editor', $context);
}
/**
* Render a custom report table
*
* @param custom_report_table $table
* @return string
*/
protected function render_custom_report_table(custom_report_table $table): string {
ob_start();
$table->out($table->get_default_per_page(), false);
$output = ob_get_contents();
ob_end_clean();
return $output;
}
/**
* Render a custom report table (view only mode)
*
* @param custom_report_table_view $table
* @return string
*/
protected function render_custom_report_table_view(custom_report_table_view $table): string {
ob_start();
$table->out($table->get_default_per_page(), false);
$output = ob_get_contents();
ob_end_clean();
return $output;
}
/**
* Renders the New report button
*
* @return string
*/
public function render_new_report_button(): string {
return html_writer::tag('button', get_string('newreport', 'core_reportbuilder'), [
'class' => 'btn btn-primary my-auto',
'data-action' => 'report-create',
]);
}
/**
* Renders full page editor header
*
* @param report $report
* @return string
*/
public function render_fullpage_editor_header(report $report): string {
$reportname = $report->get_formatted_name();
$editdetailsbutton = html_writer::tag('button', get_string('editdetails', 'core_reportbuilder'), [
'class' => 'btn btn-outline-secondary mr-2',
'data-action' => 'report-edit',
'data-report-id' => $report->get('id')
]);
$closebutton = html_writer::link(new moodle_url('/reportbuilder/index.php'), get_string('close', 'core_reportbuilder'), [
'class' => 'btn btn-secondary',
'title' => get_string('closeeditor', 'core_reportbuilder', $reportname),
'role' => 'button'
]);
$context = [
'title' => $reportname,
'buttons' => $editdetailsbutton . $closebutton,
];
return $this->render_from_template('core_reportbuilder/editor_navbar', $context);
}
}
@@ -0,0 +1,83 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
declare(strict_types=1);
namespace core_reportbuilder\output;
use html_writer;
use moodle_url;
use core\output\inplace_editable;
use core_external\external_api;
use core_reportbuilder\permission;
use core_reportbuilder\local\models\report;
/**
* Report name editable component
*
* @package core_reportbuilder
* @copyright 2021 Paul Holden <paulh@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class report_name_editable extends inplace_editable {
/**
* Class constructor
*
* @param int $reportid
* @param report|null $report The report persistent, note that in addition to id/name properties being present we also
* require the following to be correctly set in order to perform permission checks: contextid/type/usercreated
*/
public function __construct(int $reportid, ?report $report = null) {
if ($report === null) {
$report = new report($reportid);
}
$editable = permission::can_edit_report($report);
$url = $editable
? new moodle_url('/reportbuilder/edit.php', ['id' => $report->get('id')])
: new moodle_url('/reportbuilder/view.php', ['id' => $report->get('id')]);
$displayvalue = html_writer::link($url, $report->get_formatted_name());
parent::__construct('core_reportbuilder', 'reportname', $report->get('id'), $editable, $displayvalue, $report->get('name'),
get_string('editreportname', 'core_reportbuilder'));
}
/**
* Update report persistent and return self, called from inplace_editable callback
*
* @param int $reportid
* @param string $value
* @return self
*/
public static function update(int $reportid, string $value): self {
$report = new report($reportid);
external_api::validate_context($report->get_context());
permission::require_can_edit_report($report);
$value = trim(clean_param($value, PARAM_TEXT));
if ($value !== '') {
$report
->set('name', $value)
->update();
}
return new self(0, $report);
}
}
@@ -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\output;
use core\output\inplace_editable;
use core_external\external_api;
use core_reportbuilder\permission;
use core_reportbuilder\local\models\schedule;
/**
* Schedule name editable component
*
* @package core_reportbuilder
* @copyright 2021 Paul Holden <paulh@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class schedule_name_editable extends inplace_editable {
/**
* Class constructor
*
* @param int $scheduleid
* @param schedule|null $schedule
*/
public function __construct(int $scheduleid, ?schedule $schedule = null) {
if ($schedule === null) {
$schedule = new schedule($scheduleid);
}
$report = $schedule->get_report();
$editable = permission::can_edit_report($report);
$displayvalue = $schedule->get_formatted_name($report->get_context());
parent::__construct('core_reportbuilder', 'schedulename', $schedule->get('id'), $editable, $displayvalue,
$schedule->get('name'), get_string('editschedulename', 'core_reportbuilder'));
}
/**
* Update schedule persistent and return self, called from inplace_editable callback
*
* @param int $scheduleid
* @param string $value
* @return self
*/
public static function update(int $scheduleid, string $value): self {
$schedule = new schedule($scheduleid);
$report = $schedule->get_report();
external_api::validate_context($report->get_context());
permission::require_can_edit_report($report);
$value = trim(clean_param($value, PARAM_TEXT));
if ($value !== '') {
$schedule
->set('name', $value)
->update();
}
return new self(0, $schedule);
}
}
@@ -0,0 +1,74 @@
<?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\output;
use renderable;
use renderer_base;
use stdClass;
use templatable;
use core_reportbuilder\system_report as system_report_base;
use core_reportbuilder\external\system_report_exporter;
use core_reportbuilder\local\models\report;
/**
* System report output 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 implements renderable, templatable {
/** @var report $report */
protected $report;
/** @var system_report_base $source */
protected $source;
/** @var array $parameters */
protected $parameters;
/**
* Class constructor
*
* @param report $report
* @param system_report_base $source
* @param array $parameters
*/
public function __construct(report $report, system_report_base $source, array $parameters) {
$this->report = $report;
$this->source = $source;
$this->parameters = $parameters;
}
/**
* Export report data suitable for a template
*
* @param renderer_base $output
* @return stdClass
*/
public function export_for_template(renderer_base $output): stdClass {
$exporter = new system_report_exporter($this->report, [
'source' => $this->source,
'parameters' => json_encode($this->parameters),
]);
return $exporter->export($output);
}
}