@@ -23,9 +23,11 @@ import { CoreQuestionProvider, CoreQuestionState } from '@core/question/provider
2323 *
2424 * @param question The question.
2525 * @param answers Object with the question answers (without prefix).
26+ * @param component The component the question is related to.
27+ * @param componentId Component ID.
2628 * @return 1 if complete, 0 if not complete, -1 if cannot determine.
2729 */
28- export type isCompleteResponseFunction = ( question : any , answers : any ) => number ;
30+ export type isCompleteResponseFunction = ( question : any , answers : any , component : string , componentId : string | number ) => number ;
2931
3032/**
3133 * Check if two responses are the same.
@@ -35,10 +37,12 @@ export type isCompleteResponseFunction = (question: any, answers: any) => number
3537 * @param prevBasicAnswers Object with the previous basic" answers (without sequencecheck, certainty, ...).
3638 * @param newAnswers Object with the new question answers.
3739 * @param newBasicAnswers Object with the previous basic" answers (without sequencecheck, certainty, ...).
40+ * @param component The component the question is related to.
41+ * @param componentId Component ID.
3842 * @return Whether they're the same.
3943 */
4044export type isSameResponseFunction = ( question : any , prevAnswers : any , prevBasicAnswers : any , newAnswers : any ,
41- newBasicAnswers : any ) => boolean ;
45+ newBasicAnswers : any , component : string , componentId : string | number ) => boolean ;
4246
4347/**
4448 * Handler to support manual graded question behaviour.
@@ -58,12 +62,13 @@ export class AddonQbehaviourManualGradedHandler implements CoreQuestionBehaviour
5862 * @param component Component the question belongs to.
5963 * @param attemptId Attempt ID the question belongs to.
6064 * @param question The question.
65+ * @param componentId Component ID.
6166 * @param siteId Site ID. If not defined, current site.
6267 * @return New state (or promise resolved with state).
6368 */
64- determineNewState ( component : string , attemptId : number , question : any , siteId ?: string )
69+ determineNewState ( component : string , attemptId : number , question : any , componentId : string | number , siteId ?: string )
6570 : CoreQuestionState | Promise < CoreQuestionState > {
66- return this . determineNewStateManualGraded ( component , attemptId , question , siteId ) ;
71+ return this . determineNewStateManualGraded ( component , attemptId , question , componentId , siteId ) ;
6772 }
6873
6974 /**
@@ -72,13 +77,15 @@ export class AddonQbehaviourManualGradedHandler implements CoreQuestionBehaviour
7277 * @param component Component the question belongs to.
7378 * @param attemptId Attempt ID the question belongs to.
7479 * @param question The question.
80+ * @param componentId Component ID.
7581 * @param siteId Site ID. If not defined, current site.
7682 * @param isCompleteFn Function to override the default isCompleteResponse check.
7783 * @param isSameFn Function to override the default isSameResponse check.
7884 * @return Promise resolved with state.
7985 */
80- determineNewStateManualGraded ( component : string , attemptId : number , question : any , siteId ?: string ,
81- isCompleteFn ?: isCompleteResponseFunction , isSameFn ?: isSameResponseFunction ) : Promise < CoreQuestionState > {
86+ determineNewStateManualGraded ( component : string , attemptId : number , question : any , componentId : string | number ,
87+ siteId ?: string , isCompleteFn ?: isCompleteResponseFunction , isSameFn ?: isSameResponseFunction )
88+ : Promise < CoreQuestionState > {
8289
8390 // Check if we have local data for the question.
8491 return this . questionProvider . getQuestion ( component , attemptId , question . slot , siteId ) . catch ( ( ) => {
@@ -103,11 +110,12 @@ export class AddonQbehaviourManualGradedHandler implements CoreQuestionBehaviour
103110
104111 // If answers haven't changed the state is the same.
105112 if ( isSameFn ) {
106- if ( isSameFn ( question , prevAnswers , prevBasicAnswers , question . answers , newBasicAnswers ) ) {
113+ if ( isSameFn ( question , prevAnswers , prevBasicAnswers , question . answers , newBasicAnswers ,
114+ component , componentId ) ) {
107115 return state ;
108116 }
109117 } else {
110- if ( this . questionDelegate . isSameResponse ( question , prevBasicAnswers , newBasicAnswers ) ) {
118+ if ( this . questionDelegate . isSameResponse ( question , prevBasicAnswers , newBasicAnswers , component , componentId ) ) {
111119 return state ;
112120 }
113121 }
@@ -117,10 +125,10 @@ export class AddonQbehaviourManualGradedHandler implements CoreQuestionBehaviour
117125 newState : string ;
118126 if ( isCompleteFn ) {
119127 // Pass all the answers since some behaviours might need the extra data.
120- complete = isCompleteFn ( question , question . answers ) ;
128+ complete = isCompleteFn ( question , question . answers , component , componentId ) ;
121129 } else {
122130 // Only pass the basic answers since questions should be independent of extra data.
123- complete = this . questionDelegate . isCompleteResponse ( question , newBasicAnswers ) ;
131+ complete = this . questionDelegate . isCompleteResponse ( question , newBasicAnswers , component , componentId ) ;
124132 }
125133
126134 if ( complete < 0 ) {
0 commit comments