Files
Global-Jain/app/Jobs/Notifications/Chaturmas/SendRejectChaturmas.php

96 lines
3.6 KiB
PHP
Raw Normal View History

2025-11-05 10:37:10 +05:30
<?php
namespace App\Jobs\Notifications\Chaturmas;
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 SendRejectChaturmas implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels, PushNotificationTraits;
/**
* @var
*/
protected $sant;
/**
* @var
*/
protected $user;
/**
*
*/
public function __construct($sant, $user)
{
$this->sant = $sant;
$this->user = $user;
}
/**
* Execute the job.
*
* @return void
*/
public function handle()
{
try {
//Push Notification to shravak who added
$tokens = UserDeviceToken::where('user_id', $this->user->id)->get()->toArray();
$data = [];
$users = [];
if($tokens && $tokens > 0) {
foreach ($tokens as $token) {
$data['userToken'] = $token['token'] ?? [];
$data['title'] = trans('notifications.notification_title.chaturmas_rejected',['sant' => $this->sant->name]);
$data['body'] = trans('notifications.sant.chaturmas_rejected');
$data['image'] = ($this->sant->avatar) ? $this->sant->avatar : "";
$data['from_id'] = $this->sant->id;
$extraData = [];
$extraData['user_id'] = $this->user->id ?? '';
$extraData['user_name'] = $this->user->name ?? '';
$extraData['user_type'] = 'sant';
$extraData['type'] = trans('notifications.sant_notification_type.chaturmas-rejected');
$extraData['created_at'] = date('Y/m/d H:i:s');
$extraData['os'] = $token['os'] ? getPlatform($token['os']) : [];
$data['extraData'] = $extraData ?? [];
$this->pushNotification($data, $extraData);
}
}
//Store notification for reject chaturmas
$notificationData = [];
$notificationData['body'] = trans('notifications.sant.chaturmas_rejected');
$notificationData['user_id'] = $this->user->id;
$notificationData['type'] = trans('notifications.sant_notification_type.chaturmas-rejected');
$notificationData['title'] = trans('notifications.notification_title.chaturmas_rejected',['sant' => $this->sant->name]);
$extraNotificationData = [];
$extraNotificationData['from_id'] = $this->sant->id ?? '';
$extraNotificationData['user_id'] = $this->user->id ?? '';
$extraNotificationData['name'] = $this->sant->name ?? '';
$extraNotificationData['avatar'] = ($this->sant->avatar) ? $this->sant->avatar : "";
$extraNotificationData['user_type'] = 'sant';
$extraNotificationData['created_at'] = date('Y/m/d H:i:s');
$notificationData['extraNotificationData'] = $extraNotificationData ?? [];
if (!in_array($this->user->id, $users)) {
$users[$this->user->id] = $this->user->id;
$this->storeNotification($notificationData);
//Unread count increament
unreadNotificationCounter($this->user->id);
}
} catch (\Exception $ex) {
Log::error($ex);
}
}
}