Fix filtres and scopes to take into account job and scope when the refferrer is add to the accompanying period work

This commit is contained in:
Julien Fastré 2023-10-16 10:58:41 +02:00
parent 63e9d1a96f
commit 68d28f3e28
Signed by: julienfastre
GPG Key ID: BDE2190974723FCB
24 changed files with 352 additions and 173 deletions

View File

@ -57,7 +57,7 @@ class ListActivityHelper
->addSelect('AGGREGATE(actPerson.id) AS personsNames')
->leftJoin('activity.users', 'users_u')
->addSelect('AGGREGATE(users_u.id) AS usersIds')
->addSelect('AGGREGATE(users_u.id) AS usersNames')
->addSelect('AGGREGATE(JSON_BUILD_OBJECT(\'uid\', users_u.id, \'d\', activity.date)) AS usersNames')
->leftJoin('activity.thirdParties', 'thirdparty')
->addSelect('AGGREGATE(thirdparty.id) AS thirdPartiesIds')
->addSelect('AGGREGATE(thirdparty.id) AS thirdPartiesNames')
@ -68,9 +68,9 @@ class ListActivityHelper
->leftJoin('activity.location', 'location')
->addSelect('location.name AS locationName')
->addSelect('activity.sentReceived')
->addSelect('IDENTITY(activity.createdBy) AS createdBy')
->addSelect('JSON_BUILD_OBJECT(\'uid\', IDENTITY(activity.createdBy), \'d\', activity.createdAt) AS createdBy')
->addSelect('activity.createdAt')
->addSelect('IDENTITY(activity.updatedBy) AS updatedBy')
->addSelect('JSON_BUILD_OBJECT(\'uid\', IDENTITY(activity.updatedBy), \'d\', activity.updatedAt) AS updatedBy')
->addSelect('activity.updatedAt')
->addGroupBy('activity.id')
->addGroupBy('location.id');

View File

@ -395,6 +395,9 @@ export:
by_creator_scope:
Group activity by creator scope: Grouper les échanges par service du créateur de l'échange
Calc date: Date de calcul du service du créateur de l'échange
by_creator_job:
Group activity by creator job: Grouper les échanges par service du créateur de l'échange
Calc date: Date de calcul du service du créateur de l'échange
generic_doc:
filter:

View File

@ -182,7 +182,10 @@ final readonly class ListAsideActivity implements ListInterface, GroupedExportIn
{
$qb = $this->em->createQueryBuilder()
->from(AsideActivity::class, 'aside')
->leftJoin('aside.agent', 'agent');
->leftJoin('aside.agent', 'agent')
->leftJoin('agent.scopeHistories', 'scopeHistories')
->andWhere('scopeHistories.startDate <= aside.date AND (scopeHistories.endDate IS NULL or scopeHistories.endDate > aside.date)')
;
$qb
->addSelect('aside.id AS id')
@ -190,7 +193,7 @@ final readonly class ListAsideActivity implements ListInterface, GroupedExportIn
->addSelect('aside.updatedAt AS updatedAt')
->addSelect('IDENTITY(aside.agent) AS agent_id')
->addSelect('IDENTITY(aside.createdBy) AS creator_id')
->addSelect('IDENTITY(agent.mainScope) AS main_scope') ///
->addSelect('IDENTITY(scopeHistories.scope) AS main_scope')
->addSelect('IDENTITY(agent.mainCenter) AS main_center')
->addSelect('IDENTITY(aside.type) AS aside_activity_type')
->addSelect('aside.date')

View File

@ -0,0 +1,43 @@
<?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\AsideActivityBundle\Tests\Export\Export;
use Chill\AsideActivityBundle\Export\Export\ListAsideActivity;
use Chill\MainBundle\Test\Export\AbstractExportTest;
use Doctrine\ORM\AbstractQuery;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
/**
* @internal
* @coversNothing
*/
class ListAsideActivityTest extends KernelTestCase
{
private ListAsideActivity $listAsideActivity;
protected function setUp(): void
{
parent::setUp();
self::bootKernel();
$this->listAsideActivity = self::$container->get(ListAsideActivity::class);
}
public function testExecuteQuery(): void
{
$qb = $this->listAsideActivity->initiateQuery([], [], [])
->setMaxResults(1);
$results = $qb->getQuery()->getResult(AbstractQuery::HYDRATE_ARRAY);
self::assertIsArray($results, "smoke test: test that the result is an array");
}
}

View File

@ -292,9 +292,7 @@ class User implements UserInterface, \Stringable
$sortedScopeHistories = $scopeHistories->toArray();
usort($sortedScopeHistories, function ($a, $b) {
return $a->getStartDate() < $b->getStartDate() ? 1 : -1;
});
usort($sortedScopeHistories, fn ($a, $b) => $a->getStartDate() < $b->getStartDate() ? 1 : -1);
return new ArrayCollection($sortedScopeHistories);
}
@ -346,9 +344,7 @@ class User implements UserInterface, \Stringable
$sortedJobHistories = $jobHistories->toArray();
usort($sortedJobHistories, function ($a, $b) {
return $a->getStartDate() < $b->getStartDate() ? 1 : -1;
});
usort($sortedJobHistories, fn ($a, $b) => $a->getStartDate() < $b->getStartDate() ? 1 : -1);
return new ArrayCollection($sortedJobHistories);
}

