Search in sources :

Example 21 with Question

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

the class CSVToQuestionConverter method processChoice.

private void processChoice(String[] parts) {
    if (currentItem == null || parts.length < 2) {
        return;
    }
    try {
        Question question = currentItem.getItem().getQuestion();
        int type = question.getType();
        if (type == Question.TYPE_MC || type == Question.TYPE_SC) {
            float point = parseFloat(parts[0], 1.0f);
            String content = parts[1];
            ChoiceQuestion choice = (ChoiceQuestion) question;
            List<Response> choices = choice.getResponses();
            ChoiceResponse newChoice = new ChoiceResponse();
            newChoice.getContent().add(createMattext(content));
            newChoice.setCorrect(point > 0.0f);
            newChoice.setPoints(point);
            choices.add(newChoice);
        } else if (type == Question.TYPE_FIB) {
            String firstPart = parts[0].toLowerCase();
            FIBQuestion fib = (FIBQuestion) question;
            if ("text".equals(firstPart) || "texte".equals(firstPart)) {
                String text = parts[1];
                FIBResponse response = new FIBResponse();
                response.setType(FIBResponse.TYPE_CONTENT);
                Material mat = createMaterialWithText(text);
                response.setContent(mat);
                fib.getResponses().add(response);
            } else {
                float point = parseFloat(parts[0], 1.0f);
                String correctBlank = parts[1];
                FIBResponse response = new FIBResponse();
                response.setType(FIBResponse.TYPE_BLANK);
                response.setCorrectBlank(correctBlank);
                response.setPoints(point);
                if (parts.length > 2) {
                    String sizes = parts[2];
                    String[] sizeArr = sizes.split(",");
                    if (sizeArr.length >= 2) {
                        int size = Integer.parseInt(sizeArr[0]);
                        int maxLength = Integer.parseInt(sizeArr[1]);
                        response.setSize(size);
                        response.setMaxLength(maxLength);
                    }
                }
                fib.getResponses().add(response);
            }
        }
    } catch (NumberFormatException e) {
        log.warn("Cannot parse point for: " + parts[0] + " / " + parts[1], e);
    }
}
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) ChoiceResponse(org.olat.ims.qti.editor.beecom.objects.ChoiceResponse) FIBResponse(org.olat.ims.qti.editor.beecom.objects.FIBResponse) 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) ChoiceQuestion(org.olat.ims.qti.editor.beecom.objects.ChoiceQuestion) Material(org.olat.ims.qti.editor.beecom.objects.Material) FIBQuestion(org.olat.ims.qti.editor.beecom.objects.FIBQuestion)

Example 22 with Question

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

the class QTIEditorMainController method doCopy.

