src/Admin/Entity/StdUsers.php line 19

Open in your IDE?
  1. <?php
  2. namespace App\Admin\Entity;
  3. use Doctrine\Common\Collections\ArrayCollection;
  4. use Doctrine\Common\Collections\Collection;
  5. use Doctrine\ORM\Mapping as ORM;
  6. use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
  7. use Symfony\Component\Security\Core\User\UserInterface;
  8. use Symfony\Component\Validator\Constraints as Assert;
  9. /**
  10.  * StdUsers
  11.  */
  12. #[ORM\Table(name'std_users')]
  13. #[ORM\Index(name'fk_std_users_std_users'columns: ['created_by'])]
  14. #[ORM\Index(name'fk_std_users_std_users_upd'columns: ['updated_by'])]
  15. #[ORM\Entity(repositoryClass'App\Admin\Repository\StdUsersRepository')]
  16. #[ORM\HasLifecycleCallbacks]
  17. class StdUsers implements UserInterface/*, \Serializable*/PasswordAuthenticatedUserInterface
  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
  38.      */
  39.     #[Assert\Email]
  40.     #[ORM\Column(name'email'type'string'length254nullablefalseoptions: ['comment' => 'Email address of the user'])]
  41.     private $email;
  42.     /**
  43.      * @var string
  44.      */
  45.     #[ORM\Column(name'password'type'string'length255nullablefalseoptions: ['comment' => "User's password"])]
  46.     private $password;
  47.     /**
  48.      * @var \DateTime|null
  49.      */
  50.     #[ORM\Column(name'password_date'type'datetime'nullabletrueoptions: ['comment' => 'Last date and time the password was updated'])]
  51.     private $passwordDate;
  52.     /**
  53.      * @var int|null
  54.      */
  55.     #[ORM\Column(name'failed_attempts'type'integer'nullabletrueoptions: ['unsigned' => true'comment' => 'Number of failed login attempts'])]
  56.     private $failedAttempts '0';
  57.     /**
  58.      * @var bool|null
  59.      */
  60.     #[ORM\Column(name'force_password_change'type'boolean'nullabletrueoptions: ['comment' => 'Flag to force the user to change the password on the next login'])]
  61.     private $forcePasswordChange;
  62.     /**
  63.      * @var \DateTime|null
  64.      */
  65.     #[ORM\Column(name'last_login_date'type'datetime'nullabletrueoptions: ['comment' => 'Date and time of the last successful login'])]
  66.     private $lastLoginDate;
  67.     /**
  68.      * @var \DateTime|null
  69.      */
  70.     #[ORM\Column(name'penultimate_login_date'type'datetime'nullabletrueoptions: ['comment' => 'Date and time of the penultimate successful login'])]
  71.     private $penultimateLoginDate;
  72.     /**
  73.      * @var string|null
  74.      */
  75.     #[ORM\Column(name'language'type'string'length3nullabletrueoptions: ['comment' => "Preferred user interface's language code"])]
  76.     private $language;
  77.     /**
  78.      * @var bool
  79.      */
  80.     #[ORM\Column(name'is_locked'type'boolean'nullablefalseoptions: ['comment' => 'Flag to lock the user'])]
  81.     private $isLocked '0';
  82.     /**
  83.      * @var bool
  84.      */
  85.     #[ORM\Column(name'is_super_user'type'boolean'nullablefalseoptions: ['comment' => 'Flag indicating super user privileges'])]
  86.     private $isSuperUser '0';
  87.     /**
  88.      * @var bool
  89.      */
  90.     #[ORM\Column(name'is_deleted'type'boolean'nullablefalseoptions: ['comment' => 'Flag that indicates the user has been deleted'])]
  91.     private $isDeleted '0';
  92.     /**
  93.      * @var bool
  94.      */
  95.     #[ORM\Column(name'is_active'type'boolean'nullablefalseoptions: ['default' => 1'comment' => 'Flag that indicates if the user is active'])]
  96.     private $isActive '1';
  97.     /**
  98.      * @var \DateTime
  99.      */
  100.     #[ORM\Column(name'created_date'type'datetime'nullablefalseoptions: ['comment' => 'Date and time of the record creation'])]
  101.     private $createdDate;
  102.     /**
  103.      * @var \DateTime
  104.      */
  105.     #[ORM\Column(name'updated_date'type'datetime'nullablefalseoptions: ['comment' => 'Date and time the record was last updated'])]
  106.     private $updatedDate;
  107.     /**
  108.      * @var \App\Admin\Entity\StdUsers
  109.      */
  110.     #[ORM\JoinColumn(name'created_by'referencedColumnName'id')]
  111.     #[ORM\ManyToOne(targetEntity'\App\Admin\Entity\StdUsers')]
  112.     private $createdBy;
  113.     /**
  114.      * @var \App\Admin\Entity\StdUsers
  115.      */
  116.     #[ORM\JoinColumn(name'updated_by'referencedColumnName'id')]
  117.     #[ORM\ManyToOne(targetEntity'\App\Admin\Entity\StdUsers')]
  118.     private $updatedBy;
  119.      /**
  120.      * @var Doctrine\Common\Collections\ArrayCollection|null
  121.      */
  122.     #[ORM\OneToMany(targetEntity'StdFavoritePagesUsers'mappedBy'userId'cascade: ['persist''remove'], orphanRemovaltruefetch'EXTRA_LAZY')]
  123.     private $favoritePages;
  124.     #[ORM\ManyToMany(targetEntityStdRoles::class, inversedBy'users')]
  125.     private Collection $userRoles;
  126.     /**
  127.      * @var Collection<int, StdPages>
  128.      */
  129.     #[ORM\ManyToMany(targetEntityStdPages::class, mappedBy'pageAuthors')]
  130.     #[ORM\JoinTable(name'std_pages_authors')]
  131.     private Collection $authoredPages;
  132.     /**
  133.      * @var string|null
  134.      */
  135.     #[ORM\Column(name'author_function'type'string'length2048nullabletrueoptions: ['comment' => 'User function/role when authoring pages'])]
  136.     private $authorFunction;
  137.     /**
  138.      * @var string|null
  139.      */
  140.     #[ORM\Column(name'user_image'type'string'length255nullabletrueoptions: ['comment' => 'User avatar image'])]
  141.     private $userImage;
  142.     public function __construct()
  143.     {
  144.         $this->userRoles = new ArrayCollection();
  145.         $this->authoredPages = new ArrayCollection();
  146.     }
  147.     /**
  148.      * @param bool $firewallCall this must be true if used to validate user roles on Symfony's native code, otherwise it'll return a Collection and Symfony will be mad
  149.      * @return array|Collection<int, StdRoles> this will return either an array or a Collection, depending on how the parameter above is setup
  150.      */
  151.     public function getRoles(bool $firewallCall true): array|Collection
  152.     {
  153.         if ($firewallCall) {
  154.             $roleArray = [];
  155.             foreach ($this->userRoles as $role) {
  156.                 if ($role->getIsActive()) {
  157.                     $roleArray[] = $role->getName();
  158.                 }
  159.             }
  160.             if (empty($roleArray)) {
  161.                 $roleArray[] = 'ROLE_ADMIN';
  162.             } 
  163.         } else {
  164.             $roleArray $this->userRoles;
  165.         }
  166.         return $roleArray;
  167.     }
  168.     /**
  169.      * @return Collection<int, StdRoles> this will return a Collection
  170.      */
  171.     public function getUserRoles(): array|Collection
  172.     {
  173.         return $this->userRoles;
  174.     }
  175.     public function getId(): ?int
  176.     {
  177.         return $this->id;
  178.     }
  179.     public function getName(): ?string
  180.     {
  181.         return $this->name;
  182.     }
  183.     public function setName(?string $name): self
  184.     {
  185.         $this->name $name;
  186.         return $this;
  187.     }
  188.     public function getUsername(): ?string
  189.     {
  190.         return $this->username;
  191.     }
  192.     public function getUserIdentifier(): string
  193.     {
  194.         return (string) $this->username;
  195.     }
  196.     public function setUsername(string $username): self
  197.     {
  198.         $this->username $username;
  199.         return $this;
  200.     }
  201.     public function getEmail(): ?string
  202.     {
  203.         return $this->email;
  204.     }
  205.     public function setEmail(string $email): self
  206.     {
  207.         $this->email $email;
  208.         return $this;
  209.     }
  210.     public function getPassword(): ?string
  211.     {
  212.         return $this->password;
  213.     }
  214.     public function setPassword(string $password): self
  215.     {
  216.         $this->password $password;
  217.         return $this;
  218.     }
  219.     public function getPasswordDate(): ?\DateTimeInterface
  220.     {
  221.         return $this->passwordDate;
  222.     }
  223.     public function setPasswordDate(?\DateTimeInterface $passwordDate): self
  224.     {
  225.         $this->passwordDate $passwordDate;
  226.         return $this;
  227.     }
  228.     public function getFailedAttempts(): ?int
  229.     {
  230.         return $this->failedAttempts;
  231.     }
  232.     public function setFailedAttempts(?int $failedAttempts): self
  233.     {
  234.         $this->failedAttempts $failedAttempts;
  235.         return $this;
  236.     }
  237.     public function getForcePasswordChange(): ?bool
  238.     {
  239.         return $this->forcePasswordChange;
  240.     }
  241.     public function setForcePasswordChange(?bool $forcePasswordChange): self
  242.     {
  243.         $this->forcePasswordChange $forcePasswordChange;
  244.         return $this;
  245.     }
  246.     public function getLastLoginDate(): ?\DateTimeInterface
  247.     {
  248.         return $this->lastLoginDate;
  249.     }
  250.     public function setLastLoginDate(?\DateTimeInterface $lastLoginDate): self
  251.     {
  252.         $this->lastLoginDate $lastLoginDate;
  253.         return $this;
  254.     }
  255.     public function getPenultimateLoginDate(): ?\DateTimeInterface
  256.     {
  257.         return $this->penultimateLoginDate;
  258.     }
  259.     public function setPenultimateLoginDate(?\DateTimeInterface $penultimateLoginDate): self
  260.     {
  261.         $this->penultimateLoginDate $penultimateLoginDate;
  262.         return $this;
  263.     }
  264.     public function getLanguage(): ?string
  265.     {
  266.         return $this->language;
  267.     }
  268.     public function setLanguage(?string $language): self
  269.     {
  270.         $this->language $language;
  271.         return $this;
  272.     }
  273.     public function getIsLocked(): ?bool
  274.     {
  275.         return $this->isLocked;
  276.     }
  277.     public function setIsLocked(bool $isLocked): self
  278.     {
  279.         $this->isLocked $isLocked;
  280.         return $this;
  281.     }
  282.     public function getIsSuperUser(): ?bool
  283.     {
  284.         return $this->isSuperUser;
  285.     }
  286.     public function setIsSuperUser(bool $isSuperUser): self
  287.     {
  288.         $this->isSuperUser $isSuperUser;
  289.         return $this;
  290.     }
  291.     public function getIsDeleted(): ?bool
  292.     {
  293.         return $this->isDeleted;
  294.     }
  295.     public function setIsDeleted(bool $isDeleted): self
  296.     {
  297.         $this->isDeleted $isDeleted;
  298.         return $this;
  299.     }
  300.     public function getIsActive(): ?bool
  301.     {
  302.         return $this->isActive;
  303.     }
  304.     public function setIsActive(bool $isActive): self
  305.     {
  306.         $this->isActive $isActive;
  307.         return $this;
  308.     }
  309.     public function getCreatedDate(): ?\DateTimeInterface
  310.     {
  311.         return $this->createdDate;
  312.     }
  313.     public function setCreatedDate(\DateTimeInterface $createdDate): self
  314.     {
  315.         $this->createdDate $createdDate;
  316.         return $this;
  317.     }
  318.     public function getUpdatedDate(): ?\DateTimeInterface
  319.     {
  320.         return $this->updatedDate;
  321.     }
  322.     public function setUpdatedDate(\DateTimeInterface $updatedDate): self
  323.     {
  324.         $this->updatedDate $updatedDate;
  325.         return $this;
  326.     }
  327.     public function getCreatedBy(): ?\App\Admin\Entity\StdUsers
  328.     {
  329.         return $this->createdBy;
  330.     }
  331.     public function setCreatedBy(?self $createdBy): self
  332.     {
  333.         $this->createdBy $createdBy;
  334.         return $this;
  335.     }
  336.     public function getUpdatedBy(): ?self
  337.     {
  338.         return $this->updatedBy;
  339.     }
  340.     public function setUpdatedBy(?self $updatedBy): self
  341.     {
  342.         $this->updatedBy $updatedBy;
  343.         return $this;
  344.     }
  345.  
  346.     public function getSalt(): ?string
  347.     {
  348.         return null;
  349.     }
  350.     public function eraseCredentials()
  351.     {
  352.         // If you store any temporary, sensitive data on the user, clear it here
  353.         // $this->plainPassword = null;
  354.     }
  355.     #[ORM\PreUpdate]
  356.     public function setUpdated()
  357.     {
  358.         $this->setUpdatedDate(new \DateTime());
  359.     }
  360.     #[ORM\PrePersist]
  361.     public function setCreated()
  362.     {
  363.         $this->setUpdatedDate(new \DateTime());
  364.         $this->setCreatedDate(new \DateTime());
  365.     }
  366.     /**
  367.      * Get the value of favoritePage
  368.      *
  369.      * @return  object
  370.      */ 
  371.     public function getFavoritePage()
  372.     {
  373.         return $this->favoritePages;
  374.     }
  375.     /**
  376.      * Set the value of favoritePage
  377.      *
  378.      * @param  Page  $favoritePage
  379.      *
  380.      * @return  self
  381.      */ 
  382.     public function setFavoritePage(object $favoritePage)
  383.     {
  384.         $this->favoritePages $favoritePage;
  385.         return $this;
  386.     }
  387.     /** Function serialize is here to solve "Notice: unserialize(): Error at offset" on php version 7.3 */
  388.     /*public function serialize()
  389.     {
  390.         list($major, $minor, $release) = explode(".", phpversion());
  391.         $vars = get_object_vars($this);
  392.         if ($major == 7 && $minor == 3)
  393.         {
  394.             unset($vars["createdBy"]);
  395.             unset($vars["updatedBy"]);
  396.             unset($vars["favoritePages"]);
  397.         }
  398.         return serialize($vars);
  399.     }*/
  400.     /** Function unserialize is here to solve "Notice: unserialize(): Error at offset" on php version 7.3 */
  401.     /*public function unserialize($data)
  402.     {
  403.         $vars = unserialize($data);
  404.         foreach ($vars as $key => $value)
  405.         {
  406.             $this->$key = $value;
  407.         }
  408.     }*/
  409.     public function addUserRole(StdRoles $role): static
  410.     {
  411.         if (!$this->userRoles->contains($role)) {
  412.             $this->userRoles->add($role);
  413.         }
  414.         return $this;
  415.     }
  416.     public function removeUserRole(StdRoles $role): static
  417.     {
  418.         $this->userRoles->removeElement($role);
  419.         return $this;
  420.     }
  421.     public function isSuperAdmin(): bool
  422.     {
  423.         foreach ($this->getRoles() as $role) {
  424.             if ($role === "ROLE_SUPER_ADMIN") {
  425.                 return true;
  426.             }
  427.         }
  428.         return false;
  429.     }
  430.     /**
  431.      * @return Collection<int, StdPages>
  432.      */
  433.     public function getAuthoredPages(): Collection
  434.     {
  435.         return $this->authoredPages;
  436.     }
  437.     public function addAuthoredPage(StdPages $page): self
  438.     {
  439.         if (!$this->authoredPages->contains($page)) {
  440.             $this->authoredPages->add($page);
  441.         }
  442.         return $this;
  443.     }
  444.     public function removeAuthoredPage(StdPages $page): self
  445.     {
  446.         $this->authoredPages->removeElement($page);
  447.         return $this;
  448.     }
  449.     public function getAuthorFunction(): ?string
  450.     {
  451.         return $this->authorFunction;
  452.     }
  453.     public function setAuthorFunction(?string $authorFunction): self
  454.     {
  455.         $this->authorFunction $authorFunction;
  456.         return $this;
  457.     }
  458.     public function getUserImage(): ?string
  459.     {
  460.         return $this->userImage;
  461.     }
  462.     public function setUserImage(?string $userImage): self
  463.     {
  464.         $this->userImage $userImage;
  465.         return $this;
  466.     }
  467. }