View File

@ -281,9 +281,9 @@ class ExportAddressHelper
};
case 'country':
return function ($value) use ($key) {
return function ($value) use ($sanitizedKey, $translationPrefix) {
if ('_header' === $value) {
return 'export.list.acp' . $key;
return $translationPrefix . $sanitizedKey;
}
if (null === $value) {

View File

@ -20,21 +20,64 @@ class UserHelper
{
public function __construct(private readonly UserRender $userRender, private readonly UserRepositoryInterface $userRepository) {}
/**
* Return a callable that will transform a value into a string representing a user
*
* The callable may receive as argument:
*
* - an int or a string, the id of the user;
* - a string containing a json which will be decoded, and will have this structure: array{uid: int, d: string}. The job and scopes will be shown at this date
*
* @param string $key the key of the content
* @param array $values the list of values
* @param string $header the header's content
*/
public function getLabel($key, array $values, string $header): callable
{
return function ($value) use ($header) {
return function (null|int|string $value) use ($header) {
if ('_header' === $value) {
return $header;
}
if (null === $value || null === $user = $this->userRepository->find($value)) {
if (null === $value) {
return '';
}
return $this->userRender->renderString($user, []);
if (is_numeric($value)) {
$uid = $value;
$date = null;
} else {
$decode = json_decode($value, true, 512, JSON_THROW_ON_ERROR);
$uid = $decode['uid'];
if (null === $uid) {
return '';
}
$date = new \DateTimeImmutable($decode['d']);
}
if (null === $user = $this->userRepository->find($uid)) {
return '';
}
return $this->userRender->renderString($user, ['at' => $date]);
};
}
/**
* Return a callable that will transform a value into a string representing a user
*
* The callable may receive as argument:
*
* - an int or a string, the id of the user;
* - a string containing a json which will be decoded, and will have this structure: array{uid: int, d: string}. The job and scopes will be shown at this date * @param $key
*
* @param string $key the key of the element
* @param array $values a list of values
* @param string $header the header's content
* @return callable
*/
public function getLabelMulti($key, array $values, string $header): callable
{
return function ($value) use ($header) {
@ -46,31 +89,36 @@ class UserHelper
return '';
}
$decoded = json_decode((string) $value, null, 512, JSON_THROW_ON_ERROR);
$decoded = json_decode((string) $value, true, 512, JSON_THROW_ON_ERROR);
if (0 === count($decoded)) {
return '';
}
$asStrings = [];
return
implode(
'|',
array_map(
function (int $userId) {
$user = $this->userRepository->find($userId);
foreach ($decoded as $userId) {
if (is_array($userId)) {
$uid = $userId['uid'];
$date = new \DateTimeImmutable($userId['d']);
} else {
$uid = $userId;
$date = null;
}
if (null === $user) {
return '';
}
if (null === $uid) {
continue;
}
return $this->userRender->renderString($user, []);
},
array_unique(
array_filter($decoded, static fn (?int $userId) => null !== $userId),
SORT_NUMERIC
)
)
);
$user = $this->userRepository->find($uid);
if (null === $user) {
continue;
}
$asStrings[$uid] = $this->userRender->renderString($user, ['absence' => false, 'at' => $date]);
}
return implode('|', $asStrings);
};
}
}

View File

@ -1,10 +1,10 @@
<span class="chill-entity entity-user">
{{- user.label }}
{%- if opts['user_job'] and user.userJob is not null %}
<span class="user-job">({{ user.userJob.label|localize_translatable_string }})</span>
{%- if opts['user_job'] and user.userJob(opts['at']) is not null %}
<span class="user-job">({{ user.userJob(opts['at']).label|localize_translatable_string }})</span>
{%- endif -%}
{%- if opts['main_scope'] and user.mainScope is not null %}
<span class="main-scope">({{ user.mainScope.name|localize_translatable_string }})</span>
{%- if opts['main_scope'] and user.mainScope(opts['at']) is not null %}
<span class="main-scope">({{ user.mainScope(opts['at']).name|localize_translatable_string }})</span>
{%- endif -%}
{%- if opts['absence'] and user.isAbsent %}
<span class="badge bg-danger rounded-pill" title="{{ 'absence.Absent'|trans|escape('html_attr') }}">{{ 'absence.A'|trans }}</span>

View File

@ -28,10 +28,14 @@ class UserRender implements ChillEntityRenderInterface
'main_scope' => true,
'user_job' => true,
'absence' => true,
'at' => null,
];
public function __construct(private readonly TranslatableStringHelper $translatableStringHelper, private readonly \Twig\Environment $engine, private readonly TranslatorInterface $translator) {}
/**
* @param mixed $entity
*/
public function renderBox($entity, array $options): string
{
$opts = array_merge(self::DEFAULT_OPTIONS, $options);
@ -42,20 +46,23 @@ class UserRender implements ChillEntityRenderInterface
]);
}
/**
* @param mixed $entity
*/
public function renderString($entity, array $options): string
{
$opts = array_merge(self::DEFAULT_OPTIONS, $options);
$str = $entity->getLabel();
if (null !== $entity->getUserJob() && $opts['user_job']) {
if (null !== $entity->getUserJob($opts['at']) && $opts['user_job']) {
$str .= ' (' . $this->translatableStringHelper
->localize($entity->getUserJob()->getLabel()) . ')';
->localize($entity->getUserJob($opts['at'])->getLabel()) . ')';
}
if (null !== $entity->getMainScope() && $opts['main_scope']) {
if (null !== $entity->getMainScope($opts['at']) && $opts['main_scope']) {
$str .= ' (' . $this->translatableStringHelper
->localize($entity->getMainScope()->getName()) . ')';
->localize($entity->getMainScope($opts['at'])->getName()) . ')';
}
if ($entity->isAbsent() && $opts['absence']) {

View File

@ -11,13 +11,16 @@ declare(strict_types=1);
namespace Chill\PersonBundle\Export\Aggregator\SocialWorkAggregators;
use Chill\MainBundle\Entity\Scope;
use Chill\MainBundle\Entity\User\UserJobHistory;
use Chill\MainBundle\Entity\UserJob;
use Chill\MainBundle\Export\AggregatorInterface;
use Chill\MainBundle\Form\Type\PickRollingDateType;
use Chill\MainBundle\Repository\UserJobRepository;
use Chill\MainBundle\Service\RollingDate\RollingDate;
use Chill\MainBundle\Service\RollingDate\RollingDateConverter;
use Chill\MainBundle\Templating\TranslatableStringHelper;
use Chill\PersonBundle\Entity\AccompanyingPeriod\AccompanyingPeriodWorkReferrerHistory;
use Chill\PersonBundle\Export\Declarations;
use Doctrine\ORM\Query\Expr;
use Doctrine\ORM\QueryBuilder;
@ -29,7 +32,6 @@ final readonly class JobAggregator implements AggregatorInterface
private const PREFIX = 'acp_work_action_agg_user_job';
public function __construct(
private RollingDateConverter $rollingDateConverter,
private UserJobRepository $jobRepository,
private TranslatableStringHelper $translatableStringHelper
) {}
@ -44,27 +46,16 @@ final readonly class JobAggregator implements AggregatorInterface
$p = self::PREFIX;
$qb
->leftJoin("acpw.referrers", "{$p}_user")
->leftJoin(
UserJobHistory::class,
"{$p}_history",
UserJob::class,
"{$p}_job",
Expr\Join::WITH,
$qb->expr()->eq("{$p}_history.user", "{$p}_user")
)
->andWhere(
$qb->expr()->andX(
$qb->expr()->lte("{$p}_history.startDate", ":{$p}_at"),
$qb->expr()->orX(
$qb->expr()->isNull("{$p}_history.endDate"),
$qb->expr()->gt("{$p}_history.endDate", ":{$p}_at")
)
)
)
->addSelect("IDENTITY({$p}_history.job) as {$p}_select")
->setParameter(
"{$p}_at",
$this->rollingDateConverter->convert($data['job_at'])
'EXISTS (SELECT 1 FROM ' . AccompanyingPeriodWorkReferrerHistory::class . " {$p}_ref_history
JOIN {$p}_ref_history.user {$p}_ref_history_user JOIN {$p}_ref_history_user.jobHistories {$p}_job_history
WHERE {$p}_ref_history.accompanyingPeriodWork = acpw AND IDENTITY({$p}_job_history.job) = {$p}_job.id AND {$p}_job_history.startDate <= {$p}_ref_history.startDate
AND ({$p}_job_history.endDate IS NULL or {$p}_job_history.endDate >= {$p}_ref_history.startDate))"
)
->addSelect("{$p}_job.id as {$p}_select")
->addGroupBy("{$p}_select");
}
@ -73,17 +64,11 @@ final readonly class JobAggregator implements AggregatorInterface
return Declarations::SOCIAL_WORK_ACTION_TYPE;
}
public function buildForm(FormBuilderInterface $builder)
{
$builder->add('job_at', PickRollingDateType::class, [
'label' => 'export.aggregator.course_work.by_agent_job.Calc date',
'required' => true
]);
}
public function buildForm(FormBuilderInterface $builder) {}
public function getFormDefaultData(): array
{
return ['job_at' => new RollingDate(RollingDate::T_TODAY)];
return [];
}
public function getLabels($key, array $values, $data)

View File

@ -65,7 +65,7 @@ final readonly class ReferrerAggregator implements AggregatorInterface
$r = $this->userRepository->find($value);
return $this->userRender->renderString($r, []);
return $this->userRender->renderString($r, ['absence' => false, 'user_job' => false, 'main_scope' => false]);
};
}

View File

@ -11,13 +11,16 @@ declare(strict_types=1);
namespace Chill\PersonBundle\Export\Aggregator\SocialWorkAggregators;
use Chill\MainBundle\Entity\Scope;
use Chill\MainBundle\Entity\User\UserScopeHistory;
use Chill\MainBundle\Entity\UserJob;
use Chill\MainBundle\Export\AggregatorInterface;
use Chill\MainBundle\Form\Type\PickRollingDateType;
use Chill\MainBundle\Repository\ScopeRepository;
use Chill\MainBundle\Service\RollingDate\RollingDate;
use Chill\MainBundle\Service\RollingDate\RollingDateConverter;
use Chill\MainBundle\Templating\TranslatableStringHelper;
use Chill\PersonBundle\Entity\AccompanyingPeriod\AccompanyingPeriodWorkReferrerHistory;
use Chill\PersonBundle\Export\Declarations;
use Doctrine\ORM\Query\Expr;
use Doctrine\ORM\QueryBuilder;
@ -29,7 +32,6 @@ final readonly class ScopeAggregator implements AggregatorInterface
private const PREFIX = 'acp_work_action_agg_user_scope';
public function __construct(
private RollingDateConverter $rollingDateConverter,
private ScopeRepository $scopeRepository,
private TranslatableStringHelper $translatableStringHelper
) {}
@ -44,27 +46,16 @@ final readonly class ScopeAggregator implements AggregatorInterface
$p = self::PREFIX;
$qb
->leftJoin("acpw.referrers", "{$p}_user")
->leftJoin(
UserScopeHistory::class,
"{$p}_history",
Scope::class,
"{$p}_scope",
Expr\Join::WITH,
$qb->expr()->eq("{$p}_history.user", "{$p}_user")
)
->andWhere(
$qb->expr()->andX(
$qb->expr()->lte("{$p}_history.startDate", ":{$p}_at"),
$qb->expr()->orX(
$qb->expr()->isNull("{$p}_history.endDate"),
$qb->expr()->gt("{$p}_history.endDate", ":{$p}_at")
)
)
)
->addSelect("IDENTITY({$p}_history.scope) as {$p}_select")
->setParameter(
"{$p}_at",
$this->rollingDateConverter->convert($data['scope_at'])
'EXISTS (SELECT 1 FROM ' . AccompanyingPeriodWorkReferrerHistory::class . " {$p}_ref_history
JOIN {$p}_ref_history.user {$p}_ref_history_user JOIN {$p}_ref_history_user.scopeHistories {$p}_scope_history
WHERE {$p}_ref_history.accompanyingPeriodWork = acpw AND IDENTITY({$p}_scope_history.scope) = {$p}_scope.id AND {$p}_scope_history.startDate <= {$p}_ref_history.startDate
AND ({$p}_scope_history.endDate IS NULL or {$p}_scope_history.endDate >= {$p}_ref_history.startDate))"
)
->addSelect("{$p}_scope.id as {$p}_select")
->addGroupBy("{$p}_select");
}
@ -73,17 +64,11 @@ final readonly class ScopeAggregator implements AggregatorInterface
return Declarations::SOCIAL_WORK_ACTION_TYPE;
}
public function buildForm(FormBuilderInterface $builder)
{
$builder->add('scope_at', PickRollingDateType::class, [
'label' => 'export.aggregator.course_work.by_agent_scope.Calc date',
'required' => true,
]);
}
public function buildForm(FormBuilderInterface $builder) {}
public function getFormDefaultData(): array
{
return ['scope_at' => new RollingDate(RollingDate::T_TODAY)];
return [];
}
public function getLabels($key, array $values, $data)

