Search in sources :

Example 11 with Control

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

Example 12 with Control

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

the class ItemMetadataFormController 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.metadata");
    int t = item.getQuestion().getType();
    if (!isSurvey && t == Question.TYPE_ESSAY) {
        setFormWarning("warning.essay.test");
    }
    if (isSurvey) {
        setFormContextHelp("Test and Questionnaire Editor in Detail#details_testeditor_test_konf_frage");
    } else {
        setFormContextHelp("Test and Questionnaire Editor in Detail#details_testeditor_test_konf_frage");
    }
    // Title
    title = uifactory.addTextElement("title", "form.imd.title", -1, item.getTitle(), formLayout);
    title.setMandatory(true);
    title.setNotEmptyCheck("form.imd.error.empty.title");
    // Question Type
    String typeName = getType();
    uifactory.addStaticTextElement("type", "form.imd.type", typeName, formLayout);
    // Description
    desc = uifactory.addRichTextElementForStringData("desc", "form.imd.descr", item.getObjectives(), 8, -1, true, null, null, formLayout, ureq.getUserSession(), getWindowControl());
    desc.getEditorConfiguration().setFigCaption(false);
    RichTextConfiguration richTextConfig = desc.getEditorConfiguration();
    // set upload dir to the media dir
    richTextConfig.setFileBrowserUploadRelPath("media");
    // Layout/Alignment
    Question q = item.getQuestion();
    // alignment of KPRIM is only horizontal
    if (q instanceof ChoiceQuestion && item.getQuestion().getType() != Question.TYPE_KPRIM) {
        String[] layoutKeys = new String[] { "h", "v" };
        String[] layoutValues = new String[] { translate("form.imd.layout.horizontal"), translate("form.imd.layout.vertical") };
        // layout = uifactory.addDropdownSingleselect("form.imd.layout", formLayout, layoutKeys, layoutValues, null);
        layout = uifactory.addRadiosHorizontal("layout", "form.imd.layout", formLayout, layoutKeys, layoutValues);
        layout.select(((ChoiceQuestion) q).getFlowLabelClass().equals(ChoiceQuestion.BLOCK) ? "h" : "v", true);
    }
    if (!isSurvey) {
        String[] yesnoKeys = new String[] { "y", "n" };
        String[] yesnoValues = new String[] { translate("yes"), translate("no") };
        // Attempts
        limitAttempts = uifactory.addRadiosHorizontal("form.imd.limittries", formLayout, yesnoKeys, yesnoValues);
        limitAttempts.setEnabled(!isRestrictedEditMode);
        // Radios/Checkboxes need onclick because of IE bug OLAT-5753
        limitAttempts.addActionListener(FormEvent.ONCLICK);
        attempts = uifactory.addIntegerElement("form.imd.tries", 0, formLayout);
        attempts.setEnabled(!isRestrictedEditMode);
        attempts.setDisplaySize(3);
        if (item.getMaxattempts() > 0) {
            limitAttempts.select("y", true);
            attempts.setIntValue(item.getMaxattempts());
        } else {
            limitAttempts.select("n", true);
            attempts.setVisible(false);
        }
        // Time Limit
        limitTime = uifactory.addRadiosHorizontal("form.imd.limittime", formLayout, yesnoKeys, yesnoValues);
        // Radios/Checkboxes need onclick because of IE bug OLAT-5753
        limitTime.addActionListener(FormEvent.ONCLICK);
        limitTime.setEnabled(!isRestrictedEditMode);
        timeMin = uifactory.addIntegerElement("form.imd.time.min", 0, formLayout);
        timeMin.setEnabled(!isRestrictedEditMode);
        timeMin.setDisplaySize(3);
        timeSec = uifactory.addIntegerElement("form.imd.time.sek", 0, formLayout);
        timeSec.setEnabled(!isRestrictedEditMode);
        timeSec.setDisplaySize(3);
        if (item.getDuration() != null && item.getDuration().isSet()) {
            limitTime.select("y", true);
            timeMin.setIntValue(item.getDuration().getMin());
            timeSec.setIntValue(item.getDuration().getSec());
        } else {
            limitTime.select("n", true);
            timeMin.setVisible(false);
            timeSec.setVisible(false);
        }
        // Shuffle Answers
        shuffle = uifactory.addRadiosHorizontal("shuffle", "form.imd.shuffle", formLayout, yesnoKeys, yesnoValues);
        shuffle.setEnabled(!isRestrictedEditMode);
        shuffle.setVisible(t != Question.TYPE_ESSAY && t != Question.TYPE_FIB);
        if (item.getQuestion().isShuffle()) {
            shuffle.select("y", true);
        } else {
            shuffle.select("n", true);
        }
        // Hints
        Control itemControl = item.getItemcontrols().get(0);
        showHints = uifactory.addRadiosHorizontal("showHints", "form.imd.solutionhints.show", formLayout, yesnoKeys, yesnoValues);
        showHints.setEnabled(!isRestrictedEditMode);
        // Radios/Checkboxes need onclick because of IE bug OLAT-5753
        showHints.addActionListener(FormEvent.ONCLICK);
        showHints.setVisible(t != Question.TYPE_ESSAY);
        hint = uifactory.addRichTextElementForStringData("hint", "form.imd.solutionhints", item.getQuestion().getHintText(), 8, -1, true, qti.getBaseDir(), null, formLayout, ureq.getUserSession(), getWindowControl());
        hint.setEnabled(!isRestrictedEditMode);
        hint.getEditorConfiguration().setFigCaption(false);
        // set upload dir to the media dir
        hint.getEditorConfiguration().setFileBrowserUploadRelPath("media");
        if (itemControl.isHint()) {
            showHints.select("y", true);
        } else {
            showHints.select("n", true);
            hint.setVisible(false);
        }
        // Solution
        showSolution = uifactory.addRadiosHorizontal("showSolution", "form.imd.correctsolution.show", formLayout, yesnoKeys, yesnoValues);
        showSolution.setEnabled(!isRestrictedEditMode);
        // Radios/Checkboxes need onclick because of IE bug OLAT-5753
        showSolution.addActionListener(FormEvent.ONCLICK);
        boolean essay = (q.getType() == Question.TYPE_ESSAY);
        String solLabel = essay ? "form.imd.correctsolution.word" : "form.imd.correctsolution";
        solution = uifactory.addRichTextElementForStringData("solution", solLabel, item.getQuestion().getSolutionText(), 8, -1, true, qti.getBaseDir(), null, formLayout, ureq.getUserSession(), getWindowControl());
        solution.setEnabled(!isRestrictedEditMode);
        solution.getEditorConfiguration().setFigCaption(false);
        // set upload dir to the media dir
        solution.getEditorConfiguration().setFileBrowserUploadRelPath("media");
        if (itemControl.isSolution()) {
            showSolution.select("y", true);
        } else {
            showSolution.select("n", true);
            showSolution.setVisible(!essay);
            // solution always visible for essay
            solution.setVisible(essay);
        }
    }
    // Submit Button
    uifactory.addFormSubmitButton("submit", formLayout);
}
Also used : RichTextConfiguration(org.olat.core.gui.components.form.flexible.impl.elements.richText.RichTextConfiguration) WindowControl(org.olat.core.gui.control.WindowControl) Control(org.olat.ims.qti.editor.beecom.objects.Control) 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 Control

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

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 14 with Control

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

