<?php 
class Application_Model_Subjectlevel extends MyWeb_Model_Database
{

    protected $_storageName = 'Subjectlevel';

    protected $_formClasses = array(
        'insert' => 'subjectlevelNew',
        'update' => 'subjectlevelEdit',
        'search' => 'subjectlevelSearch'
        );

    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' => 'subjectlevel'),
        						array('id_subjectLevel','subjectLevel_name','State_id_state'))
        
        					->	join(array('S' => 'State'),
        						'S.State_id_state=S.id_state',
        						array('id_state','state_state','NameState_id_NameState','TableDatabase_id_tableDatabase'));
        }else {
        	$select	->	from(array('S' => 'subjectlevel'),
        				array('id_subjectLevel','subjectLevel_name','State_id_state'))
        
        					->	join(array('S' => 'State'),
        						'S.State_id_state=S.id_state',
        						array('id_state','state_state','NameState_id_NameState','TableDatabase_id_tableDatabase'))
        			->	where('S.id_subjectLevel = ?',$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' => 'subjectlevel'),
        					array('id_subjectLevel','subjectLevel_name','State_id_state'))
        
        					->	join(array('S' => 'State'),
        						'S.State_id_state=S.id_state',
        						array('id_state','state_state','NameState_id_NameState','TableDatabase_id_tableDatabase'));
        // načítá údaje
         if (is_null($data)){
        	//echo "<p>kompletni vypis</p>";
        }else {
        	if (array_key_exists('id_subjectLevel', $data)){
        		if (!is_null($data['id_subjectLevel']) && (strcmp($data['id_subjectLevel'],"none") !== 0) && (strcmp($data['id_subjectLevel'],"") !== 0)){
        			$select	->	where('S.id_subjectLevel = ?',$data['id_subjectLevel']); 
        		}
        	}
        
        	if (array_key_exists('subjectLevel_name', $data)){
        		if (!is_null($data['subjectLevel_name']) && (strcmp($data['subjectLevel_name'],"none") !== 0) && (strcmp($data['subjectLevel_name'],"") !== 0)){
        			$select	->	where('S.subjectLevel_name = ?',$data['subjectLevel_name']); 
        		}
        	}
        
        	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;
    }


}
