You are here

public function SqlGroupGraphStorage::getGraph in Subgroup (Graph) 1.0.x

Get all relations between groups ordered by the number of hops.

Return value

array An array containing all relations between groups with the parent group as key and the child group as value.

Overrides GroupGraphStorageInterface::getGraph

File

src/Graph/SqlGroupGraphStorage.php, line 393

Class

SqlGroupGraphStorage
SQL based storage of the group relationship graph.

Namespace

Drupal\ggroup\Graph

Code

public function getGraph($group_id) {
  $query = $this->connection
    ->select('group_graph', 'gg')
    ->fields('gg', [
    'start_vertex',
    'end_vertex',
  ])
    ->orderBy('hops')
    ->orderBy('start_vertex');

  // This Or Group is identical to the one used in the query below.
  $or_group = $query
    ->orConditionGroup();
  $or_group
    ->condition('gg.start_vertex', $group_id)
    ->condition('gg.end_vertex', $group_id);

  // Add the Or Group.
  $query
    ->condition($or_group);
  return $query
    ->execute()
    ->fetchAll();
}