src/CmsBundle/Entity/Site.php line 24

Open in your IDE?
  1. <?php
  2. namespace App\CmsBundle\Entity;
  3. use App\CasinoBundle\Entity\Country;
  4. use App\CasinoBundle\Entity\NewBonus;
  5. use App\CmsBundle\Enum\LogActionEnum;
  6. use Doctrine\Common\Collections\ArrayCollection;
  7. use Doctrine\Common\Collections\Collection;
  8. use Doctrine\ORM\Mapping as ORM;
  9. /**
  10.  * @ORM\Table(
  11.  *     name="site",
  12.  *     indexes={
  13.  *         @ORM\Index(name="site_default_locale_index", columns={"default_locale_id"}),
  14.  *         @ORM\Index(name="site_default_country_index", columns={"default_country_id"}),
  15.  *         @ORM\Index(name="site_canonical_index", columns={"canonical_id"})
  16.  *     }
  17.  * )
  18.  * @ORM\Entity(repositoryClass="App\CmsBundle\Repository\SiteRepository")
  19.  * @ORM\HasLifecycleCallbacks()
  20.  */
  21. class Site implements LogInterface
  22. {
  23.     use IdTraitTitleTraitTimeStampedTraitParametersTraitLogTrait;
  24.     /**
  25.      * @ORM\Column(type="string", length=255)
  26.      */
  27.     private $domain;
  28.     /**
  29.      * @ORM\OneToOne(targetEntity="App\CmsBundle\Entity\SiteInfo", mappedBy="site", cascade={"persist","remove"})
  30.      */
  31.     private $info;
  32.     /**
  33.      * @ORM\Column(type="string", length=255, nullable=true)
  34.      */
  35.     private $template;
  36.     /**
  37.      * @ORM\Cache("NONSTRICT_READ_WRITE")
  38.      * @ORM\ManyToOne(targetEntity="App\CmsBundle\Entity\Locale", cascade={"persist"})
  39.      */
  40.     private $defaultLocale;
  41.     /**
  42.      * @ORM\Cache("NONSTRICT_READ_WRITE")
  43.      * @ORM\ManyToOne(targetEntity="App\CasinoBundle\Entity\Country", cascade={"persist"})
  44.      */
  45.     private $defaultCountry;
  46.     /**
  47.      * @var ArrayCollection
  48.      * @ORM\OneToMany(targetEntity="App\CmsBundle\Entity\Route", mappedBy="site", cascade={"persist","remove"})
  49.      */
  50.     private $routes;
  51.     /**
  52.      * @var ArrayCollection
  53.      * @ORM\OneToMany(targetEntity="App\CmsBundle\Entity\Redirect", mappedBy="site", cascade={"persist","remove"})
  54.      */
  55.     private $redirects;
  56.     /**
  57.      * @var ArrayCollection
  58.      * @ORM\JoinColumn(nullable=true)
  59.      * @ORM\OneToMany(targetEntity="App\CmsBundle\Entity\Directory", mappedBy="site", cascade={"persist","remove"})
  60.      */
  61.     private $directories;
  62.     /**
  63.      * @ORM\ManyToMany(targetEntity="App\CmsBundle\Entity\Locale", inversedBy="availableSites", cascade={"persist"})
  64.      * @ORM\JoinTable(
  65.      *     name="site_locale",
  66.      *     joinColumns={
  67.      *          @ORM\JoinColumn(name="site_id", referencedColumnName="id")
  68.      *     },
  69.      *     inverseJoinColumns={
  70.      *          @ORM\JoinColumn(name="locale_id", referencedColumnName="id")
  71.      *     }
  72.      * )
  73.      */
  74.     protected $availableLocales;
  75.     /**
  76.      * @ORM\OneToMany(targetEntity="App\CmsBundle\Entity\Menu", mappedBy="site", cascade={"persist","remove"})
  77.      */
  78.     private $menus;
  79.     /**
  80.      * @ORM\OneToMany(targetEntity="App\CmsBundle\Entity\SitemapImport", mappedBy="site", cascade={"persist","remove"})
  81.      */
  82.     private $sitemapImports;
  83.     /**
  84.      * @ORM\ManyToOne(targetEntity="App\CmsBundle\Entity\Site", inversedBy="canonicals", fetch="EAGER")
  85.      * @ORM\JoinColumn(nullable=true)
  86.      */
  87.     private $canonical;
  88.     /**
  89.      * @ORM\OneToMany(targetEntity="App\CmsBundle\Entity\Site", mappedBy="canonical", cascade={"persist","remove"})
  90.      */
  91.     private $canonicals;
  92.     /**
  93.      * @ORM\ManyToMany(
  94.      *     targetEntity="App\CasinoBundle\Entity\NewBonus",
  95.      *     mappedBy="sites",
  96.      *     cascade={"persist"}
  97.      * )
  98.      */
  99.     private Collection $newBonuses;
  100.     /**
  101.      * @ORM\ManyToOne(targetEntity="App\CmsBundle\Entity\Site", inversedBy="relates", fetch="EXTRA_LAZY")
  102.      * @ORM\JoinColumn(nullable=true)
  103.      */
  104.     private $relatedTo;
  105.     /**
  106.      * @ORM\OneToMany(targetEntity="App\CmsBundle\Entity\Site", mappedBy="relatedTo", cascade={"persist","remove"})
  107.      */
  108.     private $relates;
  109.     public function __toString()
  110.     {
  111.         return $this->domain;
  112.     }
  113.     public function __construct()
  114.     {
  115.         $this->info = (new SiteInfo())->setSite($this);
  116.         $this->availableLocales = new ArrayCollection();
  117.         $this->canonicals = new ArrayCollection();
  118.         $this->directories = new ArrayCollection();
  119.         $this->routes = new ArrayCollection();
  120.         $this->newBonuses = new ArrayCollection();
  121.         $this->parameters json_encode([]);
  122.         $this->relates = new ArrayCollection();
  123.     }
  124.     /**
  125.      * @return string|null
  126.      */
  127.     public function getTitle(): ?string
  128.     {
  129.         return ($this->getCanonical())
  130.             ? $this->getCanonical()->getTitle()
  131.             : $this->title;
  132.     }
  133.     /**
  134.      * @return string|null
  135.      */
  136.     public function getDomain(): ?string
  137.     {
  138.         return $this->domain;
  139.     }
  140.     /**
  141.      * @param string $domain
  142.      * @return $this
  143.      */
  144.     public function setDomain(string $domain): self
  145.     {
  146.         $this->domain $domain;
  147.         if (!$this->title) {
  148.             $this->setTitle($domain);
  149.         }
  150.         return $this;
  151.     }
  152.     /**
  153.      * @return string|null
  154.      */
  155.     public function getTemplate(): ?string
  156.     {
  157.         return $this->template;
  158.     }
  159.     /**
  160.      * @param string|null $template
  161.      * @return $this
  162.      */
  163.     public function setTemplate(?string $template): self
  164.     {
  165.         $this->template $template;
  166.         return $this;
  167.     }
  168.     /**
  169.      * @return SiteInfo|null
  170.      */
  171.     public function getInfo(): ?SiteInfo
  172.     {
  173.         return $this->info;
  174.     }
  175.     /**
  176.      * @param SiteInfo $info
  177.      * @return $this
  178.      */
  179.     public function setInfo(SiteInfo $info): self
  180.     {
  181.         $this->info $info;
  182.         return $this;
  183.     }
  184.     /**
  185.      * @return Locale|null
  186.      */
  187.     public function getDefaultLocale(): ?Locale
  188.     {
  189.         return $this->defaultLocale;
  190.     }
  191.     /**
  192.      * @param Locale|null $defaultLocale
  193.      * @return $this
  194.      */
  195.     public function setDefaultLocale(?Locale $defaultLocale): self
  196.     {
  197.         $this->defaultLocale $defaultLocale;
  198.         return $this;
  199.     }
  200.     /**
  201.      * @return Country|null
  202.      */
  203.     public function getDefaultCountry(): ?Country
  204.     {
  205.         return $this->defaultCountry;
  206.     }
  207.     /**
  208.      * @param Country|null $defaultCountry
  209.      * @return $this
  210.      */
  211.     public function setDefaultCountry(?Country $defaultCountry): self
  212.     {
  213.         $this->defaultCountry $defaultCountry;
  214.         return $this;
  215.     }
  216.     /**
  217.      * @return Collection|Route[]
  218.      */
  219.     public function getRoutes(): Collection
  220.     {
  221.         return $this->routes;
  222.     }
  223.     /**
  224.      * @param Route $route
  225.      * @return $this
  226.      */
  227.     public function addRoute(Route $route): self
  228.     {
  229.         if (!$this->routes->contains($route)) {
  230.             $this->routes->add($route);
  231.             $this->addCollectionLog(LogActionEnum::ADD'route'$route);
  232.         }
  233.         return $this;
  234.     }
  235.     /**
  236.      * @param Route $route
  237.      * @return $this
  238.      */
  239.     public function removeRoute(Route $route): self
  240.     {
  241.         if ($this->routes->contains($route)) {
  242.             $this->routes->removeElement($route);
  243.             $this->addCollectionLog(LogActionEnum::REMOVE'route'$route);
  244.         }
  245.         return $this;
  246.     }
  247.     /**
  248.      * @return Collection|Redirect[]
  249.      */
  250.     public function getRedirects(): Collection
  251.     {
  252.         return $this->redirects;
  253.     }
  254.     /**
  255.      * @param Redirect $redirect
  256.      * @return $this
  257.      */
  258.     public function addRedirect(Redirect $redirect): self
  259.     {
  260.         if (!$this->redirects->contains($redirect)) {
  261.             $this->redirects->add($redirect);
  262.             $this->addCollectionLog(LogActionEnum::ADD'redirect'$redirect);
  263.         }
  264.         return $this;
  265.     }
  266.     /**
  267.      * @param Redirect $redirect
  268.      * @return $this
  269.      */
  270.     public function removeRedirect(Redirect $redirect): self
  271.     {
  272.         if ($this->redirects->contains($redirect)) {
  273.             $this->redirects->removeElement($redirect);
  274.             $this->addCollectionLog(LogActionEnum::REMOVE'redirect'$redirect);
  275.         }
  276.         return $this;
  277.     }
  278.     /**
  279.      * @return Collection|Menu[]
  280.      */
  281.     public function getMenus(): Collection
  282.     {
  283.         return $this->menus;
  284.     }
  285.     /**
  286.      * @param Menu $menu
  287.      * @return $this
  288.      */
  289.     public function addMenu(Menu $menu): self
  290.     {
  291.         if (!$this->menus->contains($menu)) {
  292.             $this->menus->add($menu);
  293.             $this->addCollectionLog(LogActionEnum::ADD'menu'$menu);
  294.         }
  295.         return $this;
  296.     }
  297.     /**
  298.      * @param Menu $menu
  299.      * @return $this
  300.      */
  301.     public function removeMenu(Menu $menu): self
  302.     {
  303.         if ($this->menus->contains($menu)) {
  304.             $this->menus->removeElement($menu);
  305.             $this->addCollectionLog(LogActionEnum::REMOVE'menu'$menu);
  306.         }
  307.         return $this;
  308.     }
  309.     /**
  310.      * @return Collection|Locale[]
  311.      */
  312.     public function getAvailableLocales(): Collection
  313.     {
  314.         return $this->availableLocales;
  315.     }
  316.     /**
  317.      * @param Locale $locale
  318.      * @return $this
  319.      */
  320.     public function addAvailableLocale(Locale $locale): self
  321.     {
  322.         if (!$this->availableLocales->contains($locale)) {
  323.             $this->availableLocales[] = $locale;
  324.             $this->addCollectionLog(LogActionEnum::ADD'availableLocale'$locale);
  325.         }
  326.         return $this;
  327.     }
  328.     /**
  329.      * @param Locale $locale
  330.      * @return $this
  331.      */
  332.     public function removeAvailableLocale(Locale $locale): self
  333.     {
  334.         if ($this->availableLocales->contains($locale)) {
  335.             $this->availableLocales->removeElement($locale);
  336.             $this->addCollectionLog(LogActionEnum::REMOVE'availableLocale'$locale);
  337.         }
  338.         return $this;
  339.     }
  340.     /**
  341.      * @return Site|null
  342.      */
  343.     public function getCanonical(): ?Site
  344.     {
  345.         return $this->canonical;
  346.     }
  347.     /**
  348.      * @param Site|null $canonical
  349.      * @return $this
  350.      */
  351.     public function setCanonical(?Site $canonical): self
  352.     {
  353.         $this->canonical $canonical;
  354.         return $this;
  355.     }
  356.     /**
  357.      * @return Collection|Site[]
  358.      */
  359.     public function getCanonicals(): Collection
  360.     {
  361.         return $this->canonicals;
  362.     }
  363.     public function addCanonical(Site $canonical): self
  364.     {
  365.         if (!$this->canonicals->contains($canonical)) {
  366.             $this->canonicals[] = $canonical;
  367.             $canonical->setCanonical($this);
  368.             $this->addCollectionLog(LogActionEnum::ADD'canonical'$canonical);
  369.         }
  370.         return $this;
  371.     }
  372.     public function removeCanonical(Site $canonical): self
  373.     {
  374.         if ($this->canonicals->contains($canonical)) {
  375.             $this->canonicals->removeElement($canonical);
  376.             // set the owning side to null (unless already changed)
  377.             if ($canonical->getCanonical() === $this) {
  378.                 $canonical->setCanonical(null);
  379.             }
  380.             $this->addCollectionLog(LogActionEnum::REMOVE'canonical'$canonical);
  381.         }
  382.         return $this;
  383.     }
  384.     /**
  385.      * @return Collection
  386.      */
  387.     public function getDirectories(): Collection
  388.     {
  389.         return $this->directories;
  390.     }
  391.     /**
  392.      * @param Directory $directory
  393.      * @return $this
  394.      */
  395.     public function addDirectory(Directory $directory): self
  396.     {
  397.         if (!$this->directories->contains($directory)) {
  398.             $this->directories[] = $directory;
  399.             $directory->setSite($this);
  400.             $this->addCollectionLog(LogActionEnum::ADD'directory'$directory);
  401.         }
  402.         return $this;
  403.     }
  404.     /**
  405.      * @param Directory $directory
  406.      * @return $this
  407.      */
  408.     public function removeDirectory(Directory $directory): self
  409.     {
  410.         if ($this->directories->contains($directory)) {
  411.             $this->directories->removeElement($directory);
  412.             // set the owning side to null (unless already changed)
  413.             if ($directory->getSite() === $this) {
  414.                 $directory->setSite(null);
  415.             }
  416.             $this->addCollectionLog(LogActionEnum::REMOVE'directory'$directory);
  417.         }
  418.         return $this;
  419.     }
  420.     /**
  421.      * @return Collection
  422.      */
  423.     public function getNewBonuses(): Collection
  424.     {
  425.         return $this->newBonuses;
  426.     }
  427.     /**
  428.      * @param NewBonus $newBonus
  429.      * @return $this
  430.      */
  431.     public function addNewBonus(NewBonus $newBonus): self
  432.     {
  433.         if (!$this->newBonuses->contains($newBonus)) {
  434.             $this->newBonuses[] = $newBonus;
  435.             $newBonus->addSite($this);
  436.             $this->addCollectionLog(LogActionEnum::ADD'newBonus'$newBonus);
  437.         }
  438.         return $this;
  439.     }
  440.     /**
  441.      * @param NewBonus $newBonus
  442.      * @return $this
  443.      */
  444.     public function removeNewBonus(NewBonus $newBonus): self
  445.     {
  446.         if ($this->newBonuses->contains($newBonus)) {
  447.             $this->newBonuses->removeElement($newBonus);
  448.             $newBonus->removeSite($this);
  449.             $this->addCollectionLog(LogActionEnum::REMOVE'newBonus'$newBonus);
  450.         }
  451.         return $this;
  452.     }
  453.     /**
  454.      * @return Site|null
  455.      */
  456.     public function getRelatedTo(): ?Site
  457.     {
  458.         return $this->relatedTo;
  459.     }
  460.     /**
  461.      * @param Site|null $relatedTo
  462.      * @return $this
  463.      */
  464.     public function setRelatedTo(?Site $relatedTo): self
  465.     {
  466.         $this->relatedTo $relatedTo;
  467.         return $this;
  468.     }
  469.     /**
  470.      * @return Collection|Site[]
  471.      */
  472.     public function getRelates(): Collection
  473.     {
  474.         return $this->relates;
  475.     }
  476.     /**
  477.      * @param Site $relate
  478.      * @return $this
  479.      */
  480.     public function addRelates(Site $relate): self
  481.     {
  482.         if (!$this->relates->contains($relate)) {
  483.             $this->relates[] = $relate;
  484.             $relate->setRelatedTo($this);
  485.             $this->addCollectionLog(LogActionEnum::ADD'relates'$relate);
  486.         }
  487.         return $this;
  488.     }
  489.     /**
  490.      * @param Site $relate
  491.      * @return $this
  492.      */
  493.     public function removeRelates(Site $relate): self
  494.     {
  495.         if ($this->relates->contains($relate)) {
  496.             $this->relates->removeElement($relate);
  497.             if ($relate->getRelatedTo() === $this) {
  498.                 $relate->setRelatedTo(null);
  499.             }
  500.             $this->addCollectionLog(LogActionEnum::REMOVE'relates'$relate);
  501.         }
  502.         return $this;
  503.     }
  504. }