Search in sources :

Example 6 with AssessmentInstance

use of org.olat.ims.qti.process.AssessmentInstance in project OpenOLAT by OpenOLAT.

the class IQDisplayController method init.

private void init(IQSecurityCallback secCallback, UserRequest ureq) {
    this.iqsec = secCallback;
    this.translator = Util.createPackageTranslator(IQDisplayController.class, ureq.getLocale());
    this.ready = false;
    retrieveListenerOres = new IQRetrievedEvent(ureq.getIdentity(), courseResId, courseNodeIdent);
    CoordinatorManager.getInstance().getCoordinator().getEventBus().registerFor(this, ureq.getIdentity(), retrieveListenerOres);
    iqm = CoreSpringFactory.getImpl(IQManager.class);
    myContent = new VelocityContainer("olatmodiqrun", VELOCITY_ROOT + "/qti.html", translator, this);
    // Check if fibautocompl.js and fibautocompl.css exists for enhance FIB autocomplete feature
    Resolver autcompResolver = null;
    if (resolver == null) {
        RepositoryEntry re = RepositoryManager.getInstance().lookupRepositoryEntryBySoftkey(repositorySoftkey, true);
        autcompResolver = new ImsRepositoryResolver(re);
    } else {
        autcompResolver = this.resolver;
    }
    if (autcompResolver != null && autcompResolver.hasAutocompleteFiles()) {
        // Add Autocomplte JS and CSS file to header
        StringBuilder sb = new StringBuilder();
        // must be like <script type="text/javascript" src="/olat/secstatic/qti/74579818809617/_unzipped_/fibautocompl.js"></script>
        sb.append("<script type=\"text/javascript\" src=\"").append(autcompResolver.getStaticsBaseURI()).append("/").append(ImsRepositoryResolver.QTI_FIB_AUTOCOMPLETE_JS_FILE).append("\"></script>\n");
        // must be like <link rel="StyleSheet" href="/olat/secstatic/qti/74579818809617/_unzipped_/fibautocompl.css" type="text/css" media="screen, print">
        sb.append("<link rel=\"StyleSheet\" href=\"").append(autcompResolver.getStaticsBaseURI()).append("/").append(ImsRepositoryResolver.QTI_FIB_AUTOCOMPLETE_CSS_FILE).append("\" type=\"text/css\" media=\"screen\" >\n");
        JSAndCSSComponent autoCompleteJsCss = new JSAndCSSComponent("auto_complete_js_css", this.getClass(), true, sb.toString());
        myContent.put("autoCompleteJsCss", autoCompleteJsCss);
    }
    closeButton = LinkFactory.createButton("close", myContent, this);
    closeButton.setPrimary(true);
    qtiscoreprogress = new ProgressBar("qtiscoreprogress", 150, 0, 0, "");
    myContent.put("qtiscoreprogress", qtiscoreprogress);
    Boolean displayScoreProgress = modConfig.getBooleanEntry(IQEditController.CONFIG_KEY_SCOREPROGRESS);
    // migration,
    if (displayScoreProgress == null)
        displayScoreProgress = Boolean.TRUE;
    // menu
    if (!displayScoreProgress.booleanValue())
        qtiscoreprogress.setVisible(false);
    myContent.contextPut("displayScoreProgress", displayScoreProgress);
    qtiquestionprogress = new ProgressBar("qtiquestionprogress", 150, 0, 0, "");
    myContent.put("qtiquestionprogress", qtiquestionprogress);
    Boolean displayQuestionProgress = modConfig.getBooleanEntry(IQEditController.CONFIG_KEY_QUESTIONPROGRESS);
    // migration,
    if (displayQuestionProgress == null)
        displayQuestionProgress = Boolean.FALSE;
    if (!displayQuestionProgress.booleanValue())
        qtiquestionprogress.setVisible(false);
    myContent.contextPut("displayQuestionProgress", displayQuestionProgress);
    Boolean displayMenu = modConfig.getBooleanEntry(IQEditController.CONFIG_KEY_DISPLAYMENU);
    // migration
    if (displayMenu == null)
        displayMenu = Boolean.TRUE;
    myContent.contextPut("displayMenu", displayMenu);
    Boolean enableCancel = modConfig.getBooleanEntry(IQEditController.CONFIG_KEY_ENABLECANCEL);
    if (enableCancel == null) {
        if (// migration:
        modConfig.get(IQEditController.CONFIG_KEY_TYPE).equals(AssessmentInstance.QMD_ENTRY_TYPE_ASSESS))
            // migration:
            enableCancel = Boolean.FALSE;
        else
            // disable
            // cancel
            // for
            // assessments
            // migration: enable otherwise
            enableCancel = Boolean.TRUE;
    }
    myContent.contextPut("enableCancel", enableCancel);
    Boolean enableSuspend = modConfig.getBooleanEntry(IQEditController.CONFIG_KEY_ENABLESUSPEND);
    // migration
    if (enableSuspend == null)
        enableSuspend = Boolean.FALSE;
    myContent.contextPut("enableSuspend", enableSuspend);
    qtistatus = new IQStatus(translator);
    qtistatus.setPreview(iqsec.isPreview());
    myContent.contextPut("qtistatus", qtistatus);
    setInitialComponent(myContent);
    // get the assessment
    AssessmentInstance ai = null;
    if (repositorySoftkey != null) {
        // instantiate from repository
        // build path information which will be used to store tempory qti file
        String resourcePathInfo = courseResId + File.separator + courseNodeIdent;
        ai = AssessmentFactory.createAssessmentInstance(ureq.getIdentity(), ureq.getHttpReq().getRemoteAddr(), modConfig, iqsec.isPreview(), courseResId, courseNodeIdent, resourcePathInfo, this);
    } else if (resolver != null) {
        // instantiate from given resolver
        ai = AssessmentFactory.createAssessmentInstance(ureq.getIdentity(), ureq.getHttpReq().getRemoteAddr(), courseResId, courseNodeIdent, resolver, persister, modConfig, this);
    }
    // check for null instance or instance with no items
    if (ai == null || ai.getAssessmentContext().getSectionContext(0).getItemContextCount() == 0)
        throw new AssertException("Assessment Instance was null or no sections/items found.");
    if (!iqsec.isAllowed(ai)) {
        // security check
        getWindowControl().setError(translator.translate("status.notallowed"));
        return;
    }
    if (iqsec.attemptsLeft(ai) < 1) {
        // security check
        // note: important: do not check on == 0 since the nr of attempts can be
        // republished for the same test with a smaller number as the latest time.
        getWindowControl().setInfo(translator.translate(ai.isSurvey() ? "status.survey.nomoreattempts" : "status.assess.nomoreattempts"));
        return;
    }
    if (ai.isResuming()) {
        getWindowControl().setInfo(translator.translate(ai.isSurvey() ? "status.survey.resumed" : "status.assess.resumed"));
    }
    ai.setPreview(iqsec.isPreview());
    /*
		 * menu render option: render only section titles or titles and questions.
		 */
    Object tmp = modConfig.get(IQEditController.CONFIG_KEY_RENDERMENUOPTION);
    Boolean renderSectionsOnly;
    if (tmp == null) {
        // migration
        modConfig.set(IQEditController.CONFIG_KEY_RENDERMENUOPTION, Boolean.FALSE);
        renderSectionsOnly = Boolean.FALSE;
    } else {
        renderSectionsOnly = (Boolean) tmp;
    }
    boolean enabledMenu = modConfig.getBooleanEntry(IQEditController.CONFIG_KEY_ENABLEMENU).booleanValue();
    boolean itemPageSequence = ((String) modConfig.get(IQEditController.CONFIG_KEY_SEQUENCE)).equals(AssessmentInstance.QMD_ENTRY_SEQUENCE_ITEM);
    IQMenuDisplayConf mdc = new IQMenuDisplayConf(renderSectionsOnly.booleanValue(), enabledMenu, itemPageSequence);
    Boolean tmpMemo = modConfig.getBooleanEntry(IQEditController.CONFIG_KEY_MEMO);
    boolean memo = tmpMemo == null ? false : tmpMemo.booleanValue();
    qticomp = new IQComponent("qticomponent", translator, ai, mdc, memo);
    qticomp.addListener(this);
    myContent.put("qticomp", qticomp);
    if (!ai.isResuming()) {
        Navigator navigator = ai.getNavigator();
        navigator.startAssessment();
    } else {
        // fxdiff BAKS-7 Resume function
        AssessmentContext act = ai.getAssessmentContext();
        if (act.getCurrentSectionContextPos() >= 0) {
            int sectionPos = act.getCurrentSectionContextPos();
            OLATResourceable sres = OresHelper.createOLATResourceableInstance("gse", new Long(sectionPos));
            WindowControl bwControl = addToHistory(ureq, sres, null, getWindowControl(), false);
            if (!ai.isSectionPage()) {
                SectionContext sct = act.getCurrentSectionContext();
                int itemPos = sct.getCurrentItemContextPos();
                if (itemPos >= 0) {
                    OLATResourceable ires = OresHelper.createOLATResourceableInstance("git", new Long(itemPos));
                    addToHistory(ureq, ires, null, bwControl, true);
                }
            }
        }
    }
    qtistatus.update(ai);
    if (!qtistatus.isSurvey()) {
        qtiscoreprogress.setMax(ai.getAssessmentContext().getMaxScore());
        qtiscoreprogress.setActual(ai.getAssessmentContext().getScore());
    }
    qtiquestionprogress.setMax(Integer.parseInt(qtistatus.getMaxQuestions()));
    updateQuestionProgressDisplay(ai);
    ready = true;
}
Also used : SectionContext(org.olat.ims.qti.container.SectionContext) OLATResourceable(org.olat.core.id.OLATResourceable) RepositoryEntry(org.olat.repository.RepositoryEntry) WindowControl(org.olat.core.gui.control.WindowControl) AssessmentInstance(org.olat.ims.qti.process.AssessmentInstance) ProgressBar(org.olat.core.gui.components.progressbar.ProgressBar) JSAndCSSComponent(org.olat.core.gui.components.htmlheader.jscss.JSAndCSSComponent) AssertException(org.olat.core.logging.AssertException) Resolver(org.olat.ims.qti.process.Resolver) ImsRepositoryResolver(org.olat.ims.qti.process.ImsRepositoryResolver) ImsRepositoryResolver(org.olat.ims.qti.process.ImsRepositoryResolver) Navigator(org.olat.ims.qti.navigator.Navigator) VelocityContainer(org.olat.core.gui.components.velocity.VelocityContainer) AssessmentContext(org.olat.ims.qti.container.AssessmentContext)

