Completed
Branch master (16095c)
by
unknown
09:17 queued 04:49
created
core/services/dependencies/DependencyHandler.php 1 patch
Indentation   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -7,19 +7,19 @@
 block discarded – undo
7 7
 abstract class DependencyHandler implements DependencyHandlerInterface
8 8
 {
9 9
 
10
-    /**
11
-     * @var EE_Dependency_Map $dependency_map
12
-     */
13
-    protected $dependency_map;
10
+	/**
11
+	 * @var EE_Dependency_Map $dependency_map
12
+	 */
13
+	protected $dependency_map;
14 14
 
15 15
 
16
-    /**
17
-     * DependencyHandler constructor.
18
-     *
19
-     * @param EE_Dependency_Map $dependency_map
20
-     */
21
-    public function __construct(EE_Dependency_Map $dependency_map)
22
-    {
23
-        $this->dependency_map = $dependency_map;
24
-    }
16
+	/**
17
+	 * DependencyHandler constructor.
18
+	 *
19
+	 * @param EE_Dependency_Map $dependency_map
20
+	 */
21
+	public function __construct(EE_Dependency_Map $dependency_map)
22
+	{
23
+		$this->dependency_map = $dependency_map;
24
+	}
25 25
 }
Please login to merge, or discard this patch.
core/domain/entities/admin/GraphQLData/GraphQLData.php 2 patches
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -44,15 +44,15 @@  discard block
 block discarded – undo
44 44
      */
45 45
     protected function getQueryResponse(string $field_key, array $where_params = [])
46 46
     {
47
-        if (! empty($where_params)) {
48
-            if (! array_key_exists('variables', $this->params)) {
47
+        if ( ! empty($where_params)) {
48
+            if ( ! array_key_exists('variables', $this->params)) {
49 49
                 $this->params['variables'] = [];
50 50
             }
51 51
             $this->params['variables']['where'] = $where_params;
52 52
         }
53 53
 
54 54
         $responseData = $this->makeGraphQLRequest($this->params);
55
-        return ! empty($responseData[ $field_key ]) ? $responseData[ $field_key ] : null;
55
+        return ! empty($responseData[$field_key]) ? $responseData[$field_key] : null;
56 56
     }
57 57
 
58 58
 
@@ -66,7 +66,7 @@  discard block
 block discarded – undo
66 66
         $error = '';
67 67
         try {
68 68
             $response = graphql($data);
69
-            if (! empty($response['data'])) {
69
+            if ( ! empty($response['data'])) {
70 70
                 return $response['data'];
71 71
             }
72 72
             $error = ! empty($response['errors'])
Please login to merge, or discard this patch.
Indentation   +61 added lines, -61 removed lines patch added patch discarded remove patch
@@ -14,74 +14,74 @@
 block discarded – undo
14 14
  */
15 15
 abstract class GraphQLData implements GraphQLDataInterface
16 16
 {
17
-    /**
18
-     * @var string $namespace The graphql namespace/prefix.
19
-     */
20
-    protected $namespace = 'Espresso';
17
+	/**
18
+	 * @var string $namespace The graphql namespace/prefix.
19
+	 */
20
+	protected $namespace = 'Espresso';
21 21
 
22
-    /**
23
-     * @var array $params
24
-     */
25
-    private $params = [];
22
+	/**
23
+	 * @var array $params
24
+	 */
25
+	private $params = [];
26 26
 
27 27
 
28
-    /**
29
-     * @param array $params
30
-     */
31
-    public function setParams(array $params)
32
-    {
33
-        $this->params = $params;
34
-    }
28
+	/**
29
+	 * @param array $params
30
+	 */
31
+	public function setParams(array $params)
32
+	{
33
+		$this->params = $params;
34
+	}
35 35
 
36 36
 
37 37
 
38
-    /**
39
-     * @param string $field_key
40
-     * @param array  $where_params
41
-     * @return mixed|null
42
-     * @since 5.0.0.p
43
-     */
44
-    protected function getQueryResponse(string $field_key, array $where_params = [])
45
-    {
46
-        if (! empty($where_params)) {
47
-            if (! array_key_exists('variables', $this->params)) {
48
-                $this->params['variables'] = [];
49
-            }
50
-            $this->params['variables']['where'] = $where_params;
51
-        }
38
+	/**
39
+	 * @param string $field_key
40
+	 * @param array  $where_params
41
+	 * @return mixed|null
42
+	 * @since 5.0.0.p
43
+	 */
44
+	protected function getQueryResponse(string $field_key, array $where_params = [])
45
+	{
46
+		if (! empty($where_params)) {
47
+			if (! array_key_exists('variables', $this->params)) {
48
+				$this->params['variables'] = [];
49
+			}
50
+			$this->params['variables']['where'] = $where_params;
51
+		}
52 52
 
53
-        $responseData = $this->makeGraphQLRequest($this->params);
54
-        return ! empty($responseData[ $field_key ]) ? $responseData[ $field_key ] : null;
55
-    }
53
+		$responseData = $this->makeGraphQLRequest($this->params);
54
+		return ! empty($responseData[ $field_key ]) ? $responseData[ $field_key ] : null;
55
+	}
56 56
 
57 57
 
58
-    /**
59
-     * @param array $data
60
-     * @return array|null
61
-     * @since 5.0.0.p
62
-     */
63
-    protected function makeGraphQLRequest(array $data)
64
-    {
65
-        $error = '';
66
-        try {
67
-            $response = graphql($data);
68
-            if (! empty($response['data'])) {
69
-                return $response['data'];
70
-            }
71
-            $error = ! empty($response['errors'])
72
-                ? print_r($response['errors'], true)
73
-                : esc_html__(
74
-                    'An unknown error has occurred during the GraphQL request and no data was found to return.',
75
-                    'event_espresso'
76
-                );
77
-        } catch (Exception $e) {
78
-            if (defined('GRAPHQL_DEBUG') && GRAPHQL_DEBUG) {
79
-                $error = $e->getMessage();
80
-            }
81
-        }
82
-        if ($error !== '') {
83
-            error_log($error);
84
-        }
85
-        return null;
86
-    }
58
+	/**
59
+	 * @param array $data
60
+	 * @return array|null
61
+	 * @since 5.0.0.p
62
+	 */
63
+	protected function makeGraphQLRequest(array $data)
64
+	{
65
+		$error = '';
66
+		try {
67
+			$response = graphql($data);
68
+			if (! empty($response['data'])) {
69
+				return $response['data'];
70
+			}
71
+			$error = ! empty($response['errors'])
72
+				? print_r($response['errors'], true)
73
+				: esc_html__(
74
+					'An unknown error has occurred during the GraphQL request and no data was found to return.',
75
+					'event_espresso'
76
+				);
77
+		} catch (Exception $e) {
78
+			if (defined('GRAPHQL_DEBUG') && GRAPHQL_DEBUG) {
79
+				$error = $e->getMessage();
80
+			}
81
+		}
82
+		if ($error !== '') {
83
+			error_log($error);
84
+		}
85
+		return null;
86
+	}
87 87
 }
Please login to merge, or discard this patch.
core/domain/EnqueueAssetsInterface.php 1 patch
Indentation   +35 added lines, -35 removed lines patch added patch discarded remove patch
@@ -4,45 +4,45 @@
 block discarded – undo
4 4
 interface EnqueueAssetsInterface
5 5
 {
6 6
 
7
-    /**
8
-     * a place to register scripts and stylesheets with WordPress core
9
-     * IMPORTANT !!!
10
-     * ALL JavaScript files need to be registered for loading in the footer
11
-     * by setting the 5th parameter of wp_register_script() to ` true `
12
-     *
13
-     * @return void
14
-     */
15
-    public function registerScriptsAndStylesheets();
7
+	/**
8
+	 * a place to register scripts and stylesheets with WordPress core
9
+	 * IMPORTANT !!!
10
+	 * ALL JavaScript files need to be registered for loading in the footer
11
+	 * by setting the 5th parameter of wp_register_script() to ` true `
12
+	 *
13
+	 * @return void
14
+	 */
15
+	public function registerScriptsAndStylesheets();
16 16
 
17
-    /**
18
-     * a place to enqueue previously registered stylesheets
19
-     * this will be called during the wp_enqueue_scripts hook for frontend requests
20
-     *
21
-     * @return void
22
-     */
23
-    public function enqueueStylesheets();
17
+	/**
18
+	 * a place to enqueue previously registered stylesheets
19
+	 * this will be called during the wp_enqueue_scripts hook for frontend requests
20
+	 *
21
+	 * @return void
22
+	 */
23
+	public function enqueueStylesheets();
24 24
 
25
-    /**
26
-     * a place to enqueue previously registered stylesheets
27
-     * this will be called during the admin_enqueue_scripts hook for admin requests
28
-     *
29
-     * @return void
30
-     */
31
-    public function enqueueAdminStylesheets();
25
+	/**
26
+	 * a place to enqueue previously registered stylesheets
27
+	 * this will be called during the admin_enqueue_scripts hook for admin requests
28
+	 *
29
+	 * @return void
30
+	 */
31
+	public function enqueueAdminStylesheets();
32 32
 
33
-    /**
34
-     * a place to enqueue previously registered scripts for frontend requests
35
-     *
36
-     * @return void
37
-     */
38
-    public function enqueueScripts();
33
+	/**
34
+	 * a place to enqueue previously registered scripts for frontend requests
35
+	 *
36
+	 * @return void
37
+	 */
38
+	public function enqueueScripts();
39 39
 
40
-    /**
41
-     * a place to enqueue previously registered scripts for admin requests
42
-     *
43
-     * @return void
44
-     */
45
-    public function enqueueAdminScripts();
40
+	/**
41
+	 * a place to enqueue previously registered scripts for admin requests
42
+	 *
43
+	 * @return void
44
+	 */
45
+	public function enqueueAdminScripts();
46 46
 }
47 47
 // End of file EnqueueAssetsInterface.php
48 48
 // Location: EventEspresso\core\domain/EnqueueAssetsInterface.php
Please login to merge, or discard this patch.
Paypal_Pro/help_tabs/payment_methods_overview_paypalpro.help_tab.php 1 patch
Indentation   +39 added lines, -39 removed lines patch added patch discarded remove patch
@@ -2,12 +2,12 @@  discard block
 block discarded – undo
2 2
 <p><?php esc_html_e('Adjust the settings for the PayPal Pro payment gateway.', 'event_espresso'); ?></p>
3 3
 <p>
4 4
     <?php
5
-    printf(
6
-        esc_html__('See %1$shere%2$s for list of currencies supported by Paypal Pro.', 'event_espresso'),
7
-        "<a href='https://www.paypal.com/multicurrency' target='_blank' rel='noopener noreferrer'>",
8
-        "</a>"
9
-    );
10
-    ?>
5
+	printf(
6
+		esc_html__('See %1$shere%2$s for list of currencies supported by Paypal Pro.', 'event_espresso'),
7
+		"<a href='https://www.paypal.com/multicurrency' target='_blank' rel='noopener noreferrer'>",
8
+		"</a>"
9
+	);
10
+	?>
11 11
 </p>
12 12
 <p><strong><?php esc_html_e('PayPal Pro Settings', 'event_espresso'); ?></strong></p>
13 13
 <ul>
@@ -18,48 +18,48 @@  discard block
 block discarded – undo
18 18
     <li>
19 19
         <strong><?php esc_html_e('PayPal API Username', 'event_espresso'); ?></strong><br/>
20 20
         <?php
21
-        printf(
22
-            esc_html__(
23
-                'Enter your API Username for PayPal. Learn how to find your %1$sAPI Username%2$s.',
24
-                'event_espresso'
25
-            ),
26
-            '<a href="https://www.paypal.com/us/cgi-bin/webscr?cmd=xpt/cps/merchant/wppro/WPProIntegrationSteps-outside#SectionB" target="_blank" rel="noopener noreferrer">',
27
-            '</a>'
28
-        );
29
-        ?>
21
+		printf(
22
+			esc_html__(
23
+				'Enter your API Username for PayPal. Learn how to find your %1$sAPI Username%2$s.',
24
+				'event_espresso'
25
+			),
26
+			'<a href="https://www.paypal.com/us/cgi-bin/webscr?cmd=xpt/cps/merchant/wppro/WPProIntegrationSteps-outside#SectionB" target="_blank" rel="noopener noreferrer">',
27
+			'</a>'
28
+		);
29
+		?>
30 30
     </li>
31 31
     <li>
32 32
         <strong><?php esc_html_e('PayPal API Password', 'event_espresso'); ?></strong><br/>
33 33
         <?php
34
-        printf(
35
-            esc_html__(
36
-                'Enter your API Password for PayPal. Learn how to find your %1$sAPI Password%2$s.',
37
-                'event_espresso'
38
-            ),
39
-            '<a href="https://www.paypal.com/us/cgi-bin/webscr?cmd=xpt/cps/merchant/wppro/WPProIntegrationSteps-outside#SectionB" target="_blank" rel="noopener noreferrer">',
40
-            '</a>'
41
-        );
42
-        ?>
34
+		printf(
35
+			esc_html__(
36
+				'Enter your API Password for PayPal. Learn how to find your %1$sAPI Password%2$s.',
37
+				'event_espresso'
38
+			),
39
+			'<a href="https://www.paypal.com/us/cgi-bin/webscr?cmd=xpt/cps/merchant/wppro/WPProIntegrationSteps-outside#SectionB" target="_blank" rel="noopener noreferrer">',
40
+			'</a>'
41
+		);
42
+		?>
43 43
     </li>
44 44
     <li>
45 45
         <strong><?php esc_html_e('PayPal API Signature', 'event_espresso'); ?></strong><br/>
46 46
         <?php
47
-        printf(
48
-            esc_html__(
49
-                'Enter your API Signature for PayPal. Learn how to find your %1$sAPI Signature%2$s.',
50
-                'event_espresso'
51
-            ),
52
-            '<a href="https://www.paypal.com/us/cgi-bin/webscr?cmd=xpt/cps/merchant/wppro/WPProIntegrationSteps-outside#SectionB" target="_blank" rel="noopener noreferrer">',
53
-            '</a>'
54
-        );
55
-        ?>
47
+		printf(
48
+			esc_html__(
49
+				'Enter your API Signature for PayPal. Learn how to find your %1$sAPI Signature%2$s.',
50
+				'event_espresso'
51
+			),
52
+			'<a href="https://www.paypal.com/us/cgi-bin/webscr?cmd=xpt/cps/merchant/wppro/WPProIntegrationSteps-outside#SectionB" target="_blank" rel="noopener noreferrer">',
53
+			'</a>'
54
+		);
55
+		?>
56 56
     </li>
57 57
     <li>
58 58
         <strong><?php esc_html_e('Country Currency', 'event_espresso'); ?></strong><br/>
59 59
         <?php esc_html_e(
60
-            'Select the currency for your country. Payments will be accepted in this currency.',
61
-            'event_espresso'
62
-        ); ?>
60
+			'Select the currency for your country. Payments will be accepted in this currency.',
61
+			'event_espresso'
62
+		); ?>
63 63
     </li>
64 64
     <li>
65 65
         <strong><?php esc_html_e('Accepted Card Types', 'event_espresso'); ?></strong><br/>
@@ -68,9 +68,9 @@  discard block
 block discarded – undo
68 68
     <li>
69 69
         <strong><?php esc_html_e('Use the Debugging Feature and the PayPal Sandbox', 'event_espresso'); ?></strong><br/>
70 70
         <?php esc_html_e(
71
-            'Specify if you want to test the payment gateway by submitting a test transaction. If this option is enabled, be sure to enter your PayPal sandbox credentials in the fields above. Be sure to turn this setting off when you are done testing.',
72
-            'event_espresso'
73
-        ); ?>
71
+			'Specify if you want to test the payment gateway by submitting a test transaction. If this option is enabled, be sure to enter your PayPal sandbox credentials in the fields above. Be sure to turn this setting off when you are done testing.',
72
+			'event_espresso'
73
+		); ?>
74 74
     </li>
75 75
     <li>
76 76
         <strong><?php esc_html_e('Button Image URL', 'event_espresso'); ?></strong><br/>
Please login to merge, or discard this patch.
admin_pages/messages/help_tabs/messages_overview_types.help_tab.php 1 patch
Indentation   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -1,15 +1,15 @@  discard block
 block discarded – undo
1 1
 <p><strong><?php esc_html_e('Message Types', 'event_espresso'); ?></strong></p>
2 2
 <p>
3 3
     <?php
4
-    printf(
5
-        esc_html__(
6
-            'Messages are email notifications that are sent out by Event Espresso. Message Types are the %1$skinds%2$s of messages that get delivered.  They can be thought of as the "type" of package that is being delivered by the messenger. For example, Event Espresso comes with two Message Types attached to the Email Messenger:',
7
-            'event_espresso'
8
-        ),
9
-        '<em>',
10
-        '</em>'
11
-    );
12
-    ?>
4
+	printf(
5
+		esc_html__(
6
+			'Messages are email notifications that are sent out by Event Espresso. Message Types are the %1$skinds%2$s of messages that get delivered.  They can be thought of as the "type" of package that is being delivered by the messenger. For example, Event Espresso comes with two Message Types attached to the Email Messenger:',
7
+			'event_espresso'
8
+		),
9
+		'<em>',
10
+		'</em>'
11
+	);
12
+	?>
13 13
 </p>
14 14
 <ul>
15 15
     <li>
@@ -24,20 +24,20 @@  discard block
 block discarded – undo
24 24
 <p><strong><?php esc_html_e('Contexts', 'event_espresso'); ?></strong></p>
25 25
 <p>
26 26
     <?php esc_html_e(
27
-        'Each Message Type (kind of message) has different contexts. Contexts are dynamic and typically represent recipients (individuals receiving email notifications). For example, when the Registration Confirmation message type is triggered, it will send out a message to the following recipients: Event Administrator, Primary Registrant, and Additional Registrants. On the other hand, the Payment Message Type has only two recipients: Event Administrator and Primary Registrant.',
28
-        'event_espresso'
29
-    ); ?>
27
+		'Each Message Type (kind of message) has different contexts. Contexts are dynamic and typically represent recipients (individuals receiving email notifications). For example, when the Registration Confirmation message type is triggered, it will send out a message to the following recipients: Event Administrator, Primary Registrant, and Additional Registrants. On the other hand, the Payment Message Type has only two recipients: Event Administrator and Primary Registrant.',
28
+		'event_espresso'
29
+	); ?>
30 30
 </p>
31 31
 <p>
32 32
     <?php esc_html_e(
33
-        'A message context can be deactivated by removing a recipient from the "TO" field. This will set the field to blank and you can save changes. Deactivated message contexts will appear in grey when viewed in the Messages Overview tab. To re-activate a message context, go to that message context and setup a recipient (using one of the available shortcodes) and save changes. This will reactivate the message context and it will appear as blue in the Messages Overview tab.',
34
-        'event_espresso'
35
-    ); ?>
33
+		'A message context can be deactivated by removing a recipient from the "TO" field. This will set the field to blank and you can save changes. Deactivated message contexts will appear in grey when viewed in the Messages Overview tab. To re-activate a message context, go to that message context and setup a recipient (using one of the available shortcodes) and save changes. This will reactivate the message context and it will appear as blue in the Messages Overview tab.',
34
+		'event_espresso'
35
+	); ?>
36 36
 </p>
