src/Controller/PortfolioguideController.php line 129

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. /**
  4.  * The core controller for Portfolioguide Portal
  5.  * 
  6.  * Login session criteria to be declared
  7.  *
  8.  * PHP version 5.3
  9.  *
  10.  * @category  Portfolio_Guide
  11.  * @package   PortfolioGuide
  12.  * @author    TCS Beam Suntory
  13.  * @copyright TCS Beam Suntory
  14.  * @license   
  15.  * @link
  16.  */
  17. /**
  18.  * The core controller for Portfolioguide Portal
  19.  */
  20. use Pimcore\Controller\FrontendController;
  21. use Pimcore\Model\DataObject;
  22. use Pimcore\Mail;
  23. use Pimcore\Model\Search\Backend\Data;
  24. use Symfony\Component\HttpFoundation\Request;
  25. use Symfony\Component\HttpKernel\Event\FilterControllerEvent;
  26. use Symfony\Component\Intl\Intl;
  27. // class PortfolioguideController extends \Website\Controller\Action
  28. class PortfolioguideController extends Action
  29. {
  30.     public $countryId;
  31.     public $countryObj;
  32.     /**
  33.      * Init function in which the cookie based authentication is written
  34.      * Checks authentication based on URL parameter passed from Connect Library
  35.      * Also sets the cookie variable for displaying/hiding Downloads section in Detail page
  36.      */
  37.     public function onKernelController(FilterControllerEvent $event)
  38.     {
  39.         parent::onKernelController($event);
  40.         
  41.         if ($event->getRequest()->get("country")) {
  42.             
  43.             $country strtolower($event->getRequest()->get("country"));
  44.             $countryObj DataObject\AvailabilityCountry::getByPath("/availability-countries/" $country);
  45.             if ($countryObj) {
  46.                 if ($countryObj->getportfolioGuideEnable()) {
  47.                     $this->countryId $countryObj->getId();
  48.                     $this->view->countryId $countryObj->getId();
  49.                     $this->country $country;
  50.                     $this->view->country $country;
  51.                     $this->countryObj $countryObj;
  52.                     $this->view->countryObj $countryObj;
  53.                 }
  54.             }
  55.         }
  56.         
  57.         if (!$this->country || !$this->countryId) {
  58.             $this->countryId 32853;
  59.             $this->view->countryId 32853;
  60.             $this->country "us";
  61.             $this->view->country "us";
  62.             $this->countryObj DataObject\AvailabilityCountry::getById(32853);
  63.             $this->view->countryObj DataObject\AvailabilityCountry::getById(32853);
  64.         }
  65.         
  66.         //get available countries
  67.         $countriesView = [];
  68.         $x 0;
  69.         $countries = new DataObject\AvailabilityCountry\Listing();
  70.         $countries->setCondition("portfolioGuideEnable = 1");
  71.         
  72.         foreach ($countries as $enabledCountry) {
  73.             if ($enabledCountry->getAltCode()) {
  74.                 $countriesView[$x]["Value"] = $enabledCountry->getAltCode();
  75.                 $countriesView[$x]["Name"] = $enabledCountry->getAltName();
  76.             } else {
  77.                 $countriesView[$x]["Value"] = $enabledCountry->getCountry();
  78.                 $countriesView[$x]["Name"] = Intl::getRegionBundle()->getCountryName($enabledCountry->getName());
  79.             }
  80.             if ($this->country == $enabledCountry->getKey()) {
  81.                 $countriesView[$x]["Selected"] = "Selected";
  82.             }
  83.             $countriesView[$x]["Icon"] = $enabledCountry->getFlagIconImage();
  84.             $x++;        
  85.         }
  86.         $this->view->countries $countriesView;
  87.         
  88.         $localesView = [];
  89.         $x 0;
  90.         $locales DataObject\EnabledLanguages::getByPath("/enabled-languages/enabled-languages");
  91.         foreach($locales->getEnabledLanguages() as $item) {
  92.             if ($item['portfolioGuideEnable']->getData()) {
  93.                 $localesView[$x]["Value"] = $item['EnabledLanguage']->getData();
  94.                 $localesView[$x]["Name"] = $item['LanguageDisplay']->getData();
  95.                 $localesView[$x]["Icon"] = $item['FlagIconImage']->getData();
  96.                 if ($this->locale == $item['EnabledLanguage']->getData()) {
  97.                     $localesView[$x]["Selected"] = "Selected";
  98.                 }
  99.                 $x++;    
  100.             }
  101.         }
  102.         
  103.         $this->view->localesView $localesView;
  104.         
  105.         //need to change this to SSO        
  106.         if(!empty($_GET['v'])){ // Checks whether a url parameter is passed for 'Downloads' section display in Detail page
  107.                 //$paramV = $_GET['v'];
  108.                 setcookie("paramV""f"time()+2592000); // Sets cookie for 1 month as per client requirement
  109.                 $this->view->paramV "f";
  110.         }
  111.         $this->view->paramV $_COOKIE['paramV'];    
  112.         
  113.     }
  114.     
  115.     /**
  116.      * Get the list of published portfolioguides 
  117.      * 
  118.      * @return html products landing page
  119.      */
  120.     public function portfolioguideLandingAction(Request $request
  121.     {  
  122.         ini_set('memory_limit''512M'); 
  123.         $order_by "";        
  124.         $condition "";
  125.         $limit "";
  126.         $this->view->current_alcohol_type "";
  127.         //$this->layout()->setLayout('portfolioguideportal');
  128.         $this->view->CssClass "sub-category-page";
  129.         $headTitleHelper \Pimcore::getContainer()->get('pimcore.templating.view_helper.head_title');
  130.         $headTitleHelper("Portfolio Guide");
  131.         $alcohol_type_obj = new DataObject\CategoryAlcoholType();       
  132.         $brand_obj = new DataObject\Brand();
  133.         $brand_extension_obj = new DataObject\BrandExtension();
  134.         $portfolio_guide_obj = new DataObject\PortfolioGuide();
  135.         $portfolio_brand DataObject\CategoryAlcoholType::getList();
  136.         
  137.         $locale $this->locale;
  138.         $type_id = ($_REQUEST['type']) ? $_REQUEST['type'] : "";
  139.         $brand_id = ($_REQUEST['Brand']) ? $_REQUEST['Brand'] : "";
  140.         $search = ($_REQUEST['search']) ? $_REQUEST['search'] : "";
  141.         $countryAvailability = ($this->countryId) ? $this->countryId "";
  142.         $count_per_page = ($_REQUEST['counter'])? $_REQUEST['counter']:15;        
  143.         
  144.         //the below line gets all Portfolio Guide objects + all the related data, becomes 160MB array and kills php, let's use SQL
  145.         //$portfolio_guides_list = Object\PortfolioGuide::getList();        
  146.         $db \Pimcore\Db::get();
  147.         $result $db->fetchAll("SELECT COUNT(`oo_id`) as PFG_Number FROM `object_localized_" $portfolio_guide_obj->getClassId() . "_" $locale "` WHERE `o_published` = 1");
  148.         $portfolio_guides_list $result[0]['PFG_Number'];
  149.             
  150.         $count_per_page = ($count_per_page == "all")? $portfolio_guides_list:$count_per_page;
  151.         $sorting =  ($_REQUEST['sorting'])? $_REQUEST['sorting']:1;  
  152.         $childs $this->view->types \App\Model\DataObject\PortfolioGuide::getAlcoholChilds($type_id);   
  153.         $child_array = array($type_id);
  154.         foreach($childs as $child)
  155.         {
  156.             $child_array[] = $child->getId();
  157.         }        
  158.         if($type_id)
  159.         {
  160.             $current_alcohol_type \App\Model\DataObject\PortfolioGuide::getAlcoholTypeName($type_id);
  161.             $this->view->current_alcohol_type $current_alcohol_type;
  162.         }
  163.         if ($type_id) {
  164.             $condition .= " AND REPLACE(object_localized_" $brand_extension_obj->getClassId() . "_" $locale ".AlcoholType,',','') IN (" implode(', '$child_array) . ")";
  165.         }        
  166.         if ($brand_id) {
  167.             $condition .= " AND object_localized_" $brand_extension_obj->getClassId() . "_" $locale ".Brand LIKE '%" $brand_id "%'";
  168.         }
  169.         if ($search) {
  170.             $condition .= " AND object_localized_" $brand_extension_obj->getClassId() . "_" $locale ".BrandExtensionName LIKE '%" trim($search) . "%'";
  171.         }
  172.         
  173.         if ($countryAvailability) {
  174.             $condition .= " AND object_localized_" $brand_extension_obj->getClassId() . "_" $locale ".CountryAvailabilityList LIKE '%" trim($countryAvailability) . "%'";
  175.         }
  176.         
  177.         if ($sorting) {
  178.             if ($sorting == 2) {
  179.                 $order_by " ORDER BY object_localized_" $brand_extension_obj->getClassId() . "_" $locale ".BrandExtensionName ASC";
  180.             } else if ($sorting == 3) {
  181.                 $order_by " ORDER BY object_localized_" $brand_extension_obj->getClassId() . "_" $locale ".BrandExtensionName DESC";
  182.             } else if ($sorting == 4) {
  183.                 $order_by " ORDER BY object_localized_" $portfolio_guide_obj->getClassId() . "_" $locale ".o_modificationDate DESC";
  184.             } else {
  185.                 $order_by " ORDER BY BrandName ASC, Ordering ASC";
  186.             }
  187.         }
  188.         $db \Pimcore\Db::get();
  189.                        
  190.         $start = ($_REQUEST["page"])?($_REQUEST["page"]-1)*$count_per_page:0;
  191.         $start = ($start $portfolio_guides_list)? $start:0;
  192.         $limit " LIMIT ".$start.",".$count_per_page;
  193.         
  194.         $sql "SELECT "
  195.                 "object_localized_" $portfolio_guide_obj->getClassId() . "_" $locale ".oo_id AS guide_id, "
  196.                 "object_localized_" $portfolio_guide_obj->getClassId() . "_" $locale ".Order AS Ordering, "
  197.                 "object_localized_" $brand_extension_obj->getClassId() . "_" $locale ".o_creationDate AS creation_date,"
  198.                 "object_localized_" $brand_extension_obj->getClassId() . "_" $locale ".o_modificationDate AS modification_date, "
  199.                 "object_localized_" $brand_extension_obj->getClassId() . "_" $locale ".oo_id AS brand_extension_id, "
  200.                 "object_localized_" $brand_extension_obj->getClassId() . "_" $locale ".BrandExtensionNameTrademark, "
  201.                 "object_localized_" $brand_extension_obj->getClassId() . "_" $locale ".BrandExtensionName, "
  202.                 "object_localized_" $brand_extension_obj->getClassId() . "_" $locale ".FullDescriptionHeadline as brandextDescriptionHeadline, "
  203.                 "object_localized_" $brand_extension_obj->getClassId() . "_" $locale ".CountryAvailabilityList, "
  204.                 "object_localized_" $brand_extension_obj->getClassId() . "_" $locale ".P_BrandName as BrandName, "
  205.                 "object_localized_" $alcohol_type_obj->getClassId() . "_" $locale ".*"
  206.                 "FROM object_localized_" $portfolio_guide_obj->getClassId() . "_" $locale ""
  207.                 " LEFT JOIN object_localized_" $brand_extension_obj->getClassId() . "_" $locale ""
  208.                 " ON REPLACE(SUBSTRING_INDEX(object_localized_" $portfolio_guide_obj->getClassId() . "_" $locale ".BrandExtension, ',', 2),',','') = object_localized_" $brand_extension_obj->getClassId() . "_" $locale ".oo_id"
  209.                 " LEFT JOIN object_localized_" $brand_obj->getClassId() . "_" $locale ""
  210.                 " ON REPLACE(object_localized_" $brand_extension_obj->getClassId() . "_" $locale ".Brand,',','') = object_localized_" $brand_obj->getClassId() . "_" $locale ".oo_id"
  211.                 " LEFT JOIN object_localized_" $alcohol_type_obj->getClassId() . "_" $locale ""
  212.                 " ON REPLACE(object_localized_" $brand_extension_obj->getClassId() . "_" $locale ".AlcoholType,',','') = object_localized_" $alcohol_type_obj->getClassId() . "_" $locale ".oo_id"
  213.                 " WHERE object_localized_" $portfolio_guide_obj->getClassId() . "_" $locale ".o_published=1" $condition;        
  214.         
  215.         $portfolio_guide_all_list $db->fetchAll($sql);
  216.         $this->view->total_items ceil((count($portfolio_guide_all_list))/$count_per_page);
  217.         $portfolio_guide $db->fetchAll($sql.$order_by.$limit);
  218.         $this->view->current_page = ($_REQUEST["page"])?($_REQUEST["page"]):1;       
  219.         $display_items_id = array();                
  220.         $all_portfolio_type_count \App\Model\DataObject\PortfolioGuide::getAlcoholTypeCount($brand_id$portfolio_guide_all_list);
  221.         
  222.         foreach($this->view->types as $type)
  223.         {
  224.             $sub_child_count_alcohol[$type->getId()] = 0;
  225.             $items = new DataObject\CategoryAlcoholType\Listing();                
  226.             $items ->setCondition("o_parentId = ?", array($type->getId()));  
  227.             if($all_portfolio_type_count[$type->getId()])
  228.             {
  229.                 $display_items_id[] = $type->getId();                  
  230.             }            
  231.             else
  232.             {
  233.                 foreach($items as $item)
  234.                 {
  235.                     if($all_portfolio_type_count[$item->getId()])
  236.                     {
  237.                         $display_items_id[] = $type->getId();                          
  238.                     }
  239.                 }
  240.             }            
  241.         }  
  242.                         
  243.         DataObject\AbstractObject::setHideUnpublished(false);
  244.         $this->view->brand DataObject\Brand::getList();
  245.         DataObject\AbstractObject::setHideUnpublished(true);
  246.         $this->view->portfolio_guide $portfolio_guide;        
  247.         $this->view->portfolio_brand_count \App\Model\DataObject\PortfolioGuide::getBrandCount($type_id$portfolio_guide_all_list);
  248.         $this->view->portfolio_type_count $all_portfolio_type_count;
  249.         $this->view->initial_display_alcohol_type $display_items_id;
  250.         
  251.         //$this->enableLayout();  
  252.         
  253.     }
  254.     /**
  255.      *  Function used to display the detail page of portfolioguide
  256.      * 
  257.      * @return Portfolioguide detail page html
  258.      */
  259.     public function portfolioguideDetailPageAction(Request $request
  260.     {
  261.         
  262.         $brand $brand_extension $portfolioGuideName $sizes '';
  263.         $pgMultiFlag false;
  264.         //$this->layout()->setLayout('portfolioguideportal');
  265.         $this->view->CssClass "detail-page";  
  266.         $headTitleHelper \Pimcore::getContainer()->get('pimcore.templating.view_helper.head_title');
  267.         $headTitleHelper("Portfolio Guide");
  268.                 
  269.         $locale $this->locale;
  270.         
  271.         $paramId $request->get("portfolioid");
  272.         $pgObject DataObject\PortfolioGuide::getById($paramId);    
  273.         
  274.         $this->view->brand_info_connect $pgObject->getCONNECTBrandPageURL($locale);
  275.         $this->view->recipe $pgObject->getRecipesPageURL($locale);
  276.         $this->view->related1 $pgObject->getAddlRelatedLinkURL1($locale);
  277.         $this->view->related2 $pgObject->getAddlRelatedLinkURL2($locale);
  278.         $this->view->related3 $pgObject->getAddlRelatedLinkURL3($locale); 
  279.         
  280.         //Show Ordering Specs for U.S. or the rest of the world (Global)
  281.         if ($this->countryId == 32853) {        
  282.             $this->view->orderingspecs $pgObject->getOrderingSpecsDownloadURL($locale);
  283.         } else {
  284.             $this->view->orderingspecs $pgObject->getGlobalOrderingSpecsDownloadURL($locale);
  285.         }
  286.         //$this->view->otherBrandExtObj = $pgObject->getOtherBrandExtensions($locale);
  287.         $this->view->footerNotes $pgObject->getFootnotesLegalDisclaimer($locale);
  288.         
  289.         DataObject\AbstractObject::setHideUnpublished(false);
  290.         $brand_extension $pgObject->getBrandExtension(); 
  291.         $pgMultiBottleImage $pgObject->getMultiBottlesPhoto($locale);
  292.         $portfolioGuideName $pgObject->getAltTitle($locale);
  293.         
  294.         if ($brand_extension) {
  295.             
  296.             if (count($brand_extension) > 1)
  297.             {
  298.                 $pgMultiFlag true;
  299.                 $this->view->brandExtList $brand_extension;
  300.             }              
  301.             
  302.             $brandExtObj $brand_extension[0]->getObject();
  303.             $brand $brandExtObj->getBrand();
  304.             DataObject\AbstractObject::setHideUnpublished(true);
  305.             
  306.             if ($brand) {
  307.                 $brand $brand[0]->getObject();
  308.                 $this->view->website $brand->getBrandWebsiteURL();
  309.                 $this->view->brandNameTrademark $brand->getBrandNameTrademark();
  310.                 $brandExtParent $brand;
  311.                 $brandPhotoAsset $brandExtParent->getBrandMarkImage();
  312.                 $brandPhoto $brandPhotoAsset->getPath().$brandPhotoAsset->getFilename();
  313.                 //$brandPhotoName = $brandPhoto->getFilename();
  314.                 $brandPhotoName $brandPhotoAsset->getFilename();
  315.             } else {
  316.                 $this->view->website "";
  317.                 $this->view->brandExtParent "";
  318.             }
  319.             $photo $brandExtObj->getBottlePhoto();
  320.             $bottleImage $photo->getPath().$photo->getFilename();
  321.             $bottleImageName $photo->getFilename();
  322.             if($pgMultiBottleImage)
  323.             {
  324.                 $bottleImageHtml $pgMultiBottleImage->getThumbnail('PGDetail_HTML')->getHtml(['class' => 'product-image']);
  325.             } 
  326.             else if ($pgMultiFlag)
  327.             {
  328.                 if ($brandPhotoAsset)
  329.                 {
  330.                     $bottleImageHtml $brandPhotoAsset->getThumbnail('PGDetail_HTML')->getHtml(['class' => 'product-image']);
  331.                 }
  332.             }
  333.             else
  334.             {
  335.                 $bottleImageHtml $brandExtObj->getFirstImage('PGDetail_HTML'$this->countryObj)->getHtml(['class' => 'product-image']);
  336.             }
  337.                                     
  338.             $alcoholTypeCategObj $brandExtObj->getAlcoholType();
  339.             if($alcoholTypeCategObj){
  340.                 $alcoholTypeCateg $alcoholTypeCategObj[0]->getObject();
  341.                 $alcoholTypeCateg $alcoholTypeCateg->getAlcoholType();
  342.             }
  343.             $this->view->proof $brandExtObj->getProof();
  344.             $this->view->abv $brandExtObj->getABV();
  345.             $this->view->aging $brandExtObj->getAging($locale);  
  346.             DataObject\AbstractObject::setHideUnpublished(false);
  347.             $variants $brandExtObj->getSizeVariants($this->countryObj);
  348.             DataObject\AbstractObject::setHideUnpublished(true);
  349.             if ($variants) {
  350.                 foreach ($variants as $variants){
  351.                     if($variants->getBottleSize()!=''){
  352.                         //bottle sizes
  353.                         $sizeValue str_replace(" ml"""$variants->getBottleSize());
  354.                         $sizeValue = (int)$sizeValue;
  355.                         if($sizeValue >= 1000){
  356.                             $sizeValue  $sizeValue 1000;
  357.                             $sizeValue  $sizeValue." L";
  358.                         }else{
  359.                             $sizeValue  $variants->getBottleSize();
  360.                         }
  361.                         $sizes.=$sizeValue.', ';
  362.                     }
  363.                     
  364.                     $countries $variants->getCountryAvailabilityList();
  365.                     $continue 0;
  366.                     if (count($countries) == 1) {
  367.                         foreach ($countries as $country) {
  368.                                 if ($country->getObject()->getId() == $this->countryId) {
  369.                                     $this->view->proof $variants->getProof();
  370.                                     $this->view->abv $variants->getABV();
  371.                                 }
  372.                         }
  373.                     }
  374.                 }
  375.             }
  376.             if ($sizes !='') {
  377.                 $sizes rtrim($sizes', ');
  378.             }
  379.             
  380.             $accolades $brandExtObj->getAccoladesList();
  381.             if ($accolades) {
  382.                 $this->view->accoladeItems $accolades->getItems();
  383.             }
  384.             
  385.             //$tasingNoteItems = $brandExtObj->getlocalizedfields()->getItems();
  386.             $tasingNoteItems = array();
  387.             $tasingNoteItems['TasteProfileColor'] = $brandExtObj->getTasteProfileColor($locale);
  388.             $tasingNoteItems['TasteProfileAroma'] = $brandExtObj->getTasteProfileAroma($locale);
  389.             $tasingNoteItems['TasteProfileTaste'] = $brandExtObj->getTasteProfileTaste($locale);
  390.             $tasingNoteItems['TasteProfileFinish'] = $brandExtObj->getTasteProfileFinish($locale);
  391.             $tasingNoteItems['TasteProfileHeadline'] = $brandExtObj->getTasteProfileHeadline($locale);
  392.             $tasingNoteItems['TasteProfileIntro'] = $brandExtObj->getTasteProfileIntro($locale);
  393.             $this->view->tastingNotes $tasingNoteItems;
  394.             
  395.             $brandExtFullDescrHeadline $brandExtObj->getFullDescriptionHeadline($locale);
  396.             $brandExtFullDescr $brandExtObj->getFullDescription($locale);
  397.             
  398.             $brandExtNameTradeMark $this->view->brandExtNameTradeMark $brandExtObj->getBrandExtensionNameTrademark();
  399.             $this->view->brandExtName $brandExtObj->getBrandExtensionName();
  400.             
  401.             if((!$portfolioGuideName || $portfolioGuideName == '') && !$pgMultiFlag){
  402.                 
  403.                 if (!$brandExtNameTradeMark || $brandExtNameTradeMark == '')
  404.                 {
  405.                     $portfolioGuideName $brandExtObj->getBrandExtensionName();
  406.                 }
  407.                 else
  408.                 {
  409.                     $portfolioGuideName $brandExtNameTradeMark;
  410.                 }
  411.             }
  412.         }
  413.                    
  414.         $altProdDescrHeadline $pgObject->getAltProductDescrHeadline($locale);
  415.         if((!$altProdDescrHeadline || $altProdDescrHeadline == "") && !$pgMultiFlag){
  416.             $altProdDescrHeadline $brandExtFullDescrHeadline;
  417.         }
  418.         
  419.         //get other expressions
  420.         $otherExpressionsHeadline $pgObject->getAltExpressionsHeadline($locale);
  421.         if(!$otherExpressionsHeadline || $otherExpressionsHeadline == ""){
  422.             if ($brand->getBrandNameTrademark()) {
  423.                 $otherExpressionsHeadline $brand->getBrandNameTrademark();
  424.             } else {
  425.                 $otherExpressionsHeadline $brand->getBrandName();
  426.             }
  427.         }
  428.                 
  429.         $otherExpressions = [];
  430.         $otherExpressionsList $pgObject->getOtherPortfolioGuides();
  431.         $x 0;
  432.         if ($otherExpressionsList)
  433.         {
  434.             foreach ($otherExpressionsList as $otherExpression)
  435.             {
  436.                 $otherPG $otherExpression->getObject();
  437.                 $otherPGId $otherPG->getId();
  438.                 
  439.                 if($otherExpression->getaltdisplayname()){
  440.                     $otherPGName $otherExpression->getaltdisplayname();
  441.                 }
  442.                 else
  443.                 {    
  444.                     DataObject\AbstractObject::setHideUnpublished(false);
  445.                     $otherPGbrandExtensionList $otherPG->getBrandExtension();
  446.                     DataObject\AbstractObject::setHideUnpublished(true);
  447.                     DataObject\AbstractObject::setHideUnpublished(false);
  448.                     $otherPGNameBrandExt $otherPG->getBrandExtension();
  449.                     if ($otherPGNameBrandExt)
  450.                     {
  451.                         $otherPGNameBrandExtObj $otherPGNameBrandExt[0]->getObject();
  452.                         
  453.                         $countries $otherPGNameBrandExtObj->getCountryAvailabilityList();
  454.                         $add 0;
  455.                         if ($countries) {
  456.                             foreach ($countries as $country) {
  457.                                     if ($country->getObject()->getId() == $this->countryId) {
  458.                                         $add 1;
  459.                                     }
  460.                             }
  461.                             if ($add == 0) {
  462.                                 continue;
  463.                             }
  464.                         }
  465.                         if ($otherPG->getAltTitle())
  466.                         {
  467.                             $otherPGName $otherPG->getAltTitle();
  468.                         }
  469.                         else
  470.                         {
  471.                             $otherPGName $otherPGNameBrandExtObj->getBrandExtensionNameTrademark();
  472.                             if (!$otherPGName || $otherPGName == '')
  473.                             {
  474.                                 $otherPGName $otherPGNameBrandExtObj->getBrandExtensionName();
  475.                             }
  476.                         }
  477.                     }
  478.                     DataObject\AbstractObject::setHideUnpublished(true);
  479.                     if(count($otherPGbrandExtensionList) > 1)
  480.                     {
  481.                          
  482.                     } 
  483.                     else
  484.                     {
  485.                     }
  486.                 }
  487.                 
  488.                 $otherExpressions[$x][0] = $otherPGId;
  489.                 $otherExpressions[$x][1] = $otherPGName;
  490.                 $otherExpressions[$x][2] = $otherPG->getKey();
  491.                 $x++;
  492.             }
  493.             
  494.             $this->view->otherExpressionsList $otherExpressions;
  495.                 
  496.         }
  497.         
  498.         $altProdDescr $pgObject->getAltProductDescr($locale);
  499.         if((!$altProdDescr || $altProdDescr == "") && !$pgMultiFlag){
  500.             $altProdDescr $brandExtFullDescr;
  501.         }
  502.         $this->view->pgMultiFlag $pgMultiFlag;      
  503.         $this->view->pgKey $pgObject->getKey();
  504.         $this->view->portfolioGuideName $portfolioGuideName;
  505.         $this->view->paramId $paramId;
  506.         $this->view->alcoholTypeCateg $alcoholTypeCateg;
  507.         $this->view->bottleImageHtml $bottleImageHtml;
  508.         $this->view->altProdDescrHeadline $altProdDescrHeadline;
  509.         $this->view->altProdDescr $altProdDescr;
  510.         $this->view->sizes $sizes;
  511.         $this->view->otherExpressionsHeadline $otherExpressionsHeadline;
  512.         $this->view->bottleImage $bottleImage;
  513.         $this->view->bottleImageName $bottleImageName;
  514.         $this->view->brandPhoto $brandPhoto;
  515.         $this->view->brandPhotoName $brandPhotoName;
  516.         //$this->enableLayout();
  517.     }
  518.     
  519.     public function pageAction(Request $request) {
  520.         
  521.             //$this->layout()->setLayout('portfolioguideportal');
  522.             //$this->enableLayout();    
  523.     }
  524.     public function footerAction(Request $request) {
  525.     }
  526.     
  527.     public function portfolioGuideOrdering() 
  528.     {  
  529.         ini_set('memory_limit''512M'); 
  530.         $order_by "";        
  531.         $condition "";
  532.         $limit "";
  533.         $this->view->current_alcohol_type "";
  534.         //$this->layout()->setLayout('portfolioguideportal');
  535.         $this->view->CssClass "sub-category-page";
  536.         $headTitleHelper \Pimcore::getContainer()->get('pimcore.templating.view_helper.head_title');
  537.         $headTitleHelper("Portfolio Guide");
  538.         $alcohol_type_obj = new DataObject\CategoryAlcoholType();       
  539.         $brand_obj = new DataObject\Brand();
  540.         $brand_extension_obj = new DataObject\BrandExtension();
  541.         $portfolio_guide_obj = new DataObject\PortfolioGuide();
  542.         $portfolio_brand DataObject\CategoryAlcoholType::getList();
  543.         
  544.         $locale $this->locale;
  545.                 
  546.         $type_id = ($_REQUEST['type']) ? $_REQUEST['type'] : "";
  547.         $brand_id = ($_REQUEST['Brand']) ? $_REQUEST['Brand'] : "";
  548.         $search = ($_REQUEST['search']) ? $_REQUEST['search'] : "";
  549.         $countryAvailability = ($this->countryId) ? $this->countryId "";
  550.         $count_per_page = ($_REQUEST['counter'])? $_REQUEST['counter']:15;        
  551.         
  552.         //the below line gets all Portfolio Guide objects + all the related data, becomes 160MB array and kills php, let's use SQL
  553.         //$portfolio_guides_list = Object\PortfolioGuide::getList();        
  554.         $db \Pimcore\Db::get();
  555.         $result $db->fetchAll("SELECT COUNT(`oo_id`) as PFG_Number FROM `object_localized_" $portfolio_guide_obj->getClassId() . "_" $locale "` WHERE `o_published` = 1");
  556.         $portfolio_guides_list $result[0]['PFG_Number'];
  557.             
  558.         $count_per_page = ($count_per_page == "all")? $portfolio_guides_list:$count_per_page;
  559.         $sorting =  ($_REQUEST['sorting'])? $_REQUEST['sorting']:1;  
  560.         $childs $this->view->types \App\Model\DataObject\PortfolioGuide::getAlcoholChilds($type_id);   
  561.         $child_array = array($type_id);
  562.         foreach($childs as $child)
  563.         {
  564.             $child_array[] = $child->getId();
  565.         }        
  566.         if($type_id)
  567.         {
  568.             $current_alcohol_type \App\Model\DataObject\PortfolioGuide::getAlcoholTypeName($type_id);
  569.             $this->view->current_alcohol_type $current_alcohol_type;
  570.         }
  571.         if ($type_id) {
  572.             $condition .= " AND REPLACE(object_localized_" $brand_extension_obj->getClassId() . "_" $locale ".AlcoholType,',','') IN (" implode(', '$child_array) . ")";
  573.         }        
  574.         if ($brand_id) {
  575.             $condition .= " AND object_localized_" $brand_extension_obj->getClassId() . "_" $locale ".Brand LIKE '%" $brand_id "%'";
  576.         }
  577.         if ($search) {
  578.             $condition .= " AND object_localized_" $brand_extension_obj->getClassId() . "_" $locale ".BrandExtensionName LIKE '%" trim($search) . "%'";
  579.         }
  580.         
  581.         if ($countryAvailability) {
  582.             $condition .= " AND object_localized_" $brand_extension_obj->getClassId() . "_" $locale ".CountryAvailabilityList LIKE '%" trim($countryAvailability) . "%'";
  583.         }
  584.         
  585.         if ($sorting) {
  586.             if ($sorting == 2) {
  587.                 $order_by " ORDER BY object_localized_" $brand_extension_obj->getClassId() . "_" $locale ".BrandExtensionName ASC";
  588.             } else if ($sorting == 3) {
  589.                 $order_by " ORDER BY object_localized_" $brand_extension_obj->getClassId() . "_" $locale ".BrandExtensionName DESC";
  590.             } else if ($sorting == 4) {
  591.                 $order_by " ORDER BY object_localized_" $portfolio_guide_obj->getClassId() . "_" $locale ".o_modificationDate DESC";
  592.             } else {
  593.                 $order_by " ORDER BY object_localized_" $brand_extension_obj->getClassId() . "_" $locale ".Brand ASC, Ordering";
  594.             }
  595.         }
  596.         $db \Pimcore\Db::get();
  597.                        
  598.         $start = ($_REQUEST["page"])?($_REQUEST["page"]-1)*$count_per_page:0;
  599.         $start = ($start $portfolio_guides_list)? $start:0;
  600.         $limit " LIMIT ".$start.",".$count_per_page;
  601.         
  602.         $sql "SELECT "
  603.                 "object_localized_" $portfolio_guide_obj->getClassId() . "_" $locale ".oo_id AS guide_id, "
  604.                 "object_localized_" $portfolio_guide_obj->getClassId() . "_" $locale ".Order AS Ordering, "
  605.                 "object_localized_" $brand_extension_obj->getClassId() . "_" $locale ".o_creationDate AS creation_date,"
  606.                 "object_localized_" $brand_extension_obj->getClassId() . "_" $locale ".o_modificationDate AS modification_date, "
  607.                 "object_localized_" $brand_extension_obj->getClassId() . "_" $locale ".oo_id AS brand_extension_id, "
  608.                 "object_localized_" $brand_extension_obj->getClassId() . "_" $locale ".BrandExtensionNameTrademark, "
  609.                 "object_localized_" $brand_extension_obj->getClassId() . "_" $locale ".BrandExtensionName, "
  610.                 "object_localized_" $brand_extension_obj->getClassId() . "_" $locale ".FullDescriptionHeadline as brandextDescriptionHeadline, "
  611.                 "object_localized_" $brand_extension_obj->getClassId() . "_" $locale ".CountryAvailabilityList, "
  612.                 "object_localized_" $alcohol_type_obj->getClassId() . "_" $locale ".*"
  613.                 "FROM object_localized_" $portfolio_guide_obj->getClassId() . "_" $locale ""
  614.                 " LEFT JOIN object_localized_" $brand_extension_obj->getClassId() . "_" $locale ""
  615.                 " ON REPLACE(SUBSTRING_INDEX(object_localized_" $portfolio_guide_obj->getClassId() . "_" $locale ".BrandExtension, ',', 2),',','') = object_localized_" $brand_extension_obj->getClassId() . "_" $locale ".oo_id"
  616.                 " LEFT JOIN object_localized_" $brand_obj->getClassId() . "_" $locale ""
  617.                 " ON REPLACE(object_localized_" $brand_extension_obj->getClassId() . "_" $locale ".Brand,',','') = object_localized_" $brand_obj->getClassId() . "_" $locale ".oo_id"
  618.                 " LEFT JOIN object_localized_" $alcohol_type_obj->getClassId() . "_" $locale ""
  619.                 " ON REPLACE(object_localized_" $brand_extension_obj->getClassId() . "_" $locale ".AlcoholType,',','') = object_localized_" $alcohol_type_obj->getClassId() . "_" $locale ".oo_id"
  620.                 " WHERE object_localized_" $portfolio_guide_obj->getClassId() . "_" $locale ".o_published=1" $condition;        
  621.         
  622.         $portfolio_guide_all_list $db->fetchAll($sql);
  623.         $this->view->total_items ceil((count($portfolio_guide_all_list))/$count_per_page);
  624.         $portfolio_guide $db->fetchAll($sql.$order_by.$limit);
  625.         
  626.         $this->view->current_page = ($_REQUEST["page"])?($_REQUEST["page"]):1;       
  627.         $display_items_id = array();                
  628.         $all_portfolio_type_count \App\Model\DataObject\PortfolioGuide::getAlcoholTypeCount($brand_id$portfolio_guide_all_list);
  629.         
  630.         foreach($this->view->types as $type)
  631.         {
  632.             $sub_child_count_alcohol[$type->getId()] = 0;
  633.             $items = new DataObject\CategoryAlcoholType\Listing();                
  634.             $items ->setCondition("o_parentId = ?", array($type->getId()));  
  635.             if($all_portfolio_type_count[$type->getId()])
  636.             {
  637.                 $display_items_id[] = $type->getId();                  
  638.             }            
  639.             else
  640.             {
  641.                 foreach($items as $item)
  642.                 {
  643.                     if($all_portfolio_type_count[$item->getId()])
  644.                     {
  645.                         $display_items_id[] = $type->getId();                          
  646.                     }
  647.                 }
  648.             }            
  649.         }  
  650.                         
  651.         DataObject\AbstractObject::setHideUnpublished(false);
  652.         $this->view->brand DataObject\Brand::getList();
  653.         DataObject\AbstractObject::setHideUnpublished(true);
  654.         $this->view->portfolio_guide $portfolio_guide;        
  655.         $this->view->portfolio_brand_count \App\Model\DataObject\PortfolioGuide::getBrandCount($type_id$portfolio_guide_all_list);
  656.         $this->view->portfolio_type_count $all_portfolio_type_count;
  657.         $this->view->initial_display_alcohol_type $display_items_id;
  658.         
  659.         //$this->enableLayout();  
  660.         
  661.     }
  662. }