Elgg  Version 4.x
ElggData.php
Go to the documentation of this file.
1 <?php
2 
5 
10 abstract class ElggData implements CollectionItemInterface,
11  Loggable,
12  Iterator,
13  ArrayAccess {
14 
15  use TimeUsing;
16 
26  protected $attributes = [];
27 
35  protected function initializeAttributes() {
36  $this->attributes['time_created'] = null;
37  }
38 
44  protected function getDatabase() {
45  return _elgg_services()->db;
46  }
47 
57  public function __isset($name) {
58  return $this->$name !== null;
59  }
60 
70  public function __unset($name) {
71  $this->$name = null;
72  }
73 
79  abstract public function getURL();
80 
86  abstract public function save() : bool;
87 
93  abstract public function delete();
94 
100  public function getTimeCreated() {
101  return $this->attributes['time_created'];
102  }
103 
111  abstract public function toObject(array $params = []);
112 
113  /*
114  * ITERATOR INTERFACE
115  */
116 
117  protected $valid = false;
118 
126  #[\ReturnTypeWillChange]
127  public function rewind() {
128  $this->valid = (false !== reset($this->attributes));
129  }
130 
138  #[\ReturnTypeWillChange]
139  public function current() {
140  return current($this->attributes);
141  }
142 
150  #[\ReturnTypeWillChange]
151  public function key() {
152  return key($this->attributes);
153  }
154 
162  #[\ReturnTypeWillChange]
163  public function next() {
164  $this->valid = (false !== next($this->attributes));
165  }
166 
174  #[\ReturnTypeWillChange]
175  public function valid() {
176  return $this->valid;
177  }
178 
179  /*
180  * ARRAY ACCESS INTERFACE
181  */
182 
193  #[\ReturnTypeWillChange]
194  public function offsetSet($key, $value) {
195  if (array_key_exists($key, $this->attributes)) {
196  $this->attributes[$key] = $value;
197  }
198  }
199 
209  #[\ReturnTypeWillChange]
210  public function offsetGet($key) {
211  if (array_key_exists($key, $this->attributes)) {
212  return $this->$key;
213  }
214 
215  return null;
216  }
217 
227  #[\ReturnTypeWillChange]
228  public function offsetUnset($key) {
229  if (array_key_exists($key, $this->attributes)) {
230  // Full unsetting is dangerous for our objects
231  unset($this->$key);
232  }
233  }
234 
244  #[\ReturnTypeWillChange]
245  public function offsetExists($offset) {
246  return array_key_exists($offset, $this->attributes);
247  }
248 
252  public function getID() {
253  return $this->getSystemLogID();
254  }
255 
259  public function getPriority() {
260  return $this->getTimeCreated();
261  }
262 
270  public function __serialize(): array {
271  return $this->attributes;
272  }
273 
283  public function __unserialize(array $data): void {
284  $this->attributes = $data;
285  }
286 }
getDatabase()
Provides a pointer to the database object.
Definition: ElggData.php:44
key()
Iterator interface.
Definition: ElggData.php:151
offsetSet($key, $value)
Array access interface.
Definition: ElggData.php:194
valid()
Iterator interface.
Definition: ElggData.php:175
if(!$user||!$user->canDelete()) $name
Definition: delete.php:22
getTimeCreated()
Returns the UNIX epoch time that this entity was created.
Definition: ElggData.php:100
next()
Iterator interface.
Definition: ElggData.php:163
$params
Saves global plugin settings.
Definition: save.php:13
c Accompany it with the information you received as to the offer to distribute corresponding source complete source code means all the source code for all modules it plus any associated interface definition plus the scripts used to control compilation and installation of the executable as a special the source code distributed need not include anything that is normally and so on of the operating system on which the executable unless that component itself accompanies the executable If distribution of executable or object code is made by offering access to copy from a designated then offering equivalent access to copy the source code from the same place counts as distribution of the source even though third parties are not compelled to copy the source along with the object code You may not or distribute the Program except as expressly provided under this License Any attempt otherwise to sublicense or distribute the Program is void
Definition: LICENSE.txt:215
if(elgg_trigger_plugin_hook('usersettings:save', 'user', $hooks_params, true)) foreach($request->validation() ->all() as $item) $data
Definition: save.php:53
if(!$count) $offset
Definition: pagination.php:26
getID()
{Get unique item identifier within a collection.string|int}
Definition: ElggData.php:252
offsetUnset($key)
Array access interface.
Definition: ElggData.php:228
trait TimeUsing
Adds methods for setting the current time (for testing)
Definition: TimeUsing.php:10
__isset($name)
Test if property is set either as an attribute or metadata.
Definition: ElggData.php:57
$value
Definition: generic.php:51
getPriority()
{Get priority (weight) of the item within a collection.int}
Definition: ElggData.php:259
__serialize()
Called during serialization.
Definition: ElggData.php:270
initializeAttributes()
Initialize the attributes array.
Definition: ElggData.php:35
current()
Iterator interface.
Definition: ElggData.php:139
offsetGet($key)
Array access interface.
Definition: ElggData.php:210
save()
Save this data to the appropriate database table.
if($container instanceof ElggGroup &&$container->guid!=elgg_get_page_owner_guid()) $key
Definition: summary.php:44
__unset($name)
Unset a property from metadata or attribute.
Definition: ElggData.php:70
_elgg_services()
Get the global service provider.
Definition: elgglib.php:777
toObject(array $params=[])
Get a plain old object copy for public consumption.
offsetExists($offset)
Array access interface.
Definition: ElggData.php:245
__unserialize(array $data)
Called during unserialization.
Definition: ElggData.php:283
getURL()
Get a URL for this object.
rewind()
Iterator interface.
Definition: ElggData.php:127