85 lines
2.8 KiB
PHP
85 lines
2.8 KiB
PHP
<?php
|
|
|
|
namespace App\Notifications;
|
|
|
|
use App\Filament\Resources\TenantFeedbackResource;
|
|
use App\Models\TenantFeedback;
|
|
use Illuminate\Bus\Queueable;
|
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
|
use Illuminate\Notifications\Messages\MailMessage;
|
|
use Illuminate\Notifications\Notification;
|
|
use Illuminate\Support\Str;
|
|
|
|
class TenantFeedbackSubmitted extends Notification implements ShouldQueue
|
|
{
|
|
use Queueable;
|
|
|
|
public function __construct(protected TenantFeedback $feedback)
|
|
{
|
|
$this->feedback->loadMissing('tenant', 'event');
|
|
}
|
|
|
|
public function via(object $notifiable): array
|
|
{
|
|
return ['mail'];
|
|
}
|
|
|
|
public function toMail(object $notifiable): MailMessage
|
|
{
|
|
$tenantName = $this->resolveName($this->feedback->tenant?->name) ?: __('emails.tenant_feedback.unknown_tenant');
|
|
$eventName = $this->resolveName($this->feedback->event?->name) ?: ($this->feedback->metadata['event_name'] ?? null);
|
|
$sentiment = $this->feedback->sentiment ? Str::headline($this->feedback->sentiment) : __('emails.tenant_feedback.unknown');
|
|
$rating = $this->feedback->rating ? sprintf('%d/5', $this->feedback->rating) : null;
|
|
|
|
$subject = __('emails.tenant_feedback.subject', [
|
|
'tenant' => $tenantName,
|
|
'sentiment' => $sentiment,
|
|
]);
|
|
|
|
$mail = (new MailMessage())
|
|
->subject($subject)
|
|
->line(__('emails.tenant_feedback.tenant', ['tenant' => $tenantName]))
|
|
->line(__('emails.tenant_feedback.category', ['category' => $this->feedback->category ? Str::headline($this->feedback->category) : '—']))
|
|
->line(__('emails.tenant_feedback.sentiment', ['sentiment' => $sentiment]));
|
|
|
|
if ($eventName) {
|
|
$mail->line(__('emails.tenant_feedback.event', ['event' => $eventName]));
|
|
}
|
|
|
|
if ($rating) {
|
|
$mail->line(__('emails.tenant_feedback.rating', ['rating' => $rating]));
|
|
}
|
|
|
|
if ($this->feedback->title) {
|
|
$mail->line(__('emails.tenant_feedback.title', ['subject' => $this->feedback->title]));
|
|
}
|
|
|
|
if ($this->feedback->message) {
|
|
$mail->line(__('emails.tenant_feedback.message'))->line($this->feedback->message);
|
|
}
|
|
|
|
$url = TenantFeedbackResource::getUrl('view', ['record' => $this->feedback], panel: 'superadmin');
|
|
|
|
if ($url) {
|
|
$mail->action(__('emails.tenant_feedback.open'), $url);
|
|
}
|
|
|
|
$mail->line(__('emails.tenant_feedback.received_at', ['date' => $this->feedback->created_at?->toDayDateTimeString()]));
|
|
|
|
return $mail;
|
|
}
|
|
|
|
protected function resolveName(mixed $name): ?string
|
|
{
|
|
if (is_string($name) && $name !== '') {
|
|
return $name;
|
|
}
|
|
|
|
if (is_array($name)) {
|
|
return $name['de'] ?? $name['en'] ?? reset($name) ?: null;
|
|
}
|
|
|
|
return null;
|
|
}
|
|
}
|