added PDFTable

This commit is contained in:
Roland Gruber 2015-07-08 18:41:53 +00:00
parent 95b87c003f
commit 451c1c5e4c
2 changed files with 26 additions and 17 deletions

View File

@ -866,13 +866,14 @@ abstract class baseModule {
* @param PDFTable $table table * @param PDFTable $table table
*/ */
public function addPDFTable(&$result, $name, $table) { public function addPDFTable(&$result, $name, $table) {
$first = true; if (empty($table->rows)) {
return;
}
if (!empty($table->label)) {
$result[get_class($this) . '_' . $name][] = '<block><tr><td><b>' . $table->label . ':</b></td></tr></block>';
}
foreach ($table->rows as $row) { foreach ($table->rows as $row) {
$xml = '<block>'; $xml = '<block><tr>';
if ($first && !empty($table->label)) {
$xml .= '<key>' . $table->label . '</key>';
}
$xml .= '<tr>';
foreach ($row->cells as $cell) { foreach ($row->cells as $cell) {
$width = empty($cell->width) ? '' : ' width="' . $cell->width . '"'; $width = empty($cell->width) ? '' : ' width="' . $cell->width . '"';
$content = ($cell->bold) ? '<b>' . $cell->content . '</b>' : $cell->content; $content = ($cell->bold) ? '<b>' . $cell->content . '</b>' : $cell->content;
@ -880,7 +881,6 @@ abstract class baseModule {
} }
$xml .= '</tr></block>'; $xml .= '</tr></block>';
$result[get_class($this) . '_' . $name][] = $xml; $result[get_class($this) . '_' . $name][] = $xml;
$first = false;
} }
} }
@ -1828,6 +1828,15 @@ class PDFTable {
/** list of PDFTableRow elements */ /** list of PDFTableRow elements */
public $rows = array(); public $rows = array();
/**
* Constructor
*
* @param String $label label
*/
public function __construct($label = null) {
$this->label = $label;
}
} }
/** /**
@ -1868,11 +1877,11 @@ class PDFTableCell {
* Constructor. * Constructor.
* *
* @param String $content cell content * @param String $content cell content
* @param String $align cell alignment (default: left)
* @param String $width width (e.g. "20%") * @param String $width width (e.g. "20%")
* @param String $align cell alignment (default: left)
* @param boolean $bold print in bold * @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->content = empty($content) ? ' ' : $content;
$this->align = ($align == null) ? self::ALIGN_LEFT : $align; $this->align = ($align == null) ? self::ALIGN_LEFT : $align;
$this->width = $width; $this->width = $width;

View File

@ -819,10 +819,10 @@ class asteriskExtension extends baseModule {
$entries = $this->load_extension_parts($extName); $entries = $this->load_extension_parts($extName);
$pdfTable = new PDFTable(); $pdfTable = new PDFTable();
$pdfRow = new PDFTableRow(); $pdfRow = new PDFTableRow();
$pdfRow->cells[] = new PDFTableCell(_('Name'), null, '20%', true); $pdfRow->cells[] = new PDFTableCell(_('Name'), '20%', null, true);
$pdfRow->cells[] = new PDFTableCell(_('Application'), null, '30%', true); $pdfRow->cells[] = new PDFTableCell(_('Application'), '30%', null, true);
$pdfRow->cells[] = new PDFTableCell(_('Application data'), null, '30%', true); $pdfRow->cells[] = new PDFTableCell(_('Application data'), '30%', null, true);
$pdfRow->cells[] = new PDFTableCell(_('Priority'), null, '20%', true); $pdfRow->cells[] = new PDFTableCell(_('Priority'), '20%', null, true);
$pdfTable->rows[] = $pdfRow; $pdfTable->rows[] = $pdfRow;
for ($i = 0; $i < sizeof($entries); $i++) { for ($i = 0; $i < sizeof($entries); $i++) {
$appdata = ' '; $appdata = ' ';
@ -830,10 +830,10 @@ class asteriskExtension extends baseModule {
$appdata = $entries[$i]['astapplicationdata'][0]; $appdata = $entries[$i]['astapplicationdata'][0];
} }
$pdfRow = new PDFTableRow(); $pdfRow = new PDFTableRow();
$pdfRow->cells[] = new PDFTableCell($entries[$i]['cn'][0], null, '20%'); $pdfRow->cells[] = new PDFTableCell($entries[$i]['cn'][0], '20%');
$pdfRow->cells[] = new PDFTableCell($entries[$i]['astapplication'][0], null, '30%'); $pdfRow->cells[] = new PDFTableCell($entries[$i]['astapplication'][0], '30%');
$pdfRow->cells[] = new PDFTableCell($appdata, null, '30%'); $pdfRow->cells[] = new PDFTableCell($appdata, '30%');
$pdfRow->cells[] = new PDFTableCell($entries[$i]['astpriority'][0], null, '20%'); $pdfRow->cells[] = new PDFTableCell($entries[$i]['astpriority'][0], '20%');
$pdfTable->rows[] = $pdfRow; $pdfTable->rows[] = $pdfRow;
} }
$this->addPDFTable($return, 'rules', $pdfTable); $this->addPDFTable($return, 'rules', $pdfTable);