View File

@ -132,7 +132,7 @@ class ListEvaluation implements ListInterface, GroupedExportInterface
);
},
'createdBy', 'updatedBy', 'acpw_acp_user' => $this->userHelper->getLabel($key, $values, 'export.list.eval.' . $key),
'acpw_referrers' => $this->userHelper->getLabel($key, $values, 'export.list.eval.' . $key),
'acpw_referrers' => $this->userHelper->getLabelMulti($key, $values, 'export.list.eval.' . $key),
'acpw_persons_id' => $this->aggregateStringHelper->getLabelMulti($key, $values, 'export.list.eval.' . $key),
'acpw_persons' => $this->personHelper->getLabelMulti($key, $values, 'export.list.eval.' . $key),
'eval_title' => $this->translatableStringExportLabelHelper
@ -252,8 +252,8 @@ class ListEvaluation implements ListInterface, GroupedExportInterface
// referrers => at date XXXX
$qb
->addSelect('(SELECT IDENTITY(history.user) FROM ' . UserHistory::class . ' history ' .
'WHERE history.accompanyingPeriod = acp AND history.startDate <= :calc_date AND (history.endDate IS NULL OR history.endDate > :calc_date)) AS acpw_referrers');
->addSelect('(SELECT JSON_BUILD_OBJECT(\'uid\', IDENTITY(history.user), \'d\', history.startDate) FROM ' . UserHistory::class . ' history ' .
'WHERE history.accompanyingPeriod = acp AND history.startDate <= :calc_date AND (history.endDate IS NULL OR history.endDate > :calc_date)) AS referrers');
// persons
$qb

