Search in sources :

Example 6 with SimpleAssociableChoice

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

the class TrueFalseEditorController method initForm.

@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
    FormLayoutContainer metadata = FormLayoutContainer.createDefaultFormLayout("metadata", getTranslator());
    if (itemBuilder.getQuestionType() == QTI21QuestionType.matchdraganddrop) {
        metadata.setFormContextHelp("Test editor QTI 2.1 in detail#details_testeditor_fragetypen_draganddrop");
    } else {
        metadata.setFormContextHelp("Test editor QTI 2.1 in detail#details_testeditor_fragetypen_match");
    }
    metadata.setRootForm(mainForm);
    formLayout.add(metadata);
    formLayout.add("metadata", metadata);
    titleEl = uifactory.addTextElement("title", "form.imd.title", -1, itemBuilder.getTitle(), metadata);
    titleEl.setElementCssClass("o_sel_assessment_item_title");
    titleEl.setMandatory(true);
    titleEl.setEnabled(!readOnly);
    String description = itemBuilder.getQuestion();
    textEl = uifactory.addRichTextElementForQTI21("desc", "form.imd.descr", description, 8, -1, itemContainer, metadata, ureq.getUserSession(), getWindowControl());
    textEl.setEnabled(!readOnly);
    textEl.setVisible(!readOnly);
    if (readOnly) {
        FlowFormItem textReadOnlyEl = new FlowFormItem("descro", itemFile);
        textReadOnlyEl.setLabel("form.imd.descr", null);
        textReadOnlyEl.setBlocks(itemBuilder.getQuestionBlocks());
        textReadOnlyEl.setMapperUri(mapperUri);
        metadata.add(textReadOnlyEl);
    }
    // responses
    String page = velocity_root + "/match_truefalse.html";
    answersCont = FormLayoutContainer.createCustomFormLayout("answers", getTranslator(), page);
    answersCont.setRootForm(mainForm);
    answersCont.contextPut("showHeaders", (itemBuilder.getQuestionType() == QTI21QuestionType.matchdraganddrop));
    formLayout.add(answersCont);
    formLayout.add("answers", answersCont);
    MatchInteraction interaction = itemBuilder.getMatchInteraction();
    if (interaction != null) {
        List<SimpleAssociableChoice> sourceChoices = itemBuilder.getSourceChoices();
        for (SimpleAssociableChoice sourceChoice : sourceChoices) {
            wrapSource(ureq, sourceChoice, sourceWrappers);
        }
        List<TargetWrapper> targetChoices = itemBuilder.getTargetChoices().stream().map(c -> new TargetWrapper(c)).collect(Collectors.toList());
        answersCont.contextPut("targetChoices", targetChoices);
    }
    answersCont.contextPut("sourceChoices", sourceWrappers);
    answersCont.contextPut("restrictedEdit", restrictedEdit || readOnly);
    answersCont.contextPut("responseIdentifier", itemBuilder.getResponseIdentifier());
    int maxAssociations = itemBuilder.getMatchInteraction().getMaxAssociations();
    answersCont.contextPut("interactionMaxAssociations", maxAssociations);
    JSAndCSSFormItem js = new JSAndCSSFormItem("js", new String[] { "js/jquery/qti/jquery.match.js" });
    formLayout.add(js);
    if (!readOnly) {
        uifactory.addFormSubmitButton("submit", answersCont);
    }
    if (!restrictedEdit && !readOnly) {
        addRowButton = uifactory.addFormLink("add.match.row", answersCont, Link.BUTTON);
        addRowButton.setElementCssClass("o_sel_match_add_row");
        addRowButton.setIconLeftCSS("o_icon o_icon_add");
    }
}
Also used : MatchInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.MatchInteraction) Util(org.olat.core.util.Util) AssessmentItemFactory.createSimpleAssociableChoice(org.olat.ims.qti21.model.xml.AssessmentItemFactory.createSimpleAssociableChoice) FormEvent(org.olat.core.gui.components.form.flexible.impl.FormEvent) AssessmentItemEvent(org.olat.ims.qti21.ui.editor.events.AssessmentItemEvent) Identifier(uk.ac.ed.ph.jqtiplus.types.Identifier) HashMap(java.util.HashMap) QTI21QuestionType(org.olat.ims.qti21.model.QTI21QuestionType) FormItem(org.olat.core.gui.components.form.flexible.FormItem) ArrayList(java.util.ArrayList) FormBasicController(org.olat.core.gui.components.form.flexible.impl.FormBasicController) FormItemContainer(org.olat.core.gui.components.form.flexible.FormItemContainer) RichTextElement(org.olat.core.gui.components.form.flexible.elements.RichTextElement) Map(java.util.Map) JSAndCSSFormItem(org.olat.core.gui.components.htmlheader.jscss.JSAndCSSFormItem) AssessmentTestEditorController(org.olat.ims.qti21.ui.editor.AssessmentTestEditorController) FlowStatic(uk.ac.ed.ph.jqtiplus.node.content.basic.FlowStatic) Link(org.olat.core.gui.components.link.Link) WindowControl(org.olat.core.gui.control.WindowControl) ResourcesMapper(org.olat.ims.qti21.ui.ResourcesMapper) SimpleAssociableChoice(uk.ac.ed.ph.jqtiplus.node.item.interaction.choice.SimpleAssociableChoice) FlowFormItem(org.olat.ims.qti21.ui.components.FlowFormItem) Collectors(java.util.stream.Collectors) Controller(org.olat.core.gui.control.Controller) CodeHelper(org.olat.core.util.CodeHelper) File(java.io.File) TextElement(org.olat.core.gui.components.form.flexible.elements.TextElement) VFSContainer(org.olat.core.util.vfs.VFSContainer) MatchAssessmentItemBuilder(org.olat.ims.qti21.model.xml.interactions.MatchAssessmentItemBuilder) List(java.util.List) FormLink(org.olat.core.gui.components.form.flexible.elements.FormLink) MatchInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.MatchInteraction) UserRequest(org.olat.core.gui.UserRequest) FormLayoutContainer(org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer) FlowFormItem(org.olat.ims.qti21.ui.components.FlowFormItem) AssessmentItemFactory.createSimpleAssociableChoice(org.olat.ims.qti21.model.xml.AssessmentItemFactory.createSimpleAssociableChoice) SimpleAssociableChoice(uk.ac.ed.ph.jqtiplus.node.item.interaction.choice.SimpleAssociableChoice) JSAndCSSFormItem(org.olat.core.gui.components.htmlheader.jscss.JSAndCSSFormItem) FormLayoutContainer(org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer)

