Elgg  Version 6.1
Relationships.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Elgg\Traits\Entity;
4 
10 trait Relationships {
11 
23  public function addRelationship(int $guid_two, string $relationship): bool {
24  $rel = new \ElggRelationship();
25  $rel->guid_one = $this->guid;
26  $rel->relationship = $relationship;
27  $rel->guid_two = $guid_two;
28 
29  return $rel->save();
30  }
31 
43  public function hasRelationship(int $guid_two, string $relationship): bool {
44  return (bool) _elgg_services()->relationshipsTable->check($this->guid, $relationship, $guid_two);
45  }
46 
56  public function getRelationship(int $guid_two, string $relationship): ?\ElggRelationship {
57  return _elgg_services()->relationshipsTable->check($this->guid, $relationship, $guid_two) ?: null;
58  }
59 
70  public function getEntitiesFromRelationship(array $options = []) {
71  $options['relationship_guid'] = $this->guid;
73  }
74 
83  public function countEntitiesFromRelationship(string $relationship, bool $inverse_relationship = false): int {
84  return elgg_count_entities([
85  'relationship' => $relationship,
86  'relationship_guid' => $this->guid,
87  'inverse_relationship' => $inverse_relationship,
88  ]);
89  }
90 
99  public function removeRelationship(int $guid_two, string $relationship): bool {
100  return _elgg_services()->relationshipsTable->remove($this->guid, $relationship, $guid_two);
101  }
102 
116  public function removeAllRelationships(string $relationship = '', bool $inverse_relationship = false): bool {
117  return _elgg_services()->relationshipsTable->removeAll($this->guid, $relationship, $inverse_relationship);
118  }
119 }
$relationship
Elgg default relationship view.
Definition: default.php:10
if($who_can_change_language=== 'nobody') elseif($who_can_change_language=== 'admin_only'&&!elgg_is_admin_logged_in()) $options
Definition: language.php:20
elgg_get_entities(array $options=[])
Fetches/counts entities or performs a calculation on their properties.
Definition: entities.php:507
elgg_count_entities(array $options=[])
Returns a count of entities.
Definition: entities.php:518
_elgg_services()
Get the global service provider.
Definition: elgglib.php:353
$guid
Reset an ElggUpgrade.
Definition: reset.php:6