original_string: public function process_matching($quest, &$questions) {
  
          // Blackboard matching questions can't be imported in core Moodle without a loss in data,
          // as core match question don't allow HTML in subanswers. The contributed ddmatch
          // question type support HTML in subanswers.
          // The ddmatch question type is not part of core, so we need to check if it is defined.
          $ddmatchisinstalled = question_bank::is_qtype_installed('ddmatch');
  
          $question = $this->process_common($quest);
          $question = $this->add_blank_combined_feedback($question);
          $question->valid = true;
          if ($ddmatchisinstalled) {
              $question->qtype = 'ddmatch';
          } else {
              $question->qtype = 'match';
          }
          // Construction of the array holding mappings between subanswers and subquestions.
          foreach ($quest->RESPONSE_BLOCK->subquestions as $qid => $subq) {
              foreach ($quest->responses as $rid => $resp) {
                  if (isset($resp->ident) && $resp->ident == $subq->ident) {
                      $correct = $resp->correct;
                  }
              }
  
              foreach ($subq->choices as $cid => $choice) {
                  if ($choice == $correct) {
                      $mappings[$subq->ident] = $cid;
                  }
              }
          }
  
          foreach ($subq->choices as $choiceid => $choice) {
              $subanswertext = $quest->RIGHT_MATCH_BLOCK->matchinganswerset[$choiceid]->text;
              if ($ddmatchisinstalled) {
                  $subanswer = $this->cleaned_text_field($subanswertext);
              } else {
                  $subanswertext = html_to_text($this->cleaninput($subanswertext), 0);
                  $subanswer = $subanswertext;
              }
  
              if ($subanswertext != '') { // Only import non empty subanswers.
                  $subquestion = '';
  
                  $fiber = array_keys ($mappings, $choiceid);
                  foreach ($fiber as $correctanswerid) {
                      // We have found a correspondance for this subanswer so we need to take the associated subquestion.
                      foreach ($quest->RESPONSE_BLOCK->subquestions as $qid => $subq) {
                          $currentsubqid = $subq->ident;
                          if (strcmp ($currentsubqid, $correctanswerid) == 0) {
                              $subquestion = $subq->text;
                              break;
                          }
                      }
                      $question->subquestions[] = $this->cleaned_text_field($subquestion);
                      $question->subanswers[] = $subanswer;
                  }
  
                  if ($subquestion == '') { // Then in this case, $choice is a distractor.
                      $question->subquestions[] = $this->text_field('');
                      $question->subanswers[] = $subanswer;
                  }
              }
          }
  
          // Verify that this matching question has enough subquestions and subanswers.
          $subquestioncount = 0;
          $subanswercount = 0;
          $subanswers = $question->subanswers;
          foreach ($question->subquestions as $key => $subquestion) {
              $subquestion = $subquestion['text'];
              $subanswer = $subanswers[$key];
              if ($subquestion != '') {
                  $subquestioncount++;
              }
              $subanswercount++;
          }
          if ($subquestioncount < 2 || $subanswercount < 3) {
                  $this->error(get_string('notenoughtsubans', 'qformat_blackboard_six', $question->questiontext));
          } else {
              $questions[] = $question;
          }
      }
code: public function process_matching($quest, &$questions) {
  
          // Blackboard matching questions can't be imported in core Moodle without a loss in data,
          // as core match question don't allow HTML in subanswers. The contributed ddmatch
          // question type support HTML in subanswers.
          // The ddmatch question type is not part of core, so we need to check if it is defined.
          $ddmatchisinstalled = question_bank::is_qtype_installed('ddmatch');
  
          $question = $this->process_common($quest);
          $question = $this->add_blank_combined_feedback($question);
          $question->valid = true;
          if ($ddmatchisinstalled) {
              $question->qtype = 'ddmatch';
          } else {
              $question->qtype = 'match';
          }
          // Construction of the array holding mappings between subanswers and subquestions.
          foreach ($quest->RESPONSE_BLOCK->subquestions as $qid => $subq) {
              foreach ($quest->responses as $rid => $resp) {
                  if (isset($resp->ident) && $resp->ident == $subq->ident) {
                      $correct = $resp->correct;
                  }
              }
  
              foreach ($subq->choices as $cid => $choice) {
                  if ($choice == $correct) {
                      $mappings[$subq->ident] = $cid;
                  }
              }
          }
  
          foreach ($subq->choices as $choiceid => $choice) {
              $subanswertext = $quest->RIGHT_MATCH_BLOCK->matchinganswerset[$choiceid]->text;
              if ($ddmatchisinstalled) {
                  $subanswer = $this->cleaned_text_field($subanswertext);
              } else {
                  $subanswertext = html_to_text($this->cleaninput($subanswertext), 0);
                  $subanswer = $subanswertext;
              }
  
              if ($subanswertext != '') { // Only import non empty subanswers.
                  $subquestion = '';
  
                  $fiber = array_keys ($mappings, $choiceid);
                  foreach ($fiber as $correctanswerid) {
                      // We have found a correspondance for this subanswer so we need to take the associated subquestion.
                      foreach ($quest->RESPONSE_BLOCK->subquestions as $qid => $subq) {
                          $currentsubqid = $subq->ident;
                          if (strcmp ($currentsubqid, $correctanswerid) == 0) {
                              $subquestion = $subq->text;
                              break;
                          }
                      }
                      $question->subquestions[] = $this->cleaned_text_field($subquestion);
                      $question->subanswers[] = $subanswer;
                  }
  
                  if ($subquestion == '') { // Then in this case, $choice is a distractor.
                      $question->subquestions[] = $this->text_field('');
                      $question->subanswers[] = $subanswer;
                  }
              }
          }
  
          // Verify that this matching question has enough subquestions and subanswers.
          $subquestioncount = 0;
          $subanswercount = 0;
          $subanswers = $question->subanswers;
          foreach ($question->subquestions as $key => $subquestion) {
              $subquestion = $subquestion['text'];
              $subanswer = $subanswers[$key];
              if ($subquestion != '') {
                  $subquestioncount++;
              }
              $subanswercount++;
          }
          if ($subquestioncount < 2 || $subanswercount < 3) {
                  $this->error(get_string('notenoughtsubans', 'qformat_blackboard_six', $question->questiontext));
          } else {
              $questions[] = $question;
          }
      }
