MDL-36855 scorm: update to api get_scorm_question_count()
[moodle.git] / mod / scorm / report / reportlib.php
CommitLineData
62b82cbc
AKA
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.
5e85f7b5
PS
19 * @package mod
20 * @subpackage scorm
21 * @author Ankit Kumar Agarwal
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
62b82cbc
AKA
23 */
24
b2614417
DM
25defined('MOODLE_INTERNAL') || die();
26
e46cef0b
AKA
27/* Generates and returns list of available Scorm report sub-plugins
28 *
29 * @param context context level to check caps against
30 * @return array list of valid reports present
31 */
62b82cbc 32function scorm_report_list($context) {
b2614417
DM
33 global $CFG;
34 static $reportlist;
35 if (!empty($reportlist)) {
62b82cbc
AKA
36 return $reportlist;
37 }
219f919c
AKA
38 $installed = get_plugin_list('scormreport');
39 foreach ($installed as $reportname => $notused) {
b2614417 40 $pluginfile = $CFG->dirroot.'/mod/scorm/report/'.$reportname.'/report.php';
62b82cbc
AKA
41 if (is_readable($pluginfile)) {
42 include_once($pluginfile);
43 $reportclassname = "scorm_{$reportname}_report";
44 if (class_exists($reportclassname)) {
b2614417
DM
45 $report = new $reportclassname();
46
47 if ($report->canview($context)) {
48 $reportlist[] = $reportname;
49 }
62b82cbc
AKA
50 }
51 }
52 }
b2614417 53 return $reportlist;
62b82cbc 54}
b2f5ce35
AKA
55/**
56 * Returns The maximum numbers of Questions associated with an Scorm Pack
3ab853fa
AKA
57 *
58 * @param int Scorm ID
b2f5ce35
AKA
59 * @return int an integer representing the question count
60 */
3ab853fa
AKA
61function get_scorm_question_count($scormid) {
62 global $DB;
63 $count = 0;
64 $params = array();
65 $select = "scormid = ? AND ";
66 $select .= $DB->sql_like("element", "?", false);
67 $params[] = $scormid;
68 $params[] = "cmi.interactions_%.id";
69 $rs = $DB->get_recordset_select("scorm_scoes_track", $select, $params, 'element');
70 $keywords = array("cmi.interactions_", ".id");
7f7e18c3
AA
71 if ($rs->valid()) {
72 // Done as interactions start at 0 (do only if we have something to report).
73 $count++;
74 foreach ($rs as $record) {
75 $num = trim(str_ireplace($keywords, '', $record->element));
76 if (is_numeric($num) && $num > $count) {
77 $count = $num;
78 }
c03d2b75
AKA
79 }
80 }
3ab853fa 81 $rs->close(); // closing recordset
c03d2b75
AKA
82 return $count;
83}
84