You are here

public function MatchingResponse::getFeedbackValues in Quiz 8.5

Same name and namespace in other branches
  1. 8.6 question_types/quiz_matching/src/Plugin/quiz/QuizQuestion/MatchingResponse.php \Drupal\quiz_matching\Plugin\quiz\QuizQuestion\MatchingResponse::getFeedbackValues()
  2. 6.x question_types/quiz_matching/src/Plugin/quiz/QuizQuestion/MatchingResponse.php \Drupal\quiz_matching\Plugin\quiz\QuizQuestion\MatchingResponse::getFeedbackValues()

Implementation of getFeedbackValues().

Overrides QuizResultAnswerEntityTrait::getFeedbackValues

See also

QuizQuestionResponse::getFeedbackValues()

File

question_types/quiz_matching/src/Plugin/quiz/QuizQuestion/MatchingResponse.php, line 80

Class

MatchingResponse
Extension of QuizQuestionResponse

Namespace

Drupal\quiz_matching\Plugin\quiz\QuizQuestion

Code

public function getFeedbackValues() {
  $data = array();
  $answers = $this
    ->getQuizQuestion()
    ->getCorrectAnswer();
  foreach ($this
    ->get('matching_user_answer')
    ->referencedEntities() as $pair) {
    if ($pair
      ->get('matching_user_answer')
      ->getValue()) {
      $response[$pair
        ->get('matching_user_question')
        ->getValue()[0]['target_revision_id']] = $pair
        ->get('matching_user_answer')
        ->getValue()[0]['target_revision_id'];
    }
  }
  foreach ($this
    ->getQuizQuestion()
    ->get('quiz_matching')
    ->referencedEntities() as $paragraph) {
    $vid = $paragraph
      ->getRevisionId();
    $data[] = array(
      'choice' => $paragraph
        ->get('matching_question')
        ->getString(),
      'attempt' => isset($response[$paragraph
        ->getRevisionId()]) && $answers[$response[$paragraph
        ->getRevisionId()]] ? $answers[$response[$paragraph
        ->getRevisionId()]]
        ->get('matching_answer')
        ->getString() : '',
      'correct' => ($response[$vid] ?? -1) == $vid ? \Drupal\quiz\Util\QuizUtil::icon('correct') : \Drupal\quiz\Util\QuizUtil::icon('incorrect'),
      'score' => ($response[$vid] ?? -1) == $vid ? 1 : !empty($response[$vid]) && $this
        ->getQuizQuestion()
        ->get('choice_penalty')
        ->getString() ? -1 : 0,
      'answer_feedback' => 'placeholder',
      // @todo: $answer->get('matching_feedback')->getString(),
      'solution' => $paragraph
        ->get('matching_answer')
        ->getString(),
    );
  }
  return $data;
}