Search in sources :

Example 1 with Solution

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

the class QTI_respcondition method process.

/**
 * Response Condition
 *
 * ims qti 1.2.1 respcondition
 * <!ELEMENT respcondition (qticomment? , conditionvar , setvar* , displayfeedback*)>
 * <!ELEMENT conditionvar (not | and | or | unanswered | other | varequal | varlt | varlte |
 *      vargt | vargte | varsubset | varinside | varsubstring | durequal | durlt | durlte | durgt | durgte)+>
 *
 * <!ELEMENT setvar (#PCDATA)>
 * <!ATTLIST setvar  %I_VarName; action     (Set | Add | Subtract | Multiply | Divide )  'Set' >
 * mit I_VarName = varname CDATA  'SCORE'
 * <setvar action="Set" varname="SCORE">10</setvar>
 *
 * <!ELEMENT displayfeedback (#PCDATA)>
 * <!ATTLIST displayfeedback  feedbacktype  (Response | Solution | Hint )  'Response'
 *	                        %I_LinkRefId; >
 * mit I_LinkRefId = linkrefid CDATA  #REQUIRED"
 * e.g. <displayfeedback feedbacktype = "Solution" linkrefid = "CorrectSoln"/>
 *
 * ??? should be ? ? <conditionvar><or>...</or><varequal>...</varequal></conditionvar> does not make sense
 * but 	<conditionvar>
 *					<varequal respident = "Word-1">KITTENS</varequal>
 *					<varequal respident = "Word-2">HATS</varequal>
 *				</conditionvar> makes sense, so treat members of conditionvar as children of an "and" element
 * @param node_respcond
 */
public boolean process(Element el_respcond, ItemContext itc, EvalContext ect) {
    // 1. evaluate conditionvar
    // 2. if true, set variables
    // and setCurrentDisplayFeedback (TODO: assuming there is only one displayfeedback in a respcondition)
    Variables vars;
    Element el_condVar = (Element) el_respcond.selectSingleNode("conditionvar");
    String respcondtitle = el_respcond.attributeValue("title");
    QTI_and qtiAnd = QTIHelper.getQTI_and();
    boolean fulfilled = qtiAnd.eval(el_condVar, itc, ect);
    // continue to set variables and display feedback if question was answered correctly
    if (fulfilled) {
        vars = itc.getVariables();
        List setvars = el_respcond.selectNodes("setvar");
        for (Iterator iter = setvars.iterator(); iter.hasNext(); ) {
            Element element = (Element) iter.next();
            String action = element.attributeValue("action");
            String varName = element.attributeValue("varname");
            if (varName == null)
                varName = "SCORE";
            varName.trim();
            String varVal = element.getText();
            Variable var = vars.getVariable(varName);
            if (var == null)
                throw new RuntimeException("var " + varName + " is in setvar, but was not declared ");
            if (action.equals("Set")) {
                var.setValue(varVal);
            } else {
                // Add | Subtract | Multiply | Divide
                if (action.equals("Add")) {
                    var.add(varVal);
                } else if (action.equals("Subtract")) {
                    var.subtract(varVal);
                } else if (action.equals("Multiply")) {
                    var.multiply(varVal);
                } else if (action.equals("Divide")) {
                    var.divide(varVal);
                }
            }
        }
        // set displayfeedback
        // <displayfeedback feedbacktype = "Response" linkrefid = "Correct"/>
        // <!ATTLIST displayfeedback  feedbacktype  (Response | Solution | Hint )  'Response' %I_LinkRefId; >
        Output output = itc.getOutput();
        List fbs = el_respcond.selectNodes("displayfeedback");
        for (Iterator it_fbs = fbs.iterator(); it_fbs.hasNext(); ) {
            Element el_dispfb = (Element) it_fbs.next();
            // must exist (dtd)
            String linkRefId = el_dispfb.attributeValue("linkrefid");
            // must exist (dtd)
            String feedbacktype = el_dispfb.attributeValue("feedbacktype");
            Element el_resolved = (Element) itc.getEl_item().selectSingleNode(".//itemfeedback[@ident='" + linkRefId + "']");
            if (el_resolved == null)
                continue;
            if (feedbacktype.equals("Response")) {
                // additional (olat) rule:
                // we want to render the original answer again in the simple case where the respcondition was generated
                // by the olat export and contains only one varequal.
                /*
					  
					 	 <response_label ident = "2">
			     			<flow_mat>
								<material>
										<mattext texttype="text/html">...</mattext>
								</material>
                  			</flow_mat>
                		</response_label> 
					  ...
					
					 	<respcondition title="_olat_resp_feedback" continue="Yes">
							<conditionvar>
								<varequal respident="Frage6549" case="Yes">2</varequal>
							</conditionvar>
            				<displayfeedback linkrefid="2"/>
						</respcondition>
						
						In this case, it is possible (and wished) to trace the feedback back to the answer which triggered this feedback.
						Such a respcondition is identified by the title which is exactly "_olat_resp_feedback".
						
						
					 */
                Element el_chosenanswer = null;
                if (respcondtitle != null && respcondtitle.equals("_olat_resp_feedback")) {
                    Element el_vareq = (Element) el_respcond.selectSingleNode(".//varequal");
                    String answerident = el_vareq.getText();
                    el_chosenanswer = (Element) itc.getEl_item().selectSingleNode(".//response_label[@ident='" + answerident + "']//material");
                }
                // give the whole itemfeedback to render
                output.addItem_El_response(el_chosenanswer, el_resolved);
            } else if (feedbacktype.equals("Solution")) {
                Element el_solution = (Element) el_resolved.selectSingleNode(".//solution");
                if (el_solution != null)
                    output.setSolution(new Solution(el_solution));
            } else if (feedbacktype.equals("Hint")) {
                // <!ENTITY % I_FeedbackStyle " feedbackstyle  (Complete | Incremental | Multilevel | Proprietary )  'Complete'">
                Element el_hint = (Element) el_resolved.selectSingleNode(".//hint");
                output.setHint(new Hint(el_hint));
            }
        }
    }
    return fulfilled;
}
Also used : Variables(org.olat.ims.qti.container.Variables) Variable(org.olat.ims.qti.container.Variable) Hint(org.olat.ims.qti.container.qtielements.Hint) Element(org.dom4j.Element) Output(org.olat.ims.qti.container.Output) Iterator(java.util.Iterator) List(java.util.List) Solution(org.olat.ims.qti.container.qtielements.Solution)

