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

95 lines
3.6 KiB
PHP

<?php
namespace App\Jobs\Notifications\Sangh;
use App\Constant\Constant;
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 SendApproveSangh implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels, PushNotificationTraits;
/**
* @var
*/
protected $sangh;
/**
* @var
*/
protected $user;
/**
*
*/
public function __construct($user, $sangh)
{
$this->user = $user;
$this->sangh = $sangh;
}
/**
* Execute the job.
*
* @return void
*/
public function handle()
{
try {
$tokens = UserDeviceToken::where('user_id', $this->sangh->updated_by)->get()->toArray();
$pushData = [];
$users = [];
if ($tokens && $tokens > 0) {
foreach ($tokens as $token) {
$pushData['userToken'] = $token['token'] ?? [];
$pushData['title'] = trans('notifications.notification_title.sangh_approved', ['sangh' => $this->sangh->name]);
$pushData['body'] = trans('notifications.sangh.sangh_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.sangh_notification_type.sangh-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 sangh
$notificationData = [];
$notificationData['body'] = trans('notifications.sangh.sangh_approved');
$notificationData['user_id'] = $this->sangh->updated_by;
$notificationData['type'] = trans('notifications.sangh_notification_type.sangh-approved');
$notificationData['title'] = trans('notifications.notification_title.sangh_approved', ['sangh' => $this->sangh->name]);
$extraNotificationData = [];
$extraNotificationData['sangh_id'] = $this->sangh->id ?? '';
$extraNotificationData['user_id'] = $this->user->id ?? '';
$extraNotificationData['name'] = $this->sangh->name ?? '';
$extraNotificationData['avatar'] = ($this->sangh->avatar) ? $this->sangh->avatar : "";
$extraNotificationData['user_type'] = 'sangh';
$extraNotificationData['created_at'] = date('Y/m/d H:i:s');
$notificationData['extraNotificationData'] = $extraNotificationData ?? [];
if (!in_array($this->sangh->updated_by, $users)) {
$users[$this->sangh->updated_by] = $this->sangh->updated_by;
$this->storeNotification($notificationData);
//Unread count increament
unreadNotificationCounter($this->sangh->updated_by);
}
} catch (\Exception $ex) {
Log::error($ex);
}
}
}