diff options
Diffstat (limited to 'application/models')
23 files changed, 755 insertions, 13 deletions
diff --git a/application/models/BootIso.php b/application/models/BootIso.php index 706a0a2..0fce948 100644 --- a/application/models/BootIso.php +++ b/application/models/BootIso.php @@ -124,5 +124,39 @@ class Application_Model_BootIso $this->_bootisoID = $_bootisoID; 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; + } } diff --git a/application/models/BootMenu.php b/application/models/BootMenu.php index 5a3e8b9..09a5c0d 100644 --- a/application/models/BootMenu.php +++ b/application/models/BootMenu.php @@ -80,5 +80,39 @@ class Application_Model_BootMenu $this->_time = $_time; 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; + } } diff --git a/application/models/BootMenuEntries.php b/application/models/BootMenuEntries.php index 0b88402..9b6985c 100644 --- a/application/models/BootMenuEntries.php +++ b/application/models/BootMenuEntries.php @@ -89,6 +89,40 @@ class Application_Model_BootMenuEntries $this->_order = $_order; 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; + } } diff --git a/application/models/BootOs.php b/application/models/BootOs.php index a2eea2f..b61be41 100644 --- a/application/models/BootOs.php +++ b/application/models/BootOs.php @@ -151,5 +151,39 @@ class Application_Model_BootOs $this->_public = $_public; 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; + } } diff --git a/application/models/Client.php b/application/models/Client.php index 9216b20..a27c3b3 100644 --- a/application/models/Client.php +++ b/application/models/Client.php @@ -71,5 +71,39 @@ class Application_Model_Client $this->_hardwarehash = $_hardwarehash; 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; + } } diff --git a/application/models/Config.php b/application/models/Config.php index 94ff256..b9a29dc 100644 --- a/application/models/Config.php +++ b/application/models/Config.php @@ -71,5 +71,39 @@ class Application_Model_Config $this->_shellscript = $_shellscript; 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; + } } diff --git a/application/models/Filter.php b/application/models/Filter.php index f90c985..b77cf97 100644 --- a/application/models/Filter.php +++ b/application/models/Filter.php @@ -121,5 +121,39 @@ class Application_Model_Filter $this->_priority = $_priority; 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; + } } diff --git a/application/models/FilterEntries.php b/application/models/FilterEntries.php index 63aa864..59f62e5 100644 --- a/application/models/FilterEntries.php +++ b/application/models/FilterEntries.php @@ -81,5 +81,39 @@ class Application_Model_FilterEntries $this->_filtervalue2 = $_filtervalue2; 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; + } } diff --git a/application/models/FilterEntriesMapper.php b/application/models/FilterEntriesMapper.php index 54d6e3a..ef2c28f 100644 --- a/application/models/FilterEntriesMapper.php +++ b/application/models/FilterEntriesMapper.php @@ -31,20 +31,31 @@ class Application_Model_FilterEntriesMapper public function save(Application_Model_FilterEntries $filterentries) { - + try{ $data = array('filterID'=> $filterentries->getFilterID() , 'filtertypeID'=> $filterentries->getFiltertypeID() , 'filtervalue'=> $filterentries->getFiltervalue() , 'filtervalue2'=> $filterentries->getFiltervalue2() ); - - if (null != ($id1 = $filterentries->getFilterID()) && - null != ($id2 = $filterentries->getFiltertypeID()) && - $this->getDbTable()->find($filterentries->getFilterID(),$filterentries->getFiltertypeID())) { + + $filterentries2 = new Application_Model_FilterEntries(); + $result = $this->find($filterentries->getFilterID(),$filterentries->getFiltertypeID(),$filterentries2); + echo "<pre style='border:1px solid black;background-color:#F5B800'>"; + print_r(array($filterentries,$filterentries2,$result)); + echo "</pre>"; + $id1 = $filterentries->getFilterID(); + $id2 = $filterentries->getFiltertypeID(); + if (0 == count($result) && + null != $id1 && + null != $id2) { $this->getDbTable()->insert($data); - echo 'fall1'; + echo 'inserted'; } else { - $this->getDbTable()->update($data, array('filterID = ?' => $id1, 'filtertypeID = ?' => $id2)); - echo 'fall2'; + print_r($this->getDbTable()->update($data, array('filterID = ?' => $id1, 'filtertypeID = ?' => $id2))); + echo 'updated'; + } + + }catch (Zend_Exception $e) { + echo "Error message 2: " . $e->getMessage() . "\n"; } } @@ -53,13 +64,18 @@ class Application_Model_FilterEntriesMapper try{ $id1 = $filterentries->getFilterID(); $id2 = $filterentries->getFiltertypeID(); + echo "<pre>"; + echo "-----------\n"; var_dump(array($id1,$id2)); + echo "</pre>"; //TODO: Löschen klappt nicht - if ((null != $id1) && (null != $id2) && + if ((null == $id1) && (null == $id2) && $this->getDbTable()->find($filterentries->getFilterID(),$filterentries->getFiltertypeID())) { + echo 'case1'; return; } else { $this->getDbTable()->delete(array('filterID = ?' => $id1, 'filtertypeID = ?' => $id2)); + echo 'case2'; } }catch (Zend_Exception $e) { diff --git a/application/models/FilterMapper.php b/application/models/FilterMapper.php index 0ac3cb3..3960c0d 100644 --- a/application/models/FilterMapper.php +++ b/application/models/FilterMapper.php @@ -33,12 +33,17 @@ class Application_Model_FilterMapper { $data = array('filterID'=> $filter->getID() ,'membershipID'=> $filter->getMembershipID() ,'groupID'=> $filter->getGroupID() ,'bootmenuID'=> $filter->getBootmenuID() ,'title'=> $filter->getTitle() ,'description'=> $filter->getDescription() ,'created'=> $filter->getCreated() ,'priority'=> $filter->getPriority() ); + echo "<pre>"; + print_r(array('woot',$filter->getID())); + echo "</pre>"; if (null === ($id = $filter->getID()) ) { unset($data['filterID']); $this->getDbTable()->insert($data); + echo 'case1'; } else { $this->getDbTable()->update($data, array('filterID = ?' => $id)); + echo 'case2'; } } @@ -52,15 +57,22 @@ class Application_Model_FilterMapper } public function find($id, Application_Model_Filter $filter) - { + { + $result = $this->getDbTable()->find($id); if (0 == count($result)) { return; } - $row = $result->current(); - $filter->setID($row->filterID)->setMembershipID($row->membershipID)->setGroupID($row->groupID)->setBootmenuID($row->bootmenuID)->setTitle($row->title)->setDescription($row->description)->setCreated($row->created)->setPriority($row->priority); + $filter->setID($row->filterID) + ->setMembershipID($row->membershipID) + ->setGroupID($row->groupID) + ->setBootmenuID($row->bootmenuID) + ->setTitle($row->title) + ->setDescription($row->description) + ->setCreated($row->created) + ->setPriority($row->priority); } public function fetchAll() @@ -76,7 +88,7 @@ class Application_Model_FilterMapper } return $entries; } - + } diff --git a/application/models/FilterType.php b/application/models/FilterType.php index a66950a..3293083 100644 --- a/application/models/FilterType.php +++ b/application/models/FilterType.php @@ -61,5 +61,39 @@ class Application_Model_FilterType $this->_filtertypename = $_filtertypename; 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; + } } 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; + } } diff --git a/application/models/GroupGroups.php b/application/models/GroupGroups.php index 3673d57..18307e7 100644 --- a/application/models/GroupGroups.php +++ b/application/models/GroupGroups.php @@ -61,5 +61,39 @@ class Application_Model_GroupGroups $this->_groupID = $_groupID; 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; + } } diff --git a/application/models/GroupRequest.php b/application/models/GroupRequest.php index 8c24c49..6675991 100644 --- a/application/models/GroupRequest.php +++ b/application/models/GroupRequest.php @@ -81,5 +81,39 @@ class Application_Model_GroupRequest $this->_time = $_time; 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; + } } diff --git a/application/models/Membership.php b/application/models/Membership.php index 4107072..eaa1f97 100644 --- a/application/models/Membership.php +++ b/application/models/Membership.php @@ -81,5 +81,39 @@ class Application_Model_Membership $this->_personID = $_personID; 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; + } } diff --git a/application/models/Person.php b/application/models/Person.php index eb26cbf..b4545e9 100644 --- a/application/models/Person.php +++ b/application/models/Person.php @@ -181,5 +181,39 @@ class Application_Model_Person { return $this->_password_salt; } + /** + * 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; + } } diff --git a/application/models/Pool.php b/application/models/Pool.php index 76c7a3b..11d5a03 100644 --- a/application/models/Pool.php +++ b/application/models/Pool.php @@ -81,5 +81,39 @@ class Application_Model_Pool $this->_location = $_location; 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; + } } diff --git a/application/models/PoolEntries.php b/application/models/PoolEntries.php index 2a74dad..31caf5f 100644 --- a/application/models/PoolEntries.php +++ b/application/models/PoolEntries.php @@ -61,5 +61,39 @@ class Application_Model_PoolEntries $this->_clientID = $_clientID; 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; + } } diff --git a/application/models/PoolFilters.php b/application/models/PoolFilters.php index 5511c4b..8ce21fc 100644 --- a/application/models/PoolFilters.php +++ b/application/models/PoolFilters.php @@ -61,5 +61,39 @@ class Application_Model_PoolFilters $this->_filterID = $_filterID; 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; + } } 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; + } } diff --git a/application/models/RightRoles.php b/application/models/RightRoles.php index e9b75c7..b25a605 100644 --- a/application/models/RightRoles.php +++ b/application/models/RightRoles.php @@ -61,5 +61,39 @@ class Application_Model_RightRoles $this->_rightID = $_rightID; 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; + } } diff --git a/application/models/Role.php b/application/models/Role.php index 0503627..28f0af1 100644 --- a/application/models/Role.php +++ b/application/models/Role.php @@ -81,5 +81,39 @@ class Application_Model_Role $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; + } } diff --git a/application/models/Session.php b/application/models/Session.php index 73b6b4d..b042c17 100644 --- a/application/models/Session.php +++ b/application/models/Session.php @@ -101,5 +101,39 @@ class Application_Model_Session $this->_ip6 = $_ip6; 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; + } } |
