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  /**
  18   * Contains class mod_feedback_responses_anon_table
  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  
  25  defined('MOODLE_INTERNAL') || die();
  26  
  27  /**
  28   * Class mod_feedback_responses_anon_table
  29   *
  30   * @package   mod_feedback
  31   * @copyright 2016 Marina Glancy
  32   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  33   */
  34  class mod_feedback_responses_anon_table extends mod_feedback_responses_table {
  35  
  36      /** @var string */
  37      protected $showallparamname = 'ashowall';
  38  
  39      /** @var string */
  40      protected $downloadparamname = 'adownload';
  41  
  42      /**
  43       * Initialises table
  44       * @param int $group retrieve only users from this group (optional)
  45       */
  46      public function init($group = 0) {
  47  
  48          $cm = $this->feedbackstructure->get_cm();
  49          $this->uniqueid = 'feedback-showentry-anon-list-' . $cm->instance;
  50  
  51          // There potentially can be both tables with anonymouns and non-anonymous responses on
  52          // the same page (for example when feedback anonymity was changed after some people
  53          // already responded). In this case we need to distinguish tables' pagination parameters.
  54          $this->request[TABLE_VAR_PAGE] = 'apage';
  55  
  56          $tablecolumns = ['random_response'];
  57          $tableheaders = [get_string('response_nr', 'feedback')];
  58  
  59          if ($this->feedbackstructure->get_feedback()->course == SITEID && !$this->feedbackstructure->get_courseid()) {
  60              $tablecolumns[] = 'courseid';
  61              $tableheaders[] = get_string('course');
  62          }
  63  
  64          $this->define_columns($tablecolumns);
  65          $this->define_headers($tableheaders);
  66  
  67          $this->sortable(true, 'random_response');
  68          $this->collapsible(true);
  69          $this->set_attribute('id', 'showentryanontable');
  70  
  71          $params = ['instance' => $cm->instance,
  72              'anon' => FEEDBACK_ANONYMOUS_YES,
  73              'courseid' => $this->feedbackstructure->get_courseid()];
  74  
  75          $fields = 'c.id, c.random_response, c.courseid';
  76          $from = '{feedback_completed} c';
  77          $where = 'c.anonymous_response = :anon AND c.feedback = :instance';
  78          if ($this->feedbackstructure->get_courseid()) {
  79              $where .= ' AND c.courseid = :courseid';
  80          }
  81  
  82          $group = (empty($group)) ? groups_get_activity_group($this->feedbackstructure->get_cm(), true) : $group;
  83          if ($group) {
  84              $where .= ' AND c.userid IN (SELECT g.userid FROM {groups_members} g WHERE g.groupid = :group)';
  85              $params['group'] = $group;
  86          }
  87  
  88          $this->set_sql($fields, $from, $where, $params);
  89          $this->set_count_sql("SELECT COUNT(c.id) FROM $from WHERE $where", $params);
  90      }
  91  
  92      /**
  93       * Returns a link for viewing a single response
  94       * @param stdClass $row
  95       * @return \moodle_url
  96       */
  97      protected function get_link_single_entry($row) {
  98          return new moodle_url($this->baseurl, ['showcompleted' => $row->id]);
  99      }
 100  
 101      /**
 102       * Prepares column reponse for display
 103       * @param stdClass $row
 104       * @return string
 105       */
 106      public function col_random_response($row) {
 107          if ($this->is_downloading()) {
 108              return $row->random_response;
 109          } else {
 110              return html_writer::link($this->get_link_single_entry($row),
 111                      get_string('response_nr', 'feedback').': '. $row->random_response);
 112          }
 113      }
 114  
 115      /**
 116       * Add data for the external structure that will be returned.
 117       *
 118       * @param stdClass $row a database query record row
 119       * @since Moodle 3.3
 120       */
 121      protected function add_data_for_external($row) {
 122          $this->dataforexternal[] = [
 123              'id' => $row->id,
 124              'courseid' => $row->courseid,
 125              'number' => $row->random_response,
 126              'responses' => $this->get_responses_for_external($row)
 127          ];
 128      }
 129  }