Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.3.x will end 7 October 2024 (12 months).
  • Bug fixes for security issues in 4.3.x will end 21 April 2025 (18 months).
  • PHP version: minimum PHP 8.0.0 Note: minimum PHP version has increased since Moodle 4.1. PHP 8.2.x is supported too.

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

   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   * the first page to view the feedback
  19   *
  20   * @author Andreas Grabs
  21   * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
  22   * @package mod_feedback
  23   */
  24  require_once(__DIR__ . '/../../config.php');
  25  require_once($CFG->dirroot . '/mod/feedback/lib.php');
  26  
  27  $id = required_param('id', PARAM_INT);
  28  $courseid = optional_param('courseid', false, PARAM_INT);
  29  
  30  $current_tab = 'view';
  31  
  32  list($course, $cm) = get_course_and_cm_from_cmid($id, 'feedback');
  33  require_course_login($course, true, $cm);
  34  $feedback = $PAGE->activityrecord;
  35  
  36  $feedbackcompletion = new mod_feedback_completion($feedback, $cm, $courseid);
  37  
  38  $context = context_module::instance($cm->id);
  39  
  40  if ($course->id == SITEID) {
  41      $PAGE->set_pagelayout('incourse');
  42  }
  43  $PAGE->set_url('/mod/feedback/view.php', array('id' => $cm->id));
  44  $PAGE->set_title($feedback->name);
  45  $PAGE->set_heading($course->fullname);
  46  $PAGE->add_body_class('limitedwidth');
  47  
  48  // Check access to the given courseid.
  49  if ($courseid AND $courseid != SITEID) {
  50      require_course_login(get_course($courseid)); // This overwrites the object $COURSE .
  51  }
  52  
  53  // Check whether the feedback is mapped to the given courseid.
  54  if (!has_capability('mod/feedback:edititems', $context) &&
  55          !$feedbackcompletion->check_course_is_mapped()) {
  56      echo $OUTPUT->header();
  57      echo $OUTPUT->notification(get_string('cannotaccess', 'mod_feedback'));
  58      echo $OUTPUT->footer();
  59      exit;
  60  }
  61  
  62  $viewcompletion = $feedbackcompletion->is_open() && $feedbackcompletion->can_complete() && $feedbackcompletion->can_submit();
  63  $actionbar = new \mod_feedback\output\standard_action_bar(
  64      $cm->id,
  65      $viewcompletion,
  66      $feedbackcompletion->get_resume_page(),
  67      $courseid
  68  );
  69  
  70  /** @var \mod_feedback\output\renderer $renderer */
  71  $renderer = $PAGE->get_renderer('mod_feedback');
  72  
  73  // Trigger module viewed event.
  74  $feedbackcompletion->trigger_module_viewed();
  75  
  76  /// Print the main part of the page
  77  ///////////////////////////////////////////////////////////////////////////
  78  ///////////////////////////////////////////////////////////////////////////
  79  ///////////////////////////////////////////////////////////////////////////
  80  
  81  $previewimg = $OUTPUT->pix_icon('t/preview', get_string('preview'));
  82  $previewlnk = new moodle_url('/mod/feedback/print.php', array('id' => $id));
  83  if ($courseid) {
  84      $previewlnk->param('courseid', $courseid);
  85  }
  86  $preview = html_writer::link($previewlnk, $previewimg);
  87  
  88  $PAGE->activityheader->set_description("");
  89  
  90  // Print the page header.
  91  echo $OUTPUT->header();
  92  
  93  // Show description.
  94  echo $OUTPUT->box_start('generalbox feedback_description');
  95  $options = (object)array('noclean' => true);
  96  echo format_module_intro('feedback', $feedback, $cm->id);
  97  echo $renderer->main_action_bar($actionbar);
  98  echo $OUTPUT->box_end();
  99  
 100  //show some infos to the feedback
 101  if (has_capability('mod/feedback:edititems', $context)) {
 102  
 103      echo $OUTPUT->heading(get_string('overview', 'feedback'), 3);
 104  
 105      //get the groupid
 106      $groupselect = groups_print_activity_menu($cm, $CFG->wwwroot.'/mod/feedback/view.php?id='.$cm->id, true);
 107      $mygroupid = groups_get_activity_group($cm);
 108  
 109      echo $groupselect.'<div class="clearer">&nbsp;</div>';
 110      $summary = new mod_feedback\output\summary($feedbackcompletion, $mygroupid);
 111      echo $OUTPUT->render_from_template('mod_feedback/summary', $summary->export_for_template($OUTPUT));
 112  
 113      if ($pageaftersubmit = $feedbackcompletion->page_after_submit()) {
 114          echo $OUTPUT->heading(get_string("page_after_submit", "feedback"), 3);
 115          echo $OUTPUT->box($pageaftersubmit, 'generalbox feedback_after_submit');
 116      }
 117  }
 118  
 119  if (!$PAGE->has_secondary_navigation()) {
 120      if (!has_capability('mod/feedback:viewreports', $context) &&
 121          $feedbackcompletion->can_view_analysis()) {
 122          $analysisurl = new moodle_url('/mod/feedback/analysis.php', array('id' => $id));
 123          echo '<div class="mdl-align"><a href="' . $analysisurl->out() . '">';
 124          echo get_string('completed_feedbacks', 'feedback') . '</a>';
 125          echo '</div>';
 126      }
 127  
 128      if (has_capability('mod/feedback:mapcourse', $context) && $feedback->course == SITEID) {
 129          echo $OUTPUT->box_start('generalbox feedback_mapped_courses');
 130          echo $OUTPUT->heading(get_string("mappedcourses", "feedback"), 3);
 131          echo '<p>' . get_string('mapcourse_help', 'feedback') . '</p>';
 132          $mapurl = new moodle_url('/mod/feedback/mapcourse.php', array('id' => $id));
 133          echo '<p class="mdl-align">' . html_writer::link($mapurl, get_string('mapcourses', 'feedback')) . '</p>';
 134          echo $OUTPUT->box_end();
 135      }
 136  }
 137  
 138  if ($feedbackcompletion->can_complete()) {
 139      echo $OUTPUT->box_start('generalbox boxaligncenter');
 140      if (!$feedbackcompletion->is_open()) {
 141          // Feedback is not yet open or is already closed.
 142          echo $OUTPUT->notification(get_string('feedback_is_not_open', 'feedback'));
 143          echo $OUTPUT->continue_button(course_get_url($courseid ?: $course->id));
 144      } else if (!$feedbackcompletion->can_submit()) {
 145          // Feedback was already submitted.
 146          echo $OUTPUT->notification(get_string('this_feedback_is_already_submitted', 'feedback'));
 147          $OUTPUT->continue_button(course_get_url($courseid ?: $course->id));
 148      }
 149      echo $OUTPUT->box_end();
 150  }
 151  
 152  echo $OUTPUT->footer();