Search in sources :

Example 1 with ChoiceResponse

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

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 2 with ChoiceResponse

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

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 3 with ChoiceResponse

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

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 4 with ChoiceResponse

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

the class QTI12To21Converter method convertFeedbackPerAnswers.

private void convertFeedbackPerAnswers(Item item, AssessmentItemBuilder itemBuilder, Map<String, Identifier> identToIdentifier) {
    Question question = item.getQuestion();
    List<ModalFeedbackBuilder> additionalFeedbacks = new ArrayList<>();
    for (Response response : question.getResponses()) {
        if (response instanceof ChoiceResponse) {
            Material responseFeedbackMat = QTIEditHelper.getFeedbackOlatRespMaterial(item, response.getIdent());
            if (responseFeedbackMat != null) {
                String feedbackCondition = responseFeedbackMat.renderAsHtmlForEditor();
                feedbackCondition = blockedHtml(feedbackCondition);
                ModalFeedbackCondition condition = new ModalFeedbackCondition();
                condition.setVariable(Variable.response);
                condition.setOperator(Operator.equals);
                condition.setValue(identToIdentifier.get(response.getIdent()).toString());
                List<ModalFeedbackCondition> conditions = new ArrayList<>(1);
                conditions.add(condition);
                ModalFeedbackBuilder feedback = new ModalFeedbackBuilder(itemBuilder.getAssessmentItem(), ModalFeedbackType.additional);
                feedback.setFeedbackConditions(conditions);
                feedback.setText(feedbackCondition);
                additionalFeedbacks.add(feedback);
            }
        }
    }
    itemBuilder.setAdditionalFeedbackBuilders(additionalFeedbacks);
}
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) ChoiceResponse(org.olat.ims.qti.editor.beecom.objects.ChoiceResponse) ModalFeedbackBuilder(org.olat.ims.qti21.model.xml.ModalFeedbackBuilder) ArrayList(java.util.ArrayList) 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) Material(org.olat.ims.qti.editor.beecom.objects.Material) ModalFeedbackCondition(org.olat.ims.qti21.model.xml.ModalFeedbackCondition)

Example 5 with ChoiceResponse

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

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