src/Entity/User.php line 14

  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\UserRepository;
  4. use Doctrine\Common\Collections\Collection;
  5. use Doctrine\ORM\Mapping as ORM;
  6. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  7. use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
  8. use Symfony\Component\Security\Core\User\UserInterface;
  9. #[ORM\Entity(repositoryClassUserRepository::class)]
  10. #[UniqueEntity(fields: ['email'], message'There is already an account with this email')]
  11. class User implements UserInterfacePasswordAuthenticatedUserInterface
  12. {
  13.     public static function generatePassword($length 8)
  14.     {
  15.         $chars 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%&*()-_=+';
  16.         $password '';
  17.         for ($i 0$i $length$i++) {
  18.             $password .= $chars[rand(0strlen($chars) - 1)];
  19.         }
  20.         return $password;
  21.     }
  22.     #[ORM\Id]
  23.     #[ORM\GeneratedValue]
  24.     #[ORM\Column]
  25.     private ?int $id null;
  26.     #[ORM\Column(length180uniquetrue)]
  27.     private ?string $email null;
  28.     #[ORM\Column]
  29.     private array $roles = [];
  30.     #[ORM\OneToMany(mappedBy'user'targetEntityCart::class)]
  31.     private ?Collection $cart;
  32.     #[ORM\OneToMany(mappedBy'user'targetEntitySpecialCustomer::class)]
  33.     private ?Collection $specialCustomerPourcent;
  34.     #[ORM\Column(name'specialCustomer'type'boolean'nullabletrue)]
  35.     private ?bool $specialCustomer;
  36.     #[ORM\OneToMany(mappedBy'user'targetEntityCustomerControl::class)]
  37.     private ?Collection $customer;
  38.     #[ORM\OneToMany(mappedBy'customer'targetEntityCustomerControl::class)]
  39.     private ?Collection $customerControl;
  40.     #[ORM\OneToMany(mappedBy'user'targetEntityBillings::class)]
  41.     private ?Collection $billings;
  42.     #[ORM\OneToMany(mappedBy'user'targetEntityInvoices::class)]
  43.     private ?Collection $invoice;
  44.     #[ORM\OneToMany(mappedBy'user'targetEntityCartFinished::class)]
  45.     private ?Collection $cartFinished;
  46.     #[ORM\OneToMany(mappedBy'user'targetEntityAdditionalCompanyInformation::class)]
  47.     private ?Collection $AdditionalCompanyInformation;
  48.     #[ORM\OneToMany(mappedBy'user'targetEntityJoker::class)]
  49.     private ?Collection $joker;
  50.     #[ORM\OneToMany(mappedBy'user'targetEntityDeliveryAddress::class)]
  51.     private ?Collection $deliveryAddress;
  52.     #[ORM\OneToMany(mappedBy'client'targetEntityTva::class)]
  53.     private ?Collection $tva;
  54.     #[ORM\Column(name'generatePasswordRecovery'type'string'nullabletrue)]
  55.     private ?string $generatePasswordRecovery;
  56.     //    #[ORM\Column(name: 'typeOfProfessional', type: 'string', nullable: true)]
  57.     //    private ?string $typeOfProfessional;
  58.     #[ORM\Column(name'additionalPercentage'type'float'nullabletrue)]
  59.     private ?float $additionalPercentage 0.0;
  60.     #[ORM\Column(name'name'type'string'nullabletrue)]
  61.     private ?string $name;
  62.     #[ORM\Column(name'firstName'type'string'nullabletrue)]
  63.     private ?string $firstName;
  64.     #[ORM\Column(name'address'type'string'nullabletrue)]
  65.     private ?string $address;
  66.     #[ORM\Column(name'postal'type'string'nullabletrue)]
  67.     private ?string $postal;
  68.     #[ORM\Column(name'locality'type'string'nullabletrue)]
  69.     private ?string $locality;
  70.     #[ORM\Column(name'country'type'string'nullabletrue)]
  71.     private ?string $country;
  72.     #[ORM\Column(name'phoneNumber'type'string'nullabletrue)]
  73.     private ?string $phoneNumber;
  74.     #[ORM\Column(name'directPhone'type'string'nullabletrue)]
  75.     private ?string $directPhone;
  76.     #[ORM\Column(name'otherMail'type'string'nullabletrue)]
  77.     private ?string $otherMail;
  78.     #[ORM\Column(name'companyName'type'string'nullabletrue)]
  79.     private ?string $companyName;
  80.     #[ORM\Column(name'active'type'boolean'nullabletrue)]
  81.     private ?bool $active;
  82.     #[ORM\Column(name'gender'type'string'nullabletrue)]
  83.     private ?string $gender;
  84.     #[ORM\Column(name'userSupplementsPurchaseDecisionMaker'type'boolean'nullabletrue)]
  85.     private ?bool $userSupplementsPurchaseDecisionMaker;
  86.     /**
  87.      * @return string|null
  88.      */
  89.     public function getGeneratePasswordRecovery(): ?string
  90.     {
  91.         return $this->generatePasswordRecovery;
  92.     }
  93.     /**
  94.      * @param string|null $generatePasswordRecovery
  95.      */
  96.     public function setGeneratePasswordRecovery(?string $generatePasswordRecovery): void
  97.     {
  98.         $this->generatePasswordRecovery $generatePasswordRecovery;
  99.     }
  100.     /**
  101.      * @return Collection|null
  102.      */
  103.     public function getSpecialCustomerPourcent(): ?Collection
  104.     {
  105.         return $this->specialCustomerPourcent;
  106.     }
  107.     /**
  108.      * @param Collection|null $specialCustomerPourcent
  109.      */
  110.     public function setSpecialCustomerPourcent(?Collection $specialCustomerPourcent): void
  111.     {
  112.         $this->specialCustomerPourcent $specialCustomerPourcent;
  113.     }
  114.     /**
  115.      * @return bool|null
  116.      */
  117.     public function getSpecialCustomer(): ?bool
  118.     {
  119.         return $this->specialCustomer;
  120.     }
  121.     /**
  122.      * @param bool|null $specialCustomer
  123.      */
  124.     public function setSpecialCustomer(?bool $specialCustomer): void
  125.     {
  126.         $this->specialCustomer $specialCustomer;
  127.     }
  128.     /**
  129.      * @return Collection|null
  130.      */
  131.     public function getInvoice(): ?Collection
  132.     {
  133.         return $this->invoice;
  134.     }
  135.     /**
  136.      * @param Collection|null $invoice
  137.      */
  138.     public function setInvoice(?Collection $invoice): void
  139.     {
  140.         $this->invoice $invoice;
  141.     }
  142.     /**
  143.      * @return Collection|null
  144.      */
  145.     public function getCustomer(): ?Collection
  146.     {
  147.         return $this->customer;
  148.     }
  149.     /**
  150.      * @param Collection|null $customer
  151.      */
  152.     public function setCustomer(?Collection $customer): void
  153.     {
  154.         $this->customer $customer;
  155.     }
  156.     /**
  157.      * @return Collection|null
  158.      */
  159.     public function getCustomerControl(): ?Collection
  160.     {
  161.         return $this->customerControl;
  162.     }
  163.     /**
  164.      * @param Collection|null $customerControl
  165.      */
  166.     public function setCustomerControl(?Collection $customerControl): void
  167.     {
  168.         $this->customerControl $customerControl;
  169.     }
  170.     /**
  171.      * @return bool|null
  172.      */
  173.     public function getUserSupplementsPurchaseDecisionMaker(): ?bool
  174.     {
  175.         return $this->userSupplementsPurchaseDecisionMaker;
  176.     }
  177.     /**
  178.      * @param bool|null $userSupplementsPurchaseDecisionMaker
  179.      */
  180.     public function setUserSupplementsPurchaseDecisionMaker(?bool $userSupplementsPurchaseDecisionMaker): void
  181.     {
  182.         $this->userSupplementsPurchaseDecisionMaker $userSupplementsPurchaseDecisionMaker;
  183.     }
  184.     /**
  185.      * @return string|null
  186.      */
  187.     public function getGender(): ?string
  188.     {
  189.         return $this->gender;
  190.     }
  191.     /**
  192.      * @param string|null $gender
  193.      */
  194.     public function setGender(?string $gender): void
  195.     {
  196.         $this->gender $gender;
  197.     }
  198.     /**
  199.      * @return Collection|null
  200.      */
  201.     public function getBillings(): ?Collection
  202.     {
  203.         return $this->billings;
  204.     }
  205.     /**
  206.      * @param Collection|null $billings
  207.      */
  208.     public function setBillings(?Collection $billings): void
  209.     {
  210.         $this->billings $billings;
  211.     }
  212.     /**
  213.      * @return string|null
  214.      */
  215.     public function getDirectPhone(): ?string
  216.     {
  217.         return $this->directPhone;
  218.     }
  219.     /**
  220.      * @param string|null $directPhone
  221.      */
  222.     public function setDirectPhone(?string $directPhone): void
  223.     {
  224.         $this->directPhone $directPhone;
  225.     }
  226.     /**
  227.      * @return string|null
  228.      */
  229.     public function getLocality(): ?string
  230.     {
  231.         return $this->locality;
  232.     }
  233.     /**
  234.      * @param string|null $locality
  235.      */
  236.     public function setLocality(?string $locality): void
  237.     {
  238.         $this->locality $locality;
  239.     }
  240.     /**
  241.      * @return Collection|null
  242.      */
  243.     public function getCartFinished(): ?Collection
  244.     {
  245.         return $this->cartFinished;
  246.     }
  247.     /**
  248.      * @param Collection|null $cartFinished
  249.      */
  250.     public function setCartFinished(?Collection $cartFinished): void
  251.     {
  252.         $this->cartFinished $cartFinished;
  253.     }
  254.     /**
  255.      * @return float|null
  256.      */
  257.     public function getAdditionalPercentage(): ?float
  258.     {
  259.         return $this->additionalPercentage;
  260.     }
  261.     /**
  262.      * @param float|null $additionalPercentage
  263.      */
  264.     public function setAdditionalPercentage(?float $additionalPercentage): void
  265.     {
  266.         $this->additionalPercentage $additionalPercentage;
  267.     }
  268.     /**
  269.      * @return Collection|null
  270.      */
  271.     public function getAdditionalCompanyInformation(): ?Collection
  272.     {
  273.         return $this->AdditionalCompanyInformation;
  274.     }
  275.     /**
  276.      * @param Collection|null $AdditionalCompanyInformation
  277.      */
  278.     public function setAdditionalCompanyInformation(?Collection $AdditionalCompanyInformation): void
  279.     {
  280.         $this->AdditionalCompanyInformation $AdditionalCompanyInformation;
  281.     }
  282.     /**
  283.      * @return Collection|null
  284.      */
  285.     public function getJoker(): ?Collection
  286.     {
  287.         return $this->joker;
  288.     }
  289.     /**
  290.      * @param Collection|null $joker
  291.      */
  292.     public function setJoker(?Collection $joker): void
  293.     {
  294.         $this->joker $joker;
  295.     }
  296.     /**
  297.      * @return bool|null
  298.      */
  299.     public function getActive(): ?bool
  300.     {
  301.         return $this->active;
  302.     }
  303.     /**
  304.      * @param bool|null $active
  305.      */
  306.     public function setActive(?bool $active false): void
  307.     {
  308.         $this->active $active;
  309.     }
  310.     /**
  311.      * @return Collection|null
  312.      */
  313.     public function getDeliveryAddress(): ?Collection
  314.     {
  315.         return $this->deliveryAddress;
  316.     }
  317.     /**
  318.      * @param Collection|null $deliveryAddress
  319.      */
  320.     public function setDeliveryAddress(?Collection $deliveryAddress): void
  321.     {
  322.         $this->deliveryAddress $deliveryAddress;
  323.     }
  324.     /**
  325.      * @return Collection|null
  326.      */
  327.     public function getTva(): ?Collection
  328.     {
  329.         return $this->tva;
  330.     }
  331.     /**
  332.      * @param Collection|null $tva
  333.      */
  334.     public function setTva(?Collection $tva): void
  335.     {
  336.         $this->tva $tva;
  337.     }
  338.     /**
  339.      * @return string|null
  340.      */
  341.     public function getName(): ?string
  342.     {
  343.         return $this->name;
  344.     }
  345.     /**
  346.      * @param string|null $name
  347.      */
  348.     public function setName(?string $name): void
  349.     {
  350.         $this->name $name;
  351.     }
  352.     /**
  353.      * @return string|null
  354.      */
  355.     public function getFirstName(): ?string
  356.     {
  357.         return $this->firstName;
  358.     }
  359.     /**
  360.      * @param string|null $firstName
  361.      */
  362.     public function setFirstName(?string $firstName): void
  363.     {
  364.         $this->firstName $firstName;
  365.     }
  366.     /**
  367.      * @return string|null
  368.      */
  369.     public function getAddress(): ?string
  370.     {
  371.         return $this->address;
  372.     }
  373.     /**
  374.      * @param string|null $address
  375.      */
  376.     public function setAddress(?string $address): void
  377.     {
  378.         $this->address $address;
  379.     }
  380.     /**
  381.      * @return string|null
  382.      */
  383.     public function getCountry(): ?string
  384.     {
  385.         return $this->country;
  386.     }
  387.     /**
  388.      * @param string|null $country
  389.      */
  390.     public function setCountry(?string $country): void
  391.     {
  392.         $this->country $country;
  393.     }
  394.     /**
  395.      * @return string|null
  396.      */
  397.     public function getPostal(): ?string
  398.     {
  399.         return $this->postal;
  400.     }
  401.     /**
  402.      * @param string|null $postal
  403.      */
  404.     public function setPostal(?string $postal): void
  405.     {
  406.         $this->postal $postal;
  407.     }
  408.     /**
  409.      * @return string|null
  410.      */
  411.     public function getPhoneNumber(): ?string
  412.     {
  413.         return $this->phoneNumber;
  414.     }
  415.     /**
  416.      * @param string|null $phoneNumber
  417.      */
  418.     public function setPhoneNumber(?string $phoneNumber): void
  419.     {
  420.         $this->phoneNumber $phoneNumber;
  421.     }
  422.     /**
  423.      * @return string|null
  424.      */
  425.     public function getOtherMail(): ?string
  426.     {
  427.         return $this->otherMail;
  428.     }
  429.     /**
  430.      * @param string|null $otherMail
  431.      */
  432.     public function setOtherMail(?string $otherMail): void
  433.     {
  434.         $this->otherMail $otherMail;
  435.     }
  436.     /**
  437.      * @return string|null
  438.      */
  439.     public function getCompanyName(): ?string
  440.     {
  441.         return $this->companyName;
  442.     }
  443.     /**
  444.      * @param string|null $companyName
  445.      */
  446.     public function setCompanyName(?string $companyName): void
  447.     {
  448.         $this->companyName $companyName;
  449.     }
  450.     //    /**
  451.     //     * @return string|null
  452.     //     */
  453.     //    public function getTypeOfProfessional(): ?string
  454.     //    {
  455.     //        return $this->typeOfProfessional;
  456.     //    }
  457.     //
  458.     //    /**
  459.     //     * @param string|null $typeOfProfessional
  460.     //     */
  461.     //    public function setTypeOfProfessional(?string $typeOfProfessional): void
  462.     //    {
  463.     //        $this->typeOfProfessional = $typeOfProfessional;
  464.     //    }
  465.     /**
  466.      * @return Collection|null
  467.      */
  468.     public function getCart(): ?Collection
  469.     {
  470.         return $this->cart;
  471.     }
  472.     /**
  473.      * @param Collection|null $cart
  474.      */
  475.     public function setCart(?Collection $cart): void
  476.     {
  477.         $this->cart $cart;
  478.     }
  479.     /**
  480.      * @var string The hashed password
  481.      */
  482.     #[ORM\Column]
  483.     private ?string $password null;
  484.     public function getId(): ?int
  485.     {
  486.         return $this->id;
  487.     }
  488.     public function getEmail(): ?string
  489.     {
  490.         return $this->email;
  491.     }
  492.     public function setEmail(string $email): self
  493.     {
  494.         $this->email $email;
  495.         return $this;
  496.     }
  497.     /**
  498.      * A visual identifier that represents this user.
  499.      *
  500.      * @see UserInterface
  501.      */
  502.     public function getUserIdentifier(): string
  503.     {
  504.         return (string) $this->email;
  505.     }
  506.     /**
  507.      * @see UserInterface
  508.      */
  509.     public function getRoles(): array
  510.     {
  511.         $roles $this->roles;
  512.         // guarantee every user at least has ROLE_USER
  513.         $roles[] = 'ROLE_USER';
  514.         return array_unique($roles);
  515.     }
  516.     public function setRoles(array $roles): self
  517.     {
  518.         $this->roles $roles;
  519.         return $this;
  520.     }
  521.     /**
  522.      * @see PasswordAuthenticatedUserInterface
  523.      */
  524.     public function getPassword(): string
  525.     {
  526.         return $this->password;
  527.     }
  528.     public function setPassword(string $password): self
  529.     {
  530.         $this->password $password;
  531.         return $this;
  532.     }
  533.     /**
  534.      * @see UserInterface
  535.      */
  536.     public function eraseCredentials()
  537.     {
  538.         // If you store any temporary, sensitive data on the user, clear it here
  539.         // $this->plainPassword = null;
  540.     }
  541.     public function __toString(): string
  542.     {
  543.         return $this->email ?? '';
  544.     }
  545.     public function getTvaNumbersAsString(): string
  546.     {
  547.         $tvas = [];
  548.         foreach ($this->AdditionalCompanyInformation as $info) {
  549.             // Assurez-vous que l'entité AdditionalCompanyInformation a une méthode getTva()
  550.             $tvas[] = $info->getTva();
  551.         }
  552.         return implode(", "$tvas);
  553.     }
  554.     public function getCompanyNameFromAdditionalInfo(): ?string
  555.     {
  556.         if ($this->AdditionalCompanyInformation && $this->AdditionalCompanyInformation->count() > 0) {
  557.             $firstInfo $this->AdditionalCompanyInformation->first();
  558.             return $firstInfo $firstInfo->getCompanyName() : null;
  559.         }
  560.         return null;
  561.     }
  562. }