Search in sources :

Example 16 with ItemContext

use of org.olat.ims.qti.container.ItemContext in project OpenOLAT by OpenOLAT.

the class DefaultNavigator method submitAssessment.

/**
 * @see org.olat.qti.process.Navigator#submitAssessment()
 */
public final void submitAssessment() {
    Output pendingOutput = null;
    boolean pendingFeedback = getInfo().isFeedback();
    boolean alreadyClosed = getAssessmentInstance().isClosed();
    if (pendingFeedback && getAssessmentInstance().getAssessmentContext().getCurrentSectionContext() != null) {
        ItemContext itc = getAssessmentInstance().getAssessmentContext().getCurrentSectionContext().getCurrentItemContext();
        pendingOutput = itc.getOutput();
    }
    getAssessmentInstance().stop();
    if (!getAssessmentInstance().isPreview() && !alreadyClosed) {
        CoreSpringFactory.getImpl(IQManager.class).persistResults(getAssessmentInstance());
    }
    AssessmentContext ac = getAssessmentContext();
    info.clear();
    if (ac.isFeedbackavailable()) {
        Output outp = ac.getOutput();
        getInfo().setCurrentOutput(outp);
        getInfo().setFeedback(true);
    } else if (pendingFeedback) {
        getInfo().setCurrentOutput(pendingOutput);
        getInfo().setFeedback(true);
    }
    // info.clear();
    info.setMessage(QTIConstants.MESSAGE_ASSESSMENT_SUBMITTED);
    info.setStatus(QTIConstants.ASSESSMENT_FINISHED);
    info.setRenderItems(false);
    if (delegate != null && !getAssessmentInstance().isPreview() && !alreadyClosed) {
        delegate.submitAssessment(assessmentInstance);
    }
    getAssessmentInstance().cleanUp();
}
Also used : ItemContext(org.olat.ims.qti.container.ItemContext) IQManager(org.olat.modules.iq.IQManager) AssessmentContext(org.olat.ims.qti.container.AssessmentContext) Output(org.olat.ims.qti.container.Output)

Example 17 with ItemContext

use of org.olat.ims.qti.container.ItemContext in project OpenOLAT by OpenOLAT.

the class MenuSectionNavigator method startSection.

private void startSection(SectionContext sc) {
    sc.start();
    for (int i = 0; i < sc.getItemContextCount(); i++) {
        ItemContext itc = sc.getItemContext(i);
        itc.start();
    }
}
Also used : ItemContext(org.olat.ims.qti.container.ItemContext)

Example 18 with ItemContext

use of org.olat.ims.qti.container.ItemContext in project OpenOLAT by OpenOLAT.

the class IQComponentRenderer method buildForm.

/**
 * Render the QTI form
 * @param comp
 * @param translator
 * @param renderer
 * @return rendered form
 */
