use of uk.ac.ed.ph.jqtiplus.node.item.interaction.MatchInteraction in project openolat by klemens.
the class KPrimEditorController method initForm.
@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
FormLayoutContainer metadata = FormLayoutContainer.createDefaultFormLayout("metadata", getTranslator());
metadata.setFormContextHelp("Test editor QTI 2.1 in detail#details_testeditor_fragetypen_kprim");
metadata.setRootForm(mainForm);
formLayout.add(metadata);
formLayout.add("metadata", metadata);
titleEl = uifactory.addTextElement("title", "form.imd.title", -1, itemBuilder.getTitle(), metadata);
titleEl.setElementCssClass("o_sel_assessment_item_title");
titleEl.setMandatory(true);
titleEl.setEnabled(!readOnly);
String description = itemBuilder.getQuestion();
textEl = uifactory.addRichTextElementForQTI21("desc", "form.imd.descr", description, 8, -1, itemContainer, metadata, ureq.getUserSession(), getWindowControl());
textEl.setEnabled(!readOnly);
textEl.setVisible(!readOnly);
if (readOnly) {
FlowFormItem textReadOnlyEl = new FlowFormItem("descro", itemFile);
textReadOnlyEl.setLabel("form.imd.descr", null);
textReadOnlyEl.setBlocks(itemBuilder.getQuestionBlocks());
textReadOnlyEl.setMapperUri(mapperUri);
metadata.add(textReadOnlyEl);
}
// shuffle
String[] yesnoValues = new String[] { translate("yes"), translate("no") };
shuffleEl = uifactory.addRadiosHorizontal("shuffle", "form.imd.shuffle", metadata, yesnoKeys, yesnoValues);
shuffleEl.setEnabled(!restrictedEdit && !readOnly);
if (itemBuilder.isShuffle()) {
shuffleEl.select("y", true);
} else {
shuffleEl.select("n", true);
}
// layout
String[] alignmentValues = new String[] { translate("form.imd.alignment.left"), translate("form.imd.alignment.right") };
alignmentEl = uifactory.addRadiosHorizontal("alignment", "form.imd.alignment", metadata, alignmentKeys, alignmentValues);
alignmentEl.setEnabled(!restrictedEdit && !readOnly);
if (itemBuilder.hasClassAttr(QTI21Constants.CHOICE_ALIGN_RIGHT)) {
alignmentEl.select(alignmentKeys[1], true);
} else {
alignmentEl.select(alignmentKeys[0], true);
}
// responses
String page = velocity_root + "/kprim_choices.html";
answersCont = FormLayoutContainer.createCustomFormLayout("answers", getTranslator(), page);
answersCont.setRootForm(mainForm);
formLayout.add(answersCont);
formLayout.add("answers", answersCont);
MatchInteraction interaction = itemBuilder.getMatchInteraction();
if (interaction != null) {
List<SimpleAssociableChoice> choices = itemBuilder.getKprimChoices();
for (SimpleAssociableChoice choice : choices) {
wrapAnswer(ureq, choice);
}
}
answersCont.contextPut("choices", choiceWrappers);
answersCont.contextPut("restrictedEdit", restrictedEdit || readOnly);
recalculateUpDownLinks();
// Submit Button
FormLayoutContainer buttonsContainer = FormLayoutContainer.createDefaultFormLayout("buttons", getTranslator());
buttonsContainer.setElementCssClass("o_sel_choices_save");
buttonsContainer.setRootForm(mainForm);
buttonsContainer.setVisible(!readOnly);
formLayout.add(buttonsContainer);
formLayout.add("buttons", buttonsContainer);
uifactory.addFormSubmitButton("submit", buttonsContainer);
}
use of uk.ac.ed.ph.jqtiplus.node.item.interaction.MatchInteraction in project OpenOLAT by OpenOLAT.
the class MatchInteractionArchive method writeInteractionData.
@Override
public int writeInteractionData(AssessmentItem item, AssessmentResponse response, Interaction interaction, int itemNumber, Row dataRow, int col, OpenXMLWorkbook workbook) {
MatchInteraction matchInteraction = (MatchInteraction) interaction;
String stringuifiedResponse = response == null ? null : response.getStringuifiedResponse();
if (!StringHelper.containsNonWhitespace(stringuifiedResponse)) {
col += matchInteraction.getSimpleMatchSets().get(0).getSimpleAssociableChoices().size();
} else {
boolean kprim = matchInteraction.getResponseIdentifier().toString().startsWith("KPRIM_") || QTI21QuestionType.hasClass(matchInteraction, QTI21Constants.CSS_MATCH_KPRIM);
Set<String> correctAnswers = CorrectResponsesUtil.getCorrectDirectPairResponses(item, matchInteraction, false);
List<String> responses = CorrectResponsesUtil.parseResponses(stringuifiedResponse);
SimpleMatchSet firstMatchSet = matchInteraction.getSimpleMatchSets().get(0);
SimpleMatchSet secondMatchSet = matchInteraction.getSimpleMatchSets().get(1);
for (SimpleAssociableChoice choice : firstMatchSet.getSimpleAssociableChoices()) {
String choiceIdentifier = choice.getIdentifier().toString();
if (kprim) {
String markerCorrect = choiceIdentifier + " correct";
String markerWrong = choiceIdentifier + " wrong";
boolean isCorrectRight = correctAnswers.contains(markerCorrect);
String rightFlag = isCorrectRight ? markerCorrect : markerWrong;
String wrongFlag = isCorrectRight ? markerWrong : markerCorrect;
String value = null;
if (stringuifiedResponse.contains(markerCorrect)) {
value = "+";
} else if (stringuifiedResponse.contains(markerWrong)) {
value = "-";
}
if (stringuifiedResponse.indexOf(rightFlag) >= 0) {
dataRow.addCell(col++, value, workbook.getStyles().getCorrectStyle());
} else if (stringuifiedResponse.indexOf(wrongFlag) >= 0) {
dataRow.addCell(col++, value, null);
} else {
col++;
}
} else {
String aResponse = null;
for (String r : responses) {
if (r.startsWith(choiceIdentifier)) {
aResponse = r;
}
}
if (StringHelper.containsNonWhitespace(aResponse)) {
boolean correct = correctAnswers.contains(aResponse);
String value = null;
for (SimpleAssociableChoice association : secondMatchSet.getSimpleAssociableChoices()) {
if (aResponse.endsWith(association.getIdentifier().toString())) {
value = getContent(association);
break;
}
}
if (correct) {
dataRow.addCell(col++, value, workbook.getStyles().getCorrectStyle());
} else {
dataRow.addCell(col++, value, null);
}
} else {
col++;
}
}
}
}
return col;
}
use of uk.ac.ed.ph.jqtiplus.node.item.interaction.MatchInteraction in project OpenOLAT by OpenOLAT.
the class AssessmentObjectComponentRenderer method getInteractionTemplate.
private String getInteractionTemplate(QtiNode interaction) {
String interactionName;
switch(interaction.getQtiClassName()) {
case "matchInteraction":
{
MatchInteraction matchInteraction = (MatchInteraction) interaction;
interactionName = interaction.getQtiClassName();
if (matchInteraction.getResponseIdentifier().toString().startsWith("KPRIM_")) {
interactionName += "_kprim";
} else if (hasClass(matchInteraction, QTI21Constants.CSS_MATCH_DRAG_AND_DROP)) {
interactionName += "_dnd";
} else if (hasClass(matchInteraction, QTI21Constants.CSS_MATCH_TRUE_FALSE)) {
interactionName += "_truefalse";
} else if (hasClass(matchInteraction, QTI21Constants.CSS_MATCH_KPRIM)) {
interactionName += "_kprim";
}
break;
}
case "mathEntryInteraction":
{
if (!CoreSpringFactory.getImpl(QTI21Module.class).isMathAssessExtensionEnabled()) {
interactionName = "mathEntryInteractionNotEnabled";
break;
}
}
default:
interactionName = interaction.getQtiClassName();
break;
}
String templateName = interactionName.substring(0, 1).toLowerCase().concat(interactionName.substring(1));
return velocity_root + "/" + templateName + ".html";
}
use of uk.ac.ed.ph.jqtiplus.node.item.interaction.MatchInteraction in project OpenOLAT by OpenOLAT.
the class AssessmentObjectVelocityRenderDecorator method getVisibleOrderedChoices.
public List<SimpleAssociableChoice> getVisibleOrderedChoices(MatchInteraction interaction, int pos) {
try {
List<SimpleAssociableChoice> choices;
if (interaction.getShuffle()) {
List<Identifier> choiceOrders = itemSessionState.getShuffledInteractionChoiceOrder(interaction.getResponseIdentifier());
Map<Identifier, SimpleAssociableChoice> idTochoice = new HashMap<>();
List<SimpleAssociableChoice> allChoices = interaction.getSimpleMatchSets().get(pos).getSimpleAssociableChoices();
for (SimpleAssociableChoice allChoice : allChoices) {
idTochoice.put(allChoice.getIdentifier(), allChoice);
}
choices = new ArrayList<>();
for (Identifier choiceOrder : choiceOrders) {
SimpleAssociableChoice choice = idTochoice.get(choiceOrder);
if (choice != null) {
choices.add(choice);
}
}
} else {
choices = interaction.getSimpleMatchSets().get(pos).getSimpleAssociableChoices();
}
return choices.stream().filter((choice) -> isVisible(choice, itemSessionState)).collect(Collectors.toList());
} catch (Exception e) {
log.error("", e);
return null;
}
}
use of uk.ac.ed.ph.jqtiplus.node.item.interaction.MatchInteraction in project OpenOLAT by OpenOLAT.
the class KPrimEditorController method initForm.
@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
FormLayoutContainer metadata = FormLayoutContainer.createDefaultFormLayout("metadata", getTranslator());
metadata.setFormContextHelp("Test editor QTI 2.1 in detail#details_testeditor_fragetypen_kprim");
metadata.setRootForm(mainForm);
formLayout.add(metadata);
formLayout.add("metadata", metadata);
titleEl = uifactory.addTextElement("title", "form.imd.title", -1, itemBuilder.getTitle(), metadata);
titleEl.setElementCssClass("o_sel_assessment_item_title");
titleEl.setMandatory(true);
titleEl.setEnabled(!readOnly);
String description = itemBuilder.getQuestion();
textEl = uifactory.addRichTextElementForQTI21("desc", "form.imd.descr", description, 8, -1, itemContainer, metadata, ureq.getUserSession(), getWindowControl());
textEl.setEnabled(!readOnly);
textEl.setVisible(!readOnly);
if (readOnly) {
FlowFormItem textReadOnlyEl = new FlowFormItem("descro", itemFile);
textReadOnlyEl.setLabel("form.imd.descr", null);
textReadOnlyEl.setBlocks(itemBuilder.getQuestionBlocks());
textReadOnlyEl.setMapperUri(mapperUri);
metadata.add(textReadOnlyEl);
}
// shuffle
String[] yesnoValues = new String[] { translate("yes"), translate("no") };
shuffleEl = uifactory.addRadiosHorizontal("shuffle", "form.imd.shuffle", metadata, yesnoKeys, yesnoValues);
shuffleEl.setEnabled(!restrictedEdit && !readOnly);
if (itemBuilder.isShuffle()) {
shuffleEl.select("y", true);
} else {
shuffleEl.select("n", true);
}
// layout
String[] alignmentValues = new String[] { translate("form.imd.alignment.left"), translate("form.imd.alignment.right") };
alignmentEl = uifactory.addRadiosHorizontal("alignment", "form.imd.alignment", metadata, alignmentKeys, alignmentValues);
alignmentEl.setEnabled(!restrictedEdit && !readOnly);
if (itemBuilder.hasClassAttr(QTI21Constants.CHOICE_ALIGN_RIGHT)) {
alignmentEl.select(alignmentKeys[1], true);
} else {
alignmentEl.select(alignmentKeys[0], true);
}
// responses
String page = velocity_root + "/kprim_choices.html";
answersCont = FormLayoutContainer.createCustomFormLayout("answers", getTranslator(), page);
answersCont.setRootForm(mainForm);
formLayout.add(answersCont);
formLayout.add("answers", answersCont);
MatchInteraction interaction = itemBuilder.getMatchInteraction();
if (interaction != null) {
List<SimpleAssociableChoice> choices = itemBuilder.getKprimChoices();
for (SimpleAssociableChoice choice : choices) {
wrapAnswer(ureq, choice);
}
}
answersCont.contextPut("choices", choiceWrappers);
answersCont.contextPut("restrictedEdit", restrictedEdit || readOnly);
recalculateUpDownLinks();
// Submit Button
FormLayoutContainer buttonsContainer = FormLayoutContainer.createDefaultFormLayout("buttons", getTranslator());
buttonsContainer.setElementCssClass("o_sel_choices_save");
buttonsContainer.setRootForm(mainForm);
buttonsContainer.setVisible(!readOnly);
formLayout.add(buttonsContainer);
formLayout.add("buttons", buttonsContainer);
uifactory.addFormSubmitButton("submit", buttonsContainer);
}
Aggregations