diff --git a/concrete/src/Csv/Export/UserExporter.php b/concrete/src/Csv/Export/UserExporter.php index 308498c3494..bf6a4a52a23 100644 --- a/concrete/src/Csv/Export/UserExporter.php +++ b/concrete/src/Csv/Export/UserExporter.php @@ -3,6 +3,7 @@ use Concrete\Core\Attribute\Category\UserCategory; use Concrete\Core\Attribute\ObjectInterface; +use Concrete\Core\Config\Repository\Repository; use Concrete\Core\Localization\Service\Date; use League\Csv\Writer; @@ -15,6 +16,16 @@ class UserExporter extends AbstractExporter */ protected $appTimezone; + /** + * @var Date + */ + protected $dateService; + + /** + * @var string + */ + protected $format; + /** * Initialize the instance. * @@ -22,10 +33,12 @@ class UserExporter extends AbstractExporter * @param UserCategory $userCategory * @param Date $dateService */ - public function __construct(Writer $writer, UserCategory $userCategory, Date $dateService) + public function __construct(Writer $writer, UserCategory $userCategory, Date $dateService, Repository $config) { parent::__construct($writer, $userCategory); $this->appTimezone = $dateService->getTimezone('app'); + $this->dateService = $dateService; + $this->format = $this->getFormat($config->get('concrete.export.csv.datetime_format', 'ATOM')); } /** @@ -58,12 +71,22 @@ protected function getStaticFieldValues(ObjectInterface $userInfo) $dateTime = $userInfo->getUserDateAdded(); if ($dateTime) { $dateTime = clone $dateTime; - $dateTime->setTimezone($this->appTimezone); - yield $dateTime->format('Y-m-d H:i:s'); + yield $this->dateService->formatCustom($this->format, $dateTime, 'app'); } else { yield ''; } yield $userInfo->isActive() ? '1' : '0'; yield (string) (int) $userInfo->getNumLogins(); } + + protected function getFormat(string $formatName = 'ATOM') + { + $datetime_format_constant = sprintf('DATE_%s', $formatName); + + if (defined($datetime_format_constant)) { + return constant($datetime_format_constant); + } + + return DATE_ATOM; + } }