src/Entity/Store/Store.php line 29

  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Entity\Store;
  4. use App\Entity\Deal\Deal;
  5. use App\Entity\Discount\DiscountCoupon;
  6. use App\Enum\BillingTypesEnum;
  7. use App\Enum\SubscriptionTypeEnum;
  8. use App\Repository\Store\StoreRepository;
  9. use DateTime;
  10. use Doctrine\Common\Collections\ArrayCollection;
  11. use Doctrine\Common\Collections\Collection;
  12. use Doctrine\ORM\Mapping\Column;
  13. use Doctrine\ORM\Mapping\Entity;
  14. use Doctrine\ORM\Mapping\GeneratedValue;
  15. use Doctrine\ORM\Mapping\Id;
  16. use Doctrine\ORM\Mapping\JoinColumn;
  17. use Doctrine\ORM\Mapping\ManyToOne;
  18. use Doctrine\ORM\Mapping\OneToMany;
  19. use Doctrine\ORM\Mapping\Table;
  20. use Symfony\Component\Security\Core\User\UserInterface;
  21. use function in_array;
  22. #[Entity(repositoryClass: StoreRepository::class)]
  23. #[Table(name: 'app_store')]
  24. class Store implements UserInterface
  25. {
  26.     #[Id]
  27.     #[Column(type: 'integer')]
  28.     #[GeneratedValue]
  29.     private int $id;
  30.     #[Column(type: 'string', unique: true)]
  31.     private string $name;
  32.     #[Column(type: 'string')]
  33.     private string $state;
  34.     #[Column(type: 'json')]
  35.     private array $roles = [];
  36.     #[Column(type: 'string', nullable: true)]
  37.     private ?string $email = null;
  38.     #[Column(name: 'totally_new', type: 'boolean', options: ['default' => true])]
  39.     private bool $totallyNew = true;
  40.     #[Column(name: 'keep_quantity_input', type: 'boolean', options: ['default' => false])]
  41.     private bool $keepQuantityInput = false;
  42.     #[Column(name: 'active_theme_id', nullable: true)]
  43.     private ?string $activeThemeId = null;
  44.     #[Column(type: 'string', nullable: true, enumType: BillingTypesEnum::class)]
  45.     private ?BillingTypesEnum $billingType = null;
  46.     #[Column(type: 'string', nullable: true)]
  47.     private ?string $currency = null;
  48.     #[Column(name: 'money_format', type: 'string', nullable: true)]
  49.     private ?string $moneyFormat = null;
  50.     #[Column(name: 'access_token', type: 'string', nullable: true)]
  51.     private ?string $accessToken = null;
  52.     #[Column(type: 'string', nullable: true)]
  53.     private ?string $plan = null;
  54.     #[Column(name: 'mailerlite_id', type: 'string', nullable: true)]
  55.     private ?string $mailerLiteId = null;
  56.     #[Column(name: 'installed_at', type: 'datetime', nullable: true)]
  57.     private ?DateTime $installedAt = null;
  58.     #[Column(name: 'uninstalled_at', type: 'datetime', nullable: true)]
  59.     private ?DateTime $uninstalledAt = null;
  60.     #[OneToMany(mappedBy: 'store', targetEntity: Deal::class)]
  61.     private Collection $deals;
  62.     #[ManyToOne(targetEntity: DiscountCoupon::class)]
  63.     #[JoinColumn(name: 'discount_coupon_id', referencedColumnName: 'id')]
  64.     private ?DiscountCoupon $discountCoupon = null;
  65.     #[Column(type: 'string', nullable: true)]
  66.     private ?string $subscriptionId = null;
  67.     #[Column(type: 'string', enumType: SubscriptionTypeEnum::class, options: ['default' => SubscriptionTypeEnum::Paid])]
  68.     private SubscriptionTypeEnum $subscriptionType = SubscriptionTypeEnum::Paid;
  69.     public function __construct()
  70.     {
  71.         $this->deals = new ArrayCollection();
  72.     }
  73.     public function getId(): int
  74.     {
  75.         return $this->id;
  76.     }
  77.     public function setName(string $name): Store
  78.     {
  79.         $this->name = $name;
  80.         return $this;
  81.     }
  82.     public function getName(): string
  83.     {
  84.         return $this->name;
  85.     }
  86.     public function getAccessToken(): ?string
  87.     {
  88.         return $this->accessToken;
  89.     }
  90.     public function setAccessToken(?string $accessToken): Store
  91.     {
  92.         $this->accessToken = $accessToken;
  93.         return $this;
  94.     }
  95.     public function getEmail(): ?string
  96.     {
  97.         return $this->email;
  98.     }
  99.     public function setEmail(?string $email): Store
  100.     {
  101.         $this->email = $email;
  102.         return $this;
  103.     }
  104.     public function addDeal(Deal $deal): Store
  105.     {
  106.         if ($this->deals->contains($deal) === false) {
  107.             $this->deals->add($deal);
  108.             $deal->setStore($this);
  109.         }
  110.         return $this;
  111.     }
  112.     public function setDeals(Collection $deals): Store
  113.     {
  114.         $this->deals = $deals;
  115.         return $this;
  116.     }
  117.     public function getDeals(): Collection
  118.     {
  119.         return $this->deals;
  120.     }
  121.     public function getBillingType(): ?BillingTypesEnum
  122.     {
  123.         return $this->billingType;
  124.     }
  125.     public function setBillingType(?BillingTypesEnum $billingType): Store
  126.     {
  127.         $this->billingType = $billingType;
  128.         return $this;
  129.     }
  130.     public function getDealsByDiscountId(string $discountId): Collection
  131.     {
  132.         return $this->deals->filter(fn(Deal $deal) => $deal->getDiscountId() === $discountId);
  133.     }
  134.     public function isTotallyNew(): bool
  135.     {
  136.         return $this->totallyNew;
  137.     }
  138.     public function setTotallyNew(bool $totallyNew): Store
  139.     {
  140.         $this->totallyNew = $totallyNew;
  141.         return $this;
  142.     }
  143.     public function getMailerLiteId(): ?string
  144.     {
  145.         return $this->mailerLiteId;
  146.     }
  147.     public function setMailerLiteId(?string $mailerLiteId): Store
  148.     {
  149.         $this->mailerLiteId = $mailerLiteId;
  150.         return $this;
  151.     }
  152.     public function getSubscriptionId(): ?string
  153.     {
  154.         return $this->subscriptionId;
  155.     }
  156.     public function setSubscriptionId(?string $subscriptionId): Store
  157.     {
  158.         $this->subscriptionId = $subscriptionId;
  159.         return $this;
  160.     }
  161.     public function getState(): string
  162.     {
  163.         return $this->state;
  164.     }
  165.     public function setState(string $state): Store
  166.     {
  167.         $this->state = $state;
  168.         return $this;
  169.     }
  170.     public function isKeepQuantityInput(): bool
  171.     {
  172.         return $this->keepQuantityInput;
  173.     }
  174.     public function setKeepQuantityInput(bool $keepQuantityInput): Store
  175.     {
  176.         $this->keepQuantityInput = $keepQuantityInput;
  177.         return $this;
  178.     }
  179.     public function getSubscriptionType(): SubscriptionTypeEnum
  180.     {
  181.         return $this->subscriptionType;
  182.     }
  183.     public function setSubscriptionType(SubscriptionTypeEnum $subscriptionType): Store
  184.     {
  185.         $this->subscriptionType = $subscriptionType;
  186.         return $this;
  187.     }
  188.     public function markInstalled(): Store
  189.     {
  190.         $this->installedAt = new DateTime();
  191.         return $this;
  192.     }
  193.     public function getPlan(): ?string
  194.     {
  195.         return $this->plan;
  196.     }
  197.     public function setPlan(?string $plan): Store
  198.     {
  199.         $this->plan = $plan;
  200.         return $this;
  201.     }
  202.     public function getInstalledAt(): ?DateTime
  203.     {
  204.         return $this->installedAt;
  205.     }
  206.     public function setUninstalledAt(?DateTime $uninstalledAt): Store
  207.     {
  208.         $this->uninstalledAt = $uninstalledAt;
  209.         return $this;
  210.     }
  211.     public function markUnInstalled(): Store
  212.     {
  213.         $this->uninstalledAt = new DateTime();
  214.         return $this;
  215.     }
  216.     public function getUnInstalledAt(): ?DateTime
  217.     {
  218.         return $this->uninstalledAt;
  219.     }
  220.     public function getDiscountCoupon(): ?DiscountCoupon
  221.     {
  222.         return $this->discountCoupon;
  223.     }
  224.     public function setDiscountCoupon(?DiscountCoupon $discountCoupon): Store
  225.     {
  226.         $this->discountCoupon = $discountCoupon;
  227.         return $this;
  228.     }
  229.     public function getActiveThemeId(): ?string
  230.     {
  231.         return $this->activeThemeId;
  232.     }
  233.     public function setActiveThemeId(?string $activeThemeId): Store
  234.     {
  235.         $this->activeThemeId = $activeThemeId;
  236.         return $this;
  237.     }
  238.     public function getCurrency(): ?string
  239.     {
  240.         return $this->currency;
  241.     }
  242.     public function setCurrency(?string $currency): Store
  243.     {
  244.         $this->currency = $currency;
  245.         return $this;
  246.     }
  247.     public function getMoneyFormat(): ?string
  248.     {
  249.         return $this->moneyFormat;
  250.     }
  251.     public function setMoneyFormat(?string $moneyFormat): Store
  252.     {
  253.         $this->moneyFormat = $moneyFormat;
  254.         return $this;
  255.     }
  256.     /** @return string[] */
  257.     public function getRoles(): array
  258.     {
  259.         return $this->roles;
  260.     }
  261.     public function addApiAccessRole(): Store
  262.     {
  263.         return $this->addRole('ROLE_API_USER');
  264.     }
  265.     public function addPaidUserRole(): Store
  266.     {
  267.         return $this->addRole('ROLE_PAID_USER');
  268.     }
  269.     public function removePaidUserRole(): Store
  270.     {
  271.         return $this->removeRole('ROLE_PAID_USER');
  272.     }
  273.     public function isPaid(): bool
  274.     {
  275.         return $this->hasRole('ROLE_PAID_USER');
  276.     }
  277.     public function hasRole(string $role): bool
  278.     {
  279.         return in_array($role, $this->roles, true);
  280.     }
  281.     public function addRole(string $role): Store
  282.     {
  283.         if (in_array($role, $this->roles, true) === false) {
  284.             $this->roles[] = $role;
  285.         }
  286.         return $this;
  287.     }
  288.     public function removeRole(string $role): Store
  289.     {
  290.         $this->roles = array_filter($this->roles, static fn(string $r): bool => $r !== $role);
  291.         return $this;
  292.     }
  293.     public function eraseCredentials(): void
  294.     {
  295.     }
  296.     public function getUserIdentifier(): string
  297.     {
  298.         return $this->getName();
  299.     }
  300. }