View File

@ -18,6 +18,7 @@ use Chill\MainBundle\Form\Type\PickRollingDateType;
use Chill\MainBundle\Service\RollingDate\RollingDate;
use Chill\MainBundle\Service\RollingDate\RollingDateConverter;
use Chill\MainBundle\Templating\TranslatableStringHelper;
use Chill\PersonBundle\Entity\AccompanyingPeriod\AccompanyingPeriodWorkReferrerHistory;
use Chill\PersonBundle\Export\Declarations;
use Doctrine\ORM\Query\Expr;
use Doctrine\ORM\Query\Expr\Andx;
@ -32,7 +33,6 @@ class JobFilter implements FilterInterface
private const PREFIX = 'acp_work_action_filter_user_job';
public function __construct(
private readonly RollingDateConverter $rollingDateConverter,
protected TranslatorInterface $translator,
private readonly TranslatableStringHelper $translatableStringHelper
) {}
@ -46,30 +46,14 @@ class JobFilter implements FilterInterface
{
$p = self::PREFIX;
$qb
->leftJoin("acpw.referrers", "{$p}_user")
->leftJoin(
UserJobHistory::class,
"{$p}_history",
Expr\Join::WITH,
$qb->expr()->eq("{$p}_history.user", "{$p}_user")
)
->andWhere(
$qb->expr()->andX(
$qb->expr()->lte("{$p}_history.startDate", ":{$p}_at"),
$qb->expr()->orX(
$qb->expr()->isNull("{$p}_history.endDate"),
$qb->expr()->gt("{$p}_history.endDate", ":{$p}_at")
)
)
)
->andWhere(
$qb->expr()->in("{$p}_history.job", ":{$p}_job")
)
->setParameters([
"{$p}_job" => $data["job"],
"{$p}_at" => $this->rollingDateConverter->convert($data['job_at'])
]);
$qb->andWhere(
'EXISTS (SELECT 1 FROM ' . AccompanyingPeriodWorkReferrerHistory::class . " {$p}_ref_history
JOIN {$p}_ref_history.user {$p}_ref_history_user JOIN {$p}_ref_history_user.jobHistories {$p}_job_history
WHERE {$p}_ref_history.accompanyingPeriodWork = acpw AND {$p}_job_history.job IN (:{$p}_job) AND {$p}_job_history.startDate <= {$p}_ref_history.startDate
AND ({$p}_job_history.endDate IS NULL or {$p}_job_history.endDate >= {$p}_ref_history.startDate))"
);
$qb->setParameter("{$p}_job", $data["job"]);
}
public function applyOn(): string
@ -88,10 +72,6 @@ class JobFilter implements FilterInterface
'multiple' => true,
'expanded' => true,
])
->add('job_at', PickRollingDateType::class, [
'label' => 'export.filter.work.by_user_job.Calc date',
'required' => true,
])
;
}

