src/Entity/GiftCertificate.php line 10

Open in your IDE?
  1. <?php
  2. namespace Slivki\Entity;
  3. use Doctrine\Common\Collections\ArrayCollection;
  4. use Doctrine\Common\Collections\Collection;
  5. use Slivki\Entity\GiftCertificate\GiftCertificateGroup;
  6. use Slivki\Entity\Media\GiftCertificateMedia;
  7. class GiftCertificate extends Entity
  8. {
  9.     public const PREVIEW_PATH '/znijki-media/crt-preview/';
  10.     protected $active;
  11.     protected $name;
  12.     protected $priceRegular;
  13.     protected $priceOffer;
  14.     protected $discountPercent;
  15.     protected $description;
  16.     protected $offer;
  17.     protected Collection $media;
  18.     protected $position;
  19.     protected $codesPerItem;
  20.     protected $hidden;
  21.     private bool $buyOnlyCode;
  22.     private bool $special123;
  23.     protected $geoLocations;
  24.     protected $tags;
  25.     protected $activeDays;
  26.     protected $pricePartnerPurchase;
  27.     protected $giftCertificateCodePools;
  28.     protected $codeSuffix;
  29.     protected Collection $categories;
  30.     protected Collection $giftCategories;
  31.     protected Collection $groups;
  32.     private ?int $bundlePromoCount;
  33.     protected int $purchaseCount;
  34.     protected ?int $positionBeauty;
  35.     private ?int $multiUseCodePeriod;
  36.     private ?int $multiUseCodePerPeriod;
  37.     private bool $isSubscription;
  38.     public function __construct()
  39.     {
  40.         $this->tags = new ArrayCollection();
  41.         $this->geoLocations = new ArrayCollection();
  42.         $this->giftCertificateCodePools = new ArrayCollection();
  43.         $this->categories = new ArrayCollection();
  44.         $this->giftCategories = new ArrayCollection();
  45.         $this->groups = new ArrayCollection();
  46.         $this->media = new ArrayCollection();
  47.         $this->buyOnlyCode false;
  48.         $this->purchaseCount 0;
  49.     }
  50.     public function isActive()
  51.     {
  52.         return $this->active;
  53.     }
  54.     public function setActive($active) {
  55.         $this->active $active;
  56.     }
  57.     public function getName() {
  58.         return $this->name;
  59.     }
  60.     public function setName($name) {
  61.         $this->name $name;
  62.     }
  63.     public function getPriceRegular() {
  64.         return $this->priceRegular;
  65.     }
  66.     public function setPriceRegular($priceRegular) {
  67.         $this->priceRegular $priceRegular;
  68.     }
  69.     public function getPriceOffer() {
  70.         return $this->priceOffer;
  71.     }
  72.     public function setPriceOffer($priceOffer) {
  73.         $this->priceOffer $priceOffer;
  74.     }
  75.     public function getDiscountPercent() {
  76.         return $this->discountPercent;
  77.     }
  78.     public function setDiscountPercent($dicountPercent) {
  79.         $this->discountPercent $dicountPercent;
  80.     }
  81.     public function getDescription() {
  82.         return $this->description;
  83.     }
  84.     public function setDescription($description) {
  85.         $this->description $description;
  86.     }
  87.     /**
  88.      * @return Offer
  89.      */
  90.     public function getOffer()
  91.     {
  92.         return $this->offer;
  93.     }
  94.     public function setOffer(Offer $offer) {
  95.         $this->offer $offer;
  96.     }
  97.     public function getMedia(): ?GiftCertificateMedia
  98.     {
  99.         return $this->media->count() > $this->media->first() : null;
  100.     }
  101.     public function setMedia(GiftCertificateMedia $media): void
  102.     {
  103.         $media->setGiftCertificate($this);
  104.         $this->media = new ArrayCollection([$media]);
  105.     }
  106.     public function getCurrentPrice() {
  107.         return $this->priceOffer;
  108.     }
  109.     public function getPrice() {
  110.         return $this->priceRegular;
  111.     }
  112.     public function getPriceByTime() {
  113.         return '[[0,0,"' $this->priceOffer '"]]';
  114.     }
  115.     public function getPosition() {
  116.         return $this->position;
  117.     }
  118.     public function setPosition($position) {
  119.         $this->position $position;
  120.     }
  121.     public function getCodesPerItem() {
  122.         return $this->codesPerItem;
  123.     }
  124.     public function setCodesPerItem($codesPerItem) {
  125.         $this->codesPerItem $codesPerItem;
  126.     }
  127.     public function isHidden() {
  128.         return $this->hidden;
  129.     }
  130.     public function setHidden($hidden) {
  131.         $this->hidden $hidden;
  132.     }
  133.     public function isBuyOnlyCode(): bool
  134.     {
  135.         return $this->buyOnlyCode;
  136.     }
  137.     public function setBuyOnlyCode(bool $buyOnlyCode): void
  138.     {
  139.         $this->buyOnlyCode $buyOnlyCode;
  140.     }
  141.     public function isSpecial123(): bool
  142.     {
  143.         return $this->special123;
  144.     }
  145.     public function setSpecial123(bool $special123): void
  146.     {
  147.         $this->special123 $special123;
  148.     }
  149.     public function getGeoLocations() {
  150.         return $this->geoLocations;
  151.     }
  152.     public function addGeoLocation(GeoLocation $geoLocation) {
  153.         if (!$this->geoLocations->contains($geoLocation)) {
  154.             $this->geoLocations->add($geoLocation);
  155.         }
  156.     }
  157.     public function removeGeoLocation(GeoLocation $geoLocation) {
  158.         $this->geoLocations->removeElement($geoLocation);
  159.     }
  160.     /**
  161.      * @return ArrayCollection
  162.      */
  163.     public function getTags() {
  164.         return $this->tags;
  165.     }
  166.     public function addTag(GiftCertificateTag $tag) {
  167.         if (!$this->tags->contains($tag)) {
  168.             $tag->addGiftCertificates($this);
  169.             $this->tags->add($tag);
  170.         }
  171.     }
  172.     public function deleteTag(GiftCertificateTag $tag) {
  173.         $this->tags->removeElement($tag);
  174.     }
  175.     public function getActiveDays() {
  176.         return $this->activeDays;
  177.     }
  178.     public function setActiveDays($activeDays) {
  179.         $this->activeDays $activeDays;
  180.     }
  181.     public function getPricePartnerPurchase() {
  182.         return $this->pricePartnerPurchase;
  183.     }
  184.     public function setPricePartnerPurchase($pricePartnerPurchase) {
  185.         $this->pricePartnerPurchase $pricePartnerPurchase;
  186.     }
  187.     public function getGiftCertificateCodePools() {
  188.         return $this->giftCertificateCodePools;
  189.     }
  190.     public function setGiftCertificateCodePools(ArrayCollection $giftCertificateCodePools) {
  191.         $this->giftCertificateCodePools $giftCertificateCodePools;
  192.     }
  193.     /** @return bool|GiftCertificateCodePool */
  194.     public function getLastActiveCodePool() {
  195.         /** @var \Slivki\Entity\GiftCertificateCodePool $giftCertificateCodePool */
  196.         foreach ($this->giftCertificateCodePools as $giftCertificateCodePool) {
  197.             if ($giftCertificateCodePool->isActive()) {
  198.                 return $giftCertificateCodePool;
  199.             }
  200.         }
  201.         return false;
  202.     }
  203.     public function getCodeSuffix() {
  204.         return $this->codeSuffix;
  205.     }
  206.     public function setCodeSuffix($codeSuffix) {
  207.         $this->codeSuffix $codeSuffix;
  208.     }
  209.     public function getCategories(): Collection
  210.     {
  211.         return $this->categories;
  212.     }
  213.     public function addCategory(GiftCertificateCategory $category): void
  214.     {
  215.         if (!$this->categories->contains($category)) {
  216.             $this->categories->add($category);
  217.         }
  218.     }
  219.     public function removeCategory(GiftCertificateCategory $category):void
  220.     {
  221.         $this->categories->removeElement($category);
  222.     }
  223.     public function getGiftCategories(): Collection
  224.     {
  225.         return $this->giftCategories;
  226.     }
  227.     public function addGiftCategory(GiftCertificateGiftCategory $category): void
  228.     {
  229.         if (!$this->giftCategories->contains($category)) {
  230.             $this->giftCategories->add($category);
  231.         }
  232.     }
  233.     public function removeGiftCategory(GiftCertificateGiftCategory $category):void
  234.     {
  235.         $this->giftCategories->removeElement($category);
  236.     }
  237.     /**
  238.      * @return Collection<GiftCertificateGroup>
  239.      */
  240.     public function getGroups(): Collection
  241.     {
  242.         return $this->groups;
  243.     }
  244.     public function addGroup(GiftCertificateGroup $group): void
  245.     {
  246.         if (!$this->groups->contains($group)) {
  247.             $this->groups->add($group);
  248.         }
  249.     }
  250.     public function removeGroup(GiftCertificateGroup $group):void
  251.     {
  252.         $this->groups->removeElement($group);
  253.     }
  254.     public function getBundlePromoCount(): ?int
  255.     {
  256.         return $this->bundlePromoCount;
  257.     }
  258.     public function setBundlePromoCount(?int $bundlePromoCount): void
  259.     {
  260.         $this->bundlePromoCount $bundlePromoCount;
  261.     }
  262.     public function getPurchaseCount(): int
  263.     {
  264.         return $this->purchaseCount;
  265.     }
  266.     public function getPositionBeauty(): ?int
  267.     {
  268.         return $this->positionBeauty;
  269.     }
  270.     public function editPositionBeauty(int $positionBeauty): void
  271.     {
  272.         $this->positionBeauty $positionBeauty;
  273.     }
  274.     public function getMultiUseCodePeriod(): ?int
  275.     {
  276.         return $this->multiUseCodePeriod;
  277.     }
  278.     public function setMultiUseCodePeriod(?int $multiUseCodePeriod): void
  279.     {
  280.         $this->multiUseCodePeriod $multiUseCodePeriod;
  281.     }
  282.     public function getMultiUseCodePerPeriod(): ?int
  283.     {
  284.         return $this->multiUseCodePerPeriod;
  285.     }
  286.     public function setMultiUseCodePerPeriod(?int $multiUseCodePerPeriod): void
  287.     {
  288.         $this->multiUseCodePerPeriod $multiUseCodePerPeriod;
  289.     }
  290.     public function isMultiUseCode(): bool
  291.     {
  292.         return $this->multiUseCodePeriod && $this->multiUseCodePerPeriod 0;
  293.     }
  294.     public function isSubscription(): bool
  295.     {
  296.         return $this->isSubscription;
  297.     }
  298.     public function setIsSubscription(bool $isSubscription): void
  299.     {
  300.         $this->isSubscription $isSubscription;
  301.     }
  302. }