use of uk.ac.ed.ph.jqtiplus.node.item.interaction.choice.SimpleChoice in project OpenOLAT by OpenOLAT.
the class QTI12To21Converter method convertSingleChoice.
private AssessmentItemBuilder convertSingleChoice(Item item) {
SingleChoiceAssessmentItemBuilder itemBuilder = new SingleChoiceAssessmentItemBuilder("Single choice", "New answer", qtiSerializer);
convertItemBasics(item, itemBuilder);
itemBuilder.clearMapping();
itemBuilder.clearSimpleChoices();
itemBuilder.setScoreEvaluationMode(ScoreEvaluation.allCorrectAnswers);
ChoiceInteraction interaction = itemBuilder.getChoiceInteraction();
Question question = item.getQuestion();
itemBuilder.setShuffle(question.isShuffle());
convertOrientation(question, itemBuilder);
List<Response> responses = question.getResponses();
Map<String, Identifier> identToIdentifier = new HashMap<>();
for (Response response : responses) {
String responseText = response.getContent().renderAsHtmlForEditor();
responseText = blockedHtml(responseText);
SimpleChoice newChoice;
if (StringHelper.isHtml(responseText)) {
newChoice = AssessmentItemFactory.createSimpleChoice(interaction, "", itemBuilder.getQuestionType().getPrefix());
htmlBuilder.appendHtml(newChoice, responseText);
} else {
newChoice = AssessmentItemFactory.createSimpleChoice(interaction, responseText, itemBuilder.getQuestionType().getPrefix());
}
itemBuilder.addSimpleChoice(newChoice);
identToIdentifier.put(response.getIdent(), newChoice.getIdentifier());
if (response.isCorrect()) {
itemBuilder.setCorrectAnswer(newChoice.getIdentifier());
}
}
convertFeedbackPerAnswers(item, itemBuilder, identToIdentifier);
double correctScore = question.getSingleCorrectScore();
if (correctScore >= 0.0d) {
itemBuilder.setMinScore(0.0d);
itemBuilder.setMaxScore(correctScore);
}
return itemBuilder;
}
use of uk.ac.ed.ph.jqtiplus.node.item.interaction.choice.SimpleChoice in project OpenOLAT by OpenOLAT.
the class AssessmentItemFactory method appendSimpleChoice.
public static SimpleChoice appendSimpleChoice(ChoiceInteraction choiceInteraction, String text, String prefix) {
SimpleChoice newChoice = createSimpleChoice(choiceInteraction, text, prefix);
choiceInteraction.getNodeGroups().getSimpleChoiceGroup().getSimpleChoices().add(newChoice);
return newChoice;
}
use of uk.ac.ed.ph.jqtiplus.node.item.interaction.choice.SimpleChoice in project OpenOLAT by OpenOLAT.
the class AssessmentItemFactory method createSimpleChoice.
public static SimpleChoice createSimpleChoice(ChoiceInteraction choiceInteraction, String text, String prefix) {
SimpleChoice newChoice = new SimpleChoice(choiceInteraction);
newChoice.setIdentifier(IdentifierGenerator.newAsIdentifier(prefix));
P firstChoiceText = AssessmentItemFactory.getParagraph(newChoice, text);
newChoice.getFlowStatics().add(firstChoiceText);
return newChoice;
}
use of uk.ac.ed.ph.jqtiplus.node.item.interaction.choice.SimpleChoice in project OpenOLAT by OpenOLAT.
the class MultipleChoiceAssessmentItemBuilder method buildItemBody.
@Override
protected void buildItemBody() {
// remove current blocks
List<Block> blocks = assessmentItem.getItemBody().getBlocks();
blocks.clear();
// add question
getHtmlHelper().appendHtml(assessmentItem.getItemBody(), question);
// add interaction
ChoiceInteraction singleChoiceInteraction = AssessmentItemFactory.createMultipleChoiceInteraction(assessmentItem, responseIdentifier, orientation, cssClass);
singleChoiceInteraction.setShuffle(isShuffle());
blocks.add(singleChoiceInteraction);
List<SimpleChoice> choiceList = getChoices();
singleChoiceInteraction.getSimpleChoices().addAll(choiceList);
int finalMaxChoices = 0;
if (maxChoices >= 0 && maxChoices <= choiceList.size()) {
finalMaxChoices = maxChoices;
}
singleChoiceInteraction.setMaxChoices(finalMaxChoices);
int finalMinChoices = 0;
if (minChoices >= 0 && minChoices <= choiceList.size()) {
finalMinChoices = minChoices;
}
singleChoiceInteraction.setMinChoices(finalMinChoices);
}
use of uk.ac.ed.ph.jqtiplus.node.item.interaction.choice.SimpleChoice in project OpenOLAT by OpenOLAT.
the class SingleChoiceAssessmentItemBuilder method buildItemBody.
@Override
protected void buildItemBody() {
// remove current blocks
List<Block> blocks = assessmentItem.getItemBody().getBlocks();
blocks.clear();
// add question
getHtmlHelper().appendHtml(assessmentItem.getItemBody(), question);
// add interaction
ChoiceInteraction singleChoiceInteraction = AssessmentItemFactory.createSingleChoiceInteraction(assessmentItem, responseIdentifier, orientation, cssClass);
singleChoiceInteraction.setShuffle(isShuffle());
blocks.add(singleChoiceInteraction);
List<SimpleChoice> choiceList = getChoices();
singleChoiceInteraction.getSimpleChoices().addAll(choiceList);
}
Aggregations