Merge remote-tracking branch 'origin/master' into upgrade-sf5

This commit is contained in:
2024-04-04 18:45:01 +02:00
162 changed files with 3849 additions and 713 deletions

View File

@@ -38,7 +38,7 @@ readonly class AccompanyingPeriodStepChangeCronjob implements CronJobInterface
return 'accompanying-period-step-change';
}
public function run(array $lastExecutionData): array|null
public function run(array $lastExecutionData): ?array
{
($this->requestor)();

View File

@@ -13,6 +13,7 @@ namespace Chill\PersonBundle;
use Chill\PersonBundle\Actions\Remove\PersonMoveSqlHandlerInterface;
use Chill\PersonBundle\DependencyInjection\CompilerPass\AccompanyingPeriodTimelineCompilerPass;
use Chill\PersonBundle\Export\Helper\CustomizeListPersonHelperInterface;
use Chill\PersonBundle\Service\EntityInfo\AccompanyingPeriodInfoUnionQueryPartInterface;
use Chill\PersonBundle\Widget\PersonListWidgetFactory;
use Symfony\Component\DependencyInjection\ContainerBuilder;
@@ -32,5 +33,7 @@ class ChillPersonBundle extends Bundle
->addTag('chill_person.accompanying_period_info_part');
$container->registerForAutoconfiguration(PersonMoveSqlHandlerInterface::class)
->addTag('chill_person.person_move_handler');
$container->registerForAutoconfiguration(CustomizeListPersonHelperInterface::class)
->addTag('chill_person.list_person_customizer');
}
}

View File

@@ -22,8 +22,8 @@ use Symfony\Component\Config\Definition\ConfigurationInterface;
class Configuration implements ConfigurationInterface
{
private string $validationBirthdateNotAfterInfos = 'The period before today during which'
.' any birthdate is not allowed. The birthdate is expressed as ISO8601 : '
.'https://en.wikipedia.org/wiki/ISO_8601#Durations';
.' any birthdate is not allowed. The birthdate is expressed as ISO8601 : '
.'https://en.wikipedia.org/wiki/ISO_8601#Durations';
public function getConfigTreeBuilder()
{

View File

@@ -12,7 +12,6 @@ declare(strict_types=1);
namespace Chill\PersonBundle\Doctrine\DQL;
use Doctrine\ORM\Query\AST\Functions\FunctionNode;
use Doctrine\ORM\Query\Lexer;
use Doctrine\ORM\Query\Parser;
use Doctrine\ORM\Query\SqlWalker;
@@ -73,13 +72,13 @@ abstract class AddressPart extends FunctionNode
public function parse(Parser $parser)
{
$a = $parser->match(Lexer::T_IDENTIFIER);
$parser->match(Lexer::T_OPEN_PARENTHESIS);
$a = $parser->match(\Doctrine\ORM\Query\TokenType::T_IDENTIFIER);
$parser->match(\Doctrine\ORM\Query\TokenType::T_OPEN_PARENTHESIS);
// person id
$this->pid = $parser->SingleValuedPathExpression();
$parser->match(Lexer::T_COMMA);
$parser->match(\Doctrine\ORM\Query\TokenType::T_COMMA);
// date
$this->date = $parser->ArithmeticPrimary();
$parser->match(Lexer::T_CLOSE_PARENTHESIS);
$parser->match(\Doctrine\ORM\Query\TokenType::T_CLOSE_PARENTHESIS);
}
}

View File

@@ -555,7 +555,7 @@ class AccompanyingPeriod implements
// ensure continuity of histories
$criteria = new Criteria();
$criteria->orderBy(['startDate' => Criteria::ASC, 'id' => Criteria::ASC]);
$criteria->orderBy(['startDate' => \Doctrine\Common\Collections\Order::Ascending, 'id' => \Doctrine\Common\Collections\Order::Ascending]);
/** @var \Iterator $locations */
$locations = $this->getLocationHistories()->matching($criteria)->getIterator();
@@ -1536,7 +1536,7 @@ class AccompanyingPeriod implements
{
// ensure continuity of histories
$criteria = new Criteria();
$criteria->orderBy(['startDate' => Criteria::ASC, 'id' => Criteria::ASC]);
$criteria->orderBy(['startDate' => \Doctrine\Common\Collections\Order::Ascending, 'id' => \Doctrine\Common\Collections\Order::Ascending]);
/** @var \Iterator $steps */
$steps = $this->getStepHistories()->matching($criteria)->getIterator();

View File

@@ -1205,7 +1205,7 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI
->where(
$expr->eq('shareHousehold', false)
)
->orderBy(['startDate' => Criteria::DESC]);
->orderBy(['startDate' => \Doctrine\Common\Collections\Order::Descending]);
return $this->getHouseholdParticipations()
->matching($criteria);
@@ -1227,7 +1227,7 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI
->where(
$expr->eq('shareHousehold', true)
)
->orderBy(['startDate' => Criteria::DESC, 'id' => Criteria::DESC]);
->orderBy(['startDate' => \Doctrine\Common\Collections\Order::Descending, 'id' => \Doctrine\Common\Collections\Order::Descending]);
return $this->getHouseholdParticipations()
->matching($criteria);

View File

@@ -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';
}

View File

@@ -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';
}

View File

@@ -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, '\\'),

View File

@@ -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();
}
}
}
}

View File

@@ -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);

View File

@@ -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,

View File

@@ -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,

View File

@@ -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;
}
}

View File

@@ -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()
),

View File

@@ -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()
),

View File

@@ -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;
}

View File

@@ -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);
}

View File

@@ -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}");
}

View File

@@ -35,9 +35,11 @@
<div class="warnings">
<div class="alert alert-danger">
<h2>{{ 'This course is closed'|trans }}</h2>
<p>
{{ 'Closing motive'|trans }} : {{ accompanyingCourse.closingMotive.name|localize_translatable_string }}
</p>
{% if accompanyingCourse.closingMotive is not same as null %}
<p>
{{ 'Closing motive'|trans }} : {{ accompanyingCourse.closingMotive.name|localize_translatable_string }}
</p>
{% endif %}
</div>
</div>
</div>

View File

@@ -226,7 +226,7 @@ class AccompanyingPeriodContext implements
}
}
if ($options['thirdParty']) {
if ($options['thirdParty'] ?? false) {
$data['thirdParty'] = $this->normalizer->normalize($contextGenerationData['thirdParty'], 'docgen', [
'docgen:expects' => ThirdParty::class,
'groups' => 'docgen:read',

View File

@@ -11,7 +11,6 @@ declare(strict_types=1);
namespace Chill\PersonBundle\Tests\Export\Export;
use Chill\MainBundle\Export\Helper\ExportAddressHelper;
use Chill\MainBundle\Service\RollingDate\RollingDate;
use Chill\MainBundle\Service\RollingDate\RollingDateConverterInterface;
use Chill\MainBundle\Test\Export\AbstractExportTest;
@@ -35,13 +34,11 @@ class ListPersonHavingAccompanyingPeriodTest extends AbstractExportTest
public function getExport()
{
$addressHelper = self::getContainer()->get(ExportAddressHelper::class);
$listPersonHelper = self::getContainer()->get(ListPersonHelper::class);
$entityManager = self::getContainer()->get(EntityManagerInterface::class);
$rollingDateconverter = self::getContainer()->get(RollingDateConverterInterface::class);
yield new ListPersonHavingAccompanyingPeriod(
$addressHelper,
$listPersonHelper,
$entityManager,
$rollingDateconverter,
@@ -49,7 +46,6 @@ class ListPersonHavingAccompanyingPeriodTest extends AbstractExportTest
);
yield new ListPersonHavingAccompanyingPeriod(
$addressHelper,
$listPersonHelper,
$entityManager,
$rollingDateconverter,
@@ -59,7 +55,7 @@ class ListPersonHavingAccompanyingPeriodTest extends AbstractExportTest
public static function getFormData(): array
{
return [['address_date_rolling' => new RollingDate(RollingDate::T_TODAY), 'fields' => ListPersonHelper::FIELDS]];
return [['address_date_rolling' => new RollingDate(RollingDate::T_TODAY)]];
}
public static function getModifiersCombination(): array

View File

@@ -12,7 +12,6 @@ declare(strict_types=1);
namespace Chill\PersonBundle\Tests\Export\Export;
use Chill\CustomFieldsBundle\Service\CustomFieldProvider;
use Chill\MainBundle\Export\Helper\ExportAddressHelper;
use Chill\MainBundle\Templating\TranslatableStringHelper;
use Chill\MainBundle\Test\Export\AbstractExportTest;
use Chill\PersonBundle\Export\Export\ListPerson;
@@ -50,14 +49,12 @@ final class ListPersonTest extends AbstractExportTest
public function getExport()
{
$addressHelper = self::getContainer()->get(ExportAddressHelper::class);
$customFieldProvider = self::getContainer()->get(CustomFieldProvider::class);
$listPersonHelper = self::getContainer()->get(ListPersonHelper::class);
$entityManager = self::getContainer()->get(EntityManagerInterface::class);
$translatableStringHelper = self::getContainer()->get(TranslatableStringHelper::class);
yield new ListPerson(
$addressHelper,
$customFieldProvider,
$listPersonHelper,
$entityManager,
@@ -66,7 +63,6 @@ final class ListPersonTest extends AbstractExportTest
);
yield new ListPerson(
$addressHelper,
$customFieldProvider,
$listPersonHelper,
$entityManager,
@@ -77,18 +73,7 @@ final class ListPersonTest extends AbstractExportTest
public static function getFormData(): array
{
$data = [];
foreach ([
['fields' => ['id', 'firstName', 'lastName']],
['fields' => ['id', 'birthdate', 'gender', 'memo', 'email', 'phonenumber']],
['fields' => ['firstName', 'lastName', 'phonenumber']],
['fields' => ['id', 'nationality']],
['fields' => ['id', 'countryOfBirth']],
] as $base) {
$data[] = [...$base, 'address_date' => new \DateTimeImmutable('today')];
}
return $data;
yield ['address_date' => new \DateTimeImmutable('today')];
}
public static function getModifiersCombination(): array

View File

@@ -0,0 +1,63 @@
<?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 Export\Filter\SocialWorkFilters;
use Chill\MainBundle\Service\RollingDate\RollingDate;
use Chill\MainBundle\Test\Export\AbstractFilterTest;
use Chill\PersonBundle\Entity\AccompanyingPeriod\AccompanyingPeriodWork;
use Chill\PersonBundle\Export\Filter\SocialWorkFilters\AccompanyingPeriodWorkWithEvaluationBetweenDatesFilter;
use Doctrine\ORM\EntityManagerInterface;
/**
* @internal
*
* @coversNothing
*/
final class WithEvaluationBetweenDatesFilterTest extends AbstractFilterTest
{
private AccompanyingPeriodWorkWithEvaluationBetweenDatesFilter $filter;
protected function setUp(): void
{
self::bootKernel();
$this->filter = self::$container->get(AccompanyingPeriodWorkWithEvaluationBetweenDatesFilter::class);
}
public function getFilter()
{
return $this->filter;
}
public function getFormData()
{
return [
[
'start_date' => new RollingDate(RollingDate::T_MONTH_CURRENT_START),
'end_date' => new RollingDate(RollingDate::T_TODAY),
],
];
}
public function getQueryBuilders()
{
self::bootKernel();
$em = self::$container->get(EntityManagerInterface::class);
return [
$em->createQueryBuilder()
->select('acpw.id')
->from(AccompanyingPeriodWork::class, 'acpw'),
];
}
}

View File

@@ -529,7 +529,7 @@ class AccompanyingPeriodACLAwareRepositoryTest extends KernelTestCase
/**
* @param array<Scope> $scopes
*/
private static function buildPeriod(Person $person, array $scopes, User|null $creator, bool $confirm): AccompanyingPeriod
private static function buildPeriod(Person $person, array $scopes, ?User $creator, bool $confirm): AccompanyingPeriod
{
$entityManager = self::getContainer()->get(EntityManagerInterface::class);
$registry = self::getContainer()->get(Registry::class);

View File

@@ -16,6 +16,10 @@ services:
tags:
- { name: chill.export, alias: list_person }
Chill\PersonBundle\Export\Helper\ListPersonHelper:
arguments:
$customPersonHelpers: !tagged_iterator chill_person.list_person_customizer
Chill\PersonBundle\Export\Export\ListPersonHavingAccompanyingPeriod:
tags:
- { name: chill.export, alias: list_person_with_acp }

View File

@@ -79,6 +79,10 @@ services:
tags:
- { name: chill.export_filter, alias: social_work_actions_creator_scope_filter }
Chill\PersonBundle\Export\Filter\SocialWorkFilters\AccompanyingPeriodWorkWithEvaluationBetweenDatesFilter:
tags:
- { name: chill.export_filter, alias: social_work_actions_evaluation_btw_dates_filter }
## AGGREGATORS
chill.person.export.aggregator_action_type:

View File

@@ -57,7 +57,7 @@ Add new phone: Ajouter un numéro de téléphone
Remove phone: Supprimer
'Notes on contact information': 'Remarques sur les informations de contact'
'Remarks': 'Remarques'
Spoken languages': 'Langues parlées'
Spoken languages: 'Langues parlées'
'Unknown spoken languages': 'Langues parlées inconnues'
Male: Homme
Female: Femme
@@ -1291,6 +1291,11 @@ export:
by_creator_scope:
title: Filtrer les actions par service du créateur
"Filtered by creator scope: only %scopes%": "Filtré par service du créateur: uniquement %scopes%"
evaluation_between_dates:
title: Filtrer les actions associées à une évaluation créée entre deux dates
description: Uniquement les actions associées à une évaluation créée entre le %startDate% et le %endDate%
start_date: Date de début
end_date: Date de fin
list:
person_with_acp:
@@ -1341,6 +1346,8 @@ export:
requestorThirdParty: Demandeur (tiers)
acpParticipantPersons: Usagers concernés
acpParticipantPersonsIds: Usagers concernés (identifiants)
duration: Durée du parcours (en jours)
centers: Centres des usagers
eval:
List of evaluations: Liste des évaluations