From 3ec25faf65be28ab90e5fa447bc41b5fb860efa7 Mon Sep 17 00:00:00 2001 From: Dani Palou Date: Thu, 18 Apr 2019 12:47:01 +0200 Subject: [PATCH 1/2] MOBILE-2817 lesson: Remove continue button if not needed --- src/addon/mod/lesson/pages/player/player.ts | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/addon/mod/lesson/pages/player/player.ts b/src/addon/mod/lesson/pages/player/player.ts index 10e5e3ab0..ab32eb9d6 100644 --- a/src/addon/mod/lesson/pages/player/player.ts +++ b/src/addon/mod/lesson/pages/player/player.ts @@ -570,10 +570,15 @@ export class AddonModLessonPlayerPage implements OnInit, OnDestroy { // Button to continue. if (this.lesson.review && !result.correctanswer && !result.noanswer && !result.isessayquestion && !result.maxattemptsreached) { - this.processData.buttons.push({ - label: 'addon.mod_lesson.reviewquestioncontinue', - pageId: result.newpageid - }); + /* If both the "Yes, I'd like to try again" and "No, I just want to go on to the next question" point to the + same page then don't show the "No, I just want to go on to the next question" button. It's confusing. */ + if (this.pageData.page.id != result.newpageid) { + // Button to continue the lesson (the page to go is configured by the teacher). + this.processData.buttons.push({ + label: 'addon.mod_lesson.reviewquestioncontinue', + pageId: result.newpageid + }); + } } else { this.processData.buttons.push({ label: 'addon.mod_lesson.continue', From 4edf05d975f6198278fe8bc6d1db0da8ecdb33d4 Mon Sep 17 00:00:00 2001 From: Dani Palou Date: Thu, 18 Apr 2019 13:04:36 +0200 Subject: [PATCH 2/2] MOBILE-2817 lesson: Support new 'Other answers' option --- src/addon/mod/lesson/providers/lesson.ts | 33 ++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/src/addon/mod/lesson/providers/lesson.ts b/src/addon/mod/lesson/providers/lesson.ts index a364d1693..bfad310ed 100644 --- a/src/addon/mod/lesson/providers/lesson.ts +++ b/src/addon/mod/lesson/providers/lesson.ts @@ -156,6 +156,8 @@ export class AddonModLessonProvider { */ static MULTIANSWER_DELIMITER = '@^#|'; + static LESSON_OTHER_ANSWERS = '@#wronganswer#@'; + // Variables for database. static PASSWORD_TABLE = 'addon_mod_lesson_password'; protected siteSchema: CoreSiteSchema = { @@ -793,6 +795,8 @@ export class AddonModLessonProvider { break; } } + + this.checkOtherAnswers(lesson, pageData, result); } /** @@ -907,6 +911,8 @@ export class AddonModLessonProvider { } } + this.checkOtherAnswers(lesson, pageData, result); + result.userresponse = studentAnswer; result.studentanswer = this.textUtils.s(studentAnswer); // Clean student answer as it goes to output. } @@ -945,6 +951,33 @@ export class AddonModLessonProvider { } } + /** + * Check the "other answers" value. + * + * @param {any} lesson Lesson. + * @param {any} pageData Result of getPageData for the page to process. + * @param {AddonModLessonCheckAnswerResult} result Object where to store the result. + */ + protected checkOtherAnswers(lesson: any, pageData: any, result: AddonModLessonCheckAnswerResult): void { + // We could check here to see if we have a wrong answer jump to use. + if (result.answerid == 0) { + // Use the all other answers jump details if it is set up. + const lastAnswer = pageData.answers[pageData.answers.length - 1] || {}; + + // Double check that this is the OTHER_ANSWERS answer. + if (typeof lastAnswer.answer == 'string' && + lastAnswer.answer.indexOf(AddonModLessonProvider.LESSON_OTHER_ANSWERS) != -1) { + result.newpageid = lastAnswer.jumpto; + result.response = lastAnswer.response; + + if (lesson.custom) { + result.correctanswer = lastAnswer.score > 0; + } + result.answerid = lastAnswer.id; + } + } + } + /** * Create a list of pages indexed by page ID based on a list of pages. *