@@ -34,221 +34,221 @@ discard block |
||
34 | 34 | class AdvancedEditorData |
35 | 35 | { |
36 | 36 | |
37 | - /** |
|
38 | - * @var string $namespace The graphql namespace/prefix. |
|
39 | - */ |
|
40 | - protected $namespace = 'Espresso'; |
|
41 | - |
|
42 | - /** |
|
43 | - * @var EE_Event |
|
44 | - */ |
|
45 | - protected $event; |
|
46 | - |
|
47 | - /** |
|
48 | - * @var EE_Admin_Config |
|
49 | - */ |
|
50 | - protected $admin_config; |
|
51 | - /** |
|
52 | - * @var EEM_Datetime $datetime_model |
|
53 | - */ |
|
54 | - protected $datetime_model; |
|
55 | - /** |
|
56 | - * @var EEM_Price $price_model |
|
57 | - */ |
|
58 | - protected $price_model; |
|
59 | - /** |
|
60 | - * @var EEM_Ticket $ticket_model |
|
61 | - */ |
|
62 | - protected $ticket_model; |
|
63 | - |
|
64 | - |
|
65 | - /** |
|
66 | - * AdvancedEditorAdminForm constructor. |
|
67 | - * |
|
68 | - * @param EE_Event $event |
|
69 | - * @param EE_Admin_Config $admin_config |
|
70 | - * @param EEM_Datetime $datetime_model |
|
71 | - * @param EEM_Price $price_model |
|
72 | - * @param EEM_Ticket $ticket_model |
|
73 | - */ |
|
74 | - public function __construct( |
|
75 | - EE_Event $event, |
|
76 | - EE_Admin_Config $admin_config, |
|
77 | - EEM_Datetime $datetime_model, |
|
78 | - EEM_Price $price_model, |
|
79 | - EEM_Ticket $ticket_model |
|
80 | - ) { |
|
81 | - $this->event = $event; |
|
82 | - $this->admin_config = $admin_config; |
|
83 | - $this->datetime_model = $datetime_model; |
|
84 | - $this->price_model = $price_model; |
|
85 | - $this->ticket_model = $ticket_model; |
|
86 | - add_action('admin_enqueue_scripts', [$this, 'loadScriptsStyles']); |
|
87 | - } |
|
88 | - |
|
89 | - |
|
90 | - /** |
|
91 | - * @throws EE_Error |
|
92 | - * @throws InvalidArgumentException |
|
93 | - * @throws InvalidDataTypeException |
|
94 | - * @throws InvalidInterfaceException |
|
95 | - * @throws ModelConfigurationException |
|
96 | - * @throws ReflectionException |
|
97 | - * @throws UnexpectedEntityException |
|
98 | - * @throws DomainException |
|
99 | - * @since $VID:$ |
|
100 | - */ |
|
101 | - public function loadScriptsStyles() |
|
102 | - { |
|
103 | - if ($this->admin_config->useAdvancedEditor()) { |
|
104 | - $eventId = $this->event instanceof EE_Event ? $this->event->ID() : 0; |
|
105 | - if (! $eventId) { |
|
106 | - global $post; |
|
107 | - $eventId = isset($_REQUEST['post']) ? absint($_REQUEST['post']) : 0; |
|
108 | - $eventId = $eventId === 0 && $post instanceof WP_Post && $post->post_type === 'espresso_events' |
|
109 | - ? $post->ID |
|
110 | - : $eventId; |
|
111 | - } |
|
112 | - if ($eventId) { |
|
113 | - $data = $this->getEditorData($eventId); |
|
114 | - $data = wp_json_encode($data); |
|
115 | - add_action( |
|
116 | - 'admin_footer', |
|
117 | - static function () use ($data) { |
|
118 | - wp_add_inline_script( |
|
119 | - EspressoEditorAssetManager::JS_HANDLE_EDITOR, |
|
120 | - " |
|
37 | + /** |
|
38 | + * @var string $namespace The graphql namespace/prefix. |
|
39 | + */ |
|
40 | + protected $namespace = 'Espresso'; |
|
41 | + |
|
42 | + /** |
|
43 | + * @var EE_Event |
|
44 | + */ |
|
45 | + protected $event; |
|
46 | + |
|
47 | + /** |
|
48 | + * @var EE_Admin_Config |
|
49 | + */ |
|
50 | + protected $admin_config; |
|
51 | + /** |
|
52 | + * @var EEM_Datetime $datetime_model |
|
53 | + */ |
|
54 | + protected $datetime_model; |
|
55 | + /** |
|
56 | + * @var EEM_Price $price_model |
|
57 | + */ |
|
58 | + protected $price_model; |
|
59 | + /** |
|
60 | + * @var EEM_Ticket $ticket_model |
|
61 | + */ |
|
62 | + protected $ticket_model; |
|
63 | + |
|
64 | + |
|
65 | + /** |
|
66 | + * AdvancedEditorAdminForm constructor. |
|
67 | + * |
|
68 | + * @param EE_Event $event |
|
69 | + * @param EE_Admin_Config $admin_config |
|
70 | + * @param EEM_Datetime $datetime_model |
|
71 | + * @param EEM_Price $price_model |
|
72 | + * @param EEM_Ticket $ticket_model |
|
73 | + */ |
|
74 | + public function __construct( |
|
75 | + EE_Event $event, |
|
76 | + EE_Admin_Config $admin_config, |
|
77 | + EEM_Datetime $datetime_model, |
|
78 | + EEM_Price $price_model, |
|
79 | + EEM_Ticket $ticket_model |
|
80 | + ) { |
|
81 | + $this->event = $event; |
|
82 | + $this->admin_config = $admin_config; |
|
83 | + $this->datetime_model = $datetime_model; |
|
84 | + $this->price_model = $price_model; |
|
85 | + $this->ticket_model = $ticket_model; |
|
86 | + add_action('admin_enqueue_scripts', [$this, 'loadScriptsStyles']); |
|
87 | + } |
|
88 | + |
|
89 | + |
|
90 | + /** |
|
91 | + * @throws EE_Error |
|
92 | + * @throws InvalidArgumentException |
|
93 | + * @throws InvalidDataTypeException |
|
94 | + * @throws InvalidInterfaceException |
|
95 | + * @throws ModelConfigurationException |
|
96 | + * @throws ReflectionException |
|
97 | + * @throws UnexpectedEntityException |
|
98 | + * @throws DomainException |
|
99 | + * @since $VID:$ |
|
100 | + */ |
|
101 | + public function loadScriptsStyles() |
|
102 | + { |
|
103 | + if ($this->admin_config->useAdvancedEditor()) { |
|
104 | + $eventId = $this->event instanceof EE_Event ? $this->event->ID() : 0; |
|
105 | + if (! $eventId) { |
|
106 | + global $post; |
|
107 | + $eventId = isset($_REQUEST['post']) ? absint($_REQUEST['post']) : 0; |
|
108 | + $eventId = $eventId === 0 && $post instanceof WP_Post && $post->post_type === 'espresso_events' |
|
109 | + ? $post->ID |
|
110 | + : $eventId; |
|
111 | + } |
|
112 | + if ($eventId) { |
|
113 | + $data = $this->getEditorData($eventId); |
|
114 | + $data = wp_json_encode($data); |
|
115 | + add_action( |
|
116 | + 'admin_footer', |
|
117 | + static function () use ($data) { |
|
118 | + wp_add_inline_script( |
|
119 | + EspressoEditorAssetManager::JS_HANDLE_EDITOR, |
|
120 | + " |
|
121 | 121 | var eeEditorData={$data}; |
122 | 122 | ", |
123 | - 'before' |
|
124 | - ); |
|
125 | - } |
|
126 | - ); |
|
127 | - add_action( |
|
128 | - 'admin_footer', |
|
129 | - static function () use ($data) { |
|
130 | - wp_add_inline_script( |
|
131 | - EspressoEditorAssetManager::JS_HANDLE_EDITOR_PROTOTYPE, |
|
132 | - " |
|
123 | + 'before' |
|
124 | + ); |
|
125 | + } |
|
126 | + ); |
|
127 | + add_action( |
|
128 | + 'admin_footer', |
|
129 | + static function () use ($data) { |
|
130 | + wp_add_inline_script( |
|
131 | + EspressoEditorAssetManager::JS_HANDLE_EDITOR_PROTOTYPE, |
|
132 | + " |
|
133 | 133 | var eeEditorData={$data}; |
134 | 134 | ", |
135 | - 'before' |
|
136 | - ); |
|
137 | - } |
|
138 | - ); |
|
139 | - } |
|
140 | - } |
|
141 | - } |
|
142 | - |
|
143 | - |
|
144 | - /** |
|
145 | - * @param int $eventId |
|
146 | - * @return array |
|
147 | - * @throws EE_Error |
|
148 | - * @throws InvalidDataTypeException |
|
149 | - * @throws InvalidInterfaceException |
|
150 | - * @throws ModelConfigurationException |
|
151 | - * @throws UnexpectedEntityException |
|
152 | - * @throws InvalidArgumentException |
|
153 | - * @throws ReflectionException |
|
154 | - * @throws DomainException |
|
155 | - * @since $VID:$ |
|
156 | - */ |
|
157 | - protected function getEditorData($eventId) |
|
158 | - { |
|
159 | - $event = $this->getEventGraphQLData($eventId); |
|
160 | - $event['dbId'] = $eventId; |
|
161 | - |
|
162 | - $graphqlEndpoint = class_exists('WPGraphQL') ? trailingslashit(site_url()) . Router::$route : ''; |
|
163 | - $graphqlEndpoint = esc_url($graphqlEndpoint); |
|
164 | - |
|
165 | - $currentUser = $this->getGraphQLCurrentUser(); |
|
166 | - |
|
167 | - $generalSettings = $this->getGraphQLGeneralSettings(); |
|
168 | - |
|
169 | - return compact('event', 'graphqlEndpoint', 'currentUser', 'generalSettings'); |
|
170 | - } |
|
171 | - |
|
172 | - |
|
173 | - /** |
|
174 | - * @param int $eventId |
|
175 | - * @return array |
|
176 | - * @since $VID:$ |
|
177 | - */ |
|
178 | - protected function getEventGraphQLData($eventId) |
|
179 | - { |
|
180 | - $datetimes = $this->getGraphQLDatetimes($eventId); |
|
181 | - |
|
182 | - if (empty($datetimes['nodes']) || (isset($_REQUEST['action']) && $_REQUEST['action'] === 'create_new')) { |
|
183 | - $this->addDefaultEntities($eventId); |
|
184 | - $datetimes = $this->getGraphQLDatetimes($eventId); |
|
185 | - } |
|
186 | - |
|
187 | - if (! empty($datetimes['nodes'])) { |
|
188 | - $datetimeIn = wp_list_pluck($datetimes['nodes'], 'id'); |
|
189 | - |
|
190 | - if (! empty($datetimeIn)) { |
|
191 | - $tickets = $this->getGraphQLTickets($datetimeIn); |
|
192 | - } |
|
193 | - } |
|
194 | - |
|
195 | - if (! empty($tickets['nodes'])) { |
|
196 | - $ticketIn = wp_list_pluck($tickets['nodes'], 'id'); |
|
197 | - |
|
198 | - if (! empty($ticketIn)) { |
|
199 | - $prices = $this->getGraphQLPrices($ticketIn); |
|
200 | - } |
|
201 | - } |
|
202 | - |
|
203 | - $priceTypes = $this->getGraphQLPriceTypes(); |
|
204 | - |
|
205 | - $relations = $this->getRelationalData($eventId); |
|
206 | - |
|
207 | - return compact('datetimes', 'tickets', 'prices', 'priceTypes', 'relations'); |
|
208 | - } |
|
209 | - |
|
210 | - /** |
|
211 | - * @param int $eventId |
|
212 | - * @throws DomainException |
|
213 | - * @throws EE_Error |
|
214 | - * @throws InvalidArgumentException |
|
215 | - * @throws InvalidDataTypeException |
|
216 | - * @throws InvalidInterfaceException |
|
217 | - * @throws ModelConfigurationException |
|
218 | - * @throws ReflectionException |
|
219 | - * @throws UnexpectedEntityException |
|
220 | - * @since $VID:$ |
|
221 | - */ |
|
222 | - protected function addDefaultEntities($eventId) |
|
223 | - { |
|
224 | - $default_dates = $this->datetime_model->create_new_blank_datetime(); |
|
225 | - if (is_array($default_dates) && isset($default_dates[0]) && $default_dates[0] instanceof EE_Datetime) { |
|
226 | - $default_date = $default_dates[0]; |
|
227 | - $default_date->save(); |
|
228 | - $default_date->_add_relation_to($eventId, 'Event'); |
|
229 | - $default_tickets = $this->ticket_model->get_all_default_tickets(); |
|
230 | - $default_prices = $this->price_model->get_all_default_prices(); |
|
231 | - foreach ($default_tickets as $default_ticket) { |
|
232 | - $default_ticket->save(); |
|
233 | - $default_ticket->_add_relation_to($default_date, 'Datetime'); |
|
234 | - foreach ($default_prices as $default_price) { |
|
235 | - $default_price->save(); |
|
236 | - $default_price->_add_relation_to($default_ticket, 'Ticket'); |
|
237 | - } |
|
238 | - } |
|
239 | - } |
|
240 | - } |
|
241 | - |
|
242 | - |
|
243 | - /** |
|
244 | - * @param int $eventId |
|
245 | - * @return array|null |
|
246 | - * @since $VID:$ |
|
247 | - */ |
|
248 | - protected function getGraphQLDatetimes($eventId) |
|
249 | - { |
|
250 | - $field_key = lcfirst($this->namespace) . 'Datetimes'; |
|
251 | - $query = <<<QUERY |
|
135 | + 'before' |
|
136 | + ); |
|
137 | + } |
|
138 | + ); |
|
139 | + } |
|
140 | + } |
|
141 | + } |
|
142 | + |
|
143 | + |
|
144 | + /** |
|
145 | + * @param int $eventId |
|
146 | + * @return array |
|
147 | + * @throws EE_Error |
|
148 | + * @throws InvalidDataTypeException |
|
149 | + * @throws InvalidInterfaceException |
|
150 | + * @throws ModelConfigurationException |
|
151 | + * @throws UnexpectedEntityException |
|
152 | + * @throws InvalidArgumentException |
|
153 | + * @throws ReflectionException |
|
154 | + * @throws DomainException |
|
155 | + * @since $VID:$ |
|
156 | + */ |
|
157 | + protected function getEditorData($eventId) |
|
158 | + { |
|
159 | + $event = $this->getEventGraphQLData($eventId); |
|
160 | + $event['dbId'] = $eventId; |
|
161 | + |
|
162 | + $graphqlEndpoint = class_exists('WPGraphQL') ? trailingslashit(site_url()) . Router::$route : ''; |
|
163 | + $graphqlEndpoint = esc_url($graphqlEndpoint); |
|
164 | + |
|
165 | + $currentUser = $this->getGraphQLCurrentUser(); |
|
166 | + |
|
167 | + $generalSettings = $this->getGraphQLGeneralSettings(); |
|
168 | + |
|
169 | + return compact('event', 'graphqlEndpoint', 'currentUser', 'generalSettings'); |
|
170 | + } |
|
171 | + |
|
172 | + |
|
173 | + /** |
|
174 | + * @param int $eventId |
|
175 | + * @return array |
|
176 | + * @since $VID:$ |
|
177 | + */ |
|
178 | + protected function getEventGraphQLData($eventId) |
|
179 | + { |
|
180 | + $datetimes = $this->getGraphQLDatetimes($eventId); |
|
181 | + |
|
182 | + if (empty($datetimes['nodes']) || (isset($_REQUEST['action']) && $_REQUEST['action'] === 'create_new')) { |
|
183 | + $this->addDefaultEntities($eventId); |
|
184 | + $datetimes = $this->getGraphQLDatetimes($eventId); |
|
185 | + } |
|
186 | + |
|
187 | + if (! empty($datetimes['nodes'])) { |
|
188 | + $datetimeIn = wp_list_pluck($datetimes['nodes'], 'id'); |
|
189 | + |
|
190 | + if (! empty($datetimeIn)) { |
|
191 | + $tickets = $this->getGraphQLTickets($datetimeIn); |
|
192 | + } |
|
193 | + } |
|
194 | + |
|
195 | + if (! empty($tickets['nodes'])) { |
|
196 | + $ticketIn = wp_list_pluck($tickets['nodes'], 'id'); |
|
197 | + |
|
198 | + if (! empty($ticketIn)) { |
|
199 | + $prices = $this->getGraphQLPrices($ticketIn); |
|
200 | + } |
|
201 | + } |
|
202 | + |
|
203 | + $priceTypes = $this->getGraphQLPriceTypes(); |
|
204 | + |
|
205 | + $relations = $this->getRelationalData($eventId); |
|
206 | + |
|
207 | + return compact('datetimes', 'tickets', 'prices', 'priceTypes', 'relations'); |
|
208 | + } |
|
209 | + |
|
210 | + /** |
|
211 | + * @param int $eventId |
|
212 | + * @throws DomainException |
|
213 | + * @throws EE_Error |
|
214 | + * @throws InvalidArgumentException |
|
215 | + * @throws InvalidDataTypeException |
|
216 | + * @throws InvalidInterfaceException |
|
217 | + * @throws ModelConfigurationException |
|
218 | + * @throws ReflectionException |
|
219 | + * @throws UnexpectedEntityException |
|
220 | + * @since $VID:$ |
|
221 | + */ |
|
222 | + protected function addDefaultEntities($eventId) |
|
223 | + { |
|
224 | + $default_dates = $this->datetime_model->create_new_blank_datetime(); |
|
225 | + if (is_array($default_dates) && isset($default_dates[0]) && $default_dates[0] instanceof EE_Datetime) { |
|
226 | + $default_date = $default_dates[0]; |
|
227 | + $default_date->save(); |
|
228 | + $default_date->_add_relation_to($eventId, 'Event'); |
|
229 | + $default_tickets = $this->ticket_model->get_all_default_tickets(); |
|
230 | + $default_prices = $this->price_model->get_all_default_prices(); |
|
231 | + foreach ($default_tickets as $default_ticket) { |
|
232 | + $default_ticket->save(); |
|
233 | + $default_ticket->_add_relation_to($default_date, 'Datetime'); |
|
234 | + foreach ($default_prices as $default_price) { |
|
235 | + $default_price->save(); |
|
236 | + $default_price->_add_relation_to($default_ticket, 'Ticket'); |
|
237 | + } |
|
238 | + } |
|
239 | + } |
|
240 | + } |
|
241 | + |
|
242 | + |
|
243 | + /** |
|
244 | + * @param int $eventId |
|
245 | + * @return array|null |
|
246 | + * @since $VID:$ |
|
247 | + */ |
|
248 | + protected function getGraphQLDatetimes($eventId) |
|
249 | + { |
|
250 | + $field_key = lcfirst($this->namespace) . 'Datetimes'; |
|
251 | + $query = <<<QUERY |
|
252 | 252 | query GET_DATETIMES(\$where: {$this->namespace}RootQueryDatetimesConnectionWhereArgs) { |
253 | 253 | {$field_key}(where: \$where) { |
254 | 254 | nodes { |
@@ -276,31 +276,31 @@ discard block |
||
276 | 276 | } |
277 | 277 | } |
278 | 278 | QUERY; |
279 | - $data = [ |
|
280 | - 'operation_name' => 'GET_DATETIMES', |
|
281 | - 'variables' => [ |
|
282 | - 'first' => 50, |
|
283 | - 'where' => [ |
|
284 | - 'eventId' => $eventId, |
|
285 | - ], |
|
286 | - ], |
|
287 | - 'query' => $query, |
|
288 | - ]; |
|
289 | - |
|
290 | - $responseData = $this->makeGraphQLRequest($data); |
|
291 | - return !empty($responseData[ $field_key ]) ? $responseData[ $field_key ] : null; |
|
292 | - } |
|
293 | - |
|
294 | - |
|
295 | - /** |
|
296 | - * @param array $datetimeIn |
|
297 | - * @return array|null |
|
298 | - * @since $VID:$ |
|
299 | - */ |
|
300 | - protected function getGraphQLTickets(array $datetimeIn) |
|
301 | - { |
|
302 | - $field_key = lcfirst($this->namespace) . 'Tickets'; |
|
303 | - $query = <<<QUERY |
|
279 | + $data = [ |
|
280 | + 'operation_name' => 'GET_DATETIMES', |
|
281 | + 'variables' => [ |
|
282 | + 'first' => 50, |
|
283 | + 'where' => [ |
|
284 | + 'eventId' => $eventId, |
|
285 | + ], |
|
286 | + ], |
|
287 | + 'query' => $query, |
|
288 | + ]; |
|
289 | + |
|
290 | + $responseData = $this->makeGraphQLRequest($data); |
|
291 | + return !empty($responseData[ $field_key ]) ? $responseData[ $field_key ] : null; |
|
292 | + } |
|
293 | + |
|
294 | + |
|
295 | + /** |
|
296 | + * @param array $datetimeIn |
|
297 | + * @return array|null |
|
298 | + * @since $VID:$ |
|
299 | + */ |
|
300 | + protected function getGraphQLTickets(array $datetimeIn) |
|
301 | + { |
|
302 | + $field_key = lcfirst($this->namespace) . 'Tickets'; |
|
303 | + $query = <<<QUERY |
|
304 | 304 | query GET_TICKETS(\$where: {$this->namespace}RootQueryTicketsConnectionWhereArgs) { |
305 | 305 | {$field_key}(where: \$where) { |
306 | 306 | nodes { |
@@ -330,30 +330,30 @@ discard block |
||
330 | 330 | } |
331 | 331 | } |
332 | 332 | QUERY; |
333 | - $data = [ |
|
334 | - 'operation_name' => 'GET_TICKETS', |
|
335 | - 'variables' => [ |
|
336 | - 'where' => [ |
|
337 | - 'datetimeIn' => $datetimeIn, |
|
338 | - ], |
|
339 | - ], |
|
340 | - 'query' => $query, |
|
341 | - ]; |
|
342 | - |
|
343 | - $responseData = $this->makeGraphQLRequest($data); |
|
344 | - return !empty($responseData[ $field_key ]) ? $responseData[ $field_key ] : null; |
|
345 | - } |
|
346 | - |
|
347 | - |
|
348 | - /** |
|
349 | - * @param array $ticketIn |
|
350 | - * @return array|null |
|
351 | - * @since $VID:$ |
|
352 | - */ |
|
353 | - protected function getGraphQLPrices(array $ticketIn) |
|
354 | - { |
|
355 | - $field_key = lcfirst($this->namespace) . 'Prices'; |
|
356 | - $query = <<<QUERY |
|
333 | + $data = [ |
|
334 | + 'operation_name' => 'GET_TICKETS', |
|
335 | + 'variables' => [ |
|
336 | + 'where' => [ |
|
337 | + 'datetimeIn' => $datetimeIn, |
|
338 | + ], |
|
339 | + ], |
|
340 | + 'query' => $query, |
|
341 | + ]; |
|
342 | + |
|
343 | + $responseData = $this->makeGraphQLRequest($data); |
|
344 | + return !empty($responseData[ $field_key ]) ? $responseData[ $field_key ] : null; |
|
345 | + } |
|
346 | + |
|
347 | + |
|
348 | + /** |
|
349 | + * @param array $ticketIn |
|
350 | + * @return array|null |
|
351 | + * @since $VID:$ |
|
352 | + */ |
|
353 | + protected function getGraphQLPrices(array $ticketIn) |
|
354 | + { |
|
355 | + $field_key = lcfirst($this->namespace) . 'Prices'; |
|
356 | + $query = <<<QUERY |
|
357 | 357 | query GET_PRICES(\$where: {$this->namespace}RootQueryPricesConnectionWhereArgs) { |
358 | 358 | {$field_key}(where: \$where) { |
359 | 359 | nodes { |
@@ -377,29 +377,29 @@ discard block |
||
377 | 377 | } |
378 | 378 | } |
379 | 379 | QUERY; |
380 | - $data = [ |
|
381 | - 'operation_name' => 'GET_PRICES', |
|
382 | - 'variables' => [ |
|
383 | - 'where' => [ |
|
384 | - 'ticketIn' => $ticketIn, |
|
385 | - ], |
|
386 | - ], |
|
387 | - 'query' => $query, |
|
388 | - ]; |
|
389 | - |
|
390 | - $responseData = $this->makeGraphQLRequest($data); |
|
391 | - return !empty($responseData[ $field_key ]) ? $responseData[ $field_key ] : null; |
|
392 | - } |
|
393 | - |
|
394 | - |
|
395 | - /** |
|
396 | - * @return array|null |
|
397 | - * @since $VID:$ |
|
398 | - */ |
|
399 | - protected function getGraphQLPriceTypes() |
|
400 | - { |
|
401 | - $field_key = lcfirst($this->namespace) . 'PriceTypes'; |
|
402 | - $query = <<<QUERY |
|
380 | + $data = [ |
|
381 | + 'operation_name' => 'GET_PRICES', |
|
382 | + 'variables' => [ |
|
383 | + 'where' => [ |
|
384 | + 'ticketIn' => $ticketIn, |
|
385 | + ], |
|
386 | + ], |
|
387 | + 'query' => $query, |
|
388 | + ]; |
|
389 | + |
|
390 | + $responseData = $this->makeGraphQLRequest($data); |
|
391 | + return !empty($responseData[ $field_key ]) ? $responseData[ $field_key ] : null; |
|
392 | + } |
|
393 | + |
|
394 | + |
|
395 | + /** |
|
396 | + * @return array|null |
|
397 | + * @since $VID:$ |
|
398 | + */ |
|
399 | + protected function getGraphQLPriceTypes() |
|
400 | + { |
|
401 | + $field_key = lcfirst($this->namespace) . 'PriceTypes'; |
|
402 | + $query = <<<QUERY |
|
403 | 403 | query GET_PRICES { |
404 | 404 | {$field_key} { |
405 | 405 | nodes { |
@@ -419,24 +419,24 @@ discard block |
||
419 | 419 | } |
420 | 420 | } |
421 | 421 | QUERY; |
422 | - $data = [ |
|
423 | - 'operation_name' => 'GET_PRICES', |
|
424 | - 'query' => $query, |
|
425 | - ]; |
|
426 | - |
|
427 | - $responseData = $this->makeGraphQLRequest($data); |
|
428 | - return !empty($responseData[ $field_key ]) ? $responseData[ $field_key ] : null; |
|
429 | - } |
|
430 | - |
|
431 | - |
|
432 | - /** |
|
433 | - * @return array|null |
|
434 | - * @since $VID:$ |
|
435 | - */ |
|
436 | - protected function getGraphQLCurrentUser() |
|
437 | - { |
|
438 | - $field_key = 'viewer'; |
|
439 | - $query = <<<QUERY |
|
422 | + $data = [ |
|
423 | + 'operation_name' => 'GET_PRICES', |
|
424 | + 'query' => $query, |
|
425 | + ]; |
|
426 | + |
|
427 | + $responseData = $this->makeGraphQLRequest($data); |
|
428 | + return !empty($responseData[ $field_key ]) ? $responseData[ $field_key ] : null; |
|
429 | + } |
|
430 | + |
|
431 | + |
|
432 | + /** |
|
433 | + * @return array|null |
|
434 | + * @since $VID:$ |
|
435 | + */ |
|
436 | + protected function getGraphQLCurrentUser() |
|
437 | + { |
|
438 | + $field_key = 'viewer'; |
|
439 | + $query = <<<QUERY |
|
440 | 440 | query GET_CURRENT_USER { |
441 | 441 | {$field_key} { |
442 | 442 | description |
@@ -454,24 +454,24 @@ discard block |
||
454 | 454 | } |
455 | 455 | } |
456 | 456 | QUERY; |
457 | - $data = [ |
|
458 | - 'operation_name' => 'GET_CURRENT_USER', |
|
459 | - 'query' => $query, |
|
460 | - ]; |
|
461 | - |
|
462 | - $responseData = $this->makeGraphQLRequest($data); |
|
463 | - return !empty($responseData[ $field_key ]) ? $responseData[ $field_key ] : null; |
|
464 | - } |
|
465 | - |
|
466 | - |
|
467 | - /** |
|
468 | - * @return array|null |
|
469 | - * @since $VID:$ |
|
470 | - */ |
|
471 | - protected function getGraphQLGeneralSettings() |
|
472 | - { |
|
473 | - $field_key = 'generalSettings'; |
|
474 | - $query = <<<QUERY |
|
457 | + $data = [ |
|
458 | + 'operation_name' => 'GET_CURRENT_USER', |
|
459 | + 'query' => $query, |
|
460 | + ]; |
|
461 | + |
|
462 | + $responseData = $this->makeGraphQLRequest($data); |
|
463 | + return !empty($responseData[ $field_key ]) ? $responseData[ $field_key ] : null; |
|
464 | + } |
|
465 | + |
|
466 | + |
|
467 | + /** |
|
468 | + * @return array|null |
|
469 | + * @since $VID:$ |
|
470 | + */ |
|
471 | + protected function getGraphQLGeneralSettings() |
|
472 | + { |
|
473 | + $field_key = 'generalSettings'; |
|
474 | + $query = <<<QUERY |
|
475 | 475 | query GET_GENERAL_SETTINGS { |
476 | 476 | {$field_key} { |
477 | 477 | dateFormat |
@@ -481,144 +481,144 @@ discard block |
||
481 | 481 | } |
482 | 482 | } |
483 | 483 | QUERY; |
484 | - $data = [ |
|
485 | - 'operation_name' => 'GET_CURRENT_USER', |
|
486 | - 'query' => $query, |
|
487 | - ]; |
|
488 | - |
|
489 | - $responseData = $this->makeGraphQLRequest($data); |
|
490 | - return !empty($responseData[ $field_key ]) ? $responseData[ $field_key ] : null; |
|
491 | - } |
|
492 | - |
|
493 | - |
|
494 | - /** |
|
495 | - * @param array $data |
|
496 | - * @return array |
|
497 | - * @since $VID:$ |
|
498 | - */ |
|
499 | - protected function makeGraphQLRequest($data) |
|
500 | - { |
|
501 | - try { |
|
502 | - $response = graphql($data); |
|
503 | - if (!empty($response['data'])) { |
|
504 | - return $response['data']; |
|
505 | - } |
|
506 | - return null; |
|
507 | - } catch (\Exception $e) { |
|
508 | - // do something with the errors thrown |
|
509 | - return null; |
|
510 | - } |
|
511 | - } |
|
512 | - |
|
513 | - |
|
514 | - /** |
|
515 | - * @param mixed $source The source that's passed down the GraphQL queries |
|
516 | - * @param array $args The inputArgs on the field |
|
517 | - * @param AppContext $context The AppContext passed down the GraphQL tree |
|
518 | - * @param ResolveInfo $info The ResolveInfo passed down the GraphQL tree |
|
519 | - * @return string |
|
520 | - * @throws EE_Error |
|
521 | - * @throws Exception |
|
522 | - * @throws InvalidArgumentException |
|
523 | - * @throws InvalidDataTypeException |
|
524 | - * @throws InvalidInterfaceException |
|
525 | - * @throws ReflectionException |
|
526 | - * @throws UserError |
|
527 | - * @throws UnexpectedEntityException |
|
528 | - * @since $VID:$ |
|
529 | - */ |
|
530 | - public static function getRelationalData($eventId) |
|
531 | - { |
|
532 | - |
|
533 | - $data = [ |
|
534 | - 'datetimes' => [], |
|
535 | - 'tickets' => [], |
|
536 | - 'prices' => [], |
|
537 | - ]; |
|
538 | - |
|
539 | - $eem_datetime = EEM_Datetime::instance(); |
|
540 | - $eem_ticket = EEM_Ticket::instance(); |
|
541 | - $eem_price = EEM_Price::instance(); |
|
542 | - $eem_price_type = EEM_Price_Type::instance(); |
|
543 | - |
|
544 | - // PROCESS DATETIMES |
|
545 | - $related_models = [ |
|
546 | - 'tickets' => $eem_ticket, |
|
547 | - ]; |
|
548 | - // Get the IDs of event datetimes. |
|
549 | - $datetimeIds = $eem_datetime->get_col([[ |
|
550 | - 'EVT_ID' => $eventId, |
|
551 | - 'DTT_deleted' => ['IN', [true, false]], |
|
552 | - ]]); |
|
553 | - foreach ($datetimeIds as $datetimeId) { |
|
554 | - $GID = self::convertToGlobalId($eem_datetime->item_name(), $datetimeId); |
|
555 | - foreach ($related_models as $key => $model) { |
|
556 | - // Get the IDs of related entities for the datetime ID. |
|
557 | - $Ids = $model->get_col([['Datetime.DTT_ID' => $datetimeId]]); |
|
558 | - if (! empty($Ids)) { |
|
559 | - $data['datetimes'][ $GID ][ $key ] = self::convertToGlobalId($model->item_name(), $Ids); |
|
560 | - } |
|
561 | - } |
|
562 | - } |
|
563 | - |
|
564 | - // PROCESS TICKETS |
|
565 | - $related_models = [ |
|
566 | - 'datetimes' => $eem_datetime, |
|
567 | - 'prices' => $eem_price, |
|
568 | - ]; |
|
569 | - // Get the IDs of all datetime tickets. |
|
570 | - $ticketIds = $eem_ticket->get_col([[ |
|
571 | - 'Datetime.DTT_ID' => ['in', $datetimeIds], |
|
572 | - 'TKT_deleted' => ['IN', [true, false]], |
|
573 | - ]]); |
|
574 | - foreach ($ticketIds as $ticketId) { |
|
575 | - $GID = self::convertToGlobalId($eem_ticket->item_name(), $ticketId); |
|
576 | - |
|
577 | - foreach ($related_models as $key => $model) { |
|
578 | - // Get the IDs of related entities for the ticket ID. |
|
579 | - $Ids = $model->get_col([['Ticket.TKT_ID' => $ticketId]]); |
|
580 | - if (! empty($Ids)) { |
|
581 | - $data['tickets'][ $GID ][ $key ] = self::convertToGlobalId($model->item_name(), $Ids); |
|
582 | - } |
|
583 | - } |
|
584 | - } |
|
585 | - |
|
586 | - // PROCESS PRICES |
|
587 | - $related_models = [ |
|
588 | - 'tickets' => $eem_ticket, |
|
589 | - 'priceTypes' => $eem_price_type, |
|
590 | - ]; |
|
591 | - // Get the IDs of all ticket prices. |
|
592 | - $priceIds = $eem_price->get_col([['Ticket.TKT_ID' => ['in', $ticketIds]]]); |
|
593 | - foreach ($priceIds as $priceId) { |
|
594 | - $GID = self::convertToGlobalId($eem_price->item_name(), $priceId); |
|
595 | - |
|
596 | - foreach ($related_models as $key => $model) { |
|
597 | - // Get the IDs of related entities for the price ID. |
|
598 | - $Ids = $model->get_col([['Price.PRC_ID' => $priceId]]); |
|
599 | - if (! empty($Ids)) { |
|
600 | - $data['prices'][ $GID ][ $key ] = self::convertToGlobalId($model->item_name(), $Ids); |
|
601 | - } |
|
602 | - } |
|
603 | - } |
|
604 | - |
|
605 | - return $data; |
|
606 | - } |
|
607 | - |
|
608 | - /** |
|
609 | - * Convert the DB ID into GID |
|
610 | - * |
|
611 | - * @param string $type |
|
612 | - * @param int|int[] $ID |
|
613 | - * @return mixed |
|
614 | - */ |
|
615 | - public static function convertToGlobalId($type, $ID) |
|
616 | - { |
|
617 | - if (is_array($ID)) { |
|
618 | - return array_map(function ($id) use ($type) { |
|
619 | - return self::convertToGlobalId($type, $id); |
|
620 | - }, $ID); |
|
621 | - } |
|
622 | - return Relay::toGlobalId($type, $ID); |
|
623 | - } |
|
484 | + $data = [ |
|
485 | + 'operation_name' => 'GET_CURRENT_USER', |
|
486 | + 'query' => $query, |
|
487 | + ]; |
|
488 | + |
|
489 | + $responseData = $this->makeGraphQLRequest($data); |
|
490 | + return !empty($responseData[ $field_key ]) ? $responseData[ $field_key ] : null; |
|
491 | + } |
|
492 | + |
|
493 | + |
|
494 | + /** |
|
495 | + * @param array $data |
|
496 | + * @return array |
|
497 | + * @since $VID:$ |
|
498 | + */ |
|
499 | + protected function makeGraphQLRequest($data) |
|
500 | + { |
|
501 | + try { |
|
502 | + $response = graphql($data); |
|
503 | + if (!empty($response['data'])) { |
|
504 | + return $response['data']; |
|
505 | + } |
|
506 | + return null; |
|
507 | + } catch (\Exception $e) { |
|
508 | + // do something with the errors thrown |
|
509 | + return null; |
|
510 | + } |
|
511 | + } |
|
512 | + |
|
513 | + |
|
514 | + /** |
|
515 | + * @param mixed $source The source that's passed down the GraphQL queries |
|
516 | + * @param array $args The inputArgs on the field |
|
517 | + * @param AppContext $context The AppContext passed down the GraphQL tree |
|
518 | + * @param ResolveInfo $info The ResolveInfo passed down the GraphQL tree |
|
519 | + * @return string |
|
520 | + * @throws EE_Error |
|
521 | + * @throws Exception |
|
522 | + * @throws InvalidArgumentException |
|
523 | + * @throws InvalidDataTypeException |
|
524 | + * @throws InvalidInterfaceException |
|
525 | + * @throws ReflectionException |
|
526 | + * @throws UserError |
|
527 | + * @throws UnexpectedEntityException |
|
528 | + * @since $VID:$ |
|
529 | + */ |
|
530 | + public static function getRelationalData($eventId) |
|
531 | + { |
|
532 | + |
|
533 | + $data = [ |
|
534 | + 'datetimes' => [], |
|
535 | + 'tickets' => [], |
|
536 | + 'prices' => [], |
|
537 | + ]; |
|
538 | + |
|
539 | + $eem_datetime = EEM_Datetime::instance(); |
|
540 | + $eem_ticket = EEM_Ticket::instance(); |
|
541 | + $eem_price = EEM_Price::instance(); |
|
542 | + $eem_price_type = EEM_Price_Type::instance(); |
|
543 | + |
|
544 | + // PROCESS DATETIMES |
|
545 | + $related_models = [ |
|
546 | + 'tickets' => $eem_ticket, |
|
547 | + ]; |
|
548 | + // Get the IDs of event datetimes. |
|
549 | + $datetimeIds = $eem_datetime->get_col([[ |
|
550 | + 'EVT_ID' => $eventId, |
|
551 | + 'DTT_deleted' => ['IN', [true, false]], |
|
552 | + ]]); |
|
553 | + foreach ($datetimeIds as $datetimeId) { |
|
554 | + $GID = self::convertToGlobalId($eem_datetime->item_name(), $datetimeId); |
|
555 | + foreach ($related_models as $key => $model) { |
|
556 | + // Get the IDs of related entities for the datetime ID. |
|
557 | + $Ids = $model->get_col([['Datetime.DTT_ID' => $datetimeId]]); |
|
558 | + if (! empty($Ids)) { |
|
559 | + $data['datetimes'][ $GID ][ $key ] = self::convertToGlobalId($model->item_name(), $Ids); |
|
560 | + } |
|
561 | + } |
|
562 | + } |
|
563 | + |
|
564 | + // PROCESS TICKETS |
|
565 | + $related_models = [ |
|
566 | + 'datetimes' => $eem_datetime, |
|
567 | + 'prices' => $eem_price, |
|
568 | + ]; |
|
569 | + // Get the IDs of all datetime tickets. |
|
570 | + $ticketIds = $eem_ticket->get_col([[ |
|
571 | + 'Datetime.DTT_ID' => ['in', $datetimeIds], |
|
572 | + 'TKT_deleted' => ['IN', [true, false]], |
|
573 | + ]]); |
|
574 | + foreach ($ticketIds as $ticketId) { |
|
575 | + $GID = self::convertToGlobalId($eem_ticket->item_name(), $ticketId); |
|
576 | + |
|
577 | + foreach ($related_models as $key => $model) { |
|
578 | + // Get the IDs of related entities for the ticket ID. |
|
579 | + $Ids = $model->get_col([['Ticket.TKT_ID' => $ticketId]]); |
|
580 | + if (! empty($Ids)) { |
|
581 | + $data['tickets'][ $GID ][ $key ] = self::convertToGlobalId($model->item_name(), $Ids); |
|
582 | + } |
|
583 | + } |
|
584 | + } |
|
585 | + |
|
586 | + // PROCESS PRICES |
|
587 | + $related_models = [ |
|
588 | + 'tickets' => $eem_ticket, |
|
589 | + 'priceTypes' => $eem_price_type, |
|
590 | + ]; |
|
591 | + // Get the IDs of all ticket prices. |
|
592 | + $priceIds = $eem_price->get_col([['Ticket.TKT_ID' => ['in', $ticketIds]]]); |
|
593 | + foreach ($priceIds as $priceId) { |
|
594 | + $GID = self::convertToGlobalId($eem_price->item_name(), $priceId); |
|
595 | + |
|
596 | + foreach ($related_models as $key => $model) { |
|
597 | + // Get the IDs of related entities for the price ID. |
|
598 | + $Ids = $model->get_col([['Price.PRC_ID' => $priceId]]); |
|
599 | + if (! empty($Ids)) { |
|
600 | + $data['prices'][ $GID ][ $key ] = self::convertToGlobalId($model->item_name(), $Ids); |
|
601 | + } |
|
602 | + } |
|
603 | + } |
|
604 | + |
|
605 | + return $data; |
|
606 | + } |
|
607 | + |
|
608 | + /** |
|
609 | + * Convert the DB ID into GID |
|
610 | + * |
|
611 | + * @param string $type |
|
612 | + * @param int|int[] $ID |
|
613 | + * @return mixed |
|
614 | + */ |
|
615 | + public static function convertToGlobalId($type, $ID) |
|
616 | + { |
|
617 | + if (is_array($ID)) { |
|
618 | + return array_map(function ($id) use ($type) { |
|
619 | + return self::convertToGlobalId($type, $id); |
|
620 | + }, $ID); |
|
621 | + } |
|
622 | + return Relay::toGlobalId($type, $ID); |
|
623 | + } |
|
624 | 624 | } |