mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
64 lines
2.4 KiB
PHP
64 lines
2.4 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\DocStoreBundle\GenericDoc\Providers;
|
|
|
|
use Chill\DocStoreBundle\GenericDoc\FetchQueryInterface;
|
|
use Chill\DocStoreBundle\GenericDoc\GenericDocForAccompanyingPeriodProviderInterface;
|
|
use Chill\DocStoreBundle\GenericDoc\GenericDocForPersonProviderInterface;
|
|
use Chill\DocStoreBundle\Repository\PersonDocumentACLAwareRepositoryInterface;
|
|
use Chill\DocStoreBundle\Security\Authorization\PersonDocumentVoter;
|
|
use Chill\PersonBundle\Entity\AccompanyingPeriod;
|
|
use Chill\PersonBundle\Entity\Person;
|
|
use Symfony\Component\Security\Core\Security;
|
|
|
|
final readonly class PersonDocumentGenericDocProvider implements GenericDocForPersonProviderInterface, GenericDocForAccompanyingPeriodProviderInterface
|
|
{
|
|
public const KEY = 'person_document';
|
|
|
|
public function __construct(
|
|
private Security $security,
|
|
private PersonDocumentACLAwareRepositoryInterface $personDocumentACLAwareRepository,
|
|
) {}
|
|
|
|
public function buildFetchQueryForPerson(
|
|
Person $person,
|
|
?\DateTimeImmutable $startDate = null,
|
|
?\DateTimeImmutable $endDate = null,
|
|
?string $content = null,
|
|
?string $origin = null
|
|
): FetchQueryInterface {
|
|
return $this->personDocumentACLAwareRepository->buildFetchQueryForPerson(
|
|
$person,
|
|
$startDate,
|
|
$endDate,
|
|
$content
|
|
);
|
|
}
|
|
|
|
public function isAllowedForPerson(Person $person): bool
|
|
{
|
|
return $this->security->isGranted(PersonDocumentVoter::SEE, $person);
|
|
}
|
|
|
|
public function buildFetchQueryForAccompanyingPeriod(AccompanyingPeriod $accompanyingPeriod, ?\DateTimeImmutable $startDate = null, ?\DateTimeImmutable $endDate = null, ?string $content = null, ?string $origin = null): FetchQueryInterface
|
|
{
|
|
return $this->personDocumentACLAwareRepository->buildFetchQueryForAccompanyingPeriod($accompanyingPeriod, $startDate, $endDate, $content);
|
|
}
|
|
|
|
public function isAllowedForAccompanyingPeriod(AccompanyingPeriod $accompanyingPeriod): bool
|
|
{
|
|
// we assume that the user is allowed to see at least one person of the course
|
|
// this will be double checked when running the query
|
|
return true;
|
|
}
|
|
}
|