Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.0.x will end 8 May 2023 (12 months).
  • Bug fixes for security issues in 4.0.x will end 13 November 2023 (18 months).
  • PHP version: minimum PHP 7.3.0 Note: the minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is also supported.

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 export 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 export_action_bar extends action_bar {
  29  
  30      /** @var moodle_url $exportactiveurl The URL that should be set as active in the exports URL selector element. */
  31      protected $exportactiveurl;
  32  
  33      /** @var string $activeplugin The plugin of the current export grades page (xml, ods, ...). */
  34      protected $activeplugin;
  35  
  36      /**
  37       * The class constructor.
  38       *
  39       * @param \context $context The context object.
  40       * @param moodle_url $exportactiveurl The URL that should be set as active in the exports URL selector element.
  41       * @param string $activeplugin The plugin of the current export grades page (xml, ods, ...).
  42       */
  43      public function __construct(\context $context, moodle_url $exportactiveurl, string $activeplugin) {
  44          parent::__construct($context);
  45          $this->exportactiveurl = $exportactiveurl;
  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/export_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/export/index.php', ['id' => $courseid]), 'export', $this->activeplugin);
  72          $data = $generalnavselector->export_for_template($output);
  73  
  74          // Get all grades export plugins. If there isn't any available export plugins there is no need to create and
  75          // display the exports navigation selector menu. Therefore, return only the current data.
  76          if (!$exports = \grade_helper::get_plugins_export($courseid)) {
  77              return $data;
  78          }
  79  
  80          // If exports key management is enabled, always display this item at the end of the list.
  81          if (array_key_exists('keymanager', $exports)) {
  82              $keymanager = $exports['keymanager'];
  83              unset($exports['keymanager']);
  84              $exports['keymanager'] = $keymanager;
  85          }
  86  
  87          $exportsmenu = [];
  88          // Generate the data for the exports navigation selector menu.
  89          foreach ($exports as $export) {
  90              $exportsmenu[$export->link->out()] = $export->string;
  91          }
  92  
  93          // This navigation selector menu will contain the links to all available grade export plugin pages.
  94          $exportsurlselect = new \url_select($exportsmenu, $this->exportactiveurl->out(false), null,
  95              'gradesexportactionselect');
  96          $data['exportselector'] = $exportsurlselect->export_for_template($output);
  97  
  98          return $data;
  99      }
 100  }