mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
without date and time This is useful when generating a letter, to fill the today's date in the letter's header.
57 lines
1.7 KiB
PHP
57 lines
1.7 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
/*
|
|
* Chill is a software for social workers
|
|
*
|
|
* For the full copyright and license information, please view
|
|
* the LICENSE file that was distributed with this source code.
|
|
*/
|
|
|
|
namespace Chill\DocGeneratorBundle\Service\Context;
|
|
|
|
use Chill\MainBundle\Entity\Location;
|
|
use Chill\MainBundle\Entity\User;
|
|
use DateTimeImmutable;
|
|
use Symfony\Component\Security\Core\Security;
|
|
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
|
|
|
|
class BaseContextData
|
|
{
|
|
private NormalizerInterface $normalizer;
|
|
|
|
private Security $security;
|
|
|
|
public function __construct(Security $security, NormalizerInterface $normalizer)
|
|
{
|
|
$this->security = $security;
|
|
$this->normalizer = $normalizer;
|
|
}
|
|
|
|
public function getData(): array
|
|
{
|
|
$data = [];
|
|
$user = $this->security->getUser();
|
|
|
|
$data['creator'] = $this->normalizer->normalize(
|
|
$user instanceof User ? $user : null,
|
|
'docgen',
|
|
['docgen:expects' => User::class, 'groups' => ['docgen:read']]
|
|
);
|
|
$data['createdAt'] = $this->normalizer->normalize(new DateTimeImmutable(), 'docgen', [
|
|
'docgen:expects' => DateTimeImmutable::class, 'groups' => ['docgen:read'],
|
|
]);
|
|
$data['createdAtDate'] = $this->normalizer->normalize(new DateTimeImmutable('today'), 'docgen', [
|
|
'docgen:expects' => DateTimeImmutable::class, 'groups' => ['docgen:read'],
|
|
]);
|
|
$data['location'] = $this->normalizer->normalize(
|
|
$user instanceof User ? $user->getCurrentLocation() : null,
|
|
'docgen',
|
|
['docgen:expects' => Location::class, 'groups' => ['docgen:read']]
|
|
);
|
|
|
|
return $data;
|
|
}
|
|
}
|