src/CmsBundle/Entity/Route.php line 27

Open in your IDE?
  1. <?php
  2. namespace App\CmsBundle\Entity;
  3. use App\CasinoBundle\Entity\Author;
  4. use App\CmsBundle\Enum\LogActionEnum;
  5. use Doctrine\ORM\Mapping as ORM;
  6. use Doctrine\Common\Collections\ArrayCollection;
  7. use Doctrine\Common\Collections\Collection;
  8. /**
  9.  * @ORM\Entity(
  10.  *     repositoryClass="App\CmsBundle\Repository\RouteRepository"
  11.  * )
  12.  * @ORM\Table(
  13.  *     name="route",
  14.  *     indexes={
  15.  *         @ORM\Index(name="route_site_index", columns={"site_id"}),
  16.  *         @ORM\Index(name="route_position_index", columns={"position"}),
  17.  *         @ORM\Index(name="route_parent_route_index", columns={"parent_route_id"}),
  18.  *         @ORM\Index(name="route_related_route_index", columns={"related_to_id"}),
  19.  *         @ORM\Index(name="route_author_index", columns={"author_id"}),
  20.  *         @ORM\Index(name="route_reviewer_index", columns={"reviewer_id"})
  21.  *     }
  22.  * )
  23.  */
  24. class Route implements LogInterface
  25. {
  26.     use ParametersTraitPositionTraitIdTraitTitleTraitSiteTraitDescriptionTraitLogTrait;
  27.     /**
  28.      * @ORM\ManyToOne(targetEntity="App\CmsBundle\Entity\Route", inversedBy="relates", fetch="EXTRA_LAZY")
  29.      * @ORM\JoinColumn(nullable=true)
  30.      */
  31.     private $relatedTo;
  32.     /**
  33.      * @ORM\OneToMany(targetEntity="App\CmsBundle\Entity\Route", mappedBy="relatedTo", cascade={"persist"})
  34.      */
  35.     private $relates;
  36.     /**
  37.      * @ORM\Column(type="string", length=255)
  38.      */
  39.     private $urlPattern;
  40.     /**
  41.      * @ORM\ManyToOne(targetEntity="App\CmsBundle\Entity\Site", inversedBy="routes")
  42.      * @ORM\JoinColumn(nullable=false, onDelete="CASCADE")
  43.      */
  44.     private $site;
  45.     /**
  46.      * @var ArrayCollection
  47.      * @ORM\OneToMany(targetEntity="App\CmsBundle\Entity\Widget", mappedBy="route", cascade={"persist"}, orphanRemoval=true)
  48.      * @ORM\JoinColumn(nullable=false)
  49.      */
  50.     protected $widgets;
  51.     /**
  52.      * @var ArrayCollection
  53.      * @ORM\OneToMany(targetEntity="App\CmsBundle\Entity\Page", mappedBy="route", cascade={"persist","remove"}, orphanRemoval=true)
  54.      * @ORM\JoinColumn(nullable=false)
  55.      */
  56.     protected $pages;
  57.     /**
  58.      * @var ArrayCollection
  59.      * @ORM\OneToMany(targetEntity="App\CmsBundle\Entity\Template", mappedBy="route", cascade={"persist","remove"}, orphanRemoval=true)
  60.      * @ORM\JoinColumn(nullable=false)
  61.      */
  62.     protected $templates;
  63.     /**
  64.      * @ORM\ManyToOne(targetEntity="App\CmsBundle\Entity\Route", inversedBy="childRoutes")
  65.      * @ORM\JoinColumn(nullable=true)
  66.      */
  67.     private $parentRoute;
  68.     /**
  69.      * @ORM\OneToMany(targetEntity="App\CmsBundle\Entity\Route", mappedBy="parentRoute")
  70.      * @ORM\JoinColumn(nullable=true)
  71.      */
  72.     private $childRoutes;
  73.     /**
  74.      * @ORM\Column(type="text", nullable=true)
  75.      */
  76.     private $parameters;
  77.     /**
  78.      * @ORM\Column(type="text", nullable=true)
  79.      */
  80.     private $defaults;
  81.     /**
  82.      * @ORM\OneToOne(targetEntity="App\CmsBundle\Entity\Directory", mappedBy="route")
  83.      * @ORM\JoinColumn(nullable=true)
  84.      */
  85.     private $directory;
  86.     /**
  87.      * @ORM\Column(type="string", length=255, nullable=true)
  88.      */
  89.     private $pageTitle;
  90.     /**
  91.      * @ORM\Column(type="string", length=255, nullable=true)
  92.      */
  93.     private $h1;
  94.     /**
  95.      * @ORM\Column(type="string", length=255, nullable=true)
  96.      */
  97.     private $breadcrumbsTitle;
  98.     /**
  99.      * @ORM\Column(type="string", length=255, nullable=true)
  100.      */
  101.     private $summaryTitle;
  102.     private $canonical;
  103.     private $robots;
  104.     /**
  105.      *
  106.      * @ORM\OneToMany(targetEntity="App\CmsBundle\Entity\Bullet", mappedBy="route", cascade={"persist"}, orphanRemoval=true)
  107.      * @ORM\JoinColumn(nullable=true)
  108.      */
  109.     private Collection $bullet;
  110.     /**
  111.      * @ORM\ManyToOne(targetEntity="App\CasinoBundle\Entity\Author")
  112.      * @ORM\JoinColumn(name="author_id", referencedColumnName="id", nullable=true)
  113.      */
  114.     private ?Author $author null;
  115.     /**
  116.      * @ORM\ManyToOne(targetEntity="App\CasinoBundle\Entity\Author")
  117.      * @ORM\JoinColumn(name="reviewer_id", referencedColumnName="id", nullable=true)
  118.      */
  119.     private ?Author $reviewer null;
  120.     public function __construct()
  121.     {
  122.         $this->widgets = new ArrayCollection();
  123.         $this->childRoutes = new ArrayCollection();
  124.         $this->parameters json_encode([]);
  125.         $this->defaults json_encode([]);
  126.         $this->pages = new ArrayCollection();
  127.         $this->templates = new ArrayCollection();
  128.         $this->bullet = new ArrayCollection();
  129.         $this->relates = new ArrayCollection();
  130.     }
  131.     /**
  132.      * @return string
  133.      */
  134.     public function __toString(): string
  135.     {
  136.         return $this->title ?? '';
  137.     }
  138.     /**
  139.      * @return int|null
  140.      */
  141.     public function getId(): ?int
  142.     {
  143.         return $this->id;
  144.     }
  145.     /**
  146.      * @return string|null
  147.      */
  148.     public function getTitle(): ?string
  149.     {
  150.         return $this->title;
  151.     }
  152.     /**
  153.      * @param string $title
  154.      * @return $this
  155.      */
  156.     public function setTitle(string $title): self
  157.     {
  158.         $this->title $title;
  159.         return $this;
  160.     }
  161.     /**
  162.      * @return string|null
  163.      */
  164.     public function getUrlPattern(): ?string
  165.     {
  166.         return $this->urlPattern;
  167.     }
  168.     /**
  169.      * @param string $urlPattern
  170.      * @return $this
  171.      */
  172.     public function setUrlPattern(string $urlPattern): self
  173.     {
  174.         $this->urlPattern $urlPattern;
  175.         return $this;
  176.     }
  177.     /**
  178.      * @return array
  179.      */
  180.     public function getDefaults(): array
  181.     {
  182.         return json_decode($this->defaultstrue) ?? [];
  183.     }
  184.     /**
  185.      * @param array $defaults
  186.      * @return $this
  187.      */
  188.     public function setDefaults(array $defaults): self
  189.     {
  190.         $this->defaults json_encode($defaults);
  191.         return $this;
  192.     }
  193.     /**
  194.      * @return string|null
  195.      */
  196.     public function getDefaultsAsString(): ?string
  197.     {
  198.         return $this->defaults;
  199.     }
  200.     /**
  201.      * @param string|null $defaults
  202.      * @return $this
  203.      */
  204.     public function setDefaultsAsString(?string $defaults null): self
  205.     {
  206.         $this->defaults = ($defaults) ? $defaults '[]';
  207.         return $this;
  208.     }
  209.     /**
  210.      * @return Collection
  211.      */
  212.     public function getWidgets(): Collection
  213.     {
  214.         return ($this->widgets)
  215.             ? $this->widgets
  216.             : new ArrayCollection();
  217.     }
  218.     /**
  219.      * @param Widget $widget
  220.      * @return $this
  221.      */
  222.     public function addWidget(Widget $widget): self
  223.     {
  224.         if (!$this->widgets->contains($widget)) {
  225.             $this->widgets[] = $widget;
  226.             $widget->setRoute($this);
  227.             $this->addCollectionLog(LogActionEnum::ADD'widget'$widget);
  228.         }
  229.         return $this;
  230.     }
  231.     /**
  232.      * @param Widget $widget
  233.      * @return $this
  234.      */
  235.     public function removeWidget(Widget $widget): self
  236.     {
  237.         if ($this->widgets->contains($widget)) {
  238.             $this->widgets->removeElement($widget);
  239.             $widget->setRoute(null);
  240.             $this->addCollectionLog(LogActionEnum::REMOVE'widget'$widget);
  241.         }
  242.         return $this;
  243.     }
  244.     /**
  245.      * @param Route|null $route
  246.      * @return $this
  247.      */
  248.     public function setParentRoute(?Route $route): self
  249.     {
  250.         $this->parentRoute $route;
  251.         return $this;
  252.     }
  253.     /**
  254.      * @return Route|null
  255.      */
  256.     public function getParentRoute(): ?Route
  257.     {
  258.         return $this->parentRoute;
  259.     }
  260.     /**
  261.      * @return Collection|null
  262.      */
  263.     public function getChildRoutes(): ?Collection
  264.     {
  265.         return $this->childRoutes;
  266.     }
  267.     /**
  268.      * @return Collection
  269.      */
  270.     public function getPages(): Collection
  271.     {
  272.         return ($this->pages)
  273.             ? $this->pages
  274.             : new ArrayCollection();
  275.     }
  276.     /**
  277.      * @param Page $page
  278.      * @return $this
  279.      */
  280.     public function addPage(Page $page): self
  281.     {
  282.         if (!$this->pages->contains($page)) {
  283.             $this->pages[] = $page;
  284.             $page->setRoute($this);
  285.             $this->addCollectionLog(LogActionEnum::ADD'page'$page);
  286.         }
  287.         return $this;
  288.     }
  289.     /**
  290.      * @param Page $page
  291.      * @return $this
  292.      */
  293.     public function removePage(Page $page): self
  294.     {
  295.         if ($this->pages->contains($page)) {
  296.             $this->pages->removeElement($page);
  297.             $page->setRoute(null);
  298.             $this->addCollectionLog(LogActionEnum::REMOVE'page'$page);
  299.         }
  300.         return $this;
  301.     }
  302.     /**
  303.      * @return Collection
  304.      */
  305.     public function getTemplates(): Collection
  306.     {
  307.         return ($this->templates)
  308.             ? $this->templates
  309.             : new ArrayCollection();
  310.     }
  311.     /**
  312.      * @param Template $template
  313.      * @return $this
  314.      */
  315.     public function addTemplate(Template $template): self
  316.     {
  317.         if (!$this->templates->contains($template)) {
  318.             $this->templates[] = $template;
  319.             $template->setRoute($this);
  320.             $this->addCollectionLog(LogActionEnum::ADD'template'$template);
  321.         }
  322.         return $this;
  323.     }
  324.     /**
  325.      * @param Template $template
  326.      * @return $this
  327.      */
  328.     public function removeTemplate(Template $template): self
  329.     {
  330.         if ($this->templates->contains($template)) {
  331.             $this->templates->removeElement($template);
  332.             $template->setRoute(null);
  333.             $this->addCollectionLog(LogActionEnum::REMOVE'template'$template);
  334.         }
  335.         return $this;
  336.     }
  337.     /**
  338.      * @return array
  339.      */
  340.     public function getAutoReplacedVariables(): array
  341.     {
  342.         return [
  343.             '{pageTitle}' => $this->pageTitle,
  344.             '{description}' => $this->description,
  345.             '{h1}' => $this->h1,
  346.             '{breadcrumbsTitle}' => $this->breadcrumbsTitle,
  347.             '{summaryTitle}' => $this->summaryTitle
  348.         ];
  349.     }
  350.     /**
  351.      * @return string|null
  352.      */
  353.     public function getPageTitle(): ?string
  354.     {
  355.         return $this->pageTitle;
  356.     }
  357.     /**
  358.      * @param string|null $pageTitle
  359.      * @return $this
  360.      */
  361.     public function setPageTitle(?string $pageTitle): self
  362.     {
  363.         $this->pageTitle $pageTitle;
  364.         return $this;
  365.     }
  366.     /**
  367.      * @return string|null
  368.      */
  369.     public function getH1(): ?string
  370.     {
  371.         return $this->h1;
  372.     }
  373.     /**
  374.      * @param string|null $h1
  375.      * @return $this
  376.      */
  377.     public function setH1(?string $h1): self
  378.     {
  379.         $this->h1 $h1;
  380.         return $this;
  381.     }
  382.     /**
  383.      * @return string|null
  384.      */
  385.     public function getBreadcrumbsTitle(): ?string
  386.     {
  387.         return $this->breadcrumbsTitle;
  388.     }
  389.     /**
  390.      * @param string|null $breadcrumbsTitle
  391.      * @return $this
  392.      */
  393.     public function setBreadcrumbsTitle(?string $breadcrumbsTitle): self
  394.     {
  395.         $this->breadcrumbsTitle $breadcrumbsTitle;
  396.         return $this;
  397.     }
  398.     /**
  399.      * @return string|null
  400.      */
  401.     public function getSummaryTitle(): ?string
  402.     {
  403.         return $this->summaryTitle;
  404.     }
  405.     /**
  406.      * @param string|null $summaryTitle
  407.      * @return $this
  408.      */
  409.     public function setSummaryTitle(?string $summaryTitle): self
  410.     {
  411.         $this->summaryTitle $summaryTitle;
  412.         return $this;
  413.     }
  414.     /**
  415.      * @return string|null
  416.      */
  417.     public function getCanonical(): ?string
  418.     {
  419.         return $this->canonical;
  420.     }
  421.     /**
  422.      * @param string|null $canonical
  423.      * @return $this
  424.      */
  425.     public function setCanonical(?string $canonical null): self
  426.     {
  427.         $this->canonical $canonical;
  428.         return $this;
  429.     }
  430.     /**
  431.      * @return string|null
  432.      */
  433.     public function getRobots(): ?string
  434.     {
  435.         return $this->robots;
  436.     }
  437.     /**
  438.      * @param Directory|null $directory
  439.      * @return $this
  440.      */
  441.     public function setDirectory(?Directory $directory null): self
  442.     {
  443.         $this->directory $directory;
  444.         return $this;
  445.     }
  446.     /**
  447.      * @return Directory|null
  448.      */
  449.     public function getDirectory(): ?Directory
  450.     {
  451.         return $this->directory;
  452.     }
  453.     /**
  454.      * @return Collection
  455.      */
  456.     public function getBullet(): Collection
  457.     {
  458.         return $this->bullet ?? new ArrayCollection();
  459.     }
  460.     /**
  461.      * @param Bullet $bullet
  462.      * @return $this
  463.      */
  464.     public function addBullet(Bullet $bullet): self
  465.     {
  466.         $this->bullet[] = $bullet;
  467.         $bullet->setRoute($this);
  468.         $this->addCollectionLog(LogActionEnum::ADD'bullet'$bullet);
  469.         return $this;
  470.     }
  471.     /**
  472.      * @param Bullet $bullet
  473.      * @return void
  474.      */
  475.     public function removeBullet(Bullet $bullet): void
  476.     {
  477.         $this->bullet->removeElement($bullet);
  478.         $this->addCollectionLog(LogActionEnum::REMOVE'bullet'$bullet);
  479.     }
  480.     /**
  481.      * @return Route|null
  482.      */
  483.     public function getRelatedTo(): ?Route
  484.     {
  485.         return $this->relatedTo;
  486.     }
  487.     /**
  488.      * @param Route|null $relatedTo
  489.      * @return $this
  490.      */
  491.     public function setRelatedTo(?Route $relatedTo): self
  492.     {
  493.         $this->relatedTo $relatedTo;
  494.         return $this;
  495.     }
  496.     /**
  497.      * @return Collection|Route[]
  498.      */
  499.     public function getRelates(): Collection
  500.     {
  501.         return $this->relates;
  502.     }
  503.     /**
  504.      * @param Route $relate
  505.      * @return $this
  506.      */
  507.     public function addRelates(Route $relate): self
  508.     {
  509.         if (!$this->relates->contains($relate)) {
  510.             $this->relates[] = $relate;
  511.             $relate->setRelatedTo($this);
  512.             $this->addCollectionLog(LogActionEnum::ADD'relates'$relate);
  513.         }
  514.         return $this;
  515.     }
  516.     /**
  517.      * @param Route $relate
  518.      * @return $this
  519.      */
  520.     public function removeRelates(Route $relate): self
  521.     {
  522.         if ($this->relates->contains($relate)) {
  523.             $this->relates->removeElement($relate);
  524.             // set the owning side to null (unless already changed)
  525.             if ($relate->getRelatedTo() === $this) {
  526.                 $relate->setRelatedTo(null);
  527.             }
  528.             $this->addCollectionLog(LogActionEnum::REMOVE'relates'$relate);
  529.         }
  530.         return $this;
  531.     }
  532.     /**
  533.      * @param $action
  534.      * @param $property
  535.      * @param object $value
  536.      * @return $this
  537.      */
  538.     public function addCollectionLog($action$propertyobject $value): self
  539.     {
  540.         if (LogActionEnum::exists($action)) {
  541.             $log json_decode($this->log ?? '[]'true);
  542.             if ($value instanceof Bullet) {
  543.                 $log[$property][$action][] = $value->__toArray();
  544.             } else {
  545.                 $log[$property][$action][] = $value->getId();
  546.             }
  547.             $this->log json_encode($log);
  548.         }
  549.         return $this;
  550.     }
  551.     /**
  552.      * @return Author|null
  553.      */
  554.     public function getAuthor(): ?Author
  555.     {
  556.         return $this->author;
  557.     }
  558.     /**
  559.      * @param Author|null $author
  560.      * @return $this
  561.      */
  562.     public function setAuthor(?Author $author): self
  563.     {
  564.         $this->author $author;
  565.         return $this;
  566.     }
  567.     /**
  568.      * @return Author|null
  569.      */
  570.     public function getReviewer(): ?Author
  571.     {
  572.         return $this->reviewer;
  573.     }
  574.     /**
  575.      * @param Author|null $reviewer
  576.      * @return self
  577.      */
  578.     public function setReviewer(?Author $reviewer): self
  579.     {
  580.         $this->reviewer $reviewer;
  581.         return $this;
  582.     }
  583. }