Search in sources :

Example 41 with AssessmentItem

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

the class FIBAssessmentItemBuilder method createAssessmentItem.

private static AssessmentItem createAssessmentItem(String title, EntryType type) {
    AssessmentItem assessmentItem = AssessmentItemFactory.createAssessmentItem(QTI21QuestionType.fib, title);
    // define the response
    Identifier responseDeclarationId = Identifier.assumedLegal("RESPONSE_1");
    if (type == EntryType.numerical) {
        ResponseDeclaration responseDeclaration = createNumericalEntryResponseDeclaration(assessmentItem, responseDeclarationId, 42);
        assessmentItem.getNodeGroups().getResponseDeclarationGroup().getResponseDeclarations().add(responseDeclaration);
    } else {
        ResponseDeclaration responseDeclaration = createTextEntryResponseDeclaration(assessmentItem, responseDeclarationId, "gap", Collections.emptyList());
        assessmentItem.getNodeGroups().getResponseDeclarationGroup().getResponseDeclarations().add(responseDeclaration);
    }
    // outcomes
    appendDefaultOutcomeDeclarations(assessmentItem, 1.0d);
    ItemBody itemBody = appendDefaultItemBody(assessmentItem);
    appendTextEntryInteraction(itemBody, responseDeclarationId);
    // response processing
    ResponseProcessing responseProcessing = createResponseProcessing(assessmentItem, responseDeclarationId);
    assessmentItem.getNodeGroups().getResponseProcessingGroup().setResponseProcessing(responseProcessing);
    return assessmentItem;
}
Also used : 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) AssessmentItem(uk.ac.ed.ph.jqtiplus.node.item.AssessmentItem) AssessmentItemFactory.createResponseProcessing(org.olat.ims.qti21.model.xml.AssessmentItemFactory.createResponseProcessing) ResponseProcessing(uk.ac.ed.ph.jqtiplus.node.item.response.processing.ResponseProcessing) AssessmentItemFactory.createNumericalEntryResponseDeclaration(org.olat.ims.qti21.model.xml.AssessmentItemFactory.createNumericalEntryResponseDeclaration) ResponseDeclaration(uk.ac.ed.ph.jqtiplus.node.item.response.declaration.ResponseDeclaration) AssessmentItemFactory.createTextEntryResponseDeclaration(org.olat.ims.qti21.model.xml.AssessmentItemFactory.createTextEntryResponseDeclaration)

Example 42 with AssessmentItem

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

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 43 with AssessmentItem

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

the class MultipleChoiceAssessmentItemBuilder method createAssessmentItem.

private static AssessmentItem createAssessmentItem(String title, String defaultAnswer) {
    AssessmentItem assessmentItem = AssessmentItemFactory.createAssessmentItem(QTI21QuestionType.mc, title);
    NodeGroupList nodeGroups = assessmentItem.getNodeGroups();
    Identifier responseDeclarationId = Identifier.assumedLegal("RESPONSE_1");
    Identifier correctResponseId = IdentifierGenerator.newAsIdentifier("mc");
    // define correct answer
    ResponseDeclaration responseDeclaration = createMultipleChoiceCorrectResponseDeclaration(assessmentItem, responseDeclarationId, Collections.singletonList(correctResponseId));
    nodeGroups.getResponseDeclarationGroup().getResponseDeclarations().add(responseDeclaration);
    // outcomes
    appendDefaultOutcomeDeclarations(assessmentItem, 1.0d);
    // the single choice interaction
    ItemBody itemBody = appendDefaultItemBody(assessmentItem);
    ChoiceInteraction choiceInteraction = appendChoiceInteraction(itemBody, responseDeclarationId, 0, true);
    appendSimpleChoice(choiceInteraction, defaultAnswer, correctResponseId);
    // response processing
    ResponseProcessing responseProcessing = createResponseProcessing(assessmentItem, responseDeclarationId);
    assessmentItem.getNodeGroups().getResponseProcessingGroup().setResponseProcessing(responseProcessing);
    return assessmentItem;
}
Also used : 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) NodeGroupList(uk.ac.ed.ph.jqtiplus.group.NodeGroupList) ChoiceInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.ChoiceInteraction) AssessmentItemFactory.appendChoiceInteraction(org.olat.ims.qti21.model.xml.AssessmentItemFactory.appendChoiceInteraction) AssessmentItem(uk.ac.ed.ph.jqtiplus.node.item.AssessmentItem) ResponseProcessing(uk.ac.ed.ph.jqtiplus.node.item.response.processing.ResponseProcessing) AssessmentItemFactory.createResponseProcessing(org.olat.ims.qti21.model.xml.AssessmentItemFactory.createResponseProcessing) ResponseDeclaration(uk.ac.ed.ph.jqtiplus.node.item.response.declaration.ResponseDeclaration) AssessmentItemFactory.createMultipleChoiceCorrectResponseDeclaration(org.olat.ims.qti21.model.xml.AssessmentItemFactory.createMultipleChoiceCorrectResponseDeclaration)

Example 44 with AssessmentItem

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

the class SingleChoiceAssessmentItemBuilder method createAssessmentItem.

