where('createdFor', $request->header->account) ->where('seenAt', null) ->where('createdAt', $now, '<') // Don't show pre-created notifications ->sort('createdAt', OrderType::ASC) ->execute(); foreach ($notifications as $notification) { $new = clone $notification; $new->seenAt = $now; $this->updateModel($request->header->account, $notification, $new, NotificationMapper::class, 'notification', $request->getOrigin()); } $this->createStandardUpdateResponse($request, $response, []); } /** * Api method to create a task * * @param RequestAbstract $request Request * @param ResponseAbstract $response Response * @param array $data Generic data * * @return void * * @api * * @since 1.0.0 */ public function apiNotificationsGet(RequestAbstract $request, ResponseAbstract $response, array $data = []) : void { $now = new \DateTimeImmutable('now'); $notifications = NotificationMapper::getAll() ->where('createdFor', $request->header->account) ->where('seenAt', null) ->where('createdAt', $now, '<') // Don't show pre-created notifications ->where('createdAt', $request->getDataDateTime('start') ?? $now->modify('-1 hour'), '>') ->sort('createdAt', OrderType::ASC) ->execute(); $response->header->set('Content-Type', MimeType::M_JSON . '; charset=utf-8', true); $response->data[$request->uri->__toString()] = [ 'status' => NotificationLevel::OK, 'title' => 'New Notification', 'message' => 'You have new notifications', 'response' => $notifications, ]; } }