src/StartPlatz/Bundle/RheinlandPitchBundle/Controller/ApplyController.php line 608

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace App\StartPlatz\Bundle\RheinlandPitchBundle\Controller;
  3. /**
  4.  * CRITICAL DEPENDENCY WARNING - EVENT REGISTRATION SYSTEM
  5.  * 
  6.  * This controller is heavily used by the EventBundle for event registrations.
  7.  * Event registration is the MOST IMPORTANT registration method for events.
  8.  * 
  9.  * DO NOT modify this controller without thoroughly testing event registration functionality.
  10.  * 
  11.  * Key dependencies from EventBundle:
  12.  * - EventBundle/Controller/DefaultController uses this for all internal event registrations
  13.  * - Event registration forms are rendered using templates from this bundle
  14.  * - Application workflow (validation, status management) is shared with events
  15.  * 
  16.  * Critical methods used by events:
  17.  * - applyAction() - Main registration form handling
  18.  * - Form validation and submission logic
  19.  * - Email validation workflows (validateEmail/validateLogin)
  20.  * - Application status management
  21.  * 
  22.  * Templates used by events:
  23.  * - Apply/_edit.registration.event.widget.html.twig
  24.  * - Apply/_edit.registration.widget.html.twig
  25.  * - Apply/apply.default.html.twig (for anonymous access)
  26.  * 
  27.  * IMPORTANT: Event registrations depend on:
  28.  * - Application entity structure
  29.  * - Form field definitions in ApplicationType
  30.  * - Validation logic and error handling
  31.  * - Email confirmation workflows
  32.  * - Member/Team assignment logic
  33.  * 
  34.  * See also:
  35.  * - EventBundle/Controller/DefaultController.php (lines 763-1000+ for registration logic)
  36.  * - StartupBundle/Entity/ApplicationRepository.php (for data operations)
  37.  * - Documentation: /doc/claude-files/application-process.md#event-integration
  38.  */
  39. use App\StartPlatz\Bundle\EventBundle\Entity\Event;
  40. use App\StartPlatz\Bundle\MailmanBundle\ConfirmationMailService;
  41. use App\StartPlatz\Bundle\MailmanBundle\Entity\MailTemplate;
  42. use App\StartPlatz\Bundle\MemberBundle\Entity\Member;
  43. use App\StartPlatz\Bundle\MemberBundle\Entity\MemberTeam;
  44. use App\StartPlatz\Bundle\MemberBundle\Entity\Option;
  45. use App\StartPlatz\Bundle\MemberBundle\Entity\Product;
  46. use App\StartPlatz\Bundle\MemberBundle\Entity\Team;
  47. use App\StartPlatz\Bundle\MetaBundle\Entity\Attribute;
  48. use App\StartPlatz\Bundle\MonsumBundle\Entity\Customer;
  49. use App\StartPlatz\Bundle\StartupBundle\Entity\Reminder;
  50. use App\StartPlatz\Bundle\StartupBundle\Entity\Startup;
  51. use App\StartPlatz\Bundle\WebsiteBundle\MenuTranslationService;
  52. use DateTime;
  53. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
  54. use Speicher210\CloudinaryBundle\Cloudinary\Api;
  55. use Symfony\Component\Mailer\MailerInterface;
  56. use Symfony\Component\Mime\Email;
  57. use Symfony\Component\Routing\Annotation\Route;
  58. use App\StartPlatz\Bundle\FeedbackBundle\CallbackService;
  59. use App\StartPlatz\Bundle\FeedbackBundle\Form\ContentPlainEditorFormType;
  60. use App\StartPlatz\Bundle\StartupBundle\Entity\Application;
  61. use App\StartPlatz\Bundle\StartupBundle\Entity\Batch;
  62. use App\StartPlatz\Bundle\StartupBundle\Entity\Program;
  63. use App\StartPlatz\Bundle\StartupBundle\Form\ApplicationType;
  64. use App\StartPlatz\Bundle\UserBundle\Entity\User;
  65. use App\StartPlatz\Bundle\UserBundle\Form\SetPasswordFormType;
  66. use App\StartPlatz\Bundle\UserBundle\LoginService;
  67. use App\StartPlatz\Bundle\WebsiteBundle\Utility\Utility;
  68. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  69. use Symfony\Component\HttpFoundation\Request;
  70. use Symfony\Component\HttpFoundation\Response;
  71. use Symfony\Component\HttpFoundation\Session\SessionInterface;
  72. use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
  73. use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
  74. use Symfony\Component\Stopwatch\Stopwatch;
  75. use Symfony\Component\Validator\Constraints as Assert;
  76. use Symfony\Component\Validator\Validation;
  77. use Twig\Environment;
  78. use Twig\Loader\ArrayLoader;
  79. class ApplyController extends AbstractController
  80. {
  81.     public function __construct(
  82.         private readonly SessionInterface             $session,
  83.         private readonly MailerInterface              $mailer,
  84.         private readonly CallbackService              $callbackService,
  85.         private readonly LoginService                 $loginService,
  86.         private readonly UserPasswordEncoderInterface $encoder,
  87.         private readonly MenuTranslationService       $menuTranslationService,
  88.         private readonly ConfirmationMailService      $confirmationMailService,
  89.         private readonly Api                          $cloudinary,
  90.         private readonly Stopwatch                    $stopwatch,
  91.     ) {
  92.     }
  93.     /*
  94.      * this page uses a collection of bootstrap4 pages
  95.      * https://colorlib.com/wp/template/meetup/
  96.      */
  97.     /**
  98.      * @Route("/apply/action/allmeda_application_set-application-done/{applicationId}", name="allmeda_application_set-application-done" )
  99.      * @Security("is_granted('ROLE_ADMIN')")
  100.      */
  101.     public function setApplicationDoneAction(Request $request$applicationId)
  102.     {
  103.         $em $this->getDoctrine()->getManager();
  104.         if (!$redirect json_decode(base64_decode($request->get('redirect')))) {
  105.             $redirect json_decode(json_encode(['path' => 'allmeda_doku_twig-render-mail-from-template''parameters' => []]));
  106.         }
  107.         $application $em->getRepository(Application::class)->findOneBy(['id' => $applicationId]);
  108.         $application $em->getRepository(Application::class)->setApplicationDone($application);
  109.         $application $em->getRepository(Application::class)->setApplication($application);
  110.         return $this->redirect($this->generateUrl($redirect->path, (array)$redirect->parameters));
  111.     }
  112.     /**
  113.      * @Route("/apply/action/allmeda_application_set-error-validate-email/{applicationId}", name="allmeda_application_set-error-validate-email" )
  114.      * @Security("is_granted('ROLE_ADMIN')")
  115.      */
  116.     public function setErrorValidateEmailAction(Request $request$applicationId)
  117.     {
  118.         $em $this->getDoctrine()->getManager();
  119.         if (!$redirect json_decode(base64_decode($request->get('redirect')))) {
  120.             $redirect json_decode(json_encode(['path' => 'allmeda_doku_twig-render-mail-from-template''parameters' => []]));
  121.         }
  122.         $application $em->getRepository(Application::class)->findOneBy(['id' => $applicationId]);
  123.         $application $em->getRepository(Application::class)->setApplicationStarted($application);
  124.         $application $em->getRepository(Application::class)->setErrorValidateEmail($application);
  125.         $application $em->getRepository(Application::class)->setApplication($application);
  126.         return $this->redirect($this->generateUrl($redirect->path, (array)$redirect->parameters));
  127.     }
  128.     /**
  129.      * @Route("/apply/action/allmeda_application_set-error-validate-login/{applicationId}", name="allmeda_application_set-error-validate-login" )
  130.      * @Security("is_granted('ROLE_ADMIN')")
  131.      */
  132.     public function setErrorValidateLoginAction(Request $request$applicationId)
  133.     {
  134.         $em $this->getDoctrine()->getManager();
  135.         if (!$redirect json_decode(base64_decode($request->get('redirect')))) {
  136.             $redirect json_decode(json_encode(['path' => 'allmeda_doku_twig-render-mail-from-template''parameters' => []]));
  137.         }
  138.         $application $em->getRepository(Application::class)->findOneBy(['id' => $applicationId]);
  139.         $application $em->getRepository(Application::class)->setApplicationStarted($application);
  140.         $application $em->getRepository(Application::class)->setErrorValidateLogin($application);
  141.         $application $em->getRepository(Application::class)->setApplication($application);
  142.         return $this->redirect($this->generateUrl($redirect->path, (array)$redirect->parameters));
  143.     }
  144.     /**
  145.      * @Route("/apply/action/list-tests", name="allmeda_startups_batches_test")
  146.      */
  147.     public function listTestsAction(Request $request)
  148.     {
  149.         /*
  150.          * Program Slug: rheinland-pitch // Batch Slug:
  151.          * Program Slug: startup-tools // Batch Slug: 01-twilio-sms-voice-whatsapp
  152.          * Program Slug: online-circle-sales // Batch Slug: 05-session
  153.          * Program Slug: startplatz-aob // Batch Slug: 01-interesse-an-effzeh-karten
  154.          * Program Slug: feedback-zu-deiner-startup-idee // Batch Slug: 19-sondersitzung-woche-13
  155.          * Program Slug: rheinland-pitch-zuschauer // Batch Slug: 100-jubilaeum
  156.          * Program Slug: membership // Batch Slug: 17041-test-startup-membership
  157.          */
  158.         $tests = [
  159.             'Rheinland-Pitch' => ['batchId' => 283'programSlug' => 'rheinland-pitch''batchSlug' => ''],
  160.             'Feedback' => ['batchId' => 298'programSlug' => 'feedback-zu-deiner-startup-idee''batchSlug' => ''],
  161.             'Startup Tools' => ['batchId' => 269'programSlug' => 'startup-tools''batchSlug' => '01-twilio-sms-voice-whatsapp'],
  162.             'Startup Tools AWS' => ['batchId' => 188'programSlug' => 'startup-tools''batchSlug' => '01-aws'],
  163.             'Online Circle' => ['batchId' => 386'programSlug' => 'online-circle-sales''batchSlug' => 'session-11'],
  164.             'OC Gründerstip.' => ['batchId' => 305'programSlug' => 'online-circle-gruenderstipendium''batchSlug' => '03-session'],
  165.             'RPitch-Zuschauer' => ['batchId' => 123'programSlug' => 'rheinland-pitch-zuschauer''batchSlug' => '100-jubilaeum'],
  166.             'Membership' => ['batchId' => 208'programSlug' => 'membership''batchSlug' => '17041-test-startup-membership'],
  167.             'Membership Trial' => ['batchId' => 360'programSlug' => 'membership''batchSlug' => '16017-cgn-trial-community-membership'],
  168.             'Event' => ['batchId' => 357'programSlug' => 'businessclub-politischer-dialog''batchSlug' => 'spd-08-07-2021'],
  169.             'Sign Up Mentor' => ['batchId' => 391'programSlug' => 'sign-up''batchSlug' => 'mentor-registration-01'],
  170.         ];
  171.         return $this->render('@StartPlatzRheinlandPitchBundle/Apply/list-tests.html.twig', [
  172.             'tests' => $tests,
  173.             'menuLinksAndPhrases' => $this->menuTranslationService->getMenuLinksAndPhrases($request->server->get('REQUEST_URI')),
  174.         ]);
  175.     }
  176.     /**
  177.      * @Route("/apply/action/add-to-podio/{batchId}/{applicationId}", name="apply_action_add-to-podio")
  178.      */
  179.     public function triggerPodioAction(Request $request$batchId$applicationId)
  180.     {
  181.         $em $this->getDoctrine()->getManager();
  182.         $responseContent "";
  183.         $action $request->get('action');
  184.         $batch $em->getRepository(Batch::class)->find($batchId);
  185.         $application $em->getRepository(Application::class)->find($applicationId);
  186.         if ($batch->getProgram()->getSlug() == 'accelerator') {
  187.             $responseContent $this->addApplicationToPodioByZapier($application$batch$action);
  188.         } else {
  189.             $responseContent $this->addApplicationToPodioByZapierSwitch($application$batch);
  190.         }
  191.         $response = new Response();
  192.         $response->setContent(json_encode($responseContent));
  193.         $response->headers->set('Content-Type''application/json');
  194.         return $response;
  195.     }
  196.     /**
  197.      * @Route("/apply/action/run-workflow/{applicationId}", name="apply_action_run-workflow")
  198.      */
  199.     public function runWorkflow(Request $request$applicationId)
  200.     {
  201.         $em $this->getDoctrine()->getManager();
  202.         $responseContent "";
  203.         $application $em->getRepository(Application::class)->find($applicationId);
  204.         $message $em->getRepository(Application::class)->runApplicationDoneWorkflow($application);
  205.         $responseContent "workflow set for application with id={$applicationId} and {$message}";
  206.         $this->session->getFlashBag()->add('notice'$responseContent );
  207.         return $this->redirect($this->generateUrl("allmeda_applications_home", ['filter'=>"batchId:{$application->getBatchId()}"]));
  208.     }
  209.     /**
  210.      * @Route("/apply/action/update-from-podio/{applicationId}", name="apply_action_update-from-podio")
  211.      */
  212.     public function triggerPodioUpdateAction(Request $request$applicationId)
  213.     {
  214.         $em $this->getDoctrine()->getManager();
  215.         $responseContent "";
  216.         $application $em->getRepository(Application::class)->find($applicationId);
  217.         $payload json_encode([
  218.             'applicationId' => $application->getId(),
  219.             'podioId' => $application->getPodioId() ? $application->getPodioId() : "",
  220.             'podioItemId' => $application->getPodioItemId() ? $application->getPodioItemId() : "",
  221.             'startupName' => $application->getStartupName(),
  222.         ]);
  223.         if ($application->getPodioItemId()) {
  224.             $callbackUrl "https://hooks.zapier.com/hooks/catch/1872803/bxkn68s/";
  225.         } else {
  226.             $callbackUrl "https://hooks.zapier.com/hooks/catch/1872803/bxkn68s/";
  227.         }
  228.         $responseContent $this->callbackService->curl_callback($callbackUrl$payload);
  229.         $response = new Response();
  230.         $response->setContent(json_encode($responseContent));
  231.         $response->headers->set('Content-Type''application/json');
  232.         return $response;
  233.     }
  234.     /**
  235.      * @Route("/apply/action/podio-to-allmeda", name="apply_action_podio-to-allmeda")
  236.      */
  237.     public function podioToAllmedaAction(Request $request)
  238.     {
  239.         $em $this->getDoctrine()->getManager();
  240.         $parameters $request->getContent();
  241.         $response = new Response();
  242.         $response->setContent(json_encode(["status" => "success"]));
  243.         $apikey $request->headers->get('apikey');
  244.         if ($apikey != '50670') {
  245.             $response->setContent(json_encode(["status" => "error"]));
  246.         }
  247.         $parameters json_decode($parameters);
  248.         $applicationId $parameters->applicationId;
  249.         $podioId $parameters->podioId;
  250.         $podioItemId $parameters->podioItemId;
  251.         $podioUrl $parameters->podioUrl;
  252.         if ($application $em->getRepository(Application::class)->find($applicationId)) {
  253.             $application->setPodioId($podioId);
  254.             $application->setPodioItemId($podioItemId);
  255.             $application->setPodioUrl($podioUrl);
  256.             $em->persist($application);
  257.             $em->flush();
  258.         }
  259.         $response->headers->set('Content-Type''application/json');
  260.         return $response;
  261.     }
  262.     /**
  263.      * @Route("/apply/settings", defaults={"program" = "example", "batch" = "batch11"})
  264.      * @Route("/apply/{program}/settings", defaults={"batch" = "general"})
  265.      * @Route("/apply/{program}/{batch}/settings", name="apply_settings")
  266.      * @Security("is_granted('ROLE_ADMIN')")
  267.      */
  268.     public function setSettingsAction(Request $request$program$batch)
  269.     {
  270.         $em $this->getDoctrine()->getManager();
  271.         $now = new datetime();
  272.         $metaName "settings.program.{$program}.{$batch}";
  273.         if (!$settingsProgram $em->getRepository(Option::class)->getOptionMetaValue($metaName)) {
  274.             if (!$settingsProgram $em->getRepository(Option::class)->getOptionMetaValue($metaName)) {
  275.                 $settingsProgram $this->getSettingsProgramDefault();
  276.                 $em->getRepository(Option::class)->setOptionMetaValueJsonEncoded($metaName"settingsProgram"$settingsProgram);
  277.             }
  278.         }
  279.         $content Utility::transformArrayAssocIntoCsvString($settingsProgram);
  280.         $data['content'] = $content;
  281.         $form $this->createForm(ContentPlainEditorFormType::class, $data);
  282.         $form->handleRequest($request);
  283.         if ($form->isSubmitted() && $form->isValid()) {
  284.             $data $form->getData();
  285.             $importString $data['content'];
  286.             $rows explode(PHP_EOL, (string) $importString);
  287.             foreach ($rows as $row) {
  288.                 $parts str_getcsv($row"\t");
  289.                 $settingsProgram[$parts[0]] = $parts[1];
  290.             }
  291.             $metaName "settings.program.{$settingsProgram['programSlug']}.{$settingsProgram['batchSlug']}";
  292.             $em->getRepository(Option::class)->setOptionMetaValueJsonEncoded($metaNamenull$settingsProgram);
  293.             $this->session->getFlashBag()->add('notice''SUCCESS data saved');
  294.             $this->redirect($this->generateUrl('apply_settings', ['program' => $settingsProgram['programSlug'], 'batch' => $settingsProgram['batchSlug']]));
  295.         }
  296.         return $this->render('@StartPlatzRheinlandPitchBundle/Apply/settings.html.twig', [
  297.             'settings' => $settingsProgram,
  298.             'event' => $em->getRepository(Event::class)->findOneBy(['id' => '4982']),
  299.             'form' => $form->createView(),
  300.             'redirectUrl' => base64_encode(json_encode(['path' => 'apply_settings''parameters' => []])),
  301.         ]);
  302.     }
  303.     /**
  304.      * @Route("/apply/", name="apply_home")
  305.      */
  306.     public function indexAction(Request $request)
  307.     {
  308.         $em $this->getDoctrine()->getManager();
  309.         $batches $em->getRepository(Batch::class)->findOpenApplications(['programId' => ['1''3''8'], 'visibility' => 'public']);
  310.         return $this->render('@StartPlatzRheinlandPitchBundle/Apply/index.html.twig', [
  311.             'batches' => $batches,
  312.             'redirectUrl' => base64_encode(json_encode(['path' => 'apply_home''parameters' => []])),
  313.         ]);
  314.     }
  315.     /**
  316.      * @Route("/apply/{programSlug}", name="apply_program_redirect-to-next-open-application")
  317.      */
  318.     public function findNextOpenApplicationAction(Request $request$programSlug)
  319.     {
  320.         $em $this->getDoctrine()->getManager();
  321.         $test $request->get('test');
  322.         if (!$program $em->getRepository(Program::class /*Startup Program*/)->findOneBy(['slug' => $programSlug])) {
  323.             $this->session->getFlashBag()->add('notice''ERROR Sorry, no program found');
  324.             return $this->redirect($this->generateUrl('apply_home', []));
  325.         }
  326.         $sorry "Sorry, no open application for {$program->getName()} right now";
  327.         if ($batch $em->getRepository(Batch::class)->findOpenApplicationsByProgram($program)) {
  328.             if ($test) {
  329.                 return $this->redirect($this->generateUrl('apply_program_home', ['programSlug' => $programSlug'batchSlug' => $batch->getSlug(), 'test' => $test]));
  330.             } else {
  331.                 return $this->redirect($this->generateUrl('apply_program_home', ['programSlug' => $programSlug'batchSlug' => $batch->getSlug()]));
  332.             }
  333.         } else {
  334.             $this->session->getFlashBag()->add('notice''ERROR ' $sorry);
  335.             return $this->redirect($this->generateUrl('apply_home', []));
  336.         }
  337.     }
  338.     /**
  339.      * @Route("/apply/{programSlug}/{batchSlug}/{id}/monsum-checkout", name="apply_program_monsum-checkout")
  340.      */
  341.     public function checkoutAction(Request $request$programSlug$batchSlug$id)
  342.     {
  343.         $em $this->getDoctrine()->getManager();
  344.         $now = new datetime();
  345.         /** @var User $user */
  346.         $user $this->getUser();
  347.         $em->getRepository(User::class)->writeActivity($user);
  348.         if (!$program $em->getRepository(Program::class /*Startup Program*/)->findOneBy(['slug' => $programSlug])) {
  349.             $this->session->getFlashBag()->add('notice''ERROR Sorry, no program found');
  350.             return $this->redirect($this->generateUrl('apply_home', []));
  351.         }
  352.         if (!$batch $em->getRepository(Batch::class)->findOneBy(['slug' => $batchSlug'program' => $program])) {
  353.             $this->session->getFlashBag()->add('notice''ERROR Sorry, no batch found');
  354.             return $this->redirect($this->generateUrl('apply_home', []));
  355.         }
  356.         if ($customerHash $request->get('customerId')) {
  357.             $customer $em->getRepository(Customer::class)->findOneBy(['hash' => $customerHash]);
  358.             $teamId $customer->getTeamId();
  359.             $team $em->getRepository(Team::class)->findOneBy(['id' => $teamId]);
  360.         }
  361.         $settings $em->getRepository(Application::class)->getSettingsProgram($program$batch);
  362.         $productNumber $batch->getBatchNumber();
  363.         $account $this->getAccountBySlug($batchSlug);
  364.         $accountHash $em->getRepository(Customer::class)->getAccountHashByAccount($account);
  365.         $promocode $request->get('promocode') ? $request->get('promocode') : '';
  366.         if (isset($settings['isFrame']) and $settings['isFrame']) {
  367.             return $this->render('@StartPlatzRheinlandPitchBundle/Apply/monsum.checkout.html.twig', [
  368.                 'accountHash' => $accountHash,
  369.                 'customerHash' => $customerHash,
  370.                 'productNumber' => $productNumber,
  371.                 'settings' => $settings,
  372.                 'redirectUrl' => base64_encode(json_encode(['path' => 'rheinland-pitch_apply_home''parameters' => []])),
  373.                 'menuLinksAndPhrases' => $this->menuTranslationService->getMenuLinksAndPhrases($request->server->get('REQUEST_URI')),
  374.             ]);
  375.         } else {
  376.             if ($promocode) {
  377.                 return $this->redirect("https://app.monsum.com/checkout/0/{$accountHash}/{$customerHash}/{$productNumber}&promocode={$promocode}&x_applicationId={$id}");
  378.             } else {
  379.                 return $this->redirect("https://app.monsum.com/checkout/0/{$accountHash}/{$customerHash}/{$productNumber}&x_applicationId={$id}");
  380.             }
  381.             /* Gerrit stash membership 11.4.23
  382.             if ($promocode) {
  383.                 return $this->redirect("https://app.monsum.com/checkout/0/{$accountHash}/{$customerHash}/{$productNumber}&promocode={$promocode}&x_applicationId={$id}&success_url={$successUrl}");
  384.             } else {
  385.                 return $this->redirect("https://app.monsum.com/checkout/0/{$accountHash}/{$customerHash}/{$productNumber}&x_applicationId={$id}&success_url={$successUrl}");
  386.             }
  387.             */
  388.         }
  389.         /*
  390.         Rückgabe von Monsum auf
  391.         https://www.startplatz.de/x/membership/receipt-monsum/17048?customerId=6a982bbfe539c9cb0ba1ca967210e0cc&subscriptionId=83add62a2825deabc141b278bd7f1fe3
  392.          */
  393.     }
  394.     private function getAccountBySlug($slug)
  395.     {
  396.         $accountShortName explode('-'$slug)[1];
  397.         $accounts = [
  398.             "cgn" => "SP-CGN",
  399.             "dus" => "SP-DUS",
  400.             "test" => "TESTPLATZ",
  401.         ];
  402.         return $accounts[$accountShortName];
  403.     }
  404.     /**
  405.      * @Route("/access/startup-membership/{programSlug}/{batchSlug}/", name="access_startup-membership")
  406.      * @Security("is_granted('ROLE_USER')")
  407.      */
  408.     public function hasStartupMembershipAction(Request $request$programSlug$batchSlug)
  409.     {
  410.         $em $this->getDoctrine()->getManager();
  411.         /** @var User $user */
  412.         $user $this->getUser();
  413.         $em->getRepository(User::class)->writeActivity($user);
  414.         if (!$program $em->getRepository(Program::class /*Startup Program*/)->findOneBy(['slug' => $programSlug])) {
  415.             $this->session->getFlashBag()->add('notice''ERROR Sorry, no program found');
  416.             return $this->redirect($this->generateUrl('apply_home', []));
  417.         }
  418.         if (!$batch $em->getRepository(Batch::class)->findOneBy(['slug' => $batchSlug'program' => $program])) {
  419.             $this->session->getFlashBag()->add('notice''ERROR Sorry, no batch found');
  420.             return $this->redirect($this->generateUrl('apply_home', []));
  421.         }
  422.         $settings = [
  423.             'bgImage' => 'https://res.cloudinary.com/startplatz/image/upload/v1610197223/applications/backgrounds/friendly-coworking.png',
  424.         ];
  425.         return $this->render('@StartPlatzRheinlandPitchBundle/Apply/checkHasStartupMembership.html.twig', [
  426.             'program' => $program,
  427.             'batch' => $batch,
  428.             'settings' => $settings,
  429.             'product' => ['name' => 'test'],
  430.             'action' => 'default',
  431.             'application' => ['websiteUrl' => ''],
  432.             'redirectUrl' => base64_encode(json_encode(['path' => 'rheinland-pitch_apply_home''parameters' => []])),
  433.             'menuLinksAndPhrases' => $this->menuTranslationService->getMenuLinksAndPhrases($request->server->get('REQUEST_URI')),
  434.         ]);
  435.     }
  436.     /**
  437.      * @Route("/apply/rheinland-pitch/startup-academy-pitch-night-bewerbungen-00", name="redirect_applications")
  438.      */
  439.     public function redirectApplicationAction()
  440.     {
  441.         return $this->redirect($this->generateUrl('apply_program_home', ['programSlug' => 'event''batchSlug' => 'startup-academy-pitch-night-bewerbungen-01''id' => 'start']));
  442.     }
  443.     private function getExtraFieldsAttributes($settings)
  444.     {
  445.         if (!isset($settings['extraFields'])) {
  446.             return $settings;
  447.         }
  448.         $em $this->getDoctrine()->getManager();
  449.         $extraFields $settings['extraFields'];
  450.         $i 0;
  451.         foreach ($extraFields as $extraField) {
  452.             if ($extraField['type'] == 'choice') {
  453.                 $choices = [];
  454.                 if (isset($extraField['arr'])) {
  455.                     $choices $em->getRepository(Attribute::class)->findCodesByAttributeName($extraField['arr']);
  456.                 }
  457.                 $settings['extraFields'][$i]['choices'] = $choices;
  458.             }
  459.             $i++;
  460.         }
  461.         return $settings;
  462.     }
  463.     private function getExtraFieldsData(Application $application$settings$form)
  464.     {
  465.         $extraFields $settings['extraFields'];
  466.         $data = [];
  467.         $i 0;
  468.         foreach ($extraFields as $extraField) {
  469.             $data[$extraField['field']] = $form->get($extraField['field'])->getData();
  470.             $i++;
  471.         }
  472.         if ($data) {
  473.             $application->setExtraFields(json_encode($data)) ;
  474.         }
  475.         return $application;
  476.     }
  477.     /**
  478.      * @Route("/schnuppermitgliedschaft-buchen/welcome/{id}", name="schnuppermitgliedschaft_buchen_welcome_de")
  479.      * @Route("/schnuppermitgliedschaft-buchen/{id}", name="schnuppermitgliedschaft_buchen_de")
  480.      * @Route("/schnuppermitgliedschaft-team-buchen/welcome/{id}", name="schnuppermitgliedschaft_team_buchen_welcome_de")
  481.      * @Route("/schnuppermitgliedschaft-team-buchen/{id}", name="schnuppermitgliedschaft_team_buchen_de")
  482.      * @Route("/startup-academy-test-mitgliedschaft-buchen/{id}", name="startup-academy-test-mitgliedschaft_buchen_de")
  483.      * @Route("/trial-membership-register/{id}", name="schnuppermitgliedschaft_buchen_en")
  484.      * @Route("/trial-membership-register/{id}", name="schnuppermitgliedschaft_buchen_en")
  485.      * @Route("/free-token/{id}", name="free-token")
  486.      * @Route("/apply/{programSlug}/{batchSlug}/{id}", name="apply_program_home")
  487.      * @Route("/{lang}/apply/{programSlug}/{batchSlug}/{id}", name="apply_program_home_lang")
  488.      */
  489.     public function applyAction(Request $request$programSlug 'undef'$batchSlug 'undef'$id 'start'$lang null)
  490.     {
  491.         ##apply
  492.         $em $this->getDoctrine()->getManager();
  493.         $now = new datetime();
  494.         $pathInfo $request->getPathInfo();
  495.         $host $request->getHost();
  496.         $test $request->get('test');
  497.         $routeName $request->get('_route');
  498.         $routeParameters $request->get('_route_params');
  499.         $isMemberloggedIn false;
  500.         $isEmailRegistered false;
  501.         $product null;
  502.         $landingPageContent "";
  503.         $landingPageTwig "";
  504.         $lang strtoupper($lang ?? 'DE');
  505.         $priceAndDiscount = [];
  506.         $settings = []; // array contains specific definitions in relation to program, batch and template
  507.         // Retrieve the UTM parameters from the URL
  508.         $utmParameters = [
  509.             'utmSource'   => $request->query->get('utm_source'),
  510.             'utmMedium'   => $request->query->get('utm_medium'),
  511.             'utmCampaign' => $request->query->get('utm_campaign'),
  512.             'utmTerm'     => $request->query->get('utm_term'),
  513.             'utmContent'  => $request->query->get('utm_content'),
  514.         ];
  515.         if ($routeName != 'apply_program_home' && $routeName != 'apply_program_home_lang') {
  516.             ## evaluate special routes like 'schnuppermitgliedschaft_buchen_en' ########################
  517.             if (!$response $this->evaluateAliasSlug($routeName)) {
  518.                 $this->session->getFlashBag()->add('notice''ERROR url is invalid');
  519.                 return $this->redirect($this->generateUrl('apply_home', []));
  520.             } else {
  521.                 /** @var Program $program */
  522.                 $program $response['data']['program'];
  523.                 /** @var Batch $batch */
  524.                 $batch $response['data']['batch'];
  525.                 $batchSlug $batch->getSlug();
  526.                 $programSlug $program->getSlug();
  527.             }
  528.             ## end of route evaluation
  529.         } else {
  530.             ## find program and batch by the default way ############
  531.             /** @var Program $program */
  532.             if (!$program $em->getRepository(Program::class /*Startup Program*/)->findOneBy(['slug' => $programSlug])) {
  533.                 $this->session->getFlashBag()->add('notice''ERROR Sorry, no program found');
  534.                 return $this->redirect($this->generateUrl('apply_home', []));
  535.             }
  536.             if (!$batch $em->getRepository(Batch::class)->findOneBy(['slug' => $batchSlug'program' => $program])) {
  537.                 $this->session->getFlashBag()->add('notice''ERROR Sorry, no batch found');
  538.                 return $this->redirect($this->generateUrl('apply_home', []));
  539.             }
  540.         }
  541.         if ($program->getSlug() == 'membership') {
  542.             $productNumber $batch->getBatchNumber();
  543.             $account $this->getAccountBySlug($batchSlug);
  544.             // find product by productNumber, account and agent == monsum
  545.             $product $em->getRepository(Product::class /*Product Member*/)->findOneBy(['account' => $account'productNumber' => $productNumber'agent' => 'monsum']);
  546.         }
  547.         ##-- now we know program and batch (and product if membership) --##
  548.         // check if application is still open
  549.         if ($batch->getStatus() == 'inactive') {
  550.             $this->session->getFlashBag()->add('notice''ERROR Sorry, application is currently not active');
  551.             return $this->redirect($this->generateUrl('apply_home', []));
  552.         }
  553.         ## is application open
  554.         ##toBeTested
  555.         $response $em->getRepository(Batch::class)->isApplicationOpen($batch);
  556.         if ($response['status'] == 'error') {
  557.             $this->session->getFlashBag()->add('notice'$response['message']);
  558.             return $this->redirect($this->generateUrl('apply_home', []));
  559.         }
  560.         // check if settings contains necessary setters
  561.         $batch $em->getRepository(Batch::class)->checkLegacyData($batch);
  562.         // settings for program and batch will be merged
  563.         $settings $em->getRepository(Application::class)->getSettingsProgram($program$batch);
  564.         // check LoginStatus
  565.         /** @var User $user */
  566.         if ($user $this->getUser()) {
  567.             ## user is logged in. this will be the default case ############
  568.             $adminEmail $user->getEmail();
  569.             $em->getRepository(User::class)->writeActivity($user);
  570.             /** @var Member $member */
  571.             $member $em->getRepository(Member::class)->find($user->getMemberId());
  572.             $isMemberloggedIn true;
  573.         } else {
  574.             ## if user is not logged in - kick her out except it is allowed to access batch without being logged in
  575.             if ($batch->getAccess() != 'anonymous') {
  576.                 // Pass the UTM parameters along with other necessary arguments to the createApplicationByApplyForm method
  577.                 $application $em->getRepository(Application::class)->createApplicationByApplyForm(
  578.                     $program,
  579.                     $batch,
  580.                     $lang,
  581.                     $priceAndDiscount,
  582.                     $utmParameters  // This is the array you created earlier
  583.                 );
  584.                 return $this->render('@StartPlatzRheinlandPitchBundle/Apply/apply.default.html.twig', [
  585.                     'settings' => $settings,
  586.                     'program' => $program,
  587.                     'batch' => $batch,
  588.                     'test' => $test,
  589.                     'application' => $application,
  590.                     'applicationId' => $id,
  591.                     'phrases' => $em->getRepository(Option::class)->getApplicationPhrases($program$batch$product$lang),
  592.                     'redirectUrl' => base64_encode(json_encode(['path' => 'apply_program_home_lang''parameters' => ['id' => $id'programSlug' => $programSlug'batchSlug' => $batchSlug], 'lang' => strtolower($lang)])),
  593.                     'menuLinksAndPhrases' => $this->menuTranslationService->getMenuLinksAndPhrases($request->server->get('REQUEST_URI')),
  594.                 ]);
  595.             }
  596.             $member $em->getRepository(Member::class)->setEmptyMemberAccount();
  597.         }
  598.         $settings['isMemberloggedIn'] = $isMemberloggedIn;
  599.         if ($isMemberloggedIn) {
  600.             // check access conditions
  601.             if ($batch->getAccess() == 'hasStartupMembership') {
  602.                 $team $em->getRepository(Team::class)->findOneBy(['id' => $user->getTeamId()]);
  603.                 if (!$team->getHasStartupMembership()) {
  604.                     return $this->redirect($this->generateUrl('access_startup-membership', ['programSlug' => $programSlug'batchSlug' => $batchSlug'id' => $id]));
  605.                 }
  606.             }
  607.             // check is missing if Community Membership
  608.         }
  609.         ## -- settings -- #############
  610.         // important distinction - is it necessary to bind this application to a team
  611.         // or is it okay to bind it with a person only
  612.         // event are normally person only, applications for accelerator need a team
  613.         // it can be defined via batch (isMultipleApplicationsPerTeam)
  614.         // but in every case an application need to be tied to a member and at least a virtual team
  615.         // we need to keep track is a member team relationship has been set
  616.         // because either member or team can be created during application process
  617.         $_isMemberTeamRelationSet 0;
  618.         // for memberships we need the product type
  619.         $settings['productType'] = 'Applicant';
  620.         if ($product) {
  621.             $settings['productType'] = $product->getType();
  622.         }
  623.         // we set an virtual team as fallback if no new allmeda team is needed to process the request
  624.         $virtualTeam array_key_exists('virtualTeam'$settings) ? $settings['virtualTeam'] : 'applicants';
  625.         // access the relevant virtual team or create that team if it does not exists
  626.         $applicantsTeam $em->getRepository(Team::class)->getVirtualTeamByName($virtualTeam);
  627.         $adminEmail $user $user->getEmail() : "";
  628.         $application null;
  629.         // find application or create new one if id = start
  630.         if ($id == 'start') {
  631.             if ($teamId $request->get('teamId') and $user and $teamId 0) {
  632.                 if (!$em->getRepository(MemberTeam::class)->isMemberOfTeam($user->getMemberId(), $teamId)) {
  633.                     $this->session->getFlashBag()->add('notice''ERROR 01 no access to team');
  634.                     return $this->redirect($this->generateUrl('apply_program_home_lang', ['id' => $id'programSlug' => $programSlug'batchSlug' => $batchSlug'lang' => strtolower($lang)]));
  635.                 }
  636.                 if ($application $em->getRepository(Application::class)->findOneBy(['teamId' => $teamId'programSlug' => $programSlug'batchSlug' => $batchSlug])) {
  637.                     $this->session->getFlashBag()->add('notice''SUCCESS application for your team found');
  638.                     return $this->redirect($this->generateUrl('apply_program_home_lang', ['id' => $application->getId(), 'programSlug' => $programSlug'batchSlug' => $batchSlug'lang' => strtolower($lang)]));
  639.                 }
  640.             }
  641.             if ($batch->isMultipleApplicationsPerTeam() and $user) {
  642.                 // look up application of that member
  643.                 $application $em->getRepository(Application::class)->findOneBy(['batchId' => $batch->getId(), 'memberId' => $user->getMemberId()]);
  644.             } elseif ($user) {
  645.                 if (!$batch->isMultipleApplicationsPerMember()) {
  646.                     // look up application of that team
  647.                     if (!$application $em->getRepository(Application::class)->findOneBy(['batchId' => $batch->getId(), 'teamId' => $user->getTeamId()])) {
  648.                         // if there is no application bound with the primary team of the member look for an application bound with that member directly
  649.                         $application $em->getRepository(Application::class)->findOneBy(['batchId' => $batch->getId(), 'memberId' => $user->getMemberId()]);
  650.                     }
  651.                 }
  652.             }
  653.             if ($application) {
  654.                 $member $em->getRepository(Member::class)->find($application->getMemberId());
  655.                 $teamId $request->get('teamId') ? $request->get('teamId') : $application->getTeamId();
  656.                 $team $this->setTeam($member$settings$teamId$applicantsTeam);
  657.             } else { // create new application
  658.                 // Pass the UTM parameters along with other necessary arguments to the createApplicationByApplyForm method
  659.                 $application $em->getRepository(Application::class)->createApplicationByApplyForm(
  660.                     $program,
  661.                     $batch,
  662.                     $lang,
  663.                     $priceAndDiscount,
  664.                     $utmParameters  // This is the array you created earlier
  665.                 );
  666.                 if ($program->getSlug() == 'membership') {
  667.                     if ($memberId $request->get('w')) {
  668.                         if ($werber $em->getRepository(Member::class)->find($memberId)) {
  669.                             $application->setRecommendedBy($werber->getEmail());
  670.                         }
  671.                     }
  672.                 }
  673.                 $member $em->getRepository(Application::class)->setMember($program$batch$applicantsTeam$user);
  674.                 $application $em->getRepository(Application::class)->updateApplicationByMember($application$member);
  675.                 if ($request->get('teamId')) {
  676.                     $teamId $request->get('teamId');
  677.                 } elseif ($user) {
  678.                     if ($settings['createAlwaysNewTeam']) {
  679.                         $teamId 0;
  680.                     } else {
  681.                         $teamId $user->getTeamId();
  682.                     }
  683.                 } else {
  684.                     $teamId 0;
  685.                 }
  686.                 $team $this->setTeam($member$settings$teamId$applicantsTeam);
  687.                 if ($settings['isTeamNeeded']) {
  688.                     $application $this->updateApplicationByTeam($application$team);
  689.                 } else {
  690.                     $teamId $applicantsTeam->getId();
  691.                     $application->setTeamId($teamId);
  692.                 }
  693.             }
  694.         } else {
  695.             if (!$application $em->getRepository(Application::class)->find($id)) {
  696.                 $this->session->getFlashBag()->add('notice''ERROR apply:01 - Application could not be found. You can create a new one');
  697.                 return $this->redirect($this->generateUrl('apply_program_home_lang', ['programSlug' => $programSlug'batchSlug' => $batchSlug'id' => 'start''lang' => strtolower($lang)]));
  698.             }
  699.             if ($application->getProgramSlug() != $programSlug or $application->getBatchSlug() != $batchSlug) {
  700.                 $this->session->getFlashBag()->add('notice''ERROR apply:011 - Application could not be found. You can create a new one');
  701.                 return $this->redirect($this->generateUrl('apply_program_home_lang', ['programSlug' => $programSlug'batchSlug' => $batchSlug'id' => 'start''lang' => strtolower($lang)]));
  702.             }
  703.             $canPassWithoutLogin = [
  704.                 "error:validateLogin",
  705.                 "error:validateEmail",
  706.             ];
  707.             if (!in_array($application->getEditStatus(), $canPassWithoutLogin)) {
  708.                 if (!$user) {
  709.                     $this->session->getFlashBag()->add('notice''ERROR apply:021 - Please Login first');
  710.                     return $this->redirect($this->generateUrl('apply_program_home_lang', ['programSlug' => $programSlug'batchSlug' => $batchSlug'id' => 'start''lang' => strtolower($lang)]));
  711.                 } else {
  712.                     if ($application->getMemberId() != $user->getMemberId() and $user) {
  713.                         $this->session->getFlashBag()->add('notice''ERROR apply:012 - Application could not be found. You can create a new one');
  714.                         return $this->redirect($this->generateUrl('apply_program_home_lang', ['programSlug' => $programSlug'batchSlug' => $batchSlug'id' => 'start''lang' => strtolower($lang)]));
  715.                     }
  716.                 }
  717.             }
  718.             if ($user) {
  719.                 if ($application->getMemberId() != $user->getMemberId()) {
  720.                     if (!$em->getRepository(MemberTeam::class)->isMemberOfTeam($user->getMemberId(), $application->getTeamId())) {
  721.                         $this->session->getFlashBag()->add('notice''ERROR apply:013 - No access to this application. You can create a new one');
  722.                         return $this->redirect($this->generateUrl('apply_program_home_lang', ['programSlug' => $programSlug'batchSlug' => $batchSlug'id' => 'start''lang' => strtolower($lang)]));
  723.                     }
  724.                 }
  725.             }
  726.             $teamId $request->get('teamId') ? $request->get('teamId') : $application->getTeamId();
  727.             $team $this->setTeam($member$settings$teamId$applicantsTeam);
  728.         }
  729.         ## now in every case there is an application
  730.         ## we need to check the language
  731.         if ($lang) {
  732.             if ($lang != $application->getLang()) {
  733.                 $application->setLang($lang);
  734.             }
  735.         } else {
  736.             $lang $application->getLang() ? $application->getLang() : $batch->getLang();
  737.         }
  738.         ## now in every case the variable $lang is set
  739.         // checkAccessRight for team if found by external teamId
  740.         if ($request->get('teamId') > and !$teamMember $em->getRepository(MemberTeam::class)->findOneBy(['team' => $team'member' => $member])) {
  741.             $this->session->getFlashBag()->add('notice''ERROR 02 no access to team');
  742.             return $this->redirect($this->generateUrl('apply_home'));
  743.         }
  744.         if ($adminEmail) {
  745.             $application->setLastChangeUser($adminEmail);
  746.         }
  747.         $action $request->get('action');
  748.         // action can be only set to 'finish' internally
  749.         if ($action == "finish") {
  750.             $action "";
  751.         }
  752.         if ($action == "changeName") {
  753.             $application->setStartupName("copy of " $application->getStartupName());
  754.             $application->setEditStatus("open");
  755.             $action "start";
  756.         }
  757.         if ($action == "shortenIdeaPitch") {
  758.             $application->setEditStatus("open");
  759.             $action "start";
  760.         }
  761.         if (str_contains(strtolower($application->getEditStatus() ?? ''), "error")   and $action and $user) {
  762.             // Zuordnung memberTeam checken bzw. erstellen - falls validate Login - falls keine Zuordnung und isTeamNeeded GF sonst MA
  763.             $response $em->getRepository(Application::class)->validateApplication($application$member$team$settings$action$request->get('code'));
  764.             /** @var Application $application */
  765.             $application $response['data']['application'];
  766.             $action $response['action'];
  767.             /* Gerrit stash membership 11.4.23
  768.             $application = $em->getRepository(Application::class)->setProcessGoToMonsum($application);
  769.             */
  770.             /*
  771.             if ($response['status'] == "success") {
  772.                 $application = $this->setApplicationStatusByTemplate($application);
  773.                 $action = $this->setActionByProgramSlug($application);
  774.             }*/
  775.             /** @var Member $member */
  776.             $member $response['data']['member'];
  777.             /** @var Team $team */
  778.             $team $response['data']['team'];
  779.             $teamId $team->getId();
  780.             if (!$user->getTeamId()) {
  781.                 $em->getRepository(Member::class)->setPrimaryTeam($member$team$this->getUser()->getEmail());
  782.             }
  783.             /*  Gerrit stash membership 11.4.23
  784.              } elseif ($program->getSlug() == 'membership' and $application->getEditStatus() == "success:applied" and $user) {
  785.                  $action = "goToMonsum"; */
  786.         } elseif ($application->getEditStatus() == "success:applied" and $user) {
  787.             //todo find another status for people that have applied long before
  788.             $action "finish";
  789.         } elseif ($application->getEditStatus() == "success:confirmationMailSent" and $user) {
  790.             $action "done";
  791.         } elseif (($application->getEditStatus() == "success:validatedLogin" or $application->getEditStatus() == "success:validatedEmail" or $application->getEditStatus() == "validated") and $user) {
  792.             $action $this->setActionByProgramSlug($application);
  793.         } elseif ($application->getApplicationStatus() == "started" and $user) {
  794.             $action "continue";
  795.         } elseif ($application->getApplicationStatus() == "applied" and $user) {
  796.             if (in_array($application->getTemplate(), ['accelerator''rheinland-pitch'])) {
  797.                 $action "reopen";
  798.             } else {
  799.                 $action "finish";
  800.             }
  801.         }
  802.         $_isMemberTeamRelationSet $em->getRepository(MemberTeam::class)->findOneBy(['team' => $team'member' => $member]) ? 0;
  803.         $form $this->createForm(ApplicationType::class, $application, ['settings' => $settings'program' => $program'batch' => $batch]);
  804.         $form->handleRequest($request);
  805.         ##############################################################
  806.         ##   form validation starts here                            ##
  807.         ##############################################################
  808.         if ($form->isSubmitted() && $form->isValid()) {
  809.             // make email lower case
  810.             $application->setEmail(strtolower($application->getEmail()));
  811.             if (!$application->getPerson() and $application->getFirstName()) {
  812.                 $application->setPerson("{$application->getFirstName()} {$application->getLastName()}");
  813.             }
  814.             if (!$adminEmail) {
  815.                 $adminEmail $application->getEmail();
  816.             }
  817.             if (isset($settings['extraFields'])) {
  818.                 $application $this->getExtraFieldsData($application$settings$form);
  819.             }
  820.             // now we can check if the email of the form already registered within startplatz
  821.             $isEmailRegistered $em->getRepository(Member::class)->isEmailRegistered($application->getEmail());
  822.             if ($isMemberloggedIn or !$isEmailRegistered) {
  823.                 // if settings[isTeamNeeded] is set a corporate team is created otherwise a person team
  824.                 if ($teamId == 'create' or !$team->getId()) {
  825.                     $team $em->getRepository(Team::class)->createTeamByApplication($application$settings$member);
  826.                     $application->setTeamId($team->getId());
  827.                     $teamId $team->getId();
  828.                 }
  829.             }
  830.             ##email validation - only relevant if access == anonymous or login
  831.             $response $this->evaluateApplicationEmail($application$member$team$settings$user);
  832.             $application $response['data']['application'];
  833.             $member $response['data']['member'];
  834.             $hasExistingApplication $response['hasExistingApplication'];
  835.             $_isMemberTeamRelationSet $teamMember $em->getRepository(MemberTeam::class)->findOneBy(['team' => $team'member' => $member]) ? 0;
  836.             // Do we allow multiple applications?
  837.             $allowMultiple $settings['isTeamNeeded']
  838.                 ? $settings['isMultipleApplicationsPerTeam']
  839.                 : $settings['isMultipleApplicationsPerMember'];
  840.             if (!$allowMultiple
  841.                 && $hasExistingApplication
  842.                 && $application->getApplicationStatus() == 'applied'
  843.                 && $program->getSlug() == 'membership'
  844.             ) {
  845.                 $targetUrl strtolower($this->generateUrl('apply_program_home_lang'$routeParameters));
  846.                 $loginLink $this->generateUrl('login', ['targetPath' => $targetUrl]);
  847.                 $this->session->getFlashBag()->add('notice'"ERROR: You already applied for this membership with your email address. <a title=\"Login page\" href=\"$loginLink\">You can login here</a>.");
  848.                 $routeParameters['action'] = "";
  849.                 return $this->redirect($targetUrl);
  850.             }
  851.             if (!$application->getApplicationStatus()) {
  852.                 $application->setApplicationStatus('started');
  853.             }
  854.             $application $em->getRepository(Application::class)->setApplication($application);
  855.             // at this point application is set and stored in database
  856.             // and member is set and team is set - now we can do last changes to team
  857.             if ($response['status'] == 'error') {
  858.                 /*
  859.                     $status  = "error";
  860.                     $todo    = "validateLogin";
  861.                  */
  862.                 $routeParameters = [
  863.                     'programSlug' => $programSlug,
  864.                     'batchSlug' => $batchSlug,
  865.                     'id' => $application->getId(),
  866.                     'lang' => $lang,
  867.                     'action' => 'validate'
  868.                 ];
  869.                 if ($test) {
  870.                     $routeParameters['test'] = $test;
  871.                 }
  872.                 if ($response['todo'] == "validateLogin") {
  873.                     $targetPath strtolower($this->generateUrl('apply_program_home_lang'$routeParameters));
  874.                     $loginLink $this->loginService->getLoginLinkByTargetPath($member->getEmail(), $targetPath);
  875.                     $mailTemplate $em->getRepository(MailTemplate::class)->getValidateLoginMailTemplateByBatch($batch$application$loginLink);
  876.                     $feedback Utility::sendAlertMailPerZapier($mailTemplate['recipientEmail'], $mailTemplate['mailText'], $mailTemplate['mailSubject'], $mailTemplate['replyToEmail'], $mailTemplate['fromName'], $mailTemplate['bodyType']);
  877.                     $feedback json_decode($feedback);
  878.                     if ($feedback->status == "success") {
  879.                         $routeParameters['action'] = "needsLoginValidation";
  880.                         $targetUrl strtolower($this->generateUrl('apply_program_home_lang'$routeParameters));
  881.                         return $this->redirect($targetUrl);
  882.                     } else {
  883.                         $this->session->getFlashBag()->add('notice''ERROR email is invalid please check your email address!');
  884.                         $routeParameters['action'] = "";
  885.                         $targetUrl strtolower($this->generateUrl('apply_program_home_lang'$routeParameters));
  886.                         return $this->redirect($targetUrl);
  887.                     }
  888.                 }
  889.                 if ($response['todo'] == "validateEmail") {
  890.                     $targetPath strtolower($this->generateUrl('apply_program_home_lang'$routeParameters));
  891.                     $loginLink $this->loginService->getLoginLinkByTargetPath($member->getEmail(), $targetPath);
  892.                     $mailTemplate $em->getRepository(MailTemplate::class)->getValidateEmailMailTemplateByBatch($batch$application$loginLink);
  893.                     $em->persist($application);
  894.                     $em->flush();
  895.                     $feedback Utility::sendAlertMailPerZapier($mailTemplate['recipientEmail'], $mailTemplate['mailText'], $mailTemplate['mailSubject'], $mailTemplate['replyToEmail'], $mailTemplate['fromName'], $mailTemplate['bodyType']);
  896.                     $feedback json_decode($feedback);
  897.                     if ($feedback->status == "success") {
  898.                         $routeParameters['action'] = "needsEmailVerification";
  899.                         $targetUrl strtolower($this->generateUrl('apply_program_home_lang'$routeParameters));
  900.                         return $this->redirect($targetUrl);
  901.                     } else {
  902.                         $this->session->getFlashBag()->add('notice''ERROR email is invalid please check your email adress!');
  903.                         $routeParameters['action'] = "";
  904.                         $targetUrl strtolower($this->generateUrl('apply_program_home_lang'$routeParameters));
  905.                         return $this->redirect($targetUrl);
  906.                     }
  907.                 }
  908.                 if ($test) {
  909.                     return $this->redirect($this->generateUrl('apply_program_home_lang', ['programSlug' => $programSlug'batchSlug' => $batchSlug'id' => $application->getId(), 'test' => $test'lang' => strtolower($lang)]));
  910.                 } else {
  911.                     return $this->redirect($this->generateUrl('apply_program_home_lang', ['programSlug' => $programSlug'batchSlug' => $batchSlug'id' => $application->getId(), 'lang' => strtolower($lang)]));
  912.                 }
  913.             }
  914.             $response $this->checkPlausibility($application$member$team$settings);
  915.             $application $response['data']['application'];
  916.             $application $em->getRepository(Application::class)->setApplication($application);
  917.             if (!$user) {
  918.                 switch ($program->getSlug()) {
  919.                     case "rheinland-pitch":
  920.                     case "accelerator":
  921.                         // make applicant a guest member and login
  922.                         $guestTeam $em->getRepository(Team::class)->getVirtualTeamByName("Guest Membership");
  923.                         $memberTeam $em->getRepository(Member::class)->setTeamAssignment($member$guestTeam"MA"$adminEmail);
  924.                         break;
  925.                     case "nft":
  926.                         // make applicant a guest member and login
  927.                         if (!$isEmailRegistered) {
  928.                             $guestTeam $em->getRepository(Team::class)->getVirtualTeamByName("Guest Membership");
  929.                             $memberTeam $em->getRepository(Member::class)->setTeamAssignment($member$guestTeam"MA"$adminEmail);
  930.                         }
  931.                         $user $em->getRepository(User::class)->findOneBy(['memberId' => $member->getId()]);
  932.                         break;
  933.                     default:
  934.                         break;
  935.                 }
  936.             }
  937.             if ($response['status'] == 'error') {
  938.                 if (!$user) {
  939.                     $targetPath $this->generateUrl('apply_program_home', ['programSlug' => $programSlug'batchSlug' => $batchSlug'id' => $application->getId(), $action => 'validate']);
  940.                     $loginLink $this->loginService->getLoginLinkByTargetPath($member->getEmail(), $targetPath);
  941.                     return $this->redirect($loginLink);
  942.                 } else {
  943.                     return $this->redirect($this->generateUrl('apply_program_home', ['programSlug' => $programSlug'batchSlug' => $batchSlug'id' => $application->getId(), $action => 'validate']));
  944.                 }
  945.             }
  946.             if ($settings['isPitchDeckRequired']) {
  947.                 if ($form->get('uploadImage')->isClicked()) {
  948.                     $uploadTag "application/{$application->getId()}";
  949.                     if ($application->getLinkPitchDeck()) {
  950.                         $application->setLinkPitchDeck('');
  951.                         $application->setPublicIdPitchDeck('');
  952.                         $application $em->getRepository(Application::class)->setApplication($application);
  953.                         $result $this->cloudinary->delete_resources_by_tag($uploadTag);
  954.                     }
  955.                     return $this->redirect($this->generateUrl('apply_program_uploadPitchDeck', ['programSlug' => $programSlug'batchSlug' => $batchSlug'id' => $application->getId(), 'teamId' => $application->getTeamId(), 'memberId' => $application->getMemberId()]));
  956.                 }
  957.             }
  958.             if ($form->get('finish')->isClicked()) {
  959.                 $action "finish";
  960.                 if ($application->getPhone() and !$member->getPhone()) {
  961.                     $member $em->getRepository(Member::class)->setPhone($member$application->getPhone(), $adminEmail);
  962.                 }
  963.                 // relevant only for membership applicants - all applications for membership exit here
  964.                 if ($program->getSlug() == 'membership') {
  965.                     $settings['routeName'] = $routeName;
  966.                     $settings['monsumArticleNumber'] = $product->getMonsumArticleNumber();
  967.                     /* Gerrit stash membership 11.4.23 - exchange with next line
  968.                     return $this->redirect($this->generateUrl('x_membership_monsum-checkout', ['productId' => $product->getProductNumber()]));
  969.                     */
  970.                     return $this->goToMonsum($program$batch$settings$application$member$team$applicantsTeam$user);
  971.                 }
  972.                 // make applicant member of additional virtual team specified in settings
  973.                 $applicantsTeamMember $em->getRepository(Member::class)->setTeamAssignment($member$applicantsTeam"MA"$adminEmail);
  974.                 // final plausibility checks - brauchen wir die überhaupt noch? oder sind das finale Anpassungen der application
  975.                 switch ($program->getSlug()) {
  976.                     case "rheinland-pitch":
  977.                     case "accelerator":
  978.                         if (!$application->getLinkPitchDeck()) {
  979.                             $this->session->getFlashBag()->add('notice''ERROR - Your application will not be processed unless you upload a pitch deck!');
  980.                         } else {
  981.                             $wordsCount str_word_count($application->getIdeaPitch() ?? '');
  982.                             if ($wordsCount 1500) {
  983.                                 $this->session->getFlashBag()->add('notice'"ERROR - Your idea pitch contains {$wordsCount} words, please reduce the length of your idea pitch!");
  984.                             } else {
  985.                                 $action "finish";
  986.                                 $application->setApplicationStatus('applied');
  987.                                 if ($application->getVotesRegistered() == 0) {
  988.                                     $application->setVotesRegistered($settings['initialVotes']);
  989.                                 }
  990.                                 $em->persist($application);
  991.                                 $em->flush();
  992.                             }
  993.                         }
  994.                         break;
  995.                     default:
  996.                         $application $em->getRepository(Application::class)->setApplicationApplied($application);
  997.                         break;
  998.                 }
  999.             } // end of validation of submit button (finish)
  1000.             if ($action != "finish") {
  1001.                 $this->session->getFlashBag()->add('notice''SUCCESS data saved');
  1002.                 if ($id != $application->getId()) {
  1003.                     if (!$user) {
  1004.                         $targetPath $this->generateUrl('apply_program_home_lang', ['programSlug' => $programSlug'batchSlug' => $batchSlug'id' => $application->getId(), 'lang' => strtolower($lang)]);
  1005.                         $loginLink $this->loginService->getLoginLinkByTargetPath($member->getEmail(), $targetPath);
  1006.                         return $this->redirect($loginLink);
  1007.                     } else {
  1008.                         return $this->redirect($this->generateUrl('apply_program_home_lang', ['programSlug' => $programSlug'batchSlug' => $batchSlug'id' => $application->getId(), 'lang' => strtolower($lang)]));
  1009.                     }
  1010.                 } else {
  1011.                     $id $application->getId();
  1012.                 }
  1013.             }
  1014.         } // end of form validation
  1015.         else {
  1016.             $errorString $form->getErrors(truefalse);
  1017.             // @todo: $errorString ist ein Array -> StringCast in der nächsten Zeile anders behandeln
  1018.             if (str_contains((string) $errorString'ERROR:')) {
  1019.                 $this->session->getFlashBag()->add('notice''ERROR - Data have not been saved, reason: ' $errorString);
  1020.             }
  1021.         }
  1022.         if ($action == "goToMonsum") {
  1023.             $settings['routeName'] = $routeName;
  1024.             $settings['monsumArticleNumber'] = $product->getMonsumArticleNumber();
  1025.             return $this->goToMonsum($program$batch$settings$application$member$team$applicantsTeam$user);
  1026.         }
  1027.         if ($action == "finish") {
  1028.             $batch $em->getRepository(Batch::class)->updateNumbers($batch);
  1029.             ##final actions and good bye messages
  1030.             switch ($batch->getTemplate()) {
  1031.                 case "accelerator":
  1032.                 case "rheinland-pitch":
  1033.                     $this->session->getFlashBag()->add('notice''SUCCESS Thank you for your application. We have sent you a confirmation mail with additional information.');
  1034.                     break;
  1035.                 case "registration":
  1036.                 case "businessclub":
  1037.                 case "event":
  1038.                     if ($batch->getAccess() == "anonymous") {
  1039.                         if (!$user and $member->getId()) {
  1040.                             $targetPath $this->generateUrl('apply_program_home', ['programSlug' => $programSlug'batchSlug' => $batchSlug'id' => $application->getId(), 'action' => 'finish']);
  1041.                             $loginLink $this->loginService->getLoginLinkByTargetPath($member->getEmail(), $targetPath);
  1042.                             $user $em->getRepository(User::class)->findOneBy(['memberId' => $member->getId()]);
  1043.                             $this->sendConfirmationMailToApplicant($user$settings$application$batch);
  1044.                             return $this->redirect($loginLink);
  1045.                         }
  1046.                     }
  1047.                     break;
  1048.                 case "speed-networking":
  1049.                     break;
  1050.                 case "sign-up":
  1051.                     // what follow up should be done after
  1052.                     if ($batch->getGoToPage() == 'editMentorsProfile') {
  1053.                         $targetPath $this->generateUrl('x_connect_mentors_edit-profile', ['id' => $member->getId()]);
  1054.                         if (!$user and $member->getId()) {
  1055.                             $loginLink $this->loginService->getLoginLinkByTargetPath($member->getEmail(), $targetPath);
  1056.                             return $this->redirect($loginLink);
  1057.                         } else {
  1058.                             return $this->redirect($targetPath);
  1059.                         }
  1060.                     }
  1061.                     break;
  1062.                 case "startup-tools":
  1063.                     $this->session->getFlashBag()->add('notice''SUCCESS Thank you for your application. We will come back to you soon');
  1064.                     break;
  1065.                 default:
  1066.                     $view '@StartPlatzRheinlandPitchBundle/Apply/apply.default.html.twig';
  1067.                     break;
  1068.             }
  1069.             //$this->session->getFlashBag()->add('notice', 'MESSAGE sendConfirmationMailToApplicant($user, $settings, $application, $batch)');
  1070.             if (!$user){
  1071.                 $user $em->getRepository(User::class)->findOneBy(['memberId' => $member->getId()]);
  1072.             }
  1073.             $this->sendConfirmationMailToApplicant($user$settings$application$batch);
  1074.             if ($programSlug == 'ai-hub'){
  1075.                 $application->setEditStatus("success:confirmationMailSent");
  1076.                 $application $em->getRepository(Application::class)->setApplicationDoneWithoutWorkflow($application);
  1077.             }
  1078.             // additional actions for specific programs
  1079.             switch ($batch->getTemplate()) {
  1080.                 case "accelerator":
  1081.                     //$this->session->getFlashBag()->add('notice', 'MESSAGE addApplicationToPodioByZapier($application, $batch)');
  1082.                     $response $this->addApplicationToPodioByZapier($application$batch);
  1083.                     break;
  1084.                 case "rheinland-pitch":
  1085.                     break;
  1086.             }
  1087.             if ($batch->getLandingPageTwig()) {
  1088.                 $loader = new ArrayLoader([
  1089.                     'landingPageTwig' => $batch->getLandingPageTwig(),
  1090.                 ]);
  1091.                 $twig = new Environment($loader);
  1092.                 //$landingPageTwig = $twig->render('landingPageTwig', ['member' => $member]);
  1093.             }
  1094.         }
  1095.         $editWidget $this->setEditWidgetByTemplate($batch->getTemplate());
  1096.         $phrases $em->getRepository(Option::class)->getApplicationPhrases($program$batch$product$lang);
  1097.         $_isMemberTeamRelationSet $teamMember $em->getRepository(MemberTeam::class)->findOneBy(['team' => $team'member' => $member]) ? 0;
  1098.         $showFooter true// Default to showing the footer
  1099.         if ($request->query->get('iframe') === 'true') {
  1100.             // If the 'iframe' parameter is 'true', always hide the footer
  1101.             $showFooter false;
  1102.         } elseif (isset($settings['showFooter']) && $settings['showFooter'] == 0) {
  1103.             // If the 'iframe' parameter is not 'true' and $setting['showFooter'] exists and is 0, hide the footer
  1104.             $showFooter false;
  1105.         }
  1106.         // Auswahl des Twig-Templates basierend auf programId
  1107.         switch ($batch->getProgramId()) {
  1108.             case 1:
  1109.             case 3:
  1110.             default:
  1111.                 // Fallback auf das zentrale Template, falls programId unbekannt ist
  1112.                 $view '@StartPlatzRheinlandPitchBundle/Apply/apply.default.html.twig';
  1113.                 break;
  1114.         }
  1115.         $landingPageContent $batch->getLandingPageContent();
  1116.         ##view-apply
  1117.         // render specific application form or show landing page
  1118.         return $this->render($view, [
  1119.             'id' => $id,
  1120.             'settings' => $settings,
  1121.             'programSlug' => $programSlug,
  1122.             'batchSlug' => $batchSlug,
  1123.             'program' => $program,
  1124.             'phrases' => $phrases,
  1125.             'batch' => $batch,
  1126.             'lang' => $lang,
  1127.             'product' => $product,
  1128.             'googleCalendarLink' => $em->getRepository(Event::class)->getGoogleCalendardEventByEventId($batch->getEventId(), Utility::getZoomLink($batch->getZoomLink(), $application->getId())),
  1129.             'icsDownloadLink' => $this->generateUrl('event_download',['eventId'=>(int)$batch->getEventId()],UrlGeneratorInterface::ABSOLUTE_URL),
  1130.             'test' => $test,
  1131.             'host' => $host,
  1132.             'pathInfo' => $pathInfo,
  1133.             'view' => $view,
  1134.             'editWidget' => $editWidget,
  1135.             'showFooter' => $showFooter,
  1136.             'member' => $member,
  1137.             'team' => $team,
  1138.             'teamId' => $teamId,
  1139.             'application' => $application,
  1140.             'applicationId' => $id,
  1141.             'form' => $form->createView(),
  1142.             'action' => $action,
  1143.             'landingPageContent' => $landingPageContent,
  1144.             'landingPageTwig' => $landingPageTwig,
  1145.             'targetPathEN' => $this->generateUrl('apply_program_home_lang', ['programSlug' => $programSlug'batchSlug' => $batchSlug'lang' => 'en']),
  1146.             'targetPathDE' => $this->generateUrl('apply_program_home_lang', ['programSlug' => $programSlug'batchSlug' => $batchSlug'lang' => 'de']),
  1147.             'redirectUrl' => base64_encode(json_encode(['path' => 'apply_program_home_lang''parameters' => ['id' => $id'programSlug' => $programSlug'batchSlug' => $batchSlug'lang' => strtolower($lang)]])),
  1148.             'menuLinksAndPhrases' => $this->menuTranslationService->getMenuLinksAndPhrases($request->server->get('REQUEST_URI'), $lang),
  1149.         ]);
  1150.     }
  1151.     private function goToMonsum($programBatch $batch$settingsApplication $application$member$team$applicantsTeam$user)
  1152.     {
  1153.         $em $this->getDoctrine()->getManager();
  1154.         if ($program->getSlug() == 'membership') {
  1155.             // assume that everything went right
  1156.             // save member, assign member to team, save application
  1157.             $data['email'] = $application->getEmail();
  1158.             $data['name'] = $application->getPerson();
  1159.             $adminEmail $application->getEmail();
  1160.             if (!$user) {
  1161.                 $member $em->getRepository(Member::class)->createGuestMemberIfNotExists($data$team$adminEmail);
  1162.             } else {
  1163.                 $applicantsTeamMember $em->getRepository(Member::class)->setTeamAssignment($member$applicantsTeam"MA"$adminEmail);
  1164.             }
  1165.             $account $this->getAccountBySlug($batch->getSlug());
  1166.             if (!$customer $em->getRepository(Customer::class)->findPrimaryMonsumAccount($member$account)) {
  1167.                 $team $em->getRepository(Team::class)->createTeamByMembershipApplicant($member);
  1168.                 $customer $this->setMonsumAccountIfNotExists($member$team$application$account);
  1169.             }
  1170.             $productNumber $batch->getBatchNumber();
  1171.             $customer $em->getRepository(Customer::class)->setCheckoutData($customer$account$productNumber$member->getId());
  1172.             if ($batch->getTemplate() == 'membership-per-api') {
  1173.                 $login $em->getRepository(Customer::class)->getLoginByAccount($customer->getAccount());
  1174.                 $payload json_encode([
  1175.                     'SERVICE' => "subscription.create",
  1176.                     'DATA' => [
  1177.                         'CUSTOMER_ID' => "{$customer->getCustomerId()}",
  1178.                         'ARTICLE_NUMBER' => $settings['monsumArticleNumber'],
  1179.                     ],
  1180.                 ]);
  1181.                 $feedback $this->callbackService->curl_get_monsum_all($payload$login);
  1182.                 $feedback json_decode($feedback);
  1183.                 if (isset($feedback->RESPONSE->STATUS) and $feedback->RESPONSE->STATUS == "success") {
  1184.                     $subscriptionId $feedback->RESPONSE->SUBSCRIPTION_ID;
  1185.                     $application->setEditStatus("sucess:subscriptionId=={$subscriptionId}");
  1186.                     $application $em->getRepository(Application::class)->setHistory($application$application->getEditMessage());
  1187.                     $application->setApplicationStatus('applied');
  1188.                     $em->persist($application);
  1189.                     $em->flush();
  1190.                     ## assign to team ##
  1191.                     $virtualTeam array_key_exists('virtualTeam'$settings) ? $settings['virtualTeam'] : 'applicants';
  1192.                     $funnelTeam $em->getRepository(Team::class)->getVirtualTeamByName($virtualTeam);
  1193.                     $memberTeam $em->getRepository(Member::class)->setTeamAssignment($member$funnelTeam"MA"$adminEmail);
  1194.                     $action "finish";
  1195.                     if ($settings['routeName'] != 'apply_program_home' && $settings['routeName'] != 'apply_program_home_lang') {
  1196.                         $route $settings['routeName'];
  1197.                         if ($route == "schnuppermitgliedschaft_buchen_de") {
  1198.                             $route "schnuppermitgliedschaft_buchen_welcome_de";
  1199.                         } elseif ($route == "schnuppermitgliedschaft_team_buchen_de") {
  1200.                             $route "schnuppermitgliedschaft_team_buchen_welcome_de";
  1201.                         }
  1202.                         $targetPath $this->generateUrl($route, ['id' => $application->getId()]);
  1203.                     } else {
  1204.                         $targetPath $this->generateUrl('apply_program_home', ['programSlug' => $application->getProgramSlug(), 'batchSlug' => $application->getBatchSlug(), 'id' => $application->getId()]);
  1205.                     }
  1206.                     if (!$user) {
  1207.                         $loginLink $this->loginService->getLoginLinkByTargetPath($member->getEmail(), $targetPath);
  1208.                         return $this->redirect($loginLink);
  1209.                     } else {
  1210.                         return $this->redirect($targetPath);
  1211.                     }
  1212.                 } else {
  1213.                     $application->setEditStatus("error:monsum-purchase-failed");
  1214.                     $em->persist($application);
  1215.                     $em->flush();
  1216.                     $action "error";
  1217.                 }
  1218.             } else {
  1219.                 $application $em->getRepository(Application::class)->setProcessGoToMonsum($application);
  1220.                 $application $em->getRepository(Application::class)->setHistory($application$application->getEditMessage());
  1221.                 $application->setApplicationStatus('applied');
  1222.                 $em->persist($application);
  1223.                 $em->flush();
  1224.                 $promocode $application->getRecommendedBy() ? 'welcome-startplatz' '';
  1225.                 return $this->redirect($this->generateUrl('apply_program_monsum-checkout', [
  1226.                     'id' => $application->getId(),
  1227.                     'programSlug' => $program->getSlug(),
  1228.                     'batchSlug' => $batch->getSlug(),
  1229.                     'customerId' => $customer->getHash(),
  1230.                     'promocode' => $promocode,
  1231.                 ]));
  1232.             }
  1233.         }
  1234.     }
  1235.     private function setEditWidgetByTemplate($template)
  1236.     {
  1237.         switch ($template) {
  1238.             case "accelerator":
  1239.                 $editWidget '@StartPlatzRheinlandPitchBundle/Apply/_edit.accelerator.widget.html.twig';
  1240.                 break;
  1241.             case "membership":
  1242.                 $editWidget '@StartPlatzRheinlandPitchBundle/Apply/_edit.membership.widget.html.twig';
  1243.                 break;
  1244.             case "registration":
  1245.             case "businessclub":
  1246.             case "event":
  1247.             case "speed-networking":
  1248.             case "sign-up":
  1249.                 $editWidget '@StartPlatzRheinlandPitchBundle/Apply/_edit.registration.widget.html.twig';
  1250.                 break;
  1251.             case "nft":
  1252.                 $editWidget '@StartPlatzRheinlandPitchBundle/Apply/_edit.nft.widget.html.twig';
  1253.                 break;
  1254.             default:
  1255.                 $editWidget '@StartPlatzRheinlandPitchBundle/Apply/_edit.default.widget.html.twig';
  1256.                 break;
  1257.         }
  1258.         /*
  1259.         these templates are implemented as of 19.10.2021
  1260.         accelerator 25
  1261.         businessclub 8
  1262.         effzeh 1
  1263.         event 37
  1264.         feedback-zu-deiner-startup-idee 46
  1265.         membership 13
  1266.         membership-per-api 2
  1267.         registration 18
  1268.         rheinland-pitch 122
  1269.         sign-up 2
  1270.         speed-networking 161
  1271.         startup-tools 19
  1272.         */
  1273.         return $editWidget;
  1274.     }
  1275.     private function getLandingPageDescription($type)
  1276.     {
  1277.         if ($type == 'default-de') {
  1278.             $description "
  1279.                     <section>
  1280.                         <ul>
  1281.                             <li>Du m&ouml;chtest wissen, wie Du am STARTPLATZ Mitglied werden kannst?
  1282.                             <ul>
  1283.                                 <li>=> <a href=\/tarife/\">Dann informiere Dich auf unserer Mitgliedschafts-Seite</a></li>
  1284.                             </ul>
  1285.                             </li>
  1286.                             <li>Du m&ouml;chtest wissen, welche Konferenzr&auml;ume Du am STARTPLATZ buchen kannst?
  1287.                             <ul>
  1288.                                 <li>=> Dann informiere Dich zu den <a href=\"/koeln-tagungsraeume-und-konferenzraeume/\">Konferenzr&auml;umen in K&ouml;ln</a> oder zu den <a href=\"/duesseldorf-tagungsraeume-und-konferenzraeume/\">Konferenzr&auml;umen in D&uuml;sseldorf</a></li>
  1289.                             </ul>
  1290.                             </li>
  1291.                             <li>Du m&ouml;chtest wissen, welche Workshops oder Events am STARTPLATZ stattfinden?
  1292.                             <ul>
  1293.                                 <li>=> <a href=\"/events/list\">Dann informiere Dich auf unseren Event-Seiten</a></li>
  1294.                             </ul>
  1295.                             </li>
  1296.                         </ul>
  1297.                     </section>
  1298.                     ";
  1299.         } else {
  1300.             $description "
  1301.                     <ul>
  1302.                         <li>Do you want to explore more options within STARTPLATZ?
  1303.                         <ul>
  1304.                             <li>=> <a href=\/tarife/\">go to our Membership Page</a></li>
  1305.                         </ul>
  1306.                         </li>
  1307.                         <li>Do you want to book additional conference rooms at STARTPLATZ?
  1308.                         <ul>
  1309.                             <li>=> Go to <a href=\"/koeln-tagungsraeume-und-konferenzraeume/\">Konferenzr&auml;umen in K&ouml;ln</a> or go to <a href=\"/duesseldorf-tagungsraeume-und-konferenzraeume/\">Konferenzr&auml;umen in D&uuml;sseldorf</a></li>
  1310.                         </ul>
  1311.                         </li>
  1312.                         <li>Do you want to know more about current events at STARTPLATZ?
  1313.                         <ul>
  1314.                             <li>=> <a href=\"/events/list\">Go to our events page</a></li>
  1315.                         </ul>
  1316.                         </li>
  1317.                     </ul>
  1318.                     ";
  1319.         }
  1320.         return $description;
  1321.     }
  1322.     private function setActionByProgramSlug(Application $application)
  1323.     {
  1324.         switch ($application->getTemplate()) {
  1325.             case "rheinland-pitch":
  1326.             case "rheinland-pitch-web3":
  1327.             case "accelerator":
  1328.                 $action "continue";
  1329.                 break;
  1330.             case "membership":
  1331.                 $action "goToMonsum";
  1332.                 break;
  1333.             default:
  1334.                 $action "finish";
  1335.                 break;
  1336.         }
  1337.         // only in case of membership the program slug counts more
  1338.         if ($application->getProgramSlug() == 'membership') {
  1339.             $action "goToMonsum";
  1340.         }
  1341.         return $action;
  1342.     }
  1343.     private function setApplicationStatusByTemplate(Application $application)
  1344.     {
  1345.         $em $this->getDoctrine()->getManager();
  1346.         switch ($application->getTemplate()) {
  1347.             case "rheinland-pitch":
  1348.             case "rheinland-pitch-web3":
  1349.             case "accelerator":
  1350.                 $application $em->getRepository(Application::class)->setApplicationStarted($application);
  1351.                 break;
  1352.             default:
  1353.                 $application $em->getRepository(Application::class)->setApplicationApplied($application);
  1354.                 break;
  1355.         }
  1356.         return $application;
  1357.     }
  1358.     private function updateApplicationByTeam(Application $applicationTeam $team)
  1359.     {
  1360.         $em $this->getDoctrine()->getManager();
  1361.         $application->setTeamId($team->getId());
  1362.         $application->setStartupName($team->getShortName());
  1363.         $application->setCity($team->getAddressCity());
  1364.         $application->setTeamSize($team->getNEmployees());
  1365.         $application->setWebsiteUrl($team->getHomepage());
  1366.         if ($team->getStartupId()) {
  1367.             $startup $em->getRepository(Startup::class)->find($team->getStartupId());
  1368.             $application->setIdeaPitch($startup->getOneSentencePitch());
  1369.             $application->setIndustry($startup->getIndustry());
  1370.             $application->setStartupId($team->getStartupId());
  1371.         }
  1372.         return $application;
  1373.     }
  1374.     /**
  1375.      * Snapshot member data at registration time for historical analysis.
  1376.      * Captures tags, membership status, UTM source, and KI-Kompetenz at the moment of registration.
  1377.      */
  1378.     private function setMemberSnapshotAtRegistration(Application $applicationMember $member): void
  1379.     {
  1380.         // Capture member tags at registration
  1381.         $application->setMemberTagsAtRegistration($member->getTags());
  1382.         // Capture community membership status
  1383.         $application->setWasCommunityMemberAtRegistration($member->getHasCommunityMembership() ?? false);
  1384.         // Check if member was a physical/coworking member at registration time
  1385.         $isPhysicalMember $member->getPhysicalMembershipStarted() !== null
  1386.             && ($member->getPhysicalMembershipEnded() === null
  1387.                 || $member->getPhysicalMembershipEnded() > new \DateTime());
  1388.         $application->setWasPhysicalMemberAtRegistration($isPhysicalMember);
  1389.         // Capture member's original UTM source (first touch attribution)
  1390.         $application->setMemberUtmSourceAtRegistration($member->getUtmSource());
  1391.         // Capture member's KI-Kompetenz level at registration
  1392.         $application->setKiKompetenzAtRegistration($member->getKiKompetenz());
  1393.     }
  1394.     private function setTeam($member$settings$teamIdTeam $applicantsTeam)
  1395.     {
  1396.         $em $this->getDoctrine()->getManager();
  1397.         if ($settings['isTeamNeeded']) {
  1398.             if ($teamId == 'create' or $teamId == 0) {
  1399.                 $team $em->getRepository(Team::class)->setNewTeamForApplication($member$settings);
  1400.             } else {
  1401.                 if ($settings['isSignUp']) {
  1402.                     // in this case virtual teams are okay
  1403.                     $team $em->getRepository(Team::class)->find($teamId);
  1404.                 } else {
  1405.                     $virtualTeams $em->getRepository(Team::class)->findKeysOfVirtualTeams();
  1406.                     if (in_array($member->getTeamId(), $virtualTeams)) {
  1407.                         $team $em->getRepository(Team::class)->setNewTeamForApplication($member$settings);
  1408.                     } else {
  1409.                         $team $em->getRepository(Team::class)->find($teamId);
  1410.                     }
  1411.                 }
  1412.             }
  1413.         } else {
  1414.             // in this case we need only the virtual team related with that batch
  1415.             $team $applicantsTeam;
  1416.         }
  1417.         return $team;
  1418.     }
  1419.     private function evaluateAliasSlug($routeName)
  1420.     {
  1421.         $em $this->getDoctrine()->getManager();
  1422.         $status "";
  1423.         $message "";
  1424.         $todo "";
  1425.         $data = ['program' => false'batch' => false];
  1426.         $programSlug 'membership';
  1427.         switch ($routeName) {
  1428.             case "startup-academy-test-mitgliedschaft_buchen_de":
  1429.                 $batchSlug '16127-test-trial-startup-academy-community-membership';
  1430.                 break;
  1431.             case "schnuppermitgliedschaft_buchen_de":
  1432.             case "schnuppermitgliedschaft_buchen_welcome_de":
  1433.             case "schnuppermitgliedschaft_buchen_en":
  1434.                 $batchSlug '16017-cgn-trial-community-membership';
  1435.                 break;
  1436.             case "schnuppermitgliedschaft_team_buchen_de":
  1437.             case "schnuppermitgliedschaft_team_buchen_welcome_de":
  1438.                 $batchSlug '17047-cgn-trial-startup-membership';
  1439.                 break;
  1440.             case "free-token":
  1441.                 $batchSlug 'free-to-own-token-meetup-24112022';
  1442.                 break;
  1443.             default:
  1444.                 $batchSlug '16017-cgn-trial-community-membership';
  1445.                 break;
  1446.         }
  1447.         if (!$batch $em->getRepository(Batch::class)->findOneBy(['slug' => $batchSlug])) {
  1448.             return false;
  1449.         } else {
  1450.             $status "success";
  1451.             $data = ['batch' => $batch'program' => $batch->getProgram()];
  1452.             $response = [
  1453.                 'status' => $status,
  1454.                 'todo' => $todo,
  1455.                 'message' => $message,
  1456.                 'data' => $data,
  1457.             ];
  1458.             return $response;
  1459.         }
  1460.     }
  1461.     private function evaluateApplicationEmail(Application $application$memberTeam $team$settings$user)
  1462.     {
  1463.         $em $this->getDoctrine()->getManager();
  1464.         $status "";
  1465.         $message "";
  1466.         $todo "";
  1467.         $data = ['application' => $application'member' => $member];
  1468.         $isEmailRegistered $em->getRepository(Member::class)->isEmailRegistered($application->getEmail());
  1469.         $isMemberloggedIn $user true false;
  1470.         $existingApplication false;
  1471.         if ($isEmailRegistered) {
  1472.             $existingMember $em->getRepository(Member::class)->findOneBy(['email' => $application->getEmail()]);
  1473.             $existingApplication $this->checkForMultipleApplications($team$existingMember$settings);
  1474.         }
  1475.         // ['Anonymous' => 'anonymous', 'Login' => 'login', 'Community Membership'=>'hasCommunityMembership', 'Startup Membership'=>'hasStartupMembership'],'required'=> false])
  1476.         switch ($settings['access']) {
  1477.             case "anonymous":
  1478.                 if ($isEmailRegistered == false and $isMemberloggedIn == false) {
  1479.                     if ($settings['isNeedsEmailValidation']) {
  1480.                         $status "error";
  1481.                         $todo "validateEmail";
  1482.                         $message "Email is not yet registered. Email needs to be validated";
  1483.                         $application $em->getRepository(Application::class)->setErrorValidateEmail($application);
  1484.                     } else {
  1485.                         $status "process";
  1486.                         $todo "notValidatedEmail";
  1487.                         $message "Email will be registered without being validated";
  1488.                         $application $em->getRepository(Application::class)->setEditStatus($application$status$todo$message);
  1489.                     }
  1490.                     $data['email'] = $application->getEmail();
  1491.                     $data['firstName'] = $application->getFirstName();
  1492.                     $data['lastName'] = $application->getLastName();
  1493.                     $data['name'] = $application->getPerson();
  1494.                     $adminEmail $application->getEmail();
  1495.                     if ($settings['isTeamNeeded']) {
  1496.                         $memberType "GF";
  1497.                     } else {
  1498.                         $memberType "MA";
  1499.                     }
  1500.                     $member $em->getRepository(Member::class)->createGuestMemberIfNotExists($data$team$adminEmail$memberType);
  1501.                     $application->setMemberId($member->getId());
  1502.                     $this->setMemberSnapshotAtRegistration($application$member);
  1503.                     $application->setTeamId($team->getId());
  1504.                     $data = ['application' => $application'member' => $member];
  1505.                 }
  1506.                 if ($isEmailRegistered == false and $isMemberloggedIn == true) {
  1507.                     $status "error";
  1508.                     $todo "check2ndAccount";
  1509.                     $message "You are registered at STARTPLATZ with another email address.";
  1510.                     $application->setSecondaryEmail($application->getEmail());
  1511.                     $application->setEmail($member->getEmail());
  1512.                     $data = ['application' => $application'member' => $member];
  1513.                 }
  1514.                 if ($isEmailRegistered == true and $isMemberloggedIn == false) {
  1515.                     // "error"; "validateLogin";
  1516.                     /** @var Member $existingMember */
  1517.                     $isAdmin false;
  1518.                     if ($existingMember) {
  1519.                         // check if member is admin
  1520.                         $user $em->getRepository(User::class)->findOneBy(['memberId' => $existingMember->getId()]);
  1521.                         if ($user->getIsAdmin()) {
  1522.                             $isAdmin true;
  1523.                         }
  1524.                     }
  1525.                     if ($settings['isNeedsLoginValidation'] or $isAdmin) {
  1526.                         $status "error";
  1527.                         $todo "validateLogin";
  1528.                         $message "This email address is already in use. Please login to make your application valid.";
  1529.                     } else {
  1530.                         $status "process";
  1531.                         $todo "notValidatedLogin";
  1532.                         $message "This email address is already in use. Application will be processed without login being validated";
  1533.                     }
  1534.                     if (!$existingApplication) {
  1535.                         $message "This email address is already in use. Please login to make your application valid.";
  1536.                         $application->setMemberId($existingMember->getId());
  1537.                         $this->setMemberSnapshotAtRegistration($application$existingMember);
  1538.                         if (!$team->getId()) {
  1539.                             if ($settings['createAlwaysNewTeam']) {
  1540.                                 $team $em->getRepository(Team::class)->createTeamByApplication($application$settings$member);
  1541.                                 $application->setTeamId($team->getId());
  1542.                                 $em->getRepository(Member::class)->setTeamAssignment($existingMember$team'GF'$application->getEmail());
  1543.                             } else {
  1544.                                 $application->setTeamId($existingMember->getTeamId());
  1545.                             }
  1546.                         }
  1547.                     } else {
  1548.                         $message "This email address is already in use and there is already an application of your team. Please login to edit your application.";
  1549.                         $application $existingApplication;
  1550.                     }
  1551.                     $application $em->getRepository(Application::class)->setEditStatus($application$status$todo$message);
  1552.                     $data = ['application' => $application'member' => $existingMember];
  1553.                 }
  1554.                 if ($isEmailRegistered == true and $isMemberloggedIn == true) {
  1555.                     if ($user->getEmail() != $application->getEmail()) {
  1556.                         // "error"; "validateLogin";
  1557.                         $status "error";
  1558.                         $todo "validateLogin";
  1559.                         $application $em->getRepository(Application::class)->setErrorValidateLogin($application);
  1560.                     } else {
  1561.                         if ($application->getProgramSlug() == "membership") {
  1562.                             $status "process";
  1563.                             $todo "goToMonsum";
  1564.                             $message "You need to check out";
  1565.                         } else {
  1566.                             $status "success";
  1567.                             $todo "loggedIn";
  1568.                             $message "We will register your application";
  1569.                         }
  1570.                         $data = ['application' => $application'member' => $member];
  1571.                     }
  1572.                 }
  1573.                 $application->setEditStatus("{$status}:{$todo}");
  1574.                 $application->setEditMessage($message);
  1575.                 break;
  1576.             case "login":
  1577.             case "hasCommunityMembership":
  1578.             case "hasStartupMembership":
  1579.                 if ($existingApplication) {
  1580.                     $data['application'] = $existingApplication;
  1581.                 }
  1582.                 break;
  1583.             default:
  1584.                 break;
  1585.         }
  1586.         $response = [
  1587.             'status' => $status,
  1588.             'todo' => $todo,
  1589.             'message' => $message,
  1590.             'data' => $data,
  1591.             'hasExistingApplication' => !!$existingApplication,
  1592.         ];
  1593.         return $response;
  1594.     }
  1595.     private function checkForMultipleApplications(Team $teamMember $member$settings)
  1596.     {
  1597.         $em $this->getDoctrine()->getManager();
  1598.         $application null;
  1599.         if (!$settings['isMultipleApplicationsPerTeam'] and $team->getId()) {
  1600.             $application $em->getRepository(Application::class)->findOneBy(['teamId' => $team->getId(), 'batchId' => $settings['batchId']]);
  1601.         } else {
  1602.             if (!$settings['isMultipleApplicationsPerMember']) {
  1603.                 $application $em->getRepository(Application::class)->findOneBy(['memberId' => $member->getId(), 'batchId' => $settings['batchId']]);
  1604.             }
  1605.         }
  1606.         return $application;
  1607.     }
  1608.     private function checkPlausibility(Application $applicationMember $memberTeam $team$settings)
  1609.     {
  1610.         $em $this->getDoctrine()->getManager();
  1611.         $status "";
  1612.         $message "";
  1613.         $todo "";
  1614.         $data = ['application' => $application];
  1615.         switch ($settings['programSlug']) {
  1616.             case "rheinland-pitch":
  1617.             case "accelerator":
  1618.                 // plausibility checks
  1619.                 if ($em->getRepository(Application::class)->findByCriteriaButNotTeam(['programSlug' => $application->getProgramSlug(), 'batchSlug' => $application->getBatchSlug(), 'startupName' => $application->getStartupName()], $team)) {
  1620.                     $status "error";
  1621.                     $todo "changeName";
  1622.                     $message "An Application with this name already exists. Please change name!";
  1623.                 }
  1624.                 if (!$application->getIdeaPitch()) {
  1625.                     $status "error";
  1626.                     $todo "fillOutIdeaPitch";
  1627.                     $message "Please specify your idea pitch!";
  1628.                 }
  1629.                 $wordsCount str_word_count($application->getIdeaPitch() ?? '');
  1630.                 if ($wordsCount 150) {
  1631.                     $status "error";
  1632.                     $todo "shortenIdeaPitch";
  1633.                     $message "Your idea pitch contains {$wordsCount} words, max words is 150, please reduce the length of your idea pitch!";
  1634.                 }
  1635.                 break;
  1636.             default:
  1637.                 break;
  1638.         }
  1639.         if ($status "") {
  1640.             $application->setEditStatus("{$status}:{$todo}");
  1641.             $application->setEditMessage($message);
  1642.             $data = ['application' => $application];
  1643.         }
  1644.         $response = [
  1645.             'status' => $status,
  1646.             'todo' => $todo,
  1647.             'message' => $message,
  1648.             'data' => $data,
  1649.         ];
  1650.         return $response;
  1651.     }
  1652.     private function addApplicationToPodioByZapier(Application $applicationBatch $batch$action 'create')
  1653.     {
  1654.         $responseContent = [];
  1655.         ## check for validity of website url
  1656.         ## $application->getWebsiteUrl()
  1657.         $websiteUrl $application->getWebsiteUrl();
  1658.         $urlConstraint = new Assert\Url();
  1659.         // all constraint "options" can be set this way
  1660.         $urlConstraint->message 'Invalid url';
  1661.         // use the validator to validate the value
  1662.         $validator Validation::createValidator();
  1663.         $errors $validator->validate(
  1664.             $application->getWebsiteUrl(),
  1665.             $urlConstraint
  1666.         );
  1667.         if ($errors->count()) {
  1668.             $cleanedURL Utility::generateSlug($application->getWebsiteUrl());
  1669.             $cleanedURL "https://{$cleanedURL}.de";
  1670.             $websiteUrl "https://error-with-url--{$cleanedURL}--please-check-application.de";
  1671.         }
  1672.         $dealRoomUrl $application->getDealroomUrl();
  1673.         $urlConstraint = new Assert\Url();
  1674.         // all constraint "options" can be set this way
  1675.         $urlConstraint->message 'Invalid url';
  1676.         // use the validator to validate the value
  1677.         $validator Validation::createValidator();
  1678.         $errors $validator->validate(
  1679.             $application->getDealroomUrl(),
  1680.             $urlConstraint
  1681.         );
  1682.         if ($errors->count()) {
  1683.             $cleanedURL Utility::generateSlug($application->getDealroomUrl());
  1684.             $cleanedURL "https://{$cleanedURL}.de";
  1685.             $dealRoomUrl "https://error-with-url--{$cleanedURL}--please-check-application.de";
  1686.         }
  1687.         $payload json_encode([
  1688.             'action' => $action == 'update' "update" "add",
  1689.             'applicationId' => $application->getId(),
  1690.             'podioId' => $application->getPodioId(),
  1691.             'podioItemId' => $application->getPodioItemId(),
  1692.             'program' => "accelerator",
  1693.             'batch' => $batch->getBatchNumber(),
  1694.             'startupName' => $application->getStartupName(),
  1695.             'location' => $application->getCity(),
  1696.             'acceleratorStatus' => $application->getApplicationStatus(),
  1697.             'teamId' => $application->getTeamId(),
  1698.             'industry' => $application->getIndustry(),
  1699.             'teamsize' => $application->getTeamSize(),
  1700.             'website' => $websiteUrl,
  1701.             'dealroomUrl' => $dealRoomUrl,
  1702.             'fulltime' => $application->getFulltime(),
  1703.             'mvpStatus' => $application->getMvpStatus(),
  1704.             'pitchDeckLink' => $application->getLinkPitchDeck(),
  1705.             'ideaPitch' => strip_tags($application->getIdeaPitch()),
  1706.             'firstName' => $application->getFirstName(),
  1707.             'lastName' => $application->getLastName(),
  1708.             'email' => $application->getEmail(),
  1709.             'phone' => $application->getPhone(),
  1710.             'linkedIn' => $application->getLinkedin(),
  1711.             'contactPerson' => $application->getPerson() ? $application->getPerson() : "{$application->getFirstName()} {$application->getLastName()}",
  1712.             'applicationDate' => $application->getCreatedAt()->format('Y-m-d H:i'),
  1713.         ]);
  1714.         if ($action == "update") {
  1715.             $callbackUrl "https://hooks.zapier.com/hooks/catch/1872803/bxz3547/";
  1716.         } else {
  1717.             $callbackUrl "https://hooks.zapier.com/hooks/catch/1872803/o7r9f2c/";
  1718.         }
  1719.         $responseContent[] = $this->callbackService->curl_callback($callbackUrl$payload);
  1720.         return $responseContent;
  1721.     }
  1722.     private function addApplicationToPodioByZapierSwitch(Application $applicationBatch $batch)
  1723.     {
  1724.         $responseContent "";
  1725.         $fields Utility::getEntityFieldsArray($application, ['assessments']);
  1726.         $storedData Utility::fillDataByObject($application$fields);
  1727.         $payload json_encode([
  1728.                 'action' => "add",
  1729.                 'batchNumber' => $batch->getBatchNumber(),
  1730.             ] + $storedData);
  1731.         $callbackUrl "https://hooks.zapier.com/hooks/catch/1872803/ovd3dks/";
  1732.         $responseContent $this->callbackService->curl_callback($callbackUrl$payload);
  1733.         //
  1734.         return $responseContent;
  1735.     }
  1736.     private function setMonsumAccountIfNotExists(Member $memberTeam $teamApplication $application$account)
  1737.     {
  1738.         $em $this->getDoctrine()->getManager();
  1739.         $adminEmail $member->getEmail();
  1740.         $responseContent = [];
  1741.         $teamId $team->getId();
  1742.         $customer null;
  1743.         $monsumCustomer null;
  1744.         $settings = [
  1745.             'adminEmail' => $adminEmail,
  1746.             'location' => $em->getRepository(Customer::class)->getLocationByAccount($account),
  1747.             'account' => $account,
  1748.             'accountHash' => $em->getRepository(Customer::class)->getAccountHashByAccount($account),
  1749.         ];
  1750.         $login $em->getRepository(Customer::class)->getLoginByAccount($account);
  1751.         $payload json_encode([
  1752.             'SERVICE' => "customer.get",
  1753.             'FILTER' => [
  1754.                 'CUSTOMER_EXT_UID' => "{$team->getId()}",
  1755.             ],
  1756.         ]);
  1757.         $feedback $this->callbackService->curl_get_monsum_all($payload$login);
  1758.         $feedback json_decode($feedback);
  1759.         if (isset($feedback->RESPONSE->CUSTOMERS[0])) {
  1760.             $responseContent[] = "Team {$teamId} has already account in Monsum";
  1761.             $customer $feedback->RESPONSE->CUSTOMERS[0];
  1762.         } else {
  1763.             $responseContent[] = "New account will be created for team {$teamId} in Monsum";
  1764.             $customerSettings $em->getRepository(Customer::class)->getCustomerSettingsByTeamAndMember($team$member);
  1765.             $payload json_encode([
  1766.                 'SERVICE' => "customer.create",
  1767.                 'DATA' => $customerSettings,
  1768.             ]);
  1769.             $feedback $this->callbackService->curl_get_monsum_all($payload$login);
  1770.             $feedback json_decode($feedback);
  1771.             $monsumResponse $feedback->RESPONSE;
  1772.             if (isset($monsumResponse->ERRORS)) {
  1773.                 $responseContent[] = "ERROR ======== ERROR";
  1774.                 $responseContent[] = $monsumResponse->ERRORS;
  1775.                 $responseContent[] = $feedback;
  1776.             } else {
  1777.                 $responseContent[] = $monsumResponse;
  1778.                 if ($monsumResponse->STATUS == "success") {
  1779.                     $customerId $monsumResponse->CUSTOMER_ID;
  1780.                     $payload $em->getRepository(Customer::class)->getPayloadSingleCustomerByCustomerId($customerId);
  1781.                     $feedback $this->callbackService->curl_get_monsum_all($payload$login);
  1782.                     if ($feedback json_decode($feedback)) {
  1783.                         $customer $feedback->RESPONSE->CUSTOMERS[0];
  1784.                     } else {
  1785.                         $responseContent[] = "ERROR: could not decode feedback from monsum";
  1786.                         $responseContent[] = $feedback;
  1787.                     }
  1788.                 }
  1789.             }
  1790.         }
  1791.         if ($customer) {
  1792.             $monsumCustomer $em->getRepository(Customer::class)->createOrUpdateMonsumCustomerByTeam($customer$settings$team);
  1793.         }
  1794.         return $monsumCustomer;
  1795.     }
  1796.     /**
  1797.      * @Route("/apply-add-application/{memberId}/{batchId}/", name="apply_add-application")
  1798.      */
  1799.     public function addApplicationAction(Request $request$batchId$memberId)
  1800.     {
  1801.         $em $this->getDoctrine()->getManager();
  1802.         $redirect Utility::getRedirectTarget($request);
  1803.         $now = new datetime();
  1804.         $batch $em->getRepository(Batch::class)->findOneBy(['id' => $batchId]);
  1805.         $program $em->getRepository(Program::class /*Startup Program*/)->findOneBy(['id' => $batch->getProgramId()]);
  1806.         $member $em->getRepository(Member::class)->findOneBy(['id' => $memberId]);
  1807.         // check if settings contains necessary setters
  1808.         $batch $em->getRepository(Batch::class)->checkLegacyData($batch);
  1809.         $settings $em->getRepository(Application::class)->getSettingsProgram($program$batch);
  1810.         /** @var User $user */
  1811.         $user $this->getUser();
  1812.         $adminEmail $user->getEmail();
  1813.         $em->getRepository(User::class)->writeActivity($user);
  1814.         // falls member Mitglied in mehreren teams ist, auswählen lassen, ob für bestehendes team einreichen oder für neues team
  1815.         $virtualTeam array_key_exists('virtualTeam'$settings) ? $settings['virtualTeam'] : 'applicants';
  1816.         $applicantsTeam $em->getRepository(Team::class)->getVirtualTeamByName($virtualTeam);
  1817.         // check if $member is part of specified - virtual team
  1818.         if (!$applicantsTeamMember $em->getRepository(MemberTeam::class)->findOneBy(['team' => $applicantsTeam'member' => $member])) {
  1819.             $em->getRepository(Member::class)->setTeamAssignmentByUser($user$member->getId(), $applicantsTeam->getId());
  1820.         }
  1821.         $id $member->getTeamId();
  1822.         $team $em->getRepository(Team::class)->findOneBy(['id' => $id]);
  1823.         $teamMember $em->getRepository(MemberTeam::class)->findOneBy(['team' => $team'member' => $member]);
  1824.         $teamId $team->getId();
  1825.         if ($batch->getIsMultipleApplicationsPerTeam()) {
  1826.             if (!$application $em->getRepository(Application::class)->findOneBy(['programSlug' => $program->getSlug(), 'batchSlug' => $batch->getSlug(), 'memberId' => $member->getId()])) {
  1827.                 $application $em->getRepository(Application::class)->createApplicationIfNotExists($program$batch$team$member$adminEmail);
  1828.             }
  1829.         } else {
  1830.             if (!$application $em->getRepository(Application::class)->findOneBy(['programSlug' => $program->getSlug(), 'batchSlug' => $batch->getSlug(), 'teamId' => $teamId])) {
  1831.                 $application $em->getRepository(Application::class)->createApplicationIfNotExists($program$batch$team$member$adminEmail);
  1832.             }
  1833.         }
  1834.         $application->setBatchStatus('applicant');
  1835.         $application->setApplicationStatus('applied');
  1836.         $em->persist($application);
  1837.         $em->flush();
  1838.         $batch $em->getRepository(Batch::class)->updateNumbers($batch);
  1839.         $this->session->getFlashBag()->add('notice''SUCCESS ' "Application created for member {$member->getName()} and batch {$batch->getName()}");
  1840.         return $this->redirect($this->generateUrl($redirect->path, (array)$redirect->parameters));
  1841.     }
  1842.     /**
  1843.      * @Route("/apply/{programSlug}/{batchSlug}/action/get-access", name="apply_program_get_access")
  1844.      */
  1845.     public function getAccessAction(Request $request$programSlug$batchSlug)
  1846.     {
  1847.         $em $this->getDoctrine()->getManager();
  1848.         $data $request->request->all();
  1849.         if (!($data['email'] and $data['firstName'] and $data['lastName'])) {
  1850.             $this->session->getFlashBag()->add('notice''ERROR Please fill in your data');
  1851.             return $this->redirect($this->generateUrl('apply_program_home', ['programSlug' => $programSlug'batchSlug' => $batchSlug]));
  1852.         }
  1853.         // https://symfony.com/doc/4.4/validation/raw_values.html
  1854.         $validator Validation::createValidator();
  1855.         $constraint = new Assert\Collection([
  1856.             // the keys correspond to the keys in the input array
  1857.             'firstName' => new Assert\Length(['min' => 3]),
  1858.             'lastName' => new Assert\Length(['min' => 3]),
  1859.             'email' => new Assert\Email(),
  1860.         ]);
  1861.         if ($violations $validator->validate($data$constraint)) {
  1862.             $error false;
  1863.             foreach ($violations as $violation) {
  1864.                 $this->session->getFlashBag()->add('notice''ERROR ' $violation->getMessage());
  1865.                 $error true;
  1866.             }
  1867.             if ($error) {
  1868.                 return $this->redirect($this->generateUrl('apply_program_home', ['programSlug' => $programSlug'batchSlug' => $batchSlug]));
  1869.             }
  1870.         }
  1871.         if (!$program $em->getRepository(Program::class /*Startup Program*/)->findOneBy(['slug' => $programSlug])) {
  1872.             $this->session->getFlashBag()->add('notice''ERROR Sorry, no program found');
  1873.             return $this->redirect($this->generateUrl('apply_home', []));
  1874.         }
  1875.         if (!$batch $em->getRepository(Batch::class)->findOneBy(['slug' => $batchSlug])) {
  1876.             $this->session->getFlashBag()->add('notice''ERROR Sorry, no batch found');
  1877.             return $this->redirect($this->generateUrl('apply_home', []));
  1878.         }
  1879.         $settingsProgram $em->getRepository(Application::class)->getSettingsProgram($program$batch);
  1880.         //$adminEmail = $data['email'];
  1881.         $userEmail $data['email'];
  1882.         $adminEmail "support@startplatz.de";
  1883.         // check if there is the defined virtual team
  1884.         $virtualTeam array_key_exists('virtualTeam'$settingsProgram) ? $settingsProgram['virtualTeam'] : 'applicants';
  1885.         $team $em->getRepository(Team::class)->getVirtualTeamByName($virtualTeam);
  1886.         $member $em->getRepository(Member::class)->createGuestMemberIfNotExists($data$team$userEmail);
  1887.         $loginLink $this->loginService->getLoginLinkByTargetPath($member->getEmail(), $this->generateUrl('apply_program_home', ['programSlug' => $programSlug'batchSlug' => $batchSlug]));
  1888.         $mailSubject "{$settingsProgram['programName']} - Access Code - Application Area";
  1889.         $mailText $this->renderView(
  1890.             '@StartPlatzRheinlandPitchBundle/Apply/_mail.get.access.txt.twig',
  1891.             [
  1892.                 'member' => $member,
  1893.                 'loginLink' => $loginLink,
  1894.                 'settings' => $settingsProgram,
  1895.             ]
  1896.         );
  1897.         $this->callbackService->sendAlertMailPerZapier("{$member->getEmail()}"$mailText$mailSubject$adminEmail);
  1898.         $mailText "
  1899. Es gibt eine Anmeldung von {$data['firstName']} {$data['lastName']}   
  1900. Bewerber im Program {$settingsProgram['programName']} mit der E-Mail-Adresse {$data['email']}
  1901. und der Bitte um Zugang zum internen Bereich
  1902.         ";
  1903.         $this->callbackService->sendAlertMailPerZapier($adminEmail$mailText"{$settingsProgram['programName']} - Registration internal Area"$userEmail);
  1904.         $this->callbackService->setSlackMonitoring($mailText);
  1905.         $this->session->getFlashBag()->add('notice''SUCCESS Thank you for your message; we have sent you an access code');
  1906.         return $this->redirect($this->generateUrl('apply_program_home', ['programSlug' => $programSlug'batchSlug' => $batchSlug]));
  1907.     }
  1908.     /**
  1909.      * @Route("/apply/{programSlug}/{batchSlug}/action/feedback", name="apply_program_feedback")
  1910.      */
  1911.     public function receiveFeedbackAction(Request $request$programSlug$batchSlug)
  1912.     {
  1913.         $em $this->getDoctrine()->getManager();
  1914.         $data $request->request->all();
  1915.         if (!array_key_exists('context'$data)) {
  1916.             $data['context'] = "Application Platform";
  1917.         }
  1918.         if (!$data['email']) {
  1919.             $this->session->getFlashBag()->add('notice''ERROR Please specify your email address');
  1920.             return $this->redirect($this->generateUrl('apply_program_home', ['programSlug' => $programSlug'batchSlug' => $batchSlug]));
  1921.         }
  1922.         $mailText "
  1923. Es gibt eine Nachricht von {$data['name']}        
  1924. mit der E-Mail-Adresse {$data['email']}
  1925. und dem Betreff: {$data['subject']}
  1926. und dem Inhalt:
  1927. {$data['message']}
  1928.         ";
  1929.         $this->callbackService->sendAlertMailPerZapier("lorenz.graef@startplatz.de"$mailText$data['context'] . ": " $data['subject'], "support@startplatz.de");
  1930.         $this->callbackService->setSlackMonitoring($mailText);
  1931.         $this->session->getFlashBag()->add('notice''SUCCESS Thank you for your message');
  1932.         return $this->redirect($this->generateUrl('apply_program_home', ['programSlug' => $programSlug'batchSlug' => $batchSlug]));
  1933.     }
  1934.     /**
  1935.      * @Route("/apply/{programSlug}/{batchSlug}/{id}/account", name="apply_program_account")
  1936.      * @Security("is_granted('ROLE_USER')")
  1937.      */
  1938.     public function accountAction(Request $request$programSlug$batchSlug$id)
  1939.     {
  1940.         $em $this->getDoctrine()->getManager();
  1941.         if (!$user $this->getUser()) {
  1942.             return $this->redirect($this->generateUrl('apply_home', []));
  1943.         }
  1944.         $em->getRepository(User::class)->writeActivity($user);
  1945.         $form $this->createForm(SetPasswordFormType::class);
  1946.         $form->handleRequest($request);
  1947.         if ($form->isSubmitted() && $form->isValid()) {
  1948.             /** @var User $user */
  1949.             $user $this->getUser();
  1950.             $data $form->getData();
  1951.             $password $data['new_password'];
  1952.             $encodedPassword $this->encoder->encodePassword($user$password);
  1953.             $user->setPassword($encodedPassword);
  1954.             $em->getRepository(User::class)->add($user);
  1955.             $message = new Email();
  1956.             $message->to($user->getEmail());
  1957.             $message->from('info@startplatz.de');
  1958.             $message->subject('Your password for startplatz.de has been changed');
  1959.             $message->text(
  1960.                 $this->renderView(
  1961.                     '@StartPlatzUserBundle/Mails/passwordChangeAlert.txt.twig',
  1962.                     [
  1963.                         'email' => $user->getEmail(),
  1964.                         'password' => $password,
  1965.                     ]
  1966.                 )
  1967.             );
  1968.             $this->mailer->send($message);
  1969.             $this->session->getFlashBag()->add('notice''SUCCESS ' "Passwort has been set");
  1970.             return $this->redirect($this->generateUrl('apply_program_home', ['id' => $id'programSlug' => $programSlug'batchSlug' => $batchSlug]));
  1971.         }
  1972.         return $this->render('@StartPlatzRheinlandPitchBundle/Apply/account.html.twig', [
  1973.             'form' => $form->createView(),
  1974.             'redirectUrl' => base64_encode(json_encode(['path' => 'apply_program_home''parameters' => ['programSlug' => $programSlug'batchSlug' => $batchSlug]])),
  1975.         ]);
  1976.     }
  1977.     /**
  1978.      * @Route("/apply/{programSlug}/{batchSlug}/{id}/uploadPitchDeck", name="apply_program_uploadPitchDeck")
  1979.      */
  1980.     public function uploadPitchDeckAction(Request $request$programSlug$batchSlug$id)
  1981.     {
  1982.         $em $this->getDoctrine()->getManager();
  1983.         $now = new datetime();
  1984.         if (!$program $em->getRepository(Program::class /*Startup Program*/)->findOneBy(['slug' => $programSlug])) {
  1985.             $this->session->getFlashBag()->add('notice''ERROR Sorry, no program found');
  1986.             return $this->redirect($this->generateUrl('apply_home', []));
  1987.         }
  1988.         if (!$batch $em->getRepository(Batch::class)->findOneBy(['slug' => $batchSlug])) {
  1989.             $this->session->getFlashBag()->add('notice''ERROR Sorry, no batch found');
  1990.             return $this->redirect($this->generateUrl('apply_home', []));
  1991.         }
  1992.         $settings $em->getRepository(Application::class)->getSettingsProgram($program$batch);
  1993.         /** @var User $user */
  1994.         if ($user $this->getUser()) {
  1995.             $em->getRepository(User::class)->writeActivity($user);
  1996.         }
  1997.         $isAdminUpload $request->get('isAdminUpload');
  1998.         if (!$application $em->getRepository(Application::class)->findOneBy(['programSlug' => $programSlug'batchSlug' => $batchSlug'id' => $id])) {
  1999.             $this->session->getFlashBag()->add('notice''ERROR no application found ');
  2000.             return $this->redirect($this->generateUrl('apply_home', []));
  2001.         }
  2002.         if (!$teamId $application->getTeamId()) {
  2003.             $this->session->getFlashBag()->add('notice''ERROR Sorry, no team found');
  2004.             return $this->redirect($this->generateUrl('apply_home', []));
  2005.         }
  2006.         if (!$memberId $application->getMemberId()) {
  2007.             $this->session->getFlashBag()->add('notice''ERROR Sorry, no member found');
  2008.             return $this->redirect($this->generateUrl('apply_home', []));
  2009.         }
  2010.         if (!$isAdminUpload) {
  2011.             if (!$em->getRepository(MemberTeam::class)->isMemberOfTeam($memberId$teamId)) {
  2012.                 $this->session->getFlashBag()->add('notice''ERROR Sorry, we found a problem with the team access rights');
  2013.                 return $this->redirect($this->generateUrl('apply_home', []));
  2014.             }
  2015.         }
  2016.         $publicId $request->get('PublicId');
  2017.         $uploadTag "application/{$application->getId()}";
  2018.         if (!$isAdminUpload) {
  2019.             $redirectTargetUrl $this->generateUrl('apply_program_home_lang', ['programSlug' => $programSlug'batchSlug' => $batchSlug'lang' => strtolower($application->getLang())]);
  2020.         } else {
  2021.             $redirectTargetUrl $this->generateUrl('allmeda_application_edit', ['id' => $application->getId()]);
  2022.         }
  2023.         return $this->render('@StartPlatzRheinlandPitchBundle/Apply/uploadPitchDeck.html.twig', [
  2024.             'application' => $application,
  2025.             'settings' => $settings,
  2026.             'programSlug' => $programSlug,
  2027.             'batchSlug' => $batchSlug,
  2028.             'program' => $program,
  2029.             'batch' => $batch,
  2030.             'uploadTag' => $uploadTag,
  2031.             'publicId' => $publicId,
  2032.             'isAdminUpload' => $isAdminUpload,
  2033.             'teamId' => $teamId,
  2034.             'memberId' => $memberId,
  2035.             'redirect' => $redirectTargetUrl,
  2036.             'redirectUrl' => base64_encode(json_encode(['path' => 'apply_program_home_lang''parameters' => ['programSlug' => $programSlug'batchSlug' => $batchSlug'lang' => strtolower($application->getLang())]])),
  2037.         ]);
  2038.     }
  2039.     /**
  2040.      * @Route("/apply/{programSlug}/{batchSlug}/{id}/add-images-by-tag/", name="apply_program_add_images_by_tag")
  2041.      */
  2042.     public function addImagesByTagAction(Request $request$programSlug$batchSlug$id)
  2043.     {
  2044.         $time_start microtime(true);
  2045.         $tag $request->request->get('tag');
  2046.         $redirect Utility::getRedirectTarget($request);
  2047.         $em $this->getDoctrine()->getManager();
  2048.         $now = new DateTime();
  2049.         if (!$application $em->getRepository(Application::class)->findOneBy(['id' => $id])) {
  2050.             $response = new Response();
  2051.             $response->setContent(json_encode('ERROR no application found'));
  2052.             $response->headers->set('Content-Type''application/json');
  2053.             return $response;
  2054.         }
  2055.         $result $this->cloudinary->resources_by_tag($tag);
  2056.         $resources $result['resources'];
  2057.         foreach ($resources as $resource) {
  2058.             $publicId $resource['public_id'];
  2059.             $secureUrl $resource['secure_url'];
  2060.             $application->setLinkPitchDeck($secureUrl);
  2061.             $application->setPublicIdPitchDeck($publicId);
  2062.             $application->setEditStatus("feedback:pitchdeckUploaded");
  2063.             $application->setEditMessage("Thank you for uploading your pitch deck.");
  2064.             $em->persist($application);
  2065.             $em->flush();
  2066.         }
  2067.         $response = new Response();
  2068.         $response->setContent(json_encode($result));
  2069.         $response->headers->set('Content-Type''application/json');
  2070.         return $response;
  2071.     }
  2072.     private function getSettingsProgramDefault()
  2073.     {
  2074.         return [
  2075.             "programName" => "Example",
  2076.             "programSlug" => "example",
  2077.             "batchName" => "Batch11",
  2078.             "batchSlug" => "batch11",
  2079.             "applicationStart" => "2019-11-11",
  2080.             "programStart" => "2019-12-11",
  2081.             "programEnd" => "2019-12-11",
  2082.             "applicationStages" => "applied,approved",
  2083.             "programStages" => "applicant,participant,alumni,drop-out,rejected",
  2084.             "programTag" => "example-batch11-participant",
  2085.             "eventId" => "4982",
  2086.             "bgImage" => "https://res.cloudinary.com/startplatz/image/upload/v1573496116/rheinland-pitch/impressions/final-koeln-2017_audience_manor-lux.jpg",
  2087.             "virtualTeam" => "example-team",
  2088.             "status" => "test",
  2089.         ];
  2090.     }
  2091.     /**
  2092.      * @Route("/apply/administration/batch/test-confirmation-mail/{batchId}", name="apply_test_confirmation-mail")
  2093.      * @Security("is_granted('ROLE_ADMIN')")
  2094.      */
  2095.     public function sendConfirmationTestMail(Request $request$batchId)
  2096.     {
  2097.         $redirect Utility::getRedirectTarget($request);
  2098.         $em $this->getDoctrine()->getManager();
  2099.         $reminder null;
  2100.         $sendReminderMail $request->get('sendReminderMail');
  2101.         /** @var User $user */
  2102.         $user $this->getUser();
  2103.         $em->getRepository(User::class)->writeActivity($user);
  2104.         if ($sendReminderMail){
  2105.             $reminder $em->getRepository(Reminder::class)->find($batchId);
  2106.             $batchId $reminder->getBatchId();
  2107.         }
  2108.         /** @var Batch $batch */
  2109.         if (!$batch $em->getRepository(Batch::class)->findOneBy(['id' => $batchId])) {
  2110.             $this->session->getFlashBag()->add('notice''ERROR batch not found');
  2111.             return $this->redirect($this->generateUrl($redirect->path, (array)$redirect->parameters));
  2112.         }
  2113.         $member $em->getRepository(Member::class)->find($user->getMemberId());
  2114.         if (!$application $em->getRepository(Application::class)->findOneBy(['memberId'=>$member->getId(), 'batchId'=>$batch->getId()])){
  2115.             $application $em->getRepository(Application::class)->getTemporaryApplicationByBatchAndMember($batch$member);
  2116.             $application $em->getRepository(Application::class)->setApplicationDone($application);
  2117.         }
  2118.         $application->setApplicationStatus('applied');
  2119.         // Start timing
  2120.         $this->stopwatch->start('confirmation_mail');
  2121.         $response $this->sendConfirmationMailToApplicant($user, [], $application$batch$reminder);
  2122.         // Stop timing
  2123.         $stopwatchEvent $this->stopwatch->stop('confirmation_mail');
  2124.         // Get duration and memory usage
  2125.         $duration $stopwatchEvent->getDuration();
  2126.         $memory round($stopwatchEvent->getMemory() / (1024 1024), 2); // Convert to MB and round to 2 decimal places
  2127.         $this->addFlash('notice'"SUCCESS via service: A test confirmation mail has been sent to {$user->getEmail()}. Time: {$duration}ms, Memory: {$memory} MB");
  2128.         return $this->redirect($this->generateUrl($redirect->path, (array)$redirect->parameters));
  2129.     }
  2130.     /**
  2131.      * @Route("/apply/administration/batch/test-confirmation-mail-service/{batchId}", name="apply_test_confirmation-mail_service")
  2132.      * @Security("is_granted('ROLE_ADMIN')")
  2133.      */
  2134.     public function sendConfirmationTestMailViaService(Request $request$batchId)
  2135.     {
  2136.         $redirect Utility::getRedirectTarget($request);
  2137.         $em $this->getDoctrine()->getManager();
  2138.         $reminder null;
  2139.         $sendReminderMail $request->get('sendReminderMail');
  2140.         /** @var User $user */
  2141.         $user $this->getUser();
  2142.         $em->getRepository(User::class)->writeActivity($user);
  2143.         if ($sendReminderMail){
  2144.             $reminder $em->getRepository(Reminder::class)->find($batchId);
  2145.             $batchId $reminder->getBatchId();
  2146.         }
  2147.         /** @var Batch $batch */
  2148.         if (!$batch $em->getRepository(Batch::class)->findOneBy(['id' => $batchId])) {
  2149.             $this->session->getFlashBag()->add('notice''ERROR batch not found');
  2150.             return $this->redirect($this->generateUrl($redirect->path, (array)$redirect->parameters));
  2151.         }
  2152.         $member $em->getRepository(Member::class)->find($user->getMemberId());
  2153.         if (!$application $em->getRepository(Application::class)->findOneBy(['memberId'=>$member->getId(), 'batchId'=>$batch->getId()])){
  2154.             $application $em->getRepository(Application::class)->getTemporaryApplicationByBatchAndMember($batch$member);
  2155.             $application $em->getRepository(Application::class)->setApplicationDone($application);
  2156.         }
  2157.         $application->setApplicationStatus('applied');
  2158.         // Start timing
  2159.         $this->stopwatch->start('confirmation_mail');
  2160.         $result $this->confirmationMailService->sendConfirmationMailToApplicant($user$member, [], $application$batch$reminder);
  2161.         // Stop timing
  2162.         $stopwatchEvent $this->stopwatch->stop('confirmation_mail');
  2163.         // Get duration and memory usage
  2164.         $duration $stopwatchEvent->getDuration();
  2165.         $memory round($stopwatchEvent->getMemory() / (1024 1024), 2); // Convert to MB and round to 2 decimal places
  2166.         // Verarbeiten der Nachrichten aus dem Service
  2167.         foreach ($result['messages'] as $message) {
  2168.             $this->addFlash('notice'$message);
  2169.         }
  2170.         // Zusätzliche Flash-Nachricht für Leistungsinformationen
  2171.         $this->addFlash('notice'"Service execution: Time: {$duration}ms, Memory: {$memory} MB");
  2172.         // Status-basierte Nachricht
  2173.         if ($result['status'] === 'success') {
  2174.             $this->addFlash('notice''SUCCESS: Mail sent successfully via service');
  2175.         } else {
  2176.             $this->addFlash('notice''ERROR: Failed to send mail via service');
  2177.         }
  2178.         return $this->redirect($this->generateUrl($redirect->path, (array)$redirect->parameters));
  2179.     }
  2180.     private function sendConfirmationMailToApplicant(User $user$settingsApplication $applicationBatch $batchReminder $reminder null)
  2181.     {
  2182.         $em $this->getDoctrine()->getManager();
  2183.         if (!$settings) {
  2184.             $application->setStartupName("Test Startup");
  2185.             $application->setEmail($user->getEmail());
  2186.         }
  2187.         $program $batch->getProgram();
  2188.         $routeParameters = [
  2189.             'programSlug' => $program->getSlug(),
  2190.             'batchSlug' => $batch->getSlug(),
  2191.         ];
  2192.         if (isset($reminder) && $reminder->getType() == 'feedbackMail' && $batch->getSurveyId() > ''){
  2193.             $loginPath = ['path'=>'survey_proceed','parameters'=>['id'=>$batch->getSurveyId(), 'slug'=>"{$program->getSlug()}-{$batch->getSlug()}"]];
  2194.             //$mailTemplate->setLoginPath(json_encode($loginPath));
  2195.             $targetPath $this->generateUrl($loginPath['path'], $loginPath['parameters']);
  2196.         } else {
  2197.             $targetPath $this->generateUrl('apply_program_home'$routeParameters);
  2198.         }
  2199.         $loginLink $this->loginService->getLoginLinkByTargetPath($application->getEmail(), $targetPath);
  2200.         $metaName $batch->getMailDesignTemplate();
  2201.         $designTemplate $em->getRepository(Option::class)->getOptionMetaValuePlain($metaName);
  2202.         if ($reminder){
  2203.             $content $reminder->getReminderMailContent();
  2204.             $subject $reminder->getReminderMailSubject();
  2205.         } else {
  2206.             $content $batch->getConfirmationMailContent();
  2207.             $subject $batch->getConfirmationMailSubject();
  2208.         }
  2209.         $loader = new ArrayLoader([
  2210.             'mailBase' => $designTemplate,
  2211.             'content' => $content,
  2212.             'subject' => $subject,
  2213.         ]);
  2214.         // create new twig object with all twig templates
  2215.         $twig = new Environment($loader);
  2216.         $viewBase 'mailBase';
  2217.         $viewContent 'content';
  2218.         $viewSubject 'subject';
  2219.         $renderedSubject $twig->render(
  2220.             $viewSubject,
  2221.             [
  2222.                 'userId' => $user->getId(),
  2223.                 'loginLink' => $loginLink,
  2224.                 'batch' => $batch,
  2225.                 'program' => $program,
  2226.                 'application' => $application,
  2227.                 'dateEN' => $batch->getPitchDate()->format('Y-m-d'),
  2228.                 'dateDE' => $batch->getPitchDate()->format('d.m.y'),
  2229.                 'timeEN' => $batch->getPitchTime()->format('g:i A'), // English 12-hour format
  2230.                 'timeDE' => $batch->getPitchTime()->format('H:i'),   // German 24-hour format
  2231.                 'zoomLink' => Utility::getZoomLink($batch->getZoomLink(), $application->getId()),
  2232.             ]
  2233.         );
  2234.         $renderedContent $twig->render(
  2235.             $viewContent,
  2236.             [
  2237.                 'userId' => $user->getId(),
  2238.                 'name' => $application->getPerson(),
  2239.                 'firstName' => $application->getFirstName(),
  2240.                 'loginLink' => $loginLink,
  2241.                 'batch' => $batch,
  2242.                 'program' => $program,
  2243.                 'application' => $application,
  2244.                 'dateEN' => $batch->getPitchDate()->format('Y-m-d'),
  2245.                 'dateDE' => $batch->getPitchDate()->format('d.m.y'),
  2246.                 'timeEN' => $batch->getPitchTime()->format('g:i A'), // English 12-hour format
  2247.                 'timeDE' => $batch->getPitchTime()->format('H:i'),   // German 24-hour format
  2248.                 'zoomLink' => Utility::getZoomLink($batch->getZoomLink(), $application->getId()),
  2249.                 'googleCalendarLink' => $em->getRepository(Event::class)->getGoogleCalendardEventByEventId($batch->getEventId(), Utility::getZoomLink($batch->getZoomLink(), $application->getId())),
  2250.                 'icsDownloadLink' => $this->generateUrl('event_download',['eventId'=>(int)$batch->getEventId()],UrlGeneratorInterface::ABSOLUTE_URL),
  2251.             ]
  2252.         );
  2253.         $html $twig->render(
  2254.             $viewBase,
  2255.             [
  2256.                 'userId' => $user->getId(),
  2257.                 'name' => $application->getPerson(),
  2258.                 'firstName' => $application->getFirstName(),
  2259.                 'loginLink' => $loginLink,
  2260.                 'batch' => $batch,
  2261.                 'program' => $program,
  2262.                 'application' => $application,
  2263.                 'dateEN' => $batch->getPitchDate()->format('Y-m-d'),
  2264.                 'dateDE' => $batch->getPitchDate()->format('d.m.y'),
  2265.                 'timeEN' => $batch->getPitchTime()->format('g:i A'), // English 12-hour format
  2266.                 'timeDE' => $batch->getPitchTime()->format('H:i'),   // German 24-hour format
  2267.                 'zoomLink' => Utility::getZoomLink($batch->getZoomLink(), $application->getId()),
  2268.                 'googleCalendarLink' => $em->getRepository(Event::class)->getGoogleCalendardEventByEventId($batch->getEventId(), Utility::getZoomLink($batch->getZoomLink(), $application->getId())),
  2269.                 'icsDownloadLink' => $this->generateUrl('event_download',['eventId'=>(int)$batch->getEventId()],UrlGeneratorInterface::ABSOLUTE_URL),
  2270.                 'content' => $renderedContent,
  2271.             ]
  2272.         );
  2273.         $feedback Utility::sendAlertMailPerZapier($application->getEmail(), $html$renderedSubject$batch->getSenderMail(), $batch->getFromName(), 'html');
  2274.         $this->session->getFlashBag()->add('notice'"SUCCESS Confirmation Mail has been sent via Zapier to {$application->getEmail()} with feedback=" print_r($feedbacktrue));
  2275.         $mailSubject "{$batch->getProgram()->getName()} - Application submitted by {$application->getStartupName()}";
  2276.         $mailText $this->renderView(
  2277.             '@StartPlatzRheinlandPitchBundle/Apply/_mail.altert.admin.application.txt.twig',
  2278.             [
  2279.                 'user' => $user,
  2280.                 'batch' => $batch,
  2281.                 'application' => $application,
  2282.             ]
  2283.         );
  2284.         $feedback $this->callbackService->sendAlertMailPerZapier($batch->getRecipientMonitoringMail(), $mailText$mailSubject$application->getEmail());
  2285.         $this->session->getFlashBag()->add('notice'"SUCCESS Confirmation Mail has been sent via Zapier to {$application->getEmail()} with feedback=" print_r($feedbacktrue));
  2286.         if ($batch->getSkoolWebhook() > ''){
  2287.             $feedback $this->callbackService->sendPostRequest($batch->getSkoolWebhook(), $application->getEmail());
  2288.             $this->session->getFlashBag()->add('notice'"SUCCESS Skool Webhook has been posted with email= {$application->getEmail()} and feedback=" print_r($feedbacktrue));
  2289.         }
  2290.         if ($batch->getZapierWebhook() > ''){
  2291.             $payload json_encode($em->getRepository(Event::class)->setPayloadSingleApplicationAndBatch($application$batch));
  2292.             $callbackUrl $batch->getZapierWebhook();
  2293.             $feedback $this->callbackService->curl_callback($callbackUrl$payload);
  2294.             $this->session->getFlashBag()->add('notice'"SUCCESS Zapier webhook {$batch->getZapierWebhook()} called with feedback=" print_r($feedback,true));
  2295.         }
  2296.         if ($reminder && $reminder->getSkoolWebhook() > ''){
  2297.             $feedback $this->callbackService->sendPostRequest($reminder->getSkoolWebhook(), $application->getEmail());
  2298.             $this->session->getFlashBag()->add('notice'"SUCCESS Skool Webhook has been posted with email= {$application->getEmail()} and feedback=" print_r($feedbacktrue));
  2299.         }
  2300.         if ($reminder && $reminder->getZapierWebhook() > ''){
  2301.             $payload json_encode($em->getRepository(Event::class)->setPayloadSingleApplicationAndBatch($application$batch));
  2302.             $callbackUrl $reminder->getZapierWebhook();
  2303.             $feedback $this->callbackService->curl_callback($callbackUrl$payload);
  2304.             $this->session->getFlashBag()->add('notice'"SUCCESS Zapier webhook {$reminder->getZapierWebhook()} called with feedback=" print_r($feedback,true));
  2305.         }
  2306.         return true;
  2307.     }
  2308. }