src/StartPlatz/Bundle/EventBundle/Controller/EventRegistrationController.php line 456

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace App\StartPlatz\Bundle\EventBundle\Controller;
  3. /**
  4.  * CRITICAL DEPENDENCY WARNING - APPLICATION SYSTEM INTEGRATION
  5.  *
  6.  * This controller handles the event/signup REGISTRATION flow.
  7.  * It has HEAVY DEPENDENCIES on the Application system from StartupBundle.
  8.  *
  9.  * DO NOT modify Application-related code without testing ALL event registration scenarios:
  10.  * - Anonymous (non-member) event registration
  11.  * - Member event registration
  12.  * - Paid event registration with Stripe
  13.  * - Free event registration
  14.  * - Multi-batch event registration
  15.  * - Event registration with validation workflows
  16.  *
  17.  * Extracted from DefaultController (B-60 Phase 2). Uses shared services for dependencies.
  18.  */
  19. use App\StartPlatz\Bundle\EventBundle\Entity\Event;
  20. use App\StartPlatz\Bundle\EventBundle\Entity\EventRepository;
  21. use App\StartPlatz\Bundle\EventBundle\Service\EventNotificationService;
  22. use App\StartPlatz\Bundle\EventBundle\Service\EventPaymentService;
  23. use App\StartPlatz\Bundle\EventBundle\Service\EventRegistrationService;
  24. use App\StartPlatz\Bundle\EventBundle\Service\EventViewHelper;
  25. use App\StartPlatz\Bundle\MailBundle\Service\MailService;
  26. use App\StartPlatz\Bundle\MemberBundle\Entity\Member;
  27. use App\StartPlatz\Bundle\MemberBundle\Entity\Option;
  28. use App\StartPlatz\Bundle\MemberBundle\Entity\Product;
  29. use App\StartPlatz\Bundle\MemberBundle\Entity\Service;
  30. use App\StartPlatz\Bundle\MonsumBundle\Entity\Customer;
  31. use App\StartPlatz\Bundle\StartupBundle\Entity\Application;
  32. use App\StartPlatz\Bundle\StartupBundle\Entity\Batch;
  33. use App\StartPlatz\Bundle\StartupBundle\Entity\Program;
  34. use App\StartPlatz\Bundle\StartupBundle\Form\ApplicationType;
  35. use App\StartPlatz\Bundle\UserBundle\Entity\User;
  36. use App\StartPlatz\Bundle\UserBundle\LoginService;
  37. use App\StartPlatz\Bundle\MemberBundle\Entity\Team;
  38. use App\StartPlatz\Bundle\WebsiteBundle\MenuTranslationService;
  39. use App\StartPlatz\Bundle\WebsiteBundle\Utility\Utility;
  40. use DateTime;
  41. use Doctrine\ORM\EntityManagerInterface;
  42. use Psr\Log\LoggerInterface;
  43. use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
  44. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  45. use Symfony\Component\HttpFoundation\Request;
  46. use Symfony\Component\HttpFoundation\Response;
  47. use Symfony\Component\Routing\Annotation\Route;
  48. use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
  49. class EventRegistrationController extends AbstractController
  50. {
  51.     public function __construct(
  52.         private readonly MailService $mailService,
  53.         private readonly LoginService $loginService,
  54.         private readonly LoggerInterface $logger,
  55.         private readonly EventNotificationService $eventNotificationService,
  56.         private readonly EventPaymentService $eventPaymentService,
  57.         private readonly EventRegistrationService $eventRegistrationService,
  58.         private readonly EventViewHelper $eventViewHelper,
  59.         private readonly EntityManagerInterface $entityManager,
  60.         private readonly MenuTranslationService $menuTranslationService,
  61.     ) {
  62.     }
  63.     #[Route('/signup/{slug}'name'signup_show_single')]
  64.     public function signupSingleAction(Request $request$slug)
  65.     {
  66.         $em $this->entityManager;
  67.         /** @var Program $program */
  68.         if (!$program $em->getRepository(Program::class /*Startup Program*/)->findOneBy(['slug' => 'sign-up'])) {
  69.             $this->addFlash('notice''ERROR Sorry, no program found');
  70.             return $this->redirect($this->generateUrl('apply_home', []));
  71.         }
  72.         /** @var Batch $batch */
  73.         if (!$batch $em->getRepository(Batch::class)->findOneBy(['slug' => $slug'program' => $program])) {
  74.             $this->addFlash('notice''ERROR Sorry, no batch found');
  75.             return $this->redirect($this->generateUrl('apply_home', []));
  76.         }
  77.         // Retrieve the UTM parameters from the URL
  78.         $utmParameters = [
  79.             'utmSource'   => $request->query->get('utm_source'),
  80.             'utmMedium'   => $request->query->get('utm_medium'),
  81.             'utmCampaign' => $request->query->get('utm_campaign'),
  82.             'utmTerm'     => $request->query->get('utm_term'),
  83.             'utmContent'  => $request->query->get('utm_content'),
  84.         ];
  85.         $lang 'DE';
  86.         if ($targetPath $request->server->get('REDIRECT_URL')) {
  87.             $lang $this->menuTranslationService->getLang($targetPath);
  88.         }
  89.         $batchIsOpen $batch && $em->getRepository(Batch::class)->isBatchApplicationOpen($batch);
  90.         $form    null;
  91.         $program null;
  92.         $member  null;
  93.         $application null;
  94.         $product     null;
  95.         $editFeedback "";
  96.         $settings     = [];
  97.         $action       "";
  98.         $customersArr = [];
  99.         if ($batchIsOpen) {
  100.             $program $batch->getProgram();
  101.             $settings $this->eventViewHelper->getProgramSettings($program$batch);
  102.             $batch $em->getRepository(Batch::class)->updateNumbers($batch);
  103.             /** @var User $user */
  104.             if ($user $this->getUser()) {
  105.                 $member $em->getRepository(Member::class)->find($user->getMemberId());
  106.             }
  107.             $action   $request->get('action');
  108.             $application $this->eventRegistrationService->getOrCreateApplication($request$batch$program$member$lang$settings$utmParametersnull);
  109.             if ($batch->getPriceInEuroCent() > 0) {
  110.                 $route                   "signup_show_single";
  111.                 $routeParameters["slug"] = $batch->getSlug();
  112.                 $application $this->handleAction($request$member$application$batch$lang$route$routeParameters$settings);
  113.                 if (is_string($application)) {
  114.                     // Handle redirect
  115.                     return $this->redirect($application);
  116.                 }
  117.             }
  118.             if ($user && in_array($action, ["needsloginvalidation""needsemailverification"])) {
  119.                 $response $this->validateEventApplication($application$member$settings$batch$lang);
  120.                 $application $response['data']['application'];
  121.             }
  122.             if ($batch->getPriceInEuroCent() > && $batch->getProductId()) {
  123.                 if (!$product $em->getRepository(Product::class /*Product Member*/)->find($batch->getProductId())) {
  124.                     $this->addFlash('notice''ERROR configuration not found');
  125.                     return $this->redirect($this->generateUrl('events_list'));
  126.                 }
  127.                 if ($application->getId() && isset($member) && $member->getId()) {
  128.                     $customersArr $em->getRepository(Customer::class)->findValidMonsumCustomersByMemberAndAccount($member$product->getAccount(), false);
  129.                 }
  130.             }
  131.             $form $this->createForm(ApplicationType::class, $application, ['settings' => $settings'program' => $program'batch' => $batch]);
  132.             $form->handleRequest($request);
  133.             ##############################################################
  134.             ##   form validation starts here                            ##
  135.             ##############################################################
  136.             if ($form->isSubmitted() && $form->isValid()) {
  137.                 $application $em->getRepository(Application::class)->cleanApplicationData($application);
  138.                 $adminEmail  $application->getEmail();
  139.                 if ($member) {
  140.                     $memberToBeRegistered $member;
  141.                     $isExistingMember     true;
  142.                 } else {
  143.                     $response $this->eventRegistrationService->resolveOrCreateMember($application);
  144.                     $isExistingMember     $response['data']['isExistingMember'];
  145.                     $memberToBeRegistered $response['data']['memberToBeRegistered'];
  146.                 }
  147.                 $memberToBeRegistered->setIsExistingMember($isExistingMember);
  148.                 // fill application with memberId and teamId and discount information
  149.                 $application $this->eventRegistrationService->bindMemberToApplication($application$memberToBeRegistered$batch);
  150.                 if (!$batch->isMultipleApplicationsPerMember()) {
  151.                     // check if there is already an application to this event == batch with that batchId and memberId
  152.                     if ($existingApplication $em->getRepository(Application::class)->findOneBy(['batchId' => $batch->getId(), 'memberId' => $memberToBeRegistered->getId()])) {
  153.                         // there are two applications - the latest application will always win
  154.                         $fields     Utility::getEntityFieldsArray($application, ['id','assessments''votesRegistered''applicationStatus''editStatus''editMessage''lastChangeUser','history','extraFields','lastModified','createdAt']);
  155.                         $storedData Utility::fillDataByObject($existingApplication$fields);
  156.                         $updatedData Utility::fillDataByObject($application$fields);
  157.                         $differences array_diff_assoc($updatedData$storedData);
  158.                         $application $existingApplication;
  159.                         $application $this->updateApplication($application$differences);
  160.                         $application->setIsExistingApplication(true);
  161.                     }
  162.                 }
  163.                 if (isset($settings['extraFields'])) {
  164.                     $application $this->eventViewHelper->getExtraFieldsData($application$settings$form);
  165.                 }
  166.                 $dummyEvent = new Event();
  167.                 $isPaidEvent $this->eventPaymentService->isPaidEvent($application$batch$dummyEvent);
  168.                 $hasToPay    $this->eventPaymentService->isPaymentRequired($application$memberToBeRegistered$dummyEvent$settings$batch);
  169.                 if ($isPaidEvent && $hasToPay) {
  170.                     // falls es bereits einen zugänglichen Monsum Account für diese Person gibt
  171.                     $customersArr $em->getRepository(Customer::class)->findValidMonsumCustomersByMemberAndAccount($memberToBeRegistered$product->getAccount(), false);
  172.                     $dummyEvent = new Event();
  173.                     $application  $this->eventPaymentService->updateApplicationWithStepOneInfo($application$memberToBeRegistered$dummyEvent);
  174.                     // Application in Datenbank schreiben, sonst kann im nächsten Schritt keine appId übergeben werden
  175.                     $application $em->getRepository(Application::class)->setApplication($application);
  176.                 } else {
  177.                     $route 'signup_show_single';
  178.                     $routeParameters $request->get('_route_params');
  179.                     $response $this->eventRegistrationService->processRegistrationWithoutPayment($isExistingMember$user$memberToBeRegistered$application$settings$lang$adminEmail$batch$route$routeParameters);
  180.                     // Bei SignUps: Prüfe ob goToPage gesetzt ist
  181.                     if ($batch->getGoToPage()) {
  182.                         // Weiterleitung zu goToPage (kann URL oder interner Pfad sein)
  183.                         return $this->redirect($batch->getGoToPage());
  184.                     }
  185.                     // Ansonsten auf SignUp-Seite bleiben - keine Weiterleitung
  186.                     $application  $response['data']['application'];
  187.                     $member       $response['data']['member'];
  188.                 }
  189.             }
  190.         }
  191.         // Default to legacy template for backward compatibility
  192.         $view '@StartPlatzEventBundle/Default/signup-single.html.twig';
  193.         // Check for pageTemplate field (new approach)
  194.         if ($batch->getPageTemplate()) {
  195.             switch ($batch->getPageTemplate()) {
  196.                 case 'modern':
  197.                 case 'flexible':
  198.                     $view '@StartPlatzEventBundle/Default/signup-single.modern.html.twig';
  199.                     break;
  200.                 case 'petition':
  201.                     $view '@StartPlatzEventBundle/Default/signup-single.deepSeekPetition.html.twig';
  202.                     break;
  203.                 case 'legacy':
  204.                 default:
  205.                     $view '@StartPlatzEventBundle/Default/signup-single.html.twig';
  206.                     break;
  207.             }
  208.         }
  209.         // Keep backward compatibility for existing petition SignUps using JSON settings
  210.         elseif (array_key_exists('signupTemplate'$settings)) {
  211.             $view '@StartPlatzEventBundle/Default/signup-single.deepSeekPetition.html.twig';
  212.         }
  213. // Build the metaData array using only the $batch object (landing page fields)
  214.         $metaData = [
  215.             // SEO Tag: Description (using landingPageDescription)
  216.             'description'       => $batch->getLandingPageDescription(),
  217.             // Canonical URL (the domain remains lowercase)
  218.             'canonical'         => 'https://www.startplatz.de/signup/' urlencode($batch->getSlug()),
  219.             // Open Graph Tags for Social Sharing (using landingPage fields)
  220.             'ogTitle'           => $batch->getLandingPageTitle(),
  221.             'ogDescription'     => $batch->getLandingPageDescription(),
  222.             'ogImage'           => $batch->getLandingPageSocialImage(),
  223.             'ogUrl'             => 'https://www.startplatz.de/signup/' urlencode($batch->getSlug()),
  224.             'ogType'            => 'website',
  225.             'ogSiteName'        => 'STARTPLATZ'// Protected trademark must be uppercase
  226.             // Twitter Card Tags (using landingPage fields)
  227.             'twitterCard'       => 'summary'// or "summary_large_image" if preferred
  228.             'twitterTitle'      => $batch->getLandingPageTitle(),
  229.             'twitterDescription'=> $batch->getLandingPageDescription(),
  230.             'twitterImage'      => $batch->getLandingPageSocialImage(),
  231.             'twitterSite'       => '@STARTPLATZ'// Protected trademark must be uppercase
  232.             // Title for the page (taken from landingPageTitle)
  233.             'title'             => $batch->getLandingPageTitle(),
  234.             // Additional Landing Page Fields
  235.             'landingPageCss'            => $batch->getLandingPageCss(),
  236.             'landingPageContent'        => $batch->getLandingPageContent(),
  237.             'landingPageJs'             => $batch->getLandingPageJs(),
  238.             'landingPageFooterTemplate' => $batch->getLandingPageFooterTemplate(),
  239.         ];
  240.         return $this->render($view, [
  241.             'batch'          => $batch,
  242.             'program'        => $program,
  243.             'settings'       => $settings,
  244.             'metaData'       => $metaData,
  245.             'form'           => $form $form->createView() : $form,
  246.             'application'    => $application,
  247.             'action'         => $action,
  248.             'batchIsOpen'    => $batchIsOpen,
  249.             'customersArr'   => $customersArr,
  250.             'member'         => $member,
  251.             'isMultiBatchEvent' => false,  // Signups have no event, so no multi-batch
  252.             'utmParameters'  => $utmParameters,
  253.             'phrases'        => $em->getRepository(Option::class)->getApplicationPhrases($program$batchfalse$lang),
  254.             'editFeedback'   => $editFeedback,
  255.             'templateVars'   => [],
  256.             'preview'             => $request->get('preview'),
  257.             'lang'            => $lang,
  258.             'targetRoute'     => "signup_show_single",
  259.             'targetRouteSlug' => $batch->getSlug(),
  260.             'targetPath'      => $targetPath,
  261.         ]);
  262.     }
  263.     ### section signup ends here ###
  264.     #[Route('/allmeda/event/application/send-confirmation-mail/{applicationId}'name'allmeda_event_send-confirmation-mail')]
  265.     /**
  266.      * @IsGranted("ROLE_ADMIN")
  267.      */
  268.     public function sendConfirmationMailViaPublicFunction($applicationId)
  269.     {
  270.         $em $this->entityManager;
  271.         $application $em->getRepository(Application::class)->find($applicationId);
  272.         $member $em->getRepository(Member::class)->find($application->getMemberId());
  273.         $batch $em->getRepository(Batch::class)->find($application->getBatchId());
  274.         $feedback $this->eventNotificationService->sendConfirmationMail(null$member, [], $application$batch);
  275.         $response "SUCCESS Confirmation Mail has been sent";
  276.         return new Response($response);
  277.     }
  278.     #[Route('/event-confirmation/{slug}/'name'event_confirmation')]
  279.     public function eventConfirmationAction(Request $request$slug)
  280.     {
  281.         $em $this->entityManager;
  282.         $event $this->findEventBySlug($slug);
  283.         if (!$event) {
  284.             $this->addFlash('notice''ERROR Event not found');
  285.             return $this->redirectToRoute('events_list');
  286.         }
  287.         $seriesEvents = [];
  288.         if ($seriesTag $event->getSeriesTag()) {
  289.             /** @var EventRepository $eventRepository */
  290.             $eventRepository $em->getRepository(Event::class);
  291.             $seriesEvents $eventRepository->findBySeriesTag($seriesTag'', ['startDate' => 'DESC']);
  292.         }
  293.         $embed $request->get('embed');
  294.         $batch $em->getRepository(Batch::class)->findOneBy(['programId'=>27'eventId'=>$event->getId(), 'status'=>'active''access' =>'anonymous']);
  295.         if (!$batch) {
  296.             $this->addFlash('notice''ERROR No active batch found for this event');
  297.             return $this->redirectToRoute('events_list');
  298.         }
  299.         $program $batch->getProgram();
  300.         $action   $request->get('action');
  301.         $applicationId $request->get('app');
  302.         $route                   "event_confirmation";
  303.         $routeParameters["slug"] = $event->getSlug();
  304.         $settings = [];
  305.         $member   false;
  306.         $application = new Application();
  307.         // Load application first, then determine language
  308.         if ($applicationId){
  309.             if (!$application $em->getRepository(Application::class)->find($applicationId)){
  310.                 $this->addFlash('notice''ERROR Application with ID '.$applicationId.' not found');
  311.                 return $this->redirectToRoute('events_list');
  312.             }
  313.         }
  314.         // Language detection: Priority is Application > Event > Default DE
  315.         // This ensures user's language choice persists through Stripe redirect
  316.         $lang = ($application && $application->getId() && $application->getLang())
  317.             ? $application->getLang()
  318.             : ($event->getLang() ?? 'DE');
  319.         // Handle action after language is determined
  320.         if ($applicationId && $action){
  321.             $application $this->handleAction($request$member$application$batch$lang$route$routeParameters$settings);
  322.             if (is_string($application)) {
  323.                 // Handle redirect
  324.                 return $this->redirect($application);
  325.             }
  326.         }
  327.         // Generate the absolute base URL based on the route and parameters
  328.         $baseURL $this->generateUrl('event_show_single', ['slug' => $slug], UrlGeneratorInterface::ABSOLUTE_URL);
  329.         // UTM parameters for the promotion URL
  330.         $promotionUtmParameters = [
  331.             'utm_source'   => 'affiliate',
  332.             'utm_medium'   => is_numeric($application->getMemberId()) ? $application->getMemberId() : '',
  333.             'utm_campaign' => 'event:' $event->getId(),
  334.             'utm_term'     => '',
  335.             'utm_content'  => '',
  336.         ];
  337.         $promotionUrl $em->getRepository(Batch::class)->generatePromotionUrl($baseURL$promotionUtmParameters);
  338.         $view '@StartPlatzEventBundle/Default/event-confirmation.html.twig';
  339.         if ($embed){
  340.             $view '@StartPlatzEventBundle/Default/event-confirmation.embed.html.twig';
  341.         }
  342.         if ($event->getTwigFile() == 'winter-2025' ){
  343.             $view '@StartPlatzEventBundle/Default/event-confirmation.winter-2025.html.twig';
  344.         }
  345.         if ($event->getTwigFile() == 'style-ecodynamics' ){
  346.             $view '@StartPlatzEventBundle/Default/event-confirmation.style-ecodynamics.html.twig';
  347.         }
  348.         if ($event->getTwigFile() == 'style-ai-hub' ){
  349.             $view '@StartPlatzEventBundle/Default/event-confirmation.style-ai-hub.html.twig';
  350.         }
  351.         if ($event->getTwigFile() == 'style-startplatz' ){
  352.             $view '@StartPlatzEventBundle/Default/event-confirmation.style-ai-hub.html.twig';
  353.         }
  354.         return $this->render($view, [
  355.             'event'         => $event,
  356.             'seriesEvents'  => $seriesEvents,
  357.             'promotionUrl'   => $promotionUrl,
  358.             'batch'          => $batch,
  359.             'settings'       => $settings,
  360.             'application'    => $application,
  361.             'action'         => $action,
  362.             'member'         => $member,
  363.             'speakers'       => $this->eventViewHelper->getSpeakers($event),
  364.             'phrases'        => $em->getRepository(Option::class)->getApplicationPhrases($program$batchfalse$lang),
  365.             'templateVars'   => [],
  366.             'embed'          => $embed,
  367.             'lang'            => $lang,
  368.             'isMultiBatchEvent' => $event->isMultiBatchEvent(),
  369.         ]);
  370.     }
  371.     #[Route('/event/{slug}/'name'event_show_single')]
  372.     #[Route('/event/{slug}/{date}'name'event_show_single_by_date'requirements: [])]
  373.     public function eventSingleAction(Request $request$slug$date null)
  374.     {
  375.         ##event-single
  376.         if ($slug == 'ai-bootcamp-koeln-2024-01-18') return $this->redirect$this->generateUrl('event_show_single', array('slug' => 'ai-bootcamp-koeln-2024-01-29')) );
  377.         if ($slug == 'ai-summer-school-koeln-2208') return $this->redirect$this->generateUrl('event_show_single', array('slug' => 'ai-bootcamp-koeln-1109')) );
  378.         if ($slug == 'ai-summer-school-duesseldorf-2908') return $this->redirect$this->generateUrl('event_show_single', array('slug' => 'ai-bootcamp-duesseldorf-2609')) );
  379.         if ($slug == 'ai-disruptme-marketing-in-unternehmen-koeln-2023-10-19') return $this->redirect$this->generateUrl('event_show_single', array('slug' => 'ai-disruptme-marketing-in-unternehmen-koeln-2024-01-31')) );
  380.         if ($slug == 'ai-disruptme-publisher-koeln-2023-10-18') return $this->redirect$this->generateUrl('event_show_single', array('slug' => 'ai-disruptme-publisher-duesseldorf-2024-03-20')) );
  381.         if ($slug == 'ai-disruptme-travel-tourismus-duesseldorf-2023-11-09') return $this->redirect$this->generateUrl('event_show_single', array('slug' => 'ai-disruptme-travel-tourismus-duesseldorf-2024-02-22')) );
  382.         if ($slug == 'genai-ki-app-no-code-backend-fuer-ki-anwendung-2024-05-28') return $this->redirect$this->generateUrl('event_show_single', array('slug' => 'genai-ki-anwendung-bauen-frontend-ux-ui-2024-05-21')) );
  383.         if ($slug == 'ai-barcamp-generative-ki') return $this->redirect$this->generateUrl('event_show_single', array('slug' => 'ai-barcamp-logistik')) );
  384.         if ($slug == 'genai-generative-ki-zertifikat-ki-kompetenz-erwerben-2025-05-20') return $this->redirect$this->generateUrl('event_show_single', array('slug' => 'ki-kompetenzpflicht-zertifikat-artikel-4-2025-05-20')) );
  385.         // Retrieve the UTM parameters from the URL
  386.         $utmParameters = [
  387.             'utmSource'   => $request->query->get('utm_source') ?? 'homepage',
  388.             'utmMedium'   => $request->query->get('utm_medium'),
  389.             'utmCampaign' => $request->query->get('utm_campaign'),
  390.             'utmTerm'     => $request->query->get('utm_term'),
  391.             'utmContent'  => $request->query->get('utm_content'),
  392.         ];
  393.         $em $this->entityManager;
  394.         /** @var Event $event */
  395.         $event $this->findEventBySlug($slug);
  396.         if (!$event) {
  397.             $this->addFlash('notice''ERROR Veranstaltung nicht gefunden');
  398.             return $this->redirectToRoute('events_list');
  399.         }
  400.         // Handle event visibility: redirect if not published or previewed without user session.
  401.         $response $this->handleEventStatus($event$request);
  402.         if ($response) {
  403.             return $response;
  404.         }
  405.         $seriesEvents = [];
  406.         if ($seriesTag $event->getSeriesTag()) {
  407.             /** @var EventRepository $eventRepository */
  408.             $eventRepository $em->getRepository(Event::class);
  409.             $seriesEvents $eventRepository->findBySeriesTag($seriesTag'', ['startDate' => 'DESC']);
  410.         }
  411.         // Language detection with priority: URL parameter > Event default
  412.         // This ensures ?lang=en parameter works for bilingual events
  413.         $lang strtoupper($request->query->get('lang''')) ?: ($event->getLang() ?? 'DE');
  414.         $embed $request->get('embed');
  415.         $eventbriteId   $event->getEventbriteId();
  416.         $isEventbriteOnly $event->getTicketing() > '';
  417.         $applicationUrl $event->getApplicationUrl();
  418.         // Multi-batch aware logic
  419.         $futureBatches = [];
  420.         $allBatches = [];
  421.         if ($event->isMultiBatchEvent()) {
  422.             $allBatches $em->getRepository(Batch::class)->findAllBatchesByEvent($event);
  423.             if ($date) {
  424.                 // User selected a specific date
  425.                 $batch $em->getRepository(Batch::class)->findBatchByEventAndDate($event$date);
  426.                 if (!$batch) {
  427.                     // Invalid date, redirect to main event page
  428.                     $this->addFlash('notice''Der gewählte Termin ist nicht verfügbar.');
  429.                     return $this->redirectToRoute('event_show_single', ['slug' => $slug]);
  430.                 }
  431.             } else {
  432.                 // No date selected, show next upcoming batch
  433.                 $batch $em->getRepository(Batch::class)->findNextOpenBatchByEvent($event);
  434.             }
  435.             // Get all future batches for the selector
  436.             $futureBatches $em->getRepository(Batch::class)->findFutureBatchesByEvent($event10);
  437.             // Get past batches for archive display
  438.             $pastBatches $em->getRepository(Batch::class)->findPastBatchesByEvent($event10);
  439.         } else {
  440.             // Single batch event - keep existing logic
  441.             // Try to find active batch first, then fall back to completed batch for display
  442.             $batch $em->getRepository(Batch::class)->findOneBy(['programId'=>27'eventId'=>$event->getId(), 'status'=>'active''access' =>'anonymous']);
  443.             if (!$batch) {
  444.                 // No active batch found, look for completed batch (for past events that need to display)
  445.                 $batch $em->getRepository(Batch::class)->findOneBy(['programId'=>27'eventId'=>$event->getId(), 'status'=>'completed''access' =>'anonymous']);
  446.             }
  447.             if ($batch) {
  448.                 $allBatches = [$batch];
  449.             }
  450.         }
  451.         $batchIsOpen $batch && $em->getRepository(Batch::class)->isBatchApplicationOpen($batch);
  452.         $form    null;
  453.         $program null;
  454.         $application null;
  455.         $product     null;
  456.         $editFeedback "";
  457.         $settings     = [];
  458.         $action       "";
  459.         $customersArr = [];
  460.         $member null;
  461.         /** @var User $user */
  462.         if ($user $this->getUser()) {
  463.             $member $em->getRepository(Member::class)->find($user->getMemberId());
  464.         }
  465.         if ($batch && !$isEventbriteOnly) {
  466.             $program $batch->getProgram();
  467.         }
  468.         if ($batchIsOpen && !$isEventbriteOnly) {
  469.             $settings $this->eventViewHelper->getProgramSettings($program$batch);
  470.             $batch $em->getRepository(Batch::class)->updateNumbers($batch);
  471.             $action   $request->get('action');
  472.             $referral $request->get('referral');
  473.             // do some exceptions
  474.             if ($member && isset($settings['batchType'])) {
  475.                 if ($settings['batchType'] == 'memberDocumentation'){
  476.                     // check if member
  477.                     if ($em->getRepository(Application::class)->findApplicationsByAiFridayBatchSlugAndMemberId($member->getId()))
  478.                     {
  479.                         if (!$em->getRepository(Application::class)->findOneBy(['memberId'=>$member->getId(), 'batchId' => $batch->getId()])){
  480.                             $memberTeam  $em->getRepository(Team::class)->find($member->getTeamId());
  481.                             $adminEmail  $member->getEmail();
  482.                             $application $em->getRepository(Application::class)->createApplicationIfNotExists($program$batch$memberTeam$member$adminEmail);
  483.                             $application->setBatchStatus('applicant');
  484.                             $application->setApplicationStatus('applied');
  485.                             $em->persist($application);
  486.                             $em->flush();
  487.                             $batch $em->getRepository(Batch::class)->updateNumbers($batch);
  488.                         }
  489.                     }
  490.                 }
  491.             }
  492.             $application $this->eventRegistrationService->getOrCreateApplication($request$batch$program$member$lang$settings$utmParameters$event);
  493.             if ($referral && $application->getRealPriceinEuroCent() > 0) {
  494.                 if ($recommendedByMember $em->getRepository(Member::class)->find($referral)) {
  495.                     if ($neededTag $settings['isRecommendedBy'] ?? '') {
  496.                         if (Utility::contains($recommendedByMember->getTags(), $neededTag)) {
  497.                             $application->setRealPriceinEuroCent(0);
  498.                             $application->setDiscountReason("geworben durch {$recommendedByMember->getName()}");
  499.                             $application->setDiscountPercent(100);
  500.                         }
  501.                     }
  502.                 }
  503.             }
  504.             if ($user && in_array($action, ["needsloginvalidation""needsemailverification"])) {
  505.                 $response $this->validateEventApplication($application$member$settings$batch$lang);
  506.                 $application $response['data']['application'];
  507.             }
  508.             // Only check for Monsum product if we're not using Stripe
  509.             $hasStripeConfig = ($batch && $batch->getStripePriceId()) || ($event && $event->getStripePriceId());
  510.             if ($batch->getPriceInEuroCent() > && $batch->getProductId() && !$hasStripeConfig) {
  511.                 if (!$product $em->getRepository(Product::class /*Product Member*/)->find($batch->getProductId())) {
  512.                     $this->addFlash('notice''ERROR configuration not found');
  513.                     return $this->redirect($this->generateUrl('events_list'));
  514.                 }
  515.             }
  516.             $form $this->createForm(ApplicationType::class, $application, [
  517.                 'settings' => $settings,
  518.                 'program' => $program,
  519.                 'batch' => $batch,
  520.                 'csrf_protection' => $embed false true,
  521.                 ]);
  522.             $form->handleRequest($request);
  523.             ##############################################################
  524.             ##   form validation starts here                            ##
  525.             ##############################################################
  526.             if ($form->isSubmitted() && $form->isValid()) {
  527.                 $application $em->getRepository(Application::class)->cleanApplicationData($application);
  528.                 $adminEmail $application->getEmail();
  529.                 $email $application->getEmail();
  530.                 if (!Utility::validateEmail($email)){
  531.                     $this->addFlash('notice''ERROR Incorrect email adress. Please check your email adress!');
  532.                 } else {
  533.                     // maxApplicants
  534.                     if (isset($settings['maxApplicants'])) {
  535.                         $applicants $em->getRepository(Application::class)->findBy(['batchId' => $batch->getId(), 'applicationStatus' => 'applied']);
  536.                         $currentApplicantsCount count($applicants);
  537.                         if ($currentApplicantsCount >= $settings['maxApplicants']) {
  538.                             $this->addFlash('notice''ERROR Leider sind alle verfügbaren Plätze bereits vergeben.');
  539.                             return $this->redirectToRoute('event_show_single', ['slug' => $slug]);
  540.                         }
  541.                     }
  542.                     // isErrorDetectionOn
  543.                     if (isset($settings['isErrorDetectionOn']) and $settings['isErrorDetectionOn']) {
  544.                         $this->addFlash('notice''ERROR There was a problem in processing your application. Please contact support@startplatz.de');
  545.                         return $this->redirectToRoute('event_show_single', ['slug' => $slug]);
  546.                     }
  547.                     if ($member) {
  548.                         $memberToBeRegistered $member;
  549.                         $isExistingMember true;
  550.                     } else {
  551.                         $response $this->eventRegistrationService->resolveOrCreateMember($application);
  552.                         $isExistingMember $response['data']['isExistingMember'];
  553.                         $memberToBeRegistered $response['data']['memberToBeRegistered'];
  554.                     }
  555.                     $memberToBeRegistered->setIsExistingMember($isExistingMember);
  556.                     // fill application with memberId and teamId and discount information
  557.                     $application $this->eventRegistrationService->bindMemberToApplication($application$memberToBeRegistered$batch);
  558.                     if (!$batch->isMultipleApplicationsPerMember()) {
  559.                         // check if there is already an application to this event == batch with that batchId and memberId
  560.                         if ($existingApplication $em->getRepository(Application::class)->findOneBy(['batchId' => $batch->getId(), 'memberId' => $memberToBeRegistered->getId()])) {
  561.                             // there are two applications - the latest application will always win
  562.                             $fields Utility::getEntityFieldsArray($application, ['id''assessments''votesRegistered''applicationStatus''editStatus''editMessage''lastChangeUser''history''extraFields''lastModified''createdAt']);
  563.                             $storedData Utility::fillDataByObject($existingApplication$fields);
  564.                             $updatedData Utility::fillDataByObject($application$fields);
  565.                             $differences array_diff_assoc($updatedData$storedData);
  566.                             $application $existingApplication;
  567.                             $application $this->updateApplication($application$differences);
  568.                             $application->setIsExistingApplication(true);
  569.                         }
  570.                     }
  571.                     if (isset($settings['extraFields'])) {
  572.                         $application $this->eventViewHelper->getExtraFieldsData($application$settings$form);
  573.                     }
  574.                     $isPaidEvent $this->eventPaymentService->isPaidEvent($application$batch$event);
  575.                     // Debug logging for ki-campus payment exception
  576.                     $this->logger->info('Payment exception check', [
  577.                         'member_exists' => $member true false,
  578.                         'member_id' => $member $member->getId() : null,
  579.                         'member_email' => $member $member->getEmail() : null,
  580.                         'member_tags' => $member $member->getTags() : null,
  581.                         'memberToBeRegistered_id' => $memberToBeRegistered->getId(),
  582.                         'memberToBeRegistered_email' => $memberToBeRegistered->getEmail(),
  583.                         'memberToBeRegistered_tags' => $memberToBeRegistered->getTags(),
  584.                         'batch_isFreeForKiCampus' => $batch $batch->getIsFreeForKiCampus() : null,
  585.                         'event_isFreeForKiCampus' => $event $event->getIsFreeForKiCampus() : null,
  586.                     ]);
  587.                     // Always use memberToBeRegistered for payment exception check
  588.                     $hasToPay $this->eventPaymentService->isPaymentRequired($application$memberToBeRegistered$event$settings$batch);
  589.                     if ($isPaidEvent && $hasToPay) {
  590.                         $application $this->eventPaymentService->updateApplicationWithStepOneInfo($application$memberToBeRegistered$event);
  591.                         $isAdmin $user && $user->getIsAdmin();
  592.                         $paymentLink $this->eventPaymentService->createStripeCheckoutUrl($application$memberToBeRegistered$event$batch$embed$isAdmin);
  593.                         if (is_string($paymentLink)) {
  594.                             // call stripe and let applicant pay for the ticket
  595.                             if ($embed){
  596.                                 return $this->render('@StartPlatzEventBundle/Default/iframe_redirect.html.twig', [
  597.                                     'targetUrl' => $paymentLink
  598.                                 ]);
  599.                             } else {
  600.                                 return $this->redirect($paymentLink);
  601.                             }
  602.                         } elseif ($paymentLink === null) {
  603.                             // No Stripe config — check Monsum
  604.                             if ($product) {
  605.                                 $customersArr $em->getRepository(Customer::class)->findValidMonsumCustomersByMemberAndAccount($memberToBeRegistered$product->getAccount(), false);
  606.                             }
  607.                         }
  608.                         // paymentLink === false: Stripe was configured but failed — fall through to render page
  609.                         // Application in Datenbank schreiben, sonst kann im nächsten Schritt keine appId übergeben werden
  610.                         $application $em->getRepository(Application::class)->setApplication($application);
  611.                     } else {
  612.                         $route 'event_show_single';
  613.                         $routeParameters $request->get('_route_params');
  614.                         if (!array_key_exists('slug'$routeParameters)) {
  615.                             $routeParameters['slug'] = $event->getSlug();
  616.                         }
  617.                         $response $this->eventRegistrationService->processRegistrationWithoutPayment($isExistingMember$user$memberToBeRegistered$application$settings$lang$adminEmail$batch$route$routeParameters);
  618.                         if ($response['status'] == 'error') {
  619.                             $targetPath $response['data']['targetPath'];
  620.                             return $this->redirect($targetPath);
  621.                         }
  622.                         $application $response['data']['application'];
  623.                         $member $response['data']['member'];
  624.                         if ($this->shouldSetAiHubMembership($settings$application->getApplicationStatus())) {
  625.                             $aiHubStatus $settings["setAiHubMembership"];
  626.                             $service $this->configureServiceForAiHub($aiHubStatus$event->getStartDate());
  627.                             $reason "participated in event with id={$event->getId()} and title={$event->getTitle()}";
  628.                             $em->getRepository(Member::class)->setAiHubMembership($service$member$reason);
  629.                         }
  630.                     }
  631.                 }
  632.             }
  633.         }
  634.         $promotionUrl null;
  635.         if ($user && $batch) {
  636.             // Generate the absolute base URL based on the route and parameters
  637.             $baseURL $this->generateUrl('event_show_single', ['slug' => $slug], UrlGeneratorInterface::ABSOLUTE_URL);
  638.             // UTM parameters for the promotion URL
  639.             $promotionUtmParameters = [
  640.                 'utm_source' => 'affiliate',
  641.                 'utm_medium' => $member->getId(),
  642.                 'utm_campaign' => 'event:' $event->getId(),
  643.                 'utm_term'     => '',
  644.                 'utm_content'  => '',
  645.             ];
  646.             $promotionUrl $em->getRepository(Batch::class)->generatePromotionUrl($baseURL$promotionUtmParameters);
  647.         }
  648.         // Überprüfen Sie den Wert des Teaserfeldes, um showTeaser zu setzen
  649.         $showTeaser = !empty($event->getTeaser());
  650.         $paymentLink false;
  651.         $view '@StartPlatzEventBundle/Default/event-single.html.twig';
  652.         if ($event->isSinglePage() or $embed){
  653.             $view '@StartPlatzEventBundle/Default/event-single.lp.html.twig';
  654.         }
  655.         if ($event->getTwigFile() == 'winter-2025' ){
  656.             $view '@StartPlatzEventBundle/Default/event-single.winter-2025.html.twig';
  657.         }
  658.         if ($event->getTwigFile() == 'style-ecodynamics' ){
  659.             $view '@StartPlatzEventBundle/Default/event-single.style-ecodynamics.html.twig';
  660.         }
  661.         if ($event->getTwigFile() == 'style-ai-hub' ){
  662.             $view '@StartPlatzEventBundle/Default/event-single.style-ai-hub.html.twig';
  663.         }
  664.         if ($event->getTwigFile() == 'style-startplatz' ){
  665.             $view '@StartPlatzEventBundle/Default/event-single.style-startplatz.html.twig';
  666.         }
  667.         if ($event->getTwigFile() == 'tailwind' ){
  668.             $view '@StartPlatzEventBundle/Default/event-single.tailwind.html.twig';
  669.         }
  670.         return $this->render($view, [
  671.             'event'         => $event,
  672.             'seriesEvents'  => $seriesEvents,
  673.             'showTeaser'    => $showTeaser,
  674.             'utmParameters'  => $utmParameters,
  675.             'promotionUrl'   => $promotionUrl,
  676.             'eventbriteId'   => $eventbriteId,
  677.             'isEventbriteOnly' => $isEventbriteOnly,
  678.             'applicationUrl' => $applicationUrl,
  679.             'batch'          => $batch,
  680.             'settings'       => $settings,
  681.             'form'           => $form $form->createView() : $form,
  682.             'application'    => $application,
  683.             'action'         => $action,
  684.             'batchIsOpen'    => $batchIsOpen,
  685.             'customersArr'   => $customersArr,
  686.             'member'         => $member,
  687.             'paymentLink'    => $paymentLink,
  688.             // Multi-batch event support
  689.             'futureBatches'  => $futureBatches,
  690.             'pastBatches'    => $pastBatches ?? [],
  691.             'allBatches'     => $allBatches,
  692.             'selectedDate'   => $date,
  693.             'isMultiBatchEvent' => $event->isMultiBatchEvent(),
  694.             'speakers'       => $this->eventViewHelper->getSpeakers($event),
  695.             'phrases'        => $em->getRepository(Option::class)->getApplicationPhrases($program$batchfalse$lang),
  696.             'editFeedback'   => $editFeedback,
  697.             'templateVars'   => [],
  698.             'preview'             => $request->get('preview'),
  699.             'lang'           => $lang,
  700.             'isEnglish'      => $lang === 'EN',
  701.             'embed'          => $embed,
  702.             'targetRoute'     => "event_show_single",
  703.             'targetRouteSlug' => $event->getSlug(),
  704.         ]);
  705.     }
  706.     // ── Private Helpers ──────────────────────────────────────────────
  707.     private function findEventBySlug($slug)
  708.     {
  709.         /** @var EventRepository $eventRepository */
  710.         $eventRepository $this->entityManager->getRepository(Event::class);
  711.         $event $eventRepository->findOneBy(['slug' => $slug]);
  712.         if (!$event) {
  713.             $querySlug '/' $slug;
  714.             $event $eventRepository->findOneBy(['slug' => $querySlug]);
  715.             if (!$event) {
  716.                 return false;
  717.             } else {
  718.                 $em $this->entityManager;
  719.                 $event->setSlug($slug);
  720.                 $em->persist($event);
  721.                 $em->flush();
  722.             }
  723.         }
  724.         return $event;
  725.     }
  726.     private function handleEventStatus(Event $eventRequest $request)
  727.     {
  728.         // SEO-optimized handling: Archive events are displayed normally (no redirect)
  729.         // Template will show archive banner and hide registration forms
  730.         // This preserves 100% SEO juice and backlinks
  731.         if ($event->getStatus() != 'publish' and $event->getStatus() != 'archive' and !$request->get('preview')) {
  732.             // Draft and trash events require authentication
  733.             if (!$this->getUser()) {
  734.                 $this->addFlash('notice''ERROR Veranstaltung ist nicht verfügbar');
  735.                 return $this->redirectToRoute('events_list');
  736.             }
  737.         }
  738.         return null;
  739.     }
  740.     /**
  741.      * handleAction - Handles various actions for the application
  742.      *
  743.      * This function is called in the following contexts:
  744.      * 1. During Signup (signupSingleAction)
  745.      *    - With route "signup_show_single"
  746.      *    - Parameters include batch slug, language, etc.
  747.      *
  748.      * 2. During Event Handling (eventSingleAction / eventConfirmationAction)
  749.      *    - With route "event_show_single" or "event_confirmation"
  750.      *    - Parameters include event slug, language, etc.
  751.      */
  752.     private function handleAction(Request $request$memberApplication $applicationBatch $batch$lang$route$routeParameters$settings)
  753.     {
  754.         $action $request->get("action");
  755.         $em $this->entityManager;
  756.         switch ($action) {
  757.             case "checkSuccess":
  758.                 $provider $request->get('provider');
  759.                 if ($provider == 'stripe'){
  760.                     $application->setEditStatus("success:stripePaid");
  761.                 }
  762.                 $application->setApplicationStatus('applied');
  763.                 $application->setHasPaid(true);
  764.                 $application $em->getRepository(Application::class)->setApplication($application);
  765.                 switch ($lang) {
  766.                     case "DE":
  767.                         $message "Danke für Deine Anmeldung.<br>Wir freuen uns auf Dich!";
  768.                         break;
  769.                     case "EN":
  770.                         $message "Thanks, Your application is now approved.<br>We are looking forward to having you!";
  771.                         break;
  772.                 }
  773.                 if ($productNumber $request->get('productnumber') or $provider == 'stripe'){
  774.                     ## productNumber is only given in case of sign up
  775.                     switch ($lang) {
  776.                         case "DE":
  777.                             $message "Danke für Deine Buchung.<br>Wir freuen uns auf Dich!";
  778.                             break;
  779.                         case "EN":
  780.                             $message "Thanks, Your booking was successful.<br>We are looking forward to having you!";
  781.                             break;
  782.                     }
  783.                     $account      $request->get('account');
  784.                     $customerHash $request->get('customerId');
  785.                     $subscriptionHash $request->get('subscriptionId');
  786.                     if (!$member) {
  787.                         $member $em->getRepository(Member::class)->find($application->getMemberId());
  788.                     }
  789.                     if (array_key_exists("setAiHubMembership"$settings)) {
  790.                         // Hole den Status aus den Einstellungen
  791.                         $aiMembershipStatus $settings["setAiHubMembership"];
  792.                         // Setze das Start- und Enddatum basierend auf dem aktuellen Datum und dem Status
  793.                         $aiMembershipStartDate = new DateTime();  // Setze auf aktuelles Datum und Uhrzeit
  794.                         $aiMembershipEndDate = clone $aiMembershipStartDate;
  795.                         if ($aiMembershipStatus === 'trial') {
  796.                             $aiMembershipEndDate->modify('+1 month');
  797.                         } elseif ($aiMembershipStatus === 'active') {
  798.                             $aiMembershipEndDate->modify('+3 months');
  799.                         }
  800.                         // Setze den Grund für die Mitgliedschaft
  801.                         $reason "Buy of {$productNumber}";
  802.                         // Erstelle oder aktualisiere das Service-Objekt mit den neuen Daten
  803.                         // (Du müsstest diese Logik entsprechend deiner Anwendung implementieren)
  804.                         $service = new Service();  // oder hole ein existierendes Service-Objekt
  805.                         $service->setStatus($aiMembershipStatus);
  806.                         $service->setStartDate($aiMembershipStartDate);
  807.                         $service->setEndDate($aiMembershipEndDate);
  808.                         // Rufe die setAiHubMembership Funktion auf
  809.                         $successContent[] = $em->getRepository(Member::class)->setAiHubMembership($service$member$reason);
  810.                     }
  811.                     $loginLink null;
  812.                     $targetPath $this->generateUrl('x_membership_first-steps', ['productNumber' => $productNumber'account' => $account]);
  813.                     $this->addFlash('notice'$message);
  814.                     if (!$user $this->getUser()) {
  815.                         $loginLink $this->loginService->getLoginLinkByTargetPath($member->getEmail(), $targetPath);
  816.                         $user $em->getRepository(User::class)->findOneBy(['memberId'=>$member->getId()]);
  817.                     }
  818.                     $feedback $this->eventNotificationService->sendConfirmationMail($usernull$settings$application$batch);
  819.                     if ($provider == 'stripe'){
  820.                         $mailContent = [
  821.                             'applicationId' => $application->getId(),
  822.                             'memberId' => $application->getMemberId(),
  823.                             'editStatus' => $application->getEditStatus(),
  824.                             'applicationStatus' => $application->getApplicationStatus(),
  825.                             'person' => $application->getPerson(),
  826.                             'email' => $application->getEmail(),
  827.                             'utmSource' => $application->getUtmSource(),
  828.                             'batchSlug' => $application->getBatchSlug(),
  829.                         ];
  830.                         $response $this->mailService->send("stripe step two {$application->getBatchId()} {$application->getEmail()}"'support@startplatz.de''Monitoring Stripe''lorenz.graef@startplatz.de''Lorenz'print_r($mailContent,true), false);
  831.                         return $application;
  832.                     } else {
  833.                         return isset($loginLink) ? $loginLink $targetPath;
  834.                     }
  835.                 } else { // if productNumber is not defined
  836.                     if (!$user $this->getUser()) {
  837.                         $user $em->getRepository(User::class)->findOneBy(['memberId'=>$member->getId()]);
  838.                     }
  839.                     $feedback $this->eventNotificationService->sendConfirmationMail($usernull$settings$application$batch);
  840.                 }
  841.                 break;
  842.             case "sendMagicLinkForPayment":
  843.                 // create LoginLink and send email
  844.                 $customerId  $request->get('customerId');
  845.                 $feedbackUrl $this->eventPaymentService->sendMagicLinkForPayment($application$batch$customerId$route$routeParameters);
  846.                 return $feedbackUrl;
  847.             case "createConsumerMonsumAccount":
  848.             case "useExistingCustomerAccount":
  849.                 $customerId  $request->get('customerId');
  850.                 $checkoutUrl $this->eventPaymentService->prepareMonsumCheckout($application$batch$action$route$routeParameters$customerId);
  851.                 return $checkoutUrl;
  852.         }
  853.         // Return the modified $application object to the main controller
  854.         return $application;
  855.     }
  856.     private function validateEventApplication(Application $applicationMember $member$settings$batchstring $lang): array
  857.     {
  858.         $em $this->entityManager;
  859.         $message "";
  860.         $status "";
  861.         // Check if a confirmation email needs to be sent
  862.         $shouldSendConfirmationMail false;
  863.         $feedback null;
  864.         switch ($application->getEditStatus()) {
  865.             case "error:validateLogin":
  866.                 $application->setEditStatus('success:validatedLogin');
  867.                 $application->setEditMessage("Application has been validated by {$member->getEmail()}");
  868.                 $application $em->getRepository(Application::class)->setHistory($application$application->getEditMessage());
  869.                 $application $em->getRepository(Application::class)->setApplication($application$member);
  870.                 $status "success";
  871.                 $shouldSendConfirmationMail true;
  872.                 break;
  873.             case "error:validateEmail":
  874.                 $application->setEditStatus('success:validatedEmail');
  875.                 $application->setEditMessage("Email of this Application has been validated by {$member->getEmail()}");
  876.                 $application $em->getRepository(Application::class)->setHistory($application$application->getEditMessage());
  877.                 if ($application->getApplicationStatus() == 'started') {
  878.                     $application->setApplicationStatus('applied');
  879.                 }
  880.                 $application $em->getRepository(Application::class)->setApplication($application$member);
  881.                 $status "success";
  882.                 $shouldSendConfirmationMail true;
  883.                 break;
  884.         }
  885.         if ($shouldSendConfirmationMail) {
  886.             // Logic to send confirmation mail
  887.             $feedback $this->eventNotificationService->sendConfirmationMail(null$member$settings$application$batch);
  888.         }
  889.         if ($status == "success") {
  890.             $application $em->getRepository(Application::class)->setApplicationApplied($application$member);
  891.             switch ($lang) {
  892.                 case "DE":
  893.                     $message "SUCCESS Danke, Deine Anmeldung ist jetzt bestätigt. Wir freuen uns auf Dich!";
  894.                     if ($feedback){
  895.                         $message .= "<br>Wir haben Dir eine Bestätigungsmail geschickt. Bitte prüfe Deinen Posteingang.";
  896.                     }
  897.                     break;
  898.                 case "EN":
  899.                     $message "SUCCESS Thanks, Your application is now approved. We are looking forward to having you!";
  900.                     if ($feedback){
  901.                         $message .= "<br>We have sent you a confirmation mail. Please check your inbox!";
  902.                     }
  903.                     break;
  904.             }
  905.             $this->addFlash('notice'$message);
  906.         }
  907.         return [
  908.             'data' => [
  909.                 'application' => $application,
  910.             ],
  911.             'message' => $message,
  912.             'status' => $status,
  913.         ];
  914.     }
  915.     private function shouldSetAiHubMembership($settings$applicationStatus)
  916.     {
  917.         return array_key_exists("setAiHubMembership"$settings) && $applicationStatus === 'applied';
  918.     }
  919.     private function configureServiceForAiHub($statusDateTime $startDate)
  920.     {
  921.         $service = new Service();  // oder hole ein existierendes Service-Objekt
  922.         $endDate = clone $startDate;
  923.         if ($status === 'trial') {
  924.             $endDate->modify('+1 month');
  925.         } elseif ($status === 'active') {
  926.             $endDate->modify('+3 months');
  927.         }
  928.         $service->setStatus($status);
  929.         $service->setStartDate($startDate);
  930.         $service->setEndDate($endDate);
  931.         return $service;
  932.     }
  933.     private function updateApplication(Application $application$differences)
  934.     {
  935.         foreach ($differences as $diff => $value) {
  936.             $method 'set' ucfirst((string) $diff);
  937.             if (method_exists($application$method)) {
  938.                 $application->$method($value);
  939.             }
  940.         }
  941.         return $application;
  942.     }
  943. }