mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
notificaiton: improve NotificationHandlerInterface + mark notification
as unread if a comment is appended
This commit is contained in:
parent
ebc6d21ba6
commit
4ef024516c
@ -25,7 +25,7 @@ final class ActivityNotificationHandler implements NotificationHandlerInterface
|
|||||||
$this->activityRepository = $activityRepository;
|
$this->activityRepository = $activityRepository;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getTemplate(array $options = []): string
|
public function getTemplate(Notification $notification, array $options = []): string
|
||||||
{
|
{
|
||||||
return '@ChillActivity/Activity/showInNotification.html.twig';
|
return '@ChillActivity/Activity/showInNotification.html.twig';
|
||||||
}
|
}
|
||||||
|
@ -15,11 +15,14 @@ use Chill\MainBundle\Doctrine\Model\TrackCreationInterface;
|
|||||||
use Chill\MainBundle\Doctrine\Model\TrackUpdateInterface;
|
use Chill\MainBundle\Doctrine\Model\TrackUpdateInterface;
|
||||||
use DateTimeImmutable;
|
use DateTimeImmutable;
|
||||||
use DateTimeInterface;
|
use DateTimeInterface;
|
||||||
|
use Doctrine\ORM\Event\LifecycleEventArgs;
|
||||||
|
use Doctrine\ORM\Event\PreFlushEventArgs;
|
||||||
use Doctrine\ORM\Mapping as ORM;
|
use Doctrine\ORM\Mapping as ORM;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @ORM\Entity
|
* @ORM\Entity
|
||||||
* @ORM\Table("chill_main_notification_comment")
|
* @ORM\Table("chill_main_notification_comment")
|
||||||
|
* @ORM\HasLifecycleCallbacks
|
||||||
*/
|
*/
|
||||||
class NotificationComment implements TrackCreationInterface, TrackUpdateInterface
|
class NotificationComment implements TrackCreationInterface, TrackUpdateInterface
|
||||||
{
|
{
|
||||||
@ -52,6 +55,13 @@ class NotificationComment implements TrackCreationInterface, TrackUpdateInterfac
|
|||||||
*/
|
*/
|
||||||
private ?Notification $notification = null;
|
private ?Notification $notification = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Internal variable which detect if the comment is just persisted.
|
||||||
|
*
|
||||||
|
* @internal
|
||||||
|
*/
|
||||||
|
private bool $recentlyPersisted = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @ORM\Column(type="datetime_immutable", nullable=true)
|
* @ORM\Column(type="datetime_immutable", nullable=true)
|
||||||
*/
|
*/
|
||||||
@ -98,6 +108,32 @@ class NotificationComment implements TrackCreationInterface, TrackUpdateInterfac
|
|||||||
return $this->updatedBy;
|
return $this->updatedBy;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ORM\PreFlush
|
||||||
|
*/
|
||||||
|
public function onFlushMarkNotificationAsUnread(PreFlushEventArgs $eventArgs): void
|
||||||
|
{
|
||||||
|
if ($this->recentlyPersisted) {
|
||||||
|
foreach ($this->getNotification()->getAddressees() as $addressee) {
|
||||||
|
if ($this->getCreatedBy() !== $addressee) {
|
||||||
|
$this->getNotification()->markAsUnreadBy($addressee);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($this->getNotification()->getSender() !== $this->getCreatedBy()) {
|
||||||
|
$this->getNotification()->markAsUnreadBy($this->getNotification()->getSender());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ORM\PrePersist
|
||||||
|
*/
|
||||||
|
public function onPrePersist(LifecycleEventArgs $eventArgs): void
|
||||||
|
{
|
||||||
|
$this->recentlyPersisted = true;
|
||||||
|
}
|
||||||
|
|
||||||
public function setContent(string $content): self
|
public function setContent(string $content): self
|
||||||
{
|
{
|
||||||
$this->content = $content;
|
$this->content = $content;
|
||||||
|
@ -18,7 +18,7 @@ interface NotificationHandlerInterface
|
|||||||
/**
|
/**
|
||||||
* Return the template path (twig file).
|
* Return the template path (twig file).
|
||||||
*/
|
*/
|
||||||
public function getTemplate(array $options = []): string;
|
public function getTemplate(Notification $notification, array $options = []): string;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return an array which will be passed as data for the template.
|
* Return an array which will be passed as data for the template.
|
||||||
|
@ -45,7 +45,7 @@ final class NotificationHandlerManager
|
|||||||
|
|
||||||
public function getTemplate(Notification $notification, array $options = []): string
|
public function getTemplate(Notification $notification, array $options = []): string
|
||||||
{
|
{
|
||||||
return $this->getHandler($notification, $options)->getTemplate($options);
|
return $this->getHandler($notification, $options)->getTemplate($notification, $options);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getTemplateData(Notification $notification, array $options = []): array
|
public function getTemplateData(Notification $notification, array $options = []): array
|
||||||
|
@ -25,7 +25,7 @@ final class AccompanyingPeriodNotificationHandler implements NotificationHandler
|
|||||||
$this->accompanyingPeriodRepository = $accompanyingPeriodRepository;
|
$this->accompanyingPeriodRepository = $accompanyingPeriodRepository;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getTemplate(array $options = []): string
|
public function getTemplate(Notification $notification, array $options = []): string
|
||||||
{
|
{
|
||||||
return 'ChillPersonBundle:AccompanyingPeriod:showInNotification.html.twig';
|
return 'ChillPersonBundle:AccompanyingPeriod:showInNotification.html.twig';
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user