src/Entity/User.php line 37
<?phpnamespace App\Entity;use ApiPlatform\Metadata\ApiResource;use ApiPlatform\Metadata\Post;use App\Controller\Api\ApiRegisterController;use App\Repository\UserRepository;use App\Service\GeoIP;use App\Trait\DateTrait;use App\Trait\DeletableTrait;use App\Trait\Notifiable;use DateTimeImmutable;use DateTimeInterface;use Doctrine\Common\Collections\ArrayCollection;use Doctrine\Common\Collections\Collection;use Doctrine\ORM\Mapping as ORM;use GeoIp2\Exception\AddressNotFoundException;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;use Symfony\Component\Validator\Constraints as Assert;#[ORM\Entity(repositoryClass: UserRepository::class)]#[ORM\Table(name: '`user`')]#[UniqueEntity(fields: ['email'], message: "Cet adresse email est déjà utilisée pour un autre compte")]#[UniqueEntity(fields: ['phone'], message: "Ce numéro est déjà utilisé pour un autre compte")]#[ApiResource(operations: [new Post(uriTemplate: '/register',controller: ApiRegisterController::class,denormalizationContext: ['groups' => ['user:register']],write: false)])]class User implements UserInterface, PasswordAuthenticatedUserInterface{use DateTrait;use Notifiable;use DeletableTrait;#[ORM\Id]#[ORM\GeneratedValue]#[ORM\Column]#[Groups(['article:view'])]private ?int $id = null;#[ORM\Column(length: 255, nullable: true)]#[Groups(['user:register', 'article:view'])]private ?string $lastname = null;#[ORM\Column(length: 255)]#[Groups(['user:register', 'article:view'])]private ?string $firstname = null;#[ORM\Column(length: 180, unique: true)]#[Groups(['user:register'])]private ?string $email = null;#[ORM\Column]private array $roles = [];/*** @var string The hashed password*/#[ORM\Column]#[Groups(['user:register'])]private ?string $password = null;#[ORM\Column(length: 15, unique: true)]#[Groups(['user:register'])]private ?string $phone = null;#[ORM\Column(options: ["default" => false])]private ?bool $isPhoneVerified = false;#[ORM\ManyToOne(cascade: ["persist"])]#[ORM\JoinColumn(nullable: true)]private ?Attachment $thumbnail = null;#[ORM\Column(length: 3, nullable: true, options: ["default" => "CD"])]private ?string $country;#[ORM\Column(length: 255, nullable: true)]private ?string $lastLoginIp = null;#[ORM\Column(nullable: true)]private ?DateTimeImmutable $lastLoginAt = null;#[ORM\Column(nullable: true)]private ?DateTimeInterface $bannedAt = null;#[ORM\Column(nullable: true)]private ?string $confirmationToken = null;#[ORM\Column(type: 'boolean')]private bool $isVerified = false;#[ORM\Column(type: 'string', nullable: true, options: ["default" => null])]private ?string $theme = null;#[ORM\OneToMany(mappedBy: 'author', targetEntity: Article::class, orphanRemoval: true)]private Collection $articles;#[ORM\OneToMany(mappedBy: 'author', targetEntity: Service::class, orphanRemoval: true)]private Collection $services;#[ORM\OneToMany(mappedBy: 'user', targetEntity: Establishment::class, orphanRemoval: true)]private Collection $establishments;#[ORM\OneToMany(mappedBy: 'user', targetEntity: ConnectionLog::class, orphanRemoval: true)]private Collection $connectionLogs;#[ORM\Column(options: ['default' => true])]private ?bool $isActive = true;#[ORM\OneToMany(mappedBy: 'user', targetEntity: OTP::class, orphanRemoval: true)]private Collection $OTPs;#[ORM\Column(length: 255, nullable: true)]private ?string $city = null;#[ORM\Column(length: 255, nullable: true)]private ?string $latitude = null;#[ORM\Column(length: 255, nullable: true)]private ?string $longitude = null;#[ORM\Column(length: 255, nullable: true)]private ?string $timeZone = null;#[ORM\Column(length: 255, nullable: true)]private ?string $postal = null;#[ORM\Column(length: 255, nullable: true)]private ?string $ip = null;#[ORM\Column(length: 255, nullable: true)]private ?string $subdivisions = null;#[ORM\Column(length: 255, nullable: true)]private ?string $isp = null;#[ORM\OneToMany(mappedBy: 'createdBy', targetEntity: Cms::class)]private Collection $cms;#[ORM\OneToOne(inversedBy: 'user', cascade: ['persist', 'remove'])]private ?UserDetail $detail = null;#[ORM\OneToMany(mappedBy: 'user', targetEntity: Mutuality::class)]private Collection $mutualities;#[ORM\Column(length: 255, options: ['default' => "fr"])]#[Assert\Locale(canonicalize: true,)]private ?string $locale;#[ORM\OneToMany(mappedBy: 'author', targetEntity: Planning::class)]private Collection $createdPlannings;#[ORM\ManyToMany(targetEntity: Planning::class, mappedBy: 'users')]private Collection $plannings;public function __construct($ip = null){if (is_null($this->createdAt)) $this->createdAt = new DateTimeImmutable();$this->updatedAt = new DateTimeImmutable();$this->OTPs = new ArrayCollection();$this->country = 'CD';$this->locale = 'fr';if ($ip) $this->initGeoIp($ip);$this->articles = new ArrayCollection();$this->services = new ArrayCollection();$this->establishments = new ArrayCollection();$this->connectionLogs = new ArrayCollection();$this->cms = new ArrayCollection();$this->mutualities = new ArrayCollection();}public function __serialize(): array{return [$this->id, $this->phone, $this->email, $this->password,];}public function __unserialize(array $data): void{if (count($data) === 4) [$this->id, $this->phone, $this->email, $this->password,] = $data;}public function __toString(): string{return "$this->firstname $this->lastname";}public function getId(): ?int{return $this->id;}public function getName(){return "$this->firstname $this->lastname";}public function getLastname(): ?string{return $this->lastname;}public function setLastname(?string $lastname): self{$this->lastname = $lastname;return $this;}public function getFirstname(): ?string{return $this->firstname;}public function setFirstname(string $firstname): self{$this->firstname = $firstname;return $this;}public function getEmail(): ?string{return $this->email;}public function setEmail(string $email): self{$this->email = $email;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;}public function getPhone(): ?string{return $this->phone;}public function getThumbnail(): ?Attachment{return $this->thumbnail;}public function setThumbnail(?Attachment $thumbnail): self{$this->thumbnail = $thumbnail;return $this;}public function setPhone(string $phone): static{$this->phone = GeoIP::phoneResolve($phone, $this->country);return $this;}public function isIsActive(): ?bool{return $this->isActive;}public function setIsActive(bool $isActive): static{$this->isActive = $isActive;return $this;}public function getCity(): ?string{return $this->city;}public function setCity(?string $city): self{$this->city = $city;return $this;}public function getLatitude(): ?string{return $this->latitude;}public function setLatitude(?string $latitude): self{$this->latitude = $latitude;return $this;}public function getLongitude(): ?string{return $this->longitude;}public function setLongitude(?string $longitude): self{$this->longitude = $longitude;return $this;}public function getTimeZone(): ?string{return $this->timeZone;}public function setTimeZone(?string $timeZone): self{$this->timeZone = $timeZone;return $this;}public function getPostal(): ?string{return $this->postal;}public function setPostal(?string $postal): self{$this->postal = $postal;return $this;}public function getIp(): ?string{return $this->ip;}public function setIp(?string $ip): self{$this->ip = $ip;return $this;}public function getSubdivisions(): ?string{return $this->subdivisions;}public function setSubdivisions(?string $subdivisions): self{$this->subdivisions = $subdivisions;return $this;}public function getIsp(): ?string{return $this->isp;}public function setIsp(?string $isp): self{$this->isp = $isp;return $this;}public function getLastLogin(): ?DateTimeImmutable{return $this->lastLogin;}public function setLastLogin(DateTimeImmutable $lastLogin): self{$this->lastLogin = $lastLogin;return $this;}public function getCountry(): ?string{return $this->country ?: 'CD';}public function setCountry(?string $country): self{$this->country = $country;return $this;}public function getLastLoginIp(): ?string{return $this->lastLoginIp;}public function setLastLoginIp(?string $lastLoginIp): User{$this->lastLoginIp = $lastLoginIp;return $this;}public function getLastLoginAt(): ?DateTimeImmutable{return $this->lastLoginAt;}public function setLastLoginAt(DateTimeImmutable $lastLoginAt): self{$this->lastLoginAt = $lastLoginAt;return $this;}public function isBanned(): bool{return null !== $this->bannedAt;}public function getBannedAt(): ?DateTimeInterface{return $this->bannedAt;}public function setBannedAt(?DateTimeInterface $bannedAt): User{$this->bannedAt = $bannedAt;return $this;}public function getConfirmationToken(): ?string{return $this->confirmationToken;}public function setConfirmationToken(?string $confirmationToken): User{$this->confirmationToken = $confirmationToken;return $this;}public function canLogin(): bool{return !$this->isBanned() && null === $this->getConfirmationToken();}public function isVerified(): bool{return $this->isVerified;}public function setIsVerified(bool $isVerified): self{$this->isVerified = $isVerified;return $this;}public function getTheme(): ?string{return $this->theme;}public function setTheme(?string $theme): self{$this->theme = $theme;return $this;}/*** @return Collection<int, Article>*/public function getArticles(): Collection{return $this->articles;}public function addArticle(Article $article): self{if (!$this->articles->contains($article)) {$this->articles->add($article);$article->setAuthor($this);}return $this;}public function removeArticle(Article $article): self{if ($this->articles->removeElement($article)) {if ($article->getAuthor() === $this) {$article->setAuthor(null);}}return $this;}/*** @return Collection<int, Service>*/public function getServices(): Collection{return $this->services;}public function addService(Service $service): self{if (!$this->services->contains($service)) {$this->services->add($service);$service->setAuthor($this);}return $this;}public function removeService(Service $service): self{if ($this->services->removeElement($service)) {// set the owning side to null (unless already changed)if ($service->getAuthor() === $this) {$service->setAuthor(null);}}return $this;}/*** @return Collection<int, Establishment>*/public function getEstablishments(): Collection{return $this->establishments;}public function addEstablishment(Establishment $establishment): self{if (!$this->establishments->contains($establishment)) {$this->establishments->add($establishment);$establishment->setUser($this);}return $this;}public function removeEstablishment(Establishment $establishment): self{if ($this->establishments->removeElement($establishment)) {// set the owning side to null (unless already changed)if ($establishment->getUser() === $this) {$establishment->setUser(null);}}return $this;}/*** @return Collection<int, ConnectionLog>*/public function getConnectionLogs(): Collection{return $this->connectionLogs;}public function addConnectionLog(ConnectionLog $connectionLog): self{if (!$this->connectionLogs->contains($connectionLog)) {$this->connectionLogs->add($connectionLog);$connectionLog->setUser($this);}return $this;}public function removeConnectionLog(ConnectionLog $connectionLog): self{if ($this->connectionLogs->removeElement($connectionLog)) {// set the owning side to null (unless already changed)if ($connectionLog->getUser() === $this) {$connectionLog->setUser(null);}}return $this;}/*** @return Collection<int, Cms>*/public function getCms(): Collection{return $this->cms;}public function addCm(Cms $cm): self{if (!$this->cms->contains($cm)) {$this->cms->add($cm);$cm->setCreatedBy($this);}return $this;}public function removeCm(Cms $cm): self{if ($this->cms->removeElement($cm)) {// set the owning side to null (unless already changed)if ($cm->getCreatedBy() === $this) {$cm->setCreatedBy(null);}}return $this;}/*** @param string $ip* @throws \Exception*/public function initGeoIp(string $ip): void{try {$isLocal = in_array($ip, ['127.0.0.1', '::1']);$ip = $isLocal ? '41.78.192.90' : $ip;$record = GeoIP::check($ip);$this->setCountry($record->countryCode ?? null); // 'US'$this->setIsp($record->isp ?? null);$this->setSubdivisions($record->regionName ?? null);$this->setCity($record->city ?? null); // 'Minneapolis'$this->setPostal($record->zip ?? null); // '55455'$this->setIp($record->query ?? null);$this->setTimeZone($record->timezone ?? null);$this->setLatitude($record->lat ?? null); // 44.9733$this->setLongitude($record->lon ?? null);} catch (AddressNotFoundException $ex) {throw new \Exception("It wasn't possible to retrieve information about the providen IP");}}public function isIsPhoneVerified(): ?bool{return $this->isPhoneVerified;}public function setIsPhoneVerified(bool $isPhoneVerified): static{$this->isPhoneVerified = $isPhoneVerified;return $this;}public function getGender(): ?string{return $this->gender;}public function setGender(string $gender): static{$this->gender = $gender;return $this;}public function getDetail(): ?UserDetail{return $this->detail;}public function setDetail(?UserDetail $detail): static{$this->detail = $detail;return $this;}/*** @return Collection<int, Mutuality>*/public function getMutualities(): Collection{return $this->mutualities;}public function addMutuality(Mutuality $mutuality): static{if (!$this->mutualities->contains($mutuality)) {$this->mutualities->add($mutuality);$mutuality->setUser($this);}return $this;}public function removeMutuality(Mutuality $mutuality): static{if ($this->mutualities->removeElement($mutuality)) {// set the owning side to null (unless already changed)if ($mutuality->getUser() === $this) {$mutuality->setUser(null);}}return $this;}public function getFullname(): string{return $this->firstname . ' ' . $this->lastname;}public function getLocale(): ?string{return $this->locale;}public function setLocale(string $locale): static{$this->locale = $locale;return $this;}}