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.

Differences Between: [Versions 310 and 311] [Versions 310 and 400] [Versions 310 and 401] [Versions 310 and 402] [Versions 310 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   * shows an analysed view of a feedback on the mainsite
  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  $current_tab = 'analysis';
  29  
  30  $id = required_param('id', PARAM_INT);  //the POST dominated the GET
  31  $courseitemfilter = optional_param('courseitemfilter', '0', PARAM_INT);
  32  $courseitemfiltertyp = optional_param('courseitemfiltertyp', '0', PARAM_ALPHANUM);
  33  $courseid = optional_param('courseid', false, PARAM_INT);
  34  
  35  $url = new moodle_url('/mod/feedback/analysis_course.php', array('id'=>$id));
  36  navigation_node::override_active_url($url);
  37  if ($courseid !== false) {
  38      $url->param('courseid', $courseid);
  39  }
  40  if ($courseitemfilter !== '0') {
  41      $url->param('courseitemfilter', $courseitemfilter);
  42  }
  43  if ($courseitemfiltertyp !== '0') {
  44      $url->param('courseitemfiltertyp', $courseitemfiltertyp);
  45  }
  46  $PAGE->set_url($url);
  47  
  48  list($course, $cm) = get_course_and_cm_from_cmid($id, 'feedback');
  49  $context = context_module::instance($cm->id);
  50  
  51  require_course_login($course, true, $cm);
  52  
  53  $feedback = $PAGE->activityrecord;
  54  
  55  if (!($feedback->publish_stats OR has_capability('mod/feedback:viewreports', $context))) {
  56      print_error('error');
  57  }
  58  
  59  $feedbackstructure = new mod_feedback_structure($feedback, $PAGE->cm, $courseid);
  60  
  61  // Process course select form.
  62  $courseselectform = new mod_feedback_course_select_form($url, $feedbackstructure);
  63  if ($data = $courseselectform->get_data()) {
  64      redirect(new moodle_url($url, ['courseid' => $data->courseid]));
  65  }
  66  
  67  /// Print the page header
  68  $strfeedbacks = get_string("modulenameplural", "feedback");
  69  $strfeedback  = get_string("modulename", "feedback");
  70  
  71  $PAGE->set_heading($course->fullname);
  72  $PAGE->set_title($feedback->name);
  73  echo $OUTPUT->header();
  74  echo $OUTPUT->heading(format_string($feedback->name));
  75  
  76  /// print the tabs
  77  require ('tabs.php');
  78  
  79  //get the groupid
  80  //lstgroupid is the choosen id
  81  $mygroupid = false;
  82  
  83  $courseselectform->display();
  84  
  85  // Button "Export to excel".
  86  if (has_capability('mod/feedback:viewreports', $context) && $feedbackstructure->get_items()) {
  87      echo $OUTPUT->container_start('form-buttons');
  88      $aurl = new moodle_url('/mod/feedback/analysis_to_excel.php',
  89          ['sesskey' => sesskey(), 'id' => $id, 'courseid' => (int)$courseid]);
  90      echo $OUTPUT->single_button($aurl, get_string('export_to_excel', 'feedback'));
  91      echo $OUTPUT->container_end();
  92  }
  93  
  94  // Show the summary.
  95  $summary = new mod_feedback\output\summary($feedbackstructure);
  96  echo $OUTPUT->render_from_template('mod_feedback/summary', $summary->export_for_template($OUTPUT));
  97  
  98  // Get the items of the feedback.
  99  $items = $feedbackstructure->get_items(true);
 100  
 101  if ($courseitemfilter > 0) {
 102      $sumvalue = 'SUM(' . $DB->sql_cast_char2real('value', true) . ')';
 103      $sql = "SELECT fv.course_id, c.shortname, $sumvalue AS sumvalue, COUNT(value) as countvalue
 104              FROM {feedback_value} fv, {course} c, {feedback_item} fi
 105              WHERE fv.course_id = c.id AND fi.id = fv.item AND fi.typ = ? AND fv.item = ?
 106              GROUP BY course_id, shortname
 107              ORDER BY sumvalue desc";
 108  
 109      if ($courses = $DB->get_records_sql($sql, array($courseitemfiltertyp, $courseitemfilter))) {
 110          $item = $DB->get_record('feedback_item', array('id'=>$courseitemfilter));
 111          echo '<h4>'.$item->name.'</h4>';
 112          echo '<div class="clearfix">';
 113          echo '<table>';
 114          echo '<tr><th>Course</th><th>Average</th></tr>';
 115  
 116          foreach ($courses as $c) {
 117              $coursecontext = context_course::instance($c->course_id);
 118              $shortname = format_string($c->shortname, true, array('context' => $coursecontext));
 119  
 120              echo '<tr>';
 121              echo '<td>'.$shortname.'</td>';
 122              echo '<td align="right">';
 123              echo format_float(($c->sumvalue / $c->countvalue), 2);
 124              echo '</td>';
 125              echo '</tr>';
 126          }
 127          echo '</table>';
 128      } else {
 129          echo '<p>'.get_string('noresults').'</p>';
 130      }
 131      echo '<p><a href="analysis_course.php?id=' . $id . '">';
 132      echo get_string('back');
 133      echo '</a></p>';
 134  } else {
 135  
 136      // Print the items in an analysed form.
 137      foreach ($items as $item) {
 138          echo '<table class="analysis">';
 139          $itemobj = feedback_get_item_class($item->typ);
 140          $printnr = ($feedback->autonumbering && $item->itemnr) ? ($item->itemnr . '.') : '';
 141          $itemobj->print_analysed($item, $printnr, $mygroupid, $feedbackstructure->get_courseid());
 142          if (preg_match('/rated$/i', $item->typ)) {
 143              $url = new moodle_url('/mod/feedback/analysis_course.php', array('id' => $id,
 144                  'courseitemfilter' => $item->id, 'courseitemfiltertyp' => $item->typ));
 145              $anker = html_writer::link($url, get_string('sort_by_course', 'feedback'));
 146  
 147              echo '<tr><td colspan="2">'.$anker.'</td></tr>';
 148          }
 149          echo '</table>';
 150      }
 151  }
 152  
 153  echo $OUTPUT->footer();
 154