diff --git a/Classes/Controller/DatabaseStorageController.php b/Classes/Controller/DatabaseStorageController.php index 6d1b83d..595b209 100644 --- a/Classes/Controller/DatabaseStorageController.php +++ b/Classes/Controller/DatabaseStorageController.php @@ -1,4 +1,5 @@ getProperties(); foreach ($properties as &$value) { - if ($value instanceof PersistentResource) { - $value = $this->resourceManager->getPublicPersistentResourceUri($value) ?: '-'; - } elseif (is_string($value)) { - } elseif (is_object($value) && method_exists($value, '__toString')) { - $value = (string)$value; - } elseif (isset($value['dateFormat'], $value['date'])) { - $timezone = null; - if(isset($value['timezone'])){ - $timezone = new \DateTimeZone($value['timezone']); + if (is_array($value)) { + // Todo fix this for deep arrays + foreach ($value as &$innerValue) { + $innerValue = $this->getStringValue($innerValue); } - $dateTime = \DateTime::createFromFormat($value['dateFormat'], $value['date'], $timezone); - $value = $dateTime->format($this->settings['datetimeFormat']); + $value = sprintf('', implode('
  • ', $value)); } else { - $value = '-'; + $value = $this->getStringValue($value); } } @@ -258,22 +254,7 @@ public function exportAction(string $identifier, string $writerType = 'Xlsx', bo $values = []; foreach ($entry->getProperties() as $value) { - if ($value instanceof PersistentResource) { - $values[] = $this->resourceManager->getPublicPersistentResourceUri($value) ?: '-'; - } elseif (is_string($value)) { - $values[] = $value; - } elseif (is_object($value) && method_exists($value, '__toString')) { - $values[] = (string)$value; - } elseif (isset($value['dateFormat'], $value['date'])) { - $timezone = null; - if(isset($value['timezone'])){ - $timezone = new \DateTimeZone($value['timezone']); - } - $dateTime = \DateTime::createFromFormat($value['dateFormat'], $value['date'], $timezone); - $values[] = $dateTime->format($this->settings['datetimeFormat']); - } else { - $values[] = '-'; - } + $values[] = $this->getStringValue($value); } if ($exportDateTime) { @@ -326,4 +307,42 @@ public function exportAction(string $identifier, string $writerType = 'Xlsx', bo $writer->save('php://output'); exit; } + + /** + * Internal function to replace value with a string for export / listing. + * + * @param mixed $value The database column value. + * @param int $indent The level of indentation (for array values). + * + * @return string + */ + protected function getStringValue($value, int $indent = 0): string + { + if ($value instanceof PersistentResource) { + return $this->resourceManager->getPublicPersistentResourceUri($value) ?: '-'; + } elseif (is_string($value)) { + return $value; + } elseif (is_object($value) && method_exists($value, '__toString')) { + return (string)$value; + } elseif (isset($value['dateFormat'], $value['date'])) { + $timezone = null; + if (isset($value['timezone'])) { + $timezone = new \DateTimeZone($value['timezone']); + } + $dateTime = \DateTime::createFromFormat($value['dateFormat'], $value['date'], $timezone); + return $dateTime->format($this->settings['datetimeFormat']); + } elseif (is_array($value)) { + foreach ($value as &$innerValue) { + $innerValue = $this->getStringValue($innerValue, $indent + 1); + } + $prefix = str_repeat(' ', $indent * 2) . '- '; + return sprintf( + '%s%s', + $prefix, + implode("\r\n" . $prefix, $value) + ); + } + + return '-'; + } }