Search in sources :

Example 6 with TextEntryAlternative

use of org.olat.ims.qti21.model.xml.interactions.FIBAssessmentItemBuilder.TextEntryAlternative in project openolat by klemens.

the class AssessmentItemFactory method createTextEntryResponseDeclaration.

public static ResponseDeclaration createTextEntryResponseDeclaration(AssessmentItem assessmentItem, Identifier declarationId, String response, Double score, boolean caseSensitive, List<TextEntryAlternative> alternatives) {
    ResponseDeclaration responseDeclaration = new ResponseDeclaration(assessmentItem);
    responseDeclaration.setIdentifier(declarationId);
    responseDeclaration.setCardinality(Cardinality.SINGLE);
    responseDeclaration.setBaseType(BaseType.STRING);
    // correct response
    CorrectResponse correctResponse = new CorrectResponse(responseDeclaration);
    responseDeclaration.setCorrectResponse(correctResponse);
    appendStringValue(correctResponse, response);
    // mapping
    Mapping mapping = new Mapping(responseDeclaration);
    mapping.setDefaultValue(0.0d);
    responseDeclaration.setMapping(mapping);
    {
        // map correct response
        MapEntry mapEntry = new MapEntry(mapping);
        mapEntry.setMapKey(new StringValue(response));
        mapEntry.setMappedValue(score);
        mapEntry.setCaseSensitive(new Boolean(caseSensitive));
        mapping.getMapEntries().add(mapEntry);
    }
    // map alternatives
    if (alternatives != null && alternatives.size() > 0) {
        for (TextEntryAlternative alternative : alternatives) {
            if (StringHelper.containsNonWhitespace(alternative.getAlternative())) {
                MapEntry mapEntry = new MapEntry(mapping);
                mapEntry.setMapKey(new StringValue(alternative.getAlternative()));
                mapEntry.setMappedValue(score);
                mapEntry.setCaseSensitive(new Boolean(caseSensitive));
                mapping.getMapEntries().add(mapEntry);
            }
        }
    }
    return responseDeclaration;
}
Also used : MapEntry(uk.ac.ed.ph.jqtiplus.node.item.response.declaration.MapEntry) Mapping(uk.ac.ed.ph.jqtiplus.node.item.response.declaration.Mapping) CorrectResponse(uk.ac.ed.ph.jqtiplus.node.item.CorrectResponse) StringValue(uk.ac.ed.ph.jqtiplus.value.StringValue) TextEntryAlternative(org.olat.ims.qti21.model.xml.interactions.FIBAssessmentItemBuilder.TextEntryAlternative) ResponseDeclaration(uk.ac.ed.ph.jqtiplus.node.item.response.declaration.ResponseDeclaration)

Example 7 with TextEntryAlternative

use of org.olat.ims.qti21.model.xml.interactions.FIBAssessmentItemBuilder.TextEntryAlternative in project openolat by klemens.

the class FIBTextEntrySettingsController method initForm.

