. * * The interactive user interfaces in modified source and object code versions * of this program must display Appropriate Legal Notices, as required under * Section 5 of the GNU Affero General Public License version 3. * * In accordance with Section 7(b) of the GNU Affero General Public License version 3, * these Appropriate Legal Notices must retain the display of the "EspoCRM" word. ************************************************************************/ namespace Espo\Tools\PopupNotification; use Espo\Core\InjectableFactory; use Espo\Core\Utils\Log; use Espo\Core\Utils\Metadata; use Espo\Entities\User; use Throwable; class Service { public function __construct( private Metadata $metadata, private User $user, private Log $log, private InjectableFactory $injectableFactory, ) {} /** * @return array Items grouped by type. */ public function getGrouped(): array { $data = $this->metadata->get(['app', 'popupNotifications']) ?? []; $data = array_filter($data, function ($item) { if (!($item['grouped'] ?? false)) { return false; } if ($item['disabled'] ?? false) { return false; } if (empty($item['providerClassName'])) { return false; } $portalDisabled = $item['portalDisabled'] ?? false; if ($portalDisabled && $this->user->isPortal()) { return false; } return true; }); $result = []; foreach ($data as $type => $item) { /** @var ?class-string $className */ $className = $item['providerClassName'] ?? null; if (!$className) { continue; } try { $provider = $this->injectableFactory->create($className); $result[$type] = $provider->get($this->user); } catch (Throwable $e) { $this->log->error("Popup notification error.", ['exception' => $e]); } } return $result; } }