mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
send system notification on period confirmation
This commit is contained in:
parent
7bc4ad9779
commit
5bf1b9d8bd
@ -74,9 +74,14 @@ class Notification implements TrackUpdateInterface
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @ORM\ManyToOne(targetEntity=User::class)
|
* @ORM\ManyToOne(targetEntity=User::class)
|
||||||
* @ORM\JoinColumn(nullable=false)
|
* @ORM\JoinColumn(nullable=true)
|
||||||
*/
|
*/
|
||||||
private User $sender;
|
private ?User $sender = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ORM\Column(type="text", options={"default": ""})
|
||||||
|
*/
|
||||||
|
private string $title = '';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @ORM\ManyToMany(targetEntity=User::class)
|
* @ORM\ManyToMany(targetEntity=User::class)
|
||||||
@ -179,6 +184,11 @@ class Notification implements TrackUpdateInterface
|
|||||||
return $this->sender;
|
return $this->sender;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getTitle(): string
|
||||||
|
{
|
||||||
|
return $this->title;
|
||||||
|
}
|
||||||
|
|
||||||
public function getUnreadBy(): Collection
|
public function getUnreadBy(): Collection
|
||||||
{
|
{
|
||||||
return $this->unreadBy;
|
return $this->unreadBy;
|
||||||
@ -199,6 +209,11 @@ class Notification implements TrackUpdateInterface
|
|||||||
return !$this->unreadBy->contains($user);
|
return !$this->unreadBy->contains($user);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function isSystem(): bool
|
||||||
|
{
|
||||||
|
return null === $this->sender;
|
||||||
|
}
|
||||||
|
|
||||||
public function markAsReadBy(User $user): self
|
public function markAsReadBy(User $user): self
|
||||||
{
|
{
|
||||||
return $this->removeUnreadBy($user);
|
return $this->removeUnreadBy($user);
|
||||||
@ -299,6 +314,13 @@ class Notification implements TrackUpdateInterface
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function setTitle(string $title): Notification
|
||||||
|
{
|
||||||
|
$this->title = $title;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
public function setUpdatedAt(DateTimeInterface $datetime): self
|
public function setUpdatedAt(DateTimeInterface $datetime): self
|
||||||
{
|
{
|
||||||
$this->updatedAt = $datetime;
|
$this->updatedAt = $datetime;
|
||||||
|
@ -1,5 +1,14 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace Chill\MainBundle\Notification;
|
namespace Chill\MainBundle\Notification;
|
||||||
|
|
||||||
use Chill\MainBundle\Entity\Notification;
|
use Chill\MainBundle\Entity\Notification;
|
||||||
@ -8,14 +17,14 @@ use Chill\MainBundle\Repository\NotificationRepository;
|
|||||||
use Symfony\Component\Security\Core\Security;
|
use Symfony\Component\Security\Core\Security;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helps to find if a notification exist for a given entity
|
* Helps to find if a notification exist for a given entity.
|
||||||
*/
|
*/
|
||||||
class NotificationPresence
|
class NotificationPresence
|
||||||
{
|
{
|
||||||
private Security $security;
|
|
||||||
|
|
||||||
private NotificationRepository $notificationRepository;
|
private NotificationRepository $notificationRepository;
|
||||||
|
|
||||||
|
private Security $security;
|
||||||
|
|
||||||
public function __construct(Security $security, NotificationRepository $notificationRepository)
|
public function __construct(Security $security, NotificationRepository $notificationRepository)
|
||||||
{
|
{
|
||||||
$this->security = $security;
|
$this->security = $security;
|
||||||
|
@ -1,5 +1,14 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace Chill\MainBundle\Notification\Templating;
|
namespace Chill\MainBundle\Notification\Templating;
|
||||||
|
|
||||||
use Twig\Extension\AbstractExtension;
|
use Twig\Extension\AbstractExtension;
|
||||||
|
@ -1,5 +1,14 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace Chill\MainBundle\Notification\Templating;
|
namespace Chill\MainBundle\Notification\Templating;
|
||||||
|
|
||||||
use Chill\MainBundle\Notification\NotificationPresence;
|
use Chill\MainBundle\Notification\NotificationPresence;
|
||||||
@ -27,5 +36,4 @@ class NotificationTwigExtensionRuntime implements RuntimeExtensionInterface
|
|||||||
'notifications' => $notifications,
|
'notifications' => $notifications,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -134,9 +134,17 @@ final class NotificationRepository implements ObjectRepository
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $relatedEntityClass
|
* @param mixed|null $limit
|
||||||
* @param int $relatedEntityId
|
* @param mixed|null $offset
|
||||||
* @param User $user
|
*
|
||||||
|
* @return Notification[]
|
||||||
|
*/
|
||||||
|
public function findBy(array $criteria, ?array $orderBy = null, $limit = null, $offset = null): array
|
||||||
|
{
|
||||||
|
return $this->repository->findBy($criteria, $orderBy, $limit, $offset);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
* @return array|Notification[]
|
* @return array|Notification[]
|
||||||
*/
|
*/
|
||||||
public function findNotificationAsAddresseeByRelatedEntityAndUser(string $relatedEntityClass, int $relatedEntityId, User $user): array
|
public function findNotificationAsAddresseeByRelatedEntityAndUser(string $relatedEntityClass, int $relatedEntityId, User $user): array
|
||||||
@ -150,23 +158,11 @@ final class NotificationRepository implements ObjectRepository
|
|||||||
->andWhere($qb->expr()->isMemberOf(':user', 'n.addressees'))
|
->andWhere($qb->expr()->isMemberOf(':user', 'n.addressees'))
|
||||||
->setParameter('relatedEntityClass', $relatedEntityClass)
|
->setParameter('relatedEntityClass', $relatedEntityClass)
|
||||||
->setParameter('relatedEntityId', $relatedEntityId)
|
->setParameter('relatedEntityId', $relatedEntityId)
|
||||||
->setParameter('user', $user)
|
->setParameter('user', $user);
|
||||||
;
|
|
||||||
|
|
||||||
return $qb->getQuery()->getResult();
|
return $qb->getQuery()->getResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param mixed|null $limit
|
|
||||||
* @param mixed|null $offset
|
|
||||||
*
|
|
||||||
* @return Notification[]
|
|
||||||
*/
|
|
||||||
public function findBy(array $criteria, ?array $orderBy = null, $limit = null, $offset = null): array
|
|
||||||
{
|
|
||||||
return $this->repository->findBy($criteria, $orderBy, $limit, $offset);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function findOneBy(array $criteria, ?array $orderBy = null): ?Notification
|
public function findOneBy(array $criteria, ?array $orderBy = null): ?Notification
|
||||||
{
|
{
|
||||||
return $this->repository->findOneBy($criteria, $orderBy);
|
return $this->repository->findOneBy($criteria, $orderBy);
|
||||||
|
@ -1,7 +1,11 @@
|
|||||||
<div class="list_notification_for">
|
<div class="list_notification_for">
|
||||||
{% for notification in notifications %}
|
{% for notification in notifications %}
|
||||||
<div class="notification {% if notification.isReadBy(app.user) %}read{% else %}unread{% endif %}">
|
<div class="notification {% if notification.isReadBy(app.user) %}read{% else %}unread{% endif %}">
|
||||||
|
{% if not notification.isSystem %}
|
||||||
<div>{{ 'notification.you were notified by %sender%'|trans({'%sender%': notification.sender|chill_entity_render_string }) }}</div>
|
<div>{{ 'notification.you were notified by %sender%'|trans({'%sender%': notification.sender|chill_entity_render_string }) }}</div>
|
||||||
|
{% else %}
|
||||||
|
<div>{{ 'notification.you were notified by system'|trans }}</div>
|
||||||
|
{% endif %}
|
||||||
<div>
|
<div>
|
||||||
<ul class="record_actions_small">
|
<ul class="record_actions_small">
|
||||||
<li>
|
<li>
|
||||||
|
@ -0,0 +1,38 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Chill\Migrations\Main;
|
||||||
|
|
||||||
|
use Doctrine\DBAL\Schema\Schema;
|
||||||
|
use Doctrine\Migrations\AbstractMigration;
|
||||||
|
|
||||||
|
final class Version20211230003532 extends AbstractMigration
|
||||||
|
{
|
||||||
|
public function down(Schema $schema): void
|
||||||
|
{
|
||||||
|
$this->addSql('ALTER TABLE chill_main_notification DROP title');
|
||||||
|
$this->addSql('ALTER TABLE chill_main_notification ALTER sender_id SET NOT NULL');
|
||||||
|
$this->addSql('ALTER TABLE chill_main_notification ALTER updatedAt DROP NOT NULL');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getDescription(): string
|
||||||
|
{
|
||||||
|
return 'Add title and allow system notification (sender is null)';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function up(Schema $schema): void
|
||||||
|
{
|
||||||
|
$this->addSql('ALTER TABLE chill_main_notification ADD title TEXT DEFAULT \'\' NOT NULL');
|
||||||
|
$this->addSql('ALTER TABLE chill_main_notification ALTER sender_id DROP NOT NULL');
|
||||||
|
$this->addSql('UPDATE chill_main_notification set updatedat="date"');
|
||||||
|
$this->addSql('ALTER TABLE chill_main_notification ALTER updatedat SET NOT NULL');
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,77 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Chill\PersonBundle\AccompanyingPeriod\Workflow;
|
||||||
|
|
||||||
|
use Chill\MainBundle\Entity\Notification;
|
||||||
|
use Chill\MainBundle\Entity\User;
|
||||||
|
use Chill\PersonBundle\Entity\AccompanyingPeriod;
|
||||||
|
use Doctrine\ORM\EntityManagerInterface;
|
||||||
|
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
|
||||||
|
{
|
||||||
|
private EntityManagerInterface $em;
|
||||||
|
|
||||||
|
private EngineInterface $engine;
|
||||||
|
|
||||||
|
private Security $security;
|
||||||
|
|
||||||
|
private TranslatorInterface $translator;
|
||||||
|
|
||||||
|
public function __construct(Security $security, TranslatorInterface $translator, EngineInterface $engine, EntityManagerInterface $em)
|
||||||
|
{
|
||||||
|
$this->security = $security;
|
||||||
|
$this->translator = $translator;
|
||||||
|
$this->engine = $engine;
|
||||||
|
$this->em = $em;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getSubscribedEvents()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'workflow.accompanying_period_lifecycle.entered' => [
|
||||||
|
'onStateEntered',
|
||||||
|
],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function onStateEntered(EnteredEvent $enteredEvent): void
|
||||||
|
{
|
||||||
|
if ($enteredEvent->getMarking()->has(AccompanyingPeriod::STEP_CONFIRMED)) {
|
||||||
|
$this->onPeriodConfirmed($enteredEvent->getSubject());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,12 @@
|
|||||||
|
{{ 'period_notification.You are designated to a new period.'|trans }}
|
||||||
|
|
||||||
|
{{ 'period_notification.See it online'|trans }}: {{ path('chill_person_accompanying_course_index', {'accompanying_period_id': accompanyingCourse.id}, true) }}
|
||||||
|
|
||||||
|
{{ 'period_notification.Persons are'|trans }}:
|
||||||
|
|
||||||
|
{% 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 %}.
|
||||||
|
|
@ -0,0 +1,22 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace AccompanyingPeriod\Workflow;
|
||||||
|
|
||||||
|
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @internal
|
||||||
|
* @coversNothing
|
||||||
|
*/
|
||||||
|
final class WorkflowEventSubscriberTest extends KernelTestCase
|
||||||
|
{
|
||||||
|
}
|
@ -20,3 +20,9 @@ services:
|
|||||||
|
|
||||||
Chill\PersonBundle\AccompanyingPeriod\Suggestion\ReferralsSuggestionInterface: '@Chill\PersonBundle\AccompanyingPeriod\Suggestion\ReferralsSuggestion'
|
Chill\PersonBundle\AccompanyingPeriod\Suggestion\ReferralsSuggestionInterface: '@Chill\PersonBundle\AccompanyingPeriod\Suggestion\ReferralsSuggestion'
|
||||||
|
|
||||||
|
Chill\PersonBundle\AccompanyingPeriod\Workflow\:
|
||||||
|
resource: './../../AccompanyingPeriod/Workflow'
|
||||||
|
autowire: true
|
||||||
|
autoconfigure: true
|
||||||
|
|
||||||
|
|
||||||
|
@ -475,3 +475,10 @@ docgen:
|
|||||||
A basic context for accompanying period: Contexte pour les parcours
|
A basic context for accompanying period: Contexte pour les parcours
|
||||||
A context for accompanying period work: Contexte pour les actions d'accompagnement
|
A context for accompanying period work: Contexte pour les actions d'accompagnement
|
||||||
A context for accompanying period work evaluation: Contexte pour les évaluations dans les actions d'accompagnement
|
A context for accompanying period work evaluation: Contexte pour les évaluations dans les actions d'accompagnement
|
||||||
|
|
||||||
|
period_notification:
|
||||||
|
period_designated_subject: Vous êtes référent d'un parcours d'accompagnement
|
||||||
|
You are designated to a new period: Vous avez été désigné référent d'un parcours d'accompagnement.
|
||||||
|
Persons are: Les usagers concernés sont les suivants
|
||||||
|
Social issues are: Les problématiques sociales renseignées sont les suivantes
|
||||||
|
See it online: Visualisez le parcours en ligne
|
||||||
|
Loading…
x
Reference in New Issue
Block a user