src/Entity/AppUser.php line 21

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use Doctrine\Common\Collections\ArrayCollection;
  4. use Doctrine\Common\Collections\Collection;
  5. use Doctrine\ORM\Mapping as ORM;
  6. use FOS\UserBundle\Model\User as BaseUser;
  7. use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
  8. use Symfony\Component\Security\Core\User\UserInterface;
  9. use Symfony\Component\HttpFoundation\File\File;
  10. use Symfony\Component\HttpFoundation\File\UploadedFile;
  11. use Gedmo\Mapping\Annotation as Gedmo;
  12. /**
  13.  * Users
  14.  * @ORM\Entity
  15.  * @ORM\HasLifecycleCallbacks()
  16.  * @ORM\Table(name="app_user")
  17.  */ 
  18. class AppUser implements UserInterfacePasswordAuthenticatedUserInterface
  19. {
  20.     /**
  21.     * @Gedmo\Slug(fields={"username"})
  22.     * @ORM\Column(length=128, unique=true)
  23.     */
  24.     private $slugUsername;
  25.     /**
  26.      * @ORM\Column(type="string", length=255, unique=true)
  27.      */
  28.     private $username;
  29.     /**
  30.      * @var string
  31.      */
  32.     private $plainPassword;
  33.     /**
  34.      * @var string The hashed password
  35.      * @ORM\Column(type="string")
  36.      */
  37.     private $password;
  38.     /**
  39.      * @ORM\Column(type="json")
  40.      */
  41.     private $roles = [];
  42.     /**
  43.      * @ORM\ManyToOne(targetEntity="\App\Entity\Boutique")
  44.      */
  45.     private $boutique;
  46.     const ROLES = [
  47.         'ROLE_SUPER_ADMIN' => 'Super Administrateur',
  48.         'ROLE_ENTREPRISE' => 'Entreprise',
  49.         'ROLE_PARTICULIER' => 'Particulier',
  50.     ];
  51.     /**
  52.      * @ORM\OneToOne(targetEntity="\App\Entity\Photo", cascade={"persist", "remove"})
  53.      */
  54.     private $avatar;
  55.     /**
  56.      * @var int
  57.      *
  58.      * @ORM\Column(name="id", type="integer", nullable=false)
  59.      * @ORM\Id
  60.      * @ORM\GeneratedValue(strategy="IDENTITY")
  61.      */
  62.     protected $id;
  63.     /*
  64.      * @var string
  65.      *
  66.      * @ORM\Column(name="nomprenoms", type="string", length=255, nullable=true)
  67.      */
  68.     private $nomprenoms;
  69.     /**
  70.      * @ORM\Column(type="string", length=180, unique=true)
  71.      */
  72.     private $email;
  73.     /**
  74.      * @ORM\Column(type="string", length=255, nullable=true)
  75.      */
  76.     private $emailToken;
  77.     /**
  78.      * @var string
  79.      *
  80.      * @ORM\Column(name="nom", type="string", length=255, nullable=true)
  81.      */
  82.     private $nom;
  83.     /**
  84.      * @var string
  85.      *
  86.      * @ORM\Column(name="prenom", type="string", length=255, nullable=true)
  87.      */
  88.     private $prenom;
  89.     /**
  90.      * @var string
  91.      *
  92.      * @ORM\Column(name="nom_complet", type="string", length=255, nullable=true)
  93.      */
  94.     private $nomComplet;
  95.     /** 
  96.      * @var string
  97.      *
  98.      * @ORM\Column(name="dateNaissance", type="date", nullable=true)
  99.      */
  100.     private $dateNaissance;
  101.     /**
  102.      * @var string
  103.      *
  104.      * @ORM\Column(name="contacts", type="string", length=255, nullable=true)
  105.      */
  106.     private $contacts;
  107.     /**
  108.      * @var string|null
  109.      *
  110.      * @ORM\Column(name="adresse", type="string", length=255, nullable=true)
  111.      */
  112.     private $adresse;
  113.     /**
  114.      * @var string|null
  115.      *
  116.      * @ORM\Column(name="matricule", type="string", length=255, nullable=true)
  117.      */
  118.     private $matricule;
  119.     /**
  120.      * @var string|null
  121.      *
  122.      * @ORM\Column(name="salaire", type="float", nullable=true)
  123.      */
  124.     private $salaire;
  125.      /**
  126.      * @var string|null
  127.      *
  128.      * @ORM\Column(name="numero_cnps", type="string", length=255, nullable=true)
  129.      */
  130.     private $numeroCNPS;
  131.     /**
  132.      * @var string|null
  133.      *
  134.      * @ORM\Column(name="vacataire", type="boolean", nullable=true)
  135.      */
  136.     private $vacataire;
  137.     /**
  138.      * @var \DateTime
  139.      *
  140.      * @ORM\Column(name="created_at", type="datetime", nullable=false)
  141.      */
  142.     private $createdAt;
  143.     /**
  144.      * @var \DateTime|null
  145.      *
  146.      * @ORM\Column(name="updated_at", type="datetime", nullable=true)
  147.      */
  148.     private $updatedAt;
  149.     /**
  150.      * @ORM\Column(type="string", length=255, nullable=true)
  151.      */
  152.     private $filename;
  153.     //Sync from main base piliersoft
  154.     public function __construct()
  155.     {
  156.         $this->roles = ['ROLE_USER'];
  157.         $this->createdAt = new \DateTime('now');
  158.         $p = new Photo;
  159.         
  160.         $fullUrl '';
  161.         $domaine $_SERVER['HTTP_HOST'];
  162.         $protocol '';
  163.         if(!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off'){
  164.             $protocol 'https://';
  165.         } else{
  166.             $protocol 'http://';
  167.         }
  168.         
  169.         $fullUrl $protocol.$domaine.'/image/male-user.png';
  170.         $p->setFullUrl($fullUrl);
  171.         $p->setUrl('image/male-user.png');
  172.         
  173.         $p->setAlt('Photo de profile');
  174.         $this->avatar $p;
  175.     }
  176.     public function getId(): ?int
  177.     {
  178.         return $this->id;
  179.     }
  180.     public function getNomprenoms(): ?string
  181.     {
  182.         return $this->nomprenoms;
  183.     }
  184.     public function setNomprenoms(string $nomprenoms): self
  185.     {
  186.         $this->nomprenoms $nomprenoms;
  187.         return $this;
  188.     }
  189.     public function getContacts(): ?string
  190.     {
  191.         return $this->contacts;
  192.     }
  193.     public function setContacts(string $contacts): self
  194.     {
  195.         $this->contacts $contacts;
  196.         return $this;
  197.     }
  198.     public function getAdresse(): ?string
  199.     {
  200.         return $this->adresse;
  201.     }
  202.     public function setAdresse(?string $adresse): self
  203.     {
  204.         $this->adresse $adresse;
  205.         return $this;
  206.     }
  207.     public function getCreatedAt(): ?\DateTimeInterface
  208.     {
  209.         return $this->createdAt;
  210.     }
  211.     public function setCreatedAt(\DateTimeInterface $createdAt): self
  212.     {
  213.         $this->createdAt $createdAt;
  214.         return $this;
  215.     }
  216.     public function getUpdatedAt(): ?\DateTimeInterface
  217.     {
  218.         return $this->updatedAt;
  219.     }
  220.     public function setUpdatedAt(?\DateTimeInterface $updatedAt): self
  221.     {
  222.         $this->updatedAt $updatedAt;
  223.         return $this;
  224.     }
  225.     public function getRolesUsers(): string {
  226.         return self::ROLES[$this->role];
  227.     }
  228.     /**
  229.      * @return mixed
  230.      */
  231.     public function getEnabled()
  232.     {
  233.         return $this->enabled;
  234.     }
  235.     /**
  236.      * @param mixed $enabled
  237.      * @return Users
  238.      */
  239.     public function setEnabled($enabled)
  240.     {
  241.         $this->enabled $enabled;
  242.         return $this;
  243.     }
  244.     public function getFilename(): ?string
  245.     {
  246.         return $this->filename;
  247.     }
  248.     public function setFilename(?string $filename): self
  249.     {
  250.         $this->filename $filename;
  251.         return $this;
  252.     }
  253.     public function getBoutique(): ?Boutique
  254.     {
  255.         return $this->boutique;
  256.     }
  257.     public function setBoutique(?Boutique $boutique): self
  258.     {
  259.         $this->boutique $boutique;
  260.         return $this;
  261.     }
  262.     public function getNom(): ?string
  263.     {
  264.         return $this->nom;
  265.     }
  266.     public function setNom(?string $nom): self
  267.     {
  268.         $this->nom $nom;
  269.         return $this;
  270.     }
  271.     public function getPrenom(): ?string
  272.     {
  273.         return $this->prenom;
  274.     }
  275.     public function setPrenom(?string $prenom): self
  276.     {
  277.         $this->prenom $prenom;
  278.         return $this;
  279.     }
  280.     public function getNomComplet(): ?string
  281.     {
  282.         return $this->nomComplet;
  283.     }
  284.     public function setNomComplet(?string $nomComplet): self
  285.     {
  286.         $this->nomComplet $nomComplet;
  287.         return $this;
  288.     }
  289.     public function getDateNaissance(): ?\DateTimeInterface
  290.     {
  291.         return $this->dateNaissance;
  292.     }
  293.     public function setDateNaissance(?\DateTimeInterface $dateNaissance): self
  294.     {
  295.         $this->dateNaissance $dateNaissance;
  296.         return $this;
  297.     }
  298.     public function getSalaire(): ?float
  299.     {
  300.         return $this->salaire;
  301.     }
  302.     public function setSalaire(?float $salaire): self
  303.     {
  304.         $this->salaire $salaire;
  305.         return $this;
  306.     }
  307.     public function getVacataire(): ?bool
  308.     {
  309.         return $this->vacataire;
  310.     }
  311.     public function setVacataire(?bool $vacataire): self
  312.     {
  313.         $this->vacataire $vacataire;
  314.         return $this;
  315.     }
  316.     public function getMatricule(): ?string
  317.     {
  318.         return $this->matricule;
  319.     }
  320.     public function setMatricule(?string $matricule): self
  321.     {
  322.         $this->matricule $matricule;
  323.         return $this;
  324.     }
  325.     /**
  326.      * A visual identifier that represents this user.
  327.      *
  328.      * @see UserInterface
  329.      */
  330.     public function getUserIdentifier(): string
  331.     {
  332.         return (string) $this->email;
  333.     }
  334.     /**
  335.      * @deprecated since Symfony 5.3, use getUserIdentifier instead
  336.      */
  337.     public function getUsername(): string
  338.     {
  339.         return (string) $this->username;
  340.     }
  341.     /**
  342.      * @see UserInterface
  343.      */
  344.     public function getRoles(): array
  345.     {
  346.         $roles $this->roles;
  347.         // guarantee every user at least has ROLE_USER
  348.         $roles[] = 'ROLE_USER';
  349.         return array_unique($roles);
  350.     }
  351.     public function setRoles(array $roles): self
  352.     {
  353.         $this->roles $roles;
  354.         return $this;
  355.     }
  356.     /**
  357.      * @see PasswordAuthenticatedUserInterface
  358.      */
  359.     public function getPassword(): string
  360.     {
  361.         return $this->password;
  362.     }
  363.     public function setPassword(string $password): self
  364.     {
  365.         $this->password $password;
  366.         return $this;
  367.     }
  368.     /**
  369.      * Returning a salt is only needed, if you are not using a modern
  370.      * hashing algorithm (e.g. bcrypt or sodium) in your security.yaml.
  371.      *
  372.      * @see UserInterface
  373.      */
  374.     public function getSalt(): ?string
  375.     {
  376.         return null;
  377.     }
  378.     /**
  379.      * @see UserInterface
  380.      */
  381.     public function eraseCredentials()
  382.     {
  383.         // If you store any temporary, sensitive data on the user, clear it here
  384.         // $this->plainPassword = null;
  385.     }
  386.     public function getEmail(): ?string
  387.     {
  388.         return $this->email;
  389.     }
  390.     public function setEmail(string $email): self
  391.     {
  392.         $this->email $email;
  393.         return $this;
  394.     }
  395.     public function isVacataire(): ?bool
  396.     {
  397.         return $this->vacataire;
  398.     }
  399.     public function getSlugUsername(): ?string
  400.     {
  401.         return $this->slugUsername;
  402.     }
  403.     public function setSlugUsername(string $slugUsername): self
  404.     {
  405.         $this->slugUsername $slugUsername;
  406.         return $this;
  407.     }
  408.     public function setUsername(string $username): self
  409.     {
  410.         $this->username $username;
  411.         return $this;
  412.     }
  413.     /**
  414.      * 
  415.      */
  416.     public function getPlainPassword(): string
  417.     {
  418.         return $this->plainPassword;
  419.     }
  420.     public function setPlainPassword(string $plainPassword): self
  421.     {
  422.         $this->plainPassword $plainPassword;
  423.         return $this;
  424.     }
  425.       public function getAvatar(): ?Photo
  426.     {
  427.         return $this->avatar;
  428.     }
  429.     public function setAvatar(?Photo $avatar): self
  430.     {
  431.         $this->avatar $avatar;
  432.         return $this;
  433.     }
  434.     public function getNumeroCNPS(): ?string
  435.     {
  436.         return $this->numeroCNPS;
  437.     }
  438.     public function setNumeroCNPS(?string $numeroCNPS): self
  439.     {
  440.         $this->numeroCNPS $numeroCNPS;
  441.         return $this;
  442.     }
  443.     /**
  444.      *@ORM\PreUpdate
  445.      */
  446.     public function persistEntity()
  447.     {
  448.         $this->nomComplet $this->getNom().' '.$this->getPrenom();
  449.     }
  450.     
  451.     /**
  452.      *@ORM\PrePersist
  453.     */
  454.     public function updateEntity()
  455.     {
  456.         $this->nomComplet $this->getNom().' '.$this->getPrenom();
  457.     }
  458.     public function getEmailToken(): ?string
  459.     {
  460.         return $this->emailToken;
  461.     }
  462.     public function setEmailToken(?string $emailToken): self
  463.     {
  464.         $this->emailToken $emailToken;
  465.         return $this;
  466.     }
  467. }