Last commit july 5th

This commit is contained in:
2024-07-05 13:46:23 +02:00
parent dad0d86e8c
commit b0e4dfbb76
24982 changed files with 2621219 additions and 413 deletions

View File

@@ -0,0 +1,72 @@
<?php
namespace App\Notification;
use App\Entity\Comment;
use Symfony\Component\Notifier\Bridge\Slack\Block\SlackDividerBlock;
use Symfony\Component\Notifier\Bridge\Slack\Block\SlackSectionBlock;
use Symfony\Component\Notifier\Bridge\Slack\SlackOptions;
use Symfony\Component\Notifier\Message\ChatMessage;
use Symfony\Component\Notifier\Message\EmailMessage;
use Symfony\Component\Notifier\Notification\ChatNotificationInterface;
use Symfony\Component\Notifier\Notification\EmailNotificationInterface;
use Symfony\Component\Notifier\Notification\Notification;
use Symfony\Component\Notifier\Recipient\EmailRecipientInterface;
use Symfony\Component\Notifier\Recipient\RecipientInterface;
class CommentReviewNotification extends Notification implements EmailNotificationInterface, ChatNotificationInterface
{
public function __construct(
private Comment $comment,
private string $reviewUrl,
)
{
parent::__construct('New comment posted');
}
public function asChatMessage(RecipientInterface $recipient, string $transport = null): ?ChatMessage
{
if ('slack' !== $transport) {
return null;
}
$message = ChatMessage::fromNotification($this, $recipient, $transport);
$message->subject($this->getSubject());
$message->options((new SlackOptions())
->iconEmoji('tada')
->iconUrl('https://guestbook.example.com')
->username('Guestbook')
->block((new SlackSectionBlock())->text($this->getSubject()))
->block(new SlackDividerBlock())
->block((new SlackSectionBlock())
->text(sprintf('%s (%s) says: %s', $this->comment->getAuthor(), $this->comment->getEmail(), $this->comment->getText()))
)
->block((new SlackActionsBlock())
->button('Accept', $this->reviewUrl, 'primary')
->button('Reject', $this->reviewUrl . '?reject=1', 'danger')
)
);
return $message;
}
public function asEmailMessage(EmailRecipientInterface $recipient, string $transport = null): ?EmailMessage
{
$message = EmailMessage::fromNotification($this, $recipient, $transport);
$message->getMessage()
->htmlTemplate('emails/comment_notification.html.twig')
->context(['comment' => $this->comment]);
return $message;
}
public function getChannels(RecipientInterface $recipient): array
{
if (preg_match('{\b(great|awesome)\b}i', $this->comment->getText())) {
return ['email', 'chat/slack'];
}
$this->importance(Notification::IMPORTANCE_LOW);
return ['email'];
}
}