You are here

protected function SqlGroupGraphStorage::insertEdgesParentIncomingToChildOutgoing in Subgroup (Graph) 1.0.x

Insert the parent group incoming edges to the child group outgoing edges.

Parameters

int $edge_id: The existing edge ID relating the parent group to the child group.

int $parent_group_id: The ID of the parent group.

int $child_group_id: The ID of the child group.

1 call to SqlGroupGraphStorage::insertEdgesParentIncomingToChildOutgoing()
SqlGroupGraphStorage::addEdge in src/Graph/SqlGroupGraphStorage.php
Relates the parent group and the child group.

File

src/Graph/SqlGroupGraphStorage.php, line 363

Class

SqlGroupGraphStorage
SQL based storage of the group relationship graph.

Namespace

Drupal\ggroup\Graph

Code

protected function insertEdgesParentIncomingToChildOutgoing($edge_id, $parent_group_id, $child_group_id) {

  // Since fields are added before expressions, all fields are added as
  // expressions to keep the field order intact.
  $query = $this->connection
    ->select('group_graph', 'parent_gg');
  $query
    ->join('group_graph', 'child_gg', 'child_gg.end_vertex = parent_gg.start_vertex');
  $query
    ->addExpression('parent_gg.id', 'entry_edge_id');
  $query
    ->addExpression($edge_id, 'direct_edge_id');
  $query
    ->addExpression('child_gg.id', 'exit_edge_id');
  $query
    ->addExpression('parent_gg.start_vertex', 'start_vertex');
  $query
    ->addExpression('child_gg.end_vertex', 'end_vertex');
  $query
    ->addExpression('parent_gg.hops + child_gg.hops + 1', 'hops');
  $query
    ->condition('parent_gg.end_vertex', $parent_group_id);
  $query
    ->condition('child_gg.start_vertex', $child_group_id);
  $this->connection
    ->insert('group_graph')
    ->fields([
    'entry_edge_id',
    'direct_edge_id',
    'exit_edge_id',
    'start_vertex',
    'end_vertex',
    'hops',
  ])
    ->from($query)
    ->execute();
}