* * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. */ /** * \file globalnotify/class/actions_globalnotify.class.php * \ingroup globalnotify * \brief Hook class for displaying notifications in top bar */ require_once DOL_DOCUMENT_ROOT.'/core/class/commonhookactions.class.php'; dol_include_once('/globalnotify/class/globalnotify.class.php'); /** * Class ActionsGlobalNotify * Hook actions for GlobalNotify module */ class ActionsGlobalNotify extends CommonHookActions { /** * @var DoliDB Database handler */ public $db; /** * @var string Error message */ public $error = ''; /** * @var array Error messages */ public $errors = array(); /** * @var array Results */ public $results = array(); /** * @var string Returned string */ public $resprints = ''; /** * Constructor * * @param DoliDB $db Database handler */ public function __construct($db) { $this->db = $db; } /** * Hook to add floating notification widget * * @param array $parameters Parameters * @param object $object Object * @param string $action Action * @return int 0=OK, >0=KO */ public function printTopRightMenu($parameters, &$object, &$action) { global $conf, $user, $langs; if (!$user->admin) { return 0; // Only show to admins } $langs->load('globalnotify@globalnotify'); $notify = new GlobalNotify($this->db); $unreadNotifications = $notify->getAllNotifications($user->id, true); $readNotifications = $notify->getReadNotifications($user->id, 20); $unreadCount = count($unreadNotifications); $readCount = count($readNotifications); $totalCount = $unreadCount + $readCount; // Check for urgent notifications $hasUrgent = false; foreach ($unreadNotifications as $n) { if (in_array($n['type'], array('error', 'action'))) { $hasUrgent = true; break; } } // Build floating widget HTML $html = ''; // Floating button (always visible, bottom-left corner) $html .= '
'; // widget $this->resprints = $html; return 0; } /** * Render a single notification item * * @param array $notif Notification data * @param bool $isRead Is this a read notification * @return string HTML */ private function renderNotificationItem($notif, $isRead = false) { $typeClass = 'globalnotify-item globalnotify-item-'.$notif['type']; if ($isRead) { $typeClass .= ' globalnotify-item-read'; } $html = '