View File

@ -18,6 +18,7 @@ use Chill\MainBundle\Form\Type\PickRollingDateType;
use Chill\MainBundle\Service\RollingDate\RollingDate;
use Chill\MainBundle\Service\RollingDate\RollingDateConverter;
use Chill\MainBundle\Templating\TranslatableStringHelper;
use Chill\PersonBundle\Entity\AccompanyingPeriod\AccompanyingPeriodWorkReferrerHistory;
use Chill\PersonBundle\Export\Declarations;
use Doctrine\ORM\Query\Expr;
use Doctrine\ORM\QueryBuilder;
@ -30,7 +31,6 @@ class ScopeFilter implements FilterInterface
private const PREFIX = 'acp_work_action_filter_user_scope';
public function __construct(
private readonly RollingDateConverter $rollingDateConverter,
protected TranslatorInterface $translator,
private readonly TranslatableStringHelper $translatableStringHelper
) {}
@ -44,30 +44,13 @@ class ScopeFilter implements FilterInterface
{
$p = self::PREFIX;
$qb
->leftJoin("acpw.referrers", "{$p}_user")
->leftJoin(
UserScopeHistory::class,
"{$p}_history",
Expr\Join::WITH,
$qb->expr()->eq("{$p}_history.user", "{$p}_user")
)
->andWhere(
$qb->expr()->andX(
$qb->expr()->lte("{$p}_history.startDate", ":{$p}_at"),
$qb->expr()->orX(
$qb->expr()->isNull("{$p}_history.endDate"),
$qb->expr()->gt("{$p}_history.endDate", ":{$p}_at")
)
)
)
->andWhere(
$qb->expr()->in("{$p}_history.scope", ":{$p}_scope")
)
->setParameters([
"{$p}_scope" => $data["scope"],
"{$p}_at" => $this->rollingDateConverter->convert($data['scope_at'])
]);
$qb->andWhere(
'EXISTS (SELECT 1 FROM ' . AccompanyingPeriodWorkReferrerHistory::class . " {$p}_ref_history
JOIN {$p}_ref_history.user {$p}_ref_history_user JOIN {$p}_ref_history_user.scopeHistories {$p}_scope_history
WHERE {$p}_ref_history.accompanyingPeriodWork = acpw AND {$p}_scope_history.scope IN (:{$p}_scope) AND {$p}_scope_history.startDate <= {$p}_ref_history.startDate
AND ({$p}_scope_history.endDate IS NULL or {$p}_scope_history.endDate >= {$p}_ref_history.startDate))"
)
->setParameter("{$p}_scope", $data["scope"]);
}
public function applyOn()
@ -86,10 +69,6 @@ class ScopeFilter implements FilterInterface
'multiple' => true,
'expanded' => true,
])
->add('scope_at', PickRollingDateType::class, [
'label' => 'export.filter.work.by_user_scope.Calc date',
'required' => true,
])
;
}

View File

