Search in sources :

Example 6 with ChoiceResponse

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

the class QTIEditHelper method fetchChoices.

/**
 * Fetch choices.
 * @param response_labels
 * @return Map of choices.
 */
public static List<Response> fetchChoices(List response_labels) {
    List<Response> choices = new ArrayList<Response>();
    for (Iterator i = response_labels.iterator(); i.hasNext(); ) {
        ChoiceResponse choice = new ChoiceResponse();
        Element response_label = (Element) i.next();
        choice.setIdent(response_label.attributeValue("ident"));
        List materials = response_label.selectNodes(".//material");
        Material content = new Material();
        for (Iterator iter = materials.iterator(); iter.hasNext(); ) {
            Element el_material = (Element) iter.next();
            Material mat = (Material) parserManager.parse(el_material);
            content.getElements().addAll(mat.getElements());
        }
        // assure material always has some content
        if (content.getElements().size() == 0) {
            content.getElements().add(new Mattext(""));
        }
        choice.setContent(content);
        choices.add(choice);
    }
    return choices;
}
Also used : ChoiceResponse(org.olat.ims.qti.editor.beecom.objects.ChoiceResponse) 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) ChoiceResponse(org.olat.ims.qti.editor.beecom.objects.ChoiceResponse) Mattext(org.olat.ims.qti.editor.beecom.objects.Mattext) Element(org.dom4j.Element) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) Material(org.olat.ims.qti.editor.beecom.objects.Material)

Example 7 with ChoiceResponse

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

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

the class CSVToQuestionConverter method processChoice.

private void processChoice(String[] parts) {
    if (currentItem == null || parts.length < 2) {
        return;
    }
    try {
        Question question = currentItem.getItem().getQuestion();
        int type = question.getType();
        if (type == Question.TYPE_MC || type == Question.TYPE_SC) {
            float point = parseFloat(parts[0], 1.0f);
            String content = parts[1];
            ChoiceQuestion choice = (ChoiceQuestion) question;
            List<Response> choices = choice.getResponses();
            ChoiceResponse newChoice = new ChoiceResponse();
            newChoice.getContent().add(createMattext(content));
            newChoice.setCorrect(point > 0.0f);
            newChoice.setPoints(point);
            choices.add(newChoice);
        } else if (type == Question.TYPE_FIB) {
            String firstPart = parts[0].toLowerCase();
            FIBQuestion fib = (FIBQuestion) question;
            if ("text".equals(firstPart) || "texte".equals(firstPart)) {
                String text = parts[1];
                FIBResponse response = new FIBResponse();
                response.setType(FIBResponse.TYPE_CONTENT);
                Material mat = createMaterialWithText(text);
                response.setContent(mat);
                fib.getResponses().add(response);
            } else {
                float point = parseFloat(parts[0], 1.0f);
                String correctBlank = parts[1];
                FIBResponse response = new FIBResponse();
                response.setType(FIBResponse.TYPE_BLANK);
                response.setCorrectBlank(correctBlank);
                response.setPoints(point);
                if (parts.length > 2) {
                    String sizes = parts[2];
                    String[] sizeArr = sizes.split(",");
                    if (sizeArr.length >= 2) {
                        int size = Integer.parseInt(sizeArr[0]);
                        int maxLength = Integer.parseInt(sizeArr[1]);
                        response.setSize(size);
                        response.setMaxLength(maxLength);
                    }
                }
                fib.getResponses().add(response);
            }
        }
    } catch (NumberFormatException e) {
        log.warn("Cannot parse point for: " + parts[0] + " / " + parts[1], e);
    }
}
Also used : ChoiceResponse(org.olat.ims.qti.editor.beecom.objects.ChoiceResponse) FIBResponse(org.olat.ims.qti.editor.beecom.objects.FIBResponse) Response(org.olat.ims.qti.editor.beecom.objects.Response) ChoiceResponse(org.olat.ims.qti.editor.beecom.objects.ChoiceResponse) FIBResponse(org.olat.ims.qti.editor.beecom.objects.FIBResponse) ChoiceQuestion(org.olat.ims.qti.editor.beecom.objects.ChoiceQuestion) Question(org.olat.ims.qti.editor.beecom.objects.Question) FIBQuestion(org.olat.ims.qti.editor.beecom.objects.FIBQuestion) ChoiceQuestion(org.olat.ims.qti.editor.beecom.objects.ChoiceQuestion) Material(org.olat.ims.qti.editor.beecom.objects.Material) FIBQuestion(org.olat.ims.qti.editor.beecom.objects.FIBQuestion)

Example 9 with ChoiceResponse

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

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)

Example 10 with ChoiceResponse

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

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