src/Controller/ContentController.php line 128

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Services\CheckwebsitesettingService;
  4. use App\Services\GeneralSendMailService;
  5. use MultilingualBundle\Service\DocumentLookupService;
  6. use Pimcore\Controller\FrontendController;
  7. use Pimcore\Model\DataObject;
  8. use Pimcore\Translation\Translator;
  9. use Symfony\Component\HttpFoundation\Request;
  10. use Symfony\Component\HttpFoundation\Response;
  11. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
  12. use Symfony\Component\Routing\Annotation\Route;
  13. use FtpClient\FtpClient;
  14. class ContentController extends BaseController
  15. {
  16.     protected $checkwebsitesettingService;
  17.     protected $inotherlang;
  18.     public function __construct(CheckwebsitesettingService $checkwebsitesettingServiceDocumentLookupService $inotherlang){
  19.         $this->checkwebsitesettingService $checkwebsitesettingService;
  20.         $this->inotherlang $inotherlang;
  21.     }
  22.     /**
  23.      * @Template
  24.      * @param Request $request
  25.      * @return array
  26.      */
  27.     public function defaultAction(Request $request)
  28.     {
  29.         // check if Type is page, snippet, email
  30. //        if($request->get('type') == 'snippet' || $request->get('type') == 'email'){
  31. //            // Change controller
  32. //            /** @var \Pimcore\Model\Document $document */
  33. //            $document = $this->document;
  34. //
  35. //            $document->save();
  36. //        }
  37. //        $documentInfo = $this->document;
  38. //
  39. //        print_r($documentInfo->getProperty('language'));
  40. //        print_r($documentInfo);
  41. //        die();
  42.         return [];
  43.     }
  44.     /**
  45.      * @param Request $request
  46.      *
  47.      * @return Response
  48.      */
  49.     public function homepageAction(Request $request)
  50.     {
  51.         $currentLanguage $request->attributes->get('_locale');
  52.         // Load Groups
  53.         $groupList = new DataObject\ProductGroup\Listing();
  54.         $groupList->setOrderKey(['orderList''oms']);
  55.         $groupList->setOrder('asc');
  56.         $groupList->setCondition("visible = :visible", ["visible" => "1"]); // Only visible on website
  57.         // only show required groups
  58.         $groupListGroups = [];
  59.         /** @var \Pimcore\Model\DataObject\ProductGroup $group */
  60.         foreach($groupList as $group){
  61.             $dependencies $group->getDependencies();
  62.             $requiredBy $dependencies->getRequiredBy();
  63.             if(!$requiredBy){
  64.                 $groupListGroups[] = $group;
  65.             }
  66.         }
  67.         // Load Promotion Articles
  68.         $productList = new DataObject\ProductArticle\Listing();
  69.         $productList->setCondition("promotion = :promotion", ["promotion" => '1']);
  70.         // Load News
  71.         if ($this->checkwebsitesettingService->check("news_document""document")) {
  72.             $getNewsPage \Pimcore\Model\WebsiteSetting::getByName("news_document");
  73.             $getNewsConfig $getNewsPage->getData();
  74.             $newsPage $this->inotherlang->getLocalizedDocument($getNewsConfig$currentLanguage);
  75.         }
  76.         if($newsPage){
  77.             $requestPage 0;
  78.             $requestArticles 3;
  79.             $news = [];
  80.             $getchildNewsDocs $newsPage->getChildren();
  81.             if($getchildNewsDocs){
  82.                 foreach ($getchildNewsDocs as $getchildNewsDoc){
  83.                     if($getchildNewsDoc->getEditable('publicationDate') != ''){
  84.                         $childTimeStamp $getchildNewsDoc->getEditable('publicationDate')->getData()->timestamp;
  85.                     }
  86.                     $news[$childTimeStamp.'-'.$getchildNewsDoc->getId()] = $getchildNewsDoc;
  87.                 }
  88.             }
  89.             krsort($news);
  90.             $news array_slice($news$requestPage$requestArticles);
  91.         }
  92.         // Load Over-ons
  93.         if ($this->checkwebsitesettingService->check("overons_document""document")) {
  94.             $getOverOnsPage \Pimcore\Model\WebsiteSetting::getByName("overons_document");
  95.             $getOverOnsPageConfig $getOverOnsPage->getData();
  96.             $overOnsPage $this->inotherlang->getLocalizedDocument($getOverOnsPageConfig$currentLanguage);
  97.         }
  98.         if($overOnsPage){
  99.             if($overOnsPage->hasChildren()) {
  100.                 $getchildOverOnsDocs $overOnsPage->getChildren();
  101.             }
  102.         }
  103.         return $this->render('content/homepage.html.twig',[
  104.             "productsGroups" => $groupListGroups,
  105.             "overons" => $getchildOverOnsDocs,
  106.             "productPromotion" => $productList,
  107.             "news" => $news
  108.         ]);
  109.     }
  110. }