Search in sources :

Example 11 with ChoiceQuestion

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

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

the class QTIEditHelper method createSCItem.

/**
 * Creates a new Single Choice item
 * @param trans
 * @return New Singe Choice item.
 */
public static Item createSCItem(Translator trans) {
    Item newItem = new Item();
    newItem.setIdent(EDITOR_IDENT + ":" + ITEM_TYPE_SC + ":" + 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);
    // pepare question
    ChoiceQuestion question = new ChoiceQuestion();
    question.setLable(trans.translate("editor.newquestion"));
    question.getQuestion().getElements().add(new Mattext(trans.translate("editor.newquestiontext")));
    question.setType(Question.TYPE_SC);
    question.setSingleCorrect(true);
    question.setSingleCorrectScore(1);
    ChoiceResponse newChoice = new ChoiceResponse();
    newChoice.setCorrect(true);
    newChoice.getContent().add(new Mattext(trans.translate("editor.newresponsetext")));
    question.getResponses().add(newChoice);
    QTIEditHelper.setFeedbackMastery(newItem, "");
    QTIEditHelper.setFeedbackFail(newItem, "");
    newItem.setQuestion(question);
    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)

Example 13 with ChoiceQuestion

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

the class QTIEditHelper method createMCItem.

/**
 * Creates a new Multiple Choice item.
 * @param trans
 * @return New Multiple Choice item.
 */
public static Item createMCItem(Translator trans) {
    // create item
    Item newItem = new Item();
    newItem.setIdent(EDITOR_IDENT + ":" + ITEM_TYPE_MC + ":" + String.valueOf(CodeHelper.getRAMUniqueID()));
    newItem.setTitle(trans.translate("editor.newquestion"));
    newItem.setLabel("");
    // conrols
    Control control = new Control();
    List<Control> controls = new ArrayList<Control>();
    controls.add(control);
    newItem.setItemcontrols(controls);
    // pepare question
    ChoiceQuestion question = new ChoiceQuestion();
    question.setLable(trans.translate("editor.newquestion"));
    question.getQuestion().getElements().add(new Mattext(trans.translate("editor.newquestiontext")));
    question.setType(Question.TYPE_MC);
    question.setSingleCorrect(true);
    question.setSingleCorrectScore(1);
    ChoiceResponse newChoice = new ChoiceResponse();
    newChoice.getContent().add(new Mattext(trans.translate("editor.newresponsetext")));
    newChoice.setCorrect(true);
    newChoice.setPoints(1);
    question.getResponses().add(newChoice);
    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)

Example 14 with ChoiceQuestion

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

the class ChoiceItemController 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)
 */
