@@ -37,128 +37,128 @@ |
||
37 | 37 | * @since 4.0 |
38 | 38 | */ |
39 | 39 | if (function_exists('espresso_version')) { |
40 | - if (! function_exists('espresso_duplicate_plugin_error')) { |
|
41 | - /** |
|
42 | - * espresso_duplicate_plugin_error |
|
43 | - * displays if more than one version of EE is activated at the same time |
|
44 | - */ |
|
45 | - function espresso_duplicate_plugin_error() |
|
46 | - { |
|
47 | - ?> |
|
40 | + if (! function_exists('espresso_duplicate_plugin_error')) { |
|
41 | + /** |
|
42 | + * espresso_duplicate_plugin_error |
|
43 | + * displays if more than one version of EE is activated at the same time |
|
44 | + */ |
|
45 | + function espresso_duplicate_plugin_error() |
|
46 | + { |
|
47 | + ?> |
|
48 | 48 | <div class="error"> |
49 | 49 | <p> |
50 | 50 | <?php |
51 | - echo esc_html__( |
|
52 | - 'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.', |
|
53 | - 'event_espresso' |
|
54 | - ); ?> |
|
51 | + echo esc_html__( |
|
52 | + 'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.', |
|
53 | + 'event_espresso' |
|
54 | + ); ?> |
|
55 | 55 | </p> |
56 | 56 | </div> |
57 | 57 | <?php |
58 | - espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
59 | - } |
|
60 | - } |
|
61 | - add_action('admin_notices', 'espresso_duplicate_plugin_error', 1); |
|
58 | + espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
59 | + } |
|
60 | + } |
|
61 | + add_action('admin_notices', 'espresso_duplicate_plugin_error', 1); |
|
62 | 62 | } else { |
63 | - define('EE_MIN_PHP_VER_REQUIRED', '5.4.0'); |
|
64 | - if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { |
|
65 | - /** |
|
66 | - * espresso_minimum_php_version_error |
|
67 | - * |
|
68 | - * @return void |
|
69 | - */ |
|
70 | - function espresso_minimum_php_version_error() |
|
71 | - { |
|
72 | - ?> |
|
63 | + define('EE_MIN_PHP_VER_REQUIRED', '5.4.0'); |
|
64 | + if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { |
|
65 | + /** |
|
66 | + * espresso_minimum_php_version_error |
|
67 | + * |
|
68 | + * @return void |
|
69 | + */ |
|
70 | + function espresso_minimum_php_version_error() |
|
71 | + { |
|
72 | + ?> |
|
73 | 73 | <div class="error"> |
74 | 74 | <p> |
75 | 75 | <?php |
76 | - printf( |
|
77 | - esc_html__( |
|
78 | - 'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.', |
|
79 | - 'event_espresso' |
|
80 | - ), |
|
81 | - EE_MIN_PHP_VER_REQUIRED, |
|
82 | - PHP_VERSION, |
|
83 | - '<br/>', |
|
84 | - '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>' |
|
85 | - ); |
|
86 | - ?> |
|
76 | + printf( |
|
77 | + esc_html__( |
|
78 | + 'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.', |
|
79 | + 'event_espresso' |
|
80 | + ), |
|
81 | + EE_MIN_PHP_VER_REQUIRED, |
|
82 | + PHP_VERSION, |
|
83 | + '<br/>', |
|
84 | + '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>' |
|
85 | + ); |
|
86 | + ?> |
|
87 | 87 | </p> |
88 | 88 | </div> |
89 | 89 | <?php |
90 | - espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
91 | - } |
|
90 | + espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
91 | + } |
|
92 | 92 | |
93 | - add_action('admin_notices', 'espresso_minimum_php_version_error', 1); |
|
94 | - } else { |
|
95 | - define('EVENT_ESPRESSO_MAIN_FILE', __FILE__); |
|
96 | - /** |
|
97 | - * espresso_version |
|
98 | - * Returns the plugin version |
|
99 | - * |
|
100 | - * @return string |
|
101 | - */ |
|
102 | - function espresso_version() |
|
103 | - { |
|
104 | - return apply_filters('FHEE__espresso__espresso_version', '4.10.5.rc.000'); |
|
105 | - } |
|
93 | + add_action('admin_notices', 'espresso_minimum_php_version_error', 1); |
|
94 | + } else { |
|
95 | + define('EVENT_ESPRESSO_MAIN_FILE', __FILE__); |
|
96 | + /** |
|
97 | + * espresso_version |
|
98 | + * Returns the plugin version |
|
99 | + * |
|
100 | + * @return string |
|
101 | + */ |
|
102 | + function espresso_version() |
|
103 | + { |
|
104 | + return apply_filters('FHEE__espresso__espresso_version', '4.10.5.rc.000'); |
|
105 | + } |
|
106 | 106 | |
107 | - /** |
|
108 | - * espresso_plugin_activation |
|
109 | - * adds a wp-option to indicate that EE has been activated via the WP admin plugins page |
|
110 | - */ |
|
111 | - function espresso_plugin_activation() |
|
112 | - { |
|
113 | - update_option('ee_espresso_activation', true); |
|
107 | + /** |
|
108 | + * espresso_plugin_activation |
|
109 | + * adds a wp-option to indicate that EE has been activated via the WP admin plugins page |
|
110 | + */ |
|
111 | + function espresso_plugin_activation() |
|
112 | + { |
|
113 | + update_option('ee_espresso_activation', true); |
|
114 | 114 | |
115 | - // Run WP GraphQL activation callback |
|
116 | - if (PHP_VERSION_ID < 70000) { |
|
117 | - return; |
|
118 | - } |
|
119 | - if (! class_exists('WPGraphQL')) { |
|
120 | - require_once EE_THIRD_PARTY . 'wp-graphql/wp-graphql.php'; |
|
121 | - } |
|
122 | - graphql_init()->activate(); |
|
123 | - } |
|
115 | + // Run WP GraphQL activation callback |
|
116 | + if (PHP_VERSION_ID < 70000) { |
|
117 | + return; |
|
118 | + } |
|
119 | + if (! class_exists('WPGraphQL')) { |
|
120 | + require_once EE_THIRD_PARTY . 'wp-graphql/wp-graphql.php'; |
|
121 | + } |
|
122 | + graphql_init()->activate(); |
|
123 | + } |
|
124 | 124 | |
125 | - register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation'); |
|
125 | + register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation'); |
|
126 | 126 | |
127 | - /** |
|
128 | - * espresso_plugin_deactivation |
|
129 | - */ |
|
130 | - function espresso_plugin_deactivation() |
|
131 | - { |
|
132 | - // Run WP GraphQL deactivation callback |
|
133 | - if (PHP_VERSION_ID < 70000) { |
|
134 | - return; |
|
135 | - } |
|
136 | - if (! class_exists('WPGraphQL')) { |
|
137 | - require_once EE_THIRD_PARTY . 'wp-graphql/wp-graphql.php'; |
|
138 | - } |
|
139 | - graphql_init()->deactivate(); |
|
140 | - } |
|
141 | - register_deactivation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_deactivation'); |
|
127 | + /** |
|
128 | + * espresso_plugin_deactivation |
|
129 | + */ |
|
130 | + function espresso_plugin_deactivation() |
|
131 | + { |
|
132 | + // Run WP GraphQL deactivation callback |
|
133 | + if (PHP_VERSION_ID < 70000) { |
|
134 | + return; |
|
135 | + } |
|
136 | + if (! class_exists('WPGraphQL')) { |
|
137 | + require_once EE_THIRD_PARTY . 'wp-graphql/wp-graphql.php'; |
|
138 | + } |
|
139 | + graphql_init()->deactivate(); |
|
140 | + } |
|
141 | + register_deactivation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_deactivation'); |
|
142 | 142 | |
143 | - require_once __DIR__ . '/core/bootstrap_espresso.php'; |
|
144 | - bootstrap_espresso(); |
|
145 | - } |
|
143 | + require_once __DIR__ . '/core/bootstrap_espresso.php'; |
|
144 | + bootstrap_espresso(); |
|
145 | + } |
|
146 | 146 | } |
147 | 147 | if (! function_exists('espresso_deactivate_plugin')) { |
148 | - /** |
|
149 | - * deactivate_plugin |
|
150 | - * usage: espresso_deactivate_plugin( plugin_basename( __FILE__ )); |
|
151 | - * |
|
152 | - * @access public |
|
153 | - * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file |
|
154 | - * @return void |
|
155 | - */ |
|
156 | - function espresso_deactivate_plugin($plugin_basename = '') |
|
157 | - { |
|
158 | - if (! function_exists('deactivate_plugins')) { |
|
159 | - require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
|
160 | - } |
|
161 | - unset($_GET['activate'], $_REQUEST['activate']); |
|
162 | - deactivate_plugins($plugin_basename); |
|
163 | - } |
|
148 | + /** |
|
149 | + * deactivate_plugin |
|
150 | + * usage: espresso_deactivate_plugin( plugin_basename( __FILE__ )); |
|
151 | + * |
|
152 | + * @access public |
|
153 | + * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file |
|
154 | + * @return void |
|
155 | + */ |
|
156 | + function espresso_deactivate_plugin($plugin_basename = '') |
|
157 | + { |
|
158 | + if (! function_exists('deactivate_plugins')) { |
|
159 | + require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
|
160 | + } |
|
161 | + unset($_GET['activate'], $_REQUEST['activate']); |
|
162 | + deactivate_plugins($plugin_basename); |
|
163 | + } |
|
164 | 164 | } |
@@ -37,7 +37,7 @@ discard block |
||
37 | 37 | * @since 4.0 |
38 | 38 | */ |
39 | 39 | if (function_exists('espresso_version')) { |
40 | - if (! function_exists('espresso_duplicate_plugin_error')) { |
|
40 | + if ( ! function_exists('espresso_duplicate_plugin_error')) { |
|
41 | 41 | /** |
42 | 42 | * espresso_duplicate_plugin_error |
43 | 43 | * displays if more than one version of EE is activated at the same time |
@@ -61,7 +61,7 @@ discard block |
||
61 | 61 | add_action('admin_notices', 'espresso_duplicate_plugin_error', 1); |
62 | 62 | } else { |
63 | 63 | define('EE_MIN_PHP_VER_REQUIRED', '5.4.0'); |
64 | - if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { |
|
64 | + if ( ! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { |
|
65 | 65 | /** |
66 | 66 | * espresso_minimum_php_version_error |
67 | 67 | * |
@@ -116,8 +116,8 @@ discard block |
||
116 | 116 | if (PHP_VERSION_ID < 70000) { |
117 | 117 | return; |
118 | 118 | } |
119 | - if (! class_exists('WPGraphQL')) { |
|
120 | - require_once EE_THIRD_PARTY . 'wp-graphql/wp-graphql.php'; |
|
119 | + if ( ! class_exists('WPGraphQL')) { |
|
120 | + require_once EE_THIRD_PARTY.'wp-graphql/wp-graphql.php'; |
|
121 | 121 | } |
122 | 122 | graphql_init()->activate(); |
123 | 123 | } |
@@ -133,18 +133,18 @@ discard block |
||
133 | 133 | if (PHP_VERSION_ID < 70000) { |
134 | 134 | return; |
135 | 135 | } |
136 | - if (! class_exists('WPGraphQL')) { |
|
137 | - require_once EE_THIRD_PARTY . 'wp-graphql/wp-graphql.php'; |
|
136 | + if ( ! class_exists('WPGraphQL')) { |
|
137 | + require_once EE_THIRD_PARTY.'wp-graphql/wp-graphql.php'; |
|
138 | 138 | } |
139 | 139 | graphql_init()->deactivate(); |
140 | 140 | } |
141 | 141 | register_deactivation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_deactivation'); |
142 | 142 | |
143 | - require_once __DIR__ . '/core/bootstrap_espresso.php'; |
|
143 | + require_once __DIR__.'/core/bootstrap_espresso.php'; |
|
144 | 144 | bootstrap_espresso(); |
145 | 145 | } |
146 | 146 | } |
147 | -if (! function_exists('espresso_deactivate_plugin')) { |
|
147 | +if ( ! function_exists('espresso_deactivate_plugin')) { |
|
148 | 148 | /** |
149 | 149 | * deactivate_plugin |
150 | 150 | * usage: espresso_deactivate_plugin( plugin_basename( __FILE__ )); |
@@ -155,8 +155,8 @@ discard block |
||
155 | 155 | */ |
156 | 156 | function espresso_deactivate_plugin($plugin_basename = '') |
157 | 157 | { |
158 | - if (! function_exists('deactivate_plugins')) { |
|
159 | - require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
|
158 | + if ( ! function_exists('deactivate_plugins')) { |
|
159 | + require_once ABSPATH.'wp-admin/includes/plugin.php'; |
|
160 | 160 | } |
161 | 161 | unset($_GET['activate'], $_REQUEST['activate']); |
162 | 162 | deactivate_plugins($plugin_basename); |
@@ -35,213 +35,213 @@ 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 | - } |
|
129 | - } |
|
130 | - } |
|
131 | - |
|
132 | - |
|
133 | - /** |
|
134 | - * @param int $eventId |
|
135 | - * @return array |
|
136 | - * @throws EE_Error |
|
137 | - * @throws InvalidDataTypeException |
|
138 | - * @throws InvalidInterfaceException |
|
139 | - * @throws ModelConfigurationException |
|
140 | - * @throws UnexpectedEntityException |
|
141 | - * @throws InvalidArgumentException |
|
142 | - * @throws ReflectionException |
|
143 | - * @throws DomainException |
|
144 | - * @since $VID:$ |
|
145 | - */ |
|
146 | - protected function getEditorData($eventId) |
|
147 | - { |
|
148 | - $event = $this->getEventGraphQLData($eventId); |
|
149 | - $event['dbId'] = $eventId; |
|
150 | - |
|
151 | - $graphqlEndpoint = class_exists('WPGraphQL') ? trailingslashit(site_url()) . Router::$route : ''; |
|
152 | - $graphqlEndpoint = esc_url($graphqlEndpoint); |
|
153 | - |
|
154 | - $currentUser = $this->getGraphQLCurrentUser(); |
|
155 | - |
|
156 | - $generalSettings = $this->getGraphQLGeneralSettings(); |
|
157 | - |
|
158 | - $i18n = self::getJedLocaleData('event_espresso'); |
|
159 | - |
|
160 | - $assetsUrl = EE_PLUGIN_DIR_URL . 'assets/dist/'; |
|
161 | - |
|
162 | - return compact('event', 'graphqlEndpoint', 'currentUser', 'generalSettings', 'i18n', 'assetsUrl'); |
|
163 | - } |
|
164 | - |
|
165 | - |
|
166 | - /** |
|
167 | - * @param int $eventId |
|
168 | - * @return array |
|
169 | - * @since $VID:$ |
|
170 | - */ |
|
171 | - protected function getEventGraphQLData($eventId) |
|
172 | - { |
|
173 | - $datetimes = $this->getGraphQLDatetimes($eventId); |
|
174 | - |
|
175 | - if (empty($datetimes['nodes']) || (isset($_REQUEST['action']) && $_REQUEST['action'] === 'create_new')) { |
|
176 | - $this->addDefaultEntities($eventId); |
|
177 | - $datetimes = $this->getGraphQLDatetimes($eventId); |
|
178 | - } |
|
179 | - |
|
180 | - if (! empty($datetimes['nodes'])) { |
|
181 | - $datetimeIn = wp_list_pluck($datetimes['nodes'], 'id'); |
|
182 | - |
|
183 | - if (! empty($datetimeIn)) { |
|
184 | - $tickets = $this->getGraphQLTickets($datetimeIn); |
|
185 | - } |
|
186 | - } |
|
187 | - |
|
188 | - if (! empty($tickets['nodes'])) { |
|
189 | - $ticketIn = wp_list_pluck($tickets['nodes'], 'id'); |
|
190 | - |
|
191 | - if (! empty($ticketIn)) { |
|
192 | - $prices = $this->getGraphQLPrices($ticketIn); |
|
193 | - } |
|
194 | - } |
|
195 | - |
|
196 | - $priceTypes = $this->getGraphQLPriceTypes(); |
|
197 | - |
|
198 | - $relations = $this->getRelationalData($eventId); |
|
199 | - |
|
200 | - return compact('datetimes', 'tickets', 'prices', 'priceTypes', 'relations'); |
|
201 | - } |
|
202 | - |
|
203 | - /** |
|
204 | - * @param int $eventId |
|
205 | - * @throws DomainException |
|
206 | - * @throws EE_Error |
|
207 | - * @throws InvalidArgumentException |
|
208 | - * @throws InvalidDataTypeException |
|
209 | - * @throws InvalidInterfaceException |
|
210 | - * @throws ModelConfigurationException |
|
211 | - * @throws ReflectionException |
|
212 | - * @throws UnexpectedEntityException |
|
213 | - * @since $VID:$ |
|
214 | - */ |
|
215 | - protected function addDefaultEntities($eventId) |
|
216 | - { |
|
217 | - $default_dates = $this->datetime_model->create_new_blank_datetime(); |
|
218 | - if (is_array($default_dates) && isset($default_dates[0]) && $default_dates[0] instanceof EE_Datetime) { |
|
219 | - $default_date = $default_dates[0]; |
|
220 | - $default_date->save(); |
|
221 | - $default_date->_add_relation_to($eventId, 'Event'); |
|
222 | - $default_tickets = $this->ticket_model->get_all_default_tickets(); |
|
223 | - $default_prices = $this->price_model->get_all_default_prices(); |
|
224 | - foreach ($default_tickets as $default_ticket) { |
|
225 | - $default_ticket->save(); |
|
226 | - $default_ticket->_add_relation_to($default_date, 'Datetime'); |
|
227 | - foreach ($default_prices as $default_price) { |
|
228 | - $default_price->save(); |
|
229 | - $default_price->_add_relation_to($default_ticket, 'Ticket'); |
|
230 | - } |
|
231 | - } |
|
232 | - } |
|
233 | - } |
|
234 | - |
|
235 | - |
|
236 | - /** |
|
237 | - * @param int $eventId |
|
238 | - * @return array|null |
|
239 | - * @since $VID:$ |
|
240 | - */ |
|
241 | - protected function getGraphQLDatetimes($eventId) |
|
242 | - { |
|
243 | - $field_key = lcfirst($this->namespace) . 'Datetimes'; |
|
244 | - $query = <<<QUERY |
|
124 | + 'before' |
|
125 | + ); |
|
126 | + } |
|
127 | + ); |
|
128 | + } |
|
129 | + } |
|
130 | + } |
|
131 | + |
|
132 | + |
|
133 | + /** |
|
134 | + * @param int $eventId |
|
135 | + * @return array |
|
136 | + * @throws EE_Error |
|
137 | + * @throws InvalidDataTypeException |
|
138 | + * @throws InvalidInterfaceException |
|
139 | + * @throws ModelConfigurationException |
|
140 | + * @throws UnexpectedEntityException |
|
141 | + * @throws InvalidArgumentException |
|
142 | + * @throws ReflectionException |
|
143 | + * @throws DomainException |
|
144 | + * @since $VID:$ |
|
145 | + */ |
|
146 | + protected function getEditorData($eventId) |
|
147 | + { |
|
148 | + $event = $this->getEventGraphQLData($eventId); |
|
149 | + $event['dbId'] = $eventId; |
|
150 | + |
|
151 | + $graphqlEndpoint = class_exists('WPGraphQL') ? trailingslashit(site_url()) . Router::$route : ''; |
|
152 | + $graphqlEndpoint = esc_url($graphqlEndpoint); |
|
153 | + |
|
154 | + $currentUser = $this->getGraphQLCurrentUser(); |
|
155 | + |
|
156 | + $generalSettings = $this->getGraphQLGeneralSettings(); |
|
157 | + |
|
158 | + $i18n = self::getJedLocaleData('event_espresso'); |
|
159 | + |
|
160 | + $assetsUrl = EE_PLUGIN_DIR_URL . 'assets/dist/'; |
|
161 | + |
|
162 | + return compact('event', 'graphqlEndpoint', 'currentUser', 'generalSettings', 'i18n', 'assetsUrl'); |
|
163 | + } |
|
164 | + |
|
165 | + |
|
166 | + /** |
|
167 | + * @param int $eventId |
|
168 | + * @return array |
|
169 | + * @since $VID:$ |
|
170 | + */ |
|
171 | + protected function getEventGraphQLData($eventId) |
|
172 | + { |
|
173 | + $datetimes = $this->getGraphQLDatetimes($eventId); |
|
174 | + |
|
175 | + if (empty($datetimes['nodes']) || (isset($_REQUEST['action']) && $_REQUEST['action'] === 'create_new')) { |
|
176 | + $this->addDefaultEntities($eventId); |
|
177 | + $datetimes = $this->getGraphQLDatetimes($eventId); |
|
178 | + } |
|
179 | + |
|
180 | + if (! empty($datetimes['nodes'])) { |
|
181 | + $datetimeIn = wp_list_pluck($datetimes['nodes'], 'id'); |
|
182 | + |
|
183 | + if (! empty($datetimeIn)) { |
|
184 | + $tickets = $this->getGraphQLTickets($datetimeIn); |
|
185 | + } |
|
186 | + } |
|
187 | + |
|
188 | + if (! empty($tickets['nodes'])) { |
|
189 | + $ticketIn = wp_list_pluck($tickets['nodes'], 'id'); |
|
190 | + |
|
191 | + if (! empty($ticketIn)) { |
|
192 | + $prices = $this->getGraphQLPrices($ticketIn); |
|
193 | + } |
|
194 | + } |
|
195 | + |
|
196 | + $priceTypes = $this->getGraphQLPriceTypes(); |
|
197 | + |
|
198 | + $relations = $this->getRelationalData($eventId); |
|
199 | + |
|
200 | + return compact('datetimes', 'tickets', 'prices', 'priceTypes', 'relations'); |
|
201 | + } |
|
202 | + |
|
203 | + /** |
|
204 | + * @param int $eventId |
|
205 | + * @throws DomainException |
|
206 | + * @throws EE_Error |
|
207 | + * @throws InvalidArgumentException |
|
208 | + * @throws InvalidDataTypeException |
|
209 | + * @throws InvalidInterfaceException |
|
210 | + * @throws ModelConfigurationException |
|
211 | + * @throws ReflectionException |
|
212 | + * @throws UnexpectedEntityException |
|
213 | + * @since $VID:$ |
|
214 | + */ |
|
215 | + protected function addDefaultEntities($eventId) |
|
216 | + { |
|
217 | + $default_dates = $this->datetime_model->create_new_blank_datetime(); |
|
218 | + if (is_array($default_dates) && isset($default_dates[0]) && $default_dates[0] instanceof EE_Datetime) { |
|
219 | + $default_date = $default_dates[0]; |
|
220 | + $default_date->save(); |
|
221 | + $default_date->_add_relation_to($eventId, 'Event'); |
|
222 | + $default_tickets = $this->ticket_model->get_all_default_tickets(); |
|
223 | + $default_prices = $this->price_model->get_all_default_prices(); |
|
224 | + foreach ($default_tickets as $default_ticket) { |
|
225 | + $default_ticket->save(); |
|
226 | + $default_ticket->_add_relation_to($default_date, 'Datetime'); |
|
227 | + foreach ($default_prices as $default_price) { |
|
228 | + $default_price->save(); |
|
229 | + $default_price->_add_relation_to($default_ticket, 'Ticket'); |
|
230 | + } |
|
231 | + } |
|
232 | + } |
|
233 | + } |
|
234 | + |
|
235 | + |
|
236 | + /** |
|
237 | + * @param int $eventId |
|
238 | + * @return array|null |
|
239 | + * @since $VID:$ |
|
240 | + */ |
|
241 | + protected function getGraphQLDatetimes($eventId) |
|
242 | + { |
|
243 | + $field_key = lcfirst($this->namespace) . 'Datetimes'; |
|
244 | + $query = <<<QUERY |
|
245 | 245 | query GET_DATETIMES(\$where: {$this->namespace}RootQueryDatetimesConnectionWhereArgs, \$first: Int, \$last: Int ) { |
246 | 246 | {$field_key}(where: \$where, first: \$first, last: \$last) { |
247 | 247 | nodes { |
@@ -270,31 +270,31 @@ discard block |
||
270 | 270 | } |
271 | 271 | } |
272 | 272 | QUERY; |
273 | - $data = [ |
|
274 | - 'operation_name' => 'GET_DATETIMES', |
|
275 | - 'variables' => [ |
|
276 | - 'first' => 100, |
|
277 | - 'where' => [ |
|
278 | - 'eventId' => $eventId, |
|
279 | - ], |
|
280 | - ], |
|
281 | - 'query' => $query, |
|
282 | - ]; |
|
283 | - |
|
284 | - $responseData = $this->makeGraphQLRequest($data); |
|
285 | - return !empty($responseData[ $field_key ]) ? $responseData[ $field_key ] : null; |
|
286 | - } |
|
287 | - |
|
288 | - |
|
289 | - /** |
|
290 | - * @param array $datetimeIn |
|
291 | - * @return array|null |
|
292 | - * @since $VID:$ |
|
293 | - */ |
|
294 | - protected function getGraphQLTickets(array $datetimeIn) |
|
295 | - { |
|
296 | - $field_key = lcfirst($this->namespace) . 'Tickets'; |
|
297 | - $query = <<<QUERY |
|
273 | + $data = [ |
|
274 | + 'operation_name' => 'GET_DATETIMES', |
|
275 | + 'variables' => [ |
|
276 | + 'first' => 100, |
|
277 | + 'where' => [ |
|
278 | + 'eventId' => $eventId, |
|
279 | + ], |
|
280 | + ], |
|
281 | + 'query' => $query, |
|
282 | + ]; |
|
283 | + |
|
284 | + $responseData = $this->makeGraphQLRequest($data); |
|
285 | + return !empty($responseData[ $field_key ]) ? $responseData[ $field_key ] : null; |
|
286 | + } |
|
287 | + |
|
288 | + |
|
289 | + /** |
|
290 | + * @param array $datetimeIn |
|
291 | + * @return array|null |
|
292 | + * @since $VID:$ |
|
293 | + */ |
|
294 | + protected function getGraphQLTickets(array $datetimeIn) |
|
295 | + { |
|
296 | + $field_key = lcfirst($this->namespace) . 'Tickets'; |
|
297 | + $query = <<<QUERY |
|
298 | 298 | query GET_TICKETS(\$where: {$this->namespace}RootQueryTicketsConnectionWhereArgs, \$first: Int, \$last: Int ) { |
299 | 299 | {$field_key}(where: \$where, first: \$first, last: \$last) { |
300 | 300 | nodes { |
@@ -330,31 +330,31 @@ discard block |
||
330 | 330 | } |
331 | 331 | } |
332 | 332 | QUERY; |
333 | - $data = [ |
|
334 | - 'operation_name' => 'GET_TICKETS', |
|
335 | - 'variables' => [ |
|
336 | - 'first' => 100, |
|
337 | - 'where' => [ |
|
338 | - 'datetimeIn' => $datetimeIn, |
|
339 | - ], |
|
340 | - ], |
|
341 | - 'query' => $query, |
|
342 | - ]; |
|
343 | - |
|
344 | - $responseData = $this->makeGraphQLRequest($data); |
|
345 | - return !empty($responseData[ $field_key ]) ? $responseData[ $field_key ] : null; |
|
346 | - } |
|
347 | - |
|
348 | - |
|
349 | - /** |
|
350 | - * @param array $ticketIn |
|
351 | - * @return array|null |
|
352 | - * @since $VID:$ |
|
353 | - */ |
|
354 | - protected function getGraphQLPrices(array $ticketIn) |
|
355 | - { |
|
356 | - $field_key = lcfirst($this->namespace) . 'Prices'; |
|
357 | - $query = <<<QUERY |
|
333 | + $data = [ |
|
334 | + 'operation_name' => 'GET_TICKETS', |
|
335 | + 'variables' => [ |
|
336 | + 'first' => 100, |
|
337 | + 'where' => [ |
|
338 | + 'datetimeIn' => $datetimeIn, |
|
339 | + ], |
|
340 | + ], |
|
341 | + 'query' => $query, |
|
342 | + ]; |
|
343 | + |
|
344 | + $responseData = $this->makeGraphQLRequest($data); |
|
345 | + return !empty($responseData[ $field_key ]) ? $responseData[ $field_key ] : null; |
|
346 | + } |
|
347 | + |
|
348 | + |
|
349 | + /** |
|
350 | + * @param array $ticketIn |
|
351 | + * @return array|null |
|
352 | + * @since $VID:$ |
|
353 | + */ |
|
354 | + protected function getGraphQLPrices(array $ticketIn) |
|
355 | + { |
|
356 | + $field_key = lcfirst($this->namespace) . 'Prices'; |
|
357 | + $query = <<<QUERY |
|
358 | 358 | query GET_PRICES(\$where: {$this->namespace}RootQueryPricesConnectionWhereArgs, \$first: Int, \$last: Int ) { |
359 | 359 | {$field_key}(where: \$where, first: \$first, last: \$last) { |
360 | 360 | nodes { |
@@ -378,30 +378,30 @@ discard block |
||
378 | 378 | } |
379 | 379 | } |
380 | 380 | QUERY; |
381 | - $data = [ |
|
382 | - 'operation_name' => 'GET_PRICES', |
|
383 | - 'variables' => [ |
|
384 | - 'first' => 100, |
|
385 | - 'where' => [ |
|
386 | - 'ticketIn' => $ticketIn, |
|
387 | - ], |
|
388 | - ], |
|
389 | - 'query' => $query, |
|
390 | - ]; |
|
391 | - |
|
392 | - $responseData = $this->makeGraphQLRequest($data); |
|
393 | - return !empty($responseData[ $field_key ]) ? $responseData[ $field_key ] : null; |
|
394 | - } |
|
395 | - |
|
396 | - |
|
397 | - /** |
|
398 | - * @return array|null |
|
399 | - * @since $VID:$ |
|
400 | - */ |
|
401 | - protected function getGraphQLPriceTypes() |
|
402 | - { |
|
403 | - $field_key = lcfirst($this->namespace) . 'PriceTypes'; |
|
404 | - $query = <<<QUERY |
|
381 | + $data = [ |
|
382 | + 'operation_name' => 'GET_PRICES', |
|
383 | + 'variables' => [ |
|
384 | + 'first' => 100, |
|
385 | + 'where' => [ |
|
386 | + 'ticketIn' => $ticketIn, |
|
387 | + ], |
|
388 | + ], |
|
389 | + 'query' => $query, |
|
390 | + ]; |
|
391 | + |
|
392 | + $responseData = $this->makeGraphQLRequest($data); |
|
393 | + return !empty($responseData[ $field_key ]) ? $responseData[ $field_key ] : null; |
|
394 | + } |
|
395 | + |
|
396 | + |
|
397 | + /** |
|
398 | + * @return array|null |
|
399 | + * @since $VID:$ |
|
400 | + */ |
|
401 | + protected function getGraphQLPriceTypes() |
|
402 | + { |
|
403 | + $field_key = lcfirst($this->namespace) . 'PriceTypes'; |
|
404 | + $query = <<<QUERY |
|
405 | 405 | query GET_PRICE_TYPES(\$first: Int, \$last: Int ) { |
406 | 406 | {$field_key}(first: \$first, last: \$last) { |
407 | 407 | nodes { |
@@ -422,27 +422,27 @@ discard block |
||
422 | 422 | } |
423 | 423 | } |
424 | 424 | QUERY; |
425 | - $data = [ |
|
426 | - 'operation_name' => 'GET_PRICE_TYPES', |
|
427 | - 'variables' => [ |
|
428 | - 'first' => 100, |
|
429 | - ], |
|
430 | - 'query' => $query, |
|
431 | - ]; |
|
432 | - |
|
433 | - $responseData = $this->makeGraphQLRequest($data); |
|
434 | - return !empty($responseData[ $field_key ]) ? $responseData[ $field_key ] : null; |
|
435 | - } |
|
436 | - |
|
437 | - |
|
438 | - /** |
|
439 | - * @return array|null |
|
440 | - * @since $VID:$ |
|
441 | - */ |
|
442 | - protected function getGraphQLCurrentUser() |
|
443 | - { |
|
444 | - $field_key = 'viewer'; |
|
445 | - $query = <<<QUERY |
|
425 | + $data = [ |
|
426 | + 'operation_name' => 'GET_PRICE_TYPES', |
|
427 | + 'variables' => [ |
|
428 | + 'first' => 100, |
|
429 | + ], |
|
430 | + 'query' => $query, |
|
431 | + ]; |
|
432 | + |
|
433 | + $responseData = $this->makeGraphQLRequest($data); |
|
434 | + return !empty($responseData[ $field_key ]) ? $responseData[ $field_key ] : null; |
|
435 | + } |
|
436 | + |
|
437 | + |
|
438 | + /** |
|
439 | + * @return array|null |
|
440 | + * @since $VID:$ |
|
441 | + */ |
|
442 | + protected function getGraphQLCurrentUser() |
|
443 | + { |
|
444 | + $field_key = 'viewer'; |
|
445 | + $query = <<<QUERY |
|
446 | 446 | query GET_CURRENT_USER { |
447 | 447 | {$field_key} { |
448 | 448 | description |
@@ -460,24 +460,24 @@ discard block |
||
460 | 460 | } |
461 | 461 | } |
462 | 462 | QUERY; |
463 | - $data = [ |
|
464 | - 'operation_name' => 'GET_CURRENT_USER', |
|
465 | - 'query' => $query, |
|
466 | - ]; |
|
467 | - |
|
468 | - $responseData = $this->makeGraphQLRequest($data); |
|
469 | - return !empty($responseData[ $field_key ]) ? $responseData[ $field_key ] : null; |
|
470 | - } |
|
471 | - |
|
472 | - |
|
473 | - /** |
|
474 | - * @return array|null |
|
475 | - * @since $VID:$ |
|
476 | - */ |
|
477 | - protected function getGraphQLGeneralSettings() |
|
478 | - { |
|
479 | - $field_key = 'generalSettings'; |
|
480 | - $query = <<<QUERY |
|
463 | + $data = [ |
|
464 | + 'operation_name' => 'GET_CURRENT_USER', |
|
465 | + 'query' => $query, |
|
466 | + ]; |
|
467 | + |
|
468 | + $responseData = $this->makeGraphQLRequest($data); |
|
469 | + return !empty($responseData[ $field_key ]) ? $responseData[ $field_key ] : null; |
|
470 | + } |
|
471 | + |
|
472 | + |
|
473 | + /** |
|
474 | + * @return array|null |
|
475 | + * @since $VID:$ |
|
476 | + */ |
|
477 | + protected function getGraphQLGeneralSettings() |
|
478 | + { |
|
479 | + $field_key = 'generalSettings'; |
|
480 | + $query = <<<QUERY |
|
481 | 481 | query GET_GENERAL_SETTINGS { |
482 | 482 | {$field_key} { |
483 | 483 | dateFormat |
@@ -487,185 +487,185 @@ discard block |
||
487 | 487 | } |
488 | 488 | } |
489 | 489 | QUERY; |
490 | - $data = [ |
|
491 | - 'operation_name' => 'GET_CURRENT_USER', |
|
492 | - 'query' => $query, |
|
493 | - ]; |
|
494 | - |
|
495 | - $responseData = $this->makeGraphQLRequest($data); |
|
496 | - return !empty($responseData[ $field_key ]) ? $responseData[ $field_key ] : null; |
|
497 | - } |
|
498 | - |
|
499 | - |
|
500 | - /** |
|
501 | - * @param array $data |
|
502 | - * @return array |
|
503 | - * @since $VID:$ |
|
504 | - */ |
|
505 | - protected function makeGraphQLRequest($data) |
|
506 | - { |
|
507 | - try { |
|
508 | - $response = graphql($data); |
|
509 | - if (!empty($response['data'])) { |
|
510 | - return $response['data']; |
|
511 | - } |
|
512 | - return null; |
|
513 | - } catch (\Exception $e) { |
|
514 | - // do something with the errors thrown |
|
515 | - return null; |
|
516 | - } |
|
517 | - } |
|
518 | - |
|
519 | - |
|
520 | - /** |
|
521 | - * @param mixed $source The source that's passed down the GraphQL queries |
|
522 | - * @param array $args The inputArgs on the field |
|
523 | - * @param AppContext $context The AppContext passed down the GraphQL tree |
|
524 | - * @param ResolveInfo $info The ResolveInfo passed down the GraphQL tree |
|
525 | - * @return string |
|
526 | - * @throws EE_Error |
|
527 | - * @throws Exception |
|
528 | - * @throws InvalidArgumentException |
|
529 | - * @throws InvalidDataTypeException |
|
530 | - * @throws InvalidInterfaceException |
|
531 | - * @throws ReflectionException |
|
532 | - * @throws UserError |
|
533 | - * @throws UnexpectedEntityException |
|
534 | - * @since $VID:$ |
|
535 | - */ |
|
536 | - public static function getRelationalData($eventId) |
|
537 | - { |
|
538 | - $data = [ |
|
539 | - 'datetimes' => [], |
|
540 | - 'tickets' => [], |
|
541 | - 'prices' => [], |
|
542 | - ]; |
|
543 | - |
|
544 | - $eem_datetime = EEM_Datetime::instance(); |
|
545 | - $eem_ticket = EEM_Ticket::instance(); |
|
546 | - $eem_price = EEM_Price::instance(); |
|
547 | - $eem_price_type = EEM_Price_Type::instance(); |
|
548 | - |
|
549 | - // PROCESS DATETIMES |
|
550 | - $related_models = [ |
|
551 | - 'tickets' => $eem_ticket, |
|
552 | - ]; |
|
553 | - // Get the IDs of event datetimes. |
|
554 | - $datetimeIds = $eem_datetime->get_col([ |
|
555 | - [ |
|
556 | - 'EVT_ID' => $eventId, |
|
557 | - ], |
|
558 | - 'default_where_conditions' => 'minimum', |
|
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([ |
|
565 | - [ |
|
566 | - 'Datetime.DTT_ID' => $datetimeId, |
|
567 | - ], |
|
568 | - 'default_where_conditions' => 'minimum', |
|
569 | - ]); |
|
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 | - [ |
|
582 | - 'Datetime.DTT_ID' => ['IN', $datetimeIds], |
|
583 | - ], |
|
584 | - 'default_where_conditions' => 'minimum', |
|
585 | - ]); |
|
586 | - foreach ($ticketIds as $ticketId) { |
|
587 | - $GID = self::convertToGlobalId($eem_ticket->item_name(), $ticketId); |
|
588 | - |
|
589 | - foreach ($related_models as $key => $model) { |
|
590 | - // Get the IDs of related entities for the ticket ID. |
|
591 | - $Ids = $model->get_col([ |
|
592 | - [ |
|
593 | - 'Ticket.TKT_ID' => $ticketId, |
|
594 | - ], |
|
595 | - 'default_where_conditions' => 'minimum', |
|
596 | - ]); |
|
597 | - $data['tickets'][ $GID ][ $key ] = empty($Ids) ? [] : self::convertToGlobalId($model->item_name(), $Ids); |
|
598 | - } |
|
599 | - } |
|
600 | - |
|
601 | - // PROCESS PRICES |
|
602 | - $related_models = [ |
|
603 | - 'tickets' => $eem_ticket, |
|
604 | - 'priceTypes' => $eem_price_type, |
|
605 | - ]; |
|
606 | - // Get the IDs of all ticket prices. |
|
607 | - $priceIds = $eem_price->get_col([['Ticket.TKT_ID' => ['IN', $ticketIds]]]); |
|
608 | - foreach ($priceIds as $priceId) { |
|
609 | - $GID = self::convertToGlobalId($eem_price->item_name(), $priceId); |
|
610 | - |
|
611 | - foreach ($related_models as $key => $model) { |
|
612 | - // Get the IDs of related entities for the price ID. |
|
613 | - $Ids = $model->get_col([ |
|
614 | - [ |
|
615 | - 'Price.PRC_ID' => $priceId, |
|
616 | - ], |
|
617 | - 'default_where_conditions' => 'minimum', |
|
618 | - ]); |
|
619 | - $data['prices'][ $GID ][ $key ] = empty($Ids) ? [] : self::convertToGlobalId($model->item_name(), $Ids); |
|
620 | - } |
|
621 | - } |
|
622 | - |
|
623 | - return $data; |
|
624 | - } |
|
625 | - |
|
626 | - /** |
|
627 | - * Convert the DB ID into GID |
|
628 | - * |
|
629 | - * @param string $type |
|
630 | - * @param int|int[] $ID |
|
631 | - * @return mixed |
|
632 | - */ |
|
633 | - public static function convertToGlobalId($type, $ID) |
|
634 | - { |
|
635 | - if (is_array($ID)) { |
|
636 | - return array_map(function ($id) use ($type) { |
|
637 | - return self::convertToGlobalId($type, $id); |
|
638 | - }, $ID); |
|
639 | - } |
|
640 | - return Relay::toGlobalId($type, $ID); |
|
641 | - } |
|
642 | - |
|
643 | - |
|
644 | - /** |
|
645 | - * Returns Jed-formatted localization data. |
|
646 | - * |
|
647 | - * @param string $domain Translation domain. |
|
648 | - * @return array |
|
649 | - */ |
|
650 | - public static function getJedLocaleData($domain) |
|
651 | - { |
|
652 | - $translations = get_translations_for_domain($domain); |
|
653 | - |
|
654 | - $locale = array( |
|
655 | - '' => array( |
|
656 | - 'domain' => $domain, |
|
657 | - 'lang' => is_admin() ? EEH_DTT_Helper::get_user_locale() : get_locale() |
|
658 | - ), |
|
659 | - ); |
|
660 | - |
|
661 | - if (! empty($translations->headers['Plural-Forms'])) { |
|
662 | - $locale['']['plural_forms'] = $translations->headers['Plural-Forms']; |
|
663 | - } |
|
664 | - |
|
665 | - foreach ($translations->entries as $msgid => $entry) { |
|
666 | - $locale[ $msgid ] = $entry->translations; |
|
667 | - } |
|
668 | - |
|
669 | - return $locale; |
|
670 | - } |
|
490 | + $data = [ |
|
491 | + 'operation_name' => 'GET_CURRENT_USER', |
|
492 | + 'query' => $query, |
|
493 | + ]; |
|
494 | + |
|
495 | + $responseData = $this->makeGraphQLRequest($data); |
|
496 | + return !empty($responseData[ $field_key ]) ? $responseData[ $field_key ] : null; |
|
497 | + } |
|
498 | + |
|
499 | + |
|
500 | + /** |
|
501 | + * @param array $data |
|
502 | + * @return array |
|
503 | + * @since $VID:$ |
|
504 | + */ |
|
505 | + protected function makeGraphQLRequest($data) |
|
506 | + { |
|
507 | + try { |
|
508 | + $response = graphql($data); |
|
509 | + if (!empty($response['data'])) { |
|
510 | + return $response['data']; |
|
511 | + } |
|
512 | + return null; |
|
513 | + } catch (\Exception $e) { |
|
514 | + // do something with the errors thrown |
|
515 | + return null; |
|
516 | + } |
|
517 | + } |
|
518 | + |
|
519 | + |
|
520 | + /** |
|
521 | + * @param mixed $source The source that's passed down the GraphQL queries |
|
522 | + * @param array $args The inputArgs on the field |
|
523 | + * @param AppContext $context The AppContext passed down the GraphQL tree |
|
524 | + * @param ResolveInfo $info The ResolveInfo passed down the GraphQL tree |
|
525 | + * @return string |
|
526 | + * @throws EE_Error |
|
527 | + * @throws Exception |
|
528 | + * @throws InvalidArgumentException |
|
529 | + * @throws InvalidDataTypeException |
|
530 | + * @throws InvalidInterfaceException |
|
531 | + * @throws ReflectionException |
|
532 | + * @throws UserError |
|
533 | + * @throws UnexpectedEntityException |
|
534 | + * @since $VID:$ |
|
535 | + */ |
|
536 | + public static function getRelationalData($eventId) |
|
537 | + { |
|
538 | + $data = [ |
|
539 | + 'datetimes' => [], |
|
540 | + 'tickets' => [], |
|
541 | + 'prices' => [], |
|
542 | + ]; |
|
543 | + |
|
544 | + $eem_datetime = EEM_Datetime::instance(); |
|
545 | + $eem_ticket = EEM_Ticket::instance(); |
|
546 | + $eem_price = EEM_Price::instance(); |
|
547 | + $eem_price_type = EEM_Price_Type::instance(); |
|
548 | + |
|
549 | + // PROCESS DATETIMES |
|
550 | + $related_models = [ |
|
551 | + 'tickets' => $eem_ticket, |
|
552 | + ]; |
|
553 | + // Get the IDs of event datetimes. |
|
554 | + $datetimeIds = $eem_datetime->get_col([ |
|
555 | + [ |
|
556 | + 'EVT_ID' => $eventId, |
|
557 | + ], |
|
558 | + 'default_where_conditions' => 'minimum', |
|
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([ |
|
565 | + [ |
|
566 | + 'Datetime.DTT_ID' => $datetimeId, |
|
567 | + ], |
|
568 | + 'default_where_conditions' => 'minimum', |
|
569 | + ]); |
|
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 | + [ |
|
582 | + 'Datetime.DTT_ID' => ['IN', $datetimeIds], |
|
583 | + ], |
|
584 | + 'default_where_conditions' => 'minimum', |
|
585 | + ]); |
|
586 | + foreach ($ticketIds as $ticketId) { |
|
587 | + $GID = self::convertToGlobalId($eem_ticket->item_name(), $ticketId); |
|
588 | + |
|
589 | + foreach ($related_models as $key => $model) { |
|
590 | + // Get the IDs of related entities for the ticket ID. |
|
591 | + $Ids = $model->get_col([ |
|
592 | + [ |
|
593 | + 'Ticket.TKT_ID' => $ticketId, |
|
594 | + ], |
|
595 | + 'default_where_conditions' => 'minimum', |
|
596 | + ]); |
|
597 | + $data['tickets'][ $GID ][ $key ] = empty($Ids) ? [] : self::convertToGlobalId($model->item_name(), $Ids); |
|
598 | + } |
|
599 | + } |
|
600 | + |
|
601 | + // PROCESS PRICES |
|
602 | + $related_models = [ |
|
603 | + 'tickets' => $eem_ticket, |
|
604 | + 'priceTypes' => $eem_price_type, |
|
605 | + ]; |
|
606 | + // Get the IDs of all ticket prices. |
|
607 | + $priceIds = $eem_price->get_col([['Ticket.TKT_ID' => ['IN', $ticketIds]]]); |
|
608 | + foreach ($priceIds as $priceId) { |
|
609 | + $GID = self::convertToGlobalId($eem_price->item_name(), $priceId); |
|
610 | + |
|
611 | + foreach ($related_models as $key => $model) { |
|
612 | + // Get the IDs of related entities for the price ID. |
|
613 | + $Ids = $model->get_col([ |
|
614 | + [ |
|
615 | + 'Price.PRC_ID' => $priceId, |
|
616 | + ], |
|
617 | + 'default_where_conditions' => 'minimum', |
|
618 | + ]); |
|
619 | + $data['prices'][ $GID ][ $key ] = empty($Ids) ? [] : self::convertToGlobalId($model->item_name(), $Ids); |
|
620 | + } |
|
621 | + } |
|
622 | + |
|
623 | + return $data; |
|
624 | + } |
|
625 | + |
|
626 | + /** |
|
627 | + * Convert the DB ID into GID |
|
628 | + * |
|
629 | + * @param string $type |
|
630 | + * @param int|int[] $ID |
|
631 | + * @return mixed |
|
632 | + */ |
|
633 | + public static function convertToGlobalId($type, $ID) |
|
634 | + { |
|
635 | + if (is_array($ID)) { |
|
636 | + return array_map(function ($id) use ($type) { |
|
637 | + return self::convertToGlobalId($type, $id); |
|
638 | + }, $ID); |
|
639 | + } |
|
640 | + return Relay::toGlobalId($type, $ID); |
|
641 | + } |
|
642 | + |
|
643 | + |
|
644 | + /** |
|
645 | + * Returns Jed-formatted localization data. |
|
646 | + * |
|
647 | + * @param string $domain Translation domain. |
|
648 | + * @return array |
|
649 | + */ |
|
650 | + public static function getJedLocaleData($domain) |
|
651 | + { |
|
652 | + $translations = get_translations_for_domain($domain); |
|
653 | + |
|
654 | + $locale = array( |
|
655 | + '' => array( |
|
656 | + 'domain' => $domain, |
|
657 | + 'lang' => is_admin() ? EEH_DTT_Helper::get_user_locale() : get_locale() |
|
658 | + ), |
|
659 | + ); |
|
660 | + |
|
661 | + if (! empty($translations->headers['Plural-Forms'])) { |
|
662 | + $locale['']['plural_forms'] = $translations->headers['Plural-Forms']; |
|
663 | + } |
|
664 | + |
|
665 | + foreach ($translations->entries as $msgid => $entry) { |
|
666 | + $locale[ $msgid ] = $entry->translations; |
|
667 | + } |
|
668 | + |
|
669 | + return $locale; |
|
670 | + } |
|
671 | 671 | } |
@@ -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 | " |
@@ -148,7 +148,7 @@ discard block |
||
148 | 148 | $event = $this->getEventGraphQLData($eventId); |
149 | 149 | $event['dbId'] = $eventId; |
150 | 150 | |
151 | - $graphqlEndpoint = class_exists('WPGraphQL') ? trailingslashit(site_url()) . Router::$route : ''; |
|
151 | + $graphqlEndpoint = class_exists('WPGraphQL') ? trailingslashit(site_url()).Router::$route : ''; |
|
152 | 152 | $graphqlEndpoint = esc_url($graphqlEndpoint); |
153 | 153 | |
154 | 154 | $currentUser = $this->getGraphQLCurrentUser(); |
@@ -157,7 +157,7 @@ discard block |
||
157 | 157 | |
158 | 158 | $i18n = self::getJedLocaleData('event_espresso'); |
159 | 159 | |
160 | - $assetsUrl = EE_PLUGIN_DIR_URL . 'assets/dist/'; |
|
160 | + $assetsUrl = EE_PLUGIN_DIR_URL.'assets/dist/'; |
|
161 | 161 | |
162 | 162 | return compact('event', 'graphqlEndpoint', 'currentUser', 'generalSettings', 'i18n', 'assetsUrl'); |
163 | 163 | } |
@@ -177,18 +177,18 @@ discard block |
||
177 | 177 | $datetimes = $this->getGraphQLDatetimes($eventId); |
178 | 178 | } |
179 | 179 | |
180 | - if (! empty($datetimes['nodes'])) { |
|
180 | + if ( ! empty($datetimes['nodes'])) { |
|
181 | 181 | $datetimeIn = wp_list_pluck($datetimes['nodes'], 'id'); |
182 | 182 | |
183 | - if (! empty($datetimeIn)) { |
|
183 | + if ( ! empty($datetimeIn)) { |
|
184 | 184 | $tickets = $this->getGraphQLTickets($datetimeIn); |
185 | 185 | } |
186 | 186 | } |
187 | 187 | |
188 | - if (! empty($tickets['nodes'])) { |
|
188 | + if ( ! empty($tickets['nodes'])) { |
|
189 | 189 | $ticketIn = wp_list_pluck($tickets['nodes'], 'id'); |
190 | 190 | |
191 | - if (! empty($ticketIn)) { |
|
191 | + if ( ! empty($ticketIn)) { |
|
192 | 192 | $prices = $this->getGraphQLPrices($ticketIn); |
193 | 193 | } |
194 | 194 | } |
@@ -240,7 +240,7 @@ discard block |
||
240 | 240 | */ |
241 | 241 | protected function getGraphQLDatetimes($eventId) |
242 | 242 | { |
243 | - $field_key = lcfirst($this->namespace) . 'Datetimes'; |
|
243 | + $field_key = lcfirst($this->namespace).'Datetimes'; |
|
244 | 244 | $query = <<<QUERY |
245 | 245 | query GET_DATETIMES(\$where: {$this->namespace}RootQueryDatetimesConnectionWhereArgs, \$first: Int, \$last: Int ) { |
246 | 246 | {$field_key}(where: \$where, first: \$first, last: \$last) { |
@@ -282,7 +282,7 @@ discard block |
||
282 | 282 | ]; |
283 | 283 | |
284 | 284 | $responseData = $this->makeGraphQLRequest($data); |
285 | - return !empty($responseData[ $field_key ]) ? $responseData[ $field_key ] : null; |
|
285 | + return ! empty($responseData[$field_key]) ? $responseData[$field_key] : null; |
|
286 | 286 | } |
287 | 287 | |
288 | 288 | |
@@ -293,7 +293,7 @@ discard block |
||
293 | 293 | */ |
294 | 294 | protected function getGraphQLTickets(array $datetimeIn) |
295 | 295 | { |
296 | - $field_key = lcfirst($this->namespace) . 'Tickets'; |
|
296 | + $field_key = lcfirst($this->namespace).'Tickets'; |
|
297 | 297 | $query = <<<QUERY |
298 | 298 | query GET_TICKETS(\$where: {$this->namespace}RootQueryTicketsConnectionWhereArgs, \$first: Int, \$last: Int ) { |
299 | 299 | {$field_key}(where: \$where, first: \$first, last: \$last) { |
@@ -342,7 +342,7 @@ discard block |
||
342 | 342 | ]; |
343 | 343 | |
344 | 344 | $responseData = $this->makeGraphQLRequest($data); |
345 | - return !empty($responseData[ $field_key ]) ? $responseData[ $field_key ] : null; |
|
345 | + return ! empty($responseData[$field_key]) ? $responseData[$field_key] : null; |
|
346 | 346 | } |
347 | 347 | |
348 | 348 | |
@@ -353,7 +353,7 @@ discard block |
||
353 | 353 | */ |
354 | 354 | protected function getGraphQLPrices(array $ticketIn) |
355 | 355 | { |
356 | - $field_key = lcfirst($this->namespace) . 'Prices'; |
|
356 | + $field_key = lcfirst($this->namespace).'Prices'; |
|
357 | 357 | $query = <<<QUERY |
358 | 358 | query GET_PRICES(\$where: {$this->namespace}RootQueryPricesConnectionWhereArgs, \$first: Int, \$last: Int ) { |
359 | 359 | {$field_key}(where: \$where, first: \$first, last: \$last) { |
@@ -390,7 +390,7 @@ discard block |
||
390 | 390 | ]; |
391 | 391 | |
392 | 392 | $responseData = $this->makeGraphQLRequest($data); |
393 | - return !empty($responseData[ $field_key ]) ? $responseData[ $field_key ] : null; |
|
393 | + return ! empty($responseData[$field_key]) ? $responseData[$field_key] : null; |
|
394 | 394 | } |
395 | 395 | |
396 | 396 | |
@@ -400,7 +400,7 @@ discard block |
||
400 | 400 | */ |
401 | 401 | protected function getGraphQLPriceTypes() |
402 | 402 | { |
403 | - $field_key = lcfirst($this->namespace) . 'PriceTypes'; |
|
403 | + $field_key = lcfirst($this->namespace).'PriceTypes'; |
|
404 | 404 | $query = <<<QUERY |
405 | 405 | query GET_PRICE_TYPES(\$first: Int, \$last: Int ) { |
406 | 406 | {$field_key}(first: \$first, last: \$last) { |
@@ -431,7 +431,7 @@ discard block |
||
431 | 431 | ]; |
432 | 432 | |
433 | 433 | $responseData = $this->makeGraphQLRequest($data); |
434 | - return !empty($responseData[ $field_key ]) ? $responseData[ $field_key ] : null; |
|
434 | + return ! empty($responseData[$field_key]) ? $responseData[$field_key] : null; |
|
435 | 435 | } |
436 | 436 | |
437 | 437 | |
@@ -466,7 +466,7 @@ discard block |
||
466 | 466 | ]; |
467 | 467 | |
468 | 468 | $responseData = $this->makeGraphQLRequest($data); |
469 | - return !empty($responseData[ $field_key ]) ? $responseData[ $field_key ] : null; |
|
469 | + return ! empty($responseData[$field_key]) ? $responseData[$field_key] : null; |
|
470 | 470 | } |
471 | 471 | |
472 | 472 | |
@@ -493,7 +493,7 @@ discard block |
||
493 | 493 | ]; |
494 | 494 | |
495 | 495 | $responseData = $this->makeGraphQLRequest($data); |
496 | - return !empty($responseData[ $field_key ]) ? $responseData[ $field_key ] : null; |
|
496 | + return ! empty($responseData[$field_key]) ? $responseData[$field_key] : null; |
|
497 | 497 | } |
498 | 498 | |
499 | 499 | |
@@ -506,7 +506,7 @@ discard block |
||
506 | 506 | { |
507 | 507 | try { |
508 | 508 | $response = graphql($data); |
509 | - if (!empty($response['data'])) { |
|
509 | + if ( ! empty($response['data'])) { |
|
510 | 510 | return $response['data']; |
511 | 511 | } |
512 | 512 | return null; |
@@ -567,7 +567,7 @@ discard block |
||
567 | 567 | ], |
568 | 568 | 'default_where_conditions' => 'minimum', |
569 | 569 | ]); |
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 | |
@@ -594,7 +594,7 @@ discard block |
||
594 | 594 | ], |
595 | 595 | 'default_where_conditions' => 'minimum', |
596 | 596 | ]); |
597 | - $data['tickets'][ $GID ][ $key ] = empty($Ids) ? [] : self::convertToGlobalId($model->item_name(), $Ids); |
|
597 | + $data['tickets'][$GID][$key] = empty($Ids) ? [] : self::convertToGlobalId($model->item_name(), $Ids); |
|
598 | 598 | } |
599 | 599 | } |
600 | 600 | |
@@ -616,7 +616,7 @@ discard block |
||
616 | 616 | ], |
617 | 617 | 'default_where_conditions' => 'minimum', |
618 | 618 | ]); |
619 | - $data['prices'][ $GID ][ $key ] = empty($Ids) ? [] : self::convertToGlobalId($model->item_name(), $Ids); |
|
619 | + $data['prices'][$GID][$key] = empty($Ids) ? [] : self::convertToGlobalId($model->item_name(), $Ids); |
|
620 | 620 | } |
621 | 621 | } |
622 | 622 | |
@@ -633,7 +633,7 @@ discard block |
||
633 | 633 | public static function convertToGlobalId($type, $ID) |
634 | 634 | { |
635 | 635 | if (is_array($ID)) { |
636 | - return array_map(function ($id) use ($type) { |
|
636 | + return array_map(function($id) use ($type) { |
|
637 | 637 | return self::convertToGlobalId($type, $id); |
638 | 638 | }, $ID); |
639 | 639 | } |
@@ -658,12 +658,12 @@ discard block |
||
658 | 658 | ), |
659 | 659 | ); |
660 | 660 | |
661 | - if (! empty($translations->headers['Plural-Forms'])) { |
|
661 | + if ( ! empty($translations->headers['Plural-Forms'])) { |
|
662 | 662 | $locale['']['plural_forms'] = $translations->headers['Plural-Forms']; |
663 | 663 | } |
664 | 664 | |
665 | 665 | foreach ($translations->entries as $msgid => $entry) { |
666 | - $locale[ $msgid ] = $entry->translations; |
|
666 | + $locale[$msgid] = $entry->translations; |
|
667 | 667 | } |
668 | 668 | |
669 | 669 | return $locale; |