Search in sources :

Example 21 with MatchInteraction

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);
}
Also used : MatchInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.MatchInteraction) FlowFormItem(org.olat.ims.qti21.ui.components.FlowFormItem) SimpleAssociableChoice(uk.ac.ed.ph.jqtiplus.node.item.interaction.choice.SimpleAssociableChoice) FormLayoutContainer(org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer)

Example 22 with MatchInteraction

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;
}
Also used : MatchInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.MatchInteraction) SimpleMatchSet(uk.ac.ed.ph.jqtiplus.node.item.interaction.choice.SimpleMatchSet) SimpleAssociableChoice(uk.ac.ed.ph.jqtiplus.node.item.interaction.choice.SimpleAssociableChoice)

Example 23 with MatchInteraction

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";
}
Also used : MatchInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.MatchInteraction) GraphicGapMatchInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.GraphicGapMatchInteraction) GapMatchInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.GapMatchInteraction) QTI21Module(org.olat.ims.qti21.QTI21Module) AssessmentRenderFunctions.contentAsString(org.olat.ims.qti21.ui.components.AssessmentRenderFunctions.contentAsString)

Example 24 with MatchInteraction

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;
    }
}
Also used : URLBuilder(org.olat.core.gui.render.URLBuilder) HottextInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.HottextInteraction) GraphicAssociateInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.GraphicAssociateInteraction) Identifier(uk.ac.ed.ph.jqtiplus.types.Identifier) Choice(uk.ac.ed.ph.jqtiplus.node.item.interaction.choice.Choice) Map(java.util.Map) Flow(uk.ac.ed.ph.jqtiplus.node.content.basic.Flow) InlineChoiceInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.InlineChoiceInteraction) StringOutput(org.olat.core.gui.render.StringOutput) OLog(org.olat.core.logging.OLog) ListValue(uk.ac.ed.ph.jqtiplus.value.ListValue) FlowStatic(uk.ac.ed.ph.jqtiplus.node.content.basic.FlowStatic) HotspotInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.HotspotInteraction) Translator(org.olat.core.gui.translator.Translator) InlineChoice(uk.ac.ed.ph.jqtiplus.node.item.interaction.choice.InlineChoice) ResponseDeclaration(uk.ac.ed.ph.jqtiplus.node.item.response.declaration.ResponseDeclaration) FormJSHelper(org.olat.core.gui.components.form.flexible.impl.FormJSHelper) AssociateInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.AssociateInteraction) StringInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.StringInteraction) Value(uk.ac.ed.ph.jqtiplus.value.Value) ChoiceInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.ChoiceInteraction) AssociableHotspot(uk.ac.ed.ph.jqtiplus.node.item.interaction.graphic.AssociableHotspot) Collectors(java.util.stream.Collectors) GapImg(uk.ac.ed.ph.jqtiplus.node.item.interaction.choice.GapImg) List(java.util.List) BlockStatic(uk.ac.ed.ph.jqtiplus.node.content.basic.BlockStatic) MatchInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.MatchInteraction) AssessmentRenderFunctions.renderValue(org.olat.ims.qti21.ui.components.AssessmentRenderFunctions.renderValue) TextOrVariable(uk.ac.ed.ph.jqtiplus.node.content.variable.TextOrVariable) BaseType(uk.ac.ed.ph.jqtiplus.value.BaseType) VelocityRenderDecorator(org.olat.core.gui.render.velocity.VelocityRenderDecorator) RecordValue(uk.ac.ed.ph.jqtiplus.value.RecordValue) GraphicOrderInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.GraphicOrderInteraction) Block(uk.ac.ed.ph.jqtiplus.node.content.basic.Block) Settings(org.olat.core.helpers.Settings) Orientation(uk.ac.ed.ph.jqtiplus.value.Orientation) QtiNode(uk.ac.ed.ph.jqtiplus.node.QtiNode) GapChoice(uk.ac.ed.ph.jqtiplus.node.item.interaction.choice.GapChoice) QueryUtils(uk.ac.ed.ph.jqtiplus.utils.QueryUtils) CandidateSessionContext(org.olat.ims.qti21.ui.CandidateSessionContext) ResolvedAssessmentItem(uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentItem) HashMap(java.util.HashMap) StringMultipleAttribute(uk.ac.ed.ph.jqtiplus.attribute.value.StringMultipleAttribute) Prompt(uk.ac.ed.ph.jqtiplus.node.item.interaction.Prompt) ItemSessionState(uk.ac.ed.ph.jqtiplus.state.ItemSessionState) ResponseData(uk.ac.ed.ph.jqtiplus.types.ResponseData) ArrayList(java.util.ArrayList) Gap(uk.ac.ed.ph.jqtiplus.node.item.interaction.content.Gap) SliderInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.SliderInteraction) Cardinality(uk.ac.ed.ph.jqtiplus.value.Cardinality) ExtendedTextInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.ExtendedTextInteraction) OrderInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.OrderInteraction) StringHelper(org.olat.core.util.StringHelper) AssessmentItem(uk.ac.ed.ph.jqtiplus.node.item.AssessmentItem) AssessmentTestSession(org.olat.ims.qti21.AssessmentTestSession) Iterator(java.util.Iterator) SimpleChoice(uk.ac.ed.ph.jqtiplus.node.item.interaction.choice.SimpleChoice) HotspotChoice(uk.ac.ed.ph.jqtiplus.node.item.interaction.graphic.HotspotChoice) Interaction(uk.ac.ed.ph.jqtiplus.node.item.interaction.Interaction) SimpleAssociableChoice(uk.ac.ed.ph.jqtiplus.node.item.interaction.choice.SimpleAssociableChoice) IOException(java.io.IOException) SingleValue(uk.ac.ed.ph.jqtiplus.value.SingleValue) Shape(uk.ac.ed.ph.jqtiplus.node.expression.operator.Shape) GraphicGapMatchInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.GraphicGapMatchInteraction) NullValue(uk.ac.ed.ph.jqtiplus.value.NullValue) GapMatchInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.GapMatchInteraction) Tracing(org.olat.core.logging.Tracing) FileValue(uk.ac.ed.ph.jqtiplus.value.FileValue) BodyElement(uk.ac.ed.ph.jqtiplus.node.content.BodyElement) SimpleAssociableChoice(uk.ac.ed.ph.jqtiplus.node.item.interaction.choice.SimpleAssociableChoice) Identifier(uk.ac.ed.ph.jqtiplus.types.Identifier) HashMap(java.util.HashMap) IOException(java.io.IOException)

