metadata = $metadata; $this->serviceFactory = $serviceFactory; $this->user = $user; $this->log = $log; } public function getGroupedList(): StdClass { $data = $this->metadata->get(['app', 'popupNotifications']) ?? []; $data = array_filter($data, function ($item) { if (!($item['grouped'] ?? false)) { return false; } if (!($item['serviceName'] ?? null)) { return false; } if (!($item['methodName'] ?? null)) { return false; } $portalDisabled = $item['portalDisabled'] ?? false; if ($portalDisabled && $this->user->isPortal()) { return false; } return true; }); $result = (object) []; foreach ($data as $type => $item) { $serviceName = $item['serviceName']; $methodName = $item['methodName']; try { $service = $this->serviceFactory->create($serviceName); $result->$type = $service->$methodName($this->user->id); } catch (Throwable $e) { $this->log->error("Popup notifications: " . $e->getMessage()); } } return $result; } }