summaryrefslogblamecommitdiffstats
path: root/application/models/BootMenuMapper.php
blob: fa9b8a7fb6132227f54a123156f442dbb1f3088f (plain) (tree)
1
2
3
4
5
6
7



                                      

                            
 




                                                  
 











                                                                                   
                                                                                




                                       
                                                                 

                
                                                                                                                                                                                     
 
                                                          
                                                  

                                                           









                                                                                          


                 
                                                                      







                                                         
                                                                                                                                           








                                                                  
                                                                                                                                                        


                                            




                                

 
<?php

class Application_Model_BootMenuMapper
{
	
	protected $_dbTable;

	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_BootMenu');
		}
		
		return $this->_dbTable;
	}

	public function save(Application_Model_BootMenu $botmenu)
	{
		
		$data = array('bootmenuID'=> $botmenu->getBootmenuID() ,'membershipID'=> $botmenu->getMembershipID() ,'title'=> $botmenu->getTitle() ,'time'=> $botmenu->getTime() );

		if (null === ($id = $botmenu->getID()) ) {
			unset($data['botmenuID']);
			$this->getDbTable()->insert($data);
		} else {
			$this->getDbTable()->update($data, array('botmenuID = ?' => $id));
		}
	}
	
	public function delete(Application_Model_BootMenu $botmenu)
	{
		if (null === ($id = $botmenu->getID()) ) {
			return;
		} else {
			$this->getDbTable()->delete(array('botmenuID = ?' => $id));
		}
	}

	public function find($id, Application_Model_BootMenu $botmenu)
	{
		$result = $this->getDbTable()->find($id);
		if (0 == count($result)) {
			return;
		}

		$row = $result->current();
		
		$botmenu->setBootmenuID($row->bootmenuID)->setMembershipID($row->membershipID)->setTitle($row->title)->setTime($row->time);
	}

	public function fetchAll()
	{
		$resultSet = $this->getDbTable()->fetchAll();
		$entries   = array();
		foreach ($resultSet as $row) {
			$entry = new Application_Model_BootMenu();
			
			$entry->setBootmenuID($row->bootmenuID)->setMembershipID($row->membershipID)->setTitle($row->title)->setTime($row->time);	

			$entries[] = $entry;
		}
		return $entries;
	}


	
}