Search in sources :

Example 1 with Navigator

use of org.olat.ims.qti.navigator.Navigator in project OpenOLAT by OpenOLAT.

the class CourseAssessmentWebService method importTestItems.

private void importTestItems(ICourse course, String nodeKey, Identity identity, AssessableResultsVO resultsVO) {
    try {
        IQManager iqManager = CoreSpringFactory.getImpl(IQManager.class);
        // load the course and the course node
        CourseNode courseNode = getParentNode(course, nodeKey);
        ModuleConfiguration modConfig = courseNode.getModuleConfiguration();
        // check if the result set is already saved
        QTIResultSet set = iqManager.getLastResultSet(identity, course.getResourceableId(), courseNode.getIdent());
        if (set == null) {
            String resourcePathInfo = course.getResourceableId() + File.separator + courseNode.getIdent();
            // The use of these classes AssessmentInstance, AssessmentContext and
            // Navigator
            // allow the use of the persistence mechanism of OLAT without
            // duplicating the code.
            // The consequence is that we must loop on section and items and set the
            // navigator on
            // the right position before submitting the inputs.
            AssessmentInstance ai = AssessmentFactory.createAssessmentInstance(identity, "", modConfig, false, course.getResourceableId(), courseNode.getIdent(), resourcePathInfo, null);
            Navigator navigator = ai.getNavigator();
            navigator.startAssessment();
            // The type of the navigator depends on the setting of the course node
            boolean perItem = (navigator instanceof MenuItemNavigator);
            Map<String, ItemInput> datas = convertToHttpItemInput(resultsVO.getResults());
            AssessmentContext ac = ai.getAssessmentContext();
            int sectioncnt = ac.getSectionContextCount();
            // loop on the sections
            for (int i = 0; i < sectioncnt; i++) {
                SectionContext sc = ac.getSectionContext(i);
                navigator.goToSection(i);
                ItemsInput iips = new ItemsInput();
                int itemcnt = sc.getItemContextCount();
                // loop on the items
                for (int j = 0; j < itemcnt; j++) {
                    ItemContext it = sc.getItemContext(j);
                    if (datas.containsKey(it.getIdent())) {
                        if (perItem) {
                            // save the datas on a per item base
                            navigator.goToItem(i, j);
                            // the navigator can give informations on its current status
                            Info info = navigator.getInfo();
                            if (info.containsError()) {
                            // some items cannot processed twice
                            } else {
                                iips.addItemInput(datas.get(it.getIdent()));
                                navigator.submitItems(iips);
                                iips = new ItemsInput();
                            }
                        } else {
                            // put for a section
                            iips.addItemInput(datas.get(it.getIdent()));
                        }
                    }
                }
                if (!perItem) {
                    // save the inputs of the section. In a section based navigation,
                    // we must saved the inputs of the whole section at once
                    navigator.submitItems(iips);
                }
            }
            navigator.submitAssessment();
            // persist the QTIResultSet (o_qtiresultset and o_qtiresult) on the
            // database
            // TODO iqManager.persistResults(ai, course.getResourceableId(),
            // courseNode.getIdent(), identity, "127.0.0.1");
            // write the reporting file on the file system
            // The path is <olatdata> / resreporting / <username> / Assessment /
            // <assessId>.xml
            // TODO Document docResReporting = iqManager.getResultsReporting(ai,
            // identity, Locale.getDefault());
            // TODO FilePersister.createResultsReporting(docResReporting, identity,
            // ai.getFormattedType(), ai.getAssessID());
            // prepare all instances needed to save the score at the course node
            // level
            CourseEnvironment cenv = course.getCourseEnvironment();
            IdentityEnvironment identEnv = new IdentityEnvironment();
            identEnv.setIdentity(identity);
            UserCourseEnvironment userCourseEnv = new UserCourseEnvironmentImpl(identEnv, cenv);
            // update scoring overview for the user in the current course
            Float score = ac.getScore();
            Boolean passed = ac.isPassed();
            // perhaps don't pass this key directly
            ScoreEvaluation sceval = new ScoreEvaluation(score, passed, passed, new Long(nodeKey));
            AssessableCourseNode acn = (AssessableCourseNode) courseNode;
            // assessment nodes are assessable
            boolean incrementUserAttempts = true;
            acn.updateUserScoreEvaluation(sceval, userCourseEnv, identity, incrementUserAttempts, Role.coach);
        } else {
            log.error("Result set already saved");
        }
    } catch (Exception e) {
        log.error("", e);
    }
}
Also used : SectionContext(org.olat.ims.qti.container.SectionContext) ScoreEvaluation(org.olat.course.run.scoring.ScoreEvaluation) HttpItemInput(org.olat.ims.qti.container.HttpItemInput) ItemInput(org.olat.ims.qti.container.ItemInput) ItemsInput(org.olat.ims.qti.container.ItemsInput) AssessableCourseNode(org.olat.course.nodes.AssessableCourseNode) AssessmentInstance(org.olat.ims.qti.process.AssessmentInstance) CourseNode(org.olat.course.nodes.CourseNode) AssessableCourseNode(org.olat.course.nodes.AssessableCourseNode) IQTESTCourseNode(org.olat.course.nodes.IQTESTCourseNode) IdentityEnvironment(org.olat.core.id.IdentityEnvironment) IQManager(org.olat.modules.iq.IQManager) ModuleConfiguration(org.olat.modules.ModuleConfiguration) UserCourseEnvironment(org.olat.course.run.userview.UserCourseEnvironment) CourseEnvironment(org.olat.course.run.environment.CourseEnvironment) UserCourseEnvironment(org.olat.course.run.userview.UserCourseEnvironment) Navigator(org.olat.ims.qti.navigator.Navigator) MenuItemNavigator(org.olat.ims.qti.navigator.MenuItemNavigator) Info(org.olat.ims.qti.navigator.Info) WebApplicationException(javax.ws.rs.WebApplicationException) QTIResultSet(org.olat.ims.qti.QTIResultSet) MenuItemNavigator(org.olat.ims.qti.navigator.MenuItemNavigator) AssessmentContext(org.olat.ims.qti.container.AssessmentContext) ItemContext(org.olat.ims.qti.container.ItemContext) UserCourseEnvironmentImpl(org.olat.course.run.userview.UserCourseEnvironmentImpl)

