Search in sources :

Example 1 with Material

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

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

the class QTIEditHelper method fetchChoices.

/**
 * Fetch choices.
 * @param response_labels
 * @return Map of choices.
 */
public static List<Response> fetchChoices(List response_labels) {
    List<Response> choices = new ArrayList<Response>();
    for (Iterator i = response_labels.iterator(); i.hasNext(); ) {
        ChoiceResponse choice = new ChoiceResponse();
        Element response_label = (Element) i.next();
        choice.setIdent(response_label.attributeValue("ident"));
        List materials = response_label.selectNodes(".//material");
        Material content = new Material();
        for (Iterator iter = materials.iterator(); iter.hasNext(); ) {
            Element el_material = (Element) iter.next();
            Material mat = (Material) parserManager.parse(el_material);
            content.getElements().addAll(mat.getElements());
        }
        // assure material always has some content
        if (content.getElements().size() == 0) {
            content.getElements().add(new Mattext(""));
        }
        choice.setContent(content);
        choices.add(choice);
    }
    return choices;
}
Also used : ChoiceResponse(org.olat.ims.qti.editor.beecom.objects.ChoiceResponse) 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) ChoiceResponse(org.olat.ims.qti.editor.beecom.objects.ChoiceResponse) Mattext(org.olat.ims.qti.editor.beecom.objects.Mattext) Element(org.dom4j.Element) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) Material(org.olat.ims.qti.editor.beecom.objects.Material)

Example 3 with Material

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

the class QTIEditHelper method getFeedbackMaterial.

/**
 * @param object
 * @param sIdent
 * @return
 */
public static Material getFeedbackMaterial(QTIObject object, String sIdent) {
    Feedback feedback = getFeedback(object, sIdent);
    Material mat = null;
    try {
        mat = (Material) feedback.getMaterials().get(0);
    } catch (NullPointerException e) {
    // feedback is null
    }
    return mat;
}
Also used : Feedback(org.olat.ims.qti.editor.beecom.objects.Feedback) Material(org.olat.ims.qti.editor.beecom.objects.Material)

Example 4 with Material

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

the class QTIEditHelper method getMediaReferences.

/**
 * Retrieves all referenced media by thisItem if filterOut is false,
 * or all referenced media by other items if filterOut is true.
 * <p>
 * Iterates over all sections, items, etc. </br>
 * -> if filterOut is true gets all references except those for thisItem.
 * -> if filterOut is false gets all references for thisItem.
 *
 * @param qtiDocument
 * @param thisItem
 * @param filterOut
 * @return Returns empty set if no reference found.
 */
private static Set<String> getMediaReferences(QTIDocument qtiDocument, Item thisItem, boolean filterOut) {
    HashSet<String> returnSet = new HashSet<String>();
    // sections
    List sectionList = qtiDocument.getAssessment().getSections();
    Iterator sectionIterator = sectionList.iterator();
    while (sectionIterator.hasNext()) {
        // section
        Section section = (Section) sectionIterator.next();
        List itemList = section.getItems();
        Iterator listIterator = itemList.iterator();
        while (listIterator.hasNext()) {
            // item
            Item item = (Item) listIterator.next();
            if ((filterOut && thisItem.getIdent().equals(item.getIdent())) || (!filterOut && !thisItem.getIdent().equals(item.getIdent()))) {
                continue;
            }
            // question
            Material material = item.getQuestion().getQuestion();
            if (material != null) {
                String htmlContent = material.renderAsHtmlForEditor();
                // parse filenames
                returnSet.addAll(getMediaFileNames(htmlContent));
            }
            // responses
            List responseList = item.getQuestion().getResponses();
            Iterator responseIterator = responseList.iterator();
            while (responseIterator.hasNext()) {
                Response response = (Response) responseIterator.next();
                Material responseMat = response.getContent();
                // parse filenames
                if (responseMat != null) {
                    returnSet.addAll(getMediaFileNames(responseMat.renderAsHtmlForEditor()));
                }
                // response-level feedback
                Material responseFeedbackMat = QTIEditHelper.getFeedbackOlatRespMaterial(item, response.getIdent());
                if (responseFeedbackMat != null) {
                    returnSet.addAll(getMediaFileNames(responseFeedbackMat.renderAsHtmlForEditor()));
                }
            }
            // feedback
            Material masteryMat = QTIEditHelper.getFeedbackMasteryMaterial(item);
            if (masteryMat != null) {
                returnSet.addAll(getMediaFileNames(masteryMat.renderAsHtmlForEditor()));
            }
            Material failureMat = QTIEditHelper.getFeedbackFailMaterial(item);
            if (failureMat != null) {
                returnSet.addAll(getMediaFileNames(failureMat.renderAsHtmlForEditor()));
            }
        }
    }
    return returnSet;
}
Also used : ChoiceResponse(org.olat.ims.qti.editor.beecom.objects.ChoiceResponse) 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) Item(org.olat.ims.qti.editor.beecom.objects.Item) VFSItem(org.olat.core.util.vfs.VFSItem) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) Material(org.olat.ims.qti.editor.beecom.objects.Material) Section(org.olat.ims.qti.editor.beecom.objects.Section) HashSet(java.util.HashSet)

Example 5 with Material

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

Material (org.olat.ims.qti.editor.beecom.objects.Material)36 ArrayList (java.util.ArrayList)20 Response (org.olat.ims.qti.editor.beecom.objects.Response)20 FIBResponse (org.olat.ims.qti.editor.beecom.objects.FIBResponse)18 ChoiceResponse (org.olat.ims.qti.editor.beecom.objects.ChoiceResponse)16 Mattext (org.olat.ims.qti.editor.beecom.objects.Mattext)16 ChoiceQuestion (org.olat.ims.qti.editor.beecom.objects.ChoiceQuestion)14 List (java.util.List)12 EssayResponse (org.olat.ims.qti.editor.beecom.objects.EssayResponse)12 Question (org.olat.ims.qti.editor.beecom.objects.Question)12 QTIObject (org.olat.ims.qti.editor.beecom.objects.QTIObject)10 FIBQuestion (org.olat.ims.qti.editor.beecom.objects.FIBQuestion)8 Item (org.olat.ims.qti.editor.beecom.objects.Item)8 Iterator (java.util.Iterator)6 VFSItem (org.olat.core.util.vfs.VFSItem)6 Control (org.olat.ims.qti.editor.beecom.objects.Control)6 EssayQuestion (org.olat.ims.qti.editor.beecom.objects.EssayQuestion)6 Element (org.dom4j.Element)4 FormLayoutContainer (org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer)4 Feedback (org.olat.ims.qti.editor.beecom.objects.Feedback)4