private void doCopy(UserRequest ureq, TreePosition tp) {
    // user chose a position to insert the node to be copied
    int targetPos = tp.getChildpos();
    ItemNode selectedNode = (ItemNode) menuTree.getSelectedNode();
    // only items are moveable
    // use XStream instead of ObjectCloner
    // Item qtiItem =
    // (Item)xstream.fromXML(xstream.toXML(selectedNode.getUnderlyingQTIObject()));
    Item toClone = (Item) selectedNode.getUnderlyingQTIObject();
    Item qtiItem = (Item) XStreamHelper.xstreamClone(toClone);
    // copy flow label class too, olat-2791
    Question orgQuestion = toClone.getQuestion();
    if (orgQuestion instanceof ChoiceQuestion) {
        String flowLabelClass = ((ChoiceQuestion) orgQuestion).getFlowLabelClass();
        Question copyQuestion = qtiItem.getQuestion();
        if (copyQuestion instanceof ChoiceQuestion) {
            ((ChoiceQuestion) copyQuestion).setFlowLabelClass(flowLabelClass);
        } else {
            throw new AssertException("Could not copy flow-label-class, wrong type of copy question , must be 'ChoiceQuestion' but is " + copyQuestion);
        }
    }
    String editorIdentPrefix = "";
    if (qtiItem.getIdent().startsWith(ItemParser.ITEM_PREFIX_SCQ))
        editorIdentPrefix = ItemParser.ITEM_PREFIX_SCQ;
    else if (qtiItem.getIdent().startsWith(ItemParser.ITEM_PREFIX_MCQ))
        editorIdentPrefix = ItemParser.ITEM_PREFIX_MCQ;
    else if (qtiItem.getIdent().startsWith(ItemParser.ITEM_PREFIX_KPRIM))
        editorIdentPrefix = ItemParser.ITEM_PREFIX_KPRIM;
    else if (qtiItem.getIdent().startsWith(ItemParser.ITEM_PREFIX_FIB))
        editorIdentPrefix = ItemParser.ITEM_PREFIX_FIB;
    else if (qtiItem.getIdent().startsWith(ItemParser.ITEM_PREFIX_ESSAY))
        editorIdentPrefix = ItemParser.ITEM_PREFIX_ESSAY;
    // set new ident... this is all it needs for our engine to recognise it
    // as a new item.
    qtiItem.setIdent(editorIdentPrefix + CodeHelper.getForeverUniqueID());
    // insert into menutree (insert on GenericNode do a remove from parent)
    GenericQtiNode parentTargetNode = (GenericQtiNode) tp.getParentTreeNode();
    GenericQtiNode newNode = new ItemNode(qtiItem, qtiPackage);
    parentTargetNode.insert(newNode, targetPos);
    // insert into model
    parentTargetNode.insertQTIObjectAt(qtiItem, targetPos);
    // activate copied node
    menuTree.setSelectedNodeId(newNode.getIdent());
    event(ureq, menuTree, new Event(MenuTree.COMMAND_TREENODE_CLICKED));
    qtiPackage.serializeQTIDocument();
    parentTargetNode.childNodeChanges();
}
Also used : Item(org.olat.ims.qti.editor.beecom.objects.Item) ItemNode(org.olat.ims.qti.editor.tree.ItemNode) AssertException(org.olat.core.logging.AssertException) GenericQtiNode(org.olat.ims.qti.editor.tree.GenericQtiNode) QItemViewEvent(org.olat.modules.qpool.ui.events.QItemViewEvent) Event(org.olat.core.gui.control.Event) 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 23 with Question

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

the class ItemMetadataFormController method formOK.

/**
 * @see org.olat.core.gui.components.form.flexible.impl.FormBasicController#formOK(org.olat.core.gui.UserRequest)
 */
protected void formOK(UserRequest ureq) {
    // Fire Change Event
    String newTitle = title.getValue();
    String oldTitle = item.getTitle();
    boolean hasTitleChange = newTitle != null && !newTitle.equals(oldTitle);
    // trust authors, don't do XSS filtering
    String newObjectives = desc.getRawValue();
    // Remove any conditional comments due to strange behavior in test (OLAT-4518)
    Filter conditionalCommentFilter = FilterFactory.getConditionalHtmlCommentsFilter();
    newObjectives = conditionalCommentFilter.filter(newObjectives);
    String oldObjectives = item.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.setItemIdent(item.getIdent());
        nce.setQuestionIdent(item.getQuestion().getQuestion().getId());
        fireEvent(ureq, nce);
    }
    // Update item
    item.setTitle(newTitle);
    // trust authors, don't to XSS filtering
    item.setObjectives(newObjectives);
    Question q = item.getQuestion();
    if (layout != null && q instanceof ChoiceQuestion) {
        ((ChoiceQuestion) q).setFlowLabelClass("h".equals(layout.getSelectedKey()) ? ChoiceQuestion.BLOCK : ChoiceQuestion.LIST);
    }
    if (!isSurvey && !isRestrictedEditMode) {
        q.setShuffle(shuffle.getSelected() == 0);
        Control itemControl = item.getItemcontrols().get(0);
        itemControl.setFeedback(itemControl.getFeedback() == Control.CTRL_UNDEF ? Control.CTRL_NO : itemControl.getFeedback());
        itemControl.setHint(showHints.getSelected() == 0 ? Control.CTRL_YES : Control.CTRL_NO);
        itemControl.setSolution(showSolution.getSelected() == 0 ? Control.CTRL_YES : Control.CTRL_NO);
        String hintRawValue = hint.getRawValue();
        // trust authors, don't to XSS filtering
        q.setHintText(conditionalCommentFilter.filter(hintRawValue));
        String solutionRawValue = solution.getRawValue();
        // trust authors, don't to XSS filtering
        q.setSolutionText(conditionalCommentFilter.filter(solutionRawValue));
        if (limitTime.getSelectedKey().equals("y")) {
            item.setDuration(new Duration(1000 * timeSec.getIntValue() + 1000 * 60 * timeMin.getIntValue()));
        } else {
            item.setDuration(null);
        }
        if (limitAttempts.getSelectedKey().equals("y")) {
            item.setMaxattempts(attempts.getIntValue());
        } else {
            item.setMaxattempts(0);
        }
    }
    fireEvent(ureq, Event.DONE_EVENT);
}
Also used : WindowControl(org.olat.core.gui.control.WindowControl) Control(org.olat.ims.qti.editor.beecom.objects.Control) Filter(org.olat.core.util.filter.Filter) 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) Duration(org.olat.ims.qti.editor.beecom.objects.Duration)

