diff options
Diffstat (limited to 'application/models/PreBootMapper.php')
| -rw-r--r-- | application/models/PreBootMapper.php | 37 |
1 files changed, 28 insertions, 9 deletions
diff --git a/application/models/PreBootMapper.php b/application/models/PreBootMapper.php index 6053b19..28b8b04 100644 --- a/application/models/PreBootMapper.php +++ b/application/models/PreBootMapper.php @@ -5,25 +5,44 @@ class Application_Model_PreBootMapper 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(); - $entries = array(); - foreach ($result as $row) { - - $entry = new Application_Model_PreBoot($row); - $entry->setID($row['prebootID']); - $entries[] = $entry; + if(!$array){ + $entries = array(); + foreach ($result as $row) { + $entry = new Application_Model_PreBoot($row); + $entry->setID($row['prebootID']); + $entries[] = $entry; + } + return $entries; + }else{ + return $result; } - return $entries; + }catch (Zend_Exception $e) { echo "Error message 2: " . $e->getMessage() . "\n"; } |
