@@ -15,226 +15,226 @@ |
||
15 | 15 | */ |
16 | 16 | class I18nRegistry |
17 | 17 | { |
18 | - /** |
|
19 | - * @var DomainInterface |
|
20 | - */ |
|
21 | - private $domain; |
|
22 | - |
|
23 | - /** |
|
24 | - * Will hold all registered i18n scripts. Prevents script handles from being registered more than once. |
|
25 | - * |
|
26 | - * @var array |
|
27 | - */ |
|
28 | - private $registered_i18n = array(); |
|
29 | - |
|
30 | - /** |
|
31 | - * Used to hold queued translations for the chunks loading in a view. |
|
32 | - * |
|
33 | - * @var array |
|
34 | - */ |
|
35 | - private $queued_handle_translations = array(); |
|
36 | - |
|
37 | - /** |
|
38 | - * Used to track script handles queued for adding translation strings as inline data in the dom. |
|
39 | - * |
|
40 | - * @var array |
|
41 | - */ |
|
42 | - private $queued_scripts = array(); |
|
43 | - |
|
44 | - /** |
|
45 | - * Obtained from the generated json file from the all javascript using wp.i18n with a map of script handle names to |
|
46 | - * translation strings. |
|
47 | - * |
|
48 | - * @var array |
|
49 | - */ |
|
50 | - private $i18n_map; |
|
51 | - |
|
52 | - /** |
|
53 | - * I18nRegistry constructor. |
|
54 | - * |
|
55 | - * @param array() $i18n_map An array of script handle names and the strings translated for those handles. If not |
|
56 | - * provided, the class will look for map in root of plugin with filename of |
|
57 | - * 'translation-map.json'. |
|
58 | - * @param DomainInterface $domain |
|
59 | - */ |
|
60 | - public function __construct(array $i18n_map = array(), DomainInterface $domain) |
|
61 | - { |
|
62 | - $this->domain = $domain; |
|
63 | - $this->setI18nMap($i18n_map); |
|
64 | - add_filter('print_scripts_array', array($this, 'queueI18n')); |
|
65 | - } |
|
66 | - |
|
67 | - /** |
|
68 | - * Used to register a script that has i18n strings for its $handle |
|
69 | - * |
|
70 | - * @param string $handle The script handle reference. |
|
71 | - * @param string $domain The i18n domain for the strings. |
|
72 | - */ |
|
73 | - public function registerScriptI18n($handle, $domain = 'event_espresso') |
|
74 | - { |
|
75 | - if (!isset($this->registered_i18n[$handle])) { |
|
76 | - $this->registered_i18n[$handle] = 1; |
|
77 | - $this->queued_scripts[$handle] = $domain; |
|
78 | - } |
|
79 | - } |
|
80 | - |
|
81 | - /** |
|
82 | - * Callback on print_scripts_array to listen for scripts enqueued and handle setting up the localized data. |
|
83 | - * |
|
84 | - * @param array $handles Array of registered script handles. |
|
85 | - * @return array |
|
86 | - */ |
|
87 | - public function queueI18n(array $handles) |
|
88 | - { |
|
89 | - if (empty($this->queued_scripts)) { |
|
90 | - return $handles; |
|
91 | - } |
|
92 | - foreach ($handles as $handle) { |
|
93 | - $this->queueI18nTranslationsForHandle($handle); |
|
94 | - } |
|
95 | - if ($this->queued_handle_translations) { |
|
96 | - foreach ($this->queued_handle_translations as $handle => $translations_for_domain) { |
|
97 | - $this->registerInlineScript( |
|
98 | - $handle, |
|
99 | - $translations_for_domain['translations'], |
|
100 | - $translations_for_domain['domain'] |
|
101 | - ); |
|
102 | - unset($this->queued_handle_translations[$handle]); |
|
103 | - } |
|
104 | - } |
|
105 | - return $handles; |
|
106 | - } |
|
107 | - |
|
108 | - /** |
|
109 | - * Registers inline script with translations for given handle and domain. |
|
110 | - * |
|
111 | - * @param string $handle Handle used to register javascript file containing translations. |
|
112 | - * @param array $translations Array of string translations. |
|
113 | - * @param string $domain Domain for translations. If left empty then strings are registered with the default |
|
114 | - * domain for the javascript. |
|
115 | - */ |
|
116 | - protected function registerInlineScript($handle, array $translations, $domain) |
|
117 | - { |
|
118 | - $script = $domain ? |
|
119 | - 'wp.i18n.setLocaleData( ' . wp_json_encode($translations) . ', "' . $domain . '" );' : |
|
120 | - 'wp.i18n.setLocaleData( ' . wp_json_encode($translations) . ' );'; |
|
121 | - wp_add_inline_script($handle, $script, 'before'); |
|
122 | - } |
|
123 | - |
|
124 | - /** |
|
125 | - * Queues up the translation strings for the given handle. |
|
126 | - * |
|
127 | - * @param string $handle The script handle being queued up. |
|
128 | - */ |
|
129 | - private function queueI18nTranslationsForHandle($handle) |
|
130 | - { |
|
131 | - if (isset($this->queued_scripts[$handle])) { |
|
132 | - $domain = $this->queued_scripts[$handle]; |
|
133 | - $translations = $this->getJedLocaleDataForDomainAndChunk($handle, $domain); |
|
134 | - if (count($translations) > 0) { |
|
135 | - $this->queued_handle_translations[$handle] = array( |
|
136 | - 'domain' => $domain, |
|
137 | - 'translations' => $translations, |
|
138 | - ); |
|
139 | - } |
|
140 | - unset($this->queued_scripts[$handle]); |
|
141 | - } |
|
142 | - } |
|
143 | - |
|
144 | - /** |
|
145 | - * Sets the internal i18n_map property. |
|
146 | - * If $chunk_map is empty or not an array, will attempt to load a chunk map from a default named map. |
|
147 | - * |
|
148 | - * @param array $i18n_map If provided, an array of translation strings indexed by script handle names they |
|
149 | - * correspond to. |
|
150 | - */ |
|
151 | - private function setI18nMap(array $i18n_map) |
|
152 | - { |
|
153 | - if (empty($i18n_map)) { |
|
154 | - $i18n_map = file_exists($this->domain->pluginPath() . 'translation-map.json') |
|
155 | - ? json_decode( |
|
156 | - file_get_contents($this->domain->pluginPath() . 'translation-map.json'), |
|
157 | - true |
|
158 | - ) |
|
159 | - : array(); |
|
160 | - } |
|
161 | - $this->i18n_map = $i18n_map; |
|
162 | - } |
|
163 | - |
|
164 | - /** |
|
165 | - * Get the jed locale data for a given $handle and domain |
|
166 | - * |
|
167 | - * @param string $handle The name for the script handle we want strings returned for. |
|
168 | - * @param string $domain The i18n domain. |
|
169 | - * @return array |
|
170 | - */ |
|
171 | - protected function getJedLocaleDataForDomainAndChunk($handle, $domain) |
|
172 | - { |
|
173 | - $translations = $this->getJedLocaleData($domain); |
|
174 | - // get index for adding back after extracting strings for this $chunk. |
|
175 | - $index = $translations['']; |
|
176 | - $translations = $this->getLocaleDataMatchingMap( |
|
177 | - $this->getOriginalStringsForHandleFromMap($handle), |
|
178 | - $translations |
|
179 | - ); |
|
180 | - $translations[''] = $index; |
|
181 | - return $translations; |
|
182 | - } |
|
183 | - |
|
184 | - /** |
|
185 | - * Get locale data for given strings from given translations |
|
186 | - * |
|
187 | - * @param array $string_set This is the subset of strings (msgIds) we want to extract from the translations array. |
|
188 | - * @param array $translations Translation data to extra strings from. |
|
189 | - * @return array |
|
190 | - */ |
|
191 | - protected function getLocaleDataMatchingMap(array $string_set, array $translations) |
|
192 | - { |
|
193 | - if (empty($string_set)) { |
|
194 | - return array(); |
|
195 | - } |
|
196 | - // some strings with quotes in them will break on the array_flip, so making sure quotes in the string are |
|
197 | - // slashed also filter falsey values. |
|
198 | - $string_set = array_unique(array_filter(wp_slash($string_set))); |
|
199 | - return array_intersect_key($translations, array_flip($string_set)); |
|
200 | - } |
|
201 | - |
|
202 | - /** |
|
203 | - * Get original strings to translate for the given chunk from the map |
|
204 | - * |
|
205 | - * @param string $handle The script handle name to get strings from the map for. |
|
206 | - * @return array |
|
207 | - */ |
|
208 | - protected function getOriginalStringsForHandleFromMap($handle) |
|
209 | - { |
|
210 | - return isset($this->i18n_map[$handle]) ? $this->i18n_map[$handle] : array(); |
|
211 | - } |
|
212 | - |
|
213 | - /** |
|
214 | - * Returns Jed-formatted localization data. |
|
215 | - * |
|
216 | - * @param string $domain Translation domain. |
|
217 | - * @return array |
|
218 | - */ |
|
219 | - private function getJedLocaleData($domain) |
|
220 | - { |
|
221 | - $translations = get_translations_for_domain($domain); |
|
222 | - |
|
223 | - $locale = array( |
|
224 | - '' => array( |
|
225 | - 'domain' => $domain, |
|
226 | - 'lang' => is_admin() ? EEH_DTT_Helper::get_user_locale() : get_locale(), |
|
227 | - ), |
|
228 | - ); |
|
229 | - |
|
230 | - if (!empty($translations->headers['Plural-Forms'])) { |
|
231 | - $locale['']['plural_forms'] = $translations->headers['Plural-Forms']; |
|
232 | - } |
|
233 | - |
|
234 | - foreach ($translations->entries as $msgid => $entry) { |
|
235 | - $locale[$msgid] = $entry->translations; |
|
236 | - } |
|
237 | - |
|
238 | - return $locale; |
|
239 | - } |
|
18 | + /** |
|
19 | + * @var DomainInterface |
|
20 | + */ |
|
21 | + private $domain; |
|
22 | + |
|
23 | + /** |
|
24 | + * Will hold all registered i18n scripts. Prevents script handles from being registered more than once. |
|
25 | + * |
|
26 | + * @var array |
|
27 | + */ |
|
28 | + private $registered_i18n = array(); |
|
29 | + |
|
30 | + /** |
|
31 | + * Used to hold queued translations for the chunks loading in a view. |
|
32 | + * |
|
33 | + * @var array |
|
34 | + */ |
|
35 | + private $queued_handle_translations = array(); |
|
36 | + |
|
37 | + /** |
|
38 | + * Used to track script handles queued for adding translation strings as inline data in the dom. |
|
39 | + * |
|
40 | + * @var array |
|
41 | + */ |
|
42 | + private $queued_scripts = array(); |
|
43 | + |
|
44 | + /** |
|
45 | + * Obtained from the generated json file from the all javascript using wp.i18n with a map of script handle names to |
|
46 | + * translation strings. |
|
47 | + * |
|
48 | + * @var array |
|
49 | + */ |
|
50 | + private $i18n_map; |
|
51 | + |
|
52 | + /** |
|
53 | + * I18nRegistry constructor. |
|
54 | + * |
|
55 | + * @param array() $i18n_map An array of script handle names and the strings translated for those handles. If not |
|
56 | + * provided, the class will look for map in root of plugin with filename of |
|
57 | + * 'translation-map.json'. |
|
58 | + * @param DomainInterface $domain |
|
59 | + */ |
|
60 | + public function __construct(array $i18n_map = array(), DomainInterface $domain) |
|
61 | + { |
|
62 | + $this->domain = $domain; |
|
63 | + $this->setI18nMap($i18n_map); |
|
64 | + add_filter('print_scripts_array', array($this, 'queueI18n')); |
|
65 | + } |
|
66 | + |
|
67 | + /** |
|
68 | + * Used to register a script that has i18n strings for its $handle |
|
69 | + * |
|
70 | + * @param string $handle The script handle reference. |
|
71 | + * @param string $domain The i18n domain for the strings. |
|
72 | + */ |
|
73 | + public function registerScriptI18n($handle, $domain = 'event_espresso') |
|
74 | + { |
|
75 | + if (!isset($this->registered_i18n[$handle])) { |
|
76 | + $this->registered_i18n[$handle] = 1; |
|
77 | + $this->queued_scripts[$handle] = $domain; |
|
78 | + } |
|
79 | + } |
|
80 | + |
|
81 | + /** |
|
82 | + * Callback on print_scripts_array to listen for scripts enqueued and handle setting up the localized data. |
|
83 | + * |
|
84 | + * @param array $handles Array of registered script handles. |
|
85 | + * @return array |
|
86 | + */ |
|
87 | + public function queueI18n(array $handles) |
|
88 | + { |
|
89 | + if (empty($this->queued_scripts)) { |
|
90 | + return $handles; |
|
91 | + } |
|
92 | + foreach ($handles as $handle) { |
|
93 | + $this->queueI18nTranslationsForHandle($handle); |
|
94 | + } |
|
95 | + if ($this->queued_handle_translations) { |
|
96 | + foreach ($this->queued_handle_translations as $handle => $translations_for_domain) { |
|
97 | + $this->registerInlineScript( |
|
98 | + $handle, |
|
99 | + $translations_for_domain['translations'], |
|
100 | + $translations_for_domain['domain'] |
|
101 | + ); |
|
102 | + unset($this->queued_handle_translations[$handle]); |
|
103 | + } |
|
104 | + } |
|
105 | + return $handles; |
|
106 | + } |
|
107 | + |
|
108 | + /** |
|
109 | + * Registers inline script with translations for given handle and domain. |
|
110 | + * |
|
111 | + * @param string $handle Handle used to register javascript file containing translations. |
|
112 | + * @param array $translations Array of string translations. |
|
113 | + * @param string $domain Domain for translations. If left empty then strings are registered with the default |
|
114 | + * domain for the javascript. |
|
115 | + */ |
|
116 | + protected function registerInlineScript($handle, array $translations, $domain) |
|
117 | + { |
|
118 | + $script = $domain ? |
|
119 | + 'wp.i18n.setLocaleData( ' . wp_json_encode($translations) . ', "' . $domain . '" );' : |
|
120 | + 'wp.i18n.setLocaleData( ' . wp_json_encode($translations) . ' );'; |
|
121 | + wp_add_inline_script($handle, $script, 'before'); |
|
122 | + } |
|
123 | + |
|
124 | + /** |
|
125 | + * Queues up the translation strings for the given handle. |
|
126 | + * |
|
127 | + * @param string $handle The script handle being queued up. |
|
128 | + */ |
|
129 | + private function queueI18nTranslationsForHandle($handle) |
|
130 | + { |
|
131 | + if (isset($this->queued_scripts[$handle])) { |
|
132 | + $domain = $this->queued_scripts[$handle]; |
|
133 | + $translations = $this->getJedLocaleDataForDomainAndChunk($handle, $domain); |
|
134 | + if (count($translations) > 0) { |
|
135 | + $this->queued_handle_translations[$handle] = array( |
|
136 | + 'domain' => $domain, |
|
137 | + 'translations' => $translations, |
|
138 | + ); |
|
139 | + } |
|
140 | + unset($this->queued_scripts[$handle]); |
|
141 | + } |
|
142 | + } |
|
143 | + |
|
144 | + /** |
|
145 | + * Sets the internal i18n_map property. |
|
146 | + * If $chunk_map is empty or not an array, will attempt to load a chunk map from a default named map. |
|
147 | + * |
|
148 | + * @param array $i18n_map If provided, an array of translation strings indexed by script handle names they |
|
149 | + * correspond to. |
|
150 | + */ |
|
151 | + private function setI18nMap(array $i18n_map) |
|
152 | + { |
|
153 | + if (empty($i18n_map)) { |
|
154 | + $i18n_map = file_exists($this->domain->pluginPath() . 'translation-map.json') |
|
155 | + ? json_decode( |
|
156 | + file_get_contents($this->domain->pluginPath() . 'translation-map.json'), |
|
157 | + true |
|
158 | + ) |
|
159 | + : array(); |
|
160 | + } |
|
161 | + $this->i18n_map = $i18n_map; |
|
162 | + } |
|
163 | + |
|
164 | + /** |
|
165 | + * Get the jed locale data for a given $handle and domain |
|
166 | + * |
|
167 | + * @param string $handle The name for the script handle we want strings returned for. |
|
168 | + * @param string $domain The i18n domain. |
|
169 | + * @return array |
|
170 | + */ |
|
171 | + protected function getJedLocaleDataForDomainAndChunk($handle, $domain) |
|
172 | + { |
|
173 | + $translations = $this->getJedLocaleData($domain); |
|
174 | + // get index for adding back after extracting strings for this $chunk. |
|
175 | + $index = $translations['']; |
|
176 | + $translations = $this->getLocaleDataMatchingMap( |
|
177 | + $this->getOriginalStringsForHandleFromMap($handle), |
|
178 | + $translations |
|
179 | + ); |
|
180 | + $translations[''] = $index; |
|
181 | + return $translations; |
|
182 | + } |
|
183 | + |
|
184 | + /** |
|
185 | + * Get locale data for given strings from given translations |
|
186 | + * |
|
187 | + * @param array $string_set This is the subset of strings (msgIds) we want to extract from the translations array. |
|
188 | + * @param array $translations Translation data to extra strings from. |
|
189 | + * @return array |
|
190 | + */ |
|
191 | + protected function getLocaleDataMatchingMap(array $string_set, array $translations) |
|
192 | + { |
|
193 | + if (empty($string_set)) { |
|
194 | + return array(); |
|
195 | + } |
|
196 | + // some strings with quotes in them will break on the array_flip, so making sure quotes in the string are |
|
197 | + // slashed also filter falsey values. |
|
198 | + $string_set = array_unique(array_filter(wp_slash($string_set))); |
|
199 | + return array_intersect_key($translations, array_flip($string_set)); |
|
200 | + } |
|
201 | + |
|
202 | + /** |
|
203 | + * Get original strings to translate for the given chunk from the map |
|
204 | + * |
|
205 | + * @param string $handle The script handle name to get strings from the map for. |
|
206 | + * @return array |
|
207 | + */ |
|
208 | + protected function getOriginalStringsForHandleFromMap($handle) |
|
209 | + { |
|
210 | + return isset($this->i18n_map[$handle]) ? $this->i18n_map[$handle] : array(); |
|
211 | + } |
|
212 | + |
|
213 | + /** |
|
214 | + * Returns Jed-formatted localization data. |
|
215 | + * |
|
216 | + * @param string $domain Translation domain. |
|
217 | + * @return array |
|
218 | + */ |
|
219 | + private function getJedLocaleData($domain) |
|
220 | + { |
|
221 | + $translations = get_translations_for_domain($domain); |
|
222 | + |
|
223 | + $locale = array( |
|
224 | + '' => array( |
|
225 | + 'domain' => $domain, |
|
226 | + 'lang' => is_admin() ? EEH_DTT_Helper::get_user_locale() : get_locale(), |
|
227 | + ), |
|
228 | + ); |
|
229 | + |
|
230 | + if (!empty($translations->headers['Plural-Forms'])) { |
|
231 | + $locale['']['plural_forms'] = $translations->headers['Plural-Forms']; |
|
232 | + } |
|
233 | + |
|
234 | + foreach ($translations->entries as $msgid => $entry) { |
|
235 | + $locale[$msgid] = $entry->translations; |
|
236 | + } |
|
237 | + |
|
238 | + return $locale; |
|
239 | + } |
|
240 | 240 | } |
@@ -72,7 +72,7 @@ discard block |
||
72 | 72 | */ |
73 | 73 | public function registerScriptI18n($handle, $domain = 'event_espresso') |
74 | 74 | { |
75 | - if (!isset($this->registered_i18n[$handle])) { |
|
75 | + if ( ! isset($this->registered_i18n[$handle])) { |
|
76 | 76 | $this->registered_i18n[$handle] = 1; |
77 | 77 | $this->queued_scripts[$handle] = $domain; |
78 | 78 | } |
@@ -116,8 +116,7 @@ discard block |
||
116 | 116 | protected function registerInlineScript($handle, array $translations, $domain) |
117 | 117 | { |
118 | 118 | $script = $domain ? |
119 | - 'wp.i18n.setLocaleData( ' . wp_json_encode($translations) . ', "' . $domain . '" );' : |
|
120 | - 'wp.i18n.setLocaleData( ' . wp_json_encode($translations) . ' );'; |
|
119 | + 'wp.i18n.setLocaleData( '.wp_json_encode($translations).', "'.$domain.'" );' : 'wp.i18n.setLocaleData( '.wp_json_encode($translations).' );'; |
|
121 | 120 | wp_add_inline_script($handle, $script, 'before'); |
122 | 121 | } |
123 | 122 | |
@@ -151,9 +150,9 @@ discard block |
||
151 | 150 | private function setI18nMap(array $i18n_map) |
152 | 151 | { |
153 | 152 | if (empty($i18n_map)) { |
154 | - $i18n_map = file_exists($this->domain->pluginPath() . 'translation-map.json') |
|
153 | + $i18n_map = file_exists($this->domain->pluginPath().'translation-map.json') |
|
155 | 154 | ? json_decode( |
156 | - file_get_contents($this->domain->pluginPath() . 'translation-map.json'), |
|
155 | + file_get_contents($this->domain->pluginPath().'translation-map.json'), |
|
157 | 156 | true |
158 | 157 | ) |
159 | 158 | : array(); |
@@ -227,7 +226,7 @@ discard block |
||
227 | 226 | ), |
228 | 227 | ); |
229 | 228 | |
230 | - if (!empty($translations->headers['Plural-Forms'])) { |
|
229 | + if ( ! empty($translations->headers['Plural-Forms'])) { |
|
231 | 230 | $locale['']['plural_forms'] = $translations->headers['Plural-Forms']; |
232 | 231 | } |
233 | 232 |
@@ -19,51 +19,51 @@ |
||
19 | 19 | */ |
20 | 20 | class EspressoEditorAssetManager extends AssetManager |
21 | 21 | { |
22 | - const JS_HANDLE_EDITOR = 'eventespresso-editor'; |
|
23 | - const JS_HANDLE_EDITOR_PROTOTYPE = 'eventespresso-editor-prototype'; |
|
24 | - const CSS_HANDLE_EDITOR = 'eventespresso-editor'; |
|
25 | - const CSS_HANDLE_EDITOR_PROTOTYPE = 'eventespresso-editor-prototype'; |
|
22 | + const JS_HANDLE_EDITOR = 'eventespresso-editor'; |
|
23 | + const JS_HANDLE_EDITOR_PROTOTYPE = 'eventespresso-editor-prototype'; |
|
24 | + const CSS_HANDLE_EDITOR = 'eventespresso-editor'; |
|
25 | + const CSS_HANDLE_EDITOR_PROTOTYPE = 'eventespresso-editor-prototype'; |
|
26 | 26 | |
27 | 27 | |
28 | - /** |
|
29 | - * @throws InvalidDataTypeException |
|
30 | - * @throws InvalidEntityException |
|
31 | - * @throws DuplicateCollectionIdentifierException |
|
32 | - * @throws DomainException |
|
33 | - */ |
|
34 | - public function addAssets() |
|
35 | - { |
|
36 | - $this->registerJavascript(); |
|
37 | - $this->registerStyleSheets(); |
|
38 | - } |
|
28 | + /** |
|
29 | + * @throws InvalidDataTypeException |
|
30 | + * @throws InvalidEntityException |
|
31 | + * @throws DuplicateCollectionIdentifierException |
|
32 | + * @throws DomainException |
|
33 | + */ |
|
34 | + public function addAssets() |
|
35 | + { |
|
36 | + $this->registerJavascript(); |
|
37 | + $this->registerStyleSheets(); |
|
38 | + } |
|
39 | 39 | |
40 | 40 | |
41 | - /** |
|
42 | - * Register javascript assets |
|
43 | - * |
|
44 | - * @throws InvalidDataTypeException |
|
45 | - * @throws InvalidEntityException |
|
46 | - * @throws DuplicateCollectionIdentifierException |
|
47 | - * @throws DomainException |
|
48 | - */ |
|
49 | - private function registerJavascript() |
|
50 | - { |
|
51 | - $this->addJs(self::JS_HANDLE_EDITOR, [CoreAssetManager::JS_HANDLE_JS_CORE])->setRequiresTranslation(); |
|
52 | - $this->addJs(self::JS_HANDLE_EDITOR_PROTOTYPE, [self::JS_HANDLE_EDITOR])->setRequiresTranslation(); |
|
53 | - } |
|
41 | + /** |
|
42 | + * Register javascript assets |
|
43 | + * |
|
44 | + * @throws InvalidDataTypeException |
|
45 | + * @throws InvalidEntityException |
|
46 | + * @throws DuplicateCollectionIdentifierException |
|
47 | + * @throws DomainException |
|
48 | + */ |
|
49 | + private function registerJavascript() |
|
50 | + { |
|
51 | + $this->addJs(self::JS_HANDLE_EDITOR, [CoreAssetManager::JS_HANDLE_JS_CORE])->setRequiresTranslation(); |
|
52 | + $this->addJs(self::JS_HANDLE_EDITOR_PROTOTYPE, [self::JS_HANDLE_EDITOR])->setRequiresTranslation(); |
|
53 | + } |
|
54 | 54 | |
55 | 55 | |
56 | - /** |
|
57 | - * Register CSS assets. |
|
58 | - * |
|
59 | - * @throws DuplicateCollectionIdentifierException |
|
60 | - * @throws InvalidDataTypeException |
|
61 | - * @throws InvalidEntityException |
|
62 | - * @throws DomainException |
|
63 | - */ |
|
64 | - private function registerStyleSheets() |
|
65 | - { |
|
66 | - $this->addCss(self::CSS_HANDLE_EDITOR); |
|
67 | - $this->addCss(self::CSS_HANDLE_EDITOR_PROTOTYPE, [self::CSS_HANDLE_EDITOR]); |
|
68 | - } |
|
56 | + /** |
|
57 | + * Register CSS assets. |
|
58 | + * |
|
59 | + * @throws DuplicateCollectionIdentifierException |
|
60 | + * @throws InvalidDataTypeException |
|
61 | + * @throws InvalidEntityException |
|
62 | + * @throws DomainException |
|
63 | + */ |
|
64 | + private function registerStyleSheets() |
|
65 | + { |
|
66 | + $this->addCss(self::CSS_HANDLE_EDITOR); |
|
67 | + $this->addCss(self::CSS_HANDLE_EDITOR_PROTOTYPE, [self::CSS_HANDLE_EDITOR]); |
|
68 | + } |
|
69 | 69 | } |
@@ -34,209 +34,209 @@ discard block |
||
34 | 34 | class AdvancedEditorData |
35 | 35 | { |
36 | 36 | |
37 | - /** |
|
38 | - * @var string $namespace The graphql namespace/prefix. |
|
39 | - */ |
|
40 | - protected $namespace = 'Espresso'; |
|
41 | - |
|
42 | - /** |
|
43 | - * @var EE_Event |
|
44 | - */ |
|
45 | - protected $event; |
|
46 | - |
|
47 | - /** |
|
48 | - * @var EE_Admin_Config |
|
49 | - */ |
|
50 | - protected $admin_config; |
|
51 | - /** |
|
52 | - * @var EEM_Datetime $datetime_model |
|
53 | - */ |
|
54 | - protected $datetime_model; |
|
55 | - /** |
|
56 | - * @var EEM_Price $price_model |
|
57 | - */ |
|
58 | - protected $price_model; |
|
59 | - /** |
|
60 | - * @var EEM_Ticket $ticket_model |
|
61 | - */ |
|
62 | - protected $ticket_model; |
|
63 | - |
|
64 | - |
|
65 | - /** |
|
66 | - * AdvancedEditorAdminForm constructor. |
|
67 | - * |
|
68 | - * @param EE_Event $event |
|
69 | - * @param EE_Admin_Config $admin_config |
|
70 | - * @param EEM_Datetime $datetime_model |
|
71 | - * @param EEM_Price $price_model |
|
72 | - * @param EEM_Ticket $ticket_model |
|
73 | - */ |
|
74 | - public function __construct( |
|
75 | - EE_Event $event, |
|
76 | - EE_Admin_Config $admin_config, |
|
77 | - EEM_Datetime $datetime_model, |
|
78 | - EEM_Price $price_model, |
|
79 | - EEM_Ticket $ticket_model |
|
80 | - ) { |
|
81 | - $this->event = $event; |
|
82 | - $this->admin_config = $admin_config; |
|
83 | - $this->datetime_model = $datetime_model; |
|
84 | - $this->price_model = $price_model; |
|
85 | - $this->ticket_model = $ticket_model; |
|
86 | - add_action('admin_enqueue_scripts', [$this, 'loadScriptsStyles']); |
|
87 | - } |
|
88 | - |
|
89 | - |
|
90 | - /** |
|
91 | - * @throws EE_Error |
|
92 | - * @throws InvalidArgumentException |
|
93 | - * @throws InvalidDataTypeException |
|
94 | - * @throws InvalidInterfaceException |
|
95 | - * @throws ModelConfigurationException |
|
96 | - * @throws ReflectionException |
|
97 | - * @throws UnexpectedEntityException |
|
98 | - * @throws DomainException |
|
99 | - * @since $VID:$ |
|
100 | - */ |
|
101 | - public function loadScriptsStyles() |
|
102 | - { |
|
103 | - if ($this->admin_config->useAdvancedEditor()) { |
|
104 | - $eventId = $this->event instanceof EE_Event ? $this->event->ID() : 0; |
|
105 | - if (! $eventId) { |
|
106 | - global $post; |
|
107 | - $eventId = isset($_REQUEST['post']) ? absint($_REQUEST['post']) : 0; |
|
108 | - $eventId = $eventId === 0 && $post instanceof WP_Post && $post->post_type === 'espresso_events' |
|
109 | - ? $post->ID |
|
110 | - : $eventId; |
|
111 | - } |
|
112 | - if ($eventId) { |
|
113 | - $data = $this->getEditorData($eventId); |
|
114 | - $data = wp_json_encode($data); |
|
115 | - add_action( |
|
116 | - 'admin_footer', |
|
117 | - static function () use ($data) { |
|
118 | - wp_add_inline_script( |
|
119 | - EspressoEditorAssetManager::JS_HANDLE_EDITOR_PROTOTYPE, |
|
120 | - " |
|
37 | + /** |
|
38 | + * @var string $namespace The graphql namespace/prefix. |
|
39 | + */ |
|
40 | + protected $namespace = 'Espresso'; |
|
41 | + |
|
42 | + /** |
|
43 | + * @var EE_Event |
|
44 | + */ |
|
45 | + protected $event; |
|
46 | + |
|
47 | + /** |
|
48 | + * @var EE_Admin_Config |
|
49 | + */ |
|
50 | + protected $admin_config; |
|
51 | + /** |
|
52 | + * @var EEM_Datetime $datetime_model |
|
53 | + */ |
|
54 | + protected $datetime_model; |
|
55 | + /** |
|
56 | + * @var EEM_Price $price_model |
|
57 | + */ |
|
58 | + protected $price_model; |
|
59 | + /** |
|
60 | + * @var EEM_Ticket $ticket_model |
|
61 | + */ |
|
62 | + protected $ticket_model; |
|
63 | + |
|
64 | + |
|
65 | + /** |
|
66 | + * AdvancedEditorAdminForm constructor. |
|
67 | + * |
|
68 | + * @param EE_Event $event |
|
69 | + * @param EE_Admin_Config $admin_config |
|
70 | + * @param EEM_Datetime $datetime_model |
|
71 | + * @param EEM_Price $price_model |
|
72 | + * @param EEM_Ticket $ticket_model |
|
73 | + */ |
|
74 | + public function __construct( |
|
75 | + EE_Event $event, |
|
76 | + EE_Admin_Config $admin_config, |
|
77 | + EEM_Datetime $datetime_model, |
|
78 | + EEM_Price $price_model, |
|
79 | + EEM_Ticket $ticket_model |
|
80 | + ) { |
|
81 | + $this->event = $event; |
|
82 | + $this->admin_config = $admin_config; |
|
83 | + $this->datetime_model = $datetime_model; |
|
84 | + $this->price_model = $price_model; |
|
85 | + $this->ticket_model = $ticket_model; |
|
86 | + add_action('admin_enqueue_scripts', [$this, 'loadScriptsStyles']); |
|
87 | + } |
|
88 | + |
|
89 | + |
|
90 | + /** |
|
91 | + * @throws EE_Error |
|
92 | + * @throws InvalidArgumentException |
|
93 | + * @throws InvalidDataTypeException |
|
94 | + * @throws InvalidInterfaceException |
|
95 | + * @throws ModelConfigurationException |
|
96 | + * @throws ReflectionException |
|
97 | + * @throws UnexpectedEntityException |
|
98 | + * @throws DomainException |
|
99 | + * @since $VID:$ |
|
100 | + */ |
|
101 | + public function loadScriptsStyles() |
|
102 | + { |
|
103 | + if ($this->admin_config->useAdvancedEditor()) { |
|
104 | + $eventId = $this->event instanceof EE_Event ? $this->event->ID() : 0; |
|
105 | + if (! $eventId) { |
|
106 | + global $post; |
|
107 | + $eventId = isset($_REQUEST['post']) ? absint($_REQUEST['post']) : 0; |
|
108 | + $eventId = $eventId === 0 && $post instanceof WP_Post && $post->post_type === 'espresso_events' |
|
109 | + ? $post->ID |
|
110 | + : $eventId; |
|
111 | + } |
|
112 | + if ($eventId) { |
|
113 | + $data = $this->getEditorData($eventId); |
|
114 | + $data = wp_json_encode($data); |
|
115 | + add_action( |
|
116 | + 'admin_footer', |
|
117 | + static function () use ($data) { |
|
118 | + wp_add_inline_script( |
|
119 | + EspressoEditorAssetManager::JS_HANDLE_EDITOR_PROTOTYPE, |
|
120 | + " |
|
121 | 121 | var eeEditorData={$data}; |
122 | 122 | ", |
123 | - 'before' |
|
124 | - ); |
|
125 | - } |
|
126 | - ); |
|
127 | - } |
|
128 | - } |
|
129 | - } |
|
130 | - |
|
131 | - |
|
132 | - /** |
|
133 | - * @param int $eventId |
|
134 | - * @return array |
|
135 | - * @throws EE_Error |
|
136 | - * @throws InvalidDataTypeException |
|
137 | - * @throws InvalidInterfaceException |
|
138 | - * @throws ModelConfigurationException |
|
139 | - * @throws UnexpectedEntityException |
|
140 | - * @throws InvalidArgumentException |
|
141 | - * @throws ReflectionException |
|
142 | - * @throws DomainException |
|
143 | - * @since $VID:$ |
|
144 | - */ |
|
145 | - protected function getEditorData($eventId) |
|
146 | - { |
|
147 | - $event = $this->getEventGraphQLData($eventId); |
|
148 | - $event['dbId'] = $eventId; |
|
149 | - |
|
150 | - $graphqlEndpoint = class_exists('WPGraphQL') ? trailingslashit(site_url()) . Router::$route : ''; |
|
151 | - $graphqlEndpoint = esc_url($graphqlEndpoint); |
|
152 | - |
|
153 | - $currentUser = $this->getGraphQLCurrentUser(); |
|
154 | - |
|
155 | - $generalSettings = $this->getGraphQLGeneralSettings(); |
|
156 | - |
|
157 | - return compact('event', 'graphqlEndpoint', 'currentUser', 'generalSettings'); |
|
158 | - } |
|
159 | - |
|
160 | - |
|
161 | - /** |
|
162 | - * @param int $eventId |
|
163 | - * @return array |
|
164 | - * @since $VID:$ |
|
165 | - */ |
|
166 | - protected function getEventGraphQLData($eventId) |
|
167 | - { |
|
168 | - $datetimes = $this->getGraphQLDatetimes($eventId); |
|
169 | - |
|
170 | - if (empty($datetimes['nodes']) || (isset($_REQUEST['action']) && $_REQUEST['action'] === 'create_new')) { |
|
171 | - $this->addDefaultEntities($eventId); |
|
172 | - $datetimes = $this->getGraphQLDatetimes($eventId); |
|
173 | - } |
|
174 | - |
|
175 | - if (! empty($datetimes['nodes'])) { |
|
176 | - $datetimeIn = wp_list_pluck($datetimes['nodes'], 'id'); |
|
177 | - |
|
178 | - if (! empty($datetimeIn)) { |
|
179 | - $tickets = $this->getGraphQLTickets($datetimeIn); |
|
180 | - } |
|
181 | - } |
|
182 | - |
|
183 | - if (! empty($tickets['nodes'])) { |
|
184 | - $ticketIn = wp_list_pluck($tickets['nodes'], 'id'); |
|
185 | - |
|
186 | - if (! empty($ticketIn)) { |
|
187 | - $prices = $this->getGraphQLPrices($ticketIn); |
|
188 | - } |
|
189 | - } |
|
190 | - |
|
191 | - $priceTypes = $this->getGraphQLPriceTypes(); |
|
192 | - |
|
193 | - $relations = $this->getRelationalData($eventId); |
|
194 | - |
|
195 | - return compact('datetimes', 'tickets', 'prices', 'priceTypes', 'relations'); |
|
196 | - } |
|
197 | - |
|
198 | - /** |
|
199 | - * @param int $eventId |
|
200 | - * @throws DomainException |
|
201 | - * @throws EE_Error |
|
202 | - * @throws InvalidArgumentException |
|
203 | - * @throws InvalidDataTypeException |
|
204 | - * @throws InvalidInterfaceException |
|
205 | - * @throws ModelConfigurationException |
|
206 | - * @throws ReflectionException |
|
207 | - * @throws UnexpectedEntityException |
|
208 | - * @since $VID:$ |
|
209 | - */ |
|
210 | - protected function addDefaultEntities($eventId) |
|
211 | - { |
|
212 | - $default_dates = $this->datetime_model->create_new_blank_datetime(); |
|
213 | - if (is_array($default_dates) && isset($default_dates[0]) && $default_dates[0] instanceof EE_Datetime) { |
|
214 | - $default_date = $default_dates[0]; |
|
215 | - $default_date->save(); |
|
216 | - $default_date->_add_relation_to($eventId, 'Event'); |
|
217 | - $default_tickets = $this->ticket_model->get_all_default_tickets(); |
|
218 | - $default_prices = $this->price_model->get_all_default_prices(); |
|
219 | - foreach ($default_tickets as $default_ticket) { |
|
220 | - $default_ticket->save(); |
|
221 | - $default_ticket->_add_relation_to($default_date, 'Datetime'); |
|
222 | - foreach ($default_prices as $default_price) { |
|
223 | - $default_price->save(); |
|
224 | - $default_price->_add_relation_to($default_ticket, 'Ticket'); |
|
225 | - } |
|
226 | - } |
|
227 | - } |
|
228 | - } |
|
229 | - |
|
230 | - |
|
231 | - /** |
|
232 | - * @param int $eventId |
|
233 | - * @return array|null |
|
234 | - * @since $VID:$ |
|
235 | - */ |
|
236 | - protected function getGraphQLDatetimes($eventId) |
|
237 | - { |
|
238 | - $field_key = lcfirst($this->namespace) . 'Datetimes'; |
|
239 | - $query = <<<QUERY |
|
123 | + 'before' |
|
124 | + ); |
|
125 | + } |
|
126 | + ); |
|
127 | + } |
|
128 | + } |
|
129 | + } |
|
130 | + |
|
131 | + |
|
132 | + /** |
|
133 | + * @param int $eventId |
|
134 | + * @return array |
|
135 | + * @throws EE_Error |
|
136 | + * @throws InvalidDataTypeException |
|
137 | + * @throws InvalidInterfaceException |
|
138 | + * @throws ModelConfigurationException |
|
139 | + * @throws UnexpectedEntityException |
|
140 | + * @throws InvalidArgumentException |
|
141 | + * @throws ReflectionException |
|
142 | + * @throws DomainException |
|
143 | + * @since $VID:$ |
|
144 | + */ |
|
145 | + protected function getEditorData($eventId) |
|
146 | + { |
|
147 | + $event = $this->getEventGraphQLData($eventId); |
|
148 | + $event['dbId'] = $eventId; |
|
149 | + |
|
150 | + $graphqlEndpoint = class_exists('WPGraphQL') ? trailingslashit(site_url()) . Router::$route : ''; |
|
151 | + $graphqlEndpoint = esc_url($graphqlEndpoint); |
|
152 | + |
|
153 | + $currentUser = $this->getGraphQLCurrentUser(); |
|
154 | + |
|
155 | + $generalSettings = $this->getGraphQLGeneralSettings(); |
|
156 | + |
|
157 | + return compact('event', 'graphqlEndpoint', 'currentUser', 'generalSettings'); |
|
158 | + } |
|
159 | + |
|
160 | + |
|
161 | + /** |
|
162 | + * @param int $eventId |
|
163 | + * @return array |
|
164 | + * @since $VID:$ |
|
165 | + */ |
|
166 | + protected function getEventGraphQLData($eventId) |
|
167 | + { |
|
168 | + $datetimes = $this->getGraphQLDatetimes($eventId); |
|
169 | + |
|
170 | + if (empty($datetimes['nodes']) || (isset($_REQUEST['action']) && $_REQUEST['action'] === 'create_new')) { |
|
171 | + $this->addDefaultEntities($eventId); |
|
172 | + $datetimes = $this->getGraphQLDatetimes($eventId); |
|
173 | + } |
|
174 | + |
|
175 | + if (! empty($datetimes['nodes'])) { |
|
176 | + $datetimeIn = wp_list_pluck($datetimes['nodes'], 'id'); |
|
177 | + |
|
178 | + if (! empty($datetimeIn)) { |
|
179 | + $tickets = $this->getGraphQLTickets($datetimeIn); |
|
180 | + } |
|
181 | + } |
|
182 | + |
|
183 | + if (! empty($tickets['nodes'])) { |
|
184 | + $ticketIn = wp_list_pluck($tickets['nodes'], 'id'); |
|
185 | + |
|
186 | + if (! empty($ticketIn)) { |
|
187 | + $prices = $this->getGraphQLPrices($ticketIn); |
|
188 | + } |
|
189 | + } |
|
190 | + |
|
191 | + $priceTypes = $this->getGraphQLPriceTypes(); |
|
192 | + |
|
193 | + $relations = $this->getRelationalData($eventId); |
|
194 | + |
|
195 | + return compact('datetimes', 'tickets', 'prices', 'priceTypes', 'relations'); |
|
196 | + } |
|
197 | + |
|
198 | + /** |
|
199 | + * @param int $eventId |
|
200 | + * @throws DomainException |
|
201 | + * @throws EE_Error |
|
202 | + * @throws InvalidArgumentException |
|
203 | + * @throws InvalidDataTypeException |
|
204 | + * @throws InvalidInterfaceException |
|
205 | + * @throws ModelConfigurationException |
|
206 | + * @throws ReflectionException |
|
207 | + * @throws UnexpectedEntityException |
|
208 | + * @since $VID:$ |
|
209 | + */ |
|
210 | + protected function addDefaultEntities($eventId) |
|
211 | + { |
|
212 | + $default_dates = $this->datetime_model->create_new_blank_datetime(); |
|
213 | + if (is_array($default_dates) && isset($default_dates[0]) && $default_dates[0] instanceof EE_Datetime) { |
|
214 | + $default_date = $default_dates[0]; |
|
215 | + $default_date->save(); |
|
216 | + $default_date->_add_relation_to($eventId, 'Event'); |
|
217 | + $default_tickets = $this->ticket_model->get_all_default_tickets(); |
|
218 | + $default_prices = $this->price_model->get_all_default_prices(); |
|
219 | + foreach ($default_tickets as $default_ticket) { |
|
220 | + $default_ticket->save(); |
|
221 | + $default_ticket->_add_relation_to($default_date, 'Datetime'); |
|
222 | + foreach ($default_prices as $default_price) { |
|
223 | + $default_price->save(); |
|
224 | + $default_price->_add_relation_to($default_ticket, 'Ticket'); |
|
225 | + } |
|
226 | + } |
|
227 | + } |
|
228 | + } |
|
229 | + |
|
230 | + |
|
231 | + /** |
|
232 | + * @param int $eventId |
|
233 | + * @return array|null |
|
234 | + * @since $VID:$ |
|
235 | + */ |
|
236 | + protected function getGraphQLDatetimes($eventId) |
|
237 | + { |
|
238 | + $field_key = lcfirst($this->namespace) . 'Datetimes'; |
|
239 | + $query = <<<QUERY |
|
240 | 240 | query GET_DATETIMES(\$where: {$this->namespace}RootQueryDatetimesConnectionWhereArgs) { |
241 | 241 | {$field_key}(where: \$where) { |
242 | 242 | nodes { |
@@ -264,31 +264,31 @@ discard block |
||
264 | 264 | } |
265 | 265 | } |
266 | 266 | QUERY; |
267 | - $data = [ |
|
268 | - 'operation_name' => 'GET_DATETIMES', |
|
269 | - 'variables' => [ |
|
270 | - 'first' => 50, |
|
271 | - 'where' => [ |
|
272 | - 'eventId' => $eventId, |
|
273 | - ], |
|
274 | - ], |
|
275 | - 'query' => $query, |
|
276 | - ]; |
|
277 | - |
|
278 | - $responseData = $this->makeGraphQLRequest($data); |
|
279 | - return !empty($responseData[ $field_key ]) ? $responseData[ $field_key ] : null; |
|
280 | - } |
|
281 | - |
|
282 | - |
|
283 | - /** |
|
284 | - * @param array $datetimeIn |
|
285 | - * @return array|null |
|
286 | - * @since $VID:$ |
|
287 | - */ |
|
288 | - protected function getGraphQLTickets(array $datetimeIn) |
|
289 | - { |
|
290 | - $field_key = lcfirst($this->namespace) . 'Tickets'; |
|
291 | - $query = <<<QUERY |
|
267 | + $data = [ |
|
268 | + 'operation_name' => 'GET_DATETIMES', |
|
269 | + 'variables' => [ |
|
270 | + 'first' => 50, |
|
271 | + 'where' => [ |
|
272 | + 'eventId' => $eventId, |
|
273 | + ], |
|
274 | + ], |
|
275 | + 'query' => $query, |
|
276 | + ]; |
|
277 | + |
|
278 | + $responseData = $this->makeGraphQLRequest($data); |
|
279 | + return !empty($responseData[ $field_key ]) ? $responseData[ $field_key ] : null; |
|
280 | + } |
|
281 | + |
|
282 | + |
|
283 | + /** |
|
284 | + * @param array $datetimeIn |
|
285 | + * @return array|null |
|
286 | + * @since $VID:$ |
|
287 | + */ |
|
288 | + protected function getGraphQLTickets(array $datetimeIn) |
|
289 | + { |
|
290 | + $field_key = lcfirst($this->namespace) . 'Tickets'; |
|
291 | + $query = <<<QUERY |
|
292 | 292 | query GET_TICKETS(\$where: {$this->namespace}RootQueryTicketsConnectionWhereArgs) { |
293 | 293 | {$field_key}(where: \$where) { |
294 | 294 | nodes { |
@@ -319,30 +319,30 @@ discard block |
||
319 | 319 | } |
320 | 320 | } |
321 | 321 | QUERY; |
322 | - $data = [ |
|
323 | - 'operation_name' => 'GET_TICKETS', |
|
324 | - 'variables' => [ |
|
325 | - 'where' => [ |
|
326 | - 'datetimeIn' => $datetimeIn, |
|
327 | - ], |
|
328 | - ], |
|
329 | - 'query' => $query, |
|
330 | - ]; |
|
331 | - |
|
332 | - $responseData = $this->makeGraphQLRequest($data); |
|
333 | - return !empty($responseData[ $field_key ]) ? $responseData[ $field_key ] : null; |
|
334 | - } |
|
335 | - |
|
336 | - |
|
337 | - /** |
|
338 | - * @param array $ticketIn |
|
339 | - * @return array|null |
|
340 | - * @since $VID:$ |
|
341 | - */ |
|
342 | - protected function getGraphQLPrices(array $ticketIn) |
|
343 | - { |
|
344 | - $field_key = lcfirst($this->namespace) . 'Prices'; |
|
345 | - $query = <<<QUERY |
|
322 | + $data = [ |
|
323 | + 'operation_name' => 'GET_TICKETS', |
|
324 | + 'variables' => [ |
|
325 | + 'where' => [ |
|
326 | + 'datetimeIn' => $datetimeIn, |
|
327 | + ], |
|
328 | + ], |
|
329 | + 'query' => $query, |
|
330 | + ]; |
|
331 | + |
|
332 | + $responseData = $this->makeGraphQLRequest($data); |
|
333 | + return !empty($responseData[ $field_key ]) ? $responseData[ $field_key ] : null; |
|
334 | + } |
|
335 | + |
|
336 | + |
|
337 | + /** |
|
338 | + * @param array $ticketIn |
|
339 | + * @return array|null |
|
340 | + * @since $VID:$ |
|
341 | + */ |
|
342 | + protected function getGraphQLPrices(array $ticketIn) |
|
343 | + { |
|
344 | + $field_key = lcfirst($this->namespace) . 'Prices'; |
|
345 | + $query = <<<QUERY |
|
346 | 346 | query GET_PRICES(\$where: {$this->namespace}RootQueryPricesConnectionWhereArgs) { |
347 | 347 | {$field_key}(where: \$where) { |
348 | 348 | nodes { |
@@ -366,29 +366,29 @@ discard block |
||
366 | 366 | } |
367 | 367 | } |
368 | 368 | QUERY; |
369 | - $data = [ |
|
370 | - 'operation_name' => 'GET_PRICES', |
|
371 | - 'variables' => [ |
|
372 | - 'where' => [ |
|
373 | - 'ticketIn' => $ticketIn, |
|
374 | - ], |
|
375 | - ], |
|
376 | - 'query' => $query, |
|
377 | - ]; |
|
378 | - |
|
379 | - $responseData = $this->makeGraphQLRequest($data); |
|
380 | - return !empty($responseData[ $field_key ]) ? $responseData[ $field_key ] : null; |
|
381 | - } |
|
382 | - |
|
383 | - |
|
384 | - /** |
|
385 | - * @return array|null |
|
386 | - * @since $VID:$ |
|
387 | - */ |
|
388 | - protected function getGraphQLPriceTypes() |
|
389 | - { |
|
390 | - $field_key = lcfirst($this->namespace) . 'PriceTypes'; |
|
391 | - $query = <<<QUERY |
|
369 | + $data = [ |
|
370 | + 'operation_name' => 'GET_PRICES', |
|
371 | + 'variables' => [ |
|
372 | + 'where' => [ |
|
373 | + 'ticketIn' => $ticketIn, |
|
374 | + ], |
|
375 | + ], |
|
376 | + 'query' => $query, |
|
377 | + ]; |
|
378 | + |
|
379 | + $responseData = $this->makeGraphQLRequest($data); |
|
380 | + return !empty($responseData[ $field_key ]) ? $responseData[ $field_key ] : null; |
|
381 | + } |
|
382 | + |
|
383 | + |
|
384 | + /** |
|
385 | + * @return array|null |
|
386 | + * @since $VID:$ |
|
387 | + */ |
|
388 | + protected function getGraphQLPriceTypes() |
|
389 | + { |
|
390 | + $field_key = lcfirst($this->namespace) . 'PriceTypes'; |
|
391 | + $query = <<<QUERY |
|
392 | 392 | query GET_PRICES { |
393 | 393 | {$field_key} { |
394 | 394 | nodes { |
@@ -408,24 +408,24 @@ discard block |
||
408 | 408 | } |
409 | 409 | } |
410 | 410 | QUERY; |
411 | - $data = [ |
|
412 | - 'operation_name' => 'GET_PRICES', |
|
413 | - 'query' => $query, |
|
414 | - ]; |
|
415 | - |
|
416 | - $responseData = $this->makeGraphQLRequest($data); |
|
417 | - return !empty($responseData[ $field_key ]) ? $responseData[ $field_key ] : null; |
|
418 | - } |
|
419 | - |
|
420 | - |
|
421 | - /** |
|
422 | - * @return array|null |
|
423 | - * @since $VID:$ |
|
424 | - */ |
|
425 | - protected function getGraphQLCurrentUser() |
|
426 | - { |
|
427 | - $field_key = 'viewer'; |
|
428 | - $query = <<<QUERY |
|
411 | + $data = [ |
|
412 | + 'operation_name' => 'GET_PRICES', |
|
413 | + 'query' => $query, |
|
414 | + ]; |
|
415 | + |
|
416 | + $responseData = $this->makeGraphQLRequest($data); |
|
417 | + return !empty($responseData[ $field_key ]) ? $responseData[ $field_key ] : null; |
|
418 | + } |
|
419 | + |
|
420 | + |
|
421 | + /** |
|
422 | + * @return array|null |
|
423 | + * @since $VID:$ |
|
424 | + */ |
|
425 | + protected function getGraphQLCurrentUser() |
|
426 | + { |
|
427 | + $field_key = 'viewer'; |
|
428 | + $query = <<<QUERY |
|
429 | 429 | query GET_CURRENT_USER { |
430 | 430 | {$field_key} { |
431 | 431 | description |
@@ -443,24 +443,24 @@ discard block |
||
443 | 443 | } |
444 | 444 | } |
445 | 445 | QUERY; |
446 | - $data = [ |
|
447 | - 'operation_name' => 'GET_CURRENT_USER', |
|
448 | - 'query' => $query, |
|
449 | - ]; |
|
450 | - |
|
451 | - $responseData = $this->makeGraphQLRequest($data); |
|
452 | - return !empty($responseData[ $field_key ]) ? $responseData[ $field_key ] : null; |
|
453 | - } |
|
454 | - |
|
455 | - |
|
456 | - /** |
|
457 | - * @return array|null |
|
458 | - * @since $VID:$ |
|
459 | - */ |
|
460 | - protected function getGraphQLGeneralSettings() |
|
461 | - { |
|
462 | - $field_key = 'generalSettings'; |
|
463 | - $query = <<<QUERY |
|
446 | + $data = [ |
|
447 | + 'operation_name' => 'GET_CURRENT_USER', |
|
448 | + 'query' => $query, |
|
449 | + ]; |
|
450 | + |
|
451 | + $responseData = $this->makeGraphQLRequest($data); |
|
452 | + return !empty($responseData[ $field_key ]) ? $responseData[ $field_key ] : null; |
|
453 | + } |
|
454 | + |
|
455 | + |
|
456 | + /** |
|
457 | + * @return array|null |
|
458 | + * @since $VID:$ |
|
459 | + */ |
|
460 | + protected function getGraphQLGeneralSettings() |
|
461 | + { |
|
462 | + $field_key = 'generalSettings'; |
|
463 | + $query = <<<QUERY |
|
464 | 464 | query GET_GENERAL_SETTINGS { |
465 | 465 | {$field_key} { |
466 | 466 | dateFormat |
@@ -470,143 +470,143 @@ discard block |
||
470 | 470 | } |
471 | 471 | } |
472 | 472 | QUERY; |
473 | - $data = [ |
|
474 | - 'operation_name' => 'GET_CURRENT_USER', |
|
475 | - 'query' => $query, |
|
476 | - ]; |
|
477 | - |
|
478 | - $responseData = $this->makeGraphQLRequest($data); |
|
479 | - return !empty($responseData[ $field_key ]) ? $responseData[ $field_key ] : null; |
|
480 | - } |
|
481 | - |
|
482 | - |
|
483 | - /** |
|
484 | - * @param array $data |
|
485 | - * @return array |
|
486 | - * @since $VID:$ |
|
487 | - */ |
|
488 | - protected function makeGraphQLRequest($data) |
|
489 | - { |
|
490 | - try { |
|
491 | - $response = graphql($data); |
|
492 | - if (!empty($response['data'])) { |
|
493 | - return $response['data']; |
|
494 | - } |
|
495 | - return null; |
|
496 | - } catch (\Exception $e) { |
|
497 | - // do something with the errors thrown |
|
498 | - return null; |
|
499 | - } |
|
500 | - } |
|
501 | - |
|
502 | - |
|
503 | - /** |
|
504 | - * @param mixed $source The source that's passed down the GraphQL queries |
|
505 | - * @param array $args The inputArgs on the field |
|
506 | - * @param AppContext $context The AppContext passed down the GraphQL tree |
|
507 | - * @param ResolveInfo $info The ResolveInfo passed down the GraphQL tree |
|
508 | - * @return string |
|
509 | - * @throws EE_Error |
|
510 | - * @throws Exception |
|
511 | - * @throws InvalidArgumentException |
|
512 | - * @throws InvalidDataTypeException |
|
513 | - * @throws InvalidInterfaceException |
|
514 | - * @throws ReflectionException |
|
515 | - * @throws UserError |
|
516 | - * @throws UnexpectedEntityException |
|
517 | - * @since $VID:$ |
|
518 | - */ |
|
519 | - public static function getRelationalData($eventId) |
|
520 | - { |
|
521 | - $data = [ |
|
522 | - 'datetimes' => [], |
|
523 | - 'tickets' => [], |
|
524 | - 'prices' => [], |
|
525 | - ]; |
|
526 | - |
|
527 | - $eem_datetime = EEM_Datetime::instance(); |
|
528 | - $eem_ticket = EEM_Ticket::instance(); |
|
529 | - $eem_price = EEM_Price::instance(); |
|
530 | - $eem_price_type = EEM_Price_Type::instance(); |
|
531 | - |
|
532 | - // PROCESS DATETIMES |
|
533 | - $related_models = [ |
|
534 | - 'tickets' => $eem_ticket, |
|
535 | - ]; |
|
536 | - // Get the IDs of event datetimes. |
|
537 | - $datetimeIds = $eem_datetime->get_col([[ |
|
538 | - 'EVT_ID' => $eventId, |
|
539 | - 'DTT_deleted' => ['IN', [true, false]], |
|
540 | - ]]); |
|
541 | - foreach ($datetimeIds as $datetimeId) { |
|
542 | - $GID = self::convertToGlobalId($eem_datetime->item_name(), $datetimeId); |
|
543 | - foreach ($related_models as $key => $model) { |
|
544 | - // Get the IDs of related entities for the datetime ID. |
|
545 | - $Ids = $model->get_col([['Datetime.DTT_ID' => $datetimeId]]); |
|
546 | - if (! empty($Ids)) { |
|
547 | - $data['datetimes'][ $GID ][ $key ] = self::convertToGlobalId($model->item_name(), $Ids); |
|
548 | - } |
|
549 | - } |
|
550 | - } |
|
551 | - |
|
552 | - // PROCESS TICKETS |
|
553 | - $related_models = [ |
|
554 | - 'datetimes' => $eem_datetime, |
|
555 | - 'prices' => $eem_price, |
|
556 | - ]; |
|
557 | - // Get the IDs of all datetime tickets. |
|
558 | - $ticketIds = $eem_ticket->get_col([[ |
|
559 | - 'Datetime.DTT_ID' => ['in', $datetimeIds], |
|
560 | - 'TKT_deleted' => ['IN', [true, false]], |
|
561 | - ]]); |
|
562 | - foreach ($ticketIds as $ticketId) { |
|
563 | - $GID = self::convertToGlobalId($eem_ticket->item_name(), $ticketId); |
|
564 | - |
|
565 | - foreach ($related_models as $key => $model) { |
|
566 | - // Get the IDs of related entities for the ticket ID. |
|
567 | - $Ids = $model->get_col([['Ticket.TKT_ID' => $ticketId]]); |
|
568 | - if (! empty($Ids)) { |
|
569 | - $data['tickets'][ $GID ][ $key ] = self::convertToGlobalId($model->item_name(), $Ids); |
|
570 | - } |
|
571 | - } |
|
572 | - } |
|
573 | - |
|
574 | - // PROCESS PRICES |
|
575 | - $related_models = [ |
|
576 | - 'tickets' => $eem_ticket, |
|
577 | - 'priceTypes' => $eem_price_type, |
|
578 | - ]; |
|
579 | - // Get the IDs of all ticket prices. |
|
580 | - $priceIds = $eem_price->get_col([['Ticket.TKT_ID' => ['in', $ticketIds]]]); |
|
581 | - foreach ($priceIds as $priceId) { |
|
582 | - $GID = self::convertToGlobalId($eem_price->item_name(), $priceId); |
|
583 | - |
|
584 | - foreach ($related_models as $key => $model) { |
|
585 | - // Get the IDs of related entities for the price ID. |
|
586 | - $Ids = $model->get_col([['Price.PRC_ID' => $priceId]]); |
|
587 | - if (! empty($Ids)) { |
|
588 | - $data['prices'][ $GID ][ $key ] = self::convertToGlobalId($model->item_name(), $Ids); |
|
589 | - } |
|
590 | - } |
|
591 | - } |
|
592 | - |
|
593 | - return $data; |
|
594 | - } |
|
595 | - |
|
596 | - /** |
|
597 | - * Convert the DB ID into GID |
|
598 | - * |
|
599 | - * @param string $type |
|
600 | - * @param int|int[] $ID |
|
601 | - * @return mixed |
|
602 | - */ |
|
603 | - public static function convertToGlobalId($type, $ID) |
|
604 | - { |
|
605 | - if (is_array($ID)) { |
|
606 | - return array_map(function ($id) use ($type) { |
|
607 | - return self::convertToGlobalId($type, $id); |
|
608 | - }, $ID); |
|
609 | - } |
|
610 | - return Relay::toGlobalId($type, $ID); |
|
611 | - } |
|
473 | + $data = [ |
|
474 | + 'operation_name' => 'GET_CURRENT_USER', |
|
475 | + 'query' => $query, |
|
476 | + ]; |
|
477 | + |
|
478 | + $responseData = $this->makeGraphQLRequest($data); |
|
479 | + return !empty($responseData[ $field_key ]) ? $responseData[ $field_key ] : null; |
|
480 | + } |
|
481 | + |
|
482 | + |
|
483 | + /** |
|
484 | + * @param array $data |
|
485 | + * @return array |
|
486 | + * @since $VID:$ |
|
487 | + */ |
|
488 | + protected function makeGraphQLRequest($data) |
|
489 | + { |
|
490 | + try { |
|
491 | + $response = graphql($data); |
|
492 | + if (!empty($response['data'])) { |
|
493 | + return $response['data']; |
|
494 | + } |
|
495 | + return null; |
|
496 | + } catch (\Exception $e) { |
|
497 | + // do something with the errors thrown |
|
498 | + return null; |
|
499 | + } |
|
500 | + } |
|
501 | + |
|
502 | + |
|
503 | + /** |
|
504 | + * @param mixed $source The source that's passed down the GraphQL queries |
|
505 | + * @param array $args The inputArgs on the field |
|
506 | + * @param AppContext $context The AppContext passed down the GraphQL tree |
|
507 | + * @param ResolveInfo $info The ResolveInfo passed down the GraphQL tree |
|
508 | + * @return string |
|
509 | + * @throws EE_Error |
|
510 | + * @throws Exception |
|
511 | + * @throws InvalidArgumentException |
|
512 | + * @throws InvalidDataTypeException |
|
513 | + * @throws InvalidInterfaceException |
|
514 | + * @throws ReflectionException |
|
515 | + * @throws UserError |
|
516 | + * @throws UnexpectedEntityException |
|
517 | + * @since $VID:$ |
|
518 | + */ |
|
519 | + public static function getRelationalData($eventId) |
|
520 | + { |
|
521 | + $data = [ |
|
522 | + 'datetimes' => [], |
|
523 | + 'tickets' => [], |
|
524 | + 'prices' => [], |
|
525 | + ]; |
|
526 | + |
|
527 | + $eem_datetime = EEM_Datetime::instance(); |
|
528 | + $eem_ticket = EEM_Ticket::instance(); |
|
529 | + $eem_price = EEM_Price::instance(); |
|
530 | + $eem_price_type = EEM_Price_Type::instance(); |
|
531 | + |
|
532 | + // PROCESS DATETIMES |
|
533 | + $related_models = [ |
|
534 | + 'tickets' => $eem_ticket, |
|
535 | + ]; |
|
536 | + // Get the IDs of event datetimes. |
|
537 | + $datetimeIds = $eem_datetime->get_col([[ |
|
538 | + 'EVT_ID' => $eventId, |
|
539 | + 'DTT_deleted' => ['IN', [true, false]], |
|
540 | + ]]); |
|
541 | + foreach ($datetimeIds as $datetimeId) { |
|
542 | + $GID = self::convertToGlobalId($eem_datetime->item_name(), $datetimeId); |
|
543 | + foreach ($related_models as $key => $model) { |
|
544 | + // Get the IDs of related entities for the datetime ID. |
|
545 | + $Ids = $model->get_col([['Datetime.DTT_ID' => $datetimeId]]); |
|
546 | + if (! empty($Ids)) { |
|
547 | + $data['datetimes'][ $GID ][ $key ] = self::convertToGlobalId($model->item_name(), $Ids); |
|
548 | + } |
|
549 | + } |
|
550 | + } |
|
551 | + |
|
552 | + // PROCESS TICKETS |
|
553 | + $related_models = [ |
|
554 | + 'datetimes' => $eem_datetime, |
|
555 | + 'prices' => $eem_price, |
|
556 | + ]; |
|
557 | + // Get the IDs of all datetime tickets. |
|
558 | + $ticketIds = $eem_ticket->get_col([[ |
|
559 | + 'Datetime.DTT_ID' => ['in', $datetimeIds], |
|
560 | + 'TKT_deleted' => ['IN', [true, false]], |
|
561 | + ]]); |
|
562 | + foreach ($ticketIds as $ticketId) { |
|
563 | + $GID = self::convertToGlobalId($eem_ticket->item_name(), $ticketId); |
|
564 | + |
|
565 | + foreach ($related_models as $key => $model) { |
|
566 | + // Get the IDs of related entities for the ticket ID. |
|
567 | + $Ids = $model->get_col([['Ticket.TKT_ID' => $ticketId]]); |
|
568 | + if (! empty($Ids)) { |
|
569 | + $data['tickets'][ $GID ][ $key ] = self::convertToGlobalId($model->item_name(), $Ids); |
|
570 | + } |
|
571 | + } |
|
572 | + } |
|
573 | + |
|
574 | + // PROCESS PRICES |
|
575 | + $related_models = [ |
|
576 | + 'tickets' => $eem_ticket, |
|
577 | + 'priceTypes' => $eem_price_type, |
|
578 | + ]; |
|
579 | + // Get the IDs of all ticket prices. |
|
580 | + $priceIds = $eem_price->get_col([['Ticket.TKT_ID' => ['in', $ticketIds]]]); |
|
581 | + foreach ($priceIds as $priceId) { |
|
582 | + $GID = self::convertToGlobalId($eem_price->item_name(), $priceId); |
|
583 | + |
|
584 | + foreach ($related_models as $key => $model) { |
|
585 | + // Get the IDs of related entities for the price ID. |
|
586 | + $Ids = $model->get_col([['Price.PRC_ID' => $priceId]]); |
|
587 | + if (! empty($Ids)) { |
|
588 | + $data['prices'][ $GID ][ $key ] = self::convertToGlobalId($model->item_name(), $Ids); |
|
589 | + } |
|
590 | + } |
|
591 | + } |
|
592 | + |
|
593 | + return $data; |
|
594 | + } |
|
595 | + |
|
596 | + /** |
|
597 | + * Convert the DB ID into GID |
|
598 | + * |
|
599 | + * @param string $type |
|
600 | + * @param int|int[] $ID |
|
601 | + * @return mixed |
|
602 | + */ |
|
603 | + public static function convertToGlobalId($type, $ID) |
|
604 | + { |
|
605 | + if (is_array($ID)) { |
|
606 | + return array_map(function ($id) use ($type) { |
|
607 | + return self::convertToGlobalId($type, $id); |
|
608 | + }, $ID); |
|
609 | + } |
|
610 | + return Relay::toGlobalId($type, $ID); |
|
611 | + } |
|
612 | 612 | } |
@@ -102,7 +102,7 @@ discard block |
||
102 | 102 | { |
103 | 103 | if ($this->admin_config->useAdvancedEditor()) { |
104 | 104 | $eventId = $this->event instanceof EE_Event ? $this->event->ID() : 0; |
105 | - if (! $eventId) { |
|
105 | + if ( ! $eventId) { |
|
106 | 106 | global $post; |
107 | 107 | $eventId = isset($_REQUEST['post']) ? absint($_REQUEST['post']) : 0; |
108 | 108 | $eventId = $eventId === 0 && $post instanceof WP_Post && $post->post_type === 'espresso_events' |
@@ -114,7 +114,7 @@ discard block |
||
114 | 114 | $data = wp_json_encode($data); |
115 | 115 | add_action( |
116 | 116 | 'admin_footer', |
117 | - static function () use ($data) { |
|
117 | + static function() use ($data) { |
|
118 | 118 | wp_add_inline_script( |
119 | 119 | EspressoEditorAssetManager::JS_HANDLE_EDITOR_PROTOTYPE, |
120 | 120 | " |
@@ -147,7 +147,7 @@ discard block |
||
147 | 147 | $event = $this->getEventGraphQLData($eventId); |
148 | 148 | $event['dbId'] = $eventId; |
149 | 149 | |
150 | - $graphqlEndpoint = class_exists('WPGraphQL') ? trailingslashit(site_url()) . Router::$route : ''; |
|
150 | + $graphqlEndpoint = class_exists('WPGraphQL') ? trailingslashit(site_url()).Router::$route : ''; |
|
151 | 151 | $graphqlEndpoint = esc_url($graphqlEndpoint); |
152 | 152 | |
153 | 153 | $currentUser = $this->getGraphQLCurrentUser(); |
@@ -172,18 +172,18 @@ discard block |
||
172 | 172 | $datetimes = $this->getGraphQLDatetimes($eventId); |
173 | 173 | } |
174 | 174 | |
175 | - if (! empty($datetimes['nodes'])) { |
|
175 | + if ( ! empty($datetimes['nodes'])) { |
|
176 | 176 | $datetimeIn = wp_list_pluck($datetimes['nodes'], 'id'); |
177 | 177 | |
178 | - if (! empty($datetimeIn)) { |
|
178 | + if ( ! empty($datetimeIn)) { |
|
179 | 179 | $tickets = $this->getGraphQLTickets($datetimeIn); |
180 | 180 | } |
181 | 181 | } |
182 | 182 | |
183 | - if (! empty($tickets['nodes'])) { |
|
183 | + if ( ! empty($tickets['nodes'])) { |
|
184 | 184 | $ticketIn = wp_list_pluck($tickets['nodes'], 'id'); |
185 | 185 | |
186 | - if (! empty($ticketIn)) { |
|
186 | + if ( ! empty($ticketIn)) { |
|
187 | 187 | $prices = $this->getGraphQLPrices($ticketIn); |
188 | 188 | } |
189 | 189 | } |
@@ -235,7 +235,7 @@ discard block |
||
235 | 235 | */ |
236 | 236 | protected function getGraphQLDatetimes($eventId) |
237 | 237 | { |
238 | - $field_key = lcfirst($this->namespace) . 'Datetimes'; |
|
238 | + $field_key = lcfirst($this->namespace).'Datetimes'; |
|
239 | 239 | $query = <<<QUERY |
240 | 240 | query GET_DATETIMES(\$where: {$this->namespace}RootQueryDatetimesConnectionWhereArgs) { |
241 | 241 | {$field_key}(where: \$where) { |
@@ -276,7 +276,7 @@ discard block |
||
276 | 276 | ]; |
277 | 277 | |
278 | 278 | $responseData = $this->makeGraphQLRequest($data); |
279 | - return !empty($responseData[ $field_key ]) ? $responseData[ $field_key ] : null; |
|
279 | + return ! empty($responseData[$field_key]) ? $responseData[$field_key] : null; |
|
280 | 280 | } |
281 | 281 | |
282 | 282 | |
@@ -287,7 +287,7 @@ discard block |
||
287 | 287 | */ |
288 | 288 | protected function getGraphQLTickets(array $datetimeIn) |
289 | 289 | { |
290 | - $field_key = lcfirst($this->namespace) . 'Tickets'; |
|
290 | + $field_key = lcfirst($this->namespace).'Tickets'; |
|
291 | 291 | $query = <<<QUERY |
292 | 292 | query GET_TICKETS(\$where: {$this->namespace}RootQueryTicketsConnectionWhereArgs) { |
293 | 293 | {$field_key}(where: \$where) { |
@@ -330,7 +330,7 @@ discard block |
||
330 | 330 | ]; |
331 | 331 | |
332 | 332 | $responseData = $this->makeGraphQLRequest($data); |
333 | - return !empty($responseData[ $field_key ]) ? $responseData[ $field_key ] : null; |
|
333 | + return ! empty($responseData[$field_key]) ? $responseData[$field_key] : null; |
|
334 | 334 | } |
335 | 335 | |
336 | 336 | |
@@ -341,7 +341,7 @@ discard block |
||
341 | 341 | */ |
342 | 342 | protected function getGraphQLPrices(array $ticketIn) |
343 | 343 | { |
344 | - $field_key = lcfirst($this->namespace) . 'Prices'; |
|
344 | + $field_key = lcfirst($this->namespace).'Prices'; |
|
345 | 345 | $query = <<<QUERY |
346 | 346 | query GET_PRICES(\$where: {$this->namespace}RootQueryPricesConnectionWhereArgs) { |
347 | 347 | {$field_key}(where: \$where) { |
@@ -377,7 +377,7 @@ discard block |
||
377 | 377 | ]; |
378 | 378 | |
379 | 379 | $responseData = $this->makeGraphQLRequest($data); |
380 | - return !empty($responseData[ $field_key ]) ? $responseData[ $field_key ] : null; |
|
380 | + return ! empty($responseData[$field_key]) ? $responseData[$field_key] : null; |
|
381 | 381 | } |
382 | 382 | |
383 | 383 | |
@@ -387,7 +387,7 @@ discard block |
||
387 | 387 | */ |
388 | 388 | protected function getGraphQLPriceTypes() |
389 | 389 | { |
390 | - $field_key = lcfirst($this->namespace) . 'PriceTypes'; |
|
390 | + $field_key = lcfirst($this->namespace).'PriceTypes'; |
|
391 | 391 | $query = <<<QUERY |
392 | 392 | query GET_PRICES { |
393 | 393 | {$field_key} { |
@@ -414,7 +414,7 @@ discard block |
||
414 | 414 | ]; |
415 | 415 | |
416 | 416 | $responseData = $this->makeGraphQLRequest($data); |
417 | - return !empty($responseData[ $field_key ]) ? $responseData[ $field_key ] : null; |
|
417 | + return ! empty($responseData[$field_key]) ? $responseData[$field_key] : null; |
|
418 | 418 | } |
419 | 419 | |
420 | 420 | |
@@ -449,7 +449,7 @@ discard block |
||
449 | 449 | ]; |
450 | 450 | |
451 | 451 | $responseData = $this->makeGraphQLRequest($data); |
452 | - return !empty($responseData[ $field_key ]) ? $responseData[ $field_key ] : null; |
|
452 | + return ! empty($responseData[$field_key]) ? $responseData[$field_key] : null; |
|
453 | 453 | } |
454 | 454 | |
455 | 455 | |
@@ -476,7 +476,7 @@ discard block |
||
476 | 476 | ]; |
477 | 477 | |
478 | 478 | $responseData = $this->makeGraphQLRequest($data); |
479 | - return !empty($responseData[ $field_key ]) ? $responseData[ $field_key ] : null; |
|
479 | + return ! empty($responseData[$field_key]) ? $responseData[$field_key] : null; |
|
480 | 480 | } |
481 | 481 | |
482 | 482 | |
@@ -489,7 +489,7 @@ discard block |
||
489 | 489 | { |
490 | 490 | try { |
491 | 491 | $response = graphql($data); |
492 | - if (!empty($response['data'])) { |
|
492 | + if ( ! empty($response['data'])) { |
|
493 | 493 | return $response['data']; |
494 | 494 | } |
495 | 495 | return null; |
@@ -543,8 +543,8 @@ discard block |
||
543 | 543 | foreach ($related_models as $key => $model) { |
544 | 544 | // Get the IDs of related entities for the datetime ID. |
545 | 545 | $Ids = $model->get_col([['Datetime.DTT_ID' => $datetimeId]]); |
546 | - if (! empty($Ids)) { |
|
547 | - $data['datetimes'][ $GID ][ $key ] = self::convertToGlobalId($model->item_name(), $Ids); |
|
546 | + if ( ! empty($Ids)) { |
|
547 | + $data['datetimes'][$GID][$key] = self::convertToGlobalId($model->item_name(), $Ids); |
|
548 | 548 | } |
549 | 549 | } |
550 | 550 | } |
@@ -565,8 +565,8 @@ discard block |
||
565 | 565 | foreach ($related_models as $key => $model) { |
566 | 566 | // Get the IDs of related entities for the ticket ID. |
567 | 567 | $Ids = $model->get_col([['Ticket.TKT_ID' => $ticketId]]); |
568 | - if (! empty($Ids)) { |
|
569 | - $data['tickets'][ $GID ][ $key ] = self::convertToGlobalId($model->item_name(), $Ids); |
|
568 | + if ( ! empty($Ids)) { |
|
569 | + $data['tickets'][$GID][$key] = self::convertToGlobalId($model->item_name(), $Ids); |
|
570 | 570 | } |
571 | 571 | } |
572 | 572 | } |
@@ -584,8 +584,8 @@ discard block |
||
584 | 584 | foreach ($related_models as $key => $model) { |
585 | 585 | // Get the IDs of related entities for the price ID. |
586 | 586 | $Ids = $model->get_col([['Price.PRC_ID' => $priceId]]); |
587 | - if (! empty($Ids)) { |
|
588 | - $data['prices'][ $GID ][ $key ] = self::convertToGlobalId($model->item_name(), $Ids); |
|
587 | + if ( ! empty($Ids)) { |
|
588 | + $data['prices'][$GID][$key] = self::convertToGlobalId($model->item_name(), $Ids); |
|
589 | 589 | } |
590 | 590 | } |
591 | 591 | } |
@@ -603,7 +603,7 @@ discard block |
||
603 | 603 | public static function convertToGlobalId($type, $ID) |
604 | 604 | { |
605 | 605 | if (is_array($ID)) { |
606 | - return array_map(function ($id) use ($type) { |
|
606 | + return array_map(function($id) use ($type) { |
|
607 | 607 | return self::convertToGlobalId($type, $id); |
608 | 608 | }, $ID); |
609 | 609 | } |