Search in sources :

Example 31 with Block

use of uk.ac.ed.ph.jqtiplus.node.content.basic.Block 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 32 with Block

use of uk.ac.ed.ph.jqtiplus.node.content.basic.Block 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)

Example 33 with Block

use of uk.ac.ed.ph.jqtiplus.node.content.basic.Block in project OpenOLAT by OpenOLAT.

the class DrawingAssessmentItemBuilder method extractExtendedTextInteraction.

private void extractExtendedTextInteraction() {
    try (StringOutput sb = new StringOutput()) {
        List<Block> blocks = assessmentItem.getItemBody().getBlocks();
        for (Block block : blocks) {
            if (block instanceof DrawingInteraction) {
                drawingInteraction = (DrawingInteraction) block;
                responseIdentifier = drawingInteraction.getResponseIdentifier();
                break;
            } else {
                serializeJqtiObject(block, sb);
            }
        }
        question = sb.toString();
    } catch (IOException e) {
        log.error("", e);
    }
}
Also used : Block(uk.ac.ed.ph.jqtiplus.node.content.basic.Block) StringOutput(org.olat.core.gui.render.StringOutput) IOException(java.io.IOException) AssessmentItemFactory.appendDrawingInteraction(org.olat.ims.qti21.model.xml.AssessmentItemFactory.appendDrawingInteraction) DrawingInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.DrawingInteraction)

Example 34 with Block

use of uk.ac.ed.ph.jqtiplus.node.content.basic.Block in project OpenOLAT by OpenOLAT.

the class FIBAssessmentItemBuilder method buildItemBody.

@Override
protected void buildItemBody() {
    // remove current blocks
    List<Block> blocks = assessmentItem.getItemBody().getBlocks();
    blocks.clear();
    // add question
    getHtmlHelper().appendHtml(assessmentItem.getItemBody(), question);
    // transfer text entry to the interactions
    List<Interaction> interactions = assessmentItem.getItemBody().findInteractions();
    List<String> usedResponseIdentifiers = new ArrayList<>(interactions.size());
    for (Interaction interaction : interactions) {
        if (interaction instanceof TextEntryInteraction && interaction.getResponseIdentifier() != null) {
            TextEntryInteraction textEntryInteraction = (TextEntryInteraction) interaction;
            String responseIdentifier = interaction.getResponseIdentifier().toString();
            AbstractEntry entry = responseIdentifierToTextEntry.get(responseIdentifier);
            if (entry != null) {
                textEntryInteraction.setPlaceholderText(entry.getPlaceholder());
                textEntryInteraction.setExpectedLength(entry.getExpectedLength());
            }
            usedResponseIdentifiers.add(responseIdentifier);
        }
    }
    List<String> mappedResponseIdentifiers = new ArrayList<>(responseIdentifierToTextEntry.keySet());
    mappedResponseIdentifiers.removeAll(usedResponseIdentifiers);
    for (String mappedResponseIdentifier : mappedResponseIdentifiers) {
        responseIdentifierToTextEntry.remove(mappedResponseIdentifier);
    }
}
Also used : AssessmentItemFactory.appendTextEntryInteraction(org.olat.ims.qti21.model.xml.AssessmentItemFactory.appendTextEntryInteraction) TextEntryInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.TextEntryInteraction) AssessmentItemFactory.appendTextEntryInteraction(org.olat.ims.qti21.model.xml.AssessmentItemFactory.appendTextEntryInteraction) TextEntryInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.TextEntryInteraction) Interaction(uk.ac.ed.ph.jqtiplus.node.item.interaction.Interaction) ArrayList(java.util.ArrayList) Block(uk.ac.ed.ph.jqtiplus.node.content.basic.Block)

Example 35 with Block

use of uk.ac.ed.ph.jqtiplus.node.content.basic.Block in project OpenOLAT by OpenOLAT.

the class QTI21WordExport method renderAssessmentItem.

