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
|
|
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* Contains route related configuration
|
|
|
|
|
*
|
|
|
|
|
* @var array
|
|
|
|
|
*/
|
|
|
|
|
protected $_config;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* NotificationRepository
|
|
|
|
|
*
|
|
|
|
|
* @var object
|
|
|
|
|
*/
|
|
|
|
|
protected $notificationRepository;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Create a new controller instance.
|
|
|
|
|
*
|
|
|
|
|
* @return void
|
|
|
|
|
*/
|
|
|
|
|
public function __construct(NotificationRepository $notificationRepository)
|
|
|
|
|
{
|
|
|
|
|
$this->notificationRepository = $notificationRepository;
|
|
|
|
|
|
|
|
|
|
$this->middleware('admin');
|
|
|
|
|
|
|
|
|
|
$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:07:58 +00:00
|
|
|
if (isset($params) && isset($params['page'])) {
|
2021-12-30 13:30:13 +00:00
|
|
|
unset($params['page']);
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-15 05:07:58 +00:00
|
|
|
if (isset($params) && $params != NULL) {
|
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:07:58 +00:00
|
|
|
'total_unread' => $this->notificationRepository->where('read', 0)->count()
|
2021-12-30 13:30:13 +00:00
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Update the notification is readed or not
|
|
|
|
|
*
|
|
|
|
|
* @return \Illuminate\View\View
|
|
|
|
|
*/
|
2022-03-15 05:07:58 +00:00
|
|
|
public function viewedNotifications($orderId)
|
|
|
|
|
{
|
2021-12-30 13:30:13 +00:00
|
|
|
|
2022-03-15 05:07:58 +00:00
|
|
|
if ($notification = $this->notificationRepository->where('order_id', $orderId)->first()) {
|
2021-12-30 13:30:13 +00:00
|
|
|
$notification->read = 1;
|
2022-03-15 05:07:58 +00:00
|
|
|
|
2021-12-30 13:30:13 +00:00
|
|
|
$notification->save();
|
|
|
|
|
|
|
|
|
|
return redirect()->route('admin.sales.orders.view',$orderId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
abort(404);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Update the notification is readed or not
|
|
|
|
|
*
|
|
|
|
|
* @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
|
|
|
|
|
|
|
|
$params = [
|
|
|
|
|
"limit" => 5,
|
2022-03-15 05:07:58 +00:00
|
|
|
"read" => 0
|
2021-12-30 13:30:13 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
|
|
$searchResults = $this->notificationRepository->getParamsData($params);
|
|
|
|
|
|
|
|
|
|
return [
|
2022-03-15 05:07:58 +00:00
|
|
|
'search_results' => $searchResults,
|
|
|
|
|
'total_unread' => $this->notificationRepository->where('read', 0)->count(),
|
2021-12-30 13:30:13 +00:00
|
|
|
'success_message' => trans('admin::app.notification.notification-marked-success')
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
abort(404);
|
|
|
|
|
}
|
|
|
|
|
}
|