<?php
namespace App\Entity;
use App\Repository\WidgetRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Nelmio\ApiDocBundle\Annotation\Model;
use Ramsey\Uuid\Uuid;
use Ramsey\Uuid\UuidInterface;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Validator\Constraints as Assert;
use OpenApi\Annotations as OA;
/**
* @ORM\Entity(repositoryClass=WidgetRepository::class)
*/
class Widget
{
public const FONT_VARIANTS = [
'Inter' => 'Inter',
'Lato' => 'Lato',
'Avenir Next' => 'Avenir Next',
'Roboto' => 'Roboto',
'Gotham' => 'Gotham',
'Museo Sans Cyrl' => 'Museo Sans Cyrl',
'Helvetica Neue' => 'Helvetica Neue',
'Arial' => 'Arial',
];
public const DELIVERY_VARIANTS = [
'Email' => 'Email',
'SMS' => 'SMS',
'Благотворительность' => 'Charity',
];
/**
* @Groups("widget")
* @ORM\Id
* @ORM\Column(type="uuid", unique=true)
* @ORM\GeneratedValue(strategy="NONE")
* @OA\Property(
* type="string",
* )
* @Assert\NotBlank()
*/
private $id;
/**
* @Groups({"widget"})
* @ORM\Column(type="string", length=255)
* @Assert\NotBlank()
*/
private $name;
/**
* @Groups({"widget"})
* @ORM\Column(type="string", length=255)
* @Assert\NotBlank()
*/
private $domain;
/**
* @Groups({"widget"})
* @ORM\ManyToOne(targetEntity=WidgetUser::class, inversedBy="widgets", cascade={"persist"})
* @ORM\JoinColumn(nullable=false)
* @Assert\NotBlank()
* @OA\Property(
* type="object",
* ref=@Model(type=WidgetUser::class)
* )
*/
private $Client;
/**
* @Groups({"widget"})
* @ORM\Column(type="string", name="ykassa_dsn", length=255, nullable=true)
*/
private $ykassaDsn;
/**
* @Groups({"widget"})
* @ORM\ManyToOne(targetEntity=MailTemplate::class, inversedBy="widgets", fetch="EAGER", cascade={"persist"})
* @ORM\JoinColumn(nullable=false)
* @OA\Property(
* type="object",
* ref=@Model(type=MailTemplate::class, groups={"widget","template"})
* )
*/
private $mailTemplate;
/**
* @Groups("widget")
* @ORM\Column(type="string", length=255)
*/
private $primaryBackgroundColor;
/**
* @Groups("widget")
* @ORM\Column(type="string", length=255)
*/
private $primaryColor;
/**
* @Groups("widget")
* @ORM\Column(type="string", length=255)
*/
private $iconsColor;
/**
* @Groups("widget")
* @ORM\Column(type="string", length=255)
*/
private $circlesColor;
/**
* @Groups("widget")
* @ORM\Column(type="string", length=255)
*/
private $starsColor;
/**
* @Groups("widget")
* @ORM\Column(type="string", length=255)
*/
private $ribbonColor;
/**
* @Groups("widget")
* @ORM\Column(type="string", length=255)
*/
private $logotypeImage;
/**
* @Groups("widget")
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $logotypeLink;
/**
* @Groups("widget")
* @ORM\Column(type="string", length=255)
*/
private $faviconImage;
/**
* @Groups("widget")
* @ORM\Column(type="string", length=255)
*/
private $metaTitle;
/**
* @Groups("widget")
* @ORM\Column(type="string", length=255)
*/
private $font;
/**
* @Groups("widget")
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $externalCssFile;
/**
* @Groups("widget")
* @ORM\Column(type="string", length=255)
*/
private $supportTelNumber;
/**
* @Groups("widget")
* @ORM\Column(type="string", length=255)
*/
private $supportEmail;
/**
* @Groups("widget")
* @ORM\Column(type="array")
*/
private $deliveryVariants = [];
/**
* @Groups("widget")
* @ORM\Column(type="boolean", nullable=true)
*/
private $sendToFriend;
/**
* @Groups("widget")
* @ORM\Column(type="string", length=255)
*/
private $orderService;
/**
* @Groups("widget")
* @ORM\Column(type="text")
*/
private $offer;
/**
* @var array
* @Groups("widget")
* @ORM\Column(type="array", nullable=true)
*/
private $faq = [];
/**
* @Groups("widget")
* @ORM\Column(type="string", length=255)
*/
private $hiwCreateTitle;
/**
* @Groups("widget")
* @ORM\Column(type="string", length=255)
*/
private $hiwCreateText;
/**
* @Groups("widget")
* @ORM\Column(type="string", length=255)
*/
private $hiwReceiveTitle;
/**
* @Groups("widget")
* @ORM\Column(type="string", length=255)
*/
private $hiwReceiveText;
/**
* @Groups("widget")
* @ORM\Column(type="string", length=255)
*/
private $hiwGladTitle;
/**
* @Groups("widget")
* @ORM\Column(type="string", length=255)
*/
private $hiwGladText;
/**
* @Groups("widget")
* @ORM\Column(type="text")
*/
private $rulesText;
/**
* @Groups("widget")
* @ORM\Column(type="string", length=255)
*/
private $products;
/**
* @ORM\OneToMany(targetEntity=Order::class, mappedBy="widget")
*/
private $orders;
/**
* @ORM\OneToMany(targetEntity=UserFile::class, mappedBy="widget")
*/
private $userFiles;
/**
* @Groups("cover")
* @ORM\Column(type="array", nullable=true)
*/
private $covers = [];
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $order_service_dsn_login;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $order_service_dsn_password;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $order_service_dsn_url;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $order_service_dsn_port;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $id_metric_google;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $id_metric_yandex;
/**
* @ORM\ManyToMany(targetEntity=WidgetUser::class, inversedBy="widgets")
*/
private $widgetUsers;
/**
* @Groups("widget")
* @ORM\Column(type="boolean", nullable=true)
*/
private $customDesign;
/**
* @ORM\Column(type="json", nullable=true)
*/
private $usageRules = [];
/**
* @Groups("widget")
* @ORM\Column(type="string", length=255)
*/
private $backgroundImage;
/**
* @ORM\Column(type="json", nullable=true)
*/
private $saleProductIds = [];
/**
* @Groups("widget")
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $saleImage;
/**
* @Groups("widget")
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $saleColor;
/**
* @Groups("widget")
* @ORM\Column(type="boolean")
*/
private $canWholesale = false;
/**
* @Groups("widget")
* @ORM\Column(type="text", nullable=true)
*/
private $bxCorporateScript;
/**
* @Groups("widget")
* @ORM\Column(type="boolean")
*/
private $enableBxCorporateScript;
/**
* @Groups("widget")
* @ORM\Column(type="boolean")
*/
private $productDefaultRemains;
/**
* Разрешать использовать ИИ для генерации текста
*
* @Groups("widget")
* @ORM\Column(type="boolean")
*/
private bool $aiTextEnable;
/**
* Разрешать использовать ИИ для генерации изображений
*
* @Groups("widget")
* @ORM\Column(type="boolean")
*/
private bool $aiImageEnable;
/**
* Отправлять PIN по sms
*
* @Groups("widget")
* @ORM\Column(type="boolean")
*/
private $sendSmsPin;
/**
* ID поставщика в ПЦ
*
* @Groups("widget")
* @ORM\Column(type="text")
*/
private $supplierId;
public function __construct()
{
$this->orders = new ArrayCollection();
$this->id = Uuid::uuid4();
$this->widgetUsers = new ArrayCollection();
$this->userFiles = new ArrayCollection();
}
public function __toString()
{
return $this->getName();
}
public function setId(string $id): self
{
$this->id = $id;
return $this;
}
public function getId(): ?UuidInterface
{
return $this->id;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
public function getDomain(): ?string
{
return $this->domain;
}
public function setDomain(string $domain): self
{
$this->domain = $domain;
return $this;
}
public function getClient(): ?WidgetUser
{
return $this->Client;
}
public function setClient(?WidgetUser $Client): self
{
$this->Client = $Client;
return $this;
}
public function getYkassaDsn(): ?string
{
return $this->ykassaDsn;
}
public function setYkassaDsn(?string $ykassaDsn): self
{
$this->ykassaDsn = $ykassaDsn;
return $this;
}
public function getMailTemplate(): ?MailTemplate
{
return $this->mailTemplate;
}
public function setMailTemplate(?MailTemplate $mailTemplate): self
{
$this->mailTemplate = $mailTemplate;
return $this;
}
public function getPrimaryBackgroundColor(): ?string
{
return $this->primaryBackgroundColor;
}
public function setPrimaryBackgroundColor(string $primaryBackgroundColor): self
{
$this->primaryBackgroundColor = $primaryBackgroundColor;
return $this;
}
public function getPrimaryColor(): ?string
{
return $this->primaryColor;
}
public function setPrimaryColor(string $primaryColor): self
{
$this->primaryColor = $primaryColor;
return $this;
}
public function getIconsColor(): ?string
{
return $this->iconsColor;
}
public function setIconsColor(string $iconsColor): self
{
$this->iconsColor = $iconsColor;
return $this;
}
public function getCirclesColor(): ?string
{
return $this->circlesColor;
}
public function setCirclesColor(string $circlesColor): self
{
$this->circlesColor = $circlesColor;
return $this;
}
public function getStarsColor(): ?string
{
return $this->starsColor;
}
public function setStarsColor(string $starsColor): self
{
$this->starsColor = $starsColor;
return $this;
}
public function getRibbonColor(): ?string
{
return $this->ribbonColor;
}
public function setRibbonColor(string $ribbonColor): self
{
$this->ribbonColor = $ribbonColor;
return $this;
}
public function getLogotypeImage(): ?string
{
return $this->logotypeImage;
}
public function setLogotypeImage(string $logotypeImage): self
{
$this->logotypeImage = $logotypeImage;
return $this;
}
public function getLogotypeLink(): ?string
{
return $this->logotypeLink;
}
public function setLogotypeLink(?string $logotypeLink): self
{
$this->logotypeLink = $logotypeLink;
return $this;
}
public function getFaviconImage(): ?string
{
return $this->faviconImage;
}
public function setFaviconImage(string $faviconImage): self
{
$this->faviconImage = $faviconImage;
return $this;
}
public function getMetaTitle(): ?string
{
return $this->metaTitle;
}
public function setMetaTitle(string $metaTitle): self
{
$this->metaTitle = $metaTitle;
return $this;
}
public function getFont(): ?string
{
return $this->font;
}
public function setFont(string $font): self
{
$this->font = $font;
return $this;
}
public function getExternalCssFile(): ?string
{
return $this->externalCssFile;
}
public function setExternalCssFile(?string $externalCssFile): self
{
$this->externalCssFile = $externalCssFile;
return $this;
}
public function getSupportTelNumber(): ?string
{
return $this->supportTelNumber;
}
public function setSupportTelNumber(string $supportTelNumber): self
{
$this->supportTelNumber = $supportTelNumber;
return $this;
}
public function getSupportEmail(): ?string
{
return $this->supportEmail;
}
public function setSupportEmail(string $supportEmail): self
{
$this->supportEmail = $supportEmail;
return $this;
}
/**
* @return string[]|null
* @OA\Property(
* type="string[]"
* )
*/
public function getDeliveryVariants(): ?array
{
return $this->deliveryVariants;
}
public function setDeliveryVariants(array $deliveryVariants): self
{
$this->deliveryVariants = $deliveryVariants;
return $this;
}
public function getSendToFriend(): ?bool
{
return $this->sendToFriend;
}
public function setSendToFriend(?bool $sendToFriend): self
{
$this->sendToFriend = $sendToFriend;
return $this;
}
public function getOrderService(): ?string
{
return $this->orderService;
}
public function setOrderService(string $orderService): self
{
$this->orderService = $orderService;
return $this;
}
public function getOrderServiceDsn(): ?string
{
return
parse_url($this->order_service_dsn_url, PHP_URL_SCHEME) . '://' .
$this->order_service_dsn_login . ':' .
$this->order_service_dsn_password . '@' .
parse_url($this->order_service_dsn_url, PHP_URL_HOST) .
parse_url($this->order_service_dsn_url, PHP_URL_PATH);
}
public function getOffer(): ?string
{
return $this->offer;
}
public function setOffer(string $offer): self
{
$this->offer = $offer;
return $this;
}
/**
* @return string[]|null
* @OA\Property(
* type="string[]"
* )
*/
public function getFaq(): ?array
{
return $this->faq??null;
}
public function setFaq(?array $faq): self
{
$this->faq = $faq;
return $this;
}
public function getHiwCreateTitle(): ?string
{
return $this->hiwCreateTitle;
}
public function setHiwCreateTitle(string $hiwCreateTitle): self
{
$this->hiwCreateTitle = $hiwCreateTitle;
return $this;
}
public function getHiwCreateText(): ?string
{
return $this->hiwCreateText;
}
public function setHiwCreateText(string $hiwCreateText): self
{
$this->hiwCreateText = $hiwCreateText;
return $this;
}
public function getHiwReceiveTitle(): ?string
{
return $this->hiwReceiveTitle;
}
public function setHiwReceiveTitle(string $hiwReceiveTitle): self
{
$this->hiwReceiveTitle = $hiwReceiveTitle;
return $this;
}
public function getHiwReceiveText(): ?string
{
return $this->hiwReceiveText;
}
public function setHiwReceiveText(string $hiwReceiveText): self
{
$this->hiwReceiveText = $hiwReceiveText;
return $this;
}
public function getHiwGladTitle(): ?string
{
return $this->hiwGladTitle;
}
public function setHiwGladTitle(string $hiwGladTitle): self
{
$this->hiwGladTitle = $hiwGladTitle;
return $this;
}
public function getHiwGladText(): ?string
{
return $this->hiwGladText;
}
public function setHiwGladText(string $hiwGladText): self
{
$this->hiwGladText = $hiwGladText;
return $this;
}
public function getRulesText(): ?string
{
return $this->rulesText;
}
public function setRulesText(string $rulesText): self
{
$this->rulesText = $rulesText;
return $this;
}
public function getProducts(): ?string
{
return $this->products;
}
public function setProducts(string $products): self
{
$this->products = $products;
return $this;
}
/**
* @return Collection|Order[]
*/
public function getOrders(): Collection
{
return $this->orders;
}
public function addOrder(Order $order): self
{
if (!$this->orders->contains($order)) {
$this->orders[] = $order;
$order->setWidget($this);
}
return $this;
}
public function removeOrder(Order $order): self
{
if ($this->orders->removeElement($order)) {
// set the owning side to null (unless already changed)
if ($order->getWidget() === $this) {
$order->setWidget(null);
}
}
return $this;
}
/**
* @return Collection|UserFile[]
*/
public function getUserFiles(): Collection
{
return $this->userFiles;
}
public function addUserFile(UserFile $userFile): self
{
if (!$this->userFiles->contains($userFile)) {
$this->userFiles[] = $userFile;
$userFile->setWidget($this);
}
return $this;
}
public function removeUserFile(UserFile $userFile): self
{
if ($this->userFiles->removeElement($userFile)) {
// set the owning side to null (unless already changed)
if ($userFile->getWidget() === $this) {
$userFile->setWidget(null);
}
}
return $this;
}
/**
* @return string[]|null
* @OA\Property(
* type="string[]"
* )
*/
public function getCovers(): ?array
{
if(null !== $this->covers) {
uasort($this->covers, function ($a,$b) { return $a['sortOrder'] >= $b['sortOrder'] ? 1 : -1; } );
}
return $this->covers??[];
}
public function setCovers(?array $covers): self
{
usort($covers, function ($a, $b) {
return $b['sortOrder'] < $a['sortOrder'] ? 1 : -1;
});
$this->covers = $covers;
return $this;
}
public function getOrderServiceDsnLogin(): ?string
{
return $this->order_service_dsn_login;
}
public function setOrderServiceDsnLogin(?string $order_service_dsn_login): self
{
$this->order_service_dsn_login = $order_service_dsn_login;
return $this;
}
public function getOrderServiceDsnPassword(): ?string
{
return $this->order_service_dsn_password;
}
public function setOrderServiceDsnPassword(?string $order_service_dsn_password): self
{
$this->order_service_dsn_password = $order_service_dsn_password;
return $this;
}
public function getOrderServiceDsnUrl(): ?string
{
return $this->order_service_dsn_url;
}
public function setOrderServiceDsnUrl(?string $order_service_dsn_url): self
{
$this->order_service_dsn_url = $order_service_dsn_url;
return $this;
}
public function getOrderServiceDsnPort(): ?string
{
return $this->order_service_dsn_port;
}
public function setOrderServiceDsnPort(?string $order_service_dsn_port): self
{
$this->order_service_dsn_port = $order_service_dsn_port;
return $this;
}
public function getIdMetricGoogle(): ?string
{
return $this->id_metric_google;
}
public function setIdMetricGoogle(?string $id_metric_google): self
{
$this->id_metric_google = $id_metric_google;
return $this;
}
public function getIdMetricYandex(): ?string
{
return $this->id_metric_yandex;
}
public function setIdMetricYandex(?string $id_metric_yandex): self
{
$this->id_metric_yandex = $id_metric_yandex;
return $this;
}
/**
* @return Collection<int, WidgetUser>
*/
public function getWidgetUsers(): Collection
{
return $this->widgetUsers;
}
public function addWidgetUser(WidgetUser $widgetUser): self
{
if (!$this->widgetUsers->contains($widgetUser)) {
$this->widgetUsers[] = $widgetUser;
$widgetUser->addWiget($this);
}
return $this;
}
public function removeWidgetUser(WidgetUser $widgetUser): self
{
if ($this->widgetUsers->removeElement($widgetUser)) {
$widgetUser->removeWiget($this);
}
return $this;
}
public function getCustomDesign(): ?bool
{
return $this->customDesign;
}
public function setCustomDesign(?bool $customDesign): self
{
$this->customDesign = $customDesign;
return $this;
}
/**
* @return string[]|null
*/
public function getUsageRules(): ?array
{
return $this->usageRules;
}
public function setUsageRules(?array $usageRules): self
{
$this->usageRules = $usageRules;
return $this;
}
public function getBackgroundImage(): ?string
{
return $this->backgroundImage;
}
public function setBackgroundImage(?string $backgroundImage): self
{
$this->backgroundImage = $backgroundImage;
return $this;
}
/**
* @return array
*/
public function getProductsAsArray(): array
{
return explode(',', $this->products);
}
/**
* @return array|null
*/
public function getSaleProductIds(): ?array
{
return $this->saleProductIds;
}
/**
* @param array|null $saleProductIds
* @return Widget
*/
public function setSaleProductIds(?array $saleProductIds): self
{
$this->saleProductIds = $saleProductIds;
return $this;
}
/**
* @return string|null
*/
public function getSaleImage(): ?string
{
return $this->saleImage;
}
/**
* @param string|null $saleImage
* @return Widget
*/
public function setSaleImage(?string $saleImage): self
{
$this->saleImage = $saleImage;
return $this;
}
/**
* @return string|null
*/
public function getSaleColor(): ?string
{
return $this->saleColor;
}
/**
* @param string|null $saleColor
* @return Widget
*/
public function setSaleColor(?string $saleColor): self
{
$this->saleColor = $saleColor;
return $this;
}
/**
* @return bool
*/
public function getCanWholesale(): bool
{
return $this->canWholesale;
}
/**
* @param bool $canWholesale
* @return Widget
*/
public function setCanWholesale(bool $canWholesale): self
{
$this->canWholesale = $canWholesale;
return $this;
}
/**
* @return string|null
*/
public function getBxCorporateScript(): ?string
{
return $this->bxCorporateScript;
}
/**
* @param string $bxCorporateScript
* @return Widget
*/
public function setBxCorporateScript(string $bxCorporateScript): self
{
$this->bxCorporateScript = $bxCorporateScript;
return $this;
}
/**
* @return bool
*/
public function getEnableBxCorporateScript(): bool
{
return $this->enableBxCorporateScript;
}
/**
* @param bool $enableBxCorporateScript
* @return $this
*/
public function setEnableBxCorporateScript(bool $enableBxCorporateScript): self
{
$this->enableBxCorporateScript = $enableBxCorporateScript;
return $this;
}
/**
* @return string
*/
public function getHashedId(): string
{
return hash('sha256', $this->getId());
}
/**
* @return bool
*/
public function getProductDefaultRemains(): bool
{
return $this->productDefaultRemains;
}
/**
* @param mixed $productDefaultRemains
*/
public function setProductDefaultRemains(bool $productDefaultRemains): self
{
$this->productDefaultRemains = $productDefaultRemains;
return $this;
}
/**
* @return bool
*/
public function isAiTextEnable(): bool
{
return $this->aiTextEnable;
}
/**
* @param bool $aiTextEnable
* @return $this
*/
public function setAiTextEnable(bool $aiTextEnable): self
{
$this->aiTextEnable = $aiTextEnable;
return $this;
}
/**
* @return bool
*/
public function isAiImageEnable(): bool
{
return $this->aiImageEnable;
}
/**
* @param bool $aiImageEnable
* @return $this
*/
public function setAiImageEnable(bool $aiImageEnable): self
{
$this->aiImageEnable = $aiImageEnable;
return $this;
}
/**
* @return bool
*/
public function isSendSmsPin(): bool
{
return $this->sendSmsPin;
}
/**
* @param bool $sendSmsPin
* @return $this
*/
public function setSendSmsPin(bool $sendSmsPin): self
{
$this->sendSmsPin = $sendSmsPin;
return $this;
}
/**
* @return string
*/
public function isSupplierId(): string
{
return $this->supplierId;
}
/**
* @param string $supplierId
* @return $this
*/
public function setSupplierId(string $supplierId): self
{
$this->supplierId = $supplierId;
return $this;
}
}