Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-8671

Check full 100% grade attached to minimum one answer in SHORTANSWER question edit mode

    XMLWordPrintable

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 1.8
    • Fix Version/s: 1.8, 1.9
    • Component/s: Questions
    • Labels:
      None
    • Affected Branches:
      MOODLE_18_STABLE
    • Fixed Branches:
      MOODLE_18_STABLE, MOODLE_19_STABLE

      Description

      In 1.8 a new checking mechanism is available to questions editing.

      However, in the SHORTANSWER question type, this mechanism does not check that the teacher has assigned a 100% grade value to at least one of the answers. The checking mechanism from previous Moodle versions is used instead, which looks obsolete and not so efficient.

      I suggest the following small changes in question/type/shortanswer/edit_shortanswer_form.php.

      Replace:
      function validation($data){
      $errors = array();
      $answers = $data['answer'];
      $answercount = 0;
      foreach ($answers as $answer){
      $trimmedanswer = trim($answer);
      if (!empty($trimmedanswer))

      { $answercount++; }
      }
      if ($answercount==0){ $errors['answer[0]'] = get_string('notenoughanswers', 'quiz', 1); }
      return $errors;
      }
      --------------------------------------------------
      with:
      --------------------------------------------------
      function validation($data){
      $errors = array();
      $answers = $data['answer'];
      $answercount = 0;
      $maxgrade = false;
      foreach ($answers as $key => $answer){
      $trimmedanswer = trim($answer);
      if (!empty($trimmedanswer)){ $answercount++; }

      //check grades
      if ($answer != '') {
      if ($data['fraction'][$key] == 1)

      { $maxgrade = true; }

      }
      }
      if ($answercount==0)

      { $errors['answer[0]'] = get_string('notenoughanswers', 'quiz', 1); }

      if ($maxgrade == false)

      { $errors['fraction[0]'] = "One of the answers should be 100%, so that it is possible to get a full grade for this question."; }

      return $errors;
      }

      Of course, the hard-coded error message "One of the answers etc." should be replaced by getting the appropriate message from language file (i.e. a slightly modified version of the Moodle 1.7 version $string['fractionsnomax'].

      Joseph

        Attachments

          Activity

            People

            Assignee:
            timhunt Tim Hunt
            Reporter:
            rezeau Joseph Rézeau
            Tester:
            Jérôme Mouneyrac
            Participants:
            Component watchers:
            Tim Hunt, Andrew Nicols, Jun Pataleta, Michael Hawkins, Shamim Rezaie, Simey Lameze
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:
              Fix Release Date:
              31/Mar/07