src/Entity/User.php line 16

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\UserRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  8. use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
  9. use Symfony\Component\Security\Core\User\UserInterface;
  10. #[ORM\Entity(repositoryClassUserRepository::class)]
  11. #[UniqueEntity(fields: ['email'], message'There is already an account with this email')]
  12. class User implements UserInterfacePasswordAuthenticatedUserInterface
  13. {
  14.     #[ORM\Id]
  15.     #[ORM\GeneratedValue]
  16.     #[ORM\Column]
  17.     private ?int $id null;
  18.     #[ORM\Column(length180uniquetrue)]
  19.     private ?string $email null;
  20.     #[ORM\Column]
  21.     private array $roles = [];
  22.     /**
  23.      * @var string The hashed password
  24.      */
  25.     #[ORM\Column]
  26.     private ?string $password null;
  27.     #[ORM\Column(type'boolean')]
  28.     private $isVerified false;
  29.     #[ORM\Column(length150nullabletrue)]
  30.     private ?string $firstname null;
  31.     #[ORM\Column(length150nullabletrue)]
  32.     private ?string $lastname null;
  33.     #[ORM\Column(length50nullabletrue)]
  34.     private ?string $phone_number null;
  35.     #[ORM\ManyToMany(targetEntityConferences::class, mappedBy'presidents')]
  36.     private Collection $presidents;
  37.     #[ORM\ManyToMany(targetEntityConferences::class, mappedBy'conferenciers')]
  38.     private Collection $conferenciers;
  39.     #[ORM\ManyToMany(targetEntitySeminaires::class, mappedBy'admins')]
  40.     private Collection $seminaires;
  41.     #[ORM\ManyToMany(targetEntitySeminaires::class, mappedBy'communicants')]
  42.     private Collection $MySeminaires;
  43.     #[ORM\Column(length255nullabletrue)]
  44.     private ?string $plainpassword null;
  45.     #[ORM\ManyToMany(targetEntityCommunications::class, mappedBy'conferenciers')]
  46.     private Collection $communications;
  47.     #[ORM\Column(length255nullabletrue)]
  48.     private ?string $avatar null;
  49.     public function __construct()
  50.     {
  51.         $this->presidents = new ArrayCollection();
  52.         $this->conferenciers = new ArrayCollection();
  53.         $this->seminaires = new ArrayCollection();
  54.         $this->MySeminaires = new ArrayCollection();
  55.         $this->communications = new ArrayCollection();
  56.     }
  57.     public function getId(): ?int
  58.     {
  59.         return $this->id;
  60.     }
  61.     public function setId($id): self
  62.     {
  63.         $this->id $id;
  64.         return $this;
  65.     }
  66.     public function getEmail(): ?string
  67.     {
  68.         return $this->email;
  69.     }
  70.     public function setEmail(string $email): self
  71.     {
  72.         $this->email $email;
  73.         return $this;
  74.     }
  75.     /**
  76.      * A visual identifier that represents this user.
  77.      *
  78.      * @see UserInterface
  79.      */
  80.     public function getUserIdentifier(): string
  81.     {
  82.         return (string) $this->email;
  83.     }
  84.     /**
  85.      * @see UserInterface
  86.      */
  87.     public function getRoles(): array
  88.     {
  89.         $roles $this->roles;
  90.         // guarantee every user at least has ROLE_USER
  91.         $roles[] = 'ROLE_USER';
  92.         return array_unique($roles);
  93.     }
  94.     public function setRoles(array $roles): self
  95.     {
  96.         $this->roles $roles;
  97.         return $this;
  98.     }
  99.     public function addRole($role): self {
  100.         if(!in_array($role,$this->getRoles())){
  101.             $roles $this->getRoles();
  102.             array_push($roles,$role);
  103.             $this->setRoles($roles);
  104.         }
  105.         return $this;
  106.     }
  107.     /**
  108.      * @see PasswordAuthenticatedUserInterface
  109.      */
  110.     public function getPassword(): string
  111.     {
  112.         return $this->password;
  113.     }
  114.     public function setPassword(string $password): self
  115.     {
  116.         $this->password $password;
  117.         return $this;
  118.     }
  119.     /**
  120.      * @see UserInterface
  121.      */
  122.     public function eraseCredentials()
  123.     {
  124.         // If you store any temporary, sensitive data on the user, clear it here
  125.         // $this->plainPassword = null;
  126.     }
  127.     public function isVerified(): bool
  128.     {
  129.         return $this->isVerified;
  130.     }
  131.     public function setIsVerified(bool $isVerified): self
  132.     {
  133.         $this->isVerified $isVerified;
  134.         return $this;
  135.     }
  136.     public function __toString(): string
  137.     {
  138.         return $this->email;
  139.     }
  140.     public function getFirstname(): ?string
  141.     {
  142.         return $this->firstname;
  143.     }
  144.     public function setFirstname(?string $firstname): self
  145.     {
  146.         $this->firstname $firstname;
  147.         return $this;
  148.     }
  149.     public function getLastname(): ?string
  150.     {
  151.         return $this->lastname;
  152.     }
  153.     public function setLastname(?string $lastname): self
  154.     {
  155.         $this->lastname $lastname;
  156.         return $this;
  157.     }
  158.     public function getIdentite(): ?string 
  159.         {
  160.             return $this->firstname.' '.$this->lastname.' ('.$this->email.')';
  161.         }
  162.     public function getPhoneNumber(): ?string
  163.     {
  164.         return $this->phone_number;
  165.     }
  166.     public function setPhoneNumber(?string $phone_number): self
  167.     {
  168.         $this->phone_number $phone_number;
  169.         return $this;
  170.     }
  171.     /**
  172.      * @return Collection<int, Conferences>
  173.      */
  174.     public function getPresidents(): Collection
  175.     {
  176.         return $this->presidents;
  177.     }
  178.     public function addPresident(Conferences $president): self
  179.     {
  180.         if (!$this->presidents->contains($president)) {
  181.             $this->presidents->add($president);
  182.             $president->addPresident($this);
  183.         }
  184.         return $this;
  185.     }
  186.     public function removePresident(Conferences $president): self
  187.     {
  188.         if ($this->presidents->removeElement($president)) {
  189.             $president->removePresident($this);
  190.         }
  191.         return $this;
  192.     }
  193.     /**
  194.      * @return Collection<int, Conferences>
  195.      */
  196.     public function getConferenciers(): Collection
  197.     {
  198.         return $this->conferenciers;
  199.     }
  200.     public function addConferencier(Conferences $conferencier): self
  201.     {
  202.         if (!$this->conferenciers->contains($conferencier)) {
  203.             $this->conferenciers->add($conferencier);
  204.             $conferencier->addConferencier($this);
  205.         }
  206.         return $this;
  207.     }
  208.     public function removeConferencier(Conferences $conferencier): self
  209.     {
  210.         if ($this->conferenciers->removeElement($conferencier)) {
  211.             $conferencier->removeConferencier($this);
  212.         }
  213.         return $this;
  214.     }
  215.     /**
  216.      * @return Collection<int, Seminaires>
  217.      */
  218.     public function getSeminaires(): Collection
  219.     {
  220.         return $this->seminaires;
  221.     }
  222.     public function addSeminaire(Seminaires $seminaire): self
  223.     {
  224.         if (!$this->seminaires->contains($seminaire)) {
  225.             $this->seminaires->add($seminaire);
  226.             $seminaire->addAdmin($this);
  227.         }
  228.         return $this;
  229.     }
  230.     public function removeSeminaire(Seminaires $seminaire): self
  231.     {
  232.         if ($this->seminaires->removeElement($seminaire)) {
  233.             $seminaire->removeAdmin($this);
  234.         }
  235.         return $this;
  236.     }
  237.     /**
  238.      * @return Collection<int, Seminaires>
  239.      */
  240.     public function getMySeminaires(): Collection
  241.     {
  242.         return $this->MySeminaires;
  243.     }
  244.     public function addMySeminaire(Seminaires $mySeminaire): self
  245.     {
  246.         if (!$this->MySeminaires->contains($mySeminaire)) {
  247.             $this->MySeminaires->add($mySeminaire);
  248.             $mySeminaire->addCommunicant($this);
  249.         }
  250.         return $this;
  251.     }
  252.     public function removeMySeminaire(Seminaires $mySeminaire): self
  253.     {
  254.         if ($this->MySeminaires->removeElement($mySeminaire)) {
  255.             $mySeminaire->removeCommunicant($this);
  256.         }
  257.         return $this;
  258.     }
  259.     public function getPlainpassword(): ?string
  260.     {
  261.         return $this->plainpassword;
  262.     }
  263.     public function setPlainpassword(?string $plainpassword): self
  264.     {
  265.         $this->plainpassword $plainpassword;
  266.         return $this;
  267.     }
  268.     /**
  269.      * @return Collection<int, Communications>
  270.      */
  271.     public function getCommunications(): Collection
  272.     {
  273.         return $this->communications;
  274.     }
  275.     public function addCommunication(Communications $communication): self
  276.     {
  277.         if (!$this->communications->contains($communication)) {
  278.             $this->communications->add($communication);
  279.             $communication->addConferencier($this);
  280.         }
  281.         return $this;
  282.     }
  283.     public function removeCommunication(Communications $communication): self
  284.     {
  285.         if ($this->communications->removeElement($communication)) {
  286.             $communication->removeConferencier($this);
  287.         }
  288.         return $this;
  289.     }
  290.     public function getPP(){
  291.         //on check si l'id user à une pp 
  292.         $filename dirname(__FILE__).'/../../public/uploads/avatar/av-'.$this->id.'.png';
  293.         if(file_exists($filename)) {
  294.                 //si oui on envoie le link
  295.                 $link '/uploads/avatar/av-'.$this->id.'.png';
  296.                 return $link;
  297.             } else {
  298.                 //si non on genere une image rond gris initiales
  299.                 /*$avatar = new \LasseRafn\InitialAvatarGenerator\InitialAvatar();
  300.                 //$image = $avatar->name($this->fistname.' '.$this->lastname)->generate();
  301.                 $image = $avatar->name($this->firstname.' '.$this->lastname)
  302.                         ->length(2)
  303.                         ->fontSize(0.5)
  304.                         ->size(96) // 48 * 2
  305.                         ->background('#8BC34A')
  306.                         ->color('#fff')
  307.                         ->fontName('Arial, Helvetica, sans-serif')
  308.                         ->generate()
  309.                         ->stream('png', 100);
  310.                         return $image;*/
  311.                 $link 'https://ui-avatars.com/api/?background=d3d3d3&color=fff&name='.$this->firstname.'+'.$this->lastname;
  312.                 return $link;
  313.             }
  314.     }
  315.     public function getAvatar(): ?string
  316.     {
  317.         return $this->avatar;
  318.     }
  319.     public function setAvatar(?string $avatar): self
  320.     {
  321.         $this->avatar $avatar;
  322.         return $this;
  323.     }
  324. }