Search in sources :

Example 11 with ChoiceResponse

use of org.olat.ims.qti.editor.beecom.objects.ChoiceResponse 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 12 with ChoiceResponse

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

the class QTI12MetadataController method initForm.

@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
    Question question = item.getQuestion();
    FormLayoutContainer layoutCont = (FormLayoutContainer) formLayout;
    if (question != null) {
        layoutCont.contextPut("hasQuestion", Boolean.TRUE);
        // settings
        String shuffleStr = translate(question.isShuffle() ? "editor.true" : "editor.false");
        uifactory.addStaticTextElement("form.imd.shuffle", shuffleStr, formLayout);
        String duration = "";
        if (item.getDuration() != null) {
            duration = item.getDuration().getMin() + ":" + item.getDuration().getSec();
        }
        uifactory.addStaticTextElement("form.metadata.duration", duration, formLayout);
        if (question instanceof ChoiceQuestion) {
            ChoiceQuestion choice = (ChoiceQuestion) question;
            if (item.getQuestion().getType() == Question.TYPE_SC) {
                String score = Float.toString(question.getSingleCorrectScore());
                uifactory.addStaticTextElement("score", score, formLayout);
            } else if (item.getQuestion().getType() == Question.TYPE_MC) {
                String minVal = Float.toString(choice.getMinValue());
                String maxVal = Float.toString(choice.getMaxValue());
                uifactory.addStaticTextElement("score.min", minVal, formLayout);
                uifactory.addStaticTextElement("score.max", maxVal, formLayout);
            }
        }
        // correct responses
        List<Response> responses = question.getResponses();
        if (question.getType() == Question.TYPE_MC || question.getType() == Question.TYPE_SC) {
            setMCAndSCCorrectResponses(question, responses, layoutCont);
        } else if (question.getType() == Question.TYPE_KPRIM) {
            setKPrimCorrectResponses(responses, layoutCont);
        }
    }
    // feedbacks
    boolean hasFeedbacks = false;
    Material masteryMat = QTIEditHelper.getFeedbackMasteryMaterial(item);
    if (masteryMat != null) {
        layoutCont.contextPut("item_feedback_mastery", masteryMat.renderAsText());
        hasFeedbacks = true;
    }
    Material failureMat = QTIEditHelper.getFeedbackFailMaterial(item);
    if (failureMat != null) {
        layoutCont.contextPut("item_feedback_fail", failureMat.renderAsText());
        hasFeedbacks = true;
    }
    List<String> responsesFeedback = new ArrayList<>();
    if (question != null && question.getType() <= Question.TYPE_MC) {
        for (Object obj : question.getResponses()) {
            ChoiceResponse response = (ChoiceResponse) obj;
            Material responseFeedbackMat = QTIEditHelper.getFeedbackOlatRespMaterial(item, response.getIdent());
            if (responseFeedbackMat != null) {
                responsesFeedback.add(responseFeedbackMat.renderAsText());
            }
        }
        hasFeedbacks |= responsesFeedback.size() > 0;
    }
    layoutCont.contextPut("responsesFeedback", responsesFeedback);
    layoutCont.contextPut("hasFeedbacks", new Boolean(hasFeedbacks));
}
Also used : ArrayList(java.util.ArrayList) FormLayoutContainer(org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer) 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) ChoiceQuestion(org.olat.ims.qti.editor.beecom.objects.ChoiceQuestion) Question(org.olat.ims.qti.editor.beecom.objects.Question) ChoiceQuestion(org.olat.ims.qti.editor.beecom.objects.ChoiceQuestion)

Example 13 with ChoiceResponse

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

the class QTI12MetadataController method initForm.

