src/Entity/User.php line 18

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Entity\Traits\CommonTrait;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  8. use Symfony\Component\Security\Core\User\UserInterface;
  9. /**
  10.  * @ORM\Entity(repositoryClass="App\Repository\UserRepository")
  11.  * @UniqueEntity(fields={"email"}, message="Podany adres e-mail jest już używany")
  12.  * @ORM\Table(name="app_user")
  13.  * @ORM\HasLifecycleCallbacks()
  14.  */
  15. class User implements UserInterface\Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface
  16. {
  17.     use CommonTrait;
  18.     /**
  19.      * @ORM\Column(type="string", length=180, unique=true)
  20.      */
  21.     private $email;
  22.     
  23.     /**
  24.      * @var string The hashed password
  25.      * @ORM\Column(type="string", nullable=true)
  26.      */
  27.     private $password;
  28.     /**
  29.      * @ORM\Column(type="string", length=255)
  30.      */
  31.     private $firstName;
  32.     /**
  33.      * @ORM\Column(type="string", length=255)
  34.      */
  35.     private $lastName;
  36.     /**
  37.      * @ORM\Column(type="string", length=255, nullable=true)
  38.      */
  39.     private $nickname;
  40.     /**
  41.      * @ORM\Column(type="string", length=15, nullable=true)
  42.      */
  43.     private $phone;
  44.     /**
  45.      * @ORM\OneToMany(targetEntity="App\Entity\Item", mappedBy="author")
  46.      */
  47.     private $items;
  48.     /**
  49.      * @ORM\OneToMany(targetEntity="App\Entity\UserLoginEvent", mappedBy="user")
  50.      */
  51.     private $userLoginEvents;
  52.     /**
  53.      * @ORM\OneToOne(targetEntity="App\Entity\File", cascade={"persist", "remove"})
  54.      */
  55.     private $avatar;
  56.     /**
  57.      * @ORM\OneToMany(targetEntity="App\Entity\UserSaveSearch", mappedBy="user", orphanRemoval=true)
  58.      */
  59.     private $userSaveSearches;
  60.     /**
  61.      * @ORM\OneToMany(targetEntity="App\Entity\UserSaveItem", mappedBy="user", orphanRemoval=true)
  62.      */
  63.     private $userSaveItems;
  64.     /**
  65.      * @ORM\ManyToMany(targetEntity=UserRoles::class, inversedBy="users")
  66.      */
  67.     #[ApiProperty(readablefalsewritablefalse)]
  68.     private $userRoles;
  69.     protected $roles;
  70.     /**
  71.      * @ORM\OneToMany(targetEntity=ReportedItems::class, mappedBy="author", orphanRemoval=true)
  72.      */
  73.     private $reportedItems;
  74.     /**
  75.      * @ORM\Column(type="json", nullable=true)
  76.      */
  77.     private $location = [];
  78.     /**
  79.      * @ORM\Column(type="string", length=255, nullable=true)
  80.      */
  81.     private $locationName;
  82.     /**
  83.      * @ORM\OneToMany(targetEntity=PromoPayTransaction::class, mappedBy="buyer", orphanRemoval=true)
  84.      */
  85.     private $promoPayTransactions;
  86.     /**
  87.      * @ORM\OneToMany(targetEntity=Chat::class, mappedBy="personOne", orphanRemoval=true)
  88.      */
  89.     private $chats;
  90.     /**
  91.      * @ORM\Column(type="boolean", nullable=true)
  92.      */
  93.     private $isPhoneVerified;
  94.     /**
  95.      * @ORM\Column(type="boolean", nullable=true)
  96.      */
  97.     private $showNickname;
  98.     public function __construct()
  99.     {
  100.         $this->items = new ArrayCollection();
  101.         $this->userLoginEvents = new ArrayCollection();
  102.         $this->userSaveSearches = new ArrayCollection();
  103.         $this->userSaveAnnouncements = new ArrayCollection();
  104.         $this->userSaveItems = new ArrayCollection();
  105.         $this->roles = new ArrayCollection();
  106.         $this->userRoles = new ArrayCollection();
  107.         $this->reportedItems = new ArrayCollection();
  108.         $this->promoPayTransactions = new ArrayCollection();
  109.         $this->chats = new ArrayCollection();
  110.     }
  111.     public function getEmail(): ?string
  112.     {
  113.         return $this->email;
  114.     }
  115.     public function setEmail(string $email): self
  116.     {
  117.         $this->email $email;
  118.         return $this;
  119.     }
  120.     /**
  121.      * A visual identifier that represents this user.
  122.      *
  123.      * @see UserInterface
  124.      */
  125.     public function getUsername(): string
  126.     {
  127.         return (string) $this->email;
  128.     }
  129.     /**
  130.      * @see UserInterface
  131.      */
  132.     public function getRoles(): array
  133.     {
  134.         $tmp = [];
  135.         foreach ($this->userRoles as $role) {
  136.             $tmp[] = $role->getRole();
  137.         }
  138.         $tmp[] = "ROLE_USER";
  139.         return array_unique($tmp);
  140.     }
  141.     /**
  142.      * @see UserInterface
  143.      */
  144.     public function getPassword(): string
  145.     {
  146.         return (string) $this->password;
  147.     }
  148.     public function setPassword(string $password): self
  149.     {
  150.         $this->password $password;
  151.         return $this;
  152.     }
  153.     /**
  154.      * @see UserInterface
  155.      */
  156.     public function getSalt()
  157.     {
  158.         // not needed when using the "bcrypt" algorithm in security.yaml
  159.     }
  160.     /**
  161.      * @see UserInterface
  162.      */
  163.     public function eraseCredentials()
  164.     {
  165.         // If you store any temporary, sensitive data on the user, clear it here
  166.         // $this->plainPassword = null;
  167.     }
  168.     public function getFirstName(): ?string
  169.     {
  170.         return $this->firstName;
  171.     }
  172.     public function setFirstName(string $firstName): self
  173.     {
  174.         $this->firstName $firstName;
  175.         return $this;
  176.     }
  177.     public function getLastName(): ?string
  178.     {
  179.         return $this->lastName;
  180.     }
  181.     public function setLastName(string $lastName): self
  182.     {
  183.         $this->lastName $lastName;
  184.         return $this;
  185.     }
  186.     public function getNickname(): ?string
  187.     {
  188.         return $this->nickname;
  189.     }
  190.     public function setNickname(?string $nickname): self
  191.     {
  192.         $this->nickname $nickname;
  193.         return $this;
  194.     }
  195.     public function getPhone(): ?string
  196.     {
  197.         return $this->phone;
  198.     }
  199.     public function setPhone(?string $phone): self
  200.     {
  201.         $this->phone $phone;
  202.         return $this;
  203.     }
  204.     /**
  205.      * @return Collection|Item[]
  206.      */
  207.     public function getItems(): Collection
  208.     {
  209.         return $this->items;
  210.     }
  211.     public function addItem(Item $item): self
  212.     {
  213.         if (!$this->items->contains($item)) {
  214.             $this->items[] = $item;
  215.             $item->setAuthor($this);
  216.         }
  217.         return $this;
  218.     }
  219.     public function removeItem(Item $item): self
  220.     {
  221.         if ($this->items->contains($item)) {
  222.             $this->items->removeElement($item);
  223.             // set the owning side to null (unless already changed)
  224.             if ($item->getAuthor() === $this) {
  225.                 $item->setAuthor(null);
  226.             }
  227.         }
  228.         return $this;
  229.     }
  230.     /**
  231.      * @return Collection|UserLoginEvent[]
  232.      */
  233.     public function getUserLoginEvents(): Collection
  234.     {
  235.         return $this->userLoginEvents;
  236.     }
  237.     public function addUserLoginEvent(UserLoginEvent $userLoginEvent): self
  238.     {
  239.         if (!$this->userLoginEvents->contains($userLoginEvent)) {
  240.             $this->userLoginEvents[] = $userLoginEvent;
  241.             $userLoginEvent->setUser($this);
  242.         }
  243.         return $this;
  244.     }
  245.     public function removeUserLoginEvent(UserLoginEvent $userLoginEvent): self
  246.     {
  247.         if ($this->userLoginEvents->contains($userLoginEvent)) {
  248.             $this->userLoginEvents->removeElement($userLoginEvent);
  249.             // set the owning side to null (unless already changed)
  250.             if ($userLoginEvent->getUser() === $this) {
  251.                 $userLoginEvent->setUser(null);
  252.             }
  253.         }
  254.         return $this;
  255.     }
  256.     public function getAvatar(): ?File
  257.     {
  258.         return $this->avatar;
  259.     }
  260.     public function setAvatar(?File $avatar): self
  261.     {
  262.         $this->avatar $avatar;
  263.         return $this;
  264.     }
  265.     /**
  266.      * @return Collection|UserSaveSearch[]
  267.      */
  268.     public function getUserSaveSearches(): Collection
  269.     {
  270.         return $this->userSaveSearches;
  271.     }
  272.     public function addUserSaveSearch(UserSaveSearch $userSaveSearch): self
  273.     {
  274.         if (!$this->userSaveSearches->contains($userSaveSearch)) {
  275.             $this->userSaveSearches[] = $userSaveSearch;
  276.             $userSaveSearch->setUser($this);
  277.         }
  278.         return $this;
  279.     }
  280.     public function removeUserSaveSearch(UserSaveSearch $userSaveSearch): self
  281.     {
  282.         if ($this->userSaveSearches->contains($userSaveSearch)) {
  283.             $this->userSaveSearches->removeElement($userSaveSearch);
  284.             // set the owning side to null (unless already changed)
  285.             if ($userSaveSearch->getUser() === $this) {
  286.                 $userSaveSearch->setUser(null);
  287.             }
  288.         }
  289.         return $this;
  290.     }
  291.     /**
  292.      * @return Collection|UserSaveItem[]
  293.      */
  294.     public function getUserSaveItems(): Collection
  295.     {
  296.         return $this->userSaveItems;
  297.     }
  298.     public function addUserSaveItem(UserSaveItem $userSaveItem): self
  299.     {
  300.         if (!$this->userSaveItems->contains($userSaveItem)) {
  301.             $this->userSaveItems[] = $userSaveItem;
  302.             $userSaveItem->setUser($this);
  303.         }
  304.         return $this;
  305.     }
  306.     public function removeUserSaveItem(UserSaveItem $userSaveItem): self
  307.     {
  308.         if ($this->userSaveItems->contains($userSaveItem)) {
  309.             $this->userSaveItems->removeElement($userSaveItem);
  310.             // set the owning side to null (unless already changed)
  311.             if ($userSaveItem->getUser() === $this) {
  312.                 $userSaveItem->setUser(null);
  313.             }
  314.         }
  315.         return $this;
  316.     }
  317.     public function __toString()
  318.     {
  319.         return $this->firstName ' ' $this->lastName;
  320.     }
  321.     /**
  322.      * @return Collection|UserRoles[]
  323.      */
  324.     public function getUserRoles(): Collection
  325.     {
  326.         return $this->userRoles;
  327.     }
  328.     public function addUserRole(UserRoles $userRole): self
  329.     {
  330.         if (!$this->userRoles->contains($userRole)) {
  331.             $this->userRoles[] = $userRole;
  332.         }
  333.         return $this;
  334.     }
  335.     public function removeUserRole(UserRoles $userRole): self
  336.     {
  337.         if ($this->userRoles->contains($userRole)) {
  338.             $this->userRoles->removeElement($userRole);
  339.         }
  340.         return $this;
  341.     }
  342.     /**
  343.      * @ORM\PostLoad()
  344.      */
  345.     public function postLoad()
  346.     {
  347.         $this->roles $this->getRoles();
  348.     }
  349.     public function getFullName()
  350.     {
  351.         return $this->nickname $this->nickname $this->firstName ' ' $this->lastName;
  352.     }
  353.     /**
  354.      * @return Collection|ReportedItems[]
  355.      */
  356.     public function getReportedItems(): Collection
  357.     {
  358.         return $this->reportedItems;
  359.     }
  360.     public function addReportedItem(ReportedItems $reportedItem): self
  361.     {
  362.         if (!$this->reportedItems->contains($reportedItem)) {
  363.             $this->reportedItems[] = $reportedItem;
  364.             $reportedItem->setAuthor($this);
  365.         }
  366.         return $this;
  367.     }
  368.     public function removeReportedItem(ReportedItems $reportedItem): self
  369.     {
  370.         if ($this->reportedItems->contains($reportedItem)) {
  371.             $this->reportedItems->removeElement($reportedItem);
  372.             // set the owning side to null (unless already changed)
  373.             if ($reportedItem->getAuthor() === $this) {
  374.                 $reportedItem->setAuthor(null);
  375.             }
  376.         }
  377.         return $this;
  378.     }
  379.     public function getLocation(): ?array
  380.     {
  381.         return $this->location;
  382.     }
  383.     public function setLocation(?array $location): self
  384.     {
  385.         $this->location $location;
  386.         return $this;
  387.     }
  388.     public function getLocationName(): ?string
  389.     {
  390.         return $this->locationName;
  391.     }
  392.     public function setLocationName(?string $locationName): self
  393.     {
  394.         $this->locationName $locationName;
  395.         return $this;
  396.     }
  397.     /**
  398.      * @return Collection|PromoPayTransaction[]
  399.      */
  400.     public function getPromoPayTransactions(): Collection
  401.     {
  402.         return $this->promoPayTransactions;
  403.     }
  404.     public function addPromoPayTransaction(PromoPayTransaction $promoPayTransaction): self
  405.     {
  406.         if (!$this->promoPayTransactions->contains($promoPayTransaction)) {
  407.             $this->promoPayTransactions[] = $promoPayTransaction;
  408.             $promoPayTransaction->setBuyer($this);
  409.         }
  410.         return $this;
  411.     }
  412.     public function removePromoPayTransaction(PromoPayTransaction $promoPayTransaction): self
  413.     {
  414.         if ($this->promoPayTransactions->removeElement($promoPayTransaction)) {
  415.             // set the owning side to null (unless already changed)
  416.             if ($promoPayTransaction->getBuyer() === $this) {
  417.                 $promoPayTransaction->setBuyer(null);
  418.             }
  419.         }
  420.         return $this;
  421.     }
  422.     /**
  423.      * @return Collection|Chat[]
  424.      */
  425.     public function getChats(): Collection
  426.     {
  427.         return $this->chats;
  428.     }
  429.     public function addChat(Chat $chat): self
  430.     {
  431.         if (!$this->chats->contains($chat)) {
  432.             $this->chats[] = $chat;
  433.             $chat->setPersonOne($this);
  434.         }
  435.         return $this;
  436.     }
  437.     public function removeChat(Chat $chat): self
  438.     {
  439.         if ($this->chats->removeElement($chat)) {
  440.             // set the owning side to null (unless already changed)
  441.             if ($chat->getPersonOne() === $this) {
  442.                 $chat->setPersonOne(null);
  443.             }
  444.         }
  445.         return $this;
  446.     }
  447.     public function getUserIdentifier(): string
  448.     {
  449.         return $this->email;
  450.     }
  451.     public function getIsPhoneVerified(): ?bool
  452.     {
  453.         return $this->isPhoneVerified;
  454.     }
  455.     public function setIsPhoneVerified(?bool $isPhoneVerified): self
  456.     {
  457.         $this->isPhoneVerified $isPhoneVerified;
  458.         return $this;
  459.     }
  460.     public function getShowNickname(): ?bool
  461.     {
  462.         return $this->showNickname;
  463.     }
  464.     public function setShowNickname(?bool $showNickname): self
  465.     {
  466.         $this->showNickname $showNickname;
  467.         return $this;
  468.     }
  469. }