@@ -35,225 +35,225 @@ discard block |
||
| 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 | - $assets_url = EE_PLUGIN_DIR_URL . 'assets/dist/'; |
|
| 173 | - |
|
| 174 | - return compact('event', 'graphqlEndpoint', 'currentUser', 'generalSettings', 'i18n', 'assets_url'); |
|
| 175 | - } |
|
| 176 | - |
|
| 177 | - |
|
| 178 | - /** |
|
| 179 | - * @param int $eventId |
|
| 180 | - * @return array |
|
| 181 | - * @since $VID:$ |
|
| 182 | - */ |
|
| 183 | - protected function getEventGraphQLData($eventId) |
|
| 184 | - { |
|
| 185 | - $datetimes = $this->getGraphQLDatetimes($eventId); |
|
| 186 | - |
|
| 187 | - if (empty($datetimes['nodes']) || (isset($_REQUEST['action']) && $_REQUEST['action'] === 'create_new')) { |
|
| 188 | - $this->addDefaultEntities($eventId); |
|
| 189 | - $datetimes = $this->getGraphQLDatetimes($eventId); |
|
| 190 | - } |
|
| 191 | - |
|
| 192 | - if (! empty($datetimes['nodes'])) { |
|
| 193 | - $datetimeIn = wp_list_pluck($datetimes['nodes'], 'id'); |
|
| 194 | - |
|
| 195 | - if (! empty($datetimeIn)) { |
|
| 196 | - $tickets = $this->getGraphQLTickets($datetimeIn); |
|
| 197 | - } |
|
| 198 | - } |
|
| 199 | - |
|
| 200 | - if (! empty($tickets['nodes'])) { |
|
| 201 | - $ticketIn = wp_list_pluck($tickets['nodes'], 'id'); |
|
| 202 | - |
|
| 203 | - if (! empty($ticketIn)) { |
|
| 204 | - $prices = $this->getGraphQLPrices($ticketIn); |
|
| 205 | - } |
|
| 206 | - } |
|
| 207 | - |
|
| 208 | - $priceTypes = $this->getGraphQLPriceTypes(); |
|
| 209 | - |
|
| 210 | - $relations = $this->getRelationalData($eventId); |
|
| 211 | - |
|
| 212 | - return compact('datetimes', 'tickets', 'prices', 'priceTypes', 'relations'); |
|
| 213 | - } |
|
| 214 | - |
|
| 215 | - /** |
|
| 216 | - * @param int $eventId |
|
| 217 | - * @throws DomainException |
|
| 218 | - * @throws EE_Error |
|
| 219 | - * @throws InvalidArgumentException |
|
| 220 | - * @throws InvalidDataTypeException |
|
| 221 | - * @throws InvalidInterfaceException |
|
| 222 | - * @throws ModelConfigurationException |
|
| 223 | - * @throws ReflectionException |
|
| 224 | - * @throws UnexpectedEntityException |
|
| 225 | - * @since $VID:$ |
|
| 226 | - */ |
|
| 227 | - protected function addDefaultEntities($eventId) |
|
| 228 | - { |
|
| 229 | - $default_dates = $this->datetime_model->create_new_blank_datetime(); |
|
| 230 | - if (is_array($default_dates) && isset($default_dates[0]) && $default_dates[0] instanceof EE_Datetime) { |
|
| 231 | - $default_date = $default_dates[0]; |
|
| 232 | - $default_date->save(); |
|
| 233 | - $default_date->_add_relation_to($eventId, 'Event'); |
|
| 234 | - $default_tickets = $this->ticket_model->get_all_default_tickets(); |
|
| 235 | - $default_prices = $this->price_model->get_all_default_prices(); |
|
| 236 | - foreach ($default_tickets as $default_ticket) { |
|
| 237 | - $default_ticket->save(); |
|
| 238 | - $default_ticket->_add_relation_to($default_date, 'Datetime'); |
|
| 239 | - foreach ($default_prices as $default_price) { |
|
| 240 | - $default_price->save(); |
|
| 241 | - $default_price->_add_relation_to($default_ticket, 'Ticket'); |
|
| 242 | - } |
|
| 243 | - } |
|
| 244 | - } |
|
| 245 | - } |
|
| 246 | - |
|
| 247 | - |
|
| 248 | - /** |
|
| 249 | - * @param int $eventId |
|
| 250 | - * @return array|null |
|
| 251 | - * @since $VID:$ |
|
| 252 | - */ |
|
| 253 | - protected function getGraphQLDatetimes($eventId) |
|
| 254 | - { |
|
| 255 | - $field_key = lcfirst($this->namespace) . 'Datetimes'; |
|
| 256 | - $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 | + $assets_url = EE_PLUGIN_DIR_URL . 'assets/dist/'; |
|
| 173 | + |
|
| 174 | + return compact('event', 'graphqlEndpoint', 'currentUser', 'generalSettings', 'i18n', 'assets_url'); |
|
| 175 | + } |
|
| 176 | + |
|
| 177 | + |
|
| 178 | + /** |
|
| 179 | + * @param int $eventId |
|
| 180 | + * @return array |
|
| 181 | + * @since $VID:$ |
|
| 182 | + */ |
|
| 183 | + protected function getEventGraphQLData($eventId) |
|
| 184 | + { |
|
| 185 | + $datetimes = $this->getGraphQLDatetimes($eventId); |
|
| 186 | + |
|
| 187 | + if (empty($datetimes['nodes']) || (isset($_REQUEST['action']) && $_REQUEST['action'] === 'create_new')) { |
|
| 188 | + $this->addDefaultEntities($eventId); |
|
| 189 | + $datetimes = $this->getGraphQLDatetimes($eventId); |
|
| 190 | + } |
|
| 191 | + |
|
| 192 | + if (! empty($datetimes['nodes'])) { |
|
| 193 | + $datetimeIn = wp_list_pluck($datetimes['nodes'], 'id'); |
|
| 194 | + |
|
| 195 | + if (! empty($datetimeIn)) { |
|
| 196 | + $tickets = $this->getGraphQLTickets($datetimeIn); |
|
| 197 | + } |
|
| 198 | + } |
|
| 199 | + |
|
| 200 | + if (! empty($tickets['nodes'])) { |
|
| 201 | + $ticketIn = wp_list_pluck($tickets['nodes'], 'id'); |
|
| 202 | + |
|
| 203 | + if (! empty($ticketIn)) { |
|
| 204 | + $prices = $this->getGraphQLPrices($ticketIn); |
|
| 205 | + } |
|
| 206 | + } |
|
| 207 | + |
|
| 208 | + $priceTypes = $this->getGraphQLPriceTypes(); |
|
| 209 | + |
|
| 210 | + $relations = $this->getRelationalData($eventId); |
|
| 211 | + |
|
| 212 | + return compact('datetimes', 'tickets', 'prices', 'priceTypes', 'relations'); |
|
| 213 | + } |
|
| 214 | + |
|
| 215 | + /** |
|
| 216 | + * @param int $eventId |
|
| 217 | + * @throws DomainException |
|
| 218 | + * @throws EE_Error |
|
| 219 | + * @throws InvalidArgumentException |
|
| 220 | + * @throws InvalidDataTypeException |
|
| 221 | + * @throws InvalidInterfaceException |
|
| 222 | + * @throws ModelConfigurationException |
|
| 223 | + * @throws ReflectionException |
|
| 224 | + * @throws UnexpectedEntityException |
|
| 225 | + * @since $VID:$ |
|
| 226 | + */ |
|
| 227 | + protected function addDefaultEntities($eventId) |
|
| 228 | + { |
|
| 229 | + $default_dates = $this->datetime_model->create_new_blank_datetime(); |
|
| 230 | + if (is_array($default_dates) && isset($default_dates[0]) && $default_dates[0] instanceof EE_Datetime) { |
|
| 231 | + $default_date = $default_dates[0]; |
|
| 232 | + $default_date->save(); |
|
| 233 | + $default_date->_add_relation_to($eventId, 'Event'); |
|
| 234 | + $default_tickets = $this->ticket_model->get_all_default_tickets(); |
|
| 235 | + $default_prices = $this->price_model->get_all_default_prices(); |
|
| 236 | + foreach ($default_tickets as $default_ticket) { |
|
| 237 | + $default_ticket->save(); |
|
| 238 | + $default_ticket->_add_relation_to($default_date, 'Datetime'); |
|
| 239 | + foreach ($default_prices as $default_price) { |
|
| 240 | + $default_price->save(); |
|
| 241 | + $default_price->_add_relation_to($default_ticket, 'Ticket'); |
|
| 242 | + } |
|
| 243 | + } |
|
| 244 | + } |
|
| 245 | + } |
|
| 246 | + |
|
| 247 | + |
|
| 248 | + /** |
|
| 249 | + * @param int $eventId |
|
| 250 | + * @return array|null |
|
| 251 | + * @since $VID:$ |
|
| 252 | + */ |
|
| 253 | + protected function getGraphQLDatetimes($eventId) |
|
| 254 | + { |
|
| 255 | + $field_key = lcfirst($this->namespace) . 'Datetimes'; |
|
| 256 | + $query = <<<QUERY |
|
| 257 | 257 | query GET_DATETIMES(\$where: {$this->namespace}RootQueryDatetimesConnectionWhereArgs, \$first: Int, \$last: Int ) { |
| 258 | 258 | {$field_key}(where: \$where, first: \$first, last: \$last) { |
| 259 | 259 | nodes { |
@@ -281,31 +281,31 @@ discard block |
||
| 281 | 281 | } |
| 282 | 282 | } |
| 283 | 283 | QUERY; |
| 284 | - $data = [ |
|
| 285 | - 'operation_name' => 'GET_DATETIMES', |
|
| 286 | - 'variables' => [ |
|
| 287 | - 'first' => 100, |
|
| 288 | - 'where' => [ |
|
| 289 | - 'eventId' => $eventId, |
|
| 290 | - ], |
|
| 291 | - ], |
|
| 292 | - 'query' => $query, |
|
| 293 | - ]; |
|
| 294 | - |
|
| 295 | - $responseData = $this->makeGraphQLRequest($data); |
|
| 296 | - return !empty($responseData[ $field_key ]) ? $responseData[ $field_key ] : null; |
|
| 297 | - } |
|
| 298 | - |
|
| 299 | - |
|
| 300 | - /** |
|
| 301 | - * @param array $datetimeIn |
|
| 302 | - * @return array|null |
|
| 303 | - * @since $VID:$ |
|
| 304 | - */ |
|
| 305 | - protected function getGraphQLTickets(array $datetimeIn) |
|
| 306 | - { |
|
| 307 | - $field_key = lcfirst($this->namespace) . 'Tickets'; |
|
| 308 | - $query = <<<QUERY |
|
| 284 | + $data = [ |
|
| 285 | + 'operation_name' => 'GET_DATETIMES', |
|
| 286 | + 'variables' => [ |
|
| 287 | + 'first' => 100, |
|
| 288 | + 'where' => [ |
|
| 289 | + 'eventId' => $eventId, |
|
| 290 | + ], |
|
| 291 | + ], |
|
| 292 | + 'query' => $query, |
|
| 293 | + ]; |
|
| 294 | + |
|
| 295 | + $responseData = $this->makeGraphQLRequest($data); |
|
| 296 | + return !empty($responseData[ $field_key ]) ? $responseData[ $field_key ] : null; |
|
| 297 | + } |
|
| 298 | + |
|
| 299 | + |
|
| 300 | + /** |
|
| 301 | + * @param array $datetimeIn |
|
| 302 | + * @return array|null |
|
| 303 | + * @since $VID:$ |
|
| 304 | + */ |
|
| 305 | + protected function getGraphQLTickets(array $datetimeIn) |
|
| 306 | + { |
|
| 307 | + $field_key = lcfirst($this->namespace) . 'Tickets'; |
|
| 308 | + $query = <<<QUERY |
|
| 309 | 309 | query GET_TICKETS(\$where: {$this->namespace}RootQueryTicketsConnectionWhereArgs, \$first: Int, \$last: Int ) { |
| 310 | 310 | {$field_key}(where: \$where, first: \$first, last: \$last) { |
| 311 | 311 | nodes { |
@@ -339,31 +339,31 @@ discard block |
||
| 339 | 339 | } |
| 340 | 340 | } |
| 341 | 341 | QUERY; |
| 342 | - $data = [ |
|
| 343 | - 'operation_name' => 'GET_TICKETS', |
|
| 344 | - 'variables' => [ |
|
| 345 | - 'first' => 100, |
|
| 346 | - 'where' => [ |
|
| 347 | - 'datetimeIn' => $datetimeIn, |
|
| 348 | - ], |
|
| 349 | - ], |
|
| 350 | - 'query' => $query, |
|
| 351 | - ]; |
|
| 352 | - |
|
| 353 | - $responseData = $this->makeGraphQLRequest($data); |
|
| 354 | - return !empty($responseData[ $field_key ]) ? $responseData[ $field_key ] : null; |
|
| 355 | - } |
|
| 356 | - |
|
| 357 | - |
|
| 358 | - /** |
|
| 359 | - * @param array $ticketIn |
|
| 360 | - * @return array|null |
|
| 361 | - * @since $VID:$ |
|
| 362 | - */ |
|
| 363 | - protected function getGraphQLPrices(array $ticketIn) |
|
| 364 | - { |
|
| 365 | - $field_key = lcfirst($this->namespace) . 'Prices'; |
|
| 366 | - $query = <<<QUERY |
|
| 342 | + $data = [ |
|
| 343 | + 'operation_name' => 'GET_TICKETS', |
|
| 344 | + 'variables' => [ |
|
| 345 | + 'first' => 100, |
|
| 346 | + 'where' => [ |
|
| 347 | + 'datetimeIn' => $datetimeIn, |
|
| 348 | + ], |
|
| 349 | + ], |
|
| 350 | + 'query' => $query, |
|
| 351 | + ]; |
|
| 352 | + |
|
| 353 | + $responseData = $this->makeGraphQLRequest($data); |
|
| 354 | + return !empty($responseData[ $field_key ]) ? $responseData[ $field_key ] : null; |
|
| 355 | + } |
|
| 356 | + |
|
| 357 | + |
|
| 358 | + /** |
|
| 359 | + * @param array $ticketIn |
|
| 360 | + * @return array|null |
|
| 361 | + * @since $VID:$ |
|
| 362 | + */ |
|
| 363 | + protected function getGraphQLPrices(array $ticketIn) |
|
| 364 | + { |
|
| 365 | + $field_key = lcfirst($this->namespace) . 'Prices'; |
|
| 366 | + $query = <<<QUERY |
|
| 367 | 367 | query GET_PRICES(\$where: {$this->namespace}RootQueryPricesConnectionWhereArgs, \$first: Int, \$last: Int ) { |
| 368 | 368 | {$field_key}(where: \$where, first: \$first, last: \$last) { |
| 369 | 369 | nodes { |
@@ -386,30 +386,30 @@ discard block |
||
| 386 | 386 | } |
| 387 | 387 | } |
| 388 | 388 | QUERY; |
| 389 | - $data = [ |
|
| 390 | - 'operation_name' => 'GET_PRICES', |
|
| 391 | - 'variables' => [ |
|
| 392 | - 'first' => 100, |
|
| 393 | - 'where' => [ |
|
| 394 | - 'ticketIn' => $ticketIn, |
|
| 395 | - ], |
|
| 396 | - ], |
|
| 397 | - 'query' => $query, |
|
| 398 | - ]; |
|
| 399 | - |
|
| 400 | - $responseData = $this->makeGraphQLRequest($data); |
|
| 401 | - return !empty($responseData[ $field_key ]) ? $responseData[ $field_key ] : null; |
|
| 402 | - } |
|
| 403 | - |
|
| 404 | - |
|
| 405 | - /** |
|
| 406 | - * @return array|null |
|
| 407 | - * @since $VID:$ |
|
| 408 | - */ |
|
| 409 | - protected function getGraphQLPriceTypes() |
|
| 410 | - { |
|
| 411 | - $field_key = lcfirst($this->namespace) . 'PriceTypes'; |
|
| 412 | - $query = <<<QUERY |
|
| 389 | + $data = [ |
|
| 390 | + 'operation_name' => 'GET_PRICES', |
|
| 391 | + 'variables' => [ |
|
| 392 | + 'first' => 100, |
|
| 393 | + 'where' => [ |
|
| 394 | + 'ticketIn' => $ticketIn, |
|
| 395 | + ], |
|
| 396 | + ], |
|
| 397 | + 'query' => $query, |
|
| 398 | + ]; |
|
| 399 | + |
|
| 400 | + $responseData = $this->makeGraphQLRequest($data); |
|
| 401 | + return !empty($responseData[ $field_key ]) ? $responseData[ $field_key ] : null; |
|
| 402 | + } |
|
| 403 | + |
|
| 404 | + |
|
| 405 | + /** |
|
| 406 | + * @return array|null |
|
| 407 | + * @since $VID:$ |
|
| 408 | + */ |
|
| 409 | + protected function getGraphQLPriceTypes() |
|
| 410 | + { |
|
| 411 | + $field_key = lcfirst($this->namespace) . 'PriceTypes'; |
|
| 412 | + $query = <<<QUERY |
|
| 413 | 413 | query GET_PRICE_TYPES(\$first: Int, \$last: Int ) { |
| 414 | 414 | {$field_key}(first: \$first, last: \$last) { |
| 415 | 415 | nodes { |
@@ -429,27 +429,27 @@ discard block |
||
| 429 | 429 | } |
| 430 | 430 | } |
| 431 | 431 | QUERY; |
| 432 | - $data = [ |
|
| 433 | - 'operation_name' => 'GET_PRICE_TYPES', |
|
| 434 | - 'variables' => [ |
|
| 435 | - 'first' => 100, |
|
| 436 | - ], |
|
| 437 | - 'query' => $query, |
|
| 438 | - ]; |
|
| 439 | - |
|
| 440 | - $responseData = $this->makeGraphQLRequest($data); |
|
| 441 | - return !empty($responseData[ $field_key ]) ? $responseData[ $field_key ] : null; |
|
| 442 | - } |
|
| 443 | - |
|
| 444 | - |
|
| 445 | - /** |
|
| 446 | - * @return array|null |
|
| 447 | - * @since $VID:$ |
|
| 448 | - */ |
|
| 449 | - protected function getGraphQLCurrentUser() |
|
| 450 | - { |
|
| 451 | - $field_key = 'viewer'; |
|
| 452 | - $query = <<<QUERY |
|
| 432 | + $data = [ |
|
| 433 | + 'operation_name' => 'GET_PRICE_TYPES', |
|
| 434 | + 'variables' => [ |
|
| 435 | + 'first' => 100, |
|
| 436 | + ], |
|
| 437 | + 'query' => $query, |
|
| 438 | + ]; |
|
| 439 | + |
|
| 440 | + $responseData = $this->makeGraphQLRequest($data); |
|
| 441 | + return !empty($responseData[ $field_key ]) ? $responseData[ $field_key ] : null; |
|
| 442 | + } |
|
| 443 | + |
|
| 444 | + |
|
| 445 | + /** |
|
| 446 | + * @return array|null |
|
| 447 | + * @since $VID:$ |
|
| 448 | + */ |
|
| 449 | + protected function getGraphQLCurrentUser() |
|
| 450 | + { |
|
| 451 | + $field_key = 'viewer'; |
|
| 452 | + $query = <<<QUERY |
|
| 453 | 453 | query GET_CURRENT_USER { |
| 454 | 454 | {$field_key} { |
| 455 | 455 | description |
@@ -467,24 +467,24 @@ discard block |
||
| 467 | 467 | } |
| 468 | 468 | } |
| 469 | 469 | QUERY; |
| 470 | - $data = [ |
|
| 471 | - 'operation_name' => 'GET_CURRENT_USER', |
|
| 472 | - 'query' => $query, |
|
| 473 | - ]; |
|
| 474 | - |
|
| 475 | - $responseData = $this->makeGraphQLRequest($data); |
|
| 476 | - return !empty($responseData[ $field_key ]) ? $responseData[ $field_key ] : null; |
|
| 477 | - } |
|
| 478 | - |
|
| 479 | - |
|
| 480 | - /** |
|
| 481 | - * @return array|null |
|
| 482 | - * @since $VID:$ |
|
| 483 | - */ |
|
| 484 | - protected function getGraphQLGeneralSettings() |
|
| 485 | - { |
|
| 486 | - $field_key = 'generalSettings'; |
|
| 487 | - $query = <<<QUERY |
|
| 470 | + $data = [ |
|
| 471 | + 'operation_name' => 'GET_CURRENT_USER', |
|
| 472 | + 'query' => $query, |
|
| 473 | + ]; |
|
| 474 | + |
|
| 475 | + $responseData = $this->makeGraphQLRequest($data); |
|
| 476 | + return !empty($responseData[ $field_key ]) ? $responseData[ $field_key ] : null; |
|
| 477 | + } |
|
| 478 | + |
|
| 479 | + |
|
| 480 | + /** |
|
| 481 | + * @return array|null |
|
| 482 | + * @since $VID:$ |
|
| 483 | + */ |
|
| 484 | + protected function getGraphQLGeneralSettings() |
|
| 485 | + { |
|
| 486 | + $field_key = 'generalSettings'; |
|
| 487 | + $query = <<<QUERY |
|
| 488 | 488 | query GET_GENERAL_SETTINGS { |
| 489 | 489 | {$field_key} { |
| 490 | 490 | dateFormat |
@@ -494,166 +494,166 @@ discard block |
||
| 494 | 494 | } |
| 495 | 495 | } |
| 496 | 496 | QUERY; |
| 497 | - $data = [ |
|
| 498 | - 'operation_name' => 'GET_CURRENT_USER', |
|
| 499 | - 'query' => $query, |
|
| 500 | - ]; |
|
| 501 | - |
|
| 502 | - $responseData = $this->makeGraphQLRequest($data); |
|
| 503 | - return !empty($responseData[ $field_key ]) ? $responseData[ $field_key ] : null; |
|
| 504 | - } |
|
| 505 | - |
|
| 506 | - |
|
| 507 | - /** |
|
| 508 | - * @param array $data |
|
| 509 | - * @return array |
|
| 510 | - * @since $VID:$ |
|
| 511 | - */ |
|
| 512 | - protected function makeGraphQLRequest($data) |
|
| 513 | - { |
|
| 514 | - try { |
|
| 515 | - $response = graphql($data); |
|
| 516 | - if (!empty($response['data'])) { |
|
| 517 | - return $response['data']; |
|
| 518 | - } |
|
| 519 | - return null; |
|
| 520 | - } catch (\Exception $e) { |
|
| 521 | - // do something with the errors thrown |
|
| 522 | - return null; |
|
| 523 | - } |
|
| 524 | - } |
|
| 525 | - |
|
| 526 | - |
|
| 527 | - /** |
|
| 528 | - * @param mixed $source The source that's passed down the GraphQL queries |
|
| 529 | - * @param array $args The inputArgs on the field |
|
| 530 | - * @param AppContext $context The AppContext passed down the GraphQL tree |
|
| 531 | - * @param ResolveInfo $info The ResolveInfo passed down the GraphQL tree |
|
| 532 | - * @return string |
|
| 533 | - * @throws EE_Error |
|
| 534 | - * @throws Exception |
|
| 535 | - * @throws InvalidArgumentException |
|
| 536 | - * @throws InvalidDataTypeException |
|
| 537 | - * @throws InvalidInterfaceException |
|
| 538 | - * @throws ReflectionException |
|
| 539 | - * @throws UserError |
|
| 540 | - * @throws UnexpectedEntityException |
|
| 541 | - * @since $VID:$ |
|
| 542 | - */ |
|
| 543 | - public static function getRelationalData($eventId) |
|
| 544 | - { |
|
| 545 | - $data = [ |
|
| 546 | - 'datetimes' => [], |
|
| 547 | - 'tickets' => [], |
|
| 548 | - 'prices' => [], |
|
| 549 | - ]; |
|
| 550 | - |
|
| 551 | - $eem_datetime = EEM_Datetime::instance(); |
|
| 552 | - $eem_ticket = EEM_Ticket::instance(); |
|
| 553 | - $eem_price = EEM_Price::instance(); |
|
| 554 | - $eem_price_type = EEM_Price_Type::instance(); |
|
| 555 | - |
|
| 556 | - // PROCESS DATETIMES |
|
| 557 | - $related_models = [ |
|
| 558 | - 'tickets' => $eem_ticket, |
|
| 559 | - ]; |
|
| 560 | - // Get the IDs of event datetimes. |
|
| 561 | - $datetimeIds = $eem_datetime->get_col([[ |
|
| 562 | - 'EVT_ID' => $eventId, |
|
| 563 | - 'DTT_deleted' => ['IN', [true, false]], |
|
| 564 | - ]]); |
|
| 565 | - foreach ($datetimeIds as $datetimeId) { |
|
| 566 | - $GID = self::convertToGlobalId($eem_datetime->item_name(), $datetimeId); |
|
| 567 | - foreach ($related_models as $key => $model) { |
|
| 568 | - // Get the IDs of related entities for the datetime ID. |
|
| 569 | - $Ids = $model->get_col([['Datetime.DTT_ID' => $datetimeId]]); |
|
| 570 | - $data['datetimes'][ $GID ][ $key ] = empty($Ids) ? [] : self::convertToGlobalId($model->item_name(), $Ids); |
|
| 571 | - } |
|
| 572 | - } |
|
| 573 | - |
|
| 574 | - // PROCESS TICKETS |
|
| 575 | - $related_models = [ |
|
| 576 | - 'datetimes' => $eem_datetime, |
|
| 577 | - 'prices' => $eem_price, |
|
| 578 | - ]; |
|
| 579 | - // Get the IDs of all datetime tickets. |
|
| 580 | - $ticketIds = $eem_ticket->get_col([[ |
|
| 581 | - 'Datetime.DTT_ID' => ['in', $datetimeIds], |
|
| 582 | - 'TKT_deleted' => ['IN', [true, false]], |
|
| 583 | - ]]); |
|
| 584 | - foreach ($ticketIds as $ticketId) { |
|
| 585 | - $GID = self::convertToGlobalId($eem_ticket->item_name(), $ticketId); |
|
| 586 | - |
|
| 587 | - foreach ($related_models as $key => $model) { |
|
| 588 | - // Get the IDs of related entities for the ticket ID. |
|
| 589 | - $Ids = $model->get_col([['Ticket.TKT_ID' => $ticketId]]); |
|
| 590 | - $data['tickets'][ $GID ][ $key ] = empty($Ids) ? [] : self::convertToGlobalId($model->item_name(), $Ids); |
|
| 591 | - } |
|
| 592 | - } |
|
| 593 | - |
|
| 594 | - // PROCESS PRICES |
|
| 595 | - $related_models = [ |
|
| 596 | - 'tickets' => $eem_ticket, |
|
| 597 | - 'priceTypes' => $eem_price_type, |
|
| 598 | - ]; |
|
| 599 | - // Get the IDs of all ticket prices. |
|
| 600 | - $priceIds = $eem_price->get_col([['Ticket.TKT_ID' => ['in', $ticketIds]]]); |
|
| 601 | - foreach ($priceIds as $priceId) { |
|
| 602 | - $GID = self::convertToGlobalId($eem_price->item_name(), $priceId); |
|
| 603 | - |
|
| 604 | - foreach ($related_models as $key => $model) { |
|
| 605 | - // Get the IDs of related entities for the price ID. |
|
| 606 | - $Ids = $model->get_col([['Price.PRC_ID' => $priceId]]); |
|
| 607 | - $data['prices'][ $GID ][ $key ] = empty($Ids) ? [] : self::convertToGlobalId($model->item_name(), $Ids); |
|
| 608 | - } |
|
| 609 | - } |
|
| 610 | - |
|
| 611 | - return $data; |
|
| 612 | - } |
|
| 613 | - |
|
| 614 | - /** |
|
| 615 | - * Convert the DB ID into GID |
|
| 616 | - * |
|
| 617 | - * @param string $type |
|
| 618 | - * @param int|int[] $ID |
|
| 619 | - * @return mixed |
|
| 620 | - */ |
|
| 621 | - public static function convertToGlobalId($type, $ID) |
|
| 622 | - { |
|
| 623 | - if (is_array($ID)) { |
|
| 624 | - return array_map(function ($id) use ($type) { |
|
| 625 | - return self::convertToGlobalId($type, $id); |
|
| 626 | - }, $ID); |
|
| 627 | - } |
|
| 628 | - return Relay::toGlobalId($type, $ID); |
|
| 629 | - } |
|
| 630 | - |
|
| 631 | - |
|
| 632 | - /** |
|
| 633 | - * Returns Jed-formatted localization data. |
|
| 634 | - * |
|
| 635 | - * @param string $domain Translation domain. |
|
| 636 | - * @return array |
|
| 637 | - */ |
|
| 638 | - public static function getJedLocaleData($domain) |
|
| 639 | - { |
|
| 640 | - $translations = get_translations_for_domain($domain); |
|
| 641 | - |
|
| 642 | - $locale = array( |
|
| 643 | - '' => array( |
|
| 644 | - 'domain' => $domain, |
|
| 645 | - 'lang' => is_admin() ? EEH_DTT_Helper::get_user_locale() : get_locale() |
|
| 646 | - ), |
|
| 647 | - ); |
|
| 648 | - |
|
| 649 | - if (! empty($translations->headers['Plural-Forms'])) { |
|
| 650 | - $locale['']['plural_forms'] = $translations->headers['Plural-Forms']; |
|
| 651 | - } |
|
| 652 | - |
|
| 653 | - foreach ($translations->entries as $msgid => $entry) { |
|
| 654 | - $locale[ $msgid ] = $entry->translations; |
|
| 655 | - } |
|
| 656 | - |
|
| 657 | - return $locale; |
|
| 658 | - } |
|
| 497 | + $data = [ |
|
| 498 | + 'operation_name' => 'GET_CURRENT_USER', |
|
| 499 | + 'query' => $query, |
|
| 500 | + ]; |
|
| 501 | + |
|
| 502 | + $responseData = $this->makeGraphQLRequest($data); |
|
| 503 | + return !empty($responseData[ $field_key ]) ? $responseData[ $field_key ] : null; |
|
| 504 | + } |
|
| 505 | + |
|
| 506 | + |
|
| 507 | + /** |
|
| 508 | + * @param array $data |
|
| 509 | + * @return array |
|
| 510 | + * @since $VID:$ |
|
| 511 | + */ |
|
| 512 | + protected function makeGraphQLRequest($data) |
|
| 513 | + { |
|
| 514 | + try { |
|
| 515 | + $response = graphql($data); |
|
| 516 | + if (!empty($response['data'])) { |
|
| 517 | + return $response['data']; |
|
| 518 | + } |
|
| 519 | + return null; |
|
| 520 | + } catch (\Exception $e) { |
|
| 521 | + // do something with the errors thrown |
|
| 522 | + return null; |
|
| 523 | + } |
|
| 524 | + } |
|
| 525 | + |
|
| 526 | + |
|
| 527 | + /** |
|
| 528 | + * @param mixed $source The source that's passed down the GraphQL queries |
|
| 529 | + * @param array $args The inputArgs on the field |
|
| 530 | + * @param AppContext $context The AppContext passed down the GraphQL tree |
|
| 531 | + * @param ResolveInfo $info The ResolveInfo passed down the GraphQL tree |
|
| 532 | + * @return string |
|
| 533 | + * @throws EE_Error |
|
| 534 | + * @throws Exception |
|
| 535 | + * @throws InvalidArgumentException |
|
| 536 | + * @throws InvalidDataTypeException |
|
| 537 | + * @throws InvalidInterfaceException |
|
| 538 | + * @throws ReflectionException |
|
| 539 | + * @throws UserError |
|
| 540 | + * @throws UnexpectedEntityException |
|
| 541 | + * @since $VID:$ |
|
| 542 | + */ |
|
| 543 | + public static function getRelationalData($eventId) |
|
| 544 | + { |
|
| 545 | + $data = [ |
|
| 546 | + 'datetimes' => [], |
|
| 547 | + 'tickets' => [], |
|
| 548 | + 'prices' => [], |
|
| 549 | + ]; |
|
| 550 | + |
|
| 551 | + $eem_datetime = EEM_Datetime::instance(); |
|
| 552 | + $eem_ticket = EEM_Ticket::instance(); |
|
| 553 | + $eem_price = EEM_Price::instance(); |
|
| 554 | + $eem_price_type = EEM_Price_Type::instance(); |
|
| 555 | + |
|
| 556 | + // PROCESS DATETIMES |
|
| 557 | + $related_models = [ |
|
| 558 | + 'tickets' => $eem_ticket, |
|
| 559 | + ]; |
|
| 560 | + // Get the IDs of event datetimes. |
|
| 561 | + $datetimeIds = $eem_datetime->get_col([[ |
|
| 562 | + 'EVT_ID' => $eventId, |
|
| 563 | + 'DTT_deleted' => ['IN', [true, false]], |
|
| 564 | + ]]); |
|
| 565 | + foreach ($datetimeIds as $datetimeId) { |
|
| 566 | + $GID = self::convertToGlobalId($eem_datetime->item_name(), $datetimeId); |
|
| 567 | + foreach ($related_models as $key => $model) { |
|
| 568 | + // Get the IDs of related entities for the datetime ID. |
|
| 569 | + $Ids = $model->get_col([['Datetime.DTT_ID' => $datetimeId]]); |
|
| 570 | + $data['datetimes'][ $GID ][ $key ] = empty($Ids) ? [] : self::convertToGlobalId($model->item_name(), $Ids); |
|
| 571 | + } |
|
| 572 | + } |
|
| 573 | + |
|
| 574 | + // PROCESS TICKETS |
|
| 575 | + $related_models = [ |
|
| 576 | + 'datetimes' => $eem_datetime, |
|
| 577 | + 'prices' => $eem_price, |
|
| 578 | + ]; |
|
| 579 | + // Get the IDs of all datetime tickets. |
|
| 580 | + $ticketIds = $eem_ticket->get_col([[ |
|
| 581 | + 'Datetime.DTT_ID' => ['in', $datetimeIds], |
|
| 582 | + 'TKT_deleted' => ['IN', [true, false]], |
|
| 583 | + ]]); |
|
| 584 | + foreach ($ticketIds as $ticketId) { |
|
| 585 | + $GID = self::convertToGlobalId($eem_ticket->item_name(), $ticketId); |
|
| 586 | + |
|
| 587 | + foreach ($related_models as $key => $model) { |
|
| 588 | + // Get the IDs of related entities for the ticket ID. |
|
| 589 | + $Ids = $model->get_col([['Ticket.TKT_ID' => $ticketId]]); |
|
| 590 | + $data['tickets'][ $GID ][ $key ] = empty($Ids) ? [] : self::convertToGlobalId($model->item_name(), $Ids); |
|
| 591 | + } |
|
| 592 | + } |
|
| 593 | + |
|
| 594 | + // PROCESS PRICES |
|
| 595 | + $related_models = [ |
|
| 596 | + 'tickets' => $eem_ticket, |
|
| 597 | + 'priceTypes' => $eem_price_type, |
|
| 598 | + ]; |
|
| 599 | + // Get the IDs of all ticket prices. |
|
| 600 | + $priceIds = $eem_price->get_col([['Ticket.TKT_ID' => ['in', $ticketIds]]]); |
|
| 601 | + foreach ($priceIds as $priceId) { |
|
| 602 | + $GID = self::convertToGlobalId($eem_price->item_name(), $priceId); |
|
| 603 | + |
|
| 604 | + foreach ($related_models as $key => $model) { |
|
| 605 | + // Get the IDs of related entities for the price ID. |
|
| 606 | + $Ids = $model->get_col([['Price.PRC_ID' => $priceId]]); |
|
| 607 | + $data['prices'][ $GID ][ $key ] = empty($Ids) ? [] : self::convertToGlobalId($model->item_name(), $Ids); |
|
| 608 | + } |
|
| 609 | + } |
|
| 610 | + |
|
| 611 | + return $data; |
|
| 612 | + } |
|
| 613 | + |
|
| 614 | + /** |
|
| 615 | + * Convert the DB ID into GID |
|
| 616 | + * |
|
| 617 | + * @param string $type |
|
| 618 | + * @param int|int[] $ID |
|
| 619 | + * @return mixed |
|
| 620 | + */ |
|
| 621 | + public static function convertToGlobalId($type, $ID) |
|
| 622 | + { |
|
| 623 | + if (is_array($ID)) { |
|
| 624 | + return array_map(function ($id) use ($type) { |
|
| 625 | + return self::convertToGlobalId($type, $id); |
|
| 626 | + }, $ID); |
|
| 627 | + } |
|
| 628 | + return Relay::toGlobalId($type, $ID); |
|
| 629 | + } |
|
| 630 | + |
|
| 631 | + |
|
| 632 | + /** |
|
| 633 | + * Returns Jed-formatted localization data. |
|
| 634 | + * |
|
| 635 | + * @param string $domain Translation domain. |
|
| 636 | + * @return array |
|
| 637 | + */ |
|
| 638 | + public static function getJedLocaleData($domain) |
|
| 639 | + { |
|
| 640 | + $translations = get_translations_for_domain($domain); |
|
| 641 | + |
|
| 642 | + $locale = array( |
|
| 643 | + '' => array( |
|
| 644 | + 'domain' => $domain, |
|
| 645 | + 'lang' => is_admin() ? EEH_DTT_Helper::get_user_locale() : get_locale() |
|
| 646 | + ), |
|
| 647 | + ); |
|
| 648 | + |
|
| 649 | + if (! empty($translations->headers['Plural-Forms'])) { |
|
| 650 | + $locale['']['plural_forms'] = $translations->headers['Plural-Forms']; |
|
| 651 | + } |
|
| 652 | + |
|
| 653 | + foreach ($translations->entries as $msgid => $entry) { |
|
| 654 | + $locale[ $msgid ] = $entry->translations; |
|
| 655 | + } |
|
| 656 | + |
|
| 657 | + return $locale; |
|
| 658 | + } |
|
| 659 | 659 | } |
@@ -103,7 +103,7 @@ discard block |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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(); |
@@ -169,7 +169,7 @@ discard block |
||
| 169 | 169 | |
| 170 | 170 | $i18n = self::getJedLocaleData('event_espresso'); |
| 171 | 171 | |
| 172 | - $assets_url = EE_PLUGIN_DIR_URL . 'assets/dist/'; |
|
| 172 | + $assets_url = EE_PLUGIN_DIR_URL.'assets/dist/'; |
|
| 173 | 173 | |
| 174 | 174 | return compact('event', 'graphqlEndpoint', 'currentUser', 'generalSettings', 'i18n', 'assets_url'); |
| 175 | 175 | } |
@@ -189,18 +189,18 @@ discard block |
||
| 189 | 189 | $datetimes = $this->getGraphQLDatetimes($eventId); |
| 190 | 190 | } |
| 191 | 191 | |
| 192 | - if (! empty($datetimes['nodes'])) { |
|
| 192 | + if ( ! empty($datetimes['nodes'])) { |
|
| 193 | 193 | $datetimeIn = wp_list_pluck($datetimes['nodes'], 'id'); |
| 194 | 194 | |
| 195 | - if (! empty($datetimeIn)) { |
|
| 195 | + if ( ! empty($datetimeIn)) { |
|
| 196 | 196 | $tickets = $this->getGraphQLTickets($datetimeIn); |
| 197 | 197 | } |
| 198 | 198 | } |
| 199 | 199 | |
| 200 | - if (! empty($tickets['nodes'])) { |
|
| 200 | + if ( ! empty($tickets['nodes'])) { |
|
| 201 | 201 | $ticketIn = wp_list_pluck($tickets['nodes'], 'id'); |
| 202 | 202 | |
| 203 | - if (! empty($ticketIn)) { |
|
| 203 | + if ( ! empty($ticketIn)) { |
|
| 204 | 204 | $prices = $this->getGraphQLPrices($ticketIn); |
| 205 | 205 | } |
| 206 | 206 | } |
@@ -252,7 +252,7 @@ discard block |
||
| 252 | 252 | */ |
| 253 | 253 | protected function getGraphQLDatetimes($eventId) |
| 254 | 254 | { |
| 255 | - $field_key = lcfirst($this->namespace) . 'Datetimes'; |
|
| 255 | + $field_key = lcfirst($this->namespace).'Datetimes'; |
|
| 256 | 256 | $query = <<<QUERY |
| 257 | 257 | query GET_DATETIMES(\$where: {$this->namespace}RootQueryDatetimesConnectionWhereArgs, \$first: Int, \$last: Int ) { |
| 258 | 258 | {$field_key}(where: \$where, first: \$first, last: \$last) { |
@@ -293,7 +293,7 @@ discard block |
||
| 293 | 293 | ]; |
| 294 | 294 | |
| 295 | 295 | $responseData = $this->makeGraphQLRequest($data); |
| 296 | - return !empty($responseData[ $field_key ]) ? $responseData[ $field_key ] : null; |
|
| 296 | + return ! empty($responseData[$field_key]) ? $responseData[$field_key] : null; |
|
| 297 | 297 | } |
| 298 | 298 | |
| 299 | 299 | |
@@ -304,7 +304,7 @@ discard block |
||
| 304 | 304 | */ |
| 305 | 305 | protected function getGraphQLTickets(array $datetimeIn) |
| 306 | 306 | { |
| 307 | - $field_key = lcfirst($this->namespace) . 'Tickets'; |
|
| 307 | + $field_key = lcfirst($this->namespace).'Tickets'; |
|
| 308 | 308 | $query = <<<QUERY |
| 309 | 309 | query GET_TICKETS(\$where: {$this->namespace}RootQueryTicketsConnectionWhereArgs, \$first: Int, \$last: Int ) { |
| 310 | 310 | {$field_key}(where: \$where, first: \$first, last: \$last) { |
@@ -351,7 +351,7 @@ discard block |
||
| 351 | 351 | ]; |
| 352 | 352 | |
| 353 | 353 | $responseData = $this->makeGraphQLRequest($data); |
| 354 | - return !empty($responseData[ $field_key ]) ? $responseData[ $field_key ] : null; |
|
| 354 | + return ! empty($responseData[$field_key]) ? $responseData[$field_key] : null; |
|
| 355 | 355 | } |
| 356 | 356 | |
| 357 | 357 | |
@@ -362,7 +362,7 @@ discard block |
||
| 362 | 362 | */ |
| 363 | 363 | protected function getGraphQLPrices(array $ticketIn) |
| 364 | 364 | { |
| 365 | - $field_key = lcfirst($this->namespace) . 'Prices'; |
|
| 365 | + $field_key = lcfirst($this->namespace).'Prices'; |
|
| 366 | 366 | $query = <<<QUERY |
| 367 | 367 | query GET_PRICES(\$where: {$this->namespace}RootQueryPricesConnectionWhereArgs, \$first: Int, \$last: Int ) { |
| 368 | 368 | {$field_key}(where: \$where, first: \$first, last: \$last) { |
@@ -398,7 +398,7 @@ discard block |
||
| 398 | 398 | ]; |
| 399 | 399 | |
| 400 | 400 | $responseData = $this->makeGraphQLRequest($data); |
| 401 | - return !empty($responseData[ $field_key ]) ? $responseData[ $field_key ] : null; |
|
| 401 | + return ! empty($responseData[$field_key]) ? $responseData[$field_key] : null; |
|
| 402 | 402 | } |
| 403 | 403 | |
| 404 | 404 | |
@@ -408,7 +408,7 @@ discard block |
||
| 408 | 408 | */ |
| 409 | 409 | protected function getGraphQLPriceTypes() |
| 410 | 410 | { |
| 411 | - $field_key = lcfirst($this->namespace) . 'PriceTypes'; |
|
| 411 | + $field_key = lcfirst($this->namespace).'PriceTypes'; |
|
| 412 | 412 | $query = <<<QUERY |
| 413 | 413 | query GET_PRICE_TYPES(\$first: Int, \$last: Int ) { |
| 414 | 414 | {$field_key}(first: \$first, last: \$last) { |
@@ -438,7 +438,7 @@ discard block |
||
| 438 | 438 | ]; |
| 439 | 439 | |
| 440 | 440 | $responseData = $this->makeGraphQLRequest($data); |
| 441 | - return !empty($responseData[ $field_key ]) ? $responseData[ $field_key ] : null; |
|
| 441 | + return ! empty($responseData[$field_key]) ? $responseData[$field_key] : null; |
|
| 442 | 442 | } |
| 443 | 443 | |
| 444 | 444 | |
@@ -473,7 +473,7 @@ discard block |
||
| 473 | 473 | ]; |
| 474 | 474 | |
| 475 | 475 | $responseData = $this->makeGraphQLRequest($data); |
| 476 | - return !empty($responseData[ $field_key ]) ? $responseData[ $field_key ] : null; |
|
| 476 | + return ! empty($responseData[$field_key]) ? $responseData[$field_key] : null; |
|
| 477 | 477 | } |
| 478 | 478 | |
| 479 | 479 | |
@@ -500,7 +500,7 @@ discard block |
||
| 500 | 500 | ]; |
| 501 | 501 | |
| 502 | 502 | $responseData = $this->makeGraphQLRequest($data); |
| 503 | - return !empty($responseData[ $field_key ]) ? $responseData[ $field_key ] : null; |
|
| 503 | + return ! empty($responseData[$field_key]) ? $responseData[$field_key] : null; |
|
| 504 | 504 | } |
| 505 | 505 | |
| 506 | 506 | |
@@ -513,7 +513,7 @@ discard block |
||
| 513 | 513 | { |
| 514 | 514 | try { |
| 515 | 515 | $response = graphql($data); |
| 516 | - if (!empty($response['data'])) { |
|
| 516 | + if ( ! empty($response['data'])) { |
|
| 517 | 517 | return $response['data']; |
| 518 | 518 | } |
| 519 | 519 | return null; |
@@ -567,7 +567,7 @@ discard block |
||
| 567 | 567 | foreach ($related_models as $key => $model) { |
| 568 | 568 | // Get the IDs of related entities for the datetime ID. |
| 569 | 569 | $Ids = $model->get_col([['Datetime.DTT_ID' => $datetimeId]]); |
| 570 | - $data['datetimes'][ $GID ][ $key ] = empty($Ids) ? [] : self::convertToGlobalId($model->item_name(), $Ids); |
|
| 570 | + $data['datetimes'][$GID][$key] = empty($Ids) ? [] : self::convertToGlobalId($model->item_name(), $Ids); |
|
| 571 | 571 | } |
| 572 | 572 | } |
| 573 | 573 | |
@@ -587,7 +587,7 @@ discard block |
||
| 587 | 587 | foreach ($related_models as $key => $model) { |
| 588 | 588 | // Get the IDs of related entities for the ticket ID. |
| 589 | 589 | $Ids = $model->get_col([['Ticket.TKT_ID' => $ticketId]]); |
| 590 | - $data['tickets'][ $GID ][ $key ] = empty($Ids) ? [] : self::convertToGlobalId($model->item_name(), $Ids); |
|
| 590 | + $data['tickets'][$GID][$key] = empty($Ids) ? [] : self::convertToGlobalId($model->item_name(), $Ids); |
|
| 591 | 591 | } |
| 592 | 592 | } |
| 593 | 593 | |
@@ -604,7 +604,7 @@ discard block |
||
| 604 | 604 | foreach ($related_models as $key => $model) { |
| 605 | 605 | // Get the IDs of related entities for the price ID. |
| 606 | 606 | $Ids = $model->get_col([['Price.PRC_ID' => $priceId]]); |
| 607 | - $data['prices'][ $GID ][ $key ] = empty($Ids) ? [] : self::convertToGlobalId($model->item_name(), $Ids); |
|
| 607 | + $data['prices'][$GID][$key] = empty($Ids) ? [] : self::convertToGlobalId($model->item_name(), $Ids); |
|
| 608 | 608 | } |
| 609 | 609 | } |
| 610 | 610 | |
@@ -621,7 +621,7 @@ discard block |
||
| 621 | 621 | public static function convertToGlobalId($type, $ID) |
| 622 | 622 | { |
| 623 | 623 | if (is_array($ID)) { |
| 624 | - return array_map(function ($id) use ($type) { |
|
| 624 | + return array_map(function($id) use ($type) { |
|
| 625 | 625 | return self::convertToGlobalId($type, $id); |
| 626 | 626 | }, $ID); |
| 627 | 627 | } |
@@ -646,12 +646,12 @@ discard block |
||
| 646 | 646 | ), |
| 647 | 647 | ); |
| 648 | 648 | |
| 649 | - if (! empty($translations->headers['Plural-Forms'])) { |
|
| 649 | + if ( ! empty($translations->headers['Plural-Forms'])) { |
|
| 650 | 650 | $locale['']['plural_forms'] = $translations->headers['Plural-Forms']; |
| 651 | 651 | } |
| 652 | 652 | |
| 653 | 653 | foreach ($translations->entries as $msgid => $entry) { |
| 654 | - $locale[ $msgid ] = $entry->translations; |
|
| 654 | + $locale[$msgid] = $entry->translations; |
|
| 655 | 655 | } |
| 656 | 656 | |
| 657 | 657 | return $locale; |