Example 2 with Solution

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

the class QTI_respcondition method process.

/**
 * Response Condition
 *
 * ims qti 1.2.1 respcondition
 * <!ELEMENT respcondition (qticomment? , conditionvar , setvar* , displayfeedback*)>
 * <!ELEMENT conditionvar (not | and | or | unanswered | other | varequal | varlt | varlte |
 *      vargt | vargte | varsubset | varinside | varsubstring | durequal | durlt | durlte | durgt | durgte)+>
 *
 * <!ELEMENT setvar (#PCDATA)>
 * <!ATTLIST setvar  %I_VarName; action     (Set | Add | Subtract | Multiply | Divide )  'Set' >
 * mit I_VarName = varname CDATA  'SCORE'
 * <setvar action="Set" varname="SCORE">10</setvar>
 *
 * <!ELEMENT displayfeedback (#PCDATA)>
 * <!ATTLIST displayfeedback  feedbacktype  (Response | Solution | Hint )  'Response'
 *	                        %I_LinkRefId; >
 * mit I_LinkRefId = linkrefid CDATA  #REQUIRED"
 * e.g. <displayfeedback feedbacktype = "Solution" linkrefid = "CorrectSoln"/>
 *
 * ??? should be ? ? <conditionvar><or>...</or><varequal>...</varequal></conditionvar> does not make sense
 * but 	<conditionvar>
 *					<varequal respident = "Word-1">KITTENS</varequal>
 *					<varequal respident = "Word-2">HATS</varequal>
 *				</conditionvar> makes sense, so treat members of conditionvar as children of an "and" element
 * @param node_respcond
 */
