Completed
Push — main ( 439431...5a0a5a )
by Daniel
27s queued 13s
created

Bookwhen::setLogging()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 3
ccs 0
cts 0
cp 0
crap 2
rs 10
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
     * {@inheritDoc}
131
     * @see \InShore\Bookwhen\Interfaces\ClientInterface::attachment()
132
     * @todo all attachment properties
133
     */
134 3
    public function attachment(string $attachmentId): Attachment
135
    {
136 3
        if (!$this->validator->validId($attachmentId, 'attachment')) {
137 2
            throw new ValidationException('attachmentId', $attachmentId);
138
        }
139
140 1
        $attachment = $this->client->attachments()->retrieve($attachmentId);
141
142 1
        return $this->attachment = new Attachment(
143 1
            $attachment->contentType,
144 1
            $attachment->fileUrl,
145 1
            $attachment->fileSizeBytes,
146 1
            $attachment->fileSizeText,
147 1
            $attachment->fileName,
148 1
            $attachment->fileType,
149 1
            $attachment->id,
150 1
            $attachment->title,
151 1
        );
152
    }
153
154
    /**
155
     *
156
     * {@inheritDoc}
157
     * @see \InShore\Bookwhen\Interfaces\BookwhenInterface::attachment()
158
     * @todo
159
     */
160 1
    public function attachments(
161
        string $title = null,
162
        string $fileName = null,
163
        string $fileType = null
164
    ): array {
165
        //$this->logger->debug(__METHOD__ . '(' . var_export(func_get_args(), true) . ')');
166
167 1
        if (!is_null($title)) {
168
            if ($this->validator->validTitle($title)) {
169
                $this->filters['filter[title]'] = $title;
170
            } else {
171
                throw new ValidationException('title', $title);
172
            }
173
        }
174
175 1
        if (!is_null($fileName) && !$this->validator->validFileName($fileName)) {
176
            throw new ValidationException('file name', $fileName);
177
        } else {
178 1
            $this->filters['filter[file_name]'] = $fileName;
179
        }
180
181 1
        if (!is_null($fileType) && !$this->validator->validFileType($fileType)) {
182
            throw new ValidationException('file type', $fileType);
183
        } else {
184 1
            $this->filters['filter[file_type]'] = $fileType;
185
        }
186
187 1
        $attachments = $this->client->attachments()->list($this->filters);
188
189 1
        foreach ($attachments->data as $attachment) {
190 1
            array_push($this->attachments, new Attachment(
191 1
                $attachment->contentType,
192 1
                $attachment->fileUrl,
193 1
                $attachment->fileSizeBytes,
194 1
                $attachment->fileSizeText,
195 1
                $attachment->fileName,
196 1
                $attachment->fileType,
197 1
                $attachment->id,
198 1
                $attachment->title
199 1
            ));
200
        }
201
202 1
        return $this->attachments;
203
    }
204
205
    /**
206
     *
207
     * {@inheritDoc}
208
     * @see \InShore\Bookwhen\Interfaces\ClientInterface::getClassPass()
209
     * @todo
210
     */
211 1
    public function classPass(string $classPassId): ClassPass
212
    {
213
        //         $this->logger->debug(__METHOD__ . '(' . var_export(func_get_args(), true) . ')');
214
215 1
        if (!$this->validator->validId($classPassId, 'classPass')) {
216
            throw new ValidationException('classPassId', $classPassId);
217
        }
218
219 1
        $classPass = $this->client->classPasses()->retrieve($classPassId);
220
221 1
        return new ClassPass(
222 1
            $classPass->details,
223 1
            $classPass->id,
224 1
            $classPass->numberAvailable,
225 1
            $classPass->title,
226 1
            $classPass->usageAllowance,
227 1
            $classPass->usageType,
228 1
            $classPass->useRestrictedForDays
229 1
        );
230
    }
231
232
    /**
233
     *
234
     * {@inheritDoc}
235
     * @see \InShore\Bookwhen\Interfaces\ClientInterface::getClassPasses()
236
     */
237 1
    public function classPasses(
238
        $cost = null,
239
        $detail = null,
240
        $title = null,
241
        $usageAllowance = null,
242
        $usageType = null,
243
        $useRestrictedForDays = null
244
    ): array {
245
246
        //$this->logger->debug(__METHOD__ . '(' . var_export(func_get_args(), true) . ')');
247
248 1
        if (!is_null($detail) && !$this->validator->validDetails($detail)) {
249
            throw new ValidationException('detail', $detail);
250
        } else {
251 1
            $this->filters['filter[detail]'] = $detail;
252
        }
253
254 1
        if (!is_null($title) && !$this->validator->validTitle($title)) {
255
            throw new ValidationException('title', $title);
256
        } else {
257 1
            $this->filters['filter[title]'] = $title;
258
        }
259
260 1
        if (!is_null($usageAllowance) && !$this->validator->validUsageAllowance($usageAllowance)) {
261
            throw new ValidationException('usageAllowance', $usageAllowance);
262
        } else {
263 1
            $this->filters['filter[usage_allowance]'] = $usageAllowance;
264
        }
265
266 1
        if (!is_null($usageType) && !$this->validator->validUsageType($usageType)) {
267
            throw new ValidationException('usageType', $usageType);
268
        } else {
269 1
            $this->filters['filter[usage_type]'] = $usageType;
270
        }
271
272 1
        if (!is_null($useRestrictedForDays) && !$this->validator->validUseRestrictedForDays($useRestrictedForDays)) {
273
            throw new ValidationException('useRestrictedForDays', $useRestrictedForDays);
274
        } else {
275 1
            $this->filters['filter[use_restricted_for_days]'] = $useRestrictedForDays;
276
        }
277
278 1
        $classPasses = $this->client->classPasses()->list($this->filters);
279
280 1
        foreach ($classPasses->data as $classPass) {
281 1
            array_push($this->classPasses, new ClassPass(
282 1
                $classPass->details,
283 1
                $classPass->id,
284 1
                $classPass->numberAvailable,
285 1
                $classPass->title,
286 1
                $classPass->usageAllowance,
287 1
                $classPass->usageType,
288 1
                $classPass->useRestrictedForDays,
289 1
            ));
290
        }
291 1
        return $this->classPasses;
292
    }
293
294
    /**
295
     *
296
     * {@inheritDoc}
297
     * @see \InShore\Bookwhen\Interfaces\BookwhenInterface::event()
298
     */
299 2
    public function event(
300
        string $eventId,
301
        bool $includeAttachments = false,
302
        bool $includeLocation = false,
303
        bool $includeTickets = false,
304
        bool $includeTicketsClassPasses = false,
305
        bool $includeTicketsEvents = false
306
    ): Event {
307
        //$this->logger->debug(__METHOD__ . '(' . var_export(func_get_args(), true) . ')');
308
309 2
        if (!$this->validator->validId($eventId, 'event')) {
310
            throw new ValidationException('eventId', $eventId);
311
        }
312
313
        // Validate $includeAttachments;
314 2
        if (!$this->validator->validInclude($includeAttachments)) {
315
            throw new ValidationException('includeAttachments', $includeAttachments);
316
        }
317
318 2
        if ($includeAttachments) {
319
            array_push($this->includes, 'attachments');
320
        }
321
322
        // Validate $includeTickets;
323 2
        if (!$this->validator->validInclude($includeLocation)) {
324
            throw new ValidationException('includeLocation', $includeLocation);
325
        }
326 2
        if ($includeLocation) {
327
            array_push($this->includes, 'location');
328
        }
329
330
        // Validate $includeTickets;
331 2
        if (!$this->validator->validInclude($includeTickets)) {
332
            throw new ValidationException('includeTickets', $includeTickets);
333
        }
334
335 2
        if ($includeTickets) {
336
            array_push($this->includes, 'tickets');
337
        }
338
339
        // Validate $includeTicketsEvents;
340 2
        if (!$this->validator->validInclude($includeTicketsEvents)) {
341
            throw new ValidationException('includeTicketsEvents', $includeTicketsEvents);
342
        }
343
344 2
        if ($includeTicketsEvents) {
345
            array_push($this->includes, 'tickets.events');
346
        }
347
348
        // Validate $includeTicketsClassPasses;
349 2
        if (!$this->validator->validInclude($includeTicketsClassPasses)) {
350
            throw new ValidationException('includeTicketsClassPasses', $includeTicketsClassPasses);
351
        }
352
353 2
        if ($includeTicketsClassPasses) {
354
            array_push($this->includes, 'tickets.class_passes');
355
        }
356
357 2
        $event = $this->client->events()->retrieve($eventId, ['include' => implode(',', $this->includes)]);
358
359
        // attachments
360 2
        $eventAttachments = [];
361
362 2
        foreach ($event->attachments as $eventAttachment) {
363
            $attachment = $this->client->attachments()->retrieve($eventAttachment->id);
364
            array_push($eventAttachments, new Attachment(
365
                $attachment->contentType,
366
                $attachment->fileUrl,
367
                $attachment->fileSizeBytes,
368
                $attachment->fileSizeText,
369
                $attachment->fileName,
370
                $attachment->fileType,
371
                $attachment->id,
372
                $attachment->title
373
            ));
374
        }
375
376
        // eventTickets
377 2
        $eventTickets = [];
378 2
        foreach ($event->tickets as $ticket) {
379 2
            array_push($eventTickets, new Ticket(
380 2
                $ticket->available,
381 2
                $ticket->availableFrom,
382 2
                $ticket->availableTo,
383 2
                $ticket->builtBasketUrl,
384 2
                $ticket->builtBasketIframeUrl,
385 2
                $ticket->cost,
386 2
                $ticket->courseTicket,
387 2
                $ticket->details,
388 2
                $ticket->groupTicket,
389 2
                $ticket->groupMin,
390 2
                $ticket->groupMax,
391 2
                $ticket->id,
392 2
                $ticket->numberIssued,
393 2
                $ticket->numberTaken,
394 2
                $ticket->title
395 2
            ));
396
        }
397
398
        // ticketsClassPasses
399
        // @todo
400
401 2
        return $this->event = new Event(
402 2
            $event->allDay,
403 2
            $eventAttachments,
404 2
            $event->attendeeCount,
405 2
            $event->attendeeLimit,
406 2
            $event->details,
407 2
            $event->endAt,
408 2
            $event->id,
409 2
            new Location(
410 2
                $event->location->additionalInfo,
411 2
                $event->location->addressText,
412 2
                $event->location->id,
413 2
                $event->location->latitude,
414 2
                $event->location->longitude,
415 2
                $event->location->mapUrl,
416 2
                $event->location->zoom
417 2
            ),
418 2
            $event->maxTicketsPerBooking,
419 2
            $event->startAt,
420 2
            $eventTickets,
421 2
            $event->title,
422 2
            $event->waitingList
423 2
        );
424
    }
425
426
    /**
427
     *
428
     * {@inheritDoc}
429
     * @see \InShore\Bookwhen\Interfaces\ClientInterface::getEvents()
430
     */
431 1
    public function events(
432
        $calendar = false,
433
        $entry = false,
434
        $location = [],
435
        $tags = [],
436
        $title = [],
437
        $detail = [],
438
        $from = null,
439
        $to = null,
440
        bool $includeAttachments = false,
441
        bool $includeLocation = false,
442
        bool $includeTickets = false,
443
        bool $includeTicketsClassPasses = false,
444
        bool $includeTicketsEvents = false
445
    ): array {
446
447
        //$this->logger->debug(__METHOD__ . '(' . var_export(func_get_args(), true) . ')');
448
449
        // Validate $calendar
450
        // @todo details required
451
452
        // Validate $detail
453 1
        if (!empty($detail)) {
454
            if (!is_array($detail)) {
455
                throw new ValidationException('detail', implode(' ', $detail));
456
            } else {
457
                $detail = array_unique($detail);
458
                foreach ($detail as $item) {
459
                    if (!$this->validator->validLocation($item)) {
460
                        throw new ValidationException('detail', $item);
461
                    }
462
                }
463
                $this->filters['filter[detail]'] = implode(',', $detail);
464
            }
465
        }
466
467
        // Validate $entry
468
        // @todo details required
469
470
        // Validate $from;
471 1
        if (!empty($from)) {
472
            if (!$this->validator->validFrom($from, $to)) {
473
                throw new ValidationException('from', $from . '-' . $to);
474
            } else {
475
                $this->filters['filter[from]'] = $from;
476
            }
477
        }
478
479
        // Validate $location
480 1
        if (!empty($location)) {
481
            if (!is_array($location)) {
482
                throw new ValidationException('location', implode(' ', $title));
483
            } else {
484
                $location = array_unique($location);
485
                foreach ($location as $item) {
486
                    if (!$this->validator->validLocation($item)) {
487
                        throw new ValidationException('location', $item);
488
                    }
489
                }
490
                $this->filters['filter[location]'] = implode(',', $location);
491
            }
492
        }
493
494
        // Validate $tags.
495 1
        if (!empty($tags)) {
496
            if (!is_array($tags)) {
497
                throw new ValidationException('tags', implode(' ', $tags));
498
            } else {
499
                $tags = array_unique($tags);
500
                foreach ($tags as $tag) {
501
                    if (!empty($tag) && !$this->validator->validTag($tag)) {
502
                        throw new ValidationException('tag', $tag);
503
                    }
504
                }
505
            }
506
            $this->filters['filter[tag]'] = implode(',', $tags);
507
        }
508
509
        // Validate $title;
510 1
        if (!empty($title)) {
511
            if (!is_array($title)) {
512
                throw new ValidationException('title', implode(' ', $title));
513
            } else {
514
                $title = array_unique($title);
515
                foreach ($title as $item) {
516
                    if (!$this->validator->validTitle($item)) {
517
                        throw new ValidationException('title', $item);
518
                    }
519
                }
520
                $this->filters['filter[title]'] = implode(',', $title);
521
            }
522
        }
523
524
        // Validate $to;
525 1
        if (!empty($to)) {
526
            if (!$this->validator->validTo($to, $from)) {
527
                throw new ValidationException('to', $to . '-' . $from);
528
            } else {
529
                $this->filters['filter[to]'] = $to;
530
            }
531
        }
532
533
        // Validate $includeTickets;
534 1
        if (!$this->validator->validInclude($includeLocation)) {
535
            throw new ValidationException('includeLocation', $includeLocation);
536
        }
537 1
        if ($includeLocation) {
538
            array_push($this->includes, 'location');
539
        }
540
541
        // Validate $includeTickets;
542 1
        if (!$this->validator->validInclude($includeTickets)) {
543
            throw new ValidationException('includeTickets', $includeTickets);
544
        }
545
546 1
        if ($includeTickets) {
547
            array_push($this->includes, 'tickets');
548
        }
549
550
        // Validate $includeTicketsEvents;
551 1
        if (!$this->validator->validInclude($includeTicketsEvents)) {
552
            throw new ValidationException('includeTicketsEvents', $includeTicketsEvents);
553
        }
554
555 1
        if ($includeTicketsEvents) {
556
            array_push($this->includes, 'tickets.events');
557
        }
558
559
        // Validate $includeTicketsClassPasses;
560 1
        if (!$this->validator->validInclude($includeTicketsClassPasses)) {
561
            throw new ValidationException('includeTicketsClassPasses', $includeTicketsClassPasses);
562
        }
563
564 1
        if ($includeTicketsClassPasses) {
565
            array_push($this->includes, 'tickets.class_passes');
566
        }
567
568 1
        $events = $this->client->events()->list(array_merge($this->filters, ['include' => implode(',', $this->includes)]));
569
570 1
        foreach ($events->data as $event) {
571
572 1
            $eventTickets = [];
573 1
            foreach ($event->tickets as $ticket) {
574 1
                array_push($eventTickets, new Ticket(
575 1
                    $ticket->available,
576 1
                    $ticket->availableFrom,
577 1
                    $ticket->availableTo,
578 1
                    $ticket->builtBasketUrl,
579 1
                    $ticket->builtBasketIframeUrl,
580 1
                    $ticket->cost,
581 1
                    $ticket->courseTicket,
582 1
                    $ticket->details,
583 1
                    $ticket->groupTicket,
584 1
                    $ticket->groupMin,
585 1
                    $ticket->groupMax,
586 1
                    $ticket->id,
587 1
                    $ticket->numberIssued,
588 1
                    $ticket->numberTaken,
589 1
                    $ticket->title
590 1
                ));
591
            }
592
593 1
            array_push($this->events, new Event(
594 1
                $event->allDay,
595 1
                $event->attachments,
596 1
                $event->attendeeCount,
597 1
                $event->attendeeLimit,
598 1
                $event->details,
599 1
                $event->endAt,
600 1
                $event->id,
601 1
                new Location(
602 1
                    $event->location->additionalInfo,
603 1
                    $event->location->addressText,
604 1
                    $event->location->id,
605 1
                    $event->location->latitude,
606 1
                    $event->location->longitude,
607 1
                    $event->location->mapUrl,
608 1
                    $event->location->zoom
609 1
                ),
610 1
                $event->maxTicketsPerBooking,
611 1
                $event->startAt,
612 1
                $eventTickets,
613 1
                $event->title,
614 1
                $event->waitingList
615 1
            ));
616
        }
617
618 1
        return $this->events;
619
    }