@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
    formLayout.setElementCssClass("o_sel_gap_entry_form");
    String solution = interaction.getSolution();
    solutionEl = uifactory.addTextElement("fib.solution", "fib.solution", 256, solution, formLayout);
    solutionEl.setElementCssClass("o_sel_gap_entry_solution");
    solutionEl.setEnabled(!restrictedEdit && !readOnly);
    if (!StringHelper.containsNonWhitespace(solution)) {
        solutionEl.setFocus(true);
    }
    String placeholder = interaction.getPlaceholder();
    placeholderEl = uifactory.addTextElement("fib.placeholder", "fib.placeholder", 256, placeholder, formLayout);
    placeholderEl.setElementCssClass("o_sel_gap_entry_placeholder");
    placeholderEl.setEnabled(!restrictedEdit && !readOnly);
    String alternativesPage = velocity_root + "/fib_alternatives.html";
    alternativesCont = FormLayoutContainer.createCustomFormLayout("alternatives.list", getTranslator(), alternativesPage);
    alternativesCont.setRootForm(mainForm);
    formLayout.add(alternativesCont);
    alternativesCont.setLabel("fib.alternative", null);
    alternativesCont.setHelpText(translate("fib.alternative.help"));
    alternativesCont.setHelpUrlForManualPage("Test editor QTI 2.1 in detail#details_testeditor_fragetypen_fib");
    alternativesCont.contextPut("alternatives", alternativeRows);
    addFirstAlternative = uifactory.addFormLink("add.first.alternative", "add", "", null, alternativesCont, Link.LINK | Link.NONTRANSLATED);
    addFirstAlternative.setIconLeftCSS("o_icon o_icon-lg o_icon_add");
    addFirstAlternative.setVisible(!restrictedEdit && !readOnly);
    List<TextEntryAlternative> alternatives = interaction.getAlternatives();
    if (alternatives != null && alternatives.size() > 0) {
        for (TextEntryAlternative alternative : alternatives) {
            appendAlternative(alternative, null, false);
        }
    }
    Integer expectedLength = interaction.getExpectedLength();
    String expectedLengthStr = expectedLength == null ? null : expectedLength.toString();
    expectedLengthEl = uifactory.addTextElement("fib.expectedLength", "fib.expectedLength", 256, expectedLengthStr, formLayout);
    expectedLengthEl.setEnabled(!restrictedEdit && !readOnly);
    caseSensitiveEl = uifactory.addCheckboxesHorizontal("fib.caseSensitive", "fib.caseSensitive", formLayout, onKeys, new String[] { "" });
    caseSensitiveEl.setEnabled(!restrictedEdit && !readOnly);
    if (interaction.isCaseSensitive()) {
        caseSensitiveEl.select(onKeys[0], true);
    }
    // Submit Button
    FormLayoutContainer buttonsContainer = FormLayoutContainer.createButtonLayout("buttons", getTranslator());
    buttonsContainer.setRootForm(mainForm);
    formLayout.add(buttonsContainer);
    uifactory.addFormCancelButton("cancel", buttonsContainer, ureq, getWindowControl());
    if (!restrictedEdit && !readOnly) {
        uifactory.addFormSubmitButton("submit", buttonsContainer);
    }
}
Also used : FormLayoutContainer(org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer) TextEntryAlternative(org.olat.ims.qti21.model.xml.interactions.FIBAssessmentItemBuilder.TextEntryAlternative)

Example 8 with TextEntryAlternative

use of org.olat.ims.qti21.model.xml.interactions.FIBAssessmentItemBuilder.TextEntryAlternative in project openolat by klemens.

the class FIBTextEntrySettingsController method formOK.

@Override
protected void formOK(UserRequest ureq) {
    interaction.setSolution(solutionEl.getValue());
    interaction.setPlaceholder(placeholderEl.getValue());
    List<TextEntryAlternative> alternatives = new ArrayList<>(alternativeRows.size());
    for (AlternativeRow row : alternativeRows) {
        TextEntryAlternative alternative = row.getAlternative();
        String val = row.getAlternativeEl().getValue();
        int indexSeparator = val.indexOf(';');
        // Don't split single ;, or &auml;
        if (indexSeparator >= 0 && val.length() > 1 && indexSeparator != val.length() - 1) {
            String[] valArr = val.split("[;]");
            for (int i = 0; i < valArr.length; i++) {
                if (i == 0) {
                    alternative.setAlternative(valArr[i]);
                    alternatives.add(alternative);
                } else {
                    TextEntryAlternative newAlternative = new TextEntryAlternative();
                    newAlternative.setAlternative(valArr[i]);
                    newAlternative.setScore(alternative.getScore());
                    alternatives.add(newAlternative);
                }
            }
        } else {
            alternative.setAlternative(val);
            alternatives.add(alternative);
        }
    }
    interaction.setAlternatives(alternatives);
    interaction.setCaseSensitive(caseSensitiveEl.isAtLeastSelected(1));
    if (StringHelper.containsNonWhitespace(expectedLengthEl.getValue())) {
        interaction.setExpectedLength(new Integer(expectedLengthEl.getValue()));
    } else {
        interaction.setExpectedLength(null);
    }
    fireEvent(ureq, Event.DONE_EVENT);
}
Also used : ArrayList(java.util.ArrayList) TextEntryAlternative(org.olat.ims.qti21.model.xml.interactions.FIBAssessmentItemBuilder.TextEntryAlternative)

Aggregations

TextEntryAlternative (org.olat.ims.qti21.model.xml.interactions.FIBAssessmentItemBuilder.TextEntryAlternative)8 CorrectResponse (uk.ac.ed.ph.jqtiplus.node.item.CorrectResponse)4 ResponseDeclaration (uk.ac.ed.ph.jqtiplus.node.item.response.declaration.ResponseDeclaration)4 ArrayList (java.util.ArrayList)2 FormLayoutContainer (org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer)2 MapEntry (uk.ac.ed.ph.jqtiplus.node.item.response.declaration.MapEntry)2 Mapping (uk.ac.ed.ph.jqtiplus.node.item.response.declaration.Mapping)2 StringValue (uk.ac.ed.ph.jqtiplus.value.StringValue)2