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.
   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 action_link;
  21  use single_select;
  22  use url_select;
  23  
  24  /**
  25   * Class actionbar - Display the action bar
  26   *
  27   * @package   mod_feedback
  28   * @copyright 2021 Peter Dias
  29   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  30   */
  31  class edit_action_bar extends base_action_bar {
  32      /** @var moodle_url $currenturl The current page url */
  33      private $currenturl;
  34      /** @var int|null $lastposition The index of the last question type in the feedback module */
  35      private $lastposition;
  36  
  37      /**
  38       * edit_action_bar constructor.
  39       *
  40       * @param int $cmid The course module id
  41       * @param moodle_url $pageurl The current page url
  42       * @param int|null $lastposition Index of the last question in the feedback
  43       */
  44      public function __construct(int $cmid, moodle_url $pageurl, ?int $lastposition = null) {
  45          parent::__construct($cmid);
  46          $this->currenturl = $pageurl;
  47          $this->lastposition = $lastposition;
  48      }
  49  
  50      /**
  51       * Return the items to be used for the tertiary nav
  52       *
  53       * @return array
  54       */
  55      public function get_items(): array {
  56          $url = new moodle_url('/mod/feedback/view.php', ['id' => $this->cmid]);
  57          $items['left'][]['actionlink'] = new action_link($url, get_string('back'), null, ['class' => 'btn btn-secondary']);
  58  
  59          if (has_capability('mod/feedback:edititems', $this->context)) {
  60              $editurl = new moodle_url('/mod/feedback/edit.php', $this->urlparams);
  61              $templateurl = new moodle_url('/mod/feedback/manage_templates.php', $this->urlparams);
  62              $importurl = new moodle_url('/mod/feedback/import.php', $this->urlparams);
  63  
  64              $options = [
  65                  $editurl->out(false) => get_string('add_item', 'feedback'),
  66                  $templateurl->out(false) => get_string('using_templates', 'feedback'),
  67                  $importurl->out(false) => get_string('import_questions', 'feedback')
  68              ];
  69  
  70              $selected = $this->currenturl;
  71              // Template pages can have sub pages, so match these.
  72              if ($this->currenturl->compare(new moodle_url('/mod/feedback/use_templ.php'), URL_MATCH_BASE)) {
  73                  $selected = $templateurl;
  74              }
  75  
  76              $items['left'][]['urlselect'] = new url_select($options, $selected->out(false), null);
  77  
  78              $viewquestions = $editurl->compare($this->currenturl);
  79              if ($viewquestions) {
  80                  $select = new single_select(new moodle_url('/mod/feedback/edit_item.php',
  81                      ['cmid' => $this->cmid, 'position' => $this->lastposition, 'sesskey' => sesskey()]),
  82                      'typ', feedback_load_feedback_items_options());
  83                  $items['left'][]['singleselect'] = $select;
  84  
  85                  $exporturl = new moodle_url('/mod/feedback/export.php', $this->urlparams + ['action' => 'exportfile']);
  86                  $items['export'] = new action_link(
  87                      $exporturl,
  88                      get_string('export_questions', 'feedback'),
  89                      null,
  90                      ['class' => 'btn btn-secondary']);
  91              }
  92          }
  93  
  94          return $items;
  95      }
  96  }