mirror of
https://github.com/moodle/moodle.git
synced 2025-01-19 06:18:28 +01:00
MDL-66332 too_capability: add show differences option
This commit is contained in:
parent
6aacd8d6d1
commit
e96bbb53af
@ -60,6 +60,11 @@ class tool_capability_settings_form extends moodleform {
|
||||
$form->addElement('select', 'roles', get_string('roleslabel', 'tool_capability'), $roles, $attributes);
|
||||
$form->setType('roles', PARAM_TEXT);
|
||||
|
||||
$form->addElement('checkbox', 'onlydiff',
|
||||
get_string('filters', 'tool_capability'),
|
||||
get_string('onlydiff', 'tool_capability'));
|
||||
$form->setType('onlydiff', PARAM_BOOL);
|
||||
|
||||
$form->addElement('submit', 'submitbutton', get_string('getreport', 'tool_capability'));
|
||||
}
|
||||
|
||||
|
@ -66,6 +66,7 @@ $capabilities = array();
|
||||
$rolestoshow = array();
|
||||
$roleids = array('0');
|
||||
$cleanedroleids = array();
|
||||
$onlydiff = false;
|
||||
if ($data = $form->get_data()) {
|
||||
|
||||
$roleids = array();
|
||||
@ -90,6 +91,10 @@ if ($data = $form->get_data()) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($data->onlydiff)) {
|
||||
$onlydiff = $data->onlydiff;
|
||||
}
|
||||
}
|
||||
|
||||
\tool_capability\event\report_viewed::create()->trigger();
|
||||
@ -103,7 +108,7 @@ $form->display();
|
||||
// If we have a capability, generate the report.
|
||||
if (count($capabilities) && count($rolestoshow)) {
|
||||
/* @var tool_capability_renderer $renderer */
|
||||
echo $renderer->capability_comparison_table($capabilities, $context->id, $rolestoshow);
|
||||
echo $renderer->capability_comparison_table($capabilities, $context->id, $rolestoshow, $onlydiff);
|
||||
}
|
||||
|
||||
// Footer.
|
||||
|
@ -22,15 +22,18 @@
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
$string['onlydiff'] = 'Show differences only';
|
||||
$string['capabilitylabel'] = 'Capability:';
|
||||
$string['capabilityreport'] = 'Capability overview';
|
||||
$string['eventreportviewed'] = 'Report viewed';
|
||||
$string['filters'] = 'Filter results';
|
||||
$string['forroles'] = 'For roles {$a}';
|
||||
$string['getreport'] = 'Get the overview';
|
||||
$string['changeoverrides'] = 'Change overrides in this context';
|
||||
$string['changeroles'] = 'Change role definitions';
|
||||
$string['intro'] = 'This report shows, for a particular capability, what permission that capability has in the definition of every role (or a selection of roles), and everywhere in the site where that capability is overridden.';
|
||||
$string['pluginname'] = 'Capability overview';
|
||||
$string['nodifferences'] = 'There are no differences to show between selected roles in this context';
|
||||
$string['reportforcapability'] = 'Report for capability \'{$a}\'';
|
||||
$string['reportsettings'] = 'Report settings';
|
||||
$string['roleslabel'] = 'Roles:';
|
||||
|
@ -72,9 +72,10 @@ class tool_capability_renderer extends plugin_renderer_base {
|
||||
* @param array $capabilities An array of capabilities to show comparison for.
|
||||
* @param int $contextid The context we are displaying for.
|
||||
* @param array $roles An array of roles to show comparison for.
|
||||
* @param bool $onlydiff show only different permissions
|
||||
* @return string
|
||||
*/
|
||||
public function capability_comparison_table(array $capabilities, $contextid, array $roles) {
|
||||
public function capability_comparison_table(array $capabilities, $contextid, array $roles, $onlydiff=false) {
|
||||
|
||||
$strpermissions = $this->get_permission_strings();
|
||||
$permissionclasses = $this->get_permission_classes();
|
||||
@ -99,18 +100,23 @@ class tool_capability_renderer extends plugin_renderer_base {
|
||||
|
||||
$row = new html_table_row(array($captitle));
|
||||
|
||||
$permissiontypes = array();
|
||||
foreach ($roles as $role) {
|
||||
if (isset($contexts[$contextid]->rolecapabilities[$role->id])) {
|
||||
$permission = $contexts[$contextid]->rolecapabilities[$role->id];
|
||||
} else {
|
||||
$permission = CAP_INHERIT;
|
||||
}
|
||||
if (!in_array($permission, $permissiontypes)) {
|
||||
$permissiontypes[] = $permission;
|
||||
}
|
||||
$cell = new html_table_cell($strpermissions[$permission]);
|
||||
$cell->attributes['class'] = $permissionclasses[$permission];
|
||||
$row->cells[] = $cell;
|
||||
}
|
||||
|
||||
$table->data[] = $row;
|
||||
if (!$onlydiff || count($permissiontypes) > 1) {
|
||||
$table->data[] = $row;
|
||||
}
|
||||
}
|
||||
|
||||
// Start the list item, and print the context name as a link to the place to make changes.
|
||||
@ -125,11 +131,15 @@ class tool_capability_renderer extends plugin_renderer_base {
|
||||
$title = get_string('permissionsincontext', 'core_role', $context->get_context_name());
|
||||
|
||||
$html = $this->output->heading(html_writer::link($url, $title), 3);
|
||||
$html .= html_writer::table($table);
|
||||
if (!empty($table->data)) {
|
||||
$html .= html_writer::table($table);
|
||||
} else {
|
||||
$html .= html_writer::tag('p', get_string('nodifferences', 'tool_capability'));
|
||||
}
|
||||
// If there are any child contexts, print them recursively.
|
||||
if (!empty($contexts[$contextid]->children)) {
|
||||
foreach ($contexts[$contextid]->children as $childcontextid) {
|
||||
$html .= $this->capability_comparison_table($capabilities, $childcontextid, $roles, true);
|
||||
$html .= $this->capability_comparison_table($capabilities, $childcontextid, $roles, $onlydiff);
|
||||
}
|
||||
}
|
||||
return $html;
|
||||
|
Loading…
x
Reference in New Issue
Block a user