public function createAction(
        string $production_slug,
        AuthorizationCheckerInterface $auth,
        TokenStorageInterface $token,
        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, must be an editor or better.
        if (!$auth->isGranted('GROUP_ROLE_EDITOR', $production)) {
            throw new AccessDeniedException();
        }

        // Create new schedule in this production.
        $schedule = new Schedule();
        $schedule->setActive(true);
        $schedule->addGroup($production);
        $schedule->setAuthor($token->getToken()->getUser()->getUsername());

        // Create a form for this schedule and handle it.
        $form = $this->form->create(ScheduleType::class, $schedule);
        $form->handleRequest($request);

        // Form is submitted and valid.
        if ($form->isSubmitted() && $form->isValid()) {
            // Match events with schedule.
            foreach ($schedule->getEvents() as $event) {
                foreach ($schedule->getGroups() as $group) {
                    if (!$event->hasGroup($group)) {
                        $event->addGroup($group);
                    }
                }
                $event->setColour($schedule->getColour());
                $event->setLocation($schedule->getLocation());
                $event->setActive($schedule->isActive());
                $event->setAuthor($schedule->getAuthor());
            }

            // Persist the schedule (will cascade persist).
            $this->em->persist($schedule);
            $this->em->flush();

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

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

        // Render the form.
        return new Response($this->templating->render('@BkstgSchedule/Schedule/create.html.twig', [
            'form' => $form->createView(),
            'production' => $production,
        ]));
    }
public function createAction(
        string $production_slug,
        AuthorizationCheckerInterface $auth,
        TokenStorageInterface $token,
        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, must be an editor or better.
        if (!$auth->isGranted('GROUP_ROLE_EDITOR', $production)) {
            throw new AccessDeniedException();
        }

        // Create new schedule in this production.
        $schedule = new Schedule();
        $schedule->setActive(true);
        $schedule->addGroup($production);
        $schedule->setAuthor($token->getToken()->getUser()->getUsername());

        // Create a form for this schedule and handle it.
        $form = $this->form->create(ScheduleType::class, $schedule);
        $form->handleRequest($request);

        // Form is submitted and valid.
        if ($form->isSubmitted() && $form->isValid()) {
            // Match events with schedule.
            foreach ($schedule->getEvents() as $event) {
                foreach ($schedule->getGroups() as $group) {
                    if (!$event->hasGroup($group)) {
                        $event->addGroup($group);
                    }
                }
                $event->setColour($schedule->getColour());
                $event->setLocation($schedule->getLocation());
                $event->setActive($schedule->isActive());
                $event->setAuthor($schedule->getAuthor());
            }

            // Persist the schedule (will cascade persist).
            $this->em->persist($schedule);
            $this->em->flush();

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

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

        // Render the form.
        return new Response($this->templating->render('@BkstgSchedule/Schedule/create.html.twig', [
            'form' => $form->createView(),
            'production' => $production,
        ]));
    }
public function createAction ( string $ production_slug , AuthorizationCheckerInterface $ auth , TokenStorageInterface $ token , 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, must be an editor or better. if ( ! $ auth -> isGranted ( 'GROUP_ROLE_EDITOR' , $ production ) ) { throw new AccessDeniedException ( ) ; } // Create new schedule in this production. $ schedule = new Schedule ( ) ; $ schedule -> setActive ( true ) ; $ schedule -> addGroup ( $ production ) ; $ schedule -> setAuthor ( $ token -> getToken ( ) -> getUser ( ) -> getUsername ( ) ) ; // Create a form for this schedule and handle it. $ form = $ this -> form -> create ( ScheduleType :: class , $ schedule ) ; $ form -> handleRequest ( $ request ) ; // Form is submitted and valid. if ( $ form -> isSubmitted ( ) && $ form -> isValid ( ) ) { // Match events with schedule. foreach ( $ schedule -> getEvents ( ) as $ event ) { foreach ( $ schedule -> getGroups ( ) as $ group ) { if ( ! $ event -> hasGroup ( $ group ) ) { $ event -> addGroup ( $ group ) ; } } $ event -> setColour ( $ schedule -> getColour ( ) ) ; $ event -> setLocation ( $ schedule -> getLocation ( ) ) ; $ event -> setActive ( $ schedule -> isActive ( ) ) ; $ event -> setAuthor ( $ schedule -> getAuthor ( ) ) ; } // Persist the schedule (will cascade persist). $ this -> em -> persist ( $ schedule ) ; $ this -> em -> flush ( ) ; // Set success message and redirect. $ this -> session -> getFlashBag ( ) -> add ( 'success' , $ this -> translator -> trans ( 'schedule.created' , [ '%schedule%' => $ schedule -> getName ( ) , ] , BkstgScheduleBundle :: TRANSLATION_DOMAIN ) ) ; return new RedirectResponse ( $ this -> url_generator -> generate ( 'bkstg_schedule_read' , [ 'id' => $ schedule -> getId ( ) , 'production_slug' => $ production -> getSlug ( ) , ] ) ) ; } // Render the form. return new Response ( $ this -> templating -> render ( '@BkstgSchedule/Schedule/create.html.twig' , [ 'form' => $ form -> createView ( ) , 'production' => $ production , ] ) ) ; }
Create a new schedule, which is a collection of events.

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

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

@return Response A response.
Create a new schedule which is a collection of events .