diff --git a/src/Entity/Commentary.php b/src/Entity/Commentary.php index 669cbfd..f54f60c 100644 --- a/src/Entity/Commentary.php +++ b/src/Entity/Commentary.php @@ -18,6 +18,14 @@ class Commentary #[ORM\Column(length: 255, nullable: true)] private ?string $text = null; + #[ORM\ManyToOne(inversedBy: 'commentaries')] + #[ORM\JoinColumn(nullable: false)] + private ?Post $post = null; + + #[ORM\ManyToOne(inversedBy: 'commentaries')] + #[ORM\JoinColumn(nullable: false)] + private ?Profil $profil = null; + public function getId(): ?int { return $this->id; @@ -34,4 +42,28 @@ class Commentary return $this; } + + public function getPost(): ?Post + { + return $this->post; + } + + public function setPost(?Post $post): static + { + $this->post = $post; + + return $this; + } + + public function getProfil(): ?Profil + { + return $this->profil; + } + + public function setProfil(?Profil $profil): static + { + $this->profil = $profil; + + return $this; + } } diff --git a/src/Entity/Post.php b/src/Entity/Post.php index 98e5ed5..54cfa46 100644 --- a/src/Entity/Post.php +++ b/src/Entity/Post.php @@ -4,6 +4,8 @@ namespace App\Entity; use ApiPlatform\Metadata\ApiResource; use App\Repository\PostRepository; +use Doctrine\Common\Collections\ArrayCollection; +use Doctrine\Common\Collections\Collection; use Doctrine\ORM\Mapping as ORM; #[ORM\Entity(repositoryClass: PostRepository::class)] @@ -30,6 +32,28 @@ class Post #[ORM\Column] private ?int $downVote = null; + #[ORM\ManyToOne(inversedBy: 'posts')] + #[ORM\JoinColumn(nullable: false)] + private ?Profil $profil = null; + + /** + * @var Collection + */ + #[ORM\OneToMany(targetEntity: Commentary::class, mappedBy: 'post')] + private Collection $commentaries; + + /** + * @var Collection + */ + #[ORM\ManyToMany(targetEntity: Tags::class, inversedBy: 'posts')] + private Collection $tags; + + public function __construct() + { + $this->commentaries = new ArrayCollection(); + $this->tags = new ArrayCollection(); + } + public function getId(): ?int { return $this->id; @@ -94,4 +118,70 @@ class Post return $this; } + + public function getProfil(): ?Profil + { + return $this->profil; + } + + public function setProfil(?Profil $profil): static + { + $this->profil = $profil; + + return $this; + } + + /** + * @return Collection + */ + public function getCommentaries(): Collection + { + return $this->commentaries; + } + + public function addCommentary(Commentary $commentary): static + { + if (!$this->commentaries->contains($commentary)) { + $this->commentaries->add($commentary); + $commentary->setPost($this); + } + + return $this; + } + + public function removeCommentary(Commentary $commentary): static + { + if ($this->commentaries->removeElement($commentary)) { + // set the owning side to null (unless already changed) + if ($commentary->getPost() === $this) { + $commentary->setPost(null); + } + } + + return $this; + } + + /** + * @return Collection + */ + public function getTags(): Collection + { + return $this->tags; + } + + public function addTag(Tags $tag): static + { + if (!$this->tags->contains($tag)) { + $this->tags->add($tag); + } + + return $this; + } + + public function removeTag(Tags $tag): static + { + $this->tags->removeElement($tag); + + return $this; + } } diff --git a/src/Entity/Profil.php b/src/Entity/Profil.php index 2d10216..f93f791 100644 --- a/src/Entity/Profil.php +++ b/src/Entity/Profil.php @@ -4,6 +4,8 @@ namespace App\Entity; use ApiPlatform\Metadata\ApiResource; use App\Repository\ProfilRepository; +use Doctrine\Common\Collections\ArrayCollection; +use Doctrine\Common\Collections\Collection; use Doctrine\ORM\Mapping as ORM; #[ORM\Entity(repositoryClass: ProfilRepository::class)] @@ -24,6 +26,31 @@ class Profil #[ORM\Column(length: 255, nullable: true)] private ?string $password = null; + /** + * @var Collection + */ + #[ORM\OneToMany(targetEntity: Post::class, mappedBy: 'profil')] + private Collection $posts; + + /** + * @var Collection + */ + #[ORM\OneToMany(targetEntity: Commentary::class, mappedBy: 'profil')] + private Collection $commentaries; + + /** + * @var Collection + */ + #[ORM\ManyToMany(targetEntity: self::class, inversedBy: 'followers')] + private Collection $followers; + + public function __construct() + { + $this->posts = new ArrayCollection(); + $this->commentaries = new ArrayCollection(); + $this->followers = new ArrayCollection(); + } + public function getId(): ?int { return $this->id; @@ -64,4 +91,88 @@ class Profil return $this; } + + /** + * @return Collection + */ + public function getPosts(): Collection + { + return $this->posts; + } + + public function addPost(Post $post): static + { + if (!$this->posts->contains($post)) { + $this->posts->add($post); + $post->setProfil($this); + } + + return $this; + } + + public function removePost(Post $post): static + { + if ($this->posts->removeElement($post)) { + // set the owning side to null (unless already changed) + if ($post->getProfil() === $this) { + $post->setProfil(null); + } + } + + return $this; + } + + /** + * @return Collection + */ + public function getCommentaries(): Collection + { + return $this->commentaries; + } + + public function addCommentary(Commentary $commentary): static + { + if (!$this->commentaries->contains($commentary)) { + $this->commentaries->add($commentary); + $commentary->setProfil($this); + } + + return $this; + } + + public function removeCommentary(Commentary $commentary): static + { + if ($this->commentaries->removeElement($commentary)) { + // set the owning side to null (unless already changed) + if ($commentary->getProfil() === $this) { + $commentary->setProfil(null); + } + } + + return $this; + } + + /** + * @return Collection + */ + public function getFollowers(): Collection + { + return $this->followers; + } + + public function addFollower(self $follower): static + { + if (!$this->followers->contains($follower)) { + $this->followers->add($follower); + } + + return $this; + } + + public function removeFollower(self $follower): static + { + $this->followers->removeElement($follower); + + return $this; + } } diff --git a/src/Entity/Tags.php b/src/Entity/Tags.php index 61657dc..817c672 100644 --- a/src/Entity/Tags.php +++ b/src/Entity/Tags.php @@ -4,6 +4,8 @@ namespace App\Entity; use ApiPlatform\Metadata\ApiResource; use App\Repository\TagsRepository; +use Doctrine\Common\Collections\ArrayCollection; +use Doctrine\Common\Collections\Collection; use Doctrine\ORM\Mapping as ORM; #[ORM\Entity(repositoryClass: TagsRepository::class)] @@ -21,6 +23,17 @@ class Tags #[ORM\Column(length: 255, nullable: true)] private ?string $color = null; + /** + * @var Collection + */ + #[ORM\ManyToMany(targetEntity: Post::class, mappedBy: 'tags')] + private Collection $posts; + + public function __construct() + { + $this->posts = new ArrayCollection(); + } + public function getId(): ?int { return $this->id; @@ -49,4 +62,31 @@ class Tags return $this; } + + /** + * @return Collection + */ + public function getPosts(): Collection + { + return $this->posts; + } + + public function addPost(Post $post): static + { + if (!$this->posts->contains($post)) { + $this->posts->add($post); + $post->addTag($this); + } + + return $this; + } + + public function removePost(Post $post): static + { + if ($this->posts->removeElement($post)) { + $post->removeTag($this); + } + + return $this; + } }