Completed
Branch EDTR/master (85176e)
by
unknown
26:30 queued 17:48
created
core/domain/services/admin/events/editor/AdvancedEditorData.php 2 patches
Indentation   +488 added lines, -488 removed lines patch added patch discarded remove patch
@@ -35,223 +35,223 @@  discard block
 block discarded – undo
35 35
 class AdvancedEditorData
36 36
 {
37 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
-                            "
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 122
 var eeEditorData={$data};
123 123
 ",
124
-                            'before'
125
-                        );
126
-                    }
127
-                );
128
-                add_action(
129
-                    'admin_footer',
130
-                    static function () use ($data) {
131
-                        wp_add_inline_script(
132
-                            EspressoEditorAssetManager::JS_HANDLE_EDITOR_PROTOTYPE,
133
-                            "
124
+							'before'
125
+						);
126
+					}
127
+				);
128
+				add_action(
129
+					'admin_footer',
130
+					static function () use ($data) {
131
+						wp_add_inline_script(
132
+							EspressoEditorAssetManager::JS_HANDLE_EDITOR_PROTOTYPE,
133
+							"
134 134
 var eeEditorData={$data};
135 135
 ",
136
-                            'before'
137
-                        );
138
-                    }
139
-                );
140
-            }
141
-        }
142
-    }
143
-
144
-
145
-    /**
146
-     * @param int $eventId
147
-     * @return array
148
-     * @throws EE_Error
149
-     * @throws InvalidDataTypeException
150
-     * @throws InvalidInterfaceException
151
-     * @throws ModelConfigurationException
152
-     * @throws UnexpectedEntityException
153
-     * @throws InvalidArgumentException
154
-     * @throws ReflectionException
155
-     * @throws DomainException
156
-     * @since $VID:$
157
-     */
158
-    protected function getEditorData($eventId)
159
-    {
160
-        $event = $this->getEventGraphQLData($eventId);
161
-        $event['dbId'] = $eventId;
162
-
163
-        $graphqlEndpoint = class_exists('WPGraphQL') ? trailingslashit(site_url()) . Router::$route : '';
164
-        $graphqlEndpoint = esc_url($graphqlEndpoint);
165
-
166
-        $currentUser = $this->getGraphQLCurrentUser();
167
-
168
-        $generalSettings = $this->getGraphQLGeneralSettings();
169
-
170
-        $i18n = self::getJedLocaleData('event_espresso');
171
-
172
-        return compact('event', 'graphqlEndpoint', 'currentUser', 'generalSettings', 'i18n');
173
-    }
174
-
175
-
176
-    /**
177
-     * @param int $eventId
178
-     * @return array
179
-     * @since $VID:$
180
-     */
181
-    protected function getEventGraphQLData($eventId)
182
-    {
183
-        $datetimes = $this->getGraphQLDatetimes($eventId);
184
-
185
-        if (empty($datetimes['nodes']) || (isset($_REQUEST['action']) && $_REQUEST['action'] === 'create_new')) {
186
-            $this->addDefaultEntities($eventId);
187
-            $datetimes = $this->getGraphQLDatetimes($eventId);
188
-        }
189
-
190
-        if (! empty($datetimes['nodes'])) {
191
-            $datetimeIn = wp_list_pluck($datetimes['nodes'], 'id');
192
-
193
-            if (! empty($datetimeIn)) {
194
-                $tickets = $this->getGraphQLTickets($datetimeIn);
195
-            }
196
-        }
197
-
198
-        if (! empty($tickets['nodes'])) {
199
-            $ticketIn = wp_list_pluck($tickets['nodes'], 'id');
200
-
201
-            if (! empty($ticketIn)) {
202
-                $prices = $this->getGraphQLPrices($ticketIn);
203
-            }
204
-        }
205
-
206
-        $priceTypes = $this->getGraphQLPriceTypes();
207
-
208
-        $relations = $this->getRelationalData($eventId);
209
-
210
-        return compact('datetimes', 'tickets', 'prices', 'priceTypes', 'relations');
211
-    }
212
-
213
-    /**
214
-     * @param int $eventId
215
-     * @throws DomainException
216
-     * @throws EE_Error
217
-     * @throws InvalidArgumentException
218
-     * @throws InvalidDataTypeException
219
-     * @throws InvalidInterfaceException
220
-     * @throws ModelConfigurationException
221
-     * @throws ReflectionException
222
-     * @throws UnexpectedEntityException
223
-     * @since $VID:$
224
-     */
225
-    protected function addDefaultEntities($eventId)
226
-    {
227
-        $default_dates = $this->datetime_model->create_new_blank_datetime();
228
-        if (is_array($default_dates) && isset($default_dates[0]) && $default_dates[0] instanceof EE_Datetime) {
229
-            $default_date = $default_dates[0];
230
-            $default_date->save();
231
-            $default_date->_add_relation_to($eventId, 'Event');
232
-            $default_tickets = $this->ticket_model->get_all_default_tickets();
233
-            $default_prices = $this->price_model->get_all_default_prices();
234
-            foreach ($default_tickets as $default_ticket) {
235
-                $default_ticket->save();
236
-                $default_ticket->_add_relation_to($default_date, 'Datetime');
237
-                foreach ($default_prices as $default_price) {
238
-                    $default_price->save();
239
-                    $default_price->_add_relation_to($default_ticket, 'Ticket');
240
-                }
241
-            }
242
-        }
243
-    }
244
-
245
-
246
-    /**
247
-     * @param int $eventId
248
-     * @return array|null
249
-     * @since $VID:$
250
-     */
251
-    protected function getGraphQLDatetimes($eventId)
252
-    {
253
-        $field_key = lcfirst($this->namespace) . 'Datetimes';
254
-        $query = <<<QUERY
136
+							'before'
137
+						);
138
+					}
139
+				);
140
+			}
141
+		}
142
+	}
143
+
144
+
145
+	/**
146
+	 * @param int $eventId
147
+	 * @return array
148
+	 * @throws EE_Error
149
+	 * @throws InvalidDataTypeException
150
+	 * @throws InvalidInterfaceException
151
+	 * @throws ModelConfigurationException
152
+	 * @throws UnexpectedEntityException
153
+	 * @throws InvalidArgumentException
154
+	 * @throws ReflectionException
155
+	 * @throws DomainException
156
+	 * @since $VID:$
157
+	 */
158
+	protected function getEditorData($eventId)
159
+	{
160
+		$event = $this->getEventGraphQLData($eventId);
161
+		$event['dbId'] = $eventId;
162
+
163
+		$graphqlEndpoint = class_exists('WPGraphQL') ? trailingslashit(site_url()) . Router::$route : '';
164
+		$graphqlEndpoint = esc_url($graphqlEndpoint);
165
+
166
+		$currentUser = $this->getGraphQLCurrentUser();
167
+
168
+		$generalSettings = $this->getGraphQLGeneralSettings();
169
+
170
+		$i18n = self::getJedLocaleData('event_espresso');
171
+
172
+		return compact('event', 'graphqlEndpoint', 'currentUser', 'generalSettings', 'i18n');
173
+	}
174
+
175
+
176
+	/**
177
+	 * @param int $eventId
178
+	 * @return array
179
+	 * @since $VID:$
180
+	 */
181
+	protected function getEventGraphQLData($eventId)
182
+	{
183
+		$datetimes = $this->getGraphQLDatetimes($eventId);
184
+
185
+		if (empty($datetimes['nodes']) || (isset($_REQUEST['action']) && $_REQUEST['action'] === 'create_new')) {
186
+			$this->addDefaultEntities($eventId);
187
+			$datetimes = $this->getGraphQLDatetimes($eventId);
188
+		}
189
+
190
+		if (! empty($datetimes['nodes'])) {
191
+			$datetimeIn = wp_list_pluck($datetimes['nodes'], 'id');
192
+
193
+			if (! empty($datetimeIn)) {
194
+				$tickets = $this->getGraphQLTickets($datetimeIn);
195
+			}
196
+		}
197
+
198
+		if (! empty($tickets['nodes'])) {
199
+			$ticketIn = wp_list_pluck($tickets['nodes'], 'id');
200
+
201
+			if (! empty($ticketIn)) {
202
+				$prices = $this->getGraphQLPrices($ticketIn);
203
+			}
204
+		}
205
+
206
+		$priceTypes = $this->getGraphQLPriceTypes();
207
+
208
+		$relations = $this->getRelationalData($eventId);
209
+
210
+		return compact('datetimes', 'tickets', 'prices', 'priceTypes', 'relations');
211
+	}
212
+
213
+	/**
214
+	 * @param int $eventId
215
+	 * @throws DomainException
216
+	 * @throws EE_Error
217
+	 * @throws InvalidArgumentException
218
+	 * @throws InvalidDataTypeException
219
+	 * @throws InvalidInterfaceException
220
+	 * @throws ModelConfigurationException
221
+	 * @throws ReflectionException
222
+	 * @throws UnexpectedEntityException
223
+	 * @since $VID:$
224
+	 */
225
+	protected function addDefaultEntities($eventId)
226
+	{
227
+		$default_dates = $this->datetime_model->create_new_blank_datetime();
228
+		if (is_array($default_dates) && isset($default_dates[0]) && $default_dates[0] instanceof EE_Datetime) {
229
+			$default_date = $default_dates[0];
230
+			$default_date->save();
231
+			$default_date->_add_relation_to($eventId, 'Event');
232
+			$default_tickets = $this->ticket_model->get_all_default_tickets();
233
+			$default_prices = $this->price_model->get_all_default_prices();
234
+			foreach ($default_tickets as $default_ticket) {
235
+				$default_ticket->save();
236
+				$default_ticket->_add_relation_to($default_date, 'Datetime');
237
+				foreach ($default_prices as $default_price) {
238
+					$default_price->save();
239
+					$default_price->_add_relation_to($default_ticket, 'Ticket');
240
+				}
241
+			}
242
+		}
243
+	}
244
+
245
+
246
+	/**
247
+	 * @param int $eventId
248
+	 * @return array|null
249
+	 * @since $VID:$
250
+	 */
251
+	protected function getGraphQLDatetimes($eventId)
252
+	{
253
+		$field_key = lcfirst($this->namespace) . 'Datetimes';
254
+		$query = <<<QUERY
255 255
         query GET_DATETIMES(\$where: {$this->namespace}RootQueryDatetimesConnectionWhereArgs, \$first: Int, \$last: Int ) {
256 256
             {$field_key}(where: \$where, first: \$first, last: \$last) {
257 257
                 nodes {
@@ -279,31 +279,31 @@  discard block
 block discarded – undo
279 279
             }
280 280
         }
281 281
 QUERY;
282
-        $data = [
283
-            'operation_name' => 'GET_DATETIMES',
284
-            'variables' => [
285
-                'first' => 100,
286
-                'where' => [
287
-                    'eventId' => $eventId,
288
-                ],
289
-            ],
290
-            'query' => $query,
291
-        ];
292
-
293
-        $responseData = $this->makeGraphQLRequest($data);
294
-        return !empty($responseData[ $field_key ]) ? $responseData[ $field_key ] : null;
295
-    }
296
-
297
-
298
-    /**
299
-     * @param array $datetimeIn
300
-     * @return array|null
301
-     * @since $VID:$
302
-     */
303
-    protected function getGraphQLTickets(array $datetimeIn)
304
-    {
305
-        $field_key = lcfirst($this->namespace) . 'Tickets';
306
-        $query = <<<QUERY
282
+		$data = [
283
+			'operation_name' => 'GET_DATETIMES',
284
+			'variables' => [
285
+				'first' => 100,
286
+				'where' => [
287
+					'eventId' => $eventId,
288
+				],
289
+			],
290
+			'query' => $query,
291
+		];
292
+
293
+		$responseData = $this->makeGraphQLRequest($data);
294
+		return !empty($responseData[ $field_key ]) ? $responseData[ $field_key ] : null;
295
+	}
296
+
297
+
298
+	/**
299
+	 * @param array $datetimeIn
300
+	 * @return array|null
301
+	 * @since $VID:$
302
+	 */
303
+	protected function getGraphQLTickets(array $datetimeIn)
304
+	{
305
+		$field_key = lcfirst($this->namespace) . 'Tickets';
306
+		$query = <<<QUERY
307 307
         query GET_TICKETS(\$where: {$this->namespace}RootQueryTicketsConnectionWhereArgs, \$first: Int, \$last: Int ) {
308 308
             {$field_key}(where: \$where, first: \$first, last: \$last) {
309 309
                 nodes {
@@ -334,31 +334,31 @@  discard block
 block discarded – undo
334 334
             }
335 335
         }
336 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
-    protected function getGraphQLPrices(array $ticketIn)
359
-    {
360
-        $field_key = lcfirst($this->namespace) . 'Prices';
361
-        $query = <<<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
+	protected function getGraphQLPrices(array $ticketIn)
359
+	{
360
+		$field_key = lcfirst($this->namespace) . 'Prices';
361
+		$query = <<<QUERY
362 362
         query GET_PRICES(\$where: {$this->namespace}RootQueryPricesConnectionWhereArgs, \$first: Int, \$last: Int ) {
363 363
             {$field_key}(where: \$where, first: \$first, last: \$last) {
364 364
                 nodes {
@@ -381,30 +381,30 @@  discard block
 block discarded – undo
381 381
             }
382 382
         }
383 383
 QUERY;
384
-        $data = [
385
-            'operation_name' => 'GET_PRICES',
386
-            'variables' => [
387
-                'first' => 100,
388
-                'where' => [
389
-                    'ticketIn' => $ticketIn,
390
-                ],
391
-            ],
392
-            'query' => $query,
393
-        ];
394
-
395
-        $responseData = $this->makeGraphQLRequest($data);
396
-        return !empty($responseData[ $field_key ]) ? $responseData[ $field_key ] : null;
397
-    }
398
-
399
-
400
-    /**
401
-     * @return array|null
402
-     * @since $VID:$
403
-     */
404
-    protected function getGraphQLPriceTypes()
405
-    {
406
-        $field_key = lcfirst($this->namespace) . 'PriceTypes';
407
-        $query = <<<QUERY
384
+		$data = [
385
+			'operation_name' => 'GET_PRICES',
386
+			'variables' => [
387
+				'first' => 100,
388
+				'where' => [
389
+					'ticketIn' => $ticketIn,
390
+				],
391
+			],
392
+			'query' => $query,
393
+		];
394
+
395
+		$responseData = $this->makeGraphQLRequest($data);
396
+		return !empty($responseData[ $field_key ]) ? $responseData[ $field_key ] : null;
397
+	}
398
+
399
+
400
+	/**
401
+	 * @return array|null
402
+	 * @since $VID:$
403
+	 */
404
+	protected function getGraphQLPriceTypes()
405
+	{
406
+		$field_key = lcfirst($this->namespace) . 'PriceTypes';
407
+		$query = <<<QUERY
408 408
         query GET_PRICE_TYPES(\$first: Int, \$last: Int ) {
409 409
             {$field_key}(first: \$first, last: \$last) {
410 410
                 nodes {
@@ -424,27 +424,27 @@  discard block
 block discarded – undo
424 424
             }
425 425
         }
426 426
 QUERY;
427
-        $data = [
428
-            'operation_name' => 'GET_PRICE_TYPES',
429
-            'variables' => [
430
-                'first' => 100,
431
-            ],
432
-            'query' => $query,
433
-        ];
434
-
435
-        $responseData = $this->makeGraphQLRequest($data);
436
-        return !empty($responseData[ $field_key ]) ? $responseData[ $field_key ] : null;
437
-    }
438
-
439
-
440
-    /**
441
-     * @return array|null
442
-     * @since $VID:$
443
-     */
444
-    protected function getGraphQLCurrentUser()
445
-    {
446
-        $field_key = 'viewer';
447
-        $query = <<<QUERY
427
+		$data = [
428
+			'operation_name' => 'GET_PRICE_TYPES',
429
+			'variables' => [
430
+				'first' => 100,
431
+			],
432
+			'query' => $query,
433
+		];
434
+
435
+		$responseData = $this->makeGraphQLRequest($data);
436
+		return !empty($responseData[ $field_key ]) ? $responseData[ $field_key ] : null;
437
+	}
438
+
439
+
440
+	/**
441
+	 * @return array|null
442
+	 * @since $VID:$
443
+	 */
444
+	protected function getGraphQLCurrentUser()
445
+	{
446
+		$field_key = 'viewer';
447
+		$query = <<<QUERY
448 448
         query GET_CURRENT_USER {
449 449
             {$field_key} {
450 450
                 description
@@ -462,24 +462,24 @@  discard block
 block discarded – undo
462 462
             }
463 463
         }
464 464
 QUERY;
465
-        $data = [
466
-            'operation_name' => 'GET_CURRENT_USER',
467
-            'query' => $query,
468
-        ];
469
-
470
-        $responseData = $this->makeGraphQLRequest($data);
471
-        return !empty($responseData[ $field_key ]) ? $responseData[ $field_key ] : null;
472
-    }
473
-
474
-
475
-    /**
476
-     * @return array|null
477
-     * @since $VID:$
478
-     */
479
-    protected function getGraphQLGeneralSettings()
480
-    {
481
-        $field_key = 'generalSettings';
482
-        $query = <<<QUERY
465
+		$data = [
466
+			'operation_name' => 'GET_CURRENT_USER',
467
+			'query' => $query,
468
+		];
469
+
470
+		$responseData = $this->makeGraphQLRequest($data);
471
+		return !empty($responseData[ $field_key ]) ? $responseData[ $field_key ] : null;
472
+	}
473
+
474
+
475
+	/**
476
+	 * @return array|null
477
+	 * @since $VID:$
478
+	 */
479
+	protected function getGraphQLGeneralSettings()
480
+	{
481
+		$field_key = 'generalSettings';
482
+		$query = <<<QUERY
483 483
         query GET_GENERAL_SETTINGS {
484 484
             {$field_key} {
485 485
                 dateFormat
@@ -489,166 +489,166 @@  discard block
 block discarded – undo
489 489
             }
490 490
         }
491 491
 QUERY;
492
-        $data = [
493
-            'operation_name' => 'GET_CURRENT_USER',
494
-            'query' => $query,
495
-        ];
496
-
497
-        $responseData = $this->makeGraphQLRequest($data);
498
-        return !empty($responseData[ $field_key ]) ? $responseData[ $field_key ] : null;
499
-    }
500
-
501
-
502
-    /**
503
-     * @param array $data
504
-     * @return array
505
-     * @since $VID:$
506
-     */
507
-    protected function makeGraphQLRequest($data)
508
-    {
509
-        try {
510
-            $response = graphql($data);
511
-            if (!empty($response['data'])) {
512
-                return $response['data'];
513
-            }
514
-            return null;
515
-        } catch (\Exception $e) {
516
-            // do something with the errors thrown
517
-            return null;
518
-        }
519
-    }
520
-
521
-
522
-    /**
523
-     * @param mixed       $source  The source that's passed down the GraphQL queries
524
-     * @param array       $args    The inputArgs on the field
525
-     * @param AppContext  $context The AppContext passed down the GraphQL tree
526
-     * @param ResolveInfo $info    The ResolveInfo passed down the GraphQL tree
527
-     * @return string
528
-     * @throws EE_Error
529
-     * @throws Exception
530
-     * @throws InvalidArgumentException
531
-     * @throws InvalidDataTypeException
532
-     * @throws InvalidInterfaceException
533
-     * @throws ReflectionException
534
-     * @throws UserError
535
-     * @throws UnexpectedEntityException
536
-     * @since $VID:$
537
-     */
538
-    public static function getRelationalData($eventId)
539
-    {
540
-        $data = [
541
-            'datetimes'  => [],
542
-            'tickets'    => [],
543
-            'prices'     => [],
544
-        ];
545
-
546
-        $eem_datetime   = EEM_Datetime::instance();
547
-        $eem_ticket     = EEM_Ticket::instance();
548
-        $eem_price      = EEM_Price::instance();
549
-        $eem_price_type = EEM_Price_Type::instance();
550
-
551
-        // PROCESS DATETIMES
552
-        $related_models = [
553
-            'tickets' => $eem_ticket,
554
-        ];
555
-        // Get the IDs of event datetimes.
556
-        $datetimeIds = $eem_datetime->get_col([[
557
-            'EVT_ID' => $eventId,
558
-            'DTT_deleted' => ['IN', [true, false]],
559
-        ]]);
560
-        foreach ($datetimeIds as $datetimeId) {
561
-            $GID = self::convertToGlobalId($eem_datetime->item_name(), $datetimeId);
562
-            foreach ($related_models as $key => $model) {
563
-                // Get the IDs of related entities for the datetime ID.
564
-                $Ids = $model->get_col([['Datetime.DTT_ID' => $datetimeId]]);
565
-                $data['datetimes'][ $GID ][ $key ] = empty($Ids) ? [] : self::convertToGlobalId($model->item_name(), $Ids);
566
-            }
567
-        }
568
-
569
-        // PROCESS TICKETS
570
-        $related_models = [
571
-            'datetimes' => $eem_datetime,
572
-            'prices'    => $eem_price,
573
-        ];
574
-        // Get the IDs of all datetime tickets.
575
-        $ticketIds = $eem_ticket->get_col([[
576
-            'Datetime.DTT_ID' => ['in', $datetimeIds],
577
-            'TKT_deleted' => ['IN', [true, false]],
578
-        ]]);
579
-        foreach ($ticketIds as $ticketId) {
580
-            $GID = self::convertToGlobalId($eem_ticket->item_name(), $ticketId);
581
-
582
-            foreach ($related_models as $key => $model) {
583
-                // Get the IDs of related entities for the ticket ID.
584
-                $Ids = $model->get_col([['Ticket.TKT_ID' => $ticketId]]);
585
-                $data['tickets'][ $GID ][ $key ] = empty($Ids) ? [] : self::convertToGlobalId($model->item_name(), $Ids);
586
-            }
587
-        }
588
-
589
-        // PROCESS PRICES
590
-        $related_models = [
591
-            'tickets'    => $eem_ticket,
592
-            'priceTypes' => $eem_price_type,
593
-        ];
594
-        // Get the IDs of all ticket prices.
595
-        $priceIds = $eem_price->get_col([['Ticket.TKT_ID' => ['in', $ticketIds]]]);
596
-        foreach ($priceIds as $priceId) {
597
-            $GID = self::convertToGlobalId($eem_price->item_name(), $priceId);
598
-
599
-            foreach ($related_models as $key => $model) {
600
-                // Get the IDs of related entities for the price ID.
601
-                $Ids = $model->get_col([['Price.PRC_ID' => $priceId]]);
602
-                $data['prices'][ $GID ][ $key ] = empty($Ids) ? [] : self::convertToGlobalId($model->item_name(), $Ids);
603
-            }
604
-        }
605
-
606
-        return $data;
607
-    }
608
-
609
-    /**
610
-     * Convert the DB ID into GID
611
-     *
612
-     * @param string    $type
613
-     * @param int|int[] $ID
614
-     * @return mixed
615
-     */
616
-    public static function convertToGlobalId($type, $ID)
617
-    {
618
-        if (is_array($ID)) {
619
-            return array_map(function ($id) use ($type) {
620
-                return self::convertToGlobalId($type, $id);
621
-            }, $ID);
622
-        }
623
-        return Relay::toGlobalId($type, $ID);
624
-    }
625
-
626
-
627
-    /**
628
-     * Returns Jed-formatted localization data.
629
-     *
630
-     * @param  string $domain Translation domain.
631
-     * @return array
632
-     */
633
-    public static function getJedLocaleData($domain)
634
-    {
635
-        $translations = get_translations_for_domain($domain);
636
-
637
-        $locale = array(
638
-            '' => array(
639
-                'domain' => $domain,
640
-                'lang'   => is_admin() ? EEH_DTT_Helper::get_user_locale() : get_locale()
641
-            ),
642
-        );
643
-
644
-        if (! empty($translations->headers['Plural-Forms'])) {
645
-            $locale['']['plural_forms'] = $translations->headers['Plural-Forms'];
646
-        }
647
-
648
-        foreach ($translations->entries as $msgid => $entry) {
649
-            $locale[ $msgid ] = $entry->translations;
650
-        }
651
-
652
-        return $locale;
653
-    }
492
+		$data = [
493
+			'operation_name' => 'GET_CURRENT_USER',
494
+			'query' => $query,
495
+		];
496
+
497
+		$responseData = $this->makeGraphQLRequest($data);
498
+		return !empty($responseData[ $field_key ]) ? $responseData[ $field_key ] : null;
499
+	}
500
+
501
+
502
+	/**
503
+	 * @param array $data
504
+	 * @return array
505
+	 * @since $VID:$
506
+	 */
507
+	protected function makeGraphQLRequest($data)
508
+	{
509
+		try {
510
+			$response = graphql($data);
511
+			if (!empty($response['data'])) {
512
+				return $response['data'];
513
+			}
514
+			return null;
515
+		} catch (\Exception $e) {
516
+			// do something with the errors thrown
517
+			return null;
518
+		}
519
+	}
520
+
521
+
522
+	/**
523
+	 * @param mixed       $source  The source that's passed down the GraphQL queries
524
+	 * @param array       $args    The inputArgs on the field
525
+	 * @param AppContext  $context The AppContext passed down the GraphQL tree
526
+	 * @param ResolveInfo $info    The ResolveInfo passed down the GraphQL tree
527
+	 * @return string
528
+	 * @throws EE_Error
529
+	 * @throws Exception
530
+	 * @throws InvalidArgumentException
531
+	 * @throws InvalidDataTypeException
532
+	 * @throws InvalidInterfaceException
533
+	 * @throws ReflectionException
534
+	 * @throws UserError
535
+	 * @throws UnexpectedEntityException
536
+	 * @since $VID:$
537
+	 */
538
+	public static function getRelationalData($eventId)
539
+	{
540
+		$data = [
541
+			'datetimes'  => [],
542
+			'tickets'    => [],
543
+			'prices'     => [],
544
+		];
545
+
546
+		$eem_datetime   = EEM_Datetime::instance();
547
+		$eem_ticket     = EEM_Ticket::instance();
548
+		$eem_price      = EEM_Price::instance();
549
+		$eem_price_type = EEM_Price_Type::instance();
550
+
551
+		// PROCESS DATETIMES
552
+		$related_models = [
553
+			'tickets' => $eem_ticket,
554
+		];
555
+		// Get the IDs of event datetimes.
556
+		$datetimeIds = $eem_datetime->get_col([[
557
+			'EVT_ID' => $eventId,
558
+			'DTT_deleted' => ['IN', [true, false]],
559
+		]]);
560
+		foreach ($datetimeIds as $datetimeId) {
561
+			$GID = self::convertToGlobalId($eem_datetime->item_name(), $datetimeId);
562
+			foreach ($related_models as $key => $model) {
563
+				// Get the IDs of related entities for the datetime ID.
564
+				$Ids = $model->get_col([['Datetime.DTT_ID' => $datetimeId]]);
565
+				$data['datetimes'][ $GID ][ $key ] = empty($Ids) ? [] : self::convertToGlobalId($model->item_name(), $Ids);
566
+			}
567
+		}
568
+
569
+		// PROCESS TICKETS
570
+		$related_models = [
571
+			'datetimes' => $eem_datetime,
572
+			'prices'    => $eem_price,
573
+		];
574
+		// Get the IDs of all datetime tickets.
575
+		$ticketIds = $eem_ticket->get_col([[
576
+			'Datetime.DTT_ID' => ['in', $datetimeIds],
577
+			'TKT_deleted' => ['IN', [true, false]],
578
+		]]);
579
+		foreach ($ticketIds as $ticketId) {
580
+			$GID = self::convertToGlobalId($eem_ticket->item_name(), $ticketId);
581
+
582
+			foreach ($related_models as $key => $model) {
583
+				// Get the IDs of related entities for the ticket ID.
584
+				$Ids = $model->get_col([['Ticket.TKT_ID' => $ticketId]]);
585
+				$data['tickets'][ $GID ][ $key ] = empty($Ids) ? [] : self::convertToGlobalId($model->item_name(), $Ids);
586
+			}
587
+		}
588
+
589
+		// PROCESS PRICES
590
+		$related_models = [
591
+			'tickets'    => $eem_ticket,
592
+			'priceTypes' => $eem_price_type,
593
+		];
594
+		// Get the IDs of all ticket prices.
595
+		$priceIds = $eem_price->get_col([['Ticket.TKT_ID' => ['in', $ticketIds]]]);
596
+		foreach ($priceIds as $priceId) {
597
+			$GID = self::convertToGlobalId($eem_price->item_name(), $priceId);
598
+
599
+			foreach ($related_models as $key => $model) {
600
+				// Get the IDs of related entities for the price ID.
601
+				$Ids = $model->get_col([['Price.PRC_ID' => $priceId]]);
602
+				$data['prices'][ $GID ][ $key ] = empty($Ids) ? [] : self::convertToGlobalId($model->item_name(), $Ids);
603
+			}
604
+		}
605
+
606
+		return $data;
607
+	}
608
+
609
+	/**
610
+	 * Convert the DB ID into GID
611
+	 *
612
+	 * @param string    $type
613
+	 * @param int|int[] $ID
614
+	 * @return mixed
615
+	 */
616
+	public static function convertToGlobalId($type, $ID)
617
+	{
618
+		if (is_array($ID)) {
619
+			return array_map(function ($id) use ($type) {
620
+				return self::convertToGlobalId($type, $id);
621
+			}, $ID);
622
+		}
623
+		return Relay::toGlobalId($type, $ID);
624
+	}
625
+
626
+
627
+	/**
628
+	 * Returns Jed-formatted localization data.
629
+	 *
630
+	 * @param  string $domain Translation domain.
631
+	 * @return array
632
+	 */
633
+	public static function getJedLocaleData($domain)
634
+	{
635
+		$translations = get_translations_for_domain($domain);
636
+
637
+		$locale = array(
638
+			'' => array(
639
+				'domain' => $domain,
640
+				'lang'   => is_admin() ? EEH_DTT_Helper::get_user_locale() : get_locale()
641
+			),
642
+		);
643
+
644
+		if (! empty($translations->headers['Plural-Forms'])) {
645
+			$locale['']['plural_forms'] = $translations->headers['Plural-Forms'];
646
+		}
647
+
648
+		foreach ($translations->entries as $msgid => $entry) {
649
+			$locale[ $msgid ] = $entry->translations;
650
+		}
651
+
652
+		return $locale;
653
+	}
654 654
 }
Please login to merge, or discard this patch.
Spacing   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -103,7 +103,7 @@  discard block
 block discarded – undo
103 103
     {
104 104
         if ($this->admin_config->useAdvancedEditor()) {
105 105
             $eventId = $this->event instanceof EE_Event ? $this->event->ID() : 0;
106
-            if (! $eventId) {
106
+            if ( ! $eventId) {
107 107
                 global $post;
108 108
                 $eventId = isset($_REQUEST['post']) ? absint($_REQUEST['post']) : 0;
109 109
                 $eventId = $eventId === 0 && $post instanceof WP_Post && $post->post_type === 'espresso_events'
@@ -115,7 +115,7 @@  discard block
 block discarded – undo
115 115
                 $data = wp_json_encode($data);
116 116
                 add_action(
117 117
                     'admin_footer',
118
-                    static function () use ($data) {
118
+                    static function() use ($data) {
119 119
                         wp_add_inline_script(
120 120
                             EspressoEditorAssetManager::JS_HANDLE_EDITOR,
121 121
                             "
@@ -127,7 +127,7 @@  discard block
 block discarded – undo
127 127
                 );
128 128
                 add_action(
129 129
                     'admin_footer',
130
-                    static function () use ($data) {
130
+                    static function() use ($data) {
131 131
                         wp_add_inline_script(
132 132
                             EspressoEditorAssetManager::JS_HANDLE_EDITOR_PROTOTYPE,
133 133
                             "
@@ -160,7 +160,7 @@  discard block
 block discarded – undo
160 160
         $event = $this->getEventGraphQLData($eventId);
161 161
         $event['dbId'] = $eventId;
162 162
 
163
-        $graphqlEndpoint = class_exists('WPGraphQL') ? trailingslashit(site_url()) . Router::$route : '';
163
+        $graphqlEndpoint = class_exists('WPGraphQL') ? trailingslashit(site_url()).Router::$route : '';
164 164
         $graphqlEndpoint = esc_url($graphqlEndpoint);
165 165
 
166 166
         $currentUser = $this->getGraphQLCurrentUser();
@@ -187,18 +187,18 @@  discard block
 block discarded – undo
187 187
             $datetimes = $this->getGraphQLDatetimes($eventId);
188 188
         }
189 189
 
190
-        if (! empty($datetimes['nodes'])) {
190
+        if ( ! empty($datetimes['nodes'])) {
191 191
             $datetimeIn = wp_list_pluck($datetimes['nodes'], 'id');
192 192
 
193
-            if (! empty($datetimeIn)) {
193
+            if ( ! empty($datetimeIn)) {
194 194
                 $tickets = $this->getGraphQLTickets($datetimeIn);
195 195
             }
196 196
         }
197 197
 
198
-        if (! empty($tickets['nodes'])) {
198
+        if ( ! empty($tickets['nodes'])) {
199 199
             $ticketIn = wp_list_pluck($tickets['nodes'], 'id');
200 200
 
201
-            if (! empty($ticketIn)) {
201
+            if ( ! empty($ticketIn)) {
202 202
                 $prices = $this->getGraphQLPrices($ticketIn);
203 203
             }
204 204
         }
@@ -250,7 +250,7 @@  discard block
 block discarded – undo
250 250
      */
251 251
     protected function getGraphQLDatetimes($eventId)
252 252
     {
253
-        $field_key = lcfirst($this->namespace) . 'Datetimes';
253
+        $field_key = lcfirst($this->namespace).'Datetimes';
254 254
         $query = <<<QUERY
255 255
         query GET_DATETIMES(\$where: {$this->namespace}RootQueryDatetimesConnectionWhereArgs, \$first: Int, \$last: Int ) {
256 256
             {$field_key}(where: \$where, first: \$first, last: \$last) {
@@ -291,7 +291,7 @@  discard block
 block discarded – undo
291 291
         ];
292 292
 
293 293
         $responseData = $this->makeGraphQLRequest($data);
294
-        return !empty($responseData[ $field_key ]) ? $responseData[ $field_key ] : null;
294
+        return ! empty($responseData[$field_key]) ? $responseData[$field_key] : null;
295 295
     }
296 296
 
297 297
 
@@ -302,7 +302,7 @@  discard block
 block discarded – undo
302 302
      */
303 303
     protected function getGraphQLTickets(array $datetimeIn)
304 304
     {
305
-        $field_key = lcfirst($this->namespace) . 'Tickets';
305
+        $field_key = lcfirst($this->namespace).'Tickets';
306 306
         $query = <<<QUERY
307 307
         query GET_TICKETS(\$where: {$this->namespace}RootQueryTicketsConnectionWhereArgs, \$first: Int, \$last: Int ) {
308 308
             {$field_key}(where: \$where, first: \$first, last: \$last) {
@@ -346,7 +346,7 @@  discard block
 block discarded – undo
346 346
         ];
347 347
 
348 348
         $responseData = $this->makeGraphQLRequest($data);
349
-        return !empty($responseData[ $field_key ]) ? $responseData[ $field_key ] : null;
349
+        return ! empty($responseData[$field_key]) ? $responseData[$field_key] : null;
350 350
     }
351 351
 
352 352
 
@@ -357,7 +357,7 @@  discard block
 block discarded – undo
357 357
      */
358 358
     protected function getGraphQLPrices(array $ticketIn)
359 359
     {
360
-        $field_key = lcfirst($this->namespace) . 'Prices';
360
+        $field_key = lcfirst($this->namespace).'Prices';
361 361
         $query = <<<QUERY
362 362
         query GET_PRICES(\$where: {$this->namespace}RootQueryPricesConnectionWhereArgs, \$first: Int, \$last: Int ) {
363 363
             {$field_key}(where: \$where, first: \$first, last: \$last) {
@@ -393,7 +393,7 @@  discard block
 block discarded – undo
393 393
         ];
394 394
 
395 395
         $responseData = $this->makeGraphQLRequest($data);
396
-        return !empty($responseData[ $field_key ]) ? $responseData[ $field_key ] : null;
396
+        return ! empty($responseData[$field_key]) ? $responseData[$field_key] : null;
397 397
     }
398 398
 
399 399
 
@@ -403,7 +403,7 @@  discard block
 block discarded – undo
403 403
      */
404 404
     protected function getGraphQLPriceTypes()
405 405
     {
406
-        $field_key = lcfirst($this->namespace) . 'PriceTypes';
406
+        $field_key = lcfirst($this->namespace).'PriceTypes';
407 407
         $query = <<<QUERY
408 408
         query GET_PRICE_TYPES(\$first: Int, \$last: Int ) {
409 409
             {$field_key}(first: \$first, last: \$last) {
@@ -433,7 +433,7 @@  discard block
 block discarded – undo
433 433
         ];
434 434
 
435 435
         $responseData = $this->makeGraphQLRequest($data);
436
-        return !empty($responseData[ $field_key ]) ? $responseData[ $field_key ] : null;
436
+        return ! empty($responseData[$field_key]) ? $responseData[$field_key] : null;
437 437
     }
438 438
 
439 439
 
@@ -468,7 +468,7 @@  discard block
 block discarded – undo
468 468
         ];
469 469
 
470 470
         $responseData = $this->makeGraphQLRequest($data);
471
-        return !empty($responseData[ $field_key ]) ? $responseData[ $field_key ] : null;
471
+        return ! empty($responseData[$field_key]) ? $responseData[$field_key] : null;
472 472
     }
473 473
 
474 474
 
@@ -495,7 +495,7 @@  discard block
 block discarded – undo
495 495
         ];
496 496
 
497 497
         $responseData = $this->makeGraphQLRequest($data);
498
-        return !empty($responseData[ $field_key ]) ? $responseData[ $field_key ] : null;
498
+        return ! empty($responseData[$field_key]) ? $responseData[$field_key] : null;
499 499
     }
500 500
 
501 501
 
@@ -508,7 +508,7 @@  discard block
 block discarded – undo
508 508
     {
509 509
         try {
510 510
             $response = graphql($data);
511
-            if (!empty($response['data'])) {
511
+            if ( ! empty($response['data'])) {
512 512
                 return $response['data'];
513 513
             }
514 514
             return null;
@@ -562,7 +562,7 @@  discard block
 block discarded – undo
562 562
             foreach ($related_models as $key => $model) {
563 563
                 // Get the IDs of related entities for the datetime ID.
564 564
                 $Ids = $model->get_col([['Datetime.DTT_ID' => $datetimeId]]);
565
-                $data['datetimes'][ $GID ][ $key ] = empty($Ids) ? [] : self::convertToGlobalId($model->item_name(), $Ids);
565
+                $data['datetimes'][$GID][$key] = empty($Ids) ? [] : self::convertToGlobalId($model->item_name(), $Ids);
566 566
             }
567 567
         }
568 568
 
@@ -582,7 +582,7 @@  discard block
 block discarded – undo
582 582
             foreach ($related_models as $key => $model) {
583 583
                 // Get the IDs of related entities for the ticket ID.
584 584
                 $Ids = $model->get_col([['Ticket.TKT_ID' => $ticketId]]);
585
-                $data['tickets'][ $GID ][ $key ] = empty($Ids) ? [] : self::convertToGlobalId($model->item_name(), $Ids);
585
+                $data['tickets'][$GID][$key] = empty($Ids) ? [] : self::convertToGlobalId($model->item_name(), $Ids);
586 586
             }
587 587
         }
588 588
 
@@ -599,7 +599,7 @@  discard block
 block discarded – undo
599 599
             foreach ($related_models as $key => $model) {
600 600
                 // Get the IDs of related entities for the price ID.
601 601
                 $Ids = $model->get_col([['Price.PRC_ID' => $priceId]]);
602
-                $data['prices'][ $GID ][ $key ] = empty($Ids) ? [] : self::convertToGlobalId($model->item_name(), $Ids);
602
+                $data['prices'][$GID][$key] = empty($Ids) ? [] : self::convertToGlobalId($model->item_name(), $Ids);
603 603
             }
604 604
         }
605 605
 
@@ -616,7 +616,7 @@  discard block
 block discarded – undo
616 616
     public static function convertToGlobalId($type, $ID)
617 617
     {
618 618
         if (is_array($ID)) {
619
-            return array_map(function ($id) use ($type) {
619
+            return array_map(function($id) use ($type) {
620 620
                 return self::convertToGlobalId($type, $id);
621 621
             }, $ID);
622 622
         }
@@ -641,12 +641,12 @@  discard block
 block discarded – undo
641 641
             ),
642 642
         );
643 643
 
644
-        if (! empty($translations->headers['Plural-Forms'])) {
644
+        if ( ! empty($translations->headers['Plural-Forms'])) {
645 645
             $locale['']['plural_forms'] = $translations->headers['Plural-Forms'];
646 646
         }
647 647
 
648 648
         foreach ($translations->entries as $msgid => $entry) {
649
-            $locale[ $msgid ] = $entry->translations;
649
+            $locale[$msgid] = $entry->translations;
650 650
         }
651 651
 
652 652
         return $locale;
Please login to merge, or discard this patch.