<?php
namespace App\Entity\Website\Website;
use App\Entity\BaseEntity;
use App\Entity\BaseSite\Domain;
use App\Entity\BaseSite\Plan\AddOn;
use App\Entity\BaseSite\Plan\Plan;
use App\Entity\Generic\Customer\Customer;
use App\Entity\Generic\User;
use App\Entity\Website\Analytics;
use App\Entity\Website\Analytics\ServersUsage;
use App\Entity\Website\Campaign;
use App\Entity\Website\Cms\Article;
use App\Entity\Website\Cms\Category;
use App\Entity\Website\Cms\Page;
use App\Entity\Website\Cms\Tag;
use App\Entity\Website\Cost;
use App\Entity\Website\CostCategory;
use App\Entity\Website\Setting;
use App\Entity\Website\Sms\SmsIncome;
use App\Entity\Website\SubTransactions\VasetPal;
use App\Entity\Website\Telegram\AgentPublicBot\Bot;
use App\Entity\Website\Transaction;
use App\Entity\Website\VPN\OcServ\Server;
use App\Entity\Website\VPN\Service\Service;
use App\Repository\Website\Website\WebsiteRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\IdGenerator\UuidGenerator;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
#[ORM\Entity(repositoryClass: WebsiteRepository::class)]
#[UniqueEntity(fields: ['subdomain'], message: 'این نام کاربری فروشگاه از قبل موجود می باشد')]
class Website extends BaseEntity
{
#[ORM\Id]
#[ORM\Column(type: 'guid', unique: true)]
#[ORM\GeneratedValue(strategy: 'CUSTOM')]
#[ORM\CustomIdGenerator(class: UuidGenerator::class)]
private ?string $id;
#[ORM\Column(length: 255)]
private ?string $name = null;
#[ORM\Column(length: 255, unique: true)]
private ?string $subdomain = null;
#[ORM\Column]
private ?float $shopBalance = null;
#[ORM\ManyToOne(inversedBy: 'shops')]
#[ORM\JoinColumn(nullable: false)]
private ?User $owner = null;
#[ORM\OneToMany(mappedBy: 'website', targetEntity: Customer::class)]
private Collection $customers;
#[ORM\Column(length: 255, nullable: true)]
private ?string $theme = null;
#[ORM\Column(nullable: true)]
private ?array $analyticsData = null;
#[ORM\Column(nullable: true)]
private ?\DateTimeImmutable $expiredAt = null;
#[ORM\OneToMany(mappedBy: 'website', targetEntity: Transaction::class)]
private Collection $transactions;
#[ORM\Column(type: Types::BIGINT)]
private ?string $trafficUsage = null;
#[ORM\OneToMany(mappedBy: 'website', targetEntity: Domain::class)]
private Collection $domains;
#[ORM\ManyToOne(inversedBy: 'shops')]
private ?Plan $currentPlan = null;
#[ORM\OneToMany(mappedBy: 'website', targetEntity: AddOn::class)]
private Collection $addOns;
#[ORM\Column(type: Types::DATETIME_MUTABLE, nullable: true)]
private ?\DateTimeInterface $planStartedAt = null;
#[ORM\OneToMany(mappedBy: 'website', targetEntity: Setting::class)]
private Collection $settings;
#[ORM\OneToMany(mappedBy: 'website', targetEntity: ServersUsage::class)]
private Collection $serversUsages;
#[ORM\OneToMany(mappedBy: 'website', targetEntity: Article::class)]
private Collection $articles;
#[ORM\OneToMany(mappedBy: 'website', targetEntity: Category::class)]
private Collection $categories;
#[ORM\OneToMany(mappedBy: 'website', targetEntity: Page::class)]
private Collection $pages;
#[ORM\OneToMany(mappedBy: 'website', targetEntity: Tag::class)]
private Collection $tags;
#[ORM\OneToMany(mappedBy: 'website', targetEntity: \App\Entity\Website\Domains\Domain::class)]
private Collection $subPanelDomains;
#[ORM\OneToMany(mappedBy: 'website', targetEntity: SmsIncome::class)]
private Collection $smsIncomes;
#[ORM\OneToMany(mappedBy: 'website', targetEntity: VasetPal::class)]
private Collection $vasetPals;
#[ORM\OneToMany(mappedBy: 'website', targetEntity: Bot::class)]
private Collection $bots;
#[ORM\OneToMany(mappedBy: 'website', targetEntity: Analytics::class)]
private Collection $analytics;
#[ORM\OneToMany(mappedBy: 'website', targetEntity: Campaign::class)]
private Collection $campaigns;
#[ORM\OneToMany(mappedBy: 'website', targetEntity: Cost::class)]
private Collection $costs;
#[ORM\OneToMany(mappedBy: 'website', targetEntity: CostCategory::class)]
private Collection $costCategories;
#[ORM\OneToMany(mappedBy: 'website', targetEntity: Transaction::class)]
private Collection $websiteTransactions;
#[ORM\OneToMany(mappedBy: 'website', targetEntity: Service::class)]
private Collection $services;
#[ORM\OneToMany(mappedBy: 'website', targetEntity: Server::class)]
private Collection $servers;
#[ORM\OneToMany(mappedBy: 'website', targetEntity: \App\Entity\Website\VPN\OpenVPN\Server::class)]
private Collection $openVPNServers;
#[ORM\OneToMany(mappedBy: 'website', targetEntity: \App\Entity\Website\VPN\Service\Plan::class)]
private Collection $plans;
#[ORM\OneToMany(mappedBy: 'website', targetEntity: \App\Entity\Website\VPN\V2ray\Server::class)]
private Collection $v2rayServers;
public function subdomainAddress()
{
return $this->subdomain.'.tehranabr.org';
}
public function __construct()
{
$this->setTrafficUsage(0);
parent::__construct();
$now = new \DateTimeImmutable();
$this->setExpiredAt($now->modify("+7 days"));
$this->setPlanStartedAt($now);
$this->shopBalance = 0;
$this->customers = new ArrayCollection();
$this->pages = new ArrayCollection();
$this->articles = new ArrayCollection();
$this->categories = new ArrayCollection();
$this->tags = new ArrayCollection();
$this->transactions = new ArrayCollection();
$this->domains = new ArrayCollection();
$this->addOns = new ArrayCollection();
$this->settings = new ArrayCollection();
$this->serversUsages = new ArrayCollection();
$this->subPanelDomains = new ArrayCollection();
$this->smsIncomes = new ArrayCollection();
$this->vasetPals = new ArrayCollection();
$this->bots = new ArrayCollection();
$this->analytics = new ArrayCollection();
$this->campaigns = new ArrayCollection();
$this->costs = new ArrayCollection();
$this->costCategories = new ArrayCollection();
$this->websiteTransactions = new ArrayCollection();
$this->services = new ArrayCollection();
$this->servers = new ArrayCollection();
$this->openVPNServers = new ArrayCollection();
$this->plans = new ArrayCollection();
$this->v2rayServers = new ArrayCollection();
}
public function getId(): ?string
{
return $this->id;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): static
{
$this->name = $name;
return $this;
}
public function getSubdomain(): ?string
{
return $this->subdomain;
}
public function setSubdomain(string $subdomain): static
{
$this->subdomain = $subdomain;
return $this;
}
public function getShopBalance(): ?float
{
return $this->shopBalance;
}
public function setShopBalance(float $shopBalance): static
{
$this->shopBalance = $shopBalance;
return $this;
}
public function getOwner(): ?User
{
return $this->owner;
}
public function setOwner(?User $owner): static
{
$this->owner = $owner;
return $this;
}
/**
* @return Collection<int, Customer>
*/
public function getCustomers(): Collection
{
return $this->customers;
}
public function addCustomer(Customer $customer): static
{
if (!$this->customers->contains($customer)) {
$this->customers->add($customer);
$customer->setWebsite($this);
}
return $this;
}
public function removeCustomer(Customer $customer): static
{
if ($this->customers->removeElement($customer)) {
// set the owning side to null (unless already changed)
if ($customer->getWebsite() === $this) {
$customer->setWebsite(null);
}
}
return $this;
}
public function getTheme(): ?string
{
if ($this->theme == null){
return 'default';
}
return $this->theme;
}
public function setTheme(?string $theme): static
{
$this->theme = $theme;
return $this;
}
public function getAnalyticsData(): ?array
{
return $this->analyticsData;
}
public function setAnalyticsData(?array $analyticsData): static
{
$this->analyticsData = $analyticsData;
return $this;
}
public function getExpiredAt(): ?\DateTimeImmutable
{
return $this->expiredAt;
}
public function setExpiredAt(?\DateTimeImmutable $expiredAt): static
{
$this->expiredAt = $expiredAt;
return $this;
}
/**
* @return Collection<int, Page>
*/
public function getPages(): Collection
{
return $this->pages;
}
public function addPage(Page $page): static
{
if (!$this->pages->contains($page)) {
$this->pages->add($page);
$page->setWebsite($this);
}
return $this;
}
public function removePage(Page $page): static
{
if ($this->pages->removeElement($page)) {
// set the owning side to null (unless already changed)
if ($page->getWebsite() === $this) {
$page->setWebsite(null);
}
}
return $this;
}
/**
* @return Collection<int, Article>
*/
public function getArticles(): Collection
{
return $this->articles;
}
public function addArticle(Article $article): static
{
if (!$this->articles->contains($article)) {
$this->articles->add($article);
$article->setWebsite($this);
}
return $this;
}
public function removeArticle(Article $article): static
{
if ($this->articles->removeElement($article)) {
// set the owning side to null (unless already changed)
if ($article->getWebsite() === $this) {
$article->setWebsite(null);
}
}
return $this;
}
/**
* @return Collection<int, Category>
*/
public function getCategories(): Collection
{
return $this->categories;
}
public function addCategory(Category $category): static
{
if (!$this->categories->contains($category)) {
$this->categories->add($category);
$category->setWebsite($this);
}
return $this;
}
public function removeCategory(Category $category): static
{
if ($this->categories->removeElement($category)) {
// set the owning side to null (unless already changed)
if ($category->getWebsite() === $this) {
$category->setWebsite(null);
}
}
return $this;
}
/**
* @return Collection<int, Tag>
*/
public function getTags(): Collection
{
return $this->tags;
}
public function addTag(Tag $tag): static
{
if (!$this->tags->contains($tag)) {
$this->tags->add($tag);
$tag->setWebsite($this);
}
return $this;
}
public function removeTag(Tag $tag): static
{
if ($this->tags->removeElement($tag)) {
// set the owning side to null (unless already changed)
if ($tag->getWebsite() === $this) {
$tag->setWebsite(null);
}
}
return $this;
}
/**
* @return Collection<int, Transaction>
*/
public function getTransactions(): Collection
{
return $this->transactions;
}
public function addTransaction(Transaction $transaction): static
{
if (!$this->transactions->contains($transaction)) {
$this->transactions->add($transaction);
$transaction->getWebsite($this);
}
return $this;
}
public function removeTransaction(Transaction $transaction): static
{
if ($this->transactions->removeElement($transaction)) {
// set the owning side to null (unless already changed)
if ($transaction->getWebsite() === $this) {
$transaction->setWebsite(null);
}
}
return $this;
}
public function getTrafficUsage(): ?string
{
return $this->trafficUsage;
}
public function setTrafficUsage(string $trafficUsage): static
{
$this->trafficUsage = $trafficUsage;
return $this;
}
public function getCurrentPlanString()
{
if ($this->currentPlan){
return $this->currentPlan->getTitle();
}else{
return '';
}
}
/**
* @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->setWebsite($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->getWebsite() === $this) {
$domain->setWebsite(null);
}
}
return $this;
}
public function getCurrentPlan(): ?Plan
{
return $this->currentPlan;
}
public function setCurrentPlan(?Plan $currentPlan): static
{
$this->currentPlan = $currentPlan;
return $this;
}
/**
* @return Collection<int, AddOn>
*/
public function getAddOns(): Collection
{
return $this->addOns;
}
public function addAddOn(AddOn $addOn): static
{
if (!$this->addOns->contains($addOn)) {
$this->addOns->add($addOn);
$addOn->setWebsite($this);
}
return $this;
}
public function removeAddOn(AddOn $addOn): static
{
if ($this->addOns->removeElement($addOn)) {
// set the owning side to null (unless already changed)
if ($addOn->getWebsite() === $this) {
$addOn->getWebsite(null);
}
}
return $this;
}
public function getPlanStartedAt(): ?\DateTimeInterface
{
return $this->planStartedAt;
}
public function setPlanStartedAt(?\DateTimeInterface $planStartedAt): static
{
$this->planStartedAt = $planStartedAt;
return $this;
}
/**
* @return Collection<int, Setting>
*/
public function getSettings(): Collection
{
return $this->settings;
}
public function addSetting(Setting $setting): static
{
if (!$this->settings->contains($setting)) {
$this->settings->add($setting);
$setting->setWebsite($this);
}
return $this;
}
public function removeSetting(Setting $setting): static
{
if ($this->settings->removeElement($setting)) {
// set the owning side to null (unless already changed)
if ($setting->getWebsite() === $this) {
$setting->setWebsite(null);
}
}
return $this;
}
/**
* @return Collection<int, ServersUsage>
*/
public function getServersUsages(): Collection
{
return $this->serversUsages;
}
public function addServersUsage(ServersUsage $serversUsage): static
{
if (!$this->serversUsages->contains($serversUsage)) {
$this->serversUsages->add($serversUsage);
$serversUsage->setWebsite($this);
}
return $this;
}
public function removeServersUsage(ServersUsage $serversUsage): static
{
if ($this->serversUsages->removeElement($serversUsage)) {
// set the owning side to null (unless already changed)
if ($serversUsage->getWebsite() === $this) {
$serversUsage->setWebsite(null);
}
}
return $this;
}
/**
* @return Collection<int, \App\Entity\Website\Domains\Domain>
*/
public function getSubPanelDomains(): Collection
{
return $this->subPanelDomains;
}
public function addSubPanelDomain(\App\Entity\Website\Domains\Domain $subPanelDomain): static
{
if (!$this->subPanelDomains->contains($subPanelDomain)) {
$this->subPanelDomains->add($subPanelDomain);
$subPanelDomain->setWebsite($this);
}
return $this;
}
public function removeSubPanelDomain(\App\Entity\Website\Domains\Domain $subPanelDomain): static
{
if ($this->subPanelDomains->removeElement($subPanelDomain)) {
// set the owning side to null (unless already changed)
if ($subPanelDomain->getWebsite() === $this) {
$subPanelDomain->setWebsite(null);
}
}
return $this;
}
/**
* @return Collection<int, SmsIncome>
*/
public function getSmsIncomes(): Collection
{
return $this->smsIncomes;
}
public function addSmsIncome(SmsIncome $smsIncome): static
{
if (!$this->smsIncomes->contains($smsIncome)) {
$this->smsIncomes->add($smsIncome);
$smsIncome->setWebsite($this);
}
return $this;
}
public function removeSmsIncome(SmsIncome $smsIncome): static
{
if ($this->smsIncomes->removeElement($smsIncome)) {
// set the owning side to null (unless already changed)
if ($smsIncome->getWebsite() === $this) {
$smsIncome->setWebsite(null);
}
}
return $this;
}
/**
* @return Collection<int, VasetPal>
*/
public function getVasetPals(): Collection
{
return $this->vasetPals;
}
public function addVasetPal(VasetPal $vasetPal): static
{
if (!$this->vasetPals->contains($vasetPal)) {
$this->vasetPals->add($vasetPal);
$vasetPal->setWebsite($this);
}
return $this;
}
public function removeVasetPal(VasetPal $vasetPal): static
{
if ($this->vasetPals->removeElement($vasetPal)) {
// set the owning side to null (unless already changed)
if ($vasetPal->getWebsite() === $this) {
$vasetPal->setWebsite(null);
}
}
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->setWebsite($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->getWebsite() === $this) {
$bot->setWebsite(null);
}
}
return $this;
}
/**
* @return Collection<int, Analytics>
*/
public function getAnalytics(): Collection
{
return $this->analytics;
}
public function addAnalytic(Analytics $analytic): static
{
if (!$this->analytics->contains($analytic)) {
$this->analytics->add($analytic);
$analytic->setWebsite($this);
}
return $this;
}
public function removeAnalytic(Analytics $analytic): static
{
if ($this->analytics->removeElement($analytic)) {
// set the owning side to null (unless already changed)
if ($analytic->getWebsite() === $this) {
$analytic->setWebsite(null);
}
}
return $this;
}
/**
* @return Collection<int, Campaign>
*/
public function getCampaigns(): Collection
{
return $this->campaigns;
}
public function addCampaign(Campaign $campaign): static
{
if (!$this->campaigns->contains($campaign)) {
$this->campaigns->add($campaign);
$campaign->setWebsite($this);
}
return $this;
}
public function removeCampaign(Campaign $campaign): static
{
if ($this->campaigns->removeElement($campaign)) {
// set the owning side to null (unless already changed)
if ($campaign->getWebsite() === $this) {
$campaign->setWebsite(null);
}
}
return $this;
}
/**
* @return Collection<int, Cost>
*/
public function getCosts(): Collection
{
return $this->costs;
}
public function addCost(Cost $cost): static
{
if (!$this->costs->contains($cost)) {
$this->costs->add($cost);
$cost->setWebsite($this);
}
return $this;
}
public function removeCost(Cost $cost): static
{
if ($this->costs->removeElement($cost)) {
// set the owning side to null (unless already changed)
if ($cost->getWebsite() === $this) {
$cost->setWebsite(null);
}
}
return $this;
}
/**
* @return Collection<int, CostCategory>
*/
public function getCostCategories(): Collection
{
return $this->costCategories;
}
public function addCostCategory(CostCategory $costCategory): static
{
if (!$this->costCategories->contains($costCategory)) {
$this->costCategories->add($costCategory);
$costCategory->setWebsite($this);
}
return $this;
}
public function removeCostCategory(CostCategory $costCategory): static
{
if ($this->costCategories->removeElement($costCategory)) {
// set the owning side to null (unless already changed)
if ($costCategory->getWebsite() === $this) {
$costCategory->setWebsite(null);
}
}
return $this;
}
/**
* @return Collection<int, Transaction>
*/
public function getWebsiteTransactions(): Collection
{
return $this->websiteTransactions;
}
public function addWebsiteTransaction(Transaction $websiteTransaction): static
{
if (!$this->websiteTransactions->contains($websiteTransaction)) {
$this->websiteTransactions->add($websiteTransaction);
$websiteTransaction->setWebsite($this);
}
return $this;
}
public function removeWebsiteTransaction(Transaction $websiteTransaction): static
{
if ($this->websiteTransactions->removeElement($websiteTransaction)) {
// set the owning side to null (unless already changed)
if ($websiteTransaction->getWebsite() === $this) {
$websiteTransaction->setWebsite(null);
}
}
return $this;
}
/**
* @return Collection<int, Service>
*/
public function getServices(): Collection
{
return $this->services;
}
public function addService(Service $service): static
{
if (!$this->services->contains($service)) {
$this->services->add($service);
$service->setWebsite($this);
}
return $this;
}
public function removeService(Service $service): static
{
if ($this->services->removeElement($service)) {
// set the owning side to null (unless already changed)
if ($service->getWebsite() === $this) {
$service->setWebsite(null);
}
}
return $this;
}
/**
* @return Collection<int, Server>
*/
public function getServers(): Collection
{
return $this->servers;
}
public function addServer(Server $server): static
{
if (!$this->servers->contains($server)) {
$this->servers->add($server);
$server->setWebsite($this);
}
return $this;
}
public function removeServer(Server $server): static
{
if ($this->servers->removeElement($server)) {
// set the owning side to null (unless already changed)
if ($server->getWebsite() === $this) {
$server->setWebsite(null);
}
}
return $this;
}
/**
* @return Collection<int, \App\Entity\Website\VPN\OpenVPN\Server>
*/
public function getOpenVPNServers(): Collection
{
return $this->openVPNServers;
}
public function addOpenVPNServer(\App\Entity\Website\VPN\OpenVPN\Server $openVPNServer): static
{
if (!$this->openVPNServers->contains($openVPNServer)) {
$this->openVPNServers->add($openVPNServer);
$openVPNServer->setWebsite($this);
}
return $this;
}
public function removeOpenVPNServer(\App\Entity\Website\VPN\OpenVPN\Server $openVPNServer): static
{
if ($this->openVPNServers->removeElement($openVPNServer)) {
// set the owning side to null (unless already changed)
if ($openVPNServer->getWebsite() === $this) {
$openVPNServer->setWebsite(null);
}
}
return $this;
}
/**
* @return Collection<int, \App\Entity\Website\VPN\Service\Plan>
*/
public function getPlans(): Collection
{
return $this->plans;
}
public function addPlan(\App\Entity\Website\VPN\Service\Plan $plan): static
{
if (!$this->plans->contains($plan)) {
$this->plans->add($plan);
$plan->setWebsite($this);
}
return $this;
}
public function removePlan(\App\Entity\Website\VPN\Service\Plan $plan): static
{
if ($this->plans->removeElement($plan)) {
// set the owning side to null (unless already changed)
if ($plan->getWebsite() === $this) {
$plan->setWebsite(null);
}
}
return $this;
}
/**
* @return Collection<int, \App\Entity\Website\VPN\V2ray\Server>
*/
public function getV2rayServers(): Collection
{
return $this->v2rayServers;
}
public function addV2rayServer(\App\Entity\Website\VPN\V2ray\Server $v2rayServer): static
{
if (!$this->v2rayServers->contains($v2rayServer)) {
$this->v2rayServers->add($v2rayServer);
$v2rayServer->setWebsite($this);
}
return $this;
}
public function removeV2rayServer(\App\Entity\Website\VPN\V2ray\Server $v2rayServer): static
{
if ($this->v2rayServers->removeElement($v2rayServer)) {
// set the owning side to null (unless already changed)
if ($v2rayServer->getWebsite() === $this) {
$v2rayServer->setWebsite(null);
}
}
return $this;
}
}