original_string: public function recode_legacy_state_answer($state) {
          $answer = $state->answer;
          $orderarr = array();
          $responsesarr = array();
          $lists = explode(':', $answer);
          // If only 1 list, answer is missing the order list, adjust.
          if (count($lists) == 1) {
              $lists[1] = $lists[0]; // Here we have the responses.
              $lists[0] = '';        // Here we have the order.
          }
          // Map order.
          if (!empty($lists[0])) {
              foreach (explode(',', $lists[0]) as $id) {
                  if ($newid = $this->get_mappingid('question_answer', $id)) {
                      $orderarr[] = $newid;
                  }
              }
          }
          // Map responses.
          if (!empty($lists[1])) {
              foreach (explode(',', $lists[1]) as $id) {
                  if ($newid = $this->get_mappingid('question_answer', $id)) {
                      $responsesarr[] = $newid;
                  }
              }
          }
          // Build the final answer, if not order, only responses.
          $result = '';
          if (empty($orderarr)) {
              $result = implode(',', $responsesarr);
          } else {
              $result = implode(',', $orderarr) . ':' . implode(',', $responsesarr);
          }
          return $result;
      }
code: public function recode_legacy_state_answer($state) {
          $answer = $state->answer;
          $orderarr = array();
          $responsesarr = array();
          $lists = explode(':', $answer);
          // If only 1 list, answer is missing the order list, adjust.
          if (count($lists) == 1) {
              $lists[1] = $lists[0]; // Here we have the responses.
              $lists[0] = '';        // Here we have the order.
          }
          // Map order.
          if (!empty($lists[0])) {
              foreach (explode(',', $lists[0]) as $id) {
                  if ($newid = $this->get_mappingid('question_answer', $id)) {
                      $orderarr[] = $newid;
                  }
              }
          }
          // Map responses.
          if (!empty($lists[1])) {
              foreach (explode(',', $lists[1]) as $id) {
                  if ($newid = $this->get_mappingid('question_answer', $id)) {
                      $responsesarr[] = $newid;
                  }
              }
          }
          // Build the final answer, if not order, only responses.
          $result = '';
          if (empty($orderarr)) {
              $result = implode(',', $responsesarr);
          } else {
              $result = implode(',', $orderarr) . ':' . implode(',', $responsesarr);
          }
          return $result;
      }
code_tokens: public function recode_legacy_state_answer ( $ state ) { $ answer = $ state -> answer ; $ orderarr = array ( ) ; $ responsesarr = array ( ) ; $ lists = explode ( ':' , $ answer ) ; // If only 1 list, answer is missing the order list, adjust. if ( count ( $ lists ) == 1 ) { $ lists [ 1 ] = $ lists [ 0 ] ; // Here we have the responses. $ lists [ 0 ] = '' ; // Here we have the order. } // Map order. if ( ! empty ( $ lists [ 0 ] ) ) { foreach ( explode ( ',' , $ lists [ 0 ] ) as $ id ) { if ( $ newid = $ this -> get_mappingid ( 'question_answer' , $ id ) ) { $ orderarr [ ] = $ newid ; } } } // Map responses. if ( ! empty ( $ lists [ 1 ] ) ) { foreach ( explode ( ',' , $ lists [ 1 ] ) as $ id ) { if ( $ newid = $ this -> get_mappingid ( 'question_answer' , $ id ) ) { $ responsesarr [ ] = $ newid ; } } } // Build the final answer, if not order, only responses. $ result = '' ; if ( empty ( $ orderarr ) ) { $ result = implode ( ',' , $ responsesarr ) ; } else { $ result = implode ( ',' , $ orderarr ) . ':' . implode ( ',' , $ responsesarr ) ; } return $ result ; }
docstring: Given one question_states record, return the answer
  recoded pointing to all the restored stuff for multichoice questions
  
  answer are two (hypen speparated) lists of comma separated question_answers
  the first to specify the order of the answers and the second to specify the
  responses. Note the order list (the first one) can be optional
docstring_tokens: Given one question_states record return the answer recoded pointing to all the restored stuff for multichoice questions