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\DBAL\Types\Types;
  7. use Doctrine\ORM\Mapping as ORM;
  8. use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
  9. use Symfony\Component\Security\Core\User\UserInterface;
  10. use Symfony\Component\Serializer\Annotation\Groups;
  11. #[ORM\Entity(repositoryClassUserRepository::class)]
  12. #[ORM\Table(name'`user`')]
  13. class User implements UserInterfacePasswordAuthenticatedUserInterface
  14. {
  15.     public const TYPE_ADMIN "ADMIN";
  16.     public const TYPE_USER "USER";
  17.     #[ORM\Id]
  18.     #[ORM\GeneratedValue]
  19.     #[ORM\Column(type'integer')]
  20.     #[Groups(['list'])]
  21.     private ?int $id;
  22.     #[ORM\Column(type'string'length180uniquetrue)]
  23.     #[Groups(['list'])]
  24.     private ?string $email;
  25.     #[ORM\Column(type'boolean')]
  26.     #[Groups(['list'])]
  27.     private ?string $superUser;
  28.     #[ORM\Column(type'string'length10)]
  29.     #[Groups(['list'])]
  30.     private ?string $userType;
  31.     #[ORM\Column(type'json')]
  32.     private array $roles = [];
  33.     #[ORM\Column(type'string')]
  34.     private string $password;
  35.     #[ORM\Column(type'datetime')]
  36.     private ?\DateTimeInterface $timeCreated;
  37.     #[ORM\Column(type'boolean')]
  38.     private ?bool $isDeleted;
  39.     #[ORM\OneToOne(mappedBy'user'targetEntityUserInfo::class)]
  40.     private ?UserInfo $userInfo;
  41.     #[ORM\ManyToMany(targetEntityUserGroup::class)]
  42.     #[ORM\JoinTable(name'users_groups')]
  43.     private $groups;
  44.     #[ORM\ManyToMany(targetEntityDepartment::class)]
  45.     #[ORM\JoinTable(name'users_departments')]
  46.     private $departments;
  47.     #[ORM\ManyToMany(targetEntityDegree::class)]
  48.     #[ORM\JoinTable(name'users_degrees')]
  49.     private $degrees;
  50.     #[ORM\ManyToMany(targetEntityGlobalConstant::class)]
  51.     #[ORM\JoinTable(name'users_global_constants')]
  52.     private $globalConstants;
  53.     #[ORM\ManyToMany(targetEntitySector::class)]
  54.     #[ORM\JoinTable(name'users_sectors')]
  55.     private $sectors;
  56.     public function __construct()
  57.     {
  58.         $this->groups = new ArrayCollection();
  59.         $this->departments = new ArrayCollection();
  60.         $this->degrees = new ArrayCollection();
  61.         $this->globalConstants = new ArrayCollection();
  62.         $this->sectors = new ArrayCollection();
  63.     }
  64.     public function getId(): ?int
  65.     {
  66.         return $this->id;
  67.     }
  68.     public function getEmail(): ?string
  69.     {
  70.         return $this->email;
  71.     }
  72.     public function setEmail(string $email): self
  73.     {
  74.         $this->email $email;
  75.         return $this;
  76.     }
  77.     /**
  78.      * A visual identifier that represents this user.
  79.      *
  80.      * @see UserInterface
  81.      */
  82.     public function getUserIdentifier(): string
  83.     {
  84.         return (string)$this->email;
  85.     }
  86.     /**
  87.      * @see UserInterface
  88.      */
  89.     public function getRoles(): array
  90.     {
  91.         $roles $this->roles;
  92.         // guarantee every user at least has ROLE_USER
  93.         $roles[] = 'ROLE_USER';
  94.         if ($this->userType === self::TYPE_ADMIN) {
  95.             $roles[] = 'ROLE_ADMIN';
  96.             if ($this->getSuperUser()) {
  97.                 $roles[] = 'ROLE_SUPER_USER';
  98.             }
  99.             foreach ($this->getGroups() as $group) {
  100.                 foreach ($group->getRoles() as $role) {
  101.                     $roles[] = 'ROLE_' $role;
  102.                 }
  103.             }
  104.         }
  105.         return array_unique($roles);
  106.     }
  107.     public function setRoles(array $roles): self
  108.     {
  109.         $this->roles $roles;
  110.         return $this;
  111.     }
  112.     /**
  113.      * @see PasswordAuthenticatedUserInterface
  114.      */
  115.     public function getPassword(): string
  116.     {
  117.         return $this->password;
  118.     }
  119.     public function setPassword(string $password): self
  120.     {
  121.         $this->password $password;
  122.         return $this;
  123.     }
  124.     /**
  125.      * @see UserInterface
  126.      */
  127.     public function eraseCredentials()
  128.     {
  129.         // If you store any temporary, sensitive data on the user, clear it here
  130.         // $this->plainPassword = null;
  131.     }
  132.     public function getTimeCreated(): ?\DateTimeInterface
  133.     {
  134.         return $this->timeCreated;
  135.     }
  136.     public function setTimeCreated(\DateTimeInterface $timeCreated): self
  137.     {
  138.         $this->timeCreated $timeCreated;
  139.         return $this;
  140.     }
  141.     public function getIsDeleted(): ?bool
  142.     {
  143.         return $this->isDeleted;
  144.     }
  145.     public function setIsDeleted(bool $isDeleted): self
  146.     {
  147.         $this->isDeleted $isDeleted;
  148.         return $this;
  149.     }
  150.     public function getUserType(): ?string
  151.     {
  152.         return $this->userType;
  153.     }
  154.     public function setUserType(string $userType): self
  155.     {
  156.         $this->userType $userType;
  157.         return $this;
  158.     }
  159.     /**
  160.      * @return Collection<int, UserGroup>
  161.      */
  162.     public function getGroups(): Collection
  163.     {
  164.         return $this->groups;
  165.     }
  166.     public function addGroup(UserGroup $group): self
  167.     {
  168.         if (!$this->groups->contains($group)) {
  169.             $this->groups[] = $group;
  170.         }
  171.         return $this;
  172.     }
  173.     public function removeGroup(UserGroup $group): self
  174.     {
  175.         $this->groups->removeElement($group);
  176.         return $this;
  177.     }
  178.     public function getSuperUser(): ?bool
  179.     {
  180.         return $this->superUser;
  181.     }
  182.     public function setSuperUser(bool $superUser): self
  183.     {
  184.         $this->superUser $superUser;
  185.         return $this;
  186.     }
  187.     public function getUserInfo(): ?UserInfo
  188.     {
  189.         return $this->userInfo;
  190.     }
  191.     public function setUserInfo(?UserInfo $userInfo): self
  192.     {
  193.         // unset the owning side of the relation if necessary
  194.         if ($userInfo === null && $this->userInfo !== null) {
  195.             $this->userInfo->setUser(null);
  196.         }
  197.         // set the owning side of the relation if necessary
  198.         if ($userInfo !== null && $userInfo->getUser() !== $this) {
  199.             $userInfo->setUser($this);
  200.         }
  201.         $this->userInfo $userInfo;
  202.         return $this;
  203.     }
  204.     public function isSuperUser(): ?bool
  205.     {
  206.         return $this->superUser;
  207.     }
  208.     public function isIsDeleted(): ?bool
  209.     {
  210.         return $this->isDeleted;
  211.     }
  212.     /**
  213.      * @return Collection<int, Department>
  214.      */
  215.     public function getDepartments(): Collection
  216.     {
  217.         return $this->departments;
  218.     }
  219.     public function addDepartment(Department $department): self
  220.     {
  221.         if (!$this->departments->contains($department)) {
  222.             $this->departments[] = $department;
  223.         }
  224.         return $this;
  225.     }
  226.     public function removeDepartment(Department $department): self
  227.     {
  228.         $this->departments->removeElement($department);
  229.         return $this;
  230.     }
  231.     /**
  232.      * @return Collection<int, Degree>
  233.      */
  234.     public function getDegrees(): Collection
  235.     {
  236.         return $this->degrees;
  237.     }
  238.     public function addDegree(Degree $degree): self
  239.     {
  240.         if (!$this->degrees->contains($degree)) {
  241.             $this->degrees->add($degree);
  242.         }
  243.         return $this;
  244.     }
  245.     public function removeDegree(Degree $degree): self
  246.     {
  247.         $this->degrees->removeElement($degree);
  248.         return $this;
  249.     }
  250.     /**
  251.      * @return Collection<int, GlobalConstant>
  252.      */
  253.     public function getGlobalConstant(): Collection
  254.     {
  255.         return $this->globalConstants;
  256.     }
  257.     public function addGlobalConstant(GlobalConstant $globalConstant): self
  258.     {
  259.         if (!$this->globalConstants->contains($globalConstant)) {
  260.             $this->globalConstants->add($globalConstant);
  261.         }
  262.         return $this;
  263.     }
  264.     public function removeGlobalConstant(GlobalConstant $globalConstant): self
  265.     {
  266.         $this->globalConstants->removeElement($globalConstant);
  267.         return $this;
  268.     }
  269.     /**
  270.      * @return Collection<int, GlobalConstant>
  271.      */
  272.     public function getGlobalConstants(): Collection
  273.     {
  274.         return $this->globalConstants;
  275.     }
  276.     /**
  277.      * @return Collection<int, Sector>
  278.      */
  279.     public function getSector(): Collection
  280.     {
  281.         return $this->sector;
  282.     }
  283.     public function addSector(Sector $sector): self
  284.     {
  285.         if (!$this->sector->contains($sector)) {
  286.             $this->sector->add($sector);
  287.         }
  288.         return $this;
  289.     }
  290.     public function removeSector(Sector $sector): self
  291.     {
  292.         $this->sector->removeElement($sector);
  293.         return $this;
  294.     }
  295.     /**
  296.      * @return Collection<int, Sector>
  297.      */
  298.     public function getSectors(): Collection
  299.     {
  300.         return $this->sectors;
  301.     }
  302. }