<?php
namespace App\Zet\ContentBundle\Services;
use App\Zet\ContentBundle\Entity\ContentBlock;
use App\Zet\ContentBundle\Util\ContentBlockHandler;
use Doctrine\ORM\EntityManagerInterface;
use App\Zet\ContentBundle\Entity\Content;
class TwigGlobalService
{
private $em;
private $handler;
const BANNER_CATEGORY = 1;
const ABOUT_CATEGORY = 2;
const NEWS_CATEGORY = 3;
public function __construct(EntityManagerInterface $em, ContentBlockHandler $handler)
{
$this->em = $em;
$this->handler = $handler;
}
private function getBlock($code){
if(!$model = $this->em->getRepository(ContentBlock::class)->findOneBy(['code' => $code])){
$model = new ContentBlock();
$model->setCode($code);
$this->em->persist($model);
$this->em->flush();
}
return $model->getBlockText();
}
public function isIe($agent){
if( strpos($agent, 'MSIE') !== FALSE ){
return true;
}
if(strpos($agent, 'Trident/') !== FALSE){
return true;
}
return false;
}
public function getHeaderContactBlock(){
return $this->getBlock('HeaderContact');
}
public function getFooterBlock(){
return $this->getBlock('FooterBlock');
}
public function getBanner(){
return $this->em->getRepository(Content::class)->findByCategory(self::BANNER_CATEGORY);
}
public function getAbout(){
return $this->em->getRepository(Content::class)->findByCategory(self::ABOUT_CATEGORY);
}
public function getNews(){
return $this->em->getRepository(Content::class)->findByCategory(self::NEWS_CATEGORY);
}
public function getLocaleNames(){
return ['en', 'uk', 'ru'];
}
public function getCopyright(){
return $this->handler->getCopyright();
}
public function getPhones(){
return $this->handler->getPhones();
}
public function getUrl(){
return $this->handler->getUrl();
}
public function getProjectName(){
return $this->handler->getProjectName();
}
public function getFacebookLink(){
return $this->handler->getFacebookLink();
}
public function getYouTubeLink(){
return $this->handler->getYouTubeLink();
}
public function getInstagramLink(){
return $this->handler->getInstagramLink();
}
public function getGooglePlusLink(){
return $this->handler->getGooglePlusLink();
}
}