src/Entity/User.php line 16

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\UserRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use Doctrine\ORM\Mapping\JoinColumn;
  8. use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
  9. use Symfony\Component\Security\Core\User\UserInterface;
  10. #[ORM\Entity(repositoryClassUserRepository::class)]
  11. #[ORM\Table(name'tb_users')]
  12. #[ORM\HasLifecycleCallbacks]
  13. class User implements UserInterfacePasswordAuthenticatedUserInterface
  14. {
  15.     #[ORM\Id]
  16.     #[ORM\GeneratedValue]
  17.     #[ORM\Column(type"integer"uniquetrue)]
  18.     private ?int $id;
  19.     #[ORM\Column(type'string'length50nullablefalse)]
  20.     private ?string $code;
  21.     #[ORM\Column(type'string'length100nullabletrue)]
  22.     private $username;
  23.     #[ORM\Column(type'string'length100nullabletrue)]
  24.     private ?string $password;
  25.     #[ORM\Column(type'string'length100nullabletrue)]
  26.     private ?string $name;
  27.     #[ORM\Column(type'boolean'nullabletrue)]
  28.     private ?bool $activated;
  29.     #[ORM\Column(type'datetime'nullablefalse)]
  30.     private \DateTimeInterface $createdAt;
  31.     #[ORM\Column(type'datetime'nullabletrue)]
  32.     private ?\DateTimeInterface $modifiedAt;
  33.     #[ORM\ManyToMany(targetEntityRole::class, inversedBy"users")]
  34.     #[ORM\JoinTable(name'tb_users_roles')]
  35.     #[ORM\JoinColumn(name'users_id'referencedColumnName'id')]
  36.     #[ORM\InverseJoinColumn(name'roles_id'referencedColumnName'id')]
  37.     private Collection $rls;
  38.     #[ORM\ManyToOne(targetEntityUser::class)]
  39.     private ?User $createdBy;
  40.     #[ORM\OneToMany(mappedBy"createdBy"targetEntityAgency::class)]
  41.     private Collection $agencies;
  42.     #[ORM\OneToMany(mappedBy"createdBy"targetEntityAgencyAccountType::class)]
  43.     private Collection $agencyAccountTypes;
  44.     #[ORM\OneToMany(mappedBy"createdBy"targetEntityAgencyAccount::class)]
  45.     private Collection $agencyAccounts;
  46.     public function __construct()
  47.     {
  48.         $this->createdAt = new \DateTime();
  49.         $this->rls = new ArrayCollection();
  50.         $this->agencies = new ArrayCollection();
  51.         $this->agencyAccountTypes = new ArrayCollection();
  52.         $this->agencyAccounts = new ArrayCollection();
  53.     }
  54.     public function getId(): ?int
  55.     {
  56.         return $this->id;
  57.     }
  58.     public function getCode(): ?string
  59.     {
  60.         return $this->code;
  61.     }
  62.     public function setCode(string $code): self
  63.     {
  64.         $this->code $code;
  65.         return $this;
  66.     }
  67.     public function getUsername(): ?string
  68.     {
  69.         return $this->username;
  70.     }
  71.     public function setUsername(string $username): self
  72.     {
  73.         $this->username $username;
  74.         return $this;
  75.     }
  76.     public function getPassword(): ?string
  77.     {
  78.         return $this->password;
  79.     }
  80.     public function setPassword(string $password): self
  81.     {
  82.         $this->password $password;
  83.         return $this;
  84.     }
  85.     public function getName(): ?string
  86.     {
  87.         return $this->name;
  88.     }
  89.     public function setName(string $name): self
  90.     {
  91.         $this->name $name;
  92.         return $this;
  93.     }
  94.     public function getActivated(): ?bool
  95.     {
  96.         return $this->activated;
  97.     }
  98.     public function setActivated(?bool $activated): self
  99.     {
  100.         $this->activated $activated;
  101.         return $this;
  102.     }
  103.     public function getCreatedAt(): ?\DateTimeInterface
  104.     {
  105.         return $this->createdAt;
  106.     }
  107.     public function setCreatedAt(?\DateTimeInterface $createdAt): self
  108.     {
  109.         $this->createdAt $createdAt;
  110.         return $this;
  111.     }
  112.     public function getModifiedAt(): ?\DateTimeInterface
  113.     {
  114.         return $this->modifiedAt;
  115.     }
  116.     public function setModifiedAt(?\DateTimeInterface $modifiedAt): self
  117.     {
  118.         $this->modifiedAt $modifiedAt;
  119.         return $this;
  120.     }
  121.     public function getRoles()
  122.     {
  123.         $rs = array();
  124.         foreach ($this->getRls()->toArray() as $role)
  125.             $rs[] = 'ROLE_'.$role->getName();
  126.         return $rs;
  127.     }
  128.     public function addRole(Role $role): self
  129.     {
  130.         if (!$this->rls->contains($role)) {
  131.             $this->rls[] = $role;
  132.         }
  133.         return $this;
  134.     }
  135.     public function removeRole(Role $role): self
  136.     {
  137.         $this->rls->removeElement($role);
  138.         return $this;
  139.     }
  140.     /**
  141.      * @return Collection|Role[]
  142.      */
  143.     public function getRls()
  144.     {
  145.         return $this->rls;
  146.     }
  147.     public function getCreatedBy(): ?self
  148.     {
  149.         return $this->createdBy;
  150.     }
  151.     public function setCreatedBy(?self $createdBy): self
  152.     {
  153.         $this->createdBy $createdBy;
  154.         return $this;
  155.     }
  156.     public function getSalt()
  157.     {
  158.         return null;
  159.     }
  160.     public function eraseCredentials()
  161.     {
  162.         // TODO: Implement eraseCredentials() method.
  163.     }
  164.     public function __call($name$arguments)
  165.     {
  166.         // TODO: Implement @method string getUserIdentifier()
  167.     }
  168.     /**
  169.      *
  170.      * @see UserInterface
  171.      */
  172.     public function getUserIdentifier(): string
  173.     {
  174.         return (string) $this->username;
  175.     }
  176.     /**
  177.      * @ORM\PreUpdate
  178.      */
  179.     public function onUpdate() {
  180.         $this->modifiedAt = new \DateTime();
  181.     }
  182.     /**
  183.      * @return Collection|Agency[]
  184.      */
  185.     public function getAgencies(): Collection
  186.     {
  187.         return $this->agencies;
  188.     }
  189.     public function addAgency(Agency $agency): self
  190.     {
  191.         if (!$this->agencies->contains($agency)) {
  192.             $this->agencies[] = $agency;
  193.             $agency->setCreatedBy($this);
  194.         }
  195.         return $this;
  196.     }
  197.     public function removeAgency(Agency $agency): self
  198.     {
  199.         if ($this->agencies->removeElement($agency)) {
  200.             // set the owning side to null (unless already changed)
  201.             if ($agency->getCreatedBy() === $this) {
  202.                 $agency->setCreatedBy(null);
  203.             }
  204.         }
  205.         return $this;
  206.     }
  207.     /**
  208.      * @return Collection|AgencyAccountType[]
  209.      */
  210.     public function getAgencyAccountTypes(): Collection
  211.     {
  212.         return $this->agencyAccountTypes;
  213.     }
  214.     public function addAgencyAccountType(AgencyAccountType $agencyAccountType): self
  215.     {
  216.         if (!$this->agencyAccountTypes->contains($agencyAccountType)) {
  217.             $this->agencyAccountTypes[] = $agencyAccountType;
  218.             $agencyAccountType->setCreatedBy($this);
  219.         }
  220.         return $this;
  221.     }
  222.     public function removeAgencyAccountType(AgencyAccountType $agencyAccountType): self
  223.     {
  224.         if ($this->agencyAccountTypes->removeElement($agencyAccountType)) {
  225.             // set the owning side to null (unless already changed)
  226.             if ($agencyAccountType->getCreatedBy() === $this) {
  227.                 $agencyAccountType->setCreatedBy(null);
  228.             }
  229.         }
  230.         return $this;
  231.     }
  232.     /**
  233.      * @return Collection|AgencyAccount[]
  234.      */
  235.     public function getAgencyAccounts(): Collection
  236.     {
  237.         return $this->agencyAccounts;
  238.     }
  239.     public function addAgencyAccount(AgencyAccount $agencyAccount): self
  240.     {
  241.         if (!$this->agencyAccounts->contains($agencyAccount)) {
  242.             $this->agencyAccounts[] = $agencyAccount;
  243.             $agencyAccount->setCreatedBy($this);
  244.         }
  245.         return $this;
  246.     }
  247.     public function removeAgencyAccount(AgencyAccount $agencyAccount): self
  248.     {
  249.         if ($this->agencyAccounts->removeElement($agencyAccount)) {
  250.             // set the owning side to null (unless already changed)
  251.             if ($agencyAccount->getCreatedBy() === $this) {
  252.                 $agencyAccount->setCreatedBy(null);
  253.             }
  254.         }
  255.         return $this;
  256.     }
  257. }