src/Entity/Post.php line 24
<?phpnamespace App\Entity;use App\Entity\Traits\BlameableEntity;use App\Entity\Traits\DomainEntity;use App\Entity\Traits\TimestampableEntity;use App\Repository\PostRepository;use DateTime;use DateTimeImmutable;use DateTimeInterface;use Doctrine\Common\Collections\ArrayCollection;use Doctrine\Common\Collections\Collection;use Doctrine\DBAL\Types\Types;use Doctrine\ORM\Mapping as ORM;use Gedmo\Mapping\Annotation as Gedmo;use Gedmo\SoftDeleteable\Traits\SoftDeleteableEntity;use Symfony\Component\Validator\Constraints as Assert;#[Assert\GroupSequence(['Post', 'Strict'])]#[ORM\Entity(repositoryClass: PostRepository::class)]//#[UniqueEntity(fields: ['slug'], errorPath: 'title', message: 'post.slug_unique')]#[Gedmo\SoftDeleteable(fieldName: 'deletedAt', timeAware: false, hardDelete: true)]class Post{#[ORM\Id]#[ORM\GeneratedValue]#[ORM\Column(type: 'integer')]private ?int $id = null;#[ORM\Column(type: 'datetime')]private DateTime $publishedAt;#[Gedmo\Translatable]#[ORM\Column(type: 'string', length: 600)]// #[Assert\NotBlank]// #[Assert\Length(max: 400, minMessage: 'post.too_long_title')]private ?string $title = null;#[ORM\Column(type: 'string', length: 600)]#[Gedmo\Slug(fields: ['title', 'id'], unique: false)]private ?string $slug;#[ORM\Column(type: 'string', nullable: true)]#[Assert\Length(max: 255)]private ?string $summary = null;#[Gedmo\Translatable]#[ORM\Column(type: 'text', nullable: true)]// #[Assert\NotBlank(message: 'post.blank_content')]// #[Assert\Length(min: 10, minMessage: 'post.too_short_content')]private ?string $content = null;#[ORM\ManyToOne]#[ORM\JoinColumn(nullable: false)]private ?User $author = null;#[ORM\Column]private ?bool $isActive = null;#[ORM\Column(length: 20)]private ?string $type = null;#[ORM\Column(length: 255, nullable: true)]private ?string $template = null;#[ORM\ManyToOne(targetEntity: self::class)]private ?self $parent = null;#[ORM\OneToMany(mappedBy: 'post', targetEntity: Attachment::class, cascade: ["persist", "remove"])]private Collection $attachments;#[ORM\Column(nullable: true, options: ['default' => 0])]private ?int $counter = 0;#[Gedmo\Timestampable(on: 'change', field: ['title', 'summary', 'content', 'parent'])]#[ORM\Column(nullable: true)]private ?DateTimeImmutable $modifiedAt;#[ORM\Column(type: Types::BIGINT, nullable: true)]private ?string $idOld = null;#[ORM\Column(length: 255, nullable: true)]private ?string $template_old = null;#[ORM\JoinTable(name: 'post_category')]#[ORM\JoinColumn(name: 'post_id', referencedColumnName: 'id')]#[ORM\InverseJoinColumn(name: 'category_id', referencedColumnName: 'id')]#[ORM\ManyToMany(targetEntity: Category::class)]private Collection $category;use DomainEntity;use TimestampableEntity;use SoftDeleteableEntity;use BlameableEntity;/*** Used locale to override Translation listener`s locale* this is not a mapped field of entity metadata, just a simple property*/#[Gedmo\Locale]private $locale;private ?string $titleSecondary = null;private ?string $contentSecondary = null;private ?string $titleEnglish = null;private ?string $contentEnglish = null;#[ORM\Column(nullable: true)]private ?bool $isSliderActive = null;public function __construct(){$this->publishedAt = new DateTime();$this->type = 'post';$this->attachments = new ArrayCollection();$this->category = new ArrayCollection();}public function getLocale(): ?string{return $this->locale;}public function setLocale(string $locale): self{$this->locale = $locale;return $this;}public function getTitleSecondary(): ?string{return $this->titleSecondary;}public function setTitleSecondary(?string $titleSecondary): self{$this->titleSecondary = $titleSecondary;return $this;}public function getTitleEnglish(): ?string{return $this->titleEnglish;}public function setTitleEnglish(?string $titleEnglish): self{$this->titleEnglish = $titleEnglish;return $this;}public function getSlug(): ?string{return $this->slug;}public function setSlug(string $slug): self{$this->slug = $slug;return $this;}public function getContent(): ?string{return $this->content;}public function setContent(?string $content): self{$this->content = $content;return $this;}public function getContentSecondary(): ?string{return $this->contentSecondary;}public function setContentSecondary($contentSecondary): self{$this->contentSecondary = $contentSecondary;return $this;}public function getContentEnglish(): ?string{return $this->contentEnglish;}public function setContentEnglish($contentEnglish): self{$this->contentEnglish = $contentEnglish;return $this;}public function getPublishedAt(): ?DateTimeInterface{return $this->publishedAt;}public function setPublishedAt(DateTimeInterface $publishedAt): self{$this->publishedAt = $publishedAt;return $this;}public function getSummary(): ?string{return $this->summary;}public function setSummary(string $summary): self{$this->summary = $summary;return $this;}public function __toString(): string{if ($this->getTitle())return $this->getTitle();elsereturn $this->getId();}public function getTitle(): ?string{return $this->title;}public function setTitle(?string $title): self{$this->title = $title;return $this;}public function getId(): ?int{return $this->id;}public function getAuthor(): ?User{return $this->author;}public function setAuthor(?User $author): self{$this->author = $author;return $this;}public function getModifiedAt(): ?DateTimeImmutable{return $this->modifiedAt;}public function setModifiedAt(DateTimeImmutable $modifiedAt): self{$this->modifiedAt = $modifiedAt;return $this;}public function getParent(): ?self{return $this->parent;}public function setParent(?self $parent): self{$this->parent = $parent;return $this;}public function getType(): ?string{return $this->type;}public function setType(string $type): self{$this->type = $type;return $this;}public function setTranslatableLocale($locale){$this->locale = $locale;}/*** @return Collection<int, Attachment>*/public function getAttachments(): Collection{return $this->attachments;}public function addAttachment(Attachment $attachment): self{if (!$this->attachments->contains($attachment)) {$this->attachments->add($attachment);$attachment->setPost($this);}return $this;}public function removeAttachment(Attachment $attachment): self{if ($this->attachments->removeElement($attachment)) {// set the owning side to null (unless already changed)if ($attachment->getPost() === $this) {$attachment->setPost(null);}}return $this;}/*** @return Collection<int, Attachment>*/public function getCategory(): Collection{return $this->category;}public function addCategory(Category $category): self{if (!$this->category->contains($category)) {$this->category->add($category);// $category->setPost($this);}return $this;}// public function removeCategory(Category $category): self// {// if ($this->category->removeElement($category)) {// // set the owning side to null (unless already changed)// if ($category->getPost() === $this) {// $attachment->setPost(null);// }// }//// return $this;// }public function isIsActive(): ?bool{return $this->isActive;}public function setIsActive(bool $isActive): self{$this->isActive = $isActive;return $this;}public function getTemplate(): ?string{return $this->template;}public function setTemplate(?string $template): self{$this->template = $template;return $this;}public function getCounter(): ?int{return $this->counter;}public function setCounter(?int $counter): self{$this->counter = $counter;return $this;}public function getIdOld(): ?string{return $this->idOld;}public function setIdOld(?string $idOld): self{$this->idOld = $idOld;return $this;}public function getTemplateOld(): ?string{return $this->template_old;}public function setTemplateOld(?string $template_old): self{$this->template_old = $template_old;return $this;}#[Assert\IsTrue(message: 'You must fill at least one language of content',groups: ['Strict'],)]public function isAnyLanguageAdded(){return (($this->title != '' && $this->content != '') || ($this->titleSecondary != '' && $this->contentSecondary != ''));}public function isIsSliderActive(): ?bool{return $this->isSliderActive;}public function setIsSliderActive(?bool $isSliderActive): self{$this->isSliderActive = $isSliderActive;return $this;}}