src/Service/Sites.php line 138

Open in your IDE?
  1. <?php
  2. namespace App\Service;
  3. use App\Entity\SettingsSite;
  4. use App\Entity\Site;
  5. use App\Entity\Theme;
  6. use Symfony\Component\HttpClient\CurlHttpClient;
  7. use Symfony\Component\HttpFoundation\Response;
  8. use Symfony\Component\Serializer\Serializer;
  9. use Symfony\Component\Serializer\Encoder\XmlEncoder;
  10. use Symfony\Component\Serializer\Encoder\JsonEncoder;
  11. use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
  12. use App\Entity\Pages;
  13. use Doctrine\ORM\EntityManagerInterface;
  14. use Symfony\Component\Serializer\SerializerInterface;
  15. class Sites
  16. {
  17.     protected $em;
  18.     protected $serializer;
  19.     protected $settingsTheme;
  20.     public function __construct(EntityManagerInterface $emSerializerInterface $serializerSettings $settings)
  21.     {
  22.         $this->em $em;
  23.         $this->serializer $serializer;
  24.         $this->settingsTheme $settings;
  25.     }
  26.     public function create($userID$host$alias$hash$theme)
  27.     {
  28.         $this->show($host$userID);
  29.         if (!$this->show($host$userID)) {
  30.             $em $this->em;
  31.             $themes $em->getRepository(Theme::class)->findBy(array('id' => $theme));
  32.             $site = new Site();
  33.             $site->setUsercliclishop($userID);
  34.             $site->setHashCatalog($hash);
  35.             $site->setAlias($alias);
  36.             $site->setHost($host);
  37.             $site->setDateCreate(new \DateTime());
  38.             $site->setStatus(true);
  39.             $site->setTheme($themes[0]);
  40.             $em->persist($site);
  41.             $this->settingsTheme->create($themes[0], $site);
  42.             $idSite $site->getId();
  43.             $em->flush();
  44.             return array('id' => $idSite,
  45.                 'text' => 'ok');
  46.         } else {
  47.             return array('text' => 'Уже существует');
  48.         }
  49.     }
  50.     public function edit($idSite$userID$hash$alias$host$idTheme)
  51.     {
  52.         $em $this->em;
  53.         $site $em->getRepository(Site::class)->findBy(array('id' => $idSite));
  54.         $themes $em->getRepository(Theme::class)->findBy(array('id' => $idTheme));
  55.         $site[0]->setUsercliclishop($userID);
  56.         $site[0]->setHashCatalog($hash);
  57.         $site[0]->setAlias($alias);
  58.         $site[0]->setHost($host);
  59.         $site[0]->setDateCreate(new \DateTime());
  60.         $site[0]->setStatus(true);
  61.         $site[0]->setTheme($themes[0]);
  62.         if (!$this->settingsTheme->show($themes[0]->getId(), $idSite)) {
  63.             $this->settingsTheme->create($themes[0], $site[0]);
  64.         }
  65.         $em->persist($site[0]);
  66.         $em->flush();
  67.         return array('id' => $idSite,
  68.             'text' => 'ok');
  69.     }
  70. //Все сайты пользователя
  71.     public function showAll($idUser)
  72.     {
  73.         $em $this->em;
  74.         if ($idUser == 2){
  75.             $sites $em->getRepository(Site::class)->findAll();
  76.         }
  77.         else{
  78.             $sites $em->getRepository(Site::class)->findBy(array('usercliclishop' => $idUser));
  79.         }
  80.         return $sites;
  81.     }
  82.     //Все сайты в системе
  83.     public function showAllFull()
  84.     {
  85.         $em $this->em;
  86.         $sites $em->getRepository(Site::class)->findAll();
  87.         return $sites;
  88.     }
  89.     public function showIdSite($idSite)
  90.     {
  91.         $em $this->em;
  92.         $site $em->getRepository(Site::class)->findBy(array('id' => $idSite));
  93.         return $site;
  94.     }
  95.     public function showHash($host)
  96.     {
  97.         $em $this->em;
  98.         $site $em->getRepository(Site::class)->findBy(array('host' => $host));
  99.         return $site[0];
  100.     }
  101.     public function show($host$idUser$idSite null)
  102.     {
  103.         $em $this->em;
  104.         if ($host) {
  105.             $site $em->getRepository(Site::class)->findBy(array('host' => $host));
  106.         } else {
  107.             $site $em->getRepository(Site::class)->findBy(array('usercliclishop' => $idUser'id' => $idSite));
  108.         }
  109.         return $site;
  110.     }
  111.     public function delete($idStore)
  112.     {
  113.         $em $this->em;
  114.         $store $em->getRepository(Store::class)->findBy(array('id' => $idStore));
  115.         $em->remove($store[0]);
  116.         $em->flush();
  117.     }
  118.     public function showSettings($idSite$idTheme)
  119.     {
  120.         $em $this->em;
  121.         $settings $em->getRepository(SettingsSite::class)->findOneBy(array('theme' => $idTheme'site' => $idSite));
  122.         if ($settings) {
  123.             return $settings;
  124.         } else {
  125.             return [];
  126.         }
  127.     }
  128. }