<?php
namespace Slivki\Entity;
use DateTime;
use JsonSerializable;
use Doctrine\Common\Collections\ArrayCollection;
class Category extends AbstractCategoryBase implements JsonSerializable
{
const CATEGORY_ID = 1488;
const OFFER_CATEGORY_ID = 1;
const SALE_CATEGORY_ID = 2;
const DISCOUNT_CARD_CATEGORY_ID = 3;
const PARTNER_CATEGORY_ID = 4;
const INSTALLMENT_CATEGORY_ID = 5;
const GENDER_CATEGORY_ID = 6;
const PRICE_CATEGORY_ID = 7;
const TRANSPORT_TYPE_CATEGORY_ID = 8;
const TOUR_TYPE_CATEGORY_ID = 9;
const DEFAULT_CATEGORY_TYPE = 1;
const SERVICE_CATEGORY_TYPE = 2;
const SUPPLIER_CATEGORY_TYPE = 3;
const DEFAULT_PRICE_CATEGORY_TYPE = 4;
const TOURISM_PRICE_CATEGORY_TYPE = 5;
const LOCATION_CATEGORY_TYPE = 9;
const FREE_CATEGORY_TYPE = 11;
const FREE_CODES_CATEGORY_ID = 41;
const TOP_CATEGORY_CODE = 'top';
const TOP_CATEGORY_ID = 23;
const RECOMMEND_CATEGORY_ID = 3;
const VIP_CATEGORY_ID = 97;
const NEW_OFFER_CATEGORY_ID = 14;
const NEW_SALE_CATEGORY_ID = 59;
const TOURISM_CATEGORY_ID = 11;
const TOURISM_POPULAR_CATEGORY_ID = 592;
const AUTO_CATEGORY = 10;
const BEAUTY_SALONS_CATEGORY_ID = 8;
const PHOTOGUIDE_SALE_CATEGORY_ID = 56;
const FOOD_SALE_CATEGORY_ID = 55;
const COMPANY_NEWS_SALE_CATEGORY_ID = 53;
const FLIER_SALE_CATEGORY_ID = 2202;
const FLIER_COMPANY_NEWS_CATEGORY_ID = 2927;
const GIFT_CERTIFICATES_CATEGORY_ID = 24;
const NEW_YEAR_CATEGORY_ID = 1403;
const NEW_YEAR_SALE_CATEGORY_ID = 4517;
const FREELANCE_CATEGORY_ID = 2087;
const GIFT_FROM_SLIVKI_CATEGORY_ID = 3065;
const LANDING_IMAGE_PATH = '/public/znijki-media/initial/default/1009921/';
const MOBILE_MENU_ICON_IMAGE_PATH = '/public/znijki-media/initial/default/1009921/';
const CATEGORY_HOT_FEED_IMAGE_PATH = '/public/znijki-media/initial/default/1009921/';
const PARTNER_OFFER_OTHER_CATEGORY_ID = 1976;
const FOOD_CATEGORY_ID = 9;
const KIDS_CATEGORY_ID = 17;
const APARTMENTS_CATEGORY_ID = 2020;
const PSEUDO_CATEGORY_LIST = [self::RECOMMEND_CATEGORY_ID, self::NEW_OFFER_CATEGORY_ID, self::TOP_CATEGORY_ID];
const SALE_VIDEO_GUIDE_CATEGORY_ID = 3894;
const BANQUET_CATEGORY_ID = 2066;
const TIRE_FITTING_CATEGORY_ID = 492;
const MANICURE_CATEGORY_ID = 160;
const PEDICURE_CATEGORY_ID = 162;
const SALE_VIDEO_GUIDE_AUTORS_CATEGORY_ID = 4367;
const POPULAR_SALE_VIDEO_GUIDE_CATEGORY_ID = 4387;
const NEW_SALE_VIDEO_GUIDE_CATEGORY_ID = 4447;
const POPULAR_FLIER_CATEGORY_ID = 6287;
const BLACK_FRIDAY_CATEGORY_ID = 3065;
const MEDICAL_CENTER_CATEGORY_ID = 54;
const HEALTH_AND_SPORT_CATEGORY_ID = 12;
const LASER_EPILATION_CATEGORY_ID = 212;
const PREMIUM_CATEGORY_ID = 97;
const COUNTRY_CATEGORY_ID = 43;
const TOP_BEAUTY_CATEGORY_ID = 5034;
const TOP_BEAUTY_MANICURE_PEDICURE_CATEGORY_ID = 9404;
const BEAUTY_SALONS_PREMIUM_CATEGORY_ID = 411;
const GOODS_AND_GIFTS_CATEGORY_ID = 18;
public const FOOD_DELIVERY_CATEGORY_ID = 473;
private const DEFAULT_ME_ON_MAP_POSITION = 9999;
public const RESTOFEST_CATEGORY_ID = 11919;
public const SUSHI_CATEGORY_ID = 476;
public const BEYOND_MINSK_RING_ROAD_DELIVERY_CATEGORY_ID = 9434;
public const BREAKFAST_CATEGORY_ID = 3109;
public const ROUND_THE_CLOCK_CATEGORY_ID = 13986;
protected $typeID;
protected $categoryType;
protected $code;
protected $past;
protected $topCount;
protected $domainObjectID;
protected $entityCount;
protected $description;
protected $banners;
protected $brandingBanners;
protected $mobileApiHash;
protected $sales;
protected $lastModified;
protected $inMenuBottom;
protected $hotFeedMedia;
protected $hotFeedIconMedia;
protected $hotFeedName;
protected $unpopular;
protected $position;
protected $featuredInMenu;
protected $telegramBotShow;
protected $telegramBotName;
protected $telegramBotPosition;
protected $utmCampaign;
protected bool $meOnMapActive;
protected ?int $meOnMapPosition;
protected bool $meOnMapFeaturedActive;
protected ?int $meOnMapFeaturedPosition;
protected int $splitOffersWithSameCategories;
private bool $activeInBestOffersCategory = false;
private ?bool $showItemsCatalog = false;
private bool $hideWorkExamples = false;
private bool $isBonusCode = false;
public function __construct() {
$this->children = new ArrayCollection();
$this->parents = new ArrayCollection();
$this->banners = new ArrayCollection();
$this->brandingBanners = new ArrayCollection();
$this->sales = new ArrayCollection();
$this->meOnMapActive = false;
$this->meOnMapFeaturedActive = false;
$this->splitOffersWithSameCategories = 0;
}
public function getDescription() {
return $this->description;
}
public function setDescription($description) {
$this->description = $description;
}
public function getTypeID() {
return $this->typeID;
}
public function setTypeID($typeID) {
$this->typeID = $typeID;
}
public function getLastModified() {
return $this->lastModified;
}
public function setLastModified($lastModified) {
$this->lastModified = $lastModified;
}
/**
* @return CategoryType
*/
public function getCategoryType() {
return $this->categoryType;
}
public function setCategoryType($category) {
$this->categoryType = $category;
}
public function getCode() {
return $this->code;
}
public function setCode($code) {
$this->code = $code;
}
public function isPast() {
return $this->past;
}
public function setPast($past) {
$this->past = $past;
}
public function getTopCount() {
return $this->topCount;
}
public function setTopCount($topCount) {
$this->topCount = $topCount;
}
public function getDomainObjectID() {
return $this->domainObjectID;
}
public function setDomainObjectID($domainObjectID) {
$this->domainObjectID = $domainObjectID;
}
public function getEntityCount() {
return $this->entityCount;
}
public function setEntityCount($entityCount) {
$this->entityCount = $entityCount;
}
public function setSubCategories($subCategoryList) {
$this->children = $subCategoryList;
}
public function clearBanners() {
$this->banners = new ArrayCollection();
}
public function getBanners() {
return $this->banners;
}
public function getBrandingBanners() {
return $this->brandingBanners;
}
public function setHotFeedMedia(Media $hotFeedMedia = null) {
$this->hotFeedMedia = $hotFeedMedia;
}
/**
* @return null|Media
*/
public function getHotFeedMedia() {
return $this->hotFeedMedia;
}
public function setHotFeedIconMedia(Media $hotFeedIconMedia = null) {
$this->hotFeedIconMedia = $hotFeedIconMedia;
}
/**
* @return null|Media
*/
public function getHotFeedIconMedia() {
if ($this->hotFeedIconMedia || $this->getParentCategories()->count() == 0) {
return $this->hotFeedIconMedia;
}
foreach ($this->getParentCategories() as $parentCategory) {
$iconMedia = $parentCategory->getHotFeedIconMedia();
if ($iconMedia) {
return $iconMedia;
}
}
return null;
}
public function getHotFeedName() {
return $this->hotFeedName;
}
public function setHotFeedName($hotFeedName) {
$this->hotFeedName = $hotFeedName;
}
public function getBannersByType($typeID) {
$banners = array();
foreach($this->banners as $key => $banner) {
if($banner->getTypeID() == $typeID) {
$banners[] = $banner;
}
}
usort($banners, function ($firstBanner, $secondBanner) {
if(($firstID = $firstBanner->getID()) == ($secondID = $secondBanner->getID())) {
return 0;
}
return $firstID < $secondID ? 1 : -1;
});
return $banners;
}
public function getCountActiveBannersByType($typeID) {
$count = 0;
foreach($this->banners as $banner) {
if($banner->getTypeID() == $typeID and $banner->isActive()) {
$count++;
}
}
return $count;
}
public function getActiveBannersByType($typeID) {
$banners = array();
foreach($this->banners as $key => $banner) {
if($banner->getTypeID() == $typeID && $banner->isActive()) {
$banners[] = $banner;
}
}
usort($banners, function ($firstBanner, $secondBanner) {
if(($firstID = $firstBanner->getID()) == ($secondID = $secondBanner->getID())) {
return 0;
}
return $firstID < $secondID ? 1 : -1;
});
return $banners;
}
public function addBanner(Banner $banner) {
if (!$this->banners->contains($banner)) {
$this->banners->add($banner);
}
}
public function deleteBanner($banner) {
$this->banners->removeElement($banner);
}
public function getMobileApiHash() {
return $this->mobileApiHash;
}
public function setMobileApiHash($mobileApiHash) {
$this->mobileApiHash = $mobileApiHash;
}
public function getSales() {
return $this->sales;
}
public function addSale(Sale $sale) {
if (!$this->sales->contains($sale)) {
$this->sales->add($sale);
}
}
public function removeSale(Sale $sale) {
if ($this->sales->contains($sale)) {
$this->sales->removeElement($sale);
}
}
public function clearSales() {
$this->sales = new ArrayCollection();
}
public function isInMenuBottom() {
return $this->inMenuBottom;
}
public function setInMenuBottom($inMenuBottom) {
$this->inMenuBottom = $inMenuBottom;
}
public function getTopParentCategory() {
if ($this->parents->count() == 0) {
return $this;
}
foreach ($this->parents as $category) {
if ($category->isActive() && !$category->isPast() && $category->getTypeID() != Category::SUPPLIER_CATEGORY_TYPE && !in_array($category->getID(), Category::PSEUDO_CATEGORY_LIST)) {
return $category->getTopParentCategory();
}
}
}
public function isUnpopular() {
return $this->unpopular;
}
public function setUnpopular($unpopular) {
$this->unpopular = $unpopular;
}
public function isFeaturedInMenu() {
return $this->featuredInMenu;
}
public function setFeaturedInMenu($featuredInMenu) {
$this->featuredInMenu = $featuredInMenu;
}
public function getPosition() {
return $this->position;
}
public function setPosition($position) {
$this->position = $position;
}
public function getType() {
return self::DEFAULT_CATEGORY_TYPE;
}
public function isTelegramBotShow() {
return $this->telegramBotShow;
}
public function setTelegramBotShow($telegramBotShow) {
$this->telegramBotShow = $telegramBotShow;
}
public function getTelegramBotName() {
return $this->telegramBotName;
}
public function setTelegramBotName($telegramBotName) {
$this->telegramBotName = $telegramBotName;
}
public function getTelegramBotPosition() {
return $this->telegramBotPosition;
}
public function setTelegramBotPosition($telegramBotPosition) {
$this->telegramBotPosition = $telegramBotPosition;
}
public function getUtmCampaign() {
return $this->utmCampaign;
}
public function setUtmCampaign($utmCampaign) {
$this->utmCampaign = $utmCampaign;
}
public function isMeOnMapActive(): bool
{
return $this->meOnMapActive;
}
public function activateMeOnMap(): void
{
$this->meOnMapActive = true;
$this->meOnMapPosition = self::DEFAULT_ME_ON_MAP_POSITION;
}
public function deactivateMeOnMap(): void
{
$this->meOnMapActive = false;
$this->meOnMapPosition = null;
}
public function getMeOnMapPosition(): int
{
return $this->meOnMapPosition ?? self::DEFAULT_ME_ON_MAP_POSITION;
}
public function editMeOnMapPosition(int $meOnMapPosition): void
{
$this->meOnMapPosition = $meOnMapPosition;
}
public function isMeOnMapFeaturedActive(): bool
{
return $this->meOnMapFeaturedActive;
}
public function activateMeOnMapFeatured(): void
{
$this->meOnMapFeaturedActive = true;
$this->meOnMapFeaturedPosition = self::DEFAULT_ME_ON_MAP_POSITION;
}
public function deactivateMeOnMapFeatured(): void
{
$this->meOnMapFeaturedActive = false;
$this->meOnMapFeaturedPosition = null;
}
public function getMeOnMapFeaturedPosition(): int
{
return $this->meOnMapFeaturedPosition ?? self::DEFAULT_ME_ON_MAP_POSITION;
}
public function editMeOnMapFeaturedPosition(int $meOnMapFeaturedPosition): void
{
$this->meOnMapFeaturedPosition = $meOnMapFeaturedPosition;
}
public function getSplitOffersWithSameCategories(): int
{
return $this->splitOffersWithSameCategories;
}
public function setSplitOffersWithSameCategories(int $splitOffersWithSameCategories): void
{
$this->splitOffersWithSameCategories = $splitOffersWithSameCategories;
}
public function activate(): void
{
$this->active = true;
}
public function deactivate(): void
{
$this->active = false;
}
public function updateModifyDate(): void
{
$this->lastModified = new DateTime();
}
public function getShowItemsCatalog(): ?bool
{
return $this->showItemsCatalog;
}
public function setShowItemsCatalog(?bool $shouldShowItemsCatalog): void
{
$this->showItemsCatalog = $shouldShowItemsCatalog;
}
public function isActiveInBestOffersCategory(): bool
{
return $this->activeInBestOffersCategory;
}
public function activateInBestOffersCategory(): void
{
$this->activeInBestOffersCategory = true;
}
public function deactivateInBestOffersCategory(): void
{
$this->activeInBestOffersCategory = false;
}
public function isHideWorkExamples(): bool
{
return $this->hideWorkExamples;
}
public function setHideWorkExamples(bool $hideWorkExamples): void
{
$this->hideWorkExamples = $hideWorkExamples;
}
public function isBonusCode(): bool
{
return $this->isBonusCode;
}
public function setIsBonusCode(bool $isBonusCode): void
{
$this->isBonusCode = $isBonusCode;
}
public function getTarantoolTuple() {
return [
$this->ID,
$this->name,
$this->domainObjectID,
$this->getType(),
$this->entityCount,
$this->city ? $this->city->getID() : City::DEFAULT_CITY_ID,
$this->typeID,
$this->sortOrder,
$this->topCount
];
}
public function jsonSerialize(): array
{
return [
'ID' => $this->ID,
'typeID' => $this->typeID,
'name' => $this->name,
'hotFeedName' => $this->hotFeedName,
'active' => $this->active,
'sortOrder' => $this->sortOrder,
'position' => $this->position,
'categoryType' => $this->categoryType,
'code' => $this->code,
'past' => $this->past,
'topCount' => $this->topCount,
'domainObjectID' => $this->domainObjectID,
'entityCount' => $this->entityCount,
'description' => $this->description,
'inMenuBottom' => $this->inMenuBottom,
'unpopular' => $this->unpopular,
'featuredInMenu' => $this->featuredInMenu,
'telegramBotShow' => $this->telegramBotShow,
'telegramBotName' => $this->telegramBotName,
'utmCampaign' => $this->utmCampaign,
'h1' => $this->h1,
'splitOffersWithSameCategories' => $this->splitOffersWithSameCategories,
'showItemsCatalog' => $this->showItemsCatalog,
'mapPinColor' => $this->mapPinColor,
'hideWorkExamples' => $this->hideWorkExamples,
'isBonusCode' => $this->isBonusCode,
];
}
}