src/Controller/DefaultController.php line 360

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use Carbon\Carbon;
  4. use FormBuilderBundle\Assembler\FormAssembler;
  5. use FormBuilderBundle\Resolver\FormOptionsResolver;
  6. use Pimcore\Controller\FrontendController;
  7. use Pimcore\Model\DataObject;
  8. use Pimcore\Model\Asset;
  9. use Pimcore\Model\Element\Tag;
  10. use Pimcore\Model\DataObject\Service;
  11. use Symfony\Component\HttpFoundation\Request;
  12. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
  13. use Symfony\Component\Routing\Annotation\Route;
  14. use Symfony\Component\HttpFoundation\Response;
  15. use App\Model\DataObject\News;
  16. use App\Model\DataObject\Event;
  17. use Symfony\Component\String\Slugger\AsciiSlugger;
  18. class DefaultController extends FrontendController
  19. {
  20.     /**
  21.      * @Template
  22.      * @param Request $request
  23.      * @return array
  24.      */
  25.     public function defaultAction(Request $request)
  26.     {
  27.         return [];
  28.     }
  29.     /**
  30.      * @Route("/news/reader", name="news_reader")
  31.      * @Route("/news/reader/{requestDate}", name="news_reader_date")
  32.      * @Template(template="views/newsReader.html.twig")
  33.      */
  34.     public function newsReaderAction(Request $request$requestDate '') {
  35.         $today Carbon::now();
  36.         $dayStart Carbon::parse(($requestDate $requestDate 'today') . ' at 00:00:00');
  37.         $dayEnd Carbon::parse(($requestDate $requestDate 'today') . ' at 23:59:59');
  38.         $news = new DataObject\News\Listing();
  39.         $news->setOrderKey('articleDate');
  40.         $news->setOrder('desc');
  41.         $news->setCondition('o_published = 1 and (articleDate between :dateStart and :dateEnd)', [
  42.             'dateStart' => $dayStart->getTimestamp(),
  43.             'dateEnd' => $dayEnd->getTimestamp()
  44.         ]);
  45.         $news->load();
  46.         $results $news->getObjects();
  47.         $nextDay $dayEnd->copy()->addMonth();
  48.         if ($nextDay->gt($today)) {
  49.             $nextDay $today;
  50.         }
  51.         $prevDay $dayStart->copy()->subMonth();
  52.         $newsDays = new DataObject\News\Listing();
  53.         $newsDays->setOrderKey('articleDate');
  54.         $newsDays->setOrder('desc');
  55.         $newsDays->setCondition('o_published = 1 and (articleDate between :dateStart and :dateEnd)', [
  56.             'dateStart' => $prevDay->getTimestamp(),
  57.             'dateEnd' => $nextDay->getTimestamp()
  58.         ]);
  59.         // for loop from nextDayStart day to prevDayEnd day
  60.         $days = [];
  61.         foreach ($newsDays->load() as $newsDay) {
  62.             $day intval($newsDay->getArticleDate()->format('Ymd'));
  63.             if (!isset($days[$day])) {
  64.                 $days[$day] = [ 'count' => 0'date' => $newsDay->getArticleDate() ];
  65.             }
  66.             $days[$day]['count']++;
  67.         }
  68.         return [
  69.             'currentDate' => $dayStart,
  70.             'news' => $results,
  71.             'days' => $days
  72.         ];
  73.     }
  74.     /**
  75.      * @Route("/news/{path}", name="news_detail")
  76.      * @Template(template="views/newsDetail.html.twig")
  77.      */
  78.     public function newsDetailAction(Request $request$path)
  79.     {
  80.         $listing = new DataObject\News\Listing();
  81.         $news $listing->filterByKey($path);
  82.         if ($news->getCount() === 0) {
  83.             throw $this->createNotFoundException('nichts gefunden :(');
  84.         } else {
  85.             $dataObject $news->getObjects()[0];
  86.             $tags self::getTagsForElement('object'$dataObject->getId());
  87.             return [
  88.                 'dataObject' => $news->getObjects()[0],
  89.                 'tags' => $tags
  90.             ];
  91.         }
  92.     }
  93.     /**
  94.      * @Route("/veranstaltungen/{path}", name="event_detail")
  95.      * @Template(template="views/eventDetail.html.twig")
  96.      */
  97.     public function eventDetailAction(Request $request$path)
  98.     {
  99.         $listing = new DataObject\Event\Listing();
  100.         $events $listing->filterByKey($path);
  101.         if ($events->getCount() === 0) {
  102.             throw $this->createNotFoundException('nichts gefunden :(');
  103.         } else {
  104.             /** @var DataObject\Event $event */
  105.             $event $events->getObjects()[0];
  106.             $otherDates = [];
  107.             $otherDates[] = [
  108.                 "dateStart" => $event->getDateStart(),
  109.                 "dateEnd" => $event->getDateEnd()
  110.             ];
  111.             if ($event->getOtherDates()) {
  112.                 /** @var DataObject\Fieldcollection\Data\EventDates $otherDate */
  113.                 foreach ($event->getOtherDates() as $otherDate) {
  114.                     $otherDates[] = [
  115.                         "dateStart" => $otherDate->getDateStart(),
  116.                         "dateEnd" => $otherDate->getDateEnd()
  117.                     ];
  118.                 }
  119.             }
  120.             usort($otherDates, function ($a$b): int {
  121.                 return [$a['dateStart']] <=> [$b['dateStart']];
  122.             });
  123.             return [
  124.                 'dataObject' => $event,
  125.                 'otherDates' => $otherDates
  126.             ];
  127.         }
  128.     }
  129.     /**
  130.      * @Route("/jobportal/anzeige/{customerPath}/{path}", name="job_offer_detail")
  131.      * @Template(template="views/jobportal/jobOfferDetail.html.twig")
  132.      */
  133.     public function jobOfferDetailAction(Request $request$customerPath$path)
  134.     {
  135.         $listing = new DataObject\JobOffer\Listing();
  136.         $listing->filterByKey($path);
  137.         $jobCategory null;
  138.         /** @var DataObject\JobOffer $jobOffer */
  139.         $jobOffer null;
  140.         foreach ($listing->getObjects() as $offer){
  141.             if(!empty($offer->getJobCustomer()) && $offer->getJobCustomer()[0]->getKey() == $customerPath){
  142.                 $jobOffer $offer;
  143.             }
  144.         }
  145.         if ($jobOffer == null && !empty($listing->getObjects())) {
  146.             $jobOffer $listing->getObjects()[0];
  147.         }
  148.         if ($jobOffer == null){
  149.             throw $this->createNotFoundException('nichts gefunden :(');
  150.         }
  151.         $jobOfferAdditionalData null;
  152.         if($jobOffer->getJobCustomer()){
  153.             $jobOfferAdditionalData $this->getAdditionalOffersData($jobOffer->getJobCustomer()[0], $jobOffer->getId());
  154.         }
  155.         return [
  156.             'dataObject' => $jobOffer,
  157.             'additionalJobOffers' => $jobOfferAdditionalData
  158.         ];
  159.     }
  160.     /**
  161.      * @Route("/jobportal/firma/{path}", name="job_customer_detail")
  162.      * @Template(template="views/jobportal/jobCustomerDetail.html.twig")
  163.      */
  164.     public function jobCustomerAction(Request $request$path)
  165.     {
  166.         $listing = new DataObject\JobCustomer\Listing();
  167.         $jobCustomers $listing->filterByKey($path);
  168.         /** @var DataObject\JobCustomer $jobCustomer */
  169.         $jobCustomer $jobCustomers->getObjects()[0];
  170.         $jobOfferAdditionalData $this->getAdditionalOffersData($jobCustomer);
  171.         return [
  172.             'dataObject' => $jobCustomer,
  173.             'additionalJobOffers' => $jobOfferAdditionalData,
  174.         ];
  175.     }
  176.     /**
  177.      * @Route("/aktionen/aktion/{path}", name="action_detail")
  178.      * @Template(template="views/actionDetail.html.twig")
  179.      */
  180.     public function actionDetailAction(Request $request$path)
  181.     {
  182.         $listing = new DataObject\Action\Listing();
  183.         $actions $listing->filterByKey($path);
  184.         return [
  185.             'dataObject' => $actions->getObjects()[0],
  186.         ];
  187.     }
  188.     /**
  189.      * @Route("/themen", name="thema")
  190.      * @Template(template="views/thema.html.twig")
  191.      */
  192.     public function themaAction(Request $request)
  193.     {
  194.         $bereichListing = new DataObject\ThemaBereich\Listing();
  195.         $bereiche = [];
  196.         $otherBereiche = [];
  197.         $folder null;
  198.         /** @var DataObject\ThemaBereich $bereich */
  199.         foreach ($bereichListing->getObjects() as $bereich) {
  200.             if ($bereich->getParent()->getType() === 'folder') {
  201.                 if (!$folder) {
  202.                     $folder $bereich->getParent();
  203.                 }
  204.                 $condition = [];
  205.                 $conditionParams = [];
  206.                 $condition[] = "articleDate < ?";
  207.                 $conditionParams[] = Carbon::now()->getTimestamp();
  208.                 $bereichIds = [$bereich->getId()];
  209.                 /** @var DataObject\ThemaBereich $subBereich */
  210.                 foreach ($bereich->getChildren() as $subBereich) {
  211.                     $bereichIds[] = $subBereich->getId();
  212.                 }
  213.                 $bereichCondition = [];
  214.                 foreach ($bereichIds as $bereichId) {
  215.                     $bereichCondition[] = "bereiche LIKE ?";
  216.                     $conditionParams[] = "%," $bereichId ",%";
  217.                 }
  218.                 $condition[] = '(' join(' OR '$bereichCondition) . ')';
  219.                 $bereichListing = new DataObject\ThemaArtikel\Listing();
  220.                 $bereichListing->setOrderKey('articleDate');
  221.                 $bereichListing->setOrder('desc');
  222.                 $bereichListing->setLimit(9);
  223.                 $bereichListing->setCondition(join(' AND '$condition), $conditionParams);
  224.                 $articles $bereichListing->getObjects();
  225.                 $data = [
  226.                     "order" => 0,
  227.                     "bereich" => $bereich,
  228.                     "articles" => $articles
  229.                 ];
  230.                 $bereiche[] = $data;
  231.             }
  232.         }
  233.         // get folder sort order
  234.         $i 0;
  235.         foreach ($folder->getChildren() as $child) {
  236.             $i++;
  237.             foreach ($bereiche as $index => $bereich) {
  238.                 if ($bereich["bereich"]->getId() === $child->getId()) {
  239.                     $bereiche[$index]["order"] = $i;
  240.                 }
  241.             }
  242.         }
  243.         usort($bereiche, function ($a$b) {
  244.             return $a['order'] - $b['order'];
  245.         });
  246. //        echo "<pre>";
  247. //        var_dump($bereiche);
  248. //        die();
  249.         return [
  250.             'error' => count($bereiche) === 0,
  251.             'bereiche' => $bereiche
  252.         ];
  253.     }
  254.     /**
  255.      * @Route("/themen/{path}", name="thema_bereich")
  256.      * @Template(template="views/themaOverview.html.twig")
  257.      */
  258.     public function themaOverviewAction(Request $request$path)
  259.     {
  260.         $bereich = new DataObject\ThemaBereich\Listing();
  261.         $condition = [];
  262.         $conditionParams = [];
  263.         $listing = new DataObject\ThemaArtikel\Listing();
  264.         $listing->setOrderKey('articleDate');
  265.         $listing->setOrder('desc');
  266.         $condition[] = "articleDate < ?";
  267.         $conditionParams[] = Carbon::now()->getTimestamp();
  268.         $bereich->filterByKey($path);
  269.         $found $bereich->getObjects();
  270.         $actions = [];
  271.         $otherBereiche = [];
  272.         if (count($found) > 0) {
  273. //            $condition[] = "bereiche in (:bereiche)";
  274. //            $conditionParams["bereiche"] = [$found[0]->getId()];
  275.             $listing->setCondition(join(' AND '$condition), $conditionParams);
  276.             $actions $listing->filterByBereiche($found[0]->getId())->getObjects();
  277.             foreach ($found[0]->getChildren() as $child) {
  278.                 $condition = [];
  279.                 $conditionParams = [];
  280.                 $condition[] = "articleDate < ?";
  281.                 $conditionParams[] = Carbon::now()->getTimestamp();
  282.                 $bereichListing = new DataObject\ThemaArtikel\Listing();
  283.                 $bereichListing->setOrderKey('articleDate');
  284.                 $bereichListing->setOrder('desc');
  285.                 $bereichListing->setLimit(3);
  286.                 $bereichListing->setCondition(join(' AND '$condition), $conditionParams);
  287.                 $articles $bereichListing->filterByBereiche($child->getId())->getObjects();
  288.                 $data = [
  289.                   "bereich" => $child,
  290.                   "articles" => $articles
  291.                 ];
  292.                 $otherBereiche[$child->getId()] = $data;
  293.             }
  294.         }
  295. //        echo "<pre>";
  296. //        var_dump($found[0]->getChildren());
  297. //        die();
  298.         return [
  299.             'error' => count($found) === 0,
  300.             'bereich' => count($found) > $found[0] : '',
  301.             'bereiche' => $otherBereiche,
  302.             'articles' => $actions,
  303.         ];
  304.     }
  305.     public function themaLatest(): Response
  306.     {
  307.         $listing = new DataObject\ThemaArtikel\Listing();
  308.         $listing->setOrderKey('articleDate');
  309.         $listing->setOrder('desc');
  310.         $listing->setLimit(5);
  311.         $condition = [];
  312.         $conditionParams = [];
  313.         $condition[] = "articleDate < ?";
  314.         $conditionParams[] = Carbon::now()->getTimestamp();
  315.         $listing->setCondition(join(' AND '$condition), $conditionParams);
  316.         return $this->render('includes/themenLatest.html.twig', [
  317.             'articles' => $listing->load()
  318.         ]);
  319.     }
  320.     /**
  321.      * @Route("/themen/artikel/{path}", name="thema_detail")
  322.      * @Template(template="views/themaDetail.html.twig")
  323.      */
  324.     public function themaDetailAction(Request $request$path)
  325.     {
  326.         $listing = new DataObject\ThemaArtikel\Listing();
  327.         $entries $listing->filterByKey($path)->getObjects();
  328.         $entry null;
  329.         $others = [];
  330.         $ids = [];
  331.         if ($request->get('pimcore_object_preview')) {
  332.             $entry DataObject\ThemaArtikel::getById($request->get('pimcore_object_preview'), true);
  333.         } elseif (count($entries) > 0) {
  334.             $entry $entries[0];
  335.             $ids[] = $entry->getId();
  336.             $otherListing = new DataObject\ThemaArtikel\Listing();
  337.             $otherListing->setCondition(join(' AND ', ['articleDate <= ?''o_id != ?']), [Carbon::now()->getTimestamp(), $entry->getId()]);
  338.             $otherListing->filterByBereiche($entry->getBereiche()[0]->getId());
  339.             $otherListing->setLimit(6);
  340.             $otherListing->setOrderKey('RAND()'false);
  341.             $others $otherListing->getObjects();
  342.             if (count($others) < 6) {
  343.                 foreach ($others as $other) {
  344.                     $ids[] = $other->getId();
  345.                 }
  346.                 $additionalListing = new DataObject\ThemaArtikel\Listing();
  347.                 $additionalListing->setCondition(join(' AND ', ['articleDate <= ?''o_id not in (?)']), [Carbon::now()->getTimestamp(), $ids]);
  348.                 $additionalListing->setLimit(count($others));
  349.                 $additionalListing->setOrderKey('RAND()'false);
  350.                 $others array_merge($others$additionalListing->getObjects());
  351.             }
  352.         }
  353.         return [
  354.             'dataObject' => $entry,
  355.             'others' => $others
  356.         ];
  357.     }
  358.     /**
  359.      * @Route("/branchenverzeichnis/firma/{path}", name="branchen_customer_detail")
  360.      * @Template(template="views/branchenportal/branchenCustomerDetail.html.twig")
  361.      */
  362.     public function branchenCustomerAction(Request $request$path)
  363.     {
  364.         $listing = new DataObject\BranchenCustomer\Listing();
  365.         $branchenCustomers $listing->filterByKey($path);
  366.         /** @var DataObject\BranchenCustomer $branchenCustomer */
  367.         $branchenCustomer $branchenCustomers->getObjects()[0];
  368.         return [
  369.             'dataObject' => $branchenCustomer,
  370.         ];
  371.     }
  372.     public function photoboothOverviewAction(Request $request) {
  373.         $event $request->get('event'null);
  374.         $slugger = new AsciiSlugger();
  375.         $tomorrow Carbon::parse('tomorrow');
  376.         $listing = new DataObject\Photobooth\Listing();
  377.         $listing->setOrderKey('eventDate');
  378.         $listing->setOrder('desc');
  379.         $entries = [];
  380.         $eventObject null;
  381.         foreach ($listing as $entry) {
  382.             // get asset folder /Photobooth/{entry.key}
  383.             $images = [];
  384.             $folders = [$entry->getKey(), $slugger->slug($entry->getKey(), '.')];
  385.             foreach ($folders as $folderName) {
  386.                 $folder Asset\Folder::getByPath('/Photobooth/' $folderName);
  387.                 if ($folder) {
  388.                     if ($folder->getChildren()) {
  389.                         foreach ($folder->getChildren() as $image) {
  390.                             $images[$image->getCreationDate()] = $image;
  391.                         }
  392.                         krsort($images);
  393.                     }
  394.                     $entries[] = [
  395.                         'event' => $entry,
  396.                         'hide' => $entry->getHide(),
  397.                         'path' => '/Photobooth/' $folderName,
  398.                         'images' => $images
  399.                     ];
  400.                 }
  401.             }
  402.             if ($entry->getKey() === $event) {
  403.                 $eventObject end($entries);
  404.             }
  405.         }
  406.         return $this->render('views/photobooth/overview.html.twig', [
  407.             'entries' => $entries,
  408.             'event' => $event,
  409.             'eventObject' => $eventObject
  410.         ]);
  411.     }
  412.     /**
  413.      * @Route("/sport/{sportType}", name="sport_type_overview")
  414.      * @Template(template="views/sport/sportType.html.twig")
  415.      */
  416.     public function sportTypeAction(Request $request$sportType)
  417.     {
  418.         $listing = new DataObject\SportType\Listing();
  419.         $type $listing->filterByKey($sportType);
  420.         /** @var DataObject\SportType $sportTypeObject */
  421.         $results $type->getObjects();
  422.         $sportTypeObject count($results) > $results[0] : null;
  423.         return [
  424.             'dataObject' => $sportTypeObject,
  425.         ];
  426.     }
  427.     /**
  428.      * @Route("/preview/app-banner/{bannerId}", name="app_banner_preview")
  429.      * @Template(template="views/preview/appBanner.html.twig")
  430.      */
  431.     public function appBannerPreviewAction(Request $request$bannerId)
  432.     {
  433.         $context json_decode($request->get("context"), true);
  434.         $banner Service::getElementFromSession('object'$bannerId);
  435.         return ['banner' => $banner];
  436.     }
  437.     /**
  438.      * @Route("/app-link/news/{newsId}", name="app_link_news")
  439.      */
  440.     public function appLinkNewsAction(Request $request$newsId)
  441.     {
  442.         // If the app is installed, this URL is linked directly into the app by the OS,
  443.         // if it is not, we redirect to the respective content on the web.
  444.         $article DataObject\News::getById($newsId);
  445.         if ($article) {
  446.             return $this->redirectToRoute('news_detail', ['path' => $article->getKey()]);
  447.         }
  448.         return $this->redirect('https://boa.bayern');
  449.     }
  450.     /**
  451.      * @Route("/app-link/event/{eventId}", name="app_link_event")
  452.      */
  453.     public function appLinkEventAction(Request $request$newsId)
  454.     {
  455.         // If the app is installed, this URL is linked directly into the app by the OS,
  456.         // if it is not, we redirect to the respective content on the web.
  457.         $event DataObject\Event::getById($newsId);
  458.         if ($event) {
  459.             return $this->redirectToRoute('event_detail', ['path' => $event->getKey()]);
  460.         }
  461.         return $this->redirect('https://boa.bayern');
  462.     }
  463.     /**
  464.      * @Route("/app-link/{path}", name="app_link_default", requirements={"path"=".+"}, priority=-1)
  465.      */
  466.     public function appLinkDefaultAction(Request $request$path)
  467.     {
  468.         // Fallback for any deeplinks we do not know
  469.         return $this->redirect('https://boa.bayern');
  470.     }
  471.     protected function getAdditionalOffersData($jobCustomer$jobId null){
  472.         $jobOfferData = [];
  473.         foreach ($jobCustomer->getJobOffers() as $offer){
  474.             $jobCategory null;
  475.             $jobKey 'firma';
  476.             if(!empty($offer->getJobCustomer())){
  477.                 $jobKey $offer->getJobCustomer()[0]->getKey();
  478.             }
  479.             $link $this->generateUrl('job_offer_detail', ['customerPath' => $jobKey'path' => $offer->getKey()]);
  480.             $dateDiffer abs($offer->getDatePublished()->getTimestamp() - time());
  481.             $days round(($dateDiffer/ (60 60 24)));
  482.             if ($days == 1) {
  483.                 $days 'vor 1 Tag';
  484.             } elseif ($days == 0) {
  485.                 $days 'heute';
  486.             } else {
  487.                 $days 'vor '.$days.' Tagen';
  488.             }
  489.             $catData = [];
  490.             foreach ($offer->getJobCategories() as $cat){
  491.                 $catData[] = [
  492.                     "id" => $cat->getId(),
  493.                     "title" => $cat->getTitle()
  494.                 ];
  495.                 if($cat->getTitle() == "Ausbildung"){
  496.                     $jobCategory = ["id" => $cat->getId(), "title" => $cat->getTitle()];
  497.                 }
  498.             }
  499.             if($offer->getId() != $jobId){
  500.                 $jobOfferData[] = [
  501.                     "jobCustomer" => $offer->getJobCustomer(),
  502.                     "jobCategory" => $jobCategory,
  503.                     "jobLocation" => $offer->getJobLocation(),
  504.                     "jobLocationTitle" => $offer->getJobLocation() ? $offer->getJobLocation()->getTitle() : '',
  505.                     "id" => $offer->getId(),
  506.                     "title" => $offer->getTitle(),
  507.                     "description" => $offer->getDescription(),
  508.                     //"image" => ($offer->getImage() ? $offer->getImage()->getThumbnail('website')->getHtml() : null),
  509.                     "datePublished" => $offer->getDatePublished(),
  510.                     "published" => $offer->getPublished(),
  511.                     "big" => $offer->getBig(),
  512.                     "jobCustomerLogo" => ($offer->getJobCustomer() ? $offer->getJobCustomer()[0]->getLogo()->getThumbnail()->getHtml() : null),
  513.                     "jobCustomerKey" => ($offer->getJobCustomer() ? $offer->getJobCustomer()[0]->getKey() : null),
  514.                     //"highlight" => $article->getHighlight(),
  515.                     "creationDate" => date("c"$offer->getCreationDate()),
  516.                     "modificationDate" => date("c"$offer->getModificationDate()),
  517.                     "class" => 'md:w-6/12 lg:w-3/12',
  518.                     "contentClass" => 'w-full',
  519.                     /*"class" => ($offer->getImage() ? 'lg:w-6/12' : 'lg:w-3/12'),
  520.                     "contentClass" => ($offer->getImage() ? 'w-6/12' : 'w-full'),*/
  521.                     "key" => $offer->getKey(),
  522.                     "link" => $link,
  523.                     "days" => $days,
  524.                 ];
  525.             }
  526.         }
  527.         return $jobOfferData;
  528.     }
  529.     /**
  530.      * returns all assigned tags for element
  531.      *
  532.      * @param string $cType
  533.      * @param int $cId
  534.      * @return Tag[]
  535.      */
  536.     public static function getTagsForElement($cType$cId)
  537.     {
  538.         $tag = new Tag();
  539.         return $tag->getDao()->getTagsForElement($cType$cId);
  540.     }
  541.     /**
  542.      * @Template(template="includes/tags.html.twig")
  543.      */
  544.     public function renderTagsForElement(Request $request$cType$cId)
  545.     {
  546.         $tags self::getTagsForElement($cType$cId);
  547.         return [
  548.             'tags' => $tags
  549.         ];
  550.     }
  551. }