From ca442132e7e5538096965b8b7cebef38d2905ace Mon Sep 17 00:00:00 2001 From: Peter Rotich <peter@osticket.com> Date: Mon, 15 May 2017 16:12:15 +0000 Subject: [PATCH] Result Set Exporter Add object as a third callback parameters Add ability to set static value as a key --- include/class.export.php | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/include/class.export.php b/include/class.export.php index 21e89bf80..97bfd8a4a 100644 --- a/include/class.export.php +++ b/include/class.export.php @@ -156,7 +156,7 @@ class Export { 'attachment_count' => __('Attachment Count'), ) + $cdata, $how, - array('modify' => function(&$record, $keys) use ($fields) { + array('modify' => function(&$record, $keys, $obj) use ($fields) { foreach ($fields as $k=>$f) { if (($i = array_search($k, $keys)) !== false) { $record[$i] = $f->export($f->to_php($record[$i])); @@ -201,7 +201,7 @@ class Export { '::getEmail' => __('Email'), ) + $cdata, $how, - array('modify' => function(&$record, $keys) use ($fields) { + array('modify' => function(&$record, $keys, $obj) use ($fields) { foreach ($fields as $k=>$f) { if ($f && ($i = array_search($k, $keys)) !== false) { $record[$i] = $f->export($f->to_php($record[$i])); @@ -240,7 +240,7 @@ class Export { 'name' => 'Name', ) + $cdata, $how, - array('modify' => function(&$record, $keys) use ($fields) { + array('modify' => function(&$record, $keys, $obj) use ($fields) { foreach ($fields as $k=>$f) { if ($f && ($i = array_search($k, $keys)) !== false) { $record[$i] = $f->export($f->to_php($record[$i])); @@ -295,26 +295,32 @@ class ResultSetExporter { $this->_res->next(); $record = array(); - foreach ($this->keys as $field) { list($field, $func) = explode('::', $field); $path = explode('.', $field); + $current = $object; // Evaluate dotted ORM path if ($field) { foreach ($path as $P) { - $current = $current->{$P}; + if (isset($current->{$P})) + $current = $current->{$P}; + else { + $current = $P; + break; + } } } // Evalutate :: function call on target current if ($func && (method_exists($current, $func) || method_exists($current, '__call'))) { $current = $current->{$func}(); } + $record[] = (string) $current; } if (isset($this->options['modify']) && is_callable($this->options['modify'])) - $record = $this->options['modify']($record, $this->keys); + $record = $this->options['modify']($record, $this->keys, $object); return $record; } -- GitLab