Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.11.x will end 14 Nov 2022 (12 months plus 6 months extension).
  • Bug fixes for security issues in 3.11.x will end 13 Nov 2023 (18 months plus 12 months extension).
  • PHP version: minimum PHP 7.3.0 Note: minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is supported too.

Differences Between: [Versions 311 and 400] [Versions 311 and 401] [Versions 311 and 402] [Versions 311 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   * prints the overview of all feedbacks included into the current course
  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  $id = required_param('id', PARAM_INT);
  29  
  30  $url = new moodle_url('/mod/feedback/index.php', array('id'=>$id));
  31  
  32  $PAGE->set_url($url);
  33  
  34  if (!$course = $DB->get_record('course', array('id'=>$id))) {
  35      print_error('invalidcourseid');
  36  }
  37  
  38  $context = context_course::instance($course->id);
  39  
  40  require_login($course);
  41  $PAGE->set_pagelayout('incourse');
  42  
  43  // Trigger instances list viewed event.
  44  $event = \mod_feedback\event\course_module_instance_list_viewed::create(array('context' => $context));
  45  $event->add_record_snapshot('course', $course);
  46  $event->trigger();
  47  
  48  /// Print the page header
  49  $strfeedbacks = get_string("modulenameplural", "feedback");
  50  $strfeedback  = get_string("modulename", "feedback");
  51  
  52  $PAGE->navbar->add($strfeedbacks);
  53  $PAGE->set_heading($course->fullname);
  54  $PAGE->set_title(get_string('modulename', 'feedback').' '.get_string('activities'));
  55  echo $OUTPUT->header();
  56  echo $OUTPUT->heading($strfeedbacks);
  57  
  58  /// Get all the appropriate data
  59  
  60  if (! $feedbacks = get_all_instances_in_course("feedback", $course)) {
  61      $url = new moodle_url('/course/view.php', array('id'=>$course->id));
  62      notice(get_string('thereareno', 'moodle', $strfeedbacks), $url);
  63      die;
  64  }
  65  
  66  $usesections = course_format_uses_sections($course->format);
  67  
  68  /// Print the list of instances (your module will probably extend this)
  69  
  70  $timenow = time();
  71  $strname  = get_string("name");
  72  $strresponses = get_string('responses', 'feedback');
  73  
  74  $table = new html_table();
  75  
  76  if ($usesections) {
  77      $strsectionname = get_string('sectionname', 'format_'.$course->format);
  78      if (has_capability('mod/feedback:viewreports', $context)) {
  79          $table->head  = array ($strsectionname, $strname, $strresponses);
  80          $table->align = array ("center", "left", 'center');
  81      } else {
  82          $table->head  = array ($strsectionname, $strname);
  83          $table->align = array ("center", "left");
  84      }
  85  } else {
  86      if (has_capability('mod/feedback:viewreports', $context)) {
  87          $table->head  = array ($strname, $strresponses);
  88          $table->align = array ("left", "center");
  89      } else {
  90          $table->head  = array ($strname);
  91          $table->align = array ("left");
  92      }
  93  }
  94  
  95  
  96  foreach ($feedbacks as $feedback) {
  97      //get the responses of each feedback
  98      $viewurl = new moodle_url('/mod/feedback/view.php', array('id'=>$feedback->coursemodule));
  99  
 100      if (has_capability('mod/feedback:viewreports', $context)) {
 101          $completed_feedback_count = intval(feedback_get_completeds_group_count($feedback));
 102      }
 103  
 104      $dimmedclass = $feedback->visible ? '' : 'class="dimmed"';
 105      $link = '<a '.$dimmedclass.' href="'.$viewurl->out().'">'.$feedback->name.'</a>';
 106  
 107      if ($usesections) {
 108          $tabledata = array (get_section_name($course, $feedback->section), $link);
 109      } else {
 110          $tabledata = array ($link);
 111      }
 112      if (has_capability('mod/feedback:viewreports', $context)) {
 113          $tabledata[] = $completed_feedback_count;
 114      }
 115  
 116      $table->data[] = $tabledata;
 117  
 118  }
 119  
 120  echo "<br />";
 121  
 122  echo html_writer::table($table);
 123  
 124  /// Finish the page
 125  
 126  echo $OUTPUT->footer();
 127