You are here

private function SqlGroupGraphStorage::mergeMappings in Subgroup (Graph) 1.0.x

Merges a multi-dimentional mapping array with the existing mapping values.

Parameters

array $mapping: A multi-dimentional array of mappings keyed by the mapping relation.

Return value

$this

1 call to SqlGroupGraphStorage::mergeMappings()
SqlGroupGraphStorage::loadGroupMapping in src/Graph/SqlGroupGraphStorage.php
Fetch the records from graph for the provided group and cache them.

File

src/Graph/SqlGroupGraphStorage.php, line 195

Class

SqlGroupGraphStorage
SQL based storage of the group relationship graph.

Namespace

Drupal\ggroup\Graph

Code

private function mergeMappings(array $mapping) {
  if (!empty($mapping)) {

    // Loop through all the relations from the fetched mapping.
    foreach ($mapping as $relation => $relatives) {

      // Don't bother proceeding if there is nothing to map.
      if (!empty($relatives)) {

        // Grab the root mappings value for this relation.
        ($rootRelation =& $this->{$relation}) ?: [];

        // Merge each value of the relation with root.
        foreach ($relatives as $parentGid => $groupMap) {

          // Convert the map to an associative array so it merges cleanly.
          $groupMap = array_combine($groupMap, $groupMap);

          // Merge new and root mappings.
          if (!empty($rootRelation[$parentGid])) {
            $rootRelation[$parentGid] = $rootRelation[$parentGid] + $groupMap;
          }
          else {
            $rootRelation[$parentGid] = $groupMap;
          }
        }
      }
    }
  }
  return $this;
}