public StringOutput buildForm(IQComponent comp, Translator translator, Renderer renderer, URLBuilder ubu) {
    StringOutput sb = new StringOutput();
    Info info = comp.getAssessmentInstance().getNavigator().getInfo();
    AssessmentInstance ai = comp.getAssessmentInstance();
    int status = info.getStatus();
    int message = info.getMessage();
    boolean renderItems = info.isRenderItems();
    AssessmentContext act = ai.getAssessmentContext();
    // first treat messages and errors
    if (info.containsMessage()) {
        switch(message) {
            case QTIConstants.MESSAGE_ITEM_SUBMITTED:
                // item hints?
                if (info.isHint()) {
                    Hint el_hint = info.getCurrentOutput().getHint();
                    if (el_hint.getFeedbackstyle() == Hint.FEEDBACKSTYLE_INCREMENTAL) {
                        // increase the hint level so we know which hint to display
                        ItemContext itc = act.getCurrentSectionContext().getCurrentItemContext();
                        int nLevel = itc.getHintLevel() + 1;
                        int numofhints = el_hint.getChildCount();
                        if (nLevel > numofhints)
                            nLevel = numofhints;
                        itc.setHintLevel(nLevel);
                        // <!ELEMENT hint (qticomment? , hintmaterial+)>
                        displayFeedback(sb, (GenericQTIElement) el_hint.getChildAt(nLevel - 1), ai, translator.getLocale());
                    } else {
                        displayFeedback(sb, el_hint, ai, translator.getLocale());
                    }
                }
                // item solution?
                if (info.isSolution()) {
                    Solution el_solution = info.getCurrentOutput().getSolution();
                    displayFeedback(sb, el_solution, ai, translator.getLocale());
                }
                // item fb?
                renderFeedback(info, sb, ai, translator);
                if (!comp.getMenuDisplayConf().isEnabledMenu() && comp.getMenuDisplayConf().isItemPageSequence() && !info.isRenderItems()) {
                    // if item was submitted and sequence is pageSequence and menu not enabled and isRenderItems returns false show section info
                    SectionContext sc = ai.getAssessmentContext().getCurrentSectionContext();
                    displaySectionInfo(sb, sc, ai, comp, ubu, translator);
                }
                break;
            case QTIConstants.MESSAGE_SECTION_SUBMITTED:
                // SectionContext sc = act.getCurrentSectionContext();
                if (info.isFeedback()) {
                    Output outp = info.getCurrentOutput();
                    GenericQTIElement el_feedback = outp.getEl_response();
                    if (el_feedback != null) {
                        displayFeedback(sb, el_feedback, ai, translator.getLocale());
                    } else {
                        renderFeedback(info, sb, ai, translator);
                    }
                }
                if (!comp.getMenuDisplayConf().isEnabledMenu() && !comp.getMenuDisplayConf().isItemPageSequence()) {
                    SectionContext sc = ai.getAssessmentContext().getCurrentSectionContext();
                    displaySectionInfo(sb, sc, ai, comp, ubu, translator);
                }
                break;
            case QTIConstants.MESSAGE_ASSESSMENT_SUBMITTED:
                // provide assessment feedback if enabled and existing
                if (info.isFeedback()) {
                    Output outp = info.getCurrentOutput();
                    GenericQTIElement el_feedback = outp.getEl_response();
                    if (el_feedback != null)
                        displayFeedback(sb, el_feedback, ai, translator.getLocale());
                }
                break;
            case // for menu item navigator
            QTIConstants.MESSAGE_SECTION_INFODEMANDED:
                // provide some stats maybe
                SectionContext sc = ai.getAssessmentContext().getCurrentSectionContext();
                displaySectionInfo(sb, sc, ai, comp, ubu, translator);
                break;
            case // at the start of the test
            QTIConstants.MESSAGE_ASSESSMENT_INFODEMANDED:
                displayAssessmentInfo(sb, act, ai, comp, ubu, translator);
                break;
        }
    }
    if (renderItems) {
        boolean displayForm = true;
        // First check wether we need to render a form.
        // No form is needed if the current item has a matapplet object to be displayed.
        // Matapplets will send their response back directly.
        SectionContext sct = act.getCurrentSectionContext();
        ItemContext itc = null;
        if (sct != null && !ai.isSectionPage()) {
            itc = sct.getCurrentItemContext();
            if (itc != null) {
                Item item = itc.getQtiItem();
                if (item.getQTIIdent().startsWith("QTIEDIT:FLA:"))
                    displayForm = false;
            }
        }
        // do not display form with button in case no more item is open
        if (sct != null && ai.isSectionPage()) {
            displayForm = sct.getItemsOpenCount() > 0;
        }
        sb.append("<form action=\"");
        ubu.buildURI(sb, new String[] { VelocityContainer.COMMAND_ID }, new String[] { "sitse" });
        sb.append("\" id=\"ofo_iq_item\" method=\"post\">");
        String memoId = null;
        String memoTx = "";
        boolean memo = comp.provideMemoField();
        if (!ai.isSectionPage()) {
            if (itc != null) {
                displayItem(sb, renderer, ubu, itc, ai);
                if (memo) {
                    memoId = itc.getIdent();
                    memoTx = ai.getMemo(memoId);
                }
            }
        } else {
            if (sct != null && sct.getItemContextCount() != 0) {
                displayItems(sb, renderer, ubu, sct, ai);
                if (memo) {
                    memoId = sct.getIdent();
                    memoTx = ai.getMemo(memoId);
                }
            }
        }
        boolean isDefaultMemo = false;
        if (memo) {
            if (memoTx == null) {
                isDefaultMemo = true;
                memoTx = translator.translate("qti.memofield.text");
            }
        }
        sb.append("<div class=\"row\">");
        sb.append("<div class='o_button_group'>");
        sb.append("<input class=\"btn btn-primary\" type=\"submit\" name=\"olat_fosm\" value=\"");
        if (ai.isSectionPage())
            sb.append(StringEscapeUtils.escapeHtml(translator.translate("submitMultiAnswers")));
        else
            sb.append(StringEscapeUtils.escapeHtml(translator.translate("submitSingleAnswer")));
        sb.append("\"");
        if (!displayForm)
            sb.append(" style=\"display: none;\"");
        sb.append(" />").append("</div><div class='col-md-10'>");
        if (memo && memoId != null) {
            sb.append("<div class=\"o_qti_item_note_box\">");
            sb.append("<label class=\"control-label\" for=\"o_qti_item_note\">").append(translator.translate("qti.memofield")).append("</label>");
            sb.append("<textarea id=\"o_qti_item_note\" class=\"form-control\" rows=\"4\" spellcheck=\"false\" onchange=\"memo('");
            sb.append(memoId);
            sb.append("', this.value);\" onkeyup=\"resize(this);\" onmouseup=\"resize(this);\"");
            if (isDefaultMemo) {
                sb.append(" onfocus=\"clrMemo(this);\"");
            }
            sb.append(">").append(memoTx).append("</textarea>").append("</div>");
        }
        // end memo
        sb.append("</div>").append(// end row
        "</div>").append("</form>");
    }
    if (status == QTIConstants.ASSESSMENT_FINISHED) {
        if (info.isFeedback()) {
            Output outp = info.getCurrentOutput();
            GenericQTIElement el_feedback = outp.getEl_response();
            if (el_feedback != null) {
                displayFeedback(sb, el_feedback, ai, null);
            } else {
                renderFeedback(info, sb, ai, translator);
                // add the next button
                sb.append("<a class=\"btn btn-primary\" onclick=\"return o2cl()\" href=\"");
                ubu.buildURI(sb, new String[] { VelocityContainer.COMMAND_ID }, new String[] { "sitsec" });
                String title = translator.translate("next");
                sb.append("\" title=\"" + StringEscapeUtils.escapeHtml(title) + "\">");
                sb.append("<span>").append(title).append("</span>");
                sb.append("</a>");
            }
        }
    }
    return sb;
}
Also used : SectionContext(org.olat.ims.qti.container.SectionContext) Hint(org.olat.ims.qti.container.qtielements.Hint) StringOutput(org.olat.core.gui.render.StringOutput) Info(org.olat.ims.qti.navigator.Info) Hint(org.olat.ims.qti.container.qtielements.Hint) AssessmentContext(org.olat.ims.qti.container.AssessmentContext) ItemContext(org.olat.ims.qti.container.ItemContext) Item(org.olat.ims.qti.container.qtielements.Item) StringOutput(org.olat.core.gui.render.StringOutput) Output(org.olat.ims.qti.container.Output) GenericQTIElement(org.olat.ims.qti.container.qtielements.GenericQTIElement) AssessmentInstance(org.olat.ims.qti.process.AssessmentInstance) Solution(org.olat.ims.qti.container.qtielements.Solution)

