return JsonView::render(array('message' => 'Message not found.')); } JsonView::render($message); }); $app->map("/{$v}/messages/rows/:id/?", function ($id) use($params, $requestPayload, $app, $acl, $ZendDb) { $currentUser = Auth::getUserInfo(); $messagesTableGateway = new DirectusMessagesTableGateway($acl, $ZendDb); $messagesRecipientsTableGateway = new DirectusMessagesRecipientsTableGateway($acl, $ZendDb); $message = $messagesTableGateway->fetchMessageWithRecipients($id, $currentUser['id']); $ids = array($message['id']); $message['read'] = '1'; foreach ($message['responses']['rows'] as &$response) { $ids[] = $response['id']; $response['read'] = "1"; } $messagesRecipientsTableGateway->markAsRead($ids, $currentUser['id']); JsonView::render($message); })->via('PATCH'); $app->post("/{$v}/messages/rows/?", function () use($params, $requestPayload, $app, $acl, $ZendDb) { $currentUser = Auth::getUserInfo(); // Unpack recipients $recipients = explode(',', $requestPayload['recipients']); $groupRecipients = array(); $userRecipients = array(); foreach ($recipients as $recipient) { $typeAndId = explode('_', $recipient); if ($typeAndId[0] == 0) { $userRecipients[] = $typeAndId[1]; } else { $groupRecipients[] = $typeAndId[1]; }