use of uk.ac.ed.ph.jqtiplus.node.item.interaction.ChoiceInteraction in project OpenOLAT by OpenOLAT.
the class SingleChoiceEditorController method doAddSimpleChoice.
private void doAddSimpleChoice(UserRequest ureq) {
ChoiceInteraction interaction = itemBuilder.getChoiceInteraction();
SimpleChoice newChoice = AssessmentItemFactory.createSimpleChoice(interaction, translate("new.answer"), "sc");
wrapAnswer(ureq, newChoice);
flc.setDirty(true);
}
use of uk.ac.ed.ph.jqtiplus.node.item.interaction.ChoiceInteraction in project OpenOLAT by OpenOLAT.
the class QTI21AssessmentItemStatisticsController method interactionControllerFactory.
private Component interactionControllerFactory(UserRequest ureq, Interaction interaction, StatisticsItem itemStats) {
Controller interactionCtrl = null;
if (interaction instanceof ChoiceInteraction) {
interactionCtrl = new SimpleChoiceInteractionStatisticsController(ureq, getWindowControl(), itemRef, item, (ChoiceInteraction) interaction, itemStats, resourceResult);
} else if (interaction instanceof MatchInteraction) {
String responseIdentifier = interaction.getResponseIdentifier().toString();
if (responseIdentifier.startsWith("KPRIM_") || QTI21QuestionType.hasClass(interaction, QTI21Constants.CSS_MATCH_KPRIM)) {
interactionCtrl = new KPrimStatisticsController(ureq, getWindowControl(), itemRef, item, (MatchInteraction) interaction, resourceResult);
} else {
interactionCtrl = new MatchStatisticsController(ureq, getWindowControl(), itemRef, item, (MatchInteraction) interaction, resourceResult);
}
} else if (interaction instanceof HotspotInteraction) {
interactionCtrl = new HotspotInteractionStatisticsController(ureq, getWindowControl(), itemRef, item, (HotspotInteraction) interaction, itemStats, resourceResult);
} else if (interaction instanceof HottextInteraction) {
interactionCtrl = new HottextInteractionStatisticsController(ureq, getWindowControl(), itemRef, item, (HottextInteraction) interaction, itemStats, resourceResult);
}
if (interactionCtrl == null) {
interactionCtrl = new UnsupportedInteractionController(ureq, getWindowControl(), interaction);
}
listenTo(interactionCtrl);
return interactionCtrl.getInitialComponent();
}
use of uk.ac.ed.ph.jqtiplus.node.item.interaction.ChoiceInteraction in project OpenOLAT by OpenOLAT.
the class SimpleChoiceAssessmentItemBuilder method extractChoiceInteraction.
private void extractChoiceInteraction() {
try (StringOutput sb = new StringOutput()) {
List<Block> blocks = assessmentItem.getItemBody().getBlocks();
for (Block block : blocks) {
if (block instanceof ChoiceInteraction) {
choiceInteraction = (ChoiceInteraction) block;
responseIdentifier = choiceInteraction.getResponseIdentifier();
shuffle = choiceInteraction.getShuffle();
break;
} else if (block != null) {
serializeJqtiObject(block, sb);
}
}
question = sb.toString();
} catch (IOException e) {
log.error("", e);
}
choices = new ArrayList<>();
if (choiceInteraction != null) {
choices.addAll(choiceInteraction.getSimpleChoices());
orientation = choiceInteraction.getOrientation();
cssClass = choiceInteraction.getClassAttr();
maxChoices = choiceInteraction.getMaxChoices();
minChoices = choiceInteraction.getMinChoices();
}
}
use of uk.ac.ed.ph.jqtiplus.node.item.interaction.ChoiceInteraction 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.ChoiceInteraction in project OpenOLAT by OpenOLAT.
the class AssessmentItemFactory method createSingleChoice.
public static AssessmentItem createSingleChoice(String title, String defaultAnswer) {
AssessmentItem assessmentItem = createAssessmentItem(QTI21QuestionType.sc, title);
// define correct answer
Identifier responseDeclarationId = Identifier.assumedLegal("RESPONSE_1");
Identifier correctResponseId = IdentifierGenerator.newAsIdentifier("sc");
ResponseDeclaration responseDeclaration = createSingleChoiceCorrectResponseDeclaration(assessmentItem, responseDeclarationId, correctResponseId);
assessmentItem.getNodeGroups().getResponseDeclarationGroup().getResponseDeclarations().add(responseDeclaration);
// outcomes
appendDefaultOutcomeDeclarations(assessmentItem, 1.0d);
// the single choice interaction
ItemBody itemBody = appendDefaultItemBody(assessmentItem);
ChoiceInteraction choiceInteraction = appendChoiceInteraction(itemBody, responseDeclarationId, 1, true);
appendSimpleChoice(choiceInteraction, defaultAnswer, correctResponseId);
// response processing
ResponseProcessing responseProcessing = createResponseProcessing(assessmentItem, responseDeclarationId);
assessmentItem.getNodeGroups().getResponseProcessingGroup().setResponseProcessing(responseProcessing);
return assessmentItem;
}
Aggregations