Example 19 with ItemContext

use of org.olat.ims.qti.container.ItemContext in project OpenOLAT by OpenOLAT.

the class IQComponentRenderer method buildMenu.

/**
 * Method buildMenu.
 *
 * @return DOCUMENT ME!
 */
private StringOutput buildMenu(IQComponent comp, Translator translator, Renderer r, URLBuilder ubu) {
    StringOutput sb = new StringOutput();
    AssessmentInstance ai = comp.getAssessmentInstance();
    AssessmentContext ac = ai.getAssessmentContext();
    boolean renderSectionTitlesOnly = comp.getMenuDisplayConf().isRenderSectionsOnly();
    sb.append("<div id=\"o_qti_menu\">");
    sb.append("<h4>");
    sb.append(StringHelper.escapeHtml(ac.getTitle()));
    sb.append("</h4>");
    sb.append("<table border=0 width=\"100%\">");
    // append assessment navigation
    Formatter formatter = Formatter.getInstance(translator.getLocale());
    int scnt = ac.getSectionContextCount();
    for (int i = 0; i < scnt; i++) {
        SectionContext sc = ac.getSectionContext(i);
        boolean clickable = (ai.isSectionPage() && sc.isOpen()) || (!ai.isSectionPage());
        clickable = clickable && !ai.isClosed();
        clickable = clickable && ai.isMenu();
        sb.append("<tr>");
        sb.append(addSectionLink(r, ubu, formatter, sc, i, clickable, ac.getCurrentSectionContextPos() == i, ai.isSectionPage()));
        sb.append("</tr>");
        if (!renderSectionTitlesOnly) {
            // not only sections, but render questions to
            int icnt = sc.getItemContextCount();
            for (int j = 0; j < icnt; j++) {
                ItemContext itc = sc.getItemContext(j);
                clickable = !ai.isSectionPage() && sc.isOpen() && itc.isOpen();
                clickable = clickable && !ai.isClosed();
                clickable = clickable && ai.isMenu();
                sb.append("<tr>");
                sb.append(addItemLink(r, ubu, formatter, ai, itc, i, j, clickable, (ac.getCurrentSectionContextPos() == i && sc.getCurrentItemContextPos() == j), !ai.isSurvey()));
                sb.append("</tr>");
            }
        }
    }
    sb.append("</table>");
    sb.append("</div>");
    return sb;
}
Also used : SectionContext(org.olat.ims.qti.container.SectionContext) AssessmentContext(org.olat.ims.qti.container.AssessmentContext) ItemContext(org.olat.ims.qti.container.ItemContext) Formatter(org.olat.core.util.Formatter) AssessmentInstance(org.olat.ims.qti.process.AssessmentInstance) StringOutput(org.olat.core.gui.render.StringOutput) Hint(org.olat.ims.qti.container.qtielements.Hint)

