Search in sources :

Example 6 with HottextInteraction

use of uk.ac.ed.ph.jqtiplus.node.item.interaction.HottextInteraction in project openolat by klemens.

the class HottextAssessmentItemBuilder method createAssessmentItem.

private static AssessmentItem createAssessmentItem(String title, String text, String hottext) {
    AssessmentItem assessmentItem = AssessmentItemFactory.createAssessmentItem(QTI21QuestionType.hottext, title);
    // define correct answer
    Identifier responseDeclarationId = Identifier.assumedLegal("RESPONSE_1");
    Identifier correctResponseId = IdentifierGenerator.newAsIdentifier("ht");
    List<Identifier> correctResponseIds = new ArrayList<>();
    correctResponseIds.add(correctResponseId);
    ResponseDeclaration responseDeclaration = createHottextCorrectResponseDeclaration(assessmentItem, responseDeclarationId, correctResponseIds);
    assessmentItem.getNodeGroups().getResponseDeclarationGroup().getResponseDeclarations().add(responseDeclaration);
    // outcomes
    appendDefaultOutcomeDeclarations(assessmentItem, 1.0d);
    // the single choice interaction
    ItemBody itemBody = appendDefaultItemBody(assessmentItem);
    HottextInteraction hottextInteraction = appendHottextInteraction(itemBody, responseDeclarationId, 0);
    P p = new P(itemBody);
    p.getInlines().add(new TextRun(p, text));
    appendHottext(p, correctResponseId, hottext);
    hottextInteraction.getBlockStatics().add(p);
    // response processing
    ResponseProcessing responseProcessing = createResponseProcessing(assessmentItem, responseDeclarationId);
    assessmentItem.getNodeGroups().getResponseProcessingGroup().setResponseProcessing(responseProcessing);
    return assessmentItem;
}
Also used : P(uk.ac.ed.ph.jqtiplus.node.content.xhtml.text.P) Identifier(uk.ac.ed.ph.jqtiplus.types.Identifier) ComplexReferenceIdentifier(uk.ac.ed.ph.jqtiplus.types.ComplexReferenceIdentifier) AssessmentItemFactory.appendDefaultItemBody(org.olat.ims.qti21.model.xml.AssessmentItemFactory.appendDefaultItemBody) ItemBody(uk.ac.ed.ph.jqtiplus.node.content.ItemBody) ArrayList(java.util.ArrayList) AssessmentItem(uk.ac.ed.ph.jqtiplus.node.item.AssessmentItem) HottextInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.HottextInteraction) AssessmentItemFactory.appendHottextInteraction(org.olat.ims.qti21.model.xml.AssessmentItemFactory.appendHottextInteraction) TextRun(uk.ac.ed.ph.jqtiplus.node.content.basic.TextRun) AssessmentItemFactory.createResponseProcessing(org.olat.ims.qti21.model.xml.AssessmentItemFactory.createResponseProcessing) ResponseProcessing(uk.ac.ed.ph.jqtiplus.node.item.response.processing.ResponseProcessing) ResponseDeclaration(uk.ac.ed.ph.jqtiplus.node.item.response.declaration.ResponseDeclaration) AssessmentItemFactory.createHottextCorrectResponseDeclaration(org.olat.ims.qti21.model.xml.AssessmentItemFactory.createHottextCorrectResponseDeclaration)

Example 7 with HottextInteraction

use of uk.ac.ed.ph.jqtiplus.node.item.interaction.HottextInteraction in project openolat by klemens.

the class AssessmentItemFactory method appendHottextInteraction.

public static HottextInteraction appendHottextInteraction(ItemBody itemBody, Identifier responseDeclarationId, int maxChoices) {
    HottextInteraction hottextInteraction = new HottextInteraction(itemBody);
    hottextInteraction.setMaxChoices(maxChoices);
    hottextInteraction.setResponseIdentifier(responseDeclarationId);
    itemBody.getBlocks().add(hottextInteraction);
    PromptGroup prompts = new PromptGroup(hottextInteraction);
    hottextInteraction.getNodeGroups().add(prompts);
    return hottextInteraction;
}
Also used : PromptGroup(uk.ac.ed.ph.jqtiplus.group.item.interaction.PromptGroup) HottextInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.HottextInteraction)

