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