Skip to content
Snippets Groups Projects
Commit abb9f17e authored by Justus Dieckmann's avatar Justus Dieckmann
Browse files

Make course backups table searchable

parent 8eee4e1d
No related branches found
No related tags found
No related merge requests found
<?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/>.
/**
* A moodle form for filtering the course backups table
*
* @package tool_lifecycle
* @copyright 2021 Justus Dieckmann WWU
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace tool_lifecycle\local\form;
defined('MOODLE_INTERNAL') || die();
require_once($CFG->libdir . '/formslib.php');
/**
* A moodle form for filtering the course backups table
*
* @package tool_lifecycle
* @copyright 2021 Justus Dieckmann WWU
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class form_backups_filter extends \moodleform {
/**
* Defines forms elements
*/
public function definition() {
$mform = $this->_form;
$mform->addElement('text', 'shortname', get_string('shortname'));
$mform->setType('shortname', PARAM_TEXT);
$mform->addElement('text', 'fullname', get_string('fullname'));
$mform->setType('fullname', PARAM_TEXT);
$this->add_action_buttons(true, get_string('apply', 'tool_lifecycle'));
}
}
...@@ -39,14 +39,31 @@ class course_backups_table extends \table_sql { ...@@ -39,14 +39,31 @@ class course_backups_table extends \table_sql {
/** /**
* Constructor for course_backups_table. * Constructor for course_backups_table.
* @param int $uniqueid Unique id of this table. * @param int $uniqueid Unique id of this table.
* @param \stdClass|null $filterdata
*/ */
public function __construct($uniqueid) { public function __construct($uniqueid, $filterdata) {
parent::__construct($uniqueid); parent::__construct($uniqueid);
global $PAGE; global $PAGE, $DB;
$this->set_attribute('class', $this->attributes['class'] . ' ' . $uniqueid); $this->set_attribute('class', $this->attributes['class'] . ' ' . $uniqueid);
$where = ['TRUE'];
$params = [];
if ($filterdata) {
if ($filterdata && $filterdata->shortname) {
$where[] = $DB->sql_like('b.shortname', ':shortname', false, false);
$params['shortname'] = '%' . $DB->sql_like_escape($filterdata->shortname) . '%';
}
if ($filterdata && $filterdata->fullname) {
$where[] = $DB->sql_like('b.fullname', ':fullname', false, false);
$params['fullname'] = '%' . $DB->sql_like_escape($filterdata->fullname) . '%';
}
}
$this->set_sql('b.id, b.courseid, b.shortname as courseshortname, b.fullname as coursefullname, b.backupcreated', $this->set_sql('b.id, b.courseid, b.shortname as courseshortname, b.fullname as coursefullname, b.backupcreated',
'{tool_lifecycle_backups} b', '{tool_lifecycle_backups} b',
"TRUE"); join(" AND ", $where), $params);
$this->no_sorting('download'); $this->no_sorting('download');
$this->no_sorting('restore'); $this->no_sorting('restore');
$this->define_baseurl($PAGE->url); $this->define_baseurl($PAGE->url);
... ...
......
...@@ -32,7 +32,23 @@ admin_externalpage_setup('tool_lifecycle_coursebackups'); ...@@ -32,7 +32,23 @@ admin_externalpage_setup('tool_lifecycle_coursebackups');
$PAGE->set_url(new \moodle_url('/admin/tool/lifecycle/coursebackups.php')); $PAGE->set_url(new \moodle_url('/admin/tool/lifecycle/coursebackups.php'));
$table = new tool_lifecycle\local\table\course_backups_table('tool_lifecycle_course_backups'); $mform = new \tool_lifecycle\local\form\form_backups_filter();
// Cache handling.
$cache = cache::make('tool_lifecycle', 'mformdata');
if ($mform->is_cancelled()) {
$cache->delete('coursebackups_filter');
redirect($PAGE->url);
} else if ($data = $mform->get_data()) {
$cache->set('coursebackups_filter', $data);
} else {
$data = $cache->get('coursebackups_filter');
if ($data) {
$mform->set_data($data);
}
}
$table = new tool_lifecycle\local\table\course_backups_table('tool_lifecycle_course_backups', $data);
$PAGE->set_title(get_string('course_backups_list_header', 'tool_lifecycle')); $PAGE->set_title(get_string('course_backups_list_header', 'tool_lifecycle'));
$PAGE->set_heading(get_string('course_backups_list_header', 'tool_lifecycle')); $PAGE->set_heading(get_string('course_backups_list_header', 'tool_lifecycle'));
...@@ -40,6 +56,13 @@ $PAGE->set_heading(get_string('course_backups_list_header', 'tool_lifecycle')); ...@@ -40,6 +56,13 @@ $PAGE->set_heading(get_string('course_backups_list_header', 'tool_lifecycle'));
$renderer = $PAGE->get_renderer('tool_lifecycle'); $renderer = $PAGE->get_renderer('tool_lifecycle');
echo $renderer->header(); echo $renderer->header();
echo '<br>';
$mform->display();
echo '<br>';
$table->out(50, false); $table->out(50, false);
echo $renderer->footer(); echo $renderer->footer();
... ...
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment