Elgg  Version 1.9
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 
23  protected $attributes = array();
24 
25  // @codingStandardsIgnoreStart
39  protected function initialise_attributes($pre18_api = true) {
40  if ($pre18_api) {
41  elgg_deprecated_notice('initialise_attributes() is deprecated by initializeAttributes()', 1.8);
42  }
43  }
44  // @codingStandardsIgnoreEnd
45 
53  protected function initializeAttributes() {
54  // Create attributes array if not already created
55  if (!is_array($this->attributes)) {
56  $this->attributes = array();
57  }
58 
59  $this->attributes['time_created'] = null;
60  }
61 
67  protected function getDatabase() {
68  return _elgg_services()->db;
69  }
70 
80  public function __isset($name) {
81  return $this->$name !== null;
82  }
83 
92  abstract protected function get($name);
93 
103  abstract protected function set($name, $value);
104 
110  abstract public function getURL();
111 
117  abstract public function save();
118 
124  abstract public function delete();
125 
131  public function getTimeCreated() {
132  return $this->time_created;
133  }
134 
140  abstract public function toObject();
141 
142  /*
143  * SYSTEM LOG INTERFACE
144  */
145 
152  public function getClassName() {
153  elgg_deprecated_notice("getClassName() is deprecated. Use get_class().", 1.9);
154  return get_class($this);
155  }
156 
163  public function getObjectOwnerGUID() {
164  elgg_deprecated_notice("getObjectOwnerGUID() was deprecated. Use getOwnerGUID().", 1.8);
165  return $this->owner_guid;
166  }
167 
168  /*
169  * ITERATOR INTERFACE
170  */
171 
172  protected $valid = false;
173 
181  public function rewind() {
182  $this->valid = (false !== reset($this->attributes));
183  }
184 
192  public function current() {
193  return current($this->attributes);
194  }
195 
203  public function key() {
204  return key($this->attributes);
205  }
206 
214  public function next() {
215  $this->valid = (false !== next($this->attributes));
216  }
217 
225  public function valid() {
226  return $this->valid;
227  }
228 
229  /*
230  * ARRAY ACCESS INTERFACE
231  */
232 
243  public function offsetSet($key, $value) {
244  if (array_key_exists($key, $this->attributes)) {
245  $this->attributes[$key] = $value;
246  }
247  }
248 
258  public function offsetGet($key) {
259  if (array_key_exists($key, $this->attributes)) {
260  return $this->attributes[$key];
261  }
262  return null;
263  }
264 
274  public function offsetUnset($key) {
275  if (array_key_exists($key, $this->attributes)) {
276  // Full unsetting is dangerous for our objects
277  $this->attributes[$key] = "";
278  }
279  }
280 
290  public function offsetExists($offset) {
291  return array_key_exists($offset, $this->attributes);
292  }
293 }
getObjectOwnerGUID()
Return the GUID of the owner of this object.
Definition: ElggData.php:163
getDatabase()
Provides a pointer to the database object.
Definition: ElggData.php:67
getClassName()
Return the class name of the object.
Definition: ElggData.php:152
key()
Iterator interface.
Definition: ElggData.php:203
offsetSet($key, $value)
Array access interface.
Definition: ElggData.php:243
valid()
Iterator interface.
Definition: ElggData.php:225
getTimeCreated()
Returns the UNIX epoch time that this entity was created.
Definition: ElggData.php:131
next()
Iterator interface.
Definition: ElggData.php:214
if($guid==elgg_get_logged_in_user_guid()) $name
Definition: delete.php:21
if(elgg_in_context('widget')) $offset
Definition: pagination.php:20
$value
Definition: longtext.php:29
offsetUnset($key)
Array access interface.
Definition: ElggData.php:274
__isset($name)
Test if property is set either as an attribute or metadata.
Definition: ElggData.php:80
$owner_guid
$key
Definition: summary.php:34
_elgg_services()
Definition: autoloader.php:14
initialise_attributes($pre18_api=true)
Initialise the attributes array.
Definition: ElggData.php:39
$time_created
Definition: online.php:16
initializeAttributes()
Initialize the attributes array.
Definition: ElggData.php:53
toObject()
Get a plain old object copy for public consumption.
elgg_deprecated_notice($msg, $dep_version, $backtrace_level=1)
Sends a notice about deprecated use of a function, view, etc.
Definition: elgglib.php:1171
$attributes
The main attributes of an entity.
Definition: ElggData.php:23
current()
Iterator interface.
Definition: ElggData.php:192
offsetGet($key)
Array access interface.
Definition: ElggData.php:258
save()
Save this data to the appropriate database table.
offsetExists($offset)
Array access interface.
Definition: ElggData.php:290
getURL()
Get a URL for this object.
rewind()
Iterator interface.
Definition: ElggData.php:181