Elgg  Version 4.3
Friends.php
Go to the documentation of this file.
1 <?php
2 
4 
10 trait Friends {
11 
20  public function addFriend(int $friend_guid, bool $create_river_item = false) {
21  if (!get_user($friend_guid)) {
22  return false;
23  }
24 
25  if (!$this->addRelationship($friend_guid, 'friend')) {
26  return false;
27  }
28 
29  if ($create_river_item) {
31  'view' => 'river/relationship/friend/create',
32  'action_type' => 'friend',
33  'subject_guid' => $this->guid,
34  'object_guid' => $friend_guid,
35  ]);
36  }
37 
38  return true;
39  }
40 
48  public function removeFriend(int $friend_guid): bool {
49  return $this->removeRelationship($friend_guid, 'friend');
50  }
51 
58  public function isFriend(): bool {
59  elgg_deprecated_notice(__CLASS__ . '->' . __FUNCTION__ . '() has been deprecated. Use ' . __CLASS__ . '->isFriendOf()', '4.3');
60 
61  return $this->isFriendOf(_elgg_services()->session->getLoggedInUserGuid());
62  }
63 
71  public function isFriendsWith(int $user_guid): bool {
72  return $this->hasRelationship($user_guid, 'friend');
73  }
74 
82  public function isFriendOf(int $user_guid): bool {
83  return (bool) _elgg_services()->relationshipsTable->check($user_guid, 'friend', $this->guid);
84  }
85 
96  public function getFriends(array $options = []) {
97  elgg_deprecated_notice(__CLASS__ . '->' . __FUNCTION__ . '() has been deprecated. Use ' . __CLASS__ . '->getEntitiesFromRelationship()', '4.3');
98 
99  $options['relationship'] = 'friend';
100  $options['relationship_guid'] = $this->guid;
101  $options['type'] = 'user';
102 
103  return elgg_get_entities($options);
104  }
105 
117  public function getFriendsOf(array $options = []) {
118  elgg_deprecated_notice(__CLASS__ . '->' . __FUNCTION__ . '() has been deprecated. Use ' . __CLASS__ . '->getEntitiesFromRelationship()', '4.3');
119 
120  $options['relationship'] = 'friend';
121  $options['relationship_guid'] = $this->guid;
122  $options['inverse_relationship'] = true;
123  $options['type'] = 'user';
124 
125  return elgg_get_entities($options);
126  }
127 
139  public function getFriendsObjects(array $options = []) {
140  elgg_deprecated_notice(__CLASS__ . '->' . __FUNCTION__ . '() has been deprecated. Use ' . __CLASS__ . '->getEntitiesFromRelationship()', '4.3');
141 
142  $options['type'] = 'object';
143  $options['relationship'] = 'friend';
144  $options['relationship_guid'] = $this->guid;
145  $options['relationship_join_on'] = 'container_guid';
146 
147  return elgg_get_entities($options);
148  }
149 }
$user_guid
Definition: login_as.php:10
get_user($guid)
Get a user object from a GUID.
Definition: users.php:20
elgg_deprecated_notice(string $msg, string $dep_version)
Log a notice about deprecated use of a function, view, etc.
Definition: deprecation.php:52
elgg_create_river_item(array $options=[])
Elgg river.
Definition: river.php:27
$friend_guid
Assembles and outputs the registration page.
Definition: register.php:12
$options
Elgg admin footer.
Definition: footer.php:6
elgg_get_entities(array $options=[])
Fetches/counts entities or performs a calculation on their properties.
Definition: entities.php:545
_elgg_services()
Get the global service provider.
Definition: elgglib.php:638
$guid
Reset an ElggUpgrade.
Definition: reset.php:6