Package org.olat.ims.qti.container

Examples of org.olat.ims.qti.container.ItemInput


   * <!ATTLIST vargte  %I_RespIdent;
                   %I_Index; >
   * e.g. <vargte respident = "NUM01">3.141</vargte>
   */
  public boolean eval(Element boolElement, ItemContext userContext, EvalContext ect) {
    ItemInput iinp = userContext.getItemInput();
    if (iinp.isEmpty()) return false; // user has given no answer   
    String respident = boolElement.attributeValue("respident");
    String shouldVal = boolElement.getText(); // the answer is tested against content of elem.
    String isVal = iinp.getSingle(respident);
    // the isVal and shouldVal must be numeric
    // we use Float so we are on the safe side, even if comparison was only Integer
    shouldVal = shouldVal.trim();
    isVal = isVal.trim();
    Float fs = new Float(shouldVal);
View Full Code Here


   * <!ATTLIST vargte  %I_RespIdent;
                   %I_Index; >
   * e.g. <vargte respident = "NUM01">3.141</vargte>
   */
  public boolean eval(Element boolElement, ItemContext userContext, EvalContext ect) {
    ItemInput iinp = userContext.getItemInput();
    if (iinp.isEmpty()) return false; // user has given no answer   
    String respident = boolElement.attributeValue("respident");
    String shouldVal = boolElement.getText(); // the answer is tested against content of elem.
    String isVal = iinp.getSingle(respident);
    // the isVal and shouldVal must be numeric
    // we use Float so we are on the safe side, even if comparison was only Integer
    shouldVal = shouldVal.trim();
    isVal = isVal.trim();
    Float fs = new Float(shouldVal);
View Full Code Here

        qtiResult.setIp(ureq.getHttpReq().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 im = inp.getInputMap();
            // Create answer block
            Set keys = im.keySet();
            Iterator iter = keys.iterator();
            while (iter.hasNext()) {
              String ident = (String) iter.next();
              sb.append(ident); // response_lid ident
              sb.append("[");
              List answers = inp.getAsList(ident);
              for (int y = 0; y < answers.size(); y++) {
                sb.append("[");
                String answer = (String) answers.get(y);
                // answer is referenced to response_label ident, if
                // render_choice
View Full Code Here

  public int submitOneItem(ItemsInput curitsinp) {
    if (info.getStatus() != QTIConstants.ASSESSMENT_RUNNING) throw new RuntimeException("assessment is NOT running yet or anymore");
    int cnt = curitsinp.getItemCount();
    if (cnt == 0) throw new RuntimeException("program bug: not even one iteminput in the answer");
    if (cnt > 1) throw new RuntimeException("may only submit 1 item");
    ItemInput itemInput = (ItemInput) curitsinp.getItemInputIterator().next();
    String ident = itemInput.getIdent();
    AssessmentContext ac = getAssessmentContext();
    SectionContext sc = ac.getCurrentSectionContext();
    ItemContext it = sc.getCurrentItemContext();
    ItemContext ict = sc.getItemContext(ident);
    if (ict == null) throw new RuntimeException("submitted item id ("+ident+")not found in xml");
View Full Code Here

    if (!sc.isOpen())
      return QTIConstants.ERROR_SUBMITTEDSECTION_OUTOFTIME;

    int sectionResult = QTIConstants.SECTION_SUBMITTED;
    for (Iterator it_inp = curitsinp.getItemInputIterator(); it_inp.hasNext();) {
      ItemInput itemInput = (ItemInput) it_inp.next();
      String ident = itemInput.getIdent();
      ItemContext ict = sc.getItemContext(ident);
      if (ict == null) throw new RuntimeException("submitted item id ("+ident+") not found in section sectioncontext "+sc.getIdent());
      int subres = ict.addItemInput(itemInput);
      ict.eval(); // to be up-to-date with the scores
      if (subres != QTIConstants.ITEM_SUBMITTED) {
View Full Code Here

  /**
   * @see org.olat.ims.qti.container.qtielements.QTIElement#render(StringBuilder,
   *      RenderInstructions)
   */
  public void render(StringBuilder buffer, RenderInstructions ri) {
    ItemInput iinput = (ItemInput) ri.get(RenderInstructions.KEY_ITEM_INPUT);
    String responseIdent = (String) ri.get(RenderInstructions.KEY_RESPONSE_IDENT);
    // find parent render_xxx element
    String renderClass = (String) ri.get(RenderInstructions.KEY_RENDER_CLASS);
    if (ri == null) throw new AssertException("Render class must be set previousely to call respnse_label.render.");
    if (renderClass.equals("choice")) {
      // render multiple/single choice
      Integer rCardinality = (Integer) ri.get(RenderInstructions.KEY_RESPONSE_RCARDINALITY);
      if (rCardinality == null) throw new AssertException(
          "Cardinality must be set previousely to call respnse_label.render for a render_choice class.");
      if (rCardinality.intValue() == Response_lid.RCARDINALITY_SINGLE) {
        // single choice
        buffer.append("<input id=\"QTI_").append(getQTIIdent()).append("\" type=\"radio\" class=\"b_radio\" name=\"");
        buffer.append("qti").append(PARA).append(ri.get(RenderInstructions.KEY_ITEM_IDENT)).append(PARA).append(
            ri.get(RenderInstructions.KEY_RESPONSE_IDENT)).append(PARA).append("choice");
        buffer.append("\" value=\"").append(getQTIIdent());
        if (iinput != null && !iinput.isEmpty()) {
          String response = iinput.getSingle(responseIdent);
          if (response.equals(getQTIIdent())) buffer.append("\" checked=\"checked");
        }
        buffer.append("\" onchange=\"return setFormDirty('ofo_iq_item')\" onclick=\"return setFormDirty('ofo_iq_item')\" />&nbsp;");
      } else if (rCardinality.intValue() == Response_lid.RCARDINALITY_MULTIPLE) {
        // multiple choice
        buffer.append("<input id=\"QTI_").append(getQTIIdent()).append("\" type=\"checkbox\" class=\"b_checkbox\" name=\"");
        appendParameterIdent(buffer, ri);
        buffer.append("\" value=\"").append(getQTIIdent());
        if (iinput != null) {
          List responses = iinput.getAsList(responseIdent);
          if (responses != null && responses.contains(getQTIIdent())) buffer.append("\" checked=\"checked");
        }
        buffer.append("\" onchange=\"return setFormDirty('ofo_iq_item')\" onclick=\"return setFormDirty('ofo_iq_item')\" />&nbsp;");
      }
      super.render(buffer, ri);

    } else if (renderClass.equals("kprim")) {
      buffer.append("<tr><td align=\"center\"><input id=\"QTI_").append(getQTIIdent()).append("\" type=\"radio\" class=\"b_radio\" name=\"");
      appendParameterIdent(buffer, ri);
      buffer.append("\" value=\"" + getQTIIdent() + ":correct\"");
      if (iinput != null && !iinput.isEmpty()) {
        List responses = iinput.getAsList(responseIdent);
        if (responses != null && responses.contains(getQTIIdent() + ":correct")) buffer.append("\" checked=\"checked");
      }
      buffer.append("\" onchange=\"return setFormDirty('ofo_iq_item')\" onclick=\"return setFormDirty('ofo_iq_item')\"/>");
      buffer.append("</td><td align=\"center\"><input id=\"QTI_").append(getQTIIdent()).append("\" type=\"radio\" class=\"b_radio\" name=\"");
      appendParameterIdent(buffer, ri);
      buffer.append("\" value=\"" + getQTIIdent() + ":wrong\"");
      if (iinput != null && !iinput.isEmpty()) {
        List responses = iinput.getAsList(responseIdent);
        if (responses != null && responses.contains(getQTIIdent() + ":wrong")) buffer.append("\" checked=\"checked");
      }
      buffer.append("\" onchange=\"return setFormDirty('ofo_iq_item')\" onclick=\"return setFormDirty('ofo_iq_item')\"/>");
      buffer.append("</td><td>");
      super.render(buffer, ri);
      buffer.append("</td></tr>");
      ri.put(RenderInstructions.KEY_FLOW_LABEL, new Integer(RenderInstructions.RENDER_FLOW_BLOCK));
     
    } else if (renderClass.equals("fib")) {
      Integer rows = (Integer) ri.get(RenderInstructions.KEY_FIB_ROWS);
      Integer columns = (Integer) ri.get(RenderInstructions.KEY_FIB_COLUMNS);
      Integer maxlength = (Integer) ri.get(RenderInstructions.KEY_FIB_MAXLENGTH);
      if (rows == null || columns == null || maxlength == null) throw new AssertException(
          "Rows and/or columns attribute not specified for render_fib.");
      if (rows.intValue() > 1) {
        // render as textarea
        buffer.append("<textarea id=\"QTI_").append(getQTIIdent()).append("\" name=\"");
        appendParameterIdent(buffer, ri);
        buffer.append("\" rows=\"").append(rows).append("\" cols=\"").append(columns)
            .append("\" onchange=\"return setFormDirty('ofo_iq_item')\" onclick=\"return setFormDirty('ofo_iq_item')\">");
        if (iinput != null && !iinput.isEmpty() && iinput.getSingle(responseIdent) != null) {
          buffer.append(iinput.getSingle(getQTIIdent()));
        }
        buffer.append("</textarea>");
      } else {
        // render as input string
        buffer.append("<input id=\"QTI_").append(getQTIIdent()).append("\" name=\"");
        appendParameterIdent(buffer, ri);
        buffer.append("\" type=\"text\" size=\"").append(columns).append("\" maxlength=\"").append(maxlength);
        if (iinput != null && !iinput.isEmpty() && iinput.getSingle(responseIdent) != null) {
          buffer.append("\" value=\"").append(iinput.getSingle(getQTIIdent())); //TODO: LD: must this value be escapeHtml?         
        }
        buffer.append("\" onchange=\"return setFormDirty('ofo_iq_item')\" onclick=\"return setFormDirty('ofo_iq_item')\" />&nbsp;");
      }
    }
    Integer flowLabelClass = (Integer) ri.get(RenderInstructions.KEY_FLOW_LABEL);
View Full Code Here

   * <!ATTLIST vargte  %I_RespIdent;
                   %I_Index; >
   * e.g. <vargte respident = "NUM01">3.141</vargte>
   */
  public boolean eval(Element boolElement, ItemContext userContext, EvalContext ect) {
    ItemInput iinp = userContext.getItemInput();
    if (iinp.isEmpty()) return false; // user has given no answer   
    String respident = boolElement.attributeValue("respident");
    String shouldVal = boolElement.getText(); // the answer is tested against content of elem.
    String isVal = iinp.getSingle(respident);
    // the isVal and shouldVal must be numeric
    // we use Float so we are on the safe side, even if comparison was only Integer
    shouldVal = shouldVal.trim();
    isVal = isVal.trim();
    Float fs = new Float(shouldVal);
View Full Code Here

   *  <!ATTLIST varequal  %I_Case; %I_RespIdent; %I_Index; >
   * mit I_Case = case  (Yes | No 'No'
   * e.g. <varequal respident = "LID01">A</varequal>
   */
  public boolean eval(Element boolElement, ItemContext userContext, EvalContext ect) {
    ItemInput iinp = userContext.getItemInput();
    if (iinp.isEmpty()) return false; // user has given no answer
    String respident = boolElement.attributeValue("respident");
    String yescase = boolElement.attributeValue("case");
    boolean caseimp = (yescase == null) ? true : yescase.equals("Yes");   // make it compatible with faulty QTI documentation
    String shouldVal = boolElement.getText(); // the answer is tested against content of elem.
    boolean ok = (caseimp ? iinp.contains(respident,shouldVal) : iinp.containsIgnoreCase(respident,shouldVal));
    return ok;
  }
View Full Code Here

   * @param ect
   * @return
   */
  public boolean eval(Element boolElement, ItemContext userContext, EvalContext ect) {
    boolean ok = false;
    ItemInput iinp = userContext.getItemInput();
    if (iinp.isEmpty()) return false; // user has given no answer
    String respident = boolElement.attributeValue("respident");
    String shouldVal = boolElement.getText(); // the answer is tested against
                                              // content of elem.
    String isVal = iinp.getSingle(respident);
    // the isVal and shouldVal must be numeric
    // we use Float so we are on the safe side, even if comparison was only
    // Integer
    shouldVal = shouldVal.trim();
    isVal = isVal.trim();
View Full Code Here

          String respName = resp.getName();
          String type = respName.substring(respName.indexOf("_") + 1);
          res_responseform.addAttribute("response_type", type);

          // add user answer
          ItemInput itemInp = itemc.getItemInput();
          Translator trans = Util.createPackageTranslator(QTIModule.class, locale);
          if (itemInp == null) { // user did not answer this question at all
            res_response.addElement("response_value").addText(trans.translate("ResBuilder.NoAnswer"));
          } else {
            List userAnswer = itemInp.getAsList(ident);
            if (userAnswer == null) { // user did not answer this question at
                                      // all
              res_response.addElement("response_value").addText(trans.translate("ResBuilder.NoAnswer"));
            } else { // the user chose at least one option of an answer (did not
                     // simply click send)
View Full Code Here

TOP

Related Classes of org.olat.ims.qti.container.ItemInput

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.