Example 20 with ItemContext

use of org.olat.ims.qti.container.ItemContext in project OpenOLAT by OpenOLAT.

the class IQStatus method update.

/**
 * Update this status object with the given assessment instance
 * @param ai assessment instance
 */
public void update(AssessmentInstance ai) {
    if (ai == null) {
        return;
    }
    if (title == null)
        title = ai.getAssessmentContext().getTitle();
    isOpen = !ai.isClosed();
    isSurvey = ai.isSurvey();
    if (!isSurvey) {
        score = ai.getAssessmentContext().getScore();
        maxScore = ai.getAssessmentContext().getMaxScore();
    }
    assessStart = ai.getAssessmentContext().getTimeOfStart();
    assessMaxdur = ai.getAssessmentContext().getDurationLimit();
    SectionContext sc = ai.getAssessmentContext().getCurrentSectionContext();
    if (sc != null && sc.getCurrentItemContextPos() != -1) {
        ItemContext itc = sc.getCurrentItemContext();
        itemStart = itc.getTimeOfStart();
        itemMaxdur = itc.getDurationLimit();
        itemAttemptsLeft = (itc.getMaxAttempts() == -1) ? -1 : (itc.getMaxAttempts() - itc.getTimesAnswered());
    } else {
        itemMaxdur = -1;
        itemAttemptsLeft = -1;
    }
    questionPos = ai.getAssessmentContext().getItemPosWithinAssessment();
    maxQuestions = ai.getAssessmentContext().getItemContextCount();
    isAssess = ai.isAssess();
    isSelfAssess = ai.isSelfAssess();
    info = ai.getNavigator().getInfo();
}
Also used : SectionContext(org.olat.ims.qti.container.SectionContext) ItemContext(org.olat.ims.qti.container.ItemContext)

Aggregations

ItemContext (org.olat.ims.qti.container.ItemContext)28 AssessmentContext (org.olat.ims.qti.container.AssessmentContext)20 SectionContext (org.olat.ims.qti.container.SectionContext)20 ItemInput (org.olat.ims.qti.container.ItemInput)10 Output (org.olat.ims.qti.container.Output)8 AssessmentInstance (org.olat.ims.qti.process.AssessmentInstance)6 Date (java.util.Date)4 List (java.util.List)4 StringOutput (org.olat.core.gui.render.StringOutput)4 QTIResultSet (org.olat.ims.qti.QTIResultSet)4 HttpItemInput (org.olat.ims.qti.container.HttpItemInput)4 Hint (org.olat.ims.qti.container.qtielements.Hint)4 Info (org.olat.ims.qti.navigator.Info)4 IQManager (org.olat.modules.iq.IQManager)4 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 Iterator (java.util.Iterator)2 Set (java.util.Set)2 WebApplicationException (javax.ws.rs.WebApplicationException)2