original_string: public function prepare_simulated_post_data($simulatedresponses) {
          $simulatedpostdata = array();
          $simulatedpostdata['slots'] = implode(',', array_keys($simulatedresponses));
          foreach ($simulatedresponses as $slot => $responsedata) {
              $slotresponse = array();
  
              // Behaviour vars should not be processed by question type, just add prefix.
              $behaviourvars = $this->get_question_attempt($slot)->get_behaviour()->get_expected_data();
              foreach (array_keys($responsedata) as $responsedatakey) {
                  if ($responsedatakey{0} === '-') {
                      $behaviourvarname = substr($responsedatakey, 1);
                      if (isset($behaviourvars[$behaviourvarname])) {
                          // Expected behaviour var found.
                          if ($responsedata[$responsedatakey]) {
                              // Only set the behaviour var if the column value from the cvs file is non zero.
                              // The behaviours only look at whether the var is set or not they don't look at the value.
                              $slotresponse[$responsedatakey] = $responsedata[$responsedatakey];
                          }
                      }
                      // Remove both expected and unexpected vars from data passed to question type.
                      unset($responsedata[$responsedatakey]);
                  }
              }
  
              $slotresponse += $this->get_question($slot)->prepare_simulated_post_data($responsedata);
              $slotresponse[':sequencecheck'] = $this->get_question_attempt($slot)->get_sequence_check_count();
  
              // Add this slot's prefix to slot data.
              $prefix = $this->get_field_prefix($slot);
              foreach ($slotresponse as $key => $value) {
                  $simulatedpostdata[$prefix.$key] = $value;
              }
          }
          return $simulatedpostdata;
      }
code: public function prepare_simulated_post_data($simulatedresponses) {
          $simulatedpostdata = array();
          $simulatedpostdata['slots'] = implode(',', array_keys($simulatedresponses));
          foreach ($simulatedresponses as $slot => $responsedata) {
              $slotresponse = array();
  
              // Behaviour vars should not be processed by question type, just add prefix.
              $behaviourvars = $this->get_question_attempt($slot)->get_behaviour()->get_expected_data();
              foreach (array_keys($responsedata) as $responsedatakey) {
                  if ($responsedatakey{0} === '-') {
                      $behaviourvarname = substr($responsedatakey, 1);
                      if (isset($behaviourvars[$behaviourvarname])) {
                          // Expected behaviour var found.
                          if ($responsedata[$responsedatakey]) {
                              // Only set the behaviour var if the column value from the cvs file is non zero.
                              // The behaviours only look at whether the var is set or not they don't look at the value.
                              $slotresponse[$responsedatakey] = $responsedata[$responsedatakey];
                          }
                      }
                      // Remove both expected and unexpected vars from data passed to question type.
                      unset($responsedata[$responsedatakey]);
                  }
              }
  
              $slotresponse += $this->get_question($slot)->prepare_simulated_post_data($responsedata);
              $slotresponse[':sequencecheck'] = $this->get_question_attempt($slot)->get_sequence_check_count();
  
              // Add this slot's prefix to slot data.
              $prefix = $this->get_field_prefix($slot);
              foreach ($slotresponse as $key => $value) {
                  $simulatedpostdata[$prefix.$key] = $value;
              }
          }
          return $simulatedpostdata;
      }
code_tokens: public function prepare_simulated_post_data ( $ simulatedresponses ) { $ simulatedpostdata = array ( ) ; $ simulatedpostdata [ 'slots' ] = implode ( ',' , array_keys ( $ simulatedresponses ) ) ; foreach ( $ simulatedresponses as $ slot => $ responsedata ) { $ slotresponse = array ( ) ; // Behaviour vars should not be processed by question type, just add prefix. $ behaviourvars = $ this -> get_question_attempt ( $ slot ) -> get_behaviour ( ) -> get_expected_data ( ) ; foreach ( array_keys ( $ responsedata ) as $ responsedatakey ) { if ( $ responsedatakey { 0 } === '-' ) { $ behaviourvarname = substr ( $ responsedatakey , 1 ) ; if ( isset ( $ behaviourvars [ $ behaviourvarname ] ) ) { // Expected behaviour var found. if ( $ responsedata [ $ responsedatakey ] ) { // Only set the behaviour var if the column value from the cvs file is non zero. // The behaviours only look at whether the var is set or not they don't look at the value. $ slotresponse [ $ responsedatakey ] = $ responsedata [ $ responsedatakey ] ; } } // Remove both expected and unexpected vars from data passed to question type. unset ( $ responsedata [ $ responsedatakey ] ) ; } } $ slotresponse += $ this -> get_question ( $ slot ) -> prepare_simulated_post_data ( $ responsedata ) ; $ slotresponse [ ':sequencecheck' ] = $ this -> get_question_attempt ( $ slot ) -> get_sequence_check_count ( ) ; // Add this slot's prefix to slot data. $ prefix = $ this -> get_field_prefix ( $ slot ) ; foreach ( $ slotresponse as $ key => $ value ) { $ simulatedpostdata [ $ prefix . $ key ] = $ value ; } } return $ simulatedpostdata ; }
docstring: Transform an array of response data for slots to an array of post data as you would get from quiz attempt form.
  
  @param $simulatedresponses array keys are slot nos => contains arrays representing student
  responses which will be passed to question_definition::prepare_simulated_post_data method
  and then have the appropriate prefix added.
  @return array simulated post data
docstring_tokens: Transform an array of response data for slots to an array of post data as you would get from quiz attempt form .