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

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

- Page: https://pluginprobe.com/plugins/fluent-boards/1.13/code/app/Http/Controllers/NotificationController.php
- Raw: https://pluginprobe.com/plugins/fluent-boards/1.13/raw/app/Http/Controllers/NotificationController.php
- Modified: 2024-05-31T06:41:46+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/1.13/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)
    {
        $data = $request->all();
        try {
            $per_page = isset($data['per_page']) ? $data['per_page'] : 20;
            $page = isset($data['page']) ? $data['page'] : 1;
            $data = $this->notificationService->getAllNotifications($per_page, $page);

            return $this->sendSuccess($data, 200);
        } catch (\Exception $e) {
            return $this->sendError($e->getMessage(), 404);
        }
    }
    public function getAllUnreadNotifications(Request $request)
    {
        $data = $request->all();
        try {
            $per_page = isset($data['per_page']) ? $data['per_page'] : 20;
            $page = isset($data['page']) ? $data['page'] : 1;
            return $this->sendSuccess(
                $this->notificationService->getAllUnreadNotifications($per_page, $page),
                200);
        } catch (\Exception $e) {
            return $this->sendError($e->getMessage(), 404);
        }
    }

    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(), 404);
        }
    }

    public function getBoardNotificationSettings($board_id)
    {
        try {
            $userId = get_current_user_id();
            $boardSettings = $this->notificationService->getBoardNotificationSettingsOfUser($board_id, $userId);
            if ($boardSettings->preferences)
                $currentSettings = maybe_unserialize($boardSettings->preferences);

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

    public function updateBoardNotificationSettings(Request $request, $board_id)
    {
        try {
            $newSettings = $request->getSafe('updatedSettings');


            $this->notificationService->updateBoardNotificationSettings($newSettings, $board_id);
            return $this->sendSuccess([
                'message' => __('Board notification settings has been updated', 'fluent-boards'),
            ], 200);
        } catch (\Exception $e) {
            return $this->sendError($e->getMessage(), 404);
        }
    }

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

            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(), 404);
        }
    }
}
```
