MDL-72873 core_grades: Add tertiary navigation in grade scales

This commit is contained in:
Mihail Geshoski
2021-12-16 00:10:13 +08:00
parent 4f403bfdca
commit eb0b022bb7
5 changed files with 165 additions and 13 deletions
@@ -0,0 +1,64 @@
<?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 core_grades\output;
use moodle_url;
/**
* Renderable class for the action bar elements in the gradebook scales page.
*
* @package core_grades
* @copyright 2021 Mihail Geshoski <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class scales_action_bar extends action_bar {
/**
* Returns the template for the action bar.
*
* @return string
*/
public function get_template(): string {
return 'core_grades/scales_action_bar';
}
/**
* Export the data for the mustache template.
*
* @param \renderer_base $output renderer to be used to render the action bar elements.
* @return array
*/
public function export_for_template(\renderer_base $output): array {
$data = [];
$courseid = 0;
// If in the course context, we should display the general navigation selector in gradebook.
if ($this->context->contextlevel === CONTEXT_COURSE) {
$courseid = $this->context->instanceid;
// Get the data used to output the general navigation selector.
$generalnavselector = new general_action_bar($this->context,
new moodle_url('/grade/edit/scale/index.php', ['id' => $courseid]), 'scale', 'scale');
$data = $generalnavselector->export_for_template($output);
}
// Add a button to the action bar with a link to the 'add new scale' page.
$addnewscalelink = new moodle_url('/grade/edit/scale/edit.php', ['courseid' => $courseid]);
$addnewscalebutton = new \single_button($addnewscalelink, get_string('scalescustomcreate'),
'get', true);
$data['addnewscalebutton'] = $addnewscalebutton->export_for_template($output);
return $data;
}
}
+1 -4
View File
@@ -36,12 +36,9 @@ navigation_node::override_active_url(new moodle_url('/grade/edit/scale/index.php
array('id' => $courseid)));
$systemcontext = context_system::instance();
$heading = '';
// a bit complex access control :-O
if ($id) {
$heading = get_string('editscale', 'grades');
/// editing existing scale
if (!$scale_rec = $DB->get_record('scale', array('id' => $id))) {
print_error('invalidscaleid');
@@ -68,7 +65,6 @@ if ($id) {
}
} else if ($courseid){
$heading = get_string('addscale', 'grades');
/// adding new scale from course
if (!$course = $DB->get_record('course', array('id' => $courseid))) {
print_error('invalidcourseid');
@@ -147,6 +143,7 @@ if ($mform->is_cancelled()) {
redirect($returnurl);
}
$heading = $id ? get_string('editscale', 'grades') : get_string('addscale', 'grades');
print_grade_page_head($COURSE->id, 'scale', null, $heading, false, false, false);
$mform->display();
+25 -9
View File
@@ -43,6 +43,7 @@ if ($courseid) {
} else {
require_once $CFG->libdir.'/adminlib.php';
admin_externalpage_setup('scales');
$context = context_system::instance();
}
/// return tracking object
@@ -54,7 +55,6 @@ $strcustomscales = get_string('scalescustom');
$strname = get_string('name');
$strdelete = get_string('delete');
$stredit = get_string('edit');
$srtcreatenewscale = get_string('scalescustomcreate');
$strused = get_string('used');
$stredit = get_string('edit');
@@ -164,16 +164,32 @@ if ($scales = grade_scale::fetch_all_global()) {
$table2->data = $data;
}
$actionbar = new \core_grades\output\scales_action_bar($context);
if ($courseid) {
print_grade_page_head($courseid, 'scale', 'scale', get_string('coursescales', 'grades'));
print_grade_page_head($courseid, 'scale', 'scale', get_string('coursescales', 'grades'),
false, false, true, null, null, null, $actionbar);
} else {
$renderer = $PAGE->get_renderer('core_grades');
echo $renderer->render_action_bar($actionbar);
echo $OUTPUT->heading(get_string('scales', 'core'));
}
echo $OUTPUT->heading($strcustomscales, 3, 'main');
echo html_writer::table($table);
echo $OUTPUT->heading($strstandardscale, 3, 'main');
echo html_writer::table($table2);
echo $OUTPUT->container_start('buttons');
echo $OUTPUT->single_button(new moodle_url('edit.php', array('courseid'=>$courseid)), $srtcreatenewscale);
echo $OUTPUT->container_end();
$hascustomscales = !empty($table->data);
$hasstandardscales = !empty($table2->data);
// If there are custom scales available in this context, output the custom scales table and a heading.
if ($hascustomscales) {
echo $OUTPUT->heading($strcustomscales, 3, 'main mt-3');
echo html_writer::table($table);
}
// If there are standard scales available in this context, output the standard scales table and a heading.
if ($hasstandardscales) {
echo $OUTPUT->heading($strstandardscale, 3, 'main mt-3');
echo html_writer::table($table2);
}
// If the are no available scales, display a notification.
if (!$hascustomscales && !$hasstandardscales) {
echo $OUTPUT->notification(get_string('noexistingscales', 'grades'), 'info', false);
}
echo $OUTPUT->footer();
@@ -0,0 +1,74 @@
{{!
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/>.
}}
{{!
@template core_grades/scales_action_bar
Actions bar for the gradebook scales page.
Context variables required for this template:
* generalnavselector - The data object containing the required properties to render the general navigation selector.
* addnewscalebutton - The data object containing the required properties to render the 'add new scale' button.
Example context (json):
{
"generalnavselector": {
"id": "url_select12345",
"action": "https://example.com/get",
"classes": "urlselect",
"formid": "gradesactionselect",
"sesskey": "sesskey",
"label": "",
"helpicon": false,
"showbutton": null,
"options": [{
"name": "View", "isgroup": true, "options":
[
{"name": "Grader report", "isgroup": false, "value": "/grade/report/grader/index.php"}
]},
{"name": "Setup", "isgroup": true, "options":
[
{"name": "Gradebook setup", "isgroup": false, "value": "/grade/edit/tree/index.php"}
]}],
"disabled": false,
"title": null
},
"addnewscalebutton": {
"id": "single_button12345",
"method" : "get",
"classes": "singlebutton",
"formid": null,
"url" : "#",
"primary" : true,
"tooltip" : null,
"label" : "Manage outcomes",
"attributes": []
}
}
}}
<div class="container-fluid mb-4">
<div class="row">
<div class="d-flex">
{{#generalnavselector}}
<div class="mr-2">
{{>core/url_select}}
</div>
{{/generalnavselector}}
{{#addnewscalebutton}}
<div>
{{>core/single_button}}
</div>
{{/addnewscalebutton}}
</div>
</div>
</div>
+1
View File
@@ -555,6 +555,7 @@ $string['nocategories'] = 'Grade categories could not be added or found for this
$string['nocategoryname'] = 'No category name was given.';
$string['nocategoryview'] = 'No category to view by';
$string['nocourses'] = 'There are no courses yet';
$string['noexistingscales'] = 'There are no existing scales.';
$string['noexistingoutcomes'] = 'There are no existing outcomes.';
$string['noforce'] = 'Do not force';
$string['nogradeletters'] = 'No grade letters set';