src/Entity/Offer.php line 28

Open in your IDE?
  1. <?php
  2. namespace Slivki\Entity;
  3. use DateTime;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use JsonSerializable;
  7. use Doctrine\Common\Collections\Criteria;
  8. use Slivki\Entity\Media\GiftCertificatePdfBgMedia;
  9. use Slivki\Entity\Media\OfferAppTeaserMedia;
  10. use Slivki\Entity\Media\OfferDeliveryZoneMedia;
  11. use Slivki\Entity\Media\OfferMailingTeaserMedia;
  12. use Slivki\Entity\Media\OfferMapLogoMedia;
  13. use Slivki\Entity\Media\OfferMobileTeaserMedia;
  14. use Slivki\Entity\Media\OfferTeaserMedia;
  15. use Slivki\Entity\Media\OfferTopBlockMedia;
  16. use Slivki\Entity\Media\OfferTopBlockMobileMedia;
  17. use Slivki\Entity\Media\OnlineOrderPopupLogoMedia;
  18. use Slivki\Enum\Offer\OfferOnlineOrderDevice;
  19. use Slivki\Enum\Offer\OfferOnlineOrderType;
  20. use Slivki\Enum\Offer\OfferStatus;
  21. use Slivki\Util\CommonUtil;
  22. use Slivki\Util\Iiko\Dominos;
  23. use function in_array;
  24. use function count;
  25. class Offer extends Entity implements JsonSerializable
  26. {
  27.     const TEASER_MEDIA_TYPE "bsns-market-action-teaser-media";
  28.     const TEASER_MEDIA_PATH "/public/znijki-media/initial/default/1009921/";
  29.     const DETAIL_MEDIA_PATH "/public/znijki-media/initial/default/1009921/";
  30.     const SHOP_MEDIA_PATH "/public/znijki-media/initial/default/1009921/";
  31.     const SUPPLIER_MEDIA_PATH "/public/znijki-media/initial/default/1009921/";
  32.     const DESCRIPTION_IMAGES_PATH '/public/ximage/';
  33.     const PETROL_OFFER_ID 142938;
  34.     public const DREAMLAND_OFFER_ID 141563;
  35.     public const DREAMLAND_NEW_OFFER_ID 281797;
  36.     public const WHITE_LOTUS_OFFER_ID 141075;
  37.     public const OBLAKA_SALON_OFFER_ID 139498;
  38.     public const OBLAKA_ULTRASOUND_OFFER_ID 279947;
  39.     public const BLACK_START_BURGER_OFFER_ID 283384;
  40.     public const DOMINOS 168243;
  41.     public const JASMIN_OFFER_ID 247462;
  42.     public const TEST_CERTIFICATE_OFFER_ID 286127;
  43.     const FITNESS_WORLD_OFFER_ID 141207;
  44.     const KFC_OFFER_ID 239232;
  45.     const CAR_SHARING_OFFER_ID 275103;
  46.     const BOOKING_OFFER_ID 275216;
  47.     const SUSHI_HOUSE_OFFER_ID 131201;
  48.     const FREESTYLE_OFFER_ID 137760;
  49.     const HEROPARK_OFFER_ID 142436;
  50.     const TYPE_DEFAULT 0;
  51.     const TYPE_ONLINE_ORDER 1;
  52.     const TYPE_TRIPLE 2;
  53.     const TYPE_ONLINE_ORDER_ONLY 3;
  54.     const TYPE_TIRE 4;
  55.     const TYPE_GIFT_CERTIFICATE 5;
  56.     const TYPE_GIFT_CERTIFICATE_DISABLE_CODE 6;
  57.     const TYPE_DOMINOS 7;
  58.     const TYPE_FREE_PER_DAY 8;
  59.     const BEAUTY_OFFERS = [self::OBLAKA_SALON_OFFER_IDself::OBLAKA_ULTRASOUND_OFFER_ID132400239378245043138907132242138583142192,
  60.         243406135251132690139305141075self::JASMIN_OFFER_ID]; // Марсель, Белый лотос.
  61.     const SOSEDI_OFFER_ID 283793;
  62.     const MARSEL_OFFER_ID 141075;
  63.     public const FREESTYLE_CERTIFICATE_OFFER_ID 283213;
  64.     public const FREESTYLE_OFFER_IDS = [
  65.         self::FREESTYLE_CERTIFICATE_OFFER_ID,
  66.         137906,
  67.         138755,
  68.         136284,
  69.     ];
  70.     public const MINSK_WORLD_CERTIFICATE_OFFER_ID 288763;
  71.     public const FREESTYLE_CERTIFICATE_START_QR_CODES_DATE '2021-03-25';
  72.     public const YANDEX_ALISA_OFFER_ID 290406;
  73.     public const SMART_GOODS_OFFER_ID 290491;
  74.     public const TL24_OFFER_ID 291548;
  75.     public const ROYAL_PLAZA_EVENTS_OFFER_ID 290238;
  76.     public const ROYAL_PLAZA_PSYCHOLOGIST_OFFER_ID 291114;
  77.     public const IZUMI_OFFER_ID 141144;
  78.     public const OUSHEN_OFFER_ID 289105;
  79.     public const PLANETA_OFFER_ID 135977;
  80.     public const IDEALMED_OFFER_ID 141086;
  81.     public const PONPUSHKA_OFFER_ID 292879;
  82.     public const MARSEL_MASSAGE_OFFER_ID 140351;
  83.     protected $creator;
  84.     protected $title;
  85.     protected ?string $meOnMapName null;
  86.     protected $explanationText;
  87.     protected $regularPrice;
  88.     protected $offerPrice;
  89.     protected $price;
  90.     protected $oldPrice;
  91.     protected $discount;
  92.     protected $activeSince;
  93.     protected $activeTill;
  94.     protected $codeActiveTill;
  95.     protected $active;
  96.     protected $hidden;
  97.     protected $paid;
  98.     protected $free;
  99.     // TODO: null is temporary while cache reloaded
  100.     protected ?bool $withoutCodes;
  101.     protected $showPriceInConditions;
  102.     protected $additionalPercents;
  103.     protected $showAltOffers;
  104.     protected $showCurrencies;
  105.     protected $address;
  106.     protected $searchPosition;
  107.     protected $activeSearchPosition;
  108.     protected $categories;
  109.     protected $medias;
  110.     protected $seo;
  111.     /**
  112.      * @var iterable<EntityDescription>|null
  113.      */
  114.     protected ?iterable $descriptions;
  115.     protected $teaserMedias;
  116.     protected $mobileTeaserMedias;
  117.     protected $appTeaserMedias;
  118.     protected $topBlockMedias;
  119.     protected $topBlockMobileMedias;
  120.     protected $mailingTeaserMedias;
  121.     protected Collection $onlineOrderPopupLogoMedias;
  122.     protected $hotFeedIconMedia;
  123.     protected $detailMeidas;
  124.     protected $shopMedias;
  125.     protected $offerCodePools;
  126.     protected $offerOrders;
  127.     protected ?int $lastCodePoolStartPurchaseCount null;
  128.     protected $usedCodesCount;
  129.     protected $geoLocations;
  130.     protected $phoneNumbers;
  131.     protected $directors;
  132.     protected $directorID;
  133.     protected $captionName;
  134.     protected $captionColor;
  135.     protected $activeCurrencyCalculator;
  136.     protected $bankCurrency;
  137.     protected $bankCurrencyID;
  138.     protected $luceneReindex;
  139.     protected $codeCost;
  140.     protected $codeCostByCount;
  141.     protected $rating;
  142.     protected $lastModified;
  143.     protected $manager;
  144.     protected $defaultCategoryID;
  145.     protected $companyName;
  146.     protected $giftCertificates;
  147.     protected $hint;
  148.     protected $review;
  149.     protected $onReview;
  150.     protected $renewedOn;
  151.     protected $defaultCity;
  152.     protected $teaserLogoWidth;
  153.     protected $teaserLogoHeight;
  154.     protected $hideNoveltyLabel;
  155.     protected $hideBannersInComments;
  156.     protected $extensions;
  157.     protected $sumForFreeDelivery;
  158.     protected $deliveryPrice;
  159.     protected $antitags;
  160.     protected $createdOn;
  161.     protected $allowedBuyOnlyCode;
  162.     protected $buyCodeButtonText;
  163.     protected $buyItemsButtonText;
  164.     protected $freeCodesCount;
  165.     protected $reservedCodesCount;
  166.     protected $shareClick;
  167.     protected $inFreeCategory;
  168.     protected $fakeFreeCodesCount;
  169.     protected $categoriIDs;
  170.     protected $purchaseKoeff;
  171.     protected $giftCertificateOffer;
  172.     protected $supplierPhotoMedias;
  173.     protected $version;
  174.     protected $supplierCategoryData;
  175.     protected $telegramBotShow;
  176.     protected $telegramBotPosition;
  177.     protected $onlineOrderAllowed;
  178.     protected $mobileAppOnlineOrderAllowed;
  179.     protected $buyCodeDisable;
  180.     private $phoneCoverClick;
  181.     private $productFastDelivery;
  182.     private $brandboxEnabled;
  183.     private $offerDeliveryZone;
  184.     private $offerFoodDeliveryZone;
  185.     protected $hideInApp;
  186.     protected ?Collection $onlineOrderSettings;
  187.     protected $giftCertificatePdfBgMedias;
  188.     protected Collection $mapLogoMedias;
  189.     protected Collection $deliveryZoneMedias;
  190.     private $discountDeliveryPopup;
  191.     private $discountPickupPopup;
  192.     private $externalOfferLink;
  193.     private $isShowExternalOfferLink;
  194.     protected $hideFeatures;
  195.     private $deliveryTimeTeaser null;
  196.     private ?\DateTimeImmutable $onlineOrderAllowedRemovedAt null;
  197.     private ?string $regionalCaptionName null;
  198.     private ?string $regionalCaptionColor null;
  199.     private ?string $foodcourtInfoTeaser null;
  200.     private ?string $foodcourtInfoColorTeaser null;
  201.     private bool $isIncludedInBeauty false;
  202.     private bool $qrCodes false;
  203.     private bool $recurrentDisabled false;
  204.     private bool $availableOnFood false;
  205.     private bool $onlineAutoOpened false;
  206.     private bool $foodcourtLogoEnabled false;
  207.     private bool $onlineOrderGiftEnabled false;
  208.     private bool $buyCodeInAppOnly false;
  209.     private bool $showProductsInOfferDescription false;
  210.     private bool $checkAddressInOfferMenu false;
  211.     private bool $showMapIconInApp true;
  212.     private ?array $allowedOnlineOrderTypes null;
  213.     private string $titleFontColor '#000000';
  214.     private bool $separateTabForCertificatesInApp true;
  215.     private ?float $mapPrice null;
  216.     private ?int $mapRating null;
  217.     private ?int $defaultCityId null;
  218.     private ?string $directorName null;
  219.     private ?string $telegram null;
  220.     private ?string $viber null;
  221.     private ?string $messengerCallBack null;
  222.     public function __construct()
  223.     {
  224.         $this->productFastDelivery = new ArrayCollection();
  225.         $this->offerDeliveryZone = new ArrayCollection();
  226.         $this->offerFoodDeliveryZone = new ArrayCollection();
  227.         $this->categories = new ArrayCollection();
  228.         $this->medias = new ArrayCollection();
  229.         $this->descriptions = new ArrayCollection();
  230.         $this->detailMeidas = [];
  231.         $this->shopMedias = [];
  232.         $this->supplierPhotoMedias = new ArrayCollection();
  233.         $this->offerCodePools = new ArrayCollection();
  234.         $this->geoLocations = new ArrayCollection();
  235.         $this->phoneNumbers = new ArrayCollection();
  236.         $this->directors = new ArrayCollection();
  237.         $this->giftCertificates = new ArrayCollection();
  238.         $this->extensions = new ArrayCollection();
  239.         $this->antitags = new ArrayCollection();
  240.         $this->createdOn = new DateTime();
  241.         $this->renewedOn = new DateTime();
  242.         $this->categoriIDs = [];
  243.         $this->version 0;
  244.         $this->teaserMedias = new ArrayCollection();
  245.         $this->mobileTeaserMedias = new ArrayCollection();
  246.         $this->appTeaserMedias = new ArrayCollection();
  247.         $this->giftCertificatePdfBgMedias = new ArrayCollection();
  248.         $this->mapLogoMedias = new ArrayCollection();
  249.         $this->deliveryZoneMedias = new ArrayCollection();
  250.         $this->mailingTeaserMedias = new ArrayCollection();
  251.         $this->topBlockMedias = new ArrayCollection();
  252.         $this->topBlockMobileMedias = new ArrayCollection();
  253.         $this->onlineOrderPopupLogoMedias = new ArrayCollection();
  254.         $this->onlineOrderSettings = new ArrayCollection();
  255.         $this->rating 0;
  256.     }
  257.     public function getPrice() {
  258.         return $this->price;
  259.     }
  260.     public function setPrice($price) {
  261.         $this->price $price;
  262.     }
  263.     public function getOldPrice() {
  264.         return $this->oldPrice;
  265.     }
  266.     public function setOldPrice($oldPrice) {
  267.         $this->oldPrice $oldPrice;
  268.     }
  269.     /**
  270.      * @return User
  271.      */
  272.     public function getCreator() {
  273.         return $this->creator;
  274.     }
  275.     public function setCreator(User $creator) {
  276.         $this->creator $creator;
  277.     }
  278.     public function getLastModified() {
  279.         return $this->lastModified;
  280.     }
  281.     public function setLastModified($lastModified) {
  282.         $this->lastModified $lastModified;
  283.     }
  284.     public function addCategory(Category $category) {
  285.         if (!$this->categories->contains($category)) {
  286.             $this->categories->add($category);
  287.             if ($category->getID() == Category::NEW_OFFER_CATEGORY_ID) {
  288.                 $this->renewedOn = new \DateTime();
  289.             }
  290.             return true;
  291.         }
  292.         return false;
  293.     }
  294.     public function removeCategory(Category $category) {
  295.         $this->categories->removeElement($category);
  296.     }
  297.     public function hasCategory($categoryID) {
  298.         if ($this->categoriIDs && count($this->categoriIDs) > 0) {
  299.             foreach ($this->categoriIDs as $id) {
  300.                 if ($categoryID == $id) {
  301.                     return true;
  302.                 }
  303.             }
  304.             return false;
  305.         }
  306.         foreach ($this->categories as $categoryItem) {
  307.             if ($categoryID == $categoryItem->getID()) {
  308.                 return true;
  309.             }
  310.         }
  311.         return false;
  312.     }
  313.     public function hasCategoryType($categoryTypeID) {
  314.         foreach ($this->categories as $categoryItem) {
  315.             if ($categoryTypeID == $categoryItem->getTypeID()) {
  316.                 return true;
  317.             }
  318.         }
  319.         return false;
  320.     }
  321.     public function hasNotDefaultCityCategory() {
  322.         foreach ($this->categories as $category) {
  323.             if ($category->getCity() and $category->getCity()->getID() != City::DEFAULT_CITY_ID) {
  324.                 return true;
  325.             }
  326.         }
  327.         return false;
  328.     }
  329.     public function addDescription(EntityDescription $description) {
  330.         if (!$this->descriptions->contains($description)) {
  331.             $this->descriptions->add($description);
  332.         }
  333.     }
  334.     public function getTitle() {
  335.         return $this->title;
  336.     }
  337.     public function setTitle($title) {
  338.         $this->title $title;
  339.     }
  340.     public function getMeOnMapName(): ?string
  341.     {
  342.         return $this->meOnMapName;
  343.     }
  344.     public function setMeOnMapName(?string $meOnMapName): void
  345.     {
  346.         $this->meOnMapName $meOnMapName;
  347.     }
  348.     public function getExplanationText() {
  349.         return $this->explanationText;
  350.     }
  351.     public function setExplanationText($explanationText) {
  352.         $this->explanationText $explanationText;
  353.     }
  354.     public function getRegularPrice() {
  355.         $price $this->regularPrice;
  356.         if ($this->isActiveCurrencyCalculator() && is_numeric($price)) {
  357.             $bankCurrency $this->getBankCurrency();
  358.             $price *= $bankCurrency->getRate();
  359.             $price number_format($price0'.'' ') . ' руб.';
  360.         }
  361.         return $price;
  362.     }
  363.     public function getRawRegularPrice() {
  364.         return $this->regularPrice;
  365.     }
  366.     public function setRegularPrice($regularPrice) {
  367.         $this->regularPrice $regularPrice;
  368.     }
  369.     public function getOfferPrice() {
  370.         $price $this->offerPrice;
  371.         if ($this->isActiveCurrencyCalculator() && is_numeric($price)) {
  372.             $bankCurrency $this->getBankCurrency();
  373.             $price *= $bankCurrency->getRate();
  374.             $price number_format($price0'.'' ') . ' руб.';
  375.         }
  376.         return $price;
  377.     }
  378.     public function getRawOfferPrice() {
  379.         return $this->offerPrice;
  380.     }
  381.     public function setOfferPrice($offerPrice) {
  382.         $this->offerPrice $offerPrice;
  383.     }
  384.     public function getDiscount() {
  385.         return $this->discount;
  386.     }
  387.     public function setDiscount($discount) {
  388.         $this->discount $discount;
  389.     }
  390.     public function getHint() {
  391.         return $this->hint;
  392.     }
  393.     public function setHint($hint) {
  394.         $this->hint $hint;
  395.     }
  396.     public function getDiscountLabelText() {
  397.         if (mb_strlen($this->discount) > && is_numeric(mb_substr($this->discount01))) {
  398.             return '-' $this->discount;
  399.         }
  400.         return $this->discount;
  401.     }
  402.     public function getActiveSince() {
  403.         return $this->activeSince;
  404.     }
  405.     public function setActiveSince($activeSince) {
  406.         $this->activeSince $activeSince;
  407.     }
  408.     /**
  409.      * @return \DateTime
  410.      */
  411.     public function getActiveTill()
  412.     {
  413.         return $this->activeTill;
  414.     }
  415.     public function setActiveTill($activeTill) {
  416.         $this->activeTill $activeTill;
  417.     }
  418.     public function getCodeActiveTill() {
  419.         return $this->codeActiveTill;
  420.     }
  421.     public function setCodeActiveTill($codeActiveTill) {
  422.         $this->codeActiveTill $codeActiveTill;
  423.     }
  424.     public function isActive() {
  425.         return $this->active;
  426.     }
  427.     public function setActive($active) {
  428.         $this->active $active;
  429.     }
  430.     public function isHidden() {
  431.         return $this->hidden;
  432.     }
  433.     public function setHidden($hidden) {
  434.         $this->hidden $hidden;
  435.     }
  436.     public function isPaid() {
  437.         return $this->paid;
  438.     }
  439.     public function setPaid($paid) {
  440.         $this->paid $paid;
  441.     }
  442.     public function isFree() {
  443.         return $this->free;
  444.     }
  445.     public function setFree($free) {
  446.         $this->free $free;
  447.     }
  448.     public function getCaptionName() {
  449.         return $this->captionName;
  450.     }
  451.     public function setCaptionName($captionName) {
  452.         $this->captionName $captionName;
  453.     }
  454.     public function getCaptionColor() {
  455.         return $this->captionColor;
  456.     }
  457.     public function setCaptionColor($captionColor) {
  458.         $this->captionColor $captionColor;
  459.     }
  460.     public function getRegionalCaptionName(): ?string
  461.     {
  462.         return $this->regionalCaptionName;
  463.     }
  464.     public function setRegionalCaptionName(?string $regionalCaptionName): void
  465.     {
  466.         $this->regionalCaptionName $regionalCaptionName;
  467.     }
  468.     public function getRegionalCaptionColor(): ?string
  469.     {
  470.         return $this->regionalCaptionColor;
  471.     }
  472.     public function setRegionalCaptionColor(?string $regionalCaptionColor): void
  473.     {
  474.         $this->regionalCaptionColor $regionalCaptionColor;
  475.     }
  476.     /**
  477.      * @deprecated
  478.      */
  479.     public function isOnlineOrderAllowed() {
  480.         return $this->onlineOrderAllowed;
  481.     }
  482.     public function setOnlineOrderAllowed($onlineOrderAllowed) {
  483.         $this->onlineOrderAllowed $onlineOrderAllowed;
  484.     }
  485.     public function isMobileAppOnlineOrderAllowed() {
  486.         return $this->mobileAppOnlineOrderAllowed;
  487.     }
  488.     public function setMobileAppOnlineOrderAllowed($mobileAppOnlineOrderAllowed) {
  489.         $this->mobileAppOnlineOrderAllowed $mobileAppOnlineOrderAllowed;
  490.     }
  491.     public function getOnlineOrderAllowedRemovedAt(): ?\DateTimeImmutable
  492.     {
  493.         return $this->onlineOrderAllowedRemovedAt;
  494.     }
  495.     public function setOnlineOrderAllowedRemovedAt(?\DateTimeImmutable $onlineOrderAllowedRemovedAt): void
  496.     {
  497.         $this->onlineOrderAllowedRemovedAt $onlineOrderAllowedRemovedAt;
  498.     }
  499.     // TODO: null is temporary while cache reloaded
  500.     public function isWithoutCodes(): ?bool
  501.     {
  502.         return $this->withoutCodes;
  503.     }
  504.     // TODO: null is temporary while cache reloaded
  505.     public function setWithoutCodes(?bool $withoutCodes): void
  506.     {
  507.         $this->withoutCodes = (bool) $withoutCodes;
  508.     }
  509.     public function isShowPriceInConditions() {
  510.         return $this->showPriceInConditions;
  511.     }
  512.     public function setShowPriceInConditions($showPriceInConditions) {
  513.         $this->showPriceInConditions $showPriceInConditions;
  514.     }
  515.     public function isShowAltOffers() {
  516.         return $this->showAltOffers;
  517.     }
  518.     public function setShowAltOffers($showAltOffers) {
  519.         $this->showAltOffers $showAltOffers;
  520.     }
  521.     public function isActiveCurrencyCalculator() {
  522.         return $this->activeCurrencyCalculator;
  523.     }
  524.     public function setActiveCurrencyCalculator($activeCurrencyCalculator) {
  525.         $this->activeCurrencyCalculator $activeCurrencyCalculator;
  526.     }
  527.     public function getBankCurrencyID() {
  528.         return $this->bankCurrencyID;
  529.     }
  530.     public function setBankCurrencyID($bankCurrencyID) {
  531.         $this->bankCurrencyID $bankCurrencyID;
  532.     }
  533.     /**
  534.      * @return BankCurrency
  535.      */
  536.     public function getBankCurrency() {
  537.         return $this->bankCurrency;
  538.     }
  539.     public function setBankCurrency(BankCurrency $bankCurrency null) {
  540.         $this->bankCurrency $bankCurrency;
  541.     }
  542.     public function getAdditionalPercents() {
  543.         return $this->additionalPercents;
  544.     }
  545.     public function setAdditionalPercents($additionalPercents) {
  546.         $this->additionalPercents $additionalPercents;
  547.     }
  548.     public function getShowCurrencies() {
  549.         return $this->showCurrencies;
  550.     }
  551.     public function setShowCurrencies($showCurrencies) {
  552.         $this->showCurrencies $showCurrencies;
  553.     }
  554.     public function getAddress() {
  555.         return $this->address;
  556.     }
  557.     public function setAddress($address) {
  558.         $this->address $address;
  559.     }
  560.     public function getSearchPosition() {
  561.         return $this->searchPosition;
  562.     }
  563.     public function setSearchPosition($searchPosition) {
  564.         $this->searchPosition $searchPosition;
  565.     }
  566.     public function isActiveSearchPosition() {
  567.         return $this->activeSearchPosition;
  568.     }
  569.     public function setActiveSearchPosition($activeCearchPosition) {
  570.         $this->activeSearchPosition $activeCearchPosition;
  571.     }
  572.     public function getGeoLocations() {
  573.         return $this->geoLocations;
  574.     }
  575.     public function setGeoLocation(ArrayCollection $geoLocations) {
  576.         $this->geoLocations $geoLocations;
  577.     }
  578.     public function getGeoLocationById(int $id): ?GeoLocation
  579.     {
  580.         foreach ($this->geoLocations as $geoLocation) {
  581.             if ($id === $geoLocation->getID()) {
  582.                 return $geoLocation;
  583.             }
  584.         }
  585.         return null;
  586.     }
  587.     public function getGeoLocationsSortedByDistanceToLocation($location) {
  588.         if (!is_array($location)) {
  589.             return $this->geoLocations;
  590.         }
  591.         $iterator $this->getGeoLocations()->getIterator();
  592.         $iterator->uasort(function ($geoLocation1$geoLocation2) use ($location) {
  593.             $distance1 CommonUtil::getDistance($location[0], $location[1], $geoLocation1->getLatitude(), $geoLocation1->getLongitude(), 'K');
  594.             $distance2 CommonUtil::getDistance($location[0], $location[1], $geoLocation2->getLatitude(), $geoLocation2->getLongitude(), 'K');
  595.             return $distance1 $distance2 ? -1;
  596.         });
  597.         return new ArrayCollection(iterator_to_array($iterator));
  598.     }
  599.     public function addGeoLocation(GeoLocation $geoLocation) {
  600.         if (!$this->geoLocations->contains($geoLocation)) {
  601.             $this->geoLocations->add($geoLocation);
  602.         }
  603.     }
  604.     public function addProductFastDelivery(ProductFastDelivery $productFastDelivery)
  605.     {
  606.         if (!$this->productFastDelivery->contains($productFastDelivery)) {
  607.             $productFastDelivery->setOffer($this);
  608.             $this->productFastDelivery->add($productFastDelivery);
  609.         }
  610.     }
  611.     public function addOfferDeliveryZone(OfferDeliveryZone $offerDeliveryZone)
  612.     {
  613.         if (!$this->offerDeliveryZone->contains($offerDeliveryZone)) {
  614.             $offerDeliveryZone->setOffer($this);
  615.             $this->offerDeliveryZone->add($offerDeliveryZone);
  616.         }
  617.     }
  618.     public function getProductFastDelivery() {
  619.         return $this->productFastDelivery;
  620.     }
  621.     public function getPhoneNumbers() {
  622.         return $this->phoneNumbers;
  623.     }
  624.     public function setPhoneNumbers(ArrayCollection $phoneNumbers) {
  625.         $this->phoneNumbers $phoneNumbers;
  626.     }
  627.     public function getPhoneNumbersWithoutGeoLocations() {
  628.         $phoneNumberWithLocationIDList = [];
  629.         foreach ($this->getGeoLocations() as $geoLocation) {
  630.             foreach ($geoLocation->getPhoneNumbers() as $phoneNumber) {
  631.                 $phoneNumberWithLocationIDList[] = $phoneNumber->getID();
  632.             }
  633.         }
  634.         $phoneNumbersWithoutGeoLocations = [];
  635.         foreach ($this->phoneNumbers as $phoneNumber) {
  636.             if (!in_array($phoneNumber->getID(), $phoneNumberWithLocationIDList)) {
  637.                 $phoneNumbersWithoutGeoLocations[] = $phoneNumber;
  638.             }
  639.         }
  640.         return $phoneNumbersWithoutGeoLocations;
  641.     }
  642.     public function addPhoneNumber(PhoneNumber $phoneNumber) {
  643.         if (!$this->phoneNumbers->contains($phoneNumber)) {
  644.             $phoneNumber->setOffer($this);
  645.             $this->phoneNumbers->add($phoneNumber);
  646.             return true;
  647.         }
  648.         return false;
  649.     }
  650.     public function removePhoneNumberByID($phoneNumberID) {
  651.         foreach ($this->phoneNumbers as $phoneNumber) {
  652.             if ($phoneNumber->getID() == $phoneNumberID) {
  653.                 $this->phoneNumbers->removeElement($phoneNumber);
  654.                 $phoneNumber->setOffer(null);
  655.             }
  656.         }
  657.     }
  658.     /**
  659.      * @return \Doctrine\Common\Collections\ArrayCollection
  660.      */
  661.     public function getCategories() {
  662.         return $this->categories;
  663.     }
  664.     public function getCategoriesByType($type) {
  665.         $result = new ArrayCollection();
  666.         foreach ($this->categories as $category) {
  667.             if ($category->getTypeID() == $type) {
  668.                 $result->add($category);
  669.             }
  670.         }
  671.         return $result;
  672.     }
  673.     public function getCategoriesByCity($cityID) {
  674.         $categories = new ArrayCollection();
  675.         foreach ($this->categories as $category) {
  676.             if ($category->getCity()->getID() == $cityID) {
  677.                 $categories->add($category);
  678.             }
  679.         }
  680.         return $categories;
  681.     }
  682.     /**
  683.      * @deprecated
  684.      */
  685.     public function setCategories(ArrayCollection $categories) {
  686.         $this->categories $categories;
  687.     }
  688.     /**
  689.      * @return \Doctrine\Common\Collections\ArrayCollection
  690.      */
  691.     public function getMedias() {
  692.         return $this->medias;
  693.     }
  694.     public function setMedias($medias) {
  695.         $this->medias $medias;
  696.     }
  697.     /**
  698.      * @return \Slivki\Entity\Seo
  699.      */
  700.     public function getSeo() {
  701.         return $this->seo;
  702.     }
  703.     public function setSeo(Seo $seo) {
  704.         $seo->setResourceURL("Slivki:Default:details");
  705.         $this->seo $seo;
  706.     }
  707.     public function setDescriptions($descriptions) {
  708.         $this->descriptions $descriptions;
  709.     }
  710.     public function getDescriptions() {
  711.         return $this->descriptions;
  712.     }
  713.     public function getDescriptionByType($descriptionType) {
  714.         /** @var \Slivki\Entity\EntityDescription $description */
  715.         foreach ($this->descriptions as $description) {
  716.             if ($description->getTypeID() == $descriptionType) {
  717.                 return $description->getDescription();
  718.             }
  719.         }
  720.         return "";
  721.     }
  722.     public function getConditions() {
  723.         return $this->getDescriptionByType(EntityDescription::TYPE_OFFER_CONDITIONS_ID);
  724.     }
  725.     public function getFeatures() {
  726.         return $this->getDescriptionByType(EntityDescription::TYPE_OFFER_FEATURES_ID);
  727.     }
  728.     public function getLocation() {
  729.         return $this->getDescriptionByType(EntityDescription::TYPE_OFFER_LOCATION_ID);
  730.     }
  731.     public function getLogo() {
  732.         return $this->getDescriptionByType(EntityDescription::TYPE_OFFER_LOGO_ID);
  733.     }
  734.     public function getLegal() {
  735.         return $this->getDescriptionByType(EntityDescription::TYPE_OFFER_LEGAL_ID);
  736.     }
  737.     public function getDescriptionList(): array
  738.     {
  739.         return array_filter(
  740.             array(...$this->descriptions),
  741.             static fn (EntityDescription $description): bool => EntityDescription::TYPE_OFFER_DESCRIPTION_ID === $description->getTypeID(),
  742.         );
  743.     }
  744.     public function getCommonWorkingHours() {
  745.         return $this->getDescriptionByType(EntityDescription::TYPE_OFFER_WORKING_HOURS_ID);
  746.     }
  747.     public function addTeaserMedia(OfferTeaserMedia $teaserMedia) {
  748.         if (!$this->teaserMedias->contains($teaserMedia)) {
  749.             $this->teaserMedias->add($teaserMedia);
  750.             $teaserMedia->setOffer($this);
  751.         }
  752.     }
  753.     public function getTeaserMedia(): ?OfferTeaserMedia
  754.     {
  755.         return $this->teaserMedias->count() > $this->teaserMedias->first() : null;
  756.     }
  757.     public function getTeaserMedias() {
  758.         return $this->teaserMedias;
  759.     }
  760.     public function setTeaserMedias(ArrayCollection $medias) {
  761.         $this->teaserMedias $medias;
  762.     }
  763.     public function removeTeaserMedia(OfferTeaserMedia $teaserMedia) {
  764.         $this->teaserMedias->removeElement($teaserMedia);
  765.     }
  766.     public function addMobileTeaserMedia(OfferMobileTeaserMedia $mobileTeaserMedia) {
  767.         if (!$this->mobileTeaserMedias->contains($mobileTeaserMedia)) {
  768.             $this->mobileTeaserMedias->add($mobileTeaserMedia);
  769.             $mobileTeaserMedia->setOffer($this);
  770.         }
  771.     }
  772.     /** @return null|OfferMobileTeaserMedia */
  773.     public function getMobileTeaserMedia() {
  774.         return $this->mobileTeaserMedias->first();
  775.     }
  776.     public function getMobileTeaserMedias() {
  777.         return $this->mobileTeaserMedias;
  778.     }
  779.     public function setMobileTeaserMedias(ArrayCollection $medias) {
  780.         $this->mobileTeaserMedias $medias;
  781.     }
  782.     public function removeMobileTeaserMedia(OfferMobileTeaserMedia $mobileTeaserMedia) {
  783.         $this->mobileTeaserMedias->removeElement($mobileTeaserMedia);
  784.     }
  785.     public function addAppTeaserMedia(OfferAppTeaserMedia $appTeaserMedia) {
  786.         if (!$this->appTeaserMedias->contains($appTeaserMedia)) {
  787.             $this->appTeaserMedias->add($appTeaserMedia);
  788.             $appTeaserMedia->setOffer($this);
  789.         }
  790.     }
  791.     public function getAppTeaserMedia(): ?OfferAppTeaserMedia
  792.     {
  793.         return $this->appTeaserMedias->count() > $this->appTeaserMedias->first() : null;
  794.     }
  795.     public function getAppTeaserMedias() {
  796.         return $this->appTeaserMedias;
  797.     }
  798.     public function setAppTeaserMedias(ArrayCollection $medias) {
  799.         $this->appTeaserMedias $medias;
  800.     }
  801.     public function removeAppTeaserMedia(OfferAppTeaserMedia $appTeaserMedia) {
  802.         $this->appTeaserMedias->removeElement($appTeaserMedia);
  803.     }
  804.     public function addGiftCertificatePdfBgMedia(GiftCertificatePdfBgMedia $giftCertificatePdfBgMedia) {
  805.         if (!$this->giftCertificatePdfBgMedias->contains($giftCertificatePdfBgMedia)) {
  806.             $this->giftCertificatePdfBgMedias->add($giftCertificatePdfBgMedia);
  807.             $giftCertificatePdfBgMedia->setOffer($this);
  808.         }
  809.     }
  810.     /** @return null|GiftCertificatePdfBgMedia */
  811.     public function getGiftCertificatePdfBgMedia() {
  812.         return $this->giftCertificatePdfBgMedias->first();
  813.     }
  814.     public function getGiftCertificatePdfBgMedias() {
  815.         return $this->giftCertificatePdfBgMedias;
  816.     }
  817.     public function setGiftCertificatePdfBgMedias(ArrayCollection $medias) {
  818.         $this->giftCertificatePdfBgMedias $medias;
  819.     }
  820.     public function removeGiftCertificatePdfBgMedia(GiftCertificatePdfBgMedia $giftCertificatePdfBgMedia) {
  821.         $this->giftCertificatePdfBgMedias->removeElement($giftCertificatePdfBgMedia);
  822.     }
  823.     public function getOnlineOrderSettings(): ?OnlineOrderSettings
  824.     {
  825.         return $this->onlineOrderSettings->count() > $this->onlineOrderSettings->first() : null;
  826.     }
  827.     public function setOnlineOrderSettings(OnlineOrderSettings $onlineOrderSettings): void
  828.     {
  829.         $onlineOrderSettings->setOffer($this);
  830.         $this->onlineOrderSettings = new ArrayCollection([$onlineOrderSettings]);
  831.     }
  832.     public function getOnlineOrderSettingsJSON(): ?array
  833.     {
  834.         $onlineOrderSettings $this->getOnlineOrderSettings();
  835.         if (null === $onlineOrderSettings) {
  836.             return null;
  837.         }
  838.         return $onlineOrderSettings->jsonSerialize();
  839.     }
  840.     public function addMapLogoMedia(OfferMapLogoMedia $media): void
  841.     {
  842.         if (!$this->mapLogoMedias->contains($media)) {
  843.             $this->mapLogoMedias->add($media);
  844.             $media->setOffer($this);
  845.         }
  846.     }
  847.     public function getMapLogoMedia(): ?OfferMapLogoMedia
  848.     {
  849.         return $this->mapLogoMedias->count() > $this->mapLogoMedias->first() : null;
  850.     }
  851.     public function getMapLogoMedias(): Collection
  852.     {
  853.         return $this->mapLogoMedias;
  854.     }
  855.     public function setMapLogoMedias(ArrayCollection $mapLogoMedias): void
  856.     {
  857.         $this->mapLogoMedias $mapLogoMedias;
  858.     }
  859.     public function removeMapLogoMedia(OfferMapLogoMedia $media): void
  860.     {
  861.         $this->mapLogoMedias->removeElement($media);
  862.     }
  863.     public function addDeliveryZoneMedia(OfferDeliveryZoneMedia $media): void
  864.     {
  865.         if (!$this->deliveryZoneMedias->contains($media)) {
  866.             $this->deliveryZoneMedias->add($media);
  867.             $media->setOffer($this);
  868.         }
  869.     }
  870.     public function getDeliveryZoneMedia(): ?OfferDeliveryZoneMedia
  871.     {
  872.         return $this->deliveryZoneMedias->count() > $this->deliveryZoneMedias->first() : null;
  873.     }
  874.     public function getDeliveryZoneMedias(): Collection
  875.     {
  876.         return $this->deliveryZoneMedias;
  877.     }
  878.     public function setDeliveryZoneMedias(ArrayCollection $deliveryZoneMedias): void
  879.     {
  880.         $this->deliveryZoneMedias $deliveryZoneMedias;
  881.     }
  882.     public function removeDeliveryZoneMedia(OfferDeliveryZoneMedia $media): void
  883.     {
  884.         $this->deliveryZoneMedias->removeElement($media);
  885.     }
  886.     public function addTopBlockMedia(OfferTopBlockMedia $topBlockMedia) {
  887.         if (!$this->topBlockMedias->contains($topBlockMedia)) {
  888.             $this->topBlockMedias->add($topBlockMedia);
  889.             $topBlockMedia->setOffer($this);
  890.         }
  891.     }
  892.     public function getTopBlockMedia(): ?OfferTopBlockMedia
  893.     {
  894.         return $this->topBlockMedias->count() > $this->topBlockMedias->first() : null;
  895.     }
  896.     public function getTopBlockMedias() {
  897.         return $this->topBlockMedias;
  898.     }
  899.     public function setTopBlockMedias(ArrayCollection $medias) {
  900.         $this->topBlockMedias $medias;
  901.     }
  902.     public function removeTopBlockMedia(OfferTopBlockMedia $topBlockMedia) {
  903.         $this->topBlockMedias->removeElement($topBlockMedia);
  904.     }
  905.     public function addTopBlockMobileMedia(OfferTopBlockMobileMedia $topBlockMobileMedia) {
  906.         if (!$this->topBlockMobileMedias->contains($topBlockMobileMedia)) {
  907.             $this->topBlockMobileMedias->add($topBlockMobileMedia);
  908.             $topBlockMobileMedia->setOffer($this);
  909.         }
  910.     }
  911.     public function getTopBlockMobileMedia(): ?OfferTopBlockMobileMedia
  912.     {
  913.         return $this->topBlockMobileMedias->count() > $this->topBlockMobileMedias->first() : null;
  914.     }
  915.     public function getTopBlockMobileMedias() {
  916.         return $this->topBlockMobileMedias;
  917.     }
  918.     public function setTopBlockMobileMedias(ArrayCollection $medias) {
  919.         $this->topBlockMobileMedias $medias;
  920.     }
  921.     public function removeTopBlockMobileMedia(OfferTopBlockMobileMedia $topBlockMobileMedia) {
  922.         $this->topBlockMobileMedias->removeElement($topBlockMobileMedia);
  923.     }
  924.     public function addOnlineOrderPopupLogoMedia(OnlineOrderPopupLogoMedia $onlineOrderPopupLogoMedia): void
  925.     {
  926.         if (!$this->onlineOrderPopupLogoMedias->contains($onlineOrderPopupLogoMedia)) {
  927.             $this->onlineOrderPopupLogoMedias = new ArrayCollection();
  928.             $this->onlineOrderPopupLogoMedias->add($onlineOrderPopupLogoMedia);
  929.             $onlineOrderPopupLogoMedia->setOffer($this);
  930.         }
  931.     }
  932.     public function getOnlineOrderPopupLogoMedia(): ?OnlineOrderPopupLogoMedia
  933.     {
  934.         return false === $this->onlineOrderPopupLogoMedias->first() ? null $this->onlineOrderPopupLogoMedias->first();
  935.     }
  936.     /**
  937.      * @return Collection<OnlineOrderPopupLogoMedia>
  938.      */
  939.     public function getOnlineOrderPopupLogoMedias(): Collection
  940.     {
  941.         return $this->onlineOrderPopupLogoMedias;
  942.     }
  943.     public function setOnlineOrderPopupLogoMedias(ArrayCollection $medias): void
  944.     {
  945.         $this->onlineOrderPopupLogoMedias $medias;
  946.     }
  947.     public function removeOnlineOrderPopupLogoMedia(OnlineOrderPopupLogoMedia $onlineOrderPopupLogoMedia): void
  948.     {
  949.         $this->topBlockMedias->removeElement($onlineOrderPopupLogoMedia);
  950.     }
  951.     public function addMailingTeaserMedia(OfferMailingTeaserMedia $mailingTeaserMedia null) {
  952.         if (!$this->mailingTeaserMedias->contains($mailingTeaserMedia)) {
  953.             $this->mailingTeaserMedias->add($mailingTeaserMedia);
  954.             $mailingTeaserMedia->setOffer($this);
  955.         }
  956.     }
  957.     /** @return null|OfferMailingTeaserMedia */
  958.     public function getMailingTeaserMedia() {
  959.         return $this->mailingTeaserMedias->first();
  960.     }
  961.     public function getMailingTeaserMedias() {
  962.         return $this->mailingTeaserMedias;
  963.     }
  964.     public function setMailingTeaserMedias(ArrayCollection $medias) {
  965.         $this->mailingTeaserMedias $medias;
  966.     }
  967.     public function removeMailingTeaserMedia(OfferMailingTeaserMedia $mailingTeaserMedia) {
  968.         $this->mailingTeaserMedias->removeElement($mailingTeaserMedia);
  969.     }
  970.     public function setHotFeedIconMedia(Media $hotFeedIconMedia null) {
  971.         $this->hotFeedIconMedia $hotFeedIconMedia;
  972.     }
  973.     /**
  974.      * @return null|Media
  975.      */
  976.     public function getHotFeedIconMedia() {
  977.         return $this->hotFeedIconMedia;
  978.     }
  979.     public function setDetailMeidas(array $mediaList) {
  980.         $this->detailMeidas $mediaList;
  981.     }
  982.     public function getDetailMedias() {
  983.         return $this->detailMeidas;
  984.     }
  985.     public function setShopMedias(array $mediaList) {
  986.         $this->shopMedias $mediaList;
  987.     }
  988.     public function getShopMedias(): array
  989.     {
  990.         return $this->shopMedias ?? [];
  991.     }
  992.     public function addShopMedias(Media $media) {
  993.         if (!$this->shopMedias->contains($media)) {
  994.             $this->shopMedias->add($media);
  995.         }
  996.     }
  997.     public function setSupplierPhotoMedias(array $mediaList) {
  998.         $this->supplierPhotoMedias $mediaList;
  999.     }
  1000.     public function getSupplierPhotoMedias() {
  1001.         return $this->supplierPhotoMedias;
  1002.     }
  1003.     public function getOfferCodePools() {
  1004.         return $this->offerCodePools;
  1005.     }
  1006.     public function setOfferCodePools(ArrayCollection $offerCodePools) {
  1007.         $this->offerCodePools $offerCodePools;
  1008.     }
  1009.     /**
  1010.      * @return bool|OfferCodePool
  1011.      */
  1012.     public function getLastActiveCodePool() {
  1013.         /** @var \Slivki\Entity\OfferCodePool $offerCodePool */
  1014.         foreach ($this->offerCodePools->toArray() as $offerCodePool) {
  1015.             if ($offerCodePool->isActive()) {
  1016.                 return $offerCodePool;
  1017.             }
  1018.         }
  1019.         return false;
  1020.     }
  1021.     public function setCodePool(OfferCodePool $codePool) {
  1022.         if ($this->offerCodePools->count() == 0) {
  1023.             $this->offerCodePools->add($codePool);
  1024.         }
  1025.         foreach ($this->offerCodePools as $key => $pool) {
  1026.             if ($pool->getID() == $codePool->getID()) {
  1027.                 $this->offerCodePools->set($key$codePool);
  1028.             }
  1029.         }
  1030.         $this->usedCodesCount $this->getUsedCodesCount(true);
  1031.         $this->fakeFreeCodesCount $this->getFakeFreeCodesCount(true);
  1032.         $this->freeCodesCount $this->getFreeCodesCount(true);
  1033.         $this->reservedCodesCount $this->getReservedCodesCount(true);
  1034.         $this->setLastCodePoolStartPurchaseCount();
  1035.         $this->lastCodePoolStartPurchaseCount $this->getLastCodePoolStartPurchaseCount();
  1036.     }
  1037.     public function getOfferOrders() {
  1038.         return $this->offerOrders;
  1039.     }
  1040.     public function setOfferOrders(ArrayCollection $offerOrders) {
  1041.         $this->offerOrders $offerOrders;
  1042.     }
  1043.     public function getUsedCodesCount($reload false) {
  1044.         if ($this->usedCodesCount != null && !$reload) {
  1045.             return $this->usedCodesCount;
  1046.         }
  1047.         $lastActiveCodePool $this->getLastActiveCodePool();
  1048.         if (!$lastActiveCodePool) {
  1049.             $this->usedCodesCount 0;
  1050.             return 0;
  1051.         }
  1052.         $usedCodes trim($lastActiveCodePool->getCodesUsed(), "\n");
  1053.         if ($usedCodes == '') {
  1054.             $this->usedCodesCount $lastActiveCodePool->getUsedCodesCountFake();
  1055.             return $this->usedCodesCount;
  1056.         }
  1057.         $this->usedCodesCount count(explode("\n"$usedCodes)) + $lastActiveCodePool->getUsedCodesCountFake();
  1058.         return $this->usedCodesCount;
  1059.     }
  1060.     public function getLastCodePoolStartPurchaseCount(): int
  1061.     {
  1062.         if (null === $this->lastCodePoolStartPurchaseCount) {
  1063.             $this->setLastCodePoolStartPurchaseCount();
  1064.         }
  1065.         return $this->lastCodePoolStartPurchaseCount;
  1066.     }
  1067.     public function setLastCodePoolStartPurchaseCount(): void
  1068.     {
  1069.         $lastActiveCodePool $this->getLastActiveCodePool();
  1070.         if (!$lastActiveCodePool) {
  1071.             $this->lastCodePoolStartPurchaseCount 0;
  1072.             return;
  1073.         }
  1074.         $this->lastCodePoolStartPurchaseCount $lastActiveCodePool->getUsedCodesCountFake();
  1075.     }
  1076.     public function getUsedCodesCountForPastOffer() {
  1077.         $this->usedCodesCount 0;
  1078.         if ($this->offerCodePools->count() > 0) {
  1079.             $codePool $this->offerCodePools->last();
  1080.             if ($codePool) {
  1081.                 $usedCodes trim($codePool->getCodesUsed(), "\n");
  1082.                 if ($usedCodes == '') {
  1083.                     return 0;
  1084.                 }
  1085.                 return count(explode("\n"$usedCodes)) + $codePool->getUsedCodesCountFake();
  1086.             }
  1087.         }
  1088.         return 0;
  1089.     }
  1090.     public function setUsedCodesCount($usedCodesCount) {
  1091.         $this->usedCodesCount $usedCodesCount;
  1092.     }
  1093.     public function getFreeCodesCount($reload false) {
  1094.         if ($this->freeCodesCount != null && !$reload) {
  1095.             return $this->freeCodesCount;
  1096.         }
  1097.         $lastActiveCodePool $this->getLastActiveCodePool();
  1098.         if (!$lastActiveCodePool) {
  1099.             $this->freeCodesCount 0;
  1100.             return 0;
  1101.         }
  1102.         $this->freeCodesCount $lastActiveCodePool->getFreeCodesCount();
  1103.         return $this->freeCodesCount;
  1104.     }
  1105.     public function hasFreeCodes(): bool
  1106.     {
  1107.         return $this->getFreeCodesCount() > 0;
  1108.     }
  1109.     public function getReservedCodesCount($reload false) {
  1110.         if ($this->reservedCodesCount != null && !$reload) {
  1111.             return $this->reservedCodesCount;
  1112.         }
  1113.         $lastActiveCodePool $this->getLastActiveCodePool();
  1114.         if (!$lastActiveCodePool) {
  1115.             $this->reservedCodesCount 0;
  1116.             return 0;
  1117.         }
  1118.         $this->reservedCodesCount $lastActiveCodePool->getReservedCodesCount();
  1119.         return $this->reservedCodesCount;
  1120.     }
  1121.     public function getFakeFreeCodesCount($reload false) {
  1122.         if ($this->fakeFreeCodesCount != null && !$reload) {
  1123.             return $this->fakeFreeCodesCount;
  1124.         }
  1125.         $codePool $this->getLastActiveCodePool();
  1126.         if (!$codePool) {
  1127.             $this->fakeFreeCodesCount 0;
  1128.             return 0;
  1129.         }
  1130.         $this->fakeFreeCodesCount $this->getUsedCodesCount() + $codePool->getFreeCodesCount();
  1131.         return $this->fakeFreeCodesCount;
  1132.     }
  1133.     public function getDirectors() {
  1134.         return $this->directors;
  1135.     }
  1136.     public function findFirstDirector(): ?Director
  1137.     {
  1138.         return false === $this->directors->first() ? null $this->directors->first();
  1139.     }
  1140.     public function getDirectorID() {
  1141.         if ($this->directorID !== null) {
  1142.             return $this->directorID;
  1143.         }
  1144.         if ($this->directors->count()) {
  1145.             $directorID $this->directors->first()->getID();
  1146.             $this->directorID $directorID;
  1147.             return $directorID;
  1148.         }
  1149.         return null;
  1150.     }
  1151.     public function getCodesCountByUser(User $user) {
  1152.         $criteria Criteria::create()->where(Criteria::expr()->eq("user"$user));
  1153.         $offerOrders $this->offerOrders->matching($criteria);
  1154.         $codesCount 0;
  1155.         /** @var OfferOrder $offerOrder */
  1156.         foreach($offerOrders as $offerOrder) {
  1157.             $offerOrderStatus $offerOrder->getStatus();
  1158.             if ($offerOrderStatus == OfferOrder::STATUS_CONFIRM) {
  1159.                 $codesCount += $offerOrder->getCodesCount();
  1160.             }
  1161.         }
  1162.         return $codesCount;
  1163.     }
  1164.     public function isLuceneReindex() {
  1165.         return $this->luceneReindex;
  1166.     }
  1167.     public function setLuceneReindex($luceneReindex) {
  1168.         $this->luceneReindex $luceneReindex;
  1169.     }
  1170.     public function getCodeCost() {
  1171.         return $this->codeCost;
  1172.     }
  1173.     public function setCodeCost($codeCost) {
  1174.         $this->codeCost $codeCost;
  1175.     }
  1176.     public function getCodeCostByCount() {
  1177.         return $this->codeCostByCount;
  1178.     }
  1179.     public function setCodeCostByCount($codeCostByCount) {
  1180.         $this->codeCostByCount $codeCostByCount;
  1181.     }
  1182.     public function isInFreeCodesCategory() {
  1183.         if ($this->inFreeCategory != null) {
  1184.             return $this->inFreeCategory;
  1185.         }
  1186.         foreach ($this->categories as $category) {
  1187.             if ($category->getID() == Category::FREE_CODES_CATEGORY_ID || $category->getTypeID() == Category::FREE_CATEGORY_TYPE) {
  1188.                 $this->inFreeCategory true;
  1189.                 return true;
  1190.             }
  1191.         }
  1192.         $this->inFreeCategory false;
  1193.         return false;
  1194.     }
  1195.     /**
  1196.      * @return boolean
  1197.      */
  1198.     public function isInActivePeriod() {
  1199.         $activeSince $this->getActiveSince();
  1200.         $activeTill $this->getActiveTill();
  1201.         $timeNow = new \DateTime();
  1202.         if(!$activeSince instanceof \DateTime || !$activeTill instanceof \DateTime) {
  1203.             return false;
  1204.         }
  1205.         return $activeSince <= $timeNow && $activeTill $timeNow;
  1206.     }
  1207.     public function isVisible(): bool
  1208.     {
  1209.         return $this->isActive() && $this->isInActivePeriod() && !$this->isHidden();
  1210.     }
  1211.     /**
  1212.      * @return boolean
  1213.      * @deprecated
  1214.      */
  1215.     public function isInVisiblePeriod() {
  1216.         return !$this->hidden;
  1217.     }
  1218.     public function getRating() {
  1219.         return $this->rating;
  1220.     }
  1221.     public function setRating($rating) {
  1222.         $this->rating $rating;
  1223.     }
  1224.     /**
  1225.      * @return User
  1226.      */
  1227.     public function getManager() {
  1228.         return $this->manager;
  1229.     }
  1230.     public function setManager(User $manager) {
  1231.         $this->manager $manager;
  1232.     }
  1233.     public function getDefaultCategoryID() {
  1234.         return $this->defaultCategoryID;
  1235.     }
  1236.     public function setDefaultCategoryID($categoryID) {
  1237.         $this->defaultCategoryID $categoryID;
  1238.     }
  1239.     public function getCompanyName() {
  1240.         return $this->companyName;
  1241.     }
  1242.     public function setCompanyName($companyName) {
  1243.         $this->companyName $companyName;
  1244.     }
  1245.     public function isTelegramBotShow() {
  1246.         return $this->telegramBotShow;
  1247.     }
  1248.     public function setTelegramBotShow($telegramBotShow) {
  1249.         $this->telegramBotShow $telegramBotShow;
  1250.     }
  1251.     public function getTelegramBotPosition() {
  1252.         return $this->telegramBotPosition;
  1253.     }
  1254.     public function setTelegramBotPosition($telegramBotPosition) {
  1255.         $this->telegramBotPosition $telegramBotPosition;
  1256.     }
  1257.     public function getGiftCertificates() {
  1258.         return $this->giftCertificates;
  1259.     }
  1260.     public function getActiveGiftCertificates() {
  1261.         $criteria Criteria::create()->where(Criteria::expr()->eq('active'true))->andWhere(Criteria::expr()->eq('hidden'false));
  1262.         return $this->giftCertificates->matching($criteria);
  1263.     }
  1264.     public function isGiftCertificateOffer() {
  1265.         if ($this->giftCertificateOffer != null) {
  1266.             return $this->giftCertificateOffer;
  1267.         }
  1268.         $this->giftCertificateOffer $this->getActiveGiftCertificates()->count() > 0;
  1269.         return $this->giftCertificateOffer;
  1270.     }
  1271.     public function setGiftCertificates(Collection $giftCertificates) {
  1272.         $this->giftCertificates $giftCertificates;
  1273.     }
  1274.     public function addGiftCertificate(GiftCertificate $giftCertificate) {
  1275.         if (!$this->giftCertificates->contains($giftCertificate)) {
  1276.             $this->giftCertificates->add($giftCertificate);
  1277.             $giftCertificate->setOffer($this);
  1278.         }
  1279.     }
  1280.     public function isNeedReview() {
  1281.         return $this->review;
  1282.     }
  1283.     public function setNeedReview($review) {
  1284.         $this->review $review;
  1285.     }
  1286.     public function isOnReview() {
  1287.         return $this->onReview;
  1288.     }
  1289.     public function setOnReview($onReview) {
  1290.         $this->onReview $onReview;
  1291.     }
  1292.     public function getRenewedOn() {
  1293.         return $this->renewedOn;
  1294.     }
  1295.     public function setRenewedOn(\DateTime $renewedOn) {
  1296.         $this->renewedOn $renewedOn;
  1297.     }
  1298.     /** @return City */
  1299.     public function getDefaultCity() {
  1300.         return $this->defaultCity;
  1301.     }
  1302.     public function setDefaultCity(City $defaultCity) {
  1303.         $this->defaultCity $defaultCity;
  1304.     }
  1305.     public function getDefaultCityId(): ?int
  1306.     {
  1307.         return $this->defaultCityId;
  1308.     }
  1309.     public function setDefaultCityId(?int $defaultCityId): void
  1310.     {
  1311.         $this->defaultCityId $defaultCityId;
  1312.     }
  1313.     public function getTeaserLogoWidth() {
  1314.         return $this->teaserLogoWidth;
  1315.     }
  1316.     public function setTeaserLogoWidth($teaserLogoWidth) {
  1317.         $this->teaserLogoWidth $teaserLogoWidth;
  1318.     }
  1319.     public function getTeaserLogoHeight() {
  1320.         return $this->teaserLogoHeight;
  1321.     }
  1322.     public function setTeaserLogoHeight($teaserLogoHeight) {
  1323.         $this->teaserLogoHeight $teaserLogoHeight;
  1324.     }
  1325.     public function isHideNoveltyLabel() {
  1326.         return $this->hideNoveltyLabel;
  1327.     }
  1328.     public function setHideNoveltyLabel($hideNoveltyLabel) {
  1329.         $this->hideNoveltyLabel $hideNoveltyLabel;
  1330.     }
  1331.     public function isHideBannersInComments() {
  1332.         return $this->hideBannersInComments;
  1333.     }
  1334.     public function setHideBannersInComments($hideBannersInComments) {
  1335.         $this->hideBannersInComments $hideBannersInComments;
  1336.     }
  1337.     public function getExtensions() {
  1338.         return $this->extensions;
  1339.     }
  1340.     public function setExtensions(ArrayCollection $extensions) {
  1341.         $this->extensions $extensions;
  1342.     }
  1343.     /**
  1344.      * @return FoodOfferExtension[]|ArrayCollection
  1345.      */
  1346.     public function getFoodExtensions() {
  1347.         $foodExtensions = new ArrayCollection();
  1348.         if (!$this->extensions) {
  1349.             return $foodExtensions;
  1350.         }
  1351.         foreach ($this->extensions as $extension) {
  1352.             if ($extension instanceof FoodOfferExtension && !$extension instanceof FoodOfferOptionExtension) {
  1353.                 $foodExtensions->add($extension);
  1354.             }
  1355.         }
  1356.         return $foodExtensions;
  1357.     }
  1358.     public function getTireExtensions() {
  1359.         $tireExtensions = new ArrayCollection();
  1360.         foreach ($this->extensions as $extension) {
  1361.             if ($extension instanceof TireOfferExtension) {
  1362.                 $tireExtensions->add($extension);
  1363.             }
  1364.         }
  1365.         return $tireExtensions;
  1366.     }
  1367.     public function getFoodOptionExtensions() {
  1368.         $foodOptionExtensions = new ArrayCollection();
  1369.         foreach ($this->extensions as $extension) {
  1370.             if ($extension instanceof FoodOfferOptionExtension) {
  1371.                 $foodOptionExtensions->add($extension);
  1372.             }
  1373.         }
  1374.         return $foodOptionExtensions;
  1375.     }
  1376.     public function getItems() {
  1377.         $items = new ArrayCollection();
  1378.         if (!$this->extensions) {
  1379.             return $items;
  1380.         }
  1381.         foreach ($this->extensions as $extension) {
  1382.             if ($extension instanceof ItemOfferExtension) {
  1383.                 $items->add($extension);
  1384.             }
  1385.         }
  1386.         return $items;
  1387.     }
  1388.     public function addExtension(OfferExtension $extension) {
  1389.         if (!$this->extensions->contains($extension)) {
  1390.             $this->extensions->add($extension);
  1391.             $extension->setOffer($this);
  1392.         }
  1393.     }
  1394.     public function getSumForFreeDelivery() {
  1395.         return $this->sumForFreeDelivery;
  1396.     }
  1397.     public function setSumForFreeDelivery($sumForFreeDelivery) {
  1398.         $this->sumForFreeDelivery $sumForFreeDelivery;
  1399.     }
  1400.     public function getDeliveryPrice() {
  1401.         return $this->deliveryPrice;
  1402.     }
  1403.     public function setDeliveryPrice($deliveryPrice) {
  1404.         $this->deliveryPrice $deliveryPrice;
  1405.     }
  1406.     /**
  1407.      * @return ArrayCollection
  1408.      */
  1409.     public function getAntiTags() {
  1410.         return $this->antitags;
  1411.     }
  1412.     public function addAntiTag(AntiTag $antitag) {
  1413.         if (!$this->antitags->contains($antitag)) {
  1414.             $antitag->addOffer($this);
  1415.             $this->antitags->add($antitag);
  1416.         }
  1417.     }
  1418.     public function deleteAntiTag(AntiTag $antitag) {
  1419.         $this->antitags->removeElement($antitag);
  1420.     }
  1421.     public function hasAntiTag(AntiTag $antitag) {
  1422.         return $this->antitags->contains($antitag);
  1423.     }
  1424.     public function getCreatedOn() {
  1425.         return $this->createdOn;
  1426.     }
  1427.     public function setCreatedOn($createdOn) {
  1428.         $this->createdOn $createdOn;
  1429.     }
  1430.     public function isAllowedBuyOnlyCode() {
  1431.         return $this->allowedBuyOnlyCode;
  1432.     }
  1433.     public function setAllowedBuyOnlyCode($allowedBuyOnlyCode) {
  1434.         $this->allowedBuyOnlyCode $allowedBuyOnlyCode;
  1435.     }
  1436.     public function getBuyCodeButtonText() {
  1437.         return $this->buyCodeButtonText;
  1438.     }
  1439.     public function setBuyCodeButtonText($buyCodeButtonText) {
  1440.         $this->buyCodeButtonText $buyCodeButtonText;
  1441.     }
  1442.     public function getBuyItemsButtonText() {
  1443.         return $this->buyItemsButtonText;
  1444.     }
  1445.     public function setBuyItemsButtonText($buyItemsButtonText) {
  1446.         $this->buyItemsButtonText $buyItemsButtonText;
  1447.     }
  1448.     public function setShareClick($shareClick) {
  1449.         $this->shareClick $shareClick;
  1450.     }
  1451.     public function getShareClick() {
  1452.         return $this->shareClick;
  1453.     }
  1454.     public function getOfferDeliveryZone(): ?Collection
  1455.     {
  1456.         return $this->offerDeliveryZone;
  1457.     }
  1458.     public function getPurchaseKoeff() {
  1459.         return $this->purchaseKoeff;
  1460.     }
  1461.     public function setPurchaseKoeff($purchaseKoeff) {
  1462.         $this->purchaseKoeff $purchaseKoeff;
  1463.     }
  1464.     public function getVersion() {
  1465.         return $this->version;
  1466.     }
  1467.     public function setVersion($version) {
  1468.         $this->version $version;
  1469.     }
  1470.     public function getSupplierCategoryData() {
  1471.         return $this->supplierCategoryData;
  1472.     }
  1473.     public function setSupplierCategoryData($supplierCategoryData) {
  1474.         $this->supplierCategoryData $supplierCategoryData;
  1475.     }
  1476.     public function isQrCodes(): bool
  1477.     {
  1478.         return $this->qrCodes;
  1479.     }
  1480.     public function setQrCodes(bool $qrCodes): void
  1481.     {
  1482.         $this->qrCodes $qrCodes;
  1483.     }
  1484.     public function isRecurrentDisabled(): bool
  1485.     {
  1486.         return $this->recurrentDisabled;
  1487.     }
  1488.     public function setRecurrentDisabled(bool $recurrentDisabled): void
  1489.     {
  1490.         $this->recurrentDisabled $recurrentDisabled;
  1491.     }
  1492.     public function isAvailableOnFood(): bool
  1493.     {
  1494.         return $this->availableOnFood;
  1495.     }
  1496.     public function setAvailableOnFood(bool $availableOnFood): void
  1497.     {
  1498.         $this->availableOnFood $availableOnFood;
  1499.     }
  1500.     public function getAllowedOnlineOrderTypes(): ?array
  1501.     {
  1502.         return $this->allowedOnlineOrderTypes;
  1503.     }
  1504.     public function setAllowedOnlineOrderTypes(?array $allowedOnlineOrderTypes): void
  1505.     {
  1506.         $this->allowedOnlineOrderTypes $allowedOnlineOrderTypes;
  1507.     }
  1508.     public function getTitleFontColor(): string
  1509.     {
  1510.         return $this->titleFontColor;
  1511.     }
  1512.     public function setTitleFontColor(string $titleFontColor): void
  1513.     {
  1514.         $this->titleFontColor $titleFontColor;
  1515.     }
  1516.     public function getCategoriesIds(): array
  1517.     {
  1518.         $categoryIds = [];
  1519.         foreach ($this->categories as $category) {
  1520.             $categoryIds[] = $category->getID();
  1521.         }
  1522.         return $categoryIds;
  1523.     }
  1524.     public function jsonSerialize(): array
  1525.     {
  1526.         $categoryIDs = [];
  1527.         foreach ($this->categories as $category) {
  1528.             $categoryIDs[] = $category->getID();
  1529.         }
  1530.         return [
  1531.             'ID' => $this->ID,
  1532.             'title' => $this->title,
  1533.             'defaultCityId' => $this->getDefaultCity() !== null $this->getDefaultCity()->getID(): $this->defaultCityId,
  1534.             'meOnMapName' => $this->meOnMapName,
  1535.             'explanationText' => $this->explanationText,
  1536.             'active' => $this->active,
  1537.             'hidden' => $this->hidden,
  1538.             'discount' => $this->discount,
  1539.             'regularPrice' => $this->regularPrice,
  1540.             'offerPrice' => $this->offerPrice,
  1541.             'address' => $this->address,
  1542.             'codeCost' => $this->codeCost,
  1543.             'codeCostByCount' => $this->codeCostByCount,
  1544.             'additionalPercents' => $this->additionalPercents,
  1545.             'showPriceInConditions' => $this->showPriceInConditions,
  1546.             'showAltOffers' => $this->showAltOffers,
  1547.             'free' => $this->free,
  1548.             'captionName' => $this->captionName,
  1549.             'captionColor' => $this->captionColor,
  1550.             'titleFontColor' => $this->titleFontColor,
  1551.             'regionalCaptionName' => $this->regionalCaptionName,
  1552.             'regionalCaptionColor' => $this->regionalCaptionColor,
  1553.             'withoutCodes' => $this->withoutCodes,
  1554.             'activeCurrencyCalculator' => $this->activeCurrencyCalculator,
  1555.             'bankCurrencyID' => $this->bankCurrencyID,
  1556.             'rawRegularPrice' => $this->getRawRegularPrice(),
  1557.             'rawOfferPrice' => $this->getRawOfferPrice(),
  1558.             'activeSearchPosition' => $this->activeSearchPosition,
  1559.             'searchPosition' => $this->searchPosition,
  1560.             'defaultCategoryID' => $this->defaultCategoryID,
  1561.             'companyName' => $this->companyName,
  1562.             'hint' => $this->hint ?: '',
  1563.             'price' => $this->price,
  1564.             'oldPrice' => $this->oldPrice,
  1565.             'teaserLogoWidth' => $this->teaserLogoWidth,
  1566.             'teaserLogoHeight' => $this->teaserLogoHeight,
  1567.             'hideNoveltyLabel' => $this->hideNoveltyLabel,
  1568.             'hideBannersInComments' => $this->hideBannersInComments,
  1569.             'onlineOrderAllowed' => $this->onlineOrderAllowed,
  1570.             'mobileAppOnlineOrderAllowed' => $this->mobileAppOnlineOrderAllowed,
  1571.             'buyCodeDisable' => $this->buyCodeDisable,
  1572.             'hideInApp' => $this->hideInApp,
  1573.             'brandboxEnabled' => $this->brandboxEnabled,
  1574.             'allowedBuyOnlyCode' => $this->allowedBuyOnlyCode,
  1575.             'buyCodeButtonText' => $this->buyCodeButtonText,
  1576.             'buyItemsButtonText' => $this->buyItemsButtonText,
  1577.             'activeSince' => $this->activeSince,
  1578.             'activeTill' => $this->activeTill,
  1579.             'freeCodesCount' => $this->getFreeCodesCount(),
  1580.             'reservedCodesCount' => $this->getReservedCodesCount(),
  1581.             'inFreeCategory' => $this->isInFreeCodesCategory(),
  1582.             'bankCurrency' => $this->bankCurrency,
  1583.             'codeActiveTill' => $this->codeActiveTill,
  1584.             'usedCodesCount' => $this->getUsedCodesCount(),
  1585.             'fakeFreeCodesCount' => $this->getFakeFreeCodesCount(),
  1586.             'lastCodePoolStartPurchaseCount' => $this->getLastCodePoolStartPurchaseCount(),
  1587.             'categoryIDs' => $categoryIDs,
  1588.             'purchaseKoeff' => $this->purchaseKoeff,
  1589.             'giftCertificateOffer' => $this->isGiftCertificateOffer(),
  1590.             'supplierCategoryData' => $this->supplierCategoryData,
  1591.             'telegramBotShow' => $this->telegramBotShow,
  1592.             'discountDeliveryPopup' => $this->getDiscountDeliveryPopup(),
  1593.             'discountPickupPopup' => $this->getDiscountPickupPopup(),
  1594.             'deliveryTimeTeaser' => $this->getDeliveryTimeTeaser(),
  1595.             'foodcourtInfoTeaser' => $this->getFoodcourtInfoTeaser(),
  1596.             'foodcourtInfoColorTeaser' => $this->getFoodcourtInfoColorTeaser(),
  1597.             'externalOfferLink' => $this->getExternalOfferLink(),
  1598.             'isShowExternalOfferLink' => $this->getIsShowExternalOfferLink(),
  1599.             'hideFeatures' => $this->hideFeatures,
  1600.             'isIncludedInBeauty' => $this->isIncludedInBeauty,
  1601.             'qrCodes' =>  $this->qrCodes,
  1602.             'recurrentDisabled' => $this->recurrentDisabled,
  1603.             'availableOnFood' => $this->availableOnFood,
  1604.             'onlineAutoOpened' => $this->onlineAutoOpened,
  1605.             'foodcourtLogoEnabled' => $this->foodcourtLogoEnabled,
  1606.             'onlineOrderGiftEnabled' => $this->onlineOrderGiftEnabled,
  1607.             'onlineOrderSettings' => $this->getOnlineOrderSettingsJSON(),
  1608.             'directorID' => $this->getDirectorID(),
  1609.             'rating' => $this->rating,
  1610.             'buyCodeInAppOnly' => $this->buyCodeInAppOnly,
  1611.             'allowedOnlineOrderTypes' => $this->allowedOnlineOrderTypes,
  1612.             'showProductsInOfferDescription' => $this->showProductsInOfferDescription,
  1613.             'separateTabForCertificatesInApp' => $this->separateTabForCertificatesInApp,
  1614.             'checkAddressInOfferMenu' => $this->checkAddressInOfferMenu,
  1615.             'showMapIconInApp' => $this->showMapIconInApp,
  1616.             'telegram' => $this->telegram,
  1617.             'viber' => $this->viber,
  1618.             'messengerCallBack' => $this->messengerCallBack,
  1619.         ];
  1620.     }
  1621.     public function fromJSON($data)
  1622.     {
  1623.         $this->freeCodesCount $data->freeCodesCount;
  1624.         $this->reservedCodesCount $data->reservedCodesCount;
  1625.         $this->lastCodePoolStartPurchaseCount $data->lastCodePoolStartPurchaseCount ?? 0;
  1626.         $this->usedCodesCount $data->usedCodesCount;
  1627.         $this->fakeFreeCodesCount $data->fakeFreeCodesCount;
  1628.         $this->inFreeCategory $data->inFreeCategory;
  1629.         $this->activeSince = new \DateTime($data->activeSince->date);
  1630.         $this->activeTill = new \DateTime($data->activeTill->date);
  1631.         $this->codeActiveTill = new \DateTime($data->codeActiveTill->date);
  1632.         if (isset($data->categoryIDs)) {
  1633.             $this->categoriIDs $data->categoryIDs;
  1634.         }
  1635.         if (isset($data->giftCertificateOffer)) {
  1636.             $this->giftCertificateOffer $data->giftCertificateOffer;
  1637.         }
  1638.         if (isset($data->bankCurrency) && isset($data->bankCurrency->ID)) {
  1639.             $bankCurrency = new BankCurrency();
  1640.             $bankCurrency->setID($data->bankCurrency->ID);
  1641.             $bankCurrency->setRate($data->bankCurrency->rate);
  1642.             $bankCurrency->setCurrency($data->bankCurrency->currency);
  1643.             $bankCurrency->setSign($data->bankCurrency->sign);
  1644.             $this->bankCurrency $bankCurrency;
  1645.         }
  1646.         if (isset($data->onlineOrderSettings) && isset($data->onlineOrderSettings->ID)) {
  1647.             $onlineOrderSettings = new OnlineOrderSettings();
  1648.             $onlineOrderSettings->setID($data->onlineOrderSettings->ID);
  1649.             $onlineOrderSettings->setMinDeliverySum($data->onlineOrderSettings->minDeliverySum);
  1650.             $onlineOrderSettings->setMinSumForFreeDelivery($data->onlineOrderSettings->minSumForFreeDelivery);
  1651.             $onlineOrderSettings->setDeliveryPrice($data->onlineOrderSettings->deliveryPrice);
  1652.             $onlineOrderSettings->setPickupEnabled($data->onlineOrderSettings->pickupEnabled);
  1653.             $onlineOrderSettings->setDeliveryEnabled($data->onlineOrderSettings->deliveryEnabled);
  1654.             $onlineOrderSettings->setAllowedPaymentMethods($data->onlineOrderSettings->allowedPaymentMethods);
  1655.             $onlineOrderSettings->setOrderPeriodInDays($data->onlineOrderSettings->orderPeriodInDays);
  1656.             $onlineOrderSettings->setPickupDiscountPercent($data->onlineOrderSettings->pickupDiscountPercent);
  1657.             $onlineOrderSettings->setEmail($data->onlineOrderSettings->email);
  1658.             $onlineOrderSettings->setSplitPayment($data->onlineOrderSettings->splitPayment);
  1659.             $onlineOrderSettings->setDomain($data->onlineOrderSettings->domain);
  1660.             $onlineOrderSettings->setSchedule($data->onlineOrderSettings->schedule);
  1661.             $onlineOrderSettings->setDeliveryTimeFrom($data->onlineOrderSettings->deliveryTimeFrom);
  1662.             $onlineOrderSettings->setDeliveryTimeTill($data->onlineOrderSettings->deliveryTimeTill);
  1663.             $onlineOrderSettings->setDeliverySchedule($data->onlineOrderSettings->deliverySchedule);
  1664.             $onlineOrderSettings->setDeliveryLeadType($data->onlineOrderSettings->deliveryLeadType);
  1665.             $onlineOrderSettings->setDeliveryLeadTime($data->onlineOrderSettings->deliveryLeadTime);
  1666.             $onlineOrderSettings->setDeliveryIntervalBetweenOrdersType($data->onlineOrderSettings->deliveryIntervalBetweenOrdersType);
  1667.             $onlineOrderSettings->setDeliveryIntervalBetweenOrdersTime($data->onlineOrderSettings->deliveryIntervalBetweenOrdersTime);
  1668.             $onlineOrderSettings->setDeliveryDisableType($data->onlineOrderSettings->deliveryDisableType);
  1669.             $onlineOrderSettings->setDeliveryDisableTime($data->onlineOrderSettings->deliveryDisableTime);
  1670.             $onlineOrderSettings->setDeliveryNearlyEnabled($data->onlineOrderSettings->deliveryNearlyEnabled);
  1671.             $onlineOrderSettings->setDeliveryPriceInfo($data->onlineOrderSettings->deliveryPriceInfo ?? null);
  1672.             $onlineOrderSettings->setDeliveryWorkingTime($data->onlineOrderSettings->deliveryWorkingTime ?? null);
  1673.             $onlineOrderSettings->setPickupCookingTime($data->onlineOrderSettings->pickupCookingTime ?? null);
  1674.             $this->setOnlineOrderSettings($onlineOrderSettings);
  1675.         }
  1676.         if (isset($data->directorID)) {
  1677.             $this->directorID $data->directorID;
  1678.         }
  1679.     }
  1680.     public function isBuyCodeDisable() {
  1681.         return $this->buyCodeDisable;
  1682.     }
  1683.     public function setBuyCodeDisable($buyCodeDisable) {
  1684.         $this->buyCodeDisable $buyCodeDisable;
  1685.     }
  1686.     public function isHideInApp() {
  1687.         return $this->hideInApp;
  1688.     }
  1689.     public function setHideInApp($hideInApp) {
  1690.         $this->hideInApp $hideInApp;
  1691.     }
  1692.     public function getBrandboxEnabled() {
  1693.         return $this->brandboxEnabled;
  1694.     }
  1695.     public function setBrandboxEnabled($brandboxEnabled): void {
  1696.         $this->brandboxEnabled $brandboxEnabled;
  1697.     }
  1698.     public function getDiscountPickupPopup(): ?string
  1699.     {
  1700.         return $this->discountPickupPopup;
  1701.     }
  1702.     public function setDiscountPickupPopup(?string $discountPickupPopup): void
  1703.     {
  1704.         $this->discountPickupPopup $discountPickupPopup;
  1705.     }
  1706.     public function getExternalOfferLink(): ?string
  1707.     {
  1708.         return $this->externalOfferLink;
  1709.     }
  1710.     public function setExternalOfferLink(?string $externalOfferLink): void
  1711.     {
  1712.         $this->externalOfferLink $externalOfferLink;
  1713.     }
  1714.     public function getIsShowExternalOfferLink()
  1715.     {
  1716.         return $this->isShowExternalOfferLink;
  1717.     }
  1718.     public function setIsShowExternalOfferLink($isShowExternalOfferLink): void
  1719.     {
  1720.         $this->isShowExternalOfferLink $isShowExternalOfferLink;
  1721.     }
  1722.     public function getDiscountDeliveryPopup(): ?string
  1723.     {
  1724.         return $this->discountDeliveryPopup;
  1725.     }
  1726.     public function setDiscountDeliveryPopup(?string $discountDeliveryPopup): void
  1727.     {
  1728.         $this->discountDeliveryPopup $discountDeliveryPopup;
  1729.     }
  1730.     public function isFoodOnlineOrderAllowedOnSite(): bool
  1731.     {
  1732.         return $this->isOnlineOrderAllowedByDeviceAndType(
  1733.             OfferOnlineOrderDevice::byValue(OfferOnlineOrderDevice::SITE),
  1734.             OfferOnlineOrderType::byValue(OfferOnlineOrderType::FOOD)
  1735.         );
  1736.     }
  1737.     public function isFoodOnlineOrderAllowedOnApp(): bool
  1738.     {
  1739.         return $this->isOnlineOrderAllowedByDeviceAndType(
  1740.             OfferOnlineOrderDevice::byValue(OfferOnlineOrderDevice::APP),
  1741.             OfferOnlineOrderType::byValue(OfferOnlineOrderType::FOOD)
  1742.         );
  1743.     }
  1744.     public function isGiftCertificateOnlineOrderAllowedOnSite(): bool
  1745.     {
  1746.         return $this->isOnlineOrderAllowedByDeviceAndType(
  1747.             OfferOnlineOrderDevice::byValue(OfferOnlineOrderDevice::SITE),
  1748.             OfferOnlineOrderType::byValue(OfferOnlineOrderType::GIFT_CERTIFICATE)
  1749.         );
  1750.     }
  1751.     public function isGiftCertificateOnlineOrderAllowedOnApp(): bool
  1752.     {
  1753.         return $this->isOnlineOrderAllowedByDeviceAndType(
  1754.             OfferOnlineOrderDevice::byValue(OfferOnlineOrderDevice::APP),
  1755.             OfferOnlineOrderType::byValue(OfferOnlineOrderType::GIFT_CERTIFICATE)
  1756.         );
  1757.     }
  1758.     public function isTireOnlineOrderAllowedOnSite(): bool
  1759.     {
  1760.         return $this->isOnlineOrderAllowedByDeviceAndType(
  1761.             OfferOnlineOrderDevice::byValue(OfferOnlineOrderDevice::SITE),
  1762.             OfferOnlineOrderType::byValue(OfferOnlineOrderType::TIRE)
  1763.         );
  1764.     }
  1765.     public function isTireOnlineOrderAllowedOnApp(): bool
  1766.     {
  1767.         return $this->isOnlineOrderAllowedByDeviceAndType(
  1768.             OfferOnlineOrderDevice::byValue(OfferOnlineOrderDevice::APP),
  1769.             OfferOnlineOrderType::byValue(OfferOnlineOrderType::TIRE)
  1770.         );
  1771.     }
  1772.     public function isOneOfOnlineOrderAllowedOnApp(): bool
  1773.     {
  1774.         if (null === $this->allowedOnlineOrderTypes) {
  1775.             return false;
  1776.         }
  1777.         return \count($this->allowedOnlineOrderTypes[OfferOnlineOrderDevice::APP]) > 0;
  1778.     }
  1779.     public function isOneOfOnlineOrderAllowedOnSite(): bool
  1780.     {
  1781.         if (null === $this->allowedOnlineOrderTypes) {
  1782.             return false;
  1783.         }
  1784.         return \count($this->allowedOnlineOrderTypes[OfferOnlineOrderDevice::SITE]) > 0;
  1785.     }
  1786.     public function getAllowedOnlineOrderTypesOnApp(): ?array
  1787.     {
  1788.         if (null === $this->allowedOnlineOrderTypes || === count($this->allowedOnlineOrderTypes[OfferOnlineOrderDevice::APP])) {
  1789.             return null;
  1790.         }
  1791.         return $this->allowedOnlineOrderTypes[OfferOnlineOrderDevice::APP];
  1792.     }
  1793.     private function isOnlineOrderAllowedByDeviceAndType(OfferOnlineOrderDevice $deviceOfferOnlineOrderType $type): bool
  1794.     {
  1795.         if (null === $this->allowedOnlineOrderTypes) {
  1796.             return false;
  1797.         }
  1798.         return in_array($type->getValue(), $this->allowedOnlineOrderTypes[$device->getValue()], true);
  1799.     }
  1800.     public function getOfferType(bool $isBoughtFreeCode false): int
  1801.     {
  1802.         $offerType self::TYPE_DEFAULT;
  1803.         if (in_array($this->getID(), Dominos::OFFER_IDS_MINSK_AND_REGIONStrue)) {
  1804.             return self::TYPE_DOMINOS;
  1805.         }
  1806.         if ($this->isFoodOnlineOrderAllowedOnApp()) {
  1807.             return $this->isBuyCodeDisable() ? self::TYPE_ONLINE_ORDER_ONLY self::TYPE_ONLINE_ORDER;
  1808.         }
  1809.         if ($this->isGiftCertificateOnlineOrderAllowedOnApp()) {
  1810.             return $this->isBuyCodeDisable() ? self::TYPE_GIFT_CERTIFICATE_DISABLE_CODE self::TYPE_GIFT_CERTIFICATE;
  1811.         }
  1812.         if ($this->getID() === self::PETROL_OFFER_ID) {
  1813.             return self::TYPE_TRIPLE;
  1814.         }
  1815.         if ($this->getTireExtensions()->count() > 0) {
  1816.             return self::TYPE_TIRE;
  1817.         }
  1818.         if (!$isBoughtFreeCode && ($this->isInFreeCodesCategory() || $this->isFree())) {
  1819.             return self::TYPE_FREE_PER_DAY;
  1820.         }
  1821.         return $offerType;
  1822.     }
  1823.     public function isHideFeatures() {
  1824.         return $this->hideFeatures;
  1825.     }
  1826.     public function setHideFeatures($hideFeatures) {
  1827.         $this->hideFeatures $hideFeatures;
  1828.     }
  1829.     public function getFirstGeoLocation(): GeoLocation
  1830.     {
  1831.         return $this->geoLocations->first();
  1832.     }
  1833.     public function getDeliveryTimeTeaser(): ?string
  1834.     {
  1835.         return $this->deliveryTimeTeaser;
  1836.     }
  1837.     public function setDeliveryTimeTeaser(?string $deliveryTimeTeaser): void
  1838.     {
  1839.         $this->deliveryTimeTeaser $deliveryTimeTeaser;
  1840.     }
  1841.     public function isExternalOfferLinkAndShow(): bool
  1842.     {
  1843.         return null !== $this->externalOfferLink && $this->isShowExternalOfferLink;
  1844.     }
  1845.     public function isNotAccess(): bool
  1846.     {
  1847.         return !$this->isActive() || $this->isHidden() || !$this->isInActivePeriod() || $this->isBuyCodeDisable();
  1848.     }
  1849.     public function getFoodcourtInfoTeaser(): ?string
  1850.     {
  1851.         return $this->foodcourtInfoTeaser;
  1852.     }
  1853.     public function setFoodcourtInfoTeaser(?string $foodcourtInfoTeaser): void
  1854.     {
  1855.         $this->foodcourtInfoTeaser $foodcourtInfoTeaser;
  1856.     }
  1857.     public function getFoodcourtInfoColorTeaser(): ?string
  1858.     {
  1859.         return $this->foodcourtInfoColorTeaser;
  1860.     }
  1861.     public function setFoodcourtInfoColorTeaser(?string $foodcourtInfoColorTeaser): void
  1862.     {
  1863.         $this->foodcourtInfoColorTeaser $foodcourtInfoColorTeaser;
  1864.     }
  1865.     public function isIncludedInBeauty(): bool
  1866.     {
  1867.         return $this->isIncludedInBeauty;
  1868.     }
  1869.     public function setIsIncludedInBeauty(bool $isIncludedInBeauty): void
  1870.     {
  1871.         $this->isIncludedInBeauty $isIncludedInBeauty;
  1872.     }
  1873.     public function getStatus(): OfferStatus
  1874.     {
  1875.         return $this->isVisible() ? OfferStatus::byValue(OfferStatus::ACTIVATED) : OfferStatus::byValue(OfferStatus::DEACTIVATED);
  1876.     }
  1877.     public function getCity(): ?City
  1878.     {
  1879.         foreach ($this->categories as $category) {
  1880.             if ($category->getID() === $this->getDefaultCategoryID()) {
  1881.                 return $category->getCity();
  1882.             }
  1883.         }
  1884.         $category $this->categories->first();
  1885.         return false === $category null $category->getCity();
  1886.     }
  1887.     public function isOnlineAutoOpened(): bool
  1888.     {
  1889.         return $this->onlineAutoOpened;
  1890.     }
  1891.     public function setOnlineAutoOpened(bool $onlineAutoOpened): void
  1892.     {
  1893.         $this->onlineAutoOpened $onlineAutoOpened;
  1894.     }
  1895.     public function isFoodcourtLogoEnabled(): bool
  1896.     {
  1897.         return $this->foodcourtLogoEnabled;
  1898.     }
  1899.     public function setFoodcourtLogoEnabled(bool $foodcourtLogoEnabled): void
  1900.     {
  1901.         $this->foodcourtLogoEnabled $foodcourtLogoEnabled;
  1902.     }
  1903.     public function isOnlineOrderGiftEnabled(): bool
  1904.     {
  1905.         return $this->onlineOrderGiftEnabled;
  1906.     }
  1907.     public function setOnlineOrderGiftEnabled(bool $onlineOrderGiftEnabled): void
  1908.     {
  1909.         $this->onlineOrderGiftEnabled $onlineOrderGiftEnabled;
  1910.     }
  1911.     public function isBuyCodeInAppOnly(): bool
  1912.     {
  1913.         return $this->buyCodeInAppOnly;
  1914.     }
  1915.     public function setBuyCodeInAppOnly(bool $buyCodeInAppOnly): void
  1916.     {
  1917.         $this->buyCodeInAppOnly $buyCodeInAppOnly;
  1918.     }
  1919.     public function isShowProductsInOfferDescription(): bool
  1920.     {
  1921.         return $this->showProductsInOfferDescription;
  1922.     }
  1923.     public function setShowProductsInOfferDescription(bool $showProductsInOfferDescription): void
  1924.     {
  1925.         $this->showProductsInOfferDescription $showProductsInOfferDescription;
  1926.     }
  1927.     public function isCheckAddressInOfferMenu(): bool
  1928.     {
  1929.         return $this->checkAddressInOfferMenu;
  1930.     }
  1931.     public function setCheckAddressInOfferMenu(bool $checkAddressInOfferMenu): void
  1932.     {
  1933.         $this->checkAddressInOfferMenu $checkAddressInOfferMenu;
  1934.     }
  1935.     public function isShowMapIconInApp(): bool
  1936.     {
  1937.         return $this->showMapIconInApp;
  1938.     }
  1939.     public function setShowMapIconInApp(bool $showMapIconInApp): void
  1940.     {
  1941.         $this->showMapIconInApp $showMapIconInApp;
  1942.     }
  1943.     public function isDuplicateCodesEnable(): bool
  1944.     {
  1945.         return in_array($this->ID, [
  1946.                 self::CAR_SHARING_OFFER_ID,
  1947.                 280939,
  1948.                 289045,
  1949.                 289751,
  1950.                 self::TL24_OFFER_ID,
  1951.                 294815,
  1952.             ],
  1953.             true,
  1954.         );
  1955.     }
  1956.     public function getCityByFirstCategory(): ?City
  1957.     {
  1958.         return $this->categories->count() > $this->categories->first()->getCity() : null;
  1959.     }
  1960.     public function isSeparateTabForCertificatesInApp(): bool
  1961.     {
  1962.         return $this->separateTabForCertificatesInApp;
  1963.     }
  1964.     public function setSeparateTabForCertificatesInApp(bool $separateTabForCertificatesInApp): void
  1965.     {
  1966.         $this->separateTabForCertificatesInApp $separateTabForCertificatesInApp;
  1967.     }
  1968.     public function getMapPrice(): ?float
  1969.     {
  1970.         return $this->mapPrice;
  1971.     }
  1972.     public function updateMapPrice(?float $mapPrice): void
  1973.     {
  1974.         $this->mapPrice $mapPrice;
  1975.     }
  1976.     public function getMapRating(): ?int
  1977.     {
  1978.         return $this->mapRating;
  1979.     }
  1980.     public function updateMapRating(?int $mapRating): void
  1981.     {
  1982.         $this->mapRating $mapRating;
  1983.     }
  1984.     public function getSumInCurrency(float $sum): ?float
  1985.     {
  1986.         return $this->isActiveCurrencyCalculator() && null !== $this->getBankCurrency()
  1987.             ? $sum $this->getBankCurrency()->getRate()
  1988.             : null;
  1989.     }
  1990.     public function getDirectorName(): ?string
  1991.     {
  1992.         if (null !== $this->directorName) {
  1993.             return $this->directorName;
  1994.         }
  1995.         if ($this->directors->count() > 0) {
  1996.             $directorName $this->directors->first()->getName();
  1997.             $this->directorName $directorName;
  1998.             return $directorName;
  1999.         }
  2000.         return null;
  2001.     }
  2002.     public function getOfferFoodDeliveryZoneNames(): array
  2003.     {
  2004.         if (null === $this->offerFoodDeliveryZone) {
  2005.             return [];
  2006.         }
  2007.         $sortedZoneNames = [];
  2008.         foreach ($this->offerFoodDeliveryZone->toArray() as $zone) {
  2009.             $sortedZoneNames[$zone->getPosition()] = $zone->getName();
  2010.         }
  2011.         return $sortedZoneNames;
  2012.     }
  2013.     public function getTelegram(): ?string
  2014.     {
  2015.         return $this->telegram;
  2016.     }
  2017.     public function getViber(): ?string
  2018.     {
  2019.         return $this->viber;
  2020.     }
  2021.     public function setTelegram(?string $telegram): void
  2022.     {
  2023.         $this->telegram $telegram;
  2024.     }
  2025.     public function setViber(?string $viber): void
  2026.     {
  2027.         $this->viber $viber;
  2028.     }
  2029.     public function getMessengerCallBack(): ?string
  2030.     {
  2031.         return $this->messengerCallBack;
  2032.     }
  2033.     public function setMessengerCallBack(?string $messengerCallBack): void
  2034.     {
  2035.         $this->messengerCallBack $messengerCallBack;
  2036.     }
  2037.     public function isBundleOffer(): bool
  2038.     {
  2039.         return in_array($this->getID(), [self::MARSEL_MASSAGE_OFFER_IDself::FREESTYLE_CERTIFICATE_OFFER_ID], true);
  2040.     }
  2041. }