public function createAction(
        string $production_slug,
        AuthorizationCheckerInterface $auth,
        TokenStorageInterface $token_storage,
        Request $request
    ): Response {
        // Lookup the production by production_slug.
        $production_repo = $this->em->getRepository(Production::class);
        if (null === $production = $production_repo->findOneBy(['slug' => $production_slug])) {
            throw new NotFoundHttpException();
        }

        // Check permissions for this action.
        if (!$auth->isGranted('GROUP_ROLE_EDITOR', $production)) {
            throw new AccessDeniedException();
        }

        // Create a new event with author and production.
        $user = $token_storage->getToken()->getUser();
        $event = new Event();
        $event->addGroup($production);
        $event->setAuthor($user->getUsername());
        $event->setActive(true);

        // Create a new invitation for the current user.
        $invitation = new Invitation();
        $invitation->setInvitee($user->getUsername());
        $event->addInvitation($invitation);

        // Set start and end times using closest 1 hour intervals.
        $start = new \DateTime();
        $start->modify('+1 hour');
        $start->modify('-' . $start->format('i') . ' minutes');
        $event->setStart($start);

        $end = new \DateTime('+1 hour');
        $end->modify('+1 hour');
        $end->modify('-' . $end->format('i') . ' minutes');
        $event->setEnd($end);

        // Create and handle the form.
        $form = $this->form->create(EventType::class, $event);
        $form->handleRequest($request);

        // If the form is submitted and valid persist the event.
        if ($form->isSubmitted() && $form->isValid()) {
            $this->em->persist($event);
            $this->em->flush();

            // Set success message and redirect.
            $this->session->getFlashBag()->add(
                'success',
                $this->translator->trans('event.created', [
                    '%event%' => $event->getName(),
                ], BkstgScheduleBundle::TRANSLATION_DOMAIN)
            );

            return new RedirectResponse($this->url_generator->generate(
                'bkstg_event_read',
                ['id' => $event->getId(), 'production_slug' => $production->getSlug()]
            ));
        }

        // Render the form.
        return new Response($this->templating->render('@BkstgSchedule/Event/create.html.twig', [
            'form' => $form->createView(),
            'production' => $production,
        ]));
    }
public function createAction(
        string $production_slug,
        AuthorizationCheckerInterface $auth,
        TokenStorageInterface $token_storage,
        Request $request
    ): Response {
        // Lookup the production by production_slug.
        $production_repo = $this->em->getRepository(Production::class);
        if (null === $production = $production_repo->findOneBy(['slug' => $production_slug])) {
            throw new NotFoundHttpException();
        }

        // Check permissions for this action.
        if (!$auth->isGranted('GROUP_ROLE_EDITOR', $production)) {
            throw new AccessDeniedException();
        }

        // Create a new event with author and production.
        $user = $token_storage->getToken()->getUser();
        $event = new Event();
        $event->addGroup($production);
        $event->setAuthor($user->getUsername());
        $event->setActive(true);

        // Create a new invitation for the current user.
        $invitation = new Invitation();
        $invitation->setInvitee($user->getUsername());
        $event->addInvitation($invitation);

        // Set start and end times using closest 1 hour intervals.
        $start = new \DateTime();
        $start->modify('+1 hour');
        $start->modify('-' . $start->format('i') . ' minutes');
        $event->setStart($start);

        $end = new \DateTime('+1 hour');
        $end->modify('+1 hour');
        $end->modify('-' . $end->format('i') . ' minutes');
        $event->setEnd($end);

        // Create and handle the form.
        $form = $this->form->create(EventType::class, $event);
        $form->handleRequest($request);

        // If the form is submitted and valid persist the event.
        if ($form->isSubmitted() && $form->isValid()) {
            $this->em->persist($event);
            $this->em->flush();

            // Set success message and redirect.
            $this->session->getFlashBag()->add(
                'success',
                $this->translator->trans('event.created', [
                    '%event%' => $event->getName(),
                ], BkstgScheduleBundle::TRANSLATION_DOMAIN)
            );

            return new RedirectResponse($this->url_generator->generate(
                'bkstg_event_read',
                ['id' => $event->getId(), 'production_slug' => $production->getSlug()]
            ));
        }

        // Render the form.
        return new Response($this->templating->render('@BkstgSchedule/Event/create.html.twig', [
            'form' => $form->createView(),
            'production' => $production,
        ]));
    }
public function createAction ( string $ production_slug , AuthorizationCheckerInterface $ auth , TokenStorageInterface $ token_storage , Request $ request ) : Response { // Lookup the production by production_slug. $ production_repo = $ this -> em -> getRepository ( Production :: class ) ; if ( null === $ production = $ production_repo -> findOneBy ( [ 'slug' => $ production_slug ] ) ) { throw new NotFoundHttpException ( ) ; } // Check permissions for this action. if ( ! $ auth -> isGranted ( 'GROUP_ROLE_EDITOR' , $ production ) ) { throw new AccessDeniedException ( ) ; } // Create a new event with author and production. $ user = $ token_storage -> getToken ( ) -> getUser ( ) ; $ event = new Event ( ) ; $ event -> addGroup ( $ production ) ; $ event -> setAuthor ( $ user -> getUsername ( ) ) ; $ event -> setActive ( true ) ; // Create a new invitation for the current user. $ invitation = new Invitation ( ) ; $ invitation -> setInvitee ( $ user -> getUsername ( ) ) ; $ event -> addInvitation ( $ invitation ) ; // Set start and end times using closest 1 hour intervals. $ start = new \ DateTime ( ) ; $ start -> modify ( '+1 hour' ) ; $ start -> modify ( '-' . $ start -> format ( 'i' ) . ' minutes' ) ; $ event -> setStart ( $ start ) ; $ end = new \ DateTime ( '+1 hour' ) ; $ end -> modify ( '+1 hour' ) ; $ end -> modify ( '-' . $ end -> format ( 'i' ) . ' minutes' ) ; $ event -> setEnd ( $ end ) ; // Create and handle the form. $ form = $ this -> form -> create ( EventType :: class , $ event ) ; $ form -> handleRequest ( $ request ) ; // If the form is submitted and valid persist the event. if ( $ form -> isSubmitted ( ) && $ form -> isValid ( ) ) { $ this -> em -> persist ( $ event ) ; $ this -> em -> flush ( ) ; // Set success message and redirect. $ this -> session -> getFlashBag ( ) -> add ( 'success' , $ this -> translator -> trans ( 'event.created' , [ '%event%' => $ event -> getName ( ) , ] , BkstgScheduleBundle :: TRANSLATION_DOMAIN ) ) ; return new RedirectResponse ( $ this -> url_generator -> generate ( 'bkstg_event_read' , [ 'id' => $ event -> getId ( ) , 'production_slug' => $ production -> getSlug ( ) ] ) ) ; } // Render the form. return new Response ( $ this -> templating -> render ( '@BkstgSchedule/Event/create.html.twig' , [ 'form' => $ form -> createView ( ) , 'production' => $ production , ] ) ) ; }
Create a new standalone event.

@param string                        $production_slug The slug for the production.
@param AuthorizationCheckerInterface $auth            The authorization checker service.
@param TokenStorageInterface         $token_storage   The token storage service.
@param Request                       $request         The request.

@throws NotFoundHttpException When the production does not exist.
@throws AccessDeniedException When the user is not an editor.

@return Response The response.
Create a new standalone event .