Elgg  Version 3.0
ElggData.php
Go to the documentation of this file.
1 <?php
2 
4 
12 abstract class ElggData implements CollectionItemInterface,
14  Loggable,
15  Iterator,
16  ArrayAccess {
17 
19 
27  protected $attributes = [];
28 
36  protected function initializeAttributes() {
37  // Create attributes array if not already created
38  if (!is_array($this->attributes)) {
39  $this->attributes = [];
40  }
41 
42  $this->attributes['time_created'] = null;
43  }
44 
50  protected function getDatabase() {
51  return _elgg_services()->db;
52  }
53 
63  public function __isset($name) {
64  return $this->$name !== null;
65  }
66 
76  public function __unset($name) {
77  $this->$name = null;
78  }
79 
85  abstract public function getURL();
86 
92  abstract public function save();
93 
99  abstract public function delete();
100 
106  public function getTimeCreated() {
107  return $this->attributes['time_created'];
108  }
109 
117  abstract public function toObject(array $params = []);
118 
119  /*
120  * ITERATOR INTERFACE
121  */
122 
123  protected $valid = false;
124 
132  public function rewind() {
133  $this->valid = (false !== reset($this->attributes));
134  }
135 
143  public function current() {
144  return current($this->attributes);
145  }
146 
154  public function key() {
155  return key($this->attributes);
156  }
157 
165  public function next() {
166  $this->valid = (false !== next($this->attributes));
167  }
168 
176  public function valid() {
177  return $this->valid;
178  }
179 
180  /*
181  * ARRAY ACCESS INTERFACE
182  */
183 
194  public function offsetSet($key, $value) {
195  if (array_key_exists($key, $this->attributes)) {
196  $this->attributes[$key] = $value;
197  }
198  }
199 
209  public function offsetGet($key) {
210  if (array_key_exists($key, $this->attributes)) {
211  return $this->$key;
212  }
213 
214  return null;
215  }
216 
226  public function offsetUnset($key) {
227  if (array_key_exists($key, $this->attributes)) {
228  // Full unsetting is dangerous for our objects
229  unset($this->$key);
230  }
231  }
232 
242  public function offsetExists($offset) {
243  return array_key_exists($offset, $this->attributes);
244  }
245 
249  public function getId() {
250  return $this->getSystemLogID();
251  }
252 
256  public function getPriority() {
257  return $this->getTimeCreated();
258  }
259 
263  public function serialize() {
264  return serialize($this->attributes);
265  }
266 
270  public function unserialize($serialized) {
271  $this->attributes = unserialize($serialized);
272  }
273 }
getDatabase()
Provides a pointer to the database object.
Definition: ElggData.php:50
key()
Iterator interface.
Definition: ElggData.php:154
offsetSet($key, $value)
Array access interface.
Definition: ElggData.php:194
valid()
Iterator interface.
Definition: ElggData.php:176
if(!$user||!$user->canDelete()) $name
Definition: delete.php:22
getTimeCreated()
Returns the UNIX epoch time that this entity was created.
Definition: ElggData.php:106
next()
Iterator interface.
Definition: ElggData.php:165
$params
Saves global plugin settings.
Definition: save.php:13
if(!$count) $offset
Definition: pagination.php:26
offsetUnset($key)
Array access interface.
Definition: ElggData.php:226
__isset($name)
Test if property is set either as an attribute or metadata.
Definition: ElggData.php:63
getPriority()
{Get priority (weight) of the item within a collection.int}
Definition: ElggData.php:256
getId()
{Get unique item identifier within a collection.string|int}
Definition: ElggData.php:249
initializeAttributes()
Initialize the attributes array.
Definition: ElggData.php:36
$attributes
The main attributes of an entity.
Definition: ElggData.php:27
current()
Iterator interface.
Definition: ElggData.php:143
offsetGet($key)
Array access interface.
Definition: ElggData.php:209
save()
Save this data to the appropriate database table.
if($container instanceof ElggGroup &&$container->guid!=elgg_get_page_owner_guid()) $key
Definition: summary.php:55
unserialize($serialized)
{}
Definition: ElggData.php:270
$value
Definition: debugging.php:7
__unset($name)
Unset a property from metadata or attribute.
Definition: ElggData.php:76
_elgg_services()
Get the global service provider.
Definition: elgglib.php:1292
serialize()
{}
Definition: ElggData.php:263
trait TimeUsing
Adds methods for setting the current time (for testing)
Definition: TimeUsing.php:12
toObject(array $params=[])
Get a plain old object copy for public consumption.
offsetExists($offset)
Array access interface.
Definition: ElggData.php:242
getURL()
Get a URL for this object.
rewind()
Iterator interface.
Definition: ElggData.php:132