37 37
 <p><strong><?php esc_html_e('Activation / Deactivation of Message Types', 'event_espresso'); ?></strong></p>
38 38
 <p>
39 39
     <?php esc_html_e(
40
-        'When a new install of Event Espresso is activated, all message types will be activated except for those for Cancelled and Declined registrations. The message types for Cancelled and Declined registrations can be easily activated through the Settings tab for Messages. Deactivating and re-activating Event Espresso will keep the current settings saved.',
41
-        'event_espresso'
42
-    ); ?>
40
+		'When a new install of Event Espresso is activated, all message types will be activated except for those for Cancelled and Declined registrations. The message types for Cancelled and Declined registrations can be easily activated through the Settings tab for Messages. Deactivating and re-activating Event Espresso will keep the current settings saved.',
41
+		'event_espresso'
42
+	); ?>
43 43
 </p>
Please login to merge, or discard this patch.
admin_pages/payments/help_tabs/payment_methods_overview.help_tab.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -53,7 +53,7 @@
 block discarded – undo
53 53
                 'The URL of the button image for this payment method in the registration process. You may use any uploaded image on your website (click %s next to the field to select). If left blank, the default button image will be used.',
54 54
                 'event_espresso'
55 55
             ),
56
-            '<img src="' . admin_url('images/media-button-image.gif') . '">'
56
+            '<img src="'.admin_url('images/media-button-image.gif').'">'
57 57
         );
58 58
         ?>
59 59
     </li>
Please login to merge, or discard this patch.
Indentation   +37 added lines, -37 removed lines patch added patch discarded remove patch
@@ -12,62 +12,62 @@  discard block
 block discarded – undo
12 12
         <strong><?php esc_html_e('Name', 'event_espresso'); ?></strong>
13 13
         <br>
14 14
         <?php esc_html_e(
15
-            'The name of the payment method as customers see it in the registration form, in emails, in receipts, etc.',
16
-            'event_espresso'
17
-        ); ?>
15
+			'The name of the payment method as customers see it in the registration form, in emails, in receipts, etc.',
16
+			'event_espresso'
17
+		); ?>
18 18
     </li>
19 19
     <li>
20 20
         <strong><?php esc_html_e('Description', 'event_espresso'); ?></strong>
21 21
         <br />
22 22
         <?php esc_html_e(
23
-            'The description of how to use the payment method as customers will see it. This is mostly only seen during registration.',
24
-            'event_espresso'
25
-        ); ?>
23
+			'The description of how to use the payment method as customers will see it. This is mostly only seen during registration.',
24
+			'event_espresso'
25
+		); ?>
26 26
     </li>
27 27
     <li>
28 28
         <strong><?php esc_html_e('Admin-Only Name', 'event_espresso'); ?></strong>
29 29
         <br />
30 30
         <?php esc_html_e(
31
-            'The name of the payment method as seen internally by site administrators and staff.',
32
-            'event_espresso'
33
-        ); ?>
31
+			'The name of the payment method as seen internally by site administrators and staff.',
32
+			'event_espresso'
33
+		); ?>
34 34
     </li>
35 35
     <li>
36 36
         <strong><?php esc_html_e('Admin-Only Description', 'event_espresso'); ?></strong>
37 37
         <br />
38 38
         <?php esc_html_e(
39
-            'The description of the payment method as seen internally by site administrators and staff.',
40
-            'event_espresso'
41
-        ); ?>
39
+			'The description of the payment method as seen internally by site administrators and staff.',
40
+			'event_espresso'
41
+		); ?>
42 42
     </li>
43 43
     <li>
44 44
         <strong><?php esc_html_e('Debug (sandbox) Mode', 'event_espresso'); ?></strong>
45 45
         <br />
46 46
         <?php esc_html_e(
47
-            'Many payment methods have a debug/sandbox mode where payments are not processed but are only simulated. This is helpful when setup and debugging.',
48
-            'event_espresso'
49
-        ); ?>
47
+			'Many payment methods have a debug/sandbox mode where payments are not processed but are only simulated. This is helpful when setup and debugging.',
48
+			'event_espresso'
49
+		); ?>
50 50
     </li>
51 51
     <li>
52 52
         <strong><?php esc_html_e('Open by Default', 'event_espresso'); ?></strong>
53 53
         <br />
54 54
         <?php esc_html_e(
55
-            'If checked, this payment method will be selected by default (assuming no other valid payment methods are also marked as open by default.)',
56
-            'event_espresso'
57
-        ); ?>
55
+			'If checked, this payment method will be selected by default (assuming no other valid payment methods are also marked as open by default.)',
56
+			'event_espresso'
57
+		); ?>
58 58
     </li>
59 59
     <li>
60 60
         <strong><?php esc_html_e('Button URL', 'event_espresso'); ?></strong>
61 61
         <br />
62 62
         <?php
63
-        printf(
64
-            esc_html__(
65
-                'The URL of the button image for this payment method in the registration process. You may use any uploaded image on your website (click %s next to the field to select). If left blank, the default button image will be used.',
66
-                'event_espresso'
67
-            ),
68
-            '<img src="' . admin_url('images/media-button-image.gif') . '">'
69
-        );
70
-        ?>
63
+		printf(
64
+			esc_html__(
65
+				'The URL of the button image for this payment method in the registration process. You may use any uploaded image on your website (click %s next to the field to select). If left blank, the default button image will be used.',
66
+				'event_espresso'
67
+			),
68
+			'<img src="' . admin_url('images/media-button-image.gif') . '">'
69
+		);
70
+		?>
71 71
     </li>
72 72
     <li>
73 73
         <strong><?php esc_html_e('Usable From', 'event_espresso'); ?></strong>
@@ -76,15 +76,15 @@  discard block
 block discarded – undo
76 76
         <ul>
77 77
             <li>
78 78
                 <?php esc_html_e(
79
-                    'Front-end Registration Page: the payment method will appear as an option during the normal registration process to customers and they can use it to process payments.',
80
-                    'event_espresso'
81
-                ); ?>
79
+					'Front-end Registration Page: the payment method will appear as an option during the normal registration process to customers and they can use it to process payments.',
80
+					'event_espresso'
81
+				); ?>
82 82
             </li>
83 83
             <li>
84 84
                 <?php esc_html_e(
85
-                    'Admin Registration Page: when recording payments made from the transaction admin page, the payment method will appear as an option. Note: currently payments can only be RECORDED from the admin, they cannot be PROCESSED.',
86
-                    'event_espresso'
87
-                ); ?>
85
+					'Admin Registration Page: when recording payments made from the transaction admin page, the payment method will appear as an option. Note: currently payments can only be RECORDED from the admin, they cannot be PROCESSED.',
86
+					'event_espresso'
87
+				); ?>
88 88
             </li>
89 89
         </ul>
90 90
     </li>
@@ -92,14 +92,14 @@  discard block
 block discarded – undo
92 92
 <strong><?php esc_html_e('Recommendations', 'event_espresso'); ?></strong>
93 93
 <br />
94 94
 <?php esc_html_e(
95
-    'To learn more about the options on this page, take a look at the different tabs that appear on the left side of the page.',
96
-    'event_espresso'
95
+	'To learn more about the options on this page, take a look at the different tabs that appear on the left side of the page.',
96
+	'event_espresso'
97 97
 ); ?>
98 98
 <p>
99 99
     <strong><?php esc_html_e('Screen Options', 'event_espresso'); ?></strong>
100 100
     <br />
101 101
     <?php esc_html_e(
102
-        'You can customize the information that is shown on this page by toggling the Screen Options tab. Then you can add or remove checkmarks to hide or show certain content.',
103
-        'event_espresso'
104
-    ); ?>
102
+		'You can customize the information that is shown on this page by toggling the Screen Options tab. Then you can add or remove checkmarks to hide or show certain content.',
103
+		'event_espresso'
104
+	); ?>
105 105
 </p>
