aboutsummaryrefslogtreecommitdiff
path: root/engine
diff options
context:
space:
mode:
authoricewing <icewing@36083f99-b078-4883-b0ff-0f9b5a30f544>2008-04-03 10:54:08 +0000
committericewing <icewing@36083f99-b078-4883-b0ff-0f9b5a30f544>2008-04-03 10:54:08 +0000
commit7bd568ce9ab0754df711f7b5b6fc3281e14cdfeb (patch)
tree8cceaefd0d34c0d74d90ea748573a66d02a070af /engine
parentecd6f2180a5c2d846e15d2205f696f52bce9a575 (diff)
downloadelgg-7bd568ce9ab0754df711f7b5b6fc3281e14cdfeb.tar.gz
elgg-7bd568ce9ab0754df711f7b5b6fc3281e14cdfeb.tar.bz2
Marcus Povey <marcus@dushka.co.uk>
* Added Iterator interface to override foreach behaviour git-svn-id: https://code.elgg.org/elgg/trunk@390 36083f99-b078-4883-b0ff-0f9b5a30f544
Diffstat (limited to 'engine')
-rw-r--r--engine/lib/entities.php43
1 files changed, 42 insertions, 1 deletions
diff --git a/engine/lib/entities.php b/engine/lib/entities.php
index 60ad89733..ce5121d71 100644
--- a/engine/lib/entities.php
+++ b/engine/lib/entities.php
@@ -16,7 +16,10 @@
* This class holds methods for accessing the main entities table.
* @author Marcus Povey <marcus@dushka.co.uk>
*/
- abstract class ElggEntity implements Exportable, Importable
+ abstract class ElggEntity implements
+ Exportable, // Allow export of data
+ Importable, // Allow import of data
+ Iterator // Override foreach behaviour
{
/**
* The main attributes of an entity.
@@ -299,6 +302,8 @@
return delete_entity($this->get('guid'));
}
+ // EXPORTABLE INTERFACE ////////////////////////////////////////////////////////////
+
/**
* Export this class into a stdClass containing all necessary fields.
* Override if you wish to return more information than can be found in $this->attributes (shouldn't happen)
@@ -315,6 +320,8 @@
return $tmp;
}
+ // IMPORTABLE INTERFACE ////////////////////////////////////////////////////////////
+
/**
* Import data from an parsed xml data array.
*
@@ -366,6 +373,40 @@
else
throw new ImportException("Unsupported version ($version) passed to ElggEntity::import()");
}
+
+ // ITERATOR INTERFACE //////////////////////////////////////////////////////////////
+ /*
+ * This lets an entity's attributes be displayed using foreach as a normal array.
+ * Example: http://www.sitepoint.com/print/php5-standard-library
+ */
+
+ private $valid = FALSE;
+
+ function rewind()
+ {
+ $this->valid = (FALSE !== reset($this->attributes));
+ }
+
+ function current()
+ {
+ return current($this->attributes);
+ }
+
+ function key()
+ {
+ return key($this->attributes);
+ }
+
+ function next()
+ {
+ $this->valid = (FALSE !== next($this->attributes));
+ }
+
+ function valid()
+ {
+ return $this->valid;
+ }
+
}
/**