Example 8 with HottextInteraction

use of uk.ac.ed.ph.jqtiplus.node.item.interaction.HottextInteraction in project openolat by klemens.

the class HottextAssessmentItemBuilderTest method readHottextAssessmentItem_allCorrectAnswers.

@Test
public void readHottextAssessmentItem_allCorrectAnswers() throws URISyntaxException {
    QtiSerializer qtiSerializer = new QtiSerializer(new JqtiExtensionManager());
    URL itemUrl = AssessmentItemBuilderTest.class.getResource("resources/openolat/hottext-score-all-11-4-0.xml");
    AssessmentItem assessmentItem = loadAssessmentItem(itemUrl);
    HottextAssessmentItemBuilder itemBuilder = new HottextAssessmentItemBuilder(assessmentItem, qtiSerializer);
    // basic check ChoiceInteraction
    AssessmentItem loadedItem = itemBuilder.getAssessmentItem();
    List<Interaction> interactions = loadedItem.getItemBody().findInteractions();
    Assert.assertNotNull(interactions);
    Assert.assertEquals(2, interactions.size());
    Assert.assertTrue(interactions.get(0) instanceof HottextInteraction);
    Assert.assertTrue(interactions.get(1) instanceof EndAttemptInteraction);
    // hot texts
    Choice correct1 = itemBuilder.getChoice(Identifier.assumedLegal("htebdb40344641dba115e3c8c6ce3926"));
    Assert.assertTrue(itemBuilder.isCorrect(correct1));
    Choice correct2 = itemBuilder.getChoice(Identifier.assumedLegal("ht103ce53892dea97613005a5ce76be31e"));
    Assert.assertTrue(itemBuilder.isCorrect(correct2));
    Choice wrong1 = itemBuilder.getChoice(Identifier.assumedLegal("hte11a51c3e3d86a5f7293da19a1a8700e"));
    Assert.assertFalse(itemBuilder.isCorrect(wrong1));
    // score
    Double maxScore = itemBuilder.getMaxScoreBuilder().getScore();
    Assert.assertEquals(2.0, maxScore.doubleValue(), 0.0001);
    Double minScore = itemBuilder.getMinScoreBuilder().getScore();
    Assert.assertEquals(0.0, minScore.doubleValue(), 0.0001);
    // per answer
    Assert.assertEquals(ScoreEvaluation.allCorrectAnswers, itemBuilder.getScoreEvaluationMode());
    // correct feedback
    ModalFeedbackBuilder correctFeedback = itemBuilder.getCorrectFeedback();
    Assert.assertNotNull(correctFeedback);
    Assert.assertNotNull(correctFeedback.getText());
    Assert.assertTrue(correctFeedback.getText().contains("You check the right answers"));
    // incorrect
    ModalFeedbackBuilder incorrectFeedback = itemBuilder.getIncorrectFeedback();
    Assert.assertNotNull(incorrectFeedback);
    Assert.assertNotNull(incorrectFeedback.getText());
    Assert.assertTrue(incorrectFeedback.getText().contains("Some of your anwsers are not the correct one."));
    // correct solution feedback
    ModalFeedbackBuilder correctSolutionFeedback = itemBuilder.getCorrectSolutionFeedback();
    Assert.assertNotNull(correctSolutionFeedback);
    Assert.assertNotNull(correctSolutionFeedback.getText());
    Assert.assertTrue(correctSolutionFeedback.getText().contains("A little hint towards the correct solution"));
    // hint
    ModalFeedbackBuilder hint = itemBuilder.getHint();
    Assert.assertNotNull(hint);
    Assert.assertNotNull(hint.getText());
    Assert.assertTrue(hint.getText().contains("This is an endAttemptInteraction"));
}
Also used : HottextAssessmentItemBuilder(org.olat.ims.qti21.model.xml.interactions.HottextAssessmentItemBuilder) Choice(uk.ac.ed.ph.jqtiplus.node.item.interaction.choice.Choice) JqtiExtensionManager(uk.ac.ed.ph.jqtiplus.JqtiExtensionManager) EndAttemptInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.EndAttemptInteraction) QtiSerializer(uk.ac.ed.ph.jqtiplus.serialization.QtiSerializer) HottextInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.HottextInteraction) Interaction(uk.ac.ed.ph.jqtiplus.node.item.interaction.Interaction) EndAttemptInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.EndAttemptInteraction) ResolvedAssessmentItem(uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentItem) AssessmentItem(uk.ac.ed.ph.jqtiplus.node.item.AssessmentItem) HottextInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.HottextInteraction) URL(java.net.URL) Test(org.junit.Test)

