mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-20 14:43:49 +00:00
FEATURE [genericDoc] generic doc interface implemented for rendez-vous
This commit is contained in:
@@ -0,0 +1,101 @@
|
||||
<?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\CalendarBundle\Service\GenericDoc\Providers;
|
||||
|
||||
use Chill\CalendarBundle\Entity\Calendar;
|
||||
use Chill\CalendarBundle\Entity\CalendarDoc;
|
||||
use Chill\CalendarBundle\Security\Voter\CalendarVoter;
|
||||
use Chill\DocStoreBundle\Entity\StoredObject;
|
||||
use Chill\DocStoreBundle\GenericDoc\FetchQuery;
|
||||
use Chill\DocStoreBundle\GenericDoc\FetchQueryInterface;
|
||||
use Chill\DocStoreBundle\GenericDoc\GenericDocForAccompanyingPeriodProviderInterface;
|
||||
use Chill\PersonBundle\Entity\AccompanyingPeriod;
|
||||
use Doctrine\DBAL\Types\Types;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Component\Security\Core\Security;
|
||||
|
||||
final class AccompanyingPeriodCalendarGenericDocProvider implements GenericDocForAccompanyingPeriodProviderInterface
|
||||
{
|
||||
public const KEY = 'accompanying_period_calendar_document';
|
||||
|
||||
private EntityManagerInterface $em;
|
||||
|
||||
private Security $security;
|
||||
|
||||
public function __construct(
|
||||
Security $security,
|
||||
EntityManagerInterface $entityManager
|
||||
) {
|
||||
$this->security = $security;
|
||||
$this->em = $entityManager;
|
||||
}
|
||||
|
||||
public function buildFetchQueryForAccompanyingPeriod(AccompanyingPeriod $accompanyingPeriod, ?\DateTimeImmutable $startDate = null, ?\DateTimeImmutable $endDate = null, ?string $content = null, ?string $origin = null): FetchQueryInterface
|
||||
{
|
||||
$classMetadata = $this->em->getClassMetadata(CalendarDoc::class);
|
||||
$storedObjectMetadata = $this->em->getClassMetadata(StoredObject::class);
|
||||
$calendarMetadata = $this->em->getClassMetadata(Calendar::class);
|
||||
|
||||
$query = new FetchQuery(
|
||||
self::KEY,
|
||||
sprintf("jsonb_build_object('id', cd.%s)", $classMetadata->getColumnName('id')),
|
||||
'cd.'.$storedObjectMetadata->getColumnName('createdAt'),
|
||||
$classMetadata->getSchemaName().'.'.$classMetadata->getTableName().' AS cd'
|
||||
);
|
||||
$query->addJoinClause(
|
||||
'JOIN chill_doc.stored_object doc_store ON doc_store.id = cd.storedobject_id'
|
||||
);
|
||||
|
||||
$query->addJoinClause(
|
||||
'JOIN chill_calendar.calendar calendar ON calendar.id = cd.calendar_id'
|
||||
);
|
||||
|
||||
$query->addWhereClause(
|
||||
'calendar.accompanyingperiod_id = ?',
|
||||
[$accompanyingPeriod->getId()],
|
||||
[Types::INTEGER]
|
||||
);
|
||||
|
||||
if (null !== $startDate) {
|
||||
$query->addWhereClause(
|
||||
sprintf('doc_store.%s >= ?', $storedObjectMetadata->getColumnName('createdAt')),
|
||||
[$startDate],
|
||||
[Types::DATE_IMMUTABLE]
|
||||
);
|
||||
}
|
||||
|
||||
if (null !== $endDate) {
|
||||
$query->addWhereClause(
|
||||
sprintf('doc_store.%s < ?', $storedObjectMetadata->getColumnName('createdAt')),
|
||||
[$endDate],
|
||||
[Types::DATE_IMMUTABLE]
|
||||
);
|
||||
}
|
||||
|
||||
if (null !== $content) {
|
||||
$query->addWhereClause(
|
||||
'doc_store.title ilike ?',
|
||||
['%' . $content . '%'],
|
||||
[Types::STRING]
|
||||
);
|
||||
}
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
public function isAllowedForAccompanyingPeriod(AccompanyingPeriod $accompanyingPeriod): bool
|
||||
{
|
||||
return $this->security->isGranted(CalendarVoter::SEE, $accompanyingPeriod);
|
||||
}
|
||||
|
||||
|
||||
}
|
@@ -0,0 +1,44 @@
|
||||
<?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\CalendarBundle\Service\GenericDoc\Renderers;
|
||||
|
||||
use Chill\CalendarBundle\Repository\CalendarDocRepository;
|
||||
use Chill\CalendarBundle\Service\GenericDoc\Providers\AccompanyingPeriodCalendarGenericDocProvider;
|
||||
use Chill\DocStoreBundle\GenericDoc\GenericDocDTO;
|
||||
use Chill\DocStoreBundle\GenericDoc\Twig\GenericDocRendererInterface;
|
||||
|
||||
final class AccompanyingPeriodCalendarGenericDocRenderer implements GenericDocRendererInterface
|
||||
{
|
||||
private CalendarDocRepository $repository;
|
||||
|
||||
public function __construct(CalendarDocRepository $calendarDocRepository)
|
||||
{
|
||||
$this->repository = $calendarDocRepository;
|
||||
}
|
||||
|
||||
public function supports(GenericDocDTO $genericDocDTO, $options = []): bool
|
||||
{
|
||||
return $genericDocDTO->key === AccompanyingPeriodCalendarGenericDocProvider::KEY;
|
||||
}
|
||||
|
||||
public function getTemplate(GenericDocDTO $genericDocDTO, $options = []): string
|
||||
{
|
||||
return '@ChillCalendar/GenericDoc/calendar_document.html.twig';
|
||||
}
|
||||
|
||||
public function getTemplateData(GenericDocDTO $genericDocDTO, $options = []): array
|
||||
{
|
||||
return [
|
||||
'document' => $this->repository->find($genericDocDTO->identifiers['id'])
|
||||
];
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user