forked from CIT/Vmeda.Online
		
	MOBILE-2998 quiz: Fix drag and drop in Moodle 3.7
This commit is contained in:
		
							parent
							
								
									265f4a40f4
								
							
						
					
					
						commit
						f746b28dfe
					
				| @ -58,7 +58,7 @@ | |||||||
|                         </ion-note> |                         </ion-note> | ||||||
|                     </ion-item-divider> |                     </ion-item-divider> | ||||||
|                     <!-- Body of the question. --> |                     <!-- Body of the question. --> | ||||||
|                     <core-question text-wrap [question]="question" [component]="component" [componentId]="quiz.coursemodule" [attemptId]="attempt.id" [offlineEnabled]="offline" (onAbort)="abortQuiz()" (buttonClicked)="behaviourButtonClicked($event)"></core-question> |                     <core-question text-wrap [question]="question" [component]="component" [componentId]="quiz.coursemodule" [attemptId]="attempt.id" [usageId]="attempt.uniqueid" [offlineEnabled]="offline" (onAbort)="abortQuiz()" (buttonClicked)="behaviourButtonClicked($event)"></core-question> | ||||||
|                 </ion-card> |                 </ion-card> | ||||||
|             </div> |             </div> | ||||||
|         </form> |         </form> | ||||||
|  | |||||||
| @ -75,7 +75,7 @@ | |||||||
|                         </ion-note> |                         </ion-note> | ||||||
|                     </ion-item-divider> |                     </ion-item-divider> | ||||||
|                     <!-- Body of the question. --> |                     <!-- Body of the question. --> | ||||||
|                     <core-question text-wrap [question]="question" [component]="component" [componentId]="componentId" [attemptId]="attempt.id" [offlineEnabled]="false"></core-question> |                     <core-question text-wrap [question]="question" [component]="component" [componentId]="componentId" [attemptId]="attempt.id" [usageId]="attempt.uniqueid" [offlineEnabled]="false"></core-question> | ||||||
|                 </ion-card> |                 </ion-card> | ||||||
|             </div> |             </div> | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -409,7 +409,7 @@ export class AddonModQuizPrefetchHandler extends CoreCourseActivityPrefetchHandl | |||||||
| 
 | 
 | ||||||
|                 data.questions.forEach((question) => { |                 data.questions.forEach((question) => { | ||||||
|                     questionPromises.push(this.questionHelper.prefetchQuestionFiles( |                     questionPromises.push(this.questionHelper.prefetchQuestionFiles( | ||||||
|                             question, this.component, quiz.coursemodule, siteId)); |                             question, this.component, quiz.coursemodule, siteId, attempt.uniqueid)); | ||||||
|                 }); |                 }); | ||||||
| 
 | 
 | ||||||
|                 return Promise.all(questionPromises); |                 return Promise.all(questionPromises); | ||||||
| @ -437,7 +437,7 @@ export class AddonModQuizPrefetchHandler extends CoreCourseActivityPrefetchHandl | |||||||
| 
 | 
 | ||||||
|                         data.questions.forEach((question) => { |                         data.questions.forEach((question) => { | ||||||
|                             questionPromises.push(this.questionHelper.prefetchQuestionFiles( |                             questionPromises.push(this.questionHelper.prefetchQuestionFiles( | ||||||
|                                     question, this.component, quiz.coursemodule, siteId)); |                                     question, this.component, quiz.coursemodule, siteId, attempt.uniqueid)); | ||||||
|                         }); |                         }); | ||||||
| 
 | 
 | ||||||