Example 9 with HottextInteraction

use of uk.ac.ed.ph.jqtiplus.node.item.interaction.HottextInteraction in project openolat by klemens.

the class AssessmentObjectComponentRenderer method renderHottext.

/*
	  <xsl:template match="qti:hottext">
	    <xsl:if test="qw:is-visible(.)">
	      <xsl:variable name="hottextInteraction" select="ancestor::qti:hottextInteraction" as="element(qti:hottextInteraction)"/>
	      <xsl:variable name="responseIdentifier" select="$hottextInteraction/@responseIdentifier" as="xs:string"/>
	      <span class="hottext">
	        <input type="{if ($hottextInteraction/@maxChoices=1) then 'radio' else 'checkbox'}"
	             name="qtiworks_response_{$responseIdentifier}"
	             value="{@identifier}">
	          <xsl:if test="$isItemSessionEnded">
	            <xsl:attribute name="disabled">disabled</xsl:attribute>
	          </xsl:if>
	          <xsl:if test="qw:value-contains(qw:get-response-value(/, $responseIdentifier), @identifier)">
	            <xsl:attribute name="checked" select="'checked'"/>
	          </xsl:if>
	        </input>
	        <xsl:apply-templates/>
	      </span>
	    </xsl:if>
	  </xsl:template>
	 */
