From 451c1c5e4c08af89406123f43964c0fdc44d958a Mon Sep 17 00:00:00 2001 From: Roland Gruber Date: Wed, 8 Jul 2015 18:41:53 +0000 Subject: [PATCH] added PDFTable --- lam/lib/baseModule.inc | 27 ++++++++++++++++++--------- lam/lib/modules/asteriskExtension.inc | 16 ++++++++-------- 2 files changed, 26 insertions(+), 17 deletions(-) diff --git a/lam/lib/baseModule.inc b/lam/lib/baseModule.inc index a6368ada..17964df6 100644 --- a/lam/lib/baseModule.inc +++ b/lam/lib/baseModule.inc @@ -866,13 +866,14 @@ abstract class baseModule { * @param PDFTable $table table */ public function addPDFTable(&$result, $name, $table) { - $first = true; + if (empty($table->rows)) { + return; + } + if (!empty($table->label)) { + $result[get_class($this) . '_' . $name][] = '' . $table->label . ':'; + } foreach ($table->rows as $row) { - $xml = ''; - if ($first && !empty($table->label)) { - $xml .= '' . $table->label . ''; - } - $xml .= ''; + $xml = ''; foreach ($row->cells as $cell) { $width = empty($cell->width) ? '' : ' width="' . $cell->width . '"'; $content = ($cell->bold) ? '' . $cell->content . '' : $cell->content; @@ -880,7 +881,6 @@ abstract class baseModule { } $xml .= ''; $result[get_class($this) . '_' . $name][] = $xml; - $first = false; } } @@ -1828,6 +1828,15 @@ class PDFTable { /** list of PDFTableRow elements */ public $rows = array(); + /** + * Constructor + * + * @param String $label label + */ + public function __construct($label = null) { + $this->label = $label; + } + } /** @@ -1868,11 +1877,11 @@ class PDFTableCell { * Constructor. * * @param String $content cell content - * @param String $align cell alignment (default: left) * @param String $width width (e.g. "20%") + * @param String $align cell alignment (default: left) * @param boolean $bold print in bold */ - public function __construct($content, $align = null, $width = null, $bold = false) { + public function __construct($content, $width = null, $align = null, $bold = false) { $this->content = empty($content) ? ' ' : $content; $this->align = ($align == null) ? self::ALIGN_LEFT : $align; $this->width = $width; diff --git a/lam/lib/modules/asteriskExtension.inc b/lam/lib/modules/asteriskExtension.inc index f12e5b8d..7c69a3b3 100644 --- a/lam/lib/modules/asteriskExtension.inc +++ b/lam/lib/modules/asteriskExtension.inc @@ -819,10 +819,10 @@ class asteriskExtension extends baseModule { $entries = $this->load_extension_parts($extName); $pdfTable = new PDFTable(); $pdfRow = new PDFTableRow(); - $pdfRow->cells[] = new PDFTableCell(_('Name'), null, '20%', true); - $pdfRow->cells[] = new PDFTableCell(_('Application'), null, '30%', true); - $pdfRow->cells[] = new PDFTableCell(_('Application data'), null, '30%', true); - $pdfRow->cells[] = new PDFTableCell(_('Priority'), null, '20%', true); + $pdfRow->cells[] = new PDFTableCell(_('Name'), '20%', null, true); + $pdfRow->cells[] = new PDFTableCell(_('Application'), '30%', null, true); + $pdfRow->cells[] = new PDFTableCell(_('Application data'), '30%', null, true); + $pdfRow->cells[] = new PDFTableCell(_('Priority'), '20%', null, true); $pdfTable->rows[] = $pdfRow; for ($i = 0; $i < sizeof($entries); $i++) { $appdata = ' '; @@ -830,10 +830,10 @@ class asteriskExtension extends baseModule { $appdata = $entries[$i]['astapplicationdata'][0]; } $pdfRow = new PDFTableRow(); - $pdfRow->cells[] = new PDFTableCell($entries[$i]['cn'][0], null, '20%'); - $pdfRow->cells[] = new PDFTableCell($entries[$i]['astapplication'][0], null, '30%'); - $pdfRow->cells[] = new PDFTableCell($appdata, null, '30%'); - $pdfRow->cells[] = new PDFTableCell($entries[$i]['astpriority'][0], null, '20%'); + $pdfRow->cells[] = new PDFTableCell($entries[$i]['cn'][0], '20%'); + $pdfRow->cells[] = new PDFTableCell($entries[$i]['astapplication'][0], '30%'); + $pdfRow->cells[] = new PDFTableCell($appdata, '30%'); + $pdfRow->cells[] = new PDFTableCell($entries[$i]['astpriority'][0], '20%'); $pdfTable->rows[] = $pdfRow; } $this->addPDFTable($return, 'rules', $pdfTable);