|                         return Promise.all(questionPromises); |                         return Promise.all(questionPromises); | ||||||
|  | |||||||
| @ -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. |      * Get the list of files that needs to be downloaded in addition to the files embedded in the HTML. | ||||||
|      * |      * | ||||||
|      * @param {any} question Question. |      * @param {any} question Question. | ||||||
|  |      * @param {number} usageId Usage ID. | ||||||
|      * @return {string[]} List of URLs. |      * @return {string[]} List of URLs. | ||||||
|      */ |      */ | ||||||
|     getAdditionalDownloadableFiles(question: any): string[] { |     getAdditionalDownloadableFiles(question: any, usageId: number): string[] { | ||||||
|         this.questionHelper.extractQuestionScripts(question); |         this.questionHelper.extractQuestionScripts(question, usageId); | ||||||
| 
 | 
 | ||||||
|         if (question.amdArgs && typeof question.amdArgs[1] !== 'undefined') { |         if (question.amdArgs && typeof question.amdArgs[1] !== 'undefined') { | ||||||
|             // Moodle 3.6+.
 |             // Moodle 3.6+.
 | ||||||
|  | |||||||
| @ -34,6 +34,7 @@ export class CoreQuestionComponent implements OnInit { | |||||||
|     @Input() component: string; // The component the question belongs to.
 |     @Input() component: string; // The component the question belongs to.
 | ||||||
|     @Input() componentId: number; // ID of the component the question belongs to.
 |     @Input() componentId: number; // ID of the component the question belongs to.
 | ||||||
|     @Input() attemptId: number; // Attempt ID.
 |     @Input() attemptId: number; // Attempt ID.
 | ||||||
|  |     @Input() usageId: number; // Usage ID.
 | ||||||
|     @Input() offlineEnabled?: boolean | string; // Whether the question can be answered in offline.
 |     @Input() offlineEnabled?: boolean | string; // Whether the question can be answered in offline.
 | ||||||
|     @Output() buttonClicked: EventEmitter<any>; // Will emit an event when a behaviour button is clicked.
 |     @Output() buttonClicked: EventEmitter<any>; // Will emit an event when a behaviour button is clicked.
 | ||||||
|     @Output() onAbort: EventEmitter<void>; // Will emit an event if the question should be aborted.
 |     @Output() onAbort: EventEmitter<void>; // Will emit an event if the question should be aborted.
 | ||||||
| @ -86,7 +87,7 @@ export class CoreQuestionComponent implements OnInit { | |||||||
|                 }; |                 }; | ||||||
| 
 | 
 | ||||||
|                 // Treat the question.
 |                 // Treat the question.
 | ||||||
|                 this.questionHelper.extractQuestionScripts(this.question); |                 this.questionHelper.extractQuestionScripts(this.question, this.usageId); | ||||||
| 
 | 
 | ||||||
|                 // Handle question behaviour.
 |                 // Handle question behaviour.
 | ||||||
|                 const behaviour = this.questionDelegate.getBehaviourForQuestion(this.question, this.question.preferredBehaviour); |                 const behaviour = this.questionDelegate.getBehaviourForQuestion(this.question, this.question.preferredBehaviour); | ||||||
|  | |||||||
| @ -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. |      * Get the list of files that needs to be downloaded in addition to the files embedded in the HTML. | ||||||
|      * |      * | ||||||
|      * @param {any} question Question. |      * @param {any} question Question. | ||||||
|  |      * @param {number} usageId Usage ID. | ||||||
|      * @return {string[]} List of URLs. |      * @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. |      * Get the list of files that needs to be downloaded in addition to the files embedded in the HTML. | ||||||
|      * |      * | ||||||
|      * @param {any} question Question. |      * @param {any} question Question. | ||||||
|  |      * @param {number} usageId Usage ID. | ||||||
|      * @return {string[]} List of URLs. |      * @return {string[]} List of URLs. | ||||||
|      */ |      */ | ||||||
|     getAdditionalDownloadableFiles(question: any): string[] { |     getAdditionalDownloadableFiles(question: any, usageId: number): string[] { | ||||||
|         const type = this.getTypeName(question); |         const type = this.getTypeName(question); | ||||||
| 
 | 
 | ||||||
|         return this.executeFunctionOnEnabled(type, 'getAdditionalDownloadableFiles', [question]) || []; |         return this.executeFunctionOnEnabled(type, 'getAdditionalDownloadableFiles', [question, usageId]) || []; | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  | |||||||
| @ -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. |      * 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 {any} question Question. | ||||||
|  |      * @param {number} usageId Usage ID. | ||||||
|      */ |      */ | ||||||
|     extractQuestionScripts(question: any): void { |     extractQuestionScripts(question: any, usageId: number): void { | ||||||
|         question.scriptsCode = ''; |         question.scriptsCode = ''; | ||||||
|         question.initObjects = null; |         question.initObjects = null; | ||||||
|         question.amdArgs = null; |         question.amdArgs = null; | ||||||
| @ -272,7 +273,8 @@ export class CoreQuestionHelperProvider { | |||||||
|                 } |                 } | ||||||
| 
 | 
 | ||||||
|                 const amdRegExp = new RegExp('require\\(\\["qtype_' + question.type + '/question"\\], ' + |                 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); |                 const amdMatch = match.match(amdRegExp); | ||||||
|                 if (amdMatch) { |                 if (amdMatch) { | ||||||
|                     // Try to convert the arguments to an array and add them to the question.
 |                     // 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} [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|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 {string} [siteId] Site ID. If not defined, current site. | ||||||
|  |      * @param {number} [usageId] Usage ID. Required in Moodle 3.7+. | ||||||
|      * @return {Promise<any>} Promise resolved when all the files have been downloaded. |      * @return {Promise<any>} Promise resolved when all the files have been downloaded. | ||||||
|      */ |      */ | ||||||
|     prefetchQuestionFiles(question: any, component?: string, componentId?: string | number, siteId?: string): Promise<any> { |     prefetchQuestionFiles(question: any, component?: string, componentId?: string | number, siteId?: string, usageId?: number) | ||||||
|  |             : Promise<any> { | ||||||
|         const urls = this.domUtils.extractDownloadableFilesFromHtml(question.html); |         const urls = this.domUtils.extractDownloadableFilesFromHtml(question.html); | ||||||
| 
 | 
 | ||||||
|         if (!component) { |         if (!component) { | ||||||
| @ -516,7 +520,7 @@ export class CoreQuestionHelperProvider { | |||||||
|             componentId = question.id; |             componentId = question.id; | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         urls.push(...this.questionDelegate.getAdditionalDownloadableFiles(question)); |         urls.push(...this.questionDelegate.getAdditionalDownloadableFiles(question, usageId)); | ||||||
| 
 | 
 | ||||||
|         return this.sitesProvider.getSite(siteId).then((site) => { |         return this.sitesProvider.getSite(siteId).then((site) => { | ||||||
|             const promises = []; |             const promises = []; | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user