Skip to content
Snippets Groups Projects
Unverified Commit b004908e authored by AnneliKlamas's avatar AnneliKlamas Committed by GitHub
Browse files

feat: Allow "shuffle" option #22 (#32)

parent 627c9d84
No related branches found
No related tags found
No related merge requests found
......@@ -23,10 +23,12 @@ Pictures are always added to the end of the text.
Supports only single choice and multiple choice/checkbox questions.
Doesn't support multi paragraph question descriptions.
Doesn't support multi paragraph question descriptions.
Coursera doesn't support default feedback for multi nor single choice questions.
By default no shuffle.
When multiple choice question then in MOODLE every correct answer gives 100/nrOfCorrectAnswers and every incorrect answer gives
-100/nrOfCorrectAnswers. In COURSERA it is behaving as "no partial credit".
......@@ -24,9 +24,19 @@ public class QuestionHandler {
}
addQuestionType(text);
addQuestionName(text);
addQuestionOptions(text);
return question;
}
private void addQuestionOptions(String text) {
var lowerCaseText = text.toLowerCase();
if (lowerCaseText.matches(".*(no)\s*(shuffle).*")) {
state.setShuffle(false);
} else if (lowerCaseText.matches(".*(shuffle).*")) {
state.setShuffle(true);
}
}
private void addQuestionName(String text) {
try {
int endOfNameIndex = !text.contains("-") ? text.indexOf("–") : text.indexOf("-");
......
......@@ -13,5 +13,6 @@ public record Question(
QuestionDescription description,
List<Answer> answerOptions,
List<QuestionErrorType> errors,
List<QuestionWarningType> warnings) {
List<QuestionWarningType> warnings,
boolean shuffle) {
}
......@@ -21,6 +21,7 @@ public class QuestionState {
private ParagraphType previousParagraphType = ParagraphType.EMPTY_TEXT;
private List<QuestionErrorType> errors = new ArrayList<>();
private List<QuestionWarningType> warnings = new ArrayList<>();
private boolean shuffle = false;
public void cleanState() {
name = "";
......@@ -31,9 +32,10 @@ public class QuestionState {
previousParagraphType = ParagraphType.EMPTY_TEXT;
errors = new ArrayList<>();
warnings = new ArrayList<>();
shuffle = false;
}
public Question createQuestion() {
return new Question(name, defaultFeedback, type, description, answerOptions, errors, warnings);
return new Question(name, defaultFeedback, type, description, answerOptions, errors, warnings, shuffle);
}
}
......@@ -58,7 +58,8 @@ public class CourseraDocxCreatorService {
} catch (NumberFormatException e) {
questionName = questions.indexOf(question) + 1;
}
questionDetailsRun.setText("Question " + questionName + " - " + questionTypeText);
var shuffle = question.shuffle() ? "shuffle" : "no shuffle";
questionDetailsRun.setText("Question " + questionName + " - " + questionTypeText + "," + shuffle);
}
private static void addAnswerOptions(Question question, int i, XWPFDocument doc) {
......
......@@ -54,6 +54,7 @@ public class MoodleXmlCreatorService {
addAnswer(doc, answer, questionElem, correctAnswerCount);
}
addQuestionOptions(question, doc, questionElem);
addQuestionType(question, doc, questionElem);
if (!question.feedback().isEmpty()) {
......@@ -61,6 +62,13 @@ public class MoodleXmlCreatorService {
}
}
private static void addQuestionOptions(Question question, Document doc, Element questionElem) {
var shuffleTagElem = doc.createElement("shuffleanswers");
var shuffleText = question.shuffle() ? "1" : "0";
shuffleTagElem.setTextContent(shuffleText);
questionElem.appendChild(shuffleTagElem);
}
private static void addQuestionType(Question question, Document doc, Element questionElem) {
var singleChoiceTagElem = doc.createElement("single");
var singleChoiceText = question.type().equals(QuestionType.SINGLE_CHOICE) ? "true" : "false";
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment