Skip to content
Snippets Groups Projects
Commit ca442132 authored by Peter Rotich's avatar Peter Rotich
Browse files

Result Set Exporter

Add object as a third callback parameters
Add ability to set static value as a key
parent bcbb47b3
No related branches found
No related tags found
No related merge requests found
...@@ -156,7 +156,7 @@ class Export { ...@@ -156,7 +156,7 @@ class Export {
'attachment_count' => __('Attachment Count'), 'attachment_count' => __('Attachment Count'),
) + $cdata, ) + $cdata,
$how, $how,
array('modify' => function(&$record, $keys) use ($fields) { array('modify' => function(&$record, $keys, $obj) use ($fields) {
foreach ($fields as $k=>$f) { foreach ($fields as $k=>$f) {
if (($i = array_search($k, $keys)) !== false) { if (($i = array_search($k, $keys)) !== false) {
$record[$i] = $f->export($f->to_php($record[$i])); $record[$i] = $f->export($f->to_php($record[$i]));
...@@ -201,7 +201,7 @@ class Export { ...@@ -201,7 +201,7 @@ class Export {
'::getEmail' => __('Email'), '::getEmail' => __('Email'),
) + $cdata, ) + $cdata,
$how, $how,
array('modify' => function(&$record, $keys) use ($fields) { array('modify' => function(&$record, $keys, $obj) use ($fields) {
foreach ($fields as $k=>$f) { foreach ($fields as $k=>$f) {
if ($f && ($i = array_search($k, $keys)) !== false) { if ($f && ($i = array_search($k, $keys)) !== false) {
$record[$i] = $f->export($f->to_php($record[$i])); $record[$i] = $f->export($f->to_php($record[$i]));
...@@ -240,7 +240,7 @@ class Export { ...@@ -240,7 +240,7 @@ class Export {
'name' => 'Name', 'name' => 'Name',
) + $cdata, ) + $cdata,
$how, $how,
array('modify' => function(&$record, $keys) use ($fields) { array('modify' => function(&$record, $keys, $obj) use ($fields) {
foreach ($fields as $k=>$f) { foreach ($fields as $k=>$f) {
if ($f && ($i = array_search($k, $keys)) !== false) { if ($f && ($i = array_search($k, $keys)) !== false) {
$record[$i] = $f->export($f->to_php($record[$i])); $record[$i] = $f->export($f->to_php($record[$i]));
...@@ -295,26 +295,32 @@ class ResultSetExporter { ...@@ -295,26 +295,32 @@ class ResultSetExporter {
$this->_res->next(); $this->_res->next();
$record = array(); $record = array();
foreach ($this->keys as $field) { foreach ($this->keys as $field) {
list($field, $func) = explode('::', $field); list($field, $func) = explode('::', $field);
$path = explode('.', $field); $path = explode('.', $field);
$current = $object; $current = $object;
// Evaluate dotted ORM path // Evaluate dotted ORM path
if ($field) { if ($field) {
foreach ($path as $P) { foreach ($path as $P) {
$current = $current->{$P}; if (isset($current->{$P}))
$current = $current->{$P};
else {
$current = $P;
break;
}
} }
} }
// Evalutate :: function call on target current // Evalutate :: function call on target current
if ($func && (method_exists($current, $func) || method_exists($current, '__call'))) { if ($func && (method_exists($current, $func) || method_exists($current, '__call'))) {
$current = $current->{$func}(); $current = $current->{$func}();
} }
$record[] = (string) $current; $record[] = (string) $current;
} }
if (isset($this->options['modify']) && is_callable($this->options['modify'])) 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; return $record;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment