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 310 and 311] [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 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  
  90  $navbar = [];
  91  if ($manager->can_view_all_attempts()) {
  92      // Report navbar have 3 levels for teachers:
  93      // - Participants list
  94      // - Participant attempts list
  95      // - Individual attempt details.
  96      $nav = [get_string('attempts', 'mod_h5pactivity'), null];
  97      if ($user) {
  98          $nav[1] = new moodle_url('/mod/h5pactivity/report.php', ['a' => $cm->instance]);
  99          $navbar[] = $nav;
 100  
 101          $nav = [fullname($user), null];
 102          if ($attempt) {
 103              $nav[1] = new moodle_url('/mod/h5pactivity/report.php', ['a' => $cm->instance, 'userid' => $user->id]);
 104          }
 105      }
 106      $navbar[] = $nav;
 107  } else {
 108      // Report navbar have 2 levels for a regular participant:
 109      // - My attempts
 110      // - Individual attempt details.
 111      $nav = [get_string('myattempts', 'mod_h5pactivity'), null];
 112      if ($attempt) {
 113          $nav[1] = new moodle_url('/mod/h5pactivity/report.php', ['a' => $cm->instance]);
 114      }
 115      $navbar[] = $nav;
 116  
 117  }
 118  if ($attempt) {
 119      $navbar[] = [get_string('attempt_number', 'mod_h5pactivity', $attempt->get_attempt()), null];
 120  }
 121  foreach ($navbar as $nav) {
 122      $PAGE->navbar->add($nav[0], $nav[1]);
 123  }
 124  
 125  $PAGE->set_heading(format_string($course->fullname));
 126  $PAGE->set_context($context);
 127  
 128  echo $OUTPUT->header();
 129  
 130  groups_print_activity_menu($cm, $PAGE->url);
 131  
 132  echo $report->print();
 133  
 134  echo $OUTPUT->footer();