From 50dcd70ac9ab6b5b67edcf76bb9dd368d814d7ae Mon Sep 17 00:00:00 2001 From: Simon Date: Wed, 20 Apr 2011 17:29:21 +0200 Subject: BootOsUser und HomeType Models hinzugefĆ¼gt --- application/models/BootOsUser.php | 154 ++++++++++++++++++++++++++++++ application/models/DbTable/BootOsUser.php | 20 ++++ application/models/DbTable/HomeType.php | 20 ++++ application/models/HomeType.php | 111 +++++++++++++++++++++ application/models/HomeTypeMapper.php | 142 +++++++++++++++++++++++++++ 5 files changed, 447 insertions(+) create mode 100644 application/models/BootOsUser.php create mode 100644 application/models/DbTable/BootOsUser.php create mode 100644 application/models/DbTable/HomeType.php create mode 100644 application/models/HomeType.php create mode 100644 application/models/HomeTypeMapper.php (limited to 'application/models') diff --git a/application/models/BootOsUser.php b/application/models/BootOsUser.php new file mode 100644 index 0000000..aefd311 --- /dev/null +++ b/application/models/BootOsUser.php @@ -0,0 +1,154 @@ +setOptions($options); + } + } + + public function __set($name, $value) + { + $method = 'set' . $name; + if (('mapper' == $name) || !method_exists($this, $method)) { + throw new Exception('Invalid BootOsUser property'); + } + $this->$method($value); + } + + public function __get($name) + { + $method = 'get' . $name; + if (('mapper' == $name) || !method_exists($this, $method)) { + throw new Exception('Invalid BootOsUser property'); + } + return $this->$method(); + } + + public function setOptions(array $options) + { + $methods = get_class_methods($this); + foreach ($options as $key => $value) { + $method = 'set' . ucfirst($key); + if (in_array($method, $methods)) { + $this->$method($value); + } + } + return $this; + } + + public function getID() + { + return $this->_bootosuserID; + } + public function setID($_bootosuserID) + { + $this->_bootosuserID = $_bootosuserID; + return $this; + } + + public function getConfigID() + { + return $this->_configID; + } + + public function setConfigID($_configID) + { + $this->_configID = $_configID; + return $this; + } + + public function getLogin() + { + return $this->_login; + } + + public function setLogin($_login) + { + $this->_login = $_login; + return $this; + } + public function getPassword() + { + return $this->_password; + } + + public function setPassword($_password) + { + $this->_password = $_password; + return $this; + } + + public function getHomepath() + { + return $this->_homepath; + } + public function setHomepath($_homepath) + { + $this->_homepath = $_homepath; + return $this; + } + public function getHometypeID() + { + return $this->_hometypeID; + } + public function setHometypeID($_hometypeID) + { + $this->_hometypeID = $_hometypeID; + 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/DbTable/BootOsUser.php b/application/models/DbTable/BootOsUser.php new file mode 100644 index 0000000..976e21a --- /dev/null +++ b/application/models/DbTable/BootOsUser.php @@ -0,0 +1,20 @@ +setOptions($options); + } + } + + public function __set($name, $value) + { + $method = 'set' . $name; + if (('mapper' == $name) || !method_exists($this, $method)) { + throw new Exception('Invalid HomeType property'); + } + $this->$method($value); + } + + public function __get($name) + { + $method = 'get' . $name; + if (('mapper' == $name) || !method_exists($this, $method)) { + throw new Exception('Invalid HomeType property'); + } + return $this->$method(); + } + + public function setOptions(array $options) + { + $methods = get_class_methods($this); + foreach ($options as $key => $value) { + $method = 'set' . ucfirst($key); + if (in_array($method, $methods)) { + $this->$method($value); + } + } + return $this; + } + + public function getID() + { + return $this->_hometypeID; + } + public function setID($_hometypeID) + { + $this->_hometypeID = $_hometypeID; + return $this; + } + + public function getName() + { + return $this->_name; + } + + public function setName($_name) + { + $this->_name = $_name; + 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/HomeTypeMapper.php b/application/models/HomeTypeMapper.php new file mode 100644 index 0000000..6bccceb --- /dev/null +++ b/application/models/HomeTypeMapper.php @@ -0,0 +1,142 @@ + $v){ + if($v != null) + $where2[] = "$k = '$v'"; + else + $where2[] = "$k IS NULL"; + } + $where = implode(" AND " ,$where2); + + try{ + $db = Zend_Db_Table::getDefaultAdapter(); + $select = $this->getDbTable()->select() + ->from($this->_dbTable) + ->where($where); + + if(is_array($order)){ + foreach ($order as $k => $v) + $a[] = "$k $v"; + $select->order($a); + } + + $stmt = $select->query(); + $result = $stmt->fetchAll(); + + if(!$array){ + $entries = array(); + foreach ($result as $row) { + $entry = new Application_Model_HomeType($row); + $entry->setID($row['hometypeID']); + $entries[] = $entry; + } + return $entries; + }else{ + return $result; + } + + }catch (Zend_Exception $e) { + echo "Error message 2: " . $e->getMessage() . "\n"; + } + } + public function setDbTable($dbTable) + { + if (is_string($dbTable)) { + $dbTable = new $dbTable(); + } + + if (!$dbTable instanceof Zend_Db_Table_Abstract) { + throw new Exception('Invalid table data gateway provided'); + } + + $this->_dbTable = $dbTable; + + return $this; + } + + public function getDbTable() + { + if (null === $this->_dbTable) { + $this->setDbTable('Application_Model_DbTable_HomeType'); + } + + return $this->_dbTable; + } + + public function save(Application_Model_HomeType $hometype) + { + + $data = array('hometypeID'=> $hometype->getID() ,'name'=> $hometype->getName() ); + + if (null === ($id = $hometype->getID()) ) { + unset($data['hometypeID']); + $this->getDbTable()->insert($data); + } else { + $this->getDbTable()->update($data, array('hometypeID = ?' => $id)); + } + } + + public function delete(Application_Model_HomeType $hometype) + { + if (null === ($id = $hometype->getID()) ) { + return; + } else { + $this->getDbTable()->delete(array('hometypeID = ?' => $id)); + } + } + + public function find($id, Application_Model_HomeType $hometype) + { + $result = $this->getDbTable()->find($id); + if (0 == count($result)) { + return; + } + + $row = $result->current(); + + $hometype->setID($row->hometypeID) + ->setName($row->name); + } + + public function fetchAll() + { + $resultSet = $this->getDbTable()->fetchAll(); + $entries = array(); + foreach ($resultSet as $row) { + $entry = new Application_Model_HomeType(); + + $entry->setID($row->hometypeID) + ->setName($row->name); + + $entries[] = $entry; + } + return $entries; + } + + public function compare(Application_Model_HomeType $v1,Application_Model_HomeType $v2){ + $vv1 = $v1->toArray(); + $vv2 = $v2->toArray(); + return array_diff($vv1,$vv2); + } + + + +} + -- cgit v1.2.3-55-g7522