@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
    Question question = item.getQuestion();
    FormLayoutContainer layoutCont = (FormLayoutContainer) formLayout;
    if (question != null) {
        layoutCont.contextPut("hasQuestion", Boolean.TRUE);
        // settings
        String shuffleStr = translate(question.isShuffle() ? "editor.true" : "editor.false");
        uifactory.addStaticTextElement("form.imd.shuffle", shuffleStr, formLayout);
        String duration = "";
        if (item.getDuration() != null) {
            duration = item.getDuration().getMin() + ":" + item.getDuration().getSec();
        }
        uifactory.addStaticTextElement("form.metadata.duration", duration, formLayout);
        if (question instanceof ChoiceQuestion) {
            ChoiceQuestion choice = (ChoiceQuestion) question;
            if (item.getQuestion().getType() == Question.TYPE_SC) {
                String score = Float.toString(question.getSingleCorrectScore());
                uifactory.addStaticTextElement("score", score, formLayout);
            } else if (item.getQuestion().getType() == Question.TYPE_MC) {
                String minVal = Float.toString(choice.getMinValue());
                String maxVal = Float.toString(choice.getMaxValue());
                uifactory.addStaticTextElement("score.min", minVal, formLayout);
                uifactory.addStaticTextElement("score.max", maxVal, formLayout);
            }
        }
        // correct responses
        List<Response> responses = question.getResponses();
        if (question.getType() == Question.TYPE_MC || question.getType() == Question.TYPE_SC) {
            setMCAndSCCorrectResponses(question, responses, layoutCont);
        } else if (question.getType() == Question.TYPE_KPRIM) {
            setKPrimCorrectResponses(responses, layoutCont);
        }
    }
    // feedbacks
    boolean hasFeedbacks = false;
    Material masteryMat = QTIEditHelper.getFeedbackMasteryMaterial(item);
    if (masteryMat != null) {
        layoutCont.contextPut("item_feedback_mastery", masteryMat.renderAsText());
        hasFeedbacks = true;
    }
    Material failureMat = QTIEditHelper.getFeedbackFailMaterial(item);
    if (failureMat != null) {
        layoutCont.contextPut("item_feedback_fail", failureMat.renderAsText());
        hasFeedbacks = true;
    }
    List<String> responsesFeedback = new ArrayList<>();
    if (question != null && question.getType() <= Question.TYPE_MC) {
        for (Object obj : question.getResponses()) {
            ChoiceResponse response = (ChoiceResponse) obj;
            Material responseFeedbackMat = QTIEditHelper.getFeedbackOlatRespMaterial(item, response.getIdent());
            if (responseFeedbackMat != null) {
                responsesFeedback.add(responseFeedbackMat.renderAsText());
            }
        }
        hasFeedbacks |= responsesFeedback.size() > 0;
    }
    layoutCont.contextPut("responsesFeedback", responsesFeedback);
    layoutCont.contextPut("hasFeedbacks", new Boolean(hasFeedbacks));
}
Also used : ArrayList(java.util.ArrayList) FormLayoutContainer(org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer) 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) ChoiceQuestion(org.olat.ims.qti.editor.beecom.objects.ChoiceQuestion) Question(org.olat.ims.qti.editor.beecom.objects.Question) ChoiceQuestion(org.olat.ims.qti.editor.beecom.objects.ChoiceQuestion)

Example 14 with ChoiceResponse

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

the class QTIEditHelper method createKPRIMItem.

/**
 * Creates a new Kprim item
 * @param trans
 * @return New Kprim item.
 */
