Completed
Branch BUG-9951-10331-8793-pue-fixes (40e696)
by
unknown
27:52 queued 13:57
created
core/db_classes/EE_Base_Class.class.php 1 patch
Indentation   +2650 added lines, -2650 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php if ( ! defined('EVENT_ESPRESSO_VERSION')) {
2
-    exit('No direct script access allowed');
2
+	exit('No direct script access allowed');
3 3
 }
4 4
 do_action('AHEE_log', __FILE__, ' FILE LOADED', '');
5 5
 
@@ -25,2655 +25,2655 @@  discard block
 block discarded – undo
25 25
 abstract class EE_Base_Class
26 26
 {
27 27
 
28
-    /**
29
-     * This is an array of the original properties and values provided during construction
30
-     * of this model object. (keys are model field names, values are their values).
31
-     * This list is important to remember so that when we are merging data from the db, we know
32
-     * which values to override and which to not override.
33
-     *
34
-     * @var array
35
-     */
36
-    protected $_props_n_values_provided_in_constructor;
37
-
38
-    /**
39
-     * Timezone
40
-     * This gets set by the "set_timezone()" method so that we know what timezone incoming strings|timestamps are in.
41
-     * This can also be used before a get to set what timezone you want strings coming out of the object to be in.  NOT
42
-     * all EE_Base_Class child classes use this property but any that use a EE_Datetime_Field data type will have
43
-     * access to it.
44
-     *
45
-     * @var string
46
-     */
47
-    protected $_timezone;
48
-
49
-
50
-
51
-    /**
52
-     * date format
53
-     * pattern or format for displaying dates
54
-     *
55
-     * @var string $_dt_frmt
56
-     */
57
-    protected $_dt_frmt;
58
-
59
-
60
-
61
-    /**
62
-     * time format
63
-     * pattern or format for displaying time
64
-     *
65
-     * @var string $_tm_frmt
66
-     */
67
-    protected $_tm_frmt;
68
-
69
-
70
-
71
-    /**
72
-     * This property is for holding a cached array of object properties indexed by property name as the key.
73
-     * The purpose of this is for setting a cache on properties that may have calculated values after a
74
-     * prepare_for_get.  That way the cache can be checked first and the calculated property returned instead of having
75
-     * to recalculate. Used by _set_cached_property() and _get_cached_property() methods.
76
-     *
77
-     * @var array
78
-     */
79
-    protected $_cached_properties = array();
80
-
81
-    /**
82
-     * An array containing keys of the related model, and values are either an array of related mode objects or a
83
-     * single
84
-     * related model object. see the model's _model_relations. The keys should match those specified. And if the
85
-     * relation is of type EE_Belongs_To (or one of its children), then there should only be ONE related model object,
86
-     * all others have an array)
87
-     *
88
-     * @var array
89
-     */
90
-    protected $_model_relations = array();
91
-
92
-    /**
93
-     * Array where keys are field names (see the model's _fields property) and values are their values. To see what
94
-     * their types should be, look at what that field object returns on its prepare_for_get and prepare_for_set methods)
95
-     *
96
-     * @var array
97
-     */
98
-    protected $_fields = array();
99
-
100
-    /**
101
-     * @var boolean indicating whether or not this model object is intended to ever be saved
102
-     * For example, we might create model objects intended to only be used for the duration
103
-     * of this request and to be thrown away, and if they were accidentally saved
104
-     * it would be a bug.
105
-     */
106
-    protected $_allow_persist = true;
107
-
108
-
109
-
110
-    /**
111
-     * basic constructor for Event Espresso classes, performs any necessary initialization, and verifies it's children
112
-     * play nice
113
-     *
114
-     * @param array   $fieldValues                             where each key is a field (ie, array key in the 2nd
115
-     *                                                         layer of the model's _fields array, (eg, EVT_ID,
116
-     *                                                         TXN_amount, QST_name, etc) and values are their values
117
-     * @param boolean $bydb                                    a flag for setting if the class is instantiated by the
118
-     *                                                         corresponding db model or not.
119
-     * @param string  $timezone                                indicate what timezone you want any datetime fields to
120
-     *                                                         be in when instantiating a EE_Base_Class object.
121
-     * @param array   $date_formats                            An array of date formats to set on construct where first
122
-     *                                                         value is the date_format and second value is the time
123
-     *                                                         format.
124
-     * @throws EE_Error
125
-     */
126
-    protected function __construct($fieldValues = array(), $bydb = false, $timezone = '', $date_formats = array())
127
-    {
128
-        $className = get_class($this);
129
-        do_action("AHEE__{$className}__construct", $this, $fieldValues);
130
-        $model = $this->get_model();
131
-        $model_fields = $model->field_settings(false);
132
-        // ensure $fieldValues is an array
133
-        $fieldValues = is_array($fieldValues) ? $fieldValues : array($fieldValues);
134
-        // EEH_Debug_Tools::printr( $fieldValues, '$fieldValues  <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' );
135
-        // verify client code has not passed any invalid field names
136
-        foreach ($fieldValues as $field_name => $field_value) {
137
-            if ( ! isset($model_fields[$field_name])) {
138
-                throw new EE_Error(sprintf(__("Invalid field (%s) passed to constructor of %s. Allowed fields are :%s",
139
-                    "event_espresso"), $field_name, get_class($this), implode(", ", array_keys($model_fields))));
140
-            }
141
-        }
142
-        // EEH_Debug_Tools::printr( $model_fields, '$model_fields  <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' );
143
-        $this->_timezone = EEH_DTT_Helper::get_valid_timezone_string($timezone);
144
-        if ( ! empty($date_formats) && is_array($date_formats)) {
145
-            list($this->_dt_frmt, $this->_tm_frmt) = $date_formats;
146
-        } else {
147
-            //set default formats for date and time
148
-            $this->_dt_frmt = (string)get_option('date_format', 'Y-m-d');
149
-            $this->_tm_frmt = (string)get_option('time_format', 'g:i a');
150
-        }
151
-        //if db model is instantiating
152
-        if ($bydb) {
153
-            //client code has indicated these field values are from the database
154
-            foreach ($model_fields as $fieldName => $field) {
155
-                $this->set_from_db($fieldName, isset($fieldValues[$fieldName]) ? $fieldValues[$fieldName] : null);
156
-            }
157
-        } else {
158
-            //we're constructing a brand
159
-            //new instance of the model object. Generally, this means we'll need to do more field validation
160
-            foreach ($model_fields as $fieldName => $field) {
161
-                $this->set($fieldName, isset($fieldValues[$fieldName]) ? $fieldValues[$fieldName] : null, true);
162
-            }
163
-        }
164
-        //remember what values were passed to this constructor
165
-        $this->_props_n_values_provided_in_constructor = $fieldValues;
166
-        //remember in entity mapper
167
-        if ( ! $bydb && $model->has_primary_key_field() && $this->ID()) {
168
-            $model->add_to_entity_map($this);
169
-        }
170
-        //setup all the relations
171
-        foreach ($this->get_model()->relation_settings() as $relation_name => $relation_obj) {
172
-            if ($relation_obj instanceof EE_Belongs_To_Relation) {
173
-                $this->_model_relations[$relation_name] = null;
174
-            } else {
175
-                $this->_model_relations[$relation_name] = array();
176
-            }
177
-        }
178
-        /**
179
-         * Action done at the end of each model object construction
180
-         *
181
-         * @param EE_Base_Class $this the model object just created
182
-         */
183
-        do_action('AHEE__EE_Base_Class__construct__finished', $this);
184
-    }
185
-
186
-
187
-
188
-    /**
189
-     * Gets whether or not this model object is allowed to persist/be saved to the database.
190
-     *
191
-     * @return boolean
192
-     */
193
-    public function allow_persist()
194
-    {
195
-        return $this->_allow_persist;
196
-    }
197
-
198
-
199
-
200
-    /**
201
-     * Sets whether or not this model object should be allowed to be saved to the DB.
202
-     * Normally once this is set to FALSE you wouldn't set it back to TRUE, unless
203
-     * you got new information that somehow made you change your mind.
204
-     *
205
-     * @param boolean $allow_persist
206
-     * @return boolean
207
-     */
208
-    public function set_allow_persist($allow_persist)
209
-    {
210
-        return $this->_allow_persist = $allow_persist;
211
-    }
212
-
213
-
214
-
215
-    /**
216
-     * Gets the field's original value when this object was constructed during this request.
217
-     * This can be helpful when determining if a model object has changed or not
218
-     *
219
-     * @param string $field_name
220
-     * @return mixed|null
221
-     * @throws \EE_Error
222
-     */
223
-    public function get_original($field_name)
224
-    {
225
-        if (isset($this->_props_n_values_provided_in_constructor[$field_name])
226
-            && $field_settings = $this->get_model()->field_settings_for($field_name)
227
-        ) {
228
-            return $field_settings->prepare_for_get($this->_props_n_values_provided_in_constructor[$field_name]);
229
-        } else {
230
-            return null;
231
-        }
232
-    }
233
-
234
-
235
-
236
-    /**
237
-     * @param EE_Base_Class $obj
238
-     * @return string
239
-     */
240
-    public function get_class($obj)
241
-    {
242
-        return get_class($obj);
243
-    }
244
-
245
-
246
-
247
-    /**
248
-     * Overrides parent because parent expects old models.
249
-     * This also doesn't do any validation, and won't work for serialized arrays
250
-     *
251
-     * @param    string $field_name
252
-     * @param    mixed  $field_value
253
-     * @param bool      $use_default
254
-     * @throws \EE_Error
255
-     */
256
-    public function set($field_name, $field_value, $use_default = false)
257
-    {
258
-        $field_obj = $this->get_model()->field_settings_for($field_name);
259
-        if ($field_obj instanceof EE_Model_Field_Base) {
260
-            //			if ( method_exists( $field_obj, 'set_timezone' )) {
261
-            if ($field_obj instanceof EE_Datetime_Field) {
262
-                $field_obj->set_timezone($this->_timezone);
263
-                $field_obj->set_date_format($this->_dt_frmt);
264
-                $field_obj->set_time_format($this->_tm_frmt);
265
-            }
266
-            $holder_of_value = $field_obj->prepare_for_set($field_value);
267
-            //should the value be null?
268
-            if (($field_value === null || $holder_of_value === null || $holder_of_value === '') && $use_default) {
269
-                $this->_fields[$field_name] = $field_obj->get_default_value();
270
-                /**
271
-                 * To save having to refactor all the models, if a default value is used for a
272
-                 * EE_Datetime_Field, and that value is not null nor is it a DateTime
273
-                 * object.  Then let's do a set again to ensure that it becomes a DateTime
274
-                 * object.
275
-                 *
276
-                 * @since 4.6.10+
277
-                 */
278
-                if (
279
-                    $field_obj instanceof EE_Datetime_Field
280
-                    && $this->_fields[$field_name] !== null
281
-                    && ! $this->_fields[$field_name] instanceof DateTime
282
-                ) {
283
-                    empty($this->_fields[$field_name])
284
-                        ? $this->set($field_name, time())
285
-                        : $this->set($field_name, $this->_fields[$field_name]);
286
-                }
287
-            } else {
288
-                $this->_fields[$field_name] = $holder_of_value;
289
-            }
290
-            //if we're not in the constructor...
291
-            //now check if what we set was a primary key
292
-            if (
293
-                //note: props_n_values_provided_in_constructor is only set at the END of the constructor
294
-                $this->_props_n_values_provided_in_constructor
295
-                && $field_value
296
-                && $field_name === self::_get_primary_key_name(get_class($this))
297
-            ) {
298
-                //if so, we want all this object's fields to be filled either with
299
-                //what we've explicitly set on this model
300
-                //or what we have in the db
301
-                // echo "setting primary key!";
302
-                $fields_on_model = self::_get_model(get_class($this))->field_settings();
303
-                $obj_in_db = self::_get_model(get_class($this))->get_one_by_ID($field_value);
304
-                foreach ($fields_on_model as $field_obj) {
305
-                    if ( ! array_key_exists($field_obj->get_name(), $this->_props_n_values_provided_in_constructor)
306
-                         && $field_obj->get_name() !== $field_name
307
-                    ) {
308
-                        $this->set($field_obj->get_name(), $obj_in_db->get($field_obj->get_name()));
309
-                    }
310
-                }
311
-                //oh this model object has an ID? well make sure its in the entity mapper
312
-                $this->get_model()->add_to_entity_map($this);
313
-            }
314
-            //let's unset any cache for this field_name from the $_cached_properties property.
315
-            $this->_clear_cached_property($field_name);
316
-        } else {
317
-            throw new EE_Error(sprintf(__("A valid EE_Model_Field_Base could not be found for the given field name: %s",
318
-                "event_espresso"), $field_name));
319
-        }
320
-    }
321
-
322
-
323
-
324
-    /**
325
-     * This sets the field value on the db column if it exists for the given $column_name or
326
-     * saves it to EE_Extra_Meta if the given $column_name does not match a db column.
327
-     *
328
-     * @see EE_message::get_column_value for related documentation on the necessity of this method.
329
-     * @param string $field_name  Must be the exact column name.
330
-     * @param mixed  $field_value The value to set.
331
-     * @return int|bool @see EE_Base_Class::update_extra_meta() for return docs.
332
-     * @throws \EE_Error
333
-     */
334
-    public function set_field_or_extra_meta($field_name, $field_value)
335
-    {
336
-        if ($this->get_model()->has_field($field_name)) {
337
-            $this->set($field_name, $field_value);
338
-            return true;
339
-        } else {
340
-            //ensure this object is saved first so that extra meta can be properly related.
341
-            $this->save();
342
-            return $this->update_extra_meta($field_name, $field_value);
343
-        }
344
-    }
345
-
346
-
347
-
348
-    /**
349
-     * This retrieves the value of the db column set on this class or if that's not present
350
-     * it will attempt to retrieve from extra_meta if found.
351
-     * Example Usage:
352
-     * Via EE_Message child class:
353
-     * Due to the dynamic nature of the EE_messages system, EE_messengers will always have a "to",
354
-     * "from", "subject", and "content" field (as represented in the EE_Message schema), however they may
355
-     * also have additional main fields specific to the messenger.  The system accommodates those extra
356
-     * fields through the EE_Extra_Meta table.  This method allows for EE_messengers to retrieve the
357
-     * value for those extra fields dynamically via the EE_message object.
358
-     *
359
-     * @param  string $field_name expecting the fully qualified field name.
360
-     * @return mixed|null  value for the field if found.  null if not found.
361
-     * @throws \EE_Error
362
-     */
363
-    public function get_field_or_extra_meta($field_name)
364
-    {
365
-        if ($this->get_model()->has_field($field_name)) {
366
-            $column_value = $this->get($field_name);
367
-        } else {
368
-            //This isn't a column in the main table, let's see if it is in the extra meta.
369
-            $column_value = $this->get_extra_meta($field_name, true, null);
370
-        }
371
-        return $column_value;
372
-    }
373
-
374
-
375
-
376
-    /**
377
-     * See $_timezone property for description of what the timezone property is for.  This SETS the timezone internally
378
-     * for being able to reference what timezone we are running conversions on when converting TO the internal timezone
379
-     * (UTC Unix Timestamp) for the object OR when converting FROM the internal timezone (UTC Unix Timestamp). This is
380
-     * available to all child classes that may be using the EE_Datetime_Field for a field data type.
381
-     *
382
-     * @access public
383
-     * @param string $timezone A valid timezone string as described by @link http://www.php.net/manual/en/timezones.php
384
-     * @return void
385
-     * @throws \EE_Error
386
-     */
387
-    public function set_timezone($timezone = '')
388
-    {
389
-        $this->_timezone = EEH_DTT_Helper::get_valid_timezone_string($timezone);
390
-        //make sure we clear all cached properties because they won't be relevant now
391
-        $this->_clear_cached_properties();
392
-        //make sure we update field settings and the date for all EE_Datetime_Fields
393
-        $model_fields = $this->get_model()->field_settings(false);
394
-        foreach ($model_fields as $field_name => $field_obj) {
395
-            if ($field_obj instanceof EE_Datetime_Field) {
396
-                $field_obj->set_timezone($this->_timezone);
397
-                if (isset($this->_fields[$field_name]) && $this->_fields[$field_name] instanceof DateTime) {
398
-                    $this->_fields[$field_name]->setTimezone(new DateTimeZone($this->_timezone));
399
-                }
400
-            }
401
-        }
402
-    }
403
-
404
-
405
-
406
-    /**
407
-     * This just returns whatever is set for the current timezone.
408
-     *
409
-     * @access public
410
-     * @return string timezone string
411
-     */
412
-    public function get_timezone()
413
-    {
414
-        return $this->_timezone;
415
-    }
416
-
417
-
418
-
419
-    /**
420
-     * This sets the internal date format to what is sent in to be used as the new default for the class
421
-     * internally instead of wp set date format options
422
-     *
423
-     * @since 4.6
424
-     * @param string $format should be a format recognizable by PHP date() functions.
425
-     */
426
-    public function set_date_format($format)
427
-    {
428
-        $this->_dt_frmt = $format;
429
-        //clear cached_properties because they won't be relevant now.
430
-        $this->_clear_cached_properties();
431
-    }
432
-
433
-
434
-
435
-    /**
436
-     * This sets the internal time format string to what is sent in to be used as the new default for the
437
-     * class internally instead of wp set time format options.
438
-     *
439
-     * @since 4.6
440
-     * @param string $format should be a format recognizable by PHP date() functions.
441
-     */
442
-    public function set_time_format($format)
443
-    {
444
-        $this->_tm_frmt = $format;
445
-        //clear cached_properties because they won't be relevant now.
446
-        $this->_clear_cached_properties();
447
-    }
448
-
449
-
450
-
451
-    /**
452
-     * This returns the current internal set format for the date and time formats.
453
-     *
454
-     * @param bool $full           if true (default), then return the full format.  Otherwise will return an array
455
-     *                             where the first value is the date format and the second value is the time format.
456
-     * @return mixed string|array
457
-     */
458
-    public function get_format($full = true)
459
-    {
460
-        return $full ? $this->_dt_frmt . ' ' . $this->_tm_frmt : array($this->_dt_frmt, $this->_tm_frmt);
461
-    }
462
-
463
-
464
-
465
-    /**
466
-     * cache
467
-     * stores the passed model object on the current model object.
468
-     * In certain circumstances, we can use this cached model object instead of querying for another one entirely.
469
-     *
470
-     * @param string        $relationName    one of the keys in the _model_relations array on the model. Eg
471
-     *                                       'Registration' associated with this model object
472
-     * @param EE_Base_Class $object_to_cache that has a relation to this model object. (Eg, if this is a Transaction,
473
-     *                                       that could be a payment or a registration)
474
-     * @param null          $cache_id        a string or number that will be used as the key for any Belongs_To_Many
475
-     *                                       items which will be stored in an array on this object
476
-     * @throws EE_Error
477
-     * @return mixed    index into cache, or just TRUE if the relation is of type Belongs_To (because there's only one
478
-     *                  related thing, no array)
479
-     */
480
-    public function cache($relationName = '', $object_to_cache = null, $cache_id = null)
481
-    {
482
-        // its entirely possible that there IS no related object yet in which case there is nothing to cache.
483
-        if ( ! $object_to_cache instanceof EE_Base_Class) {
484
-            return false;
485
-        }
486
-        // also get "how" the object is related, or throw an error
487
-        if ( ! $relationship_to_model = $this->get_model()->related_settings_for($relationName)) {
488
-            throw new EE_Error(sprintf(__('There is no relationship to %s on a %s. Cannot cache it', 'event_espresso'),
489
-                $relationName, get_class($this)));
490
-        }
491
-        // how many things are related ?
492
-        if ($relationship_to_model instanceof EE_Belongs_To_Relation) {
493
-            // if it's a "belongs to" relationship, then there's only one related model object  eg, if this is a registration, there's only 1 attendee for it
494
-            // so for these model objects just set it to be cached
495
-            $this->_model_relations[$relationName] = $object_to_cache;
496
-            $return = true;
497
-        } else {
498
-            // otherwise, this is the "many" side of a one to many relationship, so we'll add the object to the array of related objects for that type.
499
-            // eg: if this is an event, there are many registrations for that event, so we cache the registrations in an array
500
-            if ( ! is_array($this->_model_relations[$relationName])) {
501
-                // if for some reason, the cached item is a model object, then stick that in the array, otherwise start with an empty array
502
-                $this->_model_relations[$relationName] = $this->_model_relations[$relationName] instanceof EE_Base_Class
503
-                    ? array($this->_model_relations[$relationName]) : array();
504
-            }
505
-            // first check for a cache_id which is normally empty
506
-            if ( ! empty($cache_id)) {
507
-                // if the cache_id exists, then it means we are purposely trying to cache this with a known key that can then be used to retrieve the object later on
508
-                $this->_model_relations[$relationName][$cache_id] = $object_to_cache;
509
-                $return = $cache_id;
510
-            } elseif ($object_to_cache->ID()) {
511
-                // OR the cached object originally came from the db, so let's just use it's PK for an ID
512
-                $this->_model_relations[$relationName][$object_to_cache->ID()] = $object_to_cache;
513
-                $return = $object_to_cache->ID();
514
-            } else {
515
-                // OR it's a new object with no ID, so just throw it in the array with an auto-incremented ID
516
-                $this->_model_relations[$relationName][] = $object_to_cache;
517
-                // move the internal pointer to the end of the array
518
-                end($this->_model_relations[$relationName]);
519
-                // and grab the key so that we can return it
520
-                $return = key($this->_model_relations[$relationName]);
521
-            }
522
-        }
523
-        return $return;
524
-    }
525
-
526
-
527
-
528
-    /**
529
-     * For adding an item to the cached_properties property.
530
-     *
531
-     * @access protected
532
-     * @param string      $fieldname the property item the corresponding value is for.
533
-     * @param mixed       $value     The value we are caching.
534
-     * @param string|null $cache_type
535
-     * @return void
536
-     * @throws \EE_Error
537
-     */
538
-    protected function _set_cached_property($fieldname, $value, $cache_type = null)
539
-    {
540
-        //first make sure this property exists
541
-        $this->get_model()->field_settings_for($fieldname);
542
-        $cache_type = empty($cache_type) ? 'standard' : $cache_type;
543
-        $this->_cached_properties[$fieldname][$cache_type] = $value;
544
-    }
545
-
546
-
547
-
548
-    /**
549
-     * This returns the value cached property if it exists OR the actual property value if the cache doesn't exist.
550
-     * This also SETS the cache if we return the actual property!
551
-     *
552
-     * @param string $fieldname        the name of the property we're trying to retrieve
553
-     * @param bool   $pretty
554
-     * @param string $extra_cache_ref  This allows the user to specify an extra cache ref for the given property
555
-     *                                 (in cases where the same property may be used for different outputs
556
-     *                                 - i.e. datetime, money etc.)
557
-     *                                 It can also accept certain pre-defined "schema" strings
558
-     *                                 to define how to output the property.
559
-     *                                 see the field's prepare_for_pretty_echoing for what strings can be used
560
-     * @return mixed                   whatever the value for the property is we're retrieving
561
-     * @throws \EE_Error
562
-     */
563
-    protected function _get_cached_property($fieldname, $pretty = false, $extra_cache_ref = null)
564
-    {
565
-        //verify the field exists
566
-        $this->get_model()->field_settings_for($fieldname);
567
-        $cache_type = $pretty ? 'pretty' : 'standard';
568
-        $cache_type .= ! empty($extra_cache_ref) ? '_' . $extra_cache_ref : '';
569
-        if (isset($this->_cached_properties[$fieldname][$cache_type])) {
570
-            return $this->_cached_properties[$fieldname][$cache_type];
571
-        }
572
-        $field_obj = $this->get_model()->field_settings_for($fieldname);
573
-        if ($field_obj instanceof EE_Model_Field_Base) {
574
-            // If this is an EE_Datetime_Field we need to make sure timezone, formats, and output are correct
575
-            if ($field_obj instanceof EE_Datetime_Field) {
576
-                $this->_prepare_datetime_field($field_obj, $pretty, $extra_cache_ref);
577
-            }
578
-            if ( ! isset($this->_fields[$fieldname])) {
579
-                $this->_fields[$fieldname] = null;
580
-            }
581
-            $value = $pretty
582
-                ? $field_obj->prepare_for_pretty_echoing($this->_fields[$fieldname], $extra_cache_ref)
583
-                : $field_obj->prepare_for_get($this->_fields[$fieldname]);
584
-            $this->_set_cached_property($fieldname, $value, $cache_type);
585
-            return $value;
586
-        }
587
-        return null;
588
-    }
589
-
590
-
591
-
592
-    /**
593
-     * set timezone, formats, and output for EE_Datetime_Field objects
594
-     *
595
-     * @param \EE_Datetime_Field $datetime_field
596
-     * @param bool               $pretty
597
-     * @param null $date_or_time
598
-     * @return void
599
-     * @throws \EE_Error
600
-     */
601
-    protected function _prepare_datetime_field(
602
-        EE_Datetime_Field $datetime_field,
603
-        $pretty = false,
604
-        $date_or_time = null
605
-    ) {
606
-        $datetime_field->set_timezone($this->_timezone);
607
-        $datetime_field->set_date_format($this->_dt_frmt, $pretty);
608
-        $datetime_field->set_time_format($this->_tm_frmt, $pretty);
609
-        //set the output returned
610
-        switch ($date_or_time) {
611
-            case 'D' :
612
-                $datetime_field->set_date_time_output('date');
613
-                break;
614
-            case 'T' :
615
-                $datetime_field->set_date_time_output('time');
616
-                break;
617
-            default :
618
-                $datetime_field->set_date_time_output();
619
-        }
620
-    }
621
-
622
-
623
-
624
-    /**
625
-     * This just takes care of clearing out the cached_properties
626
-     *
627
-     * @return void
628
-     */
629
-    protected function _clear_cached_properties()
630
-    {
631
-        $this->_cached_properties = array();
632
-    }
633
-
634
-
635
-
636
-    /**
637
-     * This just clears out ONE property if it exists in the cache
638
-     *
639
-     * @param  string $property_name the property to remove if it exists (from the _cached_properties array)
640
-     * @return void
641
-     */
642
-    protected function _clear_cached_property($property_name)
643
-    {
644
-        if (isset($this->_cached_properties[$property_name])) {
645
-            unset($this->_cached_properties[$property_name]);
646
-        }
647
-    }
648
-
649
-
650
-
651
-    /**
652
-     * Ensures that this related thing is a model object.
653
-     *
654
-     * @param mixed  $object_or_id EE_base_Class/int/string either a related model object, or its ID
655
-     * @param string $model_name   name of the related thing, eg 'Attendee',
656
-     * @return EE_Base_Class
657
-     * @throws \EE_Error
658
-     */
659
-    protected function ensure_related_thing_is_model_obj($object_or_id, $model_name)
660
-    {
661
-        $other_model_instance = self::_get_model_instance_with_name(
662
-            self::_get_model_classname($model_name),
663
-            $this->_timezone
664
-        );
665
-        return $other_model_instance->ensure_is_obj($object_or_id);
666
-    }
667
-
668
-
669
-
670
-    /**
671
-     * Forgets the cached model of the given relation Name. So the next time we request it,
672
-     * we will fetch it again from the database. (Handy if you know it's changed somehow).
673
-     * If a specific object is supplied, and the relationship to it is either a HasMany or HABTM,
674
-     * then only remove that one object from our cached array. Otherwise, clear the entire list
675
-     *
676
-     * @param string $relationName                         one of the keys in the _model_relations array on the model.
677
-     *                                                     Eg 'Registration'
678
-     * @param mixed  $object_to_remove_or_index_into_array or an index into the array of cached things, or NULL
679
-     *                                                     if you intend to use $clear_all = TRUE, or the relation only
680
-     *                                                     has 1 object anyways (ie, it's a BelongsToRelation)
681
-     * @param bool   $clear_all                            This flags clearing the entire cache relation property if
682
-     *                                                     this is HasMany or HABTM.
683
-     * @throws EE_Error
684
-     * @return EE_Base_Class | boolean from which was cleared from the cache, or true if we requested to remove a
685
-     *                       relation from all
686
-     */
687
-    public function clear_cache($relationName, $object_to_remove_or_index_into_array = null, $clear_all = false)
688
-    {
689
-        $relationship_to_model = $this->get_model()->related_settings_for($relationName);
690
-        $index_in_cache = '';
691
-        if ( ! $relationship_to_model) {
692
-            throw new EE_Error(
693
-                sprintf(
694
-                    __("There is no relationship to %s on a %s. Cannot clear that cache", 'event_espresso'),
695
-                    $relationName,
696
-                    get_class($this)
697
-                )
698
-            );
699
-        }
700
-        if ($clear_all) {
701
-            $obj_removed = true;
702
-            $this->_model_relations[$relationName] = null;
703
-        } elseif ($relationship_to_model instanceof EE_Belongs_To_Relation) {
704
-            $obj_removed = $this->_model_relations[$relationName];
705
-            $this->_model_relations[$relationName] = null;
706
-        } else {
707
-            if ($object_to_remove_or_index_into_array instanceof EE_Base_Class
708
-                && $object_to_remove_or_index_into_array->ID()
709
-            ) {
710
-                $index_in_cache = $object_to_remove_or_index_into_array->ID();
711
-                if (is_array($this->_model_relations[$relationName])
712
-                    && ! isset($this->_model_relations[$relationName][$index_in_cache])
713
-                ) {
714
-                    $index_found_at = null;
715
-                    //find this object in the array even though it has a different key
716
-                    foreach ($this->_model_relations[$relationName] as $index => $obj) {
717
-                        if (
718
-                            $obj instanceof EE_Base_Class
719
-                            && (
720
-                                $obj == $object_to_remove_or_index_into_array
721
-                                || $obj->ID() === $object_to_remove_or_index_into_array->ID()
722
-                            )
723
-                        ) {
724
-                            $index_found_at = $index;
725
-                            break;
726
-                        }
727
-                    }
728
-                    if ($index_found_at) {
729
-                        $index_in_cache = $index_found_at;
730
-                    } else {
731
-                        //it wasn't found. huh. well obviously it doesn't need to be removed from teh cache
732
-                        //if it wasn't in it to begin with. So we're done
733
-                        return $object_to_remove_or_index_into_array;
734
-                    }
735
-                }
736
-            } elseif ($object_to_remove_or_index_into_array instanceof EE_Base_Class) {
737
-                //so they provided a model object, but it's not yet saved to the DB... so let's go hunting for it!
738
-                foreach ($this->get_all_from_cache($relationName) as $index => $potentially_obj_we_want) {
739
-                    if ($potentially_obj_we_want == $object_to_remove_or_index_into_array) {
740
-                        $index_in_cache = $index;
741
-                    }
742
-                }
743
-            } else {
744
-                $index_in_cache = $object_to_remove_or_index_into_array;
745
-            }
746
-            //supposedly we've found it. But it could just be that the client code
747
-            //provided a bad index/object
748
-            if (
749
-            isset(
750
-                $this->_model_relations[$relationName],
751
-                $this->_model_relations[$relationName][$index_in_cache]
752
-            )
753
-            ) {
754
-                $obj_removed = $this->_model_relations[$relationName][$index_in_cache];
755
-                unset($this->_model_relations[$relationName][$index_in_cache]);
756
-            } else {
757
-                //that thing was never cached anyways.
758
-                $obj_removed = null;
759
-            }
760
-        }
761
-        return $obj_removed;
762
-    }
763
-
764
-
765
-
766
-    /**
767
-     * update_cache_after_object_save
768
-     * Allows a cached item to have it's cache ID (within the array of cached items) reset using the new ID it has
769
-     * obtained after being saved to the db
770
-     *
771
-     * @param string         $relationName       - the type of object that is cached
772
-     * @param \EE_Base_Class $newly_saved_object - the newly saved object to be re-cached
773
-     * @param string         $current_cache_id   - the ID that was used when originally caching the object
774
-     * @return boolean TRUE on success, FALSE on fail
775
-     * @throws \EE_Error
776
-     */
777
-    public function update_cache_after_object_save(
778
-        $relationName,
779
-        EE_Base_Class $newly_saved_object,
780
-        $current_cache_id = ''
781
-    ) {
782
-        // verify that incoming object is of the correct type
783
-        $obj_class = 'EE_' . $relationName;
784
-        if ($newly_saved_object instanceof $obj_class) {
785
-            /* @type EE_Base_Class $newly_saved_object */
786
-            // now get the type of relation
787
-            $relationship_to_model = $this->get_model()->related_settings_for($relationName);
788
-            // if this is a 1:1 relationship
789
-            if ($relationship_to_model instanceof EE_Belongs_To_Relation) {
790
-                // then just replace the cached object with the newly saved object
791
-                $this->_model_relations[$relationName] = $newly_saved_object;
792
-                return true;
793
-                // or if it's some kind of sordid feral polyamorous relationship...
794
-            } elseif (is_array($this->_model_relations[$relationName])
795
-                      && isset($this->_model_relations[$relationName][$current_cache_id])
796
-            ) {
797
-                // then remove the current cached item
798
-                unset($this->_model_relations[$relationName][$current_cache_id]);
799
-                // and cache the newly saved object using it's new ID
800
-                $this->_model_relations[$relationName][$newly_saved_object->ID()] = $newly_saved_object;
801
-                return true;
802
-            }
803
-        }
804
-        return false;
805
-    }
806
-
807
-
808
-
809
-    /**
810
-     * Fetches a single EE_Base_Class on that relation. (If the relation is of type
811
-     * BelongsTo, it will only ever have 1 object. However, other relations could have an array of objects)
812
-     *
813
-     * @param string $relationName
814
-     * @return EE_Base_Class
815
-     */
816
-    public function get_one_from_cache($relationName)
817
-    {
818
-        $cached_array_or_object = isset($this->_model_relations[$relationName]) ? $this->_model_relations[$relationName]
819
-            : null;
820
-        if (is_array($cached_array_or_object)) {
821
-            return array_shift($cached_array_or_object);
822
-        } else {
823
-            return $cached_array_or_object;
824
-        }
825
-    }
826
-
827
-
828
-
829
-    /**
830
-     * Fetches a single EE_Base_Class on that relation. (If the relation is of type
831
-     * BelongsTo, it will only ever have 1 object. However, other relations could have an array of objects)
832
-     *
833
-     * @param string $relationName
834
-     * @throws \EE_Error
835
-     * @return EE_Base_Class[] NOT necessarily indexed by primary keys
836
-     */
837
-    public function get_all_from_cache($relationName)
838
-    {
839
-        $objects = isset($this->_model_relations[$relationName]) ? $this->_model_relations[$relationName] : array();
840
-        // if the result is not an array, but exists, make it an array
841
-        $objects = is_array($objects) ? $objects : array($objects);
842
-        //bugfix for https://events.codebasehq.com/projects/event-espresso/tickets/7143
843
-        //basically, if this model object was stored in the session, and these cached model objects
844
-        //already have IDs, let's make sure they're in their model's entity mapper
845
-        //otherwise we will have duplicates next time we call
846
-        // EE_Registry::instance()->load_model( $relationName )->get_one_by_ID( $result->ID() );
847
-        $model = EE_Registry::instance()->load_model($relationName);
848
-        foreach ($objects as $model_object) {
849
-            if ($model instanceof EEM_Base && $model_object instanceof EE_Base_Class) {
850
-                //ensure its in the map if it has an ID; otherwise it will be added to the map when its saved
851
-                if ($model_object->ID()) {
852
-                    $model->add_to_entity_map($model_object);
853
-                }
854
-            } else {
855
-                throw new EE_Error(
856
-                    sprintf(
857
-                        __(
858
-                            'Error retrieving related model objects. Either $1%s is not a model or $2%s is not a model object',
859
-                            'event_espresso'
860
-                        ),
861
-                        $relationName,
862
-                        gettype($model_object)
863
-                    )
864
-                );
865
-            }
866
-        }
867
-        return $objects;
868
-    }
869
-
870
-
871
-
872
-    /**
873
-     * Returns the next x number of EE_Base_Class objects in sequence from this object as found in the database
874
-     * matching the given query conditions.
875
-     *
876
-     * @param null  $field_to_order_by  What field is being used as the reference point.
877
-     * @param int   $limit              How many objects to return.
878
-     * @param array $query_params       Any additional conditions on the query.
879
-     * @param null  $columns_to_select  If left null, then an array of EE_Base_Class objects is returned, otherwise
880
-     *                                  you can indicate just the columns you want returned
881
-     * @return array|EE_Base_Class[]
882
-     * @throws \EE_Error
883
-     */
884
-    public function next_x($field_to_order_by = null, $limit = 1, $query_params = array(), $columns_to_select = null)
885
-    {
886
-        $field = empty($field_to_order_by) && $this->get_model()->has_primary_key_field()
887
-            ? $this->get_model()->get_primary_key_field()->get_name()
888
-            : $field_to_order_by;
889
-        $current_value = ! empty($field) ? $this->get($field) : null;
890
-        if (empty($field) || empty($current_value)) {
891
-            return array();
892
-        }
893
-        return $this->get_model()->next_x($current_value, $field, $limit, $query_params, $columns_to_select);
894
-    }
895
-
896
-
897
-
898
-    /**
899
-     * Returns the previous x number of EE_Base_Class objects in sequence from this object as found in the database
900
-     * matching the given query conditions.
901
-     *
902
-     * @param null  $field_to_order_by  What field is being used as the reference point.
903
-     * @param int   $limit              How many objects to return.
904
-     * @param array $query_params       Any additional conditions on the query.
905
-     * @param null  $columns_to_select  If left null, then an array of EE_Base_Class objects is returned, otherwise
906
-     *                                  you can indicate just the columns you want returned
907
-     * @return array|EE_Base_Class[]
908
-     * @throws \EE_Error
909
-     */
910
-    public function previous_x(
911
-        $field_to_order_by = null,
912
-        $limit = 1,
913
-        $query_params = array(),
914
-        $columns_to_select = null
915
-    ) {
916
-        $field = empty($field_to_order_by) && $this->get_model()->has_primary_key_field()
917
-            ? $this->get_model()->get_primary_key_field()->get_name()
918
-            : $field_to_order_by;
919
-        $current_value = ! empty($field) ? $this->get($field) : null;
920
-        if (empty($field) || empty($current_value)) {
921
-            return array();
922
-        }
923
-        return $this->get_model()->previous_x($current_value, $field, $limit, $query_params, $columns_to_select);
924
-    }
925
-
926
-
927
-
928
-    /**
929
-     * Returns the next EE_Base_Class object in sequence from this object as found in the database
930
-     * matching the given query conditions.
931
-     *
932
-     * @param null  $field_to_order_by  What field is being used as the reference point.
933
-     * @param array $query_params       Any additional conditions on the query.
934
-     * @param null  $columns_to_select  If left null, then an array of EE_Base_Class objects is returned, otherwise
935
-     *                                  you can indicate just the columns you want returned
936
-     * @return array|EE_Base_Class
937
-     * @throws \EE_Error
938
-     */
939
-    public function next($field_to_order_by = null, $query_params = array(), $columns_to_select = null)
940
-    {
941
-        $field = empty($field_to_order_by) && $this->get_model()->has_primary_key_field()
942
-            ? $this->get_model()->get_primary_key_field()->get_name()
943
-            : $field_to_order_by;
944
-        $current_value = ! empty($field) ? $this->get($field) : null;
945
-        if (empty($field) || empty($current_value)) {
946
-            return array();
947
-        }
948
-        return $this->get_model()->next($current_value, $field, $query_params, $columns_to_select);
949
-    }
950
-
951
-
952
-
953
-    /**
954
-     * Returns the previous EE_Base_Class object in sequence from this object as found in the database
955
-     * matching the given query conditions.
956
-     *
957
-     * @param null  $field_to_order_by  What field is being used as the reference point.
958
-     * @param array $query_params       Any additional conditions on the query.
959
-     * @param null  $columns_to_select  If left null, then an EE_Base_Class object is returned, otherwise
960
-     *                                  you can indicate just the column you want returned
961
-     * @return array|EE_Base_Class
962
-     * @throws \EE_Error
963
-     */
964
-    public function previous($field_to_order_by = null, $query_params = array(), $columns_to_select = null)
965
-    {
966
-        $field = empty($field_to_order_by) && $this->get_model()->has_primary_key_field()
967
-            ? $this->get_model()->get_primary_key_field()->get_name()
968
-            : $field_to_order_by;
969
-        $current_value = ! empty($field) ? $this->get($field) : null;
970
-        if (empty($field) || empty($current_value)) {
971
-            return array();
972
-        }
973
-        return $this->get_model()->previous($current_value, $field, $query_params, $columns_to_select);
974
-    }
975
-
976
-
977
-
978
-    /**
979
-     * Overrides parent because parent expects old models.
980
-     * This also doesn't do any validation, and won't work for serialized arrays
981
-     *
982
-     * @param string $field_name
983
-     * @param mixed  $field_value_from_db
984
-     * @throws \EE_Error
985
-     */
986
-    public function set_from_db($field_name, $field_value_from_db)
987
-    {
988
-        $field_obj = $this->get_model()->field_settings_for($field_name);
989
-        if ($field_obj instanceof EE_Model_Field_Base) {
990
-            //you would think the DB has no NULLs for non-null label fields right? wrong!
991
-            //eg, a CPT model object could have an entry in the posts table, but no
992
-            //entry in the meta table. Meaning that all its columns in the meta table
993
-            //are null! yikes! so when we find one like that, use defaults for its meta columns
994
-            if ($field_value_from_db === null) {
995
-                if ($field_obj->is_nullable()) {
996
-                    //if the field allows nulls, then let it be null
997
-                    $field_value = null;
998
-                } else {
999
-                    $field_value = $field_obj->get_default_value();
1000
-                }
1001
-            } else {
1002
-                $field_value = $field_obj->prepare_for_set_from_db($field_value_from_db);
1003
-            }
1004
-            $this->_fields[$field_name] = $field_value;
1005
-            $this->_clear_cached_property($field_name);
1006
-        }
1007
-    }
1008
-
1009
-
1010
-
1011
-    /**
1012
-     * verifies that the specified field is of the correct type
1013
-     *
1014
-     * @param string $field_name
1015
-     * @param string $extra_cache_ref This allows the user to specify an extra cache ref for the given property
1016
-     *                                (in cases where the same property may be used for different outputs
1017
-     *                                - i.e. datetime, money etc.)
1018
-     * @return mixed
1019
-     * @throws \EE_Error
1020
-     */
1021
-    public function get($field_name, $extra_cache_ref = null)
1022
-    {
1023
-        return $this->_get_cached_property($field_name, false, $extra_cache_ref);
1024
-    }
1025
-
1026
-
1027
-
1028
-    /**
1029
-     * This method simply returns the RAW unprocessed value for the given property in this class
1030
-     *
1031
-     * @param  string $field_name A valid fieldname
1032
-     * @return mixed              Whatever the raw value stored on the property is.
1033
-     * @throws EE_Error if fieldSettings is misconfigured or the field doesn't exist.
1034
-     */
1035
-    public function get_raw($field_name)
1036
-    {
1037
-        $field_settings = $this->get_model()->field_settings_for($field_name);
1038
-        return $field_settings instanceof EE_Datetime_Field && $this->_fields[$field_name] instanceof DateTime
1039
-            ? $this->_fields[$field_name]->format('U')
1040
-            : $this->_fields[$field_name];
1041
-    }
1042
-
1043
-
1044
-
1045
-    /**
1046
-     * This is used to return the internal DateTime object used for a field that is a
1047
-     * EE_Datetime_Field.
1048
-     *
1049
-     * @param string $field_name               The field name retrieving the DateTime object.
1050
-     * @return mixed null | false | DateTime  If the requested field is NOT a EE_Datetime_Field then
1051
-     * @throws \EE_Error
1052
-     *                                         an error is set and false returned.  If the field IS an
1053
-     *                                         EE_Datetime_Field and but the field value is null, then
1054
-     *                                         just null is returned (because that indicates that likely
1055
-     *                                         this field is nullable).
1056
-     */
1057
-    public function get_DateTime_object($field_name)
1058
-    {
1059
-        $field_settings = $this->get_model()->field_settings_for($field_name);
1060
-        if ( ! $field_settings instanceof EE_Datetime_Field) {
1061
-            EE_Error::add_error(
1062
-                sprintf(
1063
-                    __(
1064
-                        'The field %s is not an EE_Datetime_Field field.  There is no DateTime object stored on this field type.',
1065
-                        'event_espresso'
1066
-                    ),
1067
-                    $field_name
1068
-                ),
1069
-                __FILE__,
1070
-                __FUNCTION__,
1071
-                __LINE__
1072
-            );
1073
-            return false;
1074
-        }
1075
-        return $this->_fields[$field_name];
1076
-    }
1077
-
1078
-
1079
-
1080
-    /**
1081
-     * To be used in template to immediately echo out the value, and format it for output.
1082
-     * Eg, should call stripslashes and whatnot before echoing
1083
-     *
1084
-     * @param string $field_name      the name of the field as it appears in the DB
1085
-     * @param string $extra_cache_ref This allows the user to specify an extra cache ref for the given property
1086
-     *                                (in cases where the same property may be used for different outputs
1087
-     *                                - i.e. datetime, money etc.)
1088
-     * @return void
1089
-     * @throws \EE_Error
1090
-     */
1091
-    public function e($field_name, $extra_cache_ref = null)
1092
-    {
1093
-        echo $this->get_pretty($field_name, $extra_cache_ref);
1094
-    }
1095
-
1096
-
1097
-
1098
-    /**
1099
-     * Exactly like e(), echoes out the field, but sets its schema to 'form_input', so that it
1100
-     * can be easily used as the value of form input.
1101
-     *
1102
-     * @param string $field_name
1103
-     * @return void
1104
-     * @throws \EE_Error
1105
-     */
1106
-    public function f($field_name)
1107
-    {
1108
-        $this->e($field_name, 'form_input');
1109
-    }
1110
-
1111
-
1112
-
1113
-    /**
1114
-     * Gets a pretty view of the field's value. $extra_cache_ref can specify different formats for this.
1115
-     * The $extra_cache_ref will be passed to the model field's prepare_for_pretty_echoing, so consult the field's class
1116
-     * to see what options are available.
1117
-     * @param string $field_name
1118
-     * @param string $extra_cache_ref This allows the user to specify an extra cache ref for the given property
1119
-     *                                (in cases where the same property may be used for different outputs
1120
-     *                                - i.e. datetime, money etc.)
1121
-     * @return mixed
1122
-     * @throws \EE_Error
1123
-     */
1124
-    public function get_pretty($field_name, $extra_cache_ref = null)
1125
-    {
1126
-        return $this->_get_cached_property($field_name, true, $extra_cache_ref);
1127
-    }
1128
-
1129
-
1130
-
1131
-    /**
1132
-     * This simply returns the datetime for the given field name
1133
-     * Note: this protected function is called by the wrapper get_date or get_time or get_datetime functions
1134
-     * (and the equivalent e_date, e_time, e_datetime).
1135
-     *
1136
-     * @access   protected
1137
-     * @param string   $field_name   Field on the instantiated EE_Base_Class child object
1138
-     * @param string   $dt_frmt      valid datetime format used for date
1139
-     *                               (if '' then we just use the default on the field,
1140
-     *                               if NULL we use the last-used format)
1141
-     * @param string   $tm_frmt      Same as above except this is for time format
1142
-     * @param string   $date_or_time if NULL then both are returned, otherwise "D" = only date and "T" = only time.
1143
-     * @param  boolean $echo         Whether the dtt is echoing using pretty echoing or just returned using vanilla get
1144
-     * @return string|bool|EE_Error string on success, FALSE on fail, or EE_Error Exception is thrown
1145
-     *                               if field is not a valid dtt field, or void if echoing
1146
-     * @throws \EE_Error
1147
-     */
1148
-    protected function _get_datetime($field_name, $dt_frmt = '', $tm_frmt = '', $date_or_time = '', $echo = false)
1149
-    {
1150
-        // clear cached property
1151
-        $this->_clear_cached_property($field_name);
1152
-        //reset format properties because they are used in get()
1153
-        $this->_dt_frmt = $dt_frmt !== '' ? $dt_frmt : $this->_dt_frmt;
1154
-        $this->_tm_frmt = $tm_frmt !== '' ? $tm_frmt : $this->_tm_frmt;
1155
-        if ($echo) {
1156
-            $this->e($field_name, $date_or_time);
1157
-            return '';
1158
-        }
1159
-        return $this->get($field_name, $date_or_time);
1160
-    }
1161
-
1162
-
1163
-
1164
-    /**
1165
-     * below are wrapper functions for the various datetime outputs that can be obtained for JUST returning the date
1166
-     * portion of a datetime value. (note the only difference between get_ and e_ is one returns the value and the
1167
-     * other echoes the pretty value for dtt)
1168
-     *
1169
-     * @param  string $field_name name of model object datetime field holding the value
1170
-     * @param  string $format     format for the date returned (if NULL we use default in dt_frmt property)
1171
-     * @return string            datetime value formatted
1172
-     * @throws \EE_Error
1173
-     */
1174
-    public function get_date($field_name, $format = '')
1175
-    {
1176
-        return $this->_get_datetime($field_name, $format, null, 'D');
1177
-    }
1178
-
1179
-
1180
-
1181
-    /**
1182
-     * @param      $field_name
1183
-     * @param string $format
1184
-     * @throws \EE_Error
1185
-     */
1186
-    public function e_date($field_name, $format = '')
1187
-    {
1188
-        $this->_get_datetime($field_name, $format, null, 'D', true);
1189
-    }
1190
-
1191
-
1192
-
1193
-    /**
1194
-     * below are wrapper functions for the various datetime outputs that can be obtained for JUST returning the time
1195
-     * portion of a datetime value. (note the only difference between get_ and e_ is one returns the value and the
1196
-     * other echoes the pretty value for dtt)
1197
-     *
1198
-     * @param  string $field_name name of model object datetime field holding the value
1199
-     * @param  string $format     format for the time returned ( if NULL we use default in tm_frmt property)
1200
-     * @return string             datetime value formatted
1201
-     * @throws \EE_Error
1202
-     */
1203
-    public function get_time($field_name, $format = '')
1204
-    {
1205
-        return $this->_get_datetime($field_name, null, $format, 'T');
1206
-    }
1207
-
1208
-
1209
-
1210
-    /**
1211
-     * @param      $field_name
1212
-     * @param string $format
1213
-     * @throws \EE_Error
1214
-     */
1215
-    public function e_time($field_name, $format = '')
1216
-    {
1217
-        $this->_get_datetime($field_name, null, $format, 'T', true);
1218
-    }
1219
-
1220
-
1221
-
1222
-    /**
1223
-     * below are wrapper functions for the various datetime outputs that can be obtained for returning the date AND
1224
-     * time portion of a datetime value. (note the only difference between get_ and e_ is one returns the value and the
1225
-     * other echoes the pretty value for dtt)
1226
-     *
1227
-     * @param  string $field_name name of model object datetime field holding the value
1228
-     * @param  string $dt_frmt    format for the date returned (if NULL we use default in dt_frmt property)
1229
-     * @param  string $tm_frmt    format for the time returned (if NULL we use default in tm_frmt property)
1230
-     * @return string             datetime value formatted
1231
-     * @throws \EE_Error
1232
-     */
1233
-    public function get_datetime($field_name, $dt_frmt = '', $tm_frmt = '')
1234
-    {
1235
-        return $this->_get_datetime($field_name, $dt_frmt, $tm_frmt);
1236
-    }
1237
-
1238
-
1239
-
1240
-    /**
1241
-     * @param string $field_name
1242
-     * @param string $dt_frmt
1243
-     * @param string $tm_frmt
1244
-     * @throws \EE_Error
1245
-     */
1246
-    public function e_datetime($field_name, $dt_frmt = '', $tm_frmt = '')
1247
-    {
1248
-        $this->_get_datetime($field_name, $dt_frmt, $tm_frmt, null, true);
1249
-    }
1250
-
1251
-
1252
-
1253
-    /**
1254
-     * Get the i8ln value for a date using the WordPress @see date_i18n function.
1255
-     *
1256
-     * @param string $field_name The EE_Datetime_Field reference for the date being retrieved.
1257
-     * @param string $format     PHP valid date/time string format.  If none is provided then the internal set format
1258
-     *                           on the object will be used.
1259
-     * @return string Date and time string in set locale or false if no field exists for the given
1260
-     * @throws \EE_Error
1261
-     *                           field name.
1262
-     */
1263
-    public function get_i18n_datetime($field_name, $format = '')
1264
-    {
1265
-        $format = empty($format) ? $this->_dt_frmt . ' ' . $this->_tm_frmt : $format;
1266
-        return date_i18n(
1267
-            $format,
1268
-            EEH_DTT_Helper::get_timestamp_with_offset($this->get_raw($field_name), $this->_timezone)
1269
-        );
1270
-    }
1271
-
1272
-
1273
-
1274
-    /**
1275
-     * This method validates whether the given field name is a valid field on the model object as well as it is of a
1276
-     * type EE_Datetime_Field.  On success there will be returned the field settings.  On fail an EE_Error exception is
1277
-     * thrown.
1278
-     *
1279
-     * @param  string $field_name The field name being checked
1280
-     * @throws EE_Error
1281
-     * @return EE_Datetime_Field
1282
-     */
1283
-    protected function _get_dtt_field_settings($field_name)
1284
-    {
1285
-        $field = $this->get_model()->field_settings_for($field_name);
1286
-        //check if field is dtt
1287
-        if ($field instanceof EE_Datetime_Field) {
1288
-            return $field;
1289
-        } else {
1290
-            throw new EE_Error(sprintf(__('The field name "%s" has been requested for the EE_Base_Class datetime functions and it is not a valid EE_Datetime_Field.  Please check the spelling of the field and make sure it has been setup as a EE_Datetime_Field in the %s model constructor',
1291
-                'event_espresso'), $field_name, self::_get_model_classname(get_class($this))));
1292
-        }
1293
-    }
1294
-
1295
-
1296
-
1297
-
1298
-    /**
1299
-     * NOTE ABOUT BELOW:
1300
-     * These convenience date and time setters are for setting date and time independently.  In other words you might
1301
-     * want to change the time on a datetime_field but leave the date the same (or vice versa). IF on the other hand
1302
-     * you want to set both date and time at the same time, you can just use the models default set($fieldname,$value)
1303
-     * method and make sure you send the entire datetime value for setting.
1304
-     */
1305
-    /**
1306
-     * sets the time on a datetime property
1307
-     *
1308
-     * @access protected
1309
-     * @param string|Datetime $time      a valid time string for php datetime functions (or DateTime object)
1310
-     * @param string          $fieldname the name of the field the time is being set on (must match a EE_Datetime_Field)
1311
-     * @throws \EE_Error
1312
-     */
1313
-    protected function _set_time_for($time, $fieldname)
1314
-    {
1315
-        $this->_set_date_time('T', $time, $fieldname);
1316
-    }
1317
-
1318
-
1319
-
1320
-    /**
1321
-     * sets the date on a datetime property
1322
-     *
1323
-     * @access protected
1324
-     * @param string|DateTime $date      a valid date string for php datetime functions ( or DateTime object)
1325
-     * @param string          $fieldname the name of the field the date is being set on (must match a EE_Datetime_Field)
1326
-     * @throws \EE_Error
1327
-     */
1328
-    protected function _set_date_for($date, $fieldname)
1329
-    {
1330
-        $this->_set_date_time('D', $date, $fieldname);
1331
-    }
1332
-
1333
-
1334
-
1335
-    /**
1336
-     * This takes care of setting a date or time independently on a given model object property. This method also
1337
-     * verifies that the given fieldname matches a model object property and is for a EE_Datetime_Field field
1338
-     *
1339
-     * @access protected
1340
-     * @param string          $what           "T" for time, 'B' for both, 'D' for Date.
1341
-     * @param string|DateTime $datetime_value A valid Date or Time string (or DateTime object)
1342
-     * @param string          $fieldname      the name of the field the date OR time is being set on (must match a
1343
-     *                                        EE_Datetime_Field property)
1344
-     * @throws \EE_Error
1345
-     */
1346
-    protected function _set_date_time($what = 'T', $datetime_value, $fieldname)
1347
-    {
1348
-        $field = $this->_get_dtt_field_settings($fieldname);
1349
-        $field->set_timezone($this->_timezone);
1350
-        $field->set_date_format($this->_dt_frmt);
1351
-        $field->set_time_format($this->_tm_frmt);
1352
-        switch ($what) {
1353
-            case 'T' :
1354
-                $this->_fields[$fieldname] = $field->prepare_for_set_with_new_time(
1355
-                    $datetime_value,
1356
-                    $this->_fields[$fieldname]
1357
-                );
1358
-                break;
1359
-            case 'D' :
1360
-                $this->_fields[$fieldname] = $field->prepare_for_set_with_new_date(
1361
-                    $datetime_value,
1362
-                    $this->_fields[$fieldname]
1363
-                );
1364
-                break;
1365
-            case 'B' :
1366
-                $this->_fields[$fieldname] = $field->prepare_for_set($datetime_value);
1367
-                break;
1368
-        }
1369
-        $this->_clear_cached_property($fieldname);
1370
-    }
1371
-
1372
-
1373
-
1374
-    /**
1375
-     * This will return a timestamp for the website timezone but ONLY when the current website timezone is different
1376
-     * than the timezone set for the website. NOTE, this currently only works well with methods that return values.  If
1377
-     * you use it with methods that echo values the $_timestamp property may not get reset to its original value and
1378
-     * that could lead to some unexpected results!
1379
-     *
1380
-     * @access public
1381
-     * @param string               $field_name This is the name of the field on the object that contains the date/time
1382
-     *                                         value being returned.
1383
-     * @param string               $callback   must match a valid method in this class (defaults to get_datetime)
1384
-     * @param mixed (array|string) $args       This is the arguments that will be passed to the callback.
1385
-     * @param string               $prepend    You can include something to prepend on the timestamp
1386
-     * @param string               $append     You can include something to append on the timestamp
1387
-     * @throws EE_Error
1388
-     * @return string timestamp
1389
-     */
1390
-    public function display_in_my_timezone(
1391
-        $field_name,
1392
-        $callback = 'get_datetime',
1393
-        $args = null,
1394
-        $prepend = '',
1395
-        $append = ''
1396
-    ) {
1397
-        $timezone = EEH_DTT_Helper::get_timezone();
1398
-        if ($timezone === $this->_timezone) {
1399
-            return '';
1400
-        }
1401
-        $original_timezone = $this->_timezone;
1402
-        $this->set_timezone($timezone);
1403
-        $fn = (array)$field_name;
1404
-        $args = array_merge($fn, (array)$args);
1405
-        if ( ! method_exists($this, $callback)) {
1406
-            throw new EE_Error(
1407
-                sprintf(
1408
-                    __(
1409
-                        'The method named "%s" given as the callback param in "display_in_my_timezone" does not exist.  Please check your spelling',
1410
-                        'event_espresso'
1411
-                    ),
1412
-                    $callback
1413
-                )
1414
-            );
1415
-        }
1416
-        $args = (array)$args;
1417
-        $return = $prepend . call_user_func_array(array($this, $callback), $args) . $append;
1418
-        $this->set_timezone($original_timezone);
1419
-        return $return;
1420
-    }
1421
-
1422
-
1423
-
1424
-    /**
1425
-     * Deletes this model object.
1426
-     * This calls the `EE_Base_Class::_delete` method.  Child classes wishing to change default behaviour should
1427
-     * override
1428
-     * `EE_Base_Class::_delete` NOT this class.
1429
-     *
1430
-     * @return boolean | int
1431
-     * @throws \EE_Error
1432
-     */
1433
-    public function delete()
1434
-    {
1435
-        /**
1436
-         * Called just before the `EE_Base_Class::_delete` method call.
1437
-         * Note: `EE_Base_Class::_delete` might be overridden by child classes so any client code hooking into these actions
1438
-         * should be aware that `_delete` may not always result in a permanent delete.  For example, `EE_Soft_Delete_Base_Class::_delete`
1439
-         * soft deletes (trash) the object and does not permanently delete it.
1440
-         *
1441
-         * @param EE_Base_Class $model_object about to be 'deleted'
1442
-         */
1443
-        do_action('AHEE__EE_Base_Class__delete__before', $this);
1444
-        $result = $this->_delete();
1445
-        /**
1446
-         * Called just after the `EE_Base_Class::_delete` method call.
1447
-         * Note: `EE_Base_Class::_delete` might be overridden by child classes so any client code hooking into these actions
1448
-         * should be aware that `_delete` may not always result in a permanent delete.  For example `EE_Soft_Base_Class::_delete`
1449
-         * soft deletes (trash) the object and does not permanently delete it.
1450
-         *
1451
-         * @param EE_Base_Class $model_object that was just 'deleted'
1452
-         * @param boolean       $result
1453
-         */
1454
-        do_action('AHEE__EE_Base_Class__delete__end', $this, $result);
1455
-        return $result;
1456
-    }
1457
-
1458
-
1459
-
1460
-    /**
1461
-     * Calls the specific delete method for the instantiated class.
1462
-     * This method is called by the public `EE_Base_Class::delete` method.  Any child classes desiring to override
1463
-     * default functionality for "delete" (which is to call `permanently_delete`) should override this method NOT
1464
-     * `EE_Base_Class::delete`
1465
-     *
1466
-     * @return bool|int
1467
-     * @throws \EE_Error
1468
-     */
1469
-    protected function _delete()
1470
-    {
1471
-        return $this->delete_permanently();
1472
-    }
1473
-
1474
-
1475
-
1476
-    /**
1477
-     * Deletes this model object permanently from db (but keep in mind related models my block the delete and return an
1478
-     * error)
1479
-     *
1480
-     * @return bool | int
1481
-     * @throws \EE_Error
1482
-     */
1483
-    public function delete_permanently()
1484
-    {
1485
-        /**
1486
-         * Called just before HARD deleting a model object
1487
-         *
1488
-         * @param EE_Base_Class $model_object about to be 'deleted'
1489
-         */
1490
-        do_action('AHEE__EE_Base_Class__delete_permanently__before', $this);
1491
-        $model = $this->get_model();
1492
-        $result = $model->delete_permanently_by_ID($this->ID());
1493
-        $this->refresh_cache_of_related_objects();
1494
-        /**
1495
-         * Called just after HARD deleting a model object
1496
-         *
1497
-         * @param EE_Base_Class $model_object that was just 'deleted'
1498
-         * @param boolean       $result
1499
-         */
1500
-        do_action('AHEE__EE_Base_Class__delete_permanently__end', $this, $result);
1501
-        return $result;
1502
-    }
1503
-
1504
-
1505
-
1506
-    /**
1507
-     * When this model object is deleted, it may still be cached on related model objects. This clears the cache of
1508
-     * related model objects
1509
-     *
1510
-     * @throws \EE_Error
1511
-     */
1512
-    public function refresh_cache_of_related_objects()
1513
-    {
1514
-        foreach ($this->get_model()->relation_settings() as $relation_name => $relation_obj) {
1515
-            if ( ! empty($this->_model_relations[$relation_name])) {
1516
-                $related_objects = $this->_model_relations[$relation_name];
1517
-                if ($relation_obj instanceof EE_Belongs_To_Relation) {
1518
-                    //this relation only stores a single model object, not an array
1519
-                    //but let's make it consistent
1520
-                    $related_objects = array($related_objects);
1521
-                }
1522
-                foreach ($related_objects as $related_object) {
1523
-                    //only refresh their cache if they're in memory
1524
-                    if ($related_object instanceof EE_Base_Class) {
1525
-                        $related_object->clear_cache($this->get_model()->get_this_model_name(), $this);
1526
-                    }
1527
-                }
1528
-            }
1529
-        }
1530
-    }
1531
-
1532
-
1533
-
1534
-    /**
1535
-     *        Saves this object to the database. An array may be supplied to set some values on this
1536
-     * object just before saving.
1537
-     *
1538
-     * @access public
1539
-     * @param array $set_cols_n_values keys are field names, values are their new values,
1540
-     *                                 if provided during the save() method (often client code will change the fields'
1541
-     *                                 values before calling save)
1542
-     * @throws \EE_Error
1543
-     * @return int , 1 on a successful update, the ID of the new entry on insert; 0 on failure or if the model object
1544
-     *                                 isn't allowed to persist (as determined by EE_Base_Class::allow_persist())
1545
-     */
1546
-    public function save($set_cols_n_values = array())
1547
-    {
1548
-        /**
1549
-         * Filters the fields we're about to save on the model object
1550
-         *
1551
-         * @param array         $set_cols_n_values
1552
-         * @param EE_Base_Class $model_object
1553
-         */
1554
-        $set_cols_n_values = (array)apply_filters('FHEE__EE_Base_Class__save__set_cols_n_values', $set_cols_n_values,
1555
-            $this);
1556
-        //set attributes as provided in $set_cols_n_values
1557
-        foreach ($set_cols_n_values as $column => $value) {
1558
-            $this->set($column, $value);
1559
-        }
1560
-        /**
1561
-         * Saving a model object.
1562
-         * Before we perform a save, this action is fired.
1563
-         *
1564
-         * @param EE_Base_Class $model_object the model object about to be saved.
1565
-         */
1566
-        do_action('AHEE__EE_Base_Class__save__begin', $this);
1567
-        if ( ! $this->allow_persist()) {
1568
-            return 0;
1569
-        }
1570
-        //now get current attribute values
1571
-        $save_cols_n_values = $this->_fields;
1572
-        //if the object already has an ID, update it. Otherwise, insert it
1573
-        //also: change the assumption about values passed to the model NOT being prepare dby the model object. They have been
1574
-        $old_assumption_concerning_value_preparation = $this->get_model()
1575
-                                                            ->get_assumption_concerning_values_already_prepared_by_model_object();
1576
-        $this->get_model()->assume_values_already_prepared_by_model_object(true);
1577
-        //does this model have an autoincrement PK?
1578
-        if ($this->get_model()->has_primary_key_field()) {
1579
-            if ($this->get_model()->get_primary_key_field()->is_auto_increment()) {
1580
-                //ok check if it's set, if so: update; if not, insert
1581
-                if ( ! empty($save_cols_n_values[self::_get_primary_key_name(get_class($this))])) {
1582
-                    $results = $this->get_model()->update_by_ID($save_cols_n_values, $this->ID());
1583
-                } else {
1584
-                    unset($save_cols_n_values[self::_get_primary_key_name(get_class($this))]);
1585
-                    $results = $this->get_model()->insert($save_cols_n_values);
1586
-                    if ($results) {
1587
-                        //if successful, set the primary key
1588
-                        //but don't use the normal SET method, because it will check if
1589
-                        //an item with the same ID exists in the mapper & db, then
1590
-                        //will find it in the db (because we just added it) and THAT object
1591
-                        //will get added to the mapper before we can add this one!
1592
-                        //but if we just avoid using the SET method, all that headache can be avoided
1593
-                        $pk_field_name = self::_get_primary_key_name(get_class($this));
1594
-                        $this->_fields[$pk_field_name] = $results;
1595
-                        $this->_clear_cached_property($pk_field_name);
1596
-                        $this->get_model()->add_to_entity_map($this);
1597
-                        $this->_update_cached_related_model_objs_fks();
1598
-                    }
1599
-                }
1600
-            } else {//PK is NOT auto-increment
1601
-                //so check if one like it already exists in the db
1602
-                if ($this->get_model()->exists_by_ID($this->ID())) {
1603
-                    if (WP_DEBUG && ! $this->in_entity_map()) {
1604
-                        throw new EE_Error(
1605
-                            sprintf(
1606
-                                __('Using a model object %1$s that is NOT in the entity map, can lead to unexpected errors. You should either: %4$s 1. Put it in the entity mapper by calling %2$s %4$s 2. Discard this model object and use what is in the entity mapper %4$s 3. Fetch from the database using %3$s',
1607
-                                    'event_espresso'),
1608
-                                get_class($this),
1609
-                                get_class($this->get_model()) . '::instance()->add_to_entity_map()',
1610
-                                get_class($this->get_model()) . '::instance()->get_one_by_ID()',
1611
-                                '<br />'
1612
-                            )
1613
-                        );
1614
-                    }
1615
-                    $results = $this->get_model()->update_by_ID($save_cols_n_values, $this->ID());
1616
-                } else {
1617
-                    $results = $this->get_model()->insert($save_cols_n_values);
1618
-                    $this->_update_cached_related_model_objs_fks();
1619
-                }
1620
-            }
1621
-        } else {//there is NO primary key
1622
-            $already_in_db = false;
1623
-            foreach ($this->get_model()->unique_indexes() as $index) {
1624
-                $uniqueness_where_params = array_intersect_key($save_cols_n_values, $index->fields());
1625
-                if ($this->get_model()->exists(array($uniqueness_where_params))) {
1626
-                    $already_in_db = true;
1627
-                }
1628
-            }
1629
-            if ($already_in_db) {
1630
-                $combined_pk_fields_n_values = array_intersect_key($save_cols_n_values,
1631
-                    $this->get_model()->get_combined_primary_key_fields());
1632
-                $results = $this->get_model()->update($save_cols_n_values, $combined_pk_fields_n_values);
1633
-            } else {
1634
-                $results = $this->get_model()->insert($save_cols_n_values);
1635
-            }
1636
-        }
1637
-        //restore the old assumption about values being prepared by the model object
1638
-        $this->get_model()
1639
-             ->assume_values_already_prepared_by_model_object($old_assumption_concerning_value_preparation);
1640
-        /**
1641
-         * After saving the model object this action is called
1642
-         *
1643
-         * @param EE_Base_Class $model_object which was just saved
1644
-         * @param boolean|int   $results      if it were updated, TRUE or FALSE; if it were newly inserted
1645
-         *                                    the new ID (or 0 if an error occurred and it wasn't updated)
1646
-         */
1647
-        do_action('AHEE__EE_Base_Class__save__end', $this, $results);
1648
-        return $results;
1649
-    }
1650
-
1651
-
1652
-
1653
-    /**
1654
-     * Updates the foreign key on related models objects pointing to this to have this model object's ID
1655
-     * as their foreign key.  If the cached related model objects already exist in the db, saves them (so that the DB
1656
-     * is consistent) Especially useful in case we JUST added this model object ot the database and we want to let its
1657
-     * cached relations with foreign keys to it know about that change. Eg: we've created a transaction but haven't
1658
-     * saved it to the db. We also create a registration and don't save it to the DB, but we DO cache it on the
1659
-     * transaction. Now, when we save the transaction, the registration's TXN_ID will be automatically updated, whether
1660
-     * or not they exist in the DB (if they do, their DB records will be automatically updated)
1661
-     *
1662
-     * @return void
1663
-     * @throws \EE_Error
1664
-     */
1665
-    protected function _update_cached_related_model_objs_fks()
1666
-    {
1667
-        foreach ($this->get_model()->relation_settings() as $relation_name => $relation_obj) {
1668
-            if ($relation_obj instanceof EE_Has_Many_Relation) {
1669
-                foreach ($this->get_all_from_cache($relation_name) as $related_model_obj_in_cache) {
1670
-                    $fk_to_this = $related_model_obj_in_cache->get_model()->get_foreign_key_to(
1671
-                        $this->get_model()->get_this_model_name()
1672
-                    );
1673
-                    $related_model_obj_in_cache->set($fk_to_this->get_name(), $this->ID());
1674
-                    if ($related_model_obj_in_cache->ID()) {
1675
-                        $related_model_obj_in_cache->save();
1676
-                    }
1677
-                }
1678
-            }
1679
-        }
1680
-    }
1681
-
1682
-
1683
-
1684
-    /**
1685
-     * Saves this model object and its NEW cached relations to the database.
1686
-     * (Meaning, for now, IT DOES NOT WORK if the cached items already exist in the DB.
1687
-     * In order for that to work, we would need to mark model objects as dirty/clean...
1688
-     * because otherwise, there's a potential for infinite looping of saving
1689
-     * Saves the cached related model objects, and ensures the relation between them
1690
-     * and this object and properly setup
1691
-     *
1692
-     * @return int ID of new model object on save; 0 on failure+
1693
-     * @throws \EE_Error
1694
-     */
1695
-    public function save_new_cached_related_model_objs()
1696
-    {
1697
-        //make sure this has been saved
1698
-        if ( ! $this->ID()) {
1699
-            $id = $this->save();
1700
-        } else {
1701
-            $id = $this->ID();
1702
-        }
1703
-        //now save all the NEW cached model objects  (ie they don't exist in the DB)
1704
-        foreach ($this->get_model()->relation_settings() as $relationName => $relationObj) {
1705
-            if ($this->_model_relations[$relationName]) {
1706
-                //is this a relation where we should expect just ONE related object (ie, EE_Belongs_To_relation)
1707
-                //or MANY related objects (ie, EE_HABTM_Relation or EE_Has_Many_Relation)?
1708
-                if ($relationObj instanceof EE_Belongs_To_Relation) {
1709
-                    //add a relation to that relation type (which saves the appropriate thing in the process)
1710
-                    //but ONLY if it DOES NOT exist in the DB
1711
-                    /* @var $related_model_obj EE_Base_Class */
1712
-                    $related_model_obj = $this->_model_relations[$relationName];
1713
-                    //					if( ! $related_model_obj->ID()){
1714
-                    $this->_add_relation_to($related_model_obj, $relationName);
1715
-                    $related_model_obj->save_new_cached_related_model_objs();
1716
-                    //					}
1717
-                } else {
1718
-                    foreach ($this->_model_relations[$relationName] as $related_model_obj) {
1719
-                        //add a relation to that relation type (which saves the appropriate thing in the process)
1720
-                        //but ONLY if it DOES NOT exist in the DB
1721
-                        //						if( ! $related_model_obj->ID()){
1722
-                        $this->_add_relation_to($related_model_obj, $relationName);
1723
-                        $related_model_obj->save_new_cached_related_model_objs();
1724
-                        //						}
1725
-                    }
1726
-                }
1727
-            }
1728
-        }
1729
-        return $id;
1730
-    }
1731
-
1732
-
1733
-
1734
-    /**
1735
-     * for getting a model while instantiated.
1736
-     *
1737
-     * @return \EEM_Base | \EEM_CPT_Base
1738
-     */
1739
-    public function get_model()
1740
-    {
1741
-        $modelName = self::_get_model_classname(get_class($this));
1742
-        return self::_get_model_instance_with_name($modelName, $this->_timezone);
1743
-    }
1744
-
1745
-
1746
-
1747
-    /**
1748
-     * @param $props_n_values
1749
-     * @param $classname
1750
-     * @return mixed bool|EE_Base_Class|EEM_CPT_Base
1751
-     * @throws \EE_Error
1752
-     */
1753
-    protected static function _get_object_from_entity_mapper($props_n_values, $classname)
1754
-    {
1755
-        //TODO: will not work for Term_Relationships because they have no PK!
1756
-        $primary_id_ref = self::_get_primary_key_name($classname);
1757
-        if (array_key_exists($primary_id_ref, $props_n_values) && ! empty($props_n_values[$primary_id_ref])) {
1758
-            $id = $props_n_values[$primary_id_ref];
1759
-            return self::_get_model($classname)->get_from_entity_map($id);
1760
-        }
1761
-        return false;
1762
-    }
1763
-
1764
-
1765
-
1766
-    /**
1767
-     * This is called by child static "new_instance" method and we'll check to see if there is an existing db entry for
1768
-     * the primary key (if present in incoming values). If there is a key in the incoming array that matches the
1769
-     * primary key for the model AND it is not null, then we check the db. If there's a an object we return it.  If not
1770
-     * we return false.
1771
-     *
1772
-     * @param  array  $props_n_values   incoming array of properties and their values
1773
-     * @param  string $classname        the classname of the child class
1774
-     * @param null    $timezone
1775
-     * @param array   $date_formats     incoming date_formats in an array where the first value is the
1776
-     *                                  date_format and the second value is the time format
1777
-     * @return mixed (EE_Base_Class|bool)
1778
-     * @throws \EE_Error
1779
-     */
1780
-    protected static function _check_for_object($props_n_values, $classname, $timezone = null, $date_formats = array())
1781
-    {
1782
-        $existing = null;
1783
-        if (self::_get_model($classname)->has_primary_key_field()) {
1784
-            $primary_id_ref = self::_get_primary_key_name($classname);
1785
-            if (array_key_exists($primary_id_ref, $props_n_values)
1786
-                && ! empty($props_n_values[$primary_id_ref])
1787
-            ) {
1788
-                $existing = self::_get_model($classname, $timezone)->get_one_by_ID(
1789
-                    $props_n_values[$primary_id_ref]
1790
-                );
1791
-            }
1792
-        } elseif (self::_get_model($classname, $timezone)->has_all_combined_primary_key_fields($props_n_values)) {
1793
-            //no primary key on this model, but there's still a matching item in the DB
1794
-            $existing = self::_get_model($classname, $timezone)->get_one_by_ID(
1795
-                self::_get_model($classname, $timezone)->get_index_primary_key_string($props_n_values)
1796
-            );
1797
-        }
1798
-        if ($existing) {
1799
-            //set date formats if present before setting values
1800
-            if ( ! empty($date_formats) && is_array($date_formats)) {
1801
-                $existing->set_date_format($date_formats[0]);
1802
-                $existing->set_time_format($date_formats[1]);
1803
-            } else {
1804
-                //set default formats for date and time
1805
-                $existing->set_date_format(get_option('date_format'));
1806
-                $existing->set_time_format(get_option('time_format'));
1807
-            }
1808
-            foreach ($props_n_values as $property => $field_value) {
1809
-                $existing->set($property, $field_value);
1810
-            }
1811
-            return $existing;
1812
-        } else {
1813
-            return false;
1814
-        }
1815
-    }
1816
-
1817
-
1818
-
1819
-    /**
1820
-     * Gets the EEM_*_Model for this class
1821
-     *
1822
-     * @access public now, as this is more convenient
1823
-     * @param      $classname
1824
-     * @param null $timezone
1825
-     * @throws EE_Error
1826
-     * @return EEM_Base
1827
-     */
1828
-    protected static function _get_model($classname, $timezone = null)
1829
-    {
1830
-        //find model for this class
1831
-        if ( ! $classname) {
1832
-            throw new EE_Error(
1833
-                sprintf(
1834
-                    __(
1835
-                        "What were you thinking calling _get_model(%s)?? You need to specify the class name",
1836
-                        "event_espresso"
1837
-                    ),
1838
-                    $classname
1839
-                )
1840
-            );
1841
-        }
1842
-        $modelName = self::_get_model_classname($classname);
1843
-        return self::_get_model_instance_with_name($modelName, $timezone);
1844
-    }
1845
-
1846
-
1847
-
1848
-    /**
1849
-     * Gets the model instance (eg instance of EEM_Attendee) given its classname (eg EE_Attendee)
1850
-     *
1851
-     * @param string $model_classname
1852
-     * @param null   $timezone
1853
-     * @return EEM_Base
1854
-     */
1855
-    protected static function _get_model_instance_with_name($model_classname, $timezone = null)
1856
-    {
1857
-        $model_classname = str_replace('EEM_', '', $model_classname);
1858
-        $model = EE_Registry::instance()->load_model($model_classname);
1859
-        $model->set_timezone($timezone);
1860
-        return $model;
1861
-    }
1862
-
1863
-
1864
-
1865
-    /**
1866
-     * If a model name is provided (eg Registration), gets the model classname for that model.
1867
-     * Also works if a model class's classname is provided (eg EE_Registration).
1868
-     *
1869
-     * @param null $model_name
1870
-     * @return string like EEM_Attendee
1871
-     */
1872
-    private static function _get_model_classname($model_name = null)
1873
-    {
1874
-        if (strpos($model_name, "EE_") === 0) {
1875
-            $model_classname = str_replace("EE_", "EEM_", $model_name);
1876
-        } else {
1877
-            $model_classname = "EEM_" . $model_name;
1878
-        }
1879
-        return $model_classname;
1880
-    }
1881
-
1882
-
1883
-
1884
-    /**
1885
-     * returns the name of the primary key attribute
1886
-     *
1887
-     * @param null $classname
1888
-     * @throws EE_Error
1889
-     * @return string
1890
-     */
1891
-    protected static function _get_primary_key_name($classname = null)
1892
-    {
1893
-        if ( ! $classname) {
1894
-            throw new EE_Error(
1895
-                sprintf(
1896
-                    __("What were you thinking calling _get_primary_key_name(%s)", "event_espresso"),
1897
-                    $classname
1898
-                )
1899
-            );
1900
-        }
1901
-        return self::_get_model($classname)->get_primary_key_field()->get_name();
1902
-    }
1903
-
1904
-
1905
-
1906
-    /**
1907
-     * Gets the value of the primary key.
1908
-     * If the object hasn't yet been saved, it should be whatever the model field's default was
1909
-     * (eg, if this were the EE_Event class, look at the primary key field on EEM_Event and see what its default value
1910
-     * is. Usually defaults for integer primary keys are 0; string primary keys are usually NULL).
1911
-     *
1912
-     * @return mixed, if the primary key is of type INT it'll be an int. Otherwise it could be a string
1913
-     * @throws \EE_Error
1914
-     */
1915
-    public function ID()
1916
-    {
1917
-        //now that we know the name of the variable, use a variable variable to get its value and return its
1918
-        if ($this->get_model()->has_primary_key_field()) {
1919
-            return $this->_fields[self::_get_primary_key_name(get_class($this))];
1920
-        } else {
1921
-            return $this->get_model()->get_index_primary_key_string($this->_fields);
1922
-        }
1923
-    }
1924
-
1925
-
1926
-
1927
-    /**
1928
-     * Adds a relationship to the specified EE_Base_Class object, given the relationship's name. Eg, if the current
1929
-     * model is related to a group of events, the $relationName should be 'Event', and should be a key in the EE
1930
-     * Model's $_model_relations array. If this model object doesn't exist in the DB, just caches the related thing
1931
-     *
1932
-     * @param mixed  $otherObjectModelObjectOrID       EE_Base_Class or the ID of the other object
1933
-     * @param string $relationName                     eg 'Events','Question',etc.
1934
-     *                                                 an attendee to a group, you also want to specify which role they
1935
-     *                                                 will have in that group. So you would use this parameter to
1936
-     *                                                 specify array('role-column-name'=>'role-id')
1937
-     * @param array  $extra_join_model_fields_n_values You can optionally include an array of key=>value pairs that
1938
-     *                                                 allow you to further constrict the relation to being added.
1939
-     *                                                 However, keep in mind that the columns (keys) given must match a
1940
-     *                                                 column on the JOIN table and currently only the HABTM models
1941
-     *                                                 accept these additional conditions.  Also remember that if an
1942
-     *                                                 exact match isn't found for these extra cols/val pairs, then a
1943
-     *                                                 NEW row is created in the join table.
1944
-     * @param null   $cache_id
1945
-     * @throws EE_Error
1946
-     * @return EE_Base_Class the object the relation was added to
1947
-     */
1948
-    public function _add_relation_to(
1949
-        $otherObjectModelObjectOrID,
1950
-        $relationName,
1951
-        $extra_join_model_fields_n_values = array(),
1952
-        $cache_id = null
1953
-    ) {
1954
-        //if this thing exists in the DB, save the relation to the DB
1955
-        if ($this->ID()) {
1956
-            $otherObject = $this->get_model()
1957
-                                ->add_relationship_to($this, $otherObjectModelObjectOrID, $relationName,
1958
-                                    $extra_join_model_fields_n_values);
1959
-            //clear cache so future get_many_related and get_first_related() return new results.
1960
-            $this->clear_cache($relationName, $otherObject, true);
1961
-            if ($otherObject instanceof EE_Base_Class) {
1962
-                $otherObject->clear_cache($this->get_model()->get_this_model_name(), $this);
1963
-            }
1964
-        } else {
1965
-            //this thing doesn't exist in the DB,  so just cache it
1966
-            if ( ! $otherObjectModelObjectOrID instanceof EE_Base_Class) {
1967
-                throw new EE_Error(sprintf(
1968
-                    __('Before a model object is saved to the database, calls to _add_relation_to must be passed an actual object, not just an ID. You provided %s as the model object to a %s',
1969
-                        'event_espresso'),
1970
-                    $otherObjectModelObjectOrID,
1971
-                    get_class($this)
1972
-                ));
1973
-            } else {
1974
-                $otherObject = $otherObjectModelObjectOrID;
1975
-            }
1976
-            $this->cache($relationName, $otherObjectModelObjectOrID, $cache_id);
1977
-        }
1978
-        if ($otherObject instanceof EE_Base_Class) {
1979
-            //fix the reciprocal relation too
1980
-            if ($otherObject->ID()) {
1981
-                //its saved so assumed relations exist in the DB, so we can just
1982
-                //clear the cache so future queries use the updated info in the DB
1983
-                $otherObject->clear_cache($this->get_model()->get_this_model_name(), null, true);
1984
-            } else {
1985
-                //it's not saved, so it caches relations like this
1986
-                $otherObject->cache($this->get_model()->get_this_model_name(), $this);
1987
-            }
1988
-        }
1989
-        return $otherObject;
1990
-    }
1991
-
1992
-
1993
-
1994
-    /**
1995
-     * Removes a relationship to the specified EE_Base_Class object, given the relationships' name. Eg, if the current
1996
-     * model is related to a group of events, the $relationName should be 'Events', and should be a key in the EE
1997
-     * Model's $_model_relations array. If this model object doesn't exist in the DB, just removes the related thing
1998
-     * from the cache
1999
-     *
2000
-     * @param mixed  $otherObjectModelObjectOrID
2001
-     *                EE_Base_Class or the ID of the other object, OR an array key into the cache if this isn't saved
2002
-     *                to the DB yet
2003
-     * @param string $relationName
2004
-     * @param array  $where_query
2005
-     *                You can optionally include an array of key=>value pairs that allow you to further constrict the
2006
-     *                relation to being added. However, keep in mind that the columns (keys) given must match a column
2007
-     *                on the JOIN table and currently only the HABTM models accept these additional conditions. Also
2008
-     *                remember that if an exact match isn't found for these extra cols/val pairs, then a NEW row is
2009
-     *                created in the join table.
2010
-     * @return EE_Base_Class the relation was removed from
2011
-     * @throws \EE_Error
2012
-     */
2013
-    public function _remove_relation_to($otherObjectModelObjectOrID, $relationName, $where_query = array())
2014
-    {
2015
-        if ($this->ID()) {
2016
-            //if this exists in the DB, save the relation change to the DB too
2017
-            $otherObject = $this->get_model()
2018
-                                ->remove_relationship_to($this, $otherObjectModelObjectOrID, $relationName,
2019
-                                    $where_query);
2020
-            $this->clear_cache($relationName, $otherObject);
2021
-        } else {
2022
-            //this doesn't exist in the DB, just remove it from the cache
2023
-            $otherObject = $this->clear_cache($relationName, $otherObjectModelObjectOrID);
2024
-        }
2025
-        if ($otherObject instanceof EE_Base_Class) {
2026
-            $otherObject->clear_cache($this->get_model()->get_this_model_name(), $this);
2027
-        }
2028
-        return $otherObject;
2029
-    }
2030
-
2031
-
2032
-
2033
-    /**
2034
-     * Removes ALL the related things for the $relationName.
2035
-     *
2036
-     * @param string $relationName
2037
-     * @param array  $where_query_params like EEM_Base::get_all's $query_params[0] (where conditions)
2038
-     * @return EE_Base_Class
2039
-     * @throws \EE_Error
2040
-     */
2041
-    public function _remove_relations($relationName, $where_query_params = array())
2042
-    {
2043
-        if ($this->ID()) {
2044
-            //if this exists in the DB, save the relation change to the DB too
2045
-            $otherObjects = $this->get_model()->remove_relations($this, $relationName, $where_query_params);
2046
-            $this->clear_cache($relationName, null, true);
2047
-        } else {
2048
-            //this doesn't exist in the DB, just remove it from the cache
2049
-            $otherObjects = $this->clear_cache($relationName, null, true);
2050
-        }
2051
-        if (is_array($otherObjects)) {
2052
-            foreach ($otherObjects as $otherObject) {
2053
-                $otherObject->clear_cache($this->get_model()->get_this_model_name(), $this);
2054
-            }
2055
-        }
2056
-        return $otherObjects;
2057
-    }
2058
-
2059
-
2060
-
2061
-    /**
2062
-     * Gets all the related model objects of the specified type. Eg, if the current class if
2063
-     * EE_Event, you could call $this->get_many_related('Registration') to get an array of all the
2064
-     * EE_Registration objects which related to this event. Note: by default, we remove the "default query params"
2065
-     * because we want to get even deleted items etc.
2066
-     *
2067
-     * @param string $relationName key in the model's _model_relations array
2068
-     * @param array  $query_params like EEM_Base::get_all
2069
-     * @return EE_Base_Class[] Results not necessarily indexed by IDs, because some results might not have primary keys
2070
-     * @throws \EE_Error
2071
-     *                             or might not be saved yet. Consider using EEM_Base::get_IDs() on these results if
2072
-     *                             you want IDs
2073
-     */
2074
-    public function get_many_related($relationName, $query_params = array())
2075
-    {
2076
-        if ($this->ID()) {
2077
-            //this exists in the DB, so get the related things from either the cache or the DB
2078
-            //if there are query parameters, forget about caching the related model objects.
2079
-            if ($query_params) {
2080
-                $related_model_objects = $this->get_model()->get_all_related($this, $relationName, $query_params);
2081
-            } else {
2082
-                //did we already cache the result of this query?
2083
-                $cached_results = $this->get_all_from_cache($relationName);
2084
-                if ( ! $cached_results) {
2085
-                    $related_model_objects = $this->get_model()->get_all_related($this, $relationName, $query_params);
2086
-                    //if no query parameters were passed, then we got all the related model objects
2087
-                    //for that relation. We can cache them then.
2088
-                    foreach ($related_model_objects as $related_model_object) {
2089
-                        $this->cache($relationName, $related_model_object);
2090
-                    }
2091
-                } else {
2092
-                    $related_model_objects = $cached_results;
2093
-                }
2094
-            }
2095
-        } else {
2096
-            //this doesn't exist in the DB, so just get the related things from the cache
2097
-            $related_model_objects = $this->get_all_from_cache($relationName);
2098
-        }
2099
-        return $related_model_objects;
2100
-    }
2101
-
2102
-
2103
-
2104
-    /**
2105
-     * Instead of getting the related model objects, simply counts them. Ignores default_where_conditions by default,
2106
-     * unless otherwise specified in the $query_params
2107
-     *
2108
-     * @param string $relation_name  model_name like 'Event', or 'Registration'
2109
-     * @param array  $query_params   like EEM_Base::get_all's
2110
-     * @param string $field_to_count name of field to count by. By default, uses primary key
2111
-     * @param bool   $distinct       if we want to only count the distinct values for the column then you can trigger
2112
-     *                               that by the setting $distinct to TRUE;
2113
-     * @return int
2114
-     */
2115
-    public function count_related($relation_name, $query_params = array(), $field_to_count = null, $distinct = false)
2116
-    {
2117
-        return $this->get_model()->count_related($this, $relation_name, $query_params, $field_to_count, $distinct);
2118
-    }
2119
-
2120
-
2121
-
2122
-    /**
2123
-     * Instead of getting the related model objects, simply sums up the values of the specified field.
2124
-     * Note: ignores default_where_conditions by default, unless otherwise specified in the $query_params
2125
-     *
2126
-     * @param string $relation_name model_name like 'Event', or 'Registration'
2127
-     * @param array  $query_params  like EEM_Base::get_all's
2128
-     * @param string $field_to_sum  name of field to count by.
2129
-     *                              By default, uses primary key (which doesn't make much sense, so you should probably
2130
-     *                              change it)
2131
-     * @return int
2132
-     */
2133
-    public function sum_related($relation_name, $query_params = array(), $field_to_sum = null)
2134
-    {
2135
-        return $this->get_model()->sum_related($this, $relation_name, $query_params, $field_to_sum);
2136
-    }
2137
-
2138
-
2139
-
2140
-    /**
2141
-     * Gets the first (ie, one) related model object of the specified type.
2142
-     *
2143
-     * @param string $relationName key in the model's _model_relations array
2144
-     * @param array  $query_params like EEM_Base::get_all
2145
-     * @return EE_Base_Class (not an array, a single object)
2146
-     * @throws \EE_Error
2147
-     */
2148
-    public function get_first_related($relationName, $query_params = array())
2149
-    {
2150
-        if ($this->ID()) {//this exists in the DB, get from the cache OR the DB
2151
-            //if they've provided some query parameters, don't bother trying to cache the result
2152
-            //also make sure we're not caching the result of get_first_related
2153
-            //on a relation which should have an array of objects (because the cache might have an array of objects)
2154
-            if ($query_params
2155
-                || ! $this->get_model()->related_settings_for($relationName)
2156
-                     instanceof
2157
-                     EE_Belongs_To_Relation
2158
-            ) {
2159
-                $related_model_object = $this->get_model()->get_first_related($this, $relationName, $query_params);
2160
-            } else {
2161
-                //first, check if we've already cached the result of this query
2162
-                $cached_result = $this->get_one_from_cache($relationName);
2163
-                if ( ! $cached_result) {
2164
-                    $related_model_object = $this->get_model()->get_first_related($this, $relationName, $query_params);
2165
-                    $this->cache($relationName, $related_model_object);
2166
-                } else {
2167
-                    $related_model_object = $cached_result;
2168
-                }
2169
-            }
2170
-        } else {
2171
-            $related_model_object = null;
2172
-            //this doesn't exist in the Db, but maybe the relation is of type belongs to, and so the related thing might
2173
-            if ($this->get_model()->related_settings_for($relationName) instanceof EE_Belongs_To_Relation) {
2174
-                $related_model_object = $this->get_model()->get_first_related($this, $relationName, $query_params);
2175
-            }
2176
-            //this doesn't exist in the DB and apparently the thing it belongs to doesn't either, just get what's cached on this object
2177
-            if ( ! $related_model_object) {
2178
-                $related_model_object = $this->get_one_from_cache($relationName);
2179
-            }
2180
-        }
2181
-        return $related_model_object;
2182
-    }
2183
-
2184
-
2185
-
2186
-    /**
2187
-     * Does a delete on all related objects of type $relationName and removes
2188
-     * the current model object's relation to them. If they can't be deleted (because
2189
-     * of blocking related model objects) does nothing. If the related model objects are
2190
-     * soft-deletable, they will be soft-deleted regardless of related blocking model objects.
2191
-     * If this model object doesn't exist yet in the DB, just removes its related things
2192
-     *
2193
-     * @param string $relationName
2194
-     * @param array  $query_params like EEM_Base::get_all's
2195
-     * @return int how many deleted
2196
-     * @throws \EE_Error
2197
-     */
2198
-    public function delete_related($relationName, $query_params = array())
2199
-    {
2200
-        if ($this->ID()) {
2201
-            $count = $this->get_model()->delete_related($this, $relationName, $query_params);
2202
-        } else {
2203
-            $count = count($this->get_all_from_cache($relationName));
2204
-            $this->clear_cache($relationName, null, true);
2205
-        }
2206
-        return $count;
2207
-    }
2208
-
2209
-
2210
-
2211
-    /**
2212
-     * Does a hard delete (ie, removes the DB row) on all related objects of type $relationName and removes
2213
-     * the current model object's relation to them. If they can't be deleted (because
2214
-     * of blocking related model objects) just does a soft delete on it instead, if possible.
2215
-     * If the related thing isn't a soft-deletable model object, this function is identical
2216
-     * to delete_related(). If this model object doesn't exist in the DB, just remove its related things
2217
-     *
2218
-     * @param string $relationName
2219
-     * @param array  $query_params like EEM_Base::get_all's
2220
-     * @return int how many deleted (including those soft deleted)
2221
-     * @throws \EE_Error
2222
-     */
2223
-    public function delete_related_permanently($relationName, $query_params = array())
2224
-    {
2225
-        if ($this->ID()) {
2226
-            $count = $this->get_model()->delete_related_permanently($this, $relationName, $query_params);
2227
-        } else {
2228
-            $count = count($this->get_all_from_cache($relationName));
2229
-        }
2230
-        $this->clear_cache($relationName, null, true);
2231
-        return $count;
2232
-    }
2233
-
2234
-
2235
-
2236
-    /**
2237
-     * is_set
2238
-     * Just a simple utility function children can use for checking if property exists
2239
-     *
2240
-     * @access  public
2241
-     * @param  string $field_name property to check
2242
-     * @return bool                              TRUE if existing,FALSE if not.
2243
-     */
2244
-    public function is_set($field_name)
2245
-    {
2246
-        return isset($this->_fields[$field_name]);
2247
-    }
2248
-
2249
-
2250
-
2251
-    /**
2252
-     * Just a simple utility function children can use for checking if property (or properties) exists and throwing an
2253
-     * EE_Error exception if they don't
2254
-     *
2255
-     * @param  mixed (string|array) $properties properties to check
2256
-     * @throws EE_Error
2257
-     * @return bool                              TRUE if existing, throw EE_Error if not.
2258
-     */
2259
-    protected function _property_exists($properties)
2260
-    {
2261
-        foreach ((array)$properties as $property_name) {
2262
-            //first make sure this property exists
2263
-            if ( ! $this->_fields[$property_name]) {
2264
-                throw new EE_Error(
2265
-                    sprintf(
2266
-                        __(
2267
-                            'Trying to retrieve a non-existent property (%s).  Double check the spelling please',
2268
-                            'event_espresso'
2269
-                        ),
2270
-                        $property_name
2271
-                    )
2272
-                );
2273
-            }
2274
-        }
2275
-        return true;
2276
-    }
2277
-
2278
-
2279
-
2280
-    /**
2281
-     * This simply returns an array of model fields for this object
2282
-     *
2283
-     * @return array
2284
-     * @throws \EE_Error
2285
-     */
2286
-    public function model_field_array()
2287
-    {
2288
-        $fields = $this->get_model()->field_settings(false);
2289
-        $properties = array();
2290
-        //remove prepended underscore
2291
-        foreach ($fields as $field_name => $settings) {
2292
-            $properties[$field_name] = $this->get($field_name);
2293
-        }
2294
-        return $properties;
2295
-    }
2296
-
2297
-
2298
-
2299
-    /**
2300
-     * Very handy general function to allow for plugins to extend any child of EE_Base_Class.
2301
-     * If a method is called on a child of EE_Base_Class that doesn't exist, this function is called
2302
-     * (http://www.garfieldtech.com/blog/php-magic-call) and passed the method's name and arguments. Instead of
2303
-     * requiring a plugin to extend the EE_Base_Class (which works fine is there's only 1 plugin, but when will that
2304
-     * happen?) they can add a hook onto 'filters_hook_espresso__{className}__{methodName}' (eg,
2305
-     * filters_hook_espresso__EE_Answer__my_great_function) and accepts 2 arguments: the object on which the function
2306
-     * was called, and an array of the original arguments passed to the function. Whatever their callback function
2307
-     * returns will be returned by this function. Example: in functions.php (or in a plugin):
2308
-     * add_filter('FHEE__EE_Answer__my_callback','my_callback',10,3); function
2309
-     * my_callback($previousReturnValue,EE_Base_Class $object,$argsArray){
2310
-     * $returnString= "you called my_callback! and passed args:".implode(",",$argsArray);
2311
-     *        return $previousReturnValue.$returnString;
2312
-     * }
2313
-     * require('EE_Answer.class.php');
2314
-     * $answer= EE_Answer::new_instance(array('REG_ID' => 2,'QST_ID' => 3,'ANS_value' => The answer is 42'));
2315
-     * echo $answer->my_callback('monkeys',100);
2316
-     * //will output "you called my_callback! and passed args:monkeys,100"
2317
-     *
2318
-     * @param string $methodName name of method which was called on a child of EE_Base_Class, but which
2319
-     * @param array  $args       array of original arguments passed to the function
2320
-     * @throws EE_Error
2321
-     * @return mixed whatever the plugin which calls add_filter decides
2322
-     */
2323
-    public function __call($methodName, $args)
2324
-    {
2325
-        $className = get_class($this);
2326
-        $tagName = "FHEE__{$className}__{$methodName}";
2327
-        if ( ! has_filter($tagName)) {
2328
-            throw new EE_Error(
2329
-                sprintf(
2330
-                    __(
2331
-                        "Method %s on class %s does not exist! You can create one with the following code in functions.php or in a plugin: add_filter('%s','my_callback',10,3);function my_callback(\$previousReturnValue,EE_Base_Class \$object, \$argsArray){/*function body*/return \$whatever;}",
2332
-                        "event_espresso"
2333
-                    ),
2334
-                    $methodName,
2335
-                    $className,
2336
-                    $tagName
2337
-                )
2338
-            );
2339
-        }
2340
-        return apply_filters($tagName, null, $this, $args);
2341
-    }
2342
-
2343
-
2344
-
2345
-    /**
2346
-     * Similar to insert_post_meta, adds a record in the Extra_Meta model's table with the given key and value.
2347
-     * A $previous_value can be specified in case there are many meta rows with the same key
2348
-     *
2349
-     * @param string $meta_key
2350
-     * @param string $meta_value
2351
-     * @param string $previous_value
2352
-     * @return int records updated (or BOOLEAN if we actually ended up inserting the extra meta row)
2353
-     * @throws \EE_Error
2354
-     * NOTE: if the values haven't changed, returns 0
2355
-     */
2356
-    public function update_extra_meta($meta_key, $meta_value, $previous_value = null)
2357
-    {
2358
-        $query_params = array(
2359
-            array(
2360
-                'EXM_key'  => $meta_key,
2361
-                'OBJ_ID'   => $this->ID(),
2362
-                'EXM_type' => $this->get_model()->get_this_model_name(),
2363
-            ),
2364
-        );
2365
-        if ($previous_value !== null) {
2366
-            $query_params[0]['EXM_value'] = $meta_value;
2367
-        }
2368
-        $existing_rows_like_that = EEM_Extra_Meta::instance()->get_all($query_params);
2369
-        if ( ! $existing_rows_like_that) {
2370
-            return $this->add_extra_meta($meta_key, $meta_value);
2371
-        } else {
2372
-            foreach ($existing_rows_like_that as $existing_row) {
2373
-                $existing_row->save(array('EXM_value' => $meta_value));
2374
-            }
2375
-            return count($existing_rows_like_that);
2376
-        }
2377
-    }
2378
-
2379
-
2380
-
2381
-    /**
2382
-     * Adds a new extra meta record. If $unique is set to TRUE, we'll first double-check
2383
-     * no other extra meta for this model object have the same key. Returns TRUE if the
2384
-     * extra meta row was entered, false if not
2385
-     *
2386
-     * @param string  $meta_key
2387
-     * @param string  $meta_value
2388
-     * @param boolean $unique
2389
-     * @return boolean
2390
-     * @throws \EE_Error
2391
-     */
2392
-    public function add_extra_meta($meta_key, $meta_value, $unique = false)
2393
-    {
2394
-        if ($unique) {
2395
-            $existing_extra_meta = EEM_Extra_Meta::instance()->get_one(
2396
-                array(
2397
-                    array(
2398
-                        'EXM_key'  => $meta_key,
2399
-                        'OBJ_ID'   => $this->ID(),
2400
-                        'EXM_type' => $this->get_model()->get_this_model_name(),
2401
-                    ),
2402
-                )
2403
-            );
2404
-            if ($existing_extra_meta) {
2405
-                return false;
2406
-            }
2407
-        }
2408
-        $new_extra_meta = EE_Extra_Meta::new_instance(
2409
-            array(
2410
-                'EXM_key'   => $meta_key,
2411
-                'EXM_value' => $meta_value,
2412
-                'OBJ_ID'    => $this->ID(),
2413
-                'EXM_type'  => $this->get_model()->get_this_model_name(),
2414
-            )
2415
-        );
2416
-        $new_extra_meta->save();
2417
-        return true;
2418
-    }
2419
-
2420
-
2421
-
2422
-    /**
2423
-     * Deletes all the extra meta rows for this record as specified by key. If $meta_value
2424
-     * is specified, only deletes extra meta records with that value.
2425
-     *
2426
-     * @param string $meta_key
2427
-     * @param string $meta_value
2428
-     * @return int number of extra meta rows deleted
2429
-     * @throws \EE_Error
2430
-     */
2431
-    public function delete_extra_meta($meta_key, $meta_value = null)
2432
-    {
2433
-        $query_params = array(
2434
-            array(
2435
-                'EXM_key'  => $meta_key,
2436
-                'OBJ_ID'   => $this->ID(),
2437
-                'EXM_type' => $this->get_model()->get_this_model_name(),
2438
-            ),
2439
-        );
2440
-        if ($meta_value !== null) {
2441
-            $query_params[0]['EXM_value'] = $meta_value;
2442
-        }
2443
-        return EEM_Extra_Meta::instance()->delete($query_params);
2444
-    }
2445
-
2446
-
2447
-
2448
-    /**
2449
-     * Gets the extra meta with the given meta key. If you specify "single" we just return 1, otherwise
2450
-     * an array of everything found. Requires that this model actually have a relation of type EE_Has_Many_Any_Relation.
2451
-     * You can specify $default is case you haven't found the extra meta
2452
-     *
2453
-     * @param string  $meta_key
2454
-     * @param boolean $single
2455
-     * @param mixed   $default if we don't find anything, what should we return?
2456
-     * @return mixed single value if $single; array if ! $single
2457
-     * @throws \EE_Error
2458
-     */
2459
-    public function get_extra_meta($meta_key, $single = false, $default = null)
2460
-    {
2461
-        if ($single) {
2462
-            $result = $this->get_first_related('Extra_Meta', array(array('EXM_key' => $meta_key)));
2463
-            if ($result instanceof EE_Extra_Meta) {
2464
-                return $result->value();
2465
-            } else {
2466
-                return $default;
2467
-            }
2468
-        } else {
2469
-            $results = $this->get_many_related('Extra_Meta', array(array('EXM_key' => $meta_key)));
2470
-            if ($results) {
2471
-                $values = array();
2472
-                foreach ($results as $result) {
2473
-                    if ($result instanceof EE_Extra_Meta) {
2474
-                        $values[$result->ID()] = $result->value();
2475
-                    }
2476
-                }
2477
-                return $values;
2478
-            } else {
2479
-                return $default;
2480
-            }
2481
-        }
2482
-    }
2483
-
2484
-
2485
-
2486
-    /**
2487
-     * Returns a simple array of all the extra meta associated with this model object.
2488
-     * If $one_of_each_key is true (Default), it will be an array of simple key-value pairs, keys being the
2489
-     * extra meta's key, and teh value being its value. However, if there are duplicate extra meta rows with
2490
-     * the same key, only one will be used. (eg array('foo'=>'bar','monkey'=>123))
2491
-     * If $one_of_each_key is false, it will return an array with the top-level keys being
2492
-     * the extra meta keys, but their values are also arrays, which have the extra-meta's ID as their sub-key, and
2493
-     * finally the extra meta's value as each sub-value. (eg
2494
-     * array('foo'=>array(1=>'bar',2=>'bill'),'monkey'=>array(3=>123)))
2495
-     *
2496
-     * @param boolean $one_of_each_key
2497
-     * @return array
2498
-     * @throws \EE_Error
2499
-     */
2500
-    public function all_extra_meta_array($one_of_each_key = true)
2501
-    {
2502
-        $return_array = array();
2503
-        if ($one_of_each_key) {
2504
-            $extra_meta_objs = $this->get_many_related('Extra_Meta', array('group_by' => 'EXM_key'));
2505
-            foreach ($extra_meta_objs as $extra_meta_obj) {
2506
-                if ($extra_meta_obj instanceof EE_Extra_Meta) {
2507
-                    $return_array[$extra_meta_obj->key()] = $extra_meta_obj->value();
2508
-                }
2509
-            }
2510
-        } else {
2511
-            $extra_meta_objs = $this->get_many_related('Extra_Meta');
2512
-            foreach ($extra_meta_objs as $extra_meta_obj) {
2513
-                if ($extra_meta_obj instanceof EE_Extra_Meta) {
2514
-                    if ( ! isset($return_array[$extra_meta_obj->key()])) {
2515
-                        $return_array[$extra_meta_obj->key()] = array();
2516
-                    }
2517
-                    $return_array[$extra_meta_obj->key()][$extra_meta_obj->ID()] = $extra_meta_obj->value();
2518
-                }
2519
-            }
2520
-        }
2521
-        return $return_array;
2522
-    }
2523
-
2524
-
2525
-
2526
-    /**
2527
-     * Gets a pretty nice displayable nice for this model object. Often overridden
2528
-     *
2529
-     * @return string
2530
-     * @throws \EE_Error
2531
-     */
2532
-    public function name()
2533
-    {
2534
-        //find a field that's not a text field
2535
-        $field_we_can_use = $this->get_model()->get_a_field_of_type('EE_Text_Field_Base');
2536
-        if ($field_we_can_use) {
2537
-            return $this->get($field_we_can_use->get_name());
2538
-        } else {
2539
-            $first_few_properties = $this->model_field_array();
2540
-            $first_few_properties = array_slice($first_few_properties, 0, 3);
2541
-            $name_parts = array();
2542
-            foreach ($first_few_properties as $name => $value) {
2543
-                $name_parts[] = "$name:$value";
2544
-            }
2545
-            return implode(",", $name_parts);
2546
-        }
2547
-    }
2548
-
2549
-
2550
-
2551
-    /**
2552
-     * in_entity_map
2553
-     * Checks if this model object has been proven to already be in the entity map
2554
-     *
2555
-     * @return boolean
2556
-     * @throws \EE_Error
2557
-     */
2558
-    public function in_entity_map()
2559
-    {
2560
-        if ($this->ID() && $this->get_model()->get_from_entity_map($this->ID()) === $this) {
2561
-            //well, if we looked, did we find it in the entity map?
2562
-            return true;
2563
-        } else {
2564
-            return false;
2565
-        }
2566
-    }
2567
-
2568
-
2569
-
2570
-    /**
2571
-     * refresh_from_db
2572
-     * Makes sure the fields and values on this model object are in-sync with what's in the database.
2573
-     *
2574
-     * @throws EE_Error if this model object isn't in the entity mapper (because then you should
2575
-     * just use what's in the entity mapper and refresh it) and WP_DEBUG is TRUE
2576
-     */
2577
-    public function refresh_from_db()
2578
-    {
2579
-        if ($this->ID() && $this->in_entity_map()) {
2580
-            $this->get_model()->refresh_entity_map_from_db($this->ID());
2581
-        } else {
2582
-            //if it doesn't have ID, you shouldn't be asking to refresh it from teh database (because its not in the database)
2583
-            //if it has an ID but it's not in the map, and you're asking me to refresh it
2584
-            //that's kinda dangerous. You should just use what's in the entity map, or add this to the entity map if there's
2585
-            //absolutely nothing in it for this ID
2586
-            if (WP_DEBUG) {
2587
-                throw new EE_Error(
2588
-                    sprintf(
2589
-                        __('Trying to refresh a model object with ID "%1$s" that\'s not in the entity map? First off: you should put it in the entity map by calling %2$s. Second off, if you want what\'s in the database right now, you should just call %3$s yourself and discard this model object.',
2590
-                            'event_espresso'),
2591
-                        $this->ID(),
2592
-                        get_class($this->get_model()) . '::instance()->add_to_entity_map()',
2593
-                        get_class($this->get_model()) . '::instance()->refresh_entity_map()'
2594
-                    )
2595
-                );
2596
-            }
2597
-        }
2598
-    }
2599
-
2600
-
2601
-
2602
-    /**
2603
-     * Because some other plugins, like Advanced Cron Manager, expect all objects to have this method
2604
-     * (probably a bad assumption they have made, oh well)
2605
-     *
2606
-     * @return string
2607
-     */
2608
-    public function __toString()
2609
-    {
2610
-        try {
2611
-            return sprintf('%s (%s)', $this->name(), $this->ID());
2612
-        } catch (Exception $e) {
2613
-            EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
2614
-            return '';
2615
-        }
2616
-    }
2617
-
2618
-
2619
-
2620
-    /**
2621
-     * Clear related model objects if they're already in the DB, because otherwise when we
2622
-     * UN-serialize this model object we'll need to be careful to add them to the entity map.
2623
-     * This means if we have made changes to those related model objects, and want to unserialize
2624
-     * the this model object on a subsequent request, changes to those related model objects will be lost.
2625
-     * Instead, those related model objects should be directly serialized and stored.
2626
-     * Eg, the following won't work:
2627
-     * $reg = EEM_Registration::instance()->get_one_by_ID( 123 );
2628
-     * $att = $reg->attendee();
2629
-     * $att->set( 'ATT_fname', 'Dirk' );
2630
-     * update_option( 'my_option', serialize( $reg ) );
2631
-     * //END REQUEST
2632
-     * //START NEXT REQUEST
2633
-     * $reg = get_option( 'my_option' );
2634
-     * $reg->attendee()->save();
2635
-     * And would need to be replace with:
2636
-     * $reg = EEM_Registration::instance()->get_one_by_ID( 123 );
2637
-     * $att = $reg->attendee();
2638
-     * $att->set( 'ATT_fname', 'Dirk' );
2639
-     * update_option( 'my_option', serialize( $reg ) );
2640
-     * //END REQUEST
2641
-     * //START NEXT REQUEST
2642
-     * $att = get_option( 'my_option' );
2643
-     * $att->save();
2644
-     *
2645
-     * @return array
2646
-     * @throws \EE_Error
2647
-     */
2648
-    public function __sleep()
2649
-    {
2650
-        foreach ($this->get_model()->relation_settings() as $relation_name => $relation_obj) {
2651
-            if ($relation_obj instanceof EE_Belongs_To_Relation) {
2652
-                $classname = 'EE_' . $this->get_model()->get_this_model_name();
2653
-                if (
2654
-                    $this->get_one_from_cache($relation_name) instanceof $classname
2655
-                    && $this->get_one_from_cache($relation_name)->ID()
2656
-                ) {
2657
-                    $this->clear_cache($relation_name, $this->get_one_from_cache($relation_name)->ID());
2658
-                }
2659
-            }
2660
-        }
2661
-        $this->_props_n_values_provided_in_constructor = array();
2662
-        return array_keys(get_object_vars($this));
2663
-    }
2664
-
2665
-
2666
-
2667
-    /**
2668
-     * restore _props_n_values_provided_in_constructor
2669
-     * PLZ NOTE: this will reset the array to whatever fields values were present prior to serialization,
2670
-     * and therefore should NOT be used to determine if state change has occurred since initial construction.
2671
-     * At best, you would only be able to detect if state change has occurred during THIS request.
2672
-     */
2673
-    public function __wakeup()
2674
-    {
2675
-        $this->_props_n_values_provided_in_constructor = $this->_fields;
2676
-    }
28
+	/**
29
+	 * This is an array of the original properties and values provided during construction
30
+	 * of this model object. (keys are model field names, values are their values).
31
+	 * This list is important to remember so that when we are merging data from the db, we know
32
+	 * which values to override and which to not override.
33
+	 *
34
+	 * @var array
35
+	 */
36
+	protected $_props_n_values_provided_in_constructor;
37
+
38
+	/**
39
+	 * Timezone
40
+	 * This gets set by the "set_timezone()" method so that we know what timezone incoming strings|timestamps are in.
41
+	 * This can also be used before a get to set what timezone you want strings coming out of the object to be in.  NOT
42
+	 * all EE_Base_Class child classes use this property but any that use a EE_Datetime_Field data type will have
43
+	 * access to it.
44
+	 *
45
+	 * @var string
46
+	 */
47
+	protected $_timezone;
48
+
49
+
50
+
51
+	/**
52
+	 * date format
53
+	 * pattern or format for displaying dates
54
+	 *
55
+	 * @var string $_dt_frmt
56
+	 */
57
+	protected $_dt_frmt;
58
+
59
+
60
+
61
+	/**
62
+	 * time format
63
+	 * pattern or format for displaying time
64
+	 *
65
+	 * @var string $_tm_frmt
66
+	 */
67
+	protected $_tm_frmt;
68
+
69
+
70
+
71
+	/**
72
+	 * This property is for holding a cached array of object properties indexed by property name as the key.
73
+	 * The purpose of this is for setting a cache on properties that may have calculated values after a
74
+	 * prepare_for_get.  That way the cache can be checked first and the calculated property returned instead of having
75
+	 * to recalculate. Used by _set_cached_property() and _get_cached_property() methods.
76
+	 *
77
+	 * @var array
78
+	 */
79
+	protected $_cached_properties = array();
80
+
81
+	/**
82
+	 * An array containing keys of the related model, and values are either an array of related mode objects or a
83
+	 * single
84
+	 * related model object. see the model's _model_relations. The keys should match those specified. And if the
85
+	 * relation is of type EE_Belongs_To (or one of its children), then there should only be ONE related model object,
86
+	 * all others have an array)
87
+	 *
88
+	 * @var array
89
+	 */
90
+	protected $_model_relations = array();
91
+
92
+	/**
93
+	 * Array where keys are field names (see the model's _fields property) and values are their values. To see what
94
+	 * their types should be, look at what that field object returns on its prepare_for_get and prepare_for_set methods)
95
+	 *
96
+	 * @var array
97
+	 */
98
+	protected $_fields = array();
99
+
100
+	/**
101
+	 * @var boolean indicating whether or not this model object is intended to ever be saved
102
+	 * For example, we might create model objects intended to only be used for the duration
103
+	 * of this request and to be thrown away, and if they were accidentally saved
104
+	 * it would be a bug.
105
+	 */
106
+	protected $_allow_persist = true;
107
+
108
+
109
+
110
+	/**
111
+	 * basic constructor for Event Espresso classes, performs any necessary initialization, and verifies it's children
112
+	 * play nice
113
+	 *
114
+	 * @param array   $fieldValues                             where each key is a field (ie, array key in the 2nd
115
+	 *                                                         layer of the model's _fields array, (eg, EVT_ID,
116
+	 *                                                         TXN_amount, QST_name, etc) and values are their values
117
+	 * @param boolean $bydb                                    a flag for setting if the class is instantiated by the
118
+	 *                                                         corresponding db model or not.
119
+	 * @param string  $timezone                                indicate what timezone you want any datetime fields to
120
+	 *                                                         be in when instantiating a EE_Base_Class object.
121
+	 * @param array   $date_formats                            An array of date formats to set on construct where first
122
+	 *                                                         value is the date_format and second value is the time
123
+	 *                                                         format.
124
+	 * @throws EE_Error
125
+	 */
126
+	protected function __construct($fieldValues = array(), $bydb = false, $timezone = '', $date_formats = array())
127
+	{
128
+		$className = get_class($this);
129
+		do_action("AHEE__{$className}__construct", $this, $fieldValues);
130
+		$model = $this->get_model();
131
+		$model_fields = $model->field_settings(false);
132
+		// ensure $fieldValues is an array
133
+		$fieldValues = is_array($fieldValues) ? $fieldValues : array($fieldValues);
134
+		// EEH_Debug_Tools::printr( $fieldValues, '$fieldValues  <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' );
135
+		// verify client code has not passed any invalid field names
136
+		foreach ($fieldValues as $field_name => $field_value) {
137
+			if ( ! isset($model_fields[$field_name])) {
138
+				throw new EE_Error(sprintf(__("Invalid field (%s) passed to constructor of %s. Allowed fields are :%s",
139
+					"event_espresso"), $field_name, get_class($this), implode(", ", array_keys($model_fields))));
140
+			}
141
+		}
142
+		// EEH_Debug_Tools::printr( $model_fields, '$model_fields  <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' );
143
+		$this->_timezone = EEH_DTT_Helper::get_valid_timezone_string($timezone);
144
+		if ( ! empty($date_formats) && is_array($date_formats)) {
145
+			list($this->_dt_frmt, $this->_tm_frmt) = $date_formats;
146
+		} else {
147
+			//set default formats for date and time
148
+			$this->_dt_frmt = (string)get_option('date_format', 'Y-m-d');
149
+			$this->_tm_frmt = (string)get_option('time_format', 'g:i a');
150
+		}
151
+		//if db model is instantiating
152
+		if ($bydb) {
153
+			//client code has indicated these field values are from the database
154
+			foreach ($model_fields as $fieldName => $field) {
155
+				$this->set_from_db($fieldName, isset($fieldValues[$fieldName]) ? $fieldValues[$fieldName] : null);
156
+			}
157
+		} else {
158
+			//we're constructing a brand
159
+			//new instance of the model object. Generally, this means we'll need to do more field validation
160
+			foreach ($model_fields as $fieldName => $field) {
161
+				$this->set($fieldName, isset($fieldValues[$fieldName]) ? $fieldValues[$fieldName] : null, true);
162
+			}
163
+		}
164
+		//remember what values were passed to this constructor
165
+		$this->_props_n_values_provided_in_constructor = $fieldValues;
166
+		//remember in entity mapper
167
+		if ( ! $bydb && $model->has_primary_key_field() && $this->ID()) {
168
+			$model->add_to_entity_map($this);
169
+		}
170
+		//setup all the relations
171
+		foreach ($this->get_model()->relation_settings() as $relation_name => $relation_obj) {
172
+			if ($relation_obj instanceof EE_Belongs_To_Relation) {
173
+				$this->_model_relations[$relation_name] = null;
174
+			} else {
175
+				$this->_model_relations[$relation_name] = array();
176
+			}
177
+		}
178
+		/**
179
+		 * Action done at the end of each model object construction
180
+		 *
181
+		 * @param EE_Base_Class $this the model object just created
182
+		 */
183
+		do_action('AHEE__EE_Base_Class__construct__finished', $this);
184
+	}
185
+
186
+
187
+
188
+	/**
189
+	 * Gets whether or not this model object is allowed to persist/be saved to the database.
190
+	 *
191
+	 * @return boolean
192
+	 */
193
+	public function allow_persist()
194
+	{
195
+		return $this->_allow_persist;
196
+	}
197
+
198
+
199
+
200
+	/**
201
+	 * Sets whether or not this model object should be allowed to be saved to the DB.
202
+	 * Normally once this is set to FALSE you wouldn't set it back to TRUE, unless
203
+	 * you got new information that somehow made you change your mind.
204
+	 *
205
+	 * @param boolean $allow_persist
206
+	 * @return boolean
207
+	 */
208
+	public function set_allow_persist($allow_persist)
209
+	{
210
+		return $this->_allow_persist = $allow_persist;
211
+	}
212
+
213
+
214
+
215
+	/**
216
+	 * Gets the field's original value when this object was constructed during this request.
217
+	 * This can be helpful when determining if a model object has changed or not
218
+	 *
219
+	 * @param string $field_name
220
+	 * @return mixed|null
221
+	 * @throws \EE_Error
222
+	 */
223
+	public function get_original($field_name)
224
+	{
225
+		if (isset($this->_props_n_values_provided_in_constructor[$field_name])
226
+			&& $field_settings = $this->get_model()->field_settings_for($field_name)
227
+		) {
228
+			return $field_settings->prepare_for_get($this->_props_n_values_provided_in_constructor[$field_name]);
229
+		} else {
230
+			return null;
231
+		}
232
+	}
233
+
234
+
235
+
236
+	/**
237
+	 * @param EE_Base_Class $obj
238
+	 * @return string
239
+	 */
240
+	public function get_class($obj)
241
+	{
242
+		return get_class($obj);
243
+	}
244
+
245
+
246
+
247
+	/**
248
+	 * Overrides parent because parent expects old models.
249
+	 * This also doesn't do any validation, and won't work for serialized arrays
250
+	 *
251
+	 * @param    string $field_name
252
+	 * @param    mixed  $field_value
253
+	 * @param bool      $use_default
254
+	 * @throws \EE_Error
255
+	 */
256
+	public function set($field_name, $field_value, $use_default = false)
257
+	{
258
+		$field_obj = $this->get_model()->field_settings_for($field_name);
259
+		if ($field_obj instanceof EE_Model_Field_Base) {
260
+			//			if ( method_exists( $field_obj, 'set_timezone' )) {
261
+			if ($field_obj instanceof EE_Datetime_Field) {
262
+				$field_obj->set_timezone($this->_timezone);
263
+				$field_obj->set_date_format($this->_dt_frmt);
264
+				$field_obj->set_time_format($this->_tm_frmt);
265
+			}
266
+			$holder_of_value = $field_obj->prepare_for_set($field_value);
267
+			//should the value be null?
268
+			if (($field_value === null || $holder_of_value === null || $holder_of_value === '') && $use_default) {
269
+				$this->_fields[$field_name] = $field_obj->get_default_value();
270
+				/**
271
+				 * To save having to refactor all the models, if a default value is used for a
272
+				 * EE_Datetime_Field, and that value is not null nor is it a DateTime
273
+				 * object.  Then let's do a set again to ensure that it becomes a DateTime
274
+				 * object.
275
+				 *
276
+				 * @since 4.6.10+
277
+				 */
278
+				if (
279
+					$field_obj instanceof EE_Datetime_Field
280
+					&& $this->_fields[$field_name] !== null
281
+					&& ! $this->_fields[$field_name] instanceof DateTime
282
+				) {
283
+					empty($this->_fields[$field_name])
284
+						? $this->set($field_name, time())
285
+						: $this->set($field_name, $this->_fields[$field_name]);
286
+				}
287
+			} else {
288
+				$this->_fields[$field_name] = $holder_of_value;
289
+			}
290
+			//if we're not in the constructor...
291
+			//now check if what we set was a primary key
292
+			if (
293
+				//note: props_n_values_provided_in_constructor is only set at the END of the constructor
294
+				$this->_props_n_values_provided_in_constructor
295
+				&& $field_value
296
+				&& $field_name === self::_get_primary_key_name(get_class($this))
297
+			) {
298
+				//if so, we want all this object's fields to be filled either with
299
+				//what we've explicitly set on this model
300
+				//or what we have in the db
301
+				// echo "setting primary key!";
302
+				$fields_on_model = self::_get_model(get_class($this))->field_settings();
303
+				$obj_in_db = self::_get_model(get_class($this))->get_one_by_ID($field_value);
304
+				foreach ($fields_on_model as $field_obj) {
305
+					if ( ! array_key_exists($field_obj->get_name(), $this->_props_n_values_provided_in_constructor)
306
+						 && $field_obj->get_name() !== $field_name
307
+					) {
308
+						$this->set($field_obj->get_name(), $obj_in_db->get($field_obj->get_name()));
309
+					}
310
+				}
311
+				//oh this model object has an ID? well make sure its in the entity mapper
312
+				$this->get_model()->add_to_entity_map($this);
313
+			}
314
+			//let's unset any cache for this field_name from the $_cached_properties property.
315
+			$this->_clear_cached_property($field_name);
316
+		} else {
317
+			throw new EE_Error(sprintf(__("A valid EE_Model_Field_Base could not be found for the given field name: %s",
318
+				"event_espresso"), $field_name));
319
+		}
320
+	}
321
+
322
+
323
+
324
+	/**
325
+	 * This sets the field value on the db column if it exists for the given $column_name or
326
+	 * saves it to EE_Extra_Meta if the given $column_name does not match a db column.
327
+	 *
328
+	 * @see EE_message::get_column_value for related documentation on the necessity of this method.
329
+	 * @param string $field_name  Must be the exact column name.
330
+	 * @param mixed  $field_value The value to set.
331
+	 * @return int|bool @see EE_Base_Class::update_extra_meta() for return docs.
332
+	 * @throws \EE_Error
333
+	 */
334
+	public function set_field_or_extra_meta($field_name, $field_value)
335
+	{
336
+		if ($this->get_model()->has_field($field_name)) {
337
+			$this->set($field_name, $field_value);
338
+			return true;
339
+		} else {
340
+			//ensure this object is saved first so that extra meta can be properly related.
341
+			$this->save();
342
+			return $this->update_extra_meta($field_name, $field_value);
343
+		}
344
+	}
345
+
346
+
347
+
348
+	/**
349
+	 * This retrieves the value of the db column set on this class or if that's not present
350
+	 * it will attempt to retrieve from extra_meta if found.
351
+	 * Example Usage:
352
+	 * Via EE_Message child class:
353
+	 * Due to the dynamic nature of the EE_messages system, EE_messengers will always have a "to",
354
+	 * "from", "subject", and "content" field (as represented in the EE_Message schema), however they may
355
+	 * also have additional main fields specific to the messenger.  The system accommodates those extra
356
+	 * fields through the EE_Extra_Meta table.  This method allows for EE_messengers to retrieve the
357
+	 * value for those extra fields dynamically via the EE_message object.
358
+	 *
359
+	 * @param  string $field_name expecting the fully qualified field name.
360
+	 * @return mixed|null  value for the field if found.  null if not found.
361
+	 * @throws \EE_Error
362
+	 */
363
+	public function get_field_or_extra_meta($field_name)
364
+	{
365
+		if ($this->get_model()->has_field($field_name)) {
366
+			$column_value = $this->get($field_name);
367
+		} else {
368
+			//This isn't a column in the main table, let's see if it is in the extra meta.
369
+			$column_value = $this->get_extra_meta($field_name, true, null);
370
+		}
371
+		return $column_value;
372
+	}
373
+
374
+
375
+
376
+	/**
377
+	 * See $_timezone property for description of what the timezone property is for.  This SETS the timezone internally
378
+	 * for being able to reference what timezone we are running conversions on when converting TO the internal timezone
379
+	 * (UTC Unix Timestamp) for the object OR when converting FROM the internal timezone (UTC Unix Timestamp). This is
380
+	 * available to all child classes that may be using the EE_Datetime_Field for a field data type.
381
+	 *
382
+	 * @access public
383
+	 * @param string $timezone A valid timezone string as described by @link http://www.php.net/manual/en/timezones.php
384
+	 * @return void
385
+	 * @throws \EE_Error
386
+	 */
387
+	public function set_timezone($timezone = '')
388
+	{
389
+		$this->_timezone = EEH_DTT_Helper::get_valid_timezone_string($timezone);
390
+		//make sure we clear all cached properties because they won't be relevant now
391
+		$this->_clear_cached_properties();
392
+		//make sure we update field settings and the date for all EE_Datetime_Fields
393
+		$model_fields = $this->get_model()->field_settings(false);
394
+		foreach ($model_fields as $field_name => $field_obj) {
395
+			if ($field_obj instanceof EE_Datetime_Field) {
396
+				$field_obj->set_timezone($this->_timezone);
397
+				if (isset($this->_fields[$field_name]) && $this->_fields[$field_name] instanceof DateTime) {
398
+					$this->_fields[$field_name]->setTimezone(new DateTimeZone($this->_timezone));
399
+				}
400
+			}
401
+		}
402
+	}
403
+
404
+
405
+
406
+	/**
407
+	 * This just returns whatever is set for the current timezone.
408
+	 *
409
+	 * @access public
410
+	 * @return string timezone string
411
+	 */
412
+	public function get_timezone()
413
+	{
414
+		return $this->_timezone;
415
+	}
416
+
417
+
418
+
419
+	/**
420
+	 * This sets the internal date format to what is sent in to be used as the new default for the class
421
+	 * internally instead of wp set date format options
422
+	 *
423
+	 * @since 4.6
424
+	 * @param string $format should be a format recognizable by PHP date() functions.
425
+	 */
426
+	public function set_date_format($format)
427
+	{
428
+		$this->_dt_frmt = $format;
429
+		//clear cached_properties because they won't be relevant now.
430
+		$this->_clear_cached_properties();
431
+	}
432
+
433
+
434
+
435
+	/**
436
+	 * This sets the internal time format string to what is sent in to be used as the new default for the
437
+	 * class internally instead of wp set time format options.
438
+	 *
439
+	 * @since 4.6
440
+	 * @param string $format should be a format recognizable by PHP date() functions.
441
+	 */
442
+	public function set_time_format($format)
443
+	{
444
+		$this->_tm_frmt = $format;
445
+		//clear cached_properties because they won't be relevant now.
446
+		$this->_clear_cached_properties();
447
+	}
448
+
449
+
450
+
451
+	/**
452
+	 * This returns the current internal set format for the date and time formats.
453
+	 *
454
+	 * @param bool $full           if true (default), then return the full format.  Otherwise will return an array
455
+	 *                             where the first value is the date format and the second value is the time format.
456
+	 * @return mixed string|array
457
+	 */
458
+	public function get_format($full = true)
459
+	{
460
+		return $full ? $this->_dt_frmt . ' ' . $this->_tm_frmt : array($this->_dt_frmt, $this->_tm_frmt);
461
+	}
462
+
463
+
464
+
465
+	/**
466
+	 * cache
467
+	 * stores the passed model object on the current model object.
468
+	 * In certain circumstances, we can use this cached model object instead of querying for another one entirely.
469
+	 *
470
+	 * @param string        $relationName    one of the keys in the _model_relations array on the model. Eg
471
+	 *                                       'Registration' associated with this model object
472
+	 * @param EE_Base_Class $object_to_cache that has a relation to this model object. (Eg, if this is a Transaction,
473
+	 *                                       that could be a payment or a registration)
474
+	 * @param null          $cache_id        a string or number that will be used as the key for any Belongs_To_Many
475
+	 *                                       items which will be stored in an array on this object
476
+	 * @throws EE_Error
477
+	 * @return mixed    index into cache, or just TRUE if the relation is of type Belongs_To (because there's only one
478
+	 *                  related thing, no array)
479
+	 */
480
+	public function cache($relationName = '', $object_to_cache = null, $cache_id = null)
481
+	{
482
+		// its entirely possible that there IS no related object yet in which case there is nothing to cache.
483
+		if ( ! $object_to_cache instanceof EE_Base_Class) {
484
+			return false;
485
+		}
486
+		// also get "how" the object is related, or throw an error
487
+		if ( ! $relationship_to_model = $this->get_model()->related_settings_for($relationName)) {
488
+			throw new EE_Error(sprintf(__('There is no relationship to %s on a %s. Cannot cache it', 'event_espresso'),
489
+				$relationName, get_class($this)));
490
+		}
491
+		// how many things are related ?
492
+		if ($relationship_to_model instanceof EE_Belongs_To_Relation) {
493
+			// if it's a "belongs to" relationship, then there's only one related model object  eg, if this is a registration, there's only 1 attendee for it
494
+			// so for these model objects just set it to be cached
495
+			$this->_model_relations[$relationName] = $object_to_cache;
496
+			$return = true;
497
+		} else {
498
+			// otherwise, this is the "many" side of a one to many relationship, so we'll add the object to the array of related objects for that type.
499
+			// eg: if this is an event, there are many registrations for that event, so we cache the registrations in an array
500
+			if ( ! is_array($this->_model_relations[$relationName])) {
501
+				// if for some reason, the cached item is a model object, then stick that in the array, otherwise start with an empty array
502
+				$this->_model_relations[$relationName] = $this->_model_relations[$relationName] instanceof EE_Base_Class
503
+					? array($this->_model_relations[$relationName]) : array();
504
+			}
505
+			// first check for a cache_id which is normally empty
506
+			if ( ! empty($cache_id)) {
507
+				// if the cache_id exists, then it means we are purposely trying to cache this with a known key that can then be used to retrieve the object later on
508
+				$this->_model_relations[$relationName][$cache_id] = $object_to_cache;
509
+				$return = $cache_id;
510
+			} elseif ($object_to_cache->ID()) {
511
+				// OR the cached object originally came from the db, so let's just use it's PK for an ID
512
+				$this->_model_relations[$relationName][$object_to_cache->ID()] = $object_to_cache;
513
+				$return = $object_to_cache->ID();
514
+			} else {
515
+				// OR it's a new object with no ID, so just throw it in the array with an auto-incremented ID
516
+				$this->_model_relations[$relationName][] = $object_to_cache;
517
+				// move the internal pointer to the end of the array
518
+				end($this->_model_relations[$relationName]);
519
+				// and grab the key so that we can return it
520
+				$return = key($this->_model_relations[$relationName]);
521
+			}
522
+		}
523
+		return $return;
524
+	}
525
+
526
+
527
+
528
+	/**
529
+	 * For adding an item to the cached_properties property.
530
+	 *
531
+	 * @access protected
532
+	 * @param string      $fieldname the property item the corresponding value is for.
533
+	 * @param mixed       $value     The value we are caching.
534
+	 * @param string|null $cache_type
535
+	 * @return void
536
+	 * @throws \EE_Error
537
+	 */
538
+	protected function _set_cached_property($fieldname, $value, $cache_type = null)
539
+	{
540
+		//first make sure this property exists
541
+		$this->get_model()->field_settings_for($fieldname);
542
+		$cache_type = empty($cache_type) ? 'standard' : $cache_type;
543
+		$this->_cached_properties[$fieldname][$cache_type] = $value;
544
+	}
545
+
546
+
547
+
548
+	/**
549
+	 * This returns the value cached property if it exists OR the actual property value if the cache doesn't exist.
550
+	 * This also SETS the cache if we return the actual property!
551
+	 *
552
+	 * @param string $fieldname        the name of the property we're trying to retrieve
553
+	 * @param bool   $pretty
554
+	 * @param string $extra_cache_ref  This allows the user to specify an extra cache ref for the given property
555
+	 *                                 (in cases where the same property may be used for different outputs
556
+	 *                                 - i.e. datetime, money etc.)
557
+	 *                                 It can also accept certain pre-defined "schema" strings
558
+	 *                                 to define how to output the property.
559
+	 *                                 see the field's prepare_for_pretty_echoing for what strings can be used
560
+	 * @return mixed                   whatever the value for the property is we're retrieving
561
+	 * @throws \EE_Error
562
+	 */
563
+	protected function _get_cached_property($fieldname, $pretty = false, $extra_cache_ref = null)
564
+	{
565
+		//verify the field exists
566
+		$this->get_model()->field_settings_for($fieldname);
567
+		$cache_type = $pretty ? 'pretty' : 'standard';
568
+		$cache_type .= ! empty($extra_cache_ref) ? '_' . $extra_cache_ref : '';
569
+		if (isset($this->_cached_properties[$fieldname][$cache_type])) {
570
+			return $this->_cached_properties[$fieldname][$cache_type];
571
+		}
572
+		$field_obj = $this->get_model()->field_settings_for($fieldname);
573
+		if ($field_obj instanceof EE_Model_Field_Base) {
574
+			// If this is an EE_Datetime_Field we need to make sure timezone, formats, and output are correct
575
+			if ($field_obj instanceof EE_Datetime_Field) {
576
+				$this->_prepare_datetime_field($field_obj, $pretty, $extra_cache_ref);
577
+			}
578
+			if ( ! isset($this->_fields[$fieldname])) {
579
+				$this->_fields[$fieldname] = null;
580
+			}
581
+			$value = $pretty
582
+				? $field_obj->prepare_for_pretty_echoing($this->_fields[$fieldname], $extra_cache_ref)
583
+				: $field_obj->prepare_for_get($this->_fields[$fieldname]);
584
+			$this->_set_cached_property($fieldname, $value, $cache_type);
585
+			return $value;
586
+		}
587
+		return null;
588
+	}
589
+
590
+
591
+
592
+	/**
593
+	 * set timezone, formats, and output for EE_Datetime_Field objects
594
+	 *
595
+	 * @param \EE_Datetime_Field $datetime_field
596
+	 * @param bool               $pretty
597
+	 * @param null $date_or_time
598
+	 * @return void
599
+	 * @throws \EE_Error
600
+	 */
601
+	protected function _prepare_datetime_field(
602
+		EE_Datetime_Field $datetime_field,
603
+		$pretty = false,
604
+		$date_or_time = null
605
+	) {
606
+		$datetime_field->set_timezone($this->_timezone);
607
+		$datetime_field->set_date_format($this->_dt_frmt, $pretty);
608
+		$datetime_field->set_time_format($this->_tm_frmt, $pretty);
609
+		//set the output returned
610
+		switch ($date_or_time) {
611
+			case 'D' :
612
+				$datetime_field->set_date_time_output('date');
613
+				break;
614
+			case 'T' :
615
+				$datetime_field->set_date_time_output('time');
616
+				break;
617
+			default :
618
+				$datetime_field->set_date_time_output();
619
+		}
620
+	}
621
+
622
+
623
+
624
+	/**
625
+	 * This just takes care of clearing out the cached_properties
626
+	 *
627
+	 * @return void
628
+	 */
629
+	protected function _clear_cached_properties()
630
+	{
631
+		$this->_cached_properties = array();
632
+	}
633
+
634
+
635
+
636
+	/**
637
+	 * This just clears out ONE property if it exists in the cache
638
+	 *
639
+	 * @param  string $property_name the property to remove if it exists (from the _cached_properties array)
640
+	 * @return void
641
+	 */
642
+	protected function _clear_cached_property($property_name)
643
+	{
644
+		if (isset($this->_cached_properties[$property_name])) {
645
+			unset($this->_cached_properties[$property_name]);
646
+		}
647
+	}
648
+
649
+
650
+
651
+	/**
652
+	 * Ensures that this related thing is a model object.
653
+	 *
654
+	 * @param mixed  $object_or_id EE_base_Class/int/string either a related model object, or its ID
655
+	 * @param string $model_name   name of the related thing, eg 'Attendee',
656
+	 * @return EE_Base_Class
657
+	 * @throws \EE_Error
658
+	 */
659
+	protected function ensure_related_thing_is_model_obj($object_or_id, $model_name)
660
+	{
661
+		$other_model_instance = self::_get_model_instance_with_name(
662
+			self::_get_model_classname($model_name),
663
+			$this->_timezone
664
+		);
665
+		return $other_model_instance->ensure_is_obj($object_or_id);
666
+	}
667
+
668
+
669
+
670
+	/**
671
+	 * Forgets the cached model of the given relation Name. So the next time we request it,
672
+	 * we will fetch it again from the database. (Handy if you know it's changed somehow).
673
+	 * If a specific object is supplied, and the relationship to it is either a HasMany or HABTM,
674
+	 * then only remove that one object from our cached array. Otherwise, clear the entire list
675
+	 *
676
+	 * @param string $relationName                         one of the keys in the _model_relations array on the model.
677
+	 *                                                     Eg 'Registration'
678
+	 * @param mixed  $object_to_remove_or_index_into_array or an index into the array of cached things, or NULL
679
+	 *                                                     if you intend to use $clear_all = TRUE, or the relation only
680
+	 *                                                     has 1 object anyways (ie, it's a BelongsToRelation)
681
+	 * @param bool   $clear_all                            This flags clearing the entire cache relation property if
682
+	 *                                                     this is HasMany or HABTM.
683
+	 * @throws EE_Error
684
+	 * @return EE_Base_Class | boolean from which was cleared from the cache, or true if we requested to remove a
685
+	 *                       relation from all
686
+	 */
687
+	public function clear_cache($relationName, $object_to_remove_or_index_into_array = null, $clear_all = false)
688
+	{
689
+		$relationship_to_model = $this->get_model()->related_settings_for($relationName);
690
+		$index_in_cache = '';
691
+		if ( ! $relationship_to_model) {
692
+			throw new EE_Error(
693
+				sprintf(
694
+					__("There is no relationship to %s on a %s. Cannot clear that cache", 'event_espresso'),
695
+					$relationName,
696
+					get_class($this)
697
+				)
698
+			);
699
+		}
700
+		if ($clear_all) {
701
+			$obj_removed = true;
702
+			$this->_model_relations[$relationName] = null;
703
+		} elseif ($relationship_to_model instanceof EE_Belongs_To_Relation) {
704
+			$obj_removed = $this->_model_relations[$relationName];
705
+			$this->_model_relations[$relationName] = null;
706
+		} else {
707
+			if ($object_to_remove_or_index_into_array instanceof EE_Base_Class
708
+				&& $object_to_remove_or_index_into_array->ID()
709
+			) {
710
+				$index_in_cache = $object_to_remove_or_index_into_array->ID();
711
+				if (is_array($this->_model_relations[$relationName])
712
+					&& ! isset($this->_model_relations[$relationName][$index_in_cache])
713
+				) {
714
+					$index_found_at = null;
715
+					//find this object in the array even though it has a different key
716
+					foreach ($this->_model_relations[$relationName] as $index => $obj) {
717
+						if (
718
+							$obj instanceof EE_Base_Class
719
+							&& (
720
+								$obj == $object_to_remove_or_index_into_array
721
+								|| $obj->ID() === $object_to_remove_or_index_into_array->ID()
722
+							)
723
+						) {
724
+							$index_found_at = $index;
725
+							break;
726
+						}
727
+					}
728
+					if ($index_found_at) {
729
+						$index_in_cache = $index_found_at;
730
+					} else {
731
+						//it wasn't found. huh. well obviously it doesn't need to be removed from teh cache
732
+						//if it wasn't in it to begin with. So we're done
733
+						return $object_to_remove_or_index_into_array;
734
+					}
735
+				}
736
+			} elseif ($object_to_remove_or_index_into_array instanceof EE_Base_Class) {
737
+				//so they provided a model object, but it's not yet saved to the DB... so let's go hunting for it!
738
+				foreach ($this->get_all_from_cache($relationName) as $index => $potentially_obj_we_want) {
739
+					if ($potentially_obj_we_want == $object_to_remove_or_index_into_array) {
740
+						$index_in_cache = $index;
741
+					}
742
+				}
743
+			} else {
744
+				$index_in_cache = $object_to_remove_or_index_into_array;
745
+			}
746
+			//supposedly we've found it. But it could just be that the client code
747
+			//provided a bad index/object
748
+			if (
749
+			isset(
750
+				$this->_model_relations[$relationName],
751
+				$this->_model_relations[$relationName][$index_in_cache]
752
+			)
753
+			) {
754
+				$obj_removed = $this->_model_relations[$relationName][$index_in_cache];
755
+				unset($this->_model_relations[$relationName][$index_in_cache]);
756
+			} else {
757
+				//that thing was never cached anyways.
758
+				$obj_removed = null;
759
+			}
760
+		}
761
+		return $obj_removed;
762
+	}
763
+
764
+
765
+
766
+	/**
767
+	 * update_cache_after_object_save
768
+	 * Allows a cached item to have it's cache ID (within the array of cached items) reset using the new ID it has
769
+	 * obtained after being saved to the db
770
+	 *
771
+	 * @param string         $relationName       - the type of object that is cached
772
+	 * @param \EE_Base_Class $newly_saved_object - the newly saved object to be re-cached
773
+	 * @param string         $current_cache_id   - the ID that was used when originally caching the object
774
+	 * @return boolean TRUE on success, FALSE on fail
775
+	 * @throws \EE_Error
776
+	 */
777
+	public function update_cache_after_object_save(
778
+		$relationName,
779
+		EE_Base_Class $newly_saved_object,
780
+		$current_cache_id = ''
781
+	) {
782
+		// verify that incoming object is of the correct type
783
+		$obj_class = 'EE_' . $relationName;
784
+		if ($newly_saved_object instanceof $obj_class) {
785
+			/* @type EE_Base_Class $newly_saved_object */
786
+			// now get the type of relation
787
+			$relationship_to_model = $this->get_model()->related_settings_for($relationName);
788
+			// if this is a 1:1 relationship
789
+			if ($relationship_to_model instanceof EE_Belongs_To_Relation) {
790
+				// then just replace the cached object with the newly saved object
791
+				$this->_model_relations[$relationName] = $newly_saved_object;
792
+				return true;
793
+				// or if it's some kind of sordid feral polyamorous relationship...
794
+			} elseif (is_array($this->_model_relations[$relationName])
795
+					  && isset($this->_model_relations[$relationName][$current_cache_id])
796
+			) {
797
+				// then remove the current cached item
798
+				unset($this->_model_relations[$relationName][$current_cache_id]);
799
+				// and cache the newly saved object using it's new ID
800
+				$this->_model_relations[$relationName][$newly_saved_object->ID()] = $newly_saved_object;
801
+				return true;
802
+			}
803
+		}
804
+		return false;
805
+	}
806
+
807
+
808
+
809
+	/**
810
+	 * Fetches a single EE_Base_Class on that relation. (If the relation is of type
811
+	 * BelongsTo, it will only ever have 1 object. However, other relations could have an array of objects)
812
+	 *
813
+	 * @param string $relationName
814
+	 * @return EE_Base_Class
815
+	 */
816
+	public function get_one_from_cache($relationName)
817
+	{
818
+		$cached_array_or_object = isset($this->_model_relations[$relationName]) ? $this->_model_relations[$relationName]
819
+			: null;
820
+		if (is_array($cached_array_or_object)) {
821
+			return array_shift($cached_array_or_object);
822
+		} else {
823
+			return $cached_array_or_object;
824
+		}
825
+	}
826
+
827
+
828
+
829
+	/**
830
+	 * Fetches a single EE_Base_Class on that relation. (If the relation is of type
831
+	 * BelongsTo, it will only ever have 1 object. However, other relations could have an array of objects)
832
+	 *
833
+	 * @param string $relationName
834
+	 * @throws \EE_Error
835
+	 * @return EE_Base_Class[] NOT necessarily indexed by primary keys
836
+	 */
837
+	public function get_all_from_cache($relationName)
838
+	{
839
+		$objects = isset($this->_model_relations[$relationName]) ? $this->_model_relations[$relationName] : array();
840
+		// if the result is not an array, but exists, make it an array
841
+		$objects = is_array($objects) ? $objects : array($objects);
842
+		//bugfix for https://events.codebasehq.com/projects/event-espresso/tickets/7143
843
+		//basically, if this model object was stored in the session, and these cached model objects
844
+		//already have IDs, let's make sure they're in their model's entity mapper
845
+		//otherwise we will have duplicates next time we call
846
+		// EE_Registry::instance()->load_model( $relationName )->get_one_by_ID( $result->ID() );
847
+		$model = EE_Registry::instance()->load_model($relationName);
848
+		foreach ($objects as $model_object) {
849
+			if ($model instanceof EEM_Base && $model_object instanceof EE_Base_Class) {
850
+				//ensure its in the map if it has an ID; otherwise it will be added to the map when its saved
851
+				if ($model_object->ID()) {
852
+					$model->add_to_entity_map($model_object);
853
+				}
854
+			} else {
855
+				throw new EE_Error(
856
+					sprintf(
857
+						__(
858
+							'Error retrieving related model objects. Either $1%s is not a model or $2%s is not a model object',
859
+							'event_espresso'
860
+						),
861
+						$relationName,
862
+						gettype($model_object)
863
+					)
864
+				);
865
+			}
866
+		}
867
+		return $objects;
868
+	}
869
+
870
+
871
+
872
+	/**
873
+	 * Returns the next x number of EE_Base_Class objects in sequence from this object as found in the database
874
+	 * matching the given query conditions.
875
+	 *
876
+	 * @param null  $field_to_order_by  What field is being used as the reference point.
877
+	 * @param int   $limit              How many objects to return.
878
+	 * @param array $query_params       Any additional conditions on the query.
879
+	 * @param null  $columns_to_select  If left null, then an array of EE_Base_Class objects is returned, otherwise
880
+	 *                                  you can indicate just the columns you want returned
881
+	 * @return array|EE_Base_Class[]
882
+	 * @throws \EE_Error
883
+	 */
884
+	public function next_x($field_to_order_by = null, $limit = 1, $query_params = array(), $columns_to_select = null)
885
+	{
886
+		$field = empty($field_to_order_by) && $this->get_model()->has_primary_key_field()
887
+			? $this->get_model()->get_primary_key_field()->get_name()
888
+			: $field_to_order_by;
889
+		$current_value = ! empty($field) ? $this->get($field) : null;
890
+		if (empty($field) || empty($current_value)) {
891
+			return array();
892
+		}
893
+		return $this->get_model()->next_x($current_value, $field, $limit, $query_params, $columns_to_select);
894
+	}
895
+
896
+
897
+
898
+	/**
899
+	 * Returns the previous x number of EE_Base_Class objects in sequence from this object as found in the database
900
+	 * matching the given query conditions.
901
+	 *
902
+	 * @param null  $field_to_order_by  What field is being used as the reference point.
903
+	 * @param int   $limit              How many objects to return.
904
+	 * @param array $query_params       Any additional conditions on the query.
905
+	 * @param null  $columns_to_select  If left null, then an array of EE_Base_Class objects is returned, otherwise
906
+	 *                                  you can indicate just the columns you want returned
907
+	 * @return array|EE_Base_Class[]
908
+	 * @throws \EE_Error
909
+	 */
910
+	public function previous_x(
911
+		$field_to_order_by = null,
912
+		$limit = 1,
913
+		$query_params = array(),
914
+		$columns_to_select = null
915
+	) {
916
+		$field = empty($field_to_order_by) && $this->get_model()->has_primary_key_field()
917
+			? $this->get_model()->get_primary_key_field()->get_name()
918
+			: $field_to_order_by;
919
+		$current_value = ! empty($field) ? $this->get($field) : null;
920
+		if (empty($field) || empty($current_value)) {
921
+			return array();
922
+		}
923
+		return $this->get_model()->previous_x($current_value, $field, $limit, $query_params, $columns_to_select);
924
+	}
925
+
926
+
927
+
928
+	/**
929
+	 * Returns the next EE_Base_Class object in sequence from this object as found in the database
930
+	 * matching the given query conditions.
931
+	 *
932
+	 * @param null  $field_to_order_by  What field is being used as the reference point.
933
+	 * @param array $query_params       Any additional conditions on the query.
934
+	 * @param null  $columns_to_select  If left null, then an array of EE_Base_Class objects is returned, otherwise
935
+	 *                                  you can indicate just the columns you want returned
936
+	 * @return array|EE_Base_Class
937
+	 * @throws \EE_Error
938
+	 */
939
+	public function next($field_to_order_by = null, $query_params = array(), $columns_to_select = null)
940
+	{
941
+		$field = empty($field_to_order_by) && $this->get_model()->has_primary_key_field()
942
+			? $this->get_model()->get_primary_key_field()->get_name()
943
+			: $field_to_order_by;
944
+		$current_value = ! empty($field) ? $this->get($field) : null;
945
+		if (empty($field) || empty($current_value)) {
946
+			return array();
947
+		}
948
+		return $this->get_model()->next($current_value, $field, $query_params, $columns_to_select);
949
+	}
950
+
951
+
952
+
953
+	/**
954
+	 * Returns the previous EE_Base_Class object in sequence from this object as found in the database
955
+	 * matching the given query conditions.
956
+	 *
957
+	 * @param null  $field_to_order_by  What field is being used as the reference point.
958
+	 * @param array $query_params       Any additional conditions on the query.
959
+	 * @param null  $columns_to_select  If left null, then an EE_Base_Class object is returned, otherwise
960
+	 *                                  you can indicate just the column you want returned
961
+	 * @return array|EE_Base_Class
962
+	 * @throws \EE_Error
963
+	 */
964
+	public function previous($field_to_order_by = null, $query_params = array(), $columns_to_select = null)
965
+	{
966
+		$field = empty($field_to_order_by) && $this->get_model()->has_primary_key_field()
967
+			? $this->get_model()->get_primary_key_field()->get_name()
968
+			: $field_to_order_by;
969
+		$current_value = ! empty($field) ? $this->get($field) : null;
970
+		if (empty($field) || empty($current_value)) {
971
+			return array();
972
+		}
973
+		return $this->get_model()->previous($current_value, $field, $query_params, $columns_to_select);
974
+	}
975
+
976
+
977
+
978
+	/**
979
+	 * Overrides parent because parent expects old models.
980
+	 * This also doesn't do any validation, and won't work for serialized arrays
981
+	 *
982
+	 * @param string $field_name
983
+	 * @param mixed  $field_value_from_db
984
+	 * @throws \EE_Error
985
+	 */
986
+	public function set_from_db($field_name, $field_value_from_db)
987
+	{
988
+		$field_obj = $this->get_model()->field_settings_for($field_name);
989
+		if ($field_obj instanceof EE_Model_Field_Base) {
990
+			//you would think the DB has no NULLs for non-null label fields right? wrong!
991
+			//eg, a CPT model object could have an entry in the posts table, but no
992
+			//entry in the meta table. Meaning that all its columns in the meta table
993
+			//are null! yikes! so when we find one like that, use defaults for its meta columns
994
+			if ($field_value_from_db === null) {
995
+				if ($field_obj->is_nullable()) {
996
+					//if the field allows nulls, then let it be null
997
+					$field_value = null;
998
+				} else {
999
+					$field_value = $field_obj->get_default_value();
1000
+				}
1001
+			} else {
1002
+				$field_value = $field_obj->prepare_for_set_from_db($field_value_from_db);
1003
+			}
1004
+			$this->_fields[$field_name] = $field_value;
1005
+			$this->_clear_cached_property($field_name);
1006
+		}
1007
+	}
1008
+
1009
+
1010
+
1011
+	/**
1012
+	 * verifies that the specified field is of the correct type
1013
+	 *
1014
+	 * @param string $field_name
1015
+	 * @param string $extra_cache_ref This allows the user to specify an extra cache ref for the given property
1016
+	 *                                (in cases where the same property may be used for different outputs
1017
+	 *                                - i.e. datetime, money etc.)
1018
+	 * @return mixed
1019
+	 * @throws \EE_Error
1020
+	 */
1021
+	public function get($field_name, $extra_cache_ref = null)
1022
+	{
1023
+		return $this->_get_cached_property($field_name, false, $extra_cache_ref);
1024
+	}
1025
+
1026
+
1027
+
1028
+	/**
1029
+	 * This method simply returns the RAW unprocessed value for the given property in this class
1030
+	 *
1031
+	 * @param  string $field_name A valid fieldname
1032
+	 * @return mixed              Whatever the raw value stored on the property is.
1033
+	 * @throws EE_Error if fieldSettings is misconfigured or the field doesn't exist.
1034
+	 */
1035
+	public function get_raw($field_name)
1036
+	{
1037
+		$field_settings = $this->get_model()->field_settings_for($field_name);
1038
+		return $field_settings instanceof EE_Datetime_Field && $this->_fields[$field_name] instanceof DateTime
1039
+			? $this->_fields[$field_name]->format('U')
1040
+			: $this->_fields[$field_name];
1041
+	}
1042
+
1043
+
1044
+
1045
+	/**
1046
+	 * This is used to return the internal DateTime object used for a field that is a
1047
+	 * EE_Datetime_Field.
1048
+	 *
1049
+	 * @param string $field_name               The field name retrieving the DateTime object.
1050
+	 * @return mixed null | false | DateTime  If the requested field is NOT a EE_Datetime_Field then
1051
+	 * @throws \EE_Error
1052
+	 *                                         an error is set and false returned.  If the field IS an
1053
+	 *                                         EE_Datetime_Field and but the field value is null, then
1054
+	 *                                         just null is returned (because that indicates that likely
1055
+	 *                                         this field is nullable).
1056
+	 */
1057
+	public function get_DateTime_object($field_name)
1058
+	{
1059
+		$field_settings = $this->get_model()->field_settings_for($field_name);
1060
+		if ( ! $field_settings instanceof EE_Datetime_Field) {
1061
+			EE_Error::add_error(
1062
+				sprintf(
1063
+					__(
1064
+						'The field %s is not an EE_Datetime_Field field.  There is no DateTime object stored on this field type.',
1065
+						'event_espresso'
1066
+					),
1067
+					$field_name
1068
+				),
1069
+				__FILE__,
1070
+				__FUNCTION__,
1071
+				__LINE__
1072
+			);
1073
+			return false;
1074
+		}
1075
+		return $this->_fields[$field_name];
1076
+	}
1077
+
1078
+
1079
+
1080
+	/**
1081
+	 * To be used in template to immediately echo out the value, and format it for output.
1082
+	 * Eg, should call stripslashes and whatnot before echoing
1083
+	 *
1084
+	 * @param string $field_name      the name of the field as it appears in the DB
1085
+	 * @param string $extra_cache_ref This allows the user to specify an extra cache ref for the given property
1086
+	 *                                (in cases where the same property may be used for different outputs
1087
+	 *                                - i.e. datetime, money etc.)
1088
+	 * @return void
1089
+	 * @throws \EE_Error
1090
+	 */
1091
+	public function e($field_name, $extra_cache_ref = null)
1092
+	{
1093
+		echo $this->get_pretty($field_name, $extra_cache_ref);
1094
+	}
1095
+
1096
+
1097
+
1098
+	/**
1099
+	 * Exactly like e(), echoes out the field, but sets its schema to 'form_input', so that it
1100
+	 * can be easily used as the value of form input.
1101
+	 *
1102
+	 * @param string $field_name
1103
+	 * @return void
1104
+	 * @throws \EE_Error
1105
+	 */
1106
+	public function f($field_name)
1107
+	{
1108
+		$this->e($field_name, 'form_input');
1109
+	}
1110
+
1111
+
1112
+
1113
+	/**
1114
+	 * Gets a pretty view of the field's value. $extra_cache_ref can specify different formats for this.
1115
+	 * The $extra_cache_ref will be passed to the model field's prepare_for_pretty_echoing, so consult the field's class
1116
+	 * to see what options are available.
1117
+	 * @param string $field_name
1118
+	 * @param string $extra_cache_ref This allows the user to specify an extra cache ref for the given property
1119
+	 *                                (in cases where the same property may be used for different outputs
1120
+	 *                                - i.e. datetime, money etc.)
1121
+	 * @return mixed
1122
+	 * @throws \EE_Error
1123
+	 */
1124
+	public function get_pretty($field_name, $extra_cache_ref = null)
1125
+	{
1126
+		return $this->_get_cached_property($field_name, true, $extra_cache_ref);
1127
+	}
1128
+
1129
+
1130
+
1131
+	/**
1132
+	 * This simply returns the datetime for the given field name
1133
+	 * Note: this protected function is called by the wrapper get_date or get_time or get_datetime functions
1134
+	 * (and the equivalent e_date, e_time, e_datetime).
1135
+	 *
1136
+	 * @access   protected
1137
+	 * @param string   $field_name   Field on the instantiated EE_Base_Class child object
1138
+	 * @param string   $dt_frmt      valid datetime format used for date
1139
+	 *                               (if '' then we just use the default on the field,
1140
+	 *                               if NULL we use the last-used format)
1141
+	 * @param string   $tm_frmt      Same as above except this is for time format
1142
+	 * @param string   $date_or_time if NULL then both are returned, otherwise "D" = only date and "T" = only time.
1143
+	 * @param  boolean $echo         Whether the dtt is echoing using pretty echoing or just returned using vanilla get
1144
+	 * @return string|bool|EE_Error string on success, FALSE on fail, or EE_Error Exception is thrown
1145
+	 *                               if field is not a valid dtt field, or void if echoing
1146
+	 * @throws \EE_Error
1147
+	 */
1148
+	protected function _get_datetime($field_name, $dt_frmt = '', $tm_frmt = '', $date_or_time = '', $echo = false)
1149
+	{
1150
+		// clear cached property
1151
+		$this->_clear_cached_property($field_name);
1152
+		//reset format properties because they are used in get()
1153
+		$this->_dt_frmt = $dt_frmt !== '' ? $dt_frmt : $this->_dt_frmt;
1154
+		$this->_tm_frmt = $tm_frmt !== '' ? $tm_frmt : $this->_tm_frmt;
1155
+		if ($echo) {
1156
+			$this->e($field_name, $date_or_time);
1157
+			return '';
1158
+		}
1159
+		return $this->get($field_name, $date_or_time);
1160
+	}
1161
+
1162
+
1163
+
1164
+	/**
1165
+	 * below are wrapper functions for the various datetime outputs that can be obtained for JUST returning the date
1166
+	 * portion of a datetime value. (note the only difference between get_ and e_ is one returns the value and the
1167
+	 * other echoes the pretty value for dtt)
1168
+	 *
1169
+	 * @param  string $field_name name of model object datetime field holding the value
1170
+	 * @param  string $format     format for the date returned (if NULL we use default in dt_frmt property)
1171
+	 * @return string            datetime value formatted
1172
+	 * @throws \EE_Error
1173
+	 */
1174
+	public function get_date($field_name, $format = '')
1175
+	{
1176
+		return $this->_get_datetime($field_name, $format, null, 'D');
1177
+	}
1178
+
1179
+
1180
+
1181
+	/**
1182
+	 * @param      $field_name
1183
+	 * @param string $format
1184
+	 * @throws \EE_Error
1185
+	 */
1186
+	public function e_date($field_name, $format = '')
1187
+	{
1188
+		$this->_get_datetime($field_name, $format, null, 'D', true);
1189
+	}
1190
+
1191
+
1192
+
1193
+	/**
1194
+	 * below are wrapper functions for the various datetime outputs that can be obtained for JUST returning the time
1195
+	 * portion of a datetime value. (note the only difference between get_ and e_ is one returns the value and the
1196
+	 * other echoes the pretty value for dtt)
1197
+	 *
1198
+	 * @param  string $field_name name of model object datetime field holding the value
1199
+	 * @param  string $format     format for the time returned ( if NULL we use default in tm_frmt property)
1200
+	 * @return string             datetime value formatted
1201
+	 * @throws \EE_Error
1202
+	 */
1203
+	public function get_time($field_name, $format = '')
1204
+	{
1205
+		return $this->_get_datetime($field_name, null, $format, 'T');
1206
+	}
1207
+
1208
+
1209
+
1210
+	/**
1211
+	 * @param      $field_name
1212
+	 * @param string $format
1213
+	 * @throws \EE_Error
1214
+	 */
1215
+	public function e_time($field_name, $format = '')
1216
+	{
1217
+		$this->_get_datetime($field_name, null, $format, 'T', true);
1218
+	}
1219
+
1220
+
1221
+
1222
+	/**
1223
+	 * below are wrapper functions for the various datetime outputs that can be obtained for returning the date AND
1224
+	 * time portion of a datetime value. (note the only difference between get_ and e_ is one returns the value and the
1225
+	 * other echoes the pretty value for dtt)
1226
+	 *
1227
+	 * @param  string $field_name name of model object datetime field holding the value
1228
+	 * @param  string $dt_frmt    format for the date returned (if NULL we use default in dt_frmt property)
1229
+	 * @param  string $tm_frmt    format for the time returned (if NULL we use default in tm_frmt property)
1230
+	 * @return string             datetime value formatted
1231
+	 * @throws \EE_Error
1232
+	 */
1233
+	public function get_datetime($field_name, $dt_frmt = '', $tm_frmt = '')
1234
+	{
1235
+		return $this->_get_datetime($field_name, $dt_frmt, $tm_frmt);
1236
+	}
1237
+
1238
+
1239
+
1240
+	/**
1241
+	 * @param string $field_name
1242
+	 * @param string $dt_frmt
1243
+	 * @param string $tm_frmt
1244
+	 * @throws \EE_Error
1245
+	 */
1246
+	public function e_datetime($field_name, $dt_frmt = '', $tm_frmt = '')
1247
+	{
1248
+		$this->_get_datetime($field_name, $dt_frmt, $tm_frmt, null, true);
1249
+	}
1250
+
1251
+
1252
+
1253
+	/**
1254
+	 * Get the i8ln value for a date using the WordPress @see date_i18n function.
1255
+	 *
1256
+	 * @param string $field_name The EE_Datetime_Field reference for the date being retrieved.
1257
+	 * @param string $format     PHP valid date/time string format.  If none is provided then the internal set format
1258
+	 *                           on the object will be used.
1259
+	 * @return string Date and time string in set locale or false if no field exists for the given
1260
+	 * @throws \EE_Error
1261
+	 *                           field name.
1262
+	 */
1263
+	public function get_i18n_datetime($field_name, $format = '')
1264
+	{
1265
+		$format = empty($format) ? $this->_dt_frmt . ' ' . $this->_tm_frmt : $format;
1266
+		return date_i18n(
1267
+			$format,
1268
+			EEH_DTT_Helper::get_timestamp_with_offset($this->get_raw($field_name), $this->_timezone)
1269
+		);
1270
+	}
1271
+
1272
+
1273
+
1274
+	/**
1275
+	 * This method validates whether the given field name is a valid field on the model object as well as it is of a
1276
+	 * type EE_Datetime_Field.  On success there will be returned the field settings.  On fail an EE_Error exception is
1277
+	 * thrown.
1278
+	 *
1279
+	 * @param  string $field_name The field name being checked
1280
+	 * @throws EE_Error
1281
+	 * @return EE_Datetime_Field
1282
+	 */
1283
+	protected function _get_dtt_field_settings($field_name)
1284
+	{
1285
+		$field = $this->get_model()->field_settings_for($field_name);
1286
+		//check if field is dtt
1287
+		if ($field instanceof EE_Datetime_Field) {
1288
+			return $field;
1289
+		} else {
1290
+			throw new EE_Error(sprintf(__('The field name "%s" has been requested for the EE_Base_Class datetime functions and it is not a valid EE_Datetime_Field.  Please check the spelling of the field and make sure it has been setup as a EE_Datetime_Field in the %s model constructor',
1291
+				'event_espresso'), $field_name, self::_get_model_classname(get_class($this))));
1292
+		}
1293
+	}
1294
+
1295
+
1296
+
1297
+
1298
+	/**
1299
+	 * NOTE ABOUT BELOW:
1300
+	 * These convenience date and time setters are for setting date and time independently.  In other words you might
1301
+	 * want to change the time on a datetime_field but leave the date the same (or vice versa). IF on the other hand
1302
+	 * you want to set both date and time at the same time, you can just use the models default set($fieldname,$value)
1303
+	 * method and make sure you send the entire datetime value for setting.
1304
+	 */
1305
+	/**
1306
+	 * sets the time on a datetime property
1307
+	 *
1308
+	 * @access protected
1309
+	 * @param string|Datetime $time      a valid time string for php datetime functions (or DateTime object)
1310
+	 * @param string          $fieldname the name of the field the time is being set on (must match a EE_Datetime_Field)
1311
+	 * @throws \EE_Error
1312
+	 */
1313
+	protected function _set_time_for($time, $fieldname)
1314
+	{
1315
+		$this->_set_date_time('T', $time, $fieldname);
1316
+	}
1317
+
1318
+
1319
+
1320
+	/**
1321
+	 * sets the date on a datetime property
1322
+	 *
1323
+	 * @access protected
1324
+	 * @param string|DateTime $date      a valid date string for php datetime functions ( or DateTime object)
1325
+	 * @param string          $fieldname the name of the field the date is being set on (must match a EE_Datetime_Field)
1326
+	 * @throws \EE_Error
1327
+	 */
1328
+	protected function _set_date_for($date, $fieldname)
1329
+	{
1330
+		$this->_set_date_time('D', $date, $fieldname);
1331
+	}
1332
+
1333
+
1334
+
1335
+	/**
1336
+	 * This takes care of setting a date or time independently on a given model object property. This method also
1337
+	 * verifies that the given fieldname matches a model object property and is for a EE_Datetime_Field field
1338
+	 *
1339
+	 * @access protected
1340
+	 * @param string          $what           "T" for time, 'B' for both, 'D' for Date.
1341
+	 * @param string|DateTime $datetime_value A valid Date or Time string (or DateTime object)
1342
+	 * @param string          $fieldname      the name of the field the date OR time is being set on (must match a
1343
+	 *                                        EE_Datetime_Field property)
1344
+	 * @throws \EE_Error
1345
+	 */
1346
+	protected function _set_date_time($what = 'T', $datetime_value, $fieldname)
1347
+	{
1348
+		$field = $this->_get_dtt_field_settings($fieldname);
1349
+		$field->set_timezone($this->_timezone);
1350
+		$field->set_date_format($this->_dt_frmt);
1351
+		$field->set_time_format($this->_tm_frmt);
1352
+		switch ($what) {
1353
+			case 'T' :
1354
+				$this->_fields[$fieldname] = $field->prepare_for_set_with_new_time(
1355
+					$datetime_value,
1356
+					$this->_fields[$fieldname]
1357
+				);
1358
+				break;
1359
+			case 'D' :
1360
+				$this->_fields[$fieldname] = $field->prepare_for_set_with_new_date(
1361
+					$datetime_value,
1362
+					$this->_fields[$fieldname]
1363
+				);
1364
+				break;
1365
+			case 'B' :
1366
+				$this->_fields[$fieldname] = $field->prepare_for_set($datetime_value);
1367
+				break;
1368
+		}
1369
+		$this->_clear_cached_property($fieldname);
1370
+	}
1371
+
1372
+
1373
+
1374
+	/**
1375
+	 * This will return a timestamp for the website timezone but ONLY when the current website timezone is different
1376
+	 * than the timezone set for the website. NOTE, this currently only works well with methods that return values.  If
1377
+	 * you use it with methods that echo values the $_timestamp property may not get reset to its original value and
1378
+	 * that could lead to some unexpected results!
1379
+	 *
1380
+	 * @access public
1381
+	 * @param string               $field_name This is the name of the field on the object that contains the date/time
1382
+	 *                                         value being returned.
1383
+	 * @param string               $callback   must match a valid method in this class (defaults to get_datetime)
1384
+	 * @param mixed (array|string) $args       This is the arguments that will be passed to the callback.
1385
+	 * @param string               $prepend    You can include something to prepend on the timestamp
1386
+	 * @param string               $append     You can include something to append on the timestamp
1387
+	 * @throws EE_Error
1388
+	 * @return string timestamp
1389
+	 */
1390
+	public function display_in_my_timezone(
1391
+		$field_name,
1392
+		$callback = 'get_datetime',
1393
+		$args = null,
1394
+		$prepend = '',
1395
+		$append = ''
1396
+	) {
1397
+		$timezone = EEH_DTT_Helper::get_timezone();
1398
+		if ($timezone === $this->_timezone) {
1399
+			return '';
1400
+		}
1401
+		$original_timezone = $this->_timezone;
1402
+		$this->set_timezone($timezone);
1403
+		$fn = (array)$field_name;
1404
+		$args = array_merge($fn, (array)$args);
1405
+		if ( ! method_exists($this, $callback)) {
1406
+			throw new EE_Error(
1407
+				sprintf(
1408
+					__(
1409
+						'The method named "%s" given as the callback param in "display_in_my_timezone" does not exist.  Please check your spelling',
1410
+						'event_espresso'
1411
+					),
1412
+					$callback
1413
+				)
1414
+			);
1415
+		}
1416
+		$args = (array)$args;
1417
+		$return = $prepend . call_user_func_array(array($this, $callback), $args) . $append;
1418
+		$this->set_timezone($original_timezone);
1419
+		return $return;
1420
+	}
1421
+
1422
+
1423
+
1424
+	/**
1425
+	 * Deletes this model object.
1426
+	 * This calls the `EE_Base_Class::_delete` method.  Child classes wishing to change default behaviour should
1427
+	 * override
1428
+	 * `EE_Base_Class::_delete` NOT this class.
1429
+	 *
1430
+	 * @return boolean | int
1431
+	 * @throws \EE_Error
1432
+	 */
1433
+	public function delete()
1434
+	{
1435
+		/**
1436
+		 * Called just before the `EE_Base_Class::_delete` method call.
1437
+		 * Note: `EE_Base_Class::_delete` might be overridden by child classes so any client code hooking into these actions
1438
+		 * should be aware that `_delete` may not always result in a permanent delete.  For example, `EE_Soft_Delete_Base_Class::_delete`
1439
+		 * soft deletes (trash) the object and does not permanently delete it.
1440
+		 *
1441
+		 * @param EE_Base_Class $model_object about to be 'deleted'
1442
+		 */
1443
+		do_action('AHEE__EE_Base_Class__delete__before', $this);
1444
+		$result = $this->_delete();
1445
+		/**
1446
+		 * Called just after the `EE_Base_Class::_delete` method call.
1447
+		 * Note: `EE_Base_Class::_delete` might be overridden by child classes so any client code hooking into these actions
1448
+		 * should be aware that `_delete` may not always result in a permanent delete.  For example `EE_Soft_Base_Class::_delete`
1449
+		 * soft deletes (trash) the object and does not permanently delete it.
1450
+		 *
1451
+		 * @param EE_Base_Class $model_object that was just 'deleted'
1452
+		 * @param boolean       $result
1453
+		 */
1454
+		do_action('AHEE__EE_Base_Class__delete__end', $this, $result);
1455
+		return $result;
1456
+	}
1457
+
1458
+
1459
+
1460
+	/**
1461
+	 * Calls the specific delete method for the instantiated class.
1462
+	 * This method is called by the public `EE_Base_Class::delete` method.  Any child classes desiring to override
1463
+	 * default functionality for "delete" (which is to call `permanently_delete`) should override this method NOT
1464
+	 * `EE_Base_Class::delete`
1465
+	 *
1466
+	 * @return bool|int
1467
+	 * @throws \EE_Error
1468
+	 */
1469
+	protected function _delete()
1470
+	{
1471
+		return $this->delete_permanently();
1472
+	}
1473
+
1474
+
1475
+
1476
+	/**
1477
+	 * Deletes this model object permanently from db (but keep in mind related models my block the delete and return an
1478
+	 * error)
1479
+	 *
1480
+	 * @return bool | int
1481
+	 * @throws \EE_Error
1482
+	 */
1483
+	public function delete_permanently()
1484
+	{
1485
+		/**
1486
+		 * Called just before HARD deleting a model object
1487
+		 *
1488
+		 * @param EE_Base_Class $model_object about to be 'deleted'
1489
+		 */
1490
+		do_action('AHEE__EE_Base_Class__delete_permanently__before', $this);
1491
+		$model = $this->get_model();
1492
+		$result = $model->delete_permanently_by_ID($this->ID());
1493
+		$this->refresh_cache_of_related_objects();
1494
+		/**
1495
+		 * Called just after HARD deleting a model object
1496
+		 *
1497
+		 * @param EE_Base_Class $model_object that was just 'deleted'
1498
+		 * @param boolean       $result
1499
+		 */
1500
+		do_action('AHEE__EE_Base_Class__delete_permanently__end', $this, $result);
1501
+		return $result;
1502
+	}
1503
+
1504
+
1505
+
1506
+	/**
1507
+	 * When this model object is deleted, it may still be cached on related model objects. This clears the cache of
1508
+	 * related model objects
1509
+	 *
1510
+	 * @throws \EE_Error
1511
+	 */
1512
+	public function refresh_cache_of_related_objects()
1513
+	{
1514
+		foreach ($this->get_model()->relation_settings() as $relation_name => $relation_obj) {
1515
+			if ( ! empty($this->_model_relations[$relation_name])) {
1516
+				$related_objects = $this->_model_relations[$relation_name];
1517
+				if ($relation_obj instanceof EE_Belongs_To_Relation) {
1518
+					//this relation only stores a single model object, not an array
1519
+					//but let's make it consistent
1520
+					$related_objects = array($related_objects);
1521
+				}
1522
+				foreach ($related_objects as $related_object) {
1523
+					//only refresh their cache if they're in memory
1524
+					if ($related_object instanceof EE_Base_Class) {
1525
+						$related_object->clear_cache($this->get_model()->get_this_model_name(), $this);
1526
+					}
1527
+				}
1528
+			}
1529
+		}
1530
+	}
1531
+
1532
+
1533
+
1534
+	/**
1535
+	 *        Saves this object to the database. An array may be supplied to set some values on this
1536
+	 * object just before saving.
1537
+	 *
1538
+	 * @access public
1539
+	 * @param array $set_cols_n_values keys are field names, values are their new values,
1540
+	 *                                 if provided during the save() method (often client code will change the fields'
1541
+	 *                                 values before calling save)
1542
+	 * @throws \EE_Error
1543
+	 * @return int , 1 on a successful update, the ID of the new entry on insert; 0 on failure or if the model object
1544
+	 *                                 isn't allowed to persist (as determined by EE_Base_Class::allow_persist())
1545
+	 */
1546
+	public function save($set_cols_n_values = array())
1547
+	{
1548
+		/**
1549
+		 * Filters the fields we're about to save on the model object
1550
+		 *
1551
+		 * @param array         $set_cols_n_values
1552
+		 * @param EE_Base_Class $model_object
1553
+		 */
1554
+		$set_cols_n_values = (array)apply_filters('FHEE__EE_Base_Class__save__set_cols_n_values', $set_cols_n_values,
1555
+			$this);
1556
+		//set attributes as provided in $set_cols_n_values
1557
+		foreach ($set_cols_n_values as $column => $value) {
1558
+			$this->set($column, $value);
1559
+		}
1560
+		/**
1561
+		 * Saving a model object.
1562
+		 * Before we perform a save, this action is fired.
1563
+		 *
1564
+		 * @param EE_Base_Class $model_object the model object about to be saved.
1565
+		 */
1566
+		do_action('AHEE__EE_Base_Class__save__begin', $this);
1567
+		if ( ! $this->allow_persist()) {
1568
+			return 0;
1569
+		}
1570
+		//now get current attribute values
1571
+		$save_cols_n_values = $this->_fields;
1572
+		//if the object already has an ID, update it. Otherwise, insert it
1573
+		//also: change the assumption about values passed to the model NOT being prepare dby the model object. They have been
1574
+		$old_assumption_concerning_value_preparation = $this->get_model()
1575
+															->get_assumption_concerning_values_already_prepared_by_model_object();
1576
+		$this->get_model()->assume_values_already_prepared_by_model_object(true);
1577
+		//does this model have an autoincrement PK?
1578
+		if ($this->get_model()->has_primary_key_field()) {
1579
+			if ($this->get_model()->get_primary_key_field()->is_auto_increment()) {
1580
+				//ok check if it's set, if so: update; if not, insert
1581
+				if ( ! empty($save_cols_n_values[self::_get_primary_key_name(get_class($this))])) {
1582
+					$results = $this->get_model()->update_by_ID($save_cols_n_values, $this->ID());
1583
+				} else {
1584
+					unset($save_cols_n_values[self::_get_primary_key_name(get_class($this))]);
1585
+					$results = $this->get_model()->insert($save_cols_n_values);
1586
+					if ($results) {
1587
+						//if successful, set the primary key
1588
+						//but don't use the normal SET method, because it will check if
1589
+						//an item with the same ID exists in the mapper & db, then
1590
+						//will find it in the db (because we just added it) and THAT object
1591
+						//will get added to the mapper before we can add this one!
1592
+						//but if we just avoid using the SET method, all that headache can be avoided
1593
+						$pk_field_name = self::_get_primary_key_name(get_class($this));
1594
+						$this->_fields[$pk_field_name] = $results;
1595
+						$this->_clear_cached_property($pk_field_name);
1596
+						$this->get_model()->add_to_entity_map($this);
1597
+						$this->_update_cached_related_model_objs_fks();
1598
+					}
1599
+				}
1600
+			} else {//PK is NOT auto-increment
1601
+				//so check if one like it already exists in the db
1602
+				if ($this->get_model()->exists_by_ID($this->ID())) {
1603
+					if (WP_DEBUG && ! $this->in_entity_map()) {
1604
+						throw new EE_Error(
1605
+							sprintf(
1606
+								__('Using a model object %1$s that is NOT in the entity map, can lead to unexpected errors. You should either: %4$s 1. Put it in the entity mapper by calling %2$s %4$s 2. Discard this model object and use what is in the entity mapper %4$s 3. Fetch from the database using %3$s',
1607
+									'event_espresso'),
1608
+								get_class($this),
1609
+								get_class($this->get_model()) . '::instance()->add_to_entity_map()',
1610
+								get_class($this->get_model()) . '::instance()->get_one_by_ID()',
1611
+								'<br />'
1612
+							)
1613
+						);
1614
+					}
1615
+					$results = $this->get_model()->update_by_ID($save_cols_n_values, $this->ID());
1616
+				} else {
1617
+					$results = $this->get_model()->insert($save_cols_n_values);
1618
+					$this->_update_cached_related_model_objs_fks();
1619
+				}
1620
+			}
1621
+		} else {//there is NO primary key
1622
+			$already_in_db = false;
1623
+			foreach ($this->get_model()->unique_indexes() as $index) {
1624
+				$uniqueness_where_params = array_intersect_key($save_cols_n_values, $index->fields());
1625
+				if ($this->get_model()->exists(array($uniqueness_where_params))) {
1626
+					$already_in_db = true;
1627
+				}
1628
+			}
1629
+			if ($already_in_db) {
1630
+				$combined_pk_fields_n_values = array_intersect_key($save_cols_n_values,
1631
+					$this->get_model()->get_combined_primary_key_fields());
1632
+				$results = $this->get_model()->update($save_cols_n_values, $combined_pk_fields_n_values);
1633
+			} else {
1634
+				$results = $this->get_model()->insert($save_cols_n_values);
1635
+			}
1636
+		}
1637
+		//restore the old assumption about values being prepared by the model object
1638
+		$this->get_model()
1639
+			 ->assume_values_already_prepared_by_model_object($old_assumption_concerning_value_preparation);
1640
+		/**
1641
+		 * After saving the model object this action is called
1642
+		 *
1643
+		 * @param EE_Base_Class $model_object which was just saved
1644
+		 * @param boolean|int   $results      if it were updated, TRUE or FALSE; if it were newly inserted
1645
+		 *                                    the new ID (or 0 if an error occurred and it wasn't updated)
1646
+		 */
1647
+		do_action('AHEE__EE_Base_Class__save__end', $this, $results);
1648
+		return $results;
1649
+	}
1650
+
1651
+
1652
+
1653
+	/**
1654
+	 * Updates the foreign key on related models objects pointing to this to have this model object's ID
1655
+	 * as their foreign key.  If the cached related model objects already exist in the db, saves them (so that the DB
1656
+	 * is consistent) Especially useful in case we JUST added this model object ot the database and we want to let its
1657
+	 * cached relations with foreign keys to it know about that change. Eg: we've created a transaction but haven't
1658
+	 * saved it to the db. We also create a registration and don't save it to the DB, but we DO cache it on the
1659
+	 * transaction. Now, when we save the transaction, the registration's TXN_ID will be automatically updated, whether
1660
+	 * or not they exist in the DB (if they do, their DB records will be automatically updated)
1661
+	 *
1662
+	 * @return void
1663
+	 * @throws \EE_Error
1664
+	 */
1665
+	protected function _update_cached_related_model_objs_fks()
1666
+	{
1667
+		foreach ($this->get_model()->relation_settings() as $relation_name => $relation_obj) {
1668
+			if ($relation_obj instanceof EE_Has_Many_Relation) {
1669
+				foreach ($this->get_all_from_cache($relation_name) as $related_model_obj_in_cache) {
1670
+					$fk_to_this = $related_model_obj_in_cache->get_model()->get_foreign_key_to(
1671
+						$this->get_model()->get_this_model_name()
1672
+					);
1673
+					$related_model_obj_in_cache->set($fk_to_this->get_name(), $this->ID());
1674
+					if ($related_model_obj_in_cache->ID()) {
1675
+						$related_model_obj_in_cache->save();
1676
+					}
1677
+				}
1678
+			}
1679
+		}
1680
+	}
1681
+
1682
+
1683
+
1684
+	/**
1685
+	 * Saves this model object and its NEW cached relations to the database.
1686
+	 * (Meaning, for now, IT DOES NOT WORK if the cached items already exist in the DB.
1687
+	 * In order for that to work, we would need to mark model objects as dirty/clean...
1688
+	 * because otherwise, there's a potential for infinite looping of saving
1689
+	 * Saves the cached related model objects, and ensures the relation between them
1690
+	 * and this object and properly setup
1691
+	 *
1692
+	 * @return int ID of new model object on save; 0 on failure+
1693
+	 * @throws \EE_Error
1694
+	 */
1695
+	public function save_new_cached_related_model_objs()
1696
+	{
1697
+		//make sure this has been saved
1698
+		if ( ! $this->ID()) {
1699
+			$id = $this->save();
1700
+		} else {
1701
+			$id = $this->ID();
1702
+		}
1703
+		//now save all the NEW cached model objects  (ie they don't exist in the DB)
1704
+		foreach ($this->get_model()->relation_settings() as $relationName => $relationObj) {
1705
+			if ($this->_model_relations[$relationName]) {
1706
+				//is this a relation where we should expect just ONE related object (ie, EE_Belongs_To_relation)
1707
+				//or MANY related objects (ie, EE_HABTM_Relation or EE_Has_Many_Relation)?
1708
+				if ($relationObj instanceof EE_Belongs_To_Relation) {
1709
+					//add a relation to that relation type (which saves the appropriate thing in the process)
1710
+					//but ONLY if it DOES NOT exist in the DB
1711
+					/* @var $related_model_obj EE_Base_Class */
1712
+					$related_model_obj = $this->_model_relations[$relationName];
1713
+					//					if( ! $related_model_obj->ID()){
1714
+					$this->_add_relation_to($related_model_obj, $relationName);
1715
+					$related_model_obj->save_new_cached_related_model_objs();
1716
+					//					}
1717
+				} else {
1718
+					foreach ($this->_model_relations[$relationName] as $related_model_obj) {
1719
+						//add a relation to that relation type (which saves the appropriate thing in the process)
1720
+						//but ONLY if it DOES NOT exist in the DB
1721
+						//						if( ! $related_model_obj->ID()){
1722
+						$this->_add_relation_to($related_model_obj, $relationName);
1723
+						$related_model_obj->save_new_cached_related_model_objs();
1724
+						//						}
1725
+					}
1726
+				}
1727
+			}
1728
+		}
1729
+		return $id;
1730
+	}
1731
+
1732
+
1733
+
1734
+	/**
1735
+	 * for getting a model while instantiated.
1736
+	 *
1737
+	 * @return \EEM_Base | \EEM_CPT_Base
1738
+	 */
1739
+	public function get_model()
1740
+	{
1741
+		$modelName = self::_get_model_classname(get_class($this));
1742
+		return self::_get_model_instance_with_name($modelName, $this->_timezone);
1743
+	}
1744
+
1745
+
1746
+
1747
+	/**
1748
+	 * @param $props_n_values
1749
+	 * @param $classname
1750
+	 * @return mixed bool|EE_Base_Class|EEM_CPT_Base
1751
+	 * @throws \EE_Error
1752
+	 */
1753
+	protected static function _get_object_from_entity_mapper($props_n_values, $classname)
1754
+	{
1755
+		//TODO: will not work for Term_Relationships because they have no PK!
1756
+		$primary_id_ref = self::_get_primary_key_name($classname);
1757
+		if (array_key_exists($primary_id_ref, $props_n_values) && ! empty($props_n_values[$primary_id_ref])) {
1758
+			$id = $props_n_values[$primary_id_ref];
1759
+			return self::_get_model($classname)->get_from_entity_map($id);
1760
+		}
1761
+		return false;
1762
+	}
1763
+
1764
+
1765
+
1766
+	/**
1767
+	 * This is called by child static "new_instance" method and we'll check to see if there is an existing db entry for
1768
+	 * the primary key (if present in incoming values). If there is a key in the incoming array that matches the
1769
+	 * primary key for the model AND it is not null, then we check the db. If there's a an object we return it.  If not
1770
+	 * we return false.
1771
+	 *
1772
+	 * @param  array  $props_n_values   incoming array of properties and their values
1773
+	 * @param  string $classname        the classname of the child class
1774
+	 * @param null    $timezone
1775
+	 * @param array   $date_formats     incoming date_formats in an array where the first value is the
1776
+	 *                                  date_format and the second value is the time format
1777
+	 * @return mixed (EE_Base_Class|bool)
1778
+	 * @throws \EE_Error
1779
+	 */
1780
+	protected static function _check_for_object($props_n_values, $classname, $timezone = null, $date_formats = array())
1781
+	{
1782
+		$existing = null;
1783
+		if (self::_get_model($classname)->has_primary_key_field()) {
1784
+			$primary_id_ref = self::_get_primary_key_name($classname);
1785
+			if (array_key_exists($primary_id_ref, $props_n_values)
1786
+				&& ! empty($props_n_values[$primary_id_ref])
1787
+			) {
1788
+				$existing = self::_get_model($classname, $timezone)->get_one_by_ID(
1789
+					$props_n_values[$primary_id_ref]
1790
+				);
1791
+			}
1792
+		} elseif (self::_get_model($classname, $timezone)->has_all_combined_primary_key_fields($props_n_values)) {
1793
+			//no primary key on this model, but there's still a matching item in the DB
1794
+			$existing = self::_get_model($classname, $timezone)->get_one_by_ID(
1795
+				self::_get_model($classname, $timezone)->get_index_primary_key_string($props_n_values)
1796
+			);
1797
+		}
1798
+		if ($existing) {
1799
+			//set date formats if present before setting values
1800
+			if ( ! empty($date_formats) && is_array($date_formats)) {
1801
+				$existing->set_date_format($date_formats[0]);
1802
+				$existing->set_time_format($date_formats[1]);
1803
+			} else {
1804
+				//set default formats for date and time
1805
+				$existing->set_date_format(get_option('date_format'));
1806
+				$existing->set_time_format(get_option('time_format'));
1807
+			}
1808
+			foreach ($props_n_values as $property => $field_value) {
1809
+				$existing->set($property, $field_value);
1810
+			}
1811
+			return $existing;
1812
+		} else {
1813
+			return false;
1814
+		}
1815
+	}
1816
+
1817
+
1818
+
1819
+	/**
1820
+	 * Gets the EEM_*_Model for this class
1821
+	 *
1822
+	 * @access public now, as this is more convenient
1823
+	 * @param      $classname
1824
+	 * @param null $timezone
1825
+	 * @throws EE_Error
1826
+	 * @return EEM_Base
1827
+	 */
1828
+	protected static function _get_model($classname, $timezone = null)
1829
+	{
1830
+		//find model for this class
1831
+		if ( ! $classname) {
1832
+			throw new EE_Error(
1833
+				sprintf(
1834
+					__(
1835
+						"What were you thinking calling _get_model(%s)?? You need to specify the class name",
1836
+						"event_espresso"
1837
+					),
1838
+					$classname
1839
+				)
1840
+			);
1841
+		}
1842
+		$modelName = self::_get_model_classname($classname);
1843
+		return self::_get_model_instance_with_name($modelName, $timezone);
1844
+	}
1845
+
1846
+
1847
+
1848
+	/**
1849
+	 * Gets the model instance (eg instance of EEM_Attendee) given its classname (eg EE_Attendee)
1850
+	 *
1851
+	 * @param string $model_classname
1852
+	 * @param null   $timezone
1853
+	 * @return EEM_Base
1854
+	 */
1855
+	protected static function _get_model_instance_with_name($model_classname, $timezone = null)
1856
+	{
1857
+		$model_classname = str_replace('EEM_', '', $model_classname);
1858
+		$model = EE_Registry::instance()->load_model($model_classname);
1859
+		$model->set_timezone($timezone);
1860
+		return $model;
1861
+	}
1862
+
1863
+
1864
+
1865
+	/**
1866
+	 * If a model name is provided (eg Registration), gets the model classname for that model.
1867
+	 * Also works if a model class's classname is provided (eg EE_Registration).
1868
+	 *
1869
+	 * @param null $model_name
1870
+	 * @return string like EEM_Attendee
1871
+	 */
1872
+	private static function _get_model_classname($model_name = null)
1873
+	{
1874
+		if (strpos($model_name, "EE_") === 0) {
1875
+			$model_classname = str_replace("EE_", "EEM_", $model_name);
1876
+		} else {
1877
+			$model_classname = "EEM_" . $model_name;
1878
+		}
1879
+		return $model_classname;
1880
+	}
1881
+
1882
+
1883
+
1884
+	/**
1885
+	 * returns the name of the primary key attribute
1886
+	 *
1887
+	 * @param null $classname
1888
+	 * @throws EE_Error
1889
+	 * @return string
1890
+	 */
1891
+	protected static function _get_primary_key_name($classname = null)
1892
+	{
1893
+		if ( ! $classname) {
1894
+			throw new EE_Error(
1895
+				sprintf(
1896
+					__("What were you thinking calling _get_primary_key_name(%s)", "event_espresso"),
1897
+					$classname
1898
+				)
1899
+			);
1900
+		}
1901
+		return self::_get_model($classname)->get_primary_key_field()->get_name();
1902
+	}
1903
+
1904
+
1905
+
1906
+	/**
1907
+	 * Gets the value of the primary key.
1908
+	 * If the object hasn't yet been saved, it should be whatever the model field's default was
1909
+	 * (eg, if this were the EE_Event class, look at the primary key field on EEM_Event and see what its default value
1910
+	 * is. Usually defaults for integer primary keys are 0; string primary keys are usually NULL).
1911
+	 *
1912
+	 * @return mixed, if the primary key is of type INT it'll be an int. Otherwise it could be a string
1913
+	 * @throws \EE_Error
1914
+	 */
1915
+	public function ID()
1916
+	{
1917
+		//now that we know the name of the variable, use a variable variable to get its value and return its
1918
+		if ($this->get_model()->has_primary_key_field()) {
1919
+			return $this->_fields[self::_get_primary_key_name(get_class($this))];
1920
+		} else {
1921
+			return $this->get_model()->get_index_primary_key_string($this->_fields);
1922
+		}
1923
+	}
1924
+
1925
+
1926
+
1927
+	/**
1928
+	 * Adds a relationship to the specified EE_Base_Class object, given the relationship's name. Eg, if the current
1929
+	 * model is related to a group of events, the $relationName should be 'Event', and should be a key in the EE
1930
+	 * Model's $_model_relations array. If this model object doesn't exist in the DB, just caches the related thing
1931
+	 *
1932
+	 * @param mixed  $otherObjectModelObjectOrID       EE_Base_Class or the ID of the other object
1933
+	 * @param string $relationName                     eg 'Events','Question',etc.
1934
+	 *                                                 an attendee to a group, you also want to specify which role they
1935
+	 *                                                 will have in that group. So you would use this parameter to
1936
+	 *                                                 specify array('role-column-name'=>'role-id')
1937
+	 * @param array  $extra_join_model_fields_n_values You can optionally include an array of key=>value pairs that
1938
+	 *                                                 allow you to further constrict the relation to being added.
1939
+	 *                                                 However, keep in mind that the columns (keys) given must match a
1940
+	 *                                                 column on the JOIN table and currently only the HABTM models
1941
+	 *                                                 accept these additional conditions.  Also remember that if an
1942
+	 *                                                 exact match isn't found for these extra cols/val pairs, then a
1943
+	 *                                                 NEW row is created in the join table.
1944
+	 * @param null   $cache_id
1945
+	 * @throws EE_Error
1946
+	 * @return EE_Base_Class the object the relation was added to
1947
+	 */
1948
+	public function _add_relation_to(
1949
+		$otherObjectModelObjectOrID,
1950
+		$relationName,
1951
+		$extra_join_model_fields_n_values = array(),
1952
+		$cache_id = null
1953
+	) {
1954
+		//if this thing exists in the DB, save the relation to the DB
1955
+		if ($this->ID()) {
1956
+			$otherObject = $this->get_model()
1957
+								->add_relationship_to($this, $otherObjectModelObjectOrID, $relationName,
1958
+									$extra_join_model_fields_n_values);
1959
+			//clear cache so future get_many_related and get_first_related() return new results.
1960
+			$this->clear_cache($relationName, $otherObject, true);
1961
+			if ($otherObject instanceof EE_Base_Class) {
1962
+				$otherObject->clear_cache($this->get_model()->get_this_model_name(), $this);
1963
+			}
1964
+		} else {
1965
+			//this thing doesn't exist in the DB,  so just cache it
1966
+			if ( ! $otherObjectModelObjectOrID instanceof EE_Base_Class) {
1967
+				throw new EE_Error(sprintf(
1968
+					__('Before a model object is saved to the database, calls to _add_relation_to must be passed an actual object, not just an ID. You provided %s as the model object to a %s',
1969
+						'event_espresso'),
1970
+					$otherObjectModelObjectOrID,
1971
+					get_class($this)
1972
+				));
1973
+			} else {
1974
+				$otherObject = $otherObjectModelObjectOrID;
1975
+			}
1976
+			$this->cache($relationName, $otherObjectModelObjectOrID, $cache_id);
1977
+		}
1978
+		if ($otherObject instanceof EE_Base_Class) {
1979
+			//fix the reciprocal relation too
1980
+			if ($otherObject->ID()) {
1981
+				//its saved so assumed relations exist in the DB, so we can just
1982
+				//clear the cache so future queries use the updated info in the DB
1983
+				$otherObject->clear_cache($this->get_model()->get_this_model_name(), null, true);
1984
+			} else {
1985
+				//it's not saved, so it caches relations like this
1986
+				$otherObject->cache($this->get_model()->get_this_model_name(), $this);
1987
+			}
1988
+		}
1989
+		return $otherObject;
1990
+	}
1991
+
1992
+
1993
+
1994
+	/**
1995
+	 * Removes a relationship to the specified EE_Base_Class object, given the relationships' name. Eg, if the current
1996
+	 * model is related to a group of events, the $relationName should be 'Events', and should be a key in the EE
1997
+	 * Model's $_model_relations array. If this model object doesn't exist in the DB, just removes the related thing
1998
+	 * from the cache
1999
+	 *
2000
+	 * @param mixed  $otherObjectModelObjectOrID
2001
+	 *                EE_Base_Class or the ID of the other object, OR an array key into the cache if this isn't saved
2002
+	 *                to the DB yet
2003
+	 * @param string $relationName
2004
+	 * @param array  $where_query
2005
+	 *                You can optionally include an array of key=>value pairs that allow you to further constrict the
2006
+	 *                relation to being added. However, keep in mind that the columns (keys) given must match a column
2007
+	 *                on the JOIN table and currently only the HABTM models accept these additional conditions. Also
2008
+	 *                remember that if an exact match isn't found for these extra cols/val pairs, then a NEW row is
2009
+	 *                created in the join table.
2010
+	 * @return EE_Base_Class the relation was removed from
2011
+	 * @throws \EE_Error
2012
+	 */
2013
+	public function _remove_relation_to($otherObjectModelObjectOrID, $relationName, $where_query = array())
2014
+	{
2015
+		if ($this->ID()) {
2016
+			//if this exists in the DB, save the relation change to the DB too
2017
+			$otherObject = $this->get_model()
2018
+								->remove_relationship_to($this, $otherObjectModelObjectOrID, $relationName,
2019
+									$where_query);
2020
+			$this->clear_cache($relationName, $otherObject);
2021
+		} else {
2022
+			//this doesn't exist in the DB, just remove it from the cache
2023
+			$otherObject = $this->clear_cache($relationName, $otherObjectModelObjectOrID);
2024
+		}
2025
+		if ($otherObject instanceof EE_Base_Class) {
2026
+			$otherObject->clear_cache($this->get_model()->get_this_model_name(), $this);
2027
+		}
2028
+		return $otherObject;
2029
+	}
2030
+
2031
+
2032
+
2033
+	/**
2034
+	 * Removes ALL the related things for the $relationName.
2035
+	 *
2036
+	 * @param string $relationName
2037
+	 * @param array  $where_query_params like EEM_Base::get_all's $query_params[0] (where conditions)
2038
+	 * @return EE_Base_Class
2039
+	 * @throws \EE_Error
2040
+	 */
2041
+	public function _remove_relations($relationName, $where_query_params = array())
2042
+	{
2043
+		if ($this->ID()) {
2044
+			//if this exists in the DB, save the relation change to the DB too
2045
+			$otherObjects = $this->get_model()->remove_relations($this, $relationName, $where_query_params);
2046
+			$this->clear_cache($relationName, null, true);
2047
+		} else {
2048
+			//this doesn't exist in the DB, just remove it from the cache
2049
+			$otherObjects = $this->clear_cache($relationName, null, true);
2050
+		}
2051
+		if (is_array($otherObjects)) {
2052
+			foreach ($otherObjects as $otherObject) {
2053
+				$otherObject->clear_cache($this->get_model()->get_this_model_name(), $this);
2054
+			}
2055
+		}
2056
+		return $otherObjects;
2057
+	}
2058
+
2059
+
2060
+
2061
+	/**
2062
+	 * Gets all the related model objects of the specified type. Eg, if the current class if
2063
+	 * EE_Event, you could call $this->get_many_related('Registration') to get an array of all the
2064
+	 * EE_Registration objects which related to this event. Note: by default, we remove the "default query params"
2065
+	 * because we want to get even deleted items etc.
2066
+	 *
2067
+	 * @param string $relationName key in the model's _model_relations array
2068
+	 * @param array  $query_params like EEM_Base::get_all
2069
+	 * @return EE_Base_Class[] Results not necessarily indexed by IDs, because some results might not have primary keys
2070
+	 * @throws \EE_Error
2071
+	 *                             or might not be saved yet. Consider using EEM_Base::get_IDs() on these results if
2072
+	 *                             you want IDs
2073
+	 */
2074
+	public function get_many_related($relationName, $query_params = array())
2075
+	{
2076
+		if ($this->ID()) {
2077
+			//this exists in the DB, so get the related things from either the cache or the DB
2078
+			//if there are query parameters, forget about caching the related model objects.
2079
+			if ($query_params) {
2080
+				$related_model_objects = $this->get_model()->get_all_related($this, $relationName, $query_params);
2081
+			} else {
2082
+				//did we already cache the result of this query?
2083
+				$cached_results = $this->get_all_from_cache($relationName);
2084
+				if ( ! $cached_results) {
2085
+					$related_model_objects = $this->get_model()->get_all_related($this, $relationName, $query_params);
2086
+					//if no query parameters were passed, then we got all the related model objects
2087
+					//for that relation. We can cache them then.
2088
+					foreach ($related_model_objects as $related_model_object) {
2089
+						$this->cache($relationName, $related_model_object);
2090
+					}
2091
+				} else {
2092
+					$related_model_objects = $cached_results;
2093
+				}
2094
+			}
2095
+		} else {
2096
+			//this doesn't exist in the DB, so just get the related things from the cache
2097
+			$related_model_objects = $this->get_all_from_cache($relationName);
2098
+		}
2099
+		return $related_model_objects;
2100
+	}
2101
+
2102
+
2103
+
2104
+	/**
2105
+	 * Instead of getting the related model objects, simply counts them. Ignores default_where_conditions by default,
2106
+	 * unless otherwise specified in the $query_params
2107
+	 *
2108
+	 * @param string $relation_name  model_name like 'Event', or 'Registration'
2109
+	 * @param array  $query_params   like EEM_Base::get_all's
2110
+	 * @param string $field_to_count name of field to count by. By default, uses primary key
2111
+	 * @param bool   $distinct       if we want to only count the distinct values for the column then you can trigger
2112
+	 *                               that by the setting $distinct to TRUE;
2113
+	 * @return int
2114
+	 */
2115
+	public function count_related($relation_name, $query_params = array(), $field_to_count = null, $distinct = false)
2116
+	{
2117
+		return $this->get_model()->count_related($this, $relation_name, $query_params, $field_to_count, $distinct);
2118
+	}
2119
+
2120
+
2121
+
2122
+	/**
2123
+	 * Instead of getting the related model objects, simply sums up the values of the specified field.
2124
+	 * Note: ignores default_where_conditions by default, unless otherwise specified in the $query_params
2125
+	 *
2126
+	 * @param string $relation_name model_name like 'Event', or 'Registration'
2127
+	 * @param array  $query_params  like EEM_Base::get_all's
2128
+	 * @param string $field_to_sum  name of field to count by.
2129
+	 *                              By default, uses primary key (which doesn't make much sense, so you should probably
2130
+	 *                              change it)
2131
+	 * @return int
2132
+	 */
2133
+	public function sum_related($relation_name, $query_params = array(), $field_to_sum = null)
2134
+	{
2135
+		return $this->get_model()->sum_related($this, $relation_name, $query_params, $field_to_sum);
2136
+	}
2137
+
2138
+
2139
+
2140
+	/**
2141
+	 * Gets the first (ie, one) related model object of the specified type.
2142
+	 *
2143
+	 * @param string $relationName key in the model's _model_relations array
2144
+	 * @param array  $query_params like EEM_Base::get_all
2145
+	 * @return EE_Base_Class (not an array, a single object)
2146
+	 * @throws \EE_Error
2147
+	 */
2148
+	public function get_first_related($relationName, $query_params = array())
2149
+	{
2150
+		if ($this->ID()) {//this exists in the DB, get from the cache OR the DB
2151
+			//if they've provided some query parameters, don't bother trying to cache the result
2152
+			//also make sure we're not caching the result of get_first_related
2153
+			//on a relation which should have an array of objects (because the cache might have an array of objects)
2154
+			if ($query_params
2155
+				|| ! $this->get_model()->related_settings_for($relationName)
2156
+					 instanceof
2157
+					 EE_Belongs_To_Relation
2158
+			) {
2159
+				$related_model_object = $this->get_model()->get_first_related($this, $relationName, $query_params);
2160
+			} else {
2161
+				//first, check if we've already cached the result of this query
2162
+				$cached_result = $this->get_one_from_cache($relationName);
2163
+				if ( ! $cached_result) {
2164
+					$related_model_object = $this->get_model()->get_first_related($this, $relationName, $query_params);
2165
+					$this->cache($relationName, $related_model_object);
2166
+				} else {
2167
+					$related_model_object = $cached_result;
2168
+				}
2169
+			}
2170
+		} else {
2171
+			$related_model_object = null;
2172
+			//this doesn't exist in the Db, but maybe the relation is of type belongs to, and so the related thing might
2173
+			if ($this->get_model()->related_settings_for($relationName) instanceof EE_Belongs_To_Relation) {
2174
+				$related_model_object = $this->get_model()->get_first_related($this, $relationName, $query_params);
2175
+			}
2176
+			//this doesn't exist in the DB and apparently the thing it belongs to doesn't either, just get what's cached on this object
2177
+			if ( ! $related_model_object) {
2178
+				$related_model_object = $this->get_one_from_cache($relationName);
2179
+			}
2180
+		}
2181
+		return $related_model_object;
2182
+	}
2183
+
2184
+
2185
+
2186
+	/**
2187
+	 * Does a delete on all related objects of type $relationName and removes
2188
+	 * the current model object's relation to them. If they can't be deleted (because
2189
+	 * of blocking related model objects) does nothing. If the related model objects are
2190
+	 * soft-deletable, they will be soft-deleted regardless of related blocking model objects.
2191
+	 * If this model object doesn't exist yet in the DB, just removes its related things
2192
+	 *
2193
+	 * @param string $relationName
2194
+	 * @param array  $query_params like EEM_Base::get_all's
2195
+	 * @return int how many deleted
2196
+	 * @throws \EE_Error
2197
+	 */
2198
+	public function delete_related($relationName, $query_params = array())
2199
+	{
2200
+		if ($this->ID()) {
2201
+			$count = $this->get_model()->delete_related($this, $relationName, $query_params);
2202
+		} else {
2203
+			$count = count($this->get_all_from_cache($relationName));
2204
+			$this->clear_cache($relationName, null, true);
2205
+		}
2206
+		return $count;
2207
+	}
2208
+
2209
+
2210
+
2211
+	/**
2212
+	 * Does a hard delete (ie, removes the DB row) on all related objects of type $relationName and removes
2213
+	 * the current model object's relation to them. If they can't be deleted (because
2214
+	 * of blocking related model objects) just does a soft delete on it instead, if possible.
2215
+	 * If the related thing isn't a soft-deletable model object, this function is identical
2216
+	 * to delete_related(). If this model object doesn't exist in the DB, just remove its related things
2217
+	 *
2218
+	 * @param string $relationName
2219
+	 * @param array  $query_params like EEM_Base::get_all's
2220
+	 * @return int how many deleted (including those soft deleted)
2221
+	 * @throws \EE_Error
2222
+	 */
2223
+	public function delete_related_permanently($relationName, $query_params = array())
2224
+	{
2225
+		if ($this->ID()) {
2226
+			$count = $this->get_model()->delete_related_permanently($this, $relationName, $query_params);
2227
+		} else {
2228
+			$count = count($this->get_all_from_cache($relationName));
2229
+		}
2230
+		$this->clear_cache($relationName, null, true);
2231
+		return $count;
2232
+	}
2233
+
2234
+
2235
+
2236
+	/**
2237
+	 * is_set
2238
+	 * Just a simple utility function children can use for checking if property exists
2239
+	 *
2240
+	 * @access  public
2241
+	 * @param  string $field_name property to check
2242
+	 * @return bool                              TRUE if existing,FALSE if not.
2243
+	 */
2244
+	public function is_set($field_name)
2245
+	{
2246
+		return isset($this->_fields[$field_name]);
2247
+	}
2248
+
2249
+
2250
+
2251
+	/**
2252
+	 * Just a simple utility function children can use for checking if property (or properties) exists and throwing an
2253
+	 * EE_Error exception if they don't
2254
+	 *
2255
+	 * @param  mixed (string|array) $properties properties to check
2256
+	 * @throws EE_Error
2257
+	 * @return bool                              TRUE if existing, throw EE_Error if not.
2258
+	 */
2259
+	protected function _property_exists($properties)
2260
+	{
2261
+		foreach ((array)$properties as $property_name) {
2262
+			//first make sure this property exists
2263
+			if ( ! $this->_fields[$property_name]) {
2264
+				throw new EE_Error(
2265
+					sprintf(
2266
+						__(
2267
+							'Trying to retrieve a non-existent property (%s).  Double check the spelling please',
2268
+							'event_espresso'
2269
+						),
2270
+						$property_name
2271
+					)
2272
+				);
2273
+			}
2274
+		}
2275
+		return true;
2276
+	}
2277
+
2278
+
2279
+
2280
+	/**
2281
+	 * This simply returns an array of model fields for this object
2282
+	 *
2283
+	 * @return array
2284
+	 * @throws \EE_Error
2285
+	 */
2286
+	public function model_field_array()
2287
+	{
2288
+		$fields = $this->get_model()->field_settings(false);
2289
+		$properties = array();
2290
+		//remove prepended underscore
2291
+		foreach ($fields as $field_name => $settings) {
2292
+			$properties[$field_name] = $this->get($field_name);
2293
+		}
2294
+		return $properties;
2295
+	}
2296
+
2297
+
2298
+
2299
+	/**
2300
+	 * Very handy general function to allow for plugins to extend any child of EE_Base_Class.
2301
+	 * If a method is called on a child of EE_Base_Class that doesn't exist, this function is called
2302
+	 * (http://www.garfieldtech.com/blog/php-magic-call) and passed the method's name and arguments. Instead of
2303
+	 * requiring a plugin to extend the EE_Base_Class (which works fine is there's only 1 plugin, but when will that
2304
+	 * happen?) they can add a hook onto 'filters_hook_espresso__{className}__{methodName}' (eg,
2305
+	 * filters_hook_espresso__EE_Answer__my_great_function) and accepts 2 arguments: the object on which the function
2306
+	 * was called, and an array of the original arguments passed to the function. Whatever their callback function
2307
+	 * returns will be returned by this function. Example: in functions.php (or in a plugin):
2308
+	 * add_filter('FHEE__EE_Answer__my_callback','my_callback',10,3); function
2309
+	 * my_callback($previousReturnValue,EE_Base_Class $object,$argsArray){
2310
+	 * $returnString= "you called my_callback! and passed args:".implode(",",$argsArray);
2311
+	 *        return $previousReturnValue.$returnString;
2312
+	 * }
2313
+	 * require('EE_Answer.class.php');
2314
+	 * $answer= EE_Answer::new_instance(array('REG_ID' => 2,'QST_ID' => 3,'ANS_value' => The answer is 42'));
2315
+	 * echo $answer->my_callback('monkeys',100);
2316
+	 * //will output "you called my_callback! and passed args:monkeys,100"
2317
+	 *
2318
+	 * @param string $methodName name of method which was called on a child of EE_Base_Class, but which
2319
+	 * @param array  $args       array of original arguments passed to the function
2320
+	 * @throws EE_Error
2321
+	 * @return mixed whatever the plugin which calls add_filter decides
2322
+	 */
2323
+	public function __call($methodName, $args)
2324
+	{
2325
+		$className = get_class($this);
2326
+		$tagName = "FHEE__{$className}__{$methodName}";
2327
+		if ( ! has_filter($tagName)) {
2328
+			throw new EE_Error(
2329
+				sprintf(
2330
+					__(
2331
+						"Method %s on class %s does not exist! You can create one with the following code in functions.php or in a plugin: add_filter('%s','my_callback',10,3);function my_callback(\$previousReturnValue,EE_Base_Class \$object, \$argsArray){/*function body*/return \$whatever;}",
2332
+						"event_espresso"
2333
+					),
2334
+					$methodName,
2335
+					$className,
2336
+					$tagName
2337
+				)
2338
+			);
2339
+		}
2340
+		return apply_filters($tagName, null, $this, $args);
2341
+	}
2342
+
2343
+
2344
+
2345
+	/**
2346
+	 * Similar to insert_post_meta, adds a record in the Extra_Meta model's table with the given key and value.
2347
+	 * A $previous_value can be specified in case there are many meta rows with the same key
2348
+	 *
2349
+	 * @param string $meta_key
2350
+	 * @param string $meta_value
2351
+	 * @param string $previous_value
2352
+	 * @return int records updated (or BOOLEAN if we actually ended up inserting the extra meta row)
2353
+	 * @throws \EE_Error
2354
+	 * NOTE: if the values haven't changed, returns 0
2355
+	 */
2356
+	public function update_extra_meta($meta_key, $meta_value, $previous_value = null)
2357
+	{
2358
+		$query_params = array(
2359
+			array(
2360
+				'EXM_key'  => $meta_key,
2361
+				'OBJ_ID'   => $this->ID(),
2362
+				'EXM_type' => $this->get_model()->get_this_model_name(),
2363
+			),
2364
+		);
2365
+		if ($previous_value !== null) {
2366
+			$query_params[0]['EXM_value'] = $meta_value;
2367
+		}
2368
+		$existing_rows_like_that = EEM_Extra_Meta::instance()->get_all($query_params);
2369
+		if ( ! $existing_rows_like_that) {
2370
+			return $this->add_extra_meta($meta_key, $meta_value);
2371
+		} else {
2372
+			foreach ($existing_rows_like_that as $existing_row) {
2373
+				$existing_row->save(array('EXM_value' => $meta_value));
2374
+			}
2375
+			return count($existing_rows_like_that);
2376
+		}
2377
+	}
2378
+
2379
+
2380
+
2381
+	/**
2382
+	 * Adds a new extra meta record. If $unique is set to TRUE, we'll first double-check
2383
+	 * no other extra meta for this model object have the same key. Returns TRUE if the
2384
+	 * extra meta row was entered, false if not
2385
+	 *
2386
+	 * @param string  $meta_key
2387
+	 * @param string  $meta_value
2388
+	 * @param boolean $unique
2389
+	 * @return boolean
2390
+	 * @throws \EE_Error
2391
+	 */
2392
+	public function add_extra_meta($meta_key, $meta_value, $unique = false)
2393
+	{
2394
+		if ($unique) {
2395
+			$existing_extra_meta = EEM_Extra_Meta::instance()->get_one(
2396
+				array(
2397
+					array(
2398
+						'EXM_key'  => $meta_key,
2399
+						'OBJ_ID'   => $this->ID(),
2400
+						'EXM_type' => $this->get_model()->get_this_model_name(),
2401
+					),
2402
+				)
2403
+			);
2404
+			if ($existing_extra_meta) {
2405
+				return false;
2406
+			}
2407
+		}
2408
+		$new_extra_meta = EE_Extra_Meta::new_instance(
2409
+			array(
2410
+				'EXM_key'   => $meta_key,
2411
+				'EXM_value' => $meta_value,
2412
+				'OBJ_ID'    => $this->ID(),
2413
+				'EXM_type'  => $this->get_model()->get_this_model_name(),
2414
+			)
2415
+		);
2416
+		$new_extra_meta->save();
2417
+		return true;
2418
+	}
2419
+
2420
+
2421
+
2422
+	/**
2423
+	 * Deletes all the extra meta rows for this record as specified by key. If $meta_value
2424
+	 * is specified, only deletes extra meta records with that value.
2425
+	 *
2426
+	 * @param string $meta_key
2427
+	 * @param string $meta_value
2428
+	 * @return int number of extra meta rows deleted
2429
+	 * @throws \EE_Error
2430
+	 */
2431
+	public function delete_extra_meta($meta_key, $meta_value = null)
2432
+	{
2433
+		$query_params = array(
2434
+			array(
2435
+				'EXM_key'  => $meta_key,
2436
+				'OBJ_ID'   => $this->ID(),
2437
+				'EXM_type' => $this->get_model()->get_this_model_name(),
2438
+			),
2439
+		);
2440
+		if ($meta_value !== null) {
2441
+			$query_params[0]['EXM_value'] = $meta_value;
2442
+		}
2443
+		return EEM_Extra_Meta::instance()->delete($query_params);
2444
+	}
2445
+
2446
+
2447
+
2448
+	/**
2449
+	 * Gets the extra meta with the given meta key. If you specify "single" we just return 1, otherwise
2450
+	 * an array of everything found. Requires that this model actually have a relation of type EE_Has_Many_Any_Relation.
2451
+	 * You can specify $default is case you haven't found the extra meta
2452
+	 *
2453
+	 * @param string  $meta_key
2454
+	 * @param boolean $single
2455
+	 * @param mixed   $default if we don't find anything, what should we return?
2456
+	 * @return mixed single value if $single; array if ! $single
2457
+	 * @throws \EE_Error
2458
+	 */
2459
+	public function get_extra_meta($meta_key, $single = false, $default = null)
2460
+	{
2461
+		if ($single) {
2462
+			$result = $this->get_first_related('Extra_Meta', array(array('EXM_key' => $meta_key)));
2463
+			if ($result instanceof EE_Extra_Meta) {
2464
+				return $result->value();
2465
+			} else {
2466
+				return $default;
2467
+			}
2468
+		} else {
2469
+			$results = $this->get_many_related('Extra_Meta', array(array('EXM_key' => $meta_key)));
2470
+			if ($results) {
2471
+				$values = array();
2472
+				foreach ($results as $result) {
2473
+					if ($result instanceof EE_Extra_Meta) {
2474
+						$values[$result->ID()] = $result->value();
2475
+					}
2476
+				}
2477
+				return $values;
2478
+			} else {
2479
+				return $default;
2480
+			}
2481
+		}
2482
+	}
2483
+
2484
+
2485
+
2486
+	/**
2487
+	 * Returns a simple array of all the extra meta associated with this model object.
2488
+	 * If $one_of_each_key is true (Default), it will be an array of simple key-value pairs, keys being the
2489
+	 * extra meta's key, and teh value being its value. However, if there are duplicate extra meta rows with
2490
+	 * the same key, only one will be used. (eg array('foo'=>'bar','monkey'=>123))
2491
+	 * If $one_of_each_key is false, it will return an array with the top-level keys being
2492
+	 * the extra meta keys, but their values are also arrays, which have the extra-meta's ID as their sub-key, and
2493
+	 * finally the extra meta's value as each sub-value. (eg
2494
+	 * array('foo'=>array(1=>'bar',2=>'bill'),'monkey'=>array(3=>123)))
2495
+	 *
2496
+	 * @param boolean $one_of_each_key
2497
+	 * @return array
2498
+	 * @throws \EE_Error
2499
+	 */
2500
+	public function all_extra_meta_array($one_of_each_key = true)
2501
+	{
2502
+		$return_array = array();
2503
+		if ($one_of_each_key) {
2504
+			$extra_meta_objs = $this->get_many_related('Extra_Meta', array('group_by' => 'EXM_key'));
2505
+			foreach ($extra_meta_objs as $extra_meta_obj) {
2506
+				if ($extra_meta_obj instanceof EE_Extra_Meta) {
2507
+					$return_array[$extra_meta_obj->key()] = $extra_meta_obj->value();
2508
+				}
2509
+			}
2510
+		} else {
2511
+			$extra_meta_objs = $this->get_many_related('Extra_Meta');
2512
+			foreach ($extra_meta_objs as $extra_meta_obj) {
2513
+				if ($extra_meta_obj instanceof EE_Extra_Meta) {
2514
+					if ( ! isset($return_array[$extra_meta_obj->key()])) {
2515
+						$return_array[$extra_meta_obj->key()] = array();
2516
+					}
2517
+					$return_array[$extra_meta_obj->key()][$extra_meta_obj->ID()] = $extra_meta_obj->value();
2518
+				}
2519
+			}
2520
+		}
2521
+		return $return_array;
2522
+	}
2523
+
2524
+
2525
+
2526
+	/**
2527
+	 * Gets a pretty nice displayable nice for this model object. Often overridden
2528
+	 *
2529
+	 * @return string
2530
+	 * @throws \EE_Error
2531
+	 */
2532
+	public function name()
2533
+	{
2534
+		//find a field that's not a text field
2535
+		$field_we_can_use = $this->get_model()->get_a_field_of_type('EE_Text_Field_Base');
2536
+		if ($field_we_can_use) {
2537
+			return $this->get($field_we_can_use->get_name());
2538
+		} else {
2539
+			$first_few_properties = $this->model_field_array();
2540
+			$first_few_properties = array_slice($first_few_properties, 0, 3);
2541
+			$name_parts = array();
2542
+			foreach ($first_few_properties as $name => $value) {
2543
+				$name_parts[] = "$name:$value";
2544
+			}
2545
+			return implode(",", $name_parts);
2546
+		}
2547
+	}
2548
+
2549
+
2550
+
2551
+	/**
2552
+	 * in_entity_map
2553
+	 * Checks if this model object has been proven to already be in the entity map
2554
+	 *
2555
+	 * @return boolean
2556
+	 * @throws \EE_Error
2557
+	 */
2558
+	public function in_entity_map()
2559
+	{
2560
+		if ($this->ID() && $this->get_model()->get_from_entity_map($this->ID()) === $this) {
2561
+			//well, if we looked, did we find it in the entity map?
2562
+			return true;
2563
+		} else {
2564
+			return false;
2565
+		}
2566
+	}
2567
+
2568
+
2569
+
2570
+	/**
2571
+	 * refresh_from_db
2572
+	 * Makes sure the fields and values on this model object are in-sync with what's in the database.
2573
+	 *
2574
+	 * @throws EE_Error if this model object isn't in the entity mapper (because then you should
2575
+	 * just use what's in the entity mapper and refresh it) and WP_DEBUG is TRUE
2576
+	 */
2577
+	public function refresh_from_db()
2578
+	{
2579
+		if ($this->ID() && $this->in_entity_map()) {
2580
+			$this->get_model()->refresh_entity_map_from_db($this->ID());
2581
+		} else {
2582
+			//if it doesn't have ID, you shouldn't be asking to refresh it from teh database (because its not in the database)
2583
+			//if it has an ID but it's not in the map, and you're asking me to refresh it
2584
+			//that's kinda dangerous. You should just use what's in the entity map, or add this to the entity map if there's
2585
+			//absolutely nothing in it for this ID
2586
+			if (WP_DEBUG) {
2587
+				throw new EE_Error(
2588
+					sprintf(
2589
+						__('Trying to refresh a model object with ID "%1$s" that\'s not in the entity map? First off: you should put it in the entity map by calling %2$s. Second off, if you want what\'s in the database right now, you should just call %3$s yourself and discard this model object.',
2590
+							'event_espresso'),
2591
+						$this->ID(),
2592
+						get_class($this->get_model()) . '::instance()->add_to_entity_map()',
2593
+						get_class($this->get_model()) . '::instance()->refresh_entity_map()'
2594
+					)
2595
+				);
2596
+			}
2597
+		}
2598
+	}
2599
+
2600
+
2601
+
2602
+	/**
2603
+	 * Because some other plugins, like Advanced Cron Manager, expect all objects to have this method
2604
+	 * (probably a bad assumption they have made, oh well)
2605
+	 *
2606
+	 * @return string
2607
+	 */
2608
+	public function __toString()
2609
+	{
2610
+		try {
2611
+			return sprintf('%s (%s)', $this->name(), $this->ID());
2612
+		} catch (Exception $e) {
2613
+			EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
2614
+			return '';
2615
+		}
2616
+	}
2617
+
2618
+
2619
+
2620
+	/**
2621
+	 * Clear related model objects if they're already in the DB, because otherwise when we
2622
+	 * UN-serialize this model object we'll need to be careful to add them to the entity map.
2623
+	 * This means if we have made changes to those related model objects, and want to unserialize
2624
+	 * the this model object on a subsequent request, changes to those related model objects will be lost.
2625
+	 * Instead, those related model objects should be directly serialized and stored.
2626
+	 * Eg, the following won't work:
2627
+	 * $reg = EEM_Registration::instance()->get_one_by_ID( 123 );
2628
+	 * $att = $reg->attendee();
2629
+	 * $att->set( 'ATT_fname', 'Dirk' );
2630
+	 * update_option( 'my_option', serialize( $reg ) );
2631
+	 * //END REQUEST
2632
+	 * //START NEXT REQUEST
2633
+	 * $reg = get_option( 'my_option' );
2634
+	 * $reg->attendee()->save();
2635
+	 * And would need to be replace with:
2636
+	 * $reg = EEM_Registration::instance()->get_one_by_ID( 123 );
2637
+	 * $att = $reg->attendee();
2638
+	 * $att->set( 'ATT_fname', 'Dirk' );
2639
+	 * update_option( 'my_option', serialize( $reg ) );
2640
+	 * //END REQUEST
2641
+	 * //START NEXT REQUEST
2642
+	 * $att = get_option( 'my_option' );
2643
+	 * $att->save();
2644
+	 *
2645
+	 * @return array
2646
+	 * @throws \EE_Error
2647
+	 */
2648
+	public function __sleep()
2649
+	{
2650
+		foreach ($this->get_model()->relation_settings() as $relation_name => $relation_obj) {
2651
+			if ($relation_obj instanceof EE_Belongs_To_Relation) {
2652
+				$classname = 'EE_' . $this->get_model()->get_this_model_name();
2653
+				if (
2654
+					$this->get_one_from_cache($relation_name) instanceof $classname
2655
+					&& $this->get_one_from_cache($relation_name)->ID()
2656
+				) {
2657
+					$this->clear_cache($relation_name, $this->get_one_from_cache($relation_name)->ID());
2658
+				}
2659
+			}
2660
+		}
2661
+		$this->_props_n_values_provided_in_constructor = array();
2662
+		return array_keys(get_object_vars($this));
2663
+	}
2664
+
2665
+
2666
+
2667
+	/**
2668
+	 * restore _props_n_values_provided_in_constructor
2669
+	 * PLZ NOTE: this will reset the array to whatever fields values were present prior to serialization,
2670
+	 * and therefore should NOT be used to determine if state change has occurred since initial construction.
2671
+	 * At best, you would only be able to detect if state change has occurred during THIS request.
2672
+	 */
2673
+	public function __wakeup()
2674
+	{
2675
+		$this->_props_n_values_provided_in_constructor = $this->_fields;
2676
+	}
2677 2677
 
2678 2678
 
2679 2679
 
Please login to merge, or discard this patch.
core/services/payment_methods/gateways/GatewayDataFormatter.php 1 patch
Indentation   +116 added lines, -116 removed lines patch added patch discarded remove patch
@@ -17,122 +17,122 @@
 block discarded – undo
17 17
 class GatewayDataFormatter implements GatewayDataFormatterInterface
18 18
 {
19 19
 
20
-    /**
21
-     * Gets the text to use for a gateway's line item name when this is a partial payment
22
-     *
23
-     * @param \EEI_Payment $payment
24
-     * @return string
25
-     */
26
-    public function formatPartialPaymentLineItemName(\EEI_Payment $payment)
27
-    {
28
-        return apply_filters(
29
-            'EEG_Paypal_Pro__do_direct_payment__partial_amount_line_item_name',
30
-            $payment->get_first_event_name(),
31
-            $this,
32
-            $payment
33
-        );
34
-    }
35
-
36
-
37
-
38
-    /**
39
-     * Gets the text to use for a gateway's line item description when this is a partial payment
40
-     *
41
-     * @param \EEI_Payment $payment
42
-     * @return string
43
-     */
44
-    public function formatPartialPaymentLineItemDesc(\EEI_Payment $payment)
45
-    {
46
-        return apply_filters(
47
-            'FHEE__EE_Gateway___partial_payment_desc',
48
-            sprintf(
49
-                __("Payment of %s for %s", "event_espresso"),
50
-                $payment->get_pretty('PAY_amount', 'no_currency_code'),
51
-                $payment->get_first_event_name()
52
-            ),
53
-            $this,
54
-            $payment
55
-        );
56
-    }
57
-
58
-
59
-
60
-    /**
61
-     * Gets the name to use for a line item when sending line items to the gateway
62
-     *
63
-     * @param \EEI_Line_Item $line_item
64
-     * @param \EEI_Payment   $payment
65
-     * @return string
66
-     */
67
-    public function formatLineItemName(\EEI_Line_Item $line_item, \EEI_Payment $payment)
68
-    {
69
-        return apply_filters(
70
-            'FHEE__EE_gateway___line_item_name',
71
-            sprintf(
72
-                _x('%1$s for %2$s', 'Ticket for Event', 'event_espresso'),
73
-                $line_item->name(),
74
-                $line_item->ticket_event_name()
75
-            ),
76
-            $this,
77
-            $line_item,
78
-            $payment
79
-        );
80
-    }
81
-
82
-
83
-
84
-    /**
85
-     * Gets the description to use for a line item when sending line items to the gateway
86
-     *
87
-     * @param \EEI_Line_Item $line_item
88
-     * @param \EEI_Payment   $payment
89
-     * @return string
90
-     */
91
-    public function formatLineItemDesc(\EEI_Line_Item $line_item, \EEI_Payment $payment)
92
-    {
93
-        return apply_filters(
94
-            'FHEE__EE_Gateway___line_item_desc',
95
-            $line_item->desc(),
96
-            $this,
97
-            $line_item,
98
-            $payment
99
-        );
100
-    }
101
-
102
-
103
-
104
-    /**
105
-     * Gets the order description that should generally be sent to gateways
106
-     *
107
-     * @param \EEI_Payment $payment
108
-     * @return string
109
-     */
110
-    public function formatOrderDescription(\EEI_Payment $payment)
111
-    {
112
-        return apply_filters(
113
-            'FHEE__EE_Gateway___order_description',
114
-            sprintf(
115
-                __('Event Registrations from %1$s for %2$s', "event_espresso"),
116
-                get_bloginfo('name'),
117
-                $payment->get_first_event_name()
118
-            ),
119
-            $this,
120
-            $payment
121
-        );
122
-    }
123
-
124
-
125
-
126
-    /**
127
-     * Formats the amount so it can generally be sent to gateways
128
-     *
129
-     * @param float $amount
130
-     * @return string
131
-     */
132
-    public function formatCurrency($amount)
133
-    {
134
-        return number_format($amount, 2, '.', '');
135
-    }
20
+	/**
21
+	 * Gets the text to use for a gateway's line item name when this is a partial payment
22
+	 *
23
+	 * @param \EEI_Payment $payment
24
+	 * @return string
25
+	 */
26
+	public function formatPartialPaymentLineItemName(\EEI_Payment $payment)
27
+	{
28
+		return apply_filters(
29
+			'EEG_Paypal_Pro__do_direct_payment__partial_amount_line_item_name',
30
+			$payment->get_first_event_name(),
31
+			$this,
32
+			$payment
33
+		);
34
+	}
35
+
36
+
37
+
38
+	/**
39
+	 * Gets the text to use for a gateway's line item description when this is a partial payment
40
+	 *
41
+	 * @param \EEI_Payment $payment
42
+	 * @return string
43
+	 */
44
+	public function formatPartialPaymentLineItemDesc(\EEI_Payment $payment)
45
+	{
46
+		return apply_filters(
47
+			'FHEE__EE_Gateway___partial_payment_desc',
48
+			sprintf(
49
+				__("Payment of %s for %s", "event_espresso"),
50
+				$payment->get_pretty('PAY_amount', 'no_currency_code'),
51
+				$payment->get_first_event_name()
52
+			),
53
+			$this,
54
+			$payment
55
+		);
56
+	}
57
+
58
+
59
+
60
+	/**
61
+	 * Gets the name to use for a line item when sending line items to the gateway
62
+	 *
63
+	 * @param \EEI_Line_Item $line_item
64
+	 * @param \EEI_Payment   $payment
65
+	 * @return string
66
+	 */
67
+	public function formatLineItemName(\EEI_Line_Item $line_item, \EEI_Payment $payment)
68
+	{
69
+		return apply_filters(
70
+			'FHEE__EE_gateway___line_item_name',
71
+			sprintf(
72
+				_x('%1$s for %2$s', 'Ticket for Event', 'event_espresso'),
73
+				$line_item->name(),
74
+				$line_item->ticket_event_name()
75
+			),
76
+			$this,
77
+			$line_item,
78
+			$payment
79
+		);
80
+	}
81
+
82
+
83
+
84
+	/**
85
+	 * Gets the description to use for a line item when sending line items to the gateway
86
+	 *
87
+	 * @param \EEI_Line_Item $line_item
88
+	 * @param \EEI_Payment   $payment
89
+	 * @return string
90
+	 */
91
+	public function formatLineItemDesc(\EEI_Line_Item $line_item, \EEI_Payment $payment)
92
+	{
93
+		return apply_filters(
94
+			'FHEE__EE_Gateway___line_item_desc',
95
+			$line_item->desc(),
96
+			$this,
97
+			$line_item,
98
+			$payment
99
+		);
100
+	}
101
+
102
+
103
+
104
+	/**
105
+	 * Gets the order description that should generally be sent to gateways
106
+	 *
107
+	 * @param \EEI_Payment $payment
108
+	 * @return string
109
+	 */
110
+	public function formatOrderDescription(\EEI_Payment $payment)
111
+	{
112
+		return apply_filters(
113
+			'FHEE__EE_Gateway___order_description',
114
+			sprintf(
115
+				__('Event Registrations from %1$s for %2$s', "event_espresso"),
116
+				get_bloginfo('name'),
117
+				$payment->get_first_event_name()
118
+			),
119
+			$this,
120
+			$payment
121
+		);
122
+	}
123
+
124
+
125
+
126
+	/**
127
+	 * Formats the amount so it can generally be sent to gateways
128
+	 *
129
+	 * @param float $amount
130
+	 * @return string
131
+	 */
132
+	public function formatCurrency($amount)
133
+	{
134
+		return number_format($amount, 2, '.', '');
135
+	}
136 136
 }
137 137
 // End of file GatewayDataFormatter.php
138 138
 // Location: core\services\gateways/GatewayDataFormatter.php
139 139
\ No newline at end of file
Please login to merge, or discard this patch.
core/services/payment_methods/gateways/GatewayDataFormatterInterface.php 1 patch
Indentation   +44 added lines, -44 removed lines patch added patch discarded remove patch
@@ -16,65 +16,65 @@
 block discarded – undo
16 16
 interface GatewayDataFormatterInterface
17 17
 {
18 18
 
19
-    /**
20
-     * Gets the text to use for a gateway's line item name when this is a partial payment
21
-     *
22
-     * @param \EEI_Payment $payment
23
-     * @return string
24
-     */
25
-    public function formatPartialPaymentLineItemName(\EEI_Payment $payment);
19
+	/**
20
+	 * Gets the text to use for a gateway's line item name when this is a partial payment
21
+	 *
22
+	 * @param \EEI_Payment $payment
23
+	 * @return string
24
+	 */
25
+	public function formatPartialPaymentLineItemName(\EEI_Payment $payment);
26 26
 
27 27
 
28 28
 
29
-    /**
30
-     * Gets the text to use for a gateway's line item description when this is a partial payment
31
-     *
32
-     * @param \EEI_Payment $payment
33
-     * @return string
34
-     */
35
-    public function formatPartialPaymentLineItemDesc(\EEI_Payment $payment);
29
+	/**
30
+	 * Gets the text to use for a gateway's line item description when this is a partial payment
31
+	 *
32
+	 * @param \EEI_Payment $payment
33
+	 * @return string
34
+	 */
35
+	public function formatPartialPaymentLineItemDesc(\EEI_Payment $payment);
36 36
 
37 37
 
38 38
 
39
-    /**
40
-     * Gets the name to use for a line item when sending line items to the gateway
41
-     *
42
-     * @param \EEI_Line_Item $line_item
43
-     * @param \EEI_Payment   $payment
44
-     * @return string
45
-     */
46
-    public function formatLineItemName(\EEI_Line_Item $line_item, \EEI_Payment $payment);
39
+	/**
40
+	 * Gets the name to use for a line item when sending line items to the gateway
41
+	 *
42
+	 * @param \EEI_Line_Item $line_item
43
+	 * @param \EEI_Payment   $payment
44
+	 * @return string
45
+	 */
46
+	public function formatLineItemName(\EEI_Line_Item $line_item, \EEI_Payment $payment);
47 47
 
48 48
 
49 49
 
50
-    /**
51
-     * Gets the description to use for a line item when sending line items to the gateway
52
-     *
53
-     * @param \EEI_Line_Item $line_item
54
-     * @param \EEI_Payment   $payment
55
-     * @return string
56
-     */
57
-    public function formatLineItemDesc(\EEI_Line_Item $line_item, \EEI_Payment $payment);
50
+	/**
51
+	 * Gets the description to use for a line item when sending line items to the gateway
52
+	 *
53
+	 * @param \EEI_Line_Item $line_item
54
+	 * @param \EEI_Payment   $payment
55
+	 * @return string
56
+	 */
57
+	public function formatLineItemDesc(\EEI_Line_Item $line_item, \EEI_Payment $payment);
58 58
 
59 59
 
60 60
 
61
-    /**
62
-     * Gets the order description that should generally be sent to gateways
63
-     *
64
-     * @param \EEI_Payment $payment
65
-     * @return string
66
-     */
67
-    public function formatOrderDescription(\EEI_Payment $payment);
61
+	/**
62
+	 * Gets the order description that should generally be sent to gateways
63
+	 *
64
+	 * @param \EEI_Payment $payment
65
+	 * @return string
66
+	 */
67
+	public function formatOrderDescription(\EEI_Payment $payment);
68 68
 
69 69
 
70 70
 
71
-    /**
72
-     * Formats the amount so it can generally be sent to gateways
73
-     *
74
-     * @param float $amount
75
-     * @return string
76
-     */
77
-    public function formatCurrency($amount);
71
+	/**
72
+	 * Formats the amount so it can generally be sent to gateways
73
+	 *
74
+	 * @param float $amount
75
+	 * @return string
76
+	 */
77
+	public function formatCurrency($amount);
78 78
 }
79 79
 // End of file GatewayDataFormatterInterface.php
80 80
 // Location: core\services\payment_methods\gateways/GatewayDataFormatterInterface.php
81 81
\ No newline at end of file
Please login to merge, or discard this patch.
core/EE_Config.core.php 2 patches
Indentation   +3130 added lines, -3130 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php if ( ! defined('EVENT_ESPRESSO_VERSION')) {
2
-    exit('No direct script access allowed');
2
+	exit('No direct script access allowed');
3 3
 }
4 4
 
5 5
 
@@ -14,2515 +14,2515 @@  discard block
 block discarded – undo
14 14
 final class EE_Config
15 15
 {
16 16
 
17
-    const OPTION_NAME        = 'ee_config';
17
+	const OPTION_NAME        = 'ee_config';
18
+
19
+	const LOG_NAME           = 'ee_config_log';
20
+
21
+	const LOG_LENGTH         = 100;
22
+
23
+	const ADDON_OPTION_NAMES = 'ee_config_option_names';
24
+
25
+
26
+	/**
27
+	 *    instance of the EE_Config object
28
+	 *
29
+	 * @var    EE_Config $_instance
30
+	 * @access    private
31
+	 */
32
+	private static $_instance;
33
+
34
+	/**
35
+	 * @var boolean $_logging_enabled
36
+	 */
37
+	private static $_logging_enabled = false;
38
+
39
+	/**
40
+	 * An StdClass whose property names are addon slugs,
41
+	 * and values are their config classes
42
+	 *
43
+	 * @var StdClass
44
+	 */
45
+	public $addons;
46
+
47
+	/**
48
+	 * @var EE_Admin_Config
49
+	 */
50
+	public $admin;
51
+
52
+	/**
53
+	 * @var EE_Core_Config
54
+	 */
55
+	public $core;
56
+
57
+	/**
58
+	 * @var EE_Currency_Config
59
+	 */
60
+	public $currency;
61
+
62
+	/**
63
+	 * @var EE_Organization_Config
64
+	 */
65
+	public $organization;
66
+
67
+	/**
68
+	 * @var EE_Registration_Config
69
+	 */
70
+	public $registration;
71
+
72
+	/**
73
+	 * @var EE_Template_Config
74
+	 */
75
+	public $template_settings;
76
+
77
+	/**
78
+	 * Holds EE environment values.
79
+	 *
80
+	 * @var EE_Environment_Config
81
+	 */
82
+	public $environment;
83
+
84
+	/**
85
+	 * settings pertaining to Google maps
86
+	 *
87
+	 * @var EE_Map_Config
88
+	 */
89
+	public $map_settings;
90
+
91
+	/**
92
+	 * settings pertaining to Taxes
93
+	 *
94
+	 * @var EE_Tax_Config
95
+	 */
96
+	public $tax_settings;
97
+
98
+
99
+	/**
100
+	 * Settings pertaining to global messages settings.
101
+	 *
102
+	 * @var EE_Messages_Config
103
+	 */
104
+	public $messages;
105
+
106
+	/**
107
+	 * @deprecated
108
+	 * @var EE_Gateway_Config
109
+	 */
110
+	public $gateway;
111
+
112
+	/**
113
+	 * @var    array $_addon_option_names
114
+	 * @access    private
115
+	 */
116
+	private $_addon_option_names = array();
117
+
118
+	/**
119
+	 * @var    array $_module_route_map
120
+	 * @access    private
121
+	 */
122
+	private static $_module_route_map = array();
123
+
124
+	/**
125
+	 * @var    array $_module_forward_map
126
+	 * @access    private
127
+	 */
128
+	private static $_module_forward_map = array();
129
+
130
+	/**
131
+	 * @var    array $_module_view_map
132
+	 * @access    private
133
+	 */
134
+	private static $_module_view_map = array();
135
+
136
+
137
+
138
+	/**
139
+	 * @singleton method used to instantiate class object
140
+	 * @access    public
141
+	 * @return EE_Config instance
142
+	 */
143
+	public static function instance()
144
+	{
145
+		// check if class object is instantiated, and instantiated properly
146
+		if (! self::$_instance instanceof EE_Config) {
147
+			self::$_instance = new self();
148
+		}
149
+		return self::$_instance;
150
+	}
151
+
152
+
153
+
154
+	/**
155
+	 * Resets the config
156
+	 *
157
+	 * @param bool    $hard_reset    if TRUE, sets EE_CONFig back to its original settings in the database. If FALSE
158
+	 *                               (default) leaves the database alone, and merely resets the EE_Config object to
159
+	 *                               reflect its state in the database
160
+	 * @param boolean $reinstantiate if TRUE (default) call instance() and return it. Otherwise, just leave
161
+	 *                               $_instance as NULL. Useful in case you want to forget about the old instance on
162
+	 *                               EE_Config, but might not be ready to instantiate EE_Config currently (eg if the
163
+	 *                               site was put into maintenance mode)
164
+	 * @return EE_Config
165
+	 */
166
+	public static function reset($hard_reset = false, $reinstantiate = true)
167
+	{
168
+		if (self::$_instance instanceof EE_Config) {
169
+			if ($hard_reset) {
170
+				self::$_instance->_addon_option_names = array();
171
+				self::$_instance->_initialize_config();
172
+				self::$_instance->update_espresso_config();
173
+			}
174
+			self::$_instance->update_addon_option_names();
175
+		}
176
+		self::$_instance = null;
177
+		//we don't need to reset the static properties imo because those should
178
+		//only change when a module is added or removed. Currently we don't
179
+		//support removing a module during a request when it previously existed
180
+		if ($reinstantiate) {
181
+			return self::instance();
182
+		} else {
183
+			return null;
184
+		}
185
+	}
186
+
187
+
188
+
189
+	/**
190
+	 *    class constructor
191
+	 *
192
+	 * @access    private
193
+	 */
194
+	private function __construct()
195
+	{
196
+		do_action('AHEE__EE_Config__construct__begin', $this);
197
+		EE_Config::$_logging_enabled = apply_filters('FHEE__EE_Config___construct__logging_enabled', false);
198
+		// setup empty config classes
199
+		$this->_initialize_config();
200
+		// load existing EE site settings
201
+		$this->_load_core_config();
202
+		// confirm everything loaded correctly and set filtered defaults if not
203
+		$this->_verify_config();
204
+		//  register shortcodes and modules
205
+		add_action(
206
+			'AHEE__EE_System__register_shortcodes_modules_and_widgets',
207
+			array($this, 'register_shortcodes_and_modules'),
208
+			999
209
+		);
210
+		//  initialize shortcodes and modules
211
+		add_action('AHEE__EE_System__core_loaded_and_ready', array($this, 'initialize_shortcodes_and_modules'));
212
+		// register widgets
213
+		add_action('widgets_init', array($this, 'widgets_init'), 10);
214
+		// shutdown
215
+		add_action('shutdown', array($this, 'shutdown'), 10);
216
+		// construct__end hook
217
+		do_action('AHEE__EE_Config__construct__end', $this);
218
+		// hardcoded hack
219
+		$this->template_settings->current_espresso_theme = 'Espresso_Arabica_2014';
220
+	}
221
+
222
+
223
+
224
+	/**
225
+	 * @return boolean
226
+	 */
227
+	public static function logging_enabled()
228
+	{
229
+		return self::$_logging_enabled;
230
+	}
231
+
232
+
233
+
234
+	/**
235
+	 * use to get the current theme if needed from static context
236
+	 *
237
+	 * @return string current theme set.
238
+	 */
239
+	public static function get_current_theme()
240
+	{
241
+		return isset(self::$_instance->template_settings->current_espresso_theme)
242
+			? self::$_instance->template_settings->current_espresso_theme : 'Espresso_Arabica_2014';
243
+	}
244
+
245
+
246
+
247
+	/**
248
+	 *        _initialize_config
249
+	 *
250
+	 * @access private
251
+	 * @return void
252
+	 */
253
+	private function _initialize_config()
254
+	{
255
+		EE_Config::trim_log();
256
+		//set defaults
257
+		$this->_addon_option_names = get_option(EE_Config::ADDON_OPTION_NAMES, array());
258
+		$this->addons = new stdClass();
259
+		// set _module_route_map
260
+		EE_Config::$_module_route_map = array();
261
+		// set _module_forward_map
262
+		EE_Config::$_module_forward_map = array();
263
+		// set _module_view_map
264
+		EE_Config::$_module_view_map = array();
265
+	}
266
+
267
+
268
+
269
+	/**
270
+	 *        load core plugin configuration
271
+	 *
272
+	 * @access private
273
+	 * @return void
274
+	 */
275
+	private function _load_core_config()
276
+	{
277
+		// load_core_config__start hook
278
+		do_action('AHEE__EE_Config___load_core_config__start', $this);
279
+		$espresso_config = $this->get_espresso_config();
280
+		foreach ($espresso_config as $config => $settings) {
281
+			// load_core_config__start hook
282
+			$settings = apply_filters(
283
+				'FHEE__EE_Config___load_core_config__config_settings',
284
+				$settings,
285
+				$config,
286
+				$this
287
+			);
288
+			if (is_object($settings) && property_exists($this, $config)) {
289
+				$this->{$config} = apply_filters('FHEE__EE_Config___load_core_config__' . $config, $settings);
290
+				//call configs populate method to ensure any defaults are set for empty values.
291
+				if (method_exists($settings, 'populate')) {
292
+					$this->{$config}->populate();
293
+				}
294
+				if (method_exists($settings, 'do_hooks')) {
295
+					$this->{$config}->do_hooks();
296
+				}
297
+			}
298
+		}
299
+		if (apply_filters('FHEE__EE_Config___load_core_config__update_espresso_config', false)) {
300
+			$this->update_espresso_config();
301
+		}
302
+		// load_core_config__end hook
303
+		do_action('AHEE__EE_Config___load_core_config__end', $this);
304
+	}
305
+
306
+
307
+
308
+	/**
309
+	 *    _verify_config
310
+	 *
311
+	 * @access    protected
312
+	 * @return    void
313
+	 */
314
+	protected function _verify_config()
315
+	{
316
+		$this->core = $this->core instanceof EE_Core_Config
317
+			? $this->core
318
+			: new EE_Core_Config();
319
+		$this->core = apply_filters('FHEE__EE_Config___initialize_config__core', $this->core);
320
+		$this->organization = $this->organization instanceof EE_Organization_Config
321
+			? $this->organization
322
+			: new EE_Organization_Config();
323
+		$this->organization = apply_filters('FHEE__EE_Config___initialize_config__organization',
324
+			$this->organization);
325
+		$this->currency = $this->currency instanceof EE_Currency_Config
326
+			? $this->currency
327
+			: new EE_Currency_Config();
328
+		$this->currency = apply_filters('FHEE__EE_Config___initialize_config__currency', $this->currency);
329
+		$this->registration = $this->registration instanceof EE_Registration_Config
330
+			? $this->registration
331
+			: new EE_Registration_Config();
332
+		$this->registration = apply_filters('FHEE__EE_Config___initialize_config__registration',
333
+			$this->registration);
334
+		$this->admin = $this->admin instanceof EE_Admin_Config
335
+			? $this->admin
336
+			: new EE_Admin_Config();
337
+		$this->admin = apply_filters('FHEE__EE_Config___initialize_config__admin', $this->admin);
338
+		$this->template_settings = $this->template_settings instanceof EE_Template_Config
339
+			? $this->template_settings
340
+			: new EE_Template_Config();
341
+		$this->template_settings = apply_filters(
342
+			'FHEE__EE_Config___initialize_config__template_settings',
343
+			$this->template_settings
344
+		);
345
+		$this->map_settings = $this->map_settings instanceof EE_Map_Config
346
+			? $this->map_settings
347
+			: new EE_Map_Config();
348
+		$this->map_settings = apply_filters('FHEE__EE_Config___initialize_config__map_settings',
349
+			$this->map_settings);
350
+		$this->environment = $this->environment instanceof EE_Environment_Config
351
+			? $this->environment
352
+			: new EE_Environment_Config();
353
+		$this->environment = apply_filters('FHEE__EE_Config___initialize_config__environment',
354
+			$this->environment);
355
+		$this->tax_settings = $this->tax_settings instanceof EE_Tax_Config
356
+			? $this->tax_settings
357
+			: new EE_Tax_Config();
358
+		$this->tax_settings = apply_filters('FHEE__EE_Config___initialize_config__tax_settings',
359
+			$this->tax_settings);
360
+		$this->messages = apply_filters('FHEE__EE_Config__initialize_config__messages', $this->messages);
361
+		$this->messages = $this->messages instanceof EE_Messages_Config
362
+			? $this->messages
363
+			: new EE_Messages_Config();
364
+		$this->gateway = $this->gateway instanceof EE_Gateway_Config
365
+			? $this->gateway
366
+			: new EE_Gateway_Config();
367
+		$this->gateway = apply_filters('FHEE__EE_Config___initialize_config__gateway', $this->gateway);
368
+	}
369
+
370
+
371
+	/**
372
+	 *    get_espresso_config
373
+	 *
374
+	 * @access    public
375
+	 * @return    array of espresso config stuff
376
+	 */
377
+	public function get_espresso_config()
378
+	{
379
+		// grab espresso configuration
380
+		return apply_filters(
381
+			'FHEE__EE_Config__get_espresso_config__CFG',
382
+			get_option(EE_Config::OPTION_NAME, array())
383
+		);
384
+	}
385
+
386
+
387
+
388
+	/**
389
+	 *    double_check_config_comparison
390
+	 *
391
+	 * @access    public
392
+	 * @param string $option
393
+	 * @param        $old_value
394
+	 * @param        $value
395
+	 */
396
+	public function double_check_config_comparison($option = '', $old_value, $value)
397
+	{
398
+		// make sure we're checking the ee config
399
+		if ($option === EE_Config::OPTION_NAME) {
400
+			// run a loose comparison of the old value against the new value for type and properties,
401
+			// but NOT exact instance like WP update_option does (ie: NOT type safe comparison)
402
+			if ($value != $old_value) {
403
+				// if they are NOT the same, then remove the hook,
404
+				// which means the subsequent update results will be based solely on the update query results
405
+				// the reason we do this is because, as stated above,
406
+				// WP update_option performs an exact instance comparison (===) on any update values passed to it
407
+				// this happens PRIOR to serialization and any subsequent update.
408
+				// If values are found to match their previous old value,
409
+				// then WP bails before performing any update.
410
+				// Since we are passing the EE_Config object, it is comparing the EXACT instance of the saved version
411
+				// it just pulled from the db, with the one being passed to it (which will not match).
412
+				// HOWEVER, once the object is serialized and passed off to MySQL to update,
413
+				// MySQL MAY ALSO NOT perform the update because
414
+				// the string it sees in the db looks the same as the new one it has been passed!!!
415
+				// This results in the query returning an "affected rows" value of ZERO,
416
+				// which gets returned immediately by WP update_option and looks like an error.
417
+				remove_action('update_option', array($this, 'check_config_updated'));
418
+			}
419
+		}
420
+	}
421
+
422
+
423
+
424
+	/**
425
+	 *    update_espresso_config
426
+	 *
427
+	 * @access   public
428
+	 */
429
+	protected function _reset_espresso_addon_config()
430
+	{
431
+		$this->_addon_option_names = array();
432
+		foreach ($this->addons as $addon_name => $addon_config_obj) {
433
+			$addon_config_obj = maybe_unserialize($addon_config_obj);
434
+			$config_class = get_class($addon_config_obj);
435
+			if ($addon_config_obj instanceof $config_class && ! $addon_config_obj instanceof __PHP_Incomplete_Class) {
436
+				$this->update_config('addons', $addon_name, $addon_config_obj, false);
437
+			}
438
+			$this->addons->{$addon_name} = null;
439
+		}
440
+	}
441
+
442
+
443
+
444
+	/**
445
+	 *    update_espresso_config
446
+	 *
447
+	 * @access   public
448
+	 * @param   bool $add_success
449
+	 * @param   bool $add_error
450
+	 * @return   bool
451
+	 */
452
+	public function update_espresso_config($add_success = false, $add_error = true)
453
+	{
454
+		// don't allow config updates during WP heartbeats
455
+		if (\EE_Registry::instance()->REQ->get('action', '') === 'heartbeat') {
456
+			return false;
457
+		}
458
+		// commented out the following re: https://events.codebasehq.com/projects/event-espresso/tickets/8197
459
+		//$clone = clone( self::$_instance );
460
+		//self::$_instance = NULL;
461
+		do_action('AHEE__EE_Config__update_espresso_config__begin', $this);
462
+		$this->_reset_espresso_addon_config();
463
+		// hook into update_option because that happens AFTER the ( $value === $old_value ) conditional
464
+		// but BEFORE the actual update occurs
465
+		add_action('update_option', array($this, 'double_check_config_comparison'), 1, 3);
466
+		// now update "ee_config"
467
+		$saved = update_option(EE_Config::OPTION_NAME, $this);
468
+		EE_Config::log(EE_Config::OPTION_NAME);
469
+		// if not saved... check if the hook we just added still exists;
470
+		// if it does, it means one of two things:
471
+		// 		that update_option bailed at the ( $value === $old_value ) conditional,
472
+		//		 or...
473
+		// 		the db update query returned 0 rows affected
474
+		// 		(probably because the data  value was the same from it's perspective)
475
+		// so the existence of the hook means that a negative result from update_option is NOT an error,
476
+		// but just means no update occurred, so don't display an error to the user.
477
+		// BUT... if update_option returns FALSE, AND the hook is missing,
478
+		// then it means that something truly went wrong
479
+		$saved = ! $saved ? has_action('update_option', array($this, 'double_check_config_comparison')) : $saved;
480
+		// remove our action since we don't want it in the system anymore
481
+		remove_action('update_option', array($this, 'double_check_config_comparison'), 1);
482
+		do_action('AHEE__EE_Config__update_espresso_config__end', $this, $saved);
483
+		//self::$_instance = $clone;
484
+		//unset( $clone );
485
+		// if config remains the same or was updated successfully
486
+		if ($saved) {
487
+			if ($add_success) {
488
+				EE_Error::add_success(
489
+					__('The Event Espresso Configuration Settings have been successfully updated.', 'event_espresso'),
490
+					__FILE__,
491
+					__FUNCTION__,
492
+					__LINE__
493
+				);
494
+			}
495
+			return true;
496
+		} else {
497
+			if ($add_error) {
498
+				EE_Error::add_error(
499
+					__('The Event Espresso Configuration Settings were not updated.', 'event_espresso'),
500
+					__FILE__,
501
+					__FUNCTION__,
502
+					__LINE__
503
+				);
504
+			}
505
+			return false;
506
+		}
507
+	}
508
+
509
+
510
+
511
+	/**
512
+	 *    _verify_config_params
513
+	 *
514
+	 * @access    private
515
+	 * @param    string         $section
516
+	 * @param    string         $name
517
+	 * @param    string         $config_class
518
+	 * @param    EE_Config_Base $config_obj
519
+	 * @param    array          $tests_to_run
520
+	 * @param    bool           $display_errors
521
+	 * @return    bool    TRUE on success, FALSE on fail
522
+	 */
523
+	private function _verify_config_params(
524
+		$section = '',
525
+		$name = '',
526
+		$config_class = '',
527
+		$config_obj = null,
528
+		$tests_to_run = array(1, 2, 3, 4, 5, 6, 7, 8),
529
+		$display_errors = true
530
+	) {
531
+		try {
532
+			foreach ($tests_to_run as $test) {
533
+				switch ($test) {
534
+					// TEST #1 : check that section was set
535
+					case 1 :
536
+						if (empty($section)) {
537
+							if ($display_errors) {
538
+								throw new EE_Error(
539
+									sprintf(
540
+										__(
541
+											'No configuration section has been provided while attempting to save "%s".',
542
+											'event_espresso'
543
+										),
544
+										$config_class
545
+									)
546
+								);
547
+							}
548
+							return false;
549
+						}
550
+						break;
551
+					// TEST #2 : check that settings section exists
552
+					case 2 :
553
+						if (! isset($this->{$section})) {
554
+							if ($display_errors) {
555
+								throw new EE_Error(
556
+									sprintf(
557
+										__('The "%s" configuration section does not exist.', 'event_espresso'),
558
+										$section
559
+									)
560
+								);
561
+							}
562
+							return false;
563
+						}
564
+						break;
565
+					// TEST #3 : check that section is the proper format
566
+					case 3 :
567
+						if (
568
+						! ($this->{$section} instanceof EE_Config_Base || $this->{$section} instanceof stdClass)
569
+						) {
570
+							if ($display_errors) {
571
+								throw new EE_Error(
572
+									sprintf(
573
+										__(
574
+											'The "%s" configuration settings have not been formatted correctly.',
575
+											'event_espresso'
576
+										),
577
+										$section
578
+									)
579
+								);
580
+							}
581
+							return false;
582
+						}
583
+						break;
584
+					// TEST #4 : check that config section name has been set
585
+					case 4 :
586
+						if (empty($name)) {
587
+							if ($display_errors) {
588
+								throw new EE_Error(
589
+									__(
590
+										'No name has been provided for the specific configuration section.',
591
+										'event_espresso'
592
+									)
593
+								);
594
+							}
595
+							return false;
596
+						}
597
+						break;
598
+					// TEST #5 : check that a config class name has been set
599
+					case 5 :
600
+						if (empty($config_class)) {
601
+							if ($display_errors) {
602
+								throw new EE_Error(
603
+									__(
604
+										'No class name has been provided for the specific configuration section.',
605
+										'event_espresso'
606
+									)
607
+								);
608
+							}
609
+							return false;
610
+						}
611
+						break;
612
+					// TEST #6 : verify config class is accessible
613
+					case 6 :
614
+						if (! class_exists($config_class)) {
615
+							if ($display_errors) {
616
+								throw new EE_Error(
617
+									sprintf(
618
+										__(
619
+											'The "%s" class does not exist. Please ensure that an autoloader has been set for it.',
620
+											'event_espresso'
621
+										),
622
+										$config_class
623
+									)
624
+								);
625
+							}
626
+							return false;
627
+						}
628
+						break;
629
+					// TEST #7 : check that config has even been set
630
+					case 7 :
631
+						if (! isset($this->{$section}->{$name})) {
632
+							if ($display_errors) {
633
+								throw new EE_Error(
634
+									sprintf(
635
+										__('No configuration has been set for "%1$s->%2$s".', 'event_espresso'),
636
+										$section,
637
+										$name
638
+									)
639
+								);
640
+							}
641
+							return false;
642
+						} else {
643
+							// and make sure it's not serialized
644
+							$this->{$section}->{$name} = maybe_unserialize($this->{$section}->{$name});
645
+						}
646
+						break;
647
+					// TEST #8 : check that config is the requested type
648
+					case 8 :
649
+						if (! $this->{$section}->{$name} instanceof $config_class) {
650
+							if ($display_errors) {
651
+								throw new EE_Error(
652
+									sprintf(
653
+										__(
654
+											'The configuration for "%1$s->%2$s" is not of the "%3$s" class.',
655
+											'event_espresso'
656
+										),
657
+										$section,
658
+										$name,
659
+										$config_class
660
+									)
661
+								);
662
+							}
663
+							return false;
664
+						}
665
+						break;
666
+					// TEST #9 : verify config object
667
+					case 9 :
668
+						if (! $config_obj instanceof EE_Config_Base) {
669
+							if ($display_errors) {
670
+								throw new EE_Error(
671
+									sprintf(
672
+										__('The "%s" class is not an instance of EE_Config_Base.', 'event_espresso'),
673
+										print_r($config_obj, true)
674
+									)
675
+								);
676
+							}
677
+							return false;
678
+						}
679
+						break;
680
+				}
681
+			}
682
+		} catch (EE_Error $e) {
683
+			$e->get_error();
684
+		}
685
+		// you have successfully run the gauntlet
686
+		return true;
687
+	}
688
+
689
+
690
+
691
+	/**
692
+	 *    _generate_config_option_name
693
+	 *
694
+	 * @access        protected
695
+	 * @param        string $section
696
+	 * @param        string $name
697
+	 * @return        string
698
+	 */
699
+	private function _generate_config_option_name($section = '', $name = '')
700
+	{
701
+		return 'ee_config-' . strtolower($section . '-' . str_replace(array('EE_', 'EED_'), '', $name));
702
+	}
703
+
704
+
705
+
706
+	/**
707
+	 *    _set_config_class
708
+	 * ensures that a config class is set, either from a passed config class or one generated from the config name
709
+	 *
710
+	 * @access    private
711
+	 * @param    string $config_class
712
+	 * @param    string $name
713
+	 * @return    string
714
+	 */
715
+	private function _set_config_class($config_class = '', $name = '')
716
+	{
717
+		return ! empty($config_class)
718
+			? $config_class
719
+			: str_replace(' ', '_', ucwords(str_replace('_', ' ', $name))) . '_Config';
720
+	}
721
+
722
+
723
+
724
+	/**
725
+	 *    set_config
726
+	 *
727
+	 * @access    protected
728
+	 * @param    string         $section
729
+	 * @param    string         $name
730
+	 * @param    string         $config_class
731
+	 * @param    EE_Config_Base $config_obj
732
+	 * @return    EE_Config_Base
733
+	 */
734
+	public function set_config($section = '', $name = '', $config_class = '', EE_Config_Base $config_obj = null)
735
+	{
736
+		// ensure config class is set to something
737
+		$config_class = $this->_set_config_class($config_class, $name);
738
+		// run tests 1-4, 6, and 7 to verify all config params are set and valid
739
+		if (! $this->_verify_config_params($section, $name, $config_class, null, array(1, 2, 3, 4, 5, 6))) {
740
+			return null;
741
+		}
742
+		$config_option_name = $this->_generate_config_option_name($section, $name);
743
+		// if the config option name hasn't been added yet to the list of option names we're tracking, then do so now
744
+		if (! isset($this->_addon_option_names[$config_option_name])) {
745
+			$this->_addon_option_names[$config_option_name] = $config_class;
746
+			$this->update_addon_option_names();
747
+		}
748
+		// verify the incoming config object but suppress errors
749
+		if (! $this->_verify_config_params($section, $name, $config_class, $config_obj, array(9), false)) {
750
+			$config_obj = new $config_class();
751
+		}
752
+		if (get_option($config_option_name)) {
753
+			EE_Config::log($config_option_name);
754
+			update_option($config_option_name, $config_obj);
755
+			$this->{$section}->{$name} = $config_obj;
756
+			return $this->{$section}->{$name};
757
+		} else {
758
+			// create a wp-option for this config
759
+			if (add_option($config_option_name, $config_obj, '', 'no')) {
760
+				$this->{$section}->{$name} = maybe_unserialize($config_obj);
761
+				return $this->{$section}->{$name};
762
+			} else {
763
+				EE_Error::add_error(
764
+					sprintf(__('The "%s" could not be saved to the database.', 'event_espresso'), $config_class),
765
+					__FILE__,
766
+					__FUNCTION__,
767
+					__LINE__
768
+				);
769
+				return null;
770
+			}
771
+		}
772
+	}
773
+
774
+
775
+
776
+	/**
777
+	 *    update_config
778
+	 * Important: the config object must ALREADY be set, otherwise this will produce an error.
779
+	 *
780
+	 * @access    public
781
+	 * @param    string                $section
782
+	 * @param    string                $name
783
+	 * @param    EE_Config_Base|string $config_obj
784
+	 * @param    bool                  $throw_errors
785
+	 * @return    bool
786
+	 */
787
+	public function update_config($section = '', $name = '', $config_obj = '', $throw_errors = true)
788
+	{
789
+		// don't allow config updates during WP heartbeats
790
+		if (\EE_Registry::instance()->REQ->get('action', '') === 'heartbeat') {
791
+			return false;
792
+		}
793
+		$config_obj = maybe_unserialize($config_obj);
794
+		// get class name of the incoming object
795
+		$config_class = get_class($config_obj);
796
+		// run tests 1-5 and 9 to verify config
797
+		if (! $this->_verify_config_params(
798
+			$section,
799
+			$name,
800
+			$config_class,
801
+			$config_obj,
802
+			array(1, 2, 3, 4, 7, 9)
803
+		)
804
+		) {
805
+			return false;
806
+		}
807
+		$config_option_name = $this->_generate_config_option_name($section, $name);
808
+		// check if config object has been added to db by seeing if config option name is in $this->_addon_option_names array
809
+		if (! isset($this->_addon_option_names[$config_option_name])) {
810
+			// save new config to db
811
+			if ($this->set_config($section, $name, $config_class, $config_obj)) {
812
+				return true;
813
+			}
814
+		} else {
815
+			// first check if the record already exists
816
+			$existing_config = get_option($config_option_name);
817
+			$config_obj = serialize($config_obj);
818
+			// just return if db record is already up to date (NOT type safe comparison)
819
+			if ($existing_config == $config_obj) {
820
+				$this->{$section}->{$name} = $config_obj;
821
+				return true;
822
+			} else if (update_option($config_option_name, $config_obj)) {
823
+				EE_Config::log($config_option_name);
824
+				// update wp-option for this config class
825
+				$this->{$section}->{$name} = $config_obj;
826
+				return true;
827
+			} elseif ($throw_errors) {
828
+				EE_Error::add_error(
829
+					sprintf(
830
+						__(
831
+							'The "%1$s" object stored at"%2$s" was not successfully updated in the database.',
832
+							'event_espresso'
833
+						),
834
+						$config_class,
835
+						'EE_Config->' . $section . '->' . $name
836
+					),
837
+					__FILE__,
838
+					__FUNCTION__,
839
+					__LINE__
840
+				);
841
+			}
842
+		}
843
+		return false;
844
+	}
845
+
846
+
847
+
848
+	/**
849
+	 *    get_config
850
+	 *
851
+	 * @access    public
852
+	 * @param    string $section
853
+	 * @param    string $name
854
+	 * @param    string $config_class
855
+	 * @return    mixed EE_Config_Base | NULL
856
+	 */
857
+	public function get_config($section = '', $name = '', $config_class = '')
858
+	{
859
+		// ensure config class is set to something
860
+		$config_class = $this->_set_config_class($config_class, $name);
861
+		// run tests 1-4, 6 and 7 to verify that all params have been set
862
+		if (! $this->_verify_config_params($section, $name, $config_class, null, array(1, 2, 3, 4, 5, 6))) {
863
+			return null;
864
+		}
865
+		// now test if the requested config object exists, but suppress errors
866
+		if ($this->_verify_config_params($section, $name, $config_class, null, array(7, 8), false)) {
867
+			// config already exists, so pass it back
868
+			return $this->{$section}->{$name};
869
+		}
870
+		// load config option from db if it exists
871
+		$config_obj = $this->get_config_option($this->_generate_config_option_name($section, $name));
872
+		// verify the newly retrieved config object, but suppress errors
873
+		if ($this->_verify_config_params($section, $name, $config_class, $config_obj, array(9), false)) {
874
+			// config is good, so set it and pass it back
875
+			$this->{$section}->{$name} = $config_obj;
876
+			return $this->{$section}->{$name};
877
+		}
878
+		// oops! $config_obj is not already set and does not exist in the db, so create a new one
879
+		$config_obj = $this->set_config($section, $name, $config_class);
880
+		// verify the newly created config object
881
+		if ($this->_verify_config_params($section, $name, $config_class, $config_obj, array(9))) {
882
+			return $this->{$section}->{$name};
883
+		} else {
884
+			EE_Error::add_error(
885
+				sprintf(__('The "%s" could not be retrieved from the database.', 'event_espresso'), $config_class),
886
+				__FILE__,
887
+				__FUNCTION__,
888
+				__LINE__
889
+			);
890
+		}
891
+		return null;
892
+	}
893
+
894
+
895
+
896
+	/**
897
+	 *    get_config_option
898
+	 *
899
+	 * @access    public
900
+	 * @param    string $config_option_name
901
+	 * @return    mixed EE_Config_Base | FALSE
902
+	 */
903
+	public function get_config_option($config_option_name = '')
904
+	{
905
+		// retrieve the wp-option for this config class.
906
+		$config_option = maybe_unserialize(get_option($config_option_name, array()));
907
+		if (empty($config_option)) {
908
+			EE_Config::log($config_option_name . '-NOT-FOUND');
909
+		}
910
+		return $config_option;
911
+	}
912
+
913
+
914
+
915
+	/**
916
+	 * log
917
+	 *
918
+	 * @param string $config_option_name
919
+	 */
920
+	public static function log($config_option_name = '')
921
+	{
922
+		if (EE_Config::logging_enabled() && ! empty($config_option_name)) {
923
+			$config_log = get_option(EE_Config::LOG_NAME, array());
924
+			//copy incoming $_REQUEST and sanitize it so we can save it
925
+			$_request = $_REQUEST;
926
+			array_walk_recursive($_request, 'sanitize_text_field');
927
+			$config_log[(string)microtime(true)] = array(
928
+				'config_name' => $config_option_name,
929
+				'request'     => $_request,
930
+			);
931
+			update_option(EE_Config::LOG_NAME, $config_log);
932
+		}
933
+	}
934
+
935
+
936
+
937
+	/**
938
+	 * trim_log
939
+	 * reduces the size of the config log to the length specified by EE_Config::LOG_LENGTH
940
+	 */
941
+	public static function trim_log()
942
+	{
943
+		if (! EE_Config::logging_enabled()) {
944
+			return;
945
+		}
946
+		$config_log = maybe_unserialize(get_option(EE_Config::LOG_NAME, array()));
947
+		$log_length = count($config_log);
948
+		if ($log_length > EE_Config::LOG_LENGTH) {
949
+			ksort($config_log);
950
+			$config_log = array_slice($config_log, $log_length - EE_Config::LOG_LENGTH, null, true);
951
+			update_option(EE_Config::LOG_NAME, $config_log);
952
+		}
953
+	}
954
+
955
+
956
+
957
+	/**
958
+	 *    get_page_for_posts
959
+	 *    if the wp-option "show_on_front" is set to "page", then this is the post_name for the post set in the
960
+	 *    wp-option "page_for_posts", or "posts" if no page is selected
961
+	 *
962
+	 * @access    public
963
+	 * @return    string
964
+	 */
965
+	public static function get_page_for_posts()
966
+	{
967
+		$page_for_posts = get_option('page_for_posts');
968
+		if (! $page_for_posts) {
969
+			return 'posts';
970
+		}
971
+		/** @type WPDB $wpdb */
972
+		global $wpdb;
973
+		$SQL = "SELECT post_name from $wpdb->posts WHERE post_type='posts' OR post_type='page' AND post_status='publish' AND ID=%d";
974
+		return $wpdb->get_var($wpdb->prepare($SQL, $page_for_posts));
975
+	}
976
+
977
+
978
+
979
+	/**
980
+	 *    register_shortcodes_and_modules.
981
+	 *    At this point, it's too early to tell if we're maintenance mode or not.
982
+	 *    In fact, this is where we give modules a chance to let core know they exist
983
+	 *    so they can help trigger maintenance mode if it's needed
984
+	 *
985
+	 * @access    public
986
+	 * @return    void
987
+	 */
988
+	public function register_shortcodes_and_modules()
989
+	{
990
+		// allow shortcodes to register with WP and to set hooks for the rest of the system
991
+		EE_Registry::instance()->shortcodes = $this->_register_shortcodes();
992
+		// allow modules to set hooks for the rest of the system
993
+		EE_Registry::instance()->modules = $this->_register_modules();
994
+	}
995
+
996
+
997
+
998
+	/**
999
+	 *    initialize_shortcodes_and_modules
1000
+	 *    meaning they can start adding their hooks to get stuff done
1001
+	 *
1002
+	 * @access    public
1003
+	 * @return    void
1004
+	 */
1005
+	public function initialize_shortcodes_and_modules()
1006
+	{
1007
+		// allow shortcodes to set hooks for the rest of the system
1008
+		$this->_initialize_shortcodes();
1009
+		// allow modules to set hooks for the rest of the system
1010
+		$this->_initialize_modules();
1011
+	}
1012
+
1013
+
1014
+
1015
+	/**
1016
+	 *    widgets_init
1017
+	 *
1018
+	 * @access private
1019
+	 * @return void
1020
+	 */
1021
+	public function widgets_init()
1022
+	{
1023
+		//only init widgets on admin pages when not in complete maintenance, and
1024
+		//on frontend when not in any maintenance mode
1025
+		if (
1026
+			! EE_Maintenance_Mode::instance()->level()
1027
+			|| (
1028
+				is_admin()
1029
+				&& EE_Maintenance_Mode::instance()->level() !== EE_Maintenance_Mode::level_2_complete_maintenance
1030
+			)
1031
+		) {
1032
+			// grab list of installed widgets
1033
+			$widgets_to_register = glob(EE_WIDGETS . '*', GLOB_ONLYDIR);
1034
+			// filter list of modules to register
1035
+			$widgets_to_register = apply_filters(
1036
+				'FHEE__EE_Config__register_widgets__widgets_to_register',
1037
+				$widgets_to_register
1038
+			);
1039
+			if (! empty($widgets_to_register)) {
1040
+				// cycle thru widget folders
1041
+				foreach ($widgets_to_register as $widget_path) {
1042
+					// add to list of installed widget modules
1043
+					EE_Config::register_ee_widget($widget_path);
1044
+				}
1045
+			}
1046
+			// filter list of installed modules
1047
+			EE_Registry::instance()->widgets = apply_filters(
1048
+				'FHEE__EE_Config__register_widgets__installed_widgets',
1049
+				EE_Registry::instance()->widgets
1050
+			);
1051
+		}
1052
+	}
1053
+
1054
+
1055
+
1056
+	/**
1057
+	 *    register_ee_widget - makes core aware of this widget
1058
+	 *
1059
+	 * @access    public
1060
+	 * @param    string $widget_path - full path up to and including widget folder
1061
+	 * @return    void
1062
+	 */
1063
+	public static function register_ee_widget($widget_path = null)
1064
+	{
1065
+		do_action('AHEE__EE_Config__register_widget__begin', $widget_path);
1066
+		$widget_ext = '.widget.php';
1067
+		// make all separators match
1068
+		$widget_path = rtrim(str_replace('/\\', DS, $widget_path), DS);
1069
+		// does the file path INCLUDE the actual file name as part of the path ?
1070
+		if (strpos($widget_path, $widget_ext) !== false) {
1071
+			// grab and shortcode file name from directory name and break apart at dots
1072
+			$file_name = explode('.', basename($widget_path));
1073
+			// take first segment from file name pieces and remove class prefix if it exists
1074
+			$widget = strpos($file_name[0], 'EEW_') === 0 ? substr($file_name[0], 4) : $file_name[0];
1075
+			// sanitize shortcode directory name
1076
+			$widget = sanitize_key($widget);
1077
+			// now we need to rebuild the shortcode path
1078
+			$widget_path = explode(DS, $widget_path);
1079
+			// remove last segment
1080
+			array_pop($widget_path);
1081
+			// glue it back together
1082
+			$widget_path = implode(DS, $widget_path);
1083
+		} else {
1084
+			// grab and sanitize widget directory name
1085
+			$widget = sanitize_key(basename($widget_path));
1086
+		}
1087
+		// create classname from widget directory name
1088
+		$widget = str_replace(' ', '_', ucwords(str_replace('_', ' ', $widget)));
1089
+		// add class prefix
1090
+		$widget_class = 'EEW_' . $widget;
1091
+		// does the widget exist ?
1092
+		if (! is_readable($widget_path . DS . $widget_class . $widget_ext)) {
1093
+			$msg = sprintf(
1094
+				__(
1095
+					'The requested %s widget file could not be found or is not readable due to file permissions. Please ensure the following path is correct: %s',
1096
+					'event_espresso'
1097
+				),
1098
+				$widget_class,
1099
+				$widget_path . DS . $widget_class . $widget_ext
1100
+			);
1101
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1102
+			return;
1103
+		}
1104
+		// load the widget class file
1105
+		require_once($widget_path . DS . $widget_class . $widget_ext);
1106
+		// verify that class exists
1107
+		if (! class_exists($widget_class)) {
1108
+			$msg = sprintf(__('The requested %s widget class does not exist.', 'event_espresso'), $widget_class);
1109
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1110
+			return;
1111
+		}
1112
+		register_widget($widget_class);
1113
+		// add to array of registered widgets
1114
+		EE_Registry::instance()->widgets->{$widget_class} = $widget_path . DS . $widget_class . $widget_ext;
1115
+	}
1116
+
1117
+
1118
+
1119
+	/**
1120
+	 *        _register_shortcodes
1121
+	 *
1122
+	 * @access private
1123
+	 * @return array
1124
+	 */
1125
+	private function _register_shortcodes()
1126
+	{
1127
+		// grab list of installed shortcodes
1128
+		$shortcodes_to_register = glob(EE_SHORTCODES . '*', GLOB_ONLYDIR);
1129
+		// filter list of modules to register
1130
+		$shortcodes_to_register = apply_filters(
1131
+			'FHEE__EE_Config__register_shortcodes__shortcodes_to_register',
1132
+			$shortcodes_to_register
1133
+		);
1134
+		if (! empty($shortcodes_to_register)) {
1135
+			// cycle thru shortcode folders
1136
+			foreach ($shortcodes_to_register as $shortcode_path) {
1137
+				// add to list of installed shortcode modules
1138
+				EE_Config::register_shortcode($shortcode_path);
1139
+			}
1140
+		}
1141
+		// filter list of installed modules
1142
+		return apply_filters(
1143
+			'FHEE__EE_Config___register_shortcodes__installed_shortcodes',
1144
+			EE_Registry::instance()->shortcodes
1145
+		);
1146
+	}
1147
+
1148
+
1149
+
1150
+	/**
1151
+	 *    register_shortcode - makes core aware of this shortcode
1152
+	 *
1153
+	 * @access    public
1154
+	 * @param    string $shortcode_path - full path up to and including shortcode folder
1155
+	 * @return    bool
1156
+	 */
1157
+	public static function register_shortcode($shortcode_path = null)
1158
+	{
1159
+		do_action('AHEE__EE_Config__register_shortcode__begin', $shortcode_path);
1160
+		$shortcode_ext = '.shortcode.php';
1161
+		// make all separators match
1162
+		$shortcode_path = str_replace(array('\\', '/'), DS, $shortcode_path);
1163
+		// does the file path INCLUDE the actual file name as part of the path ?
1164
+		if (strpos($shortcode_path, $shortcode_ext) !== false) {
1165
+			// grab shortcode file name from directory name and break apart at dots
1166
+			$shortcode_file = explode('.', basename($shortcode_path));
1167
+			// take first segment from file name pieces and remove class prefix if it exists
1168
+			$shortcode = strpos($shortcode_file[0], 'EES_') === 0
1169
+				? substr($shortcode_file[0], 4)
1170
+				: $shortcode_file[0];
1171
+			// sanitize shortcode directory name
1172
+			$shortcode = sanitize_key($shortcode);
1173
+			// now we need to rebuild the shortcode path
1174
+			$shortcode_path = explode(DS, $shortcode_path);
1175
+			// remove last segment
1176
+			array_pop($shortcode_path);
1177
+			// glue it back together
1178
+			$shortcode_path = implode(DS, $shortcode_path) . DS;
1179
+		} else {
1180
+			// we need to generate the filename based off of the folder name
1181
+			// grab and sanitize shortcode directory name
1182
+			$shortcode = sanitize_key(basename($shortcode_path));
1183
+			$shortcode_path = rtrim($shortcode_path, DS) . DS;
1184
+		}
1185
+		// create classname from shortcode directory or file name
1186
+		$shortcode = str_replace(' ', '_', ucwords(str_replace('_', ' ', $shortcode)));
1187
+		// add class prefix
1188
+		$shortcode_class = 'EES_' . $shortcode;
1189
+		// does the shortcode exist ?
1190
+		if (! is_readable($shortcode_path . DS . $shortcode_class . $shortcode_ext)) {
1191
+			$msg = sprintf(
1192
+				__(
1193
+					'The requested %s shortcode file could not be found or is not readable due to file permissions. It should be in %s',
1194
+					'event_espresso'
1195
+				),
1196
+				$shortcode_class,
1197
+				$shortcode_path . DS . $shortcode_class . $shortcode_ext
1198
+			);
1199
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1200
+			return false;
1201
+		}
1202
+		// load the shortcode class file
1203
+		require_once($shortcode_path . $shortcode_class . $shortcode_ext);
1204
+		// verify that class exists
1205
+		if (! class_exists($shortcode_class)) {
1206
+			$msg = sprintf(
1207
+				__('The requested %s shortcode class does not exist.', 'event_espresso'),
1208
+				$shortcode_class
1209
+			);
1210
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1211
+			return false;
1212
+		}
1213
+		$shortcode = strtoupper($shortcode);
1214
+		// add to array of registered shortcodes
1215
+		EE_Registry::instance()->shortcodes->{$shortcode} = $shortcode_path . $shortcode_class . $shortcode_ext;
1216
+		return true;
1217
+	}
1218
+
1219
+
1220
+
1221
+	/**
1222
+	 *        _register_modules
1223
+	 *
1224
+	 * @access private
1225
+	 * @return array
1226
+	 */
1227
+	private function _register_modules()
1228
+	{
1229
+		// grab list of installed modules
1230
+		$modules_to_register = glob(EE_MODULES . '*', GLOB_ONLYDIR);
1231
+		// filter list of modules to register
1232
+		$modules_to_register = apply_filters(
1233
+			'FHEE__EE_Config__register_modules__modules_to_register',
1234
+			$modules_to_register
1235
+		);
1236
+		if (! empty($modules_to_register)) {
1237
+			// loop through folders
1238
+			foreach ($modules_to_register as $module_path) {
1239
+				/**TEMPORARILY EXCLUDE gateways from modules for time being**/
1240
+				if (
1241
+					$module_path !== EE_MODULES . 'zzz-copy-this-module-template'
1242
+					&& $module_path !== EE_MODULES . 'gateways'
1243
+				) {
1244
+					// add to list of installed modules
1245
+					EE_Config::register_module($module_path);
1246
+				}
1247
+			}
1248
+		}
1249
+		// filter list of installed modules
1250
+		return apply_filters(
1251
+			'FHEE__EE_Config___register_modules__installed_modules',
1252
+			EE_Registry::instance()->modules
1253
+		);
1254
+	}
1255
+
1256
+
1257
+
1258
+	/**
1259
+	 *    register_module - makes core aware of this module
1260
+	 *
1261
+	 * @access    public
1262
+	 * @param    string $module_path - full path up to and including module folder
1263
+	 * @return    bool
1264
+	 */
1265
+	public static function register_module($module_path = null)
1266
+	{
1267
+		do_action('AHEE__EE_Config__register_module__begin', $module_path);
1268
+		$module_ext = '.module.php';
1269
+		// make all separators match
1270
+		$module_path = str_replace(array('\\', '/'), DS, $module_path);
1271
+		// does the file path INCLUDE the actual file name as part of the path ?
1272
+		if (strpos($module_path, $module_ext) !== false) {
1273
+			// grab and shortcode file name from directory name and break apart at dots
1274
+			$module_file = explode('.', basename($module_path));
1275
+			// now we need to rebuild the shortcode path
1276
+			$module_path = explode(DS, $module_path);
1277
+			// remove last segment
1278
+			array_pop($module_path);
1279
+			// glue it back together
1280
+			$module_path = implode(DS, $module_path) . DS;
1281
+			// take first segment from file name pieces and sanitize it
1282
+			$module = preg_replace('/[^a-zA-Z0-9_\-]/', '', $module_file[0]);
1283
+			// ensure class prefix is added
1284
+			$module_class = strpos($module, 'EED_') !== 0 ? 'EED_' . $module : $module;
1285
+		} else {
1286
+			// we need to generate the filename based off of the folder name
1287
+			// grab and sanitize module name
1288
+			$module = strtolower(basename($module_path));
1289
+			$module = preg_replace('/[^a-z0-9_\-]/', '', $module);
1290
+			// like trailingslashit()
1291
+			$module_path = rtrim($module_path, DS) . DS;
1292
+			// create classname from module directory name
1293
+			$module = str_replace(' ', '_', ucwords(str_replace('_', ' ', $module)));
1294
+			// add class prefix
1295
+			$module_class = 'EED_' . $module;
1296
+		}
1297
+		// does the module exist ?
1298
+		if (! is_readable($module_path . DS . $module_class . $module_ext)) {
1299
+			$msg = sprintf(
1300
+				__(
1301
+					'The requested %s module file could not be found or is not readable due to file permissions.',
1302
+					'event_espresso'
1303
+				),
1304
+				$module
1305
+			);
1306
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1307
+			return false;
1308
+		}
1309
+		// load the module class file
1310
+		require_once($module_path . $module_class . $module_ext);
1311
+		// verify that class exists
1312
+		if (! class_exists($module_class)) {
1313
+			$msg = sprintf(__('The requested %s module class does not exist.', 'event_espresso'), $module_class);
1314
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1315
+			return false;
1316
+		}
1317
+		// add to array of registered modules
1318
+		EE_Registry::instance()->modules->{$module_class} = $module_path . $module_class . $module_ext;
1319
+		do_action(
1320
+			'AHEE__EE_Config__register_module__complete',
1321
+			$module_class,
1322
+			EE_Registry::instance()->modules->{$module_class}
1323
+		);
1324
+		return true;
1325
+	}
1326
+
1327
+
1328
+
1329
+	/**
1330
+	 *    _initialize_shortcodes
1331
+	 *    allow shortcodes to set hooks for the rest of the system
1332
+	 *
1333
+	 * @access private
1334
+	 * @return void
1335
+	 */
1336
+	private function _initialize_shortcodes()
1337
+	{
1338
+		// cycle thru shortcode folders
1339
+		foreach (EE_Registry::instance()->shortcodes as $shortcode => $shortcode_path) {
1340
+			// add class prefix
1341
+			$shortcode_class = 'EES_' . $shortcode;
1342
+			// fire the shortcode class's set_hooks methods in case it needs to hook into other parts of the system
1343
+			// which set hooks ?
1344
+			if (is_admin()) {
1345
+				// fire immediately
1346
+				call_user_func(array($shortcode_class, 'set_hooks_admin'));
1347
+			} else {
1348
+				// delay until other systems are online
1349
+				add_action(
1350
+					'AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons',
1351
+					array($shortcode_class, 'set_hooks')
1352
+				);
1353
+				// convert classname to UPPERCASE and create WP shortcode.
1354
+				$shortcode_tag = strtoupper($shortcode);
1355
+				// but first check if the shortcode has already been added before assigning 'fallback_shortcode_processor'
1356
+				if (! shortcode_exists($shortcode_tag)) {
1357
+					// NOTE: this shortcode declaration will get overridden if the shortcode is successfully detected in the post content in EE_Front_Controller->_initialize_shortcodes()
1358
+					add_shortcode($shortcode_tag, array($shortcode_class, 'fallback_shortcode_processor'));
1359
+				}
1360
+			}
1361
+		}
1362
+	}
1363
+
1364
+
1365
+
1366
+	/**
1367
+	 *    _initialize_modules
1368
+	 *    allow modules to set hooks for the rest of the system
1369
+	 *
1370
+	 * @access private
1371
+	 * @return void
1372
+	 */
1373
+	private function _initialize_modules()
1374
+	{
1375
+		// cycle thru shortcode folders
1376
+		foreach (EE_Registry::instance()->modules as $module_class => $module_path) {
1377
+			// fire the shortcode class's set_hooks methods in case it needs to hook into other parts of the system
1378
+			// which set hooks ?
1379
+			if (is_admin()) {
1380
+				// fire immediately
1381
+				call_user_func(array($module_class, 'set_hooks_admin'));
1382
+			} else {
1383
+				// delay until other systems are online
1384
+				add_action(
1385
+					'AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons',
1386
+					array($module_class, 'set_hooks')
1387
+				);
1388
+			}
1389
+		}
1390
+	}
1391
+
1392
+
1393
+
1394
+	/**
1395
+	 *    register_route - adds module method routes to route_map
1396
+	 *
1397
+	 * @access    public
1398
+	 * @param    string $route       - "pretty" public alias for module method
1399
+	 * @param    string $module      - module name (classname without EED_ prefix)
1400
+	 * @param    string $method_name - the actual module method to be routed to
1401
+	 * @param    string $key         - url param key indicating a route is being called
1402
+	 * @return    bool
1403
+	 */
1404
+	public static function register_route($route = null, $module = null, $method_name = null, $key = 'ee')
1405
+	{
1406
+		do_action('AHEE__EE_Config__register_route__begin', $route, $module, $method_name);
1407
+		$module = str_replace('EED_', '', $module);
1408
+		$module_class = 'EED_' . $module;
1409
+		if (! isset(EE_Registry::instance()->modules->{$module_class})) {
1410
+			$msg = sprintf(__('The module %s has not been registered.', 'event_espresso'), $module);
1411
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1412
+			return false;
1413
+		}
1414
+		if (empty($route)) {
1415
+			$msg = sprintf(__('No route has been supplied.', 'event_espresso'), $route);
1416
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1417
+			return false;
1418
+		}
1419
+		if (! method_exists('EED_' . $module, $method_name)) {
1420
+			$msg = sprintf(
1421
+				__('A valid class method for the %s route has not been supplied.', 'event_espresso'),
1422
+				$route
1423
+			);
1424
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1425
+			return false;
1426
+		}
1427
+		EE_Config::$_module_route_map[$key][$route] = array('EED_' . $module, $method_name);
1428
+		return true;
1429
+	}
1430
+
1431
+
1432
+
1433
+	/**
1434
+	 *    get_route - get module method route
1435
+	 *
1436
+	 * @access    public
1437
+	 * @param    string $route - "pretty" public alias for module method
1438
+	 * @param    string $key   - url param key indicating a route is being called
1439
+	 * @return    string
1440
+	 */
1441
+	public static function get_route($route = null, $key = 'ee')
1442
+	{
1443
+		do_action('AHEE__EE_Config__get_route__begin', $route);
1444
+		$route = (string)apply_filters('FHEE__EE_Config__get_route', $route);
1445
+		if (isset(EE_Config::$_module_route_map[$key][$route])) {
1446
+			return EE_Config::$_module_route_map[$key][$route];
1447
+		}
1448
+		return null;
1449
+	}
1450
+
1451
+
1452
+
1453
+	/**
1454
+	 *    get_routes - get ALL module method routes
1455
+	 *
1456
+	 * @access    public
1457
+	 * @return    array
1458
+	 */
1459
+	public static function get_routes()
1460
+	{
1461
+		return EE_Config::$_module_route_map;
1462
+	}
1463
+
1464
+
1465
+
1466
+	/**
1467
+	 *    register_forward - allows modules to forward request to another module for further processing
1468
+	 *
1469
+	 * @access    public
1470
+	 * @param    string       $route   - "pretty" public alias for module method
1471
+	 * @param    integer      $status  - integer value corresponding  to status constant strings set in module parent
1472
+	 *                                 class, allows different forwards to be served based on status
1473
+	 * @param    array|string $forward - function name or array( class, method )
1474
+	 * @param    string       $key     - url param key indicating a route is being called
1475
+	 * @return    bool
1476
+	 */
1477
+	public static function register_forward($route = null, $status = 0, $forward = null, $key = 'ee')
1478
+	{
1479
+		do_action('AHEE__EE_Config__register_forward', $route, $status, $forward);
1480
+		if (! isset(EE_Config::$_module_route_map[$key][$route]) || empty($route)) {
1481
+			$msg = sprintf(
1482
+				__('The module route %s for this forward has not been registered.', 'event_espresso'),
1483
+				$route
1484
+			);
1485
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1486
+			return false;
1487
+		}
1488
+		if (empty($forward)) {
1489
+			$msg = sprintf(__('No forwarding route has been supplied.', 'event_espresso'), $route);
1490
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1491
+			return false;
1492
+		}
1493
+		if (is_array($forward)) {
1494
+			if (! isset($forward[1])) {
1495
+				$msg = sprintf(
1496
+					__('A class method for the %s forwarding route has not been supplied.', 'event_espresso'),
1497
+					$route
1498
+				);
1499
+				EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1500
+				return false;
1501
+			}
1502
+			if (! method_exists($forward[0], $forward[1])) {
1503
+				$msg = sprintf(
1504
+					__('The class method %s for the %s forwarding route is in invalid.', 'event_espresso'),
1505
+					$forward[1],
1506
+					$route
1507
+				);
1508
+				EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1509
+				return false;
1510
+			}
1511
+		} else if (! function_exists($forward)) {
1512
+			$msg = sprintf(
1513
+				__('The function %s for the %s forwarding route is in invalid.', 'event_espresso'),
1514
+				$forward,
1515
+				$route
1516
+			);
1517
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1518
+			return false;
1519
+		}
1520
+		EE_Config::$_module_forward_map[$key][$route][absint($status)] = $forward;
1521
+		return true;
1522
+	}
1523
+
1524
+
1525
+
1526
+	/**
1527
+	 *    get_forward - get forwarding route
1528
+	 *
1529
+	 * @access    public
1530
+	 * @param    string  $route  - "pretty" public alias for module method
1531
+	 * @param    integer $status - integer value corresponding  to status constant strings set in module parent class,
1532
+	 *                           allows different forwards to be served based on status
1533
+	 * @param    string  $key    - url param key indicating a route is being called
1534
+	 * @return    string
1535
+	 */
1536
+	public static function get_forward($route = null, $status = 0, $key = 'ee')
1537
+	{
1538
+		do_action('AHEE__EE_Config__get_forward__begin', $route, $status);
1539
+		if (isset(EE_Config::$_module_forward_map[$key][$route][$status])) {
1540
+			return apply_filters(
1541
+				'FHEE__EE_Config__get_forward',
1542
+				EE_Config::$_module_forward_map[$key][$route][$status],
1543
+				$route,
1544
+				$status
1545
+			);
1546
+		}
1547
+		return null;
1548
+	}
1549
+
1550
+
1551
+
1552
+	/**
1553
+	 *    register_forward - allows modules to specify different view templates for different method routes and status
1554
+	 *    results
1555
+	 *
1556
+	 * @access    public
1557
+	 * @param    string  $route  - "pretty" public alias for module method
1558
+	 * @param    integer $status - integer value corresponding  to status constant strings set in module parent class,
1559
+	 *                           allows different views to be served based on status
1560
+	 * @param    string  $view
1561
+	 * @param    string  $key    - url param key indicating a route is being called
1562
+	 * @return    bool
1563
+	 */
1564
+	public static function register_view($route = null, $status = 0, $view = null, $key = 'ee')
1565
+	{
1566
+		do_action('AHEE__EE_Config__register_view__begin', $route, $status, $view);
1567
+		if (! isset(EE_Config::$_module_route_map[$key][$route]) || empty($route)) {
1568
+			$msg = sprintf(
1569
+				__('The module route %s for this view has not been registered.', 'event_espresso'),
1570
+				$route
1571
+			);
1572
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1573
+			return false;
1574
+		}
1575
+		if (! is_readable($view)) {
1576
+			$msg = sprintf(
1577
+				__(
1578
+					'The %s view file could not be found or is not readable due to file permissions.',
1579
+					'event_espresso'
1580
+				),
1581
+				$view
1582
+			);
1583
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1584
+			return false;
1585
+		}
1586
+		EE_Config::$_module_view_map[$key][$route][absint($status)] = $view;
1587
+		return true;
1588
+	}
1589
+
1590
+
1591
+
1592
+	/**
1593
+	 *    get_view - get view for route and status
1594
+	 *
1595
+	 * @access    public
1596
+	 * @param    string  $route  - "pretty" public alias for module method
1597
+	 * @param    integer $status - integer value corresponding  to status constant strings set in module parent class,
1598
+	 *                           allows different views to be served based on status
1599
+	 * @param    string  $key    - url param key indicating a route is being called
1600
+	 * @return    string
1601
+	 */
1602
+	public static function get_view($route = null, $status = 0, $key = 'ee')
1603
+	{
1604
+		do_action('AHEE__EE_Config__get_view__begin', $route, $status);
1605
+		if (isset(EE_Config::$_module_view_map[$key][$route][$status])) {
1606
+			return apply_filters(
1607
+				'FHEE__EE_Config__get_view',
1608
+				EE_Config::$_module_view_map[$key][$route][$status],
1609
+				$route,
1610
+				$status
1611
+			);
1612
+		}
1613
+		return null;
1614
+	}
1615
+
1616
+
1617
+
1618
+	public function update_addon_option_names()
1619
+	{
1620
+		update_option(EE_Config::ADDON_OPTION_NAMES, $this->_addon_option_names);
1621
+	}
1622
+
1623
+
1624
+
1625
+	public function shutdown()
1626
+	{
1627
+		$this->update_addon_option_names();
1628
+	}
18 1629
 
19
-    const LOG_NAME           = 'ee_config_log';
20 1630
 
21
-    const LOG_LENGTH         = 100;
22
-
23
-    const ADDON_OPTION_NAMES = 'ee_config_option_names';
24
-
25
-
26
-    /**
27
-     *    instance of the EE_Config object
28
-     *
29
-     * @var    EE_Config $_instance
30
-     * @access    private
31
-     */
32
-    private static $_instance;
33
-
34
-    /**
35
-     * @var boolean $_logging_enabled
36
-     */
37
-    private static $_logging_enabled = false;
38
-
39
-    /**
40
-     * An StdClass whose property names are addon slugs,
41
-     * and values are their config classes
42
-     *
43
-     * @var StdClass
44
-     */
45
-    public $addons;
46
-
47
-    /**
48
-     * @var EE_Admin_Config
49
-     */
50
-    public $admin;
51
-
52
-    /**
53
-     * @var EE_Core_Config
54
-     */
55
-    public $core;
56
-
57
-    /**
58
-     * @var EE_Currency_Config
59
-     */
60
-    public $currency;
61
-
62
-    /**
63
-     * @var EE_Organization_Config
64
-     */
65
-    public $organization;
66
-
67
-    /**
68
-     * @var EE_Registration_Config
69
-     */
70
-    public $registration;
71
-
72
-    /**
73
-     * @var EE_Template_Config
74
-     */
75
-    public $template_settings;
76
-
77
-    /**
78
-     * Holds EE environment values.
79
-     *
80
-     * @var EE_Environment_Config
81
-     */
82
-    public $environment;
83
-
84
-    /**
85
-     * settings pertaining to Google maps
86
-     *
87
-     * @var EE_Map_Config
88
-     */
89
-    public $map_settings;
90
-
91
-    /**
92
-     * settings pertaining to Taxes
93
-     *
94
-     * @var EE_Tax_Config
95
-     */
96
-    public $tax_settings;
97
-
98
-
99
-    /**
100
-     * Settings pertaining to global messages settings.
101
-     *
102
-     * @var EE_Messages_Config
103
-     */
104
-    public $messages;
105
-
106
-    /**
107
-     * @deprecated
108
-     * @var EE_Gateway_Config
109
-     */
110
-    public $gateway;
111
-
112
-    /**
113
-     * @var    array $_addon_option_names
114
-     * @access    private
115
-     */
116
-    private $_addon_option_names = array();
117
-
118
-    /**
119
-     * @var    array $_module_route_map
120
-     * @access    private
121
-     */
122
-    private static $_module_route_map = array();
123
-
124
-    /**
125
-     * @var    array $_module_forward_map
126
-     * @access    private
127
-     */
128
-    private static $_module_forward_map = array();
129
-
130
-    /**
131
-     * @var    array $_module_view_map
132
-     * @access    private
133
-     */
134
-    private static $_module_view_map = array();
135
-
136
-
137
-
138
-    /**
139
-     * @singleton method used to instantiate class object
140
-     * @access    public
141
-     * @return EE_Config instance
142
-     */
143
-    public static function instance()
144
-    {
145
-        // check if class object is instantiated, and instantiated properly
146
-        if (! self::$_instance instanceof EE_Config) {
147
-            self::$_instance = new self();
148
-        }
149
-        return self::$_instance;
150
-    }
151
-
152
-
153
-
154
-    /**
155
-     * Resets the config
156
-     *
157
-     * @param bool    $hard_reset    if TRUE, sets EE_CONFig back to its original settings in the database. If FALSE
158
-     *                               (default) leaves the database alone, and merely resets the EE_Config object to
159
-     *                               reflect its state in the database
160
-     * @param boolean $reinstantiate if TRUE (default) call instance() and return it. Otherwise, just leave
161
-     *                               $_instance as NULL. Useful in case you want to forget about the old instance on
162
-     *                               EE_Config, but might not be ready to instantiate EE_Config currently (eg if the
163
-     *                               site was put into maintenance mode)
164
-     * @return EE_Config
165
-     */
166
-    public static function reset($hard_reset = false, $reinstantiate = true)
167
-    {
168
-        if (self::$_instance instanceof EE_Config) {
169
-            if ($hard_reset) {
170
-                self::$_instance->_addon_option_names = array();
171
-                self::$_instance->_initialize_config();
172
-                self::$_instance->update_espresso_config();
173
-            }
174
-            self::$_instance->update_addon_option_names();
175
-        }
176
-        self::$_instance = null;
177
-        //we don't need to reset the static properties imo because those should
178
-        //only change when a module is added or removed. Currently we don't
179
-        //support removing a module during a request when it previously existed
180
-        if ($reinstantiate) {
181
-            return self::instance();
182
-        } else {
183
-            return null;
184
-        }
185
-    }
186
-
187
-
188
-
189
-    /**
190
-     *    class constructor
191
-     *
192
-     * @access    private
193
-     */
194
-    private function __construct()
195
-    {
196
-        do_action('AHEE__EE_Config__construct__begin', $this);
197
-        EE_Config::$_logging_enabled = apply_filters('FHEE__EE_Config___construct__logging_enabled', false);
198
-        // setup empty config classes
199
-        $this->_initialize_config();
200
-        // load existing EE site settings
201
-        $this->_load_core_config();
202
-        // confirm everything loaded correctly and set filtered defaults if not
203
-        $this->_verify_config();
204
-        //  register shortcodes and modules
205
-        add_action(
206
-            'AHEE__EE_System__register_shortcodes_modules_and_widgets',
207
-            array($this, 'register_shortcodes_and_modules'),
208
-            999
209
-        );
210
-        //  initialize shortcodes and modules
211
-        add_action('AHEE__EE_System__core_loaded_and_ready', array($this, 'initialize_shortcodes_and_modules'));
212
-        // register widgets
213
-        add_action('widgets_init', array($this, 'widgets_init'), 10);
214
-        // shutdown
215
-        add_action('shutdown', array($this, 'shutdown'), 10);
216
-        // construct__end hook
217
-        do_action('AHEE__EE_Config__construct__end', $this);
218
-        // hardcoded hack
219
-        $this->template_settings->current_espresso_theme = 'Espresso_Arabica_2014';
220
-    }
221
-
222
-
223
-
224
-    /**
225
-     * @return boolean
226
-     */
227
-    public static function logging_enabled()
228
-    {
229
-        return self::$_logging_enabled;
230
-    }
231
-
232
-
233
-
234
-    /**
235
-     * use to get the current theme if needed from static context
236
-     *
237
-     * @return string current theme set.
238
-     */
239
-    public static function get_current_theme()
240
-    {
241
-        return isset(self::$_instance->template_settings->current_espresso_theme)
242
-            ? self::$_instance->template_settings->current_espresso_theme : 'Espresso_Arabica_2014';
243
-    }
244
-
245
-
246
-
247
-    /**
248
-     *        _initialize_config
249
-     *
250
-     * @access private
251
-     * @return void
252
-     */
253
-    private function _initialize_config()
254
-    {
255
-        EE_Config::trim_log();
256
-        //set defaults
257
-        $this->_addon_option_names = get_option(EE_Config::ADDON_OPTION_NAMES, array());
258
-        $this->addons = new stdClass();
259
-        // set _module_route_map
260
-        EE_Config::$_module_route_map = array();
261
-        // set _module_forward_map
262
-        EE_Config::$_module_forward_map = array();
263
-        // set _module_view_map
264
-        EE_Config::$_module_view_map = array();
265
-    }
266
-
267
-
268
-
269
-    /**
270
-     *        load core plugin configuration
271
-     *
272
-     * @access private
273
-     * @return void
274
-     */
275
-    private function _load_core_config()
276
-    {
277
-        // load_core_config__start hook
278
-        do_action('AHEE__EE_Config___load_core_config__start', $this);
279
-        $espresso_config = $this->get_espresso_config();
280
-        foreach ($espresso_config as $config => $settings) {
281
-            // load_core_config__start hook
282
-            $settings = apply_filters(
283
-                'FHEE__EE_Config___load_core_config__config_settings',
284
-                $settings,
285
-                $config,
286
-                $this
287
-            );
288
-            if (is_object($settings) && property_exists($this, $config)) {
289
-                $this->{$config} = apply_filters('FHEE__EE_Config___load_core_config__' . $config, $settings);
290
-                //call configs populate method to ensure any defaults are set for empty values.
291
-                if (method_exists($settings, 'populate')) {
292
-                    $this->{$config}->populate();
293
-                }
294
-                if (method_exists($settings, 'do_hooks')) {
295
-                    $this->{$config}->do_hooks();
296
-                }
297
-            }
298
-        }
299
-        if (apply_filters('FHEE__EE_Config___load_core_config__update_espresso_config', false)) {
300
-            $this->update_espresso_config();
301
-        }
302
-        // load_core_config__end hook
303
-        do_action('AHEE__EE_Config___load_core_config__end', $this);
304
-    }
305
-
306
-
307
-
308
-    /**
309
-     *    _verify_config
310
-     *
311
-     * @access    protected
312
-     * @return    void
313
-     */
314
-    protected function _verify_config()
315
-    {
316
-        $this->core = $this->core instanceof EE_Core_Config
317
-            ? $this->core
318
-            : new EE_Core_Config();
319
-        $this->core = apply_filters('FHEE__EE_Config___initialize_config__core', $this->core);
320
-        $this->organization = $this->organization instanceof EE_Organization_Config
321
-            ? $this->organization
322
-            : new EE_Organization_Config();
323
-        $this->organization = apply_filters('FHEE__EE_Config___initialize_config__organization',
324
-            $this->organization);
325
-        $this->currency = $this->currency instanceof EE_Currency_Config
326
-            ? $this->currency
327
-            : new EE_Currency_Config();
328
-        $this->currency = apply_filters('FHEE__EE_Config___initialize_config__currency', $this->currency);
329
-        $this->registration = $this->registration instanceof EE_Registration_Config
330
-            ? $this->registration
331
-            : new EE_Registration_Config();
332
-        $this->registration = apply_filters('FHEE__EE_Config___initialize_config__registration',
333
-            $this->registration);
334
-        $this->admin = $this->admin instanceof EE_Admin_Config
335
-            ? $this->admin
336
-            : new EE_Admin_Config();
337
-        $this->admin = apply_filters('FHEE__EE_Config___initialize_config__admin', $this->admin);
338
-        $this->template_settings = $this->template_settings instanceof EE_Template_Config
339
-            ? $this->template_settings
340
-            : new EE_Template_Config();
341
-        $this->template_settings = apply_filters(
342
-            'FHEE__EE_Config___initialize_config__template_settings',
343
-            $this->template_settings
344
-        );
345
-        $this->map_settings = $this->map_settings instanceof EE_Map_Config
346
-            ? $this->map_settings
347
-            : new EE_Map_Config();
348
-        $this->map_settings = apply_filters('FHEE__EE_Config___initialize_config__map_settings',
349
-            $this->map_settings);
350
-        $this->environment = $this->environment instanceof EE_Environment_Config
351
-            ? $this->environment
352
-            : new EE_Environment_Config();
353
-        $this->environment = apply_filters('FHEE__EE_Config___initialize_config__environment',
354
-            $this->environment);
355
-        $this->tax_settings = $this->tax_settings instanceof EE_Tax_Config
356
-            ? $this->tax_settings
357
-            : new EE_Tax_Config();
358
-        $this->tax_settings = apply_filters('FHEE__EE_Config___initialize_config__tax_settings',
359
-            $this->tax_settings);
360
-        $this->messages = apply_filters('FHEE__EE_Config__initialize_config__messages', $this->messages);
361
-        $this->messages = $this->messages instanceof EE_Messages_Config
362
-            ? $this->messages
363
-            : new EE_Messages_Config();
364
-        $this->gateway = $this->gateway instanceof EE_Gateway_Config
365
-            ? $this->gateway
366
-            : new EE_Gateway_Config();
367
-        $this->gateway = apply_filters('FHEE__EE_Config___initialize_config__gateway', $this->gateway);
368
-    }
369
-
370
-
371
-    /**
372
-     *    get_espresso_config
373
-     *
374
-     * @access    public
375
-     * @return    array of espresso config stuff
376
-     */
377
-    public function get_espresso_config()
378
-    {
379
-        // grab espresso configuration
380
-        return apply_filters(
381
-            'FHEE__EE_Config__get_espresso_config__CFG',
382
-            get_option(EE_Config::OPTION_NAME, array())
383
-        );
384
-    }
385
-
386
-
387
-
388
-    /**
389
-     *    double_check_config_comparison
390
-     *
391
-     * @access    public
392
-     * @param string $option
393
-     * @param        $old_value
394
-     * @param        $value
395
-     */
396
-    public function double_check_config_comparison($option = '', $old_value, $value)
397
-    {
398
-        // make sure we're checking the ee config
399
-        if ($option === EE_Config::OPTION_NAME) {
400
-            // run a loose comparison of the old value against the new value for type and properties,
401
-            // but NOT exact instance like WP update_option does (ie: NOT type safe comparison)
402
-            if ($value != $old_value) {
403
-                // if they are NOT the same, then remove the hook,
404
-                // which means the subsequent update results will be based solely on the update query results
405
-                // the reason we do this is because, as stated above,
406
-                // WP update_option performs an exact instance comparison (===) on any update values passed to it
407
-                // this happens PRIOR to serialization and any subsequent update.
408
-                // If values are found to match their previous old value,
409
-                // then WP bails before performing any update.
410
-                // Since we are passing the EE_Config object, it is comparing the EXACT instance of the saved version
411
-                // it just pulled from the db, with the one being passed to it (which will not match).
412
-                // HOWEVER, once the object is serialized and passed off to MySQL to update,
413
-                // MySQL MAY ALSO NOT perform the update because
414
-                // the string it sees in the db looks the same as the new one it has been passed!!!
415
-                // This results in the query returning an "affected rows" value of ZERO,
416
-                // which gets returned immediately by WP update_option and looks like an error.
417
-                remove_action('update_option', array($this, 'check_config_updated'));
418
-            }
419
-        }
420
-    }
421
-
422
-
423
-
424
-    /**
425
-     *    update_espresso_config
426
-     *
427
-     * @access   public
428
-     */
429
-    protected function _reset_espresso_addon_config()
430
-    {
431
-        $this->_addon_option_names = array();
432
-        foreach ($this->addons as $addon_name => $addon_config_obj) {
433
-            $addon_config_obj = maybe_unserialize($addon_config_obj);
434
-            $config_class = get_class($addon_config_obj);
435
-            if ($addon_config_obj instanceof $config_class && ! $addon_config_obj instanceof __PHP_Incomplete_Class) {
436
-                $this->update_config('addons', $addon_name, $addon_config_obj, false);
437
-            }
438
-            $this->addons->{$addon_name} = null;
439
-        }
440
-    }
441
-
442
-
443
-
444
-    /**
445
-     *    update_espresso_config
446
-     *
447
-     * @access   public
448
-     * @param   bool $add_success
449
-     * @param   bool $add_error
450
-     * @return   bool
451
-     */
452
-    public function update_espresso_config($add_success = false, $add_error = true)
453
-    {
454
-        // don't allow config updates during WP heartbeats
455
-        if (\EE_Registry::instance()->REQ->get('action', '') === 'heartbeat') {
456
-            return false;
457
-        }
458
-        // commented out the following re: https://events.codebasehq.com/projects/event-espresso/tickets/8197
459
-        //$clone = clone( self::$_instance );
460
-        //self::$_instance = NULL;
461
-        do_action('AHEE__EE_Config__update_espresso_config__begin', $this);
462
-        $this->_reset_espresso_addon_config();
463
-        // hook into update_option because that happens AFTER the ( $value === $old_value ) conditional
464
-        // but BEFORE the actual update occurs
465
-        add_action('update_option', array($this, 'double_check_config_comparison'), 1, 3);
466
-        // now update "ee_config"
467
-        $saved = update_option(EE_Config::OPTION_NAME, $this);
468
-        EE_Config::log(EE_Config::OPTION_NAME);
469
-        // if not saved... check if the hook we just added still exists;
470
-        // if it does, it means one of two things:
471
-        // 		that update_option bailed at the ( $value === $old_value ) conditional,
472
-        //		 or...
473
-        // 		the db update query returned 0 rows affected
474
-        // 		(probably because the data  value was the same from it's perspective)
475
-        // so the existence of the hook means that a negative result from update_option is NOT an error,
476
-        // but just means no update occurred, so don't display an error to the user.
477
-        // BUT... if update_option returns FALSE, AND the hook is missing,
478
-        // then it means that something truly went wrong
479
-        $saved = ! $saved ? has_action('update_option', array($this, 'double_check_config_comparison')) : $saved;
480
-        // remove our action since we don't want it in the system anymore
481
-        remove_action('update_option', array($this, 'double_check_config_comparison'), 1);
482
-        do_action('AHEE__EE_Config__update_espresso_config__end', $this, $saved);
483
-        //self::$_instance = $clone;
484
-        //unset( $clone );
485
-        // if config remains the same or was updated successfully
486
-        if ($saved) {
487
-            if ($add_success) {
488
-                EE_Error::add_success(
489
-                    __('The Event Espresso Configuration Settings have been successfully updated.', 'event_espresso'),
490
-                    __FILE__,
491
-                    __FUNCTION__,
492
-                    __LINE__
493
-                );
494
-            }
495
-            return true;
496
-        } else {
497
-            if ($add_error) {
498
-                EE_Error::add_error(
499
-                    __('The Event Espresso Configuration Settings were not updated.', 'event_espresso'),
500
-                    __FILE__,
501
-                    __FUNCTION__,
502
-                    __LINE__
503
-                );
504
-            }
505
-            return false;
506
-        }
507
-    }
508
-
509
-
510
-
511
-    /**
512
-     *    _verify_config_params
513
-     *
514
-     * @access    private
515
-     * @param    string         $section
516
-     * @param    string         $name
517
-     * @param    string         $config_class
518
-     * @param    EE_Config_Base $config_obj
519
-     * @param    array          $tests_to_run
520
-     * @param    bool           $display_errors
521
-     * @return    bool    TRUE on success, FALSE on fail
522
-     */
523
-    private function _verify_config_params(
524
-        $section = '',
525
-        $name = '',
526
-        $config_class = '',
527
-        $config_obj = null,
528
-        $tests_to_run = array(1, 2, 3, 4, 5, 6, 7, 8),
529
-        $display_errors = true
530
-    ) {
531
-        try {
532
-            foreach ($tests_to_run as $test) {
533
-                switch ($test) {
534
-                    // TEST #1 : check that section was set
535
-                    case 1 :
536
-                        if (empty($section)) {
537
-                            if ($display_errors) {
538
-                                throw new EE_Error(
539
-                                    sprintf(
540
-                                        __(
541
-                                            'No configuration section has been provided while attempting to save "%s".',
542
-                                            'event_espresso'
543
-                                        ),
544
-                                        $config_class
545
-                                    )
546
-                                );
547
-                            }
548
-                            return false;
549
-                        }
550
-                        break;
551
-                    // TEST #2 : check that settings section exists
552
-                    case 2 :
553
-                        if (! isset($this->{$section})) {
554
-                            if ($display_errors) {
555
-                                throw new EE_Error(
556
-                                    sprintf(
557
-                                        __('The "%s" configuration section does not exist.', 'event_espresso'),
558
-                                        $section
559
-                                    )
560
-                                );
561
-                            }
562
-                            return false;
563
-                        }
564
-                        break;
565
-                    // TEST #3 : check that section is the proper format
566
-                    case 3 :
567
-                        if (
568
-                        ! ($this->{$section} instanceof EE_Config_Base || $this->{$section} instanceof stdClass)
569
-                        ) {
570
-                            if ($display_errors) {
571
-                                throw new EE_Error(
572
-                                    sprintf(
573
-                                        __(
574
-                                            'The "%s" configuration settings have not been formatted correctly.',
575
-                                            'event_espresso'
576
-                                        ),
577
-                                        $section
578
-                                    )
579
-                                );
580
-                            }
581
-                            return false;
582
-                        }
583
-                        break;
584
-                    // TEST #4 : check that config section name has been set
585
-                    case 4 :
586
-                        if (empty($name)) {
587
-                            if ($display_errors) {
588
-                                throw new EE_Error(
589
-                                    __(
590
-                                        'No name has been provided for the specific configuration section.',
591
-                                        'event_espresso'
592
-                                    )
593
-                                );
594
-                            }
595
-                            return false;
596
-                        }
597
-                        break;
598
-                    // TEST #5 : check that a config class name has been set
599
-                    case 5 :
600
-                        if (empty($config_class)) {
601
-                            if ($display_errors) {
602
-                                throw new EE_Error(
603
-                                    __(
604
-                                        'No class name has been provided for the specific configuration section.',
605
-                                        'event_espresso'
606
-                                    )
607
-                                );
608
-                            }
609
-                            return false;
610
-                        }
611
-                        break;
612
-                    // TEST #6 : verify config class is accessible
613
-                    case 6 :
614
-                        if (! class_exists($config_class)) {
615
-                            if ($display_errors) {
616
-                                throw new EE_Error(
617
-                                    sprintf(
618
-                                        __(
619
-                                            'The "%s" class does not exist. Please ensure that an autoloader has been set for it.',
620
-                                            'event_espresso'
621
-                                        ),
622
-                                        $config_class
623
-                                    )
624
-                                );
625
-                            }
626
-                            return false;
627
-                        }
628
-                        break;
629
-                    // TEST #7 : check that config has even been set
630
-                    case 7 :
631
-                        if (! isset($this->{$section}->{$name})) {
632
-                            if ($display_errors) {
633
-                                throw new EE_Error(
634
-                                    sprintf(
635
-                                        __('No configuration has been set for "%1$s->%2$s".', 'event_espresso'),
636
-                                        $section,
637
-                                        $name
638
-                                    )
639
-                                );
640
-                            }
641
-                            return false;
642
-                        } else {
643
-                            // and make sure it's not serialized
644
-                            $this->{$section}->{$name} = maybe_unserialize($this->{$section}->{$name});
645
-                        }
646
-                        break;
647
-                    // TEST #8 : check that config is the requested type
648
-                    case 8 :
649
-                        if (! $this->{$section}->{$name} instanceof $config_class) {
650
-                            if ($display_errors) {
651
-                                throw new EE_Error(
652
-                                    sprintf(
653
-                                        __(
654
-                                            'The configuration for "%1$s->%2$s" is not of the "%3$s" class.',
655
-                                            'event_espresso'
656
-                                        ),
657
-                                        $section,
658
-                                        $name,
659
-                                        $config_class
660
-                                    )
661
-                                );
662
-                            }
663
-                            return false;
664
-                        }
665
-                        break;
666
-                    // TEST #9 : verify config object
667
-                    case 9 :
668
-                        if (! $config_obj instanceof EE_Config_Base) {
669
-                            if ($display_errors) {
670
-                                throw new EE_Error(
671
-                                    sprintf(
672
-                                        __('The "%s" class is not an instance of EE_Config_Base.', 'event_espresso'),
673
-                                        print_r($config_obj, true)
674
-                                    )
675
-                                );
676
-                            }
677
-                            return false;
678
-                        }
679
-                        break;
680
-                }
681
-            }
682
-        } catch (EE_Error $e) {
683
-            $e->get_error();
684
-        }
685
-        // you have successfully run the gauntlet
686
-        return true;
687
-    }
688
-
689
-
690
-
691
-    /**
692
-     *    _generate_config_option_name
693
-     *
694
-     * @access        protected
695
-     * @param        string $section
696
-     * @param        string $name
697
-     * @return        string
698
-     */
699
-    private function _generate_config_option_name($section = '', $name = '')
700
-    {
701
-        return 'ee_config-' . strtolower($section . '-' . str_replace(array('EE_', 'EED_'), '', $name));
702
-    }
703
-
704
-
705
-
706
-    /**
707
-     *    _set_config_class
708
-     * ensures that a config class is set, either from a passed config class or one generated from the config name
709
-     *
710
-     * @access    private
711
-     * @param    string $config_class
712
-     * @param    string $name
713
-     * @return    string
714
-     */
715
-    private function _set_config_class($config_class = '', $name = '')
716
-    {
717
-        return ! empty($config_class)
718
-            ? $config_class
719
-            : str_replace(' ', '_', ucwords(str_replace('_', ' ', $name))) . '_Config';
720
-    }
721
-
722
-
723
-
724
-    /**
725
-     *    set_config
726
-     *
727
-     * @access    protected
728
-     * @param    string         $section
729
-     * @param    string         $name
730
-     * @param    string         $config_class
731
-     * @param    EE_Config_Base $config_obj
732
-     * @return    EE_Config_Base
733
-     */
734
-    public function set_config($section = '', $name = '', $config_class = '', EE_Config_Base $config_obj = null)
735
-    {
736
-        // ensure config class is set to something
737
-        $config_class = $this->_set_config_class($config_class, $name);
738
-        // run tests 1-4, 6, and 7 to verify all config params are set and valid
739
-        if (! $this->_verify_config_params($section, $name, $config_class, null, array(1, 2, 3, 4, 5, 6))) {
740
-            return null;
741
-        }
742
-        $config_option_name = $this->_generate_config_option_name($section, $name);
743
-        // if the config option name hasn't been added yet to the list of option names we're tracking, then do so now
744
-        if (! isset($this->_addon_option_names[$config_option_name])) {
745
-            $this->_addon_option_names[$config_option_name] = $config_class;
746
-            $this->update_addon_option_names();
747
-        }
748
-        // verify the incoming config object but suppress errors
749
-        if (! $this->_verify_config_params($section, $name, $config_class, $config_obj, array(9), false)) {
750
-            $config_obj = new $config_class();
751
-        }
752
-        if (get_option($config_option_name)) {
753
-            EE_Config::log($config_option_name);
754
-            update_option($config_option_name, $config_obj);
755
-            $this->{$section}->{$name} = $config_obj;
756
-            return $this->{$section}->{$name};
757
-        } else {
758
-            // create a wp-option for this config
759
-            if (add_option($config_option_name, $config_obj, '', 'no')) {
760
-                $this->{$section}->{$name} = maybe_unserialize($config_obj);
761
-                return $this->{$section}->{$name};
762
-            } else {
763
-                EE_Error::add_error(
764
-                    sprintf(__('The "%s" could not be saved to the database.', 'event_espresso'), $config_class),
765
-                    __FILE__,
766
-                    __FUNCTION__,
767
-                    __LINE__
768
-                );
769
-                return null;
770
-            }
771
-        }
772
-    }
773
-
774
-
775
-
776
-    /**
777
-     *    update_config
778
-     * Important: the config object must ALREADY be set, otherwise this will produce an error.
779
-     *
780
-     * @access    public
781
-     * @param    string                $section
782
-     * @param    string                $name
783
-     * @param    EE_Config_Base|string $config_obj
784
-     * @param    bool                  $throw_errors
785
-     * @return    bool
786
-     */
787
-    public function update_config($section = '', $name = '', $config_obj = '', $throw_errors = true)
788
-    {
789
-        // don't allow config updates during WP heartbeats
790
-        if (\EE_Registry::instance()->REQ->get('action', '') === 'heartbeat') {
791
-            return false;
792
-        }
793
-        $config_obj = maybe_unserialize($config_obj);
794
-        // get class name of the incoming object
795
-        $config_class = get_class($config_obj);
796
-        // run tests 1-5 and 9 to verify config
797
-        if (! $this->_verify_config_params(
798
-            $section,
799
-            $name,
800
-            $config_class,
801
-            $config_obj,
802
-            array(1, 2, 3, 4, 7, 9)
803
-        )
804
-        ) {
805
-            return false;
806
-        }
807
-        $config_option_name = $this->_generate_config_option_name($section, $name);
808
-        // check if config object has been added to db by seeing if config option name is in $this->_addon_option_names array
809
-        if (! isset($this->_addon_option_names[$config_option_name])) {
810
-            // save new config to db
811
-            if ($this->set_config($section, $name, $config_class, $config_obj)) {
812
-                return true;
813
-            }
814
-        } else {
815
-            // first check if the record already exists
816
-            $existing_config = get_option($config_option_name);
817
-            $config_obj = serialize($config_obj);
818
-            // just return if db record is already up to date (NOT type safe comparison)
819
-            if ($existing_config == $config_obj) {
820
-                $this->{$section}->{$name} = $config_obj;
821
-                return true;
822
-            } else if (update_option($config_option_name, $config_obj)) {
823
-                EE_Config::log($config_option_name);
824
-                // update wp-option for this config class
825
-                $this->{$section}->{$name} = $config_obj;
826
-                return true;
827
-            } elseif ($throw_errors) {
828
-                EE_Error::add_error(
829
-                    sprintf(
830
-                        __(
831
-                            'The "%1$s" object stored at"%2$s" was not successfully updated in the database.',
832
-                            'event_espresso'
833
-                        ),
834
-                        $config_class,
835
-                        'EE_Config->' . $section . '->' . $name
836
-                    ),
837
-                    __FILE__,
838
-                    __FUNCTION__,
839
-                    __LINE__
840
-                );
841
-            }
842
-        }
843
-        return false;
844
-    }
845
-
846
-
847
-
848
-    /**
849
-     *    get_config
850
-     *
851
-     * @access    public
852
-     * @param    string $section
853
-     * @param    string $name
854
-     * @param    string $config_class
855
-     * @return    mixed EE_Config_Base | NULL
856
-     */
857
-    public function get_config($section = '', $name = '', $config_class = '')
858
-    {
859
-        // ensure config class is set to something
860
-        $config_class = $this->_set_config_class($config_class, $name);
861
-        // run tests 1-4, 6 and 7 to verify that all params have been set
862
-        if (! $this->_verify_config_params($section, $name, $config_class, null, array(1, 2, 3, 4, 5, 6))) {
863
-            return null;
864
-        }
865
-        // now test if the requested config object exists, but suppress errors
866
-        if ($this->_verify_config_params($section, $name, $config_class, null, array(7, 8), false)) {
867
-            // config already exists, so pass it back
868
-            return $this->{$section}->{$name};
869
-        }
870
-        // load config option from db if it exists
871
-        $config_obj = $this->get_config_option($this->_generate_config_option_name($section, $name));
872
-        // verify the newly retrieved config object, but suppress errors
873
-        if ($this->_verify_config_params($section, $name, $config_class, $config_obj, array(9), false)) {
874
-            // config is good, so set it and pass it back
875
-            $this->{$section}->{$name} = $config_obj;
876
-            return $this->{$section}->{$name};
877
-        }
878
-        // oops! $config_obj is not already set and does not exist in the db, so create a new one
879
-        $config_obj = $this->set_config($section, $name, $config_class);
880
-        // verify the newly created config object
881
-        if ($this->_verify_config_params($section, $name, $config_class, $config_obj, array(9))) {
882
-            return $this->{$section}->{$name};
883
-        } else {
884
-            EE_Error::add_error(
885
-                sprintf(__('The "%s" could not be retrieved from the database.', 'event_espresso'), $config_class),
886
-                __FILE__,
887
-                __FUNCTION__,
888
-                __LINE__
889
-            );
890
-        }
891
-        return null;
892
-    }
893
-
894
-
895
-
896
-    /**
897
-     *    get_config_option
898
-     *
899
-     * @access    public
900
-     * @param    string $config_option_name
901
-     * @return    mixed EE_Config_Base | FALSE
902
-     */
903
-    public function get_config_option($config_option_name = '')
904
-    {
905
-        // retrieve the wp-option for this config class.
906
-        $config_option = maybe_unserialize(get_option($config_option_name, array()));
907
-        if (empty($config_option)) {
908
-            EE_Config::log($config_option_name . '-NOT-FOUND');
909
-        }
910
-        return $config_option;
911
-    }
912
-
913
-
914
-
915
-    /**
916
-     * log
917
-     *
918
-     * @param string $config_option_name
919
-     */
920
-    public static function log($config_option_name = '')
921
-    {
922
-        if (EE_Config::logging_enabled() && ! empty($config_option_name)) {
923
-            $config_log = get_option(EE_Config::LOG_NAME, array());
924
-            //copy incoming $_REQUEST and sanitize it so we can save it
925
-            $_request = $_REQUEST;
926
-            array_walk_recursive($_request, 'sanitize_text_field');
927
-            $config_log[(string)microtime(true)] = array(
928
-                'config_name' => $config_option_name,
929
-                'request'     => $_request,
930
-            );
931
-            update_option(EE_Config::LOG_NAME, $config_log);
932
-        }
933
-    }
934
-
935
-
936
-
937
-    /**
938
-     * trim_log
939
-     * reduces the size of the config log to the length specified by EE_Config::LOG_LENGTH
940
-     */
941
-    public static function trim_log()
942
-    {
943
-        if (! EE_Config::logging_enabled()) {
944
-            return;
945
-        }
946
-        $config_log = maybe_unserialize(get_option(EE_Config::LOG_NAME, array()));
947
-        $log_length = count($config_log);
948
-        if ($log_length > EE_Config::LOG_LENGTH) {
949
-            ksort($config_log);
950
-            $config_log = array_slice($config_log, $log_length - EE_Config::LOG_LENGTH, null, true);
951
-            update_option(EE_Config::LOG_NAME, $config_log);
952
-        }
953
-    }
954
-
955
-
956
-
957
-    /**
958
-     *    get_page_for_posts
959
-     *    if the wp-option "show_on_front" is set to "page", then this is the post_name for the post set in the
960
-     *    wp-option "page_for_posts", or "posts" if no page is selected
961
-     *
962
-     * @access    public
963
-     * @return    string
964
-     */
965
-    public static function get_page_for_posts()
966
-    {
967
-        $page_for_posts = get_option('page_for_posts');
968
-        if (! $page_for_posts) {
969
-            return 'posts';
970
-        }
971
-        /** @type WPDB $wpdb */
972
-        global $wpdb;
973
-        $SQL = "SELECT post_name from $wpdb->posts WHERE post_type='posts' OR post_type='page' AND post_status='publish' AND ID=%d";
974
-        return $wpdb->get_var($wpdb->prepare($SQL, $page_for_posts));
975
-    }
976
-
977
-
978
-
979
-    /**
980
-     *    register_shortcodes_and_modules.
981
-     *    At this point, it's too early to tell if we're maintenance mode or not.
982
-     *    In fact, this is where we give modules a chance to let core know they exist
983
-     *    so they can help trigger maintenance mode if it's needed
984
-     *
985
-     * @access    public
986
-     * @return    void
987
-     */
988
-    public function register_shortcodes_and_modules()
989
-    {
990
-        // allow shortcodes to register with WP and to set hooks for the rest of the system
991
-        EE_Registry::instance()->shortcodes = $this->_register_shortcodes();
992
-        // allow modules to set hooks for the rest of the system
993
-        EE_Registry::instance()->modules = $this->_register_modules();
994
-    }
995
-
996
-
997
-
998
-    /**
999
-     *    initialize_shortcodes_and_modules
1000
-     *    meaning they can start adding their hooks to get stuff done
1001
-     *
1002
-     * @access    public
1003
-     * @return    void
1004
-     */
1005
-    public function initialize_shortcodes_and_modules()
1006
-    {
1007
-        // allow shortcodes to set hooks for the rest of the system
1008
-        $this->_initialize_shortcodes();
1009
-        // allow modules to set hooks for the rest of the system
1010
-        $this->_initialize_modules();
1011
-    }
1012
-
1013
-
1014
-
1015
-    /**
1016
-     *    widgets_init
1017
-     *
1018
-     * @access private
1019
-     * @return void
1020
-     */
1021
-    public function widgets_init()
1022
-    {
1023
-        //only init widgets on admin pages when not in complete maintenance, and
1024
-        //on frontend when not in any maintenance mode
1025
-        if (
1026
-            ! EE_Maintenance_Mode::instance()->level()
1027
-            || (
1028
-                is_admin()
1029
-                && EE_Maintenance_Mode::instance()->level() !== EE_Maintenance_Mode::level_2_complete_maintenance
1030
-            )
1031
-        ) {
1032
-            // grab list of installed widgets
1033
-            $widgets_to_register = glob(EE_WIDGETS . '*', GLOB_ONLYDIR);
1034
-            // filter list of modules to register
1035
-            $widgets_to_register = apply_filters(
1036
-                'FHEE__EE_Config__register_widgets__widgets_to_register',
1037
-                $widgets_to_register
1038
-            );
1039
-            if (! empty($widgets_to_register)) {
1040
-                // cycle thru widget folders
1041
-                foreach ($widgets_to_register as $widget_path) {
1042
-                    // add to list of installed widget modules
1043
-                    EE_Config::register_ee_widget($widget_path);
1044
-                }
1045
-            }
1046
-            // filter list of installed modules
1047
-            EE_Registry::instance()->widgets = apply_filters(
1048
-                'FHEE__EE_Config__register_widgets__installed_widgets',
1049
-                EE_Registry::instance()->widgets
1050
-            );
1051
-        }
1052
-    }
1053
-
1054
-
1055
-
1056
-    /**
1057
-     *    register_ee_widget - makes core aware of this widget
1058
-     *
1059
-     * @access    public
1060
-     * @param    string $widget_path - full path up to and including widget folder
1061
-     * @return    void
1062
-     */
1063
-    public static function register_ee_widget($widget_path = null)
1064
-    {
1065
-        do_action('AHEE__EE_Config__register_widget__begin', $widget_path);
1066
-        $widget_ext = '.widget.php';
1067
-        // make all separators match
1068
-        $widget_path = rtrim(str_replace('/\\', DS, $widget_path), DS);
1069
-        // does the file path INCLUDE the actual file name as part of the path ?
1070
-        if (strpos($widget_path, $widget_ext) !== false) {
1071
-            // grab and shortcode file name from directory name and break apart at dots
1072
-            $file_name = explode('.', basename($widget_path));
1073
-            // take first segment from file name pieces and remove class prefix if it exists
1074
-            $widget = strpos($file_name[0], 'EEW_') === 0 ? substr($file_name[0], 4) : $file_name[0];
1075
-            // sanitize shortcode directory name
1076
-            $widget = sanitize_key($widget);
1077
-            // now we need to rebuild the shortcode path
1078
-            $widget_path = explode(DS, $widget_path);
1079
-            // remove last segment
1080
-            array_pop($widget_path);
1081
-            // glue it back together
1082
-            $widget_path = implode(DS, $widget_path);
1083
-        } else {
1084
-            // grab and sanitize widget directory name
1085
-            $widget = sanitize_key(basename($widget_path));
1086
-        }
1087
-        // create classname from widget directory name
1088
-        $widget = str_replace(' ', '_', ucwords(str_replace('_', ' ', $widget)));
1089
-        // add class prefix
1090
-        $widget_class = 'EEW_' . $widget;
1091
-        // does the widget exist ?
1092
-        if (! is_readable($widget_path . DS . $widget_class . $widget_ext)) {
1093
-            $msg = sprintf(
1094
-                __(
1095
-                    'The requested %s widget file could not be found or is not readable due to file permissions. Please ensure the following path is correct: %s',
1096
-                    'event_espresso'
1097
-                ),
1098
-                $widget_class,
1099
-                $widget_path . DS . $widget_class . $widget_ext
1100
-            );
1101
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1102
-            return;
1103
-        }
1104
-        // load the widget class file
1105
-        require_once($widget_path . DS . $widget_class . $widget_ext);
1106
-        // verify that class exists
1107
-        if (! class_exists($widget_class)) {
1108
-            $msg = sprintf(__('The requested %s widget class does not exist.', 'event_espresso'), $widget_class);
1109
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1110
-            return;
1111
-        }
1112
-        register_widget($widget_class);
1113
-        // add to array of registered widgets
1114
-        EE_Registry::instance()->widgets->{$widget_class} = $widget_path . DS . $widget_class . $widget_ext;
1115
-    }
1116
-
1117
-
1118
-
1119
-    /**
1120
-     *        _register_shortcodes
1121
-     *
1122
-     * @access private
1123
-     * @return array
1124
-     */
1125
-    private function _register_shortcodes()
1126
-    {
1127
-        // grab list of installed shortcodes
1128
-        $shortcodes_to_register = glob(EE_SHORTCODES . '*', GLOB_ONLYDIR);
1129
-        // filter list of modules to register
1130
-        $shortcodes_to_register = apply_filters(
1131
-            'FHEE__EE_Config__register_shortcodes__shortcodes_to_register',
1132
-            $shortcodes_to_register
1133
-        );
1134
-        if (! empty($shortcodes_to_register)) {
1135
-            // cycle thru shortcode folders
1136
-            foreach ($shortcodes_to_register as $shortcode_path) {
1137
-                // add to list of installed shortcode modules
1138
-                EE_Config::register_shortcode($shortcode_path);
1139
-            }
1140
-        }
1141
-        // filter list of installed modules
1142
-        return apply_filters(
1143
-            'FHEE__EE_Config___register_shortcodes__installed_shortcodes',
1144
-            EE_Registry::instance()->shortcodes
1145
-        );
1146
-    }
1147
-
1148
-
1149
-
1150
-    /**
1151
-     *    register_shortcode - makes core aware of this shortcode
1152
-     *
1153
-     * @access    public
1154
-     * @param    string $shortcode_path - full path up to and including shortcode folder
1155
-     * @return    bool
1156
-     */
1157
-    public static function register_shortcode($shortcode_path = null)
1158
-    {
1159
-        do_action('AHEE__EE_Config__register_shortcode__begin', $shortcode_path);
1160
-        $shortcode_ext = '.shortcode.php';
1161
-        // make all separators match
1162
-        $shortcode_path = str_replace(array('\\', '/'), DS, $shortcode_path);
1163
-        // does the file path INCLUDE the actual file name as part of the path ?
1164
-        if (strpos($shortcode_path, $shortcode_ext) !== false) {
1165
-            // grab shortcode file name from directory name and break apart at dots
1166
-            $shortcode_file = explode('.', basename($shortcode_path));
1167
-            // take first segment from file name pieces and remove class prefix if it exists
1168
-            $shortcode = strpos($shortcode_file[0], 'EES_') === 0
1169
-                ? substr($shortcode_file[0], 4)
1170
-                : $shortcode_file[0];
1171
-            // sanitize shortcode directory name
1172
-            $shortcode = sanitize_key($shortcode);
1173
-            // now we need to rebuild the shortcode path
1174
-            $shortcode_path = explode(DS, $shortcode_path);
1175
-            // remove last segment
1176
-            array_pop($shortcode_path);
1177
-            // glue it back together
1178
-            $shortcode_path = implode(DS, $shortcode_path) . DS;
1179
-        } else {
1180
-            // we need to generate the filename based off of the folder name
1181
-            // grab and sanitize shortcode directory name
1182
-            $shortcode = sanitize_key(basename($shortcode_path));
1183
-            $shortcode_path = rtrim($shortcode_path, DS) . DS;
1184
-        }
1185
-        // create classname from shortcode directory or file name
1186
-        $shortcode = str_replace(' ', '_', ucwords(str_replace('_', ' ', $shortcode)));
1187
-        // add class prefix
1188
-        $shortcode_class = 'EES_' . $shortcode;
1189
-        // does the shortcode exist ?
1190
-        if (! is_readable($shortcode_path . DS . $shortcode_class . $shortcode_ext)) {
1191
-            $msg = sprintf(
1192
-                __(
1193
-                    'The requested %s shortcode file could not be found or is not readable due to file permissions. It should be in %s',
1194
-                    'event_espresso'
1195
-                ),
1196
-                $shortcode_class,
1197
-                $shortcode_path . DS . $shortcode_class . $shortcode_ext
1198
-            );
1199
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1200
-            return false;
1201
-        }
1202
-        // load the shortcode class file
1203
-        require_once($shortcode_path . $shortcode_class . $shortcode_ext);
1204
-        // verify that class exists
1205
-        if (! class_exists($shortcode_class)) {
1206
-            $msg = sprintf(
1207
-                __('The requested %s shortcode class does not exist.', 'event_espresso'),
1208
-                $shortcode_class
1209
-            );
1210
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1211
-            return false;
1212
-        }
1213
-        $shortcode = strtoupper($shortcode);
1214
-        // add to array of registered shortcodes
1215
-        EE_Registry::instance()->shortcodes->{$shortcode} = $shortcode_path . $shortcode_class . $shortcode_ext;
1216
-        return true;
1217
-    }
1218
-
1219
-
1220
-
1221
-    /**
1222
-     *        _register_modules
1223
-     *
1224
-     * @access private
1225
-     * @return array
1226
-     */
1227
-    private function _register_modules()
1228
-    {
1229
-        // grab list of installed modules
1230
-        $modules_to_register = glob(EE_MODULES . '*', GLOB_ONLYDIR);
1231
-        // filter list of modules to register
1232
-        $modules_to_register = apply_filters(
1233
-            'FHEE__EE_Config__register_modules__modules_to_register',
1234
-            $modules_to_register
1235
-        );
1236
-        if (! empty($modules_to_register)) {
1237
-            // loop through folders
1238
-            foreach ($modules_to_register as $module_path) {
1239
-                /**TEMPORARILY EXCLUDE gateways from modules for time being**/
1240
-                if (
1241
-                    $module_path !== EE_MODULES . 'zzz-copy-this-module-template'
1242
-                    && $module_path !== EE_MODULES . 'gateways'
1243
-                ) {
1244
-                    // add to list of installed modules
1245
-                    EE_Config::register_module($module_path);
1246
-                }
1247
-            }
1248
-        }
1249
-        // filter list of installed modules
1250
-        return apply_filters(
1251
-            'FHEE__EE_Config___register_modules__installed_modules',
1252
-            EE_Registry::instance()->modules
1253
-        );
1254
-    }
1255
-
1256
-
1257
-
1258
-    /**
1259
-     *    register_module - makes core aware of this module
1260
-     *
1261
-     * @access    public
1262
-     * @param    string $module_path - full path up to and including module folder
1263
-     * @return    bool
1264
-     */
1265
-    public static function register_module($module_path = null)
1266
-    {
1267
-        do_action('AHEE__EE_Config__register_module__begin', $module_path);
1268
-        $module_ext = '.module.php';
1269
-        // make all separators match
1270
-        $module_path = str_replace(array('\\', '/'), DS, $module_path);
1271
-        // does the file path INCLUDE the actual file name as part of the path ?
1272
-        if (strpos($module_path, $module_ext) !== false) {
1273
-            // grab and shortcode file name from directory name and break apart at dots
1274
-            $module_file = explode('.', basename($module_path));
1275
-            // now we need to rebuild the shortcode path
1276
-            $module_path = explode(DS, $module_path);
1277
-            // remove last segment
1278
-            array_pop($module_path);
1279
-            // glue it back together
1280
-            $module_path = implode(DS, $module_path) . DS;
1281
-            // take first segment from file name pieces and sanitize it
1282
-            $module = preg_replace('/[^a-zA-Z0-9_\-]/', '', $module_file[0]);
1283
-            // ensure class prefix is added
1284
-            $module_class = strpos($module, 'EED_') !== 0 ? 'EED_' . $module : $module;
1285
-        } else {
1286
-            // we need to generate the filename based off of the folder name
1287
-            // grab and sanitize module name
1288
-            $module = strtolower(basename($module_path));
1289
-            $module = preg_replace('/[^a-z0-9_\-]/', '', $module);
1290
-            // like trailingslashit()
1291
-            $module_path = rtrim($module_path, DS) . DS;
1292
-            // create classname from module directory name
1293
-            $module = str_replace(' ', '_', ucwords(str_replace('_', ' ', $module)));
1294
-            // add class prefix
1295
-            $module_class = 'EED_' . $module;
1296
-        }
1297
-        // does the module exist ?
1298
-        if (! is_readable($module_path . DS . $module_class . $module_ext)) {
1299
-            $msg = sprintf(
1300
-                __(
1301
-                    'The requested %s module file could not be found or is not readable due to file permissions.',
1302
-                    'event_espresso'
1303
-                ),
1304
-                $module
1305
-            );
1306
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1307
-            return false;
1308
-        }
1309
-        // load the module class file
1310
-        require_once($module_path . $module_class . $module_ext);
1311
-        // verify that class exists
1312
-        if (! class_exists($module_class)) {
1313
-            $msg = sprintf(__('The requested %s module class does not exist.', 'event_espresso'), $module_class);
1314
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1315
-            return false;
1316
-        }
1317
-        // add to array of registered modules
1318
-        EE_Registry::instance()->modules->{$module_class} = $module_path . $module_class . $module_ext;
1319
-        do_action(
1320
-            'AHEE__EE_Config__register_module__complete',
1321
-            $module_class,
1322
-            EE_Registry::instance()->modules->{$module_class}
1323
-        );
1324
-        return true;
1325
-    }
1326
-
1327
-
1328
-
1329
-    /**
1330
-     *    _initialize_shortcodes
1331
-     *    allow shortcodes to set hooks for the rest of the system
1332
-     *
1333
-     * @access private
1334
-     * @return void
1335
-     */
1336
-    private function _initialize_shortcodes()
1337
-    {
1338
-        // cycle thru shortcode folders
1339
-        foreach (EE_Registry::instance()->shortcodes as $shortcode => $shortcode_path) {
1340
-            // add class prefix
1341
-            $shortcode_class = 'EES_' . $shortcode;
1342
-            // fire the shortcode class's set_hooks methods in case it needs to hook into other parts of the system
1343
-            // which set hooks ?
1344
-            if (is_admin()) {
1345
-                // fire immediately
1346
-                call_user_func(array($shortcode_class, 'set_hooks_admin'));
1347
-            } else {
1348
-                // delay until other systems are online
1349
-                add_action(
1350
-                    'AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons',
1351
-                    array($shortcode_class, 'set_hooks')
1352
-                );
1353
-                // convert classname to UPPERCASE and create WP shortcode.
1354
-                $shortcode_tag = strtoupper($shortcode);
1355
-                // but first check if the shortcode has already been added before assigning 'fallback_shortcode_processor'
1356
-                if (! shortcode_exists($shortcode_tag)) {
1357
-                    // NOTE: this shortcode declaration will get overridden if the shortcode is successfully detected in the post content in EE_Front_Controller->_initialize_shortcodes()
1358
-                    add_shortcode($shortcode_tag, array($shortcode_class, 'fallback_shortcode_processor'));
1359
-                }
1360
-            }
1361
-        }
1362
-    }
1363
-
1364
-
1365
-
1366
-    /**
1367
-     *    _initialize_modules
1368
-     *    allow modules to set hooks for the rest of the system
1369
-     *
1370
-     * @access private
1371
-     * @return void
1372
-     */
1373
-    private function _initialize_modules()
1374
-    {
1375
-        // cycle thru shortcode folders
1376
-        foreach (EE_Registry::instance()->modules as $module_class => $module_path) {
1377
-            // fire the shortcode class's set_hooks methods in case it needs to hook into other parts of the system
1378
-            // which set hooks ?
1379
-            if (is_admin()) {
1380
-                // fire immediately
1381
-                call_user_func(array($module_class, 'set_hooks_admin'));
1382
-            } else {
1383
-                // delay until other systems are online
1384
-                add_action(
1385
-                    'AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons',
1386
-                    array($module_class, 'set_hooks')
1387
-                );
1388
-            }
1389
-        }
1390
-    }
1391
-
1392
-
1393
-
1394
-    /**
1395
-     *    register_route - adds module method routes to route_map
1396
-     *
1397
-     * @access    public
1398
-     * @param    string $route       - "pretty" public alias for module method
1399
-     * @param    string $module      - module name (classname without EED_ prefix)
1400
-     * @param    string $method_name - the actual module method to be routed to
1401
-     * @param    string $key         - url param key indicating a route is being called
1402
-     * @return    bool
1403
-     */
1404
-    public static function register_route($route = null, $module = null, $method_name = null, $key = 'ee')
1405
-    {
1406
-        do_action('AHEE__EE_Config__register_route__begin', $route, $module, $method_name);
1407
-        $module = str_replace('EED_', '', $module);
1408
-        $module_class = 'EED_' . $module;
1409
-        if (! isset(EE_Registry::instance()->modules->{$module_class})) {
1410
-            $msg = sprintf(__('The module %s has not been registered.', 'event_espresso'), $module);
1411
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1412
-            return false;
1413
-        }
1414
-        if (empty($route)) {
1415
-            $msg = sprintf(__('No route has been supplied.', 'event_espresso'), $route);
1416
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1417
-            return false;
1418
-        }
1419
-        if (! method_exists('EED_' . $module, $method_name)) {
1420
-            $msg = sprintf(
1421
-                __('A valid class method for the %s route has not been supplied.', 'event_espresso'),
1422
-                $route
1423
-            );
1424
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1425
-            return false;
1426
-        }
1427
-        EE_Config::$_module_route_map[$key][$route] = array('EED_' . $module, $method_name);
1428
-        return true;
1429
-    }
1430
-
1431
-
1432
-
1433
-    /**
1434
-     *    get_route - get module method route
1435
-     *
1436
-     * @access    public
1437
-     * @param    string $route - "pretty" public alias for module method
1438
-     * @param    string $key   - url param key indicating a route is being called
1439
-     * @return    string
1440
-     */
1441
-    public static function get_route($route = null, $key = 'ee')
1442
-    {
1443
-        do_action('AHEE__EE_Config__get_route__begin', $route);
1444
-        $route = (string)apply_filters('FHEE__EE_Config__get_route', $route);
1445
-        if (isset(EE_Config::$_module_route_map[$key][$route])) {
1446
-            return EE_Config::$_module_route_map[$key][$route];
1447
-        }
1448
-        return null;
1449
-    }
1450
-
1451
-
1452
-
1453
-    /**
1454
-     *    get_routes - get ALL module method routes
1455
-     *
1456
-     * @access    public
1457
-     * @return    array
1458
-     */
1459
-    public static function get_routes()
1460
-    {
1461
-        return EE_Config::$_module_route_map;
1462
-    }
1463
-
1464
-
1465
-
1466
-    /**
1467
-     *    register_forward - allows modules to forward request to another module for further processing
1468
-     *
1469
-     * @access    public
1470
-     * @param    string       $route   - "pretty" public alias for module method
1471
-     * @param    integer      $status  - integer value corresponding  to status constant strings set in module parent
1472
-     *                                 class, allows different forwards to be served based on status
1473
-     * @param    array|string $forward - function name or array( class, method )
1474
-     * @param    string       $key     - url param key indicating a route is being called
1475
-     * @return    bool
1476
-     */
1477
-    public static function register_forward($route = null, $status = 0, $forward = null, $key = 'ee')
1478
-    {
1479
-        do_action('AHEE__EE_Config__register_forward', $route, $status, $forward);
1480
-        if (! isset(EE_Config::$_module_route_map[$key][$route]) || empty($route)) {
1481
-            $msg = sprintf(
1482
-                __('The module route %s for this forward has not been registered.', 'event_espresso'),
1483
-                $route
1484
-            );
1485
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1486
-            return false;
1487
-        }
1488
-        if (empty($forward)) {
1489
-            $msg = sprintf(__('No forwarding route has been supplied.', 'event_espresso'), $route);
1490
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1491
-            return false;
1492
-        }
1493
-        if (is_array($forward)) {
1494
-            if (! isset($forward[1])) {
1495
-                $msg = sprintf(
1496
-                    __('A class method for the %s forwarding route has not been supplied.', 'event_espresso'),
1497
-                    $route
1498
-                );
1499
-                EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1500
-                return false;
1501
-            }
1502
-            if (! method_exists($forward[0], $forward[1])) {
1503
-                $msg = sprintf(
1504
-                    __('The class method %s for the %s forwarding route is in invalid.', 'event_espresso'),
1505
-                    $forward[1],
1506
-                    $route
1507
-                );
1508
-                EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1509
-                return false;
1510
-            }
1511
-        } else if (! function_exists($forward)) {
1512
-            $msg = sprintf(
1513
-                __('The function %s for the %s forwarding route is in invalid.', 'event_espresso'),
1514
-                $forward,
1515
-                $route
1516
-            );
1517
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1518
-            return false;
1519
-        }
1520
-        EE_Config::$_module_forward_map[$key][$route][absint($status)] = $forward;
1521
-        return true;
1522
-    }
1523
-
1524
-
1525
-
1526
-    /**
1527
-     *    get_forward - get forwarding route
1528
-     *
1529
-     * @access    public
1530
-     * @param    string  $route  - "pretty" public alias for module method
1531
-     * @param    integer $status - integer value corresponding  to status constant strings set in module parent class,
1532
-     *                           allows different forwards to be served based on status
1533
-     * @param    string  $key    - url param key indicating a route is being called
1534
-     * @return    string
1535
-     */
1536
-    public static function get_forward($route = null, $status = 0, $key = 'ee')
1537
-    {
1538
-        do_action('AHEE__EE_Config__get_forward__begin', $route, $status);
1539
-        if (isset(EE_Config::$_module_forward_map[$key][$route][$status])) {
1540
-            return apply_filters(
1541
-                'FHEE__EE_Config__get_forward',
1542
-                EE_Config::$_module_forward_map[$key][$route][$status],
1543
-                $route,
1544
-                $status
1545
-            );
1546
-        }
1547
-        return null;
1548
-    }
1549
-
1550
-
1551
-
1552
-    /**
1553
-     *    register_forward - allows modules to specify different view templates for different method routes and status
1554
-     *    results
1555
-     *
1556
-     * @access    public
1557
-     * @param    string  $route  - "pretty" public alias for module method
1558
-     * @param    integer $status - integer value corresponding  to status constant strings set in module parent class,
1559
-     *                           allows different views to be served based on status
1560
-     * @param    string  $view
1561
-     * @param    string  $key    - url param key indicating a route is being called
1562
-     * @return    bool
1563
-     */
1564
-    public static function register_view($route = null, $status = 0, $view = null, $key = 'ee')
1565
-    {
1566
-        do_action('AHEE__EE_Config__register_view__begin', $route, $status, $view);
1567
-        if (! isset(EE_Config::$_module_route_map[$key][$route]) || empty($route)) {
1568
-            $msg = sprintf(
1569
-                __('The module route %s for this view has not been registered.', 'event_espresso'),
1570
-                $route
1571
-            );
1572
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1573
-            return false;
1574
-        }
1575
-        if (! is_readable($view)) {
1576
-            $msg = sprintf(
1577
-                __(
1578
-                    'The %s view file could not be found or is not readable due to file permissions.',
1579
-                    'event_espresso'
1580
-                ),
1581
-                $view
1582
-            );
1583
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1584
-            return false;
1585
-        }
1586
-        EE_Config::$_module_view_map[$key][$route][absint($status)] = $view;
1587
-        return true;
1588
-    }
1589
-
1590
-
1591
-
1592
-    /**
1593
-     *    get_view - get view for route and status
1594
-     *
1595
-     * @access    public
1596
-     * @param    string  $route  - "pretty" public alias for module method
1597
-     * @param    integer $status - integer value corresponding  to status constant strings set in module parent class,
1598
-     *                           allows different views to be served based on status
1599
-     * @param    string  $key    - url param key indicating a route is being called
1600
-     * @return    string
1601
-     */
1602
-    public static function get_view($route = null, $status = 0, $key = 'ee')
1603
-    {
1604
-        do_action('AHEE__EE_Config__get_view__begin', $route, $status);
1605
-        if (isset(EE_Config::$_module_view_map[$key][$route][$status])) {
1606
-            return apply_filters(
1607
-                'FHEE__EE_Config__get_view',
1608
-                EE_Config::$_module_view_map[$key][$route][$status],
1609
-                $route,
1610
-                $status
1611
-            );
1612
-        }
1613
-        return null;
1614
-    }
1615
-
1616
-
1617
-
1618
-    public function update_addon_option_names()
1619
-    {
1620
-        update_option(EE_Config::ADDON_OPTION_NAMES, $this->_addon_option_names);
1621
-    }
1622
-
1623
-
1624
-
1625
-    public function shutdown()
1626
-    {
1627
-        $this->update_addon_option_names();
1628
-    }
1629
-
1630
-
1631
-}
1632
-
1633
-
1634
-
1635
-/**
1636
- * Base class used for config classes. These classes should generally not have
1637
- * magic functions in use, except we'll allow them to magically set and get stuff...
1638
- * basically, they should just be well-defined stdClasses
1639
- */
1640
-class EE_Config_Base
1641
-{
1642
-
1643
-    /**
1644
-     * Utility function for escaping the value of a property and returning.
1645
-     *
1646
-     * @param string $property property name (checks to see if exists).
1647
-     * @return mixed if a detected type found return the escaped value, otherwise just the raw value is returned.
1648
-     * @throws \EE_Error
1649
-     */
1650
-    public function get_pretty($property)
1651
-    {
1652
-        if (! property_exists($this, $property)) {
1653
-            throw new EE_Error(
1654
-                sprintf(
1655
-                    __(
1656
-                        '%1$s::get_pretty() has been called with the property %2$s which does not exist on the %1$s config class.',
1657
-                        'event_espresso'
1658
-                    ),
1659
-                    get_class($this),
1660
-                    $property
1661
-                )
1662
-            );
1663
-        }
1664
-        //just handling escaping of strings for now.
1665
-        if (is_string($this->{$property})) {
1666
-            return stripslashes($this->{$property});
1667
-        }
1668
-        return $this->{$property};
1669
-    }
1670
-
1671
-
1672
-
1673
-    public function populate()
1674
-    {
1675
-        //grab defaults via a new instance of this class.
1676
-        $class_name = get_class($this);
1677
-        $defaults = new $class_name;
1678
-        //loop through the properties for this class and see if they are set.  If they are NOT, then grab the
1679
-        //default from our $defaults object.
1680
-        foreach (get_object_vars($defaults) as $property => $value) {
1681
-            if ($this->{$property} === null) {
1682
-                $this->{$property} = $value;
1683
-            }
1684
-        }
1685
-        //cleanup
1686
-        unset($defaults);
1687
-    }
1688
-
1689
-
1690
-    /**
1691
-     *        @ override magic methods
1692
-     *        @ return void
1693
-     */
1694
-    //	public function __get($a) { return apply_filters('FHEE__'.get_class($this).'__get__'.$a,$this->{$a}); }
1695
-    //	public function __set($a,$b) { return apply_filters('FHEE__'.get_class($this).'__set__'.$a, $this->{$a} = $b ); }
1696
-    /**
1697
-     *        __isset
1698
-     *
1699
-     * @param $a
1700
-     * @return bool
1701
-     */
1702
-    public function __isset($a)
1703
-    {
1704
-        return false;
1705
-    }
1706
-
1707
-
1708
-
1709
-    /**
1710
-     *        __unset
1711
-     *
1712
-     * @param $a
1713
-     * @return bool
1714
-     */
1715
-    public function __unset($a)
1716
-    {
1717
-        return false;
1718
-    }
1719
-
1720
-
1721
-
1722
-    /**
1723
-     *        __clone
1724
-     */
1725
-    public function __clone()
1726
-    {
1727
-    }
1728
-
1729
-
1730
-
1731
-    /**
1732
-     *        __wakeup
1733
-     */
1734
-    public function __wakeup()
1735
-    {
1736
-    }
1737
-
1738
-
1739
-
1740
-    /**
1741
-     *        __destruct
1742
-     */
1743
-    public function __destruct()
1744
-    {
1745
-    }
1746
-}
1747
-
1748
-
1749
-
1750
-/**
1751
- * Class for defining what's in the EE_Config relating to registration settings
1752
- */
1753
-class EE_Core_Config extends EE_Config_Base
1754
-{
1755
-
1756
-    public $current_blog_id;
1757
-
1758
-    public $ee_ueip_optin;
1759
-
1760
-    public $ee_ueip_has_notified;
1761
-
1762
-    /**
1763
-     * Not to be confused with the 4 critical page variables (See
1764
-     * get_critical_pages_array()), this is just an array of wp posts that have EE
1765
-     * shortcodes in them. Keys are slugs, values are arrays with only 1 element: where the key is the shortcode
1766
-     * in the page, and the value is the page's ID. The key 'posts' is basically a duplicate of this same array.
1767
-     *
1768
-     * @var array
1769
-     */
1770
-    public $post_shortcodes;
1771
-
1772
-    public $module_route_map;
1773
-
1774
-    public $module_forward_map;
1775
-
1776
-    public $module_view_map;
1777
-
1778
-    /**
1779
-     * The next 4 vars are the IDs of critical EE pages.
1780
-     *
1781
-     * @var int
1782
-     */
1783
-    public $reg_page_id;
1784
-
1785
-    public $txn_page_id;
1786
-
1787
-    public $thank_you_page_id;
1788
-
1789
-    public $cancel_page_id;
1790
-
1791
-    /**
1792
-     * The next 4 vars are the URLs of critical EE pages.
1793
-     *
1794
-     * @var int
1795
-     */
1796
-    public $reg_page_url;
1797
-
1798
-    public $txn_page_url;
1799
-
1800
-    public $thank_you_page_url;
1801
-
1802
-    public $cancel_page_url;
1803
-
1804
-    /**
1805
-     * The next vars relate to the custom slugs for EE CPT routes
1806
-     */
1807
-    public $event_cpt_slug;
1808
-
1809
-
1810
-    /**
1811
-     * This caches the _ee_ueip_option in case this config is reset in the same
1812
-     * request across blog switches in a multisite context.
1813
-     * Avoids extra queries to the db for this option.
1814
-     *
1815
-     * @var bool
1816
-     */
1817
-    public static $ee_ueip_option;
1818
-
1819
-
1820
-
1821
-    /**
1822
-     *    class constructor
1823
-     *
1824
-     * @access    public
1825
-     */
1826
-    public function __construct()
1827
-    {
1828
-        // set default organization settings
1829
-        $this->current_blog_id = get_current_blog_id();
1830
-        $this->current_blog_id = $this->current_blog_id === null ? 1 : $this->current_blog_id;
1831
-        $this->ee_ueip_optin = $this->_get_main_ee_ueip_optin();
1832
-        $this->ee_ueip_has_notified = is_main_site() ? get_option('ee_ueip_has_notified', false) : true;
1833
-        $this->post_shortcodes = array();
1834
-        $this->module_route_map = array();
1835
-        $this->module_forward_map = array();
1836
-        $this->module_view_map = array();
1837
-        // critical EE page IDs
1838
-        $this->reg_page_id = 0;
1839
-        $this->txn_page_id = 0;
1840
-        $this->thank_you_page_id = 0;
1841
-        $this->cancel_page_id = 0;
1842
-        // critical EE page URLs
1843
-        $this->reg_page_url = '';
1844
-        $this->txn_page_url = '';
1845
-        $this->thank_you_page_url = '';
1846
-        $this->cancel_page_url = '';
1847
-        //cpt slugs
1848
-        $this->event_cpt_slug = __('events', 'event_espresso');
1849
-        //ueip constant check
1850
-        if (defined('EE_DISABLE_UXIP') && EE_DISABLE_UXIP) {
1851
-            $this->ee_ueip_optin = false;
1852
-            $this->ee_ueip_has_notified = true;
1853
-        }
1854
-    }
1855
-
1856
-
1857
-
1858
-    /**
1859
-     * @return array
1860
-     */
1861
-    public function get_critical_pages_array()
1862
-    {
1863
-        return array(
1864
-            $this->reg_page_id,
1865
-            $this->txn_page_id,
1866
-            $this->thank_you_page_id,
1867
-            $this->cancel_page_id,
1868
-        );
1869
-    }
1870
-
1871
-
1872
-
1873
-    /**
1874
-     * @return array
1875
-     */
1876
-    public function get_critical_pages_shortcodes_array()
1877
-    {
1878
-        return array(
1879
-            $this->reg_page_id       => 'ESPRESSO_CHECKOUT',
1880
-            $this->txn_page_id       => 'ESPRESSO_TXN_PAGE',
1881
-            $this->thank_you_page_id => 'ESPRESSO_THANK_YOU',
1882
-            $this->cancel_page_id    => 'ESPRESSO_CANCELLED',
1883
-        );
1884
-    }
1885
-
1886
-
1887
-
1888
-    /**
1889
-     *  gets/returns URL for EE reg_page
1890
-     *
1891
-     * @access    public
1892
-     * @return    string
1893
-     */
1894
-    public function reg_page_url()
1895
-    {
1896
-        if (! $this->reg_page_url) {
1897
-            $this->reg_page_url = add_query_arg(
1898
-                                      array('uts' => time()),
1899
-                                      get_permalink($this->reg_page_id)
1900
-                                  ) . '#checkout';
1901
-        }
1902
-        return $this->reg_page_url;
1903
-    }
1904
-
1905
-
1906
-
1907
-    /**
1908
-     *  gets/returns URL for EE txn_page
1909
-     *
1910
-     * @param array $query_args like what gets passed to
1911
-     *                          add_query_arg() as the first argument
1912
-     * @access    public
1913
-     * @return    string
1914
-     */
1915
-    public function txn_page_url($query_args = array())
1916
-    {
1917
-        if (! $this->txn_page_url) {
1918
-            $this->txn_page_url = get_permalink($this->txn_page_id);
1919
-        }
1920
-        if ($query_args) {
1921
-            return add_query_arg($query_args, $this->txn_page_url);
1922
-        } else {
1923
-            return $this->txn_page_url;
1924
-        }
1925
-    }
1926
-
1927
-
1928
-
1929
-    /**
1930
-     *  gets/returns URL for EE thank_you_page
1931
-     *
1932
-     * @param array $query_args like what gets passed to
1933
-     *                          add_query_arg() as the first argument
1934
-     * @access    public
1935
-     * @return    string
1936
-     */
1937
-    public function thank_you_page_url($query_args = array())
1938
-    {
1939
-        if (! $this->thank_you_page_url) {
1940
-            $this->thank_you_page_url = get_permalink($this->thank_you_page_id);
1941
-        }
1942
-        if ($query_args) {
1943
-            return add_query_arg($query_args, $this->thank_you_page_url);
1944
-        } else {
1945
-            return $this->thank_you_page_url;
1946
-        }
1947
-    }
1948
-
1949
-
1950
-
1951
-    /**
1952
-     *  gets/returns URL for EE cancel_page
1953
-     *
1954
-     * @access    public
1955
-     * @return    string
1956
-     */
1957
-    public function cancel_page_url()
1958
-    {
1959
-        if (! $this->cancel_page_url) {
1960
-            $this->cancel_page_url = get_permalink($this->cancel_page_id);
1961
-        }
1962
-        return $this->cancel_page_url;
1963
-    }
1964
-
1965
-
1966
-
1967
-    /**
1968
-     * Resets all critical page urls to their original state.  Used primarily by the __sleep() magic method currently.
1969
-     *
1970
-     * @since 4.7.5
1971
-     */
1972
-    protected function _reset_urls()
1973
-    {
1974
-        $this->reg_page_url = '';
1975
-        $this->txn_page_url = '';
1976
-        $this->cancel_page_url = '';
1977
-        $this->thank_you_page_url = '';
1978
-    }
1979
-
1980
-
1981
-
1982
-    /**
1983
-     * Used to return what the optin value is set for the EE User Experience Program.
1984
-     * This accounts for multisite and this value being requested for a subsite.  In multisite, the value is set
1985
-     * on the main site only.
1986
-     *
1987
-     * @return mixed|void
1988
-     */
1989
-    protected function _get_main_ee_ueip_optin()
1990
-    {
1991
-        //if this is the main site then we can just bypass our direct query.
1992
-        if (is_main_site()) {
1993
-            return get_option('ee_ueip_optin', false);
1994
-        }
1995
-        //is this already cached for this request?  If so use it.
1996
-        if ( ! empty(EE_Core_Config::$ee_ueip_option)) {
1997
-            return EE_Core_Config::$ee_ueip_option;
1998
-        }
1999
-        global $wpdb;
2000
-        $current_network_main_site = is_multisite() ? get_current_site() : null;
2001
-        $current_main_site_id = ! empty($current_network_main_site) ? $current_network_main_site->blog_id : 1;
2002
-        $option = 'ee_ueip_optin';
2003
-        //set correct table for query
2004
-        $table_name = $wpdb->get_blog_prefix($current_main_site_id) . 'options';
2005
-        //rather than getting blog option for the $current_main_site_id, we do a direct $wpdb query because
2006
-        //get_blog_option() does a switch_to_blog an that could cause infinite recursion because EE_Core_Config might be
2007
-        //re-constructed on the blog switch.  Note, we are still executing any core wp filters on this option retrieval.
2008
-        //this bit of code is basically a direct copy of get_option without any caching because we are NOT switched to the blog
2009
-        //for the purpose of caching.
2010
-        $pre = apply_filters('pre_option_' . $option, false, $option);
2011
-        if (false !== $pre) {
2012
-            EE_Core_Config::$ee_ueip_option = $pre;
2013
-            return EE_Core_Config::$ee_ueip_option;
2014
-        }
2015
-        $row = $wpdb->get_row($wpdb->prepare("SELECT option_value FROM $table_name WHERE option_name = %s LIMIT 1",
2016
-            $option));
2017
-        if (is_object($row)) {
2018
-            $value = $row->option_value;
2019
-        } else { //option does not exist so use default.
2020
-            return apply_filters('default_option_' . $option, false, $option);
2021
-        }
2022
-        EE_Core_Config::$ee_ueip_option = apply_filters('option_' . $option, maybe_unserialize($value), $option);
2023
-        return EE_Core_Config::$ee_ueip_option;
2024
-    }
2025
-
2026
-
2027
-
2028
-    /**
2029
-     * Currently used to ensure critical page urls have initial values saved to the db instead of any current set values
2030
-     * on the object.
2031
-     *
2032
-     * @return array
2033
-     */
2034
-    public function __sleep()
2035
-    {
2036
-        //reset all url properties
2037
-        $this->_reset_urls();
2038
-        //return what to save to db
2039
-        return array_keys(get_object_vars($this));
2040
-    }
2041
-
2042
-}
2043
-
2044
-
2045
-
2046
-/**
2047
- * Config class for storing info on the Organization
2048
- */
2049
-class EE_Organization_Config extends EE_Config_Base
2050
-{
2051
-
2052
-    /**
2053
-     * @var string $name
2054
-     * eg EE4.1
2055
-     */
2056
-    public $name;
2057
-
2058
-    /**
2059
-     * @var string $address_1
2060
-     * eg 123 Onna Road
2061
-     */
2062
-    public $address_1;
2063
-
2064
-    /**
2065
-     * @var string $address_2
2066
-     * eg PO Box 123
2067
-     */
2068
-    public $address_2;
2069
-
2070
-    /**
2071
-     * @var string $city
2072
-     * eg Inna City
2073
-     */
2074
-    public $city;
2075
-
2076
-    /**
2077
-     * @var int $STA_ID
2078
-     * eg 4
2079
-     */
2080
-    public $STA_ID;
2081
-
2082
-    /**
2083
-     * @var string $CNT_ISO
2084
-     * eg US
2085
-     */
2086
-    public $CNT_ISO;
2087
-
2088
-    /**
2089
-     * @var string $zip
2090
-     * eg 12345  or V1A 2B3
2091
-     */
2092
-    public $zip;
2093
-
2094
-    /**
2095
-     * @var string $email
2096
-     * eg [email protected]
2097
-     */
2098
-    public $email;
2099
-
2100
-
2101
-    /**
2102
-     * @var string $phone
2103
-     * eg. 111-111-1111
2104
-     */
2105
-    public $phone;
2106
-
2107
-
2108
-    /**
2109
-     * @var string $vat
2110
-     * VAT/Tax Number
2111
-     */
2112
-    public $vat;
2113
-
2114
-    /**
2115
-     * @var string $logo_url
2116
-     * eg http://www.somedomain.com/wp-content/uploads/kittehs.jpg
2117
-     */
2118
-    public $logo_url;
2119
-
2120
-
2121
-    /**
2122
-     * The below are all various properties for holding links to organization social network profiles
2123
-     *
2124
-     * @var string
2125
-     */
2126
-    /**
2127
-     * facebook (facebook.com/profile.name)
2128
-     *
2129
-     * @var string
2130
-     */
2131
-    public $facebook;
2132
-
2133
-
2134
-    /**
2135
-     * twitter (twitter.com/twitter_handle)
2136
-     *
2137
-     * @var string
2138
-     */
2139
-    public $twitter;
2140
-
2141
-
2142
-    /**
2143
-     * linkedin (linkedin.com/in/profile_name)
2144
-     *
2145
-     * @var string
2146
-     */
2147
-    public $linkedin;
2148
-
2149
-
2150
-    /**
2151
-     * pinterest (www.pinterest.com/profile_name)
2152
-     *
2153
-     * @var string
2154
-     */
2155
-    public $pinterest;
2156
-
2157
-
2158
-    /**
2159
-     * google+ (google.com/+profileName)
2160
-     *
2161
-     * @var string
2162
-     */
2163
-    public $google;
2164
-
2165
-
2166
-    /**
2167
-     * instagram (instagram.com/handle)
2168
-     *
2169
-     * @var string
2170
-     */
2171
-    public $instagram;
2172
-
2173
-
2174
-
2175
-    /**
2176
-     *    class constructor
2177
-     *
2178
-     * @access    public
2179
-     */
2180
-    public function __construct()
2181
-    {
2182
-        // set default organization settings
2183
-        $this->name = get_bloginfo('name');
2184
-        $this->address_1 = '123 Onna Road';
2185
-        $this->address_2 = 'PO Box 123';
2186
-        $this->city = 'Inna City';
2187
-        $this->STA_ID = 4;
2188
-        $this->CNT_ISO = 'US';
2189
-        $this->zip = '12345';
2190
-        $this->email = get_bloginfo('admin_email');
2191
-        $this->phone = '';
2192
-        $this->vat = '123456789';
2193
-        $this->logo_url = '';
2194
-        $this->facebook = '';
2195
-        $this->twitter = '';
2196
-        $this->linkedin = '';
2197
-        $this->pinterest = '';
2198
-        $this->google = '';
2199
-        $this->instagram = '';
2200
-    }
2201
-
2202
-}
2203
-
2204
-
2205
-
2206
-/**
2207
- * Class for defining what's in the EE_Config relating to currency
2208
- */
2209
-class EE_Currency_Config extends EE_Config_Base
2210
-{
2211
-
2212
-    /**
2213
-     * @var string $code
2214
-     * eg 'US'
2215
-     */
2216
-    public $code;
2217
-
2218
-    /**
2219
-     * @var string $name
2220
-     * eg 'Dollar'
2221
-     */
2222
-    public $name;
2223
-
2224
-    /**
2225
-     * plural name
2226
-     *
2227
-     * @var string $plural
2228
-     * eg 'Dollars'
2229
-     */
2230
-    public $plural;
2231
-
2232
-    /**
2233
-     * currency sign
2234
-     *
2235
-     * @var string $sign
2236
-     * eg '$'
2237
-     */
2238
-    public $sign;
2239
-
2240
-    /**
2241
-     * Whether the currency sign should come before the number or not
2242
-     *
2243
-     * @var boolean $sign_b4
2244
-     */
2245
-    public $sign_b4;
2246
-
2247
-    /**
2248
-     * How many digits should come after the decimal place
2249
-     *
2250
-     * @var int $dec_plc
2251
-     */
2252
-    public $dec_plc;
2253
-
2254
-    /**
2255
-     * Symbol to use for decimal mark
2256
-     *
2257
-     * @var string $dec_mrk
2258
-     * eg '.'
2259
-     */
2260
-    public $dec_mrk;
2261
-
2262
-    /**
2263
-     * Symbol to use for thousands
2264
-     *
2265
-     * @var string $thsnds
2266
-     * eg ','
2267
-     */
2268
-    public $thsnds;
2269
-
2270
-
2271
-
2272
-    /**
2273
-     *    class constructor
2274
-     *
2275
-     * @access    public
2276
-     * @param string $CNT_ISO
2277
-     * @throws \EE_Error
2278
-     */
2279
-    public function __construct($CNT_ISO = '')
2280
-    {
2281
-        /** @var \EventEspresso\core\services\database\TableAnalysis $table_analysis */
2282
-        $table_analysis = EE_Registry::instance()->create('TableAnalysis', array(), true);
2283
-        // get country code from organization settings or use default
2284
-        $ORG_CNT = isset(EE_Registry::instance()->CFG->organization)
2285
-                   && EE_Registry::instance()->CFG->organization instanceof EE_Organization_Config
2286
-            ? EE_Registry::instance()->CFG->organization->CNT_ISO
2287
-            : '';
2288
-        // but override if requested
2289
-        $CNT_ISO = ! empty($CNT_ISO) ? $CNT_ISO : $ORG_CNT;
2290
-        // so if that all went well, and we are not in M-Mode (cuz you can't query the db in M-Mode) and double-check the countries table exists
2291
-        if (
2292
-            ! empty($CNT_ISO)
2293
-            && EE_Maintenance_Mode::instance()->models_can_query()
2294
-            && $table_analysis->tableExists(EE_Registry::instance()->load_model('Country')->table())
2295
-        ) {
2296
-            // retrieve the country settings from the db, just in case they have been customized
2297
-            $country = EE_Registry::instance()->load_model('Country')->get_one_by_ID($CNT_ISO);
2298
-            if ($country instanceof EE_Country) {
2299
-                $this->code = $country->currency_code();    // currency code: USD, CAD, EUR
2300
-                $this->name = $country->currency_name_single();    // Dollar
2301
-                $this->plural = $country->currency_name_plural();    // Dollars
2302
-                $this->sign = $country->currency_sign();            // currency sign: $
2303
-                $this->sign_b4 = $country->currency_sign_before();        // currency sign before or after: $TRUE  or  FALSE$
2304
-                $this->dec_plc = $country->currency_decimal_places();    // decimal places: 2 = 0.00  3 = 0.000
2305
-                $this->dec_mrk = $country->currency_decimal_mark();    // decimal mark: (comma) ',' = 0,01   or (decimal) '.' = 0.01
2306
-                $this->thsnds = $country->currency_thousands_separator();    // thousands separator: (comma) ',' = 1,000   or (decimal) '.' = 1.000
2307
-            }
2308
-        }
2309
-        // fallback to hardcoded defaults, in case the above failed
2310
-        if (empty($this->code)) {
2311
-            // set default currency settings
2312
-            $this->code = 'USD';    // currency code: USD, CAD, EUR
2313
-            $this->name = __('Dollar', 'event_espresso');    // Dollar
2314
-            $this->plural = __('Dollars', 'event_espresso');    // Dollars
2315
-            $this->sign = '$';    // currency sign: $
2316
-            $this->sign_b4 = true;    // currency sign before or after: $TRUE  or  FALSE$
2317
-            $this->dec_plc = 2;    // decimal places: 2 = 0.00  3 = 0.000
2318
-            $this->dec_mrk = '.';    // decimal mark: (comma) ',' = 0,01   or (decimal) '.' = 0.01
2319
-            $this->thsnds = ',';    // thousands separator: (comma) ',' = 1,000   or (decimal) '.' = 1.000
2320
-        }
2321
-    }
2322 1631
 }
2323 1632
 
2324 1633
 
2325 1634
 
2326 1635
 /**
2327
- * Class for defining what's in the EE_Config relating to registration settings
1636
+ * Base class used for config classes. These classes should generally not have
1637
+ * magic functions in use, except we'll allow them to magically set and get stuff...
1638
+ * basically, they should just be well-defined stdClasses
2328 1639
  */
2329
-class EE_Registration_Config extends EE_Config_Base
1640
+class EE_Config_Base
2330 1641
 {
2331 1642
 
2332
-    /**
2333
-     * Default registration status
2334
-     *
2335
-     * @var string $default_STS_ID
2336
-     * eg 'RPP'
2337
-     */
2338
-    public $default_STS_ID;
2339
-
2340
-    /**
2341
-     * level of validation to apply to email addresses
2342
-     *
2343
-     * @var string $email_validation_level
2344
-     * options: 'basic', 'wp_default', 'i18n', 'i18n_dns'
2345
-     */
2346
-    public $email_validation_level;
2347
-
2348
-    /**
2349
-     *    whether or not to show alternate payment options during the reg process if payment status is pending
2350
-     *
2351
-     * @var boolean $show_pending_payment_options
2352
-     */
2353
-    public $show_pending_payment_options;
2354
-
2355
-    /**
2356
-     * Whether to skip the registration confirmation page
2357
-     *
2358
-     * @var boolean $skip_reg_confirmation
2359
-     */
2360
-    public $skip_reg_confirmation;
2361
-
2362
-    /**
2363
-     * an array of SPCO reg steps where:
2364
-     *        the keys denotes the reg step order
2365
-     *        each element consists of an array with the following elements:
2366
-     *            "file_path" => the file path to the EE_SPCO_Reg_Step class
2367
-     *            "class_name" => the specific EE_SPCO_Reg_Step child class name
2368
-     *            "slug" => the URL param used to trigger the reg step
2369
-     *
2370
-     * @var array $reg_steps
2371
-     */
2372
-    public $reg_steps;
2373
-
2374
-    /**
2375
-     * Whether registration confirmation should be the last page of SPCO
2376
-     *
2377
-     * @var boolean $reg_confirmation_last
2378
-     */
2379
-    public $reg_confirmation_last;
2380
-
2381
-    /**
2382
-     * Whether or not to enable the EE Bot Trap
2383
-     *
2384
-     * @var boolean $use_bot_trap
2385
-     */
2386
-    public $use_bot_trap;
2387
-
2388
-    /**
2389
-     * Whether or not to encrypt some data sent by the EE Bot Trap
2390
-     *
2391
-     * @var boolean $use_encryption
2392
-     */
2393
-    public $use_encryption;
2394
-
2395
-    /**
2396
-     * Whether or not to use ReCaptcha
2397
-     *
2398
-     * @var boolean $use_captcha
2399
-     */
2400
-    public $use_captcha;
2401
-
2402
-    /**
2403
-     * ReCaptcha Theme
2404
-     *
2405
-     * @var string $recaptcha_theme
2406
-     *    options: 'dark    ', 'light'
2407
-     */
2408
-    public $recaptcha_theme;
1643
+	/**
1644
+	 * Utility function for escaping the value of a property and returning.
1645
+	 *
1646
+	 * @param string $property property name (checks to see if exists).
1647
+	 * @return mixed if a detected type found return the escaped value, otherwise just the raw value is returned.
1648
+	 * @throws \EE_Error
1649
+	 */
1650
+	public function get_pretty($property)
1651
+	{
1652
+		if (! property_exists($this, $property)) {
1653
+			throw new EE_Error(
1654
+				sprintf(
1655
+					__(
1656
+						'%1$s::get_pretty() has been called with the property %2$s which does not exist on the %1$s config class.',
1657
+						'event_espresso'
1658
+					),
1659
+					get_class($this),
1660
+					$property
1661
+				)
1662
+			);
1663
+		}
1664
+		//just handling escaping of strings for now.
1665
+		if (is_string($this->{$property})) {
1666
+			return stripslashes($this->{$property});
1667
+		}
1668
+		return $this->{$property};
1669
+	}
1670
+
1671
+
1672
+
1673
+	public function populate()
1674
+	{
1675
+		//grab defaults via a new instance of this class.
1676
+		$class_name = get_class($this);
1677
+		$defaults = new $class_name;
1678
+		//loop through the properties for this class and see if they are set.  If they are NOT, then grab the
1679
+		//default from our $defaults object.
1680
+		foreach (get_object_vars($defaults) as $property => $value) {
1681
+			if ($this->{$property} === null) {
1682
+				$this->{$property} = $value;
1683
+			}
1684
+		}
1685
+		//cleanup
1686
+		unset($defaults);
1687
+	}
1688
+
1689
+
1690
+	/**
1691
+	 *        @ override magic methods
1692
+	 *        @ return void
1693
+	 */
1694
+	//	public function __get($a) { return apply_filters('FHEE__'.get_class($this).'__get__'.$a,$this->{$a}); }
1695
+	//	public function __set($a,$b) { return apply_filters('FHEE__'.get_class($this).'__set__'.$a, $this->{$a} = $b ); }
1696
+	/**
1697
+	 *        __isset
1698
+	 *
1699
+	 * @param $a
1700
+	 * @return bool
1701
+	 */
1702
+	public function __isset($a)
1703
+	{
1704
+		return false;
1705
+	}
1706
+
1707
+
1708
+
1709
+	/**
1710
+	 *        __unset
1711
+	 *
1712
+	 * @param $a
1713
+	 * @return bool
1714
+	 */
1715
+	public function __unset($a)
1716
+	{
1717
+		return false;
1718
+	}
1719
+
1720
+
1721
+
1722
+	/**
1723
+	 *        __clone
1724
+	 */
1725
+	public function __clone()
1726
+	{
1727
+	}
1728
+
1729
+
1730
+
1731
+	/**
1732
+	 *        __wakeup
1733
+	 */
1734
+	public function __wakeup()
1735
+	{
1736
+	}
1737
+
1738
+
1739
+
1740
+	/**
1741
+	 *        __destruct
1742
+	 */
1743
+	public function __destruct()
1744
+	{
1745
+	}
1746
+}
2409 1747
 
2410
-    /**
2411
-     * ReCaptcha Type
2412
-     *
2413
-     * @var string $recaptcha_type
2414
-     *    options: 'audio', 'image'
2415
-     */
2416
-    public $recaptcha_type;
2417 1748
 
2418
-    /**
2419
-     * ReCaptcha language
2420
-     *
2421
-     * @var string $recaptcha_language
2422
-     * eg 'en'
2423
-     */
2424
-    public $recaptcha_language;
2425 1749
 
2426
-    /**
2427
-     * ReCaptcha public key
2428
-     *
2429
-     * @var string $recaptcha_publickey
2430
-     */
2431
-    public $recaptcha_publickey;
1750
+/**
1751
+ * Class for defining what's in the EE_Config relating to registration settings
1752
+ */
1753
+class EE_Core_Config extends EE_Config_Base
1754
+{
2432 1755
 
2433
-    /**
2434
-     * ReCaptcha private key
2435
-     *
2436
-     * @var string $recaptcha_privatekey
2437
-     */
2438
-    public $recaptcha_privatekey;
1756
+	public $current_blog_id;
1757
+
1758
+	public $ee_ueip_optin;
1759
+
1760
+	public $ee_ueip_has_notified;
1761
+
1762
+	/**
1763
+	 * Not to be confused with the 4 critical page variables (See
1764
+	 * get_critical_pages_array()), this is just an array of wp posts that have EE
1765
+	 * shortcodes in them. Keys are slugs, values are arrays with only 1 element: where the key is the shortcode
1766
+	 * in the page, and the value is the page's ID. The key 'posts' is basically a duplicate of this same array.
1767
+	 *
1768
+	 * @var array
1769
+	 */
1770
+	public $post_shortcodes;
1771
+
1772
+	public $module_route_map;
1773
+
1774
+	public $module_forward_map;
1775
+
1776
+	public $module_view_map;
1777
+
1778
+	/**
1779
+	 * The next 4 vars are the IDs of critical EE pages.
1780
+	 *
1781
+	 * @var int
1782
+	 */
1783
+	public $reg_page_id;
1784
+
1785
+	public $txn_page_id;
1786
+
1787
+	public $thank_you_page_id;
1788
+
1789
+	public $cancel_page_id;
1790
+
1791
+	/**
1792
+	 * The next 4 vars are the URLs of critical EE pages.
1793
+	 *
1794
+	 * @var int
1795
+	 */
1796
+	public $reg_page_url;
1797
+
1798
+	public $txn_page_url;
1799
+
1800
+	public $thank_you_page_url;
1801
+
1802
+	public $cancel_page_url;
1803
+
1804
+	/**
1805
+	 * The next vars relate to the custom slugs for EE CPT routes
1806
+	 */
1807
+	public $event_cpt_slug;
1808
+
1809
+
1810
+	/**
1811
+	 * This caches the _ee_ueip_option in case this config is reset in the same
1812
+	 * request across blog switches in a multisite context.
1813
+	 * Avoids extra queries to the db for this option.
1814
+	 *
1815
+	 * @var bool
1816
+	 */
1817
+	public static $ee_ueip_option;
1818
+
1819
+
1820
+
1821
+	/**
1822
+	 *    class constructor
1823
+	 *
1824
+	 * @access    public
1825
+	 */
1826
+	public function __construct()
1827
+	{
1828
+		// set default organization settings
1829
+		$this->current_blog_id = get_current_blog_id();
1830
+		$this->current_blog_id = $this->current_blog_id === null ? 1 : $this->current_blog_id;
1831
+		$this->ee_ueip_optin = $this->_get_main_ee_ueip_optin();
1832
+		$this->ee_ueip_has_notified = is_main_site() ? get_option('ee_ueip_has_notified', false) : true;
1833
+		$this->post_shortcodes = array();
1834
+		$this->module_route_map = array();
1835
+		$this->module_forward_map = array();
1836
+		$this->module_view_map = array();
1837
+		// critical EE page IDs
1838
+		$this->reg_page_id = 0;
1839
+		$this->txn_page_id = 0;
1840
+		$this->thank_you_page_id = 0;
1841
+		$this->cancel_page_id = 0;
1842
+		// critical EE page URLs
1843
+		$this->reg_page_url = '';
1844
+		$this->txn_page_url = '';
1845
+		$this->thank_you_page_url = '';
1846
+		$this->cancel_page_url = '';
1847
+		//cpt slugs
1848
+		$this->event_cpt_slug = __('events', 'event_espresso');
1849
+		//ueip constant check
1850
+		if (defined('EE_DISABLE_UXIP') && EE_DISABLE_UXIP) {
1851
+			$this->ee_ueip_optin = false;
1852
+			$this->ee_ueip_has_notified = true;
1853
+		}
1854
+	}
1855
+
1856
+
1857
+
1858
+	/**
1859
+	 * @return array
1860
+	 */
1861
+	public function get_critical_pages_array()
1862
+	{
1863
+		return array(
1864
+			$this->reg_page_id,
1865
+			$this->txn_page_id,
1866
+			$this->thank_you_page_id,
1867
+			$this->cancel_page_id,
1868
+		);
1869
+	}
1870
+
1871
+
1872
+
1873
+	/**
1874
+	 * @return array
1875
+	 */
1876
+	public function get_critical_pages_shortcodes_array()
1877
+	{
1878
+		return array(
1879
+			$this->reg_page_id       => 'ESPRESSO_CHECKOUT',
1880
+			$this->txn_page_id       => 'ESPRESSO_TXN_PAGE',
1881
+			$this->thank_you_page_id => 'ESPRESSO_THANK_YOU',
1882
+			$this->cancel_page_id    => 'ESPRESSO_CANCELLED',
1883
+		);
1884
+	}
1885
+
1886
+
1887
+
1888
+	/**
1889
+	 *  gets/returns URL for EE reg_page
1890
+	 *
1891
+	 * @access    public
1892
+	 * @return    string
1893
+	 */
1894
+	public function reg_page_url()
1895
+	{
1896
+		if (! $this->reg_page_url) {
1897
+			$this->reg_page_url = add_query_arg(
1898
+									  array('uts' => time()),
1899
+									  get_permalink($this->reg_page_id)
1900
+								  ) . '#checkout';
1901
+		}
1902
+		return $this->reg_page_url;
1903
+	}
1904
+
1905
+
1906
+
1907
+	/**
1908
+	 *  gets/returns URL for EE txn_page
1909
+	 *
1910
+	 * @param array $query_args like what gets passed to
1911
+	 *                          add_query_arg() as the first argument
1912
+	 * @access    public
1913
+	 * @return    string
1914
+	 */
1915
+	public function txn_page_url($query_args = array())
1916
+	{
1917
+		if (! $this->txn_page_url) {
1918
+			$this->txn_page_url = get_permalink($this->txn_page_id);
1919
+		}
1920
+		if ($query_args) {
1921
+			return add_query_arg($query_args, $this->txn_page_url);
1922
+		} else {
1923
+			return $this->txn_page_url;
1924
+		}
1925
+	}
1926
+
1927
+
1928
+
1929
+	/**
1930
+	 *  gets/returns URL for EE thank_you_page
1931
+	 *
1932
+	 * @param array $query_args like what gets passed to
1933
+	 *                          add_query_arg() as the first argument
1934
+	 * @access    public
1935
+	 * @return    string
1936
+	 */
1937
+	public function thank_you_page_url($query_args = array())
1938
+	{
1939
+		if (! $this->thank_you_page_url) {
1940
+			$this->thank_you_page_url = get_permalink($this->thank_you_page_id);
1941
+		}
1942
+		if ($query_args) {
1943
+			return add_query_arg($query_args, $this->thank_you_page_url);
1944
+		} else {
1945
+			return $this->thank_you_page_url;
1946
+		}
1947
+	}
1948
+
1949
+
1950
+
1951
+	/**
1952
+	 *  gets/returns URL for EE cancel_page
1953
+	 *
1954
+	 * @access    public
1955
+	 * @return    string
1956
+	 */
1957
+	public function cancel_page_url()
1958
+	{
1959
+		if (! $this->cancel_page_url) {
1960
+			$this->cancel_page_url = get_permalink($this->cancel_page_id);
1961
+		}
1962
+		return $this->cancel_page_url;
1963
+	}
1964
+
1965
+
1966
+
1967
+	/**
1968
+	 * Resets all critical page urls to their original state.  Used primarily by the __sleep() magic method currently.
1969
+	 *
1970
+	 * @since 4.7.5
1971
+	 */
1972
+	protected function _reset_urls()
1973
+	{
1974
+		$this->reg_page_url = '';
1975
+		$this->txn_page_url = '';
1976
+		$this->cancel_page_url = '';
1977
+		$this->thank_you_page_url = '';
1978
+	}
1979
+
1980
+
1981
+
1982
+	/**
1983
+	 * Used to return what the optin value is set for the EE User Experience Program.
1984
+	 * This accounts for multisite and this value being requested for a subsite.  In multisite, the value is set
1985
+	 * on the main site only.
1986
+	 *
1987
+	 * @return mixed|void
1988
+	 */
1989
+	protected function _get_main_ee_ueip_optin()
1990
+	{
1991
+		//if this is the main site then we can just bypass our direct query.
1992
+		if (is_main_site()) {
1993
+			return get_option('ee_ueip_optin', false);
1994
+		}
1995
+		//is this already cached for this request?  If so use it.
1996
+		if ( ! empty(EE_Core_Config::$ee_ueip_option)) {
1997
+			return EE_Core_Config::$ee_ueip_option;
1998
+		}
1999
+		global $wpdb;
2000
+		$current_network_main_site = is_multisite() ? get_current_site() : null;
2001
+		$current_main_site_id = ! empty($current_network_main_site) ? $current_network_main_site->blog_id : 1;
2002
+		$option = 'ee_ueip_optin';
2003
+		//set correct table for query
2004
+		$table_name = $wpdb->get_blog_prefix($current_main_site_id) . 'options';
2005
+		//rather than getting blog option for the $current_main_site_id, we do a direct $wpdb query because
2006
+		//get_blog_option() does a switch_to_blog an that could cause infinite recursion because EE_Core_Config might be
2007
+		//re-constructed on the blog switch.  Note, we are still executing any core wp filters on this option retrieval.
2008
+		//this bit of code is basically a direct copy of get_option without any caching because we are NOT switched to the blog
2009
+		//for the purpose of caching.
2010
+		$pre = apply_filters('pre_option_' . $option, false, $option);
2011
+		if (false !== $pre) {
2012
+			EE_Core_Config::$ee_ueip_option = $pre;
2013
+			return EE_Core_Config::$ee_ueip_option;
2014
+		}
2015
+		$row = $wpdb->get_row($wpdb->prepare("SELECT option_value FROM $table_name WHERE option_name = %s LIMIT 1",
2016
+			$option));
2017
+		if (is_object($row)) {
2018
+			$value = $row->option_value;
2019
+		} else { //option does not exist so use default.
2020
+			return apply_filters('default_option_' . $option, false, $option);
2021
+		}
2022
+		EE_Core_Config::$ee_ueip_option = apply_filters('option_' . $option, maybe_unserialize($value), $option);
2023
+		return EE_Core_Config::$ee_ueip_option;
2024
+	}
2025
+
2026
+
2027
+
2028
+	/**
2029
+	 * Currently used to ensure critical page urls have initial values saved to the db instead of any current set values
2030
+	 * on the object.
2031
+	 *
2032
+	 * @return array
2033
+	 */
2034
+	public function __sleep()
2035
+	{
2036
+		//reset all url properties
2037
+		$this->_reset_urls();
2038
+		//return what to save to db
2039
+		return array_keys(get_object_vars($this));
2040
+	}
2439 2041
 
2440
-    /**
2441
-     * ReCaptcha width
2442
-     *
2443
-     * @var int $recaptcha_width
2444
-     * @deprecated
2445
-     */
2446
-    public $recaptcha_width;
2042
+}
2447 2043
 
2448
-    /**
2449
-     * Whether or not invalid attempts to directly access the registration checkout page should be tracked.
2450
-     *
2451
-     * @var boolean $track_invalid_checkout_access
2452
-     */
2453
-    protected $track_invalid_checkout_access = true;
2454 2044
 
2455 2045
 
2046
+/**
2047
+ * Config class for storing info on the Organization
2048
+ */
2049
+class EE_Organization_Config extends EE_Config_Base
2050
+{
2456 2051
 
2457
-    /**
2458
-     *    class constructor
2459
-     *
2460
-     * @access    public
2461
-     */
2462
-    public function __construct()
2463
-    {
2464
-        // set default registration settings
2465
-        $this->default_STS_ID = EEM_Registration::status_id_pending_payment;
2466
-        $this->email_validation_level = 'wp_default';
2467
-        $this->show_pending_payment_options = true;
2468
-        $this->skip_reg_confirmation = false;
2469
-        $this->reg_steps = array();
2470
-        $this->reg_confirmation_last = false;
2471
-        $this->use_bot_trap = true;
2472
-        $this->use_encryption = true;
2473
-        $this->use_captcha = false;
2474
-        $this->recaptcha_theme = 'light';
2475
-        $this->recaptcha_type = 'image';
2476
-        $this->recaptcha_language = 'en';
2477
-        $this->recaptcha_publickey = null;
2478
-        $this->recaptcha_privatekey = null;
2479
-        $this->recaptcha_width = 500;
2480
-    }
2481
-
2482
-
2483
-
2484
-    /**
2485
-     * This is called by the config loader and hooks are initialized AFTER the config has been populated.
2486
-     *
2487
-     * @since 4.8.8.rc.019
2488
-     */
2489
-    public function do_hooks()
2490
-    {
2491
-        add_action('AHEE__EE_Config___load_core_config__end', array($this, 'set_default_reg_status_on_EEM_Event'));
2492
-    }
2052
+	/**
2053
+	 * @var string $name
2054
+	 * eg EE4.1
2055
+	 */
2056
+	public $name;
2057
+
2058
+	/**
2059
+	 * @var string $address_1
2060
+	 * eg 123 Onna Road
2061
+	 */
2062
+	public $address_1;
2063
+
2064
+	/**
2065
+	 * @var string $address_2
2066
+	 * eg PO Box 123
2067
+	 */
2068
+	public $address_2;
2069
+
2070
+	/**
2071
+	 * @var string $city
2072
+	 * eg Inna City
2073
+	 */
2074
+	public $city;
2075
+
2076
+	/**
2077
+	 * @var int $STA_ID
2078
+	 * eg 4
2079
+	 */
2080
+	public $STA_ID;
2081
+
2082
+	/**
2083
+	 * @var string $CNT_ISO
2084
+	 * eg US
2085
+	 */
2086
+	public $CNT_ISO;
2087
+
2088
+	/**
2089
+	 * @var string $zip
2090
+	 * eg 12345  or V1A 2B3
2091
+	 */
2092
+	public $zip;
2093
+
2094
+	/**
2095
+	 * @var string $email
2096
+	 * eg [email protected]
2097
+	 */
2098
+	public $email;
2099
+
2100
+
2101
+	/**
2102
+	 * @var string $phone
2103
+	 * eg. 111-111-1111
2104
+	 */
2105
+	public $phone;
2106
+
2107
+
2108
+	/**
2109
+	 * @var string $vat
2110
+	 * VAT/Tax Number
2111
+	 */
2112
+	public $vat;
2113
+
2114
+	/**
2115
+	 * @var string $logo_url
2116
+	 * eg http://www.somedomain.com/wp-content/uploads/kittehs.jpg
2117
+	 */
2118
+	public $logo_url;
2119
+
2120
+
2121
+	/**
2122
+	 * The below are all various properties for holding links to organization social network profiles
2123
+	 *
2124
+	 * @var string
2125
+	 */
2126
+	/**
2127
+	 * facebook (facebook.com/profile.name)
2128
+	 *
2129
+	 * @var string
2130
+	 */
2131
+	public $facebook;
2132
+
2133
+
2134
+	/**
2135
+	 * twitter (twitter.com/twitter_handle)
2136
+	 *
2137
+	 * @var string
2138
+	 */
2139
+	public $twitter;
2140
+
2141
+
2142
+	/**
2143
+	 * linkedin (linkedin.com/in/profile_name)
2144
+	 *
2145
+	 * @var string
2146
+	 */
2147
+	public $linkedin;
2148
+
2149
+
2150
+	/**
2151
+	 * pinterest (www.pinterest.com/profile_name)
2152
+	 *
2153
+	 * @var string
2154
+	 */
2155
+	public $pinterest;
2156
+
2157
+
2158
+	/**
2159
+	 * google+ (google.com/+profileName)
2160
+	 *
2161
+	 * @var string
2162
+	 */
2163
+	public $google;
2164
+
2165
+
2166
+	/**
2167
+	 * instagram (instagram.com/handle)
2168
+	 *
2169
+	 * @var string
2170
+	 */
2171
+	public $instagram;
2172
+
2173
+
2174
+
2175
+	/**
2176
+	 *    class constructor
2177
+	 *
2178
+	 * @access    public
2179
+	 */
2180
+	public function __construct()
2181
+	{
2182
+		// set default organization settings
2183
+		$this->name = get_bloginfo('name');
2184
+		$this->address_1 = '123 Onna Road';
2185
+		$this->address_2 = 'PO Box 123';
2186
+		$this->city = 'Inna City';
2187
+		$this->STA_ID = 4;
2188
+		$this->CNT_ISO = 'US';
2189
+		$this->zip = '12345';
2190
+		$this->email = get_bloginfo('admin_email');
2191
+		$this->phone = '';
2192
+		$this->vat = '123456789';
2193
+		$this->logo_url = '';
2194
+		$this->facebook = '';
2195
+		$this->twitter = '';
2196
+		$this->linkedin = '';
2197
+		$this->pinterest = '';
2198
+		$this->google = '';
2199
+		$this->instagram = '';
2200
+	}
2493 2201
 
2202
+}
2494 2203
 
2495 2204
 
2496
-    /**
2497
-     * @return void
2498
-     */
2499
-    public function set_default_reg_status_on_EEM_Event()
2500
-    {
2501
-        EEM_Event::set_default_reg_status($this->default_STS_ID);
2502
-    }
2503 2205
 
2206
+/**
2207
+ * Class for defining what's in the EE_Config relating to currency
2208
+ */
2209
+class EE_Currency_Config extends EE_Config_Base
2210
+{
2504 2211
 
2212
+	/**
2213
+	 * @var string $code
2214
+	 * eg 'US'
2215
+	 */
2216
+	public $code;
2217
+
2218
+	/**
2219
+	 * @var string $name
2220
+	 * eg 'Dollar'
2221
+	 */
2222
+	public $name;
2223
+
2224
+	/**
2225
+	 * plural name
2226
+	 *
2227
+	 * @var string $plural
2228
+	 * eg 'Dollars'
2229
+	 */
2230
+	public $plural;
2231
+
2232
+	/**
2233
+	 * currency sign
2234
+	 *
2235
+	 * @var string $sign
2236
+	 * eg '$'
2237
+	 */
2238
+	public $sign;
2239
+
2240
+	/**
2241
+	 * Whether the currency sign should come before the number or not
2242
+	 *
2243
+	 * @var boolean $sign_b4
2244
+	 */
2245
+	public $sign_b4;
2246
+
2247
+	/**
2248
+	 * How many digits should come after the decimal place
2249
+	 *
2250
+	 * @var int $dec_plc
2251
+	 */
2252
+	public $dec_plc;
2253
+
2254
+	/**
2255
+	 * Symbol to use for decimal mark
2256
+	 *
2257
+	 * @var string $dec_mrk
2258
+	 * eg '.'
2259
+	 */
2260
+	public $dec_mrk;
2261
+
2262
+	/**
2263
+	 * Symbol to use for thousands
2264
+	 *
2265
+	 * @var string $thsnds
2266
+	 * eg ','
2267
+	 */
2268
+	public $thsnds;
2269
+
2270
+
2271
+
2272
+	/**
2273
+	 *    class constructor
2274
+	 *
2275
+	 * @access    public
2276
+	 * @param string $CNT_ISO
2277
+	 * @throws \EE_Error
2278
+	 */
2279
+	public function __construct($CNT_ISO = '')
2280
+	{
2281
+		/** @var \EventEspresso\core\services\database\TableAnalysis $table_analysis */
2282
+		$table_analysis = EE_Registry::instance()->create('TableAnalysis', array(), true);
2283
+		// get country code from organization settings or use default
2284
+		$ORG_CNT = isset(EE_Registry::instance()->CFG->organization)
2285
+				   && EE_Registry::instance()->CFG->organization instanceof EE_Organization_Config
2286
+			? EE_Registry::instance()->CFG->organization->CNT_ISO
2287
+			: '';
2288
+		// but override if requested
2289
+		$CNT_ISO = ! empty($CNT_ISO) ? $CNT_ISO : $ORG_CNT;
2290
+		// so if that all went well, and we are not in M-Mode (cuz you can't query the db in M-Mode) and double-check the countries table exists
2291
+		if (
2292
+			! empty($CNT_ISO)
2293
+			&& EE_Maintenance_Mode::instance()->models_can_query()
2294
+			&& $table_analysis->tableExists(EE_Registry::instance()->load_model('Country')->table())
2295
+		) {
2296
+			// retrieve the country settings from the db, just in case they have been customized
2297
+			$country = EE_Registry::instance()->load_model('Country')->get_one_by_ID($CNT_ISO);
2298
+			if ($country instanceof EE_Country) {
2299
+				$this->code = $country->currency_code();    // currency code: USD, CAD, EUR
2300
+				$this->name = $country->currency_name_single();    // Dollar
2301
+				$this->plural = $country->currency_name_plural();    // Dollars
2302
+				$this->sign = $country->currency_sign();            // currency sign: $
2303
+				$this->sign_b4 = $country->currency_sign_before();        // currency sign before or after: $TRUE  or  FALSE$
2304
+				$this->dec_plc = $country->currency_decimal_places();    // decimal places: 2 = 0.00  3 = 0.000
2305
+				$this->dec_mrk = $country->currency_decimal_mark();    // decimal mark: (comma) ',' = 0,01   or (decimal) '.' = 0.01
2306
+				$this->thsnds = $country->currency_thousands_separator();    // thousands separator: (comma) ',' = 1,000   or (decimal) '.' = 1.000
2307
+			}
2308
+		}
2309
+		// fallback to hardcoded defaults, in case the above failed
2310
+		if (empty($this->code)) {
2311
+			// set default currency settings
2312
+			$this->code = 'USD';    // currency code: USD, CAD, EUR
2313
+			$this->name = __('Dollar', 'event_espresso');    // Dollar
2314
+			$this->plural = __('Dollars', 'event_espresso');    // Dollars
2315
+			$this->sign = '$';    // currency sign: $
2316
+			$this->sign_b4 = true;    // currency sign before or after: $TRUE  or  FALSE$
2317
+			$this->dec_plc = 2;    // decimal places: 2 = 0.00  3 = 0.000
2318
+			$this->dec_mrk = '.';    // decimal mark: (comma) ',' = 0,01   or (decimal) '.' = 0.01
2319
+			$this->thsnds = ',';    // thousands separator: (comma) ',' = 1,000   or (decimal) '.' = 1.000
2320
+		}
2321
+	}
2322
+}
2505 2323
 
2506
-    /**
2507
-     * @return boolean
2508
-     */
2509
-    public function track_invalid_checkout_access()
2510
-    {
2511
-        return $this->track_invalid_checkout_access;
2512
-    }
2513 2324
 
2514 2325
 
2326
+/**
2327
+ * Class for defining what's in the EE_Config relating to registration settings
2328
+ */
2329
+class EE_Registration_Config extends EE_Config_Base
2330
+{
2515 2331
 
2516
-    /**
2517
-     * @param boolean $track_invalid_checkout_access
2518
-     */
2519
-    public function set_track_invalid_checkout_access($track_invalid_checkout_access)
2520
-    {
2521
-        $this->track_invalid_checkout_access = filter_var(
2522
-            $track_invalid_checkout_access,
2523
-            FILTER_VALIDATE_BOOLEAN
2524
-        );
2525
-    }
2332
+	/**
2333
+	 * Default registration status
2334
+	 *
2335
+	 * @var string $default_STS_ID
2336
+	 * eg 'RPP'
2337
+	 */
2338
+	public $default_STS_ID;
2339
+
2340
+	/**
2341
+	 * level of validation to apply to email addresses
2342
+	 *
2343
+	 * @var string $email_validation_level
2344
+	 * options: 'basic', 'wp_default', 'i18n', 'i18n_dns'
2345
+	 */
2346
+	public $email_validation_level;
2347
+
2348
+	/**
2349
+	 *    whether or not to show alternate payment options during the reg process if payment status is pending
2350
+	 *
2351
+	 * @var boolean $show_pending_payment_options
2352
+	 */
2353
+	public $show_pending_payment_options;
2354
+
2355
+	/**
2356
+	 * Whether to skip the registration confirmation page
2357
+	 *
2358
+	 * @var boolean $skip_reg_confirmation
2359
+	 */
2360
+	public $skip_reg_confirmation;
2361
+
2362
+	/**
2363
+	 * an array of SPCO reg steps where:
2364
+	 *        the keys denotes the reg step order
2365
+	 *        each element consists of an array with the following elements:
2366
+	 *            "file_path" => the file path to the EE_SPCO_Reg_Step class
2367
+	 *            "class_name" => the specific EE_SPCO_Reg_Step child class name
2368
+	 *            "slug" => the URL param used to trigger the reg step
2369
+	 *
2370
+	 * @var array $reg_steps
2371
+	 */
2372
+	public $reg_steps;
2373
+
2374
+	/**
2375
+	 * Whether registration confirmation should be the last page of SPCO
2376
+	 *
2377
+	 * @var boolean $reg_confirmation_last
2378
+	 */
2379
+	public $reg_confirmation_last;
2380
+
2381
+	/**
2382
+	 * Whether or not to enable the EE Bot Trap
2383
+	 *
2384
+	 * @var boolean $use_bot_trap
2385
+	 */
2386
+	public $use_bot_trap;
2387
+
2388
+	/**
2389
+	 * Whether or not to encrypt some data sent by the EE Bot Trap
2390
+	 *
2391
+	 * @var boolean $use_encryption
2392
+	 */
2393
+	public $use_encryption;
2394
+
2395
+	/**
2396
+	 * Whether or not to use ReCaptcha
2397
+	 *
2398
+	 * @var boolean $use_captcha
2399
+	 */
2400
+	public $use_captcha;
2401
+
2402
+	/**
2403
+	 * ReCaptcha Theme
2404
+	 *
2405
+	 * @var string $recaptcha_theme
2406
+	 *    options: 'dark    ', 'light'
2407
+	 */
2408
+	public $recaptcha_theme;
2409
+
2410
+	/**
2411
+	 * ReCaptcha Type
2412
+	 *
2413
+	 * @var string $recaptcha_type
2414
+	 *    options: 'audio', 'image'
2415
+	 */
2416
+	public $recaptcha_type;
2417
+
2418
+	/**
2419
+	 * ReCaptcha language
2420
+	 *
2421
+	 * @var string $recaptcha_language
2422
+	 * eg 'en'
2423
+	 */
2424
+	public $recaptcha_language;
2425
+
2426
+	/**
2427
+	 * ReCaptcha public key
2428
+	 *
2429
+	 * @var string $recaptcha_publickey
2430
+	 */
2431
+	public $recaptcha_publickey;
2432
+
2433
+	/**
2434
+	 * ReCaptcha private key
2435
+	 *
2436
+	 * @var string $recaptcha_privatekey
2437
+	 */
2438
+	public $recaptcha_privatekey;
2439
+
2440
+	/**
2441
+	 * ReCaptcha width
2442
+	 *
2443
+	 * @var int $recaptcha_width
2444
+	 * @deprecated
2445
+	 */
2446
+	public $recaptcha_width;
2447
+
2448
+	/**
2449
+	 * Whether or not invalid attempts to directly access the registration checkout page should be tracked.
2450
+	 *
2451
+	 * @var boolean $track_invalid_checkout_access
2452
+	 */
2453
+	protected $track_invalid_checkout_access = true;
2454
+
2455
+
2456
+
2457
+	/**
2458
+	 *    class constructor
2459
+	 *
2460
+	 * @access    public
2461
+	 */
2462
+	public function __construct()
2463
+	{
2464
+		// set default registration settings
2465
+		$this->default_STS_ID = EEM_Registration::status_id_pending_payment;
2466
+		$this->email_validation_level = 'wp_default';
2467
+		$this->show_pending_payment_options = true;
2468
+		$this->skip_reg_confirmation = false;
2469
+		$this->reg_steps = array();
2470
+		$this->reg_confirmation_last = false;
2471
+		$this->use_bot_trap = true;
2472
+		$this->use_encryption = true;
2473
+		$this->use_captcha = false;
2474
+		$this->recaptcha_theme = 'light';
2475
+		$this->recaptcha_type = 'image';
2476
+		$this->recaptcha_language = 'en';
2477
+		$this->recaptcha_publickey = null;
2478
+		$this->recaptcha_privatekey = null;
2479
+		$this->recaptcha_width = 500;
2480
+	}
2481
+
2482
+
2483
+
2484
+	/**
2485
+	 * This is called by the config loader and hooks are initialized AFTER the config has been populated.
2486
+	 *
2487
+	 * @since 4.8.8.rc.019
2488
+	 */
2489
+	public function do_hooks()
2490
+	{
2491
+		add_action('AHEE__EE_Config___load_core_config__end', array($this, 'set_default_reg_status_on_EEM_Event'));
2492
+	}
2493
+
2494
+
2495
+
2496
+	/**
2497
+	 * @return void
2498
+	 */
2499
+	public function set_default_reg_status_on_EEM_Event()
2500
+	{
2501
+		EEM_Event::set_default_reg_status($this->default_STS_ID);
2502
+	}
2503
+
2504
+
2505
+
2506
+	/**
2507
+	 * @return boolean
2508
+	 */
2509
+	public function track_invalid_checkout_access()
2510
+	{
2511
+		return $this->track_invalid_checkout_access;
2512
+	}
2513
+
2514
+
2515
+
2516
+	/**
2517
+	 * @param boolean $track_invalid_checkout_access
2518
+	 */
2519
+	public function set_track_invalid_checkout_access($track_invalid_checkout_access)
2520
+	{
2521
+		$this->track_invalid_checkout_access = filter_var(
2522
+			$track_invalid_checkout_access,
2523
+			FILTER_VALIDATE_BOOLEAN
2524
+		);
2525
+	}
2526 2526
 
2527 2527
 
2528 2528
 }
@@ -2535,160 +2535,160 @@  discard block
 block discarded – undo
2535 2535
 class EE_Admin_Config extends EE_Config_Base
2536 2536
 {
2537 2537
 
2538
-    /**
2539
-     * @var boolean $use_personnel_manager
2540
-     */
2541
-    public $use_personnel_manager;
2542
-
2543
-    /**
2544
-     * @var boolean $use_dashboard_widget
2545
-     */
2546
-    public $use_dashboard_widget;
2547
-
2548
-    /**
2549
-     * @var int $events_in_dashboard
2550
-     */
2551
-    public $events_in_dashboard;
2552
-
2553
-    /**
2554
-     * @var boolean $use_event_timezones
2555
-     */
2556
-    public $use_event_timezones;
2557
-
2558
-    /**
2559
-     * @var boolean $use_full_logging
2560
-     */
2561
-    public $use_full_logging;
2562
-
2563
-    /**
2564
-     * @var string $log_file_name
2565
-     */
2566
-    public $log_file_name;
2567
-
2568
-    /**
2569
-     * @var string $debug_file_name
2570
-     */
2571
-    public $debug_file_name;
2572
-
2573
-    /**
2574
-     * @var boolean $use_remote_logging
2575
-     */
2576
-    public $use_remote_logging;
2577
-
2578
-    /**
2579
-     * @var string $remote_logging_url
2580
-     */
2581
-    public $remote_logging_url;
2582
-
2583
-    /**
2584
-     * @var boolean $show_reg_footer
2585
-     */
2586
-    public $show_reg_footer;
2587
-
2588
-    /**
2589
-     * @var string $affiliate_id
2590
-     */
2591
-    public $affiliate_id;
2592
-
2593
-    /**
2594
-     * help tours on or off (global setting)
2595
-     *
2596
-     * @var boolean
2597
-     */
2598
-    public $help_tour_activation;
2599
-
2600
-    /**
2601
-     * adds extra layer of encoding to session data to prevent serialization errors
2602
-     * but is incompatible with some server configuration errors
2603
-     * if you get "500 internal server errors" during registration, try turning this on
2604
-     * if you get PHP fatal errors regarding base 64 methods not defined, then turn this off
2605
-     *
2606
-     * @var boolean $encode_session_data
2607
-     */
2608
-    private $encode_session_data = false;
2609
-
2610
-
2611
-
2612
-    /**
2613
-     *    class constructor
2614
-     *
2615
-     * @access    public
2616
-     */
2617
-    public function __construct()
2618
-    {
2619
-        // set default general admin settings
2620
-        $this->use_personnel_manager = true;
2621
-        $this->use_dashboard_widget = true;
2622
-        $this->events_in_dashboard = 30;
2623
-        $this->use_event_timezones = false;
2624
-        $this->use_full_logging = false;
2625
-        $this->use_remote_logging = false;
2626
-        $this->remote_logging_url = null;
2627
-        $this->show_reg_footer = true;
2628
-        $this->affiliate_id = 'default';
2629
-        $this->help_tour_activation = true;
2630
-        $this->encode_session_data = false;
2631
-    }
2632
-
2633
-
2634
-
2635
-    /**
2636
-     * @param bool $reset
2637
-     * @return string
2638
-     */
2639
-    public function log_file_name($reset = false)
2640
-    {
2641
-        if (empty($this->log_file_name) || $reset) {
2642
-            $this->log_file_name = sanitize_key('espresso_log_' . md5(uniqid('', true))) . '.txt';
2643
-            EE_Config::instance()->update_espresso_config(false, false);
2644
-        }
2645
-        return $this->log_file_name;
2646
-    }
2647
-
2648
-
2649
-
2650
-    /**
2651
-     * @param bool $reset
2652
-     * @return string
2653
-     */
2654
-    public function debug_file_name($reset = false)
2655
-    {
2656
-        if (empty($this->debug_file_name) || $reset) {
2657
-            $this->debug_file_name = sanitize_key('espresso_debug_' . md5(uniqid('', true))) . '.txt';
2658
-            EE_Config::instance()->update_espresso_config(false, false);
2659
-        }
2660
-        return $this->debug_file_name;
2661
-    }
2662
-
2663
-
2664
-
2665
-    /**
2666
-     * @return string
2667
-     */
2668
-    public function affiliate_id()
2669
-    {
2670
-        return ! empty($this->affiliate_id) ? $this->affiliate_id : 'default';
2671
-    }
2672
-
2673
-
2674
-
2675
-    /**
2676
-     * @return boolean
2677
-     */
2678
-    public function encode_session_data()
2679
-    {
2680
-        return filter_var($this->encode_session_data, FILTER_VALIDATE_BOOLEAN);
2681
-    }
2682
-
2683
-
2684
-
2685
-    /**
2686
-     * @param boolean $encode_session_data
2687
-     */
2688
-    public function set_encode_session_data($encode_session_data)
2689
-    {
2690
-        $this->encode_session_data = filter_var($encode_session_data, FILTER_VALIDATE_BOOLEAN);
2691
-    }
2538
+	/**
2539
+	 * @var boolean $use_personnel_manager
2540
+	 */
2541
+	public $use_personnel_manager;
2542
+
2543
+	/**
2544
+	 * @var boolean $use_dashboard_widget
2545
+	 */
2546
+	public $use_dashboard_widget;
2547
+
2548
+	/**
2549
+	 * @var int $events_in_dashboard
2550
+	 */
2551
+	public $events_in_dashboard;
2552
+
2553
+	/**
2554
+	 * @var boolean $use_event_timezones
2555
+	 */
2556
+	public $use_event_timezones;
2557
+
2558
+	/**
2559
+	 * @var boolean $use_full_logging
2560
+	 */
2561
+	public $use_full_logging;
2562
+
2563
+	/**
2564
+	 * @var string $log_file_name
2565
+	 */
2566
+	public $log_file_name;
2567
+
2568
+	/**
2569
+	 * @var string $debug_file_name
2570
+	 */
2571
+	public $debug_file_name;
2572
+
2573
+	/**
2574
+	 * @var boolean $use_remote_logging
2575
+	 */
2576
+	public $use_remote_logging;
2577
+
2578
+	/**
2579
+	 * @var string $remote_logging_url
2580
+	 */
2581
+	public $remote_logging_url;
2582
+
2583
+	/**
2584
+	 * @var boolean $show_reg_footer
2585
+	 */
2586
+	public $show_reg_footer;
2587
+
2588
+	/**
2589
+	 * @var string $affiliate_id
2590
+	 */
2591
+	public $affiliate_id;
2592
+
2593
+	/**
2594
+	 * help tours on or off (global setting)
2595
+	 *
2596
+	 * @var boolean
2597
+	 */
2598
+	public $help_tour_activation;
2599
+
2600
+	/**
2601
+	 * adds extra layer of encoding to session data to prevent serialization errors
2602
+	 * but is incompatible with some server configuration errors
2603
+	 * if you get "500 internal server errors" during registration, try turning this on
2604
+	 * if you get PHP fatal errors regarding base 64 methods not defined, then turn this off
2605
+	 *
2606
+	 * @var boolean $encode_session_data
2607
+	 */
2608
+	private $encode_session_data = false;
2609
+
2610
+
2611
+
2612
+	/**
2613
+	 *    class constructor
2614
+	 *
2615
+	 * @access    public
2616
+	 */
2617
+	public function __construct()
2618
+	{
2619
+		// set default general admin settings
2620
+		$this->use_personnel_manager = true;
2621
+		$this->use_dashboard_widget = true;
2622
+		$this->events_in_dashboard = 30;
2623
+		$this->use_event_timezones = false;
2624
+		$this->use_full_logging = false;
2625
+		$this->use_remote_logging = false;
2626
+		$this->remote_logging_url = null;
2627
+		$this->show_reg_footer = true;
2628
+		$this->affiliate_id = 'default';
2629
+		$this->help_tour_activation = true;
2630
+		$this->encode_session_data = false;
2631
+	}
2632
+
2633
+
2634
+
2635
+	/**
2636
+	 * @param bool $reset
2637
+	 * @return string
2638
+	 */
2639
+	public function log_file_name($reset = false)
2640
+	{
2641
+		if (empty($this->log_file_name) || $reset) {
2642
+			$this->log_file_name = sanitize_key('espresso_log_' . md5(uniqid('', true))) . '.txt';
2643
+			EE_Config::instance()->update_espresso_config(false, false);
2644
+		}
2645
+		return $this->log_file_name;
2646
+	}
2647
+
2648
+
2649
+
2650
+	/**
2651
+	 * @param bool $reset
2652
+	 * @return string
2653
+	 */
2654
+	public function debug_file_name($reset = false)
2655
+	{
2656
+		if (empty($this->debug_file_name) || $reset) {
2657
+			$this->debug_file_name = sanitize_key('espresso_debug_' . md5(uniqid('', true))) . '.txt';
2658
+			EE_Config::instance()->update_espresso_config(false, false);
2659
+		}
2660
+		return $this->debug_file_name;
2661
+	}
2662
+
2663
+
2664
+
2665
+	/**
2666
+	 * @return string
2667
+	 */
2668
+	public function affiliate_id()
2669
+	{
2670
+		return ! empty($this->affiliate_id) ? $this->affiliate_id : 'default';
2671
+	}
2672
+
2673
+
2674
+
2675
+	/**
2676
+	 * @return boolean
2677
+	 */
2678
+	public function encode_session_data()
2679
+	{
2680
+		return filter_var($this->encode_session_data, FILTER_VALIDATE_BOOLEAN);
2681
+	}
2682
+
2683
+
2684
+
2685
+	/**
2686
+	 * @param boolean $encode_session_data
2687
+	 */
2688
+	public function set_encode_session_data($encode_session_data)
2689
+	{
2690
+		$this->encode_session_data = filter_var($encode_session_data, FILTER_VALIDATE_BOOLEAN);
2691
+	}
2692 2692
 
2693 2693
 
2694 2694
 }
@@ -2701,71 +2701,71 @@  discard block
 block discarded – undo
2701 2701
 class EE_Template_Config extends EE_Config_Base
2702 2702
 {
2703 2703
 
2704
-    /**
2705
-     * @var boolean $enable_default_style
2706
-     */
2707
-    public $enable_default_style;
2708
-
2709
-    /**
2710
-     * @var string $custom_style_sheet
2711
-     */
2712
-    public $custom_style_sheet;
2713
-
2714
-    /**
2715
-     * @var boolean $display_address_in_regform
2716
-     */
2717
-    public $display_address_in_regform;
2718
-
2719
-    /**
2720
-     * @var int $display_description_on_multi_reg_page
2721
-     */
2722
-    public $display_description_on_multi_reg_page;
2723
-
2724
-    /**
2725
-     * @var boolean $use_custom_templates
2726
-     */
2727
-    public $use_custom_templates;
2728
-
2729
-    /**
2730
-     * @var string $current_espresso_theme
2731
-     */
2732
-    public $current_espresso_theme;
2733
-
2734
-    /**
2735
-     * @var EE_Ticket_Selector_Config $EED_Ticket_Selector
2736
-     */
2737
-    public $EED_Ticket_Selector;
2738
-
2739
-    /**
2740
-     * @var EE_Event_Single_Config $EED_Event_Single
2741
-     */
2742
-    public $EED_Event_Single;
2743
-
2744
-    /**
2745
-     * @var EE_Events_Archive_Config $EED_Events_Archive
2746
-     */
2747
-    public $EED_Events_Archive;
2748
-
2749
-
2750
-
2751
-    /**
2752
-     *    class constructor
2753
-     *
2754
-     * @access    public
2755
-     */
2756
-    public function __construct()
2757
-    {
2758
-        // set default template settings
2759
-        $this->enable_default_style = true;
2760
-        $this->custom_style_sheet = null;
2761
-        $this->display_address_in_regform = true;
2762
-        $this->display_description_on_multi_reg_page = false;
2763
-        $this->use_custom_templates = false;
2764
-        $this->current_espresso_theme = 'Espresso_Arabica_2014';
2765
-        $this->EED_Event_Single = null;
2766
-        $this->EED_Events_Archive = null;
2767
-        $this->EED_Ticket_Selector = null;
2768
-    }
2704
+	/**
2705
+	 * @var boolean $enable_default_style
2706
+	 */
2707
+	public $enable_default_style;
2708
+
2709
+	/**
2710
+	 * @var string $custom_style_sheet
2711
+	 */
2712
+	public $custom_style_sheet;
2713
+
2714
+	/**
2715
+	 * @var boolean $display_address_in_regform
2716
+	 */
2717
+	public $display_address_in_regform;
2718
+
2719
+	/**
2720
+	 * @var int $display_description_on_multi_reg_page
2721
+	 */
2722
+	public $display_description_on_multi_reg_page;
2723
+
2724
+	/**
2725
+	 * @var boolean $use_custom_templates
2726
+	 */
2727
+	public $use_custom_templates;
2728
+
2729
+	/**
2730
+	 * @var string $current_espresso_theme
2731
+	 */
2732
+	public $current_espresso_theme;
2733
+
2734
+	/**
2735
+	 * @var EE_Ticket_Selector_Config $EED_Ticket_Selector
2736
+	 */
2737
+	public $EED_Ticket_Selector;
2738
+
2739
+	/**
2740
+	 * @var EE_Event_Single_Config $EED_Event_Single
2741
+	 */
2742
+	public $EED_Event_Single;
2743
+
2744
+	/**
2745
+	 * @var EE_Events_Archive_Config $EED_Events_Archive
2746
+	 */
2747
+	public $EED_Events_Archive;
2748
+
2749
+
2750
+
2751
+	/**
2752
+	 *    class constructor
2753
+	 *
2754
+	 * @access    public
2755
+	 */
2756
+	public function __construct()
2757
+	{
2758
+		// set default template settings
2759
+		$this->enable_default_style = true;
2760
+		$this->custom_style_sheet = null;
2761
+		$this->display_address_in_regform = true;
2762
+		$this->display_description_on_multi_reg_page = false;
2763
+		$this->use_custom_templates = false;
2764
+		$this->current_espresso_theme = 'Espresso_Arabica_2014';
2765
+		$this->EED_Event_Single = null;
2766
+		$this->EED_Events_Archive = null;
2767
+		$this->EED_Ticket_Selector = null;
2768
+	}
2769 2769
 
2770 2770
 }
2771 2771
 
@@ -2777,115 +2777,115 @@  discard block
 block discarded – undo
2777 2777
 class EE_Map_Config extends EE_Config_Base
2778 2778
 {
2779 2779
 
2780
-    /**
2781
-     * @var boolean $use_google_maps
2782
-     */
2783
-    public $use_google_maps;
2784
-
2785
-    /**
2786
-     * @var string $api_key
2787
-     */
2788
-    public $google_map_api_key;
2789
-
2790
-    /**
2791
-     * @var int $event_details_map_width
2792
-     */
2793
-    public $event_details_map_width;
2794
-
2795
-    /**
2796
-     * @var int $event_details_map_height
2797
-     */
2798
-    public $event_details_map_height;
2799
-
2800
-    /**
2801
-     * @var int $event_details_map_zoom
2802
-     */
2803
-    public $event_details_map_zoom;
2804
-
2805
-    /**
2806
-     * @var boolean $event_details_display_nav
2807
-     */
2808
-    public $event_details_display_nav;
2809
-
2810
-    /**
2811
-     * @var boolean $event_details_nav_size
2812
-     */
2813
-    public $event_details_nav_size;
2814
-
2815
-    /**
2816
-     * @var string $event_details_control_type
2817
-     */
2818
-    public $event_details_control_type;
2819
-
2820
-    /**
2821
-     * @var string $event_details_map_align
2822
-     */
2823
-    public $event_details_map_align;
2824
-
2825
-    /**
2826
-     * @var int $event_list_map_width
2827
-     */
2828
-    public $event_list_map_width;
2829
-
2830
-    /**
2831
-     * @var int $event_list_map_height
2832
-     */
2833
-    public $event_list_map_height;
2834
-
2835
-    /**
2836
-     * @var int $event_list_map_zoom
2837
-     */
2838
-    public $event_list_map_zoom;
2839
-
2840
-    /**
2841
-     * @var boolean $event_list_display_nav
2842
-     */
2843
-    public $event_list_display_nav;
2844
-
2845
-    /**
2846
-     * @var boolean $event_list_nav_size
2847
-     */
2848
-    public $event_list_nav_size;
2849
-
2850
-    /**
2851
-     * @var string $event_list_control_type
2852
-     */
2853
-    public $event_list_control_type;
2854
-
2855
-    /**
2856
-     * @var string $event_list_map_align
2857
-     */
2858
-    public $event_list_map_align;
2859
-
2860
-
2861
-
2862
-    /**
2863
-     *    class constructor
2864
-     *
2865
-     * @access    public
2866
-     */
2867
-    public function __construct()
2868
-    {
2869
-        // set default map settings
2870
-        $this->use_google_maps = true;
2871
-        $this->google_map_api_key = '';
2872
-        // for event details pages (reg page)
2873
-        $this->event_details_map_width = 585;            // ee_map_width_single
2874
-        $this->event_details_map_height = 362;            // ee_map_height_single
2875
-        $this->event_details_map_zoom = 14;            // ee_map_zoom_single
2876
-        $this->event_details_display_nav = true;            // ee_map_nav_display_single
2877
-        $this->event_details_nav_size = false;            // ee_map_nav_size_single
2878
-        $this->event_details_control_type = 'default';        // ee_map_type_control_single
2879
-        $this->event_details_map_align = 'center';            // ee_map_align_single
2880
-        // for event list pages
2881
-        $this->event_list_map_width = 300;            // ee_map_width
2882
-        $this->event_list_map_height = 185;        // ee_map_height
2883
-        $this->event_list_map_zoom = 12;            // ee_map_zoom
2884
-        $this->event_list_display_nav = false;        // ee_map_nav_display
2885
-        $this->event_list_nav_size = true;            // ee_map_nav_size
2886
-        $this->event_list_control_type = 'dropdown';        // ee_map_type_control
2887
-        $this->event_list_map_align = 'center';            // ee_map_align
2888
-    }
2780
+	/**
2781
+	 * @var boolean $use_google_maps
2782
+	 */
2783
+	public $use_google_maps;
2784
+
2785
+	/**
2786
+	 * @var string $api_key
2787
+	 */
2788
+	public $google_map_api_key;
2789
+
2790
+	/**
2791
+	 * @var int $event_details_map_width
2792
+	 */
2793
+	public $event_details_map_width;
2794
+
2795
+	/**
2796
+	 * @var int $event_details_map_height
2797
+	 */
2798
+	public $event_details_map_height;
2799
+
2800
+	/**
2801
+	 * @var int $event_details_map_zoom
2802
+	 */
2803
+	public $event_details_map_zoom;
2804
+
2805
+	/**
2806
+	 * @var boolean $event_details_display_nav
2807
+	 */
2808
+	public $event_details_display_nav;
2809
+
2810
+	/**
2811
+	 * @var boolean $event_details_nav_size
2812
+	 */
2813
+	public $event_details_nav_size;
2814
+
2815
+	/**
2816
+	 * @var string $event_details_control_type
2817
+	 */
2818
+	public $event_details_control_type;
2819
+
2820
+	/**
2821
+	 * @var string $event_details_map_align
2822
+	 */
2823
+	public $event_details_map_align;
2824
+
2825
+	/**
2826
+	 * @var int $event_list_map_width
2827
+	 */
2828
+	public $event_list_map_width;
2829
+
2830
+	/**
2831
+	 * @var int $event_list_map_height
2832
+	 */
2833
+	public $event_list_map_height;
2834
+
2835
+	/**
2836
+	 * @var int $event_list_map_zoom
2837
+	 */
2838
+	public $event_list_map_zoom;
2839
+
2840
+	/**
2841
+	 * @var boolean $event_list_display_nav
2842
+	 */
2843
+	public $event_list_display_nav;
2844
+
2845
+	/**
2846
+	 * @var boolean $event_list_nav_size
2847
+	 */
2848
+	public $event_list_nav_size;
2849
+
2850
+	/**
2851
+	 * @var string $event_list_control_type
2852
+	 */
2853
+	public $event_list_control_type;
2854
+
2855
+	/**
2856
+	 * @var string $event_list_map_align
2857
+	 */
2858
+	public $event_list_map_align;
2859
+
2860
+
2861
+
2862
+	/**
2863
+	 *    class constructor
2864
+	 *
2865
+	 * @access    public
2866
+	 */
2867
+	public function __construct()
2868
+	{
2869
+		// set default map settings
2870
+		$this->use_google_maps = true;
2871
+		$this->google_map_api_key = '';
2872
+		// for event details pages (reg page)
2873
+		$this->event_details_map_width = 585;            // ee_map_width_single
2874
+		$this->event_details_map_height = 362;            // ee_map_height_single
2875
+		$this->event_details_map_zoom = 14;            // ee_map_zoom_single
2876
+		$this->event_details_display_nav = true;            // ee_map_nav_display_single
2877
+		$this->event_details_nav_size = false;            // ee_map_nav_size_single
2878
+		$this->event_details_control_type = 'default';        // ee_map_type_control_single
2879
+		$this->event_details_map_align = 'center';            // ee_map_align_single
2880
+		// for event list pages
2881
+		$this->event_list_map_width = 300;            // ee_map_width
2882
+		$this->event_list_map_height = 185;        // ee_map_height
2883
+		$this->event_list_map_zoom = 12;            // ee_map_zoom
2884
+		$this->event_list_display_nav = false;        // ee_map_nav_display
2885
+		$this->event_list_nav_size = true;            // ee_map_nav_size
2886
+		$this->event_list_control_type = 'dropdown';        // ee_map_type_control
2887
+		$this->event_list_map_align = 'center';            // ee_map_align
2888
+	}
2889 2889
 
2890 2890
 }
2891 2891
 
@@ -2897,47 +2897,47 @@  discard block
 block discarded – undo
2897 2897
 class EE_Events_Archive_Config extends EE_Config_Base
2898 2898
 {
2899 2899
 
2900
-    public $display_status_banner;
2900
+	public $display_status_banner;
2901 2901
 
2902
-    public $display_description;
2902
+	public $display_description;
2903 2903
 
2904
-    public $display_ticket_selector;
2904
+	public $display_ticket_selector;
2905 2905
 
2906
-    public $display_datetimes;
2906
+	public $display_datetimes;
2907 2907
 
2908
-    public $display_venue;
2908
+	public $display_venue;
2909 2909
 
2910
-    public $display_expired_events;
2910
+	public $display_expired_events;
2911 2911
 
2912
-    public $use_sortable_display_order;
2912
+	public $use_sortable_display_order;
2913 2913
 
2914
-    public $display_order_tickets;
2914
+	public $display_order_tickets;
2915 2915
 
2916
-    public $display_order_datetimes;
2916
+	public $display_order_datetimes;
2917 2917
 
2918
-    public $display_order_event;
2918
+	public $display_order_event;
2919 2919
 
2920
-    public $display_order_venue;
2920
+	public $display_order_venue;
2921 2921
 
2922 2922
 
2923 2923
 
2924
-    /**
2925
-     *    class constructor
2926
-     */
2927
-    public function __construct()
2928
-    {
2929
-        $this->display_status_banner = 0;
2930
-        $this->display_description = 1;
2931
-        $this->display_ticket_selector = 0;
2932
-        $this->display_datetimes = 1;
2933
-        $this->display_venue = 0;
2934
-        $this->display_expired_events = 0;
2935
-        $this->use_sortable_display_order = false;
2936
-        $this->display_order_tickets = 100;
2937
-        $this->display_order_datetimes = 110;
2938
-        $this->display_order_event = 120;
2939
-        $this->display_order_venue = 130;
2940
-    }
2924
+	/**
2925
+	 *    class constructor
2926
+	 */
2927
+	public function __construct()
2928
+	{
2929
+		$this->display_status_banner = 0;
2930
+		$this->display_description = 1;
2931
+		$this->display_ticket_selector = 0;
2932
+		$this->display_datetimes = 1;
2933
+		$this->display_venue = 0;
2934
+		$this->display_expired_events = 0;
2935
+		$this->use_sortable_display_order = false;
2936
+		$this->display_order_tickets = 100;
2937
+		$this->display_order_datetimes = 110;
2938
+		$this->display_order_event = 120;
2939
+		$this->display_order_venue = 130;
2940
+	}
2941 2941
 }
2942 2942
 
2943 2943
 
@@ -2948,35 +2948,35 @@  discard block
 block discarded – undo
2948 2948
 class EE_Event_Single_Config extends EE_Config_Base
2949 2949
 {
2950 2950
 
2951
-    public $display_status_banner_single;
2951
+	public $display_status_banner_single;
2952 2952
 
2953
-    public $display_venue;
2953
+	public $display_venue;
2954 2954
 
2955
-    public $use_sortable_display_order;
2955
+	public $use_sortable_display_order;
2956 2956
 
2957
-    public $display_order_tickets;
2957
+	public $display_order_tickets;
2958 2958
 
2959
-    public $display_order_datetimes;
2959
+	public $display_order_datetimes;
2960 2960
 
2961
-    public $display_order_event;
2961
+	public $display_order_event;
2962 2962
 
2963
-    public $display_order_venue;
2963
+	public $display_order_venue;
2964 2964
 
2965 2965
 
2966 2966
 
2967
-    /**
2968
-     *    class constructor
2969
-     */
2970
-    public function __construct()
2971
-    {
2972
-        $this->display_status_banner_single = 0;
2973
-        $this->display_venue = 1;
2974
-        $this->use_sortable_display_order = false;
2975
-        $this->display_order_tickets = 100;
2976
-        $this->display_order_datetimes = 110;
2977
-        $this->display_order_event = 120;
2978
-        $this->display_order_venue = 130;
2979
-    }
2967
+	/**
2968
+	 *    class constructor
2969
+	 */
2970
+	public function __construct()
2971
+	{
2972
+		$this->display_status_banner_single = 0;
2973
+		$this->display_venue = 1;
2974
+		$this->use_sortable_display_order = false;
2975
+		$this->display_order_tickets = 100;
2976
+		$this->display_order_datetimes = 110;
2977
+		$this->display_order_event = 120;
2978
+		$this->display_order_venue = 130;
2979
+	}
2980 2980
 }
2981 2981
 
2982 2982
 
@@ -2987,151 +2987,151 @@  discard block
 block discarded – undo
2987 2987
 class EE_Ticket_Selector_Config extends EE_Config_Base
2988 2988
 {
2989 2989
 
2990
-    /**
2991
-     * constant to indicate that a datetime selector should NEVER be shown for ticket selectors
2992
-     */
2993
-    const DO_NOT_SHOW_DATETIME_SELECTOR = 'no_datetime_selector';
2994
-
2995
-    /**
2996
-     * constant to indicate that a datetime selector should only be shown for ticket selectors
2997
-     * when the number of datetimes for the event matches the value set for $datetime_selector_threshold
2998
-     */
2999
-    const MAYBE_SHOW_DATETIME_SELECTOR = 'maybe_datetime_selector';
3000
-
3001
-    /**
3002
-     * @var boolean $show_ticket_sale_columns
3003
-     */
3004
-    public $show_ticket_sale_columns;
3005
-
3006
-    /**
3007
-     * @var boolean $show_ticket_details
3008
-     */
3009
-    public $show_ticket_details;
3010
-
3011
-    /**
3012
-     * @var boolean $show_expired_tickets
3013
-     */
3014
-    public $show_expired_tickets;
3015
-
3016
-    /**
3017
-     * whether or not to display a dropdown box populated with event datetimes
3018
-     * that toggles which tickets are displayed for a ticket selector.
3019
-     * uses one of the *_DATETIME_SELECTOR constants defined above
3020
-     *
3021
-     * @var string $show_datetime_selector
3022
-     */
3023
-    private $show_datetime_selector = 'no_datetime_selector';
3024
-
3025
-    /**
3026
-     * the number of datetimes an event has to have before conditionally displaying a datetime selector
3027
-     *
3028
-     * @var int $datetime_selector_threshold
3029
-     */
3030
-    private $datetime_selector_threshold = 3;
3031
-
3032
-
3033
-
3034
-    /**
3035
-     *    class constructor
3036
-     */
3037
-    public function __construct()
3038
-    {
3039
-        $this->show_ticket_sale_columns = true;
3040
-        $this->show_ticket_details = true;
3041
-        $this->show_expired_tickets = true;
3042
-        $this->show_datetime_selector = \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR;
3043
-        $this->datetime_selector_threshold = 3;
3044
-    }
3045
-
3046
-
3047
-
3048
-    /**
3049
-     * returns true if a datetime selector should be displayed
3050
-     *
3051
-     * @param array $datetimes
3052
-     * @return bool
3053
-     */
3054
-    public function showDatetimeSelector(array $datetimes)
3055
-    {
3056
-        // if the settings are NOT: don't show OR below threshold, THEN active = true
3057
-        return ! (
3058
-            $this->getShowDatetimeSelector() === \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR
3059
-            || (
3060
-                $this->getShowDatetimeSelector() === \EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR
3061
-                && count($datetimes) < $this->getDatetimeSelectorThreshold()
3062
-            )
3063
-        );
3064
-    }
3065
-
3066
-
3067
-
3068
-    /**
3069
-     * @return string
3070
-     */
3071
-    public function getShowDatetimeSelector()
3072
-    {
3073
-        return $this->show_datetime_selector;
3074
-    }
3075
-
3076
-
3077
-
3078
-    /**
3079
-     * @param bool $keys_only
3080
-     * @return array
3081
-     */
3082
-    public function getShowDatetimeSelectorOptions($keys_only = true)
3083
-    {
3084
-        return $keys_only
3085
-            ? array(
3086
-                \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR,
3087
-                \EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR,
3088
-            )
3089
-            : array(
3090
-                \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR => esc_html__(
3091
-                    'Do not show date & time filter', 'event_espresso'
3092
-                ),
3093
-                \EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR  => esc_html__(
3094
-                    'Maybe show date & time filter', 'event_espresso'
3095
-                ),
3096
-            );
3097
-    }
3098
-
3099
-
3100
-
3101
-    /**
3102
-     * @param string $show_datetime_selector
3103
-     */
3104
-    public function setShowDatetimeSelector($show_datetime_selector)
3105
-    {
3106
-        $this->show_datetime_selector = in_array(
3107
-            $show_datetime_selector,
3108
-            $this->getShowDatetimeSelectorOptions(),
3109
-            true
3110
-        )
3111
-            ? $show_datetime_selector
3112
-            : \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR;
3113
-    }
3114
-
3115
-
3116
-
3117
-    /**
3118
-     * @return int
3119
-     */
3120
-    public function getDatetimeSelectorThreshold()
3121
-    {
3122
-        return $this->datetime_selector_threshold;
3123
-    }
3124
-
3125
-
3126
-
3127
-    /**
3128
-     * @param int $datetime_selector_threshold
3129
-     */
3130
-    public function setDatetimeSelectorThreshold($datetime_selector_threshold)
3131
-    {
3132
-        $datetime_selector_threshold = absint($datetime_selector_threshold);
3133
-        $this->datetime_selector_threshold = $datetime_selector_threshold ? $datetime_selector_threshold : 3;
3134
-    }
2990
+	/**
2991
+	 * constant to indicate that a datetime selector should NEVER be shown for ticket selectors
2992
+	 */
2993
+	const DO_NOT_SHOW_DATETIME_SELECTOR = 'no_datetime_selector';
2994
+
2995
+	/**
2996
+	 * constant to indicate that a datetime selector should only be shown for ticket selectors
2997
+	 * when the number of datetimes for the event matches the value set for $datetime_selector_threshold
2998
+	 */
2999
+	const MAYBE_SHOW_DATETIME_SELECTOR = 'maybe_datetime_selector';
3000
+
3001
+	/**
3002
+	 * @var boolean $show_ticket_sale_columns
3003
+	 */
3004
+	public $show_ticket_sale_columns;
3005
+
3006
+	/**
3007
+	 * @var boolean $show_ticket_details
3008
+	 */
3009
+	public $show_ticket_details;
3010
+
3011
+	/**
3012
+	 * @var boolean $show_expired_tickets
3013
+	 */
3014
+	public $show_expired_tickets;
3015
+
3016
+	/**
3017
+	 * whether or not to display a dropdown box populated with event datetimes
3018
+	 * that toggles which tickets are displayed for a ticket selector.
3019
+	 * uses one of the *_DATETIME_SELECTOR constants defined above
3020
+	 *
3021
+	 * @var string $show_datetime_selector
3022
+	 */
3023
+	private $show_datetime_selector = 'no_datetime_selector';
3024
+
3025
+	/**
3026
+	 * the number of datetimes an event has to have before conditionally displaying a datetime selector
3027
+	 *
3028
+	 * @var int $datetime_selector_threshold
3029
+	 */
3030
+	private $datetime_selector_threshold = 3;
3031
+
3032
+
3033
+
3034
+	/**
3035
+	 *    class constructor
3036
+	 */
3037
+	public function __construct()
3038
+	{
3039
+		$this->show_ticket_sale_columns = true;
3040
+		$this->show_ticket_details = true;
3041
+		$this->show_expired_tickets = true;
3042
+		$this->show_datetime_selector = \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR;
3043
+		$this->datetime_selector_threshold = 3;
3044
+	}
3045
+
3046
+
3047
+
3048
+	/**
3049
+	 * returns true if a datetime selector should be displayed
3050
+	 *
3051
+	 * @param array $datetimes
3052
+	 * @return bool
3053
+	 */
3054
+	public function showDatetimeSelector(array $datetimes)
3055
+	{
3056
+		// if the settings are NOT: don't show OR below threshold, THEN active = true
3057
+		return ! (
3058
+			$this->getShowDatetimeSelector() === \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR
3059
+			|| (
3060
+				$this->getShowDatetimeSelector() === \EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR
3061
+				&& count($datetimes) < $this->getDatetimeSelectorThreshold()
3062
+			)
3063
+		);
3064
+	}
3065
+
3066
+
3067
+
3068
+	/**
3069
+	 * @return string
3070
+	 */
3071
+	public function getShowDatetimeSelector()
3072
+	{
3073
+		return $this->show_datetime_selector;
3074
+	}
3075
+
3076
+
3077
+
3078
+	/**
3079
+	 * @param bool $keys_only
3080
+	 * @return array
3081
+	 */
3082
+	public function getShowDatetimeSelectorOptions($keys_only = true)
3083
+	{
3084
+		return $keys_only
3085
+			? array(
3086
+				\EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR,
3087
+				\EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR,
3088
+			)
3089
+			: array(
3090
+				\EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR => esc_html__(
3091
+					'Do not show date & time filter', 'event_espresso'
3092
+				),
3093
+				\EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR  => esc_html__(
3094
+					'Maybe show date & time filter', 'event_espresso'
3095
+				),
3096
+			);
3097
+	}
3098
+
3099
+
3100
+
3101
+	/**
3102
+	 * @param string $show_datetime_selector
3103
+	 */
3104
+	public function setShowDatetimeSelector($show_datetime_selector)
3105
+	{
3106
+		$this->show_datetime_selector = in_array(
3107
+			$show_datetime_selector,
3108
+			$this->getShowDatetimeSelectorOptions(),
3109
+			true
3110
+		)
3111
+			? $show_datetime_selector
3112
+			: \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR;
3113
+	}
3114
+
3115
+
3116
+
3117
+	/**
3118
+	 * @return int
3119
+	 */
3120
+	public function getDatetimeSelectorThreshold()
3121
+	{
3122
+		return $this->datetime_selector_threshold;
3123
+	}
3124
+
3125
+
3126
+
3127
+	/**
3128
+	 * @param int $datetime_selector_threshold
3129
+	 */
3130
+	public function setDatetimeSelectorThreshold($datetime_selector_threshold)
3131
+	{
3132
+		$datetime_selector_threshold = absint($datetime_selector_threshold);
3133
+		$this->datetime_selector_threshold = $datetime_selector_threshold ? $datetime_selector_threshold : 3;
3134
+	}
3135 3135
 
3136 3136
 
3137 3137
 }
@@ -3148,85 +3148,85 @@  discard block
 block discarded – undo
3148 3148
 class EE_Environment_Config extends EE_Config_Base
3149 3149
 {
3150 3150
 
3151
-    /**
3152
-     * Hold any php environment variables that we want to track.
3153
-     *
3154
-     * @var stdClass;
3155
-     */
3156
-    public $php;
3157
-
3158
-
3159
-
3160
-    /**
3161
-     *    constructor
3162
-     */
3163
-    public function __construct()
3164
-    {
3165
-        $this->php = new stdClass();
3166
-        $this->_set_php_values();
3167
-    }
3168
-
3169
-
3170
-
3171
-    /**
3172
-     * This sets the php environment variables.
3173
-     *
3174
-     * @since 4.4.0
3175
-     * @return void
3176
-     */
3177
-    protected function _set_php_values()
3178
-    {
3179
-        $this->php->max_input_vars = ini_get('max_input_vars');
3180
-        $this->php->version = phpversion();
3181
-    }
3182
-
3183
-
3184
-
3185
-    /**
3186
-     * helper method for determining whether input_count is
3187
-     * reaching the potential maximum the server can handle
3188
-     * according to max_input_vars
3189
-     *
3190
-     * @param int   $input_count the count of input vars.
3191
-     * @return array {
3192
-     *                           An array that represents whether available space and if no available space the error
3193
-     *                           message.
3194
-     * @type bool   $has_space   whether more inputs can be added.
3195
-     * @type string $msg         Any message to be displayed.
3196
-     *                           }
3197
-     */
3198
-    public function max_input_vars_limit_check($input_count = 0)
3199
-    {
3200
-        if (! empty($this->php->max_input_vars)
3201
-            && ($input_count >= $this->php->max_input_vars)
3202
-            && (PHP_MAJOR_VERSION >= 5 && PHP_MINOR_VERSION >= 3 && PHP_RELEASE_VERSION >= 9)
3203
-        ) {
3204
-            return sprintf(
3205
-                __(
3206
-                    'The maximum number of inputs on this page has been exceeded.  You cannot add anymore items (i.e. tickets, datetimes, custom fields) on this page because of your servers PHP "max_input_vars" setting.%1$sThere are %2$d inputs and the maximum amount currently allowed by your server is %3$d.',
3207
-                    'event_espresso'
3208
-                ),
3209
-                '<br>',
3210
-                $input_count,
3211
-                $this->php->max_input_vars
3212
-            );
3213
-        } else {
3214
-            return '';
3215
-        }
3216
-    }
3217
-
3218
-
3219
-
3220
-    /**
3221
-     * The purpose of this method is just to force rechecking php values so if they've changed, they get updated.
3222
-     *
3223
-     * @since 4.4.1
3224
-     * @return void
3225
-     */
3226
-    public function recheck_values()
3227
-    {
3228
-        $this->_set_php_values();
3229
-    }
3151
+	/**
3152
+	 * Hold any php environment variables that we want to track.
3153
+	 *
3154
+	 * @var stdClass;
3155
+	 */
3156
+	public $php;
3157
+
3158
+
3159
+
3160
+	/**
3161
+	 *    constructor
3162
+	 */
3163
+	public function __construct()
3164
+	{
3165
+		$this->php = new stdClass();
3166
+		$this->_set_php_values();
3167
+	}
3168
+
3169
+
3170
+
3171
+	/**
3172
+	 * This sets the php environment variables.
3173
+	 *
3174
+	 * @since 4.4.0
3175
+	 * @return void
3176
+	 */
3177
+	protected function _set_php_values()
3178
+	{
3179
+		$this->php->max_input_vars = ini_get('max_input_vars');
3180
+		$this->php->version = phpversion();
3181
+	}
3182
+
3183
+
3184
+
3185
+	/**
3186
+	 * helper method for determining whether input_count is
3187
+	 * reaching the potential maximum the server can handle
3188
+	 * according to max_input_vars
3189
+	 *
3190
+	 * @param int   $input_count the count of input vars.
3191
+	 * @return array {
3192
+	 *                           An array that represents whether available space and if no available space the error
3193
+	 *                           message.
3194
+	 * @type bool   $has_space   whether more inputs can be added.
3195
+	 * @type string $msg         Any message to be displayed.
3196
+	 *                           }
3197
+	 */
3198
+	public function max_input_vars_limit_check($input_count = 0)
3199
+	{
3200
+		if (! empty($this->php->max_input_vars)
3201
+			&& ($input_count >= $this->php->max_input_vars)
3202
+			&& (PHP_MAJOR_VERSION >= 5 && PHP_MINOR_VERSION >= 3 && PHP_RELEASE_VERSION >= 9)
3203
+		) {
3204
+			return sprintf(
3205
+				__(
3206
+					'The maximum number of inputs on this page has been exceeded.  You cannot add anymore items (i.e. tickets, datetimes, custom fields) on this page because of your servers PHP "max_input_vars" setting.%1$sThere are %2$d inputs and the maximum amount currently allowed by your server is %3$d.',
3207
+					'event_espresso'
3208
+				),
3209
+				'<br>',
3210
+				$input_count,
3211
+				$this->php->max_input_vars
3212
+			);
3213
+		} else {
3214
+			return '';
3215
+		}
3216
+	}
3217
+
3218
+
3219
+
3220
+	/**
3221
+	 * The purpose of this method is just to force rechecking php values so if they've changed, they get updated.
3222
+	 *
3223
+	 * @since 4.4.1
3224
+	 * @return void
3225
+	 */
3226
+	public function recheck_values()
3227
+	{
3228
+		$this->_set_php_values();
3229
+	}
3230 3230
 
3231 3231
 
3232 3232
 }
@@ -3243,22 +3243,22 @@  discard block
 block discarded – undo
3243 3243
 class EE_Tax_Config extends EE_Config_Base
3244 3244
 {
3245 3245
 
3246
-    /*
3246
+	/*
3247 3247
      * flag to indicate whether or not to display ticket prices with the taxes included
3248 3248
      *
3249 3249
      * @var boolean $prices_displayed_including_taxes
3250 3250
      */
3251
-    public $prices_displayed_including_taxes;
3251
+	public $prices_displayed_including_taxes;
3252 3252
 
3253 3253
 
3254 3254
 
3255
-    /**
3256
-     *    class constructor
3257
-     */
3258
-    public function __construct()
3259
-    {
3260
-        $this->prices_displayed_including_taxes = true;
3261
-    }
3255
+	/**
3256
+	 *    class constructor
3257
+	 */
3258
+	public function __construct()
3259
+	{
3260
+		$this->prices_displayed_including_taxes = true;
3261
+	}
3262 3262
 }
3263 3263
 
3264 3264
 
@@ -3273,17 +3273,17 @@  discard block
 block discarded – undo
3273 3273
 class EE_Messages_Config extends EE_Config_Base
3274 3274
 {
3275 3275
 
3276
-    /**
3277
-     * This is an integer representing the deletion threshold in months for when old messages will get deleted.
3278
-     * A value of 0 represents never deleting.  Default is 0.
3279
-     *
3280
-     * @var integer
3281
-     */
3282
-    public $delete_threshold;
3283
-
3284
-    public function __construct() {
3285
-        $this->delete_threshold = 0;
3286
-    }
3276
+	/**
3277
+	 * This is an integer representing the deletion threshold in months for when old messages will get deleted.
3278
+	 * A value of 0 represents never deleting.  Default is 0.
3279
+	 *
3280
+	 * @var integer
3281
+	 */
3282
+	public $delete_threshold;
3283
+
3284
+	public function __construct() {
3285
+		$this->delete_threshold = 0;
3286
+	}
3287 3287
 }
3288 3288
 
3289 3289
 
@@ -3295,34 +3295,34 @@  discard block
 block discarded – undo
3295 3295
 class EE_Gateway_Config extends EE_Config_Base
3296 3296
 {
3297 3297
 
3298
-    /**
3299
-     * Array with keys that are payment gateways slugs, and values are arrays
3300
-     * with any config info the gateway wants to store
3301
-     *
3302
-     * @var array
3303
-     */
3304
-    public $payment_settings;
3305
-
3306
-    /**
3307
-     * Where keys are gateway slugs, and values are booleans indicating whether or not
3308
-     * the gateway is stored in the uploads directory
3309
-     *
3310
-     * @var array
3311
-     */
3312
-    public $active_gateways;
3313
-
3314
-
3315
-
3316
-    /**
3317
-     *    class constructor
3318
-     *
3319
-     * @deprecated
3320
-     */
3321
-    public function __construct()
3322
-    {
3323
-        $this->payment_settings = array();
3324
-        $this->active_gateways = array('Invoice' => false);
3325
-    }
3298
+	/**
3299
+	 * Array with keys that are payment gateways slugs, and values are arrays
3300
+	 * with any config info the gateway wants to store
3301
+	 *
3302
+	 * @var array
3303
+	 */
3304
+	public $payment_settings;
3305
+
3306
+	/**
3307
+	 * Where keys are gateway slugs, and values are booleans indicating whether or not
3308
+	 * the gateway is stored in the uploads directory
3309
+	 *
3310
+	 * @var array
3311
+	 */
3312
+	public $active_gateways;
3313
+
3314
+
3315
+
3316
+	/**
3317
+	 *    class constructor
3318
+	 *
3319
+	 * @deprecated
3320
+	 */
3321
+	public function __construct()
3322
+	{
3323
+		$this->payment_settings = array();
3324
+		$this->active_gateways = array('Invoice' => false);
3325
+	}
3326 3326
 }
3327 3327
 
3328 3328
 // End of file EE_Config.core.php
Please login to merge, or discard this patch.
Spacing   +122 added lines, -122 removed lines patch added patch discarded remove patch
@@ -143,7 +143,7 @@  discard block
 block discarded – undo
143 143
     public static function instance()
144 144
     {
145 145
         // check if class object is instantiated, and instantiated properly
146
-        if (! self::$_instance instanceof EE_Config) {
146
+        if ( ! self::$_instance instanceof EE_Config) {
147 147
             self::$_instance = new self();
148 148
         }
149 149
         return self::$_instance;
@@ -286,7 +286,7 @@  discard block
 block discarded – undo
286 286
                 $this
287 287
             );
288 288
             if (is_object($settings) && property_exists($this, $config)) {
289
-                $this->{$config} = apply_filters('FHEE__EE_Config___load_core_config__' . $config, $settings);
289
+                $this->{$config} = apply_filters('FHEE__EE_Config___load_core_config__'.$config, $settings);
290 290
                 //call configs populate method to ensure any defaults are set for empty values.
291 291
                 if (method_exists($settings, 'populate')) {
292 292
                     $this->{$config}->populate();
@@ -550,7 +550,7 @@  discard block
 block discarded – undo
550 550
                         break;
551 551
                     // TEST #2 : check that settings section exists
552 552
                     case 2 :
553
-                        if (! isset($this->{$section})) {
553
+                        if ( ! isset($this->{$section})) {
554 554
                             if ($display_errors) {
555 555
                                 throw new EE_Error(
556 556
                                     sprintf(
@@ -611,7 +611,7 @@  discard block
 block discarded – undo
611 611
                         break;
612 612
                     // TEST #6 : verify config class is accessible
613 613
                     case 6 :
614
-                        if (! class_exists($config_class)) {
614
+                        if ( ! class_exists($config_class)) {
615 615
                             if ($display_errors) {
616 616
                                 throw new EE_Error(
617 617
                                     sprintf(
@@ -628,7 +628,7 @@  discard block
 block discarded – undo
628 628
                         break;
629 629
                     // TEST #7 : check that config has even been set
630 630
                     case 7 :
631
-                        if (! isset($this->{$section}->{$name})) {
631
+                        if ( ! isset($this->{$section}->{$name})) {
632 632
                             if ($display_errors) {
633 633
                                 throw new EE_Error(
634 634
                                     sprintf(
@@ -646,7 +646,7 @@  discard block
 block discarded – undo
646 646
                         break;
647 647
                     // TEST #8 : check that config is the requested type
648 648
                     case 8 :
649
-                        if (! $this->{$section}->{$name} instanceof $config_class) {
649
+                        if ( ! $this->{$section}->{$name} instanceof $config_class) {
650 650
                             if ($display_errors) {
651 651
                                 throw new EE_Error(
652 652
                                     sprintf(
@@ -665,7 +665,7 @@  discard block
 block discarded – undo
665 665
                         break;
666 666
                     // TEST #9 : verify config object
667 667
                     case 9 :
668
-                        if (! $config_obj instanceof EE_Config_Base) {
668
+                        if ( ! $config_obj instanceof EE_Config_Base) {
669 669
                             if ($display_errors) {
670 670
                                 throw new EE_Error(
671 671
                                     sprintf(
@@ -698,7 +698,7 @@  discard block
 block discarded – undo
698 698
      */
699 699
     private function _generate_config_option_name($section = '', $name = '')
700 700
     {
701
-        return 'ee_config-' . strtolower($section . '-' . str_replace(array('EE_', 'EED_'), '', $name));
701
+        return 'ee_config-'.strtolower($section.'-'.str_replace(array('EE_', 'EED_'), '', $name));
702 702
     }
703 703
 
704 704
 
@@ -716,7 +716,7 @@  discard block
 block discarded – undo
716 716
     {
717 717
         return ! empty($config_class)
718 718
             ? $config_class
719
-            : str_replace(' ', '_', ucwords(str_replace('_', ' ', $name))) . '_Config';
719
+            : str_replace(' ', '_', ucwords(str_replace('_', ' ', $name))).'_Config';
720 720
     }
721 721
 
722 722
 
@@ -736,17 +736,17 @@  discard block
 block discarded – undo
736 736
         // ensure config class is set to something
737 737
         $config_class = $this->_set_config_class($config_class, $name);
738 738
         // run tests 1-4, 6, and 7 to verify all config params are set and valid
739
-        if (! $this->_verify_config_params($section, $name, $config_class, null, array(1, 2, 3, 4, 5, 6))) {
739
+        if ( ! $this->_verify_config_params($section, $name, $config_class, null, array(1, 2, 3, 4, 5, 6))) {
740 740
             return null;
741 741
         }
742 742
         $config_option_name = $this->_generate_config_option_name($section, $name);
743 743
         // if the config option name hasn't been added yet to the list of option names we're tracking, then do so now
744
-        if (! isset($this->_addon_option_names[$config_option_name])) {
744
+        if ( ! isset($this->_addon_option_names[$config_option_name])) {
745 745
             $this->_addon_option_names[$config_option_name] = $config_class;
746 746
             $this->update_addon_option_names();
747 747
         }
748 748
         // verify the incoming config object but suppress errors
749
-        if (! $this->_verify_config_params($section, $name, $config_class, $config_obj, array(9), false)) {
749
+        if ( ! $this->_verify_config_params($section, $name, $config_class, $config_obj, array(9), false)) {
750 750
             $config_obj = new $config_class();
751 751
         }
752 752
         if (get_option($config_option_name)) {
@@ -794,7 +794,7 @@  discard block
 block discarded – undo
794 794
         // get class name of the incoming object
795 795
         $config_class = get_class($config_obj);
796 796
         // run tests 1-5 and 9 to verify config
797
-        if (! $this->_verify_config_params(
797
+        if ( ! $this->_verify_config_params(
798 798
             $section,
799 799
             $name,
800 800
             $config_class,
@@ -806,7 +806,7 @@  discard block
 block discarded – undo
806 806
         }
807 807
         $config_option_name = $this->_generate_config_option_name($section, $name);
808 808
         // check if config object has been added to db by seeing if config option name is in $this->_addon_option_names array
809
-        if (! isset($this->_addon_option_names[$config_option_name])) {
809
+        if ( ! isset($this->_addon_option_names[$config_option_name])) {
810 810
             // save new config to db
811 811
             if ($this->set_config($section, $name, $config_class, $config_obj)) {
812 812
                 return true;
@@ -832,7 +832,7 @@  discard block
 block discarded – undo
832 832
                             'event_espresso'
833 833
                         ),
834 834
                         $config_class,
835
-                        'EE_Config->' . $section . '->' . $name
835
+                        'EE_Config->'.$section.'->'.$name
836 836
                     ),
837 837
                     __FILE__,
838 838
                     __FUNCTION__,
@@ -859,7 +859,7 @@  discard block
 block discarded – undo
859 859
         // ensure config class is set to something
860 860
         $config_class = $this->_set_config_class($config_class, $name);
861 861
         // run tests 1-4, 6 and 7 to verify that all params have been set
862
-        if (! $this->_verify_config_params($section, $name, $config_class, null, array(1, 2, 3, 4, 5, 6))) {
862
+        if ( ! $this->_verify_config_params($section, $name, $config_class, null, array(1, 2, 3, 4, 5, 6))) {
863 863
             return null;
864 864
         }
865 865
         // now test if the requested config object exists, but suppress errors
@@ -905,7 +905,7 @@  discard block
 block discarded – undo
905 905
         // retrieve the wp-option for this config class.
906 906
         $config_option = maybe_unserialize(get_option($config_option_name, array()));
907 907
         if (empty($config_option)) {
908
-            EE_Config::log($config_option_name . '-NOT-FOUND');
908
+            EE_Config::log($config_option_name.'-NOT-FOUND');
909 909
         }
910 910
         return $config_option;
911 911
     }
@@ -924,7 +924,7 @@  discard block
 block discarded – undo
924 924
             //copy incoming $_REQUEST and sanitize it so we can save it
925 925
             $_request = $_REQUEST;
926 926
             array_walk_recursive($_request, 'sanitize_text_field');
927
-            $config_log[(string)microtime(true)] = array(
927
+            $config_log[(string) microtime(true)] = array(
928 928
                 'config_name' => $config_option_name,
929 929
                 'request'     => $_request,
930 930
             );
@@ -940,7 +940,7 @@  discard block
 block discarded – undo
940 940
      */
941 941
     public static function trim_log()
942 942
     {
943
-        if (! EE_Config::logging_enabled()) {
943
+        if ( ! EE_Config::logging_enabled()) {
944 944
             return;
945 945
         }
946 946
         $config_log = maybe_unserialize(get_option(EE_Config::LOG_NAME, array()));
@@ -965,7 +965,7 @@  discard block
 block discarded – undo
965 965
     public static function get_page_for_posts()
966 966
     {
967 967
         $page_for_posts = get_option('page_for_posts');
968
-        if (! $page_for_posts) {
968
+        if ( ! $page_for_posts) {
969 969
             return 'posts';
970 970
         }
971 971
         /** @type WPDB $wpdb */
@@ -1030,13 +1030,13 @@  discard block
 block discarded – undo
1030 1030
             )
1031 1031
         ) {
1032 1032
             // grab list of installed widgets
1033
-            $widgets_to_register = glob(EE_WIDGETS . '*', GLOB_ONLYDIR);
1033
+            $widgets_to_register = glob(EE_WIDGETS.'*', GLOB_ONLYDIR);
1034 1034
             // filter list of modules to register
1035 1035
             $widgets_to_register = apply_filters(
1036 1036
                 'FHEE__EE_Config__register_widgets__widgets_to_register',
1037 1037
                 $widgets_to_register
1038 1038
             );
1039
-            if (! empty($widgets_to_register)) {
1039
+            if ( ! empty($widgets_to_register)) {
1040 1040
                 // cycle thru widget folders
1041 1041
                 foreach ($widgets_to_register as $widget_path) {
1042 1042
                     // add to list of installed widget modules
@@ -1087,31 +1087,31 @@  discard block
 block discarded – undo
1087 1087
         // create classname from widget directory name
1088 1088
         $widget = str_replace(' ', '_', ucwords(str_replace('_', ' ', $widget)));
1089 1089
         // add class prefix
1090
-        $widget_class = 'EEW_' . $widget;
1090
+        $widget_class = 'EEW_'.$widget;
1091 1091
         // does the widget exist ?
1092
-        if (! is_readable($widget_path . DS . $widget_class . $widget_ext)) {
1092
+        if ( ! is_readable($widget_path.DS.$widget_class.$widget_ext)) {
1093 1093
             $msg = sprintf(
1094 1094
                 __(
1095 1095
                     'The requested %s widget file could not be found or is not readable due to file permissions. Please ensure the following path is correct: %s',
1096 1096
                     'event_espresso'
1097 1097
                 ),
1098 1098
                 $widget_class,
1099
-                $widget_path . DS . $widget_class . $widget_ext
1099
+                $widget_path.DS.$widget_class.$widget_ext
1100 1100
             );
1101
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1101
+            EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__);
1102 1102
             return;
1103 1103
         }
1104 1104
         // load the widget class file
1105
-        require_once($widget_path . DS . $widget_class . $widget_ext);
1105
+        require_once($widget_path.DS.$widget_class.$widget_ext);
1106 1106
         // verify that class exists
1107
-        if (! class_exists($widget_class)) {
1107
+        if ( ! class_exists($widget_class)) {
1108 1108
             $msg = sprintf(__('The requested %s widget class does not exist.', 'event_espresso'), $widget_class);
1109
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1109
+            EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__);
1110 1110
             return;
1111 1111
         }
1112 1112
         register_widget($widget_class);
1113 1113
         // add to array of registered widgets
1114
-        EE_Registry::instance()->widgets->{$widget_class} = $widget_path . DS . $widget_class . $widget_ext;
1114
+        EE_Registry::instance()->widgets->{$widget_class} = $widget_path.DS.$widget_class.$widget_ext;
1115 1115
     }
1116 1116
 
1117 1117
 
@@ -1125,13 +1125,13 @@  discard block
 block discarded – undo
1125 1125
     private function _register_shortcodes()
1126 1126
     {
1127 1127
         // grab list of installed shortcodes
1128
-        $shortcodes_to_register = glob(EE_SHORTCODES . '*', GLOB_ONLYDIR);
1128
+        $shortcodes_to_register = glob(EE_SHORTCODES.'*', GLOB_ONLYDIR);
1129 1129
         // filter list of modules to register
1130 1130
         $shortcodes_to_register = apply_filters(
1131 1131
             'FHEE__EE_Config__register_shortcodes__shortcodes_to_register',
1132 1132
             $shortcodes_to_register
1133 1133
         );
1134
-        if (! empty($shortcodes_to_register)) {
1134
+        if ( ! empty($shortcodes_to_register)) {
1135 1135
             // cycle thru shortcode folders
1136 1136
             foreach ($shortcodes_to_register as $shortcode_path) {
1137 1137
                 // add to list of installed shortcode modules
@@ -1175,44 +1175,44 @@  discard block
 block discarded – undo
1175 1175
             // remove last segment
1176 1176
             array_pop($shortcode_path);
1177 1177
             // glue it back together
1178
-            $shortcode_path = implode(DS, $shortcode_path) . DS;
1178
+            $shortcode_path = implode(DS, $shortcode_path).DS;
1179 1179
         } else {
1180 1180
             // we need to generate the filename based off of the folder name
1181 1181
             // grab and sanitize shortcode directory name
1182 1182
             $shortcode = sanitize_key(basename($shortcode_path));
1183
-            $shortcode_path = rtrim($shortcode_path, DS) . DS;
1183
+            $shortcode_path = rtrim($shortcode_path, DS).DS;
1184 1184
         }
1185 1185
         // create classname from shortcode directory or file name
1186 1186
         $shortcode = str_replace(' ', '_', ucwords(str_replace('_', ' ', $shortcode)));
1187 1187
         // add class prefix
1188
-        $shortcode_class = 'EES_' . $shortcode;
1188
+        $shortcode_class = 'EES_'.$shortcode;
1189 1189
         // does the shortcode exist ?
1190
-        if (! is_readable($shortcode_path . DS . $shortcode_class . $shortcode_ext)) {
1190
+        if ( ! is_readable($shortcode_path.DS.$shortcode_class.$shortcode_ext)) {
1191 1191
             $msg = sprintf(
1192 1192
                 __(
1193 1193
                     'The requested %s shortcode file could not be found or is not readable due to file permissions. It should be in %s',
1194 1194
                     'event_espresso'
1195 1195
                 ),
1196 1196
                 $shortcode_class,
1197
-                $shortcode_path . DS . $shortcode_class . $shortcode_ext
1197
+                $shortcode_path.DS.$shortcode_class.$shortcode_ext
1198 1198
             );
1199
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1199
+            EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__);
1200 1200
             return false;
1201 1201
         }
1202 1202
         // load the shortcode class file
1203
-        require_once($shortcode_path . $shortcode_class . $shortcode_ext);
1203
+        require_once($shortcode_path.$shortcode_class.$shortcode_ext);
1204 1204
         // verify that class exists
1205
-        if (! class_exists($shortcode_class)) {
1205
+        if ( ! class_exists($shortcode_class)) {
1206 1206
             $msg = sprintf(
1207 1207
                 __('The requested %s shortcode class does not exist.', 'event_espresso'),
1208 1208
                 $shortcode_class
1209 1209
             );
1210
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1210
+            EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__);
1211 1211
             return false;
1212 1212
         }
1213 1213
         $shortcode = strtoupper($shortcode);
1214 1214
         // add to array of registered shortcodes
1215
-        EE_Registry::instance()->shortcodes->{$shortcode} = $shortcode_path . $shortcode_class . $shortcode_ext;
1215
+        EE_Registry::instance()->shortcodes->{$shortcode} = $shortcode_path.$shortcode_class.$shortcode_ext;
1216 1216
         return true;
1217 1217
     }
1218 1218
 
@@ -1227,19 +1227,19 @@  discard block
 block discarded – undo
1227 1227
     private function _register_modules()
1228 1228
     {
1229 1229
         // grab list of installed modules
1230
-        $modules_to_register = glob(EE_MODULES . '*', GLOB_ONLYDIR);
1230
+        $modules_to_register = glob(EE_MODULES.'*', GLOB_ONLYDIR);
1231 1231
         // filter list of modules to register
1232 1232
         $modules_to_register = apply_filters(
1233 1233
             'FHEE__EE_Config__register_modules__modules_to_register',
1234 1234
             $modules_to_register
1235 1235
         );
1236
-        if (! empty($modules_to_register)) {
1236
+        if ( ! empty($modules_to_register)) {
1237 1237
             // loop through folders
1238 1238
             foreach ($modules_to_register as $module_path) {
1239 1239
                 /**TEMPORARILY EXCLUDE gateways from modules for time being**/
1240 1240
                 if (
1241
-                    $module_path !== EE_MODULES . 'zzz-copy-this-module-template'
1242
-                    && $module_path !== EE_MODULES . 'gateways'
1241
+                    $module_path !== EE_MODULES.'zzz-copy-this-module-template'
1242
+                    && $module_path !== EE_MODULES.'gateways'
1243 1243
                 ) {
1244 1244
                     // add to list of installed modules
1245 1245
                     EE_Config::register_module($module_path);
@@ -1277,25 +1277,25 @@  discard block
 block discarded – undo
1277 1277
             // remove last segment
1278 1278
             array_pop($module_path);
1279 1279
             // glue it back together
1280
-            $module_path = implode(DS, $module_path) . DS;
1280
+            $module_path = implode(DS, $module_path).DS;
1281 1281
             // take first segment from file name pieces and sanitize it
1282 1282
             $module = preg_replace('/[^a-zA-Z0-9_\-]/', '', $module_file[0]);
1283 1283
             // ensure class prefix is added
1284
-            $module_class = strpos($module, 'EED_') !== 0 ? 'EED_' . $module : $module;
1284
+            $module_class = strpos($module, 'EED_') !== 0 ? 'EED_'.$module : $module;
1285 1285
         } else {
1286 1286
             // we need to generate the filename based off of the folder name
1287 1287
             // grab and sanitize module name
1288 1288
             $module = strtolower(basename($module_path));
1289 1289
             $module = preg_replace('/[^a-z0-9_\-]/', '', $module);
1290 1290
             // like trailingslashit()
1291
-            $module_path = rtrim($module_path, DS) . DS;
1291
+            $module_path = rtrim($module_path, DS).DS;
1292 1292
             // create classname from module directory name
1293 1293
             $module = str_replace(' ', '_', ucwords(str_replace('_', ' ', $module)));
1294 1294
             // add class prefix
1295
-            $module_class = 'EED_' . $module;
1295
+            $module_class = 'EED_'.$module;
1296 1296
         }
1297 1297
         // does the module exist ?
1298
-        if (! is_readable($module_path . DS . $module_class . $module_ext)) {
1298
+        if ( ! is_readable($module_path.DS.$module_class.$module_ext)) {
1299 1299
             $msg = sprintf(
1300 1300
                 __(
1301 1301
                     'The requested %s module file could not be found or is not readable due to file permissions.',
@@ -1303,19 +1303,19 @@  discard block
 block discarded – undo
1303 1303
                 ),
1304 1304
                 $module
1305 1305
             );
1306
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1306
+            EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__);
1307 1307
             return false;
1308 1308
         }
1309 1309
         // load the module class file
1310
-        require_once($module_path . $module_class . $module_ext);
1310
+        require_once($module_path.$module_class.$module_ext);
1311 1311
         // verify that class exists
1312
-        if (! class_exists($module_class)) {
1312
+        if ( ! class_exists($module_class)) {
1313 1313
             $msg = sprintf(__('The requested %s module class does not exist.', 'event_espresso'), $module_class);
1314
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1314
+            EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__);
1315 1315
             return false;
1316 1316
         }
1317 1317
         // add to array of registered modules
1318
-        EE_Registry::instance()->modules->{$module_class} = $module_path . $module_class . $module_ext;
1318
+        EE_Registry::instance()->modules->{$module_class} = $module_path.$module_class.$module_ext;
1319 1319
         do_action(
1320 1320
             'AHEE__EE_Config__register_module__complete',
1321 1321
             $module_class,
@@ -1338,7 +1338,7 @@  discard block
 block discarded – undo
1338 1338
         // cycle thru shortcode folders
1339 1339
         foreach (EE_Registry::instance()->shortcodes as $shortcode => $shortcode_path) {
1340 1340
             // add class prefix
1341
-            $shortcode_class = 'EES_' . $shortcode;
1341
+            $shortcode_class = 'EES_'.$shortcode;
1342 1342
             // fire the shortcode class's set_hooks methods in case it needs to hook into other parts of the system
1343 1343
             // which set hooks ?
1344 1344
             if (is_admin()) {
@@ -1353,7 +1353,7 @@  discard block
 block discarded – undo
1353 1353
                 // convert classname to UPPERCASE and create WP shortcode.
1354 1354
                 $shortcode_tag = strtoupper($shortcode);
1355 1355
                 // but first check if the shortcode has already been added before assigning 'fallback_shortcode_processor'
1356
-                if (! shortcode_exists($shortcode_tag)) {
1356
+                if ( ! shortcode_exists($shortcode_tag)) {
1357 1357
                     // NOTE: this shortcode declaration will get overridden if the shortcode is successfully detected in the post content in EE_Front_Controller->_initialize_shortcodes()
1358 1358
                     add_shortcode($shortcode_tag, array($shortcode_class, 'fallback_shortcode_processor'));
1359 1359
                 }
@@ -1405,26 +1405,26 @@  discard block
 block discarded – undo
1405 1405
     {
1406 1406
         do_action('AHEE__EE_Config__register_route__begin', $route, $module, $method_name);
1407 1407
         $module = str_replace('EED_', '', $module);
1408
-        $module_class = 'EED_' . $module;
1409
-        if (! isset(EE_Registry::instance()->modules->{$module_class})) {
1408
+        $module_class = 'EED_'.$module;
1409
+        if ( ! isset(EE_Registry::instance()->modules->{$module_class})) {
1410 1410
             $msg = sprintf(__('The module %s has not been registered.', 'event_espresso'), $module);
1411
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1411
+            EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__);
1412 1412
             return false;
1413 1413
         }
1414 1414
         if (empty($route)) {
1415 1415
             $msg = sprintf(__('No route has been supplied.', 'event_espresso'), $route);
1416
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1416
+            EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__);
1417 1417
             return false;
1418 1418
         }
1419
-        if (! method_exists('EED_' . $module, $method_name)) {
1419
+        if ( ! method_exists('EED_'.$module, $method_name)) {
1420 1420
             $msg = sprintf(
1421 1421
                 __('A valid class method for the %s route has not been supplied.', 'event_espresso'),
1422 1422
                 $route
1423 1423
             );
1424
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1424
+            EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__);
1425 1425
             return false;
1426 1426
         }
1427
-        EE_Config::$_module_route_map[$key][$route] = array('EED_' . $module, $method_name);
1427
+        EE_Config::$_module_route_map[$key][$route] = array('EED_'.$module, $method_name);
1428 1428
         return true;
1429 1429
     }
1430 1430
 
@@ -1441,7 +1441,7 @@  discard block
 block discarded – undo
1441 1441
     public static function get_route($route = null, $key = 'ee')
1442 1442
     {
1443 1443
         do_action('AHEE__EE_Config__get_route__begin', $route);
1444
-        $route = (string)apply_filters('FHEE__EE_Config__get_route', $route);
1444
+        $route = (string) apply_filters('FHEE__EE_Config__get_route', $route);
1445 1445
         if (isset(EE_Config::$_module_route_map[$key][$route])) {
1446 1446
             return EE_Config::$_module_route_map[$key][$route];
1447 1447
         }
@@ -1477,44 +1477,44 @@  discard block
 block discarded – undo
1477 1477
     public static function register_forward($route = null, $status = 0, $forward = null, $key = 'ee')
1478 1478
     {
1479 1479
         do_action('AHEE__EE_Config__register_forward', $route, $status, $forward);
1480
-        if (! isset(EE_Config::$_module_route_map[$key][$route]) || empty($route)) {
1480
+        if ( ! isset(EE_Config::$_module_route_map[$key][$route]) || empty($route)) {
1481 1481
             $msg = sprintf(
1482 1482
                 __('The module route %s for this forward has not been registered.', 'event_espresso'),
1483 1483
                 $route
1484 1484
             );
1485
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1485
+            EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__);
1486 1486
             return false;
1487 1487
         }
1488 1488
         if (empty($forward)) {
1489 1489
             $msg = sprintf(__('No forwarding route has been supplied.', 'event_espresso'), $route);
1490
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1490
+            EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__);
1491 1491
             return false;
1492 1492
         }
1493 1493
         if (is_array($forward)) {
1494
-            if (! isset($forward[1])) {
1494
+            if ( ! isset($forward[1])) {
1495 1495
                 $msg = sprintf(
1496 1496
                     __('A class method for the %s forwarding route has not been supplied.', 'event_espresso'),
1497 1497
                     $route
1498 1498
                 );
1499
-                EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1499
+                EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__);
1500 1500
                 return false;
1501 1501
             }
1502
-            if (! method_exists($forward[0], $forward[1])) {
1502
+            if ( ! method_exists($forward[0], $forward[1])) {
1503 1503
                 $msg = sprintf(
1504 1504
                     __('The class method %s for the %s forwarding route is in invalid.', 'event_espresso'),
1505 1505
                     $forward[1],
1506 1506
                     $route
1507 1507
                 );
1508
-                EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1508
+                EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__);
1509 1509
                 return false;
1510 1510
             }
1511
-        } else if (! function_exists($forward)) {
1511
+        } else if ( ! function_exists($forward)) {
1512 1512
             $msg = sprintf(
1513 1513
                 __('The function %s for the %s forwarding route is in invalid.', 'event_espresso'),
1514 1514
                 $forward,
1515 1515
                 $route
1516 1516
             );
1517
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1517
+            EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__);
1518 1518
             return false;
1519 1519
         }
1520 1520
         EE_Config::$_module_forward_map[$key][$route][absint($status)] = $forward;
@@ -1564,15 +1564,15 @@  discard block
 block discarded – undo
1564 1564
     public static function register_view($route = null, $status = 0, $view = null, $key = 'ee')
1565 1565
     {
1566 1566
         do_action('AHEE__EE_Config__register_view__begin', $route, $status, $view);
1567
-        if (! isset(EE_Config::$_module_route_map[$key][$route]) || empty($route)) {
1567
+        if ( ! isset(EE_Config::$_module_route_map[$key][$route]) || empty($route)) {
1568 1568
             $msg = sprintf(
1569 1569
                 __('The module route %s for this view has not been registered.', 'event_espresso'),
1570 1570
                 $route
1571 1571
             );
1572
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1572
+            EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__);
1573 1573
             return false;
1574 1574
         }
1575
-        if (! is_readable($view)) {
1575
+        if ( ! is_readable($view)) {
1576 1576
             $msg = sprintf(
1577 1577
                 __(
1578 1578
                     'The %s view file could not be found or is not readable due to file permissions.',
@@ -1580,7 +1580,7 @@  discard block
 block discarded – undo
1580 1580
                 ),
1581 1581
                 $view
1582 1582
             );
1583
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1583
+            EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__);
1584 1584
             return false;
1585 1585
         }
1586 1586
         EE_Config::$_module_view_map[$key][$route][absint($status)] = $view;
@@ -1649,7 +1649,7 @@  discard block
 block discarded – undo
1649 1649
      */
1650 1650
     public function get_pretty($property)
1651 1651
     {
1652
-        if (! property_exists($this, $property)) {
1652
+        if ( ! property_exists($this, $property)) {
1653 1653
             throw new EE_Error(
1654 1654
                 sprintf(
1655 1655
                     __(
@@ -1893,11 +1893,11 @@  discard block
 block discarded – undo
1893 1893
      */
1894 1894
     public function reg_page_url()
1895 1895
     {
1896
-        if (! $this->reg_page_url) {
1896
+        if ( ! $this->reg_page_url) {
1897 1897
             $this->reg_page_url = add_query_arg(
1898 1898
                                       array('uts' => time()),
1899 1899
                                       get_permalink($this->reg_page_id)
1900
-                                  ) . '#checkout';
1900
+                                  ).'#checkout';
1901 1901
         }
1902 1902
         return $this->reg_page_url;
1903 1903
     }
@@ -1914,7 +1914,7 @@  discard block
 block discarded – undo
1914 1914
      */
1915 1915
     public function txn_page_url($query_args = array())
1916 1916
     {
1917
-        if (! $this->txn_page_url) {
1917
+        if ( ! $this->txn_page_url) {
1918 1918
             $this->txn_page_url = get_permalink($this->txn_page_id);
1919 1919
         }
1920 1920
         if ($query_args) {
@@ -1936,7 +1936,7 @@  discard block
 block discarded – undo
1936 1936
      */
1937 1937
     public function thank_you_page_url($query_args = array())
1938 1938
     {
1939
-        if (! $this->thank_you_page_url) {
1939
+        if ( ! $this->thank_you_page_url) {
1940 1940
             $this->thank_you_page_url = get_permalink($this->thank_you_page_id);
1941 1941
         }
1942 1942
         if ($query_args) {
@@ -1956,7 +1956,7 @@  discard block
 block discarded – undo
1956 1956
      */
1957 1957
     public function cancel_page_url()
1958 1958
     {
1959
-        if (! $this->cancel_page_url) {
1959
+        if ( ! $this->cancel_page_url) {
1960 1960
             $this->cancel_page_url = get_permalink($this->cancel_page_id);
1961 1961
         }
1962 1962
         return $this->cancel_page_url;
@@ -2001,13 +2001,13 @@  discard block
 block discarded – undo
2001 2001
         $current_main_site_id = ! empty($current_network_main_site) ? $current_network_main_site->blog_id : 1;
2002 2002
         $option = 'ee_ueip_optin';
2003 2003
         //set correct table for query
2004
-        $table_name = $wpdb->get_blog_prefix($current_main_site_id) . 'options';
2004
+        $table_name = $wpdb->get_blog_prefix($current_main_site_id).'options';
2005 2005
         //rather than getting blog option for the $current_main_site_id, we do a direct $wpdb query because
2006 2006
         //get_blog_option() does a switch_to_blog an that could cause infinite recursion because EE_Core_Config might be
2007 2007
         //re-constructed on the blog switch.  Note, we are still executing any core wp filters on this option retrieval.
2008 2008
         //this bit of code is basically a direct copy of get_option without any caching because we are NOT switched to the blog
2009 2009
         //for the purpose of caching.
2010
-        $pre = apply_filters('pre_option_' . $option, false, $option);
2010
+        $pre = apply_filters('pre_option_'.$option, false, $option);
2011 2011
         if (false !== $pre) {
2012 2012
             EE_Core_Config::$ee_ueip_option = $pre;
2013 2013
             return EE_Core_Config::$ee_ueip_option;
@@ -2017,9 +2017,9 @@  discard block
 block discarded – undo
2017 2017
         if (is_object($row)) {
2018 2018
             $value = $row->option_value;
2019 2019
         } else { //option does not exist so use default.
2020
-            return apply_filters('default_option_' . $option, false, $option);
2020
+            return apply_filters('default_option_'.$option, false, $option);
2021 2021
         }
2022
-        EE_Core_Config::$ee_ueip_option = apply_filters('option_' . $option, maybe_unserialize($value), $option);
2022
+        EE_Core_Config::$ee_ueip_option = apply_filters('option_'.$option, maybe_unserialize($value), $option);
2023 2023
         return EE_Core_Config::$ee_ueip_option;
2024 2024
     }
2025 2025
 
@@ -2296,27 +2296,27 @@  discard block
 block discarded – undo
2296 2296
             // retrieve the country settings from the db, just in case they have been customized
2297 2297
             $country = EE_Registry::instance()->load_model('Country')->get_one_by_ID($CNT_ISO);
2298 2298
             if ($country instanceof EE_Country) {
2299
-                $this->code = $country->currency_code();    // currency code: USD, CAD, EUR
2300
-                $this->name = $country->currency_name_single();    // Dollar
2301
-                $this->plural = $country->currency_name_plural();    // Dollars
2302
-                $this->sign = $country->currency_sign();            // currency sign: $
2303
-                $this->sign_b4 = $country->currency_sign_before();        // currency sign before or after: $TRUE  or  FALSE$
2304
-                $this->dec_plc = $country->currency_decimal_places();    // decimal places: 2 = 0.00  3 = 0.000
2305
-                $this->dec_mrk = $country->currency_decimal_mark();    // decimal mark: (comma) ',' = 0,01   or (decimal) '.' = 0.01
2306
-                $this->thsnds = $country->currency_thousands_separator();    // thousands separator: (comma) ',' = 1,000   or (decimal) '.' = 1.000
2299
+                $this->code = $country->currency_code(); // currency code: USD, CAD, EUR
2300
+                $this->name = $country->currency_name_single(); // Dollar
2301
+                $this->plural = $country->currency_name_plural(); // Dollars
2302
+                $this->sign = $country->currency_sign(); // currency sign: $
2303
+                $this->sign_b4 = $country->currency_sign_before(); // currency sign before or after: $TRUE  or  FALSE$
2304
+                $this->dec_plc = $country->currency_decimal_places(); // decimal places: 2 = 0.00  3 = 0.000
2305
+                $this->dec_mrk = $country->currency_decimal_mark(); // decimal mark: (comma) ',' = 0,01   or (decimal) '.' = 0.01
2306
+                $this->thsnds = $country->currency_thousands_separator(); // thousands separator: (comma) ',' = 1,000   or (decimal) '.' = 1.000
2307 2307
             }
2308 2308
         }
2309 2309
         // fallback to hardcoded defaults, in case the above failed
2310 2310
         if (empty($this->code)) {
2311 2311
             // set default currency settings
2312
-            $this->code = 'USD';    // currency code: USD, CAD, EUR
2313
-            $this->name = __('Dollar', 'event_espresso');    // Dollar
2314
-            $this->plural = __('Dollars', 'event_espresso');    // Dollars
2315
-            $this->sign = '$';    // currency sign: $
2316
-            $this->sign_b4 = true;    // currency sign before or after: $TRUE  or  FALSE$
2317
-            $this->dec_plc = 2;    // decimal places: 2 = 0.00  3 = 0.000
2318
-            $this->dec_mrk = '.';    // decimal mark: (comma) ',' = 0,01   or (decimal) '.' = 0.01
2319
-            $this->thsnds = ',';    // thousands separator: (comma) ',' = 1,000   or (decimal) '.' = 1.000
2312
+            $this->code = 'USD'; // currency code: USD, CAD, EUR
2313
+            $this->name = __('Dollar', 'event_espresso'); // Dollar
2314
+            $this->plural = __('Dollars', 'event_espresso'); // Dollars
2315
+            $this->sign = '$'; // currency sign: $
2316
+            $this->sign_b4 = true; // currency sign before or after: $TRUE  or  FALSE$
2317
+            $this->dec_plc = 2; // decimal places: 2 = 0.00  3 = 0.000
2318
+            $this->dec_mrk = '.'; // decimal mark: (comma) ',' = 0,01   or (decimal) '.' = 0.01
2319
+            $this->thsnds = ','; // thousands separator: (comma) ',' = 1,000   or (decimal) '.' = 1.000
2320 2320
         }
2321 2321
     }
2322 2322
 }
@@ -2639,7 +2639,7 @@  discard block
 block discarded – undo
2639 2639
     public function log_file_name($reset = false)
2640 2640
     {
2641 2641
         if (empty($this->log_file_name) || $reset) {
2642
-            $this->log_file_name = sanitize_key('espresso_log_' . md5(uniqid('', true))) . '.txt';
2642
+            $this->log_file_name = sanitize_key('espresso_log_'.md5(uniqid('', true))).'.txt';
2643 2643
             EE_Config::instance()->update_espresso_config(false, false);
2644 2644
         }
2645 2645
         return $this->log_file_name;
@@ -2654,7 +2654,7 @@  discard block
 block discarded – undo
2654 2654
     public function debug_file_name($reset = false)
2655 2655
     {
2656 2656
         if (empty($this->debug_file_name) || $reset) {
2657
-            $this->debug_file_name = sanitize_key('espresso_debug_' . md5(uniqid('', true))) . '.txt';
2657
+            $this->debug_file_name = sanitize_key('espresso_debug_'.md5(uniqid('', true))).'.txt';
2658 2658
             EE_Config::instance()->update_espresso_config(false, false);
2659 2659
         }
2660 2660
         return $this->debug_file_name;
@@ -2870,21 +2870,21 @@  discard block
 block discarded – undo
2870 2870
         $this->use_google_maps = true;
2871 2871
         $this->google_map_api_key = '';
2872 2872
         // for event details pages (reg page)
2873
-        $this->event_details_map_width = 585;            // ee_map_width_single
2874
-        $this->event_details_map_height = 362;            // ee_map_height_single
2875
-        $this->event_details_map_zoom = 14;            // ee_map_zoom_single
2876
-        $this->event_details_display_nav = true;            // ee_map_nav_display_single
2877
-        $this->event_details_nav_size = false;            // ee_map_nav_size_single
2878
-        $this->event_details_control_type = 'default';        // ee_map_type_control_single
2879
-        $this->event_details_map_align = 'center';            // ee_map_align_single
2873
+        $this->event_details_map_width = 585; // ee_map_width_single
2874
+        $this->event_details_map_height = 362; // ee_map_height_single
2875
+        $this->event_details_map_zoom = 14; // ee_map_zoom_single
2876
+        $this->event_details_display_nav = true; // ee_map_nav_display_single
2877
+        $this->event_details_nav_size = false; // ee_map_nav_size_single
2878
+        $this->event_details_control_type = 'default'; // ee_map_type_control_single
2879
+        $this->event_details_map_align = 'center'; // ee_map_align_single
2880 2880
         // for event list pages
2881
-        $this->event_list_map_width = 300;            // ee_map_width
2882
-        $this->event_list_map_height = 185;        // ee_map_height
2883
-        $this->event_list_map_zoom = 12;            // ee_map_zoom
2884
-        $this->event_list_display_nav = false;        // ee_map_nav_display
2885
-        $this->event_list_nav_size = true;            // ee_map_nav_size
2886
-        $this->event_list_control_type = 'dropdown';        // ee_map_type_control
2887
-        $this->event_list_map_align = 'center';            // ee_map_align
2881
+        $this->event_list_map_width = 300; // ee_map_width
2882
+        $this->event_list_map_height = 185; // ee_map_height
2883
+        $this->event_list_map_zoom = 12; // ee_map_zoom
2884
+        $this->event_list_display_nav = false; // ee_map_nav_display
2885
+        $this->event_list_nav_size = true; // ee_map_nav_size
2886
+        $this->event_list_control_type = 'dropdown'; // ee_map_type_control
2887
+        $this->event_list_map_align = 'center'; // ee_map_align
2888 2888
     }
2889 2889
 
2890 2890
 }
@@ -3197,7 +3197,7 @@  discard block
 block discarded – undo
3197 3197
      */
3198 3198
     public function max_input_vars_limit_check($input_count = 0)
3199 3199
     {
3200
-        if (! empty($this->php->max_input_vars)
3200
+        if ( ! empty($this->php->max_input_vars)
3201 3201
             && ($input_count >= $this->php->max_input_vars)
3202 3202
             && (PHP_MAJOR_VERSION >= 5 && PHP_MINOR_VERSION >= 3 && PHP_RELEASE_VERSION >= 9)
3203 3203
         ) {
Please login to merge, or discard this patch.
core/services/formatters/FormatterInterface.php 1 patch
Indentation   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -16,23 +16,23 @@
 block discarded – undo
16 16
 interface FormatterInterface
17 17
 {
18 18
 
19
-    /**
20
-     * Applies the formatting to all items in the array
21
-     *
22
-     * @param array $input accepts a multi-dimensional array, but all "leaf nodes" are easily cast to a string
23
-     * @return array
24
-     */
25
-    public function formatArray($input);
26
-
27
-
28
-
29
-    /**
30
-     * Formats the string
31
-     *
32
-     * @param string|int|float $input anything easily cast into a string
33
-     * @return string
34
-     */
35
-    public function format($input);
19
+	/**
20
+	 * Applies the formatting to all items in the array
21
+	 *
22
+	 * @param array $input accepts a multi-dimensional array, but all "leaf nodes" are easily cast to a string
23
+	 * @return array
24
+	 */
25
+	public function formatArray($input);
26
+
27
+
28
+
29
+	/**
30
+	 * Formats the string
31
+	 *
32
+	 * @param string|int|float $input anything easily cast into a string
33
+	 * @return string
34
+	 */
35
+	public function format($input);
36 36
 }
37 37
 // End of file FormatterInterface.php
38 38
 // Location: core\services\formatters/FormatterInterface.php
39 39
\ No newline at end of file
Please login to merge, or discard this patch.
core/db_classes/EE_Registration.class.php 3 patches
Doc Comments   +4 added lines, -3 removed lines patch added patch discarded remove patch
@@ -921,7 +921,7 @@  discard block
 block discarded – undo
921 921
 	/**
922 922
 	 * Sets deleted
923 923
 	 * @param boolean $deleted
924
-	 * @return boolean
924
+	 * @return boolean|null
925 925
 	 */
926 926
 	public function set_deleted($deleted) {
927 927
 	    if ( $deleted ) {
@@ -969,6 +969,7 @@  discard block
 block discarded – undo
969 969
 	 *
970 970
 	 * @param int | EE_Datetime $DTT_OR_ID The datetime the registration is being checked against
971 971
 	 * @param bool   $check_approved   This is used to indicate whether the caller wants can_checkin to also consider registration status as well as datetime access.
972
+	 * @param integer $DTT_OR_ID
972 973
 	 *
973 974
 	 * @return bool
974 975
 	 */
@@ -1107,7 +1108,7 @@  discard block
 block discarded – undo
1107 1108
      * Returns the latest datetime related to this registration (via the ticket attached to the registration).
1108 1109
      * "Latest" is defined by the `DTT_EVT_start` column.
1109 1110
      *
1110
-     * @return EE_Datetime|null
1111
+     * @return null|EE_Base_Class
1111 1112
      * @throws \EE_Error
1112 1113
      */
1113 1114
 	public function get_latest_related_datetime() {
@@ -1378,7 +1379,7 @@  discard block
 block discarded – undo
1378 1379
 	 * This grabs the payment method corresponding to the last payment made for the amount owing on the registration.
1379 1380
 	 * Note: if there are no payments on the registration there will be no payment method returned.
1380 1381
 	 *
1381
-	 * @return EE_Payment_Method|null
1382
+	 * @return null|EE_Base_Class
1382 1383
 	 */
1383 1384
 	public function payment_method() {
1384 1385
 		return EEM_Payment_Method::instance()->get_last_used_for_registration( $this );
Please login to merge, or discard this patch.
Indentation   +242 added lines, -242 removed lines patch added patch discarded remove patch
@@ -35,7 +35,7 @@  discard block
 block discarded – undo
35 35
 
36 36
 	/**
37 37
 	 * extra meta key for tracking reg status os trashed registrations
38
-     *
38
+	 *
39 39
 	 * @type string
40 40
 	 */
41 41
 	const PRE_TRASH_REG_STATUS_KEY = 'pre_trash_registration_status';
@@ -43,7 +43,7 @@  discard block
 block discarded – undo
43 43
 
44 44
 	/**
45 45
 	 * extra meta key for tracking if registration has reserved ticket
46
-     *
46
+	 *
47 47
 	 * @type string
48 48
 	 */
49 49
 	const HAS_RESERVED_TICKET_KEY = 'has_reserved_ticket';
@@ -89,15 +89,15 @@  discard block
 block discarded – undo
89 89
 
90 90
 
91 91
 
92
-    /**
93
-     * Overrides parent set() method so that all calls to set( 'REG_code', $REG_code ) OR set( 'STS_ID', $STS_ID ) can be routed to internal methods
94
-     *
95
-     * @param string $field_name
96
-     * @param mixed  $field_value
97
-     * @param bool   $use_default
98
-     * @throws \EE_Error
99
-     * @throws \RuntimeException
100
-     */
92
+	/**
93
+	 * Overrides parent set() method so that all calls to set( 'REG_code', $REG_code ) OR set( 'STS_ID', $STS_ID ) can be routed to internal methods
94
+	 *
95
+	 * @param string $field_name
96
+	 * @param mixed  $field_value
97
+	 * @param bool   $use_default
98
+	 * @throws \EE_Error
99
+	 * @throws \RuntimeException
100
+	 */
101 101
 	public function set( $field_name, $field_value, $use_default = FALSE ) {
102 102
 		switch( $field_name ) {
103 103
 			case 'REG_code' :
@@ -115,18 +115,18 @@  discard block
 block discarded – undo
115 115
 
116 116
 
117 117
 
118
-    /**
119
-     * Set Status ID
120
-     * updates the registration status and ALSO...
121
-     * calls reserve_registration_space() if the reg status changes TO approved from any other reg status
122
-     * calls release_registration_space() if the reg status changes FROM approved to any other reg status
123
-     *
124
-     * @param string  $new_STS_ID
125
-     * @param boolean $use_default
126
-     * @return bool
127
-     * @throws \RuntimeException
128
-     * @throws \EE_Error
129
-     */
118
+	/**
119
+	 * Set Status ID
120
+	 * updates the registration status and ALSO...
121
+	 * calls reserve_registration_space() if the reg status changes TO approved from any other reg status
122
+	 * calls release_registration_space() if the reg status changes FROM approved to any other reg status
123
+	 *
124
+	 * @param string  $new_STS_ID
125
+	 * @param boolean $use_default
126
+	 * @return bool
127
+	 * @throws \RuntimeException
128
+	 * @throws \EE_Error
129
+	 */
130 130
 	public function set_status( $new_STS_ID = NULL, $use_default = FALSE ) {
131 131
 		// get current REG_Status
132 132
 		$old_STS_ID = $this->status_ID();
@@ -137,7 +137,7 @@  discard block
 block discarded – undo
137 137
 			&& ! empty( $new_STS_ID ) // as well as the new status
138 138
 			&& $this->ID() // ensure registration is in the db
139 139
 		) {
140
-            // TO approved
140
+			// TO approved
141 141
 			if ( $new_STS_ID === EEM_Registration::status_id_approved ) {
142 142
 				// reserve a space by incrementing ticket and datetime sold values
143 143
 				$this->_reserve_registration_space();
@@ -148,12 +148,12 @@  discard block
 block discarded – undo
148 148
 				$this->_release_registration_space();
149 149
 				do_action( 'AHEE__EE_Registration__set_status__from_approved', $this, $old_STS_ID, $new_STS_ID );
150 150
 			}
151
-            // update status
152
-            parent::set('STS_ID', $new_STS_ID, $use_default);
153
-            $this->_update_if_canceled_or_declined($new_STS_ID, $old_STS_ID);
154
-            /** @type EE_Transaction_Payments $transaction_payments */
155
-            $transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments');
156
-            $transaction_payments->recalculate_transaction_total( $this->transaction(), false );
151
+			// update status
152
+			parent::set('STS_ID', $new_STS_ID, $use_default);
153
+			$this->_update_if_canceled_or_declined($new_STS_ID, $old_STS_ID);
154
+			/** @type EE_Transaction_Payments $transaction_payments */
155
+			$transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments');
156
+			$transaction_payments->recalculate_transaction_total( $this->transaction(), false );
157 157
 			$this->transaction()->update_status_based_on_total_paid( true );
158 158
 			do_action( 'AHEE__EE_Registration__set_status__after_update', $this );
159 159
 			return TRUE;
@@ -167,60 +167,60 @@  discard block
 block discarded – undo
167 167
 
168 168
 
169 169
 
170
-    /**
171
-     * update REGs and TXN when cancelled or declined registrations involved
172
-     *
173
-     * @param string $new_STS_ID
174
-     * @param string $old_STS_ID
175
-     * @throws \EE_Error
176
-     */
177
-    private function _update_if_canceled_or_declined($new_STS_ID, $old_STS_ID)
178
-    {
179
-        // these reg statuses should not be considered in any calculations involving monies owing
180
-        $closed_reg_statuses = EEM_Registration::closed_reg_statuses();
181
-        // true if registration has been cancelled or declined
182
-        if (
183
-            in_array($new_STS_ID, $closed_reg_statuses, true)
184
-            && ! in_array($old_STS_ID, $closed_reg_statuses, true)
185
-        ) {
186
-            /** @type EE_Registration_Processor $registration_processor */
187
-            $registration_processor = EE_Registry::instance()->load_class('Registration_Processor');
188
-            /** @type EE_Transaction_Processor $transaction_processor */
189
-            $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor');
190
-            // cancelled or declined registration
191
-            $registration_processor->update_registration_after_being_canceled_or_declined(
192
-                $this,
193
-                $closed_reg_statuses
194
-            );
195
-            $transaction_processor->update_transaction_after_canceled_or_declined_registration(
196
-                $this,
197
-                $closed_reg_statuses,
198
-                false
199
-            );
200
-            do_action('AHEE__EE_Registration__set_status__canceled_or_declined', $this, $old_STS_ID, $new_STS_ID);
201
-            return;
202
-        }
203
-        // true if reinstating cancelled or declined registration
204
-        if (
205
-            in_array($old_STS_ID, $closed_reg_statuses, true)
206
-            && ! in_array($new_STS_ID, $closed_reg_statuses, true)
207
-        ) {
208
-            /** @type EE_Registration_Processor $registration_processor */
209
-            $registration_processor = EE_Registry::instance()->load_class('Registration_Processor');
210
-            /** @type EE_Transaction_Processor $transaction_processor */
211
-            $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor');
212
-            // reinstating cancelled or declined registration
213
-            $registration_processor->update_canceled_or_declined_registration_after_being_reinstated(
214
-                $this,
215
-                $closed_reg_statuses
216
-            );
217
-            $transaction_processor->update_transaction_after_reinstating_canceled_registration(
218
-                $this,
219
-                $closed_reg_statuses,
220
-                false
221
-            );
222
-            do_action('AHEE__EE_Registration__set_status__after_reinstated', $this, $old_STS_ID, $new_STS_ID);
223
-        }
170
+	/**
171
+	 * update REGs and TXN when cancelled or declined registrations involved
172
+	 *
173
+	 * @param string $new_STS_ID
174
+	 * @param string $old_STS_ID
175
+	 * @throws \EE_Error
176
+	 */
177
+	private function _update_if_canceled_or_declined($new_STS_ID, $old_STS_ID)
178
+	{
179
+		// these reg statuses should not be considered in any calculations involving monies owing
180
+		$closed_reg_statuses = EEM_Registration::closed_reg_statuses();
181
+		// true if registration has been cancelled or declined
182
+		if (
183
+			in_array($new_STS_ID, $closed_reg_statuses, true)
184
+			&& ! in_array($old_STS_ID, $closed_reg_statuses, true)
185
+		) {
186
+			/** @type EE_Registration_Processor $registration_processor */
187
+			$registration_processor = EE_Registry::instance()->load_class('Registration_Processor');
188
+			/** @type EE_Transaction_Processor $transaction_processor */
189
+			$transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor');
190
+			// cancelled or declined registration
191
+			$registration_processor->update_registration_after_being_canceled_or_declined(
192
+				$this,
193
+				$closed_reg_statuses
194
+			);
195
+			$transaction_processor->update_transaction_after_canceled_or_declined_registration(
196
+				$this,
197
+				$closed_reg_statuses,
198
+				false
199
+			);
200
+			do_action('AHEE__EE_Registration__set_status__canceled_or_declined', $this, $old_STS_ID, $new_STS_ID);
201
+			return;
202
+		}
203
+		// true if reinstating cancelled or declined registration
204
+		if (
205
+			in_array($old_STS_ID, $closed_reg_statuses, true)
206
+			&& ! in_array($new_STS_ID, $closed_reg_statuses, true)
207
+		) {
208
+			/** @type EE_Registration_Processor $registration_processor */
209
+			$registration_processor = EE_Registry::instance()->load_class('Registration_Processor');
210
+			/** @type EE_Transaction_Processor $transaction_processor */
211
+			$transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor');
212
+			// reinstating cancelled or declined registration
213
+			$registration_processor->update_canceled_or_declined_registration_after_being_reinstated(
214
+				$this,
215
+				$closed_reg_statuses
216
+			);
217
+			$transaction_processor->update_transaction_after_reinstating_canceled_registration(
218
+				$this,
219
+				$closed_reg_statuses,
220
+				false
221
+			);
222
+			do_action('AHEE__EE_Registration__set_status__after_reinstated', $this, $old_STS_ID, $new_STS_ID);
223
+		}
224 224
 	}
225 225
 
226 226
 
@@ -233,16 +233,16 @@  discard block
 block discarded – undo
233 233
 
234 234
 
235 235
 
236
-    /**
237
-     * increments this registration's related ticket sold and corresponding datetime sold values
238
-     *
239
-     * @return void
240
-     * @throws \EE_Error
241
-     */
236
+	/**
237
+	 * increments this registration's related ticket sold and corresponding datetime sold values
238
+	 *
239
+	 * @return void
240
+	 * @throws \EE_Error
241
+	 */
242 242
 	private function _reserve_registration_space() {
243
-	    // reserved ticket and datetime counts will be decremented as sold counts are incremented
244
-        // so stop tracking that this reg has a ticket reserved
245
-	    $this->release_reserved_ticket();
243
+		// reserved ticket and datetime counts will be decremented as sold counts are incremented
244
+		// so stop tracking that this reg has a ticket reserved
245
+		$this->release_reserved_ticket();
246 246
 		$ticket = $this->ticket();
247 247
 		$ticket->increase_sold();
248 248
 		$ticket->save();
@@ -252,13 +252,13 @@  discard block
 block discarded – undo
252 252
 
253 253
 
254 254
 
255
-    /**
256
-     * Gets the ticket this registration is for
257
-     *
258
-     * @param boolean $include_archived whether to include archived tickets or not.
259
-     * @return EE_Ticket|EE_Base_Class
260
-     * @throws \EE_Error
261
-     */
255
+	/**
256
+	 * Gets the ticket this registration is for
257
+	 *
258
+	 * @param boolean $include_archived whether to include archived tickets or not.
259
+	 * @return EE_Ticket|EE_Base_Class
260
+	 * @throws \EE_Error
261
+	 */
262 262
 	public function ticket( $include_archived = TRUE ) {
263 263
 		$query_params = array();
264 264
 		if ( $include_archived ) {
@@ -300,12 +300,12 @@  discard block
 block discarded – undo
300 300
 
301 301
 
302 302
 
303
-    /**
304
-     * decrements (subtracts) this registration's related ticket sold and corresponding datetime sold values
305
-     *
306
-     * @return void
307
-     * @throws \EE_Error
308
-     */
303
+	/**
304
+	 * decrements (subtracts) this registration's related ticket sold and corresponding datetime sold values
305
+	 *
306
+	 * @return void
307
+	 * @throws \EE_Error
308
+	 */
309 309
 	private function _release_registration_space() {
310 310
 		$ticket = $this->ticket();
311 311
 		$ticket->decrease_sold();
@@ -314,46 +314,46 @@  discard block
 block discarded – undo
314 314
 
315 315
 
316 316
 
317
-    /**
318
-     * tracks this registration's ticket reservation in extra meta
319
-     * and can increment related ticket reserved and corresponding datetime reserved values
320
-     *
321
-     * @param bool $update_ticket if true, will increment ticket and datetime reserved count
322
-     * @return void
323
-     * @throws \EE_Error
324
-     */
317
+	/**
318
+	 * tracks this registration's ticket reservation in extra meta
319
+	 * and can increment related ticket reserved and corresponding datetime reserved values
320
+	 *
321
+	 * @param bool $update_ticket if true, will increment ticket and datetime reserved count
322
+	 * @return void
323
+	 * @throws \EE_Error
324
+	 */
325 325
 	public function reserve_ticket($update_ticket = false) {
326
-        if ($this->get_extra_meta(EE_Registration::HAS_RESERVED_TICKET_KEY, true, false) === false) {
327
-            // PLZ NOTE: although checking $update_ticket first would be more efficient,
328
-            // we NEED to ALWAYS call update_extra_meta(), which is why that is done first
329
-            if ($this->update_extra_meta(EE_Registration::HAS_RESERVED_TICKET_KEY, true, false) && $update_ticket) {
330
-                $ticket = $this->ticket();
331
-                $ticket->increase_reserved();
332
-                $ticket->save();
333
-            }
334
-        }
326
+		if ($this->get_extra_meta(EE_Registration::HAS_RESERVED_TICKET_KEY, true, false) === false) {
327
+			// PLZ NOTE: although checking $update_ticket first would be more efficient,
328
+			// we NEED to ALWAYS call update_extra_meta(), which is why that is done first
329
+			if ($this->update_extra_meta(EE_Registration::HAS_RESERVED_TICKET_KEY, true, false) && $update_ticket) {
330
+				$ticket = $this->ticket();
331
+				$ticket->increase_reserved();
332
+				$ticket->save();
333
+			}
334
+		}
335 335
 	}
336 336
 
337 337
 
338 338
 
339
-    /**
340
-     * stops tracking this registration's ticket reservation in extra meta
341
-     * decrements (subtracts) related ticket reserved and corresponding datetime reserved values
342
-     *
343
-     * @param bool $update_ticket if true, will decrement ticket and datetime reserved count
344
-     * @return void
345
-     * @throws \EE_Error
346
-     */
347
-    public function release_reserved_ticket($update_ticket = false) {
348
-        if ($this->get_extra_meta(EE_Registration::HAS_RESERVED_TICKET_KEY, true, false) !== false) {
349
-            // PLZ NOTE: although checking $update_ticket first would be more efficient,
350
-            // we NEED to ALWAYS call delete_extra_meta(), which is why that is done first
351
-            if ($this->delete_extra_meta(EE_Registration::HAS_RESERVED_TICKET_KEY) && $update_ticket) {
352
-                $ticket = $this->ticket();
353
-                $ticket->decrease_reserved();
354
-                $ticket->save();
355
-            }
356
-        }
339
+	/**
340
+	 * stops tracking this registration's ticket reservation in extra meta
341
+	 * decrements (subtracts) related ticket reserved and corresponding datetime reserved values
342
+	 *
343
+	 * @param bool $update_ticket if true, will decrement ticket and datetime reserved count
344
+	 * @return void
345
+	 * @throws \EE_Error
346
+	 */
347
+	public function release_reserved_ticket($update_ticket = false) {
348
+		if ($this->get_extra_meta(EE_Registration::HAS_RESERVED_TICKET_KEY, true, false) !== false) {
349
+			// PLZ NOTE: although checking $update_ticket first would be more efficient,
350
+			// we NEED to ALWAYS call delete_extra_meta(), which is why that is done first
351
+			if ($this->delete_extra_meta(EE_Registration::HAS_RESERVED_TICKET_KEY) && $update_ticket) {
352
+				$ticket = $this->ticket();
353
+				$ticket->decrease_reserved();
354
+				$ticket->save();
355
+			}
356
+		}
357 357
 	}
358 358
 
359 359
 
@@ -742,9 +742,9 @@  discard block
 block discarded – undo
742 742
 
743 743
 
744 744
 	/**
745
-	*		get  Attendee Number
746
-	* 		@access		public
747
-	*/
745
+	 *		get  Attendee Number
746
+	 * 		@access		public
747
+	 */
748 748
 	public function count() {
749 749
 		return $this->get( 'REG_count' );
750 750
 	}
@@ -1021,11 +1021,11 @@  discard block
 block discarded – undo
1021 1021
 	 * @return boolean
1022 1022
 	 */
1023 1023
 	public function set_deleted($deleted) {
1024
-	    if ( $deleted ) {
1025
-	        $this->delete();
1026
-        } else {
1027
-	        $this->restore();
1028
-        }
1024
+		if ( $deleted ) {
1025
+			$this->delete();
1026
+		} else {
1027
+			$this->restore();
1028
+		}
1029 1029
 	}
1030 1030
 
1031 1031
 
@@ -1130,20 +1130,20 @@  discard block
 block discarded – undo
1130 1130
 
1131 1131
 
1132 1132
 
1133
-    /**
1134
-     * toggle Check-in status for this registration
1135
-     * Check-ins are toggled in the following order:
1136
-     * never checked in -> checked in
1137
-     * checked in -> checked out
1138
-     * checked out -> checked in
1139
-     *
1140
-     * @param  int $DTT_ID  include specific datetime to toggle Check-in for.
1141
-     *                      If not included or null, then it is assumed latest datetime is being toggled.
1142
-     * @param bool $verify  If true then can_checkin() is used to verify whether the person
1143
-     *                      can be checked in or not.  Otherwise this forces change in checkin status.
1144
-     * @return bool|int     the chk_in status toggled to OR false if nothing got changed.
1145
-     * @throws EE_Error
1146
-     */
1133
+	/**
1134
+	 * toggle Check-in status for this registration
1135
+	 * Check-ins are toggled in the following order:
1136
+	 * never checked in -> checked in
1137
+	 * checked in -> checked out
1138
+	 * checked out -> checked in
1139
+	 *
1140
+	 * @param  int $DTT_ID  include specific datetime to toggle Check-in for.
1141
+	 *                      If not included or null, then it is assumed latest datetime is being toggled.
1142
+	 * @param bool $verify  If true then can_checkin() is used to verify whether the person
1143
+	 *                      can be checked in or not.  Otherwise this forces change in checkin status.
1144
+	 * @return bool|int     the chk_in status toggled to OR false if nothing got changed.
1145
+	 * @throws EE_Error
1146
+	 */
1147 1147
 	public function toggle_checkin_status( $DTT_ID = null, $verify = false ) {
1148 1148
 		if ( empty( $DTT_ID ) ) {
1149 1149
 			$datetime = $this->get_latest_related_datetime();
@@ -1200,13 +1200,13 @@  discard block
 block discarded – undo
1200 1200
 
1201 1201
 
1202 1202
 
1203
-    /**
1204
-     * Returns the latest datetime related to this registration (via the ticket attached to the registration).
1205
-     * "Latest" is defined by the `DTT_EVT_start` column.
1206
-     *
1207
-     * @return EE_Datetime|null
1208
-     * @throws \EE_Error
1209
-     */
1203
+	/**
1204
+	 * Returns the latest datetime related to this registration (via the ticket attached to the registration).
1205
+	 * "Latest" is defined by the `DTT_EVT_start` column.
1206
+	 *
1207
+	 * @return EE_Datetime|null
1208
+	 * @throws \EE_Error
1209
+	 */
1210 1210
 	public function get_latest_related_datetime() {
1211 1211
 		return EEM_Datetime::instance()->get_one(
1212 1212
 			array(
@@ -1220,12 +1220,12 @@  discard block
 block discarded – undo
1220 1220
 
1221 1221
 
1222 1222
 
1223
-    /**
1224
-     * Returns the earliest datetime related to this registration (via the ticket attached to the registration).
1225
-     * "Earliest" is defined by the `DTT_EVT_start` column.
1226
-     *
1227
-     * @throws \EE_Error
1228
-     */
1223
+	/**
1224
+	 * Returns the earliest datetime related to this registration (via the ticket attached to the registration).
1225
+	 * "Earliest" is defined by the `DTT_EVT_start` column.
1226
+	 *
1227
+	 * @throws \EE_Error
1228
+	 */
1229 1229
 	public function get_earliest_related_datetime() {
1230 1230
 		return EEM_Datetime::instance()->get_one(
1231 1231
 			array(
@@ -1239,18 +1239,18 @@  discard block
 block discarded – undo
1239 1239
 
1240 1240
 
1241 1241
 
1242
-    /**
1243
-     * This method simply returns the check-in status for this registration and the given datetime.
1244
-     * If neither the datetime nor the checkin values are provided as arguments,
1245
-     * then this will return the LATEST check-in status for the registration across all datetimes it belongs to.
1246
-     *
1247
-     * @param  int $DTT_ID        The ID of the datetime we're checking against
1248
-     *                            (if empty we'll get the primary datetime for
1249
-     *                            this registration (via event) and use it's ID);
1250
-     * @param EE_Checkin $checkin If present, we use the given checkin object rather than the dtt_id.
1251
-     * @return int                Integer representing Check-in status.
1252
-     * @throws \EE_Error
1253
-     */
1242
+	/**
1243
+	 * This method simply returns the check-in status for this registration and the given datetime.
1244
+	 * If neither the datetime nor the checkin values are provided as arguments,
1245
+	 * then this will return the LATEST check-in status for the registration across all datetimes it belongs to.
1246
+	 *
1247
+	 * @param  int $DTT_ID        The ID of the datetime we're checking against
1248
+	 *                            (if empty we'll get the primary datetime for
1249
+	 *                            this registration (via event) and use it's ID);
1250
+	 * @param EE_Checkin $checkin If present, we use the given checkin object rather than the dtt_id.
1251
+	 * @return int                Integer representing Check-in status.
1252
+	 * @throws \EE_Error
1253
+	 */
1254 1254
 	public function check_in_status_for_datetime( $DTT_ID = 0, $checkin = null ) {
1255 1255
 		$checkin_query_params = array(
1256 1256
 			'order_by' => array( 'CHK_timestamp' => 'DESC' )
@@ -1262,8 +1262,8 @@  discard block
 block discarded – undo
1262 1262
 
1263 1263
 		//get checkin object (if exists)
1264 1264
 		$checkin = $checkin instanceof EE_Checkin
1265
-            ? $checkin
1266
-            : $this->get_first_related( 'Checkin', $checkin_query_params );
1265
+			? $checkin
1266
+			: $this->get_first_related( 'Checkin', $checkin_query_params );
1267 1267
 		if ( $checkin instanceof EE_Checkin ) {
1268 1268
 			if ( $checkin->get( 'CHK_in' ) ) {
1269 1269
 				return EE_Registration::checkin_status_in; //checked in
@@ -1516,46 +1516,46 @@  discard block
 block discarded – undo
1516 1516
 
1517 1517
 
1518 1518
 
1519
-    /**
1520
-     * Soft Deletes this model object.
1521
-     *
1522
-     * @return boolean | int
1523
-     * @throws \RuntimeException
1524
-     * @throws \EE_Error
1525
-     */
1526
-    public function delete()
1527
-    {
1528
-        if($this->update_extra_meta(EE_Registration::PRE_TRASH_REG_STATUS_KEY, $this->status_ID()) === true) {
1529
-            $this->set_status(EEM_Registration::status_id_cancelled);
1530
-        }
1531
-        return parent::delete();
1532
-    }
1519
+	/**
1520
+	 * Soft Deletes this model object.
1521
+	 *
1522
+	 * @return boolean | int
1523
+	 * @throws \RuntimeException
1524
+	 * @throws \EE_Error
1525
+	 */
1526
+	public function delete()
1527
+	{
1528
+		if($this->update_extra_meta(EE_Registration::PRE_TRASH_REG_STATUS_KEY, $this->status_ID()) === true) {
1529
+			$this->set_status(EEM_Registration::status_id_cancelled);
1530
+		}
1531
+		return parent::delete();
1532
+	}
1533 1533
 
1534 1534
 
1535 1535
 
1536
-    /**
1537
-     * Restores whatever the previous status was on a registration before it was trashed (if possible)
1538
-     *
1539
-     * @throws \EE_Error
1540
-     * @throws \RuntimeException
1541
-     */
1542
-    public function restore()
1543
-    {
1544
-        $previous_status = $this->get_extra_meta(
1545
-            EE_Registration::PRE_TRASH_REG_STATUS_KEY,
1546
-            true,
1547
-            EEM_Registration::status_id_cancelled
1548
-        );
1549
-        if ($previous_status) {
1550
-            $this->delete_extra_meta(EE_Registration::PRE_TRASH_REG_STATUS_KEY);
1551
-            $this->set_status($previous_status);
1552
-        }
1553
-        return parent::restore();
1554
-    }
1536
+	/**
1537
+	 * Restores whatever the previous status was on a registration before it was trashed (if possible)
1538
+	 *
1539
+	 * @throws \EE_Error
1540
+	 * @throws \RuntimeException
1541
+	 */
1542
+	public function restore()
1543
+	{
1544
+		$previous_status = $this->get_extra_meta(
1545
+			EE_Registration::PRE_TRASH_REG_STATUS_KEY,
1546
+			true,
1547
+			EEM_Registration::status_id_cancelled
1548
+		);
1549
+		if ($previous_status) {
1550
+			$this->delete_extra_meta(EE_Registration::PRE_TRASH_REG_STATUS_KEY);
1551
+			$this->set_status($previous_status);
1552
+		}
1553
+		return parent::restore();
1554
+	}
1555 1555
 
1556 1556
 
1557 1557
 
1558
-    /*************************** DEPRECATED ***************************/
1558
+	/*************************** DEPRECATED ***************************/
1559 1559
 
1560 1560
 
1561 1561
 
@@ -1605,24 +1605,24 @@  discard block
 block discarded – undo
1605 1605
 
1606 1606
 
1607 1607
 
1608
-    /**
1609
-     * Gets the primary datetime related to this registration via the related Event to this registration
1610
-     *
1611
-     * @deprecated 4.9.17
1612
-     * @return EE_Datetime
1613
-     */
1614
-    public function get_related_primary_datetime() {
1615
-        EE_Error::doing_it_wrong(
1616
-            __METHOD__,
1617
-            esc_html__(
1618
-                'Use EE_Registration::get_latest_related_datetime() or EE_Registration::get_earliest_related_datetime()',
1619
-                'event_espresso'
1620
-            ),
1621
-            '4.9.17',
1622
-            '5.0.0'
1623
-        );
1624
-        return $this->event()->primary_datetime();
1625
-    }
1608
+	/**
1609
+	 * Gets the primary datetime related to this registration via the related Event to this registration
1610
+	 *
1611
+	 * @deprecated 4.9.17
1612
+	 * @return EE_Datetime
1613
+	 */
1614
+	public function get_related_primary_datetime() {
1615
+		EE_Error::doing_it_wrong(
1616
+			__METHOD__,
1617
+			esc_html__(
1618
+				'Use EE_Registration::get_latest_related_datetime() or EE_Registration::get_earliest_related_datetime()',
1619
+				'event_espresso'
1620
+			),
1621
+			'4.9.17',
1622
+			'5.0.0'
1623
+		);
1624
+		return $this->event()->primary_datetime();
1625
+	}
1626 1626
 
1627 1627
 
1628 1628
 
Please login to merge, or discard this patch.
Spacing   +186 added lines, -186 removed lines patch added patch discarded remove patch
@@ -1,7 +1,7 @@  discard block
 block discarded – undo
1 1
 <?php use EventEspresso\core\exceptions\EntityNotFoundException;
2 2
 
3
-if ( !defined( 'EVENT_ESPRESSO_VERSION' ) ) {
4
-	exit( 'No direct script access allowed' );
3
+if ( ! defined('EVENT_ESPRESSO_VERSION')) {
4
+	exit('No direct script access allowed');
5 5
 }
6 6
 /**
7 7
  * EE_Registration class
@@ -59,9 +59,9 @@  discard block
 block discarded – undo
59 59
 	 *                             		    date_format and the second value is the time format
60 60
 	 * @return EE_Registration
61 61
 	 */
62
-	public static function new_instance( $props_n_values = array(), $timezone = null, $date_formats = array() ) {
63
-		$has_object = parent::_check_for_object( $props_n_values, __CLASS__, $timezone, $date_formats );
64
-		return $has_object ? $has_object : new self( $props_n_values, false, $timezone, $date_formats );
62
+	public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array()) {
63
+		$has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats);
64
+		return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats);
65 65
 	}
66 66
 
67 67
 
@@ -72,8 +72,8 @@  discard block
 block discarded – undo
72 72
 	 *                          		the website will be used.
73 73
 	 * @return EE_Registration
74 74
 	 */
75
-	public static function new_instance_from_db( $props_n_values = array(), $timezone = null ) {
76
-		return new self( $props_n_values, TRUE, $timezone );
75
+	public static function new_instance_from_db($props_n_values = array(), $timezone = null) {
76
+		return new self($props_n_values, TRUE, $timezone);
77 77
 	}
78 78
 
79 79
 
@@ -83,8 +83,8 @@  discard block
 block discarded – undo
83 83
 	 *
84 84
 	 * @param        int $EVT_ID Event ID
85 85
 	 */
86
-	public function set_event( $EVT_ID = 0 ) {
87
-		$this->set( 'EVT_ID', $EVT_ID );
86
+	public function set_event($EVT_ID = 0) {
87
+		$this->set('EVT_ID', $EVT_ID);
88 88
 	}
89 89
 
90 90
 
@@ -98,18 +98,18 @@  discard block
 block discarded – undo
98 98
      * @throws \EE_Error
99 99
      * @throws \RuntimeException
100 100
      */
101
-	public function set( $field_name, $field_value, $use_default = FALSE ) {
102
-		switch( $field_name ) {
101
+	public function set($field_name, $field_value, $use_default = FALSE) {
102
+		switch ($field_name) {
103 103
 			case 'REG_code' :
104
-				if ( ! empty( $field_value ) && $this->reg_code() === null ) {
105
-					$this->set_reg_code( $field_value, $use_default );
104
+				if ( ! empty($field_value) && $this->reg_code() === null) {
105
+					$this->set_reg_code($field_value, $use_default);
106 106
 				}
107 107
 				break;
108 108
 			case 'STS_ID' :
109
-				$this->set_status( $field_value, $use_default );
109
+				$this->set_status($field_value, $use_default);
110 110
 				break;
111 111
 			default :
112
-				parent::set( $field_name, $field_value, $use_default );
112
+				parent::set($field_name, $field_value, $use_default);
113 113
 		}
114 114
 	}
115 115
 
@@ -127,40 +127,40 @@  discard block
 block discarded – undo
127 127
      * @throws \RuntimeException
128 128
      * @throws \EE_Error
129 129
      */
130
-	public function set_status( $new_STS_ID = NULL, $use_default = FALSE ) {
130
+	public function set_status($new_STS_ID = NULL, $use_default = FALSE) {
131 131
 		// get current REG_Status
132 132
 		$old_STS_ID = $this->status_ID();
133 133
 		// if status has changed
134 134
 		if (
135 135
 			$old_STS_ID !== $new_STS_ID // and that status has actually changed
136
-			&& ! empty( $old_STS_ID ) // and that old status is actually set
137
-			&& ! empty( $new_STS_ID ) // as well as the new status
136
+			&& ! empty($old_STS_ID) // and that old status is actually set
137
+			&& ! empty($new_STS_ID) // as well as the new status
138 138
 			&& $this->ID() // ensure registration is in the db
139 139
 		) {
140 140
             // TO approved
141
-			if ( $new_STS_ID === EEM_Registration::status_id_approved ) {
141
+			if ($new_STS_ID === EEM_Registration::status_id_approved) {
142 142
 				// reserve a space by incrementing ticket and datetime sold values
143 143
 				$this->_reserve_registration_space();
144
-				do_action( 'AHEE__EE_Registration__set_status__to_approved', $this, $old_STS_ID, $new_STS_ID );
144
+				do_action('AHEE__EE_Registration__set_status__to_approved', $this, $old_STS_ID, $new_STS_ID);
145 145
 			// OR FROM  approved
146
-			} else if ( $old_STS_ID === EEM_Registration::status_id_approved ) {
146
+			} else if ($old_STS_ID === EEM_Registration::status_id_approved) {
147 147
 				// release a space by decrementing ticket and datetime sold values
148 148
 				$this->_release_registration_space();
149
-				do_action( 'AHEE__EE_Registration__set_status__from_approved', $this, $old_STS_ID, $new_STS_ID );
149
+				do_action('AHEE__EE_Registration__set_status__from_approved', $this, $old_STS_ID, $new_STS_ID);
150 150
 			}
151 151
             // update status
152 152
             parent::set('STS_ID', $new_STS_ID, $use_default);
153 153
             $this->_update_if_canceled_or_declined($new_STS_ID, $old_STS_ID);
154 154
             /** @type EE_Transaction_Payments $transaction_payments */
155 155
             $transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments');
156
-            $transaction_payments->recalculate_transaction_total( $this->transaction(), false );
157
-			$this->transaction()->update_status_based_on_total_paid( true );
158
-			do_action( 'AHEE__EE_Registration__set_status__after_update', $this );
156
+            $transaction_payments->recalculate_transaction_total($this->transaction(), false);
157
+			$this->transaction()->update_status_based_on_total_paid(true);
158
+			do_action('AHEE__EE_Registration__set_status__after_update', $this);
159 159
 			return TRUE;
160 160
 		} else {
161 161
 			//even though the old value matches the new value, it's still good to
162 162
 			//allow the parent set method to have a say
163
-			parent::set( 'STS_ID', $new_STS_ID, $use_default );
163
+			parent::set('STS_ID', $new_STS_ID, $use_default);
164 164
 			return TRUE;
165 165
 		}
166 166
 	}
@@ -228,7 +228,7 @@  discard block
 block discarded – undo
228 228
 	 *        get Status ID
229 229
 	 */
230 230
 	public function status_ID() {
231
-		return $this->get( 'STS_ID' );
231
+		return $this->get('STS_ID');
232 232
 	}
233 233
 
234 234
 
@@ -259,12 +259,12 @@  discard block
 block discarded – undo
259 259
      * @return EE_Ticket|EE_Base_Class
260 260
      * @throws \EE_Error
261 261
      */
262
-	public function ticket( $include_archived = TRUE ) {
262
+	public function ticket($include_archived = TRUE) {
263 263
 		$query_params = array();
264
-		if ( $include_archived ) {
265
-			$query_params[ 'default_where_conditions' ] = 'none';
264
+		if ($include_archived) {
265
+			$query_params['default_where_conditions'] = 'none';
266 266
 		}
267
-		return $this->get_first_related( 'Ticket', $query_params );
267
+		return $this->get_first_related('Ticket', $query_params);
268 268
 	}
269 269
 
270 270
 
@@ -292,7 +292,7 @@  discard block
 block discarded – undo
292 292
 	 */
293 293
 	public function wp_user() {
294 294
 		$event = $this->event();
295
-		if ( $event instanceof EE_Event ) {
295
+		if ($event instanceof EE_Event) {
296 296
 			return $event->wp_user();
297 297
 		}
298 298
 		return 0;
@@ -363,8 +363,8 @@  discard block
 block discarded – undo
363 363
 	 *
364 364
 	 * @param        int $ATT_ID Attendee ID
365 365
 	 */
366
-	public function set_attendee_id( $ATT_ID = 0 ) {
367
-		$this->set( 'ATT_ID', $ATT_ID );
366
+	public function set_attendee_id($ATT_ID = 0) {
367
+		$this->set('ATT_ID', $ATT_ID);
368 368
 	}
369 369
 
370 370
 
@@ -374,8 +374,8 @@  discard block
 block discarded – undo
374 374
 	 *
375 375
 	 * @param        int $TXN_ID Transaction ID
376 376
 	 */
377
-	public function set_transaction_id( $TXN_ID = 0 ) {
378
-		$this->set( 'TXN_ID', $TXN_ID );
377
+	public function set_transaction_id($TXN_ID = 0) {
378
+		$this->set('TXN_ID', $TXN_ID);
379 379
 	}
380 380
 
381 381
 
@@ -385,8 +385,8 @@  discard block
 block discarded – undo
385 385
 	 *
386 386
 	 * @param    string $REG_session PHP Session ID
387 387
 	 */
388
-	public function set_session( $REG_session = '' ) {
389
-		$this->set( 'REG_session', $REG_session );
388
+	public function set_session($REG_session = '') {
389
+		$this->set('REG_session', $REG_session);
390 390
 	}
391 391
 
392 392
 
@@ -396,8 +396,8 @@  discard block
 block discarded – undo
396 396
 	 *
397 397
 	 * @param    string $REG_url_link Registration URL Link
398 398
 	 */
399
-	public function set_reg_url_link( $REG_url_link = '' ) {
400
-		$this->set( 'REG_url_link', $REG_url_link );
399
+	public function set_reg_url_link($REG_url_link = '') {
400
+		$this->set('REG_url_link', $REG_url_link);
401 401
 	}
402 402
 
403 403
 
@@ -407,8 +407,8 @@  discard block
 block discarded – undo
407 407
 	 *
408 408
 	 * @param        int $REG_count Primary Attendee
409 409
 	 */
410
-	public function set_count( $REG_count = 1 ) {
411
-		$this->set( 'REG_count', $REG_count );
410
+	public function set_count($REG_count = 1) {
411
+		$this->set('REG_count', $REG_count);
412 412
 	}
413 413
 
414 414
 
@@ -418,8 +418,8 @@  discard block
 block discarded – undo
418 418
 	 *
419 419
 	 * @param        boolean $REG_group_size Group Registration
420 420
 	 */
421
-	public function set_group_size( $REG_group_size = FALSE ) {
422
-		$this->set( 'REG_group_size', $REG_group_size );
421
+	public function set_group_size($REG_group_size = FALSE) {
422
+		$this->set('REG_group_size', $REG_group_size);
423 423
 	}
424 424
 
425 425
 
@@ -495,8 +495,8 @@  discard block
 block discarded – undo
495 495
 	 *
496 496
 	 * @param        mixed ( int or string ) $REG_date Registration Date - Unix timestamp or string representation of Date
497 497
 	 */
498
-	public function set_reg_date( $REG_date = FALSE ) {
499
-		$this->set( 'REG_date', $REG_date );
498
+	public function set_reg_date($REG_date = FALSE) {
499
+		$this->set('REG_date', $REG_date);
500 500
 	}
501 501
 
502 502
 
@@ -507,8 +507,8 @@  discard block
 block discarded – undo
507 507
 	 * @access    public
508 508
 	 * @param    float $REG_final_price
509 509
 	 */
510
-	public function set_final_price( $REG_final_price = 0.00 ) {
511
-		$this->set( 'REG_final_price', $REG_final_price );
510
+	public function set_final_price($REG_final_price = 0.00) {
511
+		$this->set('REG_final_price', $REG_final_price);
512 512
 	}
513 513
 
514 514
 
@@ -519,8 +519,8 @@  discard block
 block discarded – undo
519 519
 	 * @access    public
520 520
 	 * @param    float $REG_paid
521 521
 	 */
522
-	public function set_paid( $REG_paid = 0.00 ) {
523
-		$this->set( 'REG_paid', $REG_paid );
522
+	public function set_paid($REG_paid = 0.00) {
523
+		$this->set('REG_paid', $REG_paid);
524 524
 	}
525 525
 
526 526
 
@@ -530,8 +530,8 @@  discard block
 block discarded – undo
530 530
 	 *
531 531
 	 * @param        boolean $REG_att_is_going Attendee Is Going
532 532
 	 */
533
-	public function set_att_is_going( $REG_att_is_going = FALSE ) {
534
-		$this->set( 'REG_att_is_going', $REG_att_is_going );
533
+	public function set_att_is_going($REG_att_is_going = FALSE) {
534
+		$this->set('REG_att_is_going', $REG_att_is_going);
535 535
 	}
536 536
 
537 537
 
@@ -541,7 +541,7 @@  discard block
 block discarded – undo
541 541
 	 * @return EE_Attendee
542 542
 	 */
543 543
 	public function attendee() {
544
-		return $this->get_first_related( 'Attendee' );
544
+		return $this->get_first_related('Attendee');
545 545
 	}
546 546
 
547 547
 
@@ -550,7 +550,7 @@  discard block
 block discarded – undo
550 550
 	 *        get Event ID
551 551
 	 */
552 552
 	public function event_ID() {
553
-		return $this->get( 'EVT_ID' );
553
+		return $this->get('EVT_ID');
554 554
 	}
555 555
 
556 556
 
@@ -560,7 +560,7 @@  discard block
 block discarded – undo
560 560
 	 */
561 561
 	public function event_name() {
562 562
 		$event = $this->event_obj();
563
-		if ( $event ) {
563
+		if ($event) {
564 564
 			return $event->name();
565 565
 		} else {
566 566
 			return NULL;
@@ -574,7 +574,7 @@  discard block
 block discarded – undo
574 574
 	 * @return EE_Event
575 575
 	 */
576 576
 	public function event_obj() {
577
-		return $this->get_first_related( 'Event' );
577
+		return $this->get_first_related('Event');
578 578
 	}
579 579
 
580 580
 
@@ -583,7 +583,7 @@  discard block
 block discarded – undo
583 583
 	 *        get Attendee ID
584 584
 	 */
585 585
 	public function attendee_ID() {
586
-		return $this->get( 'ATT_ID' );
586
+		return $this->get('ATT_ID');
587 587
 	}
588 588
 
589 589
 
@@ -592,7 +592,7 @@  discard block
 block discarded – undo
592 592
 	 *        get PHP Session ID
593 593
 	 */
594 594
 	public function session_ID() {
595
-		return $this->get( 'REG_session' );
595
+		return $this->get('REG_session');
596 596
 	}
597 597
 
598 598
 
@@ -602,7 +602,7 @@  discard block
 block discarded – undo
602 602
 	 * @param string $messenger 'pdf' or 'html'.  Default 'html'.
603 603
 	 * @return string
604 604
 	 */
605
-	public function receipt_url( $messenger = 'html' ) {
605
+	public function receipt_url($messenger = 'html') {
606 606
 
607 607
 		/**
608 608
 		 * The below will be deprecated one version after this.  We check first if there is a custom receipt template already in use on old system.  If there is then we just return the standard url for it.
@@ -610,12 +610,12 @@  discard block
 block discarded – undo
610 610
 		 * @since 4.5.0
611 611
 		 */
612 612
 		$template_relative_path = 'modules/gateways/Invoice/lib/templates/receipt_body.template.php';
613
-		$has_custom = EEH_Template::locate_template( $template_relative_path , array(), TRUE, TRUE, TRUE );
613
+		$has_custom = EEH_Template::locate_template($template_relative_path, array(), TRUE, TRUE, TRUE);
614 614
 
615
-		if ( $has_custom ) {
616
-			return add_query_arg( array( 'receipt' => 'true' ), $this->invoice_url( 'launch' ) );
615
+		if ($has_custom) {
616
+			return add_query_arg(array('receipt' => 'true'), $this->invoice_url('launch'));
617 617
 		}
618
-		return apply_filters( 'FHEE__EE_Registration__receipt_url__receipt_url', '', $this, $messenger, 'receipt' );
618
+		return apply_filters('FHEE__EE_Registration__receipt_url__receipt_url', '', $this, $messenger, 'receipt');
619 619
 	}
620 620
 
621 621
 
@@ -626,28 +626,28 @@  discard block
 block discarded – undo
626 626
 	 * @param string $messenger 'pdf' or 'html'.  Default 'html'.
627 627
 	 * @return string
628 628
 	 */
629
-	public function invoice_url( $messenger = 'html' ) {
629
+	public function invoice_url($messenger = 'html') {
630 630
 		/**
631 631
 		 * The below will be deprecated one version after this.  We check first if there is a custom invoice template already in use on old system.  If there is then we just return the standard url for it.
632 632
 		 *
633 633
 		 * @since 4.5.0
634 634
 		 */
635 635
 		$template_relative_path = 'modules/gateways/Invoice/lib/templates/invoice_body.template.php';
636
-		$has_custom = EEH_Template::locate_template( $template_relative_path , array(), TRUE, TRUE, TRUE );
636
+		$has_custom = EEH_Template::locate_template($template_relative_path, array(), TRUE, TRUE, TRUE);
637 637
 
638
-		if ( $has_custom ) {
639
-			if ( $messenger == 'html' ) {
640
-				return $this->invoice_url( 'launch' );
638
+		if ($has_custom) {
639
+			if ($messenger == 'html') {
640
+				return $this->invoice_url('launch');
641 641
 			}
642 642
 			$route = $messenger == 'download' || $messenger == 'pdf' ? 'download_invoice' : 'launch_invoice';
643 643
 
644
-			$query_args = array( 'ee' => $route, 'id' => $this->reg_url_link() );
645
-			if ( $messenger == 'html' ) {
644
+			$query_args = array('ee' => $route, 'id' => $this->reg_url_link());
645
+			if ($messenger == 'html') {
646 646
 				$query_args['html'] = TRUE;
647 647
 			}
648
-			return add_query_arg( $query_args, get_permalink( EE_Registry::instance()->CFG->core->thank_you_page_id ) );
648
+			return add_query_arg($query_args, get_permalink(EE_Registry::instance()->CFG->core->thank_you_page_id));
649 649
 		}
650
-		return apply_filters( 'FHEE__EE_Registration__invoice_url__invoice_url', '', $this, $messenger, 'invoice' );
650
+		return apply_filters('FHEE__EE_Registration__invoice_url__invoice_url', '', $this, $messenger, 'invoice');
651 651
 	}
652 652
 
653 653
 
@@ -660,7 +660,7 @@  discard block
 block discarded – undo
660 660
 	 * @throws \EE_Error
661 661
 	 */
662 662
 	public function reg_url_link() {
663
-		return (string)$this->get( 'REG_url_link' );
663
+		return (string) $this->get('REG_url_link');
664 664
 	}
665 665
 
666 666
 
@@ -670,8 +670,8 @@  discard block
 block discarded – undo
670 670
 	 * @param string $type 'download','launch', or 'html' (default is 'launch')
671 671
 	 * @return void
672 672
 	 */
673
-	public function e_invoice_url( $type = 'launch' ) {
674
-		echo $this->invoice_url( $type );
673
+	public function e_invoice_url($type = 'launch') {
674
+		echo $this->invoice_url($type);
675 675
 	}
676 676
 
677 677
 
@@ -691,7 +691,7 @@  discard block
 block discarded – undo
691 691
 	 * @return string
692 692
 	 */
693 693
 	public function payment_overview_url() {
694
-		return add_query_arg( array( 'e_reg_url_link' => $this->reg_url_link(), 'step' => 'payment_options', 'revisit' => TRUE ), EE_Registry::instance()->CFG->core->reg_page_url() );
694
+		return add_query_arg(array('e_reg_url_link' => $this->reg_url_link(), 'step' => 'payment_options', 'revisit' => TRUE), EE_Registry::instance()->CFG->core->reg_page_url());
695 695
 	}
696 696
 
697 697
 
@@ -702,7 +702,7 @@  discard block
 block discarded – undo
702 702
 	 * @return string
703 703
 	 */
704 704
 	public function edit_attendee_information_url() {
705
-		return add_query_arg( array( 'e_reg_url_link' => $this->reg_url_link(), 'step' => 'attendee_information', 'revisit' => TRUE ), EE_Registry::instance()->CFG->core->reg_page_url() );
705
+		return add_query_arg(array('e_reg_url_link' => $this->reg_url_link(), 'step' => 'attendee_information', 'revisit' => TRUE), EE_Registry::instance()->CFG->core->reg_page_url());
706 706
 	}
707 707
 
708 708
 
@@ -712,7 +712,7 @@  discard block
 block discarded – undo
712 712
 	 * @return string
713 713
 	 */
714 714
 	public function get_admin_edit_url() {
715
-		return EEH_URL::add_query_args_and_nonce( array( 'page' => 'espresso_registrations', 'action' => 'view_registration', '_REG_ID' => $this->ID() ), admin_url( 'admin.php' ) );
715
+		return EEH_URL::add_query_args_and_nonce(array('page' => 'espresso_registrations', 'action' => 'view_registration', '_REG_ID' => $this->ID()), admin_url('admin.php'));
716 716
 	}
717 717
 
718 718
 
@@ -721,7 +721,7 @@  discard block
 block discarded – undo
721 721
 	 *    is_primary_registrant?
722 722
 	 */
723 723
 	public function is_primary_registrant() {
724
-		return $this->get( 'REG_count' ) == 1 ? TRUE : FALSE;
724
+		return $this->get('REG_count') == 1 ? TRUE : FALSE;
725 725
 	}
726 726
 
727 727
 
@@ -730,12 +730,12 @@  discard block
 block discarded – undo
730 730
 	 * This returns the primary registration object for this registration group (which may be this object).
731 731
 	 * @return EE_Registration
732 732
 	 */
733
-	public function get_primary_registration()  {
734
-		if ( $this->is_primary_registrant() )
733
+	public function get_primary_registration() {
734
+		if ($this->is_primary_registrant())
735 735
 			return $this;
736 736
 
737 737
 		//k reg_count !== 1 so let's get the EE_Registration object matching this txn_id and reg_count == 1
738
-		$primary_registrant = EEM_Registration::instance()->get_one( array( array('TXN_ID' => $this->transaction_ID(), 'REG_count' => 1 ) ) );
738
+		$primary_registrant = EEM_Registration::instance()->get_one(array(array('TXN_ID' => $this->transaction_ID(), 'REG_count' => 1)));
739 739
 		return $primary_registrant;
740 740
 	}
741 741
 
@@ -746,7 +746,7 @@  discard block
 block discarded – undo
746 746
 	* 		@access		public
747 747
 	*/
748 748
 	public function count() {
749
-		return $this->get( 'REG_count' );
749
+		return $this->get('REG_count');
750 750
 	}
751 751
 
752 752
 
@@ -755,7 +755,7 @@  discard block
 block discarded – undo
755 755
 	 *        get Group Size
756 756
 	 */
757 757
 	public function group_size() {
758
-		return $this->get( 'REG_group_size' );
758
+		return $this->get('REG_group_size');
759 759
 	}
760 760
 
761 761
 
@@ -764,7 +764,7 @@  discard block
 block discarded – undo
764 764
 	 *        get Registration Date
765 765
 	 */
766 766
 	public function date() {
767
-		return $this->get( 'REG_date' );
767
+		return $this->get('REG_date');
768 768
 	}
769 769
 
770 770
 
@@ -775,8 +775,8 @@  discard block
 block discarded – undo
775 775
 	 * @param string $time_format
776 776
 	 * @return string
777 777
 	 */
778
-	public function pretty_date( $date_format = NULL, $time_format = NULL ) {
779
-		return $this->get_datetime( 'REG_date', $date_format, $time_format );
778
+	public function pretty_date($date_format = NULL, $time_format = NULL) {
779
+		return $this->get_datetime('REG_date', $date_format, $time_format);
780 780
 	}
781 781
 
782 782
 
@@ -788,7 +788,7 @@  discard block
 block discarded – undo
788 788
 	 * @return    float
789 789
 	 */
790 790
 	public function final_price() {
791
-		return $this->get( 'REG_final_price' );
791
+		return $this->get('REG_final_price');
792 792
 	}
793 793
 
794 794
 
@@ -799,7 +799,7 @@  discard block
 block discarded – undo
799 799
 	 * @return string
800 800
 	 */
801 801
 	public function pretty_final_price() {
802
-		return $this->get_pretty( 'REG_final_price' );
802
+		return $this->get_pretty('REG_final_price');
803 803
 	}
804 804
 
805 805
 
@@ -809,7 +809,7 @@  discard block
 block discarded – undo
809 809
 	 * @return 	float
810 810
 	 */
811 811
 	public function paid() {
812
-		return $this->get( 'REG_paid' );
812
+		return $this->get('REG_paid');
813 813
 	}
814 814
 
815 815
 
@@ -819,7 +819,7 @@  discard block
 block discarded – undo
819 819
 	 * @return 	float
820 820
 	 */
821 821
 	public function pretty_paid() {
822
-		return $this->get_pretty( 'REG_paid' );
822
+		return $this->get_pretty('REG_paid');
823 823
 	}
824 824
 
825 825
 
@@ -830,11 +830,11 @@  discard block
 block discarded – undo
830 830
 	 * @param array $requires_payment
831 831
 	 * @return bool
832 832
 	 */
833
-	public function owes_monies_and_can_pay( $requires_payment = array()) {
833
+	public function owes_monies_and_can_pay($requires_payment = array()) {
834 834
 		// these reg statuses require payment (if event is not free)
835
-		$requires_payment = ! empty( $requires_payment ) ? $requires_payment : EEM_Registration::reg_statuses_that_allow_payment();
835
+		$requires_payment = ! empty($requires_payment) ? $requires_payment : EEM_Registration::reg_statuses_that_allow_payment();
836 836
 		if (
837
-			in_array( $this->status_ID(), $requires_payment ) &&
837
+			in_array($this->status_ID(), $requires_payment) &&
838 838
 			$this->final_price() != 0 &&
839 839
 			$this->final_price() != $this->paid()
840 840
 		) {
@@ -851,8 +851,8 @@  discard block
 block discarded – undo
851 851
 	 * @param bool $show_icons
852 852
 	 * @return void
853 853
 	 */
854
-	public function e_pretty_status( $show_icons = FALSE ) {
855
-		echo $this->pretty_status( $show_icons );
854
+	public function e_pretty_status($show_icons = FALSE) {
855
+		echo $this->pretty_status($show_icons);
856 856
 	}
857 857
 
858 858
 
@@ -863,10 +863,10 @@  discard block
 block discarded – undo
863 863
 	 * @param bool $show_icons
864 864
 	 * @return string
865 865
 	 */
866
-	public function pretty_status( $show_icons = FALSE ) {
867
-		$status = EEM_Status::instance()->localized_status( array( $this->status_ID() => __( 'unknown', 'event_espresso' ) ), FALSE, 'sentence' );
866
+	public function pretty_status($show_icons = FALSE) {
867
+		$status = EEM_Status::instance()->localized_status(array($this->status_ID() => __('unknown', 'event_espresso')), FALSE, 'sentence');
868 868
 		$icon = '';
869
-		switch ( $this->status_ID() ) {
869
+		switch ($this->status_ID()) {
870 870
 			case EEM_Registration::status_id_approved:
871 871
 				$icon = $show_icons ? '<span class="dashicons dashicons-star-filled ee-icon-size-16 green-text"></span>' : '';
872 872
 				break;
@@ -889,7 +889,7 @@  discard block
 block discarded – undo
889 889
 				$icon = $show_icons ? '<span class="dashicons dashicons-clipboard ee-icon-size-16 purple-text"></span>' : '';
890 890
 				break;
891 891
 		}
892
-		return $icon . $status[ $this->status_ID() ];
892
+		return $icon.$status[$this->status_ID()];
893 893
 	}
894 894
 
895 895
 
@@ -898,7 +898,7 @@  discard block
 block discarded – undo
898 898
 	 *        get Attendee Is Going
899 899
 	 */
900 900
 	public function att_is_going() {
901
-		return $this->get( 'REG_att_is_going' );
901
+		return $this->get('REG_att_is_going');
902 902
 	}
903 903
 
904 904
 
@@ -908,8 +908,8 @@  discard block
 block discarded – undo
908 908
 	 * @param array $query_params like EEM_Base::get_all
909 909
 	 * @return EE_Answer[]
910 910
 	 */
911
-	public function answers( $query_params = NULL ) {
912
-		return $this->get_many_related( 'Answer', $query_params );
911
+	public function answers($query_params = NULL) {
912
+		return $this->get_many_related('Answer', $query_params);
913 913
 	}
914 914
 
915 915
 
@@ -923,9 +923,9 @@  discard block
 block discarded – undo
923 923
 	 * (because the answer might be an array of answer values, so passing pretty_value=true
924 924
 	 * will convert it into some kind of string)
925 925
 	 */
926
-	public function answer_value_to_question( $question, $pretty_value=true ) {
926
+	public function answer_value_to_question($question, $pretty_value = true) {
927 927
 		$question_id = EEM_Question::instance()->ensure_is_ID($question);
928
-		return EEM_Answer::instance()->get_answer_value_to_question($this,$question_id,$pretty_value);
928
+		return EEM_Answer::instance()->get_answer_value_to_question($this, $question_id, $pretty_value);
929 929
 	}
930 930
 
931 931
 
@@ -938,13 +938,13 @@  discard block
 block discarded – undo
938 938
 	 */
939 939
 	public function question_groups() {
940 940
 		$question_groups = array();
941
-		if ( $this->event() instanceof EE_Event ) {
941
+		if ($this->event() instanceof EE_Event) {
942 942
 			$question_groups = $this->event()->question_groups(
943 943
 				array(
944 944
 					array(
945 945
 						'Event_Question_Group.EQG_primary' => $this->count() == 1 ? true : false
946 946
 					),
947
-					'order_by' => array( 'QSG_order' => 'ASC' )
947
+					'order_by' => array('QSG_order' => 'ASC')
948 948
 				)
949 949
 			);
950 950
 		}
@@ -961,7 +961,7 @@  discard block
 block discarded – undo
961 961
 	 */
962 962
 	public function count_question_groups() {
963 963
 		$qg_count = 0;
964
-		if ( $this->event() instanceof EE_Event ) {
964
+		if ($this->event() instanceof EE_Event) {
965 965
 			$qg_count = $this->event()->count_related(
966 966
 				'Question_Group',
967 967
 				array(
@@ -982,7 +982,7 @@  discard block
 block discarded – undo
982 982
 	 * @return string
983 983
 	 */
984 984
 	public function reg_date() {
985
-		return $this->get_datetime( 'REG_date' );
985
+		return $this->get_datetime('REG_date');
986 986
 	}
987 987
 
988 988
 
@@ -994,7 +994,7 @@  discard block
 block discarded – undo
994 994
 	 * @return EE_Datetime_Ticket
995 995
 	 */
996 996
 	public function datetime_ticket() {
997
-		return $this->get_first_related( 'Datetime_Ticket' );
997
+		return $this->get_first_related('Datetime_Ticket');
998 998
 	}
999 999
 
1000 1000
 
@@ -1004,15 +1004,15 @@  discard block
 block discarded – undo
1004 1004
 	 * @param EE_Datetime_Ticket $datetime_ticket
1005 1005
 	 * @return EE_Datetime_Ticket
1006 1006
 	 */
1007
-	public function set_datetime_ticket( $datetime_ticket ) {
1008
-		return $this->_add_relation_to( $datetime_ticket, 'Datetime_Ticket' );
1007
+	public function set_datetime_ticket($datetime_ticket) {
1008
+		return $this->_add_relation_to($datetime_ticket, 'Datetime_Ticket');
1009 1009
 	}
1010 1010
 	/**
1011 1011
 	 * Gets deleted
1012 1012
 	 * @return boolean
1013 1013
 	 */
1014 1014
 	public function deleted() {
1015
-		return $this->get( 'REG_deleted' );
1015
+		return $this->get('REG_deleted');
1016 1016
 	}
1017 1017
 
1018 1018
 	/**
@@ -1021,7 +1021,7 @@  discard block
 block discarded – undo
1021 1021
 	 * @return boolean
1022 1022
 	 */
1023 1023
 	public function set_deleted($deleted) {
1024
-	    if ( $deleted ) {
1024
+	    if ($deleted) {
1025 1025
 	        $this->delete();
1026 1026
         } else {
1027 1027
 	        $this->restore();
@@ -1035,7 +1035,7 @@  discard block
 block discarded – undo
1035 1035
 	 * @return EE_Status
1036 1036
 	 */
1037 1037
 	public function status_obj() {
1038
-		return $this->get_first_related( 'Status' );
1038
+		return $this->get_first_related('Status');
1039 1039
 	}
1040 1040
 
1041 1041
 
@@ -1046,7 +1046,7 @@  discard block
 block discarded – undo
1046 1046
 	 * @return int
1047 1047
 	 */
1048 1048
 	public function count_checkins() {
1049
-		return $this->get_model()->count_related( $this, 'Checkin' );
1049
+		return $this->get_model()->count_related($this, 'Checkin');
1050 1050
 	}
1051 1051
 
1052 1052
 
@@ -1056,7 +1056,7 @@  discard block
 block discarded – undo
1056 1056
 	 * @return int
1057 1057
 	 */
1058 1058
 	public function count_checkins_not_checkedout() {
1059
-		return $this->get_model()->count_related( $this, 'Checkin', array( array( 'CHK_in' => 1 ) ) );
1059
+		return $this->get_model()->count_related($this, 'Checkin', array(array('CHK_in' => 1)));
1060 1060
 	}
1061 1061
 
1062 1062
 
@@ -1069,20 +1069,20 @@  discard block
 block discarded – undo
1069 1069
 	 *
1070 1070
 	 * @return bool
1071 1071
 	 */
1072
-	public function can_checkin( $DTT_OR_ID, $check_approved = TRUE ) {
1073
-		$DTT_ID = EEM_Datetime::instance()->ensure_is_ID( $DTT_OR_ID );
1072
+	public function can_checkin($DTT_OR_ID, $check_approved = TRUE) {
1073
+		$DTT_ID = EEM_Datetime::instance()->ensure_is_ID($DTT_OR_ID);
1074 1074
 
1075 1075
 		//first check registration status
1076
-		if (  ( $check_approved && ! $this->is_approved() ) || ! $DTT_ID ) {
1076
+		if (($check_approved && ! $this->is_approved()) || ! $DTT_ID) {
1077 1077
 			return false;
1078 1078
 		}
1079 1079
 		//is there a datetime ticket that matches this dtt_ID?
1080
-		if ( ! ( EEM_Datetime_Ticket::instance()->exists( array( array( 'TKT_ID' => $this->get('TKT_ID' ), 'DTT_ID' => $DTT_ID ) ) ) ) ) {
1080
+		if ( ! (EEM_Datetime_Ticket::instance()->exists(array(array('TKT_ID' => $this->get('TKT_ID'), 'DTT_ID' => $DTT_ID))))) {
1081 1081
 			return false;
1082 1082
 		}
1083 1083
 
1084 1084
 		//final check is against TKT_uses
1085
-		return $this->verify_can_checkin_against_TKT_uses( $DTT_ID );
1085
+		return $this->verify_can_checkin_against_TKT_uses($DTT_ID);
1086 1086
 	}
1087 1087
 
1088 1088
 
@@ -1095,10 +1095,10 @@  discard block
 block discarded – undo
1095 1095
 	 * @param int | EE_Datetime  $DTT_OR_ID  The datetime the registration is being checked against
1096 1096
 	 * @return bool   true means can checkin.  false means cannot checkin.
1097 1097
 	 */
1098
-	public function verify_can_checkin_against_TKT_uses( $DTT_OR_ID ) {
1099
-		$DTT_ID = EEM_Datetime::instance()->ensure_is_ID( $DTT_OR_ID );
1098
+	public function verify_can_checkin_against_TKT_uses($DTT_OR_ID) {
1099
+		$DTT_ID = EEM_Datetime::instance()->ensure_is_ID($DTT_OR_ID);
1100 1100
 
1101
-		if ( ! $DTT_ID ) {
1101
+		if ( ! $DTT_ID) {
1102 1102
 			return false;
1103 1103
 		}
1104 1104
 
@@ -1106,23 +1106,23 @@  discard block
 block discarded – undo
1106 1106
 
1107 1107
 		// if max uses is not set or equals infinity then return true cause its not a factor for whether user can check-in
1108 1108
 		// or not.
1109
-		if ( ! $max_uses || $max_uses === EE_INF ) {
1109
+		if ( ! $max_uses || $max_uses === EE_INF) {
1110 1110
 			return true;
1111 1111
 		}
1112 1112
 
1113 1113
 		//does this datetime have a checkin record?  If so, then the dtt count has already been verified so we can just
1114 1114
 		//go ahead and toggle.
1115
-		if ( EEM_Checkin::instance()->exists( array( array( 'REG_ID' => $this->ID(), 'DTT_ID' => $DTT_ID ) ) ) ) {
1115
+		if (EEM_Checkin::instance()->exists(array(array('REG_ID' => $this->ID(), 'DTT_ID' => $DTT_ID)))) {
1116 1116
 			return true;
1117 1117
 		}
1118 1118
 
1119 1119
 		//made it here so the last check is whether the number of checkins per unique datetime on this registration
1120 1120
 		//disallows further check-ins.
1121
-		$count_unique_dtt_checkins = EEM_Checkin::instance()->count( array( array( 'REG_ID' => $this->ID(), 'CHK_in' => true ) ), 'DTT_ID', true );
1121
+		$count_unique_dtt_checkins = EEM_Checkin::instance()->count(array(array('REG_ID' => $this->ID(), 'CHK_in' => true)), 'DTT_ID', true);
1122 1122
 		// checkins have already reached their max number of uses
1123 1123
 		// so registrant can NOT checkin
1124
-		if ( $count_unique_dtt_checkins >= $max_uses ) {
1125
-			EE_Error::add_error( __( 'Check-in denied because number of datetime uses for the ticket has been reached or exceeded.', 'event_espresso' ), __FILE__, __FUNCTION__, __LINE__ );
1124
+		if ($count_unique_dtt_checkins >= $max_uses) {
1125
+			EE_Error::add_error(__('Check-in denied because number of datetime uses for the ticket has been reached or exceeded.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
1126 1126
 			return false;
1127 1127
 		}
1128 1128
 		return true;
@@ -1144,15 +1144,15 @@  discard block
 block discarded – undo
1144 1144
      * @return bool|int     the chk_in status toggled to OR false if nothing got changed.
1145 1145
      * @throws EE_Error
1146 1146
      */
1147
-	public function toggle_checkin_status( $DTT_ID = null, $verify = false ) {
1148
-		if ( empty( $DTT_ID ) ) {
1147
+	public function toggle_checkin_status($DTT_ID = null, $verify = false) {
1148
+		if (empty($DTT_ID)) {
1149 1149
 			$datetime = $this->get_latest_related_datetime();
1150 1150
 			$DTT_ID = $datetime instanceof EE_Datetime ? $datetime->ID() : 0;
1151 1151
 		// verify the registration can checkin for the given DTT_ID
1152
-		} elseif ( ! $this->can_checkin( $DTT_ID, $verify ) ) {
1152
+		} elseif ( ! $this->can_checkin($DTT_ID, $verify)) {
1153 1153
 			EE_Error::add_error(
1154 1154
 					sprintf(
1155
-						__( 'The given registration (ID:%1$d) can not be checked in to the given DTT_ID (%2$d), because the registration does not have access', 'event_espresso'),
1155
+						__('The given registration (ID:%1$d) can not be checked in to the given DTT_ID (%2$d), because the registration does not have access', 'event_espresso'),
1156 1156
 						$this->ID(),
1157 1157
 						$DTT_ID
1158 1158
 					),
@@ -1166,8 +1166,8 @@  discard block
 block discarded – undo
1166 1166
 			EE_Registration::checkin_status_out => EE_Registration::checkin_status_in
1167 1167
 		);
1168 1168
 		//start by getting the current status so we know what status we'll be changing to.
1169
-		$cur_status = $this->check_in_status_for_datetime( $DTT_ID, NULL );
1170
-		$status_to = $status_paths[ $cur_status ];
1169
+		$cur_status = $this->check_in_status_for_datetime($DTT_ID, NULL);
1170
+		$status_to = $status_paths[$cur_status];
1171 1171
 		// database only records true for checked IN or false for checked OUT
1172 1172
 		// no record ( null ) means checked in NEVER, but we obviously don't save that
1173 1173
 		$new_status = $status_to === EE_Registration::checkin_status_in ? true : false;
@@ -1175,24 +1175,24 @@  discard block
 block discarded – undo
1175 1175
 		// because we are keeping track of Check-ins over time.
1176 1176
 		// Eventually we'll probably want to show a list table
1177 1177
 		// for the individual Check-ins so that they can be managed.
1178
-		$checkin = EE_Checkin::new_instance( array(
1178
+		$checkin = EE_Checkin::new_instance(array(
1179 1179
 				'REG_ID' => $this->ID(),
1180 1180
 				'DTT_ID' => $DTT_ID,
1181 1181
 				'CHK_in' => $new_status
1182
-		) );
1182
+		));
1183 1183
 		// if the record could not be saved then return false
1184
-		if ( $checkin->save() === 0 ) {
1185
-			if ( WP_DEBUG ) {
1184
+		if ($checkin->save() === 0) {
1185
+			if (WP_DEBUG) {
1186 1186
 				global $wpdb;
1187 1187
 				$error = sprintf(
1188
-					__( 'Registration check in update failed because of the following database error: %1$s%2$s', 'event_espresso' ),
1188
+					__('Registration check in update failed because of the following database error: %1$s%2$s', 'event_espresso'),
1189 1189
 					'<br />',
1190 1190
 					$wpdb->last_error
1191 1191
 				);
1192 1192
 			} else {
1193
-				$error = __( 'Registration check in update failed because of an unknown database error', 'event_espresso' );
1193
+				$error = __('Registration check in update failed because of an unknown database error', 'event_espresso');
1194 1194
 			}
1195
-			EE_Error::add_error( $error, __FILE__, __FUNCTION__, __LINE__ );
1195
+			EE_Error::add_error($error, __FILE__, __FUNCTION__, __LINE__);
1196 1196
 			return false;
1197 1197
 		}
1198 1198
 		return $status_to;
@@ -1213,7 +1213,7 @@  discard block
 block discarded – undo
1213 1213
 				array(
1214 1214
 					'Ticket.Registration.REG_ID' => $this->ID()
1215 1215
 				),
1216
-				'order_by' => array( 'DTT_EVT_start' => 'DESC' )
1216
+				'order_by' => array('DTT_EVT_start' => 'DESC')
1217 1217
 			)
1218 1218
 		);
1219 1219
 	}
@@ -1232,7 +1232,7 @@  discard block
 block discarded – undo
1232 1232
 				array(
1233 1233
 					'Ticket.Registration.REG_ID' => $this->ID()
1234 1234
 				),
1235
-				'order_by' => array( 'DTT_EVT_start' => 'ASC' )
1235
+				'order_by' => array('DTT_EVT_start' => 'ASC')
1236 1236
 			)
1237 1237
 		);
1238 1238
 	}
@@ -1251,21 +1251,21 @@  discard block
 block discarded – undo
1251 1251
      * @return int                Integer representing Check-in status.
1252 1252
      * @throws \EE_Error
1253 1253
      */
1254
-	public function check_in_status_for_datetime( $DTT_ID = 0, $checkin = null ) {
1254
+	public function check_in_status_for_datetime($DTT_ID = 0, $checkin = null) {
1255 1255
 		$checkin_query_params = array(
1256
-			'order_by' => array( 'CHK_timestamp' => 'DESC' )
1256
+			'order_by' => array('CHK_timestamp' => 'DESC')
1257 1257
 		);
1258 1258
 
1259
-		if ( $DTT_ID > 0 ) {
1260
-			$checkin_query_params[0] = array( 'DTT_ID' => $DTT_ID );
1259
+		if ($DTT_ID > 0) {
1260
+			$checkin_query_params[0] = array('DTT_ID' => $DTT_ID);
1261 1261
 		}
1262 1262
 
1263 1263
 		//get checkin object (if exists)
1264 1264
 		$checkin = $checkin instanceof EE_Checkin
1265 1265
             ? $checkin
1266
-            : $this->get_first_related( 'Checkin', $checkin_query_params );
1267
-		if ( $checkin instanceof EE_Checkin ) {
1268
-			if ( $checkin->get( 'CHK_in' ) ) {
1266
+            : $this->get_first_related('Checkin', $checkin_query_params);
1267
+		if ($checkin instanceof EE_Checkin) {
1268
+			if ($checkin->get('CHK_in')) {
1269 1269
 				return EE_Registration::checkin_status_in; //checked in
1270 1270
 			}
1271 1271
 			return EE_Registration::checkin_status_out; //had checked in but is now checked out.
@@ -1281,28 +1281,28 @@  discard block
 block discarded – undo
1281 1281
 	 * @param bool $error  This just flags that you want an error message returned. This is put in so that the error message can be customized with the attendee name.
1282 1282
 	 * @return string         internationalized message
1283 1283
 	 */
1284
-	public function get_checkin_msg( $DTT_ID, $error = FALSE ) {
1284
+	public function get_checkin_msg($DTT_ID, $error = FALSE) {
1285 1285
 		//let's get the attendee first so we can include the name of the attendee
1286
-		$attendee = $this->get_first_related( 'Attendee' );
1287
-		if ( $attendee instanceof EE_Attendee ) {
1288
-			if ( $error ) {
1289
-				return sprintf( __( "%s's check-in status was not changed.", "event_espresso" ), $attendee->full_name() );
1286
+		$attendee = $this->get_first_related('Attendee');
1287
+		if ($attendee instanceof EE_Attendee) {
1288
+			if ($error) {
1289
+				return sprintf(__("%s's check-in status was not changed.", "event_espresso"), $attendee->full_name());
1290 1290
 			}
1291
-			$cur_status = $this->check_in_status_for_datetime( $DTT_ID );
1291
+			$cur_status = $this->check_in_status_for_datetime($DTT_ID);
1292 1292
 			//what is the status message going to be?
1293
-			switch ( $cur_status ) {
1293
+			switch ($cur_status) {
1294 1294
 				case EE_Registration::checkin_status_never :
1295
-					return sprintf( __( "%s has been removed from Check-in records", "event_espresso" ), $attendee->full_name() );
1295
+					return sprintf(__("%s has been removed from Check-in records", "event_espresso"), $attendee->full_name());
1296 1296
 					break;
1297 1297
 				case EE_Registration::checkin_status_in :
1298
-					return sprintf( __( '%s has been checked in', 'event_espresso' ), $attendee->full_name() );
1298
+					return sprintf(__('%s has been checked in', 'event_espresso'), $attendee->full_name());
1299 1299
 					break;
1300 1300
 				case EE_Registration::checkin_status_out :
1301
-					return sprintf( __( '%s has been checked out', 'event_espresso' ), $attendee->full_name() );
1301
+					return sprintf(__('%s has been checked out', 'event_espresso'), $attendee->full_name());
1302 1302
 					break;
1303 1303
 			}
1304 1304
 		}
1305
-		return __( "The check-in status could not be determined.", "event_espresso" );
1305
+		return __("The check-in status could not be determined.", "event_espresso");
1306 1306
 	}
1307 1307
 
1308 1308
 
@@ -1326,7 +1326,7 @@  discard block
 block discarded – undo
1326 1326
 	 *        get Registration Code
1327 1327
 	 */
1328 1328
 	public function reg_code() {
1329
-		return $this->get( 'REG_code' );
1329
+		return $this->get('REG_code');
1330 1330
 	}
1331 1331
 
1332 1332
 
@@ -1335,7 +1335,7 @@  discard block
 block discarded – undo
1335 1335
 	 *        get Transaction ID
1336 1336
 	 */
1337 1337
 	public function transaction_ID() {
1338
-		return $this->get( 'TXN_ID' );
1338
+		return $this->get('TXN_ID');
1339 1339
 	}
1340 1340
 
1341 1341
 
@@ -1344,7 +1344,7 @@  discard block
 block discarded – undo
1344 1344
 	 * @return int
1345 1345
 	 */
1346 1346
 	public function ticket_ID() {
1347
-		return $this->get( 'TKT_ID' );
1347
+		return $this->get('TKT_ID');
1348 1348
 	}
1349 1349
 
1350 1350
 
@@ -1356,17 +1356,17 @@  discard block
 block discarded – undo
1356 1356
 	 * @param    string $REG_code Registration Code
1357 1357
 	 * @param	boolean $use_default
1358 1358
 	 */
1359
-	public function set_reg_code( $REG_code, $use_default = FALSE ) {
1360
-		if ( empty( $REG_code )) {
1361
-			EE_Error::add_error( __( 'REG_code can not be empty.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__ );
1359
+	public function set_reg_code($REG_code, $use_default = FALSE) {
1360
+		if (empty($REG_code)) {
1361
+			EE_Error::add_error(__('REG_code can not be empty.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
1362 1362
 			return;
1363 1363
 		}
1364
-		if ( ! $this->reg_code() ) {
1365
-			parent::set( 'REG_code', $REG_code, $use_default );
1364
+		if ( ! $this->reg_code()) {
1365
+			parent::set('REG_code', $REG_code, $use_default);
1366 1366
 		} else {
1367 1367
 			EE_Error::doing_it_wrong(
1368
-				__CLASS__ . '::' . __FUNCTION__,
1369
-				__( 'Can not change a registration REG_code once it has been set.', 'event_espresso' ),
1368
+				__CLASS__.'::'.__FUNCTION__,
1369
+				__('Can not change a registration REG_code once it has been set.', 'event_espresso'),
1370 1370
 				'4.6.0'
1371 1371
 			);
1372 1372
 		}
@@ -1386,17 +1386,17 @@  discard block
 block discarded – undo
1386 1386
 	 * @return EE_Registration[]  or empty array if this isn't a group registration.
1387 1387
 	 */
1388 1388
 	public function get_all_other_registrations_in_group() {
1389
-		if ( $this->group_size() < 2 ) {
1389
+		if ($this->group_size() < 2) {
1390 1390
 			return array();
1391 1391
 		}
1392 1392
 
1393 1393
 		$query[0] = array(
1394 1394
 			'TXN_ID' => $this->transaction_ID(),
1395
-			'REG_ID' => array( '!=', $this->ID() ),
1395
+			'REG_ID' => array('!=', $this->ID()),
1396 1396
 			'TKT_ID' => $this->ticket_ID()
1397 1397
 			);
1398 1398
 
1399
-		$registrations = $this->get_model()->get_all( $query );
1399
+		$registrations = $this->get_model()->get_all($query);
1400 1400
 		return $registrations;
1401 1401
 	}
1402 1402
 
@@ -1405,14 +1405,14 @@  discard block
 block discarded – undo
1405 1405
 	 * @return string
1406 1406
 	 */
1407 1407
 	public function get_admin_details_link() {
1408
-		EE_Registry::instance()->load_helper( 'URL' );
1408
+		EE_Registry::instance()->load_helper('URL');
1409 1409
 		return EEH_URL::add_query_args_and_nonce(
1410 1410
 			array(
1411 1411
 				'page' => 'espresso_registrations',
1412 1412
 				'action' => 'view_registration',
1413 1413
 				'_REG_ID' => $this->ID()
1414 1414
 			),
1415
-			admin_url( 'admin.php' )
1415
+			admin_url('admin.php')
1416 1416
 		);
1417 1417
 	}
1418 1418
 
@@ -1437,12 +1437,12 @@  discard block
 block discarded – undo
1437 1437
 	 * @return string
1438 1438
 	 */
1439 1439
 	public function get_admin_overview_link() {
1440
-		EE_Registry::instance()->load_helper( 'URL' );
1440
+		EE_Registry::instance()->load_helper('URL');
1441 1441
 		return EEH_URL::add_query_args_and_nonce(
1442 1442
 			array(
1443 1443
 				'page' => 'espresso_registrations'
1444 1444
 			),
1445
-			admin_url( 'admin.php' )
1445
+			admin_url('admin.php')
1446 1446
 		);
1447 1447
 	}
1448 1448
 
@@ -1453,8 +1453,8 @@  discard block
 block discarded – undo
1453 1453
 	 * @return \EE_Registration[]
1454 1454
 	 * @throws \EE_Error
1455 1455
 	 */
1456
-	public function payments( $query_params = array() ) {
1457
-		return $this->get_many_related( 'Payment', $query_params );
1456
+	public function payments($query_params = array()) {
1457
+		return $this->get_many_related('Payment', $query_params);
1458 1458
 	}
1459 1459
 
1460 1460
 
@@ -1464,8 +1464,8 @@  discard block
 block discarded – undo
1464 1464
 	 * @return \EE_Registration_Payment[]
1465 1465
 	 * @throws \EE_Error
1466 1466
 	 */
1467
-	public function registration_payments( $query_params = array() ) {
1468
-		return $this->get_many_related( 'Registration_Payment', $query_params );
1467
+	public function registration_payments($query_params = array()) {
1468
+		return $this->get_many_related('Registration_Payment', $query_params);
1469 1469
 	}
1470 1470
 
1471 1471
 
@@ -1478,7 +1478,7 @@  discard block
 block discarded – undo
1478 1478
 	 * @return EE_Payment_Method|null
1479 1479
 	 */
1480 1480
 	public function payment_method() {
1481
-		return EEM_Payment_Method::instance()->get_last_used_for_registration( $this );
1481
+		return EEM_Payment_Method::instance()->get_last_used_for_registration($this);
1482 1482
 	}
1483 1483
 
1484 1484
 
@@ -1525,7 +1525,7 @@  discard block
 block discarded – undo
1525 1525
      */
1526 1526
     public function delete()
1527 1527
     {
1528
-        if($this->update_extra_meta(EE_Registration::PRE_TRASH_REG_STATUS_KEY, $this->status_ID()) === true) {
1528
+        if ($this->update_extra_meta(EE_Registration::PRE_TRASH_REG_STATUS_KEY, $this->status_ID()) === true) {
1529 1529
             $this->set_status(EEM_Registration::status_id_cancelled);
1530 1530
         }
1531 1531
         return parent::delete();
Please login to merge, or discard this patch.
admin_pages/payments/Payments_Admin_Page.core.php 3 patches
Doc Comments   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -470,7 +470,7 @@  discard block
 block discarded – undo
470 470
      *
471 471
      * @access protected
472 472
      * @param \EE_Payment_Method $payment_method
473
-     * @return \EE_Form_Section_Proper
473
+     * @return EE_Form_Section_HTML
474 474
      */
475 475
     protected function _pci_dss_compliance(EE_Payment_Method $payment_method)
476 476
     {
@@ -506,7 +506,7 @@  discard block
 block discarded – undo
506 506
      *
507 507
      * @access protected
508 508
      * @param \EE_Payment_Method $payment_method
509
-     * @return \EE_Form_Section_Proper
509
+     * @return EE_Form_Section_HTML
510 510
      */
511 511
     protected function _currency_support(EE_Payment_Method $payment_method)
512 512
     {
@@ -541,7 +541,7 @@  discard block
 block discarded – undo
541 541
      *
542 542
      * @access protected
543 543
      * @param \EE_Payment_Method $payment_method
544
-     * @return \EE_Form_Section_HTML
544
+     * @return EE_Payment_Method_Form
545 545
      */
546 546
     protected function _payment_method_settings(EE_Payment_Method $payment_method)
547 547
     {
@@ -615,7 +615,7 @@  discard block
 block discarded – undo
615 615
      *
616 616
      * @access protected
617 617
      * @param \EE_Payment_Method $payment_method
618
-     * @return \EE_Form_Section_Proper
618
+     * @return EE_Form_Section_HTML
619 619
      */
620 620
     protected function _deactivate_payment_method_button(EE_Payment_Method $payment_method)
621 621
     {
Please login to merge, or discard this patch.
Indentation   +999 added lines, -999 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 if (! defined('EVENT_ESPRESSO_VERSION')) {
3
-    exit('NO direct script access allowed');
3
+	exit('NO direct script access allowed');
4 4
 }
5 5
 
6 6
 
@@ -27,838 +27,838 @@  discard block
 block discarded – undo
27 27
 class Payments_Admin_Page extends EE_Admin_Page
28 28
 {
29 29
 
30
-    /**
31
-     * Variables used for when we're re-sorting the logs results, in case
32
-     * we needed to do two queries and we need to resort
33
-     *
34
-     * @var string
35
-     */
36
-    private $_sort_logs_again_direction;
37
-
38
-
39
-
40
-    /**
41
-     * @Constructor
42
-     * @access public
43
-     * @param bool $routing indicate whether we want to just load the object and handle routing or just load the object.
44
-     * @return \Payments_Admin_Page
45
-     */
46
-    public function __construct($routing = true)
47
-    {
48
-        parent::__construct($routing);
49
-    }
50
-
51
-
52
-
53
-    protected function _init_page_props()
54
-    {
55
-        $this->page_slug = EE_PAYMENTS_PG_SLUG;
56
-        $this->page_label = __('Payment Methods', 'event_espresso');
57
-        $this->_admin_base_url = EE_PAYMENTS_ADMIN_URL;
58
-        $this->_admin_base_path = EE_PAYMENTS_ADMIN;
59
-    }
60
-
61
-
62
-
63
-    protected function _ajax_hooks()
64
-    {
65
-        //todo: all hooks for ajax goes here.
66
-    }
67
-
68
-
69
-
70
-    protected function _define_page_props()
71
-    {
72
-        $this->_admin_page_title = $this->page_label;
73
-        $this->_labels = array(
74
-            'publishbox' => __('Update Settings', 'event_espresso'),
75
-        );
76
-    }
77
-
78
-
79
-
80
-    protected function _set_page_routes()
81
-    {
82
-        /**
83
-         * note that with payment method capabilities, although we've implemented
84
-         * capability mapping which will be used for accessing payment methods owned by
85
-         * other users.  This is not fully implemented yet in the payment method ui.
86
-         * Currently only the "plural" caps are in active use.
87
-         * When cap mapping is implemented, some routes will need to use the singular form of
88
-         * capability method and also include the $id of the payment method for the route.
89
-         **/
90
-        $this->_page_routes = array(
91
-            'default'                   => array(
92
-                'func'       => '_payment_methods_list',
93
-                'capability' => 'ee_edit_payment_methods',
94
-            ),
95
-            'payment_settings'          => array(
96
-                'func'       => '_payment_settings',
97
-                'capability' => 'ee_manage_gateways',
98
-            ),
99
-            'activate_payment_method'   => array(
100
-                'func'       => '_activate_payment_method',
101
-                'noheader'   => true,
102
-                'capability' => 'ee_edit_payment_methods',
103
-            ),
104
-            'deactivate_payment_method' => array(
105
-                'func'       => '_deactivate_payment_method',
106
-                'noheader'   => true,
107
-                'capability' => 'ee_delete_payment_methods',
108
-            ),
109
-            'update_payment_method'     => array(
110
-                'func'               => '_update_payment_method',
111
-                'noheader'           => true,
112
-                'headers_sent_route' => 'default',
113
-                'capability'         => 'ee_edit_payment_methods',
114
-            ),
115
-            'update_payment_settings'   => array(
116
-                'func'       => '_update_payment_settings',
117
-                'noheader'   => true,
118
-                'capability' => 'ee_manage_gateways',
119
-            ),
120
-            'payment_log'               => array(
121
-                'func'       => '_payment_log_overview_list_table',
122
-                'capability' => 'ee_read_payment_methods',
123
-            ),
124
-            'payment_log_details'       => array(
125
-                'func'       => '_payment_log_details',
126
-                'capability' => 'ee_read_payment_methods',
127
-            ),
128
-        );
129
-    }
130
-
131
-
132
-
133
-    protected function _set_page_config()
134
-    {
135
-        $payment_method_list_config = array(
136
-            'nav'           => array(
137
-                'label' => __('Payment Methods', 'event_espresso'),
138
-                'order' => 10,
139
-            ),
140
-            'metaboxes'     => $this->_default_espresso_metaboxes,
141
-            'help_tabs'     => array_merge(
142
-                array(
143
-                    'payment_methods_overview_help_tab' => array(
144
-                        'title'    => __('Payment Methods Overview', 'event_espresso'),
145
-                        'filename' => 'payment_methods_overview',
146
-                    ),
147
-                ),
148
-                $this->_add_payment_method_help_tabs()),
149
-            'help_tour'     => array('Payment_Methods_Selection_Help_Tour'),
150
-            'require_nonce' => false,
151
-        );
152
-        $this->_page_config = array(
153
-            'default'          => $payment_method_list_config,
154
-            'payment_settings' => array(
155
-                'nav'           => array(
156
-                    'label' => __('Settings', 'event_espresso'),
157
-                    'order' => 20,
158
-                ),
159
-                'help_tabs'     => array(
160
-                    'payment_methods_settings_help_tab' => array(
161
-                        'title'    => __('Payment Method Settings', 'event_espresso'),
162
-                        'filename' => 'payment_methods_settings',
163
-                    ),
164
-                ),
165
-                //'help_tour' => array( 'Payment_Methods_Settings_Help_Tour' ),
166
-                'metaboxes'     => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')),
167
-                'require_nonce' => false,
168
-            ),
169
-            'payment_log'      => array(
170
-                'nav'           => array(
171
-                    'label' => __("Logs", 'event_espresso'),
172
-                    'order' => 30,
173
-                ),
174
-                'list_table'    => 'Payment_Log_Admin_List_Table',
175
-                'metaboxes'     => $this->_default_espresso_metaboxes,
176
-                'require_nonce' => false,
177
-            ),
178
-        );
179
-    }
180
-
181
-
182
-
183
-    /**
184
-     * @return array
185
-     */
186
-    protected function _add_payment_method_help_tabs()
187
-    {
188
-        EE_Registry::instance()->load_lib('Payment_Method_Manager');
189
-        $payment_method_types = EE_Payment_Method_Manager::instance()->payment_method_types();
190
-        $all_pmt_help_tabs_config = array();
191
-        foreach ($payment_method_types as $payment_method_type) {
192
-            if (! EE_Registry::instance()->CAP->current_user_can($payment_method_type->cap_name(),
193
-                'specific_payment_method_type_access')
194
-            ) {
195
-                continue;
196
-            }
197
-            foreach ($payment_method_type->help_tabs_config() as $help_tab_name => $config) {
198
-                $template_args = isset($config['template_args']) ? $config['template_args'] : array();
199
-                $template_args['admin_page_obj'] = $this;
200
-                $all_pmt_help_tabs_config[$help_tab_name] = array(
201
-                    'title'   => $config['title'],
202
-                    'content' => EEH_Template::display_template(
203
-                        $payment_method_type->file_folder() . 'help_tabs' . DS . $config['filename'] . '.help_tab.php',
204
-                        $template_args,
205
-                        true),
206
-                );
207
-            }
208
-        }
209
-        return $all_pmt_help_tabs_config;
210
-    }
211
-
212
-
213
-
214
-    //none of the below group are currently used for Gateway Settings
215
-    protected function _add_screen_options()
216
-    {
217
-    }
218
-
219
-
220
-
221
-    protected function _add_feature_pointers()
222
-    {
223
-    }
224
-
225
-
226
-
227
-    public function admin_init()
228
-    {
229
-    }
230
-
231
-
232
-
233
-    public function admin_notices()
234
-    {
235
-    }
236
-
237
-
238
-
239
-    public function admin_footer_scripts()
240
-    {
241
-    }
242
-
243
-
244
-
245
-    public function load_scripts_styles()
246
-    {
247
-        wp_enqueue_script('ee_admin_js');
248
-        wp_enqueue_script('ee-text-links');
249
-        wp_enqueue_script('espresso_payments', EE_PAYMENTS_ASSETS_URL . 'espresso_payments_admin.js',
250
-            array('espresso-ui-theme', 'ee-datepicker'), EVENT_ESPRESSO_VERSION, true);
251
-    }
252
-
253
-
254
-
255
-    public function load_scripts_styles_default()
256
-    {
257
-        //styles
258
-        wp_register_style('espresso_payments', EE_PAYMENTS_ASSETS_URL . 'ee-payments.css', array(),
259
-            EVENT_ESPRESSO_VERSION);
260
-        wp_enqueue_style('espresso_payments');
261
-        wp_enqueue_style('ee-text-links');
262
-        //scripts
263
-    }
264
-
265
-
266
-
267
-    protected function _payment_methods_list()
268
-    {
269
-        /**
270
-         * first let's ensure payment methods have been setup. We do this here because when people activate a
271
-         * payment method for the first time (as an addon), it may not setup its capabilities or get registered correctly due
272
-         * to the loading process.  However, people MUST setup the details for the payment method so its safe to do a
273
-         * recheck here.
274
-         */
275
-        EE_Registry::instance()->load_lib('Payment_Method_Manager');
276
-        EEM_Payment_Method::instance()->verify_button_urls();
277
-        //setup tabs, one for each payment method type
278
-        $tabs = array();
279
-        $payment_methods = array();
280
-        foreach (EE_Payment_Method_Manager::instance()->payment_method_types() as $pmt_obj) {
281
-            // we don't want to show admin-only PMTs for now
282
-            if ($pmt_obj instanceof EE_PMT_Admin_Only) {
283
-                continue;
284
-            }
285
-            //check access
286
-            if (! EE_Registry::instance()->CAP->current_user_can($pmt_obj->cap_name(),
287
-                'specific_payment_method_type_access')
288
-            ) {
289
-                continue;
290
-            }
291
-            //check for any active pms of that type
292
-            $payment_method = EEM_Payment_Method::instance()->get_one_of_type($pmt_obj->system_name());
293
-            if (! $payment_method instanceof EE_Payment_Method) {
294
-                $payment_method = EE_Payment_Method::new_instance(
295
-                    array(
296
-                        'PMD_slug'       => sanitize_key($pmt_obj->system_name()),
297
-                        'PMD_type'       => $pmt_obj->system_name(),
298
-                        'PMD_name'       => $pmt_obj->pretty_name(),
299
-                        'PMD_admin_name' => $pmt_obj->pretty_name(),
300
-                    )
301
-                );
302
-            }
303
-            $payment_methods[$payment_method->slug()] = $payment_method;
304
-        }
305
-        $payment_methods = apply_filters('FHEE__Payments_Admin_Page___payment_methods_list__payment_methods',
306
-            $payment_methods);
307
-        foreach ($payment_methods as $payment_method) {
308
-            if ($payment_method instanceof EE_Payment_Method) {
309
-                add_meta_box(
310
-                //html id
311
-                    'espresso_' . $payment_method->slug() . '_payment_settings',
312
-                    //title
313
-                    sprintf(__('%s Settings', 'event_espresso'), $payment_method->admin_name()),
314
-                    //callback
315
-                    array($this, 'payment_method_settings_meta_box'),
316
-                    //post type
317
-                    null,
318
-                    //context
319
-                    'normal',
320
-                    //priority
321
-                    'default',
322
-                    //callback args
323
-                    array('payment_method' => $payment_method)
324
-                );
325
-                //setup for tabbed content
326
-                $tabs[$payment_method->slug()] = array(
327
-                    'label' => $payment_method->admin_name(),
328
-                    'class' => $payment_method->active() ? 'gateway-active' : '',
329
-                    'href'  => 'espresso_' . $payment_method->slug() . '_payment_settings',
330
-                    'title' => __('Modify this Payment Method', 'event_espresso'),
331
-                    'slug'  => $payment_method->slug(),
332
-                );
333
-            }
334
-        }
335
-        $this->_template_args['admin_page_header'] = EEH_Tabbed_Content::tab_text_links($tabs, 'payment_method_links',
336
-            '|', $this->_get_active_payment_method_slug());
337
-        $this->display_admin_page_with_sidebar();
338
-    }
339
-
340
-
341
-
342
-    /**
343
-     *   _get_active_payment_method_slug
344
-     *
345
-     * @return string
346
-     */
347
-    protected function _get_active_payment_method_slug()
348
-    {
349
-        $payment_method_slug = false;
350
-        //decide which payment method tab to open first, as dictated by the request's 'payment_method'
351
-        if (isset($this->_req_data['payment_method'])) {
352
-            // if they provided the current payment method, use it
353
-            $payment_method_slug = sanitize_key($this->_req_data['payment_method']);
354
-        }
355
-        $payment_method = EEM_Payment_Method::instance()->get_one(array(array('PMD_slug' => $payment_method_slug)));
356
-        // if that didn't work or wasn't provided, find another way to select the current pm
357
-        if (! $this->_verify_payment_method($payment_method)) {
358
-            // like, looking for an active one
359
-            $payment_method = EEM_Payment_Method::instance()->get_one_active('CART');
360
-            // test that one as well
361
-            if ($this->_verify_payment_method($payment_method)) {
362
-                $payment_method_slug = $payment_method->slug();
363
-            } else {
364
-                $payment_method_slug = 'paypal_standard';
365
-            }
366
-        }
367
-        return $payment_method_slug;
368
-    }
369
-
370
-
371
-
372
-    /**
373
-     *    payment_method_settings_meta_box
374
-     *    returns TRUE if the passed payment method is properly constructed and the logged in user has the correct
375
-     *    capabilities to access it
376
-     *
377
-     * @param \EE_Payment_Method $payment_method
378
-     * @return boolean
379
-     */
380
-    protected function _verify_payment_method($payment_method)
381
-    {
382
-        if (
383
-            $payment_method instanceof EE_Payment_Method && $payment_method->type_obj() instanceof EE_PMT_Base
384
-            && EE_Registry::instance()->CAP->current_user_can($payment_method->type_obj()->cap_name(),
385
-                'specific_payment_method_type_access')
386
-        ) {
387
-            return true;
388
-        }
389
-        return false;
390
-    }
391
-
392
-
393
-
394
-    /**
395
-     *    payment_method_settings_meta_box
396
-     *
397
-     * @param NULL  $post_obj_which_is_null is an object containing the current post (as a $post object)
398
-     * @param array $metabox                is an array with metabox id, title, callback, and args elements. the value
399
-     *                                      at 'args' has key 'payment_method', as set within _payment_methods_list
400
-     * @return string
401
-     * @throws EE_Error
402
-     */
403
-    public function payment_method_settings_meta_box($post_obj_which_is_null, $metabox)
404
-    {
405
-        $payment_method = isset($metabox['args'], $metabox['args']['payment_method'])
406
-            ? $metabox['args']['payment_method'] : null;
407
-        if (! $payment_method instanceof EE_Payment_Method) {
408
-            throw new EE_Error(sprintf(__('Payment method metabox setup incorrectly. No Payment method object was supplied',
409
-                'event_espresso')));
410
-        }
411
-        $payment_method_scopes = $payment_method->active();
412
-        // if the payment method really exists show its form, otherwise the activation template
413
-        if ($payment_method->ID() && ! empty($payment_method_scopes)) {
414
-            $form = $this->_generate_payment_method_settings_form($payment_method);
415
-            if ($form->form_data_present_in($this->_req_data)) {
416
-                $form->receive_form_submission($this->_req_data);
417
-            }
418
-            echo $form->form_open() . $form->get_html_and_js() . $form->form_close();
419
-        } else {
420
-            echo $this->_activate_payment_method_button($payment_method)->get_html_and_js();
421
-        }
422
-    }
423
-
424
-
425
-
426
-    /**
427
-     * Gets the form for all the settings related to this payment method type
428
-     *
429
-     * @access protected
430
-     * @param \EE_Payment_Method $payment_method
431
-     * @return \EE_Form_Section_Proper
432
-     */
433
-    protected function _generate_payment_method_settings_form(EE_Payment_Method $payment_method)
434
-    {
435
-        if (! $payment_method instanceof EE_Payment_Method) {
436
-            return new EE_Form_Section_Proper();
437
-        }
438
-        return new EE_Form_Section_Proper(
439
-            array(
440
-                'name'            => $payment_method->slug() . '_settings_form',
441
-                'html_id'         => $payment_method->slug() . '_settings_form',
442
-                'action'          => EE_Admin_Page::add_query_args_and_nonce(
443
-                    array(
444
-                        'action'         => 'update_payment_method',
445
-                        'payment_method' => $payment_method->slug(),
446
-                    ),
447
-                    EE_PAYMENTS_ADMIN_URL
448
-                ),
449
-                'layout_strategy' => new EE_Admin_Two_Column_Layout(),
450
-                'subsections'     => apply_filters(
451
-                    'FHEE__Payments_Admin_Page___generate_payment_method_settings_form__form_subsections',
452
-                    array(
453
-                        'pci_dss_compliance'      => $this->_pci_dss_compliance($payment_method),
454
-                        'currency_support'        => $this->_currency_support($payment_method),
455
-                        'payment_method_settings' => $this->_payment_method_settings($payment_method),
456
-                        'update'                  => $this->_update_payment_method_button($payment_method),
457
-                        'deactivate'              => $this->_deactivate_payment_method_button($payment_method),
458
-                        'fine_print'              => $this->_fine_print(),
459
-                    ),
460
-                    $payment_method
461
-                ),
462
-            )
463
-        );
464
-    }
465
-
466
-
467
-
468
-    /**
469
-     * _pci_dss_compliance
470
-     *
471
-     * @access protected
472
-     * @param \EE_Payment_Method $payment_method
473
-     * @return \EE_Form_Section_Proper
474
-     */
475
-    protected function _pci_dss_compliance(EE_Payment_Method $payment_method)
476
-    {
477
-        if ($payment_method->type_obj()->requires_https()) {
478
-            return new EE_Form_Section_HTML(
479
-                EEH_HTML::tr(
480
-                    EEH_HTML::th(
481
-                        EEH_HTML::label(
482
-                            EEH_HTML::strong(__('IMPORTANT', 'event_espresso'), '', 'important-notice')
483
-                        )
484
-                    ) .
485
-                    EEH_HTML::td(
486
-                        EEH_HTML::strong(__('You are responsible for your own website security and Payment Card Industry Data Security Standards (PCI DSS) compliance.',
487
-                            'event_espresso'))
488
-                        .
489
-                        EEH_HTML::br()
490
-                        .
491
-                        __('Learn more about ', 'event_espresso')
492
-                        . EEH_HTML::link('https://www.pcisecuritystandards.org/merchants/index.php',
493
-                            __('PCI DSS compliance', 'event_espresso'))
494
-                    )
495
-                )
496
-            );
497
-        } else {
498
-            return new EE_Form_Section_HTML('');
499
-        }
500
-    }
501
-
502
-
503
-
504
-    /**
505
-     * _currency_support
506
-     *
507
-     * @access protected
508
-     * @param \EE_Payment_Method $payment_method
509
-     * @return \EE_Form_Section_Proper
510
-     */
511
-    protected function _currency_support(EE_Payment_Method $payment_method)
512
-    {
513
-        if (! $payment_method->usable_for_currency(EE_Config::instance()->currency->code)) {
514
-            return new EE_Form_Section_HTML(
515
-                EEH_HTML::tr(
516
-                    EEH_HTML::th(
517
-                        EEH_HTML::label(
518
-                            EEH_HTML::strong(__('IMPORTANT', 'event_espresso'), '', 'important-notice')
519
-                        )
520
-                    ) .
521
-                    EEH_HTML::td(
522
-                        EEH_HTML::strong(
523
-                            sprintf(
524
-                                __('This payment method does not support the currency set on your site (%1$s). Please activate a different payment method or change your site\'s country and associated currency.',
525
-                                    'event_espresso'),
526
-                                EE_Config::instance()->currency->code
527
-                            )
528
-                        )
529
-                    )
530
-                )
531
-            );
532
-        } else {
533
-            return new EE_Form_Section_HTML('');
534
-        }
535
-    }
536
-
537
-
538
-
539
-    /**
540
-     * _update_payment_method_button
541
-     *
542
-     * @access protected
543
-     * @param \EE_Payment_Method $payment_method
544
-     * @return \EE_Form_Section_HTML
545
-     */
546
-    protected function _payment_method_settings(EE_Payment_Method $payment_method)
547
-    {
548
-        //modify the form so we only have/show fields that will be implemented for this version
549
-        return $this->_simplify_form($payment_method->type_obj()->settings_form(), $payment_method->name());
550
-    }
551
-
552
-
553
-
554
-    /**
555
-     * Simplifies the form to merely reproduce 4.1's gateway settings functionality
556
-     *
557
-     * @param EE_Form_Section_Proper $form_section
558
-     * @param string                 $payment_method_name
559
-     * @return \EE_Payment_Method_Form
560
-     * @throws \EE_Error
561
-     */
562
-    protected function _simplify_form($form_section, $payment_method_name = '')
563
-    {
564
-        if ($form_section instanceof EE_Payment_Method_Form) {
565
-            $form_section->exclude(
566
-                array(
567
-                    'PMD_type', //dont want them changing the type
568
-                    'PMD_slug', //or the slug (probably never)
569
-                    'PMD_wp_user', //or the user's ID
570
-                    'Currency' //or the currency, until the rest of EE supports simultaneous currencies
571
-                )
572
-            );
573
-            return $form_section;
574
-        } else {
575
-            throw new EE_Error(sprintf(__('The EE_Payment_Method_Form for the "%1$s" payment method is missing or invalid.',
576
-                'event_espresso'), $payment_method_name));
577
-        }
578
-    }
579
-
580
-
581
-
582
-    /**
583
-     * _update_payment_method_button
584
-     *
585
-     * @access protected
586
-     * @param \EE_Payment_Method $payment_method
587
-     * @return \EE_Form_Section_HTML
588
-     */
589
-    protected function _update_payment_method_button(EE_Payment_Method $payment_method)
590
-    {
591
-        $update_button = new EE_Submit_Input(
592
-            array(
593
-                'name'       => 'submit',
594
-                'html_id'    => 'save_' . $payment_method->slug() . '_settings',
595
-                'default'    => sprintf(__('Update %s Payment Settings', 'event_espresso'),
596
-                    $payment_method->admin_name()),
597
-                'html_label' => EEH_HTML::nbsp(),
598
-            )
599
-        );
600
-        return new EE_Form_Section_HTML(
601
-            EEH_HTML::no_row(EEH_HTML::br(2)) .
602
-            EEH_HTML::tr(
603
-                EEH_HTML::th(__('Update Settings', 'event_espresso')) .
604
-                EEH_HTML::td(
605
-                    $update_button->get_html_for_input()
606
-                )
607
-            )
608
-        );
609
-    }
610
-
611
-
612
-
613
-    /**
614
-     * _deactivate_payment_method_button
615
-     *
616
-     * @access protected
617
-     * @param \EE_Payment_Method $payment_method
618
-     * @return \EE_Form_Section_Proper
619
-     */
620
-    protected function _deactivate_payment_method_button(EE_Payment_Method $payment_method)
621
-    {
622
-        $link_text_and_title = sprintf(__('Deactivate %1$s Payments?', 'event_espresso'),
623
-            $payment_method->admin_name());
624
-        return new EE_Form_Section_HTML(
625
-            EEH_HTML::tr(
626
-                EEH_HTML::th(__('Deactivate Payment Method', 'event_espresso')) .
627
-                EEH_HTML::td(
628
-                    EEH_HTML::link(
629
-                        EE_Admin_Page::add_query_args_and_nonce(
630
-                            array(
631
-                                'action'         => 'deactivate_payment_method',
632
-                                'payment_method' => $payment_method->slug(),
633
-                            ),
634
-                            EE_PAYMENTS_ADMIN_URL
635
-                        ),
636
-                        $link_text_and_title,
637
-                        $link_text_and_title,
638
-                        'deactivate_' . $payment_method->slug(),
639
-                        'espresso-button button-secondary'
640
-                    )
641
-                )
642
-            )
643
-        );
644
-    }
645
-
646
-
647
-
648
-    /**
649
-     * _activate_payment_method_button
650
-     *
651
-     * @access protected
652
-     * @param \EE_Payment_Method $payment_method
653
-     * @return \EE_Form_Section_Proper
654
-     */
655
-    protected function _activate_payment_method_button(EE_Payment_Method $payment_method)
656
-    {
657
-        $link_text_and_title = sprintf(__('Activate %1$s Payment Method?', 'event_espresso'),
658
-            $payment_method->admin_name());
659
-        return new EE_Form_Section_Proper(
660
-            array(
661
-                'name'            => 'activate_' . $payment_method->slug() . '_settings_form',
662
-                'html_id'         => 'activate_' . $payment_method->slug() . '_settings_form',
663
-                'action'          => '#',
664
-                'layout_strategy' => new EE_Admin_Two_Column_Layout(),
665
-                'subsections'     => apply_filters(
666
-                    'FHEE__Payments_Admin_Page___activate_payment_method_button__form_subsections',
667
-                    array(
668
-                        new EE_Form_Section_HTML(
669
-                            EEH_HTML::tr(
670
-                                EEH_HTML::td($payment_method->type_obj()->introductory_html(),
671
-                                    '',
672
-                                    '',
673
-                                    '',
674
-                                    'colspan="2"'
675
-                                )
676
-                            ) .
677
-                            EEH_HTML::tr(
678
-                                EEH_HTML::th(
679
-                                    EEH_HTML::label(__('Click to Activate ', 'event_espresso'))
680
-                                ) .
681
-                                EEH_HTML::td(
682
-                                    EEH_HTML::link(
683
-                                        EE_Admin_Page::add_query_args_and_nonce(
684
-                                            array(
685
-                                                'action'              => 'activate_payment_method',
686
-                                                'payment_method_type' => $payment_method->type(),
687
-                                            ),
688
-                                            EE_PAYMENTS_ADMIN_URL
689
-                                        ),
690
-                                        $link_text_and_title,
691
-                                        $link_text_and_title,
692
-                                        'activate_' . $payment_method->slug(),
693
-                                        'espresso-button-green button-primary'
694
-                                    )
695
-                                )
696
-                            )
697
-                        ),
698
-                    ),
699
-                    $payment_method
700
-                ),
701
-            )
702
-        );
703
-    }
704
-
705
-
706
-
707
-    /**
708
-     * _fine_print
709
-     *
710
-     * @access protected
711
-     * @return \EE_Form_Section_HTML
712
-     */
713
-    protected function _fine_print()
714
-    {
715
-        return new EE_Form_Section_HTML(
716
-            EEH_HTML::tr(
717
-                EEH_HTML::th() .
718
-                EEH_HTML::td(
719
-                    EEH_HTML::p(__('All fields marked with a * are required fields', 'event_espresso'), '', 'grey-text')
720
-                )
721
-            )
722
-        );
723
-    }
724
-
725
-
726
-
727
-    /**
728
-     * Activates a payment method of that type. Mostly assuming there is only 1 of that type (or none so far)
729
-     *
730
-     * @global WP_User $current_user
731
-     */
732
-    protected function _activate_payment_method()
733
-    {
734
-        if (isset($this->_req_data['payment_method_type'])) {
735
-            $payment_method_type = sanitize_text_field($this->_req_data['payment_method_type']);
736
-            //see if one exists
737
-            EE_Registry::instance()->load_lib('Payment_Method_Manager');
738
-            $payment_method = EE_Payment_Method_Manager::instance()
739
-                                                       ->activate_a_payment_method_of_type($payment_method_type);
740
-            $this->_redirect_after_action(1, 'Payment Method', 'activated',
741
-                array('action' => 'default', 'payment_method' => $payment_method->slug()));
742
-        } else {
743
-            $this->_redirect_after_action(false, 'Payment Method', 'activated', array('action' => 'default'));
744
-        }
745
-    }
746
-
747
-
748
-
749
-    /**
750
-     * Deactivates the payment method with the specified slug, and redirects.
751
-     */
752
-    protected function _deactivate_payment_method()
753
-    {
754
-        if (isset($this->_req_data['payment_method'])) {
755
-            $payment_method_slug = sanitize_key($this->_req_data['payment_method']);
756
-            //deactivate it
757
-            EE_Registry::instance()->load_lib('Payment_Method_Manager');
758
-            $count_updated = EE_Payment_Method_Manager::instance()->deactivate_payment_method($payment_method_slug);
759
-            $this->_redirect_after_action($count_updated, 'Payment Method', 'deactivated',
760
-                array('action' => 'default', 'payment_method' => $payment_method_slug));
761
-        } else {
762
-            $this->_redirect_after_action(false, 'Payment Method', 'deactivated', array('action' => 'default'));
763
-        }
764
-    }
765
-
766
-
767
-
768
-    /**
769
-     * Processes the payment method form that was submitted. This is slightly trickier than usual form
770
-     * processing because we first need to identify WHICH form was processed and which payment method
771
-     * it corresponds to. Once we have done that, we see if the form is valid. If it is, the
772
-     * form's data is saved and we redirect to the default payment methods page, setting the updated payment method
773
-     * as the currently-selected one. If it DOESN'T validate, we render the page with the form's errors (in the
774
-     * subsequently called 'headers_sent_func' which is _payment_methods_list)
775
-     *
776
-     * @return void
777
-     */
778
-    protected function _update_payment_method()
779
-    {
780
-        if ($_SERVER['REQUEST_METHOD'] == 'POST') {
781
-            //ok let's find which gateway form to use based on the form input
782
-            EE_Registry::instance()->load_lib('Payment_Method_Manager');
783
-            /** @var $correct_pmt_form_to_use EE_Payment_Method_Form */
784
-            $correct_pmt_form_to_use = null;
785
-            $payment_method = null;
786
-            foreach (EEM_Payment_Method::instance()->get_all() as $payment_method) {
787
-                //get the form and simplify it, like what we do when we display it
788
-                $pmt_form = $this->_generate_payment_method_settings_form($payment_method);
789
-                if ($pmt_form->form_data_present_in($this->_req_data)) {
790
-                    $correct_pmt_form_to_use = $pmt_form;
791
-                    break;
792
-                }
793
-            }
794
-            //if we couldn't find the correct payment method type...
795
-            if (! $correct_pmt_form_to_use) {
796
-                EE_Error::add_error(__("We could not find which payment method type your form submission related to. Please contact support",
797
-                    'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
798
-                $this->_redirect_after_action(false, 'Payment Method', 'activated', array('action' => 'default'));
799
-            }
800
-            $correct_pmt_form_to_use->receive_form_submission($this->_req_data);
801
-            if ($correct_pmt_form_to_use->is_valid()) {
802
-                $payment_settings_subform = $correct_pmt_form_to_use->get_subsection('payment_method_settings');
803
-                if (! $payment_settings_subform instanceof EE_Payment_Method_Form) {
804
-                    throw new EE_Error(
805
-                        sprintf(
806
-                            __('The payment method could not be saved because the form sections were misnamed. We expected to find %1$s, but did not.',
807
-                                'event_espresso'),
808
-                            'payment_method_settings'
809
-                        )
810
-                    );
811
-                }
812
-                $payment_settings_subform->save();
813
-                /** @var $pm EE_Payment_Method */
814
-                $this->_redirect_after_action(true, 'Payment Method', 'updated',
815
-                    array('action' => 'default', 'payment_method' => $payment_method->slug()));
816
-            } else {
817
-                EE_Error::add_error(
818
-                    sprintf(
819
-                        __('Payment method of type %s was not saved because there were validation errors. They have been marked in the form',
820
-                            'event_espresso'),
821
-                        $payment_method instanceof EE_PMT_Base ? $payment_method->pretty_name()
822
-                            : __('"(unknown)"', 'event_espresso')
823
-                    ),
824
-                    __FILE__,
825
-                    __FUNCTION__,
826
-                    __LINE__
827
-                );
828
-            }
829
-        }
830
-        return;
831
-    }
832
-
833
-
834
-
835
-    protected function _payment_settings()
836
-    {
837
-        $this->_template_args['values'] = $this->_yes_no_values;
838
-        $this->_template_args['show_pending_payment_options'] = isset(EE_Registry::instance()->CFG->registration->show_pending_payment_options)
839
-            ? absint(EE_Registry::instance()->CFG->registration->show_pending_payment_options) : false;
840
-        $this->_set_add_edit_form_tags('update_payment_settings');
841
-        $this->_set_publish_post_box_vars(null, false, false, null, false);
842
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(EE_PAYMENTS_TEMPLATE_PATH
843
-                                                                                     . 'payment_settings.template.php',
844
-            $this->_template_args, true);
845
-        $this->display_admin_page_with_sidebar();
846
-    }
847
-
848
-
849
-
850
-    /**
851
-     *        _update_payment_settings
852
-     *
853
-     * @access protected
854
-     * @return array
855
-     */
856
-    protected function _update_payment_settings()
857
-    {
858
-        EE_Registry::instance()->CFG->registration->show_pending_payment_options = isset($this->_req_data['show_pending_payment_options'])
859
-            ? $this->_req_data['show_pending_payment_options'] : false;
860
-        EE_Registry::instance()->CFG = apply_filters('FHEE__Payments_Admin_Page___update_payment_settings__CFG',
861
-            EE_Registry::instance()->CFG);
30
+	/**
31
+	 * Variables used for when we're re-sorting the logs results, in case
32
+	 * we needed to do two queries and we need to resort
33
+	 *
34
+	 * @var string
35
+	 */
36
+	private $_sort_logs_again_direction;
37
+
38
+
39
+
40
+	/**
41
+	 * @Constructor
42
+	 * @access public
43
+	 * @param bool $routing indicate whether we want to just load the object and handle routing or just load the object.
44
+	 * @return \Payments_Admin_Page
45
+	 */
46
+	public function __construct($routing = true)
47
+	{
48
+		parent::__construct($routing);
49
+	}
50
+
51
+
52
+
53
+	protected function _init_page_props()
54
+	{
55
+		$this->page_slug = EE_PAYMENTS_PG_SLUG;
56
+		$this->page_label = __('Payment Methods', 'event_espresso');
57
+		$this->_admin_base_url = EE_PAYMENTS_ADMIN_URL;
58
+		$this->_admin_base_path = EE_PAYMENTS_ADMIN;
59
+	}
60
+
61
+
62
+
63
+	protected function _ajax_hooks()
64
+	{
65
+		//todo: all hooks for ajax goes here.
66
+	}
67
+
68
+
69
+
70
+	protected function _define_page_props()
71
+	{
72
+		$this->_admin_page_title = $this->page_label;
73
+		$this->_labels = array(
74
+			'publishbox' => __('Update Settings', 'event_espresso'),
75
+		);
76
+	}
77
+
78
+
79
+
80
+	protected function _set_page_routes()
81
+	{
82
+		/**
83
+		 * note that with payment method capabilities, although we've implemented
84
+		 * capability mapping which will be used for accessing payment methods owned by
85
+		 * other users.  This is not fully implemented yet in the payment method ui.
86
+		 * Currently only the "plural" caps are in active use.
87
+		 * When cap mapping is implemented, some routes will need to use the singular form of
88
+		 * capability method and also include the $id of the payment method for the route.
89
+		 **/
90
+		$this->_page_routes = array(
91
+			'default'                   => array(
92
+				'func'       => '_payment_methods_list',
93
+				'capability' => 'ee_edit_payment_methods',
94
+			),
95
+			'payment_settings'          => array(
96
+				'func'       => '_payment_settings',
97
+				'capability' => 'ee_manage_gateways',
98
+			),
99
+			'activate_payment_method'   => array(
100
+				'func'       => '_activate_payment_method',
101
+				'noheader'   => true,
102
+				'capability' => 'ee_edit_payment_methods',
103
+			),
104
+			'deactivate_payment_method' => array(
105
+				'func'       => '_deactivate_payment_method',
106
+				'noheader'   => true,
107
+				'capability' => 'ee_delete_payment_methods',
108
+			),
109
+			'update_payment_method'     => array(
110
+				'func'               => '_update_payment_method',
111
+				'noheader'           => true,
112
+				'headers_sent_route' => 'default',
113
+				'capability'         => 'ee_edit_payment_methods',
114
+			),
115
+			'update_payment_settings'   => array(
116
+				'func'       => '_update_payment_settings',
117
+				'noheader'   => true,
118
+				'capability' => 'ee_manage_gateways',
119
+			),
120
+			'payment_log'               => array(
121
+				'func'       => '_payment_log_overview_list_table',
122
+				'capability' => 'ee_read_payment_methods',
123
+			),
124
+			'payment_log_details'       => array(
125
+				'func'       => '_payment_log_details',
126
+				'capability' => 'ee_read_payment_methods',
127
+			),
128
+		);
129
+	}
130
+
131
+
132
+
133
+	protected function _set_page_config()
134
+	{
135
+		$payment_method_list_config = array(
136
+			'nav'           => array(
137
+				'label' => __('Payment Methods', 'event_espresso'),
138
+				'order' => 10,
139
+			),
140
+			'metaboxes'     => $this->_default_espresso_metaboxes,
141
+			'help_tabs'     => array_merge(
142
+				array(
143
+					'payment_methods_overview_help_tab' => array(
144
+						'title'    => __('Payment Methods Overview', 'event_espresso'),
145
+						'filename' => 'payment_methods_overview',
146
+					),
147
+				),
148
+				$this->_add_payment_method_help_tabs()),
149
+			'help_tour'     => array('Payment_Methods_Selection_Help_Tour'),
150
+			'require_nonce' => false,
151
+		);
152
+		$this->_page_config = array(
153
+			'default'          => $payment_method_list_config,
154
+			'payment_settings' => array(
155
+				'nav'           => array(
156
+					'label' => __('Settings', 'event_espresso'),
157
+					'order' => 20,
158
+				),
159
+				'help_tabs'     => array(
160
+					'payment_methods_settings_help_tab' => array(
161
+						'title'    => __('Payment Method Settings', 'event_espresso'),
162
+						'filename' => 'payment_methods_settings',
163
+					),
164
+				),
165
+				//'help_tour' => array( 'Payment_Methods_Settings_Help_Tour' ),
166
+				'metaboxes'     => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')),
167
+				'require_nonce' => false,
168
+			),
169
+			'payment_log'      => array(
170
+				'nav'           => array(
171
+					'label' => __("Logs", 'event_espresso'),
172
+					'order' => 30,
173
+				),
174
+				'list_table'    => 'Payment_Log_Admin_List_Table',
175
+				'metaboxes'     => $this->_default_espresso_metaboxes,
176
+				'require_nonce' => false,
177
+			),
178
+		);
179
+	}
180
+
181
+
182
+
183
+	/**
184
+	 * @return array
185
+	 */
186
+	protected function _add_payment_method_help_tabs()
187
+	{
188
+		EE_Registry::instance()->load_lib('Payment_Method_Manager');
189
+		$payment_method_types = EE_Payment_Method_Manager::instance()->payment_method_types();
190
+		$all_pmt_help_tabs_config = array();
191
+		foreach ($payment_method_types as $payment_method_type) {
192
+			if (! EE_Registry::instance()->CAP->current_user_can($payment_method_type->cap_name(),
193
+				'specific_payment_method_type_access')
194
+			) {
195
+				continue;
196
+			}
197
+			foreach ($payment_method_type->help_tabs_config() as $help_tab_name => $config) {
198
+				$template_args = isset($config['template_args']) ? $config['template_args'] : array();
199
+				$template_args['admin_page_obj'] = $this;
200
+				$all_pmt_help_tabs_config[$help_tab_name] = array(
201
+					'title'   => $config['title'],
202
+					'content' => EEH_Template::display_template(
203
+						$payment_method_type->file_folder() . 'help_tabs' . DS . $config['filename'] . '.help_tab.php',
204
+						$template_args,
205
+						true),
206
+				);
207
+			}
208
+		}
209
+		return $all_pmt_help_tabs_config;
210
+	}
211
+
212
+
213
+
214
+	//none of the below group are currently used for Gateway Settings
215
+	protected function _add_screen_options()
216
+	{
217
+	}
218
+
219
+
220
+
221
+	protected function _add_feature_pointers()
222
+	{
223
+	}
224
+
225
+
226
+
227
+	public function admin_init()
228
+	{
229
+	}
230
+
231
+
232
+
233
+	public function admin_notices()
234
+	{
235
+	}
236
+
237
+
238
+
239
+	public function admin_footer_scripts()
240
+	{
241
+	}
242
+
243
+
244
+
245
+	public function load_scripts_styles()
246
+	{
247
+		wp_enqueue_script('ee_admin_js');
248
+		wp_enqueue_script('ee-text-links');
249
+		wp_enqueue_script('espresso_payments', EE_PAYMENTS_ASSETS_URL . 'espresso_payments_admin.js',
250
+			array('espresso-ui-theme', 'ee-datepicker'), EVENT_ESPRESSO_VERSION, true);
251
+	}
252
+
253
+
254
+
255
+	public function load_scripts_styles_default()
256
+	{
257
+		//styles
258
+		wp_register_style('espresso_payments', EE_PAYMENTS_ASSETS_URL . 'ee-payments.css', array(),
259
+			EVENT_ESPRESSO_VERSION);
260
+		wp_enqueue_style('espresso_payments');
261
+		wp_enqueue_style('ee-text-links');
262
+		//scripts
263
+	}
264
+
265
+
266
+
267
+	protected function _payment_methods_list()
268
+	{
269
+		/**
270
+		 * first let's ensure payment methods have been setup. We do this here because when people activate a
271
+		 * payment method for the first time (as an addon), it may not setup its capabilities or get registered correctly due
272
+		 * to the loading process.  However, people MUST setup the details for the payment method so its safe to do a
273
+		 * recheck here.
274
+		 */
275
+		EE_Registry::instance()->load_lib('Payment_Method_Manager');
276
+		EEM_Payment_Method::instance()->verify_button_urls();
277
+		//setup tabs, one for each payment method type
278
+		$tabs = array();
279
+		$payment_methods = array();
280
+		foreach (EE_Payment_Method_Manager::instance()->payment_method_types() as $pmt_obj) {
281
+			// we don't want to show admin-only PMTs for now
282
+			if ($pmt_obj instanceof EE_PMT_Admin_Only) {
283
+				continue;
284
+			}
285
+			//check access
286
+			if (! EE_Registry::instance()->CAP->current_user_can($pmt_obj->cap_name(),
287
+				'specific_payment_method_type_access')
288
+			) {
289
+				continue;
290
+			}
291
+			//check for any active pms of that type
292
+			$payment_method = EEM_Payment_Method::instance()->get_one_of_type($pmt_obj->system_name());
293
+			if (! $payment_method instanceof EE_Payment_Method) {
294
+				$payment_method = EE_Payment_Method::new_instance(
295
+					array(
296
+						'PMD_slug'       => sanitize_key($pmt_obj->system_name()),
297
+						'PMD_type'       => $pmt_obj->system_name(),
298
+						'PMD_name'       => $pmt_obj->pretty_name(),
299
+						'PMD_admin_name' => $pmt_obj->pretty_name(),
300
+					)
301
+				);
302
+			}
303
+			$payment_methods[$payment_method->slug()] = $payment_method;
304
+		}
305
+		$payment_methods = apply_filters('FHEE__Payments_Admin_Page___payment_methods_list__payment_methods',
306
+			$payment_methods);
307
+		foreach ($payment_methods as $payment_method) {
308
+			if ($payment_method instanceof EE_Payment_Method) {
309
+				add_meta_box(
310
+				//html id
311
+					'espresso_' . $payment_method->slug() . '_payment_settings',
312
+					//title
313
+					sprintf(__('%s Settings', 'event_espresso'), $payment_method->admin_name()),
314
+					//callback
315
+					array($this, 'payment_method_settings_meta_box'),
316
+					//post type
317
+					null,
318
+					//context
319
+					'normal',
320
+					//priority
321
+					'default',
322
+					//callback args
323
+					array('payment_method' => $payment_method)
324
+				);
325
+				//setup for tabbed content
326
+				$tabs[$payment_method->slug()] = array(
327
+					'label' => $payment_method->admin_name(),
328
+					'class' => $payment_method->active() ? 'gateway-active' : '',
329
+					'href'  => 'espresso_' . $payment_method->slug() . '_payment_settings',
330
+					'title' => __('Modify this Payment Method', 'event_espresso'),
331
+					'slug'  => $payment_method->slug(),
332
+				);
333
+			}
334
+		}
335
+		$this->_template_args['admin_page_header'] = EEH_Tabbed_Content::tab_text_links($tabs, 'payment_method_links',
336
+			'|', $this->_get_active_payment_method_slug());
337
+		$this->display_admin_page_with_sidebar();
338
+	}
339
+
340
+
341
+
342
+	/**
343
+	 *   _get_active_payment_method_slug
344
+	 *
345
+	 * @return string
346
+	 */
347
+	protected function _get_active_payment_method_slug()
348
+	{
349
+		$payment_method_slug = false;
350
+		//decide which payment method tab to open first, as dictated by the request's 'payment_method'
351
+		if (isset($this->_req_data['payment_method'])) {
352
+			// if they provided the current payment method, use it
353
+			$payment_method_slug = sanitize_key($this->_req_data['payment_method']);
354
+		}
355
+		$payment_method = EEM_Payment_Method::instance()->get_one(array(array('PMD_slug' => $payment_method_slug)));
356
+		// if that didn't work or wasn't provided, find another way to select the current pm
357
+		if (! $this->_verify_payment_method($payment_method)) {
358
+			// like, looking for an active one
359
+			$payment_method = EEM_Payment_Method::instance()->get_one_active('CART');
360
+			// test that one as well
361
+			if ($this->_verify_payment_method($payment_method)) {
362
+				$payment_method_slug = $payment_method->slug();
363
+			} else {
364
+				$payment_method_slug = 'paypal_standard';
365
+			}
366
+		}
367
+		return $payment_method_slug;
368
+	}
369
+
370
+
371
+
372
+	/**
373
+	 *    payment_method_settings_meta_box
374
+	 *    returns TRUE if the passed payment method is properly constructed and the logged in user has the correct
375
+	 *    capabilities to access it
376
+	 *
377
+	 * @param \EE_Payment_Method $payment_method
378
+	 * @return boolean
379
+	 */
380
+	protected function _verify_payment_method($payment_method)
381
+	{
382
+		if (
383
+			$payment_method instanceof EE_Payment_Method && $payment_method->type_obj() instanceof EE_PMT_Base
384
+			&& EE_Registry::instance()->CAP->current_user_can($payment_method->type_obj()->cap_name(),
385
+				'specific_payment_method_type_access')
386
+		) {
387
+			return true;
388
+		}
389
+		return false;
390
+	}
391
+
392
+
393
+
394
+	/**
395
+	 *    payment_method_settings_meta_box
396
+	 *
397
+	 * @param NULL  $post_obj_which_is_null is an object containing the current post (as a $post object)
398
+	 * @param array $metabox                is an array with metabox id, title, callback, and args elements. the value
399
+	 *                                      at 'args' has key 'payment_method', as set within _payment_methods_list
400
+	 * @return string
401
+	 * @throws EE_Error
402
+	 */
403
+	public function payment_method_settings_meta_box($post_obj_which_is_null, $metabox)
404
+	{
405
+		$payment_method = isset($metabox['args'], $metabox['args']['payment_method'])
406
+			? $metabox['args']['payment_method'] : null;
407
+		if (! $payment_method instanceof EE_Payment_Method) {
408
+			throw new EE_Error(sprintf(__('Payment method metabox setup incorrectly. No Payment method object was supplied',
409
+				'event_espresso')));
410
+		}
411
+		$payment_method_scopes = $payment_method->active();
412
+		// if the payment method really exists show its form, otherwise the activation template
413
+		if ($payment_method->ID() && ! empty($payment_method_scopes)) {
414
+			$form = $this->_generate_payment_method_settings_form($payment_method);
415
+			if ($form->form_data_present_in($this->_req_data)) {
416
+				$form->receive_form_submission($this->_req_data);
417
+			}
418
+			echo $form->form_open() . $form->get_html_and_js() . $form->form_close();
419
+		} else {
420
+			echo $this->_activate_payment_method_button($payment_method)->get_html_and_js();
421
+		}
422
+	}
423
+
424
+
425
+
426
+	/**
427
+	 * Gets the form for all the settings related to this payment method type
428
+	 *
429
+	 * @access protected
430
+	 * @param \EE_Payment_Method $payment_method
431
+	 * @return \EE_Form_Section_Proper
432
+	 */
433
+	protected function _generate_payment_method_settings_form(EE_Payment_Method $payment_method)
434
+	{
435
+		if (! $payment_method instanceof EE_Payment_Method) {
436
+			return new EE_Form_Section_Proper();
437
+		}
438
+		return new EE_Form_Section_Proper(
439
+			array(
440
+				'name'            => $payment_method->slug() . '_settings_form',
441
+				'html_id'         => $payment_method->slug() . '_settings_form',
442
+				'action'          => EE_Admin_Page::add_query_args_and_nonce(
443
+					array(
444
+						'action'         => 'update_payment_method',
445
+						'payment_method' => $payment_method->slug(),
446
+					),
447
+					EE_PAYMENTS_ADMIN_URL
448
+				),
449
+				'layout_strategy' => new EE_Admin_Two_Column_Layout(),
450
+				'subsections'     => apply_filters(
451
+					'FHEE__Payments_Admin_Page___generate_payment_method_settings_form__form_subsections',
452
+					array(
453
+						'pci_dss_compliance'      => $this->_pci_dss_compliance($payment_method),
454
+						'currency_support'        => $this->_currency_support($payment_method),
455
+						'payment_method_settings' => $this->_payment_method_settings($payment_method),
456
+						'update'                  => $this->_update_payment_method_button($payment_method),
457
+						'deactivate'              => $this->_deactivate_payment_method_button($payment_method),
458
+						'fine_print'              => $this->_fine_print(),
459
+					),
460
+					$payment_method
461
+				),
462
+			)
463
+		);
464
+	}
465
+
466
+
467
+
468
+	/**
469
+	 * _pci_dss_compliance
470
+	 *
471
+	 * @access protected
472
+	 * @param \EE_Payment_Method $payment_method
473
+	 * @return \EE_Form_Section_Proper
474
+	 */
475
+	protected function _pci_dss_compliance(EE_Payment_Method $payment_method)
476
+	{
477
+		if ($payment_method->type_obj()->requires_https()) {
478
+			return new EE_Form_Section_HTML(
479
+				EEH_HTML::tr(
480
+					EEH_HTML::th(
481
+						EEH_HTML::label(
482
+							EEH_HTML::strong(__('IMPORTANT', 'event_espresso'), '', 'important-notice')
483
+						)
484
+					) .
485
+					EEH_HTML::td(
486
+						EEH_HTML::strong(__('You are responsible for your own website security and Payment Card Industry Data Security Standards (PCI DSS) compliance.',
487
+							'event_espresso'))
488
+						.
489
+						EEH_HTML::br()
490
+						.
491
+						__('Learn more about ', 'event_espresso')
492
+						. EEH_HTML::link('https://www.pcisecuritystandards.org/merchants/index.php',
493
+							__('PCI DSS compliance', 'event_espresso'))
494
+					)
495
+				)
496
+			);
497
+		} else {
498
+			return new EE_Form_Section_HTML('');
499
+		}
500
+	}
501
+
502
+
503
+
504
+	/**
505
+	 * _currency_support
506
+	 *
507
+	 * @access protected
508
+	 * @param \EE_Payment_Method $payment_method
509
+	 * @return \EE_Form_Section_Proper
510
+	 */
511
+	protected function _currency_support(EE_Payment_Method $payment_method)
512
+	{
513
+		if (! $payment_method->usable_for_currency(EE_Config::instance()->currency->code)) {
514
+			return new EE_Form_Section_HTML(
515
+				EEH_HTML::tr(
516
+					EEH_HTML::th(
517
+						EEH_HTML::label(
518
+							EEH_HTML::strong(__('IMPORTANT', 'event_espresso'), '', 'important-notice')
519
+						)
520
+					) .
521
+					EEH_HTML::td(
522
+						EEH_HTML::strong(
523
+							sprintf(
524
+								__('This payment method does not support the currency set on your site (%1$s). Please activate a different payment method or change your site\'s country and associated currency.',
525
+									'event_espresso'),
526
+								EE_Config::instance()->currency->code
527
+							)
528
+						)
529
+					)
530
+				)
531
+			);
532
+		} else {
533
+			return new EE_Form_Section_HTML('');
534
+		}
535
+	}
536
+
537
+
538
+
539
+	/**
540
+	 * _update_payment_method_button
541
+	 *
542
+	 * @access protected
543
+	 * @param \EE_Payment_Method $payment_method
544
+	 * @return \EE_Form_Section_HTML
545
+	 */
546
+	protected function _payment_method_settings(EE_Payment_Method $payment_method)
547
+	{
548
+		//modify the form so we only have/show fields that will be implemented for this version
549
+		return $this->_simplify_form($payment_method->type_obj()->settings_form(), $payment_method->name());
550
+	}
551
+
552
+
553
+
554
+	/**
555
+	 * Simplifies the form to merely reproduce 4.1's gateway settings functionality
556
+	 *
557
+	 * @param EE_Form_Section_Proper $form_section
558
+	 * @param string                 $payment_method_name
559
+	 * @return \EE_Payment_Method_Form
560
+	 * @throws \EE_Error
561
+	 */
562
+	protected function _simplify_form($form_section, $payment_method_name = '')
563
+	{
564
+		if ($form_section instanceof EE_Payment_Method_Form) {
565
+			$form_section->exclude(
566
+				array(
567
+					'PMD_type', //dont want them changing the type
568
+					'PMD_slug', //or the slug (probably never)
569
+					'PMD_wp_user', //or the user's ID
570
+					'Currency' //or the currency, until the rest of EE supports simultaneous currencies
571
+				)
572
+			);
573
+			return $form_section;
574
+		} else {
575
+			throw new EE_Error(sprintf(__('The EE_Payment_Method_Form for the "%1$s" payment method is missing or invalid.',
576
+				'event_espresso'), $payment_method_name));
577
+		}
578
+	}
579
+
580
+
581
+
582
+	/**
583
+	 * _update_payment_method_button
584
+	 *
585
+	 * @access protected
586
+	 * @param \EE_Payment_Method $payment_method
587
+	 * @return \EE_Form_Section_HTML
588
+	 */
589
+	protected function _update_payment_method_button(EE_Payment_Method $payment_method)
590
+	{
591
+		$update_button = new EE_Submit_Input(
592
+			array(
593
+				'name'       => 'submit',
594
+				'html_id'    => 'save_' . $payment_method->slug() . '_settings',
595
+				'default'    => sprintf(__('Update %s Payment Settings', 'event_espresso'),
596
+					$payment_method->admin_name()),
597
+				'html_label' => EEH_HTML::nbsp(),
598
+			)
599
+		);
600
+		return new EE_Form_Section_HTML(
601
+			EEH_HTML::no_row(EEH_HTML::br(2)) .
602
+			EEH_HTML::tr(
603
+				EEH_HTML::th(__('Update Settings', 'event_espresso')) .
604
+				EEH_HTML::td(
605
+					$update_button->get_html_for_input()
606
+				)
607
+			)
608
+		);
609
+	}
610
+
611
+
612
+
613
+	/**
614
+	 * _deactivate_payment_method_button
615
+	 *
616
+	 * @access protected
617
+	 * @param \EE_Payment_Method $payment_method
618
+	 * @return \EE_Form_Section_Proper
619
+	 */
620
+	protected function _deactivate_payment_method_button(EE_Payment_Method $payment_method)
621
+	{
622
+		$link_text_and_title = sprintf(__('Deactivate %1$s Payments?', 'event_espresso'),
623
+			$payment_method->admin_name());
624
+		return new EE_Form_Section_HTML(
625
+			EEH_HTML::tr(
626
+				EEH_HTML::th(__('Deactivate Payment Method', 'event_espresso')) .
627
+				EEH_HTML::td(
628
+					EEH_HTML::link(
629
+						EE_Admin_Page::add_query_args_and_nonce(
630
+							array(
631
+								'action'         => 'deactivate_payment_method',
632
+								'payment_method' => $payment_method->slug(),
633
+							),
634
+							EE_PAYMENTS_ADMIN_URL
635
+						),
636
+						$link_text_and_title,
637
+						$link_text_and_title,
638
+						'deactivate_' . $payment_method->slug(),
639
+						'espresso-button button-secondary'
640
+					)
641
+				)
642
+			)
643
+		);
644
+	}
645
+
646
+
647
+
648
+	/**
649
+	 * _activate_payment_method_button
650
+	 *
651
+	 * @access protected
652
+	 * @param \EE_Payment_Method $payment_method
653
+	 * @return \EE_Form_Section_Proper
654
+	 */
655
+	protected function _activate_payment_method_button(EE_Payment_Method $payment_method)
656
+	{
657
+		$link_text_and_title = sprintf(__('Activate %1$s Payment Method?', 'event_espresso'),
658
+			$payment_method->admin_name());
659
+		return new EE_Form_Section_Proper(
660
+			array(
661
+				'name'            => 'activate_' . $payment_method->slug() . '_settings_form',
662
+				'html_id'         => 'activate_' . $payment_method->slug() . '_settings_form',
663
+				'action'          => '#',
664
+				'layout_strategy' => new EE_Admin_Two_Column_Layout(),
665
+				'subsections'     => apply_filters(
666
+					'FHEE__Payments_Admin_Page___activate_payment_method_button__form_subsections',
667
+					array(
668
+						new EE_Form_Section_HTML(
669
+							EEH_HTML::tr(
670
+								EEH_HTML::td($payment_method->type_obj()->introductory_html(),
671
+									'',
672
+									'',
673
+									'',
674
+									'colspan="2"'
675
+								)
676
+							) .
677
+							EEH_HTML::tr(
678
+								EEH_HTML::th(
679
+									EEH_HTML::label(__('Click to Activate ', 'event_espresso'))
680
+								) .
681
+								EEH_HTML::td(
682
+									EEH_HTML::link(
683
+										EE_Admin_Page::add_query_args_and_nonce(
684
+											array(
685
+												'action'              => 'activate_payment_method',
686
+												'payment_method_type' => $payment_method->type(),
687
+											),
688
+											EE_PAYMENTS_ADMIN_URL
689
+										),
690
+										$link_text_and_title,
691
+										$link_text_and_title,
692
+										'activate_' . $payment_method->slug(),
693
+										'espresso-button-green button-primary'
694
+									)
695
+								)
696
+							)
697
+						),
698
+					),
699
+					$payment_method
700
+				),
701
+			)
702
+		);
703
+	}
704
+
705
+
706
+
707
+	/**
708
+	 * _fine_print
709
+	 *
710
+	 * @access protected
711
+	 * @return \EE_Form_Section_HTML
712
+	 */
713
+	protected function _fine_print()
714
+	{
715
+		return new EE_Form_Section_HTML(
716
+			EEH_HTML::tr(
717
+				EEH_HTML::th() .
718
+				EEH_HTML::td(
719
+					EEH_HTML::p(__('All fields marked with a * are required fields', 'event_espresso'), '', 'grey-text')
720
+				)
721
+			)
722
+		);
723
+	}
724
+
725
+
726
+
727
+	/**
728
+	 * Activates a payment method of that type. Mostly assuming there is only 1 of that type (or none so far)
729
+	 *
730
+	 * @global WP_User $current_user
731
+	 */
732
+	protected function _activate_payment_method()
733
+	{
734
+		if (isset($this->_req_data['payment_method_type'])) {
735
+			$payment_method_type = sanitize_text_field($this->_req_data['payment_method_type']);
736
+			//see if one exists
737
+			EE_Registry::instance()->load_lib('Payment_Method_Manager');
738
+			$payment_method = EE_Payment_Method_Manager::instance()
739
+													   ->activate_a_payment_method_of_type($payment_method_type);
740
+			$this->_redirect_after_action(1, 'Payment Method', 'activated',
741
+				array('action' => 'default', 'payment_method' => $payment_method->slug()));
742
+		} else {
743
+			$this->_redirect_after_action(false, 'Payment Method', 'activated', array('action' => 'default'));
744
+		}
745
+	}
746
+
747
+
748
+
749
+	/**
750
+	 * Deactivates the payment method with the specified slug, and redirects.
751
+	 */
752
+	protected function _deactivate_payment_method()
753
+	{
754
+		if (isset($this->_req_data['payment_method'])) {
755
+			$payment_method_slug = sanitize_key($this->_req_data['payment_method']);
756
+			//deactivate it
757
+			EE_Registry::instance()->load_lib('Payment_Method_Manager');
758
+			$count_updated = EE_Payment_Method_Manager::instance()->deactivate_payment_method($payment_method_slug);
759
+			$this->_redirect_after_action($count_updated, 'Payment Method', 'deactivated',
760
+				array('action' => 'default', 'payment_method' => $payment_method_slug));
761
+		} else {
762
+			$this->_redirect_after_action(false, 'Payment Method', 'deactivated', array('action' => 'default'));
763
+		}
764
+	}
765
+
766
+
767
+
768
+	/**
769
+	 * Processes the payment method form that was submitted. This is slightly trickier than usual form
770
+	 * processing because we first need to identify WHICH form was processed and which payment method
771
+	 * it corresponds to. Once we have done that, we see if the form is valid. If it is, the
772
+	 * form's data is saved and we redirect to the default payment methods page, setting the updated payment method
773
+	 * as the currently-selected one. If it DOESN'T validate, we render the page with the form's errors (in the
774
+	 * subsequently called 'headers_sent_func' which is _payment_methods_list)
775
+	 *
776
+	 * @return void
777
+	 */
778
+	protected function _update_payment_method()
779
+	{
780
+		if ($_SERVER['REQUEST_METHOD'] == 'POST') {
781
+			//ok let's find which gateway form to use based on the form input
782
+			EE_Registry::instance()->load_lib('Payment_Method_Manager');
783
+			/** @var $correct_pmt_form_to_use EE_Payment_Method_Form */
784
+			$correct_pmt_form_to_use = null;
785
+			$payment_method = null;
786
+			foreach (EEM_Payment_Method::instance()->get_all() as $payment_method) {
787
+				//get the form and simplify it, like what we do when we display it
788
+				$pmt_form = $this->_generate_payment_method_settings_form($payment_method);
789
+				if ($pmt_form->form_data_present_in($this->_req_data)) {
790
+					$correct_pmt_form_to_use = $pmt_form;
791
+					break;
792
+				}
793
+			}
794
+			//if we couldn't find the correct payment method type...
795
+			if (! $correct_pmt_form_to_use) {
796
+				EE_Error::add_error(__("We could not find which payment method type your form submission related to. Please contact support",
797
+					'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
798
+				$this->_redirect_after_action(false, 'Payment Method', 'activated', array('action' => 'default'));
799
+			}
800
+			$correct_pmt_form_to_use->receive_form_submission($this->_req_data);
801
+			if ($correct_pmt_form_to_use->is_valid()) {
802
+				$payment_settings_subform = $correct_pmt_form_to_use->get_subsection('payment_method_settings');
803
+				if (! $payment_settings_subform instanceof EE_Payment_Method_Form) {
804
+					throw new EE_Error(
805
+						sprintf(
806
+							__('The payment method could not be saved because the form sections were misnamed. We expected to find %1$s, but did not.',
807
+								'event_espresso'),
808
+							'payment_method_settings'
809
+						)
810
+					);
811
+				}
812
+				$payment_settings_subform->save();
813
+				/** @var $pm EE_Payment_Method */
814
+				$this->_redirect_after_action(true, 'Payment Method', 'updated',
815
+					array('action' => 'default', 'payment_method' => $payment_method->slug()));
816
+			} else {
817
+				EE_Error::add_error(
818
+					sprintf(
819
+						__('Payment method of type %s was not saved because there were validation errors. They have been marked in the form',
820
+							'event_espresso'),
821
+						$payment_method instanceof EE_PMT_Base ? $payment_method->pretty_name()
822
+							: __('"(unknown)"', 'event_espresso')
823
+					),
824
+					__FILE__,
825
+					__FUNCTION__,
826
+					__LINE__
827
+				);
828
+			}
829
+		}
830
+		return;
831
+	}
832
+
833
+
834
+
835
+	protected function _payment_settings()
836
+	{
837
+		$this->_template_args['values'] = $this->_yes_no_values;
838
+		$this->_template_args['show_pending_payment_options'] = isset(EE_Registry::instance()->CFG->registration->show_pending_payment_options)
839
+			? absint(EE_Registry::instance()->CFG->registration->show_pending_payment_options) : false;
840
+		$this->_set_add_edit_form_tags('update_payment_settings');
841
+		$this->_set_publish_post_box_vars(null, false, false, null, false);
842
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(EE_PAYMENTS_TEMPLATE_PATH
843
+																					 . 'payment_settings.template.php',
844
+			$this->_template_args, true);
845
+		$this->display_admin_page_with_sidebar();
846
+	}
847
+
848
+
849
+
850
+	/**
851
+	 *        _update_payment_settings
852
+	 *
853
+	 * @access protected
854
+	 * @return array
855
+	 */
856
+	protected function _update_payment_settings()
857
+	{
858
+		EE_Registry::instance()->CFG->registration->show_pending_payment_options = isset($this->_req_data['show_pending_payment_options'])
859
+			? $this->_req_data['show_pending_payment_options'] : false;
860
+		EE_Registry::instance()->CFG = apply_filters('FHEE__Payments_Admin_Page___update_payment_settings__CFG',
861
+			EE_Registry::instance()->CFG);
862 862
 //		 $superform = new EE_Form_Section_Proper(
863 863
 //		 	array(
864 864
 //		 		'subsections' => array(
@@ -876,176 +876,176 @@  discard block
 block discarded – undo
876 876
 //		 	);
877 877
 //		 	$this->_redirect_after_action( 0, 'settings', 'updated', array( 'action' => 'payment_settings' ) );
878 878
 //		 }
879
-        $what = __('Payment Settings', 'event_espresso');
880
-        $success = $this->_update_espresso_configuration($what, EE_Registry::instance()->CFG, __FILE__, __FUNCTION__,
881
-            __LINE__);
882
-        $this->_redirect_after_action($success, $what, __('updated', 'event_espresso'),
883
-            array('action' => 'payment_settings'));
884
-    }
879
+		$what = __('Payment Settings', 'event_espresso');
880
+		$success = $this->_update_espresso_configuration($what, EE_Registry::instance()->CFG, __FILE__, __FUNCTION__,
881
+			__LINE__);
882
+		$this->_redirect_after_action($success, $what, __('updated', 'event_espresso'),
883
+			array('action' => 'payment_settings'));
884
+	}
885 885
 
886 886
 
887 887
 
888
-    protected function _payment_log_overview_list_table()
889
-    {
888
+	protected function _payment_log_overview_list_table()
889
+	{
890 890
 //		$this->_search_btn_label = __('Payment Log', 'event_espresso');
891
-        $this->display_admin_list_table_page_with_sidebar();
892
-    }
893
-
894
-
895
-
896
-    protected function _set_list_table_views_payment_log()
897
-    {
898
-        $this->_views = array(
899
-            'all' => array(
900
-                'slug'  => 'all',
901
-                'label' => __('View All Logs', 'event_espresso'),
902
-                'count' => 0,
903
-            ),
904
-        );
905
-    }
906
-
907
-
908
-
909
-    /**
910
-     * @param int  $per_page
911
-     * @param int  $current_page
912
-     * @param bool $count
913
-     * @return array
914
-     */
915
-    public function get_payment_logs($per_page = 50, $current_page = 0, $count = false)
916
-    {
917
-        EE_Registry::instance()->load_model('Change_Log');
918
-        //we may need to do multiple queries (joining differently), so we actually wan tan array of query params
919
-        $query_params = array(array('LOG_type' => EEM_Change_Log::type_gateway));
920
-        //check if they've selected a specific payment method
921
-        if (isset($this->_req_data['_payment_method']) && $this->_req_data['_payment_method'] !== 'all') {
922
-            $query_params[0]['OR*pm_or_pay_pm'] = array(
923
-                'Payment.Payment_Method.PMD_ID' => $this->_req_data['_payment_method'],
924
-                'Payment_Method.PMD_ID'         => $this->_req_data['_payment_method'],
925
-            );
926
-        }
927
-        //take into account search
928
-        if (isset($this->_req_data['s']) && $this->_req_data['s']) {
929
-            $similarity_string = array('LIKE', '%' . str_replace("", "%", $this->_req_data['s']) . '%');
930
-            $query_params[0]['OR*s']['Payment.Transaction.Registration.Attendee.ATT_fname'] = $similarity_string;
931
-            $query_params[0]['OR*s']['Payment.Transaction.Registration.Attendee.ATT_lname'] = $similarity_string;
932
-            $query_params[0]['OR*s']['Payment.Transaction.Registration.Attendee.ATT_email'] = $similarity_string;
933
-            $query_params[0]['OR*s']['Payment.Payment_Method.PMD_name'] = $similarity_string;
934
-            $query_params[0]['OR*s']['Payment.Payment_Method.PMD_admin_name'] = $similarity_string;
935
-            $query_params[0]['OR*s']['Payment.Payment_Method.PMD_type'] = $similarity_string;
936
-            $query_params[0]['OR*s']['LOG_message'] = $similarity_string;
937
-            $query_params[0]['OR*s']['Payment_Method.PMD_name'] = $similarity_string;
938
-            $query_params[0]['OR*s']['Payment_Method.PMD_admin_name'] = $similarity_string;
939
-            $query_params[0]['OR*s']['Payment_Method.PMD_type'] = $similarity_string;
940
-            $query_params[0]['OR*s']['LOG_message'] = $similarity_string;
941
-        }
942
-        if (isset($this->_req_data['payment-filter-start-date'])
943
-            && isset($this->_req_data['payment-filter-end-date'])
944
-        ) {
945
-            //add date
946
-            $start_date = wp_strip_all_tags($this->_req_data['payment-filter-start-date']);
947
-            $end_date = wp_strip_all_tags($this->_req_data['payment-filter-end-date']);
948
-            //make sure our timestamps start and end right at the boundaries for each day
949
-            $start_date = date('Y-m-d', strtotime($start_date)) . ' 00:00:00';
950
-            $end_date = date('Y-m-d', strtotime($end_date)) . ' 23:59:59';
951
-            //convert to timestamps
952
-            $start_date = strtotime($start_date);
953
-            $end_date = strtotime($end_date);
954
-            //makes sure start date is the lowest value and vice versa
955
-            $start_date = min($start_date, $end_date);
956
-            $end_date = max($start_date, $end_date);
957
-            //convert for query
958
-            $start_date = EEM_Change_Log::instance()
959
-                                        ->convert_datetime_for_query('LOG_time', date('Y-m-d H:i:s', $start_date),
960
-                                            'Y-m-d H:i:s');
961
-            $end_date = EEM_Change_Log::instance()
962
-                                      ->convert_datetime_for_query('LOG_time', date('Y-m-d H:i:s', $end_date),
963
-                                          'Y-m-d H:i:s');
964
-            $query_params[0]['LOG_time'] = array('BETWEEN', array($start_date, $end_date));
965
-        }
966
-        if ($count) {
967
-            return EEM_Change_Log::instance()->count($query_params);
968
-        }
969
-        if (isset($this->_req_data['order'])) {
970
-            $sort = (isset($this->_req_data['order']) && ! empty($this->_req_data['order'])) ? $this->_req_data['order']
971
-                : 'DESC';
972
-            $query_params['order_by'] = array('LOG_time' => $sort);
973
-        } else {
974
-            $query_params['order_by'] = array('LOG_time' => 'DESC');
975
-        }
976
-        $offset = ($current_page - 1) * $per_page;
977
-        if (! isset($this->_req_data['download_results'])) {
978
-            $query_params['limit'] = array($offset, $per_page);
979
-        }
980
-        //now they've requested to instead just download the file instead of viewing it.
981
-        if (isset($this->_req_data['download_results'])) {
982
-            $wpdb_results = EEM_Change_Log::instance()->get_all_efficiently($query_params);
983
-            header('Content-Disposition: attachment');
984
-            header("Content-Disposition: attachment; filename=ee_payment_logs_for_" . sanitize_key(site_url()));
985
-            echo "<h1>Payment Logs for " . site_url() . "</h1>";
986
-            echo "<h3>Query:</h3>";
987
-            var_dump($query_params);
988
-            echo "<h3>Results:</h3>";
989
-            var_dump($wpdb_results);
990
-            die;
991
-        }
992
-        $results = EEM_Change_Log::instance()->get_all($query_params);
993
-        return $results;
994
-    }
995
-
996
-
997
-
998
-    /**
999
-     * Used by usort to RE-sort log query results, because we lose the ordering
1000
-     * because we're possibly combining the results from two queries
1001
-     *
1002
-     * @param EE_Change_Log $logA
1003
-     * @param EE_Change_Log $logB
1004
-     * @return int
1005
-     */
1006
-    protected function _sort_logs_again($logA, $logB)
1007
-    {
1008
-        $timeA = $logA->get_raw('LOG_time');
1009
-        $timeB = $logB->get_raw('LOG_time');
1010
-        if ($timeA == $timeB) {
1011
-            return 0;
1012
-        }
1013
-        $comparison = $timeA < $timeB ? -1 : 1;
1014
-        if (strtoupper($this->_sort_logs_again_direction) == 'DESC') {
1015
-            return $comparison * -1;
1016
-        } else {
1017
-            return $comparison;
1018
-        }
1019
-    }
1020
-
1021
-
1022
-
1023
-    protected function _payment_log_details()
1024
-    {
1025
-        EE_Registry::instance()->load_model('Change_Log');
1026
-        /** @var $payment_log EE_Change_Log */
1027
-        $payment_log = EEM_Change_Log::instance()->get_one_by_ID($this->_req_data['ID']);
1028
-        $payment_method = null;
1029
-        $transaction = null;
1030
-        if ($payment_log instanceof EE_Change_Log) {
1031
-            if ($payment_log->object() instanceof EE_Payment) {
1032
-                $payment_method = $payment_log->object()->payment_method();
1033
-                $transaction = $payment_log->object()->transaction();
1034
-            } elseif ($payment_log->object() instanceof EE_Payment_Method) {
1035
-                $payment_method = $payment_log->object();
1036
-            }
1037
-        }
1038
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
1039
-            EE_PAYMENTS_TEMPLATE_PATH . 'payment_log_details.template.php',
1040
-            array(
1041
-                'payment_log'    => $payment_log,
1042
-                'payment_method' => $payment_method,
1043
-                'transaction'    => $transaction,
1044
-            ),
1045
-            true
1046
-        );
1047
-        $this->display_admin_page_with_sidebar();
1048
-    }
891
+		$this->display_admin_list_table_page_with_sidebar();
892
+	}
893
+
894
+
895
+
896
+	protected function _set_list_table_views_payment_log()
897
+	{
898
+		$this->_views = array(
899
+			'all' => array(
900
+				'slug'  => 'all',
901
+				'label' => __('View All Logs', 'event_espresso'),
902
+				'count' => 0,
903
+			),
904
+		);
905
+	}
906
+
907
+
908
+
909
+	/**
910
+	 * @param int  $per_page
911
+	 * @param int  $current_page
912
+	 * @param bool $count
913
+	 * @return array
914
+	 */
915
+	public function get_payment_logs($per_page = 50, $current_page = 0, $count = false)
916
+	{
917
+		EE_Registry::instance()->load_model('Change_Log');
918
+		//we may need to do multiple queries (joining differently), so we actually wan tan array of query params
919
+		$query_params = array(array('LOG_type' => EEM_Change_Log::type_gateway));
920
+		//check if they've selected a specific payment method
921
+		if (isset($this->_req_data['_payment_method']) && $this->_req_data['_payment_method'] !== 'all') {
922
+			$query_params[0]['OR*pm_or_pay_pm'] = array(
923
+				'Payment.Payment_Method.PMD_ID' => $this->_req_data['_payment_method'],
924
+				'Payment_Method.PMD_ID'         => $this->_req_data['_payment_method'],
925
+			);
926
+		}
927
+		//take into account search
928
+		if (isset($this->_req_data['s']) && $this->_req_data['s']) {
929
+			$similarity_string = array('LIKE', '%' . str_replace("", "%", $this->_req_data['s']) . '%');
930
+			$query_params[0]['OR*s']['Payment.Transaction.Registration.Attendee.ATT_fname'] = $similarity_string;
931
+			$query_params[0]['OR*s']['Payment.Transaction.Registration.Attendee.ATT_lname'] = $similarity_string;
932
+			$query_params[0]['OR*s']['Payment.Transaction.Registration.Attendee.ATT_email'] = $similarity_string;
933
+			$query_params[0]['OR*s']['Payment.Payment_Method.PMD_name'] = $similarity_string;
934
+			$query_params[0]['OR*s']['Payment.Payment_Method.PMD_admin_name'] = $similarity_string;
935
+			$query_params[0]['OR*s']['Payment.Payment_Method.PMD_type'] = $similarity_string;
936
+			$query_params[0]['OR*s']['LOG_message'] = $similarity_string;
937
+			$query_params[0]['OR*s']['Payment_Method.PMD_name'] = $similarity_string;
938
+			$query_params[0]['OR*s']['Payment_Method.PMD_admin_name'] = $similarity_string;
939
+			$query_params[0]['OR*s']['Payment_Method.PMD_type'] = $similarity_string;
940
+			$query_params[0]['OR*s']['LOG_message'] = $similarity_string;
941
+		}
942
+		if (isset($this->_req_data['payment-filter-start-date'])
943
+			&& isset($this->_req_data['payment-filter-end-date'])
944
+		) {
945
+			//add date
946
+			$start_date = wp_strip_all_tags($this->_req_data['payment-filter-start-date']);
947
+			$end_date = wp_strip_all_tags($this->_req_data['payment-filter-end-date']);
948
+			//make sure our timestamps start and end right at the boundaries for each day
949
+			$start_date = date('Y-m-d', strtotime($start_date)) . ' 00:00:00';
950
+			$end_date = date('Y-m-d', strtotime($end_date)) . ' 23:59:59';
951
+			//convert to timestamps
952
+			$start_date = strtotime($start_date);
953
+			$end_date = strtotime($end_date);
954
+			//makes sure start date is the lowest value and vice versa
955
+			$start_date = min($start_date, $end_date);
956
+			$end_date = max($start_date, $end_date);
957
+			//convert for query
958
+			$start_date = EEM_Change_Log::instance()
959
+										->convert_datetime_for_query('LOG_time', date('Y-m-d H:i:s', $start_date),
960
+											'Y-m-d H:i:s');
961
+			$end_date = EEM_Change_Log::instance()
962
+									  ->convert_datetime_for_query('LOG_time', date('Y-m-d H:i:s', $end_date),
963
+										  'Y-m-d H:i:s');
964
+			$query_params[0]['LOG_time'] = array('BETWEEN', array($start_date, $end_date));
965
+		}
966
+		if ($count) {
967
+			return EEM_Change_Log::instance()->count($query_params);
968
+		}
969
+		if (isset($this->_req_data['order'])) {
970
+			$sort = (isset($this->_req_data['order']) && ! empty($this->_req_data['order'])) ? $this->_req_data['order']
971
+				: 'DESC';
972
+			$query_params['order_by'] = array('LOG_time' => $sort);
973
+		} else {
974
+			$query_params['order_by'] = array('LOG_time' => 'DESC');
975
+		}
976
+		$offset = ($current_page - 1) * $per_page;
977
+		if (! isset($this->_req_data['download_results'])) {
978
+			$query_params['limit'] = array($offset, $per_page);
979
+		}
980
+		//now they've requested to instead just download the file instead of viewing it.
981
+		if (isset($this->_req_data['download_results'])) {
982
+			$wpdb_results = EEM_Change_Log::instance()->get_all_efficiently($query_params);
983
+			header('Content-Disposition: attachment');
984
+			header("Content-Disposition: attachment; filename=ee_payment_logs_for_" . sanitize_key(site_url()));
985
+			echo "<h1>Payment Logs for " . site_url() . "</h1>";
986
+			echo "<h3>Query:</h3>";
987
+			var_dump($query_params);
988
+			echo "<h3>Results:</h3>";
989
+			var_dump($wpdb_results);
990
+			die;
991
+		}
992
+		$results = EEM_Change_Log::instance()->get_all($query_params);
993
+		return $results;
994
+	}
995
+
996
+
997
+
998
+	/**
999
+	 * Used by usort to RE-sort log query results, because we lose the ordering
1000
+	 * because we're possibly combining the results from two queries
1001
+	 *
1002
+	 * @param EE_Change_Log $logA
1003
+	 * @param EE_Change_Log $logB
1004
+	 * @return int
1005
+	 */
1006
+	protected function _sort_logs_again($logA, $logB)
1007
+	{
1008
+		$timeA = $logA->get_raw('LOG_time');
1009
+		$timeB = $logB->get_raw('LOG_time');
1010
+		if ($timeA == $timeB) {
1011
+			return 0;
1012
+		}
1013
+		$comparison = $timeA < $timeB ? -1 : 1;
1014
+		if (strtoupper($this->_sort_logs_again_direction) == 'DESC') {
1015
+			return $comparison * -1;
1016
+		} else {
1017
+			return $comparison;
1018
+		}
1019
+	}
1020
+
1021
+
1022
+
1023
+	protected function _payment_log_details()
1024
+	{
1025
+		EE_Registry::instance()->load_model('Change_Log');
1026
+		/** @var $payment_log EE_Change_Log */
1027
+		$payment_log = EEM_Change_Log::instance()->get_one_by_ID($this->_req_data['ID']);
1028
+		$payment_method = null;
1029
+		$transaction = null;
1030
+		if ($payment_log instanceof EE_Change_Log) {
1031
+			if ($payment_log->object() instanceof EE_Payment) {
1032
+				$payment_method = $payment_log->object()->payment_method();
1033
+				$transaction = $payment_log->object()->transaction();
1034
+			} elseif ($payment_log->object() instanceof EE_Payment_Method) {
1035
+				$payment_method = $payment_log->object();
1036
+			}
1037
+		}
1038
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
1039
+			EE_PAYMENTS_TEMPLATE_PATH . 'payment_log_details.template.php',
1040
+			array(
1041
+				'payment_log'    => $payment_log,
1042
+				'payment_method' => $payment_method,
1043
+				'transaction'    => $transaction,
1044
+			),
1045
+			true
1046
+		);
1047
+		$this->display_admin_page_with_sidebar();
1048
+	}
1049 1049
 
1050 1050
 
1051 1051
 } //end Payments_Admin_Page class
Please login to merge, or discard this patch.
Spacing   +38 added lines, -38 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if (! defined('EVENT_ESPRESSO_VERSION')) {
2
+if ( ! defined('EVENT_ESPRESSO_VERSION')) {
3 3
     exit('NO direct script access allowed');
4 4
 }
5 5
 
@@ -189,7 +189,7 @@  discard block
 block discarded – undo
189 189
         $payment_method_types = EE_Payment_Method_Manager::instance()->payment_method_types();
190 190
         $all_pmt_help_tabs_config = array();
191 191
         foreach ($payment_method_types as $payment_method_type) {
192
-            if (! EE_Registry::instance()->CAP->current_user_can($payment_method_type->cap_name(),
192
+            if ( ! EE_Registry::instance()->CAP->current_user_can($payment_method_type->cap_name(),
193 193
                 'specific_payment_method_type_access')
194 194
             ) {
195 195
                 continue;
@@ -200,7 +200,7 @@  discard block
 block discarded – undo
200 200
                 $all_pmt_help_tabs_config[$help_tab_name] = array(
201 201
                     'title'   => $config['title'],
202 202
                     'content' => EEH_Template::display_template(
203
-                        $payment_method_type->file_folder() . 'help_tabs' . DS . $config['filename'] . '.help_tab.php',
203
+                        $payment_method_type->file_folder().'help_tabs'.DS.$config['filename'].'.help_tab.php',
204 204
                         $template_args,
205 205
                         true),
206 206
                 );
@@ -246,7 +246,7 @@  discard block
 block discarded – undo
246 246
     {
247 247
         wp_enqueue_script('ee_admin_js');
248 248
         wp_enqueue_script('ee-text-links');
249
-        wp_enqueue_script('espresso_payments', EE_PAYMENTS_ASSETS_URL . 'espresso_payments_admin.js',
249
+        wp_enqueue_script('espresso_payments', EE_PAYMENTS_ASSETS_URL.'espresso_payments_admin.js',
250 250
             array('espresso-ui-theme', 'ee-datepicker'), EVENT_ESPRESSO_VERSION, true);
251 251
     }
252 252
 
@@ -255,7 +255,7 @@  discard block
 block discarded – undo
255 255
     public function load_scripts_styles_default()
256 256
     {
257 257
         //styles
258
-        wp_register_style('espresso_payments', EE_PAYMENTS_ASSETS_URL . 'ee-payments.css', array(),
258
+        wp_register_style('espresso_payments', EE_PAYMENTS_ASSETS_URL.'ee-payments.css', array(),
259 259
             EVENT_ESPRESSO_VERSION);
260 260
         wp_enqueue_style('espresso_payments');
261 261
         wp_enqueue_style('ee-text-links');
@@ -283,14 +283,14 @@  discard block
 block discarded – undo
283 283
                 continue;
284 284
             }
285 285
             //check access
286
-            if (! EE_Registry::instance()->CAP->current_user_can($pmt_obj->cap_name(),
286
+            if ( ! EE_Registry::instance()->CAP->current_user_can($pmt_obj->cap_name(),
287 287
                 'specific_payment_method_type_access')
288 288
             ) {
289 289
                 continue;
290 290
             }
291 291
             //check for any active pms of that type
292 292
             $payment_method = EEM_Payment_Method::instance()->get_one_of_type($pmt_obj->system_name());
293
-            if (! $payment_method instanceof EE_Payment_Method) {
293
+            if ( ! $payment_method instanceof EE_Payment_Method) {
294 294
                 $payment_method = EE_Payment_Method::new_instance(
295 295
                     array(
296 296
                         'PMD_slug'       => sanitize_key($pmt_obj->system_name()),
@@ -308,7 +308,7 @@  discard block
 block discarded – undo
308 308
             if ($payment_method instanceof EE_Payment_Method) {
309 309
                 add_meta_box(
310 310
                 //html id
311
-                    'espresso_' . $payment_method->slug() . '_payment_settings',
311
+                    'espresso_'.$payment_method->slug().'_payment_settings',
312 312
                     //title
313 313
                     sprintf(__('%s Settings', 'event_espresso'), $payment_method->admin_name()),
314 314
                     //callback
@@ -326,7 +326,7 @@  discard block
 block discarded – undo
326 326
                 $tabs[$payment_method->slug()] = array(
327 327
                     'label' => $payment_method->admin_name(),
328 328
                     'class' => $payment_method->active() ? 'gateway-active' : '',
329
-                    'href'  => 'espresso_' . $payment_method->slug() . '_payment_settings',
329
+                    'href'  => 'espresso_'.$payment_method->slug().'_payment_settings',
330 330
                     'title' => __('Modify this Payment Method', 'event_espresso'),
331 331
                     'slug'  => $payment_method->slug(),
332 332
                 );
@@ -354,7 +354,7 @@  discard block
 block discarded – undo
354 354
         }
355 355
         $payment_method = EEM_Payment_Method::instance()->get_one(array(array('PMD_slug' => $payment_method_slug)));
356 356
         // if that didn't work or wasn't provided, find another way to select the current pm
357
-        if (! $this->_verify_payment_method($payment_method)) {
357
+        if ( ! $this->_verify_payment_method($payment_method)) {
358 358
             // like, looking for an active one
359 359
             $payment_method = EEM_Payment_Method::instance()->get_one_active('CART');
360 360
             // test that one as well
@@ -404,7 +404,7 @@  discard block
 block discarded – undo
404 404
     {
405 405
         $payment_method = isset($metabox['args'], $metabox['args']['payment_method'])
406 406
             ? $metabox['args']['payment_method'] : null;
407
-        if (! $payment_method instanceof EE_Payment_Method) {
407
+        if ( ! $payment_method instanceof EE_Payment_Method) {
408 408
             throw new EE_Error(sprintf(__('Payment method metabox setup incorrectly. No Payment method object was supplied',
409 409
                 'event_espresso')));
410 410
         }
@@ -415,7 +415,7 @@  discard block
 block discarded – undo
415 415
             if ($form->form_data_present_in($this->_req_data)) {
416 416
                 $form->receive_form_submission($this->_req_data);
417 417
             }
418
-            echo $form->form_open() . $form->get_html_and_js() . $form->form_close();
418
+            echo $form->form_open().$form->get_html_and_js().$form->form_close();
419 419
         } else {
420 420
             echo $this->_activate_payment_method_button($payment_method)->get_html_and_js();
421 421
         }
@@ -432,13 +432,13 @@  discard block
 block discarded – undo
432 432
      */
433 433
     protected function _generate_payment_method_settings_form(EE_Payment_Method $payment_method)
434 434
     {
435
-        if (! $payment_method instanceof EE_Payment_Method) {
435
+        if ( ! $payment_method instanceof EE_Payment_Method) {
436 436
             return new EE_Form_Section_Proper();
437 437
         }
438 438
         return new EE_Form_Section_Proper(
439 439
             array(
440
-                'name'            => $payment_method->slug() . '_settings_form',
441
-                'html_id'         => $payment_method->slug() . '_settings_form',
440
+                'name'            => $payment_method->slug().'_settings_form',
441
+                'html_id'         => $payment_method->slug().'_settings_form',
442 442
                 'action'          => EE_Admin_Page::add_query_args_and_nonce(
443 443
                     array(
444 444
                         'action'         => 'update_payment_method',
@@ -481,7 +481,7 @@  discard block
 block discarded – undo
481 481
                         EEH_HTML::label(
482 482
                             EEH_HTML::strong(__('IMPORTANT', 'event_espresso'), '', 'important-notice')
483 483
                         )
484
-                    ) .
484
+                    ).
485 485
                     EEH_HTML::td(
486 486
                         EEH_HTML::strong(__('You are responsible for your own website security and Payment Card Industry Data Security Standards (PCI DSS) compliance.',
487 487
                             'event_espresso'))
@@ -510,14 +510,14 @@  discard block
 block discarded – undo
510 510
      */
511 511
     protected function _currency_support(EE_Payment_Method $payment_method)
512 512
     {
513
-        if (! $payment_method->usable_for_currency(EE_Config::instance()->currency->code)) {
513
+        if ( ! $payment_method->usable_for_currency(EE_Config::instance()->currency->code)) {
514 514
             return new EE_Form_Section_HTML(
515 515
                 EEH_HTML::tr(
516 516
                     EEH_HTML::th(
517 517
                         EEH_HTML::label(
518 518
                             EEH_HTML::strong(__('IMPORTANT', 'event_espresso'), '', 'important-notice')
519 519
                         )
520
-                    ) .
520
+                    ).
521 521
                     EEH_HTML::td(
522 522
                         EEH_HTML::strong(
523 523
                             sprintf(
@@ -591,16 +591,16 @@  discard block
 block discarded – undo
591 591
         $update_button = new EE_Submit_Input(
592 592
             array(
593 593
                 'name'       => 'submit',
594
-                'html_id'    => 'save_' . $payment_method->slug() . '_settings',
594
+                'html_id'    => 'save_'.$payment_method->slug().'_settings',
595 595
                 'default'    => sprintf(__('Update %s Payment Settings', 'event_espresso'),
596 596
                     $payment_method->admin_name()),
597 597
                 'html_label' => EEH_HTML::nbsp(),
598 598
             )
599 599
         );
600 600
         return new EE_Form_Section_HTML(
601
-            EEH_HTML::no_row(EEH_HTML::br(2)) .
601
+            EEH_HTML::no_row(EEH_HTML::br(2)).
602 602
             EEH_HTML::tr(
603
-                EEH_HTML::th(__('Update Settings', 'event_espresso')) .
603
+                EEH_HTML::th(__('Update Settings', 'event_espresso')).
604 604
                 EEH_HTML::td(
605 605
                     $update_button->get_html_for_input()
606 606
                 )
@@ -623,7 +623,7 @@  discard block
 block discarded – undo
623 623
             $payment_method->admin_name());
624 624
         return new EE_Form_Section_HTML(
625 625
             EEH_HTML::tr(
626
-                EEH_HTML::th(__('Deactivate Payment Method', 'event_espresso')) .
626
+                EEH_HTML::th(__('Deactivate Payment Method', 'event_espresso')).
627 627
                 EEH_HTML::td(
628 628
                     EEH_HTML::link(
629 629
                         EE_Admin_Page::add_query_args_and_nonce(
@@ -635,7 +635,7 @@  discard block
 block discarded – undo
635 635
                         ),
636 636
                         $link_text_and_title,
637 637
                         $link_text_and_title,
638
-                        'deactivate_' . $payment_method->slug(),
638
+                        'deactivate_'.$payment_method->slug(),
639 639
                         'espresso-button button-secondary'
640 640
                     )
641 641
                 )
@@ -658,8 +658,8 @@  discard block
 block discarded – undo
658 658
             $payment_method->admin_name());
659 659
         return new EE_Form_Section_Proper(
660 660
             array(
661
-                'name'            => 'activate_' . $payment_method->slug() . '_settings_form',
662
-                'html_id'         => 'activate_' . $payment_method->slug() . '_settings_form',
661
+                'name'            => 'activate_'.$payment_method->slug().'_settings_form',
662
+                'html_id'         => 'activate_'.$payment_method->slug().'_settings_form',
663 663
                 'action'          => '#',
664 664
                 'layout_strategy' => new EE_Admin_Two_Column_Layout(),
665 665
                 'subsections'     => apply_filters(
@@ -673,11 +673,11 @@  discard block
 block discarded – undo
673 673
                                     '',
674 674
                                     'colspan="2"'
675 675
                                 )
676
-                            ) .
676
+                            ).
677 677
                             EEH_HTML::tr(
678 678
                                 EEH_HTML::th(
679 679
                                     EEH_HTML::label(__('Click to Activate ', 'event_espresso'))
680
-                                ) .
680
+                                ).
681 681
                                 EEH_HTML::td(
682 682
                                     EEH_HTML::link(
683 683
                                         EE_Admin_Page::add_query_args_and_nonce(
@@ -689,7 +689,7 @@  discard block
 block discarded – undo
689 689
                                         ),
690 690
                                         $link_text_and_title,
691 691
                                         $link_text_and_title,
692
-                                        'activate_' . $payment_method->slug(),
692
+                                        'activate_'.$payment_method->slug(),
693 693
                                         'espresso-button-green button-primary'
694 694
                                     )
695 695
                                 )
@@ -714,7 +714,7 @@  discard block
 block discarded – undo
714 714
     {
715 715
         return new EE_Form_Section_HTML(
716 716
             EEH_HTML::tr(
717
-                EEH_HTML::th() .
717
+                EEH_HTML::th().
718 718
                 EEH_HTML::td(
719 719
                     EEH_HTML::p(__('All fields marked with a * are required fields', 'event_espresso'), '', 'grey-text')
720 720
                 )
@@ -792,7 +792,7 @@  discard block
 block discarded – undo
792 792
                 }
793 793
             }
794 794
             //if we couldn't find the correct payment method type...
795
-            if (! $correct_pmt_form_to_use) {
795
+            if ( ! $correct_pmt_form_to_use) {
796 796
                 EE_Error::add_error(__("We could not find which payment method type your form submission related to. Please contact support",
797 797
                     'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
798 798
                 $this->_redirect_after_action(false, 'Payment Method', 'activated', array('action' => 'default'));
@@ -800,7 +800,7 @@  discard block
 block discarded – undo
800 800
             $correct_pmt_form_to_use->receive_form_submission($this->_req_data);
801 801
             if ($correct_pmt_form_to_use->is_valid()) {
802 802
                 $payment_settings_subform = $correct_pmt_form_to_use->get_subsection('payment_method_settings');
803
-                if (! $payment_settings_subform instanceof EE_Payment_Method_Form) {
803
+                if ( ! $payment_settings_subform instanceof EE_Payment_Method_Form) {
804 804
                     throw new EE_Error(
805 805
                         sprintf(
806 806
                             __('The payment method could not be saved because the form sections were misnamed. We expected to find %1$s, but did not.',
@@ -926,7 +926,7 @@  discard block
 block discarded – undo
926 926
         }
927 927
         //take into account search
928 928
         if (isset($this->_req_data['s']) && $this->_req_data['s']) {
929
-            $similarity_string = array('LIKE', '%' . str_replace("", "%", $this->_req_data['s']) . '%');
929
+            $similarity_string = array('LIKE', '%'.str_replace("", "%", $this->_req_data['s']).'%');
930 930
             $query_params[0]['OR*s']['Payment.Transaction.Registration.Attendee.ATT_fname'] = $similarity_string;
931 931
             $query_params[0]['OR*s']['Payment.Transaction.Registration.Attendee.ATT_lname'] = $similarity_string;
932 932
             $query_params[0]['OR*s']['Payment.Transaction.Registration.Attendee.ATT_email'] = $similarity_string;
@@ -946,8 +946,8 @@  discard block
 block discarded – undo
946 946
             $start_date = wp_strip_all_tags($this->_req_data['payment-filter-start-date']);
947 947
             $end_date = wp_strip_all_tags($this->_req_data['payment-filter-end-date']);
948 948
             //make sure our timestamps start and end right at the boundaries for each day
949
-            $start_date = date('Y-m-d', strtotime($start_date)) . ' 00:00:00';
950
-            $end_date = date('Y-m-d', strtotime($end_date)) . ' 23:59:59';
949
+            $start_date = date('Y-m-d', strtotime($start_date)).' 00:00:00';
950
+            $end_date = date('Y-m-d', strtotime($end_date)).' 23:59:59';
951 951
             //convert to timestamps
952 952
             $start_date = strtotime($start_date);
953 953
             $end_date = strtotime($end_date);
@@ -974,15 +974,15 @@  discard block
 block discarded – undo
974 974
             $query_params['order_by'] = array('LOG_time' => 'DESC');
975 975
         }
976 976
         $offset = ($current_page - 1) * $per_page;
977
-        if (! isset($this->_req_data['download_results'])) {
977
+        if ( ! isset($this->_req_data['download_results'])) {
978 978
             $query_params['limit'] = array($offset, $per_page);
979 979
         }
980 980
         //now they've requested to instead just download the file instead of viewing it.
981 981
         if (isset($this->_req_data['download_results'])) {
982 982
             $wpdb_results = EEM_Change_Log::instance()->get_all_efficiently($query_params);
983 983
             header('Content-Disposition: attachment');
984
-            header("Content-Disposition: attachment; filename=ee_payment_logs_for_" . sanitize_key(site_url()));
985
-            echo "<h1>Payment Logs for " . site_url() . "</h1>";
984
+            header("Content-Disposition: attachment; filename=ee_payment_logs_for_".sanitize_key(site_url()));
985
+            echo "<h1>Payment Logs for ".site_url()."</h1>";
986 986
             echo "<h3>Query:</h3>";
987 987
             var_dump($query_params);
988 988
             echo "<h3>Results:</h3>";
@@ -1036,7 +1036,7 @@  discard block
 block discarded – undo
1036 1036
             }
1037 1037
         }
1038 1038
         $this->_template_args['admin_page_content'] = EEH_Template::display_template(
1039
-            EE_PAYMENTS_TEMPLATE_PATH . 'payment_log_details.template.php',
1039
+            EE_PAYMENTS_TEMPLATE_PATH.'payment_log_details.template.php',
1040 1040
             array(
1041 1041
                 'payment_log'    => $payment_log,
1042 1042
                 'payment_method' => $payment_method,
Please login to merge, or discard this patch.
core/libraries/form_sections/base/EE_Model_Form_Section.form.php 3 patches
Doc Comments   +1 added lines patch added patch discarded remove patch
@@ -372,6 +372,7 @@
 block discarded – undo
372 372
      * save the relations indicated
373 373
      *
374 374
      * @type string $relation_name
375
+     * @param integer $relation_name
375 376
      * @return bool
376 377
      * @throws EE_Error
377 378
      */
Please login to merge, or discard this patch.
Indentation   +433 added lines, -433 removed lines patch added patch discarded remove patch
@@ -14,439 +14,439 @@
 block discarded – undo
14 14
 class EE_Model_Form_Section extends EE_Form_Section_Proper
15 15
 {
16 16
 
17
-    /**
18
-     * @var EEM_Base
19
-     */
20
-    protected $_model = null;
21
-
22
-    /**
23
-     * @var EE_Base_Class
24
-     */
25
-    protected $_model_object = null;
26
-
27
-
28
-
29
-    /**
30
-     * @param array        $options_array   keys: {
31
-     * @type EEM_Base      $model
32
-     * @type EE_Base_Class $model_object
33
-     * @type array         $subsection_args array keys should be subsection names (that either do or will exist), and
34
-     *       values are the arrays as you would pass them to that subsection
35
-     *                                      }
36
-     * @throws EE_Error
37
-     */
38
-    public function __construct($options_array = array())
39
-    {
40
-        if (isset($options_array['model']) && $options_array['model'] instanceof EEM_Base) {
41
-            $this->_model = $options_array['model'];
42
-        }
43
-        if (! $this->_model || ! $this->_model instanceof EEM_Base) {
44
-            throw new EE_Error(sprintf(__("Model Form Sections must first specify the _model property to be a subclass of EEM_Base",
45
-                "event_espresso")));
46
-        }
47
-        if (isset($options_array['subsection_args'])) {
48
-            $subsection_args = $options_array['subsection_args'];
49
-        } else {
50
-            $subsection_args = array();
51
-        }
52
-        //gather fields and relations to convert to inputs
53
-        //but if they're just going to exclude a field anyways, don't bother converting it to an input
54
-        $exclude = $this->_subsections;
55
-        if (isset($options_array['exclude'])) {
56
-            $exclude = array_merge($exclude, array_flip($options_array['exclude']));
57
-        }
58
-        $model_fields = array_diff_key($this->_model->field_settings(), $exclude);
59
-        $model_relations = array_diff_key($this->_model->relation_settings(), $exclude);
60
-        //convert fields and relations to inputs
61
-        $this->_subsections = array_merge(
62
-            $this->_convert_model_fields_to_inputs($model_fields),
63
-            $this->_convert_model_relations_to_inputs($model_relations, $subsection_args),
64
-            $this->_subsections
65
-        );
66
-        parent::__construct($options_array);
67
-        if (isset($options_array['model_object']) && $options_array['model_object'] instanceof EE_Base_Class) {
68
-            $this->populate_model_obj($options_array['model_object']);
69
-        }
70
-    }
71
-
72
-
73
-
74
-    /**
75
-     * For now, just makes inputs for only HABTM relations
76
-     *
77
-     * @param EE_Model_Relation_Base[] $relations
78
-     * @param array                    $subsection_args keys should be existing or soon-to-be-existing input names, and
79
-     *                                                  their values are {
80
-     * @type array {
81
-     * @type EE_Base_Class[]           $model_objects   if the subsection is an EE_Select_Multi_Model_Input
82
-     *                                                  }
83
-     *                                                  }
84
-     * @return array
85
-     */
86
-    protected function _convert_model_relations_to_inputs($relations, $subsection_args = array())
87
-    {
88
-        $inputs = array();
89
-        foreach ($relations as $relation_name => $relation_obj) {
90
-            $input_constructor_args = array(
91
-                array_merge(
92
-                    array(
93
-                        'required'        => $relation_obj instanceof EE_Belongs_To_Relation,
94
-                        'html_label_text' => $relation_obj instanceof EE_Belongs_To_Relation
95
-                            ? $relation_obj->get_other_model()->item_name(1)
96
-                            : $relation_obj->get_other_model()
97
-                                           ->item_name(2),
98
-                    ),
99
-                    $subsection_args
100
-                ),
101
-            );
102
-            $input = null;
103
-            switch (get_class($relation_obj)) {
104
-                case 'EE_HABTM_Relation':
105
-                    if (isset($subsection_args[$relation_name])
106
-                        && isset($subsection_args[$relation_name]['model_objects'])
107
-                    ) {
108
-                        $model_objects = $subsection_args[$relation_name]['model_objects'];
109
-                    } else {
110
-                        $model_objects = $relation_obj->get_other_model()->get_all();
111
-                    }
112
-                    $input = new EE_Select_Multi_Model_Input($model_objects, $input_constructor_args);
113
-                    break;
114
-                default:
115
-            }
116
-            if ($input) {
117
-                $inputs[$relation_name] = $input;
118
-            }
119
-        }
120
-        return $inputs;
121
-    }
122
-
123
-
124
-
125
-    /**
126
-     * Changes model fields into form section inputs
127
-     *
128
-     * @param EE_Model_Field_Base[] $model_fields keys are the model's name
129
-     * @throws EE_Error
130
-     * @return EE_Form_Input_Base[]
131
-     */
132
-    protected function _convert_model_fields_to_inputs($model_fields = array())
133
-    {
134
-        $inputs = array();
135
-        foreach ($model_fields as $field_name => $model_field) {
136
-            if ($model_field instanceof EE_Model_Field_Base) {
137
-                $input_constructor_args = array(
138
-                    array(
139
-                        'required'        => ! $model_field->is_nullable()
140
-                                             && $model_field->get_default_value()
141
-                                                === null,
142
-                        'html_label_text' => $model_field->get_nicename(),
143
-                        'default'         => $model_field->get_default_value(),
144
-                    ),
145
-                );
146
-                switch (get_class($model_field)) {
147
-                    case 'EE_All_Caps_Text_Field':
148
-                    case 'EE_Any_Foreign_Model_Name_Field':
149
-                        $input_class = 'EE_Text_Input';
150
-                        break;
151
-                    case 'EE_Boolean_Field':
152
-                        $input_class = 'EE_Yes_No_Input';
153
-                        break;
154
-                    case 'EE_Datetime_Field':
155
-                        throw new EE_Error(sprintf(__("Model field '%s' does not yet have a known conversion to form input",
156
-                            "event_espresso"), get_class($model_field)));
157
-                        break;
158
-                    case 'EE_Email_Field':
159
-                        $input_class = 'EE_Email_Input';
160
-                        break;
161
-                    case 'EE_Enum_Integer_Field':
162
-                        throw new EE_Error(sprintf(__("Model field '%s' does not yet have a known conversion to form input",
163
-                            "event_espresso"), get_class($model_field)));
164
-                        break;
165
-                    case 'EE_Enum_Text_Field':
166
-                        throw new EE_Error(sprintf(__("Model field '%s' does not yet have a known conversion to form input",
167
-                            "event_espresso"), get_class($model_field)));
168
-                        break;
169
-                    case 'EE_Float_Field':
170
-                        $input_class = 'EE_Float_Input';
171
-                        break;
172
-                    case 'EE_Foreign_Key_Int_Field':
173
-                    case 'EE_Foreign_Key_String_Field':
174
-                    case 'EE_WP_User_Field':
175
-                        $models_pointed_to = $model_field instanceof EE_Field_With_Model_Name
176
-                            ? $model_field->get_model_class_names_pointed_to() : array();
177
-                        if (true || is_array($models_pointed_to) && count($models_pointed_to) > 1) {
178
-                            $input_class = 'EE_Text_Input';
179
-                        } else {
180
-                            //so its just one model
181
-                            $model_name = is_array($models_pointed_to) ? reset($models_pointed_to) : $models_pointed_to;
182
-                            $model = EE_Registry::instance()->load_model($model_name);
183
-                            $model_names = $model->get_all_names(array('limit' => 10));
184
-                            if ($model_field->is_nullable()) {
185
-                                array_unshift($model_names, __("Please Select", 'event_espresso'));
186
-                            }
187
-                            $input_constructor_args[1] = $input_constructor_args[0];
188
-                            $input_constructor_args[0] = $model_names;
189
-                            $input_class = 'EE_Select_Input';
190
-                        }
191
-                        break;
192
-                    case 'EE_Full_HTML_Field':
193
-                        $input_class = 'EE_Text_Area_Input';
194
-                        $input_constructor_args[0]['validation_strategies'] = array(new EE_Full_HTML_Validation_Strategy());
195
-                        break;
196
-                    case 'EE_Infinite_Integer':
197
-                        throw new EE_Error(sprintf(__("Model field '%s' does not yet have a known conversion to form input",
198
-                            "event_espresso"), get_class($model_field)));
199
-                        break;
200
-                    case 'EE_Integer_Field':
201
-                        $input_class = 'EE_Text_Input';
202
-                        break;
203
-                    case 'EE_Maybe_Serialized_Text_Field':
204
-                        $input_class = 'EE_Text_Area_Input';
205
-                        break;
206
-                    case 'EE_Money_Field':
207
-                        throw new EE_Error(sprintf(__("Model field '%s' does not yet have a known conversion to form input",
208
-                            "event_espresso"), get_class($model_field)));
209
-                        break;
210
-                    case 'EE_Post_Content_Field':
211
-                        $input_class = 'EE_Text_Area_Input';
212
-                        $input_constructor_args[0]['validation_strategies'] = array(new EE_Full_HTML_Validation_Strategy());
213
-                        break;
214
-                    case 'EE_Plain_Text_Field':
215
-                        $input_class = 'EE_Text_Input';
216
-                        break;
217
-                    case 'EE_Primary_Key_Int_Field':
218
-                        $input_class = 'EE_Hidden_Input';
219
-                        $input_constructor_args['normalization_strategy'] = new EE_Int_Normalization();
220
-                        break;
221
-                    case 'EE_Primary_Key_String_Field':
222
-                        $input_class = 'EE_Hidden_Input';
223
-                        break;
224
-                    case 'EE_Serialized_Text_Field':
225
-                        $input_class = 'EE_Text_Area_Input';
226
-                        break;
227
-                    case 'EE_Simple_HTML_Field':
228
-                        $input_class = 'EE_Text_Area_Input';
229
-                        $input_constructor_args[0]['validation_strategies'] = array(new EE_Simple_HTML_Validation_Strategy());
230
-                        break;
231
-                    case 'EE_Slug_Field':
232
-                        $input_class = 'EE_Text_Input';
233
-                        break;
234
-                    case 'EE_Trashed_Flag_Field':
235
-                        $input_class = 'EE_Yes_No_Input';
236
-                        break;
237
-                    case 'EE_WP_Post_Status_Field':
238
-                        throw new EE_Error(sprintf(__("Model field '%s' does not yet have a known conversion to form input",
239
-                            "event_espresso"), get_class($model_field)));
240
-                        break;
241
-                    case 'EE_WP_Post_Type_Field':
242
-                        throw new EE_Error(sprintf(__("Model field '%s' does not yet have a known conversion to form input",
243
-                            "event_espresso"), get_class($model_field)));
244
-                        break;
245
-                    default:
246
-                        throw new EE_Error(sprintf(__("Model field of type '%s' does not convert to any known Form Input. Please add a case to EE_Model_Form_section's _convert_model_fields_to_inputs switch statement",
247
-                            "event_espresso"), get_class($model_field)));
248
-                }
249
-                $reflection = new ReflectionClass($input_class);
250
-                $input = $reflection->newInstanceArgs($input_constructor_args);
251
-                $inputs[$field_name] = $input;
252
-            }
253
-        }
254
-        return $inputs;
255
-    }
256
-
257
-
258
-
259
-    /**
260
-     * Mostly the same as populate_defaults , except takes a model object as input, not an array,
261
-     * and also sets the form's _model_object
262
-     *
263
-     * @param EE_Base_Class $model_obj
264
-     * @return void
265
-     */
266
-    public function populate_model_obj($model_obj)
267
-    {
268
-        $model_obj = $this->_model->ensure_is_obj($model_obj);
269
-        $this->_model_object = $model_obj;
270
-        $defaults = $model_obj->model_field_array();
271
-        foreach ($this->_model->relation_settings() as $relation_name => $relation_obj) {
272
-            $subsection = $this->get_subsection($relation_name, false);
273
-            if ($subsection instanceof EE_Form_Input_Base) {
274
-                if ($relation_obj instanceof EE_Belongs_To_Relation) {
275
-                    //then we only expect there to be one
276
-                    $related_item = $this->_model_object->get_first_related($relation_name);
277
-                    $defaults[$relation_name] = $related_item->ID();
278
-                } else {
279
-                    $related_items = $this->_model_object->get_many_related($relation_name);
280
-                    $ids = array();
281
-                    foreach ($related_items as $related_item) {
282
-                        $ids[] = $related_item->ID();
283
-                    }
284
-                    $defaults[$relation_name] = $ids;
285
-                }
286
-            }
287
-        }
288
-        $defaults = apply_filters(
289
-            'FHEE__EE_Model_Form_Section__populate_model_obj',
290
-            $defaults,
291
-            $this
292
-        );
293
-        $this->populate_defaults($defaults);
294
-    }
295
-
296
-
297
-
298
-    /**
299
-     * Gets all the input values that correspond to model fields. Keys are the input/field names,
300
-     * values are their normalized values
301
-     *
302
-     * @return array
303
-     */
304
-    public function inputs_values_corresponding_to_model_fields()
305
-    {
306
-        return array_intersect_key($this->input_values(), $this->_model->field_settings());
307
-    }
308
-
309
-
310
-
311
-    /**
312
-     * After we've normalized the data as normal, set the corresponding model object
313
-     * on the form.
314
-     *
315
-     * @param array $req_data should usually be $_REQUEST (the default).
316
-     * @return void
317
-     */
318
-    public function _normalize($req_data)
319
-    {
320
-        parent::_normalize($req_data);
321
-        //create or set the model object, if it isn't already
322
-        if (! $this->_model_object) {
323
-            //check to see if the form indicates a PK, in which case we want to only retrieve it and update it
324
-            $pk_name = $this->_model->primary_key_name();
325
-            $model_obj = $this->_model->get_one_by_ID($this->get_input_value($pk_name));
326
-            if ($model_obj) {
327
-                $this->_model_object = $model_obj;
328
-            } else {
329
-                $this->_model_object = EE_Registry::instance()->load_class($this->_model->get_this_model_name());
330
-            }
331
-        }
332
-    }
333
-
334
-
335
-
336
-    /**
337
-     * After this form has been initialized and is verified to be valid,
338
-     * either creates a model object from its data and saves it, or updates
339
-     * the model object its data represents
340
-     *
341
-     * @throws EE_Error
342
-     * @return int, 1 on a successful update, the ID of
343
-     *                    the new entry on insert; 0 on failure
344
-     */
345
-    public function save()
346
-    {
347
-        if (! $this->_model_object) {
348
-            throw new EE_Error(sprintf(__("Cannot save the model form's model object (model is '%s') because there is no model object set. You must either set it, or call receive_form_submission where it is set automatically",
349
-                "event_espresso"), get_class($this->_model)));
350
-        }
351
-        //ok so the model object is set. Just set it with the submitted form data
352
-        foreach ($this->inputs_values_corresponding_to_model_fields() as $field_name => $field_value) {
353
-            //only set the non-primary key
354
-            if ($field_name != $this->_model->primary_key_name()) {
355
-                $this->_model_object->set($field_name, $field_value);
356
-            }
357
-        }
358
-        $success = $this->_model_object->save();
359
-        foreach ($this->_model->relation_settings() as $relation_name => $relation_obj) {
360
-            if (isset($this->_subsections[$relation_name])) {
361
-                $success = $this->_save_related_info($relation_name);
362
-            }
363
-        }
364
-        do_action('AHEE__EE_Model_Form_Section__save__done', $this, $success);
365
-        return $success;
366
-    }
367
-
368
-
369
-
370
-    /**
371
-     * Automatically finds the related model info from the form, if present, and
372
-     * save the relations indicated
373
-     *
374
-     * @type string $relation_name
375
-     * @return bool
376
-     * @throws EE_Error
377
-     */
378
-    protected function _save_related_info($relation_name)
379
-    {
380
-        $relation_obj = $this->_model->related_settings_for($relation_name);
381
-        if ($relation_obj instanceof EE_Belongs_To_Relation) {
382
-            //there is just a foreign key on this model pointing to that one
383
-            $this->_model_object->_add_relation_to($this->get_input_value($relation_name), $relation_name);
384
-        } elseif ($relation_obj instanceof EE_Has_Many_Relation) {
385
-            //then we want to consider all of its currently-related things.
386
-            //if they're in this list, keep them
387
-            //if they're not in this list, remove them
388
-            //and lastly add all the new items
389
-            throw new EE_Error(sprintf(__('Automatic saving of related info across a "has many" relation is not yet supported',
390
-                "event_espresso")));
391
-        } elseif ($relation_obj instanceof EE_HABTM_Relation) {
392
-            //delete everything NOT in this list
393
-            $normalized_input_value = $this->get_input_value($relation_name);
394
-            if ($normalized_input_value && is_array($normalized_input_value)) {
395
-                $where_query_params = array(
396
-                    $relation_obj->get_other_model()->primary_key_name() => array('NOT_IN', $normalized_input_value),
397
-                );
398
-            } else {
399
-                $where_query_params = array();
400
-            }
401
-            $this->_model_object->_remove_relations($relation_name, $where_query_params);
402
-            foreach ($normalized_input_value as $id) {
403
-                $this->_model_object->_add_relation_to($id, $relation_name);
404
-            }
405
-        }
406
-        return true;
407
-    }
408
-
409
-
410
-
411
-    /**
412
-     * Gets the model of this model form
413
-     *
414
-     * @return EEM_Base
415
-     */
416
-    public function get_model()
417
-    {
418
-        return $this->_model;
419
-    }
420
-
421
-
422
-
423
-    /**
424
-     * Gets the model object for this model form, which was either set
425
-     * upon construction (using the $options_array arg 'model_object'), by using
426
-     * set_model_object($model_obj), or implicitly
427
-     * when receive_form_submission($req_data) was called.
428
-     *
429
-     * @return EE_Base_Class
430
-     */
431
-    public function get_model_object()
432
-    {
433
-        return $this->_model_object;
434
-    }
435
-
436
-
437
-
438
-    /**
439
-     * gets teh default name of this form section if none is specified
440
-     *
441
-     * @return string
442
-     */
443
-    protected function _set_default_name_if_empty()
444
-    {
445
-        if (! $this->_name) {
446
-            $default_name = str_replace("EEM_", "", get_class($this->_model)) . "_Model_Form";
447
-            $this->_name = $default_name;
448
-        }
449
-    }
17
+	/**
18
+	 * @var EEM_Base
19
+	 */
20
+	protected $_model = null;
21
+
22
+	/**
23
+	 * @var EE_Base_Class
24
+	 */
25
+	protected $_model_object = null;
26
+
27
+
28
+
29
+	/**
30
+	 * @param array        $options_array   keys: {
31
+	 * @type EEM_Base      $model
32
+	 * @type EE_Base_Class $model_object
33
+	 * @type array         $subsection_args array keys should be subsection names (that either do or will exist), and
34
+	 *       values are the arrays as you would pass them to that subsection
35
+	 *                                      }
36
+	 * @throws EE_Error
37
+	 */
38
+	public function __construct($options_array = array())
39
+	{
40
+		if (isset($options_array['model']) && $options_array['model'] instanceof EEM_Base) {
41
+			$this->_model = $options_array['model'];
42
+		}
43
+		if (! $this->_model || ! $this->_model instanceof EEM_Base) {
44
+			throw new EE_Error(sprintf(__("Model Form Sections must first specify the _model property to be a subclass of EEM_Base",
45
+				"event_espresso")));
46
+		}
47
+		if (isset($options_array['subsection_args'])) {
48
+			$subsection_args = $options_array['subsection_args'];
49
+		} else {
50
+			$subsection_args = array();
51
+		}
52
+		//gather fields and relations to convert to inputs
53
+		//but if they're just going to exclude a field anyways, don't bother converting it to an input
54
+		$exclude = $this->_subsections;
55
+		if (isset($options_array['exclude'])) {
56
+			$exclude = array_merge($exclude, array_flip($options_array['exclude']));
57
+		}
58
+		$model_fields = array_diff_key($this->_model->field_settings(), $exclude);
59
+		$model_relations = array_diff_key($this->_model->relation_settings(), $exclude);
60
+		//convert fields and relations to inputs
61
+		$this->_subsections = array_merge(
62
+			$this->_convert_model_fields_to_inputs($model_fields),
63
+			$this->_convert_model_relations_to_inputs($model_relations, $subsection_args),
64
+			$this->_subsections
65
+		);
66
+		parent::__construct($options_array);
67
+		if (isset($options_array['model_object']) && $options_array['model_object'] instanceof EE_Base_Class) {
68
+			$this->populate_model_obj($options_array['model_object']);
69
+		}
70
+	}
71
+
72
+
73
+
74
+	/**
75
+	 * For now, just makes inputs for only HABTM relations
76
+	 *
77
+	 * @param EE_Model_Relation_Base[] $relations
78
+	 * @param array                    $subsection_args keys should be existing or soon-to-be-existing input names, and
79
+	 *                                                  their values are {
80
+	 * @type array {
81
+	 * @type EE_Base_Class[]           $model_objects   if the subsection is an EE_Select_Multi_Model_Input
82
+	 *                                                  }
83
+	 *                                                  }
84
+	 * @return array
85
+	 */
86
+	protected function _convert_model_relations_to_inputs($relations, $subsection_args = array())
87
+	{
88
+		$inputs = array();
89
+		foreach ($relations as $relation_name => $relation_obj) {
90
+			$input_constructor_args = array(
91
+				array_merge(
92
+					array(
93
+						'required'        => $relation_obj instanceof EE_Belongs_To_Relation,
94
+						'html_label_text' => $relation_obj instanceof EE_Belongs_To_Relation
95
+							? $relation_obj->get_other_model()->item_name(1)
96
+							: $relation_obj->get_other_model()
97
+										   ->item_name(2),
98
+					),
99
+					$subsection_args
100
+				),
101
+			);
102
+			$input = null;
103
+			switch (get_class($relation_obj)) {
104
+				case 'EE_HABTM_Relation':
105
+					if (isset($subsection_args[$relation_name])
106
+						&& isset($subsection_args[$relation_name]['model_objects'])
107
+					) {
108
+						$model_objects = $subsection_args[$relation_name]['model_objects'];
109
+					} else {
110
+						$model_objects = $relation_obj->get_other_model()->get_all();
111
+					}
112
+					$input = new EE_Select_Multi_Model_Input($model_objects, $input_constructor_args);
113
+					break;
114
+				default:
115
+			}
116
+			if ($input) {
117
+				$inputs[$relation_name] = $input;
118
+			}
119
+		}
120
+		return $inputs;
121
+	}
122
+
123
+
124
+
125
+	/**
126
+	 * Changes model fields into form section inputs
127
+	 *
128
+	 * @param EE_Model_Field_Base[] $model_fields keys are the model's name
129
+	 * @throws EE_Error
130
+	 * @return EE_Form_Input_Base[]
131
+	 */
132
+	protected function _convert_model_fields_to_inputs($model_fields = array())
133
+	{
134
+		$inputs = array();
135
+		foreach ($model_fields as $field_name => $model_field) {
136
+			if ($model_field instanceof EE_Model_Field_Base) {
137
+				$input_constructor_args = array(
138
+					array(
139
+						'required'        => ! $model_field->is_nullable()
140
+											 && $model_field->get_default_value()
141
+												=== null,
142
+						'html_label_text' => $model_field->get_nicename(),
143
+						'default'         => $model_field->get_default_value(),
144
+					),
145
+				);
146
+				switch (get_class($model_field)) {
147
+					case 'EE_All_Caps_Text_Field':
148
+					case 'EE_Any_Foreign_Model_Name_Field':
149
+						$input_class = 'EE_Text_Input';
150
+						break;
151
+					case 'EE_Boolean_Field':
152
+						$input_class = 'EE_Yes_No_Input';
153
+						break;
154
+					case 'EE_Datetime_Field':
155
+						throw new EE_Error(sprintf(__("Model field '%s' does not yet have a known conversion to form input",
156
+							"event_espresso"), get_class($model_field)));
157
+						break;
158
+					case 'EE_Email_Field':
159
+						$input_class = 'EE_Email_Input';
160
+						break;
161
+					case 'EE_Enum_Integer_Field':
162
+						throw new EE_Error(sprintf(__("Model field '%s' does not yet have a known conversion to form input",
163
+							"event_espresso"), get_class($model_field)));
164
+						break;
165
+					case 'EE_Enum_Text_Field':
166
+						throw new EE_Error(sprintf(__("Model field '%s' does not yet have a known conversion to form input",
167
+							"event_espresso"), get_class($model_field)));
168
+						break;
169
+					case 'EE_Float_Field':
170
+						$input_class = 'EE_Float_Input';
171
+						break;
172
+					case 'EE_Foreign_Key_Int_Field':
173
+					case 'EE_Foreign_Key_String_Field':
174
+					case 'EE_WP_User_Field':
175
+						$models_pointed_to = $model_field instanceof EE_Field_With_Model_Name
176
+							? $model_field->get_model_class_names_pointed_to() : array();
177
+						if (true || is_array($models_pointed_to) && count($models_pointed_to) > 1) {
178
+							$input_class = 'EE_Text_Input';
179
+						} else {
180
+							//so its just one model
181
+							$model_name = is_array($models_pointed_to) ? reset($models_pointed_to) : $models_pointed_to;
182
+							$model = EE_Registry::instance()->load_model($model_name);
183
+							$model_names = $model->get_all_names(array('limit' => 10));
184
+							if ($model_field->is_nullable()) {
185
+								array_unshift($model_names, __("Please Select", 'event_espresso'));
186
+							}
187
+							$input_constructor_args[1] = $input_constructor_args[0];
188
+							$input_constructor_args[0] = $model_names;
189
+							$input_class = 'EE_Select_Input';
190
+						}
191
+						break;
192
+					case 'EE_Full_HTML_Field':
193
+						$input_class = 'EE_Text_Area_Input';
194
+						$input_constructor_args[0]['validation_strategies'] = array(new EE_Full_HTML_Validation_Strategy());
195
+						break;
196
+					case 'EE_Infinite_Integer':
197
+						throw new EE_Error(sprintf(__("Model field '%s' does not yet have a known conversion to form input",
198
+							"event_espresso"), get_class($model_field)));
199
+						break;
200
+					case 'EE_Integer_Field':
201
+						$input_class = 'EE_Text_Input';
202
+						break;
203
+					case 'EE_Maybe_Serialized_Text_Field':
204
+						$input_class = 'EE_Text_Area_Input';
205
+						break;
206
+					case 'EE_Money_Field':
207
+						throw new EE_Error(sprintf(__("Model field '%s' does not yet have a known conversion to form input",
208
+							"event_espresso"), get_class($model_field)));
209
+						break;
210
+					case 'EE_Post_Content_Field':
211
+						$input_class = 'EE_Text_Area_Input';
212
+						$input_constructor_args[0]['validation_strategies'] = array(new EE_Full_HTML_Validation_Strategy());
213
+						break;
214
+					case 'EE_Plain_Text_Field':
215
+						$input_class = 'EE_Text_Input';
216
+						break;
217
+					case 'EE_Primary_Key_Int_Field':
218
+						$input_class = 'EE_Hidden_Input';
219
+						$input_constructor_args['normalization_strategy'] = new EE_Int_Normalization();
220
+						break;
221
+					case 'EE_Primary_Key_String_Field':
222
+						$input_class = 'EE_Hidden_Input';
223
+						break;
224
+					case 'EE_Serialized_Text_Field':
225
+						$input_class = 'EE_Text_Area_Input';
226
+						break;
227
+					case 'EE_Simple_HTML_Field':
228
+						$input_class = 'EE_Text_Area_Input';
229
+						$input_constructor_args[0]['validation_strategies'] = array(new EE_Simple_HTML_Validation_Strategy());
230
+						break;
231
+					case 'EE_Slug_Field':
232
+						$input_class = 'EE_Text_Input';
233
+						break;
234
+					case 'EE_Trashed_Flag_Field':
235
+						$input_class = 'EE_Yes_No_Input';
236
+						break;
237
+					case 'EE_WP_Post_Status_Field':
238
+						throw new EE_Error(sprintf(__("Model field '%s' does not yet have a known conversion to form input",
239
+							"event_espresso"), get_class($model_field)));
240
+						break;
241
+					case 'EE_WP_Post_Type_Field':
242
+						throw new EE_Error(sprintf(__("Model field '%s' does not yet have a known conversion to form input",
243
+							"event_espresso"), get_class($model_field)));
244
+						break;
245
+					default:
246
+						throw new EE_Error(sprintf(__("Model field of type '%s' does not convert to any known Form Input. Please add a case to EE_Model_Form_section's _convert_model_fields_to_inputs switch statement",
247
+							"event_espresso"), get_class($model_field)));
248
+				}
249
+				$reflection = new ReflectionClass($input_class);
250
+				$input = $reflection->newInstanceArgs($input_constructor_args);
251
+				$inputs[$field_name] = $input;
252
+			}
253
+		}
254
+		return $inputs;
255
+	}
256
+
257
+
258
+
259
+	/**
260
+	 * Mostly the same as populate_defaults , except takes a model object as input, not an array,
261
+	 * and also sets the form's _model_object
262
+	 *
263
+	 * @param EE_Base_Class $model_obj
264
+	 * @return void
265
+	 */
266
+	public function populate_model_obj($model_obj)
267
+	{
268
+		$model_obj = $this->_model->ensure_is_obj($model_obj);
269
+		$this->_model_object = $model_obj;
270
+		$defaults = $model_obj->model_field_array();
271
+		foreach ($this->_model->relation_settings() as $relation_name => $relation_obj) {
272
+			$subsection = $this->get_subsection($relation_name, false);
273
+			if ($subsection instanceof EE_Form_Input_Base) {
274
+				if ($relation_obj instanceof EE_Belongs_To_Relation) {
275
+					//then we only expect there to be one
276
+					$related_item = $this->_model_object->get_first_related($relation_name);
277
+					$defaults[$relation_name] = $related_item->ID();
278
+				} else {
279
+					$related_items = $this->_model_object->get_many_related($relation_name);
280
+					$ids = array();
281
+					foreach ($related_items as $related_item) {
282
+						$ids[] = $related_item->ID();
283
+					}
284
+					$defaults[$relation_name] = $ids;
285
+				}
286
+			}
287
+		}
288
+		$defaults = apply_filters(
289
+			'FHEE__EE_Model_Form_Section__populate_model_obj',
290
+			$defaults,
291
+			$this
292
+		);
293
+		$this->populate_defaults($defaults);
294
+	}
295
+
296
+
297
+
298
+	/**
299
+	 * Gets all the input values that correspond to model fields. Keys are the input/field names,
300
+	 * values are their normalized values
301
+	 *
302
+	 * @return array
303
+	 */
304
+	public function inputs_values_corresponding_to_model_fields()
305
+	{
306
+		return array_intersect_key($this->input_values(), $this->_model->field_settings());
307
+	}
308
+
309
+
310
+
311
+	/**
312
+	 * After we've normalized the data as normal, set the corresponding model object
313
+	 * on the form.
314
+	 *
315
+	 * @param array $req_data should usually be $_REQUEST (the default).
316
+	 * @return void
317
+	 */
318
+	public function _normalize($req_data)
319
+	{
320
+		parent::_normalize($req_data);
321
+		//create or set the model object, if it isn't already
322
+		if (! $this->_model_object) {
323
+			//check to see if the form indicates a PK, in which case we want to only retrieve it and update it
324
+			$pk_name = $this->_model->primary_key_name();
325
+			$model_obj = $this->_model->get_one_by_ID($this->get_input_value($pk_name));
326
+			if ($model_obj) {
327
+				$this->_model_object = $model_obj;
328
+			} else {
329
+				$this->_model_object = EE_Registry::instance()->load_class($this->_model->get_this_model_name());
330
+			}
331
+		}
332
+	}
333
+
334
+
335
+
336
+	/**
337
+	 * After this form has been initialized and is verified to be valid,
338
+	 * either creates a model object from its data and saves it, or updates
339
+	 * the model object its data represents
340
+	 *
341
+	 * @throws EE_Error
342
+	 * @return int, 1 on a successful update, the ID of
343
+	 *                    the new entry on insert; 0 on failure
344
+	 */
345
+	public function save()
346
+	{
347
+		if (! $this->_model_object) {
348
+			throw new EE_Error(sprintf(__("Cannot save the model form's model object (model is '%s') because there is no model object set. You must either set it, or call receive_form_submission where it is set automatically",
349
+				"event_espresso"), get_class($this->_model)));
350
+		}
351
+		//ok so the model object is set. Just set it with the submitted form data
352
+		foreach ($this->inputs_values_corresponding_to_model_fields() as $field_name => $field_value) {
353
+			//only set the non-primary key
354
+			if ($field_name != $this->_model->primary_key_name()) {
355
+				$this->_model_object->set($field_name, $field_value);
356
+			}
357
+		}
358
+		$success = $this->_model_object->save();
359
+		foreach ($this->_model->relation_settings() as $relation_name => $relation_obj) {
360
+			if (isset($this->_subsections[$relation_name])) {
361
+				$success = $this->_save_related_info($relation_name);
362
+			}
363
+		}
364
+		do_action('AHEE__EE_Model_Form_Section__save__done', $this, $success);
365
+		return $success;
366
+	}
367
+
368
+
369
+
370
+	/**
371
+	 * Automatically finds the related model info from the form, if present, and
372
+	 * save the relations indicated
373
+	 *
374
+	 * @type string $relation_name
375
+	 * @return bool
376
+	 * @throws EE_Error
377
+	 */
378
+	protected function _save_related_info($relation_name)
379
+	{
380
+		$relation_obj = $this->_model->related_settings_for($relation_name);
381
+		if ($relation_obj instanceof EE_Belongs_To_Relation) {
382
+			//there is just a foreign key on this model pointing to that one
383
+			$this->_model_object->_add_relation_to($this->get_input_value($relation_name), $relation_name);
384
+		} elseif ($relation_obj instanceof EE_Has_Many_Relation) {
385
+			//then we want to consider all of its currently-related things.
386
+			//if they're in this list, keep them
387
+			//if they're not in this list, remove them
388
+			//and lastly add all the new items
389
+			throw new EE_Error(sprintf(__('Automatic saving of related info across a "has many" relation is not yet supported',
390
+				"event_espresso")));
391
+		} elseif ($relation_obj instanceof EE_HABTM_Relation) {
392
+			//delete everything NOT in this list
393
+			$normalized_input_value = $this->get_input_value($relation_name);
394
+			if ($normalized_input_value && is_array($normalized_input_value)) {
395
+				$where_query_params = array(
396
+					$relation_obj->get_other_model()->primary_key_name() => array('NOT_IN', $normalized_input_value),
397
+				);
398
+			} else {
399
+				$where_query_params = array();
400
+			}
401
+			$this->_model_object->_remove_relations($relation_name, $where_query_params);
402
+			foreach ($normalized_input_value as $id) {
403
+				$this->_model_object->_add_relation_to($id, $relation_name);
404
+			}
405
+		}
406
+		return true;
407
+	}
408
+
409
+
410
+
411
+	/**
412
+	 * Gets the model of this model form
413
+	 *
414
+	 * @return EEM_Base
415
+	 */
416
+	public function get_model()
417
+	{
418
+		return $this->_model;
419
+	}
420
+
421
+
422
+
423
+	/**
424
+	 * Gets the model object for this model form, which was either set
425
+	 * upon construction (using the $options_array arg 'model_object'), by using
426
+	 * set_model_object($model_obj), or implicitly
427
+	 * when receive_form_submission($req_data) was called.
428
+	 *
429
+	 * @return EE_Base_Class
430
+	 */
431
+	public function get_model_object()
432
+	{
433
+		return $this->_model_object;
434
+	}
435
+
436
+
437
+
438
+	/**
439
+	 * gets teh default name of this form section if none is specified
440
+	 *
441
+	 * @return string
442
+	 */
443
+	protected function _set_default_name_if_empty()
444
+	{
445
+		if (! $this->_name) {
446
+			$default_name = str_replace("EEM_", "", get_class($this->_model)) . "_Model_Form";
447
+			$this->_name = $default_name;
448
+		}
449
+	}
450 450
 
451 451
 
452 452
 
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -40,7 +40,7 @@  discard block
 block discarded – undo
40 40
         if (isset($options_array['model']) && $options_array['model'] instanceof EEM_Base) {
41 41
             $this->_model = $options_array['model'];
42 42
         }
43
-        if (! $this->_model || ! $this->_model instanceof EEM_Base) {
43
+        if ( ! $this->_model || ! $this->_model instanceof EEM_Base) {
44 44
             throw new EE_Error(sprintf(__("Model Form Sections must first specify the _model property to be a subclass of EEM_Base",
45 45
                 "event_espresso")));
46 46
         }
@@ -319,7 +319,7 @@  discard block
 block discarded – undo
319 319
     {
320 320
         parent::_normalize($req_data);
321 321
         //create or set the model object, if it isn't already
322
-        if (! $this->_model_object) {
322
+        if ( ! $this->_model_object) {
323 323
             //check to see if the form indicates a PK, in which case we want to only retrieve it and update it
324 324
             $pk_name = $this->_model->primary_key_name();
325 325
             $model_obj = $this->_model->get_one_by_ID($this->get_input_value($pk_name));
@@ -344,7 +344,7 @@  discard block
 block discarded – undo
344 344
      */
345 345
     public function save()
346 346
     {
347
-        if (! $this->_model_object) {
347
+        if ( ! $this->_model_object) {
348 348
             throw new EE_Error(sprintf(__("Cannot save the model form's model object (model is '%s') because there is no model object set. You must either set it, or call receive_form_submission where it is set automatically",
349 349
                 "event_espresso"), get_class($this->_model)));
350 350
         }
@@ -442,8 +442,8 @@  discard block
 block discarded – undo
442 442
      */
443 443
     protected function _set_default_name_if_empty()
444 444
     {
445
-        if (! $this->_name) {
446
-            $default_name = str_replace("EEM_", "", get_class($this->_model)) . "_Model_Form";
445
+        if ( ! $this->_name) {
446
+            $default_name = str_replace("EEM_", "", get_class($this->_model))."_Model_Form";
447 447
             $this->_name = $default_name;
448 448
         }
449 449
     }
Please login to merge, or discard this patch.
libraries/form_sections/payment_methods/EE_Payment_Method_Form.form.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -119,7 +119,7 @@
 block discarded – undo
119 119
 
120 120
 
121 121
     /**
122
-     * @param $payment_method_type
122
+     * @param EE_PMT_Base $payment_method_type
123 123
      * @throws EE_Error
124 124
      */
125 125
     public function set_payment_method_type($payment_method_type)
Please login to merge, or discard this patch.
Indentation   +185 added lines, -185 removed lines patch added patch discarded remove patch
@@ -9,189 +9,189 @@
 block discarded – undo
9 9
 class EE_Payment_Method_Form extends EE_Model_Form_Section
10 10
 {
11 11
 
12
-    /**
13
-     * All the subsection inputs that correspond ot extra meta rows
14
-     * for this payment method
15
-     *
16
-     * @var EE_Form_Input_Base[]
17
-     */
18
-    protected $_extra_meta_inputs = array();
19
-
20
-    /**
21
-     * Because payment method form might DELAY part of construction, we want to remember
22
-     * what options were passed in
23
-     *
24
-     * @var array
25
-     */
26
-    protected $_options_array = array();
27
-
28
-    /**
29
-     * The payment method type for this form
30
-     *
31
-     * @var EE_PMT_Base
32
-     */
33
-    protected $_payment_method_type;
34
-
35
-
36
-
37
-    /**
38
-     * @param array      $options_array       {
39
-     * @type string      $extra_meta_inputs   should be EE_Form_Section_Validatable[] which
40
-     *                                        will be _subsections and will be saved as extra meta on the payment
41
-     *                                        method object;
42
-     * @type EE_PMT_Base $payment_method_type the payment method type this form is for
43
-     * @see EE_Model_Form_Section::__construct() for more
44
-     *                                        }
45
-     */
46
-    public function __construct($options_array = array())
47
-    {
48
-        $this->_model = EEM_Payment_Method::instance();
49
-        $this->_options_array = $options_array;
50
-        if (isset($options_array['payment_method_type'])) {
51
-            $this->_payment_method_type = $options_array['payment_method_type'];
52
-        }
53
-        $options_array = $this->_options_array;
54
-        if (isset($options_array['extra_meta_inputs'])) {
55
-            $this->_extra_meta_inputs = array_merge($this->_extra_meta_inputs, $options_array['extra_meta_inputs']);
56
-        }
57
-        if ($this->_extra_meta_inputs) {
58
-            $this->_subsections = array_merge($this->_subsections, $this->_extra_meta_inputs);
59
-        }
60
-        $this->_subsections['PMD_button_url'] = new EE_Admin_File_Uploader_Input(
61
-            array('html_label_text' => __('Button URL', 'event_espresso'))
62
-        );
63
-        $this->_subsections['PMD_scope'] = new EE_Checkbox_Multi_Input(
64
-            EEM_Payment_Method::instance()->scopes(),
65
-            array(
66
-                'html_label_text' => $this->_model->field_settings_for('PMD_scope')->get_nicename()
67
-                                     . EEH_Template::get_help_tab_link('payment_methods_overview'),
68
-            )
69
-        );
70
-        //setup the currency options
71
-        $this->_subsections['Currency'] = new EE_Select_Multi_Model_Input(
72
-            EEM_Currency::instance()->get_all_currencies_usable_by($this->_payment_method_type),
73
-            array(
74
-                'html_label_text' => __('Currencies Supported', 'event_espresso'),
75
-                'required'        => true,
76
-            )
77
-        );
78
-        $this->_subsections['PMD_order'] = new EE_Text_Input(array(
79
-            'html_label_text'        => __('Order', 'event_espresso'),
80
-            'html_help_text'         => __('Lowest numbers will be shown first', 'event_espresso'),
81
-            'normalization_strategy' => new EE_Int_Normalization(),
82
-            'validation_strategies'  => array(
83
-                new EE_Int_Validation_Strategy(),
84
-            ),
85
-            'default'                => 0,
86
-        ));
87
-        $this->_layout_strategy = new EE_Admin_Two_Column_Layout();
88
-        parent::__construct($options_array);
89
-        $debug_mode = isset($this->_subsections['PMD_debug_mode']) ? $this->_subsections['PMD_debug_mode'] : null;
90
-        if ($debug_mode instanceof EE_Form_Input_Base) {
91
-            $debug_mode->set_html_help_text(__('This payment method has a Sandbox Server (also known as Testing Server, Development Server, Quality Assurance Server, etc). While in debug mode and using this sandbox server, real payments will not be processed.',
92
-                'event_espresso'));
93
-        }
94
-    }
95
-
96
-
97
-
98
-    /**
99
-     * Finishes construction given the parent form section and this form section's name
100
-     *
101
-     * @param EE_Form_Section_Proper $parent_form_section
102
-     * @param string                 $name
103
-     * @throws EE_Error
104
-     */
105
-    public function _construct_finalize($parent_form_section, $name)
106
-    {
107
-        if (! $this->_payment_method_type instanceof EE_PMT_Base) {
108
-            throw new EE_Error(sprintf(__('Payment Method forms must have set their payment method type BEFORE calling _construct_finalize',
109
-                'event_espresso')));
110
-        }
111
-        //set the name of this form based on the payment method type
112
-        if (! $this->_name && ! $name) {
113
-            $name = str_replace(" ", "_", ucwords(str_replace("_", " ", ($this->_payment_method_type->system_name()))))
114
-                    . "_Settings_Form";
115
-        }
116
-        parent::_construct_finalize($parent_form_section, $name);
117
-    }
118
-
119
-
120
-
121
-    /**
122
-     * @param $payment_method_type
123
-     * @throws EE_Error
124
-     */
125
-    public function set_payment_method_type($payment_method_type)
126
-    {
127
-        if (! $payment_method_type instanceof EE_PMT_Base) {
128
-            throw new EE_Error(sprintf(__("Payment Method forms MUST set a payment method type by using _set_payment_method_type",
129
-                "event_espresso")));
130
-        }
131
-        $this->_payment_method_type = $payment_method_type;
132
-    }
133
-
134
-
135
-
136
-    /**
137
-     * extends the model form section's save method to also save the extra meta field values
138
-     *
139
-     * @return int ID of the payment method inserted, or true on update
140
-     */
141
-    public function save()
142
-    {
143
-        $parent_save_val = parent::save();
144
-        if ($this->_model_object && $this->_model_object->ID()) {
145
-            foreach ($this->_extra_meta_inputs as $input_name => $input) {
146
-                $this->_model_object->update_extra_meta($input_name, $input->normalized_value());
147
-            }
148
-        }
149
-        return $parent_save_val;
150
-    }
151
-
152
-
153
-
154
-    /**
155
-     * Overrides parent's populate_model_obj to also populate the extra meta fields
156
-     *
157
-     * @param EE_Base_Class $model_obj
158
-     */
159
-    public function populate_model_obj($model_obj)
160
-    {
161
-        $model_obj = $this->_model->ensure_is_obj($model_obj);
162
-        parent::populate_model_obj($model_obj);
163
-        $extra_meta = $model_obj->all_extra_meta_array();
164
-        foreach ($this->_extra_meta_inputs as $input_name => $extra_meta_input) {
165
-            if (isset($extra_meta[$input_name])) {
166
-                $extra_meta_input->set_default($extra_meta[$input_name]);
167
-            }
168
-        }
169
-    }
170
-
171
-
172
-
173
-    /**
174
-     * gets the default name of this form section if none is specified
175
-     *
176
-     * @return string
177
-     */
178
-    protected function _set_default_name_if_empty()
179
-    {
180
-        if (! $this->_name) {
181
-            $default_name = str_replace("EEM_", "", get_class($this->_model)) . "_Model_Form";
182
-            $this->_name = $default_name;
183
-        }
184
-    }
185
-
186
-
187
-
188
-    /**
189
-     * Gets all the extra meta inputs in this form
190
-     *
191
-     * @return EE_Form_Input_Base[]
192
-     */
193
-    public function extra_meta_inputs()
194
-    {
195
-        return $this->_extra_meta_inputs;
196
-    }
12
+	/**
13
+	 * All the subsection inputs that correspond ot extra meta rows
14
+	 * for this payment method
15
+	 *
16
+	 * @var EE_Form_Input_Base[]
17
+	 */
18
+	protected $_extra_meta_inputs = array();
19
+
20
+	/**
21
+	 * Because payment method form might DELAY part of construction, we want to remember
22
+	 * what options were passed in
23
+	 *
24
+	 * @var array
25
+	 */
26
+	protected $_options_array = array();
27
+
28
+	/**
29
+	 * The payment method type for this form
30
+	 *
31
+	 * @var EE_PMT_Base
32
+	 */
33
+	protected $_payment_method_type;
34
+
35
+
36
+
37
+	/**
38
+	 * @param array      $options_array       {
39
+	 * @type string      $extra_meta_inputs   should be EE_Form_Section_Validatable[] which
40
+	 *                                        will be _subsections and will be saved as extra meta on the payment
41
+	 *                                        method object;
42
+	 * @type EE_PMT_Base $payment_method_type the payment method type this form is for
43
+	 * @see EE_Model_Form_Section::__construct() for more
44
+	 *                                        }
45
+	 */
46
+	public function __construct($options_array = array())
47
+	{
48
+		$this->_model = EEM_Payment_Method::instance();
49
+		$this->_options_array = $options_array;
50
+		if (isset($options_array['payment_method_type'])) {
51
+			$this->_payment_method_type = $options_array['payment_method_type'];
52
+		}
53
+		$options_array = $this->_options_array;
54
+		if (isset($options_array['extra_meta_inputs'])) {
55
+			$this->_extra_meta_inputs = array_merge($this->_extra_meta_inputs, $options_array['extra_meta_inputs']);
56
+		}
57
+		if ($this->_extra_meta_inputs) {
58
+			$this->_subsections = array_merge($this->_subsections, $this->_extra_meta_inputs);
59
+		}
60
+		$this->_subsections['PMD_button_url'] = new EE_Admin_File_Uploader_Input(
61
+			array('html_label_text' => __('Button URL', 'event_espresso'))
62
+		);
63
+		$this->_subsections['PMD_scope'] = new EE_Checkbox_Multi_Input(
64
+			EEM_Payment_Method::instance()->scopes(),
65
+			array(
66
+				'html_label_text' => $this->_model->field_settings_for('PMD_scope')->get_nicename()
67
+									 . EEH_Template::get_help_tab_link('payment_methods_overview'),
68
+			)
69
+		);
70
+		//setup the currency options
71
+		$this->_subsections['Currency'] = new EE_Select_Multi_Model_Input(
72
+			EEM_Currency::instance()->get_all_currencies_usable_by($this->_payment_method_type),
73
+			array(
74
+				'html_label_text' => __('Currencies Supported', 'event_espresso'),
75
+				'required'        => true,
76
+			)
77
+		);
78
+		$this->_subsections['PMD_order'] = new EE_Text_Input(array(
79
+			'html_label_text'        => __('Order', 'event_espresso'),
80
+			'html_help_text'         => __('Lowest numbers will be shown first', 'event_espresso'),
81
+			'normalization_strategy' => new EE_Int_Normalization(),
82
+			'validation_strategies'  => array(
83
+				new EE_Int_Validation_Strategy(),
84
+			),
85
+			'default'                => 0,
86
+		));
87
+		$this->_layout_strategy = new EE_Admin_Two_Column_Layout();
88
+		parent::__construct($options_array);
89
+		$debug_mode = isset($this->_subsections['PMD_debug_mode']) ? $this->_subsections['PMD_debug_mode'] : null;
90
+		if ($debug_mode instanceof EE_Form_Input_Base) {
91
+			$debug_mode->set_html_help_text(__('This payment method has a Sandbox Server (also known as Testing Server, Development Server, Quality Assurance Server, etc). While in debug mode and using this sandbox server, real payments will not be processed.',
92
+				'event_espresso'));
93
+		}
94
+	}
95
+
96
+
97
+
98
+	/**
99
+	 * Finishes construction given the parent form section and this form section's name
100
+	 *
101
+	 * @param EE_Form_Section_Proper $parent_form_section
102
+	 * @param string                 $name
103
+	 * @throws EE_Error
104
+	 */
105
+	public function _construct_finalize($parent_form_section, $name)
106
+	{
107
+		if (! $this->_payment_method_type instanceof EE_PMT_Base) {
108
+			throw new EE_Error(sprintf(__('Payment Method forms must have set their payment method type BEFORE calling _construct_finalize',
109
+				'event_espresso')));
110
+		}
111
+		//set the name of this form based on the payment method type
112
+		if (! $this->_name && ! $name) {
113
+			$name = str_replace(" ", "_", ucwords(str_replace("_", " ", ($this->_payment_method_type->system_name()))))
114
+					. "_Settings_Form";
115
+		}
116
+		parent::_construct_finalize($parent_form_section, $name);
117
+	}
118
+
119
+
120
+
121
+	/**
122
+	 * @param $payment_method_type
123
+	 * @throws EE_Error
124
+	 */
125
+	public function set_payment_method_type($payment_method_type)
126
+	{
127
+		if (! $payment_method_type instanceof EE_PMT_Base) {
128
+			throw new EE_Error(sprintf(__("Payment Method forms MUST set a payment method type by using _set_payment_method_type",
129
+				"event_espresso")));
130
+		}
131
+		$this->_payment_method_type = $payment_method_type;
132
+	}
133
+
134
+
135
+
136
+	/**
137
+	 * extends the model form section's save method to also save the extra meta field values
138
+	 *
139
+	 * @return int ID of the payment method inserted, or true on update
140
+	 */
141
+	public function save()
142
+	{
143
+		$parent_save_val = parent::save();
144
+		if ($this->_model_object && $this->_model_object->ID()) {
145
+			foreach ($this->_extra_meta_inputs as $input_name => $input) {
146
+				$this->_model_object->update_extra_meta($input_name, $input->normalized_value());
147
+			}
148
+		}
149
+		return $parent_save_val;
150
+	}
151
+
152
+
153
+
154
+	/**
155
+	 * Overrides parent's populate_model_obj to also populate the extra meta fields
156
+	 *
157
+	 * @param EE_Base_Class $model_obj
158
+	 */
159
+	public function populate_model_obj($model_obj)
160
+	{
161
+		$model_obj = $this->_model->ensure_is_obj($model_obj);
162
+		parent::populate_model_obj($model_obj);
163
+		$extra_meta = $model_obj->all_extra_meta_array();
164
+		foreach ($this->_extra_meta_inputs as $input_name => $extra_meta_input) {
165
+			if (isset($extra_meta[$input_name])) {
166
+				$extra_meta_input->set_default($extra_meta[$input_name]);
167
+			}
168
+		}
169
+	}
170
+
171
+
172
+
173
+	/**
174
+	 * gets the default name of this form section if none is specified
175
+	 *
176
+	 * @return string
177
+	 */
178
+	protected function _set_default_name_if_empty()
179
+	{
180
+		if (! $this->_name) {
181
+			$default_name = str_replace("EEM_", "", get_class($this->_model)) . "_Model_Form";
182
+			$this->_name = $default_name;
183
+		}
184
+	}
185
+
186
+
187
+
188
+	/**
189
+	 * Gets all the extra meta inputs in this form
190
+	 *
191
+	 * @return EE_Form_Input_Base[]
192
+	 */
193
+	public function extra_meta_inputs()
194
+	{
195
+		return $this->_extra_meta_inputs;
196
+	}
197 197
 }
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -104,12 +104,12 @@  discard block
 block discarded – undo
104 104
      */
105 105
     public function _construct_finalize($parent_form_section, $name)
106 106
     {
107
-        if (! $this->_payment_method_type instanceof EE_PMT_Base) {
107
+        if ( ! $this->_payment_method_type instanceof EE_PMT_Base) {
108 108
             throw new EE_Error(sprintf(__('Payment Method forms must have set their payment method type BEFORE calling _construct_finalize',
109 109
                 'event_espresso')));
110 110
         }
111 111
         //set the name of this form based on the payment method type
112
-        if (! $this->_name && ! $name) {
112
+        if ( ! $this->_name && ! $name) {
113 113
             $name = str_replace(" ", "_", ucwords(str_replace("_", " ", ($this->_payment_method_type->system_name()))))
114 114
                     . "_Settings_Form";
115 115
         }
@@ -124,7 +124,7 @@  discard block
 block discarded – undo
124 124
      */
125 125
     public function set_payment_method_type($payment_method_type)
126 126
     {
127
-        if (! $payment_method_type instanceof EE_PMT_Base) {
127
+        if ( ! $payment_method_type instanceof EE_PMT_Base) {
128 128
             throw new EE_Error(sprintf(__("Payment Method forms MUST set a payment method type by using _set_payment_method_type",
129 129
                 "event_espresso")));
130 130
         }
@@ -177,8 +177,8 @@  discard block
 block discarded – undo
177 177
      */
178 178
     protected function _set_default_name_if_empty()
179 179
     {
180
-        if (! $this->_name) {
181
-            $default_name = str_replace("EEM_", "", get_class($this->_model)) . "_Model_Form";
180
+        if ( ! $this->_name) {
181
+            $default_name = str_replace("EEM_", "", get_class($this->_model))."_Model_Form";
182 182
             $this->_name = $default_name;
183 183
         }
184 184
     }
Please login to merge, or discard this patch.