Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.

Differences Between: [Versions 400 and 401]

   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 string $activeplugin The plugin of the current export grades page (xml, ods, ...). */
  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 export grades page (xml, ods, ...).
  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/export_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/export/index.php', ['id' => $courseid]), 'export', $this->activeplugin);
  71          $data = $generalnavselector->export_for_template($output);
  72  
  73          // Get all grades export plugins. If there isn't any available export plugins there is no need to create and
  74          // display the exports navigation selector menu. Therefore, return only the current data.
  75          if (!$exports = \grade_helper::get_plugins_export($courseid)) {
  76              return $data;
  77          }
  78  
  79          // If exports key management is enabled, always display this item at the end of the list.
  80          if (array_key_exists('keymanager', $exports)) {
  81              $keymanager = $exports['keymanager'];
  82              unset($exports['keymanager']);
  83              $exports['keymanager'] = $keymanager;
  84          }
  85  
  86          $exportsmenu = [];
  87          $exportactiveurl = null;
  88          // Generate the data for the exports navigation selector menu.
  89          foreach ($exports as $export) {
  90              $exportsmenu[$export->link->out()] = $export->string;
  91              if ($export->id == $this->activeplugin) {
  92                  $exportactiveurl = $export->link->out();
  93              }
  94          }
  95  
  96          // This navigation selector menu will contain the links to all available grade export plugin pages.
  97          $exportsurlselect = new \core\output\select_menu('exportas', $exportsmenu, $exportactiveurl);
  98          $exportsurlselect->set_label(get_string('exportas', 'grades'));
  99          $data['exportselector'] = $exportsurlselect->export_for_template($output);
 100  
 101          return $data;
 102      }
 103  }