Elgg  Version 2.3
ElggData.php
Go to the documentation of this file.
1 <?php
9 abstract class ElggData implements
10  Loggable, // Can events related to this object class be logged
11  Iterator, // Override foreach behaviour
12  \ArrayAccess, // Override for array access
13  Exportable // (deprecated 1.9)
14 {
15 
17 
25  protected $attributes = array();
26 
34  protected function initializeAttributes() {
35  // Create attributes array if not already created
36  if (!is_array($this->attributes)) {
37  $this->attributes = array();
38  }
39 
40  $this->attributes['time_created'] = null;
41  }
42 
48  protected function getDatabase() {
49  return _elgg_services()->db;
50  }
51 
61  public function __isset($name) {
62  return $this->$name !== null;
63  }
64 
73  abstract protected function get($name);
74 
84  abstract protected function set($name, $value);
85 
91  abstract public function getURL();
92 
98  abstract public function save();
99 
105  abstract public function delete();
106 
112  public function getTimeCreated() {
113  return $this->time_created;
114  }
115 
121  abstract public function toObject();
122 
123  /*
124  * SYSTEM LOG INTERFACE
125  */
126 
133  public function getClassName() {
134  elgg_deprecated_notice("getClassName() is deprecated. Use get_class().", 1.9);
135  return get_class($this);
136  }
137 
138  /*
139  * ITERATOR INTERFACE
140  */
141 
142  protected $valid = false;
143 
151  public function rewind() {
152  $this->valid = (false !== reset($this->attributes));
153  }
154 
162  public function current() {
163  return current($this->attributes);
164  }
165 
173  public function key() {
174  return key($this->attributes);
175  }
176 
184  public function next() {
185  $this->valid = (false !== next($this->attributes));
186  }
187 
195  public function valid() {
196  return $this->valid;
197  }
198 
199  /*
200  * ARRAY ACCESS INTERFACE
201  */
202 
213  public function offsetSet($key, $value) {
214  if (array_key_exists($key, $this->attributes)) {
215  $this->attributes[$key] = $value;
216  }
217  }
218 
228  public function offsetGet($key) {
229  if (array_key_exists($key, $this->attributes)) {
230  return $this->attributes[$key];
231  }
232  return null;
233  }
234 
244  public function offsetUnset($key) {
245  if (array_key_exists($key, $this->attributes)) {
246  // Full unsetting is dangerous for our objects
247  $this->attributes[$key] = "";
248  }
249  }
250 
260  public function offsetExists($offset) {
261  return array_key_exists($offset, $this->attributes);
262  }
263 }
getDatabase()
Provides a pointer to the database object.
Definition: ElggData.php:48
getClassName()
Return the class name of the object.
Definition: ElggData.php:133
key()
Iterator interface.
Definition: ElggData.php:173
offsetSet($key, $value)
Array access interface.
Definition: ElggData.php:213
valid()
Iterator interface.
Definition: ElggData.php:195
getTimeCreated()
Returns the UNIX epoch time that this entity was created.
Definition: ElggData.php:112
next()
Iterator interface.
Definition: ElggData.php:184
if($guid==elgg_get_logged_in_user_guid()) $name
Definition: delete.php:21
$value
Definition: longtext.php:42
if(!$count) $offset
Definition: pagination.php:26
offsetUnset($key)
Array access interface.
Definition: ElggData.php:244
__isset($name)
Test if property is set either as an attribute or metadata.
Definition: ElggData.php:61
$key
Definition: summary.php:34
$time_created
Definition: online.php:16
initializeAttributes()
Initialize the attributes array.
Definition: ElggData.php:34
toObject()
Get a plain old object copy for public consumption.
elgg_deprecated_notice($msg, $dep_version, $backtrace_level=1)
Log a notice about deprecated use of a function, view, etc.
Definition: elgglib.php:1098
$attributes
The main attributes of an entity.
Definition: ElggData.php:25
current()
Iterator interface.
Definition: ElggData.php:162
_elgg_services(\Elgg\Di\ServiceProvider $services=null)
Get the global service provider.
Definition: autoloader.php:17
offsetGet($key)
Array access interface.
Definition: ElggData.php:228
save()
Save this data to the appropriate database table.
trait TimeUsing
Adds methods for setting the current time (for testing)
Definition: TimeUsing.php:11
offsetExists($offset)
Array access interface.
Definition: ElggData.php:260
getURL()
Get a URL for this object.
rewind()
Iterator interface.
Definition: ElggData.php:151