Completed
Branch Gutenberg/master (26334c)
by
unknown
233:19 queued 208:31
created
core/domain/services/assets/CoreAssetManager.php 1 patch
Indentation   +445 added lines, -445 removed lines patch added patch discarded remove patch
@@ -29,466 +29,466 @@
 block discarded – undo
29 29
 class CoreAssetManager extends AssetManager
30 30
 {
31 31
 
32
-    // WordPress core / Third party JS asset handles
33
-    const JS_HANDLE_JQUERY = 'jquery';
32
+	// WordPress core / Third party JS asset handles
33
+	const JS_HANDLE_JQUERY = 'jquery';
34 34
 
35
-    const JS_HANDLE_JQUERY_VALIDATE = 'jquery-validate';
35
+	const JS_HANDLE_JQUERY_VALIDATE = 'jquery-validate';
36 36
 
37
-    const JS_HANDLE_JQUERY_VALIDATE_EXTRA = 'jquery-validate-extra-methods';
37
+	const JS_HANDLE_JQUERY_VALIDATE_EXTRA = 'jquery-validate-extra-methods';
38 38
 
39
-    const JS_HANDLE_UNDERSCORE = 'underscore';
39
+	const JS_HANDLE_UNDERSCORE = 'underscore';
40 40
 
41
-    const JS_HANDLE_ACCOUNTING_CORE = 'ee-accounting-core';
41
+	const JS_HANDLE_ACCOUNTING_CORE = 'ee-accounting-core';
42 42
 
43
-    // EE JS assets handles
44
-    const JS_HANDLE_EE_MANIFEST = 'ee-manifest';
43
+	// EE JS assets handles
44
+	const JS_HANDLE_EE_MANIFEST = 'ee-manifest';
45 45
 
46
-    const JS_HANDLE_EE_JS_CORE = 'eejs-core';
46
+	const JS_HANDLE_EE_JS_CORE = 'eejs-core';
47 47
 
48
-    const JS_HANDLE_EE_VENDOR = 'eventespresso-vendor';
48
+	const JS_HANDLE_EE_VENDOR = 'eventespresso-vendor';
49 49
 
50
-    const JS_HANDLE_EE_DATA_STORES = 'eventespresso-data-stores';
50
+	const JS_HANDLE_EE_DATA_STORES = 'eventespresso-data-stores';
51 51
 
52
-    const JS_HANDLE_EE_HELPERS = 'eventespresso-helpers';
52
+	const JS_HANDLE_EE_HELPERS = 'eventespresso-helpers';
53 53
 
54
-    const JS_HANDLE_EE_MODEL = 'eventespresso-model';
54
+	const JS_HANDLE_EE_MODEL = 'eventespresso-model';
55 55
 
56
-    const JS_HANDLE_EE_VALUE_OBJECTS = 'eventespresso-value-objects';
56
+	const JS_HANDLE_EE_VALUE_OBJECTS = 'eventespresso-value-objects';
57 57
 
58
-    const JS_HANDLE_EE_HOC_COMPONENTS = 'eventespresso-hoc-components';
58
+	const JS_HANDLE_EE_HOC_COMPONENTS = 'eventespresso-hoc-components';
59 59
 
60
-    const JS_HANDLE_EE_COMPONENTS = 'eventespresso-components';
60
+	const JS_HANDLE_EE_COMPONENTS = 'eventespresso-components';
61 61
 
62
-    const JS_HANDLE_EE_JS_API = 'eejs-api';
62
+	const JS_HANDLE_EE_JS_API = 'eejs-api';
63 63
 
64
-    const JS_HANDLE_EE_CORE = 'espresso_core';
64
+	const JS_HANDLE_EE_CORE = 'espresso_core';
65 65
 
66
-    const JS_HANDLE_EE_I18N = 'eei18n';
67
-
68
-    const JS_HANDLE_EE_ACCOUNTING = 'ee-accounting';
69
-
70
-    const JS_HANDLE_EE_WP_PLUGINS_PAGE = 'ee-wp-plugins-page';
71
-
72
-    // EE CSS assets handles
73
-    const CSS_HANDLE_EE_DEFAULT = 'espresso_default';
74
-
75
-    const CSS_HANDLE_EE_CUSTOM = 'espresso_custom_css';
76
-
77
-    const CSS_HANDLE_EE_COMPONENTS = 'eventespresso-components';
78
-
79
-    /**
80
-     * @var EE_Currency_Config $currency_config
81
-     */
82
-    protected $currency_config;
83
-
84
-    /**
85
-     * @var EE_Template_Config $template_config
86
-     */
87
-    protected $template_config;
88
-
89
-
90
-    /**
91
-     * CoreAssetRegister constructor.
92
-     *
93
-     * @param AssetCollection    $assets
94
-     * @param EE_Currency_Config $currency_config
95
-     * @param EE_Template_Config $template_config
96
-     * @param DomainInterface    $domain
97
-     * @param Registry           $registry
98
-     */
99
-    public function __construct(
100
-        AssetCollection $assets,
101
-        EE_Currency_Config $currency_config,
102
-        EE_Template_Config $template_config,
103
-        DomainInterface $domain,
104
-        Registry $registry
105
-    ) {
106
-        $this->currency_config = $currency_config;
107
-        $this->template_config = $template_config;
108
-        parent::__construct($domain, $assets, $registry);
109
-    }
110
-
111
-
112
-    /**
113
-     * @since 4.9.62.p
114
-     * @throws DuplicateCollectionIdentifierException
115
-     * @throws InvalidArgumentException
116
-     * @throws InvalidDataTypeException
117
-     * @throws InvalidEntityException
118
-     */
119
-    public function addAssets()
120
-    {
121
-        $this->addJavascriptFiles();
122
-        $this->addStylesheetFiles();
123
-    }
124
-
125
-
126
-    /**
127
-     * @since 4.9.62.p
128
-     * @throws DuplicateCollectionIdentifierException
129
-     * @throws InvalidArgumentException
130
-     * @throws InvalidDataTypeException
131
-     * @throws InvalidEntityException
132
-     */
133
-    public function addJavascriptFiles()
134
-    {
135
-        $this->loadCoreJs();
136
-        $this->loadJqueryValidate();
137
-        $this->loadAccountingJs();
138
-        add_action(
139
-            'AHEE__EventEspresso_core_services_assets_Registry__registerScripts__before_script',
140
-            array($this, 'loadQtipJs')
141
-        );
142
-        $this->registerAdminAssets();
143
-    }
144
-
145
-
146
-    /**
147
-     * @since 4.9.62.p
148
-     * @throws DuplicateCollectionIdentifierException
149
-     * @throws InvalidDataTypeException
150
-     * @throws InvalidEntityException
151
-     */
152
-    public function addStylesheetFiles()
153
-    {
154
-        $this->loadCoreCss();
155
-    }
156
-
157
-
158
-    /**
159
-     * core default javascript
160
-     *
161
-     * @since 4.9.62.p
162
-     * @throws DuplicateCollectionIdentifierException
163
-     * @throws InvalidArgumentException
164
-     * @throws InvalidDataTypeException
165
-     * @throws InvalidEntityException
166
-     */
167
-    private function loadCoreJs()
168
-    {
169
-        $this->addJavascript(
170
-            CoreAssetManager::JS_HANDLE_EE_MANIFEST,
171
-            $this->registry->getJsUrl($this->domain->assetNamespace(), 'manifest')
172
-        );
173
-
174
-        $this->addJavascript(
175
-            CoreAssetManager::JS_HANDLE_EE_JS_CORE,
176
-            $this->registry->getJsUrl($this->domain->assetNamespace(), 'eejs'),
177
-            array(CoreAssetManager::JS_HANDLE_EE_MANIFEST)
178
-        )
179
-        ->setHasInlineData();
180
-
181
-        $this->addJavascript(
182
-            CoreAssetManager::JS_HANDLE_EE_VENDOR,
183
-            $this->registry->getJsUrl($this->domain->assetNamespace(), 'vendor'),
184
-            array(CoreAssetManager::JS_HANDLE_EE_JS_CORE)
185
-        );
186
-
187
-        $this->addJavascript(
188
-            CoreAssetManager::JS_HANDLE_EE_DATA_STORES,
189
-            $this->registry->getJsUrl($this->domain->assetNamespace(), 'data-stores'),
190
-            array(CoreAssetManager::JS_HANDLE_EE_VENDOR, 'wp-data', 'wp-api-request')
191
-        )
192
-        ->setRequiresTranslation();
193
-
194
-        $this->addJavascript(
195
-            CoreAssetManager::JS_HANDLE_EE_HELPERS,
196
-            $this->registry->getJsUrl($this->domain->assetNamespace(), 'helpers')
197
-        )->setRequiresTranslation();
198
-
199
-        $this->addJavascript(
200
-            CoreAssetManager::JS_HANDLE_EE_MODEL,
201
-            $this->registry->getJsUrl($this->domain->assetNamespace(), 'model'),
202
-            array(
203
-                CoreAssetManager::JS_HANDLE_EE_HELPERS
204
-            )
205
-        )->setRequiresTranslation();
206
-
207
-        $this->addJavascript(
208
-            CoreAssetManager::JS_HANDLE_EE_VALUE_OBJECTS,
209
-            $this->registry->getJsUrl($this->domain->assetNamespace(), 'valueObjects'),
210
-            array(
211
-                CoreAssetManager::JS_HANDLE_EE_MODEL
212
-            )
213
-        )->setRequiresTranslation();
214
-
215
-        $this->addJavascript(
216
-            CoreAssetManager::JS_HANDLE_EE_HOC_COMPONENTS,
217
-            $this->registry->getJsUrl($this->domain->assetNamespace(), 'hocComponents'),
218
-            array(
219
-                CoreAssetManager::JS_HANDLE_EE_DATA_STORES,
220
-                CoreAssetManager::JS_HANDLE_EE_VALUE_OBJECTS,
221
-                'wp-components',
222
-            )
223
-        )->setRequiresTranslation();
224
-
225
-        $this->addJavascript(
226
-            CoreAssetManager::JS_HANDLE_EE_COMPONENTS,
227
-            $this->registry->getJsUrl($this->domain->assetNamespace(), 'components'),
228
-            array(
229
-                CoreAssetManager::JS_HANDLE_EE_DATA_STORES,
230
-                CoreAssetManager::JS_HANDLE_EE_VALUE_OBJECTS,
231
-                'wp-components',
232
-            )
233
-        )
234
-        ->setRequiresTranslation();
235
-
236
-        global $wp_version;
237
-        if (version_compare($wp_version, '4.4.0', '>')) {
238
-            //js.api
239
-            $this->addJavascript(
240
-                CoreAssetManager::JS_HANDLE_EE_JS_API,
241
-                EE_LIBRARIES_URL . 'rest_api/assets/js/eejs-api.min.js',
242
-                array(
243
-                    CoreAssetManager::JS_HANDLE_UNDERSCORE,
244
-                    CoreAssetManager::JS_HANDLE_EE_JS_CORE
245
-                )
246
-            );
247
-            $this->registry->addData('eejs_api_nonce', wp_create_nonce('wp_rest'));
248
-            $this->registry->addData(
249
-                'paths',
250
-                array(
251
-                    'rest_route' => rest_url('ee/v4.8.36/'),
252
-                    'collection_endpoints' => EED_Core_Rest_Api::getCollectionRoutesIndexedByModelName(),
253
-                    'primary_keys' => EED_Core_Rest_Api::getPrimaryKeyNamesIndexedByModelName(),
66
+	const JS_HANDLE_EE_I18N = 'eei18n';
67
+
68
+	const JS_HANDLE_EE_ACCOUNTING = 'ee-accounting';
69
+
70
+	const JS_HANDLE_EE_WP_PLUGINS_PAGE = 'ee-wp-plugins-page';
71
+
72
+	// EE CSS assets handles
73
+	const CSS_HANDLE_EE_DEFAULT = 'espresso_default';
74
+
75
+	const CSS_HANDLE_EE_CUSTOM = 'espresso_custom_css';
76
+
77
+	const CSS_HANDLE_EE_COMPONENTS = 'eventespresso-components';
78
+
79
+	/**
80
+	 * @var EE_Currency_Config $currency_config
81
+	 */
82
+	protected $currency_config;
83
+
84
+	/**
85
+	 * @var EE_Template_Config $template_config
86
+	 */
87
+	protected $template_config;
88
+
89
+
90
+	/**
91
+	 * CoreAssetRegister constructor.
92
+	 *
93
+	 * @param AssetCollection    $assets
94
+	 * @param EE_Currency_Config $currency_config
95
+	 * @param EE_Template_Config $template_config
96
+	 * @param DomainInterface    $domain
97
+	 * @param Registry           $registry
98
+	 */
99
+	public function __construct(
100
+		AssetCollection $assets,
101
+		EE_Currency_Config $currency_config,
102
+		EE_Template_Config $template_config,
103
+		DomainInterface $domain,
104
+		Registry $registry
105
+	) {
106
+		$this->currency_config = $currency_config;
107
+		$this->template_config = $template_config;
108
+		parent::__construct($domain, $assets, $registry);
109
+	}
110
+
111
+
112
+	/**
113
+	 * @since 4.9.62.p
114
+	 * @throws DuplicateCollectionIdentifierException
115
+	 * @throws InvalidArgumentException
116
+	 * @throws InvalidDataTypeException
117
+	 * @throws InvalidEntityException
118
+	 */
119
+	public function addAssets()
120
+	{
121
+		$this->addJavascriptFiles();
122
+		$this->addStylesheetFiles();
123
+	}
124
+
125
+
126
+	/**
127
+	 * @since 4.9.62.p
128
+	 * @throws DuplicateCollectionIdentifierException
129
+	 * @throws InvalidArgumentException
130
+	 * @throws InvalidDataTypeException
131
+	 * @throws InvalidEntityException
132
+	 */
133
+	public function addJavascriptFiles()
134
+	{
135
+		$this->loadCoreJs();
136
+		$this->loadJqueryValidate();
137
+		$this->loadAccountingJs();
138
+		add_action(
139
+			'AHEE__EventEspresso_core_services_assets_Registry__registerScripts__before_script',
140
+			array($this, 'loadQtipJs')
141
+		);
142
+		$this->registerAdminAssets();
143
+	}
144
+
145
+
146
+	/**
147
+	 * @since 4.9.62.p
148
+	 * @throws DuplicateCollectionIdentifierException
149
+	 * @throws InvalidDataTypeException
150
+	 * @throws InvalidEntityException
151
+	 */
152
+	public function addStylesheetFiles()
153
+	{
154
+		$this->loadCoreCss();
155
+	}
156
+
157
+
158
+	/**
159
+	 * core default javascript
160
+	 *
161
+	 * @since 4.9.62.p
162
+	 * @throws DuplicateCollectionIdentifierException
163
+	 * @throws InvalidArgumentException
164
+	 * @throws InvalidDataTypeException
165
+	 * @throws InvalidEntityException
166
+	 */
167
+	private function loadCoreJs()
168
+	{
169
+		$this->addJavascript(
170
+			CoreAssetManager::JS_HANDLE_EE_MANIFEST,
171
+			$this->registry->getJsUrl($this->domain->assetNamespace(), 'manifest')
172
+		);
173
+
174
+		$this->addJavascript(
175
+			CoreAssetManager::JS_HANDLE_EE_JS_CORE,
176
+			$this->registry->getJsUrl($this->domain->assetNamespace(), 'eejs'),
177
+			array(CoreAssetManager::JS_HANDLE_EE_MANIFEST)
178
+		)
179
+		->setHasInlineData();
180
+
181
+		$this->addJavascript(
182
+			CoreAssetManager::JS_HANDLE_EE_VENDOR,
183
+			$this->registry->getJsUrl($this->domain->assetNamespace(), 'vendor'),
184
+			array(CoreAssetManager::JS_HANDLE_EE_JS_CORE)
185
+		);
186
+
187
+		$this->addJavascript(
188
+			CoreAssetManager::JS_HANDLE_EE_DATA_STORES,
189
+			$this->registry->getJsUrl($this->domain->assetNamespace(), 'data-stores'),
190
+			array(CoreAssetManager::JS_HANDLE_EE_VENDOR, 'wp-data', 'wp-api-request')
191
+		)
192
+		->setRequiresTranslation();
193
+
194
+		$this->addJavascript(
195
+			CoreAssetManager::JS_HANDLE_EE_HELPERS,
196
+			$this->registry->getJsUrl($this->domain->assetNamespace(), 'helpers')
197
+		)->setRequiresTranslation();
198
+
199
+		$this->addJavascript(
200
+			CoreAssetManager::JS_HANDLE_EE_MODEL,
201
+			$this->registry->getJsUrl($this->domain->assetNamespace(), 'model'),
202
+			array(
203
+				CoreAssetManager::JS_HANDLE_EE_HELPERS
204
+			)
205
+		)->setRequiresTranslation();
206
+
207
+		$this->addJavascript(
208
+			CoreAssetManager::JS_HANDLE_EE_VALUE_OBJECTS,
209
+			$this->registry->getJsUrl($this->domain->assetNamespace(), 'valueObjects'),
210
+			array(
211
+				CoreAssetManager::JS_HANDLE_EE_MODEL
212
+			)
213
+		)->setRequiresTranslation();
214
+
215
+		$this->addJavascript(
216
+			CoreAssetManager::JS_HANDLE_EE_HOC_COMPONENTS,
217
+			$this->registry->getJsUrl($this->domain->assetNamespace(), 'hocComponents'),
218
+			array(
219
+				CoreAssetManager::JS_HANDLE_EE_DATA_STORES,
220
+				CoreAssetManager::JS_HANDLE_EE_VALUE_OBJECTS,
221
+				'wp-components',
222
+			)
223
+		)->setRequiresTranslation();
224
+
225
+		$this->addJavascript(
226
+			CoreAssetManager::JS_HANDLE_EE_COMPONENTS,
227
+			$this->registry->getJsUrl($this->domain->assetNamespace(), 'components'),
228
+			array(
229
+				CoreAssetManager::JS_HANDLE_EE_DATA_STORES,
230
+				CoreAssetManager::JS_HANDLE_EE_VALUE_OBJECTS,
231
+				'wp-components',
232
+			)
233
+		)
234
+		->setRequiresTranslation();
235
+
236
+		global $wp_version;
237
+		if (version_compare($wp_version, '4.4.0', '>')) {
238
+			//js.api
239
+			$this->addJavascript(
240
+				CoreAssetManager::JS_HANDLE_EE_JS_API,
241
+				EE_LIBRARIES_URL . 'rest_api/assets/js/eejs-api.min.js',
242
+				array(
243
+					CoreAssetManager::JS_HANDLE_UNDERSCORE,
244
+					CoreAssetManager::JS_HANDLE_EE_JS_CORE
245
+				)
246
+			);
247
+			$this->registry->addData('eejs_api_nonce', wp_create_nonce('wp_rest'));
248
+			$this->registry->addData(
249
+				'paths',
250
+				array(
251
+					'rest_route' => rest_url('ee/v4.8.36/'),
252
+					'collection_endpoints' => EED_Core_Rest_Api::getCollectionRoutesIndexedByModelName(),
253
+					'primary_keys' => EED_Core_Rest_Api::getPrimaryKeyNamesIndexedByModelName(),
254 254
 					'site_url' => site_url('/'),
255
-                    'admin_url' => admin_url('/'),
256
-                )
257
-            );
258
-            /** site formatting values **/
259
-            $this->registry->addData(
260
-                'site_formats',
261
-                array(
262
-                    'date_formats' => EEH_DTT_Helper::convert_php_to_js_and_moment_date_formats()
263
-                )
264
-            );
265
-            /** currency data **/
266
-            $this->registry->addData(
267
-                'currency_config',
268
-                $this->getCurrencySettings()
269
-            );
270
-            /** site timezone */
271
-            $this->registry->addData(
272
-                'default_timezone',
273
-                array(
274
-                    'pretty' => EEH_DTT_Helper::get_timezone_string_for_display(),
275
-                    'string' => get_option('timezone_string'),
276
-                    'offset' => EEH_DTT_Helper::get_site_timezone_gmt_offset(),
277
-                )
278
-            );
279
-            /** site locale (user locale if user logged in) */
280
-            $this->registry->addData(
281
-                'locale',
282
-                array(
283
-                    'user' => get_user_locale(),
284
-                    'site' => get_locale()
285
-                )
286
-            );
287
-        }
288
-
289
-        $this->addJavascript(
290
-            CoreAssetManager::JS_HANDLE_EE_CORE,
291
-            EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js',
292
-            array(CoreAssetManager::JS_HANDLE_JQUERY)
293
-        )
294
-        ->setInlineDataCallback(
295
-            function () {
296
-                wp_localize_script(
297
-                    CoreAssetManager::JS_HANDLE_EE_CORE,
298
-                    CoreAssetManager::JS_HANDLE_EE_I18N,
299
-                    EE_Registry::$i18n_js_strings
300
-                );
301
-            }
302
-        );
303
-    }
304
-
305
-
306
-    /**
307
-     * Returns configuration data for the accounting-js library.
308
-     * @since $VID:$
309
-     * @return array
310
-     */
311
-    private function getAccountingSettings() {
312
-        return array(
313
-            'currency' => array(
314
-                'symbol'    => $this->currency_config->sign,
315
-                'format'    => array(
316
-                    'pos'  => $this->currency_config->sign_b4 ? '%s%v' : '%v%s',
317
-                    'neg'  => $this->currency_config->sign_b4 ? '- %s%v' : '- %v%s',
318
-                    'zero' => $this->currency_config->sign_b4 ? '%s--' : '--%s',
319
-                ),
320
-                'decimal'   => $this->currency_config->dec_mrk,
321
-                'thousand'  => $this->currency_config->thsnds,
322
-                'precision' => $this->currency_config->dec_plc,
323
-            ),
324
-            'number'   => array(
325
-                'precision' => $this->currency_config->dec_plc,
326
-                'thousand'  => $this->currency_config->thsnds,
327
-                'decimal'   => $this->currency_config->dec_mrk,
328
-            ),
329
-        );
330
-    }
331
-
332
-
333
-    /**
334
-     * Returns configuration data for the js Currency VO.
335
-     * @sinc $VID:$
336
-     * @return array
337
-     */
338
-    private function getCurrencySettings()
339
-    {
340
-        return array(
341
-            'code' => $this->currency_config->code,
342
-            'singularLabel' => $this->currency_config->name,
343
-            'pluralLabel' => $this->currency_config->plural,
344
-            'sign' => $this->currency_config->sign,
345
-            'signB4' => $this->currency_config->sign_b4,
346
-            'decimalPlaces' => $this->currency_config->dec_plc,
347
-            'decimalMark' => $this->currency_config->dec_mrk,
348
-            'thousandsSeparator' => $this->currency_config->thsnds,
349
-        );
350
-    }
351
-
352
-
353
-    /**
354
-     * @since 4.9.62.p
355
-     * @throws DuplicateCollectionIdentifierException
356
-     * @throws InvalidDataTypeException
357
-     * @throws InvalidEntityException
358
-     */
359
-    private function loadCoreCss()
360
-    {
361
-        if ($this->template_config->enable_default_style && ! is_admin()) {
362
-            $this->addStylesheet(
363
-                CoreAssetManager::CSS_HANDLE_EE_DEFAULT,
364
-                is_readable(EVENT_ESPRESSO_UPLOAD_DIR . 'css/style.css')
365
-                    ? EVENT_ESPRESSO_UPLOAD_DIR . 'css/espresso_default.css'
366
-                    : EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css',
367
-                array('dashicons')
368
-            );
369
-            //Load custom style sheet if available
370
-            if ($this->template_config->custom_style_sheet !== null) {
371
-                $this->addStylesheet(
372
-                    CoreAssetManager::CSS_HANDLE_EE_CUSTOM,
373
-                    EVENT_ESPRESSO_UPLOAD_URL . 'css/' . $this->template_config->custom_style_sheet,
374
-                    array(CoreAssetManager::CSS_HANDLE_EE_DEFAULT)
375
-                );
376
-            }
377
-        }
378
-        $this->addStylesheet(
379
-            CoreAssetManager::CSS_HANDLE_EE_COMPONENTS,
380
-            $this->registry->getCssUrl(
381
-                $this->domain->assetNamespace(),
382
-                'components'
383
-            )
384
-        );
385
-    }
386
-
387
-
388
-    /**
389
-     * jQuery Validate for form validation
390
-     *
391
-     * @since 4.9.62.p
392
-     * @throws DuplicateCollectionIdentifierException
393
-     * @throws InvalidDataTypeException
394
-     * @throws InvalidEntityException
395
-     */
396
-    private function loadJqueryValidate()
397
-    {
398
-        $this->addJavascript(
399
-            CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE,
400
-            EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.min.js',
401
-            array(CoreAssetManager::JS_HANDLE_JQUERY)
402
-        )
403
-        ->setVersion('1.15.0');
404
-
405
-        $this->addJavascript(
406
-            CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE_EXTRA,
407
-            EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.additional-methods.min.js',
408
-            array(CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE)
409
-        )
410
-        ->setVersion('1.15.0');
411
-    }
412
-
413
-
414
-    /**
415
-     * accounting.js for performing client-side calculations
416
-     *
417
-     * @since 4.9.62.p
418
-     * @throws DuplicateCollectionIdentifierException
419
-     * @throws InvalidDataTypeException
420
-     * @throws InvalidEntityException
421
-     */
422
-    private function loadAccountingJs()
423
-    {
424
-        //accounting.js library
425
-        // @link http://josscrowcroft.github.io/accounting.js/
426
-        $this->addJavascript(
427
-            CoreAssetManager::JS_HANDLE_ACCOUNTING_CORE,
428
-            EE_THIRD_PARTY_URL . 'accounting/accounting.js',
429
-            array(CoreAssetManager::JS_HANDLE_UNDERSCORE)
430
-        )
431
-        ->setVersion('0.3.2');
432
-
433
-        $this->addJavascript(
434
-            CoreAssetManager::JS_HANDLE_EE_ACCOUNTING,
435
-            EE_GLOBAL_ASSETS_URL . 'scripts/ee-accounting-config.js',
436
-            array(CoreAssetManager::JS_HANDLE_ACCOUNTING_CORE)
437
-        )
438
-        ->setInlineDataCallback(
439
-            function () {
440
-                 wp_localize_script(
441
-                     CoreAssetManager::JS_HANDLE_EE_ACCOUNTING,
442
-                     'EE_ACCOUNTING_CFG',
443
-                     $this->getAccountingSettings()
444
-                 );
445
-            }
446
-        )
447
-        ->setVersion();
448
-    }
449
-
450
-
451
-    /**
452
-     * registers assets for cleaning your ears
453
-     *
454
-     * @param JavascriptAsset $script
455
-     */
456
-    public function loadQtipJs(JavascriptAsset $script)
457
-    {
458
-        // qtip is turned OFF by default, but prior to the wp_enqueue_scripts hook,
459
-        // can be turned back on again via: add_filter('FHEE_load_qtip', '__return_true' );
460
-        if (
461
-            $script->handle() === CoreAssetManager::JS_HANDLE_EE_WP_PLUGINS_PAGE
462
-            && apply_filters('FHEE_load_qtip', false)
463
-        ) {
464
-            EEH_Qtip_Loader::instance()->register_and_enqueue();
465
-        }
466
-    }
467
-
468
-
469
-    /**
470
-     * assets that are used in the WordPress admin
471
-     *
472
-     * @since 4.9.62.p
473
-     * @throws DuplicateCollectionIdentifierException
474
-     * @throws InvalidDataTypeException
475
-     * @throws InvalidEntityException
476
-     */
477
-    private function registerAdminAssets()
478
-    {
479
-        $this->addJavascript(
480
-            CoreAssetManager::JS_HANDLE_EE_WP_PLUGINS_PAGE,
481
-            $this->registry->getJsUrl($this->domain->assetNamespace(), 'wp-plugins-page'),
482
-            array(
483
-                CoreAssetManager::JS_HANDLE_JQUERY,
484
-                CoreAssetManager::JS_HANDLE_EE_VENDOR,
485
-            )
486
-        )
487
-        ->setRequiresTranslation();
488
-
489
-        $this->addStylesheet(
490
-            CoreAssetManager::JS_HANDLE_EE_WP_PLUGINS_PAGE,
491
-            $this->registry->getCssUrl($this->domain->assetNamespace(), 'wp-plugins-page')
492
-        );
493
-    }
255
+					'admin_url' => admin_url('/'),
256
+				)
257
+			);
258
+			/** site formatting values **/
259
+			$this->registry->addData(
260
+				'site_formats',
261
+				array(
262
+					'date_formats' => EEH_DTT_Helper::convert_php_to_js_and_moment_date_formats()
263
+				)
264
+			);
265
+			/** currency data **/
266
+			$this->registry->addData(
267
+				'currency_config',
268
+				$this->getCurrencySettings()
269
+			);
270
+			/** site timezone */
271
+			$this->registry->addData(
272
+				'default_timezone',
273
+				array(
274
+					'pretty' => EEH_DTT_Helper::get_timezone_string_for_display(),
275
+					'string' => get_option('timezone_string'),
276
+					'offset' => EEH_DTT_Helper::get_site_timezone_gmt_offset(),
277
+				)
278
+			);
279
+			/** site locale (user locale if user logged in) */
280
+			$this->registry->addData(
281
+				'locale',
282
+				array(
283
+					'user' => get_user_locale(),
284
+					'site' => get_locale()
285
+				)
286
+			);
287
+		}
288
+
289
+		$this->addJavascript(
290
+			CoreAssetManager::JS_HANDLE_EE_CORE,
291
+			EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js',
292
+			array(CoreAssetManager::JS_HANDLE_JQUERY)
293
+		)
294
+		->setInlineDataCallback(
295
+			function () {
296
+				wp_localize_script(
297
+					CoreAssetManager::JS_HANDLE_EE_CORE,
298
+					CoreAssetManager::JS_HANDLE_EE_I18N,
299
+					EE_Registry::$i18n_js_strings
300
+				);
301
+			}
302
+		);
303
+	}
304
+
305
+
306
+	/**
307
+	 * Returns configuration data for the accounting-js library.
308
+	 * @since $VID:$
309
+	 * @return array
310
+	 */
311
+	private function getAccountingSettings() {
312
+		return array(
313
+			'currency' => array(
314
+				'symbol'    => $this->currency_config->sign,
315
+				'format'    => array(
316
+					'pos'  => $this->currency_config->sign_b4 ? '%s%v' : '%v%s',
317
+					'neg'  => $this->currency_config->sign_b4 ? '- %s%v' : '- %v%s',
318
+					'zero' => $this->currency_config->sign_b4 ? '%s--' : '--%s',
319
+				),
320
+				'decimal'   => $this->currency_config->dec_mrk,
321
+				'thousand'  => $this->currency_config->thsnds,
322
+				'precision' => $this->currency_config->dec_plc,
323
+			),
324
+			'number'   => array(
325
+				'precision' => $this->currency_config->dec_plc,
326
+				'thousand'  => $this->currency_config->thsnds,
327
+				'decimal'   => $this->currency_config->dec_mrk,
328
+			),
329
+		);
330
+	}
331
+
332
+
333
+	/**
334
+	 * Returns configuration data for the js Currency VO.
335
+	 * @sinc $VID:$
336
+	 * @return array
337
+	 */
338
+	private function getCurrencySettings()
339
+	{
340
+		return array(
341
+			'code' => $this->currency_config->code,
342
+			'singularLabel' => $this->currency_config->name,
343
+			'pluralLabel' => $this->currency_config->plural,
344
+			'sign' => $this->currency_config->sign,
345
+			'signB4' => $this->currency_config->sign_b4,
346
+			'decimalPlaces' => $this->currency_config->dec_plc,
347
+			'decimalMark' => $this->currency_config->dec_mrk,
348
+			'thousandsSeparator' => $this->currency_config->thsnds,
349
+		);
350
+	}
351
+
352
+
353
+	/**
354
+	 * @since 4.9.62.p
355
+	 * @throws DuplicateCollectionIdentifierException
356
+	 * @throws InvalidDataTypeException
357
+	 * @throws InvalidEntityException
358
+	 */
359
+	private function loadCoreCss()
360
+	{
361
+		if ($this->template_config->enable_default_style && ! is_admin()) {
362
+			$this->addStylesheet(
363
+				CoreAssetManager::CSS_HANDLE_EE_DEFAULT,
364
+				is_readable(EVENT_ESPRESSO_UPLOAD_DIR . 'css/style.css')
365
+					? EVENT_ESPRESSO_UPLOAD_DIR . 'css/espresso_default.css'
366
+					: EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css',
367
+				array('dashicons')
368
+			);
369
+			//Load custom style sheet if available
370
+			if ($this->template_config->custom_style_sheet !== null) {
371
+				$this->addStylesheet(
372
+					CoreAssetManager::CSS_HANDLE_EE_CUSTOM,
373
+					EVENT_ESPRESSO_UPLOAD_URL . 'css/' . $this->template_config->custom_style_sheet,
374
+					array(CoreAssetManager::CSS_HANDLE_EE_DEFAULT)
375
+				);
376
+			}
377
+		}
378
+		$this->addStylesheet(
379
+			CoreAssetManager::CSS_HANDLE_EE_COMPONENTS,
380
+			$this->registry->getCssUrl(
381
+				$this->domain->assetNamespace(),
382
+				'components'
383
+			)
384
+		);
385
+	}
386
+
387
+
388
+	/**
389
+	 * jQuery Validate for form validation
390
+	 *
391
+	 * @since 4.9.62.p
392
+	 * @throws DuplicateCollectionIdentifierException
393
+	 * @throws InvalidDataTypeException
394
+	 * @throws InvalidEntityException
395
+	 */
396
+	private function loadJqueryValidate()
397
+	{
398
+		$this->addJavascript(
399
+			CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE,
400
+			EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.min.js',
401
+			array(CoreAssetManager::JS_HANDLE_JQUERY)
402
+		)
403
+		->setVersion('1.15.0');
404
+
405
+		$this->addJavascript(
406
+			CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE_EXTRA,
407
+			EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.additional-methods.min.js',
408
+			array(CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE)
409
+		)
410
+		->setVersion('1.15.0');
411
+	}
412
+
413
+
414
+	/**
415
+	 * accounting.js for performing client-side calculations
416
+	 *
417
+	 * @since 4.9.62.p
418
+	 * @throws DuplicateCollectionIdentifierException
419
+	 * @throws InvalidDataTypeException
420
+	 * @throws InvalidEntityException
421
+	 */
422
+	private function loadAccountingJs()
423
+	{
424
+		//accounting.js library
425
+		// @link http://josscrowcroft.github.io/accounting.js/
426
+		$this->addJavascript(
427
+			CoreAssetManager::JS_HANDLE_ACCOUNTING_CORE,
428
+			EE_THIRD_PARTY_URL . 'accounting/accounting.js',
429
+			array(CoreAssetManager::JS_HANDLE_UNDERSCORE)
430
+		)
431
+		->setVersion('0.3.2');
432
+
433
+		$this->addJavascript(
434
+			CoreAssetManager::JS_HANDLE_EE_ACCOUNTING,
435
+			EE_GLOBAL_ASSETS_URL . 'scripts/ee-accounting-config.js',
436
+			array(CoreAssetManager::JS_HANDLE_ACCOUNTING_CORE)
437
+		)
438
+		->setInlineDataCallback(
439
+			function () {
440
+				 wp_localize_script(
441
+					 CoreAssetManager::JS_HANDLE_EE_ACCOUNTING,
442
+					 'EE_ACCOUNTING_CFG',
443
+					 $this->getAccountingSettings()
444
+				 );
445
+			}
446
+		)
447
+		->setVersion();
448
+	}
449
+
450
+
451
+	/**
452
+	 * registers assets for cleaning your ears
453
+	 *
454
+	 * @param JavascriptAsset $script
455
+	 */
456
+	public function loadQtipJs(JavascriptAsset $script)
457
+	{
458
+		// qtip is turned OFF by default, but prior to the wp_enqueue_scripts hook,
459
+		// can be turned back on again via: add_filter('FHEE_load_qtip', '__return_true' );
460
+		if (
461
+			$script->handle() === CoreAssetManager::JS_HANDLE_EE_WP_PLUGINS_PAGE
462
+			&& apply_filters('FHEE_load_qtip', false)
463
+		) {
464
+			EEH_Qtip_Loader::instance()->register_and_enqueue();
465
+		}
466
+	}
467
+
468
+
469
+	/**
470
+	 * assets that are used in the WordPress admin
471
+	 *
472
+	 * @since 4.9.62.p
473
+	 * @throws DuplicateCollectionIdentifierException
474
+	 * @throws InvalidDataTypeException
475
+	 * @throws InvalidEntityException
476
+	 */
477
+	private function registerAdminAssets()
478
+	{
479
+		$this->addJavascript(
480
+			CoreAssetManager::JS_HANDLE_EE_WP_PLUGINS_PAGE,
481
+			$this->registry->getJsUrl($this->domain->assetNamespace(), 'wp-plugins-page'),
482
+			array(
483
+				CoreAssetManager::JS_HANDLE_JQUERY,
484
+				CoreAssetManager::JS_HANDLE_EE_VENDOR,
485
+			)
486
+		)
487
+		->setRequiresTranslation();
488
+
489
+		$this->addStylesheet(
490
+			CoreAssetManager::JS_HANDLE_EE_WP_PLUGINS_PAGE,
491
+			$this->registry->getCssUrl($this->domain->assetNamespace(), 'wp-plugins-page')
492
+		);
493
+	}
494 494
 }
