Search in sources :

Example 6 with SimpleChoice

use of uk.ac.ed.ph.jqtiplus.node.item.interaction.choice.SimpleChoice in project OpenOLAT by OpenOLAT.

the class MultipleChoiceEditorController method initForm.

@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
    FormLayoutContainer metadata = FormLayoutContainer.createDefaultFormLayout_2_10("metadata", getTranslator());
    metadata.setFormContextHelp("Test editor QTI 2.1 in detail#details_testeditor_fragetypen_mc");
    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.setVisible(!readOnly);
    if (readOnly) {
        FlowFormItem choiceReadOnlyEl = new FlowFormItem("descro", itemFile);
        choiceReadOnlyEl.setLabel("form.imd.descr", null);
        choiceReadOnlyEl.setBlocks(itemBuilder.getQuestionBlocks());
        choiceReadOnlyEl.setMapperUri(mapperUri);
        metadata.add(choiceReadOnlyEl);
    }
    // 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[] layoutValues = new String[] { translate("form.imd.layout.vertical"), translate("form.imd.layout.horizontal") };
    orientationEl = uifactory.addRadiosHorizontal("layout", "form.imd.layout", metadata, layoutKeys, layoutValues);
    orientationEl.setEnabled(!restrictedEdit && !readOnly);
    if (itemBuilder.getOrientation() == null || Orientation.VERTICAL.equals(itemBuilder.getOrientation())) {
        orientationEl.select(Orientation.VERTICAL.name(), true);
    } else {
        orientationEl.select(Orientation.HORIZONTAL.name(), true);
    }
    // alignment
    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 + "/multiple_choices.html";
    answersCont = FormLayoutContainer.createCustomFormLayout("answers", getTranslator(), page);
    answersCont.setRootForm(mainForm);
    formLayout.add(answersCont);
    formLayout.add("answers", answersCont);
    ChoiceInteraction interaction = itemBuilder.getChoiceInteraction();
    if (interaction != null) {
        List<SimpleChoice> choices = itemBuilder.getChoices();
        for (SimpleChoice choice : choices) {
            wrapAnswer(ureq, choice);
        }
    }
    answersCont.contextPut("choices", choiceWrappers);
    answersCont.contextPut("restrictedEdit", restrictedEdit || readOnly);
    recalculateUpDownLinks();
    // Submit Button
    FormLayoutContainer buttonsContainer = FormLayoutContainer.createDefaultFormLayout_2_10("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 : SimpleChoice(uk.ac.ed.ph.jqtiplus.node.item.interaction.choice.SimpleChoice) FlowFormItem(org.olat.ims.qti21.ui.components.FlowFormItem) FormLayoutContainer(org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer) ChoiceInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.ChoiceInteraction)

Example 7 with SimpleChoice

use of uk.ac.ed.ph.jqtiplus.node.item.interaction.choice.SimpleChoice in project OpenOLAT by OpenOLAT.

the class MultipleChoiceEditorController method doAddSimpleChoice.

private void doAddSimpleChoice(UserRequest ureq) {
    ChoiceInteraction interaction = itemBuilder.getChoiceInteraction();
    SimpleChoice newChoice = new SimpleChoice(interaction);
    newChoice.setIdentifier(IdentifierGenerator.newAsIdentifier("mc"));
    P firstChoiceText = AssessmentItemFactory.getParagraph(newChoice, translate("new.answer"));
    newChoice.getFlowStatics().add(firstChoiceText);
    wrapAnswer(ureq, newChoice);
    flc.setDirty(true);
}
Also used : P(uk.ac.ed.ph.jqtiplus.node.content.xhtml.text.P) SimpleChoice(uk.ac.ed.ph.jqtiplus.node.item.interaction.choice.SimpleChoice) ChoiceInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.ChoiceInteraction)

Example 8 with SimpleChoice

use of uk.ac.ed.ph.jqtiplus.node.item.interaction.choice.SimpleChoice in project OpenOLAT by OpenOLAT.

the class SimpleChoiceAssessmentItemBuilder method getAnswers.

@Override
public List<Answer> getAnswers() {
    List<SimpleChoice> simpleChoices = getChoices();
    List<Answer> answers = new ArrayList<>(simpleChoices.size());
    for (SimpleChoice choice : simpleChoices) {
        String choiceContent = getHtmlHelper().flowStaticString(choice.getFlowStatics());
        String label = FilterFactory.getHtmlTagAndDescapingFilter().filter(choiceContent);
        answers.add(new Answer(choice.getIdentifier(), label));
    }
    return answers;
}
Also used : SimpleChoice(uk.ac.ed.ph.jqtiplus.node.item.interaction.choice.SimpleChoice) ArrayList(java.util.ArrayList)

Example 9 with SimpleChoice

use of uk.ac.ed.ph.jqtiplus.node.item.interaction.choice.SimpleChoice in project OpenOLAT by OpenOLAT.

the class QTI12To21Converter method convertMultipleChoice.

