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
give / src / EventTickets / DataTransferObjects / TicketPurchaseData.php

TicketPurchaseData.php in GiveWP – Donation Plugin and Fundraising Platform 4.16.9, at src/EventTickets/DataTransferObjects/TicketPurchaseData.php

62 lines 1.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Give\EventTickets\DataTransferObjects;
4
5 use Give\EventTickets\Models\Event;
6 use Give\EventTickets\Models\EventTicketType;
7 use Give\Framework\Exceptions\Primitives\InvalidArgumentException;
8 use Give\Framework\Support\Facades\DateTime\Temporal;
9 use stdClass;
10
11 /**
12 * @since 3.6.0
13 */
14 class TicketPurchaseData
15 {
16 /**
17 * @since 3.6.0
18 * @var int
19 */
20 protected $quantity;
21
22 /**
23 * @since 3.6.0
24 * @var EventTicketType
25 */
26 protected $ticketType;
27
28 /**
29 * @since 3.6.0
30 */
31 public function __get($name)
32 {
33 return $this->$name;
34 }
35
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.
38 * @since 3.6.0
39 *
40 * @throws InvalidArgumentException
41 */
42 public static function fromFieldValueObject(stdClass $object, Event $event): self
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
54 $self = new self();
55
56 $self->quantity = max(0, (int) ($object->quantity ?? 0));
57 $self->ticketType = $ticketType;
58
59 return $self;
60 }
61 }
62