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.

Differences Between: [Versions 310 and 400] [Versions 311 and 400] [Versions 39 and 400]

   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   * print the single entries
  19   *
  20   * @author Andreas Grabs
  21   * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
  22   * @package mod_feedback
  23   */
  24  
  25  require_once("../../config.php");
  26  require_once ("lib.php");
  27  
  28  ////////////////////////////////////////////////////////
  29  //get the params
  30  ////////////////////////////////////////////////////////
  31  $id = required_param('id', PARAM_INT);
  32  $userid = optional_param('userid', false, PARAM_INT);
  33  $showcompleted = optional_param('showcompleted', false, PARAM_INT);
  34  $deleteid = optional_param('delete', null, PARAM_INT);
  35  $courseid = optional_param('courseid', null, PARAM_INT);
  36  
  37  ////////////////////////////////////////////////////////
  38  //get the objects
  39  ////////////////////////////////////////////////////////
  40  
  41  list($course, $cm) = get_course_and_cm_from_cmid($id, 'feedback');
  42  
  43  $baseurl = new moodle_url('/mod/feedback/show_entries.php', array('id' => $cm->id));
  44  $PAGE->set_url(new moodle_url($baseurl, array('userid' => $userid, 'showcompleted' => $showcompleted,
  45          'delete' => $deleteid)));
  46  $context = context_module::instance($cm->id);
  47  
  48  require_login($course, true, $cm);
  49  $feedback = $PAGE->activityrecord;
  50  
  51  require_capability('mod/feedback:viewreports', $context);
  52  
  53  $actionbar = new \mod_feedback\output\responses_action_bar($cm->id, $baseurl);
  54  
  55  if ($deleteid) {
  56      // This is a request to delete a reponse.
  57      require_capability('mod/feedback:deletesubmissions', $context);
  58      require_sesskey();
  59      $feedbackstructure = new mod_feedback_completion($feedback, $cm, 0, true, $deleteid);
  60      feedback_delete_completed($feedbackstructure->get_completed(), $feedback, $cm);
  61      redirect($baseurl);
  62  } else if ($showcompleted || $userid) {
  63      // Viewing individual response.
  64      $feedbackstructure = new mod_feedback_completion($feedback, $cm, 0, true, $showcompleted, $userid);
  65  } else {
  66      // Viewing list of reponses.
  67      $feedbackstructure = new mod_feedback_structure($feedback, $cm, $courseid);
  68  }
  69  
  70  $responsestable = new mod_feedback_responses_table($feedbackstructure);
  71  $anonresponsestable = new mod_feedback_responses_anon_table($feedbackstructure);
  72  
  73  if ($responsestable->is_downloading()) {
  74      $responsestable->download();
  75  }
  76  if ($anonresponsestable->is_downloading()) {
  77      $anonresponsestable->download();
  78  }
  79  
  80  // Process course select form.
  81  $courseselectform = new mod_feedback_course_select_form($baseurl, $feedbackstructure, $feedback->course == SITEID);
  82  if ($data = $courseselectform->get_data()) {
  83      redirect(new moodle_url($baseurl, ['courseid' => $data->courseid]));
  84  }
  85  // Print the page header.
  86  navigation_node::override_active_url($baseurl);
  87  $PAGE->set_heading($course->fullname);
  88  $PAGE->set_title($feedback->name);
  89  $PAGE->activityheader->set_attrs([
  90      'hidecompletion' => true,
  91      'description' => ''
  92  ]);
  93  $PAGE->add_body_class('limitedwidth');
  94  echo $OUTPUT->header();
  95  
  96  /** @var \mod_feedback\output\renderer $renderer */
  97  $renderer = $PAGE->get_renderer('mod_feedback');
  98  echo $renderer->main_action_bar($actionbar);
  99  echo $OUTPUT->heading(get_string('show_entries', 'mod_feedback'), 3);
 100  
 101  $current_tab = 'showentries';
 102  
 103  /// Print the main part of the page
 104  ///////////////////////////////////////////////////////////////////////////
 105  ///////////////////////////////////////////////////////////////////////////
 106  ///////////////////////////////////////////////////////////////////////////
 107  
 108  if ($userid || $showcompleted) {
 109      // Print the response of the given user.
 110      $completedrecord = $feedbackstructure->get_completed();
 111  
 112      if ($userid) {
 113          $usr = $DB->get_record('user', array('id' => $userid), '*', MUST_EXIST);
 114          $responsetitle = userdate($completedrecord->timemodified) . ' (' . fullname($usr) . ')';
 115      } else {
 116          $responsetitle = get_string('response_nr', 'feedback') . ': ' .
 117                  $completedrecord->random_response . ' (' . get_string('anonymous', 'feedback') . ')';
 118      }
 119  
 120      echo $OUTPUT->heading($responsetitle, 4);
 121  
 122      $form = new mod_feedback_complete_form(mod_feedback_complete_form::MODE_VIEW_RESPONSE,
 123              $feedbackstructure, 'feedback_viewresponse_form');
 124      $form->display();
 125  
 126      list($prevresponseurl, $returnurl, $nextresponseurl) = $userid ?
 127              $responsestable->get_reponse_navigation_links($completedrecord) :
 128              $anonresponsestable->get_reponse_navigation_links($completedrecord);
 129  
 130      echo html_writer::start_div('response_navigation');
 131  
 132      $responsenavigation = [
 133          'col1content' => '',
 134          'col2content' => html_writer::link($returnurl, get_string('back'), ['class' => 'back_to_list']),
 135          'col3content' => '',
 136      ];
 137  
 138      if ($prevresponseurl) {
 139          $responsenavigation['col1content'] = html_writer::link($prevresponseurl, get_string('prev'), ['class' => 'prev_response']);
 140      }
 141  
 142      if ($nextresponseurl) {
 143          $responsenavigation['col3content'] = html_writer::link($nextresponseurl, get_string('next'), ['class' => 'next_response']);
 144      }
 145  
 146      echo $OUTPUT->render_from_template('core/columns-1to1to1', $responsenavigation);
 147      echo html_writer::end_div();
 148  
 149  } else {
 150      // Print the list of responses.
 151      $courseselectform->display();
 152  
 153      // Show non-anonymous responses (always retrieve them even if current feedback is anonymous).
 154      $totalrows = $responsestable->get_total_responses_count();
 155      if (!$feedbackstructure->is_anonymous() || $totalrows) {
 156          echo $OUTPUT->heading(get_string('non_anonymous_entries', 'feedback', $totalrows), 4);
 157          $responsestable->display();
 158      }
 159  
 160      // Show anonymous responses (always retrieve them even if current feedback is not anonymous).
 161      $feedbackstructure->shuffle_anonym_responses();
 162      $totalrows = $anonresponsestable->get_total_responses_count();
 163      if ($feedbackstructure->is_anonymous() || $totalrows) {
 164          echo $OUTPUT->heading(get_string('anonymous_entries', 'feedback', $totalrows), 4);
 165          $anonresponsestable->display();
 166      }
 167  
 168  }
 169  
 170  // Finish the page.
 171  echo $OUTPUT->footer();