|
|
@@ -0,0 +1,31 @@
|
|
|
+<?php
|
|
|
+declare(strict_types=1);
|
|
|
+
|
|
|
+namespace SixShop\Message\Hook;
|
|
|
+
|
|
|
+use SixShop\Core\Attribute\Hook;
|
|
|
+use SixShop\Message\Entity\MessageNotificationsEntity;
|
|
|
+use SixShop\Message\Enum\NotificationsTypeEnum;
|
|
|
+
|
|
|
+readonly class SendNotificationsHook
|
|
|
+{
|
|
|
+ public function __construct(private MessageNotificationsEntity $messageNotificationsEntity)
|
|
|
+ {
|
|
|
+ }
|
|
|
+
|
|
|
+ #[Hook('message.send_notifications')]
|
|
|
+ public function handle(array $params): void
|
|
|
+ {
|
|
|
+ $msgList = [];
|
|
|
+ foreach ($params as $msg) {
|
|
|
+ $msgList[] = [
|
|
|
+ 'user_id' => $msg['user_id'],
|
|
|
+ 'title' => $msg['title'],
|
|
|
+ 'content' => $msg['content'],
|
|
|
+ 'type' => NotificationsTypeEnum::from((int)$msg['type']),
|
|
|
+ ];
|
|
|
+
|
|
|
+ }
|
|
|
+ $msgList && $this->messageNotificationsEntity->insertAll($msgList);
|
|
|
+ }
|
|
|
+}
|