Search in sources :

Example 16 with Mattext

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

the class QTIEditHelper method createEssayItem.

/**
 * Creates a new essay item
 * @param trans
 * @return New essay item.
 */
public static Item createEssayItem(Translator trans) {
    // create item
    Item newItem = new Item();
    newItem.setIdent(EDITOR_IDENT + ":" + ITEM_TYPE_ESSAY + ":" + String.valueOf(CodeHelper.getRAMUniqueID()));
    newItem.setTitle(trans.translate("editor.newquestion"));
    newItem.setLabel("");
    // conrols
    Control control = new Control();
    List<Control> controls = new ArrayList<Control>();
    controls.add(control);
    newItem.setItemcontrols(controls);
    QTIEditHelper.setFeedbackMastery(newItem, "");
    QTIEditHelper.setFeedbackFail(newItem, "");
    EssayQuestion essayquestion = new EssayQuestion();
    essayquestion.getQuestion().getElements().add(new Mattext(trans.translate("editor.newquestiontext")));
    essayquestion.setSingleCorrect(true);
    essayquestion.setSingleCorrectScore(1);
    EssayResponse response = new EssayResponse();
    Material mat = new Material();
    mat.add(new Mattext(trans.translate("editor.newtextelement")));
    response.setContent(mat);
    essayquestion.getResponses().add(response);
    newItem.setQuestion(essayquestion);
    return newItem;
}
Also used : EssayQuestion(org.olat.ims.qti.editor.beecom.objects.EssayQuestion) Item(org.olat.ims.qti.editor.beecom.objects.Item) VFSItem(org.olat.core.util.vfs.VFSItem) Control(org.olat.ims.qti.editor.beecom.objects.Control) Mattext(org.olat.ims.qti.editor.beecom.objects.Mattext) EssayResponse(org.olat.ims.qti.editor.beecom.objects.EssayResponse) ArrayList(java.util.ArrayList) Material(org.olat.ims.qti.editor.beecom.objects.Material)

Example 17 with Mattext

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

the class QTIEditHelper method createMCItem.

/**
 * Creates a new Multiple Choice item.
 * @param trans
 * @return New Multiple Choice item.
 */
public static Item createMCItem(Translator trans) {
    // create item
    Item newItem = new Item();
    newItem.setIdent(EDITOR_IDENT + ":" + ITEM_TYPE_MC + ":" + String.valueOf(CodeHelper.getRAMUniqueID()));
    newItem.setTitle(trans.translate("editor.newquestion"));
    newItem.setLabel("");
    // conrols
    Control control = new Control();
    List<Control> controls = new ArrayList<Control>();
    controls.add(control);
    newItem.setItemcontrols(controls);
    // pepare question
    ChoiceQuestion question = new ChoiceQuestion();
    question.setLable(trans.translate("editor.newquestion"));
    question.getQuestion().getElements().add(new Mattext(trans.translate("editor.newquestiontext")));
    question.setType(Question.TYPE_MC);
    question.setSingleCorrect(true);
    question.setSingleCorrectScore(1);
    ChoiceResponse newChoice = new ChoiceResponse();
    newChoice.getContent().add(new Mattext(trans.translate("editor.newresponsetext")));
    newChoice.setCorrect(true);
    newChoice.setPoints(1);
    question.getResponses().add(newChoice);
    newItem.setQuestion(question);
    QTIEditHelper.setFeedbackMastery(newItem, "");
    QTIEditHelper.setFeedbackFail(newItem, "");
    return newItem;
}
Also used : ChoiceResponse(org.olat.ims.qti.editor.beecom.objects.ChoiceResponse) Item(org.olat.ims.qti.editor.beecom.objects.Item) VFSItem(org.olat.core.util.vfs.VFSItem) Control(org.olat.ims.qti.editor.beecom.objects.Control) Mattext(org.olat.ims.qti.editor.beecom.objects.Mattext) ArrayList(java.util.ArrayList) ChoiceQuestion(org.olat.ims.qti.editor.beecom.objects.ChoiceQuestion)

Example 18 with Mattext

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