620
621
    /*
622
     *
623
     * {@inheritDoc}
624
     * @see \InShore\Bookwhen\Interfaces\ClientInterface::getLocation()
625
     */
626 1
    public function location(string $locationId): Location
627
    {
628
629 1
        if (!$this->validator->validId($locationId, 'location')) {
630
            throw new ValidationException('locationId', $locationId);
631
        }
632
633 1
        $location = $this->client->locations()->retrieve($locationId);
634
635 1
        return $this->location = new Location(
636 1
            $location->additionalInfo,
637 1
            $location->addressText,
638 1
            $location->id,
639 1
            $location->latitude,
640 1
            $location->longitude,
641 1
            $location->mapUrl,
642 1
            $location->zoom
643 1
        );
644
    }
645
646
    /**
647
     *
648
     */
649 1
    public function locations(
650
        null | string $addressText = null,
651
        null | string $additionalInfo = null
652
    ): array {
653
654
        // $this->logger->debug(__METHOD__ . '(' . var_export(func_get_args(), true) . ')');
655
656 1
        if (!empty($additionalInfo)) {
657
            if (!$this->validator->validAdditionalInfo($additionalInfo, 'additionalInfo')) {
658
                throw new ValidationException('additionalInfo', $additionalInfo);
659
            }
660
            $this->filters['filter[additional_info]'] = $additionalInfo;
661
        }
662
663 1
        if (!empty($addressText)) {
664
            if (!$this->validator->validAddressText($addressText, 'addressText')) {
665
                throw new ValidationException('addressText', $addressText);
666
            }
667
            $this->filters['filter[address_text]'] = $addressText;
668
        }
669
670 1
        $locations = $this->client->locations()->list($this->filters);
671
672 1
        foreach ($locations->data as $location) {
673 1
            array_push($this->locations, new Location(
674 1
                $location->additionalInfo,
675 1
                $location->addressText,
676 1
                $location->id,
677 1
                $location->latitude,
678 1
                $location->longitude,
679 1
                $location->mapUrl,
680 1
                $location->zoom
681 1
            ));
682
        }
683
684 1
        return $this->locations;
685
686
    }
