Search in sources :

Example 41 with Response

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

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

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 43 with Response

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

the class QTI12MetadataController method setMCAndSCCorrectResponses.

private void setMCAndSCCorrectResponses(Question question, List<Response> responses, FormLayoutContainer layoutCont) {
    List<String> correctResponseNames = new ArrayList<>();
    List<ResponseAndPoints> responsesPoints = new ArrayList<>();
    if (responses != null && responses.size() > 0) {
        if (question.isSingleCorrect()) {
            for (Response response : responses) {
                if (response.isCorrect()) {
                    String responseSummary = getResponseSummary(response);
                    if (responseSummary != null) {
                        correctResponseNames.add(Formatter.formatLatexFormulas(responseSummary));
                    }
                }
            }
        } else {
            boolean hasNegative = false;
            for (Response response : responses) {
                if (response.getPoints() < 0.0f) {
                    hasNegative = true;
                }
            }
            for (Response response : responses) {
                String responseSummary = getResponseSummary(response);
                if (responseSummary != null && ((hasNegative && response.getPoints() >= 0.0f) || (!hasNegative && response.getPoints() > 0.0f))) {
                    boolean correct = response.getPoints() > 0.0f;
                    String points = Float.toString(response.getPoints());
                    ResponseAndPoints responseInfos = new ResponseAndPoints(responseSummary, points, correct);
                    responsesPoints.add(responseInfos);
                }
            }
        }
    }
    layoutCont.contextPut("responses", correctResponseNames);
    layoutCont.contextPut("responsesAndPoints", responsesPoints);
}
Also used : ChoiceResponse(org.olat.ims.qti.editor.beecom.objects.ChoiceResponse) Response(org.olat.ims.qti.editor.beecom.objects.Response) ArrayList(java.util.ArrayList)

Example 44 with Response

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

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

the class QTI12To21Converter method convertKPrim.

private AssessmentItemBuilder convertKPrim(Item item) {
    KPrimAssessmentItemBuilder itemBuilder = new KPrimAssessmentItemBuilder("Kprim", "New answer", qtiSerializer);
    convertItemBasics(item, itemBuilder);
    Question question = item.getQuestion();
    itemBuilder.setShuffle(question.isShuffle());
    List<Response> responses = question.getResponses();
    List<SimpleAssociableChoice> choices = itemBuilder.getKprimChoices();
    for (int i = 0; i < 4; i++) {
        Response response = responses.get(i);
        SimpleAssociableChoice choice = choices.get(i);
        String answer = response.getContent().renderAsHtmlForEditor();
        answer = blockedHtml(answer);
        if (StringHelper.isHtml(answer)) {
            htmlBuilder.appendHtml(choice, answer);
        } else {
            P firstChoiceText = AssessmentItemFactory.getParagraph(choice, answer);
            choice.getFlowStatics().clear();
            choice.getFlowStatics().add(firstChoiceText);
        }
        if (response.isCorrect()) {
            itemBuilder.setAssociation(choice.getIdentifier(), QTI21Constants.CORRECT_IDENTIFIER);
        } else {
            itemBuilder.setAssociation(choice.getIdentifier(), QTI21Constants.WRONG_IDENTIFIER);
        }
    }
    double score = question.getMaxValue();
    itemBuilder.setMinScore(0.0d);
    itemBuilder.setMaxScore(score);
    return itemBuilder;
}
Also used : FIBResponse(org.olat.ims.qti.editor.beecom.objects.FIBResponse) ChoiceResponse(org.olat.ims.qti.editor.beecom.objects.ChoiceResponse) Response(org.olat.ims.qti.editor.beecom.objects.Response) EssayResponse(org.olat.ims.qti.editor.beecom.objects.EssayResponse) P(uk.ac.ed.ph.jqtiplus.node.content.xhtml.text.P) KPrimAssessmentItemBuilder(org.olat.ims.qti21.model.xml.interactions.KPrimAssessmentItemBuilder) SimpleAssociableChoice(uk.ac.ed.ph.jqtiplus.node.item.interaction.choice.SimpleAssociableChoice) EssayQuestion(org.olat.ims.qti.editor.beecom.objects.EssayQuestion) ChoiceQuestion(org.olat.ims.qti.editor.beecom.objects.ChoiceQuestion) Question(org.olat.ims.qti.editor.beecom.objects.Question)

Aggregations

Response (org.olat.ims.qti.editor.beecom.objects.Response)60 FIBResponse (org.olat.ims.qti.editor.beecom.objects.FIBResponse)44 ArrayList (java.util.ArrayList)32 ChoiceResponse (org.olat.ims.qti.editor.beecom.objects.ChoiceResponse)26 ChoiceQuestion (org.olat.ims.qti.editor.beecom.objects.ChoiceQuestion)22 Question (org.olat.ims.qti.editor.beecom.objects.Question)22 EssayResponse (org.olat.ims.qti.editor.beecom.objects.EssayResponse)20 Material (org.olat.ims.qti.editor.beecom.objects.Material)20 HashMap (java.util.HashMap)14 Item (org.olat.ims.qti.editor.beecom.objects.Item)14 EssayQuestion (org.olat.ims.qti.editor.beecom.objects.EssayQuestion)12 List (java.util.List)10 FIBQuestion (org.olat.ims.qti.editor.beecom.objects.FIBQuestion)10 StatisticSurveyItemResponse (org.olat.ims.qti.statistics.model.StatisticSurveyItemResponse)10 Mattext (org.olat.ims.qti.editor.beecom.objects.Mattext)8 StatisticAnswerOption (org.olat.ims.qti.statistics.model.StatisticAnswerOption)8 StatisticChoiceOption (org.olat.ims.qti.statistics.model.StatisticChoiceOption)8 File (java.io.File)6 URL (java.net.URL)6 Test (org.junit.Test)6