chg: [inbox:collectNotifications] Collect notifications for the logged in user
parent
42de70e87d
commit
74df550419
|
@ -16,6 +16,7 @@ class NotificationComponent extends Component
|
|||
public function initialize(array $config): void
|
||||
{
|
||||
$this->request = $config['request'];
|
||||
$this->Controller = $this->getController();
|
||||
}
|
||||
|
||||
public function getNotifications(): array
|
||||
|
@ -40,7 +41,7 @@ class NotificationComponent extends Component
|
|||
{
|
||||
$notifications = [];
|
||||
if (method_exists($table, 'collectNotifications')) {
|
||||
$notifications = $table->collectNotifications();
|
||||
$notifications = $table->collectNotifications($this->Controller->ACL->getUser());
|
||||
}
|
||||
return $notifications;
|
||||
}
|
||||
|
|
|
@ -92,11 +92,10 @@ class InboxTable extends AppTable
|
|||
return $savedEntry;
|
||||
}
|
||||
|
||||
public function collectNotifications(): array
|
||||
public function collectNotifications(\App\Model\Entity\User $user): array
|
||||
{
|
||||
$allNotifications = [];
|
||||
$query = $this->find();
|
||||
$inboxNotifications = $query->all()->toArray();
|
||||
$inboxNotifications = $this->getNotificationsForUser($user);
|
||||
foreach ($inboxNotifications as $notification) {
|
||||
$title = __('New message');
|
||||
$details = $notification->title;
|
||||
|
@ -116,4 +115,19 @@ class InboxTable extends AppTable
|
|||
}
|
||||
return $allNotifications;
|
||||
}
|
||||
|
||||
public function getNotificationsForUser(\App\Model\Entity\User $user): array
|
||||
{
|
||||
$query = $this->find();
|
||||
$conditions = [];
|
||||
if ($user['role']['perm_admin']) {
|
||||
// Admin will not see notifications if it doesn't belong to them. They can see process the message from the inbox
|
||||
$conditions['Inbox.user_id IS'] = null;
|
||||
} else {
|
||||
$conditions['Inbox.user_id'] = $user->id;
|
||||
}
|
||||
$query->where($conditions);
|
||||
$notifications = $query->all()->toArray();
|
||||
return $notifications;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue