Search in sources :

Example 1 with Control

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

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

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

the class ControlParser method parse.

/**
 * @see org.olat.ims.qti.editor.beecom.IParser#parse(org.dom4j.Element)
 */
public Object parse(Element element) {
    // assert element.getName().equalsIgnoreCase("assessmentcontrol")
    // || element.getName().equalsIgnoreCase("sectioncontrol")
    // || element.getName().equalsIgnoreCase("itemcontrol");
    Control control = null;
    // attributes
    String feedbackswitch = element.attribute("feedbackswitch").getValue();
    String hintswitch = element.attribute("hintswitch").getValue();
    String solutionswitch = element.attribute("solutionswitch").getValue();
    control = new Control(feedbackswitch, hintswitch, solutionswitch);
    return control;
}
Also used : Control(org.olat.ims.qti.editor.beecom.objects.Control)

Example 3 with Control

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

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

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

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

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