Example 25 with MatchInteraction

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);
}
Also used : MatchInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.MatchInteraction) FlowFormItem(org.olat.ims.qti21.ui.components.FlowFormItem) SimpleAssociableChoice(uk.ac.ed.ph.jqtiplus.node.item.interaction.choice.SimpleAssociableChoice) FormLayoutContainer(org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer)

Aggregations

MatchInteraction (uk.ac.ed.ph.jqtiplus.node.item.interaction.MatchInteraction)40 SimpleAssociableChoice (uk.ac.ed.ph.jqtiplus.node.item.interaction.choice.SimpleAssociableChoice)18 ArrayList (java.util.ArrayList)12 SimpleMatchSet (uk.ac.ed.ph.jqtiplus.node.item.interaction.choice.SimpleMatchSet)12 Block (uk.ac.ed.ph.jqtiplus.node.content.basic.Block)10 HashMap (java.util.HashMap)8 AssessmentItem (uk.ac.ed.ph.jqtiplus.node.item.AssessmentItem)8 ResponseDeclaration (uk.ac.ed.ph.jqtiplus.node.item.response.declaration.ResponseDeclaration)8 Identifier (uk.ac.ed.ph.jqtiplus.types.Identifier)8 IOException (java.io.IOException)6 List (java.util.List)6 FormLayoutContainer (org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer)6 StringOutput (org.olat.core.gui.render.StringOutput)6 AssessmentItemFactory.appendMatchInteraction (org.olat.ims.qti21.model.xml.AssessmentItemFactory.appendMatchInteraction)6 ChoiceInteraction (uk.ac.ed.ph.jqtiplus.node.item.interaction.ChoiceInteraction)6 HotspotInteraction (uk.ac.ed.ph.jqtiplus.node.item.interaction.HotspotInteraction)6 Interaction (uk.ac.ed.ph.jqtiplus.node.item.interaction.Interaction)6 FlowFormItem (org.olat.ims.qti21.ui.components.FlowFormItem)5 Map (java.util.Map)4 Collectors (java.util.stream.Collectors)4