Example 7 with SimpleAssociableChoice

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

the class TrueFalseEditorController method doAddSourceRow.

private void doAddSourceRow(UserRequest ureq) {
    SimpleAssociableChoice newChoice = createSimpleAssociableChoice("Text", itemBuilder.getSourceMatchSet());
    itemBuilder.getSourceMatchSet().getSimpleAssociableChoices().add(newChoice);
    wrapSource(ureq, newChoice, sourceWrappers);
    answersCont.setDirty(true);
}
Also used : AssessmentItemFactory.createSimpleAssociableChoice(org.olat.ims.qti21.model.xml.AssessmentItemFactory.createSimpleAssociableChoice) SimpleAssociableChoice(uk.ac.ed.ph.jqtiplus.node.item.interaction.choice.SimpleAssociableChoice)

Example 8 with SimpleAssociableChoice

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

the class TrueFalseEditorController method formOK.

@Override
protected void formOK(UserRequest ureq) {
    if (readOnly)
        return;
    // title
    itemBuilder.setTitle(titleEl.getValue());
    // question
    String questionText = textEl.getRawValue();
    itemBuilder.setQuestion(questionText);
    if (!restrictedEdit) {
        itemBuilder.setMultipleChoice(false);
        itemBuilder.setShuffle(false);
    }
    // update
    for (SourceWrapper sourceWrapper : sourceWrappers) {
        SimpleAssociableChoice choice = sourceWrapper.getSimpleChoice();
        String answer = sourceWrapper.getText().getRawValue();
        itemBuilder.getHtmlHelper().appendHtml(choice, answer);
    }
    // correct answers
    commitAssociations(ureq);
    fireEvent(ureq, new AssessmentItemEvent(AssessmentItemEvent.ASSESSMENT_ITEM_CHANGED, itemBuilder.getAssessmentItem(), QTI21QuestionType.match));
}
Also used : AssessmentItemFactory.createSimpleAssociableChoice(org.olat.ims.qti21.model.xml.AssessmentItemFactory.createSimpleAssociableChoice) SimpleAssociableChoice(uk.ac.ed.ph.jqtiplus.node.item.interaction.choice.SimpleAssociableChoice) AssessmentItemEvent(org.olat.ims.qti21.ui.editor.events.AssessmentItemEvent)

