src/Zet/ContentBundle/Services/TwigGlobalService.php line 79

Open in your IDE?
  1. <?php
  2. namespace App\Zet\ContentBundle\Services;
  3. use App\Zet\ContentBundle\Entity\ContentBlock;
  4. use App\Zet\ContentBundle\Util\ContentBlockHandler;
  5. use Doctrine\ORM\EntityManagerInterface;
  6. use App\Zet\ContentBundle\Entity\Content;
  7. class TwigGlobalService
  8. {
  9.     private $em;
  10.     private $handler;
  11.     const BANNER_CATEGORY 1;
  12.     const ABOUT_CATEGORY 2;
  13.     const NEWS_CATEGORY 3;
  14.     public function __construct(EntityManagerInterface $emContentBlockHandler $handler)
  15.     {
  16.         $this->em $em;
  17.         $this->handler $handler;
  18.     }
  19.     private function getBlock($code){
  20.         if(!$model $this->em->getRepository(ContentBlock::class)->findOneBy(['code' => $code])){
  21.             $model = new ContentBlock();
  22.             $model->setCode($code);
  23.             $this->em->persist($model);
  24.             $this->em->flush();
  25.         }
  26.         return $model->getBlockText();
  27.     }
  28.     public function isIe($agent){
  29.         if( strpos($agent'MSIE') !== FALSE ){
  30.             return true;
  31.         }
  32.         if(strpos($agent'Trident/') !== FALSE){
  33.             return true;
  34.         }
  35.         return false;
  36.     }
  37.     public function getHeaderContactBlock(){
  38.         return $this->getBlock('HeaderContact');
  39.     }
  40.     public function getFooterBlock(){
  41.         return $this->getBlock('FooterBlock');
  42.     }
  43.     public function getBanner(){
  44.         return $this->em->getRepository(Content::class)->findByCategory(self::BANNER_CATEGORY);
  45.     }
  46.     public function getAbout(){
  47.         return $this->em->getRepository(Content::class)->findByCategory(self::ABOUT_CATEGORY);
  48.     }
  49.     public function getNews(){
  50.         return $this->em->getRepository(Content::class)->findByCategory(self::NEWS_CATEGORY);
  51.     }
  52.     public function getLocaleNames(){
  53.         return ['en''uk''ru'];
  54.     }
  55.     public function getCopyright(){
  56.         return $this->handler->getCopyright();
  57.     }
  58.     public function getPhones(){
  59.         return $this->handler->getPhones();
  60.     }
  61.     public function getUrl(){
  62.         return $this->handler->getUrl();
  63.     }
  64.     public function getProjectName(){
  65.         return $this->handler->getProjectName();
  66.     }
  67.     public function getFacebookLink(){
  68.         return $this->handler->getFacebookLink();
  69.     }
  70.     public function getYouTubeLink(){
  71.         return $this->handler->getYouTubeLink();
  72.     }
  73.     public function getInstagramLink(){
  74.         return $this->handler->getInstagramLink();
  75.     }
  76.     public function getGooglePlusLink(){
  77.         return $this->handler->getGooglePlusLink();
  78.     }
  79. }