From bdbf7625d172fa64e7694f3bf37eed642517bbe1 Mon Sep 17 00:00:00 2001 From: Björn Geiger Date: Mon, 22 Aug 2011 12:31:48 +0200 Subject: Datenbankänderung --- application/models/EventtypeMapper.php | 142 +++++++++++++++++++++++++++++++++ 1 file changed, 142 insertions(+) create mode 100644 application/models/EventtypeMapper.php (limited to 'application/models/EventtypeMapper.php') diff --git a/application/models/EventtypeMapper.php b/application/models/EventtypeMapper.php new file mode 100644 index 0000000..d1e2740 --- /dev/null +++ b/application/models/EventtypeMapper.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(); + if(count($result) > 0) { + foreach ($result as $row) { + $entry = new Application_Model_Eventtype($row); + $entry->setID($row['eventtypeID']); + $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_Eventtype'); + } + + return $this->_dbTable; + } + + public function save(Application_Model_Eventtype $eventtype) + { + + $data = array('eventtypeID'=> $eventtype->getID() ,'title'=> $eventtype->getTitle() ); + + if (null === ($id = $eventtype->getID()) ) { + unset($data['eventtypeID']); + $this->getDbTable()->insert($data); + } else { + $this->getDbTable()->update($data, array('eventtypeID = ?' => $id)); + } + } + + public function delete(Application_Model_Eventtype $eventtype) + { + if (null === ($id = $eventtype->getID()) ) { + return; + } else { + $this->getDbTable()->delete(array('eventtypeID = ?' => $id)); + } + } + + public function find($id, Application_Model_Eventtype $eventtype) + { + $result = $this->getDbTable()->find($id); + if (0 == count($result)) { + return; + } + + if($eventtype == null) { + $return = true; + } + + $row = $result->current(); + + if($return) { + $eventtype = new Application_Model_Eventtype(); + $eventtype + ->setID($row->eventtypeID) + ->setTitle($row->title); + return $eventtype; + } else { + $eventtype + ->setID($row->eventtypeID) + ->setTitle($row->title); + } + } + + public function fetchAll() + { + $resultSet = $this->getDbTable()->fetchAll(); + $entries = array(); + foreach ($resultSet as $row) { + $entry = new Application_Model_Eventtype(); + + $entry + ->setID($row->eventtypeID) + ->setTitle($row->title); + + $entries[] = $entry; + } + return $entries; + } + + + +} + -- cgit v1.2.3-55-g7522