original_string: public function process_redo_question($slot, $timestamp) {
          global $DB;
  
          if (!$this->can_question_be_redone_now($slot)) {
              throw new coding_exception('Attempt to restart the question in slot ' . $slot .
                      ' when it is not in a state to be restarted.');
          }
  
          $qubaids = new \mod_quiz\question\qubaids_for_users_attempts(
                  $this->get_quizid(), $this->get_userid());
  
          $transaction = $DB->start_delegated_transaction();
  
          // Choose the replacement question.
          $questiondata = $DB->get_record('question',
                  array('id' => $this->slots[$slot]->questionid));
          if ($questiondata->qtype != 'random') {
              $newqusetionid = $questiondata->id;
          } else {
              $tagids = quiz_retrieve_slot_tag_ids($this->slots[$slot]->id);
  
              $randomloader = new \core_question\bank\random_question_loader($qubaids, array());
              $newqusetionid = $randomloader->get_next_question_id($questiondata->category,
                      (bool) $questiondata->questiontext, $tagids);
              if ($newqusetionid === null) {
                  throw new moodle_exception('notenoughrandomquestions', 'quiz',
                          $this->quizobj->view_url(), $questiondata);
              }
          }
  
          // Add the question to the usage. It is important we do this before we choose a variant.
          $newquestion = question_bank::load_question($newqusetionid);
          $newslot = $this->quba->add_question_in_place_of_other($slot, $newquestion);
  
          // Choose the variant.
          if ($newquestion->get_num_variants() == 1) {
              $variant = 1;
          } else {
              $variantstrategy = new core_question\engine\variants\least_used_strategy(
                      $this->quba, $qubaids);
              $variant = $variantstrategy->choose_variant($newquestion->get_num_variants(),
                      $newquestion->get_variants_selection_seed());
          }
  
          // Start the question.
          $this->quba->start_question($slot, $variant);
          $this->quba->set_max_mark($newslot, 0);
          $this->quba->set_question_attempt_metadata($newslot, 'originalslot', $slot);
          question_engine::save_questions_usage_by_activity($this->quba);
  
          $transaction->allow_commit();
      }
code: public function process_redo_question($slot, $timestamp) {
          global $DB;
  
          if (!$this->can_question_be_redone_now($slot)) {
              throw new coding_exception('Attempt to restart the question in slot ' . $slot .
                      ' when it is not in a state to be restarted.');
          }
  
          $qubaids = new \mod_quiz\question\qubaids_for_users_attempts(
                  $this->get_quizid(), $this->get_userid());
  
          $transaction = $DB->start_delegated_transaction();
  
          // Choose the replacement question.
          $questiondata = $DB->get_record('question',
                  array('id' => $this->slots[$slot]->questionid));
          if ($questiondata->qtype != 'random') {
              $newqusetionid = $questiondata->id;
          } else {
              $tagids = quiz_retrieve_slot_tag_ids($this->slots[$slot]->id);
  
              $randomloader = new \core_question\bank\random_question_loader($qubaids, array());
              $newqusetionid = $randomloader->get_next_question_id($questiondata->category,
                      (bool) $questiondata->questiontext, $tagids);
              if ($newqusetionid === null) {
                  throw new moodle_exception('notenoughrandomquestions', 'quiz',
                          $this->quizobj->view_url(), $questiondata);
              }
          }
  
          // Add the question to the usage. It is important we do this before we choose a variant.
          $newquestion = question_bank::load_question($newqusetionid);
          $newslot = $this->quba->add_question_in_place_of_other($slot, $newquestion);
  
          // Choose the variant.
          if ($newquestion->get_num_variants() == 1) {
              $variant = 1;
          } else {
              $variantstrategy = new core_question\engine\variants\least_used_strategy(
                      $this->quba, $qubaids);
              $variant = $variantstrategy->choose_variant($newquestion->get_num_variants(),
                      $newquestion->get_variants_selection_seed());
          }
  
          // Start the question.
          $this->quba->start_question($slot, $variant);
          $this->quba->set_max_mark($newslot, 0);
          $this->quba->set_question_attempt_metadata($newslot, 'originalslot', $slot);
          question_engine::save_questions_usage_by_activity($this->quba);
  
          $transaction->allow_commit();
      }
code_tokens: public function process_redo_question ( $ slot , $ timestamp ) { global $ DB ; if ( ! $ this -> can_question_be_redone_now ( $ slot ) ) { throw new coding_exception ( 'Attempt to restart the question in slot ' . $ slot . ' when it is not in a state to be restarted.' ) ; } $ qubaids = new \ mod_quiz \ question \ qubaids_for_users_attempts ( $ this -> get_quizid ( ) , $ this -> get_userid ( ) ) ; $ transaction = $ DB -> start_delegated_transaction ( ) ; // Choose the replacement question. $ questiondata = $ DB -> get_record ( 'question' , array ( 'id' => $ this -> slots [ $ slot ] -> questionid ) ) ; if ( $ questiondata -> qtype != 'random' ) { $ newqusetionid = $ questiondata -> id ; } else { $ tagids = quiz_retrieve_slot_tag_ids ( $ this -> slots [ $ slot ] -> id ) ; $ randomloader = new \ core_question \ bank \ random_question_loader ( $ qubaids , array ( ) ) ; $ newqusetionid = $ randomloader -> get_next_question_id ( $ questiondata -> category , ( bool ) $ questiondata -> questiontext , $ tagids ) ; if ( $ newqusetionid === null ) { throw new moodle_exception ( 'notenoughrandomquestions' , 'quiz' , $ this -> quizobj -> view_url ( ) , $ questiondata ) ; } } // Add the question to the usage. It is important we do this before we choose a variant. $ newquestion = question_bank :: load_question ( $ newqusetionid ) ; $ newslot = $ this -> quba -> add_question_in_place_of_other ( $ slot , $ newquestion ) ; // Choose the variant. if ( $ newquestion -> get_num_variants ( ) == 1 ) { $ variant = 1 ; } else { $ variantstrategy = new core_question \ engine \ variants \ least_used_strategy ( $ this -> quba , $ qubaids ) ; $ variant = $ variantstrategy -> choose_variant ( $ newquestion -> get_num_variants ( ) , $ newquestion -> get_variants_selection_seed ( ) ) ; } // Start the question. $ this -> quba -> start_question ( $ slot , $ variant ) ; $ this -> quba -> set_max_mark ( $ newslot , 0 ) ; $ this -> quba -> set_question_attempt_metadata ( $ newslot , 'originalslot' , $ slot ) ; question_engine :: save_questions_usage_by_activity ( $ this -> quba ) ; $ transaction -> allow_commit ( ) ; }
docstring: Replace a question in an attempt with a new attempt at the same qestion.
  @param int $slot the questoin to restart.
  @param int $timestamp the timestamp to record for this action.
docstring_tokens: Replace a question in an attempt with a new attempt at the same qestion .