api code global jain
This commit is contained in:
106
app/Jobs/Notifications/Sangh/SendAdminRemoveMember.php
Normal file
106
app/Jobs/Notifications/Sangh/SendAdminRemoveMember.php
Normal file
@@ -0,0 +1,106 @@
|
||||
<?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 SendAdminRemoveMember implements ShouldQueue
|
||||
{
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels, PushNotificationTraits;
|
||||
|
||||
/**
|
||||
* @var
|
||||
*/
|
||||
protected $userId;
|
||||
|
||||
/**
|
||||
* @var
|
||||
*/
|
||||
protected $sangh;
|
||||
|
||||
/**
|
||||
* @var
|
||||
*/
|
||||
protected $roleName;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function __construct($userId, $sangh, $roleName)
|
||||
{
|
||||
$this->userId = $userId;
|
||||
$this->sangh = $sangh;
|
||||
$this->roleName = $roleName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the job.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
try {
|
||||
//Push Notification to user when admin removes from sangh
|
||||
$tokens = UserDeviceToken::where('user_id', $this->userId)->get()->toArray();
|
||||
$pushData = [];
|
||||
$users = [];
|
||||
|
||||
if($tokens && $tokens > 0) {
|
||||
foreach ($tokens as $token) {
|
||||
$pushData['userToken'] = $token['token'] ?? [];
|
||||
$pushData['title'] = trans('notifications.notification_title.admin_removed_sangh_member', ['sangh' => $this->sangh->name]);
|
||||
$pushData['body'] = trans('notifications.push_sangh.admin_remove_member', ['sangh' => $this->sangh->name]);
|
||||
$pushData['image'] = ($this->sangh->avatar) ? $this->sangh->avatar : "";
|
||||
$pushData['from_id'] = $this->sangh->id;
|
||||
$extraData = [];
|
||||
$extraData['user_id'] = $this->sangh->id ?? '';
|
||||
$extraData['user_name'] = $this->sangh->name ?? '';
|
||||
$extraData['user_type'] = 'sangh';
|
||||
$extraData['type'] = trans('notifications.sangh_notification_type.admin-removed-member');
|
||||
$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.sangh.admin_remove_member', ['sangh' => $this->sangh->name]);
|
||||
$notificationData['user_id'] = $this->userId;
|
||||
$notificationData['type'] = trans('notifications.sangh_notification_type.admin-removed-member');
|
||||
$notificationData['title'] = trans('notifications.notification_title.admin_removed_sangh_member', ['sangh' => $this->sangh->name]);
|
||||
$extraNotificationData = [];
|
||||
$extraNotificationData['from_id'] = $this->sangh->id ?? '';
|
||||
$extraNotificationData['user_id'] = $this->sangh->id ?? '';
|
||||
$extraNotificationData['name'] = $this->sangh->name ?? '';
|
||||
$extraNotificationData['avatar'] = ($this->sangh->avatar) ? $this->sangh->avatar : "";
|
||||
$extraNotificationData['sangh_id'] = $this->sangh->id ?? '';
|
||||
$extraNotificationData['sangh_name'] = $this->sangh->name ?? '';
|
||||
$extraNotificationData['role'] = $roleName ?? '';
|
||||
$extraNotificationData['notification_type'] = Constant::STATUS_TWO;
|
||||
$extraNotificationData['user_type'] = 'sangh';
|
||||
$extraNotificationData['created_at'] = date('Y/m/d H:i:s');
|
||||
$notificationData['extraNotificationData'] = $extraNotificationData ?? [];
|
||||
|
||||
if (!in_array($this->userId, $users)) {
|
||||
$users[$this->userId] = $this->userId;
|
||||
$this->storeNotification($notificationData);
|
||||
//Unread notification count increament
|
||||
unreadNotificationCounter($this->userId);
|
||||
}
|
||||
|
||||
} catch (\Exception $ex) {
|
||||
Log::error($ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user