Completed
Branch FET-10325-remove-caffeinated-m... (ba33af)
by
unknown
34:17 queued 23:38
created
core/db_models/fields/EE_Datetime_Field.php 3 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -570,7 +570,7 @@  discard block
 block discarded – undo
570 570
      * allowed)
571 571
      *
572 572
      * @param string $datetime_string mysql timestamp in UTC
573
-     * @return  mixed null | DateTime
573
+     * @return  null|DbSafeDateTime null | DateTime
574 574
      * @throws \EE_Error
575 575
      */
576 576
     public function prepare_for_set_from_db($datetime_string)
@@ -708,7 +708,7 @@  discard block
 block discarded – undo
708 708
      *
709 709
      * @param \DateTimeZone $DateTimeZone
710 710
      * @param int           $time
711
-     * @return mixed
711
+     * @return string
712 712
      */
713 713
     public function get_timezone_offset(DateTimeZone $DateTimeZone, $time = null)
714 714
     {
Please login to merge, or discard this patch.
Indentation   +729 added lines, -729 removed lines patch added patch discarded remove patch
@@ -1,7 +1,7 @@  discard block
 block discarded – undo
1 1
 <?php use EventEspresso\core\domain\entities\DbSafeDateTime;
2 2
 
3 3
 if (! defined('EVENT_ESPRESSO_VERSION')) {
4
-    exit('No direct script access allowed');
4
+	exit('No direct script access allowed');
5 5
 }
6 6
 
7 7
 /**
@@ -16,734 +16,734 @@  discard block
 block discarded – undo
16 16
 class EE_Datetime_Field extends EE_Model_Field_Base
17 17
 {
18 18
 
19
-    /**
20
-     * The pattern we're looking for is if only the characters 0-9 are found and there are only
21
-     * 10 or more numbers (because 9 numbers even with all 9's would be sometime in 2001 )
22
-     *
23
-     * @type string unix_timestamp_regex
24
-     */
25
-    const unix_timestamp_regex = '/[0-9]{10,}/';
26
-
27
-    /**
28
-     * @type string mysql_timestamp_format
29
-     */
30
-    const mysql_timestamp_format = 'Y-m-d H:i:s';
31
-
32
-    /**
33
-     * @type string mysql_date_format
34
-     */
35
-    const mysql_date_format = 'Y-m-d';
36
-
37
-    /**
38
-     * @type string mysql_time_format
39
-     */
40
-    const mysql_time_format = 'H:i:s';
41
-
42
-    /**
43
-     * Const for using in the default value. If the field's default is set to this,
44
-     * then we will return the time of calling `get_default_value()`, not
45
-     * just the current time at construction
46
-     */
47
-    const now = 'now';
48
-
49
-    /**
50
-     * The following properties hold the default formats for date and time.
51
-     * Defaults are set via the constructor and can be overridden on class instantiation.
52
-     * However they can also be overridden later by the set_format() method
53
-     * (and corresponding set_date_format, set_time_format methods);
54
-     */
55
-    /**
56
-     * @type string $_date_format
57
-     */
58
-    protected $_date_format = '';
59
-
60
-    /**
61
-     * @type string $_time_format
62
-     */
63
-    protected $_time_format = '';
64
-
65
-    /**
66
-     * @type string $_pretty_date_format
67
-     */
68
-    protected $_pretty_date_format = '';
69
-
70
-    /**
71
-     * @type string $_pretty_time_format
72
-     */
73
-    protected $_pretty_time_format = '';
74
-
75
-    /**
76
-     * @type DateTimeZone $_DateTimeZone
77
-     */
78
-    protected $_DateTimeZone;
79
-
80
-    /**
81
-     * @type DateTimeZone $_UTC_DateTimeZone
82
-     */
83
-    protected $_UTC_DateTimeZone;
84
-
85
-    /**
86
-     * @type DateTimeZone $_blog_DateTimeZone
87
-     */
88
-    protected $_blog_DateTimeZone;
89
-
90
-
91
-    /**
92
-     * This property holds how we want the output returned when getting a datetime string.  It is set for the
93
-     * set_date_time_output() method.  By default this is empty.  When empty, we are assuming that we want both date
94
-     * and time returned via getters.
95
-     *
96
-     * @var mixed (null|string)
97
-     */
98
-    protected $_date_time_output;
99
-
100
-
101
-    /**
102
-     * timezone string
103
-     * This gets set by the constructor and can be changed by the "set_timezone()" method so that we know what timezone
104
-     * incoming strings|timestamps are in.  This can also be used before a get to set what timezone you want strings
105
-     * coming out of the object to be in.  Default timezone is the current WP timezone option setting
106
-     *
107
-     * @var string
108
-     */
109
-    protected $_timezone_string;
110
-
111
-
112
-    /**
113
-     * This holds whatever UTC offset for the blog (we automatically convert timezone strings into their related
114
-     * offsets for comparison purposes).
115
-     *
116
-     * @var int
117
-     */
118
-    protected $_blog_offset;
119
-
120
-
121
-    /**
122
-     * @param string $table_column
123
-     * @param string $nice_name
124
-     * @param bool   $nullable
125
-     * @param string $default_value
126
-     * @param string $timezone_string
127
-     * @param string $date_format
128
-     * @param string $time_format
129
-     * @param string $pretty_date_format
130
-     * @param string $pretty_time_format
131
-     * @throws \EE_Error
132
-     */
133
-    public function __construct(
134
-        $table_column,
135
-        $nice_name,
136
-        $nullable,
137
-        $default_value,
138
-        $timezone_string = '',
139
-        $date_format = '',
140
-        $time_format = '',
141
-        $pretty_date_format = '',
142
-        $pretty_time_format = ''
143
-    ) {
144
-
145
-        $this->_date_format        = ! empty($date_format) ? $date_format : get_option('date_format');
146
-        $this->_time_format        = ! empty($time_format) ? $time_format : get_option('time_format');
147
-        $this->_pretty_date_format = ! empty($pretty_date_format) ? $pretty_date_format : get_option('date_format');
148
-        $this->_pretty_time_format = ! empty($pretty_time_format) ? $pretty_time_format : get_option('time_format');
149
-
150
-        parent::__construct($table_column, $nice_name, $nullable, $default_value);
151
-        $this->set_timezone($timezone_string);
152
-
153
-    }
154
-
155
-
156
-    /**
157
-     * @return string
158
-     */
159
-    public function get_wpdb_data_type()
160
-    {
161
-        return '%s';
162
-    }
163
-
164
-
165
-    /**
166
-     * @return DateTimeZone
167
-     * @throws \EE_Error
168
-     */
169
-    public function get_UTC_DateTimeZone()
170
-    {
171
-        return $this->_UTC_DateTimeZone instanceof DateTimeZone
172
-            ? $this->_UTC_DateTimeZone
173
-            : $this->_create_timezone_object_from_timezone_string('UTC');
174
-    }
175
-
176
-
177
-    /**
178
-     * @return DateTimeZone
179
-     * @throws \EE_Error
180
-     */
181
-    public function get_blog_DateTimeZone()
182
-    {
183
-        return $this->_blog_DateTimeZone instanceof DateTimeZone
184
-            ? $this->_blog_DateTimeZone
185
-            : $this->_create_timezone_object_from_timezone_string('');
186
-    }
187
-
188
-
189
-    /**
190
-     * this prepares any incoming date data and make sure its converted to a utc unix timestamp
191
-     *
192
-     * @param  string|int $value_inputted_for_field_on_model_object could be a string formatted date time or int unix
193
-     *                                                              timestamp
194
-     * @return DateTime
195
-     */
196
-    public function prepare_for_set($value_inputted_for_field_on_model_object)
197
-    {
198
-        return $this->_get_date_object($value_inputted_for_field_on_model_object);
199
-    }
200
-
201
-
202
-    /**
203
-     * This returns the format string to be used by getters depending on what the $_date_time_output property is set at.
204
-     * getters need to know whether we're just returning the date or the time or both.  By default we return both.
205
-     *
206
-     * @param bool $pretty If we're returning the pretty formats or standard format string.
207
-     * @return string    The final assembled format string.
208
-     */
209
-    protected function _get_date_time_output($pretty = false)
210
-    {
211
-
212
-        switch ($this->_date_time_output) {
213
-            case 'time' :
214
-                return $pretty ? $this->_pretty_time_format : $this->_time_format;
215
-                break;
216
-
217
-            case 'date' :
218
-                return $pretty ? $this->_pretty_date_format : $this->_date_format;
219
-                break;
220
-
221
-            default :
222
-                return $pretty
223
-                    ? $this->_pretty_date_format . ' ' . $this->_pretty_time_format
224
-                    : $this->_date_format . ' ' . $this->_time_format;
225
-        }
226
-    }
227
-
228
-
229
-    /**
230
-     * This just sets the $_date_time_output property so we can flag how date and times are formatted before being
231
-     * returned (using the format properties)
232
-     *
233
-     * @param string $what acceptable values are 'time' or 'date'.
234
-     *                     Any other value will be set but will always result
235
-     *                     in both 'date' and 'time' being returned.
236
-     * @return void
237
-     */
238
-    public function set_date_time_output($what = null)
239
-    {
240
-        $this->_date_time_output = $what;
241
-    }
242
-
243
-
244
-    /**
245
-     * See $_timezone property for description of what the timezone property is for.  This SETS the timezone internally
246
-     * for being able to reference what timezone we are running conversions on when converting TO the internal timezone
247
-     * (UTC Unix Timestamp) for the object OR when converting FROM the internal timezone (UTC Unix Timestamp).
248
-     * We also set some other properties in this method.
249
-     *
250
-     * @param string $timezone_string A valid timezone string as described by @link
251
-     *                                http://www.php.net/manual/en/timezones.php
252
-     * @return void
253
-     * @throws \EE_Error
254
-     */
255
-    public function set_timezone($timezone_string)
256
-    {
257
-        if (empty($timezone_string) && $this->_timezone_string !== null) {
258
-            // leave the timezone AS-IS if we already have one and
259
-            // the function arg didn't provide one
260
-            return;
261
-        }
262
-        $timezone_string        = EEH_DTT_Helper::get_valid_timezone_string($timezone_string);
263
-        $this->_timezone_string = ! empty($timezone_string) ? $timezone_string : 'UTC';
264
-        $this->_DateTimeZone    = $this->_create_timezone_object_from_timezone_string($this->_timezone_string);
265
-    }
266
-
267
-
268
-    /**
269
-     * _create_timezone_object_from_timezone_name
270
-     *
271
-     * @access protected
272
-     * @param string $timezone_string
273
-     * @return \DateTimeZone
274
-     * @throws \EE_Error
275
-     */
276
-    protected function _create_timezone_object_from_timezone_string($timezone_string = '')
277
-    {
278
-        return new DateTimeZone(EEH_DTT_Helper::get_valid_timezone_string($timezone_string));
279
-    }
280
-
281
-
282
-    /**
283
-     * This just returns whatever is set for the current timezone.
284
-     *
285
-     * @access public
286
-     * @return string timezone string
287
-     */
288
-    public function get_timezone()
289
-    {
290
-        return $this->_timezone_string;
291
-    }
292
-
293
-
294
-    /**
295
-     * set the $_date_format property
296
-     *
297
-     * @access public
298
-     * @param string $format a new date format (corresponding to formats accepted by PHP date() function)
299
-     * @param bool   $pretty Whether to set pretty format or not.
300
-     * @return void
301
-     */
302
-    public function set_date_format($format, $pretty = false)
303
-    {
304
-        if ($pretty) {
305
-            $this->_pretty_date_format = $format;
306
-        } else {
307
-            $this->_date_format = $format;
308
-        }
309
-    }
310
-
311
-
312
-    /**
313
-     * return the $_date_format property value.
314
-     *
315
-     * @param bool $pretty Whether to get pretty format or not.
316
-     * @return string
317
-     */
318
-    public function get_date_format($pretty = false)
319
-    {
320
-        return $pretty ? $this->_pretty_date_format : $this->_date_format;
321
-    }
322
-
323
-
324
-    /**
325
-     * set the $_time_format property
326
-     *
327
-     * @access public
328
-     * @param string $format a new time format (corresponding to formats accepted by PHP date() function)
329
-     * @param bool   $pretty Whether to set pretty format or not.
330
-     * @return void
331
-     */
332
-    public function set_time_format($format, $pretty = false)
333
-    {
334
-        if ($pretty) {
335
-            $this->_pretty_time_format = $format;
336
-        } else {
337
-            $this->_time_format = $format;
338
-        }
339
-    }
340
-
341
-
342
-    /**
343
-     * return the $_time_format property value.
344
-     *
345
-     * @param bool $pretty Whether to get pretty format or not.
346
-     * @return string
347
-     */
348
-    public function get_time_format($pretty = false)
349
-    {
350
-        return $pretty ? $this->_pretty_time_format : $this->_time_format;
351
-    }
352
-
353
-
354
-    /**
355
-     * set the $_pretty_date_format property
356
-     *
357
-     * @access public
358
-     * @param string $format a new pretty date format (corresponding to formats accepted by PHP date() function)
359
-     * @return void
360
-     */
361
-    public function set_pretty_date_format($format)
362
-    {
363
-        $this->_pretty_date_format = $format;
364
-    }
365
-
366
-
367
-    /**
368
-     * set the $_pretty_time_format property
369
-     *
370
-     * @access public
371
-     * @param string $format a new pretty time format (corresponding to formats accepted by PHP date() function)
372
-     * @return void
373
-     */
374
-    public function set_pretty_time_format($format)
375
-    {
376
-        $this->_pretty_time_format = $format;
377
-    }
378
-
379
-
380
-    /**
381
-     * Only sets the time portion of the datetime.
382
-     *
383
-     * @param string|DateTime $time_to_set_string like 8am OR a DateTime object.
384
-     * @param DateTime        $current            current DateTime object for the datetime field
385
-     * @return DateTime
386
-     */
387
-    public function prepare_for_set_with_new_time($time_to_set_string, DateTime $current)
388
-    {
389
-        // if $time_to_set_string is datetime object, then let's use it to set the parse array.
390
-        // Otherwise parse the string.
391
-        if ($time_to_set_string instanceof DateTime) {
392
-            $parsed = array(
393
-                'hour'   => $time_to_set_string->format('H'),
394
-                'minute' => $time_to_set_string->format('i'),
395
-                'second' => $time_to_set_string->format('s'),
396
-            );
397
-        } else {
398
-            //parse incoming string
399
-            $parsed = date_parse_from_format($this->_time_format, $time_to_set_string);
400
-        }
401
-
402
-        //make sure $current is in the correct timezone.
403
-        $current->setTimezone($this->_DateTimeZone);
404
-
405
-        return $current->setTime($parsed['hour'], $parsed['minute'], $parsed['second']);
406
-    }
407
-
408
-
409
-    /**
410
-     * Only sets the date portion of the datetime.
411
-     *
412
-     * @param string|DateTime $date_to_set_string like Friday, January 8th or a DateTime object.
413
-     * @param DateTime        $current            current DateTime object for the datetime field
414
-     * @return DateTime
415
-     */
416
-    public function prepare_for_set_with_new_date($date_to_set_string, DateTime $current)
417
-    {
418
-        // if $time_to_set_string is datetime object, then let's use it to set the parse array.
419
-        // Otherwise parse the string.
420
-        if ($date_to_set_string instanceof DateTime) {
421
-            $parsed = array(
422
-                'year'  => $date_to_set_string->format('Y'),
423
-                'month' => $date_to_set_string->format('m'),
424
-                'day'   => $date_to_set_string->format('d'),
425
-            );
426
-        } else {
427
-            //parse incoming string
428
-            $parsed = date_parse_from_format($this->_date_format, $date_to_set_string);
429
-        }
430
-
431
-        //make sure $current is in the correct timezone
432
-        $current->setTimezone($this->_DateTimeZone);
433
-
434
-        return $current->setDate($parsed['year'], $parsed['month'], $parsed['day']);
435
-    }
436
-
437
-
438
-    /**
439
-     * This prepares the EE_DateTime value to be saved to the db as mysql timestamp (UTC +0 timezone).  When the
440
-     * datetime gets to this stage it should ALREADY be in UTC time
441
-     *
442
-     * @param  DateTime $DateTime
443
-     * @return string formatted date time for given timezone
444
-     * @throws \EE_Error
445
-     */
446
-    public function prepare_for_get($DateTime)
447
-    {
448
-        return $this->_prepare_for_display($DateTime);
449
-    }
450
-
451
-
452
-    /**
453
-     * This differs from prepare_for_get in that it considers whether the internal $_timezone differs
454
-     * from the set wp timezone.  If so, then it returns the datetime string formatted via
455
-     * _pretty_date_format, and _pretty_time_format.  However, it also appends a timezone
456
-     * abbreviation to the date_string.
457
-     *
458
-     * @param mixed $DateTime
459
-     * @param null  $schema
460
-     * @return string
461
-     * @throws \EE_Error
462
-     */
463
-    public function prepare_for_pretty_echoing($DateTime, $schema = null)
464
-    {
465
-        return $this->_prepare_for_display($DateTime, $schema ? $schema : true);
466
-    }
467
-
468
-
469
-    /**
470
-     * This prepares the EE_DateTime value to be saved to the db as mysql timestamp (UTC +0
471
-     * timezone).
472
-     *
473
-     * @param DateTime    $DateTime
474
-     * @param bool|string $schema
475
-     * @return string
476
-     * @throws \EE_Error
477
-     */
478
-    protected function _prepare_for_display($DateTime, $schema = false)
479
-    {
480
-        if (! $DateTime instanceof DateTime) {
481
-            if ($this->_nullable) {
482
-                return '';
483
-            } else {
484
-                if (WP_DEBUG) {
485
-                    throw new EE_Error(
486
-                        sprintf(
487
-                            __(
488
-                                'EE_Datetime_Field::_prepare_for_display requires a DateTime class to be the value for the $DateTime argument because the %s field is not nullable.',
489
-                                'event_espresso'
490
-                            ),
491
-                            $this->_nicename
492
-                        )
493
-                    );
494
-                } else {
495
-                    $DateTime = new DbSafeDateTime(\EE_Datetime_Field::now);
496
-                    EE_Error::add_error(
497
-                        sprintf(
498
-                            __(
499
-                                'EE_Datetime_Field::_prepare_for_display requires a DateTime class to be the value for the $DateTime argument because the %s field is not nullable.  When WP_DEBUG is false, the value is set to "now" instead of throwing an exception.',
500
-                                'event_espresso'
501
-                            ),
502
-                            $this->_nicename
503
-                        )
504
-                    );
505
-                }
506
-            }
507
-        }
508
-        $format_string = $this->_get_date_time_output($schema);
509
-        //make sure datetime_value is in the correct timezone (in case that's been updated).
510
-        $DateTime->setTimezone($this->_DateTimeZone);
511
-        if ($schema) {
512
-            if ($this->_display_timezone()) {
513
-                //must be explicit because schema could equal true.
514
-                if ($schema === 'no_html') {
515
-                    $timezone_string = ' (' . $DateTime->format('T') . ')';
516
-                } else {
517
-                    $timezone_string = ' <span class="ee_dtt_timezone_string">(' . $DateTime->format('T') . ')</span>';
518
-                }
519
-            } else {
520
-                $timezone_string = '';
521
-            }
522
-
523
-            return $DateTime->format($format_string) . $timezone_string;
524
-        } else {
525
-            return $DateTime->format($format_string);
526
-        }
527
-    }
528
-
529
-
530
-    /**
531
-     * This prepares the EE_DateTime value to be saved to the db as mysql timestamp (UTC +0
532
-     * timezone).
533
-     *
534
-     * @param  mixed $datetime_value u
535
-     * @return string mysql timestamp in UTC
536
-     * @throws \EE_Error
537
-     */
538
-    public function prepare_for_use_in_db($datetime_value)
539
-    {
540
-        //we allow an empty value or DateTime object, but nothing else.
541
-        if (! empty($datetime_value) && ! $datetime_value instanceof DateTime) {
542
-            throw new EE_Error(
543
-                __(
544
-                    'The incoming value being prepared for setting in the database must either be empty or a php DateTime object',
545
-                    'event_espresso'
546
-                )
547
-            );
548
-        }
549
-
550
-        if ($datetime_value instanceof DateTime) {
551
-            if ( ! $datetime_value instanceof DbSafeDateTime) {
552
-                $datetime_value = DbSafeDateTime::createFromDateTime($datetime_value);
553
-            }
554
-
555
-            return $datetime_value->setTimezone($this->get_UTC_DateTimeZone())->format(
556
-                EE_Datetime_Field::mysql_timestamp_format
557
-            );
558
-        }
559
-
560
-        // if $datetime_value is empty, and ! $this->_nullable, use current_time() but set the GMT flag to true
561
-        return ! $this->_nullable && empty($datetime_value) ? current_time('mysql', true) : null;
562
-    }
563
-
564
-
565
-    /**
566
-     * This prepares the datetime for internal usage as a PHP DateTime object OR null (if nullable is
567
-     * allowed)
568
-     *
569
-     * @param string $datetime_string mysql timestamp in UTC
570
-     * @return  mixed null | DateTime
571
-     * @throws \EE_Error
572
-     */
573
-    public function prepare_for_set_from_db($datetime_string)
574
-    {
575
-        //if $datetime_value is empty, and ! $this->_nullable, just use time()
576
-        if (empty($datetime_string) && $this->_nullable) {
577
-            return null;
578
-        }
579
-        // datetime strings from the db should ALWAYS be in UTC+0, so use UTC_DateTimeZone when creating
580
-        if (empty($datetime_string)) {
581
-            $DateTime = new DbSafeDateTime(\EE_Datetime_Field::now, $this->get_UTC_DateTimeZone());
582
-        } else {
583
-            $DateTime = DateTime::createFromFormat(
584
-                EE_Datetime_Field::mysql_timestamp_format,
585
-                $datetime_string,
586
-                $this->get_UTC_DateTimeZone()
587
-            );
588
-            if ($DateTime instanceof \DateTime) {
589
-                $DateTime = new DbSafeDateTime(
590
-                    $DateTime->format(\EE_Datetime_Field::mysql_timestamp_format),
591
-                    $this->get_UTC_DateTimeZone()
592
-                );
593
-            }
594
-        }
595
-
596
-        if (! $DateTime instanceof DbSafeDateTime) {
597
-            // if still no datetime object, then let's just use now
598
-            $DateTime = new DbSafeDateTime(\EE_Datetime_Field::now, $this->get_UTC_DateTimeZone());
599
-        }
600
-        // THEN apply the field's set DateTimeZone
601
-        $DateTime->setTimezone($this->_DateTimeZone);
602
-
603
-        return $DateTime;
604
-    }
605
-
606
-
607
-    /**
608
-     * All this method does is determine if we're going to display the timezone string or not on any output.
609
-     * To determine this we check if the set timezone offset is different than the blog's set timezone offset.
610
-     * If so, then true.
611
-     *
612
-     * @return bool true for yes false for no
613
-     * @throws \EE_Error
614
-     */
615
-    protected function _display_timezone()
616
-    {
617
-
618
-        // first let's do a comparison of timezone strings.
619
-        // If they match then we can get out without any further calculations
620
-        $blog_string = get_option('timezone_string');
621
-        if ($blog_string === $this->_timezone_string) {
622
-            return false;
623
-        }
624
-        // now we need to calc the offset for the timezone string so we can compare with the blog offset.
625
-        $this_offset = $this->get_timezone_offset($this->_DateTimeZone);
626
-        $blog_offset = $this->get_timezone_offset($this->get_blog_DateTimeZone());
627
-        // now compare
628
-        return $blog_offset !== $this_offset;
629
-    }
630
-
631
-
632
-    /**
633
-     * This method returns a php DateTime object for setting on the EE_Base_Class model.
634
-     * EE passes around DateTime objects because they are MUCH easier to manipulate and deal
635
-     * with.
636
-     *
637
-     * @param int|string|DateTime $date_string            This should be the incoming date string.  It's assumed to be
638
-     *                                                    in the format that is set on the date_field (or DateTime
639
-     *                                                    object)!
640
-     * @return DateTime
641
-     */
642
-    protected function _get_date_object($date_string)
643
-    {
644
-        //first if this is an empty date_string and nullable is allowed, just return null.
645
-        if ($this->_nullable && empty($date_string)) {
646
-            return null;
647
-        }
648
-
649
-        // if incoming date
650
-        if ($date_string instanceof DateTime) {
651
-            $date_string->setTimezone($this->_DateTimeZone);
652
-
653
-            return $date_string;
654
-        }
655
-        // if empty date_string and made it here.
656
-        // Return a datetime object for now in the given timezone.
657
-        if (empty($date_string)) {
658
-            return new DbSafeDateTime(\EE_Datetime_Field::now, $this->_DateTimeZone);
659
-        }
660
-        // if $date_string is matches something that looks like a Unix timestamp let's just use it.
661
-        if (preg_match(EE_Datetime_Field::unix_timestamp_regex, $date_string)) {
662
-            try {
663
-                // This is operating under the assumption that the incoming Unix timestamp
664
-                // is an ACTUAL Unix timestamp and not the calculated one output by current_time('timestamp');
665
-                $DateTime = new DbSafeDateTime(\EE_Datetime_Field::now, $this->_DateTimeZone);
666
-                $DateTime->setTimestamp($date_string);
667
-
668
-                return $DateTime;
669
-            } catch (Exception $e) {
670
-                // should be rare, but if things got fooled then let's just continue
671
-            }
672
-        }
673
-        //not a unix timestamp.  So we will use the set format on this object and set timezone to
674
-        //create the DateTime object.
675
-        $format = $this->_date_format . ' ' . $this->_time_format;
676
-        try {
677
-            $DateTime = DateTime::createFromFormat($format, $date_string, $this->_DateTimeZone);
678
-            if ($DateTime instanceof DateTime) {
679
-                $DateTime = new DbSafeDateTime(
680
-                    $DateTime->format(\EE_Datetime_Field::mysql_timestamp_format),
681
-                    $this->_DateTimeZone
682
-                );
683
-            }
684
-            if (! $DateTime instanceof DbSafeDateTime) {
685
-                throw new EE_Error(
686
-                    sprintf(
687
-                        __('"%1$s" does not represent a valid Date Time in the format "%2$s".', 'event_espresso'),
688
-                        $date_string,
689
-                        $format
690
-                    )
691
-                );
692
-            }
693
-        } catch (Exception $e) {
694
-            // if we made it here then likely then something went really wrong.
695
-            // Instead of throwing an exception, let's just return a DateTime object for now, in the set timezone.
696
-            $DateTime = new DbSafeDateTime(\EE_Datetime_Field::now, $this->_DateTimeZone);
697
-        }
698
-
699
-        return $DateTime;
700
-    }
701
-
702
-
703
-    /**
704
-     * get_timezone_offset
705
-     *
706
-     * @param \DateTimeZone $DateTimeZone
707
-     * @param int           $time
708
-     * @return mixed
709
-     */
710
-    public function get_timezone_offset(DateTimeZone $DateTimeZone, $time = null)
711
-    {
712
-        $time        = preg_match(EE_Datetime_Field::unix_timestamp_regex, $time) ? $time : time();
713
-        $transitions = $DateTimeZone->getTransitions($time);
714
-
715
-        return $transitions[0]['offset'];
716
-    }
717
-
718
-
719
-    /**
720
-     * This will take an incoming timezone string and return the abbreviation for that timezone
721
-     *
722
-     * @param  string $timezone_string
723
-     * @return string           abbreviation
724
-     * @throws \EE_Error
725
-     */
726
-    public function get_timezone_abbrev($timezone_string)
727
-    {
728
-        $timezone_string = EEH_DTT_Helper::get_valid_timezone_string($timezone_string);
729
-        $dateTime        = new DateTime(\EE_Datetime_Field::now, new DateTimeZone($timezone_string));
730
-
731
-        return $dateTime->format('T');
732
-    }
733
-
734
-    /**
735
-     * Overrides the parent to allow for having a dynamic "now" value
736
-     *
737
-     * @return mixed
738
-     */
739
-    public function get_default_value()
740
-    {
741
-        if ($this->_default_value === EE_Datetime_Field::now) {
742
-            return time();
743
-        } else {
744
-            return parent::get_default_value();
745
-        }
746
-    }
19
+	/**
20
+	 * The pattern we're looking for is if only the characters 0-9 are found and there are only
21
+	 * 10 or more numbers (because 9 numbers even with all 9's would be sometime in 2001 )
22
+	 *
23
+	 * @type string unix_timestamp_regex
24
+	 */
25
+	const unix_timestamp_regex = '/[0-9]{10,}/';
26
+
27
+	/**
28
+	 * @type string mysql_timestamp_format
29
+	 */
30
+	const mysql_timestamp_format = 'Y-m-d H:i:s';
31
+
32
+	/**
33
+	 * @type string mysql_date_format
34
+	 */
35
+	const mysql_date_format = 'Y-m-d';
36
+
37
+	/**
38
+	 * @type string mysql_time_format
39
+	 */
40
+	const mysql_time_format = 'H:i:s';
41
+
42
+	/**
43
+	 * Const for using in the default value. If the field's default is set to this,
44
+	 * then we will return the time of calling `get_default_value()`, not
45
+	 * just the current time at construction
46
+	 */
47
+	const now = 'now';
48
+
49
+	/**
50
+	 * The following properties hold the default formats for date and time.
51
+	 * Defaults are set via the constructor and can be overridden on class instantiation.
52
+	 * However they can also be overridden later by the set_format() method
53
+	 * (and corresponding set_date_format, set_time_format methods);
54
+	 */
55
+	/**
56
+	 * @type string $_date_format
57
+	 */
58
+	protected $_date_format = '';
59
+
60
+	/**
61
+	 * @type string $_time_format
62
+	 */
63
+	protected $_time_format = '';
64
+
65
+	/**
66
+	 * @type string $_pretty_date_format
67
+	 */
68
+	protected $_pretty_date_format = '';
69
+
70
+	/**
71
+	 * @type string $_pretty_time_format
72
+	 */
73
+	protected $_pretty_time_format = '';
74
+
75
+	/**
76
+	 * @type DateTimeZone $_DateTimeZone
77
+	 */
78
+	protected $_DateTimeZone;
79
+
80
+	/**
81
+	 * @type DateTimeZone $_UTC_DateTimeZone
82
+	 */
83
+	protected $_UTC_DateTimeZone;
84
+
85
+	/**
86
+	 * @type DateTimeZone $_blog_DateTimeZone
87
+	 */
88
+	protected $_blog_DateTimeZone;
89
+
90
+
91
+	/**
92
+	 * This property holds how we want the output returned when getting a datetime string.  It is set for the
93
+	 * set_date_time_output() method.  By default this is empty.  When empty, we are assuming that we want both date
94
+	 * and time returned via getters.
95
+	 *
96
+	 * @var mixed (null|string)
97
+	 */
98
+	protected $_date_time_output;
99
+
100
+
101
+	/**
102
+	 * timezone string
103
+	 * This gets set by the constructor and can be changed by the "set_timezone()" method so that we know what timezone
104
+	 * incoming strings|timestamps are in.  This can also be used before a get to set what timezone you want strings
105
+	 * coming out of the object to be in.  Default timezone is the current WP timezone option setting
106
+	 *
107
+	 * @var string
108
+	 */
109
+	protected $_timezone_string;
110
+
111
+
112
+	/**
113
+	 * This holds whatever UTC offset for the blog (we automatically convert timezone strings into their related
114
+	 * offsets for comparison purposes).
115
+	 *
116
+	 * @var int
117
+	 */
118
+	protected $_blog_offset;
119
+
120
+
121
+	/**
122
+	 * @param string $table_column
123
+	 * @param string $nice_name
124
+	 * @param bool   $nullable
125
+	 * @param string $default_value
126
+	 * @param string $timezone_string
127
+	 * @param string $date_format
128
+	 * @param string $time_format
129
+	 * @param string $pretty_date_format
130
+	 * @param string $pretty_time_format
131
+	 * @throws \EE_Error
132
+	 */
133
+	public function __construct(
134
+		$table_column,
135
+		$nice_name,
136
+		$nullable,
137
+		$default_value,
138
+		$timezone_string = '',
139
+		$date_format = '',
140
+		$time_format = '',
141
+		$pretty_date_format = '',
142
+		$pretty_time_format = ''
143
+	) {
144
+
145
+		$this->_date_format        = ! empty($date_format) ? $date_format : get_option('date_format');
146
+		$this->_time_format        = ! empty($time_format) ? $time_format : get_option('time_format');
147
+		$this->_pretty_date_format = ! empty($pretty_date_format) ? $pretty_date_format : get_option('date_format');
148
+		$this->_pretty_time_format = ! empty($pretty_time_format) ? $pretty_time_format : get_option('time_format');
149
+
150
+		parent::__construct($table_column, $nice_name, $nullable, $default_value);
151
+		$this->set_timezone($timezone_string);
152
+
153
+	}
154
+
155
+
156
+	/**
157
+	 * @return string
158
+	 */
159
+	public function get_wpdb_data_type()
160
+	{
161
+		return '%s';
162
+	}
163
+
164
+
165
+	/**
166
+	 * @return DateTimeZone
167
+	 * @throws \EE_Error
168
+	 */
169
+	public function get_UTC_DateTimeZone()
170
+	{
171
+		return $this->_UTC_DateTimeZone instanceof DateTimeZone
172
+			? $this->_UTC_DateTimeZone
173
+			: $this->_create_timezone_object_from_timezone_string('UTC');
174
+	}
175
+
176
+
177
+	/**
178
+	 * @return DateTimeZone
179
+	 * @throws \EE_Error
180
+	 */
181
+	public function get_blog_DateTimeZone()
182
+	{
183
+		return $this->_blog_DateTimeZone instanceof DateTimeZone
184
+			? $this->_blog_DateTimeZone
185
+			: $this->_create_timezone_object_from_timezone_string('');
186
+	}
187
+
188
+
189
+	/**
190
+	 * this prepares any incoming date data and make sure its converted to a utc unix timestamp
191
+	 *
192
+	 * @param  string|int $value_inputted_for_field_on_model_object could be a string formatted date time or int unix
193
+	 *                                                              timestamp
194
+	 * @return DateTime
195
+	 */
196
+	public function prepare_for_set($value_inputted_for_field_on_model_object)
197
+	{
198
+		return $this->_get_date_object($value_inputted_for_field_on_model_object);
199
+	}
200
+
201
+
202
+	/**
203
+	 * This returns the format string to be used by getters depending on what the $_date_time_output property is set at.
204
+	 * getters need to know whether we're just returning the date or the time or both.  By default we return both.
205
+	 *
206
+	 * @param bool $pretty If we're returning the pretty formats or standard format string.
207
+	 * @return string    The final assembled format string.
208
+	 */
209
+	protected function _get_date_time_output($pretty = false)
210
+	{
211
+
212
+		switch ($this->_date_time_output) {
213
+			case 'time' :
214
+				return $pretty ? $this->_pretty_time_format : $this->_time_format;
215
+				break;
216
+
217
+			case 'date' :
218
+				return $pretty ? $this->_pretty_date_format : $this->_date_format;
219
+				break;
220
+
221
+			default :
222
+				return $pretty
223
+					? $this->_pretty_date_format . ' ' . $this->_pretty_time_format
224
+					: $this->_date_format . ' ' . $this->_time_format;
225
+		}
226
+	}
227
+
228
+
229
+	/**
230
+	 * This just sets the $_date_time_output property so we can flag how date and times are formatted before being
231
+	 * returned (using the format properties)
232
+	 *
233
+	 * @param string $what acceptable values are 'time' or 'date'.
234
+	 *                     Any other value will be set but will always result
235
+	 *                     in both 'date' and 'time' being returned.
236
+	 * @return void
237
+	 */
238
+	public function set_date_time_output($what = null)
239
+	{
240
+		$this->_date_time_output = $what;
241
+	}
242
+
243
+
244
+	/**
245
+	 * See $_timezone property for description of what the timezone property is for.  This SETS the timezone internally
246
+	 * for being able to reference what timezone we are running conversions on when converting TO the internal timezone
247
+	 * (UTC Unix Timestamp) for the object OR when converting FROM the internal timezone (UTC Unix Timestamp).
248
+	 * We also set some other properties in this method.
249
+	 *
250
+	 * @param string $timezone_string A valid timezone string as described by @link
251
+	 *                                http://www.php.net/manual/en/timezones.php
252
+	 * @return void
253
+	 * @throws \EE_Error
254
+	 */
255
+	public function set_timezone($timezone_string)
256
+	{
257
+		if (empty($timezone_string) && $this->_timezone_string !== null) {
258
+			// leave the timezone AS-IS if we already have one and
259
+			// the function arg didn't provide one
260
+			return;
261
+		}
262
+		$timezone_string        = EEH_DTT_Helper::get_valid_timezone_string($timezone_string);
263
+		$this->_timezone_string = ! empty($timezone_string) ? $timezone_string : 'UTC';
264
+		$this->_DateTimeZone    = $this->_create_timezone_object_from_timezone_string($this->_timezone_string);
265
+	}
266
+
267
+
268
+	/**
269
+	 * _create_timezone_object_from_timezone_name
270
+	 *
271
+	 * @access protected
272
+	 * @param string $timezone_string
273
+	 * @return \DateTimeZone
274
+	 * @throws \EE_Error
275
+	 */
276
+	protected function _create_timezone_object_from_timezone_string($timezone_string = '')
277
+	{
278
+		return new DateTimeZone(EEH_DTT_Helper::get_valid_timezone_string($timezone_string));
279
+	}
280
+
281
+
282
+	/**
283
+	 * This just returns whatever is set for the current timezone.
284
+	 *
285
+	 * @access public
286
+	 * @return string timezone string
287
+	 */
288
+	public function get_timezone()
289
+	{
290
+		return $this->_timezone_string;
291
+	}
292
+
293
+
294
+	/**
295
+	 * set the $_date_format property
296
+	 *
297
+	 * @access public
298
+	 * @param string $format a new date format (corresponding to formats accepted by PHP date() function)
299
+	 * @param bool   $pretty Whether to set pretty format or not.
300
+	 * @return void
301
+	 */
302
+	public function set_date_format($format, $pretty = false)
303
+	{
304
+		if ($pretty) {
305
+			$this->_pretty_date_format = $format;
306
+		} else {
307
+			$this->_date_format = $format;
308
+		}
309
+	}
310
+
311
+
312
+	/**
313
+	 * return the $_date_format property value.
314
+	 *
315
+	 * @param bool $pretty Whether to get pretty format or not.
316
+	 * @return string
317
+	 */
318
+	public function get_date_format($pretty = false)
319
+	{
320
+		return $pretty ? $this->_pretty_date_format : $this->_date_format;
321
+	}
322
+
323
+
324
+	/**
325
+	 * set the $_time_format property
326
+	 *
327
+	 * @access public
328
+	 * @param string $format a new time format (corresponding to formats accepted by PHP date() function)
329
+	 * @param bool   $pretty Whether to set pretty format or not.
330
+	 * @return void
331
+	 */
332
+	public function set_time_format($format, $pretty = false)
333
+	{
334
+		if ($pretty) {
335
+			$this->_pretty_time_format = $format;
336
+		} else {
337
+			$this->_time_format = $format;
338
+		}
339
+	}
340
+
341
+
342
+	/**
343
+	 * return the $_time_format property value.
344
+	 *
345
+	 * @param bool $pretty Whether to get pretty format or not.
346
+	 * @return string
347
+	 */
348
+	public function get_time_format($pretty = false)
349
+	{
350
+		return $pretty ? $this->_pretty_time_format : $this->_time_format;
351
+	}
352
+
353
+
354
+	/**
355
+	 * set the $_pretty_date_format property
356
+	 *
357
+	 * @access public
358
+	 * @param string $format a new pretty date format (corresponding to formats accepted by PHP date() function)
359
+	 * @return void
360
+	 */
361
+	public function set_pretty_date_format($format)
362
+	{
363
+		$this->_pretty_date_format = $format;
364
+	}
365
+
366
+
367
+	/**
368
+	 * set the $_pretty_time_format property
369
+	 *
370
+	 * @access public
371
+	 * @param string $format a new pretty time format (corresponding to formats accepted by PHP date() function)
372
+	 * @return void
373
+	 */
374
+	public function set_pretty_time_format($format)
375
+	{
376
+		$this->_pretty_time_format = $format;
377
+	}
378
+
379
+
380
+	/**
381
+	 * Only sets the time portion of the datetime.
382
+	 *
383
+	 * @param string|DateTime $time_to_set_string like 8am OR a DateTime object.
384
+	 * @param DateTime        $current            current DateTime object for the datetime field
385
+	 * @return DateTime
386
+	 */
387
+	public function prepare_for_set_with_new_time($time_to_set_string, DateTime $current)
388
+	{
389
+		// if $time_to_set_string is datetime object, then let's use it to set the parse array.
390
+		// Otherwise parse the string.
391
+		if ($time_to_set_string instanceof DateTime) {
392
+			$parsed = array(
393
+				'hour'   => $time_to_set_string->format('H'),
394
+				'minute' => $time_to_set_string->format('i'),
395
+				'second' => $time_to_set_string->format('s'),
396
+			);
397
+		} else {
398
+			//parse incoming string
399
+			$parsed = date_parse_from_format($this->_time_format, $time_to_set_string);
400
+		}
401
+
402
+		//make sure $current is in the correct timezone.
403
+		$current->setTimezone($this->_DateTimeZone);
404
+
405
+		return $current->setTime($parsed['hour'], $parsed['minute'], $parsed['second']);
406
+	}
407
+
408
+
409
+	/**
410
+	 * Only sets the date portion of the datetime.
411
+	 *
412
+	 * @param string|DateTime $date_to_set_string like Friday, January 8th or a DateTime object.
413
+	 * @param DateTime        $current            current DateTime object for the datetime field
414
+	 * @return DateTime
415
+	 */
416
+	public function prepare_for_set_with_new_date($date_to_set_string, DateTime $current)
417
+	{
418
+		// if $time_to_set_string is datetime object, then let's use it to set the parse array.
419
+		// Otherwise parse the string.
420
+		if ($date_to_set_string instanceof DateTime) {
421
+			$parsed = array(
422
+				'year'  => $date_to_set_string->format('Y'),
423
+				'month' => $date_to_set_string->format('m'),
424
+				'day'   => $date_to_set_string->format('d'),
425
+			);
426
+		} else {
427
+			//parse incoming string
428
+			$parsed = date_parse_from_format($this->_date_format, $date_to_set_string);
429
+		}
430
+
431
+		//make sure $current is in the correct timezone
432
+		$current->setTimezone($this->_DateTimeZone);
433
+
434
+		return $current->setDate($parsed['year'], $parsed['month'], $parsed['day']);
435
+	}
436
+
437
+
438
+	/**
439
+	 * This prepares the EE_DateTime value to be saved to the db as mysql timestamp (UTC +0 timezone).  When the
440
+	 * datetime gets to this stage it should ALREADY be in UTC time
441
+	 *
442
+	 * @param  DateTime $DateTime
443
+	 * @return string formatted date time for given timezone
444
+	 * @throws \EE_Error
445
+	 */
446
+	public function prepare_for_get($DateTime)
447
+	{
448
+		return $this->_prepare_for_display($DateTime);
449
+	}
450
+
451
+
452
+	/**
453
+	 * This differs from prepare_for_get in that it considers whether the internal $_timezone differs
454
+	 * from the set wp timezone.  If so, then it returns the datetime string formatted via
455
+	 * _pretty_date_format, and _pretty_time_format.  However, it also appends a timezone
456
+	 * abbreviation to the date_string.
457
+	 *
458
+	 * @param mixed $DateTime
459
+	 * @param null  $schema
460
+	 * @return string
461
+	 * @throws \EE_Error
462
+	 */
463
+	public function prepare_for_pretty_echoing($DateTime, $schema = null)
464
+	{
465
+		return $this->_prepare_for_display($DateTime, $schema ? $schema : true);
466
+	}
467
+
468
+
469
+	/**
470
+	 * This prepares the EE_DateTime value to be saved to the db as mysql timestamp (UTC +0
471
+	 * timezone).
472
+	 *
473
+	 * @param DateTime    $DateTime
474
+	 * @param bool|string $schema
475
+	 * @return string
476
+	 * @throws \EE_Error
477
+	 */
478
+	protected function _prepare_for_display($DateTime, $schema = false)
479
+	{
480
+		if (! $DateTime instanceof DateTime) {
481
+			if ($this->_nullable) {
482
+				return '';
483
+			} else {
484
+				if (WP_DEBUG) {
485
+					throw new EE_Error(
486
+						sprintf(
487
+							__(
488
+								'EE_Datetime_Field::_prepare_for_display requires a DateTime class to be the value for the $DateTime argument because the %s field is not nullable.',
489
+								'event_espresso'
490
+							),
491
+							$this->_nicename
492
+						)
493
+					);
494
+				} else {
495
+					$DateTime = new DbSafeDateTime(\EE_Datetime_Field::now);
496
+					EE_Error::add_error(
497
+						sprintf(
498
+							__(
499
+								'EE_Datetime_Field::_prepare_for_display requires a DateTime class to be the value for the $DateTime argument because the %s field is not nullable.  When WP_DEBUG is false, the value is set to "now" instead of throwing an exception.',
500
+								'event_espresso'
501
+							),
502
+							$this->_nicename
503
+						)
504
+					);
505
+				}
506
+			}
507
+		}
508
+		$format_string = $this->_get_date_time_output($schema);
509
+		//make sure datetime_value is in the correct timezone (in case that's been updated).
510
+		$DateTime->setTimezone($this->_DateTimeZone);
511
+		if ($schema) {
512
+			if ($this->_display_timezone()) {
513
+				//must be explicit because schema could equal true.
514
+				if ($schema === 'no_html') {
515
+					$timezone_string = ' (' . $DateTime->format('T') . ')';
516
+				} else {
517
+					$timezone_string = ' <span class="ee_dtt_timezone_string">(' . $DateTime->format('T') . ')</span>';
518
+				}
519
+			} else {
520
+				$timezone_string = '';
521
+			}
522
+
523
+			return $DateTime->format($format_string) . $timezone_string;
524
+		} else {
525
+			return $DateTime->format($format_string);
526
+		}
527
+	}
528
+
529
+
530
+	/**
531
+	 * This prepares the EE_DateTime value to be saved to the db as mysql timestamp (UTC +0
532
+	 * timezone).
533
+	 *
534
+	 * @param  mixed $datetime_value u
535
+	 * @return string mysql timestamp in UTC
536
+	 * @throws \EE_Error
537
+	 */
538
+	public function prepare_for_use_in_db($datetime_value)
539
+	{
540
+		//we allow an empty value or DateTime object, but nothing else.
541
+		if (! empty($datetime_value) && ! $datetime_value instanceof DateTime) {
542
+			throw new EE_Error(
543
+				__(
544
+					'The incoming value being prepared for setting in the database must either be empty or a php DateTime object',
545
+					'event_espresso'
546
+				)
547
+			);
548
+		}
549
+
550
+		if ($datetime_value instanceof DateTime) {
551
+			if ( ! $datetime_value instanceof DbSafeDateTime) {
552
+				$datetime_value = DbSafeDateTime::createFromDateTime($datetime_value);
553
+			}
554
+
555
+			return $datetime_value->setTimezone($this->get_UTC_DateTimeZone())->format(
556
+				EE_Datetime_Field::mysql_timestamp_format
557
+			);
558
+		}
559
+
560
+		// if $datetime_value is empty, and ! $this->_nullable, use current_time() but set the GMT flag to true
561
+		return ! $this->_nullable && empty($datetime_value) ? current_time('mysql', true) : null;
562
+	}
563
+
564
+
565
+	/**
566
+	 * This prepares the datetime for internal usage as a PHP DateTime object OR null (if nullable is
567
+	 * allowed)
568
+	 *
569
+	 * @param string $datetime_string mysql timestamp in UTC
570
+	 * @return  mixed null | DateTime
571
+	 * @throws \EE_Error
572
+	 */
573
+	public function prepare_for_set_from_db($datetime_string)
574
+	{
575
+		//if $datetime_value is empty, and ! $this->_nullable, just use time()
576
+		if (empty($datetime_string) && $this->_nullable) {
577
+			return null;
578
+		}
579
+		// datetime strings from the db should ALWAYS be in UTC+0, so use UTC_DateTimeZone when creating
580
+		if (empty($datetime_string)) {
581
+			$DateTime = new DbSafeDateTime(\EE_Datetime_Field::now, $this->get_UTC_DateTimeZone());
582
+		} else {
583
+			$DateTime = DateTime::createFromFormat(
584
+				EE_Datetime_Field::mysql_timestamp_format,
585
+				$datetime_string,
586
+				$this->get_UTC_DateTimeZone()
587
+			);
588
+			if ($DateTime instanceof \DateTime) {
589
+				$DateTime = new DbSafeDateTime(
590
+					$DateTime->format(\EE_Datetime_Field::mysql_timestamp_format),
591
+					$this->get_UTC_DateTimeZone()
592
+				);
593
+			}
594
+		}
595
+
596
+		if (! $DateTime instanceof DbSafeDateTime) {
597
+			// if still no datetime object, then let's just use now
598
+			$DateTime = new DbSafeDateTime(\EE_Datetime_Field::now, $this->get_UTC_DateTimeZone());
599
+		}
600
+		// THEN apply the field's set DateTimeZone
601
+		$DateTime->setTimezone($this->_DateTimeZone);
602
+
603
+		return $DateTime;
604
+	}
605
+
606
+
607
+	/**
608
+	 * All this method does is determine if we're going to display the timezone string or not on any output.
609
+	 * To determine this we check if the set timezone offset is different than the blog's set timezone offset.
610
+	 * If so, then true.
611
+	 *
612
+	 * @return bool true for yes false for no
613
+	 * @throws \EE_Error
614
+	 */
615
+	protected function _display_timezone()
616
+	{
617
+
618
+		// first let's do a comparison of timezone strings.
619
+		// If they match then we can get out without any further calculations
620
+		$blog_string = get_option('timezone_string');
621
+		if ($blog_string === $this->_timezone_string) {
622
+			return false;
623
+		}
624
+		// now we need to calc the offset for the timezone string so we can compare with the blog offset.
625
+		$this_offset = $this->get_timezone_offset($this->_DateTimeZone);
626
+		$blog_offset = $this->get_timezone_offset($this->get_blog_DateTimeZone());
627
+		// now compare
628
+		return $blog_offset !== $this_offset;
629
+	}
630
+
631
+
632
+	/**
633
+	 * This method returns a php DateTime object for setting on the EE_Base_Class model.
634
+	 * EE passes around DateTime objects because they are MUCH easier to manipulate and deal
635
+	 * with.
636
+	 *
637
+	 * @param int|string|DateTime $date_string            This should be the incoming date string.  It's assumed to be
638
+	 *                                                    in the format that is set on the date_field (or DateTime
639
+	 *                                                    object)!
640
+	 * @return DateTime
641
+	 */
642
+	protected function _get_date_object($date_string)
643
+	{
644
+		//first if this is an empty date_string and nullable is allowed, just return null.
645
+		if ($this->_nullable && empty($date_string)) {
646
+			return null;
647
+		}
648
+
649
+		// if incoming date
650
+		if ($date_string instanceof DateTime) {
651
+			$date_string->setTimezone($this->_DateTimeZone);
652
+
653
+			return $date_string;
654
+		}
655
+		// if empty date_string and made it here.
656
+		// Return a datetime object for now in the given timezone.
657
+		if (empty($date_string)) {
658
+			return new DbSafeDateTime(\EE_Datetime_Field::now, $this->_DateTimeZone);
659
+		}
660
+		// if $date_string is matches something that looks like a Unix timestamp let's just use it.
661
+		if (preg_match(EE_Datetime_Field::unix_timestamp_regex, $date_string)) {
662
+			try {
663
+				// This is operating under the assumption that the incoming Unix timestamp
664
+				// is an ACTUAL Unix timestamp and not the calculated one output by current_time('timestamp');
665
+				$DateTime = new DbSafeDateTime(\EE_Datetime_Field::now, $this->_DateTimeZone);
666
+				$DateTime->setTimestamp($date_string);
667
+
668
+				return $DateTime;
669
+			} catch (Exception $e) {
670
+				// should be rare, but if things got fooled then let's just continue
671
+			}
672
+		}
673
+		//not a unix timestamp.  So we will use the set format on this object and set timezone to
674
+		//create the DateTime object.
675
+		$format = $this->_date_format . ' ' . $this->_time_format;
676
+		try {
677
+			$DateTime = DateTime::createFromFormat($format, $date_string, $this->_DateTimeZone);
678
+			if ($DateTime instanceof DateTime) {
679
+				$DateTime = new DbSafeDateTime(
680
+					$DateTime->format(\EE_Datetime_Field::mysql_timestamp_format),
681
+					$this->_DateTimeZone
682
+				);
683
+			}
684
+			if (! $DateTime instanceof DbSafeDateTime) {
685
+				throw new EE_Error(
686
+					sprintf(
687
+						__('"%1$s" does not represent a valid Date Time in the format "%2$s".', 'event_espresso'),
688
+						$date_string,
689
+						$format
690
+					)
691
+				);
692
+			}
693
+		} catch (Exception $e) {
694
+			// if we made it here then likely then something went really wrong.
695
+			// Instead of throwing an exception, let's just return a DateTime object for now, in the set timezone.
696
+			$DateTime = new DbSafeDateTime(\EE_Datetime_Field::now, $this->_DateTimeZone);
697
+		}
698
+
699
+		return $DateTime;
700
+	}
701
+
702
+
703
+	/**
704
+	 * get_timezone_offset
705
+	 *
706
+	 * @param \DateTimeZone $DateTimeZone
707
+	 * @param int           $time
708
+	 * @return mixed
709
+	 */
710
+	public function get_timezone_offset(DateTimeZone $DateTimeZone, $time = null)
711
+	{
712
+		$time        = preg_match(EE_Datetime_Field::unix_timestamp_regex, $time) ? $time : time();
713
+		$transitions = $DateTimeZone->getTransitions($time);
714
+
715
+		return $transitions[0]['offset'];
716
+	}
717
+
718
+
719
+	/**
720
+	 * This will take an incoming timezone string and return the abbreviation for that timezone
721
+	 *
722
+	 * @param  string $timezone_string
723
+	 * @return string           abbreviation
724
+	 * @throws \EE_Error
725
+	 */
726
+	public function get_timezone_abbrev($timezone_string)
727
+	{
728
+		$timezone_string = EEH_DTT_Helper::get_valid_timezone_string($timezone_string);
729
+		$dateTime        = new DateTime(\EE_Datetime_Field::now, new DateTimeZone($timezone_string));
730
+
731
+		return $dateTime->format('T');
732
+	}
733
+
734
+	/**
735
+	 * Overrides the parent to allow for having a dynamic "now" value
736
+	 *
737
+	 * @return mixed
738
+	 */
739
+	public function get_default_value()
740
+	{
741
+		if ($this->_default_value === EE_Datetime_Field::now) {
742
+			return time();
743
+		} else {
744
+			return parent::get_default_value();
745
+		}
746
+	}
747 747
 
748 748
 
749 749
 }
