<?php 
class Application_Model_StateHasState extends MyWeb_Model_Database
{

    protected $_storageName = 'StateHasState';

    protected $_formClasses = array(
        'insert' => 'StateHasStateNew',
        'update' => 'StateHasStateEdit',
        'search' => 'StateHasStateSearch'
        );

    public function fetchEntry($id)
    {
        // databázový adaptér
        $db = $this->getStorage()->getAdapter();
        
        // vytvoří SELECT
        $select = $db->select();
        if (is_null($id)){
        	$select	->	from(array('S' => 'StateHasState'),
        						array('State_id_state'))
        ;
        }else {
        	$select	->	from(array('S' => 'StateHasState'),
        				array('State_id_state'))
        
        			->	where('S.State_id_state = ?',$id);
        }
        // načítá údaje
        //echo "<p>".$select."</p>";
        $data['data'] = $db->fetchRow($select);
        return $data;
    }

    public function fetchEntries($data)
    {
        // databázový adaptér
        $db = $this->getStorage()->getAdapter();
        
        // vytvoří SELECT
        $select = $db	->	select()
        				->	from(array('S' => 'StateHasState'),
        					array('State_id_state'))
        ;
        // načítá údaje
         if (is_null($data)){
        	//echo "<p>kompletni vypis</p>";
        }else {
        	if (array_key_exists('State_id_state', $data)){
        		if (!is_null($data['State_id_state']) && (strcmp($data['State_id_state'],"none") !== 0) && (strcmp($data['State_id_state'],"") !== 0)){
        			$select	->	where('S.State_id_state = ?',$data['State_id_state']); 
        		}
        	}
        
        }
        // načítá údaje
        //echo "<p>".$select."</p>";
        $data = $db->fetchAll($select);
        	return $data;
    }


}
