X-Git-Url: https://git.llucax.com/mecon/meconlib.git/blobdiff_plain/8f02488239ef8055330bf3952e8ef8b32b325fda..1aa774a935f76496935ec5b00c00dcef4cd7288e:/lib/MECON/PDF/Tabla.php diff --git a/lib/MECON/PDF/Tabla.php b/lib/MECON/PDF/Tabla.php index db39cd7..bbe535c 100644 --- a/lib/MECON/PDF/Tabla.php +++ b/lib/MECON/PDF/Tabla.php @@ -24,42 +24,59 @@ Autor: Martin Marrese $Id$ -----------------------------------------------------------------------------*/ -require_once 'MECON/PDF/Marco.php'; +require_once 'MECON/PDF/Contenido.php'; /** * Libreria que permite agregar una tabla a un pdf. */ -class MECON_PDF_Tabla extends MECON_PDF_Marco { - +class MECON_PDF_Tabla extends MECON_PDF_Contenido { + + /** + * Configuracion + * @var array $config + * @access protected + */ + var $_config; + + /** + * Objeto MECON_HTML_Tabla. + * @var &Object $tabla MECON_HTML_Tabla + * @access protected + */ + var $_tabla; + /** - * Funcion que envia el archivo a pantalla (para que el usuario haga un - * download) + * Objeto MECON_PDF_Marco + * @var &Object $marco + * @access protected + */ + var $_marco; + + /** + * Class Constructor * - * @return string + * @param &Object $TABLA MECON_HTML_Tabla + * + * @return void * @access public */ - function display() { - if ($this->getRowCount()) { - $this->_agregarContenido(); - - //Agrego los encabezados - $t = true; - foreach ($this->_pdf->getPages() as $page) { - $this->_pdf->_pagina_actual = $page; - $this->buildPage($t, $t); - $t = false; - } - //}}} - } - else { - $this->_pdf->newPage($this->_tamanio); - $this->_pdf->addText($this->_config['Xi'], - $this->_config['contenido']['Y'], - 'No hay contenido para mostrar.', - $this->_config['contenido']); - $this->buildPage(); - } - $this->_pdf->display(); + function MECON_PDF_Tabla(&$TABLA) { + $this->_tabla =& $TABLA; + $this->_config = include 'MECON/PDF/Tabla/medidas.php'; + } + + /** + * Funcion que agrega el contenido de la tabla que se este utilizando al + * PDF. + * + * @param &Object $MARCO MECON_PDF_Marco + * + * @return void + * @access public + */ + function toPDF(&$MARCO) { + $this->_marco =& $MARCO; + $this->_agregarContenido(); } /** @@ -77,13 +94,13 @@ class MECON_PDF_Tabla extends MECON_PDF_Marco { */ function _obtenerAlineacionTexto($row, $col, $texto, $attr, $estilo) { - $at = $this->getCellAttributes($row, $col); + $at = $this->_tabla->getCellAttributes($row, $col); if (@$at['align'] == 'center') { - $tam = $this->_pdf->strlen($texto, $estilo); + $tam = $this->_marco->strlen($texto, $estilo); $init = $attr[$col] + ($attr[$col+1] - $attr[$col] - $tam) / 2; } elseif (@$at['align'] == 'right') { - $tam = $this->_pdf->strlen($texto, $estilo); + $tam = $this->_marco->strlen($texto, $estilo); $init = $attr[$col+1] - $tam + 1; } else { @@ -102,7 +119,7 @@ class MECON_PDF_Tabla extends MECON_PDF_Marco { * @access protected */ function _obtenerEstiloCelda($row, $col) { - $clase = $this->getCellAttributes($row, $col); + $clase = $this->_tabla->getCellAttributes($row, $col); if (@$clase['cabecera'] || @$clase['oscura']) { $estilo = $this->_config['celda_cabecera']; } @@ -122,22 +139,21 @@ class MECON_PDF_Tabla extends MECON_PDF_Marco { * @access protected */ function _obtenerAnchoColumnas() { - $ancho_pagina = abs($this->_config['Xf'] - - $this->_config['Xi']) ; - for ($i=0; $i<$this->getColCount(); $i++ ) { - $tmp = $this->getCellAttributes(0,$i); + $ancho_pagina = $this->_marco->getWidth($this->_marco->orientacion); + for ($i=0; $i<$this->_tabla->getColCount(); $i++ ) { + $tmp = $this->_tabla->getCellAttributes(0,$i); if (is_null(@$tmp['width'])) { die ('Todas las columnas deben tener asignado un ancho.'); } $attr[$i] = intval($tmp['width']); } $tmp = array_sum($attr); - $attr2[0] = $this->_config['Xi']; + $attr2[0] = 0; for ($i=1; $i_config['Xf']; + $attr2[$i] = $ancho_pagina; return $attr2; } @@ -148,37 +164,40 @@ class MECON_PDF_Tabla extends MECON_PDF_Marco { * @access protected */ function _agregarContenido() { - $this->_pdf->newPage($this->_tamanio); - $alto = $this->_getAvailableSpace($this->_pdf->numPage()); + $alto = $this->_marco->espacioDisponible; + if ($alto <= 0 ) { + $this->_marco->newPage($this->_marco->tamanio); + } + //\@TODO Aca antes de crear una nueva pagina utilizar la que ya existe $attr2 = $this->_obtenerAnchoColumnas(); - for ($i = 0; $i < $this->getRowCount(); $i++) { + for ($i = 0; $i < $this->_tabla->getRowCount(); $i++) { $max = 0; - for ($j = 0; $j < $this->getColCount(); $j++) { + for ($j = 0; $j < $this->_tabla->getColCount(); $j++) { $estilo = $this->_obtenerEstiloCelda($i, $j); - $txt = $this->_pdf->wordWrap($this->getCellContents($i,$j), + $txt = $this->_marco->wordWrap($this->_tabla->getCellContents($i,$j), $attr2[$j+1] - $attr2[$j], $estilo); $txtt[$j] = $txt; //Esto es para no hacer el wordWrap siempre $max = max($estilo['alto_linea'] * count($txt), $max); $rep = array (); - $rep = $this->getCellAttributes($i, $j); + $rep = $this->_tabla->getCellAttributes($i, $j); if (@$rep['cabecera'] || @$rep['titulo']) { $repetir[$i][$j] = $txt; $repetir[$i]['max'] = $max; } } - if ($alto < $this->_config['Yi']) { - $this->_pdf->newPage($this->_tamanio); - $alto = $this->_getAvailableSpace($this->_pdf->numPage()); + if ($alto <= 0) { + $this->_marco->newPage($this->_marco->tamanio); + $alto = $this->_marco->espacioDisponible; foreach ($repetir as $ii => $value) { $alto -= $repetir[$ii]['max']; - for ($jj = 0; $jj < $this->getColCount(); $jj++) { + for ($jj = 0; $jj < $this->_tabla->getColCount(); $jj++) { $estilo = $this->_obtenerEstiloCelda($ii, $jj); - $this->_pdf->addRectangle($alto, $attr2[$jj], - $alto+$repetir[$ii]['max'], - $attr2[$jj+1], @$estilo['fill']); + $this->_marco->addRectangle($attr2[$jj], $alto, + $attr2[$jj+1], $alto+$repetir[$ii]['max'], + @$estilo['fill'], null, $this->_marco->orientacion); $alto1 = $alto + $repetir[$ii]['max']; foreach ($repetir[$ii][$jj] as $t) { @@ -188,8 +207,8 @@ class MECON_PDF_Tabla extends MECON_PDF_Marco { $init = $this->_obtenerAlineacionTexto($ii, $jj, $t, $attr2, $estilo); - $this->_pdf->addText($init, $alto1 + 2, - $t, $estilo); + $this->_marco->addText($init, $alto1 + 2, + $t, $estilo, null, $this->_marco->orientacion); } } } @@ -197,13 +216,13 @@ class MECON_PDF_Tabla extends MECON_PDF_Marco { } $alto -= $max; - for ($j = 0; $j < $this->getColCount(); $j++) { + for ($j = 0; $j < $this->_tabla->getColCount(); $j++) { $estilo = $this->_obtenerEstiloCelda($i, $j); - $this->_pdf->addRectangle($alto, $attr2[$j], - $alto+$max, - $attr2[$j+1], @$estilo['fill']); + $this->_marco->addRectangle($attr2[$j], $alto, + $attr2[$j+1], $alto+$max, @$estilo['fill'], null, + $this->_marco->orientacion); $alto1 = $alto + $max; foreach ($txtt[$j] as $t) { @@ -213,11 +232,12 @@ class MECON_PDF_Tabla extends MECON_PDF_Marco { $init = $this->_obtenerAlineacionTexto($i, $j, $t, $attr2, $estilo); - $this->_pdf->addText($init, $alto1 + 2, - $t, $estilo); + $this->_marco->addText($init, $alto1 + 2, + $t, $estilo, null, $this->_marco->orientacion); } } } + $this->_marco->espacioDisponible = $alto; } } ?> \ No newline at end of file