Completed
Branch FET-9222-rest-api-writes (9a0487)
by
unknown
71:42 queued 58:38
created
core/services/notices/ConvertNoticesToEeErrors.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -43,7 +43,7 @@
 block discarded – undo
43 43
             $error_string = esc_html__('The following errors occurred:', 'event_espresso');
44 44
             foreach ($notices->getError() as $notice) {
45 45
                 if ($this->getThrowExceptions()) {
46
-                    $error_string .= '<br />' . $notice->message();
46
+                    $error_string .= '<br />'.$notice->message();
47 47
                 } else {
48 48
                     EE_Error::add_error(
49 49
                         $notice->message(),
Please login to merge, or discard this patch.
Indentation   +50 added lines, -50 removed lines patch added patch discarded remove patch
@@ -19,56 +19,56 @@
 block discarded – undo
19 19
 class ConvertNoticesToEeErrors extends NoticeConverter
20 20
 {
21 21
 
22
-    /**
23
-     * Converts Notice objects into EE_Error notifications
24
-     *
25
-     * @param NoticesContainerInterface $notices
26
-     * @throws EE_Error
27
-     */
28
-    public function process(NoticesContainerInterface $notices)
29
-    {
30
-        $this->setNotices($notices);
31
-        $notices = $this->getNotices();
32
-        if ($notices->hasAttention()) {
33
-            foreach ($notices->getAttention() as $notice) {
34
-                EE_Error::add_attention(
35
-                    $notice->message(),
36
-                    $notice->file(),
37
-                    $notice->func(),
38
-                    $notice->line()
39
-                );
40
-            }
41
-        }
42
-        if ($notices->hasError()) {
43
-            $error_string = esc_html__('The following errors occurred:', 'event_espresso');
44
-            foreach ($notices->getError() as $notice) {
45
-                if ($this->getThrowExceptions()) {
46
-                    $error_string .= '<br />' . $notice->message();
47
-                } else {
48
-                    EE_Error::add_error(
49
-                        $notice->message(),
50
-                        $notice->file(),
51
-                        $notice->func(),
52
-                        $notice->line()
53
-                    );
54
-                }
55
-            }
56
-            if ($this->getThrowExceptions()) {
57
-                throw new EE_Error($error_string);
58
-            }
59
-        }
60
-        if ($notices->hasSuccess()) {
61
-            foreach ($notices->getSuccess() as $notice) {
62
-                EE_Error::add_success(
63
-                    $notice->message(),
64
-                    $notice->file(),
65
-                    $notice->func(),
66
-                    $notice->line()
67
-                );
68
-            }
69
-        }
70
-        $this->clearNotices();
71
-    }
22
+	/**
23
+	 * Converts Notice objects into EE_Error notifications
24
+	 *
25
+	 * @param NoticesContainerInterface $notices
26
+	 * @throws EE_Error
27
+	 */
28
+	public function process(NoticesContainerInterface $notices)
29
+	{
30
+		$this->setNotices($notices);
31
+		$notices = $this->getNotices();
32
+		if ($notices->hasAttention()) {
33
+			foreach ($notices->getAttention() as $notice) {
34
+				EE_Error::add_attention(
35
+					$notice->message(),
36
+					$notice->file(),
37
+					$notice->func(),
38
+					$notice->line()
39
+				);
40
+			}
41
+		}
42
+		if ($notices->hasError()) {
43
+			$error_string = esc_html__('The following errors occurred:', 'event_espresso');
44
+			foreach ($notices->getError() as $notice) {
45
+				if ($this->getThrowExceptions()) {
46
+					$error_string .= '<br />' . $notice->message();
47
+				} else {
48
+					EE_Error::add_error(
49
+						$notice->message(),
50
+						$notice->file(),
51
+						$notice->func(),
52
+						$notice->line()
53
+					);
54
+				}
55
+			}
56
+			if ($this->getThrowExceptions()) {
57
+				throw new EE_Error($error_string);
58
+			}
59
+		}
60
+		if ($notices->hasSuccess()) {
61
+			foreach ($notices->getSuccess() as $notice) {
62
+				EE_Error::add_success(
63
+					$notice->message(),
64
+					$notice->file(),
65
+					$notice->func(),
66
+					$notice->line()
67
+				);
68
+			}
69
+		}
70
+		$this->clearNotices();
71
+	}
72 72
 
73 73
 
74 74
 }
Please login to merge, or discard this patch.
core/services/notices/NoticeConverterInterface.php 2 patches
Doc Comments   +2 added lines, -1 removed lines patch added patch discarded remove patch
@@ -24,6 +24,7 @@  discard block
 block discarded – undo
24 24
 
25 25
     /**
26 26
      * @param bool $throw_exceptions
27
+     * @return void
27 28
      */
28 29
     public function setThrowExceptions($throw_exceptions);
29 30
 
@@ -41,7 +42,7 @@  discard block
 block discarded – undo
41 42
     public function process(NoticesContainerInterface $notices);
42 43
 
43 44
     /**
44
-     * @return void;
45
+     * @return void
45 46
      */
46 47
     public function clearNotices();
47 48
 
Please login to merge, or discard this patch.
Indentation   +27 added lines, -27 removed lines patch added patch discarded remove patch
@@ -17,33 +17,33 @@
 block discarded – undo
17 17
 interface NoticeConverterInterface
18 18
 {
19 19
 
20
-    /**
21
-     * @return NoticesContainerInterface
22
-     */
23
-    public function getNotices();
24
-
25
-    /**
26
-     * @param bool $throw_exceptions
27
-     */
28
-    public function setThrowExceptions($throw_exceptions);
29
-
30
-    /**
31
-     * @return bool
32
-     */
33
-    public function getThrowExceptions();
34
-
35
-    /**
36
-     * Converts NoticesContainerInterface objects into other format
37
-     *
38
-     * @param NoticesContainerInterface $notices
39
-     * @return
40
-     */
41
-    public function process(NoticesContainerInterface $notices);
42
-
43
-    /**
44
-     * @return void;
45
-     */
46
-    public function clearNotices();
20
+	/**
21
+	 * @return NoticesContainerInterface
22
+	 */
23
+	public function getNotices();
24
+
25
+	/**
26
+	 * @param bool $throw_exceptions
27
+	 */
28
+	public function setThrowExceptions($throw_exceptions);
29
+
30
+	/**
31
+	 * @return bool
32
+	 */
33
+	public function getThrowExceptions();
34
+
35
+	/**
36
+	 * Converts NoticesContainerInterface objects into other format
37
+	 *
38
+	 * @param NoticesContainerInterface $notices
39
+	 * @return
40
+	 */
41
+	public function process(NoticesContainerInterface $notices);
42
+
43
+	/**
44
+	 * @return void;
45
+	 */
46
+	public function clearNotices();
47 47
 
48 48
 
49 49
 }
50 50
\ No newline at end of file
Please login to merge, or discard this patch.
core/services/notices/NoticeConverter.php 1 patch
Indentation   +54 added lines, -54 removed lines patch added patch discarded remove patch
@@ -17,79 +17,79 @@
 block discarded – undo
17 17
 abstract class NoticeConverter implements NoticeConverterInterface
18 18
 {
19 19
 
20
-    /**
21
-     * @var NoticesContainerInterface $notices
22
-     */
23
-    private $notices;
20
+	/**
21
+	 * @var NoticesContainerInterface $notices
22
+	 */
23
+	private $notices;
24 24
 
25
-    /**
26
-     * if set to true, then errors will be thrown as exceptions
27
-     *
28
-     * @var boolean $throw_exceptions
29
-     */
30
-    private $throw_exceptions;
25
+	/**
26
+	 * if set to true, then errors will be thrown as exceptions
27
+	 *
28
+	 * @var boolean $throw_exceptions
29
+	 */
30
+	private $throw_exceptions;
31 31
 
32 32
 
33 33
 
34
-    /**
35
-     * NoticeConverter constructor.
36
-     *
37
-     * @param bool                      $throw_exceptions
38
-     */
39
-    public function __construct($throw_exceptions = false)
40
-    {
41
-        $this->throw_exceptions = $throw_exceptions;
42
-    }
34
+	/**
35
+	 * NoticeConverter constructor.
36
+	 *
37
+	 * @param bool                      $throw_exceptions
38
+	 */
39
+	public function __construct($throw_exceptions = false)
40
+	{
41
+		$this->throw_exceptions = $throw_exceptions;
42
+	}
43 43
 
44 44
 
45 45
 
46
-    /**
47
-     * @return NoticesContainerInterface
48
-     */
49
-    public function getNotices()
50
-    {
51
-        return $this->notices;
52
-    }
46
+	/**
47
+	 * @return NoticesContainerInterface
48
+	 */
49
+	public function getNotices()
50
+	{
51
+		return $this->notices;
52
+	}
53 53
 
54 54
 
55 55
 
56
-    /**
57
-     * @param NoticesContainerInterface $notices
58
-     */
59
-    protected function setNotices(NoticesContainerInterface $notices)
60
-    {
61
-        $this->notices = $notices;
62
-    }
56
+	/**
57
+	 * @param NoticesContainerInterface $notices
58
+	 */
59
+	protected function setNotices(NoticesContainerInterface $notices)
60
+	{
61
+		$this->notices = $notices;
62
+	}
63 63
 
64 64
 
65 65
 
66
-    /**
67
-     * @return bool
68
-     */
69
-    public function getThrowExceptions()
70
-    {
71
-        return $this->throw_exceptions;
72
-    }
66
+	/**
67
+	 * @return bool
68
+	 */
69
+	public function getThrowExceptions()
70
+	{
71
+		return $this->throw_exceptions;
72
+	}
73 73
 
74 74
 
75 75
 
76
-    /**
77
-     * @param bool $throw_exceptions
78
-     */
79
-    public function setThrowExceptions($throw_exceptions)
80
-    {
81
-        $this->throw_exceptions = filter_var($throw_exceptions, FILTER_VALIDATE_BOOLEAN);
82
-    }
76
+	/**
77
+	 * @param bool $throw_exceptions
78
+	 */
79
+	public function setThrowExceptions($throw_exceptions)
80
+	{
81
+		$this->throw_exceptions = filter_var($throw_exceptions, FILTER_VALIDATE_BOOLEAN);
82
+	}
83 83
 
84 84
 
85 85
 
86
-    /**
87
-     * @return void;
88
-     */
89
-    public function clearNotices()
90
-    {
91
-        $this->notices = null;
92
-    }
86
+	/**
87
+	 * @return void;
88
+	 */
89
+	public function clearNotices()
90
+	{
91
+		$this->notices = null;
92
+	}
93 93
 
94 94
 
95 95
 }
Please login to merge, or discard this patch.
core/db_classes/EE_Event.class.php 3 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -818,7 +818,7 @@  discard block
 block discarded – undo
818 818
     /**
819 819
      * calculate spaces remaining based on "saleable" tickets
820 820
      *
821
-     * @param array $tickets
821
+     * @param EE_Base_Class[] $tickets
822 822
      * @param bool $filtered
823 823
      * @return int|float
824 824
      * @throws EE_Error
@@ -1174,7 +1174,7 @@  discard block
 block discarded – undo
1174 1174
      *
1175 1175
      * @access public
1176 1176
      * @param boolean $echo whether to return (FALSE), or echo out the result (TRUE)
1177
-     * @return mixed void|string
1177
+     * @return string void|string
1178 1178
      * @throws EE_Error
1179 1179
      */
1180 1180
     public function pretty_active_status($echo = true)
Please login to merge, or discard this patch.
Indentation   +1399 added lines, -1399 removed lines patch added patch discarded remove patch
@@ -1,7 +1,7 @@  discard block
 block discarded – undo
1 1
 <?php use EventEspresso\core\exceptions\InvalidStatusException;
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
 
@@ -15,1403 +15,1403 @@  discard block
 block discarded – undo
15 15
 class EE_Event extends EE_CPT_Base implements EEI_Line_Item_Object, EEI_Admin_Links, EEI_Has_Icon, EEI_Event
16 16
 {
17 17
 
18
-    /**
19
-     * cached value for the the logical active status for the event
20
-     *
21
-     * @see get_active_status()
22
-     * @var string
23
-     */
24
-    protected $_active_status = '';
25
-
26
-    /**
27
-     * This is just used for caching the Primary Datetime for the Event on initial retrieval
28
-     *
29
-     * @var EE_Datetime
30
-     */
31
-    protected $_Primary_Datetime;
32
-
33
-
34
-    /**
35
-     * @param array $props_n_values incoming values
36
-     * @param string $timezone incoming timezone (if not set the timezone set for the website will be
37
-     *                                        used.)
38
-     * @param array $date_formats incoming date_formats in an array where the first value is the
39
-     *                                        date_format and the second value is the time format
40
-     * @return EE_Event
41
-     * @throws EE_Error
42
-     */
43
-    public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array())
44
-    {
45
-        $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats);
46
-        return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats);
47
-    }
48
-
49
-
50
-    /**
51
-     * @param array $props_n_values incoming values from the database
52
-     * @param string $timezone incoming timezone as set by the model.  If not set the timezone for
53
-     *                                the website will be used.
54
-     * @return EE_Event
55
-     * @throws EE_Error
56
-     */
57
-    public static function new_instance_from_db($props_n_values = array(), $timezone = null)
58
-    {
59
-        return new self($props_n_values, true, $timezone);
60
-    }
61
-
62
-
63
-    /**
64
-     * Overrides parent set() method so that all calls to set( 'status', $status ) can be routed to internal methods
65
-     *
66
-     * @param string $field_name
67
-     * @param mixed $field_value
68
-     * @param bool $use_default
69
-     * @throws EE_Error
70
-     */
71
-    public function set($field_name, $field_value, $use_default = false)
72
-    {
73
-        switch ($field_name) {
74
-            case 'status' :
75
-                $this->set_status($field_value, $use_default);
76
-                break;
77
-            default :
78
-                parent::set($field_name, $field_value, $use_default);
79
-        }
80
-    }
81
-
82
-
83
-    /**
84
-     *    set_status
85
-     * Checks if event status is being changed to SOLD OUT
86
-     * and updates event meta data with previous event status
87
-     * so that we can revert things if/when the event is no longer sold out
88
-     *
89
-     * @access public
90
-     * @param string $new_status
91
-     * @param bool $use_default
92
-     * @return void
93
-     * @throws EE_Error
94
-     */
95
-    public function set_status($new_status = null, $use_default = false)
96
-    {
97
-        // if nothing is set, and we aren't explicitly wanting to reset the status, then just leave
98
-        if (empty($new_status) && !$use_default) {
99
-            return;
100
-        }
101
-        // get current Event status
102
-        $old_status = $this->status();
103
-        // if status has changed
104
-        if ($old_status !== $new_status) {
105
-            // TO sold_out
106
-            if ($new_status === EEM_Event::sold_out) {
107
-                // save the previous event status so that we can revert if the event is no longer sold out
108
-                $this->add_post_meta('_previous_event_status', $old_status);
109
-                do_action('AHEE__EE_Event__set_status__to_sold_out', $this, $old_status, $new_status);
110
-                // OR FROM  sold_out
111
-            } else if ($old_status === EEM_Event::sold_out) {
112
-                $this->delete_post_meta('_previous_event_status');
113
-                do_action('AHEE__EE_Event__set_status__from_sold_out', $this, $old_status, $new_status);
114
-            }
115
-            // update status
116
-            parent::set('status', $new_status, $use_default);
117
-            do_action('AHEE__EE_Event__set_status__after_update', $this);
118
-            return;
119
-        }
120
-        // even though the old value matches the new value, it's still good to
121
-        // allow the parent set method to have a say
122
-        parent::set('status', $new_status, $use_default);
123
-    }
124
-
125
-
126
-    /**
127
-     * Gets all the datetimes for this event
128
-     *
129
-     * @param array $query_params like EEM_Base::get_all
130
-     * @return EE_Base_Class[]|EE_Datetime[]
131
-     * @throws EE_Error
132
-     */
133
-    public function datetimes($query_params = array())
134
-    {
135
-        return $this->get_many_related('Datetime', $query_params);
136
-    }
137
-
138
-
139
-    /**
140
-     * Gets all the datetimes for this event, ordered by DTT_EVT_start in ascending order
141
-     *
142
-     * @return EE_Base_Class[]|EE_Datetime[]
143
-     * @throws EE_Error
144
-     */
145
-    public function datetimes_in_chronological_order()
146
-    {
147
-        return $this->get_many_related('Datetime', array('order_by' => array('DTT_EVT_start' => 'ASC')));
148
-    }
149
-
150
-
151
-    /**
152
-     * Gets all the datetimes for this event, ordered by the DTT_order on the datetime.
153
-     * @darren, we should probably UNSET timezone on the EEM_Datetime model
154
-     * after running our query, so that this timezone isn't set for EVERY query
155
-     * on EEM_Datetime for the rest of the request, no?
156
-     *
157
-     * @param boolean $show_expired whether or not to include expired events
158
-     * @param boolean $show_deleted whether or not to include deleted events
159
-     * @param null $limit
160
-     * @return EE_Datetime[]
161
-     * @throws EE_Error
162
-     */
163
-    public function datetimes_ordered($show_expired = true, $show_deleted = false, $limit = null)
164
-    {
165
-        return EEM_Datetime::instance($this->_timezone)->get_datetimes_for_event_ordered_by_DTT_order(
166
-            $this->ID(),
167
-            $show_expired,
168
-            $show_deleted,
169
-            $limit
170
-        );
171
-    }
172
-
173
-
174
-    /**
175
-     * Returns one related datetime. Mostly only used by some legacy code.
176
-     *
177
-     * @return EE_Base_Class|EE_Datetime
178
-     * @throws EE_Error
179
-     */
180
-    public function first_datetime()
181
-    {
182
-        return $this->get_first_related('Datetime');
183
-    }
184
-
185
-
186
-    /**
187
-     * Returns the 'primary' datetime for the event
188
-     *
189
-     * @param bool $try_to_exclude_expired
190
-     * @param bool $try_to_exclude_deleted
191
-     * @return EE_Datetime
192
-     * @throws EE_Error
193
-     */
194
-    public function primary_datetime($try_to_exclude_expired = true, $try_to_exclude_deleted = true)
195
-    {
196
-        if (!empty ($this->_Primary_Datetime)) {
197
-            return $this->_Primary_Datetime;
198
-        }
199
-        $this->_Primary_Datetime = EEM_Datetime::instance($this->_timezone)->get_primary_datetime_for_event(
200
-            $this->ID(),
201
-            $try_to_exclude_expired,
202
-            $try_to_exclude_deleted
203
-        );
204
-        return $this->_Primary_Datetime;
205
-    }
206
-
207
-
208
-    /**
209
-     * Gets all the tickets available for purchase of this event
210
-     *
211
-     * @param array $query_params like EEM_Base::get_all
212
-     * @return EE_Base_Class[]|EE_Ticket[]
213
-     * @throws EE_Error
214
-     */
215
-    public function tickets($query_params = array())
216
-    {
217
-        //first get all datetimes
218
-        $datetimes = $this->datetimes_ordered();
219
-        if (!$datetimes) {
220
-            return array();
221
-        }
222
-        $datetime_ids = array();
223
-        foreach ($datetimes as $datetime) {
224
-            $datetime_ids[] = $datetime->ID();
225
-        }
226
-        $where_params = array('Datetime.DTT_ID' => array('IN', $datetime_ids));
227
-        //if incoming $query_params has where conditions let's merge but not override existing.
228
-        if (is_array($query_params) && isset($query_params[0])) {
229
-            $where_params = array_merge($query_params[0], $where_params);
230
-            unset($query_params[0]);
231
-        }
232
-        //now add $where_params to $query_params
233
-        $query_params[0] = $where_params;
234
-        return EEM_Ticket::instance()->get_all($query_params);
235
-    }
236
-
237
-
238
-    /**
239
-     * get all unexpired untrashed tickets
240
-     *
241
-     * @return EE_Ticket[]
242
-     * @throws EE_Error
243
-     */
244
-    public function active_tickets()
245
-    {
246
-        return $this->tickets(array(
247
-            array(
248
-                'TKT_end_date' => array('>=', EEM_Ticket::instance()->current_time_for_query('TKT_end_date')),
249
-                'TKT_deleted' => false,
250
-            ),
251
-        ));
252
-    }
253
-
254
-
255
-    /**
256
-     * @return bool
257
-     * @throws EE_Error
258
-     */
259
-    public function additional_limit()
260
-    {
261
-        return $this->get('EVT_additional_limit');
262
-    }
263
-
264
-
265
-    /**
266
-     * @return bool
267
-     * @throws EE_Error
268
-     */
269
-    public function allow_overflow()
270
-    {
271
-        return $this->get('EVT_allow_overflow');
272
-    }
273
-
274
-
275
-    /**
276
-     * @return bool
277
-     * @throws EE_Error
278
-     */
279
-    public function created()
280
-    {
281
-        return $this->get('EVT_created');
282
-    }
283
-
284
-
285
-    /**
286
-     * @return bool
287
-     * @throws EE_Error
288
-     */
289
-    public function description()
290
-    {
291
-        return $this->get('EVT_desc');
292
-    }
293
-
294
-
295
-    /**
296
-     * Runs do_shortcode and wpautop on the description
297
-     *
298
-     * @return string of html
299
-     * @throws EE_Error
300
-     */
301
-    public function description_filtered()
302
-    {
303
-        return $this->get_pretty('EVT_desc');
304
-    }
305
-
306
-
307
-    /**
308
-     * @return bool
309
-     * @throws EE_Error
310
-     */
311
-    public function display_description()
312
-    {
313
-        return $this->get('EVT_display_desc');
314
-    }
315
-
316
-
317
-    /**
318
-     * @return bool
319
-     * @throws EE_Error
320
-     */
321
-    public function display_ticket_selector()
322
-    {
323
-        return (bool)$this->get('EVT_display_ticket_selector');
324
-    }
325
-
326
-
327
-    /**
328
-     * @return bool
329
-     * @throws EE_Error
330
-     */
331
-    public function external_url()
332
-    {
333
-        return $this->get('EVT_external_URL');
334
-    }
335
-
336
-
337
-    /**
338
-     * @return bool
339
-     * @throws EE_Error
340
-     */
341
-    public function member_only()
342
-    {
343
-        return $this->get('EVT_member_only');
344
-    }
345
-
346
-
347
-    /**
348
-     * @return bool
349
-     * @throws EE_Error
350
-     */
351
-    public function phone()
352
-    {
353
-        return $this->get('EVT_phone');
354
-    }
355
-
356
-
357
-    /**
358
-     * @return bool
359
-     * @throws EE_Error
360
-     */
361
-    public function modified()
362
-    {
363
-        return $this->get('EVT_modified');
364
-    }
365
-
366
-
367
-    /**
368
-     * @return bool
369
-     * @throws EE_Error
370
-     */
371
-    public function name()
372
-    {
373
-        return $this->get('EVT_name');
374
-    }
375
-
376
-
377
-    /**
378
-     * @return bool
379
-     * @throws EE_Error
380
-     */
381
-    public function order()
382
-    {
383
-        return $this->get('EVT_order');
384
-    }
385
-
386
-
387
-    /**
388
-     * @return bool|string
389
-     * @throws EE_Error
390
-     */
391
-    public function default_registration_status()
392
-    {
393
-        $event_default_registration_status = $this->get('EVT_default_registration_status');
394
-        return !empty($event_default_registration_status)
395
-            ? $event_default_registration_status
396
-            : EE_Registry::instance()->CFG->registration->default_STS_ID;
397
-    }
398
-
399
-
400
-    /**
401
-     * @param int $num_words
402
-     * @param null $more
403
-     * @param bool $not_full_desc
404
-     * @return bool|string
405
-     * @throws EE_Error
406
-     */
407
-    public function short_description($num_words = 55, $more = null, $not_full_desc = false)
408
-    {
409
-        $short_desc = $this->get('EVT_short_desc');
410
-        if (!empty($short_desc) || $not_full_desc) {
411
-            return $short_desc;
412
-        }
413
-        $full_desc = $this->get('EVT_desc');
414
-        return wp_trim_words($full_desc, $num_words, $more);
415
-    }
416
-
417
-
418
-    /**
419
-     * @return bool
420
-     * @throws EE_Error
421
-     */
422
-    public function slug()
423
-    {
424
-        return $this->get('EVT_slug');
425
-    }
426
-
427
-
428
-    /**
429
-     * @return bool
430
-     * @throws EE_Error
431
-     */
432
-    public function timezone_string()
433
-    {
434
-        return $this->get('EVT_timezone_string');
435
-    }
436
-
437
-
438
-    /**
439
-     * @return bool
440
-     * @throws EE_Error
441
-     */
442
-    public function visible_on()
443
-    {
444
-        return $this->get('EVT_visible_on');
445
-    }
446
-
447
-
448
-    /**
449
-     * @return int
450
-     * @throws EE_Error
451
-     */
452
-    public function wp_user()
453
-    {
454
-        return $this->get('EVT_wp_user');
455
-    }
456
-
457
-
458
-    /**
459
-     * @return bool
460
-     * @throws EE_Error
461
-     */
462
-    public function donations()
463
-    {
464
-        return $this->get('EVT_donations');
465
-    }
466
-
467
-
468
-    /**
469
-     * @param $limit
470
-     * @throws EE_Error
471
-     */
472
-    public function set_additional_limit($limit)
473
-    {
474
-        $this->set('EVT_additional_limit', $limit);
475
-    }
476
-
477
-
478
-    /**
479
-     * @param $created
480
-     * @throws EE_Error
481
-     */
482
-    public function set_created($created)
483
-    {
484
-        $this->set('EVT_created', $created);
485
-    }
486
-
487
-
488
-    /**
489
-     * @param $desc
490
-     * @throws EE_Error
491
-     */
492
-    public function set_description($desc)
493
-    {
494
-        $this->set('EVT_desc', $desc);
495
-    }
496
-
497
-
498
-    /**
499
-     * @param $display_desc
500
-     * @throws EE_Error
501
-     */
502
-    public function set_display_description($display_desc)
503
-    {
504
-        $this->set('EVT_display_desc', $display_desc);
505
-    }
506
-
507
-
508
-    /**
509
-     * @param $display_ticket_selector
510
-     * @throws EE_Error
511
-     */
512
-    public function set_display_ticket_selector($display_ticket_selector)
513
-    {
514
-        $this->set('EVT_display_ticket_selector', $display_ticket_selector);
515
-    }
516
-
517
-
518
-    /**
519
-     * @param $external_url
520
-     * @throws EE_Error
521
-     */
522
-    public function set_external_url($external_url)
523
-    {
524
-        $this->set('EVT_external_URL', $external_url);
525
-    }
526
-
527
-
528
-    /**
529
-     * @param $member_only
530
-     * @throws EE_Error
531
-     */
532
-    public function set_member_only($member_only)
533
-    {
534
-        $this->set('EVT_member_only', $member_only);
535
-    }
536
-
537
-
538
-    /**
539
-     * @param $event_phone
540
-     * @throws EE_Error
541
-     */
542
-    public function set_event_phone($event_phone)
543
-    {
544
-        $this->set('EVT_phone', $event_phone);
545
-    }
546
-
547
-
548
-    /**
549
-     * @param $modified
550
-     * @throws EE_Error
551
-     */
552
-    public function set_modified($modified)
553
-    {
554
-        $this->set('EVT_modified', $modified);
555
-    }
556
-
557
-
558
-    /**
559
-     * @param $name
560
-     * @throws EE_Error
561
-     */
562
-    public function set_name($name)
563
-    {
564
-        $this->set('EVT_name', $name);
565
-    }
566
-
567
-
568
-    /**
569
-     * @param $order
570
-     * @throws EE_Error
571
-     */
572
-    public function set_order($order)
573
-    {
574
-        $this->set('EVT_order', $order);
575
-    }
576
-
577
-
578
-    /**
579
-     * @param $short_desc
580
-     * @throws EE_Error
581
-     */
582
-    public function set_short_description($short_desc)
583
-    {
584
-        $this->set('EVT_short_desc', $short_desc);
585
-    }
586
-
587
-
588
-    /**
589
-     * @param $slug
590
-     * @throws EE_Error
591
-     */
592
-    public function set_slug($slug)
593
-    {
594
-        $this->set('EVT_slug', $slug);
595
-    }
596
-
597
-
598
-    /**
599
-     * @param $timezone_string
600
-     * @throws EE_Error
601
-     */
602
-    public function set_timezone_string($timezone_string)
603
-    {
604
-        $this->set('EVT_timezone_string', $timezone_string);
605
-    }
606
-
607
-
608
-    /**
609
-     * @param $visible_on
610
-     * @throws EE_Error
611
-     */
612
-    public function set_visible_on($visible_on)
613
-    {
614
-        $this->set('EVT_visible_on', $visible_on);
615
-    }
616
-
617
-
618
-    /**
619
-     * @param $wp_user
620
-     * @throws EE_Error
621
-     */
622
-    public function set_wp_user($wp_user)
623
-    {
624
-        $this->set('EVT_wp_user', $wp_user);
625
-    }
626
-
627
-
628
-    /**
629
-     * @param $default_registration_status
630
-     * @throws EE_Error
631
-     */
632
-    public function set_default_registration_status($default_registration_status)
633
-    {
634
-        $this->set('EVT_default_registration_status', $default_registration_status);
635
-    }
636
-
637
-
638
-    /**
639
-     * @param $donations
640
-     * @throws EE_Error
641
-     */
642
-    public function set_donations($donations)
643
-    {
644
-        $this->set('EVT_donations', $donations);
645
-    }
646
-
647
-
648
-    /**
649
-     * Adds a venue to this event
650
-     *
651
-     * @param EE_Venue /int $venue_id_or_obj
652
-     * @return EE_Base_Class|EE_Venue
653
-     * @throws EE_Error
654
-     */
655
-    public function add_venue($venue_id_or_obj)
656
-    {
657
-        return $this->_add_relation_to($venue_id_or_obj, 'Venue');
658
-    }
659
-
660
-
661
-    /**
662
-     * Removes a venue from the event
663
-     *
664
-     * @param EE_Venue /int $venue_id_or_obj
665
-     * @return EE_Base_Class|EE_Venue
666
-     * @throws EE_Error
667
-     */
668
-    public function remove_venue($venue_id_or_obj)
669
-    {
670
-        return $this->_remove_relation_to($venue_id_or_obj, 'Venue');
671
-    }
672
-
673
-
674
-    /**
675
-     * Gets all the venues related ot the event. May provide additional $query_params if desired
676
-     *
677
-     * @param array $query_params like EEM_Base::get_all's $query_params
678
-     * @return EE_Base_Class[]|EE_Venue[]
679
-     * @throws EE_Error
680
-     */
681
-    public function venues($query_params = array())
682
-    {
683
-        return $this->get_many_related('Venue', $query_params);
684
-    }
685
-
686
-
687
-    /**
688
-     * check if event id is present and if event is published
689
-     *
690
-     * @access public
691
-     * @return boolean true yes, false no
692
-     * @throws EE_Error
693
-     */
694
-    private function _has_ID_and_is_published()
695
-    {
696
-        // first check if event id is present and not NULL,
697
-        // then check if this event is published (or any of the equivalent "published" statuses)
698
-        return
699
-            $this->ID() && $this->ID() !== null
700
-            && (
701
-                $this->status() === 'publish'
702
-                || $this->status() === EEM_Event::sold_out
703
-                || $this->status() === EEM_Event::postponed
704
-                || $this->status() === EEM_Event::cancelled
705
-            );
706
-    }
707
-
708
-
709
-    /**
710
-     * This simply compares the internal dates with NOW and determines if the event is upcoming or not.
711
-     *
712
-     * @access public
713
-     * @return boolean true yes, false no
714
-     * @throws EE_Error
715
-     */
716
-    public function is_upcoming()
717
-    {
718
-        // check if event id is present and if this event is published
719
-        if ($this->is_inactive()) {
720
-            return false;
721
-        }
722
-        // set initial value
723
-        $upcoming = false;
724
-        //next let's get all datetimes and loop through them
725
-        $datetimes = $this->datetimes_in_chronological_order();
726
-        foreach ($datetimes as $datetime) {
727
-            if ($datetime instanceof EE_Datetime) {
728
-                //if this dtt is expired then we continue cause one of the other datetimes might be upcoming.
729
-                if ($datetime->is_expired()) {
730
-                    continue;
731
-                }
732
-                //if this dtt is active then we return false.
733
-                if ($datetime->is_active()) {
734
-                    return false;
735
-                }
736
-                //otherwise let's check upcoming status
737
-                $upcoming = $datetime->is_upcoming();
738
-            }
739
-        }
740
-        return $upcoming;
741
-    }
742
-
743
-
744
-    /**
745
-     * @return bool
746
-     * @throws EE_Error
747
-     */
748
-    public function is_active()
749
-    {
750
-        // check if event id is present and if this event is published
751
-        if ($this->is_inactive()) {
752
-            return false;
753
-        }
754
-        // set initial value
755
-        $active = false;
756
-        //next let's get all datetimes and loop through them
757
-        $datetimes = $this->datetimes_in_chronological_order();
758
-        foreach ($datetimes as $datetime) {
759
-            if ($datetime instanceof EE_Datetime) {
760
-                //if this dtt is expired then we continue cause one of the other datetimes might be active.
761
-                if ($datetime->is_expired()) {
762
-                    continue;
763
-                }
764
-                //if this dtt is upcoming then we return false.
765
-                if ($datetime->is_upcoming()) {
766
-                    return false;
767
-                }
768
-                //otherwise let's check active status
769
-                $active = $datetime->is_active();
770
-            }
771
-        }
772
-        return $active;
773
-    }
774
-
775
-
776
-    /**
777
-     * @return bool
778
-     * @throws EE_Error
779
-     */
780
-    public function is_expired()
781
-    {
782
-        // check if event id is present and if this event is published
783
-        if ($this->is_inactive()) {
784
-            return false;
785
-        }
786
-        // set initial value
787
-        $expired = false;
788
-        //first let's get all datetimes and loop through them
789
-        $datetimes = $this->datetimes_in_chronological_order();
790
-        foreach ($datetimes as $datetime) {
791
-            if ($datetime instanceof EE_Datetime) {
792
-                //if this dtt is upcoming or active then we return false.
793
-                if ($datetime->is_upcoming() || $datetime->is_active()) {
794
-                    return false;
795
-                }
796
-                //otherwise let's check active status
797
-                $expired = $datetime->is_expired();
798
-            }
799
-        }
800
-        return $expired;
801
-    }
802
-
803
-
804
-    /**
805
-     * @return bool
806
-     * @throws EE_Error
807
-     */
808
-    public function is_inactive()
809
-    {
810
-        // check if event id is present and if this event is published
811
-        if ($this->_has_ID_and_is_published()) {
812
-            return false;
813
-        }
814
-        return true;
815
-    }
816
-
817
-
818
-    /**
819
-     * calculate spaces remaining based on "saleable" tickets
820
-     *
821
-     * @param array $tickets
822
-     * @param bool $filtered
823
-     * @return int|float
824
-     * @throws EE_Error
825
-     */
826
-    public function spaces_remaining($tickets = array(), $filtered = true)
827
-    {
828
-        // get all unexpired untrashed tickets if nothing was passed
829
-        $tickets = !empty($tickets) ? $tickets : $this->active_tickets();
830
-        // set initial value
831
-        $spaces_remaining = 0;
832
-        if (!empty($tickets)) {
833
-            foreach ($tickets as $ticket) {
834
-                if ($ticket instanceof EE_Ticket) {
835
-                    $spaces_remaining += $ticket->qty('saleable');
836
-                }
837
-            }
838
-        }
839
-        return $filtered
840
-            ? apply_filters(
841
-                'FHEE_EE_Event__spaces_remaining',
842
-                $spaces_remaining,
843
-                $this,
844
-                $tickets
845
-            )
846
-            : $spaces_remaining;
847
-    }
848
-
849
-
850
-    /**
851
-     *    perform_sold_out_status_check
852
-     *    checks all of this events's datetime  reg_limit - sold values to determine if ANY datetimes have spaces available...
853
-     *    if NOT, then the event status will get toggled to 'sold_out'
854
-     *
855
-     * @access public
856
-     * @return bool    return the ACTUAL sold out state.
857
-     * @throws EE_Error
858
-     */
859
-    public function perform_sold_out_status_check()
860
-    {
861
-        // get all unexpired untrashed tickets
862
-        $tickets = $this->active_tickets();
863
-        // if all the tickets are just expired, then don't update the event status to sold out
864
-        if (empty($tickets)) {
865
-            return true;
866
-        }
867
-        $spaces_remaining = $this->spaces_remaining($tickets);
868
-        if ($spaces_remaining < 1) {
869
-            $this->set_status(EEM_Event::sold_out);
870
-            $this->save();
871
-            $sold_out = true;
872
-        } else {
873
-            $sold_out = false;
874
-            // was event previously marked as sold out ?
875
-            if ($this->status() === EEM_Event::sold_out) {
876
-                // revert status to previous value, if it was set
877
-                $previous_event_status = $this->get_post_meta('_previous_event_status', true);
878
-                if ($previous_event_status) {
879
-                    $this->set_status($previous_event_status);
880
-                    $this->save();
881
-                }
882
-            }
883
-        }
884
-        do_action('AHEE__EE_Event__perform_sold_out_status_check__end', $this, $sold_out, $spaces_remaining, $tickets);
885
-        return $sold_out;
886
-    }
887
-
888
-
889
-    /**
890
-     * This returns the total remaining spaces for sale on this event.
891
-     * ############################
892
-     * VERY IMPORTANT FOR DEVELOPERS:
893
-     * While included here, this method is still being tested internally, so its signature and behaviour COULD change.
894
-     * While this comment block is in place, usage is at your own risk and know that it may change in future builds.
895
-     * ############################
896
-     *
897
-     * @uses EE_Event::total_available_spaces()
898
-     * @return float|int  (EE_INF is returned as float)
899
-     * @throws InvalidArgumentException
900
-     * @throws InvalidStatusException
901
-     * @throws EE_Error
902
-     */
903
-    public function spaces_remaining_for_sale()
904
-    {
905
-        //first get total available spaces including consideration for tickets that have already sold.
906
-        $spaces_available = $this->total_available_spaces(true);
907
-        //if total available = 0, then exit right away because that means everything is expired.
908
-        if ($spaces_available === 0) {
909
-            return 0;
910
-        }
911
-        //subtract total approved registrations from spaces available to get how many are remaining.
912
-        $spots_taken = EEM_Registration::instance()->event_reg_count_for_statuses($this->ID());
913
-        $spaces_remaining = $spaces_available - $spots_taken;
914
-        return $spaces_remaining > 0 ? $spaces_remaining : 0;
915
-    }
916
-
917
-
918
-    /**
919
-     * This returns the total spaces available for an event while considering all the qtys on the tickets and the reg limits
920
-     * on the datetimes attached to this event.
921
-     * ############################
922
-     * VERY IMPORTANT FOR DEVELOPERS:
923
-     * While included here, this method is still being tested internally, so its signature and behaviour COULD change. While
924
-     * this comment block is in place, usage is at your own risk and know that it may change in future builds.
925
-     * ############################
926
-     * Note: by "spaces available" we are not returning how many spaces remain.  That is a calculation involving using the value
927
-     * from this method and subtracting the approved registrations for the event.
928
-     *
929
-     * @param   bool $current_total_available Whether to consider any tickets that have already sold in our calculation.
930
-     *                                              If this is false, then we return the most tickets that could ever be sold
931
-     *                                              for this event with the datetime and tickets setup on the event under optimal
932
-     *                                              selling conditions.  Otherwise we return a live calculation of spaces available
933
-     *                                              based on tickets sold.  Depending on setup and stage of sales, this
934
-     *                                              may appear to equal remaining tickets.  However, the more tickets are
935
-     *                                              sold out, the more accurate the "live" total is.
936
-     * @return  int|float  (Note: if EE_INF is returned its considered a float by PHP)
937
-     * @throws EE_Error
938
-     */
939
-    public function total_available_spaces($current_total_available = false)
940
-    {
941
-        $spaces_available = 0;
942
-        //first get all tickets on the event and include expired tickets
943
-        $tickets = $this->tickets(array('default_where_conditions' => 'none'));
944
-        $ticket_sums = array();
945
-        $datetimes = array();
946
-        $datetime_limits = array();
947
-        //loop through tickets and normalize them
948
-        foreach ($tickets as $ticket) {
949
-            $datetimes = $ticket->datetimes(array('order_by' => array('DTT_reg_limit' => 'ASC')));
950
-            if (empty($datetimes)) {
951
-                continue;
952
-            }
953
-            //first datetime should be the lowest datetime
954
-            $least_datetime = reset($datetimes);
955
-            //lets reset the ticket quantity to be the lower of either the lowest datetime reg limit or the ticket quantity
956
-            //IF datetimes sold (and we're not doing current live total available, then use spaces remaining for datetime, not reg_limit.
957
-            if ($current_total_available) {
958
-                if ($ticket->is_remaining()) {
959
-                    $remaining = $ticket->remaining();
960
-                } else {
961
-                    $spaces_available += $ticket->sold();
962
-                    //and we don't cache this ticket to our list because its sold out.
963
-                    continue;
964
-                }
965
-            } else {
966
-                $remaining = min($ticket->qty(), $least_datetime->reg_limit());
967
-            }
968
-            //if $ticket_limit == infinity then let's drop out right away and just return that because any infinity amount trumps all other "available" amounts.
969
-            if ($remaining === EE_INF) {
970
-                return EE_INF;
971
-            }
972
-            //multiply normalized $tkt quantity by the number of datetimes on the ticket as the "sum"
973
-            //also include the sum of all the datetime reg limits on the ticket for breaking ties.
974
-            $ticket_sums[$ticket->ID()]['sum'] = $remaining * count($datetimes);
975
-            $ticket_sums[$ticket->ID()]['datetime_sums'] = 0;
976
-            foreach ($datetimes as $datetime) {
977
-                if ($datetime->reg_limit() === EE_INF) {
978
-                    $ticket_sums[$ticket->ID()]['datetime_sums'] = EE_INF;
979
-                } else {
980
-                    $ticket_sums[$ticket->ID()]['datetime_sums'] += $current_total_available
981
-                        ? $datetime->spaces_remaining()
982
-                        : $datetime->reg_limit();
983
-                }
984
-                $datetime_limits[$datetime->ID()] = $current_total_available
985
-                    ? $datetime->spaces_remaining()
986
-                    : $datetime->reg_limit();
987
-            }
988
-            $ticket_sums[$ticket->ID()]['ticket'] = $ticket;
989
-        }
990
-        //The order is sorted by lowest available first (which is calculated for each ticket by multiplying the normalized
991
-        //ticket quantity by the number of datetimes on the ticket).  For tie-breakers, then the next sort is based on the
992
-        //ticket with the greatest sum of all remaining datetime->spaces_remaining() ( or $datetime->reg_limit() if not
993
-        //$current_total_available ) for the datetimes on the ticket.
994
-        usort($ticket_sums, function ($a, $b) {
995
-            if ($a['sum'] === $b['sum']) {
996
-                if ($a['datetime_sums'] === $b['datetime_sums']) {
997
-                    return 0;
998
-                }
999
-                return $a['datetime_sums'] < $b['datetime_sums'] ? 1 : -1;
1000
-            }
1001
-            return ($a['sum'] < $b['sum']) ? -1 : 1;
1002
-        });
1003
-        //now let's loop through the sorted tickets and simulate sellouts
1004
-        foreach ($ticket_sums as $ticket_info) {
1005
-            if ($ticket_info['ticket'] instanceof EE_Ticket) {
1006
-                $datetimes = $ticket_info['ticket']->datetimes(array('order_by' => array('DTT_reg_limit' => 'ASC')));
1007
-                //need to sort these $datetimes by remaining (only if $current_total_available)
1008
-                //setup datetimes for simulation
1009
-                $ticket_datetimes_remaining = array();
1010
-                foreach ($datetimes as $datetime) {
1011
-                    $DTT_ID = $datetime->ID();
1012
-                    $ticket_datetimes_remaining[$DTT_ID]['rem'] = $datetime_limits[$DTT_ID];
1013
-                    $ticket_datetimes_remaining[$DTT_ID]['datetime'] = $datetime;
1014
-                }
1015
-                usort($ticket_datetimes_remaining, function ($a, $b) {
1016
-                    if ($a['rem'] === $b['rem']) {
1017
-                        return 0;
1018
-                    }
1019
-                    return ($a['rem'] < $b['rem']) ? -1 : 1;
1020
-                });
1021
-                //get the remaining on the first datetime (which should be the one with the least remaining) and that is
1022
-                //what we add to the spaces_available running total.  Then we need to decrease the remaining on our datetime tracker.
1023
-                $lowest_datetime = reset($ticket_datetimes_remaining);
1024
-                //need to get the lower of; what the remaining is on the lowest datetime, and the remaining on the ticket.
1025
-                // If this ends up being 0 (because of previous tickets in our simulation selling out), then it has already
1026
-                // been tracked on $spaces available and this ticket is now sold out for the simulation, so we can continue
1027
-                // to the next ticket.
1028
-                if ($current_total_available) {
1029
-                    $remaining = min($lowest_datetime['rem'], $ticket_info['ticket']->remaining());
1030
-                } else {
1031
-                    $remaining = min($lowest_datetime['rem'], $ticket_info['ticket']->qty());
1032
-                }
1033
-                //if $remaining is infinite that means that all datetimes on this ticket are infinite but we've made it here because all
1034
-                //tickets have a quantity.  So we don't have to track datetimes, we can just use ticket quantities for total
1035
-                //available.
1036
-                if ($remaining === EE_INF) {
1037
-                    $spaces_available += $ticket_info['ticket']->qty();
1038
-                    continue;
1039
-                }
1040
-                //if ticket has sold amounts then we also need to add that (but only if doing live counts)
1041
-                if ($current_total_available) {
1042
-                    $spaces_available += $ticket_info['ticket']->sold();
1043
-                }
1044
-                if ($remaining <= 0) {
1045
-                    continue;
1046
-                }
1047
-                $spaces_available += $remaining;
1048
-                //loop through the datetimes and sell them out!
1049
-                foreach ($ticket_datetimes_remaining as $datetime_info) {
1050
-                    if ($datetime_info['datetime'] instanceof EE_Datetime) {
1051
-                        $datetime_limits[$datetime_info['datetime']->ID()] += -$remaining;
1052
-                    }
1053
-                }
1054
-            }
1055
-        }
1056
-        return apply_filters(
1057
-            'FHEE_EE_Event__total_available_spaces__spaces_available',
1058
-            $spaces_available,
1059
-            $this,
1060
-            $datetimes,
1061
-            $tickets
1062
-        );
1063
-    }
1064
-
1065
-
1066
-    /**
1067
-     * Checks if the event is set to sold out
1068
-     *
1069
-     * @param  bool $actual whether or not to perform calculations to not only figure the
1070
-     *                      actual status but also to flip the status if necessary to sold
1071
-     *                      out If false, we just check the existing status of the event
1072
-     * @return boolean
1073
-     * @throws EE_Error
1074
-     */
1075
-    public function is_sold_out($actual = false)
1076
-    {
1077
-        if (!$actual) {
1078
-            return $this->status() === EEM_Event::sold_out;
1079
-        }
1080
-        return $this->perform_sold_out_status_check();
1081
-    }
1082
-
1083
-
1084
-    /**
1085
-     * Checks if the event is marked as postponed
1086
-     *
1087
-     * @return boolean
1088
-     */
1089
-    public function is_postponed()
1090
-    {
1091
-        return $this->status() === EEM_Event::postponed;
1092
-    }
1093
-
1094
-
1095
-    /**
1096
-     * Checks if the event is marked as cancelled
1097
-     *
1098
-     * @return boolean
1099
-     */
1100
-    public function is_cancelled()
1101
-    {
1102
-        return $this->status() === EEM_Event::cancelled;
1103
-    }
1104
-
1105
-
1106
-    /**
1107
-     * Get the logical active status in a hierarchical order for all the datetimes.  Note
1108
-     * Basically, we order the datetimes by EVT_start_date.  Then first test on whether the event is published.  If its
1109
-     * NOT published then we test for whether its expired or not.  IF it IS published then we test first on whether an
1110
-     * event has any active dates.  If no active dates then we check for any upcoming dates.  If no upcoming dates then
1111
-     * the event is considered expired.
1112
-     * NOTE: this method does NOT calculate whether the datetimes are sold out when event is published.  Sold Out is a status
1113
-     * set on the EVENT when it is not published and thus is done
1114
-     *
1115
-     * @param bool $reset
1116
-     * @return bool | string - based on EE_Datetime active constants or FALSE if error.
1117
-     * @throws EE_Error
1118
-     */
1119
-    public function get_active_status($reset = false)
1120
-    {
1121
-        // if the active status has already been set, then just use that value (unless we are resetting it)
1122
-        if (!empty($this->_active_status) && !$reset) {
1123
-            return $this->_active_status;
1124
-        }
1125
-        //first check if event id is present on this object
1126
-        if (!$this->ID()) {
1127
-            return false;
1128
-        }
1129
-        $where_params_for_event = array(array('EVT_ID' => $this->ID()));
1130
-        //if event is published:
1131
-        if ($this->status() === 'publish') {
1132
-            //active?
1133
-            if (EEM_Datetime::instance()->get_datetime_count_for_status(EE_Datetime::active, $where_params_for_event) > 0) {
1134
-                $this->_active_status = EE_Datetime::active;
1135
-            } else {
1136
-                //upcoming?
1137
-                if (EEM_Datetime::instance()->get_datetime_count_for_status(EE_Datetime::upcoming, $where_params_for_event) > 0) {
1138
-                    $this->_active_status = EE_Datetime::upcoming;
1139
-                } else {
1140
-                    //expired?
1141
-                    if (
1142
-                        EEM_Datetime::instance()->get_datetime_count_for_status(EE_Datetime::expired, $where_params_for_event) > 0
1143
-                    ) {
1144
-                        $this->_active_status = EE_Datetime::expired;
1145
-                    } else {
1146
-                        //it would be odd if things make it this far because it basically means there are no datetime's
1147
-                        //attached to the event.  So in this case it will just be considered inactive.
1148
-                        $this->_active_status = EE_Datetime::inactive;
1149
-                    }
1150
-                }
1151
-            }
1152
-        } else {
1153
-            //the event is not published, so let's just set it's active status according to its' post status
1154
-            switch ($this->status()) {
1155
-                case EEM_Event::sold_out :
1156
-                    $this->_active_status = EE_Datetime::sold_out;
1157
-                    break;
1158
-                case EEM_Event::cancelled :
1159
-                    $this->_active_status = EE_Datetime::cancelled;
1160
-                    break;
1161
-                case EEM_Event::postponed :
1162
-                    $this->_active_status = EE_Datetime::postponed;
1163
-                    break;
1164
-                default :
1165
-                    $this->_active_status = EE_Datetime::inactive;
1166
-            }
1167
-        }
1168
-        return $this->_active_status;
1169
-    }
1170
-
1171
-
1172
-    /**
1173
-     *    pretty_active_status
1174
-     *
1175
-     * @access public
1176
-     * @param boolean $echo whether to return (FALSE), or echo out the result (TRUE)
1177
-     * @return mixed void|string
1178
-     * @throws EE_Error
1179
-     */
1180
-    public function pretty_active_status($echo = true)
1181
-    {
1182
-        $active_status = $this->get_active_status();
1183
-        $status = '<span class="ee-status event-active-status-'
1184
-            . $active_status
1185
-            . '">'
1186
-            . EEH_Template::pretty_status($active_status, false, 'sentence')
1187
-            . '</span>';
1188
-        if ($echo) {
1189
-            echo $status;
1190
-            return '';
1191
-        }
1192
-        return $status;
1193
-    }
1194
-
1195
-
1196
-    /**
1197
-     * @return bool|int
1198
-     * @throws EE_Error
1199
-     */
1200
-    public function get_number_of_tickets_sold()
1201
-    {
1202
-        $tkt_sold = 0;
1203
-        if (!$this->ID()) {
1204
-            return 0;
1205
-        }
1206
-        $datetimes = $this->datetimes();
1207
-        foreach ($datetimes as $datetime) {
1208
-            if ($datetime instanceof EE_Datetime) {
1209
-                $tkt_sold += $datetime->sold();
1210
-            }
1211
-        }
1212
-        return $tkt_sold;
1213
-    }
1214
-
1215
-
1216
-    /**
1217
-     * This just returns a count of all the registrations for this event
1218
-     *
1219
-     * @access  public
1220
-     * @return int
1221
-     * @throws EE_Error
1222
-     */
1223
-    public function get_count_of_all_registrations()
1224
-    {
1225
-        return EEM_Event::instance()->count_related($this, 'Registration');
1226
-    }
1227
-
1228
-
1229
-    /**
1230
-     * This returns the ticket with the earliest start time that is
1231
-     * available for this event (across all datetimes attached to the event)
1232
-     *
1233
-     * @return EE_Base_Class|EE_Ticket|null
1234
-     * @throws EE_Error
1235
-     */
1236
-    public function get_ticket_with_earliest_start_time()
1237
-    {
1238
-        $where['Datetime.EVT_ID'] = $this->ID();
1239
-        $query_params = array($where, 'order_by' => array('TKT_start_date' => 'ASC'));
1240
-        return EE_Registry::instance()->load_model('Ticket')->get_one($query_params);
1241
-    }
1242
-
1243
-
1244
-    /**
1245
-     * This returns the ticket with the latest end time that is available
1246
-     * for this event (across all datetimes attached to the event)
1247
-     *
1248
-     * @return EE_Base_Class|EE_Ticket|null
1249
-     * @throws EE_Error
1250
-     */
1251
-    public function get_ticket_with_latest_end_time()
1252
-    {
1253
-        $where['Datetime.EVT_ID'] = $this->ID();
1254
-        $query_params = array($where, 'order_by' => array('TKT_end_date' => 'DESC'));
1255
-        return EE_Registry::instance()->load_model('Ticket')->get_one($query_params);
1256
-    }
1257
-
1258
-
1259
-    /**
1260
-     * This returns whether there are any tickets on sale for this event.
1261
-     *
1262
-     * @return bool true = YES tickets on sale.
1263
-     * @throws EE_Error
1264
-     */
1265
-    public function tickets_on_sale()
1266
-    {
1267
-        $earliest_ticket = $this->get_ticket_with_earliest_start_time();
1268
-        $latest_ticket = $this->get_ticket_with_latest_end_time();
1269
-        if (!$latest_ticket instanceof EE_Ticket && !$earliest_ticket instanceof EE_Ticket) {
1270
-            return false;
1271
-        }
1272
-        //check on sale for these two tickets.
1273
-        if ($latest_ticket->is_on_sale() || $earliest_ticket->is_on_sale()) {
1274
-            return true;
1275
-        }
1276
-        return false;
1277
-    }
1278
-
1279
-
1280
-    /**
1281
-     * Gets the URL for viewing this event on the front-end. Overrides parent
1282
-     * to check for an external URL first
1283
-     *
1284
-     * @return string
1285
-     * @throws EE_Error
1286
-     */
1287
-    public function get_permalink()
1288
-    {
1289
-        if ($this->external_url()) {
1290
-            return $this->external_url();
1291
-        }
1292
-        return parent::get_permalink();
1293
-    }
1294
-
1295
-
1296
-    /**
1297
-     * Gets the first term for 'espresso_event_categories' we can find
1298
-     *
1299
-     * @param array $query_params like EEM_Base::get_all
1300
-     * @return EE_Base_Class|EE_Term|null
1301
-     * @throws EE_Error
1302
-     */
1303
-    public function first_event_category($query_params = array())
1304
-    {
1305
-        $query_params[0]['Term_Taxonomy.taxonomy'] = 'espresso_event_categories';
1306
-        $query_params[0]['Term_Taxonomy.Event.EVT_ID'] = $this->ID();
1307
-        return EEM_Term::instance()->get_one($query_params);
1308
-    }
1309
-
1310
-
1311
-    /**
1312
-     * Gets all terms for 'espresso_event_categories' we can find
1313
-     *
1314
-     * @param array $query_params
1315
-     * @return EE_Base_Class[]|EE_Term[]
1316
-     * @throws EE_Error
1317
-     */
1318
-    public function get_all_event_categories($query_params = array())
1319
-    {
1320
-        $query_params[0]['Term_Taxonomy.taxonomy'] = 'espresso_event_categories';
1321
-        $query_params[0]['Term_Taxonomy.Event.EVT_ID'] = $this->ID();
1322
-        return EEM_Term::instance()->get_all($query_params);
1323
-    }
1324
-
1325
-
1326
-    /**
1327
-     * Gets all the question groups, ordering them by QSG_order ascending
1328
-     *
1329
-     * @param array $query_params @see EEM_Base::get_all
1330
-     * @return EE_Base_Class[]|EE_Question_Group[]
1331
-     * @throws EE_Error
1332
-     */
1333
-    public function question_groups($query_params = array())
1334
-    {
1335
-        $query_params = !empty($query_params) ? $query_params : array('order_by' => array('QSG_order' => 'ASC'));
1336
-        return $this->get_many_related('Question_Group', $query_params);
1337
-    }
1338
-
1339
-
1340
-    /**
1341
-     * Implementation for EEI_Has_Icon interface method.
1342
-     *
1343
-     * @see EEI_Visual_Representation for comments
1344
-     * @return string
1345
-     */
1346
-    public function get_icon()
1347
-    {
1348
-        return '<span class="dashicons dashicons-flag"></span>';
1349
-    }
1350
-
1351
-
1352
-    /**
1353
-     * Implementation for EEI_Admin_Links interface method.
1354
-     *
1355
-     * @see EEI_Admin_Links for comments
1356
-     * @return string
1357
-     * @throws EE_Error
1358
-     */
1359
-    public function get_admin_details_link()
1360
-    {
1361
-        return $this->get_admin_edit_link();
1362
-    }
1363
-
1364
-
1365
-    /**
1366
-     * Implementation for EEI_Admin_Links interface method.
1367
-     *
1368
-     * @see EEI_Admin_Links for comments
1369
-     * @return string
1370
-     * @throws EE_Error
1371
-     */
1372
-    public function get_admin_edit_link()
1373
-    {
1374
-        return EEH_URL::add_query_args_and_nonce(array(
1375
-            'page' => 'espresso_events',
1376
-            'action' => 'edit',
1377
-            'post' => $this->ID(),
1378
-        ),
1379
-            admin_url('admin.php')
1380
-        );
1381
-    }
1382
-
1383
-
1384
-    /**
1385
-     * Implementation for EEI_Admin_Links interface method.
1386
-     *
1387
-     * @see EEI_Admin_Links for comments
1388
-     * @return string
1389
-     */
1390
-    public function get_admin_settings_link()
1391
-    {
1392
-        return EEH_URL::add_query_args_and_nonce(array(
1393
-            'page' => 'espresso_events',
1394
-            'action' => 'default_event_settings',
1395
-        ),
1396
-            admin_url('admin.php')
1397
-        );
1398
-    }
1399
-
1400
-
1401
-    /**
1402
-     * Implementation for EEI_Admin_Links interface method.
1403
-     *
1404
-     * @see EEI_Admin_Links for comments
1405
-     * @return string
1406
-     */
1407
-    public function get_admin_overview_link()
1408
-    {
1409
-        return EEH_URL::add_query_args_and_nonce(array(
1410
-            'page' => 'espresso_events',
1411
-            'action' => 'default',
1412
-        ),
1413
-            admin_url('admin.php')
1414
-        );
1415
-    }
18
+	/**
19
+	 * cached value for the the logical active status for the event
20
+	 *
21
+	 * @see get_active_status()
22
+	 * @var string
23
+	 */
24
+	protected $_active_status = '';
25
+
26
+	/**
27
+	 * This is just used for caching the Primary Datetime for the Event on initial retrieval
28
+	 *
29
+	 * @var EE_Datetime
30
+	 */
31
+	protected $_Primary_Datetime;
32
+
33
+
34
+	/**
35
+	 * @param array $props_n_values incoming values
36
+	 * @param string $timezone incoming timezone (if not set the timezone set for the website will be
37
+	 *                                        used.)
38
+	 * @param array $date_formats incoming date_formats in an array where the first value is the
39
+	 *                                        date_format and the second value is the time format
40
+	 * @return EE_Event
41
+	 * @throws EE_Error
42
+	 */
43
+	public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array())
44
+	{
45
+		$has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats);
46
+		return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats);
47
+	}
48
+
49
+
50
+	/**
51
+	 * @param array $props_n_values incoming values from the database
52
+	 * @param string $timezone incoming timezone as set by the model.  If not set the timezone for
53
+	 *                                the website will be used.
54
+	 * @return EE_Event
55
+	 * @throws EE_Error
56
+	 */
57
+	public static function new_instance_from_db($props_n_values = array(), $timezone = null)
58
+	{
59
+		return new self($props_n_values, true, $timezone);
60
+	}
61
+
62
+
63
+	/**
64
+	 * Overrides parent set() method so that all calls to set( 'status', $status ) can be routed to internal methods
65
+	 *
66
+	 * @param string $field_name
67
+	 * @param mixed $field_value
68
+	 * @param bool $use_default
69
+	 * @throws EE_Error
70
+	 */
71
+	public function set($field_name, $field_value, $use_default = false)
72
+	{
73
+		switch ($field_name) {
74
+			case 'status' :
75
+				$this->set_status($field_value, $use_default);
76
+				break;
77
+			default :
78
+				parent::set($field_name, $field_value, $use_default);
79
+		}
80
+	}
81
+
82
+
83
+	/**
84
+	 *    set_status
85
+	 * Checks if event status is being changed to SOLD OUT
86
+	 * and updates event meta data with previous event status
87
+	 * so that we can revert things if/when the event is no longer sold out
88
+	 *
89
+	 * @access public
90
+	 * @param string $new_status
91
+	 * @param bool $use_default
92
+	 * @return void
93
+	 * @throws EE_Error
94
+	 */
95
+	public function set_status($new_status = null, $use_default = false)
96
+	{
97
+		// if nothing is set, and we aren't explicitly wanting to reset the status, then just leave
98
+		if (empty($new_status) && !$use_default) {
99
+			return;
100
+		}
101
+		// get current Event status
102
+		$old_status = $this->status();
103
+		// if status has changed
104
+		if ($old_status !== $new_status) {
105
+			// TO sold_out
106
+			if ($new_status === EEM_Event::sold_out) {
107
+				// save the previous event status so that we can revert if the event is no longer sold out
108
+				$this->add_post_meta('_previous_event_status', $old_status);
109
+				do_action('AHEE__EE_Event__set_status__to_sold_out', $this, $old_status, $new_status);
110
+				// OR FROM  sold_out
111
+			} else if ($old_status === EEM_Event::sold_out) {
112
+				$this->delete_post_meta('_previous_event_status');
113
+				do_action('AHEE__EE_Event__set_status__from_sold_out', $this, $old_status, $new_status);
114
+			}
115
+			// update status
116
+			parent::set('status', $new_status, $use_default);
117
+			do_action('AHEE__EE_Event__set_status__after_update', $this);
118
+			return;
119
+		}
120
+		// even though the old value matches the new value, it's still good to
121
+		// allow the parent set method to have a say
122
+		parent::set('status', $new_status, $use_default);
123
+	}
124
+
125
+
126
+	/**
127
+	 * Gets all the datetimes for this event
128
+	 *
129
+	 * @param array $query_params like EEM_Base::get_all
130
+	 * @return EE_Base_Class[]|EE_Datetime[]
131
+	 * @throws EE_Error
132
+	 */
133
+	public function datetimes($query_params = array())
134
+	{
135
+		return $this->get_many_related('Datetime', $query_params);
136
+	}
137
+
138
+
139
+	/**
140
+	 * Gets all the datetimes for this event, ordered by DTT_EVT_start in ascending order
141
+	 *
142
+	 * @return EE_Base_Class[]|EE_Datetime[]
143
+	 * @throws EE_Error
144
+	 */
145
+	public function datetimes_in_chronological_order()
146
+	{
147
+		return $this->get_many_related('Datetime', array('order_by' => array('DTT_EVT_start' => 'ASC')));
148
+	}
149
+
150
+
151
+	/**
152
+	 * Gets all the datetimes for this event, ordered by the DTT_order on the datetime.
153
+	 * @darren, we should probably UNSET timezone on the EEM_Datetime model
154
+	 * after running our query, so that this timezone isn't set for EVERY query
155
+	 * on EEM_Datetime for the rest of the request, no?
156
+	 *
157
+	 * @param boolean $show_expired whether or not to include expired events
158
+	 * @param boolean $show_deleted whether or not to include deleted events
159
+	 * @param null $limit
160
+	 * @return EE_Datetime[]
161
+	 * @throws EE_Error
162
+	 */
163
+	public function datetimes_ordered($show_expired = true, $show_deleted = false, $limit = null)
164
+	{
165
+		return EEM_Datetime::instance($this->_timezone)->get_datetimes_for_event_ordered_by_DTT_order(
166
+			$this->ID(),
167
+			$show_expired,
168
+			$show_deleted,
169
+			$limit
170
+		);
171
+	}
172
+
173
+
174
+	/**
175
+	 * Returns one related datetime. Mostly only used by some legacy code.
176
+	 *
177
+	 * @return EE_Base_Class|EE_Datetime
178
+	 * @throws EE_Error
179
+	 */
180
+	public function first_datetime()
181
+	{
182
+		return $this->get_first_related('Datetime');
183
+	}
184
+
185
+
186
+	/**
187
+	 * Returns the 'primary' datetime for the event
188
+	 *
189
+	 * @param bool $try_to_exclude_expired
190
+	 * @param bool $try_to_exclude_deleted
191
+	 * @return EE_Datetime
192
+	 * @throws EE_Error
193
+	 */
194
+	public function primary_datetime($try_to_exclude_expired = true, $try_to_exclude_deleted = true)
195
+	{
196
+		if (!empty ($this->_Primary_Datetime)) {
197
+			return $this->_Primary_Datetime;
198
+		}
199
+		$this->_Primary_Datetime = EEM_Datetime::instance($this->_timezone)->get_primary_datetime_for_event(
200
+			$this->ID(),
201
+			$try_to_exclude_expired,
202
+			$try_to_exclude_deleted
203
+		);
204
+		return $this->_Primary_Datetime;
205
+	}
206
+
207
+
208
+	/**
209
+	 * Gets all the tickets available for purchase of this event
210
+	 *
211
+	 * @param array $query_params like EEM_Base::get_all
212
+	 * @return EE_Base_Class[]|EE_Ticket[]
213
+	 * @throws EE_Error
214
+	 */
215
+	public function tickets($query_params = array())
216
+	{
217
+		//first get all datetimes
218
+		$datetimes = $this->datetimes_ordered();
219
+		if (!$datetimes) {
220
+			return array();
221
+		}
222
+		$datetime_ids = array();
223
+		foreach ($datetimes as $datetime) {
224
+			$datetime_ids[] = $datetime->ID();
225
+		}
226
+		$where_params = array('Datetime.DTT_ID' => array('IN', $datetime_ids));
227
+		//if incoming $query_params has where conditions let's merge but not override existing.
228
+		if (is_array($query_params) && isset($query_params[0])) {
229
+			$where_params = array_merge($query_params[0], $where_params);
230
+			unset($query_params[0]);
231
+		}
232
+		//now add $where_params to $query_params
233
+		$query_params[0] = $where_params;
234
+		return EEM_Ticket::instance()->get_all($query_params);
235
+	}
236
+
237
+
238
+	/**
239
+	 * get all unexpired untrashed tickets
240
+	 *
241
+	 * @return EE_Ticket[]
242
+	 * @throws EE_Error
243
+	 */
244
+	public function active_tickets()
245
+	{
246
+		return $this->tickets(array(
247
+			array(
248
+				'TKT_end_date' => array('>=', EEM_Ticket::instance()->current_time_for_query('TKT_end_date')),
249
+				'TKT_deleted' => false,
250
+			),
251
+		));
252
+	}
253
+
254
+
255
+	/**
256
+	 * @return bool
257
+	 * @throws EE_Error
258
+	 */
259
+	public function additional_limit()
260
+	{
261
+		return $this->get('EVT_additional_limit');
262
+	}
263
+
264
+
265
+	/**
266
+	 * @return bool
267
+	 * @throws EE_Error
268
+	 */
269
+	public function allow_overflow()
270
+	{
271
+		return $this->get('EVT_allow_overflow');
272
+	}
273
+
274
+
275
+	/**
276
+	 * @return bool
277
+	 * @throws EE_Error
278
+	 */
279
+	public function created()
280
+	{
281
+		return $this->get('EVT_created');
282
+	}
283
+
284
+
285
+	/**
286
+	 * @return bool
287
+	 * @throws EE_Error
288
+	 */
289
+	public function description()
290
+	{
291
+		return $this->get('EVT_desc');
292
+	}
293
+
294
+
295
+	/**
296
+	 * Runs do_shortcode and wpautop on the description
297
+	 *
298
+	 * @return string of html
299
+	 * @throws EE_Error
300
+	 */
301
+	public function description_filtered()
302
+	{
303
+		return $this->get_pretty('EVT_desc');
304
+	}
305
+
306
+
307
+	/**
308
+	 * @return bool
309
+	 * @throws EE_Error
310
+	 */
311
+	public function display_description()
312
+	{
313
+		return $this->get('EVT_display_desc');
314
+	}
315
+
316
+
317
+	/**
318
+	 * @return bool
319
+	 * @throws EE_Error
320
+	 */
321
+	public function display_ticket_selector()
322
+	{
323
+		return (bool)$this->get('EVT_display_ticket_selector');
324
+	}
325
+
326
+
327
+	/**
328
+	 * @return bool
329
+	 * @throws EE_Error
330
+	 */
331
+	public function external_url()
332
+	{
333
+		return $this->get('EVT_external_URL');
334
+	}
335
+
336
+
337
+	/**
338
+	 * @return bool
339
+	 * @throws EE_Error
340
+	 */
341
+	public function member_only()
342
+	{
343
+		return $this->get('EVT_member_only');
344
+	}
345
+
346
+
347
+	/**
348
+	 * @return bool
349
+	 * @throws EE_Error
350
+	 */
351
+	public function phone()
352
+	{
353
+		return $this->get('EVT_phone');
354
+	}
355
+
356
+
357
+	/**
358
+	 * @return bool
359
+	 * @throws EE_Error
360
+	 */
361
+	public function modified()
362
+	{
363
+		return $this->get('EVT_modified');
364
+	}
365
+
366
+
367
+	/**
368
+	 * @return bool
369
+	 * @throws EE_Error
370
+	 */
371
+	public function name()
372
+	{
373
+		return $this->get('EVT_name');
374
+	}
375
+
376
+
377
+	/**
378
+	 * @return bool
379
+	 * @throws EE_Error
380
+	 */
381
+	public function order()
382
+	{
383
+		return $this->get('EVT_order');
384
+	}
385
+
386
+
387
+	/**
388
+	 * @return bool|string
389
+	 * @throws EE_Error
390
+	 */
391
+	public function default_registration_status()
392
+	{
393
+		$event_default_registration_status = $this->get('EVT_default_registration_status');
394
+		return !empty($event_default_registration_status)
395
+			? $event_default_registration_status
396
+			: EE_Registry::instance()->CFG->registration->default_STS_ID;
397
+	}
398
+
399
+
400
+	/**
401
+	 * @param int $num_words
402
+	 * @param null $more
403
+	 * @param bool $not_full_desc
404
+	 * @return bool|string
405
+	 * @throws EE_Error
406
+	 */
407
+	public function short_description($num_words = 55, $more = null, $not_full_desc = false)
408
+	{
409
+		$short_desc = $this->get('EVT_short_desc');
410
+		if (!empty($short_desc) || $not_full_desc) {
411
+			return $short_desc;
412
+		}
413
+		$full_desc = $this->get('EVT_desc');
414
+		return wp_trim_words($full_desc, $num_words, $more);
415
+	}
416
+
417
+
418
+	/**
419
+	 * @return bool
420
+	 * @throws EE_Error
421
+	 */
422
+	public function slug()
423
+	{
424
+		return $this->get('EVT_slug');
425
+	}
426
+
427
+
428
+	/**
429
+	 * @return bool
430
+	 * @throws EE_Error
431
+	 */
432
+	public function timezone_string()
433
+	{
434
+		return $this->get('EVT_timezone_string');
435
+	}
436
+
437
+
438
+	/**
439
+	 * @return bool
440
+	 * @throws EE_Error
441
+	 */
442
+	public function visible_on()
443
+	{
444
+		return $this->get('EVT_visible_on');
445
+	}
446
+
447
+
448
+	/**
449
+	 * @return int
450
+	 * @throws EE_Error
451
+	 */
452
+	public function wp_user()
453
+	{
454
+		return $this->get('EVT_wp_user');
455
+	}
456
+
457
+
458
+	/**
459
+	 * @return bool
460
+	 * @throws EE_Error
461
+	 */
462
+	public function donations()
463
+	{
464
+		return $this->get('EVT_donations');
465
+	}
466
+
467
+
468
+	/**
469
+	 * @param $limit
470
+	 * @throws EE_Error
471
+	 */
472
+	public function set_additional_limit($limit)
473
+	{
474
+		$this->set('EVT_additional_limit', $limit);
475
+	}
476
+
477
+
478
+	/**
479
+	 * @param $created
480
+	 * @throws EE_Error
481
+	 */
482
+	public function set_created($created)
483
+	{
484
+		$this->set('EVT_created', $created);
485
+	}
486
+
487
+
488
+	/**
489
+	 * @param $desc
490
+	 * @throws EE_Error
491
+	 */
492
+	public function set_description($desc)
493
+	{
494
+		$this->set('EVT_desc', $desc);
495
+	}
496
+
497
+
498
+	/**
499
+	 * @param $display_desc
500
+	 * @throws EE_Error
501
+	 */
502
+	public function set_display_description($display_desc)
503
+	{
504
+		$this->set('EVT_display_desc', $display_desc);
505
+	}
506
+
507
+
508
+	/**
509
+	 * @param $display_ticket_selector
510
+	 * @throws EE_Error
511
+	 */
512
+	public function set_display_ticket_selector($display_ticket_selector)
513
+	{
514
+		$this->set('EVT_display_ticket_selector', $display_ticket_selector);
515
+	}
516
+
517
+
518
+	/**
519
+	 * @param $external_url
520
+	 * @throws EE_Error
521
+	 */
522
+	public function set_external_url($external_url)
523
+	{
524
+		$this->set('EVT_external_URL', $external_url);
525
+	}
526
+
527
+
528
+	/**
529
+	 * @param $member_only
530
+	 * @throws EE_Error
531
+	 */
532
+	public function set_member_only($member_only)
533
+	{
534
+		$this->set('EVT_member_only', $member_only);
535
+	}
536
+
537
+
538
+	/**
539
+	 * @param $event_phone
540
+	 * @throws EE_Error
541
+	 */
542
+	public function set_event_phone($event_phone)
543
+	{
544
+		$this->set('EVT_phone', $event_phone);
545
+	}
546
+
547
+
548
+	/**
549
+	 * @param $modified
550
+	 * @throws EE_Error
551
+	 */
552
+	public function set_modified($modified)
553
+	{
554
+		$this->set('EVT_modified', $modified);
555
+	}
556
+
557
+
558
+	/**
559
+	 * @param $name
560
+	 * @throws EE_Error
561
+	 */
562
+	public function set_name($name)
563
+	{
564
+		$this->set('EVT_name', $name);
565
+	}
566
+
567
+
568
+	/**
569
+	 * @param $order
570
+	 * @throws EE_Error
571
+	 */
572
+	public function set_order($order)
573
+	{
574
+		$this->set('EVT_order', $order);
575
+	}
576
+
577
+
578
+	/**
579
+	 * @param $short_desc
580
+	 * @throws EE_Error
581
+	 */
582
+	public function set_short_description($short_desc)
583
+	{
584
+		$this->set('EVT_short_desc', $short_desc);
585
+	}
586
+
587
+
588
+	/**
589
+	 * @param $slug
590
+	 * @throws EE_Error
591
+	 */
592
+	public function set_slug($slug)
593
+	{
594
+		$this->set('EVT_slug', $slug);
595
+	}
596
+
597
+
598
+	/**
599
+	 * @param $timezone_string
600
+	 * @throws EE_Error
601
+	 */
602
+	public function set_timezone_string($timezone_string)
603
+	{
604
+		$this->set('EVT_timezone_string', $timezone_string);
605
+	}
606
+
607
+
608
+	/**
609
+	 * @param $visible_on
610
+	 * @throws EE_Error
611
+	 */
612
+	public function set_visible_on($visible_on)
613
+	{
614
+		$this->set('EVT_visible_on', $visible_on);
615
+	}
616
+
617
+
618
+	/**
619
+	 * @param $wp_user
620
+	 * @throws EE_Error
621
+	 */
622
+	public function set_wp_user($wp_user)
623
+	{
624
+		$this->set('EVT_wp_user', $wp_user);
625
+	}
626
+
627
+
628
+	/**
629
+	 * @param $default_registration_status
630
+	 * @throws EE_Error
631
+	 */
632
+	public function set_default_registration_status($default_registration_status)
633
+	{
634
+		$this->set('EVT_default_registration_status', $default_registration_status);
635
+	}
636
+
637
+
638
+	/**
639
+	 * @param $donations
640
+	 * @throws EE_Error
641
+	 */
642
+	public function set_donations($donations)
643
+	{
644
+		$this->set('EVT_donations', $donations);
645
+	}
646
+
647
+
648
+	/**
649
+	 * Adds a venue to this event
650
+	 *
651
+	 * @param EE_Venue /int $venue_id_or_obj
652
+	 * @return EE_Base_Class|EE_Venue
653
+	 * @throws EE_Error
654
+	 */
655
+	public function add_venue($venue_id_or_obj)
656
+	{
657
+		return $this->_add_relation_to($venue_id_or_obj, 'Venue');
658
+	}
659
+
660
+
661
+	/**
662
+	 * Removes a venue from the event
663
+	 *
664
+	 * @param EE_Venue /int $venue_id_or_obj
665
+	 * @return EE_Base_Class|EE_Venue
666
+	 * @throws EE_Error
667
+	 */
668
+	public function remove_venue($venue_id_or_obj)
669
+	{
670
+		return $this->_remove_relation_to($venue_id_or_obj, 'Venue');
671
+	}
672
+
673
+
674
+	/**
675
+	 * Gets all the venues related ot the event. May provide additional $query_params if desired
676
+	 *
677
+	 * @param array $query_params like EEM_Base::get_all's $query_params
678
+	 * @return EE_Base_Class[]|EE_Venue[]
679
+	 * @throws EE_Error
680
+	 */
681
+	public function venues($query_params = array())
682
+	{
683
+		return $this->get_many_related('Venue', $query_params);
684
+	}
685
+
686
+
687
+	/**
688
+	 * check if event id is present and if event is published
689
+	 *
690
+	 * @access public
691
+	 * @return boolean true yes, false no
692
+	 * @throws EE_Error
693
+	 */
694
+	private function _has_ID_and_is_published()
695
+	{
696
+		// first check if event id is present and not NULL,
697
+		// then check if this event is published (or any of the equivalent "published" statuses)
698
+		return
699
+			$this->ID() && $this->ID() !== null
700
+			&& (
701
+				$this->status() === 'publish'
702
+				|| $this->status() === EEM_Event::sold_out
703
+				|| $this->status() === EEM_Event::postponed
704
+				|| $this->status() === EEM_Event::cancelled
705
+			);
706
+	}
707
+
708
+
709
+	/**
710
+	 * This simply compares the internal dates with NOW and determines if the event is upcoming or not.
711
+	 *
712
+	 * @access public
713
+	 * @return boolean true yes, false no
714
+	 * @throws EE_Error
715
+	 */
716
+	public function is_upcoming()
717
+	{
718
+		// check if event id is present and if this event is published
719
+		if ($this->is_inactive()) {
720
+			return false;
721
+		}
722
+		// set initial value
723
+		$upcoming = false;
724
+		//next let's get all datetimes and loop through them
725
+		$datetimes = $this->datetimes_in_chronological_order();
726
+		foreach ($datetimes as $datetime) {
727
+			if ($datetime instanceof EE_Datetime) {
728
+				//if this dtt is expired then we continue cause one of the other datetimes might be upcoming.
729
+				if ($datetime->is_expired()) {
730
+					continue;
731
+				}
732
+				//if this dtt is active then we return false.
733
+				if ($datetime->is_active()) {
734
+					return false;
735
+				}
736
+				//otherwise let's check upcoming status
737
+				$upcoming = $datetime->is_upcoming();
738
+			}
739
+		}
740
+		return $upcoming;
741
+	}
742
+
743
+
744
+	/**
745
+	 * @return bool
746
+	 * @throws EE_Error
747
+	 */
748
+	public function is_active()
749
+	{
750
+		// check if event id is present and if this event is published
751
+		if ($this->is_inactive()) {
752
+			return false;
753
+		}
754
+		// set initial value
755
+		$active = false;
756
+		//next let's get all datetimes and loop through them
757
+		$datetimes = $this->datetimes_in_chronological_order();
758
+		foreach ($datetimes as $datetime) {
759
+			if ($datetime instanceof EE_Datetime) {
760
+				//if this dtt is expired then we continue cause one of the other datetimes might be active.
761
+				if ($datetime->is_expired()) {
762
+					continue;
763
+				}
764
+				//if this dtt is upcoming then we return false.
765
+				if ($datetime->is_upcoming()) {
766
+					return false;
767
+				}
768
+				//otherwise let's check active status
769
+				$active = $datetime->is_active();
770
+			}
771
+		}
772
+		return $active;
773
+	}
774
+
775
+
776
+	/**
777
+	 * @return bool
778
+	 * @throws EE_Error
779
+	 */
780
+	public function is_expired()
781
+	{
782
+		// check if event id is present and if this event is published
783
+		if ($this->is_inactive()) {
784
+			return false;
785
+		}
786
+		// set initial value
787
+		$expired = false;
788
+		//first let's get all datetimes and loop through them
789
+		$datetimes = $this->datetimes_in_chronological_order();
790
+		foreach ($datetimes as $datetime) {
791
+			if ($datetime instanceof EE_Datetime) {
792
+				//if this dtt is upcoming or active then we return false.
793
+				if ($datetime->is_upcoming() || $datetime->is_active()) {
794
+					return false;
795
+				}
796
+				//otherwise let's check active status
797
+				$expired = $datetime->is_expired();
798
+			}
799
+		}
800
+		return $expired;
801
+	}
802
+
803
+
804
+	/**
805
+	 * @return bool
806
+	 * @throws EE_Error
807
+	 */
808
+	public function is_inactive()
809
+	{
810
+		// check if event id is present and if this event is published
811
+		if ($this->_has_ID_and_is_published()) {
812
+			return false;
813
+		}
814
+		return true;
815
+	}
816
+
817
+
818
+	/**
819
+	 * calculate spaces remaining based on "saleable" tickets
820
+	 *
821
+	 * @param array $tickets
822
+	 * @param bool $filtered
823
+	 * @return int|float
824
+	 * @throws EE_Error
825
+	 */
826
+	public function spaces_remaining($tickets = array(), $filtered = true)
827
+	{
828
+		// get all unexpired untrashed tickets if nothing was passed
829
+		$tickets = !empty($tickets) ? $tickets : $this->active_tickets();
830
+		// set initial value
831
+		$spaces_remaining = 0;
832
+		if (!empty($tickets)) {
833
+			foreach ($tickets as $ticket) {
834
+				if ($ticket instanceof EE_Ticket) {
835
+					$spaces_remaining += $ticket->qty('saleable');
836
+				}
837
+			}
838
+		}
839
+		return $filtered
840
+			? apply_filters(
841
+				'FHEE_EE_Event__spaces_remaining',
842
+				$spaces_remaining,
843
+				$this,
844
+				$tickets
845
+			)
846
+			: $spaces_remaining;
847
+	}
848
+
849
+
850
+	/**
851
+	 *    perform_sold_out_status_check
852
+	 *    checks all of this events's datetime  reg_limit - sold values to determine if ANY datetimes have spaces available...
853
+	 *    if NOT, then the event status will get toggled to 'sold_out'
854
+	 *
855
+	 * @access public
856
+	 * @return bool    return the ACTUAL sold out state.
857
+	 * @throws EE_Error
858
+	 */
859
+	public function perform_sold_out_status_check()
860
+	{
861
+		// get all unexpired untrashed tickets
862
+		$tickets = $this->active_tickets();
863
+		// if all the tickets are just expired, then don't update the event status to sold out
864
+		if (empty($tickets)) {
865
+			return true;
866
+		}
867
+		$spaces_remaining = $this->spaces_remaining($tickets);
868
+		if ($spaces_remaining < 1) {
869
+			$this->set_status(EEM_Event::sold_out);
870
+			$this->save();
871
+			$sold_out = true;
872
+		} else {
873
+			$sold_out = false;
874
+			// was event previously marked as sold out ?
875
+			if ($this->status() === EEM_Event::sold_out) {
876
+				// revert status to previous value, if it was set
877
+				$previous_event_status = $this->get_post_meta('_previous_event_status', true);
878
+				if ($previous_event_status) {
879
+					$this->set_status($previous_event_status);
880
+					$this->save();
881
+				}
882
+			}
883
+		}
884
+		do_action('AHEE__EE_Event__perform_sold_out_status_check__end', $this, $sold_out, $spaces_remaining, $tickets);
885
+		return $sold_out;
886
+	}
887
+
888
+
889
+	/**
890
+	 * This returns the total remaining spaces for sale on this event.
891
+	 * ############################
892
+	 * VERY IMPORTANT FOR DEVELOPERS:
893
+	 * While included here, this method is still being tested internally, so its signature and behaviour COULD change.
894
+	 * While this comment block is in place, usage is at your own risk and know that it may change in future builds.
895
+	 * ############################
896
+	 *
897
+	 * @uses EE_Event::total_available_spaces()
898
+	 * @return float|int  (EE_INF is returned as float)
899
+	 * @throws InvalidArgumentException
900
+	 * @throws InvalidStatusException
901
+	 * @throws EE_Error
902
+	 */
903
+	public function spaces_remaining_for_sale()
904
+	{
905
+		//first get total available spaces including consideration for tickets that have already sold.
906
+		$spaces_available = $this->total_available_spaces(true);
907
+		//if total available = 0, then exit right away because that means everything is expired.
908
+		if ($spaces_available === 0) {
909
+			return 0;
910
+		}
911
+		//subtract total approved registrations from spaces available to get how many are remaining.
912
+		$spots_taken = EEM_Registration::instance()->event_reg_count_for_statuses($this->ID());
913
+		$spaces_remaining = $spaces_available - $spots_taken;
914
+		return $spaces_remaining > 0 ? $spaces_remaining : 0;
915
+	}
916
+
917
+
918
+	/**
919
+	 * This returns the total spaces available for an event while considering all the qtys on the tickets and the reg limits
920
+	 * on the datetimes attached to this event.
921
+	 * ############################
922
+	 * VERY IMPORTANT FOR DEVELOPERS:
923
+	 * While included here, this method is still being tested internally, so its signature and behaviour COULD change. While
924
+	 * this comment block is in place, usage is at your own risk and know that it may change in future builds.
925
+	 * ############################
926
+	 * Note: by "spaces available" we are not returning how many spaces remain.  That is a calculation involving using the value
927
+	 * from this method and subtracting the approved registrations for the event.
928
+	 *
929
+	 * @param   bool $current_total_available Whether to consider any tickets that have already sold in our calculation.
930
+	 *                                              If this is false, then we return the most tickets that could ever be sold
931
+	 *                                              for this event with the datetime and tickets setup on the event under optimal
932
+	 *                                              selling conditions.  Otherwise we return a live calculation of spaces available
933
+	 *                                              based on tickets sold.  Depending on setup and stage of sales, this
934
+	 *                                              may appear to equal remaining tickets.  However, the more tickets are
935
+	 *                                              sold out, the more accurate the "live" total is.
936
+	 * @return  int|float  (Note: if EE_INF is returned its considered a float by PHP)
937
+	 * @throws EE_Error
938
+	 */
939
+	public function total_available_spaces($current_total_available = false)
940
+	{
941
+		$spaces_available = 0;
942
+		//first get all tickets on the event and include expired tickets
943
+		$tickets = $this->tickets(array('default_where_conditions' => 'none'));
944
+		$ticket_sums = array();
945
+		$datetimes = array();
946
+		$datetime_limits = array();
947
+		//loop through tickets and normalize them
948
+		foreach ($tickets as $ticket) {
949
+			$datetimes = $ticket->datetimes(array('order_by' => array('DTT_reg_limit' => 'ASC')));
950
+			if (empty($datetimes)) {
951
+				continue;
952
+			}
953
+			//first datetime should be the lowest datetime
954
+			$least_datetime = reset($datetimes);
955
+			//lets reset the ticket quantity to be the lower of either the lowest datetime reg limit or the ticket quantity
956
+			//IF datetimes sold (and we're not doing current live total available, then use spaces remaining for datetime, not reg_limit.
957
+			if ($current_total_available) {
958
+				if ($ticket->is_remaining()) {
959
+					$remaining = $ticket->remaining();
960
+				} else {
961
+					$spaces_available += $ticket->sold();
962
+					//and we don't cache this ticket to our list because its sold out.
963
+					continue;
964
+				}
965
+			} else {
966
+				$remaining = min($ticket->qty(), $least_datetime->reg_limit());
967
+			}
968
+			//if $ticket_limit == infinity then let's drop out right away and just return that because any infinity amount trumps all other "available" amounts.
969
+			if ($remaining === EE_INF) {
970
+				return EE_INF;
971
+			}
972
+			//multiply normalized $tkt quantity by the number of datetimes on the ticket as the "sum"
973
+			//also include the sum of all the datetime reg limits on the ticket for breaking ties.
974
+			$ticket_sums[$ticket->ID()]['sum'] = $remaining * count($datetimes);
975
+			$ticket_sums[$ticket->ID()]['datetime_sums'] = 0;
976
+			foreach ($datetimes as $datetime) {
977
+				if ($datetime->reg_limit() === EE_INF) {
978
+					$ticket_sums[$ticket->ID()]['datetime_sums'] = EE_INF;
979
+				} else {
980
+					$ticket_sums[$ticket->ID()]['datetime_sums'] += $current_total_available
981
+						? $datetime->spaces_remaining()
982
+						: $datetime->reg_limit();
983
+				}
984
+				$datetime_limits[$datetime->ID()] = $current_total_available
985
+					? $datetime->spaces_remaining()
986
+					: $datetime->reg_limit();
987
+			}
988
+			$ticket_sums[$ticket->ID()]['ticket'] = $ticket;
989
+		}
990
+		//The order is sorted by lowest available first (which is calculated for each ticket by multiplying the normalized
991
+		//ticket quantity by the number of datetimes on the ticket).  For tie-breakers, then the next sort is based on the
992
+		//ticket with the greatest sum of all remaining datetime->spaces_remaining() ( or $datetime->reg_limit() if not
993
+		//$current_total_available ) for the datetimes on the ticket.
994
+		usort($ticket_sums, function ($a, $b) {
995
+			if ($a['sum'] === $b['sum']) {
996
+				if ($a['datetime_sums'] === $b['datetime_sums']) {
997
+					return 0;
998
+				}
999
+				return $a['datetime_sums'] < $b['datetime_sums'] ? 1 : -1;
1000
+			}
1001
+			return ($a['sum'] < $b['sum']) ? -1 : 1;
1002
+		});
1003
+		//now let's loop through the sorted tickets and simulate sellouts
1004
+		foreach ($ticket_sums as $ticket_info) {
1005
+			if ($ticket_info['ticket'] instanceof EE_Ticket) {
1006
+				$datetimes = $ticket_info['ticket']->datetimes(array('order_by' => array('DTT_reg_limit' => 'ASC')));
1007
+				//need to sort these $datetimes by remaining (only if $current_total_available)
1008
+				//setup datetimes for simulation
1009
+				$ticket_datetimes_remaining = array();
1010
+				foreach ($datetimes as $datetime) {
1011
+					$DTT_ID = $datetime->ID();
1012
+					$ticket_datetimes_remaining[$DTT_ID]['rem'] = $datetime_limits[$DTT_ID];
1013
+					$ticket_datetimes_remaining[$DTT_ID]['datetime'] = $datetime;
1014
+				}
1015
+				usort($ticket_datetimes_remaining, function ($a, $b) {
1016
+					if ($a['rem'] === $b['rem']) {
1017
+						return 0;
1018
+					}
1019
+					return ($a['rem'] < $b['rem']) ? -1 : 1;
1020
+				});
1021
+				//get the remaining on the first datetime (which should be the one with the least remaining) and that is
1022
+				//what we add to the spaces_available running total.  Then we need to decrease the remaining on our datetime tracker.
1023
+				$lowest_datetime = reset($ticket_datetimes_remaining);
1024
+				//need to get the lower of; what the remaining is on the lowest datetime, and the remaining on the ticket.
1025
+				// If this ends up being 0 (because of previous tickets in our simulation selling out), then it has already
1026
+				// been tracked on $spaces available and this ticket is now sold out for the simulation, so we can continue
1027
+				// to the next ticket.
1028
+				if ($current_total_available) {
1029
+					$remaining = min($lowest_datetime['rem'], $ticket_info['ticket']->remaining());
1030
+				} else {
1031
+					$remaining = min($lowest_datetime['rem'], $ticket_info['ticket']->qty());
1032
+				}
1033
+				//if $remaining is infinite that means that all datetimes on this ticket are infinite but we've made it here because all
1034
+				//tickets have a quantity.  So we don't have to track datetimes, we can just use ticket quantities for total
1035
+				//available.
1036
+				if ($remaining === EE_INF) {
1037
+					$spaces_available += $ticket_info['ticket']->qty();
1038
+					continue;
1039
+				}
1040
+				//if ticket has sold amounts then we also need to add that (but only if doing live counts)
1041
+				if ($current_total_available) {
1042
+					$spaces_available += $ticket_info['ticket']->sold();
1043
+				}
1044
+				if ($remaining <= 0) {
1045
+					continue;
1046
+				}
1047
+				$spaces_available += $remaining;
1048
+				//loop through the datetimes and sell them out!
1049
+				foreach ($ticket_datetimes_remaining as $datetime_info) {
1050
+					if ($datetime_info['datetime'] instanceof EE_Datetime) {
1051
+						$datetime_limits[$datetime_info['datetime']->ID()] += -$remaining;
1052
+					}
1053
+				}
1054
+			}
1055
+		}
1056
+		return apply_filters(
1057
+			'FHEE_EE_Event__total_available_spaces__spaces_available',
1058
+			$spaces_available,
1059
+			$this,
1060
+			$datetimes,
1061
+			$tickets
1062
+		);
1063
+	}
1064
+
1065
+
1066
+	/**
1067
+	 * Checks if the event is set to sold out
1068
+	 *
1069
+	 * @param  bool $actual whether or not to perform calculations to not only figure the
1070
+	 *                      actual status but also to flip the status if necessary to sold
1071
+	 *                      out If false, we just check the existing status of the event
1072
+	 * @return boolean
1073
+	 * @throws EE_Error
1074
+	 */
1075
+	public function is_sold_out($actual = false)
1076
+	{
1077
+		if (!$actual) {
1078
+			return $this->status() === EEM_Event::sold_out;
1079
+		}
1080
+		return $this->perform_sold_out_status_check();
1081
+	}
1082
+
1083
+
1084
+	/**
1085
+	 * Checks if the event is marked as postponed
1086
+	 *
1087
+	 * @return boolean
1088
+	 */
1089
+	public function is_postponed()
1090
+	{
1091
+		return $this->status() === EEM_Event::postponed;
1092
+	}
1093
+
1094
+
1095
+	/**
1096
+	 * Checks if the event is marked as cancelled
1097
+	 *
1098
+	 * @return boolean
1099
+	 */
1100
+	public function is_cancelled()
1101
+	{
1102
+		return $this->status() === EEM_Event::cancelled;
1103
+	}
1104
+
1105
+
1106
+	/**
1107
+	 * Get the logical active status in a hierarchical order for all the datetimes.  Note
1108
+	 * Basically, we order the datetimes by EVT_start_date.  Then first test on whether the event is published.  If its
1109
+	 * NOT published then we test for whether its expired or not.  IF it IS published then we test first on whether an
1110
+	 * event has any active dates.  If no active dates then we check for any upcoming dates.  If no upcoming dates then
1111
+	 * the event is considered expired.
1112
+	 * NOTE: this method does NOT calculate whether the datetimes are sold out when event is published.  Sold Out is a status
1113
+	 * set on the EVENT when it is not published and thus is done
1114
+	 *
1115
+	 * @param bool $reset
1116
+	 * @return bool | string - based on EE_Datetime active constants or FALSE if error.
1117
+	 * @throws EE_Error
1118
+	 */
1119
+	public function get_active_status($reset = false)
1120
+	{
1121
+		// if the active status has already been set, then just use that value (unless we are resetting it)
1122
+		if (!empty($this->_active_status) && !$reset) {
1123
+			return $this->_active_status;
1124
+		}
1125
+		//first check if event id is present on this object
1126
+		if (!$this->ID()) {
1127
+			return false;
1128
+		}
1129
+		$where_params_for_event = array(array('EVT_ID' => $this->ID()));
1130
+		//if event is published:
1131
+		if ($this->status() === 'publish') {
1132
+			//active?
1133
+			if (EEM_Datetime::instance()->get_datetime_count_for_status(EE_Datetime::active, $where_params_for_event) > 0) {
1134
+				$this->_active_status = EE_Datetime::active;
1135
+			} else {
1136
+				//upcoming?
1137
+				if (EEM_Datetime::instance()->get_datetime_count_for_status(EE_Datetime::upcoming, $where_params_for_event) > 0) {
1138
+					$this->_active_status = EE_Datetime::upcoming;
1139
+				} else {
1140
+					//expired?
1141
+					if (
1142
+						EEM_Datetime::instance()->get_datetime_count_for_status(EE_Datetime::expired, $where_params_for_event) > 0
1143
+					) {
1144
+						$this->_active_status = EE_Datetime::expired;
1145
+					} else {
1146
+						//it would be odd if things make it this far because it basically means there are no datetime's
1147
+						//attached to the event.  So in this case it will just be considered inactive.
1148
+						$this->_active_status = EE_Datetime::inactive;
1149
+					}
1150
+				}
1151
+			}
1152
+		} else {
1153
+			//the event is not published, so let's just set it's active status according to its' post status
1154
+			switch ($this->status()) {
1155
+				case EEM_Event::sold_out :
1156
+					$this->_active_status = EE_Datetime::sold_out;
1157
+					break;
1158
+				case EEM_Event::cancelled :
1159
+					$this->_active_status = EE_Datetime::cancelled;
1160
+					break;
1161
+				case EEM_Event::postponed :
1162
+					$this->_active_status = EE_Datetime::postponed;
1163
+					break;
1164
+				default :
1165
+					$this->_active_status = EE_Datetime::inactive;
1166
+			}
1167
+		}
1168
+		return $this->_active_status;
1169
+	}
1170
+
1171
+
1172
+	/**
1173
+	 *    pretty_active_status
1174
+	 *
1175
+	 * @access public
1176
+	 * @param boolean $echo whether to return (FALSE), or echo out the result (TRUE)
1177
+	 * @return mixed void|string
1178
+	 * @throws EE_Error
1179
+	 */
1180
+	public function pretty_active_status($echo = true)
1181
+	{
1182
+		$active_status = $this->get_active_status();
1183
+		$status = '<span class="ee-status event-active-status-'
1184
+			. $active_status
1185
+			. '">'
1186
+			. EEH_Template::pretty_status($active_status, false, 'sentence')
1187
+			. '</span>';
1188
+		if ($echo) {
1189
+			echo $status;
1190
+			return '';
1191
+		}
1192
+		return $status;
1193
+	}
1194
+
1195
+
1196
+	/**
1197
+	 * @return bool|int
1198
+	 * @throws EE_Error
1199
+	 */
1200
+	public function get_number_of_tickets_sold()
1201
+	{
1202
+		$tkt_sold = 0;
1203
+		if (!$this->ID()) {
1204
+			return 0;
1205
+		}
1206
+		$datetimes = $this->datetimes();
1207
+		foreach ($datetimes as $datetime) {
1208
+			if ($datetime instanceof EE_Datetime) {
1209
+				$tkt_sold += $datetime->sold();
1210
+			}
1211
+		}
1212
+		return $tkt_sold;
1213
+	}
1214
+
1215
+
1216
+	/**
1217
+	 * This just returns a count of all the registrations for this event
1218
+	 *
1219
+	 * @access  public
1220
+	 * @return int
1221
+	 * @throws EE_Error
1222
+	 */
1223
+	public function get_count_of_all_registrations()
1224
+	{
1225
+		return EEM_Event::instance()->count_related($this, 'Registration');
1226
+	}
1227
+
1228
+
1229
+	/**
1230
+	 * This returns the ticket with the earliest start time that is
1231
+	 * available for this event (across all datetimes attached to the event)
1232
+	 *
1233
+	 * @return EE_Base_Class|EE_Ticket|null
1234
+	 * @throws EE_Error
1235
+	 */
1236
+	public function get_ticket_with_earliest_start_time()
1237
+	{
1238
+		$where['Datetime.EVT_ID'] = $this->ID();
1239
+		$query_params = array($where, 'order_by' => array('TKT_start_date' => 'ASC'));
1240
+		return EE_Registry::instance()->load_model('Ticket')->get_one($query_params);
1241
+	}
1242
+
1243
+
1244
+	/**
1245
+	 * This returns the ticket with the latest end time that is available
1246
+	 * for this event (across all datetimes attached to the event)
1247
+	 *
1248
+	 * @return EE_Base_Class|EE_Ticket|null
1249
+	 * @throws EE_Error
1250
+	 */
1251
+	public function get_ticket_with_latest_end_time()
1252
+	{
1253
+		$where['Datetime.EVT_ID'] = $this->ID();
1254
+		$query_params = array($where, 'order_by' => array('TKT_end_date' => 'DESC'));
1255
+		return EE_Registry::instance()->load_model('Ticket')->get_one($query_params);
1256
+	}
1257
+
1258
+
1259
+	/**
1260
+	 * This returns whether there are any tickets on sale for this event.
1261
+	 *
1262
+	 * @return bool true = YES tickets on sale.
1263
+	 * @throws EE_Error
1264
+	 */
1265
+	public function tickets_on_sale()
1266
+	{
1267
+		$earliest_ticket = $this->get_ticket_with_earliest_start_time();
1268
+		$latest_ticket = $this->get_ticket_with_latest_end_time();
1269
+		if (!$latest_ticket instanceof EE_Ticket && !$earliest_ticket instanceof EE_Ticket) {
1270
+			return false;
1271
+		}
1272
+		//check on sale for these two tickets.
1273
+		if ($latest_ticket->is_on_sale() || $earliest_ticket->is_on_sale()) {
1274
+			return true;
1275
+		}
1276
+		return false;
1277
+	}
1278
+
1279
+
1280
+	/**
1281
+	 * Gets the URL for viewing this event on the front-end. Overrides parent
1282
+	 * to check for an external URL first
1283
+	 *
1284
+	 * @return string
1285
+	 * @throws EE_Error
1286
+	 */
1287
+	public function get_permalink()
1288
+	{
1289
+		if ($this->external_url()) {
1290
+			return $this->external_url();
1291
+		}
1292
+		return parent::get_permalink();
1293
+	}
1294
+
1295
+
1296
+	/**
1297
+	 * Gets the first term for 'espresso_event_categories' we can find
1298
+	 *
1299
+	 * @param array $query_params like EEM_Base::get_all
1300
+	 * @return EE_Base_Class|EE_Term|null
1301
+	 * @throws EE_Error
1302
+	 */
1303
+	public function first_event_category($query_params = array())
1304
+	{
1305
+		$query_params[0]['Term_Taxonomy.taxonomy'] = 'espresso_event_categories';
1306
+		$query_params[0]['Term_Taxonomy.Event.EVT_ID'] = $this->ID();
1307
+		return EEM_Term::instance()->get_one($query_params);
1308
+	}
1309
+
1310
+
1311
+	/**
1312
+	 * Gets all terms for 'espresso_event_categories' we can find
1313
+	 *
1314
+	 * @param array $query_params
1315
+	 * @return EE_Base_Class[]|EE_Term[]
1316
+	 * @throws EE_Error
1317
+	 */
1318
+	public function get_all_event_categories($query_params = array())
1319
+	{
1320
+		$query_params[0]['Term_Taxonomy.taxonomy'] = 'espresso_event_categories';
1321
+		$query_params[0]['Term_Taxonomy.Event.EVT_ID'] = $this->ID();
1322
+		return EEM_Term::instance()->get_all($query_params);
1323
+	}
1324
+
1325
+
1326
+	/**
1327
+	 * Gets all the question groups, ordering them by QSG_order ascending
1328
+	 *
1329
+	 * @param array $query_params @see EEM_Base::get_all
1330
+	 * @return EE_Base_Class[]|EE_Question_Group[]
1331
+	 * @throws EE_Error
1332
+	 */
1333
+	public function question_groups($query_params = array())
1334
+	{
1335
+		$query_params = !empty($query_params) ? $query_params : array('order_by' => array('QSG_order' => 'ASC'));
1336
+		return $this->get_many_related('Question_Group', $query_params);
1337
+	}
1338
+
1339
+
1340
+	/**
1341
+	 * Implementation for EEI_Has_Icon interface method.
1342
+	 *
1343
+	 * @see EEI_Visual_Representation for comments
1344
+	 * @return string
1345
+	 */
1346
+	public function get_icon()
1347
+	{
1348
+		return '<span class="dashicons dashicons-flag"></span>';
1349
+	}
1350
+
1351
+
1352
+	/**
1353
+	 * Implementation for EEI_Admin_Links interface method.
1354
+	 *
1355
+	 * @see EEI_Admin_Links for comments
1356
+	 * @return string
1357
+	 * @throws EE_Error
1358
+	 */
1359
+	public function get_admin_details_link()
1360
+	{
1361
+		return $this->get_admin_edit_link();
1362
+	}
1363
+
1364
+
1365
+	/**
1366
+	 * Implementation for EEI_Admin_Links interface method.
1367
+	 *
1368
+	 * @see EEI_Admin_Links for comments
1369
+	 * @return string
1370
+	 * @throws EE_Error
1371
+	 */
1372
+	public function get_admin_edit_link()
1373
+	{
1374
+		return EEH_URL::add_query_args_and_nonce(array(
1375
+			'page' => 'espresso_events',
1376
+			'action' => 'edit',
1377
+			'post' => $this->ID(),
1378
+		),
1379
+			admin_url('admin.php')
1380
+		);
1381
+	}
1382
+
1383
+
1384
+	/**
1385
+	 * Implementation for EEI_Admin_Links interface method.
1386
+	 *
1387
+	 * @see EEI_Admin_Links for comments
1388
+	 * @return string
1389
+	 */
1390
+	public function get_admin_settings_link()
1391
+	{
1392
+		return EEH_URL::add_query_args_and_nonce(array(
1393
+			'page' => 'espresso_events',
1394
+			'action' => 'default_event_settings',
1395
+		),
1396
+			admin_url('admin.php')
1397
+		);
1398
+	}
1399
+
1400
+
1401
+	/**
1402
+	 * Implementation for EEI_Admin_Links interface method.
1403
+	 *
1404
+	 * @see EEI_Admin_Links for comments
1405
+	 * @return string
1406
+	 */
1407
+	public function get_admin_overview_link()
1408
+	{
1409
+		return EEH_URL::add_query_args_and_nonce(array(
1410
+			'page' => 'espresso_events',
1411
+			'action' => 'default',
1412
+		),
1413
+			admin_url('admin.php')
1414
+		);
1415
+	}
1416 1416
 
1417 1417
 }
Please login to merge, or discard this patch.
Spacing   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php use EventEspresso\core\exceptions\InvalidStatusException;
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
 
@@ -95,7 +95,7 @@  discard block
 block discarded – undo
95 95
     public function set_status($new_status = null, $use_default = false)
96 96
     {
97 97
         // if nothing is set, and we aren't explicitly wanting to reset the status, then just leave
98
-        if (empty($new_status) && !$use_default) {
98
+        if (empty($new_status) && ! $use_default) {
99 99
             return;
100 100
         }
101 101
         // get current Event status
@@ -193,7 +193,7 @@  discard block
 block discarded – undo
193 193
      */
194 194
     public function primary_datetime($try_to_exclude_expired = true, $try_to_exclude_deleted = true)
195 195
     {
196
-        if (!empty ($this->_Primary_Datetime)) {
196
+        if ( ! empty ($this->_Primary_Datetime)) {
197 197
             return $this->_Primary_Datetime;
198 198
         }
199 199
         $this->_Primary_Datetime = EEM_Datetime::instance($this->_timezone)->get_primary_datetime_for_event(
@@ -216,7 +216,7 @@  discard block
 block discarded – undo
216 216
     {
217 217
         //first get all datetimes
218 218
         $datetimes = $this->datetimes_ordered();
219
-        if (!$datetimes) {
219
+        if ( ! $datetimes) {
220 220
             return array();
221 221
         }
222 222
         $datetime_ids = array();
@@ -320,7 +320,7 @@  discard block
 block discarded – undo
320 320
      */
321 321
     public function display_ticket_selector()
322 322
     {
323
-        return (bool)$this->get('EVT_display_ticket_selector');
323
+        return (bool) $this->get('EVT_display_ticket_selector');
324 324
     }
325 325
 
326 326
 
@@ -391,7 +391,7 @@  discard block
 block discarded – undo
391 391
     public function default_registration_status()
392 392
     {
393 393
         $event_default_registration_status = $this->get('EVT_default_registration_status');
394
-        return !empty($event_default_registration_status)
394
+        return ! empty($event_default_registration_status)
395 395
             ? $event_default_registration_status
396 396
             : EE_Registry::instance()->CFG->registration->default_STS_ID;
397 397
     }
@@ -407,7 +407,7 @@  discard block
 block discarded – undo
407 407
     public function short_description($num_words = 55, $more = null, $not_full_desc = false)
408 408
     {
409 409
         $short_desc = $this->get('EVT_short_desc');
410
-        if (!empty($short_desc) || $not_full_desc) {
410
+        if ( ! empty($short_desc) || $not_full_desc) {
411 411
             return $short_desc;
412 412
         }
413 413
         $full_desc = $this->get('EVT_desc');
@@ -826,10 +826,10 @@  discard block
 block discarded – undo
826 826
     public function spaces_remaining($tickets = array(), $filtered = true)
827 827
     {
828 828
         // get all unexpired untrashed tickets if nothing was passed
829
-        $tickets = !empty($tickets) ? $tickets : $this->active_tickets();
829
+        $tickets = ! empty($tickets) ? $tickets : $this->active_tickets();
830 830
         // set initial value
831 831
         $spaces_remaining = 0;
832
-        if (!empty($tickets)) {
832
+        if ( ! empty($tickets)) {
833 833
             foreach ($tickets as $ticket) {
834 834
                 if ($ticket instanceof EE_Ticket) {
835 835
                     $spaces_remaining += $ticket->qty('saleable');
@@ -991,7 +991,7 @@  discard block
 block discarded – undo
991 991
         //ticket quantity by the number of datetimes on the ticket).  For tie-breakers, then the next sort is based on the
992 992
         //ticket with the greatest sum of all remaining datetime->spaces_remaining() ( or $datetime->reg_limit() if not
993 993
         //$current_total_available ) for the datetimes on the ticket.
994
-        usort($ticket_sums, function ($a, $b) {
994
+        usort($ticket_sums, function($a, $b) {
995 995
             if ($a['sum'] === $b['sum']) {
996 996
                 if ($a['datetime_sums'] === $b['datetime_sums']) {
997 997
                     return 0;
@@ -1012,7 +1012,7 @@  discard block
 block discarded – undo
1012 1012
                     $ticket_datetimes_remaining[$DTT_ID]['rem'] = $datetime_limits[$DTT_ID];
1013 1013
                     $ticket_datetimes_remaining[$DTT_ID]['datetime'] = $datetime;
1014 1014
                 }
1015
-                usort($ticket_datetimes_remaining, function ($a, $b) {
1015
+                usort($ticket_datetimes_remaining, function($a, $b) {
1016 1016
                     if ($a['rem'] === $b['rem']) {
1017 1017
                         return 0;
1018 1018
                     }
@@ -1074,7 +1074,7 @@  discard block
 block discarded – undo
1074 1074
      */
1075 1075
     public function is_sold_out($actual = false)
1076 1076
     {
1077
-        if (!$actual) {
1077
+        if ( ! $actual) {
1078 1078
             return $this->status() === EEM_Event::sold_out;
1079 1079
         }
1080 1080
         return $this->perform_sold_out_status_check();
@@ -1119,11 +1119,11 @@  discard block
 block discarded – undo
1119 1119
     public function get_active_status($reset = false)
1120 1120
     {
1121 1121
         // if the active status has already been set, then just use that value (unless we are resetting it)
1122
-        if (!empty($this->_active_status) && !$reset) {
1122
+        if ( ! empty($this->_active_status) && ! $reset) {
1123 1123
             return $this->_active_status;
1124 1124
         }
1125 1125
         //first check if event id is present on this object
1126
-        if (!$this->ID()) {
1126
+        if ( ! $this->ID()) {
1127 1127
             return false;
1128 1128
         }
1129 1129
         $where_params_for_event = array(array('EVT_ID' => $this->ID()));
@@ -1200,7 +1200,7 @@  discard block
 block discarded – undo
1200 1200
     public function get_number_of_tickets_sold()
1201 1201
     {
1202 1202
         $tkt_sold = 0;
1203
-        if (!$this->ID()) {
1203
+        if ( ! $this->ID()) {
1204 1204
             return 0;
1205 1205
         }
1206 1206
         $datetimes = $this->datetimes();
@@ -1266,7 +1266,7 @@  discard block
 block discarded – undo
1266 1266
     {
1267 1267
         $earliest_ticket = $this->get_ticket_with_earliest_start_time();
1268 1268
         $latest_ticket = $this->get_ticket_with_latest_end_time();
1269
-        if (!$latest_ticket instanceof EE_Ticket && !$earliest_ticket instanceof EE_Ticket) {
1269
+        if ( ! $latest_ticket instanceof EE_Ticket && ! $earliest_ticket instanceof EE_Ticket) {
1270 1270
             return false;
1271 1271
         }
1272 1272
         //check on sale for these two tickets.
@@ -1332,7 +1332,7 @@  discard block
 block discarded – undo
1332 1332
      */
1333 1333
     public function question_groups($query_params = array())
1334 1334
     {
1335
-        $query_params = !empty($query_params) ? $query_params : array('order_by' => array('QSG_order' => 'ASC'));
1335
+        $query_params = ! empty($query_params) ? $query_params : array('order_by' => array('QSG_order' => 'ASC'));
1336 1336
         return $this->get_many_related('Question_Group', $query_params);
1337 1337
     }
1338 1338
 
Please login to merge, or discard this patch.
core/db_models/EEM_Registration.model.php 4 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -467,7 +467,7 @@
 block discarded – undo
467 467
      * @param    int $ATT_ID
468 468
      * @param    int $att_nmbr in case the ATT_ID is the same for multiple registrations (same details used) then the
469 469
      *                         attendee number is required
470
-     * @return        mixed        array on success, FALSE on fail
470
+     * @return        null|EE_Base_Class        array on success, FALSE on fail
471 471
      * @throws EE_Error
472 472
      */
473 473
     public function get_registration_for_transaction_attendee($TXN_ID = 0, $ATT_ID = 0, $att_nmbr = 0)
Please login to merge, or discard this patch.
Unused Use Statements   -1 removed lines patch added patch discarded remove patch
@@ -1,5 +1,4 @@
 block discarded – undo
1 1
 <?php
2
-use EventEspresso\core\exceptions\InvalidIdentifierException;
3 2
 use EventEspresso\core\exceptions\InvalidStatusException;
4 3
 use EventEspresso\core\services\database\TableAnalysis;
5 4
 
Please login to merge, or discard this patch.
Spacing   +29 added lines, -29 removed lines patch added patch discarded remove patch
@@ -3,7 +3,7 @@  discard block
 block discarded – undo
3 3
 use EventEspresso\core\exceptions\InvalidStatusException;
4 4
 use EventEspresso\core\services\database\TableAnalysis;
5 5
 
6
-if (!defined('EVENT_ESPRESSO_VERSION')) {
6
+if ( ! defined('EVENT_ESPRESSO_VERSION')) {
7 7
     exit('No direct script access allowed');
8 8
 }
9 9
 
@@ -371,13 +371,13 @@  discard block
 block discarded – undo
371 371
         //and the table hasn't actually been created, this could have an error
372 372
         /** @type WPDB $wpdb */
373 373
         global $wpdb;
374
-        if ($this->_get_table_analysis()->tableExists($wpdb->prefix . 'esp_status')) {
374
+        if ($this->_get_table_analysis()->tableExists($wpdb->prefix.'esp_status')) {
375 375
             $results = $wpdb->get_results(
376 376
                 "SELECT STS_ID, STS_code FROM {$wpdb->prefix}esp_status WHERE STS_type = 'registration'"
377 377
             );
378 378
             self::$_reg_status = array();
379 379
             foreach ($results as $status) {
380
-                if (!in_array($status->STS_ID, $exclude, true)) {
380
+                if ( ! in_array($status->STS_ID, $exclude, true)) {
381 381
                     self::$_reg_status[$status->STS_ID] = $status->STS_code;
382 382
                 }
383 383
             }
@@ -435,7 +435,7 @@  discard block
 block discarded – undo
435 435
      */
436 436
     public function get_all_registrations_for_attendee($ATT_ID = 0)
437 437
     {
438
-        if (!$ATT_ID) {
438
+        if ( ! $ATT_ID) {
439 439
             return null;
440 440
         }
441 441
         return $this->get_all(array(array('ATT_ID' => $ATT_ID)));
@@ -452,7 +452,7 @@  discard block
 block discarded – undo
452 452
      */
453 453
     public function get_registration_for_reg_url_link($REG_url_link)
454 454
     {
455
-        if (!$REG_url_link) {
455
+        if ( ! $REG_url_link) {
456 456
             return null;
457 457
         }
458 458
         return $this->get_one(array(array('REG_url_link' => $REG_url_link)));
@@ -499,7 +499,7 @@  discard block
 block discarded – undo
499 499
             'REG_date' => array('>=', $sql_date),
500 500
             'STS_ID' => array('!=', EEM_Registration::status_id_incomplete),
501 501
         );
502
-        if (!EE_Registry::instance()->CAP->current_user_can('ee_read_others_registrations', 'reg_per_day_report')) {
502
+        if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_others_registrations', 'reg_per_day_report')) {
503 503
             $where['Event.EVT_wp_user'] = get_current_user_id();
504 504
         }
505 505
         $query_interval = EEH_DTT_Helper::get_sql_query_interval_for_offset($this->get_timezone(), 'REG_date');
@@ -511,7 +511,7 @@  discard block
 block discarded – undo
511 511
             ),
512 512
             OBJECT,
513 513
             array(
514
-                'regDate' => array('DATE(' . $query_interval . ')', '%s'),
514
+                'regDate' => array('DATE('.$query_interval.')', '%s'),
515 515
                 'total' => array('count(REG_ID)', '%d'),
516 516
             ));
517 517
         return $results;
@@ -530,7 +530,7 @@  discard block
 block discarded – undo
530 530
     public function get_registrations_per_day_and_per_status_report($period = '-1 month')
531 531
     {
532 532
         global $wpdb;
533
-        $registration_table = $wpdb->prefix . 'esp_registration';
533
+        $registration_table = $wpdb->prefix.'esp_registration';
534 534
         $event_table = $wpdb->posts;
535 535
         $sql_date = date('Y-m-d H:i:s', strtotime($period));
536 536
         //prepare the query interval for displaying offset
@@ -539,9 +539,9 @@  discard block
 block discarded – undo
539 539
         $inner_date_query = "SELECT DISTINCT REG_date from {$registration_table} ";
540 540
         $inner_where = ' WHERE';
541 541
         //exclude events not authored by user if permissions in effect
542
-        if (!EE_Registry::instance()->CAP->current_user_can('ee_read_others_registrations', 'reg_per_event_report')) {
542
+        if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_others_registrations', 'reg_per_event_report')) {
543 543
             $inner_date_query .= "LEFT JOIN {$event_table} ON ID = EVT_ID";
544
-            $inner_where .= ' post_author = ' . get_current_user_id() . ' AND';
544
+            $inner_where .= ' post_author = '.get_current_user_id().' AND';
545 545
         }
546 546
         $inner_where .= " REG_date >= '{$sql_date}'";
547 547
         $inner_date_query .= $inner_where;
@@ -564,7 +564,7 @@  discard block
 block discarded – undo
564 564
         //setup the joins
565 565
         $join .= implode(' LEFT JOIN ', $join_parts);
566 566
         //now let's put it all together
567
-        $query = $select . $join . ' GROUP BY Registration_REG_date';
567
+        $query = $select.$join.' GROUP BY Registration_REG_date';
568 568
         //and execute it
569 569
         return $wpdb->get_results($query, ARRAY_A);
570 570
     }
@@ -587,7 +587,7 @@  discard block
 block discarded – undo
587 587
             'STS_ID' => array('!=', EEM_Registration::status_id_incomplete),
588 588
         );
589 589
         if (
590
-        !EE_Registry::instance()->CAP->current_user_can(
590
+        ! EE_Registry::instance()->CAP->current_user_can(
591 591
             'ee_read_others_registrations',
592 592
             'reg_per_event_report'
593 593
         )
@@ -622,16 +622,16 @@  discard block
 block discarded – undo
622 622
     public function get_registrations_per_event_and_per_status_report($period = '-1 month')
623 623
     {
624 624
         global $wpdb;
625
-        $registration_table = $wpdb->prefix . 'esp_registration';
625
+        $registration_table = $wpdb->prefix.'esp_registration';
626 626
         $event_table = $wpdb->posts;
627 627
         $sql_date = date('Y-m-d H:i:s', strtotime($period));
628 628
         //inner date query
629 629
         $inner_date_query = "SELECT DISTINCT EVT_ID, REG_date from $registration_table ";
630 630
         $inner_where = ' WHERE';
631 631
         //exclude events not authored by user if permissions in effect
632
-        if (!EE_Registry::instance()->CAP->current_user_can('ee_read_others_registrations', 'reg_per_event_report')) {
632
+        if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_others_registrations', 'reg_per_event_report')) {
633 633
             $inner_date_query .= "LEFT JOIN {$event_table} ON ID = EVT_ID";
634
-            $inner_where .= ' post_author = ' . get_current_user_id() . ' AND';
634
+            $inner_where .= ' post_author = '.get_current_user_id().' AND';
635 635
         }
636 636
         $inner_where .= " REG_date >= '{$sql_date}'";
637 637
         $inner_date_query .= $inner_where;
@@ -654,7 +654,7 @@  discard block
 block discarded – undo
654 654
         //setup remaining joins
655 655
         $join .= implode(' LEFT JOIN ', $join_parts);
656 656
         //now put it all together
657
-        $query = $select . $join . ' GROUP BY Registration_Event';
657
+        $query = $select.$join.' GROUP BY Registration_Event';
658 658
         //and execute
659 659
         return $wpdb->get_results($query, ARRAY_A);
660 660
     }
@@ -669,7 +669,7 @@  discard block
 block discarded – undo
669 669
      */
670 670
     public function get_primary_registration_for_transaction_ID($TXN_ID = 0)
671 671
     {
672
-        if (!$TXN_ID) {
672
+        if ( ! $TXN_ID) {
673 673
             return null;
674 674
         }
675 675
         return $this->get_one(array(
@@ -737,11 +737,11 @@  discard block
 block discarded – undo
737 737
         $query = $wpdb->prepare(
738 738
             'SELECT '
739 739
             . 'COUNT( DISTINCT checkins.REG_ID ) '
740
-            . 'FROM ' . EEM_Checkin::instance()->table() . ' AS checkins INNER JOIN'
740
+            . 'FROM '.EEM_Checkin::instance()->table().' AS checkins INNER JOIN'
741 741
             . '( SELECT '
742 742
             . 'max( CHK_timestamp ) AS latest_checkin, '
743 743
             . 'REG_ID AS REG_ID '
744
-            . 'FROM ' . EEM_Checkin::instance()->table() . ' '
744
+            . 'FROM '.EEM_Checkin::instance()->table().' '
745 745
             . 'WHERE DTT_ID=%d '
746 746
             . 'GROUP BY REG_ID'
747 747
             . ') AS most_recent_checkin_per_reg '
@@ -752,7 +752,7 @@  discard block
 block discarded – undo
752 752
             $DTT_ID,
753 753
             $checked_in
754 754
         );
755
-        return (int)$wpdb->get_var($query);
755
+        return (int) $wpdb->get_var($query);
756 756
     }
757 757
 
758 758
 
@@ -771,12 +771,12 @@  discard block
 block discarded – undo
771 771
         $query = $wpdb->prepare(
772 772
             'SELECT '
773 773
             . 'COUNT( DISTINCT checkins.REG_ID ) '
774
-            . 'FROM ' . EEM_Checkin::instance()->table() . ' AS checkins INNER JOIN'
774
+            . 'FROM '.EEM_Checkin::instance()->table().' AS checkins INNER JOIN'
775 775
             . '( SELECT '
776 776
             . 'max( CHK_timestamp ) AS latest_checkin, '
777 777
             . 'REG_ID AS REG_ID '
778
-            . 'FROM ' . EEM_Checkin::instance()->table() . ' AS c '
779
-            . 'INNER JOIN ' . EEM_Datetime::instance()->table() . ' AS d '
778
+            . 'FROM '.EEM_Checkin::instance()->table().' AS c '
779
+            . 'INNER JOIN '.EEM_Datetime::instance()->table().' AS d '
780 780
             . 'ON c.DTT_ID=d.DTT_ID '
781 781
             . 'WHERE d.EVT_ID=%d '
782 782
             . 'GROUP BY REG_ID'
@@ -788,7 +788,7 @@  discard block
 block discarded – undo
788 788
             $EVT_ID,
789 789
             $checked_in
790 790
         );
791
-        return (int)$wpdb->get_var($query);
791
+        return (int) $wpdb->get_var($query);
792 792
     }
793 793
 
794 794
 
@@ -805,11 +805,11 @@  discard block
 block discarded – undo
805 805
     {
806 806
         //first do a native wp_query to get the latest REG_ID's matching these attendees.
807 807
         global $wpdb;
808
-        $registration_table = $wpdb->prefix . 'esp_registration';
808
+        $registration_table = $wpdb->prefix.'esp_registration';
809 809
         $attendee_table = $wpdb->posts;
810 810
         $attendee_ids = is_array($attendee_ids)
811 811
             ? array_map('absint', $attendee_ids)
812
-            : array((int)$attendee_ids);
812
+            : array((int) $attendee_ids);
813 813
         $ATT_IDs = implode(',', $attendee_ids);
814 814
         // first we do a query to get the registration ids
815 815
         // (because a group by before order by causes the order by to be ignored.)
@@ -857,10 +857,10 @@  discard block
 block discarded – undo
857 857
      * @throws InvalidStatusException
858 858
      * @throws EE_Error
859 859
      */
860
-    public function event_reg_count_for_statuses($EVT_ID, $statuses = array() )
860
+    public function event_reg_count_for_statuses($EVT_ID, $statuses = array())
861 861
     {
862 862
         $EVT_ID = absint($EVT_ID);
863
-        if (! $EVT_ID) {
863
+        if ( ! $EVT_ID) {
864 864
             throw new InvalidArgumentException(
865 865
                 esc_html__('An invalid Event ID was supplied.', 'event_espresso')
866 866
             );
@@ -868,7 +868,7 @@  discard block
 block discarded – undo
868 868
         $statuses = ! empty($statuses) ? $statuses : array(EEM_Registration::status_id_approved);
869 869
         $valid_reg_statuses = EEM_Registration::reg_statuses();
870 870
         foreach ($statuses as $status) {
871
-            if(! in_array($status, $valid_reg_statuses, true)) {
871
+            if ( ! in_array($status, $valid_reg_statuses, true)) {
872 872
                 throw new InvalidStatusException($status, esc_html__('Registration', 'event_espresso'));
873 873
             }
874 874
         }
Please login to merge, or discard this patch.
Indentation   +854 added lines, -854 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
 use EventEspresso\core\services\database\TableAnalysis;
5 5
 
6 6
 if (!defined('EVENT_ESPRESSO_VERSION')) {
7
-    exit('No direct script access allowed');
7
+	exit('No direct script access allowed');
8 8
 }
9 9
 
10 10
 
@@ -18,802 +18,802 @@  discard block
 block discarded – undo
18 18
 class EEM_Registration extends EEM_Soft_Delete_Base
19 19
 {
20 20
 
21
-    /**
22
-     * @var EEM_Registration $_instance
23
-     */
24
-    protected static $_instance;
25
-
26
-    /**
27
-     * Keys are the status IDs for registrations (eg, RAP, RCN, etc), and the values
28
-     * are status codes (eg, approved, cancelled, etc)
29
-     *
30
-     * @var array
31
-     */
32
-    private static $_reg_status;
33
-
34
-    /**
35
-     * The value of REG_count for a primary registrant
36
-     */
37
-    const PRIMARY_REGISTRANT_COUNT = 1;
38
-
39
-    /**
40
-     * Status ID (STS_ID on esp_status table) to indicate an INCOMPLETE registration.
41
-     * Initial status for registrations when they are first created
42
-     * Payments are NOT allowed.
43
-     * Automatically toggled to whatever the default Event registration status is upon completion of the attendee
44
-     * information reg step NO space reserved. Registration is NOT active
45
-     */
46
-    const status_id_incomplete = 'RIC';
47
-
48
-    /**
49
-     * Status ID (STS_ID on esp_status table) to indicate an UNAPPROVED registration.
50
-     * Payments are NOT allowed.
51
-     * Event Admin must manually toggle STS_ID for it to change
52
-     * No space reserved.
53
-     * Registration is active
54
-     */
55
-    const status_id_not_approved = 'RNA';
56
-
57
-    /**
58
-     * Status ID (STS_ID on esp_status table) to indicate registration is PENDING_PAYMENT .
59
-     * Payments are allowed.
60
-     * STS_ID will automatically be toggled to RAP if payment is made in full by the attendee
61
-     * No space reserved.
62
-     * Registration is active
63
-     */
64
-    const status_id_pending_payment = 'RPP';
65
-
66
-    /**
67
-     * Status ID (STS_ID on esp_status table) to indicate registration is on the WAIT_LIST .
68
-     * Payments are allowed.
69
-     * STS_ID will automatically be toggled to RAP if payment is made in full by the attendee
70
-     * No space reserved.
71
-     * Registration is active
72
-     */
73
-    const status_id_wait_list = 'RWL';
74
-
75
-    /**
76
-     * Status ID (STS_ID on esp_status table) to indicate an APPROVED registration.
77
-     * the TXN may or may not be completed ( paid in full )
78
-     * Payments are allowed.
79
-     * A space IS reserved.
80
-     * Registration is active
81
-     */
82
-    const status_id_approved = 'RAP';
83
-
84
-    /**
85
-     * Status ID (STS_ID on esp_status table) to indicate a registration was CANCELLED by the attendee.
86
-     * Payments are NOT allowed.
87
-     * NO space reserved.
88
-     * Registration is NOT active
89
-     */
90
-    const status_id_cancelled = 'RCN';
91
-
92
-    /**
93
-     * Status ID (STS_ID on esp_status table) to indicate a registration was DECLINED by the Event Admin
94
-     * Payments are NOT allowed.
95
-     * No space reserved.
96
-     * Registration is NOT active
97
-     */
98
-    const status_id_declined = 'RDC';
99
-
100
-    /**
101
-     * @var TableAnalysis $table_analysis
102
-     */
103
-    protected $_table_analysis;
104
-
105
-
106
-    /**
107
-     *    private constructor to prevent direct creation
108
-     *
109
-     * @Constructor
110
-     * @access protected
111
-     * @param string $timezone string representing the timezone we want to set for returned Date Time Strings (and any
112
-     *                         incoming timezone data that gets saved). Note this just sends the timezone info to the
113
-     *                         date time model field objects.  Default is NULL (and will be assumed using the set
114
-     *                         timezone in the 'timezone_string' wp option)
115
-     * @throws EE_Error
116
-     */
117
-    protected function __construct($timezone = null)
118
-    {
119
-        $this->_table_analysis = EE_Registry::instance()->create('TableAnalysis', array(), true);
120
-        $this->singular_item = esc_html__('Registration', 'event_espresso');
121
-        $this->plural_item = esc_html__('Registrations', 'event_espresso');
122
-        $this->_tables = array(
123
-            'Registration' => new EE_Primary_Table('esp_registration', 'REG_ID'),
124
-        );
125
-        $this->_fields = array(
126
-            'Registration' => array(
127
-                'REG_ID' => new EE_Primary_Key_Int_Field(
128
-                    'REG_ID',
129
-                    esc_html__('Registration ID', 'event_espresso')
130
-                ),
131
-                'EVT_ID' => new EE_Foreign_Key_Int_Field(
132
-                    'EVT_ID',
133
-                    esc_html__('Event ID', 'event_espresso'),
134
-                    false,
135
-                    0,
136
-                    'Event'
137
-                ),
138
-                'ATT_ID' => new EE_Foreign_Key_Int_Field(
139
-                    'ATT_ID',
140
-                    esc_html__('Attendee ID', 'event_espresso'),
141
-                    false,
142
-                    0,
143
-                    'Attendee'
144
-                ),
145
-                'TXN_ID' => new EE_Foreign_Key_Int_Field(
146
-                    'TXN_ID',
147
-                    esc_html__('Transaction ID', 'event_espresso'),
148
-                    false, 0, 'Transaction'
149
-                ),
150
-                'TKT_ID' => new EE_Foreign_Key_Int_Field(
151
-                    'TKT_ID',
152
-                    esc_html__('Ticket ID', 'event_espresso'),
153
-                    false,
154
-                    0, 'Ticket'
155
-                ),
156
-                'STS_ID' => new EE_Foreign_Key_String_Field(
157
-                    'STS_ID',
158
-                    esc_html__('Status ID', 'event_espresso'),
159
-                    false,
160
-                    EEM_Registration::status_id_incomplete,
161
-                    'Status'
162
-                ),
163
-                'REG_date' => new EE_Datetime_Field(
164
-                    'REG_date',
165
-                    esc_html__('Time registration occurred', 'event_espresso'),
166
-                    false,
167
-                    EE_Datetime_Field::now,
168
-                    $timezone
169
-                ),
170
-                'REG_final_price' => new EE_Money_Field(
171
-                    'REG_final_price',
172
-                    esc_html__('Registration\'s share of the transaction total', 'event_espresso'),
173
-                    false,
174
-                    0
175
-                ),
176
-                'REG_paid' => new EE_Money_Field(
177
-                    'REG_paid',
178
-                    esc_html__('Amount paid to date towards registration', 'event_espresso'),
179
-                    false,
180
-                    0
181
-                ),
182
-                'REG_session' => new EE_Plain_Text_Field(
183
-                    'REG_session',
184
-                    esc_html__('Session ID of registration', 'event_espresso'),
185
-                    false,
186
-                    ''
187
-                ),
188
-                'REG_code' => new EE_Plain_Text_Field(
189
-                    'REG_code',
190
-                    esc_html__('Unique Code for this registration', 'event_espresso'),
191
-                    false,
192
-                    ''
193
-                ),
194
-                'REG_url_link' => new EE_Plain_Text_Field(
195
-                    'REG_url_link',
196
-                    esc_html__('String to be used in URL for identifying registration', 'event_espresso'),
197
-                    false,
198
-                    ''
199
-                ),
200
-                'REG_count' => new EE_Integer_Field(
201
-                    'REG_count',
202
-                    esc_html__('Count of this registration in the group registration ', 'event_espresso'),
203
-                    true,
204
-                    1
205
-                ),
206
-                'REG_group_size' => new EE_Integer_Field(
207
-                    'REG_group_size',
208
-                    esc_html__('Number of registrations on this group', 'event_espresso'),
209
-                    false,
210
-                    1
211
-                ),
212
-                'REG_att_is_going' => new EE_Boolean_Field(
213
-                    'REG_att_is_going',
214
-                    esc_html__('Flag indicating the registrant plans on attending', 'event_espresso'),
215
-                    false,
216
-                    false
217
-                ),
218
-                'REG_deleted' => new EE_Trashed_Flag_Field(
219
-                    'REG_deleted',
220
-                    esc_html__('Flag indicating if registration has been archived or not.', 'event_espresso'),
221
-                    false,
222
-                    false
223
-                ),
224
-            ),
225
-        );
226
-        $this->_model_relations = array(
227
-            'Event' => new EE_Belongs_To_Relation(),
228
-            'Attendee' => new EE_Belongs_To_Relation(),
229
-            'Transaction' => new EE_Belongs_To_Relation(),
230
-            'Ticket' => new EE_Belongs_To_Relation(),
231
-            'Status' => new EE_Belongs_To_Relation(),
232
-            'Answer' => new EE_Has_Many_Relation(),
233
-            'Checkin' => new EE_Has_Many_Relation(),
234
-            'Registration_Payment' => new EE_Has_Many_Relation(),
235
-            'Payment' => new EE_HABTM_Relation('Registration_Payment'),
236
-            'Message' => new EE_Has_Many_Any_Relation(false)
237
-            //allow deletes even if there are messages in the queue related
238
-        );
239
-        $this->_model_chain_to_wp_user = 'Event';
240
-        parent::__construct($timezone);
241
-    }
242
-
243
-
244
-    /**
245
-     * a list of ALL valid registration statuses currently in use within the system
246
-     * generated by combining the filterable active and inactive reg status arrays
247
-     *
248
-     * @return array
249
-     */
250
-    public static function reg_statuses()
251
-    {
252
-        return array_unique(
253
-            array_merge(
254
-                EEM_Registration::active_reg_statuses(),
255
-                EEM_Registration::inactive_reg_statuses()
256
-            )
257
-        );
258
-    }
259
-
260
-
261
-    /**
262
-     * reg_statuses_that_allow_payment
263
-     * a filterable list of registration statuses that allow a registrant to make a payment
264
-     *
265
-     * @access public
266
-     * @return array
267
-     */
268
-    public static function reg_statuses_that_allow_payment()
269
-    {
270
-        return apply_filters(
271
-            'FHEE__EEM_Registration__reg_statuses_that_allow_payment',
272
-            array(
273
-                EEM_Registration::status_id_approved,
274
-                EEM_Registration::status_id_pending_payment,
275
-            )
276
-        );
277
-    }
278
-
279
-
280
-    /**
281
-     * active_reg_statuses
282
-     * a filterable list of registration statuses that are considered active
283
-     *
284
-     * @access public
285
-     * @return array
286
-     */
287
-    public static function active_reg_statuses()
288
-    {
289
-        return apply_filters(
290
-            'FHEE__EEM_Registration__active_reg_statuses',
291
-            array(
292
-                EEM_Registration::status_id_approved,
293
-                EEM_Registration::status_id_pending_payment,
294
-                EEM_Registration::status_id_wait_list,
295
-                EEM_Registration::status_id_not_approved,
296
-            )
297
-        );
298
-    }
299
-
300
-
301
-    /**
302
-     * inactive_reg_statuses
303
-     * a filterable list of registration statuses that are not considered active
304
-     *
305
-     * @access public
306
-     * @return array
307
-     */
308
-    public static function inactive_reg_statuses()
309
-    {
310
-        return apply_filters(
311
-            'FHEE__EEM_Registration__inactive_reg_statuses',
312
-            array(
313
-                EEM_Registration::status_id_incomplete,
314
-                EEM_Registration::status_id_cancelled,
315
-                EEM_Registration::status_id_declined,
316
-            )
317
-        );
318
-    }
319
-
320
-
321
-    /**
322
-     *    closed_reg_statuses
323
-     *    a filterable list of registration statuses that are considered "closed"
324
-     * meaning they should not be considered in any calculations involving monies owing
325
-     *
326
-     * @access public
327
-     * @return array
328
-     */
329
-    public static function closed_reg_statuses()
330
-    {
331
-        return apply_filters(
332
-            'FHEE__EEM_Registration__closed_reg_statuses',
333
-            array(
334
-                EEM_Registration::status_id_cancelled,
335
-                EEM_Registration::status_id_declined,
336
-                EEM_Registration::status_id_wait_list,
337
-            )
338
-        );
339
-    }
340
-
341
-
342
-    /**
343
-     *        get list of registration statuses
344
-     *
345
-     * @access public
346
-     * @param array $exclude The status ids to exclude from the returned results
347
-     * @param bool $translated If true will return the values as singular localized strings
348
-     * @return array
349
-     * @throws EE_Error
350
-     */
351
-    public static function reg_status_array($exclude = array(), $translated = false)
352
-    {
353
-        EEM_Registration::instance()->_get_registration_status_array($exclude);
354
-        return $translated
355
-            ? EEM_Status::instance()->localized_status(self::$_reg_status, false, 'sentence')
356
-            : self::$_reg_status;
357
-    }
358
-
359
-
360
-    /**
361
-     *    get list of registration statuses
362
-     *
363
-     * @access private
364
-     * @param array $exclude
365
-     * @return void
366
-     * @throws EE_Error
367
-     */
368
-    private function _get_registration_status_array($exclude = array())
369
-    {
370
-        //in the very rare circumstance that we are deleting a model's table's data
371
-        //and the table hasn't actually been created, this could have an error
372
-        /** @type WPDB $wpdb */
373
-        global $wpdb;
374
-        if ($this->_get_table_analysis()->tableExists($wpdb->prefix . 'esp_status')) {
375
-            $results = $wpdb->get_results(
376
-                "SELECT STS_ID, STS_code FROM {$wpdb->prefix}esp_status WHERE STS_type = 'registration'"
377
-            );
378
-            self::$_reg_status = array();
379
-            foreach ($results as $status) {
380
-                if (!in_array($status->STS_ID, $exclude, true)) {
381
-                    self::$_reg_status[$status->STS_ID] = $status->STS_code;
382
-                }
383
-            }
384
-        }
385
-    }
386
-
387
-
388
-    /**
389
-     * Gets the injected table analyzer, or throws an exception
390
-     *
391
-     * @return TableAnalysis
392
-     * @throws EE_Error
393
-     */
394
-    protected function _get_table_analysis()
395
-    {
396
-        if ($this->_table_analysis instanceof TableAnalysis) {
397
-            return $this->_table_analysis;
398
-        }
399
-        throw new EE_Error(
400
-            sprintf(
401
-                esc_html__('Table analysis class on class %1$s is not set properly.', 'event_espresso'),
402
-                get_class($this)
403
-            )
404
-        );
405
-    }
406
-
407
-
408
-    /**
409
-     * This returns a wpdb->results array of all registration date month and years matching the incoming query params
410
-     * and grouped by month and year.
411
-     *
412
-     * @param  array $where_params Array of query_params as described in the comments for EEM_Base::get_all()
413
-     * @return array
414
-     * @throws EE_Error
415
-     */
416
-    public function get_reg_months_and_years($where_params)
417
-    {
418
-        $query_params[0] = $where_params;
419
-        $query_params['group_by'] = array('reg_year', 'reg_month');
420
-        $query_params['order_by'] = array('REG_date' => 'DESC');
421
-        $columns_to_select = array(
422
-            'reg_year' => array('YEAR(REG_date)', '%s'),
423
-            'reg_month' => array('MONTHNAME(REG_date)', '%s'),
424
-        );
425
-        return $this->_get_all_wpdb_results($query_params, OBJECT, $columns_to_select);
426
-    }
427
-
428
-
429
-    /**
430
-     * retrieve ALL registrations for a particular Attendee from db
431
-     *
432
-     * @param int $ATT_ID
433
-     * @return EE_Base_Class[]|EE_Registration[]|null
434
-     * @throws EE_Error
435
-     */
436
-    public function get_all_registrations_for_attendee($ATT_ID = 0)
437
-    {
438
-        if (!$ATT_ID) {
439
-            return null;
440
-        }
441
-        return $this->get_all(array(array('ATT_ID' => $ATT_ID)));
442
-    }
443
-
444
-
445
-    /**
446
-     * Gets a registration given their REG_url_link. Yes, this should usually
447
-     * be passed via a GET parameter.
448
-     *
449
-     * @param string $REG_url_link
450
-     * @return EE_Base_Class|EE_Registration|null
451
-     * @throws EE_Error
452
-     */
453
-    public function get_registration_for_reg_url_link($REG_url_link)
454
-    {
455
-        if (!$REG_url_link) {
456
-            return null;
457
-        }
458
-        return $this->get_one(array(array('REG_url_link' => $REG_url_link)));
459
-    }
460
-
461
-
462
-    /**
463
-     *        retrieve registration for a specific transaction attendee from db
464
-     *
465
-     * @access        public
466
-     * @param    int $TXN_ID
467
-     * @param    int $ATT_ID
468
-     * @param    int $att_nmbr in case the ATT_ID is the same for multiple registrations (same details used) then the
469
-     *                         attendee number is required
470
-     * @return        mixed        array on success, FALSE on fail
471
-     * @throws EE_Error
472
-     */
473
-    public function get_registration_for_transaction_attendee($TXN_ID = 0, $ATT_ID = 0, $att_nmbr = 0)
474
-    {
475
-        return $this->get_one(array(
476
-            array(
477
-                'TXN_ID' => $TXN_ID,
478
-                'ATT_ID' => $ATT_ID,
479
-            ),
480
-            'limit' => array(min($att_nmbr - 1, 0), 1),
481
-        ));
482
-    }
483
-
484
-
485
-    /**
486
-     *        get the number of registrations per day  for the Registration Admin page Reports Tab.
487
-     *        (doesn't utilize models because it's a fairly specialized query)
488
-     *
489
-     * @access        public
490
-     * @param $period string which can be passed to php's strtotime function (eg "-1 month")
491
-     * @return stdClass[] with properties regDate and total
492
-     * @throws EE_Error
493
-     */
494
-    public function get_registrations_per_day_report($period = '-1 month')
495
-    {
496
-        $sql_date = $this->convert_datetime_for_query('REG_date', date('Y-m-d H:i:s', strtotime($period)),
497
-            'Y-m-d H:i:s', 'UTC');
498
-        $where = array(
499
-            'REG_date' => array('>=', $sql_date),
500
-            'STS_ID' => array('!=', EEM_Registration::status_id_incomplete),
501
-        );
502
-        if (!EE_Registry::instance()->CAP->current_user_can('ee_read_others_registrations', 'reg_per_day_report')) {
503
-            $where['Event.EVT_wp_user'] = get_current_user_id();
504
-        }
505
-        $query_interval = EEH_DTT_Helper::get_sql_query_interval_for_offset($this->get_timezone(), 'REG_date');
506
-        $results = $this->_get_all_wpdb_results(
507
-            array(
508
-                $where,
509
-                'group_by' => 'regDate',
510
-                'order_by' => array('REG_date' => 'ASC'),
511
-            ),
512
-            OBJECT,
513
-            array(
514
-                'regDate' => array('DATE(' . $query_interval . ')', '%s'),
515
-                'total' => array('count(REG_ID)', '%d'),
516
-            ));
517
-        return $results;
518
-    }
519
-
520
-
521
-    /**
522
-     * Get the number of registrations per day including the count of registrations for each Registration Status.
523
-     * Note: EEM_Registration::status_id_incomplete registrations are excluded from the results.
524
-     *
525
-     * @param string $period
526
-     * @return stdClass[] with properties Registration_REG_date and a column for each registration status as the STS_ID
527
-     * @throws EE_Error
528
-     *                    (i.e. RAP)
529
-     */
530
-    public function get_registrations_per_day_and_per_status_report($period = '-1 month')
531
-    {
532
-        global $wpdb;
533
-        $registration_table = $wpdb->prefix . 'esp_registration';
534
-        $event_table = $wpdb->posts;
535
-        $sql_date = date('Y-m-d H:i:s', strtotime($period));
536
-        //prepare the query interval for displaying offset
537
-        $query_interval = EEH_DTT_Helper::get_sql_query_interval_for_offset($this->get_timezone(), 'dates.REG_date');
538
-        //inner date query
539
-        $inner_date_query = "SELECT DISTINCT REG_date from {$registration_table} ";
540
-        $inner_where = ' WHERE';
541
-        //exclude events not authored by user if permissions in effect
542
-        if (!EE_Registry::instance()->CAP->current_user_can('ee_read_others_registrations', 'reg_per_event_report')) {
543
-            $inner_date_query .= "LEFT JOIN {$event_table} ON ID = EVT_ID";
544
-            $inner_where .= ' post_author = ' . get_current_user_id() . ' AND';
545
-        }
546
-        $inner_where .= " REG_date >= '{$sql_date}'";
547
-        $inner_date_query .= $inner_where;
548
-        //start main query
549
-        $select = "SELECT DATE({$query_interval}) as Registration_REG_date, ";
550
-        $join = '';
551
-        $join_parts = array();
552
-        $select_parts = array();
553
-        //loop through registration stati to do parts for each status.
554
-        foreach (EEM_Registration::reg_status_array() as $STS_ID => $STS_code) {
555
-            if ($STS_ID === EEM_Registration::status_id_incomplete) {
556
-                continue;
557
-            }
558
-            $select_parts[] = "COUNT({$STS_code}.REG_ID) as {$STS_ID}";
559
-            $join_parts[] = "{$registration_table} AS {$STS_code} ON {$STS_code}.REG_date = dates.REG_date AND {$STS_code}.STS_ID = '{$STS_ID}'";
560
-        }
561
-        //setup the selects
562
-        $select .= implode(', ', $select_parts);
563
-        $select .= " FROM ($inner_date_query) AS dates LEFT JOIN ";
564
-        //setup the joins
565
-        $join .= implode(' LEFT JOIN ', $join_parts);
566
-        //now let's put it all together
567
-        $query = $select . $join . ' GROUP BY Registration_REG_date';
568
-        //and execute it
569
-        return $wpdb->get_results($query, ARRAY_A);
570
-    }
571
-
572
-
573
-    /**
574
-     *        get the number of registrations per event  for the Registration Admin page Reports Tab
575
-     *
576
-     * @access        public
577
-     * @param $period string which can be passed to php's strtotime function (eg "-1 month")
578
-     * @return stdClass[] each with properties event_name, reg_limit, and total
579
-     * @throws EE_Error
580
-     */
581
-    public function get_registrations_per_event_report($period = '-1 month')
582
-    {
583
-        $date_sql = $this->convert_datetime_for_query('REG_date', date('Y-m-d H:i:s', strtotime($period)),
584
-            'Y-m-d H:i:s', 'UTC');
585
-        $where = array(
586
-            'REG_date' => array('>=', $date_sql),
587
-            'STS_ID' => array('!=', EEM_Registration::status_id_incomplete),
588
-        );
589
-        if (
590
-        !EE_Registry::instance()->CAP->current_user_can(
591
-            'ee_read_others_registrations',
592
-            'reg_per_event_report'
593
-        )
594
-        ) {
595
-            $where['Event.EVT_wp_user'] = get_current_user_id();
596
-        }
597
-        $results = $this->_get_all_wpdb_results(array(
598
-            $where,
599
-            'group_by' => 'Event.EVT_name',
600
-            'order_by' => 'Event.EVT_name',
601
-            'limit' => array(0, 24),
602
-        ),
603
-            OBJECT,
604
-            array(
605
-                'event_name' => array('Event_CPT.post_title', '%s'),
606
-                'total' => array('COUNT(REG_ID)', '%s'),
607
-            )
608
-        );
609
-        return $results;
610
-    }
611
-
612
-
613
-    /**
614
-     * Get the number of registrations per event grouped by registration status.
615
-     * Note: EEM_Registration::status_id_incomplete registrations are excluded from the results.
616
-     *
617
-     * @param string $period
618
-     * @return stdClass[] with properties `Registration_Event` and a column for each registration status as the STS_ID
619
-     * @throws EE_Error
620
-     *                    (i.e. RAP)
621
-     */
622
-    public function get_registrations_per_event_and_per_status_report($period = '-1 month')
623
-    {
624
-        global $wpdb;
625
-        $registration_table = $wpdb->prefix . 'esp_registration';
626
-        $event_table = $wpdb->posts;
627
-        $sql_date = date('Y-m-d H:i:s', strtotime($period));
628
-        //inner date query
629
-        $inner_date_query = "SELECT DISTINCT EVT_ID, REG_date from $registration_table ";
630
-        $inner_where = ' WHERE';
631
-        //exclude events not authored by user if permissions in effect
632
-        if (!EE_Registry::instance()->CAP->current_user_can('ee_read_others_registrations', 'reg_per_event_report')) {
633
-            $inner_date_query .= "LEFT JOIN {$event_table} ON ID = EVT_ID";
634
-            $inner_where .= ' post_author = ' . get_current_user_id() . ' AND';
635
-        }
636
-        $inner_where .= " REG_date >= '{$sql_date}'";
637
-        $inner_date_query .= $inner_where;
638
-        //build main query
639
-        $select = 'SELECT Event.post_title as Registration_Event, ';
640
-        $join = '';
641
-        $join_parts = array();
642
-        $select_parts = array();
643
-        //loop through registration stati to do parts for each status.
644
-        foreach (EEM_Registration::reg_status_array() as $STS_ID => $STS_code) {
645
-            if ($STS_ID === EEM_Registration::status_id_incomplete) {
646
-                continue;
647
-            }
648
-            $select_parts[] = "COUNT({$STS_code}.REG_ID) as {$STS_ID}";
649
-            $join_parts[] = "{$registration_table} AS {$STS_code} ON {$STS_code}.EVT_ID = dates.EVT_ID AND {$STS_code}.STS_ID = '{$STS_ID}' AND {$STS_code}.REG_date = dates.REG_date";
650
-        }
651
-        //setup the selects
652
-        $select .= implode(', ', $select_parts);
653
-        $select .= " FROM ($inner_date_query) AS dates LEFT JOIN $event_table as Event ON Event.ID = dates.EVT_ID LEFT JOIN ";
654
-        //setup remaining joins
655
-        $join .= implode(' LEFT JOIN ', $join_parts);
656
-        //now put it all together
657
-        $query = $select . $join . ' GROUP BY Registration_Event';
658
-        //and execute
659
-        return $wpdb->get_results($query, ARRAY_A);
660
-    }
661
-
662
-
663
-    /**
664
-     * Returns the EE_Registration of the primary attendee on the transaction id provided
665
-     *
666
-     * @param int $TXN_ID
667
-     * @return EE_Base_Class|EE_Registration|null
668
-     * @throws EE_Error
669
-     */
670
-    public function get_primary_registration_for_transaction_ID($TXN_ID = 0)
671
-    {
672
-        if (!$TXN_ID) {
673
-            return null;
674
-        }
675
-        return $this->get_one(array(
676
-            array(
677
-                'TXN_ID' => $TXN_ID,
678
-                'REG_count' => EEM_Registration::PRIMARY_REGISTRANT_COUNT,
679
-            ),
680
-        ));
681
-    }
682
-
683
-
684
-    /**
685
-     *        get_event_registration_count
686
-     *
687
-     * @access public
688
-     * @param int $EVT_ID
689
-     * @param boolean $for_incomplete_payments
690
-     * @return int
691
-     * @throws EE_Error
692
-     */
693
-    public function get_event_registration_count($EVT_ID, $for_incomplete_payments = false)
694
-    {
695
-        // we only count approved registrations towards registration limits
696
-        $query_params = array(array('EVT_ID' => $EVT_ID, 'STS_ID' => self::status_id_approved));
697
-        if ($for_incomplete_payments) {
698
-            $query_params[0]['Transaction.STS_ID'] = array('!=', EEM_Transaction::complete_status_code);
699
-        }
700
-        return $this->count($query_params);
701
-    }
702
-
703
-
704
-    /**
705
-     * Deletes all registrations with no transactions. Note that this needs to be very efficient
706
-     * and so it uses wpdb directly
707
-     *
708
-     * @global WPDB $wpdb
709
-     * @return int number deleted
710
-     * @throws EE_Error
711
-     */
712
-    public function delete_registrations_with_no_transaction()
713
-    {
714
-        /** @type WPDB $wpdb */
715
-        global $wpdb;
716
-        return $wpdb->query(
717
-            'DELETE r FROM '
718
-            . $this->table()
719
-            . ' r LEFT JOIN '
720
-            . EEM_Transaction::instance()->table()
721
-            . ' t ON r.TXN_ID = t.TXN_ID WHERE t.TXN_ID IS NULL');
722
-    }
723
-
724
-
725
-    /**
726
-     *  Count registrations checked into (or out of) a datetime
727
-     *
728
-     * @param int $DTT_ID datetime ID
729
-     * @param boolean $checked_in whether to count registrations checked IN or OUT
730
-     * @return int
731
-     * @throws EE_Error
732
-     */
733
-    public function count_registrations_checked_into_datetime($DTT_ID, $checked_in = true)
734
-    {
735
-        global $wpdb;
736
-        //subquery to get latest checkin
737
-        $query = $wpdb->prepare(
738
-            'SELECT '
739
-            . 'COUNT( DISTINCT checkins.REG_ID ) '
740
-            . 'FROM ' . EEM_Checkin::instance()->table() . ' AS checkins INNER JOIN'
741
-            . '( SELECT '
742
-            . 'max( CHK_timestamp ) AS latest_checkin, '
743
-            . 'REG_ID AS REG_ID '
744
-            . 'FROM ' . EEM_Checkin::instance()->table() . ' '
745
-            . 'WHERE DTT_ID=%d '
746
-            . 'GROUP BY REG_ID'
747
-            . ') AS most_recent_checkin_per_reg '
748
-            . 'ON checkins.REG_ID=most_recent_checkin_per_reg.REG_ID '
749
-            . 'AND checkins.CHK_timestamp = most_recent_checkin_per_reg.latest_checkin '
750
-            . 'WHERE '
751
-            . 'checkins.CHK_in=%d',
752
-            $DTT_ID,
753
-            $checked_in
754
-        );
755
-        return (int)$wpdb->get_var($query);
756
-    }
757
-
758
-
759
-    /**
760
-     *  Count registrations checked into (or out of) an event.
761
-     *
762
-     * @param int $EVT_ID event ID
763
-     * @param boolean $checked_in whether to count registrations checked IN or OUT
764
-     * @return int
765
-     * @throws EE_Error
766
-     */
767
-    public function count_registrations_checked_into_event($EVT_ID, $checked_in = true)
768
-    {
769
-        global $wpdb;
770
-        //subquery to get latest checkin
771
-        $query = $wpdb->prepare(
772
-            'SELECT '
773
-            . 'COUNT( DISTINCT checkins.REG_ID ) '
774
-            . 'FROM ' . EEM_Checkin::instance()->table() . ' AS checkins INNER JOIN'
775
-            . '( SELECT '
776
-            . 'max( CHK_timestamp ) AS latest_checkin, '
777
-            . 'REG_ID AS REG_ID '
778
-            . 'FROM ' . EEM_Checkin::instance()->table() . ' AS c '
779
-            . 'INNER JOIN ' . EEM_Datetime::instance()->table() . ' AS d '
780
-            . 'ON c.DTT_ID=d.DTT_ID '
781
-            . 'WHERE d.EVT_ID=%d '
782
-            . 'GROUP BY REG_ID'
783
-            . ') AS most_recent_checkin_per_reg '
784
-            . 'ON checkins.REG_ID=most_recent_checkin_per_reg.REG_ID '
785
-            . 'AND checkins.CHK_timestamp = most_recent_checkin_per_reg.latest_checkin '
786
-            . 'WHERE '
787
-            . 'checkins.CHK_in=%d',
788
-            $EVT_ID,
789
-            $checked_in
790
-        );
791
-        return (int)$wpdb->get_var($query);
792
-    }
793
-
794
-
795
-    /**
796
-     * The purpose of this method is to retrieve an array of
797
-     * EE_Registration objects that represent the latest registration
798
-     * for each ATT_ID given in the function argument.
799
-     *
800
-     * @param array $attendee_ids
801
-     * @return EE_Base_Class[]|EE_Registration[]
802
-     * @throws EE_Error
803
-     */
804
-    public function get_latest_registration_for_each_of_given_contacts($attendee_ids = array())
805
-    {
806
-        //first do a native wp_query to get the latest REG_ID's matching these attendees.
807
-        global $wpdb;
808
-        $registration_table = $wpdb->prefix . 'esp_registration';
809
-        $attendee_table = $wpdb->posts;
810
-        $attendee_ids = is_array($attendee_ids)
811
-            ? array_map('absint', $attendee_ids)
812
-            : array((int)$attendee_ids);
813
-        $ATT_IDs = implode(',', $attendee_ids);
814
-        // first we do a query to get the registration ids
815
-        // (because a group by before order by causes the order by to be ignored.)
816
-        $registration_id_query = "
21
+	/**
22
+	 * @var EEM_Registration $_instance
23
+	 */
24
+	protected static $_instance;
25
+
26
+	/**
27
+	 * Keys are the status IDs for registrations (eg, RAP, RCN, etc), and the values
28
+	 * are status codes (eg, approved, cancelled, etc)
29
+	 *
30
+	 * @var array
31
+	 */
32
+	private static $_reg_status;
33
+
34
+	/**
35
+	 * The value of REG_count for a primary registrant
36
+	 */
37
+	const PRIMARY_REGISTRANT_COUNT = 1;
38
+
39
+	/**
40
+	 * Status ID (STS_ID on esp_status table) to indicate an INCOMPLETE registration.
41
+	 * Initial status for registrations when they are first created
42
+	 * Payments are NOT allowed.
43
+	 * Automatically toggled to whatever the default Event registration status is upon completion of the attendee
44
+	 * information reg step NO space reserved. Registration is NOT active
45
+	 */
46
+	const status_id_incomplete = 'RIC';
47
+
48
+	/**
49
+	 * Status ID (STS_ID on esp_status table) to indicate an UNAPPROVED registration.
50
+	 * Payments are NOT allowed.
51
+	 * Event Admin must manually toggle STS_ID for it to change
52
+	 * No space reserved.
53
+	 * Registration is active
54
+	 */
55
+	const status_id_not_approved = 'RNA';
56
+
57
+	/**
58
+	 * Status ID (STS_ID on esp_status table) to indicate registration is PENDING_PAYMENT .
59
+	 * Payments are allowed.
60
+	 * STS_ID will automatically be toggled to RAP if payment is made in full by the attendee
61
+	 * No space reserved.
62
+	 * Registration is active
63
+	 */
64
+	const status_id_pending_payment = 'RPP';
65
+
66
+	/**
67
+	 * Status ID (STS_ID on esp_status table) to indicate registration is on the WAIT_LIST .
68
+	 * Payments are allowed.
69
+	 * STS_ID will automatically be toggled to RAP if payment is made in full by the attendee
70
+	 * No space reserved.
71
+	 * Registration is active
72
+	 */
73
+	const status_id_wait_list = 'RWL';
74
+
75
+	/**
76
+	 * Status ID (STS_ID on esp_status table) to indicate an APPROVED registration.
77
+	 * the TXN may or may not be completed ( paid in full )
78
+	 * Payments are allowed.
79
+	 * A space IS reserved.
80
+	 * Registration is active
81
+	 */
82
+	const status_id_approved = 'RAP';
83
+
84
+	/**
85
+	 * Status ID (STS_ID on esp_status table) to indicate a registration was CANCELLED by the attendee.
86
+	 * Payments are NOT allowed.
87
+	 * NO space reserved.
88
+	 * Registration is NOT active
89
+	 */
90
+	const status_id_cancelled = 'RCN';
91
+
92
+	/**
93
+	 * Status ID (STS_ID on esp_status table) to indicate a registration was DECLINED by the Event Admin
94
+	 * Payments are NOT allowed.
95
+	 * No space reserved.
96
+	 * Registration is NOT active
97
+	 */
98
+	const status_id_declined = 'RDC';
99
+
100
+	/**
101
+	 * @var TableAnalysis $table_analysis
102
+	 */
103
+	protected $_table_analysis;
104
+
105
+
106
+	/**
107
+	 *    private constructor to prevent direct creation
108
+	 *
109
+	 * @Constructor
110
+	 * @access protected
111
+	 * @param string $timezone string representing the timezone we want to set for returned Date Time Strings (and any
112
+	 *                         incoming timezone data that gets saved). Note this just sends the timezone info to the
113
+	 *                         date time model field objects.  Default is NULL (and will be assumed using the set
114
+	 *                         timezone in the 'timezone_string' wp option)
115
+	 * @throws EE_Error
116
+	 */
117
+	protected function __construct($timezone = null)
118
+	{
119
+		$this->_table_analysis = EE_Registry::instance()->create('TableAnalysis', array(), true);
120
+		$this->singular_item = esc_html__('Registration', 'event_espresso');
121
+		$this->plural_item = esc_html__('Registrations', 'event_espresso');
122
+		$this->_tables = array(
123
+			'Registration' => new EE_Primary_Table('esp_registration', 'REG_ID'),
124
+		);
125
+		$this->_fields = array(
126
+			'Registration' => array(
127
+				'REG_ID' => new EE_Primary_Key_Int_Field(
128
+					'REG_ID',
129
+					esc_html__('Registration ID', 'event_espresso')
130
+				),
131
+				'EVT_ID' => new EE_Foreign_Key_Int_Field(
132
+					'EVT_ID',
133
+					esc_html__('Event ID', 'event_espresso'),
134
+					false,
135
+					0,
136
+					'Event'
137
+				),
138
+				'ATT_ID' => new EE_Foreign_Key_Int_Field(
139
+					'ATT_ID',
140
+					esc_html__('Attendee ID', 'event_espresso'),
141
+					false,
142
+					0,
143
+					'Attendee'
144
+				),
145
+				'TXN_ID' => new EE_Foreign_Key_Int_Field(
146
+					'TXN_ID',
147
+					esc_html__('Transaction ID', 'event_espresso'),
148
+					false, 0, 'Transaction'
149
+				),
150
+				'TKT_ID' => new EE_Foreign_Key_Int_Field(
151
+					'TKT_ID',
152
+					esc_html__('Ticket ID', 'event_espresso'),
153
+					false,
154
+					0, 'Ticket'
155
+				),
156
+				'STS_ID' => new EE_Foreign_Key_String_Field(
157
+					'STS_ID',
158
+					esc_html__('Status ID', 'event_espresso'),
159
+					false,
160
+					EEM_Registration::status_id_incomplete,
161
+					'Status'
162
+				),
163
+				'REG_date' => new EE_Datetime_Field(
164
+					'REG_date',
165
+					esc_html__('Time registration occurred', 'event_espresso'),
166
+					false,
167
+					EE_Datetime_Field::now,
168
+					$timezone
169
+				),
170
+				'REG_final_price' => new EE_Money_Field(
171
+					'REG_final_price',
172
+					esc_html__('Registration\'s share of the transaction total', 'event_espresso'),
173
+					false,
174
+					0
175
+				),
176
+				'REG_paid' => new EE_Money_Field(
177
+					'REG_paid',
178
+					esc_html__('Amount paid to date towards registration', 'event_espresso'),
179
+					false,
180
+					0
181
+				),
182
+				'REG_session' => new EE_Plain_Text_Field(
183
+					'REG_session',
184
+					esc_html__('Session ID of registration', 'event_espresso'),
185
+					false,
186
+					''
187
+				),
188
+				'REG_code' => new EE_Plain_Text_Field(
189
+					'REG_code',
190
+					esc_html__('Unique Code for this registration', 'event_espresso'),
191
+					false,
192
+					''
193
+				),
194
+				'REG_url_link' => new EE_Plain_Text_Field(
195
+					'REG_url_link',
196
+					esc_html__('String to be used in URL for identifying registration', 'event_espresso'),
197
+					false,
198
+					''
199
+				),
200
+				'REG_count' => new EE_Integer_Field(
201
+					'REG_count',
202
+					esc_html__('Count of this registration in the group registration ', 'event_espresso'),
203
+					true,
204
+					1
205
+				),
206
+				'REG_group_size' => new EE_Integer_Field(
207
+					'REG_group_size',
208
+					esc_html__('Number of registrations on this group', 'event_espresso'),
209
+					false,
210
+					1
211
+				),
212
+				'REG_att_is_going' => new EE_Boolean_Field(
213
+					'REG_att_is_going',
214
+					esc_html__('Flag indicating the registrant plans on attending', 'event_espresso'),
215
+					false,
216
+					false
217
+				),
218
+				'REG_deleted' => new EE_Trashed_Flag_Field(
219
+					'REG_deleted',
220
+					esc_html__('Flag indicating if registration has been archived or not.', 'event_espresso'),
221
+					false,
222
+					false
223
+				),
224
+			),
225
+		);
226
+		$this->_model_relations = array(
227
+			'Event' => new EE_Belongs_To_Relation(),
228
+			'Attendee' => new EE_Belongs_To_Relation(),
229
+			'Transaction' => new EE_Belongs_To_Relation(),
230
+			'Ticket' => new EE_Belongs_To_Relation(),
231
+			'Status' => new EE_Belongs_To_Relation(),
232
+			'Answer' => new EE_Has_Many_Relation(),
233
+			'Checkin' => new EE_Has_Many_Relation(),
234
+			'Registration_Payment' => new EE_Has_Many_Relation(),
235
+			'Payment' => new EE_HABTM_Relation('Registration_Payment'),
236
+			'Message' => new EE_Has_Many_Any_Relation(false)
237
+			//allow deletes even if there are messages in the queue related
238
+		);
239
+		$this->_model_chain_to_wp_user = 'Event';
240
+		parent::__construct($timezone);
241
+	}
242
+
243
+
244
+	/**
245
+	 * a list of ALL valid registration statuses currently in use within the system
246
+	 * generated by combining the filterable active and inactive reg status arrays
247
+	 *
248
+	 * @return array
249
+	 */
250
+	public static function reg_statuses()
251
+	{
252
+		return array_unique(
253
+			array_merge(
254
+				EEM_Registration::active_reg_statuses(),
255
+				EEM_Registration::inactive_reg_statuses()
256
+			)
257
+		);
258
+	}
259
+
260
+
261
+	/**
262
+	 * reg_statuses_that_allow_payment
263
+	 * a filterable list of registration statuses that allow a registrant to make a payment
264
+	 *
265
+	 * @access public
266
+	 * @return array
267
+	 */
268
+	public static function reg_statuses_that_allow_payment()
269
+	{
270
+		return apply_filters(
271
+			'FHEE__EEM_Registration__reg_statuses_that_allow_payment',
272
+			array(
273
+				EEM_Registration::status_id_approved,
274
+				EEM_Registration::status_id_pending_payment,
275
+			)
276
+		);
277
+	}
278
+
279
+
280
+	/**
281
+	 * active_reg_statuses
282
+	 * a filterable list of registration statuses that are considered active
283
+	 *
284
+	 * @access public
285
+	 * @return array
286
+	 */
287
+	public static function active_reg_statuses()
288
+	{
289
+		return apply_filters(
290
+			'FHEE__EEM_Registration__active_reg_statuses',
291
+			array(
292
+				EEM_Registration::status_id_approved,
293
+				EEM_Registration::status_id_pending_payment,
294
+				EEM_Registration::status_id_wait_list,
295
+				EEM_Registration::status_id_not_approved,
296
+			)
297
+		);
298
+	}
299
+
300
+
301
+	/**
302
+	 * inactive_reg_statuses
303
+	 * a filterable list of registration statuses that are not considered active
304
+	 *
305
+	 * @access public
306
+	 * @return array
307
+	 */
308
+	public static function inactive_reg_statuses()
309
+	{
310
+		return apply_filters(
311
+			'FHEE__EEM_Registration__inactive_reg_statuses',
312
+			array(
313
+				EEM_Registration::status_id_incomplete,
314
+				EEM_Registration::status_id_cancelled,
315
+				EEM_Registration::status_id_declined,
316
+			)
317
+		);
318
+	}
319
+
320
+
321
+	/**
322
+	 *    closed_reg_statuses
323
+	 *    a filterable list of registration statuses that are considered "closed"
324
+	 * meaning they should not be considered in any calculations involving monies owing
325
+	 *
326
+	 * @access public
327
+	 * @return array
328
+	 */
329
+	public static function closed_reg_statuses()
330
+	{
331
+		return apply_filters(
332
+			'FHEE__EEM_Registration__closed_reg_statuses',
333
+			array(
334
+				EEM_Registration::status_id_cancelled,
335
+				EEM_Registration::status_id_declined,
336
+				EEM_Registration::status_id_wait_list,
337
+			)
338
+		);
339
+	}
340
+
341
+
342
+	/**
343
+	 *        get list of registration statuses
344
+	 *
345
+	 * @access public
346
+	 * @param array $exclude The status ids to exclude from the returned results
347
+	 * @param bool $translated If true will return the values as singular localized strings
348
+	 * @return array
349
+	 * @throws EE_Error
350
+	 */
351
+	public static function reg_status_array($exclude = array(), $translated = false)
352
+	{
353
+		EEM_Registration::instance()->_get_registration_status_array($exclude);
354
+		return $translated
355
+			? EEM_Status::instance()->localized_status(self::$_reg_status, false, 'sentence')
356
+			: self::$_reg_status;
357
+	}
358
+
359
+
360
+	/**
361
+	 *    get list of registration statuses
362
+	 *
363
+	 * @access private
364
+	 * @param array $exclude
365
+	 * @return void
366
+	 * @throws EE_Error
367
+	 */
368
+	private function _get_registration_status_array($exclude = array())
369
+	{
370
+		//in the very rare circumstance that we are deleting a model's table's data
371
+		//and the table hasn't actually been created, this could have an error
372
+		/** @type WPDB $wpdb */
373
+		global $wpdb;
374
+		if ($this->_get_table_analysis()->tableExists($wpdb->prefix . 'esp_status')) {
375
+			$results = $wpdb->get_results(
376
+				"SELECT STS_ID, STS_code FROM {$wpdb->prefix}esp_status WHERE STS_type = 'registration'"
377
+			);
378
+			self::$_reg_status = array();
379
+			foreach ($results as $status) {
380
+				if (!in_array($status->STS_ID, $exclude, true)) {
381
+					self::$_reg_status[$status->STS_ID] = $status->STS_code;
382
+				}
383
+			}
384
+		}
385
+	}
386
+
387
+
388
+	/**
389
+	 * Gets the injected table analyzer, or throws an exception
390
+	 *
391
+	 * @return TableAnalysis
392
+	 * @throws EE_Error
393
+	 */
394
+	protected function _get_table_analysis()
395
+	{
396
+		if ($this->_table_analysis instanceof TableAnalysis) {
397
+			return $this->_table_analysis;
398
+		}
399
+		throw new EE_Error(
400
+			sprintf(
401
+				esc_html__('Table analysis class on class %1$s is not set properly.', 'event_espresso'),
402
+				get_class($this)
403
+			)
404
+		);
405
+	}
406
+
407
+
408
+	/**
409
+	 * This returns a wpdb->results array of all registration date month and years matching the incoming query params
410
+	 * and grouped by month and year.
411
+	 *
412
+	 * @param  array $where_params Array of query_params as described in the comments for EEM_Base::get_all()
413
+	 * @return array
414
+	 * @throws EE_Error
415
+	 */
416
+	public function get_reg_months_and_years($where_params)
417
+	{
418
+		$query_params[0] = $where_params;
419
+		$query_params['group_by'] = array('reg_year', 'reg_month');
420
+		$query_params['order_by'] = array('REG_date' => 'DESC');
421
+		$columns_to_select = array(
422
+			'reg_year' => array('YEAR(REG_date)', '%s'),
423
+			'reg_month' => array('MONTHNAME(REG_date)', '%s'),
424
+		);
425
+		return $this->_get_all_wpdb_results($query_params, OBJECT, $columns_to_select);
426
+	}
427
+
428
+
429
+	/**
430
+	 * retrieve ALL registrations for a particular Attendee from db
431
+	 *
432
+	 * @param int $ATT_ID
433
+	 * @return EE_Base_Class[]|EE_Registration[]|null
434
+	 * @throws EE_Error
435
+	 */
436
+	public function get_all_registrations_for_attendee($ATT_ID = 0)
437
+	{
438
+		if (!$ATT_ID) {
439
+			return null;
440
+		}
441
+		return $this->get_all(array(array('ATT_ID' => $ATT_ID)));
442
+	}
443
+
444
+
445
+	/**
446
+	 * Gets a registration given their REG_url_link. Yes, this should usually
447
+	 * be passed via a GET parameter.
448
+	 *
449
+	 * @param string $REG_url_link
450
+	 * @return EE_Base_Class|EE_Registration|null
451
+	 * @throws EE_Error
452
+	 */
453
+	public function get_registration_for_reg_url_link($REG_url_link)
454
+	{
455
+		if (!$REG_url_link) {
456
+			return null;
457
+		}
458
+		return $this->get_one(array(array('REG_url_link' => $REG_url_link)));
459
+	}
460
+
461
+
462
+	/**
463
+	 *        retrieve registration for a specific transaction attendee from db
464
+	 *
465
+	 * @access        public
466
+	 * @param    int $TXN_ID
467
+	 * @param    int $ATT_ID
468
+	 * @param    int $att_nmbr in case the ATT_ID is the same for multiple registrations (same details used) then the
469
+	 *                         attendee number is required
470
+	 * @return        mixed        array on success, FALSE on fail
471
+	 * @throws EE_Error
472
+	 */
473
+	public function get_registration_for_transaction_attendee($TXN_ID = 0, $ATT_ID = 0, $att_nmbr = 0)
474
+	{
475
+		return $this->get_one(array(
476
+			array(
477
+				'TXN_ID' => $TXN_ID,
478
+				'ATT_ID' => $ATT_ID,
479
+			),
480
+			'limit' => array(min($att_nmbr - 1, 0), 1),
481
+		));
482
+	}
483
+
484
+
485
+	/**
486
+	 *        get the number of registrations per day  for the Registration Admin page Reports Tab.
487
+	 *        (doesn't utilize models because it's a fairly specialized query)
488
+	 *
489
+	 * @access        public
490
+	 * @param $period string which can be passed to php's strtotime function (eg "-1 month")
491
+	 * @return stdClass[] with properties regDate and total
492
+	 * @throws EE_Error
493
+	 */
494
+	public function get_registrations_per_day_report($period = '-1 month')
495
+	{
496
+		$sql_date = $this->convert_datetime_for_query('REG_date', date('Y-m-d H:i:s', strtotime($period)),
497
+			'Y-m-d H:i:s', 'UTC');
498
+		$where = array(
499
+			'REG_date' => array('>=', $sql_date),
500
+			'STS_ID' => array('!=', EEM_Registration::status_id_incomplete),
501
+		);
502
+		if (!EE_Registry::instance()->CAP->current_user_can('ee_read_others_registrations', 'reg_per_day_report')) {
503
+			$where['Event.EVT_wp_user'] = get_current_user_id();
504
+		}
505
+		$query_interval = EEH_DTT_Helper::get_sql_query_interval_for_offset($this->get_timezone(), 'REG_date');
506
+		$results = $this->_get_all_wpdb_results(
507
+			array(
508
+				$where,
509
+				'group_by' => 'regDate',
510
+				'order_by' => array('REG_date' => 'ASC'),
511
+			),
512
+			OBJECT,
513
+			array(
514
+				'regDate' => array('DATE(' . $query_interval . ')', '%s'),
515
+				'total' => array('count(REG_ID)', '%d'),
516
+			));
517
+		return $results;
518
+	}
519
+
520
+
521
+	/**
522
+	 * Get the number of registrations per day including the count of registrations for each Registration Status.
523
+	 * Note: EEM_Registration::status_id_incomplete registrations are excluded from the results.
524
+	 *
525
+	 * @param string $period
526
+	 * @return stdClass[] with properties Registration_REG_date and a column for each registration status as the STS_ID
527
+	 * @throws EE_Error
528
+	 *                    (i.e. RAP)
529
+	 */
530
+	public function get_registrations_per_day_and_per_status_report($period = '-1 month')
531
+	{
532
+		global $wpdb;
533
+		$registration_table = $wpdb->prefix . 'esp_registration';
534
+		$event_table = $wpdb->posts;
535
+		$sql_date = date('Y-m-d H:i:s', strtotime($period));
536
+		//prepare the query interval for displaying offset
537
+		$query_interval = EEH_DTT_Helper::get_sql_query_interval_for_offset($this->get_timezone(), 'dates.REG_date');
538
+		//inner date query
539
+		$inner_date_query = "SELECT DISTINCT REG_date from {$registration_table} ";
540
+		$inner_where = ' WHERE';
541
+		//exclude events not authored by user if permissions in effect
542
+		if (!EE_Registry::instance()->CAP->current_user_can('ee_read_others_registrations', 'reg_per_event_report')) {
543
+			$inner_date_query .= "LEFT JOIN {$event_table} ON ID = EVT_ID";
544
+			$inner_where .= ' post_author = ' . get_current_user_id() . ' AND';
545
+		}
546
+		$inner_where .= " REG_date >= '{$sql_date}'";
547
+		$inner_date_query .= $inner_where;
548
+		//start main query
549
+		$select = "SELECT DATE({$query_interval}) as Registration_REG_date, ";
550
+		$join = '';
551
+		$join_parts = array();
552
+		$select_parts = array();
553
+		//loop through registration stati to do parts for each status.
554
+		foreach (EEM_Registration::reg_status_array() as $STS_ID => $STS_code) {
555
+			if ($STS_ID === EEM_Registration::status_id_incomplete) {
556
+				continue;
557
+			}
558
+			$select_parts[] = "COUNT({$STS_code}.REG_ID) as {$STS_ID}";
559
+			$join_parts[] = "{$registration_table} AS {$STS_code} ON {$STS_code}.REG_date = dates.REG_date AND {$STS_code}.STS_ID = '{$STS_ID}'";
560
+		}
561
+		//setup the selects
562
+		$select .= implode(', ', $select_parts);
563
+		$select .= " FROM ($inner_date_query) AS dates LEFT JOIN ";
564
+		//setup the joins
565
+		$join .= implode(' LEFT JOIN ', $join_parts);
566
+		//now let's put it all together
567
+		$query = $select . $join . ' GROUP BY Registration_REG_date';
568
+		//and execute it
569
+		return $wpdb->get_results($query, ARRAY_A);
570
+	}
571
+
572
+
573
+	/**
574
+	 *        get the number of registrations per event  for the Registration Admin page Reports Tab
575
+	 *
576
+	 * @access        public
577
+	 * @param $period string which can be passed to php's strtotime function (eg "-1 month")
578
+	 * @return stdClass[] each with properties event_name, reg_limit, and total
579
+	 * @throws EE_Error
580
+	 */
581
+	public function get_registrations_per_event_report($period = '-1 month')
582
+	{
583
+		$date_sql = $this->convert_datetime_for_query('REG_date', date('Y-m-d H:i:s', strtotime($period)),
584
+			'Y-m-d H:i:s', 'UTC');
585
+		$where = array(
586
+			'REG_date' => array('>=', $date_sql),
587
+			'STS_ID' => array('!=', EEM_Registration::status_id_incomplete),
588
+		);
589
+		if (
590
+		!EE_Registry::instance()->CAP->current_user_can(
591
+			'ee_read_others_registrations',
592
+			'reg_per_event_report'
593
+		)
594
+		) {
595
+			$where['Event.EVT_wp_user'] = get_current_user_id();
596
+		}
597
+		$results = $this->_get_all_wpdb_results(array(
598
+			$where,
599
+			'group_by' => 'Event.EVT_name',
600
+			'order_by' => 'Event.EVT_name',
601
+			'limit' => array(0, 24),
602
+		),
603
+			OBJECT,
604
+			array(
605
+				'event_name' => array('Event_CPT.post_title', '%s'),
606
+				'total' => array('COUNT(REG_ID)', '%s'),
607
+			)
608
+		);
609
+		return $results;
610
+	}
611
+
612
+
613
+	/**
614
+	 * Get the number of registrations per event grouped by registration status.
615
+	 * Note: EEM_Registration::status_id_incomplete registrations are excluded from the results.
616
+	 *
617
+	 * @param string $period
618
+	 * @return stdClass[] with properties `Registration_Event` and a column for each registration status as the STS_ID
619
+	 * @throws EE_Error
620
+	 *                    (i.e. RAP)
621
+	 */
622
+	public function get_registrations_per_event_and_per_status_report($period = '-1 month')
623
+	{
624
+		global $wpdb;
625
+		$registration_table = $wpdb->prefix . 'esp_registration';
626
+		$event_table = $wpdb->posts;
627
+		$sql_date = date('Y-m-d H:i:s', strtotime($period));
628
+		//inner date query
629
+		$inner_date_query = "SELECT DISTINCT EVT_ID, REG_date from $registration_table ";
630
+		$inner_where = ' WHERE';
631
+		//exclude events not authored by user if permissions in effect
632
+		if (!EE_Registry::instance()->CAP->current_user_can('ee_read_others_registrations', 'reg_per_event_report')) {
633
+			$inner_date_query .= "LEFT JOIN {$event_table} ON ID = EVT_ID";
634
+			$inner_where .= ' post_author = ' . get_current_user_id() . ' AND';
635
+		}
636
+		$inner_where .= " REG_date >= '{$sql_date}'";
637
+		$inner_date_query .= $inner_where;
638
+		//build main query
639
+		$select = 'SELECT Event.post_title as Registration_Event, ';
640
+		$join = '';
641
+		$join_parts = array();
642
+		$select_parts = array();
643
+		//loop through registration stati to do parts for each status.
644
+		foreach (EEM_Registration::reg_status_array() as $STS_ID => $STS_code) {
645
+			if ($STS_ID === EEM_Registration::status_id_incomplete) {
646
+				continue;
647
+			}
648
+			$select_parts[] = "COUNT({$STS_code}.REG_ID) as {$STS_ID}";
649
+			$join_parts[] = "{$registration_table} AS {$STS_code} ON {$STS_code}.EVT_ID = dates.EVT_ID AND {$STS_code}.STS_ID = '{$STS_ID}' AND {$STS_code}.REG_date = dates.REG_date";
650
+		}
651
+		//setup the selects
652
+		$select .= implode(', ', $select_parts);
653
+		$select .= " FROM ($inner_date_query) AS dates LEFT JOIN $event_table as Event ON Event.ID = dates.EVT_ID LEFT JOIN ";
654
+		//setup remaining joins
655
+		$join .= implode(' LEFT JOIN ', $join_parts);
656
+		//now put it all together
657
+		$query = $select . $join . ' GROUP BY Registration_Event';
658
+		//and execute
659
+		return $wpdb->get_results($query, ARRAY_A);
660
+	}
661
+
662
+
663
+	/**
664
+	 * Returns the EE_Registration of the primary attendee on the transaction id provided
665
+	 *
666
+	 * @param int $TXN_ID
667
+	 * @return EE_Base_Class|EE_Registration|null
668
+	 * @throws EE_Error
669
+	 */
670
+	public function get_primary_registration_for_transaction_ID($TXN_ID = 0)
671
+	{
672
+		if (!$TXN_ID) {
673
+			return null;
674
+		}
675
+		return $this->get_one(array(
676
+			array(
677
+				'TXN_ID' => $TXN_ID,
678
+				'REG_count' => EEM_Registration::PRIMARY_REGISTRANT_COUNT,
679
+			),
680
+		));
681
+	}
682
+
683
+
684
+	/**
685
+	 *        get_event_registration_count
686
+	 *
687
+	 * @access public
688
+	 * @param int $EVT_ID
689
+	 * @param boolean $for_incomplete_payments
690
+	 * @return int
691
+	 * @throws EE_Error
692
+	 */
693
+	public function get_event_registration_count($EVT_ID, $for_incomplete_payments = false)
694
+	{
695
+		// we only count approved registrations towards registration limits
696
+		$query_params = array(array('EVT_ID' => $EVT_ID, 'STS_ID' => self::status_id_approved));
697
+		if ($for_incomplete_payments) {
698
+			$query_params[0]['Transaction.STS_ID'] = array('!=', EEM_Transaction::complete_status_code);
699
+		}
700
+		return $this->count($query_params);
701
+	}
702
+
703
+
704
+	/**
705
+	 * Deletes all registrations with no transactions. Note that this needs to be very efficient
706
+	 * and so it uses wpdb directly
707
+	 *
708
+	 * @global WPDB $wpdb
709
+	 * @return int number deleted
710
+	 * @throws EE_Error
711
+	 */
712
+	public function delete_registrations_with_no_transaction()
713
+	{
714
+		/** @type WPDB $wpdb */
715
+		global $wpdb;
716
+		return $wpdb->query(
717
+			'DELETE r FROM '
718
+			. $this->table()
719
+			. ' r LEFT JOIN '
720
+			. EEM_Transaction::instance()->table()
721
+			. ' t ON r.TXN_ID = t.TXN_ID WHERE t.TXN_ID IS NULL');
722
+	}
723
+
724
+
725
+	/**
726
+	 *  Count registrations checked into (or out of) a datetime
727
+	 *
728
+	 * @param int $DTT_ID datetime ID
729
+	 * @param boolean $checked_in whether to count registrations checked IN or OUT
730
+	 * @return int
731
+	 * @throws EE_Error
732
+	 */
733
+	public function count_registrations_checked_into_datetime($DTT_ID, $checked_in = true)
734
+	{
735
+		global $wpdb;
736
+		//subquery to get latest checkin
737
+		$query = $wpdb->prepare(
738
+			'SELECT '
739
+			. 'COUNT( DISTINCT checkins.REG_ID ) '
740
+			. 'FROM ' . EEM_Checkin::instance()->table() . ' AS checkins INNER JOIN'
741
+			. '( SELECT '
742
+			. 'max( CHK_timestamp ) AS latest_checkin, '
743
+			. 'REG_ID AS REG_ID '
744
+			. 'FROM ' . EEM_Checkin::instance()->table() . ' '
745
+			. 'WHERE DTT_ID=%d '
746
+			. 'GROUP BY REG_ID'
747
+			. ') AS most_recent_checkin_per_reg '
748
+			. 'ON checkins.REG_ID=most_recent_checkin_per_reg.REG_ID '
749
+			. 'AND checkins.CHK_timestamp = most_recent_checkin_per_reg.latest_checkin '
750
+			. 'WHERE '
751
+			. 'checkins.CHK_in=%d',
752
+			$DTT_ID,
753
+			$checked_in
754
+		);
755
+		return (int)$wpdb->get_var($query);
756
+	}
757
+
758
+
759
+	/**
760
+	 *  Count registrations checked into (or out of) an event.
761
+	 *
762
+	 * @param int $EVT_ID event ID
763
+	 * @param boolean $checked_in whether to count registrations checked IN or OUT
764
+	 * @return int
765
+	 * @throws EE_Error
766
+	 */
767
+	public function count_registrations_checked_into_event($EVT_ID, $checked_in = true)
768
+	{
769
+		global $wpdb;
770
+		//subquery to get latest checkin
771
+		$query = $wpdb->prepare(
772
+			'SELECT '
773
+			. 'COUNT( DISTINCT checkins.REG_ID ) '
774
+			. 'FROM ' . EEM_Checkin::instance()->table() . ' AS checkins INNER JOIN'
775
+			. '( SELECT '
776
+			. 'max( CHK_timestamp ) AS latest_checkin, '
777
+			. 'REG_ID AS REG_ID '
778
+			. 'FROM ' . EEM_Checkin::instance()->table() . ' AS c '
779
+			. 'INNER JOIN ' . EEM_Datetime::instance()->table() . ' AS d '
780
+			. 'ON c.DTT_ID=d.DTT_ID '
781
+			. 'WHERE d.EVT_ID=%d '
782
+			. 'GROUP BY REG_ID'
783
+			. ') AS most_recent_checkin_per_reg '
784
+			. 'ON checkins.REG_ID=most_recent_checkin_per_reg.REG_ID '
785
+			. 'AND checkins.CHK_timestamp = most_recent_checkin_per_reg.latest_checkin '
786
+			. 'WHERE '
787
+			. 'checkins.CHK_in=%d',
788
+			$EVT_ID,
789
+			$checked_in
790
+		);
791
+		return (int)$wpdb->get_var($query);
792
+	}
793
+
794
+
795
+	/**
796
+	 * The purpose of this method is to retrieve an array of
797
+	 * EE_Registration objects that represent the latest registration
798
+	 * for each ATT_ID given in the function argument.
799
+	 *
800
+	 * @param array $attendee_ids
801
+	 * @return EE_Base_Class[]|EE_Registration[]
802
+	 * @throws EE_Error
803
+	 */
804
+	public function get_latest_registration_for_each_of_given_contacts($attendee_ids = array())
805
+	{
806
+		//first do a native wp_query to get the latest REG_ID's matching these attendees.
807
+		global $wpdb;
808
+		$registration_table = $wpdb->prefix . 'esp_registration';
809
+		$attendee_table = $wpdb->posts;
810
+		$attendee_ids = is_array($attendee_ids)
811
+			? array_map('absint', $attendee_ids)
812
+			: array((int)$attendee_ids);
813
+		$ATT_IDs = implode(',', $attendee_ids);
814
+		// first we do a query to get the registration ids
815
+		// (because a group by before order by causes the order by to be ignored.)
816
+		$registration_id_query = "
817 817
 			SELECT registrations.registration_ids as registration_id
818 818
 			FROM (
819 819
 				SELECT
@@ -827,63 +827,63 @@  discard block
 block discarded – undo
827 827
 			  ) AS registrations
828 828
 			  GROUP BY registrations.attendee_ids
829 829
 		";
830
-        $registration_ids = $wpdb->get_results($registration_id_query, ARRAY_A);
831
-        if (empty($registration_ids)) {
832
-            return array();
833
-        }
834
-        $ids_for_model_query = array();
835
-        //let's flatten the ids so they can be used in the model query.
836
-        foreach ($registration_ids as $registration_id) {
837
-            if (isset($registration_id['registration_id'])) {
838
-                $ids_for_model_query[] = $registration_id['registration_id'];
839
-            }
840
-        }
841
-        //construct query
842
-        $_where = array(
843
-            'REG_ID' => array('IN', $ids_for_model_query),
844
-        );
845
-        return $this->get_all(array($_where));
846
-    }
847
-
848
-
849
-
850
-    /**
851
-     * returns a count of registrations for the supplied event having the status as specified
852
-     *
853
-     * @param int $EVT_ID
854
-     * @param array $statuses
855
-     * @return int
856
-     * @throws InvalidArgumentException
857
-     * @throws InvalidStatusException
858
-     * @throws EE_Error
859
-     */
860
-    public function event_reg_count_for_statuses($EVT_ID, $statuses = array() )
861
-    {
862
-        $EVT_ID = absint($EVT_ID);
863
-        if (! $EVT_ID) {
864
-            throw new InvalidArgumentException(
865
-                esc_html__('An invalid Event ID was supplied.', 'event_espresso')
866
-            );
867
-        }
868
-        $statuses = is_array($statuses) ? $statuses : array($statuses);
869
-        $statuses = ! empty($statuses) ? $statuses : array(EEM_Registration::status_id_approved);
870
-        $valid_reg_statuses = EEM_Registration::reg_statuses();
871
-        foreach ($statuses as $status) {
872
-            if(! in_array($status, $valid_reg_statuses, true)) {
873
-                throw new InvalidStatusException($status, esc_html__('Registration', 'event_espresso'));
874
-            }
875
-        }
876
-        return $this->count(
877
-            array(
878
-                array(
879
-                    'EVT_ID' => $EVT_ID,
880
-                    'STS_ID' => array('IN', $statuses),
881
-                ),
882
-            ),
883
-            'REG_ID',
884
-            true
885
-        );
886
-    }
830
+		$registration_ids = $wpdb->get_results($registration_id_query, ARRAY_A);
831
+		if (empty($registration_ids)) {
832
+			return array();
833
+		}
834
+		$ids_for_model_query = array();
835
+		//let's flatten the ids so they can be used in the model query.
836
+		foreach ($registration_ids as $registration_id) {
837
+			if (isset($registration_id['registration_id'])) {
838
+				$ids_for_model_query[] = $registration_id['registration_id'];
839
+			}
840
+		}
841
+		//construct query
842
+		$_where = array(
843
+			'REG_ID' => array('IN', $ids_for_model_query),
844
+		);
845
+		return $this->get_all(array($_where));
846
+	}
847
+
848
+
849
+
850
+	/**
851
+	 * returns a count of registrations for the supplied event having the status as specified
852
+	 *
853
+	 * @param int $EVT_ID
854
+	 * @param array $statuses
855
+	 * @return int
856
+	 * @throws InvalidArgumentException
857
+	 * @throws InvalidStatusException
858
+	 * @throws EE_Error
859
+	 */
860
+	public function event_reg_count_for_statuses($EVT_ID, $statuses = array() )
861
+	{
862
+		$EVT_ID = absint($EVT_ID);
863
+		if (! $EVT_ID) {
864
+			throw new InvalidArgumentException(
865
+				esc_html__('An invalid Event ID was supplied.', 'event_espresso')
866
+			);
867
+		}
868
+		$statuses = is_array($statuses) ? $statuses : array($statuses);
869
+		$statuses = ! empty($statuses) ? $statuses : array(EEM_Registration::status_id_approved);
870
+		$valid_reg_statuses = EEM_Registration::reg_statuses();
871
+		foreach ($statuses as $status) {
872
+			if(! in_array($status, $valid_reg_statuses, true)) {
873
+				throw new InvalidStatusException($status, esc_html__('Registration', 'event_espresso'));
874
+			}
875
+		}
876
+		return $this->count(
877
+			array(
878
+				array(
879
+					'EVT_ID' => $EVT_ID,
880
+					'STS_ID' => array('IN', $statuses),
881
+				),
882
+			),
883
+			'REG_ID',
884
+			true
885
+		);
886
+	}
887 887
 
888 888
 }
889 889
 // End of file EEM_Registration.model.php
Please login to merge, or discard this patch.
core/exceptions/InvalidStatusException.php 1 patch
Indentation   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -8,26 +8,26 @@
 block discarded – undo
8 8
 
9 9
 class InvalidStatusException extends InvalidArgumentException
10 10
 {
11
-    /**
12
-     * InvalidStatusException constructor.
13
-     * @param string $status the invalid status id that was supplied
14
-     * @param string $domain the name of the domain, model, or class that the status belongs to
15
-     * @param string $message custom message
16
-     * @param int $code
17
-     * @param Exception|null $previous
18
-     */
19
-    public function __construct($status, $domain, $message = '', $code = 0, Exception $previous = null)
20
-    {
21
-        if (empty($message)) {
22
-            $message = sprintf(
23
-                __(
24
-                    '"%1$s" is not a valid %2$s status',
25
-                    'event_espresso'
26
-                ),
27
-                $status,
28
-                $domain
29
-            );
30
-        }
31
-        parent::__construct($message, $code, $previous);
32
-    }
11
+	/**
12
+	 * InvalidStatusException constructor.
13
+	 * @param string $status the invalid status id that was supplied
14
+	 * @param string $domain the name of the domain, model, or class that the status belongs to
15
+	 * @param string $message custom message
16
+	 * @param int $code
17
+	 * @param Exception|null $previous
18
+	 */
19
+	public function __construct($status, $domain, $message = '', $code = 0, Exception $previous = null)
20
+	{
21
+		if (empty($message)) {
22
+			$message = sprintf(
23
+				__(
24
+					'"%1$s" is not a valid %2$s status',
25
+					'event_espresso'
26
+				),
27
+				$status,
28
+				$domain
29
+			);
30
+		}
31
+		parent::__construct($message, $code, $previous);
32
+	}
33 33
 }
Please login to merge, or discard this patch.
caffeinated/brewing_regular.php 1 patch
Indentation   +269 added lines, -269 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
 use EventEspresso\core\services\database\TableAnalysis;
5 5
 
6 6
 if ( ! defined('EVENT_ESPRESSO_VERSION')) {
7
-    exit('No direct script access allowed');
7
+	exit('No direct script access allowed');
8 8
 }
9 9
 /**
10 10
  * the purpose of this file is to simply contain any action/filter hook callbacks etc for specific aspects of EE
@@ -29,277 +29,277 @@  discard block
 block discarded – undo
29 29
 class EE_Brewing_Regular extends EE_BASE implements InterminableInterface
30 30
 {
31 31
 
32
-    /**
33
-     * @var \EventEspresso\core\services\database\TableAnalysis $table_analysis
34
-     */
35
-    protected $_table_analysis;
36
-
37
-
38
-
39
-    /**
40
-     * EE_Brewing_Regular constructor.
41
-     */
42
-    public function __construct(TableAnalysis $table_analysis)
43
-    {
44
-        $this->_table_analysis = $table_analysis;
45
-        if (defined('EE_CAFF_PATH')) {
46
-            // activation
47
-            add_action('AHEE__EEH_Activation__initialize_db_content', array($this, 'initialize_caf_db_content'));
48
-            // load caff init
49
-            add_action('AHEE__EE_System__set_hooks_for_core', array($this, 'caffeinated_init'));
50
-            // remove the "powered by" credit link from receipts and invoices
51
-            add_filter('FHEE_EE_Html_messenger__add_powered_by_credit_link_to_receipt_and_invoice', '__return_false');
52
-            // add caffeinated modules
53
-            add_filter(
54
-                'FHEE__EE_Config__register_modules__modules_to_register',
55
-                array($this, 'caffeinated_modules_to_register')
56
-            );
57
-            // load caff scripts
58
-            add_action('wp_enqueue_scripts', array($this, 'enqueue_caffeinated_scripts'), 10);
59
-            add_filter('FHEE__EE_Registry__load_helper__helper_paths', array($this, 'caf_helper_paths'), 10);
60
-            add_filter(
61
-                'FHEE__EE_Payment_Method_Manager__register_payment_methods__payment_methods_to_register',
62
-                array($this, 'caf_payment_methods')
63
-            );
64
-            // caffeinated constructed
65
-            do_action('AHEE__EE_Brewing_Regular__construct__complete');
66
-            //seeing how this is caf, which isn't put on WordPress.org, we can have affiliate links without a disclaimer
67
-            add_filter('FHEE__ee_show_affiliate_links', '__return_false');
68
-        }
69
-    }
70
-
71
-
72
-
73
-    /**
74
-     * callback for the FHEE__EE_Registry__load_helper__helper_paths filter to add the caffeinated paths
75
-     *
76
-     * @param array $paths original helper paths array
77
-     * @return array             new array of paths
78
-     */
79
-    public function caf_helper_paths($paths)
80
-    {
81
-        $paths[] = EE_CAF_CORE . 'helpers' . DS;
82
-        return $paths;
83
-    }
84
-
85
-
86
-
87
-    /**
88
-     * Upon brand-new activation, if this is a new activation of CAF, we want to add
89
-     * some global prices that will show off EE4's capabilities. However, if they're upgrading
90
-     * from 3.1, or simply EE4.x decaf, we assume they don't want us to suddenly introduce these extra prices.
91
-     * This action should only be called when EE 4.x.0.P is initially activated.
92
-     * Right now the only CAF content are these global prices. If there's more in the future, then
93
-     * we should probably create a caf file to contain it all instead just a function like this.
94
-     * Right now, we ASSUME the only price types in the system are default ones
95
-     *
96
-     * @global wpdb $wpdb
97
-     */
98
-    public function initialize_caf_db_content()
99
-    {
100
-        global $wpdb;
101
-        //use same method of getting creator id as the version introducing the change
102
-        $default_creator_id = apply_filters('FHEE__EE_DMS_Core_4_5_0__get_default_creator_id', get_current_user_id());
103
-        $price_type_table = $wpdb->prefix . "esp_price_type";
104
-        $price_table = $wpdb->prefix . "esp_price";
105
-        if ($this->_get_table_analysis()->tableExists($price_type_table)) {
106
-            $SQL = 'SELECT COUNT(PRT_ID) FROM ' . $price_type_table . ' WHERE PBT_ID=4';//include trashed price types
107
-            $tax_price_type_count = $wpdb->get_var($SQL);
108
-            if ($tax_price_type_count <= 1) {
109
-                $wpdb->insert(
110
-                    $price_type_table,
111
-                    array(
112
-                        'PRT_name'       => __("Regional Tax", "event_espresso"),
113
-                        'PBT_ID'         => 4,
114
-                        'PRT_is_percent' => true,
115
-                        'PRT_order'      => 60,
116
-                        'PRT_deleted'    => false,
117
-                        'PRT_wp_user'    => $default_creator_id,
118
-                    ),
119
-                    array(
120
-                        '%s',//PRT_name
121
-                        '%d',//PBT_id
122
-                        '%d',//PRT_is_percent
123
-                        '%d',//PRT_order
124
-                        '%d',//PRT_deleted
125
-                        '%d', //PRT_wp_user
126
-                    )
127
-                );
128
-                //federal tax
129
-                $result = $wpdb->insert(
130
-                    $price_type_table,
131
-                    array(
132
-                        'PRT_name'       => __("Federal Tax", "event_espresso"),
133
-                        'PBT_ID'         => 4,
134
-                        'PRT_is_percent' => true,
135
-                        'PRT_order'      => 70,
136
-                        'PRT_deleted'    => false,
137
-                        'PRT_wp_user'    => $default_creator_id,
138
-                    ),
139
-                    array(
140
-                        '%s',//PRT_name
141
-                        '%d',//PBT_id
142
-                        '%d',//PRT_is_percent
143
-                        '%d',//PRT_order
144
-                        '%d',//PRT_deleted
145
-                        '%d' //PRT_wp_user
146
-                    )
147
-                );
148
-                if ($result) {
149
-                    $wpdb->insert(
150
-                        $price_table,
151
-                        array(
152
-                            'PRT_ID'         => $wpdb->insert_id,
153
-                            'PRC_amount'     => 15.00,
154
-                            'PRC_name'       => __("Sales Tax", "event_espresso"),
155
-                            'PRC_desc'       => '',
156
-                            'PRC_is_default' => true,
157
-                            'PRC_overrides'  => null,
158
-                            'PRC_deleted'    => false,
159
-                            'PRC_order'      => 50,
160
-                            'PRC_parent'     => null,
161
-                            'PRC_wp_user'    => $default_creator_id,
162
-                        ),
163
-                        array(
164
-                            '%d',//PRT_id
165
-                            '%f',//PRC_amount
166
-                            '%s',//PRC_name
167
-                            '%s',//PRC_desc
168
-                            '%d',//PRC_is_default
169
-                            '%d',//PRC_overrides
170
-                            '%d',//PRC_deleted
171
-                            '%d',//PRC_order
172
-                            '%d',//PRC_parent
173
-                            '%d' //PRC_wp_user
174
-                        )
175
-                    );
176
-                }
177
-            }
178
-        }
179
-    }
180
-
181
-
182
-
183
-    /**
184
-     *    caffeinated_modules_to_register
185
-     *
186
-     * @access public
187
-     * @param array $modules_to_register
188
-     * @return array
189
-     */
190
-    public function caffeinated_modules_to_register($modules_to_register = array())
191
-    {
192
-        if (is_readable(EE_CAFF_PATH . 'modules')) {
193
-            $caffeinated_modules_to_register = glob(EE_CAFF_PATH . 'modules' . DS . '*', GLOB_ONLYDIR);
194
-            if (is_array($caffeinated_modules_to_register) && ! empty($caffeinated_modules_to_register)) {
195
-                $modules_to_register = array_merge($modules_to_register, $caffeinated_modules_to_register);
196
-            }
197
-        }
198
-        return $modules_to_register;
199
-    }
200
-
201
-
202
-
203
-    public function caffeinated_init()
204
-    {
205
-        // EE_Register_CPTs hooks
206
-        add_filter('FHEE__EE_Register_CPTs__get_taxonomies__taxonomies', array($this, 'filter_taxonomies'), 10);
207
-        add_filter('FHEE__EE_Register_CPTs__get_CPTs__cpts', array($this, 'filter_cpts'), 10);
208
-        add_filter('FHEE__EE_Admin__get_extra_nav_menu_pages_items', array($this, 'nav_metabox_items'), 10);
209
-        EE_Registry::instance()->load_file(EE_CAFF_PATH, 'EE_Caf_Messages', 'class', array(), false);
210
-        // caffeinated_init__complete hook
211
-        do_action('AHEE__EE_Brewing_Regular__caffeinated_init__complete');
212
-    }
213
-
214
-
215
-
216
-    public function enqueue_caffeinated_scripts()
217
-    {
218
-        // sound of crickets...
219
-    }
220
-
221
-
222
-
223
-    /**
224
-     * callbacks below here
225
-     *
226
-     * @param array $taxonomy_array
227
-     * @return array
228
-     */
229
-    public function filter_taxonomies(array $taxonomy_array)
230
-    {
231
-        $taxonomy_array['espresso_venue_categories']['args']['show_in_nav_menus'] = true;
232
-        return $taxonomy_array;
233
-    }
234
-
235
-
236
-
237
-    /**
238
-     * @param array $cpt_array
239
-     * @return mixed
240
-     */
241
-    public function filter_cpts(array $cpt_array)
242
-    {
243
-        $cpt_array['espresso_venues']['args']['show_in_nav_menus'] = true;
244
-        return $cpt_array;
245
-    }
246
-
247
-
248
-
249
-    /**
250
-     * @param array $menuitems
251
-     * @return array
252
-     */
253
-    public function nav_metabox_items(array $menuitems)
254
-    {
255
-        $menuitems[] = array(
256
-            'title'       => __('Venue List', 'event_espresso'),
257
-            'url'         => get_post_type_archive_link('espresso_venues'),
258
-            'description' => __('Archive page for all venues.', 'event_espresso'),
259
-        );
260
-        return $menuitems;
261
-    }
262
-
263
-
264
-
265
-    /**
266
-     * Adds the payment methods in {event-espresso-core}/caffeinated/payment_methods
267
-     *
268
-     * @param array $payment_method_paths
269
-     * @return array values are folder paths to payment method folders
270
-     */
271
-    public function caf_payment_methods($payment_method_paths)
272
-    {
273
-        $caf_payment_methods_paths = glob(EE_CAF_PAYMENT_METHODS . '*', GLOB_ONLYDIR);
274
-        $payment_method_paths = array_merge($payment_method_paths, $caf_payment_methods_paths);
275
-        return $payment_method_paths;
276
-    }
277
-
278
-
279
-
280
-    /**
281
-     * Gets the injected table analyzer, or throws an exception
282
-     *
283
-     * @return TableAnalysis
284
-     * @throws \EE_Error
285
-     */
286
-    protected function _get_table_analysis()
287
-    {
288
-        if ($this->_table_analysis instanceof TableAnalysis) {
289
-            return $this->_table_analysis;
290
-        } else {
291
-            throw new \EE_Error(
292
-                sprintf(
293
-                    __('Table analysis class on class %1$s is not set properly.', 'event_espresso'),
294
-                    get_class($this)
295
-                )
296
-            );
297
-        }
298
-    }
32
+	/**
33
+	 * @var \EventEspresso\core\services\database\TableAnalysis $table_analysis
34
+	 */
35
+	protected $_table_analysis;
36
+
37
+
38
+
39
+	/**
40
+	 * EE_Brewing_Regular constructor.
41
+	 */
42
+	public function __construct(TableAnalysis $table_analysis)
43
+	{
44
+		$this->_table_analysis = $table_analysis;
45
+		if (defined('EE_CAFF_PATH')) {
46
+			// activation
47
+			add_action('AHEE__EEH_Activation__initialize_db_content', array($this, 'initialize_caf_db_content'));
48
+			// load caff init
49
+			add_action('AHEE__EE_System__set_hooks_for_core', array($this, 'caffeinated_init'));
50
+			// remove the "powered by" credit link from receipts and invoices
51
+			add_filter('FHEE_EE_Html_messenger__add_powered_by_credit_link_to_receipt_and_invoice', '__return_false');
52
+			// add caffeinated modules
53
+			add_filter(
54
+				'FHEE__EE_Config__register_modules__modules_to_register',
55
+				array($this, 'caffeinated_modules_to_register')
56
+			);
57
+			// load caff scripts
58
+			add_action('wp_enqueue_scripts', array($this, 'enqueue_caffeinated_scripts'), 10);
59
+			add_filter('FHEE__EE_Registry__load_helper__helper_paths', array($this, 'caf_helper_paths'), 10);
60
+			add_filter(
61
+				'FHEE__EE_Payment_Method_Manager__register_payment_methods__payment_methods_to_register',
62
+				array($this, 'caf_payment_methods')
63
+			);
64
+			// caffeinated constructed
65
+			do_action('AHEE__EE_Brewing_Regular__construct__complete');
66
+			//seeing how this is caf, which isn't put on WordPress.org, we can have affiliate links without a disclaimer
67
+			add_filter('FHEE__ee_show_affiliate_links', '__return_false');
68
+		}
69
+	}
70
+
71
+
72
+
73
+	/**
74
+	 * callback for the FHEE__EE_Registry__load_helper__helper_paths filter to add the caffeinated paths
75
+	 *
76
+	 * @param array $paths original helper paths array
77
+	 * @return array             new array of paths
78
+	 */
79
+	public function caf_helper_paths($paths)
80
+	{
81
+		$paths[] = EE_CAF_CORE . 'helpers' . DS;
82
+		return $paths;
83
+	}
84
+
85
+
86
+
87
+	/**
88
+	 * Upon brand-new activation, if this is a new activation of CAF, we want to add
89
+	 * some global prices that will show off EE4's capabilities. However, if they're upgrading
90
+	 * from 3.1, or simply EE4.x decaf, we assume they don't want us to suddenly introduce these extra prices.
91
+	 * This action should only be called when EE 4.x.0.P is initially activated.
92
+	 * Right now the only CAF content are these global prices. If there's more in the future, then
93
+	 * we should probably create a caf file to contain it all instead just a function like this.
94
+	 * Right now, we ASSUME the only price types in the system are default ones
95
+	 *
96
+	 * @global wpdb $wpdb
97
+	 */
98
+	public function initialize_caf_db_content()
99
+	{
100
+		global $wpdb;
101
+		//use same method of getting creator id as the version introducing the change
102
+		$default_creator_id = apply_filters('FHEE__EE_DMS_Core_4_5_0__get_default_creator_id', get_current_user_id());
103
+		$price_type_table = $wpdb->prefix . "esp_price_type";
104
+		$price_table = $wpdb->prefix . "esp_price";
105
+		if ($this->_get_table_analysis()->tableExists($price_type_table)) {
106
+			$SQL = 'SELECT COUNT(PRT_ID) FROM ' . $price_type_table . ' WHERE PBT_ID=4';//include trashed price types
107
+			$tax_price_type_count = $wpdb->get_var($SQL);
108
+			if ($tax_price_type_count <= 1) {
109
+				$wpdb->insert(
110
+					$price_type_table,
111
+					array(
112
+						'PRT_name'       => __("Regional Tax", "event_espresso"),
113
+						'PBT_ID'         => 4,
114
+						'PRT_is_percent' => true,
115
+						'PRT_order'      => 60,
116
+						'PRT_deleted'    => false,
117
+						'PRT_wp_user'    => $default_creator_id,
118
+					),
119
+					array(
120
+						'%s',//PRT_name
121
+						'%d',//PBT_id
122
+						'%d',//PRT_is_percent
123
+						'%d',//PRT_order
124
+						'%d',//PRT_deleted
125
+						'%d', //PRT_wp_user
126
+					)
127
+				);
128
+				//federal tax
129
+				$result = $wpdb->insert(
130
+					$price_type_table,
131
+					array(
132
+						'PRT_name'       => __("Federal Tax", "event_espresso"),
133
+						'PBT_ID'         => 4,
134
+						'PRT_is_percent' => true,
135
+						'PRT_order'      => 70,
136
+						'PRT_deleted'    => false,
137
+						'PRT_wp_user'    => $default_creator_id,
138
+					),
139
+					array(
140
+						'%s',//PRT_name
141
+						'%d',//PBT_id
142
+						'%d',//PRT_is_percent
143
+						'%d',//PRT_order
144
+						'%d',//PRT_deleted
145
+						'%d' //PRT_wp_user
146
+					)
147
+				);
148
+				if ($result) {
149
+					$wpdb->insert(
150
+						$price_table,
151
+						array(
152
+							'PRT_ID'         => $wpdb->insert_id,
153
+							'PRC_amount'     => 15.00,
154
+							'PRC_name'       => __("Sales Tax", "event_espresso"),
155
+							'PRC_desc'       => '',
156
+							'PRC_is_default' => true,
157
+							'PRC_overrides'  => null,
158
+							'PRC_deleted'    => false,
159
+							'PRC_order'      => 50,
160
+							'PRC_parent'     => null,
161
+							'PRC_wp_user'    => $default_creator_id,
162
+						),
163
+						array(
164
+							'%d',//PRT_id
165
+							'%f',//PRC_amount
166
+							'%s',//PRC_name
167
+							'%s',//PRC_desc
168
+							'%d',//PRC_is_default
169
+							'%d',//PRC_overrides
170
+							'%d',//PRC_deleted
171
+							'%d',//PRC_order
172
+							'%d',//PRC_parent
173
+							'%d' //PRC_wp_user
174
+						)
175
+					);
176
+				}
177
+			}
178
+		}
179
+	}
180
+
181
+
182
+
183
+	/**
184
+	 *    caffeinated_modules_to_register
185
+	 *
186
+	 * @access public
187
+	 * @param array $modules_to_register
188
+	 * @return array
189
+	 */
190
+	public function caffeinated_modules_to_register($modules_to_register = array())
191
+	{
192
+		if (is_readable(EE_CAFF_PATH . 'modules')) {
193
+			$caffeinated_modules_to_register = glob(EE_CAFF_PATH . 'modules' . DS . '*', GLOB_ONLYDIR);
194
+			if (is_array($caffeinated_modules_to_register) && ! empty($caffeinated_modules_to_register)) {
195
+				$modules_to_register = array_merge($modules_to_register, $caffeinated_modules_to_register);
196
+			}
197
+		}
198
+		return $modules_to_register;
199
+	}
200
+
201
+
202
+
203
+	public function caffeinated_init()
204
+	{
205
+		// EE_Register_CPTs hooks
206
+		add_filter('FHEE__EE_Register_CPTs__get_taxonomies__taxonomies', array($this, 'filter_taxonomies'), 10);
207
+		add_filter('FHEE__EE_Register_CPTs__get_CPTs__cpts', array($this, 'filter_cpts'), 10);
208
+		add_filter('FHEE__EE_Admin__get_extra_nav_menu_pages_items', array($this, 'nav_metabox_items'), 10);
209
+		EE_Registry::instance()->load_file(EE_CAFF_PATH, 'EE_Caf_Messages', 'class', array(), false);
210
+		// caffeinated_init__complete hook
211
+		do_action('AHEE__EE_Brewing_Regular__caffeinated_init__complete');
212
+	}
213
+
214
+
215
+
216
+	public function enqueue_caffeinated_scripts()
217
+	{
218
+		// sound of crickets...
219
+	}
220
+
221
+
222
+
223
+	/**
224
+	 * callbacks below here
225
+	 *
226
+	 * @param array $taxonomy_array
227
+	 * @return array
228
+	 */
229
+	public function filter_taxonomies(array $taxonomy_array)
230
+	{
231
+		$taxonomy_array['espresso_venue_categories']['args']['show_in_nav_menus'] = true;
232
+		return $taxonomy_array;
233
+	}
234
+
235
+
236
+
237
+	/**
238
+	 * @param array $cpt_array
239
+	 * @return mixed
240
+	 */
241
+	public function filter_cpts(array $cpt_array)
242
+	{
243
+		$cpt_array['espresso_venues']['args']['show_in_nav_menus'] = true;
244
+		return $cpt_array;
245
+	}
246
+
247
+
248
+
249
+	/**
250
+	 * @param array $menuitems
251
+	 * @return array
252
+	 */
253
+	public function nav_metabox_items(array $menuitems)
254
+	{
255
+		$menuitems[] = array(
256
+			'title'       => __('Venue List', 'event_espresso'),
257
+			'url'         => get_post_type_archive_link('espresso_venues'),
258
+			'description' => __('Archive page for all venues.', 'event_espresso'),
259
+		);
260
+		return $menuitems;
261
+	}
262
+
263
+
264
+
265
+	/**
266
+	 * Adds the payment methods in {event-espresso-core}/caffeinated/payment_methods
267
+	 *
268
+	 * @param array $payment_method_paths
269
+	 * @return array values are folder paths to payment method folders
270
+	 */
271
+	public function caf_payment_methods($payment_method_paths)
272
+	{
273
+		$caf_payment_methods_paths = glob(EE_CAF_PAYMENT_METHODS . '*', GLOB_ONLYDIR);
274
+		$payment_method_paths = array_merge($payment_method_paths, $caf_payment_methods_paths);
275
+		return $payment_method_paths;
276
+	}
277
+
278
+
279
+
280
+	/**
281
+	 * Gets the injected table analyzer, or throws an exception
282
+	 *
283
+	 * @return TableAnalysis
284
+	 * @throws \EE_Error
285
+	 */
286
+	protected function _get_table_analysis()
287
+	{
288
+		if ($this->_table_analysis instanceof TableAnalysis) {
289
+			return $this->_table_analysis;
290
+		} else {
291
+			throw new \EE_Error(
292
+				sprintf(
293
+					__('Table analysis class on class %1$s is not set properly.', 'event_espresso'),
294
+					get_class($this)
295
+				)
296
+			);
297
+		}
298
+	}
299 299
 }
300 300
 
301 301
 
302 302
 
303 303
 $brewing = new EE_Brewing_Regular(
304
-    EE_Registry::instance()->create('TableAnalysis', array(), true)
304
+	EE_Registry::instance()->create('TableAnalysis', array(), true)
305 305
 );
306 306
\ No newline at end of file
Please login to merge, or discard this patch.
core/EE_Config.core.php 1 patch
Indentation   +3061 added lines, -3061 removed lines patch added patch discarded remove patch
@@ -17,2443 +17,2443 @@  discard block
 block discarded – undo
17 17
 final class EE_Config implements ResettableInterface
18 18
 {
19 19
 
20
-    const OPTION_NAME        = 'ee_config';
20
+	const OPTION_NAME        = 'ee_config';
21
+
22
+	const LOG_NAME           = 'ee_config_log';
23
+
24
+	const LOG_LENGTH         = 100;
25
+
26
+	const ADDON_OPTION_NAMES = 'ee_config_option_names';
27
+
28
+
29
+	/**
30
+	 *    instance of the EE_Config object
31
+	 *
32
+	 * @var    EE_Config $_instance
33
+	 * @access    private
34
+	 */
35
+	private static $_instance;
36
+
37
+	/**
38
+	 * @var boolean $_logging_enabled
39
+	 */
40
+	private static $_logging_enabled = false;
41
+
42
+	/**
43
+	 * @var LegacyShortcodesManager $legacy_shortcodes_manager
44
+	 */
45
+	private $legacy_shortcodes_manager;
46
+
47
+	/**
48
+	 * An StdClass whose property names are addon slugs,
49
+	 * and values are their config classes
50
+	 *
51
+	 * @var StdClass
52
+	 */
53
+	public $addons;
54
+
55
+	/**
56
+	 * @var EE_Admin_Config
57
+	 */
58
+	public $admin;
59
+
60
+	/**
61
+	 * @var EE_Core_Config
62
+	 */
63
+	public $core;
64
+
65
+	/**
66
+	 * @var EE_Currency_Config
67
+	 */
68
+	public $currency;
69
+
70
+	/**
71
+	 * @var EE_Organization_Config
72
+	 */
73
+	public $organization;
74
+
75
+	/**
76
+	 * @var EE_Registration_Config
77
+	 */
78
+	public $registration;
79
+
80
+	/**
81
+	 * @var EE_Template_Config
82
+	 */
83
+	public $template_settings;
84
+
85
+	/**
86
+	 * Holds EE environment values.
87
+	 *
88
+	 * @var EE_Environment_Config
89
+	 */
90
+	public $environment;
91
+
92
+	/**
93
+	 * settings pertaining to Google maps
94
+	 *
95
+	 * @var EE_Map_Config
96
+	 */
97
+	public $map_settings;
98
+
99
+	/**
100
+	 * settings pertaining to Taxes
101
+	 *
102
+	 * @var EE_Tax_Config
103
+	 */
104
+	public $tax_settings;
105
+
106
+
107
+	/**
108
+	 * Settings pertaining to global messages settings.
109
+	 *
110
+	 * @var EE_Messages_Config
111
+	 */
112
+	public $messages;
113
+
114
+	/**
115
+	 * @deprecated
116
+	 * @var EE_Gateway_Config
117
+	 */
118
+	public $gateway;
119
+
120
+	/**
121
+	 * @var    array $_addon_option_names
122
+	 * @access    private
123
+	 */
124
+	private $_addon_option_names = array();
125
+
126
+	/**
127
+	 * @var    array $_module_route_map
128
+	 * @access    private
129
+	 */
130
+	private static $_module_route_map = array();
131
+
132
+	/**
133
+	 * @var    array $_module_forward_map
134
+	 * @access    private
135
+	 */
136
+	private static $_module_forward_map = array();
137
+
138
+	/**
139
+	 * @var    array $_module_view_map
140
+	 * @access    private
141
+	 */
142
+	private static $_module_view_map = array();
143
+
144
+
145
+
146
+	/**
147
+	 * @singleton method used to instantiate class object
148
+	 * @access    public
149
+	 * @return EE_Config instance
150
+	 */
151
+	public static function instance()
152
+	{
153
+		// check if class object is instantiated, and instantiated properly
154
+		if (! self::$_instance instanceof EE_Config) {
155
+			self::$_instance = new self();
156
+		}
157
+		return self::$_instance;
158
+	}
159
+
160
+
161
+
162
+	/**
163
+	 * Resets the config
164
+	 *
165
+	 * @param bool    $hard_reset    if TRUE, sets EE_CONFig back to its original settings in the database. If FALSE
166
+	 *                               (default) leaves the database alone, and merely resets the EE_Config object to
167
+	 *                               reflect its state in the database
168
+	 * @param boolean $reinstantiate if TRUE (default) call instance() and return it. Otherwise, just leave
169
+	 *                               $_instance as NULL. Useful in case you want to forget about the old instance on
170
+	 *                               EE_Config, but might not be ready to instantiate EE_Config currently (eg if the
171
+	 *                               site was put into maintenance mode)
172
+	 * @return EE_Config
173
+	 */
174
+	public static function reset($hard_reset = false, $reinstantiate = true)
175
+	{
176
+		if (self::$_instance instanceof EE_Config) {
177
+			if ($hard_reset) {
178
+				self::$_instance->legacy_shortcodes_manager = null;
179
+				self::$_instance->_addon_option_names = array();
180
+				self::$_instance->_initialize_config();
181
+				self::$_instance->update_espresso_config();
182
+			}
183
+			self::$_instance->update_addon_option_names();
184
+		}
185
+		self::$_instance = null;
186
+		//we don't need to reset the static properties imo because those should
187
+		//only change when a module is added or removed. Currently we don't
188
+		//support removing a module during a request when it previously existed
189
+		if ($reinstantiate) {
190
+			return self::instance();
191
+		} else {
192
+			return null;
193
+		}
194
+	}
195
+
196
+
197
+
198
+	/**
199
+	 *    class constructor
200
+	 *
201
+	 * @access    private
202
+	 */
203
+	private function __construct()
204
+	{
205
+		do_action('AHEE__EE_Config__construct__begin', $this);
206
+		EE_Config::$_logging_enabled = apply_filters('FHEE__EE_Config___construct__logging_enabled', false);
207
+		// setup empty config classes
208
+		$this->_initialize_config();
209
+		// load existing EE site settings
210
+		$this->_load_core_config();
211
+		// confirm everything loaded correctly and set filtered defaults if not
212
+		$this->_verify_config();
213
+		//  register shortcodes and modules
214
+		add_action(
215
+			'AHEE__EE_System__register_shortcodes_modules_and_widgets',
216
+			array($this, 'register_shortcodes_and_modules'),
217
+			999
218
+		);
219
+		//  initialize shortcodes and modules
220
+		add_action('AHEE__EE_System__core_loaded_and_ready', array($this, 'initialize_shortcodes_and_modules'));
221
+		// register widgets
222
+		add_action('widgets_init', array($this, 'widgets_init'), 10);
223
+		// shutdown
224
+		add_action('shutdown', array($this, 'shutdown'), 10);
225
+		// construct__end hook
226
+		do_action('AHEE__EE_Config__construct__end', $this);
227
+		// hardcoded hack
228
+		$this->template_settings->current_espresso_theme = 'Espresso_Arabica_2014';
229
+	}
230
+
231
+
232
+
233
+	/**
234
+	 * @return boolean
235
+	 */
236
+	public static function logging_enabled()
237
+	{
238
+		return self::$_logging_enabled;
239
+	}
240
+
241
+
242
+
243
+	/**
244
+	 * use to get the current theme if needed from static context
245
+	 *
246
+	 * @return string current theme set.
247
+	 */
248
+	public static function get_current_theme()
249
+	{
250
+		return isset(self::$_instance->template_settings->current_espresso_theme)
251
+			? self::$_instance->template_settings->current_espresso_theme : 'Espresso_Arabica_2014';
252
+	}
253
+
254
+
255
+
256
+	/**
257
+	 *        _initialize_config
258
+	 *
259
+	 * @access private
260
+	 * @return void
261
+	 */
262
+	private function _initialize_config()
263
+	{
264
+		EE_Config::trim_log();
265
+		//set defaults
266
+		$this->_addon_option_names = get_option(EE_Config::ADDON_OPTION_NAMES, array());
267
+		$this->addons = new stdClass();
268
+		// set _module_route_map
269
+		EE_Config::$_module_route_map = array();
270
+		// set _module_forward_map
271
+		EE_Config::$_module_forward_map = array();
272
+		// set _module_view_map
273
+		EE_Config::$_module_view_map = array();
274
+	}
275
+
276
+
277
+
278
+	/**
279
+	 *        load core plugin configuration
280
+	 *
281
+	 * @access private
282
+	 * @return void
283
+	 */
284
+	private function _load_core_config()
285
+	{
286
+		// load_core_config__start hook
287
+		do_action('AHEE__EE_Config___load_core_config__start', $this);
288
+		$espresso_config = $this->get_espresso_config();
289
+		foreach ($espresso_config as $config => $settings) {
290
+			// load_core_config__start hook
291
+			$settings = apply_filters(
292
+				'FHEE__EE_Config___load_core_config__config_settings',
293
+				$settings,
294
+				$config,
295
+				$this
296
+			);
297
+			if (is_object($settings) && property_exists($this, $config)) {
298
+				$this->{$config} = apply_filters('FHEE__EE_Config___load_core_config__' . $config, $settings);
299
+				//call configs populate method to ensure any defaults are set for empty values.
300
+				if (method_exists($settings, 'populate')) {
301
+					$this->{$config}->populate();
302
+				}
303
+				if (method_exists($settings, 'do_hooks')) {
304
+					$this->{$config}->do_hooks();
305
+				}
306
+			}
307
+		}
308
+		if (apply_filters('FHEE__EE_Config___load_core_config__update_espresso_config', false)) {
309
+			$this->update_espresso_config();
310
+		}
311
+		// load_core_config__end hook
312
+		do_action('AHEE__EE_Config___load_core_config__end', $this);
313
+	}
314
+
315
+
316
+
317
+	/**
318
+	 *    _verify_config
319
+	 *
320
+	 * @access    protected
321
+	 * @return    void
322
+	 */
323
+	protected function _verify_config()
324
+	{
325
+		$this->core = $this->core instanceof EE_Core_Config
326
+			? $this->core
327
+			: new EE_Core_Config();
328
+		$this->core = apply_filters('FHEE__EE_Config___initialize_config__core', $this->core);
329
+		$this->organization = $this->organization instanceof EE_Organization_Config
330
+			? $this->organization
331
+			: new EE_Organization_Config();
332
+		$this->organization = apply_filters(
333
+			'FHEE__EE_Config___initialize_config__organization',
334
+			$this->organization
335
+		);
336
+		$this->currency = $this->currency instanceof EE_Currency_Config
337
+			? $this->currency
338
+			: new EE_Currency_Config();
339
+		$this->currency = apply_filters('FHEE__EE_Config___initialize_config__currency', $this->currency);
340
+		$this->registration = $this->registration instanceof EE_Registration_Config
341
+			? $this->registration
342
+			: new EE_Registration_Config();
343
+		$this->registration = apply_filters(
344
+			'FHEE__EE_Config___initialize_config__registration',
345
+			$this->registration
346
+		);
347
+		$this->admin = $this->admin instanceof EE_Admin_Config
348
+			? $this->admin
349
+			: new EE_Admin_Config();
350
+		$this->admin = apply_filters('FHEE__EE_Config___initialize_config__admin', $this->admin);
351
+		$this->template_settings = $this->template_settings instanceof EE_Template_Config
352
+			? $this->template_settings
353
+			: new EE_Template_Config();
354
+		$this->template_settings = apply_filters(
355
+			'FHEE__EE_Config___initialize_config__template_settings',
356
+			$this->template_settings
357
+		);
358
+		$this->map_settings = $this->map_settings instanceof EE_Map_Config
359
+			? $this->map_settings
360
+			: new EE_Map_Config();
361
+		$this->map_settings = apply_filters('FHEE__EE_Config___initialize_config__map_settings',
362
+			$this->map_settings);
363
+		$this->environment = $this->environment instanceof EE_Environment_Config
364
+			? $this->environment
365
+			: new EE_Environment_Config();
366
+		$this->environment = apply_filters('FHEE__EE_Config___initialize_config__environment',
367
+			$this->environment);
368
+		$this->tax_settings = $this->tax_settings instanceof EE_Tax_Config
369
+			? $this->tax_settings
370
+			: new EE_Tax_Config();
371
+		$this->tax_settings = apply_filters('FHEE__EE_Config___initialize_config__tax_settings',
372
+			$this->tax_settings);
373
+		$this->messages = apply_filters('FHEE__EE_Config__initialize_config__messages', $this->messages);
374
+		$this->messages = $this->messages instanceof EE_Messages_Config
375
+			? $this->messages
376
+			: new EE_Messages_Config();
377
+		$this->gateway = $this->gateway instanceof EE_Gateway_Config
378
+			? $this->gateway
379
+			: new EE_Gateway_Config();
380
+		$this->gateway = apply_filters('FHEE__EE_Config___initialize_config__gateway', $this->gateway);
381
+		$this->legacy_shortcodes_manager = null;
382
+	}
383
+
384
+
385
+	/**
386
+	 *    get_espresso_config
387
+	 *
388
+	 * @access    public
389
+	 * @return    array of espresso config stuff
390
+	 */
391
+	public function get_espresso_config()
392
+	{
393
+		// grab espresso configuration
394
+		return apply_filters(
395
+			'FHEE__EE_Config__get_espresso_config__CFG',
396
+			get_option(EE_Config::OPTION_NAME, array())
397
+		);
398
+	}
399
+
400
+
401
+
402
+	/**
403
+	 *    double_check_config_comparison
404
+	 *
405
+	 * @access    public
406
+	 * @param string $option
407
+	 * @param        $old_value
408
+	 * @param        $value
409
+	 */
410
+	public function double_check_config_comparison($option = '', $old_value, $value)
411
+	{
412
+		// make sure we're checking the ee config
413
+		if ($option === EE_Config::OPTION_NAME) {
414
+			// run a loose comparison of the old value against the new value for type and properties,
415
+			// but NOT exact instance like WP update_option does (ie: NOT type safe comparison)
416
+			if ($value != $old_value) {
417
+				// if they are NOT the same, then remove the hook,
418
+				// which means the subsequent update results will be based solely on the update query results
419
+				// the reason we do this is because, as stated above,
420
+				// WP update_option performs an exact instance comparison (===) on any update values passed to it
421
+				// this happens PRIOR to serialization and any subsequent update.
422
+				// If values are found to match their previous old value,
423
+				// then WP bails before performing any update.
424
+				// Since we are passing the EE_Config object, it is comparing the EXACT instance of the saved version
425
+				// it just pulled from the db, with the one being passed to it (which will not match).
426
+				// HOWEVER, once the object is serialized and passed off to MySQL to update,
427
+				// MySQL MAY ALSO NOT perform the update because
428
+				// the string it sees in the db looks the same as the new one it has been passed!!!
429
+				// This results in the query returning an "affected rows" value of ZERO,
430
+				// which gets returned immediately by WP update_option and looks like an error.
431
+				remove_action('update_option', array($this, 'check_config_updated'));
432
+			}
433
+		}
434
+	}
435
+
436
+
437
+
438
+	/**
439
+	 *    update_espresso_config
440
+	 *
441
+	 * @access   public
442
+	 */
443
+	protected function _reset_espresso_addon_config()
444
+	{
445
+		$this->_addon_option_names = array();
446
+		foreach ($this->addons as $addon_name => $addon_config_obj) {
447
+			$addon_config_obj = maybe_unserialize($addon_config_obj);
448
+			$config_class = get_class($addon_config_obj);
449
+			if ($addon_config_obj instanceof $config_class && ! $addon_config_obj instanceof __PHP_Incomplete_Class) {
450
+				$this->update_config('addons', $addon_name, $addon_config_obj, false);
451
+			}
452
+			$this->addons->{$addon_name} = null;
453
+		}
454
+	}
455
+
456
+
457
+
458
+	/**
459
+	 *    update_espresso_config
460
+	 *
461
+	 * @access   public
462
+	 * @param   bool $add_success
463
+	 * @param   bool $add_error
464
+	 * @return   bool
465
+	 */
466
+	public function update_espresso_config($add_success = false, $add_error = true)
467
+	{
468
+		// don't allow config updates during WP heartbeats
469
+		if (\EE_Registry::instance()->REQ->get('action', '') === 'heartbeat') {
470
+			return false;
471
+		}
472
+		// commented out the following re: https://events.codebasehq.com/projects/event-espresso/tickets/8197
473
+		//$clone = clone( self::$_instance );
474
+		//self::$_instance = NULL;
475
+		do_action('AHEE__EE_Config__update_espresso_config__begin', $this);
476
+		$this->_reset_espresso_addon_config();
477
+		// hook into update_option because that happens AFTER the ( $value === $old_value ) conditional
478
+		// but BEFORE the actual update occurs
479
+		add_action('update_option', array($this, 'double_check_config_comparison'), 1, 3);
480
+		// don't want to persist legacy_shortcodes_manager, but don't want to lose it either
481
+		$legacy_shortcodes_manager = $this->legacy_shortcodes_manager;
482
+		$this->legacy_shortcodes_manager = null;
483
+		// now update "ee_config"
484
+		$saved = update_option(EE_Config::OPTION_NAME, $this);
485
+		$this->legacy_shortcodes_manager = $legacy_shortcodes_manager;
486
+		EE_Config::log(EE_Config::OPTION_NAME);
487
+		// if not saved... check if the hook we just added still exists;
488
+		// if it does, it means one of two things:
489
+		// 		that update_option bailed at the ( $value === $old_value ) conditional,
490
+		//		 or...
491
+		// 		the db update query returned 0 rows affected
492
+		// 		(probably because the data  value was the same from it's perspective)
493
+		// so the existence of the hook means that a negative result from update_option is NOT an error,
494
+		// but just means no update occurred, so don't display an error to the user.
495
+		// BUT... if update_option returns FALSE, AND the hook is missing,
496
+		// then it means that something truly went wrong
497
+		$saved = ! $saved ? has_action('update_option', array($this, 'double_check_config_comparison')) : $saved;
498
+		// remove our action since we don't want it in the system anymore
499
+		remove_action('update_option', array($this, 'double_check_config_comparison'), 1);
500
+		do_action('AHEE__EE_Config__update_espresso_config__end', $this, $saved);
501
+		//self::$_instance = $clone;
502
+		//unset( $clone );
503
+		// if config remains the same or was updated successfully
504
+		if ($saved) {
505
+			if ($add_success) {
506
+				EE_Error::add_success(
507
+					__('The Event Espresso Configuration Settings have been successfully updated.', 'event_espresso'),
508
+					__FILE__,
509
+					__FUNCTION__,
510
+					__LINE__
511
+				);
512
+			}
513
+			return true;
514
+		} else {
515
+			if ($add_error) {
516
+				EE_Error::add_error(
517
+					__('The Event Espresso Configuration Settings were not updated.', 'event_espresso'),
518
+					__FILE__,
519
+					__FUNCTION__,
520
+					__LINE__
521
+				);
522
+			}
523
+			return false;
524
+		}
525
+	}
526
+
527
+
528
+
529
+	/**
530
+	 *    _verify_config_params
531
+	 *
532
+	 * @access    private
533
+	 * @param    string         $section
534
+	 * @param    string         $name
535
+	 * @param    string         $config_class
536
+	 * @param    EE_Config_Base $config_obj
537
+	 * @param    array          $tests_to_run
538
+	 * @param    bool           $display_errors
539
+	 * @return    bool    TRUE on success, FALSE on fail
540
+	 */
541
+	private function _verify_config_params(
542
+		$section = '',
543
+		$name = '',
544
+		$config_class = '',
545
+		$config_obj = null,
546
+		$tests_to_run = array(1, 2, 3, 4, 5, 6, 7, 8),
547
+		$display_errors = true
548
+	) {
549
+		try {
550
+			foreach ($tests_to_run as $test) {
551
+				switch ($test) {
552
+					// TEST #1 : check that section was set
553
+					case 1 :
554
+						if (empty($section)) {
555
+							if ($display_errors) {
556
+								throw new EE_Error(
557
+									sprintf(
558
+										__(
559
+											'No configuration section has been provided while attempting to save "%s".',
560
+											'event_espresso'
561
+										),
562
+										$config_class
563
+									)
564
+								);
565
+							}
566
+							return false;
567
+						}
568
+						break;
569
+					// TEST #2 : check that settings section exists
570
+					case 2 :
571
+						if (! isset($this->{$section})) {
572
+							if ($display_errors) {
573
+								throw new EE_Error(
574
+									sprintf(
575
+										__('The "%s" configuration section does not exist.', 'event_espresso'),
576
+										$section
577
+									)
578
+								);
579
+							}
580
+							return false;
581
+						}
582
+						break;
583
+					// TEST #3 : check that section is the proper format
584
+					case 3 :
585
+						if (
586
+						! ($this->{$section} instanceof EE_Config_Base || $this->{$section} instanceof stdClass)
587
+						) {
588
+							if ($display_errors) {
589
+								throw new EE_Error(
590
+									sprintf(
591
+										__(
592
+											'The "%s" configuration settings have not been formatted correctly.',
593
+											'event_espresso'
594
+										),
595
+										$section
596
+									)
597
+								);
598
+							}
599
+							return false;
600
+						}
601
+						break;
602
+					// TEST #4 : check that config section name has been set
603
+					case 4 :
604
+						if (empty($name)) {
605
+							if ($display_errors) {
606
+								throw new EE_Error(
607
+									__(
608
+										'No name has been provided for the specific configuration section.',
609
+										'event_espresso'
610
+									)
611
+								);
612
+							}
613
+							return false;
614
+						}
615
+						break;
616
+					// TEST #5 : check that a config class name has been set
617
+					case 5 :
618
+						if (empty($config_class)) {
619
+							if ($display_errors) {
620
+								throw new EE_Error(
621
+									__(
622
+										'No class name has been provided for the specific configuration section.',
623
+										'event_espresso'
624
+									)
625
+								);
626
+							}
627
+							return false;
628
+						}
629
+						break;
630
+					// TEST #6 : verify config class is accessible
631
+					case 6 :
632
+						if (! class_exists($config_class)) {
633
+							if ($display_errors) {
634
+								throw new EE_Error(
635
+									sprintf(
636
+										__(
637
+											'The "%s" class does not exist. Please ensure that an autoloader has been set for it.',
638
+											'event_espresso'
639
+										),
640
+										$config_class
641
+									)
642
+								);
643
+							}
644
+							return false;
645
+						}
646
+						break;
647
+					// TEST #7 : check that config has even been set
648
+					case 7 :
649
+						if (! isset($this->{$section}->{$name})) {
650
+							if ($display_errors) {
651
+								throw new EE_Error(
652
+									sprintf(
653
+										__('No configuration has been set for "%1$s->%2$s".', 'event_espresso'),
654
+										$section,
655
+										$name
656
+									)
657
+								);
658
+							}
659
+							return false;
660
+						} else {
661
+							// and make sure it's not serialized
662
+							$this->{$section}->{$name} = maybe_unserialize($this->{$section}->{$name});
663
+						}
664
+						break;
665
+					// TEST #8 : check that config is the requested type
666
+					case 8 :
667
+						if (! $this->{$section}->{$name} instanceof $config_class) {
668
+							if ($display_errors) {
669
+								throw new EE_Error(
670
+									sprintf(
671
+										__(
672
+											'The configuration for "%1$s->%2$s" is not of the "%3$s" class.',
673
+											'event_espresso'
674
+										),
675
+										$section,
676
+										$name,
677
+										$config_class
678
+									)
679
+								);
680
+							}
681
+							return false;
682
+						}
683
+						break;
684
+					// TEST #9 : verify config object
685
+					case 9 :
686
+						if (! $config_obj instanceof EE_Config_Base) {
687
+							if ($display_errors) {
688
+								throw new EE_Error(
689
+									sprintf(
690
+										__('The "%s" class is not an instance of EE_Config_Base.', 'event_espresso'),
691
+										print_r($config_obj, true)
692
+									)
693
+								);
694
+							}
695
+							return false;
696
+						}
697
+						break;
698
+				}
699
+			}
700
+		} catch (EE_Error $e) {
701
+			$e->get_error();
702
+		}
703
+		// you have successfully run the gauntlet
704
+		return true;
705
+	}
706
+
707
+
708
+
709
+	/**
710
+	 *    _generate_config_option_name
711
+	 *
712
+	 * @access        protected
713
+	 * @param        string $section
714
+	 * @param        string $name
715
+	 * @return        string
716
+	 */
717
+	private function _generate_config_option_name($section = '', $name = '')
718
+	{
719
+		return 'ee_config-' . strtolower($section . '-' . str_replace(array('EE_', 'EED_'), '', $name));
720
+	}
721
+
722
+
723
+
724
+	/**
725
+	 *    _set_config_class
726
+	 * ensures that a config class is set, either from a passed config class or one generated from the config name
727
+	 *
728
+	 * @access    private
729
+	 * @param    string $config_class
730
+	 * @param    string $name
731
+	 * @return    string
732
+	 */
733
+	private function _set_config_class($config_class = '', $name = '')
734
+	{
735
+		return ! empty($config_class)
736
+			? $config_class
737
+			: str_replace(' ', '_', ucwords(str_replace('_', ' ', $name))) . '_Config';
738
+	}
739
+
740
+
741
+
742
+	/**
743
+	 *    set_config
744
+	 *
745
+	 * @access    protected
746
+	 * @param    string         $section
747
+	 * @param    string         $name
748
+	 * @param    string         $config_class
749
+	 * @param    EE_Config_Base $config_obj
750
+	 * @return    EE_Config_Base
751
+	 */
752
+	public function set_config($section = '', $name = '', $config_class = '', EE_Config_Base $config_obj = null)
753
+	{
754
+		// ensure config class is set to something
755
+		$config_class = $this->_set_config_class($config_class, $name);
756
+		// run tests 1-4, 6, and 7 to verify all config params are set and valid
757
+		if (! $this->_verify_config_params($section, $name, $config_class, null, array(1, 2, 3, 4, 5, 6))) {
758
+			return null;
759
+		}
760
+		$config_option_name = $this->_generate_config_option_name($section, $name);
761
+		// if the config option name hasn't been added yet to the list of option names we're tracking, then do so now
762
+		if (! isset($this->_addon_option_names[$config_option_name])) {
763
+			$this->_addon_option_names[$config_option_name] = $config_class;
764
+			$this->update_addon_option_names();
765
+		}
766
+		// verify the incoming config object but suppress errors
767
+		if (! $this->_verify_config_params($section, $name, $config_class, $config_obj, array(9), false)) {
768
+			$config_obj = new $config_class();
769
+		}
770
+		if (get_option($config_option_name)) {
771
+			EE_Config::log($config_option_name);
772
+			update_option($config_option_name, $config_obj);
773
+			$this->{$section}->{$name} = $config_obj;
774
+			return $this->{$section}->{$name};
775
+		} else {
776
+			// create a wp-option for this config
777
+			if (add_option($config_option_name, $config_obj, '', 'no')) {
778
+				$this->{$section}->{$name} = maybe_unserialize($config_obj);
779
+				return $this->{$section}->{$name};
780
+			} else {
781
+				EE_Error::add_error(
782
+					sprintf(__('The "%s" could not be saved to the database.', 'event_espresso'), $config_class),
783
+					__FILE__,
784
+					__FUNCTION__,
785
+					__LINE__
786
+				);
787
+				return null;
788
+			}
789
+		}
790
+	}
791
+
792
+
793
+
794
+	/**
795
+	 *    update_config
796
+	 * Important: the config object must ALREADY be set, otherwise this will produce an error.
797
+	 *
798
+	 * @access    public
799
+	 * @param    string                $section
800
+	 * @param    string                $name
801
+	 * @param    EE_Config_Base|string $config_obj
802
+	 * @param    bool                  $throw_errors
803
+	 * @return    bool
804
+	 */
805
+	public function update_config($section = '', $name = '', $config_obj = '', $throw_errors = true)
806
+	{
807
+		// don't allow config updates during WP heartbeats
808
+		if (\EE_Registry::instance()->REQ->get('action', '') === 'heartbeat') {
809
+			return false;
810
+		}
811
+		$config_obj = maybe_unserialize($config_obj);
812
+		// get class name of the incoming object
813
+		$config_class = get_class($config_obj);
814
+		// run tests 1-5 and 9 to verify config
815
+		if (! $this->_verify_config_params(
816
+			$section,
817
+			$name,
818
+			$config_class,
819
+			$config_obj,
820
+			array(1, 2, 3, 4, 7, 9)
821
+		)
822
+		) {
823
+			return false;
824
+		}
825
+		$config_option_name = $this->_generate_config_option_name($section, $name);
826
+		// check if config object has been added to db by seeing if config option name is in $this->_addon_option_names array
827
+		if (! isset($this->_addon_option_names[$config_option_name])) {
828
+			// save new config to db
829
+			if ($this->set_config($section, $name, $config_class, $config_obj)) {
830
+				return true;
831
+			}
832
+		} else {
833
+			// first check if the record already exists
834
+			$existing_config = get_option($config_option_name);
835
+			$config_obj = serialize($config_obj);
836
+			// just return if db record is already up to date (NOT type safe comparison)
837
+			if ($existing_config == $config_obj) {
838
+				$this->{$section}->{$name} = $config_obj;
839
+				return true;
840
+			} else if (update_option($config_option_name, $config_obj)) {
841
+				EE_Config::log($config_option_name);
842
+				// update wp-option for this config class
843
+				$this->{$section}->{$name} = $config_obj;
844
+				return true;
845
+			} elseif ($throw_errors) {
846
+				EE_Error::add_error(
847
+					sprintf(
848
+						__(
849
+							'The "%1$s" object stored at"%2$s" was not successfully updated in the database.',
850
+							'event_espresso'
851
+						),
852
+						$config_class,
853
+						'EE_Config->' . $section . '->' . $name
854
+					),
855
+					__FILE__,
856
+					__FUNCTION__,
857
+					__LINE__
858
+				);
859
+			}
860
+		}
861
+		return false;
862
+	}
863
+
864
+
865
+
866
+	/**
867
+	 *    get_config
868
+	 *
869
+	 * @access    public
870
+	 * @param    string $section
871
+	 * @param    string $name
872
+	 * @param    string $config_class
873
+	 * @return    mixed EE_Config_Base | NULL
874
+	 */
875
+	public function get_config($section = '', $name = '', $config_class = '')
876
+	{
877
+		// ensure config class is set to something
878
+		$config_class = $this->_set_config_class($config_class, $name);
879
+		// run tests 1-4, 6 and 7 to verify that all params have been set
880
+		if (! $this->_verify_config_params($section, $name, $config_class, null, array(1, 2, 3, 4, 5, 6))) {
881
+			return null;
882
+		}
883
+		// now test if the requested config object exists, but suppress errors
884
+		if ($this->_verify_config_params($section, $name, $config_class, null, array(7, 8), false)) {
885
+			// config already exists, so pass it back
886
+			return $this->{$section}->{$name};
887
+		}
888
+		// load config option from db if it exists
889
+		$config_obj = $this->get_config_option($this->_generate_config_option_name($section, $name));
890
+		// verify the newly retrieved config object, but suppress errors
891
+		if ($this->_verify_config_params($section, $name, $config_class, $config_obj, array(9), false)) {
892
+			// config is good, so set it and pass it back
893
+			$this->{$section}->{$name} = $config_obj;
894
+			return $this->{$section}->{$name};
895
+		}
896
+		// oops! $config_obj is not already set and does not exist in the db, so create a new one
897
+		$config_obj = $this->set_config($section, $name, $config_class);
898
+		// verify the newly created config object
899
+		if ($this->_verify_config_params($section, $name, $config_class, $config_obj, array(9))) {
900
+			return $this->{$section}->{$name};
901
+		} else {
902
+			EE_Error::add_error(
903
+				sprintf(__('The "%s" could not be retrieved from the database.', 'event_espresso'), $config_class),
904
+				__FILE__,
905
+				__FUNCTION__,
906
+				__LINE__
907
+			);
908
+		}
909
+		return null;
910
+	}
911
+
912
+
913
+
914
+	/**
915
+	 *    get_config_option
916
+	 *
917
+	 * @access    public
918
+	 * @param    string $config_option_name
919
+	 * @return    mixed EE_Config_Base | FALSE
920
+	 */
921
+	public function get_config_option($config_option_name = '')
922
+	{
923
+		// retrieve the wp-option for this config class.
924
+		$config_option = maybe_unserialize(get_option($config_option_name, array()));
925
+		if (empty($config_option)) {
926
+			EE_Config::log($config_option_name . '-NOT-FOUND');
927
+		}
928
+		return $config_option;
929
+	}
930
+
931
+
932
+
933
+	/**
934
+	 * log
935
+	 *
936
+	 * @param string $config_option_name
937
+	 */
938
+	public static function log($config_option_name = '')
939
+	{
940
+		if (EE_Config::logging_enabled() && ! empty($config_option_name)) {
941
+			$config_log = get_option(EE_Config::LOG_NAME, array());
942
+			//copy incoming $_REQUEST and sanitize it so we can save it
943
+			$_request = $_REQUEST;
944
+			array_walk_recursive($_request, 'sanitize_text_field');
945
+			$config_log[(string)microtime(true)] = array(
946
+				'config_name' => $config_option_name,
947
+				'request'     => $_request,
948
+			);
949
+			update_option(EE_Config::LOG_NAME, $config_log);
950
+		}
951
+	}
952
+
953
+
954
+
955
+	/**
956
+	 * trim_log
957
+	 * reduces the size of the config log to the length specified by EE_Config::LOG_LENGTH
958
+	 */
959
+	public static function trim_log()
960
+	{
961
+		if (! EE_Config::logging_enabled()) {
962
+			return;
963
+		}
964
+		$config_log = maybe_unserialize(get_option(EE_Config::LOG_NAME, array()));
965
+		$log_length = count($config_log);
966
+		if ($log_length > EE_Config::LOG_LENGTH) {
967
+			ksort($config_log);
968
+			$config_log = array_slice($config_log, $log_length - EE_Config::LOG_LENGTH, null, true);
969
+			update_option(EE_Config::LOG_NAME, $config_log);
970
+		}
971
+	}
972
+
973
+
974
+
975
+	/**
976
+	 *    get_page_for_posts
977
+	 *    if the wp-option "show_on_front" is set to "page", then this is the post_name for the post set in the
978
+	 *    wp-option "page_for_posts", or "posts" if no page is selected
979
+	 *
980
+	 * @access    public
981
+	 * @return    string
982
+	 */
983
+	public static function get_page_for_posts()
984
+	{
985
+		$page_for_posts = get_option('page_for_posts');
986
+		if (! $page_for_posts) {
987
+			return 'posts';
988
+		}
989
+		/** @type WPDB $wpdb */
990
+		global $wpdb;
991
+		$SQL = "SELECT post_name from $wpdb->posts WHERE post_type='posts' OR post_type='page' AND post_status='publish' AND ID=%d";
992
+		return $wpdb->get_var($wpdb->prepare($SQL, $page_for_posts));
993
+	}
994
+
995
+
996
+
997
+	/**
998
+	 *    register_shortcodes_and_modules.
999
+	 *    At this point, it's too early to tell if we're maintenance mode or not.
1000
+	 *    In fact, this is where we give modules a chance to let core know they exist
1001
+	 *    so they can help trigger maintenance mode if it's needed
1002
+	 *
1003
+	 * @access    public
1004
+	 * @return    void
1005
+	 */
1006
+	public function register_shortcodes_and_modules()
1007
+	{
1008
+		// allow modules to set hooks for the rest of the system
1009
+		EE_Registry::instance()->modules = $this->_register_modules();
1010
+	}
1011
+
1012
+
1013
+
1014
+	/**
1015
+	 *    initialize_shortcodes_and_modules
1016
+	 *    meaning they can start adding their hooks to get stuff done
1017
+	 *
1018
+	 * @access    public
1019
+	 * @return    void
1020
+	 */
1021
+	public function initialize_shortcodes_and_modules()
1022
+	{
1023
+		// allow modules to set hooks for the rest of the system
1024
+		$this->_initialize_modules();
1025
+	}
1026
+
1027
+
1028
+
1029
+	/**
1030
+	 *    widgets_init
1031
+	 *
1032
+	 * @access private
1033
+	 * @return void
1034
+	 */
1035
+	public function widgets_init()
1036
+	{
1037
+		//only init widgets on admin pages when not in complete maintenance, and
1038
+		//on frontend when not in any maintenance mode
1039
+		if (
1040
+			! EE_Maintenance_Mode::instance()->level()
1041
+			|| (
1042
+				is_admin()
1043
+				&& EE_Maintenance_Mode::instance()->level() !== EE_Maintenance_Mode::level_2_complete_maintenance
1044
+			)
1045
+		) {
1046
+			// grab list of installed widgets
1047
+			$widgets_to_register = glob(EE_WIDGETS . '*', GLOB_ONLYDIR);
1048
+			// filter list of modules to register
1049
+			$widgets_to_register = apply_filters(
1050
+				'FHEE__EE_Config__register_widgets__widgets_to_register',
1051
+				$widgets_to_register
1052
+			);
1053
+			if (! empty($widgets_to_register)) {
1054
+				// cycle thru widget folders
1055
+				foreach ($widgets_to_register as $widget_path) {
1056
+					// add to list of installed widget modules
1057
+					EE_Config::register_ee_widget($widget_path);
1058
+				}
1059
+			}
1060
+			// filter list of installed modules
1061
+			EE_Registry::instance()->widgets = apply_filters(
1062
+				'FHEE__EE_Config__register_widgets__installed_widgets',
1063
+				EE_Registry::instance()->widgets
1064
+			);
1065
+		}
1066
+	}
1067
+
1068
+
1069
+
1070
+	/**
1071
+	 *    register_ee_widget - makes core aware of this widget
1072
+	 *
1073
+	 * @access    public
1074
+	 * @param    string $widget_path - full path up to and including widget folder
1075
+	 * @return    void
1076
+	 */
1077
+	public static function register_ee_widget($widget_path = null)
1078
+	{
1079
+		do_action('AHEE__EE_Config__register_widget__begin', $widget_path);
1080
+		$widget_ext = '.widget.php';
1081
+		// make all separators match
1082
+		$widget_path = rtrim(str_replace('/\\', DS, $widget_path), DS);
1083
+		// does the file path INCLUDE the actual file name as part of the path ?
1084
+		if (strpos($widget_path, $widget_ext) !== false) {
1085
+			// grab and shortcode file name from directory name and break apart at dots
1086
+			$file_name = explode('.', basename($widget_path));
1087
+			// take first segment from file name pieces and remove class prefix if it exists
1088
+			$widget = strpos($file_name[0], 'EEW_') === 0 ? substr($file_name[0], 4) : $file_name[0];
1089
+			// sanitize shortcode directory name
1090
+			$widget = sanitize_key($widget);
1091
+			// now we need to rebuild the shortcode path
1092
+			$widget_path = explode(DS, $widget_path);
1093
+			// remove last segment
1094
+			array_pop($widget_path);
1095
+			// glue it back together
1096
+			$widget_path = implode(DS, $widget_path);
1097
+		} else {
1098
+			// grab and sanitize widget directory name
1099
+			$widget = sanitize_key(basename($widget_path));
1100
+		}
1101
+		// create classname from widget directory name
1102
+		$widget = str_replace(' ', '_', ucwords(str_replace('_', ' ', $widget)));
1103
+		// add class prefix
1104
+		$widget_class = 'EEW_' . $widget;
1105
+		// does the widget exist ?
1106
+		if (! is_readable($widget_path . DS . $widget_class . $widget_ext)) {
1107
+			$msg = sprintf(
1108
+				__(
1109
+					'The requested %s widget file could not be found or is not readable due to file permissions. Please ensure the following path is correct: %s',
1110
+					'event_espresso'
1111
+				),
1112
+				$widget_class,
1113
+				$widget_path . DS . $widget_class . $widget_ext
1114
+			);
1115
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1116
+			return;
1117
+		}
1118
+		// load the widget class file
1119
+		require_once($widget_path . DS . $widget_class . $widget_ext);
1120
+		// verify that class exists
1121
+		if (! class_exists($widget_class)) {
1122
+			$msg = sprintf(__('The requested %s widget class does not exist.', 'event_espresso'), $widget_class);
1123
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1124
+			return;
1125
+		}
1126
+		register_widget($widget_class);
1127
+		// add to array of registered widgets
1128
+		EE_Registry::instance()->widgets->{$widget_class} = $widget_path . DS . $widget_class . $widget_ext;
1129
+	}
1130
+
1131
+
1132
+
1133
+	/**
1134
+	 *        _register_modules
1135
+	 *
1136
+	 * @access private
1137
+	 * @return array
1138
+	 */
1139
+	private function _register_modules()
1140
+	{
1141
+		// grab list of installed modules
1142
+		$modules_to_register = glob(EE_MODULES . '*', GLOB_ONLYDIR);
1143
+		// filter list of modules to register
1144
+		$modules_to_register = apply_filters(
1145
+			'FHEE__EE_Config__register_modules__modules_to_register',
1146
+			$modules_to_register
1147
+		);
1148
+		if (! empty($modules_to_register)) {
1149
+			// loop through folders
1150
+			foreach ($modules_to_register as $module_path) {
1151
+				/**TEMPORARILY EXCLUDE gateways from modules for time being**/
1152
+				if (
1153
+					$module_path !== EE_MODULES . 'zzz-copy-this-module-template'
1154
+					&& $module_path !== EE_MODULES . 'gateways'
1155
+				) {
1156
+					// add to list of installed modules
1157
+					EE_Config::register_module($module_path);
1158
+				}
1159
+			}
1160
+		}
1161
+		// filter list of installed modules
1162
+		return apply_filters(
1163
+			'FHEE__EE_Config___register_modules__installed_modules',
1164
+			EE_Registry::instance()->modules
1165
+		);
1166
+	}
1167
+
1168
+
1169
+
1170
+	/**
1171
+	 *    register_module - makes core aware of this module
1172
+	 *
1173
+	 * @access    public
1174
+	 * @param    string $module_path - full path up to and including module folder
1175
+	 * @return    bool
1176
+	 */
1177
+	public static function register_module($module_path = null)
1178
+	{
1179
+		do_action('AHEE__EE_Config__register_module__begin', $module_path);
1180
+		$module_ext = '.module.php';
1181
+		// make all separators match
1182
+		$module_path = str_replace(array('\\', '/'), DS, $module_path);
1183
+		// does the file path INCLUDE the actual file name as part of the path ?
1184
+		if (strpos($module_path, $module_ext) !== false) {
1185
+			// grab and shortcode file name from directory name and break apart at dots
1186
+			$module_file = explode('.', basename($module_path));
1187
+			// now we need to rebuild the shortcode path
1188
+			$module_path = explode(DS, $module_path);
1189
+			// remove last segment
1190
+			array_pop($module_path);
1191
+			// glue it back together
1192
+			$module_path = implode(DS, $module_path) . DS;
1193
+			// take first segment from file name pieces and sanitize it
1194
+			$module = preg_replace('/[^a-zA-Z0-9_\-]/', '', $module_file[0]);
1195
+			// ensure class prefix is added
1196
+			$module_class = strpos($module, 'EED_') !== 0 ? 'EED_' . $module : $module;
1197
+		} else {
1198
+			// we need to generate the filename based off of the folder name
1199
+			// grab and sanitize module name
1200
+			$module = strtolower(basename($module_path));
1201
+			$module = preg_replace('/[^a-z0-9_\-]/', '', $module);
1202
+			// like trailingslashit()
1203
+			$module_path = rtrim($module_path, DS) . DS;
1204
+			// create classname from module directory name
1205
+			$module = str_replace(' ', '_', ucwords(str_replace('_', ' ', $module)));
1206
+			// add class prefix
1207
+			$module_class = 'EED_' . $module;
1208
+		}
1209
+		// does the module exist ?
1210
+		if (! is_readable($module_path . DS . $module_class . $module_ext)) {
1211
+			$msg = sprintf(
1212
+				__(
1213
+					'The requested %s module file could not be found or is not readable due to file permissions.',
1214
+					'event_espresso'
1215
+				),
1216
+				$module
1217
+			);
1218
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1219
+			return false;
1220
+		}
1221
+		// load the module class file
1222
+		require_once($module_path . $module_class . $module_ext);
1223
+		// verify that class exists
1224
+		if (! class_exists($module_class)) {
1225
+			$msg = sprintf(__('The requested %s module class does not exist.', 'event_espresso'), $module_class);
1226
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1227
+			return false;
1228
+		}
1229
+		// add to array of registered modules
1230
+		EE_Registry::instance()->modules->{$module_class} = $module_path . $module_class . $module_ext;
1231
+		do_action(
1232
+			'AHEE__EE_Config__register_module__complete',
1233
+			$module_class,
1234
+			EE_Registry::instance()->modules->{$module_class}
1235
+		);
1236
+		return true;
1237
+	}
1238
+
1239
+
1240
+
1241
+	/**
1242
+	 *    _initialize_modules
1243
+	 *    allow modules to set hooks for the rest of the system
1244
+	 *
1245
+	 * @access private
1246
+	 * @return void
1247
+	 */
1248
+	private function _initialize_modules()
1249
+	{
1250
+		// cycle thru shortcode folders
1251
+		foreach (EE_Registry::instance()->modules as $module_class => $module_path) {
1252
+			// fire the shortcode class's set_hooks methods in case it needs to hook into other parts of the system
1253
+			// which set hooks ?
1254
+			if (is_admin()) {
1255
+				// fire immediately
1256
+				call_user_func(array($module_class, 'set_hooks_admin'));
1257
+			} else {
1258
+				// delay until other systems are online
1259
+				add_action(
1260
+					'AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons',
1261
+					array($module_class, 'set_hooks')
1262
+				);
1263
+			}
1264
+		}
1265
+	}
1266
+
1267
+
1268
+
1269
+	/**
1270
+	 *    register_route - adds module method routes to route_map
1271
+	 *
1272
+	 * @access    public
1273
+	 * @param    string $route       - "pretty" public alias for module method
1274
+	 * @param    string $module      - module name (classname without EED_ prefix)
1275
+	 * @param    string $method_name - the actual module method to be routed to
1276
+	 * @param    string $key         - url param key indicating a route is being called
1277
+	 * @return    bool
1278
+	 */
1279
+	public static function register_route($route = null, $module = null, $method_name = null, $key = 'ee')
1280
+	{
1281
+		do_action('AHEE__EE_Config__register_route__begin', $route, $module, $method_name);
1282
+		$module = str_replace('EED_', '', $module);
1283
+		$module_class = 'EED_' . $module;
1284
+		if (! isset(EE_Registry::instance()->modules->{$module_class})) {
1285
+			$msg = sprintf(__('The module %s has not been registered.', 'event_espresso'), $module);
1286
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1287
+			return false;
1288
+		}
1289
+		if (empty($route)) {
1290
+			$msg = sprintf(__('No route has been supplied.', 'event_espresso'), $route);
1291
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1292
+			return false;
1293
+		}
1294
+		if (! method_exists('EED_' . $module, $method_name)) {
1295
+			$msg = sprintf(
1296
+				__('A valid class method for the %s route has not been supplied.', 'event_espresso'),
1297
+				$route
1298
+			);
1299
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1300
+			return false;
1301
+		}
1302
+		EE_Config::$_module_route_map[$key][$route] = array('EED_' . $module, $method_name);
1303
+		return true;
1304
+	}
1305
+
1306
+
1307
+
1308
+	/**
1309
+	 *    get_route - get module method route
1310
+	 *
1311
+	 * @access    public
1312
+	 * @param    string $route - "pretty" public alias for module method
1313
+	 * @param    string $key   - url param key indicating a route is being called
1314
+	 * @return    string
1315
+	 */
1316
+	public static function get_route($route = null, $key = 'ee')
1317
+	{
1318
+		do_action('AHEE__EE_Config__get_route__begin', $route);
1319
+		$route = (string)apply_filters('FHEE__EE_Config__get_route', $route);
1320
+		if (isset(EE_Config::$_module_route_map[$key][$route])) {
1321
+			return EE_Config::$_module_route_map[$key][$route];
1322
+		}
1323
+		return null;
1324
+	}
1325
+
1326
+
1327
+
1328
+	/**
1329
+	 *    get_routes - get ALL module method routes
1330
+	 *
1331
+	 * @access    public
1332
+	 * @return    array
1333
+	 */
1334
+	public static function get_routes()
1335
+	{
1336
+		return EE_Config::$_module_route_map;
1337
+	}
1338
+
1339
+
1340
+
1341
+	/**
1342
+	 *    register_forward - allows modules to forward request to another module for further processing
1343
+	 *
1344
+	 * @access    public
1345
+	 * @param    string       $route   - "pretty" public alias for module method
1346
+	 * @param    integer      $status  - integer value corresponding  to status constant strings set in module parent
1347
+	 *                                 class, allows different forwards to be served based on status
1348
+	 * @param    array|string $forward - function name or array( class, method )
1349
+	 * @param    string       $key     - url param key indicating a route is being called
1350
+	 * @return    bool
1351
+	 */
1352
+	public static function register_forward($route = null, $status = 0, $forward = null, $key = 'ee')
1353
+	{
1354
+		do_action('AHEE__EE_Config__register_forward', $route, $status, $forward);
1355
+		if (! isset(EE_Config::$_module_route_map[$key][$route]) || empty($route)) {
1356
+			$msg = sprintf(
1357
+				__('The module route %s for this forward has not been registered.', 'event_espresso'),
1358
+				$route
1359
+			);
1360
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1361
+			return false;
1362
+		}
1363
+		if (empty($forward)) {
1364
+			$msg = sprintf(__('No forwarding route has been supplied.', 'event_espresso'), $route);
1365
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1366
+			return false;
1367
+		}
1368
+		if (is_array($forward)) {
1369
+			if (! isset($forward[1])) {
1370
+				$msg = sprintf(
1371
+					__('A class method for the %s forwarding route has not been supplied.', 'event_espresso'),
1372
+					$route
1373
+				);
1374
+				EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1375
+				return false;
1376
+			}
1377
+			if (! method_exists($forward[0], $forward[1])) {
1378
+				$msg = sprintf(
1379
+					__('The class method %s for the %s forwarding route is in invalid.', 'event_espresso'),
1380
+					$forward[1],
1381
+					$route
1382
+				);
1383
+				EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1384
+				return false;
1385
+			}
1386
+		} else if (! function_exists($forward)) {
1387
+			$msg = sprintf(
1388
+				__('The function %s for the %s forwarding route is in invalid.', 'event_espresso'),
1389
+				$forward,
1390
+				$route
1391
+			);
1392
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1393
+			return false;
1394
+		}
1395
+		EE_Config::$_module_forward_map[$key][$route][absint($status)] = $forward;
1396
+		return true;
1397
+	}
1398
+
1399
+
1400
+
1401
+	/**
1402
+	 *    get_forward - get forwarding route
1403
+	 *
1404
+	 * @access    public
1405
+	 * @param    string  $route  - "pretty" public alias for module method
1406
+	 * @param    integer $status - integer value corresponding  to status constant strings set in module parent class,
1407
+	 *                           allows different forwards to be served based on status
1408
+	 * @param    string  $key    - url param key indicating a route is being called
1409
+	 * @return    string
1410
+	 */
1411
+	public static function get_forward($route = null, $status = 0, $key = 'ee')
1412
+	{
1413
+		do_action('AHEE__EE_Config__get_forward__begin', $route, $status);
1414
+		if (isset(EE_Config::$_module_forward_map[$key][$route][$status])) {
1415
+			return apply_filters(
1416
+				'FHEE__EE_Config__get_forward',
1417
+				EE_Config::$_module_forward_map[$key][$route][$status],
1418
+				$route,
1419
+				$status
1420
+			);
1421
+		}
1422
+		return null;
1423
+	}
1424
+
1425
+
1426
+
1427
+	/**
1428
+	 *    register_forward - allows modules to specify different view templates for different method routes and status
1429
+	 *    results
1430
+	 *
1431
+	 * @access    public
1432
+	 * @param    string  $route  - "pretty" public alias for module method
1433
+	 * @param    integer $status - integer value corresponding  to status constant strings set in module parent class,
1434
+	 *                           allows different views to be served based on status
1435
+	 * @param    string  $view
1436
+	 * @param    string  $key    - url param key indicating a route is being called
1437
+	 * @return    bool
1438
+	 */
1439
+	public static function register_view($route = null, $status = 0, $view = null, $key = 'ee')
1440
+	{
1441
+		do_action('AHEE__EE_Config__register_view__begin', $route, $status, $view);
1442
+		if (! isset(EE_Config::$_module_route_map[$key][$route]) || empty($route)) {
1443
+			$msg = sprintf(
1444
+				__('The module route %s for this view has not been registered.', 'event_espresso'),
1445
+				$route
1446
+			);
1447
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1448
+			return false;
1449
+		}
1450
+		if (! is_readable($view)) {
1451
+			$msg = sprintf(
1452
+				__(
1453
+					'The %s view file could not be found or is not readable due to file permissions.',
1454
+					'event_espresso'
1455
+				),
1456
+				$view
1457
+			);
1458
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1459
+			return false;
1460
+		}
1461
+		EE_Config::$_module_view_map[$key][$route][absint($status)] = $view;
1462
+		return true;
1463
+	}
1464
+
1465
+
1466
+
1467
+	/**
1468
+	 *    get_view - get view for route and status
1469
+	 *
1470
+	 * @access    public
1471
+	 * @param    string  $route  - "pretty" public alias for module method
1472
+	 * @param    integer $status - integer value corresponding  to status constant strings set in module parent class,
1473
+	 *                           allows different views to be served based on status
1474
+	 * @param    string  $key    - url param key indicating a route is being called
1475
+	 * @return    string
1476
+	 */
1477
+	public static function get_view($route = null, $status = 0, $key = 'ee')
1478
+	{
1479
+		do_action('AHEE__EE_Config__get_view__begin', $route, $status);
1480
+		if (isset(EE_Config::$_module_view_map[$key][$route][$status])) {
1481
+			return apply_filters(
1482
+				'FHEE__EE_Config__get_view',
1483
+				EE_Config::$_module_view_map[$key][$route][$status],
1484
+				$route,
1485
+				$status
1486
+			);
1487
+		}
1488
+		return null;
1489
+	}
1490
+
1491
+
1492
+
1493
+	public function update_addon_option_names()
1494
+	{
1495
+		update_option(EE_Config::ADDON_OPTION_NAMES, $this->_addon_option_names);
1496
+	}
1497
+
1498
+
1499
+
1500
+	public function shutdown()
1501
+	{
1502
+		$this->update_addon_option_names();
1503
+	}
1504
+
1505
+
1506
+
1507
+	/**
1508
+	 * @return LegacyShortcodesManager
1509
+	 */
1510
+	public static function getLegacyShortcodesManager()
1511
+	{
1512
+
1513
+		if ( ! EE_Config::instance()->legacy_shortcodes_manager instanceof LegacyShortcodesManager) {
1514
+			EE_Config::instance()->legacy_shortcodes_manager = new LegacyShortcodesManager(
1515
+				EE_Registry::instance()
1516
+			);
1517
+		}
1518
+		return EE_Config::instance()->legacy_shortcodes_manager;
1519
+	}
1520
+
1521
+
1522
+
1523
+	/**
1524
+	 * register_shortcode - makes core aware of this shortcode
1525
+	 *
1526
+	 * @deprecated 4.9.26
1527
+	 * @param    string $shortcode_path - full path up to and including shortcode folder
1528
+	 * @return    bool
1529
+	 */
1530
+	public static function register_shortcode($shortcode_path = null)
1531
+	{
1532
+		EE_Error::doing_it_wrong(
1533
+			__METHOD__,
1534
+			__(
1535
+				'Usage is deprecated. Use \EventEspresso\core\services\shortcodes\LegacyShortcodesManager::registerShortcode() as direct replacement, or better yet, please see the new \EventEspresso\core\services\shortcodes\ShortcodesManager class.',
1536
+				'event_espresso'
1537
+			),
1538
+			'4.9.26'
1539
+		);
1540
+		return EE_Config::instance()->getLegacyShortcodesManager()->registerShortcode($shortcode_path);
1541
+	}
21 1542
 
22
-    const LOG_NAME           = 'ee_config_log';
23 1543
 
24
-    const LOG_LENGTH         = 100;
25 1544
 
26
-    const ADDON_OPTION_NAMES = 'ee_config_option_names';
27
-
28
-
29
-    /**
30
-     *    instance of the EE_Config object
31
-     *
32
-     * @var    EE_Config $_instance
33
-     * @access    private
34
-     */
35
-    private static $_instance;
36
-
37
-    /**
38
-     * @var boolean $_logging_enabled
39
-     */
40
-    private static $_logging_enabled = false;
41
-
42
-    /**
43
-     * @var LegacyShortcodesManager $legacy_shortcodes_manager
44
-     */
45
-    private $legacy_shortcodes_manager;
46
-
47
-    /**
48
-     * An StdClass whose property names are addon slugs,
49
-     * and values are their config classes
50
-     *
51
-     * @var StdClass
52
-     */
53
-    public $addons;
54
-
55
-    /**
56
-     * @var EE_Admin_Config
57
-     */
58
-    public $admin;
59
-
60
-    /**
61
-     * @var EE_Core_Config
62
-     */
63
-    public $core;
64
-
65
-    /**
66
-     * @var EE_Currency_Config
67
-     */
68
-    public $currency;
69
-
70
-    /**
71
-     * @var EE_Organization_Config
72
-     */
73
-    public $organization;
74
-
75
-    /**
76
-     * @var EE_Registration_Config
77
-     */
78
-    public $registration;
79
-
80
-    /**
81
-     * @var EE_Template_Config
82
-     */
83
-    public $template_settings;
84
-
85
-    /**
86
-     * Holds EE environment values.
87
-     *
88
-     * @var EE_Environment_Config
89
-     */
90
-    public $environment;
91
-
92
-    /**
93
-     * settings pertaining to Google maps
94
-     *
95
-     * @var EE_Map_Config
96
-     */
97
-    public $map_settings;
98
-
99
-    /**
100
-     * settings pertaining to Taxes
101
-     *
102
-     * @var EE_Tax_Config
103
-     */
104
-    public $tax_settings;
105
-
106
-
107
-    /**
108
-     * Settings pertaining to global messages settings.
109
-     *
110
-     * @var EE_Messages_Config
111
-     */
112
-    public $messages;
113
-
114
-    /**
115
-     * @deprecated
116
-     * @var EE_Gateway_Config
117
-     */
118
-    public $gateway;
119
-
120
-    /**
121
-     * @var    array $_addon_option_names
122
-     * @access    private
123
-     */
124
-    private $_addon_option_names = array();
125
-
126
-    /**
127
-     * @var    array $_module_route_map
128
-     * @access    private
129
-     */
130
-    private static $_module_route_map = array();
131
-
132
-    /**
133
-     * @var    array $_module_forward_map
134
-     * @access    private
135
-     */
136
-    private static $_module_forward_map = array();
137
-
138
-    /**
139
-     * @var    array $_module_view_map
140
-     * @access    private
141
-     */
142
-    private static $_module_view_map = array();
143
-
144
-
145
-
146
-    /**
147
-     * @singleton method used to instantiate class object
148
-     * @access    public
149
-     * @return EE_Config instance
150
-     */
151
-    public static function instance()
152
-    {
153
-        // check if class object is instantiated, and instantiated properly
154
-        if (! self::$_instance instanceof EE_Config) {
155
-            self::$_instance = new self();
156
-        }
157
-        return self::$_instance;
158
-    }
159
-
160
-
161
-
162
-    /**
163
-     * Resets the config
164
-     *
165
-     * @param bool    $hard_reset    if TRUE, sets EE_CONFig back to its original settings in the database. If FALSE
166
-     *                               (default) leaves the database alone, and merely resets the EE_Config object to
167
-     *                               reflect its state in the database
168
-     * @param boolean $reinstantiate if TRUE (default) call instance() and return it. Otherwise, just leave
169
-     *                               $_instance as NULL. Useful in case you want to forget about the old instance on
170
-     *                               EE_Config, but might not be ready to instantiate EE_Config currently (eg if the
171
-     *                               site was put into maintenance mode)
172
-     * @return EE_Config
173
-     */
174
-    public static function reset($hard_reset = false, $reinstantiate = true)
175
-    {
176
-        if (self::$_instance instanceof EE_Config) {
177
-            if ($hard_reset) {
178
-                self::$_instance->legacy_shortcodes_manager = null;
179
-                self::$_instance->_addon_option_names = array();
180
-                self::$_instance->_initialize_config();
181
-                self::$_instance->update_espresso_config();
182
-            }
183
-            self::$_instance->update_addon_option_names();
184
-        }
185
-        self::$_instance = null;
186
-        //we don't need to reset the static properties imo because those should
187
-        //only change when a module is added or removed. Currently we don't
188
-        //support removing a module during a request when it previously existed
189
-        if ($reinstantiate) {
190
-            return self::instance();
191
-        } else {
192
-            return null;
193
-        }
194
-    }
195
-
196
-
197
-
198
-    /**
199
-     *    class constructor
200
-     *
201
-     * @access    private
202
-     */
203
-    private function __construct()
204
-    {
205
-        do_action('AHEE__EE_Config__construct__begin', $this);
206
-        EE_Config::$_logging_enabled = apply_filters('FHEE__EE_Config___construct__logging_enabled', false);
207
-        // setup empty config classes
208
-        $this->_initialize_config();
209
-        // load existing EE site settings
210
-        $this->_load_core_config();
211
-        // confirm everything loaded correctly and set filtered defaults if not
212
-        $this->_verify_config();
213
-        //  register shortcodes and modules
214
-        add_action(
215
-            'AHEE__EE_System__register_shortcodes_modules_and_widgets',
216
-            array($this, 'register_shortcodes_and_modules'),
217
-            999
218
-        );
219
-        //  initialize shortcodes and modules
220
-        add_action('AHEE__EE_System__core_loaded_and_ready', array($this, 'initialize_shortcodes_and_modules'));
221
-        // register widgets
222
-        add_action('widgets_init', array($this, 'widgets_init'), 10);
223
-        // shutdown
224
-        add_action('shutdown', array($this, 'shutdown'), 10);
225
-        // construct__end hook
226
-        do_action('AHEE__EE_Config__construct__end', $this);
227
-        // hardcoded hack
228
-        $this->template_settings->current_espresso_theme = 'Espresso_Arabica_2014';
229
-    }
230
-
231
-
232
-
233
-    /**
234
-     * @return boolean
235
-     */
236
-    public static function logging_enabled()
237
-    {
238
-        return self::$_logging_enabled;
239
-    }
240
-
241
-
242
-
243
-    /**
244
-     * use to get the current theme if needed from static context
245
-     *
246
-     * @return string current theme set.
247
-     */
248
-    public static function get_current_theme()
249
-    {
250
-        return isset(self::$_instance->template_settings->current_espresso_theme)
251
-            ? self::$_instance->template_settings->current_espresso_theme : 'Espresso_Arabica_2014';
252
-    }
253
-
254
-
255
-
256
-    /**
257
-     *        _initialize_config
258
-     *
259
-     * @access private
260
-     * @return void
261
-     */
262
-    private function _initialize_config()
263
-    {
264
-        EE_Config::trim_log();
265
-        //set defaults
266
-        $this->_addon_option_names = get_option(EE_Config::ADDON_OPTION_NAMES, array());
267
-        $this->addons = new stdClass();
268
-        // set _module_route_map
269
-        EE_Config::$_module_route_map = array();
270
-        // set _module_forward_map
271
-        EE_Config::$_module_forward_map = array();
272
-        // set _module_view_map
273
-        EE_Config::$_module_view_map = array();
274
-    }
275
-
276
-
277
-
278
-    /**
279
-     *        load core plugin configuration
280
-     *
281
-     * @access private
282
-     * @return void
283
-     */
284
-    private function _load_core_config()
285
-    {
286
-        // load_core_config__start hook
287
-        do_action('AHEE__EE_Config___load_core_config__start', $this);
288
-        $espresso_config = $this->get_espresso_config();
289
-        foreach ($espresso_config as $config => $settings) {
290
-            // load_core_config__start hook
291
-            $settings = apply_filters(
292
-                'FHEE__EE_Config___load_core_config__config_settings',
293
-                $settings,
294
-                $config,
295
-                $this
296
-            );
297
-            if (is_object($settings) && property_exists($this, $config)) {
298
-                $this->{$config} = apply_filters('FHEE__EE_Config___load_core_config__' . $config, $settings);
299
-                //call configs populate method to ensure any defaults are set for empty values.
300
-                if (method_exists($settings, 'populate')) {
301
-                    $this->{$config}->populate();
302
-                }
303
-                if (method_exists($settings, 'do_hooks')) {
304
-                    $this->{$config}->do_hooks();
305
-                }
306
-            }
307
-        }
308
-        if (apply_filters('FHEE__EE_Config___load_core_config__update_espresso_config', false)) {
309
-            $this->update_espresso_config();
310
-        }
311
-        // load_core_config__end hook
312
-        do_action('AHEE__EE_Config___load_core_config__end', $this);
313
-    }
314
-
315
-
316
-
317
-    /**
318
-     *    _verify_config
319
-     *
320
-     * @access    protected
321
-     * @return    void
322
-     */
323
-    protected function _verify_config()
324
-    {
325
-        $this->core = $this->core instanceof EE_Core_Config
326
-            ? $this->core
327
-            : new EE_Core_Config();
328
-        $this->core = apply_filters('FHEE__EE_Config___initialize_config__core', $this->core);
329
-        $this->organization = $this->organization instanceof EE_Organization_Config
330
-            ? $this->organization
331
-            : new EE_Organization_Config();
332
-        $this->organization = apply_filters(
333
-            'FHEE__EE_Config___initialize_config__organization',
334
-            $this->organization
335
-        );
336
-        $this->currency = $this->currency instanceof EE_Currency_Config
337
-            ? $this->currency
338
-            : new EE_Currency_Config();
339
-        $this->currency = apply_filters('FHEE__EE_Config___initialize_config__currency', $this->currency);
340
-        $this->registration = $this->registration instanceof EE_Registration_Config
341
-            ? $this->registration
342
-            : new EE_Registration_Config();
343
-        $this->registration = apply_filters(
344
-            'FHEE__EE_Config___initialize_config__registration',
345
-            $this->registration
346
-        );
347
-        $this->admin = $this->admin instanceof EE_Admin_Config
348
-            ? $this->admin
349
-            : new EE_Admin_Config();
350
-        $this->admin = apply_filters('FHEE__EE_Config___initialize_config__admin', $this->admin);
351
-        $this->template_settings = $this->template_settings instanceof EE_Template_Config
352
-            ? $this->template_settings
353
-            : new EE_Template_Config();
354
-        $this->template_settings = apply_filters(
355
-            'FHEE__EE_Config___initialize_config__template_settings',
356
-            $this->template_settings
357
-        );
358
-        $this->map_settings = $this->map_settings instanceof EE_Map_Config
359
-            ? $this->map_settings
360
-            : new EE_Map_Config();
361
-        $this->map_settings = apply_filters('FHEE__EE_Config___initialize_config__map_settings',
362
-            $this->map_settings);
363
-        $this->environment = $this->environment instanceof EE_Environment_Config
364
-            ? $this->environment
365
-            : new EE_Environment_Config();
366
-        $this->environment = apply_filters('FHEE__EE_Config___initialize_config__environment',
367
-            $this->environment);
368
-        $this->tax_settings = $this->tax_settings instanceof EE_Tax_Config
369
-            ? $this->tax_settings
370
-            : new EE_Tax_Config();
371
-        $this->tax_settings = apply_filters('FHEE__EE_Config___initialize_config__tax_settings',
372
-            $this->tax_settings);
373
-        $this->messages = apply_filters('FHEE__EE_Config__initialize_config__messages', $this->messages);
374
-        $this->messages = $this->messages instanceof EE_Messages_Config
375
-            ? $this->messages
376
-            : new EE_Messages_Config();
377
-        $this->gateway = $this->gateway instanceof EE_Gateway_Config
378
-            ? $this->gateway
379
-            : new EE_Gateway_Config();
380
-        $this->gateway = apply_filters('FHEE__EE_Config___initialize_config__gateway', $this->gateway);
381
-        $this->legacy_shortcodes_manager = null;
382
-    }
383
-
384
-
385
-    /**
386
-     *    get_espresso_config
387
-     *
388
-     * @access    public
389
-     * @return    array of espresso config stuff
390
-     */
391
-    public function get_espresso_config()
392
-    {
393
-        // grab espresso configuration
394
-        return apply_filters(
395
-            'FHEE__EE_Config__get_espresso_config__CFG',
396
-            get_option(EE_Config::OPTION_NAME, array())
397
-        );
398
-    }
399
-
400
-
401
-
402
-    /**
403
-     *    double_check_config_comparison
404
-     *
405
-     * @access    public
406
-     * @param string $option
407
-     * @param        $old_value
408
-     * @param        $value
409
-     */
410
-    public function double_check_config_comparison($option = '', $old_value, $value)
411
-    {
412
-        // make sure we're checking the ee config
413
-        if ($option === EE_Config::OPTION_NAME) {
414
-            // run a loose comparison of the old value against the new value for type and properties,
415
-            // but NOT exact instance like WP update_option does (ie: NOT type safe comparison)
416
-            if ($value != $old_value) {
417
-                // if they are NOT the same, then remove the hook,
418
-                // which means the subsequent update results will be based solely on the update query results
419
-                // the reason we do this is because, as stated above,
420
-                // WP update_option performs an exact instance comparison (===) on any update values passed to it
421
-                // this happens PRIOR to serialization and any subsequent update.
422
-                // If values are found to match their previous old value,
423
-                // then WP bails before performing any update.
424
-                // Since we are passing the EE_Config object, it is comparing the EXACT instance of the saved version
425
-                // it just pulled from the db, with the one being passed to it (which will not match).
426
-                // HOWEVER, once the object is serialized and passed off to MySQL to update,
427
-                // MySQL MAY ALSO NOT perform the update because
428
-                // the string it sees in the db looks the same as the new one it has been passed!!!
429
-                // This results in the query returning an "affected rows" value of ZERO,
430
-                // which gets returned immediately by WP update_option and looks like an error.
431
-                remove_action('update_option', array($this, 'check_config_updated'));
432
-            }
433
-        }
434
-    }
435
-
436
-
437
-
438
-    /**
439
-     *    update_espresso_config
440
-     *
441
-     * @access   public
442
-     */
443
-    protected function _reset_espresso_addon_config()
444
-    {
445
-        $this->_addon_option_names = array();
446
-        foreach ($this->addons as $addon_name => $addon_config_obj) {
447
-            $addon_config_obj = maybe_unserialize($addon_config_obj);
448
-            $config_class = get_class($addon_config_obj);
449
-            if ($addon_config_obj instanceof $config_class && ! $addon_config_obj instanceof __PHP_Incomplete_Class) {
450
-                $this->update_config('addons', $addon_name, $addon_config_obj, false);
451
-            }
452
-            $this->addons->{$addon_name} = null;
453
-        }
454
-    }
455
-
456
-
457
-
458
-    /**
459
-     *    update_espresso_config
460
-     *
461
-     * @access   public
462
-     * @param   bool $add_success
463
-     * @param   bool $add_error
464
-     * @return   bool
465
-     */
466
-    public function update_espresso_config($add_success = false, $add_error = true)
467
-    {
468
-        // don't allow config updates during WP heartbeats
469
-        if (\EE_Registry::instance()->REQ->get('action', '') === 'heartbeat') {
470
-            return false;
471
-        }
472
-        // commented out the following re: https://events.codebasehq.com/projects/event-espresso/tickets/8197
473
-        //$clone = clone( self::$_instance );
474
-        //self::$_instance = NULL;
475
-        do_action('AHEE__EE_Config__update_espresso_config__begin', $this);
476
-        $this->_reset_espresso_addon_config();
477
-        // hook into update_option because that happens AFTER the ( $value === $old_value ) conditional
478
-        // but BEFORE the actual update occurs
479
-        add_action('update_option', array($this, 'double_check_config_comparison'), 1, 3);
480
-        // don't want to persist legacy_shortcodes_manager, but don't want to lose it either
481
-        $legacy_shortcodes_manager = $this->legacy_shortcodes_manager;
482
-        $this->legacy_shortcodes_manager = null;
483
-        // now update "ee_config"
484
-        $saved = update_option(EE_Config::OPTION_NAME, $this);
485
-        $this->legacy_shortcodes_manager = $legacy_shortcodes_manager;
486
-        EE_Config::log(EE_Config::OPTION_NAME);
487
-        // if not saved... check if the hook we just added still exists;
488
-        // if it does, it means one of two things:
489
-        // 		that update_option bailed at the ( $value === $old_value ) conditional,
490
-        //		 or...
491
-        // 		the db update query returned 0 rows affected
492
-        // 		(probably because the data  value was the same from it's perspective)
493
-        // so the existence of the hook means that a negative result from update_option is NOT an error,
494
-        // but just means no update occurred, so don't display an error to the user.
495
-        // BUT... if update_option returns FALSE, AND the hook is missing,
496
-        // then it means that something truly went wrong
497
-        $saved = ! $saved ? has_action('update_option', array($this, 'double_check_config_comparison')) : $saved;
498
-        // remove our action since we don't want it in the system anymore
499
-        remove_action('update_option', array($this, 'double_check_config_comparison'), 1);
500
-        do_action('AHEE__EE_Config__update_espresso_config__end', $this, $saved);
501
-        //self::$_instance = $clone;
502
-        //unset( $clone );
503
-        // if config remains the same or was updated successfully
504
-        if ($saved) {
505
-            if ($add_success) {
506
-                EE_Error::add_success(
507
-                    __('The Event Espresso Configuration Settings have been successfully updated.', 'event_espresso'),
508
-                    __FILE__,
509
-                    __FUNCTION__,
510
-                    __LINE__
511
-                );
512
-            }
513
-            return true;
514
-        } else {
515
-            if ($add_error) {
516
-                EE_Error::add_error(
517
-                    __('The Event Espresso Configuration Settings were not updated.', 'event_espresso'),
518
-                    __FILE__,
519
-                    __FUNCTION__,
520
-                    __LINE__
521
-                );
522
-            }
523
-            return false;
524
-        }
525
-    }
526
-
527
-
528
-
529
-    /**
530
-     *    _verify_config_params
531
-     *
532
-     * @access    private
533
-     * @param    string         $section
534
-     * @param    string         $name
535
-     * @param    string         $config_class
536
-     * @param    EE_Config_Base $config_obj
537
-     * @param    array          $tests_to_run
538
-     * @param    bool           $display_errors
539
-     * @return    bool    TRUE on success, FALSE on fail
540
-     */
541
-    private function _verify_config_params(
542
-        $section = '',
543
-        $name = '',
544
-        $config_class = '',
545
-        $config_obj = null,
546
-        $tests_to_run = array(1, 2, 3, 4, 5, 6, 7, 8),
547
-        $display_errors = true
548
-    ) {
549
-        try {
550
-            foreach ($tests_to_run as $test) {
551
-                switch ($test) {
552
-                    // TEST #1 : check that section was set
553
-                    case 1 :
554
-                        if (empty($section)) {
555
-                            if ($display_errors) {
556
-                                throw new EE_Error(
557
-                                    sprintf(
558
-                                        __(
559
-                                            'No configuration section has been provided while attempting to save "%s".',
560
-                                            'event_espresso'
561
-                                        ),
562
-                                        $config_class
563
-                                    )
564
-                                );
565
-                            }
566
-                            return false;
567
-                        }
568
-                        break;
569
-                    // TEST #2 : check that settings section exists
570
-                    case 2 :
571
-                        if (! isset($this->{$section})) {
572
-                            if ($display_errors) {
573
-                                throw new EE_Error(
574
-                                    sprintf(
575
-                                        __('The "%s" configuration section does not exist.', 'event_espresso'),
576
-                                        $section
577
-                                    )
578
-                                );
579
-                            }
580
-                            return false;
581
-                        }
582
-                        break;
583
-                    // TEST #3 : check that section is the proper format
584
-                    case 3 :
585
-                        if (
586
-                        ! ($this->{$section} instanceof EE_Config_Base || $this->{$section} instanceof stdClass)
587
-                        ) {
588
-                            if ($display_errors) {
589
-                                throw new EE_Error(
590
-                                    sprintf(
591
-                                        __(
592
-                                            'The "%s" configuration settings have not been formatted correctly.',
593
-                                            'event_espresso'
594
-                                        ),
595
-                                        $section
596
-                                    )
597
-                                );
598
-                            }
599
-                            return false;
600
-                        }
601
-                        break;
602
-                    // TEST #4 : check that config section name has been set
603
-                    case 4 :
604
-                        if (empty($name)) {
605
-                            if ($display_errors) {
606
-                                throw new EE_Error(
607
-                                    __(
608
-                                        'No name has been provided for the specific configuration section.',
609
-                                        'event_espresso'
610
-                                    )
611
-                                );
612
-                            }
613
-                            return false;
614
-                        }
615
-                        break;
616
-                    // TEST #5 : check that a config class name has been set
617
-                    case 5 :
618
-                        if (empty($config_class)) {
619
-                            if ($display_errors) {
620
-                                throw new EE_Error(
621
-                                    __(
622
-                                        'No class name has been provided for the specific configuration section.',
623
-                                        'event_espresso'
624
-                                    )
625
-                                );
626
-                            }
627
-                            return false;
628
-                        }
629
-                        break;
630
-                    // TEST #6 : verify config class is accessible
631
-                    case 6 :
632
-                        if (! class_exists($config_class)) {
633
-                            if ($display_errors) {
634
-                                throw new EE_Error(
635
-                                    sprintf(
636
-                                        __(
637
-                                            'The "%s" class does not exist. Please ensure that an autoloader has been set for it.',
638
-                                            'event_espresso'
639
-                                        ),
640
-                                        $config_class
641
-                                    )
642
-                                );
643
-                            }
644
-                            return false;
645
-                        }
646
-                        break;
647
-                    // TEST #7 : check that config has even been set
648
-                    case 7 :
649
-                        if (! isset($this->{$section}->{$name})) {
650
-                            if ($display_errors) {
651
-                                throw new EE_Error(
652
-                                    sprintf(
653
-                                        __('No configuration has been set for "%1$s->%2$s".', 'event_espresso'),
654
-                                        $section,
655
-                                        $name
656
-                                    )
657
-                                );
658
-                            }
659
-                            return false;
660
-                        } else {
661
-                            // and make sure it's not serialized
662
-                            $this->{$section}->{$name} = maybe_unserialize($this->{$section}->{$name});
663
-                        }
664
-                        break;
665
-                    // TEST #8 : check that config is the requested type
666
-                    case 8 :
667
-                        if (! $this->{$section}->{$name} instanceof $config_class) {
668
-                            if ($display_errors) {
669
-                                throw new EE_Error(
670
-                                    sprintf(
671
-                                        __(
672
-                                            'The configuration for "%1$s->%2$s" is not of the "%3$s" class.',
673
-                                            'event_espresso'
674
-                                        ),
675
-                                        $section,
676
-                                        $name,
677
-                                        $config_class
678
-                                    )
679
-                                );
680
-                            }
681
-                            return false;
682
-                        }
683
-                        break;
684
-                    // TEST #9 : verify config object
685
-                    case 9 :
686
-                        if (! $config_obj instanceof EE_Config_Base) {
687
-                            if ($display_errors) {
688
-                                throw new EE_Error(
689
-                                    sprintf(
690
-                                        __('The "%s" class is not an instance of EE_Config_Base.', 'event_espresso'),
691
-                                        print_r($config_obj, true)
692
-                                    )
693
-                                );
694
-                            }
695
-                            return false;
696
-                        }
697
-                        break;
698
-                }
699
-            }
700
-        } catch (EE_Error $e) {
701
-            $e->get_error();
702
-        }
703
-        // you have successfully run the gauntlet
704
-        return true;
705
-    }
706
-
707
-
708
-
709
-    /**
710
-     *    _generate_config_option_name
711
-     *
712
-     * @access        protected
713
-     * @param        string $section
714
-     * @param        string $name
715
-     * @return        string
716
-     */
717
-    private function _generate_config_option_name($section = '', $name = '')
718
-    {
719
-        return 'ee_config-' . strtolower($section . '-' . str_replace(array('EE_', 'EED_'), '', $name));
720
-    }
721
-
722
-
723
-
724
-    /**
725
-     *    _set_config_class
726
-     * ensures that a config class is set, either from a passed config class or one generated from the config name
727
-     *
728
-     * @access    private
729
-     * @param    string $config_class
730
-     * @param    string $name
731
-     * @return    string
732
-     */
733
-    private function _set_config_class($config_class = '', $name = '')
734
-    {
735
-        return ! empty($config_class)
736
-            ? $config_class
737
-            : str_replace(' ', '_', ucwords(str_replace('_', ' ', $name))) . '_Config';
738
-    }
739
-
740
-
741
-
742
-    /**
743
-     *    set_config
744
-     *
745
-     * @access    protected
746
-     * @param    string         $section
747
-     * @param    string         $name
748
-     * @param    string         $config_class
749
-     * @param    EE_Config_Base $config_obj
750
-     * @return    EE_Config_Base
751
-     */
752
-    public function set_config($section = '', $name = '', $config_class = '', EE_Config_Base $config_obj = null)
753
-    {
754
-        // ensure config class is set to something
755
-        $config_class = $this->_set_config_class($config_class, $name);
756
-        // run tests 1-4, 6, and 7 to verify all config params are set and valid
757
-        if (! $this->_verify_config_params($section, $name, $config_class, null, array(1, 2, 3, 4, 5, 6))) {
758
-            return null;
759
-        }
760
-        $config_option_name = $this->_generate_config_option_name($section, $name);
761
-        // if the config option name hasn't been added yet to the list of option names we're tracking, then do so now
762
-        if (! isset($this->_addon_option_names[$config_option_name])) {
763
-            $this->_addon_option_names[$config_option_name] = $config_class;
764
-            $this->update_addon_option_names();
765
-        }
766
-        // verify the incoming config object but suppress errors
767
-        if (! $this->_verify_config_params($section, $name, $config_class, $config_obj, array(9), false)) {
768
-            $config_obj = new $config_class();
769
-        }
770
-        if (get_option($config_option_name)) {
771
-            EE_Config::log($config_option_name);
772
-            update_option($config_option_name, $config_obj);
773
-            $this->{$section}->{$name} = $config_obj;
774
-            return $this->{$section}->{$name};
775
-        } else {
776
-            // create a wp-option for this config
777
-            if (add_option($config_option_name, $config_obj, '', 'no')) {
778
-                $this->{$section}->{$name} = maybe_unserialize($config_obj);
779
-                return $this->{$section}->{$name};
780
-            } else {
781
-                EE_Error::add_error(
782
-                    sprintf(__('The "%s" could not be saved to the database.', 'event_espresso'), $config_class),
783
-                    __FILE__,
784
-                    __FUNCTION__,
785
-                    __LINE__
786
-                );
787
-                return null;
788
-            }
789
-        }
790
-    }
791
-
792
-
793
-
794
-    /**
795
-     *    update_config
796
-     * Important: the config object must ALREADY be set, otherwise this will produce an error.
797
-     *
798
-     * @access    public
799
-     * @param    string                $section
800
-     * @param    string                $name
801
-     * @param    EE_Config_Base|string $config_obj
802
-     * @param    bool                  $throw_errors
803
-     * @return    bool
804
-     */
805
-    public function update_config($section = '', $name = '', $config_obj = '', $throw_errors = true)
806
-    {
807
-        // don't allow config updates during WP heartbeats
808
-        if (\EE_Registry::instance()->REQ->get('action', '') === 'heartbeat') {
809
-            return false;
810
-        }
811
-        $config_obj = maybe_unserialize($config_obj);
812
-        // get class name of the incoming object
813
-        $config_class = get_class($config_obj);
814
-        // run tests 1-5 and 9 to verify config
815
-        if (! $this->_verify_config_params(
816
-            $section,
817
-            $name,
818
-            $config_class,
819
-            $config_obj,
820
-            array(1, 2, 3, 4, 7, 9)
821
-        )
822
-        ) {
823
-            return false;
824
-        }
825
-        $config_option_name = $this->_generate_config_option_name($section, $name);
826
-        // check if config object has been added to db by seeing if config option name is in $this->_addon_option_names array
827
-        if (! isset($this->_addon_option_names[$config_option_name])) {
828
-            // save new config to db
829
-            if ($this->set_config($section, $name, $config_class, $config_obj)) {
830
-                return true;
831
-            }
832
-        } else {
833
-            // first check if the record already exists
834
-            $existing_config = get_option($config_option_name);
835
-            $config_obj = serialize($config_obj);
836
-            // just return if db record is already up to date (NOT type safe comparison)
837
-            if ($existing_config == $config_obj) {
838
-                $this->{$section}->{$name} = $config_obj;
839
-                return true;
840
-            } else if (update_option($config_option_name, $config_obj)) {
841
-                EE_Config::log($config_option_name);
842
-                // update wp-option for this config class
843
-                $this->{$section}->{$name} = $config_obj;
844
-                return true;
845
-            } elseif ($throw_errors) {
846
-                EE_Error::add_error(
847
-                    sprintf(
848
-                        __(
849
-                            'The "%1$s" object stored at"%2$s" was not successfully updated in the database.',
850
-                            'event_espresso'
851
-                        ),
852
-                        $config_class,
853
-                        'EE_Config->' . $section . '->' . $name
854
-                    ),
855
-                    __FILE__,
856
-                    __FUNCTION__,
857
-                    __LINE__
858
-                );
859
-            }
860
-        }
861
-        return false;
862
-    }
863
-
864
-
865
-
866
-    /**
867
-     *    get_config
868
-     *
869
-     * @access    public
870
-     * @param    string $section
871
-     * @param    string $name
872
-     * @param    string $config_class
873
-     * @return    mixed EE_Config_Base | NULL
874
-     */
875
-    public function get_config($section = '', $name = '', $config_class = '')
876
-    {
877
-        // ensure config class is set to something
878
-        $config_class = $this->_set_config_class($config_class, $name);
879
-        // run tests 1-4, 6 and 7 to verify that all params have been set
880
-        if (! $this->_verify_config_params($section, $name, $config_class, null, array(1, 2, 3, 4, 5, 6))) {
881
-            return null;
882
-        }
883
-        // now test if the requested config object exists, but suppress errors
884
-        if ($this->_verify_config_params($section, $name, $config_class, null, array(7, 8), false)) {
885
-            // config already exists, so pass it back
886
-            return $this->{$section}->{$name};
887
-        }
888
-        // load config option from db if it exists
889
-        $config_obj = $this->get_config_option($this->_generate_config_option_name($section, $name));
890
-        // verify the newly retrieved config object, but suppress errors
891
-        if ($this->_verify_config_params($section, $name, $config_class, $config_obj, array(9), false)) {
892
-            // config is good, so set it and pass it back
893
-            $this->{$section}->{$name} = $config_obj;
894
-            return $this->{$section}->{$name};
895
-        }
896
-        // oops! $config_obj is not already set and does not exist in the db, so create a new one
897
-        $config_obj = $this->set_config($section, $name, $config_class);
898
-        // verify the newly created config object
899
-        if ($this->_verify_config_params($section, $name, $config_class, $config_obj, array(9))) {
900
-            return $this->{$section}->{$name};
901
-        } else {
902
-            EE_Error::add_error(
903
-                sprintf(__('The "%s" could not be retrieved from the database.', 'event_espresso'), $config_class),
904
-                __FILE__,
905
-                __FUNCTION__,
906
-                __LINE__
907
-            );
908
-        }
909
-        return null;
910
-    }
911
-
912
-
913
-
914
-    /**
915
-     *    get_config_option
916
-     *
917
-     * @access    public
918
-     * @param    string $config_option_name
919
-     * @return    mixed EE_Config_Base | FALSE
920
-     */
921
-    public function get_config_option($config_option_name = '')
922
-    {
923
-        // retrieve the wp-option for this config class.
924
-        $config_option = maybe_unserialize(get_option($config_option_name, array()));
925
-        if (empty($config_option)) {
926
-            EE_Config::log($config_option_name . '-NOT-FOUND');
927
-        }
928
-        return $config_option;
929
-    }
930
-
931
-
932
-
933
-    /**
934
-     * log
935
-     *
936
-     * @param string $config_option_name
937
-     */
938
-    public static function log($config_option_name = '')
939
-    {
940
-        if (EE_Config::logging_enabled() && ! empty($config_option_name)) {
941
-            $config_log = get_option(EE_Config::LOG_NAME, array());
942
-            //copy incoming $_REQUEST and sanitize it so we can save it
943
-            $_request = $_REQUEST;
944
-            array_walk_recursive($_request, 'sanitize_text_field');
945
-            $config_log[(string)microtime(true)] = array(
946
-                'config_name' => $config_option_name,
947
-                'request'     => $_request,
948
-            );
949
-            update_option(EE_Config::LOG_NAME, $config_log);
950
-        }
951
-    }
952
-
953
-
954
-
955
-    /**
956
-     * trim_log
957
-     * reduces the size of the config log to the length specified by EE_Config::LOG_LENGTH
958
-     */
959
-    public static function trim_log()
960
-    {
961
-        if (! EE_Config::logging_enabled()) {
962
-            return;
963
-        }
964
-        $config_log = maybe_unserialize(get_option(EE_Config::LOG_NAME, array()));
965
-        $log_length = count($config_log);
966
-        if ($log_length > EE_Config::LOG_LENGTH) {
967
-            ksort($config_log);
968
-            $config_log = array_slice($config_log, $log_length - EE_Config::LOG_LENGTH, null, true);
969
-            update_option(EE_Config::LOG_NAME, $config_log);
970
-        }
971
-    }
972
-
973
-
974
-
975
-    /**
976
-     *    get_page_for_posts
977
-     *    if the wp-option "show_on_front" is set to "page", then this is the post_name for the post set in the
978
-     *    wp-option "page_for_posts", or "posts" if no page is selected
979
-     *
980
-     * @access    public
981
-     * @return    string
982
-     */
983
-    public static function get_page_for_posts()
984
-    {
985
-        $page_for_posts = get_option('page_for_posts');
986
-        if (! $page_for_posts) {
987
-            return 'posts';
988
-        }
989
-        /** @type WPDB $wpdb */
990
-        global $wpdb;
991
-        $SQL = "SELECT post_name from $wpdb->posts WHERE post_type='posts' OR post_type='page' AND post_status='publish' AND ID=%d";
992
-        return $wpdb->get_var($wpdb->prepare($SQL, $page_for_posts));
993
-    }
994
-
995
-
996
-
997
-    /**
998
-     *    register_shortcodes_and_modules.
999
-     *    At this point, it's too early to tell if we're maintenance mode or not.
1000
-     *    In fact, this is where we give modules a chance to let core know they exist
1001
-     *    so they can help trigger maintenance mode if it's needed
1002
-     *
1003
-     * @access    public
1004
-     * @return    void
1005
-     */
1006
-    public function register_shortcodes_and_modules()
1007
-    {
1008
-        // allow modules to set hooks for the rest of the system
1009
-        EE_Registry::instance()->modules = $this->_register_modules();
1010
-    }
1011
-
1012
-
1013
-
1014
-    /**
1015
-     *    initialize_shortcodes_and_modules
1016
-     *    meaning they can start adding their hooks to get stuff done
1017
-     *
1018
-     * @access    public
1019
-     * @return    void
1020
-     */
1021
-    public function initialize_shortcodes_and_modules()
1022
-    {
1023
-        // allow modules to set hooks for the rest of the system
1024
-        $this->_initialize_modules();
1025
-    }
1026
-
1027
-
1028
-
1029
-    /**
1030
-     *    widgets_init
1031
-     *
1032
-     * @access private
1033
-     * @return void
1034
-     */
1035
-    public function widgets_init()
1036
-    {
1037
-        //only init widgets on admin pages when not in complete maintenance, and
1038
-        //on frontend when not in any maintenance mode
1039
-        if (
1040
-            ! EE_Maintenance_Mode::instance()->level()
1041
-            || (
1042
-                is_admin()
1043
-                && EE_Maintenance_Mode::instance()->level() !== EE_Maintenance_Mode::level_2_complete_maintenance
1044
-            )
1045
-        ) {
1046
-            // grab list of installed widgets
1047
-            $widgets_to_register = glob(EE_WIDGETS . '*', GLOB_ONLYDIR);
1048
-            // filter list of modules to register
1049
-            $widgets_to_register = apply_filters(
1050
-                'FHEE__EE_Config__register_widgets__widgets_to_register',
1051
-                $widgets_to_register
1052
-            );
1053
-            if (! empty($widgets_to_register)) {
1054
-                // cycle thru widget folders
1055
-                foreach ($widgets_to_register as $widget_path) {
1056
-                    // add to list of installed widget modules
1057
-                    EE_Config::register_ee_widget($widget_path);
1058
-                }
1059
-            }
1060
-            // filter list of installed modules
1061
-            EE_Registry::instance()->widgets = apply_filters(
1062
-                'FHEE__EE_Config__register_widgets__installed_widgets',
1063
-                EE_Registry::instance()->widgets
1064
-            );
1065
-        }
1066
-    }
1067
-
1068
-
1069
-
1070
-    /**
1071
-     *    register_ee_widget - makes core aware of this widget
1072
-     *
1073
-     * @access    public
1074
-     * @param    string $widget_path - full path up to and including widget folder
1075
-     * @return    void
1076
-     */
1077
-    public static function register_ee_widget($widget_path = null)
1078
-    {
1079
-        do_action('AHEE__EE_Config__register_widget__begin', $widget_path);
1080
-        $widget_ext = '.widget.php';
1081
-        // make all separators match
1082
-        $widget_path = rtrim(str_replace('/\\', DS, $widget_path), DS);
1083
-        // does the file path INCLUDE the actual file name as part of the path ?
1084
-        if (strpos($widget_path, $widget_ext) !== false) {
1085
-            // grab and shortcode file name from directory name and break apart at dots
1086
-            $file_name = explode('.', basename($widget_path));
1087
-            // take first segment from file name pieces and remove class prefix if it exists
1088
-            $widget = strpos($file_name[0], 'EEW_') === 0 ? substr($file_name[0], 4) : $file_name[0];
1089
-            // sanitize shortcode directory name
1090
-            $widget = sanitize_key($widget);
1091
-            // now we need to rebuild the shortcode path
1092
-            $widget_path = explode(DS, $widget_path);
1093
-            // remove last segment
1094
-            array_pop($widget_path);
1095
-            // glue it back together
1096
-            $widget_path = implode(DS, $widget_path);
1097
-        } else {
1098
-            // grab and sanitize widget directory name
1099
-            $widget = sanitize_key(basename($widget_path));
1100
-        }
1101
-        // create classname from widget directory name
1102
-        $widget = str_replace(' ', '_', ucwords(str_replace('_', ' ', $widget)));
1103
-        // add class prefix
1104
-        $widget_class = 'EEW_' . $widget;
1105
-        // does the widget exist ?
1106
-        if (! is_readable($widget_path . DS . $widget_class . $widget_ext)) {
1107
-            $msg = sprintf(
1108
-                __(
1109
-                    'The requested %s widget file could not be found or is not readable due to file permissions. Please ensure the following path is correct: %s',
1110
-                    'event_espresso'
1111
-                ),
1112
-                $widget_class,
1113
-                $widget_path . DS . $widget_class . $widget_ext
1114
-            );
1115
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1116
-            return;
1117
-        }
1118
-        // load the widget class file
1119
-        require_once($widget_path . DS . $widget_class . $widget_ext);
1120
-        // verify that class exists
1121
-        if (! class_exists($widget_class)) {
1122
-            $msg = sprintf(__('The requested %s widget class does not exist.', 'event_espresso'), $widget_class);
1123
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1124
-            return;
1125
-        }
1126
-        register_widget($widget_class);
1127
-        // add to array of registered widgets
1128
-        EE_Registry::instance()->widgets->{$widget_class} = $widget_path . DS . $widget_class . $widget_ext;
1129
-    }
1130
-
1131
-
1132
-
1133
-    /**
1134
-     *        _register_modules
1135
-     *
1136
-     * @access private
1137
-     * @return array
1138
-     */
1139
-    private function _register_modules()
1140
-    {
1141
-        // grab list of installed modules
1142
-        $modules_to_register = glob(EE_MODULES . '*', GLOB_ONLYDIR);
1143
-        // filter list of modules to register
1144
-        $modules_to_register = apply_filters(
1145
-            'FHEE__EE_Config__register_modules__modules_to_register',
1146
-            $modules_to_register
1147
-        );
1148
-        if (! empty($modules_to_register)) {
1149
-            // loop through folders
1150
-            foreach ($modules_to_register as $module_path) {
1151
-                /**TEMPORARILY EXCLUDE gateways from modules for time being**/
1152
-                if (
1153
-                    $module_path !== EE_MODULES . 'zzz-copy-this-module-template'
1154
-                    && $module_path !== EE_MODULES . 'gateways'
1155
-                ) {
1156
-                    // add to list of installed modules
1157
-                    EE_Config::register_module($module_path);
1158
-                }
1159
-            }
1160
-        }
1161
-        // filter list of installed modules
1162
-        return apply_filters(
1163
-            'FHEE__EE_Config___register_modules__installed_modules',
1164
-            EE_Registry::instance()->modules
1165
-        );
1166
-    }
1167
-
1168
-
1169
-
1170
-    /**
1171
-     *    register_module - makes core aware of this module
1172
-     *
1173
-     * @access    public
1174
-     * @param    string $module_path - full path up to and including module folder
1175
-     * @return    bool
1176
-     */
1177
-    public static function register_module($module_path = null)
1178
-    {
1179
-        do_action('AHEE__EE_Config__register_module__begin', $module_path);
1180
-        $module_ext = '.module.php';
1181
-        // make all separators match
1182
-        $module_path = str_replace(array('\\', '/'), DS, $module_path);
1183
-        // does the file path INCLUDE the actual file name as part of the path ?
1184
-        if (strpos($module_path, $module_ext) !== false) {
1185
-            // grab and shortcode file name from directory name and break apart at dots
1186
-            $module_file = explode('.', basename($module_path));
1187
-            // now we need to rebuild the shortcode path
1188
-            $module_path = explode(DS, $module_path);
1189
-            // remove last segment
1190
-            array_pop($module_path);
1191
-            // glue it back together
1192
-            $module_path = implode(DS, $module_path) . DS;
1193
-            // take first segment from file name pieces and sanitize it
1194
-            $module = preg_replace('/[^a-zA-Z0-9_\-]/', '', $module_file[0]);
1195
-            // ensure class prefix is added
1196
-            $module_class = strpos($module, 'EED_') !== 0 ? 'EED_' . $module : $module;
1197
-        } else {
1198
-            // we need to generate the filename based off of the folder name
1199
-            // grab and sanitize module name
1200
-            $module = strtolower(basename($module_path));
1201
-            $module = preg_replace('/[^a-z0-9_\-]/', '', $module);
1202
-            // like trailingslashit()
1203
-            $module_path = rtrim($module_path, DS) . DS;
1204
-            // create classname from module directory name
1205
-            $module = str_replace(' ', '_', ucwords(str_replace('_', ' ', $module)));
1206
-            // add class prefix
1207
-            $module_class = 'EED_' . $module;
1208
-        }
1209
-        // does the module exist ?
1210
-        if (! is_readable($module_path . DS . $module_class . $module_ext)) {
1211
-            $msg = sprintf(
1212
-                __(
1213
-                    'The requested %s module file could not be found or is not readable due to file permissions.',
1214
-                    'event_espresso'
1215
-                ),
1216
-                $module
1217
-            );
1218
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1219
-            return false;
1220
-        }
1221
-        // load the module class file
1222
-        require_once($module_path . $module_class . $module_ext);
1223
-        // verify that class exists
1224
-        if (! class_exists($module_class)) {
1225
-            $msg = sprintf(__('The requested %s module class does not exist.', 'event_espresso'), $module_class);
1226
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1227
-            return false;
1228
-        }
1229
-        // add to array of registered modules
1230
-        EE_Registry::instance()->modules->{$module_class} = $module_path . $module_class . $module_ext;
1231
-        do_action(
1232
-            'AHEE__EE_Config__register_module__complete',
1233
-            $module_class,
1234
-            EE_Registry::instance()->modules->{$module_class}
1235
-        );
1236
-        return true;
1237
-    }
1238
-
1239
-
1240
-
1241
-    /**
1242
-     *    _initialize_modules
1243
-     *    allow modules to set hooks for the rest of the system
1244
-     *
1245
-     * @access private
1246
-     * @return void
1247
-     */
1248
-    private function _initialize_modules()
1249
-    {
1250
-        // cycle thru shortcode folders
1251
-        foreach (EE_Registry::instance()->modules as $module_class => $module_path) {
1252
-            // fire the shortcode class's set_hooks methods in case it needs to hook into other parts of the system
1253
-            // which set hooks ?
1254
-            if (is_admin()) {
1255
-                // fire immediately
1256
-                call_user_func(array($module_class, 'set_hooks_admin'));
1257
-            } else {
1258
-                // delay until other systems are online
1259
-                add_action(
1260
-                    'AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons',
1261
-                    array($module_class, 'set_hooks')
1262
-                );
1263
-            }
1264
-        }
1265
-    }
1266
-
1267
-
1268
-
1269
-    /**
1270
-     *    register_route - adds module method routes to route_map
1271
-     *
1272
-     * @access    public
1273
-     * @param    string $route       - "pretty" public alias for module method
1274
-     * @param    string $module      - module name (classname without EED_ prefix)
1275
-     * @param    string $method_name - the actual module method to be routed to
1276
-     * @param    string $key         - url param key indicating a route is being called
1277
-     * @return    bool
1278
-     */
1279
-    public static function register_route($route = null, $module = null, $method_name = null, $key = 'ee')
1280
-    {
1281
-        do_action('AHEE__EE_Config__register_route__begin', $route, $module, $method_name);
1282
-        $module = str_replace('EED_', '', $module);
1283
-        $module_class = 'EED_' . $module;
1284
-        if (! isset(EE_Registry::instance()->modules->{$module_class})) {
1285
-            $msg = sprintf(__('The module %s has not been registered.', 'event_espresso'), $module);
1286
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1287
-            return false;
1288
-        }
1289
-        if (empty($route)) {
1290
-            $msg = sprintf(__('No route has been supplied.', 'event_espresso'), $route);
1291
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1292
-            return false;
1293
-        }
1294
-        if (! method_exists('EED_' . $module, $method_name)) {
1295
-            $msg = sprintf(
1296
-                __('A valid class method for the %s route has not been supplied.', 'event_espresso'),
1297
-                $route
1298
-            );
1299
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1300
-            return false;
1301
-        }
1302
-        EE_Config::$_module_route_map[$key][$route] = array('EED_' . $module, $method_name);
1303
-        return true;
1304
-    }
1305
-
1306
-
1307
-
1308
-    /**
1309
-     *    get_route - get module method route
1310
-     *
1311
-     * @access    public
1312
-     * @param    string $route - "pretty" public alias for module method
1313
-     * @param    string $key   - url param key indicating a route is being called
1314
-     * @return    string
1315
-     */
1316
-    public static function get_route($route = null, $key = 'ee')
1317
-    {
1318
-        do_action('AHEE__EE_Config__get_route__begin', $route);
1319
-        $route = (string)apply_filters('FHEE__EE_Config__get_route', $route);
1320
-        if (isset(EE_Config::$_module_route_map[$key][$route])) {
1321
-            return EE_Config::$_module_route_map[$key][$route];
1322
-        }
1323
-        return null;
1324
-    }
1325
-
1326
-
1327
-
1328
-    /**
1329
-     *    get_routes - get ALL module method routes
1330
-     *
1331
-     * @access    public
1332
-     * @return    array
1333
-     */
1334
-    public static function get_routes()
1335
-    {
1336
-        return EE_Config::$_module_route_map;
1337
-    }
1338
-
1339
-
1340
-
1341
-    /**
1342
-     *    register_forward - allows modules to forward request to another module for further processing
1343
-     *
1344
-     * @access    public
1345
-     * @param    string       $route   - "pretty" public alias for module method
1346
-     * @param    integer      $status  - integer value corresponding  to status constant strings set in module parent
1347
-     *                                 class, allows different forwards to be served based on status
1348
-     * @param    array|string $forward - function name or array( class, method )
1349
-     * @param    string       $key     - url param key indicating a route is being called
1350
-     * @return    bool
1351
-     */
1352
-    public static function register_forward($route = null, $status = 0, $forward = null, $key = 'ee')
1353
-    {
1354
-        do_action('AHEE__EE_Config__register_forward', $route, $status, $forward);
1355
-        if (! isset(EE_Config::$_module_route_map[$key][$route]) || empty($route)) {
1356
-            $msg = sprintf(
1357
-                __('The module route %s for this forward has not been registered.', 'event_espresso'),
1358
-                $route
1359
-            );
1360
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1361
-            return false;
1362
-        }
1363
-        if (empty($forward)) {
1364
-            $msg = sprintf(__('No forwarding route has been supplied.', 'event_espresso'), $route);
1365
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1366
-            return false;
1367
-        }
1368
-        if (is_array($forward)) {
1369
-            if (! isset($forward[1])) {
1370
-                $msg = sprintf(
1371
-                    __('A class method for the %s forwarding route has not been supplied.', 'event_espresso'),
1372
-                    $route
1373
-                );
1374
-                EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1375
-                return false;
1376
-            }
1377
-            if (! method_exists($forward[0], $forward[1])) {
1378
-                $msg = sprintf(
1379
-                    __('The class method %s for the %s forwarding route is in invalid.', 'event_espresso'),
1380
-                    $forward[1],
1381
-                    $route
1382
-                );
1383
-                EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1384
-                return false;
1385
-            }
1386
-        } else if (! function_exists($forward)) {
1387
-            $msg = sprintf(
1388
-                __('The function %s for the %s forwarding route is in invalid.', 'event_espresso'),
1389
-                $forward,
1390
-                $route
1391
-            );
1392
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1393
-            return false;
1394
-        }
1395
-        EE_Config::$_module_forward_map[$key][$route][absint($status)] = $forward;
1396
-        return true;
1397
-    }
1398
-
1399
-
1400
-
1401
-    /**
1402
-     *    get_forward - get forwarding route
1403
-     *
1404
-     * @access    public
1405
-     * @param    string  $route  - "pretty" public alias for module method
1406
-     * @param    integer $status - integer value corresponding  to status constant strings set in module parent class,
1407
-     *                           allows different forwards to be served based on status
1408
-     * @param    string  $key    - url param key indicating a route is being called
1409
-     * @return    string
1410
-     */
1411
-    public static function get_forward($route = null, $status = 0, $key = 'ee')
1412
-    {
1413
-        do_action('AHEE__EE_Config__get_forward__begin', $route, $status);
1414
-        if (isset(EE_Config::$_module_forward_map[$key][$route][$status])) {
1415
-            return apply_filters(
1416
-                'FHEE__EE_Config__get_forward',
1417
-                EE_Config::$_module_forward_map[$key][$route][$status],
1418
-                $route,
1419
-                $status
1420
-            );
1421
-        }
1422
-        return null;
1423
-    }
1424
-
1425
-
1426
-
1427
-    /**
1428
-     *    register_forward - allows modules to specify different view templates for different method routes and status
1429
-     *    results
1430
-     *
1431
-     * @access    public
1432
-     * @param    string  $route  - "pretty" public alias for module method
1433
-     * @param    integer $status - integer value corresponding  to status constant strings set in module parent class,
1434
-     *                           allows different views to be served based on status
1435
-     * @param    string  $view
1436
-     * @param    string  $key    - url param key indicating a route is being called
1437
-     * @return    bool
1438
-     */
1439
-    public static function register_view($route = null, $status = 0, $view = null, $key = 'ee')
1440
-    {
1441
-        do_action('AHEE__EE_Config__register_view__begin', $route, $status, $view);
1442
-        if (! isset(EE_Config::$_module_route_map[$key][$route]) || empty($route)) {
1443
-            $msg = sprintf(
1444
-                __('The module route %s for this view has not been registered.', 'event_espresso'),
1445
-                $route
1446
-            );
1447
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1448
-            return false;
1449
-        }
1450
-        if (! is_readable($view)) {
1451
-            $msg = sprintf(
1452
-                __(
1453
-                    'The %s view file could not be found or is not readable due to file permissions.',
1454
-                    'event_espresso'
1455
-                ),
1456
-                $view
1457
-            );
1458
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1459
-            return false;
1460
-        }
1461
-        EE_Config::$_module_view_map[$key][$route][absint($status)] = $view;
1462
-        return true;
1463
-    }
1464
-
1465
-
1466
-
1467
-    /**
1468
-     *    get_view - get view for route and status
1469
-     *
1470
-     * @access    public
1471
-     * @param    string  $route  - "pretty" public alias for module method
1472
-     * @param    integer $status - integer value corresponding  to status constant strings set in module parent class,
1473
-     *                           allows different views to be served based on status
1474
-     * @param    string  $key    - url param key indicating a route is being called
1475
-     * @return    string
1476
-     */
1477
-    public static function get_view($route = null, $status = 0, $key = 'ee')
1478
-    {
1479
-        do_action('AHEE__EE_Config__get_view__begin', $route, $status);
1480
-        if (isset(EE_Config::$_module_view_map[$key][$route][$status])) {
1481
-            return apply_filters(
1482
-                'FHEE__EE_Config__get_view',
1483
-                EE_Config::$_module_view_map[$key][$route][$status],
1484
-                $route,
1485
-                $status
1486
-            );
1487
-        }
1488
-        return null;
1489
-    }
1490
-
1491
-
1492
-
1493
-    public function update_addon_option_names()
1494
-    {
1495
-        update_option(EE_Config::ADDON_OPTION_NAMES, $this->_addon_option_names);
1496
-    }
1497
-
1498
-
1499
-
1500
-    public function shutdown()
1501
-    {
1502
-        $this->update_addon_option_names();
1503
-    }
1504
-
1505
-
1506
-
1507
-    /**
1508
-     * @return LegacyShortcodesManager
1509
-     */
1510
-    public static function getLegacyShortcodesManager()
1511
-    {
1512
-
1513
-        if ( ! EE_Config::instance()->legacy_shortcodes_manager instanceof LegacyShortcodesManager) {
1514
-            EE_Config::instance()->legacy_shortcodes_manager = new LegacyShortcodesManager(
1515
-                EE_Registry::instance()
1516
-            );
1517
-        }
1518
-        return EE_Config::instance()->legacy_shortcodes_manager;
1519
-    }
1520
-
1521
-
1522
-
1523
-    /**
1524
-     * register_shortcode - makes core aware of this shortcode
1525
-     *
1526
-     * @deprecated 4.9.26
1527
-     * @param    string $shortcode_path - full path up to and including shortcode folder
1528
-     * @return    bool
1529
-     */
1530
-    public static function register_shortcode($shortcode_path = null)
1531
-    {
1532
-        EE_Error::doing_it_wrong(
1533
-            __METHOD__,
1534
-            __(
1535
-                'Usage is deprecated. Use \EventEspresso\core\services\shortcodes\LegacyShortcodesManager::registerShortcode() as direct replacement, or better yet, please see the new \EventEspresso\core\services\shortcodes\ShortcodesManager class.',
1536
-                'event_espresso'
1537
-            ),
1538
-            '4.9.26'
1539
-        );
1540
-        return EE_Config::instance()->getLegacyShortcodesManager()->registerShortcode($shortcode_path);
1541
-    }
1542
-
1543
-
1544
-
1545
-}
1546
-
1547
-
1548
-
1549
-/**
1550
- * Base class used for config classes. These classes should generally not have
1551
- * magic functions in use, except we'll allow them to magically set and get stuff...
1552
- * basically, they should just be well-defined stdClasses
1553
- */
1554
-class EE_Config_Base
1555
-{
1556
-
1557
-    /**
1558
-     * Utility function for escaping the value of a property and returning.
1559
-     *
1560
-     * @param string $property property name (checks to see if exists).
1561
-     * @return mixed if a detected type found return the escaped value, otherwise just the raw value is returned.
1562
-     * @throws \EE_Error
1563
-     */
1564
-    public function get_pretty($property)
1565
-    {
1566
-        if (! property_exists($this, $property)) {
1567
-            throw new EE_Error(
1568
-                sprintf(
1569
-                    __(
1570
-                        '%1$s::get_pretty() has been called with the property %2$s which does not exist on the %1$s config class.',
1571
-                        'event_espresso'
1572
-                    ),
1573
-                    get_class($this),
1574
-                    $property
1575
-                )
1576
-            );
1577
-        }
1578
-        //just handling escaping of strings for now.
1579
-        if (is_string($this->{$property})) {
1580
-            return stripslashes($this->{$property});
1581
-        }
1582
-        return $this->{$property};
1583
-    }
1584
-
1585
-
1586
-
1587
-    public function populate()
1588
-    {
1589
-        //grab defaults via a new instance of this class.
1590
-        $class_name = get_class($this);
1591
-        $defaults = new $class_name;
1592
-        //loop through the properties for this class and see if they are set.  If they are NOT, then grab the
1593
-        //default from our $defaults object.
1594
-        foreach (get_object_vars($defaults) as $property => $value) {
1595
-            if ($this->{$property} === null) {
1596
-                $this->{$property} = $value;
1597
-            }
1598
-        }
1599
-        //cleanup
1600
-        unset($defaults);
1601
-    }
1602
-
1603
-
1604
-
1605
-    /**
1606
-     *        __isset
1607
-     *
1608
-     * @param $a
1609
-     * @return bool
1610
-     */
1611
-    public function __isset($a)
1612
-    {
1613
-        return false;
1614
-    }
1615
-
1616
-
1617
-
1618
-    /**
1619
-     *        __unset
1620
-     *
1621
-     * @param $a
1622
-     * @return bool
1623
-     */
1624
-    public function __unset($a)
1625
-    {
1626
-        return false;
1627
-    }
1628
-
1629
-
1630
-
1631
-    /**
1632
-     *        __clone
1633
-     */
1634
-    public function __clone()
1635
-    {
1636
-    }
1637
-
1638
-
1639
-
1640
-    /**
1641
-     *        __wakeup
1642
-     */
1643
-    public function __wakeup()
1644
-    {
1645
-    }
1646
-
1647
-
1648
-
1649
-    /**
1650
-     *        __destruct
1651
-     */
1652
-    public function __destruct()
1653
-    {
1654
-    }
1655
-}
1656
-
1657
-
1658
-
1659
-/**
1660
- * Class for defining what's in the EE_Config relating to registration settings
1661
- */
1662
-class EE_Core_Config extends EE_Config_Base
1663
-{
1664
-
1665
-    public $current_blog_id;
1666
-
1667
-    public $ee_ueip_optin;
1668
-
1669
-    public $ee_ueip_has_notified;
1670
-
1671
-    /**
1672
-     * Not to be confused with the 4 critical page variables (See
1673
-     * get_critical_pages_array()), this is just an array of wp posts that have EE
1674
-     * shortcodes in them. Keys are slugs, values are arrays with only 1 element: where the key is the shortcode
1675
-     * in the page, and the value is the page's ID. The key 'posts' is basically a duplicate of this same array.
1676
-     *
1677
-     * @var array
1678
-     */
1679
-    public $post_shortcodes;
1680
-
1681
-    public $module_route_map;
1682
-
1683
-    public $module_forward_map;
1684
-
1685
-    public $module_view_map;
1686
-
1687
-    /**
1688
-     * The next 4 vars are the IDs of critical EE pages.
1689
-     *
1690
-     * @var int
1691
-     */
1692
-    public $reg_page_id;
1693
-
1694
-    public $txn_page_id;
1695
-
1696
-    public $thank_you_page_id;
1697
-
1698
-    public $cancel_page_id;
1699
-
1700
-    /**
1701
-     * The next 4 vars are the URLs of critical EE pages.
1702
-     *
1703
-     * @var int
1704
-     */
1705
-    public $reg_page_url;
1706
-
1707
-    public $txn_page_url;
1708
-
1709
-    public $thank_you_page_url;
1710
-
1711
-    public $cancel_page_url;
1712
-
1713
-    /**
1714
-     * The next vars relate to the custom slugs for EE CPT routes
1715
-     */
1716
-    public $event_cpt_slug;
1717
-
1718
-
1719
-    /**
1720
-     * This caches the _ee_ueip_option in case this config is reset in the same
1721
-     * request across blog switches in a multisite context.
1722
-     * Avoids extra queries to the db for this option.
1723
-     *
1724
-     * @var bool
1725
-     */
1726
-    public static $ee_ueip_option;
1727
-
1728
-
1729
-
1730
-    /**
1731
-     *    class constructor
1732
-     *
1733
-     * @access    public
1734
-     */
1735
-    public function __construct()
1736
-    {
1737
-        // set default organization settings
1738
-        $this->current_blog_id = get_current_blog_id();
1739
-        $this->current_blog_id = $this->current_blog_id === null ? 1 : $this->current_blog_id;
1740
-        $this->ee_ueip_optin = $this->_get_main_ee_ueip_optin();
1741
-        $this->ee_ueip_has_notified = is_main_site() ? get_option('ee_ueip_has_notified', false) : true;
1742
-        $this->post_shortcodes = array();
1743
-        $this->module_route_map = array();
1744
-        $this->module_forward_map = array();
1745
-        $this->module_view_map = array();
1746
-        // critical EE page IDs
1747
-        $this->reg_page_id = 0;
1748
-        $this->txn_page_id = 0;
1749
-        $this->thank_you_page_id = 0;
1750
-        $this->cancel_page_id = 0;
1751
-        // critical EE page URLs
1752
-        $this->reg_page_url = '';
1753
-        $this->txn_page_url = '';
1754
-        $this->thank_you_page_url = '';
1755
-        $this->cancel_page_url = '';
1756
-        //cpt slugs
1757
-        $this->event_cpt_slug = __('events', 'event_espresso');
1758
-        //ueip constant check
1759
-        if (defined('EE_DISABLE_UXIP') && EE_DISABLE_UXIP) {
1760
-            $this->ee_ueip_optin = false;
1761
-            $this->ee_ueip_has_notified = true;
1762
-        }
1763
-    }
1764
-
1765
-
1766
-
1767
-    /**
1768
-     * @return array
1769
-     */
1770
-    public function get_critical_pages_array()
1771
-    {
1772
-        return array(
1773
-            $this->reg_page_id,
1774
-            $this->txn_page_id,
1775
-            $this->thank_you_page_id,
1776
-            $this->cancel_page_id,
1777
-        );
1778
-    }
1779
-
1780
-
1781
-
1782
-    /**
1783
-     * @return array
1784
-     */
1785
-    public function get_critical_pages_shortcodes_array()
1786
-    {
1787
-        return array(
1788
-            $this->reg_page_id       => 'ESPRESSO_CHECKOUT',
1789
-            $this->txn_page_id       => 'ESPRESSO_TXN_PAGE',
1790
-            $this->thank_you_page_id => 'ESPRESSO_THANK_YOU',
1791
-            $this->cancel_page_id    => 'ESPRESSO_CANCELLED',
1792
-        );
1793
-    }
1794
-
1795
-
1796
-
1797
-    /**
1798
-     *  gets/returns URL for EE reg_page
1799
-     *
1800
-     * @access    public
1801
-     * @return    string
1802
-     */
1803
-    public function reg_page_url()
1804
-    {
1805
-        if (! $this->reg_page_url) {
1806
-            $this->reg_page_url = add_query_arg(
1807
-                                      array('uts' => time()),
1808
-                                      get_permalink($this->reg_page_id)
1809
-                                  ) . '#checkout';
1810
-        }
1811
-        return $this->reg_page_url;
1812
-    }
1813
-
1814
-
1815
-
1816
-    /**
1817
-     *  gets/returns URL for EE txn_page
1818
-     *
1819
-     * @param array $query_args like what gets passed to
1820
-     *                          add_query_arg() as the first argument
1821
-     * @access    public
1822
-     * @return    string
1823
-     */
1824
-    public function txn_page_url($query_args = array())
1825
-    {
1826
-        if (! $this->txn_page_url) {
1827
-            $this->txn_page_url = get_permalink($this->txn_page_id);
1828
-        }
1829
-        if ($query_args) {
1830
-            return add_query_arg($query_args, $this->txn_page_url);
1831
-        } else {
1832
-            return $this->txn_page_url;
1833
-        }
1834
-    }
1835
-
1836
-
1837
-
1838
-    /**
1839
-     *  gets/returns URL for EE thank_you_page
1840
-     *
1841
-     * @param array $query_args like what gets passed to
1842
-     *                          add_query_arg() as the first argument
1843
-     * @access    public
1844
-     * @return    string
1845
-     */
1846
-    public function thank_you_page_url($query_args = array())
1847
-    {
1848
-        if (! $this->thank_you_page_url) {
1849
-            $this->thank_you_page_url = get_permalink($this->thank_you_page_id);
1850
-        }
1851
-        if ($query_args) {
1852
-            return add_query_arg($query_args, $this->thank_you_page_url);
1853
-        } else {
1854
-            return $this->thank_you_page_url;
1855
-        }
1856
-    }
1857
-
1858
-
1859
-
1860
-    /**
1861
-     *  gets/returns URL for EE cancel_page
1862
-     *
1863
-     * @access    public
1864
-     * @return    string
1865
-     */
1866
-    public function cancel_page_url()
1867
-    {
1868
-        if (! $this->cancel_page_url) {
1869
-            $this->cancel_page_url = get_permalink($this->cancel_page_id);
1870
-        }
1871
-        return $this->cancel_page_url;
1872
-    }
1873
-
1874
-
1875
-
1876
-    /**
1877
-     * Resets all critical page urls to their original state.  Used primarily by the __sleep() magic method currently.
1878
-     *
1879
-     * @since 4.7.5
1880
-     */
1881
-    protected function _reset_urls()
1882
-    {
1883
-        $this->reg_page_url = '';
1884
-        $this->txn_page_url = '';
1885
-        $this->cancel_page_url = '';
1886
-        $this->thank_you_page_url = '';
1887
-    }
1888
-
1889
-
1890
-
1891
-    /**
1892
-     * Used to return what the optin value is set for the EE User Experience Program.
1893
-     * This accounts for multisite and this value being requested for a subsite.  In multisite, the value is set
1894
-     * on the main site only.
1895
-     *
1896
-     * @return mixed|void
1897
-     */
1898
-    protected function _get_main_ee_ueip_optin()
1899
-    {
1900
-        //if this is the main site then we can just bypass our direct query.
1901
-        if (is_main_site()) {
1902
-            return get_option('ee_ueip_optin', false);
1903
-        }
1904
-        //is this already cached for this request?  If so use it.
1905
-        if ( ! empty(EE_Core_Config::$ee_ueip_option)) {
1906
-            return EE_Core_Config::$ee_ueip_option;
1907
-        }
1908
-        global $wpdb;
1909
-        $current_network_main_site = is_multisite() ? get_current_site() : null;
1910
-        $current_main_site_id = ! empty($current_network_main_site) ? $current_network_main_site->blog_id : 1;
1911
-        $option = 'ee_ueip_optin';
1912
-        //set correct table for query
1913
-        $table_name = $wpdb->get_blog_prefix($current_main_site_id) . 'options';
1914
-        //rather than getting blog option for the $current_main_site_id, we do a direct $wpdb query because
1915
-        //get_blog_option() does a switch_to_blog an that could cause infinite recursion because EE_Core_Config might be
1916
-        //re-constructed on the blog switch.  Note, we are still executing any core wp filters on this option retrieval.
1917
-        //this bit of code is basically a direct copy of get_option without any caching because we are NOT switched to the blog
1918
-        //for the purpose of caching.
1919
-        $pre = apply_filters('pre_option_' . $option, false, $option);
1920
-        if (false !== $pre) {
1921
-            EE_Core_Config::$ee_ueip_option = $pre;
1922
-            return EE_Core_Config::$ee_ueip_option;
1923
-        }
1924
-        $row = $wpdb->get_row($wpdb->prepare("SELECT option_value FROM $table_name WHERE option_name = %s LIMIT 1",
1925
-            $option));
1926
-        if (is_object($row)) {
1927
-            $value = $row->option_value;
1928
-        } else { //option does not exist so use default.
1929
-            return apply_filters('default_option_' . $option, false, $option);
1930
-        }
1931
-        EE_Core_Config::$ee_ueip_option = apply_filters('option_' . $option, maybe_unserialize($value), $option);
1932
-        return EE_Core_Config::$ee_ueip_option;
1933
-    }
1934
-
1935
-
1936
-
1937
-    /**
1938
-     * Currently used to ensure critical page urls have initial values saved to the db instead of any current set values
1939
-     * on the object.
1940
-     *
1941
-     * @return array
1942
-     */
1943
-    public function __sleep()
1944
-    {
1945
-        //reset all url properties
1946
-        $this->_reset_urls();
1947
-        //return what to save to db
1948
-        return array_keys(get_object_vars($this));
1949
-    }
1950
-
1951
-}
1952
-
1953
-
1954
-
1955
-/**
1956
- * Config class for storing info on the Organization
1957
- */
1958
-class EE_Organization_Config extends EE_Config_Base
1959
-{
1960
-
1961
-    /**
1962
-     * @var string $name
1963
-     * eg EE4.1
1964
-     */
1965
-    public $name;
1966
-
1967
-    /**
1968
-     * @var string $address_1
1969
-     * eg 123 Onna Road
1970
-     */
1971
-    public $address_1;
1972
-
1973
-    /**
1974
-     * @var string $address_2
1975
-     * eg PO Box 123
1976
-     */
1977
-    public $address_2;
1978
-
1979
-    /**
1980
-     * @var string $city
1981
-     * eg Inna City
1982
-     */
1983
-    public $city;
1984
-
1985
-    /**
1986
-     * @var int $STA_ID
1987
-     * eg 4
1988
-     */
1989
-    public $STA_ID;
1990
-
1991
-    /**
1992
-     * @var string $CNT_ISO
1993
-     * eg US
1994
-     */
1995
-    public $CNT_ISO;
1996
-
1997
-    /**
1998
-     * @var string $zip
1999
-     * eg 12345  or V1A 2B3
2000
-     */
2001
-    public $zip;
2002
-
2003
-    /**
2004
-     * @var string $email
2005
-     * eg [email protected]
2006
-     */
2007
-    public $email;
2008
-
2009
-
2010
-    /**
2011
-     * @var string $phone
2012
-     * eg. 111-111-1111
2013
-     */
2014
-    public $phone;
2015
-
2016
-
2017
-    /**
2018
-     * @var string $vat
2019
-     * VAT/Tax Number
2020
-     */
2021
-    public $vat;
2022
-
2023
-    /**
2024
-     * @var string $logo_url
2025
-     * eg http://www.somedomain.com/wp-content/uploads/kittehs.jpg
2026
-     */
2027
-    public $logo_url;
2028
-
2029
-
2030
-    /**
2031
-     * The below are all various properties for holding links to organization social network profiles
2032
-     *
2033
-     * @var string
2034
-     */
2035
-    /**
2036
-     * facebook (facebook.com/profile.name)
2037
-     *
2038
-     * @var string
2039
-     */
2040
-    public $facebook;
2041
-
2042
-
2043
-    /**
2044
-     * twitter (twitter.com/twitter_handle)
2045
-     *
2046
-     * @var string
2047
-     */
2048
-    public $twitter;
2049
-
2050
-
2051
-    /**
2052
-     * linkedin (linkedin.com/in/profile_name)
2053
-     *
2054
-     * @var string
2055
-     */
2056
-    public $linkedin;
2057
-
2058
-
2059
-    /**
2060
-     * pinterest (www.pinterest.com/profile_name)
2061
-     *
2062
-     * @var string
2063
-     */
2064
-    public $pinterest;
2065
-
2066
-
2067
-    /**
2068
-     * google+ (google.com/+profileName)
2069
-     *
2070
-     * @var string
2071
-     */
2072
-    public $google;
2073
-
2074
-
2075
-    /**
2076
-     * instagram (instagram.com/handle)
2077
-     *
2078
-     * @var string
2079
-     */
2080
-    public $instagram;
2081
-
2082
-
2083
-
2084
-    /**
2085
-     *    class constructor
2086
-     *
2087
-     * @access    public
2088
-     */
2089
-    public function __construct()
2090
-    {
2091
-        // set default organization settings
2092
-        $this->name = get_bloginfo('name');
2093
-        $this->address_1 = '123 Onna Road';
2094
-        $this->address_2 = 'PO Box 123';
2095
-        $this->city = 'Inna City';
2096
-        $this->STA_ID = 4;
2097
-        $this->CNT_ISO = 'US';
2098
-        $this->zip = '12345';
2099
-        $this->email = get_bloginfo('admin_email');
2100
-        $this->phone = '';
2101
-        $this->vat = '123456789';
2102
-        $this->logo_url = '';
2103
-        $this->facebook = '';
2104
-        $this->twitter = '';
2105
-        $this->linkedin = '';
2106
-        $this->pinterest = '';
2107
-        $this->google = '';
2108
-        $this->instagram = '';
2109
-    }
2110
-
2111
-}
2112
-
2113
-
2114
-
2115
-/**
2116
- * Class for defining what's in the EE_Config relating to currency
2117
- */
2118
-class EE_Currency_Config extends EE_Config_Base
2119
-{
2120
-
2121
-    /**
2122
-     * @var string $code
2123
-     * eg 'US'
2124
-     */
2125
-    public $code;
2126
-
2127
-    /**
2128
-     * @var string $name
2129
-     * eg 'Dollar'
2130
-     */
2131
-    public $name;
2132
-
2133
-    /**
2134
-     * plural name
2135
-     *
2136
-     * @var string $plural
2137
-     * eg 'Dollars'
2138
-     */
2139
-    public $plural;
2140
-
2141
-    /**
2142
-     * currency sign
2143
-     *
2144
-     * @var string $sign
2145
-     * eg '$'
2146
-     */
2147
-    public $sign;
2148
-
2149
-    /**
2150
-     * Whether the currency sign should come before the number or not
2151
-     *
2152
-     * @var boolean $sign_b4
2153
-     */
2154
-    public $sign_b4;
2155
-
2156
-    /**
2157
-     * How many digits should come after the decimal place
2158
-     *
2159
-     * @var int $dec_plc
2160
-     */
2161
-    public $dec_plc;
2162
-
2163
-    /**
2164
-     * Symbol to use for decimal mark
2165
-     *
2166
-     * @var string $dec_mrk
2167
-     * eg '.'
2168
-     */
2169
-    public $dec_mrk;
2170
-
2171
-    /**
2172
-     * Symbol to use for thousands
2173
-     *
2174
-     * @var string $thsnds
2175
-     * eg ','
2176
-     */
2177
-    public $thsnds;
2178
-
2179
-
2180
-
2181
-    /**
2182
-     *    class constructor
2183
-     *
2184
-     * @access    public
2185
-     * @param string $CNT_ISO
2186
-     * @throws \EE_Error
2187
-     */
2188
-    public function __construct($CNT_ISO = '')
2189
-    {
2190
-        /** @var \EventEspresso\core\services\database\TableAnalysis $table_analysis */
2191
-        $table_analysis = EE_Registry::instance()->create('TableAnalysis', array(), true);
2192
-        // get country code from organization settings or use default
2193
-        $ORG_CNT = isset(EE_Registry::instance()->CFG->organization)
2194
-                   && EE_Registry::instance()->CFG->organization instanceof EE_Organization_Config
2195
-            ? EE_Registry::instance()->CFG->organization->CNT_ISO
2196
-            : '';
2197
-        // but override if requested
2198
-        $CNT_ISO = ! empty($CNT_ISO) ? $CNT_ISO : $ORG_CNT;
2199
-        // so if that all went well, and we are not in M-Mode (cuz you can't query the db in M-Mode) and double-check the countries table exists
2200
-        if (
2201
-            ! empty($CNT_ISO)
2202
-            && EE_Maintenance_Mode::instance()->models_can_query()
2203
-            && $table_analysis->tableExists(EE_Registry::instance()->load_model('Country')->table())
2204
-        ) {
2205
-            // retrieve the country settings from the db, just in case they have been customized
2206
-            $country = EE_Registry::instance()->load_model('Country')->get_one_by_ID($CNT_ISO);
2207
-            if ($country instanceof EE_Country) {
2208
-                $this->code = $country->currency_code();    // currency code: USD, CAD, EUR
2209
-                $this->name = $country->currency_name_single();    // Dollar
2210
-                $this->plural = $country->currency_name_plural();    // Dollars
2211
-                $this->sign = $country->currency_sign();            // currency sign: $
2212
-                $this->sign_b4 = $country->currency_sign_before();        // currency sign before or after: $TRUE  or  FALSE$
2213
-                $this->dec_plc = $country->currency_decimal_places();    // decimal places: 2 = 0.00  3 = 0.000
2214
-                $this->dec_mrk = $country->currency_decimal_mark();    // decimal mark: (comma) ',' = 0,01   or (decimal) '.' = 0.01
2215
-                $this->thsnds = $country->currency_thousands_separator();    // thousands separator: (comma) ',' = 1,000   or (decimal) '.' = 1.000
2216
-            }
2217
-        }
2218
-        // fallback to hardcoded defaults, in case the above failed
2219
-        if (empty($this->code)) {
2220
-            // set default currency settings
2221
-            $this->code = 'USD';    // currency code: USD, CAD, EUR
2222
-            $this->name = __('Dollar', 'event_espresso');    // Dollar
2223
-            $this->plural = __('Dollars', 'event_espresso');    // Dollars
2224
-            $this->sign = '$';    // currency sign: $
2225
-            $this->sign_b4 = true;    // currency sign before or after: $TRUE  or  FALSE$
2226
-            $this->dec_plc = 2;    // decimal places: 2 = 0.00  3 = 0.000
2227
-            $this->dec_mrk = '.';    // decimal mark: (comma) ',' = 0,01   or (decimal) '.' = 0.01
2228
-            $this->thsnds = ',';    // thousands separator: (comma) ',' = 1,000   or (decimal) '.' = 1.000
2229
-        }
2230
-    }
2231
-}
2232
-
2233
-
2234
-
2235
-/**
2236
- * Class for defining what's in the EE_Config relating to registration settings
2237
- */
2238
-class EE_Registration_Config extends EE_Config_Base
2239
-{
2240
-
2241
-    /**
2242
-     * Default registration status
2243
-     *
2244
-     * @var string $default_STS_ID
2245
-     * eg 'RPP'
2246
-     */
2247
-    public $default_STS_ID;
2248
-
2249
-
2250
-    /**
2251
-     * For new events, this will be the default value for the maximum number of tickets (equivalent to maximum number of
2252
-     * registrations)
2253
-     * @var int
2254
-     */
2255
-    public $default_maximum_number_of_tickets;
2256
-
2257
-
2258
-    /**
2259
-     * level of validation to apply to email addresses
2260
-     *
2261
-     * @var string $email_validation_level
2262
-     * options: 'basic', 'wp_default', 'i18n', 'i18n_dns'
2263
-     */
2264
-    public $email_validation_level;
2265
-
2266
-    /**
2267
-     *    whether or not to show alternate payment options during the reg process if payment status is pending
2268
-     *
2269
-     * @var boolean $show_pending_payment_options
2270
-     */
2271
-    public $show_pending_payment_options;
2272
-
2273
-    /**
2274
-     * Whether to skip the registration confirmation page
2275
-     *
2276
-     * @var boolean $skip_reg_confirmation
2277
-     */
2278
-    public $skip_reg_confirmation;
2279
-
2280
-    /**
2281
-     * an array of SPCO reg steps where:
2282
-     *        the keys denotes the reg step order
2283
-     *        each element consists of an array with the following elements:
2284
-     *            "file_path" => the file path to the EE_SPCO_Reg_Step class
2285
-     *            "class_name" => the specific EE_SPCO_Reg_Step child class name
2286
-     *            "slug" => the URL param used to trigger the reg step
2287
-     *
2288
-     * @var array $reg_steps
2289
-     */
2290
-    public $reg_steps;
2291
-
2292
-    /**
2293
-     * Whether registration confirmation should be the last page of SPCO
2294
-     *
2295
-     * @var boolean $reg_confirmation_last
2296
-     */
2297
-    public $reg_confirmation_last;
2298
-
2299
-    /**
2300
-     * Whether or not to enable the EE Bot Trap
2301
-     *
2302
-     * @var boolean $use_bot_trap
2303
-     */
2304
-    public $use_bot_trap;
2305
-
2306
-    /**
2307
-     * Whether or not to encrypt some data sent by the EE Bot Trap
2308
-     *
2309
-     * @var boolean $use_encryption
2310
-     */
2311
-    public $use_encryption;
1545
+}
2312 1546
 
2313
-    /**
2314
-     * Whether or not to use ReCaptcha
2315
-     *
2316
-     * @var boolean $use_captcha
2317
-     */
2318
-    public $use_captcha;
2319 1547
 
2320
-    /**
2321
-     * ReCaptcha Theme
2322
-     *
2323
-     * @var string $recaptcha_theme
2324
-     *    options: 'dark    ', 'light'
2325
-     */
2326
-    public $recaptcha_theme;
2327 1548
 
2328
-    /**
2329
-     * ReCaptcha Type
2330
-     *
2331
-     * @var string $recaptcha_type
2332
-     *    options: 'audio', 'image'
2333
-     */
2334
-    public $recaptcha_type;
1549
+/**
1550
+ * Base class used for config classes. These classes should generally not have
1551
+ * magic functions in use, except we'll allow them to magically set and get stuff...
1552
+ * basically, they should just be well-defined stdClasses
1553
+ */
1554
+class EE_Config_Base
1555
+{
2335 1556
 
2336
-    /**
2337
-     * ReCaptcha language
2338
-     *
2339
-     * @var string $recaptcha_language
2340
-     * eg 'en'
2341
-     */
2342
-    public $recaptcha_language;
1557
+	/**
1558
+	 * Utility function for escaping the value of a property and returning.
1559
+	 *
1560
+	 * @param string $property property name (checks to see if exists).
1561
+	 * @return mixed if a detected type found return the escaped value, otherwise just the raw value is returned.
1562
+	 * @throws \EE_Error
1563
+	 */
1564
+	public function get_pretty($property)
1565
+	{
1566
+		if (! property_exists($this, $property)) {
1567
+			throw new EE_Error(
1568
+				sprintf(
1569
+					__(
1570
+						'%1$s::get_pretty() has been called with the property %2$s which does not exist on the %1$s config class.',
1571
+						'event_espresso'
1572
+					),
1573
+					get_class($this),
1574
+					$property
1575
+				)
1576
+			);
1577
+		}
1578
+		//just handling escaping of strings for now.
1579
+		if (is_string($this->{$property})) {
1580
+			return stripslashes($this->{$property});
1581
+		}
1582
+		return $this->{$property};
1583
+	}
1584
+
1585
+
1586
+
1587
+	public function populate()
1588
+	{
1589
+		//grab defaults via a new instance of this class.
1590
+		$class_name = get_class($this);
1591
+		$defaults = new $class_name;
1592
+		//loop through the properties for this class and see if they are set.  If they are NOT, then grab the
1593
+		//default from our $defaults object.
1594
+		foreach (get_object_vars($defaults) as $property => $value) {
1595
+			if ($this->{$property} === null) {
1596
+				$this->{$property} = $value;
1597
+			}
1598
+		}
1599
+		//cleanup
1600
+		unset($defaults);
1601
+	}
1602
+
1603
+
1604
+
1605
+	/**
1606
+	 *        __isset
1607
+	 *
1608
+	 * @param $a
1609
+	 * @return bool
1610
+	 */
1611
+	public function __isset($a)
1612
+	{
1613
+		return false;
1614
+	}
1615
+
1616
+
1617
+
1618
+	/**
1619
+	 *        __unset
1620
+	 *
1621
+	 * @param $a
1622
+	 * @return bool
1623
+	 */
1624
+	public function __unset($a)
1625
+	{
1626
+		return false;
1627
+	}
1628
+
1629
+
1630
+
1631
+	/**
1632
+	 *        __clone
1633
+	 */
1634
+	public function __clone()
1635
+	{
1636
+	}
1637
+
1638
+
1639
+
1640
+	/**
1641
+	 *        __wakeup
1642
+	 */
1643
+	public function __wakeup()
1644
+	{
1645
+	}
1646
+
1647
+
1648
+
1649
+	/**
1650
+	 *        __destruct
1651
+	 */
1652
+	public function __destruct()
1653
+	{
1654
+	}
1655
+}
2343 1656
 
2344
-    /**
2345
-     * ReCaptcha public key
2346
-     *
2347
-     * @var string $recaptcha_publickey
2348
-     */
2349
-    public $recaptcha_publickey;
2350 1657
 
2351
-    /**
2352
-     * ReCaptcha private key
2353
-     *
2354
-     * @var string $recaptcha_privatekey
2355
-     */
2356
-    public $recaptcha_privatekey;
2357 1658
 
2358
-    /**
2359
-     * ReCaptcha width
2360
-     *
2361
-     * @var int $recaptcha_width
2362
-     * @deprecated
2363
-     */
2364
-    public $recaptcha_width;
1659
+/**
1660
+ * Class for defining what's in the EE_Config relating to registration settings
1661
+ */
1662
+class EE_Core_Config extends EE_Config_Base
1663
+{
2365 1664
 
2366
-    /**
2367
-     * Whether or not invalid attempts to directly access the registration checkout page should be tracked.
2368
-     *
2369
-     * @var boolean $track_invalid_checkout_access
2370
-     */
2371
-    protected $track_invalid_checkout_access = true;
1665
+	public $current_blog_id;
1666
+
1667
+	public $ee_ueip_optin;
1668
+
1669
+	public $ee_ueip_has_notified;
1670
+
1671
+	/**
1672
+	 * Not to be confused with the 4 critical page variables (See
1673
+	 * get_critical_pages_array()), this is just an array of wp posts that have EE
1674
+	 * shortcodes in them. Keys are slugs, values are arrays with only 1 element: where the key is the shortcode
1675
+	 * in the page, and the value is the page's ID. The key 'posts' is basically a duplicate of this same array.
1676
+	 *
1677
+	 * @var array
1678
+	 */
1679
+	public $post_shortcodes;
1680
+
1681
+	public $module_route_map;
1682
+
1683
+	public $module_forward_map;
1684
+
1685
+	public $module_view_map;
1686
+
1687
+	/**
1688
+	 * The next 4 vars are the IDs of critical EE pages.
1689
+	 *
1690
+	 * @var int
1691
+	 */
1692
+	public $reg_page_id;
1693
+
1694
+	public $txn_page_id;
1695
+
1696
+	public $thank_you_page_id;
1697
+
1698
+	public $cancel_page_id;
1699
+
1700
+	/**
1701
+	 * The next 4 vars are the URLs of critical EE pages.
1702
+	 *
1703
+	 * @var int
1704
+	 */
1705
+	public $reg_page_url;
1706
+
1707
+	public $txn_page_url;
1708
+
1709
+	public $thank_you_page_url;
1710
+
1711
+	public $cancel_page_url;
1712
+
1713
+	/**
1714
+	 * The next vars relate to the custom slugs for EE CPT routes
1715
+	 */
1716
+	public $event_cpt_slug;
1717
+
1718
+
1719
+	/**
1720
+	 * This caches the _ee_ueip_option in case this config is reset in the same
1721
+	 * request across blog switches in a multisite context.
1722
+	 * Avoids extra queries to the db for this option.
1723
+	 *
1724
+	 * @var bool
1725
+	 */
1726
+	public static $ee_ueip_option;
1727
+
1728
+
1729
+
1730
+	/**
1731
+	 *    class constructor
1732
+	 *
1733
+	 * @access    public
1734
+	 */
1735
+	public function __construct()
1736
+	{
1737
+		// set default organization settings
1738
+		$this->current_blog_id = get_current_blog_id();
1739
+		$this->current_blog_id = $this->current_blog_id === null ? 1 : $this->current_blog_id;
1740
+		$this->ee_ueip_optin = $this->_get_main_ee_ueip_optin();
1741
+		$this->ee_ueip_has_notified = is_main_site() ? get_option('ee_ueip_has_notified', false) : true;
1742
+		$this->post_shortcodes = array();
1743
+		$this->module_route_map = array();
1744
+		$this->module_forward_map = array();
1745
+		$this->module_view_map = array();
1746
+		// critical EE page IDs
1747
+		$this->reg_page_id = 0;
1748
+		$this->txn_page_id = 0;
1749
+		$this->thank_you_page_id = 0;
1750
+		$this->cancel_page_id = 0;
1751
+		// critical EE page URLs
1752
+		$this->reg_page_url = '';
1753
+		$this->txn_page_url = '';
1754
+		$this->thank_you_page_url = '';
1755
+		$this->cancel_page_url = '';
1756
+		//cpt slugs
1757
+		$this->event_cpt_slug = __('events', 'event_espresso');
1758
+		//ueip constant check
1759
+		if (defined('EE_DISABLE_UXIP') && EE_DISABLE_UXIP) {
1760
+			$this->ee_ueip_optin = false;
1761
+			$this->ee_ueip_has_notified = true;
1762
+		}
1763
+	}
1764
+
1765
+
1766
+
1767
+	/**
1768
+	 * @return array
1769
+	 */
1770
+	public function get_critical_pages_array()
1771
+	{
1772
+		return array(
1773
+			$this->reg_page_id,
1774
+			$this->txn_page_id,
1775
+			$this->thank_you_page_id,
1776
+			$this->cancel_page_id,
1777
+		);
1778
+	}
1779
+
1780
+
1781
+
1782
+	/**
1783
+	 * @return array
1784
+	 */
1785
+	public function get_critical_pages_shortcodes_array()
1786
+	{
1787
+		return array(
1788
+			$this->reg_page_id       => 'ESPRESSO_CHECKOUT',
1789
+			$this->txn_page_id       => 'ESPRESSO_TXN_PAGE',
1790
+			$this->thank_you_page_id => 'ESPRESSO_THANK_YOU',
1791
+			$this->cancel_page_id    => 'ESPRESSO_CANCELLED',
1792
+		);
1793
+	}
1794
+
1795
+
1796
+
1797
+	/**
1798
+	 *  gets/returns URL for EE reg_page
1799
+	 *
1800
+	 * @access    public
1801
+	 * @return    string
1802
+	 */
1803
+	public function reg_page_url()
1804
+	{
1805
+		if (! $this->reg_page_url) {
1806
+			$this->reg_page_url = add_query_arg(
1807
+									  array('uts' => time()),
1808
+									  get_permalink($this->reg_page_id)
1809
+								  ) . '#checkout';
1810
+		}
1811
+		return $this->reg_page_url;
1812
+	}
1813
+
1814
+
1815
+
1816
+	/**
1817
+	 *  gets/returns URL for EE txn_page
1818
+	 *
1819
+	 * @param array $query_args like what gets passed to
1820
+	 *                          add_query_arg() as the first argument
1821
+	 * @access    public
1822
+	 * @return    string
1823
+	 */
1824
+	public function txn_page_url($query_args = array())
1825
+	{
1826
+		if (! $this->txn_page_url) {
1827
+			$this->txn_page_url = get_permalink($this->txn_page_id);
1828
+		}
1829
+		if ($query_args) {
1830
+			return add_query_arg($query_args, $this->txn_page_url);
1831
+		} else {
1832
+			return $this->txn_page_url;
1833
+		}
1834
+	}
1835
+
1836
+
1837
+
1838
+	/**
1839
+	 *  gets/returns URL for EE thank_you_page
1840
+	 *
1841
+	 * @param array $query_args like what gets passed to
1842
+	 *                          add_query_arg() as the first argument
1843
+	 * @access    public
1844
+	 * @return    string
1845
+	 */
1846
+	public function thank_you_page_url($query_args = array())
1847
+	{
1848
+		if (! $this->thank_you_page_url) {
1849
+			$this->thank_you_page_url = get_permalink($this->thank_you_page_id);
1850
+		}
1851
+		if ($query_args) {
1852
+			return add_query_arg($query_args, $this->thank_you_page_url);
1853
+		} else {
1854
+			return $this->thank_you_page_url;
1855
+		}
1856
+	}
1857
+
1858
+
1859
+
1860
+	/**
1861
+	 *  gets/returns URL for EE cancel_page
1862
+	 *
1863
+	 * @access    public
1864
+	 * @return    string
1865
+	 */
1866
+	public function cancel_page_url()
1867
+	{
1868
+		if (! $this->cancel_page_url) {
1869
+			$this->cancel_page_url = get_permalink($this->cancel_page_id);
1870
+		}
1871
+		return $this->cancel_page_url;
1872
+	}
1873
+
1874
+
1875
+
1876
+	/**
1877
+	 * Resets all critical page urls to their original state.  Used primarily by the __sleep() magic method currently.
1878
+	 *
1879
+	 * @since 4.7.5
1880
+	 */
1881
+	protected function _reset_urls()
1882
+	{
1883
+		$this->reg_page_url = '';
1884
+		$this->txn_page_url = '';
1885
+		$this->cancel_page_url = '';
1886
+		$this->thank_you_page_url = '';
1887
+	}
1888
+
1889
+
1890
+
1891
+	/**
1892
+	 * Used to return what the optin value is set for the EE User Experience Program.
1893
+	 * This accounts for multisite and this value being requested for a subsite.  In multisite, the value is set
1894
+	 * on the main site only.
1895
+	 *
1896
+	 * @return mixed|void
1897
+	 */
1898
+	protected function _get_main_ee_ueip_optin()
1899
+	{
1900
+		//if this is the main site then we can just bypass our direct query.
1901
+		if (is_main_site()) {
1902
+			return get_option('ee_ueip_optin', false);
1903
+		}
1904
+		//is this already cached for this request?  If so use it.
1905
+		if ( ! empty(EE_Core_Config::$ee_ueip_option)) {
1906
+			return EE_Core_Config::$ee_ueip_option;
1907
+		}
1908
+		global $wpdb;
1909
+		$current_network_main_site = is_multisite() ? get_current_site() : null;
1910
+		$current_main_site_id = ! empty($current_network_main_site) ? $current_network_main_site->blog_id : 1;
1911
+		$option = 'ee_ueip_optin';
1912
+		//set correct table for query
1913
+		$table_name = $wpdb->get_blog_prefix($current_main_site_id) . 'options';
1914
+		//rather than getting blog option for the $current_main_site_id, we do a direct $wpdb query because
1915
+		//get_blog_option() does a switch_to_blog an that could cause infinite recursion because EE_Core_Config might be
1916
+		//re-constructed on the blog switch.  Note, we are still executing any core wp filters on this option retrieval.
1917
+		//this bit of code is basically a direct copy of get_option without any caching because we are NOT switched to the blog
1918
+		//for the purpose of caching.
1919
+		$pre = apply_filters('pre_option_' . $option, false, $option);
1920
+		if (false !== $pre) {
1921
+			EE_Core_Config::$ee_ueip_option = $pre;
1922
+			return EE_Core_Config::$ee_ueip_option;
1923
+		}
1924
+		$row = $wpdb->get_row($wpdb->prepare("SELECT option_value FROM $table_name WHERE option_name = %s LIMIT 1",
1925
+			$option));
1926
+		if (is_object($row)) {
1927
+			$value = $row->option_value;
1928
+		} else { //option does not exist so use default.
1929
+			return apply_filters('default_option_' . $option, false, $option);
1930
+		}
1931
+		EE_Core_Config::$ee_ueip_option = apply_filters('option_' . $option, maybe_unserialize($value), $option);
1932
+		return EE_Core_Config::$ee_ueip_option;
1933
+	}
1934
+
1935
+
1936
+
1937
+	/**
1938
+	 * Currently used to ensure critical page urls have initial values saved to the db instead of any current set values
1939
+	 * on the object.
1940
+	 *
1941
+	 * @return array
1942
+	 */
1943
+	public function __sleep()
1944
+	{
1945
+		//reset all url properties
1946
+		$this->_reset_urls();
1947
+		//return what to save to db
1948
+		return array_keys(get_object_vars($this));
1949
+	}
2372 1950
 
1951
+}
2373 1952
 
2374 1953
 
2375
-    /**
2376
-     *    class constructor
2377
-     *
2378
-     * @access    public
2379
-     */
2380
-    public function __construct()
2381
-    {
2382
-        // set default registration settings
2383
-        $this->default_STS_ID = EEM_Registration::status_id_pending_payment;
2384
-        $this->email_validation_level = 'wp_default';
2385
-        $this->show_pending_payment_options = true;
2386
-        $this->skip_reg_confirmation = false;
2387
-        $this->reg_steps = array();
2388
-        $this->reg_confirmation_last = false;
2389
-        $this->use_bot_trap = true;
2390
-        $this->use_encryption = true;
2391
-        $this->use_captcha = false;
2392
-        $this->recaptcha_theme = 'light';
2393
-        $this->recaptcha_type = 'image';
2394
-        $this->recaptcha_language = 'en';
2395
-        $this->recaptcha_publickey = null;
2396
-        $this->recaptcha_privatekey = null;
2397
-        $this->recaptcha_width = 500;
2398
-        $this->default_maximum_number_of_tickets = 10;
2399
-    }
2400
-
2401
-
2402
-
2403
-    /**
2404
-     * This is called by the config loader and hooks are initialized AFTER the config has been populated.
2405
-     *
2406
-     * @since 4.8.8.rc.019
2407
-     */
2408
-    public function do_hooks()
2409
-    {
2410
-        add_action('AHEE__EE_Config___load_core_config__end', array($this, 'set_default_reg_status_on_EEM_Event'));
2411
-        add_action('AHEE__EE_Config___load_core_config__end', array($this, 'set_default_max_ticket_on_EEM_Event'));
2412
-    }
2413 1954
 
1955
+/**
1956
+ * Config class for storing info on the Organization
1957
+ */
1958
+class EE_Organization_Config extends EE_Config_Base
1959
+{
2414 1960
 
1961
+	/**
1962
+	 * @var string $name
1963
+	 * eg EE4.1
1964
+	 */
1965
+	public $name;
1966
+
1967
+	/**
1968
+	 * @var string $address_1
1969
+	 * eg 123 Onna Road
1970
+	 */
1971
+	public $address_1;
1972
+
1973
+	/**
1974
+	 * @var string $address_2
1975
+	 * eg PO Box 123
1976
+	 */
1977
+	public $address_2;
1978
+
1979
+	/**
1980
+	 * @var string $city
1981
+	 * eg Inna City
1982
+	 */
1983
+	public $city;
1984
+
1985
+	/**
1986
+	 * @var int $STA_ID
1987
+	 * eg 4
1988
+	 */
1989
+	public $STA_ID;
1990
+
1991
+	/**
1992
+	 * @var string $CNT_ISO
1993
+	 * eg US
1994
+	 */
1995
+	public $CNT_ISO;
1996
+
1997
+	/**
1998
+	 * @var string $zip
1999
+	 * eg 12345  or V1A 2B3
2000
+	 */
2001
+	public $zip;
2002
+
2003
+	/**
2004
+	 * @var string $email
2005
+	 * eg [email protected]
2006
+	 */
2007
+	public $email;
2008
+
2009
+
2010
+	/**
2011
+	 * @var string $phone
2012
+	 * eg. 111-111-1111
2013
+	 */
2014
+	public $phone;
2015
+
2016
+
2017
+	/**
2018
+	 * @var string $vat
2019
+	 * VAT/Tax Number
2020
+	 */
2021
+	public $vat;
2022
+
2023
+	/**
2024
+	 * @var string $logo_url
2025
+	 * eg http://www.somedomain.com/wp-content/uploads/kittehs.jpg
2026
+	 */
2027
+	public $logo_url;
2028
+
2029
+
2030
+	/**
2031
+	 * The below are all various properties for holding links to organization social network profiles
2032
+	 *
2033
+	 * @var string
2034
+	 */
2035
+	/**
2036
+	 * facebook (facebook.com/profile.name)
2037
+	 *
2038
+	 * @var string
2039
+	 */
2040
+	public $facebook;
2041
+
2042
+
2043
+	/**
2044
+	 * twitter (twitter.com/twitter_handle)
2045
+	 *
2046
+	 * @var string
2047
+	 */
2048
+	public $twitter;
2049
+
2050
+
2051
+	/**
2052
+	 * linkedin (linkedin.com/in/profile_name)
2053
+	 *
2054
+	 * @var string
2055
+	 */
2056
+	public $linkedin;
2057
+
2058
+
2059
+	/**
2060
+	 * pinterest (www.pinterest.com/profile_name)
2061
+	 *
2062
+	 * @var string
2063
+	 */
2064
+	public $pinterest;
2065
+
2066
+
2067
+	/**
2068
+	 * google+ (google.com/+profileName)
2069
+	 *
2070
+	 * @var string
2071
+	 */
2072
+	public $google;
2073
+
2074
+
2075
+	/**
2076
+	 * instagram (instagram.com/handle)
2077
+	 *
2078
+	 * @var string
2079
+	 */
2080
+	public $instagram;
2081
+
2082
+
2083
+
2084
+	/**
2085
+	 *    class constructor
2086
+	 *
2087
+	 * @access    public
2088
+	 */
2089
+	public function __construct()
2090
+	{
2091
+		// set default organization settings
2092
+		$this->name = get_bloginfo('name');
2093
+		$this->address_1 = '123 Onna Road';
2094
+		$this->address_2 = 'PO Box 123';
2095
+		$this->city = 'Inna City';
2096
+		$this->STA_ID = 4;
2097
+		$this->CNT_ISO = 'US';
2098
+		$this->zip = '12345';
2099
+		$this->email = get_bloginfo('admin_email');
2100
+		$this->phone = '';
2101
+		$this->vat = '123456789';
2102
+		$this->logo_url = '';
2103
+		$this->facebook = '';
2104
+		$this->twitter = '';
2105
+		$this->linkedin = '';
2106
+		$this->pinterest = '';
2107
+		$this->google = '';
2108
+		$this->instagram = '';
2109
+	}
2415 2110
 
2416
-    /**
2417
-     * Hooked into `AHEE__EE_Config___load_core_config__end` to ensure the default for the EVT_default_registration_status
2418
-     * field matches the config setting for default_STS_ID.
2419
-     */
2420
-    public function set_default_reg_status_on_EEM_Event()
2421
-    {
2422
-        EEM_Event::set_default_reg_status($this->default_STS_ID);
2423
-    }
2111
+}
2424 2112
 
2425 2113
 
2426
-    /**
2427
-     * Hooked into `AHEE__EE_Config___load_core_config__end` to ensure the default for the EVT_additional_limit field
2428
-     * for Events matches the config setting for default_maximum_number_of_tickets
2429
-     */
2430
-    public function set_default_max_ticket_on_EEM_Event()
2431
-    {
2432
-        EEM_Event::set_default_additional_limit($this->default_maximum_number_of_tickets);
2433
-    }
2434 2114
 
2115
+/**
2116
+ * Class for defining what's in the EE_Config relating to currency
2117
+ */
2118
+class EE_Currency_Config extends EE_Config_Base
2119
+{
2435 2120
 
2121
+	/**
2122
+	 * @var string $code
2123
+	 * eg 'US'
2124
+	 */
2125
+	public $code;
2126
+
2127
+	/**
2128
+	 * @var string $name
2129
+	 * eg 'Dollar'
2130
+	 */
2131
+	public $name;
2132
+
2133
+	/**
2134
+	 * plural name
2135
+	 *
2136
+	 * @var string $plural
2137
+	 * eg 'Dollars'
2138
+	 */
2139
+	public $plural;
2140
+
2141
+	/**
2142
+	 * currency sign
2143
+	 *
2144
+	 * @var string $sign
2145
+	 * eg '$'
2146
+	 */
2147
+	public $sign;
2148
+
2149
+	/**
2150
+	 * Whether the currency sign should come before the number or not
2151
+	 *
2152
+	 * @var boolean $sign_b4
2153
+	 */
2154
+	public $sign_b4;
2155
+
2156
+	/**
2157
+	 * How many digits should come after the decimal place
2158
+	 *
2159
+	 * @var int $dec_plc
2160
+	 */
2161
+	public $dec_plc;
2162
+
2163
+	/**
2164
+	 * Symbol to use for decimal mark
2165
+	 *
2166
+	 * @var string $dec_mrk
2167
+	 * eg '.'
2168
+	 */
2169
+	public $dec_mrk;
2170
+
2171
+	/**
2172
+	 * Symbol to use for thousands
2173
+	 *
2174
+	 * @var string $thsnds
2175
+	 * eg ','
2176
+	 */
2177
+	public $thsnds;
2178
+
2179
+
2180
+
2181
+	/**
2182
+	 *    class constructor
2183
+	 *
2184
+	 * @access    public
2185
+	 * @param string $CNT_ISO
2186
+	 * @throws \EE_Error
2187
+	 */
2188
+	public function __construct($CNT_ISO = '')
2189
+	{
2190
+		/** @var \EventEspresso\core\services\database\TableAnalysis $table_analysis */
2191
+		$table_analysis = EE_Registry::instance()->create('TableAnalysis', array(), true);
2192
+		// get country code from organization settings or use default
2193
+		$ORG_CNT = isset(EE_Registry::instance()->CFG->organization)
2194
+				   && EE_Registry::instance()->CFG->organization instanceof EE_Organization_Config
2195
+			? EE_Registry::instance()->CFG->organization->CNT_ISO
2196
+			: '';
2197
+		// but override if requested
2198
+		$CNT_ISO = ! empty($CNT_ISO) ? $CNT_ISO : $ORG_CNT;
2199
+		// so if that all went well, and we are not in M-Mode (cuz you can't query the db in M-Mode) and double-check the countries table exists
2200
+		if (
2201
+			! empty($CNT_ISO)
2202
+			&& EE_Maintenance_Mode::instance()->models_can_query()
2203
+			&& $table_analysis->tableExists(EE_Registry::instance()->load_model('Country')->table())
2204
+		) {
2205
+			// retrieve the country settings from the db, just in case they have been customized
2206
+			$country = EE_Registry::instance()->load_model('Country')->get_one_by_ID($CNT_ISO);
2207
+			if ($country instanceof EE_Country) {
2208
+				$this->code = $country->currency_code();    // currency code: USD, CAD, EUR
2209
+				$this->name = $country->currency_name_single();    // Dollar
2210
+				$this->plural = $country->currency_name_plural();    // Dollars
2211
+				$this->sign = $country->currency_sign();            // currency sign: $
2212
+				$this->sign_b4 = $country->currency_sign_before();        // currency sign before or after: $TRUE  or  FALSE$
2213
+				$this->dec_plc = $country->currency_decimal_places();    // decimal places: 2 = 0.00  3 = 0.000
2214
+				$this->dec_mrk = $country->currency_decimal_mark();    // decimal mark: (comma) ',' = 0,01   or (decimal) '.' = 0.01
2215
+				$this->thsnds = $country->currency_thousands_separator();    // thousands separator: (comma) ',' = 1,000   or (decimal) '.' = 1.000
2216
+			}
2217
+		}
2218
+		// fallback to hardcoded defaults, in case the above failed
2219
+		if (empty($this->code)) {
2220
+			// set default currency settings
2221
+			$this->code = 'USD';    // currency code: USD, CAD, EUR
2222
+			$this->name = __('Dollar', 'event_espresso');    // Dollar
2223
+			$this->plural = __('Dollars', 'event_espresso');    // Dollars
2224
+			$this->sign = '$';    // currency sign: $
2225
+			$this->sign_b4 = true;    // currency sign before or after: $TRUE  or  FALSE$
2226
+			$this->dec_plc = 2;    // decimal places: 2 = 0.00  3 = 0.000
2227
+			$this->dec_mrk = '.';    // decimal mark: (comma) ',' = 0,01   or (decimal) '.' = 0.01
2228
+			$this->thsnds = ',';    // thousands separator: (comma) ',' = 1,000   or (decimal) '.' = 1.000
2229
+		}
2230
+	}
2231
+}
2436 2232
 
2437
-    /**
2438
-     * @return boolean
2439
-     */
2440
-    public function track_invalid_checkout_access()
2441
-    {
2442
-        return $this->track_invalid_checkout_access;
2443
-    }
2444 2233
 
2445 2234
 
2235
+/**
2236
+ * Class for defining what's in the EE_Config relating to registration settings
2237
+ */
2238
+class EE_Registration_Config extends EE_Config_Base
2239
+{
2446 2240
 
2447
-    /**
2448
-     * @param boolean $track_invalid_checkout_access
2449
-     */
2450
-    public function set_track_invalid_checkout_access($track_invalid_checkout_access)
2451
-    {
2452
-        $this->track_invalid_checkout_access = filter_var(
2453
-            $track_invalid_checkout_access,
2454
-            FILTER_VALIDATE_BOOLEAN
2455
-        );
2456
-    }
2241
+	/**
2242
+	 * Default registration status
2243
+	 *
2244
+	 * @var string $default_STS_ID
2245
+	 * eg 'RPP'
2246
+	 */
2247
+	public $default_STS_ID;
2248
+
2249
+
2250
+	/**
2251
+	 * For new events, this will be the default value for the maximum number of tickets (equivalent to maximum number of
2252
+	 * registrations)
2253
+	 * @var int
2254
+	 */
2255
+	public $default_maximum_number_of_tickets;
2256
+
2257
+
2258
+	/**
2259
+	 * level of validation to apply to email addresses
2260
+	 *
2261
+	 * @var string $email_validation_level
2262
+	 * options: 'basic', 'wp_default', 'i18n', 'i18n_dns'
2263
+	 */
2264
+	public $email_validation_level;
2265
+
2266
+	/**
2267
+	 *    whether or not to show alternate payment options during the reg process if payment status is pending
2268
+	 *
2269
+	 * @var boolean $show_pending_payment_options
2270
+	 */
2271
+	public $show_pending_payment_options;
2272
+
2273
+	/**
2274
+	 * Whether to skip the registration confirmation page
2275
+	 *
2276
+	 * @var boolean $skip_reg_confirmation
2277
+	 */
2278
+	public $skip_reg_confirmation;
2279
+
2280
+	/**
2281
+	 * an array of SPCO reg steps where:
2282
+	 *        the keys denotes the reg step order
2283
+	 *        each element consists of an array with the following elements:
2284
+	 *            "file_path" => the file path to the EE_SPCO_Reg_Step class
2285
+	 *            "class_name" => the specific EE_SPCO_Reg_Step child class name
2286
+	 *            "slug" => the URL param used to trigger the reg step
2287
+	 *
2288
+	 * @var array $reg_steps
2289
+	 */
2290
+	public $reg_steps;
2291
+
2292
+	/**
2293
+	 * Whether registration confirmation should be the last page of SPCO
2294
+	 *
2295
+	 * @var boolean $reg_confirmation_last
2296
+	 */
2297
+	public $reg_confirmation_last;
2298
+
2299
+	/**
2300
+	 * Whether or not to enable the EE Bot Trap
2301
+	 *
2302
+	 * @var boolean $use_bot_trap
2303
+	 */
2304
+	public $use_bot_trap;
2305
+
2306
+	/**
2307
+	 * Whether or not to encrypt some data sent by the EE Bot Trap
2308
+	 *
2309
+	 * @var boolean $use_encryption
2310
+	 */
2311
+	public $use_encryption;
2312
+
2313
+	/**
2314
+	 * Whether or not to use ReCaptcha
2315
+	 *
2316
+	 * @var boolean $use_captcha
2317
+	 */
2318
+	public $use_captcha;
2319
+
2320
+	/**
2321
+	 * ReCaptcha Theme
2322
+	 *
2323
+	 * @var string $recaptcha_theme
2324
+	 *    options: 'dark    ', 'light'
2325
+	 */
2326
+	public $recaptcha_theme;
2327
+
2328
+	/**
2329
+	 * ReCaptcha Type
2330
+	 *
2331
+	 * @var string $recaptcha_type
2332
+	 *    options: 'audio', 'image'
2333
+	 */
2334
+	public $recaptcha_type;
2335
+
2336
+	/**
2337
+	 * ReCaptcha language
2338
+	 *
2339
+	 * @var string $recaptcha_language
2340
+	 * eg 'en'
2341
+	 */
2342
+	public $recaptcha_language;
2343
+
2344
+	/**
2345
+	 * ReCaptcha public key
2346
+	 *
2347
+	 * @var string $recaptcha_publickey
2348
+	 */
2349
+	public $recaptcha_publickey;
2350
+
2351
+	/**
2352
+	 * ReCaptcha private key
2353
+	 *
2354
+	 * @var string $recaptcha_privatekey
2355
+	 */
2356
+	public $recaptcha_privatekey;
2357
+
2358
+	/**
2359
+	 * ReCaptcha width
2360
+	 *
2361
+	 * @var int $recaptcha_width
2362
+	 * @deprecated
2363
+	 */
2364
+	public $recaptcha_width;
2365
+
2366
+	/**
2367
+	 * Whether or not invalid attempts to directly access the registration checkout page should be tracked.
2368
+	 *
2369
+	 * @var boolean $track_invalid_checkout_access
2370
+	 */
2371
+	protected $track_invalid_checkout_access = true;
2372
+
2373
+
2374
+
2375
+	/**
2376
+	 *    class constructor
2377
+	 *
2378
+	 * @access    public
2379
+	 */
2380
+	public function __construct()
2381
+	{
2382
+		// set default registration settings
2383
+		$this->default_STS_ID = EEM_Registration::status_id_pending_payment;
2384
+		$this->email_validation_level = 'wp_default';
2385
+		$this->show_pending_payment_options = true;
2386
+		$this->skip_reg_confirmation = false;
2387
+		$this->reg_steps = array();
2388
+		$this->reg_confirmation_last = false;
2389
+		$this->use_bot_trap = true;
2390
+		$this->use_encryption = true;
2391
+		$this->use_captcha = false;
2392
+		$this->recaptcha_theme = 'light';
2393
+		$this->recaptcha_type = 'image';
2394
+		$this->recaptcha_language = 'en';
2395
+		$this->recaptcha_publickey = null;
2396
+		$this->recaptcha_privatekey = null;
2397
+		$this->recaptcha_width = 500;
2398
+		$this->default_maximum_number_of_tickets = 10;
2399
+	}
2400
+
2401
+
2402
+
2403
+	/**
2404
+	 * This is called by the config loader and hooks are initialized AFTER the config has been populated.
2405
+	 *
2406
+	 * @since 4.8.8.rc.019
2407
+	 */
2408
+	public function do_hooks()
2409
+	{
2410
+		add_action('AHEE__EE_Config___load_core_config__end', array($this, 'set_default_reg_status_on_EEM_Event'));
2411
+		add_action('AHEE__EE_Config___load_core_config__end', array($this, 'set_default_max_ticket_on_EEM_Event'));
2412
+	}
2413
+
2414
+
2415
+
2416
+	/**
2417
+	 * Hooked into `AHEE__EE_Config___load_core_config__end` to ensure the default for the EVT_default_registration_status
2418
+	 * field matches the config setting for default_STS_ID.
2419
+	 */
2420
+	public function set_default_reg_status_on_EEM_Event()
2421
+	{
2422
+		EEM_Event::set_default_reg_status($this->default_STS_ID);
2423
+	}
2424
+
2425
+
2426
+	/**
2427
+	 * Hooked into `AHEE__EE_Config___load_core_config__end` to ensure the default for the EVT_additional_limit field
2428
+	 * for Events matches the config setting for default_maximum_number_of_tickets
2429
+	 */
2430
+	public function set_default_max_ticket_on_EEM_Event()
2431
+	{
2432
+		EEM_Event::set_default_additional_limit($this->default_maximum_number_of_tickets);
2433
+	}
2434
+
2435
+
2436
+
2437
+	/**
2438
+	 * @return boolean
2439
+	 */
2440
+	public function track_invalid_checkout_access()
2441
+	{
2442
+		return $this->track_invalid_checkout_access;
2443
+	}
2444
+
2445
+
2446
+
2447
+	/**
2448
+	 * @param boolean $track_invalid_checkout_access
2449
+	 */
2450
+	public function set_track_invalid_checkout_access($track_invalid_checkout_access)
2451
+	{
2452
+		$this->track_invalid_checkout_access = filter_var(
2453
+			$track_invalid_checkout_access,
2454
+			FILTER_VALIDATE_BOOLEAN
2455
+		);
2456
+	}
2457 2457
 
2458 2458
 
2459 2459
 
@@ -2467,160 +2467,160 @@  discard block
 block discarded – undo
2467 2467
 class EE_Admin_Config extends EE_Config_Base
2468 2468
 {
2469 2469
 
2470
-    /**
2471
-     * @var boolean $use_personnel_manager
2472
-     */
2473
-    public $use_personnel_manager;
2474
-
2475
-    /**
2476
-     * @var boolean $use_dashboard_widget
2477
-     */
2478
-    public $use_dashboard_widget;
2479
-
2480
-    /**
2481
-     * @var int $events_in_dashboard
2482
-     */
2483
-    public $events_in_dashboard;
2484
-
2485
-    /**
2486
-     * @var boolean $use_event_timezones
2487
-     */
2488
-    public $use_event_timezones;
2489
-
2490
-    /**
2491
-     * @var boolean $use_full_logging
2492
-     */
2493
-    public $use_full_logging;
2494
-
2495
-    /**
2496
-     * @var string $log_file_name
2497
-     */
2498
-    public $log_file_name;
2499
-
2500
-    /**
2501
-     * @var string $debug_file_name
2502
-     */
2503
-    public $debug_file_name;
2504
-
2505
-    /**
2506
-     * @var boolean $use_remote_logging
2507
-     */
2508
-    public $use_remote_logging;
2509
-
2510
-    /**
2511
-     * @var string $remote_logging_url
2512
-     */
2513
-    public $remote_logging_url;
2514
-
2515
-    /**
2516
-     * @var boolean $show_reg_footer
2517
-     */
2518
-    public $show_reg_footer;
2519
-
2520
-    /**
2521
-     * @var string $affiliate_id
2522
-     */
2523
-    public $affiliate_id;
2524
-
2525
-    /**
2526
-     * help tours on or off (global setting)
2527
-     *
2528
-     * @var boolean
2529
-     */
2530
-    public $help_tour_activation;
2531
-
2532
-    /**
2533
-     * adds extra layer of encoding to session data to prevent serialization errors
2534
-     * but is incompatible with some server configuration errors
2535
-     * if you get "500 internal server errors" during registration, try turning this on
2536
-     * if you get PHP fatal errors regarding base 64 methods not defined, then turn this off
2537
-     *
2538
-     * @var boolean $encode_session_data
2539
-     */
2540
-    private $encode_session_data = false;
2541
-
2542
-
2543
-
2544
-    /**
2545
-     *    class constructor
2546
-     *
2547
-     * @access    public
2548
-     */
2549
-    public function __construct()
2550
-    {
2551
-        // set default general admin settings
2552
-        $this->use_personnel_manager = true;
2553
-        $this->use_dashboard_widget = true;
2554
-        $this->events_in_dashboard = 30;
2555
-        $this->use_event_timezones = false;
2556
-        $this->use_full_logging = false;
2557
-        $this->use_remote_logging = false;
2558
-        $this->remote_logging_url = null;
2559
-        $this->show_reg_footer = true;
2560
-        $this->affiliate_id = 'default';
2561
-        $this->help_tour_activation = true;
2562
-        $this->encode_session_data = false;
2563
-    }
2564
-
2565
-
2566
-
2567
-    /**
2568
-     * @param bool $reset
2569
-     * @return string
2570
-     */
2571
-    public function log_file_name($reset = false)
2572
-    {
2573
-        if (empty($this->log_file_name) || $reset) {
2574
-            $this->log_file_name = sanitize_key('espresso_log_' . md5(uniqid('', true))) . '.txt';
2575
-            EE_Config::instance()->update_espresso_config(false, false);
2576
-        }
2577
-        return $this->log_file_name;
2578
-    }
2579
-
2580
-
2581
-
2582
-    /**
2583
-     * @param bool $reset
2584
-     * @return string
2585
-     */
2586
-    public function debug_file_name($reset = false)
2587
-    {
2588
-        if (empty($this->debug_file_name) || $reset) {
2589
-            $this->debug_file_name = sanitize_key('espresso_debug_' . md5(uniqid('', true))) . '.txt';
2590
-            EE_Config::instance()->update_espresso_config(false, false);
2591
-        }
2592
-        return $this->debug_file_name;
2593
-    }
2594
-
2595
-
2596
-
2597
-    /**
2598
-     * @return string
2599
-     */
2600
-    public function affiliate_id()
2601
-    {
2602
-        return ! empty($this->affiliate_id) ? $this->affiliate_id : 'default';
2603
-    }
2604
-
2605
-
2606
-
2607
-    /**
2608
-     * @return boolean
2609
-     */
2610
-    public function encode_session_data()
2611
-    {
2612
-        return filter_var($this->encode_session_data, FILTER_VALIDATE_BOOLEAN);
2613
-    }
2614
-
2615
-
2616
-
2617
-    /**
2618
-     * @param boolean $encode_session_data
2619
-     */
2620
-    public function set_encode_session_data($encode_session_data)
2621
-    {
2622
-        $this->encode_session_data = filter_var($encode_session_data, FILTER_VALIDATE_BOOLEAN);
2623
-    }
2470
+	/**
2471
+	 * @var boolean $use_personnel_manager
2472
+	 */
2473
+	public $use_personnel_manager;
2474
+
2475
+	/**
2476
+	 * @var boolean $use_dashboard_widget
2477
+	 */
2478
+	public $use_dashboard_widget;
2479
+
2480
+	/**
2481
+	 * @var int $events_in_dashboard
2482
+	 */
2483
+	public $events_in_dashboard;
2484
+
2485
+	/**
2486
+	 * @var boolean $use_event_timezones
2487
+	 */
2488
+	public $use_event_timezones;
2489
+
2490
+	/**
2491
+	 * @var boolean $use_full_logging
2492
+	 */
2493
+	public $use_full_logging;
2494
+
2495
+	/**
2496
+	 * @var string $log_file_name
2497
+	 */
2498
+	public $log_file_name;
2499
+
2500
+	/**
2501
+	 * @var string $debug_file_name
2502
+	 */
2503
+	public $debug_file_name;
2504
+
2505
+	/**
2506
+	 * @var boolean $use_remote_logging
2507
+	 */
2508
+	public $use_remote_logging;
2509
+
2510
+	/**
2511
+	 * @var string $remote_logging_url
2512
+	 */
2513
+	public $remote_logging_url;
2514
+
2515
+	/**
2516
+	 * @var boolean $show_reg_footer
2517
+	 */
2518
+	public $show_reg_footer;
2519
+
2520
+	/**
2521
+	 * @var string $affiliate_id
2522
+	 */
2523
+	public $affiliate_id;
2524
+
2525
+	/**
2526
+	 * help tours on or off (global setting)
2527
+	 *
2528
+	 * @var boolean
2529
+	 */
2530
+	public $help_tour_activation;
2531
+
2532
+	/**
2533
+	 * adds extra layer of encoding to session data to prevent serialization errors
2534
+	 * but is incompatible with some server configuration errors
2535
+	 * if you get "500 internal server errors" during registration, try turning this on
2536
+	 * if you get PHP fatal errors regarding base 64 methods not defined, then turn this off
2537
+	 *
2538
+	 * @var boolean $encode_session_data
2539
+	 */
2540
+	private $encode_session_data = false;
2541
+
2542
+
2543
+
2544
+	/**
2545
+	 *    class constructor
2546
+	 *
2547
+	 * @access    public
2548
+	 */
2549
+	public function __construct()
2550
+	{
2551
+		// set default general admin settings
2552
+		$this->use_personnel_manager = true;
2553
+		$this->use_dashboard_widget = true;
2554
+		$this->events_in_dashboard = 30;
2555
+		$this->use_event_timezones = false;
2556
+		$this->use_full_logging = false;
2557
+		$this->use_remote_logging = false;
2558
+		$this->remote_logging_url = null;
2559
+		$this->show_reg_footer = true;
2560
+		$this->affiliate_id = 'default';
2561
+		$this->help_tour_activation = true;
2562
+		$this->encode_session_data = false;
2563
+	}
2564
+
2565
+
2566
+
2567
+	/**
2568
+	 * @param bool $reset
2569
+	 * @return string
2570
+	 */
2571
+	public function log_file_name($reset = false)
2572
+	{
2573
+		if (empty($this->log_file_name) || $reset) {
2574
+			$this->log_file_name = sanitize_key('espresso_log_' . md5(uniqid('', true))) . '.txt';
2575
+			EE_Config::instance()->update_espresso_config(false, false);
2576
+		}
2577
+		return $this->log_file_name;
2578
+	}
2579
+
2580
+
2581
+
2582
+	/**
2583
+	 * @param bool $reset
2584
+	 * @return string
2585
+	 */
2586
+	public function debug_file_name($reset = false)
2587
+	{
2588
+		if (empty($this->debug_file_name) || $reset) {
2589
+			$this->debug_file_name = sanitize_key('espresso_debug_' . md5(uniqid('', true))) . '.txt';
2590
+			EE_Config::instance()->update_espresso_config(false, false);
2591
+		}
2592
+		return $this->debug_file_name;
2593
+	}
2594
+
2595
+
2596
+
2597
+	/**
2598
+	 * @return string
2599
+	 */
2600
+	public function affiliate_id()
2601
+	{
2602
+		return ! empty($this->affiliate_id) ? $this->affiliate_id : 'default';
2603
+	}
2604
+
2605
+
2606
+
2607
+	/**
2608
+	 * @return boolean
2609
+	 */
2610
+	public function encode_session_data()
2611
+	{
2612
+		return filter_var($this->encode_session_data, FILTER_VALIDATE_BOOLEAN);
2613
+	}
2614
+
2615
+
2616
+
2617
+	/**
2618
+	 * @param boolean $encode_session_data
2619
+	 */
2620
+	public function set_encode_session_data($encode_session_data)
2621
+	{
2622
+		$this->encode_session_data = filter_var($encode_session_data, FILTER_VALIDATE_BOOLEAN);
2623
+	}
2624 2624
 
2625 2625
 
2626 2626
 
@@ -2634,71 +2634,71 @@  discard block
 block discarded – undo
2634 2634
 class EE_Template_Config extends EE_Config_Base
2635 2635
 {
2636 2636
 
2637
-    /**
2638
-     * @var boolean $enable_default_style
2639
-     */
2640
-    public $enable_default_style;
2641
-
2642
-    /**
2643
-     * @var string $custom_style_sheet
2644
-     */
2645
-    public $custom_style_sheet;
2646
-
2647
-    /**
2648
-     * @var boolean $display_address_in_regform
2649
-     */
2650
-    public $display_address_in_regform;
2651
-
2652
-    /**
2653
-     * @var int $display_description_on_multi_reg_page
2654
-     */
2655
-    public $display_description_on_multi_reg_page;
2656
-
2657
-    /**
2658
-     * @var boolean $use_custom_templates
2659
-     */
2660
-    public $use_custom_templates;
2661
-
2662
-    /**
2663
-     * @var string $current_espresso_theme
2664
-     */
2665
-    public $current_espresso_theme;
2666
-
2667
-    /**
2668
-     * @var EE_Ticket_Selector_Config $EED_Ticket_Selector
2669
-     */
2670
-    public $EED_Ticket_Selector;
2671
-
2672
-    /**
2673
-     * @var EE_Event_Single_Config $EED_Event_Single
2674
-     */
2675
-    public $EED_Event_Single;
2676
-
2677
-    /**
2678
-     * @var EE_Events_Archive_Config $EED_Events_Archive
2679
-     */
2680
-    public $EED_Events_Archive;
2681
-
2682
-
2683
-
2684
-    /**
2685
-     *    class constructor
2686
-     *
2687
-     * @access    public
2688
-     */
2689
-    public function __construct()
2690
-    {
2691
-        // set default template settings
2692
-        $this->enable_default_style = true;
2693
-        $this->custom_style_sheet = null;
2694
-        $this->display_address_in_regform = true;
2695
-        $this->display_description_on_multi_reg_page = false;
2696
-        $this->use_custom_templates = false;
2697
-        $this->current_espresso_theme = 'Espresso_Arabica_2014';
2698
-        $this->EED_Event_Single = null;
2699
-        $this->EED_Events_Archive = null;
2700
-        $this->EED_Ticket_Selector = null;
2701
-    }
2637
+	/**
2638
+	 * @var boolean $enable_default_style
2639
+	 */
2640
+	public $enable_default_style;
2641
+
2642
+	/**
2643
+	 * @var string $custom_style_sheet
2644
+	 */
2645
+	public $custom_style_sheet;
2646
+
2647
+	/**
2648
+	 * @var boolean $display_address_in_regform
2649
+	 */
2650
+	public $display_address_in_regform;
2651
+
2652
+	/**
2653
+	 * @var int $display_description_on_multi_reg_page
2654
+	 */
2655
+	public $display_description_on_multi_reg_page;
2656
+
2657
+	/**
2658
+	 * @var boolean $use_custom_templates
2659
+	 */
2660
+	public $use_custom_templates;
2661
+
2662
+	/**
2663
+	 * @var string $current_espresso_theme
2664
+	 */
2665
+	public $current_espresso_theme;
2666
+
2667
+	/**
2668
+	 * @var EE_Ticket_Selector_Config $EED_Ticket_Selector
2669
+	 */
2670
+	public $EED_Ticket_Selector;
2671
+
2672
+	/**
2673
+	 * @var EE_Event_Single_Config $EED_Event_Single
2674
+	 */
2675
+	public $EED_Event_Single;
2676
+
2677
+	/**
2678
+	 * @var EE_Events_Archive_Config $EED_Events_Archive
2679
+	 */
2680
+	public $EED_Events_Archive;
2681
+
2682
+
2683
+
2684
+	/**
2685
+	 *    class constructor
2686
+	 *
2687
+	 * @access    public
2688
+	 */
2689
+	public function __construct()
2690
+	{
2691
+		// set default template settings
2692
+		$this->enable_default_style = true;
2693
+		$this->custom_style_sheet = null;
2694
+		$this->display_address_in_regform = true;
2695
+		$this->display_description_on_multi_reg_page = false;
2696
+		$this->use_custom_templates = false;
2697
+		$this->current_espresso_theme = 'Espresso_Arabica_2014';
2698
+		$this->EED_Event_Single = null;
2699
+		$this->EED_Events_Archive = null;
2700
+		$this->EED_Ticket_Selector = null;
2701
+	}
2702 2702
 
2703 2703
 }
2704 2704
 
@@ -2710,115 +2710,115 @@  discard block
 block discarded – undo
2710 2710
 class EE_Map_Config extends EE_Config_Base
2711 2711
 {
2712 2712
 
2713
-    /**
2714
-     * @var boolean $use_google_maps
2715
-     */
2716
-    public $use_google_maps;
2717
-
2718
-    /**
2719
-     * @var string $api_key
2720
-     */
2721
-    public $google_map_api_key;
2722
-
2723
-    /**
2724
-     * @var int $event_details_map_width
2725
-     */
2726
-    public $event_details_map_width;
2727
-
2728
-    /**
2729
-     * @var int $event_details_map_height
2730
-     */
2731
-    public $event_details_map_height;
2732
-
2733
-    /**
2734
-     * @var int $event_details_map_zoom
2735
-     */
2736
-    public $event_details_map_zoom;
2737
-
2738
-    /**
2739
-     * @var boolean $event_details_display_nav
2740
-     */
2741
-    public $event_details_display_nav;
2742
-
2743
-    /**
2744
-     * @var boolean $event_details_nav_size
2745
-     */
2746
-    public $event_details_nav_size;
2747
-
2748
-    /**
2749
-     * @var string $event_details_control_type
2750
-     */
2751
-    public $event_details_control_type;
2752
-
2753
-    /**
2754
-     * @var string $event_details_map_align
2755
-     */
2756
-    public $event_details_map_align;
2757
-
2758
-    /**
2759
-     * @var int $event_list_map_width
2760
-     */
2761
-    public $event_list_map_width;
2762
-
2763
-    /**
2764
-     * @var int $event_list_map_height
2765
-     */
2766
-    public $event_list_map_height;
2767
-
2768
-    /**
2769
-     * @var int $event_list_map_zoom
2770
-     */
2771
-    public $event_list_map_zoom;
2772
-
2773
-    /**
2774
-     * @var boolean $event_list_display_nav
2775
-     */
2776
-    public $event_list_display_nav;
2777
-
2778
-    /**
2779
-     * @var boolean $event_list_nav_size
2780
-     */
2781
-    public $event_list_nav_size;
2782
-
2783
-    /**
2784
-     * @var string $event_list_control_type
2785
-     */
2786
-    public $event_list_control_type;
2787
-
2788
-    /**
2789
-     * @var string $event_list_map_align
2790
-     */
2791
-    public $event_list_map_align;
2792
-
2793
-
2794
-
2795
-    /**
2796
-     *    class constructor
2797
-     *
2798
-     * @access    public
2799
-     */
2800
-    public function __construct()
2801
-    {
2802
-        // set default map settings
2803
-        $this->use_google_maps = true;
2804
-        $this->google_map_api_key = '';
2805
-        // for event details pages (reg page)
2806
-        $this->event_details_map_width = 585;            // ee_map_width_single
2807
-        $this->event_details_map_height = 362;            // ee_map_height_single
2808
-        $this->event_details_map_zoom = 14;            // ee_map_zoom_single
2809
-        $this->event_details_display_nav = true;            // ee_map_nav_display_single
2810
-        $this->event_details_nav_size = false;            // ee_map_nav_size_single
2811
-        $this->event_details_control_type = 'default';        // ee_map_type_control_single
2812
-        $this->event_details_map_align = 'center';            // ee_map_align_single
2813
-        // for event list pages
2814
-        $this->event_list_map_width = 300;            // ee_map_width
2815
-        $this->event_list_map_height = 185;        // ee_map_height
2816
-        $this->event_list_map_zoom = 12;            // ee_map_zoom
2817
-        $this->event_list_display_nav = false;        // ee_map_nav_display
2818
-        $this->event_list_nav_size = true;            // ee_map_nav_size
2819
-        $this->event_list_control_type = 'dropdown';        // ee_map_type_control
2820
-        $this->event_list_map_align = 'center';            // ee_map_align
2821
-    }
2713
+	/**
2714
+	 * @var boolean $use_google_maps
2715
+	 */
2716
+	public $use_google_maps;
2717
+
2718
+	/**
2719
+	 * @var string $api_key
2720
+	 */
2721
+	public $google_map_api_key;
2722
+
2723
+	/**
2724
+	 * @var int $event_details_map_width
2725
+	 */
2726
+	public $event_details_map_width;
2727
+
2728
+	/**
2729
+	 * @var int $event_details_map_height
2730
+	 */
2731
+	public $event_details_map_height;
2732
+
2733
+	/**
2734
+	 * @var int $event_details_map_zoom
2735
+	 */
2736
+	public $event_details_map_zoom;
2737
+
2738
+	/**
2739
+	 * @var boolean $event_details_display_nav
2740
+	 */
2741
+	public $event_details_display_nav;
2742
+
2743
+	/**
2744
+	 * @var boolean $event_details_nav_size
2745
+	 */
2746
+	public $event_details_nav_size;
2747
+
2748
+	/**
2749
+	 * @var string $event_details_control_type
2750
+	 */
2751
+	public $event_details_control_type;
2752
+
2753
+	/**
2754
+	 * @var string $event_details_map_align
2755
+	 */
2756
+	public $event_details_map_align;
2757
+
2758
+	/**
2759
+	 * @var int $event_list_map_width
2760
+	 */
2761
+	public $event_list_map_width;
2762
+
2763
+	/**
2764
+	 * @var int $event_list_map_height
2765
+	 */
2766
+	public $event_list_map_height;
2767
+
2768
+	/**
2769
+	 * @var int $event_list_map_zoom
2770
+	 */
2771
+	public $event_list_map_zoom;
2772
+
2773
+	/**
2774
+	 * @var boolean $event_list_display_nav
2775
+	 */
2776
+	public $event_list_display_nav;
2777
+
2778
+	/**
2779
+	 * @var boolean $event_list_nav_size
2780
+	 */
2781
+	public $event_list_nav_size;
2782
+
2783
+	/**
2784
+	 * @var string $event_list_control_type
2785
+	 */
2786
+	public $event_list_control_type;
2787
+
2788
+	/**
2789
+	 * @var string $event_list_map_align
2790
+	 */
2791
+	public $event_list_map_align;
2792
+
2793
+
2794
+
2795
+	/**
2796
+	 *    class constructor
2797
+	 *
2798
+	 * @access    public
2799
+	 */
2800
+	public function __construct()
2801
+	{
2802
+		// set default map settings
2803
+		$this->use_google_maps = true;
2804
+		$this->google_map_api_key = '';
2805
+		// for event details pages (reg page)
2806
+		$this->event_details_map_width = 585;            // ee_map_width_single
2807
+		$this->event_details_map_height = 362;            // ee_map_height_single
2808
+		$this->event_details_map_zoom = 14;            // ee_map_zoom_single
2809
+		$this->event_details_display_nav = true;            // ee_map_nav_display_single
2810
+		$this->event_details_nav_size = false;            // ee_map_nav_size_single
2811
+		$this->event_details_control_type = 'default';        // ee_map_type_control_single
2812
+		$this->event_details_map_align = 'center';            // ee_map_align_single
2813
+		// for event list pages
2814
+		$this->event_list_map_width = 300;            // ee_map_width
2815
+		$this->event_list_map_height = 185;        // ee_map_height
2816
+		$this->event_list_map_zoom = 12;            // ee_map_zoom
2817
+		$this->event_list_display_nav = false;        // ee_map_nav_display
2818
+		$this->event_list_nav_size = true;            // ee_map_nav_size
2819
+		$this->event_list_control_type = 'dropdown';        // ee_map_type_control
2820
+		$this->event_list_map_align = 'center';            // ee_map_align
2821
+	}
2822 2822
 
2823 2823
 }
2824 2824
 
@@ -2830,47 +2830,47 @@  discard block
 block discarded – undo
2830 2830
 class EE_Events_Archive_Config extends EE_Config_Base
2831 2831
 {
2832 2832
 
2833
-    public $display_status_banner;
2833
+	public $display_status_banner;
2834 2834
 
2835
-    public $display_description;
2835
+	public $display_description;
2836 2836
 
2837
-    public $display_ticket_selector;
2837
+	public $display_ticket_selector;
2838 2838
 
2839
-    public $display_datetimes;
2839
+	public $display_datetimes;
2840 2840
 
2841
-    public $display_venue;
2841
+	public $display_venue;
2842 2842
 
2843
-    public $display_expired_events;
2843
+	public $display_expired_events;
2844 2844
 
2845
-    public $use_sortable_display_order;
2845
+	public $use_sortable_display_order;
2846 2846
 
2847
-    public $display_order_tickets;
2847
+	public $display_order_tickets;
2848 2848
 
2849
-    public $display_order_datetimes;
2849
+	public $display_order_datetimes;
2850 2850
 
2851
-    public $display_order_event;
2851
+	public $display_order_event;
2852 2852
 
2853
-    public $display_order_venue;
2853
+	public $display_order_venue;
2854 2854
 
2855 2855
 
2856 2856
 
2857
-    /**
2858
-     *    class constructor
2859
-     */
2860
-    public function __construct()
2861
-    {
2862
-        $this->display_status_banner = 0;
2863
-        $this->display_description = 1;
2864
-        $this->display_ticket_selector = 0;
2865
-        $this->display_datetimes = 1;
2866
-        $this->display_venue = 0;
2867
-        $this->display_expired_events = 0;
2868
-        $this->use_sortable_display_order = false;
2869
-        $this->display_order_tickets = 100;
2870
-        $this->display_order_datetimes = 110;
2871
-        $this->display_order_event = 120;
2872
-        $this->display_order_venue = 130;
2873
-    }
2857
+	/**
2858
+	 *    class constructor
2859
+	 */
2860
+	public function __construct()
2861
+	{
2862
+		$this->display_status_banner = 0;
2863
+		$this->display_description = 1;
2864
+		$this->display_ticket_selector = 0;
2865
+		$this->display_datetimes = 1;
2866
+		$this->display_venue = 0;
2867
+		$this->display_expired_events = 0;
2868
+		$this->use_sortable_display_order = false;
2869
+		$this->display_order_tickets = 100;
2870
+		$this->display_order_datetimes = 110;
2871
+		$this->display_order_event = 120;
2872
+		$this->display_order_venue = 130;
2873
+	}
2874 2874
 }
2875 2875
 
2876 2876
 
@@ -2881,35 +2881,35 @@  discard block
 block discarded – undo
2881 2881
 class EE_Event_Single_Config extends EE_Config_Base
2882 2882
 {
2883 2883
 
2884
-    public $display_status_banner_single;
2884
+	public $display_status_banner_single;
2885 2885
 
2886
-    public $display_venue;
2886
+	public $display_venue;
2887 2887
 
2888
-    public $use_sortable_display_order;
2888
+	public $use_sortable_display_order;
2889 2889
 
2890
-    public $display_order_tickets;
2890
+	public $display_order_tickets;
2891 2891
 
2892
-    public $display_order_datetimes;
2892
+	public $display_order_datetimes;
2893 2893
 
2894
-    public $display_order_event;
2894
+	public $display_order_event;
2895 2895
 
2896
-    public $display_order_venue;
2896
+	public $display_order_venue;
2897 2897
 
2898 2898
 
2899 2899
 
2900
-    /**
2901
-     *    class constructor
2902
-     */
2903
-    public function __construct()
2904
-    {
2905
-        $this->display_status_banner_single = 0;
2906
-        $this->display_venue = 1;
2907
-        $this->use_sortable_display_order = false;
2908
-        $this->display_order_tickets = 100;
2909
-        $this->display_order_datetimes = 110;
2910
-        $this->display_order_event = 120;
2911
-        $this->display_order_venue = 130;
2912
-    }
2900
+	/**
2901
+	 *    class constructor
2902
+	 */
2903
+	public function __construct()
2904
+	{
2905
+		$this->display_status_banner_single = 0;
2906
+		$this->display_venue = 1;
2907
+		$this->use_sortable_display_order = false;
2908
+		$this->display_order_tickets = 100;
2909
+		$this->display_order_datetimes = 110;
2910
+		$this->display_order_event = 120;
2911
+		$this->display_order_venue = 130;
2912
+	}
2913 2913
 }
2914 2914
 
2915 2915
 
@@ -2920,152 +2920,152 @@  discard block
 block discarded – undo
2920 2920
 class EE_Ticket_Selector_Config extends EE_Config_Base
2921 2921
 {
2922 2922
 
2923
-    /**
2924
-     * constant to indicate that a datetime selector should NEVER be shown for ticket selectors
2925
-     */
2926
-    const DO_NOT_SHOW_DATETIME_SELECTOR = 'no_datetime_selector';
2927
-
2928
-    /**
2929
-     * constant to indicate that a datetime selector should only be shown for ticket selectors
2930
-     * when the number of datetimes for the event matches the value set for $datetime_selector_threshold
2931
-     */
2932
-    const MAYBE_SHOW_DATETIME_SELECTOR = 'maybe_datetime_selector';
2933
-
2934
-    /**
2935
-     * @var boolean $show_ticket_sale_columns
2936
-     */
2937
-    public $show_ticket_sale_columns;
2938
-
2939
-    /**
2940
-     * @var boolean $show_ticket_details
2941
-     */
2942
-    public $show_ticket_details;
2943
-
2944
-    /**
2945
-     * @var boolean $show_expired_tickets
2946
-     */
2947
-    public $show_expired_tickets;
2948
-
2949
-    /**
2950
-     * whether or not to display a dropdown box populated with event datetimes
2951
-     * that toggles which tickets are displayed for a ticket selector.
2952
-     * uses one of the *_DATETIME_SELECTOR constants defined above
2953
-     *
2954
-     * @var string $show_datetime_selector
2955
-     */
2956
-    private $show_datetime_selector = 'no_datetime_selector';
2957
-
2958
-    /**
2959
-     * the number of datetimes an event has to have before conditionally displaying a datetime selector
2960
-     *
2961
-     * @var int $datetime_selector_threshold
2962
-     */
2963
-    private $datetime_selector_threshold = 3;
2964
-
2965
-
2966
-
2967
-    /**
2968
-     *    class constructor
2969
-     */
2970
-    public function __construct()
2971
-    {
2972
-        $this->show_ticket_sale_columns = true;
2973
-        $this->show_ticket_details = true;
2974
-        $this->show_expired_tickets = true;
2975
-        $this->show_datetime_selector = \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR;
2976
-        $this->datetime_selector_threshold = 3;
2977
-    }
2978
-
2979
-
2980
-
2981
-    /**
2982
-     * returns true if a datetime selector should be displayed
2983
-     *
2984
-     * @param array $datetimes
2985
-     * @return bool
2986
-     */
2987
-    public function showDatetimeSelector(array $datetimes)
2988
-    {
2989
-        // if the settings are NOT: don't show OR below threshold, THEN active = true
2990
-        return ! (
2991
-            $this->getShowDatetimeSelector() === \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR
2992
-            || (
2993
-                $this->getShowDatetimeSelector() === \EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR
2994
-                && count($datetimes) < $this->getDatetimeSelectorThreshold()
2995
-            )
2996
-        );
2997
-    }
2998
-
2999
-
3000
-
3001
-    /**
3002
-     * @return string
3003
-     */
3004
-    public function getShowDatetimeSelector()
3005
-    {
3006
-        return $this->show_datetime_selector;
3007
-    }
3008
-
3009
-
3010
-
3011
-    /**
3012
-     * @param bool $keys_only
3013
-     * @return array
3014
-     */
3015
-    public function getShowDatetimeSelectorOptions($keys_only = true)
3016
-    {
3017
-        return $keys_only
3018
-            ? array(
3019
-                \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR,
3020
-                \EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR,
3021
-            )
3022
-            : array(
3023
-                \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR => esc_html__(
3024
-                    'Do not show date & time filter', 'event_espresso'
3025
-                ),
3026
-                \EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR  => esc_html__(
3027
-                    'Maybe show date & time filter', 'event_espresso'
3028
-                ),
3029
-            );
3030
-    }
3031
-
3032
-
3033
-
3034
-    /**
3035
-     * @param string $show_datetime_selector
3036
-     */
3037
-    public function setShowDatetimeSelector($show_datetime_selector)
3038
-    {
3039
-        $this->show_datetime_selector = in_array(
3040
-            $show_datetime_selector,
3041
-            $this->getShowDatetimeSelectorOptions(),
3042
-            true
3043
-        )
3044
-            ? $show_datetime_selector
3045
-            : \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR;
3046
-    }
3047
-
3048
-
3049
-
3050
-    /**
3051
-     * @return int
3052
-     */
3053
-    public function getDatetimeSelectorThreshold()
3054
-    {
3055
-        return $this->datetime_selector_threshold;
3056
-    }
3057
-
3058
-
3059
-
3060
-
3061
-    /**
3062
-     * @param int $datetime_selector_threshold
3063
-     */
3064
-    public function setDatetimeSelectorThreshold($datetime_selector_threshold)
3065
-    {
3066
-        $datetime_selector_threshold = absint($datetime_selector_threshold);
3067
-        $this->datetime_selector_threshold = $datetime_selector_threshold ? $datetime_selector_threshold : 3;
3068
-    }
2923
+	/**
2924
+	 * constant to indicate that a datetime selector should NEVER be shown for ticket selectors
2925
+	 */
2926
+	const DO_NOT_SHOW_DATETIME_SELECTOR = 'no_datetime_selector';
2927
+
2928
+	/**
2929
+	 * constant to indicate that a datetime selector should only be shown for ticket selectors
2930
+	 * when the number of datetimes for the event matches the value set for $datetime_selector_threshold
2931
+	 */
2932
+	const MAYBE_SHOW_DATETIME_SELECTOR = 'maybe_datetime_selector';
2933
+
2934
+	/**
2935
+	 * @var boolean $show_ticket_sale_columns
2936
+	 */
2937
+	public $show_ticket_sale_columns;
2938
+
2939
+	/**
2940
+	 * @var boolean $show_ticket_details
2941
+	 */
2942
+	public $show_ticket_details;
2943
+
2944
+	/**
2945
+	 * @var boolean $show_expired_tickets
2946
+	 */
2947
+	public $show_expired_tickets;
2948
+
2949
+	/**
2950
+	 * whether or not to display a dropdown box populated with event datetimes
2951
+	 * that toggles which tickets are displayed for a ticket selector.
2952
+	 * uses one of the *_DATETIME_SELECTOR constants defined above
2953
+	 *
2954
+	 * @var string $show_datetime_selector
2955
+	 */
2956
+	private $show_datetime_selector = 'no_datetime_selector';
2957
+
2958
+	/**
2959
+	 * the number of datetimes an event has to have before conditionally displaying a datetime selector
2960
+	 *
2961
+	 * @var int $datetime_selector_threshold
2962
+	 */
2963
+	private $datetime_selector_threshold = 3;
2964
+
2965
+
2966
+
2967
+	/**
2968
+	 *    class constructor
2969
+	 */
2970
+	public function __construct()
2971
+	{
2972
+		$this->show_ticket_sale_columns = true;
2973
+		$this->show_ticket_details = true;
2974
+		$this->show_expired_tickets = true;
2975
+		$this->show_datetime_selector = \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR;
2976
+		$this->datetime_selector_threshold = 3;
2977
+	}
2978
+
2979
+
2980
+
2981
+	/**
2982
+	 * returns true if a datetime selector should be displayed
2983
+	 *
2984
+	 * @param array $datetimes
2985
+	 * @return bool
2986
+	 */
2987
+	public function showDatetimeSelector(array $datetimes)
2988
+	{
2989
+		// if the settings are NOT: don't show OR below threshold, THEN active = true
2990
+		return ! (
2991
+			$this->getShowDatetimeSelector() === \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR
2992
+			|| (
2993
+				$this->getShowDatetimeSelector() === \EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR
2994
+				&& count($datetimes) < $this->getDatetimeSelectorThreshold()
2995
+			)
2996
+		);
2997
+	}
2998
+
2999
+
3000
+
3001
+	/**
3002
+	 * @return string
3003
+	 */
3004
+	public function getShowDatetimeSelector()
3005
+	{
3006
+		return $this->show_datetime_selector;
3007
+	}
3008
+
3009
+
3010
+
3011
+	/**
3012
+	 * @param bool $keys_only
3013
+	 * @return array
3014
+	 */
3015
+	public function getShowDatetimeSelectorOptions($keys_only = true)
3016
+	{
3017
+		return $keys_only
3018
+			? array(
3019
+				\EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR,
3020
+				\EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR,
3021
+			)
3022
+			: array(
3023
+				\EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR => esc_html__(
3024
+					'Do not show date & time filter', 'event_espresso'
3025
+				),
3026
+				\EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR  => esc_html__(
3027
+					'Maybe show date & time filter', 'event_espresso'
3028
+				),
3029
+			);
3030
+	}
3031
+
3032
+
3033
+
3034
+	/**
3035
+	 * @param string $show_datetime_selector
3036
+	 */
3037
+	public function setShowDatetimeSelector($show_datetime_selector)
3038
+	{
3039
+		$this->show_datetime_selector = in_array(
3040
+			$show_datetime_selector,
3041
+			$this->getShowDatetimeSelectorOptions(),
3042
+			true
3043
+		)
3044
+			? $show_datetime_selector
3045
+			: \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR;
3046
+	}
3047
+
3048
+
3049
+
3050
+	/**
3051
+	 * @return int
3052
+	 */
3053
+	public function getDatetimeSelectorThreshold()
3054
+	{
3055
+		return $this->datetime_selector_threshold;
3056
+	}
3057
+
3058
+
3059
+
3060
+
3061
+	/**
3062
+	 * @param int $datetime_selector_threshold
3063
+	 */
3064
+	public function setDatetimeSelectorThreshold($datetime_selector_threshold)
3065
+	{
3066
+		$datetime_selector_threshold = absint($datetime_selector_threshold);
3067
+		$this->datetime_selector_threshold = $datetime_selector_threshold ? $datetime_selector_threshold : 3;
3068
+	}
3069 3069
 
3070 3070
 
3071 3071
 
@@ -3083,85 +3083,85 @@  discard block
 block discarded – undo
3083 3083
 class EE_Environment_Config extends EE_Config_Base
3084 3084
 {
3085 3085
 
3086
-    /**
3087
-     * Hold any php environment variables that we want to track.
3088
-     *
3089
-     * @var stdClass;
3090
-     */
3091
-    public $php;
3092
-
3093
-
3094
-
3095
-    /**
3096
-     *    constructor
3097
-     */
3098
-    public function __construct()
3099
-    {
3100
-        $this->php = new stdClass();
3101
-        $this->_set_php_values();
3102
-    }
3103
-
3104
-
3105
-
3106
-    /**
3107
-     * This sets the php environment variables.
3108
-     *
3109
-     * @since 4.4.0
3110
-     * @return void
3111
-     */
3112
-    protected function _set_php_values()
3113
-    {
3114
-        $this->php->max_input_vars = ini_get('max_input_vars');
3115
-        $this->php->version = phpversion();
3116
-    }
3117
-
3118
-
3119
-
3120
-    /**
3121
-     * helper method for determining whether input_count is
3122
-     * reaching the potential maximum the server can handle
3123
-     * according to max_input_vars
3124
-     *
3125
-     * @param int   $input_count the count of input vars.
3126
-     * @return array {
3127
-     *                           An array that represents whether available space and if no available space the error
3128
-     *                           message.
3129
-     * @type bool   $has_space   whether more inputs can be added.
3130
-     * @type string $msg         Any message to be displayed.
3131
-     *                           }
3132
-     */
3133
-    public function max_input_vars_limit_check($input_count = 0)
3134
-    {
3135
-        if (! empty($this->php->max_input_vars)
3136
-            && ($input_count >= $this->php->max_input_vars)
3137
-            && (PHP_MAJOR_VERSION >= 5 && PHP_MINOR_VERSION >= 3 && PHP_RELEASE_VERSION >= 9)
3138
-        ) {
3139
-            return sprintf(
3140
-                __(
3141
-                    'The maximum number of inputs on this page has been exceeded.  You cannot add anymore items (i.e. tickets, datetimes, custom fields) on this page because of your servers PHP "max_input_vars" setting.%1$sThere are %2$d inputs and the maximum amount currently allowed by your server is %3$d.',
3142
-                    'event_espresso'
3143
-                ),
3144
-                '<br>',
3145
-                $input_count,
3146
-                $this->php->max_input_vars
3147
-            );
3148
-        } else {
3149
-            return '';
3150
-        }
3151
-    }
3152
-
3153
-
3154
-
3155
-    /**
3156
-     * The purpose of this method is just to force rechecking php values so if they've changed, they get updated.
3157
-     *
3158
-     * @since 4.4.1
3159
-     * @return void
3160
-     */
3161
-    public function recheck_values()
3162
-    {
3163
-        $this->_set_php_values();
3164
-    }
3086
+	/**
3087
+	 * Hold any php environment variables that we want to track.
3088
+	 *
3089
+	 * @var stdClass;
3090
+	 */
3091
+	public $php;
3092
+
3093
+
3094
+
3095
+	/**
3096
+	 *    constructor
3097
+	 */
3098
+	public function __construct()
3099
+	{
3100
+		$this->php = new stdClass();
3101
+		$this->_set_php_values();
3102
+	}
3103
+
3104
+
3105
+
3106
+	/**
3107
+	 * This sets the php environment variables.
3108
+	 *
3109
+	 * @since 4.4.0
3110
+	 * @return void
3111
+	 */
3112
+	protected function _set_php_values()
3113
+	{
3114
+		$this->php->max_input_vars = ini_get('max_input_vars');
3115
+		$this->php->version = phpversion();
3116
+	}
3117
+
3118
+
3119
+
3120
+	/**
3121
+	 * helper method for determining whether input_count is
3122
+	 * reaching the potential maximum the server can handle
3123
+	 * according to max_input_vars
3124
+	 *
3125
+	 * @param int   $input_count the count of input vars.
3126
+	 * @return array {
3127
+	 *                           An array that represents whether available space and if no available space the error
3128
+	 *                           message.
3129
+	 * @type bool   $has_space   whether more inputs can be added.
3130
+	 * @type string $msg         Any message to be displayed.
3131
+	 *                           }
3132
+	 */
3133
+	public function max_input_vars_limit_check($input_count = 0)
3134
+	{
3135
+		if (! empty($this->php->max_input_vars)
3136
+			&& ($input_count >= $this->php->max_input_vars)
3137
+			&& (PHP_MAJOR_VERSION >= 5 && PHP_MINOR_VERSION >= 3 && PHP_RELEASE_VERSION >= 9)
3138
+		) {
3139
+			return sprintf(
3140
+				__(
3141
+					'The maximum number of inputs on this page has been exceeded.  You cannot add anymore items (i.e. tickets, datetimes, custom fields) on this page because of your servers PHP "max_input_vars" setting.%1$sThere are %2$d inputs and the maximum amount currently allowed by your server is %3$d.',
3142
+					'event_espresso'
3143
+				),
3144
+				'<br>',
3145
+				$input_count,
3146
+				$this->php->max_input_vars
3147
+			);
3148
+		} else {
3149
+			return '';
3150
+		}
3151
+	}
3152
+
3153
+
3154
+
3155
+	/**
3156
+	 * The purpose of this method is just to force rechecking php values so if they've changed, they get updated.
3157
+	 *
3158
+	 * @since 4.4.1
3159
+	 * @return void
3160
+	 */
3161
+	public function recheck_values()
3162
+	{
3163
+		$this->_set_php_values();
3164
+	}
3165 3165
 
3166 3166
 
3167 3167
 
@@ -3179,22 +3179,22 @@  discard block
 block discarded – undo
3179 3179
 class EE_Tax_Config extends EE_Config_Base
3180 3180
 {
3181 3181
 
3182
-    /*
3182
+	/*
3183 3183
      * flag to indicate whether or not to display ticket prices with the taxes included
3184 3184
      *
3185 3185
      * @var boolean $prices_displayed_including_taxes
3186 3186
      */
3187
-    public $prices_displayed_including_taxes;
3187
+	public $prices_displayed_including_taxes;
3188 3188
 
3189 3189
 
3190 3190
 
3191
-    /**
3192
-     *    class constructor
3193
-     */
3194
-    public function __construct()
3195
-    {
3196
-        $this->prices_displayed_including_taxes = true;
3197
-    }
3191
+	/**
3192
+	 *    class constructor
3193
+	 */
3194
+	public function __construct()
3195
+	{
3196
+		$this->prices_displayed_including_taxes = true;
3197
+	}
3198 3198
 }
3199 3199
 
3200 3200
 
@@ -3209,17 +3209,17 @@  discard block
 block discarded – undo
3209 3209
 class EE_Messages_Config extends EE_Config_Base
3210 3210
 {
3211 3211
 
3212
-    /**
3213
-     * This is an integer representing the deletion threshold in months for when old messages will get deleted.
3214
-     * A value of 0 represents never deleting.  Default is 0.
3215
-     *
3216
-     * @var integer
3217
-     */
3218
-    public $delete_threshold;
3219
-
3220
-    public function __construct() {
3221
-        $this->delete_threshold = 0;
3222
-    }
3212
+	/**
3213
+	 * This is an integer representing the deletion threshold in months for when old messages will get deleted.
3214
+	 * A value of 0 represents never deleting.  Default is 0.
3215
+	 *
3216
+	 * @var integer
3217
+	 */
3218
+	public $delete_threshold;
3219
+
3220
+	public function __construct() {
3221
+		$this->delete_threshold = 0;
3222
+	}
3223 3223
 }
3224 3224
 
3225 3225
 
@@ -3231,34 +3231,34 @@  discard block
 block discarded – undo
3231 3231
 class EE_Gateway_Config extends EE_Config_Base
3232 3232
 {
3233 3233
 
3234
-    /**
3235
-     * Array with keys that are payment gateways slugs, and values are arrays
3236
-     * with any config info the gateway wants to store
3237
-     *
3238
-     * @var array
3239
-     */
3240
-    public $payment_settings;
3241
-
3242
-    /**
3243
-     * Where keys are gateway slugs, and values are booleans indicating whether or not
3244
-     * the gateway is stored in the uploads directory
3245
-     *
3246
-     * @var array
3247
-     */
3248
-    public $active_gateways;
3249
-
3250
-
3251
-
3252
-    /**
3253
-     *    class constructor
3254
-     *
3255
-     * @deprecated
3256
-     */
3257
-    public function __construct()
3258
-    {
3259
-        $this->payment_settings = array();
3260
-        $this->active_gateways = array('Invoice' => false);
3261
-    }
3234
+	/**
3235
+	 * Array with keys that are payment gateways slugs, and values are arrays
3236
+	 * with any config info the gateway wants to store
3237
+	 *
3238
+	 * @var array
3239
+	 */
3240
+	public $payment_settings;
3241
+
3242
+	/**
3243
+	 * Where keys are gateway slugs, and values are booleans indicating whether or not
3244
+	 * the gateway is stored in the uploads directory
3245
+	 *
3246
+	 * @var array
3247
+	 */
3248
+	public $active_gateways;
3249
+
3250
+
3251
+
3252
+	/**
3253
+	 *    class constructor
3254
+	 *
3255
+	 * @deprecated
3256
+	 */
3257
+	public function __construct()
3258
+	{
3259
+		$this->payment_settings = array();
3260
+		$this->active_gateways = array('Invoice' => false);
3261
+	}
3262 3262
 }
3263 3263
 
3264 3264
 // End of file EE_Config.core.php
Please login to merge, or discard this patch.
core/EE_Cart.core.php 1 patch
Indentation   +413 added lines, -413 removed lines patch added patch discarded remove patch
@@ -2,7 +2,7 @@  discard block
 block discarded – undo
2 2
 use EventEspresso\core\interfaces\ResettableInterface;
3 3
 
4 4
 if ( ! defined('EVENT_ESPRESSO_VERSION')) {
5
-    exit('No direct script access allowed');
5
+	exit('No direct script access allowed');
6 6
 }
7 7
 do_action('AHEE_log', __FILE__, __FUNCTION__, '');
8 8
 
@@ -23,418 +23,418 @@  discard block
 block discarded – undo
23 23
 class EE_Cart implements ResettableInterface
24 24
 {
25 25
 
26
-    /**
27
-     * instance of the EE_Cart object
28
-     *
29
-     * @access    private
30
-     * @var EE_Cart $_instance
31
-     */
32
-    private static $_instance;
33
-
34
-    /**
35
-     * instance of the EE_Session object
36
-     *
37
-     * @access    protected
38
-     * @var EE_Session $_session
39
-     */
40
-    protected $_session;
41
-
42
-    /**
43
-     * The total Line item which comprises all the children line-item subtotals,
44
-     * which in turn each have their line items.
45
-     * Typically, the line item structure will look like:
46
-     * grand total
47
-     * -tickets-sub-total
48
-     * --ticket1
49
-     * --ticket2
50
-     * --...
51
-     * -taxes-sub-total
52
-     * --tax1
53
-     * --tax2
54
-     *
55
-     * @var EE_Line_Item
56
-     */
57
-    private $_grand_total;
58
-
59
-
60
-
61
-    /**
62
-     * @singleton method used to instantiate class object
63
-     * @access    public
64
-     * @param EE_Line_Item $grand_total
65
-     * @param EE_Session   $session
66
-     * @return \EE_Cart
67
-     * @throws \EE_Error
68
-     */
69
-    public static function instance(EE_Line_Item $grand_total = null, EE_Session $session = null)
70
-    {
71
-        if ( ! empty($grand_total)) {
72
-            self::$_instance = new self($grand_total, $session);
73
-        }
74
-        // or maybe retrieve an existing one ?
75
-        if ( ! self::$_instance instanceof EE_Cart) {
76
-            // try getting the cart out of the session
77
-            $saved_cart = $session instanceof EE_Session ? $session->cart() : null;
78
-            self::$_instance = $saved_cart instanceof EE_Cart ? $saved_cart : new self($grand_total, $session);
79
-            unset($saved_cart);
80
-        }
81
-        // verify that cart is ok and grand total line item exists
82
-        if ( ! self::$_instance instanceof EE_Cart || ! self::$_instance->_grand_total instanceof EE_Line_Item) {
83
-            self::$_instance = new self($grand_total, $session);
84
-        }
85
-        self::$_instance->get_grand_total();
86
-        // once everything is all said and done, save the cart to the EE_Session
87
-        add_action('shutdown', array(self::$_instance, 'save_cart'), 90);
88
-        return self::$_instance;
89
-    }
90
-
91
-
92
-
93
-    /**
94
-     * private constructor to prevent direct creation
95
-     *
96
-     * @Constructor
97
-     * @access private
98
-     * @param EE_Line_Item $grand_total
99
-     * @param EE_Session   $session
100
-     */
101
-    private function __construct(EE_Line_Item $grand_total = null, EE_Session $session = null)
102
-    {
103
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
104
-        $this->set_session($session);
105
-        if ($grand_total instanceof EE_Line_Item) {
106
-            $this->set_grand_total_line_item($grand_total);
107
-        }
108
-    }
109
-
110
-
111
-
112
-    /**
113
-     * Resets the cart completely (whereas empty_cart
114
-     *
115
-     * @param EE_Line_Item $grand_total
116
-     * @param EE_Session   $session
117
-     * @return EE_Cart
118
-     * @throws \EE_Error
119
-     */
120
-    public static function reset(EE_Line_Item $grand_total = null, EE_Session $session = null)
121
-    {
122
-        remove_action('shutdown', array(self::$_instance, 'save_cart'), 90);
123
-        if ($session instanceof EE_Session) {
124
-            $session->reset_cart();
125
-        }
126
-        self::$_instance = null;
127
-        return self::instance($grand_total, $session);
128
-    }
129
-
130
-
131
-
132
-    /**
133
-     * @return \EE_Session
134
-     */
135
-    public function session()
136
-    {
137
-        if ( ! $this->_session instanceof EE_Session) {
138
-            $this->set_session();
139
-        }
140
-        return $this->_session;
141
-    }
142
-
143
-
144
-
145
-    /**
146
-     * @param EE_Session $session
147
-     */
148
-    public function set_session(EE_Session $session = null)
149
-    {
150
-        $this->_session = $session instanceof EE_Session ? $session : EE_Registry::instance()->load_core('Session');
151
-    }
152
-
153
-
154
-
155
-    /**
156
-     * Sets the cart to match the line item. Especially handy for loading an old cart where you
157
-     *  know the grand total line item on it
158
-     *
159
-     * @param EE_Line_Item $line_item
160
-     */
161
-    public function set_grand_total_line_item(EE_Line_Item $line_item)
162
-    {
163
-        $this->_grand_total = $line_item;
164
-    }
165
-
166
-
167
-
168
-    /**
169
-     * get_cart_from_reg_url_link
170
-     *
171
-     * @access public
172
-     * @param EE_Transaction $transaction
173
-     * @param EE_Session     $session
174
-     * @return \EE_Cart
175
-     * @throws \EE_Error
176
-     */
177
-    public static function get_cart_from_txn(EE_Transaction $transaction, EE_Session $session = null)
178
-    {
179
-        $grand_total = $transaction->total_line_item();
180
-        $grand_total->get_items();
181
-        $grand_total->tax_descendants();
182
-        return EE_Cart::instance($grand_total, $session);
183
-    }
184
-
185
-
186
-
187
-    /**
188
-     * Creates the total line item, and ensures it has its 'tickets' and 'taxes' sub-items
189
-     *
190
-     * @return EE_Line_Item
191
-     * @throws \EE_Error
192
-     */
193
-    private function _create_grand_total()
194
-    {
195
-        $this->_grand_total = EEH_Line_Item::create_total_line_item();
196
-        return $this->_grand_total;
197
-    }
198
-
199
-
200
-
201
-    /**
202
-     * Gets all the line items of object type Ticket
203
-     *
204
-     * @access public
205
-     * @return \EE_Line_Item[]
206
-     */
207
-    public function get_tickets()
208
-    {
209
-        if ($this->_grand_total === null ) {
210
-            return array();
211
-        }
212
-        return EEH_Line_Item::get_ticket_line_items($this->_grand_total);
213
-    }
214
-
215
-
216
-
217
-    /**
218
-     * returns the total quantity of tickets in the cart
219
-     *
220
-     * @access public
221
-     * @return int
222
-     * @throws \EE_Error
223
-     */
224
-    public function all_ticket_quantity_count()
225
-    {
226
-        $tickets = $this->get_tickets();
227
-        if (empty($tickets)) {
228
-            return 0;
229
-        }
230
-        $count = 0;
231
-        foreach ($tickets as $ticket) {
232
-            $count += $ticket->get('LIN_quantity');
233
-        }
234
-        return $count;
235
-    }
236
-
237
-
238
-
239
-    /**
240
-     * Gets all the tax line items
241
-     *
242
-     * @return \EE_Line_Item[]
243
-     * @throws \EE_Error
244
-     */
245
-    public function get_taxes()
246
-    {
247
-        return EEH_Line_Item::get_taxes_subtotal($this->_grand_total)->children();
248
-    }
249
-
250
-
251
-
252
-    /**
253
-     * Gets the total line item (which is a parent of all other line items) on this cart
254
-     *
255
-     * @return EE_Line_Item
256
-     * @throws \EE_Error
257
-     */
258
-    public function get_grand_total()
259
-    {
260
-        return $this->_grand_total instanceof EE_Line_Item ? $this->_grand_total : $this->_create_grand_total();
261
-    }
262
-
263
-
264
-
265
-    /**
266
-     * @process items for adding to cart
267
-     * @access  public
268
-     * @param EE_Ticket $ticket
269
-     * @param int       $qty
270
-     * @return TRUE on success, FALSE on fail
271
-     * @throws \EE_Error
272
-     */
273
-    public function add_ticket_to_cart(EE_Ticket $ticket, $qty = 1)
274
-    {
275
-        EEH_Line_Item::add_ticket_purchase($this->get_grand_total(), $ticket, $qty);
276
-        return $this->save_cart() ? true : false;
277
-    }
278
-
279
-
280
-
281
-    /**
282
-     * get_cart_total_before_tax
283
-     *
284
-     * @access public
285
-     * @return float
286
-     * @throws \EE_Error
287
-     */
288
-    public function get_cart_total_before_tax()
289
-    {
290
-        return $this->get_grand_total()->recalculate_pre_tax_total();
291
-    }
292
-
293
-
294
-
295
-    /**
296
-     * gets the total amount of tax paid for items in this cart
297
-     *
298
-     * @access public
299
-     * @return float
300
-     * @throws \EE_Error
301
-     */
302
-    public function get_applied_taxes()
303
-    {
304
-        return EEH_Line_Item::ensure_taxes_applied($this->_grand_total);
305
-    }
306
-
307
-
308
-
309
-    /**
310
-     * Gets the total amount to be paid for the items in the cart, including taxes and other modifiers
311
-     *
312
-     * @access public
313
-     * @return float
314
-     * @throws \EE_Error
315
-     */
316
-    public function get_cart_grand_total()
317
-    {
318
-        EEH_Line_Item::ensure_taxes_applied($this->_grand_total);
319
-        return $this->get_grand_total()->total();
320
-    }
321
-
322
-
323
-
324
-    /**
325
-     * Gets the total amount to be paid for the items in the cart, including taxes and other modifiers
326
-     *
327
-     * @access public
328
-     * @return float
329
-     * @throws \EE_Error
330
-     */
331
-    public function recalculate_all_cart_totals()
332
-    {
333
-        $pre_tax_total = $this->get_cart_total_before_tax();
334
-        $taxes_total = EEH_Line_Item::ensure_taxes_applied($this->_grand_total);
335
-        $this->_grand_total->set_total($pre_tax_total + $taxes_total);
336
-        $this->_grand_total->save_this_and_descendants_to_txn();
337
-        return $this->get_grand_total()->total();
338
-    }
339
-
340
-
341
-
342
-    /**
343
-     * deletes an item from the cart
344
-     *
345
-     * @access public
346
-     * @param array|bool|string $line_item_codes
347
-     * @return int on success, FALSE on fail
348
-     * @throws \EE_Error
349
-     */
350
-    public function delete_items($line_item_codes = false)
351
-    {
352
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
353
-        return EEH_Line_Item::delete_items($this->get_grand_total(), $line_item_codes);
354
-    }
355
-
356
-
357
-
358
-    /**
359
-     * @remove ALL items from cart and zero ALL totals
360
-     * @access public
361
-     * @return bool
362
-     * @throws \EE_Error
363
-     */
364
-    public function empty_cart()
365
-    {
366
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
367
-        $this->_grand_total = $this->_create_grand_total();
368
-        return $this->save_cart(true);
369
-    }
370
-
371
-
372
-
373
-    /**
374
-     * @remove ALL items from cart and delete total as well
375
-     * @access public
376
-     * @return bool
377
-     * @throws \EE_Error
378
-     */
379
-    public function delete_cart()
380
-    {
381
-        $deleted = EEH_Line_Item::delete_all_child_items($this->_grand_total);
382
-        if ($deleted) {
383
-            $deleted += $this->_grand_total->delete();
384
-            $this->_grand_total = null;
385
-        }
386
-        return $deleted;
387
-    }
388
-
389
-
390
-
391
-    /**
392
-     * @save   cart to session
393
-     * @access public
394
-     * @param bool $apply_taxes
395
-     * @return TRUE on success, FALSE on fail
396
-     * @throws \EE_Error
397
-     */
398
-    public function save_cart($apply_taxes = true)
399
-    {
400
-        if ($apply_taxes && $this->_grand_total instanceof EE_Line_Item) {
401
-            EEH_Line_Item::ensure_taxes_applied($this->_grand_total);
402
-            //make sure we don't cache the transaction because it can get stale
403
-            if ($this->_grand_total->get_one_from_cache('Transaction') instanceof EE_Transaction
404
-                && $this->_grand_total->get_one_from_cache('Transaction')->ID()
405
-            ) {
406
-                $this->_grand_total->clear_cache('Transaction', null, true);
407
-            }
408
-        }
409
-        if ($this->session() instanceof EE_Session) {
410
-            return $this->session()->set_cart($this);
411
-        } else {
412
-            return false;
413
-        }
414
-    }
415
-
416
-
417
-
418
-    public function __wakeup()
419
-    {
420
-        if ( ! $this->_grand_total instanceof EE_Line_Item && absint($this->_grand_total) !== 0) {
421
-            // $this->_grand_total is actually just an ID, so use it to get the object from the db
422
-            $this->_grand_total = EEM_Line_Item::instance()->get_one_by_ID($this->_grand_total);
423
-        }
424
-    }
425
-
426
-
427
-
428
-    /**
429
-     * @return array
430
-     */
431
-    public function __sleep()
432
-    {
433
-        if ($this->_grand_total instanceof EE_Line_Item && $this->_grand_total->ID()) {
434
-            $this->_grand_total = $this->_grand_total->ID();
435
-        }
436
-        return array('_grand_total');
437
-    }
26
+	/**
27
+	 * instance of the EE_Cart object
28
+	 *
29
+	 * @access    private
30
+	 * @var EE_Cart $_instance
31
+	 */
32
+	private static $_instance;
33
+
34
+	/**
35
+	 * instance of the EE_Session object
36
+	 *
37
+	 * @access    protected
38
+	 * @var EE_Session $_session
39
+	 */
40
+	protected $_session;
41
+
42
+	/**
43
+	 * The total Line item which comprises all the children line-item subtotals,
44
+	 * which in turn each have their line items.
45
+	 * Typically, the line item structure will look like:
46
+	 * grand total
47
+	 * -tickets-sub-total
48
+	 * --ticket1
49
+	 * --ticket2
50
+	 * --...
51
+	 * -taxes-sub-total
52
+	 * --tax1
53
+	 * --tax2
54
+	 *
55
+	 * @var EE_Line_Item
56
+	 */
57
+	private $_grand_total;
58
+
59
+
60
+
61
+	/**
62
+	 * @singleton method used to instantiate class object
63
+	 * @access    public
64
+	 * @param EE_Line_Item $grand_total
65
+	 * @param EE_Session   $session
66
+	 * @return \EE_Cart
67
+	 * @throws \EE_Error
68
+	 */
69
+	public static function instance(EE_Line_Item $grand_total = null, EE_Session $session = null)
70
+	{
71
+		if ( ! empty($grand_total)) {
72
+			self::$_instance = new self($grand_total, $session);
73
+		}
74
+		// or maybe retrieve an existing one ?
75
+		if ( ! self::$_instance instanceof EE_Cart) {
76
+			// try getting the cart out of the session
77
+			$saved_cart = $session instanceof EE_Session ? $session->cart() : null;
78
+			self::$_instance = $saved_cart instanceof EE_Cart ? $saved_cart : new self($grand_total, $session);
79
+			unset($saved_cart);
80
+		}
81
+		// verify that cart is ok and grand total line item exists
82
+		if ( ! self::$_instance instanceof EE_Cart || ! self::$_instance->_grand_total instanceof EE_Line_Item) {
83
+			self::$_instance = new self($grand_total, $session);
84
+		}
85
+		self::$_instance->get_grand_total();
86
+		// once everything is all said and done, save the cart to the EE_Session
87
+		add_action('shutdown', array(self::$_instance, 'save_cart'), 90);
88
+		return self::$_instance;
89
+	}
90
+
91
+
92
+
93
+	/**
94
+	 * private constructor to prevent direct creation
95
+	 *
96
+	 * @Constructor
97
+	 * @access private
98
+	 * @param EE_Line_Item $grand_total
99
+	 * @param EE_Session   $session
100
+	 */
101
+	private function __construct(EE_Line_Item $grand_total = null, EE_Session $session = null)
102
+	{
103
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
104
+		$this->set_session($session);
105
+		if ($grand_total instanceof EE_Line_Item) {
106
+			$this->set_grand_total_line_item($grand_total);
107
+		}
108
+	}
109
+
110
+
111
+
112
+	/**
113
+	 * Resets the cart completely (whereas empty_cart
114
+	 *
115
+	 * @param EE_Line_Item $grand_total
116
+	 * @param EE_Session   $session
117
+	 * @return EE_Cart
118
+	 * @throws \EE_Error
119
+	 */
120
+	public static function reset(EE_Line_Item $grand_total = null, EE_Session $session = null)
121
+	{
122
+		remove_action('shutdown', array(self::$_instance, 'save_cart'), 90);
123
+		if ($session instanceof EE_Session) {
124
+			$session->reset_cart();
125
+		}
126
+		self::$_instance = null;
127
+		return self::instance($grand_total, $session);
128
+	}
129
+
130
+
131
+
132
+	/**
133
+	 * @return \EE_Session
134
+	 */
135
+	public function session()
136
+	{
137
+		if ( ! $this->_session instanceof EE_Session) {
138
+			$this->set_session();
139
+		}
140
+		return $this->_session;
141
+	}
142
+
143
+
144
+
145
+	/**
146
+	 * @param EE_Session $session
147
+	 */
148
+	public function set_session(EE_Session $session = null)
149
+	{
150
+		$this->_session = $session instanceof EE_Session ? $session : EE_Registry::instance()->load_core('Session');
151
+	}
152
+
153
+
154
+
155
+	/**
156
+	 * Sets the cart to match the line item. Especially handy for loading an old cart where you
157
+	 *  know the grand total line item on it
158
+	 *
159
+	 * @param EE_Line_Item $line_item
160
+	 */
161
+	public function set_grand_total_line_item(EE_Line_Item $line_item)
162
+	{
163
+		$this->_grand_total = $line_item;
164
+	}
165
+
166
+
167
+
168
+	/**
169
+	 * get_cart_from_reg_url_link
170
+	 *
171
+	 * @access public
172
+	 * @param EE_Transaction $transaction
173
+	 * @param EE_Session     $session
174
+	 * @return \EE_Cart
175
+	 * @throws \EE_Error
176
+	 */
177
+	public static function get_cart_from_txn(EE_Transaction $transaction, EE_Session $session = null)
178
+	{
179
+		$grand_total = $transaction->total_line_item();
180
+		$grand_total->get_items();
181
+		$grand_total->tax_descendants();
182
+		return EE_Cart::instance($grand_total, $session);
183
+	}
184
+
185
+
186
+
187
+	/**
188
+	 * Creates the total line item, and ensures it has its 'tickets' and 'taxes' sub-items
189
+	 *
190
+	 * @return EE_Line_Item
191
+	 * @throws \EE_Error
192
+	 */
193
+	private function _create_grand_total()
194
+	{
195
+		$this->_grand_total = EEH_Line_Item::create_total_line_item();
196
+		return $this->_grand_total;
197
+	}
198
+
199
+
200
+
201
+	/**
202
+	 * Gets all the line items of object type Ticket
203
+	 *
204
+	 * @access public
205
+	 * @return \EE_Line_Item[]
206
+	 */
207
+	public function get_tickets()
208
+	{
209
+		if ($this->_grand_total === null ) {
210
+			return array();
211
+		}
212
+		return EEH_Line_Item::get_ticket_line_items($this->_grand_total);
213
+	}
214
+
215
+
216
+
217
+	/**
218
+	 * returns the total quantity of tickets in the cart
219
+	 *
220
+	 * @access public
221
+	 * @return int
222
+	 * @throws \EE_Error
223
+	 */
224
+	public function all_ticket_quantity_count()
225
+	{
226
+		$tickets = $this->get_tickets();
227
+		if (empty($tickets)) {
228
+			return 0;
229
+		}
230
+		$count = 0;
231
+		foreach ($tickets as $ticket) {
232
+			$count += $ticket->get('LIN_quantity');
233
+		}
234
+		return $count;
235
+	}
236
+
237
+
238
+
239
+	/**
240
+	 * Gets all the tax line items
241
+	 *
242
+	 * @return \EE_Line_Item[]
243
+	 * @throws \EE_Error
244
+	 */
245
+	public function get_taxes()
246
+	{
247
+		return EEH_Line_Item::get_taxes_subtotal($this->_grand_total)->children();
248
+	}
249
+
250
+
251
+
252
+	/**
253
+	 * Gets the total line item (which is a parent of all other line items) on this cart
254
+	 *
255
+	 * @return EE_Line_Item
256
+	 * @throws \EE_Error
257
+	 */
258
+	public function get_grand_total()
259
+	{
260
+		return $this->_grand_total instanceof EE_Line_Item ? $this->_grand_total : $this->_create_grand_total();
261
+	}
262
+
263
+
264
+
265
+	/**
266
+	 * @process items for adding to cart
267
+	 * @access  public
268
+	 * @param EE_Ticket $ticket
269
+	 * @param int       $qty
270
+	 * @return TRUE on success, FALSE on fail
271
+	 * @throws \EE_Error
272
+	 */
273
+	public function add_ticket_to_cart(EE_Ticket $ticket, $qty = 1)
274
+	{
275
+		EEH_Line_Item::add_ticket_purchase($this->get_grand_total(), $ticket, $qty);
276
+		return $this->save_cart() ? true : false;
277
+	}
278
+
279
+
280
+
281
+	/**
282
+	 * get_cart_total_before_tax
283
+	 *
284
+	 * @access public
285
+	 * @return float
286
+	 * @throws \EE_Error
287
+	 */
288
+	public function get_cart_total_before_tax()
289
+	{
290
+		return $this->get_grand_total()->recalculate_pre_tax_total();
291
+	}
292
+
293
+
294
+
295
+	/**
296
+	 * gets the total amount of tax paid for items in this cart
297
+	 *
298
+	 * @access public
299
+	 * @return float
300
+	 * @throws \EE_Error
301
+	 */
302
+	public function get_applied_taxes()
303
+	{
304
+		return EEH_Line_Item::ensure_taxes_applied($this->_grand_total);
305
+	}
306
+
307
+
308
+
309
+	/**
310
+	 * Gets the total amount to be paid for the items in the cart, including taxes and other modifiers
311
+	 *
312
+	 * @access public
313
+	 * @return float
314
+	 * @throws \EE_Error
315
+	 */
316
+	public function get_cart_grand_total()
317
+	{
318
+		EEH_Line_Item::ensure_taxes_applied($this->_grand_total);
319
+		return $this->get_grand_total()->total();
320
+	}
321
+
322
+
323
+
324
+	/**
325
+	 * Gets the total amount to be paid for the items in the cart, including taxes and other modifiers
326
+	 *
327
+	 * @access public
328
+	 * @return float
329
+	 * @throws \EE_Error
330
+	 */
331
+	public function recalculate_all_cart_totals()
332
+	{
333
+		$pre_tax_total = $this->get_cart_total_before_tax();
334
+		$taxes_total = EEH_Line_Item::ensure_taxes_applied($this->_grand_total);
335
+		$this->_grand_total->set_total($pre_tax_total + $taxes_total);
336
+		$this->_grand_total->save_this_and_descendants_to_txn();
337
+		return $this->get_grand_total()->total();
338
+	}
339
+
340
+
341
+
342
+	/**
343
+	 * deletes an item from the cart
344
+	 *
345
+	 * @access public
346
+	 * @param array|bool|string $line_item_codes
347
+	 * @return int on success, FALSE on fail
348
+	 * @throws \EE_Error
349
+	 */
350
+	public function delete_items($line_item_codes = false)
351
+	{
352
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
353
+		return EEH_Line_Item::delete_items($this->get_grand_total(), $line_item_codes);
354
+	}
355
+
356
+
357
+
358
+	/**
359
+	 * @remove ALL items from cart and zero ALL totals
360
+	 * @access public
361
+	 * @return bool
362
+	 * @throws \EE_Error
363
+	 */
364
+	public function empty_cart()
365
+	{
366
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
367
+		$this->_grand_total = $this->_create_grand_total();
368
+		return $this->save_cart(true);
369
+	}
370
+
371
+
372
+
373
+	/**
374
+	 * @remove ALL items from cart and delete total as well
375
+	 * @access public
376
+	 * @return bool
377
+	 * @throws \EE_Error
378
+	 */
379
+	public function delete_cart()
380
+	{
381
+		$deleted = EEH_Line_Item::delete_all_child_items($this->_grand_total);
382
+		if ($deleted) {
383
+			$deleted += $this->_grand_total->delete();
384
+			$this->_grand_total = null;
385
+		}
386
+		return $deleted;
387
+	}
388
+
389
+
390
+
391
+	/**
392
+	 * @save   cart to session
393
+	 * @access public
394
+	 * @param bool $apply_taxes
395
+	 * @return TRUE on success, FALSE on fail
396
+	 * @throws \EE_Error
397
+	 */
398
+	public function save_cart($apply_taxes = true)
399
+	{
400
+		if ($apply_taxes && $this->_grand_total instanceof EE_Line_Item) {
401
+			EEH_Line_Item::ensure_taxes_applied($this->_grand_total);
402
+			//make sure we don't cache the transaction because it can get stale
403
+			if ($this->_grand_total->get_one_from_cache('Transaction') instanceof EE_Transaction
404
+				&& $this->_grand_total->get_one_from_cache('Transaction')->ID()
405
+			) {
406
+				$this->_grand_total->clear_cache('Transaction', null, true);
407
+			}
408
+		}
409
+		if ($this->session() instanceof EE_Session) {
410
+			return $this->session()->set_cart($this);
411
+		} else {
412
+			return false;
413
+		}
414
+	}
415
+
416
+
417
+
418
+	public function __wakeup()
419
+	{
420
+		if ( ! $this->_grand_total instanceof EE_Line_Item && absint($this->_grand_total) !== 0) {
421
+			// $this->_grand_total is actually just an ID, so use it to get the object from the db
422
+			$this->_grand_total = EEM_Line_Item::instance()->get_one_by_ID($this->_grand_total);
423
+		}
424
+	}
425
+
426
+
427
+
428
+	/**
429
+	 * @return array
430
+	 */
431
+	public function __sleep()
432
+	{
433
+		if ($this->_grand_total instanceof EE_Line_Item && $this->_grand_total->ID()) {
434
+			$this->_grand_total = $this->_grand_total->ID();
435
+		}
436
+		return array('_grand_total');
437
+	}
438 438
 
439 439
 
440 440
 }
Please login to merge, or discard this patch.