Elgg  Version master
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 {
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 }
$guid
Reset an ElggUpgrade.
Definition: reset.php:6
return[ 'admin/delete_admin_notices'=>['access'=> 'admin'], 'admin/menu/save'=>['access'=> 'admin'], 'admin/plugins/activate'=>['access'=> 'admin'], 'admin/plugins/activate_all'=>['access'=> 'admin'], 'admin/plugins/deactivate'=>['access'=> 'admin'], 'admin/plugins/deactivate_all'=>['access'=> 'admin'], 'admin/plugins/set_priority'=>['access'=> 'admin'], 'admin/security/security_txt'=>['access'=> 'admin'], 'admin/security/settings'=>['access'=> 'admin'], 'admin/security/regenerate_site_secret'=>['access'=> 'admin'], 'admin/site/cache/invalidate'=>['access'=> 'admin'], 'admin/site/flush_cache'=>['access'=> 'admin'], 'admin/site/icons'=>['access'=> 'admin'], 'admin/site/set_maintenance_mode'=>['access'=> 'admin'], 'admin/site/set_robots'=>['access'=> 'admin'], 'admin/site/theme'=>['access'=> 'admin'], 'admin/site/unlock_upgrade'=>['access'=> 'admin'], 'admin/site/settings'=>['access'=> 'admin'], 'admin/upgrade'=>['access'=> 'admin'], 'admin/upgrade/reset'=>['access'=> 'admin'], 'admin/user/ban'=>['access'=> 'admin'], 'admin/user/bulk/ban'=>['access'=> 'admin'], 'admin/user/bulk/delete'=>['access'=> 'admin'], 'admin/user/bulk/unban'=>['access'=> 'admin'], 'admin/user/bulk/validate'=>['access'=> 'admin'], 'admin/user/change_email'=>['access'=> 'admin'], 'admin/user/delete'=>['access'=> 'admin'], 'admin/user/login_as'=>['access'=> 'admin'], 'admin/user/logout_as'=>[], 'admin/user/makeadmin'=>['access'=> 'admin'], 'admin/user/resetpassword'=>['access'=> 'admin'], 'admin/user/removeadmin'=>['access'=> 'admin'], 'admin/user/unban'=>['access'=> 'admin'], 'admin/user/validate'=>['access'=> 'admin'], 'annotation/delete'=>[], 'avatar/upload'=>[], 'comment/save'=>[], 'diagnostics/download'=>['access'=> 'admin'], 'entity/chooserestoredestination'=>[], 'entity/delete'=>[], 'entity/mute'=>[], 'entity/restore'=>[], 'entity/subscribe'=>[], 'entity/trash'=>[], 'entity/unmute'=>[], 'entity/unsubscribe'=>[], 'login'=>['access'=> 'logged_out'], 'logout'=>[], 'notifications/mute'=>['access'=> 'public'], 'plugins/settings/remove'=>['access'=> 'admin'], 'plugins/settings/save'=>['access'=> 'admin'], 'plugins/usersettings/save'=>[], 'register'=>['access'=> 'logged_out', 'middleware'=>[\Elgg\Router\Middleware\RegistrationAllowedGatekeeper::class,],], 'river/delete'=>[], 'settings/notifications'=>[], 'settings/notifications/subscriptions'=>[], 'user/changepassword'=>['access'=> 'public'], 'user/requestnewpassword'=>['access'=> 'public'], 'useradd'=>['access'=> 'admin'], 'usersettings/save'=>[], 'widgets/add'=>[], 'widgets/delete'=>[], 'widgets/move'=>[], 'widgets/save'=>[],]
Definition: actions.php:73
if($who_can_change_language==='nobody') elseif($who_can_change_language==='admin_only' &&!elgg_is_admin_logged_in()) $options
Definition: language.php:20
$relationship
Elgg default relationship view.
Definition: default.php:10
_elgg_services()
Get the global service provider.
Definition: elgglib.php:353
elgg_count_entities(array $options=[])
Returns a count of entities.
Definition: entities.php:518
elgg_get_entities(array $options=[])
Fetches/counts entities or performs a calculation on their properties.
Definition: entities.php:507