1 |
efrain |
1 |
// This file is part of Moodle - http://moodle.org/
|
|
|
2 |
//
|
|
|
3 |
// Moodle is free software: you can redistribute it and/or modify
|
|
|
4 |
// it under the terms of the GNU General Public License as published by
|
|
|
5 |
// the Free Software Foundation, either version 3 of the License, or
|
|
|
6 |
// (at your option) any later version.
|
|
|
7 |
//
|
|
|
8 |
// Moodle is distributed in the hope that it will be useful,
|
|
|
9 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
10 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
11 |
// GNU General Public License for more details.
|
|
|
12 |
//
|
|
|
13 |
// You should have received a copy of the GNU General Public License
|
|
|
14 |
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
|
|
15 |
|
|
|
16 |
H5P._getLibraryPath = H5P.getLibraryPath;
|
|
|
17 |
H5P.getLibraryPath = function (library) {
|
|
|
18 |
if (H5PIntegration.moodleLibraryPaths) {
|
|
|
19 |
if (H5PIntegration.moodleLibraryPaths[library]) {
|
|
|
20 |
return H5PIntegration.moodleLibraryPaths[library];
|
|
|
21 |
}
|
|
|
22 |
}
|
|
|
23 |
return H5P._getLibraryPath(library);
|
|
|
24 |
};
|
|
|
25 |
H5P.findInstanceFromId = function (contentId) {
|
|
|
26 |
if (!contentId) {
|
|
|
27 |
return H5P.instances[0];
|
|
|
28 |
}
|
|
|
29 |
if (H5P.instances !== undefined) {
|
|
|
30 |
for (var i = 0; i < H5P.instances.length; i++) {
|
|
|
31 |
if (H5P.instances[i].contentId === contentId) {
|
|
|
32 |
return H5P.instances[i];
|
|
|
33 |
}
|
|
|
34 |
}
|
|
|
35 |
}
|
|
|
36 |
return undefined;
|
|
|
37 |
};
|
|
|
38 |
H5P.getXAPIStatements = function (contentId, statement) {
|
|
|
39 |
var statements = [];
|
|
|
40 |
var instance = H5P.findInstanceFromId(contentId);
|
|
|
41 |
if (!instance){
|
|
|
42 |
return statements;
|
|
|
43 |
}
|
|
|
44 |
if (instance.getXAPIData == undefined) {
|
|
|
45 |
var xAPIData = {
|
|
|
46 |
statement: statement
|
|
|
47 |
};
|
|
|
48 |
} else {
|
|
|
49 |
var xAPIData = instance.getXAPIData();
|
|
|
50 |
}
|
|
|
51 |
if (xAPIData.statement != undefined) {
|
|
|
52 |
statements.push(xAPIData.statement);
|
|
|
53 |
}
|
|
|
54 |
if (xAPIData.children != undefined) {
|
|
|
55 |
statements = statements.concat(xAPIData.children.map(a => a.statement));
|
|
|
56 |
}
|
|
|
57 |
return statements;
|
|
|
58 |
};
|
|
|
59 |
H5P.getMoodleComponent = function () {
|
|
|
60 |
if (H5PIntegration.moodleComponent) {
|
|
|
61 |
return H5PIntegration.moodleComponent;
|
|
|
62 |
}
|
|
|
63 |
return undefined;
|
|
|
64 |
};
|
|
|
65 |
|
|
|
66 |
/**
|
|
|
67 |
* Set the actor. (Moved to overrides due to MDL-69467)
|
|
|
68 |
*/
|
|
|
69 |
H5P.XAPIEvent.prototype.setActor = function () {
|
|
|
70 |
if (H5PIntegration.user !== undefined) {
|
|
|
71 |
this.data.statement.actor = {
|
|
|
72 |
'name': H5PIntegration.user.name,
|
|
|
73 |
'objectType': 'Agent'
|
|
|
74 |
};
|
|
|
75 |
if (H5PIntegration.user.id !== undefined) {
|
|
|
76 |
this.data.statement.actor.account = {
|
|
|
77 |
'name': H5PIntegration.user.id,
|
|
|
78 |
'homePage': H5PIntegration.siteUrl
|
|
|
79 |
}
|
|
|
80 |
} else if (H5PIntegration.user.mail !== undefined) {
|
|
|
81 |
this.data.statement.actor.mbox = 'mailto:' + H5PIntegration.user.mail;
|
|
|
82 |
}
|
|
|
83 |
} else {
|
|
|
84 |
var uuid;
|
|
|
85 |
try {
|
|
|
86 |
if (localStorage.H5PUserUUID) {
|
|
|
87 |
uuid = localStorage.H5PUserUUID;
|
|
|
88 |
} else {
|
|
|
89 |
uuid = H5P.createUUID();
|
|
|
90 |
localStorage.H5PUserUUID = uuid;
|
|
|
91 |
}
|
|
|
92 |
}
|
|
|
93 |
catch (err) {
|
|
|
94 |
// LocalStorage and Cookies are probably disabled. Do not track the user.
|
|
|
95 |
uuid = 'not-trackable-' + H5P.createUUID();
|
|
|
96 |
}
|
|
|
97 |
this.data.statement.actor = {
|
|
|
98 |
'account': {
|
|
|
99 |
'name': uuid,
|
|
|
100 |
'homePage': H5PIntegration.siteUrl
|
|
|
101 |
},
|
|
|
102 |
'objectType': 'Agent'
|
|
|
103 |
};
|
|
|
104 |
}
|
|
|
105 |
};
|
|
|
106 |
|
|
|
107 |
/**
|
|
|
108 |
* Get the actor.
|
|
|
109 |
*
|
|
|
110 |
* @returns {Object} The Actor object.
|
|
|
111 |
*/
|
|
|
112 |
H5P.getxAPIActor = function() {
|
|
|
113 |
var actor = null;
|
|
|
114 |
if (H5PIntegration.user !== undefined) {
|
|
|
115 |
actor = {
|
|
|
116 |
'name': H5PIntegration.user.name,
|
|
|
117 |
'objectType': 'Agent'
|
|
|
118 |
};
|
|
|
119 |
if (H5PIntegration.user.id !== undefined) {
|
|
|
120 |
actor.account = {
|
|
|
121 |
'name': H5PIntegration.user.id,
|
|
|
122 |
'homePage': H5PIntegration.siteUrl
|
|
|
123 |
};
|
|
|
124 |
} else if (H5PIntegration.user.mail !== undefined) {
|
|
|
125 |
actor.mbox = 'mailto:' + H5PIntegration.user.mail;
|
|
|
126 |
}
|
|
|
127 |
} else {
|
|
|
128 |
var uuid;
|
|
|
129 |
try {
|
|
|
130 |
if (localStorage.H5PUserUUID) {
|
|
|
131 |
uuid = localStorage.H5PUserUUID;
|
|
|
132 |
} else {
|
|
|
133 |
uuid = H5P.createUUID();
|
|
|
134 |
localStorage.H5PUserUUID = uuid;
|
|
|
135 |
}
|
|
|
136 |
} catch (err) {
|
|
|
137 |
// LocalStorage and Cookies are probably disabled. Do not track the user.
|
|
|
138 |
uuid = 'not-trackable-' + H5P.createUUID();
|
|
|
139 |
}
|
|
|
140 |
actor = {
|
|
|
141 |
'account': {
|
|
|
142 |
'name': uuid,
|
|
|
143 |
'homePage': H5PIntegration.siteUrl
|
|
|
144 |
},
|
|
|
145 |
'objectType': 'Agent'
|
|
|
146 |
};
|
|
|
147 |
}
|
|
|
148 |
return actor;
|
|
|
149 |
};
|
|
|
150 |
|
|
|
151 |
/**
|
|
|
152 |
* Creates requests for inserting, updating and deleting content user data.
|
|
|
153 |
* It overrides the contentUserDataAjax private method in h5p.js.
|
|
|
154 |
*
|
|
|
155 |
* @param {number} contentId What content to store the data for.
|
|
|
156 |
* @param {string} dataType Identifies the set of data for this content.
|
|
|
157 |
* @param {string} subContentId Identifies sub content
|
|
|
158 |
* @param {function} [done] Callback when ajax is done.
|
|
|
159 |
* @param {object} [data] To be stored for future use.
|
|
|
160 |
* @param {boolean} [preload=false] Data is loaded when content is loaded.
|
|
|
161 |
* @param {boolean} [invalidate=false] Data is invalidated when content changes.
|
|
|
162 |
* @param {boolean} [async=true]
|
|
|
163 |
*/
|
|
|
164 |
H5P.contentUserDataAjax = function(contentId, dataType, subContentId, done, data, preload, invalidate, async) {
|
|
|
165 |
var instance = H5P.findInstanceFromId(contentId);
|
|
|
166 |
if (instance !== undefined) {
|
|
|
167 |
var xAPIState = {
|
|
|
168 |
activityId: H5P.XAPIEvent.prototype.getContentXAPIId(instance),
|
|
|
169 |
stateId: dataType,
|
|
|
170 |
state: data
|
|
|
171 |
};
|
|
|
172 |
H5P.externalDispatcher.trigger('xAPIState', xAPIState);
|
|
|
173 |
}
|
|
|
174 |
};
|