Example 24 with Question

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

the class ItemNode method createMemento.

public Memento createMemento() {
    Question question = item.getQuestion();
    // special case switches as question types are encoded into integers!!
    boolean isFIB = question.getType() == Question.TYPE_FIB;
    boolean isESSAY = question.getType() == Question.TYPE_ESSAY;
    // Item metadata
    QtiNodeMemento qnm = new QtiNodeMemento();
    Map<String, Object> qtiState = new HashMap<>();
    qtiState.put("ID", item.getIdent());
    qtiState.put("TITLE", item.getTitle());
    qtiState.put("OBJECTIVES", item.getObjectives());
    // question and responses
    qtiState.put("QUESTION.ID", question.getIdent());
    qtiState.put("QUESTION.HINTTEXT", question.getHintText());
    Material questMaterial = question.getQuestion();
    qtiState.put("QUESTION.MATERIAL.ASTEXT", questMaterial.renderAsText());
    List<String> ids = new ArrayList<String>();
    List<String> asTexts = new ArrayList<String>();
    List<String> feedbacks = new ArrayList<String>();
    List<Response> responses = question.getResponses();
    for (Iterator<Response> iter = responses.iterator(); iter.hasNext(); ) {
        Response resp = iter.next();
        if (isFIB) {
            if (FIBResponse.TYPE_BLANK.equals(((FIBResponse) resp).getType())) {
                asTexts.add(formatFIBResponseAsText((FIBResponse) resp));
                ids.add(resp.getIdent());
                feedbacks.add(QTIEditHelper.getFeedbackOlatRespText(item, resp.getIdent()));
            }
        } else if (isESSAY) {
            asTexts.add(formatESSAYResponseAsText((EssayResponse) resp));
            ids.add(resp.getIdent());
            feedbacks.add(QTIEditHelper.getFeedbackOlatRespText(item, resp.getIdent()));
        } else {
            // not a FIB or ESSAY response
            asTexts.add(resp.getContent().renderAsText());
            ids.add(resp.getIdent());
            feedbacks.add(QTIEditHelper.getFeedbackOlatRespText(item, resp.getIdent()));
        }
    }
    qtiState.put("QUESTION.RESPONSES.IDS", ids);
    qtiState.put("QUESTION.RESPONSES.ASTEXT", asTexts);
    qtiState.put("QUESTION.RESPONSES.FEEDBACK", feedbacks);
    // feedback
    qtiState.put("FEEDBACK.MASTERY", QTIEditHelper.getFeedbackMasteryText(item));
    qtiState.put("FEEDBACK.FAIL", QTIEditHelper.getFeedbackFailText(item));
    Control control = QTIEditHelper.getControl(item);
    qtiState.put("FEEDBACK.ENABLED", control.getFeedback() == 1 ? Boolean.TRUE : Boolean.FALSE);
    // 
    qnm.setQtiState(qtiState);
    // 
    return qnm;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Material(org.olat.ims.qti.editor.beecom.objects.Material) 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) Question(org.olat.ims.qti.editor.beecom.objects.Question) QTIObject(org.olat.ims.qti.editor.beecom.objects.QTIObject)

Example 25 with Question

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

the class QTI12MetadataController method initForm.

