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.
MDL-72873 core_grades: Add tertiary navigation in grade import plugins
- Loading branch information
Mihail Geshoski
committed
Dec 15, 2021
1 parent
08e90ee
commit bd13229
Showing
11 changed files
with
414 additions
and
10 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,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; | ||
} | ||
} |
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,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; | ||
} | ||
} |
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
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
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,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(); |
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
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
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
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,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> |
Oops, something went wrong.