Elgg  Version master
ElggData.php
Go to the documentation of this file.
1 <?php
2 
5 
10 abstract class ElggData implements CollectionItemInterface,
11  Iterator,
12  ArrayAccess {
13 
14  use TimeUsing;
15 
25  protected $attributes = [];
26 
34  protected function initializeAttributes() {
35  $this->attributes['time_created'] = null;
36  }
37 
43  protected function getDatabase(): \Elgg\Database {
44  return _elgg_services()->db;
45  }
46 
56  public function __isset($name) {
57  return $this->$name !== null;
58  }
59 
69  public function __unset($name) {
70  $this->$name = null;
71  }
72 
78  abstract public function getURL(): string;
79 
85  abstract public function save(): bool;
86 
92  abstract public function delete(): bool;
93 
99  public function getTimeCreated(): int {
100  return (int) $this->attributes['time_created'];
101  }
102 
110  abstract public function toObject(array $params = []);
111 
112  /*
113  * SYSTEM LOG RELATED FUNCTIONS
114  */
115 
122  abstract public function getSystemLogID(): int;
123 
129  abstract public function getType(): string;
130 
137  abstract public function getSubtype(): string;
138 
148  abstract public function getObjectFromID(int $id);
149 
157  protected $valid = false;
158 
166  #[\ReturnTypeWillChange]
167  public function rewind() {
168  $this->valid = (reset($this->attributes) !== false);
169  }
170 
178  #[\ReturnTypeWillChange]
179  public function current() {
180  return current($this->attributes);
181  }
182 
190  #[\ReturnTypeWillChange]
191  public function key() {
192  return key($this->attributes);
193  }
194 
202  #[\ReturnTypeWillChange]
203  public function next() {
204  $this->valid = (next($this->attributes) !== false);
205  }
206 
214  #[\ReturnTypeWillChange]
215  public function valid() {
216  return $this->valid;
217  }
218 
219  /*
220  * ARRAY ACCESS INTERFACE
221  */
222 
233  #[\ReturnTypeWillChange]
234  public function offsetSet($offset, $value) {
235  if (array_key_exists($offset, $this->attributes)) {
236  $this->attributes[$offset] = $value;
237  }
238  }
239 
249  #[\ReturnTypeWillChange]
250  public function offsetGet($offset) {
251  if (array_key_exists($offset, $this->attributes)) {
252  return $this->$offset;
253  }
254 
255  return null;
256  }
257 
267  #[\ReturnTypeWillChange]
268  public function offsetUnset($offset) {
269  if (array_key_exists($offset, $this->attributes)) {
270  // Full unsetting is dangerous for our objects
271  unset($this->$offset);
272  }
273  }
274 
284  #[\ReturnTypeWillChange]
285  public function offsetExists($offset) {
286  return array_key_exists($offset, $this->attributes);
287  }
288 
292  public function getID() {
293  return $this->getSystemLogID();
294  }
295 
299  public function getPriority() {
300  return $this->getTimeCreated();
301  }
302 
310  public function __serialize(): array {
311  return $this->attributes;
312  }
313 
323  public function __unserialize(array $data): void {
324  $this->attributes = $data;
325  }
326 }
offsetGet($offset)
Array access interface.
Definition: ElggData.php:250
getDatabase()
Provides a pointer to the database object.
Definition: ElggData.php:43
key()
Iterator interface.
Definition: ElggData.php:191
getTimeCreated()
Returns the UNIX epoch time that this entity was created.
Definition: ElggData.php:99
next()
Iterator interface.
Definition: ElggData.php:203
$params
Saves global plugin settings.
Definition: save.php:13
getSystemLogID()
Return an identification for the object for storage in the system log.
if(!$user||!$user->canDelete()) $name
Definition: delete.php:22
getType()
Return the type of the object - eg.
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(empty($count)) $offset
Definition: pagination.php:26
valid()
Iterator interface.
Definition: ElggData.php:215
getID()
{Get unique item identifier within a collection.string|int}
Definition: ElggData.php:292
getObjectFromID(int $id)
For a given ID, return the object associated with it.
getSubtype()
Return a subtype.
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:56
$value
Definition: generic.php:51
if(!$entity instanceof\ElggUser) $data
Definition: attributes.php:13
getPriority()
{Get priority (weight) of the item within a collection.int}
Definition: ElggData.php:299
offsetUnset($offset)
Array access interface.
Definition: ElggData.php:268
__serialize()
Called during serialization.
Definition: ElggData.php:310
initializeAttributes()
Initialize the attributes array.
Definition: ElggData.php:34
current()
Iterator interface.
Definition: ElggData.php:179
A generic class that contains shared code among , , and .
Definition: ElggData.php:10
offsetSet($offset, $value)
Array access interface.
Definition: ElggData.php:234
save()
Save this data to the appropriate database table.
__unset($name)
Unset a property from metadata or attribute.
Definition: ElggData.php:69
_elgg_services()
Get the global service provider.
Definition: elgglib.php:351
toObject(array $params=[])
Get a plain old object copy for public consumption.
offsetExists($offset)
Array access interface.
Definition: ElggData.php:285
__unserialize(array $data)
Called during unserialization.
Definition: ElggData.php:323
getURL()
Get a URL for this object.
$id
Generic annotation delete action.
Definition: delete.php:6
rewind()
Iterator interface.
Definition: ElggData.php:167