Search in sources :

Example 1 with Duration

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

the class ItemParser method parse.

/**
 * @see org.olat.ims.qti.editor.beecom.parser.IParser#parse(org.dom4j.Element)
 */
public Object parse(Element element) {
    // assert element.getName().equalsIgnoreCase("item");
    Item item = new Item();
    Attribute tmp = element.attribute("ident");
    if (tmp != null)
        item.setIdent(tmp.getValue());
    else
        item.setIdent("" + CodeHelper.getRAMUniqueID());
    tmp = element.attribute("title");
    if (tmp != null)
        item.setTitle(tmp.getValue());
    tmp = element.attribute("label");
    if (tmp != null)
        item.setLabel(tmp.getValue());
    tmp = element.attribute("maxattempts");
    if (tmp != null) {
        try {
            item.setMaxattempts(Integer.parseInt(tmp.getValue()));
        } catch (NumberFormatException nfe) {
            item.setMaxattempts(0);
        }
    }
    // if editor can't handle type of item, just keep raw XML
    if (!(item.getIdent().startsWith(ITEM_PREFIX_SCQ) || item.getIdent().startsWith(ITEM_PREFIX_MCQ) || item.getIdent().startsWith(ITEM_PREFIX_FIB) || item.getIdent().startsWith(ITEM_PREFIX_ESSAY) || item.getIdent().startsWith(ITEM_PREFIX_KPRIM))) {
        item.setRawXML(new QTIXMLWrapper(element));
        return item;
    }
    // for render_fib that contains rows attribute and convert them to essay
    if (item.getIdent().startsWith(ITEM_PREFIX_FIB) && element.selectNodes(".//render_fib[@rows]").size() > 0) {
        item.setIdent(item.getIdent().replaceFirst("FIB", "ESSAY"));
    }
    // DURATION
    Duration duration = (Duration) parserManager.parse(element.element("duration"));
    item.setDuration(duration);
    // CONTROLS
    List itemcontrolsXML = element.elements("itemcontrol");
    List itemcontrols = new ArrayList();
    for (Iterator i = itemcontrolsXML.iterator(); i.hasNext(); ) {
        itemcontrols.add(parserManager.parse((Element) i.next()));
    }
    if (itemcontrols.size() == 0) {
        itemcontrols.add(new Control());
    }
    item.setItemcontrols(itemcontrols);
    // OBJECTIVES
    Element mattext = (Element) element.selectSingleNode("./objectives/material/mattext");
    if (mattext != null)
        item.setObjectives(mattext.getTextTrim());
    // QUESTIONS
    if (item.getIdent().startsWith(ITEM_PREFIX_SCQ))
        item.setQuestion(ChoiceQuestion.getInstance(element));
    else if (item.getIdent().startsWith(ITEM_PREFIX_MCQ))
        item.setQuestion(ChoiceQuestion.getInstance(element));
    else if (item.getIdent().startsWith(ITEM_PREFIX_FIB))
        item.setQuestion(FIBQuestion.getInstance(element));
    else if (item.getIdent().startsWith(ITEM_PREFIX_ESSAY))
        item.setQuestion(EssayQuestion.getInstance(element));
    else if (item.getIdent().startsWith(ITEM_PREFIX_KPRIM))
        item.setQuestion(ChoiceQuestion.getInstance(element));
    // FEEDBACKS
    List feedbacksXML = element.elements("itemfeedback");
    List feedbacks = new ArrayList();
    item.setItemfeedbacks(feedbacks);
    Question question = item.getQuestion();
    for (Iterator i = feedbacksXML.iterator(); i.hasNext(); ) {
        Element el_feedback = (Element) i.next();
        if (el_feedback.element("solution") != null) {
            // fetch solution
            Element el_solution = el_feedback.element("solution");
            question.setSolutionText(getMaterialAsString(el_solution));
        } else if (el_feedback.element("hint") != null) {
            // fetch hint
            Element el_hint = el_feedback.element("hint");
            question.setHintText(getMaterialAsString(el_hint));
        } else {
            QTIObject tmpObj = (QTIObject) parserManager.parse(el_feedback);
            if (tmpObj != null)
                feedbacks.add(tmpObj);
        }
    }
    return item;
}
Also used : Item(org.olat.ims.qti.editor.beecom.objects.Item) Control(org.olat.ims.qti.editor.beecom.objects.Control) QTIObject(org.olat.ims.qti.editor.beecom.objects.QTIObject) Attribute(org.dom4j.Attribute) QTIXMLWrapper(org.olat.ims.qti.editor.beecom.objects.QTIXMLWrapper) Element(org.dom4j.Element) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) Duration(org.olat.ims.qti.editor.beecom.objects.Duration) ArrayList(java.util.ArrayList) List(java.util.List) 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) FIBQuestion(org.olat.ims.qti.editor.beecom.objects.FIBQuestion)

Example 2 with Duration

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

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

the class SectionController method formOK.