Please login to merge, or discard this patch.
core/domain/entities/admin/GraphQLData/Event.php 2 patches
Indentation   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -5,13 +5,13 @@  discard block
 block discarded – undo
5 5
 class Event extends GraphQLData
6 6
 {
7 7
 
8
-    /**
9
-     * @inheritDoc
10
-     */
11
-    public function getData(array $params = [])
12
-    {
13
-        $field_key = lcfirst($this->namespace) . 'Event';
14
-        $query     = <<<QUERY
8
+	/**
9
+	 * @inheritDoc
10
+	 */
11
+	public function getData(array $params = [])
12
+	{
13
+		$field_key = lcfirst($this->namespace) . 'Event';
14
+		$query     = <<<QUERY
15 15
         query GET_EVENT(\$id: ID!) {
16 16
             {$field_key}(id: \$id, idType: DATABASE_ID) {
17 17
                 id
@@ -48,14 +48,14 @@  discard block
 block discarded – undo
48 48
             }
49 49
         }
50 50
 QUERY;
51
-        $this->setParams(
52
-            [
53
-                'operation_name' => 'GET_EVENT',
54
-                'variables'      => $params,
55
-                'query'          => $query,
56
-            ]
57
-        );
51
+		$this->setParams(
52
+			[
53
+				'operation_name' => 'GET_EVENT',
54
+				'variables'      => $params,
55
+				'query'          => $query,
56
+			]
57
+		);
58 58
 
59
-        return $this->getQueryResponse($field_key);
60
-    }
59
+		return $this->getQueryResponse($field_key);
60
+	}
61 61
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -10,7 +10,7 @@
 block discarded – undo
10 10
      */
11 11
     public function getData(array $params = [])
12 12
     {
13
-        $field_key = lcfirst($this->namespace) . 'Event';
13
+        $field_key = lcfirst($this->namespace).'Event';
14 14
         $query     = <<<QUERY
15 15
         query GET_EVENT(\$id: ID!) {
16 16
             {$field_key}(id: \$id, idType: DATABASE_ID) {
Please login to merge, or discard this patch.
core/domain/entities/routing/data_nodes/core/SitePermissions.php 1 patch
Indentation   +27 added lines, -27 removed lines patch added patch discarded remove patch
@@ -8,31 +8,31 @@
 block discarded – undo
8 8
 
9 9
 class SitePermissions extends JsonDataNode
10 10
 {
11
-    const NODE_NAME = 'sitePermissions';
12
-
13
-    /**
14
-     * @var FeatureFlags
15
-     */
16
-    private $feature_flags;
17
-
18
-
19
-    /**
20
-     * @param FeatureFlags          $feature_flags
21
-     * @param JsonDataNodeValidator $validator
22
-     */
23
-    public function __construct(FeatureFlags $feature_flags, JsonDataNodeValidator $validator)
24
-    {
25
-        $this->feature_flags = $feature_flags;
26
-        parent::__construct($validator);
27
-        $this->setNodeName(SitePermissions::NODE_NAME);
28
-    }
29
-
30
-
31
-    /**
32
-     * @inheritDoc
33
-     */
34
-    public function initialize()
35
-    {
36
-        $this->setDataArray($this->feature_flags->getAllowedFeatures());
37
-    }
11
+	const NODE_NAME = 'sitePermissions';
12
+
13
+	/**
14
+	 * @var FeatureFlags
15
+	 */
16
+	private $feature_flags;
17
+
18
+
19
+	/**
20
+	 * @param FeatureFlags          $feature_flags
21
+	 * @param JsonDataNodeValidator $validator
22
+	 */
23
+	public function __construct(FeatureFlags $feature_flags, JsonDataNodeValidator $validator)
24
+	{
25
+		$this->feature_flags = $feature_flags;
26
+		parent::__construct($validator);
27
+		$this->setNodeName(SitePermissions::NODE_NAME);
28
+	}
29
+
30
+
31
+	/**
32
+	 * @inheritDoc
33
+	 */
34
+	public function initialize()
35
+	{
36
+		$this->setDataArray($this->feature_flags->getAllowedFeatures());
37
+	}
38 38
 }
Please login to merge, or discard this patch.
core/db_models/EEM_Datetime.model.php 2 patches
Spacing   +20 added lines, -20 removed lines patch added patch discarded remove patch
@@ -121,7 +121,7 @@  discard block
 block discarded – undo
121 121
                 ),
122 122
             ],
123 123
         ];
124
-        $this->_model_relations        = [
124
+        $this->_model_relations = [
125 125
             'Ticket'          => new EE_HABTM_Relation('Datetime_Ticket'),
126 126
             'Event'           => new EE_Belongs_To_Relation(),
127 127
             'Checkin'         => new EE_Has_Many_Relation(),
@@ -131,19 +131,19 @@  discard block
 block discarded – undo
131 131
         $this->model_chain_to_password = $path_to_event_model;
132 132
         $this->_model_chain_to_wp_user = $path_to_event_model;
133 133
         // this model is generally available for reading
134
-        $this->_cap_restriction_generators[ EEM_Base::caps_read ]       =
134
+        $this->_cap_restriction_generators[EEM_Base::caps_read] =
135 135
             new EE_Restriction_Generator_Event_Related_Public(
136 136
                 $path_to_event_model
137 137
             );
138
-        $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] =
138
+        $this->_cap_restriction_generators[EEM_Base::caps_read_admin] =
139 139
             new EE_Restriction_Generator_Event_Related_Protected(
140 140
                 $path_to_event_model
141 141
             );
142
-        $this->_cap_restriction_generators[ EEM_Base::caps_edit ]       =
142
+        $this->_cap_restriction_generators[EEM_Base::caps_edit] =
143 143
             new EE_Restriction_Generator_Event_Related_Protected(
144 144
                 $path_to_event_model
145 145
             );
146
-        $this->_cap_restriction_generators[ EEM_Base::caps_delete ]     =
146
+        $this->_cap_restriction_generators[EEM_Base::caps_delete] =
147 147
             new EE_Restriction_Generator_Event_Related_Protected(
148 148
                 $path_to_event_model,
149 149
                 EEM_Base::caps_edit
@@ -185,7 +185,7 @@  discard block
 block discarded – undo
185 185
          * @param int $end_data Unix timestamp representing now + 30 days in seconds.
186 186
          * @return int Unix timestamp
187 187
          */
188
-        $end_date       = apply_filters(
188
+        $end_date = apply_filters(
189 189
             'FHEE__EEM_Datetime__create_new_blank_datetime__end_date',
190 190
             $this->current_time_for_query('DTT_EVT_end', true) + MONTH_IN_SECONDS
191 191
         );
@@ -251,10 +251,10 @@  discard block
 block discarded – undo
251 251
      */
252 252
     private function validateStartAndEndTimeForBlankDate(array $start_time, array $end_time)
253 253
     {
254
-        if (! is_array($start_time)) {
254
+        if ( ! is_array($start_time)) {
255 255
             throw new InvalidDataTypeException('start_time', $start_time, 'array');
256 256
         }
257
-        if (! is_array($end_time)) {
257
+        if ( ! is_array($end_time)) {
258 258
             throw new InvalidDataTypeException('end_time', $end_time, 'array');
259 259
         }
260 260
         if (count($start_time) !== 2) {
@@ -289,7 +289,7 @@  discard block
 block discarded – undo
289 289
      */
290 290
     public function get_all_event_dates($EVT_ID = 0)
291 291
     {
292
-        if (! $EVT_ID) { // on add_new_event event_id gets set to 0
292
+        if ( ! $EVT_ID) { // on add_new_event event_id gets set to 0
293 293
             return $this->create_new_blank_datetime();
294 294
         }
295 295
         $results = $this->get_datetimes_for_event_ordered_by_DTT_order($EVT_ID);
@@ -426,7 +426,7 @@  discard block
 block discarded – undo
426 426
             $query_params,
427 427
             EEM_Base::default_where_conditions_this_only
428 428
         );
429
-        $query_params         = $this->addDefaultQueryParams($query_params, $limit, 'DTT_order');
429
+        $query_params = $this->addDefaultQueryParams($query_params, $limit, 'DTT_order');
430 430
         return $this->getDatetimesAndRestoreModel($query_params, $prev_data_prep_value);
431 431
     }
432 432
 
@@ -587,14 +587,14 @@  discard block
 block discarded – undo
587 587
         $query_params['group_by'] = ['dtt_year', 'dtt_month'];
588 588
         $query_params             = $this->addOrderByQueryParams($query_params, 'DTT_EVT_start', 'DESC');
589 589
 
590
-        $query_interval    = EEH_DTT_Helper::get_sql_query_interval_for_offset(
590
+        $query_interval = EEH_DTT_Helper::get_sql_query_interval_for_offset(
591 591
             $this->get_timezone(),
592 592
             'DTT_EVT_start'
593 593
         );
594 594
         $columns_to_select = [
595
-            'dtt_year'      => ['YEAR(' . $query_interval . ')', '%s'],
596
-            'dtt_month'     => ['MONTHNAME(' . $query_interval . ')', '%s'],
597
-            'dtt_month_num' => ['MONTH(' . $query_interval . ')', '%s'],
595
+            'dtt_year'      => ['YEAR('.$query_interval.')', '%s'],
596
+            'dtt_month'     => ['MONTHNAME('.$query_interval.')', '%s'],
597
+            'dtt_month_num' => ['MONTH('.$query_interval.')', '%s'],
598 598
         ];
599 599
         return $this->_get_all_wpdb_results($query_params, OBJECT, $columns_to_select);
600 600
     }
@@ -676,17 +676,17 @@  discard block
 block discarded – undo
676 676
                 ['DTT_EVT_end' => ['<', time()]]
677 677
             ),
678 678
         ];
679
-        if (! empty($stati_to_include)) {
679
+        if ( ! empty($stati_to_include)) {
680 680
             foreach (array_keys($status_query_args) as $status) {
681
-                if (! in_array($status, $stati_to_include, true)) {
682
-                    unset($status_query_args[ $status ]);
681
+                if ( ! in_array($status, $stati_to_include, true)) {
682
+                    unset($status_query_args[$status]);
683 683
                 }
684 684
             }
685 685
         }
686 686
         // loop through and query counts for each stati.
687 687
         $status_query_results = [];
688 688
         foreach ($status_query_args as $status => $status_where_conditions) {
689
-            $status_query_results[ $status ] = EEM_Datetime::count(
689
+            $status_query_results[$status] = EEM_Datetime::count(
690 690
                 [$status_where_conditions],
691 691
                 'DTT_ID',
692 692
                 true
@@ -707,7 +707,7 @@  discard block
 block discarded – undo
707 707
     public function get_datetime_count_for_status($status = EE_Datetime::active, array $query_params = [])
708 708
     {
709 709
         $count = $this->get_datetime_counts_by_status([$status], $query_params);
710
-        return ! empty($count[ $status ]) ? $count[ $status ] : 0;
710
+        return ! empty($count[$status]) ? $count[$status] : 0;
711 711
     }
712 712
 
713 713
 
@@ -806,7 +806,7 @@  discard block
 block discarded – undo
806 806
      */
807 807
     private function addExpiredWhereParams(array $where_params, bool $include_expired = true)
808 808
     {
809
-        if (! $include_expired) {
809
+        if ( ! $include_expired) {
810 810
             $where_params['DTT_EVT_end'] = ['>=', current_time('mysql', true)];
811 811
         }
812 812
         return $where_params;
Please login to merge, or discard this patch.
Indentation   +838 added lines, -838 removed lines patch added patch discarded remove patch
@@ -16,842 +16,842 @@
 block discarded – undo
16 16
  */
17 17
 class EEM_Datetime extends EEM_Soft_Delete_Base
18 18
 {
19
-    /**
20
-     * @var EEM_Datetime $_instance
21
-     */
22
-    protected static $_instance;
23
-
24
-
25
-    /**
26
-     * private constructor to prevent direct creation
27
-     *
28
-     * @param string $timezone A string representing the timezone we want to set for returned Date Time Strings
29
-     *                         (and any incoming timezone data that gets saved).
30
-     *                         Note this just sends the timezone info to the date time model field objects.
31
-     *                         Default is NULL
32
-     *                         (and will be assumed using the set timezone in the 'timezone_string' wp option)
33
-     * @throws EE_Error
34
-     * @throws InvalidArgumentException
35
-     * @throws InvalidArgumentException
36
-     */
37
-    protected function __construct($timezone)
38
-    {
39
-        $this->singular_item           = esc_html__('Datetime', 'event_espresso');
40
-        $this->plural_item             = esc_html__('Datetimes', 'event_espresso');
41
-        $this->_tables                 = [
42
-            'Datetime' => new EE_Primary_Table('esp_datetime', 'DTT_ID'),
43
-        ];
44
-        $this->_fields                 = [
45
-            'Datetime' => [
46
-                'DTT_ID'          => new EE_Primary_Key_Int_Field(
47
-                    'DTT_ID',
48
-                    esc_html__('Datetime ID', 'event_espresso')
49
-                ),
50
-                'EVT_ID'          => new EE_Foreign_Key_Int_Field(
51
-                    'EVT_ID',
52
-                    esc_html__('Event ID', 'event_espresso'),
53
-                    false,
54
-                    0,
55
-                    'Event'
56
-                ),
57
-                'VNU_ID' => new EE_Foreign_Key_Int_Field(
58
-                    'VNU_ID',
59
-                    __('Venue ID', 'event_espresso'),
60
-                    false,
61
-                    0,
62
-                    'Venue'
63
-                ),
64
-                'DTT_name'        => new EE_Plain_Text_Field(
65
-                    'DTT_name',
66
-                    esc_html__('Datetime Name', 'event_espresso'),
67
-                    false,
68
-                    ''
69
-                ),
70
-                'DTT_description' => new EE_Post_Content_Field(
71
-                    'DTT_description',
72
-                    esc_html__('Description for Datetime', 'event_espresso'),
73
-                    false,
74
-                    ''
75
-                ),
76
-                'DTT_EVT_start'   => new EE_Datetime_Field(
77
-                    'DTT_EVT_start',
78
-                    esc_html__('Start time/date of Event', 'event_espresso'),
79
-                    false,
80
-                    EE_Datetime_Field::now,
81
-                    $timezone
82
-                ),
83
-                'DTT_EVT_end'     => new EE_Datetime_Field(
84
-                    'DTT_EVT_end',
85
-                    esc_html__('End time/date of Event', 'event_espresso'),
86
-                    false,
87
-                    EE_Datetime_Field::now,
88
-                    $timezone
89
-                ),
90
-                'DTT_reg_limit'   => new EE_Infinite_Integer_Field(
91
-                    'DTT_reg_limit',
92
-                    esc_html__('Registration Limit for this time', 'event_espresso'),
93
-                    true,
94
-                    EE_INF
95
-                ),
96
-                'DTT_sold'        => new EE_Integer_Field(
97
-                    'DTT_sold',
98
-                    esc_html__('How many sales for this Datetime that have occurred', 'event_espresso'),
99
-                    true,
100
-                    0
101
-                ),
102
-                'DTT_reserved'    => new EE_Integer_Field(
103
-                    'DTT_reserved',
104
-                    esc_html__('Quantity of tickets reserved, but not yet fully purchased', 'event_espresso'),
105
-                    false,
106
-                    0
107
-                ),
108
-                'DTT_is_primary'  => new EE_Boolean_Field(
109
-                    'DTT_is_primary',
110
-                    esc_html__('Flag indicating datetime is primary one for event', 'event_espresso'),
111
-                    false,
112
-                    false
113
-                ),
114
-                'DTT_order'       => new EE_Integer_Field(
115
-                    'DTT_order',
116
-                    esc_html__('The order in which the Datetime is displayed', 'event_espresso'),
117
-                    false,
118
-                    0
119
-                ),
120
-                'DTT_parent'      => new EE_Integer_Field(
121
-                    'DTT_parent',
122
-                    esc_html__('Indicates what DTT_ID is the parent of this DTT_ID', 'event_espresso'),
123
-                    true,
124
-                    0
125
-                ),
126
-                'DTT_deleted'     => new EE_Trashed_Flag_Field(
127
-                    'DTT_deleted',
128
-                    esc_html__('Flag indicating datetime is archived', 'event_espresso'),
129
-                    false,
130
-                    false
131
-                ),
132
-            ],
133
-        ];
134
-        $this->_model_relations        = [
135
-            'Ticket'          => new EE_HABTM_Relation('Datetime_Ticket'),
136
-            'Event'           => new EE_Belongs_To_Relation(),
137
-            'Checkin'         => new EE_Has_Many_Relation(),
138
-            'Datetime_Ticket' => new EE_Has_Many_Relation(),
139
-            'Venue'           => new EE_Belongs_To_Relation(),
140
-        ];
141
-        $path_to_event_model           = 'Event';
142
-        $this->model_chain_to_password = $path_to_event_model;
143
-        $this->_model_chain_to_wp_user = $path_to_event_model;
144
-        // this model is generally available for reading
145
-        $this->_cap_restriction_generators[ EEM_Base::caps_read ]       =
146
-            new EE_Restriction_Generator_Event_Related_Public(
147
-                $path_to_event_model
148
-            );
149
-        $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] =
150
-            new EE_Restriction_Generator_Event_Related_Protected(
151
-                $path_to_event_model
152
-            );
153
-        $this->_cap_restriction_generators[ EEM_Base::caps_edit ]       =
154
-            new EE_Restriction_Generator_Event_Related_Protected(
155
-                $path_to_event_model
156
-            );
157
-        $this->_cap_restriction_generators[ EEM_Base::caps_delete ]     =
158
-            new EE_Restriction_Generator_Event_Related_Protected(
159
-                $path_to_event_model,
160
-                EEM_Base::caps_edit
161
-            );
162
-        parent::__construct($timezone);
163
-    }
164
-
165
-
166
-    /**
167
-     * create new blank datetime
168
-     *
169
-     * @access public
170
-     * @return EE_Datetime[] array on success, FALSE on fail
171
-     * @throws EE_Error
172
-     * @throws InvalidArgumentException
173
-     * @throws InvalidDataTypeException
174
-     * @throws ReflectionException
175
-     * @throws InvalidInterfaceException
176
-     */
177
-    public function create_new_blank_datetime()
178
-    {
179
-        // makes sure timezone is always set.
180
-        $timezone_string = $this->get_timezone();
181
-        /**
182
-         * Filters the initial start date for the new datetime.
183
-         * Any time included in this value will be overridden later so use additional filters to modify the time.
184
-         *
185
-         * @param int $start_date Unix timestamp representing now + 30 days in seconds.
186
-         * @return int Unix timestamp
187
-         */
188
-        $start_date = apply_filters(
189
-            'FHEE__EEM_Datetime__create_new_blank_datetime__start_date',
190
-            $this->current_time_for_query('DTT_EVT_start', true) + MONTH_IN_SECONDS
191
-        );
192
-        /**
193
-         * Filters the initial end date for the new datetime.
194
-         * Any time included in this value will be overridden later so use additional filters to modify the time.
195
-         *
196
-         * @param int $end_data Unix timestamp representing now + 30 days in seconds.
197
-         * @return int Unix timestamp
198
-         */
199
-        $end_date       = apply_filters(
200
-            'FHEE__EEM_Datetime__create_new_blank_datetime__end_date',
201
-            $this->current_time_for_query('DTT_EVT_end', true) + MONTH_IN_SECONDS
202
-        );
203
-        $blank_datetime = EE_Datetime::new_instance(
204
-            [
205
-                'DTT_EVT_start' => $start_date,
206
-                'DTT_EVT_end'   => $end_date,
207
-                'DTT_order'     => 1,
208
-                'DTT_reg_limit' => EE_INF,
209
-            ],
210
-            $timezone_string
211
-        );
212
-        /**
213
-         * Filters the initial start time and format for the new EE_Datetime instance.
214
-         *
215
-         * @param array $start_time An array having size 2.  First element is the time, second element is the time
216
-         *                          format.
217
-         * @return array
218
-         */
219
-        $start_time = apply_filters(
220
-            'FHEE__EEM_Datetime__create_new_blank_datetime__start_time',
221
-            ['8am', 'ga']
222
-        );
223
-        /**
224
-         * Filters the initial end time and format for the new EE_Datetime instance.
225
-         *
226
-         * @param array $end_time An array having size 2.  First element is the time, second element is the time
227
-         *                        format
228
-         * @return array
229
-         */
230
-        $end_time = apply_filters(
231
-            'FHEE__EEM_Datetime__create_new_blank_datetime__end_time',
232
-            ['5pm', 'ga']
233
-        );
234
-        $this->validateStartAndEndTimeForBlankDate($start_time, $end_time);
235
-        $blank_datetime->set_start_time(
236
-            $this->convert_datetime_for_query(
237
-                'DTT_EVT_start',
238
-                $start_time[0],
239
-                $start_time[1],
240
-                $timezone_string
241
-            )
242
-        );
243
-        $blank_datetime->set_end_time(
244
-            $this->convert_datetime_for_query(
245
-                'DTT_EVT_end',
246
-                $end_time[0],
247
-                $end_time[1],
248
-                $timezone_string
249
-            )
250
-        );
251
-        return [$blank_datetime];
252
-    }
253
-
254
-
255
-    /**
256
-     * Validates whether the start_time and end_time are in the expected format.
257
-     *
258
-     * @param array $start_time
259
-     * @param array $end_time
260
-     * @throws InvalidArgumentException
261
-     * @throws InvalidDataTypeException
262
-     */
263
-    private function validateStartAndEndTimeForBlankDate(array $start_time, array $end_time)
264
-    {
265
-        if (! is_array($start_time)) {
266
-            throw new InvalidDataTypeException('start_time', $start_time, 'array');
267
-        }
268
-        if (! is_array($end_time)) {
269
-            throw new InvalidDataTypeException('end_time', $end_time, 'array');
270
-        }
271
-        if (count($start_time) !== 2) {
272
-            throw new InvalidArgumentException(
273
-                sprintf(
274
-                    'The variable %1$s is expected to be an array with two elements.  The first item in the '
275
-                    . 'array should be a valid time string, the second item in the array should be a valid time format',
276
-                    '$start_time'
277
-                )
278
-            );
279
-        }
280
-        if (count($end_time) !== 2) {
281
-            throw new InvalidArgumentException(
282
-                sprintf(
283
-                    'The variable %1$s is expected to be an array with two elements.  The first item in the '
284
-                    . 'array should be a valid time string, the second item in the array should be a valid time format',
285
-                    '$end_time'
286
-                )
287
-            );
288
-        }
289
-    }
290
-
291
-
292
-    /**
293
-     * get event start date from db
294
-     *
295
-     * @access public
296
-     * @param int $EVT_ID
297
-     * @return EE_Datetime[] array on success, FALSE on fail
298
-     * @throws EE_Error
299
-     * @throws ReflectionException
300
-     */
301
-    public function get_all_event_dates($EVT_ID = 0)
302
-    {
303
-        if (! $EVT_ID) { // on add_new_event event_id gets set to 0
304
-            return $this->create_new_blank_datetime();
305
-        }
306
-        $results = $this->get_datetimes_for_event_ordered_by_DTT_order($EVT_ID);
307
-        if (empty($results)) {
308
-            return $this->create_new_blank_datetime();
309
-        }
310
-        return $results;
311
-    }
312
-
313
-
314
-    /**
315
-     * get all datetimes attached to an event ordered by the DTT_order field
316
-     *
317
-     * @public
318
-     * @param int     $EVT_ID     event id
319
-     * @param boolean $include_expired
320
-     * @param boolean $include_deleted
321
-     * @param int     $limit      If included then limit the count of results by
322
-     *                            the given number
323
-     * @return EE_Datetime[]
324
-     * @throws EE_Error
325
-     */
326
-    public function get_datetimes_for_event_ordered_by_DTT_order(
327
-        int $EVT_ID,
328
-        bool $include_expired = true,
329
-        bool $include_deleted = true,
330
-        $limit = 0
331
-    ) {
332
-        $prev_data_prep_value = $this->prepModelForQuery();
333
-        $where_params         = ['Event.EVT_ID' => absint($EVT_ID)];
334
-        $query_params[0]      = $this->addDefaultWhereParams($where_params, $include_deleted, $include_expired);
335
-        $query_params         = $this->addDefaultWhereConditions($query_params);
336
-        $query_params         = $this->addDefaultQueryParams($query_params, $limit, 'DTT_order');
337
-        return $this->getDatetimesAndRestoreModel($query_params, $prev_data_prep_value);
338
-    }
339
-
340
-
341
-    /**
342
-     * Gets the datetimes for the event (with the given limit), and orders them by "importance".
343
-     * By importance, we mean that the primary datetimes are most important (DEPRECATED FOR NOW),
344
-     * and then the earlier datetimes are the most important.
345
-     * Maybe we'll want this to take into account datetimes that haven't already passed, but we don't yet.
346
-     *
347
-     * @param int $EVT_ID
348
-     * @param int $limit
349
-     * @return EE_Datetime[]|EE_Base_Class[]
350
-     * @throws EE_Error
351
-     */
352
-    public function get_datetimes_for_event_ordered_by_importance(int $EVT_ID, $limit = 0)
353
-    {
354
-        $query_params[0] = ['Event.EVT_ID' => absint($EVT_ID)];
355
-        $query_params    = $this->addDefaultWhereConditions($query_params);
356
-        $query_params    = $this->addDefaultQueryParams($query_params, $limit);
357
-        return $this->get_all($query_params);
358
-    }
359
-
360
-
361
-    /**
362
-     * @param int     $EVT_ID
363
-     * @param boolean $include_expired
364
-     * @param boolean $include_deleted
365
-     * @return EE_Datetime
366
-     * @throws EE_Error
367
-     */
368
-    public function get_oldest_datetime_for_event(
369
-        int $EVT_ID,
370
-        bool $include_expired = false,
371
-        bool $include_deleted = false
372
-    ) {
373
-        $results = $this->get_datetimes_for_event_ordered_by_start_time(
374
-            $EVT_ID,
375
-            $include_expired,
376
-            $include_deleted,
377
-            1
378
-        );
379
-        if ($results) {
380
-            return array_shift($results);
381
-        }
382
-        return null;
383
-    }
384
-
385
-
386
-    /**
387
-     * Gets the 'primary' datetime for an event.
388
-     *
389
-     * @param int  $EVT_ID
390
-     * @param bool $try_to_exclude_expired
391
-     * @param bool $try_to_exclude_deleted
392
-     * @return EE_Datetime
393
-     * @throws EE_Error
394
-     */
395
-    public function get_primary_datetime_for_event(
396
-        int $EVT_ID,
397
-        bool $try_to_exclude_expired = true,
398
-        bool $try_to_exclude_deleted = true
399
-    ) {
400
-        if ($try_to_exclude_expired) {
401
-            $non_expired = $this->get_oldest_datetime_for_event($EVT_ID, false, false);
402
-            if ($non_expired) {
403
-                return $non_expired;
404
-            }
405
-        }
406
-        if ($try_to_exclude_deleted) {
407
-            $expired_even = $this->get_oldest_datetime_for_event($EVT_ID, true);
408
-            if ($expired_even) {
409
-                return $expired_even;
410
-            }
411
-        }
412
-        return $this->get_oldest_datetime_for_event($EVT_ID, true, true);
413
-    }
414
-
415
-
416
-    /**
417
-     * Gets ALL the datetimes for an event (including trashed ones, for now), ordered
418
-     * only by start date
419
-     *
420
-     * @param int     $EVT_ID
421
-     * @param boolean $include_expired
422
-     * @param boolean $include_deleted
423
-     * @param int     $limit
424
-     * @return EE_Datetime[]
425
-     * @throws EE_Error
426
-     */
427
-    public function get_datetimes_for_event_ordered_by_start_time(
428
-        int $EVT_ID,
429
-        bool $include_expired = true,
430
-        bool $include_deleted = true,
431
-        $limit = 0
432
-    ) {
433
-        $prev_data_prep_value = $this->prepModelForQuery();
434
-        $where_params         = ['Event.EVT_ID' => absint($EVT_ID)];
435
-        $query_params[0]      = $this->addDefaultWhereParams($where_params, $include_deleted, $include_expired);
436
-        $query_params         = $this->addDefaultWhereConditions(
437
-            $query_params,
438
-            EEM_Base::default_where_conditions_this_only
439
-        );
440
-        $query_params         = $this->addDefaultQueryParams($query_params, $limit, 'DTT_order');
441
-        return $this->getDatetimesAndRestoreModel($query_params, $prev_data_prep_value);
442
-    }
443
-
444
-
445
-    /**
446
-     * Gets ALL the datetimes for an ticket (including trashed ones, for now), ordered
447
-     * only by start date
448
-     *
449
-     * @param int     $TKT_ID
450
-     * @param boolean $include_expired
451
-     * @param boolean $include_deleted
452
-     * @param int     $limit
453
-     * @return EE_Datetime[]
454
-     * @throws EE_Error
455
-     */
456
-    public function get_datetimes_for_ticket_ordered_by_start_time(
457
-        int $TKT_ID,
458
-        bool $include_expired = true,
459
-        bool $include_deleted = true,
460
-        $limit = 0
461
-    ) {
462
-        $prev_data_prep_value = $this->prepModelForQuery();
463
-        $where_params         = ['Ticket.TKT_ID' => absint($TKT_ID)];
464
-        $query_params[0]      = $this->addDefaultWhereParams($where_params, $include_deleted, $include_expired);
465
-        $query_params         = $this->addDefaultQueryParams($query_params, $limit);
466
-        return $this->getDatetimesAndRestoreModel($query_params, $prev_data_prep_value);
467
-    }
468
-
469
-
470
-    /**
471
-     * Gets all the datetimes for a ticket (including trashed ones, for now), ordered by the DTT_order for the
472
-     * datetimes.
473
-     *
474
-     * @param int      $TKT_ID           ID of ticket to retrieve the datetimes for
475
-     * @param boolean  $include_expired  whether to include expired datetimes or not
476
-     * @param boolean  $include_deleted  whether to include trashed datetimes or not.
477
-     * @param int|null $limit            if null, no limit, if int then limit results by
478
-     *                                   that number
479
-     * @return EE_Datetime[]
480
-     * @throws EE_Error
481
-     */
482
-    public function get_datetimes_for_ticket_ordered_by_DTT_order(
483
-        int $TKT_ID,
484
-        bool $include_expired = true,
485
-        bool $include_deleted = true,
486
-        $limit = 0
487
-    ) {
488
-        $prev_data_prep_value = $this->prepModelForQuery();
489
-        $where_params         = ['Ticket.TKT_ID' => absint($TKT_ID)];
490
-        $query_params[0]      = $this->addDefaultWhereParams($where_params, $include_deleted, $include_expired);
491
-        $query_params         = $this->addDefaultQueryParams($query_params, $limit, 'DTT_order');
492
-        return $this->getDatetimesAndRestoreModel($query_params, $prev_data_prep_value);
493
-    }
494
-
495
-
496
-    /**
497
-     * Gets the most important datetime for a particular event (ie, the primary event usually. But if for some WACK
498
-     * reason it doesn't exist, we consider the earliest event the most important)
499
-     *
500
-     * @param int $EVT_ID
501
-     * @return EE_Datetime
502
-     * @throws EE_Error
503
-     */
504
-    public function get_most_important_datetime_for_event(int $EVT_ID)
505
-    {
506
-        $results = $this->get_datetimes_for_event_ordered_by_importance($EVT_ID, 1);
507
-        if ($results) {
508
-            return array_shift($results);
509
-        }
510
-        return null;
511
-    }
512
-
513
-
514
-    /**
515
-     * This returns a wpdb->results        Array of all DTT month and years matching the incoming query params and
516
-     * grouped by month and year.
517
-     *
518
-     * @param array  $where_params       @see
519
-     *                                   https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md#0-where-conditions
520
-     * @param string $evt_active_status  A string representing the evt active status to filter the months by.
521
-     *                                   Can be:
522
-     *                                   - '' = no filter
523
-     *                                   - upcoming = Published events with at least one upcoming datetime.
524
-     *                                   - expired = Events with all datetimes expired.
525
-     *                                   - active = Events that are published and have at least one datetime that
526
-     *                                   starts before now and ends after now.
527
-     *                                   - inactive = Events that are either not published.
528
-     * @return stdClass[]
529
-     * @throws EE_Error
530
-     * @throws InvalidArgumentException
531
-     * @throws InvalidArgumentException
532
-     */
533
-    public function get_dtt_months_and_years(array $where_params, $evt_active_status = '')
534
-    {
535
-        $current_time_for_DTT_EVT_start = $this->current_time_for_query('DTT_EVT_start');
536
-        $current_time_for_DTT_EVT_end   = $this->current_time_for_query('DTT_EVT_end');
537
-        switch ($evt_active_status) {
538
-            case 'upcoming':
539
-                $where_params['Event.status'] = 'publish';
540
-                // if there are already query_params matching DTT_EVT_start then we need to modify that to add them.
541
-                if (isset($where_params['DTT_EVT_start'])) {
542
-                    $where_params['DTT_EVT_start*****'] = $where_params['DTT_EVT_start'];
543
-                }
544
-                $where_params['DTT_EVT_start'] = ['>', $current_time_for_DTT_EVT_start];
545
-                break;
546
-            case 'expired':
547
-                if (isset($where_params['Event.status'])) {
548
-                    unset($where_params['Event.status']);
549
-                }
550
-                // get events to exclude
551
-                $exclude_query[0] = array_merge(
552
-                    $where_params,
553
-                    ['DTT_EVT_end' => ['>', $current_time_for_DTT_EVT_end]]
554
-                );
555
-                // first get all events that have datetimes where its not expired.
556
-                $event_ids = $this->_get_all_wpdb_results(
557
-                    $exclude_query,
558
-                    OBJECT_K,
559
-                    'Datetime.EVT_ID'
560
-                );
561
-                $event_ids = array_keys($event_ids);
562
-                if (isset($where_params['DTT_EVT_end'])) {
563
-                    $where_params['DTT_EVT_end****'] = $where_params['DTT_EVT_end'];
564
-                }
565
-                $where_params['DTT_EVT_end']  = ['<', $current_time_for_DTT_EVT_end];
566
-                $where_params['Event.EVT_ID'] = ['NOT IN', $event_ids];
567
-                break;
568
-            case 'active':
569
-                $where_params['Event.status'] = 'publish';
570
-                if (isset($where_params['DTT_EVT_start'])) {
571
-                    $where_params['Datetime.DTT_EVT_start******'] = $where_params['DTT_EVT_start'];
572
-                }
573
-                if (isset($where_params['Datetime.DTT_EVT_end'])) {
574
-                    $where_params['Datetime.DTT_EVT_end*****'] = $where_params['DTT_EVT_end'];
575
-                }
576
-                $where_params['DTT_EVT_start'] = ['<', $current_time_for_DTT_EVT_start];
577
-                $where_params['DTT_EVT_end']   = ['>', $current_time_for_DTT_EVT_end];
578
-                break;
579
-            case 'inactive':
580
-                if (isset($where_params['Event.status'])) {
581
-                    unset($where_params['Event.status']);
582
-                }
583
-                if (isset($where_params['OR'])) {
584
-                    $where_params['AND']['OR'] = $where_params['OR'];
585
-                }
586
-                if (isset($where_params['DTT_EVT_end'])) {
587
-                    $where_params['AND']['DTT_EVT_end****'] = $where_params['DTT_EVT_end'];
588
-                    unset($where_params['DTT_EVT_end']);
589
-                }
590
-                if (isset($where_params['DTT_EVT_start'])) {
591
-                    $where_params['AND']['DTT_EVT_start'] = $where_params['DTT_EVT_start'];
592
-                    unset($where_params['DTT_EVT_start']);
593
-                }
594
-                $where_params['AND']['Event.status'] = ['!=', 'publish'];
595
-                break;
596
-        }
597
-        $query_params[0]          = $where_params;
598
-        $query_params['group_by'] = ['dtt_year', 'dtt_month'];
599
-        $query_params             = $this->addOrderByQueryParams($query_params, 'DTT_EVT_start', 'DESC');
600
-
601
-        $query_interval    = EEH_DTT_Helper::get_sql_query_interval_for_offset(
602
-            $this->get_timezone(),
603
-            'DTT_EVT_start'
604
-        );
605
-        $columns_to_select = [
606
-            'dtt_year'      => ['YEAR(' . $query_interval . ')', '%s'],
607
-            'dtt_month'     => ['MONTHNAME(' . $query_interval . ')', '%s'],
608
-            'dtt_month_num' => ['MONTH(' . $query_interval . ')', '%s'],
609
-        ];
610
-        return $this->_get_all_wpdb_results($query_params, OBJECT, $columns_to_select);
611
-    }
612
-
613
-
614
-    /**
615
-     * Updates the DTT_sold attribute on each datetime (based on the registrations
616
-     * for the tickets for each datetime)
617
-     *
618
-     * @param EE_Base_Class[]|EE_Datetime[] $datetimes
619
-     * @throws EE_Error
620
-     * @throws ReflectionException
621
-     */
622
-    public function update_sold(array $datetimes)
623
-    {
624
-        EE_Error::doing_it_wrong(
625
-            __FUNCTION__,
626
-            esc_html__(
627
-                'Please use \EEM_Ticket::update_tickets_sold() instead which will in turn correctly update both the Ticket AND Datetime counts.',
628
-                'event_espresso'
629
-            ),
630
-            '4.9.32.rc.005'
631
-        );
632
-        foreach ($datetimes as $datetime) {
633
-            $datetime->update_sold();
634
-        }
635
-    }
636
-
637
-
638
-    /**
639
-     *    Gets the total number of tickets available at a particular datetime
640
-     *    (does NOT take into account the datetime's spaces available)
641
-     *
642
-     * @param int   $DTT_ID
643
-     * @param array $query_params
644
-     * @return int of tickets available. If sold out, return less than 1. If infinite, returns EE_INF,  IF there are NO
645
-     *             tickets attached to datetime then FALSE is returned.
646
-     * @throws EE_Error
647
-     * @throws ReflectionException
648
-     */
649
-    public function sum_tickets_currently_available_at_datetime(int $DTT_ID, array $query_params = [])
650
-    {
651
-        $datetime = $this->get_one_by_ID($DTT_ID);
652
-        if ($datetime instanceof EE_Datetime) {
653
-            return $datetime->tickets_remaining($query_params);
654
-        }
655
-        return 0;
656
-    }
657
-
658
-
659
-    /**
660
-     * This returns an array of counts of datetimes in the database for each Datetime status that can be queried.
661
-     *
662
-     * @param array $stati_to_include  If included you can restrict the statuses we return counts for by including the
663
-     *                                 stati you want counts for as values in the array.  An empty array returns counts
664
-     *                                 for all valid stati.
665
-     * @param array $query_params      If included can be used to refine the conditions for returning the count (i.e.
666
-     *                                 only for Datetimes connected to a specific event, or specific ticket.
667
-     * @return array  The value returned is an array indexed by Datetime Status and the values are the counts.  The
668
-     * @throws EE_Error
669
-     *                                 stati used as index keys are: EE_Datetime::active EE_Datetime::upcoming
670
-     *                                 EE_Datetime::expired
671
-     */
672
-    public function get_datetime_counts_by_status(array $stati_to_include = [], array $query_params = [])
673
-    {
674
-        // only accept where conditions for this query.
675
-        $_where            = isset($query_params[0]) ? $query_params[0] : [];
676
-        $status_query_args = [
677
-            EE_Datetime::active   => array_merge(
678
-                $_where,
679
-                ['DTT_EVT_start' => ['<', time()], 'DTT_EVT_end' => ['>', time()]]
680
-            ),
681
-            EE_Datetime::upcoming => array_merge(
682
-                $_where,
683
-                ['DTT_EVT_start' => ['>', time()]]
684
-            ),
685
-            EE_Datetime::expired  => array_merge(
686
-                $_where,
687
-                ['DTT_EVT_end' => ['<', time()]]
688
-            ),
689
-        ];
690
-        if (! empty($stati_to_include)) {
691
-            foreach (array_keys($status_query_args) as $status) {
692
-                if (! in_array($status, $stati_to_include, true)) {
693
-                    unset($status_query_args[ $status ]);
694
-                }
695
-            }
696
-        }
697
-        // loop through and query counts for each stati.
698
-        $status_query_results = [];
699
-        foreach ($status_query_args as $status => $status_where_conditions) {
700
-            $status_query_results[ $status ] = EEM_Datetime::count(
701
-                [$status_where_conditions],
702
-                'DTT_ID',
703
-                true
704
-            );
705
-        }
706
-        return $status_query_results;
707
-    }
708
-
709
-
710
-    /**
711
-     * Returns the specific count for a given Datetime status matching any given query_params.
712
-     *
713
-     * @param string $status Valid string representation for Datetime status requested. (Defaults to Active).
714
-     * @param array  $query_params
715
-     * @return int
716
-     * @throws EE_Error
717
-     */
718
-    public function get_datetime_count_for_status($status = EE_Datetime::active, array $query_params = [])
719
-    {
720
-        $count = $this->get_datetime_counts_by_status([$status], $query_params);
721
-        return ! empty($count[ $status ]) ? $count[ $status ] : 0;
722
-    }
723
-
724
-
725
-    /**
726
-     * @return bool|int
727
-     * @since   5.0.0.p
728
-     */
729
-    private function prepModelForQuery()
730
-    {
731
-        $prev_data_prep_value = $this->get_assumption_concerning_values_already_prepared_by_model_object();
732
-        $this->assume_values_already_prepared_by_model_object(EEM_Base::prepared_for_use_in_db);
733
-        return $prev_data_prep_value;
734
-    }
735
-
736
-
737
-    /**
738
-     * @param array    $query_params
739
-     * @param bool|int $prev_data_prep_value
740
-     * @return EE_Base_Class[]|EE_Datetime[]
741
-     * @throws EE_Error
742
-     * @since   5.0.0.p
743
-     */
744
-    private function getDatetimesAndRestoreModel(array $query_params, $prev_data_prep_value)
745
-    {
746
-        $result = $this->get_all($query_params);
747
-        $this->assume_values_already_prepared_by_model_object($prev_data_prep_value);
748
-        return $result;
749
-    }
750
-
751
-
752
-    /**
753
-     * @param array  $query_params
754
-     * @param int    $limit
755
-     * @param string $order_by
756
-     * @param string $order
757
-     * @return array
758
-     * @since   5.0.0.p
759
-     */
760
-    private function addDefaultQueryParams(array $query_params, $limit = 0, $order_by = 'DTT_EVT_start', $order = 'ASC')
761
-    {
762
-        $query_params = $this->addOrderByQueryParams($query_params, $order_by, $order);
763
-        $query_params = $this->addLimitQueryParams($query_params, $limit);
764
-        return $query_params;
765
-    }
766
-
767
-
768
-    /**
769
-     * @param array  $query_params
770
-     * @param string $default_where_conditions
771
-     * @return array
772
-     * @since   5.0.0.p
773
-     */
774
-    private function addDefaultWhereConditions(
775
-        array $query_params,
776
-        $default_where_conditions = EEM_Base::default_where_conditions_none
777
-    ) {
778
-        $query_params['default_where_conditions'] = $default_where_conditions;
779
-        return $query_params;
780
-    }
781
-
782
-
783
-    /**
784
-     * @param array $where_params
785
-     * @param bool  $include_deleted
786
-     * @param bool  $include_expired
787
-     * @return array
788
-     * @since   5.0.0.p
789
-     */
790
-    private function addDefaultWhereParams(array $where_params, bool $include_deleted = true, bool $include_expired = true)
791
-    {
792
-        $where_params = $this->addExpiredWhereParams($where_params, $include_expired);
793
-        $where_params = $this->addDeletedWhereParams($where_params, $include_deleted);
794
-        return $where_params;
795
-    }
796
-
797
-
798
-    /**
799
-     * @param array $where_params
800
-     * @param bool  $include_deleted
801
-     * @return array
802
-     * @since   5.0.0.p
803
-     */
804
-    private function addDeletedWhereParams(array $where_params, bool $include_deleted = true)
805
-    {
806
-        $deleted                     = $include_deleted ? [true, false] : [false];
807
-        $where_params['DTT_deleted'] = ['IN', $deleted];
808
-        return $where_params;
809
-    }
810
-
811
-
812
-    /**
813
-     * @param array $where_params
814
-     * @param bool  $include_expired
815
-     * @return array
816
-     * @since   5.0.0.p
817
-     */
818
-    private function addExpiredWhereParams(array $where_params, bool $include_expired = true)
819
-    {
820
-        if (! $include_expired) {
821
-            $where_params['DTT_EVT_end'] = ['>=', current_time('mysql', true)];
822
-        }
823
-        return $where_params;
824
-    }
825
-
826
-
827
-    /**
828
-     * @param array $query_params
829
-     * @param int   $limit
830
-     * @return array
831
-     * @since   5.0.0.p
832
-     */
833
-    private function addLimitQueryParams(array $query_params, $limit = 0)
834
-    {
835
-        if ($limit) {
836
-            $query_params['limit'] = $limit;
837
-        }
838
-        return $query_params;
839
-    }
840
-
841
-
842
-    /**
843
-     * @param array  $query_params
844
-     * @param string $order_by
845
-     * @param string $order
846
-     * @return array
847
-     * @since   5.0.0.p
848
-     */
849
-    private function addOrderByQueryParams(array $query_params, $order_by = 'DTT_EVT_start', $order = 'ASC')
850
-    {
851
-        $order                    = $order === 'ASC' ? 'ASC' : 'DESC';
852
-        $valid_order_columns      = ['DTT_ID', 'DTT_EVT_start', 'DTT_EVT_end', 'DTT_order'];
853
-        $order_by                 = in_array($order_by, $valid_order_columns, true) ? $order_by : 'DTT_EVT_start';
854
-        $query_params['order_by'] = [$order_by => $order];
855
-        return $query_params;
856
-    }
19
+	/**
20
+	 * @var EEM_Datetime $_instance
21
+	 */
22
+	protected static $_instance;
23
+
24
+
25
+	/**
26
+	 * private constructor to prevent direct creation
27
+	 *
28
+	 * @param string $timezone A string representing the timezone we want to set for returned Date Time Strings
29
+	 *                         (and any incoming timezone data that gets saved).
30
+	 *                         Note this just sends the timezone info to the date time model field objects.
31
+	 *                         Default is NULL
32
+	 *                         (and will be assumed using the set timezone in the 'timezone_string' wp option)
33
+	 * @throws EE_Error
34
+	 * @throws InvalidArgumentException
35
+	 * @throws InvalidArgumentException
36
+	 */
37
+	protected function __construct($timezone)
38
+	{
39
+		$this->singular_item           = esc_html__('Datetime', 'event_espresso');
40
+		$this->plural_item             = esc_html__('Datetimes', 'event_espresso');
41
+		$this->_tables                 = [
42
+			'Datetime' => new EE_Primary_Table('esp_datetime', 'DTT_ID'),
43
+		];
44
+		$this->_fields                 = [
45
+			'Datetime' => [
46
+				'DTT_ID'          => new EE_Primary_Key_Int_Field(
47
+					'DTT_ID',
48
+					esc_html__('Datetime ID', 'event_espresso')
49
+				),
50
+				'EVT_ID'          => new EE_Foreign_Key_Int_Field(
51
+					'EVT_ID',
52
+					esc_html__('Event ID', 'event_espresso'),
53
+					false,
54
+					0,
55
+					'Event'
56
+				),
57
+				'VNU_ID' => new EE_Foreign_Key_Int_Field(
58
+					'VNU_ID',
59
+					__('Venue ID', 'event_espresso'),
60
+					false,
61
+					0,
62
+					'Venue'
63
+				),
64
+				'DTT_name'        => new EE_Plain_Text_Field(
65
+					'DTT_name',
66
+					esc_html__('Datetime Name', 'event_espresso'),
67
+					false,
68
+					''
69
+				),
70
+				'DTT_description' => new EE_Post_Content_Field(
71
+					'DTT_description',
72
+					esc_html__('Description for Datetime', 'event_espresso'),
73
+					false,
74
+					''
75
+				),
76
+				'DTT_EVT_start'   => new EE_Datetime_Field(
77
+					'DTT_EVT_start',
78
+					esc_html__('Start time/date of Event', 'event_espresso'),
79
+					false,
80
+					EE_Datetime_Field::now,
81
+					$timezone
82
+				),
83
+				'DTT_EVT_end'     => new EE_Datetime_Field(
84
+					'DTT_EVT_end',
85
+					esc_html__('End time/date of Event', 'event_espresso'),
86
+					false,
87
+					EE_Datetime_Field::now,
88
+					$timezone
89
+				),
90
+				'DTT_reg_limit'   => new EE_Infinite_Integer_Field(
91
+					'DTT_reg_limit',
92
+					esc_html__('Registration Limit for this time', 'event_espresso'),
93
+					true,
94
+					EE_INF
95
+				),
96
+				'DTT_sold'        => new EE_Integer_Field(
97
+					'DTT_sold',
98
+					esc_html__('How many sales for this Datetime that have occurred', 'event_espresso'),
99
+					true,
100
+					0
101
+				),
102
+				'DTT_reserved'    => new EE_Integer_Field(
103
+					'DTT_reserved',
104
+					esc_html__('Quantity of tickets reserved, but not yet fully purchased', 'event_espresso'),
105
+					false,
106
+					0
107
+				),
108
+				'DTT_is_primary'  => new EE_Boolean_Field(
109
+					'DTT_is_primary',
110
+					esc_html__('Flag indicating datetime is primary one for event', 'event_espresso'),
111
+					false,
112
+					false
113
+				),
114
+				'DTT_order'       => new EE_Integer_Field(
115
+					'DTT_order',
116
+					esc_html__('The order in which the Datetime is displayed', 'event_espresso'),
117
+					false,
118
+					0
119
+				),
120
+				'DTT_parent'      => new EE_Integer_Field(
121
+					'DTT_parent',
122
+					esc_html__('Indicates what DTT_ID is the parent of this DTT_ID', 'event_espresso'),
123
+					true,
124
+					0
125
+				),
126
+				'DTT_deleted'     => new EE_Trashed_Flag_Field(
127
+					'DTT_deleted',
128
+					esc_html__('Flag indicating datetime is archived', 'event_espresso'),
129
+					false,
130
+					false
131
+				),
132
+			],
133
+		];
134
+		$this->_model_relations        = [
135
+			'Ticket'          => new EE_HABTM_Relation('Datetime_Ticket'),
136
+			'Event'           => new EE_Belongs_To_Relation(),
137
+			'Checkin'         => new EE_Has_Many_Relation(),
138
+			'Datetime_Ticket' => new EE_Has_Many_Relation(),
139
+			'Venue'           => new EE_Belongs_To_Relation(),
140
+		];
141
+		$path_to_event_model           = 'Event';
142
+		$this->model_chain_to_password = $path_to_event_model;
143
+		$this->_model_chain_to_wp_user = $path_to_event_model;
144
+		// this model is generally available for reading
145
+		$this->_cap_restriction_generators[ EEM_Base::caps_read ]       =
146
+			new EE_Restriction_Generator_Event_Related_Public(
147
+				$path_to_event_model
148
+			);
149
+		$this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] =
150
+			new EE_Restriction_Generator_Event_Related_Protected(
151
+				$path_to_event_model
152
+			);
153
+		$this->_cap_restriction_generators[ EEM_Base::caps_edit ]       =
154
+			new EE_Restriction_Generator_Event_Related_Protected(
155
+				$path_to_event_model
156
+			);
157
+		$this->_cap_restriction_generators[ EEM_Base::caps_delete ]     =
158
+			new EE_Restriction_Generator_Event_Related_Protected(
159
+				$path_to_event_model,
160
+				EEM_Base::caps_edit
161
+			);
162
+		parent::__construct($timezone);
163
+	}
164
+
165
+
166
+	/**
167
+	 * create new blank datetime
168
+	 *
169
+	 * @access public
170
+	 * @return EE_Datetime[] array on success, FALSE on fail
171
+	 * @throws EE_Error
172
+	 * @throws InvalidArgumentException
173
+	 * @throws InvalidDataTypeException
174
+	 * @throws ReflectionException
175
+	 * @throws InvalidInterfaceException
176
+	 */
177
+	public function create_new_blank_datetime()
178
+	{
179
+		// makes sure timezone is always set.
180
+		$timezone_string = $this->get_timezone();
181
+		/**
182
+		 * Filters the initial start date for the new datetime.
183
+		 * Any time included in this value will be overridden later so use additional filters to modify the time.
184
+		 *
185
+		 * @param int $start_date Unix timestamp representing now + 30 days in seconds.
186
+		 * @return int Unix timestamp
187
+		 */
188
+		$start_date = apply_filters(
189
+			'FHEE__EEM_Datetime__create_new_blank_datetime__start_date',
190
+			$this->current_time_for_query('DTT_EVT_start', true) + MONTH_IN_SECONDS
191
+		);
192
+		/**
193
+		 * Filters the initial end date for the new datetime.
194
+		 * Any time included in this value will be overridden later so use additional filters to modify the time.
195
+		 *
196
+		 * @param int $end_data Unix timestamp representing now + 30 days in seconds.
197
+		 * @return int Unix timestamp
198
+		 */
199
+		$end_date       = apply_filters(
200
+			'FHEE__EEM_Datetime__create_new_blank_datetime__end_date',
201
+			$this->current_time_for_query('DTT_EVT_end', true) + MONTH_IN_SECONDS
202
+		);
203
+		$blank_datetime = EE_Datetime::new_instance(
204
+			[
205
+				'DTT_EVT_start' => $start_date,
206
+				'DTT_EVT_end'   => $end_date,
207
+				'DTT_order'     => 1,
208
+				'DTT_reg_limit' => EE_INF,
209
+			],
210
+			$timezone_string
211
+		);
212
+		/**
213
+		 * Filters the initial start time and format for the new EE_Datetime instance.
214
+		 *
215
+		 * @param array $start_time An array having size 2.  First element is the time, second element is the time
216
+		 *                          format.
217
+		 * @return array
218
+		 */
219
+		$start_time = apply_filters(
220
+			'FHEE__EEM_Datetime__create_new_blank_datetime__start_time',
221
+			['8am', 'ga']
222
+		);
223
+		/**
224
+		 * Filters the initial end time and format for the new EE_Datetime instance.
225
+		 *
226
+		 * @param array $end_time An array having size 2.  First element is the time, second element is the time
227
+		 *                        format
228
+		 * @return array
229
+		 */
230
+		$end_time = apply_filters(
231
+			'FHEE__EEM_Datetime__create_new_blank_datetime__end_time',
232
+			['5pm', 'ga']
233
+		);
234
+		$this->validateStartAndEndTimeForBlankDate($start_time, $end_time);
235
+		$blank_datetime->set_start_time(
236
+			$this->convert_datetime_for_query(
237
+				'DTT_EVT_start',
238
+				$start_time[0],
239
+				$start_time[1],
240
+				$timezone_string
241
+			)
242
+		);
243
+		$blank_datetime->set_end_time(
244
+			$this->convert_datetime_for_query(
245
+				'DTT_EVT_end',
246
+				$end_time[0],
247
+				$end_time[1],
248
+				$timezone_string
249
+			)
250
+		);
251
+		return [$blank_datetime];
252
+	}
253
+
254
+
255
+	/**
256
+	 * Validates whether the start_time and end_time are in the expected format.
257
+	 *
258
+	 * @param array $start_time
259
+	 * @param array $end_time
260
+	 * @throws InvalidArgumentException
261
+	 * @throws InvalidDataTypeException
262
+	 */
263
+	private function validateStartAndEndTimeForBlankDate(array $start_time, array $end_time)
264
+	{
265
+		if (! is_array($start_time)) {
266
+			throw new InvalidDataTypeException('start_time', $start_time, 'array');
267
+		}
268
+		if (! is_array($end_time)) {
269
+			throw new InvalidDataTypeException('end_time', $end_time, 'array');
270
+		}
271
+		if (count($start_time) !== 2) {
272
+			throw new InvalidArgumentException(
273
+				sprintf(
274
+					'The variable %1$s is expected to be an array with two elements.  The first item in the '
275
+					. 'array should be a valid time string, the second item in the array should be a valid time format',
276
+					'$start_time'
277
+				)
278
+			);
279
+		}
280
+		if (count($end_time) !== 2) {
281
+			throw new InvalidArgumentException(
282
+				sprintf(
283
+					'The variable %1$s is expected to be an array with two elements.  The first item in the '
284
+					. 'array should be a valid time string, the second item in the array should be a valid time format',
285
+					'$end_time'
286
+				)
287
+			);
288
+		}
289
+	}
290
+
291
+
292
+	/**
293
+	 * get event start date from db
294
+	 *
295
+	 * @access public
296
+	 * @param int $EVT_ID
297
+	 * @return EE_Datetime[] array on success, FALSE on fail
298
+	 * @throws EE_Error
299
+	 * @throws ReflectionException
300
+	 */
301
+	public function get_all_event_dates($EVT_ID = 0)
302
+	{
303
+		if (! $EVT_ID) { // on add_new_event event_id gets set to 0
304
+			return $this->create_new_blank_datetime();
305
+		}
306
+		$results = $this->get_datetimes_for_event_ordered_by_DTT_order($EVT_ID);
307
+		if (empty($results)) {
308
+			return $this->create_new_blank_datetime();
309
+		}
310
+		return $results;
311
+	}
312
+
313
+
314
+	/**
315
+	 * get all datetimes attached to an event ordered by the DTT_order field
316
+	 *
317
+	 * @public
318
+	 * @param int     $EVT_ID     event id
319
+	 * @param boolean $include_expired
320
+	 * @param boolean $include_deleted
321
+	 * @param int     $limit      If included then limit the count of results by
322
+	 *                            the given number
323
+	 * @return EE_Datetime[]
324
+	 * @throws EE_Error
325
+	 */
326
+	public function get_datetimes_for_event_ordered_by_DTT_order(
327
+		int $EVT_ID,
328
+		bool $include_expired = true,
329
+		bool $include_deleted = true,
330
+		$limit = 0
331
+	) {
332
+		$prev_data_prep_value = $this->prepModelForQuery();
333
+		$where_params         = ['Event.EVT_ID' => absint($EVT_ID)];
334
+		$query_params[0]      = $this->addDefaultWhereParams($where_params, $include_deleted, $include_expired);
335
+		$query_params         = $this->addDefaultWhereConditions($query_params);
336
+		$query_params         = $this->addDefaultQueryParams($query_params, $limit, 'DTT_order');
337
+		return $this->getDatetimesAndRestoreModel($query_params, $prev_data_prep_value);
338
+	}
339
+
340
+
341
+	/**
342
+	 * Gets the datetimes for the event (with the given limit), and orders them by "importance".
343
+	 * By importance, we mean that the primary datetimes are most important (DEPRECATED FOR NOW),
344
+	 * and then the earlier datetimes are the most important.
345
+	 * Maybe we'll want this to take into account datetimes that haven't already passed, but we don't yet.
346
+	 *
347
+	 * @param int $EVT_ID
348
+	 * @param int $limit
349
+	 * @return EE_Datetime[]|EE_Base_Class[]
350
+	 * @throws EE_Error
351
+	 */
352
+	public function get_datetimes_for_event_ordered_by_importance(int $EVT_ID, $limit = 0)
353
+	{
354
+		$query_params[0] = ['Event.EVT_ID' => absint($EVT_ID)];
355
+		$query_params    = $this->addDefaultWhereConditions($query_params);
356
+		$query_params    = $this->addDefaultQueryParams($query_params, $limit);
357
+		return $this->get_all($query_params);
358
+	}
359
+
360
+
361
+	/**
362
+	 * @param int     $EVT_ID
363
+	 * @param boolean $include_expired
364
+	 * @param boolean $include_deleted
365
+	 * @return EE_Datetime
366
+	 * @throws EE_Error
367
+	 */
368
+	public function get_oldest_datetime_for_event(
369
+		int $EVT_ID,
370
+		bool $include_expired = false,
371
+		bool $include_deleted = false
372
+	) {
373
+		$results = $this->get_datetimes_for_event_ordered_by_start_time(
374
+			$EVT_ID,
375
+			$include_expired,
376
+			$include_deleted,
377
+			1
378
+		);
379
+		if ($results) {
380
+			return array_shift($results);
381
+		}
382
+		return null;
383
+	}
384
+
385
+
386
+	/**
387
+	 * Gets the 'primary' datetime for an event.
388
+	 *
389
+	 * @param int  $EVT_ID
390
+	 * @param bool $try_to_exclude_expired
391
+	 * @param bool $try_to_exclude_deleted
392
+	 * @return EE_Datetime
393
+	 * @throws EE_Error
394
+	 */
395
+	public function get_primary_datetime_for_event(
396
+		int $EVT_ID,
397
+		bool $try_to_exclude_expired = true,
398
+		bool $try_to_exclude_deleted = true
399
+	) {
400
+		if ($try_to_exclude_expired) {
401
+			$non_expired = $this->get_oldest_datetime_for_event($EVT_ID, false, false);
402
+			if ($non_expired) {
403
+				return $non_expired;
404
+			}
405
+		}
406
+		if ($try_to_exclude_deleted) {
407
+			$expired_even = $this->get_oldest_datetime_for_event($EVT_ID, true);
408
+			if ($expired_even) {
409
+				return $expired_even;
410
+			}
411
+		}
412
+		return $this->get_oldest_datetime_for_event($EVT_ID, true, true);
413
+	}
414
+
415
+
416
+	/**
417
+	 * Gets ALL the datetimes for an event (including trashed ones, for now), ordered
418
+	 * only by start date
419
+	 *
420
+	 * @param int     $EVT_ID
421
+	 * @param boolean $include_expired
422
+	 * @param boolean $include_deleted
423
+	 * @param int     $limit
424
+	 * @return EE_Datetime[]
425
+	 * @throws EE_Error
426
+	 */
427
+	public function get_datetimes_for_event_ordered_by_start_time(
428
+		int $EVT_ID,
429
+		bool $include_expired = true,
430
+		bool $include_deleted = true,
431
+		$limit = 0
432
+	) {
433
+		$prev_data_prep_value = $this->prepModelForQuery();
434
+		$where_params         = ['Event.EVT_ID' => absint($EVT_ID)];
435
+		$query_params[0]      = $this->addDefaultWhereParams($where_params, $include_deleted, $include_expired);
436
+		$query_params         = $this->addDefaultWhereConditions(
437
+			$query_params,
438
+			EEM_Base::default_where_conditions_this_only
439
+		);
440
+		$query_params         = $this->addDefaultQueryParams($query_params, $limit, 'DTT_order');
441
+		return $this->getDatetimesAndRestoreModel($query_params, $prev_data_prep_value);
442
+	}
443
+
444
+
445
+	/**
446
+	 * Gets ALL the datetimes for an ticket (including trashed ones, for now), ordered
447
+	 * only by start date
448
+	 *
449
+	 * @param int     $TKT_ID
450
+	 * @param boolean $include_expired
451
+	 * @param boolean $include_deleted
452
+	 * @param int     $limit
453
+	 * @return EE_Datetime[]
454
+	 * @throws EE_Error
455
+	 */
456
+	public function get_datetimes_for_ticket_ordered_by_start_time(
457
+		int $TKT_ID,
458
+		bool $include_expired = true,
459
+		bool $include_deleted = true,
460
+		$limit = 0
461
+	) {
462
+		$prev_data_prep_value = $this->prepModelForQuery();
463
+		$where_params         = ['Ticket.TKT_ID' => absint($TKT_ID)];
464
+		$query_params[0]      = $this->addDefaultWhereParams($where_params, $include_deleted, $include_expired);
465
+		$query_params         = $this->addDefaultQueryParams($query_params, $limit);
466
+		return $this->getDatetimesAndRestoreModel($query_params, $prev_data_prep_value);
467
+	}
468
+
469
+
470
+	/**
471
+	 * Gets all the datetimes for a ticket (including trashed ones, for now), ordered by the DTT_order for the
472
+	 * datetimes.
473
+	 *
474
+	 * @param int      $TKT_ID           ID of ticket to retrieve the datetimes for
475
+	 * @param boolean  $include_expired  whether to include expired datetimes or not
476
+	 * @param boolean  $include_deleted  whether to include trashed datetimes or not.
477
+	 * @param int|null $limit            if null, no limit, if int then limit results by
478
+	 *                                   that number
479
+	 * @return EE_Datetime[]
480
+	 * @throws EE_Error
481
+	 */
482
+	public function get_datetimes_for_ticket_ordered_by_DTT_order(
483
+		int $TKT_ID,
484
+		bool $include_expired = true,
485
+		bool $include_deleted = true,
486
+		$limit = 0
487
+	) {
488
+		$prev_data_prep_value = $this->prepModelForQuery();
489
+		$where_params         = ['Ticket.TKT_ID' => absint($TKT_ID)];
490
+		$query_params[0]      = $this->addDefaultWhereParams($where_params, $include_deleted, $include_expired);
491
+		$query_params         = $this->addDefaultQueryParams($query_params, $limit, 'DTT_order');
492
+		return $this->getDatetimesAndRestoreModel($query_params, $prev_data_prep_value);
493
+	}
494
+
495
+
496
+	/**
497
+	 * Gets the most important datetime for a particular event (ie, the primary event usually. But if for some WACK
498
+	 * reason it doesn't exist, we consider the earliest event the most important)
499
+	 *
500
+	 * @param int $EVT_ID
501
+	 * @return EE_Datetime
502
+	 * @throws EE_Error
503
+	 */
504
+	public function get_most_important_datetime_for_event(int $EVT_ID)
505
+	{
506
+		$results = $this->get_datetimes_for_event_ordered_by_importance($EVT_ID, 1);
507
+		if ($results) {
508
+			return array_shift($results);
509
+		}
510
+		return null;
511
+	}
512
+
513
+
514
+	/**
515
+	 * This returns a wpdb->results        Array of all DTT month and years matching the incoming query params and
516
+	 * grouped by month and year.
517
+	 *
518
+	 * @param array  $where_params       @see
519
+	 *                                   https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md#0-where-conditions
520
+	 * @param string $evt_active_status  A string representing the evt active status to filter the months by.
521
+	 *                                   Can be:
522
+	 *                                   - '' = no filter
523
+	 *                                   - upcoming = Published events with at least one upcoming datetime.
524
+	 *                                   - expired = Events with all datetimes expired.
525
+	 *                                   - active = Events that are published and have at least one datetime that
526
+	 *                                   starts before now and ends after now.
527
+	 *                                   - inactive = Events that are either not published.
528
+	 * @return stdClass[]
529
+	 * @throws EE_Error
530
+	 * @throws InvalidArgumentException
531
+	 * @throws InvalidArgumentException
532
+	 */
533
+	public function get_dtt_months_and_years(array $where_params, $evt_active_status = '')
534
+	{
535
+		$current_time_for_DTT_EVT_start = $this->current_time_for_query('DTT_EVT_start');
536
+		$current_time_for_DTT_EVT_end   = $this->current_time_for_query('DTT_EVT_end');
537
+		switch ($evt_active_status) {
538
+			case 'upcoming':
539
+				$where_params['Event.status'] = 'publish';
540
+				// if there are already query_params matching DTT_EVT_start then we need to modify that to add them.
541
+				if (isset($where_params['DTT_EVT_start'])) {
542
+					$where_params['DTT_EVT_start*****'] = $where_params['DTT_EVT_start'];
543
+				}
544
+				$where_params['DTT_EVT_start'] = ['>', $current_time_for_DTT_EVT_start];
545
+				break;
546
+			case 'expired':
547
+				if (isset($where_params['Event.status'])) {
548
+					unset($where_params['Event.status']);
549
+				}
550
+				// get events to exclude
551
+				$exclude_query[0] = array_merge(
552
+					$where_params,
553
+					['DTT_EVT_end' => ['>', $current_time_for_DTT_EVT_end]]
554
+				);
555
+				// first get all events that have datetimes where its not expired.
556
+				$event_ids = $this->_get_all_wpdb_results(
557
+					$exclude_query,
558
+					OBJECT_K,
559
+					'Datetime.EVT_ID'
560
+				);
561
+				$event_ids = array_keys($event_ids);
562
+				if (isset($where_params['DTT_EVT_end'])) {
563
+					$where_params['DTT_EVT_end****'] = $where_params['DTT_EVT_end'];
564
+				}
565
+				$where_params['DTT_EVT_end']  = ['<', $current_time_for_DTT_EVT_end];
566
+				$where_params['Event.EVT_ID'] = ['NOT IN', $event_ids];
567
+				break;
568
+			case 'active':
569
+				$where_params['Event.status'] = 'publish';
570
+				if (isset($where_params['DTT_EVT_start'])) {
571
+					$where_params['Datetime.DTT_EVT_start******'] = $where_params['DTT_EVT_start'];
572
+				}
573
+				if (isset($where_params['Datetime.DTT_EVT_end'])) {
574
+					$where_params['Datetime.DTT_EVT_end*****'] = $where_params['DTT_EVT_end'];
575
+				}
576
+				$where_params['DTT_EVT_start'] = ['<', $current_time_for_DTT_EVT_start];
577
+				$where_params['DTT_EVT_end']   = ['>', $current_time_for_DTT_EVT_end];
578
+				break;
579
+			case 'inactive':
580
+				if (isset($where_params['Event.status'])) {
581
+					unset($where_params['Event.status']);
582
+				}
583
+				if (isset($where_params['OR'])) {
584
+					$where_params['AND']['OR'] = $where_params['OR'];
585
+				}
586
+				if (isset($where_params['DTT_EVT_end'])) {
587
+					$where_params['AND']['DTT_EVT_end****'] = $where_params['DTT_EVT_end'];
588
+					unset($where_params['DTT_EVT_end']);
589
+				}
590
+				if (isset($where_params['DTT_EVT_start'])) {
591
+					$where_params['AND']['DTT_EVT_start'] = $where_params['DTT_EVT_start'];
592
+					unset($where_params['DTT_EVT_start']);
593
+				}
594
+				$where_params['AND']['Event.status'] = ['!=', 'publish'];
595
+				break;
596
+		}
597
+		$query_params[0]          = $where_params;
598
+		$query_params['group_by'] = ['dtt_year', 'dtt_month'];
599
+		$query_params             = $this->addOrderByQueryParams($query_params, 'DTT_EVT_start', 'DESC');
600
+
601
+		$query_interval    = EEH_DTT_Helper::get_sql_query_interval_for_offset(
602
+			$this->get_timezone(),
603
+			'DTT_EVT_start'
604
+		);
605
+		$columns_to_select = [
606
+			'dtt_year'      => ['YEAR(' . $query_interval . ')', '%s'],
607
+			'dtt_month'     => ['MONTHNAME(' . $query_interval . ')', '%s'],
608
+			'dtt_month_num' => ['MONTH(' . $query_interval . ')', '%s'],
609
+		];
610
+		return $this->_get_all_wpdb_results($query_params, OBJECT, $columns_to_select);
611
+	}
612
+
613
+
614
+	/**
615
+	 * Updates the DTT_sold attribute on each datetime (based on the registrations
616
+	 * for the tickets for each datetime)
617
+	 *
618
+	 * @param EE_Base_Class[]|EE_Datetime[] $datetimes
619
+	 * @throws EE_Error
620
+	 * @throws ReflectionException
621
+	 */
622
+	public function update_sold(array $datetimes)
623
+	{
624
+		EE_Error::doing_it_wrong(
625
+			__FUNCTION__,
626
+			esc_html__(
627
+				'Please use \EEM_Ticket::update_tickets_sold() instead which will in turn correctly update both the Ticket AND Datetime counts.',
628
+				'event_espresso'
629
+			),
630
+			'4.9.32.rc.005'
631
+		);
632
+		foreach ($datetimes as $datetime) {
633
+			$datetime->update_sold();
634
+		}
635
+	}
636
+
637
+
638
+	/**
639
+	 *    Gets the total number of tickets available at a particular datetime
640
+	 *    (does NOT take into account the datetime's spaces available)
641
+	 *
642
+	 * @param int   $DTT_ID
643
+	 * @param array $query_params
644
+	 * @return int of tickets available. If sold out, return less than 1. If infinite, returns EE_INF,  IF there are NO
645
+	 *             tickets attached to datetime then FALSE is returned.
646
+	 * @throws EE_Error
647
+	 * @throws ReflectionException
648
+	 */
649
+	public function sum_tickets_currently_available_at_datetime(int $DTT_ID, array $query_params = [])
650
+	{
651
+		$datetime = $this->get_one_by_ID($DTT_ID);
652
+		if ($datetime instanceof EE_Datetime) {
653
+			return $datetime->tickets_remaining($query_params);
654
+		}
655
+		return 0;
656
+	}
657
+
658
+
659
+	/**
660
+	 * This returns an array of counts of datetimes in the database for each Datetime status that can be queried.
661
+	 *
662
+	 * @param array $stati_to_include  If included you can restrict the statuses we return counts for by including the
663
+	 *                                 stati you want counts for as values in the array.  An empty array returns counts
664
+	 *                                 for all valid stati.
665
+	 * @param array $query_params      If included can be used to refine the conditions for returning the count (i.e.
666
+	 *                                 only for Datetimes connected to a specific event, or specific ticket.
667
+	 * @return array  The value returned is an array indexed by Datetime Status and the values are the counts.  The
668
+	 * @throws EE_Error
669
+	 *                                 stati used as index keys are: EE_Datetime::active EE_Datetime::upcoming
670
+	 *                                 EE_Datetime::expired
671
+	 */
672
+	public function get_datetime_counts_by_status(array $stati_to_include = [], array $query_params = [])
673
+	{
674
+		// only accept where conditions for this query.
675
+		$_where            = isset($query_params[0]) ? $query_params[0] : [];
676
+		$status_query_args = [
677
+			EE_Datetime::active   => array_merge(
678
+				$_where,
679
+				['DTT_EVT_start' => ['<', time()], 'DTT_EVT_end' => ['>', time()]]
680
+			),
681
+			EE_Datetime::upcoming => array_merge(
682
+				$_where,
683
+				['DTT_EVT_start' => ['>', time()]]
684
+			),
685
+			EE_Datetime::expired  => array_merge(
686
+				$_where,
687
+				['DTT_EVT_end' => ['<', time()]]
688
+			),
689
+		];
690
+		if (! empty($stati_to_include)) {
691
+			foreach (array_keys($status_query_args) as $status) {
692
+				if (! in_array($status, $stati_to_include, true)) {
693
+					unset($status_query_args[ $status ]);
694
+				}
695
+			}
696
+		}
697
+		// loop through and query counts for each stati.
698
+		$status_query_results = [];
699
+		foreach ($status_query_args as $status => $status_where_conditions) {
700
+			$status_query_results[ $status ] = EEM_Datetime::count(
701
+				[$status_where_conditions],
702
+				'DTT_ID',
703
+				true
704
+			);
705
+		}
706
+		return $status_query_results;
707
+	}
708
+
709
+
710
+	/**
711
+	 * Returns the specific count for a given Datetime status matching any given query_params.
712
+	 *
713
+	 * @param string $status Valid string representation for Datetime status requested. (Defaults to Active).
714
+	 * @param array  $query_params
715
+	 * @return int
716
+	 * @throws EE_Error
717
+	 */
718
+	public function get_datetime_count_for_status($status = EE_Datetime::active, array $query_params = [])
719
+	{
720
+		$count = $this->get_datetime_counts_by_status([$status], $query_params);
721
+		return ! empty($count[ $status ]) ? $count[ $status ] : 0;
722
+	}
723
+
724
+
725
+	/**
726
+	 * @return bool|int
727
+	 * @since   5.0.0.p
728
+	 */
729
+	private function prepModelForQuery()
730
+	{
731
+		$prev_data_prep_value = $this->get_assumption_concerning_values_already_prepared_by_model_object();
732
+		$this->assume_values_already_prepared_by_model_object(EEM_Base::prepared_for_use_in_db);
733
+		return $prev_data_prep_value;
734
+	}
735
+
736
+
737
+	/**
738
+	 * @param array    $query_params
739
+	 * @param bool|int $prev_data_prep_value
740
+	 * @return EE_Base_Class[]|EE_Datetime[]
741
+	 * @throws EE_Error
742
+	 * @since   5.0.0.p
743
+	 */
744
+	private function getDatetimesAndRestoreModel(array $query_params, $prev_data_prep_value)
745
+	{
746
+		$result = $this->get_all($query_params);
747
+		$this->assume_values_already_prepared_by_model_object($prev_data_prep_value);
748
+		return $result;
749
+	}
750
+
751
+
752
+	/**
753
+	 * @param array  $query_params
754
+	 * @param int    $limit
755
+	 * @param string $order_by
756
+	 * @param string $order
757
+	 * @return array
758
+	 * @since   5.0.0.p
759
+	 */
760
+	private function addDefaultQueryParams(array $query_params, $limit = 0, $order_by = 'DTT_EVT_start', $order = 'ASC')
761
+	{
762
+		$query_params = $this->addOrderByQueryParams($query_params, $order_by, $order);
763
+		$query_params = $this->addLimitQueryParams($query_params, $limit);
764
+		return $query_params;
765
+	}
766
+
767
+
768
+	/**
769
+	 * @param array  $query_params
770
+	 * @param string $default_where_conditions
771
+	 * @return array
772
+	 * @since   5.0.0.p
773
+	 */
774
+	private function addDefaultWhereConditions(
775
+		array $query_params,
776
+		$default_where_conditions = EEM_Base::default_where_conditions_none
777
+	) {
778
+		$query_params['default_where_conditions'] = $default_where_conditions;
779
+		return $query_params;
780
+	}
781
+
782
+
783
+	/**
784
+	 * @param array $where_params
785
+	 * @param bool  $include_deleted
786
+	 * @param bool  $include_expired
787
+	 * @return array
788
+	 * @since   5.0.0.p
789
+	 */
790
+	private function addDefaultWhereParams(array $where_params, bool $include_deleted = true, bool $include_expired = true)
791
+	{
792
+		$where_params = $this->addExpiredWhereParams($where_params, $include_expired);
793
+		$where_params = $this->addDeletedWhereParams($where_params, $include_deleted);
794
+		return $where_params;
795
+	}
796
+
797
+
798
+	/**
799
+	 * @param array $where_params
800
+	 * @param bool  $include_deleted
801
+	 * @return array
802
+	 * @since   5.0.0.p
803
+	 */
804
+	private function addDeletedWhereParams(array $where_params, bool $include_deleted = true)
805
+	{
806
+		$deleted                     = $include_deleted ? [true, false] : [false];
807
+		$where_params['DTT_deleted'] = ['IN', $deleted];
808
+		return $where_params;
809
+	}
810
+
811
+
812
+	/**
813
+	 * @param array $where_params
814
+	 * @param bool  $include_expired
815
+	 * @return array
816
+	 * @since   5.0.0.p
817
+	 */
818
+	private function addExpiredWhereParams(array $where_params, bool $include_expired = true)
819
+	{
820
+		if (! $include_expired) {
821
+			$where_params['DTT_EVT_end'] = ['>=', current_time('mysql', true)];
822
+		}
823
+		return $where_params;
824
+	}
825
+
826
+
827
+	/**
828
+	 * @param array $query_params
829
+	 * @param int   $limit
830
+	 * @return array
831
+	 * @since   5.0.0.p
832
+	 */
833
+	private function addLimitQueryParams(array $query_params, $limit = 0)
834
+	{
835
+		if ($limit) {
836
+			$query_params['limit'] = $limit;
837
+		}
838
+		return $query_params;
839
+	}
840
+
841
+
842
+	/**
843
+	 * @param array  $query_params
844
+	 * @param string $order_by
845
+	 * @param string $order
846
+	 * @return array
847
+	 * @since   5.0.0.p
848
+	 */
849
+	private function addOrderByQueryParams(array $query_params, $order_by = 'DTT_EVT_start', $order = 'ASC')
850
+	{
851
+		$order                    = $order === 'ASC' ? 'ASC' : 'DESC';
852
+		$valid_order_columns      = ['DTT_ID', 'DTT_EVT_start', 'DTT_EVT_end', 'DTT_order'];
853
+		$order_by                 = in_array($order_by, $valid_order_columns, true) ? $order_by : 'DTT_EVT_start';
854
+		$query_params['order_by'] = [$order_by => $order];
855
+		return $query_params;
856
+	}
857 857
 }
Please login to merge, or discard this patch.