PluginProbe
GiveWP – Donation Plugin and Fundraising Platform / 4.16.9
GiveWP – Donation Plugin and Fundraising Platform v4.16.9
4.16.9 4.16.8.1 4.16.8 4.16.7.2 4.16.7.1 4.16.7 4.16.6.1 4.16.6 4.16.5.1 4.16.5 4.16.4 4.16.3 4.16.2 4.16.1 4.16.0 4.15.5 4.15.4 4.15.3 4.15.2 4.15.1 4.15.0 2.3.0 2.3.1 2.3.2 2.30.0 All 255 releases
← All changes | src/EventTickets/DataTransferObjects/TicketPurchaseData.php +19 -3 4.15.24.16.9 View file →
@@ -1,9 +1,12 @@
1 1 <?php
2 2
3 3 namespace Give\EventTickets\DataTransferObjects;
4 4
5 +use Give\EventTickets\Models\Event;
5 6 use Give\EventTickets\Models\EventTicketType;
7 +use Give\Framework\Exceptions\Primitives\InvalidArgumentException;
8 +use Give\Framework\Support\Facades\DateTime\Temporal;
6 9 use stdClass;
7 10
8 11 /**
9 12 * @since 3.6.0
@@ -30,16 +33,29 @@
30 33 return $this->$name;
31 34 }
32 35
33 36 /**
37 + * @since 4.16.8.1 Require the ticket type to belong to the given event and that event to not have already ended, and clamp quantity to a non-negative integer.
34 38 * @since 3.6.0
39 + *
40 + * @throws InvalidArgumentException
35 41 */
36 - public static function fromFieldValueObject(stdClass $object): self
42 + public static function fromFieldValueObject(stdClass $object, Event $event): self
37 43 {
44 + $ticketType = EventTicketType::find($object->ticketId ?? 0);
45 +
46 + if (!$ticketType || $ticketType->eventId !== $event->id) {
47 + throw new InvalidArgumentException('Ticket type does not belong to this event.');
48 + }
49 +
50 + if ($event->endDateTime < Temporal::getCurrentDateTime()) {
51 + throw new InvalidArgumentException('Event has already ended.');
52 + }
53 +
38 54 $self = new self();
39 55
40 - $self->quantity = $object->quantity;
41 - $self->ticketType = EventTicketType::find($object->ticketId);
56 + $self->quantity = max(0, (int) ($object->quantity ?? 0));
57 + $self->ticketType = $ticketType;
42 58
43 59 return $self;
44 60 }
45 61 }