111 lines
4.4 KiB
PHP
111 lines
4.4 KiB
PHP
<?php
|
|
|
|
namespace App\Jobs\Notifications\Shravak;
|
|
|
|
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 SendAcceptRelationRequest implements ShouldQueue
|
|
{
|
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels, PushNotificationTraits;
|
|
|
|
/**
|
|
* @var
|
|
*/
|
|
protected $loggedInUser;
|
|
|
|
/**
|
|
* @var
|
|
*/
|
|
protected $receiver;
|
|
|
|
/**
|
|
* @var
|
|
*/
|
|
protected $roleName;
|
|
|
|
/**
|
|
* @var
|
|
*/
|
|
protected $requestExist;
|
|
|
|
/**
|
|
*
|
|
*/
|
|
public function __construct($loggedInUser, $receiver, $requestExist)
|
|
{
|
|
$this->loggedInUser = $loggedInUser;
|
|
$this->receiver = $receiver;
|
|
$this->requestExist = $requestExist;
|
|
}
|
|
|
|
/**
|
|
* Execute the job.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function handle()
|
|
{
|
|
try {
|
|
//Push Notification to user when someone accepts friend request
|
|
$tokens = UserDeviceToken::where('user_id', $this->receiver->id)->get()->toArray();
|
|
$pushData = [];
|
|
$users = [];
|
|
|
|
if($tokens && $tokens > 0) {
|
|
foreach ($tokens as $token) {
|
|
$pushData['userToken'] = $token['token'] ?? [];
|
|
$pushData['title'] = trans('notifications.notification_title.relationship_request_accepted',['user' => $this->loggedInUser->name]);
|
|
$pushData['body'] = trans('notifications.push_relationship.accept_request',['user' => $this->loggedInUser->name]);
|
|
$pushData['image'] = ($this->loggedInUser->avatar) ? $this->loggedInUser->avatar : "";
|
|
$pushData['from_id'] = $this->loggedInUser->id;
|
|
$extraData = [];
|
|
$extraData['user_id'] = $this->loggedInUser->id ?? '';
|
|
$extraData['user_name'] = $this->loggedInUser->name ?? '';
|
|
$extraData['user_type'] = 'relationRequest';
|
|
$extraData['type'] = trans('notifications.relationship_notification_type.relationship-request-accepted');
|
|
$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
|
|
$notificationData = [];
|
|
$notificationData['body'] = trans('notifications.relationship.accept_request');
|
|
$notificationData['user_id'] = $this->receiver->id;
|
|
$notificationData['type'] = trans('notifications.relationship_notification_type.relationship-request-accepted');
|
|
$notificationData['title'] = trans('notifications.notification_title.relationship_request_accepted',['user' => $this->loggedInUser->name]);
|
|
$extraNotificationData = [];
|
|
$extraNotificationData['from_id'] = $this->loggedInUser->id ?? '';
|
|
$extraNotificationData['user_id'] = $this->loggedInUser->id ?? '';
|
|
$extraNotificationData['name'] = $this->loggedInUser->name ?? '';
|
|
$extraNotificationData['avatar'] = ($this->loggedInUser->avatar) ? $this->loggedInUser->avatar : "";
|
|
$extraNotificationData['relation'] = $this->requestExist->relation ?? '';
|
|
$extraNotificationData['relation_request_status'] = Constant::STATUS_ONE ?? '';
|
|
$extraNotificationData['notification_type'] = Constant::STATUS_TWO;
|
|
$extraNotificationData['user_type'] = 'shravak';
|
|
$extraNotificationData['created_at'] = date('Y/m/d H:i:s');
|
|
$notificationData['extraNotificationData'] = $extraNotificationData ?? [];
|
|
|
|
if (!in_array($this->receiver->id, $users)) {
|
|
$users[$this->receiver->id] = $this->receiver->id;
|
|
$this->storeNotification($notificationData);
|
|
//Unread count increament
|
|
unreadNotificationCounter($this->receiver->id);
|
|
}
|
|
|
|
} catch (\Exception $ex) {
|
|
Log::error($ex);
|
|
}
|
|
}
|
|
}
|