private void renderHottext(AssessmentRenderer renderer, StringOutput sb, ResolvedAssessmentItem resolvedAssessmentItem, ItemSessionState itemSessionState, Hottext hottext, AssessmentObjectComponent component, URLBuilder ubu, Translator translator) {
    if (!isVisible(hottext, itemSessionState))
        return;
    HottextInteraction interaction = null;
    for (QtiNode parentNode = hottext.getParent(); parentNode.getParent() != null; parentNode = parentNode.getParent()) {
        if (parentNode instanceof HottextInteraction) {
            interaction = (HottextInteraction) parentNode;
            break;
        }
    }
    if (interaction != null) {
        sb.append("<span class='hottext'><input type='");
        if (interaction.getMaxChoices() == 1) {
            sb.append("radio");
        } else {
            sb.append("checkbox");
        }
        String guid = "oo_" + CodeHelper.getRAMUniqueID();
        String responseUniqueId = component.getResponseUniqueIdentifier(itemSessionState, interaction);
        sb.append("' id='").append(guid).append("' name='qtiworks_response_").append(responseUniqueId).append("'").append(" value='").append(hottext.getIdentifier().toString()).append("'");
        if (component.isItemSessionEnded(itemSessionState, renderer.isSolutionMode())) {
            sb.append(" disabled");
        }
        AssessmentItem assessmentItem = resolvedAssessmentItem.getRootNodeLookup().extractIfSuccessful();
        Value responseValue = getResponseValue(assessmentItem, itemSessionState, interaction.getResponseIdentifier(), renderer.isSolutionMode());
        if (valueContains(responseValue, hottext.getIdentifier())) {
            sb.append(" checked");
        }
        sb.append(" />");
        sb.append("<label for='").append(guid).append("'>");
        hottext.getInlineStatics().forEach((inline) -> renderInline(renderer, sb, component, resolvedAssessmentItem, itemSessionState, inline, ubu, translator));
        FormJSHelper.appendFlexiFormDirtyOn(sb, component.getQtiItem().getRootForm(), "change click", guid);
        sb.append("</label></span>");
    }
}
Also used : AssessmentRenderFunctions.getOutcomeValue(org.olat.ims.qti21.ui.components.AssessmentRenderFunctions.getOutcomeValue) AssessmentRenderFunctions.extractRecordFieldValue(org.olat.ims.qti21.ui.components.AssessmentRenderFunctions.extractRecordFieldValue) Value(uk.ac.ed.ph.jqtiplus.value.Value) AssessmentRenderFunctions.getHtmlAttributeValue(org.olat.ims.qti21.ui.components.AssessmentRenderFunctions.getHtmlAttributeValue) AssessmentRenderFunctions.renderOrderedCardinalityValue(org.olat.ims.qti21.ui.components.AssessmentRenderFunctions.renderOrderedCardinalityValue) AssessmentRenderFunctions.isMultipleCardinalityValue(org.olat.ims.qti21.ui.components.AssessmentRenderFunctions.isMultipleCardinalityValue) AssessmentRenderFunctions.renderSingleCardinalityValue(org.olat.ims.qti21.ui.components.AssessmentRenderFunctions.renderSingleCardinalityValue) AssessmentRenderFunctions.renderMultipleCardinalityValue(org.olat.ims.qti21.ui.components.AssessmentRenderFunctions.renderMultipleCardinalityValue) IdentifierValue(uk.ac.ed.ph.jqtiplus.value.IdentifierValue) AssessmentRenderFunctions.getTemplateValue(org.olat.ims.qti21.ui.components.AssessmentRenderFunctions.getTemplateValue) AssessmentRenderFunctions.renderRecordCardinalityValue(org.olat.ims.qti21.ui.components.AssessmentRenderFunctions.renderRecordCardinalityValue) AssessmentRenderFunctions.getResponseValue(org.olat.ims.qti21.ui.components.AssessmentRenderFunctions.getResponseValue) AssessmentRenderFunctions.isNullValue(org.olat.ims.qti21.ui.components.AssessmentRenderFunctions.isNullValue) AssessmentRenderFunctions.isSingleCardinalityValue(org.olat.ims.qti21.ui.components.AssessmentRenderFunctions.isSingleCardinalityValue) AssessmentRenderFunctions.isRecordCardinalityValue(org.olat.ims.qti21.ui.components.AssessmentRenderFunctions.isRecordCardinalityValue) AssessmentRenderFunctions.isOrderedCardinalityValue(org.olat.ims.qti21.ui.components.AssessmentRenderFunctions.isOrderedCardinalityValue) AssessmentRenderFunctions.isMathsContentValue(org.olat.ims.qti21.ui.components.AssessmentRenderFunctions.isMathsContentValue) SingleValue(uk.ac.ed.ph.jqtiplus.value.SingleValue) HottextInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.HottextInteraction) ResolvedAssessmentItem(uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentItem) AssessmentItem(uk.ac.ed.ph.jqtiplus.node.item.AssessmentItem) AssessmentRenderFunctions.contentAsString(org.olat.ims.qti21.ui.components.AssessmentRenderFunctions.contentAsString) QtiNode(uk.ac.ed.ph.jqtiplus.node.QtiNode)

Example 10 with HottextInteraction

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

the class QTI21AssessmentItemStatisticsController method interactionControllerFactory.

