diff options
Diffstat (limited to 'engine/lib/entities.php')
-rw-r--r-- | engine/lib/entities.php | 43 |
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; + } + } /** |