Completed
Branch EDTR/webpack-reconfiguration (5e800d)
by
unknown
33:50 queued 25:50
created
core/services/assets/I18nRegistry.php 2 patches
Indentation   +222 added lines, -222 removed lines patch added patch discarded remove patch
@@ -15,226 +15,226 @@
 block discarded – undo
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
 }
Please login to merge, or discard this patch.
Spacing   +5 added lines, -6 removed lines patch added patch discarded remove patch
@@ -72,7 +72,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 
Please login to merge, or discard this patch.
core/domain/services/assets/EspressoEditorAssetManager.php 1 patch
Indentation   +41 added lines, -41 removed lines patch added patch discarded remove patch
@@ -19,51 +19,51 @@
 block discarded – undo
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
 }
Please login to merge, or discard this patch.
core/domain/services/admin/events/editor/AdvancedEditorData.php 2 patches
Indentation   +479 added lines, -479 removed lines patch added patch discarded remove patch
@@ -35,211 +35,211 @@  discard block
 block discarded – undo
35 35
 class AdvancedEditorData
36 36
 {
37 37
 
38
-    /**
39
-     * @var string $namespace The graphql namespace/prefix.
40
-     */
41
-    protected $namespace = 'Espresso';
42
-
43
-    /**
44
-     * @var EE_Event
45
-     */
46
-    protected $event;
47
-
48
-    /**
49
-     * @var EE_Admin_Config
50
-     */
51
-    protected $admin_config;
52
-    /**
53
-     * @var EEM_Datetime $datetime_model
54
-     */
55
-    protected $datetime_model;
56
-    /**
57
-     * @var EEM_Price $price_model
58
-     */
59
-    protected $price_model;
60
-    /**
61
-     * @var EEM_Ticket $ticket_model
62
-     */
63
-    protected $ticket_model;
64
-
65
-
66
-    /**
67
-     * AdvancedEditorAdminForm constructor.
68
-     *
69
-     * @param EE_Event        $event
70
-     * @param EE_Admin_Config $admin_config
71
-     * @param EEM_Datetime    $datetime_model
72
-     * @param EEM_Price       $price_model
73
-     * @param EEM_Ticket      $ticket_model
74
-     */
75
-    public function __construct(
76
-        EE_Event $event,
77
-        EE_Admin_Config $admin_config,
78
-        EEM_Datetime $datetime_model,
79
-        EEM_Price $price_model,
80
-        EEM_Ticket $ticket_model
81
-    ) {
82
-        $this->event = $event;
83
-        $this->admin_config = $admin_config;
84
-        $this->datetime_model = $datetime_model;
85
-        $this->price_model = $price_model;
86
-        $this->ticket_model = $ticket_model;
87
-        add_action('admin_enqueue_scripts', [$this, 'loadScriptsStyles']);
88
-    }
89
-
90
-
91
-    /**
92
-     * @throws EE_Error
93
-     * @throws InvalidArgumentException
94
-     * @throws InvalidDataTypeException
95
-     * @throws InvalidInterfaceException
96
-     * @throws ModelConfigurationException
97
-     * @throws ReflectionException
98
-     * @throws UnexpectedEntityException
99
-     * @throws DomainException
100
-     * @since $VID:$
101
-     */
102
-    public function loadScriptsStyles()
103
-    {
104
-        if ($this->admin_config->useAdvancedEditor()) {
105
-            $eventId = $this->event instanceof EE_Event ? $this->event->ID() : 0;
106
-            if (! $eventId) {
107
-                global $post;
108
-                $eventId = isset($_REQUEST['post']) ? absint($_REQUEST['post']) : 0;
109
-                $eventId = $eventId === 0 && $post instanceof WP_Post && $post->post_type === 'espresso_events'
110
-                    ? $post->ID
111
-                    : $eventId;
112
-            }
113
-            if ($eventId) {
114
-                $data = $this->getEditorData($eventId);
115
-                $data = wp_json_encode($data);
116
-                add_action(
117
-                    'admin_footer',
118
-                    static function () use ($data) {
119
-                        wp_add_inline_script(
120
-                            EspressoEditorAssetManager::JS_HANDLE_EDITOR_PROTOTYPE,
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_PROTOTYPE,
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
-        return compact('event', 'graphqlEndpoint', 'currentUser', 'generalSettings', 'i18n');
161
-    }
162
-
163
-
164
-    /**
165
-     * @param int $eventId
166
-     * @return array
167
-     * @since $VID:$
168
-     */
169
-    protected function getEventGraphQLData($eventId)
170
-    {
171
-        $datetimes = $this->getGraphQLDatetimes($eventId);
172
-
173
-        if (empty($datetimes['nodes']) || (isset($_REQUEST['action']) && $_REQUEST['action'] === 'create_new')) {
174
-            $this->addDefaultEntities($eventId);
175
-            $datetimes = $this->getGraphQLDatetimes($eventId);
176
-        }
177
-
178
-        if (! empty($datetimes['nodes'])) {
179
-            $datetimeIn = wp_list_pluck($datetimes['nodes'], 'id');
180
-
181
-            if (! empty($datetimeIn)) {
182
-                $tickets = $this->getGraphQLTickets($datetimeIn);
183
-            }
184
-        }
185
-
186
-        if (! empty($tickets['nodes'])) {
187
-            $ticketIn = wp_list_pluck($tickets['nodes'], 'id');
188
-
189
-            if (! empty($ticketIn)) {
190
-                $prices = $this->getGraphQLPrices($ticketIn);
191
-            }
192
-        }
193
-
194
-        $priceTypes = $this->getGraphQLPriceTypes();
195
-
196
-        $relations = $this->getRelationalData($eventId);
197
-
198
-        return compact('datetimes', 'tickets', 'prices', 'priceTypes', 'relations');
199
-    }
200
-
201
-    /**
202
-     * @param int $eventId
203
-     * @throws DomainException
204
-     * @throws EE_Error
205
-     * @throws InvalidArgumentException
206
-     * @throws InvalidDataTypeException
207
-     * @throws InvalidInterfaceException
208
-     * @throws ModelConfigurationException
209
-     * @throws ReflectionException
210
-     * @throws UnexpectedEntityException
211
-     * @since $VID:$
212
-     */
213
-    protected function addDefaultEntities($eventId)
214
-    {
215
-        $default_dates = $this->datetime_model->create_new_blank_datetime();
216
-        if (is_array($default_dates) && isset($default_dates[0]) && $default_dates[0] instanceof EE_Datetime) {
217
-            $default_date = $default_dates[0];
218
-            $default_date->save();
219
-            $default_date->_add_relation_to($eventId, 'Event');
220
-            $default_tickets = $this->ticket_model->get_all_default_tickets();
221
-            $default_prices = $this->price_model->get_all_default_prices();
222
-            foreach ($default_tickets as $default_ticket) {
223
-                $default_ticket->save();
224
-                $default_ticket->_add_relation_to($default_date, 'Datetime');
225
-                foreach ($default_prices as $default_price) {
226
-                    $default_price->save();
227
-                    $default_price->_add_relation_to($default_ticket, 'Ticket');
228
-                }
229
-            }
230
-        }
231
-    }
232
-
233
-
234
-    /**
235
-     * @param int $eventId
236
-     * @return array|null
237
-     * @since $VID:$
238
-     */
239
-    protected function getGraphQLDatetimes($eventId)
240
-    {
241
-        $field_key = lcfirst($this->namespace) . 'Datetimes';
242
-        $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
+		return compact('event', 'graphqlEndpoint', 'currentUser', 'generalSettings', 'i18n');
161
+	}
162
+
163
+
164
+	/**
165
+	 * @param int $eventId
166
+	 * @return array
167
+	 * @since $VID:$
168
+	 */
169
+	protected function getEventGraphQLData($eventId)
170
+	{
171
+		$datetimes = $this->getGraphQLDatetimes($eventId);
172
+
173
+		if (empty($datetimes['nodes']) || (isset($_REQUEST['action']) && $_REQUEST['action'] === 'create_new')) {
174
+			$this->addDefaultEntities($eventId);
175
+			$datetimes = $this->getGraphQLDatetimes($eventId);
176
+		}
177
+
178
+		if (! empty($datetimes['nodes'])) {
179
+			$datetimeIn = wp_list_pluck($datetimes['nodes'], 'id');
180
+
181
+			if (! empty($datetimeIn)) {
182
+				$tickets = $this->getGraphQLTickets($datetimeIn);
183
+			}
184
+		}
185
+
186
+		if (! empty($tickets['nodes'])) {
187
+			$ticketIn = wp_list_pluck($tickets['nodes'], 'id');
188
+
189
+			if (! empty($ticketIn)) {
190
+				$prices = $this->getGraphQLPrices($ticketIn);
191
+			}
192
+		}
193
+
194
+		$priceTypes = $this->getGraphQLPriceTypes();
195
+
196
+		$relations = $this->getRelationalData($eventId);
197
+
198
+		return compact('datetimes', 'tickets', 'prices', 'priceTypes', 'relations');
199
+	}
200
+
201
+	/**
202
+	 * @param int $eventId
203
+	 * @throws DomainException
204
+	 * @throws EE_Error
205
+	 * @throws InvalidArgumentException
206
+	 * @throws InvalidDataTypeException
207
+	 * @throws InvalidInterfaceException
208
+	 * @throws ModelConfigurationException
209
+	 * @throws ReflectionException
210
+	 * @throws UnexpectedEntityException
211
+	 * @since $VID:$
212
+	 */
213
+	protected function addDefaultEntities($eventId)
214
+	{
215
+		$default_dates = $this->datetime_model->create_new_blank_datetime();
216
+		if (is_array($default_dates) && isset($default_dates[0]) && $default_dates[0] instanceof EE_Datetime) {
217
+			$default_date = $default_dates[0];
218
+			$default_date->save();
219
+			$default_date->_add_relation_to($eventId, 'Event');
220
+			$default_tickets = $this->ticket_model->get_all_default_tickets();
221
+			$default_prices = $this->price_model->get_all_default_prices();
222
+			foreach ($default_tickets as $default_ticket) {
223
+				$default_ticket->save();
224
+				$default_ticket->_add_relation_to($default_date, 'Datetime');
225
+				foreach ($default_prices as $default_price) {
226
+					$default_price->save();
227
+					$default_price->_add_relation_to($default_ticket, 'Ticket');
228
+				}
229
+			}
230
+		}
231
+	}
232
+
233
+
234
+	/**
235
+	 * @param int $eventId
236
+	 * @return array|null
237
+	 * @since $VID:$
238
+	 */
239
+	protected function getGraphQLDatetimes($eventId)
240
+	{
241
+		$field_key = lcfirst($this->namespace) . 'Datetimes';
242
+		$query = <<<QUERY
243 243
         query GET_DATETIMES(\$where: {$this->namespace}RootQueryDatetimesConnectionWhereArgs) {
244 244
             {$field_key}(where: \$where) {
245 245
                 nodes {
@@ -267,31 +267,31 @@  discard block
 block discarded – undo
267 267
             }
268 268
         }
269 269
 QUERY;
270
-        $data = [
271
-            'operation_name' => 'GET_DATETIMES',
272
-            'variables' => [
273
-                'first' => 50,
274
-                'where' => [
275
-                    'eventId' => $eventId,
276
-                ],
277
-            ],
278
-            'query' => $query,
279
-        ];
280
-
281
-        $responseData = $this->makeGraphQLRequest($data);
282
-        return !empty($responseData[ $field_key ]) ? $responseData[ $field_key ] : null;
283
-    }
284
-
285
-
286
-    /**
287
-     * @param array $datetimeIn
288
-     * @return array|null
289
-     * @since $VID:$
290
-     */
291
-    protected function getGraphQLTickets(array $datetimeIn)
292
-    {
293
-        $field_key = lcfirst($this->namespace) . 'Tickets';
294
-        $query = <<<QUERY
270
+		$data = [
271
+			'operation_name' => 'GET_DATETIMES',
272
+			'variables' => [
273
+				'first' => 50,
274
+				'where' => [
275
+					'eventId' => $eventId,
276
+				],
277
+			],
278
+			'query' => $query,
279
+		];
280
+
281
+		$responseData = $this->makeGraphQLRequest($data);
282
+		return !empty($responseData[ $field_key ]) ? $responseData[ $field_key ] : null;
283
+	}
284
+
285
+
286
+	/**
287
+	 * @param array $datetimeIn
288
+	 * @return array|null
289
+	 * @since $VID:$
290
+	 */
291
+	protected function getGraphQLTickets(array $datetimeIn)
292
+	{
293
+		$field_key = lcfirst($this->namespace) . 'Tickets';
294
+		$query = <<<QUERY
295 295
         query GET_TICKETS(\$where: {$this->namespace}RootQueryTicketsConnectionWhereArgs) {
296 296
             {$field_key}(where: \$where) {
297 297
                 nodes {
@@ -322,30 +322,30 @@  discard block
 block discarded – undo
322 322
             }
323 323
         }
324 324
 QUERY;
325
-        $data = [
326
-            'operation_name' => 'GET_TICKETS',
327
-            'variables' => [
328
-                'where' => [
329
-                    'datetimeIn' => $datetimeIn,
330
-                ],
331
-            ],
332
-            'query' => $query,
333
-        ];
334
-
335
-        $responseData = $this->makeGraphQLRequest($data);
336
-        return !empty($responseData[ $field_key ]) ? $responseData[ $field_key ] : null;
337
-    }
338
-
339
-
340
-    /**
341
-     * @param array $ticketIn
342
-     * @return array|null
343
-     * @since $VID:$
344
-     */
345
-    protected function getGraphQLPrices(array $ticketIn)
346
-    {
347
-        $field_key = lcfirst($this->namespace) . 'Prices';
348
-        $query = <<<QUERY
325
+		$data = [
326
+			'operation_name' => 'GET_TICKETS',
327
+			'variables' => [
328
+				'where' => [
329
+					'datetimeIn' => $datetimeIn,
330
+				],
331
+			],
332
+			'query' => $query,
333
+		];
334
+
335
+		$responseData = $this->makeGraphQLRequest($data);
336
+		return !empty($responseData[ $field_key ]) ? $responseData[ $field_key ] : null;
337
+	}
338
+
339
+
340
+	/**
341
+	 * @param array $ticketIn
342
+	 * @return array|null
343
+	 * @since $VID:$
344
+	 */
345
+	protected function getGraphQLPrices(array $ticketIn)
346
+	{
347
+		$field_key = lcfirst($this->namespace) . 'Prices';
348
+		$query = <<<QUERY
349 349
         query GET_PRICES(\$where: {$this->namespace}RootQueryPricesConnectionWhereArgs) {
350 350
             {$field_key}(where: \$where) {
351 351
                 nodes {
@@ -369,29 +369,29 @@  discard block
 block discarded – undo
369 369
             }
370 370
         }
371 371
 QUERY;
372
-        $data = [
373
-            'operation_name' => 'GET_PRICES',
374
-            'variables' => [
375
-                'where' => [
376
-                    'ticketIn' => $ticketIn,
377
-                ],
378
-            ],
379
-            'query' => $query,
380
-        ];
381
-
382
-        $responseData = $this->makeGraphQLRequest($data);
383
-        return !empty($responseData[ $field_key ]) ? $responseData[ $field_key ] : null;
384
-    }
385
-
386
-
387
-    /**
388
-     * @return array|null
389
-     * @since $VID:$
390
-     */
391
-    protected function getGraphQLPriceTypes()
392
-    {
393
-        $field_key = lcfirst($this->namespace) . 'PriceTypes';
394
-        $query = <<<QUERY
372
+		$data = [
373
+			'operation_name' => 'GET_PRICES',
374
+			'variables' => [
375
+				'where' => [
376
+					'ticketIn' => $ticketIn,
377
+				],
378
+			],
379
+			'query' => $query,
380
+		];
381
+
382
+		$responseData = $this->makeGraphQLRequest($data);
383
+		return !empty($responseData[ $field_key ]) ? $responseData[ $field_key ] : null;
384
+	}
385
+
386
+
387
+	/**
388
+	 * @return array|null
389
+	 * @since $VID:$
390
+	 */
391
+	protected function getGraphQLPriceTypes()
392
+	{
393
+		$field_key = lcfirst($this->namespace) . 'PriceTypes';
394
+		$query = <<<QUERY
395 395
         query GET_PRICES {
396 396
             {$field_key} {
397 397
                 nodes {
@@ -411,24 +411,24 @@  discard block
 block discarded – undo
411 411
             }
412 412
         }
413 413
 QUERY;
414
-        $data = [
415
-            'operation_name' => 'GET_PRICES',
416
-            'query' => $query,
417
-        ];
418
-
419
-        $responseData = $this->makeGraphQLRequest($data);
420
-        return !empty($responseData[ $field_key ]) ? $responseData[ $field_key ] : null;
421
-    }
422
-
423
-
424
-    /**
425
-     * @return array|null
426
-     * @since $VID:$
427
-     */
428
-    protected function getGraphQLCurrentUser()
429
-    {
430
-        $field_key = 'viewer';
431
-        $query = <<<QUERY
414
+		$data = [
415
+			'operation_name' => 'GET_PRICES',
416
+			'query' => $query,
417
+		];
418
+
419
+		$responseData = $this->makeGraphQLRequest($data);
420
+		return !empty($responseData[ $field_key ]) ? $responseData[ $field_key ] : null;
421
+	}
422
+
423
+
424
+	/**
425
+	 * @return array|null
426
+	 * @since $VID:$
427
+	 */
428
+	protected function getGraphQLCurrentUser()
429
+	{
430
+		$field_key = 'viewer';
431
+		$query = <<<QUERY
432 432
         query GET_CURRENT_USER {
433 433
             {$field_key} {
434 434
                 description
@@ -446,24 +446,24 @@  discard block
 block discarded – undo
446 446
             }
447 447
         }
448 448
 QUERY;
449
-        $data = [
450
-            'operation_name' => 'GET_CURRENT_USER',
451
-            'query' => $query,
452
-        ];
453
-
454
-        $responseData = $this->makeGraphQLRequest($data);
455
-        return !empty($responseData[ $field_key ]) ? $responseData[ $field_key ] : null;
456
-    }
457
-
458
-
459
-    /**
460
-     * @return array|null
461
-     * @since $VID:$
462
-     */
463
-    protected function getGraphQLGeneralSettings()
464
-    {
465
-        $field_key = 'generalSettings';
466
-        $query = <<<QUERY
449
+		$data = [
450
+			'operation_name' => 'GET_CURRENT_USER',
451
+			'query' => $query,
452
+		];
453
+
454
+		$responseData = $this->makeGraphQLRequest($data);
455
+		return !empty($responseData[ $field_key ]) ? $responseData[ $field_key ] : null;
456
+	}
457
+
458
+
459
+	/**
460
+	 * @return array|null
461
+	 * @since $VID:$
462
+	 */
463
+	protected function getGraphQLGeneralSettings()
464
+	{
465
+		$field_key = 'generalSettings';
466
+		$query = <<<QUERY
467 467
         query GET_GENERAL_SETTINGS {
468 468
             {$field_key} {
469 469
                 dateFormat
@@ -473,172 +473,172 @@  discard block
 block discarded – undo
473 473
             }
474 474
         }
475 475
 QUERY;
476
-        $data = [
477
-            'operation_name' => 'GET_CURRENT_USER',
478
-            'query' => $query,
479
-        ];
480
-
481
-        $responseData = $this->makeGraphQLRequest($data);
482
-        return !empty($responseData[ $field_key ]) ? $responseData[ $field_key ] : null;
483
-    }
484
-
485
-
486
-    /**
487
-     * @param array $data
488
-     * @return array
489
-     * @since $VID:$
490
-     */
491
-    protected function makeGraphQLRequest($data)
492
-    {
493
-        try {
494
-            $response = graphql($data);
495
-            if (!empty($response['data'])) {
496
-                return $response['data'];
497
-            }
498
-            return null;
499
-        } catch (\Exception $e) {
500
-            // do something with the errors thrown
501
-            return null;
502
-        }
503
-    }
504
-
505
-
506
-    /**
507
-     * @param mixed       $source  The source that's passed down the GraphQL queries
508
-     * @param array       $args    The inputArgs on the field
509
-     * @param AppContext  $context The AppContext passed down the GraphQL tree
510
-     * @param ResolveInfo $info    The ResolveInfo passed down the GraphQL tree
511
-     * @return string
512
-     * @throws EE_Error
513
-     * @throws Exception
514
-     * @throws InvalidArgumentException
515
-     * @throws InvalidDataTypeException
516
-     * @throws InvalidInterfaceException
517
-     * @throws ReflectionException
518
-     * @throws UserError
519
-     * @throws UnexpectedEntityException
520
-     * @since $VID:$
521
-     */
522
-    public static function getRelationalData($eventId)
523
-    {
524
-        $data = [
525
-            'datetimes'  => [],
526
-            'tickets'    => [],
527
-            'prices'     => [],
528
-        ];
529
-
530
-        $eem_datetime   = EEM_Datetime::instance();
531
-        $eem_ticket     = EEM_Ticket::instance();
532
-        $eem_price      = EEM_Price::instance();
533
-        $eem_price_type = EEM_Price_Type::instance();
534
-
535
-        // PROCESS DATETIMES
536
-        $related_models = [
537
-            'tickets' => $eem_ticket,
538
-        ];
539
-        // Get the IDs of event datetimes.
540
-        $datetimeIds = $eem_datetime->get_col([[
541
-            'EVT_ID' => $eventId,
542
-            'DTT_deleted' => ['IN', [true, false]],
543
-        ]]);
544
-        foreach ($datetimeIds as $datetimeId) {
545
-            $GID = self::convertToGlobalId($eem_datetime->item_name(), $datetimeId);
546
-            foreach ($related_models as $key => $model) {
547
-                // Get the IDs of related entities for the datetime ID.
548
-                $Ids = $model->get_col([['Datetime.DTT_ID' => $datetimeId]]);
549
-                if (! empty($Ids)) {
550
-                    $data['datetimes'][ $GID ][ $key ] = self::convertToGlobalId($model->item_name(), $Ids);
551
-                }
552
-            }
553
-        }
554
-
555
-        // PROCESS TICKETS
556
-        $related_models = [
557
-            'datetimes' => $eem_datetime,
558
-            'prices'    => $eem_price,
559
-        ];
560
-        // Get the IDs of all datetime tickets.
561
-        $ticketIds = $eem_ticket->get_col([[
562
-            'Datetime.DTT_ID' => ['in', $datetimeIds],
563
-            'TKT_deleted' => ['IN', [true, false]],
564
-        ]]);
565
-        foreach ($ticketIds as $ticketId) {
566
-            $GID = self::convertToGlobalId($eem_ticket->item_name(), $ticketId);
567
-
568
-            foreach ($related_models as $key => $model) {
569
-                // Get the IDs of related entities for the ticket ID.
570
-                $Ids = $model->get_col([['Ticket.TKT_ID' => $ticketId]]);
571
-                if (! empty($Ids)) {
572
-                    $data['tickets'][ $GID ][ $key ] = self::convertToGlobalId($model->item_name(), $Ids);
573
-                }
574
-            }
575
-        }
576
-
577
-        // PROCESS PRICES
578
-        $related_models = [
579
-            'tickets'    => $eem_ticket,
580
-            'priceTypes' => $eem_price_type,
581
-        ];
582
-        // Get the IDs of all ticket prices.
583
-        $priceIds = $eem_price->get_col([['Ticket.TKT_ID' => ['in', $ticketIds]]]);
584
-        foreach ($priceIds as $priceId) {
585
-            $GID = self::convertToGlobalId($eem_price->item_name(), $priceId);
586
-
587
-            foreach ($related_models as $key => $model) {
588
-                // Get the IDs of related entities for the price ID.
589
-                $Ids = $model->get_col([['Price.PRC_ID' => $priceId]]);
590
-                if (! empty($Ids)) {
591
-                    $data['prices'][ $GID ][ $key ] = self::convertToGlobalId($model->item_name(), $Ids);
592
-                }
593
-            }
594
-        }
595
-
596
-        return $data;
597
-    }
598
-
599
-    /**
600
-     * Convert the DB ID into GID
601
-     *
602
-     * @param string    $type
603
-     * @param int|int[] $ID
604
-     * @return mixed
605
-     */
606
-    public static function convertToGlobalId($type, $ID)
607
-    {
608
-        if (is_array($ID)) {
609
-            return array_map(function ($id) use ($type) {
610
-                return self::convertToGlobalId($type, $id);
611
-            }, $ID);
612
-        }
613
-        return Relay::toGlobalId($type, $ID);
614
-    }
615
-
616
-
617
-    /**
618
-     * Returns Jed-formatted localization data.
619
-     *
620
-     * @param  string $domain Translation domain.
621
-     * @return array
622
-     */
623
-    public static function getJedLocaleData($domain)
624
-    {
625
-        $translations = get_translations_for_domain($domain);
626
-
627
-        $locale = array(
628
-            '' => array(
629
-                'domain' => $domain,
630
-                'lang'   => is_admin() ? EEH_DTT_Helper::get_user_locale() : get_locale()
631
-            ),
632
-        );
633
-
634
-        if (! empty($translations->headers['Plural-Forms'])) {
635
-            $locale['']['plural_forms'] = $translations->headers['Plural-Forms'];
636
-        }
637
-
638
-        foreach ($translations->entries as $msgid => $entry) {
639
-            $locale[ $msgid ] = $entry->translations;
640
-        }
641
-
642
-        return $locale;
643
-    }
476
+		$data = [
477
+			'operation_name' => 'GET_CURRENT_USER',
478
+			'query' => $query,
479
+		];
480
+
481
+		$responseData = $this->makeGraphQLRequest($data);
482
+		return !empty($responseData[ $field_key ]) ? $responseData[ $field_key ] : null;
483
+	}
484
+
485
+
486
+	/**
487
+	 * @param array $data
488
+	 * @return array
489
+	 * @since $VID:$
490
+	 */
491
+	protected function makeGraphQLRequest($data)
492
+	{
493
+		try {
494
+			$response = graphql($data);
495
+			if (!empty($response['data'])) {
496
+				return $response['data'];
497
+			}
498
+			return null;
499
+		} catch (\Exception $e) {
500
+			// do something with the errors thrown
501
+			return null;
502
+		}
503
+	}
504
+
505
+
506
+	/**
507
+	 * @param mixed       $source  The source that's passed down the GraphQL queries
508
+	 * @param array       $args    The inputArgs on the field
509
+	 * @param AppContext  $context The AppContext passed down the GraphQL tree
510
+	 * @param ResolveInfo $info    The ResolveInfo passed down the GraphQL tree
511
+	 * @return string
512
+	 * @throws EE_Error
513
+	 * @throws Exception
514
+	 * @throws InvalidArgumentException
515
+	 * @throws InvalidDataTypeException
516
+	 * @throws InvalidInterfaceException
517
+	 * @throws ReflectionException
518
+	 * @throws UserError
519
+	 * @throws UnexpectedEntityException
520
+	 * @since $VID:$
521
+	 */
522
+	public static function getRelationalData($eventId)
523
+	{
524
+		$data = [
525
+			'datetimes'  => [],
526
+			'tickets'    => [],
527
+			'prices'     => [],
528
+		];
529
+
530
+		$eem_datetime   = EEM_Datetime::instance();
531
+		$eem_ticket     = EEM_Ticket::instance();
532
+		$eem_price      = EEM_Price::instance();
533
+		$eem_price_type = EEM_Price_Type::instance();
534
+
535
+		// PROCESS DATETIMES
536
+		$related_models = [
537
+			'tickets' => $eem_ticket,
538
+		];
539
+		// Get the IDs of event datetimes.
540
+		$datetimeIds = $eem_datetime->get_col([[
541
+			'EVT_ID' => $eventId,
542
+			'DTT_deleted' => ['IN', [true, false]],
543
+		]]);
544
+		foreach ($datetimeIds as $datetimeId) {
545
+			$GID = self::convertToGlobalId($eem_datetime->item_name(), $datetimeId);
546
+			foreach ($related_models as $key => $model) {
547
+				// Get the IDs of related entities for the datetime ID.
548
+				$Ids = $model->get_col([['Datetime.DTT_ID' => $datetimeId]]);
549
+				if (! empty($Ids)) {
550
+					$data['datetimes'][ $GID ][ $key ] = self::convertToGlobalId($model->item_name(), $Ids);
551
+				}
552
+			}
553
+		}
554
+
555
+		// PROCESS TICKETS
556
+		$related_models = [
557
+			'datetimes' => $eem_datetime,
558
+			'prices'    => $eem_price,
559
+		];
560
+		// Get the IDs of all datetime tickets.
561
+		$ticketIds = $eem_ticket->get_col([[
562
+			'Datetime.DTT_ID' => ['in', $datetimeIds],
563
+			'TKT_deleted' => ['IN', [true, false]],
564
+		]]);
565
+		foreach ($ticketIds as $ticketId) {
566
+			$GID = self::convertToGlobalId($eem_ticket->item_name(), $ticketId);
567
+
568
+			foreach ($related_models as $key => $model) {
569
+				// Get the IDs of related entities for the ticket ID.
570
+				$Ids = $model->get_col([['Ticket.TKT_ID' => $ticketId]]);
571
+				if (! empty($Ids)) {
572
+					$data['tickets'][ $GID ][ $key ] = self::convertToGlobalId($model->item_name(), $Ids);
573
+				}
574
+			}
575
+		}
576
+
577
+		// PROCESS PRICES
578
+		$related_models = [
579
+			'tickets'    => $eem_ticket,
580
+			'priceTypes' => $eem_price_type,
581
+		];
582
+		// Get the IDs of all ticket prices.
583
+		$priceIds = $eem_price->get_col([['Ticket.TKT_ID' => ['in', $ticketIds]]]);
584
+		foreach ($priceIds as $priceId) {
585
+			$GID = self::convertToGlobalId($eem_price->item_name(), $priceId);
586
+
587
+			foreach ($related_models as $key => $model) {
588
+				// Get the IDs of related entities for the price ID.
589
+				$Ids = $model->get_col([['Price.PRC_ID' => $priceId]]);
590
+				if (! empty($Ids)) {
591
+					$data['prices'][ $GID ][ $key ] = self::convertToGlobalId($model->item_name(), $Ids);
592
+				}
593
+			}
594
+		}
595
+
596
+		return $data;
597
+	}
598
+
599
+	/**
600
+	 * Convert the DB ID into GID
601
+	 *
602
+	 * @param string    $type
603
+	 * @param int|int[] $ID
604
+	 * @return mixed
605
+	 */
606
+	public static function convertToGlobalId($type, $ID)
607
+	{
608
+		if (is_array($ID)) {
609
+			return array_map(function ($id) use ($type) {
610
+				return self::convertToGlobalId($type, $id);
611
+			}, $ID);
612
+		}
613
+		return Relay::toGlobalId($type, $ID);
614
+	}
615
+
616
+
617
+	/**
618
+	 * Returns Jed-formatted localization data.
619
+	 *
620
+	 * @param  string $domain Translation domain.
621
+	 * @return array
622
+	 */
623
+	public static function getJedLocaleData($domain)
624
+	{
625
+		$translations = get_translations_for_domain($domain);
626
+
627
+		$locale = array(
628
+			'' => array(
629
+				'domain' => $domain,
630
+				'lang'   => is_admin() ? EEH_DTT_Helper::get_user_locale() : get_locale()
631
+			),
632
+		);
633
+
634
+		if (! empty($translations->headers['Plural-Forms'])) {
635
+			$locale['']['plural_forms'] = $translations->headers['Plural-Forms'];
636
+		}
637
+
638
+		foreach ($translations->entries as $msgid => $entry) {
639
+			$locale[ $msgid ] = $entry->translations;
640
+		}
641
+
642
+		return $locale;
643
+	}
644 644
 }
Please login to merge, or discard this patch.
Spacing   +27 added lines, -27 removed lines patch added patch discarded remove patch
@@ -103,7 +103,7 @@  discard block
 block discarded – undo
103 103
     {
104 104
         if ($this->admin_config->useAdvancedEditor()) {
105 105
             $eventId = $this->event instanceof EE_Event ? $this->event->ID() : 0;
106
-            if (! $eventId) {
106
+            if ( ! $eventId) {
107 107
                 global $post;
108 108
                 $eventId = isset($_REQUEST['post']) ? absint($_REQUEST['post']) : 0;
109 109
                 $eventId = $eventId === 0 && $post instanceof WP_Post && $post->post_type === 'espresso_events'
@@ -115,7 +115,7 @@  discard block
 block discarded – undo
115 115
                 $data = wp_json_encode($data);
116 116
                 add_action(
117 117
                     'admin_footer',
118
-                    static function () use ($data) {
118
+                    static function() use ($data) {
119 119
                         wp_add_inline_script(
120 120
                             EspressoEditorAssetManager::JS_HANDLE_EDITOR_PROTOTYPE,
121 121
                             "
@@ -148,7 +148,7 @@  discard block
 block discarded – undo
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();
@@ -175,18 +175,18 @@  discard block
 block discarded – undo
175 175
             $datetimes = $this->getGraphQLDatetimes($eventId);
176 176
         }
177 177
 
178
-        if (! empty($datetimes['nodes'])) {
178
+        if ( ! empty($datetimes['nodes'])) {
179 179
             $datetimeIn = wp_list_pluck($datetimes['nodes'], 'id');
180 180
 
181
-            if (! empty($datetimeIn)) {
181
+            if ( ! empty($datetimeIn)) {
182 182
                 $tickets = $this->getGraphQLTickets($datetimeIn);
183 183
             }
184 184
         }
185 185
 
186
-        if (! empty($tickets['nodes'])) {
186
+        if ( ! empty($tickets['nodes'])) {
187 187
             $ticketIn = wp_list_pluck($tickets['nodes'], 'id');
188 188
 
189
-            if (! empty($ticketIn)) {
189
+            if ( ! empty($ticketIn)) {
190 190
                 $prices = $this->getGraphQLPrices($ticketIn);
191 191
             }
192 192
         }
@@ -238,7 +238,7 @@  discard block
 block discarded – undo
238 238
      */
239 239
     protected function getGraphQLDatetimes($eventId)
240 240
     {
241
-        $field_key = lcfirst($this->namespace) . 'Datetimes';
241
+        $field_key = lcfirst($this->namespace).'Datetimes';
242 242
         $query = <<<QUERY
243 243
         query GET_DATETIMES(\$where: {$this->namespace}RootQueryDatetimesConnectionWhereArgs) {
244 244
             {$field_key}(where: \$where) {
@@ -279,7 +279,7 @@  discard block
 block discarded – undo
279 279
         ];
280 280
 
281 281
         $responseData = $this->makeGraphQLRequest($data);
282
-        return !empty($responseData[ $field_key ]) ? $responseData[ $field_key ] : null;
282
+        return ! empty($responseData[$field_key]) ? $responseData[$field_key] : null;
283 283
     }
284 284
 
285 285
 
@@ -290,7 +290,7 @@  discard block
 block discarded – undo
290 290
      */
291 291
     protected function getGraphQLTickets(array $datetimeIn)
292 292
     {
293
-        $field_key = lcfirst($this->namespace) . 'Tickets';
293
+        $field_key = lcfirst($this->namespace).'Tickets';
294 294
         $query = <<<QUERY
295 295
         query GET_TICKETS(\$where: {$this->namespace}RootQueryTicketsConnectionWhereArgs) {
296 296
             {$field_key}(where: \$where) {
@@ -333,7 +333,7 @@  discard block
 block discarded – undo
333 333
         ];
334 334
 
335 335
         $responseData = $this->makeGraphQLRequest($data);
336
-        return !empty($responseData[ $field_key ]) ? $responseData[ $field_key ] : null;
336
+        return ! empty($responseData[$field_key]) ? $responseData[$field_key] : null;
337 337
     }
338 338
 
339 339
 
@@ -344,7 +344,7 @@  discard block
 block discarded – undo
344 344
      */
345 345
     protected function getGraphQLPrices(array $ticketIn)
346 346
     {
347
-        $field_key = lcfirst($this->namespace) . 'Prices';
347
+        $field_key = lcfirst($this->namespace).'Prices';
348 348
         $query = <<<QUERY
349 349
         query GET_PRICES(\$where: {$this->namespace}RootQueryPricesConnectionWhereArgs) {
350 350
             {$field_key}(where: \$where) {
@@ -380,7 +380,7 @@  discard block
 block discarded – undo
380 380
         ];
381 381
 
382 382
         $responseData = $this->makeGraphQLRequest($data);
383
-        return !empty($responseData[ $field_key ]) ? $responseData[ $field_key ] : null;
383
+        return ! empty($responseData[$field_key]) ? $responseData[$field_key] : null;
384 384
     }
385 385
 
386 386
 
@@ -390,7 +390,7 @@  discard block
 block discarded – undo
390 390
      */
391 391
     protected function getGraphQLPriceTypes()
392 392
     {
393
-        $field_key = lcfirst($this->namespace) . 'PriceTypes';
393
+        $field_key = lcfirst($this->namespace).'PriceTypes';
394 394
         $query = <<<QUERY
395 395
         query GET_PRICES {
396 396
             {$field_key} {
@@ -417,7 +417,7 @@  discard block
 block discarded – undo
417 417
         ];
418 418
 
419 419
         $responseData = $this->makeGraphQLRequest($data);
420
-        return !empty($responseData[ $field_key ]) ? $responseData[ $field_key ] : null;
420
+        return ! empty($responseData[$field_key]) ? $responseData[$field_key] : null;
421 421
     }
422 422
 
423 423
 
@@ -452,7 +452,7 @@  discard block
 block discarded – undo
452 452
         ];
453 453
 
454 454
         $responseData = $this->makeGraphQLRequest($data);
455
-        return !empty($responseData[ $field_key ]) ? $responseData[ $field_key ] : null;
455
+        return ! empty($responseData[$field_key]) ? $responseData[$field_key] : null;
456 456
     }
457 457
 
458 458
 
@@ -479,7 +479,7 @@  discard block
 block discarded – undo
479 479
         ];
480 480
 
481 481
         $responseData = $this->makeGraphQLRequest($data);
482
-        return !empty($responseData[ $field_key ]) ? $responseData[ $field_key ] : null;
482
+        return ! empty($responseData[$field_key]) ? $responseData[$field_key] : null;
483 483
     }
484 484
 
485 485
 
@@ -492,7 +492,7 @@  discard block
 block discarded – undo
492 492
     {
493 493
         try {
494 494
             $response = graphql($data);
495
-            if (!empty($response['data'])) {
495
+            if ( ! empty($response['data'])) {
496 496
                 return $response['data'];
497 497
             }
498 498
             return null;
@@ -546,8 +546,8 @@  discard block
 block discarded – undo
546 546
             foreach ($related_models as $key => $model) {
547 547
                 // Get the IDs of related entities for the datetime ID.
548 548
                 $Ids = $model->get_col([['Datetime.DTT_ID' => $datetimeId]]);
549
-                if (! empty($Ids)) {
550
-                    $data['datetimes'][ $GID ][ $key ] = self::convertToGlobalId($model->item_name(), $Ids);
549
+                if ( ! empty($Ids)) {
550
+                    $data['datetimes'][$GID][$key] = self::convertToGlobalId($model->item_name(), $Ids);
551 551
                 }
552 552
             }
553 553
         }
@@ -568,8 +568,8 @@  discard block
 block discarded – undo
568 568
             foreach ($related_models as $key => $model) {
569 569
                 // Get the IDs of related entities for the ticket ID.
570 570
                 $Ids = $model->get_col([['Ticket.TKT_ID' => $ticketId]]);
571
-                if (! empty($Ids)) {
572
-                    $data['tickets'][ $GID ][ $key ] = self::convertToGlobalId($model->item_name(), $Ids);
571
+                if ( ! empty($Ids)) {
572
+                    $data['tickets'][$GID][$key] = self::convertToGlobalId($model->item_name(), $Ids);
573 573
                 }
574 574
             }
575 575
         }
@@ -587,8 +587,8 @@  discard block
 block discarded – undo
587 587
             foreach ($related_models as $key => $model) {
588 588
                 // Get the IDs of related entities for the price ID.
589 589
                 $Ids = $model->get_col([['Price.PRC_ID' => $priceId]]);
590
-                if (! empty($Ids)) {
591
-                    $data['prices'][ $GID ][ $key ] = self::convertToGlobalId($model->item_name(), $Ids);
590
+                if ( ! empty($Ids)) {
591
+                    $data['prices'][$GID][$key] = self::convertToGlobalId($model->item_name(), $Ids);
592 592
                 }
593 593
             }
594 594
         }
@@ -606,7 +606,7 @@  discard block
 block discarded – undo
606 606
     public static function convertToGlobalId($type, $ID)
607 607
     {
608 608
         if (is_array($ID)) {
609
-            return array_map(function ($id) use ($type) {
609
+            return array_map(function($id) use ($type) {
610 610
                 return self::convertToGlobalId($type, $id);
611 611
             }, $ID);
612 612
         }
@@ -631,12 +631,12 @@  discard block
 block discarded – undo
631 631
             ),
632 632
         );
633 633
 
634
-        if (! empty($translations->headers['Plural-Forms'])) {
634
+        if ( ! empty($translations->headers['Plural-Forms'])) {
635 635
             $locale['']['plural_forms'] = $translations->headers['Plural-Forms'];
636 636
         }
637 637
 
638 638
         foreach ($translations->entries as $msgid => $entry) {
639
-            $locale[ $msgid ] = $entry->translations;
639
+            $locale[$msgid] = $entry->translations;
640 640
         }
641 641
 
642 642
         return $locale;
Please login to merge, or discard this patch.