code_tokens: public function process_matching ( $ quest , & $ questions ) { // Blackboard matching questions can't be imported in core Moodle without a loss in data, // as core match question don't allow HTML in subanswers. The contributed ddmatch // question type support HTML in subanswers. // The ddmatch question type is not part of core, so we need to check if it is defined. $ ddmatchisinstalled = question_bank :: is_qtype_installed ( 'ddmatch' ) ; $ question = $ this -> process_common ( $ quest ) ; $ question = $ this -> add_blank_combined_feedback ( $ question ) ; $ question -> valid = true ; if ( $ ddmatchisinstalled ) { $ question -> qtype = 'ddmatch' ; } else { $ question -> qtype = 'match' ; } // Construction of the array holding mappings between subanswers and subquestions. foreach ( $ quest -> RESPONSE_BLOCK -> subquestions as $ qid => $ subq ) { foreach ( $ quest -> responses as $ rid => $ resp ) { if ( isset ( $ resp -> ident ) && $ resp -> ident == $ subq -> ident ) { $ correct = $ resp -> correct ; } } foreach ( $ subq -> choices as $ cid => $ choice ) { if ( $ choice == $ correct ) { $ mappings [ $ subq -> ident ] = $ cid ; } } } foreach ( $ subq -> choices as $ choiceid => $ choice ) { $ subanswertext = $ quest -> RIGHT_MATCH_BLOCK -> matchinganswerset [ $ choiceid ] -> text ; if ( $ ddmatchisinstalled ) { $ subanswer = $ this -> cleaned_text_field ( $ subanswertext ) ; } else { $ subanswertext = html_to_text ( $ this -> cleaninput ( $ subanswertext ) , 0 ) ; $ subanswer = $ subanswertext ; } if ( $ subanswertext != '' ) { // Only import non empty subanswers. $ subquestion = '' ; $ fiber = array_keys ( $ mappings , $ choiceid ) ; foreach ( $ fiber as $ correctanswerid ) { // We have found a correspondance for this subanswer so we need to take the associated subquestion. foreach ( $ quest -> RESPONSE_BLOCK -> subquestions as $ qid => $ subq ) { $ currentsubqid = $ subq -> ident ; if ( strcmp ( $ currentsubqid , $ correctanswerid ) == 0 ) { $ subquestion = $ subq -> text ; break ; } } $ question -> subquestions [ ] = $ this -> cleaned_text_field ( $ subquestion ) ; $ question -> subanswers [ ] = $ subanswer ; } if ( $ subquestion == '' ) { // Then in this case, $choice is a distractor. $ question -> subquestions [ ] = $ this -> text_field ( '' ) ; $ question -> subanswers [ ] = $ subanswer ; } } } // Verify that this matching question has enough subquestions and subanswers. $ subquestioncount = 0 ; $ subanswercount = 0 ; $ subanswers = $ question -> subanswers ; foreach ( $ question -> subquestions as $ key => $ subquestion ) { $ subquestion = $ subquestion [ 'text' ] ; $ subanswer = $ subanswers [ $ key ] ; if ( $ subquestion != '' ) { $ subquestioncount ++ ; } $ subanswercount ++ ; } if ( $ subquestioncount < 2 || $ subanswercount < 3 ) { $ this -> error ( get_string ( 'notenoughtsubans' , 'qformat_blackboard_six' , $ question -> questiontext ) ) ; } else { $ questions [ ] = $ question ; } }
docstring: Process Matching Questions
  Parse a matching rawquestion and add the result
  to the array of questions already parsed.
  @param object $quest rawquestion
  @param array $questions array of Moodle questions already done.
docstring_tokens: Process Matching Questions Parse a matching rawquestion and add the result to the array of questions already parsed .