Please login to merge, or discard this patch.
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php use EventEspresso\core\domain\entities\DbSafeDateTime;
2 2
 
3
-if (! defined('EVENT_ESPRESSO_VERSION')) {
3
+if ( ! defined('EVENT_ESPRESSO_VERSION')) {
4 4
     exit('No direct script access allowed');
5 5
 }
6 6
 
@@ -220,8 +220,8 @@  discard block
 block discarded – undo
220 220
 
221 221
             default :
222 222
                 return $pretty
223
-                    ? $this->_pretty_date_format . ' ' . $this->_pretty_time_format
224
-                    : $this->_date_format . ' ' . $this->_time_format;
223
+                    ? $this->_pretty_date_format.' '.$this->_pretty_time_format
224
+                    : $this->_date_format.' '.$this->_time_format;
225 225
         }
226 226
     }
227 227
 
@@ -477,7 +477,7 @@  discard block
 block discarded – undo
477 477
      */
478 478
     protected function _prepare_for_display($DateTime, $schema = false)
479 479
     {
480
-        if (! $DateTime instanceof DateTime) {
480
+        if ( ! $DateTime instanceof DateTime) {
481 481
             if ($this->_nullable) {
482 482
                 return '';
483 483
             } else {
@@ -512,15 +512,15 @@  discard block
 block discarded – undo
512 512
             if ($this->_display_timezone()) {
513 513
                 //must be explicit because schema could equal true.
514 514
                 if ($schema === 'no_html') {
515
-                    $timezone_string = ' (' . $DateTime->format('T') . ')';
515
+                    $timezone_string = ' ('.$DateTime->format('T').')';
516 516
                 } else {
517
-                    $timezone_string = ' <span class="ee_dtt_timezone_string">(' . $DateTime->format('T') . ')</span>';
517
+                    $timezone_string = ' <span class="ee_dtt_timezone_string">('.$DateTime->format('T').')</span>';
518 518
                 }
519 519
             } else {
520 520
                 $timezone_string = '';
521 521
             }
522 522
 
523
-            return $DateTime->format($format_string) . $timezone_string;
523
+            return $DateTime->format($format_string).$timezone_string;
524 524
         } else {
525 525
             return $DateTime->format($format_string);
526 526
         }
@@ -538,7 +538,7 @@  discard block
 block discarded – undo
538 538
     public function prepare_for_use_in_db($datetime_value)
539 539
     {
540 540
         //we allow an empty value or DateTime object, but nothing else.
541
-        if (! empty($datetime_value) && ! $datetime_value instanceof DateTime) {
541
+        if ( ! empty($datetime_value) && ! $datetime_value instanceof DateTime) {
542 542
             throw new EE_Error(
543 543
                 __(
544 544
                     'The incoming value being prepared for setting in the database must either be empty or a php DateTime object',
@@ -593,7 +593,7 @@  discard block
 block discarded – undo
593 593
             }
594 594
         }
595 595
 
596
-        if (! $DateTime instanceof DbSafeDateTime) {
596
+        if ( ! $DateTime instanceof DbSafeDateTime) {
597 597
             // if still no datetime object, then let's just use now
598 598
             $DateTime = new DbSafeDateTime(\EE_Datetime_Field::now, $this->get_UTC_DateTimeZone());
599 599
         }
@@ -672,7 +672,7 @@  discard block
 block discarded – undo
672 672
         }
673 673
         //not a unix timestamp.  So we will use the set format on this object and set timezone to
674 674
         //create the DateTime object.
675
-        $format = $this->_date_format . ' ' . $this->_time_format;
675
+        $format = $this->_date_format.' '.$this->_time_format;
676 676
         try {
677 677
             $DateTime = DateTime::createFromFormat($format, $date_string, $this->_DateTimeZone);
678 678
             if ($DateTime instanceof DateTime) {
@@ -681,7 +681,7 @@  discard block
 block discarded – undo
681 681
                     $this->_DateTimeZone
682 682
                 );
683 683
             }
684
-            if (! $DateTime instanceof DbSafeDateTime) {
684
+            if ( ! $DateTime instanceof DbSafeDateTime) {
685 685
                 throw new EE_Error(
686 686
                     sprintf(
687 687
                         __('"%1$s" does not represent a valid Date Time in the format "%2$s".', 'event_espresso'),
Please login to merge, or discard this patch.
core/db_models/fields/EE_Field_With_Model_Name.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -35,7 +35,7 @@
 block discarded – undo
35 35
      * Returns the name of the model(s) pointed to
36 36
      *
37 37
      * @deprecated since version 4.6.7
38
-     * @return mixed string or array of strings
38
+     * @return string string or array of strings
39 39
      */
40 40
     function get_model_name_pointed_to()
41 41
     {
Please login to merge, or discard this patch.
Indentation   +74 added lines, -74 removed lines patch added patch discarded remove patch
@@ -8,83 +8,83 @@
 block discarded – undo
8 8
  */
9 9
 abstract class EE_Field_With_Model_Name extends EE_Model_Field_Base
10 10
 {
11
-    /**
12
-     * Usually the name of a single model. However, as in the case for custom post types,
13
-     * it can actually be an array of models
14
-     *
15
-     * @var string or array
16
-     */
17
-    protected $_model_name_pointed_to;
11
+	/**
12
+	 * Usually the name of a single model. However, as in the case for custom post types,
13
+	 * it can actually be an array of models
14
+	 *
15
+	 * @var string or array
16
+	 */
17
+	protected $_model_name_pointed_to;
18 18
 
19
-    /**
20
-     * @param string  $table_column  name fo column for field
21
-     * @param string  $nicename      should eb internationalized with __('blah','event_espresso')
22
-     * @param boolean $nullable
23
-     * @param mixed   $default_value if this is a integer field, it shoudl be an int. if it's a string field, it shoul
24
-     *                               dbe a string
25
-     * @param string  $model_name    eg 'Event','Answer','Term', etc. Basically its the model class's name without the
26
-     *                               "EEM_"
27
-     */
28
-    function __construct($table_column, $nicename, $nullable, $default_value, $model_name)
29
-    {
30
-        $this->_model_name_pointed_to = $model_name;
31
-        parent::__construct($table_column, $nicename, $nullable, $default_value);
32
-    }
19
+	/**
20
+	 * @param string  $table_column  name fo column for field
21
+	 * @param string  $nicename      should eb internationalized with __('blah','event_espresso')
22
+	 * @param boolean $nullable
23
+	 * @param mixed   $default_value if this is a integer field, it shoudl be an int. if it's a string field, it shoul
24
+	 *                               dbe a string
25
+	 * @param string  $model_name    eg 'Event','Answer','Term', etc. Basically its the model class's name without the
26
+	 *                               "EEM_"
27
+	 */
28
+	function __construct($table_column, $nicename, $nullable, $default_value, $model_name)
29
+	{
30
+		$this->_model_name_pointed_to = $model_name;
31
+		parent::__construct($table_column, $nicename, $nullable, $default_value);
32
+	}
33 33
 
34
-    /**
35
-     * Returns the name of the model(s) pointed to
36
-     *
37
-     * @deprecated since version 4.6.7
38
-     * @return mixed string or array of strings
39
-     */
40
-    function get_model_name_pointed_to()
41
-    {
42
-        EE_Error::doing_it_wrong('get_model_name_pointed_to',
43
-            __('This method has been deprecated in favour of instead using get_model_names_pointed_to, which consistently returns an array',
44
-                'event_espresso'), '4.6.7');
45
-        return $this->_model_name_pointed_to;
46
-    }
34
+	/**
35
+	 * Returns the name of the model(s) pointed to
36
+	 *
37
+	 * @deprecated since version 4.6.7
38
+	 * @return mixed string or array of strings
39
+	 */
40
+	function get_model_name_pointed_to()
41
+	{
42
+		EE_Error::doing_it_wrong('get_model_name_pointed_to',
43
+			__('This method has been deprecated in favour of instead using get_model_names_pointed_to, which consistently returns an array',
44
+				'event_espresso'), '4.6.7');
45
+		return $this->_model_name_pointed_to;
46
+	}
47 47
 
48
-    /**
49
-     * Gets the model names pointed to by this field, always as an array
50
-     * (even if there's only one)
51
-     *
52
-     * @return array of model names pointed to by this field
53
-     */
54
-    function get_model_names_pointed_to()
55
-    {
56
-        if (is_array($this->_model_name_pointed_to)) {
57
-            return $this->_model_name_pointed_to;
58
-        } else {
59
-            return array($this->_model_name_pointed_to);
60
-        }
61
-    }
48
+	/**
49
+	 * Gets the model names pointed to by this field, always as an array
50
+	 * (even if there's only one)
51
+	 *
52
+	 * @return array of model names pointed to by this field
53
+	 */
54
+	function get_model_names_pointed_to()
55
+	{
56
+		if (is_array($this->_model_name_pointed_to)) {
57
+			return $this->_model_name_pointed_to;
58
+		} else {
59
+			return array($this->_model_name_pointed_to);
60
+		}
61
+	}
62 62
 
63
-    /**
64
-     * Returns the model's classname (eg EE_Event instead of just Event)
65
-     *
66
-     * @return array
67
-     */
68
-    function get_model_class_names_pointed_to()
69
-    {
70
-        $model_names = array();
71
-        if (is_array($this->_model_name_pointed_to)) {
72
-            foreach ($this->_model_name_pointed_to as $model_name) {
73
-                $model_names[] = "EE_" . $model_name;
74
-            }
75
-        } else {
76
-            $model_names = array("EE_" . $this->_model_name_pointed_to);
77
-        }
78
-        return $model_names;
79
-    }
63
+	/**
64
+	 * Returns the model's classname (eg EE_Event instead of just Event)
65
+	 *
66
+	 * @return array
67
+	 */
68
+	function get_model_class_names_pointed_to()
69
+	{
70
+		$model_names = array();
71
+		if (is_array($this->_model_name_pointed_to)) {
72
+			foreach ($this->_model_name_pointed_to as $model_name) {
73
+				$model_names[] = "EE_" . $model_name;
74
+			}
75
+		} else {
76
+			$model_names = array("EE_" . $this->_model_name_pointed_to);
77
+		}
78
+		return $model_names;
79
+	}
80 80
 
81
-    function is_model_obj_of_type_pointed_to($model_obj_or_ID)
82
-    {
83
-        foreach ($this->get_model_class_names_pointed_to() as $model_obj_classname) {
84
-            if ($model_obj_or_ID instanceof $model_obj_classname) {
85
-                return true;
86
-            }
87
-        }
88
-        return false;
89
-    }
81
+	function is_model_obj_of_type_pointed_to($model_obj_or_ID)
82
+	{
83
+		foreach ($this->get_model_class_names_pointed_to() as $model_obj_classname) {
84
+			if ($model_obj_or_ID instanceof $model_obj_classname) {
85
+				return true;
86
+			}
87
+		}
88
+		return false;
89
+	}
90 90
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -70,10 +70,10 @@
 block discarded – undo
70 70
         $model_names = array();
71 71
         if (is_array($this->_model_name_pointed_to)) {
72 72
             foreach ($this->_model_name_pointed_to as $model_name) {
73
-                $model_names[] = "EE_" . $model_name;
73
+                $model_names[] = "EE_".$model_name;
74 74
             }
75 75
         } else {
76
-            $model_names = array("EE_" . $this->_model_name_pointed_to);
76
+            $model_names = array("EE_".$this->_model_name_pointed_to);
77 77
         }
78 78
         return $model_names;
79 79
     }
Please login to merge, or discard this patch.
core/db_models/fields/EE_Model_Field_Base.php 3 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -30,9 +30,9 @@
 block discarded – undo
30 30
     protected $_model_name;
31 31
 
32 32
     /**
33
-     * @param      $table_column
33
+     * @param      string $table_column
34 34
      * @param      $nicename
35
-     * @param      $nullable
35
+     * @param      boolean $nullable
36 36
      * @param null $default_value
37 37
      */
38 38
     function __construct($table_column, $nicename, $nullable, $default_value = null)
Please login to merge, or discard this patch.
Indentation   +207 added lines, -207 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
 /**
@@ -20,210 +20,210 @@  discard block
 block discarded – undo
20 20
  */
21 21
 abstract class EE_Model_Field_Base
22 22
 {
23
-    var $_table_alias;
24
-    var $_table_column;
25
-    var $_name;
26
-    var $_nicename;
27
-    var $_nullable;
28
-    var $_default_value;
29
-    var $_other_config;
30
-    protected $_model_name;
31
-
32
-    /**
33
-     * @param      $table_column
34
-     * @param      $nicename
35
-     * @param      $nullable
36
-     * @param null $default_value
37
-     */
38
-    function __construct($table_column, $nicename, $nullable, $default_value = null)
39
-    {
40
-        $this->_table_column  = $table_column;
41
-        $this->_nicename      = $nicename;
42
-        $this->_nullable      = $nullable;
43
-        $this->_default_value = $default_value;
44
-    }
45
-
46
-
47
-    /**
48
-     * @param $table_alias
49
-     * @param $name
50
-     * @param $model_name
51
-     */
52
-    function _construct_finalize($table_alias, $name, $model_name)
53
-    {
54
-        $this->_table_alias = $table_alias;
55
-        $this->_name        = $name;
56
-        $this->_model_name  = $model_name;
57
-        /**
58
-         * allow for changing the defaults
59
-         */
60
-        $this->_nicename      = apply_filters('FHEE__EE_Model_Field_Base___construct_finalize___nicename',
61
-            $this->_nicename, $this);
62
-        $this->_default_value = apply_filters('FHEE__EE_Model_Field_Base___construct_finalize___default_value',
63
-            $this->_default_value, $this);
64
-    }
65
-
66
-    function get_table_alias()
67
-    {
68
-        return $this->_table_alias;
69
-    }
70
-
71
-    function get_table_column()
72
-    {
73
-        return $this->_table_column;
74
-    }
75
-
76
-    /**
77
-     * Returns the name of the model this field is on. Eg 'Event' or 'Ticket_Datetime'
78
-     *
79
-     * @return string
80
-     */
81
-    function get_model_name()
82
-    {
83
-        return $this->_model_name;
84
-    }
85
-
86
-    /**
87
-     * @throws \EE_Error
88
-     * @return string
89
-     */
90
-    function get_name()
91
-    {
92
-        if ($this->_name) {
93
-            return $this->_name;
94
-        } else {
95
-            throw new EE_Error(sprintf(__("Model field '%s' has no name set. Did you make a model and forget to call the parent model constructor?",
96
-                "event_espresso"), get_class($this)));
97
-        }
98
-    }
99
-
100
-    function get_nicename()
101
-    {
102
-        return $this->_nicename;
103
-    }
104
-
105
-    function is_nullable()
106
-    {
107
-        return $this->_nullable;
108
-    }
109
-
110
-    /**
111
-     * returns whether this field is an auto-increment field or not. If it is, then
112
-     * on insertion it can be null. However, on updates it must be present.
113
-     *
114
-     * @return boolean
115
-     */
116
-    function is_auto_increment()
117
-    {
118
-        return false;
119
-    }
120
-
121
-    /**
122
-     * The default value in the model object's value domain. See lengthy comment about
123
-     * value domains at the top of EEM_Base
124
-     *
125
-     * @return mixed
126
-     */
127
-    function get_default_value()
128
-    {
129
-        return $this->_default_value;
130
-    }
131
-
132
-    /**
133
-     * Returns the table alias joined to the table column, however this isn't the right
134
-     * table alias if the aliased table is being joined to. In that case, you can use
135
-     * EE_Model_Parser::extract_table_alias_model_relation_chain_prefix() to find the table's current alias
136
-     * in the current query
137
-     *
138
-     * @return string
139
-     */
140
-    function get_qualified_column()
141
-    {
142
-        return $this->get_table_alias() . "." . $this->get_table_column();
143
-    }
144
-
145
-    /**
146
-     * When get() is called on a model object (eg EE_Event), before returning its value,
147
-     * call this function on it, allowing us to customize the returned value based on
148
-     * the field's type. Eg, we may want ot serialize it, strip tags, etc. By default,
149
-     * we simply return it.
150
-     *
151
-     * @param mixed $value_of_field_on_model_object
152
-     * @return mixed
153
-     */
154
-    function prepare_for_get($value_of_field_on_model_object)
155
-    {
156
-        return $value_of_field_on_model_object;
157
-    }
158
-
159
-    /**
160
-     * When inserting or updating a field on a model object, run this function on each
161
-     * value to prepare it for insertion into the db. We may want to add slashes, serialize it, etc.
162
-     * By default, we do nothing.
163
-     *
164
-     * @param mixed $value_of_field_on_model_object
165
-     * @return mixed
166
-     */
167
-    function prepare_for_use_in_db($value_of_field_on_model_object)
168
-    {
169
-        return $value_of_field_on_model_object;
170
-    }
171
-
172
-    /**
173
-     * When creating a brand-new model object, or setting a particular value for one of its fields, this function
174
-     * is called before setting it on the model object. We may want to strip slashes, unserialize the value, etc.
175
-     * By default, we do nothing.
176
-     *
177
-     * @param mixed $value_inputted_for_field_on_model_object
178
-     * @return mixed
179
-     */
180
-    function prepare_for_set($value_inputted_for_field_on_model_object)
181
-    {
182
-        return $value_inputted_for_field_on_model_object;
183
-    }
184
-
185
-
186
-    /**
187
-     * When instantiating a model object from DB results, this function is called before setting each field.
188
-     * We may want to serialize the value, etc. By default, we return the value using prepare_for_set() method as that
189
-     * is the one child classes will most often define.
190
-     *
191
-     * @param mixed $value_found_in_db_for_model_object
192
-     * @return mixed
193
-     */
194
-    function prepare_for_set_from_db($value_found_in_db_for_model_object)
195
-    {
196
-        return $this->prepare_for_set($value_found_in_db_for_model_object);
197
-    }
198
-
199
-    /**
200
-     * When echoing a field's value on a model object, this function is run to prepare the value for presentation in a
201
-     * webpage. For example, we may want to output floats with 2 decimal places by default, dates as "Monday Jan 12,
202
-     * 2013, at 3:23pm" instead of
203
-     * "8765678632", or any other modifications to how the value should be displayed, but not modified itself.
204
-     *
205
-     * @param mixed $value_on_field_to_be_outputted
206
-     * @return mixed
207
-     */
208
-    function prepare_for_pretty_echoing($value_on_field_to_be_outputted)
209
-    {
210
-        return $value_on_field_to_be_outputted;
211
-    }
212
-
213
-    abstract function get_wpdb_data_type();
214
-
215
-    /**
216
-     * Some fields are in the database-only, (ie, used in queries etc), but shouldn't necessarily be part
217
-     * of the model objects (ie, client code shouldn't care to ever see their value... if client code does
218
-     * want to see their value, then they shouldn't be db-only fields!)
219
-     * Eg, when doing events as custom post types, querying the post_type is essential, but
220
-     * post_type is irrelevant for EE_Event objects (because they will ALL be of post_type 'esp_event').
221
-     * By default, all fields aren't db-only.
222
-     *
223
-     * @return boolean
224
-     */
225
-    function is_db_only_field()
226
-    {
227
-        return false;
228
-    }
23
+	var $_table_alias;
24
+	var $_table_column;
25
+	var $_name;
26
+	var $_nicename;
27
+	var $_nullable;
28
+	var $_default_value;
29
+	var $_other_config;
30
+	protected $_model_name;
31
+
32
+	/**
33
+	 * @param      $table_column
34
+	 * @param      $nicename
35
+	 * @param      $nullable
36
+	 * @param null $default_value
37
+	 */
38
+	function __construct($table_column, $nicename, $nullable, $default_value = null)
39
+	{
40
+		$this->_table_column  = $table_column;
41
+		$this->_nicename      = $nicename;
42
+		$this->_nullable      = $nullable;
43
+		$this->_default_value = $default_value;
44
+	}
45
+
46
+
47
+	/**
48
+	 * @param $table_alias
49
+	 * @param $name
50
+	 * @param $model_name
51
+	 */
52
+	function _construct_finalize($table_alias, $name, $model_name)
53
+	{
54
+		$this->_table_alias = $table_alias;
55
+		$this->_name        = $name;
56
+		$this->_model_name  = $model_name;
57
+		/**
58
+		 * allow for changing the defaults
59
+		 */
60
+		$this->_nicename      = apply_filters('FHEE__EE_Model_Field_Base___construct_finalize___nicename',
61
+			$this->_nicename, $this);
62
+		$this->_default_value = apply_filters('FHEE__EE_Model_Field_Base___construct_finalize___default_value',
63
+			$this->_default_value, $this);
64
+	}
65
+
66
+	function get_table_alias()
67
+	{
68
+		return $this->_table_alias;
69
+	}
70
+
71
+	function get_table_column()
72
+	{
73
+		return $this->_table_column;
74
+	}
75
+
76
+	/**
77
+	 * Returns the name of the model this field is on. Eg 'Event' or 'Ticket_Datetime'
78
+	 *
79
+	 * @return string
80
+	 */
81
+	function get_model_name()
82
+	{
83
+		return $this->_model_name;
84
+	}
85
+
86
+	/**
87
+	 * @throws \EE_Error
88
+	 * @return string
89
+	 */
90
+	function get_name()
91
+	{
92
+		if ($this->_name) {
93
+			return $this->_name;
94
+		} else {
95
+			throw new EE_Error(sprintf(__("Model field '%s' has no name set. Did you make a model and forget to call the parent model constructor?",
96
+				"event_espresso"), get_class($this)));
97
+		}
98
+	}
99
+
100
+	function get_nicename()
101
+	{
102
+		return $this->_nicename;
103
+	}
104
+
105
+	function is_nullable()
106
+	{
107
+		return $this->_nullable;
108
+	}
109
+
110
+	/**
111
+	 * returns whether this field is an auto-increment field or not. If it is, then
112
+	 * on insertion it can be null. However, on updates it must be present.
113
+	 *
114
+	 * @return boolean
115
+	 */
116
+	function is_auto_increment()
117
+	{
118
+		return false;
119
+	}
120
+
121
+	/**
122
+	 * The default value in the model object's value domain. See lengthy comment about
123
+	 * value domains at the top of EEM_Base
124
+	 *
125
+	 * @return mixed
126
+	 */
127
+	function get_default_value()
128
+	{
129
+		return $this->_default_value;
130
+	}
131
+
132
+	/**
133
+	 * Returns the table alias joined to the table column, however this isn't the right
134
+	 * table alias if the aliased table is being joined to. In that case, you can use
135
+	 * EE_Model_Parser::extract_table_alias_model_relation_chain_prefix() to find the table's current alias
136
+	 * in the current query
137
+	 *
138
+	 * @return string
139
+	 */
140
+	function get_qualified_column()
141
+	{
142
+		return $this->get_table_alias() . "." . $this->get_table_column();
143
+	}
144
+
145
+	/**
146
+	 * When get() is called on a model object (eg EE_Event), before returning its value,
147
+	 * call this function on it, allowing us to customize the returned value based on
148
+	 * the field's type. Eg, we may want ot serialize it, strip tags, etc. By default,
149
+	 * we simply return it.
150
+	 *
151
+	 * @param mixed $value_of_field_on_model_object
152
+	 * @return mixed
153
+	 */
154
+	function prepare_for_get($value_of_field_on_model_object)
155
+	{
156
+		return $value_of_field_on_model_object;
157
+	}
158
+
159
+	/**
160
+	 * When inserting or updating a field on a model object, run this function on each
161
+	 * value to prepare it for insertion into the db. We may want to add slashes, serialize it, etc.
162
+	 * By default, we do nothing.
163
+	 *
164
+	 * @param mixed $value_of_field_on_model_object
165
+	 * @return mixed
166
+	 */
167
+	function prepare_for_use_in_db($value_of_field_on_model_object)
168
+	{
169
+		return $value_of_field_on_model_object;
170
+	}
171
+
172
+	/**
173
+	 * When creating a brand-new model object, or setting a particular value for one of its fields, this function
174
+	 * is called before setting it on the model object. We may want to strip slashes, unserialize the value, etc.
175
+	 * By default, we do nothing.
176
+	 *
177
+	 * @param mixed $value_inputted_for_field_on_model_object
178
+	 * @return mixed
179
+	 */
180
+	function prepare_for_set($value_inputted_for_field_on_model_object)
181
+	{
182
+		return $value_inputted_for_field_on_model_object;
183
+	}
184
+
185
+
186
+	/**
187
+	 * When instantiating a model object from DB results, this function is called before setting each field.
188
+	 * We may want to serialize the value, etc. By default, we return the value using prepare_for_set() method as that
189
+	 * is the one child classes will most often define.
190
+	 *
191
+	 * @param mixed $value_found_in_db_for_model_object
192
+	 * @return mixed
193
+	 */
194
+	function prepare_for_set_from_db($value_found_in_db_for_model_object)
195
+	{
196
+		return $this->prepare_for_set($value_found_in_db_for_model_object);
197
+	}
198
+
199
+	/**
200
+	 * When echoing a field's value on a model object, this function is run to prepare the value for presentation in a
201
+	 * webpage. For example, we may want to output floats with 2 decimal places by default, dates as "Monday Jan 12,
202
+	 * 2013, at 3:23pm" instead of
203
+	 * "8765678632", or any other modifications to how the value should be displayed, but not modified itself.
204
+	 *
205
+	 * @param mixed $value_on_field_to_be_outputted
206
+	 * @return mixed
207
+	 */
208
+	function prepare_for_pretty_echoing($value_on_field_to_be_outputted)
209
+	{
210
+		return $value_on_field_to_be_outputted;
211
+	}
212
+
213
+	abstract function get_wpdb_data_type();
214
+
215
+	/**
216
+	 * Some fields are in the database-only, (ie, used in queries etc), but shouldn't necessarily be part
217
+	 * of the model objects (ie, client code shouldn't care to ever see their value... if client code does
218
+	 * want to see their value, then they shouldn't be db-only fields!)
219
+	 * Eg, when doing events as custom post types, querying the post_type is essential, but
220
+	 * post_type is irrelevant for EE_Event objects (because they will ALL be of post_type 'esp_event').
221
+	 * By default, all fields aren't db-only.
222
+	 *
223
+	 * @return boolean
224
+	 */
225
+	function is_db_only_field()
226
+	{
227
+		return false;
228
+	}
229 229
 }
230 230
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -1,4 +1,4 @@  discard block
 block discarded – undo
1
-<?php if (! defined('EVENT_ESPRESSO_VERSION')) {
1
+<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) {
2 2
     exit('No direct script access allowed');
3 3
 }
4 4
 
@@ -139,7 +139,7 @@  discard block
 block discarded – undo
139 139
      */
140 140
     function get_qualified_column()
141 141
     {
142
-        return $this->get_table_alias() . "." . $this->get_table_column();
142
+        return $this->get_table_alias().".".$this->get_table_column();
143 143
     }
144 144
 
145 145
     /**
Please login to merge, or discard this patch.
core/db_models/fields/EE_Primary_Key_Field_Base.php 2 patches
Doc Comments   +1 added lines patch added patch discarded remove patch
@@ -7,6 +7,7 @@
 block discarded – undo
7 7
      *
8 8
      * @param string $table_column
9 9
      * @param string $nicename
10
+     * @param integer|null $default
10 11
      */
11 12
     public function __construct($table_column, $nicename, $default)
12 13
     {
Please login to merge, or discard this patch.
Indentation   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -2,24 +2,24 @@
 block discarded – undo
2 2
 
3 3
 abstract class EE_Primary_Key_Field_Base extends EE_Field_With_Model_Name
4 4
 {
5
-    /**
6
-     * Overrides parent so it doesn't need to provide so many non-applicable fields
7
-     *
8
-     * @param string $table_column
9
-     * @param string $nicename
10
-     */
11
-    public function __construct($table_column, $nicename, $default)
12
-    {
13
-        parent::__construct($table_column, $nicename, false, $default, null);
14
-    }
5
+	/**
6
+	 * Overrides parent so it doesn't need to provide so many non-applicable fields
7
+	 *
8
+	 * @param string $table_column
9
+	 * @param string $nicename
10
+	 */
11
+	public function __construct($table_column, $nicename, $default)
12
+	{
13
+		parent::__construct($table_column, $nicename, false, $default, null);
14
+	}
15 15
 
16
-    /**
17
-     * @param $table_alias
18
-     * @param $name
19
-     */
20
-    function _construct_finalize($table_alias, $name, $model_name)
21
-    {
22
-        $this->_model_name_pointed_to = $model_name;
23
-        parent::_construct_finalize($table_alias, $name, $model_name);
24
-    }
16
+	/**
17
+	 * @param $table_alias
18
+	 * @param $name
19
+	 */
20
+	function _construct_finalize($table_alias, $name, $model_name)
21
+	{
22
+		$this->_model_name_pointed_to = $model_name;
23
+		parent::_construct_finalize($table_alias, $name, $model_name);
24
+	}
25 25
 }
Please login to merge, or discard this patch.
core/db_models/fields/EE_Primary_Key_String_Field.php 2 patches
Doc Comments   +3 added lines patch added patch discarded remove patch
@@ -8,6 +8,9 @@
 block discarded – undo
8 8
         return '%s';
9 9
     }
10 10
 
11
+    /**
12
+     * @param string $table_column
13
+     */
11 14
     public function __construct($table_column, $nicename)
12 15
     {
13 16
         parent::__construct($table_column, $nicename, null);
Please login to merge, or discard this patch.
Indentation   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -3,27 +3,27 @@
 block discarded – undo
3 3
 
4 4
 class EE_Primary_Key_String_Field extends EE_Primary_Key_Field_Base
5 5
 {
6
-    function get_wpdb_data_type()
7
-    {
8
-        return '%s';
9
-    }
6
+	function get_wpdb_data_type()
7
+	{
8
+		return '%s';
9
+	}
10 10
 
11
-    public function __construct($table_column, $nicename)
12
-    {
13
-        parent::__construct($table_column, $nicename, null);
14
-    }
11
+	public function __construct($table_column, $nicename)
12
+	{
13
+		parent::__construct($table_column, $nicename, null);
14
+	}
15 15
 
16
-    /**
17
-     * removes all tags when setting
18
-     *
19
-     * @param string $value_inputted_for_field_on_model_object
20
-     * @return string
21
-     */
22
-    function prepare_for_set($value_inputted_for_field_on_model_object)
23
-    {
24
-        if ($this->is_model_obj_of_type_pointed_to($value_inputted_for_field_on_model_object)) {
25
-            $value_inputted_for_field_on_model_object = $value_inputted_for_field_on_model_object->ID();
26
-        }
27
-        return wp_strip_all_tags($value_inputted_for_field_on_model_object);
28
-    }
16
+	/**
17
+	 * removes all tags when setting
18
+	 *
19
+	 * @param string $value_inputted_for_field_on_model_object
20
+	 * @return string
21
+	 */
22
+	function prepare_for_set($value_inputted_for_field_on_model_object)
23
+	{
24
+		if ($this->is_model_obj_of_type_pointed_to($value_inputted_for_field_on_model_object)) {
25
+			$value_inputted_for_field_on_model_object = $value_inputted_for_field_on_model_object->ID();
26
+		}
27
+		return wp_strip_all_tags($value_inputted_for_field_on_model_object);
28
+	}
29 29
 }
30 30
\ No newline at end of file
Please login to merge, or discard this patch.
core/db_models/fields/EE_WP_Post_Status_Field.php 3 patches
Doc Comments   -2 removed lines patch added patch discarded remove patch
@@ -33,8 +33,6 @@
 block discarded – undo
33 33
      *                                    )
34 34
      *                                    )
35 35
      * @link http://codex.wordpress.org/Function_Reference/register_post_status for more info
36
-     * @param boolean $store_in_db_as_int By default, enums are stored as STRINGS in the DB. However, if this var is
37
-     *                                    set to true, it will be stored as an INT
38 36
      */
39 37
     function __construct($table_column, $nicename, $nullable, $default_value, $new_stati = array())
40 38
     {
Please login to merge, or discard this patch.
Indentation   +112 added lines, -112 removed lines patch added patch discarded remove patch
@@ -4,116 +4,116 @@
 block discarded – undo
4 4
 class EE_WP_Post_Status_Field extends EE_Enum_Text_Field
5 5
 {
6 6
 
7
-    protected $_wp_post_stati;
8
-
9
-
10
-    /**
11
-     * constructor
12
-     *
13
-     * @param string  $table_column       column on table
14
-     * @param string  $nicename           nice name for column(field)
15
-     * @param bool    $nullable           is this field nullable
16
-     * @param string  $default_value      default status
17
-     * @param array   $new_stati          If additional stati are to be used other than the default WP statuses then
18
-     *                                    they can be registered via this property.  The format of the array should be
19
-     *                                    as follows: array(
20
-     *                                    'status_reference' => array(
21
-     *                                    'label' => __('Status Reference Label', 'event_espresso')
22
-     *                                    'public' => true, //'Whether posts of this status should be shown on the
23
-     *                                    frontend of the site'
24
-     *                                    'exclude_from_search' => false, //'Whether posts of this status should be
25
-     *                                    excluded from wp searches'
26
-     *                                    'show_in_admin_all_list' => true, //whether posts of this status are included
27
-     *                                    in queries for the admin "all" view in list table views.
28
-     *                                    'show_in_admin_status_list' => true, //Show in the list of statuses with post
29
-     *                                    counts at the top of the admin list tables (i.e. Status Reference(2) )
30
-     *                                    'label_count' => _n_noop( 'Status Reference <span class="count">(%s)</span>',
31
-     *                                    'Status References <span class="count">(%s)</span>' ), //the text to display
32
-     *                                    on the admin screen( or you won't see your status count ).
33
-     *                                    )
34
-     *                                    )
35
-     * @link http://codex.wordpress.org/Function_Reference/register_post_status for more info
36
-     * @param boolean $store_in_db_as_int By default, enums are stored as STRINGS in the DB. However, if this var is
37
-     *                                    set to true, it will be stored as an INT
38
-     */
39
-    function __construct($table_column, $nicename, $nullable, $default_value, $new_stati = array())
40
-    {
41
-        $this->_register_new_stati($new_stati);
42
-        $this->_set_allowed_enum_values();
43
-        parent::__construct($table_column, $nicename, $nullable, $default_value, $this->_allowed_enum_values);
44
-    }
45
-
46
-
47
-    /**
48
-     * This registers any new statuses sent via the $new_stati array on construct
49
-     *
50
-     * @access protected
51
-     * @param  array $new_stati statuses
52
-     * @return void
53
-     */
54
-    protected function _register_new_stati($new_stati)
55
-    {
56
-
57
-        foreach ((array)$new_stati as $status_key => $status_args) {
58
-            $args = array(
59
-                'label'                     => isset($status_args['label']) ? $status_args['label'] : $status_key,
60
-                'public'                    => isset($status_args['public']) && is_bool($status_args['public']) ? $status_args['public'] : true,
61
-                'exclude_from_search'       => isset($status_args['exclude_from_search']) && is_bool($status_args['exclude_from_search']) ? $status_args['exclude_from_search'] : false,
62
-                'show_in_admin_all_list'    => isset($status_args['show_in_admin_all_list']) && is_bool($status_args['show_in_admin_all_list']) ? $status_args['show_in_admin_all_list'] : false,
63
-                'show_in_admin_status_list' => isset($status_args['show_in_admin_status_list']) && is_bool($status_args['show_in_admin_status_list']) ? $status_args['show_in_admin_status_list'] : true,
64
-                'label_count'               => isset($status_args['label_count']) ? $status_args['label_count'] : '',
65
-            );
66
-            register_post_status($status_key, $status_args);
67
-        }
68
-
69
-    }
70
-
71
-
72
-    /**
73
-     * This sets the _allowed_enum_values property using the $wp_post_stati array
74
-     *
75
-     * @access protected
76
-     * @regurn void
77
-     */
78
-    protected function _set_allowed_enum_values()
79
-    {
80
-        //first let's get the post_statuses
81
-        global $wp_post_statuses;
82
-        $this->_wp_post_stati = $wp_post_statuses;
83
-
84
-        foreach ($this->_wp_post_stati as $post_status => $args_object) {
85
-            $this->_allowed_enum_values[$post_status] = $args_object->label;
86
-        }
87
-
88
-    }
89
-
90
-    /**
91
-     * Before calling parent, first double-checks our list of acceptable post
92
-     * types is up-to-date
93
-     *
94
-     * @param string $value_inputted_for_field_on_model_object
95
-     * @return string
96
-     */
97
-    public function prepare_for_set($value_inputted_for_field_on_model_object)
98
-    {
99
-        $this->_set_allowed_enum_values();
100
-        return parent::prepare_for_set($value_inputted_for_field_on_model_object);
101
-    }
102
-
103
-
104
-
105
-    //helper methods for getting various $wp_post_statuses stuff.
106
-
107
-    /**
108
-     * This just returns the status object for the given status
109
-     *
110
-     * @access public
111
-     * @see    wp_register_post_status in wp-includes/post.php for a list of properties of the status object
112
-     * @param  string $status What status object you want
113
-     * @return std_object         the status object or FALSE if it doesn't exist.
114
-     */
115
-    public function get_status_object($status)
116
-    {
117
-        return isset($this->_wp_post_stati[$status]) ? $this->_wp_post_stati[$status] : false;
118
-    }
7
+	protected $_wp_post_stati;
8
+
9
+
10
+	/**
11
+	 * constructor
12
+	 *
13
+	 * @param string  $table_column       column on table
14
+	 * @param string  $nicename           nice name for column(field)
15
+	 * @param bool    $nullable           is this field nullable
16
+	 * @param string  $default_value      default status
17
+	 * @param array   $new_stati          If additional stati are to be used other than the default WP statuses then
18
+	 *                                    they can be registered via this property.  The format of the array should be
19
+	 *                                    as follows: array(
20
+	 *                                    'status_reference' => array(
21
+	 *                                    'label' => __('Status Reference Label', 'event_espresso')
22
+	 *                                    'public' => true, //'Whether posts of this status should be shown on the
23
+	 *                                    frontend of the site'
24
+	 *                                    'exclude_from_search' => false, //'Whether posts of this status should be
25
+	 *                                    excluded from wp searches'
26
+	 *                                    'show_in_admin_all_list' => true, //whether posts of this status are included
27
+	 *                                    in queries for the admin "all" view in list table views.
28
+	 *                                    'show_in_admin_status_list' => true, //Show in the list of statuses with post
29
+	 *                                    counts at the top of the admin list tables (i.e. Status Reference(2) )
30
+	 *                                    'label_count' => _n_noop( 'Status Reference <span class="count">(%s)</span>',
31
+	 *                                    'Status References <span class="count">(%s)</span>' ), //the text to display
32
+	 *                                    on the admin screen( or you won't see your status count ).
33
+	 *                                    )
34
+	 *                                    )
35
+	 * @link http://codex.wordpress.org/Function_Reference/register_post_status for more info
36
+	 * @param boolean $store_in_db_as_int By default, enums are stored as STRINGS in the DB. However, if this var is
37
+	 *                                    set to true, it will be stored as an INT
38
+	 */
39
+	function __construct($table_column, $nicename, $nullable, $default_value, $new_stati = array())
40
+	{
41
+		$this->_register_new_stati($new_stati);
42
+		$this->_set_allowed_enum_values();
43
+		parent::__construct($table_column, $nicename, $nullable, $default_value, $this->_allowed_enum_values);
44
+	}
45
+
46
+
47
+	/**
48
+	 * This registers any new statuses sent via the $new_stati array on construct
49
+	 *
50
+	 * @access protected
51
+	 * @param  array $new_stati statuses
52
+	 * @return void
53
+	 */
54
+	protected function _register_new_stati($new_stati)
55
+	{
56
+
57
+		foreach ((array)$new_stati as $status_key => $status_args) {
58
+			$args = array(
59
+				'label'                     => isset($status_args['label']) ? $status_args['label'] : $status_key,
60
+				'public'                    => isset($status_args['public']) && is_bool($status_args['public']) ? $status_args['public'] : true,
61
+				'exclude_from_search'       => isset($status_args['exclude_from_search']) && is_bool($status_args['exclude_from_search']) ? $status_args['exclude_from_search'] : false,
62
+				'show_in_admin_all_list'    => isset($status_args['show_in_admin_all_list']) && is_bool($status_args['show_in_admin_all_list']) ? $status_args['show_in_admin_all_list'] : false,
63
+				'show_in_admin_status_list' => isset($status_args['show_in_admin_status_list']) && is_bool($status_args['show_in_admin_status_list']) ? $status_args['show_in_admin_status_list'] : true,
64
+				'label_count'               => isset($status_args['label_count']) ? $status_args['label_count'] : '',
65
+			);
66
+			register_post_status($status_key, $status_args);
67
+		}
68
+
69
+	}
70
+
71
+
72
+	/**
73
+	 * This sets the _allowed_enum_values property using the $wp_post_stati array
74
+	 *
75
+	 * @access protected
76
+	 * @regurn void
77
+	 */
78
+	protected function _set_allowed_enum_values()
79
+	{
80
+		//first let's get the post_statuses
81
+		global $wp_post_statuses;
82
+		$this->_wp_post_stati = $wp_post_statuses;
83
+
84
+		foreach ($this->_wp_post_stati as $post_status => $args_object) {
85
+			$this->_allowed_enum_values[$post_status] = $args_object->label;
86
+		}
87
+
88
+	}
89
+
90
+	/**
91
+	 * Before calling parent, first double-checks our list of acceptable post
92
+	 * types is up-to-date
93
+	 *
94
+	 * @param string $value_inputted_for_field_on_model_object
95
+	 * @return string
96
+	 */
97
+	public function prepare_for_set($value_inputted_for_field_on_model_object)
98
+	{
99
+		$this->_set_allowed_enum_values();
100
+		return parent::prepare_for_set($value_inputted_for_field_on_model_object);
101
+	}
102
+
103
+
104
+
105
+	//helper methods for getting various $wp_post_statuses stuff.
106
+
107
+	/**
108
+	 * This just returns the status object for the given status
109
+	 *
110
+	 * @access public
111
+	 * @see    wp_register_post_status in wp-includes/post.php for a list of properties of the status object
112
+	 * @param  string $status What status object you want
113
+	 * @return std_object         the status object or FALSE if it doesn't exist.
114
+	 */
115
+	public function get_status_object($status)
116
+	{
117
+		return isset($this->_wp_post_stati[$status]) ? $this->_wp_post_stati[$status] : false;
118
+	}
119 119
 }
120 120
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-require_once(EE_MODELS . 'fields/EE_Enum_Text_Field.php');
2
+require_once(EE_MODELS.'fields/EE_Enum_Text_Field.php');
3 3
 
4 4
 class EE_WP_Post_Status_Field extends EE_Enum_Text_Field
5 5
 {
@@ -54,7 +54,7 @@  discard block
 block discarded – undo
54 54
     protected function _register_new_stati($new_stati)
55 55
     {
56 56
 
57
-        foreach ((array)$new_stati as $status_key => $status_args) {
57
+        foreach ((array) $new_stati as $status_key => $status_args) {
58 58
             $args = array(
59 59
                 'label'                     => isset($status_args['label']) ? $status_args['label'] : $status_key,
60 60
                 'public'                    => isset($status_args['public']) && is_bool($status_args['public']) ? $status_args['public'] : true,
Please login to merge, or discard this patch.
core/db_models/fields/EE_Full_HTML_Field.php 1 patch
Indentation   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -15,21 +15,21 @@
 block discarded – undo
15 15
 {
16 16
 
17 17
 
18
-    /**
19
-     * Does shortcodes and auto-paragraphs the content (unless schema is 'no_wpautop')
20
-     *
21
-     * @param type $value_on_field_to_be_outputted
22
-     * @param type $schema
23
-     * @return string
24
-     */
25
-    function prepare_for_pretty_echoing($value_on_field_to_be_outputted, $schema = null)
26
-    {
27
-        if ($schema == 'form_input') {
28
-            return parent::prepare_for_pretty_echoing($value_on_field_to_be_outputted, $schema);
29
-        } elseif ($schema == 'no_wpautop') {
30
-            return do_shortcode(parent::prepare_for_pretty_echoing($value_on_field_to_be_outputted, $schema));
31
-        } else {
32
-            return wpautop(do_shortcode(parent::prepare_for_pretty_echoing($value_on_field_to_be_outputted, $schema)));
33
-        }
34
-    }
18
+	/**
19
+	 * Does shortcodes and auto-paragraphs the content (unless schema is 'no_wpautop')
20
+	 *
21
+	 * @param type $value_on_field_to_be_outputted
22
+	 * @param type $schema
23
+	 * @return string
24
+	 */
25
+	function prepare_for_pretty_echoing($value_on_field_to_be_outputted, $schema = null)
26
+	{
27
+		if ($schema == 'form_input') {
28
+			return parent::prepare_for_pretty_echoing($value_on_field_to_be_outputted, $schema);
29
+		} elseif ($schema == 'no_wpautop') {
30
+			return do_shortcode(parent::prepare_for_pretty_echoing($value_on_field_to_be_outputted, $schema));
31
+		} else {
32
+			return wpautop(do_shortcode(parent::prepare_for_pretty_echoing($value_on_field_to_be_outputted, $schema)));
33
+		}
34
+	}
35 35
 }
36 36
\ No newline at end of file
Please login to merge, or discard this patch.
core/db_models/fields/EE_Infinite_Integer_Field.php 1 patch
Indentation   +61 added lines, -61 removed lines patch added patch discarded remove patch
@@ -9,69 +9,69 @@
 block discarded – undo
9 9
  */
10 10
 class EE_Infinite_Integer_Field extends EE_Model_Field_Base
11 11
 {
12
-    function get_wpdb_data_type()
13
-    {
14
-        return '%d';
15
-    }
12
+	function get_wpdb_data_type()
13
+	{
14
+		return '%d';
15
+	}
16 16
 
17
-    function prepare_for_use_in_db($value_of_field_on_model_object)
18
-    {
19
-        if ($value_of_field_on_model_object === EE_INF) {
20
-            return EE_INF_IN_DB;
21
-        } else {
22
-            return intval($value_of_field_on_model_object);
23
-        }
24
-    }
17
+	function prepare_for_use_in_db($value_of_field_on_model_object)
18
+	{
19
+		if ($value_of_field_on_model_object === EE_INF) {
20
+			return EE_INF_IN_DB;
21
+		} else {
22
+			return intval($value_of_field_on_model_object);
23
+		}
24
+	}
25 25
 
26
-    function prepare_for_set($value_inputted_for_field_on_model_object)
27
-    {
28
-        if ($value_inputted_for_field_on_model_object === EE_INF_IN_DB ||
29
-            $value_inputted_for_field_on_model_object === EE_INF ||
30
-            $value_inputted_for_field_on_model_object === "EE_INF" ||
31
-            $value_inputted_for_field_on_model_object === ""
32
-        ) {
33
-            return EE_INF;
34
-        } else {
35
-            return intval($value_inputted_for_field_on_model_object);
36
-        }
37
-    }
26
+	function prepare_for_set($value_inputted_for_field_on_model_object)
27
+	{
28
+		if ($value_inputted_for_field_on_model_object === EE_INF_IN_DB ||
29
+			$value_inputted_for_field_on_model_object === EE_INF ||
30
+			$value_inputted_for_field_on_model_object === "EE_INF" ||
31
+			$value_inputted_for_field_on_model_object === ""
32
+		) {
33
+			return EE_INF;
34
+		} else {
35
+			return intval($value_inputted_for_field_on_model_object);
36
+		}
37
+	}
38 38
 
39
-    function prepare_for_set_from_db($value_inputted_for_field_on_model_object)
40
-    {
41
-        $intval = intval($value_inputted_for_field_on_model_object);
42
-        if ($intval == EE_INF_IN_DB) {
43
-            return EE_INF;
44
-        } else {
45
-            return $intval;
46
-        }
47
-    }
39
+	function prepare_for_set_from_db($value_inputted_for_field_on_model_object)
40
+	{
41
+		$intval = intval($value_inputted_for_field_on_model_object);
42
+		if ($intval == EE_INF_IN_DB) {
43
+			return EE_INF;
44
+		} else {
45
+			return $intval;
46
+		}
47
+	}
48 48
 
49
-    /**
50
-     * For outputting this field's value. If you want to output it into an input or something,
51
-     * use $schema=='input', as it will replace EE_INF with ''. If you want a readable version, use $schema=='text'
52
-     * as it will replace EE_INF with i18n Infinite
53
-     *
54
-     * @param type   $value_on_field_to_be_outputted
55
-     * @param string $schema input, symbol, text; or any string you want to show if the value equals EE_INF
56
-     * @return string
57
-     */
58
-    function prepare_for_pretty_echoing($value_on_field_to_be_outputted, $schema = null)
59
-    {
60
-        if ($value_on_field_to_be_outputted === EE_INF) {
61
-            switch ($schema) {
62
-                case 'input':
63
-                case 'form_input':
64
-                    return '';
65
-                case 'symbol':
66
-                    return "&infin;";
67
-                case 'text':
68
-                case null:
69
-                    return __("Unlimited", "event_espresso");
70
-                default:
71
-                    return $schema;
72
-            }
73
-        } else {
74
-            return $value_on_field_to_be_outputted;
75
-        }
76
-    }
49
+	/**
50
+	 * For outputting this field's value. If you want to output it into an input or something,
51
+	 * use $schema=='input', as it will replace EE_INF with ''. If you want a readable version, use $schema=='text'
52
+	 * as it will replace EE_INF with i18n Infinite
53
+	 *
54
+	 * @param type   $value_on_field_to_be_outputted
55
+	 * @param string $schema input, symbol, text; or any string you want to show if the value equals EE_INF
56
+	 * @return string
57
+	 */
58
+	function prepare_for_pretty_echoing($value_on_field_to_be_outputted, $schema = null)
59
+	{
60
+		if ($value_on_field_to_be_outputted === EE_INF) {
61
+			switch ($schema) {
62
+				case 'input':
63
+				case 'form_input':
64
+					return '';
65
+				case 'symbol':
66
+					return "&infin;";
67
+				case 'text':
68
+				case null:
69
+					return __("Unlimited", "event_espresso");
70
+				default:
71
+					return $schema;
72
+			}
73
+		} else {
74
+			return $value_on_field_to_be_outputted;
75
+		}
76
+	}
77 77
 }
Please login to merge, or discard this patch.
core/db_models/fields/EE_Money_Field.php 1 patch
Indentation   +51 added lines, -51 removed lines patch added patch discarded remove patch
@@ -6,63 +6,63 @@
 block discarded – undo
6 6
  */
7 7
 class EE_Money_Field extends EE_Float_Field
8 8
 {
9
-    function get_wpdb_data_type()
10
-    {
11
-        return '%f';
12
-    }
9
+	function get_wpdb_data_type()
10
+	{
11
+		return '%f';
12
+	}
13 13
 
14
-    /**
15
-     * Schemas:
16
-     *    'localized_float': "3,023.00"
17
-     *    'no_currency_code': "$3,023.00"
18
-     *    null: "$3,023.00<span>USD</span>"
19
-     *
20
-     * @param type $value_on_field_to_be_outputted
21
-     * @param type $schema
22
-     * @return string
23
-     */
24
-    function prepare_for_pretty_echoing($value_on_field_to_be_outputted, $schema = null)
25
-    {
26
-        $pretty_float = parent::prepare_for_pretty_echoing($value_on_field_to_be_outputted);
14
+	/**
15
+	 * Schemas:
16
+	 *    'localized_float': "3,023.00"
17
+	 *    'no_currency_code': "$3,023.00"
18
+	 *    null: "$3,023.00<span>USD</span>"
19
+	 *
20
+	 * @param type $value_on_field_to_be_outputted
21
+	 * @param type $schema
22
+	 * @return string
23
+	 */
24
+	function prepare_for_pretty_echoing($value_on_field_to_be_outputted, $schema = null)
25
+	{
26
+		$pretty_float = parent::prepare_for_pretty_echoing($value_on_field_to_be_outputted);
27 27
 
28
-        if ($schema == 'localized_float') {
29
-            return $pretty_float;
30
-        }
31
-        if ($schema == 'no_currency_code') {
28
+		if ($schema == 'localized_float') {
29
+			return $pretty_float;
30
+		}
31
+		if ($schema == 'no_currency_code') {
32 32
 //			echo "schema no currency!";
33
-            $display_code = false;
34
-        } else {
35
-            $display_code = true;
36
-        }
37
-        //we don't use the $pretty_float because format_currency will take care of it.
38
-        return EEH_Template::format_currency($value_on_field_to_be_outputted, false, $display_code);
39
-    }
33
+			$display_code = false;
34
+		} else {
35
+			$display_code = true;
36
+		}
37
+		//we don't use the $pretty_float because format_currency will take care of it.
38
+		return EEH_Template::format_currency($value_on_field_to_be_outputted, false, $display_code);
39
+	}
40 40
 
41
-    /**
42
-     * If provided witha string, strips out money-related formatting to turn it into a proper float.
43
-     * Rounds the float to the correct number of decimal places for this country's currency.
44
-     * Also, interprets periods and commas according to the country's currency settings.
45
-     * So if you want to pass in a string that NEEDS to interpret periods as decimal marks, call floatval() on it first.
46
-     *
47
-     * @param type $value_inputted_for_field_on_model_object
48
-     * @return float
49
-     */
50
-    function prepare_for_set($value_inputted_for_field_on_model_object)
51
-    {
52
-        //remove any currencies etc.
41
+	/**
42
+	 * If provided witha string, strips out money-related formatting to turn it into a proper float.
43
+	 * Rounds the float to the correct number of decimal places for this country's currency.
44
+	 * Also, interprets periods and commas according to the country's currency settings.
45
+	 * So if you want to pass in a string that NEEDS to interpret periods as decimal marks, call floatval() on it first.
46
+	 *
47
+	 * @param type $value_inputted_for_field_on_model_object
48
+	 * @return float
49
+	 */
50
+	function prepare_for_set($value_inputted_for_field_on_model_object)
51
+	{
52
+		//remove any currencies etc.
53 53
 //		if(is_string($value_inputted_for_field_on_model_object)){
54 54
 //			$value_inputted_for_field_on_model_object = preg_replace("/[^0-9,.]/", "", $value_inputted_for_field_on_model_object);
55 55
 //		}
56
-        //now it's a float-style string or number
57
-        $float_val = parent::prepare_for_set($value_inputted_for_field_on_model_object);
58
-        //round to the correctly number of decimal places for this  currency
59
-        $rounded_value = round($float_val, EE_Registry::instance()->CFG->currency->dec_plc);
60
-        return $rounded_value;
61
-    }
56
+		//now it's a float-style string or number
57
+		$float_val = parent::prepare_for_set($value_inputted_for_field_on_model_object);
58
+		//round to the correctly number of decimal places for this  currency
59
+		$rounded_value = round($float_val, EE_Registry::instance()->CFG->currency->dec_plc);
60
+		return $rounded_value;
61
+	}
62 62
 
63
-    function prepare_for_get($value_of_field_on_model_object)
64
-    {
65
-        $c = EE_Registry::instance()->CFG->currency;
66
-        return round(parent::prepare_for_get($value_of_field_on_model_object), $c->dec_plc);
67
-    }
63
+	function prepare_for_get($value_of_field_on_model_object)
64
+	{
65
+		$c = EE_Registry::instance()->CFG->currency;
66
+		return round(parent::prepare_for_get($value_of_field_on_model_object), $c->dec_plc);
67
+	}
68 68
 }
69 69
\ No newline at end of file
Please login to merge, or discard this patch.