Open-source event management and ticket selling platform — perfect for concerts, conferences, and everything in between 🎟️ If you find this project helpful, please consider giving us a star ⭐️
PHP attendize-alternativedoor-managementevent-check-inevent-managementevent-registrationevent-ticketingeventbrite-alternativeeventslaravelopen-sourcephpreactself-hostedsell-ticketssell-tickets-onlineticket-sellingticketing-systemtickettailor-alternativetito-alternative
<?php
namespace HiEvents\Services\Domain\Product;
use HiEvents\DomainObjects\Enums\ProductType;
use HiEvents\Repository\Interfaces\AttendeeRepositoryInterface;
use HiEvents\Repository\Interfaces\OrderItemRepositoryInterface;
class SoldAndReservedQuantitiesService
{
public function __construct(
private readonly AttendeeRepositoryInterface $attendeeRepository,
private readonly OrderItemRepositoryInterface $orderItemRepository,
) {}
/**
* @param int[] $eventIds
* @return array<int, int> product_price_id => quantity held by unexpired reservations
*/
public function getReservedByPrice(array $eventIds, ?int $eventOccurrenceId = null): array
{
return $this->orderItemRepository->getReservedQuantitiesByPrice($eventIds, $eventOccurrenceId);
}
public function getReservedTicketsForOccurrence(int $eventOccurrenceId): int
{
return $this->orderItemRepository->getReservedTicketQuantityForOccurrence($eventOccurrenceId);
}
/**
* @return array<int, int> product_price_id => quantity sold on that occurrence
*/
public function getSoldByPriceForOccurrence(int $eventOccurrenceId, ProductType $productType): array
{
return $productType === ProductType::TICKET
? $this->attendeeRepository->getSoldQuantitiesByPriceForOccurrence($eventOccurrenceId)
: $this->orderItemRepository->getSoldQuantitiesByPriceForOccurrence($eventOccurrenceId);
}
/**
* @return array<int, int> product_price_id => highest quantity sold on any single occurrence
*/
public function getMaxSoldOnAnyOccurrenceByPrice(array $productPriceIds, ProductType $productType): array
{
return $productType === ProductType::TICKET
? $this->attendeeRepository->getMaxSoldPerOccurrenceByPrice($productPriceIds)
: $this->orderItemRepository->getMaxSoldPerOccurrenceByPrice($productPriceIds);
}
}