1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace EventEspresso\core\domain\services\admin\events\editor; |
4
|
|
|
|
5
|
|
|
use DomainException; |
6
|
|
|
use EE_Admin_Config; |
7
|
|
|
use EE_Error; |
8
|
|
|
use EE_Event; |
9
|
|
|
use EEM_Datetime; |
10
|
|
|
use EE_Datetime; |
11
|
|
|
use EEM_Price; |
12
|
|
|
use EEM_Price_Type; |
13
|
|
|
use EEM_Ticket; |
14
|
|
|
use EEM_Venue; |
15
|
|
|
use EEH_DTT_Helper; |
16
|
|
|
use EventEspresso\core\domain\services\assets\EspressoEditorAssetManager; |
17
|
|
|
use EventEspresso\core\exceptions\InvalidDataTypeException; |
18
|
|
|
use EventEspresso\core\exceptions\InvalidInterfaceException; |
19
|
|
|
use EventEspresso\core\exceptions\ModelConfigurationException; |
20
|
|
|
use EventEspresso\core\exceptions\UnexpectedEntityException; |
21
|
|
|
use InvalidArgumentException; |
22
|
|
|
use ReflectionException; |
23
|
|
|
use WP_Post; |
24
|
|
|
use WPGraphQL\Router; |
25
|
|
|
use GraphQLRelay\Relay; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Class AdvancedEditorData |
29
|
|
|
* Description |
30
|
|
|
* |
31
|
|
|
* @package EventEspresso\core\domain\services\admin\events\editor |
32
|
|
|
* @author Brent Christensen |
33
|
|
|
* @since $VID:$ |
34
|
|
|
*/ |
35
|
|
|
class AdvancedEditorData |
36
|
|
|
{ |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @var string $namespace The graphql namespace/prefix. |
40
|
|
|
*/ |
41
|
|
|
protected $namespace = 'Espresso'; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @var EE_Event |
45
|
|
|
*/ |
46
|
|
|
protected $event; |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @var EE_Admin_Config |
50
|
|
|
*/ |
51
|
|
|
protected $admin_config; |
52
|
|
|
/** |
53
|
|
|
* @var EEM_Datetime $datetime_model |
54
|
|
|
*/ |
55
|
|
|
protected $datetime_model; |
56
|
|
|
/** |
57
|
|
|
* @var EEM_Price $price_model |
58
|
|
|
*/ |
59
|
|
|
protected $price_model; |
60
|
|
|
/** |
61
|
|
|
* @var EEM_Ticket $ticket_model |
62
|
|
|
*/ |
63
|
|
|
protected $ticket_model; |
64
|
|
|
|
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* AdvancedEditorAdminForm constructor. |
68
|
|
|
* |
69
|
|
|
* @param EE_Event $event |
70
|
|
|
* @param EE_Admin_Config $admin_config |
71
|
|
|
* @param EEM_Datetime $datetime_model |
72
|
|
|
* @param EEM_Price $price_model |
73
|
|
|
* @param EEM_Ticket $ticket_model |
74
|
|
|
*/ |
75
|
|
|
public function __construct( |
76
|
|
|
EE_Event $event, |
77
|
|
|
EE_Admin_Config $admin_config, |
78
|
|
|
EEM_Datetime $datetime_model, |
79
|
|
|
EEM_Price $price_model, |
80
|
|
|
EEM_Ticket $ticket_model |
81
|
|
|
) { |
82
|
|
|
$this->event = $event; |
83
|
|
|
$this->admin_config = $admin_config; |
84
|
|
|
$this->datetime_model = $datetime_model; |
85
|
|
|
$this->price_model = $price_model; |
86
|
|
|
$this->ticket_model = $ticket_model; |
87
|
|
|
add_action('admin_enqueue_scripts', [$this, 'loadScriptsStyles']); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* @throws EE_Error |
93
|
|
|
* @throws InvalidArgumentException |
94
|
|
|
* @throws InvalidDataTypeException |
95
|
|
|
* @throws InvalidInterfaceException |
96
|
|
|
* @throws ModelConfigurationException |
97
|
|
|
* @throws ReflectionException |
98
|
|
|
* @throws UnexpectedEntityException |
99
|
|
|
* @throws DomainException |
100
|
|
|
* @since $VID:$ |
101
|
|
|
*/ |
102
|
|
|
public function loadScriptsStyles() |
103
|
|
|
{ |
104
|
|
|
if ($this->admin_config->useAdvancedEditor()) { |
105
|
|
|
$eventId = $this->event instanceof EE_Event ? $this->event->ID() : 0; |
106
|
|
|
if (! $eventId) { |
107
|
|
|
global $post; |
108
|
|
|
$eventId = isset($_REQUEST['post']) ? absint($_REQUEST['post']) : 0; |
109
|
|
|
$eventId = $eventId === 0 && $post instanceof WP_Post && $post->post_type === 'espresso_events' |
|
|
|
|
110
|
|
|
? $post->ID |
111
|
|
|
: $eventId; |
112
|
|
|
} |
113
|
|
|
if ($eventId) { |
114
|
|
|
$data = $this->getEditorData($eventId); |
115
|
|
|
$data = wp_json_encode($data); |
116
|
|
|
add_action( |
117
|
|
|
'admin_footer', |
118
|
|
|
static function () use ($data) { |
119
|
|
|
wp_add_inline_script( |
120
|
|
|
EspressoEditorAssetManager::JS_HANDLE_EDITOR, |
121
|
|
|
" |
122
|
|
|
var eeEditorData={$data}; |
123
|
|
|
", |
124
|
|
|
'before' |
125
|
|
|
); |
126
|
|
|
} |
127
|
|
|
); |
128
|
|
|
} |
129
|
|
|
} |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
|
133
|
|
|
/** |
134
|
|
|
* @param int $eventId |
135
|
|
|
* @return array |
136
|
|
|
* @throws EE_Error |
137
|
|
|
* @throws InvalidDataTypeException |
138
|
|
|
* @throws InvalidInterfaceException |
139
|
|
|
* @throws ModelConfigurationException |
140
|
|
|
* @throws UnexpectedEntityException |
141
|
|
|
* @throws InvalidArgumentException |
142
|
|
|
* @throws ReflectionException |
143
|
|
|
* @throws DomainException |
144
|
|
|
* @since $VID:$ |
145
|
|
|
*/ |
146
|
|
|
protected function getEditorData($eventId) |
147
|
|
|
{ |
148
|
|
|
$event = $this->getEventGraphQLData($eventId); |
149
|
|
|
$event['dbId'] = $eventId; |
150
|
|
|
|
151
|
|
|
$graphqlEndpoint = class_exists('WPGraphQL') ? trailingslashit(site_url()) . Router::$route : ''; |
152
|
|
|
$graphqlEndpoint = esc_url($graphqlEndpoint); |
153
|
|
|
|
154
|
|
|
$currentUser = $this->getGraphQLCurrentUser(); |
155
|
|
|
|
156
|
|
|
$generalSettings = $this->getGraphQLGeneralSettings(); |
157
|
|
|
|
158
|
|
|
$i18n = self::getJedLocaleData('event_espresso'); |
159
|
|
|
|
160
|
|
|
$assetsUrl = EE_PLUGIN_DIR_URL . 'assets/dist/'; |
161
|
|
|
|
162
|
|
|
return compact('event', 'graphqlEndpoint', 'currentUser', 'generalSettings', 'i18n', 'assetsUrl'); |
163
|
|
|
} |
164
|
|
|
|
165
|
|
|
|
166
|
|
|
/** |
167
|
|
|
* @param int $eventId |
168
|
|
|
* @return array |
169
|
|
|
* @since $VID:$ |
170
|
|
|
*/ |
171
|
|
|
protected function getEventGraphQLData($eventId) |
172
|
|
|
{ |
173
|
|
|
$datetimes = $this->getGraphQLDatetimes($eventId); |
174
|
|
|
|
175
|
|
|
// Avoid undefined variable warning in PHP >= 7.3 |
176
|
|
|
$tickets = null; |
177
|
|
|
$prices = null; |
178
|
|
|
|
179
|
|
|
if (empty($datetimes['nodes']) || (isset($_REQUEST['action']) && $_REQUEST['action'] === 'create_new')) { |
180
|
|
|
$this->addDefaultEntities($eventId); |
181
|
|
|
$datetimes = $this->getGraphQLDatetimes($eventId); |
182
|
|
|
} |
183
|
|
|
|
184
|
|
|
if (! empty($datetimes['nodes'])) { |
185
|
|
|
$datetimeIn = wp_list_pluck($datetimes['nodes'], 'id'); |
186
|
|
|
|
187
|
|
|
if (! empty($datetimeIn)) { |
188
|
|
|
$tickets = $this->getGraphQLTickets($datetimeIn); |
189
|
|
|
} |
190
|
|
|
} |
191
|
|
|
|
192
|
|
|
if (! empty($tickets['nodes'])) { |
193
|
|
|
$ticketIn = wp_list_pluck($tickets['nodes'], 'id'); |
194
|
|
|
|
195
|
|
|
if (! empty($ticketIn)) { |
196
|
|
|
$prices = $this->getGraphQLPrices($ticketIn); |
197
|
|
|
} |
198
|
|
|
} |
199
|
|
|
|
200
|
|
|
$priceTypes = $this->getGraphQLPriceTypes(); |
201
|
|
|
|
202
|
|
|
$relations = $this->getRelationalData($eventId); |
203
|
|
|
|
204
|
|
|
return compact('datetimes', 'tickets', 'prices', 'priceTypes', 'relations'); |
205
|
|
|
} |
206
|
|
|
|
207
|
|
|
/** |
208
|
|
|
* @param int $eventId |
209
|
|
|
* @throws DomainException |
210
|
|
|
* @throws EE_Error |
211
|
|
|
* @throws InvalidArgumentException |
212
|
|
|
* @throws InvalidDataTypeException |
213
|
|
|
* @throws InvalidInterfaceException |
214
|
|
|
* @throws ModelConfigurationException |
215
|
|
|
* @throws ReflectionException |
216
|
|
|
* @throws UnexpectedEntityException |
217
|
|
|
* @since $VID:$ |
218
|
|
|
*/ |
219
|
|
|
protected function addDefaultEntities($eventId) |
220
|
|
|
{ |
221
|
|
|
$default_dates = $this->datetime_model->create_new_blank_datetime(); |
222
|
|
|
if (is_array($default_dates) && isset($default_dates[0]) && $default_dates[0] instanceof EE_Datetime) { |
223
|
|
|
$default_date = $default_dates[0]; |
224
|
|
|
$default_date->save(); |
225
|
|
|
$default_date->_add_relation_to($eventId, 'Event'); |
226
|
|
|
$default_tickets = $this->ticket_model->get_all_default_tickets(); |
227
|
|
|
$default_prices = $this->price_model->get_all_default_prices(); |
228
|
|
|
foreach ($default_tickets as $default_ticket) { |
229
|
|
|
$default_ticket->save(); |
230
|
|
|
$default_ticket->_add_relation_to($default_date, 'Datetime'); |
231
|
|
|
foreach ($default_prices as $default_price) { |
|
|
|
|
232
|
|
|
$default_price->save(); |
233
|
|
|
$default_price->_add_relation_to($default_ticket, 'Ticket'); |
234
|
|
|
} |
235
|
|
|
} |
236
|
|
|
} |
237
|
|
|
} |
238
|
|
|
|
239
|
|
|
|
240
|
|
|
/** |
241
|
|
|
* @param int $eventId |
242
|
|
|
* @return array|null |
243
|
|
|
* @since $VID:$ |
244
|
|
|
*/ |
245
|
|
View Code Duplication |
protected function getGraphQLDatetimes($eventId) |
246
|
|
|
{ |
247
|
|
|
$field_key = lcfirst($this->namespace) . 'Datetimes'; |
248
|
|
|
$query = <<<QUERY |
249
|
|
|
query GET_DATETIMES(\$where: {$this->namespace}RootQueryDatetimesConnectionWhereArgs, \$first: Int, \$last: Int ) { |
250
|
|
|
{$field_key}(where: \$where, first: \$first, last: \$last) { |
251
|
|
|
nodes { |
252
|
|
|
id |
253
|
|
|
dbId |
254
|
|
|
cacheId |
255
|
|
|
capacity |
256
|
|
|
description |
257
|
|
|
endDate |
258
|
|
|
isActive |
259
|
|
|
isExpired |
260
|
|
|
isPrimary |
261
|
|
|
isSoldOut |
262
|
|
|
isTrashed |
263
|
|
|
isUpcoming |
264
|
|
|
length |
265
|
|
|
name |
266
|
|
|
order |
267
|
|
|
reserved |
268
|
|
|
sold |
269
|
|
|
status |
270
|
|
|
startDate |
271
|
|
|
__typename |
272
|
|
|
} |
273
|
|
|
__typename |
274
|
|
|
} |
275
|
|
|
} |
276
|
|
|
QUERY; |
277
|
|
|
$data = [ |
278
|
|
|
'operation_name' => 'GET_DATETIMES', |
279
|
|
|
'variables' => [ |
280
|
|
|
'first' => 100, |
281
|
|
|
'where' => [ |
282
|
|
|
'eventId' => $eventId, |
283
|
|
|
], |
284
|
|
|
], |
285
|
|
|
'query' => $query, |
286
|
|
|
]; |
287
|
|
|
|
288
|
|
|
$responseData = $this->makeGraphQLRequest($data); |
289
|
|
|
return !empty($responseData[ $field_key ]) ? $responseData[ $field_key ] : null; |
290
|
|
|
} |
291
|
|
|
|
292
|
|
|
|
293
|
|
|
/** |
294
|
|
|
* @param array $datetimeIn |
295
|
|
|
* @return array|null |
296
|
|
|
* @since $VID:$ |
297
|
|
|
*/ |
298
|
|
View Code Duplication |
protected function getGraphQLTickets(array $datetimeIn) |
299
|
|
|
{ |
300
|
|
|
$field_key = lcfirst($this->namespace) . 'Tickets'; |
301
|
|
|
$query = <<<QUERY |
302
|
|
|
query GET_TICKETS(\$where: {$this->namespace}RootQueryTicketsConnectionWhereArgs, \$first: Int, \$last: Int ) { |
303
|
|
|
{$field_key}(where: \$where, first: \$first, last: \$last) { |
304
|
|
|
nodes { |
305
|
|
|
id |
306
|
|
|
cacheId |
307
|
|
|
dbId |
308
|
|
|
description |
309
|
|
|
endDate |
310
|
|
|
isDefault |
311
|
|
|
isExpired |
312
|
|
|
isFree |
313
|
|
|
isOnSale |
314
|
|
|
isPending |
315
|
|
|
isRequired |
316
|
|
|
isSoldOut |
317
|
|
|
isTaxable |
318
|
|
|
isTrashed |
319
|
|
|
max |
320
|
|
|
min |
321
|
|
|
name |
322
|
|
|
order |
323
|
|
|
price |
324
|
|
|
quantity |
325
|
|
|
registrationCount |
326
|
|
|
reserved |
327
|
|
|
reverseCalculate |
328
|
|
|
sold |
329
|
|
|
startDate |
330
|
|
|
uses |
331
|
|
|
__typename |
332
|
|
|
} |
333
|
|
|
__typename |
334
|
|
|
} |
335
|
|
|
} |
336
|
|
|
QUERY; |
337
|
|
|
$data = [ |
338
|
|
|
'operation_name' => 'GET_TICKETS', |
339
|
|
|
'variables' => [ |
340
|
|
|
'first' => 100, |
341
|
|
|
'where' => [ |
342
|
|
|
'datetimeIn' => $datetimeIn, |
343
|
|
|
], |
344
|
|
|
], |
345
|
|
|
'query' => $query, |
346
|
|
|
]; |
347
|
|
|
|
348
|
|
|
$responseData = $this->makeGraphQLRequest($data); |
349
|
|
|
return !empty($responseData[ $field_key ]) ? $responseData[ $field_key ] : null; |
350
|
|
|
} |
351
|
|
|
|
352
|
|
|
|
353
|
|
|
/** |
354
|
|
|
* @param array $ticketIn |
355
|
|
|
* @return array|null |
356
|
|
|
* @since $VID:$ |
357
|
|
|
*/ |
358
|
|
View Code Duplication |
protected function getGraphQLPrices(array $ticketIn) |
359
|
|
|
{ |
360
|
|
|
$field_key = lcfirst($this->namespace) . 'Prices'; |
361
|
|
|
$query = <<<QUERY |
362
|
|
|
query GET_PRICES(\$where: {$this->namespace}RootQueryPricesConnectionWhereArgs, \$first: Int, \$last: Int ) { |
363
|
|
|
{$field_key}(where: \$where, first: \$first, last: \$last) { |
364
|
|
|
nodes { |
365
|
|
|
id |
366
|
|
|
dbId |
367
|
|
|
amount |
368
|
|
|
cacheId |
369
|
|
|
desc |
370
|
|
|
isBasePrice |
371
|
|
|
isDefault |
372
|
|
|
isDiscount |
373
|
|
|
isPercent |
374
|
|
|
isTax |
375
|
|
|
isTrashed |
376
|
|
|
name |
377
|
|
|
order |
378
|
|
|
overrides |
379
|
|
|
__typename |
380
|
|
|
} |
381
|
|
|
__typename |
382
|
|
|
} |
383
|
|
|
} |
384
|
|
|
QUERY; |
385
|
|
|
$data = [ |
386
|
|
|
'operation_name' => 'GET_PRICES', |
387
|
|
|
'variables' => [ |
388
|
|
|
'first' => 100, |
389
|
|
|
'where' => [ |
390
|
|
|
'ticketIn' => $ticketIn, |
391
|
|
|
], |
392
|
|
|
], |
393
|
|
|
'query' => $query, |
394
|
|
|
]; |
395
|
|
|
|
396
|
|
|
$responseData = $this->makeGraphQLRequest($data); |
397
|
|
|
return !empty($responseData[ $field_key ]) ? $responseData[ $field_key ] : null; |
398
|
|
|
} |
399
|
|
|
|
400
|
|
|
|
401
|
|
|
/** |
402
|
|
|
* @return array|null |
403
|
|
|
* @since $VID:$ |
404
|
|
|
*/ |
405
|
|
|
protected function getGraphQLPriceTypes() |
406
|
|
|
{ |
407
|
|
|
$field_key = lcfirst($this->namespace) . 'PriceTypes'; |
408
|
|
|
$query = <<<QUERY |
409
|
|
|
query GET_PRICE_TYPES(\$first: Int, \$last: Int ) { |
410
|
|
|
{$field_key}(first: \$first, last: \$last) { |
411
|
|
|
nodes { |
412
|
|
|
id |
413
|
|
|
dbId |
414
|
|
|
baseType |
415
|
|
|
cacheId |
416
|
|
|
isBasePrice |
417
|
|
|
isDiscount |
418
|
|
|
isPercent |
419
|
|
|
isTax |
420
|
|
|
isTrashed |
421
|
|
|
name |
422
|
|
|
order |
423
|
|
|
__typename |
424
|
|
|
} |
425
|
|
|
__typename |
426
|
|
|
} |
427
|
|
|
} |
428
|
|
|
QUERY; |
429
|
|
|
$data = [ |
430
|
|
|
'operation_name' => 'GET_PRICE_TYPES', |
431
|
|
|
'variables' => [ |
432
|
|
|
'first' => 100, |
433
|
|
|
], |
434
|
|
|
'query' => $query, |
435
|
|
|
]; |
436
|
|
|
|
437
|
|
|
$responseData = $this->makeGraphQLRequest($data); |
438
|
|
|
return !empty($responseData[ $field_key ]) ? $responseData[ $field_key ] : null; |
439
|
|
|
} |
440
|
|
|
|
441
|
|
|
|
442
|
|
|
/** |
443
|
|
|
* @return array|null |
444
|
|
|
* @since $VID:$ |
445
|
|
|
*/ |
446
|
|
View Code Duplication |
protected function getGraphQLCurrentUser() |
447
|
|
|
{ |
448
|
|
|
$field_key = 'viewer'; |
449
|
|
|
$query = <<<QUERY |
450
|
|
|
query GET_CURRENT_USER { |
451
|
|
|
{$field_key} { |
452
|
|
|
description |
453
|
|
|
email |
454
|
|
|
firstName |
455
|
|
|
id |
456
|
|
|
name |
457
|
|
|
nicename |
458
|
|
|
nickname |
459
|
|
|
lastName |
460
|
|
|
locale |
461
|
|
|
userId |
462
|
|
|
username |
463
|
|
|
__typename |
464
|
|
|
} |
465
|
|
|
} |
466
|
|
|
QUERY; |
467
|
|
|
$data = [ |
468
|
|
|
'operation_name' => 'GET_CURRENT_USER', |
469
|
|
|
'query' => $query, |
470
|
|
|
]; |
471
|
|
|
|
472
|
|
|
$responseData = $this->makeGraphQLRequest($data); |
473
|
|
|
return !empty($responseData[ $field_key ]) ? $responseData[ $field_key ] : null; |
474
|
|
|
} |
475
|
|
|
|
476
|
|
|
|
477
|
|
|
/** |
478
|
|
|
* @return array|null |
479
|
|
|
* @since $VID:$ |
480
|
|
|
*/ |
481
|
|
View Code Duplication |
protected function getGraphQLGeneralSettings() |
482
|
|
|
{ |
483
|
|
|
$field_key = 'generalSettings'; |
484
|
|
|
$query = <<<QUERY |
485
|
|
|
query GET_GENERAL_SETTINGS { |
486
|
|
|
{$field_key} { |
487
|
|
|
dateFormat |
488
|
|
|
timeFormat |
489
|
|
|
timezone |
490
|
|
|
__typename |
491
|
|
|
} |
492
|
|
|
} |
493
|
|
|
QUERY; |
494
|
|
|
$data = [ |
495
|
|
|
'operation_name' => 'GET_CURRENT_USER', |
496
|
|
|
'query' => $query, |
497
|
|
|
]; |
498
|
|
|
|
499
|
|
|
$responseData = $this->makeGraphQLRequest($data); |
500
|
|
|
return !empty($responseData[ $field_key ]) ? $responseData[ $field_key ] : null; |
501
|
|
|
} |
502
|
|
|
|
503
|
|
|
|
504
|
|
|
/** |
505
|
|
|
* @param array $data |
506
|
|
|
* @return array |
507
|
|
|
* @since $VID:$ |
508
|
|
|
*/ |
509
|
|
|
protected function makeGraphQLRequest($data) |
510
|
|
|
{ |
511
|
|
|
try { |
512
|
|
|
$response = graphql($data); |
513
|
|
|
if (!empty($response['data'])) { |
514
|
|
|
return $response['data']; |
515
|
|
|
} |
516
|
|
|
return null; |
517
|
|
|
} catch (\Exception $e) { |
518
|
|
|
// do something with the errors thrown |
519
|
|
|
return null; |
520
|
|
|
} |
521
|
|
|
} |
522
|
|
|
|
523
|
|
|
|
524
|
|
|
/** |
525
|
|
|
* @param mixed $source The source that's passed down the GraphQL queries |
|
|
|
|
526
|
|
|
* @param array $args The inputArgs on the field |
|
|
|
|
527
|
|
|
* @param AppContext $context The AppContext passed down the GraphQL tree |
|
|
|
|
528
|
|
|
* @param ResolveInfo $info The ResolveInfo passed down the GraphQL tree |
|
|
|
|
529
|
|
|
* @return string |
530
|
|
|
* @throws EE_Error |
531
|
|
|
* @throws Exception |
532
|
|
|
* @throws InvalidArgumentException |
533
|
|
|
* @throws InvalidDataTypeException |
534
|
|
|
* @throws InvalidInterfaceException |
535
|
|
|
* @throws ReflectionException |
536
|
|
|
* @throws UserError |
537
|
|
|
* @throws UnexpectedEntityException |
538
|
|
|
* @since $VID:$ |
539
|
|
|
*/ |
540
|
|
|
public static function getRelationalData($eventId) |
541
|
|
|
{ |
542
|
|
|
$data = [ |
543
|
|
|
'datetimes' => [], |
544
|
|
|
'tickets' => [], |
545
|
|
|
'prices' => [], |
546
|
|
|
]; |
547
|
|
|
|
548
|
|
|
$eem_datetime = EEM_Datetime::instance(); |
549
|
|
|
$eem_ticket = EEM_Ticket::instance(); |
550
|
|
|
$eem_price = EEM_Price::instance(); |
551
|
|
|
$eem_price_type = EEM_Price_Type::instance(); |
552
|
|
|
|
553
|
|
|
// PROCESS DATETIMES |
554
|
|
|
$related_models = [ |
555
|
|
|
'tickets' => $eem_ticket, |
556
|
|
|
]; |
557
|
|
|
// Get the IDs of event datetimes. |
558
|
|
|
$datetimeIds = $eem_datetime->get_col([ |
559
|
|
|
[ |
560
|
|
|
'EVT_ID' => $eventId, |
561
|
|
|
], |
562
|
|
|
'default_where_conditions' => 'minimum', |
563
|
|
|
]); |
564
|
|
View Code Duplication |
foreach ($datetimeIds as $datetimeId) { |
565
|
|
|
$GID = self::convertToGlobalId($eem_datetime->item_name(), $datetimeId); |
566
|
|
|
foreach ($related_models as $key => $model) { |
567
|
|
|
// Get the IDs of related entities for the datetime ID. |
568
|
|
|
$Ids = $model->get_col([ |
569
|
|
|
[ |
570
|
|
|
'Datetime.DTT_ID' => $datetimeId, |
571
|
|
|
], |
572
|
|
|
'default_where_conditions' => 'minimum', |
573
|
|
|
]); |
574
|
|
|
$data['datetimes'][ $GID ][ $key ] = empty($Ids) ? [] : self::convertToGlobalId($model->item_name(), $Ids); |
575
|
|
|
} |
576
|
|
|
} |
577
|
|
|
|
578
|
|
|
// PROCESS TICKETS |
579
|
|
|
$related_models = [ |
580
|
|
|
'datetimes' => $eem_datetime, |
581
|
|
|
'prices' => $eem_price, |
582
|
|
|
]; |
583
|
|
|
// Get the IDs of all datetime tickets. |
584
|
|
|
$ticketIds = $eem_ticket->get_col([ |
585
|
|
|
[ |
586
|
|
|
'Datetime.DTT_ID' => ['IN', $datetimeIds], |
587
|
|
|
], |
588
|
|
|
'default_where_conditions' => 'minimum', |
589
|
|
|
]); |
590
|
|
View Code Duplication |
foreach ($ticketIds as $ticketId) { |
591
|
|
|
$GID = self::convertToGlobalId($eem_ticket->item_name(), $ticketId); |
592
|
|
|
|
593
|
|
|
foreach ($related_models as $key => $model) { |
594
|
|
|
// Get the IDs of related entities for the ticket ID. |
595
|
|
|
$Ids = $model->get_col([ |
596
|
|
|
[ |
597
|
|
|
'Ticket.TKT_ID' => $ticketId, |
598
|
|
|
], |
599
|
|
|
'default_where_conditions' => 'minimum', |
600
|
|
|
]); |
601
|
|
|
$data['tickets'][ $GID ][ $key ] = empty($Ids) ? [] : self::convertToGlobalId($model->item_name(), $Ids); |
602
|
|
|
} |
603
|
|
|
} |
604
|
|
|
|
605
|
|
|
// PROCESS PRICES |
606
|
|
|
$related_models = [ |
607
|
|
|
'tickets' => $eem_ticket, |
608
|
|
|
'priceTypes' => $eem_price_type, |
609
|
|
|
]; |
610
|
|
|
// Get the IDs of all ticket prices. |
611
|
|
|
$priceIds = $eem_price->get_col([['Ticket.TKT_ID' => ['IN', $ticketIds]]]); |
612
|
|
View Code Duplication |
foreach ($priceIds as $priceId) { |
613
|
|
|
$GID = self::convertToGlobalId($eem_price->item_name(), $priceId); |
614
|
|
|
|
615
|
|
|
foreach ($related_models as $key => $model) { |
616
|
|
|
// Get the IDs of related entities for the price ID. |
617
|
|
|
$Ids = $model->get_col([ |
618
|
|
|
[ |
619
|
|
|
'Price.PRC_ID' => $priceId, |
620
|
|
|
], |
621
|
|
|
'default_where_conditions' => 'minimum', |
622
|
|
|
]); |
623
|
|
|
$data['prices'][ $GID ][ $key ] = empty($Ids) ? [] : self::convertToGlobalId($model->item_name(), $Ids); |
624
|
|
|
} |
625
|
|
|
} |
626
|
|
|
|
627
|
|
|
return $data; |
628
|
|
|
} |
629
|
|
|
|
630
|
|
|
/** |
631
|
|
|
* Convert the DB ID into GID |
632
|
|
|
* |
633
|
|
|
* @param string $type |
634
|
|
|
* @param int|int[] $ID |
635
|
|
|
* @return mixed |
636
|
|
|
*/ |
637
|
|
|
public static function convertToGlobalId($type, $ID) |
638
|
|
|
{ |
639
|
|
|
if (is_array($ID)) { |
640
|
|
|
return array_map(function ($id) use ($type) { |
641
|
|
|
return self::convertToGlobalId($type, $id); |
642
|
|
|
}, $ID); |
643
|
|
|
} |
644
|
|
|
return Relay::toGlobalId($type, $ID); |
645
|
|
|
} |
646
|
|
|
|
647
|
|
|
|
648
|
|
|
/** |
649
|
|
|
* Returns Jed-formatted localization data. |
650
|
|
|
* |
651
|
|
|
* @param string $domain Translation domain. |
652
|
|
|
* @return array |
653
|
|
|
*/ |
654
|
|
View Code Duplication |
public static function getJedLocaleData($domain) |
655
|
|
|
{ |
656
|
|
|
$translations = get_translations_for_domain($domain); |
657
|
|
|
|
658
|
|
|
$locale = array( |
659
|
|
|
'' => array( |
660
|
|
|
'domain' => $domain, |
661
|
|
|
'lang' => is_admin() ? EEH_DTT_Helper::get_user_locale() : get_locale() |
662
|
|
|
), |
663
|
|
|
); |
664
|
|
|
|
665
|
|
|
if (! empty($translations->headers['Plural-Forms'])) { |
666
|
|
|
$locale['']['plural_forms'] = $translations->headers['Plural-Forms']; |
667
|
|
|
} |
668
|
|
|
|
669
|
|
|
foreach ($translations->entries as $msgid => $entry) { |
670
|
|
|
$locale[ $msgid ] = $entry->translations; |
671
|
|
|
} |
672
|
|
|
|
673
|
|
|
return $locale; |
674
|
|
|
} |
675
|
|
|
} |
676
|
|
|
|