private AssessmentItemBuilder convertMultipleChoice(Item item) {
    MultipleChoiceAssessmentItemBuilder itemBuilder = new MultipleChoiceAssessmentItemBuilder("Multiple choice", "New answer", qtiSerializer);
    convertItemBasics(item, itemBuilder);
    itemBuilder.clearMapping();
    itemBuilder.clearSimpleChoices();
    ChoiceInteraction interaction = itemBuilder.getChoiceInteraction();
    Question question = item.getQuestion();
    itemBuilder.setShuffle(question.isShuffle());
    convertOrientation(question, itemBuilder);
    boolean hasNegative = false;
    List<Response> responses = question.getResponses();
    for (Response response : responses) {
        if (response.getPoints() < 0.0f) {
            hasNegative = true;
        }
    }
    boolean singleCorrect = question.isSingleCorrect();
    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());
        double score = response.getPoints();
        if (singleCorrect) {
            if (response.isCorrect()) {
                itemBuilder.addCorrectAnswer(newChoice.getIdentifier());
            }
            if (score > 0.0f) {
                itemBuilder.setMaxScore(score);
            }
        } else {
            if ((hasNegative && response.getPoints() >= 0.0f) || (!hasNegative && response.getPoints() > 0.0f)) {
                itemBuilder.addCorrectAnswer(newChoice.getIdentifier());
            }
            itemBuilder.setMapping(newChoice.getIdentifier(), score);
        }
    }
    convertFeedbackPerAnswers(item, itemBuilder, identToIdentifier);
    if (singleCorrect) {
        itemBuilder.setScoreEvaluationMode(ScoreEvaluation.allCorrectAnswers);
    } else {
        itemBuilder.setScoreEvaluationMode(ScoreEvaluation.perAnswer);
        if (question instanceof ChoiceQuestion) {
            ChoiceQuestion choice = (ChoiceQuestion) question;
            itemBuilder.setMinScore(new Double(choice.getMinValue()));
            itemBuilder.setMaxScore(new Double(choice.getMaxValue()));
        }
    }
    return itemBuilder;
}
Also used : SimpleChoice(uk.ac.ed.ph.jqtiplus.node.item.interaction.choice.SimpleChoice) HashMap(java.util.HashMap) MultipleChoiceAssessmentItemBuilder(org.olat.ims.qti21.model.xml.interactions.MultipleChoiceAssessmentItemBuilder) FIBResponse(org.olat.ims.qti.editor.beecom.objects.FIBResponse) ChoiceResponse(org.olat.ims.qti.editor.beecom.objects.ChoiceResponse) Response(org.olat.ims.qti.editor.beecom.objects.Response) EssayResponse(org.olat.ims.qti.editor.beecom.objects.EssayResponse) Identifier(uk.ac.ed.ph.jqtiplus.types.Identifier) ChoiceInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.ChoiceInteraction) EssayQuestion(org.olat.ims.qti.editor.beecom.objects.EssayQuestion) ChoiceQuestion(org.olat.ims.qti.editor.beecom.objects.ChoiceQuestion) Question(org.olat.ims.qti.editor.beecom.objects.Question) ChoiceQuestion(org.olat.ims.qti.editor.beecom.objects.ChoiceQuestion)

Example 10 with SimpleChoice

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, Identifier identifier) {
    SimpleChoice newChoice = new SimpleChoice(choiceInteraction);
    newChoice.setIdentifier(identifier);
    P firstChoiceText = AssessmentItemFactory.getParagraph(newChoice, text);
    newChoice.getFlowStatics().add(firstChoiceText);
    choiceInteraction.getNodeGroups().getSimpleChoiceGroup().getSimpleChoices().add(newChoice);
    return newChoice;
}
Also used : P(uk.ac.ed.ph.jqtiplus.node.content.xhtml.text.P) SimpleChoice(uk.ac.ed.ph.jqtiplus.node.item.interaction.choice.SimpleChoice)

Aggregations

SimpleChoice (uk.ac.ed.ph.jqtiplus.node.item.interaction.choice.SimpleChoice)54 ChoiceInteraction (uk.ac.ed.ph.jqtiplus.node.item.interaction.ChoiceInteraction)32 Test (org.junit.Test)16 AssessmentItem (uk.ac.ed.ph.jqtiplus.node.item.AssessmentItem)16 ArrayList (java.util.ArrayList)14 JqtiExtensionManager (uk.ac.ed.ph.jqtiplus.JqtiExtensionManager)14 ResolvedAssessmentItem (uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentItem)14 QtiSerializer (uk.ac.ed.ph.jqtiplus.serialization.QtiSerializer)14 Identifier (uk.ac.ed.ph.jqtiplus.types.Identifier)14 URL (java.net.URL)12 MultipleChoiceAssessmentItemBuilder (org.olat.ims.qti21.model.xml.interactions.MultipleChoiceAssessmentItemBuilder)12 Interaction (uk.ac.ed.ph.jqtiplus.node.item.interaction.Interaction)12 SingleChoiceAssessmentItemBuilder (org.olat.ims.qti21.model.xml.interactions.SingleChoiceAssessmentItemBuilder)10 HashMap (java.util.HashMap)8 P (uk.ac.ed.ph.jqtiplus.node.content.xhtml.text.P)8 EndAttemptInteraction (uk.ac.ed.ph.jqtiplus.node.item.interaction.EndAttemptInteraction)8 Value (uk.ac.ed.ph.jqtiplus.value.Value)6 Block (uk.ac.ed.ph.jqtiplus.node.content.basic.Block)5 IOException (java.io.IOException)4 Map (java.util.Map)4