vendor/perfectneeds/seo-multi-lang-bundle/Entity/SeoPage.php line 28

Open in your IDE?
  1. <?php
  2. namespace PN\SeoBundle\Entity;
  3. use App\SeoBundle\Entity\Seo;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use PN\LocaleBundle\Model\LocaleTrait;
  8. use PN\LocaleBundle\Model\Translatable;
  9. use PN\ServiceBundle\Model\DateTimeTrait;
  10. use PN\ServiceBundle\Utils\General;
  11. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  12. use Symfony\Component\Validator\Constraints as Assert;
  13. /**
  14. * SeoPage
  15. *
  16. * @ORM\HasLifecycleCallbacks
  17. * @ORM\Table(name="seo_page")
  18. * @ORM\Entity(repositoryClass="PN\SeoBundle\Repository\SeoPageRepository")
  19. * @UniqueEntity(
  20. * fields={"type"},
  21. * errorPath="type",
  22. * message="This type is already exist."
  23. * )
  24. */
  25. class SeoPage implements Translatable
  26. {
  27. use DateTimeTrait,
  28. LocaleTrait;
  29. /**
  30. * @var int
  31. *
  32. * @ORM\Column(name="id", type="integer")
  33. * @ORM\Id
  34. * @ORM\GeneratedValue(strategy="AUTO")
  35. */
  36. private ?int $id = null;
  37. /**
  38. * @var string
  39. *
  40. * @Assert\NotBlank()
  41. * @ORM\Column(name="title", type="string", length=100)
  42. */
  43. private ?string $title = null;
  44. /**
  45. * @ORM\Column(name="brief", type="text", nullable=true)
  46. */
  47. private ?string $brief = null;
  48. /**
  49. * @var string
  50. *
  51. * @ORM\Column(name="type", type="string", length=255, unique=true)
  52. */
  53. private ?string $type = null;
  54. /**
  55. * @ORM\OneToOne(targetEntity="\PN\SeoBundle\Entity\Seo", cascade={"persist", "remove" }, fetch="EAGER")
  56. */
  57. private ?Seo $seo = null;
  58. /**
  59. * @ORM\OneToMany(targetEntity="PN\SeoBundle\Entity\Translation\SeoPageTranslation", mappedBy="translatable", cascade={"ALL"}, orphanRemoval=true, fetch="LAZY")
  60. */
  61. private Collection $translations;
  62. /**
  63. * Now we tell doctrine that before we persist or update we call the updatedTimestamps() function.
  64. *
  65. * @ORM\PrePersist
  66. * @ORM\PreUpdate
  67. */
  68. public function updatedTimestamps()
  69. {
  70. $this->setModified(new \DateTime(date('Y-m-d H:i:s')));
  71. if ($this->getCreated() == null) {
  72. $this->setCreated(new \DateTime(date('Y-m-d H:i:s')));
  73. }
  74. if ($this->getType() == null) {
  75. $this->setType(General::seoUrl($this->getTitle()));
  76. }
  77. }
  78. public function __construct()
  79. {
  80. $this->translations = new ArrayCollection();
  81. }
  82. public function getId(): ?int
  83. {
  84. return $this->id;
  85. }
  86. public function getTitle(): ?string
  87. {
  88. return $this->title;
  89. }
  90. public function setTitle(string $title): self
  91. {
  92. $this->title = $title;
  93. return $this;
  94. }
  95. public function getBrief(): ?string
  96. {
  97. return !$this->currentTranslation ? $this->brief : $this->currentTranslation->getBrief();
  98. }
  99. public function setBrief(string $brief): self
  100. {
  101. $this->brief = $brief;
  102. return $this;
  103. }
  104. public function getType(): ?string
  105. {
  106. return $this->type;
  107. }
  108. public function setType(string $type): self
  109. {
  110. $this->type = $type;
  111. return $this;
  112. }
  113. public function getSeo(): ?Seo
  114. {
  115. return $this->seo;
  116. }
  117. public function setSeo(?Seo $seo): self
  118. {
  119. $this->seo = $seo;
  120. return $this;
  121. }
  122. }