Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.10.x will end 8 November 2021 (12 months).
  • Bug fixes for security issues in 3.10.x will end 9 May 2022 (18 months).
  • PHP version: minimum PHP 7.2.0 Note: minimum PHP version has increased since Moodle 3.8. PHP 7.3.x and 7.4.x are 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  /**
  18   * Contains class mod_feedback_course_map_form
  19   *
  20   * @package   mod_feedback
  21   * @copyright 2016 Marina Glancy
  22   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  defined('MOODLE_INTERNAL') || die();
  25  
  26  /**
  27   * Form for mapping courses to the feedback
  28   *
  29   * @package   mod_feedback
  30   * @copyright 2016 Marina Glancy
  31   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  32   */
  33  class mod_feedback_course_select_form extends moodleform {
  34      /** @var moodle_url */
  35      protected $action;
  36      /** @var mod_feedback_structure $feedbackstructure */
  37      protected $feedbackstructure;
  38  
  39      /**
  40       * Constructor
  41       *
  42       * @param string|moodle_url $action the action attribute for the form
  43       * @param mod_feedback_structure $feedbackstructure
  44       * @param bool $editable
  45       */
  46      public function __construct($action, mod_feedback_structure $feedbackstructure, $editable = true) {
  47          $this->action = new moodle_url($action, ['courseid' => null]);
  48          $this->feedbackstructure = $feedbackstructure;
  49          parent::__construct($action, null, 'post', '', ['id' => 'feedback_course_filter'], $editable);
  50      }
  51  
  52      /**
  53       * Definition of the form
  54       */
  55      public function definition() {
  56          $mform = $this->_form;
  57          $feedbackstructure = $this->feedbackstructure;
  58  
  59          $mform->addElement('hidden', 'id');
  60          $mform->setType('id', PARAM_INT);
  61  
  62          if (!$this->_form->_freezeAll && ($courses = $feedbackstructure->get_completed_courses()) && count($courses) > 1) {
  63              $elements = [];
  64              $elements[] = $mform->createElement('autocomplete', 'courseid', get_string('filter_by_course', 'feedback'),
  65                  ['' => get_string('fulllistofcourses')] + $courses);
  66              $elements[] = $mform->createElement('submit', 'submitbutton', get_string('filter'));
  67              if ($feedbackstructure->get_courseid()) {
  68                  $elements[] = $mform->createElement('static', 'showall', '',
  69                      html_writer::link($this->action, get_string('show_all', 'feedback')));
  70              }
  71              if (defined('BEHAT_SITE_RUNNING')) {
  72                  // TODO MDL-53734 remove this - behat does not recognise autocomplete element inside a group.
  73                  foreach ($elements as $element) {
  74                      $mform->addElement($element);
  75                  }
  76              } else {
  77                  $mform->addGroup($elements, 'coursefilter', get_string('filter_by_course', 'feedback'), array(' '), false);
  78              }
  79          }
  80  
  81          $this->set_data(['courseid' => $feedbackstructure->get_courseid(), 'id' => $feedbackstructure->get_cm()->id]);
  82      }
  83  }