<?php
namespace App\Controller;
/**
* The core controller for Portfolioguide Portal
*
* Login session criteria to be declared
*
* PHP version 5.3
*
* @category Portfolio_Guide
* @package PortfolioGuide
* @author TCS Beam Suntory
* @copyright TCS Beam Suntory
* @license
* @link
*/
/**
* The core controller for Portfolioguide Portal
*/
use Pimcore\Controller\FrontendController;
use Pimcore\Model\DataObject;
use Pimcore\Mail;
use Pimcore\Model\Search\Backend\Data;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Event\FilterControllerEvent;
use Symfony\Component\Intl\Intl;
// class PortfolioguideController extends \Website\Controller\Action
class PortfolioguideController extends Action
{
public $countryId;
public $countryObj;
/**
* Init function in which the cookie based authentication is written
* Checks authentication based on URL parameter passed from Connect Library
* Also sets the cookie variable for displaying/hiding Downloads section in Detail page
*/
public function onKernelController(FilterControllerEvent $event)
{
parent::onKernelController($event);
if ($event->getRequest()->get("country")) {
$country = strtolower($event->getRequest()->get("country"));
$countryObj = DataObject\AvailabilityCountry::getByPath("/availability-countries/" . $country);
if ($countryObj) {
if ($countryObj->getportfolioGuideEnable()) {
$this->countryId = $countryObj->getId();
$this->view->countryId = $countryObj->getId();
$this->country = $country;
$this->view->country = $country;
$this->countryObj = $countryObj;
$this->view->countryObj = $countryObj;
}
}
}
if (!$this->country || !$this->countryId) {
$this->countryId = 32853;
$this->view->countryId = 32853;
$this->country = "us";
$this->view->country = "us";
$this->countryObj = DataObject\AvailabilityCountry::getById(32853);
$this->view->countryObj = DataObject\AvailabilityCountry::getById(32853);
}
//get available countries
$countriesView = [];
$x = 0;
$countries = new DataObject\AvailabilityCountry\Listing();
$countries->setCondition("portfolioGuideEnable = 1");
foreach ($countries as $enabledCountry) {
if ($enabledCountry->getAltCode()) {
$countriesView[$x]["Value"] = $enabledCountry->getAltCode();
$countriesView[$x]["Name"] = $enabledCountry->getAltName();
} else {
$countriesView[$x]["Value"] = $enabledCountry->getCountry();
$countriesView[$x]["Name"] = Intl::getRegionBundle()->getCountryName($enabledCountry->getName());
}
if ($this->country == $enabledCountry->getKey()) {
$countriesView[$x]["Selected"] = "Selected";
}
$countriesView[$x]["Icon"] = $enabledCountry->getFlagIconImage();
$x++;
}
$this->view->countries = $countriesView;
$localesView = [];
$x = 0;
$locales = DataObject\EnabledLanguages::getByPath("/enabled-languages/enabled-languages");
foreach($locales->getEnabledLanguages() as $item) {
if ($item['portfolioGuideEnable']->getData()) {
$localesView[$x]["Value"] = $item['EnabledLanguage']->getData();
$localesView[$x]["Name"] = $item['LanguageDisplay']->getData();
$localesView[$x]["Icon"] = $item['FlagIconImage']->getData();
if ($this->locale == $item['EnabledLanguage']->getData()) {
$localesView[$x]["Selected"] = "Selected";
}
$x++;
}
}
$this->view->localesView = $localesView;
//need to change this to SSO
if(!empty($_GET['v'])){ // Checks whether a url parameter is passed for 'Downloads' section display in Detail page
//$paramV = $_GET['v'];
setcookie("paramV", "f", time()+2592000); // Sets cookie for 1 month as per client requirement
$this->view->paramV = "f";
}
$this->view->paramV = $_COOKIE['paramV'];
}
/**
* Get the list of published portfolioguides
*
* @return html products landing page
*/
public function portfolioguideLandingAction(Request $request)
{
ini_set('memory_limit', '512M');
$order_by = "";
$condition = "";
$limit = "";
$this->view->current_alcohol_type = "";
//$this->layout()->setLayout('portfolioguideportal');
$this->view->CssClass = "sub-category-page";
$headTitleHelper = \Pimcore::getContainer()->get('pimcore.templating.view_helper.head_title');
$headTitleHelper("Portfolio Guide");
$alcohol_type_obj = new DataObject\CategoryAlcoholType();
$brand_obj = new DataObject\Brand();
$brand_extension_obj = new DataObject\BrandExtension();
$portfolio_guide_obj = new DataObject\PortfolioGuide();
$portfolio_brand = DataObject\CategoryAlcoholType::getList();
$locale = $this->locale;
$type_id = ($_REQUEST['type']) ? $_REQUEST['type'] : "";
$brand_id = ($_REQUEST['Brand']) ? $_REQUEST['Brand'] : "";
$search = ($_REQUEST['search']) ? $_REQUEST['search'] : "";
$countryAvailability = ($this->countryId) ? $this->countryId : "";
$count_per_page = ($_REQUEST['counter'])? $_REQUEST['counter']:15;
//the below line gets all Portfolio Guide objects + all the related data, becomes 160MB array and kills php, let's use SQL
//$portfolio_guides_list = Object\PortfolioGuide::getList();
$db = \Pimcore\Db::get();
$result = $db->fetchAll("SELECT COUNT(`oo_id`) as PFG_Number FROM `object_localized_" . $portfolio_guide_obj->getClassId() . "_" . $locale . "` WHERE `o_published` = 1");
$portfolio_guides_list = $result[0]['PFG_Number'];
$count_per_page = ($count_per_page == "all")? $portfolio_guides_list:$count_per_page;
$sorting = ($_REQUEST['sorting'])? $_REQUEST['sorting']:1;
$childs = $this->view->types = \App\Model\DataObject\PortfolioGuide::getAlcoholChilds($type_id);
$child_array = array($type_id);
foreach($childs as $child)
{
$child_array[] = $child->getId();
}
if($type_id)
{
$current_alcohol_type = \App\Model\DataObject\PortfolioGuide::getAlcoholTypeName($type_id);
$this->view->current_alcohol_type = $current_alcohol_type;
}
if ($type_id) {
$condition .= " AND REPLACE(object_localized_" . $brand_extension_obj->getClassId() . "_" . $locale . ".AlcoholType,',','') IN (" . implode(', ', $child_array) . ")";
}
if ($brand_id) {
$condition .= " AND object_localized_" . $brand_extension_obj->getClassId() . "_" . $locale . ".Brand LIKE '%" . $brand_id . "%'";
}
if ($search) {
$condition .= " AND object_localized_" . $brand_extension_obj->getClassId() . "_" . $locale . ".BrandExtensionName LIKE '%" . trim($search) . "%'";
}
if ($countryAvailability) {
$condition .= " AND object_localized_" . $brand_extension_obj->getClassId() . "_" . $locale . ".CountryAvailabilityList LIKE '%" . trim($countryAvailability) . "%'";
}
if ($sorting) {
if ($sorting == 2) {
$order_by = " ORDER BY object_localized_" . $brand_extension_obj->getClassId() . "_" . $locale . ".BrandExtensionName ASC";
} else if ($sorting == 3) {
$order_by = " ORDER BY object_localized_" . $brand_extension_obj->getClassId() . "_" . $locale . ".BrandExtensionName DESC";
} else if ($sorting == 4) {
$order_by = " ORDER BY object_localized_" . $portfolio_guide_obj->getClassId() . "_" . $locale . ".o_modificationDate DESC";
} else {
$order_by = " ORDER BY BrandName ASC, Ordering ASC";
}
}
$db = \Pimcore\Db::get();
$start = ($_REQUEST["page"])?($_REQUEST["page"]-1)*$count_per_page:0;
$start = ($start < $portfolio_guides_list)? $start:0;
$limit = " LIMIT ".$start.",".$count_per_page;
$sql = "SELECT "
. "object_localized_" . $portfolio_guide_obj->getClassId() . "_" . $locale . ".oo_id AS guide_id, "
. "object_localized_" . $portfolio_guide_obj->getClassId() . "_" . $locale . ".Order AS Ordering, "
. "object_localized_" . $brand_extension_obj->getClassId() . "_" . $locale . ".o_creationDate AS creation_date,"
. "object_localized_" . $brand_extension_obj->getClassId() . "_" . $locale . ".o_modificationDate AS modification_date, "
. "object_localized_" . $brand_extension_obj->getClassId() . "_" . $locale . ".oo_id AS brand_extension_id, "
. "object_localized_" . $brand_extension_obj->getClassId() . "_" . $locale . ".BrandExtensionNameTrademark, "
. "object_localized_" . $brand_extension_obj->getClassId() . "_" . $locale . ".BrandExtensionName, "
. "object_localized_" . $brand_extension_obj->getClassId() . "_" . $locale . ".FullDescriptionHeadline as brandextDescriptionHeadline, "
. "object_localized_" . $brand_extension_obj->getClassId() . "_" . $locale . ".CountryAvailabilityList, "
. "object_localized_" . $brand_extension_obj->getClassId() . "_" . $locale . ".P_BrandName as BrandName, "
. "object_localized_" . $alcohol_type_obj->getClassId() . "_" . $locale . ".*"
. "FROM object_localized_" . $portfolio_guide_obj->getClassId() . "_" . $locale . ""
. " LEFT JOIN object_localized_" . $brand_extension_obj->getClassId() . "_" . $locale . ""
. " ON REPLACE(SUBSTRING_INDEX(object_localized_" . $portfolio_guide_obj->getClassId() . "_" . $locale . ".BrandExtension, ',', 2),',','') = object_localized_" . $brand_extension_obj->getClassId() . "_" . $locale . ".oo_id"
. " LEFT JOIN object_localized_" . $brand_obj->getClassId() . "_" . $locale . ""
. " ON REPLACE(object_localized_" . $brand_extension_obj->getClassId() . "_" . $locale . ".Brand,',','') = object_localized_" . $brand_obj->getClassId() . "_" . $locale . ".oo_id"
. " LEFT JOIN object_localized_" . $alcohol_type_obj->getClassId() . "_" . $locale . ""
. " ON REPLACE(object_localized_" . $brand_extension_obj->getClassId() . "_" . $locale . ".AlcoholType,',','') = object_localized_" . $alcohol_type_obj->getClassId() . "_" . $locale . ".oo_id"
. " WHERE object_localized_" . $portfolio_guide_obj->getClassId() . "_" . $locale . ".o_published=1" . $condition;
$portfolio_guide_all_list = $db->fetchAll($sql);
$this->view->total_items = ceil((count($portfolio_guide_all_list))/$count_per_page);
$portfolio_guide = $db->fetchAll($sql.$order_by.$limit);
$this->view->current_page = ($_REQUEST["page"])?($_REQUEST["page"]):1;
$display_items_id = array();
$all_portfolio_type_count = \App\Model\DataObject\PortfolioGuide::getAlcoholTypeCount($brand_id, $portfolio_guide_all_list);
foreach($this->view->types as $type)
{
$sub_child_count_alcohol[$type->getId()] = 0;
$items = new DataObject\CategoryAlcoholType\Listing();
$items ->setCondition("o_parentId = ?", array($type->getId()));
if($all_portfolio_type_count[$type->getId()])
{
$display_items_id[] = $type->getId();
}
else
{
foreach($items as $item)
{
if($all_portfolio_type_count[$item->getId()])
{
$display_items_id[] = $type->getId();
}
}
}
}
DataObject\AbstractObject::setHideUnpublished(false);
$this->view->brand = DataObject\Brand::getList();
DataObject\AbstractObject::setHideUnpublished(true);
$this->view->portfolio_guide = $portfolio_guide;
$this->view->portfolio_brand_count = \App\Model\DataObject\PortfolioGuide::getBrandCount($type_id, $portfolio_guide_all_list);
$this->view->portfolio_type_count = $all_portfolio_type_count;
$this->view->initial_display_alcohol_type = $display_items_id;
//$this->enableLayout();
}
/**
* Function used to display the detail page of portfolioguide
*
* @return Portfolioguide detail page html
*/
public function portfolioguideDetailPageAction(Request $request)
{
$brand = $brand_extension = $portfolioGuideName = $sizes = '';
$pgMultiFlag = false;
//$this->layout()->setLayout('portfolioguideportal');
$this->view->CssClass = "detail-page";
$headTitleHelper = \Pimcore::getContainer()->get('pimcore.templating.view_helper.head_title');
$headTitleHelper("Portfolio Guide");
$locale = $this->locale;
$paramId = $request->get("portfolioid");
$pgObject = DataObject\PortfolioGuide::getById($paramId);
$this->view->brand_info_connect = $pgObject->getCONNECTBrandPageURL($locale);
$this->view->recipe = $pgObject->getRecipesPageURL($locale);
$this->view->related1 = $pgObject->getAddlRelatedLinkURL1($locale);
$this->view->related2 = $pgObject->getAddlRelatedLinkURL2($locale);
$this->view->related3 = $pgObject->getAddlRelatedLinkURL3($locale);
//Show Ordering Specs for U.S. or the rest of the world (Global)
if ($this->countryId == 32853) {
$this->view->orderingspecs = $pgObject->getOrderingSpecsDownloadURL($locale);
} else {
$this->view->orderingspecs = $pgObject->getGlobalOrderingSpecsDownloadURL($locale);
}
//$this->view->otherBrandExtObj = $pgObject->getOtherBrandExtensions($locale);
$this->view->footerNotes = $pgObject->getFootnotesLegalDisclaimer($locale);
DataObject\AbstractObject::setHideUnpublished(false);
$brand_extension = $pgObject->getBrandExtension();
$pgMultiBottleImage = $pgObject->getMultiBottlesPhoto($locale);
$portfolioGuideName = $pgObject->getAltTitle($locale);
if ($brand_extension) {
if (count($brand_extension) > 1)
{
$pgMultiFlag = true;
$this->view->brandExtList = $brand_extension;
}
$brandExtObj = $brand_extension[0]->getObject();
$brand = $brandExtObj->getBrand();
DataObject\AbstractObject::setHideUnpublished(true);
if ($brand) {
$brand = $brand[0]->getObject();
$this->view->website = $brand->getBrandWebsiteURL();
$this->view->brandNameTrademark = $brand->getBrandNameTrademark();
$brandExtParent = $brand;
$brandPhotoAsset = $brandExtParent->getBrandMarkImage();
$brandPhoto = $brandPhotoAsset->getPath().$brandPhotoAsset->getFilename();
//$brandPhotoName = $brandPhoto->getFilename();
$brandPhotoName = $brandPhotoAsset->getFilename();
} else {
$this->view->website = "";
$this->view->brandExtParent = "";
}
$photo = $brandExtObj->getBottlePhoto();
$bottleImage = $photo->getPath().$photo->getFilename();
$bottleImageName = $photo->getFilename();
if($pgMultiBottleImage)
{
$bottleImageHtml = $pgMultiBottleImage->getThumbnail('PGDetail_HTML')->getHtml(['class' => 'product-image']);
}
else if ($pgMultiFlag)
{
if ($brandPhotoAsset)
{
$bottleImageHtml = $brandPhotoAsset->getThumbnail('PGDetail_HTML')->getHtml(['class' => 'product-image']);
}
}
else
{
$bottleImageHtml = $brandExtObj->getFirstImage('PGDetail_HTML', $this->countryObj)->getHtml(['class' => 'product-image']);
}
$alcoholTypeCategObj = $brandExtObj->getAlcoholType();
if($alcoholTypeCategObj){
$alcoholTypeCateg = $alcoholTypeCategObj[0]->getObject();
$alcoholTypeCateg = $alcoholTypeCateg->getAlcoholType();
}
$this->view->proof = $brandExtObj->getProof();
$this->view->abv = $brandExtObj->getABV();
$this->view->aging = $brandExtObj->getAging($locale);
DataObject\AbstractObject::setHideUnpublished(false);
$variants = $brandExtObj->getSizeVariants($this->countryObj);
DataObject\AbstractObject::setHideUnpublished(true);
if ($variants) {
foreach ($variants as $variants){
if($variants->getBottleSize()!=''){
//bottle sizes
$sizeValue = str_replace(" ml", "", $variants->getBottleSize());
$sizeValue = (int)$sizeValue;
if($sizeValue >= 1000){
$sizeValue = $sizeValue / 1000;
$sizeValue = $sizeValue." L";
}else{
$sizeValue = $variants->getBottleSize();
}
$sizes.=$sizeValue.', ';
}
$countries = $variants->getCountryAvailabilityList();
$continue = 0;
if (count($countries) == 1) {
foreach ($countries as $country) {
if ($country->getObject()->getId() == $this->countryId) {
$this->view->proof = $variants->getProof();
$this->view->abv = $variants->getABV();
}
}
}
}
}
if ($sizes !='') {
$sizes = rtrim($sizes, ', ');
}
$accolades = $brandExtObj->getAccoladesList();
if ($accolades) {
$this->view->accoladeItems = $accolades->getItems();
}
//$tasingNoteItems = $brandExtObj->getlocalizedfields()->getItems();
$tasingNoteItems = array();
$tasingNoteItems['TasteProfileColor'] = $brandExtObj->getTasteProfileColor($locale);
$tasingNoteItems['TasteProfileAroma'] = $brandExtObj->getTasteProfileAroma($locale);
$tasingNoteItems['TasteProfileTaste'] = $brandExtObj->getTasteProfileTaste($locale);
$tasingNoteItems['TasteProfileFinish'] = $brandExtObj->getTasteProfileFinish($locale);
$tasingNoteItems['TasteProfileHeadline'] = $brandExtObj->getTasteProfileHeadline($locale);
$tasingNoteItems['TasteProfileIntro'] = $brandExtObj->getTasteProfileIntro($locale);
$this->view->tastingNotes = $tasingNoteItems;
$brandExtFullDescrHeadline = $brandExtObj->getFullDescriptionHeadline($locale);
$brandExtFullDescr = $brandExtObj->getFullDescription($locale);
$brandExtNameTradeMark = $this->view->brandExtNameTradeMark = $brandExtObj->getBrandExtensionNameTrademark();
$this->view->brandExtName = $brandExtObj->getBrandExtensionName();
if((!$portfolioGuideName || $portfolioGuideName == '') && !$pgMultiFlag){
if (!$brandExtNameTradeMark || $brandExtNameTradeMark == '')
{
$portfolioGuideName = $brandExtObj->getBrandExtensionName();
}
else
{
$portfolioGuideName = $brandExtNameTradeMark;
}
}
}
$altProdDescrHeadline = $pgObject->getAltProductDescrHeadline($locale);
if((!$altProdDescrHeadline || $altProdDescrHeadline == "") && !$pgMultiFlag){
$altProdDescrHeadline = $brandExtFullDescrHeadline;
}
//get other expressions
$otherExpressionsHeadline = $pgObject->getAltExpressionsHeadline($locale);
if(!$otherExpressionsHeadline || $otherExpressionsHeadline == ""){
if ($brand->getBrandNameTrademark()) {
$otherExpressionsHeadline = $brand->getBrandNameTrademark();
} else {
$otherExpressionsHeadline = $brand->getBrandName();
}
}
$otherExpressions = [];
$otherExpressionsList = $pgObject->getOtherPortfolioGuides();
$x = 0;
if ($otherExpressionsList)
{
foreach ($otherExpressionsList as $otherExpression)
{
$otherPG = $otherExpression->getObject();
$otherPGId = $otherPG->getId();
if($otherExpression->getaltdisplayname()){
$otherPGName = $otherExpression->getaltdisplayname();
}
else
{
DataObject\AbstractObject::setHideUnpublished(false);
$otherPGbrandExtensionList = $otherPG->getBrandExtension();
DataObject\AbstractObject::setHideUnpublished(true);
DataObject\AbstractObject::setHideUnpublished(false);
$otherPGNameBrandExt = $otherPG->getBrandExtension();
if ($otherPGNameBrandExt)
{
$otherPGNameBrandExtObj = $otherPGNameBrandExt[0]->getObject();
$countries = $otherPGNameBrandExtObj->getCountryAvailabilityList();
$add = 0;
if ($countries) {
foreach ($countries as $country) {
if ($country->getObject()->getId() == $this->countryId) {
$add = 1;
}
}
if ($add == 0) {
continue;
}
}
if ($otherPG->getAltTitle())
{
$otherPGName = $otherPG->getAltTitle();
}
else
{
$otherPGName = $otherPGNameBrandExtObj->getBrandExtensionNameTrademark();
if (!$otherPGName || $otherPGName == '')
{
$otherPGName = $otherPGNameBrandExtObj->getBrandExtensionName();
}
}
}
DataObject\AbstractObject::setHideUnpublished(true);
if(count($otherPGbrandExtensionList) > 1)
{
}
else
{
}
}
$otherExpressions[$x][0] = $otherPGId;
$otherExpressions[$x][1] = $otherPGName;
$otherExpressions[$x][2] = $otherPG->getKey();
$x++;
}
$this->view->otherExpressionsList = $otherExpressions;
}
$altProdDescr = $pgObject->getAltProductDescr($locale);
if((!$altProdDescr || $altProdDescr == "") && !$pgMultiFlag){
$altProdDescr = $brandExtFullDescr;
}
$this->view->pgMultiFlag = $pgMultiFlag;
$this->view->pgKey = $pgObject->getKey();
$this->view->portfolioGuideName = $portfolioGuideName;
$this->view->paramId = $paramId;
$this->view->alcoholTypeCateg = $alcoholTypeCateg;
$this->view->bottleImageHtml = $bottleImageHtml;
$this->view->altProdDescrHeadline = $altProdDescrHeadline;
$this->view->altProdDescr = $altProdDescr;
$this->view->sizes = $sizes;
$this->view->otherExpressionsHeadline = $otherExpressionsHeadline;
$this->view->bottleImage = $bottleImage;
$this->view->bottleImageName = $bottleImageName;
$this->view->brandPhoto = $brandPhoto;
$this->view->brandPhotoName = $brandPhotoName;
//$this->enableLayout();
}
public function pageAction(Request $request) {
//$this->layout()->setLayout('portfolioguideportal');
//$this->enableLayout();
}
public function footerAction(Request $request) {
}
public function portfolioGuideOrdering()
{
ini_set('memory_limit', '512M');
$order_by = "";
$condition = "";
$limit = "";
$this->view->current_alcohol_type = "";
//$this->layout()->setLayout('portfolioguideportal');
$this->view->CssClass = "sub-category-page";
$headTitleHelper = \Pimcore::getContainer()->get('pimcore.templating.view_helper.head_title');
$headTitleHelper("Portfolio Guide");
$alcohol_type_obj = new DataObject\CategoryAlcoholType();
$brand_obj = new DataObject\Brand();
$brand_extension_obj = new DataObject\BrandExtension();
$portfolio_guide_obj = new DataObject\PortfolioGuide();
$portfolio_brand = DataObject\CategoryAlcoholType::getList();
$locale = $this->locale;
$type_id = ($_REQUEST['type']) ? $_REQUEST['type'] : "";
$brand_id = ($_REQUEST['Brand']) ? $_REQUEST['Brand'] : "";
$search = ($_REQUEST['search']) ? $_REQUEST['search'] : "";
$countryAvailability = ($this->countryId) ? $this->countryId : "";
$count_per_page = ($_REQUEST['counter'])? $_REQUEST['counter']:15;
//the below line gets all Portfolio Guide objects + all the related data, becomes 160MB array and kills php, let's use SQL
//$portfolio_guides_list = Object\PortfolioGuide::getList();
$db = \Pimcore\Db::get();
$result = $db->fetchAll("SELECT COUNT(`oo_id`) as PFG_Number FROM `object_localized_" . $portfolio_guide_obj->getClassId() . "_" . $locale . "` WHERE `o_published` = 1");
$portfolio_guides_list = $result[0]['PFG_Number'];
$count_per_page = ($count_per_page == "all")? $portfolio_guides_list:$count_per_page;
$sorting = ($_REQUEST['sorting'])? $_REQUEST['sorting']:1;
$childs = $this->view->types = \App\Model\DataObject\PortfolioGuide::getAlcoholChilds($type_id);
$child_array = array($type_id);
foreach($childs as $child)
{
$child_array[] = $child->getId();
}
if($type_id)
{
$current_alcohol_type = \App\Model\DataObject\PortfolioGuide::getAlcoholTypeName($type_id);
$this->view->current_alcohol_type = $current_alcohol_type;
}
if ($type_id) {
$condition .= " AND REPLACE(object_localized_" . $brand_extension_obj->getClassId() . "_" . $locale . ".AlcoholType,',','') IN (" . implode(', ', $child_array) . ")";
}
if ($brand_id) {
$condition .= " AND object_localized_" . $brand_extension_obj->getClassId() . "_" . $locale . ".Brand LIKE '%" . $brand_id . "%'";
}
if ($search) {
$condition .= " AND object_localized_" . $brand_extension_obj->getClassId() . "_" . $locale . ".BrandExtensionName LIKE '%" . trim($search) . "%'";
}
if ($countryAvailability) {
$condition .= " AND object_localized_" . $brand_extension_obj->getClassId() . "_" . $locale . ".CountryAvailabilityList LIKE '%" . trim($countryAvailability) . "%'";
}
if ($sorting) {
if ($sorting == 2) {
$order_by = " ORDER BY object_localized_" . $brand_extension_obj->getClassId() . "_" . $locale . ".BrandExtensionName ASC";
} else if ($sorting == 3) {
$order_by = " ORDER BY object_localized_" . $brand_extension_obj->getClassId() . "_" . $locale . ".BrandExtensionName DESC";
} else if ($sorting == 4) {
$order_by = " ORDER BY object_localized_" . $portfolio_guide_obj->getClassId() . "_" . $locale . ".o_modificationDate DESC";
} else {
$order_by = " ORDER BY object_localized_" . $brand_extension_obj->getClassId() . "_" . $locale . ".Brand ASC, Ordering";
}
}
$db = \Pimcore\Db::get();
$start = ($_REQUEST["page"])?($_REQUEST["page"]-1)*$count_per_page:0;
$start = ($start < $portfolio_guides_list)? $start:0;
$limit = " LIMIT ".$start.",".$count_per_page;
$sql = "SELECT "
. "object_localized_" . $portfolio_guide_obj->getClassId() . "_" . $locale . ".oo_id AS guide_id, "
. "object_localized_" . $portfolio_guide_obj->getClassId() . "_" . $locale . ".Order AS Ordering, "
. "object_localized_" . $brand_extension_obj->getClassId() . "_" . $locale . ".o_creationDate AS creation_date,"
. "object_localized_" . $brand_extension_obj->getClassId() . "_" . $locale . ".o_modificationDate AS modification_date, "
. "object_localized_" . $brand_extension_obj->getClassId() . "_" . $locale . ".oo_id AS brand_extension_id, "
. "object_localized_" . $brand_extension_obj->getClassId() . "_" . $locale . ".BrandExtensionNameTrademark, "
. "object_localized_" . $brand_extension_obj->getClassId() . "_" . $locale . ".BrandExtensionName, "
. "object_localized_" . $brand_extension_obj->getClassId() . "_" . $locale . ".FullDescriptionHeadline as brandextDescriptionHeadline, "
. "object_localized_" . $brand_extension_obj->getClassId() . "_" . $locale . ".CountryAvailabilityList, "
. "object_localized_" . $alcohol_type_obj->getClassId() . "_" . $locale . ".*"
. "FROM object_localized_" . $portfolio_guide_obj->getClassId() . "_" . $locale . ""
. " LEFT JOIN object_localized_" . $brand_extension_obj->getClassId() . "_" . $locale . ""
. " ON REPLACE(SUBSTRING_INDEX(object_localized_" . $portfolio_guide_obj->getClassId() . "_" . $locale . ".BrandExtension, ',', 2),',','') = object_localized_" . $brand_extension_obj->getClassId() . "_" . $locale . ".oo_id"
. " LEFT JOIN object_localized_" . $brand_obj->getClassId() . "_" . $locale . ""
. " ON REPLACE(object_localized_" . $brand_extension_obj->getClassId() . "_" . $locale . ".Brand,',','') = object_localized_" . $brand_obj->getClassId() . "_" . $locale . ".oo_id"
. " LEFT JOIN object_localized_" . $alcohol_type_obj->getClassId() . "_" . $locale . ""
. " ON REPLACE(object_localized_" . $brand_extension_obj->getClassId() . "_" . $locale . ".AlcoholType,',','') = object_localized_" . $alcohol_type_obj->getClassId() . "_" . $locale . ".oo_id"
. " WHERE object_localized_" . $portfolio_guide_obj->getClassId() . "_" . $locale . ".o_published=1" . $condition;
$portfolio_guide_all_list = $db->fetchAll($sql);
$this->view->total_items = ceil((count($portfolio_guide_all_list))/$count_per_page);
$portfolio_guide = $db->fetchAll($sql.$order_by.$limit);
$this->view->current_page = ($_REQUEST["page"])?($_REQUEST["page"]):1;
$display_items_id = array();
$all_portfolio_type_count = \App\Model\DataObject\PortfolioGuide::getAlcoholTypeCount($brand_id, $portfolio_guide_all_list);
foreach($this->view->types as $type)
{
$sub_child_count_alcohol[$type->getId()] = 0;
$items = new DataObject\CategoryAlcoholType\Listing();
$items ->setCondition("o_parentId = ?", array($type->getId()));
if($all_portfolio_type_count[$type->getId()])
{
$display_items_id[] = $type->getId();
}
else
{
foreach($items as $item)
{
if($all_portfolio_type_count[$item->getId()])
{
$display_items_id[] = $type->getId();
}
}
}
}
DataObject\AbstractObject::setHideUnpublished(false);
$this->view->brand = DataObject\Brand::getList();
DataObject\AbstractObject::setHideUnpublished(true);
$this->view->portfolio_guide = $portfolio_guide;
$this->view->portfolio_brand_count = \App\Model\DataObject\PortfolioGuide::getBrandCount($type_id, $portfolio_guide_all_list);
$this->view->portfolio_type_count = $all_portfolio_type_count;
$this->view->initial_display_alcohol_type = $display_items_id;
//$this->enableLayout();
}
}