Example 7 with AssessmentInstance

use of org.olat.ims.qti.process.AssessmentInstance in project OpenOLAT by OpenOLAT.

the class IQDisplayController method event.

@Override
public void event(UserRequest ureq, Component source, Event event) {
    if (retrievedFlag) {
        fireEvent(ureq, new IQEvent(IQEvent.TEST_PULLED));
        return;
    } else if (retrievedFlag || stoppedFlag) {
        fireEvent(ureq, new IQEvent(IQEvent.TEST_STOPPED));
        return;
    }
    if (source == myContent || source == qticomp) {
        // those must be links
        String wfCommand = event.getCommand();
        // process workflow
        AssessmentInstance ai = qticomp.getAssessmentInstance();
        if (qticomp == null || ai == null) {
            throw new RuntimeException("AssessmentInstance not valid.");
        }
        Navigator navig = ai.getNavigator();
        if (wfCommand.equals("mark")) {
            ai.mark(ureq.getParameter("id"), "true".equals(ureq.getParameter("p")));
            ai.persist();
            return;
        }
        if (wfCommand.equals("memo")) {
            try {
                String memo = java.net.URLDecoder.decode(ureq.getParameter("p"), "UTF-8");
                ai.setMemo(ureq.getParameter("id"), memo);
                ai.persist();
                return;
            } catch (UnsupportedEncodingException ex) {
                log.info("Could not decode memo text " + ureq.getParameter("p"));
            }
        }
        logAudit(ureq);
        if (wfCommand.equals("sitse")) {
            // submitItemorSection
            ItemsInput iInp = iqm.getItemsInput(ureq);
            if (iInp.getItemCount() > 0) {
                navig.submitItems(iInp);
            }
            if (ai.isClosed()) {
                // do all the finishing stuff
                if (navig.getInfo().isFeedback()) {
                // render the feedback
                } else {
                    event(ureq, source, new Event(QTIConstants.QTI_WF_SUBMIT));
                    return;
                }
            }
        } else if (wfCommand.equals("sitsec")) {
            // submit
            if (ai.isClosed()) {
                // do all the finishing stuff
                if (!qtistatus.isSurvey()) {
                    // for test and self-assessment, generate detailed results
                    generateDetailsResults(ureq, ai);
                } else {
                    // Send also finished event in case of survey
                    fireEvent(ureq, new IQSubmittedEvent());
                }
                return;
            }
        } else if (wfCommand.equals("sflash")) {
            // submit flash answer
            // 
            navig.submitItems(iqm.getItemsInput(ureq));
            if (ai.isClosed()) {
                // do all the finishing stuff
                event(ureq, source, new Event(QTIConstants.QTI_WF_SUBMIT));
                return;
            }
        } else if (wfCommand.equals("git")) {
            // goToItem
            String seid = ureq.getParameter("seid");
            String itid = ureq.getParameter("itid");
            if (seid != null && seid.length() != 0 && itid != null && itid.length() != 0) {
                int sectionPos = Integer.parseInt(seid);
                int itemPos = Integer.parseInt(itid);
                navig.goToItem(sectionPos, itemPos);
                // fxdiff BAKS-7 Resume function
                OLATResourceable sres = OresHelper.createOLATResourceableInstance("gse", new Long(sectionPos));
                WindowControl bwControl = addToHistory(ureq, sres, null, getWindowControl(), false);
                OLATResourceable ires = OresHelper.createOLATResourceableInstance("git", new Long(itemPos));
                addToHistory(ureq, ires, null, bwControl, true);
            }
        } else if (wfCommand.equals("gse")) {
            // goToSection
            String seid = ureq.getParameter("seid");
            if (seid != null && seid.length() != 0) {
                int sectionPos = Integer.parseInt(seid);
                navig.goToSection(sectionPos);
                // fxdiff BAKS-7 Resume function
                OLATResourceable sres = OresHelper.createOLATResourceableInstance("gse", new Long(sectionPos));
                addToHistory(ureq, sres, null);
            }
        } else if (wfCommand.equals(QTIConstants.QTI_WF_SUBMIT)) {
            // submit
            // Assessment
            navig.submitAssessment();
            postSubmitAssessment(ureq, ai);
        } else if (wfCommand.equals(QTIConstants.QTI_WF_CANCEL)) {
            // cancel
            // assessment
            navig.cancelAssessment();
        } else if (wfCommand.equals(QTIConstants.QTI_WF_SUSPEND)) {
            // suspend
            // assessment
            // just close the controller
            fireEvent(ureq, Event.DONE_EVENT);
            return;
        } else if (wfCommand.equals("close")) {
            qtistatus.update(null);
            // Parent controller need to pop, if they pushed previously
            fireEvent(ureq, Event.DONE_EVENT);
            return;
        }
        qtistatus.update(ai);
        if (!qtistatus.isSurvey())
            qtiscoreprogress.setActual(ai.getAssessmentContext().getScore());
        updateQuestionProgressDisplay(ai);
    } else if (source == closeButton) {
        // close component
        qtistatus.update(null);
        // Parent controller need to pop, if they pushed previously
        fireEvent(ureq, Event.DONE_EVENT);
        return;
    }
}
Also used : OLATResourceable(org.olat.core.id.OLATResourceable) Navigator(org.olat.ims.qti.navigator.Navigator) UnsupportedEncodingException(java.io.UnsupportedEncodingException) WindowControl(org.olat.core.gui.control.WindowControl) ItemsInput(org.olat.ims.qti.container.ItemsInput) IQEvent(org.olat.course.nodes.iq.IQEvent) AssessmentInstance(org.olat.ims.qti.process.AssessmentInstance) IQEvent(org.olat.course.nodes.iq.IQEvent) Event(org.olat.core.gui.control.Event) AssessmentModeNotificationEvent(org.olat.course.assessment.AssessmentModeNotificationEvent)