@Override
protected void formOK(UserRequest ureq) {
    String newTitle = titleEl.getValue();
    if (newTitle.trim().isEmpty()) {
        // Remove empty title to fix OLAT-2296
        newTitle = "";
    }
    String oldTitle = section.getTitle();
    boolean hasTitleChange = newTitle != null && !newTitle.equals(oldTitle);
    String newObjectives = objectivesEl.getValue();
    String oldObjectives = section.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
        nce.setSectionIdent(section.getIdent());
        fireEvent(ureq, nce);
        // then apply changes
        section.setTitle(newTitle);
        section.setObjectives(newObjectives);
    }
    if (!restrictedEdit) {
        String selectionNumStr = selectionNumEl.getSelectedKey();
        int selectionNum = 1;
        try {
            selectionNum = Integer.parseInt(selectionNumStr);
        } catch (NumberFormatException e) {
            logWarn("", e);
        }
        section.getSelection_ordering().setSelectionNumber(selectionNum);
        boolean randomType = shuffleEl.isOneSelected() && shuffleEl.isSelected(0);
        if (randomType) {
            section.getSelection_ordering().setOrderType(SelectionOrdering.RANDOM);
        } else {
            section.getSelection_ordering().setOrderType(SelectionOrdering.SEQUENTIAL);
        }
        boolean duration = limitTimeEl.isOneSelected() && limitTimeEl.isSelected(0);
        if (duration) {
            String durationMin = timeMinEl.getValue();
            String durationSec = timeSecEl.getValue();
            try {
                Integer.parseInt(durationMin);
                int sec = Integer.parseInt(durationSec);
                if (sec > 60)
                    throw new NumberFormatException();
            } catch (NumberFormatException nfe) {
                durationMin = "0";
                durationSec = "0";
                showWarning("error.duration");
            }
            Duration d = new Duration(durationMin, durationSec);
            section.setDuration(d);
            timeMinEl.setIntValue(d.getMin());
            timeSecEl.setIntValue(d.getSec());
        } else {
            section.setDuration(null);
        }
    }
    qtiPackage.serializeQTIDocument();
}
Also used : Duration(org.olat.ims.qti.editor.beecom.objects.Duration)

Example 4 with Duration

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

the class SectionController method formOK.

@Override
protected void formOK(UserRequest ureq) {
    String newTitle = titleEl.getValue();
    if (newTitle.trim().isEmpty()) {
        // Remove empty title to fix OLAT-2296
        newTitle = "";
    }
    String oldTitle = section.getTitle();
    boolean hasTitleChange = newTitle != null && !newTitle.equals(oldTitle);
    String newObjectives = objectivesEl.getValue();
    String oldObjectives = section.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
        nce.setSectionIdent(section.getIdent());
        fireEvent(ureq, nce);
        // then apply changes
        section.setTitle(newTitle);
        section.setObjectives(newObjectives);
    }
    if (!restrictedEdit) {
        String selectionNumStr = selectionNumEl.getSelectedKey();
        int selectionNum = 1;
        try {
            selectionNum = Integer.parseInt(selectionNumStr);
        } catch (NumberFormatException e) {
            logWarn("", e);
        }
        section.getSelection_ordering().setSelectionNumber(selectionNum);
        boolean randomType = shuffleEl.isOneSelected() && shuffleEl.isSelected(0);
        if (randomType) {
            section.getSelection_ordering().setOrderType(SelectionOrdering.RANDOM);
        } else {
            section.getSelection_ordering().setOrderType(SelectionOrdering.SEQUENTIAL);
        }
        boolean duration = limitTimeEl.isOneSelected() && limitTimeEl.isSelected(0);
        if (duration) {
            String durationMin = timeMinEl.getValue();
            String durationSec = timeSecEl.getValue();
            try {
                Integer.parseInt(durationMin);
                int sec = Integer.parseInt(durationSec);
                if (sec > 60)
                    throw new NumberFormatException();
            } catch (NumberFormatException nfe) {
                durationMin = "0";
                durationSec = "0";
                showWarning("error.duration");
            }
            Duration d = new Duration(durationMin, durationSec);
            section.setDuration(d);
            timeMinEl.setIntValue(d.getMin());
            timeSecEl.setIntValue(d.getSec());
        } else {
            section.setDuration(null);
        }
    }
    qtiPackage.serializeQTIDocument();
}
Also used : Duration(org.olat.ims.qti.editor.beecom.objects.Duration)

Example 5 with Duration

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

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)

Aggregations

Duration (org.olat.ims.qti.editor.beecom.objects.Duration)10 Control (org.olat.ims.qti.editor.beecom.objects.Control)8 ArrayList (java.util.ArrayList)4 Iterator (java.util.Iterator)4 List (java.util.List)4 Element (org.dom4j.Element)4 WindowControl (org.olat.core.gui.control.WindowControl)4 ChoiceQuestion (org.olat.ims.qti.editor.beecom.objects.ChoiceQuestion)4 QTIObject (org.olat.ims.qti.editor.beecom.objects.QTIObject)4 Question (org.olat.ims.qti.editor.beecom.objects.Question)4 Attribute (org.dom4j.Attribute)2 Filter (org.olat.core.util.filter.Filter)2 EssayQuestion (org.olat.ims.qti.editor.beecom.objects.EssayQuestion)2 FIBQuestion (org.olat.ims.qti.editor.beecom.objects.FIBQuestion)2 Item (org.olat.ims.qti.editor.beecom.objects.Item)2 OutcomesProcessing (org.olat.ims.qti.editor.beecom.objects.OutcomesProcessing)2 QTIXMLWrapper (org.olat.ims.qti.editor.beecom.objects.QTIXMLWrapper)2 Section (org.olat.ims.qti.editor.beecom.objects.Section)2 SelectionOrdering (org.olat.ims.qti.editor.beecom.objects.SelectionOrdering)2