<?php
namespace Bidcoz\Bundle\CoreBundle\Entity\Auction;
use Bidcoz\Bundle\CoreBundle\Entity\Contact\Company;
use Bidcoz\Bundle\CoreBundle\Entity\Email\Email;
use Bidcoz\Bundle\CoreBundle\Entity\Email\ItemTemplate;
use Bidcoz\Bundle\CoreBundle\Entity\Purchase\BuyItNowItemPurchase;
use Bidcoz\Bundle\CoreBundle\Entity\Purchase\ItemPurchase;
use Bidcoz\Bundle\CoreBundle\Entity\Purchase\Purchase;
use Bidcoz\Bundle\CoreBundle\Entity\User;
use Bidcoz\Bundle\CoreBundle\ObjectChange\ObjectChangeTrackable;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use JMS\Serializer\Annotation as Serialize;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\Validator\Context\ExecutionContextInterface;
/**
* @ORM\Entity(repositoryClass="ItemRepository")
* @ORM\Table(
* name="auction_items",
* uniqueConstraints={
* @ORM\UniqueConstraint(name="number_uniq", columns={"auction_id", "item_number"})
* }
* )
* @Serialize\ExclusionPolicy("all")
* @ORM\EntityListeners({"\Bidcoz\Bundle\CoreBundle\EntityListener\AuctionItemListener"})
*
* @UniqueEntity(
* fields={"auction", "number"},
* errorPath="number",
* message="Item number must be unique", groups={"edit"}
* )
*/
class Item implements ObjectChangeTrackable
{
/**
* @ORM\Id
* @ORM\Column(name="id", type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
* @Serialize\Expose
*/
protected $id;
/**
* @ORM\Column(name="item_number", type="string")
* @Serialize\Expose
*/
protected $number;
/**
* @ORM\ManyToOne(targetEntity="Auction", inversedBy="items")
* @ORM\JoinColumn(name="auction_id", referencedColumnName="id", onDelete="CASCADE")
*/
protected ?Auction $auction = null;
/**
* @ORM\Column(name="name", type="text")
* @Assert\NotBlank(message="Name is required", groups={"Default", "donation"})
* @Serialize\Expose
*/
protected $name;
/**
* @ORM\Column(name="description", type="text")
* @Assert\NotBlank(message="Description is required", groups={"Default", "donation"})
*/
protected $description;
/**
* @ORM\Column(name="short_description", type="string", length=50, nullable=true)
* @Assert\Length(max=50, maxMessage="Short Description limited to 50 chars.")
*/
protected $shortDescription;
/**
* @ORM\ManyToOne(targetEntity="ItemCategory", inversedBy="items", cascade={"persist"})
* @Serialize\Expose
*/
protected ?ItemCategory $category = null;
/**
* @ORM\ManyToOne(targetEntity="ItemType", inversedBy="items")
* @Serialize\Expose
*/
protected ?ItemType $type = null;
/**
* @ORM\ManyToOne(targetEntity="ItemSaleType", inversedBy="items")
* @ORM\JoinColumn(name="sale_type_id", referencedColumnName="id")
* @Serialize\Expose
*/
protected ?ItemSaleType $saleType = null;
/**
* @ORM\ManyToOne(targetEntity="ItemCondition", inversedBy="items")
* @Serialize\Expose
*/
protected ?ItemCondition $condition = null;
/**
* @ORM\ManyToOne(targetEntity="AuctionVenue")
* @Assert\NotBlank(message="Venue is required")
* @Serialize\Expose
*/
protected ?AuctionVenue $venue = null;
/**
* @ORM\Column(name="min_bid", type="decimal", scale=2, precision=10, nullable=true)
* @Assert\Range(min=0)
* @Serialize\Expose
*/
protected $minBid;
/**
* @ORM\Column(name="reserve_price", type="decimal", scale=2, precision=10, nullable=true)
* @Assert\Range(min=0)
* @Serialize\Expose
*/
protected $reservePrice;
/**
* @ORM\Column(name="buy_it_now_price", type="decimal", scale=2, precision=10, nullable=true)
* @Assert\Range(min=0)
* @Serialize\Expose
*/
protected $buyItNowPrice;
/**
* @ORM\Column(name="bid_increment", type="decimal", scale=2, precision=10, nullable=true)
* @Assert\Range(min=0)
* @Serialize\Expose
*/
protected $bidIncrement;
/**
* @ORM\Column(name="tax_deduct_amount", type="decimal", scale=2, precision=10, nullable=false)
* @Assert\Range(min=0)
* @Serialize\Expose
*/
protected $taxDeductibleAmount = 0;
/**
* @ORM\Column(name="est_value", type="decimal", scale=2, precision=10, nullable=true)
* @Assert\Range(min=0, groups={"Default", "donation"})
* @Serialize\Expose
*/
protected $estimatedValue;
/**
* @ORM\Column(name="est_value_display", type="boolean")
*/
protected $estimatedValueDisplay = false;
/**
* @ORM\Column(name="begin_quantity", type="integer", nullable=true)
* @Assert\Range(min=0)
*/
protected $beginQuantity = 1;
/**
* @ORM\Column(name="current_quantity", type="integer", nullable=true)
* @Assert\Range(min=0)
* @Serialize\Expose
*/
protected $currentQuantity = 1;
/**
* @ORM\Column(name="overtime_bidding_extended", type="boolean");
*/
protected $overtimeBiddingExtended = false;
/**
* @ORM\Column(name="featured", type="boolean")
*/
protected $featured = false;
/**
* @ORM\ManyToOne(targetEntity="Bidcoz\Bundle\CoreBundle\Entity\User")
* @ORM\JoinColumn(name="user_id", referencedColumnName="id")
* @Serialize\Expose
*/
protected ?User $donor = null;
/**
* @ORM\ManyToOne(targetEntity="Bidcoz\Bundle\CoreBundle\Entity\Contact\Company")
* @ORM\JoinColumn(name="company_id", referencedColumnName="id", onDelete="SET NULL")
* @Serialize\Expose
*/
protected ?Company $company = null;
/**
* @ORM\Column(name="donor_anonymous", type="boolean")
*/
protected $donorAnonymous = false;
/**
* @ORM\Column(name="pickup_instructions", type="text", nullable=true)
* @Serialize\Expose
* @Serialize\Accessor(getter="getPickupInstructions")
*/
protected $pickupInstructions;
/**
* @var ItemImage[]|Collection|null
* @ORM\OneToMany(targetEntity="ItemImage", mappedBy="item", orphanRemoval=true, cascade={"persist"})
* @Serialize\Expose
*/
protected ?Collection $images = null;
/**
* @ORM\Column(name="bid_begin", type="datetime", nullable=true)
* @Serialize\Expose
*/
protected $itemBidBegin;
/**
* @ORM\Column(name="bid_end", type="datetime", nullable=true)
* @Serialize\Expose
*/
protected $itemBidEnd;
/**
* @var Bid[]|Collection|null
* @ORM\OneToMany(targetEntity="Bid", mappedBy="item", cascade={"persist"})
*/
protected ?Collection $bids = null;
/**
* @var WatchListItem[]|Collection|null
* @ORM\OneToMany(targetEntity="WatchListItem", mappedBy="item", cascade={"persist"})
*/
protected ?Collection $watchList = null;
/**
* @ORM\OneToOne(targetEntity="Bid", cascade={"persist"})
* @ORM\JoinColumn(name="winning_bid_id", referencedColumnName="id", onDelete="SET NULL")
* @Serialize\Expose
*/
protected ?Bid $winningBid = null;
/**
* @ORM\OneToOne(targetEntity="Bidcoz\Bundle\CoreBundle\Entity\Purchase\ItemPurchase", mappedBy="item", cascade={"persist", "remove"})
*/
protected ?ItemPurchase $purchase = null;
/**
* @var ItemPurchase[]|Collection|null
* @ORM\OneToMany(targetEntity="Bidcoz\Bundle\CoreBundle\Entity\Purchase\ItemPurchase", mappedBy="item", cascade={"persist", "remove"})
*/
protected ?Collection $purchases = null;
/**
* @ORM\Column(name="active", type="boolean")
*/
protected $active = true;
/**
* @ORM\OneToOne(targetEntity="Bidcoz\Bundle\CoreBundle\Entity\Email\Email", cascade={"persist"})
* @ORM\JoinColumn(name="donor_receipt_email_id", referencedColumnName="id")
*/
protected ?Email $donorReceiptEmail = null;
/**
* @var Item[]|Collection|null
* @ORM\OneToMany(targetEntity="Item", mappedBy="parentItem", cascade={"persist"})
* @Serialize\Expose
*/
protected ?Collection $packagedItems = null;
/**
* @ORM\ManyToOne(targetEntity="Item", inversedBy="packagedItems")
* @ORM\JoinColumn(name="item_package_id", referencedColumnName="id")
* @Serialize\Expose
*/
protected ?Item $parentItem = null;
/**
* @ORM\OneToMany(targetEntity="Bidcoz\Bundle\CoreBundle\Entity\Ticket\TicketType", mappedBy="includeItem")
*/
protected $includedWithTicketTypes;
/**
* @ORM\OneToMany(targetEntity="Bidcoz\Bundle\CoreBundle\Entity\Registration\RegistrationType", mappedBy="includeItem")
*/
protected $includedWithRegistrationTypes;
/**
* @ORM\Column(name="question_text", type="string", length=255, nullable=true)
* @Assert\Length(max=255, maxMessage="Question Text limited to 255 chars.")
*/
protected $questionText;
/**
* @ORM\Column(name="question_required", type="boolean")
*/
protected $questionRequired = false;
/**
* @ORM\Column(name="collect_email", type="boolean")
*/
protected $collectEmail = false;
/**
* @ORM\ManyToOne(targetEntity="Bidcoz\Bundle\CoreBundle\Entity\Email\ItemTemplate", inversedBy="items")
* @ORM\JoinColumn(name="template_id", referencedColumnName="id")
*/
protected ?ItemTemplate $template = null;
/**
* @ORM\Column(name="sort_order", type="integer")
* @Assert\NotNull
*/
protected $sortOrder = 0;
/**
* @ORM\Column(name="created_at", type="datetime")
* @Serialize\Expose
*/
protected $createdAt;
/**
* @ORM\Column(name="show_purchasers", type="boolean")
*/
protected $showPurchasers = false;
public function __construct(Auction $auction = null)
{
$this->auction = $auction;
$this->images = new ArrayCollection();
$this->bids = new ArrayCollection();
$this->watchList = new ArrayCollection();
$this->packagedItems = new ArrayCollection();
$this->purchases = new ArrayCollection();
$this->createdAt = new \DateTime();
}
public function cloneItem()
{
$newItem = clone $this;
$newItem->id = null;
$newItem->number = null;
$newItem->auction = null;
$newItem->winningBid = null;
$newItem->purchase = null;
$newItem->images = new ArrayCollection();
$newItem->bids = new ArrayCollection();
$newItem->watchList = new ArrayCollection();
$newItem->purchases = new ArrayCollection();
$newItem->createdAt = new \DateTime();
$newItem->itemBidBegin = null;
$newItem->itemBidEnd = null;
$newItem->pickupInstructions = null;
$newItem->donorReceiptEmail = null;
$newItem->packagedItems = new ArrayCollection();
return $newItem;
}
public function setId($id)
{
$this->id = $id;
}
public function getId()
{
return $this->id;
}
public function setNumber($number)
{
$this->number = $number;
}
public function getNumber()
{
return $this->number ?: '';
}
public function resetNumber()
{
$this->number = null;
}
public function setName($name)
{
$this->name = $name;
}
public function getName()
{
return $this->name;
}
public function setDescription($description)
{
$this->description = $description;
}
public function getDescription()
{
return $this->description;
}
public function setShortDescription(string $shortDescription = null)
{
$this->shortDescription = $shortDescription;
}
/**
* @Serialize\VirtualProperty
* @Serialize\SerializedName("description")
*/
public function getShortDescription()
{
return $this->shortDescription;
}
public function setMinBid($minBid)
{
$this->minBid = $minBid;
}
public function getMinBid()
{
return $this->minBid;
}
public function setReservePrice($reservePrice)
{
$this->reservePrice = $reservePrice;
}
public function getReservePrice()
{
return $this->reservePrice;
}
public function setType(?ItemType $type): void
{
$this->type = $type;
}
public function getType(): ?ItemType
{
return $this->type;
}
public function setVenue(?AuctionVenue $venue): void
{
$this->venue = $venue;
}
public function getVenue(): ?AuctionVenue
{
return $this->venue;
}
public function isOnline()
{
return $this->venue && AuctionVenue::ONLINE === $this->venue->getId();
}
public function isOnsite()
{
return $this->venue && AuctionVenue::ONSITE === $this->venue->getId();
}
public function isOnlineAndOnsite()
{
return null == $this->venue;
}
public function setSaleType(?ItemSaleType $saleType): void
{
$this->saleType = $saleType;
}
public function getSaleType(): ?ItemSaleType
{
return $this->saleType;
}
public function isDonation()
{
return $this->saleType && ItemSaleType::DONATION == $this->saleType->getId();
}
public function isAuctionType()
{
return $this->saleType && ItemSaleType::AUCTION == $this->saleType->getId();
}
public function isFixedPrice()
{
return $this->saleType && ItemSaleType::FIXED_PRICE == $this->saleType->getId();
}
public function isManualType()
{
return $this->saleType && ItemSaleType::MANUAL == $this->saleType->getId();
}
public function isConsignmentType()
{
return $this->type && ItemType::CONSIGNMENT == $this->type->getId();
}
public function isPackagedItem()
{
return (bool) $this->parentItem;
}
public function setParentItem(Item $parentItem = null)
{
$this->parentItem = $parentItem;
}
public function getParentItem()
{
return $this->parentItem;
}
public function setTaxDeductibleAmount($taxDeductibleAmount)
{
$this->taxDeductibleAmount = $taxDeductibleAmount;
}
public function getTaxDeductibleAmount()
{
return $this->taxDeductibleAmount;
}
public function setEstimatedValue($estimatedValue)
{
$this->estimatedValue = $estimatedValue;
}
public function getEstimatedValue($calculate = false)
{
if ($calculate) {
$qty = $this->isFixedPrice()
? $this->beginQuantity
: 1;
return round($this->estimatedValue / $qty, 2);
} else {
return $this->estimatedValue;
}
}
public function setEstimatedValueDisplay($estimatedValueDisplay)
{
$this->estimatedValueDisplay = $estimatedValueDisplay;
}
public function getEstimatedValueDisplay()
{
return $this->estimatedValueDisplay;
}
public function showEstimatedDisplay()
{
return $this->estimatedValueDisplay && $this->estimatedValue;
}
/**
* @Serialize\VirtualProperty
* @Serialize\SerializedName("estValue")
*/
public function getEstimatedValueString(): string
{
if (!$this->getEstimatedValue()) {
return '';
}
return $this->showEstimatedDisplay()
? 'Priceless'
: '$'.money_format('%i', $this->getEstimatedValue());
}
public function setBeginQuantity($beginQuantity)
{
$this->beginQuantity = $beginQuantity;
}
public function getBeginQuantity()
{
return $this->beginQuantity;
}
public function setAuction(?Auction $auction): void
{
$this->auction = $auction;
}
public function getAuction(): ?Auction
{
return $this->auction;
}
public function setCategory(?ItemCategory $category = null): void
{
$this->category = $category;
}
public function getCategory(): ?ItemCategory
{
return $this->category;
}
/**
* @return Collection|ItemImage[]|null
*/
public function getImages(): ?Collection
{
return $this->images;
}
public function addImage(?ItemImage $image): void
{
if (!$this->images->contains($image)) {
$this->images->add($image);
}
}
public function removeImage(?ItemImage $image): void
{
if ($this->images->contains($image)) {
$this->images->removeElement($image);
}
}
public function setPrimaryImage(ItemImage $image): void
{
foreach ($this->images as $i) {
$i->setPrimary(false);
}
$image->setPrimary(true);
}
public function getPrimaryImage()
{
$filtered = $this->getImages()->filter(function ($image) {
return $image->isPrimary();
});
return $filtered->first();
}
public function hasCustomBidDates()
{
return $this->itemBidBegin || $this->itemBidEnd;
}
public function getBidBegin()
{
if ($this->itemBidBegin) {
return $this->itemBidBegin;
}
return $this->isOnsite()
? $this->getAuction()->getOnsiteBegin()
: $this->getAuction()->getOnlineBegin();
}
public function getBidEnd()
{
if ($this->itemBidEnd) {
return $this->itemBidEnd;
}
return $this->isOnsite()
? $this->getAuction()->getOnsiteEnd()
: $this->getAuction()->getOnlineEnd();
}
public function isItemWithinBidTimeframe()
{
$now = new \DateTime();
return $now >= $this->getBidBegin() && $now <= $this->getBidEnd();
}
public function isItemUpcoming()
{
$now = new \DateTime();
return $now <= $this->getBidBegin();
}
public function isItemOver()
{
$now = new \DateTime();
return $now >= $this->getBidEnd();
}
public function setItemBidBegin(\DateTime $date = null)
{
$this->itemBidBegin = $date;
}
public function getItemBidBegin()
{
return $this->itemBidBegin;
}
public function setItemBidEnd(\DateTime $date = null)
{
$this->itemBidEnd = $date;
}
public function getItemBidEnd()
{
return $this->itemBidEnd;
}
public function isWithinOvertimeBiddingWindow()
{
$windowBegin = new \DateTime('+5 minutes');
return $this->getBidEnd() < $windowBegin;
}
/**
* @return Collection|Bid[]|null
*/
public function getBids(): ?Collection
{
return $this->bids;
}
public function setBids(?Collection $bids): void
{
$this->bids = $bids;
}
public function addBid(?Bid $bid): void
{
if (!$this->bids->contains($bid)) {
$this->bids->add($bid);
$bid->setItem($this);
}
}
public function removeBid(?Bid $bid): void
{
if ($this->bids->contains($bid)) {
$this->bids->removeElement($bid);
}
}
public function getActiveBids(): Collection
{
return $this->bids->filter(function (Bid $bid) {
return $bid->isActive();
});
}
public function hasUserBid(User $user)
{
return $this->bids->exists(function ($index, $bid) use ($user) {
return $bid->getUser() == $user && $bid->isActive();
});
}
public function setCurrentQuantity($currentQuantity)
{
$this->currentQuantity = $currentQuantity;
}
public function getCurrentQuantity()
{
return $this->currentQuantity;
}
public function decrementCurrentQuantity()
{
--$this->currentQuantity;
foreach ($this->packagedItems as $item) {
$item->decrementCurrentQuantity();
}
}
public function incrementCurrentQuantity()
{
++$this->currentQuantity;
foreach ($this->packagedItems as $item) {
$item->incrementCurrentQuantity();
}
}
public function setOvertimeBiddingExtended($overtimeBiddingExtended)
{
$this->overtimeBiddingExtended = $overtimeBiddingExtended;
}
public function getOvertimeBiddingExtended()
{
return $this->overtimeBiddingExtended;
}
public function setFeatured($featured)
{
$this->featured = $featured;
}
public function getFeatured()
{
return $this->featured;
}
public function setDonor(?User $donor = null): void
{
$this->donor = $donor;
}
public function getDonor(): ?User
{
return $this->donor;
}
public function setCompany(?Company $company = null): void
{
$this->company = $company;
}
public function getCompany(): ?Company
{
return $this->company;
}
public function setDonorAnonymous($donorAnonymous)
{
$this->donorAnonymous = $donorAnonymous;
}
public function isDonorAnonymous()
{
return $this->donorAnonymous;
}
public function hasCustomPickupInstructions()
{
return $this->pickupInstructions && strlen($this->pickupInstructions);
}
public function setCustomPickupInstructions($pickupInstructions)
{
$this->pickupInstructions = $pickupInstructions;
}
public function getCustomPickupInstructions()
{
return $this->pickupInstructions;
}
public function getPickupInstructions()
{
return $this->pickupInstructions ?: $this->auction->getPickupInstructions();
}
public function setCondition(?ItemCondition $condition): void
{
$this->condition = $condition;
}
public function getCondition(): ?ItemCondition
{
return $this->condition;
}
public function setBuyItNowPrice($buyItNowPrice)
{
$this->buyItNowPrice = $buyItNowPrice;
}
public function getBuyItNowPrice()
{
return $this->buyItNowPrice;
}
public function setFixedPrice($buyItNowPrice)
{
$this->buyItNowPrice = $buyItNowPrice;
}
public function getFixedPrice()
{
return $this->saleType && ItemSaleType::FIXED_PRICE === $this->saleType->getId() ? $this->buyItNowPrice : null;
}
public function setBuyItNowOnlyPrice($buyItNowPrice)
{
$this->buyItNowPrice = $buyItNowPrice;
}
public function getBuyItNowOnlyPrice()
{
return $this->saleType && ItemSaleType::FIXED_PRICE !== $this->saleType->getId() ? $this->buyItNowPrice : null;
}
public function setBidIncrement($bidIncrement)
{
$this->bidIncrement = $bidIncrement;
}
public function getBidIncrement()
{
return $this->bidIncrement;
}
/**
* @return Collection|WatchListItem[]|null
*/
public function getWatchList(): ?Collection
{
return $this->watchList;
}
public function setWatchList(?Collection $watchList): void
{
$this->watchList = $watchList;
}
public function addWatchListItem(WatchListItem $watchListItem): void
{
if (!$this->watchList->contains($watchListItem)) {
$this->watchList->add($watchListItem);
}
}
public function removeWatchListItem(WatchListItem $watchListItem): void
{
if ($this->watchList->contains($watchListItem)) {
$this->watchList->removeElement($watchListItem);
}
}
public function setWinningBid(?Bid $bid = null): void
{
$this->winningBid = $bid;
}
public function getWinningBid(): ?Bid
{
return $this->winningBid;
}
public function isWinningBid(?Bid $bid): bool
{
return $bid == $this->winningBid;
}
public function getCurrentBidAmount()
{
if ($winningBid = $this->getWinningBid()) {
return $winningBid->getAmount();
}
return $this->minBid;
}
public function setPurchase(?ItemPurchase $purchase): void
{
$this->purchase = $purchase;
}
public function getPurchase(): ?ItemPurchase
{
return $this->purchase;
}
public function unsetPurchase()
{
$this->purchase = null;
}
public function isPaidFor(): bool
{
if (!$this->purchase) {
return false;
}
// there is a purchase, if hold in cart return true, else check that there is a transaction
if ($this->getCampaign()->getHoldItemsInCart()) {
return true;
}
return (bool) $this->purchase->getTransaction();
}
public function isBuyItNowPurchase(): bool
{
return (bool) $this->purchase && $this->purchase instanceof BuyItNowItemPurchase;
}
public function setActive($active)
{
$this->active = $active;
}
public function isActive()
{
return $this->active;
}
public function setDonorReceiptEmail(?Email $email): void
{
$this->donorReceiptEmail = $email;
}
public function getDonorReceiptEmail(): ?Email
{
return $this->donorReceiptEmail;
}
public function getPackagedItems(): ?Collection
{
return $this->packagedItems;
}
public function addPackagedItem(Item $item): void
{
if (!$this->packagedItems->contains($item)) {
$this->packagedItems->add($item);
$item->setParentItem($this);
}
}
public function removePackagedItem(Item $item): void
{
if ($this->packagedItems->contains($item)) {
$this->packagedItems->removeElement($item);
$item->setParentItem(null);
}
}
public function getPackagedItemIds(): array
{
return array_map(static fn (Item $item) => $item->getId(), $this->packagedItems->toArray());
}
public function setPackagedItems($items = []): void
{
foreach ($this->packagedItems as $before) {
$before->setParentItem(null);
}
$this->packagedItems = new ArrayCollection();
foreach ($items as $after) {
$after->setParentItem($this);
$this->packagedItems->add($after);
}
}
public function hasPackagedItems(): bool
{
return (bool) count($this->packagedItems);
}
public function getCreatedAt()
{
return $this->createdAt;
}
public function setShowPurchasers($showPurchasers)
{
$this->showPurchasers = $showPurchasers;
}
public function getShowPurchasers()
{
return $this->showPurchasers;
}
/**
* @Assert\Callback
*/
public function ensurePricingValid(ExecutionContextInterface $context)
{
if ($this->isFixedPrice() && (!$this->buyItNowPrice || $this->buyItNowPrice <= 0)) {
$context->buildViolation('Fixed Purchase Price must be > $0')
->atPath('buyItNowPrice')
->addViolation();
} elseif ($this->isAuctionType() && (!$this->minBid || $this->minBid <= 0)) {
$context->buildViolation('Minimum Bid required for auction items')
->atPath('minBid')
->addViolation();
}
}
/**
* @Assert\Callback
*/
public function ensureValidType(ExecutionContextInterface $context)
{
if ($this->isManualType() && !$this->isOnsite()) {
$context->buildViolation('Manual Bid only available for Event Venue venue')
->atPath('saleType')
->addViolation();
}
}
/**
* @Assert\Callback
*/
public function ensureValidDates(ExecutionContextInterface $context)
{
return;
$campaign = $this->getCampaign();
if (!$campaign) {
return;
}
$format = 'M. jS g:i a T';
if ($this->getBidBegin() < $campaign->getCampaignBegin()) {
$context->buildViolation(sprintf('Cannot start before Campaign begins: %s', $campaign->getCampaignBegin()->format($format)))
->atPath('itemBidBegin')
->addViolation();
}
if ($this->getBidEnd() > $campaign->getCampaignEnd()) {
$context->buildViolation(sprintf('Cannot end after Campaign ends: %s', $campaign->getCampaignEnd()->format($format)))
->atPath('itemBidEnd')
->addViolation();
}
}
/**
* @Assert\Callback
*/
public function ensureBidIncrement(ExecutionContextInterface $context)
{
if ($this->isFixedPrice() || $this->isDonation()) {
return;
}
if (!$this->bidIncrement) {
$context->buildViolation('Bid Increment is required')
->atPath('bidIncrement')
->addViolation();
}
}
public function getCampaign()
{
return $this->auction->getCampaign();
}
public function getObjectName()
{
return sprintf('Item %d', $this->id);
}
public function getIncludedWithTicketTypes()
{
return $this->includedWithTicketTypes;
}
public function getIncludedWithRegistrationTypes()
{
return $this->includedWithRegistrationTypes;
}
public function setQuestionText(?string $questionText)
{
$this->questionText = $questionText;
}
public function getQuestionText()
{
return $this->questionText;
}
public function setQuestionRequired(bool $questionRequired)
{
$this->questionRequired = $questionRequired;
}
public function isQuestionRequired(): bool
{
return $this->questionRequired;
}
public function setCollectEmail(bool $collectEmail)
{
$this->collectEmail = $collectEmail;
}
public function getCollectEmail(): bool
{
return $this->collectEmail;
}
public function setTemplate(ItemTemplate $template)
{
$this->template = $template;
}
public function getTemplate()
{
return $this->template;
}
public function setSortOrder($sortOrder)
{
$this->sortOrder = $sortOrder;
}
public function getSortOrder()
{
return $this->sortOrder;
}
public function isSoldOut(): bool
{
if ($this->isFixedPrice() || $this->isDonation()) {
return $this->getCurrentQuantity() <= 0;
} elseif ($this->isAuctionType()) {
$campaign = $this->getCampaign();
if ($campaign->getHoldItemsInCart()) {
return $this->isBuyItNowPurchase();
} else {
return $this->isPaidFor();
}
}
return false;
}
public function getTrackedParams()
{
return [
'itemBidBegin' => 'Bid Begin',
'itemBidEnd' => 'Bid End',
'currentQuantity' => 'Current Quantity',
'saleType' => 'Sale Type',
'venue' => 'Venue',
'minBid' => 'Min Bid',
'reservePrice' => 'Reserve Price',
'buyItNowPrice' => 'Buy It Now Price',
'estimatedValue' => 'Estimated Value',
];
}
public function __toString()
{
return sprintf('%d (%d) - %s', $this->id, $this->number, $this->name);
}
public function getPurchases(): ?Collection
{
return $this->purchases;
}
public function setPurchases(?Collection $purchases): void
{
$this->purchases = $purchases;
}
public function addPurchase(Purchase $purchase): void
{
if (!$this->purchases->contains($purchase)) {
$this->purchases->add($purchase);
if ($purchase instanceof ItemPurchase) {
$purchase->setItem($this);
}
}
}
public function removePurchase(Purchase $purchase): void
{
if ($this->purchases->contains($purchase)) {
$this->purchases->removeElement($purchase);
if ($purchase instanceof ItemPurchase) {
$purchase->setItem(null);
}
}
}
}