1 |
efrain |
1 |
<?php
|
|
|
2 |
// This file is part of Moodle - http://moodle.org/
|
|
|
3 |
//
|
|
|
4 |
// Moodle is free software: you can redistribute it and/or modify
|
|
|
5 |
// it under the terms of the GNU General Public License as published by
|
|
|
6 |
// the Free Software Foundation, either version 3 of the License, or
|
|
|
7 |
// (at your option) any later version.
|
|
|
8 |
//
|
|
|
9 |
// Moodle is distributed in the hope that it will be useful,
|
|
|
10 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
11 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
12 |
// GNU General Public License for more details.
|
|
|
13 |
//
|
|
|
14 |
// You should have received a copy of the GNU General Public License
|
|
|
15 |
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
|
|
16 |
|
|
|
17 |
namespace core_grades\output;
|
|
|
18 |
|
|
|
19 |
use moodle_url;
|
|
|
20 |
|
|
|
21 |
/**
|
|
|
22 |
* Renderable class for the action bar elements in the gradebook import pages.
|
|
|
23 |
*
|
|
|
24 |
* @package core_grades
|
|
|
25 |
* @copyright 2021 Mihail Geshoski <mihail@moodle.com>
|
|
|
26 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
27 |
*/
|
|
|
28 |
class import_action_bar extends action_bar {
|
|
|
29 |
|
|
|
30 |
/** @var string $activeplugin The plugin of the current import grades page (xml, csv, ...). */
|
|
|
31 |
protected $activeplugin;
|
|
|
32 |
|
|
|
33 |
/**
|
|
|
34 |
* The class constructor.
|
|
|
35 |
*
|
|
|
36 |
* @param \context $context The context object.
|
|
|
37 |
* @param null $unused This parameter has been deprecated since 4.1 and should not be used anymore.
|
|
|
38 |
* @param string $activeplugin The plugin of the current import grades page (xml, csv, ...).
|
|
|
39 |
*/
|
|
|
40 |
public function __construct(\context $context, $unused, string $activeplugin) {
|
|
|
41 |
if ($unused !== null) {
|
|
|
42 |
debugging('Deprecated argument passed to ' . __FUNCTION__, DEBUG_DEVELOPER);
|
|
|
43 |
}
|
|
|
44 |
parent::__construct($context);
|
|
|
45 |
$this->activeplugin = $activeplugin;
|
|
|
46 |
}
|
|
|
47 |
|
|
|
48 |
/**
|
|
|
49 |
* Returns the template for the action bar.
|
|
|
50 |
*
|
|
|
51 |
* @return string
|
|
|
52 |
*/
|
|
|
53 |
public function get_template(): string {
|
|
|
54 |
return 'core_grades/import_action_bar';
|
|
|
55 |
}
|
|
|
56 |
|
|
|
57 |
/**
|
|
|
58 |
* Export the data for the mustache template.
|
|
|
59 |
*
|
|
|
60 |
* @param \renderer_base $output renderer to be used to render the action bar elements.
|
|
|
61 |
* @return array
|
|
|
62 |
*/
|
|
|
63 |
public function export_for_template(\renderer_base $output): array {
|
|
|
64 |
if ($this->context->contextlevel !== CONTEXT_COURSE) {
|
|
|
65 |
return [];
|
|
|
66 |
}
|
|
|
67 |
$courseid = $this->context->instanceid;
|
|
|
68 |
// Get the data used to output the general navigation selector.
|
|
|
69 |
$generalnavselector = new general_action_bar($this->context,
|
|
|
70 |
new moodle_url('/grade/import/index.php', ['id' => $courseid]), 'import', $this->activeplugin);
|
|
|
71 |
$data = $generalnavselector->export_for_template($output);
|
|
|
72 |
|
|
|
73 |
// Get all grades import plugins. If there isn't any available import plugins there is no need to create and
|
|
|
74 |
// display the imports navigation selector menu. Therefore, return only the current data.
|
|
|
75 |
if (!$imports = \grade_helper::get_plugins_import($courseid)) {
|
|
|
76 |
return $data;
|
|
|
77 |
}
|
|
|
78 |
|
|
|
79 |
// If imports key management is enabled, always display this item at the end of the list.
|
|
|
80 |
if (array_key_exists('keymanager', $imports)) {
|
|
|
81 |
$keymanager = $imports['keymanager'];
|
|
|
82 |
unset($imports['keymanager']);
|
|
|
83 |
$imports['keymanager'] = $keymanager;
|
|
|
84 |
}
|
|
|
85 |
|
|
|
86 |
$importsmenu = [];
|
|
|
87 |
$importactiveurl = null;
|
|
|
88 |
// Generate the data for the imports navigation selector menu.
|
|
|
89 |
foreach ($imports as $import) {
|
|
|
90 |
$importsmenu[$import->link->out()] = $import->string;
|
|
|
91 |
if ($import->id == $this->activeplugin) {
|
|
|
92 |
$importactiveurl = $import->link->out();
|
|
|
93 |
}
|
|
|
94 |
}
|
|
|
95 |
|
|
|
96 |
// This navigation selector menu will contain the links to all available grade export plugin pages.
|
|
|
97 |
$importsurlselect = new \core\output\select_menu('importas', $importsmenu, $importactiveurl);
|
|
|
98 |
$importsurlselect->set_label(get_string('importas', 'grades'));
|
|
|
99 |
$data['importselector'] = $importsurlselect->export_for_template($output);
|
|
|
100 |
|
|
|
101 |
return $data;
|
|
|
102 |
}
|
|
|
103 |
}
|