summaryrefslogtreecommitdiffstats
path: root/application/models/EventtypeMapper.php
diff options
context:
space:
mode:
authorBjörn Geiger2011-08-22 12:31:48 +0200
committerBjörn Geiger2011-08-22 12:31:48 +0200
commitbdbf7625d172fa64e7694f3bf37eed642517bbe1 (patch)
tree9e7b2593693dde4d0c224169b6c189bafc7feb72 /application/models/EventtypeMapper.php
parentminor (diff)
downloadpoolctrl-bdbf7625d172fa64e7694f3bf37eed642517bbe1.tar.gz
poolctrl-bdbf7625d172fa64e7694f3bf37eed642517bbe1.tar.xz
poolctrl-bdbf7625d172fa64e7694f3bf37eed642517bbe1.zip
Datenbankänderung
Diffstat (limited to 'application/models/EventtypeMapper.php')
-rw-r--r--application/models/EventtypeMapper.php142
1 files changed, 142 insertions, 0 deletions
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 @@
+<?php
+
+class Application_Model_RunningtypeMapper
+{
+ protected $_dbTable;
+
+ public function findBy($where, $array=false, $order=false)
+ {
+ foreach($where as $k => $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;
+ }
+
+
+
+}
+