@ -15,6 +15,7 @@ use Chill\MainBundle\Entity\Address;
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\Templating\TranslatableStringHelperInterface;
use Chill\PersonBundle\Entity\AccompanyingPeriod;
use Chill\PersonBundle\Entity\Household\PersonHouseholdAddress;
@ -59,8 +60,10 @@ final readonly class ListAccompanyingPeriodHelper
'scopes',
'socialIssues',
'acpCreatedAt',
'acpCreatedBy_id',
'acpCreatedBy',
'acpUpdatedAt',
'acpUpdatedBy_id',
'acpUpdatedBy',
];
@ -75,6 +78,7 @@ final readonly class ListAccompanyingPeriodHelper
private SocialIssueRender $socialIssueRender,
private TranslatableStringHelperInterface $translatableStringHelper,
private TranslatorInterface $translator,
private UserHelper $userHelper,
) {}
public function getQueryKeys($data)
@ -104,6 +108,7 @@ final readonly class ListAccompanyingPeriodHelper
return $this->translatableStringHelper->localize(json_decode((string) $value, true, 512, JSON_THROW_ON_ERROR));
},
'acpCreatedBy', 'acpUpdatedBy', 'referrer' => $this->userHelper->getLabel($key, $values, 'export.list.acp.' . $key),
'locationPersonName', 'requestorPerson' => function ($value) use ($key) {
if ('_header' === $value) {
return 'export.list.acp.' . $key;
@ -204,11 +209,11 @@ final readonly class ListAccompanyingPeriodHelper
// add the field which are simple association
$qb
->leftJoin('acp.createdBy', "acp_created_by_t")
->addSelect('acp_created_by_t.label AS acpCreatedBy');
->addSelect('IDENTITY(acp.createdBy) AS acpCreatedBy_id')
->addSelect('JSON_BUILD_OBJECT(\'uid\', IDENTITY(acp.createdBy), \'d\', acp.createdAt) AS acpCreatedBy');
$qb
->leftJoin('acp.updatedBy', "acp_updated_by_t")
->addSelect('acp_updated_by_t.label AS acpUpdatedBy');
->addSelect('IDENTITY(acp.updatedBy) AS acpUpdatedBy_id')
->addSelect('JSON_BUILD_OBJECT(\'uid\', IDENTITY(acp.updatedBy), \'d\', acp.updatedAt) AS acpUpdatedBy');
foreach (['origin' => 'label', 'closingMotive' => 'name', 'job' => 'label', 'administrativeLocation' => 'name'] as $entity => $field) {
$qb
@ -230,7 +235,7 @@ final readonly class ListAccompanyingPeriodHelper
// referree at date
$qb
->addSelect('referrer_t.label AS referrer')
->addSelect('JSON_BUILD_OBJECT(\'uid\', IDENTITY(userHistory.user), \'d\', userHistory.startDate) AS referrer')
->addSelect('userHistory.startDate AS referrerSince')
->leftJoin('acp.userHistories', 'userHistory')
->leftJoin('userHistory.user', 'referrer_t')

View File

@ -40,9 +40,7 @@ final class JobAggregatorTest extends AbstractAggregatorTest
public function getFormData(): array
{
return [
[
'job_at' => new RollingDate(RollingDate::T_FIXED_DATE, \DateTimeImmutable::createFromFormat('Y-m-d', '2020-01-01')),
],
[],
];
}
@ -57,7 +55,6 @@ final class JobAggregatorTest extends AbstractAggregatorTest
->select('count(acp.id)')
->from(AccompanyingPeriod::class, 'acp')
->join('acp.works', 'acpw')
->join('acpw.referrers', 'acpwuser'),
];
}
}

View File

@ -40,9 +40,7 @@ final class ScopeAggregatorTest extends AbstractAggregatorTest
public function getFormData(): array
{
return [
[
'scope_at' => new RollingDate(RollingDate::T_FIXED_DATE, \DateTimeImmutable::createFromFormat('Y-m-d', '2020-01-01')),
],
[],
];
}
@ -57,7 +55,6 @@ final class ScopeAggregatorTest extends AbstractAggregatorTest
->select('count(acp.id)')
->from(AccompanyingPeriod::class, 'acp')
->join('acp.works', 'acpw')
->join('acpw.referrers', 'acpwuser'),
];
}
}

View File

