<?php
namespace App\Entity;
use App\Entity\Traits\CommonTrait;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Security\Core\User\UserInterface;
/**
* @ORM\Entity(repositoryClass="App\Repository\UserRepository")
* @UniqueEntity(fields={"email"}, message="Podany adres e-mail jest już używany")
* @ORM\Table(name="app_user")
* @ORM\HasLifecycleCallbacks()
*/
class User implements UserInterface, \Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface
{
use CommonTrait;
/**
* @ORM\Column(type="string", length=180, unique=true)
*/
private $email;
/**
* @var string The hashed password
* @ORM\Column(type="string", nullable=true)
*/
private $password;
/**
* @ORM\Column(type="string", length=255)
*/
private $firstName;
/**
* @ORM\Column(type="string", length=255)
*/
private $lastName;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $nickname;
/**
* @ORM\Column(type="string", length=15, nullable=true)
*/
private $phone;
/**
* @ORM\OneToMany(targetEntity="App\Entity\Item", mappedBy="author")
*/
private $items;
/**
* @ORM\OneToMany(targetEntity="App\Entity\UserLoginEvent", mappedBy="user")
*/
private $userLoginEvents;
/**
* @ORM\OneToOne(targetEntity="App\Entity\File", cascade={"persist", "remove"})
*/
private $avatar;
/**
* @ORM\OneToMany(targetEntity="App\Entity\UserSaveSearch", mappedBy="user", orphanRemoval=true)
*/
private $userSaveSearches;
/**
* @ORM\OneToMany(targetEntity="App\Entity\UserSaveItem", mappedBy="user", orphanRemoval=true)
*/
private $userSaveItems;
/**
* @ORM\ManyToMany(targetEntity=UserRoles::class, inversedBy="users")
*/
#[ApiProperty(readable: false, writable: false)]
private $userRoles;
protected $roles;
/**
* @ORM\OneToMany(targetEntity=ReportedItems::class, mappedBy="author", orphanRemoval=true)
*/
private $reportedItems;
/**
* @ORM\Column(type="json", nullable=true)
*/
private $location = [];
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $locationName;
/**
* @ORM\OneToMany(targetEntity=PromoPayTransaction::class, mappedBy="buyer", orphanRemoval=true)
*/
private $promoPayTransactions;
/**
* @ORM\OneToMany(targetEntity=Chat::class, mappedBy="personOne", orphanRemoval=true)
*/
private $chats;
/**
* @ORM\Column(type="boolean", nullable=true)
*/
private $isPhoneVerified;
/**
* @ORM\Column(type="boolean", nullable=true)
*/
private $showNickname;
public function __construct()
{
$this->items = new ArrayCollection();
$this->userLoginEvents = new ArrayCollection();
$this->userSaveSearches = new ArrayCollection();
$this->userSaveAnnouncements = new ArrayCollection();
$this->userSaveItems = new ArrayCollection();
$this->roles = new ArrayCollection();
$this->userRoles = new ArrayCollection();
$this->reportedItems = new ArrayCollection();
$this->promoPayTransactions = new ArrayCollection();
$this->chats = new ArrayCollection();
}
public function getEmail(): ?string
{
return $this->email;
}
public function setEmail(string $email): self
{
$this->email = $email;
return $this;
}
/**
* A visual identifier that represents this user.
*
* @see UserInterface
*/
public function getUsername(): string
{
return (string) $this->email;
}
/**
* @see UserInterface
*/
public function getRoles(): array
{
$tmp = [];
foreach ($this->userRoles as $role) {
$tmp[] = $role->getRole();
}
$tmp[] = "ROLE_USER";
return array_unique($tmp);
}
/**
* @see UserInterface
*/
public function getPassword(): string
{
return (string) $this->password;
}
public function setPassword(string $password): self
{
$this->password = $password;
return $this;
}
/**
* @see UserInterface
*/
public function getSalt()
{
// not needed when using the "bcrypt" algorithm in security.yaml
}
/**
* @see UserInterface
*/
public function eraseCredentials()
{
// If you store any temporary, sensitive data on the user, clear it here
// $this->plainPassword = null;
}
public function getFirstName(): ?string
{
return $this->firstName;
}
public function setFirstName(string $firstName): self
{
$this->firstName = $firstName;
return $this;
}
public function getLastName(): ?string
{
return $this->lastName;
}
public function setLastName(string $lastName): self
{
$this->lastName = $lastName;
return $this;
}
public function getNickname(): ?string
{
return $this->nickname;
}
public function setNickname(?string $nickname): self
{
$this->nickname = $nickname;
return $this;
}
public function getPhone(): ?string
{
return $this->phone;
}
public function setPhone(?string $phone): self
{
$this->phone = $phone;
return $this;
}
/**
* @return Collection|Item[]
*/
public function getItems(): Collection
{
return $this->items;
}
public function addItem(Item $item): self
{
if (!$this->items->contains($item)) {
$this->items[] = $item;
$item->setAuthor($this);
}
return $this;
}
public function removeItem(Item $item): self
{
if ($this->items->contains($item)) {
$this->items->removeElement($item);
// set the owning side to null (unless already changed)
if ($item->getAuthor() === $this) {
$item->setAuthor(null);
}
}
return $this;
}
/**
* @return Collection|UserLoginEvent[]
*/
public function getUserLoginEvents(): Collection
{
return $this->userLoginEvents;
}
public function addUserLoginEvent(UserLoginEvent $userLoginEvent): self
{
if (!$this->userLoginEvents->contains($userLoginEvent)) {
$this->userLoginEvents[] = $userLoginEvent;
$userLoginEvent->setUser($this);
}
return $this;
}
public function removeUserLoginEvent(UserLoginEvent $userLoginEvent): self
{
if ($this->userLoginEvents->contains($userLoginEvent)) {
$this->userLoginEvents->removeElement($userLoginEvent);
// set the owning side to null (unless already changed)
if ($userLoginEvent->getUser() === $this) {
$userLoginEvent->setUser(null);
}
}
return $this;
}
public function getAvatar(): ?File
{
return $this->avatar;
}
public function setAvatar(?File $avatar): self
{
$this->avatar = $avatar;
return $this;
}
/**
* @return Collection|UserSaveSearch[]
*/
public function getUserSaveSearches(): Collection
{
return $this->userSaveSearches;
}
public function addUserSaveSearch(UserSaveSearch $userSaveSearch): self
{
if (!$this->userSaveSearches->contains($userSaveSearch)) {
$this->userSaveSearches[] = $userSaveSearch;
$userSaveSearch->setUser($this);
}
return $this;
}
public function removeUserSaveSearch(UserSaveSearch $userSaveSearch): self
{
if ($this->userSaveSearches->contains($userSaveSearch)) {
$this->userSaveSearches->removeElement($userSaveSearch);
// set the owning side to null (unless already changed)
if ($userSaveSearch->getUser() === $this) {
$userSaveSearch->setUser(null);
}
}
return $this;
}
/**
* @return Collection|UserSaveItem[]
*/
public function getUserSaveItems(): Collection
{
return $this->userSaveItems;
}
public function addUserSaveItem(UserSaveItem $userSaveItem): self
{
if (!$this->userSaveItems->contains($userSaveItem)) {
$this->userSaveItems[] = $userSaveItem;
$userSaveItem->setUser($this);
}
return $this;
}
public function removeUserSaveItem(UserSaveItem $userSaveItem): self
{
if ($this->userSaveItems->contains($userSaveItem)) {
$this->userSaveItems->removeElement($userSaveItem);
// set the owning side to null (unless already changed)
if ($userSaveItem->getUser() === $this) {
$userSaveItem->setUser(null);
}
}
return $this;
}
public function __toString()
{
return $this->firstName . ' ' . $this->lastName;
}
/**
* @return Collection|UserRoles[]
*/
public function getUserRoles(): Collection
{
return $this->userRoles;
}
public function addUserRole(UserRoles $userRole): self
{
if (!$this->userRoles->contains($userRole)) {
$this->userRoles[] = $userRole;
}
return $this;
}
public function removeUserRole(UserRoles $userRole): self
{
if ($this->userRoles->contains($userRole)) {
$this->userRoles->removeElement($userRole);
}
return $this;
}
/**
* @ORM\PostLoad()
*/
public function postLoad()
{
$this->roles = $this->getRoles();
}
public function getFullName()
{
return $this->nickname ? $this->nickname : $this->firstName . ' ' . $this->lastName;
}
/**
* @return Collection|ReportedItems[]
*/
public function getReportedItems(): Collection
{
return $this->reportedItems;
}
public function addReportedItem(ReportedItems $reportedItem): self
{
if (!$this->reportedItems->contains($reportedItem)) {
$this->reportedItems[] = $reportedItem;
$reportedItem->setAuthor($this);
}
return $this;
}
public function removeReportedItem(ReportedItems $reportedItem): self
{
if ($this->reportedItems->contains($reportedItem)) {
$this->reportedItems->removeElement($reportedItem);
// set the owning side to null (unless already changed)
if ($reportedItem->getAuthor() === $this) {
$reportedItem->setAuthor(null);
}
}
return $this;
}
public function getLocation(): ?array
{
return $this->location;
}
public function setLocation(?array $location): self
{
$this->location = $location;
return $this;
}
public function getLocationName(): ?string
{
return $this->locationName;
}
public function setLocationName(?string $locationName): self
{
$this->locationName = $locationName;
return $this;
}
/**
* @return Collection|PromoPayTransaction[]
*/
public function getPromoPayTransactions(): Collection
{
return $this->promoPayTransactions;
}
public function addPromoPayTransaction(PromoPayTransaction $promoPayTransaction): self
{
if (!$this->promoPayTransactions->contains($promoPayTransaction)) {
$this->promoPayTransactions[] = $promoPayTransaction;
$promoPayTransaction->setBuyer($this);
}
return $this;
}
public function removePromoPayTransaction(PromoPayTransaction $promoPayTransaction): self
{
if ($this->promoPayTransactions->removeElement($promoPayTransaction)) {
// set the owning side to null (unless already changed)
if ($promoPayTransaction->getBuyer() === $this) {
$promoPayTransaction->setBuyer(null);
}
}
return $this;
}
/**
* @return Collection|Chat[]
*/
public function getChats(): Collection
{
return $this->chats;
}
public function addChat(Chat $chat): self
{
if (!$this->chats->contains($chat)) {
$this->chats[] = $chat;
$chat->setPersonOne($this);
}
return $this;
}
public function removeChat(Chat $chat): self
{
if ($this->chats->removeElement($chat)) {
// set the owning side to null (unless already changed)
if ($chat->getPersonOne() === $this) {
$chat->setPersonOne(null);
}
}
return $this;
}
public function getUserIdentifier(): string
{
return $this->email;
}
public function getIsPhoneVerified(): ?bool
{
return $this->isPhoneVerified;
}
public function setIsPhoneVerified(?bool $isPhoneVerified): self
{
$this->isPhoneVerified = $isPhoneVerified;
return $this;
}
public function getShowNickname(): ?bool
{
return $this->showNickname;
}
public function setShowNickname(?bool $showNickname): self
{
$this->showNickname = $showNickname;
return $this;
}
}