Search in sources :

Example 1 with QTIObject

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

the class CSVToQuestionConverter method processQuestion.

private void processQuestion(String[] parts) {
    if (currentItem == null)
        return;
    Question question = currentItem.getItem().getQuestion();
    Material mat = question.getQuestion();
    String content = parts[1];
    Mattext matText = new Mattext(content);
    List<QTIObject> elements = new ArrayList<QTIObject>(1);
    elements.add(matText);
    mat.setElements(elements);
}
Also used : Mattext(org.olat.ims.qti.editor.beecom.objects.Mattext) QTIObject(org.olat.ims.qti.editor.beecom.objects.QTIObject) ArrayList(java.util.ArrayList) 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) Material(org.olat.ims.qti.editor.beecom.objects.Material)

Example 2 with QTIObject

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

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

the class QTIEditorMainController method doMove.

private void doMove(TreePosition tp) {
    // user chose a position to insert a new node
    GenericQtiNode parentTargetNode = (GenericQtiNode) tp.getParentTreeNode();
    int targetPos = tp.getChildpos();
    GenericQtiNode selectedNode = (GenericQtiNode) menuTree.getSelectedNode();
    int selectedPos = selectedNode.getPosition();
    GenericQtiNode parentSelectedNode = (GenericQtiNode) selectedNode.getParent();
    if (parentTargetNode == parentSelectedNode) {
        // if we're on the same subnode
        if (targetPos > selectedNode.getPosition()) {
            // if we're moving after our current position
            targetPos--;
        // decrease insert pos since we're going to be removed from the
        // parent before re-insert
        }
    }
    // insert into menutree (insert on GenericNode do a remove from parent)
    parentTargetNode.insert(selectedNode, targetPos);
    // insert into model (remove from parent needed prior to insert)
    QTIObject subject = parentSelectedNode.removeQTIObjectAt(selectedPos);
    parentTargetNode.insertQTIObjectAt(subject, targetPos);
    qtiPackage.serializeQTIDocument();
    parentSelectedNode.childNodeChanges();
    parentTargetNode.childNodeChanges();
}
Also used : QTIObject(org.olat.ims.qti.editor.beecom.objects.QTIObject) GenericQtiNode(org.olat.ims.qti.editor.tree.GenericQtiNode)

Example 4 with QTIObject

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

the class QTIEditorMainController method doExportQItem.

private void doExportQItem() {
    GenericQtiNode selectedNode = menuTreeModel.getQtiNode(menuTree.getSelectedNodeId());
    if (selectedNode instanceof ItemNode) {
        ItemNode itemNode = (ItemNode) selectedNode;
        QTIObject qtiObject = itemNode.getUnderlyingQTIObject();
        if (qtiObject instanceof Item) {
            ItemAndMetadata item = new ItemAndMetadata((Item) qtiObject);
            VFSContainer editorContainer = qtiPackage.getBaseDir();
            qtiQpoolServiceProvider.importBeecomItem(getIdentity(), item, editorContainer, getLocale());
            showInfo("export.qpool.successful", "1");
        }
    } else if (selectedNode instanceof SectionNode) {
        SectionNode sectionNode = (SectionNode) selectedNode;
        QTIObject qtiObject = sectionNode.getUnderlyingQTIObject();
        if (qtiObject instanceof Section) {
            int count = doExportSection((Section) qtiObject);
            showInfo("export.qpool.successful", Integer.toString(count));
        }
    } else if (selectedNode instanceof AssessmentNode) {
        AssessmentNode assessmentNode = (AssessmentNode) selectedNode;
        QTIObject qtiObject = assessmentNode.getUnderlyingQTIObject();
        if (qtiObject instanceof Assessment) {
            int count = doExportAssessment((Assessment) qtiObject);
            showInfo("export.qpool.successful", Integer.toString(count));
        }
    }
}
Also used : Item(org.olat.ims.qti.editor.beecom.objects.Item) ItemNode(org.olat.ims.qti.editor.tree.ItemNode) QTIObject(org.olat.ims.qti.editor.beecom.objects.QTIObject) AssessmentNode(org.olat.ims.qti.editor.tree.AssessmentNode) GenericQtiNode(org.olat.ims.qti.editor.tree.GenericQtiNode) VFSContainer(org.olat.core.util.vfs.VFSContainer) Assessment(org.olat.ims.qti.editor.beecom.objects.Assessment) ItemAndMetadata(org.olat.ims.qti.questionimport.ItemAndMetadata) SectionNode(org.olat.ims.qti.editor.tree.SectionNode) Section(org.olat.ims.qti.editor.beecom.objects.Section)

