src/Controller/BusinessPartnerController.php line 25

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use Pimcore\Controller\FrontendController;
  4. use Symfony\Component\HttpFoundation\Request;
  5. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
  6. use Symfony\Component\Routing\Annotation\Route;
  7. use Pimcore\Model\DataObject;
  8. use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
  9. use Pimcore\Model\Asset;
  10. use Pimcore\Model\DataObject\Folder;
  11. use Doctrine\Persistence\ManagerRegistry;
  12. class BusinessPartnerController extends FrontendController
  13. {
  14.     /**
  15.      * @Route({
  16.      *     "de": "/de/login",
  17.      *     "en": "/en/login",
  18.      *     "hu": "/hu/login"
  19.      * }, name="secure_login")
  20.      */
  21.     public function loginAction(Request $requestAuthenticationUtils $authenticationUtils)
  22.     {
  23.         // get the login error if there is one
  24.         $error $authenticationUtils->getLastAuthenticationError();
  25.         // last username entered by the user
  26.         $lastUsername $authenticationUtils->getLastUsername();
  27.         if ($this->isGranted('IS_AUTHENTICATED_FULLY')) {
  28.             return $this->redirectToRoute('business_partner');
  29.         }
  30.         return $this->render('businesspartner/login.html.twig', [
  31.             'error' => $error,
  32.             'lastUsername' => $lastUsername
  33.         ]);
  34.     }
  35.     /**
  36.      * @Route({
  37.      *     "de": "/de/logout",
  38.      *     "en": "/en/logout",
  39.      *     "hu": "/hu/logout"
  40.      * }, name="secure_logout")
  41.      */
  42.     public function logoutAction(Request $request)
  43.     {
  44.     }
  45.     /**
  46.      * @Route({
  47.      *     "de": "/de/business-partner",
  48.      *     "en": "/en/business-partner",
  49.      *     "hu": "/hu/business-partner"
  50.      * }, name="business_partner")
  51.      */
  52.     public function indexAction(Request $request\Pimcore\Config\Config $websiteConfig)
  53.     {
  54.         $user $this->getUser();
  55.         if (!$user) {
  56.             return $this->redirectToRoute("secure_login");
  57.         }
  58.         $name $user->getName();
  59.         $news_limit 4;
  60.         $events_limit 4;
  61.         $downloads_limit 4;
  62.         $listing = new DataObject\News\Listing();
  63.         $listing->setCondition("title != ''");
  64.         $listing->addConditionParam("o_path = '/bp-news/'");
  65.         $listing->setOrderKey(['date''o_creationDate']);
  66.         $listing->setOrder("DESC");
  67.         $listing->setLimit($news_limit);
  68.         $news $listing->load();
  69.         $listing = new DataObject\Events\Listing();
  70.         $listing->setCondition("title != ''");
  71.         $listing->addConditionParam("o_path = '/bp-events/'");
  72.         $listing->setOrderKey(['dateStart''o_creationDate']);
  73.         $listing->setOrder("DESC");
  74.         $listing->setLimit($events_limit);
  75.         $events $listing->load();
  76.         /*$listing = new DataObject\Downloads\Listing();
  77.         $listing->setCondition("title != ''");
  78.         $listing->addConditionParam("o_path = '/bp-downloads/'");
  79.         $listing->setOrderKey('o_creationDate');
  80.         $listing->setOrder("DESC");
  81.         $listing->setLimit($downloads_limit);
  82.         $downloads = $listing->load();*/
  83.         return $this->render('businesspartner/index.html.twig', [
  84.             'name' => $name,
  85.             'news' => $news,
  86.             'events' => $events,
  87.         ]);
  88.     }
  89.     /**
  90.      * @Route({
  91.      *     "de": "/de/business-partner/news",
  92.      *     "en": "/en/business-partner/news",
  93.      *     "hu": "/hu/business-partner/news"
  94.      * }, name="business_partner_news")
  95.      */
  96.     public function newsAction(Request $request\Pimcore\Config\Config $websiteConfig)
  97.     {
  98.         $user $this->getUser();
  99.         if (!$user) {
  100.             return $this->redirectToRoute("secure_login");
  101.         }
  102.         $name $user->getName();
  103.         $listing = new DataObject\News\Listing();
  104.         $listing->setCondition("title != ''");
  105.         $listing->addConditionParam("o_path = '/bp-news/'");
  106.         $listing->setOrderKey(['date''o_creationDate']);
  107.         $listing->setOrder("DESC");
  108.         $news $listing->load();
  109.         return $this->render('businesspartner/news.html.twig', [
  110.             'name' => $name,
  111.             'news' => $news
  112.         ]);
  113.     }
  114.     /**
  115.      * @Route({
  116.      *     "de": "/de/business-partner/news/{key}",
  117.      *     "en": "/en/business-partner/news/{key}",
  118.      *     "hu": "/hu/business-partner/news/{key}"
  119.      * }, name="business_partner_news_detail")
  120.      */
  121.     public function newsDetailAction($keyRequest $request\Pimcore\Config\Config $websiteConfig)
  122.     {
  123.         $user $this->getUser();
  124.         if (!$user) {
  125.             return $this->redirectToRoute("secure_login");
  126.         }
  127.         $name $user->getName();
  128.         $listing = new DataObject\News\Listing();
  129.         $listing->setCondition("title != ''");
  130.         $listing->addConditionParam("o_key = '" $key "'");
  131.         $listing->addConditionParam("o_path = '/bp-news/'");
  132.         $news $listing->load()[0];
  133.         if (!$news) {
  134.             return $this->redirectToRoute("business_partner_news");
  135.         }
  136.         return $this->render('businesspartner/news_detail.html.twig', [
  137.             'name' => $name,
  138.             'n' => $news
  139.         ]);
  140.     }
  141.     /**
  142.      * @Route({
  143.      *     "de": "/de/business-partner/events",
  144.      *     "en": "/en/business-partner/events",
  145.      *     "hu": "/hu/business-partner/events"
  146.      * }, name="business_partner_events")
  147.      */
  148.     public function eventsAction(Request $request\Pimcore\Config\Config $websiteConfig)
  149.     {
  150.         $user $this->getUser();
  151.         if (!$user) {
  152.             return $this->redirectToRoute("secure_login");
  153.         }
  154.         $name $user->getName();
  155.         $listing = new DataObject\Events\Listing();
  156.         $listing->setCondition("title != ''");
  157.         $listing->addConditionParam("o_path = '/bp-events/'");
  158.         $listing->setOrderKey(['dateStart''o_creationDate']);
  159.         $listing->setOrder("DESC");
  160.         $events $listing->load();
  161.         return $this->render('businesspartner/events.html.twig', [
  162.             'name' => $name,
  163.             'events' => $events
  164.         ]);
  165.     }
  166.     /**
  167.      * @Route({
  168.      *     "de": "/de/business-partner/events/{key}",
  169.      *     "en": "/en/business-partner/events/{key}",
  170.      *     "hu": "/hu/business-partner/events/{key}"
  171.      * }, name="business_partner_events_detail")
  172.      */
  173.     public function eventsDetailAction($keyRequest $request\Pimcore\Config\Config $websiteConfig)
  174.     {
  175.         $user $this->getUser();
  176.         if (!$user) {
  177.             return $this->redirectToRoute("secure_login");
  178.         }
  179.         $name $user->getName();
  180.         $listing = new DataObject\Events\Listing();
  181.         $listing->setCondition("title != ''");
  182.         $listing->addConditionParam("o_key = '" $key "'");
  183.         $listing->addConditionParam("o_path = '/bp-events/'");
  184.         $event $listing->load()[0];
  185.         if (!$event) {
  186.             return $this->redirectToRoute("business_partner_events");
  187.         }
  188.         return $this->render('businesspartner/events_detail.html.twig', [
  189.             'name' => $name,
  190.             'e' => $event,
  191.             'key' => $key
  192.         ]);
  193.     }
  194.     /**
  195.      * @Route({
  196.      *     "de": "/de/business-partner/downloads",
  197.      *     "en": "/en/business-partner/downloads",
  198.      *     "hu": "/hu/business-partner/downloads"
  199.      * }, name="business_partner_download_categories")
  200.      */
  201.     public function downloadCategoriesAction(Request $request\Pimcore\Config\Config $websiteConfig)
  202.     {
  203.         $user $this->getUser();
  204.         if (!$user) {
  205.             return $this->redirectToRoute("secure_login");
  206.         }
  207.         $name $user->getName();
  208.         $categoryImage Asset::getByPath('/bp-portal/istockphoto-1193926746-1024x1024.jpg');
  209.         $test Folder::getByPath('/bp-downloads/');
  210.         $categories = [];
  211.         foreach ($test->getChildren() as $subfolder) {
  212.             if ($subfolder->getType() == "folder") {
  213.                 $tmp = [];
  214.                 $tmp["name"] = $subfolder->getKey();
  215.                 $tmp["image"] = "empty";
  216.                 if ($categoryImage)
  217.                  $tmp["image"] = $categoryImage->getThumbnail("default");
  218.                 $categories[] = $tmp;
  219.             }
  220.         }
  221.         return $this->render('businesspartner/download_categories.html.twig', [
  222.             'name' => $name,
  223.             'categories' => $categories
  224.         ]);
  225.     }
  226.     /**
  227.      * @Route({
  228.      *     "de": "/de/business-partner/downloads/{category}",
  229.      *     "en": "/en/business-partner/downloads/{category}",
  230.      *     "hu": "/hu/business-partner/downloads/{category}"
  231.      * }, name="business_partner_downloads")
  232.      */
  233.     public function downloadsAction($categoryRequest $request\Pimcore\Config\Config $websiteConfigManagerRegistry $managerRegistry)
  234.     {
  235.        // $managerRegistry
  236.         $user $this->getUser();
  237.         if (!$user) {
  238.             return $this->redirectToRoute("secure_login");
  239.         }
  240.         $name $user->getName();
  241.         // Downloads nur auf EN
  242.         $request->setLocale("en");
  243.         //todo $this->get('translator')->setLocale('en');
  244.         $listing = new DataObject\Downloads\Listing();
  245.         //$listing->setCondition("title != ''");
  246.         $listing->addConditionParam("o_path = '/bp-downloads/" $category "/'");
  247.         $listing->setOrderKey('o_creationDate');
  248.         $listing->setOrder("DESC");
  249.         $downloads $listing->load();
  250.         return $this->render('businesspartner/downloads.html.twig', [
  251.             'name' => $name,
  252.             'downloads' => $downloads,
  253.             'category' => $category
  254.         ]);
  255.     }
  256. }