Completed
Branch EE5Update (bc64e6)
by
unknown
09:36 queued 05:38
created
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/domain/entities/routing/data_nodes/core/Api.php 1 patch
Indentation   +34 added lines, -34 removed lines patch added patch discarded remove patch
@@ -18,38 +18,38 @@
 block discarded – undo
18 18
  */
19 19
 class Api extends JsonDataNode
20 20
 {
21
-    const NODE_NAME = 'api';
22
-
23
-
24
-    /**
25
-     * @param JsonDataNodeValidator $validator
26
-     */
27
-    public function __construct(JsonDataNodeValidator $validator)
28
-    {
29
-        parent::__construct($validator);
30
-        $this->setNodeName(Api::NODE_NAME);
31
-    }
32
-
33
-
34
-    /**
35
-     * @throws DomainException
36
-     * @since $VID:$
37
-     */
38
-    public function initialize()
39
-    {
40
-        $this->addData('restApiNonce', wp_create_nonce('wp_rest'));
41
-        $this->addData('restApiBaseUrl', rest_url());
42
-        $this->addData('restApiRouteUrl', rest_url('ee/v4.8.36/'));
43
-        $this->addData('restApiCollectionEndpoints', EED_Core_Rest_Api::getCollectionRoutesIndexedByModelName());
44
-        $this->addData('restApiPrimaryKeys', EED_Core_Rest_Api::getPrimaryKeyNamesIndexedByModelName());
45
-
46
-        // route can be something like 'graphql'
47
-        $route = trim(Router::$route, '/');
48
-        // make sure we are dealing with sane folks
49
-        $has_pretty_permalinks = (bool) get_option('permalink_structure');
50
-        // if pretty permalinks, use '/graphql' otherwise '?graphql=1'
51
-        $graphqlEndpoint = $has_pretty_permalinks ? site_url($route) : add_query_arg($route, 1, site_url());
52
-        $this->addData('graphqlEndpoint', esc_url($graphqlEndpoint));
53
-        $this->setInitialized(true);
54
-    }
21
+	const NODE_NAME = 'api';
22
+
23
+
24
+	/**
25
+	 * @param JsonDataNodeValidator $validator
26
+	 */
27
+	public function __construct(JsonDataNodeValidator $validator)
28
+	{
29
+		parent::__construct($validator);
30
+		$this->setNodeName(Api::NODE_NAME);
31
+	}
32
+
33
+
34
+	/**
35
+	 * @throws DomainException
36
+	 * @since $VID:$
37
+	 */
38
+	public function initialize()
39
+	{
40
+		$this->addData('restApiNonce', wp_create_nonce('wp_rest'));
41
+		$this->addData('restApiBaseUrl', rest_url());
42
+		$this->addData('restApiRouteUrl', rest_url('ee/v4.8.36/'));
43
+		$this->addData('restApiCollectionEndpoints', EED_Core_Rest_Api::getCollectionRoutesIndexedByModelName());
44
+		$this->addData('restApiPrimaryKeys', EED_Core_Rest_Api::getPrimaryKeyNamesIndexedByModelName());
45
+
46
+		// route can be something like 'graphql'
47
+		$route = trim(Router::$route, '/');
48
+		// make sure we are dealing with sane folks
49
+		$has_pretty_permalinks = (bool) get_option('permalink_structure');
50
+		// if pretty permalinks, use '/graphql' otherwise '?graphql=1'
51
+		$graphqlEndpoint = $has_pretty_permalinks ? site_url($route) : add_query_arg($route, 1, site_url());
52
+		$this->addData('graphqlEndpoint', esc_url($graphqlEndpoint));
53
+		$this->setInitialized(true);
54
+	}
55 55
 }
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
@@ -12,842 +12,842 @@
 block discarded – undo
12 12
  */
13 13
 class EEM_Datetime extends EEM_Soft_Delete_Base
