src/StartPlatz/Bundle/AlphaBundle/Controller/StartupController.php line 231

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace App\StartPlatz\Bundle\AlphaBundle\Controller;
  3. use App\StartPlatz\Bundle\AlphaBundle\Entity\Actor;
  4. use App\StartPlatz\Bundle\AlphaBundle\Entity\Feed;
  5. use App\StartPlatz\Bundle\AlphaBundle\Entity\Page;
  6. use App\StartPlatz\Bundle\MemberBundle\Entity\Member;
  7. use App\StartPlatz\Bundle\MemberBundle\Entity\MemberTeam;
  8. use App\StartPlatz\Bundle\MemberBundle\Entity\Option;
  9. use App\StartPlatz\Bundle\MemberBundle\Entity\Team;
  10. use App\StartPlatz\Bundle\StartupBundle\Entity\Application;
  11. use App\StartPlatz\Bundle\StartupBundle\Entity\Batch;
  12. use App\StartPlatz\Bundle\StartupBundle\Entity\Startup;
  13. use App\StartPlatz\Bundle\StartupBundle\Entity\StartupAttribute;
  14. use App\StartPlatz\Bundle\StartupBundle\Entity\StartupLifecycleEvent;
  15. use App\StartPlatz\Bundle\StartupBundle\Entity\StartupRelevance;
  16. use App\StartPlatz\Bundle\StartupBundle\Form\LivecycleEventType;
  17. use App\StartPlatz\Bundle\WebsiteBundle\Utility\Utility;
  18. use DateTime;
  19. use Eckinox\TinymceBundle\Form\Type\TinymceType;
  20. use Speicher210\CloudinaryBundle\Cloudinary\Api;
  21. use Symfony\Component\HttpFoundation\Response;
  22. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
  23. use stdClass;
  24. use Symfony\Component\Mailer\Exception\TransportExceptionInterface;
  25. use Symfony\Component\Mime\Address;
  26. use Symfony\Component\Mime\Email;
  27. use Symfony\Component\Routing\Annotation\Route;
  28. use App\StartPlatz\Bundle\FeedbackBundle\FeedbackService;
  29. use App\StartPlatz\Bundle\StartupBundle\Form\StartupType;
  30. use App\StartPlatz\Bundle\UserBundle\Entity\User;
  31. use App\StartPlatz\Bundle\WebsiteBundle\MenuTranslationService;
  32. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  33. use Symfony\Component\Form\Extension\Core\Type\SubmitType;
  34. use Symfony\Component\Form\Extension\Core\Type\TextareaType;
  35. use Symfony\Component\Form\FormFactoryInterface;
  36. use Symfony\Component\Mailer\MailerInterface;
  37. use Symfony\Component\HttpFoundation\Request;
  38. use Symfony\Component\HttpFoundation\Session\SessionInterface;
  39. class StartupController extends AbstractController
  40. {
  41.     public function __construct(
  42.         private readonly SessionInterface $session,
  43.         private readonly FormFactoryInterface $formFactory,
  44.         private readonly FeedbackService $feedbackService,
  45.         private readonly MenuTranslationService $menuTranslationService,
  46.         private readonly Api $cloudinary,
  47.         private readonly MailerInterface $mailer
  48.     ) {
  49.     }
  50.     /**
  51.      * @Route("/accelerator/startups", name="accelerator_startups")
  52.      */
  53.     public function AcceleratorStartupsIndexAction(Request $request)
  54.     {
  55.         $em $this->getDoctrine()->getManager();
  56.         $startups $em->getRepository(Startup::class)->findAcceleratorAlumnis();
  57.         $teamIds array_map(fn ($entity) => $entity->getTeamId(), $startups);
  58.         $teams   $em->getRepository(Team::class)->findBy(['id'=>$teamIds]);
  59.         $teamIds array_map(fn ($entity) => $entity->getId(), $teams);
  60.         $teams   array_combine($teamIds$teams);
  61.         return $this->render('@StartPlatzAlphaBundle/Startup/index.startups.alumni.html.twig', [
  62.             'startups'   => $startups,
  63.             'teams'      => $teams,
  64.         ]);
  65.     }
  66.     /**
  67.      * @Route("/x/connect/startups/home", name="x_connect_startups_home")
  68.      * @Security("is_granted('ROLE_USER')")
  69.      */
  70.     public function indexStartupsSpconnectAction(Request $request)
  71.     {
  72.         $em $this->getDoctrine()->getManager();
  73.         $templateVars $em->getRepository(Startup::class)->getTemplateVars($request);
  74.         $route $request->get('_route');
  75.         $responseContent = [];
  76.         /** @var User $user */
  77.         $user $this->getUser();
  78.         $em->getRepository(User::class)->writeActivity($user);
  79.         $teamId $user->getMemberId();
  80.         $userMember $em->getRepository(Member::class)->find($user->getMemberId());
  81.         if (!$ajax $request->get('ajax')) {
  82.             // do whatever has to be done with first access
  83.         }
  84.         $orderBy $templateVars['dimensions'] ?: ['score' => 'DESC'];
  85.         $visibility 'sp-connect';
  86.         $criteria = ['visibility' => $visibility'status' => 'active''team' => 'exists'] + $templateVars['criteria'];
  87.         //remove location from criteria for location-button hrefs so not both CGN or DUS can be selected at the same time
  88.         $templateVarsLocation $templateVars;
  89.         if(array_key_exists('criteria'$templateVarsLocation) && array_key_exists('location'$templateVarsLocation['criteria'])) {
  90.             unset($templateVarsLocation['criteria']['location']);
  91.         }
  92.         $total $em->getRepository(Startup::class)->countByCriteria($criteria$teamId);
  93.         if ($total 72) {
  94.             $limit 72;
  95.         } else {
  96.             $limit $total ?: 1;
  97.         }
  98.         if (!$page $request->get('page')) {
  99.             $page 1;
  100.         }
  101.         $startups $em->getRepository(Startup::class)->findPaginated($criteria$teamId$orderBy$page$limit);
  102.         $maxPages $total;
  103.         $id $user->getTeamId();
  104.         $acceleratorCurrentBatchNumber $em->getRepository(Option::class)->getAcceleratorCurrentBatchNumber();
  105.         $startupsCurrentBatch $em->getRepository(Startup::class)->findPaginated($criteria + ['batch' => $acceleratorCurrentBatchNumber], $teamId$orderBy1128);
  106.         $startupsLastBatch $em->getRepository(Startup::class)->findPaginated($criteria + ['batch' => $acceleratorCurrentBatchNumber -], $teamId$orderBy1128);
  107.         $startupsBatch20 $em->getRepository(Startup::class)->findPaginated($criteria + ['batch' => $acceleratorCurrentBatchNumber -2], $teamId$orderBy1128);
  108.         $startupsSpCgn $em->getRepository(Startup::class)->findPaginated($criteria + ['startplatz' => 'sp-cgn'], $teamId$orderBy1128);
  109.         $startupsSpDus $em->getRepository(Startup::class)->findPaginated($criteria + ['startplatz' => 'sp-dus'], $teamId$orderBy1128);
  110.         $startupsAlumni $em->getRepository(Startup::class)->findPaginated($criteria + ['startplatz' => 'alumni'], $teamId$orderBy1128);
  111.         $startupsExtern $em->getRepository(Startup::class)->findPaginated($criteria + ['startplatz' => 'extern'], $teamId$orderBy$page$limit);
  112.         $startupsRheinlandPitch = [];
  113.         $startupsRheinlandPitch $em->getRepository(Startup::class)->findPaginated($criteria + ['pitchNumber' => 'rheinland-pitch-web3-edition-112'], $teamId$orderBy1128);
  114.         $startupsGruenderstipendium = [];
  115.         $startupsGruenderstipendium $em->getRepository(Startup::class)->findPaginated($criteria + ['gsStatus' => ['funded','recommended']], $teamId$orderBy1128);
  116.         $startupsGruenderstipendiumAlumni = [];
  117.         $startupsGruenderstipendiumAlumni $em->getRepository(Startup::class)->findPaginated($criteria + ['gsStatus' => ['alumni']], $teamId$orderBy1128);
  118.         // get teamIds
  119.         $teamIds array_map(fn ($entity) => $entity['teamId'], $startups);
  120.         $teamIds $teamIds array_map(fn ($entity) => $entity['teamId'], $startupsCurrentBatch);
  121.         $teamIds $teamIds array_map(fn ($entity) => $entity['teamId'], $startupsLastBatch);
  122.         $teamIds $teamIds array_map(fn ($entity) => $entity['teamId'], $startupsBatch20);
  123.         $teamIds $teamIds array_map(fn ($entity) => $entity['teamId'], $startupsSpCgn);
  124.         $teamIds $teamIds array_map(fn ($entity) => $entity['teamId'], $startupsSpDus);
  125.         $teamIds $teamIds array_map(fn ($entity) => $entity['teamId'], $startupsAlumni);
  126.         $teamIds $teamIds array_map(fn ($entity) => $entity['teamId'], $startupsExtern);
  127.         $teamIds $teamIds array_map(fn ($entity) => $entity['teamId'], $startupsRheinlandPitch);
  128.         $teamIds $teamIds array_map(fn ($entity) => $entity['teamId'], $startupsGruenderstipendium);
  129.         $teamIds $teamIds array_map(fn ($entity) => $entity['teamId'], $startupsGruenderstipendiumAlumni);
  130.         $teams $em->getRepository(Team::class)->findBy(['id'=>$teamIds]);
  131.         $teamIds array_map(fn ($entity) => $entity->getId(), $teams);
  132.         $teams array_combine($teamIds$teams);
  133.         /** @var Team $team */
  134.         $team $em->getRepository(Team::class)->find($id);
  135.         $view '@StartPlatzAlphaBundle/Startup/index.startups.sp-connect.html.twig';
  136.         $viewFeed '@StartPlatzAlphaBundle/Startup/_feed.startups.sp-connect.html.twig';
  137.         if ($ajax) {
  138.             return $this->render($viewFeed, [
  139.                 'startups'   => $startups,
  140.                 'userMember' => $userMember,
  141.                 'startupsCurrentBatch' => $startupsCurrentBatch,
  142.                 'startupsLastBatch' => $startupsLastBatch,
  143.                 'startupsBatch20' => $startupsBatch20,
  144.                 'startupsSpCgn' => $startupsSpCgn,
  145.                 'startupsSpDus' => $startupsSpDus,
  146.                 'startupsAlumni' => $startupsAlumni,
  147.                 'startupsExtern' => $startupsExtern,
  148.                 'startupsRheinlandPitch'     => $startupsRheinlandPitch,
  149.                 'startupsGruenderstipendium'       => $startupsGruenderstipendium,
  150.                 'startupsGruenderstipendiumAlumni' => $startupsGruenderstipendiumAlumni,
  151.                 'team'       => $team,
  152.                 'teams'      => $teams,
  153.                 'maxPages'   => $maxPages,
  154.                 'thisPage'   => $page,
  155.                 'ajax'       => $ajax,
  156.                 'redirectUrl' => base64_encode(json_encode(['path' => $route'parameters' => $templateVars])),
  157.                 'templateVars' => $templateVars,
  158.                 'templateVarsLocation' => $templateVarsLocation,
  159.             ]);
  160.         } else {
  161.             return $this->render($view, [
  162.                 'startups'   => $startups,
  163.                 'userMember' => $userMember,
  164.                 'title'      => "Startups",
  165.                 'startupsCurrentBatch' => $startupsCurrentBatch,
  166.                 'startupsLastBatch' => $startupsLastBatch,
  167.                 'startupsBatch20' => $startupsBatch20,
  168.                 'startupsSpCgn' => $startupsSpCgn,
  169.                 'startupsSpDus' => $startupsSpDus,
  170.                 'startupsAlumni' => $startupsAlumni,
  171.                 'startupsExtern' => $startupsExtern,
  172.                 'startupsRheinlandPitch'     => $startupsRheinlandPitch,
  173.                 'startupsGruenderstipendium'       => $startupsGruenderstipendium,
  174.                 'startupsGruenderstipendiumAlumni' => $startupsGruenderstipendiumAlumni,
  175.                 'team'       => $team,
  176.                 'teams'      => $teams,
  177.                 'maxPages'   => $maxPages,
  178.                 'thisPage'   => $page,
  179.                 'ajax'       => $ajax,
  180.                 'redirectUrl' => base64_encode(json_encode(['path' => $route'parameters' => $templateVars])),
  181.                 'templateVars' => $templateVars,
  182.                 'templateVarsLocation' => $templateVarsLocation,
  183.                 'menuLinksAndPhrases' => $this->menuTranslationService->getMenuLinksAndPhrases($request->server->get('REQUEST_URI')),
  184.             ]);
  185.         }
  186.     }
  187.     /**
  188.      * @Route("/startups", name="homepage_startups_home")
  189.      * @Route("/en/startups", name="homepage_startups_home_english")
  190.      * @Route("/fr/startups", name="homepage_startups_home_french")
  191.      */
  192.     public function indexStartupsHomepageAction(Request $request)
  193.     {
  194.         $em $this->getDoctrine()->getManager();
  195.         $redirect     json_decode(base64_decode((string) $request->get('redirect')));
  196.         $redirectUrl  $request->get('redirect');
  197.         $templateVars $em->getRepository(Startup::class)->getTemplateVars($request);
  198.         $orderBy      $templateVars['dimensions'] ?: ['score' => 'DESC'];
  199.         // Neue Zeile - Sortierung nach lastModified (neueste zuerst)
  200.         $orderBy $templateVars['dimensions'] ?: ['lastModified' => 'DESC'];
  201.         $visibility   'public';
  202.         $criteria     = ['visibility' => $visibility] + $templateVars['criteria'];
  203.         $lang         Utility::getLangByPathInfo($request->getPathInfo());
  204.         $teamId 0;
  205.         if ($user $this->getUser()) {
  206.             $teamId $user->getMemberId();
  207.             $em->getRepository(User::class)->writeActivity($user);
  208.         }
  209.         $total $em->getRepository(Startup::class)->countByCriteria($criteria$teamId);
  210.         if ($total 2560) {
  211.             $limit 2560;
  212.         } else {
  213.             $limit $total ?: 1;
  214.         }
  215.         if (!$page $request->get('page')) {
  216.             $page 1;
  217.         }
  218.         $startups $em->getRepository(Startup::class)->findPaginated($criteria$teamId$orderBy$page$limit);
  219.         $startupsExtern $em->getRepository(Startup::class)->findPaginated($criteria + ['startplatz' => 'extern'], $teamId$orderBy$page$limit);
  220.         $rheinlandPitchBatches = [];
  221.         $rheinlandPitchWinnerApplications = [];
  222.         $rheinlandPitchWinnerStartups = [];
  223.         if (array_key_exists("rheinlandPitchBestResult"$criteria)) {
  224.             /*
  225.              * now use a totally different logic
  226.              * first we find all rheinlandPitchBatches
  227.              * then we find all winnerApplications
  228.              * then we find all related startups
  229.              */
  230.             $rheinlandPitchBatches $em->getRepository(Batch::class)->findBy(['programId'=>1,'focusStatus'=>['4_past','3_previous','2_current']], ['pitchDate'=>'DESC']);
  231.             $rheinlandPitchWinnerApplications $em->getRepository(Application::class)->findBy(['programId'=>1,'pitchPosition'=>1], ['batchId'=>'DESC']);
  232.             $rheinlandPitchWinnerStartupIds array_map(fn (Application $entity) => $entity->getStartupId(), $rheinlandPitchWinnerApplications);
  233.             $rheinlandPitchWinnerStartups $em->getRepository(Startup::class)->findBy(['id'=>$rheinlandPitchWinnerStartupIds]);
  234.             $rheinlandPitchWinnerStartupIds array_map(fn (Startup $entity) => $entity->getId(), $rheinlandPitchWinnerStartups);
  235.             $rheinlandPitchWinnerStartups  array_combine($rheinlandPitchWinnerStartupIds$rheinlandPitchWinnerStartups);
  236.         }
  237.         $parentPageSlug "startups";
  238.         if (!$parentPage $em->getRepository(Page::class)->findOneBy(['slug' => $parentPageSlug])) {
  239.             $parentPage = new Page();
  240.             $parentPage->setTitle('Die STARTPLATZ Startups');
  241.             $parentPage->setTeaser('Die erfolgreichen Startups starten hier durch');
  242.             $parentPage->setDescription('Page Description');
  243.         }
  244.         $acceleratorCurrentBatchNumber $em->getRepository(Option::class)->getAcceleratorCurrentBatchNumber();
  245.         $startupsCurrentBatch $em->getRepository(Startup::class)->findPaginated($criteria + ['batch' => $acceleratorCurrentBatchNumber], $teamId$orderBy1128);
  246.         $startupsLastBatch $em->getRepository(Startup::class)->findPaginated($criteria + ['batch' => $acceleratorCurrentBatchNumber -], $teamId$orderBy1128);
  247.         $startupsBatch20 $em->getRepository(Startup::class)->findPaginated($criteria + ['batch' => $acceleratorCurrentBatchNumber -2], $teamId$orderBy1128);
  248.         $startupsSpCgn $em->getRepository(Startup::class)->findPaginated($criteria + ['startplatz' => 'sp-cgn'], $teamId$orderBy1128);
  249.         $startupsSpDus $em->getRepository(Startup::class)->findPaginated($criteria + ['startplatz' => 'sp-dus'], $teamId$orderBy1128);
  250.         $startupsAlumni $em->getRepository(Startup::class)->findPaginated($criteria + ['startplatz' => 'alumni'], $teamId$orderBy1128);
  251.         $startupsRheinlandPitch = [];
  252.         $rheinlandPitchOrderBy      $templateVars['dimensions'] ? $templateVars['dimensions']+ ['rheinlandPitch' => 'ASC','rheinlandPitchBestResult' => 'DESC'] : ['rheinlandPitch' => 'ASC','rheinlandPitchBestResult' => 'DESC'];
  253.         $rheinlandPitchCurrentPitchNumber $em->getRepository(Option::class)->getRheinlandPitchCurrentPitchNumber();
  254.         $startupsRheinlandPitch $em->getRepository(Startup::class)->findPaginated($criteria + ['pitchNumber' => $rheinlandPitchCurrentPitchNumber], $teamId$rheinlandPitchOrderBy11280);
  255.         // startups of current rheinland pitch
  256.         // $startupsRheinlandPitch = $em->getRepository(Startup::class)->findCurrentRheinlandPitchStartups('2_current');
  257.         $startupsGruenderstipendium = [];
  258.         $startupsGruenderstipendium $em->getRepository(Startup::class)->findPaginated($criteria + ['gsStatus' => ['funded','recommended']], $teamId$orderBy11280);
  259.         $startupsGruenderstipendiumAlumni = [];
  260.         $startupsGruenderstipendiumAlumni $em->getRepository(Startup::class)->findPaginated($criteria + ['gsStatus' => ['alumni']], $teamId$orderBy11280);
  261.         $industries $em->getRepository(Startup::class)->getAggregateByGroup('industry'$criteria);
  262.         // get teamIds
  263.         $teamIds array_map(fn ($entity) => $entity['teamId'], $startups);
  264.         $teamIds $teamIds array_map(fn ($entity) => $entity['teamId'], $startupsCurrentBatch);
  265.         $teamIds $teamIds array_map(fn ($entity) => $entity['teamId'], $startupsLastBatch);
  266.         $teamIds $teamIds array_map(fn ($entity) => $entity['teamId'], $startupsBatch20);
  267.         $teamIds $teamIds array_map(fn ($entity) => $entity['teamId'], $startupsSpCgn);
  268.         $teamIds $teamIds array_map(fn ($entity) => $entity['teamId'], $startupsSpDus);
  269.         $teamIds $teamIds array_map(fn ($entity) => $entity['teamId'], $startupsAlumni);
  270.         $teamIds $teamIds array_map(fn ($entity) => $entity['teamId'], $startupsExtern);
  271.         $teamIds $teamIds array_map(fn ($entity) => $entity['teamId'], $startupsRheinlandPitch);
  272.         $teamIds $teamIds array_map(fn ($entity) => $entity['teamId'], $startupsGruenderstipendium);
  273.         $teamIds $teamIds array_map(fn ($entity) => $entity['teamId'], $startupsGruenderstipendiumAlumni);
  274.         $teams $em->getRepository(Team::class)->findBy(['id'=>$teamIds]);
  275.         $teamIds array_map(fn ($entity) => $entity->getId(), $teams);
  276.         $teams array_combine($teamIds$teams);
  277.         return $this->render('@StartPlatzAlphaBundle/Startup/index.startups.homepage.html.twig', [
  278.             'startups' => $startups,
  279.             'startupsCurrentBatch' => $startupsCurrentBatch,
  280.             'startupsLastBatch' => $startupsLastBatch,
  281.             'startupsBatch20' => $startupsBatch20,
  282.             'startupsSpCgn' => $startupsSpCgn,
  283.             'startupsSpDus' => $startupsSpDus,
  284.             'startupsAlumni' => $startupsAlumni,
  285.             'startupsExtern' => $startupsExtern,
  286.             'startupsRheinlandPitch'     => $startupsRheinlandPitch,
  287.             'startupsGruenderstipendium'       => $startupsGruenderstipendium,
  288.             'startupsGruenderstipendiumAlumni' => $startupsGruenderstipendiumAlumni,
  289.             'teams'              => $teams,
  290.             'currentBatchNumber' => $acceleratorCurrentBatchNumber,
  291.             'industries'         => $industries,
  292.             'parentPage'         => $parentPage,
  293.             'pageType'           => 'startup',
  294.             'topic'              => 'deepTech',
  295.             'lang' => $lang,
  296.             'rheinlandPitchBatches' => $rheinlandPitchBatches,
  297.             'rheinlandPitchWinnerApplications' => $rheinlandPitchWinnerApplications,
  298.             'rheinlandPitchWinnerStartups' => $rheinlandPitchWinnerStartups,
  299.         'maxPages' => ceil($total $limit),
  300.             'thisPage' => $page,
  301.             'total' => $total,
  302.             'limit' => $limit,
  303.             'criteria' => $criteria,
  304.             'visibility' => $visibility,
  305.             'templateVars' => $templateVars,
  306.             'backUrl' => $redirectUrl,
  307.             'menuLinksAndPhrases' => $this->menuTranslationService->getMenuLinksAndPhrases($request->server->get('REQUEST_URI')),
  308.             'redirectUrl' => base64_encode(json_encode(['path' => 'website_startups_list''parameters' => $templateVars])),
  309.         ]);
  310.     }
  311.     /**
  312.      * @Route("/x/startups/industries/list", name="x_startups_industries_list")
  313.      */
  314.     public function listIndustriesAjaxAction(Request $request)
  315.     {
  316.         $em $this->getDoctrine()->getManager();
  317.         $redirect json_decode(base64_decode((string) $request->get('redirect')));
  318.         $templateVars $em->getRepository(Startup::class)->getTemplateVars($request);
  319.         $currentCriteria $templateVars['criteria'];
  320.         if (isset($templateVars['criteria']['industry'])) {
  321.             unset($templateVars['criteria']['industry']);
  322.         }
  323.         if (isset($templateVars['criteria']['isBookmarked'])) {
  324.             unset($templateVars['criteria']['isBookmarked']);
  325.         }
  326.         if (!$source $request->get('source')) {
  327.             $visibility 'sp-connect';
  328.             $targetPath "x_connect_startups_home";
  329.         } else {
  330.             $visibility 'public';
  331.             $targetPath "homepage_startups_home";
  332.         }
  333.         $criteria = ['visibility' => $visibility'status' => 'active''team' => 'exists'] + $templateVars['criteria'];
  334.         if ($user $this->getUser()) {
  335.             $teamId $user->getMemberId();
  336.         } else {
  337.             $teamId 0;
  338.         }
  339.         $industries $em->getRepository(Startup::class)->findIndustries($criteria$teamId);
  340.         return $this->render('@StartPlatzAlpha/Default/list.startupIndustries.modal.html.twig', [
  341.             'title' => "Available Industries",
  342.             'industries' => $industries,
  343.             'targetPath'      => $targetPath,
  344.             'currentCriteria' => $currentCriteria,
  345.             'templateVars'    => $templateVars,
  346.             'redirectUrl' => $request->get('redirect'),
  347.         ]);
  348.     }
  349.     /**
  350.      * @Route("/x/startups/tags/list", name="x_startups_tags_list")
  351.      */
  352.     public function listTagsAjaxAction(Request $request)
  353.     {
  354.         $em $this->getDoctrine()->getManager();
  355.         $redirect json_decode(base64_decode((string) $request->get('redirect')));
  356.         $templateVars $em->getRepository(Startup::class)->getTemplateVars($request);
  357.         $currentCriteria $templateVars['criteria'];
  358.         if (isset($templateVars['criteria']['tags'])) {
  359.             unset($templateVars['criteria']['tags']);
  360.         }
  361.         if (isset($templateVars['criteria']['isBookmarked'])) {
  362.             unset($templateVars['criteria']['isBookmarked']);
  363.         }
  364.         if (!$source $request->get('source')) {
  365.             $visibility 'sp-connect';
  366.             $targetPath "x_connect_startups_home";
  367.         } else {
  368.             $visibility 'public';
  369.             $targetPath "homepage_startups_home";
  370.         }
  371.         $criteria = ['visibility' => $visibility'status' => 'active''team' => 'exists'] + $templateVars['criteria'];
  372.         if ($user $this->getUser()) {
  373.             $teamId $user->getMemberId();
  374.         } else {
  375.             $teamId 0;
  376.         }
  377.         $entities $em->getRepository(Startup::class)->findTags($criteria$teamId);
  378.         return $this->render('@StartPlatzAlpha/Default/list.tags.modal.html.twig', [
  379.             'title' => "Tags",
  380.             'entities' => $entities,
  381.             'btnClass' => "btn-outline-info",
  382.             'targetEntity' => "tags",
  383.             'targetPath' => $targetPath,
  384.             'currentCriteria' => $currentCriteria,
  385.             'templateVars' => $templateVars,
  386.             'redirect' => $redirect,
  387.             'redirectUrl' => $request->get('redirect'),
  388.         ]);
  389.     }
  390.     /**
  391.      * @Route("/x/startups/filter/rheinland-pitch", name="x_startups_filter_rheinland-pitch")
  392.      */
  393.     public function selectFilterRheinlandPitchAction(Request $request)
  394.     {
  395.         $em $this->getDoctrine()->getManager();
  396.         $redirect json_decode(base64_decode((string) $request->get('redirect')));
  397.         $templateVars $em->getRepository(Startup::class)->getTemplateVars($request);
  398.         if (!$source $request->get('source')) {
  399.             $visibility 'sp-connect';
  400.             $targetPath "x_connect_startups_home";
  401.         } else {
  402.             $visibility 'public';
  403.             $targetPath "homepage_startups_home";
  404.         }
  405.         $criteria = ['visibility' => $visibility'status' => 'active''team' => 'exists'] + $templateVars['criteria'];
  406.         if ($user $this->getUser()) {
  407.             $teamId $user->getMemberId();
  408.         } else {
  409.             $teamId 0;
  410.         }
  411.         $filter $request->get('filter');
  412.         $group1 "rheinlandPitchStatus";
  413.         $aggregates1 $em->getRepository(Startup::class)->getAggregateByGroup($group1$criteria);
  414.         $group2 "rheinlandPitchBestResult";
  415.         $aggregates2 $em->getRepository(Startup::class)->getAggregateByGroup($group2$criteria);
  416.         // batches
  417.         $aggregatesBatches $em->getRepository(Startup::class)->findApplicationsByProgramId(1);
  418.         return $this->render('@StartPlatzAlpha/Default/list.rheinland-pitch.modal.html.twig', [
  419.             'title'             => "Set Filter on {$filter}",
  420.             'btnClass'          => "btn-outline-info",
  421.             'group1'            => $group1,
  422.             'group2'            => $group2,
  423.             'aggregates1'       => $aggregates1,
  424.             'aggregates2'       => $aggregates2,
  425.             'aggregatesBatches' => $aggregatesBatches,
  426.             'targetPath'        => $targetPath,
  427.             'templateVars'      => $templateVars,
  428.             'redirect'          => $redirect,
  429.             'redirectUrl'       => $request->get('redirect'),
  430.         ]);
  431.     }
  432.     /**
  433.      * @Route("/x/startups/filter", name="x_startups_filter")
  434.      */
  435.     public function selectFilterAction(Request $request)
  436.     {
  437.         $em $this->getDoctrine()->getManager();
  438.         $redirect json_decode(base64_decode((string) $request->get('redirect')));
  439.         $templateVars $em->getRepository(Startup::class)->getTemplateVars($request);
  440.         if (!$source $request->get('source')) {
  441.             $visibility 'sp-connect';
  442.         } else {
  443.             $visibility 'public';
  444.         }
  445.         if (!$targetPath $request->get('targetPath')) {
  446.             if ($visibility == 'sp-connect') {
  447.                 $targetPath "x_connect_startups_home";
  448.             } else {
  449.                 $targetPath "homepage_startups_home";
  450.             }
  451.         }
  452.         $criteria = ['visibility' => $visibility'status' => 'active''team' => 'exists'] + $templateVars['criteria'];
  453.         if ($user $this->getUser()) {
  454.             $teamId $user->getMemberId();
  455.         } else {
  456.             $teamId 0;
  457.         }
  458.         $group $request->get('filter');
  459.         $aggregates $em->getRepository(Startup::class)->getAggregateByGroup($group$criteria);
  460.         $group2 "";
  461.         $aggregates2 = [];
  462.         if ($group == 'accelerator') {
  463.             $group2 "batch";
  464.             $aggregates2 $em->getRepository(Startup::class)->getAggregateByGroup($group2$criteria, ['batchYear' => 'ASC'], true);
  465.         }
  466.         if ($group == 'rheinlandPitch') {
  467.             $group2 "pitchNumber";
  468.             $aggregates2 $em->getRepository(Startup::class)->findAndExpandAggregatesByField($group2$criteria$teamId$group);
  469.         }
  470.         return $this->render('@StartPlatzAlpha/Default/list.aggregates.modal.html.twig', [
  471.             'title'        => "Set Filter on {$group}",
  472.             'aggregates'   => $aggregates,
  473.             'btnClass'     => "btn-outline-info",
  474.             'group'        => $group,
  475.             'group2'       => $group2,
  476.             'aggregates2'  => $aggregates2,
  477.             'targetPath'   => $targetPath,
  478.             'templateVars' => $templateVars,
  479.             'redirect'     => $redirect,
  480.             'redirectUrl'  => $request->get('redirect'),
  481.         ]);
  482.     }
  483.     /**
  484.      * @Route("/startups-legacy", name="extern_startups_home")
  485.      */
  486.     public function indexLegacyAction(Request $request)
  487.     {
  488.         $em $this->getDoctrine()->getManager();
  489.         $member $em->getRepository(Member::class)->findOneBy([]);
  490.         $fields $this->feedbackService->getEntityMethodsArray($member, ['teams']);
  491.         $templateVars $em->getRepository(Member::class)->getTemplateVars($request);
  492.         if ($user $this->getUser()) {
  493.             $em->getRepository(User::class)->writeActivity($user);
  494.         }
  495.         $metaNameSectionBatch21 'website.startups.section.batch21';
  496.         $metaNameSectionBatch20 'website.startups.section.batch20';
  497.         $metaNameSectionBatch19 'website.startups.section.batch19';
  498.         $metaNameSectionBatch18 'website.startups.section.batch18';
  499.         $metaNameSectionBatch17 'website.startups.section.batch17';
  500.         $metaNameSectionKoeln 'website.startups.section.koeln';
  501.         $metaNameSectionDus 'website.startups.section.dus';
  502.         $metaNameSectionAlumni 'website.startups.section.alumni';
  503.         $edit $request->get('edit');
  504.         if (!in_array($edit, ['updateBatch21''updateBatch20''updateBatch19''updateBatch18''updateBatch17''updateKoeln''updateDus''updateAlumni'])) {
  505.             $edit null;
  506.         }
  507.         $sectionBatch21 $this->getSection($metaNameSectionBatch21);
  508.         $sectionBatch20 $this->getSection($metaNameSectionBatch20);
  509.         $sectionBatch19 $this->getSection($metaNameSectionBatch19);
  510.         $sectionBatch18 $this->getSection($metaNameSectionBatch18);
  511.         $sectionBatch17 $this->getSection($metaNameSectionBatch17);
  512.         $sectionKoeln $this->getSection($metaNameSectionKoeln);
  513.         $sectionDus $this->getSection($metaNameSectionDus);
  514.         $sectionAlumni $this->getSection($metaNameSectionAlumni);
  515.         switch ($edit) {
  516.             case 'updateBatch21':
  517.                 $content $this->transformArrayIntoCsvString($sectionBatch21['content']);
  518.                 $form $this->setPlainEditorForm($content);
  519.                 break;
  520.             case 'updateBatch20':
  521.                 $content $this->transformArrayIntoCsvString($sectionBatch20['content']);
  522.                 $form $this->setPlainEditorForm($content);
  523.                 break;
  524.             case 'updateBatch19':
  525.                 $content $this->transformArrayIntoCsvString($sectionBatch19['content']);
  526.                 $form $this->setPlainEditorForm($content);
  527.                 break;
  528.             case 'updateBatch18':
  529.                 $content $this->transformArrayIntoCsvString($sectionBatch18['content']);
  530.                 $form $this->setPlainEditorForm($content);
  531.                 break;
  532.             case 'updateBatch17':
  533.                 $content $this->transformArrayIntoCsvString($sectionBatch17['content']);
  534.                 $form $this->setPlainEditorForm($content);
  535.                 break;
  536.             case 'updateKoeln':
  537.                 $content $this->transformArrayIntoCsvString($sectionKoeln['content']);
  538.                 $form $this->setPlainEditorForm($content);
  539.                 break;
  540.             case 'updateDus':
  541.                 $content $this->transformArrayIntoCsvString($sectionDus['content']);
  542.                 $form $this->setPlainEditorForm($content);
  543.                 break;
  544.             case 'updateAlumni':
  545.                 $content $this->transformArrayIntoCsvString($sectionAlumni['content']);
  546.                 $form $this->setPlainEditorForm($content);
  547.                 break;
  548.             default:
  549.                 $content "";
  550.                 $form $this->setEditorForm($content);
  551.         }
  552.         $form->handleRequest($request);
  553.         if ($form->isSubmitted() && $form->isValid()) {
  554.             $data $form->getData();
  555.             $importString $data['content'];
  556.             $rows explode(PHP_EOL, (string) $importString);
  557.             switch ($edit) {
  558.                 case 'updateBatch21':
  559.                     $sectionBatch21['content'] = [];
  560.                     foreach ($rows as $row) {
  561.                         $sectionBatch21['content'][] = str_getcsv($row"\t");
  562.                     }
  563.                     $em->getRepository(Option::class)->setOptionMetaValueJsonEncoded($metaNameSectionBatch21null$sectionBatch21);
  564.                     break;
  565.                 case 'updateBatch20':
  566.                     $sectionBatch20['content'] = [];
  567.                     foreach ($rows as $row) {
  568.                         $sectionBatch20['content'][] = str_getcsv($row"\t");
  569.                     }
  570.                     $em->getRepository(Option::class)->setOptionMetaValueJsonEncoded($metaNameSectionBatch20null$sectionBatch20);
  571.                     break;
  572.                 case 'updateBatch19':
  573.                     $sectionBatch19['content'] = [];
  574.                     foreach ($rows as $row) {
  575.                         $sectionBatch19['content'][] = str_getcsv($row"\t");
  576.                     }
  577.                     $em->getRepository(Option::class)->setOptionMetaValueJsonEncoded($metaNameSectionBatch19null$sectionBatch19);
  578.                     break;
  579.                 case 'updateBatch18':
  580.                     $sectionBatch18['content'] = [];
  581.                     foreach ($rows as $row) {
  582.                         $sectionBatch18['content'][] = str_getcsv($row"\t");
  583.                     }
  584.                     $em->getRepository(Option::class)->setOptionMetaValueJsonEncoded($metaNameSectionBatch18null$sectionBatch18);
  585.                     break;
  586.                 case 'updateBatch17':
  587.                     $sectionBatch17['content'] = [];
  588.                     foreach ($rows as $row) {
  589.                         $sectionBatch17['content'][] = str_getcsv($row"\t");
  590.                     }
  591.                     $em->getRepository(Option::class)->setOptionMetaValueJsonEncoded($metaNameSectionBatch17null$sectionBatch17);
  592.                     break;
  593.                 case 'updateKoeln':
  594.                     $sectionKoeln['content'] = [];
  595.                     foreach ($rows as $row) {
  596.                         $sectionKoeln['content'][] = str_getcsv($row"\t");
  597.                     }
  598.                     $em->getRepository(Option::class)->setOptionMetaValueJsonEncoded($metaNameSectionKoelnnull$sectionKoeln);
  599.                     break;
  600.                 case 'updateDus':
  601.                     $sectionDus['content'] = [];
  602.                     foreach ($rows as $row) {
  603.                         $sectionDus['content'][] = str_getcsv($row"\t");
  604.                     }
  605.                     $em->getRepository(Option::class)->setOptionMetaValueJsonEncoded($metaNameSectionDusnull$sectionDus);
  606.                     break;
  607.                 case 'updateAlumni':
  608.                     $sectionAlumni['content'] = [];
  609.                     foreach ($rows as $row) {
  610.                         $sectionAlumni['content'][] = str_getcsv($row"\t");
  611.                     }
  612.                     $em->getRepository(Option::class)->setOptionMetaValueJsonEncoded($metaNameSectionAlumninull$sectionAlumni);
  613.                     break;
  614.             }
  615.             $this->session->getFlashBag()->add('notice''SUCCESS data saved');
  616.         }
  617.         $sectionBatch21 $this->getSection($metaNameSectionBatch21);
  618.         $sectionBatch20 $this->getSection($metaNameSectionBatch20);
  619.         $sectionBatch19 $this->getSection($metaNameSectionBatch19);
  620.         $sectionBatch18 $this->getSection($metaNameSectionBatch18);
  621.         $sectionBatch17 $this->getSection($metaNameSectionBatch17);
  622.         $sectionKoeln $this->getSection($metaNameSectionKoeln);
  623.         $sectionDus $this->getSection($metaNameSectionDus);
  624.         $sectionAlumni $this->getSection($metaNameSectionAlumni);
  625.         return $this->render('@StartPlatzAlphaBundle/Startup/index.legacy.html.twig', [
  626.             'templateVars' => [],
  627.             'form' => $form->createView(),
  628.             'sectionBatch21' => $sectionBatch21,
  629.             'sectionBatch20' => $sectionBatch20,
  630.             'sectionBatch19' => $sectionBatch19,
  631.             'sectionBatch18' => $sectionBatch18,
  632.             'sectionBatch17' => $sectionBatch17,
  633.             'sectionKoeln' => $sectionKoeln,
  634.             'sectionDus' => $sectionDus,
  635.             'sectionAlumni' => $sectionAlumni,
  636.             'edit' => $edit,
  637.             'menuLinksAndPhrases' => $this->menuTranslationService->getMenuLinksAndPhrases($request->server->get('REQUEST_URI')),
  638.             'redirectUrl' => base64_encode(json_encode(['path' => 'extern_startups_home''parameters' => []])),
  639.         ]);
  640.     }
  641.     /**
  642.      * @Route("/startup/{slug}", name="homepage_startup_single")
  643.      * @Route("/en/startup/{slug}", name="homepage_startup_single_english")
  644.      */
  645.     public function singleAction(Request $request$slug)
  646.     {
  647.         $em $this->getDoctrine()->getManager();
  648.         $templateVars $em->getRepository(Team::class)->getTemplateVars($request);
  649.         /** @var User $user */
  650.         if ($user $this->getUser()) {
  651.             $em->getRepository(User::class)->writeActivity($user);
  652.         }
  653.         $id explode('-', (string) $slug)[0];
  654.         $slug explode('-', (string) $slug)[1];
  655.         /** @var Startup $startup */
  656.         if (!$startup $em->getRepository(Startup::class)->findOneBy(['id' => $id])) {
  657.             $this->session->getFlashBag()->add('notice''ERROR slug not found');
  658.             return $this->redirect($this->generateUrl('homepage_startups_home'));
  659.         }
  660.         if (!$team $em->getRepository(Team::class)->findOneBy(['id' => $startup->getTeamId()])) {
  661.             $this->session->getFlashBag()->add('notice''ERROR insufficient data');
  662.             return $this->redirect($this->generateUrl('homepage_startups_home'));
  663.         }
  664.         $feedItems = [];
  665.         $entities = [];
  666.         if ($startup->getSlug()) {
  667.             // feedTags are expected to be a jsonArray
  668.             $feedTags json_encode([$startup->getSlug()]);
  669.             $feedItems $em->getRepository(Feed::class)->findByFeedTag($feedTags);
  670.             $entities $em->getRepository(Feed::class)->getEntitiesByFeedItems($feedItems);
  671.         }
  672.         // rheinlandPitch has programId == 1
  673.         $rheinlandPitches $em->getRepository(Application::class)->findApplicationsAndBatchesByStartupIdAndProgramId($id1);
  674.         $memberTypes = [];
  675.         $teamIndustries   = [];
  676.         $teamIndustryList "";
  677.         $applications     = [];
  678.         if ($team) {
  679.             if ($team->getType() == 'Partner') {
  680.                 $memberTypes = ['GF''AP'];
  681.             }
  682.             $teamIndustries $team->getIndustries();
  683.             $teamIndustryList explode("#", (string) $teamIndustries);
  684.             // plausibility checks for members of that team
  685.             $em->getRepository(Member::class)->checkIfDescriptionIsEmptyButMentorProfileIsFilled($team);
  686.             $relevantProgramIds = ['1','2','3'];
  687.             $applications $em->getRepository(Application::class)->findBy(['teamId'=>$team->getId(),'programId'=>$relevantProgramIds]);
  688.         }
  689.         $members $em->getRepository(MemberTeam::class)->getTeamMembers($id$memberTypes);
  690.         $allowEdit false;
  691.         $teamMember false;
  692.         if($user) {
  693.             $userEmail $this->getUser()->getEmail();
  694.             foreach ($members as $member) {
  695.                 if ($member['email'] == $userEmail) {
  696.                     $teamMember true;
  697.                     if ($member['type'] == 'AP' || $member['type'] == 'GF') {
  698.                         $allowEdit true;
  699.                     }
  700.                 }
  701.             }
  702.         }
  703.         // create slugs from team on the fly and from startup, what is stored there
  704.         if ($team) {
  705.             $slugs[] = Utility::generateSlug($team->getShortName());
  706.         }
  707.         if ($startup->getSlug()) {
  708.             $slugs[] = $startup->getSlug();
  709.         }
  710.         $feedTags json_encode(array_values(array_unique($slugs)));
  711.         if ($feedTags) {
  712.             $feedItems $em->getRepository(Feed::class)->findByFeedTag($feedTags);
  713.             $em->getRepository(Actor::class)->updateScoreByFeedItems(is_countable($feedItems) ? count($feedItems) : 0$startup->getId());
  714.             $entities $em->getRepository(Feed::class)->getEntitiesByFeedItems($feedItems);
  715.         }
  716.         $hasVisibleApplication false;
  717.         foreach ($applications as $application) {
  718.             if($application->getVisibility() == 'sp-connect') {
  719.                 $hasVisibleApplication true;
  720.                 break;
  721.             }
  722.         }
  723.         $lang Utility::getLangByPathInfo($request->getPathInfo());
  724.         if ($startup->getVisibility() == 'public') {
  725.             return $this->render('@StartPlatzAlphaBundle/Startup/single.homepage.html.twig', [
  726.                 'id' => $id,
  727.                 'startup' => $startup,
  728.                 'team' => $team,
  729.                 'feedItems' => $feedItems,
  730.                 'entities' => $entities,
  731.                 'lang' => $lang,
  732.                 'rheinlandPitches' => $rheinlandPitches,
  733.                 'redirectUrl' => base64_encode(json_encode(['path' => 'homepage_startup_single''parameters' => ['slug' => $id '-' $slug]])),
  734.                 'menuLinksAndPhrases' => $this->menuTranslationService->getMenuLinksAndPhrases($request->server->get('REQUEST_URI')),
  735.                 'applications' => $applications,
  736.                 'hasVisibleApplication' => $hasVisibleApplication,
  737.                 'methodsTeam'           => $team $this->feedbackService->getEntityMethodsArray($team, ['services''members']) : [],
  738.                 'methodsStartup' => $startup $this->feedbackService->getEntityMethodsArray($startup, []) : [],
  739.                 'feedTags' => $feedTags,
  740.                 'actor' => $em->getRepository(Actor::class)->findOneBy(['externalId' => $startup->getId()]),
  741.                 'templateVars' => $templateVars,
  742.                 'queryString' => '',
  743.                 //  'members' => $members,
  744.                 'memberTypes' => $memberTypes,
  745.                 'teamIndustryList' => $teamIndustryList,
  746.                 'allowEdit' => $allowEdit,
  747.                 'teamMember' => $teamMember,
  748.                 'memberTypeLabels' => $em->getRepository(MemberTeam::class)->getMemberTypeLabels(),
  749.                 'currentPath' => '/x/connect/team/{id}',
  750.                 'backUrl' => $request->get('redirect') ?: base64_encode(json_encode(['path' => 'x_connect_startups_home''parameters' => $templateVars])),
  751.             ]);
  752.         } else {
  753.             return $this->render('@StartPlatzAlphaBundle/Startup/single.homepage.sorry.html.twig', [
  754.                 'lang' => $lang,
  755.                 'menuLinksAndPhrases' => $this->menuTranslationService->getMenuLinksAndPhrases($request->server->get('REQUEST_URI')),
  756.                 'redirectUrl' => base64_encode(json_encode(['path' => 'homepage_startup_single''parameters' => ['slug' => $id '-' $slug]])),
  757.              ]);
  758.         }
  759.     }
  760.     /**
  761.      * @Route("/x/community/startups/home/", name="x_startups_home")
  762.      * @Security("is_granted('ROLE_USER')")
  763.      */
  764.     public function indexStartupsAction(Request $request)
  765.     {
  766.         $em $this->getDoctrine()->getManager();
  767.         $redirect json_decode(base64_decode((string) $request->get('redirect')));
  768.         $redirectUrl $request->get('redirect');
  769.         $templateVars $em->getRepository(Startup::class)->getTemplateVars($request);
  770.         $orderBy $templateVars['dimensions'] ?: [];
  771.         $visibility 'sp-connect';
  772.         $criteria = ['visibility' => $visibility] + $templateVars['criteria'];
  773.         $teamId 0;
  774.         if ($user $this->getUser()) {
  775.             $teamId $user->getMemberId();
  776.             $em->getRepository(User::class)->writeActivity($user);
  777.             $member $em->getRepository(Member::class)->find($user->getMemberId());
  778.         }
  779.         $total $em->getRepository(Startup::class)->countByCriteria($criteria$teamId);
  780.         if ($total 12) {
  781.             $limit 12;
  782.         } else {
  783.             $limit $total ?: 1;
  784.         }
  785.         if (!$page $request->get('page')) {
  786.             $page 1;
  787.         }
  788.         $startups $em->getRepository(Startup::class)->findPaginated($criteria$teamId$orderBy$page$limit);
  789.         $lang $request->get('lang');
  790.         if (str_contains((string) $member->getTags(), 'beta')) {
  791.             $view '@StartPlatzAlphaBundle/Startup/Startups__index.twig';
  792.         } else {
  793.             $view '@StartPlatzAlphaBundle/Startup/Startups__index_old.twig';
  794.         }
  795.         return $this->render($view, [
  796.             'maxPages' => ceil($total $limit),
  797.             'thisPage' => $page,
  798.             'total' => $total,
  799.             'criteria' => $criteria,
  800.             'visibility' => $visibility,
  801.             'templateVars' => $templateVars,
  802.             'startups' => $startups,
  803.             'backUrl' => $redirectUrl,
  804.             'menuLinksAndPhrases' => $this->menuTranslationService->getMenuLinksAndPhrases($request->server->get('REQUEST_URI')),
  805.             'redirectUrl' => base64_encode(json_encode(['path' => 'website_startups_list''parameters' => $templateVars])),
  806.         ]);
  807.     }
  808.     /**
  809.      * @Route("/startup-database/list/", name="website_startups_list")
  810.      * @Route("/startup-database/list/", name="extern_startups_list")
  811.      * @Security("is_granted('ROLE_USER')")
  812.      */
  813.     public function listAction(Request $request)
  814.     {
  815.         $em $this->getDoctrine()->getManager();
  816.         $redirect json_decode(base64_decode((string) $request->get('redirect')));
  817.         $redirectUrl $request->get('redirect');
  818.         $templateVars $em->getRepository(Startup::class)->getTemplateVars($request);
  819.         $orderBy $templateVars['dimensions'] ?: [];
  820.         $visibility 'public';
  821.         $criteria = ['visibility' => $visibility] + $templateVars['criteria'];
  822.         $teamId 0;
  823.         if ($user $this->getUser()) {
  824.             $teamId $user->getMemberId();
  825.             $em->getRepository(User::class)->writeActivity($user);
  826.         }
  827.         $total $em->getRepository(Startup::class)->countByCriteria($criteria$teamId);
  828.         if ($total 12) {
  829.             $limit 12;
  830.         } else {
  831.             $limit $total ?: 1;
  832.         }
  833.         if (!$page $request->get('page')) {
  834.             $page 1;
  835.         }
  836.         $startups $em->getRepository(Startup::class)->findPaginated($criteria$teamId$orderBy$page$limit);
  837.         $lang $request->get('lang');
  838.         $targetPath $request->server->get('REQUEST_URI');
  839.         return $this->render('@StartPlatzAlphaBundle/Startup/list.html.twig', [
  840.             'targetPath' => $targetPath,
  841.             'lang' => $lang,
  842.             'maxPages' => ceil($total $limit),
  843.             'thisPage' => $page,
  844.             'total' => $total,
  845.             'criteria' => $criteria,
  846.             'visibility' => $visibility,
  847.             'templateVars' => $templateVars,
  848.             'startups' => $startups,
  849.             'backUrl' => $redirectUrl,
  850.             'menuLinksAndPhrases' => $this->menuTranslationService->getMenuLinksAndPhrases($request->server->get('REQUEST_URI')),
  851.             'redirectUrl' => base64_encode(json_encode(['path' => 'website_startups_list''parameters' => $templateVars])),
  852.         ]);
  853.     }
  854.     /**
  855.      * @Route("/startup-database/show/{id}/{slug}", name="extern_startups_single")
  856.      */
  857.     public function singleExternAction(Request $request$id$slug)
  858.     {
  859.         $em $this->getDoctrine()->getManager();
  860.         if ($user $this->getUser()) {
  861.             $em->getRepository(User::class)->writeActivity($user);
  862.         }
  863.         if (!$redirect json_decode(base64_decode((string) $request->get('redirect')))) {
  864.             $redirect = new stdClass();
  865.             $redirect->path 'website_startups_list';
  866.             $redirect->parameters = [];
  867.         }
  868.         $redirectUrl $request->get('redirect');
  869.         if (!$startup $em->getRepository(Startup::class)->findOneBy(['id' => $id'visibility' => 'public'])) {
  870.             $this->session->getFlashBag()->add('notice''ERROR 10 entity not found');
  871.             return $this->redirect($this->generateUrl($redirect->path, (array)$redirect->parameters));
  872.         }
  873.         if ($slug != $startup->getSlug()) {
  874.             return $this->redirect($this->generateUrl('extern_startups_single', ['id' => $id'slug' => $startup->getSlug(), 'redirect' => $redirectUrl]));
  875.         }
  876.         $rightToAccessTeam false;
  877.         $team false;
  878.         $memberId 0;
  879.         $teamId $startup->getTeamId();
  880.         if ($user $this->getUser()) {
  881.             $memberId $user->getMemberId();
  882.             if (!$member $em->getRepository(Member::class)->findOneBy(['id' => $memberId])) {
  883.                 $this->session->getFlashBag()->add('notice''ERROR There is a problem with your account please contact support@startplatz.de');
  884.                 return $this->redirect($this->generateUrl($redirect->path, (array)$redirect->parameters));
  885.             }
  886.             if ($team $em->getRepository(Team::class)->findOneBy(['id' => $teamId])) {
  887.                 $rightToAccessTeam $em->getRepository(MemberTeam::class)->checkAccessRight($member$team);
  888.                 $team $em->getRepository(Team::class)->checkConsistencyWithStartup($team$startup);
  889.             }
  890.         }
  891.         // the use of memberId is on purpose
  892.         $startupAttributes $em->getRepository(StartupAttribute::class)->findOneBy(['startupId' => $startup->getId(), 'teamId' => $memberId]);
  893.         $startupLivecycleEvents $em->getRepository(StartupLifecycleEvent::class)->findBy(['startupId' => $startup->getId()], ['eventDate' => 'ASC']);
  894.         $em->getRepository(StartupRelevance::class)->updateByUserAction($id'click');
  895.         $rheinlandPitches $em->getRepository(Application::class)->findBy(['startupId' => $id], ['batchId' => 'DESC']);
  896.         return $this->render('@StartPlatzAlphaBundle/Startup/single.extern.twig', [
  897.             'templateVars' => [],
  898.             'startup' => $startup,
  899.             'rightToAccessTeam' => $rightToAccessTeam,
  900.             'startupAttributes' => $startupAttributes,
  901.             'rheinlandPitches' => $rheinlandPitches,
  902.             'startupLivecycleEvents' => $startupLivecycleEvents,
  903.             'backUrl' => $redirectUrl,
  904.             'menuLinksAndPhrases' => $this->menuTranslationService->getMenuLinksAndPhrases($request->server->get('REQUEST_URI')),
  905.             'redirectUrl' => base64_encode(json_encode(['path' => 'extern_startups_single''parameters' => ['id' => $id'slug' => $startup->getSlug()]])),
  906.         ]);
  907.     }
  908.     /**
  909.      * @Route("/x/community/startup/single/{id}", name="x_community_startup_single")
  910.      * @Security("is_granted('ROLE_USER')")
  911.      */
  912.     public function singleCommunityAction(Request $request$id)
  913.     {
  914.         $em $this->getDoctrine()->getManager();
  915.         if ($user $this->getUser()) {
  916.             $em->getRepository(User::class)->writeActivity($user);
  917.         }
  918.         if (!$redirect json_decode(base64_decode((string) $request->get('redirect')))) {
  919.             $redirect = new stdClass();
  920.             $redirect->path 'x_home';
  921.             $redirect->parameters = [];
  922.         }
  923.         $redirectUrl $request->get('redirect');
  924.         if (!$startup $em->getRepository(Startup::class)->findSingleStartupByVisibility($id'sp-connect')) {
  925.             $this->session->getFlashBag()->add('notice''ERROR 20 entity not found');
  926.             return $this->redirect($this->generateUrl($redirect->path, (array)$redirect->parameters));
  927.         }
  928.         $rightToAccessTeam false;
  929.         $team false;
  930.         $memberId 0;
  931.         $teamId $startup->getTeamId();
  932.         if ($user $this->getUser()) {
  933.             $memberId $user->getMemberId();
  934.             if (!$member $em->getRepository(Member::class)->findOneBy(['id' => $memberId])) {
  935.                 $this->session->getFlashBag()->add('notice''ERROR There is a problem with your account please contact support@startplatz.de');
  936.                 return $this->redirect($this->generateUrl($redirect->path, (array)$redirect->parameters));
  937.             }
  938.             if ($team $em->getRepository(Team::class)->findOneBy(['id' => $teamId])) {
  939.                 $rightToAccessTeam $em->getRepository(MemberTeam::class)->checkAccessRight($member$team);
  940.                 $team $em->getRepository(Team::class)->checkConsistencyWithStartup($team$startup);
  941.             }
  942.         }
  943.         // the use of memberId is on purpose
  944.         $startupAttributes $em->getRepository(StartupAttribute::class)->findOneBy(['startupId' => $startup->getId(), 'teamId' => $memberId]);
  945.         $startupLivecycleEvents $em->getRepository(StartupLifecycleEvent::class)->findBy(['startupId' => $startup->getId()], ['eventDate' => 'ASC']);
  946.         $em->getRepository(StartupRelevance::class)->updateByUserAction($id'click');
  947.         $rheinlandPitches $em->getRepository(Application::class)->findBy(['startupId' => $id], ['batchId' => 'DESC']);
  948.         $lang $request->get('lang');
  949.         $targetPath $request->server->get('REQUEST_URI');
  950.         return $this->render('@StartPlatzAlphaBundle/Startup/single.sp-connect.html.twig', [
  951.             'targetPath' => $targetPath,
  952.             'lang' => $lang,
  953.             'templateVars' => [],
  954.             'startup' => $startup,
  955.             'rightToAccessTeam' => $rightToAccessTeam,
  956.             'startupAttributes' => $startupAttributes,
  957.             'rheinlandPitches' => $rheinlandPitches,
  958.             'startupLivecycleEvents' => $startupLivecycleEvents,
  959.             'backUrl' => $redirectUrl,
  960.             'menuLinksAndPhrases' => $this->menuTranslationService->getMenuLinksAndPhrases($request->server->get('REQUEST_URI')),
  961.             'redirectUrl' => base64_encode(json_encode(['path' => 'extern_startups_single''parameters' => ['id' => $id'slug' => $startup->getSlug()]])),
  962.         ]);
  963.     }
  964.     /**
  965.      * @Route("/allmeda/startups/toggle-ajax/{id}/{field}/{action}", name="startup_edit_field_ajax")
  966.      * @Security("is_granted('ROLE_ADMIN')")
  967.      */
  968.     public function setToggleAjaxAction($id$field$action)
  969.     {
  970.         $em $this->getDoctrine()->getManager();
  971.         $response $em->getRepository(Startup::class)->setField($field$action$id);
  972.         if (str_starts_with((string) $response'field ')) {
  973.             $response "SUCCESS $response";
  974.         }
  975.         return new Response($response);
  976.     }
  977.     /**
  978.      * @Route("/x/connect/startup/edit/{id}/set-with-data", name="x_connect_startup_set_field_ajax_with_data")
  979.      * @Route("/x/connect/startup/edit/{id}/set/{field}/{action}", name="x_connect_startup_set_field_ajax")
  980.      * @Security("is_granted('ROLE_USER')")
  981.      */
  982.     public function setAjaxAction(Request $request$id null$field null$action null)
  983.     {
  984.         $em $this->getDoctrine()->getManager();
  985.         $adminEmail $this->getUser()->getIsAdmin() ? $this->getUser()->getEmail() : null;
  986.         $id ?? $id $request->get('id');
  987.         $field ?? $field $request->get('field');
  988.         $action ?? $action $request->get('action');
  989.         if(!$id or !$field or !$action) {
  990.             $response 'ERROR some data is missing';
  991.         } elseif (!$startup $em->getRepository(Startup::class)->findOneBy(['id' => $id])) {
  992.             $response 'ERROR No entity found for id=' $id;
  993.         } else {
  994.             $response $em->getRepository(Startup::class)->setFieldByAjaxConnect($field$action$startup$this->getUser());
  995.             if (str_starts_with((string) $response'Updated ')) {
  996.                 if($field == 'imageLink') {
  997.                     $this->removeOldResourcesFromCloudinary("startup-banner-{$startup->getTeamId()}"$action);
  998.                 } elseif($field == 'logoUrl') {
  999.                     $this->removeOldResourcesFromCloudinary("startup-logo-{$startup->getTeamId()}"$action);
  1000.                 }
  1001.                 $response "SUCCESS $response";
  1002.             }
  1003.         }
  1004.         return new Response($response);
  1005.     }
  1006.     /**
  1007.      * @Route("/x/connect/startup/edit/{id}/{slug}", name="x_startup_edit")
  1008.      * @Security("is_granted('ROLE_USER')")
  1009.      */
  1010.     public function editStartupAction(Request $request$id$slug)
  1011.     {
  1012.         $em $this->getDoctrine()->getManager();
  1013.         $redirect json_decode(base64_decode((string) $request->get('redirect')));
  1014.         $redirectUrl $request->get('redirect');
  1015.         /** @var Startup $startup */
  1016.         if (!$startup $em->getRepository(Startup::class)->findOneBy(['id' => $id])) {
  1017.             $this->session->getFlashBag()->add('notice''ERROR 30 entity not found');
  1018.             return $this->redirect($this->generateUrl($redirect->path, (array)$redirect->parameters));
  1019.         }
  1020.         $teamId $startup->getTeamId();
  1021.         /** @var Team $team */
  1022.         $team $em->getRepository(Team::class)->findOneBy(['id' => $teamId]);
  1023.         /** @var User $user */
  1024.         $user $this->getUser();
  1025.         $teamRights $em->getRepository(MemberTeam::class)->getTeamRights();
  1026.         if(!$user->getIsAdmin()) {
  1027.             if (!$userObjects $em->getRepository(User::class)->getUserObjectsByTeamId($user$teamId)) {
  1028.                 $this->session->getFlashBag()->add('notice''ERROR: you are not allowed to access this team');
  1029.                 return $this->redirect($this->generateUrl('x_home'));
  1030.             }
  1031.             /** @var Team $team */
  1032.             $team $em->getRepository(Team::class)->findOneBy(['id' => $teamId]);
  1033.             $teamRight $teamRights[$userObjects['accessRight']->getType()];
  1034.         } else {
  1035.             $teamRight 'SP-Admin';
  1036.         }
  1037.         if($request->get('memberId') && $user->getIsAdmin()) {
  1038.             $memberId $request->get('memberId');
  1039.         } else {
  1040.             $memberId $user->getMemberId();
  1041.         }
  1042.         /** @var Member $member */
  1043.         $member $em->getRepository(Member::class)->findOneBy(['id' => $user->getMemberId()]);
  1044.         $memberTeam $em->getRepository(MemberTeam::class)->findOneBy(['member' => $member'team' => $team]);
  1045.         $teamRight $memberTeam $teamRights[$memberTeam->getType()] : false;
  1046.         if ($errorMessage $em->getRepository(Member::class)->hasValidMembership($member)) {
  1047.             $this->session->getFlashBag()->add('notice''ERROR ' $errorMessage);
  1048.             return $this->redirect($this->generateUrl($redirect->path, (array)$redirect->parameters));
  1049.         }
  1050.         if (!$em->getRepository(MemberTeam::class)->checkAccessRight($member$team) and !$user->getIsAdmin()) {
  1051.             $this->session->getFlashBag()->add('notice''ERROR There is a problem with your account, please contact support@startplatz.de');
  1052.             return $this->redirect($this->generateUrl($redirect->path, (array)$redirect->parameters));
  1053.         }
  1054.         $fields Utility::getEntityFieldsArray($startup);
  1055.         $storedData Utility::fillDataByObject($startup$fields);
  1056.         $uploadTagLogo "team-logo-{$teamId}";
  1057.         $uploadTagBanner "startup-banner-{$teamId}";
  1058.         $industries $em->getRepository(Startup::class)->getListOfIndustries();
  1059.         $form $this->createForm(StartupType::class, $startup, ['industries' => $industries'editForm' => 'spConnect']);
  1060.         $form->handleRequest($request);
  1061.         if ($form->isSubmitted() && $form->isValid()) {
  1062.             $data $form->getData();
  1063.             $updatedData Utility::fillDataByObject($startup$fields);
  1064.             $differences array_diff_assoc($updatedData$storedData);
  1065.             if ($differences) {
  1066.                 if (array_key_exists("imageLink"$differences) && $imageLink $differences['imageLink']) {
  1067.                     $this->removeOldResourcesFromCloudinary($uploadTagBanner$imageLink);
  1068.                 }
  1069.                 if (array_key_exists("logoUrl"$differences) && $imageLink $differences['logoUrl']) {
  1070.                     $this->removeOldResourcesFromCloudinary($uploadTagLogo$imageLink);
  1071.                 }
  1072.                 $startupScoreBefore $startup->getScore();
  1073.                 $startup $em->getRepository(Startup::class)->updateByEdit($startup$differences$user->getEmail());
  1074.                 if ($team) {
  1075.                     $team $em->getRepository(Team::class)->syncDataWithStartup($team$startup);
  1076.                 }
  1077.                 if ($startup->getVisibility() != "public" && $startup->getVisibility() != "sp-connect" && $startupScoreBefore 250 && $startup->getScore() >= 250) {
  1078.                     $memberName $member->getName();
  1079.                     $profileUrl $request->getSchemeAndHttpHost() . $this->generateUrl("allmeda_startup_edit", ["id" => $startup->getId()]);
  1080.                     $mail = new Email();
  1081.                     $mail->subject("Startup profile filled in: {$startup->getName()}");
  1082.                     $mail->from(new Address("support@startplatz.de""Startup profile complete"));
  1083.                     $mail->to(new Address("community-membership@startplatz.de""Membership Profile"));
  1084.                     $mail->text("
  1085.                         Das Profil von Startup {$startup->getName()} (Id: {$startup->getId()}) wurde ausgefüllt und könnte nun veröffentlicht werden.
  1086.                         
  1087.                         The profile of startup {$startup->getName()} (Id: {$startup->getId()}) was filled in and could be set to public now.
  1088.                         
  1089.                         Link: {$profileUrl}
  1090.                         ");
  1091.                     try {
  1092.                         $this->mailer->send($mail);
  1093.                     } catch (TransportExceptionInterface) {
  1094.                         return new Response("ERROR Email couldn't be sent"503);
  1095.                     }
  1096.                 }
  1097.                 // give bonus when edited
  1098.                 $em->getRepository(StartupRelevance::class)->updateRelevanceScoreByStartup($startup->getId(), $storedData['score'], $startup->getScore());
  1099.                 //sync actors
  1100.                 return $this->redirect($this->generateUrl('x_connect_team_show', ['id' => $teamId'toast' => base64_encode("Data have been saved."), 'toastType' => base64_encode('SUCCESS')]));
  1101.             } else {
  1102.                 return $this->redirect($this->generateUrl('x_connect_team_show', ['id' => $teamId'toast' => base64_encode("No data have been saved")]));
  1103.             }
  1104.         }
  1105.         $teamIndustries = (string) $team->getIndustries(); // Cast to string to ensure $teamIndustries is not null
  1106.         $teamIndustryList explode("#", (string) $teamIndustries);
  1107.         // create slugs from team on the fly and from startup, what is stored there
  1108.         $slugs[] = Utility::generateSlug($team->getShortName());
  1109.         if ($startup->getSlug()) {
  1110.             $slugs[] = $startup->getSlug();
  1111.         }
  1112.         $feedTags json_encode(array_values(array_unique($slugs)));
  1113.         return $this->render('@StartPlatzAlphaBundle/Startup/edit.startup-profile.html.twig', [
  1114.             'templateVars' => [],
  1115.             'form' => $form->createView(),
  1116.             'startup' => $startup,
  1117.             'team' => $team,
  1118.             'feedTags' => $feedTags,
  1119.             'teamIndustryList' => $teamIndustryList,
  1120.             'actor' => $em->getRepository(Actor::class)->findOneBy(['externalId' => $startup->getId()]),
  1121.             'members' => $members $em->getRepository(MemberTeam::class)->findByTeam($team),
  1122.             'teamRights' => $teamRights,
  1123.             'teamRight' => $teamRight,
  1124.             'methodsTeam' => $this->feedbackService->getEntityMethodsArray($team, ['services''members']),
  1125.             'methodsStartup' => $startup $this->feedbackService->getEntityMethodsArray($startup, []) : [],
  1126.             'redirectUrl' => $redirectUrl,
  1127.             'menuLinksAndPhrases' => $this->menuTranslationService->getMenuLinksAndPhrases($request->server->get('REQUEST_URI')),
  1128.             'member' => $member,
  1129.             'uploadTagBanner' => $uploadTagBanner,
  1130.             'uploadTagLogo' => $uploadTagLogo,
  1131.             'ownMemberId' => $member->getId(),
  1132.         ]);
  1133.     }
  1134.     private function removeOldResourcesFromCloudinary($uploadTag$link): void
  1135.     {
  1136.         $result $this->cloudinary->resources_by_tag($uploadTag);
  1137.         $filter = fn ($res) => $res['secure_url'] != $link;
  1138.         $oldRefs array_filter($result['resources'], $filter);
  1139.         $oldIds array_map(fn ($res) => $res['public_id'], $oldRefs);
  1140.         if (!empty($oldIds)) {
  1141.             $result $this->cloudinary->delete_resources($oldIds);
  1142.         }
  1143.     }
  1144.     /**
  1145.      * @Route("/startup-database/edit/{id}/{slug}", name="extern_startups_edit")
  1146.      * @Security("is_granted('ROLE_USER')")
  1147.      */
  1148.     public function editAction(Request $request$id$slug)
  1149.     {
  1150.         $em $this->getDoctrine()->getManager();
  1151.         $redirect json_decode(base64_decode((string) $request->get('redirect')));
  1152.         $redirectUrl $request->get('redirect');
  1153.         /** @var Startup $startup */
  1154.         if (!$startup $em->getRepository(Startup::class)->findOneBy(['id' => $id])) {
  1155.             $this->session->getFlashBag()->add('notice''ERROR 40 entity not found');
  1156.             return $this->redirect($this->generateUrl($redirect->path, (array)$redirect->parameters));
  1157.         }
  1158.         if ($slug != $startup->getSlug()) {
  1159.             return $this->redirect($this->generateUrl('extern_startups_single', ['id' => $id'slug' => $startup->getSlug(), 'redirect' => $redirectUrl]));
  1160.         }
  1161.         $rightToAccessTeam false;
  1162.         $team false;
  1163.         $memberId 0;
  1164.         $teamId $startup->getTeamId();
  1165.         /** @var User $user */
  1166.         if ($user $this->getUser()) {
  1167.             $em->getRepository(User::class)->writeActivity($user);
  1168.             $memberId $user->getMemberId();
  1169.             if (!$member $em->getRepository(Member::class)->findOneBy(['id' => $memberId])) {
  1170.                 $this->session->getFlashBag()->add('notice''ERROR There is a problem with your account please contact support@startplatz.de');
  1171.                 return $this->redirect($this->generateUrl($redirect->path, (array)$redirect->parameters));
  1172.             }
  1173.             /** @var Team $team */
  1174.             if ($team $em->getRepository(Team::class)->findOneBy(['id' => $teamId])) {
  1175.                 $rightToAccessTeam $em->getRepository(MemberTeam::class)->checkAccessRight($member$team);
  1176.             }
  1177.         }
  1178.         $admin $user->getIsAdmin();
  1179.         if (!$rightToAccessTeam and !$admin) {
  1180.             $this->session->getFlashBag()->add('notice''ERROR There is a problem with your account-3 please contact support@startplatz.de');
  1181.             return $this->redirect($this->generateUrl($redirect->path, (array)$redirect->parameters));
  1182.         }
  1183.         // the use of memberId is on purpose
  1184.         $startupAttributes $em->getRepository(StartupAttribute::class)->findOneBy(['startupId' => $startup->getId(), 'teamId' => $memberId]);
  1185.         $em->getRepository(StartupRelevance::class)->updateByUserAction($id'edit');
  1186.         $rheinlandPitches $em->getRepository(Application::class)->findBy(['startupId' => $id], ['batchId' => 'DESC']);
  1187.         $fields Utility::getEntityFieldsArray($startup);
  1188.         $storedData Utility::fillDataByObject($startup$fields);
  1189.         $industries $em->getRepository(Startup::class)->getListOfIndustries();
  1190.         $form $this->createForm(StartupType::class, $startup, ['industries' => $industries'editForm' => 'extern']);
  1191.         $form->handleRequest($request);
  1192.         if ($form->isSubmitted() && $form->isValid()) {
  1193.             $data $form->getData();
  1194.             $updatedData Utility::fillDataByObject($startup$fields);
  1195.             $differences array_diff_assoc($updatedData$storedData);
  1196.             if ($differences) {
  1197.                 $startup $em->getRepository(Startup::class)->updateByEdit($startup$differences$user->getEmail());
  1198.                 if ($team) {
  1199.                     $team $em->getRepository(Team::class)->syncDataWithStartup($team$startup);
  1200.                 }
  1201.             }
  1202.         }
  1203.         return $this->render('@StartPlatzAlphaBundle/Startup/edit.html.twig', [
  1204.             'templateVars' => [],
  1205.             'form' => $form->createView(),
  1206.             'startup' => $startup,
  1207.             'rightToAccessTeam' => $rightToAccessTeam,
  1208.             'startupAttributes' => $startupAttributes,
  1209.             'rheinlandPitches' => $rheinlandPitches,
  1210.             'backUrl' => $redirectUrl,
  1211.             'menuLinksAndPhrases' => $this->menuTranslationService->getMenuLinksAndPhrases($request->server->get('REQUEST_URI')),
  1212.             'redirectUrl' => base64_encode(json_encode(['path' => 'extern_startups_single''parameters' => ['id' => $id'slug' => $startup->getSlug()]])),
  1213.         ]);
  1214.     }
  1215.     /**
  1216.      * @Route("/startup-database/event/{id}/{slug}/{eventId}", name="extern_startups_event")
  1217.      * @Security("is_granted('ROLE_USER')")
  1218.      */
  1219.     public function startupLivecycleEventAction(Request $request$id$slug$eventId)
  1220.     {
  1221.         $em $this->getDoctrine()->getManager();
  1222.         $now = new DateTime();
  1223.         $redirect json_decode(base64_decode((string) $request->get('redirect')));
  1224.         $redirectUrl $request->get('redirect');
  1225.         if (!$startup $em->getRepository(Startup::class)->findOneBy(['id' => $id])) {
  1226.             $this->session->getFlashBag()->add('notice''ERROR 50 entity not found');
  1227.             return $this->redirect($this->generateUrl($redirect->path, (array)$redirect->parameters));
  1228.         }
  1229.         if ($slug != $startup->getSlug()) {
  1230.             return $this->redirect($this->generateUrl('extern_startups_single', ['id' => $id'slug' => $startup->getSlug(), 'redirect' => $redirectUrl]));
  1231.         }
  1232.         $rightToAccessTeam false;
  1233.         $team false;
  1234.         $memberId 0;
  1235.         $teamId $startup->getTeamId();
  1236.         /** @var User $user */
  1237.         if ($user $this->getUser()) {
  1238.             $em->getRepository(User::class)->writeActivity($user);
  1239.             $memberId $user->getMemberId();
  1240.             if (!$member $em->getRepository(Member::class)->findOneBy(['id' => $memberId])) {
  1241.                 $this->session->getFlashBag()->add('notice''ERRORThere is a problem with your account please contact support@startplatz.de');
  1242.                 return $this->redirect($this->generateUrl($redirect->path, (array)$redirect->parameters));
  1243.             }
  1244.             if ($team $em->getRepository(Team::class)->findOneBy(['id' => $teamId])) {
  1245.                 $rightToAccessTeam $em->getRepository(MemberTeam::class)->checkAccessRight($member$team);
  1246.             }
  1247.         }
  1248.         $admin $user->getIsAdmin();
  1249.         if (!$rightToAccessTeam and !$admin) {
  1250.             $this->session->getFlashBag()->add('notice''ERROR There is a problem with your account-4 please contact support@startplatz.de');
  1251.             return $this->redirect($this->generateUrl($redirect->path, (array)$redirect->parameters));
  1252.         }
  1253.         // the use of memberId is on purpose
  1254.         $startupAttributes $em->getRepository(StartupAttribute::class)->findOneBy(['startupId' => $startup->getId(), 'teamId' => $memberId]);
  1255.         $em->getRepository(StartupRelevance::class)->updateByUserAction($id'edit');
  1256.         $rheinlandPitches $em->getRepository(Application::class)->findBy(['startupId' => $id], ['batchId' => 'DESC']);
  1257.         $startupLivecycleEvents $em->getRepository(StartupLifecycleEvent::class)->findBy(['startupId' => $startup->getId()], ['eventDate' => 'ASC']);
  1258.         if (!$livecycleEvent $em->getRepository(StartupLifecycleEvent::class)->findOneBy(['id' => $eventId])) {
  1259.             $livecycleEvent = new StartupLifecycleEvent();
  1260.             $livecycleEvent->setEventDate($now);
  1261.             $livecycleEvent->setStartupId($id);
  1262.         }
  1263.         // set array oldData value, nr, text
  1264.         $fields = ['eventWhat''eventDate''linkText''link'];
  1265.         $oldData $this->getDataAsArray($fields$livecycleEvent);
  1266.         $form $this->createForm(LivecycleEventType::class, $livecycleEvent);
  1267.         $form->handleRequest($request);
  1268.         if ($form->isSubmitted() && $form->isValid()) {
  1269.             $newData $this->getDataAsArray($fields$livecycleEvent);
  1270.             $differences array_diff_assoc($newData$oldData);
  1271.             if ($differences) {
  1272.                 $livecycleEvent $em->getRepository(StartupLifecycleEvent::class)->updateByEdit($livecycleEvent$differences$user->getEmail());
  1273.                 $this->session->getFlashBag()->add('notice''SUCCESSData has been saved');
  1274.             }
  1275.             return $this->redirect($this->generateUrl($redirect->path, (array)$redirect->parameters));
  1276.         }
  1277.         return $this->render('@StartPlatzAlphaBundle/Startup/editLivecycleEvent.html.twig', [
  1278.             'templateVars' => [],
  1279.             'form' => $form->createView(),
  1280.             'startup' => $startup,
  1281.             'rightToAccessTeam' => $rightToAccessTeam,
  1282.             'startupAttributes' => $startupAttributes,
  1283.             'rheinlandPitches' => $rheinlandPitches,
  1284.             'livecycleEvent' => $livecycleEvent,
  1285.             'startupLivecycleEvents' => $startupLivecycleEvents,
  1286.             'backUrl' => $redirectUrl,
  1287.             'menuLinksAndPhrases' => $this->menuTranslationService->getMenuLinksAndPhrases($request->server->get('REQUEST_URI')),
  1288.             'redirectUrl' => base64_encode(json_encode(['path' => 'extern_startups_single''parameters' => ['id' => $id'slug' => $startup->getSlug()]])),
  1289.         ]);
  1290.     }
  1291.     /**
  1292.      * @Route("/startup-database/show-event/{id}/{slug}/{eventId}", name="extern_startups_show-event")
  1293.      * @Security("is_granted('ROLE_USER')")
  1294.      */
  1295.     public function showStartupLivecycleEventAction(Request $request$id$slug$eventId)
  1296.     {
  1297.         $em $this->getDoctrine()->getManager();
  1298.         $now = new DateTime();
  1299.         $redirect json_decode(base64_decode((string) $request->get('redirect')));
  1300.         $redirectUrl $request->get('redirect');
  1301.         if (!$startup $em->getRepository(Startup::class)->findOneBy(['id' => $id])) {
  1302.             $this->session->getFlashBag()->add('notice''ERROR 60 entity not found');
  1303.             return $this->redirect($this->generateUrl($redirect->path, (array)$redirect->parameters));
  1304.         }
  1305.         if ($slug != $startup->getSlug()) {
  1306.             return $this->redirect($this->generateUrl('extern_startups_single', ['id' => $id'slug' => $startup->getSlug(), 'redirect' => $redirectUrl]));
  1307.         }
  1308.         /** @var User $user */
  1309.         if (!$user $this->getUser()) {
  1310.             $this->session->getFlashBag()->add('notice''SUCCESSplease register or login');
  1311.             return $this->redirect($this->generateUrl($redirect->path, (array)$redirect->parameters));
  1312.         }
  1313.         $em->getRepository(User::class)->writeActivity($user);
  1314.         $em->getRepository(StartupRelevance::class)->updateByUserAction($id'edit');
  1315.         if (!$startupLivecycleEvent $em->getRepository(StartupLifecycleEvent::class)->findOneBy(['id' => $eventId])) {
  1316.             $this->session->getFlashBag()->add('notice''ERRORError - no event found');
  1317.             return $this->redirect($this->generateUrl($redirect->path, (array)$redirect->parameters));
  1318.         }
  1319.         return $this->render('@StartPlatzAlphaBundle/Startup/showLivecycleEvent.html.twig', [
  1320.             'templateVars' => [],
  1321.             'startup' => $startup,
  1322.             'startupLivecycleEvent' => $startupLivecycleEvent,
  1323.             'backUrl' => $redirectUrl,
  1324.             'menuLinksAndPhrases' => $this->menuTranslationService->getMenuLinksAndPhrases($request->server->get('REQUEST_URI')),
  1325.             'redirectUrl' => base64_encode(json_encode(['path' => 'extern_startups_single''parameters' => ['id' => $id'slug' => $startup->getSlug()]])),
  1326.         ]);
  1327.     }
  1328.     private function getDataAsArray($fields$entity)
  1329.     {
  1330.         foreach ($fields as $field) {
  1331.             $method 'get' ucfirst((string) $field);
  1332.             if (method_exists($entity$method)) {
  1333.                 if ($entity->$method() instanceof DateTime) {
  1334.                     $data[$field] = $entity->$method()->format('Y-m-d');
  1335.                 } else {
  1336.                     $data[$field] = $entity->$method();
  1337.                 }
  1338.             } else {
  1339.                 $data[$field] = "";
  1340.             }
  1341.         }
  1342.         return $data;
  1343.     }
  1344.     /**
  1345.      * @Route("/startup-database/get-in-contact/{id}", name="extern_startups_get-in-contact")
  1346.      */
  1347.     public function getInContactAjaxAction(Request $request$id)
  1348.     {
  1349.         $em $this->getDoctrine()->getManager();
  1350.         $redirect json_decode(base64_decode((string) $request->get('redirect')));
  1351.         return $this->render('@StartPlatzAlphaBundle/Startup/modal.register.html.twig', [
  1352.             'title' => "Get in contact",
  1353.             'btnClass' => "btn-outline-info",
  1354.             'id' => $id,
  1355.             'redirect' => $redirect,
  1356.             'redirectUrl' => $request->get('redirect'),
  1357.         ]);
  1358.     }
  1359.     /**
  1360.      * @Route("/startup-database/register/{id}", name="extern_startups_register")
  1361.      */
  1362.     public function registerAjaxAction(Request $request$id)
  1363.     {
  1364.         $em $this->getDoctrine()->getManager();
  1365.         $redirect json_decode(base64_decode((string) $request->get('redirect')));
  1366.         return $this->render('@StartPlatzAlphaBundle/Startup/modal.register.html.twig', [
  1367.             'title' => "Please register",
  1368.             'btnClass' => "btn-outline-info",
  1369.             'id' => $id,
  1370.             'redirect' => $redirect,
  1371.             'redirectUrl' => $request->get('redirect'),
  1372.         ]);
  1373.     }
  1374.     /**
  1375.      * @Route("/x/community/startups/missions/", name="x_startups_missions")
  1376.      * @Security("is_granted('ROLE_USER')")
  1377.      */
  1378.     public function indexMissionsForBadge(Request $request)
  1379.     {
  1380.         $em $this->getDoctrine()->getManager();
  1381.         $redirect json_decode(base64_decode((string) $request->get('redirect')));
  1382.         $redirectUrl $request->get('redirect');
  1383.         $templateVars $em->getRepository(Startup::class)->getTemplateVars($request);
  1384.         /** @var User $user */
  1385.         $user $this->getUser();
  1386.         $em->getRepository(User::class)->writeActivity($user'/x/community/startups/');
  1387.         $id $user->getTeamId();
  1388.         /** @var Team $team */
  1389.         $team $em->getRepository(Team::class)->find($id);
  1390.         if (!$startup $em->getRepository(Startup::class)->findOneBy(['id' => $team->getStartupId()])) {
  1391.             $startup = new Startup();
  1392.         } else {
  1393.             // increase relevance score every time a startup team is shown
  1394.             $em->getRepository(StartupRelevance::class)->updateByUserAction($startup->getId(), 'click');
  1395.         }
  1396.         $lang $request->get('lang');
  1397.         $view '@StartPlatzAlphaBundle/Startup/index.missionsForBadge.html.twig';
  1398.         return $this->render($view, [
  1399.             'team' => $team,
  1400.             'startup' => $startup,
  1401.             'templateVars' => $templateVars,
  1402.             'backUrl' => $redirectUrl,
  1403.             'menuLinksAndPhrases' => $this->menuTranslationService->getMenuLinksAndPhrases($request->server->get('REQUEST_URI')),
  1404.             'redirectUrl' => base64_encode(json_encode(['path' => 'website_startups_list''parameters' => $templateVars])),
  1405.         ]);
  1406.     }
  1407.     private function setEditorForm($content)
  1408.     {
  1409.         return $this->formFactory->createNamedBuilder('editor')
  1410.             ->add(
  1411.                 'content',
  1412.                 TinymceType::class,
  1413.                 [
  1414.                     'label' => 'Content',
  1415.                     'data' => $content,
  1416.                     'required' => false,
  1417.                 ]
  1418.             )
  1419.             ->add('save'SubmitType::class, ['label' => 'Save'])
  1420.             ->getForm();
  1421.     }
  1422.     private function setPlainEditorForm($content)
  1423.     {
  1424.         return $this->formFactory->createNamedBuilder('editor')
  1425.             ->add(
  1426.                 'content',
  1427.                 TextareaType::class,
  1428.                 [
  1429.                     'label' => 'Content',
  1430.                     'data' => $content,
  1431.                     'attr' => ['rows' => '17''cols' => '180'],
  1432.                     'required' => false,
  1433.                 ]
  1434.             )
  1435.             ->add('save'SubmitType::class, ['label' => 'Save'])
  1436.             ->getForm();
  1437.     }
  1438.     private function getSection($metaName)
  1439.     {
  1440.         $em $this->getDoctrine()->getManager();
  1441.         if (!$section $em->getRepository(Option::class)->getOptionMetaValue($metaName)) {
  1442.             $section['fields'] = $this->setSectionFields();
  1443.             $section['content'][] = [
  1444.                 "https://www.startplatz.de/wp-content/uploads/2012/11/golfpost_225x225.jpg",
  1445.                 "http://www.golfpost.de",
  1446.                 "Golf Post",
  1447.                 "Das Online-Magazin Golf Post ist Vorreiter und inzwischen zur größten unabhängigen Golf-Plattform im deutschsprachigen Raum gereift. Ziel ist es, das elitäre Image des Golfsports zu entstauben.",
  1448.                 "#golfistbesseralsdudenkst #wirsindanders #unsereweltistgrün",
  1449.                 "99999",
  1450.             ];
  1451.             $em->getRepository(Option::class)->setOptionMetaValueJsonEncoded($metaNamenull$section);
  1452.         }
  1453.         $section['entities'] = $this->setSectionEntities($section);
  1454.         return $section;
  1455.     }
  1456.     private function setSectionEntities($section)
  1457.     {
  1458.         $entities = [];
  1459.         foreach ($section['content'] as $row) {
  1460.             if ((is_countable($section['fields']) ? count($section['fields']) : 0) != (is_countable($row) ? count($row) : 0)) {
  1461.                 $i 0;
  1462.                 foreach ($section['fields'] as $field) {
  1463.                     $entity[$field] = $row[$i] ?? $field;
  1464.                     $i++;
  1465.                 }
  1466.                 $entities[] = $entity;
  1467.             } else {
  1468.                 $entities[] = array_combine($section['fields'], $row);
  1469.             }
  1470.         }
  1471.         return $entities;
  1472.     }
  1473.     private function transformArrayIntoCsvString($rows)
  1474.     {
  1475.         $content '';
  1476.         foreach ($rows as $row) {
  1477.             $content .= implode("\t"$row) . PHP_EOL;
  1478.         }
  1479.         return $content;
  1480.     }
  1481.     private function setSectionFields()
  1482.     {
  1483.         $fields = ['logo''url''name''desc''tags''teamId'];
  1484.         return $fields;
  1485.     }
  1486. }