<?php declare(strict_types=1);
namespace App\StartPlatz\Bundle\AlphaBundle\Controller;
use App\StartPlatz\Bundle\AlphaBundle\Entity\Actor;
use App\StartPlatz\Bundle\AlphaBundle\Entity\Feed;
use App\StartPlatz\Bundle\AlphaBundle\Entity\Page;
use App\StartPlatz\Bundle\MemberBundle\Entity\Member;
use App\StartPlatz\Bundle\MemberBundle\Entity\MemberTeam;
use App\StartPlatz\Bundle\MemberBundle\Entity\Option;
use App\StartPlatz\Bundle\MemberBundle\Entity\Team;
use App\StartPlatz\Bundle\StartupBundle\Entity\Application;
use App\StartPlatz\Bundle\StartupBundle\Entity\Batch;
use App\StartPlatz\Bundle\StartupBundle\Entity\Startup;
use App\StartPlatz\Bundle\StartupBundle\Entity\StartupAttribute;
use App\StartPlatz\Bundle\StartupBundle\Entity\StartupLifecycleEvent;
use App\StartPlatz\Bundle\StartupBundle\Entity\StartupRelevance;
use App\StartPlatz\Bundle\StartupBundle\Form\LivecycleEventType;
use App\StartPlatz\Bundle\WebsiteBundle\Utility\Utility;
use DateTime;
use Eckinox\TinymceBundle\Form\Type\TinymceType;
use Speicher210\CloudinaryBundle\Cloudinary\Api;
use Symfony\Component\HttpFoundation\Response;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
use stdClass;
use Symfony\Component\Mailer\Exception\TransportExceptionInterface;
use Symfony\Component\Mime\Address;
use Symfony\Component\Mime\Email;
use Symfony\Component\Routing\Annotation\Route;
use App\StartPlatz\Bundle\FeedbackBundle\FeedbackService;
use App\StartPlatz\Bundle\StartupBundle\Form\StartupType;
use App\StartPlatz\Bundle\UserBundle\Entity\User;
use App\StartPlatz\Bundle\WebsiteBundle\MenuTranslationService;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use Symfony\Component\Form\FormFactoryInterface;
use Symfony\Component\Mailer\MailerInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
class StartupController extends AbstractController
{
public function __construct(
private readonly SessionInterface $session,
private readonly FormFactoryInterface $formFactory,
private readonly FeedbackService $feedbackService,
private readonly MenuTranslationService $menuTranslationService,
private readonly Api $cloudinary,
private readonly MailerInterface $mailer
) {
}
/**
* @Route("/accelerator/startups", name="accelerator_startups")
*/
public function AcceleratorStartupsIndexAction(Request $request)
{
$em = $this->getDoctrine()->getManager();
$startups = $em->getRepository(Startup::class)->findAcceleratorAlumnis();
$teamIds = array_map(fn ($entity) => $entity->getTeamId(), $startups);
$teams = $em->getRepository(Team::class)->findBy(['id'=>$teamIds]);
$teamIds = array_map(fn ($entity) => $entity->getId(), $teams);
$teams = array_combine($teamIds, $teams);
return $this->render('@StartPlatzAlphaBundle/Startup/index.startups.alumni.html.twig', [
'startups' => $startups,
'teams' => $teams,
]);
}
/**
* @Route("/x/connect/startups/home", name="x_connect_startups_home")
* @Security("is_granted('ROLE_USER')")
*/
public function indexStartupsSpconnectAction(Request $request)
{
$em = $this->getDoctrine()->getManager();
$templateVars = $em->getRepository(Startup::class)->getTemplateVars($request);
$route = $request->get('_route');
$responseContent = [];
/** @var User $user */
$user = $this->getUser();
$em->getRepository(User::class)->writeActivity($user);
$teamId = $user->getMemberId();
$userMember = $em->getRepository(Member::class)->find($user->getMemberId());
if (!$ajax = $request->get('ajax')) {
// do whatever has to be done with first access
}
$orderBy = $templateVars['dimensions'] ?: ['score' => 'DESC'];
$visibility = 'sp-connect';
$criteria = ['visibility' => $visibility, 'status' => 'active', 'team' => 'exists'] + $templateVars['criteria'];
//remove location from criteria for location-button hrefs so not both CGN or DUS can be selected at the same time
$templateVarsLocation = $templateVars;
if(array_key_exists('criteria', $templateVarsLocation) && array_key_exists('location', $templateVarsLocation['criteria'])) {
unset($templateVarsLocation['criteria']['location']);
}
$total = $em->getRepository(Startup::class)->countByCriteria($criteria, $teamId);
if ($total > 72) {
$limit = 72;
} else {
$limit = $total ?: 1;
}
if (!$page = $request->get('page')) {
$page = 1;
}
$startups = $em->getRepository(Startup::class)->findPaginated($criteria, $teamId, $orderBy, $page, $limit);
$maxPages = $total;
$id = $user->getTeamId();
$acceleratorCurrentBatchNumber = $em->getRepository(Option::class)->getAcceleratorCurrentBatchNumber();
$startupsCurrentBatch = $em->getRepository(Startup::class)->findPaginated($criteria + ['batch' => $acceleratorCurrentBatchNumber], $teamId, $orderBy, 1, 128);
$startupsLastBatch = $em->getRepository(Startup::class)->findPaginated($criteria + ['batch' => $acceleratorCurrentBatchNumber -1 ], $teamId, $orderBy, 1, 128);
$startupsBatch20 = $em->getRepository(Startup::class)->findPaginated($criteria + ['batch' => $acceleratorCurrentBatchNumber -2], $teamId, $orderBy, 1, 128);
$startupsSpCgn = $em->getRepository(Startup::class)->findPaginated($criteria + ['startplatz' => 'sp-cgn'], $teamId, $orderBy, 1, 128);
$startupsSpDus = $em->getRepository(Startup::class)->findPaginated($criteria + ['startplatz' => 'sp-dus'], $teamId, $orderBy, 1, 128);
$startupsAlumni = $em->getRepository(Startup::class)->findPaginated($criteria + ['startplatz' => 'alumni'], $teamId, $orderBy, 1, 128);
$startupsExtern = $em->getRepository(Startup::class)->findPaginated($criteria + ['startplatz' => 'extern'], $teamId, $orderBy, $page, $limit);
$startupsRheinlandPitch = [];
$startupsRheinlandPitch = $em->getRepository(Startup::class)->findPaginated($criteria + ['pitchNumber' => 'rheinland-pitch-web3-edition-112'], $teamId, $orderBy, 1, 128);
$startupsGruenderstipendium = [];
$startupsGruenderstipendium = $em->getRepository(Startup::class)->findPaginated($criteria + ['gsStatus' => ['funded','recommended']], $teamId, $orderBy, 1, 128);
$startupsGruenderstipendiumAlumni = [];
$startupsGruenderstipendiumAlumni = $em->getRepository(Startup::class)->findPaginated($criteria + ['gsStatus' => ['alumni']], $teamId, $orderBy, 1, 128);
// get teamIds
$teamIds = array_map(fn ($entity) => $entity['teamId'], $startups);
$teamIds = $teamIds + array_map(fn ($entity) => $entity['teamId'], $startupsCurrentBatch);
$teamIds = $teamIds + array_map(fn ($entity) => $entity['teamId'], $startupsLastBatch);
$teamIds = $teamIds + array_map(fn ($entity) => $entity['teamId'], $startupsBatch20);
$teamIds = $teamIds + array_map(fn ($entity) => $entity['teamId'], $startupsSpCgn);
$teamIds = $teamIds + array_map(fn ($entity) => $entity['teamId'], $startupsSpDus);
$teamIds = $teamIds + array_map(fn ($entity) => $entity['teamId'], $startupsAlumni);
$teamIds = $teamIds + array_map(fn ($entity) => $entity['teamId'], $startupsExtern);
$teamIds = $teamIds + array_map(fn ($entity) => $entity['teamId'], $startupsRheinlandPitch);
$teamIds = $teamIds + array_map(fn ($entity) => $entity['teamId'], $startupsGruenderstipendium);
$teamIds = $teamIds + array_map(fn ($entity) => $entity['teamId'], $startupsGruenderstipendiumAlumni);
$teams = $em->getRepository(Team::class)->findBy(['id'=>$teamIds]);
$teamIds = array_map(fn ($entity) => $entity->getId(), $teams);
$teams = array_combine($teamIds, $teams);
/** @var Team $team */
$team = $em->getRepository(Team::class)->find($id);
$view = '@StartPlatzAlphaBundle/Startup/index.startups.sp-connect.html.twig';
$viewFeed = '@StartPlatzAlphaBundle/Startup/_feed.startups.sp-connect.html.twig';
if ($ajax) {
return $this->render($viewFeed, [
'startups' => $startups,
'userMember' => $userMember,
'startupsCurrentBatch' => $startupsCurrentBatch,
'startupsLastBatch' => $startupsLastBatch,
'startupsBatch20' => $startupsBatch20,
'startupsSpCgn' => $startupsSpCgn,
'startupsSpDus' => $startupsSpDus,
'startupsAlumni' => $startupsAlumni,
'startupsExtern' => $startupsExtern,
'startupsRheinlandPitch' => $startupsRheinlandPitch,
'startupsGruenderstipendium' => $startupsGruenderstipendium,
'startupsGruenderstipendiumAlumni' => $startupsGruenderstipendiumAlumni,
'team' => $team,
'teams' => $teams,
'maxPages' => $maxPages,
'thisPage' => $page,
'ajax' => $ajax,
'redirectUrl' => base64_encode(json_encode(['path' => $route, 'parameters' => $templateVars])),
'templateVars' => $templateVars,
'templateVarsLocation' => $templateVarsLocation,
]);
} else {
return $this->render($view, [
'startups' => $startups,
'userMember' => $userMember,
'title' => "Startups",
'startupsCurrentBatch' => $startupsCurrentBatch,
'startupsLastBatch' => $startupsLastBatch,
'startupsBatch20' => $startupsBatch20,
'startupsSpCgn' => $startupsSpCgn,
'startupsSpDus' => $startupsSpDus,
'startupsAlumni' => $startupsAlumni,
'startupsExtern' => $startupsExtern,
'startupsRheinlandPitch' => $startupsRheinlandPitch,
'startupsGruenderstipendium' => $startupsGruenderstipendium,
'startupsGruenderstipendiumAlumni' => $startupsGruenderstipendiumAlumni,
'team' => $team,
'teams' => $teams,
'maxPages' => $maxPages,
'thisPage' => $page,
'ajax' => $ajax,
'redirectUrl' => base64_encode(json_encode(['path' => $route, 'parameters' => $templateVars])),
'templateVars' => $templateVars,
'templateVarsLocation' => $templateVarsLocation,
'menuLinksAndPhrases' => $this->menuTranslationService->getMenuLinksAndPhrases($request->server->get('REQUEST_URI')),
]);
}
}
/**
* @Route("/startups", name="homepage_startups_home")
* @Route("/en/startups", name="homepage_startups_home_english")
* @Route("/fr/startups", name="homepage_startups_home_french")
*/
public function indexStartupsHomepageAction(Request $request)
{
$em = $this->getDoctrine()->getManager();
$redirect = json_decode(base64_decode((string) $request->get('redirect')));
$redirectUrl = $request->get('redirect');
$templateVars = $em->getRepository(Startup::class)->getTemplateVars($request);
$orderBy = $templateVars['dimensions'] ?: ['score' => 'DESC'];
// Neue Zeile - Sortierung nach lastModified (neueste zuerst)
$orderBy = $templateVars['dimensions'] ?: ['lastModified' => 'DESC'];
$visibility = 'public';
$criteria = ['visibility' => $visibility] + $templateVars['criteria'];
$lang = Utility::getLangByPathInfo($request->getPathInfo());
$teamId = 0;
if ($user = $this->getUser()) {
$teamId = $user->getMemberId();
$em->getRepository(User::class)->writeActivity($user);
}
$total = $em->getRepository(Startup::class)->countByCriteria($criteria, $teamId);
if ($total > 2560) {
$limit = 2560;
} else {
$limit = $total ?: 1;
}
if (!$page = $request->get('page')) {
$page = 1;
}
$startups = $em->getRepository(Startup::class)->findPaginated($criteria, $teamId, $orderBy, $page, $limit);
$startupsExtern = $em->getRepository(Startup::class)->findPaginated($criteria + ['startplatz' => 'extern'], $teamId, $orderBy, $page, $limit);
$rheinlandPitchBatches = [];
$rheinlandPitchWinnerApplications = [];
$rheinlandPitchWinnerStartups = [];
if (array_key_exists("rheinlandPitchBestResult", $criteria)) {
/*
* now use a totally different logic
* first we find all rheinlandPitchBatches
* then we find all winnerApplications
* then we find all related startups
*/
$rheinlandPitchBatches = $em->getRepository(Batch::class)->findBy(['programId'=>1,'focusStatus'=>['4_past','3_previous','2_current']], ['pitchDate'=>'DESC']);
$rheinlandPitchWinnerApplications = $em->getRepository(Application::class)->findBy(['programId'=>1,'pitchPosition'=>1], ['batchId'=>'DESC']);
$rheinlandPitchWinnerStartupIds = array_map(fn (Application $entity) => $entity->getStartupId(), $rheinlandPitchWinnerApplications);
$rheinlandPitchWinnerStartups = $em->getRepository(Startup::class)->findBy(['id'=>$rheinlandPitchWinnerStartupIds]);
$rheinlandPitchWinnerStartupIds = array_map(fn (Startup $entity) => $entity->getId(), $rheinlandPitchWinnerStartups);
$rheinlandPitchWinnerStartups = array_combine($rheinlandPitchWinnerStartupIds, $rheinlandPitchWinnerStartups);
}
$parentPageSlug = "startups";
if (!$parentPage = $em->getRepository(Page::class)->findOneBy(['slug' => $parentPageSlug])) {
$parentPage = new Page();
$parentPage->setTitle('Die STARTPLATZ Startups');
$parentPage->setTeaser('Die erfolgreichen Startups starten hier durch');
$parentPage->setDescription('Page Description');
}
$acceleratorCurrentBatchNumber = $em->getRepository(Option::class)->getAcceleratorCurrentBatchNumber();
$startupsCurrentBatch = $em->getRepository(Startup::class)->findPaginated($criteria + ['batch' => $acceleratorCurrentBatchNumber], $teamId, $orderBy, 1, 128);
$startupsLastBatch = $em->getRepository(Startup::class)->findPaginated($criteria + ['batch' => $acceleratorCurrentBatchNumber -1 ], $teamId, $orderBy, 1, 128);
$startupsBatch20 = $em->getRepository(Startup::class)->findPaginated($criteria + ['batch' => $acceleratorCurrentBatchNumber -2], $teamId, $orderBy, 1, 128);
$startupsSpCgn = $em->getRepository(Startup::class)->findPaginated($criteria + ['startplatz' => 'sp-cgn'], $teamId, $orderBy, 1, 128);
$startupsSpDus = $em->getRepository(Startup::class)->findPaginated($criteria + ['startplatz' => 'sp-dus'], $teamId, $orderBy, 1, 128);
$startupsAlumni = $em->getRepository(Startup::class)->findPaginated($criteria + ['startplatz' => 'alumni'], $teamId, $orderBy, 1, 128);
$startupsRheinlandPitch = [];
$rheinlandPitchOrderBy = $templateVars['dimensions'] ? $templateVars['dimensions']+ ['rheinlandPitch' => 'ASC','rheinlandPitchBestResult' => 'DESC'] : ['rheinlandPitch' => 'ASC','rheinlandPitchBestResult' => 'DESC'];
$rheinlandPitchCurrentPitchNumber = $em->getRepository(Option::class)->getRheinlandPitchCurrentPitchNumber();
$startupsRheinlandPitch = $em->getRepository(Startup::class)->findPaginated($criteria + ['pitchNumber' => $rheinlandPitchCurrentPitchNumber], $teamId, $rheinlandPitchOrderBy, 1, 1280);
// startups of current rheinland pitch
// $startupsRheinlandPitch = $em->getRepository(Startup::class)->findCurrentRheinlandPitchStartups('2_current');
$startupsGruenderstipendium = [];
$startupsGruenderstipendium = $em->getRepository(Startup::class)->findPaginated($criteria + ['gsStatus' => ['funded','recommended']], $teamId, $orderBy, 1, 1280);
$startupsGruenderstipendiumAlumni = [];
$startupsGruenderstipendiumAlumni = $em->getRepository(Startup::class)->findPaginated($criteria + ['gsStatus' => ['alumni']], $teamId, $orderBy, 1, 1280);
$industries = $em->getRepository(Startup::class)->getAggregateByGroup('industry', $criteria);
// get teamIds
$teamIds = array_map(fn ($entity) => $entity['teamId'], $startups);
$teamIds = $teamIds + array_map(fn ($entity) => $entity['teamId'], $startupsCurrentBatch);
$teamIds = $teamIds + array_map(fn ($entity) => $entity['teamId'], $startupsLastBatch);
$teamIds = $teamIds + array_map(fn ($entity) => $entity['teamId'], $startupsBatch20);
$teamIds = $teamIds + array_map(fn ($entity) => $entity['teamId'], $startupsSpCgn);
$teamIds = $teamIds + array_map(fn ($entity) => $entity['teamId'], $startupsSpDus);
$teamIds = $teamIds + array_map(fn ($entity) => $entity['teamId'], $startupsAlumni);
$teamIds = $teamIds + array_map(fn ($entity) => $entity['teamId'], $startupsExtern);
$teamIds = $teamIds + array_map(fn ($entity) => $entity['teamId'], $startupsRheinlandPitch);
$teamIds = $teamIds + array_map(fn ($entity) => $entity['teamId'], $startupsGruenderstipendium);
$teamIds = $teamIds + array_map(fn ($entity) => $entity['teamId'], $startupsGruenderstipendiumAlumni);
$teams = $em->getRepository(Team::class)->findBy(['id'=>$teamIds]);
$teamIds = array_map(fn ($entity) => $entity->getId(), $teams);
$teams = array_combine($teamIds, $teams);
return $this->render('@StartPlatzAlphaBundle/Startup/index.startups.homepage.html.twig', [
'startups' => $startups,
'startupsCurrentBatch' => $startupsCurrentBatch,
'startupsLastBatch' => $startupsLastBatch,
'startupsBatch20' => $startupsBatch20,
'startupsSpCgn' => $startupsSpCgn,
'startupsSpDus' => $startupsSpDus,
'startupsAlumni' => $startupsAlumni,
'startupsExtern' => $startupsExtern,
'startupsRheinlandPitch' => $startupsRheinlandPitch,
'startupsGruenderstipendium' => $startupsGruenderstipendium,
'startupsGruenderstipendiumAlumni' => $startupsGruenderstipendiumAlumni,
'teams' => $teams,
'currentBatchNumber' => $acceleratorCurrentBatchNumber,
'industries' => $industries,
'parentPage' => $parentPage,
'pageType' => 'startup',
'topic' => 'deepTech',
'lang' => $lang,
'rheinlandPitchBatches' => $rheinlandPitchBatches,
'rheinlandPitchWinnerApplications' => $rheinlandPitchWinnerApplications,
'rheinlandPitchWinnerStartups' => $rheinlandPitchWinnerStartups,
'maxPages' => ceil($total / $limit),
'thisPage' => $page,
'total' => $total,
'limit' => $limit,
'criteria' => $criteria,
'visibility' => $visibility,
'templateVars' => $templateVars,
'backUrl' => $redirectUrl,
'menuLinksAndPhrases' => $this->menuTranslationService->getMenuLinksAndPhrases($request->server->get('REQUEST_URI')),
'redirectUrl' => base64_encode(json_encode(['path' => 'website_startups_list', 'parameters' => $templateVars])),
]);
}
/**
* @Route("/x/startups/industries/list", name="x_startups_industries_list")
*/
public function listIndustriesAjaxAction(Request $request)
{
$em = $this->getDoctrine()->getManager();
$redirect = json_decode(base64_decode((string) $request->get('redirect')));
$templateVars = $em->getRepository(Startup::class)->getTemplateVars($request);
$currentCriteria = $templateVars['criteria'];
if (isset($templateVars['criteria']['industry'])) {
unset($templateVars['criteria']['industry']);
}
if (isset($templateVars['criteria']['isBookmarked'])) {
unset($templateVars['criteria']['isBookmarked']);
}
if (!$source = $request->get('source')) {
$visibility = 'sp-connect';
$targetPath = "x_connect_startups_home";
} else {
$visibility = 'public';
$targetPath = "homepage_startups_home";
}
$criteria = ['visibility' => $visibility, 'status' => 'active', 'team' => 'exists'] + $templateVars['criteria'];
if ($user = $this->getUser()) {
$teamId = $user->getMemberId();
} else {
$teamId = 0;
}
$industries = $em->getRepository(Startup::class)->findIndustries($criteria, $teamId);
return $this->render('@StartPlatzAlpha/Default/list.startupIndustries.modal.html.twig', [
'title' => "Available Industries",
'industries' => $industries,
'targetPath' => $targetPath,
'currentCriteria' => $currentCriteria,
'templateVars' => $templateVars,
'redirectUrl' => $request->get('redirect'),
]);
}
/**
* @Route("/x/startups/tags/list", name="x_startups_tags_list")
*/
public function listTagsAjaxAction(Request $request)
{
$em = $this->getDoctrine()->getManager();
$redirect = json_decode(base64_decode((string) $request->get('redirect')));
$templateVars = $em->getRepository(Startup::class)->getTemplateVars($request);
$currentCriteria = $templateVars['criteria'];
if (isset($templateVars['criteria']['tags'])) {
unset($templateVars['criteria']['tags']);
}
if (isset($templateVars['criteria']['isBookmarked'])) {
unset($templateVars['criteria']['isBookmarked']);
}
if (!$source = $request->get('source')) {
$visibility = 'sp-connect';
$targetPath = "x_connect_startups_home";
} else {
$visibility = 'public';
$targetPath = "homepage_startups_home";
}
$criteria = ['visibility' => $visibility, 'status' => 'active', 'team' => 'exists'] + $templateVars['criteria'];
if ($user = $this->getUser()) {
$teamId = $user->getMemberId();
} else {
$teamId = 0;
}
$entities = $em->getRepository(Startup::class)->findTags($criteria, $teamId);
return $this->render('@StartPlatzAlpha/Default/list.tags.modal.html.twig', [
'title' => "Tags",
'entities' => $entities,
'btnClass' => "btn-outline-info",
'targetEntity' => "tags",
'targetPath' => $targetPath,
'currentCriteria' => $currentCriteria,
'templateVars' => $templateVars,
'redirect' => $redirect,
'redirectUrl' => $request->get('redirect'),
]);
}
/**
* @Route("/x/startups/filter/rheinland-pitch", name="x_startups_filter_rheinland-pitch")
*/
public function selectFilterRheinlandPitchAction(Request $request)
{
$em = $this->getDoctrine()->getManager();
$redirect = json_decode(base64_decode((string) $request->get('redirect')));
$templateVars = $em->getRepository(Startup::class)->getTemplateVars($request);
if (!$source = $request->get('source')) {
$visibility = 'sp-connect';
$targetPath = "x_connect_startups_home";
} else {
$visibility = 'public';
$targetPath = "homepage_startups_home";
}
$criteria = ['visibility' => $visibility, 'status' => 'active', 'team' => 'exists'] + $templateVars['criteria'];
if ($user = $this->getUser()) {
$teamId = $user->getMemberId();
} else {
$teamId = 0;
}
$filter = $request->get('filter');
$group1 = "rheinlandPitchStatus";
$aggregates1 = $em->getRepository(Startup::class)->getAggregateByGroup($group1, $criteria);
$group2 = "rheinlandPitchBestResult";
$aggregates2 = $em->getRepository(Startup::class)->getAggregateByGroup($group2, $criteria);
// batches
$aggregatesBatches = $em->getRepository(Startup::class)->findApplicationsByProgramId(1);
return $this->render('@StartPlatzAlpha/Default/list.rheinland-pitch.modal.html.twig', [
'title' => "Set Filter on {$filter}",
'btnClass' => "btn-outline-info",
'group1' => $group1,
'group2' => $group2,
'aggregates1' => $aggregates1,
'aggregates2' => $aggregates2,
'aggregatesBatches' => $aggregatesBatches,
'targetPath' => $targetPath,
'templateVars' => $templateVars,
'redirect' => $redirect,
'redirectUrl' => $request->get('redirect'),
]);
}
/**
* @Route("/x/startups/filter", name="x_startups_filter")
*/
public function selectFilterAction(Request $request)
{
$em = $this->getDoctrine()->getManager();
$redirect = json_decode(base64_decode((string) $request->get('redirect')));
$templateVars = $em->getRepository(Startup::class)->getTemplateVars($request);
if (!$source = $request->get('source')) {
$visibility = 'sp-connect';
} else {
$visibility = 'public';
}
if (!$targetPath = $request->get('targetPath')) {
if ($visibility == 'sp-connect') {
$targetPath = "x_connect_startups_home";
} else {
$targetPath = "homepage_startups_home";
}
}
$criteria = ['visibility' => $visibility, 'status' => 'active', 'team' => 'exists'] + $templateVars['criteria'];
if ($user = $this->getUser()) {
$teamId = $user->getMemberId();
} else {
$teamId = 0;
}
$group = $request->get('filter');
$aggregates = $em->getRepository(Startup::class)->getAggregateByGroup($group, $criteria);
$group2 = "";
$aggregates2 = [];
if ($group == 'accelerator') {
$group2 = "batch";
$aggregates2 = $em->getRepository(Startup::class)->getAggregateByGroup($group2, $criteria, ['batchYear' => 'ASC'], true);
}
if ($group == 'rheinlandPitch') {
$group2 = "pitchNumber";
$aggregates2 = $em->getRepository(Startup::class)->findAndExpandAggregatesByField($group2, $criteria, $teamId, $group);
}
return $this->render('@StartPlatzAlpha/Default/list.aggregates.modal.html.twig', [
'title' => "Set Filter on {$group}",
'aggregates' => $aggregates,
'btnClass' => "btn-outline-info",
'group' => $group,
'group2' => $group2,
'aggregates2' => $aggregates2,
'targetPath' => $targetPath,
'templateVars' => $templateVars,
'redirect' => $redirect,
'redirectUrl' => $request->get('redirect'),
]);
}
/**
* @Route("/startups-legacy", name="extern_startups_home")
*/
public function indexLegacyAction(Request $request)
{
$em = $this->getDoctrine()->getManager();
$member = $em->getRepository(Member::class)->findOneBy([]);
$fields = $this->feedbackService->getEntityMethodsArray($member, ['teams']);
$templateVars = $em->getRepository(Member::class)->getTemplateVars($request);
if ($user = $this->getUser()) {
$em->getRepository(User::class)->writeActivity($user);
}
$metaNameSectionBatch21 = 'website.startups.section.batch21';
$metaNameSectionBatch20 = 'website.startups.section.batch20';
$metaNameSectionBatch19 = 'website.startups.section.batch19';
$metaNameSectionBatch18 = 'website.startups.section.batch18';
$metaNameSectionBatch17 = 'website.startups.section.batch17';
$metaNameSectionKoeln = 'website.startups.section.koeln';
$metaNameSectionDus = 'website.startups.section.dus';
$metaNameSectionAlumni = 'website.startups.section.alumni';
$edit = $request->get('edit');
if (!in_array($edit, ['updateBatch21', 'updateBatch20', 'updateBatch19', 'updateBatch18', 'updateBatch17', 'updateKoeln', 'updateDus', 'updateAlumni'])) {
$edit = null;
}
$sectionBatch21 = $this->getSection($metaNameSectionBatch21);
$sectionBatch20 = $this->getSection($metaNameSectionBatch20);
$sectionBatch19 = $this->getSection($metaNameSectionBatch19);
$sectionBatch18 = $this->getSection($metaNameSectionBatch18);
$sectionBatch17 = $this->getSection($metaNameSectionBatch17);
$sectionKoeln = $this->getSection($metaNameSectionKoeln);
$sectionDus = $this->getSection($metaNameSectionDus);
$sectionAlumni = $this->getSection($metaNameSectionAlumni);
switch ($edit) {
case 'updateBatch21':
$content = $this->transformArrayIntoCsvString($sectionBatch21['content']);
$form = $this->setPlainEditorForm($content);
break;
case 'updateBatch20':
$content = $this->transformArrayIntoCsvString($sectionBatch20['content']);
$form = $this->setPlainEditorForm($content);
break;
case 'updateBatch19':
$content = $this->transformArrayIntoCsvString($sectionBatch19['content']);
$form = $this->setPlainEditorForm($content);
break;
case 'updateBatch18':
$content = $this->transformArrayIntoCsvString($sectionBatch18['content']);
$form = $this->setPlainEditorForm($content);
break;
case 'updateBatch17':
$content = $this->transformArrayIntoCsvString($sectionBatch17['content']);
$form = $this->setPlainEditorForm($content);
break;
case 'updateKoeln':
$content = $this->transformArrayIntoCsvString($sectionKoeln['content']);
$form = $this->setPlainEditorForm($content);
break;
case 'updateDus':
$content = $this->transformArrayIntoCsvString($sectionDus['content']);
$form = $this->setPlainEditorForm($content);
break;
case 'updateAlumni':
$content = $this->transformArrayIntoCsvString($sectionAlumni['content']);
$form = $this->setPlainEditorForm($content);
break;
default:
$content = "";
$form = $this->setEditorForm($content);
}
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$data = $form->getData();
$importString = $data['content'];
$rows = explode(PHP_EOL, (string) $importString);
switch ($edit) {
case 'updateBatch21':
$sectionBatch21['content'] = [];
foreach ($rows as $row) {
$sectionBatch21['content'][] = str_getcsv($row, "\t");
}
$em->getRepository(Option::class)->setOptionMetaValueJsonEncoded($metaNameSectionBatch21, null, $sectionBatch21);
break;
case 'updateBatch20':
$sectionBatch20['content'] = [];
foreach ($rows as $row) {
$sectionBatch20['content'][] = str_getcsv($row, "\t");
}
$em->getRepository(Option::class)->setOptionMetaValueJsonEncoded($metaNameSectionBatch20, null, $sectionBatch20);
break;
case 'updateBatch19':
$sectionBatch19['content'] = [];
foreach ($rows as $row) {
$sectionBatch19['content'][] = str_getcsv($row, "\t");
}
$em->getRepository(Option::class)->setOptionMetaValueJsonEncoded($metaNameSectionBatch19, null, $sectionBatch19);
break;
case 'updateBatch18':
$sectionBatch18['content'] = [];
foreach ($rows as $row) {
$sectionBatch18['content'][] = str_getcsv($row, "\t");
}
$em->getRepository(Option::class)->setOptionMetaValueJsonEncoded($metaNameSectionBatch18, null, $sectionBatch18);
break;
case 'updateBatch17':
$sectionBatch17['content'] = [];
foreach ($rows as $row) {
$sectionBatch17['content'][] = str_getcsv($row, "\t");
}
$em->getRepository(Option::class)->setOptionMetaValueJsonEncoded($metaNameSectionBatch17, null, $sectionBatch17);
break;
case 'updateKoeln':
$sectionKoeln['content'] = [];
foreach ($rows as $row) {
$sectionKoeln['content'][] = str_getcsv($row, "\t");
}
$em->getRepository(Option::class)->setOptionMetaValueJsonEncoded($metaNameSectionKoeln, null, $sectionKoeln);
break;
case 'updateDus':
$sectionDus['content'] = [];
foreach ($rows as $row) {
$sectionDus['content'][] = str_getcsv($row, "\t");
}
$em->getRepository(Option::class)->setOptionMetaValueJsonEncoded($metaNameSectionDus, null, $sectionDus);
break;
case 'updateAlumni':
$sectionAlumni['content'] = [];
foreach ($rows as $row) {
$sectionAlumni['content'][] = str_getcsv($row, "\t");
}
$em->getRepository(Option::class)->setOptionMetaValueJsonEncoded($metaNameSectionAlumni, null, $sectionAlumni);
break;
}
$this->session->getFlashBag()->add('notice', 'SUCCESS data saved');
}
$sectionBatch21 = $this->getSection($metaNameSectionBatch21);
$sectionBatch20 = $this->getSection($metaNameSectionBatch20);
$sectionBatch19 = $this->getSection($metaNameSectionBatch19);
$sectionBatch18 = $this->getSection($metaNameSectionBatch18);
$sectionBatch17 = $this->getSection($metaNameSectionBatch17);
$sectionKoeln = $this->getSection($metaNameSectionKoeln);
$sectionDus = $this->getSection($metaNameSectionDus);
$sectionAlumni = $this->getSection($metaNameSectionAlumni);
return $this->render('@StartPlatzAlphaBundle/Startup/index.legacy.html.twig', [
'templateVars' => [],
'form' => $form->createView(),
'sectionBatch21' => $sectionBatch21,
'sectionBatch20' => $sectionBatch20,
'sectionBatch19' => $sectionBatch19,
'sectionBatch18' => $sectionBatch18,
'sectionBatch17' => $sectionBatch17,
'sectionKoeln' => $sectionKoeln,
'sectionDus' => $sectionDus,
'sectionAlumni' => $sectionAlumni,
'edit' => $edit,
'menuLinksAndPhrases' => $this->menuTranslationService->getMenuLinksAndPhrases($request->server->get('REQUEST_URI')),
'redirectUrl' => base64_encode(json_encode(['path' => 'extern_startups_home', 'parameters' => []])),
]);
}
/**
* @Route("/startup/{slug}", name="homepage_startup_single")
* @Route("/en/startup/{slug}", name="homepage_startup_single_english")
*/
public function singleAction(Request $request, $slug)
{
$em = $this->getDoctrine()->getManager();
$templateVars = $em->getRepository(Team::class)->getTemplateVars($request);
/** @var User $user */
if ($user = $this->getUser()) {
$em->getRepository(User::class)->writeActivity($user);
}
$id = explode('-', (string) $slug)[0];
$slug = explode('-', (string) $slug)[1];
/** @var Startup $startup */
if (!$startup = $em->getRepository(Startup::class)->findOneBy(['id' => $id])) {
$this->session->getFlashBag()->add('notice', 'ERROR slug not found');
return $this->redirect($this->generateUrl('homepage_startups_home'));
}
if (!$team = $em->getRepository(Team::class)->findOneBy(['id' => $startup->getTeamId()])) {
$this->session->getFlashBag()->add('notice', 'ERROR insufficient data');
return $this->redirect($this->generateUrl('homepage_startups_home'));
}
$feedItems = [];
$entities = [];
if ($startup->getSlug()) {
// feedTags are expected to be a jsonArray
$feedTags = json_encode([$startup->getSlug()]);
$feedItems = $em->getRepository(Feed::class)->findByFeedTag($feedTags);
$entities = $em->getRepository(Feed::class)->getEntitiesByFeedItems($feedItems);
}
// rheinlandPitch has programId == 1
$rheinlandPitches = $em->getRepository(Application::class)->findApplicationsAndBatchesByStartupIdAndProgramId($id, 1);
$memberTypes = [];
$teamIndustries = [];
$teamIndustryList = "";
$applications = [];
if ($team) {
if ($team->getType() == 'Partner') {
$memberTypes = ['GF', 'AP'];
}
$teamIndustries = $team->getIndustries();
$teamIndustryList = explode("#", (string) $teamIndustries);
// plausibility checks for members of that team
$em->getRepository(Member::class)->checkIfDescriptionIsEmptyButMentorProfileIsFilled($team);
$relevantProgramIds = ['1','2','3'];
$applications = $em->getRepository(Application::class)->findBy(['teamId'=>$team->getId(),'programId'=>$relevantProgramIds]);
}
$members = $em->getRepository(MemberTeam::class)->getTeamMembers($id, $memberTypes);
$allowEdit = false;
$teamMember = false;
if($user) {
$userEmail = $this->getUser()->getEmail();
foreach ($members as $member) {
if ($member['email'] == $userEmail) {
$teamMember = true;
if ($member['type'] == 'AP' || $member['type'] == 'GF') {
$allowEdit = true;
}
}
}
}
// create slugs from team on the fly and from startup, what is stored there
if ($team) {
$slugs[] = Utility::generateSlug($team->getShortName());
}
if ($startup->getSlug()) {
$slugs[] = $startup->getSlug();
}
$feedTags = json_encode(array_values(array_unique($slugs)));
if ($feedTags) {
$feedItems = $em->getRepository(Feed::class)->findByFeedTag($feedTags);
$em->getRepository(Actor::class)->updateScoreByFeedItems(is_countable($feedItems) ? count($feedItems) : 0, $startup->getId());
$entities = $em->getRepository(Feed::class)->getEntitiesByFeedItems($feedItems);
}
$hasVisibleApplication = false;
foreach ($applications as $application) {
if($application->getVisibility() == 'sp-connect') {
$hasVisibleApplication = true;
break;
}
}
$lang = Utility::getLangByPathInfo($request->getPathInfo());
if ($startup->getVisibility() == 'public') {
return $this->render('@StartPlatzAlphaBundle/Startup/single.homepage.html.twig', [
'id' => $id,
'startup' => $startup,
'team' => $team,
'feedItems' => $feedItems,
'entities' => $entities,
'lang' => $lang,
'rheinlandPitches' => $rheinlandPitches,
'redirectUrl' => base64_encode(json_encode(['path' => 'homepage_startup_single', 'parameters' => ['slug' => $id . '-' . $slug]])),
'menuLinksAndPhrases' => $this->menuTranslationService->getMenuLinksAndPhrases($request->server->get('REQUEST_URI')),
'applications' => $applications,
'hasVisibleApplication' => $hasVisibleApplication,
'methodsTeam' => $team ? $this->feedbackService->getEntityMethodsArray($team, ['services', 'members']) : [],
'methodsStartup' => $startup ? $this->feedbackService->getEntityMethodsArray($startup, []) : [],
'feedTags' => $feedTags,
'actor' => $em->getRepository(Actor::class)->findOneBy(['externalId' => $startup->getId()]),
'templateVars' => $templateVars,
'queryString' => '',
// 'members' => $members,
'memberTypes' => $memberTypes,
'teamIndustryList' => $teamIndustryList,
'allowEdit' => $allowEdit,
'teamMember' => $teamMember,
'memberTypeLabels' => $em->getRepository(MemberTeam::class)->getMemberTypeLabels(),
'currentPath' => '/x/connect/team/{id}',
'backUrl' => $request->get('redirect') ?: base64_encode(json_encode(['path' => 'x_connect_startups_home', 'parameters' => $templateVars])),
]);
} else {
return $this->render('@StartPlatzAlphaBundle/Startup/single.homepage.sorry.html.twig', [
'lang' => $lang,
'menuLinksAndPhrases' => $this->menuTranslationService->getMenuLinksAndPhrases($request->server->get('REQUEST_URI')),
'redirectUrl' => base64_encode(json_encode(['path' => 'homepage_startup_single', 'parameters' => ['slug' => $id . '-' . $slug]])),
]);
}
}
/**
* @Route("/x/community/startups/home/", name="x_startups_home")
* @Security("is_granted('ROLE_USER')")
*/
public function indexStartupsAction(Request $request)
{
$em = $this->getDoctrine()->getManager();
$redirect = json_decode(base64_decode((string) $request->get('redirect')));
$redirectUrl = $request->get('redirect');
$templateVars = $em->getRepository(Startup::class)->getTemplateVars($request);
$orderBy = $templateVars['dimensions'] ?: [];
$visibility = 'sp-connect';
$criteria = ['visibility' => $visibility] + $templateVars['criteria'];
$teamId = 0;
if ($user = $this->getUser()) {
$teamId = $user->getMemberId();
$em->getRepository(User::class)->writeActivity($user);
$member = $em->getRepository(Member::class)->find($user->getMemberId());
}
$total = $em->getRepository(Startup::class)->countByCriteria($criteria, $teamId);
if ($total > 12) {
$limit = 12;
} else {
$limit = $total ?: 1;
}
if (!$page = $request->get('page')) {
$page = 1;
}
$startups = $em->getRepository(Startup::class)->findPaginated($criteria, $teamId, $orderBy, $page, $limit);
$lang = $request->get('lang');
if (str_contains((string) $member->getTags(), 'beta')) {
$view = '@StartPlatzAlphaBundle/Startup/Startups__index.twig';
} else {
$view = '@StartPlatzAlphaBundle/Startup/Startups__index_old.twig';
}
return $this->render($view, [
'maxPages' => ceil($total / $limit),
'thisPage' => $page,
'total' => $total,
'criteria' => $criteria,
'visibility' => $visibility,
'templateVars' => $templateVars,
'startups' => $startups,
'backUrl' => $redirectUrl,
'menuLinksAndPhrases' => $this->menuTranslationService->getMenuLinksAndPhrases($request->server->get('REQUEST_URI')),
'redirectUrl' => base64_encode(json_encode(['path' => 'website_startups_list', 'parameters' => $templateVars])),
]);
}
/**
* @Route("/startup-database/list/", name="website_startups_list")
* @Route("/startup-database/list/", name="extern_startups_list")
* @Security("is_granted('ROLE_USER')")
*/
public function listAction(Request $request)
{
$em = $this->getDoctrine()->getManager();
$redirect = json_decode(base64_decode((string) $request->get('redirect')));
$redirectUrl = $request->get('redirect');
$templateVars = $em->getRepository(Startup::class)->getTemplateVars($request);
$orderBy = $templateVars['dimensions'] ?: [];
$visibility = 'public';
$criteria = ['visibility' => $visibility] + $templateVars['criteria'];
$teamId = 0;
if ($user = $this->getUser()) {
$teamId = $user->getMemberId();
$em->getRepository(User::class)->writeActivity($user);
}
$total = $em->getRepository(Startup::class)->countByCriteria($criteria, $teamId);
if ($total > 12) {
$limit = 12;
} else {
$limit = $total ?: 1;
}
if (!$page = $request->get('page')) {
$page = 1;
}
$startups = $em->getRepository(Startup::class)->findPaginated($criteria, $teamId, $orderBy, $page, $limit);
$lang = $request->get('lang');
$targetPath = $request->server->get('REQUEST_URI');
return $this->render('@StartPlatzAlphaBundle/Startup/list.html.twig', [
'targetPath' => $targetPath,
'lang' => $lang,
'maxPages' => ceil($total / $limit),
'thisPage' => $page,
'total' => $total,
'criteria' => $criteria,
'visibility' => $visibility,
'templateVars' => $templateVars,
'startups' => $startups,
'backUrl' => $redirectUrl,
'menuLinksAndPhrases' => $this->menuTranslationService->getMenuLinksAndPhrases($request->server->get('REQUEST_URI')),
'redirectUrl' => base64_encode(json_encode(['path' => 'website_startups_list', 'parameters' => $templateVars])),
]);
}
/**
* @Route("/startup-database/show/{id}/{slug}", name="extern_startups_single")
*/
public function singleExternAction(Request $request, $id, $slug)
{
$em = $this->getDoctrine()->getManager();
if ($user = $this->getUser()) {
$em->getRepository(User::class)->writeActivity($user);
}
if (!$redirect = json_decode(base64_decode((string) $request->get('redirect')))) {
$redirect = new stdClass();
$redirect->path = 'website_startups_list';
$redirect->parameters = [];
}
$redirectUrl = $request->get('redirect');
if (!$startup = $em->getRepository(Startup::class)->findOneBy(['id' => $id, 'visibility' => 'public'])) {
$this->session->getFlashBag()->add('notice', 'ERROR 10 entity not found');
return $this->redirect($this->generateUrl($redirect->path, (array)$redirect->parameters));
}
if ($slug != $startup->getSlug()) {
return $this->redirect($this->generateUrl('extern_startups_single', ['id' => $id, 'slug' => $startup->getSlug(), 'redirect' => $redirectUrl]));
}
$rightToAccessTeam = false;
$team = false;
$memberId = 0;
$teamId = $startup->getTeamId();
if ($user = $this->getUser()) {
$memberId = $user->getMemberId();
if (!$member = $em->getRepository(Member::class)->findOneBy(['id' => $memberId])) {
$this->session->getFlashBag()->add('notice', 'ERROR There is a problem with your account please contact support@startplatz.de');
return $this->redirect($this->generateUrl($redirect->path, (array)$redirect->parameters));
}
if ($team = $em->getRepository(Team::class)->findOneBy(['id' => $teamId])) {
$rightToAccessTeam = $em->getRepository(MemberTeam::class)->checkAccessRight($member, $team);
$team = $em->getRepository(Team::class)->checkConsistencyWithStartup($team, $startup);
}
}
// the use of memberId is on purpose
$startupAttributes = $em->getRepository(StartupAttribute::class)->findOneBy(['startupId' => $startup->getId(), 'teamId' => $memberId]);
$startupLivecycleEvents = $em->getRepository(StartupLifecycleEvent::class)->findBy(['startupId' => $startup->getId()], ['eventDate' => 'ASC']);
$em->getRepository(StartupRelevance::class)->updateByUserAction($id, 'click');
$rheinlandPitches = $em->getRepository(Application::class)->findBy(['startupId' => $id], ['batchId' => 'DESC']);
return $this->render('@StartPlatzAlphaBundle/Startup/single.extern.twig', [
'templateVars' => [],
'startup' => $startup,
'rightToAccessTeam' => $rightToAccessTeam,
'startupAttributes' => $startupAttributes,
'rheinlandPitches' => $rheinlandPitches,
'startupLivecycleEvents' => $startupLivecycleEvents,
'backUrl' => $redirectUrl,
'menuLinksAndPhrases' => $this->menuTranslationService->getMenuLinksAndPhrases($request->server->get('REQUEST_URI')),
'redirectUrl' => base64_encode(json_encode(['path' => 'extern_startups_single', 'parameters' => ['id' => $id, 'slug' => $startup->getSlug()]])),
]);
}
/**
* @Route("/x/community/startup/single/{id}", name="x_community_startup_single")
* @Security("is_granted('ROLE_USER')")
*/
public function singleCommunityAction(Request $request, $id)
{
$em = $this->getDoctrine()->getManager();
if ($user = $this->getUser()) {
$em->getRepository(User::class)->writeActivity($user);
}
if (!$redirect = json_decode(base64_decode((string) $request->get('redirect')))) {
$redirect = new stdClass();
$redirect->path = 'x_home';
$redirect->parameters = [];
}
$redirectUrl = $request->get('redirect');
if (!$startup = $em->getRepository(Startup::class)->findSingleStartupByVisibility($id, 'sp-connect')) {
$this->session->getFlashBag()->add('notice', 'ERROR 20 entity not found');
return $this->redirect($this->generateUrl($redirect->path, (array)$redirect->parameters));
}
$rightToAccessTeam = false;
$team = false;
$memberId = 0;
$teamId = $startup->getTeamId();
if ($user = $this->getUser()) {
$memberId = $user->getMemberId();
if (!$member = $em->getRepository(Member::class)->findOneBy(['id' => $memberId])) {
$this->session->getFlashBag()->add('notice', 'ERROR There is a problem with your account please contact support@startplatz.de');
return $this->redirect($this->generateUrl($redirect->path, (array)$redirect->parameters));
}
if ($team = $em->getRepository(Team::class)->findOneBy(['id' => $teamId])) {
$rightToAccessTeam = $em->getRepository(MemberTeam::class)->checkAccessRight($member, $team);
$team = $em->getRepository(Team::class)->checkConsistencyWithStartup($team, $startup);
}
}
// the use of memberId is on purpose
$startupAttributes = $em->getRepository(StartupAttribute::class)->findOneBy(['startupId' => $startup->getId(), 'teamId' => $memberId]);
$startupLivecycleEvents = $em->getRepository(StartupLifecycleEvent::class)->findBy(['startupId' => $startup->getId()], ['eventDate' => 'ASC']);
$em->getRepository(StartupRelevance::class)->updateByUserAction($id, 'click');
$rheinlandPitches = $em->getRepository(Application::class)->findBy(['startupId' => $id], ['batchId' => 'DESC']);
$lang = $request->get('lang');
$targetPath = $request->server->get('REQUEST_URI');
return $this->render('@StartPlatzAlphaBundle/Startup/single.sp-connect.html.twig', [
'targetPath' => $targetPath,
'lang' => $lang,
'templateVars' => [],
'startup' => $startup,
'rightToAccessTeam' => $rightToAccessTeam,
'startupAttributes' => $startupAttributes,
'rheinlandPitches' => $rheinlandPitches,
'startupLivecycleEvents' => $startupLivecycleEvents,
'backUrl' => $redirectUrl,
'menuLinksAndPhrases' => $this->menuTranslationService->getMenuLinksAndPhrases($request->server->get('REQUEST_URI')),
'redirectUrl' => base64_encode(json_encode(['path' => 'extern_startups_single', 'parameters' => ['id' => $id, 'slug' => $startup->getSlug()]])),
]);
}
/**
* @Route("/allmeda/startups/toggle-ajax/{id}/{field}/{action}", name="startup_edit_field_ajax")
* @Security("is_granted('ROLE_ADMIN')")
*/
public function setToggleAjaxAction($id, $field, $action)
{
$em = $this->getDoctrine()->getManager();
$response = $em->getRepository(Startup::class)->setField($field, $action, $id);
if (str_starts_with((string) $response, 'field ')) {
$response = "SUCCESS $response";
}
return new Response($response);
}
/**
* @Route("/x/connect/startup/edit/{id}/set-with-data", name="x_connect_startup_set_field_ajax_with_data")
* @Route("/x/connect/startup/edit/{id}/set/{field}/{action}", name="x_connect_startup_set_field_ajax")
* @Security("is_granted('ROLE_USER')")
*/
public function setAjaxAction(Request $request, $id = null, $field = null, $action = null)
{
$em = $this->getDoctrine()->getManager();
$adminEmail = $this->getUser()->getIsAdmin() ? $this->getUser()->getEmail() : null;
$id ?? $id = $request->get('id');
$field ?? $field = $request->get('field');
$action ?? $action = $request->get('action');
if(!$id or !$field or !$action) {
$response = 'ERROR some data is missing';
} elseif (!$startup = $em->getRepository(Startup::class)->findOneBy(['id' => $id])) {
$response = 'ERROR No entity found for id=' . $id;
} else {
$response = $em->getRepository(Startup::class)->setFieldByAjaxConnect($field, $action, $startup, $this->getUser());
if (str_starts_with((string) $response, 'Updated ')) {
if($field == 'imageLink') {
$this->removeOldResourcesFromCloudinary("startup-banner-{$startup->getTeamId()}", $action);
} elseif($field == 'logoUrl') {
$this->removeOldResourcesFromCloudinary("startup-logo-{$startup->getTeamId()}", $action);
}
$response = "SUCCESS $response";
}
}
return new Response($response);
}
/**
* @Route("/x/connect/startup/edit/{id}/{slug}", name="x_startup_edit")
* @Security("is_granted('ROLE_USER')")
*/
public function editStartupAction(Request $request, $id, $slug)
{
$em = $this->getDoctrine()->getManager();
$redirect = json_decode(base64_decode((string) $request->get('redirect')));
$redirectUrl = $request->get('redirect');
/** @var Startup $startup */
if (!$startup = $em->getRepository(Startup::class)->findOneBy(['id' => $id])) {
$this->session->getFlashBag()->add('notice', 'ERROR 30 entity not found');
return $this->redirect($this->generateUrl($redirect->path, (array)$redirect->parameters));
}
$teamId = $startup->getTeamId();
/** @var Team $team */
$team = $em->getRepository(Team::class)->findOneBy(['id' => $teamId]);
/** @var User $user */
$user = $this->getUser();
$teamRights = $em->getRepository(MemberTeam::class)->getTeamRights();
if(!$user->getIsAdmin()) {
if (!$userObjects = $em->getRepository(User::class)->getUserObjectsByTeamId($user, $teamId)) {
$this->session->getFlashBag()->add('notice', 'ERROR: you are not allowed to access this team');
return $this->redirect($this->generateUrl('x_home'));
}
/** @var Team $team */
$team = $em->getRepository(Team::class)->findOneBy(['id' => $teamId]);
$teamRight = $teamRights[$userObjects['accessRight']->getType()];
} else {
$teamRight = 'SP-Admin';
}
if($request->get('memberId') && $user->getIsAdmin()) {
$memberId = $request->get('memberId');
} else {
$memberId = $user->getMemberId();
}
/** @var Member $member */
$member = $em->getRepository(Member::class)->findOneBy(['id' => $user->getMemberId()]);
$memberTeam = $em->getRepository(MemberTeam::class)->findOneBy(['member' => $member, 'team' => $team]);
$teamRight = $memberTeam ? $teamRights[$memberTeam->getType()] : false;
if ($errorMessage = $em->getRepository(Member::class)->hasValidMembership($member)) {
$this->session->getFlashBag()->add('notice', 'ERROR ' . $errorMessage);
return $this->redirect($this->generateUrl($redirect->path, (array)$redirect->parameters));
}
if (!$em->getRepository(MemberTeam::class)->checkAccessRight($member, $team) and !$user->getIsAdmin()) {
$this->session->getFlashBag()->add('notice', 'ERROR There is a problem with your account, please contact support@startplatz.de');
return $this->redirect($this->generateUrl($redirect->path, (array)$redirect->parameters));
}
$fields = Utility::getEntityFieldsArray($startup);
$storedData = Utility::fillDataByObject($startup, $fields);
$uploadTagLogo = "team-logo-{$teamId}";
$uploadTagBanner = "startup-banner-{$teamId}";
$industries = $em->getRepository(Startup::class)->getListOfIndustries();
$form = $this->createForm(StartupType::class, $startup, ['industries' => $industries, 'editForm' => 'spConnect']);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$data = $form->getData();
$updatedData = Utility::fillDataByObject($startup, $fields);
$differences = array_diff_assoc($updatedData, $storedData);
if ($differences) {
if (array_key_exists("imageLink", $differences) && $imageLink = $differences['imageLink']) {
$this->removeOldResourcesFromCloudinary($uploadTagBanner, $imageLink);
}
if (array_key_exists("logoUrl", $differences) && $imageLink = $differences['logoUrl']) {
$this->removeOldResourcesFromCloudinary($uploadTagLogo, $imageLink);
}
$startupScoreBefore = $startup->getScore();
$startup = $em->getRepository(Startup::class)->updateByEdit($startup, $differences, $user->getEmail());
if ($team) {
$team = $em->getRepository(Team::class)->syncDataWithStartup($team, $startup);
}
if ($startup->getVisibility() != "public" && $startup->getVisibility() != "sp-connect" && $startupScoreBefore < 250 && $startup->getScore() >= 250) {
$memberName = $member->getName();
$profileUrl = $request->getSchemeAndHttpHost() . $this->generateUrl("allmeda_startup_edit", ["id" => $startup->getId()]);
$mail = new Email();
$mail->subject("Startup profile filled in: {$startup->getName()}");
$mail->from(new Address("support@startplatz.de", "Startup profile complete"));
$mail->to(new Address("community-membership@startplatz.de", "Membership Profile"));
$mail->text("
Das Profil von Startup {$startup->getName()} (Id: {$startup->getId()}) wurde ausgefüllt und könnte nun veröffentlicht werden.
The profile of startup {$startup->getName()} (Id: {$startup->getId()}) was filled in and could be set to public now.
Link: {$profileUrl}
");
try {
$this->mailer->send($mail);
} catch (TransportExceptionInterface) {
return new Response("ERROR Email couldn't be sent", 503);
}
}
// give bonus when edited
$em->getRepository(StartupRelevance::class)->updateRelevanceScoreByStartup($startup->getId(), $storedData['score'], $startup->getScore());
//sync actors
return $this->redirect($this->generateUrl('x_connect_team_show', ['id' => $teamId, 'toast' => base64_encode("Data have been saved."), 'toastType' => base64_encode('SUCCESS')]));
} else {
return $this->redirect($this->generateUrl('x_connect_team_show', ['id' => $teamId, 'toast' => base64_encode("No data have been saved")]));
}
}
$teamIndustries = (string) $team->getIndustries(); // Cast to string to ensure $teamIndustries is not null
$teamIndustryList = explode("#", (string) $teamIndustries);
// create slugs from team on the fly and from startup, what is stored there
$slugs[] = Utility::generateSlug($team->getShortName());
if ($startup->getSlug()) {
$slugs[] = $startup->getSlug();
}
$feedTags = json_encode(array_values(array_unique($slugs)));
return $this->render('@StartPlatzAlphaBundle/Startup/edit.startup-profile.html.twig', [
'templateVars' => [],
'form' => $form->createView(),
'startup' => $startup,
'team' => $team,
'feedTags' => $feedTags,
'teamIndustryList' => $teamIndustryList,
'actor' => $em->getRepository(Actor::class)->findOneBy(['externalId' => $startup->getId()]),
'members' => $members = $em->getRepository(MemberTeam::class)->findByTeam($team),
'teamRights' => $teamRights,
'teamRight' => $teamRight,
'methodsTeam' => $this->feedbackService->getEntityMethodsArray($team, ['services', 'members']),
'methodsStartup' => $startup ? $this->feedbackService->getEntityMethodsArray($startup, []) : [],
'redirectUrl' => $redirectUrl,
'menuLinksAndPhrases' => $this->menuTranslationService->getMenuLinksAndPhrases($request->server->get('REQUEST_URI')),
'member' => $member,
'uploadTagBanner' => $uploadTagBanner,
'uploadTagLogo' => $uploadTagLogo,
'ownMemberId' => $member->getId(),
]);
}
private function removeOldResourcesFromCloudinary($uploadTag, $link): void
{
$result = $this->cloudinary->resources_by_tag($uploadTag);
$filter = fn ($res) => $res['secure_url'] != $link;
$oldRefs = array_filter($result['resources'], $filter);
$oldIds = array_map(fn ($res) => $res['public_id'], $oldRefs);
if (!empty($oldIds)) {
$result = $this->cloudinary->delete_resources($oldIds);
}
}
/**
* @Route("/startup-database/edit/{id}/{slug}", name="extern_startups_edit")
* @Security("is_granted('ROLE_USER')")
*/
public function editAction(Request $request, $id, $slug)
{
$em = $this->getDoctrine()->getManager();
$redirect = json_decode(base64_decode((string) $request->get('redirect')));
$redirectUrl = $request->get('redirect');
/** @var Startup $startup */
if (!$startup = $em->getRepository(Startup::class)->findOneBy(['id' => $id])) {
$this->session->getFlashBag()->add('notice', 'ERROR 40 entity not found');
return $this->redirect($this->generateUrl($redirect->path, (array)$redirect->parameters));
}
if ($slug != $startup->getSlug()) {
return $this->redirect($this->generateUrl('extern_startups_single', ['id' => $id, 'slug' => $startup->getSlug(), 'redirect' => $redirectUrl]));
}
$rightToAccessTeam = false;
$team = false;
$memberId = 0;
$teamId = $startup->getTeamId();
/** @var User $user */
if ($user = $this->getUser()) {
$em->getRepository(User::class)->writeActivity($user);
$memberId = $user->getMemberId();
if (!$member = $em->getRepository(Member::class)->findOneBy(['id' => $memberId])) {
$this->session->getFlashBag()->add('notice', 'ERROR There is a problem with your account please contact support@startplatz.de');
return $this->redirect($this->generateUrl($redirect->path, (array)$redirect->parameters));
}
/** @var Team $team */
if ($team = $em->getRepository(Team::class)->findOneBy(['id' => $teamId])) {
$rightToAccessTeam = $em->getRepository(MemberTeam::class)->checkAccessRight($member, $team);
}
}
$admin = $user->getIsAdmin();
if (!$rightToAccessTeam and !$admin) {
$this->session->getFlashBag()->add('notice', 'ERROR There is a problem with your account-3 please contact support@startplatz.de');
return $this->redirect($this->generateUrl($redirect->path, (array)$redirect->parameters));
}
// the use of memberId is on purpose
$startupAttributes = $em->getRepository(StartupAttribute::class)->findOneBy(['startupId' => $startup->getId(), 'teamId' => $memberId]);
$em->getRepository(StartupRelevance::class)->updateByUserAction($id, 'edit');
$rheinlandPitches = $em->getRepository(Application::class)->findBy(['startupId' => $id], ['batchId' => 'DESC']);
$fields = Utility::getEntityFieldsArray($startup);
$storedData = Utility::fillDataByObject($startup, $fields);
$industries = $em->getRepository(Startup::class)->getListOfIndustries();
$form = $this->createForm(StartupType::class, $startup, ['industries' => $industries, 'editForm' => 'extern']);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$data = $form->getData();
$updatedData = Utility::fillDataByObject($startup, $fields);
$differences = array_diff_assoc($updatedData, $storedData);
if ($differences) {
$startup = $em->getRepository(Startup::class)->updateByEdit($startup, $differences, $user->getEmail());
if ($team) {
$team = $em->getRepository(Team::class)->syncDataWithStartup($team, $startup);
}
}
}
return $this->render('@StartPlatzAlphaBundle/Startup/edit.html.twig', [
'templateVars' => [],
'form' => $form->createView(),
'startup' => $startup,
'rightToAccessTeam' => $rightToAccessTeam,
'startupAttributes' => $startupAttributes,
'rheinlandPitches' => $rheinlandPitches,
'backUrl' => $redirectUrl,
'menuLinksAndPhrases' => $this->menuTranslationService->getMenuLinksAndPhrases($request->server->get('REQUEST_URI')),
'redirectUrl' => base64_encode(json_encode(['path' => 'extern_startups_single', 'parameters' => ['id' => $id, 'slug' => $startup->getSlug()]])),
]);
}
/**
* @Route("/startup-database/event/{id}/{slug}/{eventId}", name="extern_startups_event")
* @Security("is_granted('ROLE_USER')")
*/
public function startupLivecycleEventAction(Request $request, $id, $slug, $eventId)
{
$em = $this->getDoctrine()->getManager();
$now = new DateTime();
$redirect = json_decode(base64_decode((string) $request->get('redirect')));
$redirectUrl = $request->get('redirect');
if (!$startup = $em->getRepository(Startup::class)->findOneBy(['id' => $id])) {
$this->session->getFlashBag()->add('notice', 'ERROR 50 entity not found');
return $this->redirect($this->generateUrl($redirect->path, (array)$redirect->parameters));
}
if ($slug != $startup->getSlug()) {
return $this->redirect($this->generateUrl('extern_startups_single', ['id' => $id, 'slug' => $startup->getSlug(), 'redirect' => $redirectUrl]));
}
$rightToAccessTeam = false;
$team = false;
$memberId = 0;
$teamId = $startup->getTeamId();
/** @var User $user */
if ($user = $this->getUser()) {
$em->getRepository(User::class)->writeActivity($user);
$memberId = $user->getMemberId();
if (!$member = $em->getRepository(Member::class)->findOneBy(['id' => $memberId])) {
$this->session->getFlashBag()->add('notice', 'ERRORThere is a problem with your account please contact support@startplatz.de');
return $this->redirect($this->generateUrl($redirect->path, (array)$redirect->parameters));
}
if ($team = $em->getRepository(Team::class)->findOneBy(['id' => $teamId])) {
$rightToAccessTeam = $em->getRepository(MemberTeam::class)->checkAccessRight($member, $team);
}
}
$admin = $user->getIsAdmin();
if (!$rightToAccessTeam and !$admin) {
$this->session->getFlashBag()->add('notice', 'ERROR There is a problem with your account-4 please contact support@startplatz.de');
return $this->redirect($this->generateUrl($redirect->path, (array)$redirect->parameters));
}
// the use of memberId is on purpose
$startupAttributes = $em->getRepository(StartupAttribute::class)->findOneBy(['startupId' => $startup->getId(), 'teamId' => $memberId]);
$em->getRepository(StartupRelevance::class)->updateByUserAction($id, 'edit');
$rheinlandPitches = $em->getRepository(Application::class)->findBy(['startupId' => $id], ['batchId' => 'DESC']);
$startupLivecycleEvents = $em->getRepository(StartupLifecycleEvent::class)->findBy(['startupId' => $startup->getId()], ['eventDate' => 'ASC']);
if (!$livecycleEvent = $em->getRepository(StartupLifecycleEvent::class)->findOneBy(['id' => $eventId])) {
$livecycleEvent = new StartupLifecycleEvent();
$livecycleEvent->setEventDate($now);
$livecycleEvent->setStartupId($id);
}
// set array oldData value, nr, text
$fields = ['eventWhat', 'eventDate', 'linkText', 'link'];
$oldData = $this->getDataAsArray($fields, $livecycleEvent);
$form = $this->createForm(LivecycleEventType::class, $livecycleEvent);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$newData = $this->getDataAsArray($fields, $livecycleEvent);
$differences = array_diff_assoc($newData, $oldData);
if ($differences) {
$livecycleEvent = $em->getRepository(StartupLifecycleEvent::class)->updateByEdit($livecycleEvent, $differences, $user->getEmail());
$this->session->getFlashBag()->add('notice', 'SUCCESSData has been saved');
}
return $this->redirect($this->generateUrl($redirect->path, (array)$redirect->parameters));
}
return $this->render('@StartPlatzAlphaBundle/Startup/editLivecycleEvent.html.twig', [
'templateVars' => [],
'form' => $form->createView(),
'startup' => $startup,
'rightToAccessTeam' => $rightToAccessTeam,
'startupAttributes' => $startupAttributes,
'rheinlandPitches' => $rheinlandPitches,
'livecycleEvent' => $livecycleEvent,
'startupLivecycleEvents' => $startupLivecycleEvents,
'backUrl' => $redirectUrl,
'menuLinksAndPhrases' => $this->menuTranslationService->getMenuLinksAndPhrases($request->server->get('REQUEST_URI')),
'redirectUrl' => base64_encode(json_encode(['path' => 'extern_startups_single', 'parameters' => ['id' => $id, 'slug' => $startup->getSlug()]])),
]);
}
/**
* @Route("/startup-database/show-event/{id}/{slug}/{eventId}", name="extern_startups_show-event")
* @Security("is_granted('ROLE_USER')")
*/
public function showStartupLivecycleEventAction(Request $request, $id, $slug, $eventId)
{
$em = $this->getDoctrine()->getManager();
$now = new DateTime();
$redirect = json_decode(base64_decode((string) $request->get('redirect')));
$redirectUrl = $request->get('redirect');
if (!$startup = $em->getRepository(Startup::class)->findOneBy(['id' => $id])) {
$this->session->getFlashBag()->add('notice', 'ERROR 60 entity not found');
return $this->redirect($this->generateUrl($redirect->path, (array)$redirect->parameters));
}
if ($slug != $startup->getSlug()) {
return $this->redirect($this->generateUrl('extern_startups_single', ['id' => $id, 'slug' => $startup->getSlug(), 'redirect' => $redirectUrl]));
}
/** @var User $user */
if (!$user = $this->getUser()) {
$this->session->getFlashBag()->add('notice', 'SUCCESSplease register or login');
return $this->redirect($this->generateUrl($redirect->path, (array)$redirect->parameters));
}
$em->getRepository(User::class)->writeActivity($user);
$em->getRepository(StartupRelevance::class)->updateByUserAction($id, 'edit');
if (!$startupLivecycleEvent = $em->getRepository(StartupLifecycleEvent::class)->findOneBy(['id' => $eventId])) {
$this->session->getFlashBag()->add('notice', 'ERRORError - no event found');
return $this->redirect($this->generateUrl($redirect->path, (array)$redirect->parameters));
}
return $this->render('@StartPlatzAlphaBundle/Startup/showLivecycleEvent.html.twig', [
'templateVars' => [],
'startup' => $startup,
'startupLivecycleEvent' => $startupLivecycleEvent,
'backUrl' => $redirectUrl,
'menuLinksAndPhrases' => $this->menuTranslationService->getMenuLinksAndPhrases($request->server->get('REQUEST_URI')),
'redirectUrl' => base64_encode(json_encode(['path' => 'extern_startups_single', 'parameters' => ['id' => $id, 'slug' => $startup->getSlug()]])),
]);
}
private function getDataAsArray($fields, $entity)
{
foreach ($fields as $field) {
$method = 'get' . ucfirst((string) $field);
if (method_exists($entity, $method)) {
if ($entity->$method() instanceof DateTime) {
$data[$field] = $entity->$method()->format('Y-m-d');
} else {
$data[$field] = $entity->$method();
}
} else {
$data[$field] = "";
}
}
return $data;
}
/**
* @Route("/startup-database/get-in-contact/{id}", name="extern_startups_get-in-contact")
*/
public function getInContactAjaxAction(Request $request, $id)
{
$em = $this->getDoctrine()->getManager();
$redirect = json_decode(base64_decode((string) $request->get('redirect')));
return $this->render('@StartPlatzAlphaBundle/Startup/modal.register.html.twig', [
'title' => "Get in contact",
'btnClass' => "btn-outline-info",
'id' => $id,
'redirect' => $redirect,
'redirectUrl' => $request->get('redirect'),
]);
}
/**
* @Route("/startup-database/register/{id}", name="extern_startups_register")
*/
public function registerAjaxAction(Request $request, $id)
{
$em = $this->getDoctrine()->getManager();
$redirect = json_decode(base64_decode((string) $request->get('redirect')));
return $this->render('@StartPlatzAlphaBundle/Startup/modal.register.html.twig', [
'title' => "Please register",
'btnClass' => "btn-outline-info",
'id' => $id,
'redirect' => $redirect,
'redirectUrl' => $request->get('redirect'),
]);
}
/**
* @Route("/x/community/startups/missions/", name="x_startups_missions")
* @Security("is_granted('ROLE_USER')")
*/
public function indexMissionsForBadge(Request $request)
{
$em = $this->getDoctrine()->getManager();
$redirect = json_decode(base64_decode((string) $request->get('redirect')));
$redirectUrl = $request->get('redirect');
$templateVars = $em->getRepository(Startup::class)->getTemplateVars($request);
/** @var User $user */
$user = $this->getUser();
$em->getRepository(User::class)->writeActivity($user, '/x/community/startups/');
$id = $user->getTeamId();
/** @var Team $team */
$team = $em->getRepository(Team::class)->find($id);
if (!$startup = $em->getRepository(Startup::class)->findOneBy(['id' => $team->getStartupId()])) {
$startup = new Startup();
} else {
// increase relevance score every time a startup team is shown
$em->getRepository(StartupRelevance::class)->updateByUserAction($startup->getId(), 'click');
}
$lang = $request->get('lang');
$view = '@StartPlatzAlphaBundle/Startup/index.missionsForBadge.html.twig';
return $this->render($view, [
'team' => $team,
'startup' => $startup,
'templateVars' => $templateVars,
'backUrl' => $redirectUrl,
'menuLinksAndPhrases' => $this->menuTranslationService->getMenuLinksAndPhrases($request->server->get('REQUEST_URI')),
'redirectUrl' => base64_encode(json_encode(['path' => 'website_startups_list', 'parameters' => $templateVars])),
]);
}
private function setEditorForm($content)
{
return $this->formFactory->createNamedBuilder('editor')
->add(
'content',
TinymceType::class,
[
'label' => 'Content',
'data' => $content,
'required' => false,
]
)
->add('save', SubmitType::class, ['label' => 'Save'])
->getForm();
}
private function setPlainEditorForm($content)
{
return $this->formFactory->createNamedBuilder('editor')
->add(
'content',
TextareaType::class,
[
'label' => 'Content',
'data' => $content,
'attr' => ['rows' => '17', 'cols' => '180'],
'required' => false,
]
)
->add('save', SubmitType::class, ['label' => 'Save'])
->getForm();
}
private function getSection($metaName)
{
$em = $this->getDoctrine()->getManager();
if (!$section = $em->getRepository(Option::class)->getOptionMetaValue($metaName)) {
$section['fields'] = $this->setSectionFields();
$section['content'][] = [
"https://www.startplatz.de/wp-content/uploads/2012/11/golfpost_225x225.jpg",
"http://www.golfpost.de",
"Golf Post",
"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.",
"#golfistbesseralsdudenkst #wirsindanders #unsereweltistgrün",
"99999",
];
$em->getRepository(Option::class)->setOptionMetaValueJsonEncoded($metaName, null, $section);
}
$section['entities'] = $this->setSectionEntities($section);
return $section;
}
private function setSectionEntities($section)
{
$entities = [];
foreach ($section['content'] as $row) {
if ((is_countable($section['fields']) ? count($section['fields']) : 0) != (is_countable($row) ? count($row) : 0)) {
$i = 0;
foreach ($section['fields'] as $field) {
$entity[$field] = $row[$i] ?? $field;
$i++;
}
$entities[] = $entity;
} else {
$entities[] = array_combine($section['fields'], $row);
}
}
return $entities;
}
private function transformArrayIntoCsvString($rows)
{
$content = '';
foreach ($rows as $row) {
$content .= implode("\t", $row) . PHP_EOL;
}
return $content;
}
private function setSectionFields()
{
$fields = ['logo', 'url', 'name', 'desc', 'tags', 'teamId'];
return $fields;
}
}