Please login to merge, or discard this patch.
core/entities/models/JsonModelSchema.php 2 patches
Indentation   +226 added lines, -226 removed lines patch added patch discarded remove patch
@@ -25,230 +25,230 @@
 block discarded – undo
25 25
 class JsonModelSchema
26 26
 {
27 27
 
28
-    /**
29
-     * @var EEM_Base
30
-     */
31
-    protected $model;
32
-
33
-    /**
34
-     * @var CalculatedModelFields
35
-     */
36
-    protected $fields_calculator;
37
-
38
-
39
-    /**
40
-     * JsonModelSchema constructor.
41
-     *
42
-     * @param EEM_Base              $model
43
-     * @param CalculatedModelFields $fields_calculator
44
-     */
45
-    public function __construct(EEM_Base $model, CalculatedModelFields $fields_calculator)
46
-    {
47
-        $this->model = $model;
48
-        $this->fields_calculator = $fields_calculator;
49
-    }
50
-
51
-
52
-    /**
53
-     * Return the schema for a given model from a given model.
54
-     *
55
-     * @return array
56
-     */
57
-    public function getModelSchema()
58
-    {
59
-        return $this->getModelSchemaForRelations(
60
-            $this->model->relation_settings(),
61
-            $this->getModelSchemaForFields(
62
-                $this->model->field_settings(),
63
-                $this->getInitialSchemaStructure()
64
-            )
65
-        );
66
-    }
67
-
68
-
69
-    /**
70
-     * Get the schema for a given set of model fields.
71
-     *
72
-     * @param EE_Model_Field_Base[] $model_fields
73
-     * @param array                  $schema
74
-     * @return array
75
-     */
76
-    public function getModelSchemaForFields(array $model_fields, array $schema)
77
-    {
78
-        foreach ($model_fields as $field => $model_field) {
79
-            if (! $model_field instanceof EE_Model_Field_Base) {
80
-                continue;
81
-            }
82
-            $schema['properties'][ $field ] = $model_field->getSchema();
83
-
84
-            // if this is a primary key field add the primary key item
85
-            if ($model_field instanceof EE_Primary_Key_Field_Base) {
86
-                $schema['properties'][ $field ]['primary_key'] = true;
87
-                if ($model_field instanceof EE_Primary_Key_Int_Field) {
88
-                    $schema['properties'][ $field ]['readonly'] = true;
89
-                }
90
-            }
91
-
92
-            // if this is a foreign key field add the foreign key item
93
-            if ($model_field instanceof EE_Foreign_Key_Field_Base) {
94
-                $schema['properties'][ $field ]['foreign_key'] = array(
95
-                    'description' => esc_html__(
96
-                        'This is a foreign key the points to the given models.',
97
-                        'event_espresso'
98
-                    ),
99
-                    'type'        => 'array',
100
-                    'enum'        => $model_field->get_model_class_names_pointed_to(),
101
-                );
102
-            }
103
-        }
104
-        return $schema;
105
-    }
106
-
107
-
108
-    /**
109
-     * Get the schema for a given set of model relations
110
-     *
111
-     * @param EE_Model_Relation_Base[] $relations_on_model
112
-     * @param array                    $schema
113
-     * @return array
114
-     */
115
-    public function getModelSchemaForRelations(array $relations_on_model, array $schema)
116
-    {
117
-        foreach ($relations_on_model as $model_name => $relation) {
118
-            if (! $relation instanceof EE_Model_Relation_Base) {
119
-                continue;
120
-            }
121
-            $model_name_for_schema = $relation instanceof EE_Belongs_To_Relation
122
-                ? strtolower($model_name)
123
-                : EEH_Inflector::pluralize_and_lower($model_name);
124
-            $schema['properties'][ $model_name_for_schema ] = $relation->getSchema();
125
-            $schema['properties'][ $model_name_for_schema ]['relation_model'] = $model_name;
126
-
127
-            // links schema
128
-            $links_key = 'https://api.eventespresso.com/' . strtolower($model_name);
129
-            $schema['properties']['_links']['properties'][ $links_key ] = array(
130
-                'description' => esc_html__(
131
-                    'Array of objects describing the link(s) for this relation resource.',
132
-                    'event_espresso'
133
-                ),
134
-                'type' => 'array',
135
-                'readonly' => true,
136
-                'items' => array(
137
-                    'type' => 'object',
138
-                    'properties' => array(
139
-                        'href' => array(
140
-                            'type' => 'string',
141
-                            'description' => sprintf(
142
-                                // translators: placeholder is the model name for the relation.
143
-                                esc_html__(
144
-                                    'The link to the resource for the %s relation(s) to this entity',
145
-                                    'event_espresso'
146
-                                ),
147
-                                $model_name
148
-                            ),
149
-                        ),
150
-                        'single' => array(
151
-                            'type' => 'boolean',
152
-                            'description' => sprintf(
153
-                                // translators: placeholder is the model name for the relation.
154
-                                esc_html__(
155
-                                    'Whether or not there is only a single %s relation to this entity',
156
-                                    'event_espresso'
157
-                                ),
158
-                                $model_name
159
-                            ),
160
-                        ),
161
-                    ),
162
-                    'additionalProperties' => false
163
-                ),
164
-            );
165
-        }
166
-        return $schema;
167
-    }
168
-
169
-
170
-    /**
171
-     * Outputs the schema header for a model.
172
-     *
173
-     * @return array
174
-     */
175
-    public function getInitialSchemaStructure()
176
-    {
177
-        return array(
178
-            '$schema'    => 'http://json-schema.org/draft-04/schema#',
179
-            'title'      => $this->model->get_this_model_name(),
180
-            'type'       => 'object',
181
-            'properties' => array(
182
-                'link' => array(
183
-                    'description' => esc_html__(
184
-                        'Link to event on WordPress site hosting events.',
185
-                        'event_espresso'
186
-                    ),
187
-                    'type' => 'string',
188
-                    'readonly' => true,
189
-                ),
190
-                '_links' => array(
191
-                    'description' => esc_html__(
192
-                        'Various links for resources related to the entity.',
193
-                        'event_espresso'
194
-                    ),
195
-                    'type' => 'object',
196
-                    'readonly' => true,
197
-                    'properties' => array(
198
-                        'self' => array(
199
-                            'description' => esc_html__(
200
-                                'Link to this entities resource.',
201
-                                'event_espresso'
202
-                            ),
203
-                            'type' => 'array',
204
-                            'items' => array(
205
-                                'type' => 'object',
206
-                                'properties' => array(
207
-                                    'href' => array(
208
-                                        'type' => 'string',
209
-                                    ),
210
-                                ),
211
-                                'additionalProperties' => false
212
-                            ),
213
-                            'readonly' => true
214
-                        ),
215
-                        'collection' => array(
216
-                            'description' => esc_html__(
217
-                                'Link to this entities collection resource.',
218
-                                'event_espresso'
219
-                            ),
220
-                            'type' => 'array',
221
-                            'items' => array(
222
-                                'type' => 'object',
223
-                                'properties' => array(
224
-                                    'href' => array(
225
-                                        'type' => 'string'
226
-                                    ),
227
-                                ),
228
-                                'additionalProperties' => false
229
-                            ),
230
-                            'readonly' => true
231
-                        ),
232
-                    ),
233
-                    'additionalProperties' => false,
234
-                ),
235
-                '_calculated_fields' => $this->fields_calculator->getJsonSchemaForModel($this->model)
236
-            ),
237
-            'additionalProperties' => false,
238
-        );
239
-    }
240
-
241
-
242
-    /**
243
-     * Allows one to just use the object as a string to get the json.
244
-     * eg.
245
-     * $json_schema = new JsonModelSchema(EEM_Event::instance(), new CalculatedModelFields);
246
-     * echo $json_schema; //outputs the schema as a json formatted string.
247
-     *
248
-     * @return bool|false|mixed|string
249
-     */
250
-    public function __toString()
251
-    {
252
-        return wp_json_encode($this->getModelSchema());
253
-    }
28
+	/**
29
+	 * @var EEM_Base
30
+	 */
31
+	protected $model;
32
+
33
+	/**
34
+	 * @var CalculatedModelFields
35
+	 */
36
+	protected $fields_calculator;
37
+
38
+
39
+	/**
40
+	 * JsonModelSchema constructor.
41
+	 *
42
+	 * @param EEM_Base              $model
43
+	 * @param CalculatedModelFields $fields_calculator
44
+	 */
45
+	public function __construct(EEM_Base $model, CalculatedModelFields $fields_calculator)
46
+	{
47
+		$this->model = $model;
48
+		$this->fields_calculator = $fields_calculator;
49
+	}
50
+
51
+
52
+	/**
53
+	 * Return the schema for a given model from a given model.
54
+	 *
55
+	 * @return array
56
+	 */
57
+	public function getModelSchema()
58
+	{
59
+		return $this->getModelSchemaForRelations(
60
+			$this->model->relation_settings(),
61
+			$this->getModelSchemaForFields(
62
+				$this->model->field_settings(),
63
+				$this->getInitialSchemaStructure()
64
+			)
65
+		);
66
+	}
67
+
68
+
69
+	/**
70
+	 * Get the schema for a given set of model fields.
71
+	 *
72
+	 * @param EE_Model_Field_Base[] $model_fields
73
+	 * @param array                  $schema
74
+	 * @return array
75
+	 */
76
+	public function getModelSchemaForFields(array $model_fields, array $schema)
77
+	{
78
+		foreach ($model_fields as $field => $model_field) {
79
+			if (! $model_field instanceof EE_Model_Field_Base) {
80
+				continue;
81
+			}
82
+			$schema['properties'][ $field ] = $model_field->getSchema();
83
+
84
+			// if this is a primary key field add the primary key item
85
+			if ($model_field instanceof EE_Primary_Key_Field_Base) {
86
+				$schema['properties'][ $field ]['primary_key'] = true;
87
+				if ($model_field instanceof EE_Primary_Key_Int_Field) {
88
+					$schema['properties'][ $field ]['readonly'] = true;
89
+				}
90
+			}
91
+
92
+			// if this is a foreign key field add the foreign key item
93
+			if ($model_field instanceof EE_Foreign_Key_Field_Base) {
94
+				$schema['properties'][ $field ]['foreign_key'] = array(
95
+					'description' => esc_html__(
96
+						'This is a foreign key the points to the given models.',
97
+						'event_espresso'
98
+					),
99
+					'type'        => 'array',
100
+					'enum'        => $model_field->get_model_class_names_pointed_to(),
101
+				);
102
+			}
103
+		}
104
+		return $schema;
105
+	}
106
+
107
+
108
+	/**
109
+	 * Get the schema for a given set of model relations
110
+	 *
111
+	 * @param EE_Model_Relation_Base[] $relations_on_model
112
+	 * @param array                    $schema
113
+	 * @return array
114
+	 */
115
+	public function getModelSchemaForRelations(array $relations_on_model, array $schema)
116
+	{
117
+		foreach ($relations_on_model as $model_name => $relation) {
118
+			if (! $relation instanceof EE_Model_Relation_Base) {
119
+				continue;
120
+			}
121
+			$model_name_for_schema = $relation instanceof EE_Belongs_To_Relation
122
+				? strtolower($model_name)
123
+				: EEH_Inflector::pluralize_and_lower($model_name);
124
+			$schema['properties'][ $model_name_for_schema ] = $relation->getSchema();
125
+			$schema['properties'][ $model_name_for_schema ]['relation_model'] = $model_name;
126
+
127
+			// links schema
128
+			$links_key = 'https://api.eventespresso.com/' . strtolower($model_name);
129
+			$schema['properties']['_links']['properties'][ $links_key ] = array(
130
+				'description' => esc_html__(
131
+					'Array of objects describing the link(s) for this relation resource.',
132
+					'event_espresso'
133
+				),
134
+				'type' => 'array',
135
+				'readonly' => true,
136
+				'items' => array(
137
+					'type' => 'object',
138
+					'properties' => array(
139
+						'href' => array(
140
+							'type' => 'string',
141
+							'description' => sprintf(
142
+								// translators: placeholder is the model name for the relation.
143
+								esc_html__(
144
+									'The link to the resource for the %s relation(s) to this entity',
145
+									'event_espresso'
146
+								),
147
+								$model_name
148
+							),
149
+						),
150
+						'single' => array(
151
+							'type' => 'boolean',
152
+							'description' => sprintf(
153
+								// translators: placeholder is the model name for the relation.
154
+								esc_html__(
155
+									'Whether or not there is only a single %s relation to this entity',
156
+									'event_espresso'
157
+								),
158
+								$model_name
159
+							),
160
+						),
161
+					),
162
+					'additionalProperties' => false
163
+				),
164
+			);
165
+		}
166
+		return $schema;
167
+	}
168
+
169
+
170
+	/**
171
+	 * Outputs the schema header for a model.
172
+	 *
173
+	 * @return array
174
+	 */
175
+	public function getInitialSchemaStructure()
176
+	{
177
+		return array(
178
+			'$schema'    => 'http://json-schema.org/draft-04/schema#',
179
+			'title'      => $this->model->get_this_model_name(),
180
+			'type'       => 'object',
181
+			'properties' => array(
182
+				'link' => array(
183
+					'description' => esc_html__(
184
+						'Link to event on WordPress site hosting events.',
185
+						'event_espresso'
186
+					),
187
+					'type' => 'string',
188
+					'readonly' => true,
189
+				),
190
+				'_links' => array(
191
+					'description' => esc_html__(
192
+						'Various links for resources related to the entity.',
193
+						'event_espresso'
194
+					),
195
+					'type' => 'object',
196
+					'readonly' => true,
197
+					'properties' => array(
198
+						'self' => array(
199
+							'description' => esc_html__(
200
+								'Link to this entities resource.',
201
+								'event_espresso'
202
+							),
203
+							'type' => 'array',
204
+							'items' => array(
205
+								'type' => 'object',
206
+								'properties' => array(
207
+									'href' => array(
208
+										'type' => 'string',
209
+									),
210
+								),
211
+								'additionalProperties' => false
212
+							),
213
+							'readonly' => true
214
+						),
215
+						'collection' => array(
216
+							'description' => esc_html__(
217
+								'Link to this entities collection resource.',
218
+								'event_espresso'
219
+							),
220
+							'type' => 'array',
221
+							'items' => array(
222
+								'type' => 'object',
223
+								'properties' => array(
224
+									'href' => array(
225
+										'type' => 'string'
226
+									),
227
+								),
228
+								'additionalProperties' => false
229
+							),
230
+							'readonly' => true
231
+						),
232
+					),
233
+					'additionalProperties' => false,
234
+				),
235
+				'_calculated_fields' => $this->fields_calculator->getJsonSchemaForModel($this->model)
236
+			),
237
+			'additionalProperties' => false,
238
+		);
239
+	}
240
+
241
+
242
+	/**
243
+	 * Allows one to just use the object as a string to get the json.
244
+	 * eg.
245
+	 * $json_schema = new JsonModelSchema(EEM_Event::instance(), new CalculatedModelFields);
246
+	 * echo $json_schema; //outputs the schema as a json formatted string.
247
+	 *
248
+	 * @return bool|false|mixed|string
249
+	 */
250
+	public function __toString()
251
+	{
252
+		return wp_json_encode($this->getModelSchema());
253
+	}
254 254
 }
