Passed
Push — main ( 8fbbef...42449e )
by Daniel
17:42 queued 03:45
created

Bookwhen::attachments()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 28
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 16
CRAP Score 2.0008

Importance

Changes 3
Bugs 0 Features 0
Metric Value
cc 2
eloc 15
c 3
b 0
f 0
nc 2
nop 3
dl 0
loc 28
ccs 16
cts 17
cp 0.9412
crap 2.0008
rs 9.7666
1
<?php
2
3
declare(strict_types=1);
4
5
namespace InShore\Bookwhen;
6
7
use InShore\Bookwhen\BookwhenApi;
8
use InShore\Bookwhen\Client;
9
use InShore\Bookwhen\Domain\Attachment;
10
use InShore\Bookwhen\Domain\ClassPass;
11
use InShore\Bookwhen\Domain\Event;
12
use InShore\Bookwhen\Domain\Location;
13
use InShore\Bookwhen\Domain\Ticket;
14
use InShore\Bookwhen\Exceptions\ConfigurationException;
15
use InShore\Bookwhen\Exceptions\ValidationException;
16
use InShore\Bookwhen\Interfaces\BookwhenInterface;
17
use InShore\Bookwhen\Validator;
18
use Monolog\Level;
19
use Monolog\Logger;
20
use Monolog\Handler\StreamHandler;
21
22
final class Bookwhen implements BookwhenInterface
23
{
24
    /**
25
     *
26
     */
27
    public Attachment $attachment;
28
29
    /**
30
     *
31
     */
32
    public array $attachments = [];
33
34
    /**
35
     *
36
     */
37
    public Client $client;
38
39
    /**
40
     *
41
     */
42
    public ClassPass $classPass;
43
44
    /**
45
     *
46
     */
47
    public array $classPasses = [];
48
49
    /**
50
     *
51
     */
52
    public Event $event;
53
54
    /**
55
     *
56
     */
57
    public array $events = [];
58
59
    /**
60
     *
61
     */
62
    private array $filters = [];
63
64
    /**
65
     *
66
     */
67
    public Location $location;
68
69
    /**
70
     *
71
     */
72
    public array $includes = [];
73
74
    /**
75
     *
76
     */
77
    public Ticket $ticket;
78
79
    /**
80
     *
81
     */
82
    public array $tickets = [];
83
84
    /**
85
     *
86
     */
87
    public $locations = [];
88
89
90
    /** @var string The path to the log file */
91
    //private $logFile;
92
93
    /** @var object loging object. */
94
    //private $logger;
95
96
    /** @var string the logging level. */
97
    //private string $logLevel;
98
99
    /**
100
     * Creates a new Bookwhen Client with the given API token.
101
     * @throws ConfigurationException
102
     * @todo logging
103
     */
104 20
    public function __construct(
105
        string $apiKey = null,
106
        Client $client = null,
107
        private $validator = new Validator()
108
    ) {
109
        //         $this->logFile = $logFile;
110
        //         $this->logLevel = $logLevel;
111
        //         $this->logger = new Logger('inShore Bookwhen API');
112
        //         $this->logger->pushHandler(new StreamHandler($this->logFile, $this->logLevel));
113
        try {
114 20
            if(!is_null($client)) {
115 11
                $this->client = $client;
116
            } else {
117 9
                $this->client = !is_null($apiKey)
118 9
                ? BookwhenApi::client($apiKey)
119 1
                : (array_key_exists('INSHORE_BOOKWHEN_API_KEY', $_ENV)
120
                    ? BookwhenApi::client($_ENV['INSHORE_BOOKWHEN_API_KEY'])
121 20
                    : throw new ConfigurationException());
122
            }
123 1
        } catch (\TypeError $e) {
124
            throw new ConfigurationException(); // @todo message
125
        }
126
    }
127
128
    /**
129
     *
130
     * @param string $filter
131
     * @param string $value
132
     * @param string $validator
133
     * @throws ValidationException
134 3
     */
135
    public function addFilter(string $filter, null | string $value, string $validator): void
136 3
    {
137 2
138
        if (!is_null($value) && !$this->validator->$validator($value)) {
139
            throw new ValidationException($filter, $value);
140 1
        } else {
141
            $this->filters['filter[' . $filter . ']'] = $value;
142 1
        }
143 1
    }
144 1
145 1
    /**
146 1
     *
147 1
     * {@inheritDoc}
148 1
     * @see \InShore\Bookwhen\Interfaces\ClientInterface::attachment()
149 1
     * @todo all attachment properties
150 1
     */
151 1
    public function attachment(string $attachmentId): Attachment
152
    {
153
        if (!$this->validator->validId($attachmentId, 'attachment')) {
154
            throw new ValidationException('attachmentId', $attachmentId);
155
        }
156
157
        $attachment = $this->client->attachments()->retrieve($attachmentId);
158
159
        return $this->attachment = new Attachment(
160 1
            $attachment->contentType,
161
            $attachment->fileUrl,
162
            $attachment->fileSizeBytes,
163
            $attachment->fileSizeText,
164
            $attachment->fileName,
165
            $attachment->fileType,
166
            $attachment->id,
167 1
            $attachment->title,
168
        );
169
    }
170
171
    /**
172
     *
173
     * {@inheritDoc}
174
     *
175 1
     * @see \InShore\Bookwhen\Interfaces\BookwhenInterface::attachment()
176
     */
177
    public function attachments(
178 1
        string $title = null,
179
        string $fileName = null,
180
        string $fileType = null
181 1
    ): array {
182
183
        $this->addFilter('title', $title, 'validTitle');
184 1
185
        $this->addFilter('file_name', $fileName, 'validFileName');
186
187 1
        $this->addFilter('file_type', $fileType, 'validFileType');
188
189 1
        $attachments = $this->client->attachments()->list($this->filters);
190 1
191 1
        foreach ($attachments->data as $attachment) {
192 1
            array_push($this->attachments, new Attachment(
193 1
                $attachment->contentType,
194 1
                $attachment->fileUrl,
195 1
                $attachment->fileSizeBytes,
196 1
                $attachment->fileSizeText,
197 1
                $attachment->fileName,
198 1
                $attachment->fileType,
199 1
                $attachment->id,
200
                $attachment->title
201
            ));
202 1
        }
203
204
        return $this->attachments;
205
    }
206
207
    /**
208
     *
209
     * {@inheritDoc}
210
     * @see \InShore\Bookwhen\Interfaces\ClientInterface::getClassPass()
211 1
     * @todo
212
     */
213
    public function classPass(string $classPassId): ClassPass
214
    {
215 1
216
        if (!$this->validator->validId($classPassId, 'classPass')) {
217
            throw new ValidationException('classPassId', $classPassId);
218
        }
219 1
220
        $classPass = $this->client->classPasses()->retrieve($classPassId);
221 1
222 1
        return new ClassPass(
223 1
            $classPass->details,
224 1
            $classPass->id,
225 1
            $classPass->numberAvailable,
226 1
            $classPass->title,
227 1
            $classPass->usageAllowance,
228 1
            $classPass->usageType,
229 1
            $classPass->useRestrictedForDays
230
        );
231
    }
232
233
    /**
234
     *
235
     * {@inheritDoc}
236
     * @see \InShore\Bookwhen\Interfaces\ClientInterface::getClassPasses()
237 1
     */
238
    public function classPasses(
239
        $cost = null,
240
        $detail = null,
241
        $title = null,
242
        $usageAllowance = null,
243
        $usageType = null,
244
        $useRestrictedForDays = null
245
    ): array {
246
247
        $this->addFilter('detail', $detail, 'validDetails');
248 1
249
        $this->addFilter('title', $title, 'validTitle');
250
251 1
        $this->addFilter('usage_allowance', $usageAllowance, 'validUsageAllowance');
252
253
        $this->addFilter('usage_type', $usageType, 'validUsageType');
254 1
255
        $this->addFilter('use_restricted_for_days', $useRestrictedForDays, 'validUseRestrictedForDays');
256
257 1
        $classPasses = $this->client->classPasses()->list($this->filters);
258
259
        foreach ($classPasses->data as $classPass) {
260 1
            array_push($this->classPasses, new ClassPass(
261
                $classPass->details,
262
                $classPass->id,
263 1
                $classPass->numberAvailable,
264
                $classPass->title,
265
                $classPass->usageAllowance,
266 1
                $classPass->usageType,
267
                $classPass->useRestrictedForDays,
268
            ));
269 1
        }
270
        return $this->classPasses;
271
    }
272 1
273
    /**
274
     *
275 1
     * {@inheritDoc}
276
     * @see \InShore\Bookwhen\Interfaces\BookwhenInterface::event()
277
     */
278 1
    public function event(
279
        string $eventId,
280 1
        bool $includeAttachments = false,
281 1
        bool $includeLocation = false,
282 1
        bool $includeTickets = false,
283 1
        bool $includeTicketsClassPasses = false,
284 1
        bool $includeTicketsEvents = false
285 1
    ): Event {
286 1
287 1
        if (!$this->validator->validId($eventId, 'event')) {
288 1
            throw new ValidationException('eventId', $eventId);
289 1
        }
290
291 1
        // Validate $includeAttachments;
292
        if (!$this->validator->validInclude($includeAttachments)) {
293
            throw new ValidationException('includeAttachments', $includeAttachments);
294
        }
295
296
        // Validate $includeTickets;
297
        if (!$this->validator->validInclude($includeLocation)) {
298
            throw new ValidationException('includeLocation', $includeLocation);
299 2
        }
300
301
        // Validate $includeTickets;
302
        if (!$this->validator->validInclude($includeTickets)) {
303
            throw new ValidationException('includeTickets', $includeTickets);
304
        }
305
306
        // Validate $includeTicketsEvents;
307
        if (!$this->validator->validInclude($includeTicketsEvents)) {
308
            throw new ValidationException('includeTicketsEvents', $includeTicketsEvents);
309 2
        }
310
311
        // Validate $includeTicketsClassPasses;
312
        if (!$this->validator->validInclude($includeTicketsClassPasses)) {
313
            throw new ValidationException('includeTicketsClassPasses', $includeTicketsClassPasses);
314 2
        }
315
316
        $includesMapping = [
317
            'attachments' => $includeAttachments,
318 2
            'location' => $includeLocation,
319
            'tickets' => $includeTickets,
320
            'tickets.events' => $includeTicketsEvents,
321
            'tickets.class_passes' => $includeTicketsClassPasses,
322
        ];
323 2
324
        $this->includes = array_keys(array_filter($includesMapping, function ($value) {
325
            return $value;
326 2
        }));
327
328
        $event = $this->client->events()->retrieve($eventId, ['include' => implode(',', $this->includes)]);
329
330
        // attachments
331 2
        $eventAttachments = [];
332
333
        foreach ($event->attachments as $eventAttachment) {
334
            $attachment = $this->client->attachments()->retrieve($eventAttachment->id);
335 2
            array_push($eventAttachments, new Attachment(
336
                $attachment->contentType,
337
                $attachment->fileUrl,
338
                $attachment->fileSizeBytes,
339
                $attachment->fileSizeText,
340 2
                $attachment->fileName,
341
                $attachment->fileType,
342
                $attachment->id,
343
                $attachment->title
344 2
            ));
345
        }
346
347
        // eventTickets
348
        $eventTickets = [];
349 2
        foreach ($event->tickets as $ticket) {
350
            array_push($eventTickets, new Ticket(
351
                $ticket->available,
352
                $ticket->availableFrom,
353 2
                $ticket->availableTo,
354
                $ticket->builtBasketUrl,
355
                $ticket->builtBasketIframeUrl,
356
                $ticket->cost,
357 2
                $ticket->courseTicket,
358
                $ticket->details,
359
                $ticket->groupTicket,
360 2
                $ticket->groupMin,
361
                $ticket->groupMax,
362 2
                $ticket->id,
363
                $ticket->numberIssued,
364
                $ticket->numberTaken,
365
                $ticket->title
366
            ));
367
        }
368
369
        // ticketsClassPasses
370
        // @todo
371
372
        return $this->event = new Event(
373
            $event->allDay,
374
            $eventAttachments,
375
            $event->attendeeCount,
376
            $event->attendeeLimit,
377 2
            $event->details,
378 2
            $event->endAt,
379 2
            $event->id,
380 2
            new Location(
381 2
                $event->location->additionalInfo,
382 2
                $event->location->addressText,
383 2
                $event->location->id,
384 2
                $event->location->latitude,
385 2
                $event->location->longitude,
386 2
                $event->location->mapUrl,
387 2
                $event->location->zoom
388 2
            ),
389 2
            $event->maxTicketsPerBooking,
390 2
            $event->startAt,
391 2
            $eventTickets,
392 2
            $event->title,
393 2
            $event->waitingList
394 2
        );
395 2
    }
396
397
    /**
398
     *
399
     * {@inheritDoc}
400
     * @see \InShore\Bookwhen\Interfaces\ClientInterface::getEvents()
401 2
     */
402 2
    public function events(
403 2
        $calendar = false,
404 2
        $entry = false,
405 2
        $location = [],
406 2
        $tags = [],
407 2
        $title = [],
408 2
        $detail = [],
409 2
        $from = null,
410 2
        $to = null,
411 2
        bool $includeAttachments = false,
412 2
        bool $includeLocation = false,
413 2
        bool $includeTickets = false,
414 2
        bool $includeTicketsClassPasses = false,
415 2
        bool $includeTicketsEvents = false
416 2
    ): array {
417 2
418 2
        //$this->logger->debug(__METHOD__ . '(' . var_export(func_get_args(), true) . ')');
419 2
420 2
        // Validate $calendar
421 2
        // @todo details required
422 2
423 2
        // Validate $detail
424
        if (!empty($detail)) {
425
            if (!is_array($detail)) {
426
                throw new ValidationException('detail', implode(' ', $detail));
427
            } else {
428
                $detail = array_unique($detail);
429
                foreach ($detail as $item) {
430
                    if (!$this->validator->validLocation($item)) {
431 1
                        throw new ValidationException('detail', $item);
432
                    }
433
                }
434
                $this->filters['filter[detail]'] = implode(',', $detail);
435
            }
436
        }
437
438
        // Validate $entry
439
        // @todo details required
440
441
        // Validate $from;
442
        if (!empty($from)) {
443
            if (!$this->validator->validFrom($from, $to)) {
444
                throw new ValidationException('from', $from . '-' . $to);
445
            } else {
446
                $this->filters['filter[from]'] = $from;
447
            }
448
        }
449
450
        // Validate $location
451
        if (!empty($location)) {
452
            if (!is_array($location)) {
453 1
                throw new ValidationException('location', implode(' ', $title));
454
            } else {
455
                $location = array_unique($location);
456
                foreach ($location as $item) {
457
                    if (!$this->validator->validLocation($item)) {
458
                        throw new ValidationException('location', $item);
459
                    }
460
                }
461
                $this->filters['filter[location]'] = implode(',', $location);
462
            }
463
        }
464
465
        // Validate $tags.
466
        if (!empty($tags)) {
467
            if (!is_array($tags)) {
468
                throw new ValidationException('tags', implode(' ', $tags));
469
            } else {
470
                $tags = array_unique($tags);
471 1
                foreach ($tags as $tag) {
472
                    if (!empty($tag) && !$this->validator->validTag($tag)) {
473
                        throw new ValidationException('tag', $tag);
474
                    }
475
                }
476
            }
477
            $this->filters['filter[tag]'] = implode(',', $tags);
478
        }
479
480 1
        // Validate $title;
481
        if (!empty($title)) {
482
            if (!is_array($title)) {
483
                throw new ValidationException('title', implode(' ', $title));
484
            } else {
485
                $title = array_unique($title);
486
                foreach ($title as $item) {
487
                    if (!$this->validator->validTitle($item)) {
488
                        throw new ValidationException('title', $item);
489
                    }
490
                }
491
                $this->filters['filter[title]'] = implode(',', $title);
492
            }
493
        }
494
495 1
        // Validate $to;
496
        if (!empty($to)) {
497
            if (!$this->validator->validTo($to, $from)) {
498
                throw new ValidationException('to', $to . '-' . $from);
499
            } else {
500
                $this->filters['filter[to]'] = $to;
501
            }
502
        }
503
504
        // Validate $includeTickets;
505
        if (!$this->validator->validInclude($includeLocation)) {
506
            throw new ValidationException('includeLocation', $includeLocation);
507
        }
508
509
        // Validate $includeTickets;
510 1
        if (!$this->validator->validInclude($includeTickets)) {
511
            throw new ValidationException('includeTickets', $includeTickets);
512
        }
513
514
        // Validate $includeTicketsEvents;
515
        if (!$this->validator->validInclude($includeTicketsEvents)) {
516
            throw new ValidationException('includeTicketsEvents', $includeTicketsEvents);
517
        }
518
519
        // Validate $includeTicketsClassPasses;
520
        if (!$this->validator->validInclude($includeTicketsClassPasses)) {
521
            throw new ValidationException('includeTicketsClassPasses', $includeTicketsClassPasses);
522
        }
523
524
        $includesMapping = [
525 1
            'location' => $includeLocation,
526
            'tickets' => $includeTickets,
527
            'tickets.events' => $includeTicketsEvents,
528
            'tickets.class_passes' => $includeTicketsClassPasses,
529
        ];
530
531
        $this->includes = array_keys(array_filter($includesMapping, function ($value) {
532
            return $value;
533
        }));
534 1
535
        $events = $this->client->events()->list(array_merge($this->filters, ['include' => implode(',', $this->includes)]));
536
537 1
        foreach ($events->data as $event) {
538
539
            $eventTickets = [];
540
            foreach ($event->tickets as $ticket) {
541
                array_push($eventTickets, new Ticket(
542 1
                    $ticket->available,
543
                    $ticket->availableFrom,
544
                    $ticket->availableTo,
545
                    $ticket->builtBasketUrl,
546 1
                    $ticket->builtBasketIframeUrl,
547
                    $ticket->cost,
548
                    $ticket->courseTicket,
549
                    $ticket->details,
550
                    $ticket->groupTicket,
551 1
                    $ticket->groupMin,
552
                    $ticket->groupMax,
553
                    $ticket->id,
554
                    $ticket->numberIssued,
555 1
                    $ticket->numberTaken,
556
                    $ticket->title
557
                ));
558
            }
559
560 1
            array_push($this->events, new Event(
561
                $event->allDay,
562
                $event->attachments,
563
                $event->attendeeCount,
564 1
                $event->attendeeLimit,
565
                $event->details,
566
                $event->endAt,
567
                $event->id,
568 1
                new Location(
569
                    $event->location->additionalInfo,
570 1
                    $event->location->addressText,
571
                    $event->location->id,
572 1
                    $event->location->latitude,
573 1
                    $event->location->longitude,
574 1
                    $event->location->mapUrl,
575 1
                    $event->location->zoom
576 1
                ),
577 1
                $event->maxTicketsPerBooking,
578 1
                $event->startAt,
579 1
                $eventTickets,
580 1
                $event->title,
581 1
                $event->waitingList
582 1
            ));
583 1
        }
584 1
585 1
        return $this->events;
586 1
    }
587 1
588 1
    /*
589 1
     *
590 1
     * {@inheritDoc}
591
     * @see \InShore\Bookwhen\Interfaces\ClientInterface::getLocation()
592
     */
593 1
    public function location(string $locationId): Location
594 1
    {
595 1
596 1
        if (!$this->validator->validId($locationId, 'location')) {
597 1
            throw new ValidationException('locationId', $locationId);
598 1
        }
599 1
600 1
        $location = $this->client->locations()->retrieve($locationId);
601 1
602 1
        return $this->location = new Location(
603 1
            $location->additionalInfo,
604 1
            $location->addressText,
605 1
            $location->id,
606 1
            $location->latitude,
607 1
            $location->longitude,
608 1
            $location->mapUrl,
609 1
            $location->zoom
610 1
        );
611 1
    }
612 1
613 1
    /**
614 1
     *
615 1
     */
616
    public function locations(
617
        null | string $addressText = null,
618 1
        null | string $additionalInfo = null
619
    ): array {
620
621
        $this->addFilter('additional_info', $additionalInfo, 'validAdditionalInfo');
622
623
        $this->addFilter('address_text', $addressText, 'validAddressText');
624
625
        $locations = $this->client->locations()->list($this->filters);
626 1
627
        foreach ($locations->data as $location) {
628
            array_push($this->locations, new Location(
629 1
                $location->additionalInfo,
630
                $location->addressText,
631
                $location->id,
632
                $location->latitude,
633 1
                $location->longitude,
634
                $location->mapUrl,
635 1
                $location->zoom
636 1
            ));
637 1
        }
638 1
639 1
        return $this->locations;
640 1
641 1
    }
642 1
643 1
//     /**
644
//      * Set Debug.
645
//      * @deprecated
646
//      */
647
//     public function setLogging($level)
648
//     {
649 1
//         $this->logLevel = $level;
650
//     }
651
652
    /**
653
     * {@inheritDoc}
654
     * @see \InShore\Bookwhen\Interfaces\BookWhenInterface::ticket()
655
     * class_passes
656 1
     */
657
    public function ticket(
658
        string $ticketId,
659
        bool $includeClassPasses = false,
660
        bool $includeEvents = false,
661
        bool $includeEventsAttachments = false,
662
        bool $includeEventsLocation = false,
663 1
        bool $includeEventsTickets = false
664
    ): Ticket {
665
666
        // ticketId
667
        if (!$this->validator->validId($ticketId, 'ticket')) {
668
            throw new ValidationException('ticketId', $ticketId);
669
        }
670 1
671
        // Validate $includeClassPasses;
672 1
        if (!$this->validator->validInclude($includeClassPasses)) {
673 1
            throw new ValidationException('includeClassPasses', $includeClassPasses);
674 1
        }
675 1
676 1
        // Validate $includeEvents;
677 1
        if (!$this->validator->validInclude($includeEvents)) {
678 1
            throw new ValidationException('includeEvents', $includeEvents);
679 1
        }
680 1
681 1
        // Validate $includeAttachments;
682
        if (!$this->validator->validInclude($includeEventsAttachments)) {
683
            throw new ValidationException('includeEventssAttachments', $includeEventsAttachments);
684 1
        }
685
686
        // Validate $includeEventsLocation;
687
        if (!$this->validator->validInclude($includeEventsLocation)) {
688
            throw new ValidationException('includeEventsLocation', $includeEventsLocation);
689
        }
690
691
        // Validate $includeEventsTickets;
692
        if (!$this->validator->validInclude($includeEventsTickets)) {
693
            throw new ValidationException('includeEventsTickets', $includeEventsTickets);
694
        }
695
696
        $includesMapping = [
697
            'class_passes' => $includeClassPasses,
698
            'events' => $includeEvents,
699
            'events.attachments' => $includeEventsAttachments,
700
            'events.location' => $includeEventsLocation,
701
            'events.tickets' => $includeEventsTickets,
702 1
        ];
703
704
        $this->includes = array_keys(array_filter($includesMapping, function ($value) {
705
            return $value;
706
        }));
707
708
        $ticket = $this->client->tickets()->retrieve($ticketId);
709
        return $this->ticket = new Ticket(
710
            $ticket->available,
711
            $ticket->availableFrom,
712 1
            $ticket->availableTo,
713
            $ticket->builtBasketUrl,
714
            $ticket->builtBasketIframeUrl,
715
            $ticket->cost,
716
            $ticket->courseTicket,
717 1
            $ticket->details,
718
            $ticket->groupTicket,
719
            $ticket->groupMin,
720
            $ticket->groupMax,
721 1
            $ticket->id,
722
            $ticket->numberIssued,
723
            $ticket->numberTaken,
724
            $ticket->title
725
        );
726 1
    }
727
728
    /**
729 1
     * {@inheritDoc}
730
     * @see \InShore\Bookwhen\Interfaces\BookWhenInterface::tickets()
731
     * @todo includes
732
     */
733
    public function tickets(
734 1
        string $eventId,
735
        bool $includeClassPasses = false,
736
        bool $includeEvents = false,
737 1
        bool $includeEventsAttachments = false,
738
        bool $includeEventsLocation = false,
739
        bool $includeEventsTickets = false
740
    ): array {
741
742 1
        // $this->logger->debug(__METHOD__ . '(' . var_export(func_get_args(), true) . ')');
743
744
        if (!$this->validator->validId($eventId, 'event')) {
745 1
            throw new ValidationException('eventId', $eventId);
746
        }
747
748
        // Validate $includeClassPasses;
749
        if (!$this->validator->validInclude($includeClassPasses)) {
750 1
            throw new ValidationException('includeClassPasses', $includeClassPasses);
751
        }
752
753 1
        // Validate $includeEvents;
754
        if (!$this->validator->validInclude($includeEvents)) {
755
            throw new ValidationException('includeEvents', $includeEvents);
756
        }
757 1
758 1
        // Validate $includeAttachments;
759 1
        if (!$this->validator->validInclude($includeEventsAttachments)) {
760 1
            throw new ValidationException('includeEventssAttachments', $includeEventsAttachments);
761 1
        }
762 1
763 1
        // Validate $includeEventsLocation;
764 1
        if (!$this->validator->validInclude($includeEventsLocation)) {
765 1
            throw new ValidationException('includeEventsLocation', $includeEventsLocation);
766 1
        }
767 1
768 1
        // Validate $includeEventsTickets;
769 1
        if (!$this->validator->validInclude($includeEventsTickets)) {
770 1
            throw new ValidationException('includeEventsTickets', $includeEventsTickets);
771 1
        }
772 1
773 1
        $includesMapping = [
774 1
            'class_passes' => $includeClassPasses,
775
            'events' => $includeEvents,
776
            'events.attachments' => $includeEventsAttachments,
777
            'events.location' => $includeEventsLocation,
778
            'events.tickets' => $includeEventsTickets,
779
        ];
780
781
        $this->includes = array_keys(array_filter($includesMapping, function ($value) {
782 1
            return $value;
783
        }));
784
785
        $tickets = $this->client->tickets()->list(array_merge(['event_id' => $eventId], ['include' => implode(',', $this->includes)]));
786
787
        foreach ($tickets->data as $ticket) {
788
            array_push($this->tickets, new Ticket(
789
                $ticket->available,
790
                $ticket->availableFrom,
791
                $ticket->availableTo,
792
                $ticket->builtBasketUrl,
793 1
                $ticket->builtBasketIframeUrl,
794
                $ticket->cost,
795
                $ticket->courseTicket,
796
                $ticket->details,
797
                $ticket->groupTicket,
798 1
                $ticket->groupMin,
799
                $ticket->groupMax,
800
                $ticket->id,
801
                $ticket->numberIssued,
802 1
                $ticket->numberTaken,
803
                $ticket->title
804
            ));
805
        }
806
807 1
        return $this->tickets;
808
809
    }
810
811
}
812