Example 2 with Navigator

use of org.olat.ims.qti.navigator.Navigator in project openolat by klemens.

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 3 with Navigator

use of org.olat.ims.qti.navigator.Navigator 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 4 with Navigator

use of org.olat.ims.qti.navigator.Navigator 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 5 with Navigator

use of org.olat.ims.qti.navigator.Navigator in project openolat by klemens.

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)

Aggregations

Navigator (org.olat.ims.qti.navigator.Navigator)6 AssessmentInstance (org.olat.ims.qti.process.AssessmentInstance)6 WindowControl (org.olat.core.gui.control.WindowControl)4 OLATResourceable (org.olat.core.id.OLATResourceable)4 AssessmentContext (org.olat.ims.qti.container.AssessmentContext)4 ItemsInput (org.olat.ims.qti.container.ItemsInput)4 SectionContext (org.olat.ims.qti.container.SectionContext)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 VelocityContainer (org.olat.core.gui.components.velocity.VelocityContainer)2 Event (org.olat.core.gui.control.Event)2 IdentityEnvironment (org.olat.core.id.IdentityEnvironment)2 AssertException (org.olat.core.logging.AssertException)2 AssessmentModeNotificationEvent (org.olat.course.assessment.AssessmentModeNotificationEvent)2 AssessableCourseNode (org.olat.course.nodes.AssessableCourseNode)2 CourseNode (org.olat.course.nodes.CourseNode)2 IQTESTCourseNode (org.olat.course.nodes.IQTESTCourseNode)2 IQEvent (org.olat.course.nodes.iq.IQEvent)2