<?php 
class Application_Model_Table3 extends MyWeb_Model_Database
{

    protected $_storageName = 'Table3';

    protected $_formClasses = array(
        'insert' => 'table3New',
        'update' => 'table3Edit',
        'search' => 'table3Search'
        );

    public function fetchEntries($dataInput)
    {
        // databázový adaptér
        $db = $this->getStorage()->getAdapter();
        $select = $this->createFetchEntrySelect($dataInput);
        
        
        
        // načítá údaje
        $this->showMe($select, 'Q');
        $data = $db->fetchAll($select);
        return $data;
    }

    public function fetchEntry($id)
    {
        // databázový adaptér
        $db = $this->getStorage()->getAdapter();
        
        // vytvoří SELECT
        $select = $db->select();
        if (is_null($id)){
        	$select	->	from(array('T3' => 'table3'),
        						array('id_table3','table3_column1','table3_column2','table3_column3'))
        ;
        }else {
        	$select	->	from(array('T3' => 'table3'),
        				array('id_table3','table3_column1','table3_column2','table3_column3'))
        
        				->	where('T3.id_table3 = ?',$id);
        }
        // načítá údaje
        $this->showMe($select, 'Q');
        $db->setFetchMode(Zend_Db::FETCH_ASSOC);
        $data['data'] = $db->fetchRow($select);
        return $data;
    }

    public function getFetchEntrySelect($data)
    {
        $select = $this->createFetchEntrySelect($data);
        $select = $this->createWhere($select, $data, " ");
        return $select;
    }

    public function createFetchEntrySelect($data)
    {
        // databázový adaptér
        $db = $this->getStorage()->getAdapter();
        
        // vytvoří SELECT
        $select = $db	->	select()
        				->	from(array('T3' => 'table3'),
        					array('id_table3','table3_column1','table3_column2','table3_column3'))
        ;
        
        // načítá údaje
         if (is_null($data)){
        	$this->showMe('kompletni vypis', 'info');
        }else {
        
        	if (array_key_exists('id_table3',$data)){
        		if (!empty($data['id_table3']) && (strcmp($data['id_table3'],"none") !== 0) && (strcmp($data['id_table3'],"") !== 0)){
        			$select	->	where('T3.id_table3 = ?',$data['id_table3']); 
        		}
        	}
        
        	if (array_key_exists('table3_column1',$data)){
        		if (!empty($data['table3_column1']) && (strcmp($data['table3_column1'],"none") !== 0) && (strcmp($data['table3_column1'],"") !== 0)){
        			$select	->	where('T3.table3_column1 = ?',$data['table3_column1']); 
        		}
        	}
        
        	if (array_key_exists('table3_column2',$data)){
        		if (!empty($data['table3_column2']) && (strcmp($data['table3_column2'],"none") !== 0) && (strcmp($data['table3_column2'],"") !== 0)){
        			$select	->	where('T3.table3_column2 = ?',$data['table3_column2']); 
        		}
        	}
        
        	if (array_key_exists('table3_column3',$data)){
        		if (!empty($data['table3_column3']) && (strcmp($data['table3_column3'],"none") !== 0) && (strcmp($data['table3_column3'],"") !== 0)){
        			$select	->	where('T3.table3_column3 = ?',$data['table3_column3']); 
        		}
        	}
        
        }
        $this->showMe($select, 'Q');
        return $select;
    }


}
