Differences Between: [Versions 400 and 401] [Versions 400 and 402] [Versions 400 and 403]
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 moodle_url $importactiveurl The URL that should be set as active in the imports URL selector element. */ 31 protected $importactiveurl; 32 33 /** @var string $activeplugin The plugin of the current import grades page (xml, csv, ...). */ 34 protected $activeplugin; 35 36 /** 37 * The class constructor. 38 * 39 * @param \context $context The context object. 40 * @param moodle_url $importactiveurl The URL that should be set as active in the imports URL selector element. 41 * @param string $activeplugin The plugin of the current import grades page (xml, csv, ...). 42 */ 43 public function __construct(\context $context, moodle_url $importactiveurl, string $activeplugin) { 44 parent::__construct($context); 45 $this->importactiveurl = $importactiveurl; 46 $this->activeplugin = $activeplugin; 47 } 48 49 /** 50 * Returns the template for the action bar. 51 * 52 * @return string 53 */ 54 public function get_template(): string { 55 return 'core_grades/import_action_bar'; 56 } 57 58 /** 59 * Export the data for the mustache template. 60 * 61 * @param \renderer_base $output renderer to be used to render the action bar elements. 62 * @return array 63 */ 64 public function export_for_template(\renderer_base $output): array { 65 if ($this->context->contextlevel !== CONTEXT_COURSE) { 66 return []; 67 } 68 $courseid = $this->context->instanceid; 69 // Get the data used to output the general navigation selector. 70 $generalnavselector = new general_action_bar($this->context, 71 new moodle_url('/grade/import/index.php', ['id' => $courseid]), 'import', $this->activeplugin); 72 $data = $generalnavselector->export_for_template($output); 73 74 // Get all grades import plugins. If there isn't any available import plugins there is no need to create and 75 // display the imports navigation selector menu. Therefore, return only the current data. 76 if (!$imports = \grade_helper::get_plugins_import($courseid)) { 77 return $data; 78 } 79 80 // If imports key management is enabled, always display this item at the end of the list. 81 if (array_key_exists('keymanager', $imports)) { 82 $keymanager = $imports['keymanager']; 83 unset($imports['keymanager']); 84 $imports['keymanager'] = $keymanager; 85 } 86 87 $importsmenu = []; 88 // Generate the data for the imports navigation selector menu. 89 foreach ($imports as $import) { 90 $importsmenu[$import->link->out()] = $import->string; 91 } 92 93 // This navigation selector menu will contain the links to all available grade export plugin pages. 94 $importsurlselect = new \url_select($importsmenu, $this->importactiveurl->out(false), null, 95 'gradesimportactionselect'); 96 $data['importselector'] = $importsurlselect->export_for_template($output); 97 98 return $data; 99 } 100 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body