change
This commit is contained in:
@@ -3,13 +3,177 @@
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\NotificationDetails;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class ManageNotificationsController extends Controller
|
||||
{
|
||||
public function index(){
|
||||
|
||||
return view('Admin.pages.manage_notification.manage_notification');
|
||||
public function index(Request $request)
|
||||
{
|
||||
/**
|
||||
* Created By : Sayli Raut
|
||||
* Created at : 11 June 2024
|
||||
* Use : To list notifications.
|
||||
*/
|
||||
$activeQuery = $request->query('active');
|
||||
|
||||
if ($activeQuery == 4) { // for customer
|
||||
$notifications = NotificationDetails::with('Notification')
|
||||
->whereHas('Notification', function ($query) {
|
||||
$query->where('principal_type_xid', 3);
|
||||
})
|
||||
->latest()
|
||||
->take(12)
|
||||
->get();
|
||||
} else if ($activeQuery == 3) { // for restaurant
|
||||
$notifications = NotificationDetails::with('Notification')
|
||||
->whereHas('Notification', function ($query) {
|
||||
$query->where('principal_type_xid', 4);
|
||||
})
|
||||
->latest()
|
||||
->take(12)
|
||||
->get();
|
||||
|
||||
// return $notifications;
|
||||
} else {
|
||||
$notificationsOfType3 = NotificationDetails::with('Notification')
|
||||
->whereHas('Notification', function ($query) {
|
||||
$query->where('principal_type_xid', 3);
|
||||
})
|
||||
->latest()
|
||||
->take(12)
|
||||
->get();
|
||||
|
||||
$notificationsOfType4 = NotificationDetails::with('Notification')
|
||||
->whereHas('Notification', function ($query) {
|
||||
$query->where('principal_type_xid', 4);
|
||||
})
|
||||
->latest()
|
||||
->take(12)
|
||||
->get();
|
||||
|
||||
$notifications = $notificationsOfType3->merge($notificationsOfType4);
|
||||
}
|
||||
|
||||
return view('Admin.pages.manage_notification.manage_notification', compact('notifications'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Created By : Sayli Raut
|
||||
* Created at : 10 June 2024
|
||||
* Use : To view notification details.s
|
||||
*/
|
||||
public function add()
|
||||
{
|
||||
return view('Admin.pages.manage_notification.manage_notifications_add');
|
||||
}
|
||||
|
||||
/**
|
||||
* Created By : Sayli Raut
|
||||
* Created at : 10 June 2024
|
||||
* Use : To add notification .
|
||||
*/
|
||||
public function store_notificaton_data(Request $request)
|
||||
{
|
||||
try {
|
||||
$request->validate([
|
||||
'image' => 'required|image|mimes:jpeg,png,jpg,gif|max:2048',
|
||||
]);
|
||||
|
||||
DB::beginTransaction();
|
||||
|
||||
if (isset($request->image)) {
|
||||
$image = $request->image;
|
||||
$image_db = null;
|
||||
} else {
|
||||
$image = null;
|
||||
$image_db = $request->image;
|
||||
}
|
||||
$tnormalImage = saveSingleImageWithoutCrop($image, 'notification_images', $image_db);
|
||||
$imagePath = ListingImageUrl('notification_images', $tnormalImage);
|
||||
$allOrders = Order::pluck('iam_principal_xid');
|
||||
$passportId = $request->passport;
|
||||
$passportUserIds = OrderedPassport::where('passport_xid', $passportId)
|
||||
->whereHas('iamPrincipal', function ($query) {
|
||||
$query->where('notification_status', 1)
|
||||
->where('principal_type_xid', 3);
|
||||
})
|
||||
->pluck('iam_principal_xid');
|
||||
|
||||
$passportUserIdsToArray = $passportUserIds->toArray();
|
||||
|
||||
$allCustomerOneSignalIds = IamPrincipal::where('is_active', 1)
|
||||
->where('notification_status', 1)
|
||||
->where('principal_type_xid', 3)
|
||||
->pluck('id');
|
||||
|
||||
// Find the remaining user IDs
|
||||
$remainingUserIds = $allCustomerOneSignalIds->diff($allOrders);
|
||||
$remainingUserIdsArray = $remainingUserIds->toArray();
|
||||
|
||||
// Find the remaining user data
|
||||
$remainingUserData = IamPrincipal::whereIn('id', $remainingUserIdsArray)->get();
|
||||
$parchasePassportUserData = IamPrincipal::whereIn('id', $passportUserIdsToArray)->get();
|
||||
$title = $request->title;
|
||||
$message = $request->description;
|
||||
$content_type = 'Notification';
|
||||
$imageUrl = $imagePath;
|
||||
|
||||
// FOR all User
|
||||
if ($request->user_type == 1) {
|
||||
foreach ($remainingUserData as $customerIdItem) {
|
||||
if ($customerIdItem->one_signal_player_id) {
|
||||
onesignalhelper::sendNotificationApi(
|
||||
$customerIdItem->one_signal_player_id,
|
||||
$title,
|
||||
$message,
|
||||
$content_type,
|
||||
$imageUrl,
|
||||
$id = null
|
||||
);
|
||||
}
|
||||
onesignalhelper::StoreNotificationDetails($customerIdItem->id, $content_type, $title, $imagePath);
|
||||
}
|
||||
} elseif ($request->user_type == 2) {
|
||||
foreach ($parchasePassportUserData as $customerIdItem) {
|
||||
if ($customerIdItem->one_signal_player_id) {
|
||||
onesignalhelper::sendNotificationApi(
|
||||
$customerIdItem->one_signal_player_id,
|
||||
$title,
|
||||
$message,
|
||||
$content_type,
|
||||
$imageUrl,
|
||||
$id = null
|
||||
);
|
||||
}
|
||||
onesignalhelper::StoreNotificationDetails($customerIdItem->id, $content_type, $title, $imagePath);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// FOR All passport user
|
||||
|
||||
|
||||
|
||||
DB::commit();
|
||||
return jsonResponseWithSuccessMessage(__('success.save_data'));
|
||||
// return $voucher_data;
|
||||
} catch (Exception $e) {
|
||||
DB::rollBack();
|
||||
Log::error("Coupon Store Page Load Failed " . $e->getMessage());
|
||||
return jsonResponseWithErrorMessage(__('auth.something_went_wrong'), 500);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Created By : Sayli Raut
|
||||
* Created at : 10 June 2024
|
||||
* Use : To view notification details.s
|
||||
*/
|
||||
public function view($id)
|
||||
{
|
||||
$notification = NotificationDetails::with('notification')->findOrFail($id);
|
||||
return view('Admin.pages.manage_notification.manage_notifications_view', compact('notification'));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user