diff --git a/src/addon/mod/quiz/pages/player/player.html b/src/addon/mod/quiz/pages/player/player.html
index 77795828b..62b15934f 100644
--- a/src/addon/mod/quiz/pages/player/player.html
+++ b/src/addon/mod/quiz/pages/player/player.html
@@ -58,7 +58,7 @@
-
+
diff --git a/src/addon/mod/quiz/pages/review/review.html b/src/addon/mod/quiz/pages/review/review.html
index f7682f1b2..3dba297ac 100644
--- a/src/addon/mod/quiz/pages/review/review.html
+++ b/src/addon/mod/quiz/pages/review/review.html
@@ -75,7 +75,7 @@
-
+
diff --git a/src/addon/mod/quiz/providers/prefetch-handler.ts b/src/addon/mod/quiz/providers/prefetch-handler.ts
index d292dc958..780064c7d 100644
--- a/src/addon/mod/quiz/providers/prefetch-handler.ts
+++ b/src/addon/mod/quiz/providers/prefetch-handler.ts
@@ -409,7 +409,7 @@ export class AddonModQuizPrefetchHandler extends CoreCourseActivityPrefetchHandl
data.questions.forEach((question) => {
questionPromises.push(this.questionHelper.prefetchQuestionFiles(
- question, this.component, quiz.coursemodule, siteId));
+ question, this.component, quiz.coursemodule, siteId, attempt.uniqueid));
});
return Promise.all(questionPromises);
@@ -437,7 +437,7 @@ export class AddonModQuizPrefetchHandler extends CoreCourseActivityPrefetchHandl
data.questions.forEach((question) => {
questionPromises.push(this.questionHelper.prefetchQuestionFiles(
- question, this.component, quiz.coursemodule, siteId));
+ question, this.component, quiz.coursemodule, siteId, attempt.uniqueid));
});
return Promise.all(questionPromises);
diff --git a/src/addon/qtype/ddmarker/providers/handler.ts b/src/addon/qtype/ddmarker/providers/handler.ts
index aaf0c781f..38ecfd1ba 100644
--- a/src/addon/qtype/ddmarker/providers/handler.ts
+++ b/src/addon/qtype/ddmarker/providers/handler.ts
@@ -112,10 +112,11 @@ export class AddonQtypeDdMarkerHandler implements CoreQuestionHandler {
* Get the list of files that needs to be downloaded in addition to the files embedded in the HTML.
*
* @param {any} question Question.
+ * @param {number} usageId Usage ID.
* @return {string[]} List of URLs.
*/
- getAdditionalDownloadableFiles(question: any): string[] {
- this.questionHelper.extractQuestionScripts(question);
+ getAdditionalDownloadableFiles(question: any, usageId: number): string[] {
+ this.questionHelper.extractQuestionScripts(question, usageId);
if (question.amdArgs && typeof question.amdArgs[1] !== 'undefined') {
// Moodle 3.6+.
diff --git a/src/core/question/components/question/question.ts b/src/core/question/components/question/question.ts
index 8e0129760..fbb31b6cf 100644
--- a/src/core/question/components/question/question.ts
+++ b/src/core/question/components/question/question.ts
@@ -34,6 +34,7 @@ export class CoreQuestionComponent implements OnInit {
@Input() component: string; // The component the question belongs to.
@Input() componentId: number; // ID of the component the question belongs to.
@Input() attemptId: number; // Attempt ID.
+ @Input() usageId: number; // Usage ID.
@Input() offlineEnabled?: boolean | string; // Whether the question can be answered in offline.
@Output() buttonClicked: EventEmitter; // Will emit an event when a behaviour button is clicked.
@Output() onAbort: EventEmitter; // Will emit an event if the question should be aborted.
@@ -86,7 +87,7 @@ export class CoreQuestionComponent implements OnInit {
};
// Treat the question.
- this.questionHelper.extractQuestionScripts(this.question);
+ this.questionHelper.extractQuestionScripts(this.question, this.usageId);
// Handle question behaviour.
const behaviour = this.questionDelegate.getBehaviourForQuestion(this.question, this.question.preferredBehaviour);
diff --git a/src/core/question/providers/delegate.ts b/src/core/question/providers/delegate.ts
index 2d3451beb..3dc33326d 100644
--- a/src/core/question/providers/delegate.ts
+++ b/src/core/question/providers/delegate.ts
@@ -112,9 +112,10 @@ export interface CoreQuestionHandler extends CoreDelegateHandler {
* Get the list of files that needs to be downloaded in addition to the files embedded in the HTML.
*
* @param {any} question Question.
+ * @param {number} usageId Usage ID.
* @return {string[]} List of URLs.
*/
- getAdditionalDownloadableFiles?(question: any): string[];
+ getAdditionalDownloadableFiles?(question: any, usageId: number): string[];
}
/**
@@ -274,11 +275,12 @@ export class CoreQuestionDelegate extends CoreDelegate {
* Get the list of files that needs to be downloaded in addition to the files embedded in the HTML.
*
* @param {any} question Question.
+ * @param {number} usageId Usage ID.
* @return {string[]} List of URLs.
*/
- getAdditionalDownloadableFiles(question: any): string[] {
+ getAdditionalDownloadableFiles(question: any, usageId: number): string[] {
const type = this.getTypeName(question);
- return this.executeFunctionOnEnabled(type, 'getAdditionalDownloadableFiles', [question]) || [];
+ return this.executeFunctionOnEnabled(type, 'getAdditionalDownloadableFiles', [question, usageId]) || [];
}
}
diff --git a/src/core/question/providers/helper.ts b/src/core/question/providers/helper.ts
index cb0fe8eb1..01f85c86e 100644
--- a/src/core/question/providers/helper.ts
+++ b/src/core/question/providers/helper.ts
@@ -239,8 +239,9 @@ export class CoreQuestionHelperProvider {
* It will also search for init_question functions of the question type and add the object to an 'initObjects' property.
*
* @param {any} question Question.
+ * @param {number} usageId Usage ID.
*/
- extractQuestionScripts(question: any): void {
+ extractQuestionScripts(question: any, usageId: number): void {
question.scriptsCode = '';
question.initObjects = null;
question.amdArgs = null;
@@ -272,7 +273,8 @@ export class CoreQuestionHelperProvider {
}
const amdRegExp = new RegExp('require\\(\\["qtype_' + question.type + '/question"\\], ' +
- 'function\\(amd\\) \\{ amd\.init\\(("q' + question.slot + '".*?)\\); \\}\\);;', 'm');
+ 'function\\(amd\\) \\{ amd\.init\\(("(q|question-' + usageId + '-)' + question.slot +
+ '".*?)\\); \\}\\);;', 'm');
const amdMatch = match.match(amdRegExp);
if (amdMatch) {
// Try to convert the arguments to an array and add them to the question.
@@ -506,9 +508,11 @@ export class CoreQuestionHelperProvider {
* @param {string} [component] The component to link the files to. If not defined, question component.
* @param {string|number} [componentId] An ID to use in conjunction with the component. If not defined, question ID.
* @param {string} [siteId] Site ID. If not defined, current site.
+ * @param {number} [usageId] Usage ID. Required in Moodle 3.7+.
* @return {Promise} Promise resolved when all the files have been downloaded.
*/
- prefetchQuestionFiles(question: any, component?: string, componentId?: string | number, siteId?: string): Promise {
+ prefetchQuestionFiles(question: any, component?: string, componentId?: string | number, siteId?: string, usageId?: number)
+ : Promise {
const urls = this.domUtils.extractDownloadableFilesFromHtml(question.html);
if (!component) {
@@ -516,7 +520,7 @@ export class CoreQuestionHelperProvider {
componentId = question.id;
}
- urls.push(...this.questionDelegate.getAdditionalDownloadableFiles(question));
+ urls.push(...this.questionDelegate.getAdditionalDownloadableFiles(question, usageId));
return this.sitesProvider.getSite(siteId).then((site) => {
const promises = [];