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

Saving an existing question should not require the $form->categorymoveto parameter

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 1.9.3
    • Fix Version/s: 1.9.5
    • Component/s: Questions
    • Labels:
      None
    • Affected Branches:
      MOODLE_19_STABLE
    • Fixed Branches:
      MOODLE_19_STABLE

      Description

      In the actual question/type/questiontype.php save_question function
      the code is
      if (!empty($question->id) && !empty($form->categorymoveto)) { // Question already exists
      list($movetocategory, $movetocontextid) = explode(',', $form->categorymoveto);
      if ($movetocategory != $question->category)

      { question_require_capability_on($question, 'move'); $question->category = $movetocategory; //don't need to test add permission of category we are moving question to. //Only categories that we have permission to add //a question to will get through the form cleaning code for the select box. }

      // keep existing unique stamp code
      $question->stamp = get_field('question', 'stamp', 'id', $question->id);
      $question->modifiedby = $USER->id;
      $question->timemodified = time();
      if (!update_record('question', $question))

      { error('Could not update question!'); }

      } else { // Question is a new one
      if (isset($form->categorymoveto))

      { // Doing save as new question, and we have move rights. list($question->category, $notused) = explode(',', $form->categorymoveto); //don't need to test add permission of category we are moving question to. //Only categories that we have permission to add //a question to will get through the form cleaning code for the select box. }

      else

      { // Really a new question. list($question->category, $notused) = explode(',', $form->category); }

      // Set the unique code
      $question->stamp = make_unique_id_code();
      $question->createdby = $USER->id;
      $question->modifiedby = $USER->id;
      $question->timecreated = time();
      $question->timemodified = time();
      if (!$question->id = insert_record('question', $question))

      { print_object($question); error('Could not insert new question!'); }

      }
      If there is a call to save_question with an existing question i.e. !empty($question->id without the $form->categorymoveto parameter, this question will be considered as a new one.
      This is the case when saving multianswers subquestions when these subquestions already exist i.e. when modifying a multianswer.
      The multianswer case can be solved by adding a false categorymoveto parameter before calling the save_question.
      However I think that the code should be modified so that it takes in account the case when the save_question is not coming from a question_edit_form with a valid $form->categorymoveto.

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              timhunt Tim Hunt
              Reporter:
              ppichet Pierre Pichet
              Participants:
              Component watchers:
              Tim Hunt, Andrew Nicols, Jun Pataleta, Michael Hawkins, Shamim Rezaie, Simey Lameze
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Fix Release Date:
                13/May/09