687
688
//     /**
689
//      * Set Debug.
690
//      * @deprecated
691
//      */
692
//     public function setLogging($level)
693
//     {
694
//         $this->logLevel = $level;
695
//     }
696
697
    /**
698
     * {@inheritDoc}
699
     * @see \InShore\Bookwhen\Interfaces\BookWhenInterface::ticket()
700
     * class_passes
701
     */
702 1
    public function ticket(
703
        string $ticketId,
704
        bool $includeClassPasses = false,
705
        bool $includeEvents = false,
706
        bool $includeEventsAttachments = false,
707
        bool $includeEventsLocation = false,
708
        bool $includeEventsTickets = false
709
    ): Ticket {
710
711
        // ticketId
712 1
        if (!$this->validator->validId($ticketId, 'ticket')) {
713
            throw new ValidationException('ticketId', $ticketId);
714
        }
715
716
        // Validate $includeClassPasses;
717 1
        if (!$this->validator->validInclude($includeClassPasses)) {
718
            throw new ValidationException('includeClassPasses', $includeClassPasses);
719
        }
720
721 1
        if ($includeClassPasses) {
722
            array_push($this->includes, 'class_passes');
723
        }
724
725
        // Validate $includeEvents;
726 1
        if (!$this->validator->validInclude($includeEvents)) {
727
            throw new ValidationException('includeEvents', $includeEvents);
728
        }
729 1
        if ($includeEvents) {
730
            array_push($this->includes, 'events');
731
        }
732
733
        // Validate $includeAttachments;
734 1
        if (!$this->validator->validInclude($includeEventsAttachments)) {
735
            throw new ValidationException('includeEventssAttachments', $includeEventsAttachments);
736
        }
737 1
        if ($includeEventsAttachments) {
738
            array_push($this->includes, 'events.attachments');
739
        }
740
741
        // Validate $includeEventsLocation;
742 1
        if (!$this->validator->validInclude($includeEventsLocation)) {
743
            throw new ValidationException('includeEventsLocation', $includeEventsLocation);
744
        }
745 1
        if ($includeEventsLocation) {
746
            array_push($this->includes, 'events.location');
747
        }
748
749
        // Validate $includeEventsTickets;
750 1
        if (!$this->validator->validInclude($includeEventsTickets)) {
751
            throw new ValidationException('includeEventsTickets', $includeEventsTickets);
752
        }
753 1
        if ($includeEventsTickets) {
754
            array_push($this->includes, 'events.tickets');
755
        }
756
757 1
        $ticket = $this->client->tickets()->retrieve($ticketId);
758 1
        return $this->ticket = new Ticket(
759 1
            $ticket->available,
760 1
            $ticket->availableFrom,
761 1
            $ticket->availableTo,
762 1
            $ticket->builtBasketUrl,
763 1
            $ticket->builtBasketIframeUrl,
764 1
            $ticket->cost,
765 1
            $ticket->courseTicket,
766 1
            $ticket->details,
767 1
            $ticket->groupTicket,
768 1
            $ticket->groupMin,
769 1
            $ticket->groupMax,
770 1
            $ticket->id,
771 1
            $ticket->numberIssued,
772 1
            $ticket->numberTaken,
773 1
            $ticket->title
774 1
        );
775
    }
