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] [Versions 400 and 401] [Versions 400 and 402] [Versions 400 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 an instance of mod_h5pactivity.
  19   *
  20   * @package     mod_h5pactivity
  21   * @copyright   2020 Ferran Recio <ferran@moodle.com>
  22   * @license     http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  
  25  use mod_h5pactivity\local\manager;
  26  use mod_h5pactivity\event\report_viewed;
  27  
  28  require(__DIR__.'/../../config.php');
  29  require_once (__DIR__.'/lib.php');
  30  
  31  $userid = optional_param('userid', null, PARAM_INT);
  32  $attemptid = optional_param('attemptid', null, PARAM_INT);
  33  
  34  // Attempts have only the instance id information but system events
  35  // have only cmid. To prevent unnecesary db queries, this page accept both.
  36  $id = optional_param('id', null, PARAM_INT);
  37  if (empty($id)) {
  38      $a = required_param('a', PARAM_INT);
  39      list ($course, $cm) = get_course_and_cm_from_instance($a, 'h5pactivity');
  40  } else {
  41      list ($course, $cm) = get_course_and_cm_from_cmid($id, 'h5pactivity');
  42  }
  43  
  44  require_login($course, true, $cm);
  45  
  46  $currentgroup = groups_get_activity_group($cm, true);
  47  
  48  $manager = manager::create_from_coursemodule($cm);
  49  
  50  $report = $manager->get_report($userid, $attemptid, $currentgroup);
  51  if (!$report) {
  52      print_error('permissiondenied');
  53  }
  54  
  55  $user = $report->get_user();
  56  $attempt = $report->get_attempt();
  57  
  58  $moduleinstance = $manager->get_instance();
  59  
  60  $context = $manager->get_context();
  61  
  62  $params = ['a' => $cm->instance];
  63  if ($user) {
  64      $params['userid'] = $user->id;
  65  }
  66  if ($attempt) {
  67      $params['attemptid'] = $attempt->get_id();
  68  }
  69  $PAGE->set_url('/mod/h5pactivity/report.php', $params);
  70  
  71  // Trigger event.
  72  $other = [
  73      'instanceid' => $params['a'],
  74      'userid' => $params['userid'] ?? null,
  75      'attemptid' => $params['attemptid'] ?? null,
  76  ];
  77  $event = report_viewed::create([
  78      'objectid' => $moduleinstance->id,
  79      'context' => $context,
  80      'other' => $other,
  81  ]);
  82  $event->add_record_snapshot('course', $course);
  83  $event->add_record_snapshot('h5pactivity', $moduleinstance);
  84  $event->trigger();
  85  
  86  $shortname = format_string($course->shortname, true, ['context' => $context]);
  87  $pagetitle = strip_tags($shortname.': '.format_string($moduleinstance->name));
  88  $PAGE->set_title(format_string($pagetitle));
  89  $PAGE->activityheader->disable();
  90  
  91  $navbar = [];
  92  if ($manager->can_view_all_attempts()) {
  93      // Report navbar have 3 levels for teachers:
  94      // - Participants list
  95      // - Participant attempts list
  96      // - Individual attempt details.
  97      $nav = [get_string('attempts', 'mod_h5pactivity'), null];
  98      if ($user) {
  99          $nav[1] = new moodle_url('/mod/h5pactivity/report.php', ['a' => $cm->instance]);
 100          $navbar[] = $nav;
 101  
 102          $nav = [fullname($user), null];
 103          if ($attempt) {
 104              $nav[1] = new moodle_url('/mod/h5pactivity/report.php', ['a' => $cm->instance, 'userid' => $user->id]);
 105          }
 106      }
 107      $navbar[] = $nav;
 108  } else {
 109      // Report navbar have 2 levels for a regular participant:
 110      // - My attempts
 111      // - Individual attempt details.
 112      $nav = [get_string('myattempts', 'mod_h5pactivity'), null];
 113      if ($attempt) {
 114          $nav[1] = new moodle_url('/mod/h5pactivity/report.php', ['a' => $cm->instance]);
 115      }
 116      $navbar[] = $nav;
 117  
 118  }
 119  if ($attempt) {
 120      $navbar[] = [get_string('attempt_number', 'mod_h5pactivity', $attempt->get_attempt()), null];
 121  }
 122  foreach ($navbar as $nav) {
 123      $PAGE->navbar->add($nav[0], $nav[1]);
 124  }
 125  
 126  $PAGE->set_heading(format_string($course->fullname));
 127  $PAGE->set_context($context);
 128  
 129  echo $OUTPUT->header();
 130  
 131  groups_print_activity_menu($cm, $PAGE->url);
 132  
 133  echo html_writer::start_div('mt-4');
 134  echo $report->print();
 135  echo html_writer::end_div();
 136  
 137  echo $OUTPUT->footer();