Elgg  Version 2.2
 All Classes Namespaces Files Functions Variables Pages
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 
32  protected function initializeAttributes() {
33  // Create attributes array if not already created
34  if (!is_array($this->attributes)) {
35  $this->attributes = array();
36  }
37 
38  $this->attributes['time_created'] = null;
39  }
40 
46  protected function getDatabase() {
47  return _elgg_services()->db;
48  }
49 
59  public function __isset($name) {
60  return $this->$name !== null;
61  }
62 
71  abstract protected function get($name);
72 
82  abstract protected function set($name, $value);
83 
89  abstract public function getURL();
90 
96  abstract public function save();
97 
103  abstract public function delete();
104 
110  public function getTimeCreated() {
111  return $this->time_created;
112  }
113 
119  abstract public function toObject();
120 
121  /*
122  * SYSTEM LOG INTERFACE
123  */
124 
131  public function getClassName() {
132  elgg_deprecated_notice("getClassName() is deprecated. Use get_class().", 1.9);
133  return get_class($this);
134  }
135 
136  /*
137  * ITERATOR INTERFACE
138  */
139 
140  protected $valid = false;
141 
149  public function rewind() {
150  $this->valid = (false !== reset($this->attributes));
151  }
152 
160  public function current() {
161  return current($this->attributes);
162  }
163 
171  public function key() {
172  return key($this->attributes);
173  }
174 
182  public function next() {
183  $this->valid = (false !== next($this->attributes));
184  }
185 
193  public function valid() {
194  return $this->valid;
195  }
196 
197  /*
198  * ARRAY ACCESS INTERFACE
199  */
200 
211  public function offsetSet($key, $value) {
212  if (array_key_exists($key, $this->attributes)) {
213  $this->attributes[$key] = $value;
214  }
215  }
216 
226  public function offsetGet($key) {
227  if (array_key_exists($key, $this->attributes)) {
228  return $this->attributes[$key];
229  }
230  return null;
231  }
232 
242  public function offsetUnset($key) {
243  if (array_key_exists($key, $this->attributes)) {
244  // Full unsetting is dangerous for our objects
245  $this->attributes[$key] = "";
246  }
247  }
248 
258  public function offsetExists($offset) {
259  return array_key_exists($offset, $this->attributes);
260  }
261 }
getDatabase()
Provides a pointer to the database object.
Definition: ElggData.php:46
set($name, $value)
Set the specified attribute.
getClassName()
Return the class name of the object.
Definition: ElggData.php:131
key()
Iterator interface.
Definition: ElggData.php:171
offsetSet($key, $value)
Array access interface.
Definition: ElggData.php:211
valid()
Iterator interface.
Definition: ElggData.php:193
getTimeCreated()
Returns the UNIX epoch time that this entity was created.
Definition: ElggData.php:110
next()
Iterator interface.
Definition: ElggData.php:182
if($guid==elgg_get_logged_in_user_guid()) $name
Definition: delete.php:21
$value
Definition: longtext.php:26
if(!$count) $offset
Definition: pagination.php:26
offsetUnset($key)
Array access interface.
Definition: ElggData.php:242
__isset($name)
Test if property is set either as an attribute or metadata.
Definition: ElggData.php:59
$key
Definition: summary.php:34
$time_created
Definition: online.php:16
initializeAttributes()
Initialize the attributes array.
Definition: ElggData.php:32
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:1070
$attributes
The main attributes of an entity.
Definition: ElggData.php:23
current()
Iterator interface.
Definition: ElggData.php:160
_elgg_services(\Elgg\Di\ServiceProvider $services=null)
Get the global service provider.
Definition: autoloader.php:17
offsetGet($key)
Array access interface.
Definition: ElggData.php:226
save()
Save this data to the appropriate database table.
offsetExists($offset)
Array access interface.
Definition: ElggData.php:258
getURL()
Get a URL for this object.
rewind()
Iterator interface.
Definition: ElggData.php:149