Skip to content

Commit 3df105b

Browse files
committed
MOBILE-2272 quiz: Use settings name instead of displayoptions
1 parent 07af88d commit 3df105b

File tree

4 files changed

+32
-29
lines changed

4 files changed

+32
-29
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1576,12 +1576,12 @@ export class AddonModQuizProvider {
15761576
for (let i = 0; i < result.questions.length; i++) {
15771577
const question = result.questions[i];
15781578

1579-
if (!question.displayoptions) {
1580-
// Site doesn't return displayoptions, stop.
1579+
if (!question.settings) {
1580+
// Site doesn't return settings, stop.
15811581
break;
15821582
}
15831583

1584-
question.displayoptions = this.utils.objectToKeyValueMap(question.displayoptions, 'name', 'value');
1584+
question.settings = this.textUtils.parseJSON(question.settings, null);
15851585
}
15861586

15871587
return result;

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,14 @@ export class AddonQtypeCalculatedHandler implements CoreQuestionHandler {
5656
* @return Whether units are in a separate field.
5757
*/
5858
hasSeparateUnitField(question: any): boolean {
59-
if (!question.displayoptions) {
59+
if (!question.settings) {
6060
const element = this.domUtils.convertToElement(question.html);
6161

6262
return !!(element.querySelector('select[name*=unit]') || element.querySelector('input[type="radio"]'));
6363
}
6464

65-
return question.displayoptions.showunits === AddonQtypeCalculatedHandler.UNITRADIO ||
66-
question.displayoptions.showunits === AddonQtypeCalculatedHandler.UNITSELECT;
65+
return question.settings.unitdisplay === AddonQtypeCalculatedHandler.UNITRADIO ||
66+
question.settings.unitdisplay === AddonQtypeCalculatedHandler.UNITSELECT;
6767
}
6868

6969
/**
@@ -85,7 +85,7 @@ export class AddonQtypeCalculatedHandler implements CoreQuestionHandler {
8585
return 0;
8686
}
8787

88-
if (!question.displayoptions) {
88+
if (!question.settings) {
8989
if (this.hasSeparateUnitField(question)) {
9090
return this.isValidValue(answers['unit']) ? 1 : 0;
9191
}
@@ -94,7 +94,7 @@ export class AddonQtypeCalculatedHandler implements CoreQuestionHandler {
9494
return -1;
9595
}
9696

97-
if (question.displayoptions.showunits != AddonQtypeCalculatedHandler.UNITINPUT && parsedAnswer.unit) {
97+
if (question.settings.unitdisplay != AddonQtypeCalculatedHandler.UNITINPUT && parsedAnswer.unit) {
9898
// There should be no units or be outside of the input, not valid.
9999
return 0;
100100
}
@@ -104,8 +104,8 @@ export class AddonQtypeCalculatedHandler implements CoreQuestionHandler {
104104
return 0;
105105
}
106106

107-
if (question.displayoptions.showunits == AddonQtypeCalculatedHandler.UNITINPUT &&
108-
question.displayoptions.unitgradingtype == AddonQtypeCalculatedHandler.UNITGRADED &&
107+
if (question.settings.unitdisplay == AddonQtypeCalculatedHandler.UNITINPUT &&
108+
question.settings.unitgradingtype == AddonQtypeCalculatedHandler.UNITGRADED &&
109109
!this.isValidValue(parsedAnswer.unit)) {
110110
// Unit not supplied inside the input and it's required.
111111
return 0;
@@ -191,15 +191,15 @@ export class AddonQtypeCalculatedHandler implements CoreQuestionHandler {
191191
let unitsLeft = false;
192192
let match = null;
193193

194-
if (!question.displayoptions) {
194+
if (!question.settings) {
195195
// We don't know if units should be before or after so we check both.
196196
match = answer.match(new RegExp('^' + regexString));
197197
if (!match) {
198198
unitsLeft = true;
199199
match = answer.match(new RegExp(regexString + '$'));
200200
}
201201
} else {
202-
unitsLeft = question.displayoptions.unitsleft == '1';
202+
unitsLeft = question.settings.unitsleft == '1';
203203
regexString = unitsLeft ? regexString + '$' : '^' + regexString;
204204

205205
match = answer.match(new RegExp(regexString));

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,10 @@ export class AddonQtypeEssayHandler implements CoreQuestionHandler {
7474
* @return Allowed options.
7575
*/
7676
protected getAllowedOptions(question: any): {text: boolean, attachments: boolean} {
77-
if (question.displayoptions) {
77+
if (question.settings) {
7878
return {
79-
text: question.displayoptions.responseformat != 'noinline',
80-
attachments: question.displayoptions.attachments != '0',
79+
text: question.settings.responseformat != 'noinline',
80+
attachments: question.settings.attachments != '0',
8181
};
8282
} else {
8383
const element = this.domUtils.convertToElement(question.html);
@@ -162,11 +162,11 @@ export class AddonQtypeEssayHandler implements CoreQuestionHandler {
162162
const attachments = CoreFileSession.instance.getFiles(component, questionComponentId);
163163

164164
if (!allowedOptions.text) {
165-
return attachments && attachments.length >= Number(question.displayoptions.attachmentsrequired) ? 1 : 0;
165+
return attachments && attachments.length >= Number(question.settings.attachmentsrequired) ? 1 : 0;
166166
}
167167

168-
return (hasTextAnswer || question.displayoptions.responserequired == '0') &&
169-
(attachments && attachments.length > Number(question.displayoptions.attachmentsrequired)) ? 1 : 0;
168+
return (hasTextAnswer || question.settings.responserequired == '0') &&
169+
(attachments && attachments.length > Number(question.settings.attachmentsrequired)) ? 1 : 0;
170170
}
171171

172172
/**

src/core/question/classes/base-question-component.ts

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,8 @@ export class CoreQuestionBaseComponent {
107107
this.question.select = selectModel;
108108

109109
// Check which one should be displayed first: the select or the input.
110-
if (this.question.displayoptions) {
111-
this.question.selectFirst = this.question.displayoptions.unitsleft == '1';
110+
if (this.question.settings) {
111+
this.question.selectFirst = this.question.settings.unitsleft == '1';
112112
} else {
113113
const input = questionEl.querySelector('input[type="text"][name*=answer]');
114114
this.question.selectFirst =
@@ -165,8 +165,8 @@ export class CoreQuestionBaseComponent {
165165
}
166166

167167
// Check which one should be displayed first: the options or the input.
168-
if (this.question.displayoptions) {
169-
this.question.optionsFirst = this.question.displayoptions.unitsleft == '1';
168+
if (this.question.settings) {
169+
this.question.optionsFirst = this.question.settings.unitsleft == '1';
170170
} else {
171171
const input = questionEl.querySelector('input[type="text"][name*=answer]');
172172
this.question.optionsFirst =
@@ -216,11 +216,11 @@ export class CoreQuestionBaseComponent {
216216
const textarea = <HTMLTextAreaElement> questionEl.querySelector('textarea[name*=_answer]');
217217
const answerDraftIdInput = <HTMLInputElement> questionEl.querySelector('input[name*="_answer:itemid"]');
218218

219-
if (this.question.displayoptions) {
220-
this.question.allowsAttachments = this.question.displayoptions.attachments != '0';
221-
this.question.allowsAnswerFiles = this.question.displayoptions.responseformat == 'editorfilepicker';
222-
this.question.isMonospaced = this.question.displayoptions.responseformat == 'monospaced';
223-
this.question.isPlainText = this.question.isMonospaced || this.question.displayoptions.responseformat == 'plain';
219+
if (this.question.settings) {
220+
this.question.allowsAttachments = this.question.settings.attachments != '0';
221+
this.question.allowsAnswerFiles = this.question.settings.responseformat == 'editorfilepicker';
222+
this.question.isMonospaced = this.question.settings.responseformat == 'monospaced';
223+
this.question.isPlainText = this.question.isMonospaced || this.question.settings.responseformat == 'plain';
224224
} else {
225225
this.question.allowsAttachments = !!questionEl.querySelector('div[id*=filemanager]');
226226
this.question.allowsAnswerFiles = !!answerDraftIdInput;
@@ -282,8 +282,11 @@ export class CoreQuestionBaseComponent {
282282
};
283283
}
284284

285-
this.question.attachmentsMaxFiles = Number(this.question.displayoptions.attachments);
286-
this.question.attachmentsAcceptedTypes = this.question.displayoptions.filetypeslist;
285+
if (this.question.settings) {
286+
this.question.attachmentsMaxFiles = Number(this.question.settings.attachments);
287+
this.question.attachmentsAcceptedTypes = this.question.settings.filetypeslist &&
288+
this.question.settings.filetypeslist.join(',');
289+
}
287290

288291
if (fileManagerUrl) {
289292
const params = CoreUrlUtils.instance.extractUrlParams(fileManagerUrl);

0 commit comments

Comments
 (0)