akaunting/app/Http/Controllers/Common/Notifications.php

102 lines
2.7 KiB
PHP
Raw Normal View History

2018-11-17 13:13:15 +03:00
<?php
namespace App\Http\Controllers\Common;
2019-11-16 10:21:14 +03:00
use App\Abstracts\Http\Controller;
2018-11-17 13:13:15 +03:00
use App\Http\Requests\Common\Notification as Request;
use App\Traits\Modules;
use App\Utilities\Date;
use Illuminate\Support\Str;
2018-11-17 13:13:15 +03:00
class Notifications extends Controller
{
use Modules;
2018-11-17 13:13:15 +03:00
/**
* Display a listing of the resource.
*
* @return Response
*/
public function index()
{
2021-06-19 18:16:09 +03:00
return view('common.notifications.index');
2018-11-17 13:13:15 +03:00
}
/**
* Show the form for viewing the specified resource.
*
* @return Response
*/
2021-06-19 18:16:09 +03:00
public function readAll()
2018-11-17 13:13:15 +03:00
{
2021-06-19 18:16:09 +03:00
$notifications = user()->unreadNotifications;
foreach ($notifications as $notification) {
$notification->markAsRead();
}
2021-06-27 16:29:01 +03:00
// Hide New Apps Notifications
$module_notifications = $this->getNotifications('new-apps');
2021-06-27 16:29:01 +03:00
foreach ($module_notifications as $module_notification) {
$prefix = 'notifications.' . user()->id . '.' . $module_notification->alias;
setting()->set([
$prefix . '.name' => $module_notification->name,
$prefix . '.message' => $module_notification->alias,
$prefix . '.date' => Date::now(),
$prefix . '.status' => '0',
]);
2021-06-27 16:29:01 +03:00
}
setting()->save();
$message = trans('messages.success.clear_all', ['type' => Str::lower(trans_choice('general.notifications', 2))]);
2021-06-19 18:16:09 +03:00
flash($message)->success();
2018-11-17 13:13:15 +03:00
2021-06-19 18:16:09 +03:00
return redirect()->route('dashboard');
2018-11-17 13:13:15 +03:00
}
/**
* Disable the specified resource.
*
* @param Company $company
*
* @return Response
*/
public function disable(Request $request)
{
$id = $request['id'];
$path = str_replace('#', '/', $request['path']);
$notifications = $this->getNotifications($path);
foreach ($notifications as $notification) {
if ($notification->id == $id) {
$prefix = 'notifications.' . $path . '.' . $id;
setting()->set([
$prefix . '.name' => $notification->name,
$prefix . '.message' => $notification->message,
$prefix . '.date' => Date::now(),
$prefix . '.status' => '0',
]);
setting()->save();
break;
2018-11-17 13:13:15 +03:00
}
}
return response()->json([
2021-06-30 17:13:08 +03:00
'message' => trans('messages.success.disabled', [
'type' => Str::lower(trans_choice('general.notifications', 2))
]),
2018-11-17 13:13:15 +03:00
'success' => true,
'error' => false,
'data' => null,
]);
}
}