src/Entity/Post.php line 21

  1. <?php
  2. namespace App\Entity;
  3. use Doctrine\ORM\Mapping as ORM;
  4. use App\Repository\PostRepository;
  5. use Doctrine\Common\Collections\Collection;
  6. use ApiPlatform\Core\Annotation\ApiResource;
  7. use DateTime;
  8. use Doctrine\Common\Collections\ArrayCollection;
  9. use Symfony\Bridge\Doctrine\IdGenerator\UlidGenerator;
  10. use Symfony\Component\Uid\Ulid;
  11. use Gedmo\Mapping\Annotation as Gedmo;
  12. #[ORM\Entity(repositoryClassPostRepository::class)]
  13. #[Gedmo\SoftDeleteable(fieldName'deletedAt'timeAwarefalsehardDeletetrue)]
  14. #[ORM\HasLifecycleCallbacks()]
  15. #[ApiResource(
  16.     attributes: ["security" => "is_granted('IS_AUTHENTICATED_FULLY')"],
  17. )]
  18. class Post
  19. {
  20.     use Timestamps;
  21.     #[ORM\Id]
  22.     #[ORM\Column(type'ulid'uniquetrue)]
  23.     #[ORM\GeneratedValue(strategy"CUSTOM")]
  24.     #[ORM\CustomIdGenerator(class: UlidGenerator::class)]
  25.     private ?Ulid $id null;
  26.     #[ORM\Column(type'string'length255)]
  27.     private $name;
  28.     #[ORM\Column(type'string'length255nullabletrue)]
  29.     private $description;
  30.     #[ORM\Column(type'string'length255nullabletrue)]
  31.     private $tags;
  32.     #[ORM\Column(type'date')]
  33.     private $date;
  34.     #[ORM\OneToMany(mappedBy'post'targetEntityImage::class, orphanRemovaltruecascade: ['persist'])]
  35.     private $images;
  36.     #[ORM\ManyToOne(targetEntityUser::class, inversedBy'posts')]
  37.     #[ORM\JoinColumn(nullablefalse)]
  38.     private $created_by;
  39.     #[ORM\ManyToOne(targetEntityCompany::class, inversedBy'posts')]
  40.     #[ORM\JoinColumn(nullablefalse)]
  41.     private $owner;
  42.     #[ORM\ManyToOne(targetEntityChild::class, inversedBy'posts')]
  43.     #[ORM\JoinColumn(nullablefalse)]
  44.     private $child;
  45.     public function __construct()
  46.     {
  47.         $this->images = new ArrayCollection();
  48.         $this->date = new DateTime();
  49.     }
  50.     public function getId(): ?Ulid
  51.     {
  52.         return $this->id;
  53.     }
  54.     public function getName(): ?string
  55.     {
  56.         return $this->name;
  57.     }
  58.     public function setName(string $name): self
  59.     {
  60.         $this->name $name;
  61.         return $this;
  62.     }
  63.     public function getDescription(): ?string
  64.     {
  65.         return $this->description;
  66.     }
  67.     public function setDescription(?string $description): self
  68.     {
  69.         $this->description $description;
  70.         return $this;
  71.     }
  72.     public function getTags(): ?string
  73.     {
  74.         return $this->tags;
  75.     }
  76.     public function setTags(?string $tags): self
  77.     {
  78.         $this->tags $tags;
  79.         return $this;
  80.     }
  81.     public function getDate(): ?\DateTimeInterface
  82.     {
  83.         return $this->date;
  84.     }
  85.     public function setDate(\DateTimeInterface $date): self
  86.     {
  87.         $this->date $date;
  88.         return $this;
  89.     }
  90.     /**
  91.      * @return Collection<int, Image>
  92.      */
  93.     public function getImages(): Collection
  94.     {
  95.         return $this->images;
  96.     }
  97.     public function addImage(Image $image): self
  98.     {
  99.         if (!$this->images->contains($image)) {
  100.             $this->images[] = $image;
  101.             $image->setPost($this);
  102.         }
  103.         return $this;
  104.     }
  105.     public function removeImage(Image $image): self
  106.     {
  107.         if ($this->images->removeElement($image)) {
  108.             // set the owning side to null (unless already changed)
  109.             if ($image->getPost() === $this) {
  110.                 $image->setPost(null);
  111.             }
  112.         }
  113.         return $this;
  114.     }
  115.     public function getCreatedBy(): ?User
  116.     {
  117.         return $this->created_by;
  118.     }
  119.     public function setCreatedBy(?User $created_by): self
  120.     {
  121.         $this->created_by $created_by;
  122.         return $this;
  123.     }
  124.     public function getOwner(): ?Company
  125.     {
  126.         return $this->owner;
  127.     }
  128.     public function setOwner(?Company $owner): self
  129.     {
  130.         $this->owner $owner;
  131.         return $this;
  132.     }
  133.     public function getChild(): ?Child
  134.     {
  135.         return $this->child;
  136.     }
  137.     public function setChild(?Child $child): self
  138.     {
  139.         $this->child $child;
  140.         return $this;
  141.     }
  142. }