<?php 
class Application_Model_Table1hastable2 extends MyWeb_Model_Database
{

    protected $_storageName = 'Table1hastable2';

    protected $_formClasses = array(
        'insert' => 'table1hastable2New',
        'update' => 'table1hastable2Edit',
        'search' => 'table1hastable2Search'
        );

    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('T2' => 'table1hastable2'),
        						array('table1_id_table1'))
        ;
        }else {
        	$select	->	from(array('T2' => 'table1hastable2'),
        				array('table1_id_table1'))
        
        				->	where('T2.table1_id_table1 = ?',$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('T2' => 'table1hastable2'),
        					array('table1_id_table1'))
        ;
        
        // načítá údaje
         if (is_null($data)){
        	$this->showMe('kompletni vypis', 'info');
        }else {
        
        	if (array_key_exists('table1_id_table1',$data)){
        		if (!empty($data['table1_id_table1']) && (strcmp($data['table1_id_table1'],"none") !== 0) && (strcmp($data['table1_id_table1'],"") !== 0)){
        			$select	->	where('T2.table1_id_table1 = ?',$data['table1_id_table1']); 
        		}
        	}
        
        }
        $this->showMe($select, 'Q');
        return $select;
    }


}
