summaryrefslogtreecommitdiffstats
path: root/application/models/Group.php
diff options
context:
space:
mode:
Diffstat (limited to 'application/models/Group.php')
-rw-r--r--application/models/Group.php34
1 files changed, 34 insertions, 0 deletions
diff --git a/application/models/Group.php b/application/models/Group.php
index 2ef4f6a..3cfabd1 100644
--- a/application/models/Group.php
+++ b/application/models/Group.php
@@ -71,5 +71,39 @@ class Application_Model_Group
$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;
+ }
}