You are here

private function FillInProcessor::getPlaceholderReplacements in Opigno module 8

Same name and namespace in other branches
  1. 3.x ActivityTypes/opigno_h5p/src/TypeProcessors/FillInProcessor.php \Drupal\opigno_h5p\TypeProcessors\FillInProcessor::getPlaceholderReplacements()

Process correct responses patterns and user responses.

Format them to replace placeholders in description.

Parameters

array $crp: Correct responses patterns.

array $response: User responses.

bool $caseSensitive: Case sensitivity of interaction.

Return value

array Placeholder replacements.

1 call to FillInProcessor::getPlaceholderReplacements()
FillInProcessor::buildReportOutput in ActivityTypes/opigno_h5p/src/TypeProcessors/FillInProcessor.php
Build report.

File

ActivityTypes/opigno_h5p/src/TypeProcessors/FillInProcessor.php, line 215

Class

FillInProcessor
Class FillInProcessor.

Namespace

Drupal\opigno_h5p\TypeProcessors

Code

private function getPlaceholderReplacements(array $crp, array $response, $caseSensitive) {
  $placeholderReplacements = [];
  foreach ($crp as $index => $value) {
    $currentResponse = isset($response[$index]) ? $response[$index] : '';

    // Determine user response styling.
    $isCorrect = $this
      ->isResponseCorrect($currentResponse, $value, $caseSensitive);
    $responseClass = $isCorrect ? 'h5p-fill-in-user-response-correct' : 'h5p-fill-in-user-response-wrong';

    // Format the placeholder replacements.
    $userResponse = '<span class="h5p-fill-in-user-response ' . $responseClass . '">' . $currentResponse . '</span>';
    $CRPhtml = $this
      ->getCRPHtml($value, $currentResponse, $caseSensitive);
    $correctResponsePattern = '';
    if (strlen($CRPhtml) > 0) {
      $correctResponsePattern .= '<span class="h5p-fill-in-correct-responses-pattern">' . $CRPhtml . '</span>';
    }
    $placeholderReplacements[] = $userResponse . $correctResponsePattern;
  }
  return $placeholderReplacements;
}