Example 9 with SimpleAssociableChoice

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

the class MatchScoreController method sync.

private List<MatchWrapper> sync(SimpleMatchSet matchSet, List<MatchWrapper> wrappers) {
    Map<Identifier, MatchWrapper> currentMapping = wrappers.stream().collect(Collectors.toMap(w -> w.getChoiceIdentifier(), w -> w));
    List<MatchWrapper> newWrappers = new ArrayList<>();
    List<SimpleAssociableChoice> choices = matchSet.getSimpleAssociableChoices();
    for (SimpleAssociableChoice choice : choices) {
        if (currentMapping.containsKey(choice.getIdentifier())) {
            newWrappers.add(currentMapping.get(choice.getIdentifier()));
        } else {
            newWrappers.add(createMatchWrapper(choice));
        }
    }
    return newWrappers;
}
Also used : Util(org.olat.core.util.Util) FormEvent(org.olat.core.gui.components.form.flexible.impl.FormEvent) AssessmentItemEvent(org.olat.ims.qti21.ui.editor.events.AssessmentItemEvent) Identifier(uk.ac.ed.ph.jqtiplus.types.Identifier) HashMap(java.util.HashMap) SingleSelection(org.olat.core.gui.components.form.flexible.elements.SingleSelection) FormItem(org.olat.core.gui.components.form.flexible.FormItem) ArrayList(java.util.ArrayList) SimpleMatchSet(uk.ac.ed.ph.jqtiplus.node.item.interaction.choice.SimpleMatchSet) FormItemContainer(org.olat.core.gui.components.form.flexible.FormItemContainer) ScoreBuilder(org.olat.ims.qti21.model.xml.ScoreBuilder) Map(java.util.Map) StringHelper(org.olat.core.util.StringHelper) URI(java.net.URI) AssessmentTestEditorController(org.olat.ims.qti21.ui.editor.AssessmentTestEditorController) WindowControl(org.olat.core.gui.control.WindowControl) ResourcesMapper(org.olat.ims.qti21.ui.ResourcesMapper) AssessmentItemRef(uk.ac.ed.ph.jqtiplus.node.test.AssessmentItemRef) SimpleAssociableChoice(uk.ac.ed.ph.jqtiplus.node.item.interaction.choice.SimpleAssociableChoice) FlowFormItem(org.olat.ims.qti21.ui.components.FlowFormItem) Collectors(java.util.stream.Collectors) Controller(org.olat.core.gui.control.Controller) CodeHelper(org.olat.core.util.CodeHelper) File(java.io.File) TextElement(org.olat.core.gui.components.form.flexible.elements.TextElement) AssessmentHtmlBuilder(org.olat.ims.qti21.model.xml.AssessmentHtmlBuilder) MatchAssessmentItemBuilder(org.olat.ims.qti21.model.xml.interactions.MatchAssessmentItemBuilder) List(java.util.List) AssessmentItemBuilder(org.olat.ims.qti21.model.xml.AssessmentItemBuilder) DirectedPairValue(uk.ac.ed.ph.jqtiplus.value.DirectedPairValue) AssessmentHelper(org.olat.course.assessment.AssessmentHelper) SyncAssessmentItem(org.olat.ims.qti21.ui.editor.SyncAssessmentItem) UserRequest(org.olat.core.gui.UserRequest) ScoreEvaluation(org.olat.ims.qti21.model.xml.interactions.SimpleChoiceAssessmentItemBuilder.ScoreEvaluation) FormLayoutContainer(org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer) SimpleAssociableChoice(uk.ac.ed.ph.jqtiplus.node.item.interaction.choice.SimpleAssociableChoice) Identifier(uk.ac.ed.ph.jqtiplus.types.Identifier) ArrayList(java.util.ArrayList)

Example 10 with SimpleAssociableChoice

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

the class KPrimAssessmentItemBuilder method createAssessmentItem.

private static AssessmentItem createAssessmentItem(String title, String defaultAnswer) {
    AssessmentItem assessmentItem = AssessmentItemFactory.createAssessmentItem(QTI21QuestionType.kprim, title);
    NodeGroupList nodeGroups = assessmentItem.getNodeGroups();
    double maxScore = 1.0d;
    Identifier responseDeclarationId = Identifier.assumedLegal("KPRIM_RESPONSE_1");
    // define correct answer
    ResponseDeclaration responseDeclaration = createKPrimResponseDeclaration(assessmentItem, responseDeclarationId, new HashMap<>(), maxScore);
    nodeGroups.getResponseDeclarationGroup().getResponseDeclarations().add(responseDeclaration);
    appendDefaultOutcomeDeclarations(assessmentItem, maxScore);
    // the single choice interaction
    ItemBody itemBody = appendDefaultItemBody(assessmentItem);
    MatchInteraction matchInteraction = appendMatchInteractionForKPrim(itemBody, responseDeclarationId, defaultAnswer);
    List<String> cssClasses = new ArrayList<>();
    cssClasses.add(QTI21Constants.CSS_MATCH_KPRIM);
    matchInteraction.setClassAttr(cssClasses);
    SimpleMatchSet matchSet = matchInteraction.getSimpleMatchSets().get(0);
    Map<Identifier, Identifier> associations = new HashMap<>();
    for (SimpleAssociableChoice choice : matchSet.getSimpleAssociableChoices()) {
        associations.put(choice.getIdentifier(), QTI21Constants.WRONG_IDENTIFIER);
    }
    appendAssociationKPrimResponseDeclaration(responseDeclaration, associations, 1.0);
    // response processing
    ResponseProcessing responseProcessing = createResponseProcessing(assessmentItem, responseDeclarationId);
    assessmentItem.getNodeGroups().getResponseProcessingGroup().setResponseProcessing(responseProcessing);
    return assessmentItem;
}
Also used : MatchInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.MatchInteraction) SimpleAssociableChoice(uk.ac.ed.ph.jqtiplus.node.item.interaction.choice.SimpleAssociableChoice) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) 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) SimpleMatchSet(uk.ac.ed.ph.jqtiplus.node.item.interaction.choice.SimpleMatchSet) 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) ResponseDeclaration(uk.ac.ed.ph.jqtiplus.node.item.response.declaration.ResponseDeclaration) AssessmentItemFactory.createKPrimResponseDeclaration(org.olat.ims.qti21.model.xml.AssessmentItemFactory.createKPrimResponseDeclaration) AssessmentItemFactory.appendAssociationKPrimResponseDeclaration(org.olat.ims.qti21.model.xml.AssessmentItemFactory.appendAssociationKPrimResponseDeclaration)

Aggregations

SimpleAssociableChoice (uk.ac.ed.ph.jqtiplus.node.item.interaction.choice.SimpleAssociableChoice)54 Identifier (uk.ac.ed.ph.jqtiplus.types.Identifier)20 MatchInteraction (uk.ac.ed.ph.jqtiplus.node.item.interaction.MatchInteraction)18 ArrayList (java.util.ArrayList)17 SimpleMatchSet (uk.ac.ed.ph.jqtiplus.node.item.interaction.choice.SimpleMatchSet)16 AssessmentItemFactory.createSimpleAssociableChoice (org.olat.ims.qti21.model.xml.AssessmentItemFactory.createSimpleAssociableChoice)14 HashMap (java.util.HashMap)12 List (java.util.List)10 FormLayoutContainer (org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer)10 AssessmentItemEvent (org.olat.ims.qti21.ui.editor.events.AssessmentItemEvent)10 P (uk.ac.ed.ph.jqtiplus.node.content.xhtml.text.P)10 ResponseDeclaration (uk.ac.ed.ph.jqtiplus.node.item.response.declaration.ResponseDeclaration)10 FlowFormItem (org.olat.ims.qti21.ui.components.FlowFormItem)7 DirectedPairValue (uk.ac.ed.ph.jqtiplus.value.DirectedPairValue)7 Map (java.util.Map)6 Collectors (java.util.stream.Collectors)6 AssessmentItem (uk.ac.ed.ph.jqtiplus.node.item.AssessmentItem)6 File (java.io.File)4 UserRequest (org.olat.core.gui.UserRequest)4 FormItem (org.olat.core.gui.components.form.flexible.FormItem)4