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
|
2020-04-26 06:07:27 -04:00
|
|
|
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);
|
2021-05-06 23:28:18 +03:00
|
|
|
$message = str_replace('#company_id#', company_id(), $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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|