From 74d2e51da636f8ec981a0b004efb7e1f04b08e08 Mon Sep 17 00:00:00 2001 From: Björn Geiger Date: Fri, 19 Aug 2011 00:45:34 +0200 Subject: verschiedene Datenbankänderungen --- application/models/DbTable/Reporttype.php | 20 ++++ application/models/Event.php | 12 +++ application/models/EventMapper.php | 8 +- application/models/Eventreport.php | 12 +++ application/models/EventreportMapper.php | 10 +- application/models/Reporttype.php | 111 ++++++++++++++++++++++ application/models/ReporttypeMapper.php | 148 ++++++++++++++++++++++++++++++ 7 files changed, 314 insertions(+), 7 deletions(-) create mode 100644 application/models/DbTable/Reporttype.php create mode 100644 application/models/Reporttype.php create mode 100644 application/models/ReporttypeMapper.php (limited to 'application/models') diff --git a/application/models/DbTable/Reporttype.php b/application/models/DbTable/Reporttype.php new file mode 100644 index 0000000..fe62330 --- /dev/null +++ b/application/models/DbTable/Reporttype.php @@ -0,0 +1,20 @@ +_pbs_filterID = $_pbs_filterID; return $this; } + + public function getRunning() + { + return $this->_running; + } + + public function setRunning($_running) + { + $this->_running = $_running; + return $this; + } } diff --git a/application/models/EventMapper.php b/application/models/EventMapper.php index 394fea2..a2648a0 100644 --- a/application/models/EventMapper.php +++ b/application/models/EventMapper.php @@ -85,7 +85,7 @@ class Application_Model_EventMapper public function save(Application_Model_Event $event) { - $data = array('eventID'=> $event->getID() ,'category'=> $event->getCategory() ,'title'=> $event->getTitle(), 'pbs_membershipID'=> $event->getPbs_membershipID(),'end'=> $event->getEnd() ,'immediate'=> $event->getImmediate() ,'note'=> $event->getNote() ,'participants'=> $event->getParticipants() ,'pbs_bootosID'=> $event->getPbs_bootosID(),'pbs_poolID'=> $event->getPbs_poolID(),'repeat'=> $event->getRepeat(),'start'=> $event->getStart(),'pbs_bootmenuID'=> $event->getPbs_bootmenuID(),'pbs_filterID'=> $event->getPbs_filterID() ); + $data = array('eventID'=> $event->getID() ,'category'=> $event->getCategory() ,'title'=> $event->getTitle(), 'pbs_membershipID'=> $event->getPbs_membershipID(),'end'=> $event->getEnd() ,'immediate'=> $event->getImmediate() ,'note'=> $event->getNote() ,'participants'=> $event->getParticipants() ,'pbs_bootosID'=> $event->getPbs_bootosID(),'pbs_poolID'=> $event->getPbs_poolID(),'repeat'=> $event->getRepeat(),'start'=> $event->getStart(),'pbs_bootmenuID'=> $event->getPbs_bootmenuID(),'pbs_filterID'=> $event->getPbs_filterID(), 'running' => $event->getRunning() ); if (null === ($id = $event->getID()) ) { unset($data['eventID']); return $this->getDbTable()->insert($data); @@ -130,7 +130,8 @@ class Application_Model_EventMapper ->setPbs_filterID($row->pbs_filterID) ->setPbs_bootmenuID($row->pbs_bootmenuID) ->setRepeat($row->repeat) - ->setStart($row->start); + ->setStart($row->start) + ->setRunning($row->running); } public function fetchAll() @@ -155,7 +156,8 @@ class Application_Model_EventMapper ->setPbs_filterID($row->pbs_filterID) ->setPbs_bootmenuID($row->pbs_bootmenuID) ->setRepeat($row->repeat) - ->setStart($row->start); + ->setStart($row->start) + ->setRunning($row->running); $entries[$row->eventID] = $entry; } diff --git a/application/models/Eventreport.php b/application/models/Eventreport.php index 3b9d11d..7b72ab0 100644 --- a/application/models/Eventreport.php +++ b/application/models/Eventreport.php @@ -14,6 +14,7 @@ class Application_Model_Eventreport { protected $_reportID; protected $_report; + protected $_type; protected $_eventID; public function __construct(array $options = null) @@ -119,5 +120,16 @@ class Application_Model_Eventreport $this->_eventID = $_eventID; return $this; } + + public function geType() + { + return $this->_type; + } + + public function setType($_type) + { + $this->_type = $_type; + return $this; + } } diff --git a/application/models/EventreportMapper.php b/application/models/EventreportMapper.php index 8ea9a28..19b2977 100644 --- a/application/models/EventreportMapper.php +++ b/application/models/EventreportMapper.php @@ -39,7 +39,7 @@ class Application_Model_EventreportMapper $stmt = $select->query(); $result = $stmt->fetchAll(); - if(!$array){ + if(!$array){ $entries = array(); if(count($result) > 0) { foreach ($result as $row) { @@ -84,7 +84,7 @@ class Application_Model_EventreportMapper public function save(Application_Model_Eventreport $eventreport) { - $data = array('reportID'=> $eventreport->getID() ,'eventID'=> $eventreport->getEventID() ,'report'=> $eventreport->getReport() ); + $data = array('reportID'=> $eventreport->getID() ,'eventID'=> $eventreport->getEventID() ,'report'=> $eventreport->getReport(), 'type' => $eventreport->geType() ); if (null === ($id = $eventreport->getID()) ) { unset($data['reportID']); return $this->getDbTable()->insert($data); @@ -118,7 +118,8 @@ class Application_Model_EventreportMapper $eventreport ->setID($row->reportID) ->setEventID($row->eventID) - ->setReport($row->report); + ->setReport($row->report) + ->setType($row->type); } public function fetchAll() @@ -131,7 +132,8 @@ class Application_Model_EventreportMapper $entry ->setID($row->reportID) ->setEventID($row->eventID) - ->setReport($row->report); + ->setReport($row->report) + ->setType($row->type); $entries[$row->reportID] = $entry; } diff --git a/application/models/Reporttype.php b/application/models/Reporttype.php new file mode 100644 index 0000000..794e3f4 --- /dev/null +++ b/application/models/Reporttype.php @@ -0,0 +1,111 @@ +setOptions($options); + } + } + + public function __set($name, $value) + { + $method = 'set' . $name; + if (('mapper' == $name) || !method_exists($this, $method)) { + throw new Exception('Invalid reporttype property'); + } + $this->$method($value); + } + + public function __get($name) + { + $method = 'get' . $name; + if (('mapper' == $name) || !method_exists($this, $method)) { + throw new Exception('Invalid reporttype 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; + } + + /** + * 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; + } + + public function getID() + { + return $this->_reporttypeID; + } + public function setID($_reporttypeID) + { + $this->reporttypeID = $_reporttypeID; + return $this; + } + + public function getTitle() + { + return $this->_title; + } + + public function setTitle($_title) + { + $this->_title = $_title; + return $this; + } +} + diff --git a/application/models/ReporttypeMapper.php b/application/models/ReporttypeMapper.php new file mode 100644 index 0000000..fbbd95a --- /dev/null +++ b/application/models/ReporttypeMapper.php @@ -0,0 +1,148 @@ + $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_Event($row); + $entry->setID($row['reporttypeID']); + $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_Reporttype'); + } + + return $this->_dbTable; + } + + public function save(Application_Model_Reporttype $reporttype) + { + $data = array('reporttypeID'=> $reporttype->getID() ,'title'=> $reporttype->getTitle() ); + if (null === ($id = $reporttype->getID()) ) { + unset($data['reporttypeID']); + return $this->getDbTable(F)->insert($data); + } else { + $this->getDbTable()->update($data, array('reporttypeID = ?' => $id)); + } + } + + public function delete(Application_Model_Reporttype $reporttype) + { + if (null === ($id = $reporttype->getID()) ) { + return; + } else { + $this->getDbTable()->delete(array('reporttypeID = ?' => $id)); + } + } + + public function find($id, Application_Model_Reporttype $reporttype = null) + { + $result = $this->getDbTable()->find($id); + if (0 == count($result)) { + return; + } + + $row = $result->current(); + + if($reporttype == null){ + $reporttype = new Application_Model_Reporttype(); + } + + $reporttype + ->setID($row->reporttypeID) + ->setTitle($row->title); + } + + public function fetchAll() + { + $resultSet = $this->getDbTable()->fetchAll(); + $entries = array(); + foreach ($resultSet as $row) { + $entry = new Application_Model_Reporttype(); + + $entry + ->setID($row->reporttypeID) + ->setTitle($row->title); + + $entries[$row->reporttypeID] = $entry; + } + return $entries; + } + + public function compare(Application_Model_Reporttype $v1,Application_Model_Reporttype $v2){ + $vv1 = $v1->toArray(); + $vv2 = $v2->toArray(); + return array_diff($vv1,$vv2); + } + + + +} \ No newline at end of file -- cgit v1.2.3-55-g7522