From 3a57892f9145bfadac4cf3bf4392020f99e0d541 Mon Sep 17 00:00:00 2001 From: Simon Date: Sat, 5 Mar 2011 17:41:24 +0100 Subject: filter-oberffäche fertig, nun zur auswahl des bootmenus && funktion toArray bei jedem Mapper hinzugefügt, um populate bei Formularen nutzen zu können --- application/models/Right.php | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'application/models/Right.php') diff --git a/application/models/Right.php b/application/models/Right.php index ad1821e..c0df29c 100644 --- a/application/models/Right.php +++ b/application/models/Right.php @@ -71,5 +71,39 @@ class Application_Model_Right $this->_description = $_description; return $this; } + /** + * Returns current data as associative array using ReflectionClass + * + * @return array Returns associative array containing model data + * If "get"-method not available (our primary keys) the function getID() is called + */ + public function toArray() + { + $reflectionClass = new ReflectionClass($this); + $properties = $reflectionClass->getProperties(); + $result = array(); + foreach ($properties as $property) { + $key = $property->name; + if (substr($key, 0, 1) != '_' && $this->$key !== null) { + $method = 'get' . ucfirst($key); + if ($reflectionClass->hasMethod($method)) { + $result[$key] = $this->$method(); + } else { + $result[$key] = $this->$key; + } + } + elseif(substr($key, 0, 1) == '_' && $this->$key !== null) { + $key = substr($key, 1); + $method = 'get' . ucfirst($key); + if ($reflectionClass->hasMethod($method)) { + $result[$key] = $this->$method(); + }else{ + $result[$key] = $this->getID(); + } + + } + } + return $result; + } } -- cgit v1.2.3-55-g7522