public function respondAction(
        int $id,
        string $response,
        AuthorizationCheckerInterface $auth
    ): Response {
        // Get the repo and lookup the invitation.
        $repo = $this->em->getRepository(Invitation::class);
        if (null === $invitation = $repo->findOneBy(['id' => $id])) {
            throw new NotFoundHttpException();
        }

        // Check that this user is allowed to respond.
        if (!$auth->isGranted('respond', $invitation)) {
            throw new AccessDeniedException();
        }

        // Record response.
        switch ($response) {
            case 'accept':
                $invitation->setResponse(Invitation::RESPONSE_ACCEPT);
                break;
            case 'maybe':
                $invitation->setResponse(Invitation::RESPONSE_MAYBE);
                break;
            case 'decline':
                $invitation->setResponse(Invitation::RESPONSE_DECLINE);
                break;
        }
        $this->em->flush();

        // Return empty json response (code 200).
        return new JsonResponse();
    }
public function respondAction(
        int $id,
        string $response,
        AuthorizationCheckerInterface $auth
    ): Response {
        // Get the repo and lookup the invitation.
        $repo = $this->em->getRepository(Invitation::class);
        if (null === $invitation = $repo->findOneBy(['id' => $id])) {
            throw new NotFoundHttpException();
        }

        // Check that this user is allowed to respond.
        if (!$auth->isGranted('respond', $invitation)) {
            throw new AccessDeniedException();
        }

        // Record response.
        switch ($response) {
            case 'accept':
                $invitation->setResponse(Invitation::RESPONSE_ACCEPT);
                break;
            case 'maybe':
                $invitation->setResponse(Invitation::RESPONSE_MAYBE);
                break;
            case 'decline':
                $invitation->setResponse(Invitation::RESPONSE_DECLINE);
                break;
        }
        $this->em->flush();

        // Return empty json response (code 200).
        return new JsonResponse();
    }
public function respondAction ( int $ id , string $ response , AuthorizationCheckerInterface $ auth ) : Response { // Get the repo and lookup the invitation. $ repo = $ this -> em -> getRepository ( Invitation :: class ) ; if ( null === $ invitation = $ repo -> findOneBy ( [ 'id' => $ id ] ) ) { throw new NotFoundHttpException ( ) ; } // Check that this user is allowed to respond. if ( ! $ auth -> isGranted ( 'respond' , $ invitation ) ) { throw new AccessDeniedException ( ) ; } // Record response. switch ( $ response ) { case 'accept' : $ invitation -> setResponse ( Invitation :: RESPONSE_ACCEPT ) ; break ; case 'maybe' : $ invitation -> setResponse ( Invitation :: RESPONSE_MAYBE ) ; break ; case 'decline' : $ invitation -> setResponse ( Invitation :: RESPONSE_DECLINE ) ; break ; } $ this -> em -> flush ( ) ; // Return empty json response (code 200). return new JsonResponse ( ) ; }
Respond to an individual invitation.

@param int                           $id       The id of the invitation.
@param string                        $response The response to the invitation.
@param AuthorizationCheckerInterface $auth     The authorization checker service.

@throws NotFoundHttpException When the invitation does not exist.
@throws AccessDeniedException When the user has no access to respond.

@return Response
Respond to an individual invitation .