MDL-72873 core_grades: Add tertiary navigation in grade import plugins

This commit is contained in:
Mihail Geshoski 2021-10-27 11:44:45 +08:00
parent 08e90eeef4
commit bd13229e75
11 changed files with 414 additions and 10 deletions

View File

@ -0,0 +1,100 @@
<?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 import pages.
*
* @package core_grades
* @copyright 2021 Mihail Geshoski <mihail@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class import_action_bar extends action_bar {
/** @var moodle_url $importactiveurl The URL that should be set as active in the imports URL selector element. */
protected $importactiveurl;
/** @var string $activeplugin The plugin of the current import grades page (xml, csv, ...). */
protected $activeplugin;
/**
* The class constructor.
*
* @param \context $context The context object.
* @param moodle_url $importactiveurl The URL that should be set as active in the imports URL selector element.
* @param string $activeplugin The plugin of the current import grades page (xml, csv, ...).
*/
public function __construct(\context $context, moodle_url $importactiveurl, string $activeplugin) {
parent::__construct($context);
$this->importactiveurl = $importactiveurl;
$this->activeplugin = $activeplugin;
}
/**
* Returns the template for the action bar.
*
* @return string
*/
public function get_template(): string {
return 'core_grades/import_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 {
if ($this->context->contextlevel !== CONTEXT_COURSE) {
return [];
}
$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/import/index.php', ['id' => $courseid]), 'import', $this->activeplugin);
$data = $generalnavselector->export_for_template($output);
// Get all grades import plugins. If there isn't any available import plugins there is no need to create and
// display the imports navigation selector menu. Therefore, return only the current data.
if (!$imports = \grade_helper::get_plugins_import($courseid)) {
return $data;
}
// If imports key management is enabled, always display this item at the end of the list.
if (array_key_exists('keymanager', $imports)) {
$keymanager = $imports['keymanager'];
unset($imports['keymanager']);
$imports['keymanager'] = $keymanager;
}
$importsmenu = [];
// Generate the data for the imports navigation selector menu.
foreach ($imports as $import) {
$importsmenu[$import->link->out()] = $import->string;
}
// This navigation selector menu will contain the links to all available grade export plugin pages.
$importsurlselect = new \url_select($importsmenu, $this->importactiveurl->out(false), null,
'gradesimportactionselect');
$data['importselector'] = $importsurlselect->export_for_template($output);
return $data;
}
}

View File

@ -0,0 +1,63 @@
<?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 import key manager page.
*
* @package core_grades
* @copyright 2021 Mihail Geshoski <mihail@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class import_key_manager_action_bar extends action_bar {
/**
* Returns the template for the action bar.
*
* @return string
*/
public function get_template(): string {
return 'core_grades/import_key_manager_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 {
if ($this->context->contextlevel !== CONTEXT_COURSE) {
return [];
}
$courseid = $this->context->instanceid;
// Get the data used to output the general navigation selector and imports navigation selector.
$importnavselectors = new import_action_bar($this->context,
new moodle_url('/grade/import/keymanager.php', ['id' => $courseid]), 'keymanager');
$data = $importnavselectors->export_for_template($output);
// Add a button to the action bar with a link to the 'add user key' page.
$adduserkeylink = new moodle_url('/grade/import/key.php', ['courseid' => $courseid]);
$adduserkeybutton = new \single_button($adduserkeylink, get_string('adduserkey', 'userkey'),
'get', true);
$data['adduserkeybutton'] = $adduserkeybutton->export_for_template($output);
return $data;
}
}

View File

@ -51,8 +51,9 @@ $separatemode = (groups_get_course_groupmode($COURSE) == SEPARATEGROUPS and
!has_capability('moodle/site:accessallgroups', $context));
$currentgroup = groups_get_course_group($course);
$actionbar = new \core_grades\output\import_action_bar($context, $PAGE->url, 'csv');
print_grade_page_head($course->id, 'import', 'csv', get_string('importcsv', 'grades'), false, false, true,
'importcsv', 'grades');
'importcsv', 'grades', null, $actionbar);
$renderer = $PAGE->get_renderer('gradeimport_csv');

View File

@ -47,8 +47,9 @@ $separatemode = (groups_get_course_groupmode($COURSE) == SEPARATEGROUPS and
!has_capability('moodle/site:accessallgroups', $context));
$currentgroup = groups_get_course_group($course);
$actionbar = new \core_grades\output\import_action_bar($context, $PAGE->url, 'direct');
print_grade_page_head($course->id, 'import', 'direct', get_string('pluginname', 'gradeimport_direct'), false, false, true,
'userdata', 'gradeimport_direct');
'userdata', 'gradeimport_direct', null, $actionbar);
$renderer = $PAGE->get_renderer('gradeimport_csv');

56
grade/import/index.php Normal file
View File

