Search in sources :

Example 6 with Control

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

the class QTIEditHelper method getControl.

/**
 * Get controls.
 * @param object
 * @return Controls.
 */
public static Control getControl(QTIObject object) {
    Control control = null;
    List controls = null;
    if (Item.class.isAssignableFrom(object.getClass())) {
        Item item = (Item) object;
        controls = item.getItemcontrols();
    } else if (Section.class.isAssignableFrom(object.getClass())) {
        Section section = (Section) object;
        controls = section.getSectioncontrols();
    } else if (Assessment.class.isAssignableFrom(object.getClass())) {
        Assessment assessment = (Assessment) object;
        controls = assessment.getAssessmentcontrols();
    }
    for (Iterator i = controls.iterator(); i.hasNext(); ) {
        Control tmp = (Control) i.next();
        if (tmp.getView() != null) {
            if (tmp.getView().equalsIgnoreCase("all")) {
                control = tmp;
                break;
            }
        } else {
            control = tmp;
        }
    }
    return control;
}
Also used : 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) Assessment(org.olat.ims.qti.editor.beecom.objects.Assessment) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) Section(org.olat.ims.qti.editor.beecom.objects.Section)

Example 7 with Control

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

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

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

the class AssessmentController 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)
 */
public void event(UserRequest ureq, Component source, Event event) {
    if (source == main) {
        if (event.getCommand().equals("sao")) {
            // asessment options submitted
            // Handle all data that is useless in survey mode
            String newTitle = ureq.getParameter("title");
            String oldTitle = assessment.getTitle();
            boolean hasTitleChange = newTitle != null && !newTitle.equals(oldTitle);
            String newObjectives = ureq.getParameter("objectives");
            String oldObjectives = assessment.getObjectives();
            boolean hasObjectivesChange = newObjectives != null && !newObjectives.equals(oldObjectives);
            NodeBeforeChangeEvent nce = new NodeBeforeChangeEvent();
            if (hasTitleChange) {
                nce.setNewTitle(newTitle);
            }
            if (hasObjectivesChange) {
                nce.setNewObjectives(newObjectives);
            }
            if (hasTitleChange || hasObjectivesChange) {
                // create a memento first
                fireEvent(ureq, nce);
                // then apply changes
                assessment.setTitle(newTitle);
                assessment.setObjectives(newObjectives);
            }
            // 
            if (!surveyMode && !restrictedEdit) {
                // ordering
                assessment.getSelection_ordering().setOrderType(ureq.getParameter("order_type"));
                assessment.getSelection_ordering().setSelectionNumber(ureq.getParameter("selection_number"));
                main.contextPut("order_type", assessment.getSelection_ordering().getOrderType());
                main.contextPut("selection_number", String.valueOf(assessment.getSelection_ordering().getSelectionNumber()));
                Control tmpControl = QTIEditHelper.getControl(assessment);
                boolean oldInheritControls = assessment.isInheritControls();
                boolean newInheritControls = ureq.getParameter("inheritswitch").equals("Yes");
                assessment.setInheritControls(newInheritControls);
                String feedbackswitchTmp = ureq.getParameter("feedbackswitch");
                String hintswitchTmp = ureq.getParameter("hintswitch");
                String solutionswitchTmp = ureq.getParameter("solutionswitch");
                tmpControl.setSwitches(feedbackswitchTmp, hintswitchTmp, solutionswitchTmp);
                if (tmpControl.getHint() != Control.CTRL_UNDEF || tmpControl.getHint() != Control.CTRL_UNDEF || tmpControl.getSolution() != Control.CTRL_UNDEF)
                    assessment.setInheritControls(true);
                if (oldInheritControls && !newInheritControls) {
                    tmpControl.setSwitches(Control.CTRL_UNDEF, Control.CTRL_UNDEF, Control.CTRL_UNDEF);
                    assessment.setInheritControls(false);
                }
                OutcomesProcessing outcomesProcessing = assessment.getOutcomes_processing();
                if (outcomesProcessing == null) {
                    // Create outcomes processing object if it doesn't already exist.
                    // Happens
                    // when creating a new assessment
                    outcomesProcessing = new OutcomesProcessing();
                    assessment.setOutcomes_processing(outcomesProcessing);
                }
                String cutval = ureq.getParameter(OutcomesProcessing.CUTVALUE);
                try {
                    Float.parseFloat(cutval);
                } catch (NumberFormatException nfe) {
                    cutval = "0.0";
                    this.showWarning("error.cutval");
                }
                outcomesProcessing.setField(OutcomesProcessing.CUTVALUE, cutval);
                main.contextPut(OutcomesProcessing.CUTVALUE, cutval);
                if (ureq.getParameter("duration").equals("Yes")) {
                    String durationMin = ureq.getParameter("duration_min");
                    String durationSec = ureq.getParameter("duration_sec");
                    try {
                        Integer.parseInt(durationMin);
                        int sec = Integer.parseInt(durationSec);
                        if (sec > 60)
                            throw new NumberFormatException();
                    } catch (NumberFormatException nfe) {
                        durationMin = "0";
                        durationSec = "0";
                        this.showWarning("error.duration");
                    }
                    Duration d = new Duration(durationMin, durationSec);
                    assessment.setDuration(d);
                    main.contextPut("duration", assessment.getDuration());
                } else {
                    assessment.setDuration(null);
                    main.contextRemove("duration");
                }
            }
            qtiPackage.serializeQTIDocument();
            // refresh for removing dirty marking of button even if nothing changed
            main.setDirty(true);
        }
    }
}
Also used : WindowControl(org.olat.core.gui.control.WindowControl) Control(org.olat.ims.qti.editor.beecom.objects.Control) OutcomesProcessing(org.olat.ims.qti.editor.beecom.objects.OutcomesProcessing) Duration(org.olat.ims.qti.editor.beecom.objects.Duration)

Example 9 with Control

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

the class CSVToQuestionConverter method processFeedbackCorrectAnswer.

private void processFeedbackCorrectAnswer(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.setFeedbackMastery(item, feedback);
    }
}
Also used : Item(org.olat.ims.qti.editor.beecom.objects.Item) Control(org.olat.ims.qti.editor.beecom.objects.Control)

Example 10 with Control

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

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