14 14
 {
15
-    /**
16
-     * @var EEM_Datetime $_instance
17
-     */
18
-    protected static $_instance;
19
-
20
-
21
-    /**
22
-     * private constructor to prevent direct creation
23
-     *
24
-     * @param string $timezone A string representing the timezone we want to set for returned Date Time Strings
25
-     *                         (and any incoming timezone data that gets saved).
26
-     *                         Note this just sends the timezone info to the date time model field objects.
27
-     *                         Default is NULL
28
-     *                         (and will be assumed using the set timezone in the 'timezone_string' wp option)
29
-     * @throws EE_Error
30
-     * @throws InvalidArgumentException
31
-     * @throws InvalidArgumentException
32
-     */
33
-    protected function __construct($timezone)
34
-    {
35
-        $this->singular_item           = esc_html__('Datetime', 'event_espresso');
36
-        $this->plural_item             = esc_html__('Datetimes', 'event_espresso');
37
-        $this->_tables                 = [
38
-            'Datetime' => new EE_Primary_Table('esp_datetime', 'DTT_ID'),
39
-        ];
40
-        $this->_fields                 = [
41
-            'Datetime' => [
42
-                'DTT_ID'          => new EE_Primary_Key_Int_Field(
43
-                    'DTT_ID',
44
-                    esc_html__('Datetime ID', 'event_espresso')
45
-                ),
46
-                'EVT_ID'          => new EE_Foreign_Key_Int_Field(
47
-                    'EVT_ID',
48
-                    esc_html__('Event ID', 'event_espresso'),
49
-                    false,
50
-                    0,
51
-                    'Event'
52
-                ),
53
-                'VNU_ID' => new EE_Foreign_Key_Int_Field(
54
-                    'VNU_ID',
55
-                    __('Venue ID', 'event_espresso'),
56
-                    false,
57
-                    0,
58
-                    'Venue'
59
-                ),
60
-                'DTT_name'        => new EE_Plain_Text_Field(
61
-                    'DTT_name',
62
-                    esc_html__('Datetime Name', 'event_espresso'),
63
-                    false,
64
-                    ''
65
-                ),
66
-                'DTT_description' => new EE_Post_Content_Field(
67
-                    'DTT_description',
68
-                    esc_html__('Description for Datetime', 'event_espresso'),
69
-                    false,
70
-                    ''
71
-                ),
72
-                'DTT_EVT_start'   => new EE_Datetime_Field(
73
-                    'DTT_EVT_start',
74
-                    esc_html__('Start time/date of Event', 'event_espresso'),
75
-                    false,
76
-                    EE_Datetime_Field::now,
77
-                    $timezone
78
-                ),
79
-                'DTT_EVT_end'     => new EE_Datetime_Field(
80
-                    'DTT_EVT_end',
81
-                    esc_html__('End time/date of Event', 'event_espresso'),
82
-                    false,
83
-                    EE_Datetime_Field::now,
84
-                    $timezone
85
-                ),
86
-                'DTT_reg_limit'   => new EE_Infinite_Integer_Field(
87
-                    'DTT_reg_limit',
88
-                    esc_html__('Registration Limit for this time', 'event_espresso'),
89
-                    true,
90
-                    EE_INF
91
-                ),
92
-                'DTT_sold'        => new EE_Integer_Field(
93
-                    'DTT_sold',
94
-                    esc_html__('How many sales for this Datetime that have occurred', 'event_espresso'),
95
-                    true,
96
-                    0
97
-                ),
98
-                'DTT_reserved'    => new EE_Integer_Field(
99
-                    'DTT_reserved',
100
-                    esc_html__('Quantity of tickets reserved, but not yet fully purchased', 'event_espresso'),
101
-                    false,
102
-                    0
103
-                ),
104
-                'DTT_is_primary'  => new EE_Boolean_Field(
105
-                    'DTT_is_primary',
106
-                    esc_html__('Flag indicating datetime is primary one for event', 'event_espresso'),
107
-                    false,
108
-                    false
109
-                ),
110
-                'DTT_order'       => new EE_Integer_Field(
111
-                    'DTT_order',
112
-                    esc_html__('The order in which the Datetime is displayed', 'event_espresso'),
113
-                    false,
114
-                    0
115
-                ),
116
-                'DTT_parent'      => new EE_Integer_Field(
117
-                    'DTT_parent',
118
-                    esc_html__('Indicates what DTT_ID is the parent of this DTT_ID', 'event_espresso'),
119
-                    true,
120
-                    0
121
-                ),
122
-                'DTT_deleted'     => new EE_Trashed_Flag_Field(
123
-                    'DTT_deleted',
124
-                    esc_html__('Flag indicating datetime is archived', 'event_espresso'),
125
-                    false,
126
-                    false
127
-                ),
128
-            ],
129
-        ];
130
-        $this->_model_relations        = [
131
-            'Ticket'          => new EE_HABTM_Relation('Datetime_Ticket'),
132
-            'Event'           => new EE_Belongs_To_Relation(),
133
-            'Checkin'         => new EE_Has_Many_Relation(),
134
-            'Datetime_Ticket' => new EE_Has_Many_Relation(),
135
-            'Venue'           => new EE_Belongs_To_Relation(),
136
-        ];
137
-        $path_to_event_model           = 'Event';
138
-        $this->model_chain_to_password = $path_to_event_model;
139
-        $this->_model_chain_to_wp_user = $path_to_event_model;
140
-        // this model is generally available for reading
141
-        $this->_cap_restriction_generators[ EEM_Base::caps_read ]       =
142
-            new EE_Restriction_Generator_Event_Related_Public(
143
-                $path_to_event_model
144
-            );
145
-        $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] =
146
-            new EE_Restriction_Generator_Event_Related_Protected(
147
-                $path_to_event_model
148
-            );
149
-        $this->_cap_restriction_generators[ EEM_Base::caps_edit ]       =
150
-            new EE_Restriction_Generator_Event_Related_Protected(
151
-                $path_to_event_model
152
-            );
153
-        $this->_cap_restriction_generators[ EEM_Base::caps_delete ]     =
154
-            new EE_Restriction_Generator_Event_Related_Protected(
155
-                $path_to_event_model,
156
-                EEM_Base::caps_edit
157
-            );
158
-        parent::__construct($timezone);
159
-    }
160
-
161
-
162
-    /**
163
-     * create new blank datetime
164
-     *
165
-     * @access public
166
-     * @return EE_Datetime[] array on success, FALSE on fail
167
-     * @throws EE_Error
168
-     * @throws InvalidArgumentException
169
-     * @throws InvalidDataTypeException
170
-     * @throws ReflectionException
171
-     * @throws InvalidInterfaceException
172
-     */
173
-    public function create_new_blank_datetime()
174
-    {
175
-        // makes sure timezone is always set.
176
-        $timezone_string = $this->get_timezone();
177
-        /**
178
-         * Filters the initial start date for the new datetime.
179
-         * Any time included in this value will be overridden later so use additional filters to modify the time.
180
-         *
181
-         * @param int $start_date Unix timestamp representing now + 30 days in seconds.
182
-         * @return int Unix timestamp
183
-         */
184
-        $start_date = apply_filters(
185
-            'FHEE__EEM_Datetime__create_new_blank_datetime__start_date',
186
-            $this->current_time_for_query('DTT_EVT_start', true) + MONTH_IN_SECONDS
187
-        );
188
-        /**
189
-         * Filters the initial end date for the new datetime.
190
-         * Any time included in this value will be overridden later so use additional filters to modify the time.
191
-         *
192
-         * @param int $end_data Unix timestamp representing now + 30 days in seconds.
193
-         * @return int Unix timestamp
194
-         */
195
-        $end_date       = apply_filters(
196
-            'FHEE__EEM_Datetime__create_new_blank_datetime__end_date',
197
-            $this->current_time_for_query('DTT_EVT_end', true) + MONTH_IN_SECONDS
198
-        );
199
-        $blank_datetime = EE_Datetime::new_instance(
200
-            [
201
-                'DTT_EVT_start' => $start_date,
202
-                'DTT_EVT_end'   => $end_date,
203
-                'DTT_order'     => 1,
204
-                'DTT_reg_limit' => EE_INF,
205
-            ],
206
-            $timezone_string
207
-        );
208
-        /**
209
-         * Filters the initial start time and format for the new EE_Datetime instance.
210
-         *
211
-         * @param array $start_time An array having size 2.  First element is the time, second element is the time
212
-         *                          format.
213
-         * @return array
214
-         */
215
-        $start_time = apply_filters(
216
-            'FHEE__EEM_Datetime__create_new_blank_datetime__start_time',
217
-            ['8am', 'ga']
218
-        );
219
-        /**
220
-         * Filters the initial end time and format for the new EE_Datetime instance.
221
-         *
222
-         * @param array $end_time An array having size 2.  First element is the time, second element is the time
223
-         *                        format
224
-         * @return array
225
-         */
226
-        $end_time = apply_filters(
227
-            'FHEE__EEM_Datetime__create_new_blank_datetime__end_time',
228
-            ['5pm', 'ga']
229
-        );
230
-        $this->validateStartAndEndTimeForBlankDate($start_time, $end_time);
231
-        $blank_datetime->set_start_time(
232
-            $this->convert_datetime_for_query(
233
-                'DTT_EVT_start',
234
-                $start_time[0],
235
-                $start_time[1],
236
-                $timezone_string
237
-            )
238
-        );
239
-        $blank_datetime->set_end_time(
240
-            $this->convert_datetime_for_query(
241
-                'DTT_EVT_end',
242
-                $end_time[0],
243
-                $end_time[1],
244
-                $timezone_string
245
-            )
246
-        );
247
-        return [$blank_datetime];
248
-    }
249
-
250
-
251
-    /**
252
-     * Validates whether the start_time and end_time are in the expected format.
253
-     *
254
-     * @param array $start_time
255
-     * @param array $end_time
256
-     * @throws InvalidArgumentException
257
-     * @throws InvalidDataTypeException
258
-     */
259
-    private function validateStartAndEndTimeForBlankDate(array $start_time, array $end_time)
260
-    {
261
-        if (! is_array($start_time)) {
262
-            throw new InvalidDataTypeException('start_time', $start_time, 'array');
263
-        }
264
-        if (! is_array($end_time)) {
265
-            throw new InvalidDataTypeException('end_time', $end_time, 'array');
266
-        }
267
-        if (count($start_time) !== 2) {
268
-            throw new InvalidArgumentException(
269
-                sprintf(
270
-                    'The variable %1$s is expected to be an array with two elements.  The first item in the '
271
-                    . 'array should be a valid time string, the second item in the array should be a valid time format',
272
-                    '$start_time'
273
-                )
274
-            );
275
-        }
276
-        if (count($end_time) !== 2) {
277
-            throw new InvalidArgumentException(
278
-                sprintf(
279
-                    'The variable %1$s is expected to be an array with two elements.  The first item in the '
280
-                    . 'array should be a valid time string, the second item in the array should be a valid time format',
281
-                    '$end_time'
282
-                )
283
-            );
284
-        }
285
-    }
286
-
287
-
288
-    /**
289
-     * get event start date from db
290
-     *
291
-     * @access public
292
-     * @param int $EVT_ID
293
-     * @return EE_Datetime[] array on success, FALSE on fail
294
-     * @throws EE_Error
295
-     * @throws ReflectionException
296
-     */
297
-    public function get_all_event_dates($EVT_ID = 0)
298
-    {
299
-        if (! $EVT_ID) { // on add_new_event event_id gets set to 0
300
-            return $this->create_new_blank_datetime();
301
-        }
302
-        $results = $this->get_datetimes_for_event_ordered_by_DTT_order($EVT_ID);
303
-        if (empty($results)) {
304
-            return $this->create_new_blank_datetime();
305
-        }
306
-        return $results;
307
-    }
308
-
309
-
310
-    /**
311
-     * get all datetimes attached to an event ordered by the DTT_order field
312
-     *
313
-     * @public
314
-     * @param int     $EVT_ID     event id
315
-     * @param boolean $include_expired
316
-     * @param boolean $include_deleted
317
-     * @param int     $limit      If included then limit the count of results by
318
-     *                            the given number
319
-     * @return EE_Datetime[]
320
-     * @throws EE_Error
321
-     */
322
-    public function get_datetimes_for_event_ordered_by_DTT_order(
323
-        int $EVT_ID,
324
-        bool $include_expired = true,
325
-        bool $include_deleted = true,
326
-        $limit = 0
327
-    ) {
328
-        $prev_data_prep_value = $this->prepModelForQuery();
329
-        $where_params         = ['Event.EVT_ID' => absint($EVT_ID)];
330
-        $query_params[0]      = $this->addDefaultWhereParams($where_params, $include_deleted, $include_expired);
331
-        $query_params         = $this->addDefaultWhereConditions($query_params);
332
-        $query_params         = $this->addDefaultQueryParams($query_params, $limit, 'DTT_order');
333
-        return $this->getDatetimesAndRestoreModel($query_params, $prev_data_prep_value);
334
-    }
335
-
336
-
337
-    /**
338
-     * Gets the datetimes for the event (with the given limit), and orders them by "importance".
339
-     * By importance, we mean that the primary datetimes are most important (DEPRECATED FOR NOW),
340
-     * and then the earlier datetimes are the most important.
341
-     * Maybe we'll want this to take into account datetimes that haven't already passed, but we don't yet.
342
-     *
343
-     * @param int $EVT_ID
344
-     * @param int $limit
345
-     * @return EE_Datetime[]|EE_Base_Class[]
346
-     * @throws EE_Error
347
-     */
348
-    public function get_datetimes_for_event_ordered_by_importance(int $EVT_ID, $limit = 0)
349
-    {
350
-        $query_params[0] = ['Event.EVT_ID' => absint($EVT_ID)];
351
-        $query_params    = $this->addDefaultWhereConditions($query_params);
352
-        $query_params    = $this->addDefaultQueryParams($query_params, $limit);
353
-        return $this->get_all($query_params);
354
-    }
355
-
356
-
357
-    /**
358
-     * @param int     $EVT_ID
359
-     * @param boolean $include_expired
360
-     * @param boolean $include_deleted
361
-     * @return EE_Datetime
362
-     * @throws EE_Error
363
-     */
364
-    public function get_oldest_datetime_for_event(
365
-        int $EVT_ID,
366
-        bool $include_expired = false,
367
-        bool $include_deleted = false
368
-    ) {
369
-        $results = $this->get_datetimes_for_event_ordered_by_start_time(
370
-            $EVT_ID,
371
-            $include_expired,
372
-            $include_deleted,
373
-            1
374
-        );
375
-        if ($results) {
376
-            return array_shift($results);
377
-        }
378
-        return null;
379
-    }
380
-
381
-
382
-    /**
383
-     * Gets the 'primary' datetime for an event.
384
-     *
385
-     * @param int  $EVT_ID
386
-     * @param bool $try_to_exclude_expired
387
-     * @param bool $try_to_exclude_deleted
388
-     * @return EE_Datetime
389
-     * @throws EE_Error
390
-     */
391
-    public function get_primary_datetime_for_event(
392
-        int $EVT_ID,
393
-        bool $try_to_exclude_expired = true,
394
-        bool $try_to_exclude_deleted = true
395
-    ) {
396
-        if ($try_to_exclude_expired) {
397
-            $non_expired = $this->get_oldest_datetime_for_event($EVT_ID, false, false);
398
-            if ($non_expired) {
399
-                return $non_expired;
400
-            }
401
-        }
402
-        if ($try_to_exclude_deleted) {
403
-            $expired_even = $this->get_oldest_datetime_for_event($EVT_ID, true);
404
-            if ($expired_even) {
405
-                return $expired_even;
406
-            }
407
-        }
408
-        return $this->get_oldest_datetime_for_event($EVT_ID, true, true);
409
-    }
410
-
411
-
412
-    /**
413
-     * Gets ALL the datetimes for an event (including trashed ones, for now), ordered
414
-     * only by start date
415
-     *
416
-     * @param int     $EVT_ID
417
-     * @param boolean $include_expired
418
-     * @param boolean $include_deleted
419
-     * @param int     $limit
420
-     * @return EE_Datetime[]
421
-     * @throws EE_Error
422
-     */
423
-    public function get_datetimes_for_event_ordered_by_start_time(
424
-        int $EVT_ID,
425
-        bool $include_expired = true,
426
-        bool $include_deleted = true,
427
-        $limit = 0
428
-    ) {
429
-        $prev_data_prep_value = $this->prepModelForQuery();
430
-        $where_params         = ['Event.EVT_ID' => absint($EVT_ID)];
431
-        $query_params[0]      = $this->addDefaultWhereParams($where_params, $include_deleted, $include_expired);
432
-        $query_params         = $this->addDefaultWhereConditions(
433
-            $query_params,
434
-            EEM_Base::default_where_conditions_this_only
435
-        );
436
-        $query_params         = $this->addDefaultQueryParams($query_params, $limit, 'DTT_order');
437
-        return $this->getDatetimesAndRestoreModel($query_params, $prev_data_prep_value);
438
-    }
439
-
440
-
441
-    /**
442
-     * Gets ALL the datetimes for an ticket (including trashed ones, for now), ordered
443
-     * only by start date
444
-     *
445
-     * @param int     $TKT_ID
446
-     * @param boolean $include_expired
447
-     * @param boolean $include_deleted
448
-     * @param int     $limit
449
-     * @return EE_Datetime[]
450
-     * @throws EE_Error
451
-     */
452
-    public function get_datetimes_for_ticket_ordered_by_start_time(
453
-        int $TKT_ID,
454
-        bool $include_expired = true,
455
-        bool $include_deleted = true,
456
-        $limit = 0
457
-    ) {
458
-        $prev_data_prep_value = $this->prepModelForQuery();
459
-        $where_params         = ['Ticket.TKT_ID' => absint($TKT_ID)];
460
-        $query_params[0]      = $this->addDefaultWhereParams($where_params, $include_deleted, $include_expired);
461
-        $query_params         = $this->addDefaultQueryParams($query_params, $limit);
462
-        return $this->getDatetimesAndRestoreModel($query_params, $prev_data_prep_value);
463
-    }
464
-
465
-
466
-    /**
467
-     * Gets all the datetimes for a ticket (including trashed ones, for now), ordered by the DTT_order for the
468
-     * datetimes.
469
-     *
470
-     * @param int      $TKT_ID           ID of ticket to retrieve the datetimes for
471
-     * @param boolean  $include_expired  whether to include expired datetimes or not
472
-     * @param boolean  $include_deleted  whether to include trashed datetimes or not.
473
-     * @param int|null $limit            if null, no limit, if int then limit results by
474
-     *                                   that number
475
-     * @return EE_Datetime[]
476
-     * @throws EE_Error
477
-     */
478
-    public function get_datetimes_for_ticket_ordered_by_DTT_order(
479
-        int $TKT_ID,
480
-        bool $include_expired = true,
481
-        bool $include_deleted = true,
482
-        $limit = 0
483
-    ) {
484
-        $prev_data_prep_value = $this->prepModelForQuery();
485
-        $where_params         = ['Ticket.TKT_ID' => absint($TKT_ID)];
486
-        $query_params[0]      = $this->addDefaultWhereParams($where_params, $include_deleted, $include_expired);
487
-        $query_params         = $this->addDefaultQueryParams($query_params, $limit, 'DTT_order');
488
-        return $this->getDatetimesAndRestoreModel($query_params, $prev_data_prep_value);
489
-    }
490
-
491
-
492
-    /**
493
-     * Gets the most important datetime for a particular event (ie, the primary event usually. But if for some WACK
494
-     * reason it doesn't exist, we consider the earliest event the most important)
495
-     *
496
-     * @param int $EVT_ID
497
-     * @return EE_Datetime
498
-     * @throws EE_Error
499
-     */
500
-    public function get_most_important_datetime_for_event(int $EVT_ID)
501
-    {
502
-        $results = $this->get_datetimes_for_event_ordered_by_importance($EVT_ID, 1);
503
-        if ($results) {
504
-            return array_shift($results);
505
-        }
506
-        return null;
507
-    }
508
-
509
-
510
-    /**
511
-     * This returns a wpdb->results        Array of all DTT month and years matching the incoming query params and
512
-     * grouped by month and year.
513
-     *
514
-     * @param array  $where_params       @see
515
-     *                                   https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md#0-where-conditions
516
-     * @param string $evt_active_status  A string representing the evt active status to filter the months by.
517
-     *                                   Can be:
518
-     *                                   - '' = no filter
519
-     *                                   - upcoming = Published events with at least one upcoming datetime.
520
-     *                                   - expired = Events with all datetimes expired.
521
-     *                                   - active = Events that are published and have at least one datetime that
522
-     *                                   starts before now and ends after now.
523
-     *                                   - inactive = Events that are either not published.
524
-     * @return stdClass[]
525
-     * @throws EE_Error
526
-     * @throws InvalidArgumentException
527
-     * @throws InvalidArgumentException
528
-     */
529
-    public function get_dtt_months_and_years(array $where_params, $evt_active_status = '')
530
-    {
531
-        $current_time_for_DTT_EVT_start = $this->current_time_for_query('DTT_EVT_start');
532
-        $current_time_for_DTT_EVT_end   = $this->current_time_for_query('DTT_EVT_end');
533
-        switch ($evt_active_status) {
534
-            case 'upcoming':
535
-                $where_params['Event.status'] = 'publish';
536
-                // if there are already query_params matching DTT_EVT_start then we need to modify that to add them.
537
-                if (isset($where_params['DTT_EVT_start'])) {
538
-                    $where_params['DTT_EVT_start*****'] = $where_params['DTT_EVT_start'];
539
-                }
540
-                $where_params['DTT_EVT_start'] = ['>', $current_time_for_DTT_EVT_start];
541
-                break;
542
-            case 'expired':
543
-                if (isset($where_params['Event.status'])) {
544
-                    unset($where_params['Event.status']);
545
-                }
546
-                // get events to exclude
547
-                $exclude_query[0] = array_merge(
548
-                    $where_params,
549
-                    ['DTT_EVT_end' => ['>', $current_time_for_DTT_EVT_end]]
550
-                );
551
-                // first get all events that have datetimes where its not expired.
552
-                $event_ids = $this->_get_all_wpdb_results(
553
-                    $exclude_query,
554
-                    OBJECT_K,
555
-                    'Datetime.EVT_ID'
556
-                );
557
-                $event_ids = array_keys($event_ids);
558
-                if (isset($where_params['DTT_EVT_end'])) {
559
-                    $where_params['DTT_EVT_end****'] = $where_params['DTT_EVT_end'];
560
-                }
561
-                $where_params['DTT_EVT_end']  = ['<', $current_time_for_DTT_EVT_end];
562
-                $where_params['Event.EVT_ID'] = ['NOT IN', $event_ids];
563
-                break;
564
-            case 'active':
565
-                $where_params['Event.status'] = 'publish';
566
-                if (isset($where_params['DTT_EVT_start'])) {
567
-                    $where_params['Datetime.DTT_EVT_start******'] = $where_params['DTT_EVT_start'];
568
-                }
569
-                if (isset($where_params['Datetime.DTT_EVT_end'])) {
570
-                    $where_params['Datetime.DTT_EVT_end*****'] = $where_params['DTT_EVT_end'];
571
-                }
572
-                $where_params['DTT_EVT_start'] = ['<', $current_time_for_DTT_EVT_start];
573
-                $where_params['DTT_EVT_end']   = ['>', $current_time_for_DTT_EVT_end];
574
-                break;
575
-            case 'inactive':
576
-                if (isset($where_params['Event.status'])) {
577
-                    unset($where_params['Event.status']);
578
-                }
579
-                if (isset($where_params['OR'])) {
580
-                    $where_params['AND']['OR'] = $where_params['OR'];
581
-                }
582
-                if (isset($where_params['DTT_EVT_end'])) {
583
-                    $where_params['AND']['DTT_EVT_end****'] = $where_params['DTT_EVT_end'];
584
-                    unset($where_params['DTT_EVT_end']);
585
-                }
586
-                if (isset($where_params['DTT_EVT_start'])) {
587
-                    $where_params['AND']['DTT_EVT_start'] = $where_params['DTT_EVT_start'];
588
-                    unset($where_params['DTT_EVT_start']);
589
-                }
590
-                $where_params['AND']['Event.status'] = ['!=', 'publish'];
591
-                break;
592
-        }
593
-        $query_params[0]          = $where_params;
594
-        $query_params['group_by'] = ['dtt_year', 'dtt_month'];
595
-        $query_params             = $this->addOrderByQueryParams($query_params, 'DTT_EVT_start', 'DESC');
596
-
597
-        $query_interval    = EEH_DTT_Helper::get_sql_query_interval_for_offset(
598
-            $this->get_timezone(),
599
-            'DTT_EVT_start'
600
-        );
601
-        $columns_to_select = [
602
-            'dtt_year'      => ['YEAR(' . $query_interval . ')', '%s'],
603
-            'dtt_month'     => ['MONTHNAME(' . $query_interval . ')', '%s'],
604
-            'dtt_month_num' => ['MONTH(' . $query_interval . ')', '%s'],
605
-        ];
606
-        return $this->_get_all_wpdb_results($query_params, OBJECT, $columns_to_select);
607
-    }
608
-
609
-
610
-    /**
611
-     * Updates the DTT_sold attribute on each datetime (based on the registrations
612
-     * for the tickets for each datetime)
613
-     *
614
-     * @param EE_Base_Class[]|EE_Datetime[] $datetimes
615
-     * @throws EE_Error
616
-     * @throws ReflectionException
617
-     */
618
-    public function update_sold(array $datetimes)
619
-    {
620
-        EE_Error::doing_it_wrong(
621
-            __FUNCTION__,
622
-            esc_html__(
623
-                'Please use \EEM_Ticket::update_tickets_sold() instead which will in turn correctly update both the Ticket AND Datetime counts.',
624
-                'event_espresso'
625
-            ),
626
-            '4.9.32.rc.005'
627
-        );
628
-        foreach ($datetimes as $datetime) {
629
-            $datetime->update_sold();
630
-        }
631
-    }
632
-
633
-
634
-    /**
635
-     *    Gets the total number of tickets available at a particular datetime
636
-     *    (does NOT take into account the datetime's spaces available)
637
-     *
638
-     * @param int   $DTT_ID
639
-     * @param array $query_params
640
-     * @return int of tickets available. If sold out, return less than 1. If infinite, returns EE_INF,  IF there are NO
641
-     *             tickets attached to datetime then FALSE is returned.
642
-     * @throws EE_Error
643
-     * @throws ReflectionException
644
-     */
645
-    public function sum_tickets_currently_available_at_datetime(int $DTT_ID, array $query_params = [])
646
-    {
647
-        $datetime = $this->get_one_by_ID($DTT_ID);
648
-        if ($datetime instanceof EE_Datetime) {
649
-            return $datetime->tickets_remaining($query_params);
650
-        }
651
-        return 0;
652
-    }
653
-
654
-
655
-    /**
656
-     * This returns an array of counts of datetimes in the database for each Datetime status that can be queried.
657
-     *
658
-     * @param array $stati_to_include  If included you can restrict the statuses we return counts for by including the
659
-     *                                 stati you want counts for as values in the array.  An empty array returns counts
660
-     *                                 for all valid stati.
661
-     * @param array $query_params      If included can be used to refine the conditions for returning the count (i.e.
662
-     *                                 only for Datetimes connected to a specific event, or specific ticket.
663
-     * @return array  The value returned is an array indexed by Datetime Status and the values are the counts.  The
664
-     * @throws EE_Error
665
-     *                                 stati used as index keys are: EE_Datetime::active EE_Datetime::upcoming
666
-     *                                 EE_Datetime::expired
667
-     */
668
-    public function get_datetime_counts_by_status(array $stati_to_include = [], array $query_params = [])
669
-    {
670
-        // only accept where conditions for this query.
671
-        $_where            = isset($query_params[0]) ? $query_params[0] : [];
672
-        $status_query_args = [
673
-            EE_Datetime::active   => array_merge(
674
-                $_where,
675
-                ['DTT_EVT_start' => ['<', time()], 'DTT_EVT_end' => ['>', time()]]
676
-            ),
677
-            EE_Datetime::upcoming => array_merge(
678
-                $_where,
679
-                ['DTT_EVT_start' => ['>', time()]]
680
-            ),
681
-            EE_Datetime::expired  => array_merge(
682
-                $_where,
683
-                ['DTT_EVT_end' => ['<', time()]]
684
-            ),
685
-        ];
686
-        if (! empty($stati_to_include)) {
687
-            foreach (array_keys($status_query_args) as $status) {
688
-                if (! in_array($status, $stati_to_include, true)) {
689
-                    unset($status_query_args[ $status ]);
690
-                }
691
-            }
692
-        }
693
-        // loop through and query counts for each stati.
694
-        $status_query_results = [];
695
-        foreach ($status_query_args as $status => $status_where_conditions) {
696
-            $status_query_results[ $status ] = EEM_Datetime::count(
697
-                [$status_where_conditions],
698
-                'DTT_ID',
699
-                true
700
-            );
701
-        }
702
-        return $status_query_results;
703
-    }
704
-
705
-
706
-    /**
707
-     * Returns the specific count for a given Datetime status matching any given query_params.
708
-     *
709
-     * @param string $status Valid string representation for Datetime status requested. (Defaults to Active).
710
-     * @param array  $query_params
711
-     * @return int
712
-     * @throws EE_Error
713
-     */
714
-    public function get_datetime_count_for_status($status = EE_Datetime::active, array $query_params = [])
715
-    {
716
-        $count = $this->get_datetime_counts_by_status([$status], $query_params);
717
-        return ! empty($count[ $status ]) ? $count[ $status ] : 0;
718
-    }
719
-
720
-
721
-    /**
722
-     * @return bool|int
723
-     * @since   $VID:$
724
-     */
725
-    private function prepModelForQuery()
726
-    {
727
-        $prev_data_prep_value = $this->get_assumption_concerning_values_already_prepared_by_model_object();
728
-        $this->assume_values_already_prepared_by_model_object(EEM_Base::prepared_for_use_in_db);
729
-        return $prev_data_prep_value;
730
-    }
731
-
732
-
733
-    /**
734
-     * @param array    $query_params
735
-     * @param bool|int $prev_data_prep_value
736
-     * @return EE_Base_Class[]|EE_Datetime[]
737
-     * @throws EE_Error
738
-     * @since   $VID:$
739
-     */
740
-    private function getDatetimesAndRestoreModel(array $query_params, $prev_data_prep_value)
741
-    {
742
-        $result = $this->get_all($query_params);
743
-        $this->assume_values_already_prepared_by_model_object($prev_data_prep_value);
744
-        return $result;
745
-    }
746
-
747
-
748
-    /**
749
-     * @param array  $query_params
750
-     * @param int    $limit
751
-     * @param string $order_by
752
-     * @param string $order
753
-     * @return array
754
-     * @since   $VID:$
755
-     */
756
-    private function addDefaultQueryParams(array $query_params, $limit = 0, $order_by = 'DTT_EVT_start', $order = 'ASC')
757
-    {
758
-        $query_params = $this->addOrderByQueryParams($query_params, $order_by, $order);
759
-        $query_params = $this->addLimitQueryParams($query_params, $limit);
760
-        return $query_params;
761
-    }
762
-
763
-
764
-    /**
765
-     * @param array  $query_params
766
-     * @param string $default_where_conditions
767
-     * @return array
768
-     * @since   $VID:$
769
-     */
770
-    private function addDefaultWhereConditions(
771
-        array $query_params,
772
-        $default_where_conditions = EEM_Base::default_where_conditions_none
773
-    ) {
774
-        $query_params['default_where_conditions'] = $default_where_conditions;
775
-        return $query_params;
776
-    }
777
-
778
-
779
-    /**
780
-     * @param array $where_params
781
-     * @param bool  $include_deleted
782
-     * @param bool  $include_expired
783
-     * @return array
784
-     * @since   $VID:$
785
-     */
786
-    private function addDefaultWhereParams(array $where_params, bool $include_deleted = true, bool $include_expired = true)
787
-    {
788
-        $where_params = $this->addExpiredWhereParams($where_params, $include_expired);
789
-        $where_params = $this->addDeletedWhereParams($where_params, $include_deleted);
790
-        return $where_params;
791
-    }
792
-
793
-
794
-    /**
795
-     * @param array $where_params
796
-     * @param bool  $include_deleted
797
-     * @return array
798
-     * @since   $VID:$
799
-     */
800
-    private function addDeletedWhereParams(array $where_params, bool $include_deleted = true)
801
-    {
802
-        $deleted                     = $include_deleted ? [true, false] : [false];
803
-        $where_params['DTT_deleted'] = ['IN', $deleted];
804
-        return $where_params;
805
-    }
806
-
807
-
808
-    /**
809
-     * @param array $where_params
810
-     * @param bool  $include_expired
811
-     * @return array
812
-     * @since   $VID:$
813
-     */
814
-    private function addExpiredWhereParams(array $where_params, bool $include_expired = true)
815
-    {
816
-        if (! $include_expired) {
817
-            $where_params['DTT_EVT_end'] = ['>=', current_time('mysql', true)];
818
-        }
819
-        return $where_params;
820
-    }
821
-
822
-
823
-    /**
824
-     * @param array $query_params
825
-     * @param int   $limit
826
-     * @return array
827
-     * @since   $VID:$
828
-     */
829
-    private function addLimitQueryParams(array $query_params, $limit = 0)
830
-    {
831
-        if ($limit) {
832
-            $query_params['limit'] = $limit;
833
-        }
834
-        return $query_params;
835
-    }
836
-
837
-
838
-    /**
839
-     * @param array  $query_params
840
-     * @param string $order_by
841
-     * @param string $order
842
-     * @return array
843
-     * @since   $VID:$
844
-     */
845
-    private function addOrderByQueryParams(array $query_params, $order_by = 'DTT_EVT_start', $order = 'ASC')
846
-    {
847
-        $order                    = $order === 'ASC' ? 'ASC' : 'DESC';
848
-        $valid_order_columns      = ['DTT_ID', 'DTT_EVT_start', 'DTT_EVT_end', 'DTT_order'];
849
-        $order_by                 = in_array($order_by, $valid_order_columns, true) ? $order_by : 'DTT_EVT_start';
850
-        $query_params['order_by'] = [$order_by => $order];
851
-        return $query_params;
852
-    }
15
+	/**
16
+	 * @var EEM_Datetime $_instance
17
+	 */
18
+	protected static $_instance;
19
+
20
+
21
+	/**
22
+	 * private constructor to prevent direct creation
23
+	 *
24
+	 * @param string $timezone A string representing the timezone we want to set for returned Date Time Strings
25
+	 *                         (and any incoming timezone data that gets saved).
26
+	 *                         Note this just sends the timezone info to the date time model field objects.
27
+	 *                         Default is NULL
28
+	 *                         (and will be assumed using the set timezone in the 'timezone_string' wp option)
29
+	 * @throws EE_Error
30
+	 * @throws InvalidArgumentException
31
+	 * @throws InvalidArgumentException
32
+	 */
33
+	protected function __construct($timezone)
34
+	{
35
+		$this->singular_item           = esc_html__('Datetime', 'event_espresso');
36
+		$this->plural_item             = esc_html__('Datetimes', 'event_espresso');
37
+		$this->_tables                 = [
38
+			'Datetime' => new EE_Primary_Table('esp_datetime', 'DTT_ID'),
39
+		];
40
+		$this->_fields                 = [
41
+			'Datetime' => [
42
+				'DTT_ID'          => new EE_Primary_Key_Int_Field(
43
+					'DTT_ID',
44
+					esc_html__('Datetime ID', 'event_espresso')
45
+				),
46
+				'EVT_ID'          => new EE_Foreign_Key_Int_Field(
47
+					'EVT_ID',
48
+					esc_html__('Event ID', 'event_espresso'),
49
+					false,
50
+					0,
51
+					'Event'
52
+				),
53
+				'VNU_ID' => new EE_Foreign_Key_Int_Field(
54
+					'VNU_ID',
55
+					__('Venue ID', 'event_espresso'),
56
+					false,
57
+					0,
58
+					'Venue'
59
+				),
60
+				'DTT_name'        => new EE_Plain_Text_Field(
61
+					'DTT_name',
62
+					esc_html__('Datetime Name', 'event_espresso'),
63
+					false,
64
+					''
65
+				),
66
+				'DTT_description' => new EE_Post_Content_Field(
67
+					'DTT_description',
68
+					esc_html__('Description for Datetime', 'event_espresso'),
69
+					false,
70
+					''
71
+				),
72
+				'DTT_EVT_start'   => new EE_Datetime_Field(
73
+					'DTT_EVT_start',
74
+					esc_html__('Start time/date of Event', 'event_espresso'),
75
+					false,
76
+					EE_Datetime_Field::now,
77
+					$timezone
78
+				),
79
+				'DTT_EVT_end'     => new EE_Datetime_Field(
80
+					'DTT_EVT_end',
81
+					esc_html__('End time/date of Event', 'event_espresso'),
82
+					false,
83
+					EE_Datetime_Field::now,
84
+					$timezone
85
+				),
86
+				'DTT_reg_limit'   => new EE_Infinite_Integer_Field(
87
+					'DTT_reg_limit',
88
+					esc_html__('Registration Limit for this time', 'event_espresso'),
89
+					true,
90
+					EE_INF
91
+				),
92
+				'DTT_sold'        => new EE_Integer_Field(
93
+					'DTT_sold',
94
+					esc_html__('How many sales for this Datetime that have occurred', 'event_espresso'),
95
+					true,
96
+					0
97
+				),
98
+				'DTT_reserved'    => new EE_Integer_Field(
99
+					'DTT_reserved',
100
+					esc_html__('Quantity of tickets reserved, but not yet fully purchased', 'event_espresso'),
101
+					false,
102
+					0
103
+				),
104
+				'DTT_is_primary'  => new EE_Boolean_Field(
105
+					'DTT_is_primary',
106
+					esc_html__('Flag indicating datetime is primary one for event', 'event_espresso'),
107
+					false,
108
+					false
109
+				),
110
+				'DTT_order'       => new EE_Integer_Field(
111
+					'DTT_order',
112
+					esc_html__('The order in which the Datetime is displayed', 'event_espresso'),
113
+					false,
114
+					0
115
+				),
116
+				'DTT_parent'      => new EE_Integer_Field(
117
+					'DTT_parent',
118
+					esc_html__('Indicates what DTT_ID is the parent of this DTT_ID', 'event_espresso'),
119
+					true,
120
+					0
121
+				),
122
+				'DTT_deleted'     => new EE_Trashed_Flag_Field(
123
+					'DTT_deleted',
124
+					esc_html__('Flag indicating datetime is archived', 'event_espresso'),
125
+					false,
126
+					false
127
+				),
128
+			],
129
+		];
130
+		$this->_model_relations        = [
131
+			'Ticket'          => new EE_HABTM_Relation('Datetime_Ticket'),
132
+			'Event'           => new EE_Belongs_To_Relation(),
133
+			'Checkin'         => new EE_Has_Many_Relation(),
134
+			'Datetime_Ticket' => new EE_Has_Many_Relation(),
135
+			'Venue'           => new EE_Belongs_To_Relation(),
136
+		];
137
+		$path_to_event_model           = 'Event';
138
+		$this->model_chain_to_password = $path_to_event_model;
139
+		$this->_model_chain_to_wp_user = $path_to_event_model;
140
+		// this model is generally available for reading
141
+		$this->_cap_restriction_generators[ EEM_Base::caps_read ]       =
142
+			new EE_Restriction_Generator_Event_Related_Public(
143
+				$path_to_event_model
144
+			);
145
+		$this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] =
146
+			new EE_Restriction_Generator_Event_Related_Protected(
147
+				$path_to_event_model
148
+			);
149
+		$this->_cap_restriction_generators[ EEM_Base::caps_edit ]       =
150
+			new EE_Restriction_Generator_Event_Related_Protected(
151
+				$path_to_event_model
152
+			);
153
+		$this->_cap_restriction_generators[ EEM_Base::caps_delete ]     =
154
+			new EE_Restriction_Generator_Event_Related_Protected(
155
+				$path_to_event_model,
156
+				EEM_Base::caps_edit
157
+			);
158
+		parent::__construct($timezone);
159
+	}
160
+
161
+
162
+	/**
163
+	 * create new blank datetime
164
+	 *
165
+	 * @access public
166
+	 * @return EE_Datetime[] array on success, FALSE on fail
167
+	 * @throws EE_Error
168
+	 * @throws InvalidArgumentException
169
+	 * @throws InvalidDataTypeException
170
+	 * @throws ReflectionException
171
+	 * @throws InvalidInterfaceException
172
+	 */
173
+	public function create_new_blank_datetime()
174
+	{
175
+		// makes sure timezone is always set.
176
+		$timezone_string = $this->get_timezone();
177
+		/**
178
+		 * Filters the initial start date for the new datetime.
179
+		 * Any time included in this value will be overridden later so use additional filters to modify the time.
180
+		 *
181
+		 * @param int $start_date Unix timestamp representing now + 30 days in seconds.
182
+		 * @return int Unix timestamp
183
+		 */
184
+		$start_date = apply_filters(
185
+			'FHEE__EEM_Datetime__create_new_blank_datetime__start_date',
186
+			$this->current_time_for_query('DTT_EVT_start', true) + MONTH_IN_SECONDS
187
+		);
188
+		/**
189
+		 * Filters the initial end date for the new datetime.
190
+		 * Any time included in this value will be overridden later so use additional filters to modify the time.
191
+		 *
192
+		 * @param int $end_data Unix timestamp representing now + 30 days in seconds.
193
+		 * @return int Unix timestamp
194
+		 */
195
+		$end_date       = apply_filters(
196
+			'FHEE__EEM_Datetime__create_new_blank_datetime__end_date',
197
+			$this->current_time_for_query('DTT_EVT_end', true) + MONTH_IN_SECONDS
198
+		);
199
+		$blank_datetime = EE_Datetime::new_instance(
200
+			[
201
+				'DTT_EVT_start' => $start_date,
202
+				'DTT_EVT_end'   => $end_date,
203
+				'DTT_order'     => 1,
204
+				'DTT_reg_limit' => EE_INF,
205
+			],
206
+			$timezone_string
207
+		);
208
+		/**
209
+		 * Filters the initial start time and format for the new EE_Datetime instance.
210
+		 *
211
+		 * @param array $start_time An array having size 2.  First element is the time, second element is the time
212
+		 *                          format.
213
+		 * @return array
214
+		 */
215
+		$start_time = apply_filters(
216
+			'FHEE__EEM_Datetime__create_new_blank_datetime__start_time',
217
+			['8am', 'ga']
218
+		);
219
+		/**
220
+		 * Filters the initial end time and format for the new EE_Datetime instance.
221
+		 *
222
+		 * @param array $end_time An array having size 2.  First element is the time, second element is the time
223
+		 *                        format
224
+		 * @return array
225
+		 */
226
+		$end_time = apply_filters(
227
+			'FHEE__EEM_Datetime__create_new_blank_datetime__end_time',
228
+			['5pm', 'ga']
229
+		);
230
+		$this->validateStartAndEndTimeForBlankDate($start_time, $end_time);
231
+		$blank_datetime->set_start_time(
232
+			$this->convert_datetime_for_query(
233
+				'DTT_EVT_start',
234
+				$start_time[0],
235
+				$start_time[1],
236
+				$timezone_string
237
+			)
238
+		);
239
+		$blank_datetime->set_end_time(
240
+			$this->convert_datetime_for_query(
241
+				'DTT_EVT_end',
242
+				$end_time[0],
243
+				$end_time[1],
244
+				$timezone_string
245
+			)
246
+		);
247
+		return [$blank_datetime];
248
+	}
249
+
250
+
251
+	/**
252
+	 * Validates whether the start_time and end_time are in the expected format.
253
+	 *
254
+	 * @param array $start_time
255
+	 * @param array $end_time
256
+	 * @throws InvalidArgumentException
257
+	 * @throws InvalidDataTypeException
258
+	 */
259
+	private function validateStartAndEndTimeForBlankDate(array $start_time, array $end_time)
260
+	{
261
+		if (! is_array($start_time)) {
262
+			throw new InvalidDataTypeException('start_time', $start_time, 'array');
263
+		}
264
+		if (! is_array($end_time)) {
265
+			throw new InvalidDataTypeException('end_time', $end_time, 'array');
266
+		}
267
+		if (count($start_time) !== 2) {
268
+			throw new InvalidArgumentException(
269
+				sprintf(
270
+					'The variable %1$s is expected to be an array with two elements.  The first item in the '
271
+					. 'array should be a valid time string, the second item in the array should be a valid time format',
272
+					'$start_time'
273
+				)
274
+			);
275
+		}
276
+		if (count($end_time) !== 2) {
277
+			throw new InvalidArgumentException(
278
+				sprintf(
279
+					'The variable %1$s is expected to be an array with two elements.  The first item in the '
280
+					. 'array should be a valid time string, the second item in the array should be a valid time format',
281
+					'$end_time'
282
+				)
283
+			);
284
+		}
285
+	}
286
+
287
+
288
+	/**
289
+	 * get event start date from db
290
+	 *
291
+	 * @access public
292
+	 * @param int $EVT_ID
293
+	 * @return EE_Datetime[] array on success, FALSE on fail
294
+	 * @throws EE_Error
295
+	 * @throws ReflectionException
296
+	 */
297
+	public function get_all_event_dates($EVT_ID = 0)
298
+	{
299
+		if (! $EVT_ID) { // on add_new_event event_id gets set to 0
300
+			return $this->create_new_blank_datetime();
301
+		}
302
+		$results = $this->get_datetimes_for_event_ordered_by_DTT_order($EVT_ID);
303
+		if (empty($results)) {
304
+			return $this->create_new_blank_datetime();
305
+		}
306
+		return $results;
307
+	}
308
+
309
+
310
+	/**
311
+	 * get all datetimes attached to an event ordered by the DTT_order field
312
+	 *
313
+	 * @public
314
+	 * @param int     $EVT_ID     event id
315
+	 * @param boolean $include_expired
316
+	 * @param boolean $include_deleted
317
+	 * @param int     $limit      If included then limit the count of results by
318
+	 *                            the given number
319
+	 * @return EE_Datetime[]
320
+	 * @throws EE_Error
321
+	 */
322
+	public function get_datetimes_for_event_ordered_by_DTT_order(
323
+		int $EVT_ID,
324
+		bool $include_expired = true,
325
+		bool $include_deleted = true,
326
+		$limit = 0
327
+	) {
328
+		$prev_data_prep_value = $this->prepModelForQuery();
329
+		$where_params         = ['Event.EVT_ID' => absint($EVT_ID)];
330
+		$query_params[0]      = $this->addDefaultWhereParams($where_params, $include_deleted, $include_expired);
331
+		$query_params         = $this->addDefaultWhereConditions($query_params);
332
+		$query_params         = $this->addDefaultQueryParams($query_params, $limit, 'DTT_order');
333
+		return $this->getDatetimesAndRestoreModel($query_params, $prev_data_prep_value);
334
+	}
335
+
336
+
337
+	/**
338
+	 * Gets the datetimes for the event (with the given limit), and orders them by "importance".
339
+	 * By importance, we mean that the primary datetimes are most important (DEPRECATED FOR NOW),
340
+	 * and then the earlier datetimes are the most important.
341
+	 * Maybe we'll want this to take into account datetimes that haven't already passed, but we don't yet.
342
+	 *
343
+	 * @param int $EVT_ID
344
+	 * @param int $limit
345
+	 * @return EE_Datetime[]|EE_Base_Class[]
346
+	 * @throws EE_Error
347
+	 */
348
+	public function get_datetimes_for_event_ordered_by_importance(int $EVT_ID, $limit = 0)
349
+	{
350
+		$query_params[0] = ['Event.EVT_ID' => absint($EVT_ID)];
351
+		$query_params    = $this->addDefaultWhereConditions($query_params);
352
+		$query_params    = $this->addDefaultQueryParams($query_params, $limit);
353
+		return $this->get_all($query_params);
354
+	}
355
+
356
+
357
+	/**
358
+	 * @param int     $EVT_ID
359
+	 * @param boolean $include_expired
360
+	 * @param boolean $include_deleted
361
+	 * @return EE_Datetime
362
+	 * @throws EE_Error
363
+	 */
364
+	public function get_oldest_datetime_for_event(
365
+		int $EVT_ID,
366
+		bool $include_expired = false,
367
+		bool $include_deleted = false
368
+	) {
369
+		$results = $this->get_datetimes_for_event_ordered_by_start_time(
370
+			$EVT_ID,
371
+			$include_expired,
372
+			$include_deleted,
373
+			1
374
+		);
375
+		if ($results) {
376
+			return array_shift($results);
377
+		}
378
+		return null;
379
+	}
380
+
381
+
382
+	/**
383
+	 * Gets the 'primary' datetime for an event.
384
+	 *
385
+	 * @param int  $EVT_ID
386
+	 * @param bool $try_to_exclude_expired
387
+	 * @param bool $try_to_exclude_deleted
388
+	 * @return EE_Datetime
389
+	 * @throws EE_Error
390
+	 */
391
+	public function get_primary_datetime_for_event(
392
+		int $EVT_ID,
393
+		bool $try_to_exclude_expired = true,
394
+		bool $try_to_exclude_deleted = true
395
+	) {
396
+		if ($try_to_exclude_expired) {
397
+			$non_expired = $this->get_oldest_datetime_for_event($EVT_ID, false, false);
398
+			if ($non_expired) {
399
+				return $non_expired;
400
+			}
401
+		}
402
+		if ($try_to_exclude_deleted) {
403
+			$expired_even = $this->get_oldest_datetime_for_event($EVT_ID, true);
404
+			if ($expired_even) {
405
+				return $expired_even;
406
+			}
407
+		}
408
+		return $this->get_oldest_datetime_for_event($EVT_ID, true, true);
409
+	}
410
+
411
+
412
+	/**
413
+	 * Gets ALL the datetimes for an event (including trashed ones, for now), ordered
414
+	 * only by start date
415
+	 *
416
+	 * @param int     $EVT_ID
417
+	 * @param boolean $include_expired
418
+	 * @param boolean $include_deleted
419
+	 * @param int     $limit
420
+	 * @return EE_Datetime[]
421
+	 * @throws EE_Error
422
+	 */
423
+	public function get_datetimes_for_event_ordered_by_start_time(
424
+		int $EVT_ID,
425
+		bool $include_expired = true,
426
+		bool $include_deleted = true,
427
+		$limit = 0
428
+	) {
429
+		$prev_data_prep_value = $this->prepModelForQuery();
430
+		$where_params         = ['Event.EVT_ID' => absint($EVT_ID)];
431
+		$query_params[0]      = $this->addDefaultWhereParams($where_params, $include_deleted, $include_expired);
432
+		$query_params         = $this->addDefaultWhereConditions(
433
+			$query_params,
434
+			EEM_Base::default_where_conditions_this_only
435
+		);
436
+		$query_params         = $this->addDefaultQueryParams($query_params, $limit, 'DTT_order');
437
+		return $this->getDatetimesAndRestoreModel($query_params, $prev_data_prep_value);
438
+	}
439
+
440
+
441
+	/**
442
+	 * Gets ALL the datetimes for an ticket (including trashed ones, for now), ordered
443
+	 * only by start date
444
+	 *
445
+	 * @param int     $TKT_ID
446
+	 * @param boolean $include_expired
447
+	 * @param boolean $include_deleted
448
+	 * @param int     $limit
449
+	 * @return EE_Datetime[]
450
+	 * @throws EE_Error
451
+	 */
452
+	public function get_datetimes_for_ticket_ordered_by_start_time(
453
+		int $TKT_ID,
454
+		bool $include_expired = true,
455
+		bool $include_deleted = true,
456
+		$limit = 0
457
+	) {
458
+		$prev_data_prep_value = $this->prepModelForQuery();
459
+		$where_params         = ['Ticket.TKT_ID' => absint($TKT_ID)];
460
+		$query_params[0]      = $this->addDefaultWhereParams($where_params, $include_deleted, $include_expired);
461
+		$query_params         = $this->addDefaultQueryParams($query_params, $limit);
462
+		return $this->getDatetimesAndRestoreModel($query_params, $prev_data_prep_value);
463
+	}
464
+
465
+
466
+	/**
467
+	 * Gets all the datetimes for a ticket (including trashed ones, for now), ordered by the DTT_order for the
468
+	 * datetimes.
469
+	 *
470
+	 * @param int      $TKT_ID           ID of ticket to retrieve the datetimes for
471
+	 * @param boolean  $include_expired  whether to include expired datetimes or not
472
+	 * @param boolean  $include_deleted  whether to include trashed datetimes or not.
473
+	 * @param int|null $limit            if null, no limit, if int then limit results by
474
+	 *                                   that number
475
+	 * @return EE_Datetime[]
476
+	 * @throws EE_Error
477
+	 */
478
+	public function get_datetimes_for_ticket_ordered_by_DTT_order(
479
+		int $TKT_ID,
480
+		bool $include_expired = true,
481
+		bool $include_deleted = true,
482
+		$limit = 0
483
+	) {
484
+		$prev_data_prep_value = $this->prepModelForQuery();
485
+		$where_params         = ['Ticket.TKT_ID' => absint($TKT_ID)];
486
+		$query_params[0]      = $this->addDefaultWhereParams($where_params, $include_deleted, $include_expired);
487
+		$query_params         = $this->addDefaultQueryParams($query_params, $limit, 'DTT_order');
488
+		return $this->getDatetimesAndRestoreModel($query_params, $prev_data_prep_value);
489
+	}
490
+
491
+
492
+	/**
493
+	 * Gets the most important datetime for a particular event (ie, the primary event usually. But if for some WACK
494
+	 * reason it doesn't exist, we consider the earliest event the most important)
495
+	 *
496
+	 * @param int $EVT_ID
497
+	 * @return EE_Datetime
498
+	 * @throws EE_Error
499
+	 */
500
+	public function get_most_important_datetime_for_event(int $EVT_ID)
501
+	{
502
+		$results = $this->get_datetimes_for_event_ordered_by_importance($EVT_ID, 1);
503
+		if ($results) {
504
+			return array_shift($results);
505
+		}
506
+		return null;
507
+	}
508
+
509
+
510
+	/**
511
+	 * This returns a wpdb->results        Array of all DTT month and years matching the incoming query params and
512
+	 * grouped by month and year.
513
+	 *
514
+	 * @param array  $where_params       @see
515
+	 *                                   https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md#0-where-conditions
516
+	 * @param string $evt_active_status  A string representing the evt active status to filter the months by.
517
+	 *                                   Can be:
518
+	 *                                   - '' = no filter
519
+	 *                                   - upcoming = Published events with at least one upcoming datetime.
520
+	 *                                   - expired = Events with all datetimes expired.
521
+	 *                                   - active = Events that are published and have at least one datetime that
522
+	 *                                   starts before now and ends after now.
523
+	 *                                   - inactive = Events that are either not published.
524
+	 * @return stdClass[]
525
+	 * @throws EE_Error
526
+	 * @throws InvalidArgumentException
527
+	 * @throws InvalidArgumentException
528
+	 */
529
+	public function get_dtt_months_and_years(array $where_params, $evt_active_status = '')
530
+	{
531
+		$current_time_for_DTT_EVT_start = $this->current_time_for_query('DTT_EVT_start');
532
+		$current_time_for_DTT_EVT_end   = $this->current_time_for_query('DTT_EVT_end');
533
+		switch ($evt_active_status) {
534
+			case 'upcoming':
535
+				$where_params['Event.status'] = 'publish';
536
+				// if there are already query_params matching DTT_EVT_start then we need to modify that to add them.
537
+				if (isset($where_params['DTT_EVT_start'])) {
538
+					$where_params['DTT_EVT_start*****'] = $where_params['DTT_EVT_start'];
539
+				}
540
+				$where_params['DTT_EVT_start'] = ['>', $current_time_for_DTT_EVT_start];
541
+				break;
542
+			case 'expired':
543
+				if (isset($where_params['Event.status'])) {
544
+					unset($where_params['Event.status']);
545
+				}
546
+				// get events to exclude
547
+				$exclude_query[0] = array_merge(
548
+					$where_params,
549
+					['DTT_EVT_end' => ['>', $current_time_for_DTT_EVT_end]]
550
+				);
551
+				// first get all events that have datetimes where its not expired.
552
+				$event_ids = $this->_get_all_wpdb_results(
553
+					$exclude_query,
554
+					OBJECT_K,
555
+					'Datetime.EVT_ID'
556
+				);
557
+				$event_ids = array_keys($event_ids);
558
+				if (isset($where_params['DTT_EVT_end'])) {
559
+					$where_params['DTT_EVT_end****'] = $where_params['DTT_EVT_end'];
560
+				}
561
+				$where_params['DTT_EVT_end']  = ['<', $current_time_for_DTT_EVT_end];
562
+				$where_params['Event.EVT_ID'] = ['NOT IN', $event_ids];
563
+				break;
564
+			case 'active':
565
+				$where_params['Event.status'] = 'publish';
566
+				if (isset($where_params['DTT_EVT_start'])) {
567
+					$where_params['Datetime.DTT_EVT_start******'] = $where_params['DTT_EVT_start'];
568
+				}
569
+				if (isset($where_params['Datetime.DTT_EVT_end'])) {
570
+					$where_params['Datetime.DTT_EVT_end*****'] = $where_params['DTT_EVT_end'];
571
+				}
572
+				$where_params['DTT_EVT_start'] = ['<', $current_time_for_DTT_EVT_start];
573
+				$where_params['DTT_EVT_end']   = ['>', $current_time_for_DTT_EVT_end];
574
+				break;
575
+			case 'inactive':
576
+				if (isset($where_params['Event.status'])) {
577
+					unset($where_params['Event.status']);
578
+				}
579
+				if (isset($where_params['OR'])) {
580
+					$where_params['AND']['OR'] = $where_params['OR'];
581
+				}
582
+				if (isset($where_params['DTT_EVT_end'])) {
583
+					$where_params['AND']['DTT_EVT_end****'] = $where_params['DTT_EVT_end'];
584
+					unset($where_params['DTT_EVT_end']);
585
+				}
586
+				if (isset($where_params['DTT_EVT_start'])) {
587
+					$where_params['AND']['DTT_EVT_start'] = $where_params['DTT_EVT_start'];
588
+					unset($where_params['DTT_EVT_start']);
589
+				}
590
+				$where_params['AND']['Event.status'] = ['!=', 'publish'];
591
+				break;
592
+		}
593
+		$query_params[0]          = $where_params;
594
+		$query_params['group_by'] = ['dtt_year', 'dtt_month'];
595
+		$query_params             = $this->addOrderByQueryParams($query_params, 'DTT_EVT_start', 'DESC');
596
+
597
+		$query_interval    = EEH_DTT_Helper::get_sql_query_interval_for_offset(
598
+			$this->get_timezone(),
599
+			'DTT_EVT_start'
600
+		);
601
+		$columns_to_select = [
602
+			'dtt_year'      => ['YEAR(' . $query_interval . ')', '%s'],
603
+			'dtt_month'     => ['MONTHNAME(' . $query_interval . ')', '%s'],
604
+			'dtt_month_num' => ['MONTH(' . $query_interval . ')', '%s'],
605
+		];
606
+		return $this->_get_all_wpdb_results($query_params, OBJECT, $columns_to_select);
607
+	}
608
+
609
+
610
+	/**
611
+	 * Updates the DTT_sold attribute on each datetime (based on the registrations
612
+	 * for the tickets for each datetime)
613
+	 *
614
+	 * @param EE_Base_Class[]|EE_Datetime[] $datetimes
615
+	 * @throws EE_Error
616
+	 * @throws ReflectionException
617
+	 */
618
+	public function update_sold(array $datetimes)
619
+	{
620
+		EE_Error::doing_it_wrong(
621
+			__FUNCTION__,
622
+			esc_html__(
623
+				'Please use \EEM_Ticket::update_tickets_sold() instead which will in turn correctly update both the Ticket AND Datetime counts.',
624
+				'event_espresso'
625
+			),
626
+			'4.9.32.rc.005'
627
+		);
628
+		foreach ($datetimes as $datetime) {
629
+			$datetime->update_sold();
630
+		}
631
+	}
632
+
633
+
634
+	/**
635
+	 *    Gets the total number of tickets available at a particular datetime
636
+	 *    (does NOT take into account the datetime's spaces available)
637
+	 *
638
+	 * @param int   $DTT_ID
639
+	 * @param array $query_params
640
+	 * @return int of tickets available. If sold out, return less than 1. If infinite, returns EE_INF,  IF there are NO
641
+	 *             tickets attached to datetime then FALSE is returned.
642
+	 * @throws EE_Error
643
+	 * @throws ReflectionException
644
+	 */
645
+	public function sum_tickets_currently_available_at_datetime(int $DTT_ID, array $query_params = [])
646
+	{
647
+		$datetime = $this->get_one_by_ID($DTT_ID);
648
+		if ($datetime instanceof EE_Datetime) {
649
+			return $datetime->tickets_remaining($query_params);
650
+		}
651
+		return 0;
652
+	}
653
+
654
+
655
+	/**
656
+	 * This returns an array of counts of datetimes in the database for each Datetime status that can be queried.
657
+	 *
658
+	 * @param array $stati_to_include  If included you can restrict the statuses we return counts for by including the
659
+	 *                                 stati you want counts for as values in the array.  An empty array returns counts
660
+	 *                                 for all valid stati.
661
+	 * @param array $query_params      If included can be used to refine the conditions for returning the count (i.e.
662
+	 *                                 only for Datetimes connected to a specific event, or specific ticket.
663
+	 * @return array  The value returned is an array indexed by Datetime Status and the values are the counts.  The
664
+	 * @throws EE_Error
665
+	 *                                 stati used as index keys are: EE_Datetime::active EE_Datetime::upcoming
666
+	 *                                 EE_Datetime::expired
667
+	 */
668
+	public function get_datetime_counts_by_status(array $stati_to_include = [], array $query_params = [])
669
+	{
670
+		// only accept where conditions for this query.
671
+		$_where            = isset($query_params[0]) ? $query_params[0] : [];
672
+		$status_query_args = [
673
+			EE_Datetime::active   => array_merge(
674
+				$_where,
675
+				['DTT_EVT_start' => ['<', time()], 'DTT_EVT_end' => ['>', time()]]
676
+			),
677
+			EE_Datetime::upcoming => array_merge(
678
+				$_where,
679
+				['DTT_EVT_start' => ['>', time()]]
680
+			),
681
+			EE_Datetime::expired  => array_merge(
682
+				$_where,
683
+				['DTT_EVT_end' => ['<', time()]]
684
+			),
685
+		];
686
+		if (! empty($stati_to_include)) {
687
+			foreach (array_keys($status_query_args) as $status) {
688
+				if (! in_array($status, $stati_to_include, true)) {
689
+					unset($status_query_args[ $status ]);
690
+				}
691
+			}
692
+		}
693
+		// loop through and query counts for each stati.
694
+		$status_query_results = [];
695
+		foreach ($status_query_args as $status => $status_where_conditions) {
696
+			$status_query_results[ $status ] = EEM_Datetime::count(
697
+				[$status_where_conditions],
698
+				'DTT_ID',
699
+				true
700
+			);
701
+		}
702
+		return $status_query_results;
703
+	}
704
+
705
+
706
+	/**
707
+	 * Returns the specific count for a given Datetime status matching any given query_params.
708
+	 *
709
+	 * @param string $status Valid string representation for Datetime status requested. (Defaults to Active).
710
+	 * @param array  $query_params
711
+	 * @return int
712
+	 * @throws EE_Error
713
+	 */
714
+	public function get_datetime_count_for_status($status = EE_Datetime::active, array $query_params = [])
715
+	{
716
+		$count = $this->get_datetime_counts_by_status([$status], $query_params);
717
+		return ! empty($count[ $status ]) ? $count[ $status ] : 0;
718
+	}
719
+
720
+
721
+	/**
722
+	 * @return bool|int
723
+	 * @since   $VID:$
724
+	 */
725
+	private function prepModelForQuery()
726
+	{
727
+		$prev_data_prep_value = $this->get_assumption_concerning_values_already_prepared_by_model_object();
728
+		$this->assume_values_already_prepared_by_model_object(EEM_Base::prepared_for_use_in_db);
729
+		return $prev_data_prep_value;
730
+	}
731
+
732
+
733
+	/**
734
+	 * @param array    $query_params
735
+	 * @param bool|int $prev_data_prep_value
736
+	 * @return EE_Base_Class[]|EE_Datetime[]
737
+	 * @throws EE_Error
738
+	 * @since   $VID:$
739
+	 */
740
+	private function getDatetimesAndRestoreModel(array $query_params, $prev_data_prep_value)
741
+	{
742
+		$result = $this->get_all($query_params);
743
+		$this->assume_values_already_prepared_by_model_object($prev_data_prep_value);
744
+		return $result;
745
+	}
746
+
747
+
748
+	/**
749
+	 * @param array  $query_params
750
+	 * @param int    $limit
751
+	 * @param string $order_by
752
+	 * @param string $order
753
+	 * @return array
754
+	 * @since   $VID:$
755
+	 */
756
+	private function addDefaultQueryParams(array $query_params, $limit = 0, $order_by = 'DTT_EVT_start', $order = 'ASC')
757
+	{
758
+		$query_params = $this->addOrderByQueryParams($query_params, $order_by, $order);
759
+		$query_params = $this->addLimitQueryParams($query_params, $limit);
760
+		return $query_params;
761
+	}
762
+
763
+
764
+	/**
765
+	 * @param array  $query_params
766
+	 * @param string $default_where_conditions
767
+	 * @return array
768
+	 * @since   $VID:$
769
+	 */
770
+	private function addDefaultWhereConditions(
771
+		array $query_params,
772
+		$default_where_conditions = EEM_Base::default_where_conditions_none
773
+	) {
774
+		$query_params['default_where_conditions'] = $default_where_conditions;
775
+		return $query_params;
776
+	}
777
+
778
+
779
+	/**
780
+	 * @param array $where_params
781
+	 * @param bool  $include_deleted
782
+	 * @param bool  $include_expired
783
+	 * @return array
784
+	 * @since   $VID:$
785
+	 */
786
+	private function addDefaultWhereParams(array $where_params, bool $include_deleted = true, bool $include_expired = true)
787
+	{
788
+		$where_params = $this->addExpiredWhereParams($where_params, $include_expired);
789
+		$where_params = $this->addDeletedWhereParams($where_params, $include_deleted);
790
+		return $where_params;
791
+	}
792
+
793
+
794
+	/**
795
+	 * @param array $where_params
796
+	 * @param bool  $include_deleted
797
+	 * @return array
798
+	 * @since   $VID:$
799
+	 */
800
+	private function addDeletedWhereParams(array $where_params, bool $include_deleted = true)
801
+	{
802
+		$deleted                     = $include_deleted ? [true, false] : [false];
803
+		$where_params['DTT_deleted'] = ['IN', $deleted];
804
+		return $where_params;
805
+	}
806
+
807
+
808
+	/**
809
+	 * @param array $where_params
810
+	 * @param bool  $include_expired
811
+	 * @return array
812
+	 * @since   $VID:$
813
+	 */
814
+	private function addExpiredWhereParams(array $where_params, bool $include_expired = true)
815
+	{
816
+		if (! $include_expired) {
817
+			$where_params['DTT_EVT_end'] = ['>=', current_time('mysql', true)];
818
+		}
819
+		return $where_params;
820
+	}
821
+
822
+
823
+	/**
824
+	 * @param array $query_params
825
+	 * @param int   $limit
826
+	 * @return array
827
+	 * @since   $VID:$
828
+	 */
829
+	private function addLimitQueryParams(array $query_params, $limit = 0)
830
+	{
831
+		if ($limit) {
832
+			$query_params['limit'] = $limit;
833
+		}
834
+		return $query_params;
835
+	}
836
+
837
+
838
+	/**
839
+	 * @param array  $query_params
840
+	 * @param string $order_by
841
+	 * @param string $order
842
+	 * @return array
843
+	 * @since   $VID:$
844
+	 */
845
+	private function addOrderByQueryParams(array $query_params, $order_by = 'DTT_EVT_start', $order = 'ASC')
846
+	{
847
+		$order                    = $order === 'ASC' ? 'ASC' : 'DESC';
848
+		$valid_order_columns      = ['DTT_ID', 'DTT_EVT_start', 'DTT_EVT_end', 'DTT_order'];
849
+		$order_by                 = in_array($order_by, $valid_order_columns, true) ? $order_by : 'DTT_EVT_start';
850
+		$query_params['order_by'] = [$order_by => $order];
851
+		return $query_params;
852
+	}
853 853
 }
