Merge remote-tracking branch 'origin/master' into rector/rules-symfony

This commit is contained in:
2023-10-17 09:29:10 +02:00
17 changed files with 203 additions and 148 deletions

View File

@@ -33,9 +33,7 @@ use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
use Symfony\Component\Security\Core\Security;
use Symfony\Component\Templating\EngineInterface;
use Symfony\Component\Validator\Constraints\NotIdenticalTo;
use Symfony\Component\Validator\Constraints\NotNull;
use function is_int;
@@ -62,7 +60,7 @@ class ReassignAccompanyingPeriodController extends AbstractController
$total = $this->accompanyingPeriodACLAwareRepository->countByUserAndPostalCodesOpenedAccompanyingPeriod($userFrom, $postalCodes);
$paginator = $this->paginatorFactory->create($total);
$paginator->setItemsPerPage(50);
$paginator->setItemsPerPage(100);
$periods = $this->accompanyingPeriodACLAwareRepository
->findByUserAndPostalCodesOpenedAccompanyingPeriod(
$userFrom,
@@ -85,6 +83,7 @@ class ReassignAccompanyingPeriodController extends AbstractController
if ($assignForm->isSubmitted() && $assignForm->isValid()) {
$assignPeriodIds = json_decode((string) $assignForm->get('periods')->getData(), true, 512, JSON_THROW_ON_ERROR);
/** @var User $userTo */
$userTo = $assignForm->get('userTo')->getData();
$userFrom = $assignForm->get('userFrom')->getData();
@@ -93,6 +92,10 @@ class ReassignAccompanyingPeriodController extends AbstractController
if ($period->getUser() === $userFrom) {
$period->setUser($userTo, true);
if (null !== $userTo->getUserJob() && $period->getJob() !== $userTo->getUserJob()) {
$period->setJob($userTo->getUserJob());
}
}
}

View File

@@ -22,7 +22,10 @@ abstract class Declarations
final public const HOUSEHOLD_TYPE = 'household';
final public const PERSON_IMPLIED_IN = 'person_implied_in';
/**
* @deprecated consider using the PERSON_TYPE instead
*/
public const PERSON_IMPLIED_IN = 'person_implied_in';
final public const PERSON_TYPE = 'person';

View File

@@ -114,9 +114,7 @@ class CountPerson implements ExportInterface, GroupedExportInterface
public function supportsModifiers()
{
return [
'abcde',
//Declarations::PERSON_TYPE,
//Declarations::PERSON_IMPLIED_IN,
Declarations::PERSON_TYPE,
];
}
}

View File

@@ -250,7 +250,7 @@ class ListPerson implements ExportElementValidatedInterface, ListInterface, Grou
public function supportsModifiers()
{
return [Declarations::PERSON_TYPE, Declarations::PERSON_IMPLIED_IN];
return [Declarations::PERSON_TYPE];
}
public function validateForm($data, ExecutionContextInterface $context)

View File

@@ -194,7 +194,7 @@ class ListPersonHavingAccompanyingPeriod implements ExportElementValidatedInterf
public function supportsModifiers()
{
return [Declarations::PERSON_TYPE, Declarations::PERSON_IMPLIED_IN, Declarations::ACP_TYPE];
return [Declarations::PERSON_TYPE, Declarations::ACP_TYPE];
}
public function validateForm($data, ExecutionContextInterface $context)

View File

@@ -152,6 +152,6 @@ final readonly class ListPersonWithAccompanyingPeriodDetails implements ListInte
public function supportsModifiers()
{
return [Declarations::PERSON_TYPE, Declarations::PERSON_IMPLIED_IN, Declarations::ACP_TYPE];
return [Declarations::PERSON_TYPE, Declarations::ACP_TYPE];
}
}

View File

