<?php
namespace FoxHabbit\BasisBundle\Document\Areabrick\Parts;
use AppBundle\Service\PartnersService;
use FoxHabbit\BasisBundle\Document\AreabrickTwig;
use Pimcore\Config;
use Pimcore\Model\DataObject\Partner;
use Pimcore\Model\Document\Editable\Area\Info;
class BasisbundlePartGooglemap extends AreabrickTwig
{
protected $partnersService;
protected $config;
public function __construct(PartnersService $partnersService, Config $config)
{
$this->partnersService = $partnersService;
$this->config = $config;
}
protected function getTemplateSubfolder()
{
return 'parts/';
}
/**
* @param Info $info
*
* @throws \Exception
*/
public function action(Info $info)
{
parent::action($info);
//$config = Config::getSystemConfig();
$googleMapsKey = null;
$googleMapsKeySetting = \Pimcore\Model\WebsiteSetting::getByName('GoogleMapsKey');
if($googleMapsKeySetting){
$googleMapsKey = $googleMapsKeySetting->getData();
}
$info->setParam("apikey", $googleMapsKey);
// ===========================================
// Dealer search stuff
// ===========================================
$preselectedPartnerType = $this->getDocumentEditable($info->getDocument(), 'select', 'preselected_partners')->getData();
$preselectedCountry = $this->getDocumentEditable($info->getDocument(), 'select', 'preselected_country')->getData();
if( $preselectedCountry && strlen( $preselectedCountry) !== 2) {
$preselectedCountry = null;
}
$partnersList = new Partner\Listing();
$partnersList->setOrderKey("companyName");
$partnersList->filterByTypeFieldKEI(0);
$partnersTypes = PartnersService::getPartnerTypes();
if ($preselectedPartnerType && in_array($preselectedPartnerType, $partnersTypes)) {
if( $preselectedCountry) {
$partnersList->setCondition("`typeField".$preselectedPartnerType."` and country = ?", [$preselectedCountry]);
} else {
$partnersList->setCondition("`typeField".$preselectedPartnerType."`");
}
} else {
if( $preselectedCountry) {
$partnersList->setCondition("country = ?", [$preselectedCountry]);
}
$preselectedPartnerType = 'all';
}
$countries = $this->partnersService->getPartnerCountries($partnersList);
$partners = $this->partnersService->partnersDisplayDataForPartnersList($partnersList,$info->getRequest()->getLocale(), $info->getDocument());
$info->setParam("countries", $countries);
$info->setParam("preselectedPartnerType", $preselectedPartnerType);
$info->setParam("partners", $partners);
$info->setParam("numberOfPartners", count($partners));
$info->setParam("validPartnerTypes", $partnersTypes);
}
}