src/Entity/User/User.php line 65

Open in your IDE?
  1. <?php
  2. namespace App\Entity\User;
  3. use ApiPlatform\Core\Annotation\ApiProperty;
  4. use ApiPlatform\Core\Annotation\ApiResource;
  5. use App\Entity\Cart\GiftCart;
  6. use App\Entity\Cart\OperationCart;
  7. use App\Entity\Catalog\Order;
  8. use App\Entity\Company\Company;
  9. use App\Entity\Newsletter;
  10. use App\Entity\Operation\Operation;
  11. use App\Entity\Participation\Participation;
  12. use App\Entity\Purse\Purse;
  13. use App\Entity\Security\Profile;
  14. use App\Entity\Sponsorship\SponsorshipRequest;
  15. use App\Entity\Tas\TasDraw;
  16. use App\Entity\Token;
  17. use App\Entity\User\Carrier;
  18. use App\Entity\User\Address\Delivery;
  19. use App\Entity\User\Address\Home;
  20. use App\Entity\User\Payment\Iban;
  21. use App\Repository\UserRepository;
  22. use Doctrine\Common\Collections\ArrayCollection;
  23. use Doctrine\Common\Collections\Collection;
  24. use Doctrine\ORM\Mapping as ORM;
  25. use Doctrine\ORM\Mapping\OrderBy;
  26. use App\Traits\TimestampableTrait;
  27. use JMS\Serializer\Annotation as Serializer;
  28. use JMS\Serializer\Annotation\ExclusionPolicy;
  29. use Ramsey\Uuid\Doctrine\UuidGenerator;
  30. use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
  31. use Symfony\Component\Security\Core\User\UserInterface;
  32. use Symfony\Component\Serializer\Annotation\Groups;
  33. use Symfony\Component\Serializer\Annotation\SerializedName;
  34. use Symfony\Component\Validator\Constraints as Assert;
  35. /**
  36.  * @ORM\Entity(repositoryClass=UserRepository::class)
  37.  * @ExclusionPolicy("all")
  38.  * @ORM\InheritanceType("SINGLE_TABLE")
  39.  * @ORM\DiscriminatorColumn(name="discr", type="string")
  40.  * @ApiResource(
  41.  *     attributes={
  42.  *          "normalization_context"={"groups"={
  43.  *              "User:output",
  44.  *              "User:io",
  45.  *          }},
  46.  *          "denormalization_context"={"groups"={
  47.  *              "User:input",
  48.  *              "User:io",
  49.  *              "reset_password",
  50.  *              "initialize_password",
  51.  *          }}
  52.  *      },
  53.  *     itemOperations={
  54.  *          "put"={
  55.  *               "access_control"="is_granted('ROLE_USER')",
  56.  *               "validation_groups"={"Default", "Edit"}
  57.  *           },
  58.  *     }
  59.  * )
  60.  */
  61. //@todo add validators
  62. class User implements UserInterfacePasswordAuthenticatedUserInterface
  63. {
  64.     public const ROLE_USER 'ROLE_USER';
  65.     public const ROLE_ADMIN_SOGEC 'ROLE_ADMIN_SOGEC';
  66.     public const IMPORT_GENDER 'civilité';
  67.     public const IMPORT_LASTNAME 'nom';
  68.     public const IMPORT_FIRSTNAME 'prenom';
  69.     public const IMPORT_EMAIL 'email';
  70.     public const MAX_CARRIERS_AUTHORIZED 3;
  71.     /**
  72.      * @Groups({
  73.      *     "User:io",
  74.      * })
  75.      */
  76.     use TimestampableTrait;
  77.     /**
  78.      * @ORM\Id
  79.      * @ORM\Column(type="uuid", unique=true)
  80.      * @ORM\GeneratedValue(strategy="CUSTOM")
  81.      * @ORM\CustomIdGenerator(class=UuidGenerator::class)
  82.      * @SerializedName("id")
  83.      * @ApiProperty(identifier=true)
  84.      * @Assert\Uuid()
  85.      * @Groups({
  86.      *     "User:output",
  87.      *     "Token:output",
  88.      *     "ParticipationStep:io",
  89.      *     "get_user_operation_carts",
  90.      *     "post_participation_step_ask_refund",
  91.      *     "get_godfather_by_godchild_email",
  92.      *     "SponsorshipRequest:output",
  93.      * })
  94.      */
  95.     private string $id;
  96.     /**
  97.      * @ORM\OneToOne(targetEntity=Identity::class, cascade={"persist", "remove"})
  98.      * @ORM\JoinColumn(nullable=false)
  99.      * @SerializedName("identity")
  100.      * @Assert\NotBlank()
  101.      * @Assert\Valid()
  102.      * @Groups({"User:io", "get_godfather_by_godchild_email", "SponsorshipRequest:output"})
  103.      */
  104.     private Identity $identity;
  105.     /**
  106.      * @ORM\Column(type="string", length=180)
  107.      * @SerializedName("email")
  108.      * @Assert\NotBlank()
  109.      * @Assert\Email(normalizer="trim")
  110.      * @Groups({"User:io", "get_godfather_by_godchild_email"})
  111.      *
  112.      * @Serializer\Expose()
  113.      * @Serializer\Groups({"shannon", "get_user_facebook"})
  114.      * @Serializer\SerializedName("email")
  115.      */
  116.     private ?string $email;
  117.     /**
  118.      * @ORM\Column(type="json")
  119.      * @SerializedName("roles")
  120.      * @Groups({"User:output"})
  121.      */
  122.     private array $roles = ['ROLE_USER'];
  123.     /**
  124.      * @Assert\NotBlank(groups={
  125.      *     "Create",
  126.      *     "reset_password",
  127.      *     "initialize_password",
  128.      * })
  129.      * @Assert\Length(max=4096)
  130.      * @Groups({
  131.      *     "User:input",
  132.      *     "reset_password",
  133.      *     "initialize_password",
  134.      * })
  135.      */
  136.     private ?string $plainPassword null;
  137.     /**
  138.      * The below length depends on the "algorithm" you use for encoding
  139.      * the password, but this works well with bcrypt.
  140.      *
  141.      * @var string The hashed password
  142.      * @ORM\Column(type="string", length=64)
  143.      * @SerializedName("password")
  144.      * @Groups({
  145.      *      "User:io",
  146.      *  })
  147.      */
  148.     private string $password;
  149.     /**
  150.      * @var bool
  151.      * @ORM\Column(type="boolean", nullable=true)
  152.      * @SerializedName("optin_brand")
  153.      * @Groups({"User:io", "get_godfather_by_godchild_email", "patch_optin_brand_phone", "patch_optin_isoskele"})
  154.      */
  155.     private ?bool $optinBrand null;
  156.     /**
  157.      * @var bool
  158.      * @ORM\Column(type="boolean", nullable=true)
  159.      * @SerializedName("optin_customer")
  160.      * @Groups({"User:io", "get_godfather_by_godchild_email", "patch_optin_isoskele"})
  161.      */
  162.     private ?bool $optinCustomer null;
  163.     /**
  164.      * @var bool
  165.      * @ORM\Column(type="boolean", nullable=true)
  166.      * @SerializedName("optin_process")
  167.      * @Groups({
  168.      *     "User:io",
  169.      *     "initialize_password",
  170.      * })
  171.      */
  172.     private ?bool $optinProcess null;
  173.     /**
  174.      * @var bool
  175.      * @ORM\Column(type="boolean", nullable=true)
  176.      * @SerializedName("optin_phone")
  177.      * @Groups({
  178.      *     "User:io",
  179.      *     "initialize_password",
  180.      *     "patch_optin_brand_phone",
  181.      * })
  182.      */
  183.     private ?bool $optinPhone null;
  184.     /**
  185.      * @var bool
  186.      * @ORM\Column(type="boolean", nullable=true)
  187.      * @SerializedName("optin_sales")
  188.      * @Groups({
  189.      *     "User:io",
  190.      *     "initialize_password",
  191.      * })
  192.      */
  193.     private ?bool $optinSales null;
  194.     /**
  195.      * @var bool
  196.      * @ORM\Column(type="boolean", nullable=true)
  197.      * @SerializedName("optin_whats_app")
  198.      * @Groups({"User:io", "patch_optin_isoskele"})
  199.      */
  200.     private ?bool $optinWhatsApp null;
  201.     /**
  202.      * @var bool
  203.      * @ORM\Column(type="boolean", nullable=true)
  204.      * @SerializedName("optin_mobile_carriers")
  205.      * @Groups({"User:io", "patch_optin_isoskele"})
  206.      */
  207.     private ?bool $optinMobileCarriers null;
  208.     /**
  209.      * @var bool
  210.      * @ORM\Column(type="boolean", nullable=true)
  211.      * @SerializedName("optin_whats_app_carriers")
  212.      * @Groups({"User:io", "patch_optin_isoskele"})
  213.      */
  214.     private ?bool $optinWhatsAppCarriers null;
  215.     /**
  216.      * @ORM\OneToMany(targetEntity=Home::class, mappedBy="user", orphanRemoval=true, cascade={"persist"})
  217.      * @SerializedName("addresses_home")
  218.      * @Assert\Valid()
  219.      * @Groups({"User:io"})
  220.      */
  221.     private Collection $addressesHome;
  222.     /**
  223.      * @ORM\OneToMany(targetEntity=Delivery::class, mappedBy="user", orphanRemoval=true, cascade={"persist"})
  224.      * @SerializedName("addresses_delivery")
  225.      * @Assert\Valid()
  226.      * @Groups({"User:io"})
  227.      */
  228.     private Collection $addressesDelivery;
  229.     /**
  230.      * @ORM\OneToMany(targetEntity=Order::class, mappedBy="user", orphanRemoval=true, cascade={"persist"})
  231.      * @SerializedName("addresses_order")
  232.      * @Assert\Valid()
  233.      * @Groups({"User:io"})
  234.      */
  235.     private Collection $addressesOrder;
  236.     /**
  237.      * @ORM\OneToMany(targetEntity=Token::class, mappedBy="user")
  238.      * @SerializedName("tokens")
  239.      */
  240.     private Collection $tokens;
  241.     /**
  242.      * @ORM\OneToMany(targetEntity=Newsletter::class, mappedBy="user")
  243.      * @SerializedName("user")
  244.      */
  245.     private Collection $newsletters;
  246.     /**
  247.      * @ORM\OneToMany(targetEntity=Iban::class, mappedBy="user", orphanRemoval=true)
  248.      * @SerializedName("ibans")
  249.      * @Groups({"User:io"})
  250.      */
  251.     private Collection $ibans;
  252.     /**
  253.      * @ORM\ManyToOne(targetEntity=Company::class, inversedBy="users")
  254.      * @Assert\NotBlank()
  255.      * @Groups({"User:io"})
  256.      */
  257.     private $company;
  258.     /**
  259.      * @ORM\OneToMany(targetEntity=Operation::class, mappedBy="owner", orphanRemoval=true, cascade={"persist"})
  260.      * @SerializedName("operations")
  261.      */
  262.     private Collection $operations;
  263.     /**
  264.      * @ORM\OneToMany(targetEntity=Participation::class, mappedBy="user")
  265.      * @OrderBy({"createdAt" = "ASC"})
  266.      */
  267.     private $participations;
  268.     /**
  269.      * @ORM\OneToMany(targetEntity=SponsorshipRequest::class, mappedBy="user")
  270.      */
  271.     private Collection $sponsorshipsRequest;
  272.     /**
  273.      * @ORM\OneToMany(targetEntity=Carrier::class, mappedBy="user", orphanRemoval=true, cascade={"persist"})
  274.      * @SerializedName("carriers")
  275.      * @Groups({"User:io"})
  276.      */
  277.     private Collection $carriers;
  278.     /**
  279.      * @ORM\OneToMany(targetEntity=OperationCart::class, mappedBy="user")
  280.      */
  281.     private Collection $operationCarts;
  282.     /**
  283.      * @ORM\OneToMany(targetEntity=GiftCart::class, mappedBy="user")
  284.      */
  285.     private Collection $giftCarts;
  286.     /**
  287.      * @ORM\OneToMany(targetEntity=Purse::class, mappedBy="user", orphanRemoval=true)
  288.      */
  289.     private $purses;
  290.     /**
  291.      * @ORM\OneToMany(targetEntity=Order::class, mappedBy="user")
  292.      */
  293.     private $orders;
  294.     /**
  295.      * @ORM\Column(type="array", nullable=true)
  296.      * @SerializedName("extra_data")
  297.      * @Groups({"User:io"})
  298.      */
  299.     private $extraData;
  300.     /**
  301.      * @ORM\OneToMany(targetEntity=TasDraw::class, mappedBy="user")
  302.      */
  303.     private $tas;
  304.     /**
  305.      * @var \DateTime
  306.      *
  307.      * @ORM\Column(name="deleted_at", type="datetime", nullable=true)
  308.      */
  309.     private $deletedAt;
  310.     /**
  311.      * @var bool
  312.      */
  313.     private $import false;
  314.     /**
  315.      * @ORM\Column(type="string", length=180, nullable=true)
  316.      * @SerializedName("referral_code")
  317.      * @Groups({"User:io"})
  318.      */
  319.     private ?string $referralCode;
  320.     /**
  321.      * @ORM\Column(type="string", length=180, nullable=true)
  322.      * @SerializedName("company_name")
  323.      * @Groups({"User:io"})
  324.      */
  325.     private ?string $companyName;
  326.     /**
  327.      * @ORM\Column(type="string", length=14, nullable=true)
  328.      * @SerializedName("siret")
  329.      * @Assert\Length(max="14")
  330.      * @Groups({"User:io"})
  331.      */
  332.     private ?string $siret;
  333.     /**
  334.      * @ORM\ManyToOne(targetEntity="Referent")
  335.      * @ORM\JoinColumn(name="referent_id", referencedColumnName="id", nullable=true)
  336.      * @Groups({"User:io"})
  337.      */
  338.     private $referent;
  339.     /**
  340.      * @ORM\ManyToOne(targetEntity="App\Entity\User\Strate")
  341.      * @ORM\JoinColumn(name="strate_id", referencedColumnName="id", nullable=true)
  342.      * @Groups({"User:io"})
  343.      */
  344.     private $strate;
  345.     /**
  346.      * @ORM\ManyToOne(targetEntity=Profile::class, inversedBy="users")
  347.      * @ORM\JoinColumn(nullable=true)
  348.      */
  349.     private $profile;
  350.     /**
  351.      * @ORM\Column(type="boolean", options={"default": 0})
  352.      */
  353.     private $active;
  354.     /**
  355.      * @ORM\Column(type="datetime", options={"default": "CURRENT_TIMESTAMP"}, nullable=true)
  356.      * @Groups({"User:io"})
  357.      */
  358.     private ?\DateTimeInterface $lastLogin;
  359.     /**
  360.      * @ORM\Column(type="array", nullable=true)
  361.      * @SerializedName("additional_information")
  362.      * @Groups({"User:io"})
  363.      */
  364.     private ?array $additionalInformation;
  365.     /**
  366.      * @ORM\Column(type="string", length=10, nullable=true)
  367.      * @SerializedName("phone_number")
  368.      * @Assert\Length(max="10")
  369.      * @Groups({"User:io"})
  370.      */
  371.     private ?string $phoneNumber;
  372.     /**
  373.      * @ORM\Column(type="string", nullable=true)
  374.      * @SerializedName("other")
  375.      * @Groups({
  376.      *      "User:io",
  377.      *      "initialize_password",
  378.      *  })
  379.      */
  380.     private ?string $other;
  381.     /**
  382.      * @Groups({"User:io"})
  383.      * @SerializedName("knowledge_responses")
  384.      * @ORM\Column(type="json", nullable=true)
  385.      */
  386.     private ?array $knowledgeResponses = [];
  387.     public function __construct()
  388.     {
  389.         $this->addressesDelivery = new ArrayCollection();
  390.         $this->addressesHome = new ArrayCollection();
  391.         $this->tokens = new ArrayCollection();
  392.         $this->ibans = new ArrayCollection();
  393.         $this->newsletters = new ArrayCollection();
  394.         $this->operations = new ArrayCollection();
  395.         $this->participations = new ArrayCollection();
  396.         $this->operationCarts = new ArrayCollection();
  397.         $this->giftCarts = new ArrayCollection();
  398.         $this->purses = new ArrayCollection();
  399.         $this->orders = new ArrayCollection();
  400.         $this->tas = new ArrayCollection();
  401.         $this->sponsorshipsRequest = new ArrayCollection();
  402.         $this->carriers = new ArrayCollection();
  403.     }
  404.     /**
  405.      * @Serializer\VirtualProperty
  406.      * @Serializer\Groups({"global_shannon"})
  407.      * @Serializer\SerializedName("participation_id")
  408.      * @return string
  409.      */
  410.     public function getId(): ?string
  411.     {
  412.         return $this->id;
  413.     }
  414.     public function getIdentity(): ?Identity
  415.     {
  416.         return $this->identity;
  417.     }
  418.     public function setIdentity(Identity $identity): self
  419.     {
  420.         $this->identity $identity;
  421.         return $this;
  422.     }
  423.     public function getEmail(): ?string
  424.     {
  425.         return $this->email;
  426.     }
  427.     public function setEmail(string $email): self
  428.     {
  429.         $this->email $email;
  430.         return $this;
  431.     }
  432.     /**
  433.      * A visual identifier that represents this user.
  434.      *
  435.      * @see UserInterface
  436.      */
  437.     public function getUsername(): string
  438.     {
  439.         return (string)$this->email;
  440.     }
  441.     /**
  442.      * @see UserInterface
  443.      */
  444.     public function getRoles(): array
  445.     {
  446.         $roles $this->roles;
  447.         // guarantee every user at least has ROLE_USER
  448.         $roles[] = 'ROLE_USER';
  449.         return array_unique($roles);
  450.     }
  451.     public function setRoles(array $roles): self
  452.     {
  453.         $this->roles $roles;
  454.         return $this;
  455.     }
  456.     /**
  457.      * @return string|null
  458.      */
  459.     public function getPlainPassword(): ?string
  460.     {
  461.         return $this->plainPassword;
  462.     }
  463.     /**
  464.      * @param string|null $plainPassword
  465.      * @return User
  466.      */
  467.     public function setPlainPassword(?string $plainPassword): User
  468.     {
  469.         $this->plainPassword $plainPassword;
  470.         return $this;
  471.     }
  472.     /**
  473.      * @see UserInterface
  474.      */
  475.     public function getPassword(): string
  476.     {
  477.         return (string)$this->password;
  478.     }
  479.     public function setPassword(string $password): self
  480.     {
  481.         $this->password $password;
  482.         return $this;
  483.     }
  484.     /**
  485.      * @see UserInterface
  486.      */
  487.     public function getSalt(): ?string
  488.     {
  489.         return null;
  490.     }
  491.     /**
  492.      * @see UserInterface
  493.      */
  494.     public function eraseCredentials()
  495.     {
  496.         // If you store any temporary, sensitive data on the user, clear it here
  497.         $this->plainPassword null;
  498.     }
  499.     /**
  500.      * @return Collection|Home[]
  501.      */
  502.     public function getAddresses(): Collection
  503.     {
  504.         return $this->addressesHome;
  505.     }
  506.     /**
  507.      * @return Collection|Home[]
  508.      */
  509.     public function getAddressesHome(): Collection
  510.     {
  511.         return $this->addressesHome;
  512.     }
  513.     public function addAddressHome(Home $addressHome): self
  514.     {
  515.         if (!$this->addressesHome->contains($addressHome)) {
  516.             $this->addressesHome[] = $addressHome;
  517.             $addressHome->setUser($this);
  518.         }
  519.         return $this;
  520.     }
  521.     public function removeAddressHome(Home $addressHome): self
  522.     {
  523.         if ($this->addressesHome->contains($addressHome)) {
  524.             $this->addressesHome->removeElement($addressHome);
  525.             // set the owning side to null (unless already changed)
  526.             if ($addressHome->getUser() === $this) {
  527.                 $addressHome->setUser(null);
  528.             }
  529.         }
  530.         return $this;
  531.     }
  532.     /**
  533.      * @return Collection|Delivery[]
  534.      */
  535.     public function getAddressesDelivery(): Collection
  536.     {
  537.         return $this->addressesDelivery;
  538.     }
  539.     public function addAddressDelivery(Delivery $addressDelivery): self
  540.     {
  541.         if (!$this->addressesDelivery->contains($addressDelivery)) {
  542.             $this->addressesDelivery[] = $addressDelivery;
  543.             $addressDelivery->setUser($this);
  544.         }
  545.         return $this;
  546.     }
  547.     public function removeAddressDelivery(Delivery $addressDelivery): self
  548.     {
  549.         if ($this->addressesDelivery->contains($addressDelivery)) {
  550.             $this->addressesDelivery->removeElement($addressDelivery);
  551.             // set the owning side to null (unless already changed)
  552.             if ($addressDelivery->getUser() === $this) {
  553.                 $addressDelivery->setUser(null);
  554.             }
  555.         }
  556.         return $this;
  557.     }
  558.     /**
  559.      * @return Collection|Token[]
  560.      */
  561.     public function getTokens(): Collection
  562.     {
  563.         return $this->tokens;
  564.     }
  565.     public function addToken(Token $token): self
  566.     {
  567.         if (!$this->tokens->contains($token)) {
  568.             $this->tokens[] = $token;
  569.             $token->setUser($this);
  570.         }
  571.         return $this;
  572.     }
  573.     public function removeToken(Token $token): self
  574.     {
  575.         if ($this->tokens->contains($token)) {
  576.             $this->tokens->removeElement($token);
  577.             // set the owning side to null (unless already changed)
  578.             if ($token->getUser() === $this) {
  579.                 $token->setUser(null);
  580.             }
  581.         }
  582.         return $this;
  583.     }
  584.     /**
  585.      * @return Collection|Iban[]
  586.      */
  587.     public function getIbans(): Collection
  588.     {
  589.         return $this->ibans;
  590.     }
  591.     public function addIban(Iban $iban): self
  592.     {
  593.         if (!$this->ibans->contains($iban)) {
  594.             $this->ibans[] = $iban;
  595.             $iban->setUser($this);
  596.         }
  597.         return $this;
  598.     }
  599.     public function removeIban(Iban $iban): self
  600.     {
  601.         if ($this->ibans->removeElement($iban)) {
  602.             // set the owning side to null (unless already changed)
  603.             if ($iban->getUser() === $this) {
  604.                 $iban->setUser(null);
  605.             }
  606.         }
  607.         return $this;
  608.     }
  609.     /**
  610.      * @return Collection|Newsletter[]
  611.      */
  612.     public function getNewsletters(): Collection
  613.     {
  614.         return $this->newsletters;
  615.     }
  616.     public function addNewsletter(Newsletter $newsletter): self
  617.     {
  618.         if (!$this->newsletters->contains($newsletter)) {
  619.             $this->newsletters[] = $newsletter;
  620.             $newsletter->setUser($this);
  621.         }
  622.         return $this;
  623.     }
  624.     public function removeNewsletter(Newsletter $newsletter): self
  625.     {
  626.         if ($this->newsletters->contains($newsletter)) {
  627.             $this->newsletters->removeElement($newsletter);
  628.             if ($newsletter->getUser() === $this) {
  629.                 $newsletter->setUser(null);
  630.             }
  631.         }
  632.         return $this;
  633.     }
  634.     /**
  635.      * @return bool|null
  636.      */
  637.     public function isOptinBrand()
  638.     {
  639.         return $this->optinBrand;
  640.     }
  641.     /**
  642.      * @param bool $optinBrand
  643.      *
  644.      * @return User
  645.      */
  646.     public function setOptinBrand(bool $optinBrand): User
  647.     {
  648.         $this->optinBrand $optinBrand;
  649.         return $this;
  650.     }
  651.     /**
  652.      * @return bool|null
  653.      */
  654.     public function isOptinCustomer()
  655.     {
  656.         return $this->optinCustomer;
  657.     }
  658.     /**
  659.      * @param bool $optinCustomer
  660.      *
  661.      * @return User
  662.      */
  663.     public function setOptinCustomer(bool $optinCustomer): User
  664.     {
  665.         $this->optinCustomer $optinCustomer;
  666.         return $this;
  667.     }
  668.     /**
  669.      * @return bool
  670.      */
  671.     public function isOptinProcess(): bool
  672.     {
  673.         return (bool)$this->optinProcess;
  674.     }
  675.     /**
  676.      * @param bool $optinProcess
  677.      *
  678.      * @return User
  679.      */
  680.     public function setOptinProcess(bool $optinProcess): User
  681.     {
  682.         $this->optinProcess $optinProcess;
  683.         return $this;
  684.     }
  685.     /**
  686.      * @return bool
  687.      */
  688.     public function isOptinPhone(): bool
  689.     {
  690.         return (bool)$this->optinPhone;
  691.     }
  692.     /**
  693.      * @param bool $optinPhone
  694.      *
  695.      * @return User
  696.      */
  697.     public function setOptinPhone(?bool $optinPhone): User
  698.     {
  699.         $this->optinPhone $optinPhone;
  700.         return $this;
  701.     }
  702.     /**
  703.      * @return bool
  704.      */
  705.     public function isOptinSales(): bool
  706.     {
  707.         return (bool)$this->optinSales;
  708.     }
  709.     /**
  710.      * @param bool $optinSales
  711.      *
  712.      * @return User
  713.      */
  714.     public function setOptinSales(bool $optinSales): User
  715.     {
  716.         $this->optinSales $optinSales;
  717.         return $this;
  718.     }
  719.     /**
  720.      * @return bool
  721.      */
  722.     public function isOptinWhatsApp(): bool
  723.     {
  724.         return (bool)$this->optinWhatsApp;
  725.     }
  726.     /**
  727.      * @param bool $optinWhatsApp
  728.      *
  729.      * @return User
  730.      */
  731.     public function setOptinWhatsApp(bool $optinWhatsApp): User
  732.     {
  733.         $this->optinWhatsApp $optinWhatsApp;
  734.         return $this;
  735.     }
  736.     /**
  737.      * @return bool
  738.      */
  739.     public function isOptinMobileCarriers(): bool
  740.     {
  741.         return (bool)$this->optinMobileCarriers;
  742.     }
  743.     /**
  744.      * @param bool $optinMobileCarriers
  745.      *
  746.      * @return User
  747.      */
  748.     public function setOptinMobileCarriers(bool $optinMobileCarriers): User
  749.     {
  750.         $this->optinMobileCarriers $optinMobileCarriers;
  751.         return $this;
  752.     }
  753.     /**
  754.      * @return bool
  755.      */
  756.     public function isOptinWhatsAppCarriers(): bool
  757.     {
  758.         return (bool)$this->optinWhatsAppCarriers;
  759.     }
  760.     /**
  761.      * @param bool $optinWhatsAppCarriers
  762.      *
  763.      * @return User
  764.      */
  765.     public function setOptinWhatsAppCarriers(bool $optinWhatsAppCarriers): User
  766.     {
  767.         $this->optinWhatsAppCarriers $optinWhatsAppCarriers;
  768.         return $this;
  769.     }
  770.     public function getCompany(): ?Company
  771.     {
  772.         return $this->company;
  773.     }
  774.     public function setCompany(?Company $company): self
  775.     {
  776.         $this->company $company;
  777.         return $this;
  778.     }
  779.     /**
  780.      * @return ArrayCollection|Collection
  781.      */
  782.     public function getOperations()
  783.     {
  784.         return $this->operations;
  785.     }
  786.     /**
  787.      * @param ArrayCollection|Collection $operations
  788.      *
  789.      * @return User
  790.      */
  791.     public function setOperations($operations)
  792.     {
  793.         $this->operations $operations;
  794.         return $this;
  795.     }
  796.     /**
  797.      * @return Collection|Participation[]
  798.      */
  799.     public function getParticipations(): Collection
  800.     {
  801.         return $this->participations;
  802.     }
  803.     public function addParticipation(Participation $participation): self
  804.     {
  805.         if (!$this->participations->contains($participation)) {
  806.             $this->participations[] = $participation;
  807.             $participation->setUser($this);
  808.         }
  809.         return $this;
  810.     }
  811.     public function removeParticipation(Participation $participation): self
  812.     {
  813.         if ($this->participations->removeElement($participation)) {
  814.             // set the owning side to null (unless already changed)
  815.             if ($participation->getUser() === $this) {
  816.                 $participation->setUser(null);
  817.             }
  818.         }
  819.         return $this;
  820.     }
  821.     /**
  822.      * @return Collection|OperationCart[]
  823.      */
  824.     public function getOperationCarts(): Collection
  825.     {
  826.         return $this->operationCarts;
  827.     }
  828.     public function addOperationCart(OperationCart $operationCart): self
  829.     {
  830.         if (!$this->operationCarts->contains($operationCart)) {
  831.             $this->operationCarts[] = $operationCart;
  832.             $operationCart->setUser($this);
  833.         }
  834.         return $this;
  835.     }
  836.     public function removeCart(OperationCart $operationCart): self
  837.     {
  838.         if ($this->operationCarts->removeElement($operationCart)) {
  839.             // set the owning side to null (unless already changed)
  840.             if ($operationCart->getUser() === $this) {
  841.                 $operationCart->setUser(null);
  842.             }
  843.         }
  844.         return $this;
  845.     }
  846.     /**
  847.      * @return Collection|GiftCart[]
  848.      */
  849.     public function getGiftCarts(): Collection
  850.     {
  851.         return $this->giftCarts;
  852.     }
  853.     public function addGiftCart(GiftCart $giftCart): self
  854.     {
  855.         if (!$this->giftCarts->contains($giftCart)) {
  856.             $this->giftCarts[] = $giftCart;
  857.             $giftCart->setUser($this);
  858.         }
  859.         return $this;
  860.     }
  861.     public function removeGiftCart(GiftCart $giftCart): self
  862.     {
  863.         if ($this->giftCarts->removeElement($giftCart)) {
  864.             // set the owning side to null (unless already changed)
  865.             if ($giftCart->getUser() === $this) {
  866.                 $giftCart->setUser(null);
  867.             }
  868.         }
  869.         return $this;
  870.     }
  871.     // Shannon serialisation
  872.     /**
  873.      * @Serializer\VirtualProperty
  874.      * @Serializer\Type("string")
  875.      * @Serializer\Groups({"shannon"})
  876.      * @Serializer\SerializedName("civility")
  877.      * @return string
  878.      */
  879.     public function getCivility(): string
  880.     {
  881.         $civility "1";
  882.         if ($this->getIdentity()->getGender() === Identity::GENDER_FEMALE) {
  883.             $civility "2";
  884.         }
  885.         return $civility;
  886.     }
  887.     public function getGender(): ?string
  888.     {
  889.         return $this->getIdentity()->getGender();
  890.     }
  891.     /**
  892.      * @Serializer\VirtualProperty
  893.      * @Serializer\Groups({"shannon"})
  894.      * @Serializer\SerializedName("firstname")
  895.      * @return string
  896.      */
  897.     public function getFirstName(): string
  898.     {
  899.         return $this->getIdentity()->getFirstName();
  900.     }
  901.     /**
  902.      * @Serializer\VirtualProperty
  903.      * @Serializer\Groups({"shannon"})
  904.      * @Serializer\SerializedName("lastname")
  905.      * @return string
  906.      */
  907.     public function getLastName(): string
  908.     {
  909.         return $this->getIdentity()->getLastName();
  910.     }
  911.     /**
  912.      * @Serializer\VirtualProperty
  913.      * @Serializer\SerializedName("address_3")
  914.      * @return string
  915.      */
  916.     public function getAddress3(): string
  917.     {
  918.         $addressHome $this->getAddressesHome()->first();
  919.         if ($addressHome instanceof Home) {
  920.             return $addressHome->getStreet();
  921.         }
  922.         return '';
  923.     }
  924.     /**
  925.      * @Serializer\VirtualProperty
  926.      * @Serializer\Groups({"shannon", "shannon_refund"})
  927.      * @Serializer\SerializedName("country")
  928.      * @return string
  929.      */
  930.     public function getCountry(): string
  931.     {
  932.         return 'FR';
  933.     }
  934.     /**
  935.      * @Serializer\VirtualProperty
  936.      * @Serializer\SerializedName("city")
  937.      * @return string
  938.      */
  939.     public function getCity(): string
  940.     {
  941.         $addressHome $this->getAddressesHome()->first();
  942.         if ($addressHome instanceof Home) {
  943.             return $addressHome->getCity();
  944.         }
  945.         return '';
  946.     }
  947.     /**
  948.      * @Serializer\VirtualProperty
  949.      * @Serializer\SerializedName("postal_code")
  950.      * @return string
  951.      */
  952.     public function getPostalCode(): string
  953.     {
  954.         $addressHome $this->getAddressesHome()->first();
  955.         if ($addressHome instanceof Home) {
  956.             return $addressHome->getPostalCode();
  957.         }
  958.         return '';
  959.     }
  960.     /**
  961.      * @return Purse|null
  962.      */
  963.     public function getCurrentPurse(): ?Purse
  964.     {
  965.         foreach ($this->getPurses() as $purse) {
  966.             if ($purse->getDueAt() >= new \DateTime() && $purse->getStatus() === Purse::STATUS_AVAILABLE) {
  967.                 return $purse;
  968.             }
  969.         }
  970.         return null;
  971.     }
  972.     /**
  973.      * @return Collection<Purse>|Purse[]
  974.      */
  975.     public function getPurses(): Collection
  976.     {
  977.         return $this->purses;
  978.     }
  979.     public function addPurse(Purse $purse): self
  980.     {
  981.         if (!$this->purses->contains($purse)) {
  982.             $this->purses[] = $purse;
  983.             $purse->setUser($this);
  984.         }
  985.         return $this;
  986.     }
  987.     public function removePurse(Purse $purse): self
  988.     {
  989.         if ($this->purses->removeElement($purse)) {
  990.             // set the owning side to null (unless already changed)
  991.             if ($purse->getUser() === $this) {
  992.                 $purse->setUser(null);
  993.             }
  994.         }
  995.         return $this;
  996.     }
  997.     public function getPursesIds(): iterable
  998.     {
  999.         foreach ($this->purses as $purse) {
  1000.             yield $purse->getId();
  1001.         }
  1002.     }
  1003.     /**
  1004.      * @Serializer\VirtualProperty
  1005.      * @Serializer\Groups({"global_shannon"})
  1006.      * @Serializer\SerializedName("channel")
  1007.      * @return string
  1008.      */
  1009.     public function getChannel(): string
  1010.     {
  1011.         return 'FI';
  1012.     }
  1013.     /**
  1014.      * @Serializer\VirtualProperty
  1015.      * @Serializer\Groups({"global_shannon"})
  1016.      * @Serializer\SerializedName("action")
  1017.      * @return string
  1018.      */
  1019.     public function getAction(): string
  1020.     {
  1021.         return 'create';
  1022.     }
  1023.     public function __toString(): string
  1024.     {
  1025.         return $this->email;
  1026.     }
  1027.     /**
  1028.      * @Serializer\VirtualProperty
  1029.      * @Serializer\Groups({"global_shannon"})
  1030.      * @Serializer\SerializedName("participation_jeu")
  1031.      * @return string
  1032.      */
  1033.     public function getParticipationJeu(): int
  1034.     {
  1035.         return 1;
  1036.     }
  1037.     /**
  1038.      * @Serializer\VirtualProperty
  1039.      * @Serializer\Groups({"global_shannon"})
  1040.      * @Serializer\SerializedName("date_participation")
  1041.      */
  1042.     public function getDateParticipation()
  1043.     {
  1044.         $date = new \DateTime();
  1045.         return $date->format('Y-m-d H:i:s');
  1046.     }
  1047.     /**
  1048.      * @Serializer\VirtualProperty
  1049.      * @Serializer\Groups({"shannon"})
  1050.      * @Serializer\SerializedName("id")
  1051.      * @return string
  1052.      */
  1053.     public function getIdConso(): string
  1054.     {
  1055.         return $this->id;
  1056.     }
  1057.     /**
  1058.      * @return Collection|Order[]
  1059.      */
  1060.     public function getOrders(): Collection
  1061.     {
  1062.         return $this->orders;
  1063.     }
  1064.     public function addOrder(Order $order): self
  1065.     {
  1066.         if (!$this->orders->contains($order)) {
  1067.             $this->orders[] = $order;
  1068.             $order->setUser($this);
  1069.         }
  1070.         return $this;
  1071.     }
  1072.     public function removeOrder(Order $order): self
  1073.     {
  1074.         if ($this->orders->removeElement($order)) {
  1075.             // set the owning side to null (unless already changed)
  1076.             if ($order->getUser() === $this) {
  1077.                 $order->setUser(null);
  1078.             }
  1079.         }
  1080.         return $this;
  1081.     }
  1082.     public function getExtraData(): ?array
  1083.     {
  1084.         if (empty($this->extraData)) {
  1085.             $this->extraData null;
  1086.         }
  1087.         return $this->extraData;
  1088.     }
  1089.     public function setExtraData(?array $extraData): User
  1090.     {
  1091.         $this->extraData $extraData;
  1092.         return $this;
  1093.     }
  1094.     /**
  1095.      * @return Collection|TasDraw[]
  1096.      */
  1097.     public function getTas(): Collection
  1098.     {
  1099.         return $this->tas;
  1100.     }
  1101.     public function addTas(TasDraw $tas): self
  1102.     {
  1103.         if (!$this->tas->contains($tas)) {
  1104.             $this->tas[] = $tas;
  1105.             $tas->setUser($this);
  1106.         }
  1107.         return $this;
  1108.     }
  1109.     public function removeTas(TasDraw $tas): self
  1110.     {
  1111.         if ($this->tas->removeElement($tas)) {
  1112.             // set the owning side to null (unless already changed)
  1113.             if ($tas->getUser() === $this) {
  1114.                 $tas->setUser(null);
  1115.             }
  1116.         }
  1117.         return $this;
  1118.     }
  1119.     /**
  1120.      * Set deletedAt
  1121.      *
  1122.      * @param \DateTime $deletedAt
  1123.      *
  1124.      * @return User
  1125.      */
  1126.     public function setDeletedAt($deletedAt)
  1127.     {
  1128.         $this->deletedAt $deletedAt;
  1129.         return $this;
  1130.     }
  1131.     /**
  1132.      * Get deletedAt
  1133.      *
  1134.      * @return \DateTime
  1135.      */
  1136.     public function getDeletedAt()
  1137.     {
  1138.         return $this->deletedAt;
  1139.     }
  1140.     public function getImport()
  1141.     {
  1142.         return $this->import;
  1143.     }
  1144.     public function setImport($bool)
  1145.     {
  1146.         $this->import $bool;
  1147.         return $this;
  1148.     }
  1149.     public function getReferralCode(): ?string
  1150.     {
  1151.         return $this->referralCode;
  1152.     }
  1153.     public function setReferralCode($referralCode): User
  1154.     {
  1155.         $this->referralCode $referralCode;
  1156.         return $this;
  1157.     }
  1158.     public function createReferralCode()
  1159.     {
  1160.         return strtoupper(uniqid($_ENV['APP_PROJET'] . '-'));
  1161.     }
  1162.     public function getCompanyName(): ?string
  1163.     {
  1164.         return $this->companyName;
  1165.     }
  1166.     public function setCompanyName($companyName): User
  1167.     {
  1168.         $this->companyName $companyName;
  1169.         return $this;
  1170.     }
  1171.     public function getSiret(): ?string
  1172.     {
  1173.         return $this->siret;
  1174.     }
  1175.     public function setSiret($siret): User
  1176.     {
  1177.         $this->siret $siret;
  1178.         return $this;
  1179.     }
  1180.     public function getReferent()
  1181.     {
  1182.         return $this->referent;
  1183.     }
  1184.     public function setReferent($referent)
  1185.     {
  1186.         $this->referent $referent;
  1187.         return $this;
  1188.     }
  1189.     public function getStrate()
  1190.     {
  1191.         return $this->strate;
  1192.     }
  1193.     public function setStrate($strate)
  1194.     {
  1195.         $this->strate $strate;
  1196.         return $this;
  1197.     }
  1198.     public function getProfile(): ?Profile
  1199.     {
  1200.         return $this->profile;
  1201.     }
  1202.     public function setProfile(?Profile $profile): self
  1203.     {
  1204.         $this->profile $profile;
  1205.         return $this;
  1206.     }
  1207.     public function getActive(): ?bool
  1208.     {
  1209.         return $this->active;
  1210.     }
  1211.     public function setActive(bool $active): self
  1212.     {
  1213.         $this->active $active;
  1214.         return $this;
  1215.     }
  1216.     public function getUserIdentifier(): string
  1217.     {
  1218.         return (string) $this->email;
  1219.     }
  1220.     public function getLastLogin(): ?\DateTimeInterface
  1221.     {
  1222.         return $this->lastLogin;
  1223.     }
  1224.     public function setLastLogin(?\DateTimeInterface $lastLogin): User
  1225.     {
  1226.         $this->lastLogin $lastLogin;
  1227.         return $this;
  1228.     }
  1229.     public function getAdditionalInformation(): ?array
  1230.     {
  1231.         return $this->additionalInformation;
  1232.     }
  1233.     public function setAdditionalInformation(?array $additionalInformation): void
  1234.     {
  1235.         $this->additionalInformation $additionalInformation;
  1236.     }
  1237.     public function getPhoneNumber(): ?string
  1238.     {
  1239.         return $this->phoneNumber;
  1240.     }
  1241.     public function setPhoneNumber(?string $phoneNumber): User
  1242.     {
  1243.         $this->phoneNumber $phoneNumber;
  1244.         return $this;
  1245.     }
  1246.     /**
  1247.      * @return Collection<Carrier>|Carrier[]
  1248.      */
  1249.     public function getCarriers(): Collection
  1250.     {
  1251.         return $this->carriers;
  1252.     }
  1253.     public function addCarrier(Carrier $carrier): self
  1254.     {
  1255.         if (!$this->carriers->contains($carrier)) {
  1256.             if (count($this->carriers) < self::MAX_CARRIERS_AUTHORIZED) {
  1257.                 $this->carriers[] = $carrier;
  1258.                 $carrier->setUser($this);
  1259.             } else {
  1260.                 throw new \Exception("You can only have up to 3 additional carriers.");
  1261.             }
  1262.         }
  1263.         return $this;
  1264.     }
  1265.     public function removeCarrier(Carrier $carrier): self
  1266.     {
  1267.         if ($this->carriers->removeElement($carrier)) {
  1268.             // set the owning side to null (unless already changed)
  1269.             if ($carrier->getUser() === $this) {
  1270.                 $carrier->setUser(null);
  1271.             }
  1272.         }
  1273.         return $this;
  1274.     }
  1275.     public function getOther(): ?string
  1276.     {
  1277.         return $this->other;
  1278.     }
  1279.     public function setOther(?string $other): self
  1280.     {
  1281.         $this->other $other;
  1282.         return $this;
  1283.     }
  1284.     public function getKnowledgeResponses(): ?array
  1285.     {
  1286.         return $this->knowledgeResponses;
  1287.     }
  1288.     public function setKnowledgeResponses(?array $knowledgeResponses): self
  1289.     {
  1290.         $this->knowledgeResponses $knowledgeResponses;
  1291.         return $this;
  1292.     }
  1293. }