make sure notification always returns array
This commit is contained in:
parent
1921c3465d
commit
d3233740b3
@ -2,15 +2,15 @@
|
|||||||
|
|
||||||
namespace App\Http\Controllers\Common;
|
namespace App\Http\Controllers\Common;
|
||||||
|
|
||||||
use Date;
|
|
||||||
use App\Abstracts\Http\Controller;
|
use App\Abstracts\Http\Controller;
|
||||||
use App\Traits\Modules as RemoteModules;
|
|
||||||
use App\Http\Requests\Common\Notification as Request;
|
use App\Http\Requests\Common\Notification as Request;
|
||||||
|
use App\Traits\Modules;
|
||||||
|
use App\Utilities\Date;
|
||||||
use Illuminate\Support\Str;
|
use Illuminate\Support\Str;
|
||||||
|
|
||||||
class Notifications extends Controller
|
class Notifications extends Controller
|
||||||
{
|
{
|
||||||
use RemoteModules;
|
use Modules;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Display a listing of the resource.
|
* Display a listing of the resource.
|
||||||
@ -36,13 +36,17 @@ class Notifications extends Controller
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Hide New Apps Notifications
|
// Hide New Apps Notifications
|
||||||
$module_notifications = $this->getNotifications('new-apps' );
|
$module_notifications = $this->getNotifications('new-apps');
|
||||||
|
|
||||||
foreach ($module_notifications as $module_notification) {
|
foreach ($module_notifications as $module_notification) {
|
||||||
setting()->set('notifications.'. user()->id . '.' . $module_notification->alias . '.name', $module_notification->name);
|
$prefix = 'notifications.' . user()->id . '.' . $module_notification->alias;
|
||||||
setting()->set('notifications.'. user()->id . '.' . $module_notification->alias . '.message', $module_notification->alias);
|
|
||||||
setting()->set('notifications.'. user()->id . '.' . $module_notification->alias . '.date', Date::now());
|
setting()->set([
|
||||||
setting()->set('notifications.'. user()->id . '.' . $module_notification->alias . '.status', '0');
|
$prefix . '.name' => $module_notification->name,
|
||||||
|
$prefix . '.message' => $module_notification->alias,
|
||||||
|
$prefix . '.date' => Date::now(),
|
||||||
|
$prefix . '.status' => '0',
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
setting()->save();
|
setting()->save();
|
||||||
@ -68,17 +72,20 @@ class Notifications extends Controller
|
|||||||
|
|
||||||
$notifications = $this->getNotifications($path);
|
$notifications = $this->getNotifications($path);
|
||||||
|
|
||||||
if ($notifications) {
|
foreach ($notifications as $notification) {
|
||||||
foreach ($notifications as $notification) {
|
if ($notification->id == $id) {
|
||||||
if ($notification->id == $id) {
|
$prefix = 'notifications.' . $path . '.' . $id;
|
||||||
setting()->set('notifications.'. $path . '.' . $id . '.name', $notification->name);
|
|
||||||
setting()->set('notifications.'. $path . '.' . $id . '.message', $notification->message);
|
|
||||||
setting()->set('notifications.'. $path . '.' . $id . '.date', Date::now());
|
|
||||||
setting()->set('notifications.'. $path . '.' . $id . '.status', '0');
|
|
||||||
|
|
||||||
setting()->save();
|
setting()->set([
|
||||||
break;
|
$prefix . '.name' => $notification->name,
|
||||||
}
|
$prefix . '.message' => $notification->message,
|
||||||
|
$prefix . '.date' => Date::now(),
|
||||||
|
$prefix . '.status' => '0',
|
||||||
|
]);
|
||||||
|
|
||||||
|
setting()->save();
|
||||||
|
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
namespace App\Http\Livewire\Common\Notifications;
|
namespace App\Http\Livewire\Common\Notifications;
|
||||||
|
|
||||||
use Date;
|
|
||||||
use App\Traits\Modules;
|
use App\Traits\Modules;
|
||||||
|
use App\Utilities\Date;
|
||||||
use Livewire\Component;
|
use Livewire\Component;
|
||||||
|
|
||||||
class NewApps extends Component
|
class NewApps extends Component
|
||||||
@ -12,39 +12,46 @@ class NewApps extends Component
|
|||||||
|
|
||||||
public function markRead($alias)
|
public function markRead($alias)
|
||||||
{
|
{
|
||||||
$notifications = $this->getNotifications('new-apps' );
|
$notifications = $this->getNotifications('new-apps');
|
||||||
|
|
||||||
foreach ($notifications as $notification) {
|
foreach ($notifications as $notification) {
|
||||||
if ($notification->alias != $alias) {
|
if ($notification->alias != $alias) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
$readed = $notification;
|
$read = $notification;
|
||||||
}
|
}
|
||||||
|
|
||||||
setting()->set('notifications.'. user()->id . '.' . $alias . '.name', $readed->name);
|
$prefix = 'notifications.' . user()->id . '.' . $alias;
|
||||||
setting()->set('notifications.'. user()->id . '.' . $alias . '.message', $readed->alias);
|
|
||||||
setting()->set('notifications.'. user()->id . '.' . $alias . '.date', Date::now());
|
setting()->set([
|
||||||
setting()->set('notifications.'. user()->id . '.' . $alias . '.status', '0');
|
$prefix . '.name' => $read->name,
|
||||||
|
$prefix . '.message' => $read->alias,
|
||||||
|
$prefix . '.date' => Date::now(),
|
||||||
|
$prefix . '.status' => '0',
|
||||||
|
]);
|
||||||
|
|
||||||
setting()->save();
|
setting()->save();
|
||||||
|
|
||||||
$this->dispatchBrowserEvent('mark-read', [
|
$this->dispatchBrowserEvent('mark-read', [
|
||||||
'type' => 'new-apps',
|
'type' => 'new-apps',
|
||||||
'message' => trans('notifications.messages.mark_read', ['type' => $notification->name]),
|
'message' => trans('notifications.messages.mark_read', ['type' => $read->name]),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function markReadAll()
|
public function markReadAll()
|
||||||
{
|
{
|
||||||
$notifications = $this->getNotifications('new-apps' );
|
$notifications = $this->getNotifications('new-apps');
|
||||||
|
|
||||||
foreach ($notifications as $notification) {
|
foreach ($notifications as $notification) {
|
||||||
setting()->set('notifications.'. user()->id . '.' . $notification->alias . '.name', $notification->name);
|
$prefix = 'notifications.' . user()->id . '.' . $notification->alias;
|
||||||
setting()->set('notifications.'. user()->id . '.' . $notification->alias . '.message', $notification->alias);
|
|
||||||
setting()->set('notifications.'. user()->id . '.' . $notification->alias . '.date', Date::now());
|
|
||||||
setting()->set('notifications.'. user()->id . '.' . $notification->alias . '.status', '0');
|
|
||||||
|
|
||||||
|
setting()->set([
|
||||||
|
$prefix . '.name' => $notification->name,
|
||||||
|
$prefix . '.message' => $notification->alias,
|
||||||
|
$prefix . '.date' => Date::now(),
|
||||||
|
$prefix . '.status' => '0',
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
setting()->save();
|
setting()->save();
|
||||||
|
@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
namespace App\Http\ViewComposers;
|
namespace App\Http\ViewComposers;
|
||||||
|
|
||||||
use App\Utilities\Versions;
|
|
||||||
use App\Traits\Modules;
|
use App\Traits\Modules;
|
||||||
|
use App\Utilities\Versions;
|
||||||
use Illuminate\View\View;
|
use Illuminate\View\View;
|
||||||
|
|
||||||
class Header
|
class Header
|
||||||
@ -71,16 +71,14 @@ class Header
|
|||||||
|
|
||||||
$new_apps = $this->getNotifications('new-apps');
|
$new_apps = $this->getNotifications('new-apps');
|
||||||
|
|
||||||
if ($new_apps) {
|
foreach ($new_apps as $key => $new_app) {
|
||||||
foreach ($new_apps as $key => $new_app) {
|
if (setting('notifications.' . user()->id . '.' . $new_app->alias)) {
|
||||||
if (setting('notifications.' . user()->id . '.' . $new_app->alias)) {
|
unset($new_apps[$key]);
|
||||||
unset($new_apps[$key]);
|
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
}
|
|
||||||
|
|
||||||
$notifications++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$notifications++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
namespace App\Http\ViewComposers;
|
namespace App\Http\ViewComposers;
|
||||||
|
|
||||||
use App\Traits\Modules;
|
use App\Traits\Modules;
|
||||||
use Route;
|
use Illuminate\Support\Facades\Route;
|
||||||
use Illuminate\View\View;
|
use Illuminate\View\View;
|
||||||
|
|
||||||
class Notifications
|
class Notifications
|
||||||
@ -29,9 +29,7 @@ class Notifications
|
|||||||
|
|
||||||
$path = str_replace('{company_id}/', '', $path);
|
$path = str_replace('{company_id}/', '', $path);
|
||||||
|
|
||||||
if (!$notifications = $this->getNotifications($path)) {
|
$notifications = $this->getNotifications($path);
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Push to a stack
|
// Push to a stack
|
||||||
foreach ($notifications as $notification) {
|
foreach ($notifications as $notification) {
|
||||||
|
@ -396,7 +396,7 @@ trait Modules
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getNotifications($path)
|
public function getNotifications($path): array
|
||||||
{
|
{
|
||||||
$key = 'apps.notifications';
|
$key = 'apps.notifications';
|
||||||
|
|
||||||
@ -407,10 +407,10 @@ trait Modules
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!empty($data) && array_key_exists($path, $data)) {
|
if (!empty($data) && array_key_exists($path, $data)) {
|
||||||
return $data[$path];
|
return (array) $data[$path];
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getPageNumberOfModules($data = [])
|
public function getPageNumberOfModules($data = [])
|
||||||
|
Loading…
x
Reference in New Issue
Block a user