@Override
public void event(UserRequest ureq, Component source, Event event) {
    if (source == main) {
        // olat::: as: improve easy fix since almost all operations change the main vc.
        main.setDirty(true);
        String cmd = event.getCommand();
        String sPosid = ureq.getParameter("posid");
        int posid = 0;
        if (sPosid != null)
            posid = Integer.parseInt(sPosid);
        if (cmd == null) {
        // ignore null cmd
        } else if (cmd.equals("up")) {
            if (posid > 0) {
                List<Response> elements = item.getQuestion().getResponses();
                Response obj = elements.remove(posid);
                elements.add(posid - 1, obj);
            }
        } else if (cmd.equals("down")) {
            List<Response> elements = item.getQuestion().getResponses();
            if (posid < elements.size() - 1) {
                Response obj = elements.remove(posid);
                elements.add(posid + 1, obj);
            }
        } else if (cmd.equals("editq")) {
            editQuestion = item.getQuestion().getQuestion();
            displayMaterialFormController(ureq, editQuestion, restrictedEdit, translate("fieldset.legend.question"));
        } else if (cmd.equals("editr")) {
            List<Response> elements = item.getQuestion().getResponses();
            if (posid >= 0 && posid < elements.size()) {
                editResponse = elements.get(posid);
                Material responseMat = editResponse.getContent();
                displayMaterialFormController(ureq, responseMat, restrictedEdit, translate("fieldset.legend.answers"));
            }
        } else if (cmd.equals("addchoice")) {
            ChoiceQuestion question = (ChoiceQuestion) item.getQuestion();
            List<Response> choices = question.getResponses();
            ChoiceResponse newChoice = new ChoiceResponse();
            newChoice.getContent().add(new Mattext(translate("newresponsetext")));
            newChoice.setCorrect(false);
            // default value is negative to make sure
            newChoice.setPoints(-1f);
            // people understand the meaning of this value
            choices.add(newChoice);
        } else if (cmd.equals("del")) {
            delYesNoCtrl = DialogBoxUIFactory.createYesNoDialog(ureq, getWindowControl(), null, translate("confirm.delete.element"));
            listenTo(delYesNoCtrl);
            delYesNoCtrl.setUserObject(new Integer(posid));
            delYesNoCtrl.activate();
        } else if (cmd.equals("ssc")) {
            // submit sc
            if (!restrictedEdit) {
                ChoiceQuestion question = (ChoiceQuestion) item.getQuestion();
                List<Response> q_choices = question.getResponses();
                String correctChoice = ureq.getParameter("correctChoice");
                for (int i = 0; i < q_choices.size(); i++) {
                    ChoiceResponse choice = (ChoiceResponse) q_choices.get(i);
                    if (correctChoice != null && correctChoice.equals("value_q" + i)) {
                        choice.setCorrect(true);
                    } else {
                        choice.setCorrect(false);
                    }
                    choice.setPoints(ureq.getParameter("points_q" + i));
                }
                String score = ureq.getParameter("single_score");
                float sc;
                try {
                    sc = Float.parseFloat(score);
                    if (sc <= 0.0001f) {
                        getWindowControl().setWarning(translate("editor.info.mc.zero.points"));
                    }
                } catch (Exception e) {
                    getWindowControl().setWarning(translate("editor.info.mc.zero.points"));
                    sc = 1.0f;
                }
                question.setSingleCorrectScore(sc);
            }
        } else if (cmd.equals("smc")) {
            // submit mc
            if (!restrictedEdit) {
                ChoiceQuestion question = (ChoiceQuestion) item.getQuestion();
                List<Response> choices = question.getResponses();
                boolean hasZeroPointChoice = false;
                for (int i = 0; i < choices.size(); i++) {
                    ChoiceResponse choice = (ChoiceResponse) choices.get(i);
                    if (ureq.getParameter("value_q" + i) != null && ureq.getParameter("value_q" + i).equalsIgnoreCase("true")) {
                        choice.setCorrect(true);
                    } else {
                        choice.setCorrect(false);
                    }
                    choice.setPoints(ureq.getParameter("points_q" + i));
                    if (choice.getPoints() == 0)
                        hasZeroPointChoice = true;
                }
                if (hasZeroPointChoice && !question.isSingleCorrect()) {
                    getWindowControl().setInfo(translate("editor.info.mc.zero.points"));
                }
                // set min/max before single_correct score
                // will be corrected by single_correct score afterwards
                question.setMinValue(ureq.getParameter("min_value"));
                question.setMaxValue(ureq.getParameter("max_value"));
                question.setSingleCorrect(ureq.getParameter("valuation_method").equals("single"));
                if (question.isSingleCorrect()) {
                    question.setSingleCorrectScore(ureq.getParameter("single_score"));
                } else {
                    question.setSingleCorrectScore(0);
                }
            }
        } else if (cmd.equals("skprim")) {
            // submit kprim
            if (!restrictedEdit) {
                float maxValue = 0;
                try {
                    maxValue = Float.parseFloat(ureq.getParameter("max_value"));
                } catch (NumberFormatException e) {
                // invalid input, set maxValue 0
                }
                ChoiceQuestion question = (ChoiceQuestion) item.getQuestion();
                List<Response> q_choices = question.getResponses();
                for (int i = 0; i < q_choices.size(); i++) {
                    String correctChoice = ureq.getParameter("correctChoice_q" + i);
                    ChoiceResponse choice = (ChoiceResponse) q_choices.get(i);
                    choice.setPoints(maxValue / 4);
                    if ("correct".equals(correctChoice)) {
                        choice.setCorrect(true);
                    } else {
                        choice.setCorrect(false);
                    }
                }
                question.setMaxValue(maxValue);
            }
        }
        qtiPackage.serializeQTIDocument();
    }
}
Also used : 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) Mattext(org.olat.ims.qti.editor.beecom.objects.Mattext) List(java.util.List) ChoiceQuestion(org.olat.ims.qti.editor.beecom.objects.ChoiceQuestion)

Example 15 with ChoiceQuestion

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

Aggregations

ChoiceQuestion (org.olat.ims.qti.editor.beecom.objects.ChoiceQuestion)24 ChoiceResponse (org.olat.ims.qti.editor.beecom.objects.ChoiceResponse)14 Question (org.olat.ims.qti.editor.beecom.objects.Question)14 Item (org.olat.ims.qti.editor.beecom.objects.Item)12 Response (org.olat.ims.qti.editor.beecom.objects.Response)12 Control (org.olat.ims.qti.editor.beecom.objects.Control)10 Mattext (org.olat.ims.qti.editor.beecom.objects.Mattext)10 ArrayList (java.util.ArrayList)8 FIBResponse (org.olat.ims.qti.editor.beecom.objects.FIBResponse)8 Material (org.olat.ims.qti.editor.beecom.objects.Material)8 VFSItem (org.olat.core.util.vfs.VFSItem)6 HashMap (java.util.HashMap)4 WindowControl (org.olat.core.gui.control.WindowControl)4 EssayQuestion (org.olat.ims.qti.editor.beecom.objects.EssayQuestion)4 FIBQuestion (org.olat.ims.qti.editor.beecom.objects.FIBQuestion)4 File (java.io.File)2 URL (java.net.URL)2 List (java.util.List)2 HttpServletResponse (javax.servlet.http.HttpServletResponse)2 Element (org.dom4j.Element)2