<?php
/**
 * DataGrid
 *
 * @date 21.03.2007
 * @name DataGrid
 * @author Margo Poolak <margo 'dot' poolak 'at' mail 'dot' ee>
 * @copyright Copyright &copy;2006 Margo Poolak. All Rights Reserved.
 * @version 2.0
 * @package System.Web.UI.WebControls
 * @category 
 * 
 * This is UI view 
 */
class DataGrid extends HtmlControl
{
	protected $dataSource;
	/*
	*
	*/
	public function __construct()
	{
	}
	/*
	*
	*/
	public function setDataSource($dataSource)
	{
		if(is_array($dataSource) OR is_object($dataSource))
			$this->dataSource = $dataSource;
		else
			trigger_error('Datasource must be an array or object',E_USER_ERROR);
	}
	/*
	*
	*/
	public function render()
	{
		$table = new TTable();
		
		foreach($this->dataSource as $value)
		{
			if(is_array($value->fields))
			{
				$columns= 1;
				$row = new TTableRow();$row->setClass('red');
				foreach($value->fields as $key=>$value)
				{
					$cell = new TTableHeaderCell();
					$cell->Text = utf8_encode($value);
					$row->Cells->add($cell);
					$columns++;
				}
				$table->Rows->add($row);
			}
		}
		
		for($i=1;$i<=$columns;$i++)
		{
			$row = new TTableRow();$row->setClass('red');
			
			$cell = new TTableCell();$cell->Text = $i;$row->Cells->add($cell);
			
			$cell = new TTableCell();$cell->Text = "Nimi";$row->Cells->add($cell);
			
			$cell = new TTableCell();$cell->Text = "Perenimi";$row->Cells->add($cell);
			
			$table->Rows->add($row);
		}
		
		return $table->render();	
	}
}
?>