src/Entity/Category.php line 9

Open in your IDE?
  1. <?php
  2. namespace Slivki\Entity;
  3. use DateTime;
  4. use JsonSerializable;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. class Category extends AbstractCategoryBase implements JsonSerializable
  7. {
  8.     const CATEGORY_ID 1488;
  9.     const OFFER_CATEGORY_ID 1;
  10.     const SALE_CATEGORY_ID 2;
  11.     const DISCOUNT_CARD_CATEGORY_ID 3;
  12.     const PARTNER_CATEGORY_ID 4;
  13.     const INSTALLMENT_CATEGORY_ID 5;
  14.     const GENDER_CATEGORY_ID 6;
  15.     const PRICE_CATEGORY_ID 7;
  16.     const TRANSPORT_TYPE_CATEGORY_ID 8;
  17.     const TOUR_TYPE_CATEGORY_ID 9;
  18.     const DEFAULT_CATEGORY_TYPE 1;
  19.     const SERVICE_CATEGORY_TYPE 2;
  20.     const SUPPLIER_CATEGORY_TYPE 3;
  21.     const DEFAULT_PRICE_CATEGORY_TYPE 4;
  22.     const TOURISM_PRICE_CATEGORY_TYPE 5;
  23.     const LOCATION_CATEGORY_TYPE 9;
  24.     const FREE_CATEGORY_TYPE 11;
  25.     const FREE_CODES_CATEGORY_ID 41;
  26.     const TOP_CATEGORY_CODE 'top';
  27.     const TOP_CATEGORY_ID 23;
  28.     const RECOMMEND_CATEGORY_ID 3;
  29.     const VIP_CATEGORY_ID 97;
  30.     const NEW_OFFER_CATEGORY_ID 14;
  31.     const NEW_SALE_CATEGORY_ID 59;
  32.     const TOURISM_CATEGORY_ID 11;
  33.     const TOURISM_POPULAR_CATEGORY_ID 592;
  34.     const AUTO_CATEGORY 10;
  35.     const BEAUTY_SALONS_CATEGORY_ID 8;
  36.     const PHOTOGUIDE_SALE_CATEGORY_ID 56;
  37.     const FOOD_SALE_CATEGORY_ID 55;
  38.     const COMPANY_NEWS_SALE_CATEGORY_ID 53;
  39.     const FLIER_SALE_CATEGORY_ID 2202;
  40.     const FLIER_COMPANY_NEWS_CATEGORY_ID 2927;
  41.     const GIFT_CERTIFICATES_CATEGORY_ID 24;
  42.     const NEW_YEAR_CATEGORY_ID 1403;
  43.     const NEW_YEAR_SALE_CATEGORY_ID 4517;
  44.     const FREELANCE_CATEGORY_ID 2087;
  45.     const GIFT_FROM_SLIVKI_CATEGORY_ID 3065;
  46.     const LANDING_IMAGE_PATH '/public/znijki-media/initial/default/1009921/';
  47.     const MOBILE_MENU_ICON_IMAGE_PATH '/public/znijki-media/initial/default/1009921/';
  48.     const CATEGORY_HOT_FEED_IMAGE_PATH '/public/znijki-media/initial/default/1009921/';
  49.     const PARTNER_OFFER_OTHER_CATEGORY_ID 1976;
  50.     const FOOD_CATEGORY_ID 9;
  51.     const KIDS_CATEGORY_ID 17;
  52.     const APARTMENTS_CATEGORY_ID 2020;
  53.     const PSEUDO_CATEGORY_LIST = [self::RECOMMEND_CATEGORY_IDself::NEW_OFFER_CATEGORY_IDself::TOP_CATEGORY_ID];
  54.     const SALE_VIDEO_GUIDE_CATEGORY_ID 3894;
  55.     const BANQUET_CATEGORY_ID 2066;
  56.     const TIRE_FITTING_CATEGORY_ID 492;
  57.     const MANICURE_CATEGORY_ID 160;
  58.     const PEDICURE_CATEGORY_ID 162;
  59.     const SALE_VIDEO_GUIDE_AUTORS_CATEGORY_ID 4367;
  60.     const POPULAR_SALE_VIDEO_GUIDE_CATEGORY_ID 4387;
  61.     const NEW_SALE_VIDEO_GUIDE_CATEGORY_ID 4447;
  62.     const POPULAR_FLIER_CATEGORY_ID 6287;
  63.     const BLACK_FRIDAY_CATEGORY_ID 3065;
  64.     const MEDICAL_CENTER_CATEGORY_ID 54;
  65.     const HEALTH_AND_SPORT_CATEGORY_ID 12;
  66.     const LASER_EPILATION_CATEGORY_ID 212;
  67.     const PREMIUM_CATEGORY_ID 97;
  68.     const COUNTRY_CATEGORY_ID 43;
  69.     const TOP_BEAUTY_CATEGORY_ID 5034;
  70.     const TOP_BEAUTY_MANICURE_PEDICURE_CATEGORY_ID 9404;
  71.     const BEAUTY_SALONS_PREMIUM_CATEGORY_ID 411;
  72.     const GOODS_AND_GIFTS_CATEGORY_ID 18;
  73.     public const FOOD_DELIVERY_CATEGORY_ID 473;
  74.     private const DEFAULT_ME_ON_MAP_POSITION 9999;
  75.     public const RESTOFEST_CATEGORY_ID 11919;
  76.     public const SUSHI_CATEGORY_ID 476;
  77.     public const BEYOND_MINSK_RING_ROAD_DELIVERY_CATEGORY_ID 9434;
  78.     public const BREAKFAST_CATEGORY_ID 3109;
  79.     public const ROUND_THE_CLOCK_CATEGORY_ID 13986;
  80.     protected $typeID;
  81.     protected $categoryType;
  82.     protected $code;
  83.     protected $past;
  84.     protected $topCount;
  85.     protected $domainObjectID;
  86.     protected $entityCount;
  87.     protected $description;
  88.     protected $banners;
  89.     protected $brandingBanners;
  90.     protected $mobileApiHash;
  91.     protected $sales;
  92.     protected $lastModified;
  93.     protected $inMenuBottom;
  94.     protected $hotFeedMedia;
  95.     protected $hotFeedIconMedia;
  96.     protected $hotFeedName;
  97.     protected $unpopular;
  98.     protected $position;
  99.     protected $featuredInMenu;
  100.     protected $telegramBotShow;
  101.     protected $telegramBotName;
  102.     protected $telegramBotPosition;
  103.     protected $utmCampaign;
  104.     protected bool $meOnMapActive;
  105.     protected ?int $meOnMapPosition;
  106.     protected bool $meOnMapFeaturedActive;
  107.     protected ?int $meOnMapFeaturedPosition;
  108.     protected int $splitOffersWithSameCategories;
  109.     private bool $activeInBestOffersCategory false;
  110.     private ?bool $showItemsCatalog false;
  111.     private bool $hideWorkExamples false;
  112.     private bool $isBonusCode false;
  113.     public function __construct() {
  114.         $this->children = new ArrayCollection();
  115.         $this->parents = new ArrayCollection();
  116.         $this->banners = new ArrayCollection();
  117.         $this->brandingBanners = new ArrayCollection();
  118.         $this->sales = new ArrayCollection();
  119.         $this->meOnMapActive false;
  120.         $this->meOnMapFeaturedActive false;
  121.         $this->splitOffersWithSameCategories 0;
  122.     }
  123.     public function getDescription() {
  124.         return $this->description;
  125.     }
  126.     public function setDescription($description) {
  127.         $this->description $description;
  128.     }
  129.     public function getTypeID() {
  130.         return $this->typeID;
  131.     }
  132.     public function setTypeID($typeID) {
  133.         $this->typeID $typeID;
  134.     }
  135.     public function getLastModified() {
  136.         return $this->lastModified;
  137.     }
  138.     public function setLastModified($lastModified) {
  139.         $this->lastModified $lastModified;
  140.     }
  141.     /**
  142.      * @return CategoryType
  143.      */
  144.     public function getCategoryType() {
  145.         return $this->categoryType;
  146.     }
  147.     public function setCategoryType($category) {
  148.         $this->categoryType $category;
  149.     }
  150.     public function getCode() {
  151.         return $this->code;
  152.     }
  153.     public function setCode($code) {
  154.         $this->code $code;
  155.     }
  156.     public function isPast() {
  157.         return $this->past;
  158.     }
  159.     public function setPast($past) {
  160.         $this->past $past;
  161.     }
  162.     public function getTopCount() {
  163.         return $this->topCount;
  164.     }
  165.     public function setTopCount($topCount) {
  166.         $this->topCount $topCount;
  167.     }
  168.     public function getDomainObjectID() {
  169.         return $this->domainObjectID;
  170.     }
  171.     public function setDomainObjectID($domainObjectID) {
  172.         $this->domainObjectID $domainObjectID;
  173.     }
  174.     public function getEntityCount() {
  175.         return $this->entityCount;
  176.     }
  177.     public function setEntityCount($entityCount) {
  178.         $this->entityCount $entityCount;
  179.     }
  180.     public function setSubCategories($subCategoryList) {
  181.         $this->children $subCategoryList;
  182.     }
  183.     public function clearBanners() {
  184.         $this->banners = new ArrayCollection();
  185.     }
  186.     public function getBanners() {
  187.         return $this->banners;
  188.     }
  189.     public function getBrandingBanners() {
  190.         return $this->brandingBanners;
  191.     }
  192.     public function setHotFeedMedia(Media $hotFeedMedia null) {
  193.         $this->hotFeedMedia $hotFeedMedia;
  194.     }
  195.     /**
  196.      * @return null|Media
  197.      */
  198.     public function getHotFeedMedia() {
  199.         return $this->hotFeedMedia;
  200.     }
  201.     public function setHotFeedIconMedia(Media $hotFeedIconMedia null) {
  202.         $this->hotFeedIconMedia $hotFeedIconMedia;
  203.     }
  204.     /**
  205.      * @return null|Media
  206.      */
  207.     public function getHotFeedIconMedia() {
  208.         if ($this->hotFeedIconMedia || $this->getParentCategories()->count() == 0) {
  209.             return $this->hotFeedIconMedia;
  210.         }
  211.         foreach ($this->getParentCategories() as $parentCategory) {
  212.             $iconMedia $parentCategory->getHotFeedIconMedia();
  213.             if ($iconMedia) {
  214.                 return $iconMedia;
  215.             }
  216.         }
  217.         return null;
  218.     }
  219.     public function getHotFeedName() {
  220.         return $this->hotFeedName;
  221.     }
  222.     public function setHotFeedName($hotFeedName) {
  223.         $this->hotFeedName $hotFeedName;
  224.     }
  225.     public function getBannersByType($typeID) {
  226.         $banners = array();
  227.         foreach($this->banners as $key => $banner) {
  228.             if($banner->getTypeID() == $typeID) {
  229.                 $banners[] = $banner;
  230.             }
  231.         }
  232.         usort($banners, function ($firstBanner$secondBanner) {
  233.             if(($firstID $firstBanner->getID()) ==  ($secondID $secondBanner->getID())) {
  234.                 return 0;
  235.             }
  236.             return $firstID $secondID : -1;
  237.         });
  238.         return $banners;
  239.     }
  240.     public function getCountActiveBannersByType($typeID) {
  241.         $count 0;
  242.         foreach($this->banners as $banner) {
  243.             if($banner->getTypeID() == $typeID and $banner->isActive()) {
  244.                 $count++;
  245.             }
  246.         }
  247.         return $count;
  248.     }
  249.     public function getActiveBannersByType($typeID) {
  250.         $banners = array();
  251.         foreach($this->banners as $key => $banner) {
  252.             if($banner->getTypeID() == $typeID && $banner->isActive()) {
  253.                 $banners[] = $banner;
  254.             }
  255.         }
  256.         usort($banners, function ($firstBanner$secondBanner) {
  257.             if(($firstID $firstBanner->getID()) ==  ($secondID $secondBanner->getID())) {
  258.                 return 0;
  259.             }
  260.             return $firstID $secondID : -1;
  261.         });
  262.         return $banners;
  263.     }
  264.     public function addBanner(Banner $banner) {
  265.         if (!$this->banners->contains($banner)) {
  266.             $this->banners->add($banner);
  267.         }
  268.     }
  269.     public function deleteBanner($banner) {
  270.         $this->banners->removeElement($banner);
  271.     }
  272.     public function getMobileApiHash() {
  273.         return $this->mobileApiHash;
  274.     }
  275.     public function setMobileApiHash($mobileApiHash) {
  276.         $this->mobileApiHash $mobileApiHash;
  277.     }
  278.     public function getSales() {
  279.         return $this->sales;
  280.     }
  281.     public function addSale(Sale $sale) {
  282.         if (!$this->sales->contains($sale)) {
  283.             $this->sales->add($sale);
  284.         }
  285.     }
  286.     public function removeSale(Sale $sale) {
  287.         if ($this->sales->contains($sale)) {
  288.             $this->sales->removeElement($sale);
  289.         }
  290.     }
  291.     public function clearSales() {
  292.         $this->sales = new ArrayCollection();
  293.     }
  294.     public function isInMenuBottom() {
  295.         return $this->inMenuBottom;
  296.     }
  297.     public function setInMenuBottom($inMenuBottom) {
  298.         $this->inMenuBottom $inMenuBottom;
  299.     }
  300.     public function getTopParentCategory() {
  301.         if ($this->parents->count() == 0) {
  302.             return $this;
  303.         }
  304.         foreach ($this->parents as $category) {
  305.             if ($category->isActive() && !$category->isPast() && $category->getTypeID() != Category::SUPPLIER_CATEGORY_TYPE && !in_array($category->getID(), Category::PSEUDO_CATEGORY_LIST)) {
  306.                 return $category->getTopParentCategory();
  307.             }
  308.         }
  309.     }
  310.     public function isUnpopular() {
  311.         return $this->unpopular;
  312.     }
  313.     public function setUnpopular($unpopular) {
  314.         $this->unpopular $unpopular;
  315.     }
  316.     public function isFeaturedInMenu() {
  317.         return $this->featuredInMenu;
  318.     }
  319.     public function setFeaturedInMenu($featuredInMenu) {
  320.         $this->featuredInMenu $featuredInMenu;
  321.     }
  322.     public function getPosition() {
  323.         return $this->position;
  324.     }
  325.     public function setPosition($position) {
  326.         $this->position $position;
  327.     }
  328.     public function getType() {
  329.         return self::DEFAULT_CATEGORY_TYPE;
  330.     }
  331.     public function isTelegramBotShow() {
  332.         return $this->telegramBotShow;
  333.     }
  334.     public function setTelegramBotShow($telegramBotShow) {
  335.         $this->telegramBotShow $telegramBotShow;
  336.     }
  337.     public function getTelegramBotName() {
  338.         return $this->telegramBotName;
  339.     }
  340.     public function setTelegramBotName($telegramBotName) {
  341.         $this->telegramBotName $telegramBotName;
  342.     }
  343.     public function getTelegramBotPosition() {
  344.         return $this->telegramBotPosition;
  345.     }
  346.     public function setTelegramBotPosition($telegramBotPosition) {
  347.         $this->telegramBotPosition $telegramBotPosition;
  348.     }
  349.     public function getUtmCampaign() {
  350.         return $this->utmCampaign;
  351.     }
  352.     public function setUtmCampaign($utmCampaign) {
  353.         $this->utmCampaign $utmCampaign;
  354.     }
  355.     public function isMeOnMapActive(): bool
  356.     {
  357.         return $this->meOnMapActive;
  358.     }
  359.     public function activateMeOnMap(): void
  360.     {
  361.         $this->meOnMapActive true;
  362.         $this->meOnMapPosition self::DEFAULT_ME_ON_MAP_POSITION;
  363.     }
  364.     public function deactivateMeOnMap(): void
  365.     {
  366.         $this->meOnMapActive false;
  367.         $this->meOnMapPosition null;
  368.     }
  369.     public function getMeOnMapPosition(): int
  370.     {
  371.         return $this->meOnMapPosition ?? self::DEFAULT_ME_ON_MAP_POSITION;
  372.     }
  373.     public function editMeOnMapPosition(int $meOnMapPosition): void
  374.     {
  375.         $this->meOnMapPosition $meOnMapPosition;
  376.     }
  377.     public function isMeOnMapFeaturedActive(): bool
  378.     {
  379.         return $this->meOnMapFeaturedActive;
  380.     }
  381.     public function activateMeOnMapFeatured(): void
  382.     {
  383.         $this->meOnMapFeaturedActive true;
  384.         $this->meOnMapFeaturedPosition self::DEFAULT_ME_ON_MAP_POSITION;
  385.     }
  386.     public function deactivateMeOnMapFeatured(): void
  387.     {
  388.         $this->meOnMapFeaturedActive false;
  389.         $this->meOnMapFeaturedPosition null;
  390.     }
  391.     public function getMeOnMapFeaturedPosition(): int
  392.     {
  393.         return $this->meOnMapFeaturedPosition ?? self::DEFAULT_ME_ON_MAP_POSITION;
  394.     }
  395.     public function editMeOnMapFeaturedPosition(int $meOnMapFeaturedPosition): void
  396.     {
  397.         $this->meOnMapFeaturedPosition $meOnMapFeaturedPosition;
  398.     }
  399.     public function getSplitOffersWithSameCategories(): int
  400.     {
  401.         return $this->splitOffersWithSameCategories;
  402.     }
  403.     public function setSplitOffersWithSameCategories(int $splitOffersWithSameCategories): void
  404.     {
  405.         $this->splitOffersWithSameCategories $splitOffersWithSameCategories;
  406.     }
  407.     public function activate(): void
  408.     {
  409.         $this->active true;
  410.     }
  411.     public function deactivate(): void
  412.     {
  413.         $this->active false;
  414.     }
  415.     public function updateModifyDate(): void
  416.     {
  417.         $this->lastModified = new DateTime();
  418.     }
  419.     public function getShowItemsCatalog(): ?bool
  420.     {
  421.         return $this->showItemsCatalog;
  422.     }
  423.     public function setShowItemsCatalog(?bool $shouldShowItemsCatalog): void
  424.     {
  425.         $this->showItemsCatalog $shouldShowItemsCatalog;
  426.     }
  427.     public function isActiveInBestOffersCategory(): bool
  428.     {
  429.         return $this->activeInBestOffersCategory;
  430.     }
  431.     public function activateInBestOffersCategory(): void
  432.     {
  433.         $this->activeInBestOffersCategory true;
  434.     }
  435.     public function deactivateInBestOffersCategory(): void
  436.     {
  437.         $this->activeInBestOffersCategory false;
  438.     }
  439.     public function isHideWorkExamples(): bool
  440.     {
  441.         return $this->hideWorkExamples;
  442.     }
  443.     public function setHideWorkExamples(bool $hideWorkExamples): void
  444.     {
  445.         $this->hideWorkExamples $hideWorkExamples;
  446.     }
  447.     public function isBonusCode(): bool
  448.     {
  449.         return $this->isBonusCode;
  450.     }
  451.     public function setIsBonusCode(bool $isBonusCode): void
  452.     {
  453.         $this->isBonusCode $isBonusCode;
  454.     }
  455.     public function getTarantoolTuple() {
  456.         return [
  457.             $this->ID,
  458.             $this->name,
  459.             $this->domainObjectID,
  460.             $this->getType(),
  461.             $this->entityCount,
  462.             $this->city $this->city->getID() : City::DEFAULT_CITY_ID,
  463.             $this->typeID,
  464.             $this->sortOrder,
  465.             $this->topCount
  466.         ];
  467.     }
  468.     public function jsonSerialize(): array
  469.     {
  470.         return [
  471.             'ID' => $this->ID,
  472.             'typeID' => $this->typeID,
  473.             'name' => $this->name,
  474.             'hotFeedName' => $this->hotFeedName,
  475.             'active' => $this->active,
  476.             'sortOrder' => $this->sortOrder,
  477.             'position' => $this->position,
  478.             'categoryType' => $this->categoryType,
  479.             'code' => $this->code,
  480.             'past' => $this->past,
  481.             'topCount' => $this->topCount,
  482.             'domainObjectID' => $this->domainObjectID,
  483.             'entityCount' => $this->entityCount,
  484.             'description' => $this->description,
  485.             'inMenuBottom' => $this->inMenuBottom,
  486.             'unpopular' => $this->unpopular,
  487.             'featuredInMenu' => $this->featuredInMenu,
  488.             'telegramBotShow' => $this->telegramBotShow,
  489.             'telegramBotName' => $this->telegramBotName,
  490.             'utmCampaign' => $this->utmCampaign,
  491.             'h1' => $this->h1,
  492.             'splitOffersWithSameCategories' => $this->splitOffersWithSameCategories,
  493.             'showItemsCatalog' => $this->showItemsCatalog,
  494.             'mapPinColor' => $this->mapPinColor,
  495.             'hideWorkExamples' => $this->hideWorkExamples,
  496.             'isBonusCode' => $this->isBonusCode,
  497.         ];
  498.     }
  499. }