private Component interactionControllerFactory(UserRequest ureq, Interaction interaction, StatisticsItem itemStats) {
    Controller interactionCtrl = null;
    if (interaction instanceof ChoiceInteraction) {
        interactionCtrl = new SimpleChoiceInteractionStatisticsController(ureq, getWindowControl(), itemRef, item, (ChoiceInteraction) interaction, itemStats, resourceResult);
    } else if (interaction instanceof MatchInteraction) {
        String responseIdentifier = interaction.getResponseIdentifier().toString();
        if (responseIdentifier.startsWith("KPRIM_") || QTI21QuestionType.hasClass(interaction, QTI21Constants.CSS_MATCH_KPRIM)) {
            interactionCtrl = new KPrimStatisticsController(ureq, getWindowControl(), itemRef, item, (MatchInteraction) interaction, resourceResult);
        } else {
            interactionCtrl = new MatchStatisticsController(ureq, getWindowControl(), itemRef, item, (MatchInteraction) interaction, resourceResult);
        }
    } else if (interaction instanceof HotspotInteraction) {
        interactionCtrl = new HotspotInteractionStatisticsController(ureq, getWindowControl(), itemRef, item, (HotspotInteraction) interaction, itemStats, resourceResult);
    } else if (interaction instanceof HottextInteraction) {
        interactionCtrl = new HottextInteractionStatisticsController(ureq, getWindowControl(), itemRef, item, (HottextInteraction) interaction, itemStats, resourceResult);
    }
    if (interactionCtrl == null) {
        interactionCtrl = new UnsupportedInteractionController(ureq, getWindowControl(), interaction);
    }
    listenTo(interactionCtrl);
    return interactionCtrl.getInitialComponent();
}
Also used : MatchInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.MatchInteraction) KPrimStatisticsController(org.olat.ims.qti21.ui.statistics.interactions.KPrimStatisticsController) HotspotInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.HotspotInteraction) HottextInteractionStatisticsController(org.olat.ims.qti21.ui.statistics.interactions.HottextInteractionStatisticsController) ChoiceInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.ChoiceInteraction) SimpleChoiceInteractionStatisticsController(org.olat.ims.qti21.ui.statistics.interactions.SimpleChoiceInteractionStatisticsController) HottextInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.HottextInteraction) MatchStatisticsController(org.olat.ims.qti21.ui.statistics.interactions.MatchStatisticsController) UnsupportedInteractionController(org.olat.ims.qti21.ui.statistics.interactions.UnsupportedInteractionController) TextEntryInteractionsStatisticsController(org.olat.ims.qti21.ui.statistics.interactions.TextEntryInteractionsStatisticsController) HotspotInteractionStatisticsController(org.olat.ims.qti21.ui.statistics.interactions.HotspotInteractionStatisticsController) MatchStatisticsController(org.olat.ims.qti21.ui.statistics.interactions.MatchStatisticsController) UserFilterController(org.olat.modules.assessment.ui.UserFilterController) SimpleChoiceInteractionStatisticsController(org.olat.ims.qti21.ui.statistics.interactions.SimpleChoiceInteractionStatisticsController) KPrimStatisticsController(org.olat.ims.qti21.ui.statistics.interactions.KPrimStatisticsController) HottextInteractionStatisticsController(org.olat.ims.qti21.ui.statistics.interactions.HottextInteractionStatisticsController) Controller(org.olat.core.gui.control.Controller) BasicController(org.olat.core.gui.control.controller.BasicController) UnsupportedInteractionController(org.olat.ims.qti21.ui.statistics.interactions.UnsupportedInteractionController) HotspotInteractionStatisticsController(org.olat.ims.qti21.ui.statistics.interactions.HotspotInteractionStatisticsController)

Aggregations

HottextInteraction (uk.ac.ed.ph.jqtiplus.node.item.interaction.HottextInteraction)16 AssessmentItem (uk.ac.ed.ph.jqtiplus.node.item.AssessmentItem)8 ResolvedAssessmentItem (uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentItem)6 URL (java.net.URL)4 Test (org.junit.Test)4 AssessmentItemFactory.appendHottextInteraction (org.olat.ims.qti21.model.xml.AssessmentItemFactory.appendHottextInteraction)4 HottextAssessmentItemBuilder (org.olat.ims.qti21.model.xml.interactions.HottextAssessmentItemBuilder)4 JqtiExtensionManager (uk.ac.ed.ph.jqtiplus.JqtiExtensionManager)4 EndAttemptInteraction (uk.ac.ed.ph.jqtiplus.node.item.interaction.EndAttemptInteraction)4 Interaction (uk.ac.ed.ph.jqtiplus.node.item.interaction.Interaction)4 Choice (uk.ac.ed.ph.jqtiplus.node.item.interaction.choice.Choice)4 ResponseDeclaration (uk.ac.ed.ph.jqtiplus.node.item.response.declaration.ResponseDeclaration)4 QtiSerializer (uk.ac.ed.ph.jqtiplus.serialization.QtiSerializer)4 ChoiceInteraction (uk.ac.ed.ph.jqtiplus.node.item.interaction.ChoiceInteraction)3 HotspotInteraction (uk.ac.ed.ph.jqtiplus.node.item.interaction.HotspotInteraction)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 Controller (org.olat.core.gui.control.Controller)2 BasicController (org.olat.core.gui.control.controller.BasicController)2 StringOutput (org.olat.core.gui.render.StringOutput)2