src/Entity/Interest.php line 19

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use ApiPlatform\Core\Annotation\ApiResource;
  4. use App\Repository\InterestRepository;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection;
  7. use Doctrine\ORM\Mapping as ORM;
  8. use Symfony\Component\Serializer\Annotation\Groups;
  9. #[ORM\Entity(repositoryClassInterestRepository::class)]
  10. #[ApiResource(
  11.     normalizationContext: ['groups' => ['profile','read']],
  12.     denormalizationContext: ['groups' => ['profile']],
  13.     
  14.     )]
  15. class Interest
  16. {
  17.     #[ORM\Id]
  18.     #[ORM\GeneratedValue]
  19.     #[ORM\Column(type'integer')]
  20.     #[Groups("profile")]
  21.     private $id;
  22.     #[ORM\Column(type'string'length255nullabletrue)]
  23.     
  24.     #[Groups("profile")]
  25.     private $title;
  26.     #[ORM\Column(type'datetime'nullabletrue)]
  27.     
  28.     private $createdAt;
  29.     #[ORM\Column(type'datetime'nullabletrue)]
  30.     private $updatedAt;
  31.     #[ORM\ManyToMany(targetEntityProfile::class, mappedBy'interests')]
  32.     private Collection $profiles;
  33.     #[ORM\OneToMany(mappedBy'interest'targetEntityInterestTranslation::class, cascade: ["persist"])]
  34.     #[Groups("read")]
  35.     private Collection $translations;
  36.   
  37.     public function __construct()
  38.     {
  39.         $this->profiles = new ArrayCollection();
  40.         $this->translations = new ArrayCollection();
  41.     }
  42.     
  43.     public function __toString()
  44.     {
  45.         return (string)$this->title;
  46.     }
  47.     public function getId(): ?int
  48.     {
  49.         return $this->id;
  50.     }
  51.     public function getTitle(): ?string
  52.     {
  53.         return $this->title;
  54.     }
  55.     public function setTitle(?string $title): self
  56.     {
  57.         $this->title $title;
  58.         return $this;
  59.     }
  60.     public function getCreatedAt(): ?\DateTimeInterface
  61.     {
  62.         return $this->createdAt;
  63.     }
  64.     public function setCreatedAt(?\DateTimeInterface $createdAt): self
  65.     {
  66.         $this->createdAt $createdAt;
  67.         return $this;
  68.     }
  69.     public function getUpdatedAt(): ?\DateTimeInterface
  70.     {
  71.         return $this->updatedAt;
  72.     }
  73.     public function setUpdatedAt(?\DateTimeInterface $updatedAt): self
  74.     {
  75.         $this->updatedAt $updatedAt;
  76.         return $this;
  77.     }
  78.     /**
  79.      * @return Collection<int, Profile>
  80.      */
  81.     public function getProfiles(): Collection
  82.     {
  83.         return $this->profiles;
  84.     }
  85.     public function addProfile(Profile $profile): self
  86.     {
  87.         if (!$this->profiles->contains($profile)) {
  88.             $this->profiles->add($profile);
  89.             $profile->addInterest($this);
  90.         }
  91.         return $this;
  92.     }
  93.     public function removeProfile(Profile $profile): self
  94.     {
  95.         if ($this->profiles->removeElement($profile)) {
  96.             $profile->removeInterest($this);
  97.         }
  98.         return $this;
  99.     }
  100.     /**
  101.      * @return Collection<int, InterestTranslation>
  102.      */
  103.     public function getTranslations(): Collection
  104.     {
  105.         return $this->translations;
  106.     }
  107.     public function addTranslation(InterestTranslation $translation): self
  108.     {
  109.         if (!$this->translations->contains($translation)) {
  110.             $this->translations->add($translation);
  111.             $translation->setInterest($this);
  112.         }
  113.         return $this;
  114.     }
  115.     public function removeTranslation(InterestTranslation $translation): self
  116.     {
  117.         if ($this->translations->removeElement($translation)) {
  118.             // set the owning side to null (unless already changed)
  119.             if ($translation->getInterest() === $this) {
  120.                 $translation->setInterest(null);
  121.             }
  122.         }
  123.         return $this;
  124.     }
  125.    
  126. }