src/Entity/Post.php line 24

  1. <?php
  2. namespace App\Entity;
  3. use App\Entity\Traits\BlameableEntity;
  4. use App\Entity\Traits\DomainEntity;
  5. use App\Entity\Traits\TimestampableEntity;
  6. use App\Repository\PostRepository;
  7. use DateTime;
  8. use DateTimeImmutable;
  9. use DateTimeInterface;
  10. use Doctrine\Common\Collections\ArrayCollection;
  11. use Doctrine\Common\Collections\Collection;
  12. use Doctrine\DBAL\Types\Types;
  13. use Doctrine\ORM\Mapping as ORM;
  14. use Gedmo\Mapping\Annotation as Gedmo;
  15. use Gedmo\SoftDeleteable\Traits\SoftDeleteableEntity;
  16. use Symfony\Component\Validator\Constraints as Assert;
  17. #[Assert\GroupSequence(['Post''Strict'])]
  18. #[ORM\Entity(repositoryClassPostRepository::class)]
  19. //#[UniqueEntity(fields: ['slug'], errorPath: 'title', message: 'post.slug_unique')]
  20. #[Gedmo\SoftDeleteable(fieldName'deletedAt'timeAwarefalsehardDeletetrue)]
  21. class Post
  22. {
  23.     #[ORM\Id]
  24.     #[ORM\GeneratedValue]
  25.     #[ORM\Column(type'integer')]
  26.     private ?int $id null;
  27.     #[ORM\Column(type'datetime')]
  28.     private DateTime $publishedAt;
  29.     #[Gedmo\Translatable]
  30.     #[ORM\Column(type'string'length600)]
  31. //    #[Assert\NotBlank]
  32. //    #[Assert\Length(max: 400, minMessage: 'post.too_long_title')]
  33.     private ?string $title null;
  34.     #[ORM\Column(type'string'length600)]
  35.     #[Gedmo\Slug(fields: ['title''id'], uniquefalse)]
  36.     private ?string $slug;
  37.     #[ORM\Column(type'string'nullabletrue)]
  38.     #[Assert\Length(max255)]
  39.     private ?string $summary null;
  40.     #[Gedmo\Translatable]
  41.     #[ORM\Column(type'text'nullabletrue)]
  42. //    #[Assert\NotBlank(message: 'post.blank_content')]
  43. //    #[Assert\Length(min: 10, minMessage: 'post.too_short_content')]
  44.     private ?string $content null;
  45.     #[ORM\ManyToOne]
  46.     #[ORM\JoinColumn(nullablefalse)]
  47.     private ?User $author null;
  48.     #[ORM\Column]
  49.     private ?bool $isActive null;
  50.     #[ORM\Column(length20)]
  51.     private ?string $type null;
  52.     #[ORM\Column(length255nullabletrue)]
  53.     private ?string $template null;
  54.     #[ORM\ManyToOne(targetEntityself::class)]
  55.     private ?self $parent null;
  56.     #[ORM\OneToMany(mappedBy'post'targetEntityAttachment::class, cascade: ["persist""remove"])]
  57.     private Collection $attachments;
  58.     #[ORM\Column(nullabletrueoptions: ['default' => 0])]
  59.     private ?int $counter 0;
  60.     #[Gedmo\Timestampable(on'change'field: ['title''summary''content''parent'])]
  61.     #[ORM\Column(nullabletrue)]
  62.     private ?DateTimeImmutable $modifiedAt;
  63.     #[ORM\Column(typeTypes::BIGINTnullabletrue)]
  64.     private ?string $idOld null;
  65.     #[ORM\Column(length255nullabletrue)]
  66.     private ?string $template_old null;
  67.     #[ORM\JoinTable(name'post_category')]
  68.     #[ORM\JoinColumn(name'post_id'referencedColumnName'id')]
  69.     #[ORM\InverseJoinColumn(name'category_id'referencedColumnName'id')]
  70.     #[ORM\ManyToMany(targetEntityCategory::class)]
  71.     private Collection $category;
  72.     use DomainEntity;
  73.     use TimestampableEntity;
  74.     use SoftDeleteableEntity;
  75.     use BlameableEntity;
  76.     /**
  77.      * Used locale to override Translation listener`s locale
  78.      * this is not a mapped field of entity metadata, just a simple property
  79.      */
  80.     #[Gedmo\Locale]
  81.     private $locale;
  82.     private ?string $titleSecondary null;
  83.     private ?string $contentSecondary null;
  84.     private ?string $titleEnglish null;
  85.     private ?string $contentEnglish null;
  86.     #[ORM\Column(nullabletrue)]
  87.     private ?bool $isSliderActive null;
  88.     public function __construct()
  89.     {
  90.         $this->publishedAt = new DateTime();
  91.         $this->type 'post';
  92.         $this->attachments = new ArrayCollection();
  93.         $this->category = new ArrayCollection();
  94.     }
  95.     public function getLocale(): ?string
  96.     {
  97.         return $this->locale;
  98.     }
  99.     public function setLocale(string $locale): self
  100.     {
  101.         $this->locale $locale;
  102.         return $this;
  103.     }
  104.     public function getTitleSecondary(): ?string
  105.     {
  106.         return $this->titleSecondary;
  107.     }
  108.     public function setTitleSecondary(?string $titleSecondary): self
  109.     {
  110.         $this->titleSecondary $titleSecondary;
  111.         return $this;
  112.     }
  113.     public function getTitleEnglish(): ?string
  114.     {
  115.         return $this->titleEnglish;
  116.     }
  117.     public function setTitleEnglish(?string $titleEnglish): self
  118.     {
  119.         $this->titleEnglish $titleEnglish;
  120.         return $this;
  121.     }
  122.     public function getSlug(): ?string
  123.     {
  124.         return $this->slug;
  125.     }
  126.     public function setSlug(string $slug): self
  127.     {
  128.         $this->slug $slug;
  129.         return $this;
  130.     }
  131.     public function getContent(): ?string
  132.     {
  133.         return $this->content;
  134.     }
  135.     public function setContent(?string $content): self
  136.     {
  137.         $this->content $content;
  138.         return $this;
  139.     }
  140.     public function getContentSecondary(): ?string
  141.     {
  142.         return $this->contentSecondary;
  143.     }
  144.     public function setContentSecondary($contentSecondary): self
  145.     {
  146.         $this->contentSecondary $contentSecondary;
  147.         return $this;
  148.     }
  149.     public function getContentEnglish(): ?string
  150.     {
  151.         return $this->contentEnglish;
  152.     }
  153.     public function setContentEnglish($contentEnglish): self
  154.     {
  155.         $this->contentEnglish $contentEnglish;
  156.         return $this;
  157.     }
  158.     public function getPublishedAt(): ?DateTimeInterface
  159.     {
  160.         return $this->publishedAt;
  161.     }
  162.     public function setPublishedAt(DateTimeInterface $publishedAt): self
  163.     {
  164.         $this->publishedAt $publishedAt;
  165.         return $this;
  166.     }
  167.     public function getSummary(): ?string
  168.     {
  169.         return $this->summary;
  170.     }
  171.     public function setSummary(string $summary): self
  172.     {
  173.         $this->summary $summary;
  174.         return $this;
  175.     }
  176.     public function __toString(): string
  177.     {
  178.         if ($this->getTitle())
  179.             return $this->getTitle();
  180.         else
  181.             return $this->getId();
  182.     }
  183.     public function getTitle(): ?string
  184.     {
  185.         return $this->title;
  186.     }
  187.     public function setTitle(?string $title): self
  188.     {
  189.         $this->title $title;
  190.         return $this;
  191.     }
  192.     public function getId(): ?int
  193.     {
  194.         return $this->id;
  195.     }
  196.     public function getAuthor(): ?User
  197.     {
  198.         return $this->author;
  199.     }
  200.     public function setAuthor(?User $author): self
  201.     {
  202.         $this->author $author;
  203.         return $this;
  204.     }
  205.     public function getModifiedAt(): ?DateTimeImmutable
  206.     {
  207.         return $this->modifiedAt;
  208.     }
  209.     public function setModifiedAt(DateTimeImmutable $modifiedAt): self
  210.     {
  211.         $this->modifiedAt $modifiedAt;
  212.         return $this;
  213.     }
  214.     public function getParent(): ?self
  215.     {
  216.         return $this->parent;
  217.     }
  218.     public function setParent(?self $parent): self
  219.     {
  220.         $this->parent $parent;
  221.         return $this;
  222.     }
  223.     public function getType(): ?string
  224.     {
  225.         return $this->type;
  226.     }
  227.     public function setType(string $type): self
  228.     {
  229.         $this->type $type;
  230.         return $this;
  231.     }
  232.     public function setTranslatableLocale($locale)
  233.     {
  234.         $this->locale $locale;
  235.     }
  236.     /**
  237.      * @return Collection<int, Attachment>
  238.      */
  239.     public function getAttachments(): Collection
  240.     {
  241.         return $this->attachments;
  242.     }
  243.     public function addAttachment(Attachment $attachment): self
  244.     {
  245.         if (!$this->attachments->contains($attachment)) {
  246.             $this->attachments->add($attachment);
  247.             $attachment->setPost($this);
  248.         }
  249.         return $this;
  250.     }
  251.     public function removeAttachment(Attachment $attachment): self
  252.     {
  253.         if ($this->attachments->removeElement($attachment)) {
  254.             // set the owning side to null (unless already changed)
  255.             if ($attachment->getPost() === $this) {
  256.                 $attachment->setPost(null);
  257.             }
  258.         }
  259.         return $this;
  260.     }
  261.     /**
  262.      * @return Collection<int, Attachment>
  263.      */
  264.     public function getCategory(): Collection
  265.     {
  266.         return $this->category;
  267.     }
  268.     public function addCategory(Category $category): self
  269.     {
  270.         if (!$this->category->contains($category)) {
  271.             $this->category->add($category);
  272. //            $category->setPost($this);
  273.         }
  274.         return $this;
  275.     }
  276. //    public function removeCategory(Category $category): self
  277. //    {
  278. //        if ($this->category->removeElement($category)) {
  279. //            // set the owning side to null (unless already changed)
  280. //            if ($category->getPost() === $this) {
  281. //                $attachment->setPost(null);
  282. //            }
  283. //        }
  284. //
  285. //        return $this;
  286. //    }
  287.     public function isIsActive(): ?bool
  288.     {
  289.         return $this->isActive;
  290.     }
  291.     public function setIsActive(bool $isActive): self
  292.     {
  293.         $this->isActive $isActive;
  294.         return $this;
  295.     }
  296.     public function getTemplate(): ?string
  297.     {
  298.         return $this->template;
  299.     }
  300.     public function setTemplate(?string $template): self
  301.     {
  302.         $this->template $template;
  303.         return $this;
  304.     }
  305.     public function getCounter(): ?int
  306.     {
  307.         return $this->counter;
  308.     }
  309.     public function setCounter(?int $counter): self
  310.     {
  311.         $this->counter $counter;
  312.         return $this;
  313.     }
  314.     public function getIdOld(): ?string
  315.     {
  316.         return $this->idOld;
  317.     }
  318.     public function setIdOld(?string $idOld): self
  319.     {
  320.         $this->idOld $idOld;
  321.         return $this;
  322.     }
  323.     public function getTemplateOld(): ?string
  324.     {
  325.         return $this->template_old;
  326.     }
  327.     public function setTemplateOld(?string $template_old): self
  328.     {
  329.         $this->template_old $template_old;
  330.         return $this;
  331.     }
  332.     #[Assert\IsTrue(
  333.         message'You must fill at least one language of content',
  334.         groups: ['Strict'],
  335.     )]
  336.     public function isAnyLanguageAdded()
  337.     {
  338.         return (($this->title != '' && $this->content != '') || ($this->titleSecondary != '' && $this->contentSecondary != ''));
  339.     }
  340.     public function isIsSliderActive(): ?bool
  341.     {
  342.         return $this->isSliderActive;
  343.     }
  344.     public function setIsSliderActive(?bool $isSliderActive): self
  345.     {
  346.         $this->isSliderActive $isSliderActive;
  347.         return $this;
  348.     }
  349. }