Skip to content

Commit

Permalink
Merge pull request concretecms#12248 from SashaMcr/SashaMcr/fix-12242
Browse files Browse the repository at this point in the history
Feature concretecms#12242: use format from config
  • Loading branch information
aembler authored Oct 21, 2024
2 parents 0363dbf + 0b5e951 commit 96e65dd
Showing 1 changed file with 26 additions and 3 deletions.
29 changes: 26 additions & 3 deletions concrete/src/Csv/Export/UserExporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -15,17 +16,29 @@ class UserExporter extends AbstractExporter
*/
protected $appTimezone;

/**
* @var Date
*/
protected $dateService;

/**
* @var string
*/
protected $format;

/**
* Initialize the instance.
*
* @param Writer $writer
* @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'));
}

/**
Expand Down Expand Up @@ -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;
}
}

0 comments on commit 96e65dd

Please sign in to comment.