Location: PHPKode > projects > pdfDOM > pdfdom-0.5/classes/class.table.php
<?php
/******************************************************************************
* File      	:	$RCSfile: class.table.php,v $
* Project   	:   pdfDOM
* Description	:   Table object
* Author    	:   Timo A. Hummel <hide@address.com>
* Created   	:   21.06.2005
* Modified  	:   $Date: 2005/06/23 11:31:04 $
*
* This file is part of the pdfDOM project.
*
* More information: 
* http://www.pdfdom.org
* http://www.sf.net/projects/pdfdom
*
* © four for business AG, www.4fb.de
*
* $Id: class.table.php,v 1.1 2005/06/23 11:31:04 timo_h Exp $
******************************************************************************/

class pdTable extends pdContainer
{
	var $_columns;
	var $_data;
	var $_containers;
	function pdTable ()
	{
		pdContainer::pdContainer();
		
		$this->_columns = array();
		$this->_data = array();
		$this->_templateContainer = null;
	}
	
	function setColumnWidth ($column, $width)
	{
		$this->_columns[$column] = $width;
	}
	
	function setTemplateContainer ($row = 0, $container = null)
	{
		$this->_templateContainer[$row] = $container;	
	}
	
	function setRow ($row)
	{
		$args = func_num_args();
		
		$rowdata = array();
		
		for ($i = 1; $i < $args; $i++)
		{
			$rowdata[$i] = func_get_arg($i);
		} 	
		
		$this->_data[$row] = $rowdata;
	}
	
	function getColumnWidth ($column)
	{
		if ($this->_columns[$column])
		{
			return $this->_columns[$column];
		} else {
			return 10;	
		}
	}
	
	function generate ()
	{
		$columns = $this->_getMaxColumns();
		foreach ($this->_data as $row => $data)
		{
			$nextstart = $this->coordinates->getX();
			
			for ($column = 1; $column < $columns + 1; $column++)
			{
				
				$pd = new pdTextContainer();
				
				if ($this->_templateContainer[0] !== null)
				{
					$pd = $this->_templateContainer[0];
					$pd->_createUUID();
				}
				
				if ($this->_templateContainer[$column] !== null)
				{
					$pd = $this->_templateContainer[$column];
					$pd->_createUUID();
				}
				

				$pd->coordinates->setXYWH($nextstart,0, $this->getColumnWidth($column), 0);
				
				if ($row == 1)
				{
					$pd->setRelative($this, "getY()", "moveY");
				} else {
					$pd->setRelative($this->_mcontainers[$row-1][$column], "getY1()", "moveY");
				
				}			
				
				$pd->setExpanding(true);
				$pd->setText($this->_data[$row][$column]);
				
				$this->_mcontainers[$row][$column] = $pd;
				$this->addContainer(&$this->_mcontainers[$row][$column]);
				$nextstart = $nextstart + $this->getColumnWidth($column);	
				
				unset($pd);	
			}	
		}	
		
		$this->preRender();
		$this->sizeCalc();
		
		foreach ($this->_data as $row => $data)
		{
			$maxHeight = 0;
			for ($column = 1; $column < $columns + 1; $column++)
			{
				
				if ($this->_mcontainers[$row][$column]->coordinates->getHeight() > $maxHeight)
				{
					$maxHeight = $this->_mcontainers[$row][$column]->coordinates->getHeight();
				}
			}

			for ($column = 1; $column < $columns + 1; $column++)
			{
				$this->_mcontainers[$row][$column]->coordinates->setHeight($maxHeight);
				$lastRow = $row;
				$lastColumn = $column;
			}

		}


		$this->preRender();
		$this->sizeCalc();		
		$this->coordinates->setX1Y1($this->_mcontainers[$lastRow][$lastColumn]->coordinates->getX1(), $this->_mcontainers[$lastRow][$lastColumn]->coordinates->getY1());
	}
	
	function _getMaxColumns ()
	{
		$maxCount = 0;
		
		foreach ($this->_data as $row => $data)
		{
			if (count($data) > $maxCount)
			{
				$maxCount = count($data);	
			}	
		}	
		
		return ($maxCount);
	}
}
?>
Return current item: pdfDOM