Skip to content

Commit 46efcc4

Browse files
committed
MOBILE-2272 quiz: Support add new files in essay in online
1 parent 3f40127 commit 46efcc4

File tree

29 files changed

+393
-102
lines changed

29 files changed

+393
-102
lines changed

src/addon/mod/quiz/pages/player/player.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -569,7 +569,8 @@ export class AddonModQuizPlayerPage implements OnInit, OnDestroy {
569569

570570
// Prepare the answers to be sent for the attempt.
571571
protected prepareAnswers(): Promise<any> {
572-
return this.questionHelper.prepareAnswers(this.questions, this.getAnswers(), this.offline);
572+
return this.questionHelper.prepareAnswers(this.questions, this.getAnswers(), this.offline, this.component,
573+
this.quiz.coursemodule);
573574
}
574575

575576
/**
@@ -612,6 +613,8 @@ export class AddonModQuizPlayerPage implements OnInit, OnDestroy {
612613
if (this.formElement) {
613614
this.domUtils.triggerFormSubmittedEvent(this.formElement, !this.offline, this.sitesProvider.getCurrentSiteId());
614615
}
616+
617+
return this.questionHelper.clearTmpData(this.questions, this.component, this.quiz.coursemodule);
615618
});
616619
}
617620

src/addon/mod/quiz/providers/quiz-offline.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -342,8 +342,8 @@ export class AddonModQuizOfflineProvider {
342342
for (const slot in questionsWithAnswers) {
343343
const question = questionsWithAnswers[slot];
344344

345-
promises.push(this.behaviourDelegate.determineNewState(
346-
quiz.preferredbehaviour, AddonModQuizProvider.COMPONENT, attempt.id, question, siteId).then((state) => {
345+
promises.push(this.behaviourDelegate.determineNewState(quiz.preferredbehaviour, AddonModQuizProvider.COMPONENT,
346+
attempt.id, question, quiz.coursemodule, siteId).then((state) => {
347347
// Check if state has changed.
348348
if (state && state.name != question.state) {
349349
newStates[question.slot] = state.name;

src/addon/qbehaviour/deferredcbm/providers/handler.ts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,14 @@ export class AddonQbehaviourDeferredCBMHandler implements CoreQuestionBehaviourH
4040
* @param component Component the question belongs to.
4141
* @param attemptId Attempt ID the question belongs to.
4242
* @param question The question.
43+
* @param componentId Component ID.
4344
* @param siteId Site ID. If not defined, current site.
4445
* @return New state (or promise resolved with state).
4546
*/
46-
determineNewState(component: string, attemptId: number, question: any, siteId?: string)
47+
determineNewState(component: string, attemptId: number, question: any, componentId: string | number, siteId?: string)
4748
: CoreQuestionState | Promise<CoreQuestionState> {
4849
// Depends on deferredfeedback.
49-
return this.deferredFeedbackHandler.determineNewStateDeferred(component, attemptId, question, siteId,
50+
return this.deferredFeedbackHandler.determineNewStateDeferred(component, attemptId, question, componentId, siteId,
5051
this.isCompleteResponse.bind(this), this.isSameResponse.bind(this));
5152
}
5253

@@ -71,11 +72,13 @@ export class AddonQbehaviourDeferredCBMHandler implements CoreQuestionBehaviourH
7172
*
7273
* @param question The question.
7374
* @param answers Object with the question answers (without prefix).
75+
* @param component The component the question is related to.
76+
* @param componentId Component ID.
7477
* @return 1 if complete, 0 if not complete, -1 if cannot determine.
7578
*/
76-
protected isCompleteResponse(question: any, answers: any): number {
79+
protected isCompleteResponse(question: any, answers: any, component: string, componentId: string | number): number {
7780
// First check if the question answer is complete.
78-
const complete = this.questionDelegate.isCompleteResponse(question, answers);
81+
const complete = this.questionDelegate.isCompleteResponse(question, answers, component, componentId);
7982
if (complete > 0) {
8083
// Answer is complete, check the user answered CBM too.
8184
return answers['-certainty'] ? 1 : 0;
@@ -101,12 +104,14 @@ export class AddonQbehaviourDeferredCBMHandler implements CoreQuestionBehaviourH
101104
* @param prevBasicAnswers Object with the previous basic" answers (without sequencecheck, certainty, ...).
102105
* @param newAnswers Object with the new question answers.
103106
* @param newBasicAnswers Object with the previous basic" answers (without sequencecheck, certainty, ...).
107+
* @param component The component the question is related to.
108+
* @param componentId Component ID.
104109
* @return Whether they're the same.
105110
*/
106-
protected isSameResponse(question: any, prevAnswers: any, prevBasicAnswers: any, newAnswers: any, newBasicAnswers: any)
107-
: boolean {
111+
protected isSameResponse(question: any, prevAnswers: any, prevBasicAnswers: any, newAnswers: any, newBasicAnswers: any,
112+
component: string, componentId: string | number): boolean {
108113
// First check if the question answer is the same.
109-
const same = this.questionDelegate.isSameResponse(question, prevBasicAnswers, newBasicAnswers);
114+
const same = this.questionDelegate.isSameResponse(question, prevBasicAnswers, newBasicAnswers, component, componentId);
110115
if (same) {
111116
// Same response, check the CBM is the same too.
112117
return prevAnswers['-certainty'] == newAnswers['-certainty'];

src/addon/qbehaviour/deferredfeedback/providers/handler.ts

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -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
*/
4044
export 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 deferred feedback question behaviour.
@@ -58,12 +62,13 @@ export class AddonQbehaviourDeferredFeedbackHandler implements CoreQuestionBehav
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.determineNewStateDeferred(component, attemptId, question, siteId);
71+
return this.determineNewStateDeferred(component, attemptId, question, componentId, siteId);
6772
}
6873

6974
/**
@@ -72,12 +77,13 @@ export class AddonQbehaviourDeferredFeedbackHandler implements CoreQuestionBehav
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-
determineNewStateDeferred(component: string, attemptId: number, question: any, siteId?: string,
86+
determineNewStateDeferred(component: string, attemptId: number, question: any, componentId: string | number, siteId?: string,
8187
isCompleteFn?: isCompleteResponseFunction, isSameFn?: isSameResponseFunction): Promise<CoreQuestionState> {
8288

8389
// Check if we have local data for the question.
@@ -103,11 +109,12 @@ export class AddonQbehaviourDeferredFeedbackHandler implements CoreQuestionBehav
103109

104110
// If answers haven't changed the state is the same.
105111
if (isSameFn) {
106-
if (isSameFn(question, prevAnswers, prevBasicAnswers, question.answers, newBasicAnswers)) {
112+
if (isSameFn(question, prevAnswers, prevBasicAnswers, question.answers, newBasicAnswers,
113+
component, componentId)) {
107114
return state;
108115
}
109116
} else {
110-
if (this.questionDelegate.isSameResponse(question, prevBasicAnswers, newBasicAnswers)) {
117+
if (this.questionDelegate.isSameResponse(question, prevBasicAnswers, newBasicAnswers, component, componentId)) {
111118
return state;
112119
}
113120
}
@@ -117,10 +124,10 @@ export class AddonQbehaviourDeferredFeedbackHandler implements CoreQuestionBehav
117124
newState: string;
118125
if (isCompleteFn) {
119126
// Pass all the answers since some behaviours might need the extra data.
120-
complete = isCompleteFn(question, question.answers);
127+
complete = isCompleteFn(question, question.answers, component, componentId);
121128
} else {
122129
// Only pass the basic answers since questions should be independent of extra data.
123-
complete = this.questionDelegate.isCompleteResponse(question, newBasicAnswers);
130+
complete = this.questionDelegate.isCompleteResponse(question, newBasicAnswers, component, componentId);
124131
}
125132

126133
if (complete < 0) {

src/addon/qbehaviour/informationitem/providers/handler.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,11 @@ export class AddonQbehaviourInformationItemHandler implements CoreQuestionBehavi
3535
* @param component Component the question belongs to.
3636
* @param attemptId Attempt ID the question belongs to.
3737
* @param question The question.
38+
* @param componentId Component ID.
3839
* @param siteId Site ID. If not defined, current site.
3940
* @return New state (or promise resolved with state).
4041
*/
41-
determineNewState(component: string, attemptId: number, question: any, siteId?: string)
42+
determineNewState(component: string, attemptId: number, question: any, componentId: string | number, siteId?: string)
4243
: CoreQuestionState | Promise<CoreQuestionState> {
4344
if (question.answers['-seen']) {
4445
return this.questionProvider.getState('complete');

src/addon/qbehaviour/manualgraded/providers/handler.ts

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -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
*/
4044
export 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) {

src/addon/qtype/calculated/providers/handler.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,11 @@ export class AddonQtypeCalculatedHandler implements CoreQuestionHandler {
4646
*
4747
* @param question The question.
4848
* @param answers Object with the question answers (without prefix).
49+
* @param component The component the question is related to.
50+
* @param componentId Component ID.
4951
* @return 1 if complete, 0 if not complete, -1 if cannot determine.
5052
*/
51-
isCompleteResponse(question: any, answers: any): number {
53+
isCompleteResponse(question: any, answers: any, component: string, componentId: string | number): number {
5254
if (this.isGradableResponse(question, answers) === 0 || !this.validateUnits(answers['answer'])) {
5355
return 0;
5456
}
@@ -93,9 +95,11 @@ export class AddonQtypeCalculatedHandler implements CoreQuestionHandler {
9395
* @param question Question.
9496
* @param prevAnswers Object with the previous question answers.
9597
* @param newAnswers Object with the new question answers.
98+
* @param component The component the question is related to.
99+
* @param componentId Component ID.
96100
* @return Whether they're the same.
97101
*/
98-
isSameResponse(question: any, prevAnswers: any, newAnswers: any): boolean {
102+
isSameResponse(question: any, prevAnswers: any, newAnswers: any, component: string, componentId: string | number): boolean {
99103
return this.utils.sameAtKeyMissingIsBlank(prevAnswers, newAnswers, 'answer') &&
100104
this.utils.sameAtKeyMissingIsBlank(prevAnswers, newAnswers, 'unit');
101105
}

src/addon/qtype/calculatedmulti/providers/handler.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,11 @@ export class AddonQtypeCalculatedMultiHandler implements CoreQuestionHandler {
4646
*
4747
* @param question The question.
4848
* @param answers Object with the question answers (without prefix).
49+
* @param component The component the question is related to.
50+
* @param componentId Component ID.
4951
* @return 1 if complete, 0 if not complete, -1 if cannot determine.
5052
*/
51-
isCompleteResponse(question: any, answers: any): number {
53+
isCompleteResponse(question: any, answers: any, component: string, componentId: string | number): number {
5254
// This question type depends on multichoice.
5355
return this.multichoiceHandler.isCompleteResponseSingle(answers);
5456
}
@@ -81,9 +83,11 @@ export class AddonQtypeCalculatedMultiHandler implements CoreQuestionHandler {
8183
* @param question Question.
8284
* @param prevAnswers Object with the previous question answers.
8385
* @param newAnswers Object with the new question answers.
86+
* @param component The component the question is related to.
87+
* @param componentId Component ID.
8488
* @return Whether they're the same.
8589
*/
86-
isSameResponse(question: any, prevAnswers: any, newAnswers: any): boolean {
90+
isSameResponse(question: any, prevAnswers: any, newAnswers: any, component: string, componentId: string | number): boolean {
8791
// This question type depends on multichoice.
8892
return this.multichoiceHandler.isSameResponseSingle(prevAnswers, newAnswers);
8993
}

0 commit comments

Comments
 (0)