<?php
namespace App\Entity;
use App\Repository\AppUserRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
use Symfony\Component\Security\Core\User\UserInterface;
/**
* @ORM\Entity(repositoryClass=AppUserRepository::class)
* @method string getUserIdentifier()
*/
class AppUser implements UserInterface, PasswordAuthenticatedUserInterface
{
public function getSalt() : ?string
{
// TODO: Implement getSalt() method.
return '';
}
public function eraseCredentials()
{
// TODO: Implement eraseCredentials() method.
}
public function __call($name, $arguments)
{
// TODO: Implement @method string getUserIdentifier()
}
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=255)
*/
private $username;
/**
* @ORM\Column(type="string", length=255)
*/
private $password;
private $roles = [];
/**
* @ORM\ManyToOne(targetEntity=Company::class, inversedBy="appUsers")
* @ORM\JoinColumn(nullable=false)
*/
private $Company;
/**
* @ORM\OneToOne(targetEntity=Partner::class, inversedBy="userAccount", cascade={"persist", "remove"})
*/
private $partner;
/**
* @ORM\ManyToMany(targetEntity=UserRole::class, mappedBy="users")
*/
private $appRoles;
/**
* @ORM\OneToMany(targetEntity=ResNotification::class, mappedBy="destination", orphanRemoval=true)
*/
private $notifications;
/**
* @ORM\OneToMany(targetEntity=ResRoleConfig::class, mappedBy="utilisateur", orphanRemoval=true)
*/
private $resRoleConfigs;
/**
* @ORM\Column(type="boolean", nullable=true)
*/
private $firstLogin;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $email;
public function __construct()
{
$this->appRoles = new ArrayCollection();
$this->notifications = new ArrayCollection();
$this->resRoleConfigs = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getUsername(): ?string
{
return $this->username;
}
public function getRolesName(): string
{
$appRoles = $this->appRoles;
// guarantee every user at least has ROLE_USER
$roles = [] ;
foreach ($appRoles as $appRole) {
$roles[] = $appRole->getNomAr();
}
$roles = array_unique($roles);
if ( count( $roles) <= 0){
$roles[]= "مستخدم";
}
return implode(";", $roles);
}
/**
* @see UserInterface
*/
public function getRoles(): array
{
$appRoles = $this->appRoles;
// guarantee every user at least has ROLE_USER
$roles[] = 'ROLE_USER';
foreach ($appRoles as $appRole) {
$roles[] = $appRole->getRole();
}
return array_unique($roles);
}
public function setRoles(array $roles): self
{
$this->roles = $roles;
return $this;
}
public function setUsername(string $username): self
{
$this->username = $username;
return $this;
}
public function getPassword(): ?string
{
return $this->password;
}
public function setPassword(string $password): self
{
$this->password = $password;
return $this;
}
public function getCompany(): ?Company
{
return $this->Company;
}
public function setCompany(?Company $Company): self
{
$this->Company = $Company;
return $this;
}
public function getPartner(): ?Partner
{
return $this->partner;
}
public function setPartner(?Partner $partner): self
{
$this->partner = $partner;
return $this;
}
/**
* @return Collection|UserRole[]
*/
public function getAppRoles(): Collection
{
return $this->appRoles;
}
public function addRole(UserRole $role): self
{
if (!$this->appRoles->contains($role)) {
$this->appRoles[] = $role;
$role->addUser($this);
}
return $this;
}
public function removeRole(UserRole $role): self
{
if ($this->appRoles->removeElement($role)) {
$role->removeUser($this);
}
return $this;
}
/**
* @return Collection<int, ResNotification>
*/
public function getNotifications(): Collection
{
return $this->notifications;
}
public function addNotification(ResNotification $notification): self
{
if (!$this->notifications->contains($notification)) {
$this->notifications[] = $notification;
$notification->setDestination($this);
}
return $this;
}
public function removeNotification(ResNotification $notification): self
{
if ($this->notifications->removeElement($notification)) {
// set the owning side to null (unless already changed)
if ($notification->getDestination() === $this) {
$notification->setDestination(null);
}
}
return $this;
}
/**
* @return Collection<int, ResRoleConfig>
*/
public function getResRoleConfigs(): Collection
{
return $this->resRoleConfigs;
}
public function addResRoleConfig(ResRoleConfig $resRoleConfig): self
{
if (!$this->resRoleConfigs->contains($resRoleConfig)) {
$this->resRoleConfigs[] = $resRoleConfig;
$resRoleConfig->setUtilisateur($this);
}
return $this;
}
public function removeResRoleConfig(ResRoleConfig $resRoleConfig): self
{
if ($this->resRoleConfigs->removeElement($resRoleConfig)) {
// set the owning side to null (unless already changed)
if ($resRoleConfig->getUtilisateur() === $this) {
$resRoleConfig->setUtilisateur(null);
}
}
return $this;
}
public function isFirstLogin(): ?bool
{
return $this->firstLogin;
}
public function setFirstLogin(?bool $firstLogin): self
{
$this->firstLogin = $firstLogin;
return $this;
}
public function getEmail(): ?string
{
return $this->email;
}
public function setEmail(?string $email): self
{
$this->email = $email;
return $this;
}
}