Skip to content

Commit 91108ae

Browse files
committed
MOBILE-4690 quiz: Add QuestionCompleteGradableResponse enum
1 parent cc2ee88 commit 91108ae

File tree

17 files changed

+128
-90
lines changed

17 files changed

+128
-90
lines changed

src/addons/qbehaviour/deferredcbm/services/handlers/deferredcbm.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import { CoreQuestionQuestionParsed, CoreQuestionsAnswers, CoreQuestionState } f
2121
import { CoreQuestionHelper } from '@features/question/services/question-helper';
2222
import { AddonQbehaviourDeferredCBMComponent } from '../../component/deferredcbm';
2323
import { CoreQuestionDelegate } from '@features/question/services/question-delegate';
24+
import { QuestionCompleteGradableResponse } from '@features/question/constants';
2425

2526
/**
2627
* Handler to support deferred CBM question behaviour.
@@ -89,12 +90,12 @@ export class AddonQbehaviourDeferredCBMHandlerService implements CoreQuestionBeh
8990
answers: CoreQuestionsAnswers,
9091
component: string,
9192
componentId: string | number,
92-
): number {
93+
): QuestionCompleteGradableResponse {
9394
// First check if the question answer is complete.
9495
const complete = CoreQuestionDelegate.isCompleteResponse(question, answers, component, componentId);
9596
if (complete > 0) {
9697
// Answer is complete, check the user answered CBM too.
97-
return answers['-certainty'] ? 1 : 0;
98+
return answers['-certainty'] ? QuestionCompleteGradableResponse.YES : QuestionCompleteGradableResponse.NO;
9899
}
99100

100101
return complete;

src/addons/qbehaviour/deferredfeedback/services/handlers/deferredfeedback.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
// limitations under the License.
1414

1515
import { Injectable } from '@angular/core';
16+
import { QuestionCompleteGradableResponse } from '@features/question/constants';
1617

1718
import { CoreQuestionBehaviourHandler, CoreQuestionQuestionWithAnswers } from '@features/question/services/behaviour-delegate';
1819
import { CoreQuestionDBRecord } from '@features/question/services/database/question';
@@ -134,7 +135,7 @@ export class AddonQbehaviourDeferredFeedbackHandlerService implements CoreQuesti
134135
}
135136

136137
// Answers have changed. Now check if the response is complete and calculate the new state.
137-
let complete: number;
138+
let complete: QuestionCompleteGradableResponse;
138139
let newState: string;
139140

140141
if (isCompleteFn) {
@@ -190,7 +191,7 @@ export type isCompleteResponseFunction = (
190191
answers: CoreQuestionsAnswers,
191192
component: string,
192193
componentId: string | number,
193-
) => number;
194+
) => QuestionCompleteGradableResponse;
194195

195196
/**
196197
* Check if two responses are the same.

src/addons/qtype/calculatedmulti/services/handlers/calculatedmulti.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import { CoreQuestionQuestionParsed, CoreQuestionsAnswers } from '@features/ques
1818
import { CoreQuestionHandler } from '@features/question/services/question-delegate';
1919
import { makeSingleton } from '@singletons';
2020
import { AddonQtypeMultichoiceHandler } from '@addons/qtype/multichoice/services/handlers/multichoice';
21+
import { QuestionCompleteGradableResponse } from '@features/question/constants';
2122

2223
/**
2324
* Handler to support calculated multi question type.
@@ -44,7 +45,7 @@ export class AddonQtypeCalculatedMultiHandlerService implements CoreQuestionHand
4445
isCompleteResponse(
4546
question: CoreQuestionQuestionParsed,
4647
answers: CoreQuestionsAnswers,
47-
): number {
48+
): QuestionCompleteGradableResponse {
4849
// This question type depends on multichoice.
4950
return AddonQtypeMultichoiceHandler.isCompleteResponseSingle(answers);
5051
}
@@ -62,7 +63,7 @@ export class AddonQtypeCalculatedMultiHandlerService implements CoreQuestionHand
6263
isGradableResponse(
6364
question: CoreQuestionQuestionParsed,
6465
answers: CoreQuestionsAnswers,
65-
): number {
66+
): QuestionCompleteGradableResponse {
6667
// This question type depends on multichoice.
6768
return AddonQtypeMultichoiceHandler.isGradableResponseSingle(answers);
6869
}

src/addons/qtype/ddimageortext/services/handlers/ddimageortext.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
// limitations under the License.
1414

1515
import { Injectable, Type } from '@angular/core';
16+
import { QuestionCompleteGradableResponse } from '@features/question/constants';
1617

1718
import { CoreQuestion, CoreQuestionQuestionParsed, CoreQuestionsAnswers } from '@features/question/services/question';
1819
import { CoreQuestionHandler } from '@features/question/services/question-delegate';
@@ -53,17 +54,17 @@ export class AddonQtypeDdImageOrTextHandlerService implements CoreQuestionHandle
5354
isCompleteResponse(
5455
question: CoreQuestionQuestionParsed,
5556
answers: CoreQuestionsAnswers,
56-
): number {
57+
): QuestionCompleteGradableResponse {
5758
// An answer is complete if all drop zones have an answer.
5859
// We should always receive all the drop zones with their value ('' if not answered).
5960
for (const name in answers) {
6061
const value = answers[name];
6162
if (!value || value === '0') {
62-
return 0;
63+
return QuestionCompleteGradableResponse.NO;
6364
}
6465
}
6566

66-
return 1;
67+
return QuestionCompleteGradableResponse.YES;
6768
}
6869

6970
/**
@@ -79,15 +80,15 @@ export class AddonQtypeDdImageOrTextHandlerService implements CoreQuestionHandle
7980
isGradableResponse(
8081
question: CoreQuestionQuestionParsed,
8182
answers: CoreQuestionsAnswers,
82-
): number {
83+
): QuestionCompleteGradableResponse{
8384
for (const name in answers) {
8485
const value = answers[name];
8586
if (value && value !== '0') {
86-
return 1;
87+
return QuestionCompleteGradableResponse.YES;
8788
}
8889
}
8990

90-
return 0;
91+
return QuestionCompleteGradableResponse.NO;
9192
}
9293

9394
/**
@@ -108,7 +109,7 @@ export class AddonQtypeDdImageOrTextHandlerService implements CoreQuestionHandle
108109
question: CoreQuestionQuestionParsed,
109110
answers: CoreQuestionsAnswers,
110111
): string | undefined {
111-
if (this.isCompleteResponse(question, answers)) {
112+
if (this.isCompleteResponse(question, answers) === QuestionCompleteGradableResponse.YES) {
112113
return;
113114
}
114115

src/addons/qtype/ddmarker/services/handlers/ddmarker.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
// limitations under the License.
1414

1515
import { Injectable, Type } from '@angular/core';
16+
import { QuestionCompleteGradableResponse } from '@features/question/constants';
1617

1718
import { CoreQuestion, CoreQuestionQuestionParsed, CoreQuestionsAnswers } from '@features/question/services/question';
1819
import { CoreQuestionHandler } from '@features/question/services/question-delegate';
@@ -55,15 +56,15 @@ export class AddonQtypeDdMarkerHandlerService implements CoreQuestionHandler {
5556
isCompleteResponse(
5657
question: CoreQuestionQuestionParsed,
5758
answers: CoreQuestionsAnswers,
58-
): number {
59+
): QuestionCompleteGradableResponse {
5960
// If 1 dragitem is set we assume the answer is complete (like Moodle does).
6061
for (const name in answers) {
6162
if (name !== ':sequencecheck' && answers[name]) {
62-
return 1;
63+
return QuestionCompleteGradableResponse.YES;
6364
}
6465
}
6566

66-
return 0;
67+
return QuestionCompleteGradableResponse.NO;
6768
}
6869

6970
/**
@@ -79,7 +80,7 @@ export class AddonQtypeDdMarkerHandlerService implements CoreQuestionHandler {
7980
isGradableResponse(
8081
question: CoreQuestionQuestionParsed,
8182
answers: CoreQuestionsAnswers,
82-
): number {
83+
): QuestionCompleteGradableResponse {
8384
return this.isCompleteResponse(question, answers);
8485
}
8586

@@ -119,7 +120,7 @@ export class AddonQtypeDdMarkerHandlerService implements CoreQuestionHandler {
119120
question: CoreQuestionQuestionParsed,
120121
answers: CoreQuestionsAnswers,
121122
): string | undefined {
122-
if (this.isCompleteResponse(question, answers)) {
123+
if (this.isCompleteResponse(question, answers) === QuestionCompleteGradableResponse.YES) {
123124
return;
124125
}
125126

src/addons/qtype/essay/services/handlers/essay.ts

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import { CoreObject } from '@singletons/object';
2828
import { CoreWSFile } from '@services/ws';
2929
import { makeSingleton, Translate } from '@singletons';
3030
import { CoreFileHelper } from '@services/file-helper';
31+
import { QuestionCompleteGradableResponse } from '@features/question/constants';
3132

3233
/**
3334
* Handler to support essay question type.
@@ -150,7 +151,8 @@ export class AddonQtypeEssayHandlerService implements CoreQuestionHandler {
150151
return;
151152
}
152153

153-
if (this.isCompleteResponse(question, answers, component, componentId)) {
154+
// Continue check in case the response completion cannot be determined.
155+
if (this.isCompleteResponse(question, answers, component, componentId) === QuestionCompleteGradableResponse.YES) {
154156
return;
155157
}
156158

@@ -201,34 +203,38 @@ export class AddonQtypeEssayHandlerService implements CoreQuestionHandler {
201203
answers: CoreQuestionsAnswers,
202204
component: string,
203205
componentId: string | number,
204-
): number {
206+
): QuestionCompleteGradableResponse {
205207

206208
const hasTextAnswer = !!answers.answer;
207209
const uploadFilesSupported = question.responsefileareas !== undefined;
208210
const allowedOptions = this.getAllowedOptions(question);
209211

210212
if (hasTextAnswer && this.checkInputWordCount(question, <string> answers.answer, undefined)) {
211-
return 0;
213+
return QuestionCompleteGradableResponse.NO;
212214
}
213215

214216
if (!allowedOptions.attachments) {
215-
return hasTextAnswer ? 1 : 0;
217+
return hasTextAnswer ? QuestionCompleteGradableResponse.YES : QuestionCompleteGradableResponse.NO;
216218
}
217219

218220
if (!uploadFilesSupported || !question.parsedSettings) {
219221
// We can't know if the attachments are required or if the user added any in web.
220-
return -1;
222+
return QuestionCompleteGradableResponse.UNKNOWN;
221223
}
222224

223225
const questionComponentId = CoreQuestion.getQuestionComponentId(question, componentId);
224226
const attachments = CoreFileSession.getFiles(component, questionComponentId);
225227

226228
if (!allowedOptions.text) {
227-
return attachments && attachments.length >= Number(question.parsedSettings.attachmentsrequired) ? 1 : 0;
229+
return attachments && attachments.length >= Number(question.parsedSettings.attachmentsrequired)
230+
? QuestionCompleteGradableResponse.YES
231+
: QuestionCompleteGradableResponse.NO;
228232
}
229233

230234
return ((hasTextAnswer || question.parsedSettings.responserequired === '0') &&
231-
(attachments && attachments.length >= Number(question.parsedSettings.attachmentsrequired))) ? 1 : 0;
235+
(attachments && attachments.length >= Number(question.parsedSettings.attachmentsrequired)))
236+
? QuestionCompleteGradableResponse.YES
237+
: QuestionCompleteGradableResponse.NO;
232238
}
233239

234240
/**
@@ -246,16 +252,18 @@ export class AddonQtypeEssayHandlerService implements CoreQuestionHandler {
246252
answers: CoreQuestionsAnswers,
247253
component: string,
248254
componentId: string | number,
249-
): number {
255+
): QuestionCompleteGradableResponse {
250256
if (question.responsefileareas === undefined) {
251-
return -1;
257+
return QuestionCompleteGradableResponse.UNKNOWN;
252258
}
253259

254260
const questionComponentId = CoreQuestion.getQuestionComponentId(question, componentId);
255261
const attachments = CoreFileSession.getFiles(component, questionComponentId);
256262

257263
// Determine if the given response has online text or attachments.
258-
return (answers.answer && answers.answer !== '') || (attachments && attachments.length > 0) ? 1 : 0;
264+
return (answers.answer && answers.answer !== '') || (attachments && attachments.length > 0)
265+
? QuestionCompleteGradableResponse.YES
266+
: QuestionCompleteGradableResponse.NO;
259267
}
260268

261269
/**

src/addons/qtype/gapselect/services/handlers/gapselect.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
// limitations under the License.
1414

1515
import { Injectable, Type } from '@angular/core';
16+
import { QuestionCompleteGradableResponse } from '@features/question/constants';
1617

1718
import { CoreQuestion, CoreQuestionQuestionParsed, CoreQuestionsAnswers } from '@features/question/services/question';
1819
import { CoreQuestionHandler } from '@features/question/services/question-delegate';
@@ -53,16 +54,16 @@ export class AddonQtypeGapSelectHandlerService implements CoreQuestionHandler {
5354
isCompleteResponse(
5455
question: CoreQuestionQuestionParsed,
5556
answers: CoreQuestionsAnswers,
56-
): number {
57+
): QuestionCompleteGradableResponse {
5758
// We should always get a value for each select so we can assume we receive all the possible answers.
5859
for (const name in answers) {
5960
const value = answers[name];
6061
if (!value || value === '0') {
61-
return 0;
62+
return QuestionCompleteGradableResponse.NO;
6263
}
6364
}
6465

65-
return 1;
66+
return QuestionCompleteGradableResponse.YES;
6667
}
6768

6869
/**
@@ -78,16 +79,16 @@ export class AddonQtypeGapSelectHandlerService implements CoreQuestionHandler {
7879
isGradableResponse(
7980
question: CoreQuestionQuestionParsed,
8081
answers: CoreQuestionsAnswers,
81-
): number {
82+
): QuestionCompleteGradableResponse {
8283
// We should always get a value for each select so we can assume we receive all the possible answers.
8384
for (const name in answers) {
8485
const value = answers[name];
8586
if (value && value !== '0') {
86-
return 1;
87+
return QuestionCompleteGradableResponse.YES;
8788
}
8889
}
8990

90-
return 0;
91+
return QuestionCompleteGradableResponse.NO;
9192
}
9293

9394
/**
@@ -108,7 +109,7 @@ export class AddonQtypeGapSelectHandlerService implements CoreQuestionHandler {
108109
question: CoreQuestionQuestionParsed,
109110
answers: CoreQuestionsAnswers,
110111
): string | undefined {
111-
if (this.isCompleteResponse(question, answers)) {
112+
if (this.isCompleteResponse(question, answers) === QuestionCompleteGradableResponse.YES) {
112113
return;
113114
}
114115

src/addons/qtype/match/services/handlers/match.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
// limitations under the License.
1414

1515
import { Injectable, Type } from '@angular/core';
16+
import { QuestionCompleteGradableResponse } from '@features/question/constants';
1617

1718
import { CoreQuestion, CoreQuestionQuestionParsed, CoreQuestionsAnswers } from '@features/question/services/question';
1819
import { CoreQuestionHandler } from '@features/question/services/question-delegate';
@@ -53,16 +54,16 @@ export class AddonQtypeMatchHandlerService implements CoreQuestionHandler {
5354
isCompleteResponse(
5455
question: CoreQuestionQuestionParsed,
5556
answers: CoreQuestionsAnswers,
56-
): number {
57+
): QuestionCompleteGradableResponse {
5758
// We should always get a value for each select so we can assume we receive all the possible answers.
5859
for (const name in answers) {
5960
const value = answers[name];
6061
if (!value || value === '0') {
61-
return 0;
62+
return QuestionCompleteGradableResponse.NO;
6263
}
6364
}
6465

65-
return 1;
66+
return QuestionCompleteGradableResponse.YES;
6667
}
6768

6869
/**
@@ -78,16 +79,16 @@ export class AddonQtypeMatchHandlerService implements CoreQuestionHandler {
7879
isGradableResponse(
7980
question: CoreQuestionQuestionParsed,
8081
answers: CoreQuestionsAnswers,
81-
): number {
82+
): QuestionCompleteGradableResponse {
8283
// We should always get a value for each select so we can assume we receive all the possible answers.
8384
for (const name in answers) {
8485
const value = answers[name];
8586
if (value && value !== '0') {
86-
return 1;
87+
return QuestionCompleteGradableResponse.YES;
8788
}
8889
}
8990

90-
return 0;
91+
return QuestionCompleteGradableResponse.NO;
9192
}
9293

9394
/**
@@ -108,7 +109,7 @@ export class AddonQtypeMatchHandlerService implements CoreQuestionHandler {
108109
question: CoreQuestionQuestionParsed,
109110
answers: CoreQuestionsAnswers,
110111
): string | undefined {
111-
if (this.isCompleteResponse(question, answers)) {
112+
if (this.isCompleteResponse(question, answers) === QuestionCompleteGradableResponse.YES) {
112113
return;
113114
}
114115

0 commit comments

Comments
 (0)