src/CMSBundle/Entity/DynamicPage.php line 21

Open in your IDE?
  1. <?php
  2. namespace App\CMSBundle\Entity;
  3. use App\CMSBundle\Entity\Translation\DynamicPageTranslation;
  4. use App\ContentBundle\Entity\Post;
  5. use App\SeoBundle\Entity\Seo;
  6. use Doctrine\Common\Collections\ArrayCollection;
  7. use Doctrine\Common\Collections\Collection;
  8. use Doctrine\ORM\Mapping as ORM;
  9. use JetBrains\PhpStorm\Pure;
  10. use PN\LocaleBundle\Model\LocaleTrait;
  11. use PN\LocaleBundle\Model\Translatable;
  12. use PN\ServiceBundle\Interfaces\DateTimeInterface;
  13. use PN\ServiceBundle\Model\DateTimeTrait;
  14. /**
  15. * @ORM\Table(name="dynamic_page")
  16. * @ORM\Entity(repositoryClass="App\CMSBundle\Repository\DynamicPageRepository")
  17. */
  18. class DynamicPage implements Translatable, DateTimeInterface
  19. {
  20. use DateTimeTrait,
  21. LocaleTrait;
  22. /**
  23. * @ORM\Id
  24. * @ORM\Column(name="id", type="integer")
  25. * @ORM\GeneratedValue(strategy="AUTO")
  26. */
  27. private ?int $id = null;
  28. /**
  29. * @ORM\OneToOne(targetEntity="\App\SeoBundle\Entity\Seo", cascade={"persist", "remove" })
  30. */
  31. private ?Seo $seo = null;
  32. /**
  33. * @ORM\OneToOne(targetEntity="App\ContentBundle\Entity\Post", cascade={"persist", "remove" })
  34. */
  35. private ?Post $post = null;
  36. /**
  37. * @ORM\Column(name="title", type="string", length=255)
  38. */
  39. private ?string $title = null;
  40. /**
  41. * @ORM\OneToMany(targetEntity="App\CMSBundle\Entity\Translation\DynamicPageTranslation", mappedBy="translatable", cascade={"ALL"}, orphanRemoval=true)
  42. */
  43. private Collection $translations;
  44. /**
  45. * Constructor
  46. */
  47. #[Pure] public function __construct()
  48. {
  49. $this->translations = new ArrayCollection();
  50. }
  51. public function getTitle(): ?string
  52. {
  53. return !$this->currentTranslation ? $this->title : $this->currentTranslation->getTitle();
  54. }
  55. public function getId(): ?int
  56. {
  57. return $this->id;
  58. }
  59. public function setTitle(string $title): self
  60. {
  61. $this->title = $title;
  62. return $this;
  63. }
  64. public function getSeo(): ?Seo
  65. {
  66. return $this->seo;
  67. }
  68. public function setSeo(?Seo $seo): self
  69. {
  70. $this->seo = $seo;
  71. return $this;
  72. }
  73. public function getPost(): ?Post
  74. {
  75. return $this->post;
  76. }
  77. public function setPost(?Post $post): self
  78. {
  79. $this->post = $post;
  80. return $this;
  81. }
  82. /**
  83. * @return Collection<int, DynamicPageTranslation>
  84. */
  85. public function getTranslations(): Collection
  86. {
  87. return $this->translations;
  88. }
  89. public function addTranslation(DynamicPageTranslation $translation): self
  90. {
  91. if (!$this->translations->contains($translation)) {
  92. $this->translations->add($translation);
  93. $translation->setTranslatable($this);
  94. }
  95. return $this;
  96. }
  97. public function removeTranslation(DynamicPageTranslation $translation): self
  98. {
  99. if ($this->translations->removeElement($translation)) {
  100. // set the owning side to null (unless already changed)
  101. if ($translation->getTranslatable() === $this) {
  102. $translation->setTranslatable(null);
  103. }
  104. }
  105. return $this;
  106. }
  107. }