Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.2.x will end 22 April 2024 (12 months).
  • Bug fixes for security issues in 4.2.x will end 7 October 2024 (18 months).
  • PHP version: minimum PHP 8.0.0 Note: minimum PHP version has increased since Moodle 4.1. PHP 8.1.x is supported too.
   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   * Contains class mod_h5pactivity\output\reportresults
  19   *
  20   * @package   mod_h5pactivity
  21   * @copyright 2020 Ferran Recio
  22   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  
  25  namespace mod_h5pactivity\output;
  26  
  27  defined('MOODLE_INTERNAL') || die();
  28  
  29  use mod_h5pactivity\local\attempt;
  30  use mod_h5pactivity\output\attempt as output_attempt;
  31  use mod_h5pactivity\output\result as output_result;
  32  use renderable;
  33  use templatable;
  34  use renderer_base;
  35  use stdClass;
  36  
  37  /**
  38   * Class to display the result report in mod_h5pactivity.
  39   *
  40   * @copyright 2020 Ferran Recio
  41   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  42   */
  43  class reportresults implements renderable, templatable {
  44  
  45      /** @var attempt the header attempt */
  46      public $attempt;
  47  
  48      /** @var stdClass user record */
  49      public $user;
  50  
  51      /** @var int courseid necesary to present user picture */
  52      public $courseid;
  53  
  54      /**
  55       * Constructor.
  56       *
  57       * @param attempt $attempt the current attempt
  58       * @param stdClass $user a user record
  59       * @param int $courseid course id
  60       */
  61      public function __construct(attempt $attempt, stdClass $user, int $courseid) {
  62          $this->attempt = $attempt;
  63          $this->user = $user;
  64          $this->courseid = $courseid;
  65      }
  66  
  67      /**
  68       * Export this data so it can be used as the context for a mustache template.
  69       *
  70       * @param renderer_base $output
  71       * @return stdClass
  72       */
  73      public function export_for_template(renderer_base $output) {
  74  
  75          $outputattempt = new output_attempt($this->attempt, $this->user, $this->courseid);
  76  
  77          $data = (object)[
  78              'attempt' => $outputattempt->export_for_template($output),
  79          ];
  80  
  81          $results = $this->attempt->get_results();
  82          $data->results = [];
  83          foreach ($results as $key => $result) {
  84              $outputresult = output_result::create_from_record($result);
  85              if ($outputresult) {
  86                  $data->results[] = $outputresult->export_for_template($output);
  87              }
  88          }
  89  
  90          return $data;
  91      }
  92  }