<?php
namespace App\Entity;
use App\Repository\UserPlatformRepository;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\Validator\Mapping\ClassMetadata;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
use Symfony\Component\Security\Core\User\UserInterface;
/**
* @ORM\Entity(repositoryClass=UserPlatformRepository::class)
*/
class UserPlatform implements UserInterface, PasswordAuthenticatedUserInterface
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=180, nullable=true)
*/
private $email;
/**
* @ORM\Column(type="json")
*/
private $roles = [];
/**
* @ORM\Column(type="json", nullable=true)
*/
private $classes = [];
/**
* @ORM\Column(type="json", nullable=true)
*/
private $matieres = [];
/**
* @var string The hashed password
* @ORM\Column(type="string")
*/
private $password;
/**
* @ORM\Column(type="string", length=255)
*/
private $nameuser;
/**
* @ORM\Column(type="string", length=255)
*/
private $adresse;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $phone;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $mail;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $mdpnoncrypt;
/**
* @ORM\OneToMany(targetEntity=Consultactivite::class, mappedBy="user", cascade={"persist", "remove"})
*/
private $consultActivites;
public function __construct()
{
$this->consultActivites = new ArrayCollection();
}
public function getMdpnoncrypt(): ?string
{
return $this->mdpnoncrypt;
}
public function setMdpnoncrypt(?string $mdpnoncrypt): self
{
$this->mdpnoncrypt = $mdpnoncrypt;
return $this;
}
public function getId(): ?int
{
return $this->id;
}
public function getEmail(): ?string
{
return $this->email;
}
public function setEmail(?string $email): self
{
$this->email = empty($email) ? null : $email;
return $this;
}
public static function loadValidatorMetadata(ClassMetadata $metadata): void
{
$metadata->addConstraint(new Assert\Callback('validateEmailOrPhone'));
}
public function validateEmailOrPhone(\Symfony\Component\Validator\Context\ExecutionContextInterface $context): void
{
if (empty($this->email) && empty($this->phone)) {
$context->buildViolation('Veuillez remplir au moins l\'email ou le numéro de téléphone.')
->atPath('email') // Vous pouvez aussi choisir 'phone' ou les deux
->addViolation();
}
}
/**
* A visual identifier that represents this user.
*
* @see UserInterface
*/
public function getUserIdentifier(): string
{
return (string) $this->email;
}
/**
* @deprecated since Symfony 5.3, use getUserIdentifier instead
*/
public function getUsername(): 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 UserInterface
*/
public function getClasses(): array
{
$classes = $this->classes;
// guarantee every user at least has ROLE_USER
$classes[] = null ;
return array_unique($classes);
}
public function setClasses(array $classes): self
{
$this->classes = $classes;
return $this;
}
/**
* @see UserInterface
*/
public function getMatieres(): array
{
$matieres = $this->matieres;
// guarantee every user at least has ROLE_USER
$matieres[] = null ;
return array_unique($matieres);
}
public function setMatieres(array $matieres): self
{
$this->matieres = $matieres;
return $this;
}
/**
* @see PasswordAuthenticatedUserInterface
*/
public function getPassword(): string
{
return $this->password;
}
public function setPassword(string $password): self
{
$this->password = $password;
return $this;
}
/**
* Returning a salt is only needed, if you are not using a modern
* hashing algorithm (e.g. bcrypt or sodium) in your security.yaml.
*
* @see UserInterface
*/
public function getSalt(): ?string
{
return null;
}
/**
* @see UserInterface
*/
public function eraseCredentials()
{
// If you store any temporary, sensitive data on the user, clear it here
// $this->plainPassword = null;
}
public function getNameuser(): ?string
{
return $this->nameuser;
}
public function setNameuser(string $nameuser): self
{
$this->nameuser = $nameuser;
return $this;
}
public function getAdresse(): ?string
{
return $this->adresse;
}
public function setAdresse(string $adresse): self
{
$this->adresse = $adresse;
return $this;
}
public function getPhone(): ?string
{
return $this->phone;
}
public function setPhone(?string $phone): self
{
$this->phone = $phone;
return $this;
}
public function getMail(): ?string
{
return $this->mail;
}
public function setMail(?string $mail): self
{
$this->mail = $mail;
return $this;
}
/**
* @return Collection|Consultactivite[]
*/
public function getConsultActivites(): Collection
{
return $this->consultActivites;
}
public function addConsultActivite(Consultactivite $consultActivite): self
{
if (!$this->consultActivites->contains($consultActivite)) {
$this->consultActivites[] = $consultActivite;
$consultActivite->setUser($this);
}
return $this;
}
public function removeConsultActivite(Consultactivite $consultActivite): self
{
if ($this->consultActivites->removeElement($consultActivite)) {
// set the owning side to null (unless already changed)
if ($consultActivite->getUser() === $this) {
$consultActivite->setUser(null);
}
}
return $this;
}
}