notificationRepository = $notificationRepository; } /** * Get all notifications from the repository. * * @return array|null */ public function getAllNotifications(): ?array { return $this->notificationRepository->getAll(); } /** * Create a new notification. * * @param Notification $notificationData * * @return int Notification ID */ public function createNotification(Notification $notificationData): int { // Create notification via repository and return new notification ID return $this->notificationRepository->add($notificationData); } /** * Get a specific notification by its ID. * * @param int $notificationId * * @return object NotificationEntity * * @throws NotFoundException If the notification is not found */ public function getNotificationById(int $notificationId): object { $notification = $this->notificationRepository->getById($notificationId); if (!$notification) { throw new NotFoundException( BackendStrings::getExceptionStrings()['notification_not_found'] ); } return $notification; } /** * Update an existing notification. * * @param int $notificationId * @param Notification $notificationData * * @return bool */ public function updateNotification(int $notificationId, Notification $notificationData): bool { // Validate notification data before updating return $this->notificationRepository->update($notificationId, $notificationData); } /** * Delete a notification by its ID. * * @param int $notificationId * * @return int */ public function deleteNotification(int $notificationId): int { return $this->notificationRepository->delete($notificationId); } /** * Get notifications by form ID. * * @param int $formId * * @return array * * @throws NotFoundException If no notifications are found */ public function getNotificationsByFormId(int $formId): array { $notification = $this->notificationRepository->getAllById($formId); if (!$notification) { throw new NotFoundException( BackendStrings::getExceptionStrings()['notification_not_found'] ); } return $notification; } /** * Get active notifications by form ID. * * @param int $formId * * @return array * * @throws NotFoundException If no active notifications are found */ public function getActiveNotificationsByFormId(int $formId): array { $notification = $this->notificationRepository->getAllActiveById($formId); if (!$notification) { throw new NotFoundException( BackendStrings::getExceptionStrings()['active_notif_not_found'] ); } return $notification; } /** * * Delete notifications by form ID. * * @throws NotFoundException */ public function deleteNotificationsByFormId(int $formId): void { $notifications = $this->getNotificationsByFormId($formId); if (!$notifications) { return; } foreach ($notifications as $notification) { $this->deleteNotification($notification->getId()); } } /** * Duplicate notifications from one form to another. * * @param int $originalFormId * @param int $newFormId * * @return void * @throws NotFoundException * @throws InvalidArgumentException */ public function duplicateNotifications(int $originalFormId, int $newFormId): void { $notifications = $this->getNotificationsByFormId($originalFormId); foreach ($notifications as $notification) { $notificationData = $notification->toArray(); unset($notificationData['id']); $notificationData['formId'] = $newFormId; $this->createNotification(NotificationFactory::create($notificationData)); } } /** * Search notifications with pagination and sorting * * @param array $params * * @return array */ public function searchNotifications(array $params): array { return $this->notificationRepository->search($params); } }