Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.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  namespace mod_bigbluebuttonbn\local\helpers;
  17  
  18  use cm_info;
  19  use mod_bigbluebuttonbn\instance;
  20  use mod_bigbluebuttonbn\logger;
  21  use stdClass;
  22  
  23  /**
  24   * Utility class for all user information
  25   *
  26   * Used mainly in user_outline and user_complete
  27   *
  28   * @package mod_bigbluebuttonbn
  29   * @copyright 2022 onwards, Blindside Networks Inc
  30   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  31   * @author    Laurent David  (laurent [at] call-learning [dt] fr)
  32   */
  33  class user_info {
  34      /**
  35       * Event to watch for.
  36       */
  37      const EVENT_TO_WATCH = [
  38          'join' => logger::EVENT_JOIN,
  39          'play_recording' => logger::EVENT_PLAYED
  40      ];
  41  
  42      /**
  43       * Get user outline and complete info
  44       *
  45       * @param stdClass $course
  46       * @param stdClass $user
  47       * @param cm_info $mod
  48       * @return array[] an array of infos and timestamps (latest timestamp)
  49       */
  50      public static function get_user_info_outline(stdClass $course, stdClass $user, cm_info $mod): array {
  51          $completion = new \completion_info($course);
  52          $cdata = $completion->get_data($mod, false, $user->id);
  53          $logtimestamps = [];
  54          $infos = [];
  55          if (!empty($cdata->viewed) && $cdata->viewed) {
  56              $infos[] = get_string('report_room_view', 'mod_bigbluebuttonbn');
  57              $logtimestamps[] = $cdata->timemodified;
  58          }
  59          $instance = instance::get_from_cmid($mod->id);
  60          foreach (self::EVENT_TO_WATCH as $eventtype => $logtype) {
  61              $logs = logger::get_user_completion_logs($instance, $user->id, [$logtype]);
  62              if ($logs) {
  63                  $infos[] = get_string("report_{$eventtype}_info", 'mod_bigbluebuttonbn', count($logs));
  64                  $latesttime = array_reduce($logs,
  65                      function($acc, $log) {
  66                          return ($acc > $log->timecreated) ? $acc : $log->timecreated;
  67                      }, 0);
  68                  $logtimestamps[] = $latesttime;
  69              }
  70          }
  71          return [$infos, $logtimestamps];
  72      }
  73  }