Completed
Branch master (465a38)
by
unknown
27:45 queued 22:40
created
core/services/assets/AssetManager.php 1 patch
Indentation   +323 added lines, -323 removed lines patch added patch discarded remove patch
@@ -23,332 +23,332 @@
 block discarded – undo
23 23
 abstract class AssetManager implements AssetManagerInterface
24 24
 {
25 25
 
26
-    /**
27
-     * @var AssetCollection|Asset[] $assets
28
-     */
29
-    protected $assets;
30
-
31
-    /**
32
-     * @var DomainInterface
33
-     */
34
-    protected $domain;
35
-
36
-    /**
37
-     * @var Registry $registry
38
-     */
39
-    protected $registry;
40
-
41
-
42
-    /**
43
-     * AssetRegister constructor.
44
-     *
45
-     * @param DomainInterface $domain
46
-     * @param AssetCollection $assets
47
-     * @param Registry        $registry
48
-     */
49
-    public function __construct(DomainInterface $domain, AssetCollection $assets, Registry $registry)
50
-    {
51
-        $this->domain = $domain;
52
-        $this->assets = $assets;
53
-        $this->registry = $registry;
54
-        $this->registry->addAssetCollection($assets);
55
-        add_action('wp_enqueue_scripts', array($this, 'addAssets'), 2);
56
-        add_action('admin_enqueue_scripts', array($this, 'addAssets'), 2);
57
-    }
58
-
59
-
60
-    /**
61
-     * @return AssetCollection
62
-     */
63
-    public function getAssets()
64
-    {
65
-        return $this->assets;
66
-    }
67
-
68
-
69
-    /**
70
-     * @since 4.9.71.p
71
-     * @return string
72
-     */
73
-    public function assetNamespace()
74
-    {
75
-        return $this->domain->assetNamespace();
76
-    }
77
-
78
-
79
-    /**
80
-     * @param string $handle
81
-     * @param string $source
82
-     * @param array  $dependencies
83
-     * @param bool   $load_in_footer
84
-     * @param string $version
85
-     * @return JavascriptAsset
86
-     * @throws DuplicateCollectionIdentifierException
87
-     * @throws InvalidDataTypeException
88
-     * @throws InvalidEntityException
89
-     * @throws DomainException
90
-     * @since 4.9.62.p
91
-     */
92
-    public function addJavascript(
93
-        $handle,
94
-        $source,
95
-        array $dependencies = array(),
96
-        $load_in_footer = true,
97
-        $version = ''
98
-    ) {
99
-        $asset = new JavascriptAsset(
100
-            $handle,
101
-            $source,
102
-            array_unique($dependencies),
103
-            $load_in_footer,
104
-            $this->domain,
105
-            $version
106
-        );
107
-        $this->assets->add($asset, $handle);
108
-        return $asset;
109
-    }
110
-
111
-
112
-    /**
113
-     * Used to register a javascript asset where everything is dynamically derived from the given handle.
114
-     *
115
-     * @param string       $handle
116
-     * @param string|array $extra_dependencies
117
-     * @return JavascriptAsset
118
-     * @throws DuplicateCollectionIdentifierException
119
-     * @throws InvalidDataTypeException
120
-     * @throws InvalidEntityException
121
-     * @throws DomainException
122
-     */
123
-    public function addJs($handle, $extra_dependencies = [])
124
-    {
125
-        $details = $this->getAssetDetails(
126
-            Asset::TYPE_JS,
127
-            $handle,
128
-            $extra_dependencies
129
-        );
130
-        $source = $this->registry->getJsUrl($this->domain->assetNamespace(), $handle);
131
-        return $this->addJavascript(
132
-            $handle,
133
-            $source,
134
-            $details['dependencies'],
135
-            true,
136
-            $details['version']
137
-        );
138
-    }
139
-
140
-
141
-    /**
142
-     * @param string $handle
143
-     * @param array  $dependencies
144
-     * @param bool   $load_in_footer
145
-     * @param string $version
146
-     * @return JavascriptAsset
147
-     * @throws DomainException
148
-     * @throws DuplicateCollectionIdentifierException
149
-     * @throws InvalidDataTypeException
150
-     * @throws InvalidEntityException
151
-     * @since 4.9.71.p
152
-     */
153
-    public function addVendorJavascript(
154
-        $handle,
155
-        array $dependencies = array(),
156
-        $load_in_footer = true,
157
-        $version = ''
158
-    ) {
159
-        $dev_suffix = wp_scripts_get_suffix('dev');
160
-        $vendor_path = $this->domain->pluginUrl() . 'assets/vendor/';
161
-        return $this->addJavascript(
162
-            $handle,
163
-            "{$vendor_path}{$handle}{$dev_suffix}". Asset::EXT_JS,
164
-            $dependencies,
165
-            $load_in_footer,
166
-            $version
167
-        );
168
-    }
169
-
170
-
171
-    /**
172
-     * @param string $handle
173
-     * @param string $source
174
-     * @param array  $dependencies
175
-     * @param string $media
176
-     * @param string $version
177
-     * @return StylesheetAsset
178
-     * @throws DomainException
179
-     * @throws DuplicateCollectionIdentifierException
180
-     * @throws InvalidDataTypeException
181
-     * @throws InvalidEntityException
182
-     * @since 4.9.62.p
183
-     */
184
-    public function addStylesheet(
185
-        $handle,
186
-        $source,
187
-        array $dependencies = array(),
188
-        $media = 'all',
189
-        $version = ''
190
-    ) {
191
-        $asset = new StylesheetAsset(
192
-            $handle,
193
-            $source,
194
-            array_unique($dependencies),
195
-            $this->domain,
196
-            $media,
197
-            $version
198
-        );
199
-        $this->assets->add($asset, $handle);
200
-        return $asset;
201
-    }
202
-
203
-
204
-    /**
205
-     * Used to register a css asset where everything is dynamically derived from the given handle.
206
-     *
207
-     * @param string       $handle
208
-     * @param string|array $extra_dependencies
209
-     * @return StylesheetAsset
210
-     * @throws DuplicateCollectionIdentifierException
211
-     * @throws InvalidDataTypeException
212
-     * @throws InvalidEntityException
213
-     * @throws DomainException
214
-     */
215
-    public function addCss($handle, $extra_dependencies = [])
216
-    {
217
-        $details = $this->getAssetDetails(
218
-            Asset::TYPE_CSS,
219
-            $handle,
220
-            $extra_dependencies
221
-        );
222
-        return $this->addStylesheet(
223
-            $handle,
224
-            $this->registry->getCssUrl($this->domain->assetNamespace(), $handle),
225
-            $details['dependencies'],
226
-            'all',
227
-            $details['version']
228
-        );
229
-    }
230
-
231
-
232
-    /**
233
-     * @param string $handle
234
-     * @return bool
235
-     * @since 4.9.62.p
236
-     */
237
-    public function enqueueAsset($handle)
238
-    {
239
-        if ($this->assets->has($handle)) {
240
-            /** @var Asset $asset */
241
-            $asset = $this->assets->get($handle);
242
-            if ($asset instanceof BrowserAsset && $asset->isRegistered()) {
243
-                $asset->enqueueAsset();
244
-                return true;
245
-            }
246
-        }
247
-        return false;
248
-    }
249
-
250
-
251
-    /**
252
-     * @return  void
253
-     * @since   5.0.0.p
254
-     */
255
-    public function enqueueBrowserAssets()
256
-    {
257
-        foreach ($this->assets as $asset) {
258
-            if ($asset instanceof BrowserAsset && $asset->isRegistered()) {
259
-                $asset->enqueueAsset();
260
-            }
261
-        }
262
-    }
263
-
264
-
265
-    /**
266
-     * @param string $asset_type
267
-     * @param string $handle
268
-     * @param array  $extra_dependencies
269
-     * @return array
270
-     * @since 4.10.2.p
271
-     */
272
-    private function getAssetDetails($asset_type, $handle, $extra_dependencies = [])
273
-    {
274
-        $getAssetDetails = '';
275
-        switch ($asset_type) {
276
-            case Asset::TYPE_JS :
277
-                $getAssetDetails = 'getJsAssetDetails';
278
-                break;
279
-            case Asset::TYPE_CSS :
280
-                $getAssetDetails = 'getCssAssetDetails';
281
-                break;
282
-        }
283
-        if ($getAssetDetails === '') {
284
-            return ['dependencies' => [], 'version' => ''];
285
-        }
286
-        $details = $this->registry->$getAssetDetails(
287
-            $this->domain->assetNamespace(),
288
-            $handle
289
-        );
290
-        $details['dependencies'] = isset($details['dependencies'])
291
-            ? $details['dependencies']
292
-            : [];
293
-        $details['version'] = isset($details['version'])
294
-            ? $details['version']
295
-            : '';
296
-        $details['dependencies'] = ! empty($extra_dependencies)
297
-            ? array_merge($details['dependencies'], (array) $extra_dependencies)
298
-            : $details['dependencies'];
299
-        return $details;
300
-
301
-    }
302
-
303
-
304
-    /**
305
-     * @param string $handle
306
-     * @return bool
307
-     * @throws DomainException
308
-     */
309
-    public function verifyAssetIsRegistered($handle)
310
-    {
311
-        if (wp_script_is($handle, 'registered')) {
312
-            return true;
313
-        }
314
-        if (WP_DEBUG) {
315
-            throw new DomainException(
316
-                sprintf(
317
-                    esc_html__(
318
-                        'The "%1$s" script is not registered when it should be!%2$s
26
+	/**
27
+	 * @var AssetCollection|Asset[] $assets
28
+	 */
29
+	protected $assets;
30
+
31
+	/**
32
+	 * @var DomainInterface
33
+	 */
34
+	protected $domain;
35
+
36
+	/**
37
+	 * @var Registry $registry
38
+	 */
39
+	protected $registry;
40
+
41
+
42
+	/**
43
+	 * AssetRegister constructor.
44
+	 *
45
+	 * @param DomainInterface $domain
46
+	 * @param AssetCollection $assets
47
+	 * @param Registry        $registry
48
+	 */
49
+	public function __construct(DomainInterface $domain, AssetCollection $assets, Registry $registry)
50
+	{
51
+		$this->domain = $domain;
52
+		$this->assets = $assets;
53
+		$this->registry = $registry;
54
+		$this->registry->addAssetCollection($assets);
55
+		add_action('wp_enqueue_scripts', array($this, 'addAssets'), 2);
56
+		add_action('admin_enqueue_scripts', array($this, 'addAssets'), 2);
57
+	}
58
+
59
+
60
+	/**
61
+	 * @return AssetCollection
62
+	 */
63
+	public function getAssets()
64
+	{
65
+		return $this->assets;
66
+	}
67
+
68
+
69
+	/**
70
+	 * @since 4.9.71.p
71
+	 * @return string
72
+	 */
73
+	public function assetNamespace()
74
+	{
75
+		return $this->domain->assetNamespace();
76
+	}
77
+
78
+
79
+	/**
80
+	 * @param string $handle
81
+	 * @param string $source
82
+	 * @param array  $dependencies
83
+	 * @param bool   $load_in_footer
84
+	 * @param string $version
85
+	 * @return JavascriptAsset
86
+	 * @throws DuplicateCollectionIdentifierException
87
+	 * @throws InvalidDataTypeException
88
+	 * @throws InvalidEntityException
89
+	 * @throws DomainException
90
+	 * @since 4.9.62.p
91
+	 */
92
+	public function addJavascript(
93
+		$handle,
94
+		$source,
95
+		array $dependencies = array(),
96
+		$load_in_footer = true,
97
+		$version = ''
98
+	) {
99
+		$asset = new JavascriptAsset(
100
+			$handle,
101
+			$source,
102
+			array_unique($dependencies),
103
+			$load_in_footer,
104
+			$this->domain,
105
+			$version
106
+		);
107
+		$this->assets->add($asset, $handle);
108
+		return $asset;
109
+	}
110
+
111
+
112
+	/**
113
+	 * Used to register a javascript asset where everything is dynamically derived from the given handle.
114
+	 *
115
+	 * @param string       $handle
116
+	 * @param string|array $extra_dependencies
117
+	 * @return JavascriptAsset
118
+	 * @throws DuplicateCollectionIdentifierException
119
+	 * @throws InvalidDataTypeException
120
+	 * @throws InvalidEntityException
121
+	 * @throws DomainException
122
+	 */
123
+	public function addJs($handle, $extra_dependencies = [])
124
+	{
125
+		$details = $this->getAssetDetails(
126
+			Asset::TYPE_JS,
127
+			$handle,
128
+			$extra_dependencies
129
+		);
130
+		$source = $this->registry->getJsUrl($this->domain->assetNamespace(), $handle);
131
+		return $this->addJavascript(
132
+			$handle,
133
+			$source,
134
+			$details['dependencies'],
135
+			true,
136
+			$details['version']
137
+		);
138
+	}
139
+
140
+
141
+	/**
142
+	 * @param string $handle
143
+	 * @param array  $dependencies
144
+	 * @param bool   $load_in_footer
145
+	 * @param string $version
146
+	 * @return JavascriptAsset
147
+	 * @throws DomainException
148
+	 * @throws DuplicateCollectionIdentifierException
149
+	 * @throws InvalidDataTypeException
150
+	 * @throws InvalidEntityException
151
+	 * @since 4.9.71.p
152
+	 */
153
+	public function addVendorJavascript(
154
+		$handle,
155
+		array $dependencies = array(),
156
+		$load_in_footer = true,
157
+		$version = ''
158
+	) {
159
+		$dev_suffix = wp_scripts_get_suffix('dev');
160
+		$vendor_path = $this->domain->pluginUrl() . 'assets/vendor/';
161
+		return $this->addJavascript(
162
+			$handle,
163
+			"{$vendor_path}{$handle}{$dev_suffix}". Asset::EXT_JS,
164
+			$dependencies,
165
+			$load_in_footer,
166
+			$version
167
+		);
168
+	}
169
+
170
+
171
+	/**
172
+	 * @param string $handle
173
+	 * @param string $source
174
+	 * @param array  $dependencies
175
+	 * @param string $media
176
+	 * @param string $version
177
+	 * @return StylesheetAsset
178
+	 * @throws DomainException
179
+	 * @throws DuplicateCollectionIdentifierException
180
+	 * @throws InvalidDataTypeException
181
+	 * @throws InvalidEntityException
182
+	 * @since 4.9.62.p
183
+	 */
184
+	public function addStylesheet(
185
+		$handle,
186
+		$source,
187
+		array $dependencies = array(),
188
+		$media = 'all',
189
+		$version = ''
190
+	) {
191
+		$asset = new StylesheetAsset(
192
+			$handle,
193
+			$source,
194
+			array_unique($dependencies),
195
+			$this->domain,
196
+			$media,
197
+			$version
198
+		);
199
+		$this->assets->add($asset, $handle);
200
+		return $asset;
201
+	}
202
+
203
+
204
+	/**
205
+	 * Used to register a css asset where everything is dynamically derived from the given handle.
206
+	 *
207
+	 * @param string       $handle
208
+	 * @param string|array $extra_dependencies
209
+	 * @return StylesheetAsset
210
+	 * @throws DuplicateCollectionIdentifierException
211
+	 * @throws InvalidDataTypeException
212
+	 * @throws InvalidEntityException
213
+	 * @throws DomainException
214
+	 */
215
+	public function addCss($handle, $extra_dependencies = [])
216
+	{
217
+		$details = $this->getAssetDetails(
218
+			Asset::TYPE_CSS,
219
+			$handle,
220
+			$extra_dependencies
221
+		);
222
+		return $this->addStylesheet(
223
+			$handle,
224
+			$this->registry->getCssUrl($this->domain->assetNamespace(), $handle),
225
+			$details['dependencies'],
226
+			'all',
227
+			$details['version']
228
+		);
229
+	}
230
+
231
+
232
+	/**
233
+	 * @param string $handle
234
+	 * @return bool
235
+	 * @since 4.9.62.p
236
+	 */
237
+	public function enqueueAsset($handle)
238
+	{
239
+		if ($this->assets->has($handle)) {
240
+			/** @var Asset $asset */
241
+			$asset = $this->assets->get($handle);
242
+			if ($asset instanceof BrowserAsset && $asset->isRegistered()) {
243
+				$asset->enqueueAsset();
244
+				return true;
245
+			}
246
+		}
247
+		return false;
248
+	}
249
+
250
+
251
+	/**
252
+	 * @return  void
253
+	 * @since   5.0.0.p
254
+	 */
255
+	public function enqueueBrowserAssets()
256
+	{
257
+		foreach ($this->assets as $asset) {
258
+			if ($asset instanceof BrowserAsset && $asset->isRegistered()) {
259
+				$asset->enqueueAsset();
260
+			}
261
+		}
262
+	}
263
+
264
+
265
+	/**
266
+	 * @param string $asset_type
267
+	 * @param string $handle
268
+	 * @param array  $extra_dependencies
269
+	 * @return array
270
+	 * @since 4.10.2.p
271
+	 */
272
+	private function getAssetDetails($asset_type, $handle, $extra_dependencies = [])
273
+	{
274
+		$getAssetDetails = '';
275
+		switch ($asset_type) {
276
+			case Asset::TYPE_JS :
277
+				$getAssetDetails = 'getJsAssetDetails';
278
+				break;
279
+			case Asset::TYPE_CSS :
280
+				$getAssetDetails = 'getCssAssetDetails';
281
+				break;
282
+		}
283
+		if ($getAssetDetails === '') {
284
+			return ['dependencies' => [], 'version' => ''];
285
+		}
286
+		$details = $this->registry->$getAssetDetails(
287
+			$this->domain->assetNamespace(),
288
+			$handle
289
+		);
290
+		$details['dependencies'] = isset($details['dependencies'])
291
+			? $details['dependencies']
292
+			: [];
293
+		$details['version'] = isset($details['version'])
294
+			? $details['version']
295
+			: '';
296
+		$details['dependencies'] = ! empty($extra_dependencies)
297
+			? array_merge($details['dependencies'], (array) $extra_dependencies)
298
+			: $details['dependencies'];
299
+		return $details;
300
+
301
+	}
302
+
303
+
304
+	/**
305
+	 * @param string $handle
306
+	 * @return bool
307
+	 * @throws DomainException
308
+	 */
309
+	public function verifyAssetIsRegistered($handle)
310
+	{
311
+		if (wp_script_is($handle, 'registered')) {
312
+			return true;
313
+		}
314
+		if (WP_DEBUG) {
315
+			throw new DomainException(
316
+				sprintf(
317
+					esc_html__(
318
+						'The "%1$s" script is not registered when it should be!%2$s
319 319
                         Are you running the Barista plugin for development purposes?
320 320
                         If so, then you need to build the appropriate assets for this domain.%2$s
321 321
                         If you are seeing this error on a live website, then you should not have
322 322
                         the WP_DEBUG constant in your wp-config.php file set to "true".
323 323
                         Please contact Event Espresso support for more information.',
324
-                        'event_espresso'
325
-                    ),
326
-                    $handle,
327
-                    '<br />'
328
-                )
329
-            );
330
-        }
331
-        return false;
332
-    }
333
-
334
-
335
-    /**************** deprecated ****************/
336
-
337
-
338
-    /**
339
-     * @return void
340
-     * @deprecated 5.0.0.p
341
-     */
342
-    public function addManifestFile()
343
-    {
344
-    }
345
-
346
-
347
-    /**
348
-     * @return void
349
-     * @deprecated 5.0.0.p
350
-     */
351
-    public function getManifestFile()
352
-    {
353
-    }
324
+						'event_espresso'
325
+					),
326
+					$handle,
327
+					'<br />'
328
+				)
329
+			);
330
+		}
331
+		return false;
332
+	}
333
+
334
+
335
+	/**************** deprecated ****************/
336
+
337
+
338
+	/**
339
+	 * @return void
340
+	 * @deprecated 5.0.0.p
341
+	 */
342
+	public function addManifestFile()
343
+	{
344
+	}
345
+
346
+
347
+	/**
348
+	 * @return void
349
+	 * @deprecated 5.0.0.p
350
+	 */
351
+	public function getManifestFile()
352
+	{
353
+	}
354 354
 }
Please login to merge, or discard this patch.
core/services/helpers/DebugDisplay.php 2 patches
Indentation   +26 added lines, -26 removed lines patch added patch discarded remove patch
@@ -4,34 +4,34 @@
 block discarded – undo
4 4
 
5 5
 trait DebugDisplay
