Elgg  Version 4.x
ElggAccessCollection.php
Go to the documentation of this file.
1 <?php
2 
11 
17  public function __construct(stdClass $row = null) {
18  $this->initializeAttributes();
19 
20  foreach ((array) $row as $key => $value) {
21  $this->attributes[$key] = $value;
22  }
23  }
24 
31  protected function initializeAttributes() {
32  parent::initializeAttributes();
33 
34  $this->attributes['id'] = null;
35  $this->attributes['owner_guid'] = null;
36  $this->attributes['name'] = null;
37  $this->attributes['subtype'] = null;
38  }
39 
48  public function __set($name, $value) {
49  if (in_array($name, ['id', 'owner_guid', 'subtype'])) {
50  throw new RuntimeException("$name can not be set at runtime");
51  }
52  $this->attributes[$name] = $value;
53  }
54 
61  public function __get($name) {
62  if (array_key_exists($name, $this->attributes)) {
63  return $this->attributes[$name];
64  }
65 
66  return null;
67  }
68 
73  public function getOwnerEntity() {
74  return _elgg_services()->entityTable->get($this->owner_guid);
75  }
76 
81  public function getDisplayName() {
82 
83  $filter = function($name = null) {
84  if (!isset($name)) {
85  $name = _elgg_services()->translator->translate('access:limited:label');
86  }
87  $params = [
88  'access_collection' => $this,
89  ];
90  return (string) _elgg_services()->hooks->trigger('access_collection:name', $this->getType(), $params, $name);
91  };
92 
93  $user = _elgg_services()->session->getLoggedInUser();
94  $owner = $this->getOwnerEntity();
95  if (!$user || !$owner) {
96  // User is not logged in or does not access to the owner entity:
97  // return default 'Limited' label
98  return $filter();
99  }
100 
101  if ($user->isAdmin() || $owner->guid == $user->guid) {
102  return $filter($this->name);
103  }
104 
105  return $filter();
106  }
107 
111  public function save() : bool {
112  if ($this->id > 0) {
113  return _elgg_services()->accessCollections->rename($this->id, $this->name);
114  } else {
115  return (bool) _elgg_services()->accessCollections->create($this->name, $this->owner_guid);
116  }
117  }
118 
122  public function delete() {
123  return _elgg_services()->accessCollections->delete($this->id);
124  }
125 
132  public function canEdit($user_guid = null) {
133  return _elgg_services()->accessCollections->canEdit($this->id, $user_guid);
134  }
135 
142  public function getMembers(array $options = []) {
143  return _elgg_services()->accessCollections->getMembers($this->id, $options);
144  }
145 
152  public function hasMember($member_guid = 0) {
153  return _elgg_services()->accessCollections->hasUser($member_guid, $this->id);
154  }
155 
162  public function addMember($member_guid = 0) {
163  return _elgg_services()->accessCollections->addUser($member_guid, $this->id);
164  }
165 
172  public function removeMember($member_guid = 0) {
173  return _elgg_services()->accessCollections->removeUser($member_guid, $this->id);
174  }
175 
179  public function getURL() {
180  $type = $this->getType();
181  $params = [
182  'access_collection' => $this,
183  ];
184  $url = _elgg_services()->hooks->trigger('access_collection:url', $type, $params);
185  return elgg_normalize_url($url);
186  }
187 
191  public function toObject(array $params = []) {
192  $object = new \Elgg\Export\AccessCollection();
193  $object->type = $this->getType();
194  $object->subtype = $this->getSubtype();
195  $object->id = $this->id;
196  $object->owner_guid = $this->owner_guid;
197  $object->name = $this->name;
198 
199  $params['access_collection'] = $this;
200 
201  return _elgg_services()->hooks->trigger('to:object', 'access_collection', $params, $object);
202  }
203 
207  public function getSystemLogID() {
208  return $this->id;
209  }
210 
214  public function getObjectFromID($id) {
215  return _elgg_services()->accessCollections->get($id);
216  }
217 
221  public function getType() {
222  return 'access_collection';
223  }
224 
228  public function getSubtype() {
229  if (isset($this->subtype)) {
230  return $this->subtype;
231  }
232 
233  return $this->name;
234  }
235 
236 }
$user_guid
Definition: login_as.php:10
removeMember($member_guid=0)
Removes a user from access collection.
if(!$user||!$user->canDelete()) $name
Definition: delete.php:22
$params
Saves global plugin settings.
Definition: save.php:13
$owner
Definition: upload.php:7
elgg_normalize_url($url)
Definition: output.php:152
canEdit($user_guid=null)
Check if user can edit this collection.
$site name
Definition: settings.php:21
toObject(array $params=[])
{}
$subtype
Definition: delete.php:22
$type
Definition: delete.php:21
$options
Elgg admin footer.
Definition: footer.php:6
getDisplayName()
Get readable access level name for this collection.
$value
Definition: generic.php:51
__set($name, $value)
Set an attribute.
$owner_guid
initializeAttributes()
Initialize the attributes array.
__construct(stdClass $row=null)
Create an access collection object.
$user
Definition: ban.php:7
getMembers(array $options=[])
Returns members of the access collection.
if($container instanceof ElggGroup &&$container->guid!=elgg_get_page_owner_guid()) $key
Definition: summary.php:44
__get($name)
Get an attribute.
getOwnerEntity()
Returns owner entity of the collection.
if($email instanceof\Elgg\Email) $object
Definition: body.php:24
foreach($plugin_guids as $guid) if(empty($deactivated_plugins)) $url
Definition: deactivate.php:39
hasMember($member_guid=0)
Checks if user is already in access collection.
_elgg_services()
Get the global service provider.
Definition: elgglib.php:777
$filter
Layout body.
Definition: body.php:18
addMember($member_guid=0)
Adds a user to access collection.
$id
Generic annotation delete action.
Definition: delete.php:6