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.
   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  declare(strict_types=1);
  18  
  19  namespace gradereport_singleview\output;
  20  
  21  use moodle_url;
  22  use renderer_base;
  23  use gradereport_singleview\report\singleview;
  24  
  25  /**
  26   * Renderable class for the action bar elements in the single view report page.
  27   *
  28   * @package   gradereport_singleview
  29   * @copyright 2022 Shamim Rezaie <shamim@moodle.com>
  30   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  31   */
  32  class action_bar extends \core_grades\output\action_bar {
  33  
  34      /** @var singleview $report The single view report class. */
  35      protected singleview $report;
  36  
  37      /** @var string $itemtype The single view item type. */
  38      protected string $itemtype;
  39  
  40      /**
  41       * The class constructor.
  42       *
  43       * @param \context $context The context object.
  44       * @param singleview $report The single view report class.
  45       * @param string $itemtype The single view item type.
  46       */
  47      public function __construct(\context $context, singleview $report, string $itemtype) {
  48          parent::__construct($context);
  49          $this->report = $report;
  50          $this->itemtype = $itemtype;
  51      }
  52  
  53      /**
  54       * Returns the template for the action bar.
  55       *
  56       * @return string
  57       */
  58      public function get_template(): string {
  59          return 'gradereport_singleview/action_bar';
  60      }
  61  
  62      /**
  63       * Export the data for the mustache template.
  64       *
  65       * @param \renderer_base $output renderer to be used to render the action bar elements.
  66       * @return array
  67       */
  68      public function export_for_template(renderer_base $output) {
  69          global $USER;
  70  
  71          $courseid = $this->context->instanceid;
  72          // Get the data used to output the general navigation selector.
  73          $generalnavselector = new \core_grades\output\general_action_bar(
  74              $this->context,
  75              new moodle_url('/grade/report/singleview/index.php', ['id' => $courseid]),
  76              'report',
  77              'singleview'
  78          );
  79          $data = $generalnavselector->export_for_template($output);
  80  
  81          // The data required to output the page toggle element.
  82          $data['pagetoggler'] = [
  83              'displaylabel' => true,
  84              'userselectactive' => $this->itemtype === 'user',
  85              'gradeselectactive' => $this->itemtype === 'grade',
  86              'gradezerolink' => (new moodle_url('/grade/report/singleview/index.php',
  87                  ['id' => $courseid, 'item' => 'grade_select']))->out(false),
  88              'userzerolink' => (new moodle_url('/grade/report/singleview/index.php',
  89                  ['id' => $courseid, 'item' => 'user_select']))->out(false)
  90          ];
  91  
  92          $data['groupselector'] = $this->report->group_selector;
  93          $data['itemselector'] = $this->report->itemselector;
  94  
  95          $data['pbarurl'] = $this->report->pbarurl->out(false);
  96  
  97          if (!empty($USER->editing) && isset($this->report->screen->item)) {
  98              $data['bulkactions'] = $this->report->bulk_actions_menu($output);
  99          }
 100  
 101          return $data;
 102      }
 103  }