Files
Global-Jain/app/Jobs/Notifications/Sant/SendApproveSant.php
2025-11-05 10:37:10 +05:30

101 lines
3.7 KiB
PHP

<?php
namespace App\Jobs\Notifications\Sant;
use Illuminate\Bus\Queueable;
use App\Models\UserDeviceToken;
use Illuminate\Support\Facades\Log;
use App\Traits\PushNotificationTraits;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
class SendApproveSant implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels, PushNotificationTraits;
/**
* @var
*/
protected $sant;
/**
* @var
*/
protected $user;
/**
* @var
*/
protected $santMain;
/**
*
*/
public function __construct($user, $sant, $santMain)
{
$this->user = $user;
$this->sant = $sant;
$this->santMain = $santMain;
}
/**
* Execute the job.
*
* @return void
*/
public function handle()
{
try {
//Push Notification to shravak who added
$tokens = UserDeviceToken::where('user_id', $this->sant->updated_by)->get()->toArray();
$pushData = [];
$users = [];
if ($tokens && $tokens > 0) {
foreach ($tokens as $token) {
$pushData['userToken'] = $token['token'] ?? [];
$pushData['title'] = trans('notifications.notification_title.sant_approved',['sant' => $this->santMain->name]);
$pushData['body'] = trans('notifications.sant.sant_approved');
$pushData['image'] = ($this->user->avatar) ? $this->user->avatar : "";
$pushData['from_id'] = $this->user->id;
$extraData = [];
$extraData['user_id'] = $this->user->id ?? '';
$extraData['user_name'] = $this->user->name ?? '';
$extraData['type'] = trans('notifications.sant_notification_type.sant-approved');
$extraData['created_at'] = date('Y/m/d H:i:s');
$extraData['os'] = $token['os'] ? getPlatform($token['os']) : [];
$pushData['extraData'] = $extraData ?? [];
$this->pushNotification($pushData, $extraData);
}
}
//Store notification for approved sant
$notificationData = [];
$notificationData['body'] = trans('notifications.sant.sant_approved');
$notificationData['user_id'] = $this->santMain->updated_by;
$notificationData['type'] = trans('notifications.sant_notification_type.sant-approved');
$notificationData['title'] = trans('notifications.notification_title.sant_approved',['sant' => $this->santMain->name]);
$extraNotificationData = [];
$extraNotificationData['from_id'] = $this->santMain->id ?? '';
$extraNotificationData['user_id'] = $this->user->id ?? '';
$extraNotificationData['name'] = $this->santMain->name ?? '';
$extraNotificationData['avatar'] = ($this->santMain->avatar) ? $this->santMain->avatar : "";
$extraNotificationData['user_type'] = 'sant';
$extraNotificationData['created_at'] = date('Y/m/d H:i:s');
$notificationData['extraNotificationData'] = $extraNotificationData ?? [];
if (!in_array($this->santMain->updated_by, $users)) {
$users[$this->santMain->updated_by] = $this->santMain->updated_by;
$this->storeNotification($notificationData);
//Unread count increament
unreadNotificationCounter($this->santMain->updated_by);
}
} catch (\Exception $ex) {
Log::error($ex);
}
}
}