@ -0,0 +1,53 @@
<?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\Tests\Export\Export;
use Chill\MainBundle\Entity\Center;
use Chill\MainBundle\Export\Formatter\SpreadsheetListFormatter;
use Chill\MainBundle\Repository\CenterRepositoryInterface;
use Chill\MainBundle\Service\RollingDate\RollingDate;
use Chill\PersonBundle\Export\Export\ListAccompanyingPeriod;
use Doctrine\ORM\AbstractQuery;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
/**
* @internal
* @coversNothing
*/
class ListAccompanyingPeriodTest extends KernelTestCase
{
private ListAccompanyingPeriod $listAccompanyingPeriod;
private CenterRepositoryInterface $centerRepository;
protected function setUp(): void
{
parent::setUp();
self::bootKernel();
$this->listAccompanyingPeriod = self::$container->get(ListAccompanyingPeriod::class);
$this->centerRepository = self::$container->get(CenterRepositoryInterface::class);
}
public function testQuery(): void
{
$centers = $this->centerRepository->findAll();
$query = $this->listAccompanyingPeriod->initiateQuery([], array_map(fn (Center $c) => ['center' => $c ], $centers), $exportOpts = ['calc_date' => new RollingDate(RollingDate::T_TODAY)]);
$query->setMaxResults(1);
$actual = $query->getQuery()->getResult(AbstractQuery::HYDRATE_ARRAY);
self::assertIsArray($actual);
}
}

View File

@ -0,0 +1,49 @@
<?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\Tests\Export\Export;
use Chill\MainBundle\Entity\Center;
use Chill\MainBundle\Repository\CenterRepositoryInterface;
use Chill\MainBundle\Service\RollingDate\RollingDate;
use Chill\PersonBundle\Export\Export\ListAccompanyingPeriodWork;
use Doctrine\ORM\AbstractQuery;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
/**
* @internal
* @coversNothing
*/
class ListAccompanyingPeriodWorkTest extends KernelTestCase
{
private ListAccompanyingPeriodWork $listAccompanyingPeriodWork;
private CenterRepositoryInterface $centerRepository;
protected function setUp(): void
{
parent::setUp();
self::bootKernel();
$this->listAccompanyingPeriodWork = self::$container->get(ListAccompanyingPeriodWork::class);
$this->centerRepository = self::$container->get(CenterRepositoryInterface::class);
}
public function testQuery(): void
{
$centers = $this->centerRepository->findAll();
$query = $this->listAccompanyingPeriodWork->initiateQuery([], array_map(fn (Center $c) => ['center' => $c], $centers), ['calc_date' => new RollingDate(RollingDate::T_TODAY)]);
$query->setMaxResults(1);
self::assertIsArray($query->getQuery()->getResult(AbstractQuery::HYDRATE_ARRAY));
}
}

View File

@ -0,0 +1,49 @@
<?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\Tests\Export\Export;
use Chill\MainBundle\Entity\Center;
use Chill\MainBundle\Repository\CenterRepositoryInterface;
use Chill\MainBundle\Service\RollingDate\RollingDate;
use Chill\PersonBundle\Export\Export\ListEvaluation;
use Doctrine\ORM\AbstractQuery;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
/**
* @internal
* @coversNothing
*/
class ListEvaluationTest extends KernelTestCase
{
private ListEvaluation $listEvaluation;
private CenterRepositoryInterface $centerRepository;
protected function setUp(): void
{
parent::setUp();
self::bootKernel();
$this->listEvaluation = self::$container->get(ListEvaluation::class);
$this->centerRepository = self::$container->get(CenterRepositoryInterface::class);
}
public function testQuery(): void
{
$centers = $this->centerRepository->findAll();
$query = $this->listEvaluation->initiateQuery([], array_map(fn (Center $c) => ['center' => $c], $centers), ['calc_date' => new RollingDate(RollingDate::T_TODAY)]);
$query->setMaxResults(1);
self::assertIsArray($query->getQuery()->getResult(AbstractQuery::HYDRATE_ARRAY));
}
}

View File

@ -51,7 +51,6 @@ final class JobFilterTest extends AbstractFilterTest
return [
[
'job' => new ArrayCollection($jobs),
'job_at' => new RollingDate(RollingDate::T_FIXED_DATE, \DateTimeImmutable::createFromFormat('Y-m-d', '2020-01-01'))
]
];
}

View File

@ -50,7 +50,6 @@ final class ScopeFilterTest extends AbstractFilterTest
return [
[
'scope' => $scopes,
'scope_at' => new RollingDate(RollingDate::T_FIXED_DATE, \DateTimeImmutable::createFromFormat('Y-m-d', '2020-01-01'))
]
];
}

View File

@ -1187,7 +1187,9 @@ export:
origin: Origine du parcours
acpClosingMotive: Motif de fermeture
acpJob: Métier du parcours
acpCreatedBy_id: Créé par (identifiant)
acpCreatedBy: Créé par
acpUpdatedBy_id: Dernière modificaton par (identifiant)
acpUpdatedBy: Dernière modification par
administrativeLocation: Location administrative
step: Etape