Search in sources :

Example 36 with SimpleChoice

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;
}
Also used : 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) SimpleChoice(uk.ac.ed.ph.jqtiplus.node.item.interaction.choice.SimpleChoice) Identifier(uk.ac.ed.ph.jqtiplus.types.Identifier) SingleChoiceAssessmentItemBuilder(org.olat.ims.qti21.model.xml.interactions.SingleChoiceAssessmentItemBuilder) HashMap(java.util.HashMap) 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)

Example 37 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, String prefix) {
    SimpleChoice newChoice = createSimpleChoice(choiceInteraction, text, prefix);
    choiceInteraction.getNodeGroups().getSimpleChoiceGroup().getSimpleChoices().add(newChoice);
    return newChoice;
}
Also used : SimpleChoice(uk.ac.ed.ph.jqtiplus.node.item.interaction.choice.SimpleChoice)

Example 38 with SimpleChoice

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;
}
Also used : P(uk.ac.ed.ph.jqtiplus.node.content.xhtml.text.P) SimpleChoice(uk.ac.ed.ph.jqtiplus.node.item.interaction.choice.SimpleChoice)

Example 39 with SimpleChoice

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);
}
Also used : AssessmentItemFactory.appendSimpleChoice(org.olat.ims.qti21.model.xml.AssessmentItemFactory.appendSimpleChoice) SimpleChoice(uk.ac.ed.ph.jqtiplus.node.item.interaction.choice.SimpleChoice) Block(uk.ac.ed.ph.jqtiplus.node.content.basic.Block) ChoiceInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.ChoiceInteraction) AssessmentItemFactory.appendChoiceInteraction(org.olat.ims.qti21.model.xml.AssessmentItemFactory.appendChoiceInteraction)

Example 40 with SimpleChoice

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);
}
Also used : AssessmentItemFactory.appendSimpleChoice(org.olat.ims.qti21.model.xml.AssessmentItemFactory.appendSimpleChoice) SimpleChoice(uk.ac.ed.ph.jqtiplus.node.item.interaction.choice.SimpleChoice) Block(uk.ac.ed.ph.jqtiplus.node.content.basic.Block) ChoiceInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.ChoiceInteraction) AssessmentItemFactory.appendChoiceInteraction(org.olat.ims.qti21.model.xml.AssessmentItemFactory.appendChoiceInteraction)

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