<?php
namespace App\Entity;
use ApiPlatform\Core\Annotation\ApiResource;
use App\Repository\InterestRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation\Groups;
#[ORM\Entity(repositoryClass: InterestRepository::class)]
#[ApiResource(
normalizationContext: ['groups' => ['profile','read']],
denormalizationContext: ['groups' => ['profile']],
)]
class Interest
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: 'integer')]
#[Groups("profile")]
private $id;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
#[Groups("profile")]
private $title;
#[ORM\Column(type: 'datetime', nullable: true)]
private $createdAt;
#[ORM\Column(type: 'datetime', nullable: true)]
private $updatedAt;
#[ORM\ManyToMany(targetEntity: Profile::class, mappedBy: 'interests')]
private Collection $profiles;
#[ORM\OneToMany(mappedBy: 'interest', targetEntity: InterestTranslation::class, cascade: ["persist"])]
#[Groups("read")]
private Collection $translations;
public function __construct()
{
$this->profiles = new ArrayCollection();
$this->translations = new ArrayCollection();
}
public function __toString()
{
return (string)$this->title;
}
public function getId(): ?int
{
return $this->id;
}
public function getTitle(): ?string
{
return $this->title;
}
public function setTitle(?string $title): self
{
$this->title = $title;
return $this;
}
public function getCreatedAt(): ?\DateTimeInterface
{
return $this->createdAt;
}
public function setCreatedAt(?\DateTimeInterface $createdAt): self
{
$this->createdAt = $createdAt;
return $this;
}
public function getUpdatedAt(): ?\DateTimeInterface
{
return $this->updatedAt;
}
public function setUpdatedAt(?\DateTimeInterface $updatedAt): self
{
$this->updatedAt = $updatedAt;
return $this;
}
/**
* @return Collection<int, Profile>
*/
public function getProfiles(): Collection
{
return $this->profiles;
}
public function addProfile(Profile $profile): self
{
if (!$this->profiles->contains($profile)) {
$this->profiles->add($profile);
$profile->addInterest($this);
}
return $this;
}
public function removeProfile(Profile $profile): self
{
if ($this->profiles->removeElement($profile)) {
$profile->removeInterest($this);
}
return $this;
}
/**
* @return Collection<int, InterestTranslation>
*/
public function getTranslations(): Collection
{
return $this->translations;
}
public function addTranslation(InterestTranslation $translation): self
{
if (!$this->translations->contains($translation)) {
$this->translations->add($translation);
$translation->setInterest($this);
}
return $this;
}
public function removeTranslation(InterestTranslation $translation): self
{
if ($this->translations->removeElement($translation)) {
// set the owning side to null (unless already changed)
if ($translation->getInterest() === $this) {
$translation->setInterest(null);
}
}
return $this;
}
}