Example 5 with QTIObject

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

the class QTIEditHelper method setFeedback.

/**
 * Set feedback
 * @param object
 * @param feedbackString
 * @param sIdent
 */
public static void setFeedback(QTIObject object, String feedbackString, String sIdent) {
    List<Feedback> feedbacks = getFeedbacks(object);
    Feedback feedback = getFeedback(sIdent, feedbacks);
    if (feedbackString == null || feedbackString.trim().length() == 0) {
        feedbacks.remove(feedback);
        return;
    }
    if (feedback != null) {
        feedbackString = feedbackString.trim();
        List matList = feedback.getMaterials();
        if (matList.size() > 0) {
            Material mat = (Material) feedback.getMaterials().get(0);
            if (mat == null) {
                mat = new Material();
                mat.getElements().add(new Mattext(feedbackString));
                feedback.getMaterials().add(mat);
            } else if (mat.getElements().size() > 0) {
                mat.getElements().set(0, new Mattext(feedbackString));
            } else {
                mat.getElements().add(new Mattext(feedbackString));
            }
        } else {
            Material mat = new Material();
            mat.getElements().add(new Mattext(feedbackString));
            feedback.getMaterials().add(mat);
        }
    } else {
        Feedback newFeedback = new Feedback();
        newFeedback.setIdent(sIdent);
        newFeedback.setView("All");
        Mattext newMattext = new Mattext(feedbackString);
        List<QTIObject> newMattextL = new ArrayList<>();
        newMattextL.add(newMattext);
        Material material = new Material();
        material.setElements(newMattextL);
        List<Material> newMaterialL = new ArrayList<>();
        newMaterialL.add(material);
        newFeedback.setMaterials(newMaterialL);
        feedbacks.add(newFeedback);
    }
}
Also used : Mattext(org.olat.ims.qti.editor.beecom.objects.Mattext) QTIObject(org.olat.ims.qti.editor.beecom.objects.QTIObject) Feedback(org.olat.ims.qti.editor.beecom.objects.Feedback) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Material(org.olat.ims.qti.editor.beecom.objects.Material)

Aggregations

QTIObject (org.olat.ims.qti.editor.beecom.objects.QTIObject)22 ArrayList (java.util.ArrayList)12 List (java.util.List)10 Element (org.dom4j.Element)10 Iterator (java.util.Iterator)8 Material (org.olat.ims.qti.editor.beecom.objects.Material)8 Mattext (org.olat.ims.qti.editor.beecom.objects.Mattext)8 Attribute (org.dom4j.Attribute)6 ChoiceQuestion (org.olat.ims.qti.editor.beecom.objects.ChoiceQuestion)6 Control (org.olat.ims.qti.editor.beecom.objects.Control)6 Item (org.olat.ims.qti.editor.beecom.objects.Item)6 Assessment (org.olat.ims.qti.editor.beecom.objects.Assessment)4 Duration (org.olat.ims.qti.editor.beecom.objects.Duration)4 FIBQuestion (org.olat.ims.qti.editor.beecom.objects.FIBQuestion)4 Question (org.olat.ims.qti.editor.beecom.objects.Question)4 Section (org.olat.ims.qti.editor.beecom.objects.Section)4 SelectionOrdering (org.olat.ims.qti.editor.beecom.objects.SelectionOrdering)4 GenericQtiNode (org.olat.ims.qti.editor.tree.GenericQtiNode)4 File (java.io.File)2 URL (java.net.URL)2