1 |
efrain |
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 |
$sql = "SELECT DISTINCT e.id, e.element
|
|
|
79 |
FROM {scorm_element} e
|
|
|
80 |
JOIN {scorm_scoes_value} v ON e.id = v.elementid
|
|
|
81 |
JOIN {scorm_attempt} a ON a.id = v.attemptid
|
|
|
82 |
WHERE a.scormid = ? AND ". $DB->sql_like("element", "?", false) .
|
|
|
83 |
" ORDER BY e.element";
|
|
|
84 |
|
|
|
85 |
$params[] = $scormid;
|
|
|
86 |
$params[] = "cmi.interactions_%.id";
|
|
|
87 |
$rs = $DB->get_recordset_sql($sql, $params);
|
|
|
88 |
$keywords = array("cmi.interactions_", ".id");
|
|
|
89 |
if ($rs->valid()) {
|
|
|
90 |
foreach ($rs as $record) {
|
|
|
91 |
$num = trim(str_ireplace($keywords, '', $record->element));
|
|
|
92 |
if (is_numeric($num) && $num > $count) {
|
|
|
93 |
$count = $num;
|
|
|
94 |
}
|
|
|
95 |
}
|
|
|
96 |
// Done as interactions start at 0 (do only if we have something to report).
|
|
|
97 |
$count++;
|
|
|
98 |
}
|
|
|
99 |
$rs->close(); // Closing recordset.
|
|
|
100 |
return $count;
|
|
|
101 |
}
|