Example 8 with AssessmentInstance

use of org.olat.ims.qti.process.AssessmentInstance 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 9 with AssessmentInstance

use of org.olat.ims.qti.process.AssessmentInstance 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 10 with AssessmentInstance

use of org.olat.ims.qti.process.AssessmentInstance in project openolat by klemens.

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)

Aggregations

AssessmentInstance (org.olat.ims.qti.process.AssessmentInstance)14 AssessmentContext (org.olat.ims.qti.container.AssessmentContext)12 SectionContext (org.olat.ims.qti.container.SectionContext)8 ScoreEvaluation (org.olat.course.run.scoring.ScoreEvaluation)6 UserCourseEnvironment (org.olat.course.run.userview.UserCourseEnvironment)6 ItemContext (org.olat.ims.qti.container.ItemContext)6 Navigator (org.olat.ims.qti.navigator.Navigator)6 ModuleConfiguration (org.olat.modules.ModuleConfiguration)6 Document (org.dom4j.Document)4 WindowControl (org.olat.core.gui.control.WindowControl)4 StringOutput (org.olat.core.gui.render.StringOutput)4 OLATResourceable (org.olat.core.id.OLATResourceable)4 AssessableCourseNode (org.olat.course.nodes.AssessableCourseNode)4 ItemsInput (org.olat.ims.qti.container.ItemsInput)4 Hint (org.olat.ims.qti.container.qtielements.Hint)4 Info (org.olat.ims.qti.navigator.Info)4 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 WebApplicationException (javax.ws.rs.WebApplicationException)2 JSAndCSSComponent (org.olat.core.gui.components.htmlheader.jscss.JSAndCSSComponent)2 ProgressBar (org.olat.core.gui.components.progressbar.ProgressBar)2