the class ChoiceItemController 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 == null) {
        // ignore null cmd
        } else if (cmd.equals("up")) {
            if (posid > 0) {
                List<Response> elements = item.getQuestion().getResponses();
                Response obj = elements.remove(posid);
                elements.add(posid - 1, obj);
            }
        } else if (cmd.equals("down")) {
            List<Response> elements = item.getQuestion().getResponses();
            if (posid < elements.size() - 1) {
                Response obj = elements.remove(posid);
                elements.add(posid + 1, obj);
            }
        } else if (cmd.equals("editq")) {
            editQuestion = item.getQuestion().getQuestion();
            displayMaterialFormController(ureq, editQuestion, restrictedEdit, translate("fieldset.legend.question"));
        } else if (cmd.equals("editr")) {
            List<Response> elements = item.getQuestion().getResponses();
            if (posid >= 0 && posid < elements.size()) {
                editResponse = elements.get(posid);
                Material responseMat = editResponse.getContent();
                displayMaterialFormController(ureq, responseMat, restrictedEdit, translate("fieldset.legend.answers"));
            }
        } else if (cmd.equals("addchoice")) {
            ChoiceQuestion question = (ChoiceQuestion) item.getQuestion();
            List<Response> choices = question.getResponses();
            ChoiceResponse newChoice = new ChoiceResponse();
            newChoice.getContent().add(new Mattext(translate("newresponsetext")));
            newChoice.setCorrect(false);
            // default value is negative to make sure
            newChoice.setPoints(-1f);
            // people understand the meaning of this value
            choices.add(newChoice);
        } 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("ssc")) {
            // submit sc
            if (!restrictedEdit) {
                ChoiceQuestion question = (ChoiceQuestion) item.getQuestion();
                List<Response> q_choices = question.getResponses();
                String correctChoice = ureq.getParameter("correctChoice");
                for (int i = 0; i < q_choices.size(); i++) {
                    ChoiceResponse choice = (ChoiceResponse) q_choices.get(i);
                    if (correctChoice != null && correctChoice.equals("value_q" + i)) {
                        choice.setCorrect(true);
                    } else {
                        choice.setCorrect(false);
                    }
                    choice.setPoints(ureq.getParameter("points_q" + i));
                }
                String score = ureq.getParameter("single_score");
                float sc;
                try {
                    sc = Float.parseFloat(score);
                    if (sc <= 0.0001f) {
                        getWindowControl().setWarning(translate("editor.info.mc.zero.points"));
                    }
                } catch (Exception e) {
                    getWindowControl().setWarning(translate("editor.info.mc.zero.points"));
                    sc = 1.0f;
                }
                question.setSingleCorrectScore(sc);
            }
        } else if (cmd.equals("smc")) {
            // submit mc
            if (!restrictedEdit) {
                ChoiceQuestion question = (ChoiceQuestion) item.getQuestion();
                List<Response> choices = question.getResponses();
                boolean hasZeroPointChoice = false;
                for (int i = 0; i < choices.size(); i++) {
                    ChoiceResponse choice = (ChoiceResponse) choices.get(i);
                    if (ureq.getParameter("value_q" + i) != null && ureq.getParameter("value_q" + i).equalsIgnoreCase("true")) {
                        choice.setCorrect(true);
                    } else {
                        choice.setCorrect(false);
                    }
                    choice.setPoints(ureq.getParameter("points_q" + i));
                    if (choice.getPoints() == 0)
                        hasZeroPointChoice = true;
                }
                if (hasZeroPointChoice && !question.isSingleCorrect()) {
                    getWindowControl().setInfo(translate("editor.info.mc.zero.points"));
                }
                // set min/max before single_correct score
                // will be corrected by single_correct score afterwards
                question.setMinValue(ureq.getParameter("min_value"));
                question.setMaxValue(ureq.getParameter("max_value"));
                question.setSingleCorrect(ureq.getParameter("valuation_method").equals("single"));
                if (question.isSingleCorrect()) {
                    question.setSingleCorrectScore(ureq.getParameter("single_score"));
                } else {
                    question.setSingleCorrectScore(0);
                }
            }
        } else if (cmd.equals("skprim")) {
            // submit kprim
            if (!restrictedEdit) {
                float maxValue = 0;
                try {
                    maxValue = Float.parseFloat(ureq.getParameter("max_value"));
                } catch (NumberFormatException e) {
                // invalid input, set maxValue 0
                }
                ChoiceQuestion question = (ChoiceQuestion) item.getQuestion();
                List<Response> q_choices = question.getResponses();
                for (int i = 0; i < q_choices.size(); i++) {
                    String correctChoice = ureq.getParameter("correctChoice_q" + i);
                    ChoiceResponse choice = (ChoiceResponse) q_choices.get(i);
                    choice.setPoints(maxValue / 4);
                    if ("correct".equals(correctChoice)) {
                        choice.setCorrect(true);
                    } else {
                        choice.setCorrect(false);
                    }
                }
                question.setMaxValue(maxValue);
            }
        }
        qtiPackage.serializeQTIDocument();
    }
}
Also used : Material(org.olat.ims.qti.editor.beecom.objects.Material) ChoiceResponse(org.olat.ims.qti.editor.beecom.objects.ChoiceResponse) Response(org.olat.ims.qti.editor.beecom.objects.Response) ChoiceResponse(org.olat.ims.qti.editor.beecom.objects.ChoiceResponse) Mattext(org.olat.ims.qti.editor.beecom.objects.Mattext) List(java.util.List) ChoiceQuestion(org.olat.ims.qti.editor.beecom.objects.ChoiceQuestion)

