You are here

public function MatchingProcessor::mapPatternIDsToIndexes in Opigno module 3.x

Same name and namespace in other branches
  1. 8 ActivityTypes/opigno_h5p/src/TypeProcessors/MatchingProcessor.php \Drupal\opigno_h5p\TypeProcessors\MatchingProcessor::mapPatternIDsToIndexes()

Creates a map for IDs from pattern and droppable and draggable arrays.

Parameters

string $pattern: Pattern.

array $dropzoneIds: Dropzone Ids.

array $draggableIds: Draggable Ids.

Return value

array Pattern mapped to indexes instead of IDs.

1 call to MatchingProcessor::mapPatternIDsToIndexes()
MatchingProcessor::generateHTML in ActivityTypes/opigno_h5p/src/TypeProcessors/MatchingProcessor.php
Processes xAPI data and returns a human readable HTML report.

File

ActivityTypes/opigno_h5p/src/TypeProcessors/MatchingProcessor.php, line 93

Class

MatchingProcessor
Class MatchingProcessor.

Namespace

Drupal\opigno_h5p\TypeProcessors

Code

public function mapPatternIDsToIndexes($pattern, array $dropzoneIds, array $draggableIds) {
  $mappedMatches = [];
  if (empty($pattern)) {
    return $mappedMatches;
  }
  $singlePatterns = explode(self::EXPRESSION_SEPARATOR, $pattern);
  foreach ($singlePatterns as $singlePattern) {
    $matches = explode(self::MATCH_SEPARATOR, $singlePattern);

    // ID does not necessarily map to index, so we must remap it.
    $dropzoneId = $this
      ->findIndexOfItemWithId($dropzoneIds, $matches[0]);
    $draggableId = $this
      ->findIndexOfItemWithId($draggableIds, $matches[1]);
    if (!isset($mappedMatches[$dropzoneId])) {
      $mappedMatches[$dropzoneId] = [];
    }
    $mappedMatches[$dropzoneId][] = $draggableId;
  }
  return $mappedMatches;
}