src/Entity/CommentRecipe.php line 15

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Entity\traits\Timestapable;
  4. use App\Repository\CommentRecipeRepository;
  5. use Doctrine\DBAL\Types\Types;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use Doctrine\ORM\Mapping\HasLifecycleCallbacks;
  8. use Doctrine\ORM\Mapping\PrePersist;
  9. use Symfony\Component\Serializer\Annotation\Groups;
  10. #[ORM\Entity(repositoryClassCommentRecipeRepository::class)]
  11. #[HasLifecycleCallbacks]
  12. class CommentRecipe
  13. {
  14.     use Timestapable;
  15.     #[ORM\Id]
  16.     #[ORM\GeneratedValue]
  17.     #[ORM\Column]
  18.     private ?int $id null;
  19.     #[ORM\ManyToOne(inversedBy'commentRecipes'cascade:['persist''remove'])]
  20.     #[ORM\JoinColumn(name:"recipe_id"referencedColumnName:"id"onDelete:"CASCADE", )]
  21.     #[Groups(["comment_list"])]
  22.     private ?recipe $recipe null;
  23.     #[ORM\Column(typeTypes::TEXT)]
  24.     #[Groups(["show_recipe""comment_list"])]
  25.     private ?string $content null;
  26.     #[Groups(["show_recipe""comment_list"])]
  27.     #[ORM\ManyToOne(inversedBy'commentRecipes')]
  28.     private ?User $user null;
  29.     #[PrePersist]
  30.     public function prePersist()
  31.     {
  32.         $this->createdAt = new \DateTimeImmutable();
  33.     }
  34.     public function getRecipe($need false)
  35.     {
  36.         if ($need == true) {
  37.             return $this->recipe;
  38.         } else {
  39.             return null;
  40.         }
  41.     }
  42.     public function setRecipe(?recipe $recipe): self
  43.     {
  44.         $this->recipe $recipe;
  45.         return $this;
  46.     }
  47.     public function getContent(): ?string
  48.     {
  49.         return $this->content;
  50.     }
  51.     public function setContent(string $content): self
  52.     {
  53.         $this->content $content;
  54.         return $this;
  55.     }
  56.     public function getUser($need true)
  57.     {
  58.         if ($need == true) {
  59.             return $this->user;
  60.         } else {
  61.             return null;
  62.         }
  63.     }
  64.     public function setUser(?User $user): self
  65.     {
  66.         $this->user $user;
  67.         return $this;
  68.     }
  69. }