src/Zet/ContentBundle/Util/ContentBlockHandler.php line 37

Open in your IDE?
  1. <?php
  2. /**
  3.  * Created by PhpStorm.
  4.  * User: oleksandrarhat
  5.  * Date: 2020-03-25
  6.  * Time: 06:28
  7.  */
  8. namespace App\Zet\ContentBundle\Util;
  9. use App\Zet\ContentBundle\Entity\ContentBlock;
  10. use Doctrine\ORM\EntityManagerInterface;
  11. use Symfony\Component\DependencyInjection\ParameterBag\ContainerBagInterface;
  12. use Symfony\Contracts\Translation\TranslatorInterface;
  13. class ContentBlockHandler
  14. {
  15.     private $em;
  16.     private $translator;
  17.     private $containerBag;
  18.     function __construct(
  19.         EntityManagerInterface $em,
  20.         TranslatorInterface $translator,
  21.         ContainerBagInterface $containerBag
  22.     )
  23.     {
  24.         $this->em $em;
  25.         $this->translator $translator;
  26.         $this->containerBag $containerBag;
  27.     }
  28.     private function getOrCreateBlockText($code){
  29.         /* @var $repo \App\Zet\ContentBundle\Repository\ContentBlockRepository */
  30.         $repo $this->em->getRepository(ContentBlock::class);
  31.         if(! $entity $repo->finByCode($code)){
  32.             $entity = new ContentBlock();
  33.             $entity->setCode($code);
  34.             $this->em->persist($entity);
  35.             $this->em->flush();
  36.         }
  37.         return $entity->getBlockText();
  38.     }
  39.     public function getCopyright(){
  40.         return $this->getOrCreateBlockText('copyright');
  41.     }
  42.     public function getFacebookLink(){
  43.         return $this->getOrCreateBlockText('facebookLink');
  44.     }
  45.     public function getInstagramLink(){
  46.         return $this->getOrCreateBlockText('instagramLink');
  47.     }
  48.     public function getTelegramLink(){
  49.         return $this->getOrCreateBlockText('telegramLink');
  50.     }
  51.     public function getYouTubeLink(){
  52.         return $this->getOrCreateBlockText('youTubeLink');
  53.     }
  54.     public function getGooglePlusLink(){
  55.         return $this->getOrCreateBlockText('googlePlusLink');
  56.     }
  57.     /**
  58.      * @return string[]
  59.      */
  60.     function getPhones(){
  61.         $data = [];
  62.         $cont $this->getOrCreateBlockText('phones');
  63.         foreach (explode(','$cont) as $row){
  64.             $data[] = trim($row);
  65.         }
  66.         return $data;
  67.     }
  68.     function getEmail(){
  69.         return $this->getOrCreateBlockText('email');
  70.     }
  71.     function getEmailFooter(){
  72.         return $this->getOrCreateBlockText('emailFooter');
  73.     }
  74.     /**
  75.      * @return array
  76.      */
  77.     function getMessengers(){
  78.         $cont $this->getOrCreateBlockText('messengers');
  79.         $data = [];
  80.         foreach (explode(', '$cont) as $row){
  81.             $pair explode(":"$row);
  82.             if(count($pair) == 2){
  83.                 $data[] = [trim($pair[0]) => trim($pair[1])];
  84.             }
  85.         }
  86.         return $data;
  87.     }
  88.     function getApiWelcome(){
  89.         return $this->getOrCreateBlockText('api_welcome');
  90.     }
  91.     function getThankBlock(){
  92.         return $this->getOrCreateBlockText('thank');
  93.     }
  94.     function getScheduleInfo(){
  95.         return $this->getOrCreateBlockText('scheduleInfo');
  96.     }
  97.     function getUploadCartInfo(){
  98.         return $this->getOrCreateBlockText('uploadCartInfo');
  99.     }
  100.     function getUrl(){
  101.         return $this->getOrCreateBlockText('url');
  102.     }
  103.     function getProjectName(){
  104.         if(! $name $this->getOrCreateBlockText('project_name')){
  105.             $name 'B2B Store';
  106.         }
  107.         return $name;
  108.     }
  109.     function getOrderInfo(){
  110.         return $this->getOrCreateBlockText('order_info');
  111.     }
  112. }