@@ -12,7 +12,7 @@ declare(strict_types=1);
namespace Chill\PersonBundle\Export\Filter\AccompanyingCourseFilters;
use Chill\MainBundle\Export\FilterInterface;
use Chill\MainBundle\Templating\TranslatableStringHelper;
use Chill\PersonBundle\Entity\AccompanyingPeriod;
use Chill\PersonBundle\Entity\SocialWork\SocialAction;
use Chill\PersonBundle\Export\Declarations;
use Chill\PersonBundle\Form\Type\PickSocialActionType;
@@ -21,9 +21,9 @@ use Doctrine\ORM\QueryBuilder;
use Symfony\Component\Form\FormBuilderInterface;
use function in_array;
class SocialActionFilter implements FilterInterface
final readonly class SocialActionFilter implements FilterInterface
{
public function __construct(private readonly TranslatableStringHelper $translatableStringHelper, private readonly SocialActionRender $actionRender) {}
public function __construct(private SocialActionRender $actionRender) {}
public function addRole(): ?string
{
@@ -32,21 +32,17 @@ class SocialActionFilter implements FilterInterface
public function alterQuery(QueryBuilder $qb, $data)
{
if (!in_array('acpw', $qb->getAllAliases(), true)) {
$qb->join('acp.works', 'acpw');
}
$qb->andWhere(
$qb->expr()->exists(
sprintf(
"SELECT 1 FROM %s acp_by_social_action_filter WHERE acp_by_social_action_filter.socialAction "
. "IN (:acp_by_social_action_filter_actions) AND acp_by_social_action_filter.accompanyingPeriod = acp",
AccompanyingPeriod\AccompanyingPeriodWork::class
)
)
);
if (!in_array('acpwsocialaction', $qb->getAllAliases(), true)) {
$qb->join('acpw.socialAction', 'acpwsocialaction');
}
$clause = $qb->expr()->in('acpwsocialaction.id', ':socialactions');
$qb->andWhere($clause)
->setParameter(
'socialactions',
SocialAction::getDescendantsWithThisForActions($data['accepted_socialactions'])->toArray()
);
$qb->setParameter('acp_by_social_action_filter_actions', SocialAction::getDescendantsWithThisForActions($data['accepted_socialactions']));
}
public function applyOn(): string

View File

@@ -26,9 +26,7 @@ use Symfony\Contracts\Translation\TranslatorInterface;
*/
class ClosingMotiveType extends AbstractType
{
public function __construct(private readonly TranslatorInterface $translator)
{
}
public function __construct(private readonly TranslatorInterface $translator) {}
public function buildForm(FormBuilderInterface $builder, array $options)
{

View File

@@ -0,0 +1,60 @@
<?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\Migrations\Person;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
final class Version20231002094521 extends AbstractMigration
{
public function getDescription(): string
{
return 'Remove doublons in chill_person_accompanying_period_location_history and add a constraint on startdate / endDate by period';
}
public function up(Schema $schema): void
{
$this->addSql(
<<<'SQL'
WITH doublons_ordered AS (
SELECT h2.id AS h2id, h2.createdAt AS h2createdAt, h2.startDate AS h2start, h2.endDate AS h2end, h1.*,
rank() OVER (partition by h1.period_id ORDER BY h1.id, h2.id) AS ranking
FROM chill_person_accompanying_period_location_history h1
JOIN chill_person_accompanying_period_location_history h2 ON h1.period_id = h2.period_id AND h1.id <> h2.id
WHERE daterange(h1.startdate, h1.enddate) && daterange(h2.startdate, h2.enddate) ORDER BY h1.period_id, h1.id
),
keep_only_first AS (
SELECT id FROM doublons_ordered WHERE ranking > 1
)
DELETE FROM chill_person_accompanying_period_location_history WHERE id IN (SELECT id FROM doublons_ordered);
SQL
);
$this->addSql(
<<<'SQL'
ALTER TABLE chill_person_accompanying_period_location_history
ADD CONSTRAINT acc_period_location_history_not_overlaps
EXCLUDE USING GIST (period_id with =, tsrange(startdate, enddate) with &&)
DEFERRABLE INITIALLY DEFERRED
SQL
);
}
public function down(Schema $schema): void
{
$this->addSql(
<<<'SQL'
ALTER TABLE chill_person_accompanying_period_location_history DROP CONSTRAINT acc_period_location_history_not_overlaps
SQL
);
}
}