Example 19 with Mattext

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

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 20 with Mattext

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

the class QTIEditHelper method createEssayItem.

/**
 * Creates a new essay item
 * @param trans
 * @return New essay item.
 */
public static Item createEssayItem(Translator trans) {
    // create item
    Item newItem = new Item();
    newItem.setIdent(EDITOR_IDENT + ":" + ITEM_TYPE_ESSAY + ":" + String.valueOf(CodeHelper.getRAMUniqueID()));
    newItem.setTitle(trans.translate("editor.newquestion"));
    newItem.setLabel("");
    // conrols
    Control control = new Control();
    List<Control> controls = new ArrayList<Control>();
    controls.add(control);
    newItem.setItemcontrols(controls);
    QTIEditHelper.setFeedbackMastery(newItem, "");
    QTIEditHelper.setFeedbackFail(newItem, "");
    EssayQuestion essayquestion = new EssayQuestion();
    essayquestion.getQuestion().getElements().add(new Mattext(trans.translate("editor.newquestiontext")));
    essayquestion.setSingleCorrect(true);
    essayquestion.setSingleCorrectScore(1);
    EssayResponse response = new EssayResponse();
    Material mat = new Material();
    mat.add(new Mattext(trans.translate("editor.newtextelement")));
    response.setContent(mat);
    essayquestion.getResponses().add(response);
    newItem.setQuestion(essayquestion);
    return newItem;
}
Also used : EssayQuestion(org.olat.ims.qti.editor.beecom.objects.EssayQuestion) Item(org.olat.ims.qti.editor.beecom.objects.Item) VFSItem(org.olat.core.util.vfs.VFSItem) Control(org.olat.ims.qti.editor.beecom.objects.Control) Mattext(org.olat.ims.qti.editor.beecom.objects.Mattext) EssayResponse(org.olat.ims.qti.editor.beecom.objects.EssayResponse) ArrayList(java.util.ArrayList) Material(org.olat.ims.qti.editor.beecom.objects.Material)

Aggregations

Mattext (org.olat.ims.qti.editor.beecom.objects.Mattext)26 ArrayList (java.util.ArrayList)18 Material (org.olat.ims.qti.editor.beecom.objects.Material)16 ChoiceQuestion (org.olat.ims.qti.editor.beecom.objects.ChoiceQuestion)12 Item (org.olat.ims.qti.editor.beecom.objects.Item)12 VFSItem (org.olat.core.util.vfs.VFSItem)10 ChoiceResponse (org.olat.ims.qti.editor.beecom.objects.ChoiceResponse)10 Control (org.olat.ims.qti.editor.beecom.objects.Control)10 List (java.util.List)8 FIBResponse (org.olat.ims.qti.editor.beecom.objects.FIBResponse)8 QTIObject (org.olat.ims.qti.editor.beecom.objects.QTIObject)8 Response (org.olat.ims.qti.editor.beecom.objects.Response)8 FIBQuestion (org.olat.ims.qti.editor.beecom.objects.FIBQuestion)6 Filter (org.olat.core.util.filter.Filter)4 EssayResponse (org.olat.ims.qti.editor.beecom.objects.EssayResponse)4 File (java.io.File)2 URL (java.net.URL)2 Iterator (java.util.Iterator)2 Element (org.dom4j.Element)2 Test (org.junit.Test)2