diff --git a/scripts/langindex.json b/scripts/langindex.json index 97ebde71e..4fa085549 100644 --- a/scripts/langindex.json +++ b/scripts/langindex.json @@ -1645,6 +1645,7 @@ "core.grades.feedback": "grades", "core.grades.grade": "grades", "core.grades.gradeitem": "grades", + "core.grades.gradepass": "grades", "core.grades.grades": "grades", "core.grades.lettergrade": "grades", "core.grades.manualitem": "grades", diff --git a/src/addons/mod/quiz/components/index/addon-mod-quiz-index.html b/src/addons/mod/quiz/components/index/addon-mod-quiz-index.html index 65d4ad412..003ea3bd9 100644 --- a/src/addons/mod/quiz/components/index/addon-mod-quiz-index.html +++ b/src/addons/mod/quiz/components/index/addon-mod-quiz-index.html @@ -49,6 +49,15 @@

{{ gradeMethodReadable }}

+ + +

{{ 'core.grades.gradepass' | translate }}

+

{{ 'addon.mod_quiz.outof' | translate: { $a: { + grade: bestGrade.gradetopass, + maxgrade: quiz.gradeFormatted + } } }}

+
+

{{ 'core.lastsync' | translate }}

diff --git a/src/addons/mod/quiz/components/index/index.ts b/src/addons/mod/quiz/components/index/index.ts index 70e0ba693..d31293695 100644 --- a/src/addons/mod/quiz/components/index/index.ts +++ b/src/addons/mod/quiz/components/index/index.ts @@ -79,6 +79,7 @@ export class AddonModQuizIndexComponent extends CoreCourseModuleMainActivityComp gradeMethodReadable?: string; // Grade method in a readable format. showReviewColumn = false; // Whether to show the review column. attempts: AddonModQuizAttempt[] = []; // List of attempts the user has made. + bestGrade?: AddonModQuizGetUserBestGradeWSResponse; // Best grade data. protected fetchContentDefaultError = 'addon.mod_quiz.errorgetquiz'; // Default error to show when loading contents. protected syncEventName = AddonModQuizSyncProvider.AUTO_SYNCED; @@ -89,7 +90,6 @@ export class AddonModQuizIndexComponent extends CoreCourseModuleMainActivityComp protected attemptAccessInfo?: AddonModQuizGetAttemptAccessInformationWSResponse; // Last attempt access info. protected moreAttempts = false; // Whether user can create/continue attempts. protected options?: AddonModQuizCombinedReviewOptions; // Combined review options. - protected bestGrade?: AddonModQuizGetUserBestGradeWSResponse; // Best grade data. protected gradebookData?: { grade?: number; feedback?: string }; // The gradebook grade and feedback. protected overallStats = false; // Equivalent to overallstats in mod_quiz_view_object in Moodle. protected finishedObserver?: CoreEventObserver; // It will observe attempt finished events. @@ -264,6 +264,8 @@ export class AddonModQuizIndexComponent extends CoreCourseModuleMainActivityComp * @return Promise resolved when done. */ protected async getAttempts(quiz: AddonModQuizQuizData): Promise { + // Always get the best grade because it includes the grade to pass. + this.bestGrade = await AddonModQuiz.getUserBestGrade(quiz.id, { cmId: this.module.id }); // Get access information of last attempt (it also works if no attempts made). this.attemptAccessInfo = await AddonModQuiz.getAttemptAccessInformation(quiz.id, 0, { cmId: this.module.id }); @@ -343,7 +345,6 @@ export class AddonModQuizIndexComponent extends CoreCourseModuleMainActivityComp * @return Promise resolved when done. */ protected async getResultInfo(quiz: AddonModQuizQuizData): Promise { - if (!this.attempts.length || !quiz.showGradeColumn || !this.bestGrade?.hasgrade || this.gradebookData?.grade === undefined) { this.showResults = false; @@ -584,6 +585,8 @@ export class AddonModQuizIndexComponent extends CoreCourseModuleMainActivityComp ): Promise { if (!attempts || !attempts.length) { // There are no attempts to treat. + quiz.gradeFormatted = AddonModQuiz.formatGrade(quiz.grade, quiz.decimalpoints); + return []; } @@ -607,7 +610,7 @@ export class AddonModQuizIndexComponent extends CoreCourseModuleMainActivityComp })); // Get best grade. - promises.push(this.getQuizGrade(quiz)); + promises.push(this.getQuizGrade()); await Promise.all(promises); @@ -635,12 +638,9 @@ export class AddonModQuizIndexComponent extends CoreCourseModuleMainActivityComp /** * Get quiz grade data. * - * @param quiz Quiz. * @return Promise resolved when done. */ - protected async getQuizGrade(quiz: AddonModQuizQuizData): Promise { - this.bestGrade = await AddonModQuiz.getUserBestGrade(quiz.id, { cmId: this.module.id }); - + protected async getQuizGrade(): Promise { try { // Get gradebook grade. const data = await AddonModQuiz.getGradeFromGradebook(this.courseId, this.module.id); @@ -654,7 +654,7 @@ export class AddonModQuizIndexComponent extends CoreCourseModuleMainActivityComp } catch { // Fallback to quiz best grade if failure or not found. this.gradebookData = { - grade: this.bestGrade.grade, + grade: this.bestGrade?.grade, }; } } diff --git a/src/addons/mod/quiz/services/quiz.ts b/src/addons/mod/quiz/services/quiz.ts index 36ac08ea9..0dd4a9d9e 100644 --- a/src/addons/mod/quiz/services/quiz.ts +++ b/src/addons/mod/quiz/services/quiz.ts @@ -2295,6 +2295,7 @@ export type AddonModQuizGetUserBestGradeWSParams = { export type AddonModQuizGetUserBestGradeWSResponse = { hasgrade: boolean; // Whether the user has a grade on the given quiz. grade?: number; // The grade (only if the user has a grade). + gradetopass?: number; // @since 3.11. The grade to pass the quiz (only if set). warnings?: CoreWSExternalWarning[]; }; diff --git a/src/core/features/grades/lang.json b/src/core/features/grades/lang.json index 2ec6b459d..1084e7782 100644 --- a/src/core/features/grades/lang.json +++ b/src/core/features/grades/lang.json @@ -9,6 +9,7 @@ "feedback": "Feedback", "grade": "Grade", "gradeitem": "Grade item", + "gradepass": "Grade to pass", "grades": "Grades", "lettergrade": "Letter grade", "manualitem": "Manual item",