elektronika_bagisto/packages/Webkul/Notification/src/Http/Controllers/Admin/NotificationController.php

102 lines
2.5 KiB
PHP
Raw Normal View History

2021-12-30 13:30:13 +00:00
<?php
namespace Webkul\Notification\Http\Controllers\Admin;
use Illuminate\Routing\Controller;
use Webkul\Notification\Repositories\NotificationRepository;
class NotificationController extends Controller
{
/**
2022-03-31 11:28:52 +00:00
* Contains route related configuration.
2021-12-30 13:30:13 +00:00
*
* @var array
*/
protected $_config;
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct(protected NotificationRepository $notificationRepository)
2021-12-30 13:30:13 +00:00
{
$this->_config = request('_config');
}
/**
* Display a listing of the resource.
*
* @return \Illuminate\View\View
*/
public function index()
{
return view($this->_config['view']);
}
/**
* Display a listing of the resource.
*
* @return array
*/
public function getNotifications()
{
$params = request()->all();
2022-03-15 05:39:33 +00:00
if (isset($params['page'])) {
2021-12-30 13:30:13 +00:00
unset($params['page']);
2022-03-31 11:28:52 +00:00
}
2021-12-30 13:30:13 +00:00
2022-03-15 05:39:33 +00:00
if (count($params)) {
2021-12-30 13:30:13 +00:00
$searchResults = $this->notificationRepository->getParamsData($params);
2022-03-15 05:07:58 +00:00
} else {
2021-12-31 12:57:34 +00:00
$searchResults = $this->notificationRepository->with('order')->latest()->paginate(10);
2021-12-30 13:30:13 +00:00
}
return [
'search_results' => $searchResults,
2022-03-15 05:39:33 +00:00
'total_unread' => $this->notificationRepository->where('read', 0)->count(),
2021-12-30 13:30:13 +00:00
];
}
/**
2022-09-23 08:18:36 +00:00
* Update the notification is reade or not.
2021-12-30 13:30:13 +00:00
*
2022-03-31 11:28:52 +00:00
* @param int $orderId
2021-12-30 13:30:13 +00:00
* @return \Illuminate\View\View
*/
2022-03-15 05:07:58 +00:00
public function viewedNotifications($orderId)
{
if ($notification = $this->notificationRepository->where('order_id', $orderId)->first()) {
2021-12-30 13:30:13 +00:00
$notification->read = 1;
2022-03-15 05:39:33 +00:00
2021-12-30 13:30:13 +00:00
$notification->save();
2022-03-31 11:28:52 +00:00
return redirect()->route('admin.sales.orders.view', $orderId);
}
2021-12-30 13:30:13 +00:00
abort(404);
}
/**
2022-09-23 08:18:36 +00:00
* Update the notification is reade or not.
2021-12-30 13:30:13 +00:00
*
* @return array
*/
2022-03-15 05:07:58 +00:00
public function readAllNotifications()
{
$this->notificationRepository->where('read', 0)->update(['read' => 1]);
2021-12-30 13:30:13 +00:00
2022-09-23 08:18:36 +00:00
$searchResults = $this->notificationRepository->getParamsData([
2022-03-31 11:28:52 +00:00
'limit' => 5,
'read' => 0,
2022-09-23 08:18:36 +00:00
]);
2021-12-30 13:30:13 +00:00
return [
2022-03-15 05:07:58 +00:00
'search_results' => $searchResults,
'total_unread' => $this->notificationRepository->where('read', 0)->count(),
2022-03-31 11:28:52 +00:00
'success_message' => trans('admin::app.notification.notification-marked-success'),
2021-12-30 13:30:13 +00:00
];
}
}