public static Item createKPRIMItem(Translator trans) {
    // create item
    Item newItem = new Item();
    newItem.setIdent(EDITOR_IDENT + ":" + ITEM_TYPE_KPRIM + ":" + String.valueOf(CodeHelper.getRAMUniqueID()));
    newItem.setTitle(trans.translate("editor.newquestion"));
    newItem.setLabel("");
    // controls
    Control control = new Control();
    List<Control> controls = new ArrayList<Control>();
    controls.add(control);
    newItem.setItemcontrols(controls);
    // prepare question
    float maxValue = 1;
    ChoiceQuestion question = new ChoiceQuestion();
    question.setLable(trans.translate("editor.newquestion"));
    question.getQuestion().getElements().add(new Mattext(trans.translate("editor.newquestiontext")));
    question.setType(Question.TYPE_KPRIM);
    question.setSingleCorrect(false);
    // Kprim has always 4 answers, each of them score 1/4 of the maximum value
    ChoiceResponse newChoice = new ChoiceResponse();
    newChoice.getContent().add(new Mattext(trans.translate("editor.newresponsetext")));
    newChoice.setCorrect(false);
    newChoice.setPoints(maxValue / 4);
    question.getResponses().add(newChoice);
    ChoiceResponse newChoice2 = new ChoiceResponse();
    newChoice2.getContent().add(new Mattext(trans.translate("editor.newresponsetext")));
    newChoice2.setCorrect(false);
    newChoice2.setPoints(maxValue / 4);
    question.getResponses().add(newChoice2);
    ChoiceResponse newChoice3 = new ChoiceResponse();
    newChoice3.getContent().add(new Mattext(trans.translate("editor.newresponsetext")));
    newChoice3.setCorrect(false);
    newChoice3.setPoints(maxValue / 4);
    question.getResponses().add(newChoice3);
    ChoiceResponse newChoice4 = new ChoiceResponse();
    newChoice4.getContent().add(new Mattext(trans.translate("editor.newresponsetext")));
    newChoice4.setCorrect(false);
    newChoice4.setPoints(maxValue / 4);
    question.getResponses().add(newChoice4);
    question.setMaxValue(maxValue);
    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 15 with ChoiceResponse

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

the class QTIEditHelper method createSCItem.

/**
 * Creates a new Single Choice item
 * @param trans
 * @return New Singe Choice item.
 */
public static Item createSCItem(Translator trans) {
    Item newItem = new Item();
    newItem.setIdent(EDITOR_IDENT + ":" + ITEM_TYPE_SC + ":" + String.valueOf(CodeHelper.getRAMUniqueID()));
    newItem.setTitle(trans.translate("editor.newquestion"));
    newItem.setLabel("");
    // controls
    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_SC);
    question.setSingleCorrect(true);
    question.setSingleCorrectScore(1);
    ChoiceResponse newChoice = new ChoiceResponse();
    newChoice.setCorrect(true);
    newChoice.getContent().add(new Mattext(trans.translate("editor.newresponsetext")));
    question.getResponses().add(newChoice);
    QTIEditHelper.setFeedbackMastery(newItem, "");
    QTIEditHelper.setFeedbackFail(newItem, "");
    newItem.setQuestion(question);
    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)

Aggregations

ChoiceResponse (org.olat.ims.qti.editor.beecom.objects.ChoiceResponse)18 ArrayList (java.util.ArrayList)14 ChoiceQuestion (org.olat.ims.qti.editor.beecom.objects.ChoiceQuestion)14 Material (org.olat.ims.qti.editor.beecom.objects.Material)12 Mattext (org.olat.ims.qti.editor.beecom.objects.Mattext)10 Response (org.olat.ims.qti.editor.beecom.objects.Response)10 VFSItem (org.olat.core.util.vfs.VFSItem)6 Control (org.olat.ims.qti.editor.beecom.objects.Control)6 FIBResponse (org.olat.ims.qti.editor.beecom.objects.FIBResponse)6 Item (org.olat.ims.qti.editor.beecom.objects.Item)6 Question (org.olat.ims.qti.editor.beecom.objects.Question)6 List (java.util.List)4 FormLayoutContainer (org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer)4 EssayResponse (org.olat.ims.qti.editor.beecom.objects.EssayResponse)4 Iterator (java.util.Iterator)2 Element (org.dom4j.Element)2 FormLink (org.olat.core.gui.components.form.flexible.elements.FormLink)2 RichTextElement (org.olat.core.gui.components.form.flexible.elements.RichTextElement)2 VFSContainer (org.olat.core.util.vfs.VFSContainer)2 EssayQuestion (org.olat.ims.qti.editor.beecom.objects.EssayQuestion)2