the class ItemNode method createChangeMessage.

public String createChangeMessage(Memento mem) {
    String retVal = null;
    if (mem instanceof QtiNodeMemento) {
        QtiNodeMemento qnm = (QtiNodeMemento) mem;
        Map<String, Object> qtiState = qnm.getQtiState();
        // 
        String oldTitle = (String) qtiState.get("TITLE");
        String newTitle = item.getTitle();
        String titleChange = null;
        // 
        String oldObjectives = (String) qtiState.get("OBJECTIVES");
        String newObjectives = item.getObjectives();
        String objectChange = null;
        // 
        Question question = item.getQuestion();
        boolean isFIB = question.getType() == Question.TYPE_FIB;
        boolean isESSAY = question.getType() == Question.TYPE_ESSAY;
        String oldHinttext = (String) qtiState.get("QUESTION.HINTTEXT");
        String newHinttext = question.getHintText();
        String hinttextChange = null;
        // 
        String oldQuestion = (String) qtiState.get("QUESTION.MATERIAL.ASTEXT");
        String newQuestion = question.getQuestion().renderAsText();
        String questionChange = null;
        // feedback
        String feedbackChanges = "";
        String oldFeedbackMastery = (String) qtiState.get("FEEDBACK.MASTERY");
        String newFeedbackMastery = QTIEditHelper.getFeedbackMasteryText(item);
        String oldFeedbackFail = (String) qtiState.get("FEEDBACK.FAIL");
        String newFeedbackFail = QTIEditHelper.getFeedbackFailText(item);
        Control control = QTIEditHelper.getControl(item);
        Boolean oldHasFeedback = (Boolean) qtiState.get("FEEDBACK.ENABLED");
        Boolean newHasFeedback = control != null ? new Boolean(control.getFeedback() == 1) : null;
        // 
        List asTexts = (List) qtiState.get("QUESTION.RESPONSES.ASTEXT");
        List feedbacks = (List) qtiState.get("QUESTION.RESPONSES.FEEDBACK");
        String oldResp = null;
        String newResp = null;
        String oldFeedback = null;
        String newFeedback = null;
        String responsesChanges = "";
        List<Response> responses = question.getResponses();
        int i = 0;
        boolean nothingToDo = false;
        for (Iterator<Response> iter = responses.iterator(); iter.hasNext(); ) {
            nothingToDo = false;
            Response resp = iter.next();
            if (isFIB) {
                if (FIBResponse.TYPE_BLANK.equals(((FIBResponse) resp).getType())) {
                    newResp = formatFIBResponseAsText((FIBResponse) resp);
                } else {
                    // skip
                    nothingToDo = true;
                }
            } else if (isESSAY) {
                newResp = formatESSAYResponseAsText((EssayResponse) resp);
            } else {
                newResp = resp.getContent().renderAsText();
            }
            // if NOT nothingToDO
            if (!nothingToDo) {
                oldResp = (String) asTexts.get(i);
                if ((oldResp != null && !oldResp.equals(newResp)) || (newResp != null && !newResp.equals(oldResp))) {
                    if (isFIB) {
                        responsesChanges += "\nBlank changed:";
                        responsesChanges += "\nold blank: \n\t" + formatVariable(oldResp) + "\n\nnew blank: \n\t" + formatVariable(newResp);
                    } else {
                        responsesChanges += "\nResponse changed:";
                        responsesChanges += "\nold response: \n\t" + formatVariable(oldResp) + "\n\nnew response: \n\t" + formatVariable(newResp);
                    }
                }
                // feedback to response changed?
                newFeedback = QTIEditHelper.getFeedbackOlatRespText(item, resp.getIdent());
                oldFeedback = (String) feedbacks.get(i);
                if ((oldFeedback != null && !oldFeedback.equals(newFeedback)) || (newFeedback != null && !newFeedback.equals(oldFeedback))) {
                    feedbackChanges += "\nFeedback changed:";
                    feedbackChanges += "\nold feedback: \n\t" + formatVariable(oldFeedback) + "\n\nnew feedback: \n\t" + formatVariable(newFeedback);
                }
                i++;
            }
        }
        // 
        retVal = "\n---+++ Item changes [" + oldTitle + "]:";
        if ((oldTitle != null && !oldTitle.equals(newTitle)) || (newTitle != null && !newTitle.equals(oldTitle))) {
            titleChange = "\n\nold title: \n\t" + formatVariable(oldTitle) + "\n\nnew title: \n\t" + formatVariable(newTitle);
        }
        if ((oldObjectives != null && !oldObjectives.equals(newObjectives)) || (newObjectives != null && !newObjectives.equals(oldObjectives))) {
            objectChange = "\n\nold objectives: \n\t" + formatVariable(oldObjectives) + "\n\nnew objectives: \n\t" + formatVariable(newObjectives);
        }
        if (titleChange != null || objectChange != null) {
            retVal += "\nMetadata changed:";
            if (titleChange != null)
                retVal += titleChange;
            if (objectChange != null)
                retVal += objectChange;
        }
        // 
        if ((oldHinttext != null && !oldHinttext.equals(newHinttext)) || (newHinttext != null && !newHinttext.equals(oldHinttext))) {
            hinttextChange = "\n---+++ old hinttext: \n\t" + formatVariable(oldHinttext) + "\n\nnew hinttext: \n\t" + formatVariable(newHinttext);
            retVal += hinttextChange;
        }
        if ((oldQuestion != null && !oldQuestion.equals(newQuestion)) || (newQuestion != null && !newQuestion.equals(oldQuestion))) {
            questionChange = "\n---+++ old question: \n\t" + formatVariable(oldQuestion) + "\n\nnew question: \n\t" + formatVariable(newQuestion);
            retVal += questionChange;
        }
        if (!responsesChanges.equals("")) {
            retVal += responsesChanges;
        }
        if ((oldFeedbackMastery != null && !oldFeedbackMastery.equals(newFeedbackMastery)) || (newFeedbackMastery != null && !newFeedbackMastery.equals(oldFeedbackMastery))) {
            String tmp = "\n---+++ old master feedback: \n\t" + formatVariable(oldFeedbackMastery) + "\n\nnew master feedback: \n\t" + formatVariable(newFeedbackMastery);
            feedbackChanges = tmp + feedbackChanges;
        }
        if ((oldFeedbackFail != null && !oldFeedbackFail.equals(newFeedbackFail)) || (newFeedbackFail != null && !newFeedbackFail.equals(oldFeedbackFail))) {
            String tmp = "\n---+++ old fail feedback: \n\t" + formatVariable(oldFeedbackFail) + "\n\nnew fail feedback: \n\t" + formatVariable(newFeedbackFail);
            feedbackChanges = tmp + feedbackChanges;
        }
        if ((oldHasFeedback != null && newHasFeedback != null && oldHasFeedback != newHasFeedback)) {
            String oldF = oldHasFeedback.booleanValue() ? "enabled" : "disabled";
            String newF = newHasFeedback.booleanValue() ? "enabled" : "disabled";
            feedbackChanges = "\n---+++ feedback was : \n\t" + oldF + "\n\n feedback is now: \n\t" + newF + feedbackChanges;
        }
        if (!feedbackChanges.equals("")) {
            retVal += feedbackChanges;
        }
        return retVal;
    }
    return "undefined";
}
Also used : 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) QTIObject(org.olat.ims.qti.editor.beecom.objects.QTIObject) Question(org.olat.ims.qti.editor.beecom.objects.Question) ArrayList(java.util.ArrayList) List(java.util.List)