@ -0,0 +1,56 @@
<?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/>.
/**
* Redirects the user to a default grades import plugin page.
*
* @package core_grades
* @copyright 2021 Mihail Geshoski <mihail@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require_once(__DIR__ . '/../../config.php');
// Course ID.
$courseid = required_param('id', PARAM_INT);
$PAGE->set_url(new moodle_url('/grade/import/index.php', ['id' => $courseid]));
// Basic access checks.
if (!$course = $DB->get_record('course', ['id' => $courseid])) {
throw new moodle_exception('invalidcourseid', 'error');
}
require_login($course);
$context = context_course::instance($courseid);
require_capability('moodle/grade:import', $context);
$importplugins = core_component::get_plugin_list('gradeimport');
if (!empty($importplugins)) {
$importplugin = array_key_first($importplugins);
$url = new moodle_url("/grade/import/{$importplugin}/index.php", ['id' => $courseid]);
redirect($url);
}
// Otherwise, output the page with a notification stating that there are no available grade import options.
$PAGE->set_title(get_string('import', 'grades'));
$PAGE->set_pagelayout('incourse');
$PAGE->set_heading($course->fullname);
$PAGE->set_pagetype('course-view-' . $course->format);
echo $OUTPUT->header();
echo $OUTPUT->heading(get_string('import', 'grades'));
echo html_writer::div($OUTPUT->notification(get_string('nogradeimport', 'grades'), 'error'), 'mt-3');
echo $OUTPUT->footer();

View File

@ -80,6 +80,7 @@ if ($id and $delete) {
if (!$confirm) {
$PAGE->set_title(get_string('deleteselectedkey'));
$PAGE->set_heading($course->fullname);
$PAGE->set_secondary_active_tab('grades');
echo $OUTPUT->header();
$optionsyes = array('id'=>$id, 'delete'=>1, 'courseid'=>$courseid, 'sesskey'=>sesskey(), 'confirm'=>1);
$optionsno = array('id'=>$courseid);
@ -133,7 +134,9 @@ $PAGE->navbar->add($strheading);
/// Print header
$PAGE->set_title($strkeys);
$PAGE->set_heading($course->fullname);
$PAGE->set_secondary_active_tab('grades');
echo $OUTPUT->header();
echo $OUTPUT->heading($strheading);
$editform->display();
echo $OUTPUT->footer();

View File

@ -45,7 +45,9 @@ if (!isset($plugins['keymanager'])) {
print_error('nopermissions');
}
print_grade_page_head($course->id, 'import', 'keymanager', get_string('keymanager', 'grades'));
$actionbar = new \core_grades\output\import_key_manager_action_bar($context);
print_grade_page_head($course->id, 'import', 'keymanager', get_string('keymanager', 'grades'),
false, false, true, 'importcsv', 'grades', null, $actionbar);
$stredit = get_string('edit');
$strdelete = get_string('delete');
@ -78,10 +80,5 @@ $table->align = array('left', 'left', 'left', 'center');
$table->width = '90%';
$table->data = $data;
echo html_writer::table($table);
echo $OUTPUT->container_start('buttons mdl-align');
echo $OUTPUT->single_button(new moodle_url('key.php', array('courseid'=>$course->id)), get_string('newuserkey', 'userkey'));
echo $OUTPUT->container_end();
echo $OUTPUT->footer();

View File

@ -87,8 +87,9 @@ if ($data = $mform->get_data()) {
}
}
print_grade_page_head($COURSE->id, 'import', 'xml',
get_string('importxml', 'grades'), false, false, true, 'importxml', 'gradeimport_xml');
$actionbar = new \core_grades\output\import_action_bar($context, $PAGE->url, 'xml');
print_grade_page_head($COURSE->id, 'import', 'xml', get_string('importxml', 'grades'),
false, false, true, 'importxml', 'gradeimport_xml', null, $actionbar);
$mform->display();

View File

@ -0,0 +1,82 @@
{{!
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/import_action_bar
Actions bar for the gradebook import pages.
Context variables required for this template:
* generalnavselector - The data object containing the required properties to render the general navigation selector.
* importselector - The data object containing the required properties to render the import options selector.
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
},
"importselector": {
"id": "url_select56789",
"action": "https://example.com/get",
"formid": "gradesimportactionselect",
"sesskey": "sesskey",
"classes": "urlselect",
"label": "",
"helpicon": false,
"showbutton": null,
"options": [
{
"name": "CSV file",
"value": "/grade/import/csv/index.php",
"selected": true
}
],
"disabled": false,
"title": null
}
}
}}
<div class="container-fluid mb-4">
<div class="row">
<div class="d-flex">
<div>
{{#generalnavselector}}
{{>core/url_select}}
{{/generalnavselector}}
</div>
<div class="ml-2">
{{#importselector}}
{{>core/url_select}}
{{/importselector}}
</div>
</div>
</div>
</div>

View File

@ -0,0 +1,99 @@
{{!
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/import_key_manager_action_bar
Actions bar for the gradebook imports key manager page.
Context variables required for this template:
* generalnavselector - The data object containing the required properties to render core/url_select.
* importselector - The data object containing the required properties to render the import options selector.
* adduserkeybutton - The data object containing the required properties to render the 'add user key' 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
},
"importselector": {
"id": "url_select56789",
"action": "https://example.com/get",
"formid": "gradesimportactionselect",
"sesskey": "sesskey",
"classes": "urlselect",
"label": "",
"helpicon": false,
"showbutton": null,
"options": [
{
"name": "CSV file",
"value": "/grade/import/csv/index.php",
"selected": true
}
],
"disabled": false,
"title": null
},
"adduserkeybutton": {
"id": "single_button12345",
"method" : "get",
"classes": "singlebutton",
"formid": null,
"url" : "#",
"primary" : true,
"tooltip" : null,
"label" : "Add user key",
"attributes": []
}
}
}}
<div class="container-fluid mb-4">
<div class="row">
<div class="d-flex">
<div>
{{#generalnavselector}}
{{>core/url_select}}
{{/generalnavselector}}
</div>
<div class="ml-2">
{{#importselector}}
{{>core/url_select}}
{{/importselector}}
</div>
{{#adduserkeybutton}}
<div class="ml-2">
{{>core/single_button}}
</div>
{{/adduserkeybutton}}
</div>
</div>
</div>

View File

@ -22,6 +22,7 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
$string['adduserkey'] = 'Add user key';
$string['createnewkey'] = 'Create a new user key';
$string['createuserkey'] = 'Create user key';
$string['deletekeyconfirm'] = 'Do you really want to delete this user key?';