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