<?php
namespace App\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use FOS\UserBundle\Model\User as BaseUser;
use DateTimeInterface;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\HttpFoundation\File\File;
use Symfony\Component\Validator\Constraints as Assert;
use Vich\UploaderBundle\Mapping\Annotation as Vich;
use App\Repository\UserRepository;
/**
* @ORM\Entity
* @ORM\Entity(repositoryClass=UserRepository::class)
* @UniqueEntity("fakeFullName")
* @ORM\Table(name="fos_user")
* @ORM\EntityListeners({"App\EventListener\User\UserListener"})
* @ORM\HasLifecycleCallbacks
* @Vich\Uploadable()
*/
class User extends BaseUser
{
const GENDER = [
'unknown' => 0,
'female' => 1,
'male' => 2,
];
const ROLE_ADMIN = 'ROLE_ADMIN';
const ROLE_IMPLEMENTOR = 'ROLE_IMPLEMENTOR';
/******************** BEGIN Summary ********************/
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @ORM\Column(type="smallint", options={"default": 0})
*/
private $gender = 0;
/**
* @ORM\Column(type="string", length=64, nullable=true)
*/
private $firstname;
/**
* @ORM\Column(type="string", length=64, nullable=true)
*/
private $lastname;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $birthday;
/**
* @ORM\Column(type="string", length=50, nullable=true)
*/
private $city;
/**
* @ORM\Column(type="string", length=64, nullable=true)
*/
private $phone;
/**
* @ORM\Column(type="string", nullable=true)
*/
private $facebookProfileLink;
/**
* @ORM\Column(type="string", nullable=true)
*/
private $instagramProfileLink;
/**
* @ORM\Column(name="avatar", type="string", nullable=true, options={"comment": "Avatar file path"})
*/
private $avatar;
/**
* @Vich\UploadableField(mapping="user_avatar", fileNameProperty="avatar")
* @Assert\File(maxSize="4194304")
* @Assert\Image()
*/
private $avatarFile;
/**
* @ORM\Column(type="text", nullable=true)
*/
public $deliveryAddress;
/**
* Is a member of the press
*
* @ORM\Column(type="boolean", options={"default" : false})
*/
private $press = false;
/**
* @ORM\Column(type="string", nullable=true)
*/
private $pressResourceName;
/**
* @ORM\Column(type="boolean", options={"default" : false})
*/
private $hiddenIdentity = false;
/**
* @ORM\Column(type="string", nullable=true, unique=true)
*/
private $fakeFullName;
/**
* @ORM\Column(type="string", nullable=true)
*/
private $fakeAvatar;
/**
* @ORM\Column(type="boolean", options={"default" : false})
*/
private $deleted = false;
/**
* @ORM\Column(type="boolean", options={"default" : false})
*/
private $policyAgreement = false;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $registrationDate;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $updatedAt;
/**
* @ORM\Column(type="integer", options={"default": 0})
*/
private $currentBalance = 0;
/******************** END Summary **********************/
/******************** BEGIN Relations ******************/
/**
* @ORM\OneToMany(targetEntity="App\Entity\UserBalanceLog", mappedBy="user")
*/
private $userBalanceLogs;
/**
* @ORM\OneToMany(targetEntity="App\Entity\UserToken", mappedBy="user", orphanRemoval=true)
*/
private $userTokens;
/**
* @ORM\OneToMany(targetEntity="App\Entity\ShopOrder", mappedBy="user")
*/
private $shopOrders;
/**
* @ORM\OneToMany(targetEntity="App\Entity\Permission", mappedBy="user")
*/
private $permissions;
/**
* @ORM\OneToMany(targetEntity="App\Entity\ContestParticipation", mappedBy="user")
*/
private $contestParticipations;
/**
* @ORM\OneToMany(targetEntity="App\Entity\DonateAlert", mappedBy="user")
*/
private $donateAlerts;
/**
* @ORM\OneToMany(targetEntity=PermissionShop::class, mappedBy="user")
*/
private $permissionShops;
/**
* @ORM\OneToMany(targetEntity=ActivityLog::class, mappedBy="user")
*/
private $activityLogs;
/******************** END Relations ********************/
public function __construct()
{
parent::__construct();
$this->userBalanceLogs = new ArrayCollection();
$this->userTokens = new ArrayCollection();
$this->shopOrders = new ArrayCollection();
$this->permissions = new ArrayCollection();
$this->contestParticipations = new ArrayCollection();
$this->donateAlerts = new ArrayCollection();
$this->permissionShops = new ArrayCollection();
$this->activityLogs = new ArrayCollection();
}
/******************** BEGIN Getters and Setters ********************/
/**
* @return int
*/
public function getId(): int
{
return $this->id;
}
/**
* @return int
*/
public function getGender(): int
{
return $this->gender;
}
/**
* @param int $gender
* @return User
*/
public function setGender($gender): self
{
$this->gender = $gender;
return $this;
}
/**
* @return string
*/
public function getStringGender()
{
return array_flip(self::GENDER)[$this->getGender()] ?? "undefined";
}
/**
* @return array
*/
public function getGenderList(): array
{
return array_keys(self::GENDER);
}
/**
* @return string|null
*/
public function getFirstname(): ?string
{
return $this->firstname;
}
/**
* @param string|null $firstname
* @return User
*/
public function setFirstname($firstname): self
{
$this->firstname = $firstname;
return $this;
}
/**
* @return string|null
*/
public function getLastname(): ?string
{
return $this->lastname;
}
/**
* @param string|null $lastname
* @return User
*/
public function setLastname($lastname): self
{
$this->lastname = $lastname;
return $this;
}
/**
* @return DateTimeInterface|null
*/
public function getBirthday(): ?DateTimeInterface
{
return $this->birthday;
}
/**
* @param DateTimeInterface|null $birthday
* @return User
*/
public function setBirthday($birthday): self
{
$this->birthday = $birthday;
return $this;
}
/**
* @return string|null
*/
public function getCity(): ?string
{
return $this->city;
}
/**
* @param string|null $city
* @return User
*/
public function setCity($city): self
{
$this->city = $city;
return $this;
}
/**
* @return string|null
*/
public function getPhone(): ?string
{
return $this->phone;
}
/**
* @param string|null $phone
* @return User
*/
public function setPhone($phone): self
{
$this->phone = $phone;
return $this;
}
/**
* @return string|null
*/
public function getFacebookProfileLink(): ?string
{
return $this->facebookProfileLink;
}
/**
* @param string|null $facebookProfileLink
* @return User
*/
public function setFacebookProfileLink($facebookProfileLink): self
{
$this->facebookProfileLink = $facebookProfileLink;
return $this;
}
/**
* @return string|null
*/
public function getInstagramProfileLink(): ?string
{
return $this->instagramProfileLink;
}
/**
* @param string|null $instagramProfileLink
* @return User
*/
public function setInstagramProfileLink($instagramProfileLink): self
{
$this->instagramProfileLink = $instagramProfileLink;
return $this;
}
/**
* @return string|null
*/
public function getAvatar(): ?string
{
return $this->avatar;
}
/**
* @param string $avatar
* @return User
*/
public function setAvatar($avatar): self
{
$this->avatar = $avatar;
return $this;
}
/**
* @return File
*/
public function getAvatarFile(): ?File
{
return $this->avatarFile;
}
/**
* @param File|\Symfony\Component\HttpFoundation\File\UploadedFile $file
* @throws \Exception
*/
public function setAvatarFile(File $file = null)
{
$this->avatarFile = $file;
if (null !== $file) {
$this->updatedAt = new \DateTime();
}
}
/**
* @return string|null
*/
public function getAvatarUrl(): ?string
{
return $this->avatar ? '/uploads/files/user/' . $this->avatar : null;
}
/**
* @return string|null
*/
public function getDeliveryAddress(): ?string
{
return $this->deliveryAddress;
}
/**
* @param string|null $deliveryAddress
* @return User
*/
public function setDeliveryAddress($deliveryAddress): self
{
$this->deliveryAddress = $deliveryAddress;
return $this;
}
/**
* @return bool
*/
public function isPress(): bool
{
return $this->press;
}
/**
* @param bool $press
* @return User
*/
public function setPress($press): self
{
$this->press = $press;
return $this;
}
/**
* @return string
*/
public function getPressResourceName(): ?string
{
return $this->pressResourceName;
}
/**
* @param string $pressResourceName
* @return User
*/
public function setPressResourceName($pressResourceName): self
{
$this->pressResourceName = $pressResourceName;
return $this;
}
/**
* @return bool
*/
public function isHiddenIdentity(): bool
{
return $this->hiddenIdentity;
}
/**
* @param bool $hiddenIdentity
* @return User
*/
public function setHiddenIdentity($hiddenIdentity): self
{
$this->hiddenIdentity = $hiddenIdentity;
return $this;
}
/**
* @return string|null
*/
public function getFakeFullName()
{
return $this->fakeFullName;
}
/**
* @param string|null $fakeFullName
* @return User
*/
public function setFakeFullName($fakeFullName): self
{
$this->fakeFullName = $fakeFullName;
return $this;
}
/**
* @return string|null
*/
public function getFakeAvatar()
{
return $this->fakeAvatar;
}
/**
* @param string|null $fakeAvatar
* @return User
*/
public function setFakeAvatar($fakeAvatar): self
{
$this->fakeAvatar = $fakeAvatar;
return $this;
}
/**
* @return bool
*/
public function isDeleted(): bool
{
return $this->deleted;
}
/**
* @param bool $deleted
* @return User
*/
public function setDeleted($deleted): self
{
$this->deleted = $deleted;
return $this;
}
/**
* @return bool
*/
public function getPolicyAgreement(): bool
{
return $this->policyAgreement;
}
/**
* @param bool $policyAgreement
* @return User
*/
public function setPolicyAgreement($policyAgreement): self
{
$this->policyAgreement = $policyAgreement;
return $this;
}
/**
* @return DateTimeInterface|null
*/
public function getRegistrationDate(): ?DateTimeInterface
{
return $this->registrationDate;
}
/**
* @param DateTimeInterface $registrationDate
* @return User
*/
public function setRegistrationDate($registrationDate): self
{
$this->registrationDate = $registrationDate;
return $this;
}
/**
* @return \DateTimeInterface|null
*/
public function getUpdatedAt(): ?\DateTimeInterface
{
return $this->updatedAt;
}
/**
* @return integer
*/
public function getCurrentBalance(): int
{
return $this->currentBalance;
}
/**
* @param integer $currentBalance
* @return User
*/
public function setCurrentBalance($currentBalance): self
{
$this->currentBalance = $currentBalance;
return $this;
}
/**
* @return Collection
*/
public function getUserBalanceLogs(): Collection
{
return $this->userBalanceLogs;
}
/**
* @return Collection|ShopOrder[]
*/
public function getShopOrders(): Collection
{
return $this->shopOrders;
}
/**
* @return Collection|Permission[]
*/
public function getPermissions(): Collection
{
return $this->permissions;
}
/**
* @return Collection|ContestParticipation[]
*/
public function getContestParticipations(): Collection
{
return $this->contestParticipations;
}
/**
* @return Collection|DonateAlert[]
*/
public function getDonateAlerts(): Collection
{
return $this->donateAlerts;
}
/**
* @return Collection|UserToken[]
*/
public function getUserTokens(): Collection
{
return $this->userTokens;
}
/**
* @param UserToken $userToken
* @return User
*/
public function addUserToken(UserToken $userToken): self
{
if (!$this->userTokens->contains($userToken)) {
$this->userTokens[] = $userToken;
$userToken->setUser($this);
}
return $this;
}
/**
* @param UserToken $userToken
* @return User
*/
public function removeUserToken(UserToken $userToken): self
{
if ($this->userTokens->contains($userToken)) {
$this->userTokens->removeElement($userToken);
// set the owning side to null (unless already changed)
if ($userToken->getUser() === $this) {
$userToken->setUser(null);
}
}
return $this;
}
/******************** END Getters and Setters ********************/
/**
* @return bool
*/
public function isAdmin()
{
return $this->hasRole(self::ROLE_ADMIN);
}
/**
* @return bool
*/
public function isImplementor()
{
return $this->hasRole(self::ROLE_IMPLEMENTOR);
}
/**
* @ORM\PrePersist
*
* @throws \Exception
*/
public function onPrePersist()
{
$this->registrationDate = new \DateTime('now');
}
/**
* @ORM\PreUpdate
*
* @throws \Exception
*/
public function onPreUpdate()
{
$this->updatedAt = new \DateTime('now');
}
public function getPress(): ?bool
{
return $this->press;
}
public function getDeleted(): ?bool
{
return $this->deleted;
}
public function setUpdatedAt(?\DateTimeInterface $updatedAt): self
{
$this->updatedAt = $updatedAt;
return $this;
}
public function addUserBalanceLog(UserBalanceLog $userBalanceLog): self
{
if (!$this->userBalanceLogs->contains($userBalanceLog)) {
$this->userBalanceLogs[] = $userBalanceLog;
$userBalanceLog->setUser($this);
}
return $this;
}
public function removeUserBalanceLog(UserBalanceLog $userBalanceLog): self
{
if ($this->userBalanceLogs->contains($userBalanceLog)) {
$this->userBalanceLogs->removeElement($userBalanceLog);
// set the owning side to null (unless already changed)
if ($userBalanceLog->getUser() === $this) {
$userBalanceLog->setUser(null);
}
}
return $this;
}
public function addShopOrder(ShopOrder $shopOrder): self
{
if (!$this->shopOrders->contains($shopOrder)) {
$this->shopOrders[] = $shopOrder;
$shopOrder->setUser($this);
}
return $this;
}
public function removeShopOrder(ShopOrder $shopOrder): self
{
if ($this->shopOrders->contains($shopOrder)) {
$this->shopOrders->removeElement($shopOrder);
// set the owning side to null (unless already changed)
if ($shopOrder->getUser() === $this) {
$shopOrder->setUser(null);
}
}
return $this;
}
public function getHiddenIdentity(): ?bool
{
return $this->hiddenIdentity;
}
public function addPermission(Permission $permission): self
{
if (!$this->permissions->contains($permission)) {
$this->permissions[] = $permission;
$permission->setUser($this);
}
return $this;
}
public function removePermission(Permission $permission): self
{
if ($this->permissions->contains($permission)) {
$this->permissions->removeElement($permission);
// set the owning side to null (unless already changed)
if ($permission->getUser() === $this) {
$permission->setUser(null);
}
}
return $this;
}
public function addContestParticipation(ContestParticipation $contestParticipation): self
{
if (!$this->contestParticipations->contains($contestParticipation)) {
$this->contestParticipations[] = $contestParticipation;
$contestParticipation->setUser($this);
}
return $this;
}
public function removeContestParticipation(ContestParticipation $contestParticipation): self
{
if ($this->contestParticipations->contains($contestParticipation)) {
$this->contestParticipations->removeElement($contestParticipation);
// set the owning side to null (unless already changed)
if ($contestParticipation->getUser() === $this) {
$contestParticipation->setUser(null);
}
}
return $this;
}
public function addDonateAlert(DonateAlert $donateAlert): self
{
if (!$this->donateAlerts->contains($donateAlert)) {
$this->donateAlerts[] = $donateAlert;
$donateAlert->setUser($this);
}
return $this;
}
public function removeDonateAlert(DonateAlert $donateAlert): self
{
if ($this->donateAlerts->contains($donateAlert)) {
$this->donateAlerts->removeElement($donateAlert);
// set the owning side to null (unless already changed)
if ($donateAlert->getUser() === $this) {
$donateAlert->setUser(null);
}
}
return $this;
}
/**
* @return Collection|PermissionShop[]
*/
public function getPermissionShops(): Collection
{
return $this->permissionShops;
}
public function addPermissionShop(PermissionShop $permissionShop): self
{
if (!$this->permissionShops->contains($permissionShop)) {
$this->permissionShops[] = $permissionShop;
$permissionShop->setUser($this);
}
return $this;
}
public function removePermissionShop(PermissionShop $permissionShop): self
{
if ($this->permissionShops->contains($permissionShop)) {
$this->permissionShops->removeElement($permissionShop);
// set the owning side to null (unless already changed)
if ($permissionShop->getUser() === $this) {
$permissionShop->setUser(null);
}
}
return $this;
}
/**
* @return Collection
*/
public function getActivityLogs(): Collection
{
return $this->activityLogs;
}
/**
* @param ActivityLog $activityLog
* @return $this
*/
public function addActivityLog(ActivityLog $activityLog): self
{
if (!$this->activityLogs->contains($activityLog)) {
$this->activityLogs[] = $activityLog;
$activityLog->setUser($this);
}
return $this;
}
/**
* @param ActivityLog $activityLog
* @return $this
*/
public function removeActivityLog(ActivityLog $activityLog): self
{
if ($this->activityLogs->contains($activityLog)) {
$this->activityLogs->removeElement($activityLog);
// set the owning side to null (unless already changed)
if ($activityLog->getUser() === $this) {
$activityLog->setUser(null);
}
}
return $this;
}
}