Example 15 with Control

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

the class CSVToQuestionConverter method processFeedbackWrongAnswer.

private void processFeedbackWrongAnswer(String[] parts) {
    if (currentItem == null || parts.length < 2)
        return;
    String feedback = parts[1];
    if (StringHelper.containsNonWhitespace(feedback)) {
        Item item = currentItem.getItem();
        Control control = QTIEditHelper.getControl(item);
        if (control.getFeedback() != 1) {
            control.setFeedback(1);
        }
        QTIEditHelper.setFeedbackFail(item, feedback);
    }
}
Also used : Item(org.olat.ims.qti.editor.beecom.objects.Item) Control(org.olat.ims.qti.editor.beecom.objects.Control)

Aggregations

Control (org.olat.ims.qti.editor.beecom.objects.Control)36 ArrayList (java.util.ArrayList)22 Item (org.olat.ims.qti.editor.beecom.objects.Item)18 VFSItem (org.olat.core.util.vfs.VFSItem)12 ChoiceQuestion (org.olat.ims.qti.editor.beecom.objects.ChoiceQuestion)12 List (java.util.List)10 WindowControl (org.olat.core.gui.control.WindowControl)10 Mattext (org.olat.ims.qti.editor.beecom.objects.Mattext)10 QTIObject (org.olat.ims.qti.editor.beecom.objects.QTIObject)10 Question (org.olat.ims.qti.editor.beecom.objects.Question)10 Iterator (java.util.Iterator)8 Duration (org.olat.ims.qti.editor.beecom.objects.Duration)8 Element (org.dom4j.Element)6 Assessment (org.olat.ims.qti.editor.beecom.objects.Assessment)6 ChoiceResponse (org.olat.ims.qti.editor.beecom.objects.ChoiceResponse)6 EssayResponse (org.olat.ims.qti.editor.beecom.objects.EssayResponse)6 FIBResponse (org.olat.ims.qti.editor.beecom.objects.FIBResponse)6 Material (org.olat.ims.qti.editor.beecom.objects.Material)6 OutcomesProcessing (org.olat.ims.qti.editor.beecom.objects.OutcomesProcessing)6 Section (org.olat.ims.qti.editor.beecom.objects.Section)6