6 6
 {
7
-    /**
8
-     * used for controlling how much data is displayed when debugging
9
-     * threshold is set to 0 by default, but can be set to 1, 2, 3, or 4
10
-     * where higher numbers display more data
11
-     *
12
-     * @var int
13
-     */
14
-    private int $threshold = 0;
7
+	/**
8
+	 * used for controlling how much data is displayed when debugging
9
+	 * threshold is set to 0 by default, but can be set to 1, 2, 3, or 4
10
+	 * where higher numbers display more data
11
+	 *
12
+	 * @var int
13
+	 */
14
+	private int $threshold = 0;
15 15
 
16
-    private array $levels = [
17
-        0 => 'none',
18
-        1 => 'low',
19
-        2 => 'medium',
20
-        3 => 'high',
21
-        4 => 'all'
22
-    ];
16
+	private array $levels = [
17
+		0 => 'none',
18
+		1 => 'low',
19
+		2 => 'medium',
20
+		3 => 'high',
21
+		4 => 'all'
22
+	];
23 23
 
24 24
 
25
-    public function initializeDebugDisplay(int $threshold = 0, ?array $levels = null)
26
-    {
27
-        $this->threshold = defined('WP_DEBUG') && WP_DEBUG ? $threshold: 0;
28
-        $this->levels = $levels ?: $this->levels;
29
-    }
25
+	public function initializeDebugDisplay(int $threshold = 0, ?array $levels = null)
26
+	{
27
+		$this->threshold = defined('WP_DEBUG') && WP_DEBUG ? $threshold: 0;
28
+		$this->levels = $levels ?: $this->levels;
29
+	}
30 30
 
31
-    public function debugLog(string $text, int $level = 1)
32
-    {
33
-        if ($this->threshold && $this->threshold >= $level) {
34
-            error_log($text);
35
-        }
36
-    }
31
+	public function debugLog(string $text, int $level = 1)
32
+	{
33
+		if ($this->threshold && $this->threshold >= $level) {
34
+			error_log($text);
35
+		}
36
+	}
37 37
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -24,7 +24,7 @@
 block discarded – undo
24 24
 
25 25
     public function initializeDebugDisplay(int $threshold = 0, ?array $levels = null)
26 26
     {
27
-        $this->threshold = defined('WP_DEBUG') && WP_DEBUG ? $threshold: 0;
27
+        $this->threshold = defined('WP_DEBUG') && WP_DEBUG ? $threshold : 0;
28 28
         $this->levels = $levels ?: $this->levels;
29 29
     }
30 30
 
Please login to merge, or discard this patch.
core/services/database/TableManager.php 1 patch
Indentation   +239 added lines, -239 removed lines patch added patch discarded remove patch
@@ -16,264 +16,264 @@
 block discarded – undo
16 16
  */
17 17
 class TableManager extends EE_Base
18 18
 {
19
-    private ?TableAnalysis $table_analysis;
19
+	private ?TableAnalysis $table_analysis;
20 20
 
21 21
 
22
-    /**
23
-     * TableManager constructor.
24
-     *
25
-     * @param TableAnalysis $TableAnalysis
26
-     */
27
-    public function __construct(TableAnalysis $TableAnalysis)
28
-    {
29
-        $this->table_analysis = $TableAnalysis;
30
-    }
22
+	/**
23
+	 * TableManager constructor.
24
+	 *
25
+	 * @param TableAnalysis $TableAnalysis
26
+	 */
27
+	public function __construct(TableAnalysis $TableAnalysis)
28
+	{
29
+		$this->table_analysis = $TableAnalysis;
30
+	}
31 31
 
32 32
 
33
-    /**
34
-     * Gets the injected table analyzer, or throws an exception
35
-     *
36
-     * @return TableAnalysis
37
-     * @throws EE_Error
38
-     */
39
-    protected function getTableAnalysis(): ?TableAnalysis
40
-    {
41
-        if ($this->table_analysis instanceof TableAnalysis) {
42
-            return $this->table_analysis;
43
-        } else {
44
-            throw new EE_Error(
45
-                sprintf(
46
-                    esc_html__('Table analysis class on class %1$s is not set properly.', 'event_espresso'),
47
-                    get_class($this)
48
-                )
49
-            );
50
-        }
51
-    }
33
+	/**
34
+	 * Gets the injected table analyzer, or throws an exception
35
+	 *
36
+	 * @return TableAnalysis
37
+	 * @throws EE_Error
38
+	 */
39
+	protected function getTableAnalysis(): ?TableAnalysis
40
+	{
41
+		if ($this->table_analysis instanceof TableAnalysis) {
42
+			return $this->table_analysis;
43
+		} else {
44
+			throw new EE_Error(
45
+				sprintf(
46
+					esc_html__('Table analysis class on class %1$s is not set properly.', 'event_espresso'),
47
+					get_class($this)
48
+				)
49
+			);
50
+		}
51
+	}
52 52
 
53 53
 
54
-    /**
55
-     * @param string $table_name which can optionally start with $wpdb->prefix or not
56
-     * @param string $column_name
57
-     * @param string $column_info
58
-     * @return bool|false|int
59
-     * @throws EE_Error
60
-     */
61
-    public function addColumn(string $table_name, string $column_name, string $column_info = 'INT UNSIGNED NOT NULL')
62
-    {
63
-        if (apply_filters('FHEE__EEH_Activation__add_column_if_it_doesnt_exist__short_circuit', false)) {
64
-            return false;
65
-        }
66
-        global $wpdb;
67
-        $full_table_name = $this->getTableAnalysis()->ensureTableNameHasPrefix($table_name);
68
-        $columns         = $this->getTableColumns($table_name);
69
-        if (! in_array($column_name, $columns)) {
70
-            $alter_query = "ALTER TABLE $full_table_name ADD $column_name $column_info";
71
-            return $wpdb->query($alter_query);
72
-        }
73
-        return true;
74
-    }
54
+	/**
55
+	 * @param string $table_name which can optionally start with $wpdb->prefix or not
56
+	 * @param string $column_name
57
+	 * @param string $column_info
58
+	 * @return bool|false|int
59
+	 * @throws EE_Error
60
+	 */
61
+	public function addColumn(string $table_name, string $column_name, string $column_info = 'INT UNSIGNED NOT NULL')
62
+	{
63
+		if (apply_filters('FHEE__EEH_Activation__add_column_if_it_doesnt_exist__short_circuit', false)) {
64
+			return false;
65
+		}
66
+		global $wpdb;
67
+		$full_table_name = $this->getTableAnalysis()->ensureTableNameHasPrefix($table_name);
68
+		$columns         = $this->getTableColumns($table_name);
69
+		if (! in_array($column_name, $columns)) {
70
+			$alter_query = "ALTER TABLE $full_table_name ADD $column_name $column_info";
71
+			return $wpdb->query($alter_query);
72
+		}
73
+		return true;
74
+	}
75 75
 
76 76
 
77
-    /**
78
-     * Gets the name of all columns on the  table. $table_name can
79
-     * optionally start with $wpdb->prefix or not
80
-     *
81
-     * @param string $table_name
82
-     * @return array
83
-     * @throws EE_Error
84
-     * @global wpdb  $wpdb
85
-     */
86
-    public function getTableColumns(string $table_name): array
87
-    {
88
-        global $wpdb;
89
-        $table_name  = $this->getTableAnalysis()->ensureTableNameHasPrefix($table_name);
90
-        $field_array = [];
91
-        if (! empty($table_name)) {
92
-            $columns = $wpdb->get_results("SHOW COLUMNS FROM $table_name ");
93
-            if ($columns !== false) {
94
-                foreach ($columns as $column) {
95
-                    $field_array[] = $column->Field;
96
-                }
97
-            }
98
-        }
99
-        return $field_array;
100
-    }
77
+	/**
78
+	 * Gets the name of all columns on the  table. $table_name can
79
+	 * optionally start with $wpdb->prefix or not
80
+	 *
81
+	 * @param string $table_name
82
+	 * @return array
83
+	 * @throws EE_Error
84
+	 * @global wpdb  $wpdb
85
+	 */
86
+	public function getTableColumns(string $table_name): array
87
+	{
88
+		global $wpdb;
89
+		$table_name  = $this->getTableAnalysis()->ensureTableNameHasPrefix($table_name);
90
+		$field_array = [];
91
+		if (! empty($table_name)) {
92
+			$columns = $wpdb->get_results("SHOW COLUMNS FROM $table_name ");
93
+			if ($columns !== false) {
94
+				foreach ($columns as $column) {
95
+					$field_array[] = $column->Field;
96
+				}
97
+			}
98
+		}
99
+		return $field_array;
100
+	}
101 101
 
102 102
 
103
-    /**
104
-     * Drops the specified table from the database. $table_name can
105
-     * optionally start with $wpdb->prefix or not
106
-     *
107
-     * @param string $table_name
108
-     * @return bool|int
109
-     * @throws EE_Error
110
-     * @global wpdb  $wpdb
111
-     */
112
-    public function dropTable(string $table_name)
113
-    {
114
-        global $wpdb;
115
-        if ($this->getTableAnalysis()->tableExists($table_name)) {
116
-            $table_name = $this->getTableAnalysis()->ensureTableNameHasPrefix($table_name);
117
-            return $wpdb->query("DROP TABLE IF EXISTS $table_name");
118
-        }
119
-        return 0;
120
-    }
103
+	/**
104
+	 * Drops the specified table from the database. $table_name can
105
+	 * optionally start with $wpdb->prefix or not
106
+	 *
107
+	 * @param string $table_name
108
+	 * @return bool|int
109
+	 * @throws EE_Error
110
+	 * @global wpdb  $wpdb
111
+	 */
112
+	public function dropTable(string $table_name)
113
+	{
114
+		global $wpdb;
115
+		if ($this->getTableAnalysis()->tableExists($table_name)) {
116
+			$table_name = $this->getTableAnalysis()->ensureTableNameHasPrefix($table_name);
117
+			return $wpdb->query("DROP TABLE IF EXISTS $table_name");
118
+		}
119
+		return 0;
120
+	}
121 121
 
122 122
 
123
-    /**
124
-     * Drops all the tables mentioned in a single MYSQL query. Double-checks
125
-     * each table name provided has a wpdb prefix attached, and that it exists.
126
-     * Returns the list actually deleted
127
-     *
128
-     * @param string[] $table_names
129
-     * @return array of table names which we deleted
130
-     * @throws EE_Error
131
-     * @global WPDB    $wpdb
132
-     */
133
-    public function dropTables(array $table_names): array
134
-    {
135
-        $tables_to_delete = [];
136
-        foreach ($table_names as $table_name) {
137
-            $table_name = $this->getTableAnalysis()->ensureTableNameHasPrefix($table_name);
138
-            if ($this->getTableAnalysis()->tableExists($table_name)) {
139
-                $tables_to_delete[ $table_name ] = $table_name;
140
-            }
141
-        }
142
-        if (! empty($tables_to_delete)) {
143
-            global $wpdb;
144
-            // make sure we only have a unique strings in the array.
145
-            $tables_to_delete = array_unique($tables_to_delete);
146
-            $wpdb->query('DROP TABLE ' . implode(', ', $tables_to_delete));
147
-        }
148
-        return $tables_to_delete;
149
-    }
123
+	/**
124
+	 * Drops all the tables mentioned in a single MYSQL query. Double-checks
125
+	 * each table name provided has a wpdb prefix attached, and that it exists.
126
+	 * Returns the list actually deleted
127
+	 *
128
+	 * @param string[] $table_names
129
+	 * @return array of table names which we deleted
130
+	 * @throws EE_Error
131
+	 * @global WPDB    $wpdb
132
+	 */
133
+	public function dropTables(array $table_names): array
134
+	{
135
+		$tables_to_delete = [];
136
+		foreach ($table_names as $table_name) {
137
+			$table_name = $this->getTableAnalysis()->ensureTableNameHasPrefix($table_name);
138
+			if ($this->getTableAnalysis()->tableExists($table_name)) {
139
+				$tables_to_delete[ $table_name ] = $table_name;
140
+			}
141
+		}
142
+		if (! empty($tables_to_delete)) {
143
+			global $wpdb;
144
+			// make sure we only have a unique strings in the array.
145
+			$tables_to_delete = array_unique($tables_to_delete);
146
+			$wpdb->query('DROP TABLE ' . implode(', ', $tables_to_delete));
147
+		}
148
+		return $tables_to_delete;
149
+	}
150 150
 
151 151
 
152
-    /**
153
-     * Drops the specified index from the specified table. $table_name can
154
-     * optionally start with $wpdb->prefix or not
155
-     *
156
-     * @param string $table_name
157
-     * @param string $index_name
158
-     * @return bool|int the number of indexes dropped. False if there was a datbase error
159
-     * @throws EE_Error
160
-     * @global wpdb  $wpdb
161
-     */
162
-    public function dropIndex(string $table_name, string $index_name)
163
-    {
164
-        if (apply_filters('FHEE__EEH_Activation__drop_index__short_circuit', false)) {
165
-            return 0;
166
-        }
167
-        global $wpdb;
168
-        $table_name         = $this->getTableAnalysis()->ensureTableNameHasPrefix($table_name);
169
-        $index_exists_query = "SHOW INDEX FROM $table_name WHERE key_name = '$index_name'";
170
-        if (
171
-            $this->getTableAnalysis()->tableExists($table_name)
172
-            && $wpdb->get_var($index_exists_query)
173
-               === $table_name // using get_var with the $index_exists_query returns the table's name
174
-        ) {
175
-            return $wpdb->query("ALTER TABLE $table_name DROP INDEX $index_name");
176
-        }
177
-        return 0;
178
-    }
152
+	/**
153
+	 * Drops the specified index from the specified table. $table_name can
154
+	 * optionally start with $wpdb->prefix or not
155
+	 *
156
+	 * @param string $table_name
157
+	 * @param string $index_name
158
+	 * @return bool|int the number of indexes dropped. False if there was a datbase error
159
+	 * @throws EE_Error
160
+	 * @global wpdb  $wpdb
161
+	 */
162
+	public function dropIndex(string $table_name, string $index_name)
163
+	{
164
+		if (apply_filters('FHEE__EEH_Activation__drop_index__short_circuit', false)) {
165
+			return 0;
166
+		}
167
+		global $wpdb;
168
+		$table_name         = $this->getTableAnalysis()->ensureTableNameHasPrefix($table_name);
169
+		$index_exists_query = "SHOW INDEX FROM $table_name WHERE key_name = '$index_name'";
170
+		if (
171
+			$this->getTableAnalysis()->tableExists($table_name)
172
+			&& $wpdb->get_var($index_exists_query)
173
+			   === $table_name // using get_var with the $index_exists_query returns the table's name
174
+		) {
175
+			return $wpdb->query("ALTER TABLE $table_name DROP INDEX $index_name");
176
+		}
177
+		return 0;
178
+	}
179 179
 
180 180
 
181
-    /**
182
-     * Just creates the requested table. $table_name can
183
-     * optionally start with $wpdb->prefix or not
184
-     *
185
-     * @param string $table_name
186
-     * @param string $create_sql defining the table's columns and indexes
187
-     * @param string $engine     (no need to specify "ENGINE=", that's implied)
188
-     * @return void
189
-     * @throws EE_Error
190
-     */
191
-    public function createTable(string $table_name, string $create_sql, string $engine = 'InnoDB')
192
-    {
193
-        $engine = apply_filters(
194
-            'FHEE__EventEspresso_core_services_database_TableManager__createTable__engine',
195
-            $engine,
196
-            $table_name,
197
-            $create_sql
198
-        );
199
-        // does $sql contain valid column information? ( LPT: https://regex101.com/ is great for working out regex patterns )
200
-        if (preg_match('((((.*?))(,\s))+)', $create_sql, $valid_column_data)) {
201
-            $table_name = $this->getTableAnalysis()->ensureTableNameHasPrefix($table_name);
202
-            /** @var wpdb $wpdb */
203
-            global $wpdb;
204
-            $SQL = "CREATE TABLE $table_name ( $create_sql ) ENGINE=$engine " . $wpdb->get_charset_collate();
181
+	/**
182
+	 * Just creates the requested table. $table_name can
183
+	 * optionally start with $wpdb->prefix or not
184
+	 *
185
+	 * @param string $table_name
186
+	 * @param string $create_sql defining the table's columns and indexes
187
+	 * @param string $engine     (no need to specify "ENGINE=", that's implied)
188
+	 * @return void
189
+	 * @throws EE_Error
190
+	 */
191
+	public function createTable(string $table_name, string $create_sql, string $engine = 'InnoDB')
192
+	{
193
+		$engine = apply_filters(
194
+			'FHEE__EventEspresso_core_services_database_TableManager__createTable__engine',
195
+			$engine,
196
+			$table_name,
197
+			$create_sql
198
+		);
199
+		// does $sql contain valid column information? ( LPT: https://regex101.com/ is great for working out regex patterns )
200
+		if (preg_match('((((.*?))(,\s))+)', $create_sql, $valid_column_data)) {
201
+			$table_name = $this->getTableAnalysis()->ensureTableNameHasPrefix($table_name);
202
+			/** @var wpdb $wpdb */
203
+			global $wpdb;
204
+			$SQL = "CREATE TABLE $table_name ( $create_sql ) ENGINE=$engine " . $wpdb->get_charset_collate();
205 205
 
206
-            // get $wpdb to echo errors, but buffer them. This way at least WE know an error
207
-            // happened. And then we can choose to tell the end user
208
-            $old_show_errors_policy       = $wpdb->show_errors();
209
-            $old_error_suppression_policy = $wpdb->suppress_errors(false);
206
+			// get $wpdb to echo errors, but buffer them. This way at least WE know an error
207
+			// happened. And then we can choose to tell the end user
208
+			$old_show_errors_policy       = $wpdb->show_errors();
209
+			$old_error_suppression_policy = $wpdb->suppress_errors(false);
210 210
 
211
-            if (! function_exists('dbDelta')) {
212
-                require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
213
-            }
211
+			if (! function_exists('dbDelta')) {
212
+				require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
213
+			}
214 214
 
215
-            ob_start();
216
-            dbDelta($SQL);
217
-            $output = ob_get_contents();
218
-            ob_end_clean();
219
-            $wpdb->show_errors($old_show_errors_policy);
220
-            $wpdb->suppress_errors($old_error_suppression_policy);
221
-            if (! empty($output)) {
222
-                throw new EE_Error($output);
223
-            }
224
-        } else {
225
-            throw new EE_Error(
226
-                sprintf(
227
-                    esc_html__(
228
-                        'The following table creation SQL does not contain valid information about the table columns: %1$s %2$s',
229
-                        'event_espresso'
230
-                    ),
231
-                    '<br />',
232
-                    $create_sql
233
-                )
234
-            );
235
-        }
236
-    }
215
+			ob_start();
216
+			dbDelta($SQL);
217
+			$output = ob_get_contents();
218
+			ob_end_clean();
219
+			$wpdb->show_errors($old_show_errors_policy);
220
+			$wpdb->suppress_errors($old_error_suppression_policy);
221
+			if (! empty($output)) {
222
+				throw new EE_Error($output);
223
+			}
224
+		} else {
225
+			throw new EE_Error(
226
+				sprintf(
227
+					esc_html__(
228
+						'The following table creation SQL does not contain valid information about the table columns: %1$s %2$s',
229
+						'event_espresso'
230
+					),
231
+					'<br />',
232
+					$create_sql
233
+				)
234
+			);
235
+		}
236
+	}
237 237
 
238 238
 
239
-    /**
240
-     * Drops the specified index if it's size differs from $desired_index_size.
241
-     * WordPress' dbdelta method doesn't automatically change index sizes, so this
242
-     * method can be used to only drop the index if needed, and afterwards dbdelta can be used as normal.
243
-     * If the table doesn't exist, or it exists but the index does not, or returns false
244
-     *
245
-     * @param string     $table_name
246
-     * @param string     $index_name
247
-     * @param string     $column_name        if none is provided, we assume the column name matches the index
248
-     *                                       (often true in EE)
249
-     * @param string|int $desired_index_size defaults to TableAnalysis::index_col_size, the max for utf8mb4.
250
-     * @return bool whether an index was dropped or not
251
-     * @throws /EE_Error if table analysis object isn't defined
252
-     */
253
-    public function dropIndexIfSizeNot(
254
-        string $table_name,
255
-        string $index_name,
256
-        string $column_name = '',
257
-        $desired_index_size = TableAnalysis::INDEX_COLUMN_SIZE
258
-    ) {
259
-        if ($column_name === '') {
260
-            $column_name = $index_name;
261
-        }
262
-        if (! $this->getTableAnalysis()->tableExists($table_name)) {
263
-            return false;
264
-        }
265
-        $index_entries = $this->getTableAnalysis()->showIndexes($table_name, $index_name);
266
-        if (empty($index_entries)) {
267
-            return false;
268
-        }
269
-        foreach ($index_entries as $index_entry) {
270
-            if (
271
-                $column_name === $index_entry->Column_name
272
-                && (string)$desired_index_size !== $index_entry->Sub_part
273
-            ) {
274
-                return $this->dropIndex($table_name, $index_name);
275
-            }
276
-        }
277
-        return false;
278
-    }
239
+	/**
240
+	 * Drops the specified index if it's size differs from $desired_index_size.
241
+	 * WordPress' dbdelta method doesn't automatically change index sizes, so this
242
+	 * method can be used to only drop the index if needed, and afterwards dbdelta can be used as normal.
243
+	 * If the table doesn't exist, or it exists but the index does not, or returns false
244
+	 *
245
+	 * @param string     $table_name
246
+	 * @param string     $index_name
247
+	 * @param string     $column_name        if none is provided, we assume the column name matches the index
248
+	 *                                       (often true in EE)
249
+	 * @param string|int $desired_index_size defaults to TableAnalysis::index_col_size, the max for utf8mb4.
250
+	 * @return bool whether an index was dropped or not
251
+	 * @throws /EE_Error if table analysis object isn't defined
252
+	 */
253
+	public function dropIndexIfSizeNot(
254
+		string $table_name,
255
+		string $index_name,
256
+		string $column_name = '',
257
+		$desired_index_size = TableAnalysis::INDEX_COLUMN_SIZE
258
+	) {
259
+		if ($column_name === '') {
260
+			$column_name = $index_name;
261
+		}
262
+		if (! $this->getTableAnalysis()->tableExists($table_name)) {
263
+			return false;
264
+		}
265
+		$index_entries = $this->getTableAnalysis()->showIndexes($table_name, $index_name);
266
+		if (empty($index_entries)) {
267
+			return false;
268
+		}
269
+		foreach ($index_entries as $index_entry) {
270
+			if (
271
+				$column_name === $index_entry->Column_name
272
+				&& (string)$desired_index_size !== $index_entry->Sub_part
273
+			) {
274
+				return $this->dropIndex($table_name, $index_name);
275
+			}
276
+		}
277
+		return false;
278
+	}
279 279
 }
Please login to merge, or discard this patch.
core/services/request/RequestStackCoreApp.php 1 patch
Indentation   +76 added lines, -76 removed lines patch added patch discarded remove patch
@@ -29,87 +29,87 @@
 block discarded – undo
29 29
  */
30 30
 class RequestStackCoreApp implements RequestDecoratorInterface, RequestStackCoreAppInterface
31 31
 {
32
-    protected RequestInterface $request;
32
+	protected RequestInterface $request;
33 33
 
34
-    protected ResponseInterface $response;
34
+	protected ResponseInterface $response;
35 35
 
36 36
 
37
-    /**
38
-     * handle
39
-     * sets hooks for running rest of system
40
-     * provides "AHEE__EE_System__construct__complete" hook for EE Addons to use as their starting point
41
-     * starting EE Addons from any other point may lead to problems
42
-     *
43
-     * @param RequestInterface  $request
44
-     * @param ResponseInterface $response
45
-     * @return ResponseInterface
46
-     * @throws InvalidClassException
47
-     * @throws EE_Error
48
-     * @throws InvalidDataTypeException
49
-     * @throws InvalidInterfaceException
50
-     * @throws InvalidArgumentException
51
-     */
52
-    public function handleRequest(RequestInterface $request, ResponseInterface $response): ResponseInterface
53
-    {
54
-        $this->request  = $request;
55
-        $this->response = $response;
56
-        espresso_load_required('EE_Base', EE_CORE . 'EE_Base.core.php');
57
-        DeprecationManager::loadDeprecations();
58
-        // workarounds for PHP < 5.3
59
-        espresso_load_required('EEH_Class_Tools', EE_HELPERS . 'EEH_Class_Tools.helper.php');
60
-        do_action(
61
-            'EE_EventEspresso_core_services_request_RequestStackCoreApp__handle_request__initialize_core_loading'
62
-        );
63
-        // legacy action for backwards compatibility
64
-        do_action('EE_Load_Espresso_Core__handle_request__initialize_core_loading');
65
-        $this->setupFramework();
66
-        $capabilities_checker = LoaderFactory::getShared(CapabilitiesChecker::class, [EE_Capabilities::instance()]);
67
-        LoaderFactory::getShared(PersistentAdminNoticeManager::class, [$capabilities_checker, $request]);
68
-        // needed
69
-        LoaderFactory::getShared(EE_Maintenance_Mode::class);
70
-        LoaderFactory::getShared(EE_Cron_Tasks::class);
71
-        LoaderFactory::getShared(EE_System::class);
72
-        return $this->response;
73
-    }
37
+	/**
38
+	 * handle
39
+	 * sets hooks for running rest of system
40
+	 * provides "AHEE__EE_System__construct__complete" hook for EE Addons to use as their starting point
41
+	 * starting EE Addons from any other point may lead to problems
42
+	 *
43
+	 * @param RequestInterface  $request
44
+	 * @param ResponseInterface $response
45
+	 * @return ResponseInterface
46
+	 * @throws InvalidClassException
47
+	 * @throws EE_Error
48
+	 * @throws InvalidDataTypeException
49
+	 * @throws InvalidInterfaceException
50
+	 * @throws InvalidArgumentException
51
+	 */
52
+	public function handleRequest(RequestInterface $request, ResponseInterface $response): ResponseInterface
53
+	{
54
+		$this->request  = $request;
55
+		$this->response = $response;
56
+		espresso_load_required('EE_Base', EE_CORE . 'EE_Base.core.php');
57
+		DeprecationManager::loadDeprecations();
58
+		// workarounds for PHP < 5.3
59
+		espresso_load_required('EEH_Class_Tools', EE_HELPERS . 'EEH_Class_Tools.helper.php');
60
+		do_action(
61
+			'EE_EventEspresso_core_services_request_RequestStackCoreApp__handle_request__initialize_core_loading'
62
+		);
63
+		// legacy action for backwards compatibility
64
+		do_action('EE_Load_Espresso_Core__handle_request__initialize_core_loading');
65
+		$this->setupFramework();
66
+		$capabilities_checker = LoaderFactory::getShared(CapabilitiesChecker::class, [EE_Capabilities::instance()]);
67
+		LoaderFactory::getShared(PersistentAdminNoticeManager::class, [$capabilities_checker, $request]);
68
+		// needed
69
+		LoaderFactory::getShared(EE_Maintenance_Mode::class);
70
+		LoaderFactory::getShared(EE_Cron_Tasks::class);
71
+		LoaderFactory::getShared(EE_System::class);
72
+		return $this->response;
73
+	}
74 74
 
75 75
 
76
-    /**
77
-     * set framework for the rest of EE to hook into when loading
78
-     *
79
-     * @throws EE_Error
80
-     */
81
-    private function setupFramework()
82
-    {
83
-        espresso_load_required('EE_Bootstrap', EE_CORE . 'EE_Bootstrap.core.php');
84
-        add_action('plugins_loaded', ['EE_Bootstrap', 'load_espresso_addons'], 1);
85
-        add_action('plugins_loaded', ['EE_Bootstrap', 'detect_activations_or_upgrades'], 3);
86
-        add_action('plugins_loaded', ['EE_Bootstrap', 'load_core_configuration'], 5);
87
-        add_action('plugins_loaded', ['EE_Bootstrap', 'register_shortcodes_modules_and_widgets'], 7);
88
-        add_action('plugins_loaded', ['EE_Bootstrap', 'brew_espresso'], 9);
89
-    }
76
+	/**
77
+	 * set framework for the rest of EE to hook into when loading
78
+	 *
79
+	 * @throws EE_Error
80
+	 */
81
+	private function setupFramework()
82
+	{
83
+		espresso_load_required('EE_Bootstrap', EE_CORE . 'EE_Bootstrap.core.php');
84
+		add_action('plugins_loaded', ['EE_Bootstrap', 'load_espresso_addons'], 1);
85
+		add_action('plugins_loaded', ['EE_Bootstrap', 'detect_activations_or_upgrades'], 3);
86
+		add_action('plugins_loaded', ['EE_Bootstrap', 'load_core_configuration'], 5);
87
+		add_action('plugins_loaded', ['EE_Bootstrap', 'register_shortcodes_modules_and_widgets'], 7);
88
+		add_action('plugins_loaded', ['EE_Bootstrap', 'brew_espresso'], 9);
89
+	}
90 90
 
91 91
 
92
-    /**
93
-     * called after the request stack has been fully processed
94
-     * if any of the middleware apps has requested the plugin be deactivated, then we do that now
95
-     *
96
-     * @param RequestInterface  $request
97
-     * @param ResponseInterface $response
98
-     */
99
-    public function handleResponse(RequestInterface $request, ResponseInterface $response)
100
-    {
101
-        if ($response->pluginDeactivated()) {
102
-            espresso_deactivate_plugin(EE_PLUGIN_BASENAME);
103
-        }
104
-        $request_headers = $response->requestHeaders();
105
-        if ($request_headers) {
106
-            foreach ($request_headers as $request_header) {
107
-                header($request_header);
108
-            }
109
-            // headers set AND request terminated? then kill the current request
110
-            if ($response->requestTerminated()) {
111
-                exit;
112
-            }
113
-        }
114
-    }
92
+	/**
93
+	 * called after the request stack has been fully processed
94
+	 * if any of the middleware apps has requested the plugin be deactivated, then we do that now
95
+	 *
96
+	 * @param RequestInterface  $request
97
+	 * @param ResponseInterface $response
98
+	 */
99
+	public function handleResponse(RequestInterface $request, ResponseInterface $response)
100
+	{
101
+		if ($response->pluginDeactivated()) {
102
+			espresso_deactivate_plugin(EE_PLUGIN_BASENAME);
103
+		}
104
+		$request_headers = $response->requestHeaders();
105
+		if ($request_headers) {
106
+			foreach ($request_headers as $request_header) {
107
+				header($request_header);
108
+			}
109
+			// headers set AND request terminated? then kill the current request
110
+			if ($response->requestTerminated()) {
111
+				exit;
112
+			}
113
+		}
114
+	}
115 115
 }
Please login to merge, or discard this patch.
core/EE_Cart.core.php 1 patch
Indentation   +408 added lines, -408 removed lines patch added patch discarded remove patch
@@ -16,412 +16,412 @@
 block discarded – undo
16 16
  */
17 17
 class EE_Cart implements ResettableInterface
18 18
 {
19
-    /**
20
-     * instance of the EE_Cart object
21
-     *
22
-     * @access    private
23
-     * @var EE_Cart $_instance
24
-     */
25
-    private static $_instance;
26
-
27
-    /**
28
-     * instance of the EE_Session object
29
-     *
30
-     * @access    protected
31
-     * @var EE_Session $_session
32
-     */
33
-    protected $_session;
34
-
35
-    /**
36
-     * The total Line item which comprises all the children line-item subtotals,
37
-     * which in turn each have their line items.
38
-     * Typically, the line item structure will look like:
39
-     * grand total
40
-     * -tickets-sub-total
41
-     * --ticket1
42
-     * --ticket2
43
-     * --...
44
-     * -taxes-sub-total
45
-     * --tax1
46
-     * --tax2
47
-     *
48
-     * @var EE_Line_Item
49
-     */
50
-    private $_grand_total;
51
-
52
-
53
-    /**
54
-     * @singleton method used to instantiate class object
55
-     * @access    public
56
-     * @param EE_Line_Item $grand_total
57
-     * @param EE_Session   $session
58
-     * @return EE_Cart
59
-     * @throws EE_Error
60
-     * @throws ReflectionException
61
-     */
62
-    public static function instance(EE_Line_Item $grand_total = null, EE_Session $session = null)
63
-    {
64
-        if ($grand_total instanceof EE_Line_Item && $grand_total->is_total()) {
65
-            self::$_instance = new self($grand_total, $session);
66
-        }
67
-        // or maybe retrieve an existing one ?
68
-        if (! self::$_instance instanceof EE_Cart) {
69
-            // try getting the cart out of the session
70
-            $saved_cart = $session instanceof EE_Session ? $session->cart() : null;
71
-            self::$_instance = $saved_cart instanceof EE_Cart ? $saved_cart : new self($grand_total, $session);
72
-            unset($saved_cart);
73
-        }
74
-        // verify that cart is ok and grand total line item exists
75
-        if (! self::$_instance instanceof EE_Cart || ! self::$_instance->_grand_total instanceof EE_Line_Item) {
76
-            self::$_instance = new self($grand_total, $session);
77
-        }
78
-        self::$_instance->get_grand_total();
79
-        // once everything is all said and done, save the cart to the EE_Session
80
-        add_action('shutdown', array(self::$_instance, 'save_cart'), 90);
81
-        return self::$_instance;
82
-    }
83
-
84
-
85
-    /**
86
-     * private constructor to prevent direct creation
87
-     *
88
-     * @Constructor
89
-     * @access private
90
-     * @param EE_Line_Item $grand_total
91
-     * @param EE_Session   $session
92
-     */
93
-    private function __construct(EE_Line_Item $grand_total = null, EE_Session $session = null)
94
-    {
95
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
96
-        $this->set_session($session);
97
-        if ($grand_total instanceof EE_Line_Item && $grand_total->is_total()) {
98
-            $this->set_grand_total_line_item($grand_total);
99
-        }
100
-    }
101
-
102
-
103
-    /**
104
-     * Resets the cart completely (whereas empty_cart
105
-     *
106
-     * @param EE_Line_Item $grand_total
107
-     * @param EE_Session   $session
108
-     * @return EE_Cart
109
-     * @throws EE_Error
110
-     * @throws ReflectionException
111
-     */
112
-    public static function reset(EE_Line_Item $grand_total = null, EE_Session $session = null)
113
-    {
114
-        remove_action('shutdown', array(self::$_instance, 'save_cart'), 90);
115
-        if ($session instanceof EE_Session) {
116
-            $session->reset_cart();
117
-        }
118
-        self::$_instance = null;
119
-        return self::instance($grand_total, $session);
120
-    }
121
-
122
-
123
-    /**
124
-     * @return EE_Session
125
-     */
126
-    public function session()
127
-    {
128
-        if (! $this->_session instanceof EE_Session) {
129
-            $this->set_session();
130
-        }
131
-        return $this->_session;
132
-    }
133
-
134
-
135
-    /**
136
-     * @param EE_Session $session
137
-     */
138
-    public function set_session(EE_Session $session = null)
139
-    {
140
-        $this->_session = $session instanceof EE_Session ? $session : EE_Registry::instance()->load_core('Session');
141
-    }
142
-
143
-
144
-    /**
145
-     * Sets the cart to match the line item. Especially handy for loading an old cart where you
146
-     *  know the grand total line item on it
147
-     *
148
-     * @param EE_Line_Item $line_item
149
-     */
150
-    public function set_grand_total_line_item(EE_Line_Item $line_item)
151
-    {
152
-        $this->_grand_total = $line_item;
153
-    }
154
-
155
-
156
-    /**
157
-     * get_cart_from_reg_url_link
158
-     *
159
-     * @access public
160
-     * @param EE_Transaction $transaction
161
-     * @param EE_Session     $session
162
-     * @return EE_Cart
163
-     * @throws EE_Error
164
-     * @throws ReflectionException
165
-     */
166
-    public static function get_cart_from_txn(EE_Transaction $transaction, EE_Session $session = null)
167
-    {
168
-        $grand_total = $transaction->total_line_item();
169
-        $grand_total->get_items();
170
-        $grand_total->tax_descendants();
171
-        return EE_Cart::instance($grand_total, $session);
172
-    }
173
-
174
-
175
-    /**
176
-     * Creates the total line item, and ensures it has its 'tickets' and 'taxes' sub-items
177
-     *
178
-     * @return EE_Line_Item
179
-     * @throws EE_Error
180
-     * @throws ReflectionException
181
-     */
182
-    private function _create_grand_total()
183
-    {
184
-        $this->_grand_total = EEH_Line_Item::create_total_line_item();
185
-        return $this->_grand_total;
186
-    }
187
-
188
-
189
-    /**
190
-     * Gets all the line items of object type Ticket
191
-     *
192
-     * @access public
193
-     * @return EE_Line_Item[]
194
-     */
195
-    public function get_tickets()
196
-    {
197
-        if ($this->_grand_total === null) {
198
-            return array();
199
-        }
200
-        return EEH_Line_Item::get_ticket_line_items($this->_grand_total);
201
-    }
202
-
203
-
204
-    /**
205
-     * returns the total quantity of tickets in the cart
206
-     *
207
-     * @access public
208
-     * @return int
209
-     * @throws EE_Error
210
-     * @throws ReflectionException
211
-     */
212
-    public function all_ticket_quantity_count()
213
-    {
214
-        $tickets = $this->get_tickets();
215
-        if (empty($tickets)) {
216
-            return 0;
217
-        }
218
-        $count = 0;
219
-        foreach ($tickets as $ticket) {
220
-            $count += $ticket->get('LIN_quantity');
221
-        }
222
-        return $count;
223
-    }
224
-
225
-
226
-    /**
227
-     * Gets all the tax line items
228
-     *
229
-     * @return EE_Line_Item[]
230
-     * @throws EE_Error
231
-     * @throws ReflectionException
232
-     */
233
-    public function get_taxes()
234
-    {
235
-        return EEH_Line_Item::get_taxes_subtotal($this->_grand_total)->children();
236
-    }
237
-
238
-
239
-    /**
240
-     * Gets the total line item (which is a parent of all other line items) on this cart
241
-     *
242
-     * @return EE_Line_Item
243
-     * @throws EE_Error
244
-     * @throws ReflectionException
245
-     */
246
-    public function get_grand_total()
247
-    {
248
-        return $this->_grand_total instanceof EE_Line_Item ? $this->_grand_total : $this->_create_grand_total();
249
-    }
250
-
251
-
252
-    /**
253
-     * @process items for adding to cart
254
-     * @access  public
255
-     * @param EE_Ticket $ticket
256
-     * @param int       $qty
257
-     * @return bool TRUE on success, FALSE on fail
258
-     * @throws EE_Error
259
-     * @throws ReflectionException
260
-     */
261
-    public function add_ticket_to_cart(EE_Ticket $ticket, $qty = 1)
262
-    {
263
-        EEH_Line_Item::add_ticket_purchase($this->get_grand_total(), $ticket, $qty, false);
264
-        return $this->save_cart();
265
-    }
266
-
267
-
268
-    /**
269
-     * get_cart_total_before_tax
270
-     *
271
-     * @access public
272
-     * @return float
273
-     * @throws EE_Error
274
-     * @throws ReflectionException
275
-     */
276
-    public function get_cart_total_before_tax()
277
-    {
278
-        return $this->get_grand_total()->recalculate_pre_tax_total();
279
-    }
280
-
281
-
282
-    /**
283
-     * gets the total amount of tax paid for items in this cart
284
-     *
285
-     * @access public
286
-     * @return float
287
-     * @throws EE_Error
288
-     * @throws ReflectionException
289
-     */
290
-    public function get_applied_taxes()
291
-    {
292
-        return EEH_Line_Item::ensure_taxes_applied($this->_grand_total);
293
-    }
294
-
295
-
296
-    /**
297
-     * Gets the total amount to be paid for the items in the cart, including taxes and other modifiers
298
-     *
299
-     * @access public
300
-     * @return float
301
-     * @throws EE_Error
302
-     * @throws ReflectionException
303
-     */
304
-    public function get_cart_grand_total()
305
-    {
306
-        EEH_Line_Item::ensure_taxes_applied($this->_grand_total);
307
-        return $this->get_grand_total()->total();
308
-    }
309
-
310
-
311
-    /**
312
-     * Gets the total amount to be paid for the items in the cart, including taxes and other modifiers
313
-     *
314
-     * @access public
315
-     * @return float
316
-     * @throws EE_Error
317
-     * @throws ReflectionException
318
-     */
319
-    public function recalculate_all_cart_totals()
320
-    {
321
-        $pre_tax_total = $this->get_cart_total_before_tax();
322
-        $taxes_total = EEH_Line_Item::ensure_taxes_applied($this->_grand_total);
323
-        $this->_grand_total->set_total($pre_tax_total + $taxes_total);
324
-        $this->_grand_total->save_this_and_descendants_to_txn();
325
-        return $this->get_grand_total()->total();
326
-    }
327
-
328
-
329
-    /**
330
-     * deletes an item from the cart
331
-     *
332
-     * @access public
333
-     * @param array|bool|string $line_item_codes
334
-     * @return int on success, FALSE on fail
335
-     * @throws EE_Error
336
-     * @throws ReflectionException
337
-     */
338
-    public function delete_items($line_item_codes = false)
339
-    {
340
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
341
-        return EEH_Line_Item::delete_items($this->get_grand_total(), $line_item_codes);
342
-    }
343
-
344
-
345
-    /**
346
-     * @remove ALL items from cart and zero ALL totals
347
-     * @access public
348
-     * @return bool
349
-     * @throws EE_Error
350
-     * @throws ReflectionException
351
-     */
352
-    public function empty_cart()
353
-    {
354
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
355
-        $this->_grand_total = $this->_create_grand_total();
356
-        return $this->save_cart(true);
357
-    }
358
-
359
-
360
-    /**
361
-     * @remove ALL items from cart and delete total as well
362
-     * @access public
363
-     * @return bool
364
-     * @throws EE_Error
365
-     * @throws ReflectionException
366
-     */
367
-    public function delete_cart()
368
-    {
369
-        if ($this->_grand_total instanceof EE_Line_Item) {
370
-            $deleted = EEH_Line_Item::delete_all_child_items($this->_grand_total);
371
-            if ($deleted) {
372
-                $deleted += $this->_grand_total->delete();
373
-                $this->_grand_total = null;
374
-                return true;
375
-            }
376
-        }
377
-        return false;
378
-    }
379
-
380
-
381
-    /**
382
-     * @save   cart to session
383
-     * @access public
384
-     * @param bool $apply_taxes
385
-     * @return bool TRUE on success, FALSE on fail
386
-     * @throws EE_Error
387
-     * @throws ReflectionException
388
-     */
389
-    public function save_cart($apply_taxes = true)
390
-    {
391
-        if ($apply_taxes && $this->_grand_total instanceof EE_Line_Item) {
392
-            EEH_Line_Item::ensure_taxes_applied($this->_grand_total);
393
-            // make sure we don't cache the transaction because it can get stale
394
-            if (
395
-                $this->_grand_total->get_one_from_cache('Transaction') instanceof EE_Transaction
396
-                && $this->_grand_total->get_one_from_cache('Transaction')->ID()
397
-            ) {
398
-                $this->_grand_total->clear_cache('Transaction', null, true);
399
-            }
400
-        }
401
-        if ($this->session() instanceof EE_Session) {
402
-            return $this->session()->set_cart($this);
403
-        }
404
-        return false;
405
-    }
406
-
407
-
408
-    public function __wakeup()
409
-    {
410
-        if (! $this->_grand_total instanceof EE_Line_Item && absint($this->_grand_total) !== 0) {
411
-            // $this->_grand_total is actually just an ID, so use it to get the object from the db
412
-            $this->_grand_total = EEM_Line_Item::instance()->get_one_by_ID($this->_grand_total);
413
-        }
414
-    }
415
-
416
-
417
-    /**
418
-     * @return array
419
-     */
420
-    public function __sleep()
421
-    {
422
-        if ($this->_grand_total instanceof EE_Line_Item && $this->_grand_total->ID()) {
423
-            $this->_grand_total = $this->_grand_total->ID();
424
-        }
425
-        return array('_grand_total');
426
-    }
19
+	/**
20
+	 * instance of the EE_Cart object
21
+	 *
22
+	 * @access    private
23
+	 * @var EE_Cart $_instance
24
+	 */
25
+	private static $_instance;
26
+
27
+	/**
28
+	 * instance of the EE_Session object
29
+	 *
30
+	 * @access    protected
31
+	 * @var EE_Session $_session
32
+	 */
33
+	protected $_session;
34
+
35
+	/**
36
+	 * The total Line item which comprises all the children line-item subtotals,
37
+	 * which in turn each have their line items.
38
+	 * Typically, the line item structure will look like:
39
+	 * grand total
40
+	 * -tickets-sub-total
41
+	 * --ticket1
42
+	 * --ticket2
43
+	 * --...
44
+	 * -taxes-sub-total
45
+	 * --tax1
46
+	 * --tax2
47
+	 *
48
+	 * @var EE_Line_Item
49
+	 */
50
+	private $_grand_total;
51
+
52
+
53
+	/**
54
+	 * @singleton method used to instantiate class object
55
+	 * @access    public
56
+	 * @param EE_Line_Item $grand_total
57
+	 * @param EE_Session   $session
58
+	 * @return EE_Cart
59
+	 * @throws EE_Error
60
+	 * @throws ReflectionException
61
+	 */
62
+	public static function instance(EE_Line_Item $grand_total = null, EE_Session $session = null)
63
+	{
64
+		if ($grand_total instanceof EE_Line_Item && $grand_total->is_total()) {
65
+			self::$_instance = new self($grand_total, $session);
66
+		}
67
+		// or maybe retrieve an existing one ?
68
+		if (! self::$_instance instanceof EE_Cart) {
69
+			// try getting the cart out of the session
70
+			$saved_cart = $session instanceof EE_Session ? $session->cart() : null;
71
+			self::$_instance = $saved_cart instanceof EE_Cart ? $saved_cart : new self($grand_total, $session);
72
+			unset($saved_cart);
73
+		}
74
+		// verify that cart is ok and grand total line item exists
75
+		if (! self::$_instance instanceof EE_Cart || ! self::$_instance->_grand_total instanceof EE_Line_Item) {
76
+			self::$_instance = new self($grand_total, $session);
77
+		}
78
+		self::$_instance->get_grand_total();
79
+		// once everything is all said and done, save the cart to the EE_Session
80
+		add_action('shutdown', array(self::$_instance, 'save_cart'), 90);
81
+		return self::$_instance;
82
+	}
83
+
84
+
85
+	/**
86
+	 * private constructor to prevent direct creation
87
+	 *
88
+	 * @Constructor
89
+	 * @access private
90
+	 * @param EE_Line_Item $grand_total
91
+	 * @param EE_Session   $session
92
+	 */
93
+	private function __construct(EE_Line_Item $grand_total = null, EE_Session $session = null)
94
+	{
95
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
96
+		$this->set_session($session);
97
+		if ($grand_total instanceof EE_Line_Item && $grand_total->is_total()) {
98
+			$this->set_grand_total_line_item($grand_total);
99
+		}
100
+	}
101
+
102
+
103
+	/**
104
+	 * Resets the cart completely (whereas empty_cart
105
+	 *
106
+	 * @param EE_Line_Item $grand_total
107
+	 * @param EE_Session   $session
108
+	 * @return EE_Cart
109
+	 * @throws EE_Error
110
+	 * @throws ReflectionException
111
+	 */
112
+	public static function reset(EE_Line_Item $grand_total = null, EE_Session $session = null)
113
+	{
114
+		remove_action('shutdown', array(self::$_instance, 'save_cart'), 90);
115
+		if ($session instanceof EE_Session) {
116
+			$session->reset_cart();
117
+		}
118
+		self::$_instance = null;
119
+		return self::instance($grand_total, $session);
120
+	}
121
+
122
+
123
+	/**
124
+	 * @return EE_Session
125
+	 */
126
+	public function session()
127
+	{
128
+		if (! $this->_session instanceof EE_Session) {
129
+			$this->set_session();
130
+		}
131
+		return $this->_session;
132
+	}
133
+
134
+
135
+	/**
136
+	 * @param EE_Session $session
137
+	 */
138
+	public function set_session(EE_Session $session = null)
139
+	{
140
+		$this->_session = $session instanceof EE_Session ? $session : EE_Registry::instance()->load_core('Session');
141
+	}
142
+
143
+
144
+	/**
145
+	 * Sets the cart to match the line item. Especially handy for loading an old cart where you
146
+	 *  know the grand total line item on it
147
+	 *
148
+	 * @param EE_Line_Item $line_item
149
+	 */
150
+	public function set_grand_total_line_item(EE_Line_Item $line_item)
151
+	{
152
+		$this->_grand_total = $line_item;
153
+	}
154
+
155
+
156
+	/**
157
+	 * get_cart_from_reg_url_link
158
+	 *
159
+	 * @access public
160
+	 * @param EE_Transaction $transaction
161
+	 * @param EE_Session     $session
162
+	 * @return EE_Cart
163
+	 * @throws EE_Error
164
+	 * @throws ReflectionException
165
+	 */
166
+	public static function get_cart_from_txn(EE_Transaction $transaction, EE_Session $session = null)
167
+	{
168
+		$grand_total = $transaction->total_line_item();
169
+		$grand_total->get_items();
170
+		$grand_total->tax_descendants();
171
+		return EE_Cart::instance($grand_total, $session);
172
+	}
173
+
174
+
175
+	/**
176
+	 * Creates the total line item, and ensures it has its 'tickets' and 'taxes' sub-items
177
+	 *
178
+	 * @return EE_Line_Item
179
+	 * @throws EE_Error
180
+	 * @throws ReflectionException
181
+	 */
182
+	private function _create_grand_total()
183
+	{
184
+		$this->_grand_total = EEH_Line_Item::create_total_line_item();
185
+		return $this->_grand_total;
186
+	}
187
+
188
+
189
+	/**
190
+	 * Gets all the line items of object type Ticket
191
+	 *
192
+	 * @access public
193
+	 * @return EE_Line_Item[]
194
+	 */
195
+	public function get_tickets()
196
+	{
197
+		if ($this->_grand_total === null) {
198
+			return array();
199
+		}
200
+		return EEH_Line_Item::get_ticket_line_items($this->_grand_total);
201
+	}
202
+
203
+
204
+	/**
205
+	 * returns the total quantity of tickets in the cart
206
+	 *
207
+	 * @access public
208
+	 * @return int
209
+	 * @throws EE_Error
210
+	 * @throws ReflectionException
211
+	 */
212
+	public function all_ticket_quantity_count()
213
+	{
214
+		$tickets = $this->get_tickets();
215
+		if (empty($tickets)) {
216
+			return 0;
217
+		}
218
+		$count = 0;
219
+		foreach ($tickets as $ticket) {
220
+			$count += $ticket->get('LIN_quantity');
221
+		}
222
+		return $count;
223
+	}
224
+
225
+
226
+	/**
227
+	 * Gets all the tax line items
228
+	 *
229
+	 * @return EE_Line_Item[]
230
+	 * @throws EE_Error
231
+	 * @throws ReflectionException
232
+	 */
233
+	public function get_taxes()
234
+	{
235
+		return EEH_Line_Item::get_taxes_subtotal($this->_grand_total)->children();
236
+	}
237
+
238
+
239
+	/**
240
+	 * Gets the total line item (which is a parent of all other line items) on this cart
241
+	 *
242
+	 * @return EE_Line_Item
243
+	 * @throws EE_Error
244
+	 * @throws ReflectionException
245
+	 */
246
+	public function get_grand_total()
247
+	{
248
+		return $this->_grand_total instanceof EE_Line_Item ? $this->_grand_total : $this->_create_grand_total();
249
+	}
250
+
251
+
252
+	/**
253
+	 * @process items for adding to cart
254
+	 * @access  public
255
+	 * @param EE_Ticket $ticket
256
+	 * @param int       $qty
257
+	 * @return bool TRUE on success, FALSE on fail
258
+	 * @throws EE_Error
259
+	 * @throws ReflectionException
260
+	 */
261
+	public function add_ticket_to_cart(EE_Ticket $ticket, $qty = 1)
262
+	{
263
+		EEH_Line_Item::add_ticket_purchase($this->get_grand_total(), $ticket, $qty, false);
264
+		return $this->save_cart();
265
+	}
266
+
267
+
268
+	/**
269
+	 * get_cart_total_before_tax
270
+	 *
271
+	 * @access public
272
+	 * @return float
273
+	 * @throws EE_Error
274
+	 * @throws ReflectionException
275
+	 */
276
+	public function get_cart_total_before_tax()
277
+	{
278
+		return $this->get_grand_total()->recalculate_pre_tax_total();
279
+	}
280
+
281
+
282
+	/**
283
+	 * gets the total amount of tax paid for items in this cart
284
+	 *
285
+	 * @access public
286
+	 * @return float
287
+	 * @throws EE_Error
288
+	 * @throws ReflectionException
289
+	 */
290
+	public function get_applied_taxes()
291
+	{
292
+		return EEH_Line_Item::ensure_taxes_applied($this->_grand_total);
293
+	}
294
+
295
+
296
+	/**
297
+	 * Gets the total amount to be paid for the items in the cart, including taxes and other modifiers
298
+	 *
299
+	 * @access public
300
+	 * @return float
301
+	 * @throws EE_Error
302
+	 * @throws ReflectionException
303
+	 */
304
+	public function get_cart_grand_total()
305
+	{
306
+		EEH_Line_Item::ensure_taxes_applied($this->_grand_total);
307
+		return $this->get_grand_total()->total();
308
+	}
309
+
310
+
311
+	/**
312
+	 * Gets the total amount to be paid for the items in the cart, including taxes and other modifiers
313
+	 *
314
+	 * @access public
315
+	 * @return float
316
+	 * @throws EE_Error
317
+	 * @throws ReflectionException
318
+	 */
319
+	public function recalculate_all_cart_totals()
320
+	{
321
+		$pre_tax_total = $this->get_cart_total_before_tax();
322
+		$taxes_total = EEH_Line_Item::ensure_taxes_applied($this->_grand_total);
323
+		$this->_grand_total->set_total($pre_tax_total + $taxes_total);
324
+		$this->_grand_total->save_this_and_descendants_to_txn();
325
+		return $this->get_grand_total()->total();
326
+	}
327
+
328
+
329
+	/**
330
+	 * deletes an item from the cart
331
+	 *
332
+	 * @access public
333
+	 * @param array|bool|string $line_item_codes
334
+	 * @return int on success, FALSE on fail
335
+	 * @throws EE_Error
336
+	 * @throws ReflectionException
337
+	 */
338
+	public function delete_items($line_item_codes = false)
339
+	{
340
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
341
+		return EEH_Line_Item::delete_items($this->get_grand_total(), $line_item_codes);
342
+	}
343
+
344
+
345
+	/**
346
+	 * @remove ALL items from cart and zero ALL totals
347
+	 * @access public
348
+	 * @return bool
349
+	 * @throws EE_Error
350
+	 * @throws ReflectionException
351
+	 */
352
+	public function empty_cart()
353
+	{
354
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
355
+		$this->_grand_total = $this->_create_grand_total();
356
+		return $this->save_cart(true);
357
+	}
358
+
359
+
360
+	/**
361
+	 * @remove ALL items from cart and delete total as well
362
+	 * @access public
363
+	 * @return bool
364
+	 * @throws EE_Error
365
+	 * @throws ReflectionException
366
+	 */
367
+	public function delete_cart()
368
+	{
369
+		if ($this->_grand_total instanceof EE_Line_Item) {
370
+			$deleted = EEH_Line_Item::delete_all_child_items($this->_grand_total);
371
+			if ($deleted) {
372
+				$deleted += $this->_grand_total->delete();
373
+				$this->_grand_total = null;
374
+				return true;
375
+			}
376
+		}
377
+		return false;
378
+	}
379
+
380
+
381
+	/**
382
+	 * @save   cart to session
383
+	 * @access public
384
+	 * @param bool $apply_taxes
385
+	 * @return bool TRUE on success, FALSE on fail
386
+	 * @throws EE_Error
387
+	 * @throws ReflectionException
388
+	 */
389
+	public function save_cart($apply_taxes = true)
390
+	{
391
+		if ($apply_taxes && $this->_grand_total instanceof EE_Line_Item) {
392
+			EEH_Line_Item::ensure_taxes_applied($this->_grand_total);
393
+			// make sure we don't cache the transaction because it can get stale
394
+			if (
395
+				$this->_grand_total->get_one_from_cache('Transaction') instanceof EE_Transaction
396
+				&& $this->_grand_total->get_one_from_cache('Transaction')->ID()
397
+			) {
398
+				$this->_grand_total->clear_cache('Transaction', null, true);
399
+			}
400
+		}
401
+		if ($this->session() instanceof EE_Session) {
402
+			return $this->session()->set_cart($this);
403
+		}
404
+		return false;
405
+	}
406
+
407
+
408
+	public function __wakeup()
409
+	{
410
+		if (! $this->_grand_total instanceof EE_Line_Item && absint($this->_grand_total) !== 0) {
411
+			// $this->_grand_total is actually just an ID, so use it to get the object from the db
412
+			$this->_grand_total = EEM_Line_Item::instance()->get_one_by_ID($this->_grand_total);
413
+		}
414
+	}
415
+
416
+
417
+	/**
418
+	 * @return array
419
+	 */
420
+	public function __sleep()
421
+	{
422
+		if ($this->_grand_total instanceof EE_Line_Item && $this->_grand_total->ID()) {
423
+			$this->_grand_total = $this->_grand_total->ID();
424
+		}
425
+		return array('_grand_total');
426
+	}
427 427
 }
Please login to merge, or discard this patch.
core/db_models/EEM_Line_Item.model.php 1 patch
Indentation   +625 added lines, -625 removed lines patch added patch discarded remove patch
@@ -27,632 +27,632 @@
 block discarded – undo
27 27
  */
28 28
 class EEM_Line_Item extends EEM_Base
29 29
 {
30
-    /**
31
-     * Tax sub-total is just the total of all the taxes, which should be children
32
-     * of this line item. There should only ever be one tax sub-total, and it should
33
-     * be a direct child of the grand total. Its quantity and LIN_unit_price = 1.
34
-     */
35
-    const type_tax_sub_total = 'tax-sub-total';
36
-
37
-    /**
38
-     * Tax line items indicate a tax applied to all the taxable line items.
39
-     * Should not have any children line items. Its LIN_unit_price = 0. Its LIN_percent is a percent, not a decimal
40
-     * (eg 10% tax = 10, not 0.1). Its LIN_total = LIN_unit_price * pre-tax-total. Quantity = 1.
41
-     */
42
-    const type_tax = 'tax';
43
-
44
-    /**
45
-     * Indicating individual items purchased, or discounts or surcharges.
46
-     * The sum of all the regular line items  plus the tax items should equal the grand total.
47
-     * Possible children are sub-line-items and cancellations.
48
-     * For flat items, LIN_unit_price * LIN_quantity = LIN_total. Its LIN_total is the sum of all the children
49
-     * LIN_totals. Its LIN_percent = 0.
50
-     * For percent items, its LIN_unit_price = 0. Its LIN_percent is a percent, not a decimal (eg 10% = 10, not 0.1).
51
-     * Its LIN_total is LIN_percent / 100 * sum of lower-priority sibling line items. Quantity = 1.
52
-     */
53
-    const type_line_item = 'line-item';
54
-
55
-    /**
56
-     * Line item indicating all the factors that make a single line item.
57
-     * Sub-line items should have NO children line items.
58
-     * For flat sub-items, their quantity should match their parent item, their LIN_unit_price should be this sub-item's
59
-     * contribution towards the price of ONE of their parent items, and its LIN_total should be
60
-     *  = LIN_quantity * LIN_unit_price. Its LIN_percent = 0.
61
-     * For percent sub-items, the quantity should be 1, LIN_unit_price should be 0, and its LIN_total should
62
-     * = LIN_percent / 100 * sum of lower-priority sibling line items..
63
-     */
64
-    const type_sub_line_item = 'sub-item';
65
-
66
-    /**
67
-     * SubTax line items indicate a tax that is only applied to the pre-tax total of their parent line item.
68
-     * Should not have any children line items. Its LIN_unit_price = 0. Its LIN_percent is a percent, not a decimal
69
-     * (eg 10% tax = 10, not 0.1). Its LIN_total = LIN_unit_price * pre-tax-total. Quantity = 1.
70
-     */
71
-    const type_sub_tax = 'sub-tax';
72
-
73
-    /**
74
-     * Line item indicating a sub-total (eg total for an event, or pre-tax subtotal).
75
-     * Direct children should be event subtotals.
76
-     * Should have quantity of 1, and a LIN_total and LIN_unit_price of the sum of all its sub-items' LIN_totals.
77
-     */
78
-    const type_sub_total = 'sub-total';
79
-
80
-    /**
81
-     * Line item for the grand total of an order.
82
-     * Its direct children should be tax subtotals and (pre-tax) subtotals,
83
-     * and possibly a regular line item indicating a transaction-wide discount/surcharge.
84
-     * Should have a quantity of 1, a LIN_total and LIN_unit_price of the entire order's amount.
85
-     */
86
-    const type_total = 'total';
87
-
88
-    /**
89
-     * When a line item is cancelled, a sub-line-item of type 'cancellation'
90
-     * should be created, indicating the quantity that were cancelled
91
-     * (because a line item could have a quantity of 1, and its cancellation item
92
-     * could be for 3, indicating that originally 4 were purchased, but 3 have been
93
-     * cancelled, and only one remains).
94
-     * When items are refunded, a cancellation line item should be made, which points
95
-     * to teh payment model object which actually refunded the payment.
96
-     * Cancellations should NOT have any children line items; the should NOT affect
97
-     * any calculations, and are only meant as a record that cancellations have occurred.
98
-     * Their LIN_percent should be 0.
99
-     */
100
-    const type_cancellation = 'cancellation';
101
-
102
-    // various line item object types
103
-    const OBJ_TYPE_EVENT       = 'Event';
104
-
105
-    const OBJ_TYPE_PRICE       = 'Price';
106
-
107
-    const OBJ_TYPE_PROMOTION   = 'Promotion';
108
-
109
-    const OBJ_TYPE_TICKET      = 'Ticket';
110
-
111
-    const OBJ_TYPE_TRANSACTION = 'Transaction';
112
-
113
-    /**
114
-     * @var EEM_Line_Item $_instance
115
-     */
116
-    protected static $_instance;
117
-
118
-
119
-    /**
120
-     * private constructor to prevent direct creation
121
-     *
122
-     * @param string|null $timezone string representing the timezone we want to set for returned Date Time Strings
123
-     *                              (and any incoming timezone data that gets saved).
124
-     *                              Note this just sends the timezone info to the date time model field objects.
125
-     *                              Default is NULL
126
-     *                              (and will be assumed using the set timezone in the 'timezone_string' wp option)
127
-     * @throws EE_Error
128
-     * @throws ReflectionException
129
-     */
130
-    protected function __construct(?string $timezone = '')
131
-    {
132
-        $this->singular_item = esc_html__('Line Item', 'event_espresso');
133
-        $this->plural_item   = esc_html__('Line Items', 'event_espresso');
134
-
135
-        $this->_tables                 = [
136
-            'Line_Item' => new EE_Primary_Table('esp_line_item', 'LIN_ID'),
137
-        ];
138
-        $line_items_can_be_for         = apply_filters(
139
-            'FHEE__EEM_Line_Item__line_items_can_be_for',
140
-            ['Ticket', 'Price', 'Event']
141
-        );
142
-        $this->_fields                 = [
143
-            'Line_Item' => [
144
-                'LIN_ID'         => new EE_Primary_Key_Int_Field(
145
-                    'LIN_ID',
146
-                    esc_html__('ID', 'event_espresso')
147
-                ),
148
-                'LIN_code'       => new EE_Slug_Field(
149
-                    'LIN_code',
150
-                    esc_html__('Code for index into Cart', 'event_espresso'),
151
-                    true
152
-                ),
153
-                'TXN_ID'         => new EE_Foreign_Key_Int_Field(
154
-                    'TXN_ID',
155
-                    esc_html__('Transaction ID', 'event_espresso'),
156
-                    true,
157
-                    null,
158
-                    'Transaction'
159
-                ),
160
-                'LIN_name'       => new EE_Full_HTML_Field(
161
-                    'LIN_name',
162
-                    esc_html__('Line Item Name', 'event_espresso'),
163
-                    false,
164
-                    ''
165
-                ),
166
-                'LIN_desc'       => new EE_Full_HTML_Field(
167
-                    'LIN_desc',
168
-                    esc_html__('Line Item Description', 'event_espresso'),
169
-                    true
170
-                ),
171
-                'LIN_unit_price' => new EE_Money_Field(
172
-                    'LIN_unit_price',
173
-                    esc_html__('Unit Price', 'event_espresso'),
174
-                    false,
175
-                    0
176
-                ),
177
-                'LIN_percent'    => new EE_Float_Field(
178
-                    'LIN_percent',
179
-                    esc_html__('Percent', 'event_espresso'),
180
-                    false,
181
-                    0
182
-                ),
183
-                'LIN_is_taxable' => new EE_Boolean_Field(
184
-                    'LIN_is_taxable',
185
-                    esc_html__('Taxable', 'event_espresso'),
186
-                    false,
187
-                    false
188
-                ),
189
-                'LIN_order'      => new EE_Integer_Field(
190
-                    'LIN_order',
191
-                    esc_html__('Order of Application towards total of parent', 'event_espresso'),
192
-                    false,
193
-                    1
194
-                ),
195
-                'LIN_total'      => new EE_Money_Field(
196
-                    'LIN_total',
197
-                    esc_html__('Total (unit price x quantity) after taxes', 'event_espresso'),
198
-                    false,
199
-                    0
200
-                ),
201
-                'LIN_pretax'     => new EE_Money_Field(
202
-                    'LIN_pretax',
203
-                    esc_html__('Total (unit price x quantity) before taxes', 'event_espresso'),
204
-                    false,
205
-                    0
206
-                ),
207
-                'LIN_quantity'   => new EE_Integer_Field(
208
-                    'LIN_quantity',
209
-                    esc_html__('Quantity', 'event_espresso'),
210
-                    false,
211
-                    1
212
-                ),
213
-                'LIN_parent'     => new EE_Integer_Field(
214
-                    'LIN_parent',
215
-                    esc_html__("Parent ID (this item goes towards that Line Item's total)", 'event_espresso'),
216
-                    true,
217
-                    null
218
-                ),
219
-                'LIN_type'       => new EE_Enum_Text_Field(
220
-                    'LIN_type',
221
-                    esc_html__('Type', 'event_espresso'),
222
-                    false,
223
-                    'line-item',
224
-                    [
225
-                        self::type_line_item     => esc_html__('Line Item', 'event_espresso'),
226
-                        self::type_sub_line_item => esc_html__('Sub-Item', 'event_espresso'),
227
-                        self::type_sub_tax       => esc_html__('Sub-Tax', 'event_espresso'),
228
-                        self::type_sub_total     => esc_html__('Subtotal', 'event_espresso'),
229
-                        self::type_tax_sub_total => esc_html__('Tax Subtotal', 'event_espresso'),
230
-                        self::type_tax           => esc_html__('Tax', 'event_espresso'),
231
-                        self::type_total         => esc_html__('Total', 'event_espresso'),
232
-                        self::type_cancellation  => esc_html__('Cancellation', 'event_espresso'),
233
-                    ]
234
-                ),
235
-                'OBJ_ID'         => new EE_Foreign_Key_Int_Field(
236
-                    'OBJ_ID',
237
-                    esc_html__('ID of Item purchased.', 'event_espresso'),
238
-                    true,
239
-                    null,
240
-                    $line_items_can_be_for
241
-                ),
242
-                'OBJ_type'       => new EE_Any_Foreign_Model_Name_Field(
243
-                    'OBJ_type',
244
-                    esc_html__('Model Name this Line Item is for', 'event_espresso'),
245
-                    true,
246
-                    null,
247
-                    $line_items_can_be_for
248
-                ),
249
-                'LIN_timestamp'  => new EE_Datetime_Field(
250
-                    'LIN_timestamp',
251
-                    esc_html__('When the line item was created', 'event_espresso'),
252
-                    false,
253
-                    EE_Datetime_Field::now,
254
-                    $timezone
255
-                ),
256
-            ],
257
-        ];
258
-        $this->_model_relations        = [
259
-            'Transaction' => new EE_Belongs_To_Relation(),
260
-            'Ticket'      => new EE_Belongs_To_Any_Relation(),
261
-            'Price'       => new EE_Belongs_To_Any_Relation(),
262
-            'Event'       => new EE_Belongs_To_Any_Relation(),
263
-        ];
264
-        $this->_model_chain_to_wp_user = 'Transaction.Registration.Event';
265
-        $this->_caps_slug              = 'transactions';
266
-        parent::__construct($timezone);
267
-    }
268
-
269
-
270
-    /**
271
-     * Gets all the line items for this transaction of the given type
272
-     *
273
-     * @param string             $line_item_type like one of EEM_Line_Item::type_*
274
-     * @param EE_Transaction|int $transaction
275
-     * @return EE_Base_Class[]|EE_Line_Item[]
276
-     * @throws EE_Error
277
-     * @throws InvalidArgumentException
278
-     * @throws InvalidDataTypeException
279
-     * @throws InvalidInterfaceException
280
-     */
281
-    public function get_all_of_type_for_transaction($line_item_type, $transaction)
282
-    {
283
-        $transaction = EEM_Transaction::instance()->ensure_is_ID($transaction);
284
-        return $this->get_all(
285
-            [
286
-                [
287
-                    'LIN_type' => $line_item_type,
288
-                    'TXN_ID'   => $transaction,
289
-                ],
290
-            ]
291
-        );
292
-    }
293
-
294
-
295
-    /**
296
-     * Gets all line items unrelated to tickets that are normal line items
297
-     * (eg shipping, promotions, and miscellaneous other stuff should probably fit in this category)
298
-     *
299
-     * @param EE_Transaction|int $transaction
300
-     * @return EE_Base_Class[]|EE_Line_Item[]
301
-     * @throws EE_Error
302
-     * @throws InvalidArgumentException
303
-     * @throws InvalidDataTypeException
304
-     * @throws InvalidInterfaceException
305
-     */
306
-    public function get_all_non_ticket_line_items_for_transaction($transaction)
307
-    {
308
-        $transaction = EEM_Transaction::instance()->ensure_is_ID($transaction);
309
-        return $this->get_all(
310
-            [
311
-                [
312
-                    'LIN_type' => self::type_line_item,
313
-                    'TXN_ID'   => $transaction,
314
-                    'OR'       => [
315
-                        'OBJ_type*notticket' => ['!=', EEM_Line_Item::OBJ_TYPE_TICKET],
316
-                        'OBJ_type*null'      => ['IS_NULL'],
317
-                    ],
318
-                ],
319
-            ]
320
-        );
321
-    }
322
-
323
-
324
-    /**
325
-     * Deletes line items with no transaction who have passed the transaction cutoff time.
326
-     * This needs to be very efficient
327
-     * because if there are spam bots afoot there will be LOTS of line items. Also MySQL doesn't allow a limit when
328
-     * deleting and joining tables like this.
329
-     *
330
-     * @return int count of how many deleted
331
-     * @throws EE_Error
332
-     * @throws InvalidArgumentException
333
-     * @throws InvalidDataTypeException
334
-     * @throws InvalidInterfaceException
335
-     */
336
-    public function delete_line_items_with_no_transaction()
337
-    {
338
-        /** @type WPDB $wpdb */
339
-        global $wpdb;
340
-        $time_to_leave_alone = apply_filters(
341
-            'FHEE__EEM_Line_Item__delete_line_items_with_no_transaction__time_to_leave_alone',
342
-            WEEK_IN_SECONDS
343
-        );
344
-        $query               = $wpdb->prepare(
345
-            'DELETE li
30
+	/**
31
+	 * Tax sub-total is just the total of all the taxes, which should be children
32
+	 * of this line item. There should only ever be one tax sub-total, and it should
33
+	 * be a direct child of the grand total. Its quantity and LIN_unit_price = 1.
34
+	 */
35
+	const type_tax_sub_total = 'tax-sub-total';
36
+
37
+	/**
38
+	 * Tax line items indicate a tax applied to all the taxable line items.
39
+	 * Should not have any children line items. Its LIN_unit_price = 0. Its LIN_percent is a percent, not a decimal
40
+	 * (eg 10% tax = 10, not 0.1). Its LIN_total = LIN_unit_price * pre-tax-total. Quantity = 1.
41
+	 */
42
+	const type_tax = 'tax';
43
+
44
+	/**
45
+	 * Indicating individual items purchased, or discounts or surcharges.
46
+	 * The sum of all the regular line items  plus the tax items should equal the grand total.
47
+	 * Possible children are sub-line-items and cancellations.
48
+	 * For flat items, LIN_unit_price * LIN_quantity = LIN_total. Its LIN_total is the sum of all the children
49
+	 * LIN_totals. Its LIN_percent = 0.
50
+	 * For percent items, its LIN_unit_price = 0. Its LIN_percent is a percent, not a decimal (eg 10% = 10, not 0.1).
51
+	 * Its LIN_total is LIN_percent / 100 * sum of lower-priority sibling line items. Quantity = 1.
52
+	 */
53
+	const type_line_item = 'line-item';
54
+
55
+	/**
56
+	 * Line item indicating all the factors that make a single line item.
57
+	 * Sub-line items should have NO children line items.
58
+	 * For flat sub-items, their quantity should match their parent item, their LIN_unit_price should be this sub-item's
59
+	 * contribution towards the price of ONE of their parent items, and its LIN_total should be
60
+	 *  = LIN_quantity * LIN_unit_price. Its LIN_percent = 0.
61
+	 * For percent sub-items, the quantity should be 1, LIN_unit_price should be 0, and its LIN_total should
62
+	 * = LIN_percent / 100 * sum of lower-priority sibling line items..
63
+	 */
64
+	const type_sub_line_item = 'sub-item';
65
+
66
+	/**
67
+	 * SubTax line items indicate a tax that is only applied to the pre-tax total of their parent line item.
68
+	 * Should not have any children line items. Its LIN_unit_price = 0. Its LIN_percent is a percent, not a decimal
69
+	 * (eg 10% tax = 10, not 0.1). Its LIN_total = LIN_unit_price * pre-tax-total. Quantity = 1.
70
+	 */
71
+	const type_sub_tax = 'sub-tax';
72
+
73
+	/**
74
+	 * Line item indicating a sub-total (eg total for an event, or pre-tax subtotal).
75
+	 * Direct children should be event subtotals.
76
+	 * Should have quantity of 1, and a LIN_total and LIN_unit_price of the sum of all its sub-items' LIN_totals.
77
+	 */
78
+	const type_sub_total = 'sub-total';
79
+
80
+	/**
81
+	 * Line item for the grand total of an order.
82
+	 * Its direct children should be tax subtotals and (pre-tax) subtotals,
83
+	 * and possibly a regular line item indicating a transaction-wide discount/surcharge.
84
+	 * Should have a quantity of 1, a LIN_total and LIN_unit_price of the entire order's amount.
85
+	 */
86
+	const type_total = 'total';
87
+
88
+	/**
89
+	 * When a line item is cancelled, a sub-line-item of type 'cancellation'
90
+	 * should be created, indicating the quantity that were cancelled
91
+	 * (because a line item could have a quantity of 1, and its cancellation item
92
+	 * could be for 3, indicating that originally 4 were purchased, but 3 have been
93
+	 * cancelled, and only one remains).
94
+	 * When items are refunded, a cancellation line item should be made, which points
95
+	 * to teh payment model object which actually refunded the payment.
96
+	 * Cancellations should NOT have any children line items; the should NOT affect
97
+	 * any calculations, and are only meant as a record that cancellations have occurred.
98
+	 * Their LIN_percent should be 0.
99
+	 */
100
+	const type_cancellation = 'cancellation';
101
+
102
+	// various line item object types
103
+	const OBJ_TYPE_EVENT       = 'Event';
104
+
105
+	const OBJ_TYPE_PRICE       = 'Price';
106
+
107
+	const OBJ_TYPE_PROMOTION   = 'Promotion';
108
+
109
+	const OBJ_TYPE_TICKET      = 'Ticket';
110
+
111
+	const OBJ_TYPE_TRANSACTION = 'Transaction';
112
+
113
+	/**
114
+	 * @var EEM_Line_Item $_instance
115
+	 */
116
+	protected static $_instance;
117
+
118
+
119
+	/**
120
+	 * private constructor to prevent direct creation
121
+	 *
122
+	 * @param string|null $timezone string representing the timezone we want to set for returned Date Time Strings
123
+	 *                              (and any incoming timezone data that gets saved).
124
+	 *                              Note this just sends the timezone info to the date time model field objects.
125
+	 *                              Default is NULL
126
+	 *                              (and will be assumed using the set timezone in the 'timezone_string' wp option)
127
+	 * @throws EE_Error
128
+	 * @throws ReflectionException
129
+	 */
130
+	protected function __construct(?string $timezone = '')
131
+	{
132
+		$this->singular_item = esc_html__('Line Item', 'event_espresso');
133
+		$this->plural_item   = esc_html__('Line Items', 'event_espresso');
134
+
135
+		$this->_tables                 = [
136
+			'Line_Item' => new EE_Primary_Table('esp_line_item', 'LIN_ID'),
137
+		];
138
+		$line_items_can_be_for         = apply_filters(
139
+			'FHEE__EEM_Line_Item__line_items_can_be_for',
140
+			['Ticket', 'Price', 'Event']
141
+		);
142
+		$this->_fields                 = [
143
+			'Line_Item' => [
144
+				'LIN_ID'         => new EE_Primary_Key_Int_Field(
145
+					'LIN_ID',
146
+					esc_html__('ID', 'event_espresso')
147
+				),
148
+				'LIN_code'       => new EE_Slug_Field(
149
+					'LIN_code',
150
+					esc_html__('Code for index into Cart', 'event_espresso'),
151
+					true
152
+				),
153
+				'TXN_ID'         => new EE_Foreign_Key_Int_Field(
154
+					'TXN_ID',
155
+					esc_html__('Transaction ID', 'event_espresso'),
156
+					true,
157
+					null,
158
+					'Transaction'
159
+				),
160
+				'LIN_name'       => new EE_Full_HTML_Field(
161
+					'LIN_name',
162
+					esc_html__('Line Item Name', 'event_espresso'),
163
+					false,
164
+					''
165
+				),
166
+				'LIN_desc'       => new EE_Full_HTML_Field(
167
+					'LIN_desc',
168
+					esc_html__('Line Item Description', 'event_espresso'),
169
+					true
170
+				),
171
+				'LIN_unit_price' => new EE_Money_Field(
172
+					'LIN_unit_price',
173
+					esc_html__('Unit Price', 'event_espresso'),
174
+					false,
175
+					0
176
+				),
177
+				'LIN_percent'    => new EE_Float_Field(
178
+					'LIN_percent',
179
+					esc_html__('Percent', 'event_espresso'),
180
+					false,
181
+					0
182
+				),
183
+				'LIN_is_taxable' => new EE_Boolean_Field(
184
+					'LIN_is_taxable',
185
+					esc_html__('Taxable', 'event_espresso'),
186
+					false,
187
+					false
188
+				),
189
+				'LIN_order'      => new EE_Integer_Field(
190
+					'LIN_order',
191
+					esc_html__('Order of Application towards total of parent', 'event_espresso'),
192
+					false,
193
+					1
194
+				),
195
+				'LIN_total'      => new EE_Money_Field(
196
+					'LIN_total',
197
+					esc_html__('Total (unit price x quantity) after taxes', 'event_espresso'),
198
+					false,
199
+					0
200
+				),
201
+				'LIN_pretax'     => new EE_Money_Field(
202
+					'LIN_pretax',
203
+					esc_html__('Total (unit price x quantity) before taxes', 'event_espresso'),
204
+					false,
205
+					0
206
+				),
207
+				'LIN_quantity'   => new EE_Integer_Field(
208
+					'LIN_quantity',
209
+					esc_html__('Quantity', 'event_espresso'),
210
+					false,
211
+					1
212
+				),
213
+				'LIN_parent'     => new EE_Integer_Field(
214
+					'LIN_parent',
215
+					esc_html__("Parent ID (this item goes towards that Line Item's total)", 'event_espresso'),
216
+					true,
217
+					null
218
+				),
219
+				'LIN_type'       => new EE_Enum_Text_Field(
220
+					'LIN_type',
221
+					esc_html__('Type', 'event_espresso'),
222
+					false,
223
+					'line-item',
224
+					[
225
+						self::type_line_item     => esc_html__('Line Item', 'event_espresso'),
226
+						self::type_sub_line_item => esc_html__('Sub-Item', 'event_espresso'),
227
+						self::type_sub_tax       => esc_html__('Sub-Tax', 'event_espresso'),
228
+						self::type_sub_total     => esc_html__('Subtotal', 'event_espresso'),
229
+						self::type_tax_sub_total => esc_html__('Tax Subtotal', 'event_espresso'),
230
+						self::type_tax           => esc_html__('Tax', 'event_espresso'),
231
+						self::type_total         => esc_html__('Total', 'event_espresso'),
232
+						self::type_cancellation  => esc_html__('Cancellation', 'event_espresso'),
233
+					]
234
+				),
235
+				'OBJ_ID'         => new EE_Foreign_Key_Int_Field(
236
+					'OBJ_ID',
237
+					esc_html__('ID of Item purchased.', 'event_espresso'),
238
+					true,
239
+					null,
240
+					$line_items_can_be_for
241
+				),
242
+				'OBJ_type'       => new EE_Any_Foreign_Model_Name_Field(
243
+					'OBJ_type',
244
+					esc_html__('Model Name this Line Item is for', 'event_espresso'),
245
+					true,
246
+					null,
247
+					$line_items_can_be_for
248
+				),
249
+				'LIN_timestamp'  => new EE_Datetime_Field(
250
+					'LIN_timestamp',
251
+					esc_html__('When the line item was created', 'event_espresso'),
252
+					false,
253
+					EE_Datetime_Field::now,
254
+					$timezone
255
+				),
256
+			],
257
+		];
258
+		$this->_model_relations        = [
259
+			'Transaction' => new EE_Belongs_To_Relation(),
260
+			'Ticket'      => new EE_Belongs_To_Any_Relation(),
261
+			'Price'       => new EE_Belongs_To_Any_Relation(),
262
+			'Event'       => new EE_Belongs_To_Any_Relation(),
263
+		];
264
+		$this->_model_chain_to_wp_user = 'Transaction.Registration.Event';
265
+		$this->_caps_slug              = 'transactions';
266
+		parent::__construct($timezone);
267
+	}
268
+
269
+
270
+	/**
271
+	 * Gets all the line items for this transaction of the given type
272
+	 *
273
+	 * @param string             $line_item_type like one of EEM_Line_Item::type_*
274
+	 * @param EE_Transaction|int $transaction
275
+	 * @return EE_Base_Class[]|EE_Line_Item[]
276
+	 * @throws EE_Error
277
+	 * @throws InvalidArgumentException
278
+	 * @throws InvalidDataTypeException
279
+	 * @throws InvalidInterfaceException
280
+	 */
281
+	public function get_all_of_type_for_transaction($line_item_type, $transaction)
282
+	{
283
+		$transaction = EEM_Transaction::instance()->ensure_is_ID($transaction);
284
+		return $this->get_all(
285
+			[
286
+				[
287
+					'LIN_type' => $line_item_type,
288
+					'TXN_ID'   => $transaction,
289
+				],
290
+			]
291
+		);
292
+	}
293
+
294
+
295
+	/**
296
+	 * Gets all line items unrelated to tickets that are normal line items
297
+	 * (eg shipping, promotions, and miscellaneous other stuff should probably fit in this category)
298
+	 *
299
+	 * @param EE_Transaction|int $transaction
300
+	 * @return EE_Base_Class[]|EE_Line_Item[]
301
+	 * @throws EE_Error
302
+	 * @throws InvalidArgumentException
303
+	 * @throws InvalidDataTypeException
304
+	 * @throws InvalidInterfaceException
305
+	 */
306
+	public function get_all_non_ticket_line_items_for_transaction($transaction)
307
+	{
308
+		$transaction = EEM_Transaction::instance()->ensure_is_ID($transaction);
309
+		return $this->get_all(
310
+			[
311
+				[
312
+					'LIN_type' => self::type_line_item,
313
+					'TXN_ID'   => $transaction,
314
+					'OR'       => [
315
+						'OBJ_type*notticket' => ['!=', EEM_Line_Item::OBJ_TYPE_TICKET],
316
+						'OBJ_type*null'      => ['IS_NULL'],
317
+					],
318
+				],
319
+			]
320
+		);
321
+	}
322
+
323
+
324
+	/**
325
+	 * Deletes line items with no transaction who have passed the transaction cutoff time.
326
+	 * This needs to be very efficient
327
+	 * because if there are spam bots afoot there will be LOTS of line items. Also MySQL doesn't allow a limit when
328
+	 * deleting and joining tables like this.
329
+	 *
330
+	 * @return int count of how many deleted
331
+	 * @throws EE_Error
332
+	 * @throws InvalidArgumentException
333
+	 * @throws InvalidDataTypeException
334
+	 * @throws InvalidInterfaceException
335
+	 */
336
+	public function delete_line_items_with_no_transaction()
337
+	{
338
+		/** @type WPDB $wpdb */
339
+		global $wpdb;
340
+		$time_to_leave_alone = apply_filters(
341
+			'FHEE__EEM_Line_Item__delete_line_items_with_no_transaction__time_to_leave_alone',
342
+			WEEK_IN_SECONDS
343
+		);
344
+		$query               = $wpdb->prepare(
345
+			'DELETE li
346 346
 				FROM ' . $this->table() . ' li
347 347
 				LEFT JOIN ' . EEM_Transaction::instance()->table() . ' t ON li.TXN_ID = t.TXN_ID
348 348
 				WHERE t.TXN_ID IS NULL AND li.LIN_timestamp < %s',
349
-            // use GMT time because that's what TXN_timestamps are in
350
-            date('Y-m-d H:i:s', time() - $time_to_leave_alone)
351
-        );
352
-        return $wpdb->query($query);
353
-    }
354
-
355
-
356
-    /**
357
-     * get_line_item_for_transaction_object
358
-     * Gets a transaction's line item record for a specific object such as a EE_Event or EE_Ticket
359
-     *
360
-     * @param int           $TXN_ID
361
-     * @param EE_Base_Class $object
362
-     * @return EE_Base_Class[]|EE_Line_Item[]
363
-     * @throws EE_Error
364
-     * @throws InvalidArgumentException
365
-     * @throws InvalidDataTypeException
366
-     * @throws InvalidInterfaceException
367
-     * @throws ReflectionException
368
-     */
369
-    public function get_line_item_for_transaction_object($TXN_ID, EE_Base_Class $object)
370
-    {
371
-        return $this->get_all(
372
-            [
373
-                [
374
-                    'TXN_ID'   => $TXN_ID,
375
-                    'OBJ_type' => str_replace('EE_', '', get_class($object)),
376
-                    'OBJ_ID'   => $object->ID(),
377
-                ],
378
-            ]
379
-        );
380
-    }
381
-
382
-
383
-    /**
384
-     * get_object_line_items_for_transaction
385
-     * Gets all of the the object line items for a transaction, based on an object type plus an array of object IDs
386
-     *
387
-     * @param int    $TXN_ID
388
-     * @param string $OBJ_type
389
-     * @param array  $OBJ_IDs
390
-     * @return EE_Base_Class[]|EE_Line_Item[]
391
-     * @throws EE_Error
392
-     */
393
-    public function get_object_line_items_for_transaction(
394
-        $TXN_ID,
395
-        $OBJ_type = EEM_Line_Item::OBJ_TYPE_EVENT,
396
-        $OBJ_IDs = []
397
-    ) {
398
-        $query_params = [
399
-            'OBJ_type' => $OBJ_type,
400
-            // if incoming $OBJ_IDs is an array, then make sure it is formatted correctly for the query
401
-            'OBJ_ID'   => is_array($OBJ_IDs) && ! isset($OBJ_IDs['IN']) ? ['IN', $OBJ_IDs] : $OBJ_IDs,
402
-        ];
403
-        if ($TXN_ID) {
404
-            $query_params['TXN_ID'] = $TXN_ID;
405
-        }
406
-        return $this->get_all([$query_params]);
407
-    }
408
-
409
-
410
-    /**
411
-     * get_all_ticket_line_items_for_transaction
412
-     *
413
-     * @param EE_Transaction $transaction
414
-     * @return EE_Base_Class[]|EE_Line_Item[]
415
-     * @throws EE_Error
416
-     * @throws InvalidArgumentException
417
-     * @throws InvalidDataTypeException
418
-     * @throws InvalidInterfaceException
419
-     * @throws ReflectionException
420
-     */
421
-    public function get_all_ticket_line_items_for_transaction(EE_Transaction $transaction)
422
-    {
423
-        return $this->get_all(
424
-            [
425
-                [
426
-                    'TXN_ID'   => $transaction->ID(),
427
-                    'OBJ_type' => EEM_Line_Item::OBJ_TYPE_TICKET,
428
-                ],
429
-            ]
430
-        );
431
-    }
432
-
433
-
434
-    /**
435
-     * get_ticket_line_item_for_transaction
436
-     *
437
-     * @param int $TXN_ID
438
-     * @param int $TKT_ID
439
-     * @return EE_Base_Class|EE_Line_Item|EE_Soft_Delete_Base_Class|NULL
440
-     * @throws EE_Error
441
-     * @throws InvalidArgumentException
442
-     * @throws InvalidDataTypeException
443
-     * @throws InvalidInterfaceException
444
-     */
445
-    public function get_ticket_line_item_for_transaction($TXN_ID, $TKT_ID)
446
-    {
447
-        return $this->get_one(
448
-            [
449
-                [
450
-                    'TXN_ID'   => EEM_Transaction::instance()->ensure_is_ID($TXN_ID),
451
-                    'OBJ_ID'   => $TKT_ID,
452
-                    'OBJ_type' => EEM_Line_Item::OBJ_TYPE_TICKET,
453
-                ],
454
-            ]
455
-        );
456
-    }
457
-
458
-
459
-    /**
460
-     * get_existing_promotion_line_item
461
-     * searches the cart for existing line items for the specified promotion
462
-     *
463
-     * @param EE_Line_Item $parent_line_item
464
-     * @param EE_Promotion $promotion
465
-     * @return EE_Base_Class|EE_Line_Item|EE_Soft_Delete_Base_Class|NULL
466
-     * @throws EE_Error
467
-     * @throws InvalidArgumentException
468
-     * @throws InvalidDataTypeException
469
-     * @throws InvalidInterfaceException
470
-     * @throws ReflectionException
471
-     * @since 1.0.0
472
-     */
473
-    public function get_existing_promotion_line_item(EE_Line_Item $parent_line_item, EE_Promotion $promotion)
474
-    {
475
-        return $this->get_one(
476
-            [
477
-                [
478
-                    'TXN_ID'     => $parent_line_item->TXN_ID(),
479
-                    'LIN_parent' => $parent_line_item->ID(),
480
-                    'OBJ_type'   => EEM_Line_Item::OBJ_TYPE_PROMOTION,
481
-                    'OBJ_ID'     => $promotion->ID(),
482
-                ],
483
-            ]
484
-        );
485
-    }
486
-
487
-
488
-    /**
489
-     * get_all_promotion_line_items
490
-     * searches the cart for any and all existing promotion line items
491
-     *
492
-     * @param EE_Line_Item $parent_line_item
493
-     * @return EE_Base_Class[]|EE_Line_Item[]
494
-     * @throws EE_Error
495
-     * @throws InvalidArgumentException
496
-     * @throws InvalidDataTypeException
497
-     * @throws InvalidInterfaceException
498
-     * @throws ReflectionException
499
-     * @since   1.0.0
500
-     */
501
-    public function get_all_promotion_line_items(EE_Line_Item $parent_line_item)
502
-    {
503
-        return $this->get_all(
504
-            [
505
-                [
506
-                    'TXN_ID'     => $parent_line_item->TXN_ID(),
507
-                    'LIN_parent' => $parent_line_item->ID(),
508
-                    'OBJ_type'   => EEM_Line_Item::OBJ_TYPE_PROMOTION,
509
-                ],
510
-            ]
511
-        );
512
-    }
513
-
514
-
515
-    /**
516
-     * Gets the registration's corresponding line item.
517
-     * Note: basically does NOT support having multiple line items for a single ticket,
518
-     * which would happen if some of the registrations had a price modifier while others didn't.
519
-     * In order to support that, we'd probably need a LIN_ID on registrations or something.
520
-     *
521
-     * @param EE_Registration $registration
522
-     * @return EE_Base_Class|EE_Line_ITem|EE_Soft_Delete_Base_Class|NULL
523
-     * @throws EE_Error
524
-     */
525
-    public function get_line_item_for_registration(EE_Registration $registration)
526
-    {
527
-        return $this->get_one($this->line_item_for_registration_query_params($registration));
528
-    }
529
-
530
-
531
-    /**
532
-     * Gets the query params used to retrieve a specific line item for the given registration
533
-     *
534
-     * @param EE_Registration $registration
535
-     * @param array           $original_query_params any extra query params you'd like to be merged with
536
-     * @return array @see
537
-     *                                               https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
538
-     * @throws EE_Error
539
-     */
540
-    public function line_item_for_registration_query_params(
541
-        EE_Registration $registration,
542
-        $original_query_params = []
543
-    ) {
544
-        return array_replace_recursive(
545
-            $original_query_params,
546
-            [
547
-                [
548
-                    'OBJ_ID'   => $registration->ticket_ID(),
549
-                    'OBJ_type' => EEM_Line_Item::OBJ_TYPE_TICKET,
550
-                    'TXN_ID'   => $registration->transaction_ID(),
551
-                ],
552
-            ]
553
-        );
554
-    }
555
-
556
-
557
-    /**
558
-     * @return EE_Base_Class[]|EE_Line_Item[]
559
-     * @throws InvalidInterfaceException
560
-     * @throws InvalidDataTypeException
561
-     * @throws EE_Error
562
-     * @throws InvalidArgumentException
563
-     */
564
-    public function get_total_line_items_with_no_transaction()
565
-    {
566
-        return $this->get_total_line_items_for_carts();
567
-    }
568
-
569
-
570
-    /**
571
-     * @return EE_Base_Class[]|EE_Line_Item[]
572
-     * @throws InvalidInterfaceException
573
-     * @throws InvalidDataTypeException
574
-     * @throws EE_Error
575
-     * @throws InvalidArgumentException
576
-     */
577
-    public function get_total_line_items_for_active_carts()
578
-    {
579
-        return $this->get_total_line_items_for_carts(false);
580
-    }
581
-
582
-
583
-    /**
584
-     * @return EE_Base_Class[]|EE_Line_Item[]
585
-     * @throws InvalidInterfaceException
586
-     * @throws InvalidDataTypeException
587
-     * @throws EE_Error
588
-     * @throws InvalidArgumentException
589
-     */
590
-    public function get_total_line_items_for_expired_carts()
591
-    {
592
-        return $this->get_total_line_items_for_carts(true);
593
-    }
594
-
595
-
596
-    /**
597
-     * Returns an array of grand total line items where the TXN_ID is 0.
598
-     * If $expired is set to true, then only line items for expired sessions will be returned.
599
-     * If $expired is set to false, then only line items for active sessions will be returned.
600
-     *
601
-     * @param null $expired
602
-     * @return EE_Base_Class[]|EE_Line_Item[]
603
-     * @throws EE_Error
604
-     * @throws InvalidArgumentException
605
-     * @throws InvalidDataTypeException
606
-     * @throws InvalidInterfaceException
607
-     */
608
-    private function get_total_line_items_for_carts($expired = null)
609
-    {
610
-        $where_params = [
611
-            'TXN_ID'   => 0,
612
-            'LIN_type' => 'total',
613
-        ];
614
-        if ($expired !== null) {
615
-            /** @var EventEspresso\core\domain\values\session\SessionLifespan $session_lifespan */
616
-            $session_lifespan              = LoaderFactory::getLoader()->getShared(
617
-                'EventEspresso\core\domain\values\session\SessionLifespan'
618
-            );
619
-            $where_params['LIN_timestamp'] = [
620
-                $expired ? '<=' : '>',
621
-                $session_lifespan->expiration(),
622
-            ];
623
-        }
624
-        return $this->get_all([$where_params]);
625
-    }
626
-
627
-
628
-    /**
629
-     * Returns an array of ticket total line items where the TXN_ID is 0
630
-     * AND the timestamp is older than the session lifespan.
631
-     *
632
-     * @param int $timestamp
633
-     * @return EE_Base_Class[]|EE_Line_Item[]
634
-     * @throws EE_Error
635
-     * @throws InvalidArgumentException
636
-     * @throws InvalidDataTypeException
637
-     * @throws InvalidInterfaceException
638
-     */
639
-    public function getTicketLineItemsForExpiredCarts($timestamp = 0)
640
-    {
641
-        if (! absint($timestamp)) {
642
-            /** @var EventEspresso\core\domain\values\session\SessionLifespan $session_lifespan */
643
-            $session_lifespan = LoaderFactory::getLoader()->getShared(
644
-                'EventEspresso\core\domain\values\session\SessionLifespan'
645
-            );
646
-            $timestamp        = $session_lifespan->expiration();
647
-        }
648
-        return $this->get_all(
649
-            [
650
-                [
651
-                    'TXN_ID'        => 0,
652
-                    'OBJ_type'      => EEM_Line_Item::OBJ_TYPE_TICKET,
653
-                    'LIN_timestamp' => ['<=', $timestamp],
654
-                ],
655
-            ]
656
-        );
657
-    }
349
+			// use GMT time because that's what TXN_timestamps are in
350
+			date('Y-m-d H:i:s', time() - $time_to_leave_alone)
351
+		);
352
+		return $wpdb->query($query);
353
+	}
354
+
355
+
356
+	/**
357
+	 * get_line_item_for_transaction_object
358
+	 * Gets a transaction's line item record for a specific object such as a EE_Event or EE_Ticket
359
+	 *
360
+	 * @param int           $TXN_ID
361
+	 * @param EE_Base_Class $object
362
+	 * @return EE_Base_Class[]|EE_Line_Item[]
363
+	 * @throws EE_Error
364
+	 * @throws InvalidArgumentException
365
+	 * @throws InvalidDataTypeException
366
+	 * @throws InvalidInterfaceException
367
+	 * @throws ReflectionException
368
+	 */
369
+	public function get_line_item_for_transaction_object($TXN_ID, EE_Base_Class $object)
370
+	{
371
+		return $this->get_all(
372
+			[
373
+				[
374
+					'TXN_ID'   => $TXN_ID,
375
+					'OBJ_type' => str_replace('EE_', '', get_class($object)),
376
+					'OBJ_ID'   => $object->ID(),
377
+				],
378
+			]
379
+		);
380
+	}
381
+
382
+
383
+	/**
384
+	 * get_object_line_items_for_transaction
385
+	 * Gets all of the the object line items for a transaction, based on an object type plus an array of object IDs
386
+	 *
387
+	 * @param int    $TXN_ID
388
+	 * @param string $OBJ_type
389
+	 * @param array  $OBJ_IDs
390
+	 * @return EE_Base_Class[]|EE_Line_Item[]
391
+	 * @throws EE_Error
392
+	 */
393
+	public function get_object_line_items_for_transaction(
394
+		$TXN_ID,
395
+		$OBJ_type = EEM_Line_Item::OBJ_TYPE_EVENT,
396
+		$OBJ_IDs = []
397
+	) {
398
+		$query_params = [
399
+			'OBJ_type' => $OBJ_type,
400
+			// if incoming $OBJ_IDs is an array, then make sure it is formatted correctly for the query
401
+			'OBJ_ID'   => is_array($OBJ_IDs) && ! isset($OBJ_IDs['IN']) ? ['IN', $OBJ_IDs] : $OBJ_IDs,
402
+		];
403
+		if ($TXN_ID) {
404
+			$query_params['TXN_ID'] = $TXN_ID;
405
+		}
406
+		return $this->get_all([$query_params]);
407
+	}
408
+
409
+
410
+	/**
411
+	 * get_all_ticket_line_items_for_transaction
412
+	 *
413
+	 * @param EE_Transaction $transaction
414
+	 * @return EE_Base_Class[]|EE_Line_Item[]
415
+	 * @throws EE_Error
416
+	 * @throws InvalidArgumentException
417
+	 * @throws InvalidDataTypeException
418
+	 * @throws InvalidInterfaceException
419
+	 * @throws ReflectionException
420
+	 */
421
+	public function get_all_ticket_line_items_for_transaction(EE_Transaction $transaction)
422
+	{
423
+		return $this->get_all(
424
+			[
425
+				[
426
+					'TXN_ID'   => $transaction->ID(),
427
+					'OBJ_type' => EEM_Line_Item::OBJ_TYPE_TICKET,
428
+				],
429
+			]
430
+		);
431
+	}
432
+
433
+
434
+	/**
435
+	 * get_ticket_line_item_for_transaction
436
+	 *
437
+	 * @param int $TXN_ID
438
+	 * @param int $TKT_ID
439
+	 * @return EE_Base_Class|EE_Line_Item|EE_Soft_Delete_Base_Class|NULL
440
+	 * @throws EE_Error
441
+	 * @throws InvalidArgumentException
442
+	 * @throws InvalidDataTypeException
443
+	 * @throws InvalidInterfaceException
444
+	 */
445
+	public function get_ticket_line_item_for_transaction($TXN_ID, $TKT_ID)
446
+	{
447
+		return $this->get_one(
448
+			[
449
+				[
450
+					'TXN_ID'   => EEM_Transaction::instance()->ensure_is_ID($TXN_ID),
451
+					'OBJ_ID'   => $TKT_ID,
452
+					'OBJ_type' => EEM_Line_Item::OBJ_TYPE_TICKET,
453
+				],
454
+			]
455
+		);
456
+	}
457
+
458
+
459
+	/**
460
+	 * get_existing_promotion_line_item
461
+	 * searches the cart for existing line items for the specified promotion
462
+	 *
463
+	 * @param EE_Line_Item $parent_line_item
464
+	 * @param EE_Promotion $promotion
465
+	 * @return EE_Base_Class|EE_Line_Item|EE_Soft_Delete_Base_Class|NULL
466
+	 * @throws EE_Error
467
+	 * @throws InvalidArgumentException
468
+	 * @throws InvalidDataTypeException
469
+	 * @throws InvalidInterfaceException
470
+	 * @throws ReflectionException
471
+	 * @since 1.0.0
472
+	 */
473
+	public function get_existing_promotion_line_item(EE_Line_Item $parent_line_item, EE_Promotion $promotion)
474
+	{
475
+		return $this->get_one(
476
+			[
477
+				[
478
+					'TXN_ID'     => $parent_line_item->TXN_ID(),
479
+					'LIN_parent' => $parent_line_item->ID(),
480
+					'OBJ_type'   => EEM_Line_Item::OBJ_TYPE_PROMOTION,
481
+					'OBJ_ID'     => $promotion->ID(),
482
+				],
483
+			]
484
+		);
485
+	}
486
+
487
+
488
+	/**
489
+	 * get_all_promotion_line_items
490
+	 * searches the cart for any and all existing promotion line items
491
+	 *
492
+	 * @param EE_Line_Item $parent_line_item
493
+	 * @return EE_Base_Class[]|EE_Line_Item[]
494
+	 * @throws EE_Error
495
+	 * @throws InvalidArgumentException
496
+	 * @throws InvalidDataTypeException
497
+	 * @throws InvalidInterfaceException
498
+	 * @throws ReflectionException
499
+	 * @since   1.0.0
500
+	 */
501
+	public function get_all_promotion_line_items(EE_Line_Item $parent_line_item)
502
+	{
503
+		return $this->get_all(
504
+			[
505
+				[
506
+					'TXN_ID'     => $parent_line_item->TXN_ID(),
507
+					'LIN_parent' => $parent_line_item->ID(),
508
+					'OBJ_type'   => EEM_Line_Item::OBJ_TYPE_PROMOTION,
509
+				],
510
+			]
511
+		);
512
+	}
513
+
514
+
515
+	/**
516
+	 * Gets the registration's corresponding line item.
517
+	 * Note: basically does NOT support having multiple line items for a single ticket,
518
+	 * which would happen if some of the registrations had a price modifier while others didn't.
519
+	 * In order to support that, we'd probably need a LIN_ID on registrations or something.
520
+	 *
521
+	 * @param EE_Registration $registration
522
+	 * @return EE_Base_Class|EE_Line_ITem|EE_Soft_Delete_Base_Class|NULL
523
+	 * @throws EE_Error
524
+	 */
525
+	public function get_line_item_for_registration(EE_Registration $registration)
526
+	{
527
+		return $this->get_one($this->line_item_for_registration_query_params($registration));
528
+	}
529
+
530
+
531
+	/**
532
+	 * Gets the query params used to retrieve a specific line item for the given registration
533
+	 *
534
+	 * @param EE_Registration $registration
535
+	 * @param array           $original_query_params any extra query params you'd like to be merged with
536
+	 * @return array @see
537
+	 *                                               https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
538
+	 * @throws EE_Error
539
+	 */
540
+	public function line_item_for_registration_query_params(
541
+		EE_Registration $registration,
542
+		$original_query_params = []
543
+	) {
544
+		return array_replace_recursive(
545
+			$original_query_params,
546
+			[
547
+				[
548
+					'OBJ_ID'   => $registration->ticket_ID(),
549
+					'OBJ_type' => EEM_Line_Item::OBJ_TYPE_TICKET,
550
+					'TXN_ID'   => $registration->transaction_ID(),
551
+				],
552
+			]
553
+		);
554
+	}
555
+
556
+
557
+	/**
558
+	 * @return EE_Base_Class[]|EE_Line_Item[]
559
+	 * @throws InvalidInterfaceException
560
+	 * @throws InvalidDataTypeException
561
+	 * @throws EE_Error
562
+	 * @throws InvalidArgumentException
563
+	 */
564
+	public function get_total_line_items_with_no_transaction()
565
+	{
566
+		return $this->get_total_line_items_for_carts();
567
+	}
568
+
569
+
570
+	/**
571
+	 * @return EE_Base_Class[]|EE_Line_Item[]
572
+	 * @throws InvalidInterfaceException
573
+	 * @throws InvalidDataTypeException
574
+	 * @throws EE_Error
575
+	 * @throws InvalidArgumentException
576
+	 */
577
+	public function get_total_line_items_for_active_carts()
578
+	{
579
+		return $this->get_total_line_items_for_carts(false);
580
+	}
581
+
582
+
583
+	/**
584
+	 * @return EE_Base_Class[]|EE_Line_Item[]
585
+	 * @throws InvalidInterfaceException
586
+	 * @throws InvalidDataTypeException
587
+	 * @throws EE_Error
588
+	 * @throws InvalidArgumentException
589
+	 */
590
+	public function get_total_line_items_for_expired_carts()
591
+	{
592
+		return $this->get_total_line_items_for_carts(true);
593
+	}
594
+
595
+
596
+	/**
597
+	 * Returns an array of grand total line items where the TXN_ID is 0.
598
+	 * If $expired is set to true, then only line items for expired sessions will be returned.
599
+	 * If $expired is set to false, then only line items for active sessions will be returned.
600
+	 *
601
+	 * @param null $expired
602
+	 * @return EE_Base_Class[]|EE_Line_Item[]
603
+	 * @throws EE_Error
604
+	 * @throws InvalidArgumentException
605
+	 * @throws InvalidDataTypeException
606
+	 * @throws InvalidInterfaceException
607
+	 */
608
+	private function get_total_line_items_for_carts($expired = null)
609
+	{
610
+		$where_params = [
611
+			'TXN_ID'   => 0,
612
+			'LIN_type' => 'total',
613
+		];
614
+		if ($expired !== null) {
615
+			/** @var EventEspresso\core\domain\values\session\SessionLifespan $session_lifespan */
616
+			$session_lifespan              = LoaderFactory::getLoader()->getShared(
617
+				'EventEspresso\core\domain\values\session\SessionLifespan'
618
+			);
619
+			$where_params['LIN_timestamp'] = [
620
+				$expired ? '<=' : '>',
621
+				$session_lifespan->expiration(),
622
+			];
623
+		}
624
+		return $this->get_all([$where_params]);
625
+	}
626
+
627
+
628
+	/**
629
+	 * Returns an array of ticket total line items where the TXN_ID is 0
630
+	 * AND the timestamp is older than the session lifespan.
631
+	 *
632
+	 * @param int $timestamp
633
+	 * @return EE_Base_Class[]|EE_Line_Item[]
634
+	 * @throws EE_Error
635
+	 * @throws InvalidArgumentException
636
+	 * @throws InvalidDataTypeException
637
+	 * @throws InvalidInterfaceException
638
+	 */
639
+	public function getTicketLineItemsForExpiredCarts($timestamp = 0)
640
+	{
641
+		if (! absint($timestamp)) {
642
+			/** @var EventEspresso\core\domain\values\session\SessionLifespan $session_lifespan */
643
+			$session_lifespan = LoaderFactory::getLoader()->getShared(
644
+				'EventEspresso\core\domain\values\session\SessionLifespan'
645
+			);
646
+			$timestamp        = $session_lifespan->expiration();
647
+		}
648
+		return $this->get_all(
649
+			[
650
+				[
651
+					'TXN_ID'        => 0,
652
+					'OBJ_type'      => EEM_Line_Item::OBJ_TYPE_TICKET,
653
+					'LIN_timestamp' => ['<=', $timestamp],
654
+				],
655
+			]
656
+		);
657
+	}
658 658
 }
Please login to merge, or discard this patch.
core/db_models/relations/EE_Belongs_To_Relation.php 2 patches
Indentation   +143 added lines, -143 removed lines patch added patch discarded remove patch
@@ -11,157 +11,157 @@
 block discarded – undo
11 11
  */
12 12
 class EE_Belongs_To_Relation extends EE_Model_Relation_Base
13 13
 {
14
-    /**
15
-     * Object representing the relationship between two models. Belongs_To means that THIS model has the foreign key
16
-     * to the other model. This knows how to join the models,
17
-     * get related models across the relation, and add-and-remove the relationships.
18
-     *
19
-     * @param bool   $block_deletes                                 For Belongs_To relations, this is set to FALSE by
20
-     *                                                              default. if there are related models across this
21
-     *                                                              relation, block (prevent and add an error) the
22
-     *                                                              deletion of this model
23
-     * @param string $related_model_objects_deletion_error_message  a customized error message on blocking deletes
24
-     *                                                              instead of the default
25
-     */
26
-    public function __construct(bool $block_deletes = false, string $related_model_objects_deletion_error_message = '')
27
-    {
28
-        parent::__construct($block_deletes, $related_model_objects_deletion_error_message);
29
-    }
14
+	/**
15
+	 * Object representing the relationship between two models. Belongs_To means that THIS model has the foreign key
16
+	 * to the other model. This knows how to join the models,
17
+	 * get related models across the relation, and add-and-remove the relationships.
18
+	 *
19
+	 * @param bool   $block_deletes                                 For Belongs_To relations, this is set to FALSE by
20
+	 *                                                              default. if there are related models across this
21
+	 *                                                              relation, block (prevent and add an error) the
22
+	 *                                                              deletion of this model
23
+	 * @param string $related_model_objects_deletion_error_message  a customized error message on blocking deletes
24
+	 *                                                              instead of the default
25
+	 */
26
+	public function __construct(bool $block_deletes = false, string $related_model_objects_deletion_error_message = '')
27
+	{
28
+		parent::__construct($block_deletes, $related_model_objects_deletion_error_message);
29
+	}
30 30
 
31 31
 
32
-    /**
33
-     * get_join_statement
34
-     *
35
-     * @param string $model_relation_chain
36
-     * @return string
37
-     * @throws EE_Error
38
-     * @throws Exception
39
-     */
40
-    public function get_join_statement(string $model_relation_chain): string
41
-    {
42
-        // create the sql string like
43
-        $this_table_fk_field  =
44
-            $this->get_this_model()->get_foreign_key_to($this->get_other_model()->get_this_model_name());
45
-        $other_table_pk_field = $this->get_other_model()->get_primary_key_field();
46
-        $this_table_alias     = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix(
47
-                $model_relation_chain,
48
-                $this->get_this_model()->get_this_model_name()
49
-            ) . $this_table_fk_field->get_table_alias();
50
-        $other_table_alias    = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix(
51
-                $model_relation_chain,
52
-                $this->get_other_model()->get_this_model_name()
53
-            ) . $other_table_pk_field->get_table_alias();
54
-        $other_table          = $this->get_other_model()->get_table_for_alias($other_table_alias);
55
-        return $this->_left_join(
56
-                $other_table,
57
-                $other_table_alias,
58
-                $other_table_pk_field->get_table_column(),
59
-                $this_table_alias,
60
-                $this_table_fk_field->get_table_column()
61
-            ) . $this->get_other_model()->_construct_internal_join_to_table_with_alias($other_table_alias);
62
-    }
32
+	/**
33
+	 * get_join_statement
34
+	 *
35
+	 * @param string $model_relation_chain
36
+	 * @return string
37
+	 * @throws EE_Error
38
+	 * @throws Exception
39
+	 */
40
+	public function get_join_statement(string $model_relation_chain): string
41
+	{
42
+		// create the sql string like
43
+		$this_table_fk_field  =
44
+			$this->get_this_model()->get_foreign_key_to($this->get_other_model()->get_this_model_name());
45
+		$other_table_pk_field = $this->get_other_model()->get_primary_key_field();
46
+		$this_table_alias     = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix(
47
+				$model_relation_chain,
48
+				$this->get_this_model()->get_this_model_name()
49
+			) . $this_table_fk_field->get_table_alias();
50
+		$other_table_alias    = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix(
51
+				$model_relation_chain,
52
+				$this->get_other_model()->get_this_model_name()
53
+			) . $other_table_pk_field->get_table_alias();
54
+		$other_table          = $this->get_other_model()->get_table_for_alias($other_table_alias);
55
+		return $this->_left_join(
56
+				$other_table,
57
+				$other_table_alias,
58
+				$other_table_pk_field->get_table_column(),
59
+				$this_table_alias,
60
+				$this_table_fk_field->get_table_column()
61
+			) . $this->get_other_model()->_construct_internal_join_to_table_with_alias($other_table_alias);
62
+	}
63 63
 
64 64
 
65
-    /**
66
-     * Sets this model object's foreign key to the other model object's primary key. Feel free to do this manually if
67
-     * you like.
68
-     *
69
-     * @param EE_Base_Class|int $this_obj_or_id
70
-     * @param EE_Base_Class|int $other_obj_or_id
71
-     * @param array             $extra_join_model_fields_n_values
72
-     * @return EE_Base_Class
73
-     * @throws EE_Error
74
-     * @throws Exception
75
-     */
76
-    public function add_relation_to(
77
-        $this_obj_or_id,
78
-        $other_obj_or_id,
79
-        array $extra_join_model_fields_n_values = []
80
-    ): EE_Base_Class {
81
-        $this_model_obj  = $this->get_this_model()->ensure_is_obj($this_obj_or_id, true);
82
-        $other_model_obj = $this->get_other_model()->ensure_is_obj($other_obj_or_id, true);
83
-        // find the field on the other model which is a foreign key to this model
84
-        $fk_on_this_model =
85
-            $this->get_this_model()->get_foreign_key_to($this->get_other_model()->get_this_model_name());
86
-        if ($this_model_obj->get($fk_on_this_model->get_name()) != $other_model_obj->ID()) {
87
-            // set that field on the other model to this model's ID
88
-            $this_model_obj->set($fk_on_this_model->get_name(), $other_model_obj->ID());
89
-            $this_model_obj->save();
90
-        }
91
-        return $other_model_obj;
92
-    }
65
+	/**
66
+	 * Sets this model object's foreign key to the other model object's primary key. Feel free to do this manually if
67
+	 * you like.
68
+	 *
69
+	 * @param EE_Base_Class|int $this_obj_or_id
70
+	 * @param EE_Base_Class|int $other_obj_or_id
71
+	 * @param array             $extra_join_model_fields_n_values
72
+	 * @return EE_Base_Class
73
+	 * @throws EE_Error
74
+	 * @throws Exception
75
+	 */
76
+	public function add_relation_to(
77
+		$this_obj_or_id,
78
+		$other_obj_or_id,
79
+		array $extra_join_model_fields_n_values = []
80
+	): EE_Base_Class {
81
+		$this_model_obj  = $this->get_this_model()->ensure_is_obj($this_obj_or_id, true);
82
+		$other_model_obj = $this->get_other_model()->ensure_is_obj($other_obj_or_id, true);
83
+		// find the field on the other model which is a foreign key to this model
84
+		$fk_on_this_model =
85
+			$this->get_this_model()->get_foreign_key_to($this->get_other_model()->get_this_model_name());
86
+		if ($this_model_obj->get($fk_on_this_model->get_name()) != $other_model_obj->ID()) {
87
+			// set that field on the other model to this model's ID
88
+			$this_model_obj->set($fk_on_this_model->get_name(), $other_model_obj->ID());
89
+			$this_model_obj->save();
90
+		}
91
+		return $other_model_obj;
92
+	}
93 93
 
94 94
 
95
-    /**
96
-     * Sets the this model object's foreign key to its default, instead of pointing to the other model object
97
-     *
98
-     * @param EE_Base_Class|int $this_obj_or_id
99
-     * @param EE_Base_Class|int $other_obj_or_id
100
-     * @param array             $where_query
101
-     * @return EE_Base_Class
102
-     * @throws EE_Error
103
-     * @throws Exception
104
-     */
105
-    public function remove_relation_to($this_obj_or_id, $other_obj_or_id, array $where_query = []): EE_Base_Class
106
-    {
107
-        $this_model_obj  = $this->get_this_model()->ensure_is_obj($this_obj_or_id, true);
108
-        $other_model_obj = $this->get_other_model()->ensure_is_obj($other_obj_or_id);
109
-        // find the field on the other model which is a foreign key to this model
110
-        $fk_on_this_model = $this->get_this_model()->get_foreign_key_to(
111
-            $this->get_other_model()->get_this_model_name()
112
-        );
113
-        // set that field on the other model to this model's ID
114
-        $this_model_obj->set($fk_on_this_model->get_name(), null, true);
115
-        $this_model_obj->save();
116
-        return $other_model_obj;
117
-    }
95
+	/**
96
+	 * Sets the this model object's foreign key to its default, instead of pointing to the other model object
97
+	 *
98
+	 * @param EE_Base_Class|int $this_obj_or_id
99
+	 * @param EE_Base_Class|int $other_obj_or_id
100
+	 * @param array             $where_query
101
+	 * @return EE_Base_Class
102
+	 * @throws EE_Error
103
+	 * @throws Exception
104
+	 */
105
+	public function remove_relation_to($this_obj_or_id, $other_obj_or_id, array $where_query = []): EE_Base_Class
106
+	{
107
+		$this_model_obj  = $this->get_this_model()->ensure_is_obj($this_obj_or_id, true);
108
+		$other_model_obj = $this->get_other_model()->ensure_is_obj($other_obj_or_id);
109
+		// find the field on the other model which is a foreign key to this model
110
+		$fk_on_this_model = $this->get_this_model()->get_foreign_key_to(
111
+			$this->get_other_model()->get_this_model_name()
112
+		);
113
+		// set that field on the other model to this model's ID
114
+		$this_model_obj->set($fk_on_this_model->get_name(), null, true);
115
+		$this_model_obj->save();
116
+		return $other_model_obj;
117
+	}
118 118
 
119 119
 
120
-    /**
121
-     * Overrides parent so that we don't NEED to save the $model_object before getting the related objects.
122
-     *
123
-     * @param EE_Base_Class $model_object_or_id
124
-     * @param array|null    $query_params
125
-     * @param boolean       $values_already_prepared_by_model_object @deprecated since 4.8.1
126
-     * @return EE_Base_Class[]
127
-     * @throws EE_Error
128
-     * @throws Exception
129
-     * @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
130
-     */
131
-    public function get_all_related(
132
-        $model_object_or_id,
133
-        ?array $query_params = [],
134
-        bool $values_already_prepared_by_model_object = false
135
-    ): array {
136
-        if ($values_already_prepared_by_model_object !== false) {
137
-            EE_Error::doing_it_wrong(
138
-                'EE_Model_Relation_Base::get_all_related',
139
-                esc_html__(
140
-                    'The argument $values_already_prepared_by_model_object is no longer used.',
141
-                    'event_espresso'
142
-                ),
143
-                '4.8.1'
144
-            );
145
-        }
146
-        // get column on this model object which is a foreign key to the other model
147
-        $fk_field_obj = $this->get_this_model()->get_foreign_key_to($this->get_other_model()->get_this_model_name());
148
-        // get its value
149
-        if ($model_object_or_id instanceof EE_Base_Class) {
150
-            $model_obj = $model_object_or_id;
151
-        } else {
152
-            $model_obj = $this->get_this_model()->ensure_is_obj($model_object_or_id);
153
-        }
154
-        $ID_value_on_other_model = $model_obj->get($fk_field_obj->get_name());
155
-        // if PK ID is empty, there is nothing to match to
156
-        if(empty($ID_value_on_other_model)) {
157
-            return [];
158
-        }
159
-        // get all where their PK matches that value
160
-        $query_params[0][ $this->get_other_model()->get_primary_key_field()->get_name() ] = $ID_value_on_other_model;
161
-        $query_params                                                                     =
162
-            $this->_disable_default_where_conditions_on_query_param($query_params);
120
+	/**
121
+	 * Overrides parent so that we don't NEED to save the $model_object before getting the related objects.
122
+	 *
123
+	 * @param EE_Base_Class $model_object_or_id
124
+	 * @param array|null    $query_params
125
+	 * @param boolean       $values_already_prepared_by_model_object @deprecated since 4.8.1
126
+	 * @return EE_Base_Class[]
127
+	 * @throws EE_Error
128
+	 * @throws Exception
129
+	 * @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
130
+	 */
131
+	public function get_all_related(
132
+		$model_object_or_id,
133
+		?array $query_params = [],
134
+		bool $values_already_prepared_by_model_object = false
135
+	): array {
136
+		if ($values_already_prepared_by_model_object !== false) {
137
+			EE_Error::doing_it_wrong(
138
+				'EE_Model_Relation_Base::get_all_related',
139
+				esc_html__(
140
+					'The argument $values_already_prepared_by_model_object is no longer used.',
141
+					'event_espresso'
142
+				),
143
+				'4.8.1'
144
+			);
145
+		}
146
+		// get column on this model object which is a foreign key to the other model
147
+		$fk_field_obj = $this->get_this_model()->get_foreign_key_to($this->get_other_model()->get_this_model_name());
148
+		// get its value
149
+		if ($model_object_or_id instanceof EE_Base_Class) {
150
+			$model_obj = $model_object_or_id;
151
+		} else {
152
+			$model_obj = $this->get_this_model()->ensure_is_obj($model_object_or_id);
153
+		}
154
+		$ID_value_on_other_model = $model_obj->get($fk_field_obj->get_name());
155
+		// if PK ID is empty, there is nothing to match to
156
+		if(empty($ID_value_on_other_model)) {
157
+			return [];
158
+		}
159
+		// get all where their PK matches that value
160
+		$query_params[0][ $this->get_other_model()->get_primary_key_field()->get_name() ] = $ID_value_on_other_model;
161
+		$query_params                                                                     =
162
+			$this->_disable_default_where_conditions_on_query_param($query_params);
163 163
 //      echo '$query_params';
164 164
 //      var_dump($query_params);
165
-        return $this->get_other_model()->get_all($query_params);
166
-    }
165
+		return $this->get_other_model()->get_all($query_params);
166
+	}
167 167
 }
Please login to merge, or discard this patch.
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -46,19 +46,19 @@  discard block
 block discarded – undo
46 46
         $this_table_alias     = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix(
47 47
                 $model_relation_chain,
48 48
                 $this->get_this_model()->get_this_model_name()
49
-            ) . $this_table_fk_field->get_table_alias();
50
-        $other_table_alias    = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix(
49
+            ).$this_table_fk_field->get_table_alias();
50
+        $other_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix(
51 51
                 $model_relation_chain,
52 52
                 $this->get_other_model()->get_this_model_name()
53
-            ) . $other_table_pk_field->get_table_alias();
54
-        $other_table          = $this->get_other_model()->get_table_for_alias($other_table_alias);
53
+            ).$other_table_pk_field->get_table_alias();
54
+        $other_table = $this->get_other_model()->get_table_for_alias($other_table_alias);
55 55
         return $this->_left_join(
56 56
                 $other_table,
57 57
                 $other_table_alias,
58 58
                 $other_table_pk_field->get_table_column(),
59 59
                 $this_table_alias,
60 60
                 $this_table_fk_field->get_table_column()
61
-            ) . $this->get_other_model()->_construct_internal_join_to_table_with_alias($other_table_alias);
61
+            ).$this->get_other_model()->_construct_internal_join_to_table_with_alias($other_table_alias);
62 62
     }
