<?php 
class Application_Model_Namestate extends MyWeb_Model_Database
{

    protected $_storageName = 'Namestate';

    protected $_formClasses = array(
        'insert' => 'namestateNew',
        'update' => 'namestateEdit',
        'search' => 'namestateSearch'
        );

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


}