public static void renderAssessmentItem(AssessmentItem item, File itemFile, File mediaDir, OpenXMLDocument document, boolean withResponses, Translator translator, AssessmentHtmlBuilder htmlBuilder) {
    StringBuilder addText = new StringBuilder();
    QTI21QuestionType type = QTI21QuestionType.getType(item);
    String typeDescription = "";
    switch(type) {
        case sc:
            typeDescription = translator.translate("form.choice");
            break;
        case mc:
            typeDescription = translator.translate("form.choice");
            break;
        case fib:
            typeDescription = translator.translate("form.fib");
            break;
        case numerical:
            typeDescription = translator.translate("form.fib");
            break;
        case kprim:
            typeDescription = translator.translate("form.kprim");
            break;
        case hotspot:
            typeDescription = translator.translate("form.hotspot");
            break;
        case essay:
            typeDescription = translator.translate("form.essay");
            break;
        case upload:
            typeDescription = translator.translate("form.upload");
            break;
        case drawing:
            typeDescription = translator.translate("form.drawing");
            break;
        case match:
            typeDescription = translator.translate("form.match");
            break;
        default:
            typeDescription = null;
            break;
    }
    Double maxScore = QtiNodesExtractor.extractMaxScore(item);
    if (StringHelper.containsNonWhitespace(typeDescription) || maxScore != null) {
        if (StringHelper.containsNonWhitespace(typeDescription)) {
            addText.append("(").append(typeDescription).append(")");
        }
        if (maxScore != null) {
            addText.append(" - ").append(AssessmentHelper.getRoundedScore(maxScore));
        }
    }
    String title = item.getTitle();
    document.appendHeading1(title, addText.toString());
    List<Block> itemBodyBlocks = item.getItemBody().getBlocks();
    String html = htmlBuilder.blocksString(itemBodyBlocks);
    document.appendHtmlText(html, true, new QTI21AndHTMLToOpenXMLHandler(document, item, itemFile, mediaDir, withResponses, htmlBuilder, translator));
    if (withResponses && (type == QTI21QuestionType.essay || type == QTI21QuestionType.upload || type == QTI21QuestionType.drawing)) {
        renderCorrectSolutionForWord(item, document, translator, htmlBuilder);
    }
}
Also used : QTI21QuestionType(org.olat.ims.qti21.model.QTI21QuestionType) RubricBlock(uk.ac.ed.ph.jqtiplus.node.content.variable.RubricBlock) Block(uk.ac.ed.ph.jqtiplus.node.content.basic.Block)

Aggregations

Block (uk.ac.ed.ph.jqtiplus.node.content.basic.Block)50 StringOutput (org.olat.core.gui.render.StringOutput)24 IOException (java.io.IOException)20 ArrayList (java.util.ArrayList)18 MatchInteraction (uk.ac.ed.ph.jqtiplus.node.item.interaction.MatchInteraction)12 ChoiceInteraction (uk.ac.ed.ph.jqtiplus.node.item.interaction.ChoiceInteraction)10 Interaction (uk.ac.ed.ph.jqtiplus.node.item.interaction.Interaction)8 StreamResult (javax.xml.transform.stream.StreamResult)6 ItemBody (uk.ac.ed.ph.jqtiplus.node.content.ItemBody)6 AssessmentItem (uk.ac.ed.ph.jqtiplus.node.item.AssessmentItem)6 DrawingInteraction (uk.ac.ed.ph.jqtiplus.node.item.interaction.DrawingInteraction)6 ExtendedTextInteraction (uk.ac.ed.ph.jqtiplus.node.item.interaction.ExtendedTextInteraction)6 HotspotInteraction (uk.ac.ed.ph.jqtiplus.node.item.interaction.HotspotInteraction)6 UploadInteraction (uk.ac.ed.ph.jqtiplus.node.item.interaction.UploadInteraction)6 Test (org.junit.Test)4 AssessmentItemFactory.appendExtendedTextInteraction (org.olat.ims.qti21.model.xml.AssessmentItemFactory.appendExtendedTextInteraction)4 AssessmentItemFactory.appendHotspotInteraction (org.olat.ims.qti21.model.xml.AssessmentItemFactory.appendHotspotInteraction)4 Flow (uk.ac.ed.ph.jqtiplus.node.content.basic.Flow)4 ResolvedAssessmentItem (uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentItem)4 ItemSessionState (uk.ac.ed.ph.jqtiplus.state.ItemSessionState)4