Search in sources :

Example 6 with SectionContext

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

the class SequentialItemNavigator method submitItems.

/**
 * @see org.olat.ims.qti.navigator.Navigator#submitItems(org.olat.ims.qti.container.ItemsInput)
 */
public void submitItems(ItemsInput curitsinp) {
    clearInfo();
    AssessmentContext ac = getAssessmentContext();
    SectionContext sc = ac.getCurrentSectionContext();
    int st = submitOneItem(curitsinp);
    if (st != QTIConstants.ITEM_SUBMITTED) {
        // item or assessment-finished-text
        if (st == QTIConstants.ERROR_SUBMITTEDITEM_TOOMANYATTEMPTS) {
            throw new RuntimeException("import check failed: there was a maxattempts in a item, but mode is sequential/item");
        } else if (st == QTIConstants.ERROR_ASSESSMENT_OUTOFTIME) {
            getInfo().setError(st);
            getInfo().setRenderItems(false);
        } else if (st == QTIConstants.ERROR_SUBMITTEDITEM_OUTOFTIME) {
            getInfo().setError(st);
            // still continue to next item
            getInfo().setRenderItems(true);
        }
    } else {
        // ok, display feedback
        ItemContext itc = getAssessmentContext().getCurrentSectionContext().getCurrentItemContext();
        Output outp = itc.getOutput();
        if (outp != null)
            getInfo().setCurrentOutput(outp);
        // check on item feedback
        if (itc.isFeedback()) {
            // feedback allowed
            getInfo().setFeedback(itc.getOutput().hasItem_Responses());
        }
        getInfo().setMessage(QTIConstants.MESSAGE_ITEM_SUBMITTED);
        getInfo().setRenderItems(true);
    }
    // find next item
    int itpos = sc.getCurrentItemContextPos();
    if (itpos < sc.getItemContextCount() - 1 && sc.isOpen()) {
        // there are still further items in the current section
        sc.setCurrentItemContextPos(++itpos);
        sc.getCurrentItemContext().start();
    } else {
        // fetch next section
        if (!sc.isOpen()) {
            getInfo().setError(QTIConstants.ERROR_SECTION_OUTOFTIME);
            getInfo().setRenderItems(true);
        }
        ac.getCurrentSectionContext().sectionWasSubmitted();
        int secPos = ac.getCurrentSectionContextPos();
        int secPosMax = ac.getSectionContextCount() - 1;
        if (!ac.isOpen()) {
            getInfo().setError(QTIConstants.ERROR_ASSESSMENT_OUTOFTIME);
            getInfo().setRenderItems(false);
            submitAssessment();
        } else if (secPos == secPosMax)
            submitAssessment();
        else {
            while (secPos < secPosMax) {
                // there are still further section(s)
                secPos++;
                if (ac.getSectionContext(secPos).getItemContextCount() != 0)
                    break;
            }
            if (secPos == secPosMax && ac.getSectionContext(secPos).getItemContextCount() == 0) {
                // reached last section but section is empty -> finish assessment
                submitAssessment();
            } else {
                ac.setCurrentSectionContextPos(secPos);
                ac.getCurrentSectionContext().setCurrentItemContextPos(0);
                ac.getCurrentSectionContext().start();
                ac.getCurrentSectionContext().getCurrentItemContext().start();
                // since new section starts, show next the section title and description
                getInfo().setRenderItems(false);
            }
        }
    }
    getAssessmentInstance().persist();
}
Also used : SectionContext(org.olat.ims.qti.container.SectionContext) AssessmentContext(org.olat.ims.qti.container.AssessmentContext) ItemContext(org.olat.ims.qti.container.ItemContext) Output(org.olat.ims.qti.container.Output)

Example 7 with SectionContext

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

the class MenuSectionNavigator method goToSection.

/**
 * @see org.olat.qti.process.Navigator#goToSection(int)
 */
public void goToSection(int sectionPos) {
    clearInfo();
    AssessmentContext ac = getAssessmentContext();
    SectionContext sc = ac.getSectionContext(sectionPos);
    // check if section still open
    if (!ac.isOpen()) {
        getInfo().setError(QTIConstants.ERROR_ASSESSMENT_OUTOFTIME);
        getInfo().setRenderItems(false);
    } else if (!sc.isOpen()) {
        getInfo().setError(QTIConstants.ERROR_SECTION_OUTOFTIME);
        getInfo().setRenderItems(false);
    } else {
        getInfo().setStatus(QTIConstants.ASSESSMENT_RUNNING);
        // show section info (title and description)
        getInfo().setMessage(QTIConstants.MESSAGE_SECTION_INFODEMANDED);
        getInfo().setRenderItems(true);
        ac.setCurrentSectionContextPos(sectionPos);
        sc = ac.getCurrentSectionContext();
        startSection(sc);
    }
    getAssessmentInstance().persist();
}
Also used : SectionContext(org.olat.ims.qti.container.SectionContext) AssessmentContext(org.olat.ims.qti.container.AssessmentContext)

Example 8 with SectionContext

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

the class IQManager method persistResults.

