mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-31 12:03:48 +00:00
Merge remote-tracking branch 'origin/master' into upgrade-sf5
This commit is contained in:
@@ -48,7 +48,7 @@ final readonly class ClosingDateAggregator implements AggregatorInterface
|
||||
|
||||
public function getLabels($key, array $values, mixed $data)
|
||||
{
|
||||
return function (string|null $value): string {
|
||||
return function (?string $value): string {
|
||||
if ('_header' === $value) {
|
||||
return 'export.aggregator.course.by_closing_date.header';
|
||||
}
|
||||
|
@@ -48,7 +48,7 @@ final readonly class OpeningDateAggregator implements AggregatorInterface
|
||||
|
||||
public function getLabels($key, array $values, mixed $data)
|
||||
{
|
||||
return function (string|null $value): string {
|
||||
return function (?string $value): string {
|
||||
if ('_header' === $value) {
|
||||
return 'export.aggregator.course.by_opening_date.header';
|
||||
}
|
||||
|
@@ -14,10 +14,8 @@ namespace Chill\PersonBundle\Export\Export;
|
||||
use Chill\CustomFieldsBundle\CustomFields\CustomFieldChoice;
|
||||
use Chill\CustomFieldsBundle\Entity\CustomField;
|
||||
use Chill\CustomFieldsBundle\Service\CustomFieldProvider;
|
||||
use Chill\MainBundle\Export\ExportElementValidatedInterface;
|
||||
use Chill\MainBundle\Export\FormatterInterface;
|
||||
use Chill\MainBundle\Export\GroupedExportInterface;
|
||||
use Chill\MainBundle\Export\Helper\ExportAddressHelper;
|
||||
use Chill\MainBundle\Export\ListInterface;
|
||||
use Chill\MainBundle\Form\Type\ChillDateType;
|
||||
use Chill\MainBundle\Templating\TranslatableStringHelper;
|
||||
@@ -30,21 +28,17 @@ use Doctrine\ORM\EntityManagerInterface;
|
||||
use Doctrine\ORM\Query;
|
||||
use PhpOffice\PhpSpreadsheet\Shared\Date;
|
||||
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
|
||||
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\Validator\Constraints\Callback;
|
||||
use Symfony\Component\Validator\Context\ExecutionContextInterface;
|
||||
|
||||
/**
|
||||
* Render a list of people.
|
||||
*/
|
||||
class ListPerson implements ExportElementValidatedInterface, ListInterface, GroupedExportInterface
|
||||
class ListPerson implements ListInterface, GroupedExportInterface
|
||||
{
|
||||
private array $slugs = [];
|
||||
private readonly bool $filterStatsByCenters;
|
||||
|
||||
public function __construct(
|
||||
private readonly ExportAddressHelper $addressHelper,
|
||||
private readonly CustomFieldProvider $customFieldProvider,
|
||||
private readonly ListPersonHelper $listPersonHelper,
|
||||
private readonly EntityManagerInterface $entityManager,
|
||||
@@ -56,39 +50,6 @@ class ListPerson implements ExportElementValidatedInterface, ListInterface, Grou
|
||||
|
||||
public function buildForm(FormBuilderInterface $builder)
|
||||
{
|
||||
$choices = array_combine(ListPersonHelper::FIELDS, ListPersonHelper::FIELDS);
|
||||
|
||||
foreach ($this->getCustomFields() as $cf) {
|
||||
$choices[$this->translatableStringHelper->localize($cf->getName())]
|
||||
=
|
||||
$cf->getSlug();
|
||||
}
|
||||
|
||||
// Add a checkbox to select fields
|
||||
$builder->add('fields', ChoiceType::class, [
|
||||
'multiple' => true,
|
||||
'expanded' => true,
|
||||
'choices' => $choices,
|
||||
'label' => 'Fields to include in export',
|
||||
'choice_attr' => static function (string $val): array {
|
||||
// add a 'data-display-target' for address fields
|
||||
if (str_starts_with($val, 'address') || 'center' === $val || 'household' === $val) {
|
||||
return ['data-display-target' => 'address_date'];
|
||||
}
|
||||
|
||||
return [];
|
||||
},
|
||||
'constraints' => [new Callback([
|
||||
'callback' => static function ($selected, ExecutionContextInterface $context) {
|
||||
if (0 === \count($selected)) {
|
||||
$context->buildViolation('You must select at least one element')
|
||||
->atPath('fields')
|
||||
->addViolation();
|
||||
}
|
||||
},
|
||||
])],
|
||||
]);
|
||||
|
||||
// add a date field for addresses
|
||||
$builder->add('address_date', ChillDateType::class, [
|
||||
'label' => 'Data valid at this date',
|
||||
@@ -99,15 +60,7 @@ class ListPerson implements ExportElementValidatedInterface, ListInterface, Grou
|
||||
|
||||
public function getFormDefaultData(): array
|
||||
{
|
||||
$choices = array_combine(ListPersonHelper::FIELDS, ListPersonHelper::FIELDS);
|
||||
|
||||
foreach ($this->getCustomFields() as $cf) {
|
||||
$choices[$this->translatableStringHelper->localize($cf->getName())]
|
||||
=
|
||||
$cf->getSlug();
|
||||
}
|
||||
|
||||
return ['fields' => array_values($choices), 'address_date' => new \DateTimeImmutable()];
|
||||
return ['address_date' => new \DateTimeImmutable()];
|
||||
}
|
||||
|
||||
public function getAllowedFormattersTypes()
|
||||
@@ -127,7 +80,7 @@ class ListPerson implements ExportElementValidatedInterface, ListInterface, Grou
|
||||
|
||||
public function getLabels($key, array $values, $data)
|
||||
{
|
||||
if (\in_array($key, $this->listPersonHelper->getAllPossibleFields(), true)) {
|
||||
if (\in_array($key, $this->listPersonHelper->getAllKeys(), true)) {
|
||||
return $this->listPersonHelper->getLabels($key, $values, $data);
|
||||
}
|
||||
|
||||
@@ -138,28 +91,12 @@ class ListPerson implements ExportElementValidatedInterface, ListInterface, Grou
|
||||
{
|
||||
$fields = [];
|
||||
|
||||
foreach (ListPersonHelper::FIELDS as $key) {
|
||||
if (!\in_array($key, $data['fields'], true)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (str_starts_with($key, 'address_fields')) {
|
||||
$fields = \array_merge($fields, $this->addressHelper->getKeys(ExportAddressHelper::F_ALL, 'address_fields'));
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if ('lifecycleUpdate' === $key) {
|
||||
$fields = \array_merge($fields, ['createdAt', 'createdBy', 'updatedAt', 'updatedBy']);
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach ($this->listPersonHelper->getAllKeys() as $key) {
|
||||
$fields[] = $key;
|
||||
}
|
||||
|
||||
// add the key from slugs and return
|
||||
return \array_merge($fields, \array_keys($this->slugs));
|
||||
return [...$fields, ...\array_keys($this->slugs)];
|
||||
}
|
||||
|
||||
public function getResult($query, $data)
|
||||
@@ -184,11 +121,6 @@ class ListPerson implements ExportElementValidatedInterface, ListInterface, Grou
|
||||
{
|
||||
$centers = array_map(static fn ($el) => $el['center'], $acl);
|
||||
|
||||
// throw an error if any fields are present
|
||||
if (!\array_key_exists('fields', $data)) {
|
||||
throw new \Doctrine\DBAL\Exception\InvalidArgumentException('any fields have been checked');
|
||||
}
|
||||
|
||||
$qb = $this->entityManager->createQueryBuilder()
|
||||
->from(Person::class, 'person');
|
||||
|
||||
@@ -202,15 +134,9 @@ class ListPerson implements ExportElementValidatedInterface, ListInterface, Grou
|
||||
->setParameter('authorized_centers', $centers);
|
||||
}
|
||||
|
||||
$fields = $data['fields'];
|
||||
|
||||
$this->listPersonHelper->addSelect($qb, $fields, $data['address_date']);
|
||||
$this->listPersonHelper->addSelect($qb, $data['address_date']);
|
||||
|
||||
foreach ($this->getCustomFields() as $cf) {
|
||||
if (!\in_array($cf->getSlug(), $fields, true)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$cfType = $this->customFieldProvider->getCustomFieldByType($cf->getType());
|
||||
|
||||
if ($cfType instanceof CustomFieldChoice && $cfType->isMultiple($cf)) {
|
||||
@@ -251,26 +177,6 @@ class ListPerson implements ExportElementValidatedInterface, ListInterface, Grou
|
||||
return [Declarations::PERSON_TYPE];
|
||||
}
|
||||
|
||||
public function validateForm($data, ExecutionContextInterface $context)
|
||||
{
|
||||
// get the field starting with address_
|
||||
$addressFields = array_filter(
|
||||
ListPersonHelper::FIELDS,
|
||||
static fn (string $el): bool => str_starts_with($el, 'address_')
|
||||
);
|
||||
|
||||
// check if there is one field starting with address in data
|
||||
if (\count(array_intersect($data['fields'], $addressFields)) > 0) {
|
||||
// if a field address is checked, the date must not be empty
|
||||
if (!$data['address_date'] instanceof \DateTimeImmutable) {
|
||||
$context
|
||||
->buildViolation('You must set this date if an address is checked')
|
||||
->atPath('address_date')
|
||||
->addViolation();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function DQLToSlug($cleanedSlug)
|
||||
{
|
||||
return $this->slugs[$cleanedSlug]['slug'];
|
||||
@@ -293,9 +199,9 @@ class ListPerson implements ExportElementValidatedInterface, ListInterface, Grou
|
||||
{
|
||||
return $this->entityManager
|
||||
->createQuery('SELECT cf '
|
||||
.'FROM ChillCustomFieldsBundle:CustomField cf '
|
||||
.'FROM '.CustomField::class.' cf '
|
||||
.'JOIN cf.customFieldGroup g '
|
||||
.'WHERE cf.type != :title AND g.entity LIKE :entity')
|
||||
.'WHERE cf.type != :title AND g.entity LIKE :entity AND cf.active = TRUE')
|
||||
->setParameters([
|
||||
'title' => 'title',
|
||||
'entity' => \addcslashes(Person::class, '\\'),
|
||||
|
@@ -12,10 +12,8 @@ declare(strict_types=1);
|
||||
namespace Chill\PersonBundle\Export\Export;
|
||||
|
||||
use Chill\MainBundle\Export\AccompanyingCourseExportHelper;
|
||||
use Chill\MainBundle\Export\ExportElementValidatedInterface;
|
||||
use Chill\MainBundle\Export\FormatterInterface;
|
||||
use Chill\MainBundle\Export\GroupedExportInterface;
|
||||
use Chill\MainBundle\Export\Helper\ExportAddressHelper;
|
||||
use Chill\MainBundle\Export\ListInterface;
|
||||
use Chill\MainBundle\Form\Type\PickRollingDateType;
|
||||
use Chill\MainBundle\Service\RollingDate\RollingDate;
|
||||
@@ -30,22 +28,18 @@ use DateTimeImmutable;
|
||||
use Doctrine\ORM\AbstractQuery;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
|
||||
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\Validator\Constraints\Callback;
|
||||
use Symfony\Component\Validator\Context\ExecutionContextInterface;
|
||||
|
||||
/**
|
||||
* List the persons, having an accompanying period.
|
||||
*
|
||||
* Details of the accompanying period are not included
|
||||
*/
|
||||
final readonly class ListPersonHavingAccompanyingPeriod implements ExportElementValidatedInterface, ListInterface, GroupedExportInterface
|
||||
final readonly class ListPersonHavingAccompanyingPeriod implements ListInterface, GroupedExportInterface
|
||||
{
|
||||
private bool $filterStatsByCenters;
|
||||
|
||||
public function __construct(
|
||||
private ExportAddressHelper $addressHelper,
|
||||
private ListPersonHelper $listPersonHelper,
|
||||
private EntityManagerInterface $entityManager,
|
||||
private RollingDateConverterInterface $rollingDateConverter,
|
||||
@@ -56,32 +50,6 @@ final readonly class ListPersonHavingAccompanyingPeriod implements ExportElement
|
||||
|
||||
public function buildForm(FormBuilderInterface $builder)
|
||||
{
|
||||
$choices = array_combine(ListPersonHelper::FIELDS, ListPersonHelper::FIELDS);
|
||||
|
||||
$builder->add('fields', ChoiceType::class, [
|
||||
'multiple' => true,
|
||||
'expanded' => true,
|
||||
'choices' => $choices,
|
||||
'label' => 'Fields to include in export',
|
||||
'choice_attr' => static function (string $val): array {
|
||||
// add a 'data-display-target' for address fields
|
||||
if (str_starts_with($val, 'address') || 'center' === $val || 'household' === $val) {
|
||||
return ['data-display-target' => 'address_date'];
|
||||
}
|
||||
|
||||
return [];
|
||||
},
|
||||
'constraints' => [new Callback([
|
||||
'callback' => static function ($selected, ExecutionContextInterface $context) {
|
||||
if (0 === \count($selected)) {
|
||||
$context->buildViolation('You must select at least one element')
|
||||
->atPath('fields')
|
||||
->addViolation();
|
||||
}
|
||||
},
|
||||
])],
|
||||
]);
|
||||
|
||||
$builder->add('address_date_rolling', PickRollingDateType::class, [
|
||||
'label' => 'Data valid at this date',
|
||||
'help' => 'Data regarding center, addresses, and so on will be computed at this date',
|
||||
@@ -90,9 +58,7 @@ final readonly class ListPersonHavingAccompanyingPeriod implements ExportElement
|
||||
|
||||
public function getFormDefaultData(): array
|
||||
{
|
||||
$choices = array_combine(ListPersonHelper::FIELDS, ListPersonHelper::FIELDS);
|
||||
|
||||
return ['fields' => array_values($choices), 'address_date_rolling' => new RollingDate(RollingDate::T_TODAY)];
|
||||
return ['address_date_rolling' => new RollingDate(RollingDate::T_TODAY)];
|
||||
}
|
||||
|
||||
public function getAllowedFormattersTypes()
|
||||
@@ -117,29 +83,7 @@ final readonly class ListPersonHavingAccompanyingPeriod implements ExportElement
|
||||
|
||||
public function getQueryKeys($data)
|
||||
{
|
||||
$fields = [];
|
||||
|
||||
foreach (ListPersonHelper::FIELDS as $key) {
|
||||
if (!\in_array($key, $data['fields'], true)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (str_starts_with($key, 'address_fields')) {
|
||||
$fields = array_merge($fields, $this->addressHelper->getKeys(ExportAddressHelper::F_ALL, 'address_fields'));
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if ('lifecycleUpdate' === $key) {
|
||||
$fields = array_merge($fields, ['createdAt', 'createdBy', 'updatedAt', 'updatedBy']);
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
$fields[] = $key;
|
||||
}
|
||||
|
||||
return $fields;
|
||||
return $this->listPersonHelper->getAllKeys();
|
||||
}
|
||||
|
||||
public function getResult($query, $data)
|
||||
@@ -164,11 +108,6 @@ final readonly class ListPersonHavingAccompanyingPeriod implements ExportElement
|
||||
{
|
||||
$centers = array_map(static fn ($el) => $el['center'], $acl);
|
||||
|
||||
// throw an error if any fields are present
|
||||
if (!\array_key_exists('fields', $data)) {
|
||||
throw new \Doctrine\DBAL\Exception\InvalidArgumentException('any fields have been checked');
|
||||
}
|
||||
|
||||
$qb = $this->entityManager->createQueryBuilder();
|
||||
|
||||
$qb->from(Person::class, 'person')
|
||||
@@ -185,9 +124,7 @@ final readonly class ListPersonHavingAccompanyingPeriod implements ExportElement
|
||||
)->setParameter('authorized_centers', $centers);
|
||||
}
|
||||
|
||||
$fields = $data['fields'];
|
||||
|
||||
$this->listPersonHelper->addSelect($qb, $fields, $this->rollingDateConverter->convert($data['address_date_rolling']));
|
||||
$this->listPersonHelper->addSelect($qb, $this->rollingDateConverter->convert($data['address_date_rolling']));
|
||||
|
||||
AccompanyingCourseExportHelper::addClosingMotiveExclusionClause($qb);
|
||||
|
||||
@@ -208,24 +145,4 @@ final readonly class ListPersonHavingAccompanyingPeriod implements ExportElement
|
||||
{
|
||||
return [Declarations::PERSON_TYPE, Declarations::ACP_TYPE];
|
||||
}
|
||||
|
||||
public function validateForm($data, ExecutionContextInterface $context)
|
||||
{
|
||||
// get the field starting with address_
|
||||
$addressFields = array_filter(
|
||||
ListPersonHelper::FIELDS,
|
||||
static fn (string $el): bool => str_starts_with($el, 'address_')
|
||||
);
|
||||
|
||||
// check if there is one field starting with address in data
|
||||
if (\count(array_intersect($data['fields'], $addressFields)) > 0) {
|
||||
// if a field address is checked, the date must not be empty
|
||||
if (!$data['address_date'] instanceof \DateTimeImmutable) {
|
||||
$context
|
||||
->buildViolation('You must set this date if an address is checked')
|
||||
->atPath('address_date')
|
||||
->addViolation();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -119,7 +119,7 @@ final readonly class ListPersonWithAccompanyingPeriodDetails implements ListInte
|
||||
|
||||
$this->filterListAccompanyingPeriodHelper->addFilterAccompanyingPeriods($qb, $requiredModifiers, $acl, $data);
|
||||
|
||||
$this->listPersonHelper->addSelect($qb, ListPersonHelper::FIELDS, $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']));
|
||||
|
||||
AccompanyingCourseExportHelper::addClosingMotiveExclusionClause($qb);
|
||||
|
@@ -83,13 +83,10 @@ readonly class JobWorkingOnCourseFilter implements FilterInterface
|
||||
|
||||
public function buildForm(FormBuilderInterface $builder): void
|
||||
{
|
||||
$jobs = $this->userJobRepository->findAllActive();
|
||||
usort($jobs, fn (UserJob $a, UserJob $b) => $this->translatableStringHelper->localize($a->getLabel()) <=> $this->translatableStringHelper->localize($b->getLabel()));
|
||||
|
||||
$builder
|
||||
->add('jobs', EntityType::class, [
|
||||
'class' => UserJob::class,
|
||||
'choices' => $jobs,
|
||||
'choices' => $this->userJobRepository->findAllActive(),
|
||||
'choice_label' => fn (UserJob $userJob) => $this->translatableStringHelper->localize($userJob->getLabel()),
|
||||
'multiple' => true,
|
||||
'expanded' => true,
|
||||
|
@@ -83,13 +83,10 @@ readonly class ScopeWorkingOnCourseFilter implements FilterInterface
|
||||
|
||||
public function buildForm(FormBuilderInterface $builder): void
|
||||
{
|
||||
$scopes = $this->scopeRepository->findAllActive();
|
||||
usort($scopes, fn (Scope $a, Scope $b) => $this->translatableStringHelper->localize($a->getName()) <=> $this->translatableStringHelper->localize($b->getName()));
|
||||
|
||||
$builder
|
||||
->add('scopes', EntityType::class, [
|
||||
'class' => Scope::class,
|
||||
'choices' => $scopes,
|
||||
'choices' => $this->scopeRepository->findAllActive(),
|
||||
'choice_label' => fn (Scope $scope) => $this->translatableStringHelper->localize($scope->getName()),
|
||||
'multiple' => true,
|
||||
'expanded' => true,
|
||||
|
@@ -0,0 +1,85 @@
|
||||
<?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\PersonBundle\Export\Filter\SocialWorkFilters;
|
||||
|
||||
use Chill\MainBundle\Export\FilterInterface;
|
||||
use Chill\MainBundle\Form\Type\PickRollingDateType;
|
||||
use Chill\MainBundle\Service\RollingDate\RollingDate;
|
||||
use Chill\MainBundle\Service\RollingDate\RollingDateConverterInterface;
|
||||
use Chill\PersonBundle\Entity\AccompanyingPeriod\AccompanyingPeriodWorkEvaluation;
|
||||
use Chill\PersonBundle\Export\Declarations;
|
||||
use Doctrine\ORM\QueryBuilder;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
|
||||
final readonly class AccompanyingPeriodWorkWithEvaluationBetweenDatesFilter implements FilterInterface
|
||||
{
|
||||
public function __construct(
|
||||
private RollingDateConverterInterface $rollingDateConverter,
|
||||
) {
|
||||
}
|
||||
|
||||
public function buildForm(FormBuilderInterface $builder): void
|
||||
{
|
||||
$builder
|
||||
->add('start_date', PickRollingDateType::class, [
|
||||
'label' => 'export.filter.work.evaluation_between_dates.start_date',
|
||||
])
|
||||
->add('end_date', PickRollingDateType::class, [
|
||||
'label' => 'export.filter.work.evaluation_between_dates.end_date',
|
||||
]);
|
||||
}
|
||||
|
||||
public function getFormDefaultData(): array
|
||||
{
|
||||
return ['start_date' => new RollingDate(RollingDate::T_YEAR_CURRENT_START), 'end_date' => new RollingDate(RollingDate::T_TODAY)];
|
||||
}
|
||||
|
||||
public function getTitle(): string
|
||||
{
|
||||
return 'export.filter.work.evaluation_between_dates.title';
|
||||
}
|
||||
|
||||
public function describeAction($data, $format = 'string'): array
|
||||
{
|
||||
return [
|
||||
'export.filter.work.evaluation_between_dates.description',
|
||||
[
|
||||
'%startDate%' => null !== $data['start_date'] ? $this->rollingDateConverter->convert($data['start_date'])->format('d-m-Y') : '',
|
||||
'%endDate%' => null !== $data['end_date'] ? $this->rollingDateConverter->convert($data['end_date'])->format('d-m-Y') : '',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
public function addRole(): ?string
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public function alterQuery(QueryBuilder $qb, $data): void
|
||||
{
|
||||
$s = 'workeval_between_filter_start';
|
||||
$e = 'workeval_between_filter_end';
|
||||
|
||||
$qb->andWhere(
|
||||
$qb->expr()->exists(
|
||||
'SELECT 1 FROM '.AccompanyingPeriodWorkEvaluation::class." workeval_between_filter_workeval WHERE workeval_between_filter_workeval.createdAt BETWEEN :{$s} AND :{$e} AND IDENTITY(workeval_between_filter_workeval.accompanyingPeriodWork) = acpw.id"
|
||||
)
|
||||
)
|
||||
->setParameter($s, $this->rollingDateConverter->convert($data['start_date']))
|
||||
->setParameter($e, $this->rollingDateConverter->convert($data['end_date']));
|
||||
}
|
||||
|
||||
public function applyOn(): string
|
||||
{
|
||||
return Declarations::SOCIAL_WORK_ACTION_TYPE;
|
||||
}
|
||||
}
|
@@ -13,6 +13,7 @@ namespace Chill\PersonBundle\Export\Filter\SocialWorkFilters;
|
||||
|
||||
use Chill\MainBundle\Entity\UserJob;
|
||||
use Chill\MainBundle\Export\FilterInterface;
|
||||
use Chill\MainBundle\Repository\UserJobRepositoryInterface;
|
||||
use Chill\MainBundle\Service\RollingDate\RollingDate;
|
||||
use Chill\MainBundle\Templating\TranslatableStringHelper;
|
||||
use Chill\PersonBundle\Entity\AccompanyingPeriod\AccompanyingPeriodWorkReferrerHistory;
|
||||
@@ -28,8 +29,10 @@ class JobFilter implements FilterInterface
|
||||
|
||||
public function __construct(
|
||||
protected TranslatorInterface $translator,
|
||||
private readonly TranslatableStringHelper $translatableStringHelper
|
||||
) {}
|
||||
private readonly TranslatableStringHelper $translatableStringHelper,
|
||||
private readonly UserJobRepositoryInterface $userJobRepository,
|
||||
) {
|
||||
}
|
||||
|
||||
public function addRole(): ?string
|
||||
{
|
||||
@@ -60,6 +63,7 @@ class JobFilter implements FilterInterface
|
||||
$builder
|
||||
->add('job', EntityType::class, [
|
||||
'class' => UserJob::class,
|
||||
'choices' => $this->userJobRepository->findAllActive(),
|
||||
'choice_label' => fn (UserJob $j) => $this->translatableStringHelper->localize(
|
||||
$j->getLabel()
|
||||
),
|
||||
|
@@ -13,6 +13,7 @@ namespace Chill\PersonBundle\Export\Filter\SocialWorkFilters;
|
||||
|
||||
use Chill\MainBundle\Entity\Scope;
|
||||
use Chill\MainBundle\Export\FilterInterface;
|
||||
use Chill\MainBundle\Repository\ScopeRepositoryInterface;
|
||||
use Chill\MainBundle\Service\RollingDate\RollingDate;
|
||||
use Chill\MainBundle\Templating\TranslatableStringHelper;
|
||||
use Chill\PersonBundle\Entity\AccompanyingPeriod\AccompanyingPeriodWorkReferrerHistory;
|
||||
@@ -28,8 +29,10 @@ class ScopeFilter implements FilterInterface
|
||||
|
||||
public function __construct(
|
||||
protected TranslatorInterface $translator,
|
||||
private readonly TranslatableStringHelper $translatableStringHelper
|
||||
) {}
|
||||
private readonly TranslatableStringHelper $translatableStringHelper,
|
||||
private readonly ScopeRepositoryInterface $scopeRepository
|
||||
) {
|
||||
}
|
||||
|
||||
public function addRole(): ?string
|
||||
{
|
||||
@@ -59,6 +62,7 @@ class ScopeFilter implements FilterInterface
|
||||
$builder
|
||||
->add('scope', EntityType::class, [
|
||||
'class' => Scope::class,
|
||||
'choices' => $this->scopeRepository->findAllActive(),
|
||||
'choice_label' => fn (Scope $s) => $this->translatableStringHelper->localize(
|
||||
$s->getName()
|
||||
),
|
||||
|
@@ -0,0 +1,36 @@
|
||||
<?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\PersonBundle\Export\Helper;
|
||||
|
||||
use Doctrine\ORM\QueryBuilder;
|
||||
|
||||
/**
|
||||
* This interface provides methods for customizing the list of person.
|
||||
*/
|
||||
interface CustomizeListPersonHelperInterface
|
||||
{
|
||||
/**
|
||||
* Alter the keys possibles (column header) for the list.
|
||||
*/
|
||||
public function alterKeys(array $existing): array;
|
||||
|
||||
public function alterSelect(QueryBuilder $qb, \DateTimeImmutable $computedDate): void;
|
||||
|
||||
/**
|
||||
* Return the callable which transform the doctrine result representation.
|
||||
*
|
||||
* If the key is not managed by the current implementation, this method must return null.
|
||||
*
|
||||
* @return callable|null return null if the key is not managed by the current implementation
|
||||
*/
|
||||
public function getLabels(string $key, array $values, array $data): ?callable;
|
||||
}
|
@@ -16,10 +16,12 @@ use Chill\MainBundle\Entity\Scope;
|
||||
use Chill\MainBundle\Export\Helper\DateTimeHelper;
|
||||
use Chill\MainBundle\Export\Helper\ExportAddressHelper;
|
||||
use Chill\MainBundle\Export\Helper\UserHelper;
|
||||
use Chill\MainBundle\Repository\CenterRepository;
|
||||
use Chill\MainBundle\Templating\TranslatableStringHelperInterface;
|
||||
use Chill\PersonBundle\Entity\AccompanyingPeriod;
|
||||
use Chill\PersonBundle\Entity\AccompanyingPeriodParticipation;
|
||||
use Chill\PersonBundle\Entity\Household\PersonHouseholdAddress;
|
||||
use Chill\PersonBundle\Entity\Person\PersonCenterHistory;
|
||||
use Chill\PersonBundle\Entity\SocialWork\SocialIssue;
|
||||
use Chill\PersonBundle\Repository\PersonRepository;
|
||||
use Chill\PersonBundle\Repository\SocialWork\SocialIssueRepository;
|
||||
@@ -39,6 +41,8 @@ final readonly class ListAccompanyingPeriodHelper
|
||||
'stepSince',
|
||||
'openingDate',
|
||||
'closingDate',
|
||||
'duration',
|
||||
'centers',
|
||||
'referrer',
|
||||
'referrerSince',
|
||||
'acpParticipantPersons',
|
||||
@@ -83,7 +87,9 @@ final readonly class ListAccompanyingPeriodHelper
|
||||
private TranslatorInterface $translator,
|
||||
private UserHelper $userHelper,
|
||||
private LabelPersonHelper $labelPersonHelper,
|
||||
) {}
|
||||
private CenterRepository $centerRepository
|
||||
) {
|
||||
}
|
||||
|
||||
public function getQueryKeys($data)
|
||||
{
|
||||
@@ -201,6 +207,25 @@ final readonly class ListAccompanyingPeriodHelper
|
||||
AccompanyingPeriod::INTENSITY_REGULAR => $this->translator->trans('regular'),
|
||||
default => $value,
|
||||
},
|
||||
'centers' => function ($value) use ($key) {
|
||||
if ('_header' === $value) {
|
||||
return 'export.list.acp.'.$key;
|
||||
}
|
||||
|
||||
if (null === $value || '' === $value || !json_validate((string) $value)) {
|
||||
return '';
|
||||
}
|
||||
|
||||
return implode(
|
||||
'|',
|
||||
array_map(
|
||||
fn ($cid) => $this->centerRepository->find($cid)->getName(),
|
||||
array_unique(
|
||||
json_decode((string) $value, true, 512, JSON_THROW_ON_ERROR)
|
||||
)
|
||||
)
|
||||
);
|
||||
},
|
||||
default => static function ($value) use ($key) {
|
||||
if ('_header' === $value) {
|
||||
return 'export.list.acp.'.$key;
|
||||
@@ -314,6 +339,19 @@ final readonly class ListAccompanyingPeriodHelper
|
||||
// social issues
|
||||
->addSelect('(SELECT AGGREGATE(socialIssue.id) FROM '.SocialIssue::class.' socialIssue WHERE socialIssue MEMBER OF acp.socialIssues) AS socialIssues');
|
||||
|
||||
// duration
|
||||
$qb->addSelect('DATE_DIFF(COALESCE(acp.closingDate, :calcDate), acp.openingDate) AS duration');
|
||||
|
||||
// centers
|
||||
$qb->addSelect(
|
||||
'(SELECT AGGREGATE(IDENTITY(cppch.center))
|
||||
FROM '.AccompanyingPeriodParticipation::class.' part
|
||||
JOIN '.PersonCenterHistory::class." cppch
|
||||
WITH IDENTITY(cppch.person) = IDENTITY(part.person)
|
||||
AND OVERLAPSI (cppch.startDate, cppch.endDate), (part.startDate, part.endDate) = 'TRUE'
|
||||
WHERE part.accompanyingPeriod = acp
|
||||
) AS centers"
|
||||
);
|
||||
// add parameter
|
||||
$qb->setParameter('calcDate', $calcDate);
|
||||
}
|
||||
|
@@ -35,9 +35,9 @@ use Symfony\Contracts\Translation\TranslatorInterface;
|
||||
*
|
||||
* for some fields
|
||||
*/
|
||||
class ListPersonHelper
|
||||
final readonly class ListPersonHelper
|
||||
{
|
||||
final public const FIELDS = [
|
||||
private const FIELDS = [
|
||||
'personId',
|
||||
'civility',
|
||||
'firstName',
|
||||
@@ -60,16 +60,32 @@ class ListPersonHelper
|
||||
'countryOfBirth',
|
||||
'nationality',
|
||||
// add full addresses
|
||||
'address_fields',
|
||||
// 'address_fields',
|
||||
// add a list of spoken languages
|
||||
'spokenLanguages',
|
||||
// add household id
|
||||
'household_id',
|
||||
// add created at, created by, updated at, and updated by
|
||||
'lifecycleUpdate',
|
||||
// 'lifecycleUpdate',
|
||||
'createdAt', 'createdBy', 'updatedAt', 'updatedBy',
|
||||
];
|
||||
|
||||
public function __construct(private readonly ExportAddressHelper $addressHelper, private readonly CenterRepositoryInterface $centerRepository, private readonly CivilityRepositoryInterface $civilityRepository, private readonly CountryRepository $countryRepository, private readonly LanguageRepositoryInterface $languageRepository, private readonly MaritalStatusRepositoryInterface $maritalStatusRepository, private readonly TranslatableStringHelper $translatableStringHelper, private readonly TranslatorInterface $translator, private readonly UserRepositoryInterface $userRepository) {}
|
||||
public function __construct(
|
||||
private ExportAddressHelper $addressHelper,
|
||||
private CenterRepositoryInterface $centerRepository,
|
||||
private CivilityRepositoryInterface $civilityRepository,
|
||||
private CountryRepository $countryRepository,
|
||||
private LanguageRepositoryInterface $languageRepository,
|
||||
private MaritalStatusRepositoryInterface $maritalStatusRepository,
|
||||
private TranslatableStringHelper $translatableStringHelper,
|
||||
private TranslatorInterface $translator,
|
||||
private UserRepositoryInterface $userRepository,
|
||||
/**
|
||||
* @var iterable<CustomizeListPersonHelperInterface>
|
||||
*/
|
||||
private iterable $customPersonHelpers,
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Those keys are the "direct" keys, which are created when we decide to use to list all the keys.
|
||||
@@ -80,26 +96,34 @@ class ListPersonHelper
|
||||
*/
|
||||
public function getAllKeys(): array
|
||||
{
|
||||
return [
|
||||
...array_filter(
|
||||
ListPersonHelper::FIELDS,
|
||||
fn (string $key) => !\in_array($key, ['address_fields', 'lifecycleUpdate'], true)
|
||||
),
|
||||
$keys = [
|
||||
...ListPersonHelper::FIELDS,
|
||||
...$this->addressHelper->getKeys(ExportAddressHelper::F_ALL, 'address_fields'),
|
||||
...['createdAt', 'createdBy', 'updatedAt', 'updatedBy'],
|
||||
];
|
||||
|
||||
foreach ($this->customPersonHelpers as $customize) {
|
||||
$keys = $customize->alterKeys($keys);
|
||||
}
|
||||
|
||||
return $keys;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<value-of<self::FIELDS>> $fields
|
||||
*/
|
||||
public function addSelect(QueryBuilder $qb, array $fields, \DateTimeImmutable $computedDate): void
|
||||
public function addSelect(QueryBuilder $qb, \DateTimeImmutable $computedDate): void
|
||||
{
|
||||
foreach (ListPersonHelper::FIELDS as $f) {
|
||||
if (!\in_array($f, $fields, true)) {
|
||||
continue;
|
||||
}
|
||||
// we first add all the fields which are handled by the
|
||||
$focusedFieldKeys = [
|
||||
'personId', 'countryOfBirth', 'nationality', // 'address_fields',
|
||||
'spokenLanguages', 'household_id', 'center', // 'lifecycleUpdate',
|
||||
'genderComment', 'maritalStatus', 'maritalStatusComment', 'civility',
|
||||
'createdAt', 'createdBy', 'updatedAt', 'updatedBy',
|
||||
];
|
||||
|
||||
$filteredFields = array_filter(
|
||||
ListPersonHelper::FIELDS,
|
||||
fn ($field) => !in_array($field, $focusedFieldKeys, true)
|
||||
);
|
||||
|
||||
foreach ($this->getAllKeys() as $f) {
|
||||
switch ($f) {
|
||||
case 'personId':
|
||||
$qb->addSelect('person.id AS personId');
|
||||
@@ -112,13 +136,6 @@ class ListPersonHelper
|
||||
|
||||
break;
|
||||
|
||||
case 'address_fields':
|
||||
$this->addCurrentAddressAt($qb, $computedDate);
|
||||
$qb->leftJoin('personHouseholdAddress.address', 'personAddress');
|
||||
$this->addressHelper->addSelectClauses(ExportAddressHelper::F_ALL, $qb, 'personAddress', 'address_fields');
|
||||
|
||||
break;
|
||||
|
||||
case 'spokenLanguages':
|
||||
$qb->addSelect('(SELECT AGGREGATE(language.id) FROM '.Language::class.' language WHERE language MEMBER OF person.spokenLanguages) AS spokenLanguages');
|
||||
|
||||
@@ -152,15 +169,6 @@ class ListPersonHelper
|
||||
|
||||
break;
|
||||
|
||||
case 'lifecycleUpdate':
|
||||
$qb
|
||||
->addSelect('person.createdAt AS createdAt')
|
||||
->addSelect('IDENTITY(person.createdBy) AS createdBy')
|
||||
->addSelect('person.updatedAt AS updatedAt')
|
||||
->addSelect('IDENTITY(person.updatedBy) AS updatedBy');
|
||||
|
||||
break;
|
||||
|
||||
case 'genderComment':
|
||||
$qb->addSelect('person.genderComment.comment AS genderComment');
|
||||
|
||||
@@ -182,25 +190,47 @@ class ListPersonHelper
|
||||
break;
|
||||
|
||||
default:
|
||||
$qb->addSelect(sprintf('person.%s as %s', $f, $f));
|
||||
if (in_array($f, $filteredFields, true)) {
|
||||
$qb->addSelect(sprintf('person.%s as %s', $f, $f));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// address
|
||||
$this->addCurrentAddressAt($qb, $computedDate);
|
||||
$qb->leftJoin('personHouseholdAddress.address', 'personAddress');
|
||||
$this->addressHelper->addSelectClauses(ExportAddressHelper::F_ALL, $qb, 'personAddress', 'address_fields');
|
||||
|
||||
// lifecycle update
|
||||
$qb
|
||||
->addSelect('person.createdAt AS createdAt')
|
||||
->addSelect('IDENTITY(person.createdBy) AS createdBy')
|
||||
->addSelect('person.updatedAt AS updatedAt')
|
||||
->addSelect('IDENTITY(person.updatedBy) AS updatedBy');
|
||||
|
||||
foreach ($this->customPersonHelpers as $customPersonHelper) {
|
||||
$customPersonHelper->alterSelect($qb, $computedDate);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array|string[]
|
||||
*
|
||||
* @deprecated
|
||||
*/
|
||||
public function getAllPossibleFields(): array
|
||||
{
|
||||
return array_merge(
|
||||
self::FIELDS,
|
||||
['createdAt', 'createdBy', 'updatedAt', 'updatedBy'],
|
||||
$this->addressHelper->getKeys(ExportAddressHelper::F_ALL, 'address_fields')
|
||||
);
|
||||
return $this->getAllKeys();
|
||||
}
|
||||
|
||||
public function getLabels($key, array $values, $data): callable
|
||||
{
|
||||
foreach ($this->customPersonHelpers as $customPersonHelper) {
|
||||
if (null !== $callable = $customPersonHelper->getLabels($key, $values, $data)) {
|
||||
return $callable;
|
||||
}
|
||||
}
|
||||
|
||||
if (str_starts_with((string) $key, 'address_fields')) {
|
||||
return $this->addressHelper->getLabel($key, $values, $data, 'address_fields');
|
||||
}
|
||||
@@ -364,7 +394,7 @@ class ListPersonHelper
|
||||
};
|
||||
|
||||
default:
|
||||
if (!\in_array($key, self::getAllPossibleFields(), true)) {
|
||||
if (!\in_array($key, self::getAllKeys(), true)) {
|
||||
throw new \RuntimeException("this key is not supported by this helper: {$key}");
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user