public boolean process(Element el_respcond, ItemContext itc, EvalContext ect) {
    // 1. evaluate conditionvar
    // 2. if true, set variables
    // and setCurrentDisplayFeedback (TODO: assuming there is only one displayfeedback in a respcondition)
    Variables vars;
    Element el_condVar = (Element) el_respcond.selectSingleNode("conditionvar");
    String respcondtitle = el_respcond.attributeValue("title");
    QTI_and qtiAnd = QTIHelper.getQTI_and();
    boolean fulfilled = qtiAnd.eval(el_condVar, itc, ect);
    // continue to set variables and display feedback if question was answered correctly
    if (fulfilled) {
        vars = itc.getVariables();
        List setvars = el_respcond.selectNodes("setvar");
        for (Iterator iter = setvars.iterator(); iter.hasNext(); ) {
            Element element = (Element) iter.next();
            String action = element.attributeValue("action");
            String varName = element.attributeValue("varname");
            if (varName == null)
                varName = "SCORE";
            varName.trim();
            String varVal = element.getText();
            Variable var = vars.getVariable(varName);
            if (var == null)
                throw new RuntimeException("var " + varName + " is in setvar, but was not declared ");
            if (action.equals("Set")) {
                var.setValue(varVal);
            } else {
                // Add | Subtract | Multiply | Divide
                if (action.equals("Add")) {
                    var.add(varVal);
                } else if (action.equals("Subtract")) {
                    var.subtract(varVal);
                } else if (action.equals("Multiply")) {
                    var.multiply(varVal);
                } else if (action.equals("Divide")) {
                    var.divide(varVal);
                }
            }
        }
        // set displayfeedback
        // <displayfeedback feedbacktype = "Response" linkrefid = "Correct"/>
        // <!ATTLIST displayfeedback  feedbacktype  (Response | Solution | Hint )  'Response' %I_LinkRefId; >
        Output output = itc.getOutput();
        List fbs = el_respcond.selectNodes("displayfeedback");
        for (Iterator it_fbs = fbs.iterator(); it_fbs.hasNext(); ) {
            Element el_dispfb = (Element) it_fbs.next();
            // must exist (dtd)
            String linkRefId = el_dispfb.attributeValue("linkrefid");
            // must exist (dtd)
            String feedbacktype = el_dispfb.attributeValue("feedbacktype");
            Element el_resolved = (Element) itc.getEl_item().selectSingleNode(".//itemfeedback[@ident='" + linkRefId + "']");
            if (el_resolved == null)
                continue;
            if (feedbacktype.equals("Response")) {
                // additional (olat) rule:
                // we want to render the original answer again in the simple case where the respcondition was generated
                // by the olat export and contains only one varequal.
                /*
					  
					 	 <response_label ident = "2">
			     			<flow_mat>
								<material>
										<mattext texttype="text/html">...</mattext>
								</material>
                  			</flow_mat>
                		</response_label> 
					  ...
					
					 	<respcondition title="_olat_resp_feedback" continue="Yes">
							<conditionvar>
								<varequal respident="Frage6549" case="Yes">2</varequal>
							</conditionvar>
            				<displayfeedback linkrefid="2"/>
						</respcondition>
						
						In this case, it is possible (and wished) to trace the feedback back to the answer which triggered this feedback.
						Such a respcondition is identified by the title which is exactly "_olat_resp_feedback".
						
						
					 */
                Element el_chosenanswer = null;
                if (respcondtitle != null && respcondtitle.equals("_olat_resp_feedback")) {
                    Element el_vareq = (Element) el_respcond.selectSingleNode(".//varequal");
                    String answerident = el_vareq.getText();
                    el_chosenanswer = (Element) itc.getEl_item().selectSingleNode(".//response_label[@ident='" + answerident + "']//material");
                }
                // give the whole itemfeedback to render
                output.addItem_El_response(el_chosenanswer, el_resolved);
            } else if (feedbacktype.equals("Solution")) {
                Element el_solution = (Element) el_resolved.selectSingleNode(".//solution");
                if (el_solution != null)
                    output.setSolution(new Solution(el_solution));
            } else if (feedbacktype.equals("Hint")) {
                // <!ENTITY % I_FeedbackStyle " feedbackstyle  (Complete | Incremental | Multilevel | Proprietary )  'Complete'">
                Element el_hint = (Element) el_resolved.selectSingleNode(".//hint");
                output.setHint(new Hint(el_hint));
            }
        }
    }
    return fulfilled;
}
Also used : Variables(org.olat.ims.qti.container.Variables) Variable(org.olat.ims.qti.container.Variable) Hint(org.olat.ims.qti.container.qtielements.Hint) Element(org.dom4j.Element) Output(org.olat.ims.qti.container.Output) Iterator(java.util.Iterator) List(java.util.List) Solution(org.olat.ims.qti.container.qtielements.Solution)

Example 3 with Solution

use of org.olat.ims.qti.container.qtielements.Solution 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 4 with Solution

use of org.olat.ims.qti.container.qtielements.Solution 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

Output (org.olat.ims.qti.container.Output)4 Hint (org.olat.ims.qti.container.qtielements.Hint)4 Solution (org.olat.ims.qti.container.qtielements.Solution)4 Iterator (java.util.Iterator)2 List (java.util.List)2 Element (org.dom4j.Element)2 StringOutput (org.olat.core.gui.render.StringOutput)2 AssessmentContext (org.olat.ims.qti.container.AssessmentContext)2 ItemContext (org.olat.ims.qti.container.ItemContext)2 SectionContext (org.olat.ims.qti.container.SectionContext)2 Variable (org.olat.ims.qti.container.Variable)2 Variables (org.olat.ims.qti.container.Variables)2 GenericQTIElement (org.olat.ims.qti.container.qtielements.GenericQTIElement)2 Item (org.olat.ims.qti.container.qtielements.Item)2 Info (org.olat.ims.qti.navigator.Info)2 AssessmentInstance (org.olat.ims.qti.process.AssessmentInstance)2