108 lines
3.6 KiB
PHP
108 lines
3.6 KiB
PHP
<?php
|
|
|
|
namespace App\Notifications;
|
|
|
|
use Illuminate\Bus\Queueable;
|
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
|
use Illuminate\Notifications\Messages\MailMessage;
|
|
use Illuminate\Notifications\Notification;
|
|
use App\Notifications\Channels\FcmChannel;
|
|
|
|
class HireConfirmationNotification extends Notification implements ShouldQueue
|
|
{
|
|
use Queueable;
|
|
|
|
public $jobTitle;
|
|
public $workerName;
|
|
public $daysRemaining;
|
|
public $reminderLevel;
|
|
public $applicationId;
|
|
|
|
/**
|
|
* Create a new notification instance.
|
|
*/
|
|
public function __construct($jobTitle, $workerName, $daysRemaining, $reminderLevel, $applicationId)
|
|
{
|
|
$this->jobTitle = $jobTitle;
|
|
$this->workerName = $workerName;
|
|
$this->daysRemaining = $daysRemaining;
|
|
$this->reminderLevel = $reminderLevel;
|
|
$this->applicationId = $applicationId;
|
|
}
|
|
|
|
/**
|
|
* Get the notification's delivery channels.
|
|
*/
|
|
public function via($notifiable): array
|
|
{
|
|
$channels = ['database'];
|
|
|
|
$emailEnabled = true;
|
|
if (method_exists($notifiable, 'employerProfile') && $notifiable->employerProfile) {
|
|
$emailEnabled = (bool) ($notifiable->employerProfile->email_notifications ?? true);
|
|
}
|
|
if ($emailEnabled && !empty($notifiable->email)) {
|
|
$channels[] = 'mail';
|
|
}
|
|
|
|
$pushEnabled = true;
|
|
if (method_exists($notifiable, 'employerProfile') && $notifiable->employerProfile) {
|
|
$pushEnabled = (bool) ($notifiable->employerProfile->push_notifications ?? true);
|
|
}
|
|
if ($pushEnabled && !empty($notifiable->fcm_token)) {
|
|
$channels[] = FcmChannel::class;
|
|
}
|
|
|
|
return $channels;
|
|
}
|
|
|
|
/**
|
|
* Get the mail representation of the notification.
|
|
*/
|
|
public function toMail($notifiable): MailMessage
|
|
{
|
|
$name = $notifiable->name ?? 'Employer';
|
|
return (new MailMessage)
|
|
->subject("Action Required: Confirm Hiring for {$this->jobTitle}")
|
|
->greeting("Hello {$name},")
|
|
->line("You selected {$this->workerName} for the job: {$this->jobTitle}.")
|
|
->line("Please confirm the hiring within {$this->daysRemaining} days before the job start date.")
|
|
->action('Confirm Hiring Now', url("/employer/candidates"))
|
|
->line('Thank you for using our application!');
|
|
}
|
|
|
|
/**
|
|
* Get the array representation of the notification for in-app storage.
|
|
*/
|
|
public function toArray($notifiable): array
|
|
{
|
|
return [
|
|
'title' => "Pending Hire Confirmation",
|
|
'body' => "Please confirm hiring {$this->workerName} for '{$this->jobTitle}' in {$this->daysRemaining} days.",
|
|
'job_title' => $this->jobTitle,
|
|
'worker_name' => $this->workerName,
|
|
'days_remaining' => $this->daysRemaining,
|
|
'reminder_level' => $this->reminderLevel,
|
|
'application_id' => $this->applicationId,
|
|
'type' => 'hire_confirmation',
|
|
];
|
|
}
|
|
|
|
/**
|
|
* Get the push notification representation.
|
|
*/
|
|
public function toFcm($notifiable): array
|
|
{
|
|
return [
|
|
'token' => $notifiable->fcm_token,
|
|
'title' => "Action Required: Confirm Hiring",
|
|
'body' => "Please confirm hiring {$this->workerName} for '{$this->jobTitle}' within {$this->daysRemaining} days.",
|
|
'data' => [
|
|
'type' => 'hire_confirmation',
|
|
'application_id' => $this->applicationId,
|
|
'days_remaining' => $this->daysRemaining,
|
|
],
|
|
];
|
|
}
|
|
}
|