Elgg  Version 6.1
AccessCollections.php
Go to the documentation of this file.
1 <?php
2 
4 
6 
12 trait AccessCollections {
13 
24  public function getOwnedAccessCollections(array $options = []): array {
25  $options['owner_guid'] = $this->guid;
26  return _elgg_services()->accessCollections->getEntityCollections($options);
27  }
28 
39  public function getOwnedAccessCollection(string $subtype): ?\ElggAccessCollection {
40  if ($subtype === '') {
41  throw new ElggInvalidArgumentException(__METHOD__ . ' requires $subtype to be non empty');
42  }
43 
44  $acls = $this->getOwnedAccessCollections([
45  'subtype' => $subtype,
46  ]);
47 
48  return elgg_extract(0, $acls);
49  }
50 
57  public function deleteAccessCollectionMemberships() {
58  if (!$this->guid) {
59  return false;
60  }
61 
62  if ($this->type !== 'user') {
63  return true;
64  }
65 
66  $ac = _elgg_services()->accessCollections;
67 
68  $collections = $ac->getCollectionsByMember($this->guid);
69  if (empty($collections)) {
70  return true;
71  }
72 
73  $result = true;
74  foreach ($collections as $collection) {
75  $result &= $ac->removeUser($this->guid, $collection->id);
76  }
77 
78  return $result;
79  }
80 
87  public function deleteOwnedAccessCollections() {
88  if (!$this->guid) {
89  return false;
90  }
91 
92  $collections = $this->getOwnedAccessCollections();
93  if (empty($collections)) {
94  return true;
95  }
96 
97  $result = true;
98  foreach ($collections as $collection) {
99  $result = $result & $collection->delete();
100  }
101 
102  return $result;
103  }
104 }
elgg_extract($key, $array, $default=null, bool $strict=true)
Checks for $array[$key] and returns its value if it exists, else returns $default.
Definition: elgglib.php:256
if($who_can_change_language=== 'nobody') elseif($who_can_change_language=== 'admin_only'&&!elgg_is_admin_logged_in()) $options
Definition: language.php:20
$subtype
Definition: delete.php:22
_elgg_services()
Get the global service provider.
Definition: elgglib.php:353
$guid
Reset an ElggUpgrade.
Definition: reset.php:6