# fluent-boards/trunk/app/Http/Controllers/NotificationController.php

FluentBoards – Project Management, Task Management, Goal Tracking, Kanban Board, and, Team Collaboration, version trunk. 119 lines.

- Page: https://pluginprobe.com/plugins/fluent-boards/trunk/code/app/Http/Controllers/NotificationController.php
- Raw: https://pluginprobe.com/plugins/fluent-boards/trunk/raw/app/Http/Controllers/NotificationController.php
- Modified: 2026-07-30T14:27:06+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/fluent-boards/trunk/code/app/Http/Controllers/NotificationController.php#L10-L20`.

```php
<?php

namespace FluentBoards\App\Http\Controllers;

use FluentBoards\App\Services\NotificationService;
use FluentBoards\Framework\Http\Request\Request;

class NotificationController extends Controller
{
    private $notificationService;

    public function __construct(NotificationService  $notificationService)
    {
        parent::__construct();
        $this->notificationService = $notificationService;
    }
    public function getAllNotifications(Request $request)
    {
        try {
            $per_page = $request->getSafe('per_page', 'intval', 20);
            $page = $request->getSafe('page', 'intval', 1);
            $action = $request->getSafe('action', 'sanitize_text_field', 'all');
            $data = $this->notificationService->getAllNotifications($per_page, $page, $action);

            return $this->sendSuccess($data, 200);
        } catch (\Exception $e) {
            return $this->sendError($e->getMessage(), 400);
        }
    }
    public function getAllUnreadNotifications(Request $request)
    {
        try {
            $per_page = $request->getSafe('per_page', 'intval', 20);
            $page = $request->getSafe('page', 'intval', 1);
            return $this->sendSuccess(
                $this->notificationService->getAllUnreadNotifications($per_page, $page),
                200);
        } catch (\Exception $e) {
            return $this->sendError($e->getMessage(), 400);
        }
    }

    public function newNotificationNumber()
    {
        try {
            $unread_notifications = $this->notificationService->newNotificationNumber();

            return $this->sendSuccess([
                'total_unread' => $unread_notifications,
            ], 200);
        } catch (\Exception $e) {
            return $this->sendError($e->getMessage(), 400);
        }
    }

    /**
     * Return the current user's board notification settings with safe defaults.
     */
    public function getBoardNotificationSettings($board_id)
    {
        $board_id = absint($board_id);
        try {
            $userId = get_current_user_id();
            $currentSettings = $this->notificationService->getBoardNotificationSettingsWithDefaults($board_id, $userId);

            return $this->sendSuccess([
                'currentSettings' => $currentSettings,
            ], 200);
        } catch (\Exception $e) {
            return $this->sendError($e->getMessage(), 400);
        }
    }

    public function updateBoardNotificationSettings(Request $request, $board_id)
    {
        $board_id = absint($board_id);
        try {
            // updatedSettings is an array, sanitize each element
            $rawSettings = $request->getSafe('updatedSettings');
            $newSettings = [];
            if (is_array($rawSettings)) {
                foreach ($rawSettings as $key => $value) {
                    // Sanitize key and value
                    $sanitizedKey = sanitize_text_field($key);
                    $sanitizedValue = sanitize_text_field($value);
                    $newSettings[$sanitizedKey] = $sanitizedValue;
                }
            }
            $this->notificationService->updateBoardNotificationSettings($newSettings, $board_id);
            return $this->sendSuccess([
                'message' => __('Board notification settings have been updated', 'fluent-boards'),
            ], 200);
        } catch (\Exception $e) {
            return $this->sendError($e->getMessage(), 400);
        }
    }

    public function readNotification(Request $request)
    {
        try {
            $notificationId = $request->getSafe('notification_id', 'intval');

            if ($notificationId) {
                $notification = $this->notificationService->markNotificationRead($notificationId);
            } else {
                $notification = $this->notificationService->markAllRead();
            }

            return $this->sendSuccess([
                'message' => __('Notification is updated', 'fluent-boards'),
                'notification' => $notification
            ], 200);

        } catch (\Exception $e) {
            return $this->sendError($e->getMessage(), 400);
        }
    }
}

```