776
777
    /**
778
     * {@inheritDoc}
779
     * @see \InShore\Bookwhen\Interfaces\BookWhenInterface::tickets()
780
     * @todo includes
781
     */
782 1
    public function tickets(
783
        string $eventId,
784
        bool $includeClassPasses = false,
785
        bool $includeEvents = false,
786
        bool $includeEventsAttachments = false,
787
        bool $includeEventsLocation = false,
788
        bool $includeEventsTickets = false
789
    ): array {
790
791
        // $this->logger->debug(__METHOD__ . '(' . var_export(func_get_args(), true) . ')');
792
793 1
        if (!$this->validator->validId($eventId, 'event')) {
794
            throw new ValidationException('eventId', $eventId);
795
        }
796
797
        // Validate $includeClassPasses;
798 1
        if (!$this->validator->validInclude($includeClassPasses)) {
799
            throw new ValidationException('includeClassPasses', $includeClassPasses);
800
        }
801
802 1
        if ($includeClassPasses) {
803
            array_push($this->includes, 'class_passes');
804
        }
805
806
        // Validate $includeEvents;
807 1
        if (!$this->validator->validInclude($includeEvents)) {
808
            throw new ValidationException('includeEvents', $includeEvents);
809
        }
810
811 1
        if ($includeEvents) {
812
            array_push($this->includes, 'events');
813
        }
814
815
        // Validate $includeAttachments;
816 1
        if (!$this->validator->validInclude($includeEventsAttachments)) {
817
            throw new ValidationException('includeEventssAttachments', $includeEventsAttachments);
818
        }
819
820 1
        if ($includeEventsAttachments) {
821
            array_push($this->includes, 'events.attachments');
822
        }
823
824
        // Validate $includeEventsLocation;
825 1
        if (!$this->validator->validInclude($includeEventsLocation)) {
826
            throw new ValidationException('includeEventsLocation', $includeEventsLocation);
827
        }
828
829 1
        if ($includeEventsLocation) {
830
            array_push($this->includes, 'events.location');
831
        }
832
833
        // Validate $includeEventsTickets;
834 1
        if (!$this->validator->validInclude($includeEventsTickets)) {
835
            throw new ValidationException('includeEventsTickets', $includeEventsTickets);
836
        }
837
838 1
        if ($includeEventsTickets) {
839
            array_push($this->includes, 'events.tickets');
840
        }
841
842 1
        $tickets = $this->client->tickets()->list(array_merge(['event_id' => $eventId], ['include' => implode(',', $this->includes)]));
843
844 1
        foreach ($tickets->data as $ticket) {
845 1
            array_push($this->tickets, new Ticket(
846 1
                $ticket->available,
847 1
                $ticket->availableFrom,
848 1
                $ticket->availableTo,
849 1
                $ticket->builtBasketUrl,
850 1
                $ticket->builtBasketIframeUrl,
851 1
                $ticket->cost,
852 1
                $ticket->courseTicket,
853 1
                $ticket->details,
854 1
                $ticket->groupTicket,
855 1
                $ticket->groupMin,
856 1
                $ticket->groupMax,
857 1
                $ticket->id,
858 1
                $ticket->numberIssued,
859 1
                $ticket->numberTaken,
860 1
                $ticket->title
861 1
            ));
862
        }
863
864 1
        return $this->tickets;
865
866
    }
867
}
868