63 63
 
64 64
 
@@ -153,11 +153,11 @@  discard block
 block discarded – undo
153 153
         }
154 154
         $ID_value_on_other_model = $model_obj->get($fk_field_obj->get_name());
155 155
         // if PK ID is empty, there is nothing to match to
156
-        if(empty($ID_value_on_other_model)) {
156
+        if (empty($ID_value_on_other_model)) {
157 157
             return [];
158 158
         }
159 159
         // get all where their PK matches that value
160
-        $query_params[0][ $this->get_other_model()->get_primary_key_field()->get_name() ] = $ID_value_on_other_model;
160
+        $query_params[0][$this->get_other_model()->get_primary_key_field()->get_name()] = $ID_value_on_other_model;
161 161
         $query_params                                                                     =
162 162
             $this->_disable_default_where_conditions_on_query_param($query_params);
163 163
 //      echo '$query_params';
Please login to merge, or discard this patch.
core/db_models/helpers/EE_Table_Base.php 1 patch
Indentation   +147 added lines, -147 removed lines patch added patch discarded remove patch
@@ -6,151 +6,151 @@
 block discarded – undo
6 6
  */
7 7
 abstract class EE_Table_Base
8 8
 {
9
-    /**
10
-     * This holds the table_name without the table prefix.
11
-     *
12
-     * @var string
13
-     */
14
-    public string $_table_name;
15
-
16
-
17
-    /**
18
-     * This holds what is used as the alias for the table in queries.
19
-     *
20
-     * @var string
21
-     */
22
-    public string $_table_alias;
23
-
24
-
25
-    /**
26
-     * Table's private key column
27
-     *
28
-     * @var string|null
29
-     */
30
-    protected ?string $_pk_column = null;
31
-
32
-
33
-    /**
34
-     * Whether this table is a global table (in multisite) or specific to site.
35
-     *
36
-     * @var bool|null
37
-     */
38
-    protected ?bool $_global;
39
-
40
-
41
-    /**
42
-     * @param string      $table_name with or without wpdb prefix
43
-     * @param string|null $pk_column
44
-     * @param boolean     $global     whether the table is "global" as in there is only 1 table on an entire multisite
45
-     *                                install, or whether each site on a multisite installation has a copy of this table
46
-     * @global wpdb       $wpdb
47
-     */
48
-    public function __construct(string $table_name, ?string $pk_column, bool $global = false)
49
-    {
50
-        $this->_global = $global;
51
-        $prefix        = $this->get_table_prefix();
52
-        // if they added the prefix, let's remove it because we delay adding the prefix until right when it's needed.
53
-        if (strpos($table_name, $prefix) === 0) {
54
-            $table_name = substr_replace($table_name, '', 0, strlen($prefix));
55
-        }
56
-        $this->_table_name = $table_name;
57
-        $this->_pk_column  = $pk_column;
58
-    }
59
-
60
-
61
-    /**
62
-     * This returns the table prefix for the current model state.
63
-     *
64
-     * @return string
65
-     * @global wpdb $wpdb
66
-     */
67
-    public function get_table_prefix()
68
-    {
69
-        global $wpdb;
70
-        if ($this->_global) {
71
-            return $wpdb->base_prefix;
72
-        }
73
-        return $wpdb->get_blog_prefix(EEM_Base::get_model_query_blog_id());
74
-    }
75
-
76
-
77
-    /**
78
-     * Used to set the table_alias property
79
-     *
80
-     * @param string $table_alias
81
-     */
82
-    public function _construct_finalize_with_alias(string $table_alias)
83
-    {
84
-        $this->_table_alias = $table_alias;
85
-    }
86
-
87
-
88
-    /**
89
-     * Returns the fully qualified table name for the database (includes the table prefix current for the blog).
90
-     *
91
-     * @return string
92
-     */
93
-    public function get_table_name()
94
-    {
95
-        return $this->get_table_prefix() . $this->_table_name;
96
-    }
97
-
98
-
99
-    /**
100
-     * Provides what is currently set as the alias for the table to be used in queries.
101
-     *
102
-     * @return string
103
-     * @throws EE_Error
104
-     */
105
-    public function get_table_alias()
106
-    {
107
-        if (! $this->_table_alias) {
108
-            throw new EE_Error("You must call _construct_finalize_with_alias before using the EE_Table_Base. Did you forget to call parent::__construct at the end of your EEMerimental_Base child's __construct?");
109
-        }
110
-        return $this->_table_alias;
111
-    }
112
-
113
-
114
-    /**
115
-     * @return string name of column of PK
116
-     */
117
-    public function get_pk_column()
118
-    {
119
-        return $this->_pk_column;
120
-    }
121
-
122
-
123
-    /**
124
-     * returns a string with the table alias, a period, and the private key's column.
125
-     *
126
-     * @return string
127
-     */
128
-    public function get_fully_qualified_pk_column()
129
-    {
130
-        return $this->get_table_alias() . "." . $this->get_pk_column();
131
-    }
132
-
133
-
134
-    /**
135
-     * returns the special sql for a inner select with a limit.
136
-     *
137
-     * @return string    SQL select
138
-     */
139
-    public function get_select_join_limit($limit)
140
-    {
141
-        $limit = is_array($limit) ? 'LIMIT ' . implode(',', array_map('intval', $limit)) : 'LIMIT ' . (int) $limit;
142
-        return SP . '(SELECT * FROM ' . $this->_table_name . SP . $limit . ') AS ' . $this->_table_alias;
143
-    }
144
-
145
-
146
-    /**
147
-     * Returns whether or not htis is a global table (ie, on multisite there's
148
-     * only one of these tables, on the main blog)
149
-     *
150
-     * @return boolean
151
-     */
152
-    public function is_global()
153
-    {
154
-        return $this->_global;
155
-    }
9
+	/**
10
+	 * This holds the table_name without the table prefix.
11
+	 *
12
+	 * @var string
13
+	 */
14
+	public string $_table_name;
15
+
16
+
17
+	/**
18
+	 * This holds what is used as the alias for the table in queries.
19
+	 *
20
+	 * @var string
21
+	 */
22
+	public string $_table_alias;
23
+
24
+
25
+	/**
26
+	 * Table's private key column
27
+	 *
28
+	 * @var string|null
29
+	 */
30
+	protected ?string $_pk_column = null;
31
+
32
+
33
+	/**
34
+	 * Whether this table is a global table (in multisite) or specific to site.
35
+	 *
36
+	 * @var bool|null
37
+	 */
38
+	protected ?bool $_global;
39
+
40
+
41
+	/**
42
+	 * @param string      $table_name with or without wpdb prefix
43
+	 * @param string|null $pk_column
44
+	 * @param boolean     $global     whether the table is "global" as in there is only 1 table on an entire multisite
45
+	 *                                install, or whether each site on a multisite installation has a copy of this table
46
+	 * @global wpdb       $wpdb
47
+	 */
48
+	public function __construct(string $table_name, ?string $pk_column, bool $global = false)
49
+	{
50
+		$this->_global = $global;
51
+		$prefix        = $this->get_table_prefix();
52
+		// if they added the prefix, let's remove it because we delay adding the prefix until right when it's needed.
53
+		if (strpos($table_name, $prefix) === 0) {
54
+			$table_name = substr_replace($table_name, '', 0, strlen($prefix));
55
+		}
56
+		$this->_table_name = $table_name;
57
+		$this->_pk_column  = $pk_column;
58
+	}
59
+
60
+
61
+	/**
62
+	 * This returns the table prefix for the current model state.
63
+	 *
64
+	 * @return string
65
+	 * @global wpdb $wpdb
66
+	 */
67
+	public function get_table_prefix()
68
+	{
69
+		global $wpdb;
70
+		if ($this->_global) {
71
+			return $wpdb->base_prefix;
72
+		}
73
+		return $wpdb->get_blog_prefix(EEM_Base::get_model_query_blog_id());
74
+	}
75
+
76
+
77
+	/**
78
+	 * Used to set the table_alias property
79
+	 *
80
+	 * @param string $table_alias
81
+	 */
82
+	public function _construct_finalize_with_alias(string $table_alias)
83
+	{
84
+		$this->_table_alias = $table_alias;
85
+	}
86
+
87
+
88
+	/**
89
+	 * Returns the fully qualified table name for the database (includes the table prefix current for the blog).
90
+	 *
91
+	 * @return string
92
+	 */
93
+	public function get_table_name()
94
+	{
95
+		return $this->get_table_prefix() . $this->_table_name;
96
+	}
97
+
98
+
99
+	/**
100
+	 * Provides what is currently set as the alias for the table to be used in queries.
101
+	 *
102
+	 * @return string
103
+	 * @throws EE_Error
104
+	 */
105
+	public function get_table_alias()
106
+	{
107
+		if (! $this->_table_alias) {
108
+			throw new EE_Error("You must call _construct_finalize_with_alias before using the EE_Table_Base. Did you forget to call parent::__construct at the end of your EEMerimental_Base child's __construct?");
109
+		}
110
+		return $this->_table_alias;
111
+	}
112
+
113
+
114
+	/**
115
+	 * @return string name of column of PK
116
+	 */
117
+	public function get_pk_column()
118
+	{
119
+		return $this->_pk_column;
120
+	}
121
+
122
+
123
+	/**
124
+	 * returns a string with the table alias, a period, and the private key's column.
125
+	 *
126
+	 * @return string
127
+	 */
128
+	public function get_fully_qualified_pk_column()
129
+	{
130
+		return $this->get_table_alias() . "." . $this->get_pk_column();
131
+	}
132
+
133
+
134
+	/**
135
+	 * returns the special sql for a inner select with a limit.
136
+	 *
137
+	 * @return string    SQL select
138
+	 */
139
+	public function get_select_join_limit($limit)
140
+	{
141
+		$limit = is_array($limit) ? 'LIMIT ' . implode(',', array_map('intval', $limit)) : 'LIMIT ' . (int) $limit;
142
+		return SP . '(SELECT * FROM ' . $this->_table_name . SP . $limit . ') AS ' . $this->_table_alias;
143
+	}
144
+
145
+
146
+	/**
147
+	 * Returns whether or not htis is a global table (ie, on multisite there's
148
+	 * only one of these tables, on the main blog)
149
+	 *
150
+	 * @return boolean
151
+	 */
152
+	public function is_global()
153
+	{
154
+		return $this->_global;
155
+	}
156 156
 }
Please login to merge, or discard this patch.
core/db_models/helpers/EE_Secondary_Table.php 2 patches
Indentation   +153 added lines, -153 removed lines patch added patch discarded remove patch
@@ -9,157 +9,157 @@
 block discarded – undo
9 9
 class EE_Secondary_Table extends EE_Table_Base
10 10
 {
11 11
 
12
-    protected ?string $_extra_join_conditions;
13
-
14
-    protected ?string $_fk_on_table;
15
-
16
-    protected ?EE_Table_Base $_table_to_join_with = null;
17
-
18
-
19
-    /**
20
-     * @param string      $table_name            with or without wpdb prefix
21
-     * @param string      $pk_column             name of primary key column on THIS table
22
-     * @param string|null $fk_column             the name of the COLUMN that is a foreign key to the primary table's
23
-     *                                           primary key
24
-     * @param string|null $extra_join_conditions string for additional SQL to add onto the join statement's ON condition
25
-     * @param boolean     $global                whether the table is "global" as in there is only 1 table on an entire
26
-     *                                           multisite install, or whether each site on a multisite installation ha
27
-     *                                           a copy of this table
28
-     * @global WPDB       $wpdb
29
-     */
30
-    public function __construct(
31
-        string $table_name,
32
-        string $pk_column,
33
-        ?string $fk_column = null,
34
-        ?string $extra_join_conditions = null,
35
-        bool $global = false
36
-    ) {
37
-        $this->_fk_on_table           = $fk_column;
38
-        $this->_extra_join_conditions = $extra_join_conditions;
39
-        parent::__construct($table_name, $pk_column, $global);
40
-    }
41
-
42
-
43
-    public function get_fk_on_table(): ?string
44
-    {
45
-        return $this->_fk_on_table;
46
-    }
47
-
48
-
49
-    public function _construct_finalize_set_table_to_join_with(EE_Table_Base $table)
50
-    {
51
-        $this->_table_to_join_with = $table;
52
-    }
53
-
54
-
55
-    /**
56
-     * @return string of sql like "Event.post_type = 'event'", which gets added to
57
-     * the end of the join statement with the primary table
58
-     */
59
-    public function get_extra_join_conditions(): ?string
60
-    {
61
-        return $this->_extra_join_conditions;
62
-    }
63
-
64
-
65
-    /**
66
-     * @return EE_Table_Base|null
67
-     */
68
-    public function get_table_to_join_with(): ?EE_Table_Base
69
-    {
70
-        return $this->_table_to_join_with;
71
-    }
72
-
73
-
74
-    /**
75
-     * creates join statement FROM primary table
76
-     * gets SQL like "LEFT JOIN table_name AS table_alias ON other_table_alias.pk = table_alias.fk
77
-     *
78
-     * @param string $primary_table_alias_with_model_chain_prefix allows us to set special conditions on the
79
-     *                                                            $table_name portion of the join query
80
-     *                                                            (i.e. doing a sub-query)
81
-     * @return string of SQL
82
-     * @throws EE_Error
83
-     */
84
-    public function get_join_sql($primary_table_alias_with_model_chain_prefix)
85
-    {
86
-        $table_name            = $this->get_table_name();
87
-        $secondary_table_alias =
88
-            EE_Model_Parser::get_prefix_from_table_alias_with_model_relation_chain_prefix(
89
-                $primary_table_alias_with_model_chain_prefix
90
-            ) . $this->get_table_alias();
91
-        $other_table_pk        = $this->get_table_to_join_with()->get_pk_column();
92
-        $fk                    = $this->get_fk_on_table();
93
-        $join_sql              =
94
-            " LEFT JOIN $table_name AS $secondary_table_alias ON $primary_table_alias_with_model_chain_prefix.$other_table_pk = $secondary_table_alias.$fk ";
95
-        if ($this->get_extra_join_conditions()) {
96
-            $join_sql .= "AND " . $this->get_extra_join_conditions();
97
-        }
98
-        return $join_sql;
99
-    }
100
-
101
-
102
-    /**
103
-     * Produces join SQL like get_join_sql, except instead of joining the primary table to the
104
-     * secondary table, does the inverse: joins the secondary table to the primary one. Eg, instead of
105
-     * " LEFT JOIN secondary_table_table AS Secondary ON ..." like get_join_sql, this function returns
106
-     * " LEFT JOIN primary_table AS Primary ON ...".
107
-     * This is useful if the secondary table is already included in the SQL, but the primary table is not yet.
108
-     *
109
-     * @return string
110
-     * @throws EE_Error
111
-     */
112
-    public function get_inverse_join_sql($secondary_table_alias_with_model_chain_prefix)
113
-    {
114
-        $primary_table_name  = $this->get_table_to_join_with()->get_table_name();
115
-        $primary_table_alias =
116
-            EE_Model_Parser::get_prefix_from_table_alias_with_model_relation_chain_prefix(
117
-                $secondary_table_alias_with_model_chain_prefix
118
-            ) . $this->get_table_to_join_with()->get_table_alias();
119
-        $primary_table_pk    = $this->get_table_to_join_with()->get_pk_column();// $this->get_pk_column();
120
-        $fk                  = $this->get_fk_on_table();
121
-        $join_sql            =
122
-            " LEFT JOIN $primary_table_name AS $primary_table_alias ON $primary_table_alias.$primary_table_pk = $secondary_table_alias_with_model_chain_prefix.$fk ";
123
-        if ($this->get_extra_join_conditions()) {
124
-            $join_sql .= "AND " . $this->get_extra_join_conditions();
125
-        }
126
-        return $join_sql;
127
-    }
128
-
129
-
130
-    /**
131
-     * This prepares the join on the other table using a select with a internal limit.
132
-     *
133
-     * @param array|string $limit limit
134
-     * @return string             SQL to return
135
-     * @throws EE_Error
136
-     */
137
-    public function get_select_join_limit_join($limit)
138
-    {
139
-        // first get the select
140
-        $select   = $this->get_select_join_limit($limit);
141
-        return $this->get_join_sql($select);
142
-    }
143
-
144
-
145
-    /**
146
-     * @throws EE_Error
147
-     */
148
-    public function get_fully_qualified_fk_column()
149
-    {
150
-        $table_alias = $this->get_table_alias();
151
-        $fk          = $this->get_fk_on_table();
152
-        return $table_alias . '.' . $fk;
153
-    }
154
-
155
-
156
-    /**
157
-     * @throws EE_Error
158
-     */
159
-    public function get_fully_qualified_pk_on_fk_table()
160
-    {
161
-        $table_alias = $this->get_table_to_join_with()->get_table_alias();
162
-        $pk          = $this->get_table_to_join_with()->get_pk_column();
163
-        return $table_alias . '.' . $pk;
164
-    }
12
+	protected ?string $_extra_join_conditions;
13
+
14
+	protected ?string $_fk_on_table;
15
+
16
+	protected ?EE_Table_Base $_table_to_join_with = null;
17
+
18
+
19
+	/**
20
+	 * @param string      $table_name            with or without wpdb prefix
21
+	 * @param string      $pk_column             name of primary key column on THIS table
22
+	 * @param string|null $fk_column             the name of the COLUMN that is a foreign key to the primary table's
23
+	 *                                           primary key
24
+	 * @param string|null $extra_join_conditions string for additional SQL to add onto the join statement's ON condition
25
+	 * @param boolean     $global                whether the table is "global" as in there is only 1 table on an entire
26
+	 *                                           multisite install, or whether each site on a multisite installation ha
27
+	 *                                           a copy of this table
28
+	 * @global WPDB       $wpdb
29
+	 */
30
+	public function __construct(
31
+		string $table_name,
32
+		string $pk_column,
33
+		?string $fk_column = null,
34
+		?string $extra_join_conditions = null,
35
+		bool $global = false
36
+	) {
37
+		$this->_fk_on_table           = $fk_column;
38
+		$this->_extra_join_conditions = $extra_join_conditions;
39
+		parent::__construct($table_name, $pk_column, $global);
40
+	}
41
+
42
+
43
+	public function get_fk_on_table(): ?string
44
+	{
45
+		return $this->_fk_on_table;
46
+	}
47
+
48
+
49
+	public function _construct_finalize_set_table_to_join_with(EE_Table_Base $table)
50
+	{
51
+		$this->_table_to_join_with = $table;
52
+	}
53
+
54
+
55
+	/**
56
+	 * @return string of sql like "Event.post_type = 'event'", which gets added to
57
+	 * the end of the join statement with the primary table
58
+	 */
59
+	public function get_extra_join_conditions(): ?string
60
+	{
61
+		return $this->_extra_join_conditions;
62
+	}
63
+
64
+
65
+	/**
66
+	 * @return EE_Table_Base|null
67
+	 */
68
+	public function get_table_to_join_with(): ?EE_Table_Base
69
+	{
70
+		return $this->_table_to_join_with;
71
+	}
72
+
73
+
74
+	/**
75
+	 * creates join statement FROM primary table
76
+	 * gets SQL like "LEFT JOIN table_name AS table_alias ON other_table_alias.pk = table_alias.fk
77
+	 *
78
+	 * @param string $primary_table_alias_with_model_chain_prefix allows us to set special conditions on the
79
+	 *                                                            $table_name portion of the join query
80
+	 *                                                            (i.e. doing a sub-query)
81
+	 * @return string of SQL
82
+	 * @throws EE_Error
83
+	 */
84
+	public function get_join_sql($primary_table_alias_with_model_chain_prefix)
85
+	{
86
+		$table_name            = $this->get_table_name();
87
+		$secondary_table_alias =
88
+			EE_Model_Parser::get_prefix_from_table_alias_with_model_relation_chain_prefix(
89
+				$primary_table_alias_with_model_chain_prefix
90
+			) . $this->get_table_alias();
91
+		$other_table_pk        = $this->get_table_to_join_with()->get_pk_column();
92
+		$fk                    = $this->get_fk_on_table();
93
+		$join_sql              =
94
+			" LEFT JOIN $table_name AS $secondary_table_alias ON $primary_table_alias_with_model_chain_prefix.$other_table_pk = $secondary_table_alias.$fk ";
95
+		if ($this->get_extra_join_conditions()) {
96
+			$join_sql .= "AND " . $this->get_extra_join_conditions();
97
+		}
98
+		return $join_sql;
99
+	}
100
+
101
+
102
+	/**
103
+	 * Produces join SQL like get_join_sql, except instead of joining the primary table to the
104
+	 * secondary table, does the inverse: joins the secondary table to the primary one. Eg, instead of
105
+	 * " LEFT JOIN secondary_table_table AS Secondary ON ..." like get_join_sql, this function returns
106
+	 * " LEFT JOIN primary_table AS Primary ON ...".
107
+	 * This is useful if the secondary table is already included in the SQL, but the primary table is not yet.
108
+	 *
109
+	 * @return string
110
+	 * @throws EE_Error
111
+	 */
112
+	public function get_inverse_join_sql($secondary_table_alias_with_model_chain_prefix)
113
+	{
114
+		$primary_table_name  = $this->get_table_to_join_with()->get_table_name();
115
+		$primary_table_alias =
116
+			EE_Model_Parser::get_prefix_from_table_alias_with_model_relation_chain_prefix(
117
+				$secondary_table_alias_with_model_chain_prefix
118
+			) . $this->get_table_to_join_with()->get_table_alias();
119
+		$primary_table_pk    = $this->get_table_to_join_with()->get_pk_column();// $this->get_pk_column();
120
+		$fk                  = $this->get_fk_on_table();
121
+		$join_sql            =
122
+			" LEFT JOIN $primary_table_name AS $primary_table_alias ON $primary_table_alias.$primary_table_pk = $secondary_table_alias_with_model_chain_prefix.$fk ";
123
+		if ($this->get_extra_join_conditions()) {
124
+			$join_sql .= "AND " . $this->get_extra_join_conditions();
125
+		}
126
+		return $join_sql;
127
+	}
128
+
129
+
130
+	/**
131
+	 * This prepares the join on the other table using a select with a internal limit.
132
+	 *
133
+	 * @param array|string $limit limit
134
+	 * @return string             SQL to return
135
+	 * @throws EE_Error
136
+	 */
137
+	public function get_select_join_limit_join($limit)
138
+	{
139
+		// first get the select
140
+		$select   = $this->get_select_join_limit($limit);
141
+		return $this->get_join_sql($select);
142
+	}
143
+
144
+
145
+	/**
146
+	 * @throws EE_Error
147
+	 */
148
+	public function get_fully_qualified_fk_column()
149
+	{
150
+		$table_alias = $this->get_table_alias();
151
+		$fk          = $this->get_fk_on_table();
152
+		return $table_alias . '.' . $fk;
153
+	}
154
+
155
+
156
+	/**
157
+	 * @throws EE_Error
158
+	 */
159
+	public function get_fully_qualified_pk_on_fk_table()
160
+	{
161
+		$table_alias = $this->get_table_to_join_with()->get_table_alias();
162
+		$pk          = $this->get_table_to_join_with()->get_pk_column();
163
+		return $table_alias . '.' . $pk;
164
+	}
165 165
 }
Please login to merge, or discard this patch.
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -87,13 +87,13 @@  discard block
 block discarded – undo
87 87
         $secondary_table_alias =
88 88
             EE_Model_Parser::get_prefix_from_table_alias_with_model_relation_chain_prefix(
89 89
                 $primary_table_alias_with_model_chain_prefix
90
-            ) . $this->get_table_alias();
90
+            ).$this->get_table_alias();
91 91
         $other_table_pk        = $this->get_table_to_join_with()->get_pk_column();
