<?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\MarketingPanel\SmsTemplate;
use App\Entity\Website\Accounting\Transaction;
use App\Entity\Website\Blog\Article;
use App\Entity\Website\Blog\Category;
use App\Entity\Website\Blog\Tag;
use App\Entity\Website\Cart\Cart;
use App\Entity\Website\Cart\CartItem;
use App\Entity\Website\Cart\CartItemAttribute;
use App\Entity\Website\Menu\Menu;
use App\Entity\Website\Order\Coupon;
use App\Entity\Website\Order\Discount;
use App\Entity\Website\Order\Order;
use App\Entity\Website\Order\ShippingMethod;
use App\Entity\Website\Page\Page;
use App\Entity\Website\PostType\PostType;
use App\Entity\Website\Product\Product;
use App\Entity\Website\Product\ProductAttribute;
use App\Entity\Website\Product\ProductAttributeValue;
use App\Entity\Website\Product\ProductCategory;
use App\Entity\Website\Setting;
use App\Entity\Website\Ticket\Ticket;
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\OneToMany(mappedBy: 'website', targetEntity: Product::class)]
private Collection $products;
#[ORM\OneToMany(mappedBy: 'website', targetEntity: ProductAttribute::class)]
private Collection $productAttributes;
#[ORM\OneToMany(mappedBy: 'website', targetEntity: ProductAttributeValue::class)]
private Collection $productAttributeValues;
#[ORM\OneToMany(mappedBy: 'website', targetEntity: Discount::class)]
private Collection $discounts;
#[ORM\OneToMany(mappedBy: 'website', targetEntity: Cart::class)]
private Collection $carts;
#[ORM\OneToMany(mappedBy: 'website', targetEntity: CartItem::class)]
private Collection $cartItems;
#[ORM\OneToMany(mappedBy: 'website', targetEntity: CartItemAttribute::class)]
private Collection $cartItemAttributes;
#[ORM\OneToMany(mappedBy: 'website', targetEntity: Coupon::class)]
private Collection $coupons;
#[ORM\OneToMany(mappedBy: 'website', targetEntity: Order::class)]
private Collection $orders;
#[ORM\OneToMany(mappedBy: 'website', targetEntity: ShippingMethod::class)]
private Collection $shippingMethods;
#[ORM\Column(length: 255, nullable: true)]
private ?string $theme = null;
#[ORM\OneToMany(mappedBy: 'website', targetEntity: ProductCategory::class)]
private Collection $productCategories;
#[ORM\Column(nullable: true)]
private ?array $analyticsData = null;
#[ORM\Column(nullable: true)]
private ?\DateTimeImmutable $expiredAt = null;
#[ORM\OneToMany(mappedBy: 'website', targetEntity: PostType::class)]
private Collection $postTypes;
#[ORM\OneToMany(mappedBy: 'website', targetEntity: Menu::class)]
private Collection $menus;
#[ORM\OneToMany(mappedBy: 'website', targetEntity: Setting::class)]
private Collection $settings;
#[ORM\OneToMany(mappedBy: 'website', targetEntity: Page::class)]
private Collection $pages;
#[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: Tag::class)]
private Collection $tags;
#[ORM\OneToMany(mappedBy: 'website', targetEntity: Ticket::class)]
private Collection $tickets;
#[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: SmsTemplate::class)]
private Collection $smsTemplates;
public function subdomainAddress()
{
return $this->subdomain.'.poooshe.com';
}
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->products = new ArrayCollection();
$this->productAttributes = new ArrayCollection();
$this->productAttributeValues = new ArrayCollection();
$this->discounts = new ArrayCollection();
$this->carts = new ArrayCollection();
$this->cartItems = new ArrayCollection();
$this->cartItemAttributes = new ArrayCollection();
$this->coupons = new ArrayCollection();
$this->orders = new ArrayCollection();
$this->shippingMethods = new ArrayCollection();
$this->productCategories = new ArrayCollection();
$this->postTypes = new ArrayCollection();
$this->menus = new ArrayCollection();
$this->settings = new ArrayCollection();
$this->pages = new ArrayCollection();
$this->articles = new ArrayCollection();
$this->categories = new ArrayCollection();
$this->tags = new ArrayCollection();
$this->tickets = new ArrayCollection();
$this->transactions = new ArrayCollection();
$this->domains = new ArrayCollection();
$this->addOns = new ArrayCollection();
$this->smsTemplates = 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;
}
/**
* @return Collection<int, Product>
*/
public function getProducts(): Collection
{
return $this->products;
}
public function addProduct(Product $product): static
{
if (!$this->products->contains($product)) {
$this->products->add($product);
$product->setWebsite($this);
}
return $this;
}
public function removeProduct(Product $product): static
{
if ($this->products->removeElement($product)) {
// set the owning side to null (unless already changed)
if ($product->getWebsite() === $this) {
$product->setWebsite(null);
}
}
return $this;
}
/**
* @return Collection<int, ProductAttribute>
*/
public function getProductAttributes(): Collection
{
return $this->productAttributes;
}
public function addProductAttribute(ProductAttribute $productAttribute): static
{
if (!$this->productAttributes->contains($productAttribute)) {
$this->productAttributes->add($productAttribute);
$productAttribute->setWebsite($this);
}
return $this;
}
public function removeProductAttribute(ProductAttribute $productAttribute): static
{
if ($this->productAttributes->removeElement($productAttribute)) {
// set the owning side to null (unless already changed)
if ($productAttribute->getWebsite() === $this) {
$productAttribute->setWebsite(null);
}
}
return $this;
}
/**
* @return Collection<int, ProductAttributeValue>
*/
public function getProductAttributeValues(): Collection
{
return $this->productAttributeValues;
}
public function addProductAttributeValue(ProductAttributeValue $productAttributeValue): static
{
if (!$this->productAttributeValues->contains($productAttributeValue)) {
$this->productAttributeValues->add($productAttributeValue);
$productAttributeValue->setWebsite($this);
}
return $this;
}
public function removeProductAttributeValue(ProductAttributeValue $productAttributeValue): static
{
if ($this->productAttributeValues->removeElement($productAttributeValue)) {
// set the owning side to null (unless already changed)
if ($productAttributeValue->getWebsite() === $this) {
$productAttributeValue->setWebsite(null);
}
}
return $this;
}
/**
* @return Collection<int, Discount>
*/
public function getDiscounts(): Collection
{
return $this->discounts;
}
public function addDiscount(Discount $discount): static
{
if (!$this->discounts->contains($discount)) {
$this->discounts->add($discount);
$discount->setWebsite($this);
}
return $this;
}
public function removeDiscount(Discount $discount): static
{
if ($this->discounts->removeElement($discount)) {
// set the owning side to null (unless already changed)
if ($discount->getWebsite() === $this) {
$discount->setWebsite(null);
}
}
return $this;
}
/**
* @return Collection<int, Cart>
*/
public function getCarts(): Collection
{
return $this->carts;
}
public function addCart(Cart $cart): static
{
if (!$this->carts->contains($cart)) {
$this->carts->add($cart);
$cart->setWebsite($this);
}
return $this;
}
public function removeCart(Cart $cart): static
{
if ($this->carts->removeElement($cart)) {
// set the owning side to null (unless already changed)
if ($cart->getWebsite() === $this) {
$cart->setWebsite(null);
}
}
return $this;
}
/**
* @return Collection<int, CartItem>
*/
public function getCartItems(): Collection
{
return $this->cartItems;
}
public function addCartItem(CartItem $cartItem): static
{
if (!$this->cartItems->contains($cartItem)) {
$this->cartItems->add($cartItem);
$cartItem->setWebsite($this);
}
return $this;
}
public function removeCartItem(CartItem $cartItem): static
{
if ($this->cartItems->removeElement($cartItem)) {
// set the owning side to null (unless already changed)
if ($cartItem->getWebsite() === $this) {
$cartItem->setWebsite(null);
}
}
return $this;
}
/**
* @return Collection<int, CartItemAttribute>
*/
public function getCartItemAttributes(): Collection
{
return $this->cartItemAttributes;
}
public function addCartItemAttribute(CartItemAttribute $cartItemAttribute): static
{
if (!$this->cartItemAttributes->contains($cartItemAttribute)) {
$this->cartItemAttributes->add($cartItemAttribute);
$cartItemAttribute->setWebsite($this);
}
return $this;
}
public function removeCartItemAttribute(CartItemAttribute $cartItemAttribute): static
{
if ($this->cartItemAttributes->removeElement($cartItemAttribute)) {
// set the owning side to null (unless already changed)
if ($cartItemAttribute->getWebsite() === $this) {
$cartItemAttribute->setWebsite(null);
}
}
return $this;
}
/**
* @return Collection<int, Coupon>
*/
public function getCoupons(): Collection
{
return $this->coupons;
}
public function addCoupon(Coupon $coupon): static
{
if (!$this->coupons->contains($coupon)) {
$this->coupons->add($coupon);
$coupon->setWebsite($this);
}
return $this;
}
public function removeCoupon(Coupon $coupon): static
{
if ($this->coupons->removeElement($coupon)) {
// set the owning side to null (unless already changed)
if ($coupon->getWebsite() === $this) {
$coupon->setWebsite(null);
}
}
return $this;
}
/**
* @return Collection<int, Order>
*/
public function getOrders(): Collection
{
return $this->orders;
}
public function addOrder(Order $order): static
{
if (!$this->orders->contains($order)) {
$this->orders->add($order);
$order->setWebsite($this);
}
return $this;
}
public function removeOrder(Order $order): static
{
if ($this->orders->removeElement($order)) {
// set the owning side to null (unless already changed)
if ($order->getWebsite() === $this) {
$order->setWebsite(null);
}
}
return $this;
}
/**
* @return Collection<int, ShippingMethod>
*/
public function getShippingMethods(): Collection
{
return $this->shippingMethods;
}
public function addShippingMethod(ShippingMethod $shippingMethod): static
{
if (!$this->shippingMethods->contains($shippingMethod)) {
$this->shippingMethods->add($shippingMethod);
$shippingMethod->setWebsite($this);
}
return $this;
}
public function removeShippingMethod(ShippingMethod $shippingMethod): static
{
if ($this->shippingMethods->removeElement($shippingMethod)) {
// set the owning side to null (unless already changed)
if ($shippingMethod->getWebsite() === $this) {
$shippingMethod->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;
}
/**
* @return Collection<int, ProductCategory>
*/
public function getProductCategories(): Collection
{
return $this->productCategories;
}
public function addProductCategory(ProductCategory $productCategory): static
{
if (!$this->productCategories->contains($productCategory)) {
$this->productCategories->add($productCategory);
$productCategory->setWebsite($this);
}
return $this;
}
public function removeProductCategory(ProductCategory $productCategory): static
{
if ($this->productCategories->removeElement($productCategory)) {
// set the owning side to null (unless already changed)
if ($productCategory->getWebsite() === $this) {
$productCategory->setWebsite(null);
}
}
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, PostType>
*/
public function getPostTypes(): Collection
{
return $this->postTypes;
}
public function addPostType(PostType $postType): static
{
if (!$this->postTypes->contains($postType)) {
$this->postTypes->add($postType);
$postType->setWebsite($this);
}
return $this;
}
public function removePostType(PostType $postType): static
{
if ($this->postTypes->removeElement($postType)) {
// set the owning side to null (unless already changed)
if ($postType->getWebsite() === $this) {
$postType->setWebsite(null);
}
}
return $this;
}
/**
* @return Collection<int, Menu>
*/
public function getMenus(): Collection
{
return $this->menus;
}
public function addMenu(Menu $menu): static
{
if (!$this->menus->contains($menu)) {
$this->menus->add($menu);
$menu->setWebsite($this);
}
return $this;
}
public function removeMenu(Menu $menu): static
{
if ($this->menus->removeElement($menu)) {
// set the owning side to null (unless already changed)
if ($menu->getWebsite() === $this) {
$menu->setWebsite(null);
}
}
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, 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, Ticket>
*/
public function getTickets(): Collection
{
return $this->tickets;
}
public function addTicket(Ticket $ticket): static
{
if (!$this->tickets->contains($ticket)) {
$this->tickets->add($ticket);
$ticket->setWebsite($this);
}
return $this;
}
public function removeTicket(Ticket $ticket): static
{
if ($this->tickets->removeElement($ticket)) {
// set the owning side to null (unless already changed)
if ($ticket->getWebsite() === $this) {
$ticket->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, SmsTemplate>
*/
public function getSmsTemplates(): Collection
{
return $this->smsTemplates;
}
public function addSmsTemplate(SmsTemplate $smsTemplate): static
{
if (!$this->smsTemplates->contains($smsTemplate)) {
$this->smsTemplates->add($smsTemplate);
$smsTemplate->setWebsite($this);
}
return $this;
}
public function removeSmsTemplate(SmsTemplate $smsTemplate): static
{
if ($this->smsTemplates->removeElement($smsTemplate)) {
// set the owning side to null (unless already changed)
if ($smsTemplate->getWebsite() === $this) {
$smsTemplate->setWebsite(null);
}
}
return $this;
}
}