original_string: public function remove_slot($slotnumber) {
          global $DB;
  
          $this->check_can_be_edited();
  
          if ($this->is_only_slot_in_section($slotnumber) && $this->get_section_count() > 1) {
              throw new \coding_exception('You cannot remove the last slot in a section.');
          }
  
          $slot = $DB->get_record('quiz_slots', array('quizid' => $this->get_quizid(), 'slot' => $slotnumber));
          if (!$slot) {
              return;
          }
          $maxslot = $DB->get_field_sql('SELECT MAX(slot) FROM {quiz_slots} WHERE quizid = ?', array($this->get_quizid()));
  
          $trans = $DB->start_delegated_transaction();
          $DB->delete_records('quiz_slot_tags', array('slotid' => $slot->id));
          $DB->delete_records('quiz_slots', array('id' => $slot->id));
          for ($i = $slot->slot + 1; $i <= $maxslot; $i++) {
              $DB->set_field('quiz_slots', 'slot', $i - 1,
                      array('quizid' => $this->get_quizid(), 'slot' => $i));
          }
  
          $qtype = $DB->get_field('question', 'qtype', array('id' => $slot->questionid));
          if ($qtype === 'random') {
              // This function automatically checks if the question is in use, and won't delete if it is.
              question_delete_question($slot->questionid);
          }
  
          quiz_update_section_firstslots($this->get_quizid(), -1, $slotnumber);
          unset($this->questions[$slot->questionid]);
  
          $this->refresh_page_numbers_and_update_db();
  
          $trans->allow_commit();
      }
code: public function remove_slot($slotnumber) {
          global $DB;
  
          $this->check_can_be_edited();
  
          if ($this->is_only_slot_in_section($slotnumber) && $this->get_section_count() > 1) {
              throw new \coding_exception('You cannot remove the last slot in a section.');
          }
  
          $slot = $DB->get_record('quiz_slots', array('quizid' => $this->get_quizid(), 'slot' => $slotnumber));
          if (!$slot) {
              return;
          }
          $maxslot = $DB->get_field_sql('SELECT MAX(slot) FROM {quiz_slots} WHERE quizid = ?', array($this->get_quizid()));
  
          $trans = $DB->start_delegated_transaction();
          $DB->delete_records('quiz_slot_tags', array('slotid' => $slot->id));
          $DB->delete_records('quiz_slots', array('id' => $slot->id));
          for ($i = $slot->slot + 1; $i <= $maxslot; $i++) {
              $DB->set_field('quiz_slots', 'slot', $i - 1,
                      array('quizid' => $this->get_quizid(), 'slot' => $i));
          }
  
          $qtype = $DB->get_field('question', 'qtype', array('id' => $slot->questionid));
          if ($qtype === 'random') {
              // This function automatically checks if the question is in use, and won't delete if it is.
              question_delete_question($slot->questionid);
          }
  
          quiz_update_section_firstslots($this->get_quizid(), -1, $slotnumber);
          unset($this->questions[$slot->questionid]);
  
          $this->refresh_page_numbers_and_update_db();
  
          $trans->allow_commit();
      }
code_tokens: public function remove_slot ( $ slotnumber ) { global $ DB ; $ this -> check_can_be_edited ( ) ; if ( $ this -> is_only_slot_in_section ( $ slotnumber ) && $ this -> get_section_count ( ) > 1 ) { throw new \ coding_exception ( 'You cannot remove the last slot in a section.' ) ; } $ slot = $ DB -> get_record ( 'quiz_slots' , array ( 'quizid' => $ this -> get_quizid ( ) , 'slot' => $ slotnumber ) ) ; if ( ! $ slot ) { return ; } $ maxslot = $ DB -> get_field_sql ( 'SELECT MAX(slot) FROM {quiz_slots} WHERE quizid = ?' , array ( $ this -> get_quizid ( ) ) ) ; $ trans = $ DB -> start_delegated_transaction ( ) ; $ DB -> delete_records ( 'quiz_slot_tags' , array ( 'slotid' => $ slot -> id ) ) ; $ DB -> delete_records ( 'quiz_slots' , array ( 'id' => $ slot -> id ) ) ; for ( $ i = $ slot -> slot + 1 ; $ i <= $ maxslot ; $ i ++ ) { $ DB -> set_field ( 'quiz_slots' , 'slot' , $ i - 1 , array ( 'quizid' => $ this -> get_quizid ( ) , 'slot' => $ i ) ) ; } $ qtype = $ DB -> get_field ( 'question' , 'qtype' , array ( 'id' => $ slot -> questionid ) ) ; if ( $ qtype === 'random' ) { // This function automatically checks if the question is in use, and won't delete if it is. question_delete_question ( $ slot -> questionid ) ; } quiz_update_section_firstslots ( $ this -> get_quizid ( ) , - 1 , $ slotnumber ) ; unset ( $ this -> questions [ $ slot -> questionid ] ) ; $ this -> refresh_page_numbers_and_update_db ( ) ; $ trans -> allow_commit ( ) ; }
docstring: Remove a slot from a quiz
  @param int $slotnumber The number of the slot to be deleted.
docstring_tokens: Remove a slot from a quiz