private static AssessmentItem createAssessmentItem(String title, String defaultAnswer) {
    AssessmentItem assessmentItem = AssessmentItemFactory.createAssessmentItem(QTI21QuestionType.sc, title);
    // define correct answer
    Identifier responseDeclarationId = Identifier.assumedLegal("RESPONSE_1");
    Identifier correctResponseId = IdentifierGenerator.newAsIdentifier("sc");
    ResponseDeclaration responseDeclaration = createSingleChoiceCorrectResponseDeclaration(assessmentItem, responseDeclarationId, correctResponseId);
    assessmentItem.getNodeGroups().getResponseDeclarationGroup().getResponseDeclarations().add(responseDeclaration);
    // outcomes
    appendDefaultOutcomeDeclarations(assessmentItem, 1.0d);
    // the single choice interaction
    ItemBody itemBody = appendDefaultItemBody(assessmentItem);
    ChoiceInteraction choiceInteraction = appendChoiceInteraction(itemBody, responseDeclarationId, 1, true);
    appendSimpleChoice(choiceInteraction, defaultAnswer, correctResponseId);
    // response processing
    ResponseProcessing responseProcessing = createResponseProcessing(assessmentItem, responseDeclarationId);
    assessmentItem.getNodeGroups().getResponseProcessingGroup().setResponseProcessing(responseProcessing);
    return assessmentItem;
}
Also used : 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) ChoiceInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.ChoiceInteraction) AssessmentItemFactory.appendChoiceInteraction(org.olat.ims.qti21.model.xml.AssessmentItemFactory.appendChoiceInteraction) AssessmentItem(uk.ac.ed.ph.jqtiplus.node.item.AssessmentItem) ResponseProcessing(uk.ac.ed.ph.jqtiplus.node.item.response.processing.ResponseProcessing) AssessmentItemFactory.createResponseProcessing(org.olat.ims.qti21.model.xml.AssessmentItemFactory.createResponseProcessing) AssessmentItemFactory.createSingleChoiceCorrectResponseDeclaration(org.olat.ims.qti21.model.xml.AssessmentItemFactory.createSingleChoiceCorrectResponseDeclaration) ResponseDeclaration(uk.ac.ed.ph.jqtiplus.node.item.response.declaration.ResponseDeclaration)

Example 45 with AssessmentItem

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

the class QTI21QPoolServiceProvider method copyItem.

@Override
public void copyItem(QuestionItemFull original, QuestionItemFull copy) {
    VFSContainer originalDir = qpoolFileStorage.getContainer(original.getDirectory());
    VFSContainer copyDir = qpoolFileStorage.getContainer(copy.getDirectory());
    VFSManager.copyContent(originalDir, copyDir);
    File file = qpoolService.getRootFile(copy);
    File resourceDirectory = qpoolService.getRootDirectory(copy);
    URI assessmentItemUri = file.toURI();
    File itemFile = qpoolService.getRootFile(copy);
    ResolvedAssessmentItem resolvedAssessmentItem = qtiService.loadAndResolveAssessmentItem(assessmentItemUri, resourceDirectory);
    AssessmentItem assessmentItem = resolvedAssessmentItem.getRootNodeLookup().extractIfSuccessful();
    assessmentItem.setTitle(copy.getTitle());
    qtiService.persistAssessmentObject(itemFile, assessmentItem);
}
Also used : ResolvedAssessmentItem(uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentItem) VFSContainer(org.olat.core.util.vfs.VFSContainer) ResolvedAssessmentItem(uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentItem) AssessmentItem(uk.ac.ed.ph.jqtiplus.node.item.AssessmentItem) File(java.io.File) URI(java.net.URI)

Aggregations

AssessmentItem (uk.ac.ed.ph.jqtiplus.node.item.AssessmentItem)174 ResolvedAssessmentItem (uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentItem)132 Test (org.junit.Test)56 File (java.io.File)42 JqtiExtensionManager (uk.ac.ed.ph.jqtiplus.JqtiExtensionManager)42 QtiSerializer (uk.ac.ed.ph.jqtiplus.serialization.QtiSerializer)42 URL (java.net.URL)34 Interaction (uk.ac.ed.ph.jqtiplus.node.item.interaction.Interaction)34 AssessmentItemRef (uk.ac.ed.ph.jqtiplus.node.test.AssessmentItemRef)32 Identifier (uk.ac.ed.ph.jqtiplus.types.Identifier)32 ItemBody (uk.ac.ed.ph.jqtiplus.node.content.ItemBody)28 ChoiceInteraction (uk.ac.ed.ph.jqtiplus.node.item.interaction.ChoiceInteraction)28 ResponseDeclaration (uk.ac.ed.ph.jqtiplus.node.item.response.declaration.ResponseDeclaration)28 URI (java.net.URI)26 ResponseProcessing (uk.ac.ed.ph.jqtiplus.node.item.response.processing.ResponseProcessing)22 URISyntaxException (java.net.URISyntaxException)20 AssessmentItemFactory.appendDefaultItemBody (org.olat.ims.qti21.model.xml.AssessmentItemFactory.appendDefaultItemBody)20 AssessmentItemFactory.createResponseProcessing (org.olat.ims.qti21.model.xml.AssessmentItemFactory.createResponseProcessing)20 MultipleChoiceAssessmentItemBuilder (org.olat.ims.qti21.model.xml.interactions.MultipleChoiceAssessmentItemBuilder)20 SingleChoiceAssessmentItemBuilder (org.olat.ims.qti21.model.xml.interactions.SingleChoiceAssessmentItemBuilder)20