Completed
Branch fix-dummy-related-question-qst... (e5efcf)
by
unknown
07:49 queued 03:45
created
core/db_models/EEM_Message_Template_Group.model.php 2 patches
Spacing   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -48,7 +48,7 @@  discard block
 block discarded – undo
48 48
             'WP_User' => new EE_Belongs_To_Relation()
49 49
         );
50 50
         foreach ($this->_cap_contexts_to_cap_action_map as $context => $action) {
51
-            $this->_cap_restriction_generators[ $context ] = new EE_Restriction_Generator_Global('MTP_is_global');
51
+            $this->_cap_restriction_generators[$context] = new EE_Restriction_Generator_Global('MTP_is_global');
52 52
         }
53 53
         $this->_caps_slug = 'messages';
54 54
 
@@ -75,7 +75,7 @@  discard block
 block discarded – undo
75 75
         $limit = null,
76 76
         $count = false
77 77
     ) {
78
-        $query_params = array( array('Event.EVT_ID' => $EVT_ID), 'order_by' => array($orderby => $order), 'limit' => $limit );
78
+        $query_params = array(array('Event.EVT_ID' => $EVT_ID), 'order_by' => array($orderby => $order), 'limit' => $limit);
79 79
         return $count ? $this->count_deleted($query_params, 'GRP_ID', true) : $this->get_all_deleted($query_params);
80 80
     }
81 81
 
@@ -93,7 +93,7 @@  discard block
 block discarded – undo
93 93
     public function get_all_message_templates_by_messenger($messenger, $orderby = 'GRP_ID', $order = 'ASC')
94 94
     {
95 95
         return $this->get_all_deleted_and_undeleted(
96
-            array( array( 'MTP_messenger' => $messenger ), 'order_by' => array( $orderby => $order ) )
96
+            array(array('MTP_messenger' => $messenger), 'order_by' => array($orderby => $order))
97 97
         );
98 98
     }
99 99
 
@@ -145,7 +145,7 @@  discard block
 block discarded – undo
145 145
         $global = true,
146 146
         $user_check = false
147 147
     ) {
148
-        $_where = $global ? array('MTP_is_global' => true ) : array('MTP_is_global' => false );
148
+        $_where = $global ? array('MTP_is_global' => true) : array('MTP_is_global' => false);
149 149
         $_where['MTP_is_active'] = true;
150 150
         $_where = $this->_maybe_mtp_filters($_where);
151 151
 
@@ -160,7 +160,7 @@  discard block
 block discarded – undo
160 160
             $_where['MTP_user_id'] = get_current_user_id();
161 161
         }
162 162
 
163
-        $query_params = array( $_where, 'order_by' => array($orderby => $order), 'limit' => $limit );
163
+        $query_params = array($_where, 'order_by' => array($orderby => $order), 'limit' => $limit);
164 164
 
165 165
         return $count ? $this->count($query_params, 'GRP_ID', true) : $this->get_all($query_params);
166 166
     }
@@ -181,7 +181,7 @@  discard block
 block discarded – undo
181 181
     {
182 182
         $_where = $this->_maybe_mtp_filters();
183 183
 
184
-        $query_params = array( $_where, 'order_by' => array($orderby => $order), 'limit' => $limit );
184
+        $query_params = array($_where, 'order_by' => array($orderby => $order), 'limit' => $limit);
185 185
 
186 186
         $r_templates = $count
187 187
             ? $this->count_deleted_and_undeleted($query_params, 'GRP_ID', true)
@@ -201,9 +201,9 @@  discard block
 block discarded – undo
201 201
      */
202 202
     public function get_all_custom_templates_by_event($EVT_ID, $query_params = array())
203 203
     {
204
-        $where = array_merge($query_params, array( 'Event.EVT_ID' => $EVT_ID ));
204
+        $where = array_merge($query_params, array('Event.EVT_ID' => $EVT_ID));
205 205
         return $this->get_all(
206
-            array( $where )
206
+            array($where)
207 207
         );
208 208
     }
209 209
 
@@ -228,11 +228,11 @@  discard block
 block discarded – undo
228 228
         $count = false,
229 229
         $global = true
230 230
     ) {
231
-        $_where = $global ? array('MTP_is_global' => true ) : array('MTP_is_global' => false );
231
+        $_where = $global ? array('MTP_is_global' => true) : array('MTP_is_global' => false);
232 232
         $_where['MTP_is_active'] = true;
233 233
         $_where = $this->_maybe_mtp_filters($_where);
234 234
 
235
-        $query_params = array( $_where, 'order_by' => array($orderby => $order), 'limit' => $limit );
235
+        $query_params = array($_where, 'order_by' => array($orderby => $order), 'limit' => $limit);
236 236
 
237 237
         return $count ? $this->count_deleted($query_params, 'GRP_ID', true) : $this->get_all_deleted($query_params);
238 238
     }
@@ -270,7 +270,7 @@  discard block
 block discarded – undo
270 270
             'MTP_is_active' => $active
271 271
         );
272 272
 
273
-        $query_params = array( $_where, 'order_by' => array($orderby => $order), 'limit' => $limit );
273
+        $query_params = array($_where, 'order_by' => array($orderby => $order), 'limit' => $limit);
274 274
 
275 275
         return $count ? $this->count($query_params, 'GRP_ID', true) : $this->get_all($query_params);
276 276
     }
@@ -310,7 +310,7 @@  discard block
 block discarded – undo
310 310
             $_where['MTP_is_active'] = $active;
311 311
         }
312 312
 
313
-        $query_params = array( $_where, 'order_by' => array( $orderby => $order ), 'limit' => $limit );
313
+        $query_params = array($_where, 'order_by' => array($orderby => $order), 'limit' => $limit);
314 314
 
315 315
         return $count ? $this->count($query_params, 'GRP_ID', true) : $this->get_all($query_params);
316 316
     }
@@ -368,19 +368,19 @@  discard block
 block discarded – undo
368 368
             // first let's figure out if the value['content'] in the current index is an array.
369 369
             //  If it is then this is special fields that are used in parsing special shortcodes (i.e. 'attendee_list').
370 370
             if (is_array($value['content'])) {
371
-                $assembled_fields[ $value['name'] ] = $value['content']['main'];
371
+                $assembled_fields[$value['name']] = $value['content']['main'];
372 372
                 // loop through the content and get the other fields.
373 373
                 foreach ($value['content'] as $name => $val) {
374 374
                     if ($name == 'main') {
375 375
                         continue;
376 376
                     }
377
-                    $assembled_fields[ $name ] = $val;
377
+                    $assembled_fields[$name] = $val;
378 378
                 }
379 379
                 continue;
380 380
             }
381 381
 
382 382
             // okay if we're here then this is just a straight field=>$value arrangement
383
-            $assembled_fields[ $value['name'] ] = $value['content'];
383
+            $assembled_fields[$value['name']] = $value['content'];
384 384
         }
385 385
 
386 386
         // now we've got the assembled_fields.
@@ -390,9 +390,9 @@  discard block
 block discarded – undo
390 390
         $mt_ref = ucwords(str_replace('_', ' ', $message_type));
391 391
         $mt_ref = str_replace(' ', '_', $mt_ref);
392 392
 
393
-        $classname = 'EE_Messages_' . $m_ref . '_' . $mt_ref . '_Validator';
393
+        $classname = 'EE_Messages_'.$m_ref.'_'.$mt_ref.'_Validator';
394 394
 
