<?php
namespace App\Entity;
use ApiPlatform\Core\Annotation\ApiFilter;
use ApiPlatform\Core\Annotation\ApiResource;
use ApiPlatform\Core\Annotation\ApiSubresource;
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter;
use App\Repository\UserRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Component\Serializer\Annotation\Groups;
#[ORM\Entity(repositoryClass: UserRepository::class)]
#[ORM\Table(name: '`user`')]
#[UniqueEntity(fields: ['email'])]
#[ApiResource(normalizationContext: ['groups' => ['profile']],denormalizationContext: ['groups' => ['profile']])]
#[ApiFilter(SearchFilter::class,properties:["googleId"=>"exact","facebookId"=>"exact","email"=>"exact"])]
class User implements UserInterface, PasswordAuthenticatedUserInterface
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: 'integer')]
#[Groups("profile")]
private $id;
#[ORM\Column(type: 'string', length: 180, unique: true)]
#[Groups(["profile","read_2"])]
private $email;
#[ORM\Column(type: 'json')]
private $roles = [];
#[ORM\Column(type: 'string')]
#[Groups("profile")]
private $password;
#[ORM\ManyToMany(targetEntity: Answer::class, inversedBy: 'users', cascade: ["persist"])]
private $answers;
#[ORM\OneToOne(mappedBy: 'user', targetEntity: Profile::class, cascade: ['persist', 'remove'])]
private $profile;
#[ORM\Column(type: 'boolean', nullable: true)]
private $isDisabled;
#[ORM\Column(nullable: true)]
#[Groups("profile")]
private ?bool $isCompleted = null;
#[ORM\Column(type: 'boolean')]
#[Groups("profile")]
private $isVerified = false;
#[Groups("profile")]
#[ORM\Column(length: 255, nullable: true)]
private ?string $googleId = null;
#[Groups("profile")]
#[ORM\Column(length: 255, nullable: true)]
private ?string $facebookId = null;
public function __toString()
{
return (string)$this->email;
}
public function __construct()
{
$this->answers = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getEmail(): ?string
{
return $this->email;
}
public function setEmail(string $email): self
{
$this->email = $email;
return $this;
}
public function isIsCompleted(): ?bool
{
return $this->isCompleted;
}
public function setIsCompleted(?bool $isCompleted): self
{
$this->isCompleted = $isCompleted;
return $this;
}
/**
* A visual identifier that represents this user.
*
* @see UserInterface
*/
public function getUserIdentifier(): string
{
return (string) $this->email;
}
/**
* @see UserInterface
*/
public function getRoles(): array
{
$roles = $this->roles;
// guarantee every user at least has ROLE_USER
$roles[] = 'ROLE_USER';
return array_unique($roles);
}
public function setRoles(array $roles): self
{
$this->roles = $roles;
return $this;
}
/**
* @see PasswordAuthenticatedUserInterface
*/
public function getPassword(): string
{
return $this->password;
}
public function setPassword(string $password): self
{
$this->password = $password;
return $this;
}
/**
* @see UserInterface
*/
public function eraseCredentials()
{
// If you store any temporary, sensitive data on the user, clear it here
// $this->plainPassword = null;
}
/**
* @return Collection<int, Answer>
*/
public function getAnswers(): Collection
{
return $this->answers;
}
public function addAnswer(Answer $answer): self
{
if (!$this->answers->contains($answer)) {
$this->answers[] = $answer;
}
return $this;
}
public function removeAnswer(Answer $answer): self
{
$this->answers->removeElement($answer);
return $this;
}
public function getProfile(): ?Profile
{
return $this->profile;
}
public function setProfile(?Profile $profile): self
{
$this->profile = $profile;
return $this;
}
public function isIsDisabled(): ?bool
{
return $this->isDisabled;
}
public function setIsDisabled(?bool $isDisabled): self
{
$this->isDisabled = $isDisabled;
return $this;
}
public function isVerified(): bool
{
return $this->isVerified;
}
public function setIsVerified(bool $isVerified): self
{
$this->isVerified = $isVerified;
return $this;
}
public function getGoogleId(): ?string
{
return $this->googleId;
}
public function setGoogleId(?string $googleId): self
{
$this->googleId = $googleId;
return $this;
}
public function getFacebookId(): ?string
{
return $this->facebookId;
}
public function setFacebookId(?string $facebookId): self
{
$this->facebookId = $facebookId;
return $this;
}
}