From 33dd97721468e3700a9cd24aeea57a2205f5dabb Mon Sep 17 00:00:00 2001 From: Thomas Gelf Date: Fri, 19 Feb 2016 02:01:53 +0100 Subject: [PATCH] ImportsourceHookTable: apply modifiers on preview --- application/tables/ImportsourceHookTable.php | 36 ++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/application/tables/ImportsourceHookTable.php b/application/tables/ImportsourceHookTable.php index d8f3d2d0..62b2afaf 100644 --- a/application/tables/ImportsourceHookTable.php +++ b/application/tables/ImportsourceHookTable.php @@ -68,11 +68,47 @@ class ImportsourceHookTable extends QuickTable } $this->dataCache = $query->fetchAll(); + $this->applyModifiers(); } return $this->dataCache; } + protected function applyModifiers() + { + $modifiers = $this->source->fetchRowModifiers(); + if (empty($modifiers)) { + return; + } + + $propertyModifiers = array(); + + + foreach ($modifiers as $mod) { + if (! array_key_exists($mod->property_name, $propertyModifiers)) { + $propertyModifiers[$mod->property_name] = array(); + } + $obj = new $mod->provider_class; + $obj->setSettings($mod->getSettings()); + $propertyModifiers[$mod->property_name][] = $obj; + + } + + foreach ($this->dataCache as & $row) { + foreach ($propertyModifiers as $key => $mods) { + foreach ($mods as $mod) { + if (is_array($row->$key)) { + foreach ($row->$key as & $k) { + $k = $mod->transform($k); + } + } else { + $row->$key = $mod->transform($row->$key); + } + } + } + } + } + public function getBaseQuery() { $ds = new ArrayDatasource($this->sourceHook()->fetchData());