You are here

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

Relates the parent group and the child group.

Inferred relationships based on existing relationships to the parent group and the child group will also be created.

Parameters

int $parent_group_id: The ID of the parent group.

int $child_group_id: The ID of the child group.

Return value

int|false The ID of the graph edge relating the parent group to the child group or FALSE if the relationship could not be created.

Overrides GroupGraphStorageInterface::addEdge

File

src/Graph/SqlGroupGraphStorage.php, line 412

Class

SqlGroupGraphStorage
SQL based storage of the group relationship graph.

Namespace

Drupal\ggroup\Graph

Code

public function addEdge($parent_group_id, $child_group_id) {
  if ($parent_group_id === $child_group_id) {
    return FALSE;
  }
  $parent_child_edge_id = $this
    ->getEdgeId($parent_group_id, $child_group_id);
  if (!empty($parent_child_edge_id)) {
    return $parent_child_edge_id;
  }
  $child_parent_edge_id = $this
    ->getEdgeId($parent_group_id, $child_group_id);
  if (!empty($child_parent_edge_id)) {
    return $child_parent_edge_id;
  }
  if ($this
    ->isDescendant($parent_group_id, $child_group_id)) {
    throw new CyclicGraphException($parent_group_id, $child_group_id);
  }
  $new_edge_id = $this
    ->insertEdge($parent_group_id, $child_group_id);
  $this
    ->insertEdgesParentIncomingToChild($new_edge_id, $parent_group_id, $child_group_id);
  $this
    ->insertEdgesParentToChildOutgoing($new_edge_id, $parent_group_id, $child_group_id);
  $this
    ->insertEdgesParentIncomingToChildOutgoing($new_edge_id, $parent_group_id, $child_group_id);
  $this
    ->invalidate([
    $parent_group_id,
    $child_group_id,
  ]);
  return $new_edge_id;
}