src/Entity/User.php line 29

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use AllowDynamicProperties;
  4. use App\Entity\ObjectValue\MainAccountInformation;
  5. use App\Manager\DonneeCompteClientManager;
  6. use App\Entity\WateringTips\WateringTips;
  7. use App\Security\RoleInterface;
  8. use App\Validator\Constraints\ValidSwiftMailerEmail;
  9. use Doctrine\Common\Collections\ArrayCollection;
  10. use Doctrine\Common\Collections\Collection;
  11. use Doctrine\ORM\Mapping as ORM;
  12. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  13. use Symfony\Component\Security\Core\User\UserInterface;
  14. /**
  15.  * @ORM\Entity(repositoryClass="App\Repository\App\UserRepository")
  16.  * @UniqueEntity(
  17.  *     fields={"email"},
  18.  *     message="my_profile.form.email.already_taken"
  19.  * )
  20.  * @ORM\Table(
  21.  *     name="`User`",
  22.  *     uniqueConstraints={@ORM\UniqueConstraint(name="email", columns={"email"})}
  23.  * )
  24.  */
  25. #[AllowDynamicProperties]
  26. class User implements UserInterface
  27. {
  28.     public const TYPE_MAIN 'main';
  29.     public const TYPE_CONTACT 'contact';
  30.     public const TYPE_GUEST 'guest';
  31.     public const TYPE_BIG_ACCOUNT 'GRAND COMPTE';
  32.     /**
  33.      * @ORM\Id
  34.      * @ORM\GeneratedValue
  35.      * @ORM\Column(type="integer")
  36.      *
  37.      * @var int
  38.      */
  39.     protected $id;
  40.     /**
  41.      * @ORM\Column(type="string")
  42.      *
  43.      * @var string
  44.      */
  45.     protected $type User::TYPE_CONTACT;
  46.     /**
  47.      * @ORM\Column(type="decimal", precision=18, scale=0, nullable=false)
  48.      *
  49.      * @var int
  50.      */
  51.     protected $customerNumber;
  52.     /**
  53.      * @ORM\Column(type="string")
  54.      *
  55.      * @var string
  56.      */
  57.     protected $password;
  58.     /**
  59.      * @ORM\Column(type="string", nullable=true)
  60.      * @ValidSwiftMailerEmail
  61.      *
  62.      * @var string
  63.      */
  64.     protected $email;
  65.     /**
  66.      * @ORM\Column(type="string", nullable=true)
  67.      * @ValidSwiftMailerEmail
  68.      *
  69.      * @var string
  70.      */
  71.     protected $newEmail;
  72.     /**
  73.      * @ORM\Column(type="string", nullable=true)
  74.      *
  75.      * @var ?string
  76.      */
  77.     protected $emailUpdateToken;
  78.     /**
  79.      * @ORM\Column(type="boolean")
  80.      *
  81.      * @var bool
  82.      */
  83.     protected $activated false;
  84.     /**
  85.      * @ORM\Column(type="datetime", nullable=true)
  86.      *
  87.      * @var \DateTime
  88.      */
  89.     protected $initializationDate;
  90.     /**
  91.      * @ORM\Column(type="datetime", nullable=true)
  92.      *
  93.      * @var \DateTime
  94.      */
  95.     protected $activationDate;
  96.     /**
  97.      * @ORM\Column(type="datetime", nullable=true)
  98.      *
  99.      * @var \DateTime
  100.      */
  101.     protected $lastConnexionDate;
  102.     /**
  103.      * @ORM\Column(type="boolean")
  104.      *
  105.      * @var bool
  106.      */
  107.     protected $newsletter false;
  108.     /**
  109.      * @ORM\Column(type="boolean")
  110.      *
  111.      * @var bool
  112.      */
  113.     protected $waterQualityAnalysis false;
  114.     /**
  115.      * @ORM\Column(type="boolean")
  116.      *
  117.      * @var bool
  118.      */
  119.     protected $monthlyConsumption false;
  120.     /**
  121.      * @ORM\Column(type="string", nullable=true)
  122.      *
  123.      * @var ?string
  124.      */
  125.     protected $passwordCreationToken;
  126.     /**
  127.      * @ORM\Column(type="string", nullable=true)
  128.      *
  129.      * @var ?string
  130.      */
  131.     protected $picture;
  132.     /**
  133.      * @ORM\OneToMany(targetEntity="App\Entity\User", mappedBy="mainAccount")
  134.      *
  135.      * var array
  136.      */
  137.     protected $contacts;
  138.     /**
  139.      * @ORM\ManyToOne(targetEntity="App\Entity\User", inversedBy="contacts")
  140.      * @ORM\JoinColumn(name="main_account_id", referencedColumnName="id")
  141.      *
  142.      * @var User
  143.      */
  144.     protected $mainAccount;
  145.     /**
  146.      * @ORM\OneToOne(targetEntity="App\Entity\Contact", cascade={"persist", "remove"})
  147.      * @ORM\JoinColumn(name="contact_information_id", referencedColumnName="id")
  148.      *
  149.      * @var Contact
  150.      */
  151.     protected $contactInformation;
  152.     /** @var string */
  153.     protected $civility;
  154.     /** @var string */
  155.     protected $firstName;
  156.     /** @var string */
  157.     protected $lastName;
  158.     /** @var string */
  159.     protected $connexionId;
  160.     /** @var string */
  161.     protected $pictureUrl;
  162.     /** @var array */
  163.     protected $roles = [RoleInterface::ROLE_USER];
  164.     /** @var MainAccountInformation */
  165.     protected $mainAccountInformation;
  166.     /** @var DonneeCompteClient|null $donneeCompteClientManager */
  167.     protected DonneeCompteClient|null $donneeCompteClientManager;
  168.     /**
  169.      * @ORM\OneToMany(targetEntity=SuiviConsoActivation::class, mappedBy="customer", orphanRemoval=true)
  170.      */
  171.     private $suiviConsoActivations;
  172.     /**
  173.      * @var Collection<WateringTips>
  174.      * @ORM\OneToMany(
  175.      *     targetEntity="App\Entity\WateringTips\WateringTips",
  176.      *     mappedBy="user",
  177.      *     cascade={"remove"},
  178.      *     orphanRemoval=true
  179.      * )
  180.      */
  181.     private $wateringTips;
  182.     public function __construct()
  183.     {
  184.         $this->suiviConsoActivations = new ArrayCollection();
  185.         $this->wateringTips = new ArrayCollection();
  186.     }
  187.     public function getRoles(): array
  188.     {
  189.         return $this->roles;
  190.     }
  191.     /**
  192.      * @return User
  193.      */
  194.     public function addRole(string $role): self
  195.     {
  196.         $this->roles[] = $role;
  197.         return $this;
  198.     }
  199.     /**
  200.      * @return User
  201.      */
  202.     public function addRoles(array $roles): self
  203.     {
  204.         foreach ($roles as $role) {
  205.             if (is_string($role)) {
  206.                 $this->addRole($role);
  207.             }
  208.         }
  209.         return $this;
  210.     }
  211.     public function hasRole(string $role): bool
  212.     {
  213.         return in_array($role$this->roles);
  214.     }
  215.     public function getPassword(): string
  216.     {
  217.         return $this->password;
  218.     }
  219.     /**
  220.      * @return null|string
  221.      */
  222.     public function getSalt(): string
  223.     {
  224.         return '';
  225.     }
  226.     public function getUsername(): string
  227.     {
  228.         return $this->lastName ' ' $this->firstName;
  229.     }
  230.     public function eraseCredentials(): void
  231.     {
  232.     }
  233.     public function getId(): int
  234.     {
  235.         return $this->id;
  236.     }
  237.     public function setId(int $id): User
  238.     {
  239.         $this->id $id;
  240.         return $this;
  241.     }
  242.     public function getType(): string
  243.     {
  244.         return $this->type;
  245.     }
  246.     public function setType(string $type): User
  247.     {
  248.         $this->type $type;
  249.         return $this;
  250.     }
  251.     public function getCustomerNumber(): ?int
  252.     {
  253.         return $this->customerNumber;
  254.     }
  255.     /**
  256.      * @return User
  257.      */
  258.     public function setCustomerNumber(int $customerNumber): self
  259.     {
  260.         $this->customerNumber $customerNumber;
  261.         return $this;
  262.     }
  263.     /**
  264.      * @return User
  265.      */
  266.     public function setPassword(string $password): self
  267.     {
  268.         $this->password $password;
  269.         return $this;
  270.     }
  271.     public function getEmail(): ?string
  272.     {
  273.         return $this->email;
  274.     }
  275.     /**
  276.      * @param string $email
  277.      *
  278.      * @return User
  279.      */
  280.     public function setEmail(?string $email): self
  281.     {
  282.         $this->email $email;
  283.         return $this;
  284.     }
  285.     public function getNewEmail(): ?string
  286.     {
  287.         return $this->newEmail;
  288.     }
  289.     /**
  290.      * @param string $newEmail
  291.      *
  292.      * @return User
  293.      */
  294.     public function setNewEmail(?string $newEmail): self
  295.     {
  296.         $this->newEmail $newEmail;
  297.         return $this;
  298.     }
  299.     public function getEmailUpdateToken(): ?string
  300.     {
  301.         return $this->emailUpdateToken;
  302.     }
  303.     /**
  304.      * @param string $emailUpdateToken
  305.      *
  306.      * @return User
  307.      */
  308.     public function setEmailUpdateToken(?string $emailUpdateToken): self
  309.     {
  310.         $this->emailUpdateToken $emailUpdateToken;
  311.         return $this;
  312.     }
  313.     public function getInitializationDate(): \DateTime
  314.     {
  315.         return $this->initializationDate;
  316.     }
  317.     /**
  318.      * @return User
  319.      */
  320.     public function setInitializationDate(\DateTime $initializationDate): self
  321.     {
  322.         $this->initializationDate $initializationDate;
  323.         return $this;
  324.     }
  325.     public function getActivationDate(): ?\DateTime
  326.     {
  327.         return $this->activationDate;
  328.     }
  329.     /**
  330.      * @return User
  331.      */
  332.     public function setActivationDate(?\DateTime $activationDate): self
  333.     {
  334.         $this->activationDate $activationDate;
  335.         return $this;
  336.     }
  337.     public function getLastConnexionDate(): ?\DateTime
  338.     {
  339.         return $this->lastConnexionDate;
  340.     }
  341.     /**
  342.      * @return User
  343.      */
  344.     public function setLastConnexionDate(?\DateTime $lastConnexionDate): self
  345.     {
  346.         $this->lastConnexionDate $lastConnexionDate;
  347.         return $this;
  348.     }
  349.     public function getPasswordCreationToken(): ?string
  350.     {
  351.         return $this->passwordCreationToken;
  352.     }
  353.     /**
  354.      * @return User
  355.      */
  356.     public function setPasswordCreationToken(?string $token): self
  357.     {
  358.         $this->passwordCreationToken $token;
  359.         return $this;
  360.     }
  361.     public function getContactInformation(): ?Contact
  362.     {
  363.         return $this->contactInformation;
  364.     }
  365.     /**
  366.      * @return User
  367.      */
  368.     public function setContactInformation(Contact $contactInformation): self
  369.     {
  370.         $this->contactInformation $contactInformation;
  371.         return $this;
  372.     }
  373.     /**
  374.      * @return mixed
  375.      */
  376.     public function getContacts()
  377.     {
  378.         return $this->contacts;
  379.     }
  380.     /**
  381.      * @param mixed $contacts
  382.      *
  383.      * @return User
  384.      */
  385.     public function setContacts($contacts)
  386.     {
  387.         $this->contacts $contacts;
  388.         return $this;
  389.     }
  390.     public function getMainAccount(): ?User
  391.     {
  392.         return $this->mainAccount;
  393.     }
  394.     public function setMainAccount(User $mainAccount): User
  395.     {
  396.         $this->mainAccount $mainAccount;
  397.         return $this;
  398.     }
  399.     public function getCivility(): ?string
  400.     {
  401.         return $this->civility;
  402.     }
  403.     /**
  404.      * @return User
  405.      */
  406.     public function setCivility(?string $civility): self
  407.     {
  408.         $this->civility $civility;
  409.         return $this;
  410.     }
  411.     public function getFirstName(): ?string
  412.     {
  413.         return $this->firstName;
  414.     }
  415.     /**
  416.      * @return User
  417.      */
  418.     public function setFirstName(?string $firstName): self
  419.     {
  420.         $this->firstName $firstName;
  421.         return $this;
  422.     }
  423.     public function getLastName(): ?string
  424.     {
  425.         return $this->lastName;
  426.     }
  427.     /**
  428.      * @return User
  429.      */
  430.     public function setLastName(?string $lastName): self
  431.     {
  432.         $this->lastName $lastName;
  433.         return $this;
  434.     }
  435.     public function getConnexionId(): ?string
  436.     {
  437.         return $this->connexionId;
  438.     }
  439.     /**
  440.      * @return User
  441.      */
  442.     public function setConnexionId(?string $connexionId): self
  443.     {
  444.         $this->connexionId $connexionId;
  445.         return $this;
  446.     }
  447.     public function hasNewsletter(): bool
  448.     {
  449.         return $this->newsletter;
  450.     }
  451.     /**
  452.      * @return User
  453.      */
  454.     public function setNewsletter(bool $newsletter): self
  455.     {
  456.         $this->newsletter $newsletter;
  457.         return $this;
  458.     }
  459.     public function hasWaterQualityAnalysis(): bool
  460.     {
  461.         return $this->waterQualityAnalysis;
  462.     }
  463.     public function setWaterQualityAnalysis(bool $waterQualityAnalysis): self
  464.     {
  465.         $this->waterQualityAnalysis $waterQualityAnalysis;
  466.         return $this;
  467.     }
  468.     public function hasMonthlyConsumption(): bool
  469.     {
  470.         return $this->monthlyConsumption;
  471.     }
  472.     public function setMonthlyConsumption(bool $monthlyConsumption): self
  473.     {
  474.         $this->monthlyConsumption $monthlyConsumption;
  475.         return $this;
  476.     }
  477.     public function isActivated(): bool
  478.     {
  479.         return $this->activated;
  480.     }
  481.     /**
  482.      * @return User
  483.      */
  484.     public function setActivated(bool $activated): self
  485.     {
  486.         $this->activated $activated;
  487.         return $this;
  488.     }
  489.     public function getPicture(): ?string
  490.     {
  491.         return $this->picture;
  492.     }
  493.     /**
  494.      * @return User
  495.      */
  496.     public function setPicture(?string $picture): self
  497.     {
  498.         $this->picture $picture;
  499.         return $this;
  500.     }
  501.     public function getPictureUrl(): ?string
  502.     {
  503.         return $this->pictureUrl;
  504.     }
  505.     /**
  506.      * @return User
  507.      */
  508.     public function setPictureUrl(?string $pictureUrl): self
  509.     {
  510.         $this->pictureUrl $pictureUrl;
  511.         return $this;
  512.     }
  513.     public function getMainAccountInformation(): ?MainAccountInformation
  514.     {
  515.         return $this->mainAccountInformation;
  516.     }
  517.     public function setMainAccountInformation(MainAccountInformation $mainAccountInformation): User
  518.     {
  519.         $this->mainAccountInformation $mainAccountInformation;
  520.         return $this;
  521.     }
  522.     public function isMainAccount(): bool
  523.     {
  524.         return User::TYPE_MAIN === $this->type;
  525.     }
  526.     public function isGuest(): bool
  527.     {
  528.         return User::TYPE_GUEST === $this->type;
  529.     }
  530.     public function isContact(): bool
  531.     {
  532.         return User::TYPE_CONTACT === $this->type;
  533.     }
  534.     /**
  535.      * @return Collection|SuiviConsoActivation[]
  536.      */
  537.     public function getSuiviConsoActivations(): Collection
  538.     {
  539.         return $this->suiviConsoActivations;
  540.     }
  541.     public function addSuiviConsoActivation(SuiviConsoActivation $suiviConsoActivation): self
  542.     {
  543.         if (!$this->suiviConsoActivations->contains($suiviConsoActivation)) {
  544.             $this->suiviConsoActivations[] = $suiviConsoActivation;
  545.             $suiviConsoActivation->setCustomer($this);
  546.         }
  547.         return $this;
  548.     }
  549.     public function removeSuiviConsoActivation(SuiviConsoActivation $suiviConsoActivation): self
  550.     {
  551.         if ($this->suiviConsoActivations->removeElement($suiviConsoActivation)) {
  552.             // set the owning side to null (unless already changed)
  553.             if ($suiviConsoActivation->getCustomer() === $this) {
  554.                 $suiviConsoActivation->setCustomer(null);
  555.             }
  556.         }
  557.         return $this;
  558.     }
  559.     public function getDonneeCompteClient(): DonneeCompteClient|null
  560.     {
  561.         return $this->donneeCompteClient ?? null;
  562.     }
  563.     public function setDonneeCompteClient(DonneeCompteClient|null $donneeCompteClient): User
  564.     {
  565.         $this->donneeCompteClient $donneeCompteClient;
  566.         return $this;
  567.     }
  568.     public function getFullname(): string
  569.     {
  570.         return $this->lastName ' ' $this->firstName;
  571.     }
  572. }