92 92
         $fk                    = $this->get_fk_on_table();
93 93
         $join_sql              =
94 94
             " LEFT JOIN $table_name AS $secondary_table_alias ON $primary_table_alias_with_model_chain_prefix.$other_table_pk = $secondary_table_alias.$fk ";
95 95
         if ($this->get_extra_join_conditions()) {
96
-            $join_sql .= "AND " . $this->get_extra_join_conditions();
96
+            $join_sql .= "AND ".$this->get_extra_join_conditions();
97 97
         }
98 98
         return $join_sql;
99 99
     }
@@ -115,13 +115,13 @@  discard block
 block discarded – undo
115 115
         $primary_table_alias =
116 116
             EE_Model_Parser::get_prefix_from_table_alias_with_model_relation_chain_prefix(
117 117
                 $secondary_table_alias_with_model_chain_prefix
118
-            ) . $this->get_table_to_join_with()->get_table_alias();
119
-        $primary_table_pk    = $this->get_table_to_join_with()->get_pk_column();// $this->get_pk_column();
118
+            ).$this->get_table_to_join_with()->get_table_alias();
119
+        $primary_table_pk    = $this->get_table_to_join_with()->get_pk_column(); // $this->get_pk_column();
120 120
         $fk                  = $this->get_fk_on_table();
