ImportsourceHookTable: apply modifiers on preview

This commit is contained in:
Thomas Gelf 2016-02-19 02:01:53 +01:00
parent 3de4869813
commit 33dd977214
1 changed files with 36 additions and 0 deletions

View File

@ -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());