<?php
namespace Slivki\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Slivki\Entity\GiftCertificate\GiftCertificateGroup;
use Slivki\Entity\Media\GiftCertificateMedia;
class GiftCertificate extends Entity
{
public const PREVIEW_PATH = '/znijki-media/crt-preview/';
protected $active;
protected $name;
protected $priceRegular;
protected $priceOffer;
protected $discountPercent;
protected $description;
protected $offer;
protected Collection $media;
protected $position;
protected $codesPerItem;
protected $hidden;
private bool $buyOnlyCode;
private bool $special123;
protected $geoLocations;
protected $tags;
protected $activeDays;
protected $pricePartnerPurchase;
protected $giftCertificateCodePools;
protected $codeSuffix;
protected Collection $categories;
protected Collection $giftCategories;
protected Collection $groups;
private ?int $bundlePromoCount;
protected int $purchaseCount;
protected ?int $positionBeauty;
private ?int $multiUseCodePeriod;
private ?int $multiUseCodePerPeriod;
private bool $isSubscription;
public function __construct()
{
$this->tags = new ArrayCollection();
$this->geoLocations = new ArrayCollection();
$this->giftCertificateCodePools = new ArrayCollection();
$this->categories = new ArrayCollection();
$this->giftCategories = new ArrayCollection();
$this->groups = new ArrayCollection();
$this->media = new ArrayCollection();
$this->buyOnlyCode = false;
$this->purchaseCount = 0;
}
public function isActive()
{
return $this->active;
}
public function setActive($active) {
$this->active = $active;
}
public function getName() {
return $this->name;
}
public function setName($name) {
$this->name = $name;
}
public function getPriceRegular() {
return $this->priceRegular;
}
public function setPriceRegular($priceRegular) {
$this->priceRegular = $priceRegular;
}
public function getPriceOffer() {
return $this->priceOffer;
}
public function setPriceOffer($priceOffer) {
$this->priceOffer = $priceOffer;
}
public function getDiscountPercent() {
return $this->discountPercent;
}
public function setDiscountPercent($dicountPercent) {
$this->discountPercent = $dicountPercent;
}
public function getDescription() {
return $this->description;
}
public function setDescription($description) {
$this->description = $description;
}
/**
* @return Offer
*/
public function getOffer()
{
return $this->offer;
}
public function setOffer(Offer $offer) {
$this->offer = $offer;
}
public function getMedia(): ?GiftCertificateMedia
{
return $this->media->count() > 0 ? $this->media->first() : null;
}
public function setMedia(GiftCertificateMedia $media): void
{
$media->setGiftCertificate($this);
$this->media = new ArrayCollection([$media]);
}
public function getCurrentPrice() {
return $this->priceOffer;
}
public function getPrice() {
return $this->priceRegular;
}
public function getPriceByTime() {
return '[[0,0,"' . $this->priceOffer . '"]]';
}
public function getPosition() {
return $this->position;
}
public function setPosition($position) {
$this->position = $position;
}
public function getCodesPerItem() {
return $this->codesPerItem;
}
public function setCodesPerItem($codesPerItem) {
$this->codesPerItem = $codesPerItem;
}
public function isHidden() {
return $this->hidden;
}
public function setHidden($hidden) {
$this->hidden = $hidden;
}
public function isBuyOnlyCode(): bool
{
return $this->buyOnlyCode;
}
public function setBuyOnlyCode(bool $buyOnlyCode): void
{
$this->buyOnlyCode = $buyOnlyCode;
}
public function isSpecial123(): bool
{
return $this->special123;
}
public function setSpecial123(bool $special123): void
{
$this->special123 = $special123;
}
public function getGeoLocations() {
return $this->geoLocations;
}
public function addGeoLocation(GeoLocation $geoLocation) {
if (!$this->geoLocations->contains($geoLocation)) {
$this->geoLocations->add($geoLocation);
}
}
public function removeGeoLocation(GeoLocation $geoLocation) {
$this->geoLocations->removeElement($geoLocation);
}
/**
* @return ArrayCollection
*/
public function getTags() {
return $this->tags;
}
public function addTag(GiftCertificateTag $tag) {
if (!$this->tags->contains($tag)) {
$tag->addGiftCertificates($this);
$this->tags->add($tag);
}
}
public function deleteTag(GiftCertificateTag $tag) {
$this->tags->removeElement($tag);
}
public function getActiveDays() {
return $this->activeDays;
}
public function setActiveDays($activeDays) {
$this->activeDays = $activeDays;
}
public function getPricePartnerPurchase() {
return $this->pricePartnerPurchase;
}
public function setPricePartnerPurchase($pricePartnerPurchase) {
$this->pricePartnerPurchase = $pricePartnerPurchase;
}
public function getGiftCertificateCodePools() {
return $this->giftCertificateCodePools;
}
public function setGiftCertificateCodePools(ArrayCollection $giftCertificateCodePools) {
$this->giftCertificateCodePools = $giftCertificateCodePools;
}
/** @return bool|GiftCertificateCodePool */
public function getLastActiveCodePool() {
/** @var \Slivki\Entity\GiftCertificateCodePool $giftCertificateCodePool */
foreach ($this->giftCertificateCodePools as $giftCertificateCodePool) {
if ($giftCertificateCodePool->isActive()) {
return $giftCertificateCodePool;
}
}
return false;
}
public function getCodeSuffix() {
return $this->codeSuffix;
}
public function setCodeSuffix($codeSuffix) {
$this->codeSuffix = $codeSuffix;
}
public function getCategories(): Collection
{
return $this->categories;
}
public function addCategory(GiftCertificateCategory $category): void
{
if (!$this->categories->contains($category)) {
$this->categories->add($category);
}
}
public function removeCategory(GiftCertificateCategory $category):void
{
$this->categories->removeElement($category);
}
public function getGiftCategories(): Collection
{
return $this->giftCategories;
}
public function addGiftCategory(GiftCertificateGiftCategory $category): void
{
if (!$this->giftCategories->contains($category)) {
$this->giftCategories->add($category);
}
}
public function removeGiftCategory(GiftCertificateGiftCategory $category):void
{
$this->giftCategories->removeElement($category);
}
/**
* @return Collection<GiftCertificateGroup>
*/
public function getGroups(): Collection
{
return $this->groups;
}
public function addGroup(GiftCertificateGroup $group): void
{
if (!$this->groups->contains($group)) {
$this->groups->add($group);
}
}
public function removeGroup(GiftCertificateGroup $group):void
{
$this->groups->removeElement($group);
}
public function getBundlePromoCount(): ?int
{
return $this->bundlePromoCount;
}
public function setBundlePromoCount(?int $bundlePromoCount): void
{
$this->bundlePromoCount = $bundlePromoCount;
}
public function getPurchaseCount(): int
{
return $this->purchaseCount;
}
public function getPositionBeauty(): ?int
{
return $this->positionBeauty;
}
public function editPositionBeauty(int $positionBeauty): void
{
$this->positionBeauty = $positionBeauty;
}
public function getMultiUseCodePeriod(): ?int
{
return $this->multiUseCodePeriod;
}
public function setMultiUseCodePeriod(?int $multiUseCodePeriod): void
{
$this->multiUseCodePeriod = $multiUseCodePeriod;
}
public function getMultiUseCodePerPeriod(): ?int
{
return $this->multiUseCodePerPeriod;
}
public function setMultiUseCodePerPeriod(?int $multiUseCodePerPeriod): void
{
$this->multiUseCodePerPeriod = $multiUseCodePerPeriod;
}
public function isMultiUseCode(): bool
{
return $this->multiUseCodePeriod > 0 && $this->multiUseCodePerPeriod > 0;
}
public function isSubscription(): bool
{
return $this->isSubscription;
}
public function setIsSubscription(bool $isSubscription): void
{
$this->isSubscription = $isSubscription;
}
}