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 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   * Returns an array of reports to which are currently readable.
  19   * @package    mod_scorm
  20   * @author     Ankit Kumar Agarwal
  21   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  22   */
  23  
  24  defined('MOODLE_INTERNAL') || die();
  25  
  26  /* Generates and returns list of available Scorm report sub-plugins
  27   *
  28   * @param context context level to check caps against
  29   * @return array list of valid reports present
  30   */
  31  function scorm_report_list($context) {
  32      global $CFG;
  33      static $reportlist;
  34      if (!empty($reportlist)) {
  35          return $reportlist;
  36      }
  37      $installed = core_component::get_plugin_list('scormreport');
  38      foreach ($installed as $reportname => $notused) {
  39  
  40          // Moodle 2.8+ style of autoloaded classes.
  41          $classname = "scormreport_$reportname\\report";
  42          if (class_exists($classname)) {
  43              $report = new $classname();
  44  
  45              if ($report->canview($context)) {
  46                  $reportlist[] = $reportname;
  47              }
  48              continue;
  49          }
  50  
  51          // Legacy style of naming classes.
  52          $pluginfile = $CFG->dirroot.'/mod/scorm/report/'.$reportname.'/report.php';
  53          if (is_readable($pluginfile)) {
  54              debugging("Please use autoloaded classnames for your plugin. Refer MDL-46469 for details", DEBUG_DEVELOPER);
  55              include_once($pluginfile);
  56              $reportclassname = "scorm_{$reportname}_report";
  57              if (class_exists($reportclassname)) {
  58                  $report = new $reportclassname();
  59  
  60                  if ($report->canview($context)) {
  61                      $reportlist[] = $reportname;
  62                  }
  63              }
  64          }
  65      }
  66      return $reportlist;
  67  }
  68  /**
  69   * Returns The maximum numbers of Questions associated with an Scorm Pack
  70   *
  71   * @param int Scorm ID
  72   * @return int an integer representing the question count
  73   */
  74  function get_scorm_question_count($scormid) {
  75      global $DB;
  76      $count = 0;
  77      $params = array();
  78      $select = "scormid = ? AND ";
  79      $select .= $DB->sql_like("element", "?", false);
  80      $params[] = $scormid;
  81      $params[] = "cmi.interactions_%.id";
  82      $rs = $DB->get_recordset_select("scorm_scoes_track", $select, $params, 'element');
  83      $keywords = array("cmi.interactions_", ".id");
  84      if ($rs->valid()) {
  85          foreach ($rs as $record) {
  86              $num = trim(str_ireplace($keywords, '', $record->element));
  87              if (is_numeric($num) && $num > $count) {
  88                  $count = $num;
  89              }
  90          }
  91          // Done as interactions start at 0 (do only if we have something to report).
  92          $count++;
  93      }
  94      $rs->close(); // Closing recordset.
  95      return $count;
  96  }