original_string: public function recode_legacy_state_answer($state) {
          global $DB;
          $answer = $state->answer;
          $resultarr = array();
          // Get sequence of questions.
          $sequence = $DB->get_field('question_multianswer', 'sequence',
                  array('question' => $state->question));
          $sequencearr = explode(',', $sequence);
          // Let's process each pair.
          foreach (explode(',', $answer) as $pair) {
              $pairarr = explode('-', $pair);
              $sequenceid = $pairarr[0];
              $subanswer = $pairarr[1];
              // Calculate the questionid based on sequenceid.
              // Note it is already one *new* questionid that doesn't need mapping.
              $questionid = $sequencearr[$sequenceid - 1];
              // Fetch qtype of the question (needed for delegation).
              $questionqtype = $DB->get_field('question', 'qtype', array('id' => $questionid));
              // Delegate subanswer recode to proper qtype, faking one question_states record.
              $substate = new stdClass();
              $substate->question = $questionid;
              $substate->answer = $subanswer;
              $newanswer = $this->step->restore_recode_legacy_answer($substate, $questionqtype);
              $resultarr[] = implode('-', array($sequenceid, $newanswer));
          }
          return implode(',', $resultarr);
      }
code: public function recode_legacy_state_answer($state) {
          global $DB;
          $answer = $state->answer;
          $resultarr = array();
          // Get sequence of questions.
          $sequence = $DB->get_field('question_multianswer', 'sequence',
                  array('question' => $state->question));
          $sequencearr = explode(',', $sequence);
          // Let's process each pair.
          foreach (explode(',', $answer) as $pair) {
              $pairarr = explode('-', $pair);
              $sequenceid = $pairarr[0];
              $subanswer = $pairarr[1];
              // Calculate the questionid based on sequenceid.
              // Note it is already one *new* questionid that doesn't need mapping.
              $questionid = $sequencearr[$sequenceid - 1];
              // Fetch qtype of the question (needed for delegation).
              $questionqtype = $DB->get_field('question', 'qtype', array('id' => $questionid));
              // Delegate subanswer recode to proper qtype, faking one question_states record.
              $substate = new stdClass();
              $substate->question = $questionid;
              $substate->answer = $subanswer;
              $newanswer = $this->step->restore_recode_legacy_answer($substate, $questionqtype);
              $resultarr[] = implode('-', array($sequenceid, $newanswer));
          }
          return implode(',', $resultarr);
      }
code_tokens: public function recode_legacy_state_answer ( $ state ) { global $ DB ; $ answer = $ state -> answer ; $ resultarr = array ( ) ; // Get sequence of questions. $ sequence = $ DB -> get_field ( 'question_multianswer' , 'sequence' , array ( 'question' => $ state -> question ) ) ; $ sequencearr = explode ( ',' , $ sequence ) ; // Let's process each pair. foreach ( explode ( ',' , $ answer ) as $ pair ) { $ pairarr = explode ( '-' , $ pair ) ; $ sequenceid = $ pairarr [ 0 ] ; $ subanswer = $ pairarr [ 1 ] ; // Calculate the questionid based on sequenceid. // Note it is already one *new* questionid that doesn't need mapping. $ questionid = $ sequencearr [ $ sequenceid - 1 ] ; // Fetch qtype of the question (needed for delegation). $ questionqtype = $ DB -> get_field ( 'question' , 'qtype' , array ( 'id' => $ questionid ) ) ; // Delegate subanswer recode to proper qtype, faking one question_states record. $ substate = new stdClass ( ) ; $ substate -> question = $ questionid ; $ substate -> answer = $ subanswer ; $ newanswer = $ this -> step -> restore_recode_legacy_answer ( $ substate , $ questionqtype ) ; $ resultarr [ ] = implode ( '-' , array ( $ sequenceid , $ newanswer ) ) ; } return implode ( ',' , $ resultarr ) ; }
docstring: Given one question_states record, return the answer
  recoded pointing to all the restored stuff for multianswer questions
  
  answer is one comma separated list of hypen separated pairs
  containing sequence (pointing to questions sequence in question_multianswer)
  and mixed answers. We'll delegate
  the recoding of answers to the proper qtype
docstring_tokens: Given one question_states record return the answer recoded pointing to all the restored stuff for multianswer questions