mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
Refactor exports to include ExportGenerationContext.
Updated initiateQuery methods to pass ExportGenerationContext, enabling better user-specific query filtering. Removed redundant user retrieval in FilterListAccompanyingPeriodHelper, now relying on context-provided user data.
This commit is contained in:
parent
b5fd9cf4af
commit
3b0a4e9c73
@ -17,6 +17,7 @@ use Chill\ActivityBundle\Export\Export\ListActivityHelper;
|
|||||||
use Chill\ActivityBundle\Security\Authorization\ActivityStatsVoter;
|
use Chill\ActivityBundle\Security\Authorization\ActivityStatsVoter;
|
||||||
use Chill\MainBundle\Entity\Scope;
|
use Chill\MainBundle\Entity\Scope;
|
||||||
use Chill\MainBundle\Export\AccompanyingCourseExportHelper;
|
use Chill\MainBundle\Export\AccompanyingCourseExportHelper;
|
||||||
|
use Chill\MainBundle\Export\ExportGenerationContext;
|
||||||
use Chill\MainBundle\Export\GroupedExportInterface;
|
use Chill\MainBundle\Export\GroupedExportInterface;
|
||||||
use Chill\MainBundle\Export\Helper\TranslatableStringExportLabelHelper;
|
use Chill\MainBundle\Export\Helper\TranslatableStringExportLabelHelper;
|
||||||
use Chill\MainBundle\Export\ListInterface;
|
use Chill\MainBundle\Export\ListInterface;
|
||||||
@ -115,7 +116,7 @@ final readonly class ListActivity implements ListInterface, GroupedExportInterfa
|
|||||||
return $this->helper->getType();
|
return $this->helper->getType();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function initiateQuery(array $requiredModifiers, array $acl, array $data = [])
|
public function initiateQuery(array $requiredModifiers, array $acl, array $data, ExportGenerationContext $context)
|
||||||
{
|
{
|
||||||
$centers = array_map(static fn ($el) => $el['center'], $acl);
|
$centers = array_map(static fn ($el) => $el['center'], $acl);
|
||||||
|
|
||||||
@ -129,7 +130,7 @@ final readonly class ListActivity implements ListInterface, GroupedExportInterfa
|
|||||||
->leftJoin('acppart.person', 'person')
|
->leftJoin('acppart.person', 'person')
|
||||||
->andWhere('acppart.startDate != acppart.endDate OR acppart.endDate IS NULL');
|
->andWhere('acppart.startDate != acppart.endDate OR acppart.endDate IS NULL');
|
||||||
|
|
||||||
$this->filterListAccompanyingPeriodHelper->addFilterAccompanyingPeriods($qb, $requiredModifiers, $acl, $data);
|
$this->filterListAccompanyingPeriodHelper->addFilterAccompanyingPeriods($qb, $requiredModifiers, $acl, $context->byUser, $data);
|
||||||
|
|
||||||
$qb
|
$qb
|
||||||
// some grouping are necessary
|
// some grouping are necessary
|
||||||
|
@ -147,7 +147,7 @@ interface ExportInterface extends ExportElementInterface
|
|||||||
*
|
*
|
||||||
* @return Q the query to execute
|
* @return Q the query to execute
|
||||||
*/
|
*/
|
||||||
public function initiateQuery(array $requiredModifiers, array $acl, array $data/* , ExportGenerationContext $context */);
|
public function initiateQuery(array $requiredModifiers, array $acl, array $data, ExportGenerationContext $context);
|
||||||
|
|
||||||
public function normalizeFormData(array $formData): array;
|
public function normalizeFormData(array $formData): array;
|
||||||
|
|
||||||
|
@ -12,6 +12,7 @@ declare(strict_types=1);
|
|||||||
namespace Chill\PersonBundle\Export\Export;
|
namespace Chill\PersonBundle\Export\Export;
|
||||||
|
|
||||||
use Chill\MainBundle\Export\AccompanyingCourseExportHelper;
|
use Chill\MainBundle\Export\AccompanyingCourseExportHelper;
|
||||||
|
use Chill\MainBundle\Export\ExportGenerationContext;
|
||||||
use Chill\MainBundle\Export\FormatterInterface;
|
use Chill\MainBundle\Export\FormatterInterface;
|
||||||
use Chill\MainBundle\Export\GroupedExportInterface;
|
use Chill\MainBundle\Export\GroupedExportInterface;
|
||||||
use Chill\MainBundle\Export\ListInterface;
|
use Chill\MainBundle\Export\ListInterface;
|
||||||
@ -108,7 +109,7 @@ final readonly class ListAccompanyingPeriod implements ListInterface, GroupedExp
|
|||||||
return Declarations::PERSON_TYPE;
|
return Declarations::PERSON_TYPE;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function initiateQuery(array $requiredModifiers, array $acl, array $data = [])
|
public function initiateQuery(array $requiredModifiers, array $acl, array $data = [], ExportGenerationContext $context)
|
||||||
{
|
{
|
||||||
$qb = $this->entityManager->createQueryBuilder();
|
$qb = $this->entityManager->createQueryBuilder();
|
||||||
|
|
||||||
@ -117,7 +118,7 @@ final readonly class ListAccompanyingPeriod implements ListInterface, GroupedExp
|
|||||||
->andWhere('acp.step != :list_acp_step')
|
->andWhere('acp.step != :list_acp_step')
|
||||||
->setParameter('list_acp_step', AccompanyingPeriod::STEP_DRAFT);
|
->setParameter('list_acp_step', AccompanyingPeriod::STEP_DRAFT);
|
||||||
|
|
||||||
$this->filterListAccompanyingPeriodHelper->addFilterAccompanyingPeriods($qb, $requiredModifiers, $acl, $data);
|
$this->filterListAccompanyingPeriodHelper->addFilterAccompanyingPeriods($qb, $requiredModifiers, $acl, $context->byUser, $data);
|
||||||
|
|
||||||
$this->listAccompanyingPeriodHelper->addSelectClauses($qb, $this->rollingDateConverter->convert($data['calc_date']));
|
$this->listAccompanyingPeriodHelper->addSelectClauses($qb, $this->rollingDateConverter->convert($data['calc_date']));
|
||||||
|
|
||||||
|
@ -12,6 +12,7 @@ declare(strict_types=1);
|
|||||||
namespace Chill\PersonBundle\Export\Export;
|
namespace Chill\PersonBundle\Export\Export;
|
||||||
|
|
||||||
use Chill\MainBundle\Export\AccompanyingCourseExportHelper;
|
use Chill\MainBundle\Export\AccompanyingCourseExportHelper;
|
||||||
|
use Chill\MainBundle\Export\ExportGenerationContext;
|
||||||
use Chill\MainBundle\Export\FormatterInterface;
|
use Chill\MainBundle\Export\FormatterInterface;
|
||||||
use Chill\MainBundle\Export\GroupedExportInterface;
|
use Chill\MainBundle\Export\GroupedExportInterface;
|
||||||
use Chill\MainBundle\Export\Helper\AggregateStringHelper;
|
use Chill\MainBundle\Export\Helper\AggregateStringHelper;
|
||||||
@ -212,7 +213,7 @@ final readonly class ListAccompanyingPeriodWorkAssociatePersonOnAccompanyingPeri
|
|||||||
return Declarations::SOCIAL_WORK_ACTION_TYPE;
|
return Declarations::SOCIAL_WORK_ACTION_TYPE;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function initiateQuery(array $requiredModifiers, array $acl, array $data = [])
|
public function initiateQuery(array $requiredModifiers, array $acl, array $data, ExportGenerationContext $context)
|
||||||
{
|
{
|
||||||
$centers = array_map(static fn ($el) => $el['center'], $acl);
|
$centers = array_map(static fn ($el) => $el['center'], $acl);
|
||||||
$calcDate = $data['calc_date'] ?? new RollingDate(RollingDate::T_TODAY);
|
$calcDate = $data['calc_date'] ?? new RollingDate(RollingDate::T_TODAY);
|
||||||
@ -232,7 +233,7 @@ final readonly class ListAccompanyingPeriodWorkAssociatePersonOnAccompanyingPeri
|
|||||||
->andWhere('acppart.startDate <= :calc_date AND (acppart.endDate > :calc_date OR acppart.endDate IS NULL)')
|
->andWhere('acppart.startDate <= :calc_date AND (acppart.endDate > :calc_date OR acppart.endDate IS NULL)')
|
||||||
->setParameter('calc_date', $this->rollingDateConverter->convert($calcDate));
|
->setParameter('calc_date', $this->rollingDateConverter->convert($calcDate));
|
||||||
|
|
||||||
$this->filterListAccompanyingPeriodHelper->addFilterAccompanyingPeriods($qb, $requiredModifiers, $acl, $data);
|
$this->filterListAccompanyingPeriodHelper->addFilterAccompanyingPeriods($qb, $requiredModifiers, $acl, $context->byUser, $data);
|
||||||
|
|
||||||
AccompanyingCourseExportHelper::addClosingMotiveExclusionClause($qb);
|
AccompanyingCourseExportHelper::addClosingMotiveExclusionClause($qb);
|
||||||
|
|
||||||
|
@ -12,6 +12,7 @@ declare(strict_types=1);
|
|||||||
namespace Chill\PersonBundle\Export\Export;
|
namespace Chill\PersonBundle\Export\Export;
|
||||||
|
|
||||||
use Chill\MainBundle\Export\AccompanyingCourseExportHelper;
|
use Chill\MainBundle\Export\AccompanyingCourseExportHelper;
|
||||||
|
use Chill\MainBundle\Export\ExportGenerationContext;
|
||||||
use Chill\MainBundle\Export\FormatterInterface;
|
use Chill\MainBundle\Export\FormatterInterface;
|
||||||
use Chill\MainBundle\Export\GroupedExportInterface;
|
use Chill\MainBundle\Export\GroupedExportInterface;
|
||||||
use Chill\MainBundle\Export\Helper\AggregateStringHelper;
|
use Chill\MainBundle\Export\Helper\AggregateStringHelper;
|
||||||
@ -212,7 +213,7 @@ final readonly class ListAccompanyingPeriodWorkAssociatePersonOnWork implements
|
|||||||
return Declarations::SOCIAL_WORK_ACTION_TYPE;
|
return Declarations::SOCIAL_WORK_ACTION_TYPE;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function initiateQuery(array $requiredModifiers, array $acl, array $data = [])
|
public function initiateQuery(array $requiredModifiers, array $acl, array $data, ExportGenerationContext $context)
|
||||||
{
|
{
|
||||||
$centers = array_map(static fn ($el) => $el['center'], $acl);
|
$centers = array_map(static fn ($el) => $el['center'], $acl);
|
||||||
$calcDate = $data['calc_date'] ?? new RollingDate(RollingDate::T_TODAY);
|
$calcDate = $data['calc_date'] ?? new RollingDate(RollingDate::T_TODAY);
|
||||||
@ -227,7 +228,7 @@ final readonly class ListAccompanyingPeriodWorkAssociatePersonOnWork implements
|
|||||||
->join('acpw.persons', 'person')
|
->join('acpw.persons', 'person')
|
||||||
;
|
;
|
||||||
|
|
||||||
$this->filterListAccompanyingPeriodHelper->addFilterAccompanyingPeriods($qb, $requiredModifiers, $acl, $data);
|
$this->filterListAccompanyingPeriodHelper->addFilterAccompanyingPeriods($qb, $requiredModifiers, $acl, $context->byUser, $data);
|
||||||
|
|
||||||
AccompanyingCourseExportHelper::addClosingMotiveExclusionClause($qb);
|
AccompanyingCourseExportHelper::addClosingMotiveExclusionClause($qb);
|
||||||
|
|
||||||
|
@ -12,6 +12,7 @@ declare(strict_types=1);
|
|||||||
namespace Chill\PersonBundle\Export\Export;
|
namespace Chill\PersonBundle\Export\Export;
|
||||||
|
|
||||||
use Chill\MainBundle\Export\AccompanyingCourseExportHelper;
|
use Chill\MainBundle\Export\AccompanyingCourseExportHelper;
|
||||||
|
use Chill\MainBundle\Export\ExportGenerationContext;
|
||||||
use Chill\MainBundle\Export\FormatterInterface;
|
use Chill\MainBundle\Export\FormatterInterface;
|
||||||
use Chill\MainBundle\Export\GroupedExportInterface;
|
use Chill\MainBundle\Export\GroupedExportInterface;
|
||||||
use Chill\MainBundle\Export\Helper\AggregateStringHelper;
|
use Chill\MainBundle\Export\Helper\AggregateStringHelper;
|
||||||
@ -200,7 +201,7 @@ final readonly class ListEvaluation implements ListInterface, GroupedExportInter
|
|||||||
return Declarations::EVAL_TYPE;
|
return Declarations::EVAL_TYPE;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function initiateQuery(array $requiredModifiers, array $acl, array $data = [])
|
public function initiateQuery(array $requiredModifiers, array $acl, array $data, ExportGenerationContext $context)
|
||||||
{
|
{
|
||||||
$centers = array_map(static fn ($el) => $el['center'], $acl);
|
$centers = array_map(static fn ($el) => $el['center'], $acl);
|
||||||
$calcDate = $data['calc_date'] ?? new RollingDate(RollingDate::T_TODAY);
|
$calcDate = $data['calc_date'] ?? new RollingDate(RollingDate::T_TODAY);
|
||||||
@ -221,7 +222,7 @@ final readonly class ListEvaluation implements ListInterface, GroupedExportInter
|
|||||||
->andWhere('acppart.startDate <= :calc_date AND (acppart.endDate > :calc_date OR acppart.endDate IS NULL)')
|
->andWhere('acppart.startDate <= :calc_date AND (acppart.endDate > :calc_date OR acppart.endDate IS NULL)')
|
||||||
->setParameter('calc_date', $this->rollingDateConverter->convert($calcDate));
|
->setParameter('calc_date', $this->rollingDateConverter->convert($calcDate));
|
||||||
|
|
||||||
$this->filterListAccompanyingPeriodHelper->addFilterAccompanyingPeriods($qb, $requiredModifiers, $acl, $data);
|
$this->filterListAccompanyingPeriodHelper->addFilterAccompanyingPeriods($qb, $requiredModifiers, $acl, $context->byUser, $data);
|
||||||
|
|
||||||
AccompanyingCourseExportHelper::addClosingMotiveExclusionClause($qb);
|
AccompanyingCourseExportHelper::addClosingMotiveExclusionClause($qb);
|
||||||
|
|
||||||
|
@ -12,6 +12,7 @@ declare(strict_types=1);
|
|||||||
namespace Chill\PersonBundle\Export\Export;
|
namespace Chill\PersonBundle\Export\Export;
|
||||||
|
|
||||||
use Chill\MainBundle\Export\AccompanyingCourseExportHelper;
|
use Chill\MainBundle\Export\AccompanyingCourseExportHelper;
|
||||||
|
use Chill\MainBundle\Export\ExportGenerationContext;
|
||||||
use Chill\MainBundle\Export\FormatterInterface;
|
use Chill\MainBundle\Export\FormatterInterface;
|
||||||
use Chill\MainBundle\Export\GroupedExportInterface;
|
use Chill\MainBundle\Export\GroupedExportInterface;
|
||||||
use Chill\MainBundle\Export\ListInterface;
|
use Chill\MainBundle\Export\ListInterface;
|
||||||
@ -121,7 +122,7 @@ final readonly class ListPersonWithAccompanyingPeriodDetails implements ListInte
|
|||||||
/**
|
/**
|
||||||
* param array{fields: string[], address_date: DateTimeImmutable} $data.
|
* param array{fields: string[], address_date: DateTimeImmutable} $data.
|
||||||
*/
|
*/
|
||||||
public function initiateQuery(array $requiredModifiers, array $acl, array $data = [])
|
public function initiateQuery(array $requiredModifiers, array $acl, array $data, ExportGenerationContext $context)
|
||||||
{
|
{
|
||||||
$centers = array_map(static fn ($el) => $el['center'], $acl);
|
$centers = array_map(static fn ($el) => $el['center'], $acl);
|
||||||
|
|
||||||
@ -132,7 +133,7 @@ final readonly class ListPersonWithAccompanyingPeriodDetails implements ListInte
|
|||||||
->join('acppart.accompanyingPeriod', 'acp')
|
->join('acppart.accompanyingPeriod', 'acp')
|
||||||
->andWhere($qb->expr()->neq('acp.step', "'".AccompanyingPeriod::STEP_DRAFT."'"));
|
->andWhere($qb->expr()->neq('acp.step', "'".AccompanyingPeriod::STEP_DRAFT."'"));
|
||||||
|
|
||||||
$this->filterListAccompanyingPeriodHelper->addFilterAccompanyingPeriods($qb, $requiredModifiers, $acl, $data);
|
$this->filterListAccompanyingPeriodHelper->addFilterAccompanyingPeriods($qb, $requiredModifiers, $acl, $context->byUser, $data);
|
||||||
|
|
||||||
$this->listPersonHelper->addSelect($qb, $this->rollingDateConverter->convert($data['address_date']));
|
$this->listPersonHelper->addSelect($qb, $this->rollingDateConverter->convert($data['address_date']));
|
||||||
$this->listAccompanyingPeriodHelper->addSelectClauses($qb, $this->rollingDateConverter->convert($data['address_date']));
|
$this->listAccompanyingPeriodHelper->addSelectClauses($qb, $this->rollingDateConverter->convert($data['address_date']));
|
||||||
|
@ -38,19 +38,13 @@ final readonly class FilterListAccompanyingPeriodHelper implements FilterListAcc
|
|||||||
$this->filterStatsByCenters = $parameterBag->get('chill_main')['acl']['filter_stats_by_center'];
|
$this->filterStatsByCenters = $parameterBag->get('chill_main')['acl']['filter_stats_by_center'];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function addFilterAccompanyingPeriods(QueryBuilder &$qb, array $requiredModifiers, array $acl, array $data = []): void
|
public function addFilterAccompanyingPeriods(QueryBuilder &$qb, array $requiredModifiers, array $acl, User $user, array $data = []): void
|
||||||
{
|
{
|
||||||
$centers = match ($this->filterStatsByCenters) {
|
$centers = match ($this->filterStatsByCenters) {
|
||||||
true => array_map(static fn ($el) => $el['center'], $acl),
|
true => array_map(static fn ($el) => $el['center'], $acl),
|
||||||
false => $this->centerRepository->findAll(),
|
false => $this->centerRepository->findAll(),
|
||||||
};
|
};
|
||||||
|
|
||||||
$user = $this->security->getUser();
|
|
||||||
|
|
||||||
if (!$user instanceof User) {
|
|
||||||
throw new \RuntimeException('only a regular user can run this export');
|
|
||||||
}
|
|
||||||
|
|
||||||
// add filtering on confidential accompanying period. The confidential is applyed on the current status of
|
// add filtering on confidential accompanying period. The confidential is applyed on the current status of
|
||||||
// the accompanying period (we do not use the 'calc_date' here
|
// the accompanying period (we do not use the 'calc_date' here
|
||||||
$aclConditionsOrX = $qb->expr()->orX(
|
$aclConditionsOrX = $qb->expr()->orX(
|
||||||
|
@ -11,6 +11,7 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace Chill\PersonBundle\Export\Helper;
|
namespace Chill\PersonBundle\Export\Helper;
|
||||||
|
|
||||||
|
use Chill\MainBundle\Entity\User;
|
||||||
use Doctrine\ORM\QueryBuilder;
|
use Doctrine\ORM\QueryBuilder;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -19,5 +20,5 @@ use Doctrine\ORM\QueryBuilder;
|
|||||||
*/
|
*/
|
||||||
interface FilterListAccompanyingPeriodHelperInterface
|
interface FilterListAccompanyingPeriodHelperInterface
|
||||||
{
|
{
|
||||||
public function addFilterAccompanyingPeriods(QueryBuilder &$qb, array $requiredModifiers, array $acl, array $data = []): void;
|
public function addFilterAccompanyingPeriods(QueryBuilder &$qb, array $requiredModifiers, array $acl, User $user, array $data = []): void;
|
||||||
}
|
}
|
||||||
|
@ -82,7 +82,7 @@ final class FilterListAccompanyingPeriodHelperTest extends KernelTestCase
|
|||||||
$parameterBag
|
$parameterBag
|
||||||
);
|
);
|
||||||
|
|
||||||
$filter->addFilterAccompanyingPeriods($qb, [], $this->getACL(), []);
|
$filter->addFilterAccompanyingPeriods($qb, [], $this->getACL(), $user, []);
|
||||||
|
|
||||||
$qb->setMaxResults(1);
|
$qb->setMaxResults(1);
|
||||||
$result = $qb->getQuery()->getResult();
|
$result = $qb->getQuery()->getResult();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user