<?php
class MyWeb_File_DbTable_DbTable extends MyWeb_File_DbTable_Abstract
{
	
	/*
	 * trida nema zadne nastaveni protoze veskere nastaveni se provadi v DbTable
	 */
	
	private function defaultSettings()
	{
		if (is_null($this->_describeTable)){
			$this->_describeTable = $this->_dbTable->get_describeTable();
		}
	}
	
	
	
	
	public function __construct($dbTable,$path = null)
	{
		$this->_dbTable = $dbTable;
		$this->defaultSettings();
		$this->_path = $path;	//*** pridano zajistuje pouziti nove cesty od uzivatele misto default
		$this->defaultSettingsPath($this->_default_path_model_table_php);
		$this->set_typeFile('php');
		$this->_currentPrefix = 0;
		if (0 === strcmp($this->_filename, 'none')){
			$this->_filename = $this->_dbTable->get_modelName();
		}
	}
	
	/**
	 * 
	 * Metoda prida retezec do vysledneho souboru
	 * @param $content
	 */
	public function add_contentFile($content)
	{
		$this->_addContent = $content;
	}
	
	/**
     *  createModelTable
     *  
     *  create class and files of DbTable
     */
	public function createContent()
	{
		$stringFile = "<?php \n";
		//**************************************************************************************
		//**************************************************************************************
			//protoze vraci pole, ve kterem se potrebuju pohzbovat indxem
        	$modelPrimary = $this->_dbTable->get__modelPrimary();
        	$modelReferenceMap = $this->_dbTable->get_modelReferenceMap();
        	$modelRefTableClass = $this->_dbTable->get_modelRefTableClass();
        	
			//	sestaveni retezce zapisovaneho do souboru
			$stringFile="<?php\n";
			$stringFile.="class ".$this->createPrefixPath().ucwords($this->_dbTable->get_modelName())." extends Zend_Db_Table_Abstract\n";
			$stringFile.="{\n";
			$stringFile.="protected \$_name = '".$this->_dbTable->get_modelName()."';\n";
		
			//      Cyklus pro sestaveni stringu primarnich klicu
			if(count($this->_dbTable->get__modelPrimary())>0){
				$pocetPrimaryKey=0;
				for ($pocetPrimaryKey;$pocetPrimaryKey<count($this->_dbTable->get__modelPrimary());$pocetPrimaryKey++)
				{
					if ($pocetPrimaryKey==0){
						$stringFile.="protected \$_primary = array('".$modelPrimary[$pocetPrimaryKey]."'";
					}
					if($pocetPrimaryKey!=0){
						$stringFile.=" ,'".$modelPrimary[$pocetPrimaryKey]."'";
					}
				}
				$stringFile.=");\n\n";
			}
		
			//cyklus pro sestaveni stringu cizych klicu
			if (count($this->_dbTable->get_modelReferenceMap())>0){
				$pocetFk=0;
				for($pocetFk=0;$pocetFk<count($this->_dbTable->get_modelReferenceMap());$pocetFk++)
				{
					if ($pocetFk==0){$stringFile.="protected \$_referenceMap = array(\n";}
					$stringFile.="\t\t\t'".$this->createPrefixPath().ucwords($modelRefTableClass[$pocetFk])."'=>array(\n";
					$stringFile.="\t\t\t\t\t\t'columns'=>'".$modelReferenceMap[$modelRefTableClass[$pocetFk]]['columns']."',\n";
					$stringFile.="\t\t\t\t\t\t'refTableClass'=>'".$this->createPrefixPath().ucwords($modelReferenceMap[$modelRefTableClass[$pocetFk]]['refTableClass'])."',\n";
					$stringFile.="\t\t\t\t\t\t'refColumns'=>'".$modelReferenceMap[$modelRefTableClass[$pocetFk]]['refColumns']."'\n";
					$stringFile.="\t\t\t\t\t\t),\n";
				}
				$stringFile.="\t\t\t);\n";
			}
			$stringFile.="}\n";
			$this->set_contentFile($stringFile);
	}
}