<?php namespace App\Entity; use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\Collection; use Doctrine\ORM\Mapping as ORM; use Symfony\Component\Validator\Constraints as Assert; use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity; /** * @ORM\Entity() * @UniqueEntity("libelle") * @UniqueEntity("code") * @ORM\Table(uniqueConstraints={ * @ORM\UniqueConstraint(columns={"label", "code"}) * }) */ class Country { /** * @ORM\Id * @ORM\GeneratedValue * @ORM\Column(type="integer") */ private ?int $id = null; /** * @ORM\Column(type="string") * @Assert\NotBlank() * @Assert\Type("string") */ private ?string $label = ''; /** * @ORM\Column(type="string") * @Assert\NotBlank() * @Assert\Type("string") */ private ?string $code = ''; /** * @ORM\Column(type="string") * @Assert\NotBlank() * @Assert\Type("string") */ private ?string $code3 = ''; /** * @ORM\Column(type="string", nullable="true") * @Assert\Type("string") */ private ?string $codeINSEE = null; /** * @ORM\OneToMany(targetEntity=User::class, mappedBy="country") */ private Collection $users; public function __construct() { $this->users = new ArrayCollection(); } /** * @return string */ public function __toString(): string { return $this->label; } /** * @return int|null */ public function getId(): ?int { return $this->id; } /** * @return string */ public function getLabel(): string { return $this->label; } /** * @param string $label * @return Country */ public function setLabel(string $label): Country { $this->label = trim($label); return $this; } /** * @return string */ public function getCode(): string { return $this->code; } /** * @param string $code * @return Country */ public function setCode(string $code): Country { $this->code = trim($code); return $this; } /** * @return ?string */ public function getCodeINSEE(): ?string { return $this->codeINSEE; } /** * @param string $codeINSEE * @return Country */ public function setCodeINSEE(?string $codeINSEE = null): Country { $this->codeINSEE = $codeINSEE; return $this; } /** * @return bool */ public function isEtranger(): bool { return $this->label != 'France'; } /** * @return bool */ public function isFrance(): bool { return $this->label == 'France'; } /** * @return string */ public function getCode3(): string { return $this->code3; } /** * @param string $code3 * @return Country */ public function setCode3(string $code3): Country { $this->code3 = $code3; return $this; } /** * @return Collection|User[] */ public function getUsers(): Collection { return $this->users; } public function addUser(User $user): self { if (!$this->users->contains($user)) { $this->users[] = $user; $user->setCountry($this); } return $this; } }