<?php
namespace App\Entity\Generic;
use App\Entity\BaseEntity;
use App\Entity\Campaign;
use App\Entity\Domains\Domain;
use App\Entity\Idea;
use App\Entity\Server\Hetzner\Ip;
use App\Entity\Server\Hetzner\Server;
use App\Entity\SubTransactions\ArzDigital;
use App\Entity\Telegram\AgentPublicBot\Bot;
use App\Entity\Transaction;
use App\Entity\VPN\Service\Service;
use App\Repository\Generic\UserRepository;
use DateTimeInterface;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use JetBrains\PhpStorm\Pure;
use Symfony\Bridge\Doctrine\IdGenerator\UuidGenerator;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Component\Validator\Constraints as Assert;
#[ORM\Entity(repositoryClass: UserRepository::class)]
#[ORM\Table(name: '`user`')]
#[UniqueEntity(fields: ['email'], message: 'این پست الکترونیک از قبل موجود می باشد')]
#[UniqueEntity(fields: ['mobile'], message: 'این شماره موبایل از قبل موجود می باشد')]
class User extends BaseEntity implements UserInterface, PasswordAuthenticatedUserInterface
{
#[ORM\Id]
#[ORM\Column(type: 'guid', unique: true)]
#[ORM\GeneratedValue(strategy: 'CUSTOM')]
#[ORM\CustomIdGenerator(class: UuidGenerator::class)]
private $id;
#[ORM\Column(type: 'string', length: 180, unique: true)]
private $email;
#[ORM\Column(type: 'json')]
private $roles = [];
#[ORM\Column(type: 'string')]
private $password;
#[ORM\Column(type: 'boolean')]
private $isVerified = false;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private $firstName;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private $lastName;
#[ORM\Column(type: 'json')]
private $access = [];
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private $image;
#[ORM\Column(type: 'bigint')]
private $wallet = 0;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private ?string $mobile;
#[ORM\OneToMany(mappedBy: 'owner', targetEntity: Transaction::class)]
private Collection $transactions;
#[ORM\Column(type: Types::DATETIME_MUTABLE, nullable: true)]
private ?DateTimeInterface $lastLogin = null;
#[ORM\ManyToOne(targetEntity: self::class, inversedBy: 'users')]
private ?self $presenter = null;
#[ORM\OneToMany(mappedBy: 'presenter', targetEntity: self::class)]
private Collection $users;
#[ORM\Column(nullable: true)]
private ?int $uniquePresenterCode = null;
#[ORM\Column(type: Types::DATETIME_MUTABLE, nullable: true)]
private ?\DateTimeInterface $lastBuy = null;
#[ORM\Column]
private ?int $subUserCount = null;
/**
* @var Collection<int, Service>
*/
#[ORM\OneToMany(targetEntity: Service::class, mappedBy: 'owner')]
private Collection $services;
#[ORM\Column(nullable: true)]
#[Assert\Range(
notInRangeMessage: '
درصد سود باید بین
{{ min }}
و
{{ max }}
باشد',
min: 0,
max: 1000,
)]
private ?int $interestRate = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $telegramChannel = null;
#[ORM\Column(type: Types::TEXT, nullable: true)]
private ?string $customerText = null;
#[ORM\Column(nullable: true)]
private ?int $thisMonthCharge = null;
#[ORM\OneToMany(mappedBy: 'author', targetEntity: Transaction::class)]
private Collection $madeTransactions;
#[ORM\ManyToOne(targetEntity: self::class, inversedBy: 'advertisedUsers')]
private ?self $advertiser = null;
#[ORM\OneToMany(mappedBy: 'advertiser', targetEntity: self::class)]
private Collection $advertisedUsers;
#[ORM\Column(length: 255, nullable: true)]
private ?string $userTrace = null;
#[ORM\ManyToOne(inversedBy: 'users')]
private ?Campaign $campaign = null;
#[ORM\OneToMany(mappedBy: 'owner', targetEntity: Domain::class)]
private Collection $domains;
#[ORM\Column(nullable: true)]
private ?bool $isTelegramContact = null;
#[ORM\Column(nullable: true)]
private ?bool $isTelegramContactChecked = null;
#[ORM\OneToMany(mappedBy: 'owner', targetEntity: Bot::class)]
private Collection $bots;
#[ORM\OneToMany(mappedBy: 'author', targetEntity: Idea::class)]
private Collection $ideas;
#[ORM\Column(length: 255, nullable: true)]
private ?string $cardNumberToCharge = null;
#[ORM\Column(type: Types::BIGINT, nullable: true)]
private ?string $advertiserMonthlyIncome = null;
#[ORM\Column(type: Types::TEXT, nullable: true)]
private ?string $connectedTelegramUserId = null;
#[ORM\OneToMany(mappedBy: 'panelOwner', targetEntity: ArzDigital::class)]
private Collection $arzDigitals;
#[ORM\Column(nullable: true)]
private ?int $VpnServicesCount = null;
#[ORM\Column(type: Types::BIGINT, nullable: true)]
private ?string $giftWallet = null;
#[ORM\OneToMany(mappedBy: 'owner', targetEntity: Ip::class)]
private Collection $hetznerIps;
#[ORM\OneToMany(mappedBy: 'owner', targetEntity: Server::class)]
private Collection $hetznerServers;
public function __construct()
{
parent::__construct();
$this->setIsVerified(false);
$this->setInterestRate(100);
$this->setSubUserCount(0);
$this->transactions = new ArrayCollection();
$this->users = new ArrayCollection();
$this->madeTransactions = new ArrayCollection();
$this->advertisedUsers = new ArrayCollection();
$this->domains = new ArrayCollection();
$this->setIsTelegramContactChecked(0);
$this->bots = new ArrayCollection();
$this->ideas = new ArrayCollection();
$this->setCardNumberToCharge('');
$this->arzDigitals = new ArrayCollection();
}
#[Pure] public function __toString(): string
{
if ($this->getFirstName() && $this->getLastName()) {
return $this->getFirstName() . ' ' . $this->getLastName();
}
return $this->getEmail();
}
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 getEmail(): ?string
{
return $this->email;
}
public function setEmail(string $email): self
{
$this->email = $email;
return $this;
}
public function hasRole($role): bool
{
return in_array($role, $this->getRoles());
}
/**
* @see UserInterface
*/
public function getRoles(): array
{
$roles = $this->roles;
// guarantee every user at least has ROLE_USER
$roles[] = 'ROLE_USER';
return array_unique($roles);
}
public function setRoles(array $roles): self
{
$this->roles = $roles;
return $this;
}
public function getId(): ?string
{
return $this->id;
}
#[Pure] public function hasAccess($access): bool
{
return in_array($access, $this->getAccess());
}
public function getAccess(): ?array
{
if ($this->access) {
return $this->access;
}
return [];
}
public function setAccess(array $access): self
{
$this->access = $access;
return $this;
}
/**
* A visual identifier that represents this user.
*
* @see UserInterface
*/
public function getUserIdentifier(): string
{
return (string)$this->email;
}
/**
* @deprecated since Symfony 5.3, use getUserIdentifier instead
*/
public function getUsername(): string
{
return (string)$this->email;
}
/**
* @see PasswordAuthenticatedUserInterface
*/
public function getPassword(): string
{
return $this->password;
}
public function setPassword(string $password): self
{
$this->password = $password;
return $this;
}
/**
* Returning a salt is only needed, if you are not using a modern
* hashing algorithm (e.g. bcrypt or sodium) in your security.yaml.
*
* @see UserInterface
*/
public function getSalt(): ?string
{
return null;
}
/**
* @see UserInterface
*/
public function eraseCredentials()
{
// If you store any temporary, sensitive data on the user, clear it here
// $this->plainPassword = null;
}
public function getImage(): ?string
{
return $this->image;
}
public function setImage(?string $image): self
{
$this->image = $image;
return $this;
}
public function getWallet(): ?string
{
return $this->wallet;
}
public function setWallet(string $wallet): self
{
$this->wallet = $wallet;
return $this;
}
public function getMobile(): ?string
{
return $this->mobile;
}
public function setMobile( $mobile): self
{
$this->mobile = $mobile;
return $this;
}
public function getMobileColoredItem(): ?string
{
if ($this->getMobile()){
return $this->getMobile();
}else{
return 'ندارد';
}
}
/**
* @return Collection<int, Transaction>
*/
public function getTransactions(): Collection
{
return $this->transactions;
}
public function addTransaction(Transaction $transaction): self
{
if (!$this->transactions->contains($transaction)) {
$this->transactions->add($transaction);
$transaction->setOwner($this);
}
return $this;
}
public function removeTransaction(Transaction $transaction): self
{
if ($this->transactions->removeElement($transaction)) {
// set the owning side to null (unless already changed)
if ($transaction->getOwner() === $this) {
$transaction->setOwner(null);
}
}
return $this;
}
public function getLastLogin(): ?DateTimeInterface
{
return $this->lastLogin;
}
public function setLastLogin(?DateTimeInterface $lastLogin): self
{
$this->lastLogin = $lastLogin;
return $this;
}
/**
* @return Collection<int, self>
*/
public function getUsers(): Collection
{
return $this->users;
}
public function addUser(self $user): self
{
if (!$this->users->contains($user)) {
$this->users->add($user);
$user->setPresenter($this);
}
return $this;
}
public function removeUser(self $user): self
{
if ($this->users->removeElement($user)) {
// set the owning side to null (unless already changed)
if ($user->getPresenter() === $this) {
$user->setPresenter(null);
}
}
return $this;
}
public function getPresenter(): ?self
{
return $this->presenter;
}
public function setPresenter(?self $presenter): self
{
$this->presenter = $presenter;
return $this;
}
public function getUniquePresenterCode(): ?int
{
return $this->uniquePresenterCode;
}
public function setUniquePresenterCode(?int $uniquePresenterCode): self
{
$this->uniquePresenterCode = $uniquePresenterCode;
return $this;
}
public function getLastBuy(): ?\DateTimeInterface
{
return $this->lastBuy;
}
public function setLastBuy(?\DateTimeInterface $lastBuy): self
{
$this->lastBuy = $lastBuy;
return $this;
}
public function getSubUserCount(): ?int
{
return $this->subUserCount;
}
public function setSubUserCount(int $subUserCount): self
{
$this->subUserCount = $subUserCount;
return $this;
}
public function getInterestRate(): ?int
{
return $this->interestRate;
}
public function setInterestRate(?int $interestRate): self
{
$this->interestRate = $interestRate;
return $this;
}
public function getTelegramChannel(): ?string
{
return $this->telegramChannel;
}
public function setTelegramChannel(?string $telegramChannel): self
{
$this->telegramChannel = $telegramChannel;
return $this;
}
public function getCustomerText(): ?string
{
return $this->customerText;
}
public function setCustomerText(?string $customerText): self
{
$this->customerText = $customerText;
return $this;
}
public function getThisMonthCharge(): ?int
{
return $this->thisMonthCharge;
}
public function setThisMonthCharge(?int $thisMonthCharge): self
{
$this->thisMonthCharge = $thisMonthCharge;
return $this;
}
/**
* @return Collection<int, Transaction>
*/
public function getMadeTransactions(): Collection
{
return $this->madeTransactions;
}
public function addMadeTransaction(Transaction $madeTransaction): self
{
if (!$this->madeTransactions->contains($madeTransaction)) {
$this->madeTransactions->add($madeTransaction);
$madeTransaction->setAuthor($this);
}
return $this;
}
public function removeMadeTransaction(Transaction $madeTransaction): self
{
if ($this->madeTransactions->removeElement($madeTransaction)) {
// set the owning side to null (unless already changed)
if ($madeTransaction->getAuthor() === $this) {
$madeTransaction->setAuthor(null);
}
}
return $this;
}
public function getAdvertiser(): ?self
{
return $this->advertiser;
}
public function setAdvertiser(?self $advertiser): self
{
$this->advertiser = $advertiser;
return $this;
}
/**
* @return Collection<int, self>
*/
public function getAdvertisedUsers(): Collection
{
return $this->advertisedUsers;
}
public function addAdvertisedUser(self $advertisedUser): self
{
if (!$this->advertisedUsers->contains($advertisedUser)) {
$this->advertisedUsers->add($advertisedUser);
$advertisedUser->setAdvertiser($this);
}
return $this;
}
public function removeAdvertisedUser(self $advertisedUser): self
{
if ($this->advertisedUsers->removeElement($advertisedUser)) {
// set the owning side to null (unless already changed)
if ($advertisedUser->getAdvertiser() === $this) {
$advertisedUser->setAdvertiser(null);
}
}
return $this;
}
/**
* @return array|null
*/
public function getUserTrace(): ?array
{
return json_decode($this->userTrace , true);
}
/**
* @param array|null $userTrace
*/
public function setUserTrace(?array $userTrace): void
{
$this->userTrace = json_encode($userTrace);
}
public function getCampaign(): ?Campaign
{
return $this->campaign;
}
public function setCampaign(?Campaign $campaign): static
{
$this->campaign = $campaign;
return $this;
}
/**
* @return Collection<int, Domain>
*/
public function getDomains(): Collection
{
return $this->domains;
}
public function addDomain(Domain $domain): static
{
if (!$this->domains->contains($domain)) {
$this->domains->add($domain);
$domain->setOwner($this);
}
return $this;
}
public function removeDomain(Domain $domain): static
{
if ($this->domains->removeElement($domain)) {
// set the owning side to null (unless already changed)
if ($domain->getOwner() === $this) {
$domain->setOwner(null);
}
}
return $this;
}
public function isVerified(): bool
{
return $this->isVerified;
}
public function setIsVerified(bool $isVerified): void
{
$this->isVerified = $isVerified;
}
public function isIsTelegramContact(): ?bool
{
return $this->isTelegramContact;
}
public function setIsTelegramContact(?bool $isTelegramContact): static
{
$this->isTelegramContact = $isTelegramContact;
return $this;
}
public function isIsTelegramContactChecked(): ?bool
{
return $this->isTelegramContactChecked;
}
public function setIsTelegramContactChecked(?bool $isTelegramContactChecked): static
{
$this->isTelegramContactChecked = $isTelegramContactChecked;
return $this;
}
/**
* @return Collection<int, Bot>
*/
public function getBots(): Collection
{
return $this->bots;
}
public function addBot(Bot $bot): static
{
if (!$this->bots->contains($bot)) {
$this->bots->add($bot);
$bot->setOwner($this);
}
return $this;
}
public function removeBot(Bot $bot): static
{
if ($this->bots->removeElement($bot)) {
// set the owning side to null (unless already changed)
if ($bot->getOwner() === $this) {
$bot->setOwner(null);
}
}
return $this;
}
/**
* @return Collection<int, Idea>
*/
public function getIdeas(): Collection
{
return $this->ideas;
}
public function addIdea(Idea $idea): static
{
if (!$this->ideas->contains($idea)) {
$this->ideas->add($idea);
$idea->setAuthor($this);
}
return $this;
}
public function removeIdea(Idea $idea): static
{
if ($this->ideas->removeElement($idea)) {
// set the owning side to null (unless already changed)
if ($idea->getAuthor() === $this) {
$idea->setAuthor(null);
}
}
return $this;
}
public function getCardNumberToCharge(): ?string
{
return $this->cardNumberToCharge;
}
public function setCardNumberToCharge(?string $cardNumberToCharge): static
{
$this->cardNumberToCharge = $cardNumberToCharge;
return $this;
}
public function getTheme(): ?string
{
// if ($this->hasRole('ROLE_ADMIN')){
return 'neon';
// }
// return 'default';
// return $this->theme?:'default';
}
public function setTheme(?string $theme): static
{
$this->theme = $theme;
return $this;
}
public function getAdvertiserMonthlyIncome(): ?string
{
return $this->advertiserMonthlyIncome;
}
public function setAdvertiserMonthlyIncome(?string $advertiserMonthlyIncome): static
{
$this->advertiserMonthlyIncome = $advertiserMonthlyIncome;
return $this;
}
public function getConnectedTelegramUserId(): ?array
{
return json_decode($this->connectedTelegramUserId , true);
}
public function setConnectedTelegramUserId(?array $connectedTelegramUserId): static
{
$this->connectedTelegramUserId = json_encode($connectedTelegramUserId);
return $this;
}
/**
* @return Collection<int, ArzDigital>
*/
public function getArzDigitals(): Collection
{
return $this->arzDigitals;
}
public function addArzDigital(ArzDigital $arzDigital): static
{
if (!$this->arzDigitals->contains($arzDigital)) {
$this->arzDigitals->add($arzDigital);
$arzDigital->setPanelOwner($this);
}
return $this;
}
public function removeArzDigital(ArzDigital $arzDigital): static
{
if ($this->arzDigitals->removeElement($arzDigital)) {
// set the owning side to null (unless already changed)
if ($arzDigital->getPanelOwner() === $this) {
$arzDigital->setPanelOwner(null);
}
}
return $this;
}
public function getVpnServicesCount(): ?int
{
return $this->VpnServicesCount;
}
public function setVpnServicesCount(?int $VpnServicesCount): static
{
$this->VpnServicesCount = $VpnServicesCount;
return $this;
}
public function getGiftWallet(): ?string
{
return $this->giftWallet;
}
public function setGiftWallet(?string $giftWallet): static
{
$this->giftWallet = $giftWallet;
return $this;
}
/**
* @return Collection<int, Ip>
*/
public function getHetznerIps(): Collection
{
return $this->hetznerIps;
}
public function addHetznerIp(Ip $hetznerIp): static
{
if (!$this->hetznerIps->contains($hetznerIp)) {
$this->hetznerIps->add($hetznerIp);
$hetznerIp->setOwner($this);
}
return $this;
}
public function removeHetznerIp(Ip $hetznerIp): static
{
if ($this->hetznerIps->removeElement($hetznerIp)) {
// set the owning side to null (unless already changed)
if ($hetznerIp->getOwner() === $this) {
$hetznerIp->setOwner(null);
}
}
return $this;
}
/**
* @return Collection<int, Server>
*/
public function getHetznerServers(): Collection
{
return $this->hetznerServers;
}
public function addHetznerServer(Server $hetznerServer): static
{
if (!$this->hetznerServers->contains($hetznerServer)) {
$this->hetznerServers->add($hetznerServer);
$hetznerServer->setOwner($this);
}
return $this;
}
public function removeHetznerServer(Server $hetznerServer): static
{
if ($this->hetznerServers->removeElement($hetznerServer)) {
// set the owning side to null (unless already changed)
if ($hetznerServer->getOwner() === $this) {
$hetznerServer->setOwner(null);
}
}
return $this;
}
}