395
-        if (!class_exists($classname)) {
395
+        if ( ! class_exists($classname)) {
396 396
             $msg[] = esc_html__('The Validator class was unable to load', 'event_espresso');
397 397
             $msg[] = sprintf(
398 398
                 esc_html__(
@@ -430,12 +430,12 @@  discard block
 block discarded – undo
430 430
         if (empty($messenger_names) && empty($message_type_names)) {
431 431
             return 0;
432 432
         }
433
-        if (! empty($messenger_names)) {
434
-            $query_args[0]['MTP_messenger'] = array( 'IN', (array) $messenger_names );
433
+        if ( ! empty($messenger_names)) {
434
+            $query_args[0]['MTP_messenger'] = array('IN', (array) $messenger_names);
435 435
         }
436
-        if (! empty($message_type_names)) {
437
-            $query_args[0]['MTP_message_type'] = array( 'IN', (array) $message_type_names );
436
+        if ( ! empty($message_type_names)) {
437
+            $query_args[0]['MTP_message_type'] = array('IN', (array) $message_type_names);
438 438
         }
439
-        return $this->update(array( 'MTP_is_active' => false ), $query_args);
439
+        return $this->update(array('MTP_is_active' => false), $query_args);
440 440
     }
441 441
 }
Please login to merge, or discard this patch.
Indentation   +423 added lines, -423 removed lines patch added patch discarded remove patch
@@ -14,427 +14,427 @@
 block discarded – undo
14 14
  */
15 15
 class EEM_Message_Template_Group extends EEM_Soft_Delete_Base
16 16
 {
17
-    // private instance of the EEM_Message_Template_Group object
18
-    protected static $_instance = null;
19
-
20
-
21
-
22
-    protected function __construct($timezone = null)
23
-    {
24
-        $this->singular_item = esc_html__('Message Template Group', 'event_espresso');
25
-        $this->plural_item = esc_html__('Message Template Groups', 'event_espresso');
26
-        $this->_tables = array(
27
-            'Message_Template_Group' => new EE_Primary_Table('esp_message_template_group', 'GRP_ID')
28
-        );
29
-        $this->_fields = array(
30
-            'Message_Template_Group' => array(
31
-                'GRP_ID' => new EE_Primary_Key_Int_Field('GRP_ID', esc_html__('Message Template Group ID', 'event_espresso')),
32
-                'MTP_name' => new EE_Plain_Text_Field('MTP_name', esc_html__('The name of the template group', 'event_espresso'), false, ''),
33
-                'MTP_description' => new EE_Simple_HTML_Field('MTP_description', esc_html__('A brief description about this template.', 'event_espresso'), false, ''),
34
-                'MTP_user_id' => new EE_WP_User_Field('MTP_user_id', esc_html__('Template Creator ID', 'event_espresso'), false, get_current_user_id()),
35
-                'MTP_messenger' => new EE_Plain_Text_Field('MTP_messenger', esc_html__('Messenger Used for Template', 'event_espresso'), false, 'email'),
36
-                'MTP_message_type' => new EE_Plain_Text_Field('MTP_message_type', esc_html__('Message Type', 'event_espresso'), false, 'registration'),
37
-                'MTP_is_global' => new EE_Boolean_Field('MTP_is_global', esc_html__('Flag indicating if Template Group is Global', 'event_espresso'), false, true),
38
-                'MTP_is_override' => new EE_Boolean_Field('MTP_is_override', esc_html__('Flag indicating if Template Group overrides any other Templates for the messenger/messagetype combination', 'event_espresso'), false, false),
39
-                'MTP_deleted' => new EE_Trashed_Flag_Field('MTP_deleted', esc_html__('Flag indicating whether this has been trashed', 'event_espresso'), false, false),
40
-                'MTP_is_active' => new EE_Boolean_Field('MTP_is_active', esc_html__('Flag indicating whether template group is active', 'event_espresso'), false, true)
41
-            )
42
-        );
43
-        $this->_model_relations = array(
44
-            'Message_Template' => new EE_Has_Many_Relation(),
45
-            'Message' => new EE_Has_Many_Relation(),
46
-            'Event' => new EE_HABTM_Relation('Event_Message_Template'),
47
-            'WP_User' => new EE_Belongs_To_Relation()
48
-        );
49
-        foreach ($this->_cap_contexts_to_cap_action_map as $context => $action) {
50
-            $this->_cap_restriction_generators[ $context ] = new EE_Restriction_Generator_Global('MTP_is_global');
51
-        }
52
-        $this->_caps_slug = 'messages';
53
-
54
-        parent::__construct($timezone);
55
-    }
56
-
57
-
58
-
59
-    /**
60
-     * get_all_trashed_message_templates_by_event
61
-     *
62
-     * @access public
63
-     * @param int    $EVT_ID specific event id
64
-     * @param string $orderby
65
-     * @param string $order
66
-     * @param null   $limit
67
-     * @param bool   $count
68
-     * @return array message template objects that are attached to a specific event.
69
-     */
70
-    public function get_all_trashed_message_templates_by_event(
71
-        $EVT_ID,
72
-        $orderby = 'GRP_ID',
73
-        $order = 'ASC',
74
-        $limit = null,
75
-        $count = false
76
-    ) {
77
-        $query_params = array( array('Event.EVT_ID' => $EVT_ID), 'order_by' => array($orderby => $order), 'limit' => $limit );
78
-        return $count ? $this->count_deleted($query_params, 'GRP_ID', true) : $this->get_all_deleted($query_params);
79
-    }
80
-
81
-
82
-
83
-    /**
84
-     * get_all_message_templates_by_messenger
85
-     *
86
-     * @access public
87
-     * @param        $messenger
88
-     * @param string $orderby
89
-     * @param string $order
90
-     * @return array all (including trashed or inactive) message template group objects for the given messenger
91
-     */
92
-    public function get_all_message_templates_by_messenger($messenger, $orderby = 'GRP_ID', $order = 'ASC')
93
-    {
94
-        return $this->get_all_deleted_and_undeleted(
95
-            array( array( 'MTP_messenger' => $messenger ), 'order_by' => array( $orderby => $order ) )
96
-        );
97
-    }
98
-
99
-
100
-    /**
101
-     * This simply adds on any messenger/message type filters that may be present in the request
102
-     *
103
-     * @param array $_where any existing where conditions to append these to.
104
-     * @return array          original where conditions or original with additional filters.
105
-     */
106
-    protected function _maybe_mtp_filters($_where = array())
107
-    {
108
-        /** @var RequestInterface $request */
109
-        $request   = LoaderFactory::getLoader()->getShared(RequestInterface::class);
110
-        $messenger = $request->getRequestParam('ee_messenger_filter_by');
111
-        // account for messenger or message type filters
112
-        if ($messenger !== '' && $messenger !== 'none_selected' && $messenger !== 'all') {
113
-            $_where['MTP_messenger'] = $messenger;
114
-        }
115
-        $message_type = $request->getRequestParam('ee_message_type_filter_by');
116
-        if (
117
-            $message_type !== '' && $message_type !== 'none_selected'
118
-        ) {
119
-            $_where['MTP_message_type'] = $message_type;
120
-        }
121
-
122
-        return $_where;
123
-    }
124
-
125
-
126
-
127
-    /**
128
-     * get_all_active_message_templates groups
129
-     *
130
-     * @access public
131
-     * @param string $orderby
132
-     * @param string $order
133
-     * @param null   $limit
134
-     * @param bool   $count
135
-     * @param bool   $global
136
-     * @param bool   $user_check
137
-     * @return array all active (non_trashed, active) message template objects
138
-     */
139
-    public function get_all_active_message_templates(
140
-        $orderby = 'GRP_ID',
141
-        $order = 'ASC',
142
-        $limit = null,
143
-        $count = false,
144
-        $global = true,
145
-        $user_check = false
146
-    ) {
147
-        $_where = $global ? array('MTP_is_global' => true ) : array('MTP_is_global' => false );
148
-        $_where['MTP_is_active'] = true;
149
-        $_where = $this->_maybe_mtp_filters($_where);
150
-
151
-        if (
152
-            $user_check
153
-            && ! $global
154
-            && ! EE_Registry::instance()->CAP->current_user_can(
155
-                'ee_read_others_messages',
156
-                'get_all_active_message_templates'
157
-            )
158
-        ) {
159
-            $_where['MTP_user_id'] = get_current_user_id();
160
-        }
161
-
162
-        $query_params = array( $_where, 'order_by' => array($orderby => $order), 'limit' => $limit );
163
-
164
-        return $count ? $this->count($query_params, 'GRP_ID', true) : $this->get_all($query_params);
165
-    }
166
-
167
-
168
-
169
-    /**
170
-     *    retrieve ALL message_template groups from db regardless of wht
171
-     *
172
-     * @access    public
173
-     * @param string $orderby
174
-     * @param string $order
175
-     * @param null   $limit
176
-     * @param bool   $count
177
-     * @return mixed array on success, FALSE on fail
178
-     */
179
-    public function get_all_message_templates($orderby = 'GRP_ID', $order = 'ASC', $limit = null, $count = false)
180
-    {
181
-        $_where = $this->_maybe_mtp_filters();
182
-
183
-        $query_params = array( $_where, 'order_by' => array($orderby => $order), 'limit' => $limit );
184
-
185
-        $r_templates = $count
186
-            ? $this->count_deleted_and_undeleted($query_params, 'GRP_ID', true)
187
-            : $this->get_all_deleted_and_undeleted($query_params);
188
-
189
-        return $r_templates;
190
-    }
191
-
192
-
193
-
194
-
195
-    /**
196
-     * This gets all the custom templates attached to a specific event
197
-     * @param  int      $EVT_ID         event id
198
-     * @param  array  $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
199
-     * @return  EE_Message_Template_Group[]
200
-     */
201
-    public function get_all_custom_templates_by_event($EVT_ID, $query_params = array())
202
-    {
203
-        $where = array_merge($query_params, array( 'Event.EVT_ID' => $EVT_ID ));
204
-        return $this->get_all(
205
-            array( $where )
206
-        );
207
-    }
208
-
209
-
210
-
211
-    /**
212
-     * get_all_trashed_grouped_message_templates
213
-     * this returns ONLY the template groups where ALL contexts are trashed and none of the group are non-trashed
214
-     *
215
-     * @access public
216
-     * @param string $orderby
217
-     * @param string $order
218
-     * @param null   $limit
219
-     * @param bool   $count
220
-     * @param bool   $global
221
-     * @return \EE_Message_Template_Group[] message template groups.
222
-     */
223
-    public function get_all_trashed_grouped_message_templates(
224
-        $orderby = 'GRP_ID',
225
-        $order = 'ASC',
226
-        $limit = null,
227
-        $count = false,
228
-        $global = true
229
-    ) {
230
-        $_where = $global ? array('MTP_is_global' => true ) : array('MTP_is_global' => false );
231
-        $_where['MTP_is_active'] = true;
232
-        $_where = $this->_maybe_mtp_filters($_where);
233
-
234
-        $query_params = array( $_where, 'order_by' => array($orderby => $order), 'limit' => $limit );
235
-
236
-        return $count ? $this->count_deleted($query_params, 'GRP_ID', true) : $this->get_all_deleted($query_params);
237
-    }
238
-
239
-
240
-
241
-    /**
242
-     * this returns the message template group(s) for a given event, messenger, and message template
243
-     *
244
-     * @param  string             $messenger
245
-     * @param  string             $message_type
246
-     * @param                     $evt_id
247
-     * @param  string             $orderby pointless at this point but still included
248
-     * @param  string             $order
249
-     * @param  mixed (array|null) $limit   array($offset, $num)
250
-     * @param  bool               $count   true = just return count, false = objects
251
-     * @param  bool               $active  ignore "active" or not. (default only return active)
252
-     * @return \mixed[]) depending on $count.
253
-     */
254
-    public function get_event_message_templates_by_m_and_mt_and_evt(
255
-        $messenger,
256
-        $message_type,
257
-        $evt_id,
258
-        $orderby = 'GRP_ID',
259
-        $order = 'ASC',
260
-        $limit = null,
261
-        $count = false,
262
-        $active = true
263
-    ) {
264
-        $_where = array(
265
-            'MTP_messenger' => $messenger,
266
-            'MTP_message_type' => $message_type,
267
-            'Event.EVT_ID' => $evt_id,
268
-            'MTP_is_global' => true,
269
-            'MTP_is_active' => $active
270
-        );
271
-
272
-        $query_params = array( $_where, 'order_by' => array($orderby => $order), 'limit' => $limit );
273
-
274
-        return $count ? $this->count($query_params, 'GRP_ID', true) : $this->get_all($query_params);
275
-    }
276
-
277
-
278
-
279
-
280
-    /**
281
-     * get all GLOBAL message template groups for the given messenger and message type
282
-     *
283
-     * @param  string $messenger    slug for messenger
284
-     * @param  string $message_type slug for message type
285
-     * @param  string $orderby      what column to orderby
286
-     * @param  string $order        ASC or DESC
287
-     * @param  mixed (array|null) $limit array($offset, $num)
288
-     * @param  bool   $count        true = just return count, false = objects
289
-     * @param  bool   $active       ignore "active" or not. (default only return active) -
290
-     *                              'all' means return both inactive AND inactive.
291
-     * @return array               message template objects that are global (i.e. non-event)
292
-     */
293
-    public function get_global_message_template_by_m_and_mt(
294
-        $messenger,
295
-        $message_type,
296
-        $orderby = 'GRP_ID',
297
-        $order = 'ASC',
298
-        $limit = null,
299
-        $count = false,
300
-        $active = true
301
-    ) {
302
-        $_where = array(
303
-            'MTP_messenger' => $messenger,
304
-            'MTP_message_type' => $message_type,
305
-            'MTP_is_global' => true,
306
-        );
307
-
308
-        if ($active != 'all') {
309
-            $_where['MTP_is_active'] = $active;
310
-        }
311
-
312
-        $query_params = array( $_where, 'order_by' => array( $orderby => $order ), 'limit' => $limit );
313
-
314
-        return $count ? $this->count($query_params, 'GRP_ID', true) : $this->get_all($query_params);
315
-    }
316
-
317
-
318
-
319
-
320
-    /**
321
-     * get all custom message template groups for the given messenger and message type
322
-     * @param  string $messenger    messenger
323
-     * @param  string $message_type messagetype
324
-     * @param  array  $query_params same as EEM_Base->get_all()
325
-     * @return EE_Message_Template_Group[]
326
-     */
327
-    public function get_custom_message_template_by_m_and_mt($messenger, $message_type, $query_params = array())
328
-    {
329
-        return $this->get_all(
330
-            array_merge(
331
-                $query_params,
332
-                array(
333
-                    array(
334
-                        'MTP_is_global'    => false,
335
-                        'MTP_messenger'    => $messenger,
336
-                        'MTP_message_type' => $message_type
337
-                    )
338
-                )
339
-            )
340
-        );
341
-    }
342
-
343
-
344
-
345
-    /**
346
-     * This sends things to the validator for the given messenger and message type.
347
-     *
348
-     * @param  array $fields the incoming fields to check.
349
-     *                       Note this array is in the formatted fields from the form fields setup.
350
-     *                       So we need to reformat this into an array of expected field refs by the validator.
351
-     *                       Note also that this is not only the fields for the Message Template Group
352
-     *                       but ALSO for Message Template.
353
-     * @param string $context      The context the fields were obtained from.
354
-     * @param string $messenger    The messenger we are validating
355
-     * @param string $message_type The message type we are validating.
356
-     * @return mixed If the fields all check out then we return true otherwise error messages are returned
357
-     *                       (indexed by field name);
358
-     * @throws \EE_Error
359
-     */
360
-    public function validate($fields, $context, $messenger, $message_type)
361
-    {
362
-
363
-        $assembled_fields = array();
364
-
365
-        // let's loop through all the fields and set them up in the right format
366
-        foreach ($fields as $index => $value) {
367
-            // first let's figure out if the value['content'] in the current index is an array.
368
-            //  If it is then this is special fields that are used in parsing special shortcodes (i.e. 'attendee_list').
369
-            if (is_array($value['content'])) {
370
-                $assembled_fields[ $value['name'] ] = $value['content']['main'];
371
-                // loop through the content and get the other fields.
372
-                foreach ($value['content'] as $name => $val) {
373
-                    if ($name == 'main') {
374
-                        continue;
375
-                    }
376
-                    $assembled_fields[ $name ] = $val;
377
-                }
378
-                continue;
379
-            }
380
-
381
-            // okay if we're here then this is just a straight field=>$value arrangement
382
-            $assembled_fields[ $value['name'] ] = $value['content'];
383
-        }
384
-
385
-        // now we've got the assembled_fields.
386
-        // We need to setup the string for the appropriate validator class and call that.
387
-        $m_ref = ucwords(str_replace('_', ' ', $messenger));
388
-        $m_ref = str_replace(' ', '_', $m_ref);
389
-        $mt_ref = ucwords(str_replace('_', ' ', $message_type));
390
-        $mt_ref = str_replace(' ', '_', $mt_ref);
391
-
392
-        $classname = 'EE_Messages_' . $m_ref . '_' . $mt_ref . '_Validator';
393
-
394
-        if (!class_exists($classname)) {
395
-            $msg[] = esc_html__('The Validator class was unable to load', 'event_espresso');
396
-            $msg[] = sprintf(
397
-                esc_html__(
398
-                    'The class name compiled was %s. Please check and make sure the spelling and case is correct for the class name and that there is an autoloader in place for this class',
399
-                    'event_espresso'
400
-                ),
401
-                $classname
402
-            );
403
-            throw new EE_Error(implode('||', $msg));
404
-        }
405
-
406
-        $a = new ReflectionClass($classname);
407
-        $_VLD = $a->newInstance($assembled_fields, $context);
408
-        $result = $_VLD->validate();
409
-        return $result;
410
-    }
411
-
412
-
413
-
414
-    /**
415
-     * Updates all message template groups matching the incoming arguments to inactive status.
416
-     *
417
-     * @param array $messenger_names    The messenger slugs.
418
-     *                              If empty then all templates matching the message types are marked inactive.
419
-     *                              Otherwise only templates matching the messengers and message types.
420
-     * @param array $message_type_names     The message type slugs.
421
-     *                              If empty then all templates matching the messengers are marked inactive.
422
-     *                              Otherwise only templates matching the messengers and message types.
423
-     *
424
-     * @return int  count of updated records.
425
-     */
426
-    public function deactivate_message_template_groups_for($messenger_names = array(), $message_type_names = array())
427
-    {
428
-        $query_args = array();
429
-        if (empty($messenger_names) && empty($message_type_names)) {
430
-            return 0;
431
-        }
432
-        if (! empty($messenger_names)) {
433
-            $query_args[0]['MTP_messenger'] = array( 'IN', (array) $messenger_names );
434
-        }
435
-        if (! empty($message_type_names)) {
436
-            $query_args[0]['MTP_message_type'] = array( 'IN', (array) $message_type_names );
437
-        }
438
-        return $this->update(array( 'MTP_is_active' => false ), $query_args);
439
-    }
17
+	// private instance of the EEM_Message_Template_Group object
18
+	protected static $_instance = null;
19
+
20
+
21
+
22
+	protected function __construct($timezone = null)
23
+	{
24
+		$this->singular_item = esc_html__('Message Template Group', 'event_espresso');
25
+		$this->plural_item = esc_html__('Message Template Groups', 'event_espresso');
26
+		$this->_tables = array(
27
+			'Message_Template_Group' => new EE_Primary_Table('esp_message_template_group', 'GRP_ID')
28
+		);
29
+		$this->_fields = array(
30
+			'Message_Template_Group' => array(
31
+				'GRP_ID' => new EE_Primary_Key_Int_Field('GRP_ID', esc_html__('Message Template Group ID', 'event_espresso')),
32
+				'MTP_name' => new EE_Plain_Text_Field('MTP_name', esc_html__('The name of the template group', 'event_espresso'), false, ''),
33
+				'MTP_description' => new EE_Simple_HTML_Field('MTP_description', esc_html__('A brief description about this template.', 'event_espresso'), false, ''),
34
+				'MTP_user_id' => new EE_WP_User_Field('MTP_user_id', esc_html__('Template Creator ID', 'event_espresso'), false, get_current_user_id()),
35
+				'MTP_messenger' => new EE_Plain_Text_Field('MTP_messenger', esc_html__('Messenger Used for Template', 'event_espresso'), false, 'email'),
36
+				'MTP_message_type' => new EE_Plain_Text_Field('MTP_message_type', esc_html__('Message Type', 'event_espresso'), false, 'registration'),
37
+				'MTP_is_global' => new EE_Boolean_Field('MTP_is_global', esc_html__('Flag indicating if Template Group is Global', 'event_espresso'), false, true),
38
+				'MTP_is_override' => new EE_Boolean_Field('MTP_is_override', esc_html__('Flag indicating if Template Group overrides any other Templates for the messenger/messagetype combination', 'event_espresso'), false, false),
39
+				'MTP_deleted' => new EE_Trashed_Flag_Field('MTP_deleted', esc_html__('Flag indicating whether this has been trashed', 'event_espresso'), false, false),
40
+				'MTP_is_active' => new EE_Boolean_Field('MTP_is_active', esc_html__('Flag indicating whether template group is active', 'event_espresso'), false, true)
41
+			)
42
+		);
43
+		$this->_model_relations = array(
44
+			'Message_Template' => new EE_Has_Many_Relation(),
45
+			'Message' => new EE_Has_Many_Relation(),
46
+			'Event' => new EE_HABTM_Relation('Event_Message_Template'),
47
+			'WP_User' => new EE_Belongs_To_Relation()
48
+		);
49
+		foreach ($this->_cap_contexts_to_cap_action_map as $context => $action) {
50
+			$this->_cap_restriction_generators[ $context ] = new EE_Restriction_Generator_Global('MTP_is_global');
51
+		}
52
+		$this->_caps_slug = 'messages';
53
+
54
+		parent::__construct($timezone);
55
+	}
56
+
57
+
58
+
59
+	/**
60
+	 * get_all_trashed_message_templates_by_event
61
+	 *
62
+	 * @access public
63
+	 * @param int    $EVT_ID specific event id
64
+	 * @param string $orderby
65
+	 * @param string $order
66
+	 * @param null   $limit
67
+	 * @param bool   $count
68
+	 * @return array message template objects that are attached to a specific event.
69
+	 */
70
+	public function get_all_trashed_message_templates_by_event(
71
+		$EVT_ID,
72
+		$orderby = 'GRP_ID',
73
+		$order = 'ASC',
74
+		$limit = null,
75
+		$count = false
76
+	) {
77
+		$query_params = array( array('Event.EVT_ID' => $EVT_ID), 'order_by' => array($orderby => $order), 'limit' => $limit );
78
+		return $count ? $this->count_deleted($query_params, 'GRP_ID', true) : $this->get_all_deleted($query_params);
79
+	}
80
+
81
+
82
+
83
+	/**
84
+	 * get_all_message_templates_by_messenger
85
+	 *
86
+	 * @access public
87
+	 * @param        $messenger
88
+	 * @param string $orderby
89
+	 * @param string $order
90
+	 * @return array all (including trashed or inactive) message template group objects for the given messenger
91
+	 */
92
+	public function get_all_message_templates_by_messenger($messenger, $orderby = 'GRP_ID', $order = 'ASC')
93
+	{
94
+		return $this->get_all_deleted_and_undeleted(
95
+			array( array( 'MTP_messenger' => $messenger ), 'order_by' => array( $orderby => $order ) )
96
+		);
97
+	}
98
+
99
+
100
+	/**
101
+	 * This simply adds on any messenger/message type filters that may be present in the request
102
+	 *
103
+	 * @param array $_where any existing where conditions to append these to.
104
+	 * @return array          original where conditions or original with additional filters.
105
+	 */
106
+	protected function _maybe_mtp_filters($_where = array())
107
+	{
108
+		/** @var RequestInterface $request */
109
+		$request   = LoaderFactory::getLoader()->getShared(RequestInterface::class);
110
+		$messenger = $request->getRequestParam('ee_messenger_filter_by');
111
+		// account for messenger or message type filters
112
+		if ($messenger !== '' && $messenger !== 'none_selected' && $messenger !== 'all') {
113
+			$_where['MTP_messenger'] = $messenger;
114
+		}
115
+		$message_type = $request->getRequestParam('ee_message_type_filter_by');
116
+		if (
117
+			$message_type !== '' && $message_type !== 'none_selected'
118
+		) {
119
+			$_where['MTP_message_type'] = $message_type;
120
+		}
121
+
122
+		return $_where;
123
+	}
124
+
125
+
126
+
127
+	/**
128
+	 * get_all_active_message_templates groups
129
+	 *
130
+	 * @access public
131
+	 * @param string $orderby
132
+	 * @param string $order
133
+	 * @param null   $limit
134
+	 * @param bool   $count
135
+	 * @param bool   $global
136
+	 * @param bool   $user_check
137
+	 * @return array all active (non_trashed, active) message template objects
138
+	 */
139
+	public function get_all_active_message_templates(
140
+		$orderby = 'GRP_ID',
141
+		$order = 'ASC',
142
+		$limit = null,
143
+		$count = false,
144
+		$global = true,
145
+		$user_check = false
146
+	) {
147
+		$_where = $global ? array('MTP_is_global' => true ) : array('MTP_is_global' => false );
148
+		$_where['MTP_is_active'] = true;
149
+		$_where = $this->_maybe_mtp_filters($_where);
150
+
151
+		if (
152
+			$user_check
153
+			&& ! $global
154
+			&& ! EE_Registry::instance()->CAP->current_user_can(
155
+				'ee_read_others_messages',
156
+				'get_all_active_message_templates'
157
+			)
158
+		) {
159
+			$_where['MTP_user_id'] = get_current_user_id();
160
+		}
161
+
162
+		$query_params = array( $_where, 'order_by' => array($orderby => $order), 'limit' => $limit );
163
+
164
+		return $count ? $this->count($query_params, 'GRP_ID', true) : $this->get_all($query_params);
165
+	}
166
+
167
+
168
+
169
+	/**
170
+	 *    retrieve ALL message_template groups from db regardless of wht
171
+	 *
172
+	 * @access    public
173
+	 * @param string $orderby
174
+	 * @param string $order
175
+	 * @param null   $limit
176
+	 * @param bool   $count
177
+	 * @return mixed array on success, FALSE on fail
178
+	 */
179
+	public function get_all_message_templates($orderby = 'GRP_ID', $order = 'ASC', $limit = null, $count = false)
180
+	{
181
+		$_where = $this->_maybe_mtp_filters();
182
+
183
+		$query_params = array( $_where, 'order_by' => array($orderby => $order), 'limit' => $limit );
184
+
185
+		$r_templates = $count
186
+			? $this->count_deleted_and_undeleted($query_params, 'GRP_ID', true)
187
+			: $this->get_all_deleted_and_undeleted($query_params);
188
+
189
+		return $r_templates;
190
+	}
191
+
192
+
193
+
194
+
195
+	/**
196
+	 * This gets all the custom templates attached to a specific event
197
+	 * @param  int      $EVT_ID         event id
198
+	 * @param  array  $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
199
+	 * @return  EE_Message_Template_Group[]
200
+	 */
201
+	public function get_all_custom_templates_by_event($EVT_ID, $query_params = array())
202
+	{
203
+		$where = array_merge($query_params, array( 'Event.EVT_ID' => $EVT_ID ));
204
+		return $this->get_all(
205
+			array( $where )
206
+		);
207
+	}
208
+
209
+
210
+
211
+	/**
212
+	 * get_all_trashed_grouped_message_templates
213
+	 * this returns ONLY the template groups where ALL contexts are trashed and none of the group are non-trashed
214
+	 *
215
+	 * @access public
216
+	 * @param string $orderby
217
+	 * @param string $order
218
+	 * @param null   $limit
219
+	 * @param bool   $count
220
+	 * @param bool   $global
221
+	 * @return \EE_Message_Template_Group[] message template groups.
222
+	 */
223
+	public function get_all_trashed_grouped_message_templates(
224
+		$orderby = 'GRP_ID',
225
+		$order = 'ASC',
226
+		$limit = null,
227
+		$count = false,
228
+		$global = true
229
+	) {
230
+		$_where = $global ? array('MTP_is_global' => true ) : array('MTP_is_global' => false );
231
+		$_where['MTP_is_active'] = true;
232
+		$_where = $this->_maybe_mtp_filters($_where);
233
+
234
+		$query_params = array( $_where, 'order_by' => array($orderby => $order), 'limit' => $limit );
235
+
236
+		return $count ? $this->count_deleted($query_params, 'GRP_ID', true) : $this->get_all_deleted($query_params);
237
+	}
238
+
239
+
240
+
241
+	/**
242
+	 * this returns the message template group(s) for a given event, messenger, and message template
243
+	 *
244
+	 * @param  string             $messenger
245
+	 * @param  string             $message_type
246
+	 * @param                     $evt_id
247
+	 * @param  string             $orderby pointless at this point but still included
248
+	 * @param  string             $order
249
+	 * @param  mixed (array|null) $limit   array($offset, $num)
250
+	 * @param  bool               $count   true = just return count, false = objects
251
+	 * @param  bool               $active  ignore "active" or not. (default only return active)
252
+	 * @return \mixed[]) depending on $count.
253
+	 */
254
+	public function get_event_message_templates_by_m_and_mt_and_evt(
255
+		$messenger,
256
+		$message_type,
257
+		$evt_id,
258
+		$orderby = 'GRP_ID',
259
+		$order = 'ASC',
260
+		$limit = null,
261
+		$count = false,
262
+		$active = true
263
+	) {
264
+		$_where = array(
265
+			'MTP_messenger' => $messenger,
266
+			'MTP_message_type' => $message_type,
267
+			'Event.EVT_ID' => $evt_id,
268
+			'MTP_is_global' => true,
269
+			'MTP_is_active' => $active
270
+		);
271
+
272
+		$query_params = array( $_where, 'order_by' => array($orderby => $order), 'limit' => $limit );
273
+
274
+		return $count ? $this->count($query_params, 'GRP_ID', true) : $this->get_all($query_params);
275
+	}
276
+
277
+
278
+
279
+
280
+	/**
281
+	 * get all GLOBAL message template groups for the given messenger and message type
282
+	 *
283
+	 * @param  string $messenger    slug for messenger
284
+	 * @param  string $message_type slug for message type
285
+	 * @param  string $orderby      what column to orderby
286
+	 * @param  string $order        ASC or DESC
287
+	 * @param  mixed (array|null) $limit array($offset, $num)
288
+	 * @param  bool   $count        true = just return count, false = objects
289
+	 * @param  bool   $active       ignore "active" or not. (default only return active) -
290
+	 *                              'all' means return both inactive AND inactive.
291
+	 * @return array               message template objects that are global (i.e. non-event)
292
+	 */
293
+	public function get_global_message_template_by_m_and_mt(
294
+		$messenger,
295
+		$message_type,
296
+		$orderby = 'GRP_ID',
297
+		$order = 'ASC',
298
+		$limit = null,
299
+		$count = false,
300
+		$active = true
301
+	) {
302
+		$_where = array(
303
+			'MTP_messenger' => $messenger,
304
+			'MTP_message_type' => $message_type,
305
+			'MTP_is_global' => true,
306
+		);
307
+
308
+		if ($active != 'all') {
309
+			$_where['MTP_is_active'] = $active;
310
+		}
311
+
312
+		$query_params = array( $_where, 'order_by' => array( $orderby => $order ), 'limit' => $limit );
313
+
314
+		return $count ? $this->count($query_params, 'GRP_ID', true) : $this->get_all($query_params);
315
+	}
316
+
317
+
318
+
319
+
320
+	/**
321
+	 * get all custom message template groups for the given messenger and message type
322
+	 * @param  string $messenger    messenger
323
+	 * @param  string $message_type messagetype
324
+	 * @param  array  $query_params same as EEM_Base->get_all()
325
+	 * @return EE_Message_Template_Group[]
326
+	 */
327
+	public function get_custom_message_template_by_m_and_mt($messenger, $message_type, $query_params = array())
328
+	{
329
+		return $this->get_all(
330
+			array_merge(
331
+				$query_params,
332
+				array(
333
+					array(
334
+						'MTP_is_global'    => false,
335
+						'MTP_messenger'    => $messenger,
336
+						'MTP_message_type' => $message_type
337
+					)
338
+				)
339
+			)
340
+		);
341
+	}
342
+
343
+
344
+
345
+	/**
346
+	 * This sends things to the validator for the given messenger and message type.
347
+	 *
348
+	 * @param  array $fields the incoming fields to check.
349
+	 *                       Note this array is in the formatted fields from the form fields setup.
350
+	 *                       So we need to reformat this into an array of expected field refs by the validator.
351
+	 *                       Note also that this is not only the fields for the Message Template Group
352
+	 *                       but ALSO for Message Template.
353
+	 * @param string $context      The context the fields were obtained from.
354
+	 * @param string $messenger    The messenger we are validating
355
+	 * @param string $message_type The message type we are validating.
356
+	 * @return mixed If the fields all check out then we return true otherwise error messages are returned
357
+	 *                       (indexed by field name);
358
+	 * @throws \EE_Error
359
+	 */
360
+	public function validate($fields, $context, $messenger, $message_type)
361
+	{
362
+
363
+		$assembled_fields = array();
364
+
365
+		// let's loop through all the fields and set them up in the right format
366
+		foreach ($fields as $index => $value) {
367
+			// first let's figure out if the value['content'] in the current index is an array.
368
+			//  If it is then this is special fields that are used in parsing special shortcodes (i.e. 'attendee_list').
369
+			if (is_array($value['content'])) {
370
+				$assembled_fields[ $value['name'] ] = $value['content']['main'];
371
+				// loop through the content and get the other fields.
372
+				foreach ($value['content'] as $name => $val) {
373
+					if ($name == 'main') {
374
+						continue;
375
+					}
376
+					$assembled_fields[ $name ] = $val;
377
+				}
378
+				continue;
379
+			}
380
+
381
+			// okay if we're here then this is just a straight field=>$value arrangement
382
+			$assembled_fields[ $value['name'] ] = $value['content'];
383
+		}
384
+
385
+		// now we've got the assembled_fields.
386
+		// We need to setup the string for the appropriate validator class and call that.
387
+		$m_ref = ucwords(str_replace('_', ' ', $messenger));
388
+		$m_ref = str_replace(' ', '_', $m_ref);
389
+		$mt_ref = ucwords(str_replace('_', ' ', $message_type));
390
+		$mt_ref = str_replace(' ', '_', $mt_ref);
391
+
392
+		$classname = 'EE_Messages_' . $m_ref . '_' . $mt_ref . '_Validator';
393
+
394
+		if (!class_exists($classname)) {
395
+			$msg[] = esc_html__('The Validator class was unable to load', 'event_espresso');
396
+			$msg[] = sprintf(
397
+				esc_html__(
398
+					'The class name compiled was %s. Please check and make sure the spelling and case is correct for the class name and that there is an autoloader in place for this class',
399
+					'event_espresso'
400
+				),
401
+				$classname
402
+			);
403
+			throw new EE_Error(implode('||', $msg));
404
+		}
405
+
406
+		$a = new ReflectionClass($classname);
407
+		$_VLD = $a->newInstance($assembled_fields, $context);
408
+		$result = $_VLD->validate();
409
+		return $result;
410
+	}
411
+
412
+
413
+
414
+	/**
415
+	 * Updates all message template groups matching the incoming arguments to inactive status.
416
+	 *
417
+	 * @param array $messenger_names    The messenger slugs.
418
+	 *                              If empty then all templates matching the message types are marked inactive.
419
+	 *                              Otherwise only templates matching the messengers and message types.
420
+	 * @param array $message_type_names     The message type slugs.
421
+	 *                              If empty then all templates matching the messengers are marked inactive.
422
+	 *                              Otherwise only templates matching the messengers and message types.
423
+	 *
424
+	 * @return int  count of updated records.
425
+	 */
426
+	public function deactivate_message_template_groups_for($messenger_names = array(), $message_type_names = array())
427
+	{
428
+		$query_args = array();
429
+		if (empty($messenger_names) && empty($message_type_names)) {
430
+			return 0;
431
+		}
432
+		if (! empty($messenger_names)) {
433
+			$query_args[0]['MTP_messenger'] = array( 'IN', (array) $messenger_names );
434
+		}
435
+		if (! empty($message_type_names)) {
436
+			$query_args[0]['MTP_message_type'] = array( 'IN', (array) $message_type_names );
437
+		}
438
+		return $this->update(array( 'MTP_is_active' => false ), $query_args);
439
+	}
440 440
 }
Please login to merge, or discard this patch.
core/db_models/fields/EE_Datetime_Field.php 2 patches
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -213,8 +213,8 @@  discard block
 block discarded – undo
213 213
 
214 214
             default:
215 215
                 return $pretty
216
-                    ? $this->_pretty_date_format . ' ' . $this->_pretty_time_format
217
-                    : $this->_date_format . ' ' . $this->_time_format;
216
+                    ? $this->_pretty_date_format.' '.$this->_pretty_time_format
217
+                    : $this->_date_format.' '.$this->_time_format;
218 218
         }
219 219
     }
220 220
 
@@ -468,7 +468,7 @@  discard block
 block discarded – undo
468 468
      */
469 469
     protected function _prepare_for_display($DateTime, $schema = false)
470 470
     {
471
-        if (! $DateTime instanceof DateTime) {
471
+        if ( ! $DateTime instanceof DateTime) {
472 472
             if ($this->_nullable) {
473 473
                 return '';
474 474
             } else {
@@ -502,15 +502,15 @@  discard block
 block discarded – undo
502 502
             if ($this->_display_timezone()) {
503 503
                 // must be explicit because schema could equal true.
504 504
                 if ($schema === 'no_html') {
505
-                    $timezone_string = ' (' . $DateTime->format('T') . ')';
505
+                    $timezone_string = ' ('.$DateTime->format('T').')';
506 506
                 } else {
507
-                    $timezone_string = ' <span class="ee_dtt_timezone_string">(' . $DateTime->format('T') . ')</span>';
507
+                    $timezone_string = ' <span class="ee_dtt_timezone_string">('.$DateTime->format('T').')</span>';
508 508
                 }
509 509
             } else {
510 510
                 $timezone_string = '';
511 511
             }
512 512
 
513
-            return $DateTime->format($format_string) . $timezone_string;
513
+            return $DateTime->format($format_string).$timezone_string;
514 514
         }
515 515
         return $DateTime->format($format_string);
516 516
     }
@@ -527,7 +527,7 @@  discard block
 block discarded – undo
527 527
     public function prepare_for_use_in_db($datetime_value)
528 528
     {
529 529
         // we allow an empty value or DateTime object, but nothing else.
530
-        if (! empty($datetime_value) && ! $datetime_value instanceof DateTime) {
530
+        if ( ! empty($datetime_value) && ! $datetime_value instanceof DateTime) {
531 531
             throw new EE_Error(
532 532
                 sprintf(
533 533
                     esc_html__(
@@ -542,7 +542,7 @@  discard block
 block discarded – undo
542 542
         }
543 543
 
544 544
         if ($datetime_value instanceof DateTime) {
545
-            if (! $datetime_value instanceof DbSafeDateTime) {
545
+            if ( ! $datetime_value instanceof DbSafeDateTime) {
546 546
                 $datetime_value = DbSafeDateTime::createFromDateTime($datetime_value);
547 547
             }
548 548
             EEH_DTT_Helper::setTimezone($datetime_value, $this->get_UTC_DateTimeZone());
@@ -581,7 +581,7 @@  discard block
 block discarded – undo
581 581
             );
582 582
         }
583 583
 
584
-        if (! $DateTime instanceof DbSafeDateTime) {
584
+        if ( ! $DateTime instanceof DbSafeDateTime) {
585 585
             // if still no datetime object, then let's just use now
586 586
             $DateTime = new DbSafeDateTime(\EE_Datetime_Field::now, $this->get_UTC_DateTimeZone());
587 587
         }
@@ -658,10 +658,10 @@  discard block
 block discarded – undo
658 658
         }
659 659
         // not a unix timestamp.  So we will use the set format on this object and set timezone to
660 660
         // create the DateTime object.
661
-        $format = $this->_date_format . ' ' . $this->_time_format;
661
+        $format = $this->_date_format.' '.$this->_time_format;
662 662
         try {
663 663
             $DateTime = DbSafeDateTime::createFromFormat($format, $date_string, $this->_DateTimeZone);
664
-            if (! $DateTime instanceof DbSafeDateTime) {
664
+            if ( ! $DateTime instanceof DbSafeDateTime) {
665 665
                 throw new EE_Error(
666 666
                     sprintf(
667 667
                         esc_html__('"%1$s" does not represent a valid Date Time in the format "%2$s".', 'event_espresso'),
Please login to merge, or discard this patch.
Indentation   +752 added lines, -752 removed lines patch added patch discarded remove patch
@@ -15,757 +15,757 @@
 block discarded – undo
15 15
  */
16 16
 class EE_Datetime_Field extends EE_Model_Field_Base
17 17
 {
18
-    /**
19
-     * The pattern we're looking for is if only the characters 0-9 are found and there are only
20
-     * 10 or more numbers (because 9 numbers even with all 9's would be sometime in 2001 )
21
-     *
22
-     * @type string unix_timestamp_regex
23
-     */
24
-    const unix_timestamp_regex = '/[0-9]{10,}/';
25
-
26
-    /**
27
-     * @type string mysql_timestamp_format
28
-     */
29
-    const mysql_timestamp_format = 'Y-m-d H:i:s';
30
-
31
-    /**
32
-     * @type string mysql_date_format
33
-     */
34
-    const mysql_date_format = 'Y-m-d';
35
-
36
-    /**
37
-     * @type string mysql_time_format
38
-     */
39
-    const mysql_time_format = 'H:i:s';
40
-
41
-    /**
42
-     * Const for using in the default value. If the field's default is set to this,
43
-     * then we will return the time of calling `get_default_value()`, not
44
-     * just the current time at construction
45
-     */
46
-    const now = 'now';
47
-
48
-    /**
49
-     * The following properties hold the default formats for date and time.
50
-     * Defaults are set via the constructor and can be overridden on class instantiation.
51
-     * However they can also be overridden later by the set_format() method
52
-     * (and corresponding set_date_format, set_time_format methods);
53
-     */
54
-    /**
55
-     * @type string $_date_format
56
-     */
57
-    protected $_date_format = '';
58
-
59
-    /**
60
-     * @type string $_time_format
61
-     */
62
-    protected $_time_format = '';
63
-
64
-    /**
65
-     * @type string $_pretty_date_format
66
-     */
67
-    protected $_pretty_date_format = '';
68
-
69
-    /**
70
-     * @type string $_pretty_time_format
71
-     */
72
-    protected $_pretty_time_format = '';
73
-
74
-    /**
75
-     * @type DateTimeZone $_DateTimeZone
76
-     */
77
-    protected $_DateTimeZone;
78
-
79
-    /**
80
-     * @type DateTimeZone $_UTC_DateTimeZone
81
-     */
82
-    protected $_UTC_DateTimeZone;
83
-
84
-    /**
85
-     * @type DateTimeZone $_blog_DateTimeZone
86
-     */
87
-    protected $_blog_DateTimeZone;
88
-
89
-
90
-    /**
91
-     * This property holds how we want the output returned when getting a datetime string.  It is set for the
92
-     * set_date_time_output() method.  By default this is empty.  When empty, we are assuming that we want both date
93
-     * and time returned via getters.
94
-     *
95
-     * @var mixed (null|string)
96
-     */
97
-    protected $_date_time_output;
98
-
99
-
100
-    /**
101
-     * timezone string
102
-     * This gets set by the constructor and can be changed by the "set_timezone()" method so that we know what timezone
103
-     * incoming strings|timestamps are in.  This can also be used before a get to set what timezone you want strings
104
-     * coming out of the object to be in.  Default timezone is the current WP timezone option setting
105
-     *
106
-     * @var string
107
-     */
108
-    protected $_timezone_string;
109
-
110
-
111
-    /**
112
-     * This holds whatever UTC offset for the blog (we automatically convert timezone strings into their related
113
-     * offsets for comparison purposes).
114
-     *
115
-     * @var int
116
-     */
117
-    protected $_blog_offset;
118
-
119
-
120
-
121
-    /**
122
-     * @param string $table_column
123
-     * @param string $nice_name
124
-     * @param bool   $nullable
125
-     * @param string $default_value
126
-     * @param string $timezone_string
127
-     * @param string $date_format
128
-     * @param string $time_format
129
-     * @param string $pretty_date_format
130
-     * @param string $pretty_time_format
131
-     * @throws EE_Error
132
-     * @throws InvalidArgumentException
133
-     */
134
-    public function __construct(
135
-        $table_column,
136
-        $nice_name,
137
-        $nullable,
138
-        $default_value,
139
-        $timezone_string = '',
140
-        $date_format = '',
141
-        $time_format = '',
142
-        $pretty_date_format = '',
143
-        $pretty_time_format = ''
144
-    ) {
145
-
146
-        $this->_date_format        = ! empty($date_format) ? $date_format : get_option('date_format');
147
-        $this->_time_format        = ! empty($time_format) ? $time_format : get_option('time_format');
148
-        $this->_pretty_date_format = ! empty($pretty_date_format) ? $pretty_date_format : get_option('date_format');
149
-        $this->_pretty_time_format = ! empty($pretty_time_format) ? $pretty_time_format : get_option('time_format');
150
-
151
-        parent::__construct($table_column, $nice_name, $nullable, $default_value);
152
-        $this->set_timezone($timezone_string);
153
-        $this->setSchemaFormat('date-time');
154
-    }
155
-
156
-
157
-    /**
158
-     * @return DateTimeZone
159
-     * @throws \EE_Error
160
-     */
161
-    public function get_UTC_DateTimeZone()
162
-    {
163
-        return $this->_UTC_DateTimeZone instanceof DateTimeZone
164
-            ? $this->_UTC_DateTimeZone
165
-            : $this->_create_timezone_object_from_timezone_string('UTC');
166
-    }
167
-
168
-
169
-    /**
170
-     * @return DateTimeZone
171
-     * @throws \EE_Error
172
-     */
173
-    public function get_blog_DateTimeZone()
174
-    {
175
-        return $this->_blog_DateTimeZone instanceof DateTimeZone
176
-            ? $this->_blog_DateTimeZone
177
-            : $this->_create_timezone_object_from_timezone_string('');
178
-    }
179
-
180
-
181
-    /**
182
-     * this prepares any incoming date data and make sure its converted to a utc unix timestamp
183
-     *
184
-     * @param  string|int $value_inputted_for_field_on_model_object could be a string formatted date time or int unix
185
-     *                                                              timestamp
186
-     * @return DateTime
187
-     */
188
-    public function prepare_for_set($value_inputted_for_field_on_model_object)
189
-    {
190
-        return $this->_get_date_object($value_inputted_for_field_on_model_object);
191
-    }
192
-
193
-
194
-    /**
195
-     * This returns the format string to be used by getters depending on what the $_date_time_output property is set at.
196
-     * getters need to know whether we're just returning the date or the time or both.  By default we return both.
197
-     *
198
-     * @param bool $pretty If we're returning the pretty formats or standard format string.
199
-     * @return string    The final assembled format string.
200
-     */
201
-    protected function _get_date_time_output($pretty = false)
202
-    {
203
-
204
-        switch ($this->_date_time_output) {
205
-            case 'time':
206
-                return $pretty ? $this->_pretty_time_format : $this->_time_format;
207
-                break;
208
-
209
-            case 'date':
210
-                return $pretty ? $this->_pretty_date_format : $this->_date_format;
211
-                break;
212
-
213
-            default:
214
-                return $pretty
215
-                    ? $this->_pretty_date_format . ' ' . $this->_pretty_time_format
216
-                    : $this->_date_format . ' ' . $this->_time_format;
217
-        }
218
-    }
219
-
220
-
221
-    /**
222
-     * This just sets the $_date_time_output property so we can flag how date and times are formatted before being
223
-     * returned (using the format properties)
224
-     *
225
-     * @param string $what acceptable values are 'time' or 'date'.
226
-     *                     Any other value will be set but will always result
227
-     *                     in both 'date' and 'time' being returned.
228
-     * @return void
229
-     */
230
-    public function set_date_time_output($what = null)
231
-    {
232
-        $this->_date_time_output = $what;
233
-    }
234
-
235
-
236
-    /**
237
-     * See $_timezone property for description of what the timezone property is for.  This SETS the timezone internally
238
-     * for being able to reference what timezone we are running conversions on when converting TO the internal timezone
239
-     * (UTC Unix Timestamp) for the object OR when converting FROM the internal timezone (UTC Unix Timestamp).
240
-     * We also set some other properties in this method.
241
-     *
242
-     * @param string $timezone_string A valid timezone string as described by @link
243
-     *                                http://www.php.net/manual/en/timezones.php
244
-     * @return void
245
-     * @throws InvalidArgumentException
246
-     * @throws InvalidDataTypeException
247
-     * @throws InvalidInterfaceException
248
-     */
249
-    public function set_timezone($timezone_string)
250
-    {
251
-        if (empty($timezone_string) && $this->_timezone_string !== null) {
252
-            // leave the timezone AS-IS if we already have one and
253
-            // the function arg didn't provide one
254
-            return;
255
-        }
256
-        $timezone_string        = EEH_DTT_Helper::get_valid_timezone_string($timezone_string);
257
-        $this->_timezone_string = ! empty($timezone_string) ? $timezone_string : 'UTC';
258
-        $this->_DateTimeZone    = $this->_create_timezone_object_from_timezone_string($this->_timezone_string);
259
-    }
260
-
261
-
262
-    /**
263
-     * _create_timezone_object_from_timezone_name
264
-     *
265
-     * @access protected
266
-     * @param string $timezone_string
267
-     * @return \DateTimeZone
268
-     * @throws InvalidArgumentException
269
-     * @throws InvalidDataTypeException
270
-     * @throws InvalidInterfaceException
271
-     */
272
-    protected function _create_timezone_object_from_timezone_string($timezone_string = '')
273
-    {
274
-        return new DateTimeZone(EEH_DTT_Helper::get_valid_timezone_string($timezone_string));
275
-    }
276
-
277
-
278
-    /**
279
-     * This just returns whatever is set for the current timezone.
280
-     *
281
-     * @access public
282
-     * @return string timezone string
283
-     */
284
-    public function get_timezone()
285
-    {
286
-        return $this->_timezone_string;
287
-    }
288
-
289
-
290
-    /**
291
-     * set the $_date_format property
292
-     *
293
-     * @access public
294
-     * @param string $format a new date format (corresponding to formats accepted by PHP date() function)
295
-     * @param bool   $pretty Whether to set pretty format or not.
296
-     * @return void
297
-     */
298
-    public function set_date_format($format, $pretty = false)
299
-    {
300
-        if ($pretty) {
301
-            $this->_pretty_date_format = $format;
302
-        } else {
303
-            $this->_date_format = $format;
304
-        }
305
-    }
306
-
307
-
308
-    /**
309
-     * return the $_date_format property value.
310
-     *
311
-     * @param bool $pretty Whether to get pretty format or not.
312
-     * @return string
313
-     */
314
-    public function get_date_format($pretty = false)
315
-    {
316
-        return $pretty ? $this->_pretty_date_format : $this->_date_format;
317
-    }
318
-
319
-
320
-    /**
321
-     * set the $_time_format property
322
-     *
323
-     * @access public
324
-     * @param string $format a new time format (corresponding to formats accepted by PHP date() function)
325
-     * @param bool   $pretty Whether to set pretty format or not.
326
-     * @return void
327
-     */
328
-    public function set_time_format($format, $pretty = false)
329
-    {
330
-        if ($pretty) {
331
-            $this->_pretty_time_format = $format;
332
-        } else {
333
-            $this->_time_format = $format;
334
-        }
335
-    }
336
-
337
-
338
-    /**
339
-     * return the $_time_format property value.
340
-     *
341
-     * @param bool $pretty Whether to get pretty format or not.
342
-     * @return string
343
-     */
344
-    public function get_time_format($pretty = false)
345
-    {
346
-        return $pretty ? $this->_pretty_time_format : $this->_time_format;
347
-    }
348
-
349
-
350
-    /**
351
-     * set the $_pretty_date_format property
352
-     *
353
-     * @access public
354
-     * @param string $format a new pretty date format (corresponding to formats accepted by PHP date() function)
355
-     * @return void
356
-     */
357
-    public function set_pretty_date_format($format)
358
-    {
359
-        $this->_pretty_date_format = $format;
360
-    }
361
-
362
-
363
-    /**
364
-     * set the $_pretty_time_format property
365
-     *
366
-     * @access public
367
-     * @param string $format a new pretty time format (corresponding to formats accepted by PHP date() function)
368
-     * @return void
369
-     */
370
-    public function set_pretty_time_format($format)
371
-    {
372
-        $this->_pretty_time_format = $format;
373
-    }
374
-
375
-
376
-    /**
377
-     * Only sets the time portion of the datetime.
378
-     *
379
-     * @param string|DateTime $time_to_set_string like 8am OR a DateTime object.
380
-     * @param DateTime        $current            current DateTime object for the datetime field
381
-     * @return DateTime
382
-     */
383
-    public function prepare_for_set_with_new_time($time_to_set_string, DateTime $current)
384
-    {
385
-        // if $time_to_set_string is datetime object, then let's use it to set the parse array.
386
-        // Otherwise parse the string.
387
-        if ($time_to_set_string instanceof DateTime) {
388
-            $parsed = array(
389
-                'hour'   => $time_to_set_string->format('H'),
390
-                'minute' => $time_to_set_string->format('i'),
391
-                'second' => $time_to_set_string->format('s'),
392
-            );
393
-        } else {
394
-            // parse incoming string
395
-            $parsed = date_parse_from_format($this->_time_format, $time_to_set_string);
396
-        }
397
-        EEH_DTT_Helper::setTimezone($current, $this->_DateTimeZone);
398
-        return $current->setTime($parsed['hour'], $parsed['minute'], $parsed['second']);
399
-    }
400
-
401
-
402
-    /**
403
-     * Only sets the date portion of the datetime.
404
-     *
405
-     * @param string|DateTime $date_to_set_string like Friday, January 8th or a DateTime object.
406
-     * @param DateTime        $current            current DateTime object for the datetime field
407
-     * @return DateTime
408
-     */
409
-    public function prepare_for_set_with_new_date($date_to_set_string, DateTime $current)
410
-    {
411
-        // if $time_to_set_string is datetime object, then let's use it to set the parse array.
412
-        // Otherwise parse the string.
413
-        if ($date_to_set_string instanceof DateTime) {
414
-            $parsed = array(
415
-                'year'  => $date_to_set_string->format('Y'),
416
-                'month' => $date_to_set_string->format('m'),
417
-                'day'   => $date_to_set_string->format('d'),
418
-            );
419
-        } else {
420
-            // parse incoming string
421
-            $parsed = date_parse_from_format($this->_date_format, $date_to_set_string);
422
-        }
423
-        EEH_DTT_Helper::setTimezone($current, $this->_DateTimeZone);
424
-        return $current->setDate($parsed['year'], $parsed['month'], $parsed['day']);
425
-    }
426
-
427
-
428
-    /**
429
-     * This prepares the EE_DateTime value to be saved to the db as mysql timestamp (UTC +0 timezone).  When the
430
-     * datetime gets to this stage it should ALREADY be in UTC time
431
-     *
432
-     * @param  DateTime $DateTime
433
-     * @return string formatted date time for given timezone
434
-     * @throws \EE_Error
435
-     */
436
-    public function prepare_for_get($DateTime)
437
-    {
438
-        return $this->_prepare_for_display($DateTime);
439
-    }
440
-
441
-
442
-    /**
443
-     * This differs from prepare_for_get in that it considers whether the internal $_timezone differs
444
-     * from the set wp timezone.  If so, then it returns the datetime string formatted via
445
-     * _pretty_date_format, and _pretty_time_format.  However, it also appends a timezone
446
-     * abbreviation to the date_string.
447
-     *
448
-     * @param mixed $DateTime
449
-     * @param null  $schema
450
-     * @return string
451
-     * @throws \EE_Error
452
-     */
453
-    public function prepare_for_pretty_echoing($DateTime, $schema = null)
454
-    {
455
-        return $this->_prepare_for_display($DateTime, $schema ? $schema : true);
456
-    }
457
-
458
-
459
-    /**
460
-     * This prepares the EE_DateTime value to be saved to the db as mysql timestamp (UTC +0
461
-     * timezone).
462
-     *
463
-     * @param DateTime    $DateTime
464
-     * @param bool|string $schema
465
-     * @return string
466
-     * @throws \EE_Error
467
-     */
468
-    protected function _prepare_for_display($DateTime, $schema = false)
469
-    {
470
-        if (! $DateTime instanceof DateTime) {
471
-            if ($this->_nullable) {
472
-                return '';
473
-            } else {
474
-                if (WP_DEBUG) {
475
-                    throw new EE_Error(
476
-                        sprintf(
477
-                            esc_html__(
478
-                                'EE_Datetime_Field::_prepare_for_display requires a DateTime class to be the value for the $DateTime argument because the %s field is not nullable.',
479
-                                'event_espresso'
480
-                            ),
481
-                            $this->_nicename
482
-                        )
483
-                    );
484
-                } else {
485
-                    $DateTime = new DbSafeDateTime(\EE_Datetime_Field::now);
486
-                    EE_Error::add_error(
487
-                        sprintf(
488
-                            esc_html__(
489
-                                'EE_Datetime_Field::_prepare_for_display requires a DateTime class to be the value for the $DateTime argument because the %s field is not nullable.  When WP_DEBUG is false, the value is set to "now" instead of throwing an exception.',
490
-                                'event_espresso'
491
-                            ),
492
-                            $this->_nicename
493
-                        )
494
-                    );
495
-                }
496
-            }
497
-        }
498
-        $format_string = $this->_get_date_time_output($schema);
499
-        EEH_DTT_Helper::setTimezone($DateTime, $this->_DateTimeZone);
500
-        if ($schema) {
501
-            if ($this->_display_timezone()) {
502
-                // must be explicit because schema could equal true.
503
-                if ($schema === 'no_html') {
504
-                    $timezone_string = ' (' . $DateTime->format('T') . ')';
505
-                } else {
506
-                    $timezone_string = ' <span class="ee_dtt_timezone_string">(' . $DateTime->format('T') . ')</span>';
507
-                }
508
-            } else {
509
-                $timezone_string = '';
510
-            }
511
-
512
-            return $DateTime->format($format_string) . $timezone_string;
513
-        }
514
-        return $DateTime->format($format_string);
515
-    }
516
-
517
-
518
-    /**
519
-     * This prepares the EE_DateTime value to be saved to the db as mysql timestamp (UTC +0
520
-     * timezone).
521
-     *
522
-     * @param  mixed $datetime_value u
523
-     * @return string mysql timestamp in UTC
524
-     * @throws \EE_Error
525
-     */
526
-    public function prepare_for_use_in_db($datetime_value)
527
-    {
528
-        // we allow an empty value or DateTime object, but nothing else.
529
-        if (! empty($datetime_value) && ! $datetime_value instanceof DateTime) {
530
-            throw new EE_Error(
531
-                sprintf(
532
-                    esc_html__(
533
-                        'The incoming value being prepared for setting in the database must either be empty or a php 
18
+	/**
19
+	 * The pattern we're looking for is if only the characters 0-9 are found and there are only
20
+	 * 10 or more numbers (because 9 numbers even with all 9's would be sometime in 2001 )
21
+	 *
22
+	 * @type string unix_timestamp_regex
23
+	 */
24
+	const unix_timestamp_regex = '/[0-9]{10,}/';
25
+
26
+	/**
27
+	 * @type string mysql_timestamp_format
28
+	 */
29
+	const mysql_timestamp_format = 'Y-m-d H:i:s';
30
+
31
+	/**
32
+	 * @type string mysql_date_format
33
+	 */
34
+	const mysql_date_format = 'Y-m-d';
35
+
36
+	/**
37
+	 * @type string mysql_time_format
38
+	 */
39
+	const mysql_time_format = 'H:i:s';
40
+
41
+	/**
42
+	 * Const for using in the default value. If the field's default is set to this,
43
+	 * then we will return the time of calling `get_default_value()`, not
44
+	 * just the current time at construction
45
+	 */
46
+	const now = 'now';
47
+
48
+	/**
49
+	 * The following properties hold the default formats for date and time.
50
+	 * Defaults are set via the constructor and can be overridden on class instantiation.
51
+	 * However they can also be overridden later by the set_format() method
52
+	 * (and corresponding set_date_format, set_time_format methods);
53
+	 */
54
+	/**
55
+	 * @type string $_date_format
56
+	 */
57
+	protected $_date_format = '';
58
+
59
+	/**
60
+	 * @type string $_time_format
61
+	 */
62
+	protected $_time_format = '';
63
+
64
+	/**
65
+	 * @type string $_pretty_date_format
66
+	 */
67
+	protected $_pretty_date_format = '';
68
+
69
+	/**
70
+	 * @type string $_pretty_time_format
71
+	 */
72
+	protected $_pretty_time_format = '';
73
+
74
+	/**
75
+	 * @type DateTimeZone $_DateTimeZone
76
+	 */
77
+	protected $_DateTimeZone;
78
+
79
+	/**
80
+	 * @type DateTimeZone $_UTC_DateTimeZone
81
+	 */
82
+	protected $_UTC_DateTimeZone;
83
+
84
+	/**
85
+	 * @type DateTimeZone $_blog_DateTimeZone
86
+	 */
87
+	protected $_blog_DateTimeZone;
88
+
89
+
90
+	/**
91
+	 * This property holds how we want the output returned when getting a datetime string.  It is set for the
92
+	 * set_date_time_output() method.  By default this is empty.  When empty, we are assuming that we want both date
93
+	 * and time returned via getters.
94
+	 *
95
+	 * @var mixed (null|string)
96
+	 */
97
+	protected $_date_time_output;
98
+
99
+
100
+	/**
101
+	 * timezone string
102
+	 * This gets set by the constructor and can be changed by the "set_timezone()" method so that we know what timezone
103
+	 * incoming strings|timestamps are in.  This can also be used before a get to set what timezone you want strings
104
+	 * coming out of the object to be in.  Default timezone is the current WP timezone option setting
105
+	 *
106
+	 * @var string
107
+	 */
108
+	protected $_timezone_string;
109
+
110
+
111
+	/**
112
+	 * This holds whatever UTC offset for the blog (we automatically convert timezone strings into their related
113
+	 * offsets for comparison purposes).
114
+	 *
115
+	 * @var int
116
+	 */
117
+	protected $_blog_offset;
118
+
119
+
120
+
121
+	/**
122
+	 * @param string $table_column
123
+	 * @param string $nice_name
124
+	 * @param bool   $nullable
125
+	 * @param string $default_value
126
+	 * @param string $timezone_string
127
+	 * @param string $date_format
128
+	 * @param string $time_format
129
+	 * @param string $pretty_date_format
130
+	 * @param string $pretty_time_format
131
+	 * @throws EE_Error
132
+	 * @throws InvalidArgumentException
133
+	 */
134
+	public function __construct(
135
+		$table_column,
136
+		$nice_name,
137
+		$nullable,
138
+		$default_value,
139
+		$timezone_string = '',
140
+		$date_format = '',
141
+		$time_format = '',
142
+		$pretty_date_format = '',
143
+		$pretty_time_format = ''
144
+	) {
145
+
146
+		$this->_date_format        = ! empty($date_format) ? $date_format : get_option('date_format');
147
+		$this->_time_format        = ! empty($time_format) ? $time_format : get_option('time_format');
148
+		$this->_pretty_date_format = ! empty($pretty_date_format) ? $pretty_date_format : get_option('date_format');
149
+		$this->_pretty_time_format = ! empty($pretty_time_format) ? $pretty_time_format : get_option('time_format');
150
+
151
+		parent::__construct($table_column, $nice_name, $nullable, $default_value);
152
+		$this->set_timezone($timezone_string);
153
+		$this->setSchemaFormat('date-time');
154
+	}
155
+
156
+
157
+	/**
158
+	 * @return DateTimeZone
159
+	 * @throws \EE_Error
160
+	 */
161
+	public function get_UTC_DateTimeZone()
162
+	{
163
+		return $this->_UTC_DateTimeZone instanceof DateTimeZone
164
+			? $this->_UTC_DateTimeZone
165
+			: $this->_create_timezone_object_from_timezone_string('UTC');
166
+	}
167
+
168
+
169
+	/**
170
+	 * @return DateTimeZone
171
+	 * @throws \EE_Error
172
+	 */
173
+	public function get_blog_DateTimeZone()
174
+	{
175
+		return $this->_blog_DateTimeZone instanceof DateTimeZone
176
+			? $this->_blog_DateTimeZone
177
+			: $this->_create_timezone_object_from_timezone_string('');
178
+	}
179
+
180
+
181
+	/**
182
+	 * this prepares any incoming date data and make sure its converted to a utc unix timestamp
183
+	 *
184
+	 * @param  string|int $value_inputted_for_field_on_model_object could be a string formatted date time or int unix
185
+	 *                                                              timestamp
186
+	 * @return DateTime
187
+	 */
188
+	public function prepare_for_set($value_inputted_for_field_on_model_object)
189
+	{
190
+		return $this->_get_date_object($value_inputted_for_field_on_model_object);
191
+	}
192
+
193
+
194
+	/**
195
+	 * This returns the format string to be used by getters depending on what the $_date_time_output property is set at.
196
+	 * getters need to know whether we're just returning the date or the time or both.  By default we return both.
197
+	 *
198
+	 * @param bool $pretty If we're returning the pretty formats or standard format string.
199
+	 * @return string    The final assembled format string.
200
+	 */
201
+	protected function _get_date_time_output($pretty = false)
202
+	{
203
+
204
+		switch ($this->_date_time_output) {
205
+			case 'time':
206
+				return $pretty ? $this->_pretty_time_format : $this->_time_format;
207
+				break;
208
+
209
+			case 'date':
210
+				return $pretty ? $this->_pretty_date_format : $this->_date_format;
211
+				break;
212
+
213
+			default:
214
+				return $pretty
215
+					? $this->_pretty_date_format . ' ' . $this->_pretty_time_format
216
+					: $this->_date_format . ' ' . $this->_time_format;
217
+		}
218
+	}
219
+
220
+
221
+	/**
222
+	 * This just sets the $_date_time_output property so we can flag how date and times are formatted before being
223
+	 * returned (using the format properties)
224
+	 *
225
+	 * @param string $what acceptable values are 'time' or 'date'.
226
+	 *                     Any other value will be set but will always result
227
+	 *                     in both 'date' and 'time' being returned.
228
+	 * @return void
229
+	 */
230
+	public function set_date_time_output($what = null)
231
+	{
232
+		$this->_date_time_output = $what;
233
+	}
234
+
235
+
236
+	/**
237
+	 * See $_timezone property for description of what the timezone property is for.  This SETS the timezone internally
238
+	 * for being able to reference what timezone we are running conversions on when converting TO the internal timezone
239
+	 * (UTC Unix Timestamp) for the object OR when converting FROM the internal timezone (UTC Unix Timestamp).
240
+	 * We also set some other properties in this method.
241
+	 *
242
+	 * @param string $timezone_string A valid timezone string as described by @link
243
+	 *                                http://www.php.net/manual/en/timezones.php
244
+	 * @return void
245
+	 * @throws InvalidArgumentException
246
+	 * @throws InvalidDataTypeException
247
+	 * @throws InvalidInterfaceException
248
+	 */
249
+	public function set_timezone($timezone_string)
250
+	{
251
+		if (empty($timezone_string) && $this->_timezone_string !== null) {
252
+			// leave the timezone AS-IS if we already have one and
253
+			// the function arg didn't provide one
254
+			return;
255
+		}
256
+		$timezone_string        = EEH_DTT_Helper::get_valid_timezone_string($timezone_string);
257
+		$this->_timezone_string = ! empty($timezone_string) ? $timezone_string : 'UTC';
258
+		$this->_DateTimeZone    = $this->_create_timezone_object_from_timezone_string($this->_timezone_string);
259
+	}
260
+
261
+
262
+	/**
263
+	 * _create_timezone_object_from_timezone_name
264
+	 *
265
+	 * @access protected
266
+	 * @param string $timezone_string
267
+	 * @return \DateTimeZone
268
+	 * @throws InvalidArgumentException
269
+	 * @throws InvalidDataTypeException
270
+	 * @throws InvalidInterfaceException
271
+	 */
272
+	protected function _create_timezone_object_from_timezone_string($timezone_string = '')
273
+	{
274
+		return new DateTimeZone(EEH_DTT_Helper::get_valid_timezone_string($timezone_string));
275
+	}
276
+
277
+
278
+	/**
279
+	 * This just returns whatever is set for the current timezone.
280
+	 *
281
+	 * @access public
282
+	 * @return string timezone string
283
+	 */
284
+	public function get_timezone()
285
+	{
286
+		return $this->_timezone_string;
287
+	}
288
+
289
+
290
+	/**
291
+	 * set the $_date_format property
292
+	 *
293
+	 * @access public
294
+	 * @param string $format a new date format (corresponding to formats accepted by PHP date() function)
295
+	 * @param bool   $pretty Whether to set pretty format or not.
296
+	 * @return void
297
+	 */
298
+	public function set_date_format($format, $pretty = false)
299
+	{
300
+		if ($pretty) {
301
+			$this->_pretty_date_format = $format;
302
+		} else {
303
+			$this->_date_format = $format;
304
+		}
305
+	}
306
+
307
+
308
+	/**
309
+	 * return the $_date_format property value.
310
+	 *
311
+	 * @param bool $pretty Whether to get pretty format or not.
312
+	 * @return string
313
+	 */
314
+	public function get_date_format($pretty = false)
315
+	{
316
+		return $pretty ? $this->_pretty_date_format : $this->_date_format;
317
+	}
318
+
319
+
320
+	/**
321
+	 * set the $_time_format property
322
+	 *
323
+	 * @access public
324
+	 * @param string $format a new time format (corresponding to formats accepted by PHP date() function)
325
+	 * @param bool   $pretty Whether to set pretty format or not.
326
+	 * @return void
327
+	 */
328
+	public function set_time_format($format, $pretty = false)
329
+	{
330
+		if ($pretty) {
331
+			$this->_pretty_time_format = $format;
332
+		} else {
333
+			$this->_time_format = $format;
334
+		}
335
+	}
336
+
337
+
338
+	/**
339
+	 * return the $_time_format property value.
340
+	 *
341
+	 * @param bool $pretty Whether to get pretty format or not.
342
+	 * @return string
343
+	 */
344
+	public function get_time_format($pretty = false)
345
+	{
346
+		return $pretty ? $this->_pretty_time_format : $this->_time_format;
347
+	}
348
+
349
+
350
+	/**
351
+	 * set the $_pretty_date_format property
352
+	 *
353
+	 * @access public
354
+	 * @param string $format a new pretty date format (corresponding to formats accepted by PHP date() function)
355
+	 * @return void
356
+	 */
357
+	public function set_pretty_date_format($format)
358
+	{
359
+		$this->_pretty_date_format = $format;
360
+	}
361
+
362
+
363
+	/**
364
+	 * set the $_pretty_time_format property
365
+	 *
366
+	 * @access public
367
+	 * @param string $format a new pretty time format (corresponding to formats accepted by PHP date() function)
368
+	 * @return void
369
+	 */
370
+	public function set_pretty_time_format($format)
371
+	{
372
+		$this->_pretty_time_format = $format;
373
+	}
374
+
375
+
376
+	/**
377
+	 * Only sets the time portion of the datetime.
378
+	 *
379
+	 * @param string|DateTime $time_to_set_string like 8am OR a DateTime object.
380
+	 * @param DateTime        $current            current DateTime object for the datetime field
381
+	 * @return DateTime
382
+	 */
383
+	public function prepare_for_set_with_new_time($time_to_set_string, DateTime $current)
384
+	{
385
+		// if $time_to_set_string is datetime object, then let's use it to set the parse array.
386
+		// Otherwise parse the string.
387
+		if ($time_to_set_string instanceof DateTime) {
388
+			$parsed = array(
389
+				'hour'   => $time_to_set_string->format('H'),
390
+				'minute' => $time_to_set_string->format('i'),
391
+				'second' => $time_to_set_string->format('s'),
392
+			);
393
+		} else {
394
+			// parse incoming string
395
+			$parsed = date_parse_from_format($this->_time_format, $time_to_set_string);
396
+		}
397
+		EEH_DTT_Helper::setTimezone($current, $this->_DateTimeZone);
398
+		return $current->setTime($parsed['hour'], $parsed['minute'], $parsed['second']);
399
+	}
400
+
401
+
402
+	/**
403
+	 * Only sets the date portion of the datetime.
404
+	 *
405
+	 * @param string|DateTime $date_to_set_string like Friday, January 8th or a DateTime object.
406
+	 * @param DateTime        $current            current DateTime object for the datetime field
407
+	 * @return DateTime
408
+	 */
409
+	public function prepare_for_set_with_new_date($date_to_set_string, DateTime $current)
410
+	{
411
+		// if $time_to_set_string is datetime object, then let's use it to set the parse array.
412
+		// Otherwise parse the string.
413
+		if ($date_to_set_string instanceof DateTime) {
414
+			$parsed = array(
415
+				'year'  => $date_to_set_string->format('Y'),
416
+				'month' => $date_to_set_string->format('m'),
417
+				'day'   => $date_to_set_string->format('d'),
418
+			);
419
+		} else {
420
+			// parse incoming string
421
+			$parsed = date_parse_from_format($this->_date_format, $date_to_set_string);
422
+		}
423
+		EEH_DTT_Helper::setTimezone($current, $this->_DateTimeZone);
424
+		return $current->setDate($parsed['year'], $parsed['month'], $parsed['day']);
425
+	}
426
+
427
+
428
+	/**
429
+	 * This prepares the EE_DateTime value to be saved to the db as mysql timestamp (UTC +0 timezone).  When the
430
+	 * datetime gets to this stage it should ALREADY be in UTC time
431
+	 *
432
+	 * @param  DateTime $DateTime
433
+	 * @return string formatted date time for given timezone
434
+	 * @throws \EE_Error
435
+	 */
436
+	public function prepare_for_get($DateTime)
437
+	{
438
+		return $this->_prepare_for_display($DateTime);
439
+	}
440
+
441
+
442
+	/**
443
+	 * This differs from prepare_for_get in that it considers whether the internal $_timezone differs
444
+	 * from the set wp timezone.  If so, then it returns the datetime string formatted via
445
+	 * _pretty_date_format, and _pretty_time_format.  However, it also appends a timezone
446
+	 * abbreviation to the date_string.
447
+	 *
448
+	 * @param mixed $DateTime
449
+	 * @param null  $schema
450
+	 * @return string
451
+	 * @throws \EE_Error
452
+	 */
453
+	public function prepare_for_pretty_echoing($DateTime, $schema = null)
454
+	{
455
+		return $this->_prepare_for_display($DateTime, $schema ? $schema : true);
456
+	}
457
+
458
+
459
+	/**
460
+	 * This prepares the EE_DateTime value to be saved to the db as mysql timestamp (UTC +0
461
+	 * timezone).
462
+	 *
463
+	 * @param DateTime    $DateTime
464
+	 * @param bool|string $schema
465
+	 * @return string
466
+	 * @throws \EE_Error
467
+	 */
468
+	protected function _prepare_for_display($DateTime, $schema = false)
469
+	{
470
+		if (! $DateTime instanceof DateTime) {
471
+			if ($this->_nullable) {
472
+				return '';
473
+			} else {
474
+				if (WP_DEBUG) {
475
+					throw new EE_Error(
476
+						sprintf(
477
+							esc_html__(
478
+								'EE_Datetime_Field::_prepare_for_display requires a DateTime class to be the value for the $DateTime argument because the %s field is not nullable.',
479
+								'event_espresso'
480
+							),
481
+							$this->_nicename
482
+						)
483
+					);
484
+				} else {
485
+					$DateTime = new DbSafeDateTime(\EE_Datetime_Field::now);
486
+					EE_Error::add_error(
487
+						sprintf(
488
+							esc_html__(
489
+								'EE_Datetime_Field::_prepare_for_display requires a DateTime class to be the value for the $DateTime argument because the %s field is not nullable.  When WP_DEBUG is false, the value is set to "now" instead of throwing an exception.',
490
+								'event_espresso'
491
+							),
492
+							$this->_nicename
493
+						)
494
+					);
495
+				}
496
+			}
497
+		}
498
+		$format_string = $this->_get_date_time_output($schema);
499
+		EEH_DTT_Helper::setTimezone($DateTime, $this->_DateTimeZone);
500
+		if ($schema) {
501
+			if ($this->_display_timezone()) {
502
+				// must be explicit because schema could equal true.
503
+				if ($schema === 'no_html') {
504
+					$timezone_string = ' (' . $DateTime->format('T') . ')';
505
+				} else {
506
+					$timezone_string = ' <span class="ee_dtt_timezone_string">(' . $DateTime->format('T') . ')</span>';
507
+				}
508
+			} else {
509
+				$timezone_string = '';
510
+			}
511
+
512
+			return $DateTime->format($format_string) . $timezone_string;
513
+		}
514
+		return $DateTime->format($format_string);
515
+	}
516
+
517
+
518
+	/**
519
+	 * This prepares the EE_DateTime value to be saved to the db as mysql timestamp (UTC +0
520
+	 * timezone).
521
+	 *
522
+	 * @param  mixed $datetime_value u
523
+	 * @return string mysql timestamp in UTC
524
+	 * @throws \EE_Error
525
+	 */
526
+	public function prepare_for_use_in_db($datetime_value)
527
+	{
528
+		// we allow an empty value or DateTime object, but nothing else.
529
+		if (! empty($datetime_value) && ! $datetime_value instanceof DateTime) {
530
+			throw new EE_Error(
531
+				sprintf(
532
+					esc_html__(
533
+						'The incoming value being prepared for setting in the database must either be empty or a php 
534 534
             		    DateTime object, instead of: %1$s %2$s',
535
-                        'event_espresso'
536
-                    ),
537
-                    '<br />',
538
-                    print_r($datetime_value, true)
539
-                )
540
-            );
541
-        }
542
-
543
-        if ($datetime_value instanceof DateTime) {
544
-            if (! $datetime_value instanceof DbSafeDateTime) {
545
-                $datetime_value = DbSafeDateTime::createFromDateTime($datetime_value);
546
-            }
547
-            EEH_DTT_Helper::setTimezone($datetime_value, $this->get_UTC_DateTimeZone());
548
-            return $datetime_value->format(
549
-                EE_Datetime_Field::mysql_timestamp_format
550
-            );
551
-        }
552
-
553
-        // if $datetime_value is empty, and ! $this->_nullable, use current_time() but set the GMT flag to true
554
-        return ! $this->_nullable && empty($datetime_value) ? current_time('mysql', true) : null;
555
-    }
556
-
557
-
558
-    /**
559
-     * This prepares the datetime for internal usage as a PHP DateTime object OR null (if nullable is
560
-     * allowed)
561
-     *
562
-     * @param string $datetime_string mysql timestamp in UTC
563
-     * @return  mixed null | DateTime
564
-     * @throws \EE_Error
565
-     */
566
-    public function prepare_for_set_from_db($datetime_string)
567
-    {
568
-        // if $datetime_value is empty, and ! $this->_nullable, just use time()
569
-        if (empty($datetime_string) && $this->_nullable) {
570
-            return null;
571
-        }
572
-        // datetime strings from the db should ALWAYS be in UTC+0, so use UTC_DateTimeZone when creating
573
-        if (empty($datetime_string)) {
574
-            $DateTime = new DbSafeDateTime(\EE_Datetime_Field::now, $this->get_UTC_DateTimeZone());
575
-        } else {
576
-            $DateTime = DbSafeDateTime::createFromFormat(
577
-                EE_Datetime_Field::mysql_timestamp_format,
578
-                $datetime_string,
579
-                $this->get_UTC_DateTimeZone()
580
-            );
581
-        }
582
-
583
-        if (! $DateTime instanceof DbSafeDateTime) {
584
-            // if still no datetime object, then let's just use now
585
-            $DateTime = new DbSafeDateTime(\EE_Datetime_Field::now, $this->get_UTC_DateTimeZone());
586
-        }
587
-        // THEN apply the field's set DateTimeZone
588
-        EEH_DTT_Helper::setTimezone($DateTime, $this->_DateTimeZone);
589
-        return $DateTime;
590
-    }
591
-
592
-
593
-    /**
594
-     * All this method does is determine if we're going to display the timezone string or not on any output.
595
-     * To determine this we check if the set timezone offset is different than the blog's set timezone offset.
596
-     * If so, then true.
597
-     *
598
-     * @return bool true for yes false for no
599
-     * @throws \EE_Error
600
-     */
601
-    protected function _display_timezone()
602
-    {
603
-
604
-        // first let's do a comparison of timezone strings.
605
-        // If they match then we can get out without any further calculations
606
-        $blog_string = get_option('timezone_string');
607
-        if ($blog_string === $this->_timezone_string) {
608
-            return false;
609
-        }
610
-        // now we need to calc the offset for the timezone string so we can compare with the blog offset.
611
-        $this_offset = $this->get_timezone_offset($this->_DateTimeZone);
612
-        $blog_offset = $this->get_timezone_offset($this->get_blog_DateTimeZone());
613
-        // now compare
614
-        return $blog_offset !== $this_offset;
615
-    }
616
-
617
-
618
-    /**
619
-     * This method returns a php DateTime object for setting on the EE_Base_Class model.
620
-     * EE passes around DateTime objects because they are MUCH easier to manipulate and deal
621
-     * with.
622
-     *
623
-     * @param int|string|DateTime $date_string            This should be the incoming date string.  It's assumed to be
624
-     *                                                    in the format that is set on the date_field (or DateTime
625
-     *                                                    object)!
626
-     * @return DateTime
627
-     */
628
-    protected function _get_date_object($date_string)
629
-    {
630
-        // first if this is an empty date_string and nullable is allowed, just return null.
631
-        if ($this->_nullable && empty($date_string)) {
632
-            return null;
633
-        }
634
-
635
-        // if incoming date
636
-        if ($date_string instanceof DateTime) {
637
-            EEH_DTT_Helper::setTimezone($date_string, $this->_DateTimeZone);
638
-            return $date_string;
639
-        }
640
-        // if empty date_string and made it here.
641
-        // Return a datetime object for now in the given timezone.
642
-        if (empty($date_string)) {
643
-            return new DbSafeDateTime(\EE_Datetime_Field::now, $this->_DateTimeZone);
644
-        }
645
-        // if $date_string is matches something that looks like a Unix timestamp let's just use it.
646
-        if (preg_match(EE_Datetime_Field::unix_timestamp_regex, $date_string)) {
647
-            try {
648
-                // This is operating under the assumption that the incoming Unix timestamp
649
-                // is an ACTUAL Unix timestamp and not the calculated one output by current_time('timestamp');
650
-                $DateTime = new DbSafeDateTime(\EE_Datetime_Field::now, $this->_DateTimeZone);
651
-                $DateTime->setTimestamp($date_string);
652
-
653
-                return $DateTime;
654
-            } catch (Exception $e) {
655
-                // should be rare, but if things got fooled then let's just continue
656
-            }
657
-        }
658
-        // not a unix timestamp.  So we will use the set format on this object and set timezone to
659
-        // create the DateTime object.
660
-        $format = $this->_date_format . ' ' . $this->_time_format;
661
-        try {
662
-            $DateTime = DbSafeDateTime::createFromFormat($format, $date_string, $this->_DateTimeZone);
663
-            if (! $DateTime instanceof DbSafeDateTime) {
664
-                throw new EE_Error(
665
-                    sprintf(
666
-                        esc_html__('"%1$s" does not represent a valid Date Time in the format "%2$s".', 'event_espresso'),
667
-                        $date_string,
668
-                        $format
669
-                    )
670
-                );
671
-            }
672
-        } catch (Exception $e) {
673
-            // if we made it here then likely then something went really wrong.
674
-            // Instead of throwing an exception, let's just return a DateTime object for now, in the set timezone.
675
-            $DateTime = new DbSafeDateTime(\EE_Datetime_Field::now, $this->_DateTimeZone);
676
-        }
677
-
678
-        return $DateTime;
679
-    }
680
-
681
-
682
-
683
-    /**
684
-     * get_timezone_transitions
685
-     *
686
-     * @param \DateTimeZone $DateTimeZone
687
-     * @param int           $time
688
-     * @param bool          $first_only
689
-     * @return mixed
690
-     */
691
-    public function get_timezone_transitions(DateTimeZone $DateTimeZone, $time = null, $first_only = true)
692
-    {
693
-        return EEH_DTT_Helper::get_timezone_transitions($DateTimeZone, $time, $first_only);
694
-    }
695
-
696
-
697
-
698
-    /**
699
-     * get_timezone_offset
700
-     *
701
-     * @param \DateTimeZone $DateTimeZone
702
-     * @param int           $time
703
-     * @return mixed
704
-     * @throws \DomainException
705
-     */
706
-    public function get_timezone_offset(DateTimeZone $DateTimeZone, $time = null)
707
-    {
708
-        return EEH_DTT_Helper::get_timezone_offset($DateTimeZone, $time);
709
-    }
710
-
711
-
712
-    /**
713
-     * This will take an incoming timezone string and return the abbreviation for that timezone
714
-     *
715
-     * @param  string $timezone_string
716
-     * @return string           abbreviation
717
-     * @throws \EE_Error
718
-     */
719
-    public function get_timezone_abbrev($timezone_string)
720
-    {
721
-        $timezone_string = EEH_DTT_Helper::get_valid_timezone_string($timezone_string);
722
-        $dateTime        = new DateTime(\EE_Datetime_Field::now, new DateTimeZone($timezone_string));
723
-
724
-        return $dateTime->format('T');
725
-    }
726
-
727
-    /**
728
-     * Overrides the parent to allow for having a dynamic "now" value
729
-     *
730
-     * @return mixed
731
-     */
732
-    public function get_default_value()
733
-    {
734
-        if ($this->_default_value === EE_Datetime_Field::now) {
735
-            return time();
736
-        } else {
737
-            return parent::get_default_value();
738
-        }
739
-    }
740
-
741
-    /**
742
-     * Gets the default datetime object from the field's default time
743
-     * @since 4.9.66.p
744
-     * @return DbSafeDateTime|null
745
-     * @throws InvalidArgumentException
746
-     * @throws InvalidDataTypeException
747
-     * @throws InvalidInterfaceException
748
-     */
749
-    public function getDefaultDateTimeObj()
750
-    {
751
-        $default_raw = $this->get_default_value();
752
-        if ($default_raw instanceof DateTime) {
753
-            return $default_raw;
754
-        } elseif (is_null($default_raw)) {
755
-            return $default_raw;
756
-        } else {
757
-            return new DbSafeDateTime(
758
-                $this->get_default_value(),
759
-                EEH_DTT_Helper::get_valid_timezone_string($this->get_timezone())
760
-            );
761
-        }
762
-    }
763
-
764
-    public function getSchemaDescription()
765
-    {
766
-        return sprintf(
767
-            esc_html__('%s - the value for this field is in the timezone of the site.', 'event_espresso'),
768
-            $this->get_nicename()
769
-        );
770
-    }
535
+						'event_espresso'
536
+					),
537
+					'<br />',
538
+					print_r($datetime_value, true)
539
+				)
540
+			);
541
+		}
542
+
543
+		if ($datetime_value instanceof DateTime) {
544
+			if (! $datetime_value instanceof DbSafeDateTime) {
545
+				$datetime_value = DbSafeDateTime::createFromDateTime($datetime_value);
546
+			}
547
+			EEH_DTT_Helper::setTimezone($datetime_value, $this->get_UTC_DateTimeZone());
548
+			return $datetime_value->format(
549
+				EE_Datetime_Field::mysql_timestamp_format
550
+			);
551
+		}
552
+
553
+		// if $datetime_value is empty, and ! $this->_nullable, use current_time() but set the GMT flag to true
554
+		return ! $this->_nullable && empty($datetime_value) ? current_time('mysql', true) : null;
555
+	}
556
+
557
+
558
+	/**
559
+	 * This prepares the datetime for internal usage as a PHP DateTime object OR null (if nullable is
560
+	 * allowed)
561
+	 *
562
+	 * @param string $datetime_string mysql timestamp in UTC
563
+	 * @return  mixed null | DateTime
564
+	 * @throws \EE_Error
565
+	 */
566
+	public function prepare_for_set_from_db($datetime_string)
567
+	{
568
+		// if $datetime_value is empty, and ! $this->_nullable, just use time()
569
+		if (empty($datetime_string) && $this->_nullable) {
570
+			return null;
571
+		}
572
+		// datetime strings from the db should ALWAYS be in UTC+0, so use UTC_DateTimeZone when creating
573
+		if (empty($datetime_string)) {
574
+			$DateTime = new DbSafeDateTime(\EE_Datetime_Field::now, $this->get_UTC_DateTimeZone());
575
+		} else {
576
+			$DateTime = DbSafeDateTime::createFromFormat(
577
+				EE_Datetime_Field::mysql_timestamp_format,
578
+				$datetime_string,
579
+				$this->get_UTC_DateTimeZone()
580
+			);
581
+		}
582
+
583
+		if (! $DateTime instanceof DbSafeDateTime) {
584
+			// if still no datetime object, then let's just use now
585
+			$DateTime = new DbSafeDateTime(\EE_Datetime_Field::now, $this->get_UTC_DateTimeZone());
586
+		}
587
+		// THEN apply the field's set DateTimeZone
588
+		EEH_DTT_Helper::setTimezone($DateTime, $this->_DateTimeZone);
589
+		return $DateTime;
590
+	}
591
+
592
+
593
+	/**
594
+	 * All this method does is determine if we're going to display the timezone string or not on any output.
595
+	 * To determine this we check if the set timezone offset is different than the blog's set timezone offset.
596
+	 * If so, then true.
597
+	 *
598
+	 * @return bool true for yes false for no
599
+	 * @throws \EE_Error
600
+	 */
601
+	protected function _display_timezone()
602
+	{
603
+
604
+		// first let's do a comparison of timezone strings.
605
+		// If they match then we can get out without any further calculations
606
+		$blog_string = get_option('timezone_string');
607
+		if ($blog_string === $this->_timezone_string) {
608
+			return false;
609
+		}
610
+		// now we need to calc the offset for the timezone string so we can compare with the blog offset.
611
+		$this_offset = $this->get_timezone_offset($this->_DateTimeZone);
612
+		$blog_offset = $this->get_timezone_offset($this->get_blog_DateTimeZone());
613
+		// now compare
614
+		return $blog_offset !== $this_offset;
615
+	}
616
+
617
+
618
+	/**
619
+	 * This method returns a php DateTime object for setting on the EE_Base_Class model.
620
+	 * EE passes around DateTime objects because they are MUCH easier to manipulate and deal
621
+	 * with.
622
+	 *
623
+	 * @param int|string|DateTime $date_string            This should be the incoming date string.  It's assumed to be
624
+	 *                                                    in the format that is set on the date_field (or DateTime
625
+	 *                                                    object)!
626
+	 * @return DateTime
627
+	 */
628
+	protected function _get_date_object($date_string)
629
+	{
630
+		// first if this is an empty date_string and nullable is allowed, just return null.
631
+		if ($this->_nullable && empty($date_string)) {
632
+			return null;
633
+		}
634
+
635
+		// if incoming date
636
+		if ($date_string instanceof DateTime) {
637
+			EEH_DTT_Helper::setTimezone($date_string, $this->_DateTimeZone);
638
+			return $date_string;
639
+		}
640
+		// if empty date_string and made it here.
641
+		// Return a datetime object for now in the given timezone.
642
+		if (empty($date_string)) {
643
+			return new DbSafeDateTime(\EE_Datetime_Field::now, $this->_DateTimeZone);
644
+		}
645
+		// if $date_string is matches something that looks like a Unix timestamp let's just use it.
646
+		if (preg_match(EE_Datetime_Field::unix_timestamp_regex, $date_string)) {
647
+			try {
648
+				// This is operating under the assumption that the incoming Unix timestamp
649
+				// is an ACTUAL Unix timestamp and not the calculated one output by current_time('timestamp');
650
+				$DateTime = new DbSafeDateTime(\EE_Datetime_Field::now, $this->_DateTimeZone);
651
+				$DateTime->setTimestamp($date_string);
652
+
653
+				return $DateTime;
654
+			} catch (Exception $e) {
655
+				// should be rare, but if things got fooled then let's just continue
656
+			}
657
+		}
658
+		// not a unix timestamp.  So we will use the set format on this object and set timezone to
659
+		// create the DateTime object.
660
+		$format = $this->_date_format . ' ' . $this->_time_format;
661
+		try {
662
+			$DateTime = DbSafeDateTime::createFromFormat($format, $date_string, $this->_DateTimeZone);
663
+			if (! $DateTime instanceof DbSafeDateTime) {
664
+				throw new EE_Error(
665
+					sprintf(
666
+						esc_html__('"%1$s" does not represent a valid Date Time in the format "%2$s".', 'event_espresso'),
667
+						$date_string,
668
+						$format
669
+					)
670
+				);
671
+			}
672
+		} catch (Exception $e) {
673
+			// if we made it here then likely then something went really wrong.
674
+			// Instead of throwing an exception, let's just return a DateTime object for now, in the set timezone.
675
+			$DateTime = new DbSafeDateTime(\EE_Datetime_Field::now, $this->_DateTimeZone);
676
+		}
677
+
678
+		return $DateTime;
679
+	}
680
+
681
+
682
+
683
+	/**
684
+	 * get_timezone_transitions
685
+	 *
686
+	 * @param \DateTimeZone $DateTimeZone
687
+	 * @param int           $time
688
+	 * @param bool          $first_only
689
+	 * @return mixed
690
+	 */
691
+	public function get_timezone_transitions(DateTimeZone $DateTimeZone, $time = null, $first_only = true)
692
+	{
693
+		return EEH_DTT_Helper::get_timezone_transitions($DateTimeZone, $time, $first_only);
694
+	}
695
+
696
+
697
+
698
+	/**
699
+	 * get_timezone_offset
700
+	 *
701
+	 * @param \DateTimeZone $DateTimeZone
702
+	 * @param int           $time
703
+	 * @return mixed
704
+	 * @throws \DomainException
705
+	 */
706
+	public function get_timezone_offset(DateTimeZone $DateTimeZone, $time = null)
707
+	{
708
+		return EEH_DTT_Helper::get_timezone_offset($DateTimeZone, $time);
709
+	}
710
+
711
+
712
+	/**
713
+	 * This will take an incoming timezone string and return the abbreviation for that timezone
714
+	 *
715
+	 * @param  string $timezone_string
716
+	 * @return string           abbreviation
717
+	 * @throws \EE_Error
718
+	 */
719
+	public function get_timezone_abbrev($timezone_string)
720
+	{
721
+		$timezone_string = EEH_DTT_Helper::get_valid_timezone_string($timezone_string);
722
+		$dateTime        = new DateTime(\EE_Datetime_Field::now, new DateTimeZone($timezone_string));
723
+
724
+		return $dateTime->format('T');
725
+	}
726
+
727
+	/**
728
+	 * Overrides the parent to allow for having a dynamic "now" value
729
+	 *
730
+	 * @return mixed
731
+	 */
732
+	public function get_default_value()
733
+	{
734
+		if ($this->_default_value === EE_Datetime_Field::now) {
735
+			return time();
736
+		} else {
737
+			return parent::get_default_value();
738
+		}
739
+	}
740
+
741
+	/**
742
+	 * Gets the default datetime object from the field's default time
743
+	 * @since 4.9.66.p
744
+	 * @return DbSafeDateTime|null
745
+	 * @throws InvalidArgumentException
746
+	 * @throws InvalidDataTypeException
747
+	 * @throws InvalidInterfaceException
748
+	 */
749
+	public function getDefaultDateTimeObj()
750
+	{
751
+		$default_raw = $this->get_default_value();
752
+		if ($default_raw instanceof DateTime) {
753
+			return $default_raw;
754
+		} elseif (is_null($default_raw)) {
755
+			return $default_raw;
756
+		} else {
757
+			return new DbSafeDateTime(
758
+				$this->get_default_value(),
759
+				EEH_DTT_Helper::get_valid_timezone_string($this->get_timezone())
760
+			);
761
+		}
762
+	}
763
+
764
+	public function getSchemaDescription()
765
+	{
766
+		return sprintf(
767
+			esc_html__('%s - the value for this field is in the timezone of the site.', 'event_espresso'),
768
+			$this->get_nicename()
769
+		);
770
+	}
771 771
 }
Please login to merge, or discard this patch.
core/db_models/fields/EE_Foreign_Key_Int_Field.php 1 patch
Indentation   +29 added lines, -29 removed lines patch added patch discarded remove patch
@@ -3,36 +3,36 @@
 block discarded – undo
3 3
 class EE_Foreign_Key_Int_Field extends EE_Foreign_Key_Field_Base
4 4
 {
5 5
 
6
-    /**
7
-     * @param string  $table_column  name fo column for field
8
-     * @param string  $nicename      should eb internationalized with esc_html__('blah','event_espresso')
9
-     * @param boolean $nullable
10
-     * @param mixed   $default_value if this is a integer field, it shoudl be an int. if it's a string field, it shoul
11
-     *                               dbe a string
12
-     * @param string|string[]  $model_name    eg 'Event','Answer','Term', etc. Basically its the model class's name without the
13
-     *                               "EEM_"
14
-     */
15
-    public function __construct($table_column, $nicename, $nullable, $default_value, $model_name)
16
-    {
17
-        parent::__construct($table_column, $nicename, $nullable, $default_value, $model_name);
18
-        $this->setSchemaType('integer');
19
-    }
6
+	/**
7
+	 * @param string  $table_column  name fo column for field
8
+	 * @param string  $nicename      should eb internationalized with esc_html__('blah','event_espresso')
9
+	 * @param boolean $nullable
10
+	 * @param mixed   $default_value if this is a integer field, it shoudl be an int. if it's a string field, it shoul
11
+	 *                               dbe a string
12
+	 * @param string|string[]  $model_name    eg 'Event','Answer','Term', etc. Basically its the model class's name without the
13
+	 *                               "EEM_"
14
+	 */
15
+	public function __construct($table_column, $nicename, $nullable, $default_value, $model_name)
16
+	{
17
+		parent::__construct($table_column, $nicename, $nullable, $default_value, $model_name);
18
+		$this->setSchemaType('integer');
19
+	}
20 20
 
21 21
 
22
-    /**
23
-     * @param int|EE_Base_Class $value_inputted_for_field_on_model_object
24
-     * @return int
25
-     */
26
-    public function prepare_for_set($value_inputted_for_field_on_model_object)
27
-    {
28
-        if ($this->is_model_obj_of_type_pointed_to($value_inputted_for_field_on_model_object)) {
29
-            $value_inputted_for_field_on_model_object = $value_inputted_for_field_on_model_object->ID();
30
-        }
31
-        return absint($value_inputted_for_field_on_model_object);
32
-    }
22
+	/**
23
+	 * @param int|EE_Base_Class $value_inputted_for_field_on_model_object
24
+	 * @return int
25
+	 */
26
+	public function prepare_for_set($value_inputted_for_field_on_model_object)
27
+	{
28
+		if ($this->is_model_obj_of_type_pointed_to($value_inputted_for_field_on_model_object)) {
29
+			$value_inputted_for_field_on_model_object = $value_inputted_for_field_on_model_object->ID();
30
+		}
31
+		return absint($value_inputted_for_field_on_model_object);
32
+	}
33 33
 
34
-    public function prepare_for_set_from_db($value_found_in_db_for_model_object)
35
-    {
36
-        return intval($value_found_in_db_for_model_object);
37
-    }
34
+	public function prepare_for_set_from_db($value_found_in_db_for_model_object)
35
+	{
36
+		return intval($value_found_in_db_for_model_object);
37
+	}
38 38
 }
Please login to merge, or discard this patch.
core/db_models/fields/EE_Boolean_Field.php 1 patch
Indentation   +58 added lines, -58 removed lines patch added patch discarded remove patch
@@ -2,66 +2,66 @@
 block discarded – undo
2 2
 
3 3
 class EE_Boolean_Field extends EE_Integer_Field
4 4
 {
5
-    /**
6
-     * @param string $table_column
7
-     * @param string $nicename
8
-     * @param bool   $nullable
9
-     * @param null   $default_value
10
-     */
11
-    public function __construct($table_column, $nicename, $nullable, $default_value = null)
12
-    {
13
-        parent::__construct($table_column, $nicename, $nullable, $default_value);
14
-        $this->setSchemaType('boolean');
15
-    }
5
+	/**
6
+	 * @param string $table_column
7
+	 * @param string $nicename
8
+	 * @param bool   $nullable
9
+	 * @param null   $default_value
10
+	 */
11
+	public function __construct($table_column, $nicename, $nullable, $default_value = null)
12
+	{
13
+		parent::__construct($table_column, $nicename, $nullable, $default_value);
14
+		$this->setSchemaType('boolean');
15
+	}
16 16
 
17
-    /**
18
-     * Double-checks the value being returned is an boolean.
19
-     * @since 4.9.74.p
20
-     * @param mixed $value_of_field_on_model_object
21
-     * @return boolean
22
-     */
23
-    public function prepare_for_get($value_of_field_on_model_object)
24
-    {
25
-        return (bool) parent::prepare_for_get($value_of_field_on_model_object);
26
-    }
17
+	/**
18
+	 * Double-checks the value being returned is an boolean.
19
+	 * @since 4.9.74.p
20
+	 * @param mixed $value_of_field_on_model_object
21
+	 * @return boolean
22
+	 */
23
+	public function prepare_for_get($value_of_field_on_model_object)
24
+	{
25
+		return (bool) parent::prepare_for_get($value_of_field_on_model_object);
26
+	}
27 27
 
28
-    /**
29
-     * @since 4.9.74.p
30
-     * @param $value_inputted_for_field_on_model_object
31
-     * @return boolean
32
-     */
33
-    public function prepare_for_set($value_inputted_for_field_on_model_object)
34
-    {
35
-        if ($value_inputted_for_field_on_model_object) {
36
-            return true;
37
-        } else {
38
-            return false;
39
-        }
40
-    }
28
+	/**
29
+	 * @since 4.9.74.p
30
+	 * @param $value_inputted_for_field_on_model_object
31
+	 * @return boolean
32
+	 */
33
+	public function prepare_for_set($value_inputted_for_field_on_model_object)
34
+	{
35
+		if ($value_inputted_for_field_on_model_object) {
36
+			return true;
37
+		} else {
38
+			return false;
39
+		}
40
+	}
41 41
 
42
-    /**
43
-     * Make sure we're returning booleans
44
-     *
45
-     * @param string $value_inputted_for_field_on_model_object
46
-     * @return boolean
47
-     */
48
-    public function prepare_for_set_from_db($value_inputted_for_field_on_model_object)
49
-    {
50
-        return intval($value_inputted_for_field_on_model_object) ? true : false;
51
-    }
42
+	/**
43
+	 * Make sure we're returning booleans
44
+	 *
45
+	 * @param string $value_inputted_for_field_on_model_object
46
+	 * @return boolean
47
+	 */
48
+	public function prepare_for_set_from_db($value_inputted_for_field_on_model_object)
49
+	{
50
+		return intval($value_inputted_for_field_on_model_object) ? true : false;
51
+	}
52 52
 
53
-    /**
54
-     * Gets a nice Yes/No value for this field
55
-     *
56
-     * @param boolean $value_on_field_to_be_outputted
57
-     * @return string Yes or No
58
-     */
59
-    public function prepare_for_pretty_echoing($value_on_field_to_be_outputted)
60
-    {
61
-        return apply_filters(
62
-            'FHEE__EE_Boolean_Field__prepare_for_pretty_echoing__return',
63
-            $value_on_field_to_be_outputted ? esc_html__('Yes', 'event_espresso') : esc_html__('No', 'event_espresso'),
64
-            $value_on_field_to_be_outputted
65
-        );
66
-    }
53
+	/**
54
+	 * Gets a nice Yes/No value for this field
55
+	 *
56
+	 * @param boolean $value_on_field_to_be_outputted
57
+	 * @return string Yes or No
58
+	 */
59
+	public function prepare_for_pretty_echoing($value_on_field_to_be_outputted)
60
+	{
61
+		return apply_filters(
62
+			'FHEE__EE_Boolean_Field__prepare_for_pretty_echoing__return',
63
+			$value_on_field_to_be_outputted ? esc_html__('Yes', 'event_espresso') : esc_html__('No', 'event_espresso'),
64
+			$value_on_field_to_be_outputted
65
+		);
66
+	}
67 67
 }
Please login to merge, or discard this patch.
core/db_models/fields/EE_WP_User_Field.php 1 patch
Indentation   +34 added lines, -34 removed lines patch added patch discarded remove patch
@@ -13,39 +13,39 @@
 block discarded – undo
13 13
  */
14 14
 class EE_WP_User_Field extends EE_Foreign_Key_Int_Field
15 15
 {
16
-    /**
17
-     * No need to provide a default or the model pointed to- the default is
18
-     * always get_current_user_id() and the model pointed to is always WP_User
19
-     *
20
-     * @param string  $table_column name fo column for field
21
-     * @param string  $nicename     should eb internationalized with esc_html__('blah','event_espresso')
22
-     * @param boolean $nullable
23
-     */
24
-    public function __construct($table_column, $nicename, $nullable)
25
-    {
26
-        parent::__construct($table_column, $nicename, $nullable, null, 'WP_User');
27
-    }
16
+	/**
17
+	 * No need to provide a default or the model pointed to- the default is
18
+	 * always get_current_user_id() and the model pointed to is always WP_User
19
+	 *
20
+	 * @param string  $table_column name fo column for field
21
+	 * @param string  $nicename     should eb internationalized with esc_html__('blah','event_espresso')
22
+	 * @param boolean $nullable
23
+	 */
24
+	public function __construct($table_column, $nicename, $nullable)
25
+	{
26
+		parent::__construct($table_column, $nicename, $nullable, null, 'WP_User');
27
+	}
28 28
 
29
-    /**
30
-     * Gets the default which is always the current user. This can't be set when initially
31
-     * constructing the model field because that's done before $current_user is set
32
-     *
33
-     * @return mixed
34
-     */
35
-    public function get_default_value()
36
-    {
37
-        if (did_action('init')) {
38
-            return get_current_user_id();
39
-        } else {
40
-            EE_Error::doing_it_wrong(
41
-                'EE_WP_User_Field::get_default_value',
42
-                esc_html__(
43
-                    'You cant get a default value for a wp_User_Field because the "init" action is called, because current_user global hasnt yet been setup. Consider doing your business logic on the "init" hook or later.',
44
-                    'event_espresso'
45
-                ),
46
-                '4.6.20'
47
-            );
48
-            return 1;
49
-        }
50
-    }
29
+	/**
30
+	 * Gets the default which is always the current user. This can't be set when initially
31
+	 * constructing the model field because that's done before $current_user is set
32
+	 *
33
+	 * @return mixed
34
+	 */
35
+	public function get_default_value()
36
+	{
37
+		if (did_action('init')) {
38
+			return get_current_user_id();
39
+		} else {
40
+			EE_Error::doing_it_wrong(
41
+				'EE_WP_User_Field::get_default_value',
42
+				esc_html__(
43
+					'You cant get a default value for a wp_User_Field because the "init" action is called, because current_user global hasnt yet been setup. Consider doing your business logic on the "init" hook or later.',
44
+					'event_espresso'
45
+				),
46
+				'4.6.20'
47
+			);
48
+			return 1;
49
+		}
50
+	}
51 51
 }
Please login to merge, or discard this patch.
core/db_models/EEM_Payment.model.php 2 patches
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -126,7 +126,7 @@  discard block
 block discarded – undo
126 126
     public function get_payments_for_transaction($TXN_ID = false, $status_of_payment = null)
127 127
     {
128 128
         // all payments for a TXN ordered chronologically
129
-        $query_params = array( array( 'TXN_ID' => $TXN_ID ), 'order_by' => array( 'PAY_timestamp' => 'ASC' ));
129
+        $query_params = array(array('TXN_ID' => $TXN_ID), 'order_by' => array('PAY_timestamp' => 'ASC'));
130 130
         // if provided with a status, search specifically for that status. Otherwise get them all
131 131
         if ($status_of_payment) {
132 132
             $query_params[0]['STS_ID'] = $status_of_payment;
@@ -168,7 +168,7 @@  discard block
 block discarded – undo
168 168
     {
169 169
         $timezone = empty($timezone) ? EEH_DTT_Helper::get_timezone() : $timezone;
170 170
         // if $start_date or $end date, verify $format is included.
171
-        if (( ! empty($start_date) || ! empty($end_date) ) && empty($format)) {
171
+        if (( ! empty($start_date) || ! empty($end_date)) && empty($format)) {
172 172
             throw new EE_Error(esc_html__('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', 'event_espresso'));
173 173
         }
174 174
         $now = new DateTime('now');
@@ -178,12 +178,12 @@  discard block
 block discarded – undo
178 178
         // setup start date
179 179
         $start_date = ! empty($start_date) ? date_create_from_format($format, $start_date, $passedDateTimeZone) : $now;
180 180
         EEH_DTT_Helper::setTimezone($start_date, $modelDateTimeZone);
181
-        $start_date = $start_date->format('Y-m-d') . ' 00:00:00';
181
+        $start_date = $start_date->format('Y-m-d').' 00:00:00';
182 182
         $start_date = strtotime($start_date);
183 183
         // setup end date
184 184
         $end_date = ! empty($end_date) ? date_create_from_format($format, $end_date, $passedDateTimeZone) : $now;
185 185
         EEH_DTT_Helper::setTimezone($end_date, $modelDateTimeZone);
186
-        $end_date = $end_date->format('Y-m-d') . ' 23:59:59';
186
+        $end_date = $end_date->format('Y-m-d').' 23:59:59';
187 187
         $end_date = strtotime($end_date);
188 188
 
189 189
         // make sure our start date is the lowest value and vice versa
@@ -191,10 +191,10 @@  discard block
 block discarded – undo
191 191
         $end = max($start_date, $end_date);
192 192
 
193 193
         // 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.
194
-        $start_date = $this->convert_datetime_for_query('PAY_timestamp', date('Y-m-d', $start) . ' 00:00:00', 'Y-m-d H:i:s', $this->get_timezone());
195
-        $end_date = $this->convert_datetime_for_query('PAY_timestamp', date('Y-m-d', $end) . ' 23:59:59', 'Y-m-d H:i:s', $this->get_timezone());
194
+        $start_date = $this->convert_datetime_for_query('PAY_timestamp', date('Y-m-d', $start).' 00:00:00', 'Y-m-d H:i:s', $this->get_timezone());
195
+        $end_date = $this->convert_datetime_for_query('PAY_timestamp', date('Y-m-d', $end).' 23:59:59', 'Y-m-d H:i:s', $this->get_timezone());
196 196
 
197
-        return $this->get_all(array(array('PAY_timestamp' => array('>=',$start_date),'PAY_timestamp*' => array('<=',$end_date))));
197
+        return $this->get_all(array(array('PAY_timestamp' => array('>=', $start_date), 'PAY_timestamp*' => array('<=', $end_date))));
198 198
     }
199 199
 
200 200
     /**
Please login to merge, or discard this patch.
Indentation   +224 added lines, -224 removed lines patch added patch discarded remove patch
@@ -11,232 +11,232 @@
 block discarded – undo
11 11
  */
12 12
 class EEM_Payment extends EEM_Base implements EEMI_Payment
13 13
 {
14
-    // private instance of the Payment object
15
-    protected static $_instance = null;
14
+	// private instance of the Payment object
15
+	protected static $_instance = null;
16 16
 
17 17
 
18 18
 
19 19
 /**
20
-     * Status id in esp_status table that represents an approved payment
21
-     */
22
-    const status_id_approved = 'PAP';
23
-
24
-
25
-    /**
26
-     * Status id in esp_status table that represents a pending payment
27
-     */
28
-    const status_id_pending = 'PPN';
29
-
30
-
31
-    /**
32
-     * Status id in esp_status table that represents a cancelled payment (eg, the
33
-     * user went to PayPal, but on the paypal site decided to cancel the payment)
34
-     */
35
-    const status_id_cancelled = 'PCN';
36
-
37
-
38
-
39
-    /**
40
-     * Status id in esp_status table that represents a payment that was declined by
41
-     * the gateway. (eg, the user's card had no funds, or it was a fraudulent card)
42
-     */
43
-    const status_id_declined = 'PDC';
44
-
45
-
46
-
47
-    /**
48
-     * Status id in esp_status table that represents a payment that failed for technical reasons.
49
-     * (Eg, there was some error in communicating with the payment gateway.)
50
-     */
51
-    const status_id_failed = 'PFL';
52
-
53
-    /**
54
-     *      private constructor to prevent direct creation
55
-     *      @Constructor
56
-     *      @access protected
57
-     *      @param string $timezone string representing the timezone we want to set for returned Date Time Strings (and any incoming timezone data that gets saved).  Note this just sends the timezone info to the date time model field objects.  Default is NULL (and will be assumed using the set timezone in the 'timezone_string' wp option)
58
-     *      @return EEM_Payment
59
-     */
60
-    protected function __construct($timezone)
61
-    {
62
-
63
-        $this->singular_item = esc_html__('Payment', 'event_espresso');
64
-        $this->plural_item = esc_html__('Payments', 'event_espresso');
65
-
66
-        $this->_tables = array(
67
-            'Payment' => new EE_Primary_Table('esp_payment', 'PAY_ID')
68
-        );
69
-        $this->_fields = array(
70
-            'Payment' => array(
71
-                'PAY_ID' => new EE_Primary_Key_Int_Field('PAY_ID', esc_html__('Payment ID', 'event_espresso')),
72
-                'TXN_ID' => new EE_Foreign_Key_Int_Field('TXN_ID', esc_html__('Transaction ID', 'event_espresso'), false, 0, 'Transaction'),
73
-                'STS_ID' => new EE_Foreign_Key_String_Field('STS_ID', esc_html__('Status ID', 'event_espresso'), false, EEM_Payment::status_id_failed, 'Status'),
74
-                'PAY_timestamp' => new EE_Datetime_Field('PAY_timestamp', esc_html__('Timestamp of when payment was attempted', 'event_espresso'), false, EE_Datetime_Field::now, $timezone),
75
-                'PAY_source' => new EE_All_Caps_Text_Field('PAY_source', esc_html__('User-friendly description of payment', 'event_espresso'), false, 'CART'),
76
-                'PAY_amount' => new EE_Money_Field('PAY_amount', esc_html__('Amount Payment should be for', 'event_espresso'), false, 0),
77
-                'PMD_ID' => new EE_Foreign_Key_Int_Field('PMD_ID', esc_html__("Payment Method ID", 'event_espresso'), false, null, 'Payment_Method'),
78
-                'PAY_gateway_response' => new EE_Plain_Text_Field('PAY_gateway_response', esc_html__('Response from Gateway about the payment', 'event_espresso'), false, ''),
79
-                'PAY_txn_id_chq_nmbr' => new EE_Plain_Text_Field('PAY_txn_id_chq_nmbr', esc_html__('Gateway Transaction ID or Cheque Number', 'event_espresso'), true, ''),
80
-                'PAY_po_number' => new EE_Plain_Text_Field('PAY_po_number', esc_html__('Purchase or Sales Number', 'event_espresso'), true, ''),
81
-                'PAY_extra_accntng' => new EE_Simple_HTML_Field('PAY_extra_accntng', esc_html__('Extra Account Info', 'event_espresso'), true, ''),
82
-                'PAY_details' => new EE_Serialized_Text_Field('PAY_details', esc_html__('Full Gateway response about payment', 'event_espresso'), true, ''),
83
-                'PAY_redirect_url' => new EE_Plain_Text_Field('PAY_redirect_url', esc_html__("Redirect URL", 'event_espresso'), true),
84
-                'PAY_redirect_args' => new EE_Serialized_Text_Field('PAY_redirect_args', esc_html__("Key-Value POST vars to send along with redirect", 'event_espresso'), true)
85
-            )
86
-        );
87
-        $this->_model_relations = array(
88
-            'Transaction' => new EE_Belongs_To_Relation(),
89
-            'Status' => new EE_Belongs_To_Relation(),
90
-            'Payment_Method' => new EE_Belongs_To_Relation(),
91
-            'Registration_Payment' => new EE_Has_Many_Relation(),
92
-            'Registration' => new EE_HABTM_Relation('Registration_Payment'),
93
-        );
94
-        $this->_model_chain_to_wp_user = 'Payment_Method';
95
-        $this->_caps_slug = 'transactions';
96
-        parent::__construct($timezone);
97
-    }
98
-
99
-
100
-
101
-
102
-    /**
103
-     * Gets the payment by the gateway server's unique ID. Eg, the unique ID PayPal assigned
104
-     * to the payment. This is handy for verifying an IPN hasn't already been processed.
105
-     * @param string $PAY_txn_id_chq_nmbr
106
-     * @return EE_Payment
107
-     */
108
-    public function get_payment_by_txn_id_chq_nmbr($PAY_txn_id_chq_nmbr)
109
-    {
110
-        return $this->get_one(array(array('PAY_txn_id_chq_nmbr' => $PAY_txn_id_chq_nmbr)));
111
-    }
112
-
113
-
114
-
115
-
116
-    /**
117
-    *       retrieve  all payments from db for a particular transaction, optionally with
118
-     *      a particular status
119
-    *
120
-    *       @access     public
121
-    *       @param      $TXN_ID
122
-     *      @param  string  $status_of_payment one of EEM_Payment::status_id_*, like 'PAP','PCN',etc. If none is provided, gets payments with any status
123
-    *       @return     EE_Payment[]
124
-    */
125
-    public function get_payments_for_transaction($TXN_ID = false, $status_of_payment = null)
126
-    {
127
-        // all payments for a TXN ordered chronologically
128
-        $query_params = array( array( 'TXN_ID' => $TXN_ID ), 'order_by' => array( 'PAY_timestamp' => 'ASC' ));
129
-        // if provided with a status, search specifically for that status. Otherwise get them all
130
-        if ($status_of_payment) {
131
-            $query_params[0]['STS_ID'] = $status_of_payment;
132
-        }
133
-        // retrieve payments
134
-        return $this->get_all($query_params);
135
-    }
136
-
137
-
138
-
139
-    /**
140
-     * Only gets payments which have been approved
141
-     * @param int $TXN_ID
142
-     * @return EE_Payment[]
143
-     */
144
-    public function get_approved_payments_for_transaction($TXN_ID = 0)
145
-    {
146
-        return $this->get_payments_for_transaction($TXN_ID, EEM_Payment::status_id_approved);
147
-    }
148
-
149
-
150
-
151
-
152
-
153
-    /**
154
-     * retrieve  all payments from db between two dates,
155
-     *
156
-     * @param string $start_date incoming start date. If empty the beginning of today is used.
157
-     * @param string $end_date   incoming end date. If empty the end of today is used.
158
-     * @param string $format    If you include $start_date or $end_date then you must include the format string
159
-     *                              for the format your date is in.
160
-     * @param string $timezone   If your range is in a different timezone then the current setting on this
161
-     *                                  WordPress install, then include it here.
162
-     * @throws EE_Error
163
-     *
164
-     * @return EE_Payment[]
165
-     */
166
-    public function get_payments_made_between_dates($start_date = '', $end_date = '', $format = '', $timezone = '')
167
-    {
168
-        $timezone = empty($timezone) ? EEH_DTT_Helper::get_timezone() : $timezone;
169
-        // if $start_date or $end date, verify $format is included.
170
-        if (( ! empty($start_date) || ! empty($end_date) ) && empty($format)) {
171
-            throw new EE_Error(esc_html__('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', 'event_espresso'));
172
-        }
173
-        $now = new DateTime('now');
174
-        // setup timezone objects once
175
-        $modelDateTimeZone = new DateTimeZone($this->_timezone);
176
-        $passedDateTimeZone = new DateTimeZone($timezone);
177
-        // setup start date
178
-        $start_date = ! empty($start_date) ? date_create_from_format($format, $start_date, $passedDateTimeZone) : $now;
179
-        EEH_DTT_Helper::setTimezone($start_date, $modelDateTimeZone);
180
-        $start_date = $start_date->format('Y-m-d') . ' 00:00:00';
181
-        $start_date = strtotime($start_date);
182
-        // setup end date
183
-        $end_date = ! empty($end_date) ? date_create_from_format($format, $end_date, $passedDateTimeZone) : $now;
184
-        EEH_DTT_Helper::setTimezone($end_date, $modelDateTimeZone);
185
-        $end_date = $end_date->format('Y-m-d') . ' 23:59:59';
186
-        $end_date = strtotime($end_date);
187
-
188
-        // make sure our start date is the lowest value and vice versa
189
-        $start = min($start_date, $end_date);
190
-        $end = max($start_date, $end_date);
191
-
192
-        // 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.
193
-        $start_date = $this->convert_datetime_for_query('PAY_timestamp', date('Y-m-d', $start) . ' 00:00:00', 'Y-m-d H:i:s', $this->get_timezone());
194
-        $end_date = $this->convert_datetime_for_query('PAY_timestamp', date('Y-m-d', $end) . ' 23:59:59', 'Y-m-d H:i:s', $this->get_timezone());
195
-
196
-        return $this->get_all(array(array('PAY_timestamp' => array('>=',$start_date),'PAY_timestamp*' => array('<=',$end_date))));
197
-    }
198
-
199
-    /**
200
-     * methods for EEMI_Payment
201
-     */
202
-    /**
203
-     * returns a string for the approved status
204
-     * @return  string
205
-     */
206
-    public function approved_status()
207
-    {
208
-        return self::status_id_approved;
209
-    }
210
-    /**
211
-     * returns a string for the pending status
212
-     * @return  string
213
-     */
214
-    public function pending_status()
215
-    {
216
-        return self::status_id_pending;
217
-    }
218
-    /**
219
-     * returns a string for the cancelled status
220
-     * @return  string
221
-     */
222
-    public function cancelled_status()
223
-    {
224
-        return self::status_id_cancelled;
225
-    }
226
-    /**
227
-     * returns a string for the failed status
228
-     * @return  string
229
-     */
230
-    public function failed_status()
231
-    {
232
-        return self::status_id_failed;
233
-    }
234
-    /**
235
-     * returns a string for the declined status
236
-     * @return  string
237
-     */
238
-    public function declined_status()
239
-    {
240
-        return self::status_id_declined;
241
-    }
20
+ * Status id in esp_status table that represents an approved payment
21
+ */
22
+	const status_id_approved = 'PAP';
23
+
24
+
25
+	/**
26
+	 * Status id in esp_status table that represents a pending payment
27
+	 */
28
+	const status_id_pending = 'PPN';
29
+
30
+
31
+	/**
32
+	 * Status id in esp_status table that represents a cancelled payment (eg, the
33
+	 * user went to PayPal, but on the paypal site decided to cancel the payment)
34
+	 */
35
+	const status_id_cancelled = 'PCN';
36
+
37
+
38
+
39
+	/**
40
+	 * Status id in esp_status table that represents a payment that was declined by
41
+	 * the gateway. (eg, the user's card had no funds, or it was a fraudulent card)
42
+	 */
43
+	const status_id_declined = 'PDC';
44
+
45
+
46
+
47
+	/**
48
+	 * Status id in esp_status table that represents a payment that failed for technical reasons.
49
+	 * (Eg, there was some error in communicating with the payment gateway.)
50
+	 */
51
+	const status_id_failed = 'PFL';
52
+
53
+	/**
54
+	 *      private constructor to prevent direct creation
55
+	 *      @Constructor
56
+	 *      @access protected
57
+	 *      @param string $timezone string representing the timezone we want to set for returned Date Time Strings (and any incoming timezone data that gets saved).  Note this just sends the timezone info to the date time model field objects.  Default is NULL (and will be assumed using the set timezone in the 'timezone_string' wp option)
58
+	 *      @return EEM_Payment
59
+	 */
60
+	protected function __construct($timezone)
61
+	{
62
+
63
+		$this->singular_item = esc_html__('Payment', 'event_espresso');
64
+		$this->plural_item = esc_html__('Payments', 'event_espresso');
65
+
66
+		$this->_tables = array(
67
+			'Payment' => new EE_Primary_Table('esp_payment', 'PAY_ID')
68
+		);
69
+		$this->_fields = array(
70
+			'Payment' => array(
71
+				'PAY_ID' => new EE_Primary_Key_Int_Field('PAY_ID', esc_html__('Payment ID', 'event_espresso')),
72
+				'TXN_ID' => new EE_Foreign_Key_Int_Field('TXN_ID', esc_html__('Transaction ID', 'event_espresso'), false, 0, 'Transaction'),
73
+				'STS_ID' => new EE_Foreign_Key_String_Field('STS_ID', esc_html__('Status ID', 'event_espresso'), false, EEM_Payment::status_id_failed, 'Status'),
74
+				'PAY_timestamp' => new EE_Datetime_Field('PAY_timestamp', esc_html__('Timestamp of when payment was attempted', 'event_espresso'), false, EE_Datetime_Field::now, $timezone),
75
+				'PAY_source' => new EE_All_Caps_Text_Field('PAY_source', esc_html__('User-friendly description of payment', 'event_espresso'), false, 'CART'),
76
+				'PAY_amount' => new EE_Money_Field('PAY_amount', esc_html__('Amount Payment should be for', 'event_espresso'), false, 0),
77
+				'PMD_ID' => new EE_Foreign_Key_Int_Field('PMD_ID', esc_html__("Payment Method ID", 'event_espresso'), false, null, 'Payment_Method'),
78
+				'PAY_gateway_response' => new EE_Plain_Text_Field('PAY_gateway_response', esc_html__('Response from Gateway about the payment', 'event_espresso'), false, ''),
79
+				'PAY_txn_id_chq_nmbr' => new EE_Plain_Text_Field('PAY_txn_id_chq_nmbr', esc_html__('Gateway Transaction ID or Cheque Number', 'event_espresso'), true, ''),
80
+				'PAY_po_number' => new EE_Plain_Text_Field('PAY_po_number', esc_html__('Purchase or Sales Number', 'event_espresso'), true, ''),
81
+				'PAY_extra_accntng' => new EE_Simple_HTML_Field('PAY_extra_accntng', esc_html__('Extra Account Info', 'event_espresso'), true, ''),
82
+				'PAY_details' => new EE_Serialized_Text_Field('PAY_details', esc_html__('Full Gateway response about payment', 'event_espresso'), true, ''),
83
+				'PAY_redirect_url' => new EE_Plain_Text_Field('PAY_redirect_url', esc_html__("Redirect URL", 'event_espresso'), true),
84
+				'PAY_redirect_args' => new EE_Serialized_Text_Field('PAY_redirect_args', esc_html__("Key-Value POST vars to send along with redirect", 'event_espresso'), true)
85
+			)
86
+		);
87
+		$this->_model_relations = array(
88
+			'Transaction' => new EE_Belongs_To_Relation(),
89
+			'Status' => new EE_Belongs_To_Relation(),
90
+			'Payment_Method' => new EE_Belongs_To_Relation(),
91
+			'Registration_Payment' => new EE_Has_Many_Relation(),
92
+			'Registration' => new EE_HABTM_Relation('Registration_Payment'),
93
+		);
94
+		$this->_model_chain_to_wp_user = 'Payment_Method';
95
+		$this->_caps_slug = 'transactions';
96
+		parent::__construct($timezone);
97
+	}
98
+
99
+
100
+
101
+
102
+	/**
103
+	 * Gets the payment by the gateway server's unique ID. Eg, the unique ID PayPal assigned
104
+	 * to the payment. This is handy for verifying an IPN hasn't already been processed.
105
+	 * @param string $PAY_txn_id_chq_nmbr
106
+	 * @return EE_Payment
107
+	 */
108
+	public function get_payment_by_txn_id_chq_nmbr($PAY_txn_id_chq_nmbr)
109
+	{
110
+		return $this->get_one(array(array('PAY_txn_id_chq_nmbr' => $PAY_txn_id_chq_nmbr)));
111
+	}
112
+
113
+
114
+
115
+
116
+	/**
117
+	 *       retrieve  all payments from db for a particular transaction, optionally with
118
+	 *      a particular status
119
+	 *
120
+	 *       @access     public
121
+	 *       @param      $TXN_ID
122
+	 *      @param  string  $status_of_payment one of EEM_Payment::status_id_*, like 'PAP','PCN',etc. If none is provided, gets payments with any status
123
+	 *       @return     EE_Payment[]
124
+	 */
125
+	public function get_payments_for_transaction($TXN_ID = false, $status_of_payment = null)
126
+	{
127
+		// all payments for a TXN ordered chronologically
128
+		$query_params = array( array( 'TXN_ID' => $TXN_ID ), 'order_by' => array( 'PAY_timestamp' => 'ASC' ));
129
+		// if provided with a status, search specifically for that status. Otherwise get them all
130
+		if ($status_of_payment) {
131
+			$query_params[0]['STS_ID'] = $status_of_payment;
132
+		}
133
+		// retrieve payments
134
+		return $this->get_all($query_params);
135
+	}
136
+
137
+
138
+
139
+	/**
140
+	 * Only gets payments which have been approved
141
+	 * @param int $TXN_ID
142
+	 * @return EE_Payment[]
143
+	 */
144
+	public function get_approved_payments_for_transaction($TXN_ID = 0)
145
+	{
146
+		return $this->get_payments_for_transaction($TXN_ID, EEM_Payment::status_id_approved);
147
+	}
148
+
149
+
150
+
151
+
152
+
153
+	/**
154
+	 * retrieve  all payments from db between two dates,
155
+	 *
156
+	 * @param string $start_date incoming start date. If empty the beginning of today is used.
157
+	 * @param string $end_date   incoming end date. If empty the end of today is used.
158
+	 * @param string $format    If you include $start_date or $end_date then you must include the format string
159
+	 *                              for the format your date is in.
160
+	 * @param string $timezone   If your range is in a different timezone then the current setting on this
161
+	 *                                  WordPress install, then include it here.
162
+	 * @throws EE_Error
163
+	 *
164
+	 * @return EE_Payment[]
165
+	 */
166
+	public function get_payments_made_between_dates($start_date = '', $end_date = '', $format = '', $timezone = '')
167
+	{
168
+		$timezone = empty($timezone) ? EEH_DTT_Helper::get_timezone() : $timezone;
169
+		// if $start_date or $end date, verify $format is included.
170
+		if (( ! empty($start_date) || ! empty($end_date) ) && empty($format)) {
171
+			throw new EE_Error(esc_html__('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', 'event_espresso'));
172
+		}
173
+		$now = new DateTime('now');
174
+		// setup timezone objects once
175
+		$modelDateTimeZone = new DateTimeZone($this->_timezone);
176
+		$passedDateTimeZone = new DateTimeZone($timezone);
177
+		// setup start date
178
+		$start_date = ! empty($start_date) ? date_create_from_format($format, $start_date, $passedDateTimeZone) : $now;
179
+		EEH_DTT_Helper::setTimezone($start_date, $modelDateTimeZone);
180
+		$start_date = $start_date->format('Y-m-d') . ' 00:00:00';
181
+		$start_date = strtotime($start_date);
182
+		// setup end date
183
+		$end_date = ! empty($end_date) ? date_create_from_format($format, $end_date, $passedDateTimeZone) : $now;
184
+		EEH_DTT_Helper::setTimezone($end_date, $modelDateTimeZone);
185
+		$end_date = $end_date->format('Y-m-d') . ' 23:59:59';
186
+		$end_date = strtotime($end_date);
187
+
188
+		// make sure our start date is the lowest value and vice versa
189
+		$start = min($start_date, $end_date);
190
+		$end = max($start_date, $end_date);
191
+
192
+		// 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.
193
+		$start_date = $this->convert_datetime_for_query('PAY_timestamp', date('Y-m-d', $start) . ' 00:00:00', 'Y-m-d H:i:s', $this->get_timezone());
194
+		$end_date = $this->convert_datetime_for_query('PAY_timestamp', date('Y-m-d', $end) . ' 23:59:59', 'Y-m-d H:i:s', $this->get_timezone());
195
+
196
+		return $this->get_all(array(array('PAY_timestamp' => array('>=',$start_date),'PAY_timestamp*' => array('<=',$end_date))));
197
+	}
198
+
199
+	/**
200
+	 * methods for EEMI_Payment
201
+	 */
202
+	/**
203
+	 * returns a string for the approved status
204
+	 * @return  string
205
+	 */
206
+	public function approved_status()
207
+	{
208
+		return self::status_id_approved;
209
+	}
210
+	/**
211
+	 * returns a string for the pending status
212
+	 * @return  string
213
+	 */
214
+	public function pending_status()
215
+	{
216
+		return self::status_id_pending;
217
+	}
218
+	/**
219
+	 * returns a string for the cancelled status
220
+	 * @return  string
221
+	 */
222
+	public function cancelled_status()
223
+	{
224
+		return self::status_id_cancelled;
225
+	}
226
+	/**
227
+	 * returns a string for the failed status
228
+	 * @return  string
229
+	 */
230
+	public function failed_status()
231
+	{
232
+		return self::status_id_failed;
233
+	}
234
+	/**
235
+	 * returns a string for the declined status
236
+	 * @return  string
237
+	 */
238
+	public function declined_status()
239
+	{
240
+		return self::status_id_declined;
241
+	}
242 242
 }
Please login to merge, or discard this patch.
core/business/EE_Transaction_Processor.class.php 2 patches
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -53,7 +53,7 @@  discard block
 block discarded – undo
53 53
     public static function instance($registration_query_params = array())
54 54
     {
55 55
         // check if class object is instantiated
56
-        if (! self::$_instance instanceof EE_Transaction_Processor) {
56
+        if ( ! self::$_instance instanceof EE_Transaction_Processor) {
57 57
             self::$_instance = new self($registration_query_params);
58 58
         }
59 59
         return self::$_instance;
@@ -311,7 +311,7 @@  discard block
 block discarded – undo
311 311
         // these reg statuses should not be considered in any calculations involving monies owing
312 312
         $closed_reg_statuses = ! empty($closed_reg_statuses) ? $closed_reg_statuses
313 313
             : EEM_Registration::closed_reg_statuses();
314
-        if (! in_array($registration->status_ID(), $closed_reg_statuses, true)) {
314
+        if ( ! in_array($registration->status_ID(), $closed_reg_statuses, true)) {
315 315
             return false;
316 316
         }
317 317
         try {
@@ -365,7 +365,7 @@  discard block
 block discarded – undo
365 365
     public function get_transaction_for_registration(EE_Registration $registration)
366 366
     {
367 367
         $transaction = $registration->transaction();
368
-        if (! $transaction instanceof EE_Transaction) {
368
+        if ( ! $transaction instanceof EE_Transaction) {
369 369
             throw new EE_Error(
370 370
                 sprintf(
371 371
                     esc_html__('The Transaction for Registration %1$d was not found or is invalid.', 'event_espresso'),
@@ -395,7 +395,7 @@  discard block
 block discarded – undo
395 395
             $transaction->ID(),
396 396
             $registration->ticket_ID()
397 397
         );
398
-        if (! $ticket_line_item instanceof EE_Line_Item) {
398
+        if ( ! $ticket_line_item instanceof EE_Line_Item) {
399 399
             throw new EE_Error(
400 400
                 sprintf(
401 401
                     esc_html__(
@@ -479,7 +479,7 @@  discard block
 block discarded – undo
479 479
         /** @type EE_Registration_Processor $registration_processor */
480 480
         $registration_processor = EE_Registry::instance()->load_class('Registration_Processor');
481 481
         // check that method exists
482
-        if (! method_exists($registration_processor, $method_name)) {
482
+        if ( ! method_exists($registration_processor, $method_name)) {
483 483
             throw new EE_Error(esc_html__('Method does not exist.', 'event_espresso'));
484 484
         }
485 485
         // make sure some query params are set for retrieving registrations
@@ -537,7 +537,7 @@  discard block
 block discarded – undo
537 537
                         $transaction,
538 538
                         EEM_Payment_Method::scope_cart
539 539
                     );
540
-                    if (! empty($available_payment_methods)) {
540
+                    if ( ! empty($available_payment_methods)) {
541 541
                         $PMD_ID = 0;
542 542
                         foreach ($available_payment_methods as $available_payment_method) {
543 543
                             if (
@@ -548,7 +548,7 @@  discard block
 block discarded – undo
548 548
                                 break;
549 549
                             }
550 550
                         }
551
-                        if (! $PMD_ID) {
551
+                        if ( ! $PMD_ID) {
552 552
                             $first_payment_method = reset($available_payment_methods);
553 553
                             if ($first_payment_method instanceof EE_Payment_Method) {
554 554
                                 $PMD_ID = $first_payment_method->ID();
Please login to merge, or discard this patch.
Indentation   +948 added lines, -948 removed lines patch added patch discarded remove patch
@@ -16,952 +16,952 @@
 block discarded – undo
16 16
  */
17 17
 class EE_Transaction_Processor extends EE_Processor_Base
18 18
 {
19
-    /**
20
-     * @var EE_Registration_Processor $_instance
21
-     * @access    private
22
-     */
23
-    private static $_instance;
24
-
25
-    /**
26
-     * array of query WHERE params to use when retrieving cached registrations from a transaction
27
-     *
28
-     * @var array $registration_query_params
29
-     * @access private
30
-     */
31
-    private $_registration_query_params = array();
32
-
33
-    /**
34
-     * @deprecated
35
-     * @var string
36
-     */
37
-    protected $_old_txn_status;
38
-
39
-    /**
40
-     * @deprecated
41
-     * @var string
42
-     */
43
-    protected $_new_txn_status;
44
-
45
-
46
-    /**
47
-     * @singleton method used to instantiate class object
48
-     * @access    public
49
-     * @param array $registration_query_params
50
-     * @return EE_Transaction_Processor instance
51
-     */
52
-    public static function instance($registration_query_params = array())
53
-    {
54
-        // check if class object is instantiated
55
-        if (! self::$_instance instanceof EE_Transaction_Processor) {
56
-            self::$_instance = new self($registration_query_params);
57
-        }
58
-        return self::$_instance;
59
-    }
60
-
61
-
62
-    /**
63
-     * @param array $registration_query_params
64
-     */
65
-    private function __construct($registration_query_params = array())
66
-    {
67
-        // make sure some query params are set for retrieving registrations
68
-        $this->_set_registration_query_params($registration_query_params);
69
-    }
70
-
71
-
72
-    /**
73
-     * @access private
74
-     * @param array $registration_query_params
75
-     */
76
-    private function _set_registration_query_params($registration_query_params)
77
-    {
78
-        $this->_registration_query_params = ! empty($registration_query_params) ? $registration_query_params
79
-            : array('order_by' => array('REG_count' => 'ASC'));
80
-    }
81
-
82
-
83
-    /**
84
-     * manually_update_registration_statuses
85
-     *
86
-     * @access public
87
-     * @param EE_Transaction $transaction
88
-     * @param string         $new_reg_status
89
-     * @param array          $registration_query_params array of query WHERE params to use
90
-     *                                                  when retrieving cached registrations from a transaction
91
-     * @return    boolean
92
-     * @throws \EE_Error
93
-     */
94
-    public function manually_update_registration_statuses(
95
-        EE_Transaction $transaction,
96
-        $new_reg_status = '',
97
-        $registration_query_params = array()
98
-    ) {
99
-        $status_updates = $this->_call_method_on_registrations_via_Registration_Processor(
100
-            'manually_update_registration_status',
101
-            $transaction,
102
-            $registration_query_params,
103
-            $new_reg_status
104
-        );
105
-        // send messages
106
-        /** @type EE_Registration_Processor $registration_processor */
107
-        $registration_processor = EE_Registry::instance()->load_class('Registration_Processor');
108
-        $registration_processor->trigger_registration_update_notifications(
109
-            $transaction->primary_registration(),
110
-            array('manually_updated' => true)
111
-        );
112
-        do_action(
113
-            'AHEE__EE_Transaction_Processor__manually_update_registration_statuses',
114
-            $transaction,
115
-            $status_updates
116
-        );
117
-        return $status_updates;
118
-    }
119
-
120
-
121
-    /**
122
-     * toggle_registration_statuses_for_default_approved_events
123
-     *
124
-     * @access public
125
-     * @param EE_Transaction $transaction
126
-     * @param array          $registration_query_params array of query WHERE params to use
127
-     *                                                  when retrieving cached registrations from a transaction
128
-     * @return    boolean
129
-     * @throws \EE_Error
130
-     */
131
-    public function toggle_registration_statuses_for_default_approved_events(
132
-        EE_Transaction $transaction,
133
-        $registration_query_params = array()
134
-    ) {
135
-        $status_updates = $this->_call_method_on_registrations_via_Registration_Processor(
136
-            'toggle_registration_status_for_default_approved_events',
137
-            $transaction,
138
-            $registration_query_params
139
-        );
140
-        do_action(
141
-            'AHEE__EE_Transaction_Processor__toggle_registration_statuses_for_default_approved_events',
142
-            $transaction,
143
-            $status_updates
144
-        );
145
-        return $status_updates;
146
-    }
147
-
148
-
149
-    /**
150
-     * toggle_registration_statuses_if_no_monies_owing
151
-     *
152
-     * @access public
153
-     * @param EE_Transaction $transaction
154
-     * @param array          $registration_query_params array of query WHERE params to use
155
-     *                                                  when retrieving cached registrations from a transaction
156
-     * @return    boolean
157
-     * @throws \EE_Error
158
-     */
159
-    public function toggle_registration_statuses_if_no_monies_owing(
160
-        EE_Transaction $transaction,
161
-        $registration_query_params = array()
162
-    ) {
163
-        $status_updates = $this->_call_method_on_registrations_via_Registration_Processor(
164
-            'toggle_registration_status_if_no_monies_owing',
165
-            $transaction,
166
-            $registration_query_params
167
-        );
168
-        do_action(
169
-            'AHEE__EE_Transaction_Processor__toggle_registration_statuses_if_no_monies_owing',
170
-            $transaction,
171
-            $status_updates
172
-        );
173
-        return $status_updates;
174
-    }
175
-
176
-
177
-    /**
178
-     * update_transaction_and_registrations_after_checkout_or_payment
179
-     * cycles thru related registrations and calls update_registration_after_checkout_or_payment() on each
180
-     *
181
-     * @param EE_Transaction     $transaction
182
-     * @param \EE_Payment | NULL $payment
183
-     * @param array              $registration_query_params    array of query WHERE params to use
184
-     *                                                         when retrieving cached registrations from a transaction
185
-     * @param bool               $trigger_notifications        whether or not to call
186
-     *                                                         \EE_Registration_Processor::trigger_registration_update_notifications()
187
-     * @return array
188
-     * @throws \EE_Error
189
-     */
190
-    public function update_transaction_and_registrations_after_checkout_or_payment(
191
-        EE_Transaction $transaction,
192
-        $payment = null,
193
-        $registration_query_params = array(),
194
-        $trigger_notifications = true
195
-    ) {
196
-        // make sure some query params are set for retrieving registrations
197
-        $this->_set_registration_query_params($registration_query_params);
198
-        // get final reg step status
199
-        $finalized = $transaction->final_reg_step_completed();
200
-        // if the 'finalize_registration' step has been initiated (has a timestamp)
201
-        // but has not yet been fully completed (TRUE)
202
-        if (is_int($finalized) && $finalized !== false && $finalized !== true) {
203
-            $transaction->set_reg_step_completed('finalize_registration');
204
-            $finalized = true;
205
-        }
206
-        $transaction->save();
207
-        // array of details to aid in decision making by systems
208
-        $update_params = array(
209
-            'old_txn_status'  => $transaction->old_txn_status(),
210
-            'new_txn_status'  => $transaction->status_ID(),
211
-            'finalized'       => $finalized,
212
-            'revisit'         => $this->_revisit,
213
-            'payment_updates' => $payment instanceof EE_Payment ? true : false,
214
-            'last_payment'    => $payment,
215
-        );
216
-        // now update the registrations and add the results to our $update_params
217
-        $update_params['status_updates'] = $this->_call_method_on_registrations_via_Registration_Processor(
218
-            'update_registration_after_checkout_or_payment',
219
-            $transaction,
220
-            $this->_registration_query_params,
221
-            $update_params
222
-        );
223
-        if ($trigger_notifications) {
224
-            // send messages
225
-            /** @type EE_Registration_Processor $registration_processor */
226
-            $registration_processor = EE_Registry::instance()->load_class('Registration_Processor');
227
-            $registration_processor->trigger_registration_update_notifications(
228
-                $transaction->primary_registration(),
229
-                $update_params
230
-            );
231
-        }
232
-        do_action(
233
-            'AHEE__EE_Transaction_Processor__update_transaction_and_registrations_after_checkout_or_payment',
234
-            $transaction,
235
-            $update_params
236
-        );
237
-        return $update_params;
238
-    }
239
-
240
-
241
-    /**
242
-     * update_transaction_after_registration_reopened
243
-     * readjusts TXN and Line Item totals after a registration is changed from
244
-     * cancelled or declined to another reg status such as pending payment or approved
245
-     *
246
-     * @param \EE_Registration $registration
247
-     * @param array            $closed_reg_statuses
248
-     * @param bool             $update_txn
249
-     * @return bool
250
-     * @throws \EE_Error
251
-     */
252
-    public function update_transaction_after_reinstating_canceled_registration(
253
-        EE_Registration $registration,
254
-        $closed_reg_statuses = array(),
255
-        $update_txn = true
256
-    ) {
257
-        // these reg statuses should not be considered in any calculations involving monies owing
258
-        $closed_reg_statuses = ! empty($closed_reg_statuses) ? $closed_reg_statuses
259
-            : EEM_Registration::closed_reg_statuses();
260
-        if (in_array($registration->status_ID(), $closed_reg_statuses, true)) {
261
-            return false;
262
-        }
263
-        try {
264
-            $transaction = $this->get_transaction_for_registration($registration);
265
-            $ticket_line_item = $this->get_ticket_line_item_for_transaction_registration(
266
-                $transaction,
267
-                $registration
268
-            );
269
-            // un-cancel the ticket
270
-            $success = EEH_Line_Item::reinstate_canceled_ticket_line_item($ticket_line_item);
271
-        } catch (EE_Error $e) {
272
-            EE_Error::add_error(
273
-                sprintf(
274
-                    esc_html__(
275
-                        'The Ticket Line Item for Registration %1$d could not be reinstated because :%2$s%3$s',
276
-                        'event_espresso'
277
-                    ),
278
-                    $registration->ID(),
279
-                    '<br />',
280
-                    $e->getMessage()
281
-                ),
282
-                __FILE__,
283
-                __FUNCTION__,
284
-                __LINE__
285
-            );
286
-            return false;
287
-        }
288
-        if ($update_txn) {
289
-            return $transaction->save() ? $success : false;
290
-        }
291
-        return $success;
292
-    }
293
-
294
-
295
-    /**
296
-     * update_transaction_after_canceled_or_declined_registration
297
-     * readjusts TXN and Line Item totals after a registration is cancelled or declined
298
-     *
299
-     * @param \EE_Registration $registration
300
-     * @param array            $closed_reg_statuses
301
-     * @param bool             $update_txn
302
-     * @return bool
303
-     * @throws \EE_Error
304
-     */
305
-    public function update_transaction_after_canceled_or_declined_registration(
306
-        EE_Registration $registration,
307
-        $closed_reg_statuses = array(),
308
-        $update_txn = true
309
-    ) {
310
-        // these reg statuses should not be considered in any calculations involving monies owing
311
-        $closed_reg_statuses = ! empty($closed_reg_statuses) ? $closed_reg_statuses
312
-            : EEM_Registration::closed_reg_statuses();
313
-        if (! in_array($registration->status_ID(), $closed_reg_statuses, true)) {
314
-            return false;
315
-        }
316
-        try {
317
-            $transaction = $this->get_transaction_for_registration($registration);
318
-            if (
319
-                apply_filters(
320
-                    'FHEE__EE_Transaction_Processor__update_transaction_after_canceled_or_declined_registration__cancel_ticket_line_item',
321
-                    true,
322
-                    $registration,
323
-                    $transaction
324
-                )
325
-            ) {
326
-                $ticket_line_item = $this->get_ticket_line_item_for_transaction_registration(
327
-                    $transaction,
328
-                    $registration
329
-                );
330
-                EEH_Line_Item::cancel_ticket_line_item($ticket_line_item);
331
-            }
332
-        } catch (EE_Error $e) {
333
-            EE_Error::add_error(
334
-                sprintf(
335
-                    esc_html__(
336
-                        'The Ticket Line Item for Registration %1$d could not be cancelled because :%2$s%3$s',
337
-                        'event_espresso'
338
-                    ),
339
-                    $registration->ID(),
340
-                    '<br />',
341
-                    $e->getMessage()
342
-                ),
343
-                __FILE__,
344
-                __FUNCTION__,
345
-                __LINE__
346
-            );
347
-            return false;
348
-        }
349
-        if ($update_txn) {
350
-            return $transaction->save() ? true : false;
351
-        }
352
-        return true;
353
-    }
354
-
355
-
356
-    /**
357
-     * get_transaction_for_registration
358
-     *
359
-     * @access    public
360
-     * @param    EE_Registration $registration
361
-     * @return    EE_Transaction
362
-     * @throws    EE_Error
363
-     */
364
-    public function get_transaction_for_registration(EE_Registration $registration)
365
-    {
366
-        $transaction = $registration->transaction();
367
-        if (! $transaction instanceof EE_Transaction) {
368
-            throw new EE_Error(
369
-                sprintf(
370
-                    esc_html__('The Transaction for Registration %1$d was not found or is invalid.', 'event_espresso'),
371
-                    $registration->ID()
372
-                )
373
-            );
374
-        }
375
-        return $transaction;
376
-    }
377
-
378
-
379
-    /**
380
-     * get_ticket_line_item_for_transaction_registration
381
-     *
382
-     * @access    public
383
-     * @param    EE_Transaction  $transaction
384
-     * @param    EE_Registration $registration
385
-     * @return    EE_Line_Item
386
-     * @throws    EE_Error
387
-     */
388
-    public function get_ticket_line_item_for_transaction_registration(
389
-        EE_Transaction $transaction,
390
-        EE_Registration $registration
391
-    ) {
392
-        EE_Registry::instance()->load_helper('Line_Item');
393
-        $ticket_line_item = EEM_Line_Item::instance()->get_ticket_line_item_for_transaction(
394
-            $transaction->ID(),
395
-            $registration->ticket_ID()
396
-        );
397
-        if (! $ticket_line_item instanceof EE_Line_Item) {
398
-            throw new EE_Error(
399
-                sprintf(
400
-                    esc_html__(
401
-                        'The Line Item for Transaction %1$d and Ticket %2$d was not found or is invalid.',
402
-                        'event_espresso'
403
-                    ),
404
-                    $transaction->ID(),
405
-                    $registration->ticket_ID()
406
-                )
407
-            );
408
-        }
409
-        return $ticket_line_item;
410
-    }
411
-
412
-
413
-    /**
414
-     * cancel_transaction_if_all_registrations_canceled
415
-     * cycles thru related registrations and checks their statuses
416
-     * if ALL registrations are Cancelled or Declined, then this sets the TXN status to
417
-     *
418
-     * @access    public
419
-     * @param    EE_Transaction $transaction
420
-     * @param    string         $new_TXN_status
421
-     * @param    array          $registration_query_params - array of query WHERE params to use when
422
-     *                                                     retrieving cached registrations from a transaction
423
-     * @param    array          $closed_reg_statuses
424
-     * @param    bool           $update_txn
425
-     * @return    bool            true if TXN status was updated, false if not
426
-     */
427
-    public function toggle_transaction_status_if_all_registrations_canceled_or_declined(
428
-        EE_Transaction $transaction,
429
-        $new_TXN_status = '',
430
-        $registration_query_params = array(),
431
-        $closed_reg_statuses = array(),
432
-        $update_txn = true
433
-    ) {
434
-        // make sure some query params are set for retrieving registrations
435
-        $this->_set_registration_query_params($registration_query_params);
436
-        // these reg statuses should not be considered in any calculations involving monies owing
437
-        $closed_reg_statuses = ! empty($closed_reg_statuses) ? $closed_reg_statuses
438
-            : EEM_Registration::closed_reg_statuses();
439
-        // loop through cached registrations
440
-        foreach ($transaction->registrations($this->_registration_query_params) as $registration) {
441
-            if (
442
-                $registration instanceof EE_Registration
443
-                && ! in_array($registration->status_ID(), $closed_reg_statuses)
444
-            ) {
445
-                return false;
446
-            }
447
-        }
448
-        if (in_array($new_TXN_status, EEM_Transaction::txn_status_array())) {
449
-            $transaction->set_status($new_TXN_status);
450
-        }
451
-        if ($update_txn) {
452
-            return $transaction->save() ? true : false;
453
-        }
454
-        return true;
455
-    }
456
-
457
-
458
-    /**
459
-     * _call_method_on_registrations_via_Registration_Processor
460
-     * cycles thru related registrations and calls the requested method on each
461
-     *
462
-     * @access private
463
-     * @param string         $method_name
464
-     * @param EE_Transaction $transaction
465
-     * @param array          $registration_query_params array of query WHERE params to use
466
-     *                                                  when retrieving cached registrations from a transaction
467
-     * @param string         $additional_param
468
-     * @throws \EE_Error
469
-     * @return boolean
470
-     */
471
-    private function _call_method_on_registrations_via_Registration_Processor(
472
-        $method_name,
473
-        EE_Transaction $transaction,
474
-        $registration_query_params = array(),
475
-        $additional_param = null
476
-    ) {
477
-        $response = false;
478
-        /** @type EE_Registration_Processor $registration_processor */
479
-        $registration_processor = EE_Registry::instance()->load_class('Registration_Processor');
480
-        // check that method exists
481
-        if (! method_exists($registration_processor, $method_name)) {
482
-            throw new EE_Error(esc_html__('Method does not exist.', 'event_espresso'));
483
-        }
484
-        // make sure some query params are set for retrieving registrations
485
-        $this->_set_registration_query_params($registration_query_params);
486
-        // loop through cached registrations
487
-        foreach ($transaction->registrations($this->_registration_query_params) as $registration) {
488
-            if ($registration instanceof EE_Registration) {
489
-                if ($additional_param) {
490
-                    $response = $registration_processor->{$method_name}($registration, $additional_param)
491
-                        ? true
492
-                        : $response;
493
-                } else {
494
-                    $response = $registration_processor->{$method_name}($registration)
495
-                        ? true
496
-                        : $response;
497
-                }
498
-            }
499
-        }
500
-        return $response;
501
-    }
502
-
503
-
504
-    /**
505
-     * set_transaction_payment_method_based_on_registration_statuses
506
-     * sets or unsets the PMD_ID field on the TXN based on the related REG statuses
507
-     * basically if ALL Registrations are "Not Approved", then the EE_Transaction.PMD_ID is set to null,
508
-     * but if any Registration has a different status, then EE_Transaction.PMD_ID is set to either:
509
-     *        the first "default" Payment Method
510
-     *        the first active Payment Method
511
-     *    whichever is found first.
512
-     *
513
-     * @param  EE_Registration $edited_registration
514
-     * @return void
515
-     * @throws \EE_Error
516
-     */
517
-    public function set_transaction_payment_method_based_on_registration_statuses(
518
-        EE_Registration $edited_registration
519
-    ) {
520
-        if ($edited_registration instanceof EE_Registration) {
521
-            $transaction = $edited_registration->transaction();
522
-            if ($transaction instanceof EE_Transaction) {
523
-                $all_not_approved = true;
524
-                foreach ($transaction->registrations() as $registration) {
525
-                    if ($registration instanceof EE_Registration) {
526
-                        // if any REG != "Not Approved" then toggle to false
527
-                        $all_not_approved = $registration->is_not_approved() ? $all_not_approved : false;
528
-                    }
529
-                }
530
-                // if ALL Registrations are "Not Approved"
531
-                if ($all_not_approved) {
532
-                    $transaction->set_payment_method_ID(null);
533
-                    $transaction->save();
534
-                } else {
535
-                    $available_payment_methods = EEM_Payment_Method::instance()->get_all_for_transaction(
536
-                        $transaction,
537
-                        EEM_Payment_Method::scope_cart
538
-                    );
539
-                    if (! empty($available_payment_methods)) {
540
-                        $PMD_ID = 0;
541
-                        foreach ($available_payment_methods as $available_payment_method) {
542
-                            if (
543
-                                $available_payment_method instanceof EE_Payment_Method
544
-                                && $available_payment_method->open_by_default()
545
-                            ) {
546
-                                $PMD_ID = $available_payment_method->ID();
547
-                                break;
548
-                            }
549
-                        }
550
-                        if (! $PMD_ID) {
551
-                            $first_payment_method = reset($available_payment_methods);
552
-                            if ($first_payment_method instanceof EE_Payment_Method) {
553
-                                $PMD_ID = $first_payment_method->ID();
554
-                            } else {
555
-                                EE_Error::add_error(
556
-                                    esc_html__(
557
-                                        'A valid Payment Method could not be determined. Please ensure that at least one Payment Method is activated.',
558
-                                        'event_espresso'
559
-                                    ),
560
-                                    __FILE__,
561
-                                    __LINE__,
562
-                                    __FUNCTION__
563
-                                );
564
-                            }
565
-                        }
566
-                        $transaction->set_payment_method_ID($PMD_ID);
567
-                        $transaction->save();
568
-                    } else {
569
-                        EE_Error::add_error(
570
-                            esc_html__(
571
-                                'Please activate at least one Payment Method in order for things to operate correctly.',
572
-                                'event_espresso'
573
-                            ),
574
-                            __FILE__,
575
-                            __LINE__,
576
-                            __FUNCTION__
577
-                        );
578
-                    }
579
-                }
580
-            }
581
-        }
582
-    }
583
-
584
-
585
-
586
-    /********************************** DEPRECATED METHODS **********************************/
587
-
588
-
589
-    /**
590
-     * @deprecated 4.9.12
591
-     * @return string
592
-     */
593
-    public function old_txn_status()
594
-    {
595
-        EE_Error::doing_it_wrong(
596
-            __METHOD__,
597
-            esc_html__(
598
-                'This logic has been moved into \EE_Transaction::old_txn_status(), please use that method instead.',
599
-                'event_espresso'
600
-            ),
601
-            '4.9.12'
602
-        );
603
-        return $this->_old_txn_status;
604
-    }
605
-
606
-
607
-    /**
608
-     * @deprecated 4.9.12
609
-     * @param string $old_txn_status
610
-     */
611
-    public function set_old_txn_status($old_txn_status)
612
-    {
613
-        EE_Error::doing_it_wrong(
614
-            __METHOD__,
615
-            esc_html__(
616
-                'This logic has been moved into \EE_Transaction::set_old_txn_status(), please use that method instead.',
617
-                'event_espresso'
618
-            ),
619
-            '4.9.12'
620
-        );
621
-        // only set the first time
622
-        if ($this->_old_txn_status === null) {
623
-            $this->_old_txn_status = $old_txn_status;
624
-        }
625
-    }
626
-
627
-
628
-    /**
629
-     * @deprecated 4.9.12
630
-     * @return string
631
-     */
632
-    public function new_txn_status()
633
-    {
634
-        EE_Error::doing_it_wrong(
635
-            __METHOD__,
636
-            esc_html__(
637
-                'This logic has been removed. Please just use \EE_Transaction::status_ID() instead.',
638
-                'event_espresso'
639
-            ),
640
-            '4.9.12'
641
-        );
642
-        return $this->_new_txn_status;
643
-    }
644
-
645
-
646
-    /**
647
-     * @deprecated 4.9.12
648
-     * @param string $new_txn_status
649
-     */
650
-    public function set_new_txn_status($new_txn_status)
651
-    {
652
-        EE_Error::doing_it_wrong(
653
-            __METHOD__,
654
-            esc_html__(
655
-                'This logic has been removed. Please just use \EE_Transaction::set_status() instead.',
656
-                'event_espresso'
657
-            ),
658
-            '4.9.12'
659
-        );
660
-        $this->_new_txn_status = $new_txn_status;
661
-    }
662
-
663
-
664
-    /**
665
-     * reg_status_updated
666
-     *
667
-     * @deprecated 4.9.12
668
-     * @return bool
669
-     */
670
-    public function txn_status_updated()
671
-    {
672
-        EE_Error::doing_it_wrong(
673
-            __METHOD__,
674
-            esc_html__(
675
-                'This logic has been moved into \EE_Transaction::txn_status_updated(), please use that method instead.',
676
-                'event_espresso'
677
-            ),
678
-            '4.9.12'
679
-        );
680
-        return $this->_new_txn_status !== $this->_old_txn_status && $this->_old_txn_status !== null ? true : false;
681
-    }
682
-
683
-
684
-    /**
685
-     * all_reg_steps_completed
686
-     * returns:
687
-     *    true if ALL reg steps have been marked as completed
688
-     *        or false if any step is not completed
689
-     *
690
-     * @deprecated 4.9.12
691
-     * @param EE_Transaction $transaction
692
-     * @return boolean
693
-     */
694
-    public function all_reg_steps_completed(EE_Transaction $transaction)
695
-    {
696
-        EE_Error::doing_it_wrong(
697
-            __METHOD__,
698
-            esc_html__(
699
-                'This logic has been moved into \EE_Transaction::all_reg_steps_completed(), please use that method instead.',
700
-                'event_espresso'
701
-            ),
702
-            '4.9.12',
703
-            '5.0.0'
704
-        );
705
-        return $transaction->all_reg_steps_completed();
706
-    }
707
-
708
-
709
-    /**
710
-     * all_reg_steps_completed_except
711
-     * returns:
712
-     *        true if ALL reg steps, except a particular step that you wish to skip over, have been marked as completed
713
-     *        or false if any other step is not completed
714
-     *        or false if ALL steps are completed including the exception you are testing !!!
715
-     *
716
-     * @deprecated 4.9.12
717
-     * @param EE_Transaction $transaction
718
-     * @param string         $exception
719
-     * @return boolean
720
-     */
721
-    public function all_reg_steps_completed_except(EE_Transaction $transaction, $exception = '')
722
-    {
723
-        EE_Error::doing_it_wrong(
724
-            __METHOD__,
725
-            esc_html__(
726
-                'This logic has been moved into \EE_Transaction::all_reg_steps_completed_except(), please use that method instead.',
727
-                'event_espresso'
728
-            ),
729
-            '4.9.12',
730
-            '5.0.0'
731
-        );
732
-        return $transaction->all_reg_steps_completed_except($exception);
733
-    }
734
-
735
-
736
-    /**
737
-     * all_reg_steps_completed_except
738
-     * returns:
739
-     *        true if ALL reg steps, except the final step, have been marked as completed
740
-     *        or false if any step is not completed
741
-     *    or false if ALL steps are completed including the final step !!!
742
-     *
743
-     * @deprecated 4.9.12
744
-     * @param EE_Transaction $transaction
745
-     * @return boolean
746
-     */
747
-    public function all_reg_steps_completed_except_final_step(EE_Transaction $transaction)
748
-    {
749
-        EE_Error::doing_it_wrong(
750
-            __METHOD__,
751
-            esc_html__(
752
-                'This logic has been moved into \EE_Transaction::all_reg_steps_completed_except_final_step(), please use that method instead.',
753
-                'event_espresso'
754
-            ),
755
-            '4.9.12',
756
-            '5.0.0'
757
-        );
758
-        return $transaction->all_reg_steps_completed_except_final_step();
759
-    }
760
-
761
-
762
-    /**
763
-     * reg_step_completed
764
-     * returns:
765
-     *    true if a specific reg step has been marked as completed
766
-     *    a Unix timestamp if it has been initialized but not yet completed,
767
-     *    or false if it has not yet been initialized
768
-     *
769
-     * @deprecated 4.9.12
770
-     * @param EE_Transaction $transaction
771
-     * @param string         $reg_step_slug
772
-     * @return boolean | int
773
-     */
774
-    public function reg_step_completed(EE_Transaction $transaction, $reg_step_slug)
775
-    {
776
-        EE_Error::doing_it_wrong(
777
-            __METHOD__,
778
-            esc_html__(
779
-                'This logic has been moved into \EE_Transaction::reg_step_completed(), please use that method instead.',
780
-                'event_espresso'
781
-            ),
782
-            '4.9.12',
783
-            '5.0.0'
784
-        );
785
-        return $transaction->reg_step_completed($reg_step_slug);
786
-    }
787
-
788
-
789
-    /**
790
-     * completed_final_reg_step
791
-     * returns:
792
-     *    true if the finalize_registration reg step has been marked as completed
793
-     *    a Unix timestamp if it has been initialized but not yet completed,
794
-     *    or false if it has not yet been initialized
795
-     *
796
-     * @deprecated 4.9.12
797
-     * @param EE_Transaction $transaction
798
-     * @return boolean | int
799
-     */
800
-    public function final_reg_step_completed(EE_Transaction $transaction)
801
-    {
802
-        EE_Error::doing_it_wrong(
803
-            __METHOD__,
804
-            esc_html__(
805
-                'This logic has been moved into \EE_Transaction::final_reg_step_completed(), please use that method instead.',
806
-                'event_espresso'
807
-            ),
808
-            '4.9.12',
809
-            '5.0.0'
810
-        );
811
-        return $transaction->final_reg_step_completed();
812
-    }
813
-
814
-
815
-    /**
816
-     * set_reg_step_initiated
817
-     * given a valid TXN_reg_step, this sets it's value to a unix timestamp
818
-     *
819
-     * @deprecated 4.9.12
820
-     * @access     public
821
-     * @param \EE_Transaction $transaction
822
-     * @param string          $reg_step_slug
823
-     * @return boolean
824
-     * @throws \EE_Error
825
-     */
826
-    public function set_reg_step_initiated(EE_Transaction $transaction, $reg_step_slug)
827
-    {
828
-        EE_Error::doing_it_wrong(
829
-            __METHOD__,
830
-            esc_html__(
831
-                'This logic has been moved into \EE_Transaction::set_reg_step_initiated(), please use that method instead.',
832
-                'event_espresso'
833
-            ),
834
-            '4.9.12',
835
-            '5.0.0'
836
-        );
837
-        return $transaction->set_reg_step_initiated($reg_step_slug);
838
-    }
839
-
840
-
841
-    /**
842
-     * set_reg_step_completed
843
-     * given a valid TXN_reg_step, this sets the step as completed
844
-     *
845
-     * @deprecated 4.9.12
846
-     * @access     public
847
-     * @param \EE_Transaction $transaction
848
-     * @param string          $reg_step_slug
849
-     * @return boolean
850
-     * @throws \EE_Error
851
-     */
852
-    public function set_reg_step_completed(EE_Transaction $transaction, $reg_step_slug)
853
-    {
854
-        EE_Error::doing_it_wrong(
855
-            __METHOD__,
856
-            esc_html__(
857
-                'This logic has been moved into \EE_Transaction::set_reg_step_completed(), please use that method instead.',
858
-                'event_espresso'
859
-            ),
860
-            '4.9.12',
861
-            '5.0.0'
862
-        );
863
-        return $transaction->set_reg_step_completed($reg_step_slug);
864
-    }
865
-
866
-
867
-    /**
868
-     * set_reg_step_completed
869
-     * given a valid TXN_reg_step slug, this sets the step as NOT completed
870
-     *
871
-     * @deprecated 4.9.12
872
-     * @access     public
873
-     * @param \EE_Transaction $transaction
874
-     * @param string          $reg_step_slug
875
-     * @return boolean
876
-     * @throws \EE_Error
877
-     */
878
-    public function set_reg_step_not_completed(EE_Transaction $transaction, $reg_step_slug)
879
-    {
880
-        EE_Error::doing_it_wrong(
881
-            __METHOD__,
882
-            esc_html__(
883
-                'This logic has been moved into \EE_Transaction::set_reg_step_not_completed(), please use that method instead.',
884
-                'event_espresso'
885
-            ),
886
-            '4.9.12',
887
-            '5.0.0'
888
-        );
889
-        return $transaction->set_reg_step_not_completed($reg_step_slug);
890
-    }
891
-
892
-
893
-    /**
894
-     * remove_reg_step
895
-     * given a valid TXN_reg_step slug, this will remove (unset)
896
-     * the reg step from the TXN reg step array
897
-     *
898
-     * @deprecated 4.9.12
899
-     * @access     public
900
-     * @param \EE_Transaction $transaction
901
-     * @param string          $reg_step_slug
902
-     * @return void
903
-     */
904
-    public function remove_reg_step(EE_Transaction $transaction, $reg_step_slug)
905
-    {
906
-        EE_Error::doing_it_wrong(
907
-            __METHOD__,
908
-            esc_html__(
909
-                'This logic has been moved into \EE_Transaction::remove_reg_step(), please use that method instead.',
910
-                'event_espresso'
911
-            ),
912
-            '4.9.12',
913
-            '5.0.0'
914
-        );
915
-        $transaction->remove_reg_step($reg_step_slug);
916
-    }
917
-
918
-
919
-    /**
920
-     *    toggle_failed_transaction_status
921
-     * upgrades a TXNs status from failed to abandoned,
922
-     * meaning that contact information has been captured for at least one registrant
923
-     *
924
-     * @deprecated 4.9.12
925
-     * @access     public
926
-     * @param EE_Transaction $transaction
927
-     * @return    boolean
928
-     * @throws \EE_Error
929
-     */
930
-    public function toggle_failed_transaction_status(EE_Transaction $transaction)
931
-    {
932
-        EE_Error::doing_it_wrong(
933
-            __METHOD__,
934
-            esc_html__(
935
-                'This logic has been moved into \EE_Transaction::toggle_failed_transaction_status(), please use that method instead.',
936
-                'event_espresso'
937
-            ),
938
-            '4.9.12',
939
-            '5.0.0'
940
-        );
941
-        return $transaction->toggle_failed_transaction_status();
942
-    }
943
-
944
-
945
-    /**
946
-     * toggle_abandoned_transaction_status
947
-     * upgrades a TXNs status from failed or abandoned to incomplete
948
-     *
949
-     * @deprecated 4.9.12
950
-     * @access     public
951
-     * @param  EE_Transaction $transaction
952
-     * @return boolean
953
-     */
954
-    public function toggle_abandoned_transaction_status(EE_Transaction $transaction)
955
-    {
956
-        EE_Error::doing_it_wrong(
957
-            __METHOD__,
958
-            esc_html__(
959
-                'This logic has been moved into \EE_Transaction::toggle_abandoned_transaction_status(), please use that method instead.',
960
-                'event_espresso'
961
-            ),
962
-            '4.9.12',
963
-            '5.0.0'
964
-        );
965
-        return $transaction->toggle_abandoned_transaction_status();
966
-    }
19
+	/**
20
+	 * @var EE_Registration_Processor $_instance
21
+	 * @access    private
22
+	 */
23
+	private static $_instance;
24
+
25
+	/**
26
+	 * array of query WHERE params to use when retrieving cached registrations from a transaction
27
+	 *
28
+	 * @var array $registration_query_params
29
+	 * @access private
30
+	 */
31
+	private $_registration_query_params = array();
32
+
33
+	/**
34
+	 * @deprecated
35
+	 * @var string
36
+	 */
37
+	protected $_old_txn_status;
38
+
39
+	/**
40
+	 * @deprecated
41
+	 * @var string
42
+	 */
43
+	protected $_new_txn_status;
44
+
45
+
46
+	/**
47
+	 * @singleton method used to instantiate class object
48
+	 * @access    public
49
+	 * @param array $registration_query_params
50
+	 * @return EE_Transaction_Processor instance
51
+	 */
52
+	public static function instance($registration_query_params = array())
53
+	{
54
+		// check if class object is instantiated
55
+		if (! self::$_instance instanceof EE_Transaction_Processor) {
56
+			self::$_instance = new self($registration_query_params);
57
+		}
58
+		return self::$_instance;
59
+	}
60
+
61
+
62
+	/**
63
+	 * @param array $registration_query_params
64
+	 */
65
+	private function __construct($registration_query_params = array())
66
+	{
67
+		// make sure some query params are set for retrieving registrations
68
+		$this->_set_registration_query_params($registration_query_params);
69
+	}
70
+
71
+
72
+	/**
73
+	 * @access private
74
+	 * @param array $registration_query_params
75
+	 */
76
+	private function _set_registration_query_params($registration_query_params)
77
+	{
78
+		$this->_registration_query_params = ! empty($registration_query_params) ? $registration_query_params
79
+			: array('order_by' => array('REG_count' => 'ASC'));
80
+	}
81
+
82
+
83
+	/**
84
+	 * manually_update_registration_statuses
85
+	 *
86
+	 * @access public
87
+	 * @param EE_Transaction $transaction
88
+	 * @param string         $new_reg_status
89
+	 * @param array          $registration_query_params array of query WHERE params to use
90
+	 *                                                  when retrieving cached registrations from a transaction
91
+	 * @return    boolean
92
+	 * @throws \EE_Error
93
+	 */
94
+	public function manually_update_registration_statuses(
95
+		EE_Transaction $transaction,
96
+		$new_reg_status = '',
97
+		$registration_query_params = array()
98
+	) {
99
+		$status_updates = $this->_call_method_on_registrations_via_Registration_Processor(
100
+			'manually_update_registration_status',
101
+			$transaction,
102
+			$registration_query_params,
103
+			$new_reg_status
104
+		);
105
+		// send messages
106
+		/** @type EE_Registration_Processor $registration_processor */
107
+		$registration_processor = EE_Registry::instance()->load_class('Registration_Processor');
108
+		$registration_processor->trigger_registration_update_notifications(
109
+			$transaction->primary_registration(),
110
+			array('manually_updated' => true)
111
+		);
112
+		do_action(
113
+			'AHEE__EE_Transaction_Processor__manually_update_registration_statuses',
114
+			$transaction,
115
+			$status_updates
116
+		);
117
+		return $status_updates;
118
+	}
119
+
120
+
121
+	/**
122
+	 * toggle_registration_statuses_for_default_approved_events
123
+	 *
124
+	 * @access public
125
+	 * @param EE_Transaction $transaction
126
+	 * @param array          $registration_query_params array of query WHERE params to use
127
+	 *                                                  when retrieving cached registrations from a transaction
128
+	 * @return    boolean
129
+	 * @throws \EE_Error
130
+	 */
131
+	public function toggle_registration_statuses_for_default_approved_events(
132
+		EE_Transaction $transaction,
133
+		$registration_query_params = array()
134
+	) {
135
+		$status_updates = $this->_call_method_on_registrations_via_Registration_Processor(
136
+			'toggle_registration_status_for_default_approved_events',
137
+			$transaction,
138
+			$registration_query_params
139
+		);
140
+		do_action(
141
+			'AHEE__EE_Transaction_Processor__toggle_registration_statuses_for_default_approved_events',
142
+			$transaction,
143
+			$status_updates
144
+		);
145
+		return $status_updates;
146
+	}
147
+
148
+
149
+	/**
150
+	 * toggle_registration_statuses_if_no_monies_owing
151
+	 *
152
+	 * @access public
153
+	 * @param EE_Transaction $transaction
154
+	 * @param array          $registration_query_params array of query WHERE params to use
155
+	 *                                                  when retrieving cached registrations from a transaction
156
+	 * @return    boolean
157
+	 * @throws \EE_Error
158
+	 */
159
+	public function toggle_registration_statuses_if_no_monies_owing(
160
+		EE_Transaction $transaction,
161
+		$registration_query_params = array()
162
+	) {
163
+		$status_updates = $this->_call_method_on_registrations_via_Registration_Processor(
164
+			'toggle_registration_status_if_no_monies_owing',
165
+			$transaction,
166
+			$registration_query_params
167
+		);
168
+		do_action(
169
+			'AHEE__EE_Transaction_Processor__toggle_registration_statuses_if_no_monies_owing',
170
+			$transaction,
171
+			$status_updates
172
+		);
173
+		return $status_updates;
174
+	}
175
+
176
+
177
+	/**
178
+	 * update_transaction_and_registrations_after_checkout_or_payment
179
+	 * cycles thru related registrations and calls update_registration_after_checkout_or_payment() on each
180
+	 *
181
+	 * @param EE_Transaction     $transaction
182
+	 * @param \EE_Payment | NULL $payment
183
+	 * @param array              $registration_query_params    array of query WHERE params to use
184
+	 *                                                         when retrieving cached registrations from a transaction
185
+	 * @param bool               $trigger_notifications        whether or not to call
186
+	 *                                                         \EE_Registration_Processor::trigger_registration_update_notifications()
187
+	 * @return array
188
+	 * @throws \EE_Error
189
+	 */
190
+	public function update_transaction_and_registrations_after_checkout_or_payment(
191
+		EE_Transaction $transaction,
192
+		$payment = null,
193
+		$registration_query_params = array(),
194
+		$trigger_notifications = true
195
+	) {
196
+		// make sure some query params are set for retrieving registrations
197
+		$this->_set_registration_query_params($registration_query_params);
198
+		// get final reg step status
199
+		$finalized = $transaction->final_reg_step_completed();
200
+		// if the 'finalize_registration' step has been initiated (has a timestamp)
201
+		// but has not yet been fully completed (TRUE)
202
+		if (is_int($finalized) && $finalized !== false && $finalized !== true) {
203
+			$transaction->set_reg_step_completed('finalize_registration');
204
+			$finalized = true;
205
+		}
206
+		$transaction->save();
207
+		// array of details to aid in decision making by systems
208
+		$update_params = array(
209
+			'old_txn_status'  => $transaction->old_txn_status(),
210
+			'new_txn_status'  => $transaction->status_ID(),
211
+			'finalized'       => $finalized,
212
+			'revisit'         => $this->_revisit,
213
+			'payment_updates' => $payment instanceof EE_Payment ? true : false,
214
+			'last_payment'    => $payment,
215
+		);
216
+		// now update the registrations and add the results to our $update_params
217
+		$update_params['status_updates'] = $this->_call_method_on_registrations_via_Registration_Processor(
218
+			'update_registration_after_checkout_or_payment',
219
+			$transaction,
220
+			$this->_registration_query_params,
221
+			$update_params
222
+		);
223
+		if ($trigger_notifications) {
224
+			// send messages
225
+			/** @type EE_Registration_Processor $registration_processor */
226
+			$registration_processor = EE_Registry::instance()->load_class('Registration_Processor');
227
+			$registration_processor->trigger_registration_update_notifications(
228
+				$transaction->primary_registration(),
229
+				$update_params
230
+			);
231
+		}
232
+		do_action(
233
+			'AHEE__EE_Transaction_Processor__update_transaction_and_registrations_after_checkout_or_payment',
234
+			$transaction,
235
+			$update_params
236
+		);
237
+		return $update_params;
238
+	}
239
+
240
+
241
+	/**
242
+	 * update_transaction_after_registration_reopened
243
+	 * readjusts TXN and Line Item totals after a registration is changed from
244
+	 * cancelled or declined to another reg status such as pending payment or approved
245
+	 *
246
+	 * @param \EE_Registration $registration
247
+	 * @param array            $closed_reg_statuses
248
+	 * @param bool             $update_txn
249
+	 * @return bool
250
+	 * @throws \EE_Error
251
+	 */
252
+	public function update_transaction_after_reinstating_canceled_registration(
253
+		EE_Registration $registration,
254
+		$closed_reg_statuses = array(),
255
+		$update_txn = true
256
+	) {
257
+		// these reg statuses should not be considered in any calculations involving monies owing
258
+		$closed_reg_statuses = ! empty($closed_reg_statuses) ? $closed_reg_statuses
259
+			: EEM_Registration::closed_reg_statuses();
260
+		if (in_array($registration->status_ID(), $closed_reg_statuses, true)) {
261
+			return false;
262
+		}
263
+		try {
264
+			$transaction = $this->get_transaction_for_registration($registration);
265
+			$ticket_line_item = $this->get_ticket_line_item_for_transaction_registration(
266
+				$transaction,
267
+				$registration
268
+			);
269
+			// un-cancel the ticket
270
+			$success = EEH_Line_Item::reinstate_canceled_ticket_line_item($ticket_line_item);
271
+		} catch (EE_Error $e) {
272
+			EE_Error::add_error(
273
+				sprintf(
274
+					esc_html__(
275
+						'The Ticket Line Item for Registration %1$d could not be reinstated because :%2$s%3$s',
276
+						'event_espresso'
277
+					),
278
+					$registration->ID(),
279
+					'<br />',
280
+					$e->getMessage()
281
+				),
282
+				__FILE__,
283
+				__FUNCTION__,
284
+				__LINE__
285
+			);
286
+			return false;
287
+		}
288
+		if ($update_txn) {
289
+			return $transaction->save() ? $success : false;
290
+		}
291
+		return $success;
292
+	}
293
+
294
+
295
+	/**
296
+	 * update_transaction_after_canceled_or_declined_registration
297
+	 * readjusts TXN and Line Item totals after a registration is cancelled or declined
298
+	 *
299
+	 * @param \EE_Registration $registration
300
+	 * @param array            $closed_reg_statuses
301
+	 * @param bool             $update_txn
302
+	 * @return bool
303
+	 * @throws \EE_Error
304
+	 */
305
+	public function update_transaction_after_canceled_or_declined_registration(
306
+		EE_Registration $registration,
307
+		$closed_reg_statuses = array(),
308
+		$update_txn = true
309
+	) {
310
+		// these reg statuses should not be considered in any calculations involving monies owing
311
+		$closed_reg_statuses = ! empty($closed_reg_statuses) ? $closed_reg_statuses
312
+			: EEM_Registration::closed_reg_statuses();
313
+		if (! in_array($registration->status_ID(), $closed_reg_statuses, true)) {
314
+			return false;
315
+		}
316
+		try {
317
+			$transaction = $this->get_transaction_for_registration($registration);
318
+			if (
319
+				apply_filters(
320
+					'FHEE__EE_Transaction_Processor__update_transaction_after_canceled_or_declined_registration__cancel_ticket_line_item',
321
+					true,
322
+					$registration,
323
+					$transaction
324
+				)
325
+			) {
326
+				$ticket_line_item = $this->get_ticket_line_item_for_transaction_registration(
327
+					$transaction,
328
+					$registration
329
+				);
330
+				EEH_Line_Item::cancel_ticket_line_item($ticket_line_item);
331
+			}
332
+		} catch (EE_Error $e) {
333
+			EE_Error::add_error(
334
+				sprintf(
335
+					esc_html__(
336
+						'The Ticket Line Item for Registration %1$d could not be cancelled because :%2$s%3$s',
337
+						'event_espresso'
338
+					),
339
+					$registration->ID(),
340
+					'<br />',
341
+					$e->getMessage()
342
+				),
343
+				__FILE__,
344
+				__FUNCTION__,
345
+				__LINE__
346
+			);
347
+			return false;
348
+		}
349
+		if ($update_txn) {
350
+			return $transaction->save() ? true : false;
351
+		}
352
+		return true;
353
+	}
354
+
355
+
356
+	/**
357
+	 * get_transaction_for_registration
358
+	 *
359
+	 * @access    public
360
+	 * @param    EE_Registration $registration
361
+	 * @return    EE_Transaction
362
+	 * @throws    EE_Error
363
+	 */
364
+	public function get_transaction_for_registration(EE_Registration $registration)
365
+	{
366
+		$transaction = $registration->transaction();
367
+		if (! $transaction instanceof EE_Transaction) {
368
+			throw new EE_Error(
369
+				sprintf(
370
+					esc_html__('The Transaction for Registration %1$d was not found or is invalid.', 'event_espresso'),
371
+					$registration->ID()
372
+				)
373
+			);
374
+		}
375
+		return $transaction;
376
+	}
377
+
378
+
379
+	/**
380
+	 * get_ticket_line_item_for_transaction_registration
381
+	 *
382
+	 * @access    public
383
+	 * @param    EE_Transaction  $transaction
384
+	 * @param    EE_Registration $registration
385
+	 * @return    EE_Line_Item
386
+	 * @throws    EE_Error
387
+	 */
388
+	public function get_ticket_line_item_for_transaction_registration(
389
+		EE_Transaction $transaction,
390
+		EE_Registration $registration
391
+	) {
392
+		EE_Registry::instance()->load_helper('Line_Item');
393
+		$ticket_line_item = EEM_Line_Item::instance()->get_ticket_line_item_for_transaction(
394
+			$transaction->ID(),
395
+			$registration->ticket_ID()
396
+		);
397
+		if (! $ticket_line_item instanceof EE_Line_Item) {
398
+			throw new EE_Error(
399
+				sprintf(
400
+					esc_html__(
401
+						'The Line Item for Transaction %1$d and Ticket %2$d was not found or is invalid.',
402
+						'event_espresso'
403
+					),
404
+					$transaction->ID(),
405
+					$registration->ticket_ID()
406
+				)
407
+			);
408
+		}
409
+		return $ticket_line_item;
410
+	}
411
+
412
+
413
+	/**
414
+	 * cancel_transaction_if_all_registrations_canceled
415
+	 * cycles thru related registrations and checks their statuses
416
+	 * if ALL registrations are Cancelled or Declined, then this sets the TXN status to
417
+	 *
418
+	 * @access    public
419
+	 * @param    EE_Transaction $transaction
420
+	 * @param    string         $new_TXN_status
421
+	 * @param    array          $registration_query_params - array of query WHERE params to use when
422
+	 *                                                     retrieving cached registrations from a transaction
423
+	 * @param    array          $closed_reg_statuses
424
+	 * @param    bool           $update_txn
425
+	 * @return    bool            true if TXN status was updated, false if not
426
+	 */
427
+	public function toggle_transaction_status_if_all_registrations_canceled_or_declined(
428
+		EE_Transaction $transaction,
429
+		$new_TXN_status = '',
430
+		$registration_query_params = array(),
431
+		$closed_reg_statuses = array(),
432
+		$update_txn = true
433
+	) {
434
+		// make sure some query params are set for retrieving registrations
435
+		$this->_set_registration_query_params($registration_query_params);
436
+		// these reg statuses should not be considered in any calculations involving monies owing
437
+		$closed_reg_statuses = ! empty($closed_reg_statuses) ? $closed_reg_statuses
438
+			: EEM_Registration::closed_reg_statuses();
439
+		// loop through cached registrations
440
+		foreach ($transaction->registrations($this->_registration_query_params) as $registration) {
441
+			if (
442
+				$registration instanceof EE_Registration
443
+				&& ! in_array($registration->status_ID(), $closed_reg_statuses)
444
+			) {
445
+				return false;
446
+			}
447
+		}
448
+		if (in_array($new_TXN_status, EEM_Transaction::txn_status_array())) {
449
+			$transaction->set_status($new_TXN_status);
450
+		}
451
+		if ($update_txn) {
452
+			return $transaction->save() ? true : false;
453
+		}
454
+		return true;
455
+	}
456
+
457
+
458
+	/**
459
+	 * _call_method_on_registrations_via_Registration_Processor
460
+	 * cycles thru related registrations and calls the requested method on each
461
+	 *
462
+	 * @access private
463
+	 * @param string         $method_name
464
+	 * @param EE_Transaction $transaction
465
+	 * @param array          $registration_query_params array of query WHERE params to use
466
+	 *                                                  when retrieving cached registrations from a transaction
467
+	 * @param string         $additional_param
468
+	 * @throws \EE_Error
469
+	 * @return boolean
470
+	 */
471
+	private function _call_method_on_registrations_via_Registration_Processor(
472
+		$method_name,
473
+		EE_Transaction $transaction,
474
+		$registration_query_params = array(),
475
+		$additional_param = null
476
+	) {
477
+		$response = false;
478
+		/** @type EE_Registration_Processor $registration_processor */
479
+		$registration_processor = EE_Registry::instance()->load_class('Registration_Processor');
480
+		// check that method exists
481
+		if (! method_exists($registration_processor, $method_name)) {
482
+			throw new EE_Error(esc_html__('Method does not exist.', 'event_espresso'));
483
+		}
484
+		// make sure some query params are set for retrieving registrations
485
+		$this->_set_registration_query_params($registration_query_params);
486
+		// loop through cached registrations
487
+		foreach ($transaction->registrations($this->_registration_query_params) as $registration) {
488
+			if ($registration instanceof EE_Registration) {
489
+				if ($additional_param) {
490
+					$response = $registration_processor->{$method_name}($registration, $additional_param)
491
+						? true
492
+						: $response;
493
+				} else {
494
+					$response = $registration_processor->{$method_name}($registration)
495
+						? true
496
+						: $response;
497
+				}
498
+			}
499
+		}
500
+		return $response;
501
+	}
502
+
503
+
504
+	/**
505
+	 * set_transaction_payment_method_based_on_registration_statuses
506
+	 * sets or unsets the PMD_ID field on the TXN based on the related REG statuses
507
+	 * basically if ALL Registrations are "Not Approved", then the EE_Transaction.PMD_ID is set to null,
508
+	 * but if any Registration has a different status, then EE_Transaction.PMD_ID is set to either:
509
+	 *        the first "default" Payment Method
510
+	 *        the first active Payment Method
511
+	 *    whichever is found first.
512
+	 *
513
+	 * @param  EE_Registration $edited_registration
514
+	 * @return void
515
+	 * @throws \EE_Error
516
+	 */
517
+	public function set_transaction_payment_method_based_on_registration_statuses(
518
+		EE_Registration $edited_registration
519
+	) {
520
+		if ($edited_registration instanceof EE_Registration) {
521
+			$transaction = $edited_registration->transaction();
522
+			if ($transaction instanceof EE_Transaction) {
523
+				$all_not_approved = true;
524
+				foreach ($transaction->registrations() as $registration) {
525
+					if ($registration instanceof EE_Registration) {
526
+						// if any REG != "Not Approved" then toggle to false
527
+						$all_not_approved = $registration->is_not_approved() ? $all_not_approved : false;
528
+					}
529
+				}
530
+				// if ALL Registrations are "Not Approved"
531
+				if ($all_not_approved) {
532
+					$transaction->set_payment_method_ID(null);
533
+					$transaction->save();
534
+				} else {
535
+					$available_payment_methods = EEM_Payment_Method::instance()->get_all_for_transaction(
536
+						$transaction,
537
+						EEM_Payment_Method::scope_cart
538
+					);
539
+					if (! empty($available_payment_methods)) {
540
+						$PMD_ID = 0;
541
+						foreach ($available_payment_methods as $available_payment_method) {
542
+							if (
543
+								$available_payment_method instanceof EE_Payment_Method
544
+								&& $available_payment_method->open_by_default()
545
+							) {
546
+								$PMD_ID = $available_payment_method->ID();
547
+								break;
548
+							}
549
+						}
550
+						if (! $PMD_ID) {
551
+							$first_payment_method = reset($available_payment_methods);
552
+							if ($first_payment_method instanceof EE_Payment_Method) {
553
+								$PMD_ID = $first_payment_method->ID();
554
+							} else {
555
+								EE_Error::add_error(
556
+									esc_html__(
557
+										'A valid Payment Method could not be determined. Please ensure that at least one Payment Method is activated.',
558
+										'event_espresso'
559
+									),
560
+									__FILE__,
561
+									__LINE__,
562
+									__FUNCTION__
563
+								);
564
+							}
565
+						}
566
+						$transaction->set_payment_method_ID($PMD_ID);
567
+						$transaction->save();
568
+					} else {
569
+						EE_Error::add_error(
570
+							esc_html__(
571
+								'Please activate at least one Payment Method in order for things to operate correctly.',
572
+								'event_espresso'
573
+							),
574
+							__FILE__,
575
+							__LINE__,
576
+							__FUNCTION__
577
+						);
578
+					}
579
+				}
580
+			}
581
+		}
582
+	}
583
+
584
+
585
+
586
+	/********************************** DEPRECATED METHODS **********************************/
587
+
588
+
589
+	/**
590
+	 * @deprecated 4.9.12
591
+	 * @return string
592
+	 */
593
+	public function old_txn_status()
594
+	{
595
+		EE_Error::doing_it_wrong(
596
+			__METHOD__,
597
+			esc_html__(
598
+				'This logic has been moved into \EE_Transaction::old_txn_status(), please use that method instead.',
599
+				'event_espresso'
600
+			),
601
+			'4.9.12'
602
+		);
603
+		return $this->_old_txn_status;
604
+	}
605
+
606
+
607
+	/**
608
+	 * @deprecated 4.9.12
609
+	 * @param string $old_txn_status
610
+	 */
611
+	public function set_old_txn_status($old_txn_status)
612
+	{
613
+		EE_Error::doing_it_wrong(
614
+			__METHOD__,
615
+			esc_html__(
616
+				'This logic has been moved into \EE_Transaction::set_old_txn_status(), please use that method instead.',
617
+				'event_espresso'
618
+			),
619
+			'4.9.12'
620
+		);
621
+		// only set the first time
622
+		if ($this->_old_txn_status === null) {
623
+			$this->_old_txn_status = $old_txn_status;
624
+		}
625
+	}
626
+
627
+
628
+	/**
629
+	 * @deprecated 4.9.12
630
+	 * @return string
631
+	 */
632
+	public function new_txn_status()
633
+	{
634
+		EE_Error::doing_it_wrong(
635
+			__METHOD__,
636
+			esc_html__(
637
+				'This logic has been removed. Please just use \EE_Transaction::status_ID() instead.',
638
+				'event_espresso'
639
+			),
640
+			'4.9.12'
641
+		);
642
+		return $this->_new_txn_status;
643
+	}
644
+
645
+
646
+	/**
647
+	 * @deprecated 4.9.12
648
+	 * @param string $new_txn_status
649
+	 */
650
+	public function set_new_txn_status($new_txn_status)
651
+	{
652
+		EE_Error::doing_it_wrong(
653
+			__METHOD__,
654
+			esc_html__(
655
+				'This logic has been removed. Please just use \EE_Transaction::set_status() instead.',
656
+				'event_espresso'
657
+			),
658
+			'4.9.12'
659
+		);
660
+		$this->_new_txn_status = $new_txn_status;
661
+	}
662
+
663
+
664
+	/**
665
+	 * reg_status_updated
666
+	 *
667
+	 * @deprecated 4.9.12
668
+	 * @return bool
669
+	 */
670
+	public function txn_status_updated()
671
+	{
672
+		EE_Error::doing_it_wrong(
673
+			__METHOD__,
674
+			esc_html__(
675
+				'This logic has been moved into \EE_Transaction::txn_status_updated(), please use that method instead.',
676
+				'event_espresso'
677
+			),
678
+			'4.9.12'
679
+		);
680
+		return $this->_new_txn_status !== $this->_old_txn_status && $this->_old_txn_status !== null ? true : false;
681
+	}
682
+
683
+
684
+	/**
685
+	 * all_reg_steps_completed
686
+	 * returns:
687
+	 *    true if ALL reg steps have been marked as completed
688
+	 *        or false if any step is not completed
689
+	 *
690
+	 * @deprecated 4.9.12
691
+	 * @param EE_Transaction $transaction
692
+	 * @return boolean
693
+	 */
694
+	public function all_reg_steps_completed(EE_Transaction $transaction)
695
+	{
696
+		EE_Error::doing_it_wrong(
697
+			__METHOD__,
698
+			esc_html__(
699
+				'This logic has been moved into \EE_Transaction::all_reg_steps_completed(), please use that method instead.',
700
+				'event_espresso'
701
+			),
702
+			'4.9.12',
703
+			'5.0.0'
704
+		);
705
+		return $transaction->all_reg_steps_completed();
706
+	}
707
+
708
+
709
+	/**
710
+	 * all_reg_steps_completed_except
711
+	 * returns:
712
+	 *        true if ALL reg steps, except a particular step that you wish to skip over, have been marked as completed
713
+	 *        or false if any other step is not completed
714
+	 *        or false if ALL steps are completed including the exception you are testing !!!
715
+	 *
716
+	 * @deprecated 4.9.12
717
+	 * @param EE_Transaction $transaction
718
+	 * @param string         $exception
719
+	 * @return boolean
720
+	 */
721
+	public function all_reg_steps_completed_except(EE_Transaction $transaction, $exception = '')
722
+	{
723
+		EE_Error::doing_it_wrong(
724
+			__METHOD__,
725
+			esc_html__(
726
+				'This logic has been moved into \EE_Transaction::all_reg_steps_completed_except(), please use that method instead.',
727
+				'event_espresso'
728
+			),
729
+			'4.9.12',
730
+			'5.0.0'
731
+		);
732
+		return $transaction->all_reg_steps_completed_except($exception);
733
+	}
734
+
735
+
736
+	/**
737
+	 * all_reg_steps_completed_except
738
+	 * returns:
739
+	 *        true if ALL reg steps, except the final step, have been marked as completed
740
+	 *        or false if any step is not completed
741
+	 *    or false if ALL steps are completed including the final step !!!
742
+	 *
743
+	 * @deprecated 4.9.12
744
+	 * @param EE_Transaction $transaction
745
+	 * @return boolean
746
+	 */
747
+	public function all_reg_steps_completed_except_final_step(EE_Transaction $transaction)
748
+	{
749
+		EE_Error::doing_it_wrong(
750
+			__METHOD__,
751
+			esc_html__(
752
+				'This logic has been moved into \EE_Transaction::all_reg_steps_completed_except_final_step(), please use that method instead.',
753
+				'event_espresso'
754
+			),
755
+			'4.9.12',
756
+			'5.0.0'
757
+		);
758
+		return $transaction->all_reg_steps_completed_except_final_step();
759
+	}
760
+
761
+
762
+	/**
763
+	 * reg_step_completed
764
+	 * returns:
765
+	 *    true if a specific reg step has been marked as completed
766
+	 *    a Unix timestamp if it has been initialized but not yet completed,
767
+	 *    or false if it has not yet been initialized
768
+	 *
769
+	 * @deprecated 4.9.12
770
+	 * @param EE_Transaction $transaction
771
+	 * @param string         $reg_step_slug
772
+	 * @return boolean | int
773
+	 */
774
+	public function reg_step_completed(EE_Transaction $transaction, $reg_step_slug)
775
+	{
776
+		EE_Error::doing_it_wrong(
777
+			__METHOD__,
778
+			esc_html__(
779
+				'This logic has been moved into \EE_Transaction::reg_step_completed(), please use that method instead.',
780
+				'event_espresso'
781
+			),
782
+			'4.9.12',
783
+			'5.0.0'
784
+		);
785
+		return $transaction->reg_step_completed($reg_step_slug);
786
+	}
787
+
788
+
789
+	/**
790
+	 * completed_final_reg_step
791
+	 * returns:
792
+	 *    true if the finalize_registration reg step has been marked as completed
793
+	 *    a Unix timestamp if it has been initialized but not yet completed,
794
+	 *    or false if it has not yet been initialized
795
+	 *
796
+	 * @deprecated 4.9.12
797
+	 * @param EE_Transaction $transaction
798
+	 * @return boolean | int
799
+	 */
800
+	public function final_reg_step_completed(EE_Transaction $transaction)
801
+	{
802
+		EE_Error::doing_it_wrong(
803
+			__METHOD__,
804
+			esc_html__(
805
+				'This logic has been moved into \EE_Transaction::final_reg_step_completed(), please use that method instead.',
806
+				'event_espresso'
807
+			),
808
+			'4.9.12',
809
+			'5.0.0'
810
+		);
811
+		return $transaction->final_reg_step_completed();
812
+	}
813
+
814
+
815
+	/**
816
+	 * set_reg_step_initiated
817
+	 * given a valid TXN_reg_step, this sets it's value to a unix timestamp
818
+	 *
819
+	 * @deprecated 4.9.12
820
+	 * @access     public
821
+	 * @param \EE_Transaction $transaction
822
+	 * @param string          $reg_step_slug
823
+	 * @return boolean
824
+	 * @throws \EE_Error
825
+	 */
826
+	public function set_reg_step_initiated(EE_Transaction $transaction, $reg_step_slug)
827
+	{
828
+		EE_Error::doing_it_wrong(
829
+			__METHOD__,
830
+			esc_html__(
831
+				'This logic has been moved into \EE_Transaction::set_reg_step_initiated(), please use that method instead.',
832
+				'event_espresso'
833
+			),
834
+			'4.9.12',
835
+			'5.0.0'
836
+		);
837
+		return $transaction->set_reg_step_initiated($reg_step_slug);
838
+	}
839
+
840
+
841
+	/**
842
+	 * set_reg_step_completed
843
+	 * given a valid TXN_reg_step, this sets the step as completed
844
+	 *
845
+	 * @deprecated 4.9.12
846
+	 * @access     public
847
+	 * @param \EE_Transaction $transaction
848
+	 * @param string          $reg_step_slug
849
+	 * @return boolean
850
+	 * @throws \EE_Error
851
+	 */
852
+	public function set_reg_step_completed(EE_Transaction $transaction, $reg_step_slug)
853
+	{
854
+		EE_Error::doing_it_wrong(
855
+			__METHOD__,
856
+			esc_html__(
857
+				'This logic has been moved into \EE_Transaction::set_reg_step_completed(), please use that method instead.',
858
+				'event_espresso'
859
+			),
860
+			'4.9.12',
861
+			'5.0.0'
862
+		);
863
+		return $transaction->set_reg_step_completed($reg_step_slug);
864
+	}
865
+
866
+
867
+	/**
868
+	 * set_reg_step_completed
869
+	 * given a valid TXN_reg_step slug, this sets the step as NOT completed
870
+	 *
871
+	 * @deprecated 4.9.12
872
+	 * @access     public
873
+	 * @param \EE_Transaction $transaction
874
+	 * @param string          $reg_step_slug
875
+	 * @return boolean
876
+	 * @throws \EE_Error
877
+	 */
878
+	public function set_reg_step_not_completed(EE_Transaction $transaction, $reg_step_slug)
879
+	{
880
+		EE_Error::doing_it_wrong(
881
+			__METHOD__,
882
+			esc_html__(
883
+				'This logic has been moved into \EE_Transaction::set_reg_step_not_completed(), please use that method instead.',
884
+				'event_espresso'
885
+			),
886
+			'4.9.12',
887
+			'5.0.0'
888
+		);
889
+		return $transaction->set_reg_step_not_completed($reg_step_slug);
890
+	}
891
+
892
+
893
+	/**
894
+	 * remove_reg_step
895
+	 * given a valid TXN_reg_step slug, this will remove (unset)
896
+	 * the reg step from the TXN reg step array
897
+	 *
898
+	 * @deprecated 4.9.12
899
+	 * @access     public
900
+	 * @param \EE_Transaction $transaction
901
+	 * @param string          $reg_step_slug
902
+	 * @return void
903
+	 */
904
+	public function remove_reg_step(EE_Transaction $transaction, $reg_step_slug)
905
+	{
906
+		EE_Error::doing_it_wrong(
907
+			__METHOD__,
908
+			esc_html__(
909
+				'This logic has been moved into \EE_Transaction::remove_reg_step(), please use that method instead.',
910
+				'event_espresso'
911
+			),
912
+			'4.9.12',
913
+			'5.0.0'
914
+		);
915
+		$transaction->remove_reg_step($reg_step_slug);
916
+	}
917
+
918
+
919
+	/**
920
+	 *    toggle_failed_transaction_status
921
+	 * upgrades a TXNs status from failed to abandoned,
922
+	 * meaning that contact information has been captured for at least one registrant
923
+	 *
924
+	 * @deprecated 4.9.12
925
+	 * @access     public
926
+	 * @param EE_Transaction $transaction
927
+	 * @return    boolean
928
+	 * @throws \EE_Error
929
+	 */
930
+	public function toggle_failed_transaction_status(EE_Transaction $transaction)
931
+	{
932
+		EE_Error::doing_it_wrong(
933
+			__METHOD__,
934
+			esc_html__(
935
+				'This logic has been moved into \EE_Transaction::toggle_failed_transaction_status(), please use that method instead.',
936
+				'event_espresso'
937
+			),
938
+			'4.9.12',
939
+			'5.0.0'
940
+		);
941
+		return $transaction->toggle_failed_transaction_status();
942
+	}
943
+
944
+
945
+	/**
946
+	 * toggle_abandoned_transaction_status
947
+	 * upgrades a TXNs status from failed or abandoned to incomplete
948
+	 *
949
+	 * @deprecated 4.9.12
950
+	 * @access     public
951
+	 * @param  EE_Transaction $transaction
952
+	 * @return boolean
953
+	 */
954
+	public function toggle_abandoned_transaction_status(EE_Transaction $transaction)
955
+	{
956
+		EE_Error::doing_it_wrong(
957
+			__METHOD__,
958
+			esc_html__(
959
+				'This logic has been moved into \EE_Transaction::toggle_abandoned_transaction_status(), please use that method instead.',
960
+				'event_espresso'
961
+			),
962
+			'4.9.12',
963
+			'5.0.0'
964
+		);
965
+		return $transaction->toggle_abandoned_transaction_status();
966
+	}
967 967
 }
Please login to merge, or discard this patch.
core/business/EE_Transaction_Payments.class.php 2 patches
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -42,7 +42,7 @@  discard block
 block discarded – undo
42 42
     public static function instance()
43 43
     {
44 44
         // check if class object is instantiated
45
-        if (! self::$_instance instanceof EE_Transaction_Payments) {
45
+        if ( ! self::$_instance instanceof EE_Transaction_Payments) {
46 46
             self::$_instance = new self();
47 47
         }
48 48
         return self::$_instance;
@@ -61,7 +61,7 @@  discard block
 block discarded – undo
61 61
     public function recalculate_transaction_total(EE_Transaction $transaction, $update_txn = true)
62 62
     {
63 63
         $total_line_item = $transaction->total_line_item();
64
-        if (! $total_line_item instanceof EE_Line_Item) {
64
+        if ( ! $total_line_item instanceof EE_Line_Item) {
65 65
             EE_Error::add_error(
66 66
                 sprintf(
67 67
                     esc_html__('The Total Line Item for Transaction %1$d\'s was not found or is invalid.', 'event_espresso'),
@@ -100,7 +100,7 @@  discard block
 block discarded – undo
100 100
     public function calculate_total_payments_and_update_status(EE_Transaction $transaction, $update_txn = true)
101 101
     {
102 102
         // verify transaction
103
-        if (! $transaction instanceof EE_Transaction) {
103
+        if ( ! $transaction instanceof EE_Transaction) {
104 104
             EE_Error::add_error(
105 105
                 esc_html__('Please provide a valid EE_Transaction object.', 'event_espresso'),
106 106
                 __FILE__,
@@ -115,7 +115,7 @@  discard block
 block discarded – undo
115 115
         if ($total_paid !== false && (float) $total_paid !== $transaction->paid()) {
116 116
             $transaction->set_paid($total_paid);
117 117
             // maybe update status, and make sure to save transaction if not done already
118
-            if (! $transaction->update_status_based_on_total_paid($update_txn)) {
118
+            if ( ! $transaction->update_status_based_on_total_paid($update_txn)) {
119 119
                 if ($update_txn) {
120 120
                     return $transaction->save() ? true : false;
121 121
                 }
@@ -144,7 +144,7 @@  discard block
 block discarded – undo
144 144
         $payment_status = EEM_Payment::status_id_approved
145 145
     ) {
146 146
         // verify transaction
147
-        if (! $transaction instanceof EE_Transaction) {
147
+        if ( ! $transaction instanceof EE_Transaction) {
148 148
             EE_Error::add_error(
149 149
                 esc_html__('Please provide a valid EE_Transaction object.', 'event_espresso'),
150 150
                 __FILE__,
@@ -177,7 +177,7 @@  discard block
 block discarded – undo
177 177
     public function delete_payment_and_update_transaction(EE_Payment $payment)
178 178
     {
179 179
         // verify payment
180
-        if (! $payment instanceof EE_Payment) {
180
+        if ( ! $payment instanceof EE_Payment) {
181 181
             EE_Error::add_error(
182 182
                 esc_html__('A valid Payment object was not received.', 'event_espresso'),
183 183
                 __FILE__,
@@ -186,10 +186,10 @@  discard block
 block discarded – undo
186 186
             );
187 187
             return false;
188 188
         }
189
-        if (! $this->delete_registration_payments_and_update_registrations($payment)) {
189
+        if ( ! $this->delete_registration_payments_and_update_registrations($payment)) {
190 190
             return false;
191 191
         }
192
-        if (! $payment->delete()) {
192
+        if ( ! $payment->delete()) {
193 193
             EE_Error::add_error(
194 194
                 esc_html__('The payment could not be deleted.', 'event_espresso'),
195 195
                 __FILE__,
@@ -213,7 +213,7 @@  discard block
 block discarded – undo
213 213
 
214 214
         // if this fails, that just means that the transaction didn't get its status changed and/or updated.
215 215
         // however the payment was still deleted.
216
-        if (! $this->calculate_total_payments_and_update_status($transaction)) {
216
+        if ( ! $this->calculate_total_payments_and_update_status($transaction)) {
217 217
             EE_Error::add_attention(
218 218
                 esc_html__(
219 219
                     'It appears that the Payment was deleted but no change was recorded for the Transaction for an unknown reason. Please verify that all data for this Transaction looks correct..',
@@ -255,7 +255,7 @@  discard block
 block discarded – undo
255 255
         $reg_payment_query_params = ! empty($reg_payment_query_params) ? $reg_payment_query_params
256 256
             : array(array('PAY_ID' => $payment->ID()));
257 257
         $registration_payments = EEM_Registration_Payment::instance()->get_all($reg_payment_query_params);
258
-        if (! empty($registration_payments)) {
258
+        if ( ! empty($registration_payments)) {
259 259
             foreach ($registration_payments as $registration_payment) {
260 260
                 if ($registration_payment instanceof EE_Registration_Payment) {
261 261
                     $amount_paid = $registration_payment->amount();
@@ -321,7 +321,7 @@  discard block
 block discarded – undo
321 321
     public function update_transaction_status_based_on_total_paid(EE_Transaction $transaction, $update_txn = true)
322 322
     {
323 323
         EE_Error::doing_it_wrong(
324
-            __CLASS__ . '::' . __FUNCTION__,
324
+            __CLASS__.'::'.__FUNCTION__,
325 325
             sprintf(
326 326
                 esc_html__('This method is deprecated. Please use "%s" instead', 'event_espresso'),
327 327
                 'EE_Transaction::update_status_based_on_total_paid()'
@@ -330,7 +330,7 @@  discard block
 block discarded – undo
330 330
             '5.0.0'
331 331
         );
332 332
         // verify transaction
333
-        if (! $transaction instanceof EE_Transaction) {
333
+        if ( ! $transaction instanceof EE_Transaction) {
334 334
             EE_Error::add_error(
335 335
                 esc_html__('Please provide a valid EE_Transaction object.', 'event_espresso'),
336 336
                 __FILE__,
Please login to merge, or discard this patch.
Indentation   +420 added lines, -420 removed lines patch added patch discarded remove patch
@@ -14,424 +14,424 @@
 block discarded – undo
14 14
  */
15 15
 class EE_Transaction_Payments
16 16
 {
17
-    /**
18
-     * @var EE_Transaction_Payments $_instance
19
-     * @access    private
20
-     */
21
-    private static $_instance;
22
-
23
-    /**
24
-     * @deprecated
25
-     * @var string
26
-     */
27
-    protected $_old_txn_status;
28
-
29
-    /**
30
-     * @deprecated
31
-     * @var string
32
-     */
33
-    protected $_new_txn_status;
34
-
35
-
36
-    /**
37
-     * @singleton method used to instantiate class object
38
-     * @access    public
39
-     * @return EE_Transaction_Payments instance
40
-     */
41
-    public static function instance()
42
-    {
43
-        // check if class object is instantiated
44
-        if (! self::$_instance instanceof EE_Transaction_Payments) {
45
-            self::$_instance = new self();
46
-        }
47
-        return self::$_instance;
48
-    }
49
-
50
-
51
-    /**
52
-     * recalculate_transaction_total
53
-     *
54
-     * @access private
55
-     * @param EE_Transaction $transaction
56
-     * @param bool           $update_txn
57
-     * @return bool true if TXN total was updated, false if not
58
-     * @throws \EE_Error
59
-     */
60
-    public function recalculate_transaction_total(EE_Transaction $transaction, $update_txn = true)
61
-    {
62
-        $total_line_item = $transaction->total_line_item();
63
-        if (! $total_line_item instanceof EE_Line_Item) {
64
-            EE_Error::add_error(
65
-                sprintf(
66
-                    esc_html__('The Total Line Item for Transaction %1$d\'s was not found or is invalid.', 'event_espresso'),
67
-                    $transaction->ID()
68
-                ),
69
-                __FILE__,
70
-                __FUNCTION__,
71
-                __LINE__
72
-            );
73
-            return false;
74
-        }
75
-        $new_total = $total_line_item->recalculate_total_including_taxes();
76
-        $transaction->set_total($new_total);
77
-        if ($update_txn) {
78
-            return $transaction->save() ? true : false;
79
-        }
80
-        return false;
81
-    }
82
-
83
-
84
-    /**
85
-     * Updates the provided EE_Transaction with all the applicable payments
86
-     * returns a boolean for whether the TXN was saved to the db
87
-     * (meaning a status change occurred)
88
-     * or not saved (which could **still** mean that
89
-     * the TXN status changed, but just was not yet saved).
90
-     * So if passing a value of false for the $update_txn param,
91
-     * then client code needs to take responsibility for saving the TXN
92
-     * regardless of what happens within EE_Transaction_Payments;
93
-     *
94
-     * @param            EE_Transaction /int $transaction_obj_or_id EE_Transaction or its ID
95
-     * @param    boolean $update_txn whether to save the TXN
96
-     * @return    boolean        whether the TXN was saved
97
-     * @throws \EE_Error
98
-     */
99
-    public function calculate_total_payments_and_update_status(EE_Transaction $transaction, $update_txn = true)
100
-    {
101
-        // verify transaction
102
-        if (! $transaction instanceof EE_Transaction) {
103
-            EE_Error::add_error(
104
-                esc_html__('Please provide a valid EE_Transaction object.', 'event_espresso'),
105
-                __FILE__,
106
-                __FUNCTION__,
107
-                __LINE__
108
-            );
109
-            return false;
110
-        }
111
-        // calculate total paid
112
-        $total_paid = $this->recalculate_total_payments_for_transaction($transaction);
113
-        // if total paid has changed
114
-        if ($total_paid !== false && (float) $total_paid !== $transaction->paid()) {
115
-            $transaction->set_paid($total_paid);
116
-            // maybe update status, and make sure to save transaction if not done already
117
-            if (! $transaction->update_status_based_on_total_paid($update_txn)) {
118
-                if ($update_txn) {
119
-                    return $transaction->save() ? true : false;
120
-                }
121
-            } else {
122
-                // the status got updated and was saved by
123
-                // update_transaction_status_based_on_total_paid()
124
-                return true;
125
-            }
126
-        }
127
-        return false;
128
-    }
129
-
130
-
131
-    /**
132
-     * recalculate_total_payments_for_transaction
133
-     *
134
-     * @access public
135
-     * @param EE_Transaction $transaction
136
-     * @param string         $payment_status One of EEM_Payment's statuses, like 'PAP' (Approved).
137
-     *                                       By default, searches for approved payments
138
-     * @return float|false   float on success, false on fail
139
-     * @throws \EE_Error
140
-     */
141
-    public function recalculate_total_payments_for_transaction(
142
-        EE_Transaction $transaction,
143
-        $payment_status = EEM_Payment::status_id_approved
144
-    ) {
145
-        // verify transaction
146
-        if (! $transaction instanceof EE_Transaction) {
147
-            EE_Error::add_error(
148
-                esc_html__('Please provide a valid EE_Transaction object.', 'event_espresso'),
149
-                __FILE__,
150
-                __FUNCTION__,
151
-                __LINE__
152
-            );
153
-            return false;
154
-        }
155
-        // ensure Payment model is loaded
156
-        EE_Registry::instance()->load_model('Payment');
157
-        // calls EEM_Base::sum()
158
-        return EEM_Payment::instance()->sum(
159
-            // query params
160
-            array(array('TXN_ID' => $transaction->ID(), 'STS_ID' => $payment_status)),
161
-            // field to sum
162
-            'PAY_amount'
163
-        );
164
-    }
165
-
166
-
167
-    /**
168
-     * delete_payment_and_update_transaction
169
-     * Before deleting the selected payment, we fetch it's transaction,
170
-     * then delete the payment, and update the transactions' amount paid.
171
-     *
172
-     * @param EE_Payment $payment
173
-     * @return boolean
174
-     * @throws \EE_Error
175
-     */
176
-    public function delete_payment_and_update_transaction(EE_Payment $payment)
177
-    {
178
-        // verify payment
179
-        if (! $payment instanceof EE_Payment) {
180
-            EE_Error::add_error(
181
-                esc_html__('A valid Payment object was not received.', 'event_espresso'),
182
-                __FILE__,
183
-                __FUNCTION__,
184
-                __LINE__
185
-            );
186
-            return false;
187
-        }
188
-        if (! $this->delete_registration_payments_and_update_registrations($payment)) {
189
-            return false;
190
-        }
191
-        if (! $payment->delete()) {
192
-            EE_Error::add_error(
193
-                esc_html__('The payment could not be deleted.', 'event_espresso'),
194
-                __FILE__,
195
-                __FUNCTION__,
196
-                __LINE__
197
-            );
198
-            return false;
199
-        }
200
-
201
-        $transaction = $payment->transaction();
202
-        $TXN_status = $transaction->status_ID();
203
-        if (
204
-            $TXN_status === EEM_Transaction::abandoned_status_code
205
-            || $TXN_status === EEM_Transaction::failed_status_code
206
-            || $payment->amount() === 0
207
-        ) {
208
-            EE_Error::add_success(esc_html__('The Payment was successfully deleted.', 'event_espresso'));
209
-            return true;
210
-        }
211
-
212
-
213
-        // if this fails, that just means that the transaction didn't get its status changed and/or updated.
214
-        // however the payment was still deleted.
215
-        if (! $this->calculate_total_payments_and_update_status($transaction)) {
216
-            EE_Error::add_attention(
217
-                esc_html__(
218
-                    'It appears that the Payment was deleted but no change was recorded for the Transaction for an unknown reason. Please verify that all data for this Transaction looks correct..',
219
-                    'event_espresso'
220
-                ),
221
-                __FILE__,
222
-                __FUNCTION__,
223
-                __LINE__
224
-            );
225
-            return true;
226
-        }
227
-
228
-        EE_Error::add_success(
229
-            esc_html__(
230
-                'The Payment was successfully deleted, and the Transaction has been updated accordingly.',
231
-                'event_espresso'
232
-            )
233
-        );
234
-        return true;
235
-    }
236
-
237
-
238
-    /**
239
-     * delete_registration_payments_and_update_registrations
240
-     *
241
-     * removes all registration payment records associated with a payment
242
-     * and subtracts their amounts from the corresponding registrations REG_paid field
243
-     *
244
-     * @param EE_Payment $payment
245
-     * @param array      $reg_payment_query_params
246
-     * @return bool
247
-     * @throws \EE_Error
248
-     */
249
-    public function delete_registration_payments_and_update_registrations(
250
-        EE_Payment $payment,
251
-        $reg_payment_query_params = array()
252
-    ) {
253
-        $save_payment = false;
254
-        $reg_payment_query_params = ! empty($reg_payment_query_params) ? $reg_payment_query_params
255
-            : array(array('PAY_ID' => $payment->ID()));
256
-        $registration_payments = EEM_Registration_Payment::instance()->get_all($reg_payment_query_params);
257
-        if (! empty($registration_payments)) {
258
-            foreach ($registration_payments as $registration_payment) {
259
-                if ($registration_payment instanceof EE_Registration_Payment) {
260
-                    $amount_paid = $registration_payment->amount();
261
-                    $registration = $registration_payment->registration();
262
-                    if ($registration instanceof EE_Registration) {
263
-                        $registration->set_paid($registration->paid() - $amount_paid);
264
-                        if ($registration->save() !== false) {
265
-                            $registration_payment->delete_permanently();
266
-                            $save_payment = true;
267
-                        }
268
-                    } else {
269
-                        EE_Error::add_error(
270
-                            sprintf(
271
-                                esc_html__(
272
-                                    'An invalid Registration object was associated with Registration Payment ID# %1$d.',
273
-                                    'event_espresso'
274
-                                ),
275
-                                $registration_payment->ID()
276
-                            ),
277
-                            __FILE__,
278
-                            __FUNCTION__,
279
-                            __LINE__
280
-                        );
281
-                        return false;
282
-                    }
283
-                } else {
284
-                    EE_Error::add_error(
285
-                        sprintf(
286
-                            esc_html__(
287
-                                'An invalid Registration Payment object was associated with payment ID# %1$d.',
288
-                                'event_espresso'
289
-                            ),
290
-                            $payment->ID()
291
-                        ),
292
-                        __FILE__,
293
-                        __FUNCTION__,
294
-                        __LINE__
295
-                    );
296
-                    return false;
297
-                }
298
-            }
299
-        }
300
-        if ($save_payment) {
301
-            $payment->save();
302
-        }
303
-        return true;
304
-    }
305
-
306
-
307
-
308
-    /********************************** DEPRECATED METHODS **********************************/
309
-
310
-
311
-    /**
312
-     * possibly toggles TXN status
313
-     *
314
-     * @deprecated 4.9.1
315
-     * @param EE_Transaction $transaction
316
-     * @param    boolean     $update_txn whether to save the TXN
317
-     * @return    boolean        whether the TXN was saved
318
-     * @throws \EE_Error
319
-     */
320
-    public function update_transaction_status_based_on_total_paid(EE_Transaction $transaction, $update_txn = true)
321
-    {
322
-        EE_Error::doing_it_wrong(
323
-            __CLASS__ . '::' . __FUNCTION__,
324
-            sprintf(
325
-                esc_html__('This method is deprecated. Please use "%s" instead', 'event_espresso'),
326
-                'EE_Transaction::update_status_based_on_total_paid()'
327
-            ),
328
-            '4.9.1',
329
-            '5.0.0'
330
-        );
331
-        // verify transaction
332
-        if (! $transaction instanceof EE_Transaction) {
333
-            EE_Error::add_error(
334
-                esc_html__('Please provide a valid EE_Transaction object.', 'event_espresso'),
335
-                __FILE__,
336
-                __FUNCTION__,
337
-                __LINE__
338
-            );
339
-            return false;
340
-        }
341
-        // set transaction status based on comparison of TXN_paid vs TXN_total
342
-        return $transaction->update_status_based_on_total_paid($update_txn);
343
-    }
344
-
345
-
346
-    /**
347
-     * @deprecated 4.9.12
348
-     * @return string
349
-     */
350
-    public function old_txn_status()
351
-    {
352
-        EE_Error::doing_it_wrong(
353
-            __METHOD__,
354
-            esc_html__(
355
-                'This logic has been moved into \EE_Transaction::old_txn_status(), please use that method instead.',
356
-                'event_espresso'
357
-            ),
358
-            '4.9.12'
359
-        );
360
-        return $this->_old_txn_status;
361
-    }
362
-
363
-
364
-    /**
365
-     * @deprecated 4.9.12
366
-     * @param string $old_txn_status
367
-     */
368
-    public function set_old_txn_status($old_txn_status)
369
-    {
370
-        EE_Error::doing_it_wrong(
371
-            __METHOD__,
372
-            esc_html__(
373
-                'This logic has been moved into \EE_Transaction::set_old_txn_status(), please use that method instead.',
374
-                'event_espresso'
375
-            ),
376
-            '4.9.12'
377
-        );
378
-        // only set the first time
379
-        if ($this->_old_txn_status === null) {
380
-            $this->_old_txn_status = $old_txn_status;
381
-        }
382
-    }
383
-
384
-
385
-    /**
386
-     * @deprecated 4.9.12
387
-     * @return string
388
-     */
389
-    public function new_txn_status()
390
-    {
391
-        EE_Error::doing_it_wrong(
392
-            __METHOD__,
393
-            esc_html__(
394
-                'This logic has been removed. Please just use \EE_Transaction::status_ID() instead.',
395
-                'event_espresso'
396
-            ),
397
-            '4.9.12'
398
-        );
399
-        return $this->_new_txn_status;
400
-    }
401
-
402
-
403
-    /**
404
-     * @deprecated 4.9.12
405
-     * @param string $new_txn_status
406
-     */
407
-    public function set_new_txn_status($new_txn_status)
408
-    {
409
-        EE_Error::doing_it_wrong(
410
-            __METHOD__,
411
-            esc_html__(
412
-                'This logic has been removed. Please just use \EE_Transaction::set_status() instead.',
413
-                'event_espresso'
414
-            ),
415
-            '4.9.12'
416
-        );
417
-        $this->_new_txn_status = $new_txn_status;
418
-    }
419
-
420
-
421
-    /**
422
-     * @deprecated 4.9.12
423
-     * @return bool
424
-     */
425
-    public function txn_status_updated()
426
-    {
427
-        EE_Error::doing_it_wrong(
428
-            __METHOD__,
429
-            esc_html__(
430
-                'This logic has been moved into \EE_Transaction::txn_status_updated(), please use that method instead.',
431
-                'event_espresso'
432
-            ),
433
-            '4.9.12'
434
-        );
435
-        return $this->_new_txn_status !== $this->_old_txn_status && $this->_old_txn_status !== null ? true : false;
436
-    }
17
+	/**
18
+	 * @var EE_Transaction_Payments $_instance
19
+	 * @access    private
20
+	 */
21
+	private static $_instance;
22
+
23
+	/**
24
+	 * @deprecated
25
+	 * @var string
26
+	 */
27
+	protected $_old_txn_status;
28
+
29
+	/**
30
+	 * @deprecated
31
+	 * @var string
32
+	 */
33
+	protected $_new_txn_status;
34
+
35
+
36
+	/**
37
+	 * @singleton method used to instantiate class object
38
+	 * @access    public
39
+	 * @return EE_Transaction_Payments instance
40
+	 */
41
+	public static function instance()
42
+	{
43
+		// check if class object is instantiated
44
+		if (! self::$_instance instanceof EE_Transaction_Payments) {
45
+			self::$_instance = new self();
46
+		}
47
+		return self::$_instance;
48
+	}
49
+
50
+
51
+	/**
52
+	 * recalculate_transaction_total
53
+	 *
54
+	 * @access private
55
+	 * @param EE_Transaction $transaction
56
+	 * @param bool           $update_txn
57
+	 * @return bool true if TXN total was updated, false if not
58
+	 * @throws \EE_Error
59
+	 */
60
+	public function recalculate_transaction_total(EE_Transaction $transaction, $update_txn = true)
61
+	{
62
+		$total_line_item = $transaction->total_line_item();
63
+		if (! $total_line_item instanceof EE_Line_Item) {
64
+			EE_Error::add_error(
65
+				sprintf(
66
+					esc_html__('The Total Line Item for Transaction %1$d\'s was not found or is invalid.', 'event_espresso'),
67
+					$transaction->ID()
68
+				),
69
+				__FILE__,
70
+				__FUNCTION__,
71
+				__LINE__
72
+			);
73
+			return false;
74
+		}
75
+		$new_total = $total_line_item->recalculate_total_including_taxes();
76
+		$transaction->set_total($new_total);
77
+		if ($update_txn) {
78
+			return $transaction->save() ? true : false;
79
+		}
80
+		return false;
81
+	}
82
+
83
+
84
+	/**
85
+	 * Updates the provided EE_Transaction with all the applicable payments
86
+	 * returns a boolean for whether the TXN was saved to the db
87
+	 * (meaning a status change occurred)
88
+	 * or not saved (which could **still** mean that
89
+	 * the TXN status changed, but just was not yet saved).
90
+	 * So if passing a value of false for the $update_txn param,
91
+	 * then client code needs to take responsibility for saving the TXN
92
+	 * regardless of what happens within EE_Transaction_Payments;
93
+	 *
94
+	 * @param            EE_Transaction /int $transaction_obj_or_id EE_Transaction or its ID
95
+	 * @param    boolean $update_txn whether to save the TXN
96
+	 * @return    boolean        whether the TXN was saved
97
+	 * @throws \EE_Error
98
+	 */
99
+	public function calculate_total_payments_and_update_status(EE_Transaction $transaction, $update_txn = true)
100
+	{
101
+		// verify transaction
102
+		if (! $transaction instanceof EE_Transaction) {
103
+			EE_Error::add_error(
104
+				esc_html__('Please provide a valid EE_Transaction object.', 'event_espresso'),
105
+				__FILE__,
106
+				__FUNCTION__,
107
+				__LINE__
108
+			);
109
+			return false;
110
+		}
111
+		// calculate total paid
112
+		$total_paid = $this->recalculate_total_payments_for_transaction($transaction);
113
+		// if total paid has changed
114
+		if ($total_paid !== false && (float) $total_paid !== $transaction->paid()) {
115
+			$transaction->set_paid($total_paid);
116
+			// maybe update status, and make sure to save transaction if not done already
117
+			if (! $transaction->update_status_based_on_total_paid($update_txn)) {
118
+				if ($update_txn) {
119
+					return $transaction->save() ? true : false;
120
+				}
121
+			} else {
122
+				// the status got updated and was saved by
123
+				// update_transaction_status_based_on_total_paid()
124
+				return true;
125
+			}
126
+		}
127
+		return false;
128
+	}
129
+
130
+
131
+	/**
132
+	 * recalculate_total_payments_for_transaction
133
+	 *
134
+	 * @access public
135
+	 * @param EE_Transaction $transaction
136
+	 * @param string         $payment_status One of EEM_Payment's statuses, like 'PAP' (Approved).
137
+	 *                                       By default, searches for approved payments
138
+	 * @return float|false   float on success, false on fail
139
+	 * @throws \EE_Error
140
+	 */
141
+	public function recalculate_total_payments_for_transaction(
142
+		EE_Transaction $transaction,
143
+		$payment_status = EEM_Payment::status_id_approved
144
+	) {
145
+		// verify transaction
146
+		if (! $transaction instanceof EE_Transaction) {
147
+			EE_Error::add_error(
148
+				esc_html__('Please provide a valid EE_Transaction object.', 'event_espresso'),
149
+				__FILE__,
150
+				__FUNCTION__,
151
+				__LINE__
152
+			);
153
+			return false;
154
+		}
155
+		// ensure Payment model is loaded
156
+		EE_Registry::instance()->load_model('Payment');
157
+		// calls EEM_Base::sum()
158
+		return EEM_Payment::instance()->sum(
159
+			// query params
160
+			array(array('TXN_ID' => $transaction->ID(), 'STS_ID' => $payment_status)),
161
+			// field to sum
162
+			'PAY_amount'
163
+		);
164
+	}
165
+
166
+
167
+	/**
168
+	 * delete_payment_and_update_transaction
169
+	 * Before deleting the selected payment, we fetch it's transaction,
170
+	 * then delete the payment, and update the transactions' amount paid.
171
+	 *
172
+	 * @param EE_Payment $payment
173
+	 * @return boolean
174
+	 * @throws \EE_Error
175
+	 */
176
+	public function delete_payment_and_update_transaction(EE_Payment $payment)
177
+	{
178
+		// verify payment
179
+		if (! $payment instanceof EE_Payment) {
180
+			EE_Error::add_error(
181
+				esc_html__('A valid Payment object was not received.', 'event_espresso'),
182
+				__FILE__,
183
+				__FUNCTION__,
184
+				__LINE__
185
+			);
186
+			return false;
187
+		}
188
+		if (! $this->delete_registration_payments_and_update_registrations($payment)) {
189
+			return false;
190
+		}
191
+		if (! $payment->delete()) {
192
+			EE_Error::add_error(
193
+				esc_html__('The payment could not be deleted.', 'event_espresso'),
194
+				__FILE__,
195
+				__FUNCTION__,
196
+				__LINE__
197
+			);
198
+			return false;
199
+		}
200
+
201
+		$transaction = $payment->transaction();
202
+		$TXN_status = $transaction->status_ID();
203
+		if (
204
+			$TXN_status === EEM_Transaction::abandoned_status_code
205
+			|| $TXN_status === EEM_Transaction::failed_status_code
206
+			|| $payment->amount() === 0
207
+		) {
208
+			EE_Error::add_success(esc_html__('The Payment was successfully deleted.', 'event_espresso'));
209
+			return true;
210
+		}
211
+
212
+
213
+		// if this fails, that just means that the transaction didn't get its status changed and/or updated.
214
+		// however the payment was still deleted.
215
+		if (! $this->calculate_total_payments_and_update_status($transaction)) {
216
+			EE_Error::add_attention(
217
+				esc_html__(
218
+					'It appears that the Payment was deleted but no change was recorded for the Transaction for an unknown reason. Please verify that all data for this Transaction looks correct..',
219
+					'event_espresso'
220
+				),
221
+				__FILE__,
222
+				__FUNCTION__,
223
+				__LINE__
224
+			);
225
+			return true;
226
+		}
227
+
228
+		EE_Error::add_success(
229
+			esc_html__(
230
+				'The Payment was successfully deleted, and the Transaction has been updated accordingly.',
231
+				'event_espresso'
232
+			)
233
+		);
234
+		return true;
235
+	}
236
+
237
+
238
+	/**
239
+	 * delete_registration_payments_and_update_registrations
240
+	 *
241
+	 * removes all registration payment records associated with a payment
242
+	 * and subtracts their amounts from the corresponding registrations REG_paid field
243
+	 *
244
+	 * @param EE_Payment $payment
245
+	 * @param array      $reg_payment_query_params
246
+	 * @return bool
247
+	 * @throws \EE_Error
248
+	 */
249
+	public function delete_registration_payments_and_update_registrations(
250
+		EE_Payment $payment,
251
+		$reg_payment_query_params = array()
252
+	) {
253
+		$save_payment = false;
254
+		$reg_payment_query_params = ! empty($reg_payment_query_params) ? $reg_payment_query_params
255
+			: array(array('PAY_ID' => $payment->ID()));
256
+		$registration_payments = EEM_Registration_Payment::instance()->get_all($reg_payment_query_params);
257
+		if (! empty($registration_payments)) {
258
+			foreach ($registration_payments as $registration_payment) {
259
+				if ($registration_payment instanceof EE_Registration_Payment) {
260
+					$amount_paid = $registration_payment->amount();
261
+					$registration = $registration_payment->registration();
262
+					if ($registration instanceof EE_Registration) {
263
+						$registration->set_paid($registration->paid() - $amount_paid);
264
+						if ($registration->save() !== false) {
265
+							$registration_payment->delete_permanently();
266
+							$save_payment = true;
267
+						}
268
+					} else {
269
+						EE_Error::add_error(
270
+							sprintf(
271
+								esc_html__(
272
+									'An invalid Registration object was associated with Registration Payment ID# %1$d.',
273
+									'event_espresso'
274
+								),
275
+								$registration_payment->ID()
276
+							),
277
+							__FILE__,
278
+							__FUNCTION__,
279
+							__LINE__
280
+						);
281
+						return false;
282
+					}
283
+				} else {
284
+					EE_Error::add_error(
285
+						sprintf(
286
+							esc_html__(
287
+								'An invalid Registration Payment object was associated with payment ID# %1$d.',
288
+								'event_espresso'
289
+							),
290
+							$payment->ID()
291
+						),
292
+						__FILE__,
293
+						__FUNCTION__,
294
+						__LINE__
295
+					);
296
+					return false;
297
+				}
298
+			}
299
+		}
300
+		if ($save_payment) {
301
+			$payment->save();
302
+		}
303
+		return true;
304
+	}
305
+
306
+
307
+
308
+	/********************************** DEPRECATED METHODS **********************************/
309
+
310
+
311
+	/**
312
+	 * possibly toggles TXN status
313
+	 *
314
+	 * @deprecated 4.9.1
315
+	 * @param EE_Transaction $transaction
316
+	 * @param    boolean     $update_txn whether to save the TXN
317
+	 * @return    boolean        whether the TXN was saved
318
+	 * @throws \EE_Error
319
+	 */
320
+	public function update_transaction_status_based_on_total_paid(EE_Transaction $transaction, $update_txn = true)
321
+	{
322
+		EE_Error::doing_it_wrong(
323
+			__CLASS__ . '::' . __FUNCTION__,
324
+			sprintf(
325
+				esc_html__('This method is deprecated. Please use "%s" instead', 'event_espresso'),
326
+				'EE_Transaction::update_status_based_on_total_paid()'
327
+			),
328
+			'4.9.1',
329
+			'5.0.0'
330
+		);
331
+		// verify transaction
332
+		if (! $transaction instanceof EE_Transaction) {
333
+			EE_Error::add_error(
334
+				esc_html__('Please provide a valid EE_Transaction object.', 'event_espresso'),
335
+				__FILE__,
336
+				__FUNCTION__,
337
+				__LINE__
338
+			);
339
+			return false;
340
+		}
341
+		// set transaction status based on comparison of TXN_paid vs TXN_total
342
+		return $transaction->update_status_based_on_total_paid($update_txn);
343
+	}
344
+
345
+
346
+	/**
347
+	 * @deprecated 4.9.12
348
+	 * @return string
349
+	 */
350
+	public function old_txn_status()
351
+	{
352
+		EE_Error::doing_it_wrong(
353
+			__METHOD__,
354
+			esc_html__(
355
+				'This logic has been moved into \EE_Transaction::old_txn_status(), please use that method instead.',
356
+				'event_espresso'
357
+			),
358
+			'4.9.12'
359
+		);
360
+		return $this->_old_txn_status;
361
+	}
362
+
363
+
364
+	/**
365
+	 * @deprecated 4.9.12
366
+	 * @param string $old_txn_status
367
+	 */
368
+	public function set_old_txn_status($old_txn_status)
369
+	{
370
+		EE_Error::doing_it_wrong(
371
+			__METHOD__,
372
+			esc_html__(
373
+				'This logic has been moved into \EE_Transaction::set_old_txn_status(), please use that method instead.',
374
+				'event_espresso'
375
+			),
376
+			'4.9.12'
377
+		);
378
+		// only set the first time
379
+		if ($this->_old_txn_status === null) {
380
+			$this->_old_txn_status = $old_txn_status;
381
+		}
382
+	}
383
+
384
+
385
+	/**
386
+	 * @deprecated 4.9.12
387
+	 * @return string
388
+	 */
389
+	public function new_txn_status()
390
+	{
391
+		EE_Error::doing_it_wrong(
392
+			__METHOD__,
393
+			esc_html__(
394
+				'This logic has been removed. Please just use \EE_Transaction::status_ID() instead.',
395
+				'event_espresso'
396
+			),
397
+			'4.9.12'
398
+		);
399
+		return $this->_new_txn_status;
400
+	}
401
+
402
+
403
+	/**
404
+	 * @deprecated 4.9.12
405
+	 * @param string $new_txn_status
406
+	 */
407
+	public function set_new_txn_status($new_txn_status)
408
+	{
409
+		EE_Error::doing_it_wrong(
410
+			__METHOD__,
411
+			esc_html__(
412
+				'This logic has been removed. Please just use \EE_Transaction::set_status() instead.',
413
+				'event_espresso'
414
+			),
415
+			'4.9.12'
416
+		);
417
+		$this->_new_txn_status = $new_txn_status;
418
+	}
419
+
420
+
421
+	/**
422
+	 * @deprecated 4.9.12
423
+	 * @return bool
424
+	 */
425
+	public function txn_status_updated()
426
+	{
427
+		EE_Error::doing_it_wrong(
428
+			__METHOD__,
429
+			esc_html__(
430
+				'This logic has been moved into \EE_Transaction::txn_status_updated(), please use that method instead.',
431
+				'event_espresso'
432
+			),
433
+			'4.9.12'
434
+		);
435
+		return $this->_new_txn_status !== $this->_old_txn_status && $this->_old_txn_status !== null ? true : false;
436
+	}
437 437
 }
Please login to merge, or discard this patch.
services/admin/registrations/list_table/page_header/TicketFilterHeader.php 2 patches
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -59,9 +59,9 @@  discard block
 block discarded – undo
59 59
         if ($TKT_ID) {
60 60
             $ticket = $this->ticket_model->get_one_by_ID($TKT_ID);
61 61
             if ($ticket instanceof EE_Ticket) {
62
-                $ticket_details = '<span class="ee-ticket-name">' . $ticket->name() . '</span> ';
62
+                $ticket_details = '<span class="ee-ticket-name">'.$ticket->name().'</span> ';
63 63
                 $ticket_details .= ! $ticket->is_free()
64
-                    ? '<span class="ee-ticket-price">' . $ticket->pretty_price() . '</span>'
64
+                    ? '<span class="ee-ticket-price">'.$ticket->pretty_price().'</span>'
65 65
                     : '<span class="reg-overview-free-event-spn">'
66 66
                       . esc_html__('free', 'event_espresso')
67 67
                       . '</span>';
@@ -78,7 +78,7 @@  discard block
 block discarded – undo
78 78
                 $text .= '&nbsp; &nbsp; ';
79 79
                 $text .= '<span class="drk-grey-text" style="font-size:.9em;">';
80 80
                 $text .= '<span class="dashicons dashicons-tickets-alt"></span>';
81
-                $text .= $ticket_details . '</span></h3>';
81
+                $text .= $ticket_details.'</span></h3>';
82 82
             }
83 83
         }
84 84
         return $text;
Please login to merge, or discard this patch.
Indentation   +56 added lines, -56 removed lines patch added patch discarded remove patch
@@ -22,64 +22,64 @@
 block discarded – undo
22 22
  */
23 23
 class TicketFilterHeader extends AdminPageHeaderDecorator
24 24
 {
25
-    /**
26
-     * @var EEM_Ticket $ticket_model
27
-     */
28
-    private $ticket_model;
25
+	/**
26
+	 * @var EEM_Ticket $ticket_model
27
+	 */
28
+	private $ticket_model;
29 29
 
30 30
 
31
-    /**
32
-     * TicketFilterHeader constructor.
33
-     *
34
-     * @param RequestInterface $request
35
-     * @param EEM_Ticket       $ticket_model
36
-     */
37
-    public function __construct(RequestInterface $request, EEM_Ticket $ticket_model)
38
-    {
39
-        parent::__construct($request);
40
-        $this->ticket_model = $ticket_model;
41
-    }
31
+	/**
32
+	 * TicketFilterHeader constructor.
33
+	 *
34
+	 * @param RequestInterface $request
35
+	 * @param EEM_Ticket       $ticket_model
36
+	 */
37
+	public function __construct(RequestInterface $request, EEM_Ticket $ticket_model)
38
+	{
39
+		parent::__construct($request);
40
+		$this->ticket_model = $ticket_model;
41
+	}
42 42
 
43 43
 
44
-    /**
45
-     * @param string $text
46
-     * @return string
47
-     * @throws EE_Error
48
-     * @throws InvalidDataTypeException
49
-     * @throws InvalidInterfaceException
50
-     * @throws InvalidArgumentException
51
-     * @throws ReflectionException
52
-     * @since 4.10.2.p
53
-     */
54
-    public function getHeaderText($text = '')
55
-    {
56
-        $TKT_ID = $this->request->getRequestParam('TKT_ID');
57
-        $TKT_ID = $this->request->getRequestParam('ticket_id', $TKT_ID, 'int');
58
-        if ($TKT_ID) {
59
-            $ticket = $this->ticket_model->get_one_by_ID($TKT_ID);
60
-            if ($ticket instanceof EE_Ticket) {
61
-                $ticket_details = '<span class="ee-ticket-name">' . $ticket->name() . '</span> ';
62
-                $ticket_details .= ! $ticket->is_free()
63
-                    ? '<span class="ee-ticket-price">' . $ticket->pretty_price() . '</span>'
64
-                    : '<span class="reg-overview-free-event-spn">'
65
-                      . esc_html__('free', 'event_espresso')
66
-                      . '</span>';
67
-                // remove the closing h3 heading tag if it exists
68
-                $text = str_replace(
69
-                    '</h3>',
70
-                    '',
71
-                    $text
72
-                );
73
-                if (empty($text)) {
74
-                    $text = '<h3 style="line-height:1.5em;">';
75
-                    $text .= esc_html__('Viewing registrations for ticket:', 'event_espresso');
76
-                }
77
-                $text .= '&nbsp; &nbsp; ';
78
-                $text .= '<span class="drk-grey-text" style="font-size:.9em;">';
79
-                $text .= '<span class="dashicons dashicons-tickets-alt"></span>';
80
-                $text .= $ticket_details . '</span></h3>';
81
-            }
82
-        }
83
-        return $text;
84
-    }
44
+	/**
45
+	 * @param string $text
46
+	 * @return string
47
+	 * @throws EE_Error
48
+	 * @throws InvalidDataTypeException
49
+	 * @throws InvalidInterfaceException
50
+	 * @throws InvalidArgumentException
51
+	 * @throws ReflectionException
52
+	 * @since 4.10.2.p
53
+	 */
54
+	public function getHeaderText($text = '')
55
+	{
56
+		$TKT_ID = $this->request->getRequestParam('TKT_ID');
57
+		$TKT_ID = $this->request->getRequestParam('ticket_id', $TKT_ID, 'int');
58
+		if ($TKT_ID) {
59
+			$ticket = $this->ticket_model->get_one_by_ID($TKT_ID);
60
+			if ($ticket instanceof EE_Ticket) {
61
+				$ticket_details = '<span class="ee-ticket-name">' . $ticket->name() . '</span> ';
62
+				$ticket_details .= ! $ticket->is_free()
63
+					? '<span class="ee-ticket-price">' . $ticket->pretty_price() . '</span>'
64
+					: '<span class="reg-overview-free-event-spn">'
65
+					  . esc_html__('free', 'event_espresso')
66
+					  . '</span>';
67
+				// remove the closing h3 heading tag if it exists
68
+				$text = str_replace(
69
+					'</h3>',
70
+					'',
71
+					$text
72
+				);
73
+				if (empty($text)) {
74
+					$text = '<h3 style="line-height:1.5em;">';
75
+					$text .= esc_html__('Viewing registrations for ticket:', 'event_espresso');
76
+				}
77
+				$text .= '&nbsp; &nbsp; ';
78
+				$text .= '<span class="drk-grey-text" style="font-size:.9em;">';
79
+				$text .= '<span class="dashicons dashicons-tickets-alt"></span>';
80
+				$text .= $ticket_details . '</span></h3>';
81
+			}
82
+		}
83
+		return $text;
84
+	}
85 85
 }
Please login to merge, or discard this patch.