mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-20 22:53:49 +00:00
Improve notifications
This commit is contained in:
@@ -9,19 +9,20 @@
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Chill\PersonBundle\AccompanyingPeriod\Workflow;
|
||||
namespace Chill\PersonBundle\AccompanyingPeriod\Events;
|
||||
|
||||
use Chill\MainBundle\Entity\Notification;
|
||||
use Chill\MainBundle\Entity\User;
|
||||
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;
|
||||
use Symfony\Component\Templating\EngineInterface;
|
||||
use Symfony\Component\Workflow\Event\EnteredEvent;
|
||||
use Symfony\Contracts\Translation\TranslatorInterface;
|
||||
|
||||
class WorkflowEventSubscriber implements EventSubscriberInterface
|
||||
class UserRefEventSubscriber implements EventSubscriberInterface
|
||||
{
|
||||
private EntityManagerInterface $em;
|
||||
|
||||
@@ -55,23 +56,46 @@ class WorkflowEventSubscriber implements EventSubscriberInterface
|
||||
}
|
||||
}
|
||||
|
||||
public function postUpdate(AccompanyingPeriod $period, LifecycleEventArgs $args): void
|
||||
{
|
||||
if ($period->hasPreviousUser()
|
||||
&& $period->getUser() !== $this->security->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)
|
||||
{
|
||||
$notification = new Notification();
|
||||
|
||||
$urgentStatement =
|
||||
$period->isEmergency() ? strtoupper($this->translator->trans('accompanying_period.emergency')) . ' ' : '';
|
||||
|
||||
$notification
|
||||
->setRelatedEntityId($period->getId())
|
||||
->setRelatedEntityClass(AccompanyingPeriod::class)
|
||||
->setTitle($urgentStatement . $this->translator->trans('period_notification.period_designated_subject'))
|
||||
->setMessage($this->engine->render(
|
||||
'@ChillPerson/Notification/accompanying_course_designation.md.twig',
|
||||
[
|
||||
'accompanyingCourse' => $period,
|
||||
]
|
||||
))
|
||||
->addAddressee($period->getUser());
|
||||
|
||||
$this->em->persist($notification);
|
||||
}
|
||||
|
||||
private function onPeriodConfirmed(AccompanyingPeriod $period)
|
||||
{
|
||||
if ($period->getUser() instanceof User
|
||||
&& $period->getUser() !== $this->security->getUser()) {
|
||||
$notification = new Notification();
|
||||
$notification
|
||||
->setRelatedEntityId($period->getId())
|
||||
->setRelatedEntityClass(AccompanyingPeriod::class)
|
||||
->setTitle($this->translator->trans('period_notification.period_designated_subject'))
|
||||
->setMessage($this->engine->render(
|
||||
'@ChillPerson/Notification/accompanying_course_designation.md.twig',
|
||||
[
|
||||
'accompanyingCourse' => $period,
|
||||
]
|
||||
))
|
||||
->addAddressee($period->getUser());
|
||||
$this->em->persist($notification);
|
||||
$this->generateNotificationToUser($period);
|
||||
}
|
||||
}
|
||||
}
|
@@ -327,6 +327,13 @@ class AccompanyingPeriod implements
|
||||
*/
|
||||
private ?User $user = null;
|
||||
|
||||
/**
|
||||
* Temporary field, which is filled when the user is changed.
|
||||
*
|
||||
* Used internally for listener when user change
|
||||
*/
|
||||
private ?User $userPrevious = null;
|
||||
|
||||
/**
|
||||
* @ORM\OneToMany(
|
||||
* targetEntity=AccompanyingPeriodWork::class,
|
||||
@@ -755,6 +762,11 @@ class AccompanyingPeriod implements
|
||||
return $this->pinnedComment;
|
||||
}
|
||||
|
||||
public function getPreviousUser(): ?User
|
||||
{
|
||||
return $this->userPrevious;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Collection|SocialAction[] All the descendant social actions of all
|
||||
* the descendants of the entity
|
||||
@@ -868,6 +880,11 @@ class AccompanyingPeriod implements
|
||||
return $this->works;
|
||||
}
|
||||
|
||||
public function hasPreviousUser(): bool
|
||||
{
|
||||
return null !== $this->userPrevious;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the closing date is after the opening date.
|
||||
*/
|
||||
@@ -1172,6 +1189,10 @@ class AccompanyingPeriod implements
|
||||
|
||||
public function setUser(User $user): self
|
||||
{
|
||||
if ($this->user !== $user) {
|
||||
$this->userPrevious = $this->user;
|
||||
}
|
||||
|
||||
$this->user = $user;
|
||||
|
||||
return $this;
|
||||
|
@@ -61,13 +61,13 @@ final class CreationPersonType extends AbstractType
|
||||
'required' => false,
|
||||
])
|
||||
->add('phonenumber', TelType::class, [
|
||||
'required' => false
|
||||
'required' => false,
|
||||
])
|
||||
->add('mobilenumber', TelType::class, [
|
||||
'required' => false
|
||||
'required' => false,
|
||||
])
|
||||
->add('email', EmailType::class, [
|
||||
'required' => false
|
||||
'required' => false,
|
||||
]);
|
||||
|
||||
if ($this->askCenters) {
|
||||
|
@@ -131,6 +131,10 @@
|
||||
{{ 'le ' ~ w.updatedAt|format_datetime('long', 'short') }}
|
||||
</div>
|
||||
<ul class="record_actions">
|
||||
{% set notif_counter = chill_count_notifications('Chill\\PersonBundle\\Entity\\AccompanyingPeriod\\AccompanyingPeriodWork', w.id) %}
|
||||
{% if notif_counter.total > 0 %}
|
||||
<li>{{ chill_counter_notifications('Chill\\PersonBundle\\Entity\\AccompanyingPeriod\\AccompanyingPeriodWork', w.id) }}</li>
|
||||
{% endif %}
|
||||
<li>
|
||||
<a class="btn btn-edit" title="{{ 'Edit'|trans }}"
|
||||
href="{{ chill_path_add_return_path('chill_person_accompanying_period_work_edit', { 'id': w.id }) }}"
|
||||
|
@@ -5,6 +5,10 @@
|
||||
|
||||
{% macro recordAction(period, contextEntity) %}
|
||||
{# TODO if enable_accompanying_course_with_multiple_persons is true ... #}
|
||||
{% set notif_counter = chill_count_notifications('Chill\\PersonBundle\\Entity\\AccompanyingPeriod', period.id) %}
|
||||
{% if notif_counter.total > 0 %}
|
||||
<li>{{ chill_counter_notifications('Chill\\PersonBundle\\Entity\\AccompanyingPeriod', period.id) }}</li>
|
||||
{% endif %}
|
||||
<li>
|
||||
<a href="{{ path('chill_person_accompanying_course_index', { 'accompanying_period_id': period.id }) }}"
|
||||
class="btn btn-show" title="{{ 'See accompanying period'|trans }}">{# {{ 'See this period'|trans }} #}</a>
|
||||
|
@@ -118,6 +118,10 @@
|
||||
{{ 'File number'|trans }} {{ acp.id }}
|
||||
</div>
|
||||
|
||||
{% set notif_counter = chill_count_notifications('Chill\\PersonBundle\\Entity\\AccompanyingPeriod', acp.id) %}
|
||||
{% if notif_counter.total > 0 %}
|
||||
<div class="counter">{{ chill_counter_notifications('Chill\\PersonBundle\\Entity\\AccompanyingPeriod', acp.id) }}</div>
|
||||
{% endif %}
|
||||
|
||||
</div>
|
||||
<div class="wl-col list">
|
||||
|
@@ -20,9 +20,19 @@ services:
|
||||
|
||||
Chill\PersonBundle\AccompanyingPeriod\Suggestion\ReferralsSuggestionInterface: '@Chill\PersonBundle\AccompanyingPeriod\Suggestion\ReferralsSuggestion'
|
||||
|
||||
Chill\PersonBundle\AccompanyingPeriod\Workflow\:
|
||||
resource: './../../AccompanyingPeriod/Workflow'
|
||||
Chill\PersonBundle\AccompanyingPeriod\Events\:
|
||||
resource: './../../AccompanyingPeriod/Events'
|
||||
autowire: true
|
||||
autoconfigure: true
|
||||
|
||||
Chill\PersonBundle\AccompanyingPeriod\Events\UserRefEventSubscriber:
|
||||
autowire: true
|
||||
autoconfigure: true
|
||||
tags:
|
||||
- # these are the options required to define the entity listener
|
||||
name: 'doctrine.orm.entity_listener'
|
||||
event: 'postUpdate'
|
||||
entity: 'Chill\PersonBundle\Entity\AccompanyingPeriod'
|
||||
|
||||
# set the 'lazy' option to TRUE to only instantiate listeners when they are used
|
||||
lazy: true
|
||||
|
Reference in New Issue
Block a user