Files
My-KOPKB/be/Modules/Feedback/Notifications/FeedbackNotification.php
T
2026-07-14 12:02:37 +08:00

67 lines
2.0 KiB
PHP

<?php
namespace Modules\Feedback\Notifications;
use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
use Modules\Feedback\Entities\Feedback;
use Modules\Auth\Entities\User;
class FeedbackNotification extends Notification
{
use Queueable;
protected $feedback;
protected $sender;
/**
* Create a new notification instance.
*/
public function __construct(Feedback $feedback, User $sender = null)
{
$this->feedback = $feedback;
$this->sender = $sender;
}
/**
* Get the notification's delivery channels.
*/
public function via($notifiable): array
{
return ['database'];
}
/**
* Get the array representation of the notification.
*/
public function toArray($notifiable): array
{
return [
'feedback_id' => $this->feedback->id,
'sender_id' => $this->sender ? $this->sender->id : null,
'type' => 'feedback_submitted',
'message' => $this->getNotificationMessage(),
'feedback_title' => $this->feedback->title ?? 'Unknown',
'feedback_type' => $this->feedback->type ?? 'Unknown',
'feedback_priority' => $this->feedback->priority ?? 'normal',
'user_name' => $this->feedback->user ? $this->feedback->user->name : 'Anonymous',
'user_email' => $this->feedback->user ? $this->feedback->user->email : null,
];
}
/**
* Get notification message
*/
private function getNotificationMessage(): string
{
$userName = $this->feedback->user ? $this->feedback->user->name : 'Pengguna tanpa nama';
$feedbackTitle = $this->feedback->title ?? 'Unknown';
$feedbackType = $this->feedback->type ?? 'Unknown';
$feedbackPriority = $this->feedback->priority ?? 'normal';
$feedbackId = $this->feedback->id;
return "Maklum balas baru telah diterima. ID: {$feedbackId}, Tajuk: {$feedbackTitle}, Jenis: {$feedbackType}, Keutamaan: {$feedbackPriority}, Pengguna: {$userName}";
}
}