From 1a0a4a8e210ae6708cb6caed163d24970fabd4c9 Mon Sep 17 00:00:00 2001 From: Alan Knowles Date: Tue, 21 May 2019 17:35:44 +0800 Subject: [PATCH] Fix #5884 - add photo to report --- Bjs.php | 24 +++++++++++++++++++++--- SimpleExcel.php | 32 +++++++++++++++++++++++++++++--- 2 files changed, 50 insertions(+), 6 deletions(-) diff --git a/Bjs.php b/Bjs.php index 1950d847..d936bcf9 100644 --- a/Bjs.php +++ b/Bjs.php @@ -10,12 +10,13 @@ class Pman_Core_Bjs { var $json; var $fields = array(); - + var $cols = array(); function __construct($file) { $this->json = json_decode(file_get_contents($file)); $this->iterateFields($this->json->items); + $this->iterateColumns($this->json->items); } function iterateFields($ar) @@ -23,7 +24,10 @@ class Pman_Core_Bjs { foreach($ar as $o) { switch ($o->xtype) { - case "ComboBox": + case "ComboBox": + if (!isset($o->{'String hiddenName'})) { + continue; + } $this->fields[] = $o->{'String hiddenName'}; // fall throught.. $k = isset($o->{'String name'}) ? 'String name' : 'string name'; @@ -66,6 +70,20 @@ class Pman_Core_Bjs { } } - + function iterateColumns($ar) + { + foreach($ar as $o) { + switch ($o->xtype) { + case "ColumnModel": + $this->cols[] = $o; + break; + default: + if (isset($o->items)) { + $this->iterateColumns($o->items); + } + } + } + } + } diff --git a/SimpleExcel.php b/SimpleExcel.php index 6515710c..6c36750e 100644 --- a/SimpleExcel.php +++ b/SimpleExcel.php @@ -74,7 +74,7 @@ class Pman_Core_SimpleExcel extends Pman var $formats = array(); var $workbook = false; var $worksheet= false; - + var $postRender = array(); function __construct($data,$cfg) { @@ -243,6 +243,7 @@ class Pman_Core_SimpleExcel extends Pman if (empty($data)) { return; } + foreach($cfg['cols'] as $c => $col_cfg) { if (isset($col_cfg['renderer'])) { $hasRender = true; @@ -279,8 +280,7 @@ class Pman_Core_SimpleExcel extends Pman continue; } if (!empty($col_cfg['renderer'])) { - - if (is_a($col_cfg['renderer'], 'Closure')) { + if (is_a($col_cfg['renderer'], 'Closure')) { $col_cfg['renderer']($cl[$col_cfg['dataIndex']], $worksheet, $r+1, $c, $cl); } else { // not sure if row is correct here...!!!? @@ -370,6 +370,18 @@ class Pman_Core_SimpleExcel extends Pman } if (isset($col_cfg['renderer'])) { $hasRender = true; + + $v = isset($cl[$col_cfg['dataIndex']]) ? $cl[$col_cfg['dataIndex']] : ''; + if (empty($cl[$col_cfg['dataIndex']])) { + continue; + } + $this->postRender[] = array( + $col_cfg['renderer'], $cl[$col_cfg['dataIndex']], $worksheet, $start_row+$r+1, $c, $cl + ); + + + + continue; } @@ -417,6 +429,20 @@ class Pman_Core_SimpleExcel extends Pman function send($fname) { + + if (!empty($this->postRender)) { + foreach($this->postRender as $ar) { + if (is_a($ar[0], 'Closure')) { + $ar[0]($ar[1], $ar[2], $ar[3], $ar[4], $ar[5]); + } else { + // not sure if row is correct here...!!!? + call_user_func($ar[0],$ar[1], $ar[2], $ar[3], $ar[4], $ar[5]); + } + } + + } + + if (!empty($this->workbook)) { $this->workbook->close(); $this->workbook = false; -- 2.39.2