-
Notifications
You must be signed in to change notification settings - Fork 17
/
courseexit.php
executable file
·100 lines (80 loc) · 4.54 KB
/
courseexit.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<?php
/*
* Copyright 2011 Rustici Software.
*
* This file is part of the SCORM Cloud Module for Moodle.
* https://github.com/RusticiSoftware/SCORMCloud_MoodleModule
* http://scorm.com/moodle/
*
* The SCORM Cloud Module is free software: you can redistribute it and/or
* modify it under the terms of the GNU General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* The SCORM Cloud Module is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with the SCORM Cloud Module. If not, see <http://www.gnu.org/licenses/>.
*/
require_once("../../config.php");
require_once($CFG->dirroot.'/lib/datalib.php');
require_once($CFG->dirroot.'/lib/accesslib.php');
require_once("locallib.php");
require_once('SCORMCloud_PHPLibrary/ScormEngineService.php');
require_once('SCORMCloud_PHPLibrary/ServiceRequest.php');
require_once('SCORMCloud_PHPLibrary/CourseData.php');
global $log;
$regid = optional_param("id", null, PARAM_ALPHANUM);
if ($regid != null) {
$log->logDebug('In courseexit.php, received regid ' . $regid);
if ($reg = $DB->get_record("scormcloud_registrations", array('regid' => $regid))) {
$log->logDebug('Found scormcloud_registration for regid ' . $regid);
if ($scormcloud = $DB->get_record("scormcloud", array('id' => $reg->scormcloudid))) {
$log->logDebug('Found scormcloud record for id ' . $reg->scormcloudid);
if (scormcloud_hascapabilitytolaunch($scormcloud->course) && $USER->id == $reg->userid) {
// Get the results from the cloud.
$scormservice = scormcloud_get_service();
$regservice = $scormservice->getRegistrationService();
$resultsxml = $regservice->GetRegistrationResult($regid, 0, 'xml');
$results = simplexml_load_string($resultsxml);
$score = $results->registrationreport->score;
if ($score == 'unknown') {
$score = 0;
}
$log->logDebug('Updating Moodle gradebook ' . $reg->userid . ' - ' . $scormcloud->course . ' - ' . $score);
if (scormcloud_grade_item_update($reg->userid, $reg->scormcloudid, $score)) {
$log->logInfo('Updated Moodle gradebook for course ' . $scormcloud->course);
} else {
$log->logWarn('Error updating Moodle gradebook for course ' . $scormcloud->course . '. Retrying.');
if (scormcloud_grade_item_update($reg->userid, $reg->scormcloudid, $score)) {
$log->logInfo('Updated Moodle gradebook for course ' . $scormcloud->course . ' after successful retry.');
} else {
$log->logError('Second attempt to update Moodle gradebook for course ' . $scormcloud->course . ' failed.');
}
}
$log->logDebug('Updating local scormcloud_registrations.');
$log->logDebug('registrationreport->complete = ' . $results->registrationreport->complete);
$reg->completion = scormcloud_getcomp($results->registrationreport->complete);
$log->logDebug('registrationreport->sucess = ' . $results->registrationreport->success);
$reg->satisfaction = scormcloud_getsat($results->registrationreport->success);
$reg->totaltime = (int)$results->registrationreport->totaltime;
$reg->score = (int)$results->registrationreport->score;
if ($result = $DB->update_record('scormcloud_registrations', $reg)) {
$log->logInfo('Updated scormcloud_registration.');
} else {
$log->logError('Failed to update scormcloud_registration.');
}
}
}
} else {
$log->logError('Failed to retrieve scormcloud_registration for regid ' . $regid . '.');
}
echo '<h2>Saving results...</h2>';
echo '<script>setTimeout("window.opener.parent.location = window.opener.parent.location;window.close();", 5000);</script>';
} else {
echo '<h2>Please wait while the course exits</h2>';
echo '<script>setInterval("window.opener.parent.location = window.opener.parent.location;window.close();", 500);</script>';
}