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  namespace mod_feedback\output;
  18  
  19  use moodle_url;
  20  use url_select;
  21  
  22  /**
  23   * Class responses_action_bar. The tertiary nav for the responses page
  24   *
  25   * @copyright 2021 Peter Dias
  26   * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
  27   * @package mod_feedback
  28   */
  29  class responses_action_bar extends base_action_bar {
  30      /** @var moodle_url $currenturl The current page url */
  31      private $currenturl;
  32  
  33      /**
  34       * responses_action_bar constructor.
  35       *
  36       * @param int $cmid The cmid for the module we are operating on
  37       * @param moodle_url $pageurl The current page url
  38       */
  39      public function __construct(int $cmid, moodle_url $pageurl) {
  40          parent::__construct($cmid);
  41          $this->currenturl = $pageurl;
  42          $this->urlparams['courseid'] = $this->course->id;
  43      }
  44  
  45      /**
  46       * Return the items to be used in the tertiary nav
  47       *
  48       * @return array
  49       */
  50      public function get_items(): array {
  51          $items = [];
  52          if (has_capability('mod/feedback:viewreports', $this->context)) {
  53              $reporturl = new moodle_url('/mod/feedback/show_entries.php', $this->urlparams);
  54              $options[$reporturl->out(false)] = get_string('show_entries', 'feedback');
  55              $selected = $this->currenturl->compare($reporturl, URL_MATCH_BASE) ? $reporturl : $this->currenturl;
  56  
  57              if ($this->feedback->anonymous == FEEDBACK_ANONYMOUS_NO && $this->course != SITEID) {
  58                  $nonrespondenturl = new moodle_url('/mod/feedback/show_nonrespondents.php', $this->urlparams);
  59                  $options[$nonrespondenturl->out(false)] = get_string('show_nonrespondents', 'feedback');
  60                  $selected = $this->currenturl->compare($nonrespondenturl, URL_MATCH_BASE) ? $nonrespondenturl : $this->currenturl;;
  61              }
  62  
  63              // Don't show the dropdown if it's only a single item.
  64              if (count($options) != 1) {
  65                  $items['left'][]['urlselect'] = new url_select($options,
  66                      $selected->out(false),
  67                      null);
  68              }
  69          }
  70          return $items;
  71      }
  72  }