src/Admin/Entity/StdWebUsers.php line 20

Open in your IDE?
  1. <?php
  2. namespace App\Admin\Entity;
  3. use App\Entity\StdPagesTracking;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use Symfony\Component\Security\Core\User\UserInterface;
  8. use App\Admin\Entity\StdWebUsersAddresses as StdWebUsersAddresses;
  9. use JsonSerializable;
  10. use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
  11. /**
  12.  * StdUsers
  13.  */
  14. #[ORM\Table(name'std_web_users')]
  15. #[ORM\Entity(repositoryClass'App\Admin\Repository\StdWebUsersRepository')]
  16. #[ORM\HasLifecycleCallbacks]
  17. class StdWebUsers implements UserInterfaceJsonSerializablePasswordAuthenticatedUserInterface
  18. {
  19.     /**
  20.      * @var int
  21.      */
  22.     #[ORM\Column(name'id'type'integer'nullablefalseoptions: ['unsigned' => true'comment' => 'Unique identifier'])]
  23.     #[ORM\Id]
  24.     #[ORM\GeneratedValue(strategy'IDENTITY')]
  25.     private $id;
  26.     /**
  27.      * @var string|null
  28.      */
  29.     #[ORM\Column(name'name'type'string'length255nullabletrueoptions: ['comment' => "User's name"])]
  30.     private $name;
  31.     /**
  32.      * @var string
  33.      */
  34.     #[ORM\Column(name'username'type'string'length100nullablefalseoptions: ['comment' => 'Username used to login'])]
  35.     private $username;
  36.     /**
  37.      * @var string|null
  38.      */
  39.     #[ORM\Column(name'erp_code'type'string'length50nullabletrueoptions: ['comment' => "User's erp code"])]
  40.     private $erpCode;
  41.     /**
  42.      * @var string
  43.      */
  44.     #[Assert\Email]
  45.     #[ORM\Column(name'email'type'string'length254nullablefalseoptions: ['comment' => 'Email address of the user'])]
  46.     private $email;
  47.     /**
  48.      * @var string
  49.      */
  50.     #[ORM\Column(name'password'type'string'length255nullabletrueoptions: ['comment' => "User's password"])]
  51.     private $password;
  52.     /**
  53.      * @var \DateTime|null
  54.      */
  55.     #[ORM\Column(name'password_date'type'datetime'nullabletrueoptions: ['comment' => 'Last date and time the password was updated'])]
  56.     private $passwordDate;
  57.     /**
  58.      * @var int|null
  59.      */
  60.     #[ORM\Column(name'failed_attempts'type'integer'nullabletrueoptions: ['unsigned' => true'comment' => 'Number of failed login attempts'])]
  61.     private $failedAttempts '0';
  62.     /**
  63.      * @var bool|null
  64.      */
  65.     #[ORM\Column(name'force_password_change'type'boolean'nullabletrueoptions: ['comment' => 'Flag to force the user to change the password on the next login'])]
  66.     private $forcePasswordChange;
  67.     /**
  68.      * @var \DateTime|null
  69.      */
  70.     #[ORM\Column(name'last_login_date'type'datetime'nullabletrueoptions: ['comment' => 'Date and time of the last successful login'])]
  71.     private $lastLoginDate;
  72.     /**
  73.      * @var \DateTime|null
  74.      */
  75.     #[ORM\Column(name'penultimate_login_date'type'datetime'nullabletrueoptions: ['comment' => 'Date and time of the penultimate successful login'])]
  76.     private $penultimateLoginDate;
  77.     /**
  78.      * @var string|null
  79.      */
  80.     #[ORM\Column(name'language'type'string'length3nullabletrueoptions: ['comment' => "Preferred user interface's language code"])]
  81.     private $language;
  82.     /**
  83.      * @var bool
  84.      */
  85.     #[ORM\Column(name'is_locked'type'boolean'nullablefalseoptions: ['comment' => 'Flag to lock the user'])]
  86.     private $isLocked '0';
  87.     /**
  88.      * @var bool
  89.      */
  90.     #[ORM\Column(name'is_super_user'type'boolean'nullablefalseoptions: ['comment' => 'Flag indicating super user privileges'])]
  91.     private $isSuperUser '0';
  92.     /**
  93.      * @var bool
  94.      */
  95.     #[ORM\Column(name'is_deleted'type'boolean'nullablefalseoptions: ['comment' => 'Flag that indicates the user has been deleted'])]
  96.     private $isDeleted '0';
  97.     /**
  98.      * @var bool
  99.      */
  100.     #[ORM\Column(name'is_active'type'boolean'nullablefalseoptions: ['default' => 1'comment' => 'Flag that indicates if the user is active'])]
  101.     private $isActive '1';
  102.     /**
  103.      * @var \App\Admin\Entity\StdUsers
  104.      */
  105.     #[ORM\JoinColumn(name'created_by'referencedColumnName'id')]
  106.     #[ORM\ManyToOne(targetEntity'App\Admin\Entity\StdUsers')]
  107.     private $createdBy;
  108.     /**
  109.      * @var \DateTime
  110.      */
  111.     #[ORM\Column(name'created_date'type'datetime'nullablefalseoptions: ['comment' => 'Date and time of the record creation'])]
  112.     private $createdDate;
  113.     /**
  114.      * @var string|null
  115.      */
  116.     #[ORM\Column(name'passwordrecovery'type'string'length250nullabletrue)]
  117.     private $passwordrecovery;
  118.     /**
  119.      * @var json|null
  120.      */
  121.     #[ORM\Column(name'info'type'json'nullabletrueoptions: ['comment' => 'Other information'])]
  122.     private $info;
  123.     /**
  124.      * @var string|null
  125.      */
  126.     #[ORM\Column(name'logintoken'type'string'length32nullabletrue)]
  127.     private $logintoken;
  128.     /**
  129.      * @var string|null
  130.      */
  131.     #[ORM\Column(name'activationkey'type'string'length100nullabletrue)]
  132.     private $activationkey;
  133.     /**
  134.      * @var string|null
  135.      */
  136.     #[ORM\Column(name'facebook_id'type'string'length255nullabletrue)]
  137.     private $facebookId;
  138.     /**
  139.      * @var bool|null
  140.      */
  141.     #[ORM\Column(name'facebook_integration'type'boolean'nullabletrue)]
  142.     private $facebookIntegration;
  143.     /**
  144.      * @var string|null
  145.      */
  146.     #[ORM\Column(name'google_id'type'string'length255nullabletrue)]
  147.     private $googleId;
  148.     /**
  149.      * @var bool|null
  150.      */
  151.     #[ORM\Column(name'google_integration'type'boolean'nullabletrue)]
  152.     private $googleIntegration;
  153.     /**
  154.      * @var string|null
  155.      */
  156.     #[ORM\Column(name'apple_id'type'string'length255nullabletrue)]
  157.     private $appleId;
  158.     /**
  159.      * @var string|null
  160.      */
  161.     #[ORM\Column(name'apple_refresh_token'type'string'length255nullabletrue)]
  162.     private $appleRefreshToken;
  163.     /**
  164.      * @var \DateTime|null
  165.      */
  166.     #[ORM\Column(name'terms_accepted_at'type'datetime'nullabletrue)]
  167.     private $termsAcceptedAt;
  168.     /**
  169.      * @var string|null
  170.      */
  171.     #[ORM\Column(name'phone'type'string'length20nullabletrue)]
  172.     private $phone;
  173.     /**
  174.      * @var string|null
  175.      */
  176.     #[ORM\Column(name'mobile'type'string'length20nullabletrue)]
  177.     private $mobile;
  178.     /**
  179.      * @var string|null
  180.      */
  181.     #[ORM\Column(name'vat'type'string'length20nullabletrue)]
  182.     private $vat;
  183.     #[ORM\OneToMany(targetEntity'StdWebUsersAddresses'mappedBy'webuser'cascade: ['persist''remove'], orphanRemovaltrue)]
  184.     private $addresses;
  185.     /**
  186.      * @var \App\Admin\Entity\StdUsers
  187.      */
  188.     #[ORM\JoinColumn(name'updated_by'referencedColumnName'id')]
  189.     #[ORM\ManyToOne(targetEntity'App\Admin\Entity\StdUsers')]
  190.     private $updatedBy;
  191.     /**
  192.      * @var \DateTime
  193.      */
  194.     #[ORM\Column(name'updated_date'type'datetime'nullablefalseoptions: ['comment' => 'Date and time the record was last updated'])]
  195.     private $updatedDate;
  196.     /**
  197.     * @var array
  198.     */
  199.    #[ORM\Column(type'json')]
  200.    private $roles = [];
  201.     #[ORM\OneToMany(mappedBy'webUser'targetEntityStdPagesTracking::class)]
  202.     private Collection $pageTrackings;
  203.     public function __construct()
  204.     {
  205.         $this->addresses = new ArrayCollection();
  206.         $this->pageTrackings = new ArrayCollection();
  207.     }
  208.     
  209.     public function getId(): ?int
  210.     {
  211.         return $this->id;
  212.     }
  213.     public function getName(): ?string
  214.     {
  215.         return $this->name;
  216.     }
  217.     public function setName(?string $name): self
  218.     {
  219.         $this->name $name;
  220.         return $this;
  221.     }
  222.     public function getUsername(): ?string
  223.     {
  224.         if(empty($this->username)){
  225.             return $this->getEmail();
  226.         }else{
  227.             return $this->username;
  228.         }
  229.     }
  230.     public function getUserIdentifier(): string
  231.     {
  232.         if(empty($this->username)){
  233.             return (string) $this->getEmail();
  234.         }else{
  235.             return (string) $this->username;
  236.         }
  237.     }
  238.     public function setUsername(string $username): self
  239.     {
  240.         $this->username $username;
  241.         return $this;
  242.     }
  243.     public function getErpCode(): ?string
  244.     {
  245.         return $this->erpCode;
  246.     }
  247.     public function setErpCode(?string $erpcode): self
  248.     {
  249.         $this->erpCode $erpcode;
  250.         return $this;
  251.     }
  252.     public function getEmail(): ?string
  253.     {
  254.         return $this->email;
  255.     }
  256.     public function setEmail(string $email): self
  257.     {
  258.         $this->email $email;
  259.         return $this;
  260.     }
  261.     public function getPassword(): ?string
  262.     {
  263.         return $this->password;
  264.     }
  265.     public function setPassword(string $password): self
  266.     {
  267.         $this->password $password;
  268.         return $this;
  269.     }
  270.     public function getPasswordDate(): ?\DateTimeInterface
  271.     {
  272.         return $this->passwordDate;
  273.     }
  274.     public function setPasswordDate(?\DateTimeInterface $passwordDate): self
  275.     {
  276.         $this->passwordDate $passwordDate;
  277.         return $this;
  278.     }
  279.     public function getFailedAttempts(): ?int
  280.     {
  281.         return $this->failedAttempts;
  282.     }
  283.     public function setFailedAttempts(?int $failedAttempts): self
  284.     {
  285.         $this->failedAttempts $failedAttempts;
  286.         return $this;
  287.     }
  288.     public function getForcePasswordChange(): ?bool
  289.     {
  290.         return $this->forcePasswordChange;
  291.     }
  292.     public function setForcePasswordChange(?bool $forcePasswordChange): self
  293.     {
  294.         $this->forcePasswordChange $forcePasswordChange;
  295.         return $this;
  296.     }
  297.     public function getLastLoginDate(): ?\DateTimeInterface
  298.     {
  299.         return $this->lastLoginDate;
  300.     }
  301.     public function setLastLoginDate(?\DateTimeInterface $lastLoginDate): self
  302.     {
  303.         $this->lastLoginDate $lastLoginDate;
  304.         return $this;
  305.     }
  306.     public function getPenultimateLoginDate(): ?\DateTimeInterface
  307.     {
  308.         return $this->penultimateLoginDate;
  309.     }
  310.     public function setPenultimateLoginDate(?\DateTimeInterface $penultimateLoginDate): self
  311.     {
  312.         $this->penultimateLoginDate $penultimateLoginDate;
  313.         return $this;
  314.     }
  315.     public function getLanguage(): ?string
  316.     {
  317.         return $this->language;
  318.     }
  319.     public function setLanguage(?string $language): self
  320.     {
  321.         $this->language $language;
  322.         return $this;
  323.     }
  324.     public function getIsLocked(): ?bool
  325.     {
  326.         return $this->isLocked;
  327.     }
  328.     public function setIsLocked(bool $isLocked): self
  329.     {
  330.         $this->isLocked $isLocked;
  331.         return $this;
  332.     }
  333.     public function getIsSuperUser(): ?bool
  334.     {
  335.         return $this->isSuperUser;
  336.     }
  337.     public function setIsSuperUser(bool $isSuperUser): self
  338.     {
  339.         $this->isSuperUser $isSuperUser;
  340.         return $this;
  341.     }
  342.     public function getIsDeleted(): ?bool
  343.     {
  344.         return $this->isDeleted;
  345.     }
  346.     public function setIsDeleted(bool $isDeleted): self
  347.     {
  348.         $this->isDeleted $isDeleted;
  349.         return $this;
  350.     }
  351.     public function getIsActive(): ?bool
  352.     {
  353.         return $this->isActive;
  354.     }
  355.     public function setIsActive(bool $isActive): self
  356.     {
  357.         $this->isActive $isActive;
  358.         return $this;
  359.     }
  360.     public function getCreatedDate(): ?\DateTimeInterface
  361.     {
  362.         return $this->createdDate;
  363.     }
  364.     public function setCreatedDate(\DateTimeInterface $createdDate): self
  365.     {
  366.         $this->createdDate $createdDate;
  367.         return $this;
  368.     }
  369.     public function getUpdatedDate(): ?\DateTimeInterface
  370.     {
  371.         return $this->updatedDate;
  372.     }
  373.     public function setUpdatedDate(\DateTimeInterface $updatedDate): self
  374.     {
  375.         $this->updatedDate $updatedDate;
  376.         return $this;
  377.     }
  378.     public function getRoles(): array
  379.     {
  380.         return $this->roles;
  381.     }
  382.     public function setRoles(array $roles): self
  383.     {
  384.         foreach ($roles as  $value) {
  385.             $data[] = $value->getName();
  386.         }
  387.         $this->roles $data;
  388.         return $this;
  389.     }
  390.     public function getPasswordrecovery(): ?string
  391.     {
  392.         return $this->passwordrecovery;
  393.     }
  394.     public function setPasswordrecovery(?string $passwordrecovery): self
  395.     {
  396.         $this->passwordrecovery $passwordrecovery;
  397.         return $this;
  398.     }
  399.     public function getInfo(): ?array
  400.     {
  401.         return $this->info;
  402.     }
  403.     public function setInfo(?array $info): self
  404.     {
  405.         $this->info $info;
  406.         return $this;
  407.     }
  408.     public function getLogintoken(): ?string
  409.     {
  410.         return $this->logintoken;
  411.     }
  412.     public function setLogintoken(?string $logintoken): self
  413.     {
  414.         $this->logintoken $logintoken;
  415.         return $this;
  416.     }
  417.     public function getActivationkey(): ?string
  418.     {
  419.         return $this->activationkey;
  420.     }
  421.     public function setActivationkey(?string $activationkey): self
  422.     {
  423.         $this->activationkey $activationkey;
  424.         return $this;
  425.     }
  426.     public function getFacebookId(): ?string
  427.     {
  428.         return $this->facebookId;
  429.     }
  430.     public function setFacebookId(?string $facebookId): self
  431.     {
  432.         $this->facebookId $facebookId;
  433.         return $this;
  434.     }
  435.     public function getFacebookIntegration(): ?bool
  436.     {
  437.         return $this->facebookIntegration;
  438.     }
  439.     public function setFacebookIntegration(?bool $facebookIntegration): self
  440.     {
  441.         $this->facebookIntegration $facebookIntegration;
  442.         return $this;
  443.     }
  444.     public function getGoogleId(): ?string
  445.     {
  446.         return $this->googleId;
  447.     }
  448.     public function setGoogleId(?string $googleId): self
  449.     {
  450.         $this->googleId $googleId;
  451.         return $this;
  452.     }
  453.     public function getAppleId(): ?string
  454.     {
  455.         return $this->appleId;
  456.     }
  457.     public function setAppleId(?string $appleId): self
  458.     {
  459.         $this->appleId $appleId;
  460.         return $this;
  461.     }
  462.     public function getAppleRefreshToken(): ?string
  463.     {
  464.         return $this->appleRefreshToken;
  465.     }
  466.     public function setAppleRefreshToken(?string $appleRefreshToken): self
  467.     {
  468.         $this->appleRefreshToken $appleRefreshToken;
  469.         return $this;
  470.     }
  471.     public function getGoogleIntegration(): ?bool
  472.     {
  473.         return $this->googleIntegration;
  474.     }
  475.     public function setGoogleIntegration(?bool $googleIntegration): self
  476.     {
  477.         $this->googleIntegration $googleIntegration;
  478.         return $this;
  479.     }
  480.     public function getTermsAcceptedAt(): ?\DateTimeInterface
  481.     {
  482.         return $this->termsAcceptedAt;
  483.     }
  484.     public function setTermsAcceptedAt(?\DateTimeInterface $termsAcceptedAt): self
  485.     {
  486.         $this->termsAcceptedAt $termsAcceptedAt;
  487.         return $this;
  488.     }
  489.     public function getPhone(): ?string
  490.     {
  491.         return $this->phone;
  492.     }
  493.     public function setPhone(?string $phone): self
  494.     {
  495.         $this->phone $phone;
  496.         return $this;
  497.     }
  498.     public function getMobile(): ?string
  499.     {
  500.         return $this->mobile;
  501.     }
  502.     public function setMobile(?string $mobile): self
  503.     {
  504.         $this->mobile $mobile;
  505.         return $this;
  506.     }
  507.     public function getVat(): ?string
  508.     {
  509.         return $this->vat;
  510.     }
  511.     public function setVat(?string $vat): self
  512.     {
  513.         $this->vat $vat;
  514.         return $this;
  515.     }
  516.     /**
  517.      * @return Collection|StdWebUsersAddresses[]
  518.      */
  519.     public function getAddresses(): Collection
  520.     {
  521.         return $this->addresses;
  522.     }
  523.     public function removeAddress(StdWebUsersAddresses $address): self
  524.     {
  525.         if ($this->addresses->contains($address)) {
  526.             $this->addresses->removeElement($address);
  527.             // set the owning side to null (unless already changed)
  528.             if ($address->getWebuser() === $this) {
  529.                 $address->setWebuser(null);
  530.             }
  531.         }
  532.         return $this;
  533.     }
  534.     public function addAddress(StdWebUsersAddresses $address): self
  535.     {
  536.         if (!$this->addresses->contains($address)) {
  537.             $this->addresses[] = $address;
  538.             $address->setWebuser($this);
  539.         }
  540.         return $this;
  541.     }
  542.     public function getUpdatedBy(): ?\App\Admin\Entity\StdUsers
  543.     {
  544.         return $this->updatedBy;
  545.     }
  546.     public function setUpdatedBy(?StdUsers $updatedBy): self
  547.     {
  548.         $this->updatedBy $updatedBy;
  549.         return $this;
  550.     }
  551.     public function getCreatedBy(): ?\App\Admin\Entity\StdUsers
  552.     {
  553.         return $this->createdBy;
  554.     }
  555.     public function setCreatedBy(?StdUsers $createdBy): self
  556.     {
  557.         $this->createdBy $createdBy;
  558.         return $this;
  559.     }
  560.     public function eraseCredentials(){
  561.         return true;
  562.     }
  563.     #[ORM\PreUpdate]
  564.     public function setUpdated()
  565.     {
  566.         $newroles = [];
  567.         if (is_array(($roles $this->getRoles())))
  568.             foreach ($roles as $role)
  569.                 if ($role instanceof StdWebRoles)
  570.                     $newroles[] = $role->getName();
  571.                 else
  572.                     $newroles[] = $role;
  573.         $this->roles=$newroles;
  574.         $this->setUpdatedDate(new \DateTime());
  575.     }
  576.     
  577.     #[ORM\PrePersist]
  578.     public function setCreated()
  579.     {
  580.         $newroles = [];
  581.         if (is_array(($roles $this->getRoles())))
  582.             foreach ($roles as $role)
  583.                 if ($role instanceof StdWebRoles)
  584.                     $newroles[] = $role->getName();
  585.                 else
  586.                     $newroles[] = $role;
  587.         $this->roles=$newroles;
  588.         $this->setUpdatedDate(new \DateTime());
  589.         $this->setCreatedDate(new \DateTime());
  590.     }
  591.     public function getSalt(): ?string
  592.     {
  593.         return null;
  594.     }
  595.     public function jsonSerialize(): mixed
  596.     {
  597.         $result get_object_vars($this);
  598.         $result['addresses']=[];
  599.         foreach ($this->getAddresses() as $address)
  600.         {
  601.             $result["addresses"][]=$address->jsonSerialize();
  602.         }
  603.         return $result;
  604.     }
  605.     /**
  606.      * @return Collection<int, StdPagesTracking>
  607.      */
  608.     public function getPageTrackings(): Collection
  609.     {
  610.         return $this->pageTrackings;
  611.     }
  612.     public function addPageTracking(StdPagesTracking $pageTracking): static
  613.     {
  614.         if (!$this->pageTrackings->contains($pageTracking)) {
  615.             $this->pageTrackings->add($pageTracking);
  616.             $pageTracking->setWebUser($this);
  617.         }
  618.         return $this;
  619.     }
  620.     public function removePageTracking(StdPagesTracking $pageTracking): static
  621.     {
  622.         if ($this->pageTrackings->removeElement($pageTracking)) {
  623.             // set the owning side to null (unless already changed)
  624.             if ($pageTracking->getWebUser() === $this) {
  625.                 $pageTracking->setWebUser(null);
  626.             }
  627.         }
  628.         return $this;
  629.     }
  630. }