<?php
/**
 * trida auto model navaze spojeni s databází a vytvoří pole objektu tridy tableModel
 */
class MyWeb_DbTable_CreatorDbTable extends MyWeb_plugin
{

	/*
	 * neni dodelana validace vstupnich udaju
	 * chybi trida pro vyjimky ve vsech metodach
	 */
	private static $_dsn;					//udaje pro nastaveni adapteru
	private static $_db;
	private static $_dbTables;
	private static $_tableNames;
	
	/**
	 * 
	 * vytvori a vrati pole s dbTable
	 * @param unknown_type $table
	 * @param unknown_type $_dsn
	 */
	public static function loadDbTables($table,$dsn)
	{
        self::addLog('MyWeb_DbTable_CreatorDbTable',1,4,'ABSTRACT');
        self::showMe(self::showLog(),'LOG2');
        
        
        self::$_tableNames=$table;
        
        self::validationDsn($dsn);
        self::dbConect(self::$_dsn);
        self::autoCreateDbTable(self::$_tableNames);
        return self::$_dbTables;
	}
	
	/**
	 * validace dsn
	 * @param array $dsn
	 */
	private function validationDsn($dsn)
	{
		self::$_dsn=$dsn;
	}
	
	/**
	 * metoda inicializuje adapter na zaklade dsn
	 * @param array $dsn
	 */
	private function dbConect($dsn)
	{
		self::addLog('MyWeb_DbTable_CreatorDbTable',2,4,'ABSTRACT');
        self::showMe(self::showLog(),'LOG2');
        
		$db = Zend_Db::factory('Pdo_Mysql', $dsn);
		self::$_db=$db;
	}
	
	
	/**
	 * vytvori pole objektu dbTable
	 */
	private function autoCreateDbTable()
	{
		self::addLog('MyWeb_DbTable_CreatorDbTable',3,4,'ABSTRACT');
        self::showMe(self::showLog(),'LOG2');
        
		$pocetTabulek=0;
		for ($pocetTabulek=0; $pocetTabulek < count(self::$_tableNames); $pocetTabulek++){
			self::$_dbTables[$pocetTabulek]['table']=new MyWeb_DbTable_DbTable(self::$_tableNames[$pocetTabulek],self::$_db);
		}
	}
}