<?php
class MyWeb_File_Form_New extends MyWeb_File_Form_Abstract
{
	private $_addContent;
	/**
	 * 
	 * Metoda prida retezec do vysledneho souboru
	 * @param $content
	 */
	public function add_contentFile($content)
	{
		$this->_addContent = $content;
	}
	
	private function defaultSettings()
	{
		if (is_null($this->_describeTable)){
			$this->_describeTable = $this->_dbTable->get_describeTable();
		}
		$this->set_defaultColumn();
		$this->foreigenKey();
	}
	
	
	
	
	public function __construct($dbTable,$path = null)
	{
		$this->_dbTable = $dbTable;
		$this->_stringAddsLink = "";
		$this->defaultSettings();
		$this->_path = $path;	//*** pridano zajistuje pouziti nove cesty od uzivatele misto default
		$this->defaultSettingsPath($this->_default_path_form_php);
		$this->set_typeFile('php');
		$this->_currentPrefix = 1;
		if (0 === strcmp($this->_filename, 'none')){
			$this->_filename = $this->_dbTable->get_modelName();
		}
	}
	
	
	
	public function createContent()
	{
		$methodInit = new Zend_CodeGenerator_Php_Method();
		$methodInit	->setName('init');
		$methodInit->setBody(
					'$request = Zend_Controller_Front::getInstance()->getRequest();'	. "\n" .
					'ZendX_JQuery::enableForm($this);	// zapnuti jQuery'				. "\n" .
					'$getValue = $request->getParams();'								. "\n" .
					'$translate = Zend_Registry::get(\'Zend_Translate\');'				. "\n\n" .
					
					'// nastaví atributy formuláře' . "\n" .
					'$this->setAction("'.$this->prefix[$this->_currentPrefix].'");' . "\n" .
					'$this->setMethod("post");' . "\n" .
					'$this->setAttrib("id", "form_'.$this->_dbTable->get_modelName()."_".$this->prefix[$this->_currentPrefix].'");' . "\n".
		
					'//nacteni config souboru s definovan7mi fomularovymi prvky' . "\n" .
					'$config = new Zend_Config_Ini(APPLICATION_PATH . "/forms/'.$this->_dbTable->get_modelName().ucfirst($this->prefix[$this->_currentPrefix]).'.ini");' . "\n" .
					'$this->setConfig($config);' . "\n\n\n" .
		
		
					'//***************************************************************************'	. "\n".
					'// Nastaveni hidden elemetu'	. "\n\n\n\n".
		
		
		
					$this->_stringAddsLink.
									
									
					'// vytvoří formulářový prvek odesílací tlačítko' . "\n" .
					'$submitInsert = new Zend_Form_Element_Submit("send", array("label" => $translate->translate(\''.ucfirst($this->prefix[$this->_currentPrefix]).'\')));' . "\n\n" .
        			
					'// přidá formulářové prvky do formuláře' . "\n" .
        			'//$this->addElements(array());' . "\n" .
       				'$this->addDisplayGroup(array('.
       										"\n\t\t\t"."'".implode("',\n\t\t\t'", $this->_selectColumn)."'".
											"\n\t\t\t".'),\'formRoleEdit\',array(\'legend\' => $translate->translate(\''.ucfirst($this->prefix[$this->_currentPrefix]).ucfirst($this->_dbTable->get_modelName()).'\')));' . "\n" .
       				'$this->addElements(array('.
        								"\n\t\t\t".'$submitInsert,'.
										"\n\t\t\t".implode(",\n\t\t\t", $this->_listAddedElements)."\n\t\t\t));" . "\n" .
        			'$this->addElements(array($submitInsert));' . "\n"
			);
			$class = new Zend_CodeGenerator_Php_Class();
			$class	->setName('Application_Model_Form_'.ucfirst($this->_dbTable->get_modelName()).ucfirst($this->prefix[$this->_currentPrefix]).' extends MyWeb_Form')
					->setMethod($methodInit);
					
			$stringFile = "<?php \n ".$class;
		$this->set_contentFile($stringFile);
	}
}