[ Index ]

PHP Cross Reference of moodle-2.8

title

Body

[close]

/mod/scorm/report/ -> userreportinteractions.php (source)

   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   * This page displays the user data from a single attempt
  19   *
  20   * @package mod_scorm
  21   * @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
  22   * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  
  25  require_once("../../../config.php");
  26  require_once($CFG->dirroot.'/mod/scorm/locallib.php');
  27  require_once($CFG->dirroot.'/mod/scorm/report/reportlib.php');
  28  require_once($CFG->libdir . '/tablelib.php');
  29  
  30  $id = required_param('id', PARAM_INT); // Course Module ID.
  31  $userid = required_param('user', PARAM_INT); // User ID.
  32  $attempt = optional_param('attempt', 1, PARAM_INT); // attempt number.
  33  $download = optional_param('download', '', PARAM_ALPHA);
  34  
  35  // Building the url to use for links.+ data details buildup.
  36  $url = new moodle_url('/mod/scorm/report/userreportinteractions.php', array('id' => $id,
  37      'user' => $userid,
  38      'attempt' => $attempt));
  39  
  40  $cm = get_coursemodule_from_id('scorm', $id, 0, false, MUST_EXIST);
  41  $course = get_course($cm->course);
  42  $scorm = $DB->get_record('scorm', array('id' => $cm->instance), '*', MUST_EXIST);
  43  $user = $DB->get_record('user', array('id' => $userid), user_picture::fields(), MUST_EXIST);
  44  // Get list of attempts this user has made.
  45  $attemptids = scorm_get_all_attempts($scorm->id, $userid);
  46  
  47  $PAGE->set_url($url);
  48  // END of url setting + data buildup.
  49  
  50  // Checking login +logging +getting context.
  51  require_login($course, false, $cm);
  52  $contextmodule = context_module::instance($cm->id);
  53  require_capability('mod/scorm:viewreport', $contextmodule);
  54  
  55  // Trigger a user interactions viewed event.
  56  $event = \mod_scorm\event\interactions_viewed::create(array(
  57      'context' => $contextmodule,
  58      'relateduserid' => $userid,
  59      'other' => array('attemptid' => $attempt, 'instanceid' => $scorm->id)
  60  ));
  61  $event->add_record_snapshot('course_modules', $cm);
  62  $event->add_record_snapshot('scorm', $scorm);
  63  $event->trigger();
  64  
  65  $trackdata = $DB->get_records('scorm_scoes_track', array('userid' => $user->id, 'scormid' => $scorm->id,
  66      'attempt' => $attempt));
  67  $usertrack = scorm_format_interactions($trackdata);
  68  
  69  $questioncount = get_scorm_question_count($scorm->id);
  70  
  71  $courseshortname = format_string($course->shortname, true,
  72      array('context' => context_course::instance($course->id)));
  73  $exportfilename = $courseshortname . '-' . format_string($scorm->name, true) . '-' . get_string('interactions', 'scorm');
  74  
  75  
  76  // Set up the table.
  77  $table = new flexible_table('mod-scorm-userreport-interactions');
  78  if (!$table->is_downloading($download, $exportfilename)) {
  79  
  80      // Print the page header.
  81      $strattempt = get_string('attempt', 'scorm');
  82      $strreport = get_string('report', 'scorm');
  83  
  84      $PAGE->set_title("$course->shortname: ".format_string($scorm->name));
  85      $PAGE->set_heading($course->fullname);
  86      $PAGE->navbar->add($strreport, new moodle_url('/mod/scorm/report.php', array('id' => $cm->id)));
  87  
  88      $PAGE->navbar->add(fullname($user). " - $strattempt $attempt");
  89  
  90      echo $OUTPUT->header();
  91      echo $OUTPUT->heading(format_string($scorm->name));
  92      // End of Print the page header.
  93      $currenttab = 'interactions';
  94      require($CFG->dirroot . '/mod/scorm/report/userreporttabs.php');
  95  
  96      // Printing user details.
  97      $output = $PAGE->get_renderer('mod_scorm');
  98      echo $output->view_user_heading($user, $course, $PAGE->url, $attempt, $attemptids);
  99  
 100  }
 101  $table->define_baseurl($PAGE->url);
 102  $table->define_columns(array('id', 'studentanswer', 'correctanswer', 'result', 'calcweight'));
 103  $table->define_headers(array(get_string('trackid', 'scorm'), get_string('response', 'scorm'),
 104      get_string('rightanswer', 'scorm'), get_string('result', 'scorm'),
 105      get_string('calculatedweight', 'scorm')));
 106  $table->set_attribute('class', 'generaltable generalbox boxaligncenter boxwidthwide');
 107  
 108  $table->show_download_buttons_at(array(TABLE_P_BOTTOM));
 109  $table->setup();
 110  
 111  for ($i = 0; $i < $questioncount; $i++) {
 112      $row = array();
 113      $element = 'cmi.interactions_'.$i.'.id';
 114      if (isset($usertrack->$element)) {
 115          $row[] = s($usertrack->$element);
 116  
 117          $element = 'cmi.interactions_'.$i.'.student_response';
 118          if (isset($usertrack->$element)) {
 119              $row[] = s($usertrack->$element);
 120          } else {
 121              $row[] = '&nbsp;';
 122          }
 123  
 124          $j = 0;
 125          $element = 'cmi.interactions_'.$i.'.correct_responses_'.$j.'.pattern';
 126          $rightans = '';
 127          if (isset($usertrack->$element)) {
 128              while (isset($usertrack->$element)) {
 129                  if ($j > 0) {
 130                      $rightans .= ',';
 131                  }
 132                  $rightans .= s($usertrack->$element);
 133                  $j++;
 134                  $element = 'cmi.interactions_'.$i.'.correct_responses_'.$j.'.pattern';
 135              }
 136              $row[] = $rightans;
 137          } else {
 138              $row[] = '&nbsp;';
 139          }
 140          $element = 'cmi.interactions_'.$i.'.result';
 141          $weighting = 'cmi.interactions_'.$i.'.weighting';
 142          if (isset($usertrack->$element)) {
 143              $row[] = s($usertrack->$element);
 144              if ($usertrack->$element == 'correct' &&
 145                  isset($usertrack->$weighting)) {
 146                  $row[] = s($usertrack->$weighting);
 147              } else {
 148                  $row[] = '0';
 149              }
 150          } else {
 151              $row[] = '&nbsp;';
 152          }
 153          $table->add_data($row);
 154      }
 155  }
 156  
 157  $table->finish_output();
 158  
 159  if (!$table->is_downloading()) {
 160      echo $OUTPUT->footer();
 161  }
 162  


Generated: Fri Nov 28 20:29:05 2014 Cross-referenced by PHPXref 0.7.1