121 121
         $join_sql            =
122 122
             " LEFT JOIN $primary_table_name AS $primary_table_alias ON $primary_table_alias.$primary_table_pk = $secondary_table_alias_with_model_chain_prefix.$fk ";
123 123
         if ($this->get_extra_join_conditions()) {
124
-            $join_sql .= "AND " . $this->get_extra_join_conditions();
124
+            $join_sql .= "AND ".$this->get_extra_join_conditions();
125 125
         }
126 126
         return $join_sql;
127 127
     }
@@ -137,7 +137,7 @@  discard block
 block discarded – undo
137 137
     public function get_select_join_limit_join($limit)
138 138
     {
139 139
         // first get the select
140
-        $select   = $this->get_select_join_limit($limit);
140
+        $select = $this->get_select_join_limit($limit);
141 141
         return $this->get_join_sql($select);
142 142
     }
143 143
 
@@ -149,7 +149,7 @@  discard block
 block discarded – undo
149 149
     {
150 150
         $table_alias = $this->get_table_alias();
151 151
         $fk          = $this->get_fk_on_table();
152
-        return $table_alias . '.' . $fk;
152
+        return $table_alias.'.'.$fk;
153 153
     }
154 154
 
155 155
 
@@ -160,6 +160,6 @@  discard block
 block discarded – undo
160 160
     {
161 161
         $table_alias = $this->get_table_to_join_with()->get_table_alias();
162 162
         $pk          = $this->get_table_to_join_with()->get_pk_column();
163
-        return $table_alias . '.' . $pk;
163
+        return $table_alias.'.'.$pk;
164 164
     }
165 165
 }
Please login to merge, or discard this patch.