From 8ceb7bad18f257127ad5790a9c0ec157d7e03f4d Mon Sep 17 00:00:00 2001 From: michael pereira Date: Mon, 4 Apr 2011 17:12:48 +0200 Subject: WICHTIG findBy Methode geƤndert & alles angepasst, siehe Ticket --- application/models/ClientMapper.php | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) (limited to 'application/models/ClientMapper.php') diff --git a/application/models/ClientMapper.php b/application/models/ClientMapper.php index 2c23cfc..a86f4b0 100644 --- a/application/models/ClientMapper.php +++ b/application/models/ClientMapper.php @@ -5,16 +5,43 @@ class Application_Model_ClientMapper protected $_dbTable; - public function findBy($criteria, $value) + 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($criteria . ' = ?', $value); + ->where($where); + + if(is_array($order)){ + foreach ($order as $k => $v) + $a[] = "$k $v"; + $select->order($a); + } + $stmt = $select->query(); $result = $stmt->fetchAll(); - return $result; + + if(!$array){ + $entries = array(); + foreach ($result as $row) { + $entry = new Application_Model_Client($row); + $entry->setID($row['clientID']); + $entries[] = $entry; + } + return $entries; + }else{ + return $result; + } + }catch (Zend_Exception $e) { echo "Error message 2: " . $e->getMessage() . "\n"; } -- cgit v1.2.3-55-g7522