Please login to merge, or discard this patch.
core/services/routing/Route.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -251,7 +251,7 @@  discard block
 block discarded – undo
251 251
     private function loadDataNode()
252 252
     {
253 253
         $data_node_fqcn = $this->dataNodeClass();
254
-        if (! empty($data_node_fqcn)) {
254
+        if ( ! empty($data_node_fqcn)) {
255 255
             $data_node = $this->loader->getShared($data_node_fqcn);
256 256
             $this->setDataNode($data_node);
257 257
         }
@@ -279,7 +279,7 @@  discard block
 block discarded – undo
279 279
      */
280 280
     private function verifyIsHandled($handled)
281 281
     {
282
-        if (! is_bool($handled)) {
282
+        if ( ! is_bool($handled)) {
283 283
             throw new DomainException(
284 284
                 esc_html__(
285 285
                     'Route::requestHandler() must return a boolean to indicate whether the request has been handled or not.',
Please login to merge, or discard this patch.
Indentation   +267 added lines, -267 removed lines patch added patch discarded remove patch
@@ -28,271 +28,271 @@
 block discarded – undo
28 28
  */
29 29
 abstract class Route implements RouteInterface, RequiresCapCheckInterface
30 30
 {
31
-    /**
32
-     * @var AssetManagerInterface $asset_manager
33
-     */
34
-    protected $asset_manager;
35
-
36
-    /**
37
-     * @var EE_Dependency_Map $dependency_map
38
-     */
39
-    protected $dependency_map;
40
-
41
-    /**
42
-     * @var JsonDataNode $data_node
43
-     */
44
-    protected $data_node;
45
-
46
-    /**
47
-     * @var LoaderInterface $loader
48
-     */
49
-    protected $loader;
50
-
51
-    /**
52
-     * @var RequestInterface $request
53
-     */
54
-    protected $request;
55
-
56
-    /**
57
-     * @var RouteMatchSpecificationInterface $specification
58
-     */
59
-    protected $specification;
60
-
61
-    /**
62
-     * @var boolean $handled
63
-     */
64
-    private $handled = false;
65
-
66
-    /**
67
-     * @var array $default_dependencies
68
-     */
69
-    protected static $default_dependencies = [
70
-        'EE_Dependency_Map'                           => EE_Dependency_Map::load_from_cache,
71
-        'EventEspresso\core\services\loaders\Loader'  => EE_Dependency_Map::load_from_cache,
72
-        'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache,
73
-    ];
74
-
75
-    /**
76
-     * @var array $full_dependencies
77
-     */
78
-    protected static $full_dependencies = [
79
-        'EE_Dependency_Map'                             => EE_Dependency_Map::load_from_cache,
80
-        'EventEspresso\core\services\loaders\Loader'    => EE_Dependency_Map::load_from_cache,
81
-        'EventEspresso\core\services\request\Request'   => EE_Dependency_Map::load_from_cache,
82
-        'EventEspresso\core\services\json\JsonDataNode' => EE_Dependency_Map::load_from_cache,
83
-        RouteMatchSpecificationInterface::class         => EE_Dependency_Map::load_from_cache,
84
-    ];
85
-
86
-
87
-    /**
88
-     * Route constructor.
89
-     *
90
-     * @param EE_Dependency_Map                     $dependency_map
91
-     * @param LoaderInterface                       $loader
92
-     * @param RequestInterface                      $request
93
-     * @param JsonDataNode|null                     $data_node
94
-     * @param RouteMatchSpecificationInterface|null $specification
95
-     */
96
-    public function __construct(
97
-        EE_Dependency_Map $dependency_map,
98
-        LoaderInterface $loader,
99
-        RequestInterface $request,
100
-        JsonDataNode $data_node = null,
101
-        RouteMatchSpecificationInterface $specification = null
102
-    ) {
103
-        $this->dependency_map = $dependency_map;
104
-        $this->data_node      = $data_node;
105
-        $this->loader         = $loader;
106
-        $this->request        = $request;
107
-        $this->setSpecification($specification);
108
-    }
109
-
110
-
111
-    /**
112
-     * @return void
113
-     */
114
-    abstract protected function registerDependencies();
115
-
116
-
117
-    /**
118
-     * implements logic required to run during request
119
-     *
120
-     * @return bool
121
-     */
122
-    abstract protected function requestHandler(): bool;
123
-
124
-
125
-    /**
126
-     * called just before matchesCurrentRequest()
127
-     * and allows Route to perform any setup required such as calling setSpecification()
128
-     *
129
-     * @return void
130
-     */
131
-    public function initialize()
132
-    {
133
-        // do nothing by default
134
-    }
135
-
136
-
137
-    /**
138
-     * returns true if the current request matches this route
139
-     * child classes can override and use Request directly to match route with request
140
-     * or supply a RouteMatchSpecification class and just use the below
141
-     *
142
-     * @return bool
143
-     */
144
-    public function matchesCurrentRequest(): bool
145
-    {
146
-        return $this->specification instanceof RouteMatchSpecificationInterface
147
-               && $this->specification->isMatchingRoute();
148
-    }
149
-
150
-
151
-    /**
152
-     * returns the FQCN for this route's JsonDataNode
153
-     *
154
-     * @return string
155
-     */
156
-    protected function dataNodeClass(): string
157
-    {
158
-        return '';
159
-    }
160
-
161
-
162
-    public function getCapCheck()
163
-    {
164
-        return new PublicCapabilities('', 'access Event Espresso route');
165
-    }
166
-
167
-
168
-    /**
169
-     * @return array
170
-     */
171
-    public static function getDefaultDependencies(): array
172
-    {
173
-        return self::$default_dependencies;
174
-    }
175
-
176
-
177
-    /**
178
-     * @return array
179
-     */
180
-    public static function getFullDependencies(): array
181
-    {
182
-        return self::$full_dependencies;
183
-    }
184
-
185
-
186
-    /**
187
-     * @param JsonDataNode|null $data_node
188
-     */
189
-    protected function setDataNode(JsonDataNode $data_node = null)
190
-    {
191
-        $this->data_node = $data_node;
192
-    }
193
-
194
-
195
-    /**
196
-     * @param RouteMatchSpecificationInterface|null $specification
197
-     */
198
-    protected function setSpecification(RouteMatchSpecificationInterface $specification = null)
199
-    {
200
-        $this->specification = $specification;
201
-    }
202
-
203
-
204
-    /**
205
-     * @return JsonDataNode
206
-     */
207
-    public function dataNode(): ?JsonDataNode
208
-    {
209
-        return $this->data_node;
210
-    }
211
-
212
-
213
-    /**
214
-     * runs route requestHandler() if
215
-     *      - route has not previously been handled
216
-     *      - route specification matches for current request
217
-     * sets route handled property based on results returned by requestHandler()
218
-     *
219
-     * @return bool
220
-     */
221
-    public function handleRequest(): bool
222
-    {
223
-        if ($this->isNotHandled()) {
224
-            $this->initialize();
225
-            if ($this->matchesCurrentRequest()) {
226
-                do_action('AHEE__EventEspresso_core_domain_entities_routes_handlers_Route__handleRequest', $this);
227
-                $this->registerDependencies();
228
-                $this->loadDataNode();
229
-                $this->verifyIsHandled($this->requestHandler());
230
-            }
231
-        }
232
-        return $this->handled;
233
-    }
234
-
235
-
236
-    /**
237
-     * @return bool
238
-     */
239
-    final public function isHandled(): bool
240
-    {
241
-        return $this->handled;
242
-    }
243
-
244
-
245
-    /**
246
-     * @return bool
247
-     */
248
-    final public function isNotHandled(): bool
249
-    {
250
-        return ! $this->handled;
251
-    }
252
-
253
-
254
-    /**
255
-     * @return void
256
-     */
257
-    private function loadDataNode()
258
-    {
259
-        $data_node_fqcn = $this->dataNodeClass();
260
-        if (! empty($data_node_fqcn)) {
261
-            $data_node = $this->loader->getShared($data_node_fqcn);
262
-            $this->setDataNode($data_node);
263
-        }
264
-    }
265
-
266
-
267
-    /**
268
-     * @param string $domain_fqcn
269
-     */
270
-    public function initializeBaristaForDomain(string $domain_fqcn)
271
-    {
272
-        if (apply_filters('FHEE__load_Barista', true)) {
273
-            /** @var BaristaFactory $factory */
274
-            $factory = $this->loader->getShared(BaristaFactory::class);
275
-            $barista = $factory->createFromDomainClass($domain_fqcn);
276
-            if ($barista instanceof BaristaInterface) {
277
-                $barista->initialize();
278
-            }
279
-        }
280
-    }
281
-
282
-
283
-    /**
284
-     * @var bool
285
-     */
286
-    private function verifyIsHandled($handled)
287
-    {
288
-        if (! is_bool($handled)) {
289
-            throw new DomainException(
290
-                esc_html__(
291
-                    'Route::requestHandler() must return a boolean to indicate whether the request has been handled or not.',
292
-                    'event_espresso'
293
-                )
294
-            );
295
-        }
296
-        $this->handled = filter_var($handled, FILTER_VALIDATE_BOOLEAN);
297
-    }
31
+	/**
32
+	 * @var AssetManagerInterface $asset_manager
33
+	 */
34
+	protected $asset_manager;
35
+
36
+	/**
37
+	 * @var EE_Dependency_Map $dependency_map
38
+	 */
39
+	protected $dependency_map;
40
+
41
+	/**
42
+	 * @var JsonDataNode $data_node
43
+	 */
44
+	protected $data_node;
45
+
46
+	/**
47
+	 * @var LoaderInterface $loader
48
+	 */
49
+	protected $loader;
50
+
51
+	/**
52
+	 * @var RequestInterface $request
53
+	 */
54
+	protected $request;
55
+
56
+	/**
57
+	 * @var RouteMatchSpecificationInterface $specification
58
+	 */
59
+	protected $specification;
60
+
61
+	/**
62
+	 * @var boolean $handled
63
+	 */
64
+	private $handled = false;
65
+
66
+	/**
67
+	 * @var array $default_dependencies
68
+	 */
69
+	protected static $default_dependencies = [
70
+		'EE_Dependency_Map'                           => EE_Dependency_Map::load_from_cache,
71
+		'EventEspresso\core\services\loaders\Loader'  => EE_Dependency_Map::load_from_cache,
72
+		'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache,
73
+	];
74
+
75
+	/**
76
+	 * @var array $full_dependencies
77
+	 */
78
+	protected static $full_dependencies = [
79
+		'EE_Dependency_Map'                             => EE_Dependency_Map::load_from_cache,
80
+		'EventEspresso\core\services\loaders\Loader'    => EE_Dependency_Map::load_from_cache,
81
+		'EventEspresso\core\services\request\Request'   => EE_Dependency_Map::load_from_cache,
82
+		'EventEspresso\core\services\json\JsonDataNode' => EE_Dependency_Map::load_from_cache,
83
+		RouteMatchSpecificationInterface::class         => EE_Dependency_Map::load_from_cache,
84
+	];
85
+
86
+
87
+	/**
88
+	 * Route constructor.
89
+	 *
90
+	 * @param EE_Dependency_Map                     $dependency_map
91
+	 * @param LoaderInterface                       $loader
92
+	 * @param RequestInterface                      $request
93
+	 * @param JsonDataNode|null                     $data_node
94
+	 * @param RouteMatchSpecificationInterface|null $specification
95
+	 */
96
+	public function __construct(
97
+		EE_Dependency_Map $dependency_map,
98
+		LoaderInterface $loader,
99
+		RequestInterface $request,
100
+		JsonDataNode $data_node = null,
101
+		RouteMatchSpecificationInterface $specification = null
102
+	) {
103
+		$this->dependency_map = $dependency_map;
104
+		$this->data_node      = $data_node;
105
+		$this->loader         = $loader;
106
+		$this->request        = $request;
107
+		$this->setSpecification($specification);
108
+	}
109
+
110
+
111
+	/**
112
+	 * @return void
113
+	 */
114
+	abstract protected function registerDependencies();
115
+
116
+
117
+	/**
118
+	 * implements logic required to run during request
119
+	 *
120
+	 * @return bool
121
+	 */
122
+	abstract protected function requestHandler(): bool;
123
+
124
+
125
+	/**
126
+	 * called just before matchesCurrentRequest()
127
+	 * and allows Route to perform any setup required such as calling setSpecification()
128
+	 *
129
+	 * @return void
130
+	 */
131
+	public function initialize()
132
+	{
133
+		// do nothing by default
134
+	}
135
+
136
+
137
+	/**
138
+	 * returns true if the current request matches this route
139
+	 * child classes can override and use Request directly to match route with request
140
+	 * or supply a RouteMatchSpecification class and just use the below
141
+	 *
142
+	 * @return bool
143
+	 */
144
+	public function matchesCurrentRequest(): bool
145
+	{
146
+		return $this->specification instanceof RouteMatchSpecificationInterface
147
+			   && $this->specification->isMatchingRoute();
148
+	}
149
+
150
+
151
+	/**
152
+	 * returns the FQCN for this route's JsonDataNode
153
+	 *
154
+	 * @return string
155
+	 */
156
+	protected function dataNodeClass(): string
157
+	{
158
+		return '';
159
+	}
160
+
161
+
162
+	public function getCapCheck()
163
+	{
164
+		return new PublicCapabilities('', 'access Event Espresso route');
165
+	}
166
+
167
+
168
+	/**
169
+	 * @return array
170
+	 */
171
+	public static function getDefaultDependencies(): array
172
+	{
173
+		return self::$default_dependencies;
174
+	}
175
+
176
+
177
+	/**
178
+	 * @return array
179
+	 */
180
+	public static function getFullDependencies(): array
181
+	{
182
+		return self::$full_dependencies;
183
+	}
184
+
185
+
186
+	/**
187
+	 * @param JsonDataNode|null $data_node
188
+	 */
189
+	protected function setDataNode(JsonDataNode $data_node = null)
190
+	{
191
+		$this->data_node = $data_node;
192
+	}
193
+
194
+
195
+	/**
196
+	 * @param RouteMatchSpecificationInterface|null $specification
197
+	 */
198
+	protected function setSpecification(RouteMatchSpecificationInterface $specification = null)
199
+	{
200
+		$this->specification = $specification;
201
+	}
202
+
203
+
204
+	/**
205
+	 * @return JsonDataNode
206
+	 */
207
+	public function dataNode(): ?JsonDataNode
208
+	{
209
+		return $this->data_node;
210
+	}
211
+
212
+
213
+	/**
214
+	 * runs route requestHandler() if
215
+	 *      - route has not previously been handled
216
+	 *      - route specification matches for current request
217
+	 * sets route handled property based on results returned by requestHandler()
218
+	 *
219
+	 * @return bool
220
+	 */
221
+	public function handleRequest(): bool
222
+	{
223
+		if ($this->isNotHandled()) {
224
+			$this->initialize();
225
+			if ($this->matchesCurrentRequest()) {
226
+				do_action('AHEE__EventEspresso_core_domain_entities_routes_handlers_Route__handleRequest', $this);
227
+				$this->registerDependencies();
228
+				$this->loadDataNode();
229
+				$this->verifyIsHandled($this->requestHandler());
230
+			}
231
+		}
232
+		return $this->handled;
233
+	}
234
+
235
+
236
+	/**
237
+	 * @return bool
238
+	 */
239
+	final public function isHandled(): bool
240
+	{
241
+		return $this->handled;
242
+	}
243
+
244
+
245
+	/**
246
+	 * @return bool
247
+	 */
248
+	final public function isNotHandled(): bool
249
+	{
250
+		return ! $this->handled;
251
+	}
252
+
253
+
254
+	/**
255
+	 * @return void
256
+	 */
257
+	private function loadDataNode()
258
+	{
259
+		$data_node_fqcn = $this->dataNodeClass();
260
+		if (! empty($data_node_fqcn)) {
261
+			$data_node = $this->loader->getShared($data_node_fqcn);
262
+			$this->setDataNode($data_node);
263
+		}
264
+	}
265
+
266
+
267
+	/**
268
+	 * @param string $domain_fqcn
269
+	 */
270
+	public function initializeBaristaForDomain(string $domain_fqcn)
271
+	{
272
+		if (apply_filters('FHEE__load_Barista', true)) {
273
+			/** @var BaristaFactory $factory */
274
+			$factory = $this->loader->getShared(BaristaFactory::class);
275
+			$barista = $factory->createFromDomainClass($domain_fqcn);
276
+			if ($barista instanceof BaristaInterface) {
277
+				$barista->initialize();
278
+			}
279
+		}
280
+	}
281
+
282
+
283
+	/**
284
+	 * @var bool
285
+	 */
286
+	private function verifyIsHandled($handled)
287
+	{
288
+		if (! is_bool($handled)) {
289
+			throw new DomainException(
290
+				esc_html__(
291
+					'Route::requestHandler() must return a boolean to indicate whether the request has been handled or not.',
292
+					'event_espresso'
293
+				)
294
+			);
295
+		}
296
+		$this->handled = filter_var($handled, FILTER_VALIDATE_BOOLEAN);
297
+	}
298 298
 }
Please login to merge, or discard this patch.