akaunting/app/Http/ViewComposers/Notifications.php

52 lines
1.3 KiB
PHP
Raw Normal View History

2018-11-16 18:33:39 +03:00
<?php
namespace App\Http\ViewComposers;
2020-07-13 15:16:56 +03:00
use App\Traits\Modules;
2018-11-16 18:33:39 +03:00
use Route;
use Illuminate\View\View;
class Notifications
{
2020-07-13 15:16:56 +03:00
use Modules;
2018-11-16 18:33:39 +03:00
/**
* Bind data to the view.
*
* @param View $view
* @return void
*/
public function compose(View $view)
{
// No need to add suggestions in console
if (app()->runningInConsole() || !config('app.installed') || !user()) {
2018-11-16 18:33:39 +03:00
return;
}
2020-07-13 15:16:56 +03:00
if (!$path = Route::current()->uri()) {
2018-11-16 18:33:39 +03:00
return;
}
2021-04-16 00:59:43 +03:00
$path = str_replace('{company_id}/', '', $path);
2020-07-13 15:16:56 +03:00
if (!$notifications = $this->getNotifications($path)) {
2018-11-16 18:33:39 +03:00
return;
}
// Push to a stack
foreach ($notifications as $notification) {
2018-11-17 13:13:15 +03:00
$path = str_replace('/', '#', $notification->path);
$message = str_replace('#path#', $path, $notification->message);
$message = str_replace('#token#', csrf_token(), $message);
2020-08-11 16:52:10 +03:00
$message = str_replace('#url#', route('dashboard'), $message);
2018-11-17 13:13:15 +03:00
2020-07-13 15:16:56 +03:00
if (!setting('notifications.' . $notification->path . '.' . $notification->id . '.status', 1)) {
continue;
2018-11-17 13:13:15 +03:00
}
2020-07-13 15:16:56 +03:00
$view->getFactory()->startPush('content_content_start', $message);
2018-11-16 18:33:39 +03:00
}
}
}