@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
    Question question = item.getQuestion();
    FormLayoutContainer layoutCont = (FormLayoutContainer) formLayout;
    if (question != null) {
        layoutCont.contextPut("hasQuestion", Boolean.TRUE);
        // settings
        String shuffleStr = translate(question.isShuffle() ? "editor.true" : "editor.false");
        uifactory.addStaticTextElement("form.imd.shuffle", shuffleStr, formLayout);
        String duration = "";
        if (item.getDuration() != null) {
            duration = item.getDuration().getMin() + ":" + item.getDuration().getSec();
        }
        uifactory.addStaticTextElement("form.metadata.duration", duration, formLayout);
        if (question instanceof ChoiceQuestion) {
            ChoiceQuestion choice = (ChoiceQuestion) question;
            if (item.getQuestion().getType() == Question.TYPE_SC) {
                String score = Float.toString(question.getSingleCorrectScore());
                uifactory.addStaticTextElement("score", score, formLayout);
            } else if (item.getQuestion().getType() == Question.TYPE_MC) {
                String minVal = Float.toString(choice.getMinValue());
                String maxVal = Float.toString(choice.getMaxValue());
                uifactory.addStaticTextElement("score.min", minVal, formLayout);
                uifactory.addStaticTextElement("score.max", maxVal, formLayout);
            }
        }
        // correct responses
        List<Response> responses = question.getResponses();
        if (question.getType() == Question.TYPE_MC || question.getType() == Question.TYPE_SC) {
            setMCAndSCCorrectResponses(question, responses, layoutCont);
        } else if (question.getType() == Question.TYPE_KPRIM) {
            setKPrimCorrectResponses(responses, layoutCont);
        }
    }
    // feedbacks
    boolean hasFeedbacks = false;
    Material masteryMat = QTIEditHelper.getFeedbackMasteryMaterial(item);
    if (masteryMat != null) {
        layoutCont.contextPut("item_feedback_mastery", masteryMat.renderAsText());
        hasFeedbacks = true;
    }
    Material failureMat = QTIEditHelper.getFeedbackFailMaterial(item);
    if (failureMat != null) {
        layoutCont.contextPut("item_feedback_fail", failureMat.renderAsText());
        hasFeedbacks = true;
    }
    List<String> responsesFeedback = new ArrayList<>();
    if (question != null && question.getType() <= Question.TYPE_MC) {
        for (Object obj : question.getResponses()) {
            ChoiceResponse response = (ChoiceResponse) obj;
            Material responseFeedbackMat = QTIEditHelper.getFeedbackOlatRespMaterial(item, response.getIdent());
            if (responseFeedbackMat != null) {
                responsesFeedback.add(responseFeedbackMat.renderAsText());
            }
        }
        hasFeedbacks |= responsesFeedback.size() > 0;
    }
    layoutCont.contextPut("responsesFeedback", responsesFeedback);
    layoutCont.contextPut("hasFeedbacks", new Boolean(hasFeedbacks));
}
Also used : ArrayList(java.util.ArrayList) FormLayoutContainer(org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer) Material(org.olat.ims.qti.editor.beecom.objects.Material) ChoiceResponse(org.olat.ims.qti.editor.beecom.objects.ChoiceResponse) Response(org.olat.ims.qti.editor.beecom.objects.Response) ChoiceResponse(org.olat.ims.qti.editor.beecom.objects.ChoiceResponse) 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)

Aggregations

Question (org.olat.ims.qti.editor.beecom.objects.Question)36 ChoiceQuestion (org.olat.ims.qti.editor.beecom.objects.ChoiceQuestion)32 Response (org.olat.ims.qti.editor.beecom.objects.Response)22 FIBResponse (org.olat.ims.qti.editor.beecom.objects.FIBResponse)18 EssayQuestion (org.olat.ims.qti.editor.beecom.objects.EssayQuestion)16 ChoiceResponse (org.olat.ims.qti.editor.beecom.objects.ChoiceResponse)14 EssayResponse (org.olat.ims.qti.editor.beecom.objects.EssayResponse)14 ArrayList (java.util.ArrayList)12 Material (org.olat.ims.qti.editor.beecom.objects.Material)12 HashMap (java.util.HashMap)10 Control (org.olat.ims.qti.editor.beecom.objects.Control)10 FIBQuestion (org.olat.ims.qti.editor.beecom.objects.FIBQuestion)10 WindowControl (org.olat.core.gui.control.WindowControl)8 Item (org.olat.ims.qti.editor.beecom.objects.Item)8 QTIObject (org.olat.ims.qti.editor.beecom.objects.QTIObject)8 List (java.util.List)4 Element (org.dom4j.Element)4 Duration (org.olat.ims.qti.editor.beecom.objects.Duration)4 ItemNode (org.olat.ims.qti.editor.tree.ItemNode)4 ModalFeedbackBuilder (org.olat.ims.qti21.model.xml.ModalFeedbackBuilder)4