/**
 * Create the QTIResults on the database for a given assessments,
 * self-assessment or survey. These database entries can be used for
 * statistical downloads.
 *
 * @param ai
 * @param resId
 * @param resDetail
 * @param ureq
 */
public void persistResults(AssessmentInstance ai) {
    AssessmentContext ac = ai.getAssessmentContext();
    QTIResultSet qtiResultSet = new QTIResultSet();
    qtiResultSet.setLastModified(new Date(System.currentTimeMillis()));
    qtiResultSet.setOlatResource(ai.getCallingResId());
    qtiResultSet.setOlatResourceDetail(ai.getCallingResDetail());
    qtiResultSet.setRepositoryRef(ai.getRepositoryEntryKey());
    qtiResultSet.setIdentity(ai.getAssessedIdentity());
    qtiResultSet.setQtiType(ai.getType());
    qtiResultSet.setAssessmentID(ai.getAssessID());
    qtiResultSet.setDuration(new Long(ai.getAssessmentContext().getDuration()));
    if (ai.isSurvey()) {
        qtiResultSet.setScore(0);
        qtiResultSet.setIsPassed(true);
    } else {
        qtiResultSet.setScore(ac.getScore());
        qtiResultSet.setIsPassed(ac.isPassed());
    }
    dbInstance.getCurrentEntityManager().persist(qtiResultSet);
    // Loop over all sections in this assessment
    int sccnt = ac.getSectionContextCount();
    for (int i = 0; i < sccnt; i++) {
        // Loop over all items in this section
        SectionContext sc = ac.getSectionContext(i);
        int iccnt = sc.getItemContextCount();
        for (int j = 0; j < iccnt; j++) {
            ItemContext ic = sc.getItemContext(j);
            // Create new result item for this item
            QTIResult qtiResult = new QTIResult();
            qtiResult.setResultSet(qtiResultSet);
            qtiResult.setItemIdent(ic.getIdent());
            qtiResult.setDuration(new Long(ic.getTimeSpent()));
            if (ai.isSurvey())
                qtiResult.setScore(0);
            else
                qtiResult.setScore(ic.getScore());
            qtiResult.setTstamp(new Date(ic.getLatestAnswerTime()));
            qtiResult.setLastModified(new Date(System.currentTimeMillis()));
            qtiResult.setIp(ai.getRemoteAddr());
            // Get user answers for this item
            StringBuilder sb = new StringBuilder();
            if (ic.getItemInput() == null) {
            } else {
                ItemInput inp = ic.getItemInput();
                if (inp.isEmpty()) {
                    sb.append("[]");
                } else {
                    Map<String, List<String>> im = inp.getInputMap();
                    // Create answer block
                    Set<String> keys = im.keySet();
                    Iterator<String> iter = keys.iterator();
                    while (iter.hasNext()) {
                        String ident = iter.next();
                        // response_lid ident
                        sb.append(ident);
                        sb.append("[");
                        List<String> answers = inp.getAsList(ident);
                        for (int y = 0; y < answers.size(); y++) {
                            sb.append("[");
                            String answer = answers.get(y);
                            // answer is referenced to response_label ident, if
                            // render_choice
                            // answer is userinput, if render_fib
                            answer = quoteSpecialQTIResultCharacters(answer);
                            sb.append(answer);
                            sb.append("]");
                        }
                        sb.append("]");
                    }
                }
            }
            qtiResult.setAnswer(sb.toString());
            // Persist result data in database
            dbInstance.getCurrentEntityManager().persist(qtiResult);
        }
    }
}
Also used : SectionContext(org.olat.ims.qti.container.SectionContext) QTIResult(org.olat.ims.qti.QTIResult) HttpItemInput(org.olat.ims.qti.container.HttpItemInput) ItemInput(org.olat.ims.qti.container.ItemInput) Date(java.util.Date) QTIResultSet(org.olat.ims.qti.QTIResultSet) AssessmentContext(org.olat.ims.qti.container.AssessmentContext) ItemContext(org.olat.ims.qti.container.ItemContext) List(java.util.List) ArrayList(java.util.ArrayList)

Example 9 with SectionContext

use of org.olat.ims.qti.container.SectionContext in project openolat by klemens.

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)

Example 10 with SectionContext

use of org.olat.ims.qti.container.SectionContext in project openolat by klemens.

the class AssessmentInstance method stop.

/**
 * Method close.
 */
public void stop() {
    closed = true;
    assessmentContext.stop();
    SectionContext sc = assessmentContext.getCurrentSectionContext();
    if (sc != null)
        sc.setCurrentItemContextPos(-1);
    assessmentContext.setCurrentSectionContextPos(-1);
}
Also used : SectionContext(org.olat.ims.qti.container.SectionContext)

Aggregations

SectionContext (org.olat.ims.qti.container.SectionContext)32 AssessmentContext (org.olat.ims.qti.container.AssessmentContext)28 ItemContext (org.olat.ims.qti.container.ItemContext)20 ItemInput (org.olat.ims.qti.container.ItemInput)10 AssessmentInstance (org.olat.ims.qti.process.AssessmentInstance)8 Output (org.olat.ims.qti.container.Output)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 Navigator (org.olat.ims.qti.navigator.Navigator)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