mirrored from git://git.moodle.org/moodle.git
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'MDL-29693' of https://github.com/paulholden/moodle
- Loading branch information
Showing
7 changed files
with
386 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
<?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/>. | ||
|
||
/** | ||
* Report search form class. | ||
* | ||
* @package report_configlog | ||
* @copyright 2019 Paul Holden (paulh@moodle.com) | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
|
||
namespace report_configlog\form; | ||
|
||
defined('MOODLE_INTERNAL') || die(); | ||
|
||
require_once($CFG->libdir . '/formslib.php'); | ||
|
||
/** | ||
* Report search form class. | ||
* | ||
* @package report_configlog | ||
* @copyright 2019 Paul Holden (paulh@moodle.com) | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
class search extends \moodleform { | ||
|
||
/** | ||
* Form definition | ||
* | ||
* @return void | ||
*/ | ||
public function definition() { | ||
$mform = $this->_form; | ||
|
||
// By default just show the 'setting' field. | ||
$mform->addElement('header', 'heading', get_string('search')); | ||
$mform->addElement('text', 'setting', get_string('setting', 'report_configlog')); | ||
$mform->setType('setting', PARAM_TEXT); | ||
|
||
// Rest of the search fields. | ||
$mform->addElement('text', 'value', get_string('value', 'report_configlog')); | ||
$mform->setType('value', PARAM_TEXT); | ||
$mform->addHelpButton('value', 'value', 'report_configlog'); | ||
$mform->setAdvanced('value', true); | ||
|
||
$mform->addElement('text', 'user', get_string('user', 'report_configlog')); | ||
$mform->setType('user', PARAM_TEXT); | ||
$mform->addHelpButton('user', 'user', 'report_configlog'); | ||
$mform->setAdvanced('user', true); | ||
|
||
$mform->addElement('date_selector', 'datefrom', get_string('datefrom', 'report_configlog'), ['optional' => true]); | ||
$mform->setAdvanced('datefrom', true); | ||
|
||
$mform->addElement('date_selector', 'dateto', get_string('dateto', 'report_configlog'), ['optional' => true]); | ||
$mform->setAdvanced('dateto', true); | ||
|
||
$this->add_action_buttons(false, get_string('search')); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?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/>. | ||
|
||
/** | ||
* Plugin renderer class. | ||
* | ||
* @package report_configlog | ||
* @copyright 2019 Paul Holden (pholden@greenhead.ac.uk) | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
|
||
namespace report_configlog\output; | ||
|
||
defined('MOODLE_INTERNAL') || die(); | ||
|
||
/** | ||
* Plugin renderer class. | ||
* | ||
* @package report_configlog | ||
* @copyright 2019 Paul Holden (pholden@greenhead.ac.uk) | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
class renderer extends \plugin_renderer_base { | ||
|
||
/** @var int Page size for displaying report table. */ | ||
const REPORT_TABLE_PAGESIZE = 30; | ||
|
||
/** | ||
* Return output to be rendered to page | ||
* | ||
* @param report_table $table | ||
* @return string HTML rendered table | ||
*/ | ||
protected function render_report_table(report_table $table) { | ||
ob_start(); | ||
|
||
$table->out(self::REPORT_TABLE_PAGESIZE, false); | ||
$output = ob_get_contents(); | ||
|
||
ob_end_clean(); | ||
|
||
return $output; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,175 @@ | ||
<?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/>. | ||
|
||
/** | ||
* Report table class. | ||
* | ||
* @package report_configlog | ||
* @copyright 2019 Paul Holden (pholden@greenhead.ac.uk) | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
|
||
namespace report_configlog\output; | ||
|
||
defined('MOODLE_INTERNAL') || die(); | ||
|
||
require_once($CFG->libdir . '/searchlib.php'); | ||
require_once($CFG->libdir . '/tablelib.php'); | ||
|
||
/** | ||
* Report table class. | ||
* | ||
* @package report_configlog | ||
* @copyright 2019 Paul Holden (pholden@greenhead.ac.uk) | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
class report_table extends \table_sql implements \renderable { | ||
|
||
/** @var string $search */ | ||
protected $search; | ||
|
||
/** | ||
* Constructor | ||
* | ||
* @param string $search | ||
*/ | ||
public function __construct(string $search) { | ||
parent::__construct('report-configlog-report-table'); | ||
|
||
$this->search = trim($search); | ||
|
||
// Define columns. | ||
$columns = [ | ||
'timemodified' => get_string('timemodified', 'report_configlog'), | ||
'fullname' => get_string('name'), | ||
'plugin' => get_string('plugin', 'report_configlog'), | ||
'name' => get_string('setting', 'report_configlog'), | ||
'value' => get_string('valuenew', 'report_configlog'), | ||
'oldvalue' => get_string('valueold', 'report_configlog'), | ||
]; | ||
$this->define_columns(array_keys($columns)); | ||
$this->define_headers(array_values($columns)); | ||
|
||
// Table configuration. | ||
$this->set_attribute('id', $this->uniqueid); | ||
$this->set_attribute('cellspacing', '0'); | ||
|
||
$this->sortable(true, 'timemodified', SORT_DESC); | ||
|
||
$this->initialbars(false); | ||
$this->collapsible(false); | ||
|
||
$this->useridfield = 'userid'; | ||
|
||
// Initialize table SQL properties. | ||
$this->init_sql(); | ||
} | ||
|
||
/** | ||
* Initializes table SQL properties | ||
* | ||
* @return void | ||
*/ | ||
protected function init_sql() { | ||
global $DB; | ||
|
||
$userfields = get_all_user_name_fields(true, 'u'); | ||
$fields = 'cl.id, cl.timemodified, cl.plugin, cl.name, cl.value, cl.oldvalue, cl.userid, ' . $userfields; | ||
|
||
$from = '{config_log} cl | ||
JOIN {user} u ON u.id = cl.userid'; | ||
|
||
// Report search. | ||
$where = '1=1'; | ||
$params = []; | ||
|
||
if (!empty($this->search)) { | ||
// Clean quotes, allow search by 'setting:' prefix. | ||
$searchstring = str_replace(["\\\"", 'setting:'], ["\"", 'subject:'], $this->search); | ||
|
||
$parser = new \search_parser(); | ||
$lexer = new \search_lexer($parser); | ||
|
||
if ($lexer->parse($searchstring)) { | ||
$parsearray = $parser->get_parsed_array(); | ||
|
||
// Data fields should contain both value/oldvalue. | ||
$datafields = $DB->sql_concat_join("':'", ['cl.value', 'cl.oldvalue']); | ||
|
||
list($where, $params) = search_generate_SQL($parsearray, $datafields, 'cl.name', 'cl.userid', 'u.id', | ||
'u.firstname', 'u.lastname', 'cl.timemodified', 'cl.id'); | ||
} | ||
} | ||
|
||
$this->set_sql($fields, $from, $where, $params); | ||
$this->set_count_sql('SELECT COUNT(1) FROM ' . $from . ' WHERE ' . $where, $params); | ||
} | ||
|
||
/** | ||
* Cross DB text-compatible sorting for value/oldvalue fields | ||
* | ||
* @return string | ||
*/ | ||
public function get_sql_sort() { | ||
global $DB; | ||
|
||
$sort = preg_replace_callback('/\b(value|oldvalue)\b/', function(array $matches) use ($DB) { | ||
return $DB->sql_order_by_text($matches[1], 255); | ||
}, parent::get_sql_sort()); | ||
|
||
return $sort; | ||
} | ||
|
||
/** | ||
* Format report timemodified field | ||
* | ||
* @param stdClass $row | ||
* @return string | ||
*/ | ||
public function col_timemodified(\stdClass $row) { | ||
return userdate($row->timemodified); | ||
} | ||
|
||
/** | ||
* Format report plugin field | ||
* | ||
* @param stdClass $row | ||
* @return string | ||
*/ | ||
public function col_plugin(\stdClass $row) { | ||
return $row->plugin ?? 'core'; | ||
} | ||
|
||
/** | ||
* Format report value field | ||
* | ||
* @param stdClass $row | ||
* @return string | ||
*/ | ||
public function col_value(\stdClass $row) { | ||
return $this->format_text($row->value, FORMAT_PLAIN); | ||
} | ||
|
||
/** | ||
* Format report old value field | ||
* | ||
* @param stdClass $row | ||
* @return string | ||
*/ | ||
public function col_oldvalue(\stdClass $row) { | ||
return $this->format_text($row->oldvalue, FORMAT_PLAIN);; | ||
} | ||
} |
Oops, something went wrong.