Skip to content

Commit

Permalink
Ad-hoc DB report: Improve sub-category navigation options #396428
Browse files Browse the repository at this point in the history
  • Loading branch information
Tien Nguyen authored and timhunt committed Nov 26, 2021
1 parent 8be504c commit 1b9b823
Show file tree
Hide file tree
Showing 29 changed files with 1,320 additions and 130 deletions.
2 changes: 1 addition & 1 deletion amd/build/reportcategories.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion amd/build/reportcategories.min.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion amd/src/reportcategories.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ define(['jquery'], function($) {
* Initialise the tabs.
*/
init: function() {
$('body').on('click', '.csql_category h2', t.expandCollapse);
$('body').on('click', '.csql_category h2 .categoryname, .csql_category h2 .reportcounts', t.expandCollapse);
$('.csql_expandcollapseall').on('click', t.expandCollapseAll);
t.updateExpandCollapseAll();
},
Expand Down
51 changes: 51 additions & 0 deletions category.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?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/>.

/**
* This page shows the list of queries in a category, with edit icons, an add new button
* if you have the report/customsql:definequeries capability
*
* @package report_customsql
* @copyright 2021 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

require_once(dirname(__FILE__) . '/../../config.php');
require_once(dirname(__FILE__) . '/locallib.php');
require_once($CFG->libdir . '/adminlib.php');

// Start the page.
admin_externalpage_setup('report_customsql');
$context = context_system::instance();
require_capability('report/customsql:view', $context);

$categoryid = required_param('id', PARAM_INT);
$record = $DB->get_record('report_customsql_categories', ['id' => $categoryid], '*', MUST_EXIST);
$queries = $DB->get_records('report_customsql_queries', ['categoryid' => $categoryid]);

$category = new \report_customsql\local\category($record);
$category->load_queries_data($queries);
$widget = new \report_customsql\output\category($category, $context);

$PAGE->set_title(format_string($category->get_name()));
$PAGE->navbar->add(format_string($category->get_name()));
$output = $PAGE->get_renderer('report_customsql');

echo $OUTPUT->header();

echo $output->render($widget);

echo $OUTPUT->footer();
7 changes: 3 additions & 4 deletions categorydelete.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,7 @@
echo $OUTPUT->heading(get_string('deletecategoryareyousure', 'report_customsql'));
echo html_writer::tag('p', get_string('categorynamex', 'report_customsql', $category->name ));
echo $OUTPUT->confirm(get_string('deletecategoryyesno', 'report_customsql'),
new single_button(new moodle_url(report_customsql_url('categorydelete.php'),
array('id' => $id, 'confirm' => 1, 'sesskey' => sesskey())), get_string('yes')),
new single_button(new moodle_url(report_customsql_url('index.php')),
get_string('no')));
new single_button(report_customsql_url('categorydelete.php',
['id' => $id, 'confirm' => 1, 'sesskey' => sesskey()]), get_string('yes')),
new single_button(report_customsql_url('index.php'), get_string('no')));
echo $OUTPUT->footer();
117 changes: 117 additions & 0 deletions classes/local/category.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
<?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/>.

namespace report_customsql\local;

use report_customsql\utils;

/**
* Category class.
*
* @package report_customsql
* @copyright 2021 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class category {
/** @var int Category ID. */
private $id;

/** @var string Category name. */
private $name;

/** @var array Pre-loaded queries data. */
private $queriesdata;

/** @var array Pre-loaded statistic data. */
private $statistic;

/**
* Create a new category object.
*
* @param \stdClass $record The record from database.
*/
public function __construct(\stdClass $record) {
$this->id = $record->id;
$this->name = $record->name;
}

/**
* Load queries of category from records.
*
* @param array $queries Records to load.
*/
public function load_queries_data(array $queries): void {
$statistic = [];
$queriesdata = [];
foreach (report_customsql_runable_options() as $type => $description) {
$fitleredqueries = utils::get_number_of_report_by_type($queries, $type);
$statistic[$type] = count($fitleredqueries);
if ($fitleredqueries) {
$queriesdata[] = [
'type' => $type,
'queries' => $fitleredqueries
];
}
}
$this->queriesdata = $queriesdata;
$this->statistic = $statistic;
}

/**
* Get category ID.
*
* @return int Category ID.
*/
public function get_id(): int {
return $this->id;
}

/**
* Get category name.
*
* @return string Category name.
*/
public function get_name(): string {
return $this->name;
}

/**
* Get pre-loaded queries' data of this category.
*
* @return array Queries' data.
*/
public function get_queries_data(): array {
return $this->queriesdata;
}

/**
* Get pre-loaded statistic of this category.
*
* @return array Statistic data.
*/
public function get_statistic(): array {
return $this->statistic;
}

/**
* Get url to view the category.
*
* @return \moodle_url Category's url.
*/
public function get_url(): \moodle_url {
return report_customsql_url('category.php', ['id' => $this->id]);
}
}
Loading

0 comments on commit 1b9b823

Please sign in to comment.