v1.0
Docs / Notifications

Notification System

The system features a multi-channel notification architecture that supports real-time alerts, email delivery, and persistent database storage.


1. Architecture

Sender (Controller/Service) │ ▼ NotificationService::send() │ ├─→ Database Channel (Persist to DB) ├─→ Email Channel (Send via SMTP) └─→ Real-time (via Polling/WebSocket)

Key Components


2. Sending Notifications

Via Service

$service = service('notification');

$service->send(
    'New Order Received',           // Title
    'Order #1234 has been placed.', // Message
    'order_created',               // Type/Event
    $userId,                       // Recipient ID
    null,                          // Related Entity ID (optional)
    'orders'                       // Related Entity Type (optional)
);

With Media Attachments

$service->send(
    'Proof of Delivery',
    'Here is the photo.',
    'delivery',
    $userId,
    null,
    null,
    $imagePath,  // Image URL/Path
    $filePath    // File URL/Path
);
$filePath // File URL/Path );

3. Export Functionality

Service Layer

The NotificationService handles exporting notifications to Excel and PDF formats.

$service = service('notification');

// Returns keys: content, filename, mime
$file = $service->exportNotifications($userId, $roleIds, 'excel'); // or 'pdf'

UI Integration

Exports are handled via Client-Side Download to ensure robust file handling.

<!-- Export Button -->
<?= component('button', [
    'onclick' => "downloadExport('/admin/notifications/export/excel')",
    'label' => 'Excel',
    'class' => 'btn btn-outline-success btn-sm',
    'icon' => 'fas fa-file-excel'
]) ?>

3. Client-Side Integration

Notification Bell

The notification bell in the topbar automatically updates when new notifications arrive.

<!-- Renders the notification bell icon with unread count -->
<?= ajax_component('notification_bell', [], true, 'bell-1', 30000) ?>

Polling Script

Located in public/assets/js/components/notification-polling.js.

ESC

Start typing to search the documentation