src/Entity/AppUser.php line 16

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\AppUserRepository;
  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\PasswordAuthenticatedUserInterface;
  8. use Symfony\Component\Security\Core\User\UserInterface;
  9. /**
  10.  * @ORM\Entity(repositoryClass=AppUserRepository::class)
  11.  * @method string getUserIdentifier()
  12.  */
  13. class AppUser implements UserInterfacePasswordAuthenticatedUserInterface
  14. {
  15.     public function getSalt() : ?string
  16.     {
  17.         // TODO: Implement getSalt() method.
  18.         return '';
  19.     }
  20.     public function eraseCredentials()
  21.     {
  22.         // TODO: Implement eraseCredentials() method.
  23.     }
  24.     public function __call($name$arguments)
  25.     {
  26.         // TODO: Implement @method string getUserIdentifier()
  27.     }
  28.     /**
  29.      * @ORM\Id
  30.      * @ORM\GeneratedValue
  31.      * @ORM\Column(type="integer")
  32.      */
  33.     private $id;
  34.     /**
  35.      * @ORM\Column(type="string", length=255)
  36.      */
  37.     private $username;
  38.     /**
  39.      * @ORM\Column(type="string", length=255)
  40.      */
  41.     private $password;
  42.     private $roles = [];
  43.     /**
  44.      * @ORM\ManyToOne(targetEntity=Company::class, inversedBy="appUsers")
  45.      * @ORM\JoinColumn(nullable=false)
  46.      */
  47.     private $Company;
  48.     /**
  49.      * @ORM\OneToOne(targetEntity=Partner::class, inversedBy="userAccount", cascade={"persist", "remove"})
  50.      */
  51.     private $partner;
  52.     /**
  53.      * @ORM\ManyToMany(targetEntity=UserRole::class, mappedBy="users")
  54.      */
  55.     private $appRoles;
  56.     /**
  57.      * @ORM\OneToMany(targetEntity=ResNotification::class, mappedBy="destination", orphanRemoval=true)
  58.      */
  59.     private $notifications;
  60.     /**
  61.      * @ORM\OneToMany(targetEntity=ResRoleConfig::class, mappedBy="utilisateur", orphanRemoval=true)
  62.      */
  63.     private $resRoleConfigs;
  64.     /**
  65.      * @ORM\Column(type="boolean", nullable=true)
  66.      */
  67.     private $firstLogin;
  68.     /**
  69.      * @ORM\Column(type="string", length=255, nullable=true)
  70.      */
  71.     private $email;
  72.     public function __construct()
  73.     {
  74.         $this->appRoles = new ArrayCollection();
  75.         $this->notifications = new ArrayCollection();
  76.         $this->resRoleConfigs = new ArrayCollection();
  77.     }
  78.     public function getId(): ?int
  79.     {
  80.         return $this->id;
  81.     }
  82.     public function getUsername(): ?string
  83.     {
  84.         return $this->username;
  85.     }
  86.     public function getRolesName(): string
  87.     {
  88.         $appRoles $this->appRoles;
  89.         // guarantee every user at least has ROLE_USER
  90.         $roles = [] ;
  91.         foreach ($appRoles as $appRole) {
  92.             $roles[] = $appRole->getNomAr();
  93.         }
  94.         $roles array_unique($roles);
  95.         if ( count$roles) <= 0){
  96.             $roles[]= "مستخدم";
  97.         }
  98.         return implode(";"$roles);
  99.     }
  100.     /**
  101.      * @see UserInterface
  102.      */
  103.     public function getRoles(): array
  104.     {
  105.         $appRoles $this->appRoles;
  106.         // guarantee every user at least has ROLE_USER
  107.         $roles[] = 'ROLE_USER';
  108.         foreach ($appRoles as $appRole) {
  109.             $roles[] = $appRole->getRole();
  110.         }
  111.         return array_unique($roles);
  112.     }
  113.     public function setRoles(array $roles): self
  114.     {
  115.         $this->roles $roles;
  116.         return $this;
  117.     }
  118.     public function setUsername(string $username): self
  119.     {
  120.         $this->username $username;
  121.         return $this;
  122.     }
  123.     public function getPassword(): ?string
  124.     {
  125.         return $this->password;
  126.     }
  127.     public function setPassword(string $password): self
  128.     {
  129.         $this->password $password;
  130.         return $this;
  131.     }
  132.     public function getCompany(): ?Company
  133.     {
  134.         return $this->Company;
  135.     }
  136.     public function setCompany(?Company $Company): self
  137.     {
  138.         $this->Company $Company;
  139.         return $this;
  140.     }
  141.     public function getPartner(): ?Partner
  142.     {
  143.         return $this->partner;
  144.     }
  145.     public function setPartner(?Partner $partner): self
  146.     {
  147.         $this->partner $partner;
  148.         return $this;
  149.     }
  150.     /**
  151.      * @return Collection|UserRole[]
  152.      */
  153.     public function getAppRoles(): Collection
  154.     {
  155.         return $this->appRoles;
  156.     }
  157.     public function addRole(UserRole $role): self
  158.     {
  159.         if (!$this->appRoles->contains($role)) {
  160.             $this->appRoles[] = $role;
  161.             $role->addUser($this);
  162.         }
  163.         return $this;
  164.     }
  165.     public function removeRole(UserRole $role): self
  166.     {
  167.         if ($this->appRoles->removeElement($role)) {
  168.             $role->removeUser($this);
  169.         }
  170.         return $this;
  171.     }
  172.     /**
  173.      * @return Collection<int, ResNotification>
  174.      */
  175.     public function getNotifications(): Collection
  176.     {
  177.         return $this->notifications;
  178.     }
  179.     public function addNotification(ResNotification $notification): self
  180.     {
  181.         if (!$this->notifications->contains($notification)) {
  182.             $this->notifications[] = $notification;
  183.             $notification->setDestination($this);
  184.         }
  185.         return $this;
  186.     }
  187.     public function removeNotification(ResNotification $notification): self
  188.     {
  189.         if ($this->notifications->removeElement($notification)) {
  190.             // set the owning side to null (unless already changed)
  191.             if ($notification->getDestination() === $this) {
  192.                 $notification->setDestination(null);
  193.             }
  194.         }
  195.         return $this;
  196.     }
  197.     /**
  198.      * @return Collection<int, ResRoleConfig>
  199.      */
  200.     public function getResRoleConfigs(): Collection
  201.     {
  202.         return $this->resRoleConfigs;
  203.     }
  204.     public function addResRoleConfig(ResRoleConfig $resRoleConfig): self
  205.     {
  206.         if (!$this->resRoleConfigs->contains($resRoleConfig)) {
  207.             $this->resRoleConfigs[] = $resRoleConfig;
  208.             $resRoleConfig->setUtilisateur($this);
  209.         }
  210.         return $this;
  211.     }
  212.     public function removeResRoleConfig(ResRoleConfig $resRoleConfig): self
  213.     {
  214.         if ($this->resRoleConfigs->removeElement($resRoleConfig)) {
  215.             // set the owning side to null (unless already changed)
  216.             if ($resRoleConfig->getUtilisateur() === $this) {
  217.                 $resRoleConfig->setUtilisateur(null);
  218.             }
  219.         }
  220.         return $this;
  221.     }
  222.     public function isFirstLogin(): ?bool
  223.     {
  224.         return $this->firstLogin;
  225.     }
  226.     public function setFirstLogin(?bool $firstLogin): self
  227.     {
  228.         $this->firstLogin $firstLogin;
  229.         return $this;
  230.     }
  231.     public function getEmail(): ?string
  232.     {
  233.         return $this->email;
  234.     }
  235.     public function setEmail(?string $email): self
  236.     {
  237.         $this->email $email;
  238.         return $this;
  239.     }
  240. }