Please login to merge, or discard this patch.
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -76,22 +76,22 @@  discard block
 block discarded – undo
76 76
     public function getModelSchemaForFields(array $model_fields, array $schema)
77 77
     {
78 78
         foreach ($model_fields as $field => $model_field) {
79
-            if (! $model_field instanceof EE_Model_Field_Base) {
79
+            if ( ! $model_field instanceof EE_Model_Field_Base) {
80 80
                 continue;
81 81
             }
82
-            $schema['properties'][ $field ] = $model_field->getSchema();
82
+            $schema['properties'][$field] = $model_field->getSchema();
83 83
 
84 84
             // if this is a primary key field add the primary key item
85 85
             if ($model_field instanceof EE_Primary_Key_Field_Base) {
86
-                $schema['properties'][ $field ]['primary_key'] = true;
86
+                $schema['properties'][$field]['primary_key'] = true;
87 87
                 if ($model_field instanceof EE_Primary_Key_Int_Field) {
88
-                    $schema['properties'][ $field ]['readonly'] = true;
88
+                    $schema['properties'][$field]['readonly'] = true;
89 89
                 }
90 90
             }
91 91
 
92 92
             // if this is a foreign key field add the foreign key item
93 93
             if ($model_field instanceof EE_Foreign_Key_Field_Base) {
94
-                $schema['properties'][ $field ]['foreign_key'] = array(
94
+                $schema['properties'][$field]['foreign_key'] = array(
95 95
                     'description' => esc_html__(
96 96
                         'This is a foreign key the points to the given models.',
97 97
                         'event_espresso'
@@ -115,18 +115,18 @@  discard block
 block discarded – undo
115 115
     public function getModelSchemaForRelations(array $relations_on_model, array $schema)
116 116
     {
117 117
         foreach ($relations_on_model as $model_name => $relation) {
118
-            if (! $relation instanceof EE_Model_Relation_Base) {
118
+            if ( ! $relation instanceof EE_Model_Relation_Base) {
119 119
                 continue;
120 120
             }
121 121
             $model_name_for_schema = $relation instanceof EE_Belongs_To_Relation
122 122
                 ? strtolower($model_name)
123 123
                 : EEH_Inflector::pluralize_and_lower($model_name);
124
-            $schema['properties'][ $model_name_for_schema ] = $relation->getSchema();
125
-            $schema['properties'][ $model_name_for_schema ]['relation_model'] = $model_name;
124
+            $schema['properties'][$model_name_for_schema] = $relation->getSchema();
125
+            $schema['properties'][$model_name_for_schema]['relation_model'] = $model_name;
126 126
 
127 127
             // links schema
128
-            $links_key = 'https://api.eventespresso.com/' . strtolower($model_name);
129
-            $schema['properties']['_links']['properties'][ $links_key ] = array(
128
+            $links_key = 'https://api.eventespresso.com/'.strtolower($model_name);
129
+            $schema['properties']['_links']['properties'][$links_key] = array(
130 130
                 'description' => esc_html__(
131 131
                     'Array of objects describing the link(s) for this relation resource.',
132 132
                     'event_espresso'
Please login to merge, or discard this patch.
core/libraries/rest_api/calculations/Registration.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -43,7 +43,7 @@  discard block
 block discarded – undo
43 43
         } else {
44 44
             $reg = null;
45 45
         }
46
-        if (! $reg instanceof EE_Registration
46
+        if ( ! $reg instanceof EE_Registration
47 47
         ) {
48 48
             throw new EE_Error(
49 49
                 sprintf(
@@ -81,7 +81,7 @@  discard block
 block discarded – undo
81 81
                     $status_pretty = 'NEVER';
82 82
                     break;
83 83
             }
84
-            $checkin_stati[ $datetime_id ] = $status_pretty;
84
+            $checkin_stati[$datetime_id] = $status_pretty;
85 85
         }
86 86
         return $checkin_stati;
87 87
     }
Please login to merge, or discard this patch.
Indentation   +100 added lines, -100 removed lines patch added patch discarded remove patch
@@ -24,108 +24,108 @@
 block discarded – undo
24 24
  */
25 25
 class Registration extends RegistrationCalculationBase
26 26
 {
27
-    /**
28
-     * @var EEM_Registration
29
-     */
30
-    protected $registration_model;
27
+	/**
28
+	 * @var EEM_Registration
29
+	 */
30
+	protected $registration_model;
31 31
 
32
-    /**
33
-     * Registration constructor.
34
-     * @param EEM_Registration $registration_model
35
-     */
36
-    public function __construct(EEM_Registration $registration_model)
37
-    {
38
-        $this->registration_model = $registration_model;
39
-    }
32
+	/**
33
+	 * Registration constructor.
34
+	 * @param EEM_Registration $registration_model
35
+	 */
36
+	public function __construct(EEM_Registration $registration_model)
37
+	{
38
+		$this->registration_model = $registration_model;
39
+	}
40 40
 
41
-    /**
42
-     * Calculates the checkin status for each datetime this registration has access to
43
-     *
44
-     * @param array            $wpdb_row
45
-     * @param WP_REST_Request $request
46
-     * @param RegistrationControllerBase $controller
47
-     * @return array
48
-     * @throws EE_Error
49
-     * @throws InvalidDataTypeException
50
-     * @throws InvalidInterfaceException
51
-     * @throws InvalidArgumentException
52
-     */
53
-    public function datetimeCheckinStati($wpdb_row, $request, $controller)
54
-    {
55
-        if (is_array($wpdb_row) && isset($wpdb_row['Registration.REG_ID'])) {
56
-            $reg = $this->registration_model->get_one_by_ID($wpdb_row['Registration.REG_ID']);
57
-        } else {
58
-            $reg = null;
59
-        }
60
-        if (! $reg instanceof EE_Registration
61
-        ) {
62
-            throw new EE_Error(
63
-                sprintf(
64
-                    __(
65
-                    // @codingStandardsIgnoreStart
66
-                        'Cannot calculate datetime_checkin_stati because the registration with ID %1$s (from database row %2$s) was not found',
67
-                        // @codingStandardsIgnoreEnd
68
-                        'event_espresso'
69
-                    ),
70
-                    $wpdb_row['Registration.REG_ID'],
71
-                    print_r($wpdb_row, true)
72
-                )
73
-            );
74
-        }
75
-        $datetime_ids = EEM_Datetime::instance()->get_col(
76
-            [
77
-                [
78
-                    'Ticket.TKT_ID' => $reg->ticket_ID(),
79
-                ],
80
-                'default_where_conditions' => EEM_Base::default_where_conditions_minimum_all,
81
-            ]
82
-        );
83
-        $checkin_stati = array();
84
-        foreach ($datetime_ids as $datetime_id) {
85
-            $status = $reg->check_in_status_for_datetime($datetime_id);
86
-            switch ($status) {
87
-                case EE_Checkin::status_checked_out:
88
-                    $status_pretty = 'OUT';
89
-                    break;
90
-                case EE_Checkin::status_checked_in:
91
-                    $status_pretty = 'IN';
92
-                    break;
93
-                case EE_Checkin::status_checked_never:
94
-                default:
95
-                    $status_pretty = 'NEVER';
96
-                    break;
97
-            }
98
-            $checkin_stati[ $datetime_id ] = $status_pretty;
99
-        }
100
-        return $checkin_stati;
101
-    }
41
+	/**
42
+	 * Calculates the checkin status for each datetime this registration has access to
43
+	 *
44
+	 * @param array            $wpdb_row
45
+	 * @param WP_REST_Request $request
46
+	 * @param RegistrationControllerBase $controller
47
+	 * @return array
48
+	 * @throws EE_Error
49
+	 * @throws InvalidDataTypeException
50
+	 * @throws InvalidInterfaceException
51
+	 * @throws InvalidArgumentException
52
+	 */
53
+	public function datetimeCheckinStati($wpdb_row, $request, $controller)
54
+	{
55
+		if (is_array($wpdb_row) && isset($wpdb_row['Registration.REG_ID'])) {
56
+			$reg = $this->registration_model->get_one_by_ID($wpdb_row['Registration.REG_ID']);
57
+		} else {
58
+			$reg = null;
59
+		}
60
+		if (! $reg instanceof EE_Registration
61
+		) {
62
+			throw new EE_Error(
63
+				sprintf(
64
+					__(
65
+					// @codingStandardsIgnoreStart
66
+						'Cannot calculate datetime_checkin_stati because the registration with ID %1$s (from database row %2$s) was not found',
67
+						// @codingStandardsIgnoreEnd
68
+						'event_espresso'
69
+					),
70
+					$wpdb_row['Registration.REG_ID'],
71
+					print_r($wpdb_row, true)
72
+				)
73
+			);
74
+		}
75
+		$datetime_ids = EEM_Datetime::instance()->get_col(
76
+			[
77
+				[
78
+					'Ticket.TKT_ID' => $reg->ticket_ID(),
79
+				],
80
+				'default_where_conditions' => EEM_Base::default_where_conditions_minimum_all,
81
+			]
82
+		);
83
+		$checkin_stati = array();
84
+		foreach ($datetime_ids as $datetime_id) {
85
+			$status = $reg->check_in_status_for_datetime($datetime_id);
86
+			switch ($status) {
87
+				case EE_Checkin::status_checked_out:
88
+					$status_pretty = 'OUT';
89
+					break;
90
+				case EE_Checkin::status_checked_in:
91
+					$status_pretty = 'IN';
92
+					break;
93
+				case EE_Checkin::status_checked_never:
94
+				default:
95
+					$status_pretty = 'NEVER';
96
+					break;
97
+			}
98
+			$checkin_stati[ $datetime_id ] = $status_pretty;
99
+		}
100
+		return $checkin_stati;
101
+	}
102 102
 
103 103
 
104
-    /**
105
-     * Provides an array for all the calculations possible that outlines a json schema for those calculations.
106
-     * Array is indexed by calculation (snake case) and value is the schema for that calculation.
107
-     *
108
-     * @since $VID:$
109
-     * @return array
110
-     */
111
-    public function schemaForCalculations()
112
-    {
113
-        return array(
114
-            'datetime_checkin_stati' => array(
115
-                'description' => esc_html__(
116
-                    'Returns the checkin status for each datetime this registration has access to.',
117
-                    'event_espresso'
118
-                ),
119
-                'type' => 'object',
120
-                'properties' => array(),
121
-                'additionalProperties' => array(
122
-                    'description' => esc_html(
123
-                        'Keys are date-time ids and values are the check-in status',
124
-                        'event_espresso'
125
-                    ),
126
-                    'type' => 'string'
127
-                ),
128
-            ),
129
-        );
130
-    }
104
+	/**
105
+	 * Provides an array for all the calculations possible that outlines a json schema for those calculations.
106
+	 * Array is indexed by calculation (snake case) and value is the schema for that calculation.
107
+	 *
108
+	 * @since $VID:$
109
+	 * @return array
110
+	 */
111
+	public function schemaForCalculations()
112
+	{
113
+		return array(
114
+			'datetime_checkin_stati' => array(
115
+				'description' => esc_html__(
116
+					'Returns the checkin status for each datetime this registration has access to.',
117
+					'event_espresso'
118
+				),
119
+				'type' => 'object',
120
+				'properties' => array(),
121
+				'additionalProperties' => array(
122
+					'description' => esc_html(
123
+						'Keys are date-time ids and values are the check-in status',
124
+						'event_espresso'
125
+					),
126
+					'type' => 'string'
127
+				),
128
+			),
129
+		);
130
+	}
131 131
 }
Please login to merge, or discard this patch.
core/libraries/rest_api/CalculatedModelFields.php 3 patches
Unused Use Statements   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -5,9 +5,8 @@
 block discarded – undo
5 5
 use EEM_Base;
6 6
 use EventEspresso\core\exceptions\UnexpectedEntityException;
7 7
 use EventEspresso\core\libraries\rest_api\calculations\CalculatedModelFieldsFactory;
8
-use EventEspresso\core\libraries\rest_api\controllers\Base;
9
-use EEH_Inflector;
10 8
 use EventEspresso\core\libraries\rest_api\controllers\Base as BaseController;
9
+use EEH_Inflector;
11 10
 
12 11
 /**
13 12
  * Class CalculatedModelFields
Please login to merge, or discard this patch.
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -57,7 +57,7 @@  discard block
 block discarded – undo
57 57
      */
58 58
     public function mapping($refresh = false)
59 59
     {
60
-        if (! $this->mapping || $refresh) {
60
+        if ( ! $this->mapping || $refresh) {
61 61
             $this->mapping = $this->generateNewMapping();
62 62
         }
63 63
         return $this->mapping;
@@ -84,7 +84,7 @@  discard block
 block discarded – undo
84 84
         foreach ($models_with_calculated_fields as $model_name) {
85 85
             $calculator = $this->factory->createFromModel($model_name);
86 86
             foreach (array_keys(call_user_func(array($calculator, 'schemaForCalculations'))) as $field_name) {
87
-                $mapping[ $model_name ][ $field_name ] = get_class($calculator);
87
+                $mapping[$model_name][$field_name] = get_class($calculator);
88 88
             }
89 89
         }
90 90
         return apply_filters(
@@ -113,8 +113,8 @@  discard block
 block discarded – undo
113 113
             foreach ($map_for_model as $calculation_index => $calculations_class) {
114 114
                 $calculator = $this->factory->createFromClassname($calculations_class);
115 115
                 $schema = call_user_func(array($calculator, 'schemaForCalculation'), $calculation_index);
116
-                if (! empty($schema)) {
117
-                    $schema_map[ $map_model ][ $calculation_index ] = $schema;
116
+                if ( ! empty($schema)) {
117
+                    $schema_map[$map_model][$calculation_index] = $schema;
118 118
                 }
119 119
             }
120 120
         }
@@ -131,8 +131,8 @@  discard block
 block discarded – undo
131 131
     public function retrieveCalculatedFieldsForModel(EEM_Base $model)
132 132
     {
133 133
         $mapping = $this->mapping();
134
-        if (isset($mapping[ $model->get_this_model_name() ])) {
135
-            return array_keys($mapping[ $model->get_this_model_name() ]);
134
+        if (isset($mapping[$model->get_this_model_name()])) {
135
+            return array_keys($mapping[$model->get_this_model_name()]);
136 136
         }
137 137
         return array();
138 138
     }
@@ -145,7 +145,7 @@  discard block
 block discarded – undo
145 145
      */
146 146
     public function getJsonSchemaForModel(EEM_Base $model)
147 147
     {
148
-        if (! $this->mapping_schema) {
148
+        if ( ! $this->mapping_schema) {
149 149
             $this->mapping_schema = $this->generateNewMappingSchema();
150 150
         }
151 151
         return array(
@@ -154,8 +154,8 @@  discard block
 block discarded – undo
154 154
                 'event_espresso'
155 155
             ),
156 156
             'type' => 'object',
157
-            'properties' => isset($this->mapping_schema[ $model->get_this_model_name() ])
158
-                ? $this->mapping_schema[ $model->get_this_model_name() ]
157
+            'properties' => isset($this->mapping_schema[$model->get_this_model_name()])
158
+                ? $this->mapping_schema[$model->get_this_model_name()]
159 159
                 : array(),
160 160
             'additionalProperties' => false,
161 161
             'readonly' => true,
@@ -183,10 +183,10 @@  discard block
 block discarded – undo
183 183
         Base $controller
184 184
     ) {
185 185
         $mapping = $this->mapping();
186
-        if (isset($mapping[ $model->get_this_model_name() ])
187
-            && isset($mapping[ $model->get_this_model_name() ][ $field_name ])
186
+        if (isset($mapping[$model->get_this_model_name()])
187
+            && isset($mapping[$model->get_this_model_name()][$field_name])
188 188
         ) {
189
-            $classname = $mapping[ $model->get_this_model_name() ][ $field_name ];
189
+            $classname = $mapping[$model->get_this_model_name()][$field_name];
190 190
             $calculator = $this->factory->createFromClassname($classname);
191 191
             $class_method_name = EEH_Inflector::camelize_all_but_first($field_name);
192 192
             return call_user_func(array($calculator, $class_method_name), $wpdb_row, $rest_request, $controller);
Please login to merge, or discard this patch.
Indentation   +173 added lines, -173 removed lines patch added patch discarded remove patch
@@ -22,177 +22,177 @@
 block discarded – undo
22 22
 class CalculatedModelFields
23 23
 {
24 24
 
25
-    /**
26
-     * @var array
27
-     */
28
-    protected $mapping;
29
-
30
-    /**
31
-     * @var array
32
-     */
33
-    protected $mapping_schema;
34
-
35
-    /**
36
-     * @var CalculatedModelFieldsFactory
37
-     */
38
-    private $factory;
39
-
40
-    /**
41
-     * CalculatedModelFields constructor.
42
-     * @param CalculatedModelFieldsFactory $factory
43
-     */
44
-    public function __construct(CalculatedModelFieldsFactory $factory)
45
-    {
46
-        $this->factory = $factory;
47
-    }
48
-    /**
49
-     * @param bool $refresh
50
-     * @return array top-level-keys are model names (eg "Event")
51
-     * next-level are the calculated field names AND method names on classes
52
-     * which perform calculations, values are the fully qualified classnames which do the calculations
53
-     * These callbacks should accept as arguments:
54
-     * the wpdb row results,
55
-     * the WP_Request object,
56
-     * the controller object
57
-     */
58
-    public function mapping($refresh = false)
59
-    {
60
-        if (! $this->mapping || $refresh) {
61
-            $this->mapping = $this->generateNewMapping();
62
-        }
63
-        return $this->mapping;
64
-    }
65
-
66
-
67
-    /**
68
-     * Generates a new mapping between model calculated fields and their callbacks
69
-     *
70
-     * @return array
71
-     */
72
-    protected function generateNewMapping()
73
-    {
74
-        $mapping = array();
75
-        $models_with_calculated_fields = array(
76
-            'Attendee',
77
-            'Datetime',
78
-            'Event',
79
-            'Registration'
80
-        );
81
-        foreach ($models_with_calculated_fields as $model_name) {
82
-            $calculator = $this->factory->createFromModel($model_name);
83
-            foreach (array_keys(call_user_func(array($calculator, 'schemaForCalculations'))) as $field_name) {
84
-                $mapping[ $model_name ][ $field_name ] = get_class($calculator);
85
-            }
86
-        }
87
-        return apply_filters(
88
-            'FHEE__EventEspresso\core\libraries\rest_api\Calculated_Model_Fields__mapping',
89
-            $mapping
90
-        );
91
-    }
92
-
93
-
94
-    /**
95
-     * Generates the schema for each calculation index in the calculation map.
96
-     *
97
-     * @return array
98
-     * @throws UnexpectedEntityException
99
-     */
100
-    protected function generateNewMappingSchema()
101
-    {
102
-        $schema_map = array();
103
-        foreach ($this->mapping() as $map_model => $map_for_model) {
104
-            /**
105
-             * @var string $calculation_index
106
-             * @var string $calculations_class
107
-             */
108
-            foreach ($map_for_model as $calculation_index => $calculations_class) {
109
-                $calculator = $this->factory->createFromClassname($calculations_class);
110
-                $schema = call_user_func(array($calculator, 'schemaForCalculation'), $calculation_index);
111
-                if (! empty($schema)) {
112
-                    $schema_map[ $map_model ][ $calculation_index ] = $schema;
113
-                }
114
-            }
115
-        }
116
-        return $schema_map;
117
-    }
118
-
119
-
120
-    /**
121
-     * Gets the known calculated fields for model
122
-     *
123
-     * @param EEM_Base $model
124
-     * @return array allowable values for this field
125
-     */
126
-    public function retrieveCalculatedFieldsForModel(EEM_Base $model)
127
-    {
128
-        $mapping = $this->mapping();
129
-        if (isset($mapping[ $model->get_this_model_name() ])) {
130
-            return array_keys($mapping[ $model->get_this_model_name() ]);
131
-        }
132
-        return array();
133
-    }
134
-
135
-
136
-    /**
137
-     * Returns the JsonSchema for the calculated fields on the given model.
138
-     * @param EEM_Base $model
139
-     * @return array
140
-     */
141
-    public function getJsonSchemaForModel(EEM_Base $model)
142
-    {
143
-        if (! $this->mapping_schema) {
144
-            $this->mapping_schema = $this->generateNewMappingSchema();
145
-        }
146
-        return array(
147
-            'description' => esc_html__(
148
-                'Available calculated fields for this model.  Fields are only present in the response if explicitly requested',
149
-                'event_espresso'
150
-            ),
151
-            'type' => 'object',
152
-            'properties' => isset($this->mapping_schema[ $model->get_this_model_name() ])
153
-                ? $this->mapping_schema[ $model->get_this_model_name() ]
154
-                : array(),
155
-            'additionalProperties' => false,
156
-            'readonly' => true,
157
-        );
158
-    }
159
-
160
-
161
-    /**
162
-     * Retrieves the value for this calculation
163
-     *
164
-     * @param EEM_Base $model
165
-     * @param string $field_name
166
-     * @param array $wpdb_row
167
-     * @param $rest_request
168
-     * @param BaseController $controller
169
-     * @return mixed|null
170
-     * @throws RestException
171
-     * @throws UnexpectedEntityException
172
-     */
173
-    public function retrieveCalculatedFieldValue(
174
-        EEM_Base $model,
175
-        $field_name,
176
-        $wpdb_row,
177
-        $rest_request,
178
-        Base $controller
179
-    ) {
180
-        $mapping = $this->mapping();
181
-        if (isset($mapping[ $model->get_this_model_name() ])
182
-            && isset($mapping[ $model->get_this_model_name() ][ $field_name ])
183
-        ) {
184
-            $classname = $mapping[ $model->get_this_model_name() ][ $field_name ];
185
-            $calculator = $this->factory->createFromClassname($classname);
186
-            $class_method_name = EEH_Inflector::camelize_all_but_first($field_name);
187
-            return call_user_func(array($calculator, $class_method_name), $wpdb_row, $rest_request, $controller);
188
-        }
189
-        throw new RestException(
190
-            'calculated_field_does_not_exist',
191
-            sprintf(
192
-                __('There is no calculated field %1$s on resource %2$s', 'event_espresso'),
193
-                $field_name,
194
-                $model->get_this_model_name()
195
-            )
196
-        );
197
-    }
25
+	/**
26
+	 * @var array
27
+	 */
28
+	protected $mapping;
29
+
30
+	/**
31
+	 * @var array
32
+	 */
33
+	protected $mapping_schema;
34
+
35
+	/**
36
+	 * @var CalculatedModelFieldsFactory
37
+	 */
38
+	private $factory;
39
+
40
+	/**
41
+	 * CalculatedModelFields constructor.
42
+	 * @param CalculatedModelFieldsFactory $factory
43
+	 */
44
+	public function __construct(CalculatedModelFieldsFactory $factory)
45
+	{
46
+		$this->factory = $factory;
47
+	}
48
+	/**
49
+	 * @param bool $refresh
50
+	 * @return array top-level-keys are model names (eg "Event")
51
+	 * next-level are the calculated field names AND method names on classes
52
+	 * which perform calculations, values are the fully qualified classnames which do the calculations
53
+	 * These callbacks should accept as arguments:
54
+	 * the wpdb row results,
55
+	 * the WP_Request object,
56
+	 * the controller object
57
+	 */
58
+	public function mapping($refresh = false)
59
+	{
60
+		if (! $this->mapping || $refresh) {
61
+			$this->mapping = $this->generateNewMapping();
62
+		}
63
+		return $this->mapping;
64
+	}
65
+
66
+
67
+	/**
68
+	 * Generates a new mapping between model calculated fields and their callbacks
69
+	 *
70
+	 * @return array
71
+	 */
72
+	protected function generateNewMapping()
73
+	{
74
+		$mapping = array();
75
+		$models_with_calculated_fields = array(
76
+			'Attendee',
77
+			'Datetime',
78
+			'Event',
79
+			'Registration'
80
+		);
81
+		foreach ($models_with_calculated_fields as $model_name) {
82
+			$calculator = $this->factory->createFromModel($model_name);
83
+			foreach (array_keys(call_user_func(array($calculator, 'schemaForCalculations'))) as $field_name) {
84
+				$mapping[ $model_name ][ $field_name ] = get_class($calculator);
85
+			}
86
+		}
87
+		return apply_filters(
88
+			'FHEE__EventEspresso\core\libraries\rest_api\Calculated_Model_Fields__mapping',
89
+			$mapping
90
+		);
91
+	}
92
+
93
+
94
+	/**
95
+	 * Generates the schema for each calculation index in the calculation map.
96
+	 *
97
+	 * @return array
98
+	 * @throws UnexpectedEntityException
99
+	 */
100
+	protected function generateNewMappingSchema()
101
+	{
102
+		$schema_map = array();
103
+		foreach ($this->mapping() as $map_model => $map_for_model) {
104
+			/**
105
+			 * @var string $calculation_index
106
+			 * @var string $calculations_class
107
+			 */
108
+			foreach ($map_for_model as $calculation_index => $calculations_class) {
109
+				$calculator = $this->factory->createFromClassname($calculations_class);
110
+				$schema = call_user_func(array($calculator, 'schemaForCalculation'), $calculation_index);
111
+				if (! empty($schema)) {
112
+					$schema_map[ $map_model ][ $calculation_index ] = $schema;
113
+				}
114
+			}
115
+		}
116
+		return $schema_map;
117
+	}
118
+
119
+
120
+	/**
121
+	 * Gets the known calculated fields for model
122
+	 *
123
+	 * @param EEM_Base $model
124
+	 * @return array allowable values for this field
125
+	 */
126
+	public function retrieveCalculatedFieldsForModel(EEM_Base $model)
127
+	{
128
+		$mapping = $this->mapping();
129
+		if (isset($mapping[ $model->get_this_model_name() ])) {
130
+			return array_keys($mapping[ $model->get_this_model_name() ]);
131
+		}
132
+		return array();
133
+	}
134
+
135
+
136
+	/**
137
+	 * Returns the JsonSchema for the calculated fields on the given model.
138
+	 * @param EEM_Base $model
139
+	 * @return array
140
+	 */
141
+	public function getJsonSchemaForModel(EEM_Base $model)
142
+	{
143
+		if (! $this->mapping_schema) {
144
+			$this->mapping_schema = $this->generateNewMappingSchema();
145
+		}
146
+		return array(
147
+			'description' => esc_html__(
148
+				'Available calculated fields for this model.  Fields are only present in the response if explicitly requested',
149
+				'event_espresso'
150
+			),
151
+			'type' => 'object',
152
+			'properties' => isset($this->mapping_schema[ $model->get_this_model_name() ])
153
+				? $this->mapping_schema[ $model->get_this_model_name() ]
154
+				: array(),
155
+			'additionalProperties' => false,
156
+			'readonly' => true,
157
+		);
158
+	}
159
+
160
+
161
+	/**
162
+	 * Retrieves the value for this calculation
163
+	 *
164
+	 * @param EEM_Base $model
165
+	 * @param string $field_name
166
+	 * @param array $wpdb_row
167
+	 * @param $rest_request
168
+	 * @param BaseController $controller
169
+	 * @return mixed|null
170
+	 * @throws RestException
171
+	 * @throws UnexpectedEntityException
172
+	 */
173
+	public function retrieveCalculatedFieldValue(
174
+		EEM_Base $model,
175
+		$field_name,
176
+		$wpdb_row,
177
+		$rest_request,
178
+		Base $controller
179
+	) {
180
+		$mapping = $this->mapping();
181
+		if (isset($mapping[ $model->get_this_model_name() ])
182
+			&& isset($mapping[ $model->get_this_model_name() ][ $field_name ])
183
+		) {
184
+			$classname = $mapping[ $model->get_this_model_name() ][ $field_name ];
185
+			$calculator = $this->factory->createFromClassname($classname);
186
+			$class_method_name = EEH_Inflector::camelize_all_but_first($field_name);
187
+			return call_user_func(array($calculator, $class_method_name), $wpdb_row, $rest_request, $controller);
188
+		}
189
+		throw new RestException(
190
+			'calculated_field_does_not_exist',
191
+			sprintf(
192
+				__('There is no calculated field %1$s on resource %2$s', 'event_espresso'),
193
+				$field_name,
194
+				$model->get_this_model_name()
195
+			)
196
+		);
197
+	}
198 198
 }
Please login to merge, or discard this patch.
core/libraries/rest_api/calculations/CalculatedModelFieldsFactory.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -40,7 +40,7 @@  discard block
 block discarded – undo
40 40
      */
41 41
     public function createFromModel($model_name)
42 42
     {
43
-        return $this->createFromClassname('EventEspresso\core\libraries\rest_api\calculations\\' . $model_name);
43
+        return $this->createFromClassname('EventEspresso\core\libraries\rest_api\calculations\\'.$model_name);
44 44
     }
45 45
 
46 46
     /**
@@ -51,7 +51,7 @@  discard block
 block discarded – undo
51 51
     public function createFromClassname($calculator_classname)
52 52
     {
53 53
         $calculator = $this->loader->getShared($calculator_classname);
54
-        if (!$calculator instanceof Base) {
54
+        if ( ! $calculator instanceof Base) {
55 55
             throw new UnexpectedEntityException(
56 56
                 $calculator_classname,
57 57
                 'EventEspresso\core\libraries\rest_api\calculations\Base'
Please login to merge, or discard this patch.
Indentation   +37 added lines, -37 removed lines patch added patch discarded remove patch
@@ -18,46 +18,46 @@
 block discarded – undo
18 18
  */
19 19
 class CalculatedModelFieldsFactory
20 20
 {
21
-    private $loader;
21
+	private $loader;
22 22
 
23
-    /**
24
-     * CalculatedModelFieldsFactory constructor.
25
-     * @param LoaderInterface $loader
26
-     */
27
-    public function __construct(LoaderInterface $loader)
28
-    {
29
-        $this->loader = $loader;
30
-    }
23
+	/**
24
+	 * CalculatedModelFieldsFactory constructor.
25
+	 * @param LoaderInterface $loader
26
+	 */
27
+	public function __construct(LoaderInterface $loader)
28
+	{
29
+		$this->loader = $loader;
30
+	}
31 31
 
32
-    /**
33
-     * Creates the calculator class that corresponds to that particular model
34
-     * @since $VID:$
35
-     * @param string $model_name
36
-     * @return Base
37
-     * @throws UnexpectedEntityException
38
-     */
39
-    public function createFromModel($model_name)
40
-    {
41
-        return $this->createFromClassname('EventEspresso\core\libraries\rest_api\calculations\\' . $model_name);
42
-    }
32
+	/**
33
+	 * Creates the calculator class that corresponds to that particular model
34
+	 * @since $VID:$
35
+	 * @param string $model_name
36
+	 * @return Base
37
+	 * @throws UnexpectedEntityException
38
+	 */
39
+	public function createFromModel($model_name)
40
+	{
41
+		return $this->createFromClassname('EventEspresso\core\libraries\rest_api\calculations\\' . $model_name);
42
+	}
43 43
 
44
-    /**
45
-     * Creates the calculator class that corresponds to that classname and verifies it's of the correct type
46
-     * @param string $calculator_classname
47
-     * @return Base
48
-     * @throws UnexpectedEntityException
49
-     */
50
-    public function createFromClassname($calculator_classname)
51
-    {
52
-        $calculator = $this->loader->getShared($calculator_classname);
53
-        if (!$calculator instanceof Base) {
54
-            throw new UnexpectedEntityException(
55
-                $calculator_classname,
56
-                'EventEspresso\core\libraries\rest_api\calculations\Base'
57
-            );
58
-        }
59
-        return $calculator;
60
-    }
44
+	/**
45
+	 * Creates the calculator class that corresponds to that classname and verifies it's of the correct type
46
+	 * @param string $calculator_classname
47
+	 * @return Base
48
+	 * @throws UnexpectedEntityException
49
+	 */
50
+	public function createFromClassname($calculator_classname)
51
+	{
52
+		$calculator = $this->loader->getShared($calculator_classname);
53
+		if (!$calculator instanceof Base) {
54
+			throw new UnexpectedEntityException(
55
+				$calculator_classname,
56
+				'EventEspresso\core\libraries\rest_api\calculations\Base'
57
+			);
58
+		}
59
+		return $calculator;
60
+	}
61 61
 }
62 62
 // End of file CalculationsFactory.php
63 63
 // Location: EventEspresso\core\libraries\rest_api\calculations/CalculationsFactory.php
Please login to merge, or discard this patch.
core/libraries/rest_api/calculations/Datetime.php 2 patches
Indentation   +196 added lines, -196 removed lines patch added patch discarded remove patch
@@ -17,210 +17,210 @@
 block discarded – undo
17 17
 
18 18
 class Datetime extends DatetimeCalculationBase
19 19
 {
20
-    /**
21
-     * @var EEM_Datetime
22
-     */
23
-    protected $datetime_model;
20
+	/**
21
+	 * @var EEM_Datetime
22
+	 */
23
+	protected $datetime_model;
24 24
 
25
-    /**
26
-     * @var EEM_Registration
27
-     */
28
-    protected $registration_model;
29
-    public function __construct(EEM_Datetime $datetime_model, EEM_Registration $registration_model)
30
-    {
31
-        $this->datetime_model = $datetime_model;
32
-        $this->registration_model = $registration_model;
33
-    }
25
+	/**
26
+	 * @var EEM_Registration
27
+	 */
28
+	protected $registration_model;
29
+	public function __construct(EEM_Datetime $datetime_model, EEM_Registration $registration_model)
30
+	{
31
+		$this->datetime_model = $datetime_model;
32
+		$this->registration_model = $registration_model;
33
+	}
34 34
 
35
-    /**
36
-     * Calculates the total spaces available on the datetime, taking into account
37
-     * ticket limits too.
38
-     *
39
-     * @see EE_Datetime::spaces_remaining( true )
40
-     * @param array            $wpdb_row
41
-     * @param WP_REST_Request $request
42
-     * @param DatetimeControllerBase  $controller
43
-     * @return int
44
-     * @throws EE_Error
45
-     * @throws InvalidDataTypeException
46
-     * @throws InvalidInterfaceException
47
-     * @throws InvalidArgumentException
48
-     * @throws ReflectionException
49
-     */
50
-    public function spacesRemainingConsideringTickets($wpdb_row, $request, $controller)
51
-    {
52
-        if (is_array($wpdb_row) && isset($wpdb_row['Datetime.DTT_ID'])) {
53
-            $dtt_obj = $this->datetime_model->get_one_by_ID($wpdb_row['Datetime.DTT_ID']);
54
-        } else {
55
-            $dtt_obj = null;
56
-        }
57
-        if ($dtt_obj instanceof EE_Datetime) {
58
-            return $dtt_obj->spaces_remaining(true);
59
-        }
60
-        throw new EE_Error(
61
-            sprintf(
62
-                __(
63
-                // @codingStandardsIgnoreStart
64
-                    'Cannot calculate spaces_remaining_considering_tickets because the datetime with ID %1$s (from database row %2$s) was not found',
65
-                    // @codingStandardsIgnoreEnd
66
-                    'event_espresso'
67
-                ),
68
-                $wpdb_row['Datetime.DTT_ID'],
69
-                print_r($wpdb_row, true)
70
-            )
71
-        );
72
-    }
35
+	/**
36
+	 * Calculates the total spaces available on the datetime, taking into account
37
+	 * ticket limits too.
38
+	 *
39
+	 * @see EE_Datetime::spaces_remaining( true )
40
+	 * @param array            $wpdb_row
41
+	 * @param WP_REST_Request $request
42
+	 * @param DatetimeControllerBase  $controller
43
+	 * @return int
44
+	 * @throws EE_Error
45
+	 * @throws InvalidDataTypeException
46
+	 * @throws InvalidInterfaceException
47
+	 * @throws InvalidArgumentException
48
+	 * @throws ReflectionException
49
+	 */
50
+	public function spacesRemainingConsideringTickets($wpdb_row, $request, $controller)
51
+	{
52
+		if (is_array($wpdb_row) && isset($wpdb_row['Datetime.DTT_ID'])) {
53
+			$dtt_obj = $this->datetime_model->get_one_by_ID($wpdb_row['Datetime.DTT_ID']);
54
+		} else {
55
+			$dtt_obj = null;
56
+		}
57
+		if ($dtt_obj instanceof EE_Datetime) {
58
+			return $dtt_obj->spaces_remaining(true);
59
+		}
60
+		throw new EE_Error(
61
+			sprintf(
62
+				__(
63
+				// @codingStandardsIgnoreStart
64
+					'Cannot calculate spaces_remaining_considering_tickets because the datetime with ID %1$s (from database row %2$s) was not found',
65
+					// @codingStandardsIgnoreEnd
66
+					'event_espresso'
67
+				),
68
+				$wpdb_row['Datetime.DTT_ID'],
69
+				print_r($wpdb_row, true)
70
+			)
71
+		);
72
+	}
73 73
 
74 74
 
75
-    /**
76
-     * Counts registrations who have checked into this datetime
77
-     *
78
-     * @param array           $wpdb_row
79
-     * @param WP_REST_Request $request
80
-     * @param DatetimeControllerBase $controller
81
-     * @return int
82
-     * @throws EE_Error
83
-     * @throws InvalidArgumentException
84
-     * @throws InvalidDataTypeException
85
-     * @throws InvalidInterfaceException
86
-     * @throws RestException
87
-     */
88
-    public function registrationsCheckedInCount($wpdb_row, $request, $controller)
89
-    {
90
-        if (! is_array($wpdb_row) || ! isset($wpdb_row['Datetime.DTT_ID'])) {
91
-            throw new EE_Error(
92
-                sprintf(
93
-                    __(
94
-                    // @codingStandardsIgnoreStart
95
-                        'Cannot calculate registrations_checked_in_count because the database row %1$s does not have an entry for "Datetime.DTT_ID"',
96
-                        // @codingStandardsIgnoreEnd
97
-                        'event_espresso'
98
-                    ),
99
-                    print_r($wpdb_row, true)
100
-                )
101
-            );
102
-        }
103
-        $this->verifyCurrentUserCan('ee_read_checkins', 'registrations_checked_in_count');
104
-        return $this->registration_model
105
-                               ->count_registrations_checked_into_datetime($wpdb_row['Datetime.DTT_ID'], true);
106
-    }
75
+	/**
76
+	 * Counts registrations who have checked into this datetime
77
+	 *
78
+	 * @param array           $wpdb_row
79
+	 * @param WP_REST_Request $request
80
+	 * @param DatetimeControllerBase $controller
81
+	 * @return int
82
+	 * @throws EE_Error
83
+	 * @throws InvalidArgumentException
84
+	 * @throws InvalidDataTypeException
85
+	 * @throws InvalidInterfaceException
86
+	 * @throws RestException
87
+	 */
88
+	public function registrationsCheckedInCount($wpdb_row, $request, $controller)
89
+	{
90
+		if (! is_array($wpdb_row) || ! isset($wpdb_row['Datetime.DTT_ID'])) {
91
+			throw new EE_Error(
92
+				sprintf(
93
+					__(
94
+					// @codingStandardsIgnoreStart
95
+						'Cannot calculate registrations_checked_in_count because the database row %1$s does not have an entry for "Datetime.DTT_ID"',
96
+						// @codingStandardsIgnoreEnd
97
+						'event_espresso'
98
+					),
99
+					print_r($wpdb_row, true)
100
+				)
101
+			);
102
+		}
103
+		$this->verifyCurrentUserCan('ee_read_checkins', 'registrations_checked_in_count');
104
+		return $this->registration_model
105
+							   ->count_registrations_checked_into_datetime($wpdb_row['Datetime.DTT_ID'], true);
106
+	}
107 107
 
108 108
 
109
-    /**
110
-     * Counts registrations who have checked out of this datetime
111
-     *
112
-     * @param array           $wpdb_row
113
-     * @param WP_REST_Request $request
114
-     * @param DatetimeControllerBase $controller
115
-     * @return int
116
-     * @throws EE_Error
117
-     * @throws InvalidArgumentException
118
-     * @throws InvalidDataTypeException
119
-     * @throws InvalidInterfaceException
120
-     * @throws RestException
121
-     */
122
-    public function registrationsCheckedOutCount($wpdb_row, $request, $controller)
123
-    {
124
-        if (! is_array($wpdb_row) || ! isset($wpdb_row['Datetime.DTT_ID'])) {
125
-            throw new EE_Error(
126
-                sprintf(
127
-                    __(
128
-                    // @codingStandardsIgnoreStart
129
-                        'Cannot calculate registrations_checked_out_count because the database row %1$s does not have an entry for "Datetime.DTT_ID"',
130
-                        // @codingStandardsIgnoreEnd
131
-                        'event_espresso'
132
-                    ),
133
-                    print_r($wpdb_row, true)
134
-                )
135
-            );
136
-        }
137
-        $this->verifyCurrentUserCan('ee_read_checkins', 'registrations_checked_out_count');
138
-        return $this->registration_model
139
-                               ->count_registrations_checked_into_datetime($wpdb_row['Datetime.DTT_ID'], false);
140
-    }
109
+	/**
110
+	 * Counts registrations who have checked out of this datetime
111
+	 *
112
+	 * @param array           $wpdb_row
113
+	 * @param WP_REST_Request $request
114
+	 * @param DatetimeControllerBase $controller
115
+	 * @return int
116
+	 * @throws EE_Error
117
+	 * @throws InvalidArgumentException
118
+	 * @throws InvalidDataTypeException
119
+	 * @throws InvalidInterfaceException
120
+	 * @throws RestException
121
+	 */
122
+	public function registrationsCheckedOutCount($wpdb_row, $request, $controller)
123
+	{
124
+		if (! is_array($wpdb_row) || ! isset($wpdb_row['Datetime.DTT_ID'])) {
125
+			throw new EE_Error(
126
+				sprintf(
127
+					__(
128
+					// @codingStandardsIgnoreStart
129
+						'Cannot calculate registrations_checked_out_count because the database row %1$s does not have an entry for "Datetime.DTT_ID"',
130
+						// @codingStandardsIgnoreEnd
131
+						'event_espresso'
132
+					),
133
+					print_r($wpdb_row, true)
134
+				)
135
+			);
136
+		}
137
+		$this->verifyCurrentUserCan('ee_read_checkins', 'registrations_checked_out_count');
138
+		return $this->registration_model
139
+							   ->count_registrations_checked_into_datetime($wpdb_row['Datetime.DTT_ID'], false);
140
+	}
141 141
 
142 142
 
143
-    /**
144
-     * Counts the number of pending-payment registrations for this event (regardless
145
-     * of how many datetimes each registrations' ticket purchase is for)
146
-     *
147
-     * @param array           $wpdb_row
148
-     * @param WP_REST_Request $request
149
-     * @param DatetimeControllerBase $controller
150
-     * @return int
151
-     * @throws EE_Error
152
-     * @throws InvalidArgumentException
153
-     * @throws InvalidDataTypeException
154
-     * @throws InvalidInterfaceException
155
-     * @throws RestException
156
-     */
157
-    public function spotsTakenPendingPayment($wpdb_row, $request, $controller)
158
-    {
159
-        if (! is_array($wpdb_row) || ! isset($wpdb_row['Datetime.DTT_ID'])) {
160
-            throw new EE_Error(
161
-                sprintf(
162
-                    __(
163
-                    // @codingStandardsIgnoreStart
164
-                        'Cannot calculate spots_taken_pending_payment because the database row %1$s does not have an entry for "Datetime.DTT_ID"',
165
-                        // @codingStandardsIgnoreEnd
166
-                        'event_espresso'
167
-                    ),
168
-                    print_r($wpdb_row, true)
169
-                )
170
-            );
171
-        }
172
-        $this->verifyCurrentUserCan('ee_read_registrations', 'spots_taken_pending_payment');
173
-        return $this->registration_model->count(
174
-            array(
175
-                array(
176
-                    'Ticket.Datetime.DTT_ID' => $wpdb_row['Datetime.DTT_ID'],
177
-                    'STS_ID'                 => EEM_Registration::status_id_pending_payment,
178
-                ),
179
-            ),
180
-            'REG_ID',
181
-            true
182
-        );
183
-    }
143
+	/**
144
+	 * Counts the number of pending-payment registrations for this event (regardless
145
+	 * of how many datetimes each registrations' ticket purchase is for)
146
+	 *
147
+	 * @param array           $wpdb_row
148
+	 * @param WP_REST_Request $request
149
+	 * @param DatetimeControllerBase $controller
150
+	 * @return int
151
+	 * @throws EE_Error
152
+	 * @throws InvalidArgumentException
153
+	 * @throws InvalidDataTypeException
154
+	 * @throws InvalidInterfaceException
155
+	 * @throws RestException
156
+	 */
157
+	public function spotsTakenPendingPayment($wpdb_row, $request, $controller)
158
+	{
159
+		if (! is_array($wpdb_row) || ! isset($wpdb_row['Datetime.DTT_ID'])) {
160
+			throw new EE_Error(
161
+				sprintf(
162
+					__(
163
+					// @codingStandardsIgnoreStart
164
+						'Cannot calculate spots_taken_pending_payment because the database row %1$s does not have an entry for "Datetime.DTT_ID"',
165
+						// @codingStandardsIgnoreEnd
166
+						'event_espresso'
167
+					),
168
+					print_r($wpdb_row, true)
169
+				)
170
+			);
171
+		}
172
+		$this->verifyCurrentUserCan('ee_read_registrations', 'spots_taken_pending_payment');
173
+		return $this->registration_model->count(
174
+			array(
175
+				array(
176
+					'Ticket.Datetime.DTT_ID' => $wpdb_row['Datetime.DTT_ID'],
177
+					'STS_ID'                 => EEM_Registration::status_id_pending_payment,
178
+				),
179
+			),
180
+			'REG_ID',
181
+			true
182
+		);
183
+	}
184 184
 
185 185
 
186
-    /**
187
-     * Provides an array for all the calculations possible that outlines a json schema for those calculations.
188
-     * Array is indexed by calculation (snake case) and value is the schema for that calculation.
189
-     *
190
-     * @since $VID:$
191
-     * @return array
192
-     */
193
-    public function schemaForCalculations()
194
-    {
195
-        return array(
196
-            'spaces_remaining_considering_tickets' => array(
197
-                'description' => esc_html__(
198
-                    'Calculates the total spaces available on the datetime, taking into account ticket limits too.',
199
-                    'event_espresso'
200
-                ),
201
-                'type' => 'number'
202
-            ),
203
-            'registrations_checked_in_count' => array(
204
-                'description' => esc_html__(
205
-                    'Counts registrations who have checked into this datetime.',
206
-                    'event_espresso'
207
-                ),
208
-                'type' => 'number'
209
-            ),
210
-            'registrations_checked_out_count' => array(
211
-                'description' => esc_html__(
212
-                    'Counts registrations who have checked out of this datetime.',
213
-                    'event_espresso'
214
-                ),
215
-                'type' => 'number'
216
-            ),
217
-            'spots_taken_pending_payment' => array(
218
-                'description' => esc_html__(
219
-                    'The count of pending-payment registrations for this event (regardless of how many datetimes each registration\'s ticket purchase is for',
220
-                    'event_espresso'
221
-                ),
222
-                'type' => 'number'
223
-            ),
224
-        );
225
-    }
186
+	/**
187
+	 * Provides an array for all the calculations possible that outlines a json schema for those calculations.
188
+	 * Array is indexed by calculation (snake case) and value is the schema for that calculation.
189
+	 *
190
+	 * @since $VID:$
191
+	 * @return array
192
+	 */
193
+	public function schemaForCalculations()
194
+	{
195
+		return array(
196
+			'spaces_remaining_considering_tickets' => array(
197
+				'description' => esc_html__(
198
+					'Calculates the total spaces available on the datetime, taking into account ticket limits too.',
199
+					'event_espresso'
200
+				),
201
+				'type' => 'number'
202
+			),
203
+			'registrations_checked_in_count' => array(
204
+				'description' => esc_html__(
205
+					'Counts registrations who have checked into this datetime.',
206
+					'event_espresso'
207
+				),
208
+				'type' => 'number'
209
+			),
210
+			'registrations_checked_out_count' => array(
211
+				'description' => esc_html__(
212
+					'Counts registrations who have checked out of this datetime.',
213
+					'event_espresso'
214
+				),
215
+				'type' => 'number'
216
+			),
217
+			'spots_taken_pending_payment' => array(
218
+				'description' => esc_html__(
219
+					'The count of pending-payment registrations for this event (regardless of how many datetimes each registration\'s ticket purchase is for',
220
+					'event_espresso'
221
+				),
222
+				'type' => 'number'
223
+			),
224
+		);
225
+	}
226 226
 }
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -87,7 +87,7 @@  discard block
 block discarded – undo
87 87
      */
88 88
     public function registrationsCheckedInCount($wpdb_row, $request, $controller)
89 89
     {
90
-        if (! is_array($wpdb_row) || ! isset($wpdb_row['Datetime.DTT_ID'])) {
90
+        if ( ! is_array($wpdb_row) || ! isset($wpdb_row['Datetime.DTT_ID'])) {
91 91
             throw new EE_Error(
92 92
                 sprintf(
93 93
                     __(
@@ -121,7 +121,7 @@  discard block
 block discarded – undo
121 121
      */
122 122
     public function registrationsCheckedOutCount($wpdb_row, $request, $controller)
123 123
     {
124
-        if (! is_array($wpdb_row) || ! isset($wpdb_row['Datetime.DTT_ID'])) {
124
+        if ( ! is_array($wpdb_row) || ! isset($wpdb_row['Datetime.DTT_ID'])) {
125 125
             throw new EE_Error(
126 126
                 sprintf(
127 127
                     __(
@@ -156,7 +156,7 @@  discard block
 block discarded – undo
156 156
      */
157 157
     public function spotsTakenPendingPayment($wpdb_row, $request, $controller)
158 158
     {
159
-        if (! is_array($wpdb_row) || ! isset($wpdb_row['Datetime.DTT_ID'])) {
159
+        if ( ! is_array($wpdb_row) || ! isset($wpdb_row['Datetime.DTT_ID'])) {
160 160
             throw new EE_Error(
161 161
                 sprintf(
162 162
                     __(
Please login to merge, or discard this patch.
core/libraries/rest_api/calculations/Attendee.php 1 patch
Indentation   +37 added lines, -37 removed lines patch added patch discarded remove patch
@@ -17,43 +17,43 @@
 block discarded – undo
17 17
 class Attendee extends AttendeeCalculationsBase
18 18
 {
19 19
 
20
-    /**
21
-     * @param array                  $wpdb_row
22
-     * @param WP_REST_Request        $request
23
-     * @param AttendeeControllerBase $controller
24
-     * @since 4.9.66.p
25
-     * @return string
26
-     */
27
-    public function userAvatar(array $wpdb_row, WP_REST_Request $request, AttendeeControllerBase $controller)
28
-    {
29
-        if (is_array($wpdb_row) && isset($wpdb_row['Attendee_Meta.ATT_email'])) {
30
-            $email_address = $wpdb_row['Attendee_Meta.ATT_email'];
31
-        }
32
-        if (empty($email_address)) {
33
-            return '';
34
-        }
35
-        $avatar = get_avatar_url($email_address);
36
-        return $avatar ? $avatar : '';
37
-    }
20
+	/**
21
+	 * @param array                  $wpdb_row
22
+	 * @param WP_REST_Request        $request
23
+	 * @param AttendeeControllerBase $controller
24
+	 * @since 4.9.66.p
25
+	 * @return string
26
+	 */
27
+	public function userAvatar(array $wpdb_row, WP_REST_Request $request, AttendeeControllerBase $controller)
28
+	{
29
+		if (is_array($wpdb_row) && isset($wpdb_row['Attendee_Meta.ATT_email'])) {
30
+			$email_address = $wpdb_row['Attendee_Meta.ATT_email'];
31
+		}
32
+		if (empty($email_address)) {
33
+			return '';
34
+		}
35
+		$avatar = get_avatar_url($email_address);
36
+		return $avatar ? $avatar : '';
37
+	}
38 38
 
39 39
 
40
-    /**
41
-     * Provides an array for all the calculations possible that outlines a json schema for those calculations.
42
-     * Array is indexed by calculation (snake case) and value is the schema for that calculation.
43
-     *
44
-     * @since $VID:$
45
-     * @return array
46
-     */
47
-    public function schemaForCalculations()
48
-    {
49
-        return array(
50
-            'user_avatar' => array(
51
-                'description' => esc_html__(
52
-                    'The avatar url for the attendee (if available).',
53
-                    'event_espresso'
54
-                ),
55
-                'type'        => 'string',
56
-            ),
57
-        );
58
-    }
40
+	/**
41
+	 * Provides an array for all the calculations possible that outlines a json schema for those calculations.
42
+	 * Array is indexed by calculation (snake case) and value is the schema for that calculation.
43
+	 *
44
+	 * @since $VID:$
45
+	 * @return array
46
+	 */
47
+	public function schemaForCalculations()
48
+	{
49
+		return array(
50
+			'user_avatar' => array(
51
+				'description' => esc_html__(
52
+					'The avatar url for the attendee (if available).',
53
+					'event_espresso'
54
+				),
55
+				'type'        => 'string',
56
+			),
57
+		);
58
+	}
59 59
 }
Please login to merge, or discard this patch.
core/libraries/rest_api/calculations/Base.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -23,7 +23,7 @@  discard block
 block discarded – undo
23 23
      */
24 24
     protected function verifyCurrentUserCan($required_permission, $attempted_calculation)
25 25
     {
26
-        if (! current_user_can($required_permission)) {
26
+        if ( ! current_user_can($required_permission)) {
27 27
             throw new RestException(
28 28
                 'permission_denied',
29 29
                 sprintf(
@@ -75,6 +75,6 @@  discard block
 block discarded – undo
75 75
     public function schemaForCalculation($calculation_index)
76 76
     {
77 77
         $schema_map = $this->schemaForCalculations();
78
-        return isset($schema_map[ $calculation_index ]) ? $schema_map[ $calculation_index ] : array();
78
+        return isset($schema_map[$calculation_index]) ? $schema_map[$calculation_index] : array();
79 79
     }
80 80
 }
Please login to merge, or discard this patch.
Indentation   +57 added lines, -57 removed lines patch added patch discarded remove patch
@@ -16,65 +16,65 @@
 block discarded – undo
16 16
 class Base
17 17
 {
18 18
 
19
-    /**
20
-     * @param $required_permission
21
-     * @param $attempted_calculation
22
-     * @throws RestException
23
-     */
24
-    protected function verifyCurrentUserCan($required_permission, $attempted_calculation)
25
-    {
26
-        if (! current_user_can($required_permission)) {
27
-            throw new RestException(
28
-                'permission_denied',
29
-                sprintf(
30
-                    __(
31
-                    // @codingStandardsIgnoreStart
32
-                        'Permission denied, you cannot calculate %1$s on %2$s because you do not have the capability "%3$s"',
33
-                        // @codingStandardsIgnoreEnd
34
-                        'event_espresso'
35
-                    ),
36
-                    $attempted_calculation,
37
-                    EEH_Inflector::pluralize_and_lower($this->getResourceName()),
38
-                    $required_permission
39
-                )
40
-            );
41
-        }
42
-    }
19
+	/**
20
+	 * @param $required_permission
21
+	 * @param $attempted_calculation
22
+	 * @throws RestException
23
+	 */
24
+	protected function verifyCurrentUserCan($required_permission, $attempted_calculation)
25
+	{
26
+		if (! current_user_can($required_permission)) {
27
+			throw new RestException(
28
+				'permission_denied',
29
+				sprintf(
30
+					__(
31
+					// @codingStandardsIgnoreStart
32
+						'Permission denied, you cannot calculate %1$s on %2$s because you do not have the capability "%3$s"',
33
+						// @codingStandardsIgnoreEnd
34
+						'event_espresso'
35
+					),
36
+					$attempted_calculation,
37
+					EEH_Inflector::pluralize_and_lower($this->getResourceName()),
38
+					$required_permission
39
+				)
40
+			);
41
+		}
42
+	}
43 43
 
44 44
 
45
-    /**
46
-     * Gets the name of the resource of the called class
47
-     *
48
-     * @return string
49
-     */
50
-    public function getResourceName()
51
-    {
52
-        return substr(__CLASS__, strrpos(__CLASS__, '\\') + 1);
53
-    }
45
+	/**
46
+	 * Gets the name of the resource of the called class
47
+	 *
48
+	 * @return string
49
+	 */
50
+	public function getResourceName()
51
+	{
52
+		return substr(__CLASS__, strrpos(__CLASS__, '\\') + 1);
53
+	}
54 54
 
55
-    /**
56
-     * Returns an array to be used for the schema for the calculated fields.
57
-     * @since $VID:$
58
-     * @return array keys are calculated field names (eg "optimum_sales_at_start") values are arrays {
59
-     * @type string $description
60
-     * @type string $type, eg "string", "int", "boolean", "object", "array", etc
61
-     * }
62
-     */
63
-    public function schemaForCalculations()
64
-    {
65
-        return array();
66
-    }
55
+	/**
56
+	 * Returns an array to be used for the schema for the calculated fields.
57
+	 * @since $VID:$
58
+	 * @return array keys are calculated field names (eg "optimum_sales_at_start") values are arrays {
59
+	 * @type string $description
60
+	 * @type string $type, eg "string", "int", "boolean", "object", "array", etc
61
+	 * }
62
+	 */
63
+	public function schemaForCalculations()
64
+	{
65
+		return array();
66
+	}
67 67
 
68
-    /**
69
-     * Returns the json schema for the given calculation index.
70
-     *
71
-     * @since $VID:$
72
-     * @param $calculation_index
73
-     * @return array
74
-     */
75
-    public function schemaForCalculation($calculation_index)
76
-    {
77
-        $schema_map = $this->schemaForCalculations();
78
-        return isset($schema_map[ $calculation_index ]) ? $schema_map[ $calculation_index ] : array();
79
-    }
68
+	/**
69
+	 * Returns the json schema for the given calculation index.
70
+	 *
71
+	 * @since $VID:$
72
+	 * @param $calculation_index
73
+	 * @return array
74
+	 */
75
+	public function schemaForCalculation($calculation_index)
76
+	{
77
+		$schema_map = $this->schemaForCalculations();
78
+		return isset($schema_map[ $calculation_index ]) ? $schema_map[ $calculation_index ] : array();
79
+	}
80 80
 }
Please login to merge, or discard this patch.
core/libraries/rest_api/calculations/Event.php 2 patches
Indentation   +560 added lines, -560 removed lines patch added patch discarded remove patch
@@ -26,564 +26,564 @@
 block discarded – undo
26 26
  */
27 27
 class Event extends EventCalculationBase
28 28
 {
29
-    /**
30
-     * @var EEM_Event
31
-     */
32
-    protected $event_model;
33
-
34
-    /**
35
-     * @var EEM_Registration
36
-     */
37
-    protected $registration_model;
38
-    public function __construct(EEM_Event $event_model, EEM_Registration $registration_model)
39
-    {
40
-        $this->event_model = $event_model;
41
-        $this->registration_model = $registration_model;
42
-    }
43
-
44
-    /**
45
-     * Calculates the total spaces on the event (not subtracting sales, but taking
46
-     * sales into account; so this is the optimum sales that CAN still be achieved)
47
-     * See EE_Event::total_available_spaces( true );
48
-     *
49
-     * @param array               $wpdb_row
50
-     * @param WP_REST_Request     $request
51
-     * @param EventControllerBase $controller
52
-     * @return int
53
-     * @throws EE_Error
54
-     * @throws DomainException
55
-     * @throws InvalidDataTypeException
56
-     * @throws InvalidInterfaceException
57
-     * @throws UnexpectedEntityException
58
-     * @throws InvalidArgumentException
59
-     */
60
-    public function optimumSalesAtStart($wpdb_row, $request, $controller)
61
-    {
62
-        $event_obj = null;
63
-        if (Event::wpdbRowHasEventId($wpdb_row)) {
64
-            $event_obj = $this->event_model->get_one_by_ID($wpdb_row['Event_CPT.ID']);
65
-        }
66
-        if ($event_obj instanceof EE_Event) {
67
-            return $event_obj->total_available_spaces();
68
-        }
69
-        throw new EE_Error(
70
-            sprintf(
71
-                __(
72
-                // @codingStandardsIgnoreStart
73
-                    'Cannot calculate optimum_sales_at_start because the event with ID %1$s (from database row %2$s) was not found',
74
-                    // @codingStandardsIgnoreEnd
75
-                    'event_espresso'
76
-                ),
77
-                $wpdb_row['Event_CPT.ID'],
78
-                print_r($wpdb_row, true)
79
-            )
80
-        );
81
-    }
82
-
83
-
84
-    /**
85
-     * Calculates the total spaces on the event (ignoring all sales; so this is the optimum
86
-     * sales that COULD have been achieved)
87
-     * See EE_Event::total_available_spaces( true );
88
-     *
89
-     * @param array               $wpdb_row
90
-     * @param WP_REST_Request     $request
91
-     * @param EventControllerBase $controller
92
-     * @return int
93
-     * @throws DomainException
94
-     * @throws EE_Error
95
-     * @throws InvalidArgumentException
96
-     * @throws InvalidDataTypeException
97
-     * @throws InvalidInterfaceException
98
-     * @throws UnexpectedEntityException
99
-     */
100
-    public function optimumSalesNow($wpdb_row, $request, $controller)
101
-    {
102
-        $event_obj = null;
103
-        if (Event::wpdbRowHasEventId($wpdb_row)) {
104
-            $event_obj = $this->event_model->get_one_by_ID($wpdb_row['Event_CPT.ID']);
105
-        }
106
-        if ($event_obj instanceof EE_Event) {
107
-            return $event_obj->total_available_spaces(true);
108
-        }
109
-        throw new EE_Error(
110
-            sprintf(
111
-                __(
112
-                // @codingStandardsIgnoreStart
113
-                    'Cannot calculate optimum_sales_now because the event with ID %1$s (from database row %2$s) was not found',
114
-                    // @codingStandardsIgnoreEnd
115
-                    'event_espresso'
116
-                ),
117
-                $wpdb_row['Event_CPT.ID'],
118
-                print_r($wpdb_row, true)
119
-            )
120
-        );
121
-    }
122
-
123
-
124
-    /**
125
-     * Like optimum_sales_now, but minus total sales so far.
126
-     * See EE_Event::spaces_remaining_for_sale( true );
127
-     *
128
-     * @param array               $wpdb_row
129
-     * @param WP_REST_Request     $request
130
-     * @param EventControllerBase $controller
131
-     * @return int
132
-     * @throws DomainException
133
-     * @throws EE_Error
134
-     * @throws InvalidArgumentException
135
-     * @throws InvalidDataTypeException
136
-     * @throws InvalidInterfaceException
137
-     * @throws UnexpectedEntityException
138
-     */
139
-    public function spacesRemaining($wpdb_row, $request, $controller)
140
-    {
141
-        $event_obj = null;
142
-        if (Event::wpdbRowHasEventId($wpdb_row)) {
143
-            $event_obj = $this->event_model->get_one_by_ID($wpdb_row['Event_CPT.ID']);
144
-        }
145
-        if ($event_obj instanceof EE_Event) {
146
-            return $event_obj->spaces_remaining_for_sale();
147
-        }
148
-        throw new EE_Error(
149
-            sprintf(
150
-                __(
151
-                // @codingStandardsIgnoreStart
152
-                    'Cannot calculate spaces_remaining because the event with ID %1$s (from database row %2$s) was not found',
153
-                    // @codingStandardsIgnoreEnd
154
-                    'event_espresso'
155
-                ),
156
-                $wpdb_row['Event_CPT.ID'],
157
-                print_r($wpdb_row, true)
158
-            )
159
-        );
160
-    }
161
-
162
-
163
-    /**
164
-     * Counts the number of approved registrations for this event (regardless
165
-     * of how many datetimes each registrations' ticket purchase is for)
166
-     *
167
-     * @param array               $wpdb_row
168
-     * @param WP_REST_Request     $request
169
-     * @param EventControllerBase $controller
170
-     * @return int
171
-     * @throws EE_Error
172
-     * @throws InvalidArgumentException
173
-     * @throws InvalidDataTypeException
174
-     * @throws InvalidInterfaceException
175
-     */
176
-    public function spotsTaken($wpdb_row, $request, $controller)
177
-    {
178
-        if (! Event::wpdbRowHasEventId($wpdb_row)) {
179
-            throw new EE_Error(
180
-                sprintf(
181
-                    __(
182
-                    // @codingStandardsIgnoreStart
183
-                        'Cannot calculate spots_taken because the database row %1$s does not have a valid entry for "Event_CPT.ID"',
184
-                        // @codingStandardsIgnoreEnd
185
-                        'event_espresso'
186
-                    ),
187
-                    print_r($wpdb_row, true)
188
-                )
189
-            );
190
-        }
191
-        return $this->registration_model->count(
192
-            array(
193
-                array(
194
-                    'EVT_ID' => $wpdb_row['Event_CPT.ID'],
195
-                    'STS_ID' => EEM_Registration::status_id_approved,
196
-                ),
197
-            ),
198
-            'REG_ID',
199
-            true
200
-        );
201
-    }
202
-
203
-
204
-    /**
205
-     * Counts the number of pending-payment registrations for this event (regardless
206
-     * of how many datetimes each registrations' ticket purchase is for)
207
-     *
208
-     * @param array               $wpdb_row
209
-     * @param WP_REST_Request     $request
210
-     * @param EventControllerBase $controller
211
-     * @return int
212
-     * @throws EE_Error
213
-     * @throws InvalidArgumentException
214
-     * @throws InvalidDataTypeException
215
-     * @throws InvalidInterfaceException
216
-     * @throws RestException
217
-     */
218
-    public function spotsTakenPendingPayment($wpdb_row, $request, $controller)
219
-    {
220
-        if (! Event::wpdbRowHasEventId($wpdb_row)) {
221
-            throw new EE_Error(
222
-                sprintf(
223
-                    __(
224
-                    // @codingStandardsIgnoreStart
225
-                        'Cannot calculate spots_taken_pending_payment because the database row %1$s does not have an entry for "Event_CPT.ID"',
226
-                        // @codingStandardsIgnoreEnd
227
-                        'event_espresso'
228
-                    ),
229
-                    print_r($wpdb_row, true)
230
-                )
231
-            );
232
-        }
233
-        $this->verifyCurrentUserCan('ee_read_registrations', 'spots_taken_pending_payment');
234
-        return $this->registration_model->count(
235
-            array(
236
-                array(
237
-                    'EVT_ID' => $wpdb_row['Event_CPT.ID'],
238
-                    'STS_ID' => EEM_Registration::status_id_pending_payment,
239
-                ),
240
-            ),
241
-            'REG_ID',
242
-            true
243
-        );
244
-    }
245
-
246
-
247
-    /**
248
-     * Counts all the registrations who have checked into one of this events' datetimes
249
-     * See EE_Event::total_available_spaces( false );
250
-     *
251
-     * @param array               $wpdb_row
252
-     * @param WP_REST_Request     $request
253
-     * @param EventControllerBase $controller
254
-     * @return int|null if permission denied
255
-     * @throws EE_Error
256
-     * @throws InvalidArgumentException
257
-     * @throws InvalidDataTypeException
258
-     * @throws InvalidInterfaceException
259
-     * @throws RestException
260
-     */
261
-    public function registrationsCheckedInCount($wpdb_row, $request, $controller)
262
-    {
263
-        if (! Event::wpdbRowHasEventId($wpdb_row)) {
264
-            throw new EE_Error(
265
-                sprintf(
266
-                    __(
267
-                    // @codingStandardsIgnoreStart
268
-                        'Cannot calculate registrations_checked_in_count because the database row %1$s does not have an entry for "Event_CPT.ID"',
269
-                        // @codingStandardsIgnoreEnd
270
-                        'event_espresso'
271
-                    ),
272
-                    print_r($wpdb_row, true)
273
-                )
274
-            );
275
-        }
276
-        $this->verifyCurrentUserCan('ee_read_checkins', 'registrations_checked_in_count');
277
-        return $this->registration_model->count_registrations_checked_into_event($wpdb_row['Event_CPT.ID'], true);
278
-    }
279
-
280
-
281
-    /**
282
-     * Counts all the registrations who have checked out of one of this events' datetimes
283
-     * See EE_Event::total_available_spaces( false );
284
-     *
285
-     * @param array               $wpdb_row
286
-     * @param WP_REST_Request     $request
287
-     * @param EventControllerBase $controller
288
-     * @return int
289
-     * @throws EE_Error
290
-     * @throws InvalidArgumentException
291
-     * @throws InvalidDataTypeException
292
-     * @throws InvalidInterfaceException
293
-     * @throws RestException
294
-     */
295
-    public function registrationsCheckedOutCount($wpdb_row, $request, $controller)
296
-    {
297
-        if (! Event::wpdbRowHasEventId($wpdb_row)) {
298
-            throw new EE_Error(
299
-                sprintf(
300
-                    __(
301
-                    // @codingStandardsIgnoreStart
302
-                        'Cannot calculate registrations_checked_out_count because the database row %1$s does not have an entry for "Event_CPT.ID"',
303
-                        // @codingStandardsIgnoreEnd
304
-                        'event_espresso'
305
-                    ),
306
-                    print_r($wpdb_row, true)
307
-                )
308
-            );
309
-        }
310
-        $this->verifyCurrentUserCan('ee_read_checkins', 'registrations_checked_out_count');
311
-        return $this->registration_model->count_registrations_checked_into_event($wpdb_row['Event_CPT.ID'], false);
312
-    }
313
-
314
-
315
-    /**
316
-     * Gets the thumbnail image
317
-     *
318
-     * @param array               $wpdb_row
319
-     * @param WP_REST_Request     $request
320
-     * @param EventControllerBase $controller
321
-     * @return array
322
-     * @throws EE_Error
323
-     */
324
-    public function imageThumbnail($wpdb_row, $request, $controller)
325
-    {
326
-        return self::calculateImageData($wpdb_row, 'thumbnail');
327
-    }
328
-
329
-
330
-    /**
331
-     * Gets the medium image
332
-     *
333
-     * @param array               $wpdb_row
334
-     * @param WP_REST_Request     $request
335
-     * @param EventControllerBase $controller
336
-     * @return array
337
-     * @throws EE_Error
338
-     */
339
-    public function imageMedium($wpdb_row, $request, $controller)
340
-    {
341
-        return self::calculateImageData($wpdb_row, 'medium');
342
-    }
343
-
344
-
345
-    /**
346
-     * Gets the medium-large image
347
-     *
348
-     * @param array               $wpdb_row
349
-     * @param WP_REST_Request     $request
350
-     * @param EventControllerBase $controller
351
-     * @return array
352
-     * @throws EE_Error
353
-     */
354
-    public function imageMediumLarge($wpdb_row, $request, $controller)
355
-    {
356
-        return self::calculateImageData($wpdb_row, 'medium_large');
357
-    }
358
-
359
-
360
-    /**
361
-     * Gets the large image
362
-     *
363
-     * @param array               $wpdb_row
364
-     * @param WP_REST_Request     $request
365
-     * @param EventControllerBase $controller
366
-     * @return array
367
-     * @throws EE_Error
368
-     */
369
-    public function imageLarge($wpdb_row, $request, $controller)
370
-    {
371
-        return self::calculateImageData($wpdb_row, 'large');
372
-    }
373
-
374
-
375
-    /**
376
-     * Gets the post-thumbnail image
377
-     *
378
-     * @param array               $wpdb_row
379
-     * @param WP_REST_Request     $request
380
-     * @param EventControllerBase $controller
381
-     * @return array
382
-     * @throws EE_Error
383
-     */
384
-    public function imagePostThumbnail($wpdb_row, $request, $controller)
385
-    {
386
-        return self::calculateImageData($wpdb_row, 'post-thumbnail');
387
-    }
388
-
389
-
390
-    /**
391
-     * Gets the full size image
392
-     *
393
-     * @param array               $wpdb_row
394
-     * @param WP_REST_Request     $request
395
-     * @param EventControllerBase $controller
396
-     * @return array
397
-     * @throws EE_Error
398
-     */
399
-    public function imageFull($wpdb_row, $request, $controller)
400
-    {
401
-        return self::calculateImageData($wpdb_row, 'full');
402
-    }
403
-
404
-
405
-    /**
406
-     * Gets image specs and formats them for the display in the API,
407
-     * according to the image size requested
408
-     *
409
-     * @param array  $wpdb_row
410
-     * @param string $image_size one of these: thumbnail, medium, medium_large, large, post-thumbnail, full
411
-     * @return array|false if no such image exists. If array it will have keys 'url', 'width', 'height' and 'original'
412
-     * @throws EE_Error
413
-     */
414
-    protected function calculateImageData($wpdb_row, $image_size)
415
-    {
416
-        if (! Event::wpdbRowHasEventId($wpdb_row)) {
417
-            throw new EE_Error(
418
-                sprintf(
419
-                    __(
420
-                    // @codingStandardsIgnoreStart
421
-                        'Cannot calculate image because the database row %1$s does not have an entry for "Event_CPT.ID"',
422
-                        // @codingStandardsIgnoreEnd
423
-                        'event_espresso'
424
-                    ),
425
-                    print_r($wpdb_row, true)
426
-                )
427
-            );
428
-        }
429
-        $EVT_ID = $wpdb_row['Event_CPT.ID'];
430
-        $attachment_id = get_post_thumbnail_id($EVT_ID);
431
-        $data = wp_get_attachment_image_src($attachment_id, $image_size);
432
-        if (! $data) {
433
-            return null;
434
-        }
435
-        $generated = true;
436
-        if (isset($data[3])) {
437
-            $generated = $data[3];
438
-        }
439
-        return array(
440
-            'url'       => $data[0],
441
-            'width'     => $data[1],
442
-            'height'    => $data[2],
443
-            'generated' => $generated,
444
-        );
445
-    }
446
-
447
-
448
-    /**
449
-     * Returns true if the array of data contains 'Event_CPT.ID'. False otherwise
450
-     *
451
-     * @param array $wpdb_row
452
-     * @return bool
453
-     */
454
-    protected function wpdbRowHasEventId($wpdb_row)
455
-    {
456
-        return (is_array($wpdb_row) && isset($wpdb_row['Event_CPT.ID']) && absint($wpdb_row['Event_CPT.ID']));
457
-    }
458
-
459
-
460
-    /**
461
-     * Provides an array for all the calculations possible that outlines a json schema for those calculations.
462
-     * Array is indexed by calculation (snake case) and value is the schema for that calculation.
463
-     *
464
-     * @since $VID:$
465
-     * @return array
466
-     */
467
-    public function schemaForCalculations()
468
-    {
469
-        $image_object_properties = array(
470
-            'url'       => array(
471
-                'type' => 'string',
472
-            ),
473
-            'width'     => array(
474
-                'type' => 'number',
475
-            ),
476
-            'height'    => array(
477
-                'type' => 'number',
478
-            ),
479
-            'generated' => array(
480
-                'type' => 'boolean',
481
-            ),
482
-        );
483
-        return array(
484
-            'optimum_sales_at_start'          => array(
485
-                'description' => esc_html__(
486
-                    'The total spaces on the event (not subtracting sales, but taking sales into account; so this is the optimum sales that CAN still be achieved.',
487
-                    'event_espresso'
488
-                ),
489
-                'type'        => 'number',
490
-            ),
491
-            'optimum_sales_now'               => array(
492
-                'description' => esc_html__(
493
-                    'The total spaces on the event (ignoring all sales; so this is the optimum sales that could have been achieved.',
494
-                    'event_espresso'
495
-                ),
496
-                'type'        => 'number',
497
-            ),
498
-            'spaces_remaining'                => array(
499
-                'description' => esc_html__(
500
-                    'The optimum_sales_number result, minus total sales so far.',
501
-                    'event_espresso'
502
-                ),
503
-                'type'        => 'number',
504
-            ),
505
-            'spots_taken'                     => array(
506
-                'description' => esc_html__(
507
-                    'The number of approved registrations for this event (regardless of how many datetimes each registration\'s ticket purchase is for)',
508
-                    'event_espresso'
509
-                ),
510
-                'type'        => 'number',
511
-            ),
512
-            'spots_taken_pending_payment'     => array(
513
-                'description' => esc_html__(
514
-                    'The number of pending-payment registrations for this event (regardless of how many datetimes each registration\'s ticket purchase is for)',
515
-                    'event_espresso'
516
-                ),
517
-                'type'        => 'number',
518
-            ),
519
-            'registrations_checked_in_count'  => array(
520
-                'description' => esc_html__(
521
-                    'The count of all the registrations who have checked into one of this event\'s datetimes.',
522
-                    'event_espresso'
523
-                ),
524
-                'type'        => 'number',
525
-            ),
526
-            'registrations_checked_out_count' => array(
527
-                'description' => esc_html__(
528
-                    'The count of all registrations who have checked out of one of this event\'s datetimes.',
529
-                    'event_espresso'
530
-                ),
531
-                'type'        => 'number',
532
-            ),
533
-            'image_thumbnail'                 => array(
534
-                'description'          => esc_html__(
535
-                    'The thumbnail image data.',
536
-                    'event_espresso'
537
-                ),
538
-                'type'                 => 'object',
539
-                'properties'           => $image_object_properties,
540
-                'additionalProperties' => false,
541
-            ),
542
-            'image_medium'                    => array(
543
-                'description'          => esc_html__(
544
-                    'The medium image data.',
545
-                    'event_espresso'
546
-                ),
547
-                'type'                 => 'object',
548
-                'properties'           => $image_object_properties,
549
-                'additionalProperties' => false,
550
-            ),
551
-            'image_medium_large'              => array(
552
-                'description'          => esc_html__(
553
-                    'The medium-large image data.',
554
-                    'event_espresso'
555
-                ),
556
-                'type'                 => 'object',
557
-                'properties'           => $image_object_properties,
558
-                'additionalProperties' => false,
559
-            ),
560
-            'image_large'                     => array(
561
-                'description'          => esc_html__(
562
-                    'The large image data.',
563
-                    'event_espresso'
564
-                ),
565
-                'type'                 => 'object',
566
-                'properties'           => $image_object_properties,
567
-                'additionalProperties' => false,
568
-            ),
569
-            'image_post_thumbnail'            => array(
570
-                'description'          => esc_html__(
571
-                    'The post-thumbnail image data.',
572
-                    'event_espresso'
573
-                ),
574
-                'type'                 => 'object',
575
-                'properties'           => $image_object_properties,
576
-                'additionalProperties' => false,
577
-            ),
578
-            'image_full'                      => array(
579
-                'description'          => esc_html__(
580
-                    'The full size image data',
581
-                    'event_espresso'
582
-                ),
583
-                'type'                 => 'object',
584
-                'properties'           => $image_object_properties,
585
-                'additionalProperties' => false,
586
-            ),
587
-        );
588
-    }
29
+	/**
30
+	 * @var EEM_Event
31
+	 */
32
+	protected $event_model;
33
+
34
+	/**
35
+	 * @var EEM_Registration
36
+	 */
37
+	protected $registration_model;
38
+	public function __construct(EEM_Event $event_model, EEM_Registration $registration_model)
39
+	{
40
+		$this->event_model = $event_model;
41
+		$this->registration_model = $registration_model;
42
+	}
43
+
44
+	/**
45
+	 * Calculates the total spaces on the event (not subtracting sales, but taking
46
+	 * sales into account; so this is the optimum sales that CAN still be achieved)
47
+	 * See EE_Event::total_available_spaces( true );
48
+	 *
49
+	 * @param array               $wpdb_row
50
+	 * @param WP_REST_Request     $request
51
+	 * @param EventControllerBase $controller
52
+	 * @return int
53
+	 * @throws EE_Error
54
+	 * @throws DomainException
55
+	 * @throws InvalidDataTypeException
56
+	 * @throws InvalidInterfaceException
57
+	 * @throws UnexpectedEntityException
58
+	 * @throws InvalidArgumentException
59
+	 */
60
+	public function optimumSalesAtStart($wpdb_row, $request, $controller)
61
+	{
62
+		$event_obj = null;
63
+		if (Event::wpdbRowHasEventId($wpdb_row)) {
64
+			$event_obj = $this->event_model->get_one_by_ID($wpdb_row['Event_CPT.ID']);
65
+		}
66
+		if ($event_obj instanceof EE_Event) {
67
+			return $event_obj->total_available_spaces();
68
+		}
69
+		throw new EE_Error(
70
+			sprintf(
71
+				__(
72
+				// @codingStandardsIgnoreStart
73
+					'Cannot calculate optimum_sales_at_start because the event with ID %1$s (from database row %2$s) was not found',
74
+					// @codingStandardsIgnoreEnd
75
+					'event_espresso'
76
+				),
77
+				$wpdb_row['Event_CPT.ID'],
78
+				print_r($wpdb_row, true)
79
+			)
80
+		);
81
+	}
82
+
83
+
84
+	/**
85
+	 * Calculates the total spaces on the event (ignoring all sales; so this is the optimum
86
+	 * sales that COULD have been achieved)
87
+	 * See EE_Event::total_available_spaces( true );
88
+	 *
89
+	 * @param array               $wpdb_row
90
+	 * @param WP_REST_Request     $request
91
+	 * @param EventControllerBase $controller
92
+	 * @return int
93
+	 * @throws DomainException
94
+	 * @throws EE_Error
95
+	 * @throws InvalidArgumentException
96
+	 * @throws InvalidDataTypeException
97
+	 * @throws InvalidInterfaceException
98
+	 * @throws UnexpectedEntityException
99
+	 */
100
+	public function optimumSalesNow($wpdb_row, $request, $controller)
101
+	{
102
+		$event_obj = null;
103
+		if (Event::wpdbRowHasEventId($wpdb_row)) {
104
+			$event_obj = $this->event_model->get_one_by_ID($wpdb_row['Event_CPT.ID']);
105
+		}
106
+		if ($event_obj instanceof EE_Event) {
107
+			return $event_obj->total_available_spaces(true);
108
+		}
109
+		throw new EE_Error(
110
+			sprintf(
111
+				__(
112
+				// @codingStandardsIgnoreStart
113
+					'Cannot calculate optimum_sales_now because the event with ID %1$s (from database row %2$s) was not found',
114
+					// @codingStandardsIgnoreEnd
115
+					'event_espresso'
116
+				),
117
+				$wpdb_row['Event_CPT.ID'],
118
+				print_r($wpdb_row, true)
119
+			)
120
+		);
121
+	}
122
+
123
+
124
+	/**
125
+	 * Like optimum_sales_now, but minus total sales so far.
126
+	 * See EE_Event::spaces_remaining_for_sale( true );
127
+	 *
128
+	 * @param array               $wpdb_row
129
+	 * @param WP_REST_Request     $request
130
+	 * @param EventControllerBase $controller
131
+	 * @return int
132
+	 * @throws DomainException
133
+	 * @throws EE_Error
134
+	 * @throws InvalidArgumentException
135
+	 * @throws InvalidDataTypeException
136
+	 * @throws InvalidInterfaceException
137
+	 * @throws UnexpectedEntityException
138
+	 */
139
+	public function spacesRemaining($wpdb_row, $request, $controller)
140
+	{
141
+		$event_obj = null;
142
+		if (Event::wpdbRowHasEventId($wpdb_row)) {
143
+			$event_obj = $this->event_model->get_one_by_ID($wpdb_row['Event_CPT.ID']);
144
+		}
145
+		if ($event_obj instanceof EE_Event) {
146
+			return $event_obj->spaces_remaining_for_sale();
147
+		}
148
+		throw new EE_Error(
149
+			sprintf(
150
+				__(
151
+				// @codingStandardsIgnoreStart
152
+					'Cannot calculate spaces_remaining because the event with ID %1$s (from database row %2$s) was not found',
153
+					// @codingStandardsIgnoreEnd
154
+					'event_espresso'
155
+				),
156
+				$wpdb_row['Event_CPT.ID'],
157
+				print_r($wpdb_row, true)
158
+			)
159
+		);
160
+	}
161
+
162
+
163
+	/**
164
+	 * Counts the number of approved registrations for this event (regardless
165
+	 * of how many datetimes each registrations' ticket purchase is for)
166
+	 *
167
+	 * @param array               $wpdb_row
168
+	 * @param WP_REST_Request     $request
169
+	 * @param EventControllerBase $controller
170
+	 * @return int
171
+	 * @throws EE_Error
172
+	 * @throws InvalidArgumentException
173
+	 * @throws InvalidDataTypeException
174
+	 * @throws InvalidInterfaceException
175
+	 */
176
+	public function spotsTaken($wpdb_row, $request, $controller)
177
+	{
178
+		if (! Event::wpdbRowHasEventId($wpdb_row)) {
179
+			throw new EE_Error(
180
+				sprintf(
181
+					__(
182
+					// @codingStandardsIgnoreStart
183
+						'Cannot calculate spots_taken because the database row %1$s does not have a valid entry for "Event_CPT.ID"',
184
+						// @codingStandardsIgnoreEnd
185
+						'event_espresso'
186
+					),
187
+					print_r($wpdb_row, true)
188
+				)
189
+			);
190
+		}
191
+		return $this->registration_model->count(
192
+			array(
193
+				array(
194
+					'EVT_ID' => $wpdb_row['Event_CPT.ID'],
195
+					'STS_ID' => EEM_Registration::status_id_approved,
196
+				),
197
+			),
198
+			'REG_ID',
199
+			true
200
+		);
201
+	}
202
+
203
+
204
+	/**
205
+	 * Counts the number of pending-payment registrations for this event (regardless
206
+	 * of how many datetimes each registrations' ticket purchase is for)
207
+	 *
208
+	 * @param array               $wpdb_row
209
+	 * @param WP_REST_Request     $request
210
+	 * @param EventControllerBase $controller
211
+	 * @return int
212
+	 * @throws EE_Error
213
+	 * @throws InvalidArgumentException
214
+	 * @throws InvalidDataTypeException
215
+	 * @throws InvalidInterfaceException
216
+	 * @throws RestException
217
+	 */
218
+	public function spotsTakenPendingPayment($wpdb_row, $request, $controller)
219
+	{
220
+		if (! Event::wpdbRowHasEventId($wpdb_row)) {
221
+			throw new EE_Error(
222
+				sprintf(
223
+					__(
224
+					// @codingStandardsIgnoreStart
225
+						'Cannot calculate spots_taken_pending_payment because the database row %1$s does not have an entry for "Event_CPT.ID"',
226
+						// @codingStandardsIgnoreEnd
227
+						'event_espresso'
228
+					),
229
+					print_r($wpdb_row, true)
230
+				)
231
+			);
232
+		}
233
+		$this->verifyCurrentUserCan('ee_read_registrations', 'spots_taken_pending_payment');
234
+		return $this->registration_model->count(
235
+			array(
236
+				array(
237
+					'EVT_ID' => $wpdb_row['Event_CPT.ID'],
238
+					'STS_ID' => EEM_Registration::status_id_pending_payment,
239
+				),
240
+			),
241
+			'REG_ID',
242
+			true
243
+		);
244
+	}
245
+
246
+
247
+	/**
248
+	 * Counts all the registrations who have checked into one of this events' datetimes
249
+	 * See EE_Event::total_available_spaces( false );
250
+	 *
251
+	 * @param array               $wpdb_row
252
+	 * @param WP_REST_Request     $request
253
+	 * @param EventControllerBase $controller
254
+	 * @return int|null if permission denied
255
+	 * @throws EE_Error
256
+	 * @throws InvalidArgumentException
257
+	 * @throws InvalidDataTypeException
258
+	 * @throws InvalidInterfaceException
259
+	 * @throws RestException
260
+	 */
261
+	public function registrationsCheckedInCount($wpdb_row, $request, $controller)
262
+	{
263
+		if (! Event::wpdbRowHasEventId($wpdb_row)) {
264
+			throw new EE_Error(
265
+				sprintf(
266
+					__(
267
+					// @codingStandardsIgnoreStart
268
+						'Cannot calculate registrations_checked_in_count because the database row %1$s does not have an entry for "Event_CPT.ID"',
269
+						// @codingStandardsIgnoreEnd
270
+						'event_espresso'
271
+					),
272
+					print_r($wpdb_row, true)
273
+				)
274
+			);
275
+		}
276
+		$this->verifyCurrentUserCan('ee_read_checkins', 'registrations_checked_in_count');
277
+		return $this->registration_model->count_registrations_checked_into_event($wpdb_row['Event_CPT.ID'], true);
278
+	}
279
+
280
+
281
+	/**
282
+	 * Counts all the registrations who have checked out of one of this events' datetimes
283
+	 * See EE_Event::total_available_spaces( false );
284
+	 *
285
+	 * @param array               $wpdb_row
286
+	 * @param WP_REST_Request     $request
287
+	 * @param EventControllerBase $controller
288
+	 * @return int
289
+	 * @throws EE_Error
290
+	 * @throws InvalidArgumentException
291
+	 * @throws InvalidDataTypeException
292
+	 * @throws InvalidInterfaceException
293
+	 * @throws RestException
294
+	 */
295
+	public function registrationsCheckedOutCount($wpdb_row, $request, $controller)
296
+	{
297
+		if (! Event::wpdbRowHasEventId($wpdb_row)) {
298
+			throw new EE_Error(
299
+				sprintf(
300
+					__(
301
+					// @codingStandardsIgnoreStart
302
+						'Cannot calculate registrations_checked_out_count because the database row %1$s does not have an entry for "Event_CPT.ID"',
303
+						// @codingStandardsIgnoreEnd
304
+						'event_espresso'
305
+					),
306
+					print_r($wpdb_row, true)
307
+				)
308
+			);
309
+		}
310
+		$this->verifyCurrentUserCan('ee_read_checkins', 'registrations_checked_out_count');
311
+		return $this->registration_model->count_registrations_checked_into_event($wpdb_row['Event_CPT.ID'], false);
312
+	}
313
+
314
+
315
+	/**
316
+	 * Gets the thumbnail image
317
+	 *
318
+	 * @param array               $wpdb_row
319
+	 * @param WP_REST_Request     $request
320
+	 * @param EventControllerBase $controller
321
+	 * @return array
322
+	 * @throws EE_Error
323
+	 */
324
+	public function imageThumbnail($wpdb_row, $request, $controller)
325
+	{
326
+		return self::calculateImageData($wpdb_row, 'thumbnail');
327
+	}
328
+
329
+
330
+	/**
331
+	 * Gets the medium image
332
+	 *
333
+	 * @param array               $wpdb_row
334
+	 * @param WP_REST_Request     $request
335
+	 * @param EventControllerBase $controller
336
+	 * @return array
337
+	 * @throws EE_Error
338
+	 */
339
+	public function imageMedium($wpdb_row, $request, $controller)
340
+	{
341
+		return self::calculateImageData($wpdb_row, 'medium');
342
+	}
343
+
344
+
345
+	/**
346
+	 * Gets the medium-large image
347
+	 *
348
+	 * @param array               $wpdb_row
349
+	 * @param WP_REST_Request     $request
350
+	 * @param EventControllerBase $controller
351
+	 * @return array
352
+	 * @throws EE_Error
353
+	 */
354
+	public function imageMediumLarge($wpdb_row, $request, $controller)
355
+	{
356
+		return self::calculateImageData($wpdb_row, 'medium_large');
357
+	}
358
+
359
+
360
+	/**
361
+	 * Gets the large image
362
+	 *
363
+	 * @param array               $wpdb_row
364
+	 * @param WP_REST_Request     $request
365
+	 * @param EventControllerBase $controller
366
+	 * @return array
367
+	 * @throws EE_Error
368
+	 */
369
+	public function imageLarge($wpdb_row, $request, $controller)
370
+	{
371
+		return self::calculateImageData($wpdb_row, 'large');
372
+	}
373
+
374
+
375
+	/**
376
+	 * Gets the post-thumbnail image
377
+	 *
378
+	 * @param array               $wpdb_row
379
+	 * @param WP_REST_Request     $request
380
+	 * @param EventControllerBase $controller
381
+	 * @return array
382
+	 * @throws EE_Error
383
+	 */
384
+	public function imagePostThumbnail($wpdb_row, $request, $controller)
385
+	{
386
+		return self::calculateImageData($wpdb_row, 'post-thumbnail');
387
+	}
388
+
389
+
390
+	/**
391
+	 * Gets the full size image
392
+	 *
393
+	 * @param array               $wpdb_row
394
+	 * @param WP_REST_Request     $request
395
+	 * @param EventControllerBase $controller
396
+	 * @return array
397
+	 * @throws EE_Error
398
+	 */
399
+	public function imageFull($wpdb_row, $request, $controller)
400
+	{
401
+		return self::calculateImageData($wpdb_row, 'full');
402
+	}
403
+
404
+
405
+	/**
406
+	 * Gets image specs and formats them for the display in the API,
407
+	 * according to the image size requested
408
+	 *
409
+	 * @param array  $wpdb_row
410
+	 * @param string $image_size one of these: thumbnail, medium, medium_large, large, post-thumbnail, full
411
+	 * @return array|false if no such image exists. If array it will have keys 'url', 'width', 'height' and 'original'
412
+	 * @throws EE_Error
413
+	 */
414
+	protected function calculateImageData($wpdb_row, $image_size)
415
+	{
416
+		if (! Event::wpdbRowHasEventId($wpdb_row)) {
417
+			throw new EE_Error(
418
+				sprintf(
419
+					__(
420
+					// @codingStandardsIgnoreStart
421
+						'Cannot calculate image because the database row %1$s does not have an entry for "Event_CPT.ID"',
422
+						// @codingStandardsIgnoreEnd
423
+						'event_espresso'
424
+					),
425
+					print_r($wpdb_row, true)
426
+				)
427
+			);
428
+		}
429
+		$EVT_ID = $wpdb_row['Event_CPT.ID'];
430
+		$attachment_id = get_post_thumbnail_id($EVT_ID);
431
+		$data = wp_get_attachment_image_src($attachment_id, $image_size);
432
+		if (! $data) {
433
+			return null;
434
+		}
435
+		$generated = true;
436
+		if (isset($data[3])) {
437
+			$generated = $data[3];
438
+		}
439
+		return array(
440
+			'url'       => $data[0],
441
+			'width'     => $data[1],
442
+			'height'    => $data[2],
443
+			'generated' => $generated,
444
+		);
445
+	}
446
+
447
+
448
+	/**
449
+	 * Returns true if the array of data contains 'Event_CPT.ID'. False otherwise
450
+	 *
451
+	 * @param array $wpdb_row
452
+	 * @return bool
453
+	 */
454
+	protected function wpdbRowHasEventId($wpdb_row)
455
+	{
456
+		return (is_array($wpdb_row) && isset($wpdb_row['Event_CPT.ID']) && absint($wpdb_row['Event_CPT.ID']));
457
+	}
458
+
459
+
460
+	/**
461
+	 * Provides an array for all the calculations possible that outlines a json schema for those calculations.
462
+	 * Array is indexed by calculation (snake case) and value is the schema for that calculation.
463
+	 *
464
+	 * @since $VID:$
465
+	 * @return array
466
+	 */
467
+	public function schemaForCalculations()
468
+	{
469
+		$image_object_properties = array(
470
+			'url'       => array(
471
+				'type' => 'string',
472
+			),
473
+			'width'     => array(
474
+				'type' => 'number',
475
+			),
476
+			'height'    => array(
477
+				'type' => 'number',
478
+			),
479
+			'generated' => array(
480
+				'type' => 'boolean',
481
+			),
482
+		);
483
+		return array(
484
+			'optimum_sales_at_start'          => array(
485
+				'description' => esc_html__(
486
+					'The total spaces on the event (not subtracting sales, but taking sales into account; so this is the optimum sales that CAN still be achieved.',
487
+					'event_espresso'
488
+				),
489
+				'type'        => 'number',
490
+			),
491
+			'optimum_sales_now'               => array(
492
+				'description' => esc_html__(
493
+					'The total spaces on the event (ignoring all sales; so this is the optimum sales that could have been achieved.',
494
+					'event_espresso'
495
+				),
496
+				'type'        => 'number',
497
+			),
498
+			'spaces_remaining'                => array(
499
+				'description' => esc_html__(
500
+					'The optimum_sales_number result, minus total sales so far.',
501
+					'event_espresso'
502
+				),
503
+				'type'        => 'number',
504
+			),
505
+			'spots_taken'                     => array(
506
+				'description' => esc_html__(
507
+					'The number of approved registrations for this event (regardless of how many datetimes each registration\'s ticket purchase is for)',
508
+					'event_espresso'
509
+				),
510
+				'type'        => 'number',
511
+			),
512
+			'spots_taken_pending_payment'     => array(
513
+				'description' => esc_html__(
514
+					'The number of pending-payment registrations for this event (regardless of how many datetimes each registration\'s ticket purchase is for)',
515
+					'event_espresso'
516
+				),
517
+				'type'        => 'number',
518
+			),
519
+			'registrations_checked_in_count'  => array(
520
+				'description' => esc_html__(
521
+					'The count of all the registrations who have checked into one of this event\'s datetimes.',
522
+					'event_espresso'
523
+				),
524
+				'type'        => 'number',
525
+			),
526
+			'registrations_checked_out_count' => array(
527
+				'description' => esc_html__(
528
+					'The count of all registrations who have checked out of one of this event\'s datetimes.',
529
+					'event_espresso'
530
+				),
531
+				'type'        => 'number',
532
+			),
533
+			'image_thumbnail'                 => array(
534
+				'description'          => esc_html__(
535
+					'The thumbnail image data.',
536
+					'event_espresso'
537
+				),
538
+				'type'                 => 'object',
539
+				'properties'           => $image_object_properties,
540
+				'additionalProperties' => false,
541
+			),
542
+			'image_medium'                    => array(
543
+				'description'          => esc_html__(
544
+					'The medium image data.',
545
+					'event_espresso'
546
+				),
547
+				'type'                 => 'object',
548
+				'properties'           => $image_object_properties,
549
+				'additionalProperties' => false,
550
+			),
551
+			'image_medium_large'              => array(
552
+				'description'          => esc_html__(
553
+					'The medium-large image data.',
554
+					'event_espresso'
555
+				),
556
+				'type'                 => 'object',
557
+				'properties'           => $image_object_properties,
558
+				'additionalProperties' => false,
559
+			),
560
+			'image_large'                     => array(
561
+				'description'          => esc_html__(
562
+					'The large image data.',
563
+					'event_espresso'
564
+				),
565
+				'type'                 => 'object',
566
+				'properties'           => $image_object_properties,
567
+				'additionalProperties' => false,
568
+			),
569
+			'image_post_thumbnail'            => array(
570
+				'description'          => esc_html__(
571
+					'The post-thumbnail image data.',
572
+					'event_espresso'
573
+				),
574
+				'type'                 => 'object',
575
+				'properties'           => $image_object_properties,
576
+				'additionalProperties' => false,
577
+			),
578
+			'image_full'                      => array(
579
+				'description'          => esc_html__(
580
+					'The full size image data',
581
+					'event_espresso'
582
+				),
583
+				'type'                 => 'object',
584
+				'properties'           => $image_object_properties,
585
+				'additionalProperties' => false,
586
+			),
587
+		);
588
+	}
589 589
 }
Please login to merge, or discard this patch.
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -175,7 +175,7 @@  discard block
 block discarded – undo
175 175
      */
176 176
     public function spotsTaken($wpdb_row, $request, $controller)
177 177
     {
178
-        if (! Event::wpdbRowHasEventId($wpdb_row)) {
178
+        if ( ! Event::wpdbRowHasEventId($wpdb_row)) {
179 179
             throw new EE_Error(
180 180
                 sprintf(
181 181
                     __(
@@ -217,7 +217,7 @@  discard block
 block discarded – undo
217 217
      */
218 218
     public function spotsTakenPendingPayment($wpdb_row, $request, $controller)
219 219
     {
220
-        if (! Event::wpdbRowHasEventId($wpdb_row)) {
220
+        if ( ! Event::wpdbRowHasEventId($wpdb_row)) {
221 221
             throw new EE_Error(
222 222
                 sprintf(
223 223
                     __(
@@ -260,7 +260,7 @@  discard block
 block discarded – undo
260 260
      */
261 261
     public function registrationsCheckedInCount($wpdb_row, $request, $controller)
262 262
     {
263
-        if (! Event::wpdbRowHasEventId($wpdb_row)) {
263
+        if ( ! Event::wpdbRowHasEventId($wpdb_row)) {
264 264
             throw new EE_Error(
265 265
                 sprintf(
266 266
                     __(
@@ -294,7 +294,7 @@  discard block
 block discarded – undo
294 294
      */
295 295
     public function registrationsCheckedOutCount($wpdb_row, $request, $controller)
296 296
     {
297
-        if (! Event::wpdbRowHasEventId($wpdb_row)) {
297
+        if ( ! Event::wpdbRowHasEventId($wpdb_row)) {
298 298
             throw new EE_Error(
299 299
                 sprintf(
300 300
                     __(
@@ -413,7 +413,7 @@  discard block
 block discarded – undo
413 413
      */
414 414
     protected function calculateImageData($wpdb_row, $image_size)
415 415
     {
416
-        if (! Event::wpdbRowHasEventId($wpdb_row)) {
416
+        if ( ! Event::wpdbRowHasEventId($wpdb_row)) {
417 417
             throw new EE_Error(
418 418
                 sprintf(
419 419
                     __(
@@ -429,7 +429,7 @@  discard block
 block discarded – undo
429 429
         $EVT_ID = $wpdb_row['Event_CPT.ID'];
430 430
         $attachment_id = get_post_thumbnail_id($EVT_ID);
431 431
         $data = wp_get_attachment_image_src($attachment_id, $image_size);
432
-        if (! $data) {
432
+        if ( ! $data) {
433 433
             return null;
434 434
         }
435 435
         $generated = true;
Please login to merge, or discard this patch.