Completed
Branch master (44537d)
by
unknown
14:30 queued 10:03
created
core/db_models/EEM_Message_Template.model.php 2 patches
Indentation   +68 added lines, -68 removed lines patch added patch discarded remove patch
@@ -10,76 +10,76 @@
 block discarded – undo
10 10
  */
11 11
 class EEM_Message_Template extends EEM_Base
12 12
 {
13
-    // private instance of the EEM_Message_Template object
14
-    protected static $_instance = null;
13
+	// private instance of the EEM_Message_Template object
14
+	protected static $_instance = null;
15 15
 
16 16
 
17
-    /**
18
-     * private constructor to prevent direct creation
19
-     *
20
-     * @param string|null $timezone
21
-     * @throws EE_Error
22
-     */
23
-    protected function __construct(?string $timezone = '')
24
-    {
25
-        $this->singular_item = esc_html__('Message Template', 'event_espresso');
26
-        $this->plural_item   = esc_html__('Message Templates', 'event_espresso');
17
+	/**
18
+	 * private constructor to prevent direct creation
19
+	 *
20
+	 * @param string|null $timezone
21
+	 * @throws EE_Error
22
+	 */
23
+	protected function __construct(?string $timezone = '')
24
+	{
25
+		$this->singular_item = esc_html__('Message Template', 'event_espresso');
26
+		$this->plural_item   = esc_html__('Message Templates', 'event_espresso');
27 27
 
28
-        $this->_tables = [
29
-            'Message_Template' => new EE_Primary_Table('esp_message_template', 'MTP_ID'),
30
-        ];
31
-        $this->_fields = [
32
-            'Message_Template' => [
33
-                'MTP_ID'             => new EE_Primary_Key_Int_Field(
34
-                    'MTP_ID',
35
-                    esc_html__('Message Template ID', 'event_espresso')
36
-                ),
37
-                'GRP_ID'             => new EE_Foreign_Key_Int_Field(
38
-                    'GRP_ID',
39
-                    esc_html__('Message Template Group ID', 'event_espresso'),
40
-                    false,
41
-                    0,
42
-                    'Message_Template_Group'
43
-                ),
44
-                'MTP_template_field' => new EE_Plain_Text_Field(
45
-                    'MTP_template_field',
46
-                    esc_html__(
47
-                        'Field Name for this Template',
48
-                        'event_espresso'
49
-                    ),
50
-                    false,
51
-                    'default'
52
-                ),
53
-                'MTP_context'        => new EE_Plain_Text_Field(
54
-                    'MTP_context',
55
-                    esc_html__(
56
-                        'Message Type Context for this field',
57
-                        'event_espresso'
58
-                    ),
59
-                    false,
60
-                    'admin'
61
-                ),
62
-                'MTP_content'        => new EE_Serialized_Text_Field(
63
-                    'MTP_content',
64
-                    esc_html__(
65
-                        'The field content for the template',
66
-                        'event_espresso'
67
-                    ),
68
-                    false,
69
-                    ''
70
-                ),
71
-            ],
72
-        ];
28
+		$this->_tables = [
29
+			'Message_Template' => new EE_Primary_Table('esp_message_template', 'MTP_ID'),
30
+		];
31
+		$this->_fields = [
32
+			'Message_Template' => [
33
+				'MTP_ID'             => new EE_Primary_Key_Int_Field(
34
+					'MTP_ID',
35
+					esc_html__('Message Template ID', 'event_espresso')
36
+				),
37
+				'GRP_ID'             => new EE_Foreign_Key_Int_Field(
38
+					'GRP_ID',
39
+					esc_html__('Message Template Group ID', 'event_espresso'),
40
+					false,
41
+					0,
42
+					'Message_Template_Group'
43
+				),
44
+				'MTP_template_field' => new EE_Plain_Text_Field(
45
+					'MTP_template_field',
46
+					esc_html__(
47
+						'Field Name for this Template',
48
+						'event_espresso'
49
+					),
50
+					false,
51
+					'default'
52
+				),
53
+				'MTP_context'        => new EE_Plain_Text_Field(
54
+					'MTP_context',
55
+					esc_html__(
56
+						'Message Type Context for this field',
57
+						'event_espresso'
58
+					),
59
+					false,
60
+					'admin'
61
+				),
62
+				'MTP_content'        => new EE_Serialized_Text_Field(
63
+					'MTP_content',
64
+					esc_html__(
65
+						'The field content for the template',
66
+						'event_espresso'
67
+					),
68
+					false,
69
+					''
70
+				),
71
+			],
72
+		];
73 73
 
74
-        $this->_model_relations        = [
75
-            'Message_Template_Group' => new EE_Belongs_To_Relation(),
76
-        ];
77
-        $this->_model_chain_to_wp_user = 'Message_Template_Group';
78
-        foreach ($this->_cap_contexts_to_cap_action_map as $context => $action) {
79
-            $this->_cap_restriction_generators[ $context ] =
80
-                new EE_Restriction_Generator_Global('Message_Template_Group.MTP_is_global');
81
-        }
82
-        $this->_caps_slug = 'messages';
83
-        parent::__construct($timezone);
84
-    }
74
+		$this->_model_relations        = [
75
+			'Message_Template_Group' => new EE_Belongs_To_Relation(),
76
+		];
77
+		$this->_model_chain_to_wp_user = 'Message_Template_Group';
78
+		foreach ($this->_cap_contexts_to_cap_action_map as $context => $action) {
79
+			$this->_cap_restriction_generators[ $context ] =
80
+				new EE_Restriction_Generator_Global('Message_Template_Group.MTP_is_global');
81
+		}
82
+		$this->_caps_slug = 'messages';
83
+		parent::__construct($timezone);
84
+	}
85 85
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -76,7 +76,7 @@
 block discarded – undo
76 76
         ];
77 77
         $this->_model_chain_to_wp_user = 'Message_Template_Group';
78 78
         foreach ($this->_cap_contexts_to_cap_action_map as $context => $action) {
79
-            $this->_cap_restriction_generators[ $context ] =
79
+            $this->_cap_restriction_generators[$context] =
80 80
                 new EE_Restriction_Generator_Global('Message_Template_Group.MTP_is_global');
81 81
         }
82 82
         $this->_caps_slug = 'messages';
Please login to merge, or discard this patch.
core/db_models/EEM_Event_Question_Group.model.php 1 patch
Indentation   +104 added lines, -104 removed lines patch added patch discarded remove patch
@@ -14,116 +14,116 @@
 block discarded – undo
14 14
  */
15 15
 class EEM_Event_Question_Group extends EEM_Base
16 16
 {
17
-    /**
18
-     * Name of the field indicating an event should use the question group for the primary attendee
19
-     */
20
-    const PRIMARY = 'EQG_primary';
17
+	/**
18
+	 * Name of the field indicating an event should use the question group for the primary attendee
19
+	 */
20
+	const PRIMARY = 'EQG_primary';
21 21
 
22
-    /**
23
-     * Name of hte field indicating an event should use the question group for additional attendees
24
-     */
25
-    const ADDITIONAL = 'EQG_additional';
22
+	/**
23
+	 * Name of hte field indicating an event should use the question group for additional attendees
24
+	 */
25
+	const ADDITIONAL = 'EQG_additional';
26 26
 
27
-    // private instance of the Event_Question_Group object
28
-    protected static $_instance = null;
27
+	// private instance of the Event_Question_Group object
28
+	protected static $_instance = null;
29 29
 
30 30
 
31
-    /**
32
-     * @param string|null $timezone
33
-     * @throws EE_Error
34
-     */
35
-    protected function __construct(?string $timezone = '')
36
-    {
37
-        $this->singular_item    = esc_html__('Event to Question Group Link', 'event_espresso');
38
-        $this->plural_item      = esc_html__('Event to Question Group Links', 'event_espresso');
39
-        $this->_tables          = [
40
-            'Event_Question_Group' => new EE_Primary_Table('esp_event_question_group', 'EQG_ID'),
41
-        ];
42
-        $this->_fields          = [
43
-            'Event_Question_Group' => [
44
-                'EQG_ID'         => new EE_Primary_Key_Int_Field(
45
-                    'EQG_ID',
46
-                    esc_html__('Event to Question Group Link ID', 'event_espresso')
47
-                ),
48
-                'EVT_ID'         => new EE_Foreign_Key_Int_Field(
49
-                    'EVT_ID',
50
-                    esc_html__('Event ID', 'event_espresso'),
51
-                    false,
52
-                    0,
53
-                    'Event'
54
-                ),
55
-                'QSG_ID'         => new EE_Foreign_Key_Int_Field(
56
-                    'QSG_ID',
57
-                    esc_html__('Question Group Id', 'event_espresso'),
58
-                    false,
59
-                    0,
60
-                    'Question_Group'
61
-                ),
62
-                'EQG_additional' => new EE_Boolean_Field(
63
-                    'EQG_additional',
64
-                    esc_html__(
65
-                        'Flag indicating question is only for additional attendees',
66
-                        'event_espresso'
67
-                    ),
68
-                    false,
69
-                    false
70
-                ),
71
-                'EQG_primary'    => new EE_Boolean_Field(
72
-                    'EQG_primary',
73
-                    esc_html__(
74
-                        'Flag indicating question is only for primary attendees',
75
-                        'event_espresso'
76
-                    ),
77
-                    false,
78
-                    false
79
-                ),
80
-            ],
81
-        ];
82
-        $this->_model_relations = [
83
-            'Event'          => new EE_Belongs_To_Relation(),
84
-            'Question_Group' => new EE_Belongs_To_Relation(),
85
-        ];
31
+	/**
32
+	 * @param string|null $timezone
33
+	 * @throws EE_Error
34
+	 */
35
+	protected function __construct(?string $timezone = '')
36
+	{
37
+		$this->singular_item    = esc_html__('Event to Question Group Link', 'event_espresso');
38
+		$this->plural_item      = esc_html__('Event to Question Group Links', 'event_espresso');
39
+		$this->_tables          = [
40
+			'Event_Question_Group' => new EE_Primary_Table('esp_event_question_group', 'EQG_ID'),
41
+		];
42
+		$this->_fields          = [
43
+			'Event_Question_Group' => [
44
+				'EQG_ID'         => new EE_Primary_Key_Int_Field(
45
+					'EQG_ID',
46
+					esc_html__('Event to Question Group Link ID', 'event_espresso')
47
+				),
48
+				'EVT_ID'         => new EE_Foreign_Key_Int_Field(
49
+					'EVT_ID',
50
+					esc_html__('Event ID', 'event_espresso'),
51
+					false,
52
+					0,
53
+					'Event'
54
+				),
55
+				'QSG_ID'         => new EE_Foreign_Key_Int_Field(
56
+					'QSG_ID',
57
+					esc_html__('Question Group Id', 'event_espresso'),
58
+					false,
59
+					0,
60
+					'Question_Group'
61
+				),
62
+				'EQG_additional' => new EE_Boolean_Field(
63
+					'EQG_additional',
64
+					esc_html__(
65
+						'Flag indicating question is only for additional attendees',
66
+						'event_espresso'
67
+					),
68
+					false,
69
+					false
70
+				),
71
+				'EQG_primary'    => new EE_Boolean_Field(
72
+					'EQG_primary',
73
+					esc_html__(
74
+						'Flag indicating question is only for primary attendees',
75
+						'event_espresso'
76
+					),
77
+					false,
78
+					false
79
+				),
80
+			],
81
+		];
82
+		$this->_model_relations = [
83
+			'Event'          => new EE_Belongs_To_Relation(),
84
+			'Question_Group' => new EE_Belongs_To_Relation(),
85
+		];
86 86
 
87
-        // this model is generally available for reading
88
-        $path_to_event = 'Event';
87
+		// this model is generally available for reading
88
+		$path_to_event = 'Event';
89 89
 
90
-        $caps[ EEM_Base::caps_read ]       = new EE_Restriction_Generator_Event_Related_Public($path_to_event);
91
-        $caps[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event);
92
-        $caps[ EEM_Base::caps_edit ]       = new EE_Restriction_Generator_Event_Related_Protected($path_to_event);
93
-        $caps[ EEM_Base::caps_delete ]     = new EE_Restriction_Generator_Event_Related_Protected(
94
-            $path_to_event,
95
-            EEM_Base::caps_edit
96
-        );
97
-        $this->_cap_restriction_generators = $caps;
98
-        parent::__construct($timezone);
99
-    }
90
+		$caps[ EEM_Base::caps_read ]       = new EE_Restriction_Generator_Event_Related_Public($path_to_event);
91
+		$caps[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event);
92
+		$caps[ EEM_Base::caps_edit ]       = new EE_Restriction_Generator_Event_Related_Protected($path_to_event);
93
+		$caps[ EEM_Base::caps_delete ]     = new EE_Restriction_Generator_Event_Related_Protected(
94
+			$path_to_event,
95
+			EEM_Base::caps_edit
96
+		);
97
+		$this->_cap_restriction_generators = $caps;
98
+		parent::__construct($timezone);
99
+	}
100 100
 
101 101
 
102
-    /**
103
-     * Decides whether to use the 'EQG_primary' or newer 'EQG_additional' for use in queries, based on whether
104
-     * this is concerning primary attendees or additional attendees.
105
-     * If 1, true, or "primary" is passed in, returns EQG_primary. If 0, false, or "additional" is passed in, returns
106
-     * EQG_additional.
107
-     *
108
-     * @param string|boolean|int $context
109
-     * @return string
110
-     * @since 4.10.0.p
111
-     */
112
-    public function fieldNameForContext($context): string
113
-    {
114
-        // Basically do a strict switch statement.
115
-        switch (true) {
116
-            case $context === 'additional':
117
-            case $context === false:
118
-            case $context === 0:
119
-                $field_name = EEM_Event_Question_Group::ADDITIONAL;
120
-                break;
121
-            case $context === 'primary':
122
-            case $context === true:
123
-            case $context === 1:
124
-            default:
125
-                $field_name = EEM_Event_Question_Group::PRIMARY;
126
-        }
127
-        return apply_filters('FHEE__EEM_Event_Question_Group__fieldNameForContext', $field_name, $context);
128
-    }
102
+	/**
103
+	 * Decides whether to use the 'EQG_primary' or newer 'EQG_additional' for use in queries, based on whether
104
+	 * this is concerning primary attendees or additional attendees.
105
+	 * If 1, true, or "primary" is passed in, returns EQG_primary. If 0, false, or "additional" is passed in, returns
106
+	 * EQG_additional.
107
+	 *
108
+	 * @param string|boolean|int $context
109
+	 * @return string
110
+	 * @since 4.10.0.p
111
+	 */
112
+	public function fieldNameForContext($context): string
113
+	{
114
+		// Basically do a strict switch statement.
115
+		switch (true) {
116
+			case $context === 'additional':
117
+			case $context === false:
118
+			case $context === 0:
119
+				$field_name = EEM_Event_Question_Group::ADDITIONAL;
120
+				break;
121
+			case $context === 'primary':
122
+			case $context === true:
123
+			case $context === 1:
124
+			default:
125
+				$field_name = EEM_Event_Question_Group::PRIMARY;
126
+		}
127
+		return apply_filters('FHEE__EEM_Event_Question_Group__fieldNameForContext', $field_name, $context);
128
+	}
129 129
 }
Please login to merge, or discard this patch.
core/db_models/EEM_Payment.model.php 2 patches
Indentation   +339 added lines, -339 removed lines patch added patch discarded remove patch
@@ -9,343 +9,343 @@
 block discarded – undo
9 9
  */
10 10
 class EEM_Payment extends EEM_Base implements EEMI_Payment
11 11
 {
12
-    // private instance of the Payment object
13
-    protected static $_instance = null;
14
-
15
-
16
-    /**
17
-     * Status id in esp_status table that represents an approved payment
18
-     */
19
-    const status_id_approved = 'PAP';
20
-
21
-
22
-    /**
23
-     * Status id in esp_status table that represents a pending payment
24
-     */
25
-    const status_id_pending = 'PPN';
26
-
27
-
28
-    /**
29
-     * Status id in esp_status table that represents a cancelled payment (eg, the
30
-     * user went to PayPal, but on the paypal site decided to cancel the payment)
31
-     */
32
-    const status_id_cancelled = 'PCN';
33
-
34
-
35
-    /**
36
-     * Status id in esp_status table that represents a payment that was declined by
37
-     * the gateway. (eg, the user's card had no funds, or it was a fraudulent card)
38
-     */
39
-    const status_id_declined = 'PDC';
40
-
41
-
42
-    /**
43
-     * Status id in esp_status table that represents a payment that failed for technical reasons.
44
-     * (Eg, there was some error in communicating with the payment gateway.)
45
-     */
46
-    const status_id_failed = 'PFL';
47
-
48
-
49
-    /**
50
-     * @param string|null $timezone string representing the timezone we want to set for returned Date Time Strings (and
51
-     *                              any incoming timezone data that gets saved).  Note this just sends the timezone
52
-     *                              info to the date time model field objects.  Default is NULL (and will be assumed
53
-     *                              using the set timezone in the 'timezone_string' wp option)
54
-     * @throws EE_Error
55
-     * @throws ReflectionException
56
-     */
57
-    protected function __construct(?string $timezone = '')
58
-    {
59
-        $this->singular_item = esc_html__('Payment', 'event_espresso');
60
-        $this->plural_item   = esc_html__('Payments', 'event_espresso');
61
-
62
-        $this->_tables                 = [
63
-            'Payment' => new EE_Primary_Table('esp_payment', 'PAY_ID'),
64
-        ];
65
-        $this->_fields                 = [
66
-            'Payment' => [
67
-                'PAY_ID'               => new EE_Primary_Key_Int_Field(
68
-                    'PAY_ID',
69
-                    esc_html__('Payment ID', 'event_espresso')
70
-                ),
71
-                'TXN_ID'               => new EE_Foreign_Key_Int_Field(
72
-                    'TXN_ID',
73
-                    esc_html__('Transaction ID', 'event_espresso'),
74
-                    false,
75
-                    0,
76
-                    'Transaction'
77
-                ),
78
-                'STS_ID'               => new EE_Foreign_Key_String_Field(
79
-                    'STS_ID',
80
-                    esc_html__('Status ID', 'event_espresso'),
81
-                    false,
82
-                    EEM_Payment::status_id_failed,
83
-                    'Status'
84
-                ),
85
-                'PAY_timestamp'        => new EE_Datetime_Field(
86
-                    'PAY_timestamp',
87
-                    esc_html__(
88
-                        'Timestamp of when payment was attempted',
89
-                        'event_espresso'
90
-                    ),
91
-                    false,
92
-                    EE_Datetime_Field::now,
93
-                    $timezone
94
-                ),
95
-                'PAY_source'           => new EE_All_Caps_Text_Field(
96
-                    'PAY_source',
97
-                    esc_html__(
98
-                        'User-friendly description of payment',
99
-                        'event_espresso'
100
-                    ),
101
-                    false,
102
-                    'CART'
103
-                ),
104
-                'PAY_amount'           => new EE_Money_Field(
105
-                    'PAY_amount',
106
-                    esc_html__('Amount Payment should be for', 'event_espresso'),
107
-                    false,
108
-                    0
109
-                ),
110
-                'PMD_ID'               => new EE_Foreign_Key_Int_Field(
111
-                    'PMD_ID',
112
-                    esc_html__("Payment Method ID", 'event_espresso'),
113
-                    false,
114
-                    null,
115
-                    'Payment_Method'
116
-                ),
117
-                'PAY_gateway_response' => new EE_Plain_Text_Field(
118
-                    'PAY_gateway_response',
119
-                    esc_html__(
120
-                        'Response from Gateway about the payment',
121
-                        'event_espresso'
122
-                    ),
123
-                    false,
124
-                    ''
125
-                ),
126
-                'PAY_txn_id_chq_nmbr'  => new EE_Plain_Text_Field(
127
-                    'PAY_txn_id_chq_nmbr',
128
-                    esc_html__(
129
-                        'Gateway Transaction ID or Cheque Number',
130
-                        'event_espresso'
131
-                    ),
132
-                    true,
133
-                    ''
134
-                ),
135
-                'PAY_po_number'        => new EE_Plain_Text_Field(
136
-                    'PAY_po_number',
137
-                    esc_html__(
138
-                        'Purchase or Sales Number',
139
-                        'event_espresso'
140
-                    ),
141
-                    true,
142
-                    ''
143
-                ),
144
-                'PAY_extra_accntng'    => new EE_Simple_HTML_Field(
145
-                    'PAY_extra_accntng',
146
-                    esc_html__('Extra Account Info', 'event_espresso'),
147
-                    true,
148
-                    ''
149
-                ),
150
-                'PAY_details'          => new EE_Serialized_Text_Field(
151
-                    'PAY_details',
152
-                    esc_html__(
153
-                        'Full Gateway response about payment',
154
-                        'event_espresso'
155
-                    ),
156
-                    true,
157
-                    ''
158
-                ),
159
-                'PAY_redirect_url'     => new EE_Plain_Text_Field(
160
-                    'PAY_redirect_url',
161
-                    esc_html__("Redirect URL", 'event_espresso'),
162
-                    true
163
-                ),
164
-                'PAY_redirect_args'    => new EE_Serialized_Text_Field(
165
-                    'PAY_redirect_args',
166
-                    esc_html__(
167
-                        "Key-Value POST vars to send along with redirect",
168
-                        'event_espresso'
169
-                    ),
170
-                    true
171
-                ),
172
-            ],
173
-        ];
174
-        $this->_model_relations        = [
175
-            'Transaction'          => new EE_Belongs_To_Relation(),
176
-            'Status'               => new EE_Belongs_To_Relation(),
177
-            'Payment_Method'       => new EE_Belongs_To_Relation(),
178
-            'Registration_Payment' => new EE_Has_Many_Relation(),
179
-            'Registration'         => new EE_HABTM_Relation('Registration_Payment'),
180
-        ];
181
-        $this->_model_chain_to_wp_user = 'Payment_Method';
182
-        $this->_caps_slug              = 'transactions';
183
-        parent::__construct($timezone);
184
-    }
185
-
186
-
187
-    /**
188
-     * Gets the payment by the gateway server's unique ID. Eg, the unique ID PayPal assigned
189
-     * to the payment. This is handy for verifying an IPN hasn't already been processed.
190
-     *
191
-     * @param string $PAY_txn_id_chq_nmbr
192
-     * @return EE_Payment
193
-     */
194
-    public function get_payment_by_txn_id_chq_nmbr($PAY_txn_id_chq_nmbr)
195
-    {
196
-        return $this->get_one([['PAY_txn_id_chq_nmbr' => $PAY_txn_id_chq_nmbr]]);
197
-    }
198
-
199
-
200
-    /**
201
-     *       retrieve  all payments from db for a particular transaction, optionally with
202
-     *      a particular status
203
-     *
204
-     * @access     public
205
-     * @param        $TXN_ID
206
-     * @param string $status_of_payment one of EEM_Payment::status_id_*, like 'PAP','PCN',etc. If none is provided,
207
-     *                                  gets payments with any status
208
-     * @return     EE_Payment[]
209
-     */
210
-    public function get_payments_for_transaction($TXN_ID = false, $status_of_payment = null)
211
-    {
212
-        // all payments for a TXN ordered chronologically
213
-        $query_params = [['TXN_ID' => $TXN_ID], 'order_by' => ['PAY_timestamp' => 'ASC']];
214
-        // if provided with a status, search specifically for that status. Otherwise get them all
215
-        if ($status_of_payment) {
216
-            $query_params[0]['STS_ID'] = $status_of_payment;
217
-        }
218
-        // retrieve payments
219
-        return $this->get_all($query_params);
220
-    }
221
-
222
-
223
-    /**
224
-     * Only gets payments which have been approved
225
-     *
226
-     * @param int $TXN_ID
227
-     * @return EE_Payment[]
228
-     */
229
-    public function get_approved_payments_for_transaction($TXN_ID = 0)
230
-    {
231
-        return $this->get_payments_for_transaction($TXN_ID, EEM_Payment::status_id_approved);
232
-    }
233
-
234
-
235
-    /**
236
-     * retrieve  all payments from db between two dates,
237
-     *
238
-     * @param string $start_date        incoming start date. If empty the beginning of today is used.
239
-     * @param string $end_date          incoming end date. If empty the end of today is used.
240
-     * @param string $format            If you include $start_date or $end_date then you must include the format string
241
-     *                                  for the format your date is in.
242
-     * @param string $timezone          If your range is in a different timezone then the current setting on this
243
-     *                                  WordPress install, then include it here.
244
-     * @return EE_Payment[]
245
-     * @throws EE_Error
246
-     */
247
-    public function get_payments_made_between_dates($start_date = '', $end_date = '', $format = '', $timezone = '')
248
-    {
249
-        $timezone = empty($timezone) ? EEH_DTT_Helper::get_timezone() : $timezone;
250
-        // if $start_date or $end date, verify $format is included.
251
-        if ((! empty($start_date) || ! empty($end_date)) && empty($format)) {
252
-            throw new EE_Error(
253
-                esc_html__(
254
-                    'You included a start date and/or a end date for this method but did not include a format string.  The format string is needed for setting up the query',
255
-                    'event_espresso'
256
-                )
257
-            );
258
-        }
259
-        $now = new DateTime('now');
260
-        // setup timezone objects once
261
-        $modelDateTimeZone  = new DateTimeZone($this->_timezone);
262
-        $passedDateTimeZone = new DateTimeZone($timezone);
263
-        // setup start date
264
-        $start_date = ! empty($start_date) ? date_create_from_format($format, $start_date, $passedDateTimeZone) : $now;
265
-        EEH_DTT_Helper::setTimezone($start_date, $modelDateTimeZone);
266
-        $start_date = $start_date->format('Y-m-d') . ' 00:00:00';
267
-        $start_date = strtotime($start_date);
268
-        // setup end date
269
-        $end_date = ! empty($end_date) ? date_create_from_format($format, $end_date, $passedDateTimeZone) : $now;
270
-        EEH_DTT_Helper::setTimezone($end_date, $modelDateTimeZone);
271
-        $end_date = $end_date->format('Y-m-d') . ' 23:59:59';
272
-        $end_date = strtotime($end_date);
273
-
274
-        // make sure our start date is the lowest value and vice versa
275
-        $start = min($start_date, $end_date);
276
-        $end   = max($start_date, $end_date);
277
-
278
-        // yes we generated the date and time string in utc but we WANT this start date and time used in the set timezone on the model.
279
-        $start_date = $this->convert_datetime_for_query(
280
-            'PAY_timestamp',
281
-            date('Y-m-d', $start) . ' 00:00:00',
282
-            'Y-m-d H:i:s',
283
-            $this->get_timezone()
284
-        );
285
-        $end_date   = $this->convert_datetime_for_query(
286
-            'PAY_timestamp',
287
-            date('Y-m-d', $end) . ' 23:59:59',
288
-            'Y-m-d H:i:s',
289
-            $this->get_timezone()
290
-        );
291
-
292
-        return $this->get_all([['PAY_timestamp' => ['>=', $start_date], 'PAY_timestamp*' => ['<=', $end_date]]]);
293
-    }
294
-
295
-    /**
296
-     * methods for EEMI_Payment
297
-     */
298
-    /**
299
-     * returns a string for the approved status
300
-     *
301
-     * @return  string
302
-     */
303
-    public function approved_status()
304
-    {
305
-        return self::status_id_approved;
306
-    }
307
-
308
-
309
-    /**
310
-     * returns a string for the pending status
311
-     *
312
-     * @return  string
313
-     */
314
-    public function pending_status()
315
-    {
316
-        return self::status_id_pending;
317
-    }
318
-
319
-
320
-    /**
321
-     * returns a string for the cancelled status
322
-     *
323
-     * @return  string
324
-     */
325
-    public function cancelled_status()
326
-    {
327
-        return self::status_id_cancelled;
328
-    }
329
-
330
-
331
-    /**
332
-     * returns a string for the failed status
333
-     *
334
-     * @return  string
335
-     */
336
-    public function failed_status()
337
-    {
338
-        return self::status_id_failed;
339
-    }
340
-
341
-
342
-    /**
343
-     * returns a string for the declined status
344
-     *
345
-     * @return  string
346
-     */
347
-    public function declined_status()
348
-    {
349
-        return self::status_id_declined;
350
-    }
12
+	// private instance of the Payment object
13
+	protected static $_instance = null;
14
+
15
+
16
+	/**
17
+	 * Status id in esp_status table that represents an approved payment
18
+	 */
19
+	const status_id_approved = 'PAP';
20
+
21
+
22
+	/**
23
+	 * Status id in esp_status table that represents a pending payment
24
+	 */
25
+	const status_id_pending = 'PPN';
26
+
27
+
28
+	/**
29
+	 * Status id in esp_status table that represents a cancelled payment (eg, the
30
+	 * user went to PayPal, but on the paypal site decided to cancel the payment)
31
+	 */
32
+	const status_id_cancelled = 'PCN';
33
+
34
+
35
+	/**
36
+	 * Status id in esp_status table that represents a payment that was declined by
37
+	 * the gateway. (eg, the user's card had no funds, or it was a fraudulent card)
38
+	 */
39
+	const status_id_declined = 'PDC';
40
+
41
+
42
+	/**
43
+	 * Status id in esp_status table that represents a payment that failed for technical reasons.
44
+	 * (Eg, there was some error in communicating with the payment gateway.)
45
+	 */
46
+	const status_id_failed = 'PFL';
47
+
48
+
49
+	/**
50
+	 * @param string|null $timezone string representing the timezone we want to set for returned Date Time Strings (and
51
+	 *                              any incoming timezone data that gets saved).  Note this just sends the timezone
52
+	 *                              info to the date time model field objects.  Default is NULL (and will be assumed
53
+	 *                              using the set timezone in the 'timezone_string' wp option)
54
+	 * @throws EE_Error
55
+	 * @throws ReflectionException
56
+	 */
57
+	protected function __construct(?string $timezone = '')
58
+	{
59
+		$this->singular_item = esc_html__('Payment', 'event_espresso');
60
+		$this->plural_item   = esc_html__('Payments', 'event_espresso');
61
+
62
+		$this->_tables                 = [
63
+			'Payment' => new EE_Primary_Table('esp_payment', 'PAY_ID'),
64
+		];
65
+		$this->_fields                 = [
66
+			'Payment' => [
67
+				'PAY_ID'               => new EE_Primary_Key_Int_Field(
68
+					'PAY_ID',
69
+					esc_html__('Payment ID', 'event_espresso')
70
+				),
71
+				'TXN_ID'               => new EE_Foreign_Key_Int_Field(
72
+					'TXN_ID',
73
+					esc_html__('Transaction ID', 'event_espresso'),
74
+					false,
75
+					0,
76
+					'Transaction'
77
+				),
78
+				'STS_ID'               => new EE_Foreign_Key_String_Field(
79
+					'STS_ID',
80
+					esc_html__('Status ID', 'event_espresso'),
81
+					false,
82
+					EEM_Payment::status_id_failed,
83
+					'Status'
84
+				),
85
+				'PAY_timestamp'        => new EE_Datetime_Field(
86
+					'PAY_timestamp',
87
+					esc_html__(
88
+						'Timestamp of when payment was attempted',
89
+						'event_espresso'
90
+					),
91
+					false,
92
+					EE_Datetime_Field::now,
93
+					$timezone
94
+				),
95
+				'PAY_source'           => new EE_All_Caps_Text_Field(
96
+					'PAY_source',
97
+					esc_html__(
98
+						'User-friendly description of payment',
99
+						'event_espresso'
100
+					),
101
+					false,
102
+					'CART'
103
+				),
104
+				'PAY_amount'           => new EE_Money_Field(
105
+					'PAY_amount',
106
+					esc_html__('Amount Payment should be for', 'event_espresso'),
107
+					false,
108
+					0
109
+				),
110
+				'PMD_ID'               => new EE_Foreign_Key_Int_Field(
111
+					'PMD_ID',
112
+					esc_html__("Payment Method ID", 'event_espresso'),
113
+					false,
114
+					null,
115
+					'Payment_Method'
116
+				),
117
+				'PAY_gateway_response' => new EE_Plain_Text_Field(
118
+					'PAY_gateway_response',
119
+					esc_html__(
120
+						'Response from Gateway about the payment',
121
+						'event_espresso'
122
+					),
123
+					false,
124
+					''
125
+				),
126
+				'PAY_txn_id_chq_nmbr'  => new EE_Plain_Text_Field(
127
+					'PAY_txn_id_chq_nmbr',
128
+					esc_html__(
129
+						'Gateway Transaction ID or Cheque Number',
130
+						'event_espresso'
131
+					),
132
+					true,
133
+					''
134
+				),
135
+				'PAY_po_number'        => new EE_Plain_Text_Field(
136
+					'PAY_po_number',
137
+					esc_html__(
138
+						'Purchase or Sales Number',
139
+						'event_espresso'
140
+					),
141
+					true,
142
+					''
143
+				),
144
+				'PAY_extra_accntng'    => new EE_Simple_HTML_Field(
145
+					'PAY_extra_accntng',
146
+					esc_html__('Extra Account Info', 'event_espresso'),
147
+					true,
148
+					''
149
+				),
150
+				'PAY_details'          => new EE_Serialized_Text_Field(
151
+					'PAY_details',
152
+					esc_html__(
153
+						'Full Gateway response about payment',
154
+						'event_espresso'
155
+					),
156
+					true,
157
+					''
158
+				),
159
+				'PAY_redirect_url'     => new EE_Plain_Text_Field(
160
+					'PAY_redirect_url',
161
+					esc_html__("Redirect URL", 'event_espresso'),
162
+					true
163
+				),
164
+				'PAY_redirect_args'    => new EE_Serialized_Text_Field(
165
+					'PAY_redirect_args',
166
+					esc_html__(
167
+						"Key-Value POST vars to send along with redirect",
168
+						'event_espresso'
169
+					),
170
+					true
171
+				),
172
+			],
173
+		];
174
+		$this->_model_relations        = [
175
+			'Transaction'          => new EE_Belongs_To_Relation(),
176
+			'Status'               => new EE_Belongs_To_Relation(),
177
+			'Payment_Method'       => new EE_Belongs_To_Relation(),
178
+			'Registration_Payment' => new EE_Has_Many_Relation(),
179
+			'Registration'         => new EE_HABTM_Relation('Registration_Payment'),
180
+		];
181
+		$this->_model_chain_to_wp_user = 'Payment_Method';
182
+		$this->_caps_slug              = 'transactions';
183
+		parent::__construct($timezone);
184
+	}
185
+
186
+
187
+	/**
188
+	 * Gets the payment by the gateway server's unique ID. Eg, the unique ID PayPal assigned
189
+	 * to the payment. This is handy for verifying an IPN hasn't already been processed.
190
+	 *
191
+	 * @param string $PAY_txn_id_chq_nmbr
192
+	 * @return EE_Payment
193
+	 */
194
+	public function get_payment_by_txn_id_chq_nmbr($PAY_txn_id_chq_nmbr)
195
+	{
196
+		return $this->get_one([['PAY_txn_id_chq_nmbr' => $PAY_txn_id_chq_nmbr]]);
197
+	}
198
+
199
+
200
+	/**
201
+	 *       retrieve  all payments from db for a particular transaction, optionally with
202
+	 *      a particular status
203
+	 *
204
+	 * @access     public
205
+	 * @param        $TXN_ID
206
+	 * @param string $status_of_payment one of EEM_Payment::status_id_*, like 'PAP','PCN',etc. If none is provided,
207
+	 *                                  gets payments with any status
208
+	 * @return     EE_Payment[]
209
+	 */
210
+	public function get_payments_for_transaction($TXN_ID = false, $status_of_payment = null)
211
+	{
212
+		// all payments for a TXN ordered chronologically
213
+		$query_params = [['TXN_ID' => $TXN_ID], 'order_by' => ['PAY_timestamp' => 'ASC']];
214
+		// if provided with a status, search specifically for that status. Otherwise get them all
215
+		if ($status_of_payment) {
216
+			$query_params[0]['STS_ID'] = $status_of_payment;
217
+		}
218
+		// retrieve payments
219
+		return $this->get_all($query_params);
220
+	}
221
+
222
+
223
+	/**
224
+	 * Only gets payments which have been approved
225
+	 *
226
+	 * @param int $TXN_ID
227
+	 * @return EE_Payment[]
228
+	 */
229
+	public function get_approved_payments_for_transaction($TXN_ID = 0)
230
+	{
231
+		return $this->get_payments_for_transaction($TXN_ID, EEM_Payment::status_id_approved);
232
+	}
233
+
234
+
235
+	/**
236
+	 * retrieve  all payments from db between two dates,
237
+	 *
238
+	 * @param string $start_date        incoming start date. If empty the beginning of today is used.
239
+	 * @param string $end_date          incoming end date. If empty the end of today is used.
240
+	 * @param string $format            If you include $start_date or $end_date then you must include the format string
241
+	 *                                  for the format your date is in.
242
+	 * @param string $timezone          If your range is in a different timezone then the current setting on this
243
+	 *                                  WordPress install, then include it here.
244
+	 * @return EE_Payment[]
245
+	 * @throws EE_Error
246
+	 */
247
+	public function get_payments_made_between_dates($start_date = '', $end_date = '', $format = '', $timezone = '')
248
+	{
249
+		$timezone = empty($timezone) ? EEH_DTT_Helper::get_timezone() : $timezone;
250
+		// if $start_date or $end date, verify $format is included.
251
+		if ((! empty($start_date) || ! empty($end_date)) && empty($format)) {
252
+			throw new EE_Error(
253
+				esc_html__(
254
+					'You included a start date and/or a end date for this method but did not include a format string.  The format string is needed for setting up the query',
255
+					'event_espresso'
256
+				)
257
+			);
258
+		}
259
+		$now = new DateTime('now');
260
+		// setup timezone objects once
261
+		$modelDateTimeZone  = new DateTimeZone($this->_timezone);
262
+		$passedDateTimeZone = new DateTimeZone($timezone);
263
+		// setup start date
264
+		$start_date = ! empty($start_date) ? date_create_from_format($format, $start_date, $passedDateTimeZone) : $now;
265
+		EEH_DTT_Helper::setTimezone($start_date, $modelDateTimeZone);
266
+		$start_date = $start_date->format('Y-m-d') . ' 00:00:00';
267
+		$start_date = strtotime($start_date);
268
+		// setup end date
269
+		$end_date = ! empty($end_date) ? date_create_from_format($format, $end_date, $passedDateTimeZone) : $now;
270
+		EEH_DTT_Helper::setTimezone($end_date, $modelDateTimeZone);
271
+		$end_date = $end_date->format('Y-m-d') . ' 23:59:59';
272
+		$end_date = strtotime($end_date);
273
+
274
+		// make sure our start date is the lowest value and vice versa
275
+		$start = min($start_date, $end_date);
276
+		$end   = max($start_date, $end_date);
277
+
278
+		// yes we generated the date and time string in utc but we WANT this start date and time used in the set timezone on the model.
279
+		$start_date = $this->convert_datetime_for_query(
280
+			'PAY_timestamp',
281
+			date('Y-m-d', $start) . ' 00:00:00',
282
+			'Y-m-d H:i:s',
283
+			$this->get_timezone()
284
+		);
285
+		$end_date   = $this->convert_datetime_for_query(
286
+			'PAY_timestamp',
287
+			date('Y-m-d', $end) . ' 23:59:59',
288
+			'Y-m-d H:i:s',
289
+			$this->get_timezone()
290
+		);
291
+
292
+		return $this->get_all([['PAY_timestamp' => ['>=', $start_date], 'PAY_timestamp*' => ['<=', $end_date]]]);
293
+	}
294
+
295
+	/**
296
+	 * methods for EEMI_Payment
297
+	 */
298
+	/**
299
+	 * returns a string for the approved status
300
+	 *
301
+	 * @return  string
302
+	 */
303
+	public function approved_status()
304
+	{
305
+		return self::status_id_approved;
306
+	}
307
+
308
+
309
+	/**
310
+	 * returns a string for the pending status
311
+	 *
312
+	 * @return  string
313
+	 */
314
+	public function pending_status()
315
+	{
316
+		return self::status_id_pending;
317
+	}
318
+
319
+
320
+	/**
321
+	 * returns a string for the cancelled status
322
+	 *
323
+	 * @return  string
324
+	 */
325
+	public function cancelled_status()
326
+	{
327
+		return self::status_id_cancelled;
328
+	}
329
+
330
+
331
+	/**
332
+	 * returns a string for the failed status
333
+	 *
334
+	 * @return  string
335
+	 */
336
+	public function failed_status()
337
+	{
338
+		return self::status_id_failed;
339
+	}
340
+
341
+
342
+	/**
343
+	 * returns a string for the declined status
344
+	 *
345
+	 * @return  string
346
+	 */
347
+	public function declined_status()
348
+	{
349
+		return self::status_id_declined;
350
+	}
351 351
 }
Please login to merge, or discard this patch.
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -171,7 +171,7 @@  discard block
 block discarded – undo
171 171
                 ),
172 172
             ],
173 173
         ];
174
-        $this->_model_relations        = [
174
+        $this->_model_relations = [
175 175
             'Transaction'          => new EE_Belongs_To_Relation(),
176 176
             'Status'               => new EE_Belongs_To_Relation(),
177 177
             'Payment_Method'       => new EE_Belongs_To_Relation(),
@@ -248,7 +248,7 @@  discard block
 block discarded – undo
248 248
     {
249 249
         $timezone = empty($timezone) ? EEH_DTT_Helper::get_timezone() : $timezone;
250 250
         // if $start_date or $end date, verify $format is included.
251
-        if ((! empty($start_date) || ! empty($end_date)) && empty($format)) {
251
+        if (( ! empty($start_date) || ! empty($end_date)) && empty($format)) {
252 252
             throw new EE_Error(
253 253
                 esc_html__(
254 254
                     'You included a start date and/or a end date for this method but did not include a format string.  The format string is needed for setting up the query',
@@ -263,12 +263,12 @@  discard block
 block discarded – undo
263 263
         // setup start date
264 264
         $start_date = ! empty($start_date) ? date_create_from_format($format, $start_date, $passedDateTimeZone) : $now;
265 265
         EEH_DTT_Helper::setTimezone($start_date, $modelDateTimeZone);
266
-        $start_date = $start_date->format('Y-m-d') . ' 00:00:00';
266
+        $start_date = $start_date->format('Y-m-d').' 00:00:00';
267 267
         $start_date = strtotime($start_date);
268 268
         // setup end date
269 269
         $end_date = ! empty($end_date) ? date_create_from_format($format, $end_date, $passedDateTimeZone) : $now;
270 270
         EEH_DTT_Helper::setTimezone($end_date, $modelDateTimeZone);
271
-        $end_date = $end_date->format('Y-m-d') . ' 23:59:59';
271
+        $end_date = $end_date->format('Y-m-d').' 23:59:59';
272 272
         $end_date = strtotime($end_date);
273 273
 
274 274
         // make sure our start date is the lowest value and vice versa
@@ -278,13 +278,13 @@  discard block
 block discarded – undo
278 278
         // yes we generated the date and time string in utc but we WANT this start date and time used in the set timezone on the model.
279 279
         $start_date = $this->convert_datetime_for_query(
280 280
             'PAY_timestamp',
281
-            date('Y-m-d', $start) . ' 00:00:00',
281
+            date('Y-m-d', $start).' 00:00:00',
282 282
             'Y-m-d H:i:s',
283 283
             $this->get_timezone()
284 284
         );
285
-        $end_date   = $this->convert_datetime_for_query(
285
+        $end_date = $this->convert_datetime_for_query(
286 286
             'PAY_timestamp',
287
-            date('Y-m-d', $end) . ' 23:59:59',
287
+            date('Y-m-d', $end).' 23:59:59',
288 288
             'Y-m-d H:i:s',
289 289
             $this->get_timezone()
290 290
         );
Please login to merge, or discard this patch.
core/db_models/EEM_Question_Option.model.php 1 patch
Indentation   +74 added lines, -74 removed lines patch added patch discarded remove patch
@@ -9,84 +9,84 @@
 block discarded – undo
9 9
  */
10 10
 class EEM_Question_Option extends EEM_Soft_Delete_Base
11 11
 {
12
-    // private instance of the Attendee object
13
-    protected static $_instance = null;
12
+	// private instance of the Attendee object
13
+	protected static $_instance = null;
14 14
 
15 15
 
16
-    /**
17
-     * @param string|null $timezone
18
-     * @throws EE_Error
19
-     */
20
-    protected function __construct(?string $timezone = '')
21
-    {
22
-        $this->singular_item = esc_html__('Question Option', 'event_espresso');
23
-        $this->plural_item   = esc_html__('Question Options', 'event_espresso');
16
+	/**
17
+	 * @param string|null $timezone
18
+	 * @throws EE_Error
19
+	 */
20
+	protected function __construct(?string $timezone = '')
21
+	{
22
+		$this->singular_item = esc_html__('Question Option', 'event_espresso');
23
+		$this->plural_item   = esc_html__('Question Options', 'event_espresso');
24 24
 
25
-        $this->_tables          = [
26
-            'Question_Option' => new EE_Primary_Table('esp_question_option', 'QSO_ID'),
27
-        ];
28
-        $this->_fields          = [
29
-            'Question_Option' => [
30
-                'QSO_ID'      => new EE_Primary_Key_Int_Field(
31
-                    'QSO_ID',
32
-                    esc_html__('Question Option ID', 'event_espresso')
33
-                ),
34
-                'QST_ID'      => new EE_Foreign_Key_Int_Field(
35
-                    'QST_ID',
36
-                    esc_html__('Question ID', 'event_espresso'),
37
-                    false,
38
-                    0,
39
-                    'Question'
40
-                ),
41
-                'QSO_deleted' => new EE_Trashed_Flag_Field(
42
-                    'QSO_deleted',
43
-                    esc_html__('Flag indicating Option was trashed', 'event_espresso'),
44
-                    false,
45
-                    false
46
-                ),
47
-                'QSO_desc'    => new EE_Post_Content_Field(
48
-                    'QSO_desc',
49
-                    esc_html__('Question Option Description', 'event_espresso'),
50
-                    false,
51
-                    ''
52
-                ),
53
-                'QSO_order'   => new EE_Integer_Field(
54
-                    'QSO_order',
55
-                    esc_html__('Question Option Order', 'event_espresso'),
56
-                    false,
57
-                    0
58
-                ),
59
-                'QSO_system'  => new EE_Plain_Text_Field(
60
-                    'QSO_system',
61
-                    esc_html__('Internal string ID for question option', 'event_espresso'),
62
-                    true,
63
-                    null
64
-                ),
65
-                'QSO_value'   => new EE_Plain_Text_Field(
66
-                    'QSO_value',
67
-                    esc_html__("Question Option Value", "event_espresso"),
68
-                    false,
69
-                    ''
70
-                ),
71
-            ],
72
-        ];
73
-        $this->_model_relations = [
74
-            'Question' => new EE_Belongs_To_Relation(),
75
-        ];
25
+		$this->_tables          = [
26
+			'Question_Option' => new EE_Primary_Table('esp_question_option', 'QSO_ID'),
27
+		];
28
+		$this->_fields          = [
29
+			'Question_Option' => [
30
+				'QSO_ID'      => new EE_Primary_Key_Int_Field(
31
+					'QSO_ID',
32
+					esc_html__('Question Option ID', 'event_espresso')
33
+				),
34
+				'QST_ID'      => new EE_Foreign_Key_Int_Field(
35
+					'QST_ID',
36
+					esc_html__('Question ID', 'event_espresso'),
37
+					false,
38
+					0,
39
+					'Question'
40
+				),
41
+				'QSO_deleted' => new EE_Trashed_Flag_Field(
42
+					'QSO_deleted',
43
+					esc_html__('Flag indicating Option was trashed', 'event_espresso'),
44
+					false,
45
+					false
46
+				),
47
+				'QSO_desc'    => new EE_Post_Content_Field(
48
+					'QSO_desc',
49
+					esc_html__('Question Option Description', 'event_espresso'),
50
+					false,
51
+					''
52
+				),
53
+				'QSO_order'   => new EE_Integer_Field(
54
+					'QSO_order',
55
+					esc_html__('Question Option Order', 'event_espresso'),
56
+					false,
57
+					0
58
+				),
59
+				'QSO_system'  => new EE_Plain_Text_Field(
60
+					'QSO_system',
61
+					esc_html__('Internal string ID for question option', 'event_espresso'),
62
+					true,
63
+					null
64
+				),
65
+				'QSO_value'   => new EE_Plain_Text_Field(
66
+					'QSO_value',
67
+					esc_html__("Question Option Value", "event_espresso"),
68
+					false,
69
+					''
70
+				),
71
+			],
72
+		];
73
+		$this->_model_relations = [
74
+			'Question' => new EE_Belongs_To_Relation(),
75
+		];
76 76
 
77
-        $this->_caps_slug              = 'questions';
78
-        $this->_model_chain_to_wp_user = 'Question';
77
+		$this->_caps_slug              = 'questions';
78
+		$this->_model_chain_to_wp_user = 'Question';
79 79
 
80
-        // this model is generally available for reading
81
-        $this->_cap_restriction_generators[ EEM_Base::caps_read ]       =
82
-            new EE_Restriction_Generator_Public();
83
-        $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] =
84
-            new EE_Restriction_Generator_Reg_Form('QSO_system');
85
-        $this->_cap_restriction_generators[ EEM_Base::caps_edit ]       =
86
-            new EE_Restriction_Generator_Reg_Form('QSO_system');
87
-        $this->_cap_restriction_generators[ EEM_Base::caps_delete ]     =
88
-            new EE_Restriction_Generator_Reg_Form('QSO_system');
80
+		// this model is generally available for reading
81
+		$this->_cap_restriction_generators[ EEM_Base::caps_read ]       =
82
+			new EE_Restriction_Generator_Public();
83
+		$this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] =
84
+			new EE_Restriction_Generator_Reg_Form('QSO_system');
85
+		$this->_cap_restriction_generators[ EEM_Base::caps_edit ]       =
86
+			new EE_Restriction_Generator_Reg_Form('QSO_system');
87
+		$this->_cap_restriction_generators[ EEM_Base::caps_delete ]     =
88
+			new EE_Restriction_Generator_Reg_Form('QSO_system');
89 89
 
90
-        parent::__construct($timezone);
91
-    }
90
+		parent::__construct($timezone);
91
+	}
92 92
 }
Please login to merge, or discard this patch.
core/db_models/EEM_Price_Type.model.php 2 patches
Indentation   +198 added lines, -198 removed lines patch added patch discarded remove patch
@@ -10,202 +10,202 @@
 block discarded – undo
10 10
  */
11 11
 class EEM_Price_Type extends EEM_Soft_Delete_Base
12 12
 {
13
-    // private instance of the Price Type object
14
-    protected static $_instance = null;
15
-
16
-    // An array of the price type objects
17
-    public $type = null;
18
-
19
-    /**
20
-     *   Price Base types
21
-     *
22
-     * @access private
23
-     * @var int
24
-     */
25
-    public $base_types = null;
26
-
27
-
28
-    /**
29
-     * return an array of Base types. Keys are INTs which are used in the database,
30
-     * values are text-representations of the base type.
31
-     *
32
-     * @return array
33
-     */
34
-    public function get_base_types()
35
-    {
36
-        return $this->base_types;
37
-    }
38
-
39
-
40
-    /**
41
-     * Gets the name of the base
42
-     *
43
-     * @param type $base_type_int
44
-     * @return type
45
-     */
46
-    public function get_base_type_name($base_type_int)
47
-    {
48
-        return $this->base_types[ $base_type_int ];
49
-    }
50
-
51
-
52
-    /**
53
-     * constants for price base types. In the DB, we decided to store the price base type
54
-     * as an integer. So, to avoid just having magic numbers everwhere (eg, querying for
55
-     * all price types with PBT_ID = 2), we define these constants, to make code more understandable.
56
-     * So, as an example, to query for all price types that are a tax, we'd do
57
-     * EEM_PRice_Type::instance()->get_all(array(array('PBT_ID'=>EEM_Price_Type::base_type_tax)))
58
-     * instead of
59
-     * EEM_Price_Type::instance()->get_all(array(array('PBT_ID'=>2)))
60
-     * Although the 2nd is shorter, it's much less obvious what it's doing. Also, should these magic IDs ever
61
-     * change, we can continue to use the constant, by simply change its value.
62
-     */
63
-    const base_type_base_price = 1;
64
-
65
-    const base_type_discount   = 2;
66
-
67
-    const base_type_surcharge  = 3;
68
-
69
-    const base_type_tax        = 4;
70
-
71
-
72
-    /**
73
-     * private constructor to prevent direct creation
74
-     *
75
-     * @param string|null $timezone
76
-     * @return void
77
-     * @throws EE_Error
78
-     */
79
-    protected function __construct(?string $timezone = '')
80
-    {
81
-        $this->base_types    = [
82
-            EEM_Price_Type::base_type_base_price => esc_html__('Price', 'event_espresso'),
83
-            EEM_Price_Type::base_type_discount   => esc_html__('Discount', 'event_espresso'),
84
-            EEM_Price_Type::base_type_surcharge  => esc_html__('Surcharge', 'event_espresso'),
85
-            EEM_Price_Type::base_type_tax        => esc_html__('Tax', 'event_espresso'),
86
-        ];
87
-        $this->singular_item = esc_html__('Price Type', 'event_espresso');
88
-        $this->plural_item   = esc_html__('Price Types', 'event_espresso');
89
-
90
-        $this->_tables          = [
91
-            'Price_Type' => new EE_Primary_Table('esp_price_type', 'PRT_ID'),
92
-        ];
93
-        $this->_fields          = [
94
-            'Price_Type' => [
95
-                'PRT_ID'         => new EE_Primary_Key_Int_Field(
96
-                    'PRT_ID', esc_html__('Price Type ID', 'event_espresso')
97
-                ),
98
-                'PRT_name'       => new EE_Plain_Text_Field(
99
-                    'PRT_name',
100
-                    esc_html__('Price Type Name', 'event_espresso'),
101
-                    false,
102
-                    ''
103
-                ),
104
-                'PBT_ID'         => new EE_Enum_Integer_Field(
105
-                    'PBT_ID',
106
-                    esc_html__(
107
-                        'Price Base type ID, 1 = Price , 2 = Discount , 3 = Surcharge , 4 = Tax',
108
-                        'event_espresso'
109
-                    ),
110
-                    false,
111
-                    EEM_Price_Type::base_type_base_price,
112
-                    $this->base_types
113
-                ),
114
-                'PRT_is_percent' => new EE_Boolean_Field(
115
-                    'PRT_is_percent',
116
-                    esc_html__(
117
-                        'Flag indicating price is a percentage',
118
-                        'event_espresso'
119
-                    ),
120
-                    false,
121
-                    false
122
-                ),
123
-                'PRT_order'      => new EE_Integer_Field(
124
-                    'PRT_order',
125
-                    esc_html__(
126
-                        'Order in which price should be applied. ',
127
-                        'event_espresso'
128
-                    ),
129
-                    false,
130
-                    0
131
-                ),
132
-                'PRT_deleted'    => new EE_Trashed_Flag_Field(
133
-                    'PRT_deleted',
134
-                    esc_html__(
135
-                        'Flag indicating price type has been trashed',
136
-                        'event_espresso'
137
-                    ),
138
-                    false,
139
-                    false
140
-                ),
141
-                'PRT_wp_user'    => new EE_WP_User_Field(
142
-                    'PRT_wp_user',
143
-                    esc_html__('Price Type Creator ID', 'event_espresso'),
144
-                    false
145
-                ),
146
-            ],
147
-        ];
148
-        $this->_model_relations = [
149
-            'Price'   => new EE_Has_Many_Relation(),
150
-            'WP_User' => new EE_Belongs_To_Relation(),
151
-        ];
152
-        // this model is generally available for reading
153
-        $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public();
154
-        // all price types are "default" in terms of capability names
155
-        $this->_caps_slug = 'default_price_types';
156
-        parent::__construct($timezone);
157
-    }
158
-
159
-
160
-    /**
161
-     *      instantiate a new price type object with blank/empty properties
162
-     *
163
-     * @access     public
164
-     * @return     mixed       array on success, FALSE on fail
165
-     */
166
-    public function get_new_price_type()
167
-    {
168
-        return EE_Price_Type::new_instance();
169
-    }
170
-
171
-
172
-    /**
173
-     * @param array $query_params
174
-     * @param bool  $allow_blocking   if TRUE, matched objects will only be deleted if there is no related model info
175
-     *                                that blocks it (ie, there' sno other data that depends on this data);
176
-     *                                if false, deletes regardless of other objects which may depend on it.
177
-     *                                Its generally advisable to always leave this as TRUE,
178
-     *                                otherwise you could easily corrupt your DB
179
-     * @return bool
180
-     * @throws EE_Error
181
-     * @throws ReflectionException
182
-     */
183
-    public function delete_permanently($query_params = [], $allow_blocking = true)
184
-    {
185
-        $would_be_deleted_price_types    = $this->get_all_deleted_and_undeleted($query_params);
186
-        $would_be_deleted_price_type_ids = array_keys($would_be_deleted_price_types);
187
-
188
-        $ID = $query_params[0][ $this->get_primary_key_field()->get_name() ];
189
-
190
-        // check if any prices use this price type
191
-        $prc_query_params = [['PRT_ID' => ['IN', $would_be_deleted_price_type_ids]]];
192
-        if ($prices = $this->get_all_related($ID, 'Price', $prc_query_params)) {
193
-            $prices_names_and_ids = [];
194
-            foreach ($prices as $price) {
195
-                /* @var $price EE_Price */
196
-                $prices_names_and_ids[] = $price->name() . "(" . $price->ID() . ")";
197
-            }
198
-            $msg = sprintf(
199
-                esc_html__(
200
-                    'The Price Type(s) could not be deleted because there are existing Prices that currently use this Price Type.  If you still wish to delete this Price Type, then either delete those Prices or change them to use other Price Types.The prices are: %s',
201
-                    'event_espresso'
202
-                ),
203
-                implode(",", $prices_names_and_ids)
204
-            );
205
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
206
-            return false;
207
-        }
208
-
209
-        return parent::delete_permanently($query_params);
210
-    }
13
+	// private instance of the Price Type object
14
+	protected static $_instance = null;
15
+
16
+	// An array of the price type objects
17
+	public $type = null;
18
+
19
+	/**
20
+	 *   Price Base types
21
+	 *
22
+	 * @access private
23
+	 * @var int
24
+	 */
25
+	public $base_types = null;
26
+
27
+
28
+	/**
29
+	 * return an array of Base types. Keys are INTs which are used in the database,
30
+	 * values are text-representations of the base type.
31
+	 *
32
+	 * @return array
33
+	 */
34
+	public function get_base_types()
35
+	{
36
+		return $this->base_types;
37
+	}
38
+
39
+
40
+	/**
41
+	 * Gets the name of the base
42
+	 *
43
+	 * @param type $base_type_int
44
+	 * @return type
45
+	 */
46
+	public function get_base_type_name($base_type_int)
47
+	{
48
+		return $this->base_types[ $base_type_int ];
49
+	}
50
+
51
+
52
+	/**
53
+	 * constants for price base types. In the DB, we decided to store the price base type
54
+	 * as an integer. So, to avoid just having magic numbers everwhere (eg, querying for
55
+	 * all price types with PBT_ID = 2), we define these constants, to make code more understandable.
56
+	 * So, as an example, to query for all price types that are a tax, we'd do
57
+	 * EEM_PRice_Type::instance()->get_all(array(array('PBT_ID'=>EEM_Price_Type::base_type_tax)))
58
+	 * instead of
59
+	 * EEM_Price_Type::instance()->get_all(array(array('PBT_ID'=>2)))
60
+	 * Although the 2nd is shorter, it's much less obvious what it's doing. Also, should these magic IDs ever
61
+	 * change, we can continue to use the constant, by simply change its value.
62
+	 */
63
+	const base_type_base_price = 1;
64
+
65
+	const base_type_discount   = 2;
66
+
67
+	const base_type_surcharge  = 3;
68
+
69
+	const base_type_tax        = 4;
70
+
71
+
72
+	/**
73
+	 * private constructor to prevent direct creation
74
+	 *
75
+	 * @param string|null $timezone
76
+	 * @return void
77
+	 * @throws EE_Error
78
+	 */
79
+	protected function __construct(?string $timezone = '')
80
+	{
81
+		$this->base_types    = [
82
+			EEM_Price_Type::base_type_base_price => esc_html__('Price', 'event_espresso'),
83
+			EEM_Price_Type::base_type_discount   => esc_html__('Discount', 'event_espresso'),
84
+			EEM_Price_Type::base_type_surcharge  => esc_html__('Surcharge', 'event_espresso'),
85
+			EEM_Price_Type::base_type_tax        => esc_html__('Tax', 'event_espresso'),
86
+		];
87
+		$this->singular_item = esc_html__('Price Type', 'event_espresso');
88
+		$this->plural_item   = esc_html__('Price Types', 'event_espresso');
89
+
90
+		$this->_tables          = [
91
+			'Price_Type' => new EE_Primary_Table('esp_price_type', 'PRT_ID'),
92
+		];
93
+		$this->_fields          = [
94
+			'Price_Type' => [
95
+				'PRT_ID'         => new EE_Primary_Key_Int_Field(
96
+					'PRT_ID', esc_html__('Price Type ID', 'event_espresso')
97
+				),
98
+				'PRT_name'       => new EE_Plain_Text_Field(
99
+					'PRT_name',
100
+					esc_html__('Price Type Name', 'event_espresso'),
101
+					false,
102
+					''
103
+				),
104
+				'PBT_ID'         => new EE_Enum_Integer_Field(
105
+					'PBT_ID',
106
+					esc_html__(
107
+						'Price Base type ID, 1 = Price , 2 = Discount , 3 = Surcharge , 4 = Tax',
108
+						'event_espresso'
109
+					),
110
+					false,
111
+					EEM_Price_Type::base_type_base_price,
112
+					$this->base_types
113
+				),
114
+				'PRT_is_percent' => new EE_Boolean_Field(
115
+					'PRT_is_percent',
116
+					esc_html__(
117
+						'Flag indicating price is a percentage',
118
+						'event_espresso'
119
+					),
120
+					false,
121
+					false
122
+				),
123
+				'PRT_order'      => new EE_Integer_Field(
124
+					'PRT_order',
125
+					esc_html__(
126
+						'Order in which price should be applied. ',
127
+						'event_espresso'
128
+					),
129
+					false,
130
+					0
131
+				),
132
+				'PRT_deleted'    => new EE_Trashed_Flag_Field(
133
+					'PRT_deleted',
134
+					esc_html__(
135
+						'Flag indicating price type has been trashed',
136
+						'event_espresso'
137
+					),
138
+					false,
139
+					false
140
+				),
141
+				'PRT_wp_user'    => new EE_WP_User_Field(
142
+					'PRT_wp_user',
143
+					esc_html__('Price Type Creator ID', 'event_espresso'),
144
+					false
145
+				),
146
+			],
147
+		];
148
+		$this->_model_relations = [
149
+			'Price'   => new EE_Has_Many_Relation(),
150
+			'WP_User' => new EE_Belongs_To_Relation(),
151
+		];
152
+		// this model is generally available for reading
153
+		$this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public();
154
+		// all price types are "default" in terms of capability names
155
+		$this->_caps_slug = 'default_price_types';
156
+		parent::__construct($timezone);
157
+	}
158
+
159
+
160
+	/**
161
+	 *      instantiate a new price type object with blank/empty properties
162
+	 *
163
+	 * @access     public
164
+	 * @return     mixed       array on success, FALSE on fail
165
+	 */
166
+	public function get_new_price_type()
167
+	{
168
+		return EE_Price_Type::new_instance();
169
+	}
170
+
171
+
172
+	/**
173
+	 * @param array $query_params
174
+	 * @param bool  $allow_blocking   if TRUE, matched objects will only be deleted if there is no related model info
175
+	 *                                that blocks it (ie, there' sno other data that depends on this data);
176
+	 *                                if false, deletes regardless of other objects which may depend on it.
177
+	 *                                Its generally advisable to always leave this as TRUE,
178
+	 *                                otherwise you could easily corrupt your DB
179
+	 * @return bool
180
+	 * @throws EE_Error
181
+	 * @throws ReflectionException
182
+	 */
183
+	public function delete_permanently($query_params = [], $allow_blocking = true)
184
+	{
185
+		$would_be_deleted_price_types    = $this->get_all_deleted_and_undeleted($query_params);
186
+		$would_be_deleted_price_type_ids = array_keys($would_be_deleted_price_types);
187
+
188
+		$ID = $query_params[0][ $this->get_primary_key_field()->get_name() ];
189
+
190
+		// check if any prices use this price type
191
+		$prc_query_params = [['PRT_ID' => ['IN', $would_be_deleted_price_type_ids]]];
192
+		if ($prices = $this->get_all_related($ID, 'Price', $prc_query_params)) {
193
+			$prices_names_and_ids = [];
194
+			foreach ($prices as $price) {
195
+				/* @var $price EE_Price */
196
+				$prices_names_and_ids[] = $price->name() . "(" . $price->ID() . ")";
197
+			}
198
+			$msg = sprintf(
199
+				esc_html__(
200
+					'The Price Type(s) could not be deleted because there are existing Prices that currently use this Price Type.  If you still wish to delete this Price Type, then either delete those Prices or change them to use other Price Types.The prices are: %s',
201
+					'event_espresso'
202
+				),
203
+				implode(",", $prices_names_and_ids)
204
+			);
205
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
206
+			return false;
207
+		}
208
+
209
+		return parent::delete_permanently($query_params);
210
+	}
211 211
 }
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -45,7 +45,7 @@  discard block
 block discarded – undo
45 45
      */
46 46
     public function get_base_type_name($base_type_int)
47 47
     {
48
-        return $this->base_types[ $base_type_int ];
48
+        return $this->base_types[$base_type_int];
49 49
     }
50 50
 
51 51
 
@@ -78,7 +78,7 @@  discard block
 block discarded – undo
78 78
      */
79 79
     protected function __construct(?string $timezone = '')
80 80
     {
81
-        $this->base_types    = [
81
+        $this->base_types = [
82 82
             EEM_Price_Type::base_type_base_price => esc_html__('Price', 'event_espresso'),
83 83
             EEM_Price_Type::base_type_discount   => esc_html__('Discount', 'event_espresso'),
84 84
             EEM_Price_Type::base_type_surcharge  => esc_html__('Surcharge', 'event_espresso'),
@@ -150,7 +150,7 @@  discard block
 block discarded – undo
150 150
             'WP_User' => new EE_Belongs_To_Relation(),
151 151
         ];
152 152
         // this model is generally available for reading
153
-        $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public();
153
+        $this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Public();
154 154
         // all price types are "default" in terms of capability names
155 155
         $this->_caps_slug = 'default_price_types';
156 156
         parent::__construct($timezone);
@@ -185,7 +185,7 @@  discard block
 block discarded – undo
185 185
         $would_be_deleted_price_types    = $this->get_all_deleted_and_undeleted($query_params);
186 186
         $would_be_deleted_price_type_ids = array_keys($would_be_deleted_price_types);
187 187
 
188
-        $ID = $query_params[0][ $this->get_primary_key_field()->get_name() ];
188
+        $ID = $query_params[0][$this->get_primary_key_field()->get_name()];
189 189
 
190 190
         // check if any prices use this price type
191 191
         $prc_query_params = [['PRT_ID' => ['IN', $would_be_deleted_price_type_ids]]];
@@ -193,7 +193,7 @@  discard block
 block discarded – undo
193 193
             $prices_names_and_ids = [];
194 194
             foreach ($prices as $price) {
195 195
                 /* @var $price EE_Price */
196
-                $prices_names_and_ids[] = $price->name() . "(" . $price->ID() . ")";
196
+                $prices_names_and_ids[] = $price->name()."(".$price->ID().")";
197 197
             }
198 198
             $msg = sprintf(
199 199
                 esc_html__(
Please login to merge, or discard this patch.
core/db_models/EEM_Currency_Payment_Method.model.php 1 patch
Indentation   +43 added lines, -43 removed lines patch added patch discarded remove patch
@@ -9,49 +9,49 @@
 block discarded – undo
9 9
  */
10 10
 class EEM_Currency_Payment_Method extends EEM_Base
11 11
 {
12
-    protected static ?EEM_Currency_Payment_Method $_instance = null;
12
+	protected static ?EEM_Currency_Payment_Method $_instance = null;
13 13
 
14 14
 
15
-    /**
16
-     * @param string|null $timezone
17
-     * @throws EE_Error
18
-     */
19
-    protected function __construct(?string $timezone = '')
20
-    {
21
-        $this->singular_item    = esc_html__('Currency Usable by Payment Method', 'event_espresso');
22
-        $this->plural_item      = esc_html__('Currencies Usable by Payment Methods', 'event_espresso');
23
-        $this->_tables          = [
24
-            'Currency_Payment_Method' => new EE_Primary_Table('esp_currency_payment_method', 'CPM_ID'),
25
-        ];
26
-        $this->_fields          = [
27
-            'Currency_Payment_Method' => [
28
-                'CPM_ID'   => new EE_Primary_Key_Int_Field(
29
-                    'CPM_ID',
30
-                    esc_html__('Currency to Payment Method LInk ID', 'event_espresso')
31
-                ),
32
-                'CUR_code' => new EE_Foreign_Key_String_Field(
33
-                    'CUR_code',
34
-                    esc_html__('Currency Code', 'event_espresso'),
35
-                    false,
36
-                    '',
37
-                    'Currency'
38
-                ),
39
-                'PMD_ID'   => new EE_Foreign_Key_Int_Field(
40
-                    'PMD_ID',
41
-                    esc_html__('Paymetn Method ID', 'event_espresso'),
42
-                    false,
43
-                    0,
44
-                    'Payment_Method'
45
-                ),
46
-            ],
47
-        ];
48
-        $this->_model_relations = [
49
-            'Currency'       => new EE_Belongs_To_Relation(),
50
-            'Payment_Method' => new EE_Belongs_To_Relation(),
51
-        ];
52
-        // this model is generally available for reading
53
-        $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public();
54
-        $this->_caps_slug                                         = 'payment_methods';
55
-        parent::__construct($timezone);
56
-    }
15
+	/**
16
+	 * @param string|null $timezone
17
+	 * @throws EE_Error
18
+	 */
19
+	protected function __construct(?string $timezone = '')
20
+	{
21
+		$this->singular_item    = esc_html__('Currency Usable by Payment Method', 'event_espresso');
22
+		$this->plural_item      = esc_html__('Currencies Usable by Payment Methods', 'event_espresso');
23
+		$this->_tables          = [
24
+			'Currency_Payment_Method' => new EE_Primary_Table('esp_currency_payment_method', 'CPM_ID'),
25
+		];
26
+		$this->_fields          = [
27
+			'Currency_Payment_Method' => [
28
+				'CPM_ID'   => new EE_Primary_Key_Int_Field(
29
+					'CPM_ID',
30
+					esc_html__('Currency to Payment Method LInk ID', 'event_espresso')
31
+				),
32
+				'CUR_code' => new EE_Foreign_Key_String_Field(
33
+					'CUR_code',
34
+					esc_html__('Currency Code', 'event_espresso'),
35
+					false,
36
+					'',
37
+					'Currency'
38
+				),
39
+				'PMD_ID'   => new EE_Foreign_Key_Int_Field(
40
+					'PMD_ID',
41
+					esc_html__('Paymetn Method ID', 'event_espresso'),
42
+					false,
43
+					0,
44
+					'Payment_Method'
45
+				),
46
+			],
47
+		];
48
+		$this->_model_relations = [
49
+			'Currency'       => new EE_Belongs_To_Relation(),
50
+			'Payment_Method' => new EE_Belongs_To_Relation(),
51
+		];
52
+		// this model is generally available for reading
53
+		$this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public();
54
+		$this->_caps_slug                                         = 'payment_methods';
55
+		parent::__construct($timezone);
56
+	}
57 57
 }
Please login to merge, or discard this patch.
core/db_models/EEM_Country.model.php 1 patch
Indentation   +209 added lines, -209 removed lines patch added patch discarded remove patch
@@ -10,213 +10,213 @@
 block discarded – undo
10 10
  */
11 11
 class EEM_Country extends EEM_Base
12 12
 {
13
-    // private instance of the Attendee object
14
-    protected static $_instance = null;
15
-
16
-    // array of all countries
17
-    private static $_all_countries = false;
18
-
19
-    // array of all active countries
20
-    private static $_active_countries = false;
21
-
22
-
23
-    /**
24
-     * Resets the country
25
-     *
26
-     * @param string|null $timezone
27
-     * @return EEM_Country|EEM_Base|null
28
-     * @throws EE_Error
29
-     * @throws ReflectionException
30
-     */
31
-    public static function reset($timezone = '')
32
-    {
33
-        self::$_active_countries = null;
34
-        self::$_all_countries    = null;
35
-        return parent::reset($timezone);
36
-    }
37
-
38
-
39
-    /**
40
-     * @param string|null $timezone
41
-     * @throws EE_Error
42
-     */
43
-    protected function __construct(?string $timezone = '')
44
-    {
45
-        $this->singular_item = esc_html__('Country', 'event_espresso');
46
-        $this->plural_item   = esc_html__('Countries', 'event_espresso');
47
-
48
-        $this->_tables = [
49
-            'Country' => new EE_Primary_Table('esp_country', 'CNT_ISO'),
50
-        ];
51
-
52
-        $this->_fields          = [
53
-            'Country' => [
54
-                'CNT_active'      => new EE_Boolean_Field(
55
-                    'CNT_active',
56
-                    esc_html__('Country Appears in Dropdown Select Lists', 'event_espresso'),
57
-                    false,
58
-                    true
59
-                ),
60
-                'CNT_ISO'         => new EE_Primary_Key_String_Field(
61
-                    'CNT_ISO',
62
-                    esc_html__('Country ISO Code', 'event_espresso')
63
-                ),
64
-                'CNT_ISO3'        => new EE_All_Caps_Text_Field(
65
-                    'CNT_ISO3',
66
-                    esc_html__('Country ISO3 Code', 'event_espresso'),
67
-                    false,
68
-                    ''
69
-                ),
70
-                'RGN_ID'          => new EE_Integer_Field(
71
-                    'RGN_ID',
72
-                    esc_html__('Region ID', 'event_espresso'),
73
-                    false,
74
-                    0
75
-                ),
76
-                // should be a foreign key, but no region table exists yet
77
-                'CNT_name'        => new EE_Plain_Text_Field(
78
-                    'CNT_name',
79
-                    esc_html__('Country Name', 'event_espresso'),
80
-                    false,
81
-                    ''
82
-                ),
83
-                'CNT_cur_code'    => new EE_All_Caps_Text_Field(
84
-                    'CNT_cur_code',
85
-                    esc_html__('Country Currency Code', 'event_espresso'),
86
-                    false
87
-                ),
88
-                'CNT_cur_single'  => new EE_Plain_Text_Field(
89
-                    'CNT_cur_single',
90
-                    esc_html__('Currency Name Singular', 'event_espresso'),
91
-                    false
92
-                ),
93
-                'CNT_cur_plural'  => new EE_Plain_Text_Field(
94
-                    'CNT_cur_plural',
95
-                    esc_html__('Currency Name Plural', 'event_espresso'),
96
-                    false
97
-                ),
98
-                'CNT_cur_sign'    => new EE_Plain_Text_Field(
99
-                    'CNT_cur_sign',
100
-                    esc_html__('Currency Sign', 'event_espresso'),
101
-                    false
102
-                ),
103
-                'CNT_cur_sign_b4' => new EE_Boolean_Field(
104
-                    'CNT_cur_sign_b4',
105
-                    esc_html__('Currency Sign Before Number', 'event_espresso'),
106
-                    false,
107
-                    true
108
-                ),
109
-                'CNT_cur_dec_plc' => new EE_Integer_Field(
110
-                    'CNT_cur_dec_plc',
111
-                    esc_html__('Currency Decimal Places', 'event_espresso'),
112
-                    false,
113
-                    2
114
-                ),
115
-                'CNT_cur_dec_mrk' => new EE_Plain_Text_Field(
116
-                    'CNT_cur_dec_mrk',
117
-                    esc_html__('Currency Decimal Mark', 'event_espresso'),
118
-                    false,
119
-                    '.'
120
-                ),
121
-                'CNT_cur_thsnds'  => new EE_Plain_Text_Field(
122
-                    'CNT_cur_thsnds',
123
-                    esc_html__('Currency Thousands Separator', 'event_espresso'),
124
-                    false,
125
-                    ','
126
-                ),
127
-                'CNT_tel_code'    => new EE_Plain_Text_Field(
128
-                    'CNT_tel_code',
129
-                    esc_html__('Country Telephone Code', 'event_espresso'),
130
-                    false,
131
-                    ''
132
-                ),
133
-                'CNT_is_EU'       => new EE_Boolean_Field(
134
-                    'CNT_is_EU',
135
-                    esc_html__('Country is Member of EU', 'event_espresso'),
136
-                    false,
137
-                    false
138
-                ),
139
-            ],
140
-        ];
141
-        $this->_model_relations = [
142
-            'Attendee' => new EE_Has_Many_Relation(),
143
-            'State'    => new EE_Has_Many_Relation(),
144
-            'Venue'    => new EE_Has_Many_Relation(),
145
-        ];
146
-        // only anyone to view, but only those with the default role can do anything
147
-        $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public();
148
-
149
-        parent::__construct($timezone);
150
-    }
151
-
152
-
153
-    /**
154
-     * @return EE_Country[]
155
-     * @throws EE_Error
156
-     */
157
-    public function get_all_countries()
158
-    {
159
-        if (! self::$_all_countries) {
160
-            self::$_all_countries = $this->get_all(['order_by' => ['CNT_name' => 'ASC'], 'limit' => [0, 99999]]);
161
-        }
162
-        return self::$_all_countries;
163
-    }
164
-
165
-
166
-    /**
167
-     * Gets and caches the list of active countries. If you know the list of active countries
168
-     * has changed during this request, first use EEM_Country::reset() to flush the cache
169
-     *
170
-     * @return EE_Country[]
171
-     * @throws EE_Error
172
-     */
173
-    public function get_all_active_countries()
174
-    {
175
-        if (! self::$_active_countries) {
176
-            self::$_active_countries =
177
-                $this->get_all([['CNT_active' => true], 'order_by' => ['CNT_name' => 'ASC'], 'limit' => [0, 99999]]);
178
-        }
179
-        return self::$_active_countries;
180
-    }
181
-
182
-
183
-    /**
184
-     * Gets the country's name by its ISO
185
-     *
186
-     * @param string $country_ISO
187
-     * @return string
188
-     * @throws EE_Error
189
-     */
190
-    public function get_country_name_by_ISO($country_ISO)
191
-    {
192
-        $countries = $this->get_all_countries();
193
-        if (isset($countries[ $country_ISO ]) && $countries[ $country_ISO ] instanceof EE_Country) {
194
-            return $countries[ $country_ISO ]->name();
195
-        }
196
-        $names = $this->get_col([['CNT_ISO' => $country_ISO], 'limit' => 1], 'CNT_name');
197
-        if (is_array($names) && ! empty($names)) {
198
-            return reset($names);
199
-        } else {
200
-            return '';
201
-        }
202
-    }
203
-
204
-
205
-    /**
206
-     * Gets the country's name by its name
207
-     *
208
-     * @param string $country_name
209
-     * @return EE_Country|null
210
-     * @throws EE_Error
211
-     */
212
-    public function getCountryByName($country_name)
213
-    {
214
-        $countries = $this->get_all_countries();
215
-        foreach ($countries as $country) {
216
-            if ($country instanceof EE_Country && $country->name() === $country_name) {
217
-                return $country;
218
-            }
219
-        }
220
-        return $this->get_one([['CNT_name' => $country_name]]);
221
-    }
13
+	// private instance of the Attendee object
14
+	protected static $_instance = null;
15
+
16
+	// array of all countries
17
+	private static $_all_countries = false;
18
+
19
+	// array of all active countries
20
+	private static $_active_countries = false;
21
+
22
+
23
+	/**
24
+	 * Resets the country
25
+	 *
26
+	 * @param string|null $timezone
27
+	 * @return EEM_Country|EEM_Base|null
28
+	 * @throws EE_Error
29
+	 * @throws ReflectionException
30
+	 */
31
+	public static function reset($timezone = '')
32
+	{
33
+		self::$_active_countries = null;
34
+		self::$_all_countries    = null;
35
+		return parent::reset($timezone);
36
+	}
37
+
38
+
39
+	/**
40
+	 * @param string|null $timezone
41
+	 * @throws EE_Error
42
+	 */
43
+	protected function __construct(?string $timezone = '')
44
+	{
45
+		$this->singular_item = esc_html__('Country', 'event_espresso');
46
+		$this->plural_item   = esc_html__('Countries', 'event_espresso');
47
+
48
+		$this->_tables = [
49
+			'Country' => new EE_Primary_Table('esp_country', 'CNT_ISO'),
50
+		];
51
+
52
+		$this->_fields          = [
53
+			'Country' => [
54
+				'CNT_active'      => new EE_Boolean_Field(
55
+					'CNT_active',
56
+					esc_html__('Country Appears in Dropdown Select Lists', 'event_espresso'),
57
+					false,
58
+					true
59
+				),
60
+				'CNT_ISO'         => new EE_Primary_Key_String_Field(
61
+					'CNT_ISO',
62
+					esc_html__('Country ISO Code', 'event_espresso')
63
+				),
64
+				'CNT_ISO3'        => new EE_All_Caps_Text_Field(
65
+					'CNT_ISO3',
66
+					esc_html__('Country ISO3 Code', 'event_espresso'),
67
+					false,
68
+					''
69
+				),
70
+				'RGN_ID'          => new EE_Integer_Field(
71
+					'RGN_ID',
72
+					esc_html__('Region ID', 'event_espresso'),
73
+					false,
74
+					0
75
+				),
76
+				// should be a foreign key, but no region table exists yet
77
+				'CNT_name'        => new EE_Plain_Text_Field(
78
+					'CNT_name',
79
+					esc_html__('Country Name', 'event_espresso'),
80
+					false,
81
+					''
82
+				),
83
+				'CNT_cur_code'    => new EE_All_Caps_Text_Field(
84
+					'CNT_cur_code',
85
+					esc_html__('Country Currency Code', 'event_espresso'),
86
+					false
87
+				),
88
+				'CNT_cur_single'  => new EE_Plain_Text_Field(
89
+					'CNT_cur_single',
90
+					esc_html__('Currency Name Singular', 'event_espresso'),
91
+					false
92
+				),
93
+				'CNT_cur_plural'  => new EE_Plain_Text_Field(
94
+					'CNT_cur_plural',
95
+					esc_html__('Currency Name Plural', 'event_espresso'),
96
+					false
97
+				),
98
+				'CNT_cur_sign'    => new EE_Plain_Text_Field(
99
+					'CNT_cur_sign',
100
+					esc_html__('Currency Sign', 'event_espresso'),
101
+					false
102
+				),
103
+				'CNT_cur_sign_b4' => new EE_Boolean_Field(
104
+					'CNT_cur_sign_b4',
105
+					esc_html__('Currency Sign Before Number', 'event_espresso'),
106
+					false,
107
+					true
108
+				),
109
+				'CNT_cur_dec_plc' => new EE_Integer_Field(
110
+					'CNT_cur_dec_plc',
111
+					esc_html__('Currency Decimal Places', 'event_espresso'),
112
+					false,
113
+					2
114
+				),
115
+				'CNT_cur_dec_mrk' => new EE_Plain_Text_Field(
116
+					'CNT_cur_dec_mrk',
117
+					esc_html__('Currency Decimal Mark', 'event_espresso'),
118
+					false,
119
+					'.'
120
+				),
121
+				'CNT_cur_thsnds'  => new EE_Plain_Text_Field(
122
+					'CNT_cur_thsnds',
123
+					esc_html__('Currency Thousands Separator', 'event_espresso'),
124
+					false,
125
+					','
126
+				),
127
+				'CNT_tel_code'    => new EE_Plain_Text_Field(
128
+					'CNT_tel_code',
129
+					esc_html__('Country Telephone Code', 'event_espresso'),
130
+					false,
131
+					''
132
+				),
133
+				'CNT_is_EU'       => new EE_Boolean_Field(
134
+					'CNT_is_EU',
135
+					esc_html__('Country is Member of EU', 'event_espresso'),
136
+					false,
137
+					false
138
+				),
139
+			],
140
+		];
141
+		$this->_model_relations = [
142
+			'Attendee' => new EE_Has_Many_Relation(),
143
+			'State'    => new EE_Has_Many_Relation(),
144
+			'Venue'    => new EE_Has_Many_Relation(),
145
+		];
146
+		// only anyone to view, but only those with the default role can do anything
147
+		$this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public();
148
+
149
+		parent::__construct($timezone);
150
+	}
151
+
152
+
153
+	/**
154
+	 * @return EE_Country[]
155
+	 * @throws EE_Error
156
+	 */
157
+	public function get_all_countries()
158
+	{
159
+		if (! self::$_all_countries) {
160
+			self::$_all_countries = $this->get_all(['order_by' => ['CNT_name' => 'ASC'], 'limit' => [0, 99999]]);
161
+		}
162
+		return self::$_all_countries;
163
+	}
164
+
165
+
166
+	/**
167
+	 * Gets and caches the list of active countries. If you know the list of active countries
168
+	 * has changed during this request, first use EEM_Country::reset() to flush the cache
169
+	 *
170
+	 * @return EE_Country[]
171
+	 * @throws EE_Error
172
+	 */
173
+	public function get_all_active_countries()
174
+	{
175
+		if (! self::$_active_countries) {
176
+			self::$_active_countries =
177
+				$this->get_all([['CNT_active' => true], 'order_by' => ['CNT_name' => 'ASC'], 'limit' => [0, 99999]]);
178
+		}
179
+		return self::$_active_countries;
180
+	}
181
+
182
+
183
+	/**
184
+	 * Gets the country's name by its ISO
185
+	 *
186
+	 * @param string $country_ISO
187
+	 * @return string
188
+	 * @throws EE_Error
189
+	 */
190
+	public function get_country_name_by_ISO($country_ISO)
191
+	{
192
+		$countries = $this->get_all_countries();
193
+		if (isset($countries[ $country_ISO ]) && $countries[ $country_ISO ] instanceof EE_Country) {
194
+			return $countries[ $country_ISO ]->name();
195
+		}
196
+		$names = $this->get_col([['CNT_ISO' => $country_ISO], 'limit' => 1], 'CNT_name');
197
+		if (is_array($names) && ! empty($names)) {
198
+			return reset($names);
199
+		} else {
200
+			return '';
201
+		}
202
+	}
203
+
204
+
205
+	/**
206
+	 * Gets the country's name by its name
207
+	 *
208
+	 * @param string $country_name
209
+	 * @return EE_Country|null
210
+	 * @throws EE_Error
211
+	 */
212
+	public function getCountryByName($country_name)
213
+	{
214
+		$countries = $this->get_all_countries();
215
+		foreach ($countries as $country) {
216
+			if ($country instanceof EE_Country && $country->name() === $country_name) {
217
+				return $country;
218
+			}
219
+		}
220
+		return $this->get_one([['CNT_name' => $country_name]]);
221
+	}
222 222
 }
Please login to merge, or discard this patch.
core/db_models/EEM_Event.model.php 2 patches
Indentation   +964 added lines, -964 removed lines patch added patch discarded remove patch
@@ -13,968 +13,968 @@
 block discarded – undo
13 13
  */
14 14
 class EEM_Event extends EEM_CPT_Base
15 15
 {
16
-    /**
17
-     * constant used by status(), indicating that no more tickets can be purchased for any of the datetimes for the
18
-     * event
19
-     */
20
-    const sold_out = 'sold_out';
21
-
22
-    /**
23
-     * constant used by status(), indicating that upcoming event dates have been postponed (may be pushed to a later
24
-     * date)
25
-     */
26
-    const postponed = 'postponed';
27
-
28
-    /**
29
-     * constant used by status(), indicating that the event will no longer occur
30
-     */
31
-    const cancelled = 'cancelled';
32
-
33
-
34
-    /**
35
-     * @var string
36
-     */
37
-    protected static $_default_reg_status;
38
-
39
-
40
-    /**
41
-     * This is the default for the additional limit field.
42
-     *
43
-     * @var int
44
-     */
45
-    protected static $_default_additional_limit = 10;
46
-
47
-
48
-    /**
49
-     * private instance of the Event object
50
-     *
51
-     * @var EEM_Event
52
-     */
53
-    protected static $_instance;
54
-
55
-
56
-    /**
57
-     * Adds a relationship to Term_Taxonomy for each CPT_Base
58
-     *
59
-     * @param string|null $timezone
60
-     * @throws EE_Error
61
-     * @throws ReflectionException
62
-     */
63
-    protected function __construct(?string $timezone = '')
64
-    {
65
-        EE_Registry::instance()->load_model('Registration');
66
-        $this->singular_item = esc_html__('Event', 'event_espresso');
67
-        $this->plural_item   = esc_html__('Events', 'event_espresso');
68
-        // to remove Cancelled events from the frontend, copy the following filter to your functions.php file
69
-        // add_filter( 'AFEE__EEM_Event__construct___custom_stati__cancelled__Public', '__return_false' );
70
-        // to remove Postponed events from the frontend, copy the following filter to your functions.php file
71
-        // add_filter( 'AFEE__EEM_Event__construct___custom_stati__postponed__Public', '__return_false' );
72
-        // to remove Sold Out events from the frontend, copy the following filter to your functions.php file
73
-        //  add_filter( 'AFEE__EEM_Event__construct___custom_stati__sold_out__Public', '__return_false' );
74
-        $this->_custom_stati       = apply_filters(
75
-            'AFEE__EEM_Event__construct___custom_stati',
76
-            [
77
-                EEM_Event::cancelled => [
78
-                    'label'  => esc_html__('Cancelled', 'event_espresso'),
79
-                    'public' => apply_filters('AFEE__EEM_Event__construct___custom_stati__cancelled__Public', true),
80
-                ],
81
-                EEM_Event::postponed => [
82
-                    'label'  => esc_html__('Postponed', 'event_espresso'),
83
-                    'public' => apply_filters('AFEE__EEM_Event__construct___custom_stati__postponed__Public', true),
84
-                ],
85
-                EEM_Event::sold_out  => [
86
-                    'label'  => esc_html__('Sold Out', 'event_espresso'),
87
-                    'public' => apply_filters('AFEE__EEM_Event__construct___custom_stati__sold_out__Public', true),
88
-                ],
89
-            ]
90
-        );
91
-        self::$_default_reg_status = empty(self::$_default_reg_status)
92
-            ? EEM_Registration::status_id_pending_payment
93
-            : self::$_default_reg_status;
94
-        $this->_tables             = [
95
-            'Event_CPT'  => new EE_Primary_Table('posts', 'ID'),
96
-            'Event_Meta' => new EE_Secondary_Table('esp_event_meta', 'EVTM_ID', 'EVT_ID'),
97
-        ];
98
-        $this->_fields             = [
99
-            'Event_CPT'  => [
100
-                'EVT_ID'         => new EE_Primary_Key_Int_Field(
101
-                    'ID',
102
-                    esc_html__('Post ID for Event', 'event_espresso')
103
-                ),
104
-                'EVT_name'       => new EE_Plain_Text_Field(
105
-                    'post_title',
106
-                    esc_html__('Event Name', 'event_espresso'),
107
-                    false,
108
-                    ''
109
-                ),
110
-                'EVT_desc'       => new EE_Post_Content_Field(
111
-                    'post_content',
112
-                    esc_html__('Event Description', 'event_espresso'),
113
-                    false,
114
-                    ''
115
-                ),
116
-                'EVT_slug'       => new EE_Slug_Field(
117
-                    'post_name',
118
-                    esc_html__('Event Slug', 'event_espresso'),
119
-                    false,
120
-                    ''
121
-                ),
122
-                'EVT_created'    => new EE_Datetime_Field(
123
-                    'post_date',
124
-                    esc_html__('Date/Time Event Created', 'event_espresso'),
125
-                    false,
126
-                    EE_Datetime_Field::now
127
-                ),
128
-                'EVT_short_desc' => new EE_Simple_HTML_Field(
129
-                    'post_excerpt',
130
-                    esc_html__('Event Short Description', 'event_espresso'),
131
-                    false,
132
-                    ''
133
-                ),
134
-                'EVT_modified'   => new EE_Datetime_Field(
135
-                    'post_modified',
136
-                    esc_html__('Date/Time Event Modified', 'event_espresso'),
137
-                    false,
138
-                    EE_Datetime_Field::now
139
-                ),
140
-                'EVT_wp_user'    => new EE_WP_User_Field(
141
-                    'post_author',
142
-                    esc_html__('Event Creator ID', 'event_espresso'),
143
-                    false
144
-                ),
145
-                'parent'         => new EE_Integer_Field(
146
-                    'post_parent',
147
-                    esc_html__('Event Parent ID', 'event_espresso'),
148
-                    false,
149
-                    0
150
-                ),
151
-                'EVT_order'      => new EE_Integer_Field(
152
-                    'menu_order',
153
-                    esc_html__('Event Menu Order', 'event_espresso'),
154
-                    false,
155
-                    1
156
-                ),
157
-                'post_type'      => new EE_WP_Post_Type_Field('espresso_events'),
158
-                // EE_Plain_Text_Field( 'post_type', esc_html__( 'Event Post Type', 'event_espresso' ), FALSE, 'espresso_events' ),
159
-                'status'         => new EE_WP_Post_Status_Field(
160
-                    'post_status',
161
-                    esc_html__('Event Status', 'event_espresso'),
162
-                    false,
163
-                    'draft',
164
-                    $this->_custom_stati
165
-                ),
166
-                'password'       => new EE_Password_Field(
167
-                    'post_password',
168
-                    esc_html__('Password', 'event_espresso'),
169
-                    false,
170
-                    '',
171
-                    [
172
-                        'EVT_desc',
173
-                        'EVT_short_desc',
174
-                        'EVT_display_desc',
175
-                        'EVT_display_ticket_selector',
176
-                        'EVT_visible_on',
177
-                        'EVT_additional_limit',
178
-                        'EVT_default_registration_status',
179
-                        'EVT_member_only',
180
-                        'EVT_phone',
181
-                        'EVT_allow_overflow',
182
-                        'EVT_timezone_string',
183
-                        'EVT_external_URL',
184
-                        'EVT_donations',
185
-                    ]
186
-                ),
187
-            ],
188
-            'Event_Meta' => [
189
-                'EVTM_ID'                         => new EE_DB_Only_Float_Field(
190
-                    'EVTM_ID',
191
-                    esc_html__('Event Meta Row ID', 'event_espresso'),
192
-                    false
193
-                ),
194
-                'EVT_ID_fk'                       => new EE_DB_Only_Int_Field(
195
-                    'EVT_ID',
196
-                    esc_html__('Foreign key to Event ID from Event Meta table', 'event_espresso'),
197
-                    false
198
-                ),
199
-                'VNU_ID'                          => new EE_Foreign_Key_Int_Field(
200
-                    'VNU_ID',
201
-                    __('Venue ID', 'event_espresso'),
202
-                    false,
203
-                    0,
204
-                    'Venue'
205
-                ),
206
-                'EVT_display_desc'                => new EE_Boolean_Field(
207
-                    'EVT_display_desc',
208
-                    esc_html__('Display Description Flag', 'event_espresso'),
209
-                    false,
210
-                    true
211
-                ),
212
-                'EVT_display_ticket_selector'     => new EE_Boolean_Field(
213
-                    'EVT_display_ticket_selector',
214
-                    esc_html__('Display Ticket Selector Flag', 'event_espresso'),
215
-                    false,
216
-                    true
217
-                ),
218
-                'EVT_visible_on'                  => new EE_Datetime_Field(
219
-                    'EVT_visible_on',
220
-                    esc_html__('Event Visible Date', 'event_espresso'),
221
-                    true,
222
-                    EE_Datetime_Field::now
223
-                ),
224
-                'EVT_additional_limit'            => new EE_Integer_Field(
225
-                    'EVT_additional_limit',
226
-                    esc_html__('Limit of Additional Registrations on Same Transaction', 'event_espresso'),
227
-                    false,
228
-                    self::$_default_additional_limit
229
-                ),
230
-                'EVT_default_registration_status' => new EE_Enum_Text_Field(
231
-                    'EVT_default_registration_status',
232
-                    esc_html__('Default Registration Status on this Event', 'event_espresso'),
233
-                    false,
234
-                    EEM_Event::$_default_reg_status,
235
-                    EEM_Registration::reg_status_array()
236
-                ),
237
-                'EVT_member_only'                 => new EE_Boolean_Field(
238
-                    'EVT_member_only',
239
-                    esc_html__('Member-Only Event Flag', 'event_espresso'),
240
-                    false,
241
-                    false
242
-                ),
243
-                'EVT_phone'                       => new EE_Plain_Text_Field(
244
-                    'EVT_phone',
245
-                    esc_html__('Event Phone Number', 'event_espresso'),
246
-                    false,
247
-                    ''
248
-                ),
249
-                'EVT_allow_overflow'              => new EE_Boolean_Field(
250
-                    'EVT_allow_overflow',
251
-                    esc_html__('Allow Overflow on Event', 'event_espresso'),
252
-                    false,
253
-                    false
254
-                ),
255
-                'EVT_timezone_string'             => new EE_Plain_Text_Field(
256
-                    'EVT_timezone_string',
257
-                    esc_html__('Timezone (name) for Event times', 'event_espresso'),
258
-                    false,
259
-                    ''
260
-                ),
261
-                'EVT_external_URL'                => new EE_Plain_Text_Field(
262
-                    'EVT_external_URL',
263
-                    esc_html__('URL of Event Page if hosted elsewhere', 'event_espresso'),
264
-                    true
265
-                ),
266
-                'EVT_donations'                   => new EE_Boolean_Field(
267
-                    'EVT_donations',
268
-                    esc_html__('Accept Donations?', 'event_espresso'),
269
-                    false,
270
-                    false
271
-                ),
272
-                'FSC_UUID'                        => new EE_Foreign_Key_String_Field(
273
-                    'FSC_UUID',
274
-                    esc_html__('Registration Form UUID (universally unique identifier)', 'event_espresso'),
275
-                    true,
276
-                    null,
277
-                    'Form_Section',
278
-                    false
279
-                ),
280
-            ],
281
-        ];
282
-        $this->_model_relations    = [
283
-            'Attendee'               => new EE_HABTM_Relation('Registration'),
284
-            'Datetime'               => new EE_Has_Many_Relation(),
285
-            'Event_Question_Group'   => new EE_Has_Many_Relation(),
286
-            'Form_Section'           => new EE_Belongs_To_Relation(),
287
-            'Message_Template_Group' => new EE_HABTM_Relation('Event_Message_Template'),
288
-            'Question_Group'         => new EE_HABTM_Relation('Event_Question_Group'),
289
-            'Registration'           => new EE_Has_Many_Relation(),
290
-            'Term_Relationship'      => new EE_Has_Many_Relation(),
291
-            'Term_Taxonomy'          => new EE_HABTM_Relation('Term_Relationship'),
292
-            'Venue'                  => new EE_Belongs_To_Relation(),
293
-            'WP_User'                => new EE_Belongs_To_Relation(),
294
-        ];
295
-        // this model is generally available for reading
296
-        $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public();
297
-        $this->model_chain_to_password                            = '';
298
-        parent::__construct($timezone);
299
-    }
300
-
301
-
302
-    /**
303
-     * @param string $default_reg_status
304
-     * @throws EE_Error
305
-     * @throws EE_Error
306
-     */
307
-    public static function set_default_reg_status($default_reg_status)
308
-    {
309
-        self::$_default_reg_status = $default_reg_status;
310
-        // if EEM_Event has already been instantiated,
311
-        // then we need to reset the `EVT_default_reg_status` field to use the new default.
312
-        if (self::$_instance instanceof EEM_Event) {
313
-            $default_reg_status = new EE_Enum_Text_Field(
314
-                'EVT_default_registration_status',
315
-                esc_html__('Default Registration Status on this Event', 'event_espresso'),
316
-                false,
317
-                $default_reg_status,
318
-                EEM_Registration::reg_status_array()
319
-            );
320
-            $default_reg_status->_construct_finalize(
321
-                'Event_Meta',
322
-                'EVT_default_registration_status',
323
-                'EEM_Event'
324
-            );
325
-            self::$_instance->_fields['Event_Meta']['EVT_default_registration_status'] = $default_reg_status;
326
-        }
327
-    }
328
-
329
-
330
-    /**
331
-     * Used to override the default for the additional limit field.
332
-     *
333
-     * @param $additional_limit
334
-     */
335
-    public static function set_default_additional_limit($additional_limit)
336
-    {
337
-        self::$_default_additional_limit = (int) $additional_limit;
338
-        if (self::$_instance instanceof EEM_Event) {
339
-            self::$_instance->_fields['Event_Meta']['EVT_additional_limit'] = new EE_Integer_Field(
340
-                'EVT_additional_limit',
341
-                esc_html__('Limit of Additional Registrations on Same Transaction', 'event_espresso'),
342
-                false,
343
-                self::$_default_additional_limit
344
-            );
345
-            self::$_instance->_fields['Event_Meta']['EVT_additional_limit']->_construct_finalize(
346
-                'Event_Meta',
347
-                'EVT_additional_limit',
348
-                'EEM_Event'
349
-            );
350
-        }
351
-    }
352
-
353
-
354
-    /**
355
-     * Return what is currently set as the default additional limit for the event.
356
-     *
357
-     * @return int
358
-     */
359
-    public static function get_default_additional_limit()
360
-    {
361
-        return apply_filters('FHEE__EEM_Event__get_default_additional_limit', self::$_default_additional_limit);
362
-    }
363
-
364
-
365
-    /**
366
-     * get_question_groups
367
-     *
368
-     * @return array
369
-     * @throws EE_Error
370
-     * @throws ReflectionException
371
-     */
372
-    public function get_all_question_groups()
373
-    {
374
-        return EE_Registry::instance()->load_model('Question_Group')->get_all(
375
-            [
376
-                ['QSG_deleted' => false],
377
-                'order_by' => ['QSG_order' => 'ASC'],
378
-            ]
379
-        );
380
-    }
381
-
382
-
383
-    /**
384
-     * get_question_groups
385
-     *
386
-     * @param int $EVT_ID
387
-     * @return array|bool
388
-     * @throws EE_Error
389
-     * @throws ReflectionException
390
-     */
391
-    public function get_all_event_question_groups($EVT_ID = 0)
392
-    {
393
-        if (! isset($EVT_ID) || ! absint($EVT_ID)) {
394
-            EE_Error::add_error(
395
-                esc_html__(
396
-                    'An error occurred. No Event Question Groups could be retrieved because an Event ID was not received.',
397
-                    'event_espresso'
398
-                ),
399
-                __FILE__,
400
-                __FUNCTION__,
401
-                __LINE__
402
-            );
403
-            return false;
404
-        }
405
-        return EE_Registry::instance()->load_model('Event_Question_Group')->get_all(
406
-            [
407
-                ['EVT_ID' => $EVT_ID],
408
-            ]
409
-        );
410
-    }
411
-
412
-
413
-    /**
414
-     * get_question_groups
415
-     *
416
-     * @param int     $EVT_ID
417
-     * @param boolean $for_primary_attendee
418
-     * @return array|bool
419
-     * @throws EE_Error
420
-     * @throws InvalidArgumentException
421
-     * @throws ReflectionException
422
-     * @throws InvalidDataTypeException
423
-     * @throws InvalidInterfaceException
424
-     */
425
-    public function get_event_question_groups($EVT_ID = 0, $for_primary_attendee = true)
426
-    {
427
-        if (! isset($EVT_ID) || ! absint($EVT_ID)) {
428
-            EE_Error::add_error(
429
-                esc_html__(
430
-                // @codingStandardsIgnoreStart
431
-                    'An error occurred. No Event Question Groups could be retrieved because an Event ID was not received.',
432
-                    // @codingStandardsIgnoreEnd
433
-                    'event_espresso'
434
-                ),
435
-                __FILE__,
436
-                __FUNCTION__,
437
-                __LINE__
438
-            );
439
-            return false;
440
-        }
441
-        $query_params = [
442
-            [
443
-                'EVT_ID'                                                                         => $EVT_ID,
444
-                EEM_Event_Question_Group::instance()->fieldNameForContext($for_primary_attendee) => true,
445
-            ],
446
-        ];
447
-        if ($for_primary_attendee) {
448
-            $query_params[0]['EQG_primary'] = true;
449
-        } else {
450
-            $query_params[0]['EQG_additional'] = true;
451
-        }
452
-        return EE_Registry::instance()->load_model('Event_Question_Group')->get_all($query_params);
453
-    }
454
-
455
-
456
-    /**
457
-     * get_question_groups
458
-     *
459
-     * @param int             $EVT_ID
460
-     * @param EE_Registration $registration
461
-     * @return array|bool
462
-     * @throws EE_Error
463
-     * @throws InvalidArgumentException
464
-     * @throws InvalidDataTypeException
465
-     * @throws InvalidInterfaceException
466
-     * @throws ReflectionException
467
-     */
468
-    public function get_question_groups_for_event($EVT_ID, EE_Registration $registration)
469
-    {
470
-        if (! absint($EVT_ID)) {
471
-            EE_Error::add_error(
472
-                esc_html__(
473
-                    'An error occurred. No Question Groups could be retrieved because an Event ID was not received.',
474
-                    'event_espresso'
475
-                ),
476
-                __FILE__,
477
-                __FUNCTION__,
478
-                __LINE__
479
-            );
480
-            return false;
481
-        }
482
-        return EE_Registry::instance()->load_model('Question_Group')->get_all(
483
-            [
484
-                [
485
-                    'Event_Question_Group.EVT_ID' => $EVT_ID,
486
-                    'Event_Question_Group.'
487
-                    . EEM_Event_Question_Group::instance()->fieldNameForContext(
488
-                        $registration->is_primary_registrant()
489
-                    )                             => true,
490
-                ],
491
-                'order_by' => ['QSG_order' => 'ASC'],
492
-            ]
493
-        );
494
-    }
495
-
496
-
497
-    /**
498
-     * get_question_target_db_column
499
-     *
500
-     * @param string $QSG_IDs csv list of $QSG IDs
501
-     * @return array|bool
502
-     * @throws EE_Error
503
-     * @throws ReflectionException
504
-     */
505
-    public function get_questions_in_groups($QSG_IDs = '')
506
-    {
507
-        if (empty($QSG_IDs)) {
508
-            EE_Error::add_error(
509
-                esc_html__('An error occurred. No Question Group IDs were received.', 'event_espresso'),
510
-                __FILE__,
511
-                __FUNCTION__,
512
-                __LINE__
513
-            );
514
-            return false;
515
-        }
516
-        return EE_Registry::instance()->load_model('Question')->get_all(
517
-            [
518
-                [
519
-                    'Question_Group.QSG_ID' => ['IN', $QSG_IDs],
520
-                    'QST_deleted'           => false,
521
-                    'QST_admin_only'        => is_admin(),
522
-                ],
523
-                'order_by' => 'QST_order',
524
-            ]
525
-        );
526
-    }
527
-
528
-
529
-    /**
530
-     * get_options_for_question
531
-     *
532
-     * @param string $QST_IDs csv list of $QST IDs
533
-     * @return array|bool
534
-     * @throws EE_Error
535
-     * @throws ReflectionException
536
-     */
537
-    public function get_options_for_question($QST_IDs)
538
-    {
539
-        if (empty($QST_IDs)) {
540
-            EE_Error::add_error(
541
-                esc_html__('An error occurred. No Question IDs were received.', 'event_espresso'),
542
-                __FILE__,
543
-                __FUNCTION__,
544
-                __LINE__
545
-            );
546
-            return false;
547
-        }
548
-        return EE_Registry::instance()->load_model('Question_Option')->get_all(
549
-            [
550
-                [
551
-                    'Question.QST_ID' => ['IN', $QST_IDs],
552
-                    'QSO_deleted'     => false,
553
-                ],
554
-                'order_by' => 'QSO_ID',
555
-            ]
556
-        );
557
-    }
558
-
559
-
560
-    /**
561
-     * Gets all events that are published
562
-     * and have event start time earlier than now and an event end time later than now
563
-     *
564
-     * @param array $query_params  An array of query params to further filter on
565
-     *                             (note that status and DTT_EVT_start and DTT_EVT_end will be overridden)
566
-     * @param bool  $count         whether to return the count or not (default FALSE)
567
-     * @return EE_Event[]|int
568
-     * @throws EE_Error
569
-     * @throws ReflectionException
570
-     */
571
-    public function get_active_events($query_params, $count = false)
572
-    {
573
-        if (array_key_exists(0, $query_params)) {
574
-            $where_params = $query_params[0];
575
-            unset($query_params[0]);
576
-        } else {
577
-            $where_params = [];
578
-        }
579
-        // if we have count make sure we don't include group by
580
-        if ($count && isset($query_params['group_by'])) {
581
-            unset($query_params['group_by']);
582
-        }
583
-        // add status query
584
-        $where_params = $this->set_where_conditions_for_status($where_params);
585
-        // if already have where params for DTT_EVT_start or DTT_EVT_end then append these conditions
586
-        if (isset($where_params['Datetime.DTT_EVT_start'])) {
587
-            $where_params['Datetime.DTT_EVT_start******'] = [
588
-                '<',
589
-                EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'),
590
-            ];
591
-        } else {
592
-            $where_params['Datetime.DTT_EVT_start'] = [
593
-                '<',
594
-                EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'),
595
-            ];
596
-        }
597
-        $where_params = $this->set_where_conditions_for_end_datetime($where_params);
598
-        return $this->_get_count_or_all($query_params, $where_params, $count);
599
-    }
600
-
601
-
602
-    /**
603
-     * get all events that are published and have an event start time later than now
604
-     *
605
-     * @param array $query_params  An array of query params to further filter on
606
-     *                             (Note that status and DTT_EVT_start will be overridden)
607
-     * @param bool  $count         whether to return the count or not (default FALSE)
608
-     * @return EE_Event[]|int
609
-     * @throws EE_Error
610
-     * @throws ReflectionException
611
-     */
612
-    public function get_upcoming_events($query_params, $count = false)
613
-    {
614
-        if (array_key_exists(0, $query_params)) {
615
-            $where_params = $query_params[0];
616
-            unset($query_params[0]);
617
-        } else {
618
-            $where_params = [];
619
-        }
620
-        // if we have count make sure we don't include group by
621
-        if ($count && isset($query_params['group_by'])) {
622
-            unset($query_params['group_by']);
623
-        }
624
-        // add status query
625
-        $where_params = $this->set_where_conditions_for_status($where_params);
626
-        // if there are already query_params matching DTT_EVT_start then we need to modify that to add them.
627
-        if (isset($where_params['Datetime.DTT_EVT_start'])) {
628
-            $where_params['Datetime.DTT_EVT_start*****'] = [
629
-                '>',
630
-                EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'),
631
-            ];
632
-        } else {
633
-            $where_params['Datetime.DTT_EVT_start'] = [
634
-                '>',
635
-                EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'),
636
-            ];
637
-        }
638
-        return $this->_get_count_or_all($query_params, $where_params, $count);
639
-    }
640
-
641
-
642
-    /**
643
-     * Gets all events that are published
644
-     * and have an event end time later than now
645
-     *
646
-     * @param array $query_params  An array of query params to further filter on
647
-     *                             (note that status and DTT_EVT_end will be overridden)
648
-     * @param bool  $count         whether to return the count or not (default FALSE)
649
-     * @return EE_Event[]|int
650
-     * @throws EE_Error
651
-     * @throws ReflectionException
652
-     */
653
-    public function get_active_and_upcoming_events($query_params, $count = false)
654
-    {
655
-        if (array_key_exists(0, $query_params)) {
656
-            $where_params = $query_params[0];
657
-            unset($query_params[0]);
658
-        } else {
659
-            $where_params = [];
660
-        }
661
-        // if we have count make sure we don't include group by
662
-        if ($count && isset($query_params['group_by'])) {
663
-            unset($query_params['group_by']);
664
-        }
665
-        // add status query
666
-        $where_params = $this->set_where_conditions_for_status($where_params);
667
-        // add where params for DTT_EVT_end
668
-        $where_params = $this->set_where_conditions_for_end_datetime($where_params);
669
-        return $this->_get_count_or_all($query_params, $where_params, $count);
670
-    }
671
-
672
-
673
-    /**
674
-     * This only returns events that are expired.
675
-     * They may still be published but all their datetimes have expired.
676
-     *
677
-     * @param array $query_params  An array of query params to further filter on
678
-     *                             (note that status and DTT_EVT_end will be overridden)
679
-     * @param bool  $count         whether to return the count or not (default FALSE)
680
-     * @return EE_Event[]|int
681
-     * @throws EE_Error
682
-     * @throws ReflectionException
683
-     */
684
-    public function get_expired_events($query_params, $count = false)
685
-    {
686
-        $where_params = isset($query_params[0])
687
-            ? $query_params[0]
688
-            : [];
689
-        // if we have count make sure we don't include group by
690
-        if ($count && isset($query_params['group_by'])) {
691
-            unset($query_params['group_by']);
692
-        }
693
-        // let's add specific query_params for active_events
694
-        // keep in mind this will override any sent status in the query AND any date queries.
695
-        if (isset($where_params['status'])) {
696
-            unset($where_params['status']);
697
-        }
698
-        // first get all events that have datetimes where its not expired.
699
-        $event_ids = $this->get_all_not_expired_event_ids($query_params);
700
-        // if we have any additional query_params, let's add them to the 'AND' condition
701
-        $and_condition = [
702
-            'Datetime.DTT_EVT_end' => ['<', EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end')],
703
-            'EVT_ID'               => ['NOT IN', $event_ids],
704
-        ];
705
-        if (isset($where_params['OR'])) {
706
-            $and_condition['OR'] = $where_params['OR'];
707
-            unset($where_params['OR']);
708
-        }
709
-        if (isset($where_params['Datetime.DTT_EVT_end'])) {
710
-            $and_condition['Datetime.DTT_EVT_end****'] = $where_params['Datetime.DTT_EVT_end'];
711
-            unset($where_params['Datetime.DTT_EVT_end']);
712
-        }
713
-        if (isset($where_params['Datetime.DTT_EVT_start'])) {
714
-            $and_condition['Datetime.DTT_EVT_start'] = $where_params['Datetime.DTT_EVT_start'];
715
-            unset($where_params['Datetime.DTT_EVT_start']);
716
-        }
717
-        // merge remaining $where params with the and conditions.
718
-        $where_params['AND'] = array_merge($and_condition, $where_params);
719
-        return $this->_get_count_or_all($query_params, $where_params, $count);
720
-    }
721
-
722
-
723
-    /**
724
-     * @param array $query_params
725
-     * @return int[]
726
-     * @throws EE_Error
727
-     * @throws ReflectionException
728
-     */
729
-    public function get_all_not_expired_event_ids(array $query_params = []): array
730
-    {
731
-        $query_params[0] = [
732
-            'Datetime.DTT_EVT_end' => [
733
-                '>',
734
-                EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'),
735
-            ],
736
-        ];
737
-        $event_ids       = $this->_get_all_wpdb_results($query_params, OBJECT_K, 'Event_CPT.ID');
738
-        return array_keys($event_ids);
739
-    }
740
-
741
-
742
-    /**
743
-     * This basically just returns the events that do not have the publish status.
744
-     *
745
-     * @param array   $query_params  An array of query params to further filter on
746
-     *                               (note that status will be overwritten)
747
-     * @param boolean $count         whether to return the count or not (default FALSE)
748
-     * @return EE_Event[]|int
749
-     * @throws EE_Error
750
-     * @throws ReflectionException
751
-     */
752
-    public function get_inactive_events($query_params, $count = false)
753
-    {
754
-        $where_params = isset($query_params[0])
755
-            ? $query_params[0]
756
-            : [];
757
-        // let's add in specific query_params for inactive events.
758
-        if (isset($where_params['status'])) {
759
-            unset($where_params['status']);
760
-        }
761
-        // if we have count make sure we don't include group by
762
-        if ($count && isset($query_params['group_by'])) {
763
-            unset($query_params['group_by']);
764
-        }
765
-        // if we have any additional query_params, let's add them to the 'AND' condition
766
-        $where_params['AND']['status'] = ['!=', 'publish'];
767
-        if (isset($where_params['OR'])) {
768
-            $where_params['AND']['OR'] = $where_params['OR'];
769
-            unset($where_params['OR']);
770
-        }
771
-        if (isset($where_params['Datetime.DTT_EVT_end'])) {
772
-            $where_params['AND']['Datetime.DTT_EVT_end****'] = $where_params['Datetime.DTT_EVT_end'];
773
-            unset($where_params['Datetime.DTT_EVT_end']);
774
-        }
775
-        if (isset($where_params['Datetime.DTT_EVT_start'])) {
776
-            $where_params['AND']['Datetime.DTT_EVT_start'] = $where_params['Datetime.DTT_EVT_start'];
777
-            unset($where_params['Datetime.DTT_EVT_start']);
778
-        }
779
-        return $this->_get_count_or_all($query_params, $where_params, $count);
780
-    }
781
-
782
-
783
-    /**
784
-     * This is just injecting into the parent add_relationship_to so we do special handling on price relationships
785
-     * because we don't want to override any existing global default prices but instead insert NEW prices that get
786
-     * attached to the event. See parent for param descriptions
787
-     *
788
-     * @param        $id_or_obj
789
-     * @param        $other_model_id_or_obj
790
-     * @param string $relationName
791
-     * @param array  $where_query
792
-     * @return EE_Base_Class
793
-     * @throws EE_Error
794
-     * @throws ReflectionException
795
-     */
796
-    public function add_relationship_to($id_or_obj, $other_model_id_or_obj, $relationName, $where_query = [])
797
-    {
798
-        if ($relationName === 'Price') {
799
-            // let's get the PRC object for the given ID to make sure that we aren't dealing with a default
800
-            $prc_chk = $this->get_related_model_obj($relationName)->ensure_is_obj($other_model_id_or_obj);
801
-            // if EVT_ID = 0, then this is a default
802
-            if ((int) $prc_chk->get('EVT_ID') === 0) {
803
-                // let's set the prc_id as 0 so we force an insert on the add_relation_to carried out by relation
804
-                $prc_chk->set('PRC_ID', 0);
805
-            }
806
-            // run parent
807
-            return parent::add_relationship_to($id_or_obj, $prc_chk, $relationName, $where_query);
808
-        }
809
-        // otherwise carry on as normal
810
-        return parent::add_relationship_to($id_or_obj, $other_model_id_or_obj, $relationName, $where_query);
811
-    }
812
-
813
-
814
-    /**
815
-     * @param array $where_params
816
-     * @return array
817
-     */
818
-    public function set_where_conditions_for_status(array $where_params): array
819
-    {
820
-        // let's add specific query_params for active_events
821
-        // keep in mind this will override any sent status in the query AND any date queries.
822
-        // we need to pull events with a status of publish and sold_out
823
-        $event_status = ['publish', EEM_Event::sold_out];
824
-        // check if the user can read private events and if so add the 'private status to the where params'
825
-        if (EE_Registry::instance()->CAP->current_user_can('ee_read_private_events', 'get_upcoming_events')) {
826
-            $event_status[] = 'private';
827
-        }
828
-        $where_params['status'] = ['IN', $event_status];
829
-        return $where_params;
830
-    }
831
-
832
-
833
-    /**
834
-     * @param array $where_params
835
-     * @return array
836
-     * @throws EE_Error
837
-     * @throws ReflectionException
838
-     */
839
-    public function set_where_conditions_for_end_datetime(array $where_params): array
840
-    {
841
-        $end_date_field_name = isset($where_params['Datetime.DTT_EVT_end'])
842
-            ? 'Datetime.DTT_EVT_end*****'
843
-            // prevents overwrite of existing where condition
844
-            : 'Datetime.DTT_EVT_end';
845
-
846
-        $where_params[ $end_date_field_name ] = [
847
-            '>',
848
-            EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'),
849
-        ];
850
-
851
-        return $where_params;
852
-    }
853
-
854
-
855
-    /**
856
-     * @param array $query_params
857
-     * @param array $where_params
858
-     * @param bool  $count
859
-     * @return EE_Soft_Delete_Base_Class[]|int
860
-     * @throws EE_Error
861
-     * @throws ReflectionException
862
-     */
863
-    protected function _get_count_or_all(array $query_params, array $where_params, bool $count = false)
864
-    {
865
-        $query_params[0] = $where_params;
866
-        // don't use $query_params with count()
867
-        // because we don't want to include additional query clauses like "GROUP BY"
868
-        return $count
869
-            ? $this->count([$where_params], 'EVT_ID', true)
870
-            : $this->get_all($query_params);
871
-    }
872
-
873
-
874
-    /******************** DEPRECATED METHODS ********************/
875
-
876
-
877
-    /**
878
-     * _get_question_target_db_column
879
-     *
880
-     * @param EE_Registration $registration    (so existing answers for registration are included)
881
-     * @param int             $EVT_ID          so all question groups are included for event (not just answers from
882
-     *                                         registration).
883
-     * @return    array
884
-     * @throws ReflectionException
885
-     * @throws EE_Error
886
-     * @deprecated as of 4.8.32.rc.001. Instead consider using
887
-     *                                         EE_Registration_Custom_Questions_Form located in
888
-     *                                         admin_pages/registrations/form_sections/EE_Registration_Custom_Questions_Form.form.php
889
-     * @access     public
890
-     */
891
-    public function assemble_array_of_groups_questions_and_options(EE_Registration $registration, $EVT_ID = 0)
892
-    {
893
-        if (empty($EVT_ID)) {
894
-            throw new EE_Error(
895
-                esc_html__(
896
-                    'An error occurred. No EVT_ID is included.  Needed to know which question groups to retrieve.',
897
-                    'event_espresso'
898
-                )
899
-            );
900
-        }
901
-        $questions = [];
902
-        // get all question groups for event
903
-        $qgs = $this->get_question_groups_for_event($EVT_ID, $registration);
904
-        if (! empty($qgs)) {
905
-            foreach ($qgs as $qg) {
906
-                $qsts                                    = $qg->questions();
907
-                $questions[ $qg->ID() ]                  = $qg->model_field_array();
908
-                $questions[ $qg->ID() ]['QSG_questions'] = [];
909
-                foreach ($qsts as $qst) {
910
-                    if ($qst->is_system_question()) {
911
-                        continue;
912
-                    }
913
-                    $answer                                                                   =
914
-                        EEM_Answer::instance()->get_one(
915
-                            [
916
-                                [
917
-                                    'QST_ID' => $qst->ID(),
918
-                                    'REG_ID' => $registration->ID(),
919
-                                ],
920
-                            ]
921
-                        );
922
-                    $answer                                                                   =
923
-                        $answer instanceof EE_Answer
924
-                            ? $answer
925
-                            : EEM_Answer::instance()->create_default_object();
926
-                    $qst_name                                                                 = $qstn_id = $qst->ID();
927
-                    $ans_id                                                                   = $answer->ID();
928
-                    $qst_name                                                                 = ! empty($ans_id)
929
-                        ? '[' . $qst_name . '][' . $ans_id . ']'
930
-                        : '[' . $qst_name . ']';
931
-                    $input_name                                                               = '';
932
-                    $input_id                                                                 =
933
-                        sanitize_key($qst->display_text());
934
-                    $input_class                                                              = '';
935
-                    $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]                    =
936
-                        $qst->model_field_array();
937
-                    $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_input_name']  = 'qstn'
938
-                                                                                                . $input_name
939
-                                                                                                . $qst_name;
940
-                    $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_input_id']    =
941
-                        $input_id . '-' . $qstn_id;
942
-                    $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_input_class'] = $input_class;
943
-                    $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_options']     = [];
944
-                    $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['qst_obj']         = $qst;
945
-                    $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['ans_obj']         = $answer;
946
-                    // leave responses as-is, don't convert stuff into html entities please!
947
-                    $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['htmlentities'] = false;
948
-                    if ($qst->type() == 'RADIO_BTN' || $qst->type() == 'CHECKBOX' || $qst->type() == 'DROPDOWN') {
949
-                        $QSOs = $qst->options(true, $answer->value());
950
-                        if (is_array($QSOs)) {
951
-                            foreach ($QSOs as $QSO_ID => $QSO) {
952
-                                $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_options'][ $QSO_ID ] =
953
-                                    $QSO->model_field_array();
954
-                            }
955
-                        }
956
-                    }
957
-                }
958
-            }
959
-        }
960
-        return $questions;
961
-    }
962
-
963
-
964
-    /**
965
-     * @param mixed $cols_n_values either an array of where each key is the name of a field, and the value is its value
966
-     *                             or an stdClass where each property is the name of a column,
967
-     * @return EE_Base_Class
968
-     * @throws EE_Error
969
-     * @throws ReflectionException
970
-     */
971
-    public function instantiate_class_from_array_or_object($cols_n_values)
972
-    {
973
-        $classInstance = parent::instantiate_class_from_array_or_object($cols_n_values);
974
-        if ($classInstance instanceof EE_Event) {
975
-            // events have their timezone defined in the DB, so use it immediately
976
-            $this->set_timezone($classInstance->get_timezone());
977
-        }
978
-        return $classInstance;
979
-    }
16
+	/**
17
+	 * constant used by status(), indicating that no more tickets can be purchased for any of the datetimes for the
18
+	 * event
19
+	 */
20
+	const sold_out = 'sold_out';
21
+
22
+	/**
23
+	 * constant used by status(), indicating that upcoming event dates have been postponed (may be pushed to a later
24
+	 * date)
25
+	 */
26
+	const postponed = 'postponed';
27
+
28
+	/**
29
+	 * constant used by status(), indicating that the event will no longer occur
30
+	 */
31
+	const cancelled = 'cancelled';
32
+
33
+
34
+	/**
35
+	 * @var string
36
+	 */
37
+	protected static $_default_reg_status;
38
+
39
+
40
+	/**
41
+	 * This is the default for the additional limit field.
42
+	 *
43
+	 * @var int
44
+	 */
45
+	protected static $_default_additional_limit = 10;
46
+
47
+
48
+	/**
49
+	 * private instance of the Event object
50
+	 *
51
+	 * @var EEM_Event
52
+	 */
53
+	protected static $_instance;
54
+
55
+
56
+	/**
57
+	 * Adds a relationship to Term_Taxonomy for each CPT_Base
58
+	 *
59
+	 * @param string|null $timezone
60
+	 * @throws EE_Error
61
+	 * @throws ReflectionException
62
+	 */
63
+	protected function __construct(?string $timezone = '')
64
+	{
65
+		EE_Registry::instance()->load_model('Registration');
66
+		$this->singular_item = esc_html__('Event', 'event_espresso');
67
+		$this->plural_item   = esc_html__('Events', 'event_espresso');
68
+		// to remove Cancelled events from the frontend, copy the following filter to your functions.php file
69
+		// add_filter( 'AFEE__EEM_Event__construct___custom_stati__cancelled__Public', '__return_false' );
70
+		// to remove Postponed events from the frontend, copy the following filter to your functions.php file
71
+		// add_filter( 'AFEE__EEM_Event__construct___custom_stati__postponed__Public', '__return_false' );
72
+		// to remove Sold Out events from the frontend, copy the following filter to your functions.php file
73
+		//  add_filter( 'AFEE__EEM_Event__construct___custom_stati__sold_out__Public', '__return_false' );
74
+		$this->_custom_stati       = apply_filters(
75
+			'AFEE__EEM_Event__construct___custom_stati',
76
+			[
77
+				EEM_Event::cancelled => [
78
+					'label'  => esc_html__('Cancelled', 'event_espresso'),
79
+					'public' => apply_filters('AFEE__EEM_Event__construct___custom_stati__cancelled__Public', true),
80
+				],
81
+				EEM_Event::postponed => [
82
+					'label'  => esc_html__('Postponed', 'event_espresso'),
83
+					'public' => apply_filters('AFEE__EEM_Event__construct___custom_stati__postponed__Public', true),
84
+				],
85
+				EEM_Event::sold_out  => [
86
+					'label'  => esc_html__('Sold Out', 'event_espresso'),
87
+					'public' => apply_filters('AFEE__EEM_Event__construct___custom_stati__sold_out__Public', true),
88
+				],
89
+			]
90
+		);
91
+		self::$_default_reg_status = empty(self::$_default_reg_status)
92
+			? EEM_Registration::status_id_pending_payment
93
+			: self::$_default_reg_status;
94
+		$this->_tables             = [
95
+			'Event_CPT'  => new EE_Primary_Table('posts', 'ID'),
96
+			'Event_Meta' => new EE_Secondary_Table('esp_event_meta', 'EVTM_ID', 'EVT_ID'),
97
+		];
98
+		$this->_fields             = [
99
+			'Event_CPT'  => [
100
+				'EVT_ID'         => new EE_Primary_Key_Int_Field(
101
+					'ID',
102
+					esc_html__('Post ID for Event', 'event_espresso')
103
+				),
104
+				'EVT_name'       => new EE_Plain_Text_Field(
105
+					'post_title',
106
+					esc_html__('Event Name', 'event_espresso'),
107
+					false,
108
+					''
109
+				),
110
+				'EVT_desc'       => new EE_Post_Content_Field(
111
+					'post_content',
112
+					esc_html__('Event Description', 'event_espresso'),
113
+					false,
114
+					''
115
+				),
116
+				'EVT_slug'       => new EE_Slug_Field(
117
+					'post_name',
118
+					esc_html__('Event Slug', 'event_espresso'),
119
+					false,
120
+					''
121
+				),
122
+				'EVT_created'    => new EE_Datetime_Field(
123
+					'post_date',
124
+					esc_html__('Date/Time Event Created', 'event_espresso'),
125
+					false,
126
+					EE_Datetime_Field::now
127
+				),
128
+				'EVT_short_desc' => new EE_Simple_HTML_Field(
129
+					'post_excerpt',
130
+					esc_html__('Event Short Description', 'event_espresso'),
131
+					false,
132
+					''
133
+				),
134
+				'EVT_modified'   => new EE_Datetime_Field(
135
+					'post_modified',
136
+					esc_html__('Date/Time Event Modified', 'event_espresso'),
137
+					false,
138
+					EE_Datetime_Field::now
139
+				),
140
+				'EVT_wp_user'    => new EE_WP_User_Field(
141
+					'post_author',
142
+					esc_html__('Event Creator ID', 'event_espresso'),
143
+					false
144
+				),
145
+				'parent'         => new EE_Integer_Field(
146
+					'post_parent',
147
+					esc_html__('Event Parent ID', 'event_espresso'),
148
+					false,
149
+					0
150
+				),
151
+				'EVT_order'      => new EE_Integer_Field(
152
+					'menu_order',
153
+					esc_html__('Event Menu Order', 'event_espresso'),
154
+					false,
155
+					1
156
+				),
157
+				'post_type'      => new EE_WP_Post_Type_Field('espresso_events'),
158
+				// EE_Plain_Text_Field( 'post_type', esc_html__( 'Event Post Type', 'event_espresso' ), FALSE, 'espresso_events' ),
159
+				'status'         => new EE_WP_Post_Status_Field(
160
+					'post_status',
161
+					esc_html__('Event Status', 'event_espresso'),
162
+					false,
163
+					'draft',
164
+					$this->_custom_stati
165
+				),
166
+				'password'       => new EE_Password_Field(
167
+					'post_password',
168
+					esc_html__('Password', 'event_espresso'),
169
+					false,
170
+					'',
171
+					[
172
+						'EVT_desc',
173
+						'EVT_short_desc',
174
+						'EVT_display_desc',
175
+						'EVT_display_ticket_selector',
176
+						'EVT_visible_on',
177
+						'EVT_additional_limit',
178
+						'EVT_default_registration_status',
179
+						'EVT_member_only',
180
+						'EVT_phone',
181
+						'EVT_allow_overflow',
182
+						'EVT_timezone_string',
183
+						'EVT_external_URL',
184
+						'EVT_donations',
185
+					]
186
+				),
187
+			],
188
+			'Event_Meta' => [
189
+				'EVTM_ID'                         => new EE_DB_Only_Float_Field(
190
+					'EVTM_ID',
191
+					esc_html__('Event Meta Row ID', 'event_espresso'),
192
+					false
193
+				),
194
+				'EVT_ID_fk'                       => new EE_DB_Only_Int_Field(
195
+					'EVT_ID',
196
+					esc_html__('Foreign key to Event ID from Event Meta table', 'event_espresso'),
197
+					false
198
+				),
199
+				'VNU_ID'                          => new EE_Foreign_Key_Int_Field(
200
+					'VNU_ID',
201
+					__('Venue ID', 'event_espresso'),
202
+					false,
203
+					0,
204
+					'Venue'
205
+				),
206
+				'EVT_display_desc'                => new EE_Boolean_Field(
207
+					'EVT_display_desc',
208
+					esc_html__('Display Description Flag', 'event_espresso'),
209
+					false,
210
+					true
211
+				),
212
+				'EVT_display_ticket_selector'     => new EE_Boolean_Field(
213
+					'EVT_display_ticket_selector',
214
+					esc_html__('Display Ticket Selector Flag', 'event_espresso'),
215
+					false,
216
+					true
217
+				),
218
+				'EVT_visible_on'                  => new EE_Datetime_Field(
219
+					'EVT_visible_on',
220
+					esc_html__('Event Visible Date', 'event_espresso'),
221
+					true,
222
+					EE_Datetime_Field::now
223
+				),
224
+				'EVT_additional_limit'            => new EE_Integer_Field(
225
+					'EVT_additional_limit',
226
+					esc_html__('Limit of Additional Registrations on Same Transaction', 'event_espresso'),
227
+					false,
228
+					self::$_default_additional_limit
229
+				),
230
+				'EVT_default_registration_status' => new EE_Enum_Text_Field(
231
+					'EVT_default_registration_status',
232
+					esc_html__('Default Registration Status on this Event', 'event_espresso'),
233
+					false,
234
+					EEM_Event::$_default_reg_status,
235
+					EEM_Registration::reg_status_array()
236
+				),
237
+				'EVT_member_only'                 => new EE_Boolean_Field(
238
+					'EVT_member_only',
239
+					esc_html__('Member-Only Event Flag', 'event_espresso'),
240
+					false,
241
+					false
242
+				),
243
+				'EVT_phone'                       => new EE_Plain_Text_Field(
244
+					'EVT_phone',
245
+					esc_html__('Event Phone Number', 'event_espresso'),
246
+					false,
247
+					''
248
+				),
249
+				'EVT_allow_overflow'              => new EE_Boolean_Field(
250
+					'EVT_allow_overflow',
251
+					esc_html__('Allow Overflow on Event', 'event_espresso'),
252
+					false,
253
+					false
254
+				),
255
+				'EVT_timezone_string'             => new EE_Plain_Text_Field(
256
+					'EVT_timezone_string',
257
+					esc_html__('Timezone (name) for Event times', 'event_espresso'),
258
+					false,
259
+					''
260
+				),
261
+				'EVT_external_URL'                => new EE_Plain_Text_Field(
262
+					'EVT_external_URL',
263
+					esc_html__('URL of Event Page if hosted elsewhere', 'event_espresso'),
264
+					true
265
+				),
266
+				'EVT_donations'                   => new EE_Boolean_Field(
267
+					'EVT_donations',
268
+					esc_html__('Accept Donations?', 'event_espresso'),
269
+					false,
270
+					false
271
+				),
272
+				'FSC_UUID'                        => new EE_Foreign_Key_String_Field(
273
+					'FSC_UUID',
274
+					esc_html__('Registration Form UUID (universally unique identifier)', 'event_espresso'),
275
+					true,
276
+					null,
277
+					'Form_Section',
278
+					false
279
+				),
280
+			],
281
+		];
282
+		$this->_model_relations    = [
283
+			'Attendee'               => new EE_HABTM_Relation('Registration'),
284
+			'Datetime'               => new EE_Has_Many_Relation(),
285
+			'Event_Question_Group'   => new EE_Has_Many_Relation(),
286
+			'Form_Section'           => new EE_Belongs_To_Relation(),
287
+			'Message_Template_Group' => new EE_HABTM_Relation('Event_Message_Template'),
288
+			'Question_Group'         => new EE_HABTM_Relation('Event_Question_Group'),
289
+			'Registration'           => new EE_Has_Many_Relation(),
290
+			'Term_Relationship'      => new EE_Has_Many_Relation(),
291
+			'Term_Taxonomy'          => new EE_HABTM_Relation('Term_Relationship'),
292
+			'Venue'                  => new EE_Belongs_To_Relation(),
293
+			'WP_User'                => new EE_Belongs_To_Relation(),
294
+		];
295
+		// this model is generally available for reading
296
+		$this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public();
297
+		$this->model_chain_to_password                            = '';
298
+		parent::__construct($timezone);
299
+	}
300
+
301
+
302
+	/**
303
+	 * @param string $default_reg_status
304
+	 * @throws EE_Error
305
+	 * @throws EE_Error
306
+	 */
307
+	public static function set_default_reg_status($default_reg_status)
308
+	{
309
+		self::$_default_reg_status = $default_reg_status;
310
+		// if EEM_Event has already been instantiated,
311
+		// then we need to reset the `EVT_default_reg_status` field to use the new default.
312
+		if (self::$_instance instanceof EEM_Event) {
313
+			$default_reg_status = new EE_Enum_Text_Field(
314
+				'EVT_default_registration_status',
315
+				esc_html__('Default Registration Status on this Event', 'event_espresso'),
316
+				false,
317
+				$default_reg_status,
318
+				EEM_Registration::reg_status_array()
319
+			);
320
+			$default_reg_status->_construct_finalize(
321
+				'Event_Meta',
322
+				'EVT_default_registration_status',
323
+				'EEM_Event'
324
+			);
325
+			self::$_instance->_fields['Event_Meta']['EVT_default_registration_status'] = $default_reg_status;
326
+		}
327
+	}
328
+
329
+
330
+	/**
331
+	 * Used to override the default for the additional limit field.
332
+	 *
333
+	 * @param $additional_limit
334
+	 */
335
+	public static function set_default_additional_limit($additional_limit)
336
+	{
337
+		self::$_default_additional_limit = (int) $additional_limit;
338
+		if (self::$_instance instanceof EEM_Event) {
339
+			self::$_instance->_fields['Event_Meta']['EVT_additional_limit'] = new EE_Integer_Field(
340
+				'EVT_additional_limit',
341
+				esc_html__('Limit of Additional Registrations on Same Transaction', 'event_espresso'),
342
+				false,
343
+				self::$_default_additional_limit
344
+			);
345
+			self::$_instance->_fields['Event_Meta']['EVT_additional_limit']->_construct_finalize(
346
+				'Event_Meta',
347
+				'EVT_additional_limit',
348
+				'EEM_Event'
349
+			);
350
+		}
351
+	}
352
+
353
+
354
+	/**
355
+	 * Return what is currently set as the default additional limit for the event.
356
+	 *
357
+	 * @return int
358
+	 */
359
+	public static function get_default_additional_limit()
360
+	{
361
+		return apply_filters('FHEE__EEM_Event__get_default_additional_limit', self::$_default_additional_limit);
362
+	}
363
+
364
+
365
+	/**
366
+	 * get_question_groups
367
+	 *
368
+	 * @return array
369
+	 * @throws EE_Error
370
+	 * @throws ReflectionException
371
+	 */
372
+	public function get_all_question_groups()
373
+	{
374
+		return EE_Registry::instance()->load_model('Question_Group')->get_all(
375
+			[
376
+				['QSG_deleted' => false],
377
+				'order_by' => ['QSG_order' => 'ASC'],
378
+			]
379
+		);
380
+	}
381
+
382
+
383
+	/**
384
+	 * get_question_groups
385
+	 *
386
+	 * @param int $EVT_ID
387
+	 * @return array|bool
388
+	 * @throws EE_Error
389
+	 * @throws ReflectionException
390
+	 */
391
+	public function get_all_event_question_groups($EVT_ID = 0)
392
+	{
393
+		if (! isset($EVT_ID) || ! absint($EVT_ID)) {
394
+			EE_Error::add_error(
395
+				esc_html__(
396
+					'An error occurred. No Event Question Groups could be retrieved because an Event ID was not received.',
397
+					'event_espresso'
398
+				),
399
+				__FILE__,
400
+				__FUNCTION__,
401
+				__LINE__
402
+			);
403
+			return false;
404
+		}
405
+		return EE_Registry::instance()->load_model('Event_Question_Group')->get_all(
406
+			[
407
+				['EVT_ID' => $EVT_ID],
408
+			]
409
+		);
410
+	}
411
+
412
+
413
+	/**
414
+	 * get_question_groups
415
+	 *
416
+	 * @param int     $EVT_ID
417
+	 * @param boolean $for_primary_attendee
418
+	 * @return array|bool
419
+	 * @throws EE_Error
420
+	 * @throws InvalidArgumentException
421
+	 * @throws ReflectionException
422
+	 * @throws InvalidDataTypeException
423
+	 * @throws InvalidInterfaceException
424
+	 */
425
+	public function get_event_question_groups($EVT_ID = 0, $for_primary_attendee = true)
426
+	{
427
+		if (! isset($EVT_ID) || ! absint($EVT_ID)) {
428
+			EE_Error::add_error(
429
+				esc_html__(
430
+				// @codingStandardsIgnoreStart
431
+					'An error occurred. No Event Question Groups could be retrieved because an Event ID was not received.',
432
+					// @codingStandardsIgnoreEnd
433
+					'event_espresso'
434
+				),
435
+				__FILE__,
436
+				__FUNCTION__,
437
+				__LINE__
438
+			);
439
+			return false;
440
+		}
441
+		$query_params = [
442
+			[
443
+				'EVT_ID'                                                                         => $EVT_ID,
444
+				EEM_Event_Question_Group::instance()->fieldNameForContext($for_primary_attendee) => true,
445
+			],
446
+		];
447
+		if ($for_primary_attendee) {
448
+			$query_params[0]['EQG_primary'] = true;
449
+		} else {
450
+			$query_params[0]['EQG_additional'] = true;
451
+		}
452
+		return EE_Registry::instance()->load_model('Event_Question_Group')->get_all($query_params);
453
+	}
454
+
455
+
456
+	/**
457
+	 * get_question_groups
458
+	 *
459
+	 * @param int             $EVT_ID
460
+	 * @param EE_Registration $registration
461
+	 * @return array|bool
462
+	 * @throws EE_Error
463
+	 * @throws InvalidArgumentException
464
+	 * @throws InvalidDataTypeException
465
+	 * @throws InvalidInterfaceException
466
+	 * @throws ReflectionException
467
+	 */
468
+	public function get_question_groups_for_event($EVT_ID, EE_Registration $registration)
469
+	{
470
+		if (! absint($EVT_ID)) {
471
+			EE_Error::add_error(
472
+				esc_html__(
473
+					'An error occurred. No Question Groups could be retrieved because an Event ID was not received.',
474
+					'event_espresso'
475
+				),
476
+				__FILE__,
477
+				__FUNCTION__,
478
+				__LINE__
479
+			);
480
+			return false;
481
+		}
482
+		return EE_Registry::instance()->load_model('Question_Group')->get_all(
483
+			[
484
+				[
485
+					'Event_Question_Group.EVT_ID' => $EVT_ID,
486
+					'Event_Question_Group.'
487
+					. EEM_Event_Question_Group::instance()->fieldNameForContext(
488
+						$registration->is_primary_registrant()
489
+					)                             => true,
490
+				],
491
+				'order_by' => ['QSG_order' => 'ASC'],
492
+			]
493
+		);
494
+	}
495
+
496
+
497
+	/**
498
+	 * get_question_target_db_column
499
+	 *
500
+	 * @param string $QSG_IDs csv list of $QSG IDs
501
+	 * @return array|bool
502
+	 * @throws EE_Error
503
+	 * @throws ReflectionException
504
+	 */
505
+	public function get_questions_in_groups($QSG_IDs = '')
506
+	{
507
+		if (empty($QSG_IDs)) {
508
+			EE_Error::add_error(
509
+				esc_html__('An error occurred. No Question Group IDs were received.', 'event_espresso'),
510
+				__FILE__,
511
+				__FUNCTION__,
512
+				__LINE__
513
+			);
514
+			return false;
515
+		}
516
+		return EE_Registry::instance()->load_model('Question')->get_all(
517
+			[
518
+				[
519
+					'Question_Group.QSG_ID' => ['IN', $QSG_IDs],
520
+					'QST_deleted'           => false,
521
+					'QST_admin_only'        => is_admin(),
522
+				],
523
+				'order_by' => 'QST_order',
524
+			]
525
+		);
526
+	}
527
+
528
+
529
+	/**
530
+	 * get_options_for_question
531
+	 *
532
+	 * @param string $QST_IDs csv list of $QST IDs
533
+	 * @return array|bool
534
+	 * @throws EE_Error
535
+	 * @throws ReflectionException
536
+	 */
537
+	public function get_options_for_question($QST_IDs)
538
+	{
539
+		if (empty($QST_IDs)) {
540
+			EE_Error::add_error(
541
+				esc_html__('An error occurred. No Question IDs were received.', 'event_espresso'),
542
+				__FILE__,
543
+				__FUNCTION__,
544
+				__LINE__
545
+			);
546
+			return false;
547
+		}
548
+		return EE_Registry::instance()->load_model('Question_Option')->get_all(
549
+			[
550
+				[
551
+					'Question.QST_ID' => ['IN', $QST_IDs],
552
+					'QSO_deleted'     => false,
553
+				],
554
+				'order_by' => 'QSO_ID',
555
+			]
556
+		);
557
+	}
558
+
559
+
560
+	/**
561
+	 * Gets all events that are published
562
+	 * and have event start time earlier than now and an event end time later than now
563
+	 *
564
+	 * @param array $query_params  An array of query params to further filter on
565
+	 *                             (note that status and DTT_EVT_start and DTT_EVT_end will be overridden)
566
+	 * @param bool  $count         whether to return the count or not (default FALSE)
567
+	 * @return EE_Event[]|int
568
+	 * @throws EE_Error
569
+	 * @throws ReflectionException
570
+	 */
571
+	public function get_active_events($query_params, $count = false)
572
+	{
573
+		if (array_key_exists(0, $query_params)) {
574
+			$where_params = $query_params[0];
575
+			unset($query_params[0]);
576
+		} else {
577
+			$where_params = [];
578
+		}
579
+		// if we have count make sure we don't include group by
580
+		if ($count && isset($query_params['group_by'])) {
581
+			unset($query_params['group_by']);
582
+		}
583
+		// add status query
584
+		$where_params = $this->set_where_conditions_for_status($where_params);
585
+		// if already have where params for DTT_EVT_start or DTT_EVT_end then append these conditions
586
+		if (isset($where_params['Datetime.DTT_EVT_start'])) {
587
+			$where_params['Datetime.DTT_EVT_start******'] = [
588
+				'<',
589
+				EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'),
590
+			];
591
+		} else {
592
+			$where_params['Datetime.DTT_EVT_start'] = [
593
+				'<',
594
+				EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'),
595
+			];
596
+		}
597
+		$where_params = $this->set_where_conditions_for_end_datetime($where_params);
598
+		return $this->_get_count_or_all($query_params, $where_params, $count);
599
+	}
600
+
601
+
602
+	/**
603
+	 * get all events that are published and have an event start time later than now
604
+	 *
605
+	 * @param array $query_params  An array of query params to further filter on
606
+	 *                             (Note that status and DTT_EVT_start will be overridden)
607
+	 * @param bool  $count         whether to return the count or not (default FALSE)
608
+	 * @return EE_Event[]|int
609
+	 * @throws EE_Error
610
+	 * @throws ReflectionException
611
+	 */
612
+	public function get_upcoming_events($query_params, $count = false)
613
+	{
614
+		if (array_key_exists(0, $query_params)) {
615
+			$where_params = $query_params[0];
616
+			unset($query_params[0]);
617
+		} else {
618
+			$where_params = [];
619
+		}
620
+		// if we have count make sure we don't include group by
621
+		if ($count && isset($query_params['group_by'])) {
622
+			unset($query_params['group_by']);
623
+		}
624
+		// add status query
625
+		$where_params = $this->set_where_conditions_for_status($where_params);
626
+		// if there are already query_params matching DTT_EVT_start then we need to modify that to add them.
627
+		if (isset($where_params['Datetime.DTT_EVT_start'])) {
628
+			$where_params['Datetime.DTT_EVT_start*****'] = [
629
+				'>',
630
+				EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'),
631
+			];
632
+		} else {
633
+			$where_params['Datetime.DTT_EVT_start'] = [
634
+				'>',
635
+				EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'),
636
+			];
637
+		}
638
+		return $this->_get_count_or_all($query_params, $where_params, $count);
639
+	}
640
+
641
+
642
+	/**
643
+	 * Gets all events that are published
644
+	 * and have an event end time later than now
645
+	 *
646
+	 * @param array $query_params  An array of query params to further filter on
647
+	 *                             (note that status and DTT_EVT_end will be overridden)
648
+	 * @param bool  $count         whether to return the count or not (default FALSE)
649
+	 * @return EE_Event[]|int
650
+	 * @throws EE_Error
651
+	 * @throws ReflectionException
652
+	 */
653
+	public function get_active_and_upcoming_events($query_params, $count = false)
654
+	{
655
+		if (array_key_exists(0, $query_params)) {
656
+			$where_params = $query_params[0];
657
+			unset($query_params[0]);
658
+		} else {
659
+			$where_params = [];
660
+		}
661
+		// if we have count make sure we don't include group by
662
+		if ($count && isset($query_params['group_by'])) {
663
+			unset($query_params['group_by']);
664
+		}
665
+		// add status query
666
+		$where_params = $this->set_where_conditions_for_status($where_params);
667
+		// add where params for DTT_EVT_end
668
+		$where_params = $this->set_where_conditions_for_end_datetime($where_params);
669
+		return $this->_get_count_or_all($query_params, $where_params, $count);
670
+	}
671
+
672
+
673
+	/**
674
+	 * This only returns events that are expired.
675
+	 * They may still be published but all their datetimes have expired.
676
+	 *
677
+	 * @param array $query_params  An array of query params to further filter on
678
+	 *                             (note that status and DTT_EVT_end will be overridden)
679
+	 * @param bool  $count         whether to return the count or not (default FALSE)
680
+	 * @return EE_Event[]|int
681
+	 * @throws EE_Error
682
+	 * @throws ReflectionException
683
+	 */
684
+	public function get_expired_events($query_params, $count = false)
685
+	{
686
+		$where_params = isset($query_params[0])
687
+			? $query_params[0]
688
+			: [];
689
+		// if we have count make sure we don't include group by
690
+		if ($count && isset($query_params['group_by'])) {
691
+			unset($query_params['group_by']);
692
+		}
693
+		// let's add specific query_params for active_events
694
+		// keep in mind this will override any sent status in the query AND any date queries.
695
+		if (isset($where_params['status'])) {
696
+			unset($where_params['status']);
697
+		}
698
+		// first get all events that have datetimes where its not expired.
699
+		$event_ids = $this->get_all_not_expired_event_ids($query_params);
700
+		// if we have any additional query_params, let's add them to the 'AND' condition
701
+		$and_condition = [
702
+			'Datetime.DTT_EVT_end' => ['<', EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end')],
703
+			'EVT_ID'               => ['NOT IN', $event_ids],
704
+		];
705
+		if (isset($where_params['OR'])) {
706
+			$and_condition['OR'] = $where_params['OR'];
707
+			unset($where_params['OR']);
708
+		}
709
+		if (isset($where_params['Datetime.DTT_EVT_end'])) {
710
+			$and_condition['Datetime.DTT_EVT_end****'] = $where_params['Datetime.DTT_EVT_end'];
711
+			unset($where_params['Datetime.DTT_EVT_end']);
712
+		}
713
+		if (isset($where_params['Datetime.DTT_EVT_start'])) {
714
+			$and_condition['Datetime.DTT_EVT_start'] = $where_params['Datetime.DTT_EVT_start'];
715
+			unset($where_params['Datetime.DTT_EVT_start']);
716
+		}
717
+		// merge remaining $where params with the and conditions.
718
+		$where_params['AND'] = array_merge($and_condition, $where_params);
719
+		return $this->_get_count_or_all($query_params, $where_params, $count);
720
+	}
721
+
722
+
723
+	/**
724
+	 * @param array $query_params
725
+	 * @return int[]
726
+	 * @throws EE_Error
727
+	 * @throws ReflectionException
728
+	 */
729
+	public function get_all_not_expired_event_ids(array $query_params = []): array
730
+	{
731
+		$query_params[0] = [
732
+			'Datetime.DTT_EVT_end' => [
733
+				'>',
734
+				EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'),
735
+			],
736
+		];
737
+		$event_ids       = $this->_get_all_wpdb_results($query_params, OBJECT_K, 'Event_CPT.ID');
738
+		return array_keys($event_ids);
739
+	}
740
+
741
+
742
+	/**
743
+	 * This basically just returns the events that do not have the publish status.
744
+	 *
745
+	 * @param array   $query_params  An array of query params to further filter on
746
+	 *                               (note that status will be overwritten)
747
+	 * @param boolean $count         whether to return the count or not (default FALSE)
748
+	 * @return EE_Event[]|int
749
+	 * @throws EE_Error
750
+	 * @throws ReflectionException
751
+	 */
752
+	public function get_inactive_events($query_params, $count = false)
753
+	{
754
+		$where_params = isset($query_params[0])
755
+			? $query_params[0]
756
+			: [];
757
+		// let's add in specific query_params for inactive events.
758
+		if (isset($where_params['status'])) {
759
+			unset($where_params['status']);
760
+		}
761
+		// if we have count make sure we don't include group by
762
+		if ($count && isset($query_params['group_by'])) {
763
+			unset($query_params['group_by']);
764
+		}
765
+		// if we have any additional query_params, let's add them to the 'AND' condition
766
+		$where_params['AND']['status'] = ['!=', 'publish'];
767
+		if (isset($where_params['OR'])) {
768
+			$where_params['AND']['OR'] = $where_params['OR'];
769
+			unset($where_params['OR']);
770
+		}
771
+		if (isset($where_params['Datetime.DTT_EVT_end'])) {
772
+			$where_params['AND']['Datetime.DTT_EVT_end****'] = $where_params['Datetime.DTT_EVT_end'];
773
+			unset($where_params['Datetime.DTT_EVT_end']);
774
+		}
775
+		if (isset($where_params['Datetime.DTT_EVT_start'])) {
776
+			$where_params['AND']['Datetime.DTT_EVT_start'] = $where_params['Datetime.DTT_EVT_start'];
777
+			unset($where_params['Datetime.DTT_EVT_start']);
778
+		}
779
+		return $this->_get_count_or_all($query_params, $where_params, $count);
780
+	}
781
+
782
+
783
+	/**
784
+	 * This is just injecting into the parent add_relationship_to so we do special handling on price relationships
785
+	 * because we don't want to override any existing global default prices but instead insert NEW prices that get
786
+	 * attached to the event. See parent for param descriptions
787
+	 *
788
+	 * @param        $id_or_obj
789
+	 * @param        $other_model_id_or_obj
790
+	 * @param string $relationName
791
+	 * @param array  $where_query
792
+	 * @return EE_Base_Class
793
+	 * @throws EE_Error
794
+	 * @throws ReflectionException
795
+	 */
796
+	public function add_relationship_to($id_or_obj, $other_model_id_or_obj, $relationName, $where_query = [])
797
+	{
798
+		if ($relationName === 'Price') {
799
+			// let's get the PRC object for the given ID to make sure that we aren't dealing with a default
800
+			$prc_chk = $this->get_related_model_obj($relationName)->ensure_is_obj($other_model_id_or_obj);
801
+			// if EVT_ID = 0, then this is a default
802
+			if ((int) $prc_chk->get('EVT_ID') === 0) {
803
+				// let's set the prc_id as 0 so we force an insert on the add_relation_to carried out by relation
804
+				$prc_chk->set('PRC_ID', 0);
805
+			}
806
+			// run parent
807
+			return parent::add_relationship_to($id_or_obj, $prc_chk, $relationName, $where_query);
808
+		}
809
+		// otherwise carry on as normal
810
+		return parent::add_relationship_to($id_or_obj, $other_model_id_or_obj, $relationName, $where_query);
811
+	}
812
+
813
+
814
+	/**
815
+	 * @param array $where_params
816
+	 * @return array
817
+	 */
818
+	public function set_where_conditions_for_status(array $where_params): array
819
+	{
820
+		// let's add specific query_params for active_events
821
+		// keep in mind this will override any sent status in the query AND any date queries.
822
+		// we need to pull events with a status of publish and sold_out
823
+		$event_status = ['publish', EEM_Event::sold_out];
824
+		// check if the user can read private events and if so add the 'private status to the where params'
825
+		if (EE_Registry::instance()->CAP->current_user_can('ee_read_private_events', 'get_upcoming_events')) {
826
+			$event_status[] = 'private';
827
+		}
828
+		$where_params['status'] = ['IN', $event_status];
829
+		return $where_params;
830
+	}
831
+
832
+
833
+	/**
834
+	 * @param array $where_params
835
+	 * @return array
836
+	 * @throws EE_Error
837
+	 * @throws ReflectionException
838
+	 */
839
+	public function set_where_conditions_for_end_datetime(array $where_params): array
840
+	{
841
+		$end_date_field_name = isset($where_params['Datetime.DTT_EVT_end'])
842
+			? 'Datetime.DTT_EVT_end*****'
843
+			// prevents overwrite of existing where condition
844
+			: 'Datetime.DTT_EVT_end';
845
+
846
+		$where_params[ $end_date_field_name ] = [
847
+			'>',
848
+			EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'),
849
+		];
850
+
851
+		return $where_params;
852
+	}
853
+
854
+
855
+	/**
856
+	 * @param array $query_params
857
+	 * @param array $where_params
858
+	 * @param bool  $count
859
+	 * @return EE_Soft_Delete_Base_Class[]|int
860
+	 * @throws EE_Error
861
+	 * @throws ReflectionException
862
+	 */
863
+	protected function _get_count_or_all(array $query_params, array $where_params, bool $count = false)
864
+	{
865
+		$query_params[0] = $where_params;
866
+		// don't use $query_params with count()
867
+		// because we don't want to include additional query clauses like "GROUP BY"
868
+		return $count
869
+			? $this->count([$where_params], 'EVT_ID', true)
870
+			: $this->get_all($query_params);
871
+	}
872
+
873
+
874
+	/******************** DEPRECATED METHODS ********************/
875
+
876
+
877
+	/**
878
+	 * _get_question_target_db_column
879
+	 *
880
+	 * @param EE_Registration $registration    (so existing answers for registration are included)
881
+	 * @param int             $EVT_ID          so all question groups are included for event (not just answers from
882
+	 *                                         registration).
883
+	 * @return    array
884
+	 * @throws ReflectionException
885
+	 * @throws EE_Error
886
+	 * @deprecated as of 4.8.32.rc.001. Instead consider using
887
+	 *                                         EE_Registration_Custom_Questions_Form located in
888
+	 *                                         admin_pages/registrations/form_sections/EE_Registration_Custom_Questions_Form.form.php
889
+	 * @access     public
890
+	 */
891
+	public function assemble_array_of_groups_questions_and_options(EE_Registration $registration, $EVT_ID = 0)
892
+	{
893
+		if (empty($EVT_ID)) {
894
+			throw new EE_Error(
895
+				esc_html__(
896
+					'An error occurred. No EVT_ID is included.  Needed to know which question groups to retrieve.',
897
+					'event_espresso'
898
+				)
899
+			);
900
+		}
901
+		$questions = [];
902
+		// get all question groups for event
903
+		$qgs = $this->get_question_groups_for_event($EVT_ID, $registration);
904
+		if (! empty($qgs)) {
905
+			foreach ($qgs as $qg) {
906
+				$qsts                                    = $qg->questions();
907
+				$questions[ $qg->ID() ]                  = $qg->model_field_array();
908
+				$questions[ $qg->ID() ]['QSG_questions'] = [];
909
+				foreach ($qsts as $qst) {
910
+					if ($qst->is_system_question()) {
911
+						continue;
912
+					}
913
+					$answer                                                                   =
914
+						EEM_Answer::instance()->get_one(
915
+							[
916
+								[
917
+									'QST_ID' => $qst->ID(),
918
+									'REG_ID' => $registration->ID(),
919
+								],
920
+							]
921
+						);
922
+					$answer                                                                   =
923
+						$answer instanceof EE_Answer
924
+							? $answer
925
+							: EEM_Answer::instance()->create_default_object();
926
+					$qst_name                                                                 = $qstn_id = $qst->ID();
927
+					$ans_id                                                                   = $answer->ID();
928
+					$qst_name                                                                 = ! empty($ans_id)
929
+						? '[' . $qst_name . '][' . $ans_id . ']'
930
+						: '[' . $qst_name . ']';
931
+					$input_name                                                               = '';
932
+					$input_id                                                                 =
933
+						sanitize_key($qst->display_text());
934
+					$input_class                                                              = '';
935
+					$questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]                    =
936
+						$qst->model_field_array();
937
+					$questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_input_name']  = 'qstn'
938
+																								. $input_name
939
+																								. $qst_name;
940
+					$questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_input_id']    =
941
+						$input_id . '-' . $qstn_id;
942
+					$questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_input_class'] = $input_class;
943
+					$questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_options']     = [];
944
+					$questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['qst_obj']         = $qst;
945
+					$questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['ans_obj']         = $answer;
946
+					// leave responses as-is, don't convert stuff into html entities please!
947
+					$questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['htmlentities'] = false;
948
+					if ($qst->type() == 'RADIO_BTN' || $qst->type() == 'CHECKBOX' || $qst->type() == 'DROPDOWN') {
949
+						$QSOs = $qst->options(true, $answer->value());
950
+						if (is_array($QSOs)) {
951
+							foreach ($QSOs as $QSO_ID => $QSO) {
952
+								$questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_options'][ $QSO_ID ] =
953
+									$QSO->model_field_array();
954
+							}
955
+						}
956
+					}
957
+				}
958
+			}
959
+		}
960
+		return $questions;
961
+	}
962
+
963
+
964
+	/**
965
+	 * @param mixed $cols_n_values either an array of where each key is the name of a field, and the value is its value
966
+	 *                             or an stdClass where each property is the name of a column,
967
+	 * @return EE_Base_Class
968
+	 * @throws EE_Error
969
+	 * @throws ReflectionException
970
+	 */
971
+	public function instantiate_class_from_array_or_object($cols_n_values)
972
+	{
973
+		$classInstance = parent::instantiate_class_from_array_or_object($cols_n_values);
974
+		if ($classInstance instanceof EE_Event) {
975
+			// events have their timezone defined in the DB, so use it immediately
976
+			$this->set_timezone($classInstance->get_timezone());
977
+		}
978
+		return $classInstance;
979
+	}
980 980
 }
Please login to merge, or discard this patch.
Spacing   +26 added lines, -26 removed lines patch added patch discarded remove patch
@@ -71,7 +71,7 @@  discard block
 block discarded – undo
71 71
         // add_filter( 'AFEE__EEM_Event__construct___custom_stati__postponed__Public', '__return_false' );
72 72
         // to remove Sold Out events from the frontend, copy the following filter to your functions.php file
73 73
         //  add_filter( 'AFEE__EEM_Event__construct___custom_stati__sold_out__Public', '__return_false' );
74
-        $this->_custom_stati       = apply_filters(
74
+        $this->_custom_stati = apply_filters(
75 75
             'AFEE__EEM_Event__construct___custom_stati',
76 76
             [
77 77
                 EEM_Event::cancelled => [
@@ -95,7 +95,7 @@  discard block
 block discarded – undo
95 95
             'Event_CPT'  => new EE_Primary_Table('posts', 'ID'),
96 96
             'Event_Meta' => new EE_Secondary_Table('esp_event_meta', 'EVTM_ID', 'EVT_ID'),
97 97
         ];
98
-        $this->_fields             = [
98
+        $this->_fields = [
99 99
             'Event_CPT'  => [
100 100
                 'EVT_ID'         => new EE_Primary_Key_Int_Field(
101 101
                     'ID',
@@ -279,7 +279,7 @@  discard block
 block discarded – undo
279 279
                 ),
280 280
             ],
281 281
         ];
282
-        $this->_model_relations    = [
282
+        $this->_model_relations = [
283 283
             'Attendee'               => new EE_HABTM_Relation('Registration'),
284 284
             'Datetime'               => new EE_Has_Many_Relation(),
285 285
             'Event_Question_Group'   => new EE_Has_Many_Relation(),
@@ -293,7 +293,7 @@  discard block
 block discarded – undo
293 293
             'WP_User'                => new EE_Belongs_To_Relation(),
294 294
         ];
295 295
         // this model is generally available for reading
296
-        $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public();
296
+        $this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Public();
297 297
         $this->model_chain_to_password                            = '';
298 298
         parent::__construct($timezone);
299 299
     }
@@ -390,7 +390,7 @@  discard block
 block discarded – undo
390 390
      */
391 391
     public function get_all_event_question_groups($EVT_ID = 0)
392 392
     {
393
-        if (! isset($EVT_ID) || ! absint($EVT_ID)) {
393
+        if ( ! isset($EVT_ID) || ! absint($EVT_ID)) {
394 394
             EE_Error::add_error(
395 395
                 esc_html__(
396 396
                     'An error occurred. No Event Question Groups could be retrieved because an Event ID was not received.',
@@ -424,7 +424,7 @@  discard block
 block discarded – undo
424 424
      */
425 425
     public function get_event_question_groups($EVT_ID = 0, $for_primary_attendee = true)
426 426
     {
427
-        if (! isset($EVT_ID) || ! absint($EVT_ID)) {
427
+        if ( ! isset($EVT_ID) || ! absint($EVT_ID)) {
428 428
             EE_Error::add_error(
429 429
                 esc_html__(
430 430
                 // @codingStandardsIgnoreStart
@@ -467,7 +467,7 @@  discard block
 block discarded – undo
467 467
      */
468 468
     public function get_question_groups_for_event($EVT_ID, EE_Registration $registration)
469 469
     {
470
-        if (! absint($EVT_ID)) {
470
+        if ( ! absint($EVT_ID)) {
471 471
             EE_Error::add_error(
472 472
                 esc_html__(
473 473
                     'An error occurred. No Question Groups could be retrieved because an Event ID was not received.',
@@ -734,7 +734,7 @@  discard block
 block discarded – undo
734 734
                 EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'),
735 735
             ],
736 736
         ];
737
-        $event_ids       = $this->_get_all_wpdb_results($query_params, OBJECT_K, 'Event_CPT.ID');
737
+        $event_ids = $this->_get_all_wpdb_results($query_params, OBJECT_K, 'Event_CPT.ID');
738 738
         return array_keys($event_ids);
739 739
     }
740 740
 
@@ -843,7 +843,7 @@  discard block
 block discarded – undo
843 843
             // prevents overwrite of existing where condition
844 844
             : 'Datetime.DTT_EVT_end';
845 845
 
846
-        $where_params[ $end_date_field_name ] = [
846
+        $where_params[$end_date_field_name] = [
847 847
             '>',
848 848
             EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'),
849 849
         ];
@@ -901,16 +901,16 @@  discard block
 block discarded – undo
901 901
         $questions = [];
902 902
         // get all question groups for event
903 903
         $qgs = $this->get_question_groups_for_event($EVT_ID, $registration);
904
-        if (! empty($qgs)) {
904
+        if ( ! empty($qgs)) {
905 905
             foreach ($qgs as $qg) {
906 906
                 $qsts                                    = $qg->questions();
907
-                $questions[ $qg->ID() ]                  = $qg->model_field_array();
908
-                $questions[ $qg->ID() ]['QSG_questions'] = [];
907
+                $questions[$qg->ID()]                  = $qg->model_field_array();
908
+                $questions[$qg->ID()]['QSG_questions'] = [];
909 909
                 foreach ($qsts as $qst) {
910 910
                     if ($qst->is_system_question()) {
911 911
                         continue;
912 912
                     }
913
-                    $answer                                                                   =
913
+                    $answer =
914 914
                         EEM_Answer::instance()->get_one(
915 915
                             [
916 916
                                 [
@@ -919,37 +919,37 @@  discard block
 block discarded – undo
919 919
                                 ],
920 920
                             ]
921 921
                         );
922
-                    $answer                                                                   =
922
+                    $answer =
923 923
                         $answer instanceof EE_Answer
924 924
                             ? $answer
925 925
                             : EEM_Answer::instance()->create_default_object();
926 926
                     $qst_name                                                                 = $qstn_id = $qst->ID();
927 927
                     $ans_id                                                                   = $answer->ID();
928 928
                     $qst_name                                                                 = ! empty($ans_id)
929
-                        ? '[' . $qst_name . '][' . $ans_id . ']'
930
-                        : '[' . $qst_name . ']';
929
+                        ? '['.$qst_name.']['.$ans_id.']'
930
+                        : '['.$qst_name.']';
931 931
                     $input_name                                                               = '';
932 932
                     $input_id                                                                 =
933 933
                         sanitize_key($qst->display_text());
934 934
                     $input_class                                                              = '';
935
-                    $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]                    =
935
+                    $questions[$qg->ID()]['QSG_questions'][$qst->ID()]                    =
936 936
                         $qst->model_field_array();
937
-                    $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_input_name']  = 'qstn'
937
+                    $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_input_name']  = 'qstn'
938 938
                                                                                                 . $input_name
939 939
                                                                                                 . $qst_name;
940
-                    $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_input_id']    =
941
-                        $input_id . '-' . $qstn_id;
942
-                    $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_input_class'] = $input_class;
943
-                    $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_options']     = [];
944
-                    $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['qst_obj']         = $qst;
945
-                    $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['ans_obj']         = $answer;
940
+                    $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_input_id']    =
941
+                        $input_id.'-'.$qstn_id;
942
+                    $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_input_class'] = $input_class;
943
+                    $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_options']     = [];
944
+                    $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['qst_obj']         = $qst;
945
+                    $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['ans_obj']         = $answer;
946 946
                     // leave responses as-is, don't convert stuff into html entities please!
947
-                    $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['htmlentities'] = false;
947
+                    $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['htmlentities'] = false;
948 948
                     if ($qst->type() == 'RADIO_BTN' || $qst->type() == 'CHECKBOX' || $qst->type() == 'DROPDOWN') {
949 949
                         $QSOs = $qst->options(true, $answer->value());
950 950
                         if (is_array($QSOs)) {
951 951
                             foreach ($QSOs as $QSO_ID => $QSO) {
952
-                                $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_options'][ $QSO_ID ] =
952
+                                $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_options'][$QSO_ID] =
953 953
                                     $QSO->model_field_array();
954 954
                             }
955 955
                         }
Please login to merge, or discard this patch.
core/db_models/EEM_Event_Venue.model.php 2 patches
Indentation   +61 added lines, -61 removed lines patch added patch discarded remove patch
@@ -9,68 +9,68 @@
 block discarded – undo
9 9
  */
10 10
 class EEM_Event_Venue extends EEM_Base
11 11
 {
12
-    // private instance of the Attendee object
13
-    protected static $_instance = null;
12
+	// private instance of the Attendee object
13
+	protected static $_instance = null;
14 14
 
15 15
 
16
-    /**
17
-     * @param string|null $timezone
18
-     * @throws EE_Error
19
-     */
20
-    protected function __construct(?string $timezone = '')
21
-    {
22
-        $this->singular_item    = esc_html__('Event to Question Group Link', 'event_espresso');
23
-        $this->plural_item      = esc_html__('Event to Question Group Links', 'event_espresso');
24
-        $this->_tables          = [
25
-            'Event_Venue' => new EE_Primary_Table('esp_event_venue', 'EVV_ID'),
26
-        ];
27
-        $this->_fields          = [
28
-            'Event_Venue' => [
29
-                'EVV_ID'      => new EE_Primary_Key_Int_Field(
30
-                    'EVV_ID',
31
-                    esc_html__('Event to Venue Link ID', 'event_espresso')
32
-                ),
33
-                'EVT_ID'      => new EE_Foreign_Key_Int_Field(
34
-                    'EVT_ID',
35
-                    esc_html__('Event ID', 'event_espresso'),
36
-                    false,
37
-                    0,
38
-                    'Event'
39
-                ),
40
-                'VNU_ID'      => new EE_Foreign_Key_Int_Field(
41
-                    'VNU_ID',
42
-                    esc_html__('Venue ID', 'event_espresso'),
43
-                    false,
44
-                    0,
45
-                    'Venue'
46
-                ),
47
-                'EVV_primary' => new EE_Boolean_Field(
48
-                    'EVV_primary',
49
-                    esc_html__(
50
-                        "Flag indicating venue is primary one for event",
51
-                        "event_espresso"
52
-                    ),
53
-                    false,
54
-                    true
55
-                ),
16
+	/**
17
+	 * @param string|null $timezone
18
+	 * @throws EE_Error
19
+	 */
20
+	protected function __construct(?string $timezone = '')
21
+	{
22
+		$this->singular_item    = esc_html__('Event to Question Group Link', 'event_espresso');
23
+		$this->plural_item      = esc_html__('Event to Question Group Links', 'event_espresso');
24
+		$this->_tables          = [
25
+			'Event_Venue' => new EE_Primary_Table('esp_event_venue', 'EVV_ID'),
26
+		];
27
+		$this->_fields          = [
28
+			'Event_Venue' => [
29
+				'EVV_ID'      => new EE_Primary_Key_Int_Field(
30
+					'EVV_ID',
31
+					esc_html__('Event to Venue Link ID', 'event_espresso')
32
+				),
33
+				'EVT_ID'      => new EE_Foreign_Key_Int_Field(
34
+					'EVT_ID',
35
+					esc_html__('Event ID', 'event_espresso'),
36
+					false,
37
+					0,
38
+					'Event'
39
+				),
40
+				'VNU_ID'      => new EE_Foreign_Key_Int_Field(
41
+					'VNU_ID',
42
+					esc_html__('Venue ID', 'event_espresso'),
43
+					false,
44
+					0,
45
+					'Venue'
46
+				),
47
+				'EVV_primary' => new EE_Boolean_Field(
48
+					'EVV_primary',
49
+					esc_html__(
50
+						"Flag indicating venue is primary one for event",
51
+						"event_espresso"
52
+					),
53
+					false,
54
+					true
55
+				),
56 56
 
57
-            ],
58
-        ];
59
-        $this->_model_relations = [
60
-            'Event' => new EE_Belongs_To_Relation(),
61
-            'Venue' => new EE_Belongs_To_Relation(),
62
-        ];
63
-        // this model is generally available for reading
64
-        $path_to_event                                                  = 'Event';
65
-        $this->_cap_restriction_generators[ EEM_Base::caps_read ]       =
66
-            new EE_Restriction_Generator_Event_Related_Public($path_to_event);
67
-        $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] =
68
-            new EE_Restriction_Generator_Event_Related_Protected($path_to_event);
69
-        $this->_cap_restriction_generators[ EEM_Base::caps_edit ]       =
70
-            new EE_Restriction_Generator_Event_Related_Protected($path_to_event);
71
-        $this->_cap_restriction_generators[ EEM_Base::caps_delete ]     =
72
-            new EE_Restriction_Generator_Event_Related_Protected($path_to_event, EEM_Base::caps_edit);
73
-        $this->model_chain_to_password                                  = $path_to_event;
74
-        parent::__construct($timezone);
75
-    }
57
+			],
58
+		];
59
+		$this->_model_relations = [
60
+			'Event' => new EE_Belongs_To_Relation(),
61
+			'Venue' => new EE_Belongs_To_Relation(),
62
+		];
63
+		// this model is generally available for reading
64
+		$path_to_event                                                  = 'Event';
65
+		$this->_cap_restriction_generators[ EEM_Base::caps_read ]       =
66
+			new EE_Restriction_Generator_Event_Related_Public($path_to_event);
67
+		$this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] =
68
+			new EE_Restriction_Generator_Event_Related_Protected($path_to_event);
69
+		$this->_cap_restriction_generators[ EEM_Base::caps_edit ]       =
70
+			new EE_Restriction_Generator_Event_Related_Protected($path_to_event);
71
+		$this->_cap_restriction_generators[ EEM_Base::caps_delete ]     =
72
+			new EE_Restriction_Generator_Event_Related_Protected($path_to_event, EEM_Base::caps_edit);
73
+		$this->model_chain_to_password                                  = $path_to_event;
74
+		parent::__construct($timezone);
75
+	}
76 76
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -62,13 +62,13 @@
 block discarded – undo
62 62
         ];
63 63
         // this model is generally available for reading
64 64
         $path_to_event                                                  = 'Event';
65
-        $this->_cap_restriction_generators[ EEM_Base::caps_read ]       =
65
+        $this->_cap_restriction_generators[EEM_Base::caps_read]       =
66 66
             new EE_Restriction_Generator_Event_Related_Public($path_to_event);
67
-        $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] =
67
+        $this->_cap_restriction_generators[EEM_Base::caps_read_admin] =
68 68
             new EE_Restriction_Generator_Event_Related_Protected($path_to_event);
69
-        $this->_cap_restriction_generators[ EEM_Base::caps_edit ]       =
69
+        $this->_cap_restriction_generators[EEM_Base::caps_edit]       =
70 70
             new EE_Restriction_Generator_Event_Related_Protected($path_to_event);
71
-        $this->_cap_restriction_generators[ EEM_Base::caps_delete ]     =
71
+        $this->_cap_restriction_generators[EEM_Base::caps_delete]     =
72 72
             new EE_Restriction_Generator_Event_Related_Protected($path_to_event, EEM_Base::caps_edit);
73 73
         $this->model_chain_to_password                                  = $path_to_event;
74 74
         parent::__construct($timezone);
Please login to merge, or discard this patch.