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 310 and 401] [Versions 311 and 401] [Versions 39 and 401] [Versions 400 and 401] [Versions 401 and 402] [Versions 401 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  /**
  18   * The gradebook simple view - initial view to select your search options
  19   *
  20   * @package   gradereport_singleview
  21   * @copyright 2014 Moodle Pty Ltd (http://moodle.com)
  22   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  
  25  namespace gradereport_singleview\local\screen;
  26  
  27  use gradereport_singleview;
  28  use moodle_url;
  29  
  30  defined('MOODLE_INTERNAL') || die;
  31  
  32  /**
  33   * The gradebook simple view - initial view to select your search options
  34   *
  35   * @package   gradereport_singleview
  36   * @copyright 2014 Moodle Pty Ltd (http://moodle.com)
  37   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  38   */
  39  class select extends screen {
  40  
  41      /**
  42       * Initialise this screen
  43       *
  44       * @param bool $selfitemisempty Has an item been selected (will be false)
  45       */
  46      public function init($selfitemisempty = false) {
  47          global $DB;
  48  
  49          $roleids = explode(',', get_config('moodle', 'gradebookroles'));
  50  
  51          $this->items = [];
  52          foreach ($roleids as $roleid) {
  53              // Keeping the first user appearance.
  54              $this->items = $this->items + get_role_users(
  55                  $roleid, $this->context, false, '',
  56                  'u.id, u.lastname, u.firstname', null, $this->groupid,
  57                  $this->perpage * $this->page, $this->perpage
  58              );
  59          }
  60          $this->item = $DB->get_record('course', ['id' => $this->courseid]);
  61      }
  62  
  63      /**
  64       * Get the type of items on this screen, not valid so return false.
  65       *
  66       * @return string|null
  67       */
  68      public function item_type(): ?string {
  69          return false;
  70      }
  71  
  72      /**
  73       * Return the HTML for the page.
  74       *
  75       * @return string
  76       */
  77      public function html(): string {
  78          global $OUTPUT, $COURSE;
  79  
  80          if ($this->itemid === null) {
  81              $userlink = new \moodle_url('/grade/report/singleview/index.php', ['id' => $COURSE->id, 'item' => 'user_select']);
  82              $gradelink = new \moodle_url('/grade/report/singleview/index.php', ['id' => $COURSE->id, 'item' => 'grade_select']);
  83              $context = [
  84                  'courseid' => $COURSE->id,
  85                  'imglink' => $OUTPUT->image_url('zero_state', 'gradereport_singleview'),
  86                  'userzerolink' => $userlink->out(false),
  87                  'userselectactive' => false,
  88                  'gradezerolink' => $gradelink->out(false),
  89                  'gradeselectactive' => false,
  90                  'displaylabel' => false
  91              ];
  92              return $OUTPUT->render_from_template('gradereport_singleview/zero_state', $context);
  93          }
  94  
  95          $html = '';
  96  
  97          $types = gradereport_singleview\report\singleview::valid_screens();
  98  
  99          foreach ($types as $type) {
 100              $classname = "gradereport_singleview\\local\\screen\\$type}";
 101  
 102              $screen = new $classname($this->courseid, null, $this->groupid);
 103  
 104              if (!$screen instanceof selectable_items) {
 105                  continue;
 106              }
 107  
 108              $options = $screen->options();
 109  
 110              if (empty($options)) {
 111                  continue;
 112              }
 113  
 114              $params = [
 115                  'id' => $this->courseid,
 116                  'item' => $screen->item_type(),
 117                  'group' => $this->groupid
 118              ];
 119  
 120              $url = new moodle_url('/grade/report/singleview/index.php', $params);
 121  
 122              $select = new \single_select($url, 'itemid', $options, '', ['' => $screen->select_label()]);
 123              $select->set_label($screen->select_label(), ['class' => 'accesshide']);
 124              $html .= $OUTPUT->render($select);
 125          }
 126          $html = $OUTPUT->container($html, 'selectitems');
 127  
 128          if (empty($html)) {
 129              $OUTPUT->notification(get_string('noscreens', 'gradereport_singleview'));
 130          }
 131  
 132          return $html;
 133      }
 134  
 135      /**
 136       * Should we show the next prev selector?
 137       * @return bool
 138       */
 139      public function supports_next_prev(): bool {
 140          return false;
 141      }
 142  
 143      /**
 144       * Should we show the base singlereport group selector?
 145       * @return bool
 146       */
 147      public function display_group_selector(): bool {
 148          if ($this->itemid === null) {
 149              return false;
 150          }
 151          return true;
 152      }
 153  
 154      /**
 155       * Get the heading for the screen.
 156       *
 157       * @return string
 158       */
 159      public function heading(): string {
 160          return ' ';
 161      }
 162  
 163      /**
 164       * Does this screen support paging?
 165       *
 166       * @return bool
 167       */
 168      public function supports_paging(): bool {
 169          return false;
 170      }
 171  }