Merge remote-tracking branch 'origin/master' into issue545_datepicker

This commit is contained in:
2022-04-25 09:37:35 +02:00
27 changed files with 307 additions and 86 deletions

View File

@@ -13,10 +13,10 @@ namespace Chill\PersonBundle\AccompanyingPeriod\Events;
use Chill\MainBundle\Entity\Address;
use Chill\MainBundle\Entity\Notification;
use Chill\MainBundle\Notification\NotificationPersisterInterface;
use Chill\PersonBundle\Entity\AccompanyingPeriod;
use Chill\PersonBundle\Event\Person\PersonAddressMoveEvent;
use DateTimeImmutable;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\Security\Core\Security;
use Symfony\Component\Templating\EngineInterface;
@@ -26,7 +26,7 @@ class PersonAddressMoveEventSubscriber implements EventSubscriberInterface
{
private EngineInterface $engine;
private EntityManagerInterface $entityManager;
private NotificationPersisterInterface $notificationPersister;
private Security $security;
@@ -34,12 +34,12 @@ class PersonAddressMoveEventSubscriber implements EventSubscriberInterface
public function __construct(
EngineInterface $engine,
EntityManagerInterface $entityManager,
NotificationPersisterInterface $notificationPersister,
Security $security,
TranslatorInterface $translator
) {
$this->engine = $engine;
$this->entityManager = $entityManager;
$this->notificationPersister = $notificationPersister;
$this->security = $security;
$this->translator = $translator;
}
@@ -87,7 +87,7 @@ class PersonAddressMoveEventSubscriber implements EventSubscriberInterface
'period' => $period,
]));
$this->entityManager->persist($notification);
$this->notificationPersister->persist($notification);
}
}
}

View File

@@ -13,8 +13,8 @@ namespace Chill\PersonBundle\AccompanyingPeriod\Events;
use Chill\MainBundle\Entity\Notification;
use Chill\MainBundle\Entity\User;
use Chill\MainBundle\Notification\NotificationPersisterInterface;
use Chill\PersonBundle\Entity\AccompanyingPeriod;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\Persistence\Event\LifecycleEventArgs;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\Security\Core\Security;
@@ -24,20 +24,20 @@ use Symfony\Contracts\Translation\TranslatorInterface;
class UserRefEventSubscriber implements EventSubscriberInterface
{
private EntityManagerInterface $em;
private EngineInterface $engine;
private NotificationPersisterInterface $notificationPersister;
private Security $security;
private TranslatorInterface $translator;
public function __construct(Security $security, TranslatorInterface $translator, EngineInterface $engine, EntityManagerInterface $em)
public function __construct(Security $security, TranslatorInterface $translator, EngineInterface $engine, NotificationPersisterInterface $notificationPersister)
{
$this->security = $security;
$this->translator = $translator;
$this->engine = $engine;
$this->em = $em;
$this->notificationPersister = $notificationPersister;
}
public static function getSubscribedEvents()
@@ -58,16 +58,13 @@ class UserRefEventSubscriber implements EventSubscriberInterface
public function postUpdate(AccompanyingPeriod $period, LifecycleEventArgs $args): void
{
if ($period->hasPreviousUser()
if ($period->isChangedUser()
&& $period->getUser() !== $this->security->getUser()
&& null !== $period->getUser()
&& $period->getStep() !== AccompanyingPeriod::STEP_DRAFT
) {
$this->generateNotificationToUser($period);
}
// we are just out of a flush operation. Launch a new one
$this->em->flush();
}
private function generateNotificationToUser(AccompanyingPeriod $period)
@@ -89,7 +86,7 @@ class UserRefEventSubscriber implements EventSubscriberInterface
))
->addAddressee($period->getUser());
$this->em->persist($notification);
$this->notificationPersister->persist($notification);
}
private function onPeriodConfirmed(AccompanyingPeriod $period)

View File

@@ -102,7 +102,6 @@ class HouseholdApiController extends ApiController
$event
->setPreviousAddress($household->getPreviousAddressOf($address))
->setNextAddress($address);
dump($event);
$this->eventDispatcher->dispatch($event);
}

View File

@@ -361,6 +361,8 @@ class AccompanyingPeriod implements
*/
private Collection $userHistories;
private bool $userIsChanged = false;
/**
* Temporary field, which is filled when the user is changed.
*
@@ -978,6 +980,11 @@ class AccompanyingPeriod implements
return null !== $this->userPrevious;
}
public function isChangedUser(): bool
{
return $this->userIsChanged && $this->user !== $this->userPrevious;
}
/**
* Returns true if the closing date is after the opening date.
*/
@@ -1103,6 +1110,14 @@ class AccompanyingPeriod implements
$this->setStep(AccompanyingPeriod::STEP_CONFIRMED);
}
public function resetPreviousUser(): self
{
$this->userPrevious = null;
$this->userIsChanged = false;
return $this;
}
/**
* @Groups({"write"})
*/
@@ -1329,6 +1344,7 @@ class AccompanyingPeriod implements
{
if ($this->user !== $user) {
$this->userPrevious = $this->user;
$this->userIsChanged = true;
foreach ($this->userHistories as $history) {
if (null === $history->getEndDate()) {

View File

@@ -57,6 +57,7 @@ class AccompanyingPeriodWork implements AccompanyingPeriodLinkedWithSocialIssues
* orphanRemoval=true
* )
* @Serializer\Groups({"read", "docgen:read"})
* @ORM\OrderBy({"startDate": "DESC", "id": "DESC"})
*
* @internal /!\ the serialization for write evaluations is handled in `AccompanyingPeriodWorkDenormalizer`
*/

View File

@@ -77,6 +77,7 @@ class AccompanyingPeriodWorkEvaluation implements TrackCreationInterface, TrackU
* cascade={"remove", "persist"},
* orphanRemoval=true
* )
* @ORM\OrderBy({"createdAt": "DESC", "id": "DESC"})
* @Serializer\Groups({"read"})
*/
private Collection $documents;

View File

@@ -19,6 +19,7 @@ use DateTimeInterface;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation\DiscriminatorMap;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Validator\Constraints as Assert;
/**
* @ORM\Entity
@@ -40,6 +41,8 @@ class Comment implements TrackCreationInterface, TrackUpdateInterface
/**
* @ORM\Column(type="text")
* @Groups({"read", "write"})
* @Assert\NotBlank
* @Assert\NotNull
*/
private $content;

View File

@@ -59,8 +59,8 @@ const appMessages = {
ok: "Oui, l'usager quitte le parcours",
show_household_number: "Voir le ménage (n° {id})",
show_household: "Voir le ménage",
person_without_household_warning: "Certaines usagers n'appartiennent actuellement à aucun ménage. Renseignez leur appartenance dès que possible.",
update_household: "Renseigner l'appartenance",
person_without_household_warning: "Certaines usagers n'appartiennent actuellement à aucun ménage. Veuillez les associer à un ménage dès que possible.",
update_household: "Associer à un ménage",
participation_not_valid: "Sélectionnez ou créez au minimum 1 usager",
},
requestor: {

View File

@@ -40,6 +40,7 @@
{% endif %}
{{ form_start(form) }}
{{ form_errors(form) }}
{{ form_errors(form.content) }}
{{ form_widget(form.content) }}
<ul class="record_actions">
<li>

View File

@@ -17,6 +17,8 @@
<div class="col-md-10">
<h1>{{ 'My accompanying periods'|trans }}</h1>
<p>{{ 'Number of periods'|trans }}: <span class="badge rounded-pill bg-primary">{{ pagination.totalItems }}</span></p>
<div class="flex-table accompanyingcourse-list">
{% for period in accompanyingPeriods %}
{% include '@ChillPerson/AccompanyingPeriod/_list_item.html.twig' with {'period': period, 'recordAction': _self.recordAction(period)} %}

View File

@@ -1,14 +1,14 @@
{{ 'period_notification.You are designated to a new period'|trans }}
{{ 'period_notification.You are designated to a new period'|trans|raw }}
{{ 'period_notification.See it online'|trans }}:
{{ 'period_notification.See it online'|trans|raw }}:
{{ absolute_url(path('chill_person_accompanying_course_index', {'accompanying_period_id': accompanyingCourse.id}, false)) }}
{{ 'period_notification.Persons are'|trans }}:
{{ 'period_notification.Persons are'|trans|raw }}:
{% for p in accompanyingCourse.getCurrentParticipations %}
* {{ p.person|chill_entity_render_string }}
{% endfor %}
{{ 'period_notification.Social issues are'|trans }}: {% for s in accompanyingCourse.socialIssues %}{{ s|chill_entity_render_string }}{% if not loop.last %}, {% endif %}{% endfor %}.
{{ 'period_notification.Social issues are'|trans|raw }}: {% for s in accompanyingCourse.socialIssues %}{{ s|chill_entity_render_string }}{% if not loop.last %}, {% endif %}{% endfor %}.

View File

@@ -14,6 +14,8 @@ namespace AccompanyingPeriod\Events;
use Chill\MainBundle\Entity\Address;
use Chill\MainBundle\Entity\Notification;
use Chill\MainBundle\Entity\User;
use Chill\MainBundle\Notification\NotificationPersister;
use Chill\MainBundle\Notification\NotificationPersisterInterface;
use Chill\PersonBundle\AccompanyingPeriod\Events\PersonAddressMoveEventSubscriber;
use Chill\PersonBundle\Entity\AccompanyingPeriod;
use Chill\PersonBundle\Entity\Household\Household;
@@ -22,7 +24,6 @@ use Chill\PersonBundle\Entity\Person;
use Chill\PersonBundle\Event\Person\PersonAddressMoveEvent;
use DateTime;
use DateTimeImmutable;
use Doctrine\ORM\EntityManagerInterface;
use Prophecy\Argument;
use Prophecy\PhpUnit\ProphecyTrait;
use ReflectionClass;
@@ -73,9 +74,9 @@ final class PersonMoveEventSubscriberTest extends KernelTestCase
->setPreviousMembership($previousMembership)
->setNextMembership($nextMembership);
$em = $this->prophesize(EntityManagerInterface::class);
$em->persist(Argument::type(Notification::class))->shouldNotBeCalled();
$eventSubscriber = $this->buildSubscriber(null, $em->reveal(), null, null);
$notificationPersister = $this->prophesize(NotificationPersisterInterface::class);
$notificationPersister->persist(Argument::type(Notification::class))->shouldNotBeCalled();
$eventSubscriber = $this->buildSubscriber(null, $notificationPersister->reveal(), null, null);
$eventSubscriber->resetPeriodLocation($event);
}
@@ -115,9 +116,9 @@ final class PersonMoveEventSubscriberTest extends KernelTestCase
->setPreviousMembership($previousMembership)
->setNextMembership($nextMembership);
$em = $this->prophesize(EntityManagerInterface::class);
$em->persist(Argument::type(Notification::class))->shouldBeCalledTimes(1);
$eventSubscriber = $this->buildSubscriber(null, $em->reveal(), null, null);
$notificationPersister = $this->prophesize(NotificationPersisterInterface::class);
$notificationPersister->persist(Argument::type(Notification::class))->shouldBeCalledTimes(1);
$eventSubscriber = $this->buildSubscriber(null, $notificationPersister->reveal(), null, null);
$eventSubscriber->resetPeriodLocation($event);
@@ -160,9 +161,9 @@ final class PersonMoveEventSubscriberTest extends KernelTestCase
->setPreviousMembership($previousMembership)
->setNextMembership($nextMembership);
$em = $this->prophesize(EntityManagerInterface::class);
$em->persist(Argument::type(Notification::class))->shouldBeCalled(1);
$eventSubscriber = $this->buildSubscriber(null, $em->reveal(), null, null);
$notificationPersister = $this->prophesize(NotificationPersisterInterface::class);
$notificationPersister->persist(Argument::type(Notification::class))->shouldBeCalled(1);
$eventSubscriber = $this->buildSubscriber(null, $notificationPersister->reveal(), null, null);
$eventSubscriber->resetPeriodLocation($event);
@@ -195,9 +196,9 @@ final class PersonMoveEventSubscriberTest extends KernelTestCase
$event
->setPreviousMembership($previousMembership);
$em = $this->prophesize(EntityManagerInterface::class);
$em->persist(Argument::type(Notification::class))->shouldBeCalledTimes(1);
$eventSubscriber = $this->buildSubscriber(null, $em->reveal(), null, null);
$notificationPersister = $this->prophesize(NotificationPersisterInterface::class);
$notificationPersister->persist(Argument::type(Notification::class))->shouldBeCalledTimes(1);
$eventSubscriber = $this->buildSubscriber(null, $notificationPersister->reveal(), null, null);
$eventSubscriber->resetPeriodLocation($event);
@@ -235,9 +236,9 @@ final class PersonMoveEventSubscriberTest extends KernelTestCase
->setPreviousAddress($household->getPreviousAddressOf($newAddress))
->setNextAddress($newAddress);
$em = $this->prophesize(EntityManagerInterface::class);
$em->persist(Argument::type(Notification::class))->shouldBeCalledTimes(1);
$eventSubscriber = $this->buildSubscriber(null, $em->reveal(), null, null);
$notificationPersister = $this->prophesize(NotificationPersisterInterface::class);
$notificationPersister->persist(Argument::type(Notification::class))->shouldBeCalledTimes(1);
$eventSubscriber = $this->buildSubscriber(null, $notificationPersister->reveal(), null, null);
$eventSubscriber->resetPeriodLocation($event);
@@ -247,7 +248,7 @@ final class PersonMoveEventSubscriberTest extends KernelTestCase
private function buildSubscriber(
?EngineInterface $engine = null,
?EntityManagerInterface $entityManager = null,
?NotificationPersisterInterface $notificationPersister = null,
?Security $security = null,
?TranslatorInterface $translator = null
): PersonAddressMoveEventSubscriber {
@@ -267,14 +268,13 @@ final class PersonMoveEventSubscriberTest extends KernelTestCase
$engine = $double->reveal();
}
if (null === $entityManager) {
$double = $this->prophesize(EntityManagerInterface::class);
$entityManager = $double->reveal();
if (null === $notificationPersister) {
$notificationPersister = new NotificationPersister();
}
return new PersonAddressMoveEventSubscriber(
$engine,
$entityManager,
$notificationPersister,
$security,
$translator
);

View File

@@ -13,6 +13,7 @@ namespace Chill\PersonBundle\Tests\Entity;
use ArrayIterator;
use Chill\MainBundle\Entity\Address;
use Chill\MainBundle\Entity\User;
use Chill\PersonBundle\Entity\AccompanyingPeriod;
use Chill\PersonBundle\Entity\AccompanyingPeriod\Comment;
use Chill\PersonBundle\Entity\AccompanyingPeriodParticipation;
@@ -62,6 +63,29 @@ final class AccompanyingPeriodTest extends \PHPUnit\Framework\TestCase
$this->assertFalse($period->isClosingAfterOpening());
}
public function testHasChangedUser()
{
$period = new AccompanyingPeriod();
$this->assertFalse($period->isChangedUser());
$this->assertFalse($period->hasPreviousUser());
$period->setUser($user1 = new User());
$this->assertTrue($period->isChangedUser());
$this->assertFalse($period->hasPreviousUser());
$period->resetPreviousUser();
$this->assertFalse($period->isChangedUser());
$this->assertFalse($period->hasPreviousUser());
$period->setUser($user2 = new User());
$this->assertTrue($period->isChangedUser());
$this->assertTrue($period->hasPreviousUser());
$this->assertSame($user1, $period->getPreviousUser());
}
public function testHistoryLocation()
{
$period = new AccompanyingPeriod();

View File

@@ -581,6 +581,7 @@ Linked evaluations: Évaluations associées
# Accompanying period per user
My accompanying periods: Mes parcours
My accompanying periods in draft: Mes parcours brouillons
Number of periods: Nombre de parcours
workflow:
Doc for evaluation (n°%eval%): Document de l'évaluation n°%eval%