Search in sources :

Example 16 with Material

use of org.olat.ims.qti.editor.beecom.objects.Material in project openolat by klemens.

the class FIBItemController method event.

/**
 * @see org.olat.core.gui.control.DefaultController#event(org.olat.core.gui.UserRequest,
 *      org.olat.core.gui.components.Component, org.olat.core.gui.control.Event)
 */
@Override
public void event(UserRequest ureq, Component source, Event event) {
    if (source == main) {
        // olat::: as: improve easy fix since almost all operations change the main vc.
        main.setDirty(true);
        String cmd = event.getCommand();
        String sPosid = ureq.getParameter("posid");
        int posid = 0;
        if (sPosid != null)
            posid = Integer.parseInt(sPosid);
        if (cmd.equals("up")) {
            List<Response> elements = item.getQuestion().getResponses();
            if (posid > 0 && posid < item.getQuestion().getResponses().size()) {
                Response obj = elements.remove(posid);
                elements.add(posid - 1, obj);
            } else {
                logError("posid doesn't match responses length: " + posid + "/" + elements.size(), null);
            }
        } else if (cmd.equals("down")) {
            List<Response> elements = item.getQuestion().getResponses();
            if (posid >= 0 && posid < elements.size() - 1) {
                Response obj = elements.remove(posid);
                elements.add(posid + 1, obj);
            } else {
                logError("posid doesn't match responses length: " + posid + "/" + elements.size(), null);
            }
        } else if (cmd.equals("editq")) {
            editQuestion = item.getQuestion().getQuestion();
            displayMaterialFormController(ureq, editQuestion, restrictedEdit);
        } else if (cmd.equals("editr")) {
            List<Response> elements = item.getQuestion().getResponses();
            if (posid >= 0 && posid < elements.size()) {
                editResponse = elements.get(posid);
                Material responseMat = elements.get(posid).getContent();
                displayMaterialFormController(ureq, responseMat, restrictedEdit);
            } else {
                logError("posid doesn't match responses length: " + posid + "/" + elements.size(), null);
            }
        } else if (cmd.equals("addtext")) {
            FIBQuestion fib = (FIBQuestion) item.getQuestion();
            FIBResponse response = new FIBResponse();
            response.setType(FIBResponse.TYPE_CONTENT);
            Material mat = new Material();
            mat.add(new Mattext(translate("newtextelement")));
            response.setContent(mat);
            fib.getResponses().add(response);
        } else if (cmd.equals("addblank")) {
            FIBQuestion fib = (FIBQuestion) item.getQuestion();
            FIBResponse response = new FIBResponse();
            response.setType(FIBResponse.TYPE_BLANK);
            response.setCorrectBlank("");
            // default value
            response.setPoints(1f);
            fib.getResponses().add(response);
        } else if (cmd.equals("del")) {
            delYesNoCtrl = DialogBoxUIFactory.createYesNoDialog(ureq, getWindowControl(), null, translate("confirm.delete.element"));
            listenTo(delYesNoCtrl);
            delYesNoCtrl.setUserObject(new Integer(posid));
            delYesNoCtrl.activate();
        } else if (cmd.equals("sfib")) {
            // submit fib
            FIBQuestion question = (FIBQuestion) item.getQuestion();
            // Survey specific variables
            if (surveyMode) {
                List<Response> responses = question.getResponses();
                for (int i = 0; i < responses.size(); i++) {
                    FIBResponse response = (FIBResponse) responses.get(i);
                    if (FIBResponse.TYPE_BLANK.equals(response.getType())) {
                        // Set size of input field
                        String size = ureq.getParameter("size_q" + i);
                        if (size != null)
                            response.setSizeFromString(size);
                        String maxLength = ureq.getParameter("maxl_q" + i);
                        if (maxLength != null)
                            response.setMaxLengthFromString(maxLength);
                    }
                }
            } else {
                // set min/max values before single_correct !!
                if (!restrictedEdit) {
                    // only in full edit mode the following fields are available:
                    // min_value, max_value, valuation_method
                    question.setMinValue(ureq.getParameter("min_value"));
                    question.setMaxValue(ureq.getParameter("max_value"));
                    question.setSingleCorrect("single".equals(ureq.getParameter("valuation_method")));
                    if (question.isSingleCorrect()) {
                        question.setSingleCorrectScore(ureq.getParameter("single_score"));
                    } else {
                        question.setSingleCorrectScore(0.0f);
                    }
                }
                NodeBeforeChangeEvent nce = new NodeBeforeChangeEvent();
                nce.setItemIdent(item.getIdent());
                List<Response> responses = question.getResponses();
                for (int i = 0; i < responses.size(); i++) {
                    FIBResponse response = (FIBResponse) responses.get(i);
                    nce.setResponseIdent(response.getIdent());
                    fireEvent(ureq, nce);
                    response.setPoints(ureq.getParameter("points_q" + i));
                    if (FIBResponse.TYPE_BLANK.equals(response.getType())) {
                        response.setCorrectBlank(ureq.getParameter("content_q" + i));
                        // Set case sensitiveness
                        String caseSensitive = ureq.getParameter("case_q" + i);
                        if (caseSensitive == null)
                            caseSensitive = "No";
                        response.setCaseSensitive(caseSensitive);
                        // Set size of input field
                        String size = ureq.getParameter("size_q" + i);
                        if (size != null)
                            response.setSizeFromString(size);
                        String maxLength = ureq.getParameter("maxl_q" + i);
                        if (maxLength != null)
                            response.setMaxLengthFromString(maxLength);
                        // find longest correct blank in all synonyms of
                        // correct answers, fix max lenght if a longer value
                        // is found
                        String[] allCorrect = response.getCorrectBlank().split(";");
                        int longestCorrect = 0;
                        for (int j = 0; j < allCorrect.length; j++) {
                            String singleCorrect = allCorrect[j];
                            if (singleCorrect.length() > longestCorrect) {
                                longestCorrect = singleCorrect.length();
                            }
                        }
                        if (longestCorrect > response.getMaxLength())
                            response.setMaxLength(longestCorrect);
                    }
                }
            }
        }
        qtiPackage.serializeQTIDocument();
    }
}
Also used : FIBResponse(org.olat.ims.qti.editor.beecom.objects.FIBResponse) Response(org.olat.ims.qti.editor.beecom.objects.Response) FIBResponse(org.olat.ims.qti.editor.beecom.objects.FIBResponse) Mattext(org.olat.ims.qti.editor.beecom.objects.Mattext) List(java.util.List) Material(org.olat.ims.qti.editor.beecom.objects.Material) FIBQuestion(org.olat.ims.qti.editor.beecom.objects.FIBQuestion)

Example 17 with Material

use of org.olat.ims.qti.editor.beecom.objects.Material in project openolat by klemens.

the class FeedbackFormController method initForm.

/**
 * @see org.olat.core.gui.components.form.flexible.impl.FormBasicController#initForm(org.olat.core.gui.components.form.flexible.FormItemContainer,
 *      org.olat.core.gui.control.Controller, org.olat.core.gui.UserRequest)
 */
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
    setFormTitle("fieldset.legend.feedback");
    setFormContextHelp("Test and Questionnaire Editor in Detail#details_testeditor_feedback");
    FormLayoutContainer switchLayout = FormLayoutContainer.createDefaultFormLayout("switchLayout", getTranslator());
    overallFeedbackLayout = FormLayoutContainer.createDefaultFormLayout("overallFeedbackLayout", getTranslator());
    responseLevelHintsLayout = FormLayoutContainer.createCustomFormLayout("responseLevelHintsLayout", getTranslator(), Util.getPackageVelocityRoot(this.getClass()) + "/response_level_feedback.html");
    // add the layouts to the custom layout
    formLayout.add(switchLayout);
    formLayout.add(overallFeedbackLayout);
    formLayout.add(responseLevelHintsLayout);
    String[] yesNoKeys, yesNoValues;
    yesNoKeys = new String[] { YES, NO };
    yesNoValues = new String[] { translate(YES), translate(NO) };
    feedbackSwitch = uifactory.addRadiosHorizontal("feedbackswitch", switchLayout, yesNoKeys, yesNoValues);
    feedbackSwitch.addActionListener(FormEvent.ONCLICK);
    if (control.isFeedback()) {
        feedbackSwitch.select(yesNoKeys[0], true);
    } else {
        // defaults to 'not showing feedback'
        feedbackSwitch.select(yesNoKeys[1], true);
    }
    responseLevelHintsLayout.contextPut("mediaBaseUrl", mediaBaseUrl);
    masteryMat = QTIEditHelper.getFeedbackMasteryMaterial(item);
    masteryMat = masteryMat == null ? new Material() : masteryMat;
    failureMat = QTIEditHelper.getFeedbackFailMaterial(item);
    failureMat = failureMat == null ? new Material() : failureMat;
    VFSContainer baseContainer = qtiPackage.getBaseDir();
    // Mastery Layout
    FormLayoutContainer masteryEditLayout = FormLayoutContainer.createCustomFormLayout("masteryEditLayout", getTranslator(), Util.getPackageVelocityRoot(this.getClass()) + "/rich_text_and_edit_link.html");
    masteryEditLayout.setLabel("item_feedback_mastery", null);
    overallFeedbackLayout.add(masteryEditLayout);
    RichTextElement masteryFeedback = uifactory.addRichTextElementForStringData("richTextElement", "item_feedback_mastery", masteryMat.renderAsHtml(mediaBaseUrl), 4, -1, true, baseContainer, null, masteryEditLayout, ureq.getUserSession(), getWindowControl());
    masteryFeedback.getEditorConfiguration().setFigCaption(false);
    FormLink editLink = uifactory.addFormLink("editLink", masteryEditLayout, Link.NONTRANSLATED + Link.LINK_CUSTOM_CSS);
    editLink.getComponent().setCustomDisplayText(" ");
    editLink.getComponent().setIconLeftCSS("o_icon o_icon_edit o_icon-lg qti_edit_link");
    registerFeedbackElement(masteryMat, masteryFeedback, editLink);
    // One Failure Layout
    FormLayoutContainer failureEditLayout = FormLayoutContainer.createCustomFormLayout("failureEditLayout", getTranslator(), Util.getPackageVelocityRoot(this.getClass()) + "/rich_text_and_edit_link.html");
    failureEditLayout.setLabel("item_feedback_fail", null);
    overallFeedbackLayout.add(failureEditLayout);
    RichTextElement failureFeedback = uifactory.addRichTextElementForStringData("richTextElement", "item_feedback_fail", failureMat.renderAsHtml(mediaBaseUrl), 4, -1, true, baseContainer, null, failureEditLayout, ureq.getUserSession(), getWindowControl());
    failureFeedback.getEditorConfiguration().setFigCaption(false);
    failureFeedback.setLabel("item_feedback_fail", null);
    FormLink failureLink = uifactory.addFormLink("editLink", failureEditLayout, Link.NONTRANSLATED + Link.LINK_CUSTOM_CSS);
    failureLink.getComponent().setCustomDisplayText("");
    failureLink.getComponent().setIconLeftCSS("o_icon o_icon_edit o_icon-lg");
    registerFeedbackElement(failureMat, failureFeedback, failureLink);
    // Feedback for each response when single or multiple choice question
    List<Material> responses = new ArrayList<Material>();
    boolean hasResponseLevelHints = false;
    if (item.getQuestion().getType() <= Question.TYPE_MC) {
        int i = 1;
        for (Object obj : item.getQuestion().getResponses()) {
            ChoiceResponse response = (ChoiceResponse) obj;
            // response-level feedback
            Material responseFeedbackMat = QTIEditHelper.getFeedbackOlatRespMaterial(item, response.getIdent());
            responseFeedbackMat = responseFeedbackMat == null ? new Material() : responseFeedbackMat;
            identities.put(responseFeedbackMat, response.getIdent());
            RichTextElement responseHintText = uifactory.addRichTextElementForStringData("feedback_" + i, null, responseFeedbackMat.renderAsHtml(mediaBaseUrl), 4, -1, true, baseContainer, null, responseLevelHintsLayout, ureq.getUserSession(), getWindowControl());
            responseHintText.getEditorConfiguration().setFigCaption(false);
            FormLink link = uifactory.addFormLink("link_" + i, responseLevelHintsLayout, Link.NONTRANSLATED + Link.LINK_CUSTOM_CSS);
            link.getComponent().setCustomDisplayText(" ");
            link.getComponent().setIconLeftCSS("o_icon o_icon_edit o_icon-lg");
            registerFeedbackElement(responseFeedbackMat, responseHintText, link);
            // get response for displaying
            Material responseMat = response.getContent();
            responses.add(responseMat);
            i++;
        }
        // If 'i' is strictly greater than the initial value, there's at least one
        // response.
        hasResponseLevelHints = i > 1;
    }
    flc.contextPut("hasResponseLevelHints", hasResponseLevelHints);
    responseLevelHintsLayout.contextPut("responses", responses);
    showHideFeedbackFields();
}
Also used : RichTextElement(org.olat.core.gui.components.form.flexible.elements.RichTextElement) VFSContainer(org.olat.core.util.vfs.VFSContainer) ArrayList(java.util.ArrayList) FormLayoutContainer(org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer) Material(org.olat.ims.qti.editor.beecom.objects.Material) FormLink(org.olat.core.gui.components.form.flexible.elements.FormLink) ChoiceResponse(org.olat.ims.qti.editor.beecom.objects.ChoiceResponse)

Example 18 with Material

use of org.olat.ims.qti.editor.beecom.objects.Material in project openolat by klemens.

the class ItemNode method createMemento.

public Memento createMemento() {
    Question question = item.getQuestion();
    // special case switches as question types are encoded into integers!!
    boolean isFIB = question.getType() == Question.TYPE_FIB;
    boolean isESSAY = question.getType() == Question.TYPE_ESSAY;
    // Item metadata
    QtiNodeMemento qnm = new QtiNodeMemento();
    Map<String, Object> qtiState = new HashMap<>();
    qtiState.put("ID", item.getIdent());
    qtiState.put("TITLE", item.getTitle());
    qtiState.put("OBJECTIVES", item.getObjectives());
    // question and responses
    qtiState.put("QUESTION.ID", question.getIdent());
    qtiState.put("QUESTION.HINTTEXT", question.getHintText());
    Material questMaterial = question.getQuestion();
    qtiState.put("QUESTION.MATERIAL.ASTEXT", questMaterial.renderAsText());
    List<String> ids = new ArrayList<String>();
    List<String> asTexts = new ArrayList<String>();
    List<String> feedbacks = new ArrayList<String>();
    List<Response> responses = question.getResponses();
    for (Iterator<Response> iter = responses.iterator(); iter.hasNext(); ) {
        Response resp = iter.next();
        if (isFIB) {
            if (FIBResponse.TYPE_BLANK.equals(((FIBResponse) resp).getType())) {
                asTexts.add(formatFIBResponseAsText((FIBResponse) resp));
                ids.add(resp.getIdent());
                feedbacks.add(QTIEditHelper.getFeedbackOlatRespText(item, resp.getIdent()));
            }
        } else if (isESSAY) {
            asTexts.add(formatESSAYResponseAsText((EssayResponse) resp));
            ids.add(resp.getIdent());
            feedbacks.add(QTIEditHelper.getFeedbackOlatRespText(item, resp.getIdent()));
        } else {
            // not a FIB or ESSAY response
            asTexts.add(resp.getContent().renderAsText());
            ids.add(resp.getIdent());
            feedbacks.add(QTIEditHelper.getFeedbackOlatRespText(item, resp.getIdent()));
        }
    }
    qtiState.put("QUESTION.RESPONSES.IDS", ids);
    qtiState.put("QUESTION.RESPONSES.ASTEXT", asTexts);
    qtiState.put("QUESTION.RESPONSES.FEEDBACK", feedbacks);
    // feedback
    qtiState.put("FEEDBACK.MASTERY", QTIEditHelper.getFeedbackMasteryText(item));
    qtiState.put("FEEDBACK.FAIL", QTIEditHelper.getFeedbackFailText(item));
    Control control = QTIEditHelper.getControl(item);
    qtiState.put("FEEDBACK.ENABLED", control.getFeedback() == 1 ? Boolean.TRUE : Boolean.FALSE);
    // 
    qnm.setQtiState(qtiState);
    // 
    return qnm;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Material(org.olat.ims.qti.editor.beecom.objects.Material) FIBResponse(org.olat.ims.qti.editor.beecom.objects.FIBResponse) Response(org.olat.ims.qti.editor.beecom.objects.Response) EssayResponse(org.olat.ims.qti.editor.beecom.objects.EssayResponse) FIBResponse(org.olat.ims.qti.editor.beecom.objects.FIBResponse) Control(org.olat.ims.qti.editor.beecom.objects.Control) WindowControl(org.olat.core.gui.control.WindowControl) Question(org.olat.ims.qti.editor.beecom.objects.Question) QTIObject(org.olat.ims.qti.editor.beecom.objects.QTIObject)

Example 19 with Material

use of org.olat.ims.qti.editor.beecom.objects.Material in project openolat by klemens.

the class MaterialParser method parse.

/**
 * @see org.olat.ims.qti.editor.beecom.parser.IParser#parse(org.dom4j.Element)
 */
public Object parse(Element element) {
    // assert element.getName().equalsIgnoreCase("material");
    List materials = element.elements();
    if (materials.size() == 0)
        return null;
    Material material = new Material();
    // ATTRIBUTES
    Attribute label = element.attribute("label");
    if (label != null)
        material.setLable(label.getValue());
    // ELEMENTS
    for (Iterator i = materials.iterator(); i.hasNext(); ) {
        QTIObject obj = (QTIObject) parserManager.parse((Element) i.next());
        if (obj != null)
            material.getElements().add(obj);
    }
    return material;
}
Also used : QTIObject(org.olat.ims.qti.editor.beecom.objects.QTIObject) Attribute(org.dom4j.Attribute) Element(org.dom4j.Element) Iterator(java.util.Iterator) List(java.util.List) Material(org.olat.ims.qti.editor.beecom.objects.Material)

Example 20 with Material

use of org.olat.ims.qti.editor.beecom.objects.Material in project OpenOLAT by OpenOLAT.

the class CSVToQuestionConverterTest method importMultipleChoice.

@Test
public void importMultipleChoice() throws IOException, URISyntaxException {
    URL importTxtUrl = CSVToQuestionConverterTest.class.getResource("question_import_mc.txt");
    Assert.assertNotNull(importTxtUrl);
    File importTxt = new File(importTxtUrl.toURI());
    String input = FileUtils.readFileToString(importTxt, "UTF-8");
    Translator translator = new KeyTranslator(Locale.ENGLISH);
    ImportOptions options = new ImportOptions();
    options.setShuffle(true);
    CSVToQuestionConverter converter = new CSVToQuestionConverter(translator, options);
    converter.parse(input);
    List<ItemAndMetadata> items = converter.getItems();
    Assert.assertNotNull(items);
    Assert.assertEquals(1, items.size());
    ItemAndMetadata importedItem = items.get(0);
    Item item = importedItem.getItem();
    Assert.assertNotNull(item);
    Assert.assertEquals("Fussball: Austragungsort", item.getTitle());
    Assert.assertEquals("Die Fussball WM wird alle vier Jahre von einem anderen Land ausgerichtet.", item.getObjectives());
    Assert.assertEquals(Question.TYPE_MC, item.getQuestion().getType());
    Assert.assertTrue(item.getQuestion() instanceof ChoiceQuestion);
    Material questionMat = item.getQuestion().getQuestion();
    Assert.assertNotNull(questionMat);
    Assert.assertNotNull(questionMat.getElements());
    Assert.assertEquals(1, questionMat.getElements().size());
    QTIObject questionMatEl = questionMat.getElements().get(0);
    Assert.assertTrue(questionMatEl instanceof Mattext);
    String text = ((Mattext) questionMatEl).getContent();
    Assert.assertEquals("In welchen L\u00E4ndern wurde zwischen dem Jahr 2000 und 2015 eine Fussball Weltmeisterschaft ausgetragen?", text);
    ChoiceQuestion question = (ChoiceQuestion) item.getQuestion();
    Assert.assertNotNull(question.getResponses());
    Assert.assertEquals(7, question.getResponses().size());
    List<Response> responses = question.getResponses();
    Assert.assertEquals(1.0f, responses.get(0).getPoints(), 0.0001);
    Assert.assertEquals(1.0f, responses.get(1).getPoints(), 0.0001);
    Assert.assertEquals(1.0f, responses.get(2).getPoints(), 0.0001);
    Assert.assertEquals(-1.0f, responses.get(3).getPoints(), 0.0001);
    Assert.assertEquals(-1.0f, responses.get(4).getPoints(), 0.0001);
    Assert.assertEquals(-1.0f, responses.get(5).getPoints(), 0.0001);
    Assert.assertEquals(-1.0f, responses.get(6).getPoints(), 0.0001);
    // after it will be set to true for all of them
    Assert.assertTrue(responses.get(0).isCorrect());
    Assert.assertTrue(responses.get(1).isCorrect());
    Assert.assertTrue(responses.get(2).isCorrect());
    Assert.assertFalse(responses.get(3).isCorrect());
    Assert.assertFalse(responses.get(4).isCorrect());
    Assert.assertFalse(responses.get(5).isCorrect());
    Assert.assertFalse(responses.get(6).isCorrect());
    String feedbackMastery = QTIEditHelper.getFeedbackMasteryText(item);
    Assert.assertEquals("Bravo! Die Antwort ich absolut korrekt.", feedbackMastery);
    String feedbackFail = QTIEditHelper.getFeedbackFailText(item);
    Assert.assertEquals("Leider falsch. Probieren Sie es noch einmal.", feedbackFail);
}
Also used : Material(org.olat.ims.qti.editor.beecom.objects.Material) URL(java.net.URL) FIBResponse(org.olat.ims.qti.editor.beecom.objects.FIBResponse) Response(org.olat.ims.qti.editor.beecom.objects.Response) Item(org.olat.ims.qti.editor.beecom.objects.Item) QTIObject(org.olat.ims.qti.editor.beecom.objects.QTIObject) Mattext(org.olat.ims.qti.editor.beecom.objects.Mattext) Translator(org.olat.core.gui.translator.Translator) KeyTranslator(org.olat.test.KeyTranslator) KeyTranslator(org.olat.test.KeyTranslator) ChoiceQuestion(org.olat.ims.qti.editor.beecom.objects.ChoiceQuestion) File(java.io.File) Test(org.junit.Test)

Aggregations

Material (org.olat.ims.qti.editor.beecom.objects.Material)36 ArrayList (java.util.ArrayList)20 Response (org.olat.ims.qti.editor.beecom.objects.Response)20 FIBResponse (org.olat.ims.qti.editor.beecom.objects.FIBResponse)18 ChoiceResponse (org.olat.ims.qti.editor.beecom.objects.ChoiceResponse)16 Mattext (org.olat.ims.qti.editor.beecom.objects.Mattext)16 ChoiceQuestion (org.olat.ims.qti.editor.beecom.objects.ChoiceQuestion)14 List (java.util.List)12 EssayResponse (org.olat.ims.qti.editor.beecom.objects.EssayResponse)12 Question (org.olat.ims.qti.editor.beecom.objects.Question)12 QTIObject (org.olat.ims.qti.editor.beecom.objects.QTIObject)10 FIBQuestion (org.olat.ims.qti.editor.beecom.objects.FIBQuestion)8 Item (org.olat.ims.qti.editor.beecom.objects.Item)8 Iterator (java.util.Iterator)6 VFSItem (org.olat.core.util.vfs.VFSItem)6 Control (org.olat.ims.qti.editor.beecom.objects.Control)6 EssayQuestion (org.olat.ims.qti.editor.beecom.objects.EssayQuestion)6 Element (org.dom4j.Element)4 FormLayoutContainer (org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer)4 Feedback (org.olat.ims.qti.editor.beecom.objects.Feedback)4