Completed
Branch master (44537d)
by
unknown
14:30 queued 10:03
created
core/db_classes/EE_Change_Log.class.php 2 patches
Indentation   +227 added lines, -227 removed lines patch added patch discarded remove patch
@@ -10,231 +10,231 @@
 block discarded – undo
10 10
  */
11 11
 class EE_Change_Log extends EE_Base_Class
12 12
 {
13
-    /**
14
-     * @param array  $props_n_values          incoming values
15
-     * @param string $timezone                incoming timezone (if not set the timezone set for the website will be
16
-     *                                        used.)
17
-     * @param array  $date_formats            incoming date_formats in an array where the first value is the
18
-     *                                        date_format and the second value is the time format
19
-     * @return EE_Change_Log
20
-     * @throws EE_Error
21
-     */
22
-    public static function new_instance($props_n_values = [], $timezone = '', $date_formats = [])
23
-    {
24
-        $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats);
25
-        return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats);
26
-    }
27
-
28
-
29
-    /**
30
-     * @param array  $props_n_values  incoming values from the database
31
-     * @param string $timezone        incoming timezone as set by the model.  If not set the timezone for
32
-     *                                the website will be used.
33
-     * @return EE_Change_Log
34
-     */
35
-    public static function new_instance_from_db($props_n_values = [], $timezone = '')
36
-    {
37
-        return new self($props_n_values, true, $timezone);
38
-    }
39
-
40
-
41
-    /**
42
-     * Gets message
43
-     *
44
-     * @return mixed
45
-     * @throws EE_Error
46
-     */
47
-    public function message()
48
-    {
49
-        return $this->get('LOG_message');
50
-    }
51
-
52
-
53
-    /**
54
-     * Sets message
55
-     *
56
-     * @param mixed $message
57
-     * @throws EE_Error
58
-     */
59
-    public function set_message($message)
60
-    {
61
-        $this->set('LOG_message', $message);
62
-    }
63
-
64
-
65
-    /**
66
-     * Gets time
67
-     *
68
-     * @return string
69
-     * @throws EE_Error
70
-     */
71
-    public function time()
72
-    {
73
-        return $this->get('LOG_time');
74
-    }
75
-
76
-
77
-    /**
78
-     * Sets time
79
-     *
80
-     * @param string $time
81
-     * @throws EE_Error
82
-     */
83
-    public function set_time($time)
84
-    {
85
-        $this->set('LOG_time', $time);
86
-    }
87
-
88
-
89
-    /**
90
-     * Gets log_type
91
-     *
92
-     * @return string
93
-     * @throws EE_Error
94
-     */
95
-    public function log_type()
96
-    {
97
-        return $this->get('LOG_type');
98
-    }
99
-
100
-
101
-    /**
102
-     * Return the localized log type label.
103
-     *
104
-     * @return string
105
-     * @throws EE_Error
106
-     */
107
-    public function log_type_label()
108
-    {
109
-        return EEM_Change_Log::get_pretty_label_for_type($this->log_type());
110
-    }
111
-
112
-
113
-    /**
114
-     * Sets log_type
115
-     *
116
-     * @param string $log_type
117
-     * @throws EE_Error
118
-     */
119
-    public function set_log_type($log_type)
120
-    {
121
-        $this->set('LOG_type', $log_type);
122
-    }
123
-
124
-
125
-    /**
126
-     * Gets type of the model object related to this log
127
-     *
128
-     * @return string
129
-     * @throws EE_Error
130
-     */
131
-    public function OBJ_type()
132
-    {
133
-        return $this->get('OBJ_type');
134
-    }
135
-
136
-
137
-    /**
138
-     * Sets type
139
-     *
140
-     * @param string $type
141
-     * @throws EE_Error
142
-     */
143
-    public function set_OBJ_type($type)
144
-    {
145
-        $this->set('OBJ_type', $type);
146
-    }
147
-
148
-
149
-    /**
150
-     * Gets OBJ_ID (the ID of the item related to this log)
151
-     *
152
-     * @return mixed
153
-     * @throws EE_Error
154
-     */
155
-    public function OBJ_ID()
156
-    {
157
-        return $this->get('OBJ_ID');
158
-    }
159
-
160
-
161
-    /**
162
-     * Sets OBJ_ID
163
-     *
164
-     * @param mixed $OBJ_ID
165
-     * @throws EE_Error
166
-     */
167
-    public function set_OBJ_ID($OBJ_ID)
168
-    {
169
-        $this->set('OBJ_ID', $OBJ_ID);
170
-    }
171
-
172
-
173
-    /**
174
-     * Gets wp_user
175
-     *
176
-     * @return int
177
-     * @throws EE_Error
178
-     */
179
-    public function wp_user()
180
-    {
181
-        return $this->get('LOG_wp_user');
182
-    }
183
-
184
-
185
-    /**
186
-     * Sets wp_user
187
-     *
188
-     * @param int $wp_user_id
189
-     * @throws EE_Error
190
-     */
191
-    public function set_wp_user($wp_user_id)
192
-    {
193
-        $this->set('LOG_wp_user', $wp_user_id);
194
-    }
195
-
196
-
197
-    /**
198
-     * Gets the model object attached to this log
199
-     *
200
-     * @return EE_Base_Class
201
-     * @throws EE_Error
202
-     */
203
-    public function object()
204
-    {
205
-        $model_name_of_related_obj = $this->OBJ_type() ?? '';
206
-        $is_model_name             = EE_Registry::instance()->is_model_name($model_name_of_related_obj);
207
-        if (! $is_model_name) {
208
-            return null;
209
-        } else {
210
-            return $this->get_first_related($model_name_of_related_obj);
211
-        }
212
-    }
213
-
214
-
215
-    /**
216
-     * Shorthand for setting the OBJ_ID and OBJ_type. Slightly handier than using
217
-     * _add_relation_to because you don't have to specify what type of model you're
218
-     * associating it with
219
-     *
220
-     * @param EE_Base_Class $object
221
-     * @param boolean       $save
222
-     * @return bool if $save=true, NULL is $save=false
223
-     * @throws EE_Error
224
-     */
225
-    public function set_object($object, $save = true)
226
-    {
227
-        if ($object instanceof EE_Base_Class) {
228
-            $this->set_OBJ_type($object->get_model()->get_this_model_name());
229
-            $this->set_OBJ_ID($object->ID());
230
-        } else {
231
-            $this->set_OBJ_type(null);
232
-            $this->set_OBJ_ID(null);
233
-        }
234
-        if ($save) {
235
-            return $this->save();
236
-        } else {
237
-            return null;
238
-        }
239
-    }
13
+	/**
14
+	 * @param array  $props_n_values          incoming values
15
+	 * @param string $timezone                incoming timezone (if not set the timezone set for the website will be
16
+	 *                                        used.)
17
+	 * @param array  $date_formats            incoming date_formats in an array where the first value is the
18
+	 *                                        date_format and the second value is the time format
19
+	 * @return EE_Change_Log
20
+	 * @throws EE_Error
21
+	 */
22
+	public static function new_instance($props_n_values = [], $timezone = '', $date_formats = [])
23
+	{
24
+		$has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats);
25
+		return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats);
26
+	}
27
+
28
+
29
+	/**
30
+	 * @param array  $props_n_values  incoming values from the database
31
+	 * @param string $timezone        incoming timezone as set by the model.  If not set the timezone for
32
+	 *                                the website will be used.
33
+	 * @return EE_Change_Log
34
+	 */
35
+	public static function new_instance_from_db($props_n_values = [], $timezone = '')
36
+	{
37
+		return new self($props_n_values, true, $timezone);
38
+	}
39
+
40
+
41
+	/**
42
+	 * Gets message
43
+	 *
44
+	 * @return mixed
45
+	 * @throws EE_Error
46
+	 */
47
+	public function message()
48
+	{
49
+		return $this->get('LOG_message');
50
+	}
51
+
52
+
53
+	/**
54
+	 * Sets message
55
+	 *
56
+	 * @param mixed $message
57
+	 * @throws EE_Error
58
+	 */
59
+	public function set_message($message)
60
+	{
61
+		$this->set('LOG_message', $message);
62
+	}
63
+
64
+
65
+	/**
66
+	 * Gets time
67
+	 *
68
+	 * @return string
69
+	 * @throws EE_Error
70
+	 */
71
+	public function time()
72
+	{
73
+		return $this->get('LOG_time');
74
+	}
75
+
76
+
77
+	/**
78
+	 * Sets time
79
+	 *
80
+	 * @param string $time
81
+	 * @throws EE_Error
82
+	 */
83
+	public function set_time($time)
84
+	{
85
+		$this->set('LOG_time', $time);
86
+	}
87
+
88
+
89
+	/**
90
+	 * Gets log_type
91
+	 *
92
+	 * @return string
93
+	 * @throws EE_Error
94
+	 */
95
+	public function log_type()
96
+	{
97
+		return $this->get('LOG_type');
98
+	}
99
+
100
+
101
+	/**
102
+	 * Return the localized log type label.
103
+	 *
104
+	 * @return string
105
+	 * @throws EE_Error
106
+	 */
107
+	public function log_type_label()
108
+	{
109
+		return EEM_Change_Log::get_pretty_label_for_type($this->log_type());
110
+	}
111
+
112
+
113
+	/**
114
+	 * Sets log_type
115
+	 *
116
+	 * @param string $log_type
117
+	 * @throws EE_Error
118
+	 */
119
+	public function set_log_type($log_type)
120
+	{
121
+		$this->set('LOG_type', $log_type);
122
+	}
123
+
124
+
125
+	/**
126
+	 * Gets type of the model object related to this log
127
+	 *
128
+	 * @return string
129
+	 * @throws EE_Error
130
+	 */
131
+	public function OBJ_type()
132
+	{
133
+		return $this->get('OBJ_type');
134
+	}
135
+
136
+
137
+	/**
138
+	 * Sets type
139
+	 *
140
+	 * @param string $type
141
+	 * @throws EE_Error
142
+	 */
143
+	public function set_OBJ_type($type)
144
+	{
145
+		$this->set('OBJ_type', $type);
146
+	}
147
+
148
+
149
+	/**
150
+	 * Gets OBJ_ID (the ID of the item related to this log)
151
+	 *
152
+	 * @return mixed
153
+	 * @throws EE_Error
154
+	 */
155
+	public function OBJ_ID()
156
+	{
157
+		return $this->get('OBJ_ID');
158
+	}
159
+
160
+
161
+	/**
162
+	 * Sets OBJ_ID
163
+	 *
164
+	 * @param mixed $OBJ_ID
165
+	 * @throws EE_Error
166
+	 */
167
+	public function set_OBJ_ID($OBJ_ID)
168
+	{
169
+		$this->set('OBJ_ID', $OBJ_ID);
170
+	}
171
+
172
+
173
+	/**
174
+	 * Gets wp_user
175
+	 *
176
+	 * @return int
177
+	 * @throws EE_Error
178
+	 */
179
+	public function wp_user()
180
+	{
181
+		return $this->get('LOG_wp_user');
182
+	}
183
+
184
+
185
+	/**
186
+	 * Sets wp_user
187
+	 *
188
+	 * @param int $wp_user_id
189
+	 * @throws EE_Error
190
+	 */
191
+	public function set_wp_user($wp_user_id)
192
+	{
193
+		$this->set('LOG_wp_user', $wp_user_id);
194
+	}
195
+
196
+
197
+	/**
198
+	 * Gets the model object attached to this log
199
+	 *
200
+	 * @return EE_Base_Class
201
+	 * @throws EE_Error
202
+	 */
203
+	public function object()
204
+	{
205
+		$model_name_of_related_obj = $this->OBJ_type() ?? '';
206
+		$is_model_name             = EE_Registry::instance()->is_model_name($model_name_of_related_obj);
207
+		if (! $is_model_name) {
208
+			return null;
209
+		} else {
210
+			return $this->get_first_related($model_name_of_related_obj);
211
+		}
212
+	}
213
+
214
+
215
+	/**
216
+	 * Shorthand for setting the OBJ_ID and OBJ_type. Slightly handier than using
217
+	 * _add_relation_to because you don't have to specify what type of model you're
218
+	 * associating it with
219
+	 *
220
+	 * @param EE_Base_Class $object
221
+	 * @param boolean       $save
222
+	 * @return bool if $save=true, NULL is $save=false
223
+	 * @throws EE_Error
224
+	 */
225
+	public function set_object($object, $save = true)
226
+	{
227
+		if ($object instanceof EE_Base_Class) {
228
+			$this->set_OBJ_type($object->get_model()->get_this_model_name());
229
+			$this->set_OBJ_ID($object->ID());
230
+		} else {
231
+			$this->set_OBJ_type(null);
232
+			$this->set_OBJ_ID(null);
233
+		}
234
+		if ($save) {
235
+			return $this->save();
236
+		} else {
237
+			return null;
238
+		}
239
+	}
240 240
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -204,7 +204,7 @@
 block discarded – undo
204 204
     {
205 205
         $model_name_of_related_obj = $this->OBJ_type() ?? '';
206 206
         $is_model_name             = EE_Registry::instance()->is_model_name($model_name_of_related_obj);
207
-        if (! $is_model_name) {
207
+        if ( ! $is_model_name) {
208 208
             return null;
209 209
         } else {
210 210
             return $this->get_first_related($model_name_of_related_obj);
Please login to merge, or discard this patch.
core/db_classes/EE_Datetime.class.php 2 patches
Indentation   +1558 added lines, -1558 removed lines patch added patch discarded remove patch
@@ -12,1566 +12,1566 @@
 block discarded – undo
12 12
  */
13 13
 class EE_Datetime extends EE_Soft_Delete_Base_Class
14 14
 {
15
-    /**
16
-     * constant used by get_active_status, indicates datetime has no more available spaces
17
-     */
18
-    const sold_out = 'DTS';
19
-
20
-    /**
21
-     * constant used by get_active_status, indicating datetime is still active (even is not over, can be registered-for)
22
-     */
23
-    const active = 'DTA';
24
-
25
-    /**
26
-     * constant used by get_active_status, indicating the datetime cannot be used for registrations yet, but has not
27
-     * expired
28
-     */
29
-    const upcoming = 'DTU';
30
-
31
-    /**
32
-     * Datetime is postponed
33
-     */
34
-    const postponed = 'DTP';
35
-
36
-    /**
37
-     * Datetime is cancelled
38
-     */
39
-    const cancelled = 'DTC';
40
-
41
-    /**
42
-     * constant used by get_active_status, indicates datetime has expired (event is over)
43
-     */
44
-    const expired = 'DTE';
45
-
46
-    /**
47
-     * constant used in various places indicating that an event is INACTIVE (not yet ready to be published)
48
-     */
49
-    const inactive = 'DTI';
50
-
51
-
52
-    /**
53
-     * @param array  $props_n_values    incoming values
54
-     * @param string $timezone          incoming timezone (if not set the timezone set for the website will be used.)
55
-     * @param array  $date_formats      incoming date_formats in an array where the first value is the date_format
56
-     *                                  and the second value is the time format
57
-     * @return EE_Datetime
58
-     * @throws ReflectionException
59
-     * @throws InvalidArgumentException
60
-     * @throws InvalidInterfaceException
61
-     * @throws InvalidDataTypeException
62
-     * @throws EE_Error
63
-     */
64
-    public static function new_instance($props_n_values = [], $timezone = '', $date_formats = [])
65
-    {
66
-        $has_object = parent::_check_for_object(
67
-            $props_n_values,
68
-            __CLASS__,
69
-            $timezone,
70
-            $date_formats
71
-        );
72
-        return $has_object
73
-            ? $has_object
74
-            : new self($props_n_values, false, $timezone, $date_formats);
75
-    }
76
-
77
-
78
-    /**
79
-     * @param array  $props_n_values  incoming values from the database
80
-     * @param string $timezone        incoming timezone as set by the model.  If not set the timezone for
81
-     *                                the website will be used.
82
-     * @return EE_Datetime
83
-     * @throws ReflectionException
84
-     * @throws InvalidArgumentException
85
-     * @throws InvalidInterfaceException
86
-     * @throws InvalidDataTypeException
87
-     * @throws EE_Error
88
-     */
89
-    public static function new_instance_from_db($props_n_values = [], $timezone = '')
90
-    {
91
-        return new self($props_n_values, true, $timezone);
92
-    }
93
-
94
-
95
-    /**
96
-     * @param $name
97
-     * @throws ReflectionException
98
-     * @throws InvalidArgumentException
99
-     * @throws InvalidInterfaceException
100
-     * @throws InvalidDataTypeException
101
-     * @throws EE_Error
102
-     */
103
-    public function set_name($name)
104
-    {
105
-        $this->set('DTT_name', $name);
106
-    }
107
-
108
-
109
-    /**
110
-     * @param $description
111
-     * @throws ReflectionException
112
-     * @throws InvalidArgumentException
113
-     * @throws InvalidInterfaceException
114
-     * @throws InvalidDataTypeException
115
-     * @throws EE_Error
116
-     */
117
-    public function set_description($description)
118
-    {
119
-        $this->set('DTT_description', $description);
120
-    }
121
-
122
-
123
-    /**
124
-     * Set event start date
125
-     * set the start date for an event
126
-     *
127
-     * @param string $date a string representation of the event's date ex:  Dec. 25, 2025 or 12-25-2025
128
-     * @throws ReflectionException
129
-     * @throws InvalidArgumentException
130
-     * @throws InvalidInterfaceException
131
-     * @throws InvalidDataTypeException
132
-     * @throws EE_Error
133
-     */
134
-    public function set_start_date($date)
135
-    {
136
-        $this->_set_date_for($date, 'DTT_EVT_start');
137
-    }
138
-
139
-
140
-    /**
141
-     * Set event start time
142
-     * set the start time for an event
143
-     *
144
-     * @param string $time a string representation of the event time ex:  9am  or  7:30 PM
145
-     * @throws ReflectionException
146
-     * @throws InvalidArgumentException
147
-     * @throws InvalidInterfaceException
148
-     * @throws InvalidDataTypeException
149
-     * @throws EE_Error
150
-     */
151
-    public function set_start_time($time)
152
-    {
153
-        $this->_set_time_for($time, 'DTT_EVT_start');
154
-    }
155
-
156
-
157
-    /**
158
-     * Set event end date
159
-     * set the end date for an event
160
-     *
161
-     * @param string $date a string representation of the event's date ex:  Dec. 25, 2025 or 12-25-2025
162
-     * @throws ReflectionException
163
-     * @throws InvalidArgumentException
164
-     * @throws InvalidInterfaceException
165
-     * @throws InvalidDataTypeException
166
-     * @throws EE_Error
167
-     */
168
-    public function set_end_date($date)
169
-    {
170
-        $this->_set_date_for($date, 'DTT_EVT_end');
171
-    }
172
-
173
-
174
-    /**
175
-     * Set event end time
176
-     * set the end time for an event
177
-     *
178
-     * @param string $time a string representation of the event time ex:  9am  or  7:30 PM
179
-     * @throws ReflectionException
180
-     * @throws InvalidArgumentException
181
-     * @throws InvalidInterfaceException
182
-     * @throws InvalidDataTypeException
183
-     * @throws EE_Error
184
-     */
185
-    public function set_end_time($time)
186
-    {
187
-        $this->_set_time_for($time, 'DTT_EVT_end');
188
-    }
189
-
190
-
191
-    /**
192
-     * Set registration limit
193
-     * set the maximum number of attendees that can be registered for this datetime slot
194
-     *
195
-     * @param int|float $reg_limit
196
-     * @throws ReflectionException
197
-     * @throws InvalidArgumentException
198
-     * @throws InvalidInterfaceException
199
-     * @throws InvalidDataTypeException
200
-     * @throws EE_Error
201
-     */
202
-    public function set_reg_limit($reg_limit)
203
-    {
204
-        $this->set('DTT_reg_limit', $reg_limit);
205
-    }
206
-
207
-
208
-    /**
209
-     * get the number of tickets sold for this datetime slot
210
-     *
211
-     * @return mixed int on success, FALSE on fail
212
-     * @throws ReflectionException
213
-     * @throws InvalidArgumentException
214
-     * @throws InvalidInterfaceException
215
-     * @throws InvalidDataTypeException
216
-     * @throws EE_Error
217
-     */
218
-    public function sold()
219
-    {
220
-        return $this->get_raw('DTT_sold');
221
-    }
222
-
223
-
224
-    /**
225
-     * @param int $sold
226
-     * @throws ReflectionException
227
-     * @throws InvalidArgumentException
228
-     * @throws InvalidInterfaceException
229
-     * @throws InvalidDataTypeException
230
-     * @throws EE_Error
231
-     */
232
-    public function set_sold($sold)
233
-    {
234
-        // sold can not go below zero
235
-        $sold = max(0, $sold);
236
-        $this->set('DTT_sold', $sold);
237
-    }
238
-
239
-
240
-    /**
241
-     * Increments sold by amount passed by $qty, and persists it immediately to the database.
242
-     * Simultaneously decreases the reserved count, unless $also_decrease_reserved is false.
243
-     *
244
-     * @param int     $qty
245
-     * @param boolean $also_decrease_reserved
246
-     * @return boolean indicating success
247
-     * @throws ReflectionException
248
-     * @throws InvalidArgumentException
249
-     * @throws InvalidInterfaceException
250
-     * @throws InvalidDataTypeException
251
-     * @throws EE_Error
252
-     */
253
-    public function increaseSold(int $qty = 1, bool $also_decrease_reserved = true): bool
254
-    {
255
-        $qty = absint($qty);
256
-        if ($also_decrease_reserved) {
257
-            $success = $this->adjustNumericFieldsInDb(
258
-                [
259
-                    'DTT_reserved' => $qty * -1,
260
-                    'DTT_sold'     => $qty,
261
-                ]
262
-            );
263
-        } else {
264
-            $success = $this->adjustNumericFieldsInDb(
265
-                [
266
-                    'DTT_sold' => $qty,
267
-                ]
268
-            );
269
-        }
270
-
271
-        do_action(
272
-            'AHEE__EE_Datetime__increase_sold',
273
-            $this,
274
-            $qty,
275
-            $this->sold(),
276
-            $success
277
-        );
278
-        return $success;
279
-    }
280
-
281
-
282
-    /**
283
-     * Decrements (subtracts) sold amount passed by $qty directly in the DB and on the model object. (Ie, no need
284
-     * to save afterwards.)
285
-     *
286
-     * @param int $qty
287
-     * @return boolean indicating success
288
-     * @throws ReflectionException
289
-     * @throws InvalidArgumentException
290
-     * @throws InvalidInterfaceException
291
-     * @throws InvalidDataTypeException
292
-     * @throws EE_Error
293
-     */
294
-    public function decreaseSold(int $qty = 1): bool
295
-    {
296
-        $qty     = absint($qty);
297
-        $success = $this->adjustNumericFieldsInDb(
298
-            [
299
-                'DTT_sold' => $qty * -1,
300
-            ]
301
-        );
302
-        do_action(
303
-            'AHEE__EE_Datetime__decrease_sold',
304
-            $this,
305
-            $qty,
306
-            $this->sold(),
307
-            $success
308
-        );
309
-        return $success;
310
-    }
311
-
312
-
313
-    /**
314
-     * Gets qty of reserved tickets for this datetime
315
-     *
316
-     * @return int
317
-     * @throws ReflectionException
318
-     * @throws InvalidArgumentException
319
-     * @throws InvalidInterfaceException
320
-     * @throws InvalidDataTypeException
321
-     * @throws EE_Error
322
-     */
323
-    public function reserved(): int
324
-    {
325
-        return $this->get_raw('DTT_reserved');
326
-    }
327
-
328
-
329
-    /**
330
-     * Sets qty of reserved tickets for this datetime
331
-     *
332
-     * @param int $reserved
333
-     * @throws ReflectionException
334
-     * @throws InvalidArgumentException
335
-     * @throws InvalidInterfaceException
336
-     * @throws InvalidDataTypeException
337
-     * @throws EE_Error
338
-     */
339
-    public function set_reserved(int $reserved)
340
-    {
341
-        // reserved can not go below zero
342
-        $reserved = max(0, $reserved);
343
-        $this->set('DTT_reserved', $reserved);
344
-    }
345
-
346
-
347
-    /**
348
-     * Increments reserved by amount passed by $qty, and persists it immediately to the database.
349
-     *
350
-     * @param int $qty
351
-     * @return boolean indicating success
352
-     * @throws ReflectionException
353
-     * @throws InvalidArgumentException
354
-     * @throws InvalidInterfaceException
355
-     * @throws InvalidDataTypeException
356
-     * @throws EE_Error
357
-     */
358
-    public function increaseReserved(int $qty = 1): bool
359
-    {
360
-        $qty     = absint($qty);
361
-        $success = $this->incrementFieldConditionallyInDb(
362
-            'DTT_reserved',
363
-            'DTT_sold',
364
-            'DTT_reg_limit',
365
-            $qty
366
-        );
367
-        do_action(
368
-            'AHEE__EE_Datetime__increase_reserved',
369
-            $this,
370
-            $qty,
371
-            $this->reserved(),
372
-            $success
373
-        );
374
-        return $success;
375
-    }
376
-
377
-
378
-    /**
379
-     * Decrements (subtracts) reserved by amount passed by $qty, and persists it immediately to the database.
380
-     *
381
-     * @param int $qty
382
-     * @return boolean indicating success
383
-     * @throws ReflectionException
384
-     * @throws InvalidArgumentException
385
-     * @throws InvalidInterfaceException
386
-     * @throws InvalidDataTypeException
387
-     * @throws EE_Error
388
-     */
389
-    public function decreaseReserved(int $qty = 1): bool
390
-    {
391
-        $qty     = absint($qty);
392
-        $success = $this->adjustNumericFieldsInDb(
393
-            [
394
-                'DTT_reserved' => $qty * -1,
395
-            ]
396
-        );
397
-        do_action(
398
-            'AHEE__EE_Datetime__decrease_reserved',
399
-            $this,
400
-            $qty,
401
-            $this->reserved(),
402
-            $success
403
-        );
404
-        return $success;
405
-    }
406
-
407
-
408
-    /**
409
-     * total sold and reserved tickets
410
-     *
411
-     * @return int
412
-     * @throws ReflectionException
413
-     * @throws InvalidArgumentException
414
-     * @throws InvalidInterfaceException
415
-     * @throws InvalidDataTypeException
416
-     * @throws EE_Error
417
-     */
418
-    public function sold_and_reserved(): int
419
-    {
420
-        return $this->sold() + $this->reserved();
421
-    }
422
-
423
-
424
-    /**
425
-     * returns the datetime name
426
-     *
427
-     * @return string
428
-     * @throws ReflectionException
429
-     * @throws InvalidArgumentException
430
-     * @throws InvalidInterfaceException
431
-     * @throws InvalidDataTypeException
432
-     * @throws EE_Error
433
-     */
434
-    public function name(): string
435
-    {
436
-        return $this->get('DTT_name');
437
-    }
438
-
439
-
440
-    /**
441
-     * returns the datetime description
442
-     *
443
-     * @return string
444
-     * @throws ReflectionException
445
-     * @throws InvalidArgumentException
446
-     * @throws InvalidInterfaceException
447
-     * @throws InvalidDataTypeException
448
-     * @throws EE_Error
449
-     */
450
-    public function description(): string
451
-    {
452
-        return $this->get('DTT_description');
453
-    }
454
-
455
-
456
-    /**
457
-     * This helper simply returns whether the event_datetime for the current datetime is a primary datetime
458
-     *
459
-     * @return boolean  TRUE if is primary, FALSE if not.
460
-     * @throws ReflectionException
461
-     * @throws InvalidArgumentException
462
-     * @throws InvalidInterfaceException
463
-     * @throws InvalidDataTypeException
464
-     * @throws EE_Error
465
-     */
466
-    public function is_primary(): bool
467
-    {
468
-        return $this->get('DTT_is_primary');
469
-    }
470
-
471
-
472
-    /**
473
-     * This helper simply returns the order for the datetime
474
-     *
475
-     * @return int  The order of the datetime for this event.
476
-     * @throws ReflectionException
477
-     * @throws InvalidArgumentException
478
-     * @throws InvalidInterfaceException
479
-     * @throws InvalidDataTypeException
480
-     * @throws EE_Error
481
-     */
482
-    public function order(): int
483
-    {
484
-        return $this->get('DTT_order');
485
-    }
486
-
487
-
488
-    /**
489
-     * This helper simply returns the parent id for the datetime
490
-     *
491
-     * @return int
492
-     * @throws ReflectionException
493
-     * @throws InvalidArgumentException
494
-     * @throws InvalidInterfaceException
495
-     * @throws InvalidDataTypeException
496
-     * @throws EE_Error
497
-     */
498
-    public function parent(): int
499
-    {
500
-        return $this->get('DTT_parent');
501
-    }
502
-
503
-
504
-    /**
505
-     * show date and/or time
506
-     *
507
-     * @param string $date_or_time    whether to display a date or time or both
508
-     * @param string $start_or_end    whether to display start or end datetimes
509
-     * @param string $dt_frmt
510
-     * @param string $tm_frmt
511
-     * @param bool   $echo            whether we echo or return (note echoing uses "pretty" formats,
512
-     *                                otherwise we use the standard formats)
513
-     * @return string|bool  string on success, FALSE on fail
514
-     * @throws ReflectionException
515
-     * @throws InvalidArgumentException
516
-     * @throws InvalidInterfaceException
517
-     * @throws InvalidDataTypeException
518
-     * @throws EE_Error
519
-     */
520
-    private function _show_datetime(
521
-        $date_or_time = null,
522
-        $start_or_end = 'start',
523
-        $dt_frmt = '',
524
-        $tm_frmt = '',
525
-        $echo = false
526
-    ) {
527
-        $field_name = "DTT_EVT_{$start_or_end}";
528
-        $dtt        = $this->_get_datetime(
529
-            $field_name,
530
-            $dt_frmt,
531
-            $tm_frmt,
532
-            $date_or_time,
533
-            $echo
534
-        );
535
-        if (! $echo) {
536
-            return $dtt;
537
-        }
538
-        return '';
539
-    }
540
-
541
-
542
-    /**
543
-     * get event start date.  Provide either the date format, or NULL to re-use the
544
-     * last-used format, or '' to use the default date format
545
-     *
546
-     * @param string $dt_frmt string representation of date format defaults to 'F j, Y'
547
-     * @return mixed            string on success, FALSE on fail
548
-     * @throws ReflectionException
549
-     * @throws InvalidArgumentException
550
-     * @throws InvalidInterfaceException
551
-     * @throws InvalidDataTypeException
552
-     * @throws EE_Error
553
-     */
554
-    public function start_date($dt_frmt = '')
555
-    {
556
-        return $this->_show_datetime('D', 'start', $dt_frmt);
557
-    }
558
-
559
-
560
-    /**
561
-     * Echoes start_date()
562
-     *
563
-     * @param string $dt_frmt
564
-     * @throws ReflectionException
565
-     * @throws InvalidArgumentException
566
-     * @throws InvalidInterfaceException
567
-     * @throws InvalidDataTypeException
568
-     * @throws EE_Error
569
-     */
570
-    public function e_start_date($dt_frmt = '')
571
-    {
572
-        $this->_show_datetime('D', 'start', $dt_frmt, null, true);
573
-    }
574
-
575
-
576
-    /**
577
-     * get end date. Provide either the date format, or NULL to re-use the
578
-     * last-used format, or '' to use the default date format
579
-     *
580
-     * @param string $dt_frmt string representation of date format defaults to 'F j, Y'
581
-     * @return mixed            string on success, FALSE on fail
582
-     * @throws ReflectionException
583
-     * @throws InvalidArgumentException
584
-     * @throws InvalidInterfaceException
585
-     * @throws InvalidDataTypeException
586
-     * @throws EE_Error
587
-     */
588
-    public function end_date($dt_frmt = '')
589
-    {
590
-        return $this->_show_datetime('D', 'end', $dt_frmt);
591
-    }
592
-
593
-
594
-    /**
595
-     * Echoes the end date. See end_date()
596
-     *
597
-     * @param string $dt_frmt
598
-     * @throws ReflectionException
599
-     * @throws InvalidArgumentException
600
-     * @throws InvalidInterfaceException
601
-     * @throws InvalidDataTypeException
602
-     * @throws EE_Error
603
-     */
604
-    public function e_end_date($dt_frmt = '')
605
-    {
606
-        $this->_show_datetime('D', 'end', $dt_frmt, null, true);
607
-    }
608
-
609
-
610
-    /**
611
-     * get date_range - meaning the start AND end date
612
-     *
613
-     * @access public
614
-     * @param string $dt_frmt     string representation of date format defaults to WP settings
615
-     * @param string $conjunction conjunction junction what's your function ?
616
-     *                            this string joins the start date with the end date ie: Jan 01 "to" Dec 31
617
-     * @return mixed              string on success, FALSE on fail
618
-     * @throws ReflectionException
619
-     * @throws InvalidArgumentException
620
-     * @throws InvalidInterfaceException
621
-     * @throws InvalidDataTypeException
622
-     * @throws EE_Error
623
-     */
624
-    public function date_range($dt_frmt = '', $conjunction = ' - ')
625
-    {
626
-        $dt_frmt = ! empty($dt_frmt) ? $dt_frmt : $this->_dt_frmt;
627
-        $start   = str_replace(
628
-            ' ',
629
-            ' ',
630
-            $this->get_i18n_datetime('DTT_EVT_start', $dt_frmt)
631
-        );
632
-        $end     = str_replace(
633
-            ' ',
634
-            ' ',
635
-            $this->get_i18n_datetime('DTT_EVT_end', $dt_frmt)
636
-        );
637
-        return $start !== $end ? $start . $conjunction . $end : $start;
638
-    }
639
-
640
-
641
-    /**
642
-     * @param string $dt_frmt
643
-     * @param string $conjunction
644
-     * @throws ReflectionException
645
-     * @throws InvalidArgumentException
646
-     * @throws InvalidInterfaceException
647
-     * @throws InvalidDataTypeException
648
-     * @throws EE_Error
649
-     */
650
-    public function e_date_range($dt_frmt = '', $conjunction = ' - ')
651
-    {
652
-        echo esc_html($this->date_range($dt_frmt, $conjunction));
653
-    }
654
-
655
-
656
-    /**
657
-     * get start time
658
-     *
659
-     * @param string $tm_format - string representation of time format defaults to 'g:i a'
660
-     * @return mixed        string on success, FALSE on fail
661
-     * @throws ReflectionException
662
-     * @throws InvalidArgumentException
663
-     * @throws InvalidInterfaceException
664
-     * @throws InvalidDataTypeException
665
-     * @throws EE_Error
666
-     */
667
-    public function start_time($tm_format = '')
668
-    {
669
-        return $this->_show_datetime('T', 'start', null, $tm_format);
670
-    }
671
-
672
-
673
-    /**
674
-     * @param string $tm_format
675
-     * @throws ReflectionException
676
-     * @throws InvalidArgumentException
677
-     * @throws InvalidInterfaceException
678
-     * @throws InvalidDataTypeException
679
-     * @throws EE_Error
680
-     */
681
-    public function e_start_time($tm_format = '')
682
-    {
683
-        $this->_show_datetime('T', 'start', null, $tm_format, true);
684
-    }
685
-
686
-
687
-    /**
688
-     * get end time
689
-     *
690
-     * @param string $tm_format string representation of time format defaults to 'g:i a'
691
-     * @return mixed                string on success, FALSE on fail
692
-     * @throws ReflectionException
693
-     * @throws InvalidArgumentException
694
-     * @throws InvalidInterfaceException
695
-     * @throws InvalidDataTypeException
696
-     * @throws EE_Error
697
-     */
698
-    public function end_time($tm_format = '')
699
-    {
700
-        return $this->_show_datetime('T', 'end', null, $tm_format);
701
-    }
702
-
703
-
704
-    /**
705
-     * @param string $tm_format
706
-     * @throws ReflectionException
707
-     * @throws InvalidArgumentException
708
-     * @throws InvalidInterfaceException
709
-     * @throws InvalidDataTypeException
710
-     * @throws EE_Error
711
-     */
712
-    public function e_end_time($tm_format = '')
713
-    {
714
-        $this->_show_datetime('T', 'end', null, $tm_format, true);
715
-    }
716
-
717
-
718
-    /**
719
-     * get time_range
720
-     *
721
-     * @access public
722
-     * @param string $tm_format   string representation of time format defaults to 'g:i a'
723
-     * @param string $conjunction conjunction junction what's your function ?
724
-     *                            this string joins the start date with the end date ie: Jan 01 "to" Dec 31
725
-     * @return mixed              string on success, FALSE on fail
726
-     * @throws ReflectionException
727
-     * @throws InvalidArgumentException
728
-     * @throws InvalidInterfaceException
729
-     * @throws InvalidDataTypeException
730
-     * @throws EE_Error
731
-     */
732
-    public function time_range($tm_format = '', $conjunction = ' - ')
733
-    {
734
-        $tm_format = ! empty($tm_format) ? $tm_format : $this->_tm_frmt;
735
-        $start     = str_replace(
736
-            ' ',
737
-            ' ',
738
-            $this->get_i18n_datetime('DTT_EVT_start', $tm_format)
739
-        );
740
-        $end       = str_replace(
741
-            ' ',
742
-            ' ',
743
-            $this->get_i18n_datetime('DTT_EVT_end', $tm_format)
744
-        );
745
-        return $start !== $end ? $start . $conjunction . $end : $start;
746
-    }
747
-
748
-
749
-    /**
750
-     * @param string $tm_format
751
-     * @param string $conjunction
752
-     * @throws ReflectionException
753
-     * @throws InvalidArgumentException
754
-     * @throws InvalidInterfaceException
755
-     * @throws InvalidDataTypeException
756
-     * @throws EE_Error
757
-     */
758
-    public function e_time_range($tm_format = '', $conjunction = ' - ')
759
-    {
760
-        echo esc_html($this->time_range($tm_format, $conjunction));
761
-    }
762
-
763
-
764
-    /**
765
-     * This returns a range representation of the date and times.
766
-     * Output is dependent on the difference (or similarity) between DTT_EVT_start and DTT_EVT_end.
767
-     * Also, the return value is localized.
768
-     *
769
-     * @param string $dt_format
770
-     * @param string $tm_format
771
-     * @param string $conjunction used between two different dates or times.
772
-     *                            ex: Dec 1{$conjunction}}Dec 6, or 2pm{$conjunction}3pm
773
-     * @param string $separator   used between the date and time formats.
774
-     *                            ex: Dec 1, 2016{$separator}2pm
775
-     * @return string
776
-     * @throws ReflectionException
777
-     * @throws InvalidArgumentException
778
-     * @throws InvalidInterfaceException
779
-     * @throws InvalidDataTypeException
780
-     * @throws EE_Error
781
-     */
782
-    public function date_and_time_range(
783
-        $dt_format = '',
784
-        $tm_format = '',
785
-        $conjunction = ' - ',
786
-        $separator = ' '
787
-    ) {
788
-        $dt_format   = ! empty($dt_format) ? $dt_format : $this->_dt_frmt;
789
-        $tm_format   = ! empty($tm_format) ? $tm_format : $this->_tm_frmt;
790
-        $full_format = $dt_format . $separator . $tm_format;
791
-        // the range output depends on various conditions
792
-        switch (true) {
793
-            // start date timestamp and end date timestamp are the same.
794
-            case ($this->get_raw('DTT_EVT_start') === $this->get_raw('DTT_EVT_end')):
795
-                $output = $this->get_i18n_datetime('DTT_EVT_start', $full_format);
796
-                break;
797
-            // start and end date are the same but times are different
798
-            case ($this->start_date() === $this->end_date()):
799
-                $output = $this->get_i18n_datetime('DTT_EVT_start', $full_format)
800
-                          . $conjunction
801
-                          . $this->get_i18n_datetime('DTT_EVT_end', $tm_format);
802
-                break;
803
-            // all other conditions
804
-            default:
805
-                $output = $this->get_i18n_datetime('DTT_EVT_start', $full_format)
806
-                          . $conjunction
807
-                          . $this->get_i18n_datetime('DTT_EVT_end', $full_format);
808
-                break;
809
-        }
810
-        return $output;
811
-    }
812
-
813
-
814
-    /**
815
-     * This echos the results of date and time range.
816
-     *
817
-     * @param string $dt_format
818
-     * @param string $tm_format
819
-     * @param string $conjunction
820
-     * @return void
821
-     * @throws ReflectionException
822
-     * @throws InvalidArgumentException
823
-     * @throws InvalidInterfaceException
824
-     * @throws InvalidDataTypeException
825
-     * @throws EE_Error
826
-     * @see date_and_time_range() for more details on purpose.
827
-     */
828
-    public function e_date_and_time_range($dt_format = '', $tm_format = '', $conjunction = ' - ')
829
-    {
830
-        echo esc_html($this->date_and_time_range($dt_format, $tm_format, $conjunction));
831
-    }
832
-
833
-
834
-    /**
835
-     * get start date and start time
836
-     *
837
-     * @param string $dt_format - string representation of date format defaults to 'F j, Y'
838
-     * @param string $tm_format - string representation of time format defaults to 'g:i a'
839
-     * @return    mixed    string on success, FALSE on fail
840
-     * @throws ReflectionException
841
-     * @throws InvalidArgumentException
842
-     * @throws InvalidInterfaceException
843
-     * @throws InvalidDataTypeException
844
-     * @throws EE_Error
845
-     */
846
-    public function start_date_and_time($dt_format = '', $tm_format = '')
847
-    {
848
-        return $this->_show_datetime('', 'start', $dt_format, $tm_format);
849
-    }
850
-
851
-
852
-    /**
853
-     * @param string $dt_frmt
854
-     * @param string $tm_format
855
-     * @throws ReflectionException
856
-     * @throws InvalidArgumentException
857
-     * @throws InvalidInterfaceException
858
-     * @throws InvalidDataTypeException
859
-     * @throws EE_Error
860
-     */
861
-    public function e_start_date_and_time($dt_frmt = '', $tm_format = '')
862
-    {
863
-        $this->_show_datetime('', 'start', $dt_frmt, $tm_format, true);
864
-    }
865
-
866
-
867
-    /**
868
-     * Shows the length of the event (start to end time).
869
-     * Can be shown in 'seconds','minutes','hours', or 'days'.
870
-     * By default, rounds up. (So if you use 'days', and then event
871
-     * only occurs for 1 hour, it will return 1 day).
872
-     *
873
-     * @param string $units 'seconds','minutes','hours','days'
874
-     * @param bool   $round_up
875
-     * @return float|int|mixed
876
-     * @throws ReflectionException
877
-     * @throws InvalidArgumentException
878
-     * @throws InvalidInterfaceException
879
-     * @throws InvalidDataTypeException
880
-     * @throws EE_Error
881
-     */
882
-    public function length($units = 'seconds', $round_up = false)
883
-    {
884
-        $start           = $this->get_raw('DTT_EVT_start');
885
-        $end             = $this->get_raw('DTT_EVT_end');
886
-        $length_in_units = $end - $start;
887
-        switch ($units) {
888
-            // NOTE: We purposefully don't use "break;" in order to chain the divisions
889
-            /** @noinspection PhpMissingBreakStatementInspection */
890
-            // phpcs:disable PSR2.ControlStructures.SwitchDeclaration.TerminatingComment
891
-            case 'days':
892
-                $length_in_units /= 24;
893
-            /** @noinspection PhpMissingBreakStatementInspection */
894
-            case 'hours':
895
-                // fall through is intentional
896
-                $length_in_units /= 60;
897
-            /** @noinspection PhpMissingBreakStatementInspection */
898
-            case 'minutes':
899
-                // fall through is intentional
900
-                $length_in_units /= 60;
901
-            case 'seconds':
902
-            default:
903
-                $length_in_units = ceil($length_in_units);
904
-        }
905
-        // phpcs:enable
906
-        if ($round_up) {
907
-            $length_in_units = max($length_in_units, 1);
908
-        }
909
-        return $length_in_units;
910
-    }
911
-
912
-
913
-    /**
914
-     *        get end date and time
915
-     *
916
-     * @param string $dt_frmt   - string representation of date format defaults to 'F j, Y'
917
-     * @param string $tm_format - string representation of time format defaults to 'g:i a'
918
-     * @return    mixed                string on success, FALSE on fail
919
-     * @throws ReflectionException
920
-     * @throws InvalidArgumentException
921
-     * @throws InvalidInterfaceException
922
-     * @throws InvalidDataTypeException
923
-     * @throws EE_Error
924
-     */
925
-    public function end_date_and_time($dt_frmt = '', $tm_format = '')
926
-    {
927
-        return $this->_show_datetime('', 'end', $dt_frmt, $tm_format);
928
-    }
929
-
930
-
931
-    /**
932
-     * @param string $dt_frmt
933
-     * @param string $tm_format
934
-     * @throws ReflectionException
935
-     * @throws InvalidArgumentException
936
-     * @throws InvalidInterfaceException
937
-     * @throws InvalidDataTypeException
938
-     * @throws EE_Error
939
-     */
940
-    public function e_end_date_and_time($dt_frmt = '', $tm_format = '')
941
-    {
942
-        $this->_show_datetime('', 'end', $dt_frmt, $tm_format, true);
943
-    }
944
-
945
-
946
-    /**
947
-     *        get start timestamp
948
-     *
949
-     * @return        int
950
-     * @throws ReflectionException
951
-     * @throws InvalidArgumentException
952
-     * @throws InvalidInterfaceException
953
-     * @throws InvalidDataTypeException
954
-     * @throws EE_Error
955
-     */
956
-    public function start()
957
-    {
958
-        return $this->get_raw('DTT_EVT_start');
959
-    }
960
-
961
-
962
-    /**
963
-     *        get end timestamp
964
-     *
965
-     * @return        int
966
-     * @throws ReflectionException
967
-     * @throws InvalidArgumentException
968
-     * @throws InvalidInterfaceException
969
-     * @throws InvalidDataTypeException
970
-     * @throws EE_Error
971
-     */
972
-    public function end()
973
-    {
974
-        return $this->get_raw('DTT_EVT_end');
975
-    }
976
-
977
-
978
-    /**
979
-     *    get the registration limit for this datetime slot
980
-     *
981
-     * @return int|float                int = finite limit   EE_INF(float) = unlimited
982
-     * @throws ReflectionException
983
-     * @throws InvalidArgumentException
984
-     * @throws InvalidInterfaceException
985
-     * @throws InvalidDataTypeException
986
-     * @throws EE_Error
987
-     */
988
-    public function reg_limit()
989
-    {
990
-        return $this->get_raw('DTT_reg_limit');
991
-    }
992
-
993
-
994
-    /**
995
-     *    have the tickets sold for this datetime, met or exceed the registration limit ?
996
-     *
997
-     * @return boolean
998
-     * @throws ReflectionException
999
-     * @throws InvalidArgumentException
1000
-     * @throws InvalidInterfaceException
1001
-     * @throws InvalidDataTypeException
1002
-     * @throws EE_Error
1003
-     */
1004
-    public function sold_out()
1005
-    {
1006
-        return $this->reg_limit() > 0 && $this->sold() >= $this->reg_limit();
1007
-    }
1008
-
1009
-
1010
-    /**
1011
-     * return the total number of spaces remaining at this venue.
1012
-     * This only takes the venue's capacity into account, NOT the tickets available for sale
1013
-     *
1014
-     * @param bool $consider_tickets Whether to consider tickets remaining when determining if there are any spaces left
1015
-     *                               Because if all tickets attached to this datetime have no spaces left,
1016
-     *                               then this datetime IS effectively sold out.
1017
-     *                               However, there are cases where we just want to know the spaces
1018
-     *                               remaining for this particular datetime, hence the flag.
1019
-     * @return int|float
1020
-     * @throws ReflectionException
1021
-     * @throws InvalidArgumentException
1022
-     * @throws InvalidInterfaceException
1023
-     * @throws InvalidDataTypeException
1024
-     * @throws EE_Error
1025
-     */
1026
-    public function spaces_remaining($consider_tickets = false)
1027
-    {
1028
-        // tickets remaining available for purchase
1029
-        // no need for special checks for infinite, because if DTT_reg_limit == EE_INF, then EE_INF - x = EE_INF
1030
-        $dtt_remaining = $this->reg_limit() - $this->sold_and_reserved();
1031
-        if (! $consider_tickets) {
1032
-            return $dtt_remaining;
1033
-        }
1034
-        $tickets_remaining = $this->tickets_remaining();
1035
-        return min($dtt_remaining, $tickets_remaining);
1036
-    }
1037
-
1038
-
1039
-    /**
1040
-     * Counts the total tickets available
1041
-     * (from all the different types of tickets which are available for this datetime).
1042
-     *
1043
-     * @param array $query_params @see
1044
-     *                            https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
1045
-     * @return int
1046
-     * @throws ReflectionException
1047
-     * @throws InvalidArgumentException
1048
-     * @throws InvalidInterfaceException
1049
-     * @throws InvalidDataTypeException
1050
-     * @throws EE_Error
1051
-     */
1052
-    public function tickets_remaining($query_params = [])
1053
-    {
1054
-        $sum     = 0;
1055
-        $tickets = $this->tickets($query_params);
1056
-        if (! empty($tickets)) {
1057
-            foreach ($tickets as $ticket) {
1058
-                if ($ticket instanceof EE_Ticket) {
1059
-                    // get the actual amount of tickets that can be sold
1060
-                    $qty = $ticket->qty('saleable');
1061
-                    if ($qty === EE_INF) {
1062
-                        return EE_INF;
1063
-                    }
1064
-                    // no negative ticket quantities plz
1065
-                    if ($qty > 0) {
1066
-                        $sum += $qty;
1067
-                    }
1068
-                }
1069
-            }
1070
-        }
1071
-        return $sum;
1072
-    }
1073
-
1074
-
1075
-    /**
1076
-     * Gets the count of all the tickets available at this datetime (not ticket types)
1077
-     * before any were sold
1078
-     *
1079
-     * @param array $query_params @see
1080
-     *                            https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
1081
-     * @return int
1082
-     * @throws ReflectionException
1083
-     * @throws InvalidArgumentException
1084
-     * @throws InvalidInterfaceException
1085
-     * @throws InvalidDataTypeException
1086
-     * @throws EE_Error
1087
-     */
1088
-    public function sum_tickets_initially_available($query_params = [])
1089
-    {
1090
-        return $this->sum_related('Ticket', $query_params, 'TKT_qty');
1091
-    }
1092
-
1093
-
1094
-    /**
1095
-     * Returns the lesser-of-the two: spaces remaining at this datetime, or
1096
-     * the total tickets remaining (a sum of the tickets remaining for each ticket type
1097
-     * that is available for this datetime).
1098
-     *
1099
-     * @return int
1100
-     * @throws ReflectionException
1101
-     * @throws InvalidArgumentException
1102
-     * @throws InvalidInterfaceException
1103
-     * @throws InvalidDataTypeException
1104
-     * @throws EE_Error
1105
-     */
1106
-    public function total_tickets_available_at_this_datetime()
1107
-    {
1108
-        return $this->spaces_remaining(true);
1109
-    }
1110
-
1111
-
1112
-    /**
1113
-     * This simply compares the internal dtt for the given string with NOW
1114
-     * and determines if the date is upcoming or not.
1115
-     *
1116
-     * @access public
1117
-     * @return boolean
1118
-     * @throws ReflectionException
1119
-     * @throws InvalidArgumentException
1120
-     * @throws InvalidInterfaceException
1121
-     * @throws InvalidDataTypeException
1122
-     * @throws EE_Error
1123
-     */
1124
-    public function is_upcoming()
1125
-    {
1126
-        return ($this->get_raw('DTT_EVT_start') > time());
1127
-    }
1128
-
1129
-
1130
-    /**
1131
-     * This simply compares the internal datetime for the given string with NOW
1132
-     * and returns if the date is active (i.e. start and end time)
1133
-     *
1134
-     * @return boolean
1135
-     * @throws ReflectionException
1136
-     * @throws InvalidArgumentException
1137
-     * @throws InvalidInterfaceException
1138
-     * @throws InvalidDataTypeException
1139
-     * @throws EE_Error
1140
-     */
1141
-    public function is_active()
1142
-    {
1143
-        return ($this->get_raw('DTT_EVT_start') < time() && $this->get_raw('DTT_EVT_end') > time());
1144
-    }
1145
-
1146
-
1147
-    /**
1148
-     * This simply compares the internal dtt for the given string with NOW
1149
-     * and determines if the date is expired or not.
1150
-     *
1151
-     * @return boolean
1152
-     * @throws ReflectionException
1153
-     * @throws InvalidArgumentException
1154
-     * @throws InvalidInterfaceException
1155
-     * @throws InvalidDataTypeException
1156
-     * @throws EE_Error
1157
-     */
1158
-    public function is_expired()
1159
-    {
1160
-        return ($this->get_raw('DTT_EVT_end') < time());
1161
-    }
1162
-
1163
-
1164
-    /**
1165
-     * This returns the active status for whether an event is active, upcoming, or expired
1166
-     *
1167
-     * @return int return value will be one of the EE_Datetime status constants.
1168
-     * @throws ReflectionException
1169
-     * @throws InvalidArgumentException
1170
-     * @throws InvalidInterfaceException
1171
-     * @throws InvalidDataTypeException
1172
-     * @throws EE_Error
1173
-     */
1174
-    public function get_active_status()
1175
-    {
1176
-        $total_tickets_for_this_dtt = $this->total_tickets_available_at_this_datetime();
1177
-        if ($total_tickets_for_this_dtt !== false && $total_tickets_for_this_dtt < 1) {
1178
-            return EE_Datetime::sold_out;
1179
-        }
1180
-        if ($this->is_expired()) {
1181
-            return EE_Datetime::expired;
1182
-        }
1183
-        if ($this->is_upcoming()) {
1184
-            return EE_Datetime::upcoming;
1185
-        }
1186
-        if ($this->is_active()) {
1187
-            return EE_Datetime::active;
1188
-        }
1189
-        return null;
1190
-    }
1191
-
1192
-
1193
-    /**
1194
-     * This returns a nice display name for the datetime that is contingent on the span between the dates and times.
1195
-     *
1196
-     * @param boolean $use_dtt_name if TRUE then we'll use DTT->name() if its not empty.
1197
-     * @return string
1198
-     * @throws ReflectionException
1199
-     * @throws InvalidArgumentException
1200
-     * @throws InvalidInterfaceException
1201
-     * @throws InvalidDataTypeException
1202
-     * @throws EE_Error
1203
-     */
1204
-    public function get_dtt_display_name($use_dtt_name = false)
1205
-    {
1206
-        if ($use_dtt_name) {
1207
-            $dtt_name = $this->name();
1208
-            if (! empty($dtt_name)) {
1209
-                return $dtt_name;
1210
-            }
1211
-        }
1212
-        // first condition is to see if the months are different
1213
-        if (
1214
-            date('m', $this->get_raw('DTT_EVT_start')) !== date('m', $this->get_raw('DTT_EVT_end'))
1215
-        ) {
1216
-            $display_date = $this->start_date('M j\, Y g:i a') . ' - ' . $this->end_date('M j\, Y g:i a');
1217
-            // next condition is if its the same month but different day
1218
-        } else {
1219
-            if (
1220
-                date('m', $this->get_raw('DTT_EVT_start')) === date('m', $this->get_raw('DTT_EVT_end'))
1221
-                && date('d', $this->get_raw('DTT_EVT_start')) !== date('d', $this->get_raw('DTT_EVT_end'))
1222
-            ) {
1223
-                $display_date = $this->start_date('M j\, g:i a') . ' - ' . $this->end_date('M j\, g:i a Y');
1224
-            } else {
1225
-                $display_date = $this->start_date('F j\, Y')
1226
-                                . ' @ '
1227
-                                . $this->start_date('g:i a')
1228
-                                . ' - '
1229
-                                . $this->end_date('g:i a');
1230
-            }
1231
-        }
1232
-        return $display_date;
1233
-    }
1234
-
1235
-
1236
-    /**
1237
-     * Gets all the tickets for this datetime
1238
-     *
1239
-     * @param array $query_params @see
1240
-     *                            https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
1241
-     * @return EE_Base_Class[]|EE_Ticket[]
1242
-     * @throws ReflectionException
1243
-     * @throws InvalidArgumentException
1244
-     * @throws InvalidInterfaceException
1245
-     * @throws InvalidDataTypeException
1246
-     * @throws EE_Error
1247
-     */
1248
-    public function tickets($query_params = [])
1249
-    {
1250
-        return $this->get_many_related('Ticket', $query_params);
1251
-    }
1252
-
1253
-
1254
-    /**
1255
-     * Gets all the ticket types currently available for purchase
1256
-     *
1257
-     * @param array $query_params @see
1258
-     *                            https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
1259
-     * @return EE_Ticket[]
1260
-     * @throws ReflectionException
1261
-     * @throws InvalidArgumentException
1262
-     * @throws InvalidInterfaceException
1263
-     * @throws InvalidDataTypeException
1264
-     * @throws EE_Error
1265
-     */
1266
-    public function ticket_types_available_for_purchase($query_params = [])
1267
-    {
1268
-        // first check if datetime is valid
1269
-        if ($this->sold_out() || ! ($this->is_upcoming() || $this->is_active())) {
1270
-            return [];
1271
-        }
1272
-        if (empty($query_params)) {
1273
-            $query_params = [
1274
-                [
1275
-                    'TKT_start_date' => ['<=', EEM_Ticket::instance()->current_time_for_query('TKT_start_date')],
1276
-                    'TKT_end_date'   => ['>=', EEM_Ticket::instance()->current_time_for_query('TKT_end_date')],
1277
-                    'TKT_deleted'    => false,
1278
-                ],
1279
-            ];
1280
-        }
1281
-        return $this->tickets($query_params);
1282
-    }
1283
-
1284
-
1285
-    /**
1286
-     * @return EE_Base_Class|EE_Event
1287
-     * @throws ReflectionException
1288
-     * @throws InvalidArgumentException
1289
-     * @throws InvalidInterfaceException
1290
-     * @throws InvalidDataTypeException
1291
-     * @throws EE_Error
1292
-     */
1293
-    public function event()
1294
-    {
1295
-        return $this->get_first_related('Event');
1296
-    }
1297
-
1298
-
1299
-    /**
1300
-     * Updates the DTT_sold attribute (and saves) based on the number of registrations for this datetime
1301
-     * (via the tickets).
1302
-     *
1303
-     * @return int
1304
-     * @throws ReflectionException
1305
-     * @throws InvalidArgumentException
1306
-     * @throws InvalidInterfaceException
1307
-     * @throws InvalidDataTypeException
1308
-     * @throws EE_Error
1309
-     */
1310
-    public function update_sold()
1311
-    {
1312
-        $count_regs_for_this_datetime = EEM_Registration::instance()->count(
1313
-            [
1314
-                [
1315
-                    'STS_ID'                 => EEM_Registration::status_id_approved,
1316
-                    'REG_deleted'            => 0,
1317
-                    'Ticket.Datetime.DTT_ID' => $this->ID(),
1318
-                ],
1319
-            ]
1320
-        );
1321
-        $this->set_sold($count_regs_for_this_datetime);
1322
-        $this->save();
1323
-        return $count_regs_for_this_datetime;
1324
-    }
1325
-
1326
-
1327
-    /**
1328
-     * Adds a venue to this event
1329
-     *
1330
-     * @param int|EE_Venue /int $venue_id_or_obj
1331
-     * @return EE_Base_Class|EE_Venue
1332
-     * @throws EE_Error
1333
-     * @throws ReflectionException
1334
-     */
1335
-    public function add_venue($venue_id_or_obj): EE_Venue
1336
-    {
1337
-        return $this->_add_relation_to($venue_id_or_obj, 'Venue');
1338
-    }
1339
-
1340
-
1341
-    /**
1342
-     * Removes a venue from the event
1343
-     *
1344
-     * @param EE_Venue /int $venue_id_or_obj
1345
-     * @return EE_Base_Class|EE_Venue
1346
-     * @throws EE_Error
1347
-     * @throws ReflectionException
1348
-     */
1349
-    public function remove_venue($venue_id_or_obj): EE_Venue
1350
-    {
1351
-        $venue_id_or_obj = ! empty($venue_id_or_obj) ? $venue_id_or_obj : $this->venue();
1352
-        return $this->_remove_relation_to($venue_id_or_obj, 'Venue');
1353
-    }
1354
-
1355
-
1356
-    /**
1357
-     * Gets the venue related to the event. May provide additional $query_params if desired
1358
-     *
1359
-     * @param array $query_params @see
1360
-     *                            https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
1361
-     * @return int
1362
-     * @throws EE_Error
1363
-     * @throws ReflectionException
1364
-     */
1365
-    public function venue_ID(array $query_params = []): int
1366
-    {
1367
-        $venue = $this->get_first_related('Venue', $query_params);
1368
-        return $venue instanceof EE_Venue
1369
-            ? $venue->ID()
1370
-            : 0;
1371
-    }
1372
-
1373
-
1374
-    /**
1375
-     * Gets the venue related to the event. May provide additional $query_params if desired
1376
-     *
1377
-     * @param array $query_params @see
1378
-     *                            https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
1379
-     * @return EE_Base_Class|EE_Venue
1380
-     * @throws EE_Error
1381
-     * @throws ReflectionException
1382
-     */
1383
-    public function venue(array $query_params = [])
1384
-    {
1385
-        return $this->get_first_related('Venue', $query_params);
1386
-    }
1387
-
1388
-
1389
-    /**
1390
-     * @param EE_Base_Class|int|string $otherObjectModelObjectOrID
1391
-     * @param string                   $relationName
1392
-     * @param array                    $extra_join_model_fields_n_values
1393
-     * @param string|null              $cache_id
1394
-     * @return EE_Base_Class
1395
-     * @throws EE_Error
1396
-     * @throws ReflectionException
1397
-     * @since   5.0.0.p
1398
-     */
1399
-    public function _add_relation_to(
1400
-        $otherObjectModelObjectOrID,
1401
-        $relationName,
1402
-        $extra_join_model_fields_n_values = [],
1403
-        $cache_id = null
1404
-    ) {
1405
-        // if we're adding a new relation to a ticket
1406
-        if ($relationName === 'Ticket' && ! $this->hasRelation($otherObjectModelObjectOrID, $relationName)) {
1407
-            /** @var EE_Ticket $ticket */
1408
-            $ticket = EEM_Ticket::instance()->ensure_is_obj($otherObjectModelObjectOrID);
1409
-            $this->increaseSold($ticket->sold(), false);
1410
-            $this->increaseReserved($ticket->reserved());
1411
-            $this->save();
1412
-            $otherObjectModelObjectOrID = $ticket;
1413
-        }
1414
-        return parent::_add_relation_to(
1415
-            $otherObjectModelObjectOrID,
1416
-            $relationName,
1417
-            $extra_join_model_fields_n_values,
1418
-            $cache_id
1419
-        );
1420
-    }
1421
-
1422
-
1423
-    /**
1424
-     * @param EE_Base_Class|int|string $otherObjectModelObjectOrID
1425
-     * @param string                   $relationName
1426
-     * @param array                    $where_query
1427
-     * @return bool|EE_Base_Class|null
1428
-     * @throws EE_Error
1429
-     * @throws ReflectionException
1430
-     * @since   5.0.0.p
1431
-     */
1432
-    public function _remove_relation_to($otherObjectModelObjectOrID, $relationName, $where_query = [])
1433
-    {
1434
-        if ($relationName === 'Ticket' && $this->hasRelation($otherObjectModelObjectOrID, $relationName)) {
1435
-            /** @var EE_Ticket $ticket */
1436
-            $ticket = EEM_Ticket::instance()->ensure_is_obj($otherObjectModelObjectOrID);
1437
-            $this->decreaseSold($ticket->sold());
1438
-            $this->decreaseReserved($ticket->reserved());
1439
-            $this->save();
1440
-            $otherObjectModelObjectOrID = $ticket;
1441
-        }
1442
-        return parent::_remove_relation_to(
1443
-            $otherObjectModelObjectOrID,
1444
-            $relationName,
1445
-            $where_query
1446
-        );
1447
-    }
1448
-
1449
-
1450
-    /**
1451
-     * Removes ALL the related things for the $relationName.
1452
-     *
1453
-     * @param string $relationName
1454
-     * @param array  $where_query_params
1455
-     * @return EE_Base_Class
1456
-     * @throws ReflectionException
1457
-     * @throws InvalidArgumentException
1458
-     * @throws InvalidInterfaceException
1459
-     * @throws InvalidDataTypeException
1460
-     * @throws EE_Error
1461
-     * @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md#0-where-conditions
1462
-     */
1463
-    public function _remove_relations($relationName, $where_query_params = [])
1464
-    {
1465
-        if ($relationName === 'Ticket') {
1466
-            $tickets = $this->tickets();
1467
-            foreach ($tickets as $ticket) {
1468
-                $this->decreaseSold($ticket->sold());
1469
-                $this->decreaseReserved($ticket->reserved());
1470
-                $this->save();
1471
-            }
1472
-        }
1473
-        return parent::_remove_relations($relationName, $where_query_params);
1474
-    }
1475
-
1476
-
1477
-    /*******************************************************************
15
+	/**
16
+	 * constant used by get_active_status, indicates datetime has no more available spaces
17
+	 */
18
+	const sold_out = 'DTS';
19
+
20
+	/**
21
+	 * constant used by get_active_status, indicating datetime is still active (even is not over, can be registered-for)
22
+	 */
23
+	const active = 'DTA';
24
+
25
+	/**
26
+	 * constant used by get_active_status, indicating the datetime cannot be used for registrations yet, but has not
27
+	 * expired
28
+	 */
29
+	const upcoming = 'DTU';
30
+
31
+	/**
32
+	 * Datetime is postponed
33
+	 */
34
+	const postponed = 'DTP';
35
+
36
+	/**
37
+	 * Datetime is cancelled
38
+	 */
39
+	const cancelled = 'DTC';
40
+
41
+	/**
42
+	 * constant used by get_active_status, indicates datetime has expired (event is over)
43
+	 */
44
+	const expired = 'DTE';
45
+
46
+	/**
47
+	 * constant used in various places indicating that an event is INACTIVE (not yet ready to be published)
48
+	 */
49
+	const inactive = 'DTI';
50
+
51
+
52
+	/**
53
+	 * @param array  $props_n_values    incoming values
54
+	 * @param string $timezone          incoming timezone (if not set the timezone set for the website will be used.)
55
+	 * @param array  $date_formats      incoming date_formats in an array where the first value is the date_format
56
+	 *                                  and the second value is the time format
57
+	 * @return EE_Datetime
58
+	 * @throws ReflectionException
59
+	 * @throws InvalidArgumentException
60
+	 * @throws InvalidInterfaceException
61
+	 * @throws InvalidDataTypeException
62
+	 * @throws EE_Error
63
+	 */
64
+	public static function new_instance($props_n_values = [], $timezone = '', $date_formats = [])
65
+	{
66
+		$has_object = parent::_check_for_object(
67
+			$props_n_values,
68
+			__CLASS__,
69
+			$timezone,
70
+			$date_formats
71
+		);
72
+		return $has_object
73
+			? $has_object
74
+			: new self($props_n_values, false, $timezone, $date_formats);
75
+	}
76
+
77
+
78
+	/**
79
+	 * @param array  $props_n_values  incoming values from the database
80
+	 * @param string $timezone        incoming timezone as set by the model.  If not set the timezone for
81
+	 *                                the website will be used.
82
+	 * @return EE_Datetime
83
+	 * @throws ReflectionException
84
+	 * @throws InvalidArgumentException
85
+	 * @throws InvalidInterfaceException
86
+	 * @throws InvalidDataTypeException
87
+	 * @throws EE_Error
88
+	 */
89
+	public static function new_instance_from_db($props_n_values = [], $timezone = '')
90
+	{
91
+		return new self($props_n_values, true, $timezone);
92
+	}
93
+
94
+
95
+	/**
96
+	 * @param $name
97
+	 * @throws ReflectionException
98
+	 * @throws InvalidArgumentException
99
+	 * @throws InvalidInterfaceException
100
+	 * @throws InvalidDataTypeException
101
+	 * @throws EE_Error
102
+	 */
103
+	public function set_name($name)
104
+	{
105
+		$this->set('DTT_name', $name);
106
+	}
107
+
108
+
109
+	/**
110
+	 * @param $description
111
+	 * @throws ReflectionException
112
+	 * @throws InvalidArgumentException
113
+	 * @throws InvalidInterfaceException
114
+	 * @throws InvalidDataTypeException
115
+	 * @throws EE_Error
116
+	 */
117
+	public function set_description($description)
118
+	{
119
+		$this->set('DTT_description', $description);
120
+	}
121
+
122
+
123
+	/**
124
+	 * Set event start date
125
+	 * set the start date for an event
126
+	 *
127
+	 * @param string $date a string representation of the event's date ex:  Dec. 25, 2025 or 12-25-2025
128
+	 * @throws ReflectionException
129
+	 * @throws InvalidArgumentException
130
+	 * @throws InvalidInterfaceException
131
+	 * @throws InvalidDataTypeException
132
+	 * @throws EE_Error
133
+	 */
134
+	public function set_start_date($date)
135
+	{
136
+		$this->_set_date_for($date, 'DTT_EVT_start');
137
+	}
138
+
139
+
140
+	/**
141
+	 * Set event start time
142
+	 * set the start time for an event
143
+	 *
144
+	 * @param string $time a string representation of the event time ex:  9am  or  7:30 PM
145
+	 * @throws ReflectionException
146
+	 * @throws InvalidArgumentException
147
+	 * @throws InvalidInterfaceException
148
+	 * @throws InvalidDataTypeException
149
+	 * @throws EE_Error
150
+	 */
151
+	public function set_start_time($time)
152
+	{
153
+		$this->_set_time_for($time, 'DTT_EVT_start');
154
+	}
155
+
156
+
157
+	/**
158
+	 * Set event end date
159
+	 * set the end date for an event
160
+	 *
161
+	 * @param string $date a string representation of the event's date ex:  Dec. 25, 2025 or 12-25-2025
162
+	 * @throws ReflectionException
163
+	 * @throws InvalidArgumentException
164
+	 * @throws InvalidInterfaceException
165
+	 * @throws InvalidDataTypeException
166
+	 * @throws EE_Error
167
+	 */
168
+	public function set_end_date($date)
169
+	{
170
+		$this->_set_date_for($date, 'DTT_EVT_end');
171
+	}
172
+
173
+
174
+	/**
175
+	 * Set event end time
176
+	 * set the end time for an event
177
+	 *
178
+	 * @param string $time a string representation of the event time ex:  9am  or  7:30 PM
179
+	 * @throws ReflectionException
180
+	 * @throws InvalidArgumentException
181
+	 * @throws InvalidInterfaceException
182
+	 * @throws InvalidDataTypeException
183
+	 * @throws EE_Error
184
+	 */
185
+	public function set_end_time($time)
186
+	{
187
+		$this->_set_time_for($time, 'DTT_EVT_end');
188
+	}
189
+
190
+
191
+	/**
192
+	 * Set registration limit
193
+	 * set the maximum number of attendees that can be registered for this datetime slot
194
+	 *
195
+	 * @param int|float $reg_limit
196
+	 * @throws ReflectionException
197
+	 * @throws InvalidArgumentException
198
+	 * @throws InvalidInterfaceException
199
+	 * @throws InvalidDataTypeException
200
+	 * @throws EE_Error
201
+	 */
202
+	public function set_reg_limit($reg_limit)
203
+	{
204
+		$this->set('DTT_reg_limit', $reg_limit);
205
+	}
206
+
207
+
208
+	/**
209
+	 * get the number of tickets sold for this datetime slot
210
+	 *
211
+	 * @return mixed int on success, FALSE on fail
212
+	 * @throws ReflectionException
213
+	 * @throws InvalidArgumentException
214
+	 * @throws InvalidInterfaceException
215
+	 * @throws InvalidDataTypeException
216
+	 * @throws EE_Error
217
+	 */
218
+	public function sold()
219
+	{
220
+		return $this->get_raw('DTT_sold');
221
+	}
222
+
223
+
224
+	/**
225
+	 * @param int $sold
226
+	 * @throws ReflectionException
227
+	 * @throws InvalidArgumentException
228
+	 * @throws InvalidInterfaceException
229
+	 * @throws InvalidDataTypeException
230
+	 * @throws EE_Error
231
+	 */
232
+	public function set_sold($sold)
233
+	{
234
+		// sold can not go below zero
235
+		$sold = max(0, $sold);
236
+		$this->set('DTT_sold', $sold);
237
+	}
238
+
239
+
240
+	/**
241
+	 * Increments sold by amount passed by $qty, and persists it immediately to the database.
242
+	 * Simultaneously decreases the reserved count, unless $also_decrease_reserved is false.
243
+	 *
244
+	 * @param int     $qty
245
+	 * @param boolean $also_decrease_reserved
246
+	 * @return boolean indicating success
247
+	 * @throws ReflectionException
248
+	 * @throws InvalidArgumentException
249
+	 * @throws InvalidInterfaceException
250
+	 * @throws InvalidDataTypeException
251
+	 * @throws EE_Error
252
+	 */
253
+	public function increaseSold(int $qty = 1, bool $also_decrease_reserved = true): bool
254
+	{
255
+		$qty = absint($qty);
256
+		if ($also_decrease_reserved) {
257
+			$success = $this->adjustNumericFieldsInDb(
258
+				[
259
+					'DTT_reserved' => $qty * -1,
260
+					'DTT_sold'     => $qty,
261
+				]
262
+			);
263
+		} else {
264
+			$success = $this->adjustNumericFieldsInDb(
265
+				[
266
+					'DTT_sold' => $qty,
267
+				]
268
+			);
269
+		}
270
+
271
+		do_action(
272
+			'AHEE__EE_Datetime__increase_sold',
273
+			$this,
274
+			$qty,
275
+			$this->sold(),
276
+			$success
277
+		);
278
+		return $success;
279
+	}
280
+
281
+
282
+	/**
283
+	 * Decrements (subtracts) sold amount passed by $qty directly in the DB and on the model object. (Ie, no need
284
+	 * to save afterwards.)
285
+	 *
286
+	 * @param int $qty
287
+	 * @return boolean indicating success
288
+	 * @throws ReflectionException
289
+	 * @throws InvalidArgumentException
290
+	 * @throws InvalidInterfaceException
291
+	 * @throws InvalidDataTypeException
292
+	 * @throws EE_Error
293
+	 */
294
+	public function decreaseSold(int $qty = 1): bool
295
+	{
296
+		$qty     = absint($qty);
297
+		$success = $this->adjustNumericFieldsInDb(
298
+			[
299
+				'DTT_sold' => $qty * -1,
300
+			]
301
+		);
302
+		do_action(
303
+			'AHEE__EE_Datetime__decrease_sold',
304
+			$this,
305
+			$qty,
306
+			$this->sold(),
307
+			$success
308
+		);
309
+		return $success;
310
+	}
311
+
312
+
313
+	/**
314
+	 * Gets qty of reserved tickets for this datetime
315
+	 *
316
+	 * @return int
317
+	 * @throws ReflectionException
318
+	 * @throws InvalidArgumentException
319
+	 * @throws InvalidInterfaceException
320
+	 * @throws InvalidDataTypeException
321
+	 * @throws EE_Error
322
+	 */
323
+	public function reserved(): int
324
+	{
325
+		return $this->get_raw('DTT_reserved');
326
+	}
327
+
328
+
329
+	/**
330
+	 * Sets qty of reserved tickets for this datetime
331
+	 *
332
+	 * @param int $reserved
333
+	 * @throws ReflectionException
334
+	 * @throws InvalidArgumentException
335
+	 * @throws InvalidInterfaceException
336
+	 * @throws InvalidDataTypeException
337
+	 * @throws EE_Error
338
+	 */
339
+	public function set_reserved(int $reserved)
340
+	{
341
+		// reserved can not go below zero
342
+		$reserved = max(0, $reserved);
343
+		$this->set('DTT_reserved', $reserved);
344
+	}
345
+
346
+
347
+	/**
348
+	 * Increments reserved by amount passed by $qty, and persists it immediately to the database.
349
+	 *
350
+	 * @param int $qty
351
+	 * @return boolean indicating success
352
+	 * @throws ReflectionException
353
+	 * @throws InvalidArgumentException
354
+	 * @throws InvalidInterfaceException
355
+	 * @throws InvalidDataTypeException
356
+	 * @throws EE_Error
357
+	 */
358
+	public function increaseReserved(int $qty = 1): bool
359
+	{
360
+		$qty     = absint($qty);
361
+		$success = $this->incrementFieldConditionallyInDb(
362
+			'DTT_reserved',
363
+			'DTT_sold',
364
+			'DTT_reg_limit',
365
+			$qty
366
+		);
367
+		do_action(
368
+			'AHEE__EE_Datetime__increase_reserved',
369
+			$this,
370
+			$qty,
371
+			$this->reserved(),
372
+			$success
373
+		);
374
+		return $success;
375
+	}
376
+
377
+
378
+	/**
379
+	 * Decrements (subtracts) reserved by amount passed by $qty, and persists it immediately to the database.
380
+	 *
381
+	 * @param int $qty
382
+	 * @return boolean indicating success
383
+	 * @throws ReflectionException
384
+	 * @throws InvalidArgumentException
385
+	 * @throws InvalidInterfaceException
386
+	 * @throws InvalidDataTypeException
387
+	 * @throws EE_Error
388
+	 */
389
+	public function decreaseReserved(int $qty = 1): bool
390
+	{
391
+		$qty     = absint($qty);
392
+		$success = $this->adjustNumericFieldsInDb(
393
+			[
394
+				'DTT_reserved' => $qty * -1,
395
+			]
396
+		);
397
+		do_action(
398
+			'AHEE__EE_Datetime__decrease_reserved',
399
+			$this,
400
+			$qty,
401
+			$this->reserved(),
402
+			$success
403
+		);
404
+		return $success;
405
+	}
406
+
407
+
408
+	/**
409
+	 * total sold and reserved tickets
410
+	 *
411
+	 * @return int
412
+	 * @throws ReflectionException
413
+	 * @throws InvalidArgumentException
414
+	 * @throws InvalidInterfaceException
415
+	 * @throws InvalidDataTypeException
416
+	 * @throws EE_Error
417
+	 */
418
+	public function sold_and_reserved(): int
419
+	{
420
+		return $this->sold() + $this->reserved();
421
+	}
422
+
423
+
424
+	/**
425
+	 * returns the datetime name
426
+	 *
427
+	 * @return string
428
+	 * @throws ReflectionException
429
+	 * @throws InvalidArgumentException
430
+	 * @throws InvalidInterfaceException
431
+	 * @throws InvalidDataTypeException
432
+	 * @throws EE_Error
433
+	 */
434
+	public function name(): string
435
+	{
436
+		return $this->get('DTT_name');
437
+	}
438
+
439
+
440
+	/**
441
+	 * returns the datetime description
442
+	 *
443
+	 * @return string
444
+	 * @throws ReflectionException
445
+	 * @throws InvalidArgumentException
446
+	 * @throws InvalidInterfaceException
447
+	 * @throws InvalidDataTypeException
448
+	 * @throws EE_Error
449
+	 */
450
+	public function description(): string
451
+	{
452
+		return $this->get('DTT_description');
453
+	}
454
+
455
+
456
+	/**
457
+	 * This helper simply returns whether the event_datetime for the current datetime is a primary datetime
458
+	 *
459
+	 * @return boolean  TRUE if is primary, FALSE if not.
460
+	 * @throws ReflectionException
461
+	 * @throws InvalidArgumentException
462
+	 * @throws InvalidInterfaceException
463
+	 * @throws InvalidDataTypeException
464
+	 * @throws EE_Error
465
+	 */
466
+	public function is_primary(): bool
467
+	{
468
+		return $this->get('DTT_is_primary');
469
+	}
470
+
471
+
472
+	/**
473
+	 * This helper simply returns the order for the datetime
474
+	 *
475
+	 * @return int  The order of the datetime for this event.
476
+	 * @throws ReflectionException
477
+	 * @throws InvalidArgumentException
478
+	 * @throws InvalidInterfaceException
479
+	 * @throws InvalidDataTypeException
480
+	 * @throws EE_Error
481
+	 */
482
+	public function order(): int
483
+	{
484
+		return $this->get('DTT_order');
485
+	}
486
+
487
+
488
+	/**
489
+	 * This helper simply returns the parent id for the datetime
490
+	 *
491
+	 * @return int
492
+	 * @throws ReflectionException
493
+	 * @throws InvalidArgumentException
494
+	 * @throws InvalidInterfaceException
495
+	 * @throws InvalidDataTypeException
496
+	 * @throws EE_Error
497
+	 */
498
+	public function parent(): int
499
+	{
500
+		return $this->get('DTT_parent');
501
+	}
502
+
503
+
504
+	/**
505
+	 * show date and/or time
506
+	 *
507
+	 * @param string $date_or_time    whether to display a date or time or both
508
+	 * @param string $start_or_end    whether to display start or end datetimes
509
+	 * @param string $dt_frmt
510
+	 * @param string $tm_frmt
511
+	 * @param bool   $echo            whether we echo or return (note echoing uses "pretty" formats,
512
+	 *                                otherwise we use the standard formats)
513
+	 * @return string|bool  string on success, FALSE on fail
514
+	 * @throws ReflectionException
515
+	 * @throws InvalidArgumentException
516
+	 * @throws InvalidInterfaceException
517
+	 * @throws InvalidDataTypeException
518
+	 * @throws EE_Error
519
+	 */
520
+	private function _show_datetime(
521
+		$date_or_time = null,
522
+		$start_or_end = 'start',
523
+		$dt_frmt = '',
524
+		$tm_frmt = '',
525
+		$echo = false
526
+	) {
527
+		$field_name = "DTT_EVT_{$start_or_end}";
528
+		$dtt        = $this->_get_datetime(
529
+			$field_name,
530
+			$dt_frmt,
531
+			$tm_frmt,
532
+			$date_or_time,
533
+			$echo
534
+		);
535
+		if (! $echo) {
536
+			return $dtt;
537
+		}
538
+		return '';
539
+	}
540
+
541
+
542
+	/**
543
+	 * get event start date.  Provide either the date format, or NULL to re-use the
544
+	 * last-used format, or '' to use the default date format
545
+	 *
546
+	 * @param string $dt_frmt string representation of date format defaults to 'F j, Y'
547
+	 * @return mixed            string on success, FALSE on fail
548
+	 * @throws ReflectionException
549
+	 * @throws InvalidArgumentException
550
+	 * @throws InvalidInterfaceException
551
+	 * @throws InvalidDataTypeException
552
+	 * @throws EE_Error
553
+	 */
554
+	public function start_date($dt_frmt = '')
555
+	{
556
+		return $this->_show_datetime('D', 'start', $dt_frmt);
557
+	}
558
+
559
+
560
+	/**
561
+	 * Echoes start_date()
562
+	 *
563
+	 * @param string $dt_frmt
564
+	 * @throws ReflectionException
565
+	 * @throws InvalidArgumentException
566
+	 * @throws InvalidInterfaceException
567
+	 * @throws InvalidDataTypeException
568
+	 * @throws EE_Error
569
+	 */
570
+	public function e_start_date($dt_frmt = '')
571
+	{
572
+		$this->_show_datetime('D', 'start', $dt_frmt, null, true);
573
+	}
574
+
575
+
576
+	/**
577
+	 * get end date. Provide either the date format, or NULL to re-use the
578
+	 * last-used format, or '' to use the default date format
579
+	 *
580
+	 * @param string $dt_frmt string representation of date format defaults to 'F j, Y'
581
+	 * @return mixed            string on success, FALSE on fail
582
+	 * @throws ReflectionException
583
+	 * @throws InvalidArgumentException
584
+	 * @throws InvalidInterfaceException
585
+	 * @throws InvalidDataTypeException
586
+	 * @throws EE_Error
587
+	 */
588
+	public function end_date($dt_frmt = '')
589
+	{
590
+		return $this->_show_datetime('D', 'end', $dt_frmt);
591
+	}
592
+
593
+
594
+	/**
595
+	 * Echoes the end date. See end_date()
596
+	 *
597
+	 * @param string $dt_frmt
598
+	 * @throws ReflectionException
599
+	 * @throws InvalidArgumentException
600
+	 * @throws InvalidInterfaceException
601
+	 * @throws InvalidDataTypeException
602
+	 * @throws EE_Error
603
+	 */
604
+	public function e_end_date($dt_frmt = '')
605
+	{
606
+		$this->_show_datetime('D', 'end', $dt_frmt, null, true);
607
+	}
608
+
609
+
610
+	/**
611
+	 * get date_range - meaning the start AND end date
612
+	 *
613
+	 * @access public
614
+	 * @param string $dt_frmt     string representation of date format defaults to WP settings
615
+	 * @param string $conjunction conjunction junction what's your function ?
616
+	 *                            this string joins the start date with the end date ie: Jan 01 "to" Dec 31
617
+	 * @return mixed              string on success, FALSE on fail
618
+	 * @throws ReflectionException
619
+	 * @throws InvalidArgumentException
620
+	 * @throws InvalidInterfaceException
621
+	 * @throws InvalidDataTypeException
622
+	 * @throws EE_Error
623
+	 */
624
+	public function date_range($dt_frmt = '', $conjunction = ' - ')
625
+	{
626
+		$dt_frmt = ! empty($dt_frmt) ? $dt_frmt : $this->_dt_frmt;
627
+		$start   = str_replace(
628
+			' ',
629
+			'&nbsp;',
630
+			$this->get_i18n_datetime('DTT_EVT_start', $dt_frmt)
631
+		);
632
+		$end     = str_replace(
633
+			' ',
634
+			'&nbsp;',
635
+			$this->get_i18n_datetime('DTT_EVT_end', $dt_frmt)
636
+		);
637
+		return $start !== $end ? $start . $conjunction . $end : $start;
638
+	}
639
+
640
+
641
+	/**
642
+	 * @param string $dt_frmt
643
+	 * @param string $conjunction
644
+	 * @throws ReflectionException
645
+	 * @throws InvalidArgumentException
646
+	 * @throws InvalidInterfaceException
647
+	 * @throws InvalidDataTypeException
648
+	 * @throws EE_Error
649
+	 */
650
+	public function e_date_range($dt_frmt = '', $conjunction = ' - ')
651
+	{
652
+		echo esc_html($this->date_range($dt_frmt, $conjunction));
653
+	}
654
+
655
+
656
+	/**
657
+	 * get start time
658
+	 *
659
+	 * @param string $tm_format - string representation of time format defaults to 'g:i a'
660
+	 * @return mixed        string on success, FALSE on fail
661
+	 * @throws ReflectionException
662
+	 * @throws InvalidArgumentException
663
+	 * @throws InvalidInterfaceException
664
+	 * @throws InvalidDataTypeException
665
+	 * @throws EE_Error
666
+	 */
667
+	public function start_time($tm_format = '')
668
+	{
669
+		return $this->_show_datetime('T', 'start', null, $tm_format);
670
+	}
671
+
672
+
673
+	/**
674
+	 * @param string $tm_format
675
+	 * @throws ReflectionException
676
+	 * @throws InvalidArgumentException
677
+	 * @throws InvalidInterfaceException
678
+	 * @throws InvalidDataTypeException
679
+	 * @throws EE_Error
680
+	 */
681
+	public function e_start_time($tm_format = '')
682
+	{
683
+		$this->_show_datetime('T', 'start', null, $tm_format, true);
684
+	}
685
+
686
+
687
+	/**
688
+	 * get end time
689
+	 *
690
+	 * @param string $tm_format string representation of time format defaults to 'g:i a'
691
+	 * @return mixed                string on success, FALSE on fail
692
+	 * @throws ReflectionException
693
+	 * @throws InvalidArgumentException
694
+	 * @throws InvalidInterfaceException
695
+	 * @throws InvalidDataTypeException
696
+	 * @throws EE_Error
697
+	 */
698
+	public function end_time($tm_format = '')
699
+	{
700
+		return $this->_show_datetime('T', 'end', null, $tm_format);
701
+	}
702
+
703
+
704
+	/**
705
+	 * @param string $tm_format
706
+	 * @throws ReflectionException
707
+	 * @throws InvalidArgumentException
708
+	 * @throws InvalidInterfaceException
709
+	 * @throws InvalidDataTypeException
710
+	 * @throws EE_Error
711
+	 */
712
+	public function e_end_time($tm_format = '')
713
+	{
714
+		$this->_show_datetime('T', 'end', null, $tm_format, true);
715
+	}
716
+
717
+
718
+	/**
719
+	 * get time_range
720
+	 *
721
+	 * @access public
722
+	 * @param string $tm_format   string representation of time format defaults to 'g:i a'
723
+	 * @param string $conjunction conjunction junction what's your function ?
724
+	 *                            this string joins the start date with the end date ie: Jan 01 "to" Dec 31
725
+	 * @return mixed              string on success, FALSE on fail
726
+	 * @throws ReflectionException
727
+	 * @throws InvalidArgumentException
728
+	 * @throws InvalidInterfaceException
729
+	 * @throws InvalidDataTypeException
730
+	 * @throws EE_Error
731
+	 */
732
+	public function time_range($tm_format = '', $conjunction = ' - ')
733
+	{
734
+		$tm_format = ! empty($tm_format) ? $tm_format : $this->_tm_frmt;
735
+		$start     = str_replace(
736
+			' ',
737
+			'&nbsp;',
738
+			$this->get_i18n_datetime('DTT_EVT_start', $tm_format)
739
+		);
740
+		$end       = str_replace(
741
+			' ',
742
+			'&nbsp;',
743
+			$this->get_i18n_datetime('DTT_EVT_end', $tm_format)
744
+		);
745
+		return $start !== $end ? $start . $conjunction . $end : $start;
746
+	}
747
+
748
+
749
+	/**
750
+	 * @param string $tm_format
751
+	 * @param string $conjunction
752
+	 * @throws ReflectionException
753
+	 * @throws InvalidArgumentException
754
+	 * @throws InvalidInterfaceException
755
+	 * @throws InvalidDataTypeException
756
+	 * @throws EE_Error
757
+	 */
758
+	public function e_time_range($tm_format = '', $conjunction = ' - ')
759
+	{
760
+		echo esc_html($this->time_range($tm_format, $conjunction));
761
+	}
762
+
763
+
764
+	/**
765
+	 * This returns a range representation of the date and times.
766
+	 * Output is dependent on the difference (or similarity) between DTT_EVT_start and DTT_EVT_end.
767
+	 * Also, the return value is localized.
768
+	 *
769
+	 * @param string $dt_format
770
+	 * @param string $tm_format
771
+	 * @param string $conjunction used between two different dates or times.
772
+	 *                            ex: Dec 1{$conjunction}}Dec 6, or 2pm{$conjunction}3pm
773
+	 * @param string $separator   used between the date and time formats.
774
+	 *                            ex: Dec 1, 2016{$separator}2pm
775
+	 * @return string
776
+	 * @throws ReflectionException
777
+	 * @throws InvalidArgumentException
778
+	 * @throws InvalidInterfaceException
779
+	 * @throws InvalidDataTypeException
780
+	 * @throws EE_Error
781
+	 */
782
+	public function date_and_time_range(
783
+		$dt_format = '',
784
+		$tm_format = '',
785
+		$conjunction = ' - ',
786
+		$separator = ' '
787
+	) {
788
+		$dt_format   = ! empty($dt_format) ? $dt_format : $this->_dt_frmt;
789
+		$tm_format   = ! empty($tm_format) ? $tm_format : $this->_tm_frmt;
790
+		$full_format = $dt_format . $separator . $tm_format;
791
+		// the range output depends on various conditions
792
+		switch (true) {
793
+			// start date timestamp and end date timestamp are the same.
794
+			case ($this->get_raw('DTT_EVT_start') === $this->get_raw('DTT_EVT_end')):
795
+				$output = $this->get_i18n_datetime('DTT_EVT_start', $full_format);
796
+				break;
797
+			// start and end date are the same but times are different
798
+			case ($this->start_date() === $this->end_date()):
799
+				$output = $this->get_i18n_datetime('DTT_EVT_start', $full_format)
800
+						  . $conjunction
801
+						  . $this->get_i18n_datetime('DTT_EVT_end', $tm_format);
802
+				break;
803
+			// all other conditions
804
+			default:
805
+				$output = $this->get_i18n_datetime('DTT_EVT_start', $full_format)
806
+						  . $conjunction
807
+						  . $this->get_i18n_datetime('DTT_EVT_end', $full_format);
808
+				break;
809
+		}
810
+		return $output;
811
+	}
812
+
813
+
814
+	/**
815
+	 * This echos the results of date and time range.
816
+	 *
817
+	 * @param string $dt_format
818
+	 * @param string $tm_format
819
+	 * @param string $conjunction
820
+	 * @return void
821
+	 * @throws ReflectionException
822
+	 * @throws InvalidArgumentException
823
+	 * @throws InvalidInterfaceException
824
+	 * @throws InvalidDataTypeException
825
+	 * @throws EE_Error
826
+	 * @see date_and_time_range() for more details on purpose.
827
+	 */
828
+	public function e_date_and_time_range($dt_format = '', $tm_format = '', $conjunction = ' - ')
829
+	{
830
+		echo esc_html($this->date_and_time_range($dt_format, $tm_format, $conjunction));
831
+	}
832
+
833
+
834
+	/**
835
+	 * get start date and start time
836
+	 *
837
+	 * @param string $dt_format - string representation of date format defaults to 'F j, Y'
838
+	 * @param string $tm_format - string representation of time format defaults to 'g:i a'
839
+	 * @return    mixed    string on success, FALSE on fail
840
+	 * @throws ReflectionException
841
+	 * @throws InvalidArgumentException
842
+	 * @throws InvalidInterfaceException
843
+	 * @throws InvalidDataTypeException
844
+	 * @throws EE_Error
845
+	 */
846
+	public function start_date_and_time($dt_format = '', $tm_format = '')
847
+	{
848
+		return $this->_show_datetime('', 'start', $dt_format, $tm_format);
849
+	}
850
+
851
+
852
+	/**
853
+	 * @param string $dt_frmt
854
+	 * @param string $tm_format
855
+	 * @throws ReflectionException
856
+	 * @throws InvalidArgumentException
857
+	 * @throws InvalidInterfaceException
858
+	 * @throws InvalidDataTypeException
859
+	 * @throws EE_Error
860
+	 */
861
+	public function e_start_date_and_time($dt_frmt = '', $tm_format = '')
862
+	{
863
+		$this->_show_datetime('', 'start', $dt_frmt, $tm_format, true);
864
+	}
865
+
866
+
867
+	/**
868
+	 * Shows the length of the event (start to end time).
869
+	 * Can be shown in 'seconds','minutes','hours', or 'days'.
870
+	 * By default, rounds up. (So if you use 'days', and then event
871
+	 * only occurs for 1 hour, it will return 1 day).
872
+	 *
873
+	 * @param string $units 'seconds','minutes','hours','days'
874
+	 * @param bool   $round_up
875
+	 * @return float|int|mixed
876
+	 * @throws ReflectionException
877
+	 * @throws InvalidArgumentException
878
+	 * @throws InvalidInterfaceException
879
+	 * @throws InvalidDataTypeException
880
+	 * @throws EE_Error
881
+	 */
882
+	public function length($units = 'seconds', $round_up = false)
883
+	{
884
+		$start           = $this->get_raw('DTT_EVT_start');
885
+		$end             = $this->get_raw('DTT_EVT_end');
886
+		$length_in_units = $end - $start;
887
+		switch ($units) {
888
+			// NOTE: We purposefully don't use "break;" in order to chain the divisions
889
+			/** @noinspection PhpMissingBreakStatementInspection */
890
+			// phpcs:disable PSR2.ControlStructures.SwitchDeclaration.TerminatingComment
891
+			case 'days':
892
+				$length_in_units /= 24;
893
+			/** @noinspection PhpMissingBreakStatementInspection */
894
+			case 'hours':
895
+				// fall through is intentional
896
+				$length_in_units /= 60;
897
+			/** @noinspection PhpMissingBreakStatementInspection */
898
+			case 'minutes':
899
+				// fall through is intentional
900
+				$length_in_units /= 60;
901
+			case 'seconds':
902
+			default:
903
+				$length_in_units = ceil($length_in_units);
904
+		}
905
+		// phpcs:enable
906
+		if ($round_up) {
907
+			$length_in_units = max($length_in_units, 1);
908
+		}
909
+		return $length_in_units;
910
+	}
911
+
912
+
913
+	/**
914
+	 *        get end date and time
915
+	 *
916
+	 * @param string $dt_frmt   - string representation of date format defaults to 'F j, Y'
917
+	 * @param string $tm_format - string representation of time format defaults to 'g:i a'
918
+	 * @return    mixed                string on success, FALSE on fail
919
+	 * @throws ReflectionException
920
+	 * @throws InvalidArgumentException
921
+	 * @throws InvalidInterfaceException
922
+	 * @throws InvalidDataTypeException
923
+	 * @throws EE_Error
924
+	 */
925
+	public function end_date_and_time($dt_frmt = '', $tm_format = '')
926
+	{
927
+		return $this->_show_datetime('', 'end', $dt_frmt, $tm_format);
928
+	}
929
+
930
+
931
+	/**
932
+	 * @param string $dt_frmt
933
+	 * @param string $tm_format
934
+	 * @throws ReflectionException
935
+	 * @throws InvalidArgumentException
936
+	 * @throws InvalidInterfaceException
937
+	 * @throws InvalidDataTypeException
938
+	 * @throws EE_Error
939
+	 */
940
+	public function e_end_date_and_time($dt_frmt = '', $tm_format = '')
941
+	{
942
+		$this->_show_datetime('', 'end', $dt_frmt, $tm_format, true);
943
+	}
944
+
945
+
946
+	/**
947
+	 *        get start timestamp
948
+	 *
949
+	 * @return        int
950
+	 * @throws ReflectionException
951
+	 * @throws InvalidArgumentException
952
+	 * @throws InvalidInterfaceException
953
+	 * @throws InvalidDataTypeException
954
+	 * @throws EE_Error
955
+	 */
956
+	public function start()
957
+	{
958
+		return $this->get_raw('DTT_EVT_start');
959
+	}
960
+
961
+
962
+	/**
963
+	 *        get end timestamp
964
+	 *
965
+	 * @return        int
966
+	 * @throws ReflectionException
967
+	 * @throws InvalidArgumentException
968
+	 * @throws InvalidInterfaceException
969
+	 * @throws InvalidDataTypeException
970
+	 * @throws EE_Error
971
+	 */
972
+	public function end()
973
+	{
974
+		return $this->get_raw('DTT_EVT_end');
975
+	}
976
+
977
+
978
+	/**
979
+	 *    get the registration limit for this datetime slot
980
+	 *
981
+	 * @return int|float                int = finite limit   EE_INF(float) = unlimited
982
+	 * @throws ReflectionException
983
+	 * @throws InvalidArgumentException
984
+	 * @throws InvalidInterfaceException
985
+	 * @throws InvalidDataTypeException
986
+	 * @throws EE_Error
987
+	 */
988
+	public function reg_limit()
989
+	{
990
+		return $this->get_raw('DTT_reg_limit');
991
+	}
992
+
993
+
994
+	/**
995
+	 *    have the tickets sold for this datetime, met or exceed the registration limit ?
996
+	 *
997
+	 * @return boolean
998
+	 * @throws ReflectionException
999
+	 * @throws InvalidArgumentException
1000
+	 * @throws InvalidInterfaceException
1001
+	 * @throws InvalidDataTypeException
1002
+	 * @throws EE_Error
1003
+	 */
1004
+	public function sold_out()
1005
+	{
1006
+		return $this->reg_limit() > 0 && $this->sold() >= $this->reg_limit();
1007
+	}
1008
+
1009
+
1010
+	/**
1011
+	 * return the total number of spaces remaining at this venue.
1012
+	 * This only takes the venue's capacity into account, NOT the tickets available for sale
1013
+	 *
1014
+	 * @param bool $consider_tickets Whether to consider tickets remaining when determining if there are any spaces left
1015
+	 *                               Because if all tickets attached to this datetime have no spaces left,
1016
+	 *                               then this datetime IS effectively sold out.
1017
+	 *                               However, there are cases where we just want to know the spaces
1018
+	 *                               remaining for this particular datetime, hence the flag.
1019
+	 * @return int|float
1020
+	 * @throws ReflectionException
1021
+	 * @throws InvalidArgumentException
1022
+	 * @throws InvalidInterfaceException
1023
+	 * @throws InvalidDataTypeException
1024
+	 * @throws EE_Error
1025
+	 */
1026
+	public function spaces_remaining($consider_tickets = false)
1027
+	{
1028
+		// tickets remaining available for purchase
1029
+		// no need for special checks for infinite, because if DTT_reg_limit == EE_INF, then EE_INF - x = EE_INF
1030
+		$dtt_remaining = $this->reg_limit() - $this->sold_and_reserved();
1031
+		if (! $consider_tickets) {
1032
+			return $dtt_remaining;
1033
+		}
1034
+		$tickets_remaining = $this->tickets_remaining();
1035
+		return min($dtt_remaining, $tickets_remaining);
1036
+	}
1037
+
1038
+
1039
+	/**
1040
+	 * Counts the total tickets available
1041
+	 * (from all the different types of tickets which are available for this datetime).
1042
+	 *
1043
+	 * @param array $query_params @see
1044
+	 *                            https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
1045
+	 * @return int
1046
+	 * @throws ReflectionException
1047
+	 * @throws InvalidArgumentException
1048
+	 * @throws InvalidInterfaceException
1049
+	 * @throws InvalidDataTypeException
1050
+	 * @throws EE_Error
1051
+	 */
1052
+	public function tickets_remaining($query_params = [])
1053
+	{
1054
+		$sum     = 0;
1055
+		$tickets = $this->tickets($query_params);
1056
+		if (! empty($tickets)) {
1057
+			foreach ($tickets as $ticket) {
1058
+				if ($ticket instanceof EE_Ticket) {
1059
+					// get the actual amount of tickets that can be sold
1060
+					$qty = $ticket->qty('saleable');
1061
+					if ($qty === EE_INF) {
1062
+						return EE_INF;
1063
+					}
1064
+					// no negative ticket quantities plz
1065
+					if ($qty > 0) {
1066
+						$sum += $qty;
1067
+					}
1068
+				}
1069
+			}
1070
+		}
1071
+		return $sum;
1072
+	}
1073
+
1074
+
1075
+	/**
1076
+	 * Gets the count of all the tickets available at this datetime (not ticket types)
1077
+	 * before any were sold
1078
+	 *
1079
+	 * @param array $query_params @see
1080
+	 *                            https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
1081
+	 * @return int
1082
+	 * @throws ReflectionException
1083
+	 * @throws InvalidArgumentException
1084
+	 * @throws InvalidInterfaceException
1085
+	 * @throws InvalidDataTypeException
1086
+	 * @throws EE_Error
1087
+	 */
1088
+	public function sum_tickets_initially_available($query_params = [])
1089
+	{
1090
+		return $this->sum_related('Ticket', $query_params, 'TKT_qty');
1091
+	}
1092
+
1093
+
1094
+	/**
1095
+	 * Returns the lesser-of-the two: spaces remaining at this datetime, or
1096
+	 * the total tickets remaining (a sum of the tickets remaining for each ticket type
1097
+	 * that is available for this datetime).
1098
+	 *
1099
+	 * @return int
1100
+	 * @throws ReflectionException
1101
+	 * @throws InvalidArgumentException
1102
+	 * @throws InvalidInterfaceException
1103
+	 * @throws InvalidDataTypeException
1104
+	 * @throws EE_Error
1105
+	 */
1106
+	public function total_tickets_available_at_this_datetime()
1107
+	{
1108
+		return $this->spaces_remaining(true);
1109
+	}
1110
+
1111
+
1112
+	/**
1113
+	 * This simply compares the internal dtt for the given string with NOW
1114
+	 * and determines if the date is upcoming or not.
1115
+	 *
1116
+	 * @access public
1117
+	 * @return boolean
1118
+	 * @throws ReflectionException
1119
+	 * @throws InvalidArgumentException
1120
+	 * @throws InvalidInterfaceException
1121
+	 * @throws InvalidDataTypeException
1122
+	 * @throws EE_Error
1123
+	 */
1124
+	public function is_upcoming()
1125
+	{
1126
+		return ($this->get_raw('DTT_EVT_start') > time());
1127
+	}
1128
+
1129
+
1130
+	/**
1131
+	 * This simply compares the internal datetime for the given string with NOW
1132
+	 * and returns if the date is active (i.e. start and end time)
1133
+	 *
1134
+	 * @return boolean
1135
+	 * @throws ReflectionException
1136
+	 * @throws InvalidArgumentException
1137
+	 * @throws InvalidInterfaceException
1138
+	 * @throws InvalidDataTypeException
1139
+	 * @throws EE_Error
1140
+	 */
1141
+	public function is_active()
1142
+	{
1143
+		return ($this->get_raw('DTT_EVT_start') < time() && $this->get_raw('DTT_EVT_end') > time());
1144
+	}
1145
+
1146
+
1147
+	/**
1148
+	 * This simply compares the internal dtt for the given string with NOW
1149
+	 * and determines if the date is expired or not.
1150
+	 *
1151
+	 * @return boolean
1152
+	 * @throws ReflectionException
1153
+	 * @throws InvalidArgumentException
1154
+	 * @throws InvalidInterfaceException
1155
+	 * @throws InvalidDataTypeException
1156
+	 * @throws EE_Error
1157
+	 */
1158
+	public function is_expired()
1159
+	{
1160
+		return ($this->get_raw('DTT_EVT_end') < time());
1161
+	}
1162
+
1163
+
1164
+	/**
1165
+	 * This returns the active status for whether an event is active, upcoming, or expired
1166
+	 *
1167
+	 * @return int return value will be one of the EE_Datetime status constants.
1168
+	 * @throws ReflectionException
1169
+	 * @throws InvalidArgumentException
1170
+	 * @throws InvalidInterfaceException
1171
+	 * @throws InvalidDataTypeException
1172
+	 * @throws EE_Error
1173
+	 */
1174
+	public function get_active_status()
1175
+	{
1176
+		$total_tickets_for_this_dtt = $this->total_tickets_available_at_this_datetime();
1177
+		if ($total_tickets_for_this_dtt !== false && $total_tickets_for_this_dtt < 1) {
1178
+			return EE_Datetime::sold_out;
1179
+		}
1180
+		if ($this->is_expired()) {
1181
+			return EE_Datetime::expired;
1182
+		}
1183
+		if ($this->is_upcoming()) {
1184
+			return EE_Datetime::upcoming;
1185
+		}
1186
+		if ($this->is_active()) {
1187
+			return EE_Datetime::active;
1188
+		}
1189
+		return null;
1190
+	}
1191
+
1192
+
1193
+	/**
1194
+	 * This returns a nice display name for the datetime that is contingent on the span between the dates and times.
1195
+	 *
1196
+	 * @param boolean $use_dtt_name if TRUE then we'll use DTT->name() if its not empty.
1197
+	 * @return string
1198
+	 * @throws ReflectionException
1199
+	 * @throws InvalidArgumentException
1200
+	 * @throws InvalidInterfaceException
1201
+	 * @throws InvalidDataTypeException
1202
+	 * @throws EE_Error
1203
+	 */
1204
+	public function get_dtt_display_name($use_dtt_name = false)
1205
+	{
1206
+		if ($use_dtt_name) {
1207
+			$dtt_name = $this->name();
1208
+			if (! empty($dtt_name)) {
1209
+				return $dtt_name;
1210
+			}
1211
+		}
1212
+		// first condition is to see if the months are different
1213
+		if (
1214
+			date('m', $this->get_raw('DTT_EVT_start')) !== date('m', $this->get_raw('DTT_EVT_end'))
1215
+		) {
1216
+			$display_date = $this->start_date('M j\, Y g:i a') . ' - ' . $this->end_date('M j\, Y g:i a');
1217
+			// next condition is if its the same month but different day
1218
+		} else {
1219
+			if (
1220
+				date('m', $this->get_raw('DTT_EVT_start')) === date('m', $this->get_raw('DTT_EVT_end'))
1221
+				&& date('d', $this->get_raw('DTT_EVT_start')) !== date('d', $this->get_raw('DTT_EVT_end'))
1222
+			) {
1223
+				$display_date = $this->start_date('M j\, g:i a') . ' - ' . $this->end_date('M j\, g:i a Y');
1224
+			} else {
1225
+				$display_date = $this->start_date('F j\, Y')
1226
+								. ' @ '
1227
+								. $this->start_date('g:i a')
1228
+								. ' - '
1229
+								. $this->end_date('g:i a');
1230
+			}
1231
+		}
1232
+		return $display_date;
1233
+	}
1234
+
1235
+
1236
+	/**
1237
+	 * Gets all the tickets for this datetime
1238
+	 *
1239
+	 * @param array $query_params @see
1240
+	 *                            https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
1241
+	 * @return EE_Base_Class[]|EE_Ticket[]
1242
+	 * @throws ReflectionException
1243
+	 * @throws InvalidArgumentException
1244
+	 * @throws InvalidInterfaceException
1245
+	 * @throws InvalidDataTypeException
1246
+	 * @throws EE_Error
1247
+	 */
1248
+	public function tickets($query_params = [])
1249
+	{
1250
+		return $this->get_many_related('Ticket', $query_params);
1251
+	}
1252
+
1253
+
1254
+	/**
1255
+	 * Gets all the ticket types currently available for purchase
1256
+	 *
1257
+	 * @param array $query_params @see
1258
+	 *                            https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
1259
+	 * @return EE_Ticket[]
1260
+	 * @throws ReflectionException
1261
+	 * @throws InvalidArgumentException
1262
+	 * @throws InvalidInterfaceException
1263
+	 * @throws InvalidDataTypeException
1264
+	 * @throws EE_Error
1265
+	 */
1266
+	public function ticket_types_available_for_purchase($query_params = [])
1267
+	{
1268
+		// first check if datetime is valid
1269
+		if ($this->sold_out() || ! ($this->is_upcoming() || $this->is_active())) {
1270
+			return [];
1271
+		}
1272
+		if (empty($query_params)) {
1273
+			$query_params = [
1274
+				[
1275
+					'TKT_start_date' => ['<=', EEM_Ticket::instance()->current_time_for_query('TKT_start_date')],
1276
+					'TKT_end_date'   => ['>=', EEM_Ticket::instance()->current_time_for_query('TKT_end_date')],
1277
+					'TKT_deleted'    => false,
1278
+				],
1279
+			];
1280
+		}
1281
+		return $this->tickets($query_params);
1282
+	}
1283
+
1284
+
1285
+	/**
1286
+	 * @return EE_Base_Class|EE_Event
1287
+	 * @throws ReflectionException
1288
+	 * @throws InvalidArgumentException
1289
+	 * @throws InvalidInterfaceException
1290
+	 * @throws InvalidDataTypeException
1291
+	 * @throws EE_Error
1292
+	 */
1293
+	public function event()
1294
+	{
1295
+		return $this->get_first_related('Event');
1296
+	}
1297
+
1298
+
1299
+	/**
1300
+	 * Updates the DTT_sold attribute (and saves) based on the number of registrations for this datetime
1301
+	 * (via the tickets).
1302
+	 *
1303
+	 * @return int
1304
+	 * @throws ReflectionException
1305
+	 * @throws InvalidArgumentException
1306
+	 * @throws InvalidInterfaceException
1307
+	 * @throws InvalidDataTypeException
1308
+	 * @throws EE_Error
1309
+	 */
1310
+	public function update_sold()
1311
+	{
1312
+		$count_regs_for_this_datetime = EEM_Registration::instance()->count(
1313
+			[
1314
+				[
1315
+					'STS_ID'                 => EEM_Registration::status_id_approved,
1316
+					'REG_deleted'            => 0,
1317
+					'Ticket.Datetime.DTT_ID' => $this->ID(),
1318
+				],
1319
+			]
1320
+		);
1321
+		$this->set_sold($count_regs_for_this_datetime);
1322
+		$this->save();
1323
+		return $count_regs_for_this_datetime;
1324
+	}
1325
+
1326
+
1327
+	/**
1328
+	 * Adds a venue to this event
1329
+	 *
1330
+	 * @param int|EE_Venue /int $venue_id_or_obj
1331
+	 * @return EE_Base_Class|EE_Venue
1332
+	 * @throws EE_Error
1333
+	 * @throws ReflectionException
1334
+	 */
1335
+	public function add_venue($venue_id_or_obj): EE_Venue
1336
+	{
1337
+		return $this->_add_relation_to($venue_id_or_obj, 'Venue');
1338
+	}
1339
+
1340
+
1341
+	/**
1342
+	 * Removes a venue from the event
1343
+	 *
1344
+	 * @param EE_Venue /int $venue_id_or_obj
1345
+	 * @return EE_Base_Class|EE_Venue
1346
+	 * @throws EE_Error
1347
+	 * @throws ReflectionException
1348
+	 */
1349
+	public function remove_venue($venue_id_or_obj): EE_Venue
1350
+	{
1351
+		$venue_id_or_obj = ! empty($venue_id_or_obj) ? $venue_id_or_obj : $this->venue();
1352
+		return $this->_remove_relation_to($venue_id_or_obj, 'Venue');
1353
+	}
1354
+
1355
+
1356
+	/**
1357
+	 * Gets the venue related to the event. May provide additional $query_params if desired
1358
+	 *
1359
+	 * @param array $query_params @see
1360
+	 *                            https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
1361
+	 * @return int
1362
+	 * @throws EE_Error
1363
+	 * @throws ReflectionException
1364
+	 */
1365
+	public function venue_ID(array $query_params = []): int
1366
+	{
1367
+		$venue = $this->get_first_related('Venue', $query_params);
1368
+		return $venue instanceof EE_Venue
1369
+			? $venue->ID()
1370
+			: 0;
1371
+	}
1372
+
1373
+
1374
+	/**
1375
+	 * Gets the venue related to the event. May provide additional $query_params if desired
1376
+	 *
1377
+	 * @param array $query_params @see
1378
+	 *                            https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
1379
+	 * @return EE_Base_Class|EE_Venue
1380
+	 * @throws EE_Error
1381
+	 * @throws ReflectionException
1382
+	 */
1383
+	public function venue(array $query_params = [])
1384
+	{
1385
+		return $this->get_first_related('Venue', $query_params);
1386
+	}
1387
+
1388
+
1389
+	/**
1390
+	 * @param EE_Base_Class|int|string $otherObjectModelObjectOrID
1391
+	 * @param string                   $relationName
1392
+	 * @param array                    $extra_join_model_fields_n_values
1393
+	 * @param string|null              $cache_id
1394
+	 * @return EE_Base_Class
1395
+	 * @throws EE_Error
1396
+	 * @throws ReflectionException
1397
+	 * @since   5.0.0.p
1398
+	 */
1399
+	public function _add_relation_to(
1400
+		$otherObjectModelObjectOrID,
1401
+		$relationName,
1402
+		$extra_join_model_fields_n_values = [],
1403
+		$cache_id = null
1404
+	) {
1405
+		// if we're adding a new relation to a ticket
1406
+		if ($relationName === 'Ticket' && ! $this->hasRelation($otherObjectModelObjectOrID, $relationName)) {
1407
+			/** @var EE_Ticket $ticket */
1408
+			$ticket = EEM_Ticket::instance()->ensure_is_obj($otherObjectModelObjectOrID);
1409
+			$this->increaseSold($ticket->sold(), false);
1410
+			$this->increaseReserved($ticket->reserved());
1411
+			$this->save();
1412
+			$otherObjectModelObjectOrID = $ticket;
1413
+		}
1414
+		return parent::_add_relation_to(
1415
+			$otherObjectModelObjectOrID,
1416
+			$relationName,
1417
+			$extra_join_model_fields_n_values,
1418
+			$cache_id
1419
+		);
1420
+	}
1421
+
1422
+
1423
+	/**
1424
+	 * @param EE_Base_Class|int|string $otherObjectModelObjectOrID
1425
+	 * @param string                   $relationName
1426
+	 * @param array                    $where_query
1427
+	 * @return bool|EE_Base_Class|null
1428
+	 * @throws EE_Error
1429
+	 * @throws ReflectionException
1430
+	 * @since   5.0.0.p
1431
+	 */
1432
+	public function _remove_relation_to($otherObjectModelObjectOrID, $relationName, $where_query = [])
1433
+	{
1434
+		if ($relationName === 'Ticket' && $this->hasRelation($otherObjectModelObjectOrID, $relationName)) {
1435
+			/** @var EE_Ticket $ticket */
1436
+			$ticket = EEM_Ticket::instance()->ensure_is_obj($otherObjectModelObjectOrID);
1437
+			$this->decreaseSold($ticket->sold());
1438
+			$this->decreaseReserved($ticket->reserved());
1439
+			$this->save();
1440
+			$otherObjectModelObjectOrID = $ticket;
1441
+		}
1442
+		return parent::_remove_relation_to(
1443
+			$otherObjectModelObjectOrID,
1444
+			$relationName,
1445
+			$where_query
1446
+		);
1447
+	}
1448
+
1449
+
1450
+	/**
1451
+	 * Removes ALL the related things for the $relationName.
1452
+	 *
1453
+	 * @param string $relationName
1454
+	 * @param array  $where_query_params
1455
+	 * @return EE_Base_Class
1456
+	 * @throws ReflectionException
1457
+	 * @throws InvalidArgumentException
1458
+	 * @throws InvalidInterfaceException
1459
+	 * @throws InvalidDataTypeException
1460
+	 * @throws EE_Error
1461
+	 * @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md#0-where-conditions
1462
+	 */
1463
+	public function _remove_relations($relationName, $where_query_params = [])
1464
+	{
1465
+		if ($relationName === 'Ticket') {
1466
+			$tickets = $this->tickets();
1467
+			foreach ($tickets as $ticket) {
1468
+				$this->decreaseSold($ticket->sold());
1469
+				$this->decreaseReserved($ticket->reserved());
1470
+				$this->save();
1471
+			}
1472
+		}
1473
+		return parent::_remove_relations($relationName, $where_query_params);
1474
+	}
1475
+
1476
+
1477
+	/*******************************************************************
1478 1478
      ***********************  DEPRECATED METHODS  **********************
1479 1479
      *******************************************************************/
1480 1480
 
1481 1481
 
1482
-    /**
1483
-     * Increments sold by amount passed by $qty, and persists it immediately to the database.
1484
-     *
1485
-     * @param int $qty
1486
-     * @return boolean
1487
-     * @throws ReflectionException
1488
-     * @throws InvalidArgumentException
1489
-     * @throws InvalidInterfaceException
1490
-     * @throws InvalidDataTypeException
1491
-     * @throws EE_Error
1492
-     * @deprecated 4.9.80.p
1493
-     */
1494
-    public function increase_sold($qty = 1)
1495
-    {
1496
-        EE_Error::doing_it_wrong(
1497
-            __FUNCTION__,
1498
-            esc_html__('Please use EE_Datetime::increaseSold() instead', 'event_espresso'),
1499
-            '4.9.80.p',
1500
-            '5.0.0.p'
1501
-        );
1502
-        return $this->increaseSold($qty);
1503
-    }
1504
-
1505
-
1506
-    /**
1507
-     * Decrements (subtracts) sold amount passed by $qty directly in the DB and on the model object. (Ie, no need
1508
-     * to save afterwards.)
1509
-     *
1510
-     * @param int $qty
1511
-     * @return boolean
1512
-     * @throws ReflectionException
1513
-     * @throws InvalidArgumentException
1514
-     * @throws InvalidInterfaceException
1515
-     * @throws InvalidDataTypeException
1516
-     * @throws EE_Error
1517
-     * @deprecated 4.9.80.p
1518
-     */
1519
-    public function decrease_sold($qty = 1)
1520
-    {
1521
-        EE_Error::doing_it_wrong(
1522
-            __FUNCTION__,
1523
-            esc_html__('Please use EE_Datetime::decreaseSold() instead', 'event_espresso'),
1524
-            '4.9.80.p',
1525
-            '5.0.0.p'
1526
-        );
1527
-        return $this->decreaseSold($qty);
1528
-    }
1529
-
1530
-
1531
-    /**
1532
-     * Increments reserved by amount passed by $qty, and persists it immediately to the database.
1533
-     *
1534
-     * @param int $qty
1535
-     * @return boolean indicating success
1536
-     * @throws ReflectionException
1537
-     * @throws InvalidArgumentException
1538
-     * @throws InvalidInterfaceException
1539
-     * @throws InvalidDataTypeException
1540
-     * @throws EE_Error
1541
-     * @deprecated 4.9.80.p
1542
-     */
1543
-    public function increase_reserved($qty = 1)
1544
-    {
1545
-        EE_Error::doing_it_wrong(
1546
-            __FUNCTION__,
1547
-            esc_html__('Please use EE_Datetime::increaseReserved() instead', 'event_espresso'),
1548
-            '4.9.80.p',
1549
-            '5.0.0.p'
1550
-        );
1551
-        return $this->increaseReserved($qty);
1552
-    }
1553
-
1554
-
1555
-    /**
1556
-     * Decrements (subtracts) reserved by amount passed by $qty, and persists it immediately to the database.
1557
-     *
1558
-     * @param int $qty
1559
-     * @return boolean
1560
-     * @throws ReflectionException
1561
-     * @throws InvalidArgumentException
1562
-     * @throws InvalidInterfaceException
1563
-     * @throws InvalidDataTypeException
1564
-     * @throws EE_Error
1565
-     * @deprecated 4.9.80.p
1566
-     */
1567
-    public function decrease_reserved($qty = 1)
1568
-    {
1569
-        EE_Error::doing_it_wrong(
1570
-            __FUNCTION__,
1571
-            esc_html__('Please use EE_Datetime::decreaseReserved() instead', 'event_espresso'),
1572
-            '4.9.80.p',
1573
-            '5.0.0.p'
1574
-        );
1575
-        return $this->decreaseReserved($qty);
1576
-    }
1482
+	/**
1483
+	 * Increments sold by amount passed by $qty, and persists it immediately to the database.
1484
+	 *
1485
+	 * @param int $qty
1486
+	 * @return boolean
1487
+	 * @throws ReflectionException
1488
+	 * @throws InvalidArgumentException
1489
+	 * @throws InvalidInterfaceException
1490
+	 * @throws InvalidDataTypeException
1491
+	 * @throws EE_Error
1492
+	 * @deprecated 4.9.80.p
1493
+	 */
1494
+	public function increase_sold($qty = 1)
1495
+	{
1496
+		EE_Error::doing_it_wrong(
1497
+			__FUNCTION__,
1498
+			esc_html__('Please use EE_Datetime::increaseSold() instead', 'event_espresso'),
1499
+			'4.9.80.p',
1500
+			'5.0.0.p'
1501
+		);
1502
+		return $this->increaseSold($qty);
1503
+	}
1504
+
1505
+
1506
+	/**
1507
+	 * Decrements (subtracts) sold amount passed by $qty directly in the DB and on the model object. (Ie, no need
1508
+	 * to save afterwards.)
1509
+	 *
1510
+	 * @param int $qty
1511
+	 * @return boolean
1512
+	 * @throws ReflectionException
1513
+	 * @throws InvalidArgumentException
1514
+	 * @throws InvalidInterfaceException
1515
+	 * @throws InvalidDataTypeException
1516
+	 * @throws EE_Error
1517
+	 * @deprecated 4.9.80.p
1518
+	 */
1519
+	public function decrease_sold($qty = 1)
1520
+	{
1521
+		EE_Error::doing_it_wrong(
1522
+			__FUNCTION__,
1523
+			esc_html__('Please use EE_Datetime::decreaseSold() instead', 'event_espresso'),
1524
+			'4.9.80.p',
1525
+			'5.0.0.p'
1526
+		);
1527
+		return $this->decreaseSold($qty);
1528
+	}
1529
+
1530
+
1531
+	/**
1532
+	 * Increments reserved by amount passed by $qty, and persists it immediately to the database.
1533
+	 *
1534
+	 * @param int $qty
1535
+	 * @return boolean indicating success
1536
+	 * @throws ReflectionException
1537
+	 * @throws InvalidArgumentException
1538
+	 * @throws InvalidInterfaceException
1539
+	 * @throws InvalidDataTypeException
1540
+	 * @throws EE_Error
1541
+	 * @deprecated 4.9.80.p
1542
+	 */
1543
+	public function increase_reserved($qty = 1)
1544
+	{
1545
+		EE_Error::doing_it_wrong(
1546
+			__FUNCTION__,
1547
+			esc_html__('Please use EE_Datetime::increaseReserved() instead', 'event_espresso'),
1548
+			'4.9.80.p',
1549
+			'5.0.0.p'
1550
+		);
1551
+		return $this->increaseReserved($qty);
1552
+	}
1553
+
1554
+
1555
+	/**
1556
+	 * Decrements (subtracts) reserved by amount passed by $qty, and persists it immediately to the database.
1557
+	 *
1558
+	 * @param int $qty
1559
+	 * @return boolean
1560
+	 * @throws ReflectionException
1561
+	 * @throws InvalidArgumentException
1562
+	 * @throws InvalidInterfaceException
1563
+	 * @throws InvalidDataTypeException
1564
+	 * @throws EE_Error
1565
+	 * @deprecated 4.9.80.p
1566
+	 */
1567
+	public function decrease_reserved($qty = 1)
1568
+	{
1569
+		EE_Error::doing_it_wrong(
1570
+			__FUNCTION__,
1571
+			esc_html__('Please use EE_Datetime::decreaseReserved() instead', 'event_espresso'),
1572
+			'4.9.80.p',
1573
+			'5.0.0.p'
1574
+		);
1575
+		return $this->decreaseReserved($qty);
1576
+	}
1577 1577
 }
Please login to merge, or discard this patch.
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -532,7 +532,7 @@  discard block
 block discarded – undo
532 532
             $date_or_time,
533 533
             $echo
534 534
         );
535
-        if (! $echo) {
535
+        if ( ! $echo) {
536 536
             return $dtt;
537 537
         }
538 538
         return '';
@@ -629,12 +629,12 @@  discard block
 block discarded – undo
629 629
             '&nbsp;',
630 630
             $this->get_i18n_datetime('DTT_EVT_start', $dt_frmt)
631 631
         );
632
-        $end     = str_replace(
632
+        $end = str_replace(
633 633
             ' ',
634 634
             '&nbsp;',
635 635
             $this->get_i18n_datetime('DTT_EVT_end', $dt_frmt)
636 636
         );
637
-        return $start !== $end ? $start . $conjunction . $end : $start;
637
+        return $start !== $end ? $start.$conjunction.$end : $start;
638 638
     }
639 639
 
640 640
 
@@ -737,12 +737,12 @@  discard block
 block discarded – undo
737 737
             '&nbsp;',
738 738
             $this->get_i18n_datetime('DTT_EVT_start', $tm_format)
739 739
         );
740
-        $end       = str_replace(
740
+        $end = str_replace(
741 741
             ' ',
742 742
             '&nbsp;',
743 743
             $this->get_i18n_datetime('DTT_EVT_end', $tm_format)
744 744
         );
745
-        return $start !== $end ? $start . $conjunction . $end : $start;
745
+        return $start !== $end ? $start.$conjunction.$end : $start;
746 746
     }
747 747
 
748 748
 
@@ -787,7 +787,7 @@  discard block
 block discarded – undo
787 787
     ) {
788 788
         $dt_format   = ! empty($dt_format) ? $dt_format : $this->_dt_frmt;
789 789
         $tm_format   = ! empty($tm_format) ? $tm_format : $this->_tm_frmt;
790
-        $full_format = $dt_format . $separator . $tm_format;
790
+        $full_format = $dt_format.$separator.$tm_format;
791 791
         // the range output depends on various conditions
792 792
         switch (true) {
793 793
             // start date timestamp and end date timestamp are the same.
@@ -1028,7 +1028,7 @@  discard block
 block discarded – undo
1028 1028
         // tickets remaining available for purchase
1029 1029
         // no need for special checks for infinite, because if DTT_reg_limit == EE_INF, then EE_INF - x = EE_INF
1030 1030
         $dtt_remaining = $this->reg_limit() - $this->sold_and_reserved();
1031
-        if (! $consider_tickets) {
1031
+        if ( ! $consider_tickets) {
1032 1032
             return $dtt_remaining;
1033 1033
         }
1034 1034
         $tickets_remaining = $this->tickets_remaining();
@@ -1053,7 +1053,7 @@  discard block
 block discarded – undo
1053 1053
     {
1054 1054
         $sum     = 0;
1055 1055
         $tickets = $this->tickets($query_params);
1056
-        if (! empty($tickets)) {
1056
+        if ( ! empty($tickets)) {
1057 1057
             foreach ($tickets as $ticket) {
1058 1058
                 if ($ticket instanceof EE_Ticket) {
1059 1059
                     // get the actual amount of tickets that can be sold
@@ -1205,7 +1205,7 @@  discard block
 block discarded – undo
1205 1205
     {
1206 1206
         if ($use_dtt_name) {
1207 1207
             $dtt_name = $this->name();
1208
-            if (! empty($dtt_name)) {
1208
+            if ( ! empty($dtt_name)) {
1209 1209
                 return $dtt_name;
1210 1210
             }
1211 1211
         }
@@ -1213,14 +1213,14 @@  discard block
 block discarded – undo
1213 1213
         if (
1214 1214
             date('m', $this->get_raw('DTT_EVT_start')) !== date('m', $this->get_raw('DTT_EVT_end'))
1215 1215
         ) {
1216
-            $display_date = $this->start_date('M j\, Y g:i a') . ' - ' . $this->end_date('M j\, Y g:i a');
1216
+            $display_date = $this->start_date('M j\, Y g:i a').' - '.$this->end_date('M j\, Y g:i a');
1217 1217
             // next condition is if its the same month but different day
1218 1218
         } else {
1219 1219
             if (
1220 1220
                 date('m', $this->get_raw('DTT_EVT_start')) === date('m', $this->get_raw('DTT_EVT_end'))
1221 1221
                 && date('d', $this->get_raw('DTT_EVT_start')) !== date('d', $this->get_raw('DTT_EVT_end'))
1222 1222
             ) {
1223
-                $display_date = $this->start_date('M j\, g:i a') . ' - ' . $this->end_date('M j\, g:i a Y');
1223
+                $display_date = $this->start_date('M j\, g:i a').' - '.$this->end_date('M j\, g:i a Y');
1224 1224
             } else {
1225 1225
                 $display_date = $this->start_date('F j\, Y')
1226 1226
                                 . ' @ '
Please login to merge, or discard this patch.
core/db_classes/EE_Registration.class.php 2 patches
Indentation   +2563 added lines, -2563 removed lines patch added patch discarded remove patch
@@ -17,2567 +17,2567 @@
 block discarded – undo
17 17
  */
18 18
 class EE_Registration extends EE_Soft_Delete_Base_Class implements EEI_Registration, EEI_Admin_Links
19 19
 {
20
-    /**
21
-     * Used to reference when a registration has never been checked in.
22
-     *
23
-     * @deprecated use \EE_Checkin::status_checked_never instead
24
-     * @type int
25
-     */
26
-    const checkin_status_never = 2;
27
-
28
-    /**
29
-     * Used to reference when a registration has been checked in.
30
-     *
31
-     * @deprecated use \EE_Checkin::status_checked_in instead
32
-     * @type int
33
-     */
34
-    const checkin_status_in = 1;
35
-
36
-    /**
37
-     * Used to reference when a registration has been checked out.
38
-     *
39
-     * @deprecated use \EE_Checkin::status_checked_out instead
40
-     * @type int
41
-     */
42
-    const checkin_status_out = 0;
43
-
44
-    /**
45
-     * extra meta key for tracking reg status os trashed registrations
46
-     *
47
-     * @type string
48
-     */
49
-    const PRE_TRASH_REG_STATUS_KEY = 'pre_trash_registration_status';
50
-
51
-    /**
52
-     * extra meta key for tracking if registration has reserved ticket
53
-     *
54
-     * @type string
55
-     */
56
-    const HAS_RESERVED_TICKET_KEY = 'has_reserved_ticket';
57
-
58
-
59
-    /**
60
-     * @param array  $props_n_values          incoming values
61
-     * @param string $timezone                incoming timezone (if not set the timezone set for the website will be
62
-     *                                        used.)
63
-     * @param array  $date_formats            incoming date_formats in an array where the first value is the
64
-     *                                        date_format and the second value is the time format
65
-     * @return EE_Registration
66
-     * @throws EE_Error
67
-     * @throws InvalidArgumentException
68
-     * @throws InvalidDataTypeException
69
-     * @throws InvalidInterfaceException
70
-     * @throws ReflectionException
71
-     */
72
-    public static function new_instance($props_n_values = [], $timezone = '', $date_formats = [])
73
-    {
74
-        $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats);
75
-        return $has_object
76
-            ?: new self($props_n_values, false, $timezone, $date_formats);
77
-    }
78
-
79
-
80
-    /**
81
-     * @param array  $props_n_values  incoming values from the database
82
-     * @param string $timezone        incoming timezone as set by the model.  If not set the timezone for
83
-     *                                the website will be used.
84
-     * @return EE_Registration
85
-     * @throws EE_Error
86
-     * @throws InvalidArgumentException
87
-     * @throws InvalidDataTypeException
88
-     * @throws InvalidInterfaceException
89
-     * @throws ReflectionException
90
-     */
91
-    public static function new_instance_from_db($props_n_values = [], $timezone = '')
92
-    {
93
-        return new self($props_n_values, true, $timezone);
94
-    }
95
-
96
-
97
-    /**
98
-     *        Set Event ID
99
-     *
100
-     * @param int $EVT_ID Event ID
101
-     * @throws DomainException
102
-     * @throws EE_Error
103
-     * @throws EntityNotFoundException
104
-     * @throws InvalidArgumentException
105
-     * @throws InvalidDataTypeException
106
-     * @throws InvalidInterfaceException
107
-     * @throws ReflectionException
108
-     * @throws RuntimeException
109
-     * @throws UnexpectedEntityException
110
-     */
111
-    public function set_event($EVT_ID = 0)
112
-    {
113
-        $this->set('EVT_ID', $EVT_ID);
114
-    }
115
-
116
-
117
-    /**
118
-     * Overrides parent set() method so that all calls to set( 'REG_code', $REG_code ) OR set( 'STS_ID', $STS_ID ) can
119
-     * be routed to internal methods
120
-     *
121
-     * @param string $field_name
122
-     * @param mixed  $field_value
123
-     * @param bool   $use_default
124
-     * @throws DomainException
125
-     * @throws EE_Error
126
-     * @throws EntityNotFoundException
127
-     * @throws InvalidArgumentException
128
-     * @throws InvalidDataTypeException
129
-     * @throws InvalidInterfaceException
130
-     * @throws ReflectionException
131
-     * @throws RuntimeException
132
-     * @throws UnexpectedEntityException
133
-     */
134
-    public function set($field_name, $field_value, $use_default = false)
135
-    {
136
-        switch ($field_name) {
137
-            case 'REG_code':
138
-                if (! empty($field_value) && ! $this->reg_code()) {
139
-                    $this->set_reg_code($field_value, $use_default);
140
-                }
141
-                break;
142
-            case 'STS_ID':
143
-                $this->set_status($field_value, $use_default);
144
-                break;
145
-            default:
146
-                parent::set($field_name, $field_value, $use_default);
147
-        }
148
-    }
149
-
150
-
151
-    /**
152
-     * Set Status ID
153
-     * updates the registration status and ALSO...
154
-     * calls reserve_registration_space() if the reg status changes TO approved from any other reg status
155
-     * calls release_registration_space() if the reg status changes FROM approved to any other reg status
156
-     *
157
-     * @param string                $new_STS_ID
158
-     * @param boolean               $use_default
159
-     * @param ContextInterface|null $context
160
-     * @return bool
161
-     * @throws DomainException
162
-     * @throws EE_Error
163
-     * @throws EntityNotFoundException
164
-     * @throws InvalidArgumentException
165
-     * @throws InvalidDataTypeException
166
-     * @throws InvalidInterfaceException
167
-     * @throws ReflectionException
168
-     * @throws RuntimeException
169
-     * @throws UnexpectedEntityException
170
-     */
171
-    public function set_status($new_STS_ID = null, $use_default = false, ContextInterface $context = null)
172
-    {
173
-        // get current REG_Status
174
-        $old_STS_ID = $this->status_ID();
175
-        // if status has changed
176
-        if (
177
-            $old_STS_ID !== $new_STS_ID // and that status has actually changed
178
-            && ! empty($old_STS_ID) // and that old status is actually set
179
-            && ! empty($new_STS_ID) // as well as the new status
180
-            && $this->ID() // ensure registration is in the db
181
-        ) {
182
-            // update internal status first
183
-            parent::set('STS_ID', $new_STS_ID, $use_default);
184
-            // THEN handle other changes that occur when reg status changes
185
-            // TO approved
186
-            if ($new_STS_ID === EEM_Registration::status_id_approved) {
187
-                // reserve a space by incrementing ticket and datetime sold values
188
-                $this->reserveRegistrationSpace();
189
-                do_action('AHEE__EE_Registration__set_status__to_approved', $this, $old_STS_ID, $new_STS_ID, $context);
190
-                // OR FROM  approved
191
-            } elseif ($old_STS_ID === EEM_Registration::status_id_approved) {
192
-                // release a space by decrementing ticket and datetime sold values
193
-                $this->releaseRegistrationSpace();
194
-                do_action(
195
-                    'AHEE__EE_Registration__set_status__from_approved',
196
-                    $this,
197
-                    $old_STS_ID,
198
-                    $new_STS_ID,
199
-                    $context
200
-                );
201
-            }
202
-            // update status
203
-            parent::set('STS_ID', $new_STS_ID, $use_default);
204
-            $this->updateIfCanceledOrReinstated($new_STS_ID, $old_STS_ID, $context);
205
-            if ($this->statusChangeUpdatesTransaction($context)) {
206
-                $this->updateTransactionAfterStatusChange();
207
-            }
208
-            do_action('AHEE__EE_Registration__set_status__after_update', $this, $old_STS_ID, $new_STS_ID, $context);
209
-            return true;
210
-        }
211
-        // even though the old value matches the new value, it's still good to
212
-        // allow the parent set method to have a say
213
-        parent::set('STS_ID', $new_STS_ID, $use_default);
214
-        return true;
215
-    }
216
-
217
-
218
-    /**
219
-     * update REGs and TXN when cancelled or declined registrations involved
220
-     *
221
-     * @param string                $new_STS_ID
222
-     * @param string                $old_STS_ID
223
-     * @param ContextInterface|null $context
224
-     * @throws EE_Error
225
-     * @throws InvalidArgumentException
226
-     * @throws InvalidDataTypeException
227
-     * @throws InvalidInterfaceException
228
-     * @throws ReflectionException
229
-     * @throws RuntimeException
230
-     */
231
-    private function updateIfCanceledOrReinstated($new_STS_ID, $old_STS_ID, ContextInterface $context = null)
232
-    {
233
-        // these reg statuses should not be considered in any calculations involving monies owing
234
-        $closed_reg_statuses = EEM_Registration::closed_reg_statuses();
235
-        // true if registration has been cancelled or declined
236
-        $this->updateIfCanceled(
237
-            $closed_reg_statuses,
238
-            $new_STS_ID,
239
-            $old_STS_ID,
240
-            $context
241
-        );
242
-        $this->updateIfReinstated(
243
-            $closed_reg_statuses,
244
-            $new_STS_ID,
245
-            $old_STS_ID,
246
-            $context
247
-        );
248
-    }
249
-
250
-
251
-    /**
252
-     * update REGs and TXN when cancelled or declined registrations involved
253
-     *
254
-     * @param array                 $closed_reg_statuses
255
-     * @param string                $new_STS_ID
256
-     * @param string                $old_STS_ID
257
-     * @param ContextInterface|null $context
258
-     * @throws EE_Error
259
-     * @throws InvalidArgumentException
260
-     * @throws InvalidDataTypeException
261
-     * @throws InvalidInterfaceException
262
-     * @throws ReflectionException
263
-     * @throws RuntimeException
264
-     */
265
-    private function updateIfCanceled(
266
-        array $closed_reg_statuses,
267
-        $new_STS_ID,
268
-        $old_STS_ID,
269
-        ContextInterface $context = null
270
-    ) {
271
-        // true if registration has been cancelled or declined
272
-        if (
273
-            in_array($new_STS_ID, $closed_reg_statuses, true)
274
-            && ! in_array($old_STS_ID, $closed_reg_statuses, true)
275
-        ) {
276
-            /** @type EE_Registration_Processor $registration_processor */
277
-            $registration_processor = EE_Registry::instance()->load_class('Registration_Processor');
278
-            /** @type EE_Transaction_Processor $transaction_processor */
279
-            $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor');
280
-            // cancelled or declined registration
281
-            $registration_processor->update_registration_after_being_canceled_or_declined(
282
-                $this,
283
-                $closed_reg_statuses
284
-            );
285
-            $transaction_processor->update_transaction_after_canceled_or_declined_registration(
286
-                $this,
287
-                $closed_reg_statuses,
288
-                false
289
-            );
290
-            do_action(
291
-                'AHEE__EE_Registration__set_status__canceled_or_declined',
292
-                $this,
293
-                $old_STS_ID,
294
-                $new_STS_ID,
295
-                $context
296
-            );
297
-            return;
298
-        }
299
-    }
300
-
301
-
302
-    /**
303
-     * update REGs and TXN when cancelled or declined registrations involved
304
-     *
305
-     * @param array                 $closed_reg_statuses
306
-     * @param string                $new_STS_ID
307
-     * @param string                $old_STS_ID
308
-     * @param ContextInterface|null $context
309
-     * @throws EE_Error
310
-     * @throws InvalidArgumentException
311
-     * @throws InvalidDataTypeException
312
-     * @throws InvalidInterfaceException
313
-     * @throws ReflectionException
314
-     * @throws RuntimeException
315
-     */
316
-    private function updateIfReinstated(
317
-        array $closed_reg_statuses,
318
-        $new_STS_ID,
319
-        $old_STS_ID,
320
-        ContextInterface $context = null
321
-    ) {
322
-        // true if reinstating cancelled or declined registration
323
-        if (
324
-            in_array($old_STS_ID, $closed_reg_statuses, true)
325
-            && ! in_array($new_STS_ID, $closed_reg_statuses, true)
326
-        ) {
327
-            /** @type EE_Registration_Processor $registration_processor */
328
-            $registration_processor = EE_Registry::instance()->load_class('Registration_Processor');
329
-            /** @type EE_Transaction_Processor $transaction_processor */
330
-            $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor');
331
-            // reinstating cancelled or declined registration
332
-            $registration_processor->update_canceled_or_declined_registration_after_being_reinstated(
333
-                $this,
334
-                $closed_reg_statuses
335
-            );
336
-            $transaction_processor->update_transaction_after_reinstating_canceled_registration(
337
-                $this,
338
-                $closed_reg_statuses,
339
-                false
340
-            );
341
-            do_action(
342
-                'AHEE__EE_Registration__set_status__after_reinstated',
343
-                $this,
344
-                $old_STS_ID,
345
-                $new_STS_ID,
346
-                $context
347
-            );
348
-        }
349
-    }
350
-
351
-
352
-    /**
353
-     * @param ContextInterface|null $context
354
-     * @return bool
355
-     */
356
-    private function statusChangeUpdatesTransaction(ContextInterface $context = null)
357
-    {
358
-        $contexts_that_do_not_update_transaction = (array) apply_filters(
359
-            'AHEE__EE_Registration__statusChangeUpdatesTransaction__contexts_that_do_not_update_transaction',
360
-            ['spco_reg_step_attendee_information_process_registrations'],
361
-            $context,
362
-            $this
363
-        );
364
-        return ! (
365
-            $context instanceof ContextInterface
366
-            && in_array($context->slug(), $contexts_that_do_not_update_transaction, true)
367
-        );
368
-    }
369
-
370
-
371
-    /**
372
-     * @throws EE_Error
373
-     * @throws EntityNotFoundException
374
-     * @throws InvalidArgumentException
375
-     * @throws InvalidDataTypeException
376
-     * @throws InvalidInterfaceException
377
-     * @throws ReflectionException
378
-     * @throws RuntimeException
379
-     */
380
-    private function updateTransactionAfterStatusChange()
381
-    {
382
-        /** @type EE_Transaction_Payments $transaction_payments */
383
-        $transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments');
384
-        $transaction_payments->recalculate_transaction_total($this->transaction(), false);
385
-        $this->transaction()->update_status_based_on_total_paid();
386
-    }
387
-
388
-
389
-    /**
390
-     * get Status ID
391
-     *
392
-     * @throws EE_Error
393
-     * @throws InvalidArgumentException
394
-     * @throws InvalidDataTypeException
395
-     * @throws InvalidInterfaceException
396
-     * @throws ReflectionException
397
-     */
398
-    public function status_ID()
399
-    {
400
-        return $this->get('STS_ID');
401
-    }
402
-
403
-
404
-    /**
405
-     * Gets the ticket this registration is for
406
-     *
407
-     * @param boolean $include_archived whether to include archived tickets or not.
408
-     * @return EE_Ticket|EE_Base_Class
409
-     * @throws EE_Error
410
-     * @throws InvalidArgumentException
411
-     * @throws InvalidDataTypeException
412
-     * @throws InvalidInterfaceException
413
-     * @throws ReflectionException
414
-     */
415
-    public function ticket($include_archived = true)
416
-    {
417
-        $query_params = [];
418
-        if ($include_archived) {
419
-            $query_params['default_where_conditions'] = 'none';
420
-        }
421
-        return $this->get_first_related('Ticket', $query_params);
422
-    }
423
-
424
-
425
-    /**
426
-     * Gets the event this registration is for
427
-     *
428
-     * @return EE_Event
429
-     * @throws EE_Error
430
-     * @throws EntityNotFoundException
431
-     * @throws InvalidArgumentException
432
-     * @throws InvalidDataTypeException
433
-     * @throws InvalidInterfaceException
434
-     * @throws ReflectionException
435
-     */
436
-    public function event(): EE_Event
437
-    {
438
-        $event = $this->get_first_related('Event');
439
-        if (! $event instanceof EE_Event) {
440
-            throw new EntityNotFoundException('Event ID', $this->event_ID());
441
-        }
442
-        return $event;
443
-    }
444
-
445
-
446
-    /**
447
-     * Gets the "author" of the registration.  Note that for the purposes of registrations, the author will correspond
448
-     * with the author of the event this registration is for.
449
-     *
450
-     * @return int
451
-     * @throws EE_Error
452
-     * @throws EntityNotFoundException
453
-     * @throws InvalidArgumentException
454
-     * @throws InvalidDataTypeException
455
-     * @throws InvalidInterfaceException
456
-     * @throws ReflectionException
457
-     * @since 4.5.0
458
-     */
459
-    public function wp_user(): int
460
-    {
461
-        return $this->event()->wp_user();
462
-    }
463
-
464
-
465
-    /**
466
-     * increments this registration's related ticket sold and corresponding datetime sold values
467
-     *
468
-     * @return void
469
-     * @throws DomainException
470
-     * @throws EE_Error
471
-     * @throws EntityNotFoundException
472
-     * @throws InvalidArgumentException
473
-     * @throws InvalidDataTypeException
474
-     * @throws InvalidInterfaceException
475
-     * @throws ReflectionException
476
-     * @throws UnexpectedEntityException
477
-     */
478
-    private function reserveRegistrationSpace()
479
-    {
480
-        // reserved ticket and datetime counts will be decremented as sold counts are incremented
481
-        // so stop tracking that this reg has a ticket reserved
482
-        $this->release_reserved_ticket(false, "REG: {$this->ID()} (ln:" . __LINE__ . ')');
483
-        $ticket = $this->ticket();
484
-        $ticket->increaseSold();
485
-        // possibly set event status to sold out
486
-        $this->event()->perform_sold_out_status_check();
487
-    }
488
-
489
-
490
-    /**
491
-     * decrements (subtracts) this registration's related ticket sold and corresponding datetime sold values
492
-     *
493
-     * @return void
494
-     * @throws DomainException
495
-     * @throws EE_Error
496
-     * @throws EntityNotFoundException
497
-     * @throws InvalidArgumentException
498
-     * @throws InvalidDataTypeException
499
-     * @throws InvalidInterfaceException
500
-     * @throws ReflectionException
501
-     * @throws UnexpectedEntityException
502
-     */
503
-    private function releaseRegistrationSpace()
504
-    {
505
-        $ticket = $this->ticket();
506
-        $ticket->decreaseSold();
507
-        // possibly change event status from sold out back to previous status
508
-        $this->event()->perform_sold_out_status_check();
509
-    }
510
-
511
-
512
-    /**
513
-     * tracks this registration's ticket reservation in extra meta
514
-     * and can increment related ticket reserved and corresponding datetime reserved values
515
-     *
516
-     * @param bool   $update_ticket if true, will increment ticket and datetime reserved count
517
-     * @param string $source
518
-     * @return void
519
-     * @throws EE_Error
520
-     * @throws InvalidArgumentException
521
-     * @throws InvalidDataTypeException
522
-     * @throws InvalidInterfaceException
523
-     * @throws ReflectionException
524
-     */
525
-    public function reserve_ticket($update_ticket = false, $source = 'unknown')
526
-    {
527
-        // only reserve ticket if space is not currently reserved
528
-        if ((bool) $this->get_extra_meta(EE_Registration::HAS_RESERVED_TICKET_KEY, true) !== true) {
529
-            $reserved = $this->update_extra_meta(EE_Registration::HAS_RESERVED_TICKET_KEY, true);
530
-            if ($reserved && $update_ticket) {
531
-                $ticket = $this->ticket();
532
-                $ticket->increaseReserved(1, "REG: {$this->ID()} (ln:" . __LINE__ . ')');
533
-                $this->update_extra_meta('reserve_ticket', "{$this->ticket_ID()} from {$source}");
534
-                $ticket->save();
535
-            }
536
-        }
537
-    }
538
-
539
-
540
-    /**
541
-     * stops tracking this registration's ticket reservation in extra meta
542
-     * decrements (subtracts) related ticket reserved and corresponding datetime reserved values
543
-     *
544
-     * @param bool   $update_ticket if true, will decrement ticket and datetime reserved count
545
-     * @param string $source
546
-     * @return void
547
-     * @throws EE_Error
548
-     * @throws InvalidArgumentException
549
-     * @throws InvalidDataTypeException
550
-     * @throws InvalidInterfaceException
551
-     * @throws ReflectionException
552
-     */
553
-    public function release_reserved_ticket($update_ticket = false, $source = 'unknown')
554
-    {
555
-        // only release ticket if space is currently reserved
556
-        if ((bool) $this->get_extra_meta(EE_Registration::HAS_RESERVED_TICKET_KEY, true) === true) {
557
-            $reserved = $this->update_extra_meta(EE_Registration::HAS_RESERVED_TICKET_KEY, false);
558
-            if ($reserved && $update_ticket) {
559
-                $ticket = $this->ticket();
560
-                $ticket->decreaseReserved(1, true, "REG: {$this->ID()} (ln:" . __LINE__ . ')');
561
-                $this->update_extra_meta('release_reserved_ticket', "{$this->ticket_ID()} from {$source}");
562
-            }
563
-        }
564
-    }
565
-
566
-
567
-    /**
568
-     * Set Attendee ID
569
-     *
570
-     * @param int $ATT_ID Attendee ID
571
-     * @throws DomainException
572
-     * @throws EE_Error
573
-     * @throws EntityNotFoundException
574
-     * @throws InvalidArgumentException
575
-     * @throws InvalidDataTypeException
576
-     * @throws InvalidInterfaceException
577
-     * @throws ReflectionException
578
-     * @throws RuntimeException
579
-     * @throws UnexpectedEntityException
580
-     */
581
-    public function set_attendee_id($ATT_ID = 0)
582
-    {
583
-        $this->set('ATT_ID', $ATT_ID);
584
-    }
585
-
586
-
587
-    /**
588
-     *        Set Transaction ID
589
-     *
590
-     * @param int $TXN_ID Transaction ID
591
-     * @throws DomainException
592
-     * @throws EE_Error
593
-     * @throws EntityNotFoundException
594
-     * @throws InvalidArgumentException
595
-     * @throws InvalidDataTypeException
596
-     * @throws InvalidInterfaceException
597
-     * @throws ReflectionException
598
-     * @throws RuntimeException
599
-     * @throws UnexpectedEntityException
600
-     */
601
-    public function set_transaction_id($TXN_ID = 0)
602
-    {
603
-        $this->set('TXN_ID', $TXN_ID);
604
-    }
605
-
606
-
607
-    /**
608
-     *        Set Session
609
-     *
610
-     * @param string $REG_session PHP Session ID
611
-     * @throws DomainException
612
-     * @throws EE_Error
613
-     * @throws EntityNotFoundException
614
-     * @throws InvalidArgumentException
615
-     * @throws InvalidDataTypeException
616
-     * @throws InvalidInterfaceException
617
-     * @throws ReflectionException
618
-     * @throws RuntimeException
619
-     * @throws UnexpectedEntityException
620
-     */
621
-    public function set_session($REG_session = '')
622
-    {
623
-        $this->set('REG_session', $REG_session);
624
-    }
625
-
626
-
627
-    /**
628
-     *        Set Registration URL Link
629
-     *
630
-     * @param string $REG_url_link Registration URL Link
631
-     * @throws DomainException
632
-     * @throws EE_Error
633
-     * @throws EntityNotFoundException
634
-     * @throws InvalidArgumentException
635
-     * @throws InvalidDataTypeException
636
-     * @throws InvalidInterfaceException
637
-     * @throws ReflectionException
638
-     * @throws RuntimeException
639
-     * @throws UnexpectedEntityException
640
-     */
641
-    public function set_reg_url_link($REG_url_link = '')
642
-    {
643
-        $this->set('REG_url_link', $REG_url_link);
644
-    }
645
-
646
-
647
-    /**
648
-     *        Set Attendee Counter
649
-     *
650
-     * @param int $REG_count Primary Attendee
651
-     * @throws DomainException
652
-     * @throws EE_Error
653
-     * @throws EntityNotFoundException
654
-     * @throws InvalidArgumentException
655
-     * @throws InvalidDataTypeException
656
-     * @throws InvalidInterfaceException
657
-     * @throws ReflectionException
658
-     * @throws RuntimeException
659
-     * @throws UnexpectedEntityException
660
-     */
661
-    public function set_count($REG_count = 1)
662
-    {
663
-        $this->set('REG_count', $REG_count);
664
-    }
665
-
666
-
667
-    /**
668
-     *        Set Group Size
669
-     *
670
-     * @param boolean $REG_group_size Group Registration
671
-     * @throws DomainException
672
-     * @throws EE_Error
673
-     * @throws EntityNotFoundException
674
-     * @throws InvalidArgumentException
675
-     * @throws InvalidDataTypeException
676
-     * @throws InvalidInterfaceException
677
-     * @throws ReflectionException
678
-     * @throws RuntimeException
679
-     * @throws UnexpectedEntityException
680
-     */
681
-    public function set_group_size($REG_group_size = false)
682
-    {
683
-        $this->set('REG_group_size', $REG_group_size);
684
-    }
685
-
686
-
687
-    /**
688
-     *    is_not_approved -  convenience method that returns TRUE if REG status ID ==
689
-     *    EEM_Registration::status_id_not_approved
690
-     *
691
-     * @return        boolean
692
-     * @throws EE_Error
693
-     * @throws InvalidArgumentException
694
-     * @throws InvalidDataTypeException
695
-     * @throws InvalidInterfaceException
696
-     * @throws ReflectionException
697
-     */
698
-    public function is_not_approved()
699
-    {
700
-        return $this->status_ID() === EEM_Registration::status_id_not_approved;
701
-    }
702
-
703
-
704
-    /**
705
-     *    is_pending_payment -  convenience method that returns TRUE if REG status ID ==
706
-     *    EEM_Registration::status_id_pending_payment
707
-     *
708
-     * @return        boolean
709
-     * @throws EE_Error
710
-     * @throws InvalidArgumentException
711
-     * @throws InvalidDataTypeException
712
-     * @throws InvalidInterfaceException
713
-     * @throws ReflectionException
714
-     */
715
-    public function is_pending_payment()
716
-    {
717
-        return $this->status_ID() === EEM_Registration::status_id_pending_payment;
718
-    }
719
-
720
-
721
-    /**
722
-     *    is_approved -  convenience method that returns TRUE if REG status ID == EEM_Registration::status_id_approved
723
-     *
724
-     * @return        boolean
725
-     * @throws EE_Error
726
-     * @throws InvalidArgumentException
727
-     * @throws InvalidDataTypeException
728
-     * @throws InvalidInterfaceException
729
-     * @throws ReflectionException
730
-     */
731
-    public function is_approved()
732
-    {
733
-        return $this->status_ID() === EEM_Registration::status_id_approved;
734
-    }
735
-
736
-
737
-    /**
738
-     *    is_cancelled -  convenience method that returns TRUE if REG status ID == EEM_Registration::status_id_cancelled
739
-     *
740
-     * @return        boolean
741
-     * @throws EE_Error
742
-     * @throws InvalidArgumentException
743
-     * @throws InvalidDataTypeException
744
-     * @throws InvalidInterfaceException
745
-     * @throws ReflectionException
746
-     */
747
-    public function is_cancelled()
748
-    {
749
-        return $this->status_ID() === EEM_Registration::status_id_cancelled;
750
-    }
751
-
752
-
753
-    /**
754
-     *    is_declined -  convenience method that returns TRUE if REG status ID == EEM_Registration::status_id_declined
755
-     *
756
-     * @return        boolean
757
-     * @throws EE_Error
758
-     * @throws InvalidArgumentException
759
-     * @throws InvalidDataTypeException
760
-     * @throws InvalidInterfaceException
761
-     * @throws ReflectionException
762
-     */
763
-    public function is_declined()
764
-    {
765
-        return $this->status_ID() === EEM_Registration::status_id_declined;
766
-    }
767
-
768
-
769
-    /**
770
-     *    is_incomplete -  convenience method that returns TRUE if REG status ID ==
771
-     *    EEM_Registration::status_id_incomplete
772
-     *
773
-     * @return        boolean
774
-     * @throws EE_Error
775
-     * @throws InvalidArgumentException
776
-     * @throws InvalidDataTypeException
777
-     * @throws InvalidInterfaceException
778
-     * @throws ReflectionException
779
-     */
780
-    public function is_incomplete()
781
-    {
782
-        return $this->status_ID() === EEM_Registration::status_id_incomplete;
783
-    }
784
-
785
-
786
-    /**
787
-     *        Set Registration Date
788
-     *
789
-     * @param mixed ( int or string ) $REG_date Registration Date - Unix timestamp or string representation of
790
-     *                                                 Date
791
-     * @throws DomainException
792
-     * @throws EE_Error
793
-     * @throws EntityNotFoundException
794
-     * @throws InvalidArgumentException
795
-     * @throws InvalidDataTypeException
796
-     * @throws InvalidInterfaceException
797
-     * @throws ReflectionException
798
-     * @throws RuntimeException
799
-     * @throws UnexpectedEntityException
800
-     */
801
-    public function set_reg_date($REG_date = false)
802
-    {
803
-        $this->set('REG_date', $REG_date);
804
-    }
805
-
806
-
807
-    /**
808
-     *    Set final price owing for this registration after all ticket/price modifications
809
-     *
810
-     * @param float $REG_final_price
811
-     * @throws DomainException
812
-     * @throws EE_Error
813
-     * @throws EntityNotFoundException
814
-     * @throws InvalidArgumentException
815
-     * @throws InvalidDataTypeException
816
-     * @throws InvalidInterfaceException
817
-     * @throws ReflectionException
818
-     * @throws RuntimeException
819
-     * @throws UnexpectedEntityException
820
-     */
821
-    public function set_final_price($REG_final_price = 0.00)
822
-    {
823
-        $this->set('REG_final_price', $REG_final_price);
824
-    }
825
-
826
-
827
-    /**
828
-     *    Set amount paid towards this registration's final price
829
-     *
830
-     * @param float|int|string $REG_paid
831
-     * @throws DomainException
832
-     * @throws EE_Error
833
-     * @throws EntityNotFoundException
834
-     * @throws InvalidArgumentException
835
-     * @throws InvalidDataTypeException
836
-     * @throws InvalidInterfaceException
837
-     * @throws ReflectionException
838
-     * @throws RuntimeException
839
-     * @throws UnexpectedEntityException
840
-     */
841
-    public function set_paid($REG_paid = 0.00)
842
-    {
843
-        $this->set('REG_paid', (float) $REG_paid);
844
-    }
845
-
846
-
847
-    /**
848
-     *        Attendee Is Going
849
-     *
850
-     * @param boolean $REG_att_is_going Attendee Is Going
851
-     * @throws DomainException
852
-     * @throws EE_Error
853
-     * @throws EntityNotFoundException
854
-     * @throws InvalidArgumentException
855
-     * @throws InvalidDataTypeException
856
-     * @throws InvalidInterfaceException
857
-     * @throws ReflectionException
858
-     * @throws RuntimeException
859
-     * @throws UnexpectedEntityException
860
-     */
861
-    public function set_att_is_going($REG_att_is_going = false)
862
-    {
863
-        $this->set('REG_att_is_going', $REG_att_is_going);
864
-    }
865
-
866
-
867
-    /**
868
-     * Gets the related attendee
869
-     *
870
-     * @return EE_Attendee|EE_Base_Class
871
-     * @throws EE_Error
872
-     * @throws InvalidArgumentException
873
-     * @throws InvalidDataTypeException
874
-     * @throws InvalidInterfaceException
875
-     * @throws ReflectionException
876
-     */
877
-    public function attendee()
878
-    {
879
-        return $this->get_first_related('Attendee');
880
-    }
881
-
882
-
883
-    /**
884
-     * Gets the name of the attendee.
885
-     *
886
-     * @param bool $apply_html_entities set to true if you want to use HTML entities.
887
-     * @return string
888
-     * @throws EE_Error
889
-     * @throws InvalidArgumentException
890
-     * @throws InvalidDataTypeException
891
-     * @throws InvalidInterfaceException
892
-     * @throws ReflectionException
893
-     * @since 4.10.12.p
894
-     */
895
-    public function attendeeName($apply_html_entities = false)
896
-    {
897
-        $attendee = $this->get_first_related('Attendee');
898
-        if ($attendee instanceof EE_Attendee) {
899
-            $attendee_name = $attendee->full_name($apply_html_entities);
900
-        } else {
901
-            $attendee_name = esc_html__('Unknown', 'event_espresso');
902
-        }
903
-        return $attendee_name;
904
-    }
905
-
906
-
907
-    /**
908
-     *        get Event ID
909
-     */
910
-    public function event_ID()
911
-    {
912
-        return $this->get('EVT_ID');
913
-    }
914
-
915
-
916
-    /**
917
-     *        get Event ID
918
-     */
919
-    public function event_name()
920
-    {
921
-        $event = $this->event_obj();
922
-        if ($event) {
923
-            return $event->name();
924
-        } else {
925
-            return null;
926
-        }
927
-    }
928
-
929
-
930
-    /**
931
-     * Fetches the event this registration is for
932
-     *
933
-     * @return EE_Base_Class|EE_Event
934
-     * @throws EE_Error
935
-     * @throws InvalidArgumentException
936
-     * @throws InvalidDataTypeException
937
-     * @throws InvalidInterfaceException
938
-     * @throws ReflectionException
939
-     */
940
-    public function event_obj()
941
-    {
942
-        return $this->get_first_related('Event');
943
-    }
944
-
945
-
946
-    /**
947
-     *        get Attendee ID
948
-     */
949
-    public function attendee_ID()
950
-    {
951
-        return $this->get('ATT_ID');
952
-    }
953
-
954
-
955
-    /**
956
-     *        get PHP Session ID
957
-     */
958
-    public function session_ID()
959
-    {
960
-        return $this->get('REG_session');
961
-    }
962
-
963
-
964
-    /**
965
-     * Gets the string which represents the URL trigger for the receipt template in the message template system.
966
-     *
967
-     * @param string $messenger 'pdf' or 'html'.  Default 'html'.
968
-     * @return string
969
-     * @throws DomainException
970
-     * @throws InvalidArgumentException
971
-     * @throws InvalidDataTypeException
972
-     * @throws InvalidInterfaceException
973
-     */
974
-    public function receipt_url($messenger = 'html')
975
-    {
976
-        return apply_filters('FHEE__EE_Registration__receipt_url__receipt_url', '', $this, $messenger, 'receipt');
977
-    }
978
-
979
-
980
-    /**
981
-     * Gets the string which represents the URL trigger for the invoice template in the message template system.
982
-     *
983
-     * @param string $messenger 'pdf' or 'html'.  Default 'html'.
984
-     * @return string
985
-     * @throws DomainException
986
-     * @throws InvalidArgumentException
987
-     * @throws InvalidDataTypeException
988
-     * @throws InvalidInterfaceException
989
-     */
990
-    public function invoice_url($messenger = 'html')
991
-    {
992
-        return apply_filters('FHEE__EE_Registration__invoice_url__invoice_url', '', $this, $messenger, 'invoice');
993
-    }
994
-
995
-
996
-    /**
997
-     * get Registration URL Link
998
-     *
999
-     * @return string
1000
-     * @throws EE_Error
1001
-     * @throws InvalidArgumentException
1002
-     * @throws InvalidDataTypeException
1003
-     * @throws InvalidInterfaceException
1004
-     * @throws ReflectionException
1005
-     */
1006
-    public function reg_url_link()
1007
-    {
1008
-        return (string) $this->get('REG_url_link');
1009
-    }
1010
-
1011
-
1012
-    /**
1013
-     * Echoes out invoice_url()
1014
-     *
1015
-     * @param string $type 'download','launch', or 'html' (default is 'launch')
1016
-     * @return void
1017
-     * @throws DomainException
1018
-     * @throws EE_Error
1019
-     * @throws InvalidArgumentException
1020
-     * @throws InvalidDataTypeException
1021
-     * @throws InvalidInterfaceException
1022
-     * @throws ReflectionException
1023
-     */
1024
-    public function e_invoice_url($type = 'launch')
1025
-    {
1026
-        echo esc_url_raw($this->invoice_url($type));
1027
-    }
1028
-
1029
-
1030
-    /**
1031
-     * Echoes out payment_overview_url
1032
-     */
1033
-    public function e_payment_overview_url()
1034
-    {
1035
-        echo esc_url_raw($this->payment_overview_url());
1036
-    }
1037
-
1038
-
1039
-    /**
1040
-     * Gets the URL for the checkout payment options reg step
1041
-     * with this registration's REG_url_link added as a query parameter
1042
-     *
1043
-     * @param bool $clear_session Set to true when you want to clear the session on revisiting the
1044
-     *                            payment overview url.
1045
-     * @return string
1046
-     * @throws EE_Error
1047
-     * @throws InvalidArgumentException
1048
-     * @throws InvalidDataTypeException
1049
-     * @throws InvalidInterfaceException
1050
-     * @throws ReflectionException
1051
-     */
1052
-    public function payment_overview_url($clear_session = false)
1053
-    {
1054
-        return add_query_arg(
1055
-            (array) apply_filters(
1056
-                'FHEE__EE_Registration__payment_overview_url__query_args',
1057
-                [
1058
-                    'e_reg_url_link' => $this->reg_url_link(),
1059
-                    'step'           => 'payment_options',
1060
-                    'revisit'        => true,
1061
-                    'clear_session'  => (bool) $clear_session,
1062
-                ],
1063
-                $this
1064
-            ),
1065
-            EE_Registry::instance()->CFG->core->reg_page_url()
1066
-        );
1067
-    }
1068
-
1069
-
1070
-    /**
1071
-     * Gets the URL for the checkout attendee information reg step
1072
-     * with this registration's REG_url_link added as a query parameter
1073
-     *
1074
-     * @return string
1075
-     * @throws EE_Error
1076
-     * @throws InvalidArgumentException
1077
-     * @throws InvalidDataTypeException
1078
-     * @throws InvalidInterfaceException
1079
-     * @throws ReflectionException
1080
-     */
1081
-    public function edit_attendee_information_url()
1082
-    {
1083
-        return add_query_arg(
1084
-            (array) apply_filters(
1085
-                'FHEE__EE_Registration__edit_attendee_information_url__query_args',
1086
-                [
1087
-                    'e_reg_url_link' => $this->reg_url_link(),
1088
-                    'step'           => 'attendee_information',
1089
-                    'revisit'        => true,
1090
-                ],
1091
-                $this
1092
-            ),
1093
-            EE_Registry::instance()->CFG->core->reg_page_url()
1094
-        );
1095
-    }
1096
-
1097
-
1098
-    /**
1099
-     * Simply generates and returns the appropriate admin_url link to edit this registration
1100
-     *
1101
-     * @return string
1102
-     * @throws EE_Error
1103
-     * @throws InvalidArgumentException
1104
-     * @throws InvalidDataTypeException
1105
-     * @throws InvalidInterfaceException
1106
-     * @throws ReflectionException
1107
-     */
1108
-    public function get_admin_edit_url()
1109
-    {
1110
-        return EEH_URL::add_query_args_and_nonce(
1111
-            [
1112
-                'page'    => 'espresso_registrations',
1113
-                'action'  => 'view_registration',
1114
-                '_REG_ID' => $this->ID(),
1115
-            ],
1116
-            admin_url('admin.php')
1117
-        );
1118
-    }
1119
-
1120
-
1121
-    /**
1122
-     * is_primary_registrant?
1123
-     *
1124
-     * @throws EE_Error
1125
-     * @throws InvalidArgumentException
1126
-     * @throws InvalidDataTypeException
1127
-     * @throws InvalidInterfaceException
1128
-     * @throws ReflectionException
1129
-     */
1130
-    public function is_primary_registrant()
1131
-    {
1132
-        return (int) $this->get('REG_count') === 1;
1133
-    }
1134
-
1135
-
1136
-    /**
1137
-     * This returns the primary registration object for this registration group (which may be this object).
1138
-     *
1139
-     * @return EE_Registration
1140
-     * @throws EE_Error
1141
-     * @throws InvalidArgumentException
1142
-     * @throws InvalidDataTypeException
1143
-     * @throws InvalidInterfaceException
1144
-     * @throws ReflectionException
1145
-     */
1146
-    public function get_primary_registration()
1147
-    {
1148
-        if ($this->is_primary_registrant()) {
1149
-            return $this;
1150
-        }
1151
-
1152
-        // k reg_count !== 1 so let's get the EE_Registration object matching this txn_id and reg_count == 1
1153
-        /** @var EE_Registration $primary_registrant */
1154
-        $primary_registrant = EEM_Registration::instance()->get_one(
1155
-            [
1156
-                [
1157
-                    'TXN_ID'    => $this->transaction_ID(),
1158
-                    'REG_count' => 1,
1159
-                ],
1160
-            ]
1161
-        );
1162
-        return $primary_registrant;
1163
-    }
1164
-
1165
-
1166
-    /**
1167
-     * get  Attendee Number
1168
-     *
1169
-     * @throws EE_Error
1170
-     * @throws InvalidArgumentException
1171
-     * @throws InvalidDataTypeException
1172
-     * @throws InvalidInterfaceException
1173
-     * @throws ReflectionException
1174
-     */
1175
-    public function count()
1176
-    {
1177
-        return $this->get('REG_count');
1178
-    }
1179
-
1180
-
1181
-    /**
1182
-     * get Group Size
1183
-     *
1184
-     * @throws EE_Error
1185
-     * @throws InvalidArgumentException
1186
-     * @throws InvalidDataTypeException
1187
-     * @throws InvalidInterfaceException
1188
-     * @throws ReflectionException
1189
-     */
1190
-    public function group_size()
1191
-    {
1192
-        return $this->get('REG_group_size');
1193
-    }
1194
-
1195
-
1196
-    /**
1197
-     * get Registration Date
1198
-     *
1199
-     * @throws EE_Error
1200
-     * @throws InvalidArgumentException
1201
-     * @throws InvalidDataTypeException
1202
-     * @throws InvalidInterfaceException
1203
-     * @throws ReflectionException
1204
-     */
1205
-    public function date()
1206
-    {
1207
-        return $this->get('REG_date');
1208
-    }
1209
-
1210
-
1211
-    /**
1212
-     * gets a pretty date
1213
-     *
1214
-     * @param string $date_format
1215
-     * @param string $time_format
1216
-     * @return string
1217
-     * @throws EE_Error
1218
-     * @throws InvalidArgumentException
1219
-     * @throws InvalidDataTypeException
1220
-     * @throws InvalidInterfaceException
1221
-     * @throws ReflectionException
1222
-     */
1223
-    public function pretty_date($date_format = null, $time_format = null)
1224
-    {
1225
-        return $this->get_datetime('REG_date', $date_format, $time_format);
1226
-    }
1227
-
1228
-
1229
-    /**
1230
-     * final_price
1231
-     * the registration's share of the transaction total, so that the
1232
-     * sum of all the transaction's REG_final_prices equal the transaction's total
1233
-     *
1234
-     * @return float
1235
-     * @throws EE_Error
1236
-     * @throws InvalidArgumentException
1237
-     * @throws InvalidDataTypeException
1238
-     * @throws InvalidInterfaceException
1239
-     * @throws ReflectionException
1240
-     */
1241
-    public function final_price(): float
1242
-    {
1243
-        return (float) $this->get('REG_final_price');
1244
-    }
1245
-
1246
-
1247
-    /**
1248
-     * pretty_final_price
1249
-     *  final price as formatted string, with correct decimal places and currency symbol
1250
-     *
1251
-     * @return string
1252
-     * @throws EE_Error
1253
-     * @throws InvalidArgumentException
1254
-     * @throws InvalidDataTypeException
1255
-     * @throws InvalidInterfaceException
1256
-     * @throws ReflectionException
1257
-     */
1258
-    public function pretty_final_price()
1259
-    {
1260
-        return $this->get_pretty('REG_final_price');
1261
-    }
1262
-
1263
-
1264
-    /**
1265
-     * get paid (yeah)
1266
-     *
1267
-     * @return float
1268
-     * @throws EE_Error
1269
-     * @throws InvalidArgumentException
1270
-     * @throws InvalidDataTypeException
1271
-     * @throws InvalidInterfaceException
1272
-     * @throws ReflectionException
1273
-     */
1274
-    public function paid(): float
1275
-    {
1276
-        return (float) $this->get('REG_paid');
1277
-    }
1278
-
1279
-
1280
-    /**
1281
-     * pretty_paid
1282
-     *
1283
-     * @return float
1284
-     * @throws EE_Error
1285
-     * @throws InvalidArgumentException
1286
-     * @throws InvalidDataTypeException
1287
-     * @throws InvalidInterfaceException
1288
-     * @throws ReflectionException
1289
-     */
1290
-    public function pretty_paid()
1291
-    {
1292
-        return $this->get_pretty('REG_paid');
1293
-    }
1294
-
1295
-
1296
-    /**
1297
-     * owes_monies_and_can_pay
1298
-     * whether or not this registration has monies owing and it's' status allows payment
1299
-     *
1300
-     * @param array $requires_payment list of registration statuses that allow a registrant to make a payment
1301
-     * @return bool
1302
-     * @throws EE_Error
1303
-     * @throws InvalidArgumentException
1304
-     * @throws InvalidDataTypeException
1305
-     * @throws InvalidInterfaceException
1306
-     * @throws ReflectionException
1307
-     */
1308
-    public function owes_monies_and_can_pay($requires_payment = [])
1309
-    {
1310
-        // these reg statuses require payment (if event is not free)
1311
-        $requires_payment = ! empty($requires_payment)
1312
-            ? $requires_payment
1313
-            : EEM_Registration::reg_statuses_that_allow_payment();
1314
-        if (
1315
-            $this->final_price() !== 0 &&
1316
-            $this->final_price() !== $this->paid() &&
1317
-            in_array($this->status_ID(), $requires_payment)
1318
-        ) {
1319
-            return true;
1320
-        }
1321
-        return false;
1322
-    }
1323
-
1324
-
1325
-    /**
1326
-     * Prints out the return value of $this->pretty_status()
1327
-     *
1328
-     * @param bool $show_icons
1329
-     * @return void
1330
-     * @throws EE_Error
1331
-     * @throws InvalidArgumentException
1332
-     * @throws InvalidDataTypeException
1333
-     * @throws InvalidInterfaceException
1334
-     * @throws ReflectionException
1335
-     */
1336
-    public function e_pretty_status($show_icons = false)
1337
-    {
1338
-        echo wp_kses($this->pretty_status($show_icons), AllowedTags::getAllowedTags());
1339
-    }
1340
-
1341
-
1342
-    /**
1343
-     * Returns a nice version of the status for displaying to customers
1344
-     *
1345
-     * @param bool $show_icons
1346
-     * @return string
1347
-     * @throws EE_Error
1348
-     * @throws InvalidArgumentException
1349
-     * @throws InvalidDataTypeException
1350
-     * @throws InvalidInterfaceException
1351
-     * @throws ReflectionException
1352
-     */
1353
-    public function pretty_status($show_icons = false)
1354
-    {
1355
-        $status = EEM_Status::instance()->localized_status(
1356
-            [$this->status_ID() => esc_html__('unknown', 'event_espresso')],
1357
-            false,
1358
-            'sentence'
1359
-        );
1360
-        $icon   = '';
1361
-        switch ($this->status_ID()) {
1362
-            case EEM_Registration::status_id_approved:
1363
-                $icon = $show_icons
1364
-                    ? '<span class="dashicons dashicons-star-filled ee-icon-size-16 green-text"></span>'
1365
-                    : '';
1366
-                break;
1367
-            case EEM_Registration::status_id_pending_payment:
1368
-                $icon = $show_icons
1369
-                    ? '<span class="dashicons dashicons-star-half ee-icon-size-16 orange-text"></span>'
1370
-                    : '';
1371
-                break;
1372
-            case EEM_Registration::status_id_not_approved:
1373
-                $icon = $show_icons
1374
-                    ? '<span class="dashicons dashicons-marker ee-icon-size-16 orange-text"></span>'
1375
-                    : '';
1376
-                break;
1377
-            case EEM_Registration::status_id_cancelled:
1378
-                $icon = $show_icons
1379
-                    ? '<span class="dashicons dashicons-no ee-icon-size-16 lt-grey-text"></span>'
1380
-                    : '';
1381
-                break;
1382
-            case EEM_Registration::status_id_incomplete:
1383
-                $icon = $show_icons
1384
-                    ? '<span class="dashicons dashicons-no ee-icon-size-16 lt-orange-text"></span>'
1385
-                    : '';
1386
-                break;
1387
-            case EEM_Registration::status_id_declined:
1388
-                $icon = $show_icons
1389
-                    ? '<span class="dashicons dashicons-no ee-icon-size-16 red-text"></span>'
1390
-                    : '';
1391
-                break;
1392
-            case EEM_Registration::status_id_wait_list:
1393
-                $icon = $show_icons
1394
-                    ? '<span class="dashicons dashicons-clipboard ee-icon-size-16 purple-text"></span>'
1395
-                    : '';
1396
-                break;
1397
-        }
1398
-        return $icon . $status[ $this->status_ID() ];
1399
-    }
1400
-
1401
-
1402
-    /**
1403
-     *        get Attendee Is Going
1404
-     */
1405
-    public function att_is_going()
1406
-    {
1407
-        return $this->get('REG_att_is_going');
1408
-    }
1409
-
1410
-
1411
-    /**
1412
-     * Gets related answers
1413
-     *
1414
-     * @param array $query_params @see
1415
-     *                            https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
1416
-     * @return EE_Answer[]|EE_Base_Class[]
1417
-     * @throws EE_Error
1418
-     * @throws InvalidArgumentException
1419
-     * @throws InvalidDataTypeException
1420
-     * @throws InvalidInterfaceException
1421
-     * @throws ReflectionException
1422
-     */
1423
-    public function answers($query_params = [])
1424
-    {
1425
-        return $this->get_many_related('Answer', $query_params);
1426
-    }
1427
-
1428
-
1429
-    /**
1430
-     * Gets the registration's answer value to the specified question
1431
-     * (either the question's ID or a question object)
1432
-     *
1433
-     * @param EE_Question|int $question
1434
-     * @param bool            $pretty_value
1435
-     * @return array|string if pretty_value= true, the result will always be a string
1436
-     * (because the answer might be an array of answer values, so passing pretty_value=true
1437
-     * will convert it into some kind of string)
1438
-     * @throws EE_Error
1439
-     * @throws InvalidArgumentException
1440
-     * @throws InvalidDataTypeException
1441
-     * @throws InvalidInterfaceException
1442
-     */
1443
-    public function answer_value_to_question($question, $pretty_value = true)
1444
-    {
1445
-        $question_id = EEM_Question::instance()->ensure_is_ID($question);
1446
-        return EEM_Answer::instance()->get_answer_value_to_question($this, $question_id, $pretty_value);
1447
-    }
1448
-
1449
-
1450
-    /**
1451
-     * question_groups
1452
-     * returns an array of EE_Question_Group objects for this registration
1453
-     *
1454
-     * @return EE_Question_Group[]
1455
-     * @throws EE_Error
1456
-     * @throws InvalidArgumentException
1457
-     * @throws InvalidDataTypeException
1458
-     * @throws InvalidInterfaceException
1459
-     * @throws ReflectionException
1460
-     */
1461
-    public function question_groups()
1462
-    {
1463
-        return EEM_Event::instance()->get_question_groups_for_event($this->event_ID(), $this);
1464
-    }
1465
-
1466
-
1467
-    /**
1468
-     * count_question_groups
1469
-     * returns a count of the number of EE_Question_Group objects for this registration
1470
-     *
1471
-     * @return int
1472
-     * @throws EE_Error
1473
-     * @throws EntityNotFoundException
1474
-     * @throws InvalidArgumentException
1475
-     * @throws InvalidDataTypeException
1476
-     * @throws InvalidInterfaceException
1477
-     * @throws ReflectionException
1478
-     */
1479
-    public function count_question_groups()
1480
-    {
1481
-        return EEM_Event::instance()->count_related(
1482
-            $this->event_ID(),
1483
-            'Question_Group',
1484
-            [
1485
-                [
1486
-                    'Event_Question_Group.'
1487
-                    . EEM_Event_Question_Group::instance()->fieldNameForContext($this->is_primary_registrant()) => true,
1488
-                ],
1489
-            ]
1490
-        );
1491
-    }
1492
-
1493
-
1494
-    /**
1495
-     * Returns the registration date in the 'standard' string format
1496
-     * (function may be improved in the future to allow for different formats and timezones)
1497
-     *
1498
-     * @return string
1499
-     * @throws EE_Error
1500
-     * @throws InvalidArgumentException
1501
-     * @throws InvalidDataTypeException
1502
-     * @throws InvalidInterfaceException
1503
-     * @throws ReflectionException
1504
-     */
1505
-    public function reg_date()
1506
-    {
1507
-        return $this->get_datetime('REG_date');
1508
-    }
1509
-
1510
-
1511
-    /**
1512
-     * Gets the datetime-ticket for this registration (ie, it can be used to isolate
1513
-     * the ticket this registration purchased, or the datetime they have registered
1514
-     * to attend)
1515
-     *
1516
-     * @return EE_Base_Class|EE_Datetime_Ticket
1517
-     * @throws EE_Error
1518
-     * @throws InvalidArgumentException
1519
-     * @throws InvalidDataTypeException
1520
-     * @throws InvalidInterfaceException
1521
-     * @throws ReflectionException
1522
-     */
1523
-    public function datetime_ticket()
1524
-    {
1525
-        return $this->get_first_related('Datetime_Ticket');
1526
-    }
1527
-
1528
-
1529
-    /**
1530
-     * Sets the registration's datetime_ticket.
1531
-     *
1532
-     * @param EE_Datetime_Ticket $datetime_ticket
1533
-     * @return EE_Base_Class|EE_Datetime_Ticket
1534
-     * @throws EE_Error
1535
-     * @throws InvalidArgumentException
1536
-     * @throws InvalidDataTypeException
1537
-     * @throws InvalidInterfaceException
1538
-     * @throws ReflectionException
1539
-     */
1540
-    public function set_datetime_ticket($datetime_ticket)
1541
-    {
1542
-        return $this->_add_relation_to($datetime_ticket, 'Datetime_Ticket');
1543
-    }
1544
-
1545
-
1546
-    /**
1547
-     * Gets deleted
1548
-     *
1549
-     * @return bool
1550
-     * @throws EE_Error
1551
-     * @throws InvalidArgumentException
1552
-     * @throws InvalidDataTypeException
1553
-     * @throws InvalidInterfaceException
1554
-     * @throws ReflectionException
1555
-     */
1556
-    public function deleted()
1557
-    {
1558
-        return $this->get('REG_deleted');
1559
-    }
1560
-
1561
-
1562
-    /**
1563
-     * Sets deleted
1564
-     *
1565
-     * @param boolean $deleted
1566
-     * @return void
1567
-     * @throws DomainException
1568
-     * @throws EE_Error
1569
-     * @throws EntityNotFoundException
1570
-     * @throws InvalidArgumentException
1571
-     * @throws InvalidDataTypeException
1572
-     * @throws InvalidInterfaceException
1573
-     * @throws ReflectionException
1574
-     * @throws RuntimeException
1575
-     * @throws UnexpectedEntityException
1576
-     */
1577
-    public function set_deleted($deleted)
1578
-    {
1579
-        if ($deleted) {
1580
-            $this->delete();
1581
-        } else {
1582
-            $this->restore();
1583
-        }
1584
-    }
1585
-
1586
-
1587
-    /**
1588
-     * Get the status object of this object
1589
-     *
1590
-     * @return EE_Base_Class|EE_Status
1591
-     * @throws EE_Error
1592
-     * @throws InvalidArgumentException
1593
-     * @throws InvalidDataTypeException
1594
-     * @throws InvalidInterfaceException
1595
-     * @throws ReflectionException
1596
-     */
1597
-    public function status_obj()
1598
-    {
1599
-        return $this->get_first_related('Status');
1600
-    }
1601
-
1602
-
1603
-    /**
1604
-     * Returns the number of times this registration has checked into any of the datetimes
1605
-     * its available for
1606
-     *
1607
-     * @return int
1608
-     * @throws EE_Error
1609
-     * @throws InvalidArgumentException
1610
-     * @throws InvalidDataTypeException
1611
-     * @throws InvalidInterfaceException
1612
-     * @throws ReflectionException
1613
-     */
1614
-    public function count_checkins()
1615
-    {
1616
-        return $this->get_model()->count_related($this, 'Checkin');
1617
-    }
1618
-
1619
-
1620
-    /**
1621
-     * Returns the number of current Check-ins this registration is checked into for any of the datetimes the
1622
-     * registration is for.  Note, this is ONLY checked in (does not include checkedout)
1623
-     *
1624
-     * @return int
1625
-     * @throws EE_Error
1626
-     * @throws InvalidArgumentException
1627
-     * @throws InvalidDataTypeException
1628
-     * @throws InvalidInterfaceException
1629
-     * @throws ReflectionException
1630
-     */
1631
-    public function count_checkins_not_checkedout()
1632
-    {
1633
-        return $this->get_model()->count_related($this, 'Checkin', [['CHK_in' => 1]]);
1634
-    }
1635
-
1636
-
1637
-    /**
1638
-     * The purpose of this method is simply to check whether this registration can checkin to the given datetime.
1639
-     *
1640
-     * @param int | EE_Datetime $DTT_OR_ID      The datetime the registration is being checked against
1641
-     * @param bool              $check_approved This is used to indicate whether the caller wants can_checkin to also
1642
-     *                                          consider registration status as well as datetime access.
1643
-     * @return bool
1644
-     * @throws EE_Error
1645
-     * @throws InvalidArgumentException
1646
-     * @throws InvalidDataTypeException
1647
-     * @throws InvalidInterfaceException
1648
-     * @throws ReflectionException
1649
-     */
1650
-    public function can_checkin($DTT_OR_ID, $check_approved = true)
1651
-    {
1652
-        $DTT_ID = EEM_Datetime::instance()->ensure_is_ID($DTT_OR_ID);
1653
-        // first check registration status
1654
-        if (! $DTT_ID || ($check_approved && ! $this->is_approved())) {
1655
-            return false;
1656
-        }
1657
-        // is there a datetime ticket that matches this dtt_ID?
1658
-        if (
1659
-            ! (EEM_Datetime_Ticket::instance()->exists(
1660
-                [
1661
-                    [
1662
-                        'TKT_ID' => $this->get('TKT_ID'),
1663
-                        'DTT_ID' => $DTT_ID,
1664
-                    ],
1665
-                ]
1666
-            ))
1667
-        ) {
1668
-            return false;
1669
-        }
1670
-
1671
-        // final check is against TKT_uses
1672
-        return $this->verify_can_checkin_against_TKT_uses($DTT_ID);
1673
-    }
1674
-
1675
-
1676
-    /**
1677
-     * This method verifies whether the user can checkin for the given datetime considering the max uses value set on
1678
-     * the ticket. To do this,  a query is done to get the count of the datetime records already checked into.  If the
1679
-     * datetime given does not have a check-in record and checking in for that datetime will exceed the allowed uses,
1680
-     * then return false.  Otherwise return true.
1681
-     *
1682
-     * @param int | EE_Datetime $DTT_OR_ID The datetime the registration is being checked against
1683
-     * @return bool true means can checkin.  false means cannot checkin.
1684
-     * @throws EE_Error
1685
-     * @throws InvalidArgumentException
1686
-     * @throws InvalidDataTypeException
1687
-     * @throws InvalidInterfaceException
1688
-     * @throws ReflectionException
1689
-     */
1690
-    public function verify_can_checkin_against_TKT_uses($DTT_OR_ID)
1691
-    {
1692
-        $DTT_ID = EEM_Datetime::instance()->ensure_is_ID($DTT_OR_ID);
1693
-
1694
-        if (! $DTT_ID) {
1695
-            return false;
1696
-        }
1697
-
1698
-        $max_uses = $this->ticket() instanceof EE_Ticket
1699
-            ? $this->ticket()->uses()
1700
-            : EE_INF;
1701
-
1702
-        // if max uses is not set or equals infinity then return true cause its not a factor for whether user can
1703
-        // check-in or not.
1704
-        if (! $max_uses || $max_uses === EE_INF) {
1705
-            return true;
1706
-        }
1707
-
1708
-        // does this datetime have a checkin record?  If so, then the dtt count has already been verified so we can just
1709
-        // go ahead and toggle.
1710
-        if (EEM_Checkin::instance()->exists([['REG_ID' => $this->ID(), 'DTT_ID' => $DTT_ID]])) {
1711
-            return true;
1712
-        }
1713
-
1714
-        // made it here so the last check is whether the number of checkins per unique datetime on this registration
1715
-        // disallows further check-ins.
1716
-        $count_unique_dtt_checkins = EEM_Checkin::instance()->count(
1717
-            [
1718
-                [
1719
-                    'REG_ID' => $this->ID(),
1720
-                    'CHK_in' => true,
1721
-                ],
1722
-            ],
1723
-            'DTT_ID',
1724
-            true
1725
-        );
1726
-        // checkins have already reached their max number of uses
1727
-        // so registrant can NOT checkin
1728
-        if ($count_unique_dtt_checkins >= $max_uses) {
1729
-            EE_Error::add_error(
1730
-                esc_html__(
1731
-                    'Check-in denied because number of datetime uses for the ticket has been reached or exceeded.',
1732
-                    'event_espresso'
1733
-                ),
1734
-                __FILE__,
1735
-                __FUNCTION__,
1736
-                __LINE__
1737
-            );
1738
-            return false;
1739
-        }
1740
-        return true;
1741
-    }
1742
-
1743
-
1744
-    /**
1745
-     * toggle Check-in status for this registration
1746
-     * Check-ins are toggled in the following order:
1747
-     * never checked in -> checked in
1748
-     * checked in -> checked out
1749
-     * checked out -> checked in
1750
-     *
1751
-     * @param int  $DTT_ID  include specific datetime to toggle Check-in for.
1752
-     *                      If not included or null, then it is assumed latest datetime is being toggled.
1753
-     * @param bool $verify  If true then can_checkin() is used to verify whether the person
1754
-     *                      can be checked in or not.  Otherwise this forces change in checkin status.
1755
-     * @return bool|int     the chk_in status toggled to OR false if nothing got changed.
1756
-     * @throws EE_Error
1757
-     * @throws InvalidArgumentException
1758
-     * @throws InvalidDataTypeException
1759
-     * @throws InvalidInterfaceException
1760
-     * @throws ReflectionException
1761
-     */
1762
-    public function toggle_checkin_status($DTT_ID = null, $verify = false)
1763
-    {
1764
-        if (empty($DTT_ID)) {
1765
-            $datetime = $this->get_latest_related_datetime();
1766
-            $DTT_ID   = $datetime instanceof EE_Datetime ? $datetime->ID() : 0;
1767
-            // verify the registration can checkin for the given DTT_ID
1768
-        } elseif (! $this->can_checkin($DTT_ID, $verify)) {
1769
-            EE_Error::add_error(
1770
-                sprintf(
1771
-                    esc_html__(
1772
-                        'The given registration (ID:%1$d) can not be checked in to the given DTT_ID (%2$d), because the registration does not have access',
1773
-                        'event_espresso'
1774
-                    ),
1775
-                    $this->ID(),
1776
-                    $DTT_ID
1777
-                ),
1778
-                __FILE__,
1779
-                __FUNCTION__,
1780
-                __LINE__
1781
-            );
1782
-            return false;
1783
-        }
1784
-        $status_paths = [
1785
-            EE_Checkin::status_checked_never => EE_Checkin::status_checked_in,
1786
-            EE_Checkin::status_checked_in    => EE_Checkin::status_checked_out,
1787
-            EE_Checkin::status_checked_out   => EE_Checkin::status_checked_in,
1788
-        ];
1789
-        // start by getting the current status so we know what status we'll be changing to.
1790
-        $cur_status = $this->check_in_status_for_datetime($DTT_ID);
1791
-        $status_to  = $status_paths[ $cur_status ];
1792
-        // database only records true for checked IN or false for checked OUT
1793
-        // no record ( null ) means checked in NEVER, but we obviously don't save that
1794
-        $new_status = $status_to === EE_Checkin::status_checked_in;
1795
-        // add relation - note Check-ins are always creating new rows
1796
-        // because we are keeping track of Check-ins over time.
1797
-        // Eventually we'll probably want to show a list table
1798
-        // for the individual Check-ins so that they can be managed.
1799
-        $checkin = EE_Checkin::new_instance(
1800
-            [
1801
-                'REG_ID' => $this->ID(),
1802
-                'DTT_ID' => $DTT_ID,
1803
-                'CHK_in' => $new_status,
1804
-            ]
1805
-        );
1806
-        // if the record could not be saved then return false
1807
-        if ($checkin->save() === 0) {
1808
-            if (WP_DEBUG) {
1809
-                global $wpdb;
1810
-                $error = sprintf(
1811
-                    esc_html__(
1812
-                        'Registration check in update failed because of the following database error: %1$s%2$s',
1813
-                        'event_espresso'
1814
-                    ),
1815
-                    '<br />',
1816
-                    $wpdb->last_error
1817
-                );
1818
-            } else {
1819
-                $error = esc_html__(
1820
-                    'Registration check in update failed because of an unknown database error',
1821
-                    'event_espresso'
1822
-                );
1823
-            }
1824
-            EE_Error::add_error($error, __FILE__, __FUNCTION__, __LINE__);
1825
-            return false;
1826
-        }
1827
-        // Fire a checked_in and checkout_out action.
1828
-        $checked_status = $status_to === EE_Checkin::status_checked_in
1829
-            ? 'checked_in'
1830
-            : 'checked_out';
1831
-        do_action("AHEE__EE_Registration__toggle_checkin_status__{$checked_status}", $this, $DTT_ID);
1832
-        return $status_to;
1833
-    }
1834
-
1835
-
1836
-    /**
1837
-     * Returns the latest datetime related to this registration (via the ticket attached to the registration).
1838
-     * "Latest" is defined by the `DTT_EVT_start` column.
1839
-     *
1840
-     * @return EE_Datetime|null
1841
-     * @throws EE_Error
1842
-     * @throws InvalidArgumentException
1843
-     * @throws InvalidDataTypeException
1844
-     * @throws InvalidInterfaceException
1845
-     * @throws ReflectionException
1846
-     */
1847
-    public function get_latest_related_datetime(): ?EE_Datetime
1848
-    {
1849
-        return EEM_Datetime::instance()->get_one(
1850
-            [
1851
-                [
1852
-                    'Ticket.Registration.REG_ID' => $this->ID(),
1853
-                ],
1854
-                'order_by' => ['DTT_EVT_start' => 'DESC'],
1855
-            ]
1856
-        );
1857
-    }
1858
-
1859
-
1860
-    /**
1861
-     * Returns the earliest datetime related to this registration (via the ticket attached to the registration).
1862
-     * "Earliest" is defined by the `DTT_EVT_start` column.
1863
-     *
1864
-     * @return EE_Base_Class|EE_Soft_Delete_Base_Class|NULL
1865
-     * @throws EE_Error
1866
-     * @throws InvalidArgumentException
1867
-     * @throws InvalidDataTypeException
1868
-     * @throws InvalidInterfaceException
1869
-     * @throws ReflectionException
1870
-     */
1871
-    public function get_earliest_related_datetime()
1872
-    {
1873
-        return EEM_Datetime::instance()->get_one(
1874
-            [
1875
-                [
1876
-            [
1877
-                [
1878
-                    'Ticket.Registration.REG_ID' => $this->ID(),
1879
-                ],
1880
-                'order_by' => ['DTT_EVT_start' => 'ASC'],
1881
-            ]
1882
-                ],
1883
-                'order_by' => ['DTT_EVT_start' => 'ASC'],
1884
-            ]
1885
-        );
1886
-    }
1887
-
1888
-
1889
-    /**
1890
-     * This method simply returns the check-in status for this registration and the given datetime.
1891
-     * If neither the datetime nor the checkin values are provided as arguments,
1892
-     * then this will return the LATEST check-in status for the registration across all datetimes it belongs to.
1893
-     *
1894
-     * @param int|null        $DTT_ID  The ID of the datetime we're checking against
1895
-     *                                 (if empty we'll get the primary datetime for
1896
-     *                                 this registration (via event) and use it's ID);
1897
-     * @param EE_Checkin|null $checkin If present, we use the given checkin object rather than the dtt_id.
1898
-     * @return int                     Integer representing Check-in status.
1899
-     * @throws EE_Error
1900
-     * @throws ReflectionException
1901
-     */
1902
-    public function check_in_status_for_datetime(?int $DTT_ID = 0, ?EE_Checkin $checkin = null): int
1903
-    {
1904
-        if ($checkin instanceof EE_Checkin) {
1905
-            return $checkin->status();
1906
-        }
1907
-
1908
-        if (! $DTT_ID) {
1909
-            return EE_Checkin::status_invalid;
1910
-        }
1911
-
1912
-        $checkin_query_params = [
1913
-            0          => ['DTT_ID' => $DTT_ID],
1914
-            'order_by' => ['CHK_timestamp' => 'DESC'],
1915
-        ];
1916
-
1917
-        $checkin = $this->get_first_related(
1918
-            'Checkin',
1919
-            $checkin_query_params
1920
-        );
1921
-        return $checkin instanceof EE_Checkin ? $checkin->status() : EE_Checkin::status_checked_never;
1922
-    }
1923
-
1924
-
1925
-    /**
1926
-     * This method returns a localized message for the toggled Check-in message.
1927
-     *
1928
-     * @param int|null $DTT_ID include specific datetime to get the correct Check-in message.  If not included or null,
1929
-     *                         then it is assumed Check-in for primary datetime was toggled.
1930
-     * @param bool     $error  This just flags that you want an error message returned. This is put in so that the error
1931
-     *                         message can be customized with the attendee name.
1932
-     * @return string internationalized message
1933
-     * @throws EE_Error
1934
-     * @throws ReflectionException
1935
-     */
1936
-    public function get_checkin_msg(?int $DTT_ID, bool $error = false): string
1937
-    {
1938
-        // let's get the attendee first so we can include the name of the attendee
1939
-        $attendee = $this->get_first_related('Attendee');
1940
-        if ($attendee instanceof EE_Attendee) {
1941
-            if ($error) {
1942
-                return sprintf(
1943
-                    esc_html__("%s's check-in status was not changed.", "event_espresso"),
1944
-                    $attendee->full_name()
1945
-                );
1946
-            }
1947
-            $cur_status = $this->check_in_status_for_datetime($DTT_ID);
1948
-            // what is the status message going to be?
1949
-            switch ($cur_status) {
1950
-                case EE_Checkin::status_checked_never:
1951
-                    return sprintf(
1952
-                        esc_html__('%s has been removed from Check-in records', 'event_espresso'),
1953
-                        $attendee->full_name()
1954
-                    );
1955
-                case EE_Checkin::status_checked_in:
1956
-                    return sprintf(esc_html__('%s has been checked in', 'event_espresso'), $attendee->full_name());
1957
-                case EE_Checkin::status_checked_out:
1958
-                    return sprintf(esc_html__('%s has been checked out', 'event_espresso'), $attendee->full_name());
1959
-            }
1960
-        }
1961
-        return esc_html__('The check-in status could not be determined.', 'event_espresso');
1962
-    }
1963
-
1964
-
1965
-    /**
1966
-     * Returns the related EE_Transaction to this registration
1967
-     *
1968
-     * @return EE_Transaction
1969
-     * @throws EE_Error
1970
-     * @throws EntityNotFoundException
1971
-     * @throws ReflectionException
1972
-     */
1973
-    public function transaction(): EE_Transaction
1974
-    {
1975
-        $transaction = $this->get_first_related('Transaction');
1976
-        if (! $transaction instanceof \EE_Transaction) {
1977
-            throw new EntityNotFoundException('Transaction ID', $this->transaction_ID());
1978
-        }
1979
-        return $transaction;
1980
-    }
1981
-
1982
-
1983
-    /**
1984
-     * get Registration Code
1985
-     *
1986
-     * @return string
1987
-     * @throws EE_Error
1988
-     * @throws InvalidArgumentException
1989
-     * @throws InvalidDataTypeException
1990
-     * @throws InvalidInterfaceException
1991
-     * @throws ReflectionException
1992
-     */
1993
-    public function reg_code(): string
1994
-    {
1995
-        return $this->get('REG_code')
1996
-            ?: '';
1997
-    }
1998
-
1999
-
2000
-    /**
2001
-     * @return mixed
2002
-     * @throws EE_Error
2003
-     * @throws InvalidArgumentException
2004
-     * @throws InvalidDataTypeException
2005
-     * @throws InvalidInterfaceException
2006
-     * @throws ReflectionException
2007
-     */
2008
-    public function transaction_ID()
2009
-    {
2010
-        return $this->get('TXN_ID');
2011
-    }
2012
-
2013
-
2014
-    /**
2015
-     * @return int
2016
-     * @throws EE_Error
2017
-     * @throws InvalidArgumentException
2018
-     * @throws InvalidDataTypeException
2019
-     * @throws InvalidInterfaceException
2020
-     * @throws ReflectionException
2021
-     */
2022
-    public function ticket_ID()
2023
-    {
2024
-        return $this->get('TKT_ID');
2025
-    }
2026
-
2027
-
2028
-    /**
2029
-     * Set Registration Code
2030
-     *
2031
-     * @param RegCode|string $REG_code Registration Code
2032
-     * @param boolean        $use_default
2033
-     * @throws EE_Error
2034
-     * @throws InvalidArgumentException
2035
-     * @throws InvalidDataTypeException
2036
-     * @throws InvalidInterfaceException
2037
-     * @throws ReflectionException
2038
-     */
2039
-    public function set_reg_code($REG_code, bool $use_default = false)
2040
-    {
2041
-        if (empty($REG_code)) {
2042
-            EE_Error::add_error(
2043
-                esc_html__('REG_code can not be empty.', 'event_espresso'),
2044
-                __FILE__,
2045
-                __FUNCTION__,
2046
-                __LINE__
2047
-            );
2048
-            return;
2049
-        }
2050
-        if (! $this->reg_code()) {
2051
-            parent::set('REG_code', $REG_code, $use_default);
2052
-        } else {
2053
-            EE_Error::doing_it_wrong(
2054
-                __CLASS__ . '::' . __FUNCTION__,
2055
-                esc_html__('Can not change a registration REG_code once it has been set.', 'event_espresso'),
2056
-                '4.6.0'
2057
-            );
2058
-        }
2059
-    }
2060
-
2061
-
2062
-    /**
2063
-     * Returns all other registrations in the same group as this registrant who have the same ticket option.
2064
-     * Note, if you want to just get all registrations in the same transaction (group), use:
2065
-     *    $registration->transaction()->registrations();
2066
-     *
2067
-     * @return EE_Registration[] or empty array if this isn't a group registration.
2068
-     * @throws EE_Error
2069
-     * @throws InvalidArgumentException
2070
-     * @throws InvalidDataTypeException
2071
-     * @throws InvalidInterfaceException
2072
-     * @throws ReflectionException
2073
-     * @since 4.5.0
2074
-     */
2075
-    public function get_all_other_registrations_in_group()
2076
-    {
2077
-        if ($this->group_size() < 2) {
2078
-            return [];
2079
-        }
2080
-
2081
-        $query[0] = [
2082
-            'TXN_ID' => $this->transaction_ID(),
2083
-            'REG_ID' => ['!=', $this->ID()],
2084
-            'TKT_ID' => $this->ticket_ID(),
2085
-        ];
2086
-        /** @var EE_Registration[] $registrations */
2087
-        $registrations = $this->get_model()->get_all($query);
2088
-        return $registrations;
2089
-    }
2090
-
2091
-
2092
-    /**
2093
-     * Return the link to the admin details for the object.
2094
-     *
2095
-     * @return string
2096
-     * @throws EE_Error
2097
-     * @throws InvalidArgumentException
2098
-     * @throws InvalidDataTypeException
2099
-     * @throws InvalidInterfaceException
2100
-     * @throws ReflectionException
2101
-     */
2102
-    public function get_admin_details_link()
2103
-    {
2104
-        EE_Registry::instance()->load_helper('URL');
2105
-        return EEH_URL::add_query_args_and_nonce(
2106
-            [
2107
-                'page'    => 'espresso_registrations',
2108
-                'action'  => 'view_registration',
2109
-                '_REG_ID' => $this->ID(),
2110
-            ],
2111
-            admin_url('admin.php')
2112
-        );
2113
-    }
2114
-
2115
-
2116
-    /**
2117
-     * Returns the link to the editor for the object.  Sometimes this is the same as the details.
2118
-     *
2119
-     * @return string
2120
-     * @throws EE_Error
2121
-     * @throws InvalidArgumentException
2122
-     * @throws InvalidDataTypeException
2123
-     * @throws InvalidInterfaceException
2124
-     * @throws ReflectionException
2125
-     */
2126
-    public function get_admin_edit_link()
2127
-    {
2128
-        return $this->get_admin_details_link();
2129
-    }
2130
-
2131
-
2132
-    /**
2133
-     * Returns the link to a settings page for the object.
2134
-     *
2135
-     * @return string
2136
-     * @throws EE_Error
2137
-     * @throws InvalidArgumentException
2138
-     * @throws InvalidDataTypeException
2139
-     * @throws InvalidInterfaceException
2140
-     * @throws ReflectionException
2141
-     */
2142
-    public function get_admin_settings_link()
2143
-    {
2144
-        return $this->get_admin_details_link();
2145
-    }
2146
-
2147
-
2148
-    /**
2149
-     * Returns the link to the "overview" for the object (typically the "list table" view).
2150
-     *
2151
-     * @return string
2152
-     * @throws EE_Error
2153
-     * @throws InvalidArgumentException
2154
-     * @throws InvalidDataTypeException
2155
-     * @throws InvalidInterfaceException
2156
-     * @throws ReflectionException
2157
-     */
2158
-    public function get_admin_overview_link()
2159
-    {
2160
-        EE_Registry::instance()->load_helper('URL');
2161
-        return EEH_URL::add_query_args_and_nonce(
2162
-            [
2163
-                'page' => 'espresso_registrations',
2164
-            ],
2165
-            admin_url('admin.php')
2166
-        );
2167
-    }
2168
-
2169
-
2170
-    /**
2171
-     * @param array $query_params
2172
-     * @return EE_Base_Class[]|EE_Registration[]
2173
-     * @throws EE_Error
2174
-     * @throws InvalidArgumentException
2175
-     * @throws InvalidDataTypeException
2176
-     * @throws InvalidInterfaceException
2177
-     * @throws ReflectionException
2178
-     */
2179
-    public function payments($query_params = [])
2180
-    {
2181
-        return $this->get_many_related('Payment', $query_params);
2182
-    }
2183
-
2184
-
2185
-    /**
2186
-     * @param array $query_params
2187
-     * @return EE_Base_Class[]|EE_Registration_Payment[]
2188
-     * @throws EE_Error
2189
-     * @throws InvalidArgumentException
2190
-     * @throws InvalidDataTypeException
2191
-     * @throws InvalidInterfaceException
2192
-     * @throws ReflectionException
2193
-     */
2194
-    public function registration_payments($query_params = [])
2195
-    {
2196
-        return $this->get_many_related('Registration_Payment', $query_params);
2197
-    }
2198
-
2199
-
2200
-    /**
2201
-     * This grabs the payment method corresponding to the last payment made for the amount owing on the registration.
2202
-     * Note: if there are no payments on the registration there will be no payment method returned.
2203
-     *
2204
-     * @return EE_Payment|EE_Payment_Method|null
2205
-     * @throws EE_Error
2206
-     * @throws InvalidArgumentException
2207
-     * @throws InvalidDataTypeException
2208
-     * @throws InvalidInterfaceException
2209
-     */
2210
-    public function payment_method()
2211
-    {
2212
-        return EEM_Payment_Method::instance()->get_last_used_for_registration($this);
2213
-    }
2214
-
2215
-
2216
-    /**
2217
-     * @return \EE_Line_Item
2218
-     * @throws EE_Error
2219
-     * @throws EntityNotFoundException
2220
-     * @throws InvalidArgumentException
2221
-     * @throws InvalidDataTypeException
2222
-     * @throws InvalidInterfaceException
2223
-     * @throws ReflectionException
2224
-     */
2225
-    public function ticket_line_item()
2226
-    {
2227
-        $ticket            = $this->ticket();
2228
-        $transaction       = $this->transaction();
2229
-        $line_item         = null;
2230
-        $ticket_line_items = \EEH_Line_Item::get_line_items_by_object_type_and_IDs(
2231
-            $transaction->total_line_item(),
2232
-            'Ticket',
2233
-            [$ticket->ID()]
2234
-        );
2235
-        foreach ($ticket_line_items as $ticket_line_item) {
2236
-            if (
2237
-                $ticket_line_item instanceof \EE_Line_Item
2238
-                && $ticket_line_item->OBJ_type() === 'Ticket'
2239
-                && $ticket_line_item->OBJ_ID() === $ticket->ID()
2240
-            ) {
2241
-                $line_item = $ticket_line_item;
2242
-                break;
2243
-            }
2244
-        }
2245
-        if (! ($line_item instanceof \EE_Line_Item && $line_item->OBJ_type() === 'Ticket')) {
2246
-            throw new EntityNotFoundException('Line Item Ticket ID', $ticket->ID());
2247
-        }
2248
-        return $line_item;
2249
-    }
2250
-
2251
-
2252
-    /**
2253
-     * Soft Deletes this model object.
2254
-     *
2255
-     * @param string $source function name that called this method
2256
-     * @return boolean | int
2257
-     * @throws DomainException
2258
-     * @throws EE_Error
2259
-     * @throws EntityNotFoundException
2260
-     * @throws InvalidArgumentException
2261
-     * @throws InvalidDataTypeException
2262
-     * @throws InvalidInterfaceException
2263
-     * @throws ReflectionException
2264
-     * @throws RuntimeException
2265
-     * @throws UnexpectedEntityException
2266
-     */
2267
-    public function delete()
2268
-    {
2269
-        if ($this->update_extra_meta(EE_Registration::PRE_TRASH_REG_STATUS_KEY, $this->status_ID()) === true) {
2270
-            $this->set_status(EEM_Registration::status_id_cancelled);
2271
-        }
2272
-        return parent::delete();
2273
-    }
2274
-
2275
-
2276
-    /**
2277
-     * Restores whatever the previous status was on a registration before it was trashed (if possible)
2278
-     *
2279
-     * @param string $source function name that called this method
2280
-     * @return bool|int
2281
-     * @throws DomainException
2282
-     * @throws EE_Error
2283
-     * @throws EntityNotFoundException
2284
-     * @throws InvalidArgumentException
2285
-     * @throws InvalidDataTypeException
2286
-     * @throws InvalidInterfaceException
2287
-     * @throws ReflectionException
2288
-     * @throws RuntimeException
2289
-     * @throws UnexpectedEntityException
2290
-     */
2291
-    public function restore()
2292
-    {
2293
-        $previous_status = $this->get_extra_meta(
2294
-            EE_Registration::PRE_TRASH_REG_STATUS_KEY,
2295
-            true,
2296
-            EEM_Registration::status_id_cancelled
2297
-        );
2298
-        if ($previous_status) {
2299
-            $this->delete_extra_meta(EE_Registration::PRE_TRASH_REG_STATUS_KEY);
2300
-            $this->set_status($previous_status);
2301
-        }
2302
-        return parent::restore();
2303
-    }
2304
-
2305
-
2306
-    /**
2307
-     * possibly toggle Registration status based on comparison of REG_paid vs REG_final_price
2308
-     *
2309
-     * @param boolean $trigger_set_status_logic  EE_Registration::set_status() can trigger additional logic
2310
-     *                                           depending on whether the reg status changes to or from "Approved"
2311
-     * @return boolean whether the Registration status was updated
2312
-     * @throws DomainException
2313
-     * @throws EE_Error
2314
-     * @throws EntityNotFoundException
2315
-     * @throws InvalidArgumentException
2316
-     * @throws InvalidDataTypeException
2317
-     * @throws InvalidInterfaceException
2318
-     * @throws ReflectionException
2319
-     * @throws RuntimeException
2320
-     * @throws UnexpectedEntityException
2321
-     */
2322
-    public function updateStatusBasedOnTotalPaid($trigger_set_status_logic = true)
2323
-    {
2324
-        $paid  = $this->paid();
2325
-        $price = $this->final_price();
2326
-        switch (true) {
2327
-            // overpaid or paid
2328
-            case EEH_Money::compare_floats($paid, $price, '>'):
2329
-            case EEH_Money::compare_floats($paid, $price):
2330
-                $new_status = EEM_Registration::status_id_approved;
2331
-                break;
2332
-            //  underpaid
2333
-            case EEH_Money::compare_floats($paid, $price, '<'):
2334
-                $new_status = EEM_Registration::status_id_pending_payment;
2335
-                break;
2336
-            // uhhh Houston...
2337
-            default:
2338
-                throw new RuntimeException(
2339
-                    esc_html__('The total paid calculation for this registration is inaccurate.', 'event_espresso')
2340
-                );
2341
-        }
2342
-        if ($new_status !== $this->status_ID()) {
2343
-            if ($trigger_set_status_logic) {
2344
-                return $this->set_status($new_status);
2345
-            }
2346
-            parent::set('STS_ID', $new_status);
2347
-            return true;
2348
-        }
2349
-        return false;
2350
-    }
2351
-
2352
-
2353
-    /*************************** DEPRECATED ***************************/
2354
-
2355
-
2356
-    /**
2357
-     * @deprecated
2358
-     * @since     4.7.0
2359
-     */
2360
-    public function price_paid()
2361
-    {
2362
-        EE_Error::doing_it_wrong(
2363
-            'EE_Registration::price_paid()',
2364
-            esc_html__(
2365
-                'This method is deprecated, please use EE_Registration::final_price() instead.',
2366
-                'event_espresso'
2367
-            ),
2368
-            '4.7.0'
2369
-        );
2370
-        return $this->final_price();
2371
-    }
2372
-
2373
-
2374
-    /**
2375
-     * @param float $REG_final_price
2376
-     * @throws EE_Error
2377
-     * @throws EntityNotFoundException
2378
-     * @throws InvalidArgumentException
2379
-     * @throws InvalidDataTypeException
2380
-     * @throws InvalidInterfaceException
2381
-     * @throws ReflectionException
2382
-     * @throws RuntimeException
2383
-     * @throws DomainException
2384
-     * @deprecated
2385
-     * @since     4.7.0
2386
-     */
2387
-    public function set_price_paid($REG_final_price = 0.00)
2388
-    {
2389
-        EE_Error::doing_it_wrong(
2390
-            'EE_Registration::set_price_paid()',
2391
-            esc_html__(
2392
-                'This method is deprecated, please use EE_Registration::set_final_price() instead.',
2393
-                'event_espresso'
2394
-            ),
2395
-            '4.7.0'
2396
-        );
2397
-        $this->set_final_price($REG_final_price);
2398
-    }
2399
-
2400
-
2401
-    /**
2402
-     * @return string
2403
-     * @throws EE_Error
2404
-     * @throws InvalidArgumentException
2405
-     * @throws InvalidDataTypeException
2406
-     * @throws InvalidInterfaceException
2407
-     * @throws ReflectionException
2408
-     * @deprecated
2409
-     * @since 4.7.0
2410
-     */
2411
-    public function pretty_price_paid()
2412
-    {
2413
-        EE_Error::doing_it_wrong(
2414
-            'EE_Registration::pretty_price_paid()',
2415
-            esc_html__(
2416
-                'This method is deprecated, please use EE_Registration::pretty_final_price() instead.',
2417
-                'event_espresso'
2418
-            ),
2419
-            '4.7.0'
2420
-        );
2421
-        return $this->pretty_final_price();
2422
-    }
2423
-
2424
-
2425
-    /**
2426
-     * Gets the primary datetime related to this registration via the related Event to this registration
2427
-     *
2428
-     * @return EE_Datetime
2429
-     * @throws EE_Error
2430
-     * @throws EntityNotFoundException
2431
-     * @throws InvalidArgumentException
2432
-     * @throws InvalidDataTypeException
2433
-     * @throws InvalidInterfaceException
2434
-     * @throws ReflectionException
2435
-     * @deprecated 4.9.17
2436
-     */
2437
-    public function get_related_primary_datetime()
2438
-    {
2439
-        EE_Error::doing_it_wrong(
2440
-            __METHOD__,
2441
-            esc_html__(
2442
-                'Use EE_Registration::get_latest_related_datetime() or EE_Registration::get_earliest_related_datetime()',
2443
-                'event_espresso'
2444
-            ),
2445
-            '4.9.17',
2446
-            '5.0.0'
2447
-        );
2448
-        return $this->event()->primary_datetime();
2449
-    }
2450
-
2451
-
2452
-    /**
2453
-     * Returns the contact's name (or "Unknown" if there is no contact.)
2454
-     *
2455
-     * @return string
2456
-     * @throws EE_Error
2457
-     * @throws InvalidArgumentException
2458
-     * @throws InvalidDataTypeException
2459
-     * @throws InvalidInterfaceException
2460
-     * @throws ReflectionException
2461
-     * @since 4.10.12.p
2462
-     */
2463
-    public function name()
2464
-    {
2465
-        return $this->attendeeName();
2466
-    }
2467
-
2468
-
2469
-    /**
2470
-     * @return bool
2471
-     * @throws EE_Error
2472
-     * @throws ReflectionException
2473
-     */
2474
-    public function wasMoved(): bool
2475
-    {
2476
-        // only need to check 'registration-moved-to' because
2477
-        // the existence of a new REG ID means the registration was moved
2478
-        $reg_moved = $this->get_extra_meta('registration-moved-to', true, []);
2479
-        return isset($reg_moved['NEW_REG_ID']) && $reg_moved['NEW_REG_ID'];
2480
-    }
2481
-
2482
-
2483
-    /**
2484
-     * @param EE_Payment $payment
2485
-     * @param float|null $amount
2486
-     * @return float
2487
-     * @throws EE_Error
2488
-     * @throws ReflectionException
2489
-     * @since 5.0.8.p
2490
-     */
2491
-    public function applyPayment(EE_Payment $payment, ?float $amount = null): float
2492
-    {
2493
-        // echo "\n\n";
2494
-        // \EEH_Debug_Tools::printr(__FUNCTION__, __CLASS__, __FILE__, __LINE__, 3);
2495
-        // \EEH_Debug_Tools::printr($this->ID(), 'REG ID', __FILE__, __LINE__);
2496
-        $payment_amount = $amount ?? $payment->amount();
2497
-        // ensure $payment_amount is NOT negative
2498
-        $payment_amount = (float) abs($payment_amount);
2499
-        // \EEH_Debug_Tools::printr($payment_amount, 'incoming $payment_amount', __FILE__, __LINE__);
2500
-        // \EEH_Debug_Tools::printr($this->final_price(), 'reg final price', __FILE__, __LINE__);
2501
-        // \EEH_Debug_Tools::printr($this->paid(), 'reg paid to date', __FILE__, __LINE__);
2502
-        $payment_amount = $payment->is_a_refund()
2503
-            ? $this->processRefund($payment_amount)
2504
-            : $this->processPayment($payment_amount);
2505
-        // \EEH_Debug_Tools::printr($payment_amount, 'applied payment_amount', __FILE__, __LINE__);
2506
-        if ($payment_amount) {
2507
-            $reg_payment = EEM_Registration_Payment::instance()->get_one(
2508
-                [['REG_ID' => $this->ID(), 'PAY_ID' => $payment->ID()]]
2509
-            );
2510
-            // if existing registration payment exists
2511
-            if ($reg_payment instanceof EE_Registration_Payment) {
2512
-                // echo "\nUPDATE EXISTING REG PAYMENT";
2513
-                // then update that record
2514
-                $reg_payment->set_amount($payment_amount);
2515
-            } else {
2516
-                // echo "\nCREATE NEW REG PAYMENT";
2517
-                // or add new relation between registration and payment and set amount
2518
-                $reg_payment = EE_Registration_Payment::new_instance(
2519
-                    [
2520
-                        'REG_ID'     => $this->ID(),
2521
-                        'PAY_ID'     => $payment->ID(),
2522
-                        'RPY_amount' => $payment_amount,
2523
-                    ]
2524
-                );
2525
-                // $this->_add_relation_to($payment, 'Payment', ['RPY_amount' => $payment_amount]);
2526
-            }
2527
-            $reg_payment->save();
2528
-            // \EEH_Debug_Tools::printr($reg_payment->ID(), '$reg payment ID', __FILE__, __LINE__);
2529
-        }
2530
-        return $payment_amount;
2531
-    }
2532
-
2533
-
2534
-    /**
2535
-     * @throws EE_Error
2536
-     * @throws ReflectionException
2537
-     */
2538
-    private function processPayment(float $payment_amount): float
2539
-    {
2540
-        // echo "\n";
2541
-        // \EEH_Debug_Tools::printr(__FUNCTION__, __CLASS__, __FILE__, __LINE__, 3);
2542
-        $paid  = $this->paid();
2543
-        $owing = $this->final_price() - $paid;
2544
-        // \EEH_Debug_Tools::printr($owing, '$owing', __FILE__, __LINE__);
2545
-        if ($owing <= 0) {
2546
-            return 0.0;
2547
-        }
2548
-        // don't allow payment amount to exceed the incoming amount, OR the amount owing
2549
-        $payment_amount = min($payment_amount, $owing);
2550
-        $paid           = $paid + $payment_amount;
2551
-        // \EEH_Debug_Tools::printr($paid, 'NEW REG PAID AMOUNT', __FILE__, __LINE__);
2552
-        // calculate and set new REG_paid
2553
-        $this->set_paid($paid);
2554
-        // make it stick
2555
-        $this->save();
2556
-        return (float) $payment_amount;
2557
-    }
2558
-
2559
-
2560
-    /**
2561
-     * @throws ReflectionException
2562
-     * @throws EE_Error
2563
-     */
2564
-    private function processRefund(float $payment_amount): float
2565
-    {
2566
-        // echo "\n";
2567
-        // \EEH_Debug_Tools::printr(__FUNCTION__, __CLASS__, __FILE__, __LINE__, 3);
2568
-        $paid = $this->paid();
2569
-        if ($paid <= 0) {
2570
-            return 0.0;
2571
-        }
2572
-        // don't allow refund amount to exceed the incoming amount, OR the amount paid
2573
-        $payment_amount = min($payment_amount, $paid);
2574
-        // calculate and set new REG_paid
2575
-        $paid = $paid - $payment_amount;
2576
-        \EEH_Debug_Tools::printr($paid, 'NEW REG PAID AMOUNT', __FILE__, __LINE__);
2577
-        $this->set_paid($paid);
2578
-        // make it stick
2579
-        $this->save();
2580
-        // convert payment amount back to a negative value for storage in the db
2581
-        return (float) $payment_amount;
2582
-    }
20
+	/**
21
+	 * Used to reference when a registration has never been checked in.
22
+	 *
23
+	 * @deprecated use \EE_Checkin::status_checked_never instead
24
+	 * @type int
25
+	 */
26
+	const checkin_status_never = 2;
27
+
28
+	/**
29
+	 * Used to reference when a registration has been checked in.
30
+	 *
31
+	 * @deprecated use \EE_Checkin::status_checked_in instead
32
+	 * @type int
33
+	 */
34
+	const checkin_status_in = 1;
35
+
36
+	/**
37
+	 * Used to reference when a registration has been checked out.
38
+	 *
39
+	 * @deprecated use \EE_Checkin::status_checked_out instead
40
+	 * @type int
41
+	 */
42
+	const checkin_status_out = 0;
43
+
44
+	/**
45
+	 * extra meta key for tracking reg status os trashed registrations
46
+	 *
47
+	 * @type string
48
+	 */
49
+	const PRE_TRASH_REG_STATUS_KEY = 'pre_trash_registration_status';
50
+
51
+	/**
52
+	 * extra meta key for tracking if registration has reserved ticket
53
+	 *
54
+	 * @type string
55
+	 */
56
+	const HAS_RESERVED_TICKET_KEY = 'has_reserved_ticket';
57
+
58
+
59
+	/**
60
+	 * @param array  $props_n_values          incoming values
61
+	 * @param string $timezone                incoming timezone (if not set the timezone set for the website will be
62
+	 *                                        used.)
63
+	 * @param array  $date_formats            incoming date_formats in an array where the first value is the
64
+	 *                                        date_format and the second value is the time format
65
+	 * @return EE_Registration
66
+	 * @throws EE_Error
67
+	 * @throws InvalidArgumentException
68
+	 * @throws InvalidDataTypeException
69
+	 * @throws InvalidInterfaceException
70
+	 * @throws ReflectionException
71
+	 */
72
+	public static function new_instance($props_n_values = [], $timezone = '', $date_formats = [])
73
+	{
74
+		$has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats);
75
+		return $has_object
76
+			?: new self($props_n_values, false, $timezone, $date_formats);
77
+	}
78
+
79
+
80
+	/**
81
+	 * @param array  $props_n_values  incoming values from the database
82
+	 * @param string $timezone        incoming timezone as set by the model.  If not set the timezone for
83
+	 *                                the website will be used.
84
+	 * @return EE_Registration
85
+	 * @throws EE_Error
86
+	 * @throws InvalidArgumentException
87
+	 * @throws InvalidDataTypeException
88
+	 * @throws InvalidInterfaceException
89
+	 * @throws ReflectionException
90
+	 */
91
+	public static function new_instance_from_db($props_n_values = [], $timezone = '')
92
+	{
93
+		return new self($props_n_values, true, $timezone);
94
+	}
95
+
96
+
97
+	/**
98
+	 *        Set Event ID
99
+	 *
100
+	 * @param int $EVT_ID Event ID
101
+	 * @throws DomainException
102
+	 * @throws EE_Error
103
+	 * @throws EntityNotFoundException
104
+	 * @throws InvalidArgumentException
105
+	 * @throws InvalidDataTypeException
106
+	 * @throws InvalidInterfaceException
107
+	 * @throws ReflectionException
108
+	 * @throws RuntimeException
109
+	 * @throws UnexpectedEntityException
110
+	 */
111
+	public function set_event($EVT_ID = 0)
112
+	{
113
+		$this->set('EVT_ID', $EVT_ID);
114
+	}
115
+
116
+
117
+	/**
118
+	 * Overrides parent set() method so that all calls to set( 'REG_code', $REG_code ) OR set( 'STS_ID', $STS_ID ) can
119
+	 * be routed to internal methods
120
+	 *
121
+	 * @param string $field_name
122
+	 * @param mixed  $field_value
123
+	 * @param bool   $use_default
124
+	 * @throws DomainException
125
+	 * @throws EE_Error
126
+	 * @throws EntityNotFoundException
127
+	 * @throws InvalidArgumentException
128
+	 * @throws InvalidDataTypeException
129
+	 * @throws InvalidInterfaceException
130
+	 * @throws ReflectionException
131
+	 * @throws RuntimeException
132
+	 * @throws UnexpectedEntityException
133
+	 */
134
+	public function set($field_name, $field_value, $use_default = false)
135
+	{
136
+		switch ($field_name) {
137
+			case 'REG_code':
138
+				if (! empty($field_value) && ! $this->reg_code()) {
139
+					$this->set_reg_code($field_value, $use_default);
140
+				}
141
+				break;
142
+			case 'STS_ID':
143
+				$this->set_status($field_value, $use_default);
144
+				break;
145
+			default:
146
+				parent::set($field_name, $field_value, $use_default);
147
+		}
148
+	}
149
+
150
+
151
+	/**
152
+	 * Set Status ID
153
+	 * updates the registration status and ALSO...
154
+	 * calls reserve_registration_space() if the reg status changes TO approved from any other reg status
155
+	 * calls release_registration_space() if the reg status changes FROM approved to any other reg status
156
+	 *
157
+	 * @param string                $new_STS_ID
158
+	 * @param boolean               $use_default
159
+	 * @param ContextInterface|null $context
160
+	 * @return bool
161
+	 * @throws DomainException
162
+	 * @throws EE_Error
163
+	 * @throws EntityNotFoundException
164
+	 * @throws InvalidArgumentException
165
+	 * @throws InvalidDataTypeException
166
+	 * @throws InvalidInterfaceException
167
+	 * @throws ReflectionException
168
+	 * @throws RuntimeException
169
+	 * @throws UnexpectedEntityException
170
+	 */
171
+	public function set_status($new_STS_ID = null, $use_default = false, ContextInterface $context = null)
172
+	{
173
+		// get current REG_Status
174
+		$old_STS_ID = $this->status_ID();
175
+		// if status has changed
176
+		if (
177
+			$old_STS_ID !== $new_STS_ID // and that status has actually changed
178
+			&& ! empty($old_STS_ID) // and that old status is actually set
179
+			&& ! empty($new_STS_ID) // as well as the new status
180
+			&& $this->ID() // ensure registration is in the db
181
+		) {
182
+			// update internal status first
183
+			parent::set('STS_ID', $new_STS_ID, $use_default);
184
+			// THEN handle other changes that occur when reg status changes
185
+			// TO approved
186
+			if ($new_STS_ID === EEM_Registration::status_id_approved) {
187
+				// reserve a space by incrementing ticket and datetime sold values
188
+				$this->reserveRegistrationSpace();
189
+				do_action('AHEE__EE_Registration__set_status__to_approved', $this, $old_STS_ID, $new_STS_ID, $context);
190
+				// OR FROM  approved
191
+			} elseif ($old_STS_ID === EEM_Registration::status_id_approved) {
192
+				// release a space by decrementing ticket and datetime sold values
193
+				$this->releaseRegistrationSpace();
194
+				do_action(
195
+					'AHEE__EE_Registration__set_status__from_approved',
196
+					$this,
197
+					$old_STS_ID,
198
+					$new_STS_ID,
199
+					$context
200
+				);
201
+			}
202
+			// update status
203
+			parent::set('STS_ID', $new_STS_ID, $use_default);
204
+			$this->updateIfCanceledOrReinstated($new_STS_ID, $old_STS_ID, $context);
205
+			if ($this->statusChangeUpdatesTransaction($context)) {
206
+				$this->updateTransactionAfterStatusChange();
207
+			}
208
+			do_action('AHEE__EE_Registration__set_status__after_update', $this, $old_STS_ID, $new_STS_ID, $context);
209
+			return true;
210
+		}
211
+		// even though the old value matches the new value, it's still good to
212
+		// allow the parent set method to have a say
213
+		parent::set('STS_ID', $new_STS_ID, $use_default);
214
+		return true;
215
+	}
216
+
217
+
218
+	/**
219
+	 * update REGs and TXN when cancelled or declined registrations involved
220
+	 *
221
+	 * @param string                $new_STS_ID
222
+	 * @param string                $old_STS_ID
223
+	 * @param ContextInterface|null $context
224
+	 * @throws EE_Error
225
+	 * @throws InvalidArgumentException
226
+	 * @throws InvalidDataTypeException
227
+	 * @throws InvalidInterfaceException
228
+	 * @throws ReflectionException
229
+	 * @throws RuntimeException
230
+	 */
231
+	private function updateIfCanceledOrReinstated($new_STS_ID, $old_STS_ID, ContextInterface $context = null)
232
+	{
233
+		// these reg statuses should not be considered in any calculations involving monies owing
234
+		$closed_reg_statuses = EEM_Registration::closed_reg_statuses();
235
+		// true if registration has been cancelled or declined
236
+		$this->updateIfCanceled(
237
+			$closed_reg_statuses,
238
+			$new_STS_ID,
239
+			$old_STS_ID,
240
+			$context
241
+		);
242
+		$this->updateIfReinstated(
243
+			$closed_reg_statuses,
244
+			$new_STS_ID,
245
+			$old_STS_ID,
246
+			$context
247
+		);
248
+	}
249
+
250
+
251
+	/**
252
+	 * update REGs and TXN when cancelled or declined registrations involved
253
+	 *
254
+	 * @param array                 $closed_reg_statuses
255
+	 * @param string                $new_STS_ID
256
+	 * @param string                $old_STS_ID
257
+	 * @param ContextInterface|null $context
258
+	 * @throws EE_Error
259
+	 * @throws InvalidArgumentException
260
+	 * @throws InvalidDataTypeException
261
+	 * @throws InvalidInterfaceException
262
+	 * @throws ReflectionException
263
+	 * @throws RuntimeException
264
+	 */
265
+	private function updateIfCanceled(
266
+		array $closed_reg_statuses,
267
+		$new_STS_ID,
268
+		$old_STS_ID,
269
+		ContextInterface $context = null
270
+	) {
271
+		// true if registration has been cancelled or declined
272
+		if (
273
+			in_array($new_STS_ID, $closed_reg_statuses, true)
274
+			&& ! in_array($old_STS_ID, $closed_reg_statuses, true)
275
+		) {
276
+			/** @type EE_Registration_Processor $registration_processor */
277
+			$registration_processor = EE_Registry::instance()->load_class('Registration_Processor');
278
+			/** @type EE_Transaction_Processor $transaction_processor */
279
+			$transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor');
280
+			// cancelled or declined registration
281
+			$registration_processor->update_registration_after_being_canceled_or_declined(
282
+				$this,
283
+				$closed_reg_statuses
284
+			);
285
+			$transaction_processor->update_transaction_after_canceled_or_declined_registration(
286
+				$this,
287
+				$closed_reg_statuses,
288
+				false
289
+			);
290
+			do_action(
291
+				'AHEE__EE_Registration__set_status__canceled_or_declined',
292
+				$this,
293
+				$old_STS_ID,
294
+				$new_STS_ID,
295
+				$context
296
+			);
297
+			return;
298
+		}
299
+	}
300
+
301
+
302
+	/**
303
+	 * update REGs and TXN when cancelled or declined registrations involved
304
+	 *
305
+	 * @param array                 $closed_reg_statuses
306
+	 * @param string                $new_STS_ID
307
+	 * @param string                $old_STS_ID
308
+	 * @param ContextInterface|null $context
309
+	 * @throws EE_Error
310
+	 * @throws InvalidArgumentException
311
+	 * @throws InvalidDataTypeException
312
+	 * @throws InvalidInterfaceException
313
+	 * @throws ReflectionException
314
+	 * @throws RuntimeException
315
+	 */
316
+	private function updateIfReinstated(
317
+		array $closed_reg_statuses,
318
+		$new_STS_ID,
319
+		$old_STS_ID,
320
+		ContextInterface $context = null
321
+	) {
322
+		// true if reinstating cancelled or declined registration
323
+		if (
324
+			in_array($old_STS_ID, $closed_reg_statuses, true)
325
+			&& ! in_array($new_STS_ID, $closed_reg_statuses, true)
326
+		) {
327
+			/** @type EE_Registration_Processor $registration_processor */
328
+			$registration_processor = EE_Registry::instance()->load_class('Registration_Processor');
329
+			/** @type EE_Transaction_Processor $transaction_processor */
330
+			$transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor');
331
+			// reinstating cancelled or declined registration
332
+			$registration_processor->update_canceled_or_declined_registration_after_being_reinstated(
333
+				$this,
334
+				$closed_reg_statuses
335
+			);
336
+			$transaction_processor->update_transaction_after_reinstating_canceled_registration(
337
+				$this,
338
+				$closed_reg_statuses,
339
+				false
340
+			);
341
+			do_action(
342
+				'AHEE__EE_Registration__set_status__after_reinstated',
343
+				$this,
344
+				$old_STS_ID,
345
+				$new_STS_ID,
346
+				$context
347
+			);
348
+		}
349
+	}
350
+
351
+
352
+	/**
353
+	 * @param ContextInterface|null $context
354
+	 * @return bool
355
+	 */
356
+	private function statusChangeUpdatesTransaction(ContextInterface $context = null)
357
+	{
358
+		$contexts_that_do_not_update_transaction = (array) apply_filters(
359
+			'AHEE__EE_Registration__statusChangeUpdatesTransaction__contexts_that_do_not_update_transaction',
360
+			['spco_reg_step_attendee_information_process_registrations'],
361
+			$context,
362
+			$this
363
+		);
364
+		return ! (
365
+			$context instanceof ContextInterface
366
+			&& in_array($context->slug(), $contexts_that_do_not_update_transaction, true)
367
+		);
368
+	}
369
+
370
+
371
+	/**
372
+	 * @throws EE_Error
373
+	 * @throws EntityNotFoundException
374
+	 * @throws InvalidArgumentException
375
+	 * @throws InvalidDataTypeException
376
+	 * @throws InvalidInterfaceException
377
+	 * @throws ReflectionException
378
+	 * @throws RuntimeException
379
+	 */
380
+	private function updateTransactionAfterStatusChange()
381
+	{
382
+		/** @type EE_Transaction_Payments $transaction_payments */
383
+		$transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments');
384
+		$transaction_payments->recalculate_transaction_total($this->transaction(), false);
385
+		$this->transaction()->update_status_based_on_total_paid();
386
+	}
387
+
388
+
389
+	/**
390
+	 * get Status ID
391
+	 *
392
+	 * @throws EE_Error
393
+	 * @throws InvalidArgumentException
394
+	 * @throws InvalidDataTypeException
395
+	 * @throws InvalidInterfaceException
396
+	 * @throws ReflectionException
397
+	 */
398
+	public function status_ID()
399
+	{
400
+		return $this->get('STS_ID');
401
+	}
402
+
403
+
404
+	/**
405
+	 * Gets the ticket this registration is for
406
+	 *
407
+	 * @param boolean $include_archived whether to include archived tickets or not.
408
+	 * @return EE_Ticket|EE_Base_Class
409
+	 * @throws EE_Error
410
+	 * @throws InvalidArgumentException
411
+	 * @throws InvalidDataTypeException
412
+	 * @throws InvalidInterfaceException
413
+	 * @throws ReflectionException
414
+	 */
415
+	public function ticket($include_archived = true)
416
+	{
417
+		$query_params = [];
418
+		if ($include_archived) {
419
+			$query_params['default_where_conditions'] = 'none';
420
+		}
421
+		return $this->get_first_related('Ticket', $query_params);
422
+	}
423
+
424
+
425
+	/**
426
+	 * Gets the event this registration is for
427
+	 *
428
+	 * @return EE_Event
429
+	 * @throws EE_Error
430
+	 * @throws EntityNotFoundException
431
+	 * @throws InvalidArgumentException
432
+	 * @throws InvalidDataTypeException
433
+	 * @throws InvalidInterfaceException
434
+	 * @throws ReflectionException
435
+	 */
436
+	public function event(): EE_Event
437
+	{
438
+		$event = $this->get_first_related('Event');
439
+		if (! $event instanceof EE_Event) {
440
+			throw new EntityNotFoundException('Event ID', $this->event_ID());
441
+		}
442
+		return $event;
443
+	}
444
+
445
+
446
+	/**
447
+	 * Gets the "author" of the registration.  Note that for the purposes of registrations, the author will correspond
448
+	 * with the author of the event this registration is for.
449
+	 *
450
+	 * @return int
451
+	 * @throws EE_Error
452
+	 * @throws EntityNotFoundException
453
+	 * @throws InvalidArgumentException
454
+	 * @throws InvalidDataTypeException
455
+	 * @throws InvalidInterfaceException
456
+	 * @throws ReflectionException
457
+	 * @since 4.5.0
458
+	 */
459
+	public function wp_user(): int
460
+	{
461
+		return $this->event()->wp_user();
462
+	}
463
+
464
+
465
+	/**
466
+	 * increments this registration's related ticket sold and corresponding datetime sold values
467
+	 *
468
+	 * @return void
469
+	 * @throws DomainException
470
+	 * @throws EE_Error
471
+	 * @throws EntityNotFoundException
472
+	 * @throws InvalidArgumentException
473
+	 * @throws InvalidDataTypeException
474
+	 * @throws InvalidInterfaceException
475
+	 * @throws ReflectionException
476
+	 * @throws UnexpectedEntityException
477
+	 */
478
+	private function reserveRegistrationSpace()
479
+	{
480
+		// reserved ticket and datetime counts will be decremented as sold counts are incremented
481
+		// so stop tracking that this reg has a ticket reserved
482
+		$this->release_reserved_ticket(false, "REG: {$this->ID()} (ln:" . __LINE__ . ')');
483
+		$ticket = $this->ticket();
484
+		$ticket->increaseSold();
485
+		// possibly set event status to sold out
486
+		$this->event()->perform_sold_out_status_check();
487
+	}
488
+
489
+
490
+	/**
491
+	 * decrements (subtracts) this registration's related ticket sold and corresponding datetime sold values
492
+	 *
493
+	 * @return void
494
+	 * @throws DomainException
495
+	 * @throws EE_Error
496
+	 * @throws EntityNotFoundException
497
+	 * @throws InvalidArgumentException
498
+	 * @throws InvalidDataTypeException
499
+	 * @throws InvalidInterfaceException
500
+	 * @throws ReflectionException
501
+	 * @throws UnexpectedEntityException
502
+	 */
503
+	private function releaseRegistrationSpace()
504
+	{
505
+		$ticket = $this->ticket();
506
+		$ticket->decreaseSold();
507
+		// possibly change event status from sold out back to previous status
508
+		$this->event()->perform_sold_out_status_check();
509
+	}
510
+
511
+
512
+	/**
513
+	 * tracks this registration's ticket reservation in extra meta
514
+	 * and can increment related ticket reserved and corresponding datetime reserved values
515
+	 *
516
+	 * @param bool   $update_ticket if true, will increment ticket and datetime reserved count
517
+	 * @param string $source
518
+	 * @return void
519
+	 * @throws EE_Error
520
+	 * @throws InvalidArgumentException
521
+	 * @throws InvalidDataTypeException
522
+	 * @throws InvalidInterfaceException
523
+	 * @throws ReflectionException
524
+	 */
525
+	public function reserve_ticket($update_ticket = false, $source = 'unknown')
526
+	{
527
+		// only reserve ticket if space is not currently reserved
528
+		if ((bool) $this->get_extra_meta(EE_Registration::HAS_RESERVED_TICKET_KEY, true) !== true) {
529
+			$reserved = $this->update_extra_meta(EE_Registration::HAS_RESERVED_TICKET_KEY, true);
530
+			if ($reserved && $update_ticket) {
531
+				$ticket = $this->ticket();
532
+				$ticket->increaseReserved(1, "REG: {$this->ID()} (ln:" . __LINE__ . ')');
533
+				$this->update_extra_meta('reserve_ticket', "{$this->ticket_ID()} from {$source}");
534
+				$ticket->save();
535
+			}
536
+		}
537
+	}
538
+
539
+
540
+	/**
541
+	 * stops tracking this registration's ticket reservation in extra meta
542
+	 * decrements (subtracts) related ticket reserved and corresponding datetime reserved values
543
+	 *
544
+	 * @param bool   $update_ticket if true, will decrement ticket and datetime reserved count
545
+	 * @param string $source
546
+	 * @return void
547
+	 * @throws EE_Error
548
+	 * @throws InvalidArgumentException
549
+	 * @throws InvalidDataTypeException
550
+	 * @throws InvalidInterfaceException
551
+	 * @throws ReflectionException
552
+	 */
553
+	public function release_reserved_ticket($update_ticket = false, $source = 'unknown')
554
+	{
555
+		// only release ticket if space is currently reserved
556
+		if ((bool) $this->get_extra_meta(EE_Registration::HAS_RESERVED_TICKET_KEY, true) === true) {
557
+			$reserved = $this->update_extra_meta(EE_Registration::HAS_RESERVED_TICKET_KEY, false);
558
+			if ($reserved && $update_ticket) {
559
+				$ticket = $this->ticket();
560
+				$ticket->decreaseReserved(1, true, "REG: {$this->ID()} (ln:" . __LINE__ . ')');
561
+				$this->update_extra_meta('release_reserved_ticket', "{$this->ticket_ID()} from {$source}");
562
+			}
563
+		}
564
+	}
565
+
566
+
567
+	/**
568
+	 * Set Attendee ID
569
+	 *
570
+	 * @param int $ATT_ID Attendee ID
571
+	 * @throws DomainException
572
+	 * @throws EE_Error
573
+	 * @throws EntityNotFoundException
574
+	 * @throws InvalidArgumentException
575
+	 * @throws InvalidDataTypeException
576
+	 * @throws InvalidInterfaceException
577
+	 * @throws ReflectionException
578
+	 * @throws RuntimeException
579
+	 * @throws UnexpectedEntityException
580
+	 */
581
+	public function set_attendee_id($ATT_ID = 0)
582
+	{
583
+		$this->set('ATT_ID', $ATT_ID);
584
+	}
585
+
586
+
587
+	/**
588
+	 *        Set Transaction ID
589
+	 *
590
+	 * @param int $TXN_ID Transaction ID
591
+	 * @throws DomainException
592
+	 * @throws EE_Error
593
+	 * @throws EntityNotFoundException
594
+	 * @throws InvalidArgumentException
595
+	 * @throws InvalidDataTypeException
596
+	 * @throws InvalidInterfaceException
597
+	 * @throws ReflectionException
598
+	 * @throws RuntimeException
599
+	 * @throws UnexpectedEntityException
600
+	 */
601
+	public function set_transaction_id($TXN_ID = 0)
602
+	{
603
+		$this->set('TXN_ID', $TXN_ID);
604
+	}
605
+
606
+
607
+	/**
608
+	 *        Set Session
609
+	 *
610
+	 * @param string $REG_session PHP Session ID
611
+	 * @throws DomainException
612
+	 * @throws EE_Error
613
+	 * @throws EntityNotFoundException
614
+	 * @throws InvalidArgumentException
615
+	 * @throws InvalidDataTypeException
616
+	 * @throws InvalidInterfaceException
617
+	 * @throws ReflectionException
618
+	 * @throws RuntimeException
619
+	 * @throws UnexpectedEntityException
620
+	 */
621
+	public function set_session($REG_session = '')
622
+	{
623
+		$this->set('REG_session', $REG_session);
624
+	}
625
+
626
+
627
+	/**
628
+	 *        Set Registration URL Link
629
+	 *
630
+	 * @param string $REG_url_link Registration URL Link
631
+	 * @throws DomainException
632
+	 * @throws EE_Error
633
+	 * @throws EntityNotFoundException
634
+	 * @throws InvalidArgumentException
635
+	 * @throws InvalidDataTypeException
636
+	 * @throws InvalidInterfaceException
637
+	 * @throws ReflectionException
638
+	 * @throws RuntimeException
639
+	 * @throws UnexpectedEntityException
640
+	 */
641
+	public function set_reg_url_link($REG_url_link = '')
642
+	{
643
+		$this->set('REG_url_link', $REG_url_link);
644
+	}
645
+
646
+
647
+	/**
648
+	 *        Set Attendee Counter
649
+	 *
650
+	 * @param int $REG_count Primary Attendee
651
+	 * @throws DomainException
652
+	 * @throws EE_Error
653
+	 * @throws EntityNotFoundException
654
+	 * @throws InvalidArgumentException
655
+	 * @throws InvalidDataTypeException
656
+	 * @throws InvalidInterfaceException
657
+	 * @throws ReflectionException
658
+	 * @throws RuntimeException
659
+	 * @throws UnexpectedEntityException
660
+	 */
661
+	public function set_count($REG_count = 1)
662
+	{
663
+		$this->set('REG_count', $REG_count);
664
+	}
665
+
666
+
667
+	/**
668
+	 *        Set Group Size
669
+	 *
670
+	 * @param boolean $REG_group_size Group Registration
671
+	 * @throws DomainException
672
+	 * @throws EE_Error
673
+	 * @throws EntityNotFoundException
674
+	 * @throws InvalidArgumentException
675
+	 * @throws InvalidDataTypeException
676
+	 * @throws InvalidInterfaceException
677
+	 * @throws ReflectionException
678
+	 * @throws RuntimeException
679
+	 * @throws UnexpectedEntityException
680
+	 */
681
+	public function set_group_size($REG_group_size = false)
682
+	{
683
+		$this->set('REG_group_size', $REG_group_size);
684
+	}
685
+
686
+
687
+	/**
688
+	 *    is_not_approved -  convenience method that returns TRUE if REG status ID ==
689
+	 *    EEM_Registration::status_id_not_approved
690
+	 *
691
+	 * @return        boolean
692
+	 * @throws EE_Error
693
+	 * @throws InvalidArgumentException
694
+	 * @throws InvalidDataTypeException
695
+	 * @throws InvalidInterfaceException
696
+	 * @throws ReflectionException
697
+	 */
698
+	public function is_not_approved()
699
+	{
700
+		return $this->status_ID() === EEM_Registration::status_id_not_approved;
701
+	}
702
+
703
+
704
+	/**
705
+	 *    is_pending_payment -  convenience method that returns TRUE if REG status ID ==
706
+	 *    EEM_Registration::status_id_pending_payment
707
+	 *
708
+	 * @return        boolean
709
+	 * @throws EE_Error
710
+	 * @throws InvalidArgumentException
711
+	 * @throws InvalidDataTypeException
712
+	 * @throws InvalidInterfaceException
713
+	 * @throws ReflectionException
714
+	 */
715
+	public function is_pending_payment()
716
+	{
717
+		return $this->status_ID() === EEM_Registration::status_id_pending_payment;
718
+	}
719
+
720
+
721
+	/**
722
+	 *    is_approved -  convenience method that returns TRUE if REG status ID == EEM_Registration::status_id_approved
723
+	 *
724
+	 * @return        boolean
725
+	 * @throws EE_Error
726
+	 * @throws InvalidArgumentException
727
+	 * @throws InvalidDataTypeException
728
+	 * @throws InvalidInterfaceException
729
+	 * @throws ReflectionException
730
+	 */
731
+	public function is_approved()
732
+	{
733
+		return $this->status_ID() === EEM_Registration::status_id_approved;
734
+	}
735
+
736
+
737
+	/**
738
+	 *    is_cancelled -  convenience method that returns TRUE if REG status ID == EEM_Registration::status_id_cancelled
739
+	 *
740
+	 * @return        boolean
741
+	 * @throws EE_Error
742
+	 * @throws InvalidArgumentException
743
+	 * @throws InvalidDataTypeException
744
+	 * @throws InvalidInterfaceException
745
+	 * @throws ReflectionException
746
+	 */
747
+	public function is_cancelled()
748
+	{
749
+		return $this->status_ID() === EEM_Registration::status_id_cancelled;
750
+	}
751
+
752
+
753
+	/**
754
+	 *    is_declined -  convenience method that returns TRUE if REG status ID == EEM_Registration::status_id_declined
755
+	 *
756
+	 * @return        boolean
757
+	 * @throws EE_Error
758
+	 * @throws InvalidArgumentException
759
+	 * @throws InvalidDataTypeException
760
+	 * @throws InvalidInterfaceException
761
+	 * @throws ReflectionException
762
+	 */
763
+	public function is_declined()
764
+	{
765
+		return $this->status_ID() === EEM_Registration::status_id_declined;
766
+	}
767
+
768
+
769
+	/**
770
+	 *    is_incomplete -  convenience method that returns TRUE if REG status ID ==
771
+	 *    EEM_Registration::status_id_incomplete
772
+	 *
773
+	 * @return        boolean
774
+	 * @throws EE_Error
775
+	 * @throws InvalidArgumentException
776
+	 * @throws InvalidDataTypeException
777
+	 * @throws InvalidInterfaceException
778
+	 * @throws ReflectionException
779
+	 */
780
+	public function is_incomplete()
781
+	{
782
+		return $this->status_ID() === EEM_Registration::status_id_incomplete;
783
+	}
784
+
785
+
786
+	/**
787
+	 *        Set Registration Date
788
+	 *
789
+	 * @param mixed ( int or string ) $REG_date Registration Date - Unix timestamp or string representation of
790
+	 *                                                 Date
791
+	 * @throws DomainException
792
+	 * @throws EE_Error
793
+	 * @throws EntityNotFoundException
794
+	 * @throws InvalidArgumentException
795
+	 * @throws InvalidDataTypeException
796
+	 * @throws InvalidInterfaceException
797
+	 * @throws ReflectionException
798
+	 * @throws RuntimeException
799
+	 * @throws UnexpectedEntityException
800
+	 */
801
+	public function set_reg_date($REG_date = false)
802
+	{
803
+		$this->set('REG_date', $REG_date);
804
+	}
805
+
806
+
807
+	/**
808
+	 *    Set final price owing for this registration after all ticket/price modifications
809
+	 *
810
+	 * @param float $REG_final_price
811
+	 * @throws DomainException
812
+	 * @throws EE_Error
813
+	 * @throws EntityNotFoundException
814
+	 * @throws InvalidArgumentException
815
+	 * @throws InvalidDataTypeException
816
+	 * @throws InvalidInterfaceException
817
+	 * @throws ReflectionException
818
+	 * @throws RuntimeException
819
+	 * @throws UnexpectedEntityException
820
+	 */
821
+	public function set_final_price($REG_final_price = 0.00)
822
+	{
823
+		$this->set('REG_final_price', $REG_final_price);
824
+	}
825
+
826
+
827
+	/**
828
+	 *    Set amount paid towards this registration's final price
829
+	 *
830
+	 * @param float|int|string $REG_paid
831
+	 * @throws DomainException
832
+	 * @throws EE_Error
833
+	 * @throws EntityNotFoundException
834
+	 * @throws InvalidArgumentException
835
+	 * @throws InvalidDataTypeException
836
+	 * @throws InvalidInterfaceException
837
+	 * @throws ReflectionException
838
+	 * @throws RuntimeException
839
+	 * @throws UnexpectedEntityException
840
+	 */
841
+	public function set_paid($REG_paid = 0.00)
842
+	{
843
+		$this->set('REG_paid', (float) $REG_paid);
844
+	}
845
+
846
+
847
+	/**
848
+	 *        Attendee Is Going
849
+	 *
850
+	 * @param boolean $REG_att_is_going Attendee Is Going
851
+	 * @throws DomainException
852
+	 * @throws EE_Error
853
+	 * @throws EntityNotFoundException
854
+	 * @throws InvalidArgumentException
855
+	 * @throws InvalidDataTypeException
856
+	 * @throws InvalidInterfaceException
857
+	 * @throws ReflectionException
858
+	 * @throws RuntimeException
859
+	 * @throws UnexpectedEntityException
860
+	 */
861
+	public function set_att_is_going($REG_att_is_going = false)
862
+	{
863
+		$this->set('REG_att_is_going', $REG_att_is_going);
864
+	}
865
+
866
+
867
+	/**
868
+	 * Gets the related attendee
869
+	 *
870
+	 * @return EE_Attendee|EE_Base_Class
871
+	 * @throws EE_Error
872
+	 * @throws InvalidArgumentException
873
+	 * @throws InvalidDataTypeException
874
+	 * @throws InvalidInterfaceException
875
+	 * @throws ReflectionException
876
+	 */
877
+	public function attendee()
878
+	{
879
+		return $this->get_first_related('Attendee');
880
+	}
881
+
882
+
883
+	/**
884
+	 * Gets the name of the attendee.
885
+	 *
886
+	 * @param bool $apply_html_entities set to true if you want to use HTML entities.
887
+	 * @return string
888
+	 * @throws EE_Error
889
+	 * @throws InvalidArgumentException
890
+	 * @throws InvalidDataTypeException
891
+	 * @throws InvalidInterfaceException
892
+	 * @throws ReflectionException
893
+	 * @since 4.10.12.p
894
+	 */
895
+	public function attendeeName($apply_html_entities = false)
896
+	{
897
+		$attendee = $this->get_first_related('Attendee');
898
+		if ($attendee instanceof EE_Attendee) {
899
+			$attendee_name = $attendee->full_name($apply_html_entities);
900
+		} else {
901
+			$attendee_name = esc_html__('Unknown', 'event_espresso');
902
+		}
903
+		return $attendee_name;
904
+	}
905
+
906
+
907
+	/**
908
+	 *        get Event ID
909
+	 */
910
+	public function event_ID()
911
+	{
912
+		return $this->get('EVT_ID');
913
+	}
914
+
915
+
916
+	/**
917
+	 *        get Event ID
918
+	 */
919
+	public function event_name()
920
+	{
921
+		$event = $this->event_obj();
922
+		if ($event) {
923
+			return $event->name();
924
+		} else {
925
+			return null;
926
+		}
927
+	}
928
+
929
+
930
+	/**
931
+	 * Fetches the event this registration is for
932
+	 *
933
+	 * @return EE_Base_Class|EE_Event
934
+	 * @throws EE_Error
935
+	 * @throws InvalidArgumentException
936
+	 * @throws InvalidDataTypeException
937
+	 * @throws InvalidInterfaceException
938
+	 * @throws ReflectionException
939
+	 */
940
+	public function event_obj()
941
+	{
942
+		return $this->get_first_related('Event');
943
+	}
944
+
945
+
946
+	/**
947
+	 *        get Attendee ID
948
+	 */
949
+	public function attendee_ID()
950
+	{
951
+		return $this->get('ATT_ID');
952
+	}
953
+
954
+
955
+	/**
956
+	 *        get PHP Session ID
957
+	 */
958
+	public function session_ID()
959
+	{
960
+		return $this->get('REG_session');
961
+	}
962
+
963
+
964
+	/**
965
+	 * Gets the string which represents the URL trigger for the receipt template in the message template system.
966
+	 *
967
+	 * @param string $messenger 'pdf' or 'html'.  Default 'html'.
968
+	 * @return string
969
+	 * @throws DomainException
970
+	 * @throws InvalidArgumentException
971
+	 * @throws InvalidDataTypeException
972
+	 * @throws InvalidInterfaceException
973
+	 */
974
+	public function receipt_url($messenger = 'html')
975
+	{
976
+		return apply_filters('FHEE__EE_Registration__receipt_url__receipt_url', '', $this, $messenger, 'receipt');
977
+	}
978
+
979
+
980
+	/**
981
+	 * Gets the string which represents the URL trigger for the invoice template in the message template system.
982
+	 *
983
+	 * @param string $messenger 'pdf' or 'html'.  Default 'html'.
984
+	 * @return string
985
+	 * @throws DomainException
986
+	 * @throws InvalidArgumentException
987
+	 * @throws InvalidDataTypeException
988
+	 * @throws InvalidInterfaceException
989
+	 */
990
+	public function invoice_url($messenger = 'html')
991
+	{
992
+		return apply_filters('FHEE__EE_Registration__invoice_url__invoice_url', '', $this, $messenger, 'invoice');
993
+	}
994
+
995
+
996
+	/**
997
+	 * get Registration URL Link
998
+	 *
999
+	 * @return string
1000
+	 * @throws EE_Error
1001
+	 * @throws InvalidArgumentException
1002
+	 * @throws InvalidDataTypeException
1003
+	 * @throws InvalidInterfaceException
1004
+	 * @throws ReflectionException
1005
+	 */
1006
+	public function reg_url_link()
1007
+	{
1008
+		return (string) $this->get('REG_url_link');
1009
+	}
1010
+
1011
+
1012
+	/**
1013
+	 * Echoes out invoice_url()
1014
+	 *
1015
+	 * @param string $type 'download','launch', or 'html' (default is 'launch')
1016
+	 * @return void
1017
+	 * @throws DomainException
1018
+	 * @throws EE_Error
1019
+	 * @throws InvalidArgumentException
1020
+	 * @throws InvalidDataTypeException
1021
+	 * @throws InvalidInterfaceException
1022
+	 * @throws ReflectionException
1023
+	 */
1024
+	public function e_invoice_url($type = 'launch')
1025
+	{
1026
+		echo esc_url_raw($this->invoice_url($type));
1027
+	}
1028
+
1029
+
1030
+	/**
1031
+	 * Echoes out payment_overview_url
1032
+	 */
1033
+	public function e_payment_overview_url()
1034
+	{
1035
+		echo esc_url_raw($this->payment_overview_url());
1036
+	}
1037
+
1038
+
1039
+	/**
1040
+	 * Gets the URL for the checkout payment options reg step
1041
+	 * with this registration's REG_url_link added as a query parameter
1042
+	 *
1043
+	 * @param bool $clear_session Set to true when you want to clear the session on revisiting the
1044
+	 *                            payment overview url.
1045
+	 * @return string
1046
+	 * @throws EE_Error
1047
+	 * @throws InvalidArgumentException
1048
+	 * @throws InvalidDataTypeException
1049
+	 * @throws InvalidInterfaceException
1050
+	 * @throws ReflectionException
1051
+	 */
1052
+	public function payment_overview_url($clear_session = false)
1053
+	{
1054
+		return add_query_arg(
1055
+			(array) apply_filters(
1056
+				'FHEE__EE_Registration__payment_overview_url__query_args',
1057
+				[
1058
+					'e_reg_url_link' => $this->reg_url_link(),
1059
+					'step'           => 'payment_options',
1060
+					'revisit'        => true,
1061
+					'clear_session'  => (bool) $clear_session,
1062
+				],
1063
+				$this
1064
+			),
1065
+			EE_Registry::instance()->CFG->core->reg_page_url()
1066
+		);
1067
+	}
1068
+
1069
+
1070
+	/**
1071
+	 * Gets the URL for the checkout attendee information reg step
1072
+	 * with this registration's REG_url_link added as a query parameter
1073
+	 *
1074
+	 * @return string
1075
+	 * @throws EE_Error
1076
+	 * @throws InvalidArgumentException
1077
+	 * @throws InvalidDataTypeException
1078
+	 * @throws InvalidInterfaceException
1079
+	 * @throws ReflectionException
1080
+	 */
1081
+	public function edit_attendee_information_url()
1082
+	{
1083
+		return add_query_arg(
1084
+			(array) apply_filters(
1085
+				'FHEE__EE_Registration__edit_attendee_information_url__query_args',
1086
+				[
1087
+					'e_reg_url_link' => $this->reg_url_link(),
1088
+					'step'           => 'attendee_information',
1089
+					'revisit'        => true,
1090
+				],
1091
+				$this
1092
+			),
1093
+			EE_Registry::instance()->CFG->core->reg_page_url()
1094
+		);
1095
+	}
1096
+
1097
+
1098
+	/**
1099
+	 * Simply generates and returns the appropriate admin_url link to edit this registration
1100
+	 *
1101
+	 * @return string
1102
+	 * @throws EE_Error
1103
+	 * @throws InvalidArgumentException
1104
+	 * @throws InvalidDataTypeException
1105
+	 * @throws InvalidInterfaceException
1106
+	 * @throws ReflectionException
1107
+	 */
1108
+	public function get_admin_edit_url()
1109
+	{
1110
+		return EEH_URL::add_query_args_and_nonce(
1111
+			[
1112
+				'page'    => 'espresso_registrations',
1113
+				'action'  => 'view_registration',
1114
+				'_REG_ID' => $this->ID(),
1115
+			],
1116
+			admin_url('admin.php')
1117
+		);
1118
+	}
1119
+
1120
+
1121
+	/**
1122
+	 * is_primary_registrant?
1123
+	 *
1124
+	 * @throws EE_Error
1125
+	 * @throws InvalidArgumentException
1126
+	 * @throws InvalidDataTypeException
1127
+	 * @throws InvalidInterfaceException
1128
+	 * @throws ReflectionException
1129
+	 */
1130
+	public function is_primary_registrant()
1131
+	{
1132
+		return (int) $this->get('REG_count') === 1;
1133
+	}
1134
+
1135
+
1136
+	/**
1137
+	 * This returns the primary registration object for this registration group (which may be this object).
1138
+	 *
1139
+	 * @return EE_Registration
1140
+	 * @throws EE_Error
1141
+	 * @throws InvalidArgumentException
1142
+	 * @throws InvalidDataTypeException
1143
+	 * @throws InvalidInterfaceException
1144
+	 * @throws ReflectionException
1145
+	 */
1146
+	public function get_primary_registration()
1147
+	{
1148
+		if ($this->is_primary_registrant()) {
1149
+			return $this;
1150
+		}
1151
+
1152
+		// k reg_count !== 1 so let's get the EE_Registration object matching this txn_id and reg_count == 1
1153
+		/** @var EE_Registration $primary_registrant */
1154
+		$primary_registrant = EEM_Registration::instance()->get_one(
1155
+			[
1156
+				[
1157
+					'TXN_ID'    => $this->transaction_ID(),
1158
+					'REG_count' => 1,
1159
+				],
1160
+			]
1161
+		);
1162
+		return $primary_registrant;
1163
+	}
1164
+
1165
+
1166
+	/**
1167
+	 * get  Attendee Number
1168
+	 *
1169
+	 * @throws EE_Error
1170
+	 * @throws InvalidArgumentException
1171
+	 * @throws InvalidDataTypeException
1172
+	 * @throws InvalidInterfaceException
1173
+	 * @throws ReflectionException
1174
+	 */
1175
+	public function count()
1176
+	{
1177
+		return $this->get('REG_count');
1178
+	}
1179
+
1180
+
1181
+	/**
1182
+	 * get Group Size
1183
+	 *
1184
+	 * @throws EE_Error
1185
+	 * @throws InvalidArgumentException
1186
+	 * @throws InvalidDataTypeException
1187
+	 * @throws InvalidInterfaceException
1188
+	 * @throws ReflectionException
1189
+	 */
1190
+	public function group_size()
1191
+	{
1192
+		return $this->get('REG_group_size');
1193
+	}
1194
+
1195
+
1196
+	/**
1197
+	 * get Registration Date
1198
+	 *
1199
+	 * @throws EE_Error
1200
+	 * @throws InvalidArgumentException
1201
+	 * @throws InvalidDataTypeException
1202
+	 * @throws InvalidInterfaceException
1203
+	 * @throws ReflectionException
1204
+	 */
1205
+	public function date()
1206
+	{
1207
+		return $this->get('REG_date');
1208
+	}
1209
+
1210
+
1211
+	/**
1212
+	 * gets a pretty date
1213
+	 *
1214
+	 * @param string $date_format
1215
+	 * @param string $time_format
1216
+	 * @return string
1217
+	 * @throws EE_Error
1218
+	 * @throws InvalidArgumentException
1219
+	 * @throws InvalidDataTypeException
1220
+	 * @throws InvalidInterfaceException
1221
+	 * @throws ReflectionException
1222
+	 */
1223
+	public function pretty_date($date_format = null, $time_format = null)
1224
+	{
1225
+		return $this->get_datetime('REG_date', $date_format, $time_format);
1226
+	}
1227
+
1228
+
1229
+	/**
1230
+	 * final_price
1231
+	 * the registration's share of the transaction total, so that the
1232
+	 * sum of all the transaction's REG_final_prices equal the transaction's total
1233
+	 *
1234
+	 * @return float
1235
+	 * @throws EE_Error
1236
+	 * @throws InvalidArgumentException
1237
+	 * @throws InvalidDataTypeException
1238
+	 * @throws InvalidInterfaceException
1239
+	 * @throws ReflectionException
1240
+	 */
1241
+	public function final_price(): float
1242
+	{
1243
+		return (float) $this->get('REG_final_price');
1244
+	}
1245
+
1246
+
1247
+	/**
1248
+	 * pretty_final_price
1249
+	 *  final price as formatted string, with correct decimal places and currency symbol
1250
+	 *
1251
+	 * @return string
1252
+	 * @throws EE_Error
1253
+	 * @throws InvalidArgumentException
1254
+	 * @throws InvalidDataTypeException
1255
+	 * @throws InvalidInterfaceException
1256
+	 * @throws ReflectionException
1257
+	 */
1258
+	public function pretty_final_price()
1259
+	{
1260
+		return $this->get_pretty('REG_final_price');
1261
+	}
1262
+
1263
+
1264
+	/**
1265
+	 * get paid (yeah)
1266
+	 *
1267
+	 * @return float
1268
+	 * @throws EE_Error
1269
+	 * @throws InvalidArgumentException
1270
+	 * @throws InvalidDataTypeException
1271
+	 * @throws InvalidInterfaceException
1272
+	 * @throws ReflectionException
1273
+	 */
1274
+	public function paid(): float
1275
+	{
1276
+		return (float) $this->get('REG_paid');
1277
+	}
1278
+
1279
+
1280
+	/**
1281
+	 * pretty_paid
1282
+	 *
1283
+	 * @return float
1284
+	 * @throws EE_Error
1285
+	 * @throws InvalidArgumentException
1286
+	 * @throws InvalidDataTypeException
1287
+	 * @throws InvalidInterfaceException
1288
+	 * @throws ReflectionException
1289
+	 */
1290
+	public function pretty_paid()
1291
+	{
1292
+		return $this->get_pretty('REG_paid');
1293
+	}
1294
+
1295
+
1296
+	/**
1297
+	 * owes_monies_and_can_pay
1298
+	 * whether or not this registration has monies owing and it's' status allows payment
1299
+	 *
1300
+	 * @param array $requires_payment list of registration statuses that allow a registrant to make a payment
1301
+	 * @return bool
1302
+	 * @throws EE_Error
1303
+	 * @throws InvalidArgumentException
1304
+	 * @throws InvalidDataTypeException
1305
+	 * @throws InvalidInterfaceException
1306
+	 * @throws ReflectionException
1307
+	 */
1308
+	public function owes_monies_and_can_pay($requires_payment = [])
1309
+	{
1310
+		// these reg statuses require payment (if event is not free)
1311
+		$requires_payment = ! empty($requires_payment)
1312
+			? $requires_payment
1313
+			: EEM_Registration::reg_statuses_that_allow_payment();
1314
+		if (
1315
+			$this->final_price() !== 0 &&
1316
+			$this->final_price() !== $this->paid() &&
1317
+			in_array($this->status_ID(), $requires_payment)
1318
+		) {
1319
+			return true;
1320
+		}
1321
+		return false;
1322
+	}
1323
+
1324
+
1325
+	/**
1326
+	 * Prints out the return value of $this->pretty_status()
1327
+	 *
1328
+	 * @param bool $show_icons
1329
+	 * @return void
1330
+	 * @throws EE_Error
1331
+	 * @throws InvalidArgumentException
1332
+	 * @throws InvalidDataTypeException
1333
+	 * @throws InvalidInterfaceException
1334
+	 * @throws ReflectionException
1335
+	 */
1336
+	public function e_pretty_status($show_icons = false)
1337
+	{
1338
+		echo wp_kses($this->pretty_status($show_icons), AllowedTags::getAllowedTags());
1339
+	}
1340
+
1341
+
1342
+	/**
1343
+	 * Returns a nice version of the status for displaying to customers
1344
+	 *
1345
+	 * @param bool $show_icons
1346
+	 * @return string
1347
+	 * @throws EE_Error
1348
+	 * @throws InvalidArgumentException
1349
+	 * @throws InvalidDataTypeException
1350
+	 * @throws InvalidInterfaceException
1351
+	 * @throws ReflectionException
1352
+	 */
1353
+	public function pretty_status($show_icons = false)
1354
+	{
1355
+		$status = EEM_Status::instance()->localized_status(
1356
+			[$this->status_ID() => esc_html__('unknown', 'event_espresso')],
1357
+			false,
1358
+			'sentence'
1359
+		);
1360
+		$icon   = '';
1361
+		switch ($this->status_ID()) {
1362
+			case EEM_Registration::status_id_approved:
1363
+				$icon = $show_icons
1364
+					? '<span class="dashicons dashicons-star-filled ee-icon-size-16 green-text"></span>'
1365
+					: '';
1366
+				break;
1367
+			case EEM_Registration::status_id_pending_payment:
1368
+				$icon = $show_icons
1369
+					? '<span class="dashicons dashicons-star-half ee-icon-size-16 orange-text"></span>'
1370
+					: '';
1371
+				break;
1372
+			case EEM_Registration::status_id_not_approved:
1373
+				$icon = $show_icons
1374
+					? '<span class="dashicons dashicons-marker ee-icon-size-16 orange-text"></span>'
1375
+					: '';
1376
+				break;
1377
+			case EEM_Registration::status_id_cancelled:
1378
+				$icon = $show_icons
1379
+					? '<span class="dashicons dashicons-no ee-icon-size-16 lt-grey-text"></span>'
1380
+					: '';
1381
+				break;
1382
+			case EEM_Registration::status_id_incomplete:
1383
+				$icon = $show_icons
1384
+					? '<span class="dashicons dashicons-no ee-icon-size-16 lt-orange-text"></span>'
1385
+					: '';
1386
+				break;
1387
+			case EEM_Registration::status_id_declined:
1388
+				$icon = $show_icons
1389
+					? '<span class="dashicons dashicons-no ee-icon-size-16 red-text"></span>'
1390
+					: '';
1391
+				break;
1392
+			case EEM_Registration::status_id_wait_list:
1393
+				$icon = $show_icons
1394
+					? '<span class="dashicons dashicons-clipboard ee-icon-size-16 purple-text"></span>'
1395
+					: '';
1396
+				break;
1397
+		}
1398
+		return $icon . $status[ $this->status_ID() ];
1399
+	}
1400
+
1401
+
1402
+	/**
1403
+	 *        get Attendee Is Going
1404
+	 */
1405
+	public function att_is_going()
1406
+	{
1407
+		return $this->get('REG_att_is_going');
1408
+	}
1409
+
1410
+
1411
+	/**
1412
+	 * Gets related answers
1413
+	 *
1414
+	 * @param array $query_params @see
1415
+	 *                            https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
1416
+	 * @return EE_Answer[]|EE_Base_Class[]
1417
+	 * @throws EE_Error
1418
+	 * @throws InvalidArgumentException
1419
+	 * @throws InvalidDataTypeException
1420
+	 * @throws InvalidInterfaceException
1421
+	 * @throws ReflectionException
1422
+	 */
1423
+	public function answers($query_params = [])
1424
+	{
1425
+		return $this->get_many_related('Answer', $query_params);
1426
+	}
1427
+
1428
+
1429
+	/**
1430
+	 * Gets the registration's answer value to the specified question
1431
+	 * (either the question's ID or a question object)
1432
+	 *
1433
+	 * @param EE_Question|int $question
1434
+	 * @param bool            $pretty_value
1435
+	 * @return array|string if pretty_value= true, the result will always be a string
1436
+	 * (because the answer might be an array of answer values, so passing pretty_value=true
1437
+	 * will convert it into some kind of string)
1438
+	 * @throws EE_Error
1439
+	 * @throws InvalidArgumentException
1440
+	 * @throws InvalidDataTypeException
1441
+	 * @throws InvalidInterfaceException
1442
+	 */
1443
+	public function answer_value_to_question($question, $pretty_value = true)
1444
+	{
1445
+		$question_id = EEM_Question::instance()->ensure_is_ID($question);
1446
+		return EEM_Answer::instance()->get_answer_value_to_question($this, $question_id, $pretty_value);
1447
+	}
1448
+
1449
+
1450
+	/**
1451
+	 * question_groups
1452
+	 * returns an array of EE_Question_Group objects for this registration
1453
+	 *
1454
+	 * @return EE_Question_Group[]
1455
+	 * @throws EE_Error
1456
+	 * @throws InvalidArgumentException
1457
+	 * @throws InvalidDataTypeException
1458
+	 * @throws InvalidInterfaceException
1459
+	 * @throws ReflectionException
1460
+	 */
1461
+	public function question_groups()
1462
+	{
1463
+		return EEM_Event::instance()->get_question_groups_for_event($this->event_ID(), $this);
1464
+	}
1465
+
1466
+
1467
+	/**
1468
+	 * count_question_groups
1469
+	 * returns a count of the number of EE_Question_Group objects for this registration
1470
+	 *
1471
+	 * @return int
1472
+	 * @throws EE_Error
1473
+	 * @throws EntityNotFoundException
1474
+	 * @throws InvalidArgumentException
1475
+	 * @throws InvalidDataTypeException
1476
+	 * @throws InvalidInterfaceException
1477
+	 * @throws ReflectionException
1478
+	 */
1479
+	public function count_question_groups()
1480
+	{
1481
+		return EEM_Event::instance()->count_related(
1482
+			$this->event_ID(),
1483
+			'Question_Group',
1484
+			[
1485
+				[
1486
+					'Event_Question_Group.'
1487
+					. EEM_Event_Question_Group::instance()->fieldNameForContext($this->is_primary_registrant()) => true,
1488
+				],
1489
+			]
1490
+		);
1491
+	}
1492
+
1493
+
1494
+	/**
1495
+	 * Returns the registration date in the 'standard' string format
1496
+	 * (function may be improved in the future to allow for different formats and timezones)
1497
+	 *
1498
+	 * @return string
1499
+	 * @throws EE_Error
1500
+	 * @throws InvalidArgumentException
1501
+	 * @throws InvalidDataTypeException
1502
+	 * @throws InvalidInterfaceException
1503
+	 * @throws ReflectionException
1504
+	 */
1505
+	public function reg_date()
1506
+	{
1507
+		return $this->get_datetime('REG_date');
1508
+	}
1509
+
1510
+
1511
+	/**
1512
+	 * Gets the datetime-ticket for this registration (ie, it can be used to isolate
1513
+	 * the ticket this registration purchased, or the datetime they have registered
1514
+	 * to attend)
1515
+	 *
1516
+	 * @return EE_Base_Class|EE_Datetime_Ticket
1517
+	 * @throws EE_Error
1518
+	 * @throws InvalidArgumentException
1519
+	 * @throws InvalidDataTypeException
1520
+	 * @throws InvalidInterfaceException
1521
+	 * @throws ReflectionException
1522
+	 */
1523
+	public function datetime_ticket()
1524
+	{
1525
+		return $this->get_first_related('Datetime_Ticket');
1526
+	}
1527
+
1528
+
1529
+	/**
1530
+	 * Sets the registration's datetime_ticket.
1531
+	 *
1532
+	 * @param EE_Datetime_Ticket $datetime_ticket
1533
+	 * @return EE_Base_Class|EE_Datetime_Ticket
1534
+	 * @throws EE_Error
1535
+	 * @throws InvalidArgumentException
1536
+	 * @throws InvalidDataTypeException
1537
+	 * @throws InvalidInterfaceException
1538
+	 * @throws ReflectionException
1539
+	 */
1540
+	public function set_datetime_ticket($datetime_ticket)
1541
+	{
1542
+		return $this->_add_relation_to($datetime_ticket, 'Datetime_Ticket');
1543
+	}
1544
+
1545
+
1546
+	/**
1547
+	 * Gets deleted
1548
+	 *
1549
+	 * @return bool
1550
+	 * @throws EE_Error
1551
+	 * @throws InvalidArgumentException
1552
+	 * @throws InvalidDataTypeException
1553
+	 * @throws InvalidInterfaceException
1554
+	 * @throws ReflectionException
1555
+	 */
1556
+	public function deleted()
1557
+	{
1558
+		return $this->get('REG_deleted');
1559
+	}
1560
+
1561
+
1562
+	/**
1563
+	 * Sets deleted
1564
+	 *
1565
+	 * @param boolean $deleted
1566
+	 * @return void
1567
+	 * @throws DomainException
1568
+	 * @throws EE_Error
1569
+	 * @throws EntityNotFoundException
1570
+	 * @throws InvalidArgumentException
1571
+	 * @throws InvalidDataTypeException
1572
+	 * @throws InvalidInterfaceException
1573
+	 * @throws ReflectionException
1574
+	 * @throws RuntimeException
1575
+	 * @throws UnexpectedEntityException
1576
+	 */
1577
+	public function set_deleted($deleted)
1578
+	{
1579
+		if ($deleted) {
1580
+			$this->delete();
1581
+		} else {
1582
+			$this->restore();
1583
+		}
1584
+	}
1585
+
1586
+
1587
+	/**
1588
+	 * Get the status object of this object
1589
+	 *
1590
+	 * @return EE_Base_Class|EE_Status
1591
+	 * @throws EE_Error
1592
+	 * @throws InvalidArgumentException
1593
+	 * @throws InvalidDataTypeException
1594
+	 * @throws InvalidInterfaceException
1595
+	 * @throws ReflectionException
1596
+	 */
1597
+	public function status_obj()
1598
+	{
1599
+		return $this->get_first_related('Status');
1600
+	}
1601
+
1602
+
1603
+	/**
1604
+	 * Returns the number of times this registration has checked into any of the datetimes
1605
+	 * its available for
1606
+	 *
1607
+	 * @return int
1608
+	 * @throws EE_Error
1609
+	 * @throws InvalidArgumentException
1610
+	 * @throws InvalidDataTypeException
1611
+	 * @throws InvalidInterfaceException
1612
+	 * @throws ReflectionException
1613
+	 */
1614
+	public function count_checkins()
1615
+	{
1616
+		return $this->get_model()->count_related($this, 'Checkin');
1617
+	}
1618
+
1619
+
1620
+	/**
1621
+	 * Returns the number of current Check-ins this registration is checked into for any of the datetimes the
1622
+	 * registration is for.  Note, this is ONLY checked in (does not include checkedout)
1623
+	 *
1624
+	 * @return int
1625
+	 * @throws EE_Error
1626
+	 * @throws InvalidArgumentException
1627
+	 * @throws InvalidDataTypeException
1628
+	 * @throws InvalidInterfaceException
1629
+	 * @throws ReflectionException
1630
+	 */
1631
+	public function count_checkins_not_checkedout()
1632
+	{
1633
+		return $this->get_model()->count_related($this, 'Checkin', [['CHK_in' => 1]]);
1634
+	}
1635
+
1636
+
1637
+	/**
1638
+	 * The purpose of this method is simply to check whether this registration can checkin to the given datetime.
1639
+	 *
1640
+	 * @param int | EE_Datetime $DTT_OR_ID      The datetime the registration is being checked against
1641
+	 * @param bool              $check_approved This is used to indicate whether the caller wants can_checkin to also
1642
+	 *                                          consider registration status as well as datetime access.
1643
+	 * @return bool
1644
+	 * @throws EE_Error
1645
+	 * @throws InvalidArgumentException
1646
+	 * @throws InvalidDataTypeException
1647
+	 * @throws InvalidInterfaceException
1648
+	 * @throws ReflectionException
1649
+	 */
1650
+	public function can_checkin($DTT_OR_ID, $check_approved = true)
1651
+	{
1652
+		$DTT_ID = EEM_Datetime::instance()->ensure_is_ID($DTT_OR_ID);
1653
+		// first check registration status
1654
+		if (! $DTT_ID || ($check_approved && ! $this->is_approved())) {
1655
+			return false;
1656
+		}
1657
+		// is there a datetime ticket that matches this dtt_ID?
1658
+		if (
1659
+			! (EEM_Datetime_Ticket::instance()->exists(
1660
+				[
1661
+					[
1662
+						'TKT_ID' => $this->get('TKT_ID'),
1663
+						'DTT_ID' => $DTT_ID,
1664
+					],
1665
+				]
1666
+			))
1667
+		) {
1668
+			return false;
1669
+		}
1670
+
1671
+		// final check is against TKT_uses
1672
+		return $this->verify_can_checkin_against_TKT_uses($DTT_ID);
1673
+	}
1674
+
1675
+
1676
+	/**
1677
+	 * This method verifies whether the user can checkin for the given datetime considering the max uses value set on
1678
+	 * the ticket. To do this,  a query is done to get the count of the datetime records already checked into.  If the
1679
+	 * datetime given does not have a check-in record and checking in for that datetime will exceed the allowed uses,
1680
+	 * then return false.  Otherwise return true.
1681
+	 *
1682
+	 * @param int | EE_Datetime $DTT_OR_ID The datetime the registration is being checked against
1683
+	 * @return bool true means can checkin.  false means cannot checkin.
1684
+	 * @throws EE_Error
1685
+	 * @throws InvalidArgumentException
1686
+	 * @throws InvalidDataTypeException
1687
+	 * @throws InvalidInterfaceException
1688
+	 * @throws ReflectionException
1689
+	 */
1690
+	public function verify_can_checkin_against_TKT_uses($DTT_OR_ID)
1691
+	{
1692
+		$DTT_ID = EEM_Datetime::instance()->ensure_is_ID($DTT_OR_ID);
1693
+
1694
+		if (! $DTT_ID) {
1695
+			return false;
1696
+		}
1697
+
1698
+		$max_uses = $this->ticket() instanceof EE_Ticket
1699
+			? $this->ticket()->uses()
1700
+			: EE_INF;
1701
+
1702
+		// if max uses is not set or equals infinity then return true cause its not a factor for whether user can
1703
+		// check-in or not.
1704
+		if (! $max_uses || $max_uses === EE_INF) {
1705
+			return true;
1706
+		}
1707
+
1708
+		// does this datetime have a checkin record?  If so, then the dtt count has already been verified so we can just
1709
+		// go ahead and toggle.
1710
+		if (EEM_Checkin::instance()->exists([['REG_ID' => $this->ID(), 'DTT_ID' => $DTT_ID]])) {
1711
+			return true;
1712
+		}
1713
+
1714
+		// made it here so the last check is whether the number of checkins per unique datetime on this registration
1715
+		// disallows further check-ins.
1716
+		$count_unique_dtt_checkins = EEM_Checkin::instance()->count(
1717
+			[
1718
+				[
1719
+					'REG_ID' => $this->ID(),
1720
+					'CHK_in' => true,
1721
+				],
1722
+			],
1723
+			'DTT_ID',
1724
+			true
1725
+		);
1726
+		// checkins have already reached their max number of uses
1727
+		// so registrant can NOT checkin
1728
+		if ($count_unique_dtt_checkins >= $max_uses) {
1729
+			EE_Error::add_error(
1730
+				esc_html__(
1731
+					'Check-in denied because number of datetime uses for the ticket has been reached or exceeded.',
1732
+					'event_espresso'
1733
+				),
1734
+				__FILE__,
1735
+				__FUNCTION__,
1736
+				__LINE__
1737
+			);
1738
+			return false;
1739
+		}
1740
+		return true;
1741
+	}
1742
+
1743
+
1744
+	/**
1745
+	 * toggle Check-in status for this registration
1746
+	 * Check-ins are toggled in the following order:
1747
+	 * never checked in -> checked in
1748
+	 * checked in -> checked out
1749
+	 * checked out -> checked in
1750
+	 *
1751
+	 * @param int  $DTT_ID  include specific datetime to toggle Check-in for.
1752
+	 *                      If not included or null, then it is assumed latest datetime is being toggled.
1753
+	 * @param bool $verify  If true then can_checkin() is used to verify whether the person
1754
+	 *                      can be checked in or not.  Otherwise this forces change in checkin status.
1755
+	 * @return bool|int     the chk_in status toggled to OR false if nothing got changed.
1756
+	 * @throws EE_Error
1757
+	 * @throws InvalidArgumentException
1758
+	 * @throws InvalidDataTypeException
1759
+	 * @throws InvalidInterfaceException
1760
+	 * @throws ReflectionException
1761
+	 */
1762
+	public function toggle_checkin_status($DTT_ID = null, $verify = false)
1763
+	{
1764
+		if (empty($DTT_ID)) {
1765
+			$datetime = $this->get_latest_related_datetime();
1766
+			$DTT_ID   = $datetime instanceof EE_Datetime ? $datetime->ID() : 0;
1767
+			// verify the registration can checkin for the given DTT_ID
1768
+		} elseif (! $this->can_checkin($DTT_ID, $verify)) {
1769
+			EE_Error::add_error(
1770
+				sprintf(
1771
+					esc_html__(
1772
+						'The given registration (ID:%1$d) can not be checked in to the given DTT_ID (%2$d), because the registration does not have access',
1773
+						'event_espresso'
1774
+					),
1775
+					$this->ID(),
1776
+					$DTT_ID
1777
+				),
1778
+				__FILE__,
1779
+				__FUNCTION__,
1780
+				__LINE__
1781
+			);
1782
+			return false;
1783
+		}
1784
+		$status_paths = [
1785
+			EE_Checkin::status_checked_never => EE_Checkin::status_checked_in,
1786
+			EE_Checkin::status_checked_in    => EE_Checkin::status_checked_out,
1787
+			EE_Checkin::status_checked_out   => EE_Checkin::status_checked_in,
1788
+		];
1789
+		// start by getting the current status so we know what status we'll be changing to.
1790
+		$cur_status = $this->check_in_status_for_datetime($DTT_ID);
1791
+		$status_to  = $status_paths[ $cur_status ];
1792
+		// database only records true for checked IN or false for checked OUT
1793
+		// no record ( null ) means checked in NEVER, but we obviously don't save that
1794
+		$new_status = $status_to === EE_Checkin::status_checked_in;
1795
+		// add relation - note Check-ins are always creating new rows
1796
+		// because we are keeping track of Check-ins over time.
1797
+		// Eventually we'll probably want to show a list table
1798
+		// for the individual Check-ins so that they can be managed.
1799
+		$checkin = EE_Checkin::new_instance(
1800
+			[
1801
+				'REG_ID' => $this->ID(),
1802
+				'DTT_ID' => $DTT_ID,
1803
+				'CHK_in' => $new_status,
1804
+			]
1805
+		);
1806
+		// if the record could not be saved then return false
1807
+		if ($checkin->save() === 0) {
1808
+			if (WP_DEBUG) {
1809
+				global $wpdb;
1810
+				$error = sprintf(
1811
+					esc_html__(
1812
+						'Registration check in update failed because of the following database error: %1$s%2$s',
1813
+						'event_espresso'
1814
+					),
1815
+					'<br />',
1816
+					$wpdb->last_error
1817
+				);
1818
+			} else {
1819
+				$error = esc_html__(
1820
+					'Registration check in update failed because of an unknown database error',
1821
+					'event_espresso'
1822
+				);
1823
+			}
1824
+			EE_Error::add_error($error, __FILE__, __FUNCTION__, __LINE__);
1825
+			return false;
1826
+		}
1827
+		// Fire a checked_in and checkout_out action.
1828
+		$checked_status = $status_to === EE_Checkin::status_checked_in
1829
+			? 'checked_in'
1830
+			: 'checked_out';
1831
+		do_action("AHEE__EE_Registration__toggle_checkin_status__{$checked_status}", $this, $DTT_ID);
1832
+		return $status_to;
1833
+	}
1834
+
1835
+
1836
+	/**
1837
+	 * Returns the latest datetime related to this registration (via the ticket attached to the registration).
1838
+	 * "Latest" is defined by the `DTT_EVT_start` column.
1839
+	 *
1840
+	 * @return EE_Datetime|null
1841
+	 * @throws EE_Error
1842
+	 * @throws InvalidArgumentException
1843
+	 * @throws InvalidDataTypeException
1844
+	 * @throws InvalidInterfaceException
1845
+	 * @throws ReflectionException
1846
+	 */
1847
+	public function get_latest_related_datetime(): ?EE_Datetime
1848
+	{
1849
+		return EEM_Datetime::instance()->get_one(
1850
+			[
1851
+				[
1852
+					'Ticket.Registration.REG_ID' => $this->ID(),
1853
+				],
1854
+				'order_by' => ['DTT_EVT_start' => 'DESC'],
1855
+			]
1856
+		);
1857
+	}
1858
+
1859
+
1860
+	/**
1861
+	 * Returns the earliest datetime related to this registration (via the ticket attached to the registration).
1862
+	 * "Earliest" is defined by the `DTT_EVT_start` column.
1863
+	 *
1864
+	 * @return EE_Base_Class|EE_Soft_Delete_Base_Class|NULL
1865
+	 * @throws EE_Error
1866
+	 * @throws InvalidArgumentException
1867
+	 * @throws InvalidDataTypeException
1868
+	 * @throws InvalidInterfaceException
1869
+	 * @throws ReflectionException
1870
+	 */
1871
+	public function get_earliest_related_datetime()
1872
+	{
1873
+		return EEM_Datetime::instance()->get_one(
1874
+			[
1875
+				[
1876
+			[
1877
+				[
1878
+					'Ticket.Registration.REG_ID' => $this->ID(),
1879
+				],
1880
+				'order_by' => ['DTT_EVT_start' => 'ASC'],
1881
+			]
1882
+				],
1883
+				'order_by' => ['DTT_EVT_start' => 'ASC'],
1884
+			]
1885
+		);
1886
+	}
1887
+
1888
+
1889
+	/**
1890
+	 * This method simply returns the check-in status for this registration and the given datetime.
1891
+	 * If neither the datetime nor the checkin values are provided as arguments,
1892
+	 * then this will return the LATEST check-in status for the registration across all datetimes it belongs to.
1893
+	 *
1894
+	 * @param int|null        $DTT_ID  The ID of the datetime we're checking against
1895
+	 *                                 (if empty we'll get the primary datetime for
1896
+	 *                                 this registration (via event) and use it's ID);
1897
+	 * @param EE_Checkin|null $checkin If present, we use the given checkin object rather than the dtt_id.
1898
+	 * @return int                     Integer representing Check-in status.
1899
+	 * @throws EE_Error
1900
+	 * @throws ReflectionException
1901
+	 */
1902
+	public function check_in_status_for_datetime(?int $DTT_ID = 0, ?EE_Checkin $checkin = null): int
1903
+	{
1904
+		if ($checkin instanceof EE_Checkin) {
1905
+			return $checkin->status();
1906
+		}
1907
+
1908
+		if (! $DTT_ID) {
1909
+			return EE_Checkin::status_invalid;
1910
+		}
1911
+
1912
+		$checkin_query_params = [
1913
+			0          => ['DTT_ID' => $DTT_ID],
1914
+			'order_by' => ['CHK_timestamp' => 'DESC'],
1915
+		];
1916
+
1917
+		$checkin = $this->get_first_related(
1918
+			'Checkin',
1919
+			$checkin_query_params
1920
+		);
1921
+		return $checkin instanceof EE_Checkin ? $checkin->status() : EE_Checkin::status_checked_never;
1922
+	}
1923
+
1924
+
1925
+	/**
1926
+	 * This method returns a localized message for the toggled Check-in message.
1927
+	 *
1928
+	 * @param int|null $DTT_ID include specific datetime to get the correct Check-in message.  If not included or null,
1929
+	 *                         then it is assumed Check-in for primary datetime was toggled.
1930
+	 * @param bool     $error  This just flags that you want an error message returned. This is put in so that the error
1931
+	 *                         message can be customized with the attendee name.
1932
+	 * @return string internationalized message
1933
+	 * @throws EE_Error
1934
+	 * @throws ReflectionException
1935
+	 */
1936
+	public function get_checkin_msg(?int $DTT_ID, bool $error = false): string
1937
+	{
1938
+		// let's get the attendee first so we can include the name of the attendee
1939
+		$attendee = $this->get_first_related('Attendee');
1940
+		if ($attendee instanceof EE_Attendee) {
1941
+			if ($error) {
1942
+				return sprintf(
1943
+					esc_html__("%s's check-in status was not changed.", "event_espresso"),
1944
+					$attendee->full_name()
1945
+				);
1946
+			}
1947
+			$cur_status = $this->check_in_status_for_datetime($DTT_ID);
1948
+			// what is the status message going to be?
1949
+			switch ($cur_status) {
1950
+				case EE_Checkin::status_checked_never:
1951
+					return sprintf(
1952
+						esc_html__('%s has been removed from Check-in records', 'event_espresso'),
1953
+						$attendee->full_name()
1954
+					);
1955
+				case EE_Checkin::status_checked_in:
1956
+					return sprintf(esc_html__('%s has been checked in', 'event_espresso'), $attendee->full_name());
1957
+				case EE_Checkin::status_checked_out:
1958
+					return sprintf(esc_html__('%s has been checked out', 'event_espresso'), $attendee->full_name());
1959
+			}
1960
+		}
1961
+		return esc_html__('The check-in status could not be determined.', 'event_espresso');
1962
+	}
1963
+
1964
+
1965
+	/**
1966
+	 * Returns the related EE_Transaction to this registration
1967
+	 *
1968
+	 * @return EE_Transaction
1969
+	 * @throws EE_Error
1970
+	 * @throws EntityNotFoundException
1971
+	 * @throws ReflectionException
1972
+	 */
1973
+	public function transaction(): EE_Transaction
1974
+	{
1975
+		$transaction = $this->get_first_related('Transaction');
1976
+		if (! $transaction instanceof \EE_Transaction) {
1977
+			throw new EntityNotFoundException('Transaction ID', $this->transaction_ID());
1978
+		}
1979
+		return $transaction;
1980
+	}
1981
+
1982
+
1983
+	/**
1984
+	 * get Registration Code
1985
+	 *
1986
+	 * @return string
1987
+	 * @throws EE_Error
1988
+	 * @throws InvalidArgumentException
1989
+	 * @throws InvalidDataTypeException
1990
+	 * @throws InvalidInterfaceException
1991
+	 * @throws ReflectionException
1992
+	 */
1993
+	public function reg_code(): string
1994
+	{
1995
+		return $this->get('REG_code')
1996
+			?: '';
1997
+	}
1998
+
1999
+
2000
+	/**
2001
+	 * @return mixed
2002
+	 * @throws EE_Error
2003
+	 * @throws InvalidArgumentException
2004
+	 * @throws InvalidDataTypeException
2005
+	 * @throws InvalidInterfaceException
2006
+	 * @throws ReflectionException
2007
+	 */
2008
+	public function transaction_ID()
2009
+	{
2010
+		return $this->get('TXN_ID');
2011
+	}
2012
+
2013
+
2014
+	/**
2015
+	 * @return int
2016
+	 * @throws EE_Error
2017
+	 * @throws InvalidArgumentException
2018
+	 * @throws InvalidDataTypeException
2019
+	 * @throws InvalidInterfaceException
2020
+	 * @throws ReflectionException
2021
+	 */
2022
+	public function ticket_ID()
2023
+	{
2024
+		return $this->get('TKT_ID');
2025
+	}
2026
+
2027
+
2028
+	/**
2029
+	 * Set Registration Code
2030
+	 *
2031
+	 * @param RegCode|string $REG_code Registration Code
2032
+	 * @param boolean        $use_default
2033
+	 * @throws EE_Error
2034
+	 * @throws InvalidArgumentException
2035
+	 * @throws InvalidDataTypeException
2036
+	 * @throws InvalidInterfaceException
2037
+	 * @throws ReflectionException
2038
+	 */
2039
+	public function set_reg_code($REG_code, bool $use_default = false)
2040
+	{
2041
+		if (empty($REG_code)) {
2042
+			EE_Error::add_error(
2043
+				esc_html__('REG_code can not be empty.', 'event_espresso'),
2044
+				__FILE__,
2045
+				__FUNCTION__,
2046
+				__LINE__
2047
+			);
2048
+			return;
2049
+		}
2050
+		if (! $this->reg_code()) {
2051
+			parent::set('REG_code', $REG_code, $use_default);
2052
+		} else {
2053
+			EE_Error::doing_it_wrong(
2054
+				__CLASS__ . '::' . __FUNCTION__,
2055
+				esc_html__('Can not change a registration REG_code once it has been set.', 'event_espresso'),
2056
+				'4.6.0'
2057
+			);
2058
+		}
2059
+	}
2060
+
2061
+
2062
+	/**
2063
+	 * Returns all other registrations in the same group as this registrant who have the same ticket option.
2064
+	 * Note, if you want to just get all registrations in the same transaction (group), use:
2065
+	 *    $registration->transaction()->registrations();
2066
+	 *
2067
+	 * @return EE_Registration[] or empty array if this isn't a group registration.
2068
+	 * @throws EE_Error
2069
+	 * @throws InvalidArgumentException
2070
+	 * @throws InvalidDataTypeException
2071
+	 * @throws InvalidInterfaceException
2072
+	 * @throws ReflectionException
2073
+	 * @since 4.5.0
2074
+	 */
2075
+	public function get_all_other_registrations_in_group()
2076
+	{
2077
+		if ($this->group_size() < 2) {
2078
+			return [];
2079
+		}
2080
+
2081
+		$query[0] = [
2082
+			'TXN_ID' => $this->transaction_ID(),
2083
+			'REG_ID' => ['!=', $this->ID()],
2084
+			'TKT_ID' => $this->ticket_ID(),
2085
+		];
2086
+		/** @var EE_Registration[] $registrations */
2087
+		$registrations = $this->get_model()->get_all($query);
2088
+		return $registrations;
2089
+	}
2090
+
2091
+
2092
+	/**
2093
+	 * Return the link to the admin details for the object.
2094
+	 *
2095
+	 * @return string
2096
+	 * @throws EE_Error
2097
+	 * @throws InvalidArgumentException
2098
+	 * @throws InvalidDataTypeException
2099
+	 * @throws InvalidInterfaceException
2100
+	 * @throws ReflectionException
2101
+	 */
2102
+	public function get_admin_details_link()
2103
+	{
2104
+		EE_Registry::instance()->load_helper('URL');
2105
+		return EEH_URL::add_query_args_and_nonce(
2106
+			[
2107
+				'page'    => 'espresso_registrations',
2108
+				'action'  => 'view_registration',
2109
+				'_REG_ID' => $this->ID(),
2110
+			],
2111
+			admin_url('admin.php')
2112
+		);
2113
+	}
2114
+
2115
+
2116
+	/**
2117
+	 * Returns the link to the editor for the object.  Sometimes this is the same as the details.
2118
+	 *
2119
+	 * @return string
2120
+	 * @throws EE_Error
2121
+	 * @throws InvalidArgumentException
2122
+	 * @throws InvalidDataTypeException
2123
+	 * @throws InvalidInterfaceException
2124
+	 * @throws ReflectionException
2125
+	 */
2126
+	public function get_admin_edit_link()
2127
+	{
2128
+		return $this->get_admin_details_link();
2129
+	}
2130
+
2131
+
2132
+	/**
2133
+	 * Returns the link to a settings page for the object.
2134
+	 *
2135
+	 * @return string
2136
+	 * @throws EE_Error
2137
+	 * @throws InvalidArgumentException
2138
+	 * @throws InvalidDataTypeException
2139
+	 * @throws InvalidInterfaceException
2140
+	 * @throws ReflectionException
2141
+	 */
2142
+	public function get_admin_settings_link()
2143
+	{
2144
+		return $this->get_admin_details_link();
2145
+	}
2146
+
2147
+
2148
+	/**
2149
+	 * Returns the link to the "overview" for the object (typically the "list table" view).
2150
+	 *
2151
+	 * @return string
2152
+	 * @throws EE_Error
2153
+	 * @throws InvalidArgumentException
2154
+	 * @throws InvalidDataTypeException
2155
+	 * @throws InvalidInterfaceException
2156
+	 * @throws ReflectionException
2157
+	 */
2158
+	public function get_admin_overview_link()
2159
+	{
2160
+		EE_Registry::instance()->load_helper('URL');
2161
+		return EEH_URL::add_query_args_and_nonce(
2162
+			[
2163
+				'page' => 'espresso_registrations',
2164
+			],
2165
+			admin_url('admin.php')
2166
+		);
2167
+	}
2168
+
2169
+
2170
+	/**
2171
+	 * @param array $query_params
2172
+	 * @return EE_Base_Class[]|EE_Registration[]
2173
+	 * @throws EE_Error
2174
+	 * @throws InvalidArgumentException
2175
+	 * @throws InvalidDataTypeException
2176
+	 * @throws InvalidInterfaceException
2177
+	 * @throws ReflectionException
2178
+	 */
2179
+	public function payments($query_params = [])
2180
+	{
2181
+		return $this->get_many_related('Payment', $query_params);
2182
+	}
2183
+
2184
+
2185
+	/**
2186
+	 * @param array $query_params
2187
+	 * @return EE_Base_Class[]|EE_Registration_Payment[]
2188
+	 * @throws EE_Error
2189
+	 * @throws InvalidArgumentException
2190
+	 * @throws InvalidDataTypeException
2191
+	 * @throws InvalidInterfaceException
2192
+	 * @throws ReflectionException
2193
+	 */
2194
+	public function registration_payments($query_params = [])
2195
+	{
2196
+		return $this->get_many_related('Registration_Payment', $query_params);
2197
+	}
2198
+
2199
+
2200
+	/**
2201
+	 * This grabs the payment method corresponding to the last payment made for the amount owing on the registration.
2202
+	 * Note: if there are no payments on the registration there will be no payment method returned.
2203
+	 *
2204
+	 * @return EE_Payment|EE_Payment_Method|null
2205
+	 * @throws EE_Error
2206
+	 * @throws InvalidArgumentException
2207
+	 * @throws InvalidDataTypeException
2208
+	 * @throws InvalidInterfaceException
2209
+	 */
2210
+	public function payment_method()
2211
+	{
2212
+		return EEM_Payment_Method::instance()->get_last_used_for_registration($this);
2213
+	}
2214
+
2215
+
2216
+	/**
2217
+	 * @return \EE_Line_Item
2218
+	 * @throws EE_Error
2219
+	 * @throws EntityNotFoundException
2220
+	 * @throws InvalidArgumentException
2221
+	 * @throws InvalidDataTypeException
2222
+	 * @throws InvalidInterfaceException
2223
+	 * @throws ReflectionException
2224
+	 */
2225
+	public function ticket_line_item()
2226
+	{
2227
+		$ticket            = $this->ticket();
2228
+		$transaction       = $this->transaction();
2229
+		$line_item         = null;
2230
+		$ticket_line_items = \EEH_Line_Item::get_line_items_by_object_type_and_IDs(
2231
+			$transaction->total_line_item(),
2232
+			'Ticket',
2233
+			[$ticket->ID()]
2234
+		);
2235
+		foreach ($ticket_line_items as $ticket_line_item) {
2236
+			if (
2237
+				$ticket_line_item instanceof \EE_Line_Item
2238
+				&& $ticket_line_item->OBJ_type() === 'Ticket'
2239
+				&& $ticket_line_item->OBJ_ID() === $ticket->ID()
2240
+			) {
2241
+				$line_item = $ticket_line_item;
2242
+				break;
2243
+			}
2244
+		}
2245
+		if (! ($line_item instanceof \EE_Line_Item && $line_item->OBJ_type() === 'Ticket')) {
2246
+			throw new EntityNotFoundException('Line Item Ticket ID', $ticket->ID());
2247
+		}
2248
+		return $line_item;
2249
+	}
2250
+
2251
+
2252
+	/**
2253
+	 * Soft Deletes this model object.
2254
+	 *
2255
+	 * @param string $source function name that called this method
2256
+	 * @return boolean | int
2257
+	 * @throws DomainException
2258
+	 * @throws EE_Error
2259
+	 * @throws EntityNotFoundException
2260
+	 * @throws InvalidArgumentException
2261
+	 * @throws InvalidDataTypeException
2262
+	 * @throws InvalidInterfaceException
2263
+	 * @throws ReflectionException
2264
+	 * @throws RuntimeException
2265
+	 * @throws UnexpectedEntityException
2266
+	 */
2267
+	public function delete()
2268
+	{
2269
+		if ($this->update_extra_meta(EE_Registration::PRE_TRASH_REG_STATUS_KEY, $this->status_ID()) === true) {
2270
+			$this->set_status(EEM_Registration::status_id_cancelled);
2271
+		}
2272
+		return parent::delete();
2273
+	}
2274
+
2275
+
2276
+	/**
2277
+	 * Restores whatever the previous status was on a registration before it was trashed (if possible)
2278
+	 *
2279
+	 * @param string $source function name that called this method
2280
+	 * @return bool|int
2281
+	 * @throws DomainException
2282
+	 * @throws EE_Error
2283
+	 * @throws EntityNotFoundException
2284
+	 * @throws InvalidArgumentException
2285
+	 * @throws InvalidDataTypeException
2286
+	 * @throws InvalidInterfaceException
2287
+	 * @throws ReflectionException
2288
+	 * @throws RuntimeException
2289
+	 * @throws UnexpectedEntityException
2290
+	 */
2291
+	public function restore()
2292
+	{
2293
+		$previous_status = $this->get_extra_meta(
2294
+			EE_Registration::PRE_TRASH_REG_STATUS_KEY,
2295
+			true,
2296
+			EEM_Registration::status_id_cancelled
2297
+		);
2298
+		if ($previous_status) {
2299
+			$this->delete_extra_meta(EE_Registration::PRE_TRASH_REG_STATUS_KEY);
2300
+			$this->set_status($previous_status);
2301
+		}
2302
+		return parent::restore();
2303
+	}
2304
+
2305
+
2306
+	/**
2307
+	 * possibly toggle Registration status based on comparison of REG_paid vs REG_final_price
2308
+	 *
2309
+	 * @param boolean $trigger_set_status_logic  EE_Registration::set_status() can trigger additional logic
2310
+	 *                                           depending on whether the reg status changes to or from "Approved"
2311
+	 * @return boolean whether the Registration status was updated
2312
+	 * @throws DomainException
2313
+	 * @throws EE_Error
2314
+	 * @throws EntityNotFoundException
2315
+	 * @throws InvalidArgumentException
2316
+	 * @throws InvalidDataTypeException
2317
+	 * @throws InvalidInterfaceException
2318
+	 * @throws ReflectionException
2319
+	 * @throws RuntimeException
2320
+	 * @throws UnexpectedEntityException
2321
+	 */
2322
+	public function updateStatusBasedOnTotalPaid($trigger_set_status_logic = true)
2323
+	{
2324
+		$paid  = $this->paid();
2325
+		$price = $this->final_price();
2326
+		switch (true) {
2327
+			// overpaid or paid
2328
+			case EEH_Money::compare_floats($paid, $price, '>'):
2329
+			case EEH_Money::compare_floats($paid, $price):
2330
+				$new_status = EEM_Registration::status_id_approved;
2331
+				break;
2332
+			//  underpaid
2333
+			case EEH_Money::compare_floats($paid, $price, '<'):
2334
+				$new_status = EEM_Registration::status_id_pending_payment;
2335
+				break;
2336
+			// uhhh Houston...
2337
+			default:
2338
+				throw new RuntimeException(
2339
+					esc_html__('The total paid calculation for this registration is inaccurate.', 'event_espresso')
2340
+				);
2341
+		}
2342
+		if ($new_status !== $this->status_ID()) {
2343
+			if ($trigger_set_status_logic) {
2344
+				return $this->set_status($new_status);
2345
+			}
2346
+			parent::set('STS_ID', $new_status);
2347
+			return true;
2348
+		}
2349
+		return false;
2350
+	}
2351
+
2352
+
2353
+	/*************************** DEPRECATED ***************************/
2354
+
2355
+
2356
+	/**
2357
+	 * @deprecated
2358
+	 * @since     4.7.0
2359
+	 */
2360
+	public function price_paid()
2361
+	{
2362
+		EE_Error::doing_it_wrong(
2363
+			'EE_Registration::price_paid()',
2364
+			esc_html__(
2365
+				'This method is deprecated, please use EE_Registration::final_price() instead.',
2366
+				'event_espresso'
2367
+			),
2368
+			'4.7.0'
2369
+		);
2370
+		return $this->final_price();
2371
+	}
2372
+
2373
+
2374
+	/**
2375
+	 * @param float $REG_final_price
2376
+	 * @throws EE_Error
2377
+	 * @throws EntityNotFoundException
2378
+	 * @throws InvalidArgumentException
2379
+	 * @throws InvalidDataTypeException
2380
+	 * @throws InvalidInterfaceException
2381
+	 * @throws ReflectionException
2382
+	 * @throws RuntimeException
2383
+	 * @throws DomainException
2384
+	 * @deprecated
2385
+	 * @since     4.7.0
2386
+	 */
2387
+	public function set_price_paid($REG_final_price = 0.00)
2388
+	{
2389
+		EE_Error::doing_it_wrong(
2390
+			'EE_Registration::set_price_paid()',
2391
+			esc_html__(
2392
+				'This method is deprecated, please use EE_Registration::set_final_price() instead.',
2393
+				'event_espresso'
2394
+			),
2395
+			'4.7.0'
2396
+		);
2397
+		$this->set_final_price($REG_final_price);
2398
+	}
2399
+
2400
+
2401
+	/**
2402
+	 * @return string
2403
+	 * @throws EE_Error
2404
+	 * @throws InvalidArgumentException
2405
+	 * @throws InvalidDataTypeException
2406
+	 * @throws InvalidInterfaceException
2407
+	 * @throws ReflectionException
2408
+	 * @deprecated
2409
+	 * @since 4.7.0
2410
+	 */
2411
+	public function pretty_price_paid()
2412
+	{
2413
+		EE_Error::doing_it_wrong(
2414
+			'EE_Registration::pretty_price_paid()',
2415
+			esc_html__(
2416
+				'This method is deprecated, please use EE_Registration::pretty_final_price() instead.',
2417
+				'event_espresso'
2418
+			),
2419
+			'4.7.0'
2420
+		);
2421
+		return $this->pretty_final_price();
2422
+	}
2423
+
2424
+
2425
+	/**
2426
+	 * Gets the primary datetime related to this registration via the related Event to this registration
2427
+	 *
2428
+	 * @return EE_Datetime
2429
+	 * @throws EE_Error
2430
+	 * @throws EntityNotFoundException
2431
+	 * @throws InvalidArgumentException
2432
+	 * @throws InvalidDataTypeException
2433
+	 * @throws InvalidInterfaceException
2434
+	 * @throws ReflectionException
2435
+	 * @deprecated 4.9.17
2436
+	 */
2437
+	public function get_related_primary_datetime()
2438
+	{
2439
+		EE_Error::doing_it_wrong(
2440
+			__METHOD__,
2441
+			esc_html__(
2442
+				'Use EE_Registration::get_latest_related_datetime() or EE_Registration::get_earliest_related_datetime()',
2443
+				'event_espresso'
2444
+			),
2445
+			'4.9.17',
2446
+			'5.0.0'
2447
+		);
2448
+		return $this->event()->primary_datetime();
2449
+	}
2450
+
2451
+
2452
+	/**
2453
+	 * Returns the contact's name (or "Unknown" if there is no contact.)
2454
+	 *
2455
+	 * @return string
2456
+	 * @throws EE_Error
2457
+	 * @throws InvalidArgumentException
2458
+	 * @throws InvalidDataTypeException
2459
+	 * @throws InvalidInterfaceException
2460
+	 * @throws ReflectionException
2461
+	 * @since 4.10.12.p
2462
+	 */
2463
+	public function name()
2464
+	{
2465
+		return $this->attendeeName();
2466
+	}
2467
+
2468
+
2469
+	/**
2470
+	 * @return bool
2471
+	 * @throws EE_Error
2472
+	 * @throws ReflectionException
2473
+	 */
2474
+	public function wasMoved(): bool
2475
+	{
2476
+		// only need to check 'registration-moved-to' because
2477
+		// the existence of a new REG ID means the registration was moved
2478
+		$reg_moved = $this->get_extra_meta('registration-moved-to', true, []);
2479
+		return isset($reg_moved['NEW_REG_ID']) && $reg_moved['NEW_REG_ID'];
2480
+	}
2481
+
2482
+
2483
+	/**
2484
+	 * @param EE_Payment $payment
2485
+	 * @param float|null $amount
2486
+	 * @return float
2487
+	 * @throws EE_Error
2488
+	 * @throws ReflectionException
2489
+	 * @since 5.0.8.p
2490
+	 */
2491
+	public function applyPayment(EE_Payment $payment, ?float $amount = null): float
2492
+	{
2493
+		// echo "\n\n";
2494
+		// \EEH_Debug_Tools::printr(__FUNCTION__, __CLASS__, __FILE__, __LINE__, 3);
2495
+		// \EEH_Debug_Tools::printr($this->ID(), 'REG ID', __FILE__, __LINE__);
2496
+		$payment_amount = $amount ?? $payment->amount();
2497
+		// ensure $payment_amount is NOT negative
2498
+		$payment_amount = (float) abs($payment_amount);
2499
+		// \EEH_Debug_Tools::printr($payment_amount, 'incoming $payment_amount', __FILE__, __LINE__);
2500
+		// \EEH_Debug_Tools::printr($this->final_price(), 'reg final price', __FILE__, __LINE__);
2501
+		// \EEH_Debug_Tools::printr($this->paid(), 'reg paid to date', __FILE__, __LINE__);
2502
+		$payment_amount = $payment->is_a_refund()
2503
+			? $this->processRefund($payment_amount)
2504
+			: $this->processPayment($payment_amount);
2505
+		// \EEH_Debug_Tools::printr($payment_amount, 'applied payment_amount', __FILE__, __LINE__);
2506
+		if ($payment_amount) {
2507
+			$reg_payment = EEM_Registration_Payment::instance()->get_one(
2508
+				[['REG_ID' => $this->ID(), 'PAY_ID' => $payment->ID()]]
2509
+			);
2510
+			// if existing registration payment exists
2511
+			if ($reg_payment instanceof EE_Registration_Payment) {
2512
+				// echo "\nUPDATE EXISTING REG PAYMENT";
2513
+				// then update that record
2514
+				$reg_payment->set_amount($payment_amount);
2515
+			} else {
2516
+				// echo "\nCREATE NEW REG PAYMENT";
2517
+				// or add new relation between registration and payment and set amount
2518
+				$reg_payment = EE_Registration_Payment::new_instance(
2519
+					[
2520
+						'REG_ID'     => $this->ID(),
2521
+						'PAY_ID'     => $payment->ID(),
2522
+						'RPY_amount' => $payment_amount,
2523
+					]
2524
+				);
2525
+				// $this->_add_relation_to($payment, 'Payment', ['RPY_amount' => $payment_amount]);
2526
+			}
2527
+			$reg_payment->save();
2528
+			// \EEH_Debug_Tools::printr($reg_payment->ID(), '$reg payment ID', __FILE__, __LINE__);
2529
+		}
2530
+		return $payment_amount;
2531
+	}
2532
+
2533
+
2534
+	/**
2535
+	 * @throws EE_Error
2536
+	 * @throws ReflectionException
2537
+	 */
2538
+	private function processPayment(float $payment_amount): float
2539
+	{
2540
+		// echo "\n";
2541
+		// \EEH_Debug_Tools::printr(__FUNCTION__, __CLASS__, __FILE__, __LINE__, 3);
2542
+		$paid  = $this->paid();
2543
+		$owing = $this->final_price() - $paid;
2544
+		// \EEH_Debug_Tools::printr($owing, '$owing', __FILE__, __LINE__);
2545
+		if ($owing <= 0) {
2546
+			return 0.0;
2547
+		}
2548
+		// don't allow payment amount to exceed the incoming amount, OR the amount owing
2549
+		$payment_amount = min($payment_amount, $owing);
2550
+		$paid           = $paid + $payment_amount;
2551
+		// \EEH_Debug_Tools::printr($paid, 'NEW REG PAID AMOUNT', __FILE__, __LINE__);
2552
+		// calculate and set new REG_paid
2553
+		$this->set_paid($paid);
2554
+		// make it stick
2555
+		$this->save();
2556
+		return (float) $payment_amount;
2557
+	}
2558
+
2559
+
2560
+	/**
2561
+	 * @throws ReflectionException
2562
+	 * @throws EE_Error
2563
+	 */
2564
+	private function processRefund(float $payment_amount): float
2565
+	{
2566
+		// echo "\n";
2567
+		// \EEH_Debug_Tools::printr(__FUNCTION__, __CLASS__, __FILE__, __LINE__, 3);
2568
+		$paid = $this->paid();
2569
+		if ($paid <= 0) {
2570
+			return 0.0;
2571
+		}
2572
+		// don't allow refund amount to exceed the incoming amount, OR the amount paid
2573
+		$payment_amount = min($payment_amount, $paid);
2574
+		// calculate and set new REG_paid
2575
+		$paid = $paid - $payment_amount;
2576
+		\EEH_Debug_Tools::printr($paid, 'NEW REG PAID AMOUNT', __FILE__, __LINE__);
2577
+		$this->set_paid($paid);
2578
+		// make it stick
2579
+		$this->save();
2580
+		// convert payment amount back to a negative value for storage in the db
2581
+		return (float) $payment_amount;
2582
+	}
2583 2583
 }
Please login to merge, or discard this patch.
Spacing   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -135,7 +135,7 @@  discard block
 block discarded – undo
135 135
     {
136 136
         switch ($field_name) {
137 137
             case 'REG_code':
138
-                if (! empty($field_value) && ! $this->reg_code()) {
138
+                if ( ! empty($field_value) && ! $this->reg_code()) {
139 139
                     $this->set_reg_code($field_value, $use_default);
140 140
                 }
141 141
                 break;
@@ -436,7 +436,7 @@  discard block
 block discarded – undo
436 436
     public function event(): EE_Event
437 437
     {
438 438
         $event = $this->get_first_related('Event');
439
-        if (! $event instanceof EE_Event) {
439
+        if ( ! $event instanceof EE_Event) {
440 440
             throw new EntityNotFoundException('Event ID', $this->event_ID());
441 441
         }
442 442
         return $event;
@@ -479,7 +479,7 @@  discard block
 block discarded – undo
479 479
     {
480 480
         // reserved ticket and datetime counts will be decremented as sold counts are incremented
481 481
         // so stop tracking that this reg has a ticket reserved
482
-        $this->release_reserved_ticket(false, "REG: {$this->ID()} (ln:" . __LINE__ . ')');
482
+        $this->release_reserved_ticket(false, "REG: {$this->ID()} (ln:".__LINE__.')');
483 483
         $ticket = $this->ticket();
484 484
         $ticket->increaseSold();
485 485
         // possibly set event status to sold out
@@ -529,7 +529,7 @@  discard block
 block discarded – undo
529 529
             $reserved = $this->update_extra_meta(EE_Registration::HAS_RESERVED_TICKET_KEY, true);
530 530
             if ($reserved && $update_ticket) {
531 531
                 $ticket = $this->ticket();
532
-                $ticket->increaseReserved(1, "REG: {$this->ID()} (ln:" . __LINE__ . ')');
532
+                $ticket->increaseReserved(1, "REG: {$this->ID()} (ln:".__LINE__.')');
533 533
                 $this->update_extra_meta('reserve_ticket', "{$this->ticket_ID()} from {$source}");
534 534
                 $ticket->save();
535 535
             }
@@ -557,7 +557,7 @@  discard block
 block discarded – undo
557 557
             $reserved = $this->update_extra_meta(EE_Registration::HAS_RESERVED_TICKET_KEY, false);
558 558
             if ($reserved && $update_ticket) {
559 559
                 $ticket = $this->ticket();
560
-                $ticket->decreaseReserved(1, true, "REG: {$this->ID()} (ln:" . __LINE__ . ')');
560
+                $ticket->decreaseReserved(1, true, "REG: {$this->ID()} (ln:".__LINE__.')');
561 561
                 $this->update_extra_meta('release_reserved_ticket', "{$this->ticket_ID()} from {$source}");
562 562
             }
563 563
         }
@@ -1357,7 +1357,7 @@  discard block
 block discarded – undo
1357 1357
             false,
1358 1358
             'sentence'
1359 1359
         );
1360
-        $icon   = '';
1360
+        $icon = '';
1361 1361
         switch ($this->status_ID()) {
1362 1362
             case EEM_Registration::status_id_approved:
1363 1363
                 $icon = $show_icons
@@ -1395,7 +1395,7 @@  discard block
 block discarded – undo
1395 1395
                     : '';
1396 1396
                 break;
1397 1397
         }
1398
-        return $icon . $status[ $this->status_ID() ];
1398
+        return $icon.$status[$this->status_ID()];
1399 1399
     }
1400 1400
 
1401 1401
 
@@ -1651,7 +1651,7 @@  discard block
 block discarded – undo
1651 1651
     {
1652 1652
         $DTT_ID = EEM_Datetime::instance()->ensure_is_ID($DTT_OR_ID);
1653 1653
         // first check registration status
1654
-        if (! $DTT_ID || ($check_approved && ! $this->is_approved())) {
1654
+        if ( ! $DTT_ID || ($check_approved && ! $this->is_approved())) {
1655 1655
             return false;
1656 1656
         }
1657 1657
         // is there a datetime ticket that matches this dtt_ID?
@@ -1691,7 +1691,7 @@  discard block
 block discarded – undo
1691 1691
     {
1692 1692
         $DTT_ID = EEM_Datetime::instance()->ensure_is_ID($DTT_OR_ID);
1693 1693
 
1694
-        if (! $DTT_ID) {
1694
+        if ( ! $DTT_ID) {
1695 1695
             return false;
1696 1696
         }
1697 1697
 
@@ -1701,7 +1701,7 @@  discard block
 block discarded – undo
1701 1701
 
1702 1702
         // if max uses is not set or equals infinity then return true cause its not a factor for whether user can
1703 1703
         // check-in or not.
1704
-        if (! $max_uses || $max_uses === EE_INF) {
1704
+        if ( ! $max_uses || $max_uses === EE_INF) {
1705 1705
             return true;
1706 1706
         }
1707 1707
 
@@ -1765,7 +1765,7 @@  discard block
 block discarded – undo
1765 1765
             $datetime = $this->get_latest_related_datetime();
1766 1766
             $DTT_ID   = $datetime instanceof EE_Datetime ? $datetime->ID() : 0;
1767 1767
             // verify the registration can checkin for the given DTT_ID
1768
-        } elseif (! $this->can_checkin($DTT_ID, $verify)) {
1768
+        } elseif ( ! $this->can_checkin($DTT_ID, $verify)) {
1769 1769
             EE_Error::add_error(
1770 1770
                 sprintf(
1771 1771
                     esc_html__(
@@ -1788,7 +1788,7 @@  discard block
 block discarded – undo
1788 1788
         ];
1789 1789
         // start by getting the current status so we know what status we'll be changing to.
1790 1790
         $cur_status = $this->check_in_status_for_datetime($DTT_ID);
1791
-        $status_to  = $status_paths[ $cur_status ];
1791
+        $status_to  = $status_paths[$cur_status];
1792 1792
         // database only records true for checked IN or false for checked OUT
1793 1793
         // no record ( null ) means checked in NEVER, but we obviously don't save that
1794 1794
         $new_status = $status_to === EE_Checkin::status_checked_in;
@@ -1905,7 +1905,7 @@  discard block
 block discarded – undo
1905 1905
             return $checkin->status();
1906 1906
         }
1907 1907
 
1908
-        if (! $DTT_ID) {
1908
+        if ( ! $DTT_ID) {
1909 1909
             return EE_Checkin::status_invalid;
1910 1910
         }
1911 1911
 
@@ -1973,7 +1973,7 @@  discard block
 block discarded – undo
1973 1973
     public function transaction(): EE_Transaction
1974 1974
     {
1975 1975
         $transaction = $this->get_first_related('Transaction');
1976
-        if (! $transaction instanceof \EE_Transaction) {
1976
+        if ( ! $transaction instanceof \EE_Transaction) {
1977 1977
             throw new EntityNotFoundException('Transaction ID', $this->transaction_ID());
1978 1978
         }
1979 1979
         return $transaction;
@@ -2047,11 +2047,11 @@  discard block
 block discarded – undo
2047 2047
             );
2048 2048
             return;
2049 2049
         }
2050
-        if (! $this->reg_code()) {
2050
+        if ( ! $this->reg_code()) {
2051 2051
             parent::set('REG_code', $REG_code, $use_default);
2052 2052
         } else {
2053 2053
             EE_Error::doing_it_wrong(
2054
-                __CLASS__ . '::' . __FUNCTION__,
2054
+                __CLASS__.'::'.__FUNCTION__,
2055 2055
                 esc_html__('Can not change a registration REG_code once it has been set.', 'event_espresso'),
2056 2056
                 '4.6.0'
2057 2057
             );
@@ -2242,7 +2242,7 @@  discard block
 block discarded – undo
2242 2242
                 break;
2243 2243
             }
2244 2244
         }
2245
-        if (! ($line_item instanceof \EE_Line_Item && $line_item->OBJ_type() === 'Ticket')) {
2245
+        if ( ! ($line_item instanceof \EE_Line_Item && $line_item->OBJ_type() === 'Ticket')) {
2246 2246
             throw new EntityNotFoundException('Line Item Ticket ID', $ticket->ID());
2247 2247
         }
2248 2248
         return $line_item;
Please login to merge, or discard this patch.
core/db_classes/EE_Question_Option.class.php 1 patch
Indentation   +220 added lines, -220 removed lines patch added patch discarded remove patch
@@ -9,224 +9,224 @@
 block discarded – undo
9 9
  */
10 10
 class EE_Question_Option extends EE_Soft_Delete_Base_Class implements EEI_Duplicatable
11 11
 {
12
-    /**
13
-     * Question Option Opt Group Name
14
-     *
15
-     * @access protected
16
-     * @var string
17
-     */
18
-    protected $_QSO_opt_group = null;
19
-
20
-
21
-    /**
22
-     * @param array  $props_n_values          incoming values
23
-     * @param string $timezone                incoming timezone (if not set the timezone set for the website will be
24
-     *                                        used.)
25
-     * @param array  $date_formats            incoming date_formats in an array where the first value is the
26
-     *                                        date_format and the second value is the time format
27
-     * @return EE_Attendee
28
-     */
29
-    public static function new_instance($props_n_values = [], $timezone = '', $date_formats = [])
30
-    {
31
-        $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats);
32
-        return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats);
33
-    }
34
-
35
-
36
-    /**
37
-     * @param array  $props_n_values  incoming values from the database
38
-     * @param string $timezone        incoming timezone as set by the model.  If not set the timezone for
39
-     *                                the website will be used.
40
-     * @return EE_Attendee
41
-     */
42
-    public static function new_instance_from_db($props_n_values = [], $timezone = '')
43
-    {
44
-        return new self($props_n_values, true, $timezone);
45
-    }
46
-
47
-
48
-    /**
49
-     * Sets the option's key value
50
-     *
51
-     * @param string $value
52
-     * @return bool success
53
-     */
54
-    public function set_value($value)
55
-    {
56
-        $this->set('QSO_value', $value);
57
-    }
58
-
59
-
60
-    /**
61
-     * Sets the option's Display Text
62
-     *
63
-     * @param string $text
64
-     * @return bool success
65
-     */
66
-    public function set_desc($text)
67
-    {
68
-        $this->set('QSO_desc', $text);
69
-    }
70
-
71
-
72
-    /**
73
-     * Sets the order for this option
74
-     *
75
-     * @access public
76
-     * @param integer $order
77
-     * @return bool      $success
78
-     */
79
-    public function set_order($order)
80
-    {
81
-        $this->set('QSO_order', $order);
82
-    }
83
-
84
-
85
-    /**
86
-     * Sets the ID of the related question
87
-     *
88
-     * @param int $question_ID
89
-     * @return bool success
90
-     */
91
-    public function set_question_ID($question_ID)
92
-    {
93
-        $this->set('QST_ID', $question_ID);
94
-    }
95
-
96
-
97
-    /**
98
-     * Sets the option's opt_group
99
-     *
100
-     * @param string $text
101
-     * @return bool success
102
-     */
103
-    public function set_opt_group($text)
104
-    {
105
-        return $this->_QSO_opt_group = $text;
106
-    }
107
-
108
-
109
-    /**
110
-     * Gets the option's key value
111
-     *
112
-     * @return string
113
-     */
114
-    public function value()
115
-    {
116
-        return $this->get('QSO_value');
117
-    }
118
-
119
-
120
-    /**
121
-     * Gets the option's display text
122
-     *
123
-     * @return string
124
-     */
125
-    public function desc()
126
-    {
127
-        return $this->get('QSO_desc');
128
-    }
129
-
130
-
131
-    /**
132
-     * Returns whether this option has been deleted or not
133
-     *
134
-     * @return boolean
135
-     */
136
-    public function deleted()
137
-    {
138
-        return $this->get('QSO_deleted');
139
-    }
140
-
141
-
142
-    /**
143
-     * Returns the order or the Question Option
144
-     *
145
-     * @access public
146
-     * @return integer
147
-     */
148
-    public function order()
149
-    {
150
-        return $this->get('QSO_option');
151
-    }
152
-
153
-
154
-    /**
155
-     * Gets the related question's ID
156
-     *
157
-     * @return int
158
-     */
159
-    public function question_ID()
160
-    {
161
-        return $this->get('QST_ID');
162
-    }
163
-
164
-
165
-    /**
166
-     * Returns the question related to this question option
167
-     *
168
-     * @return EE_Question
169
-     */
170
-    public function question()
171
-    {
172
-        return $this->get_first_related('Question');
173
-    }
174
-
175
-
176
-    /**
177
-     * Gets the option's opt_group
178
-     *
179
-     * @return string
180
-     */
181
-    public function opt_group()
182
-    {
183
-        return $this->_QSO_opt_group;
184
-    }
185
-
186
-
187
-    /**
188
-     * Duplicates this question option. By default the new question option will be for the same question,
189
-     * but that can be overriden by setting the 'QST_ID' option
190
-     *
191
-     * @param array $options {
192
-     * @type int    $QST_ID  the QST_ID attribute of this question option, otherwise it will be for the same question
193
-     *                       as the original
194
-     */
195
-    public function duplicate($options = [])
196
-    {
197
-        $new_question_option = clone $this;
198
-        $new_question_option->set('QSO_ID', null);
199
-        if (
200
-            array_key_exists(
201
-                'QST_ID',
202
-                $options
203
-            )
204
-        ) {// use array_key_exists instead of isset because NULL might be a valid value
205
-            $new_question_option->set_question_ID($options['QST_ID']);
206
-        }
207
-        $new_question_option->save();
208
-    }
209
-
210
-
211
-    /**
212
-     * Gets the QSO_system value
213
-     *
214
-     * @return string|null
215
-     */
216
-    public function system()
217
-    {
218
-        return $this->get('QSO_system');
219
-    }
220
-
221
-
222
-    /**
223
-     * Sets QSO_system
224
-     *
225
-     * @param string $QSO_system
226
-     * @return bool
227
-     */
228
-    public function set_system($QSO_system)
229
-    {
230
-        return $this->set('QSO_system', $QSO_system);
231
-    }
12
+	/**
13
+	 * Question Option Opt Group Name
14
+	 *
15
+	 * @access protected
16
+	 * @var string
17
+	 */
18
+	protected $_QSO_opt_group = null;
19
+
20
+
21
+	/**
22
+	 * @param array  $props_n_values          incoming values
23
+	 * @param string $timezone                incoming timezone (if not set the timezone set for the website will be
24
+	 *                                        used.)
25
+	 * @param array  $date_formats            incoming date_formats in an array where the first value is the
26
+	 *                                        date_format and the second value is the time format
27
+	 * @return EE_Attendee
28
+	 */
29
+	public static function new_instance($props_n_values = [], $timezone = '', $date_formats = [])
30
+	{
31
+		$has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats);
32
+		return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats);
33
+	}
34
+
35
+
36
+	/**
37
+	 * @param array  $props_n_values  incoming values from the database
38
+	 * @param string $timezone        incoming timezone as set by the model.  If not set the timezone for
39
+	 *                                the website will be used.
40
+	 * @return EE_Attendee
41
+	 */
42
+	public static function new_instance_from_db($props_n_values = [], $timezone = '')
43
+	{
44
+		return new self($props_n_values, true, $timezone);
45
+	}
46
+
47
+
48
+	/**
49
+	 * Sets the option's key value
50
+	 *
51
+	 * @param string $value
52
+	 * @return bool success
53
+	 */
54
+	public function set_value($value)
55
+	{
56
+		$this->set('QSO_value', $value);
57
+	}
58
+
59
+
60
+	/**
61
+	 * Sets the option's Display Text
62
+	 *
63
+	 * @param string $text
64
+	 * @return bool success
65
+	 */
66
+	public function set_desc($text)
67
+	{
68
+		$this->set('QSO_desc', $text);
69
+	}
70
+
71
+
72
+	/**
73
+	 * Sets the order for this option
74
+	 *
75
+	 * @access public
76
+	 * @param integer $order
77
+	 * @return bool      $success
78
+	 */
79
+	public function set_order($order)
80
+	{
81
+		$this->set('QSO_order', $order);
82
+	}
83
+
84
+
85
+	/**
86
+	 * Sets the ID of the related question
87
+	 *
88
+	 * @param int $question_ID
89
+	 * @return bool success
90
+	 */
91
+	public function set_question_ID($question_ID)
92
+	{
93
+		$this->set('QST_ID', $question_ID);
94
+	}
95
+
96
+
97
+	/**
98
+	 * Sets the option's opt_group
99
+	 *
100
+	 * @param string $text
101
+	 * @return bool success
102
+	 */
103
+	public function set_opt_group($text)
104
+	{
105
+		return $this->_QSO_opt_group = $text;
106
+	}
107
+
108
+
109
+	/**
110
+	 * Gets the option's key value
111
+	 *
112
+	 * @return string
113
+	 */
114
+	public function value()
115
+	{
116
+		return $this->get('QSO_value');
117
+	}
118
+
119
+
120
+	/**
121
+	 * Gets the option's display text
122
+	 *
123
+	 * @return string
124
+	 */
125
+	public function desc()
126
+	{
127
+		return $this->get('QSO_desc');
128
+	}
129
+
130
+
131
+	/**
132
+	 * Returns whether this option has been deleted or not
133
+	 *
134
+	 * @return boolean
135
+	 */
136
+	public function deleted()
137
+	{
138
+		return $this->get('QSO_deleted');
139
+	}
140
+
141
+
142
+	/**
143
+	 * Returns the order or the Question Option
144
+	 *
145
+	 * @access public
146
+	 * @return integer
147
+	 */
148
+	public function order()
149
+	{
150
+		return $this->get('QSO_option');
151
+	}
152
+
153
+
154
+	/**
155
+	 * Gets the related question's ID
156
+	 *
157
+	 * @return int
158
+	 */
159
+	public function question_ID()
160
+	{
161
+		return $this->get('QST_ID');
162
+	}
163
+
164
+
165
+	/**
166
+	 * Returns the question related to this question option
167
+	 *
168
+	 * @return EE_Question
169
+	 */
170
+	public function question()
171
+	{
172
+		return $this->get_first_related('Question');
173
+	}
174
+
175
+
176
+	/**
177
+	 * Gets the option's opt_group
178
+	 *
179
+	 * @return string
180
+	 */
181
+	public function opt_group()
182
+	{
183
+		return $this->_QSO_opt_group;
184
+	}
185
+
186
+
187
+	/**
188
+	 * Duplicates this question option. By default the new question option will be for the same question,
189
+	 * but that can be overriden by setting the 'QST_ID' option
190
+	 *
191
+	 * @param array $options {
192
+	 * @type int    $QST_ID  the QST_ID attribute of this question option, otherwise it will be for the same question
193
+	 *                       as the original
194
+	 */
195
+	public function duplicate($options = [])
196
+	{
197
+		$new_question_option = clone $this;
198
+		$new_question_option->set('QSO_ID', null);
199
+		if (
200
+			array_key_exists(
201
+				'QST_ID',
202
+				$options
203
+			)
204
+		) {// use array_key_exists instead of isset because NULL might be a valid value
205
+			$new_question_option->set_question_ID($options['QST_ID']);
206
+		}
207
+		$new_question_option->save();
208
+	}
209
+
210
+
211
+	/**
212
+	 * Gets the QSO_system value
213
+	 *
214
+	 * @return string|null
215
+	 */
216
+	public function system()
217
+	{
218
+		return $this->get('QSO_system');
219
+	}
220
+
221
+
222
+	/**
223
+	 * Sets QSO_system
224
+	 *
225
+	 * @param string $QSO_system
226
+	 * @return bool
227
+	 */
228
+	public function set_system($QSO_system)
229
+	{
230
+		return $this->set('QSO_system', $QSO_system);
231
+	}
232 232
 }
Please login to merge, or discard this patch.
core/EE_System.core.php 2 patches
Indentation   +1246 added lines, -1246 removed lines patch added patch discarded remove patch
@@ -25,1250 +25,1250 @@
 block discarded – undo
25 25
  */
26 26
 final class EE_System implements ResettableInterface
27 27
 {
28
-    /**
29
-     * indicates this is a 'normal' request. Ie, not activation, nor upgrade, nor activation.
30
-     * So examples of this would be a normal GET request on the frontend or backend, or a POST, etc
31
-     */
32
-    const req_type_normal = 0;
33
-
34
-    /**
35
-     * Indicates this is a brand new installation of EE so we should install
36
-     * tables and default data etc
37
-     */
38
-    const req_type_new_activation = 1;
39
-
40
-    /**
41
-     * we've detected that EE has been reactivated (or EE was activated during maintenance mode,
42
-     * and we just exited maintenance mode). We MUST check the database is setup properly
43
-     * and that default data is setup too
44
-     */
45
-    const req_type_reactivation = 2;
46
-
47
-    /**
48
-     * indicates that EE has been upgraded since its previous request.
49
-     * We may have data migration scripts to call and will want to trigger maintenance mode
50
-     */
51
-    const req_type_upgrade = 3;
52
-
53
-    /**
54
-     * TODO  will detect that EE has been DOWNGRADED. We probably don't want to run in this case...
55
-     */
56
-    const req_type_downgrade = 4;
57
-
58
-    /**
59
-     * @deprecated since version 4.6.0.dev.006
60
-     * Now whenever a new_activation is detected the request type is still just
61
-     * new_activation (same for reactivation, upgrade, downgrade etc), but if we're in maintenance mode
62
-     * EE_System::initialize_db_if_no_migrations_required and EE_Addon::initialize_db_if_no_migrations_required
63
-     * will instead enqueue that EE plugin's db initialization for when we're taken out of maintenance mode.
64
-     * (Specifically, when the migration manager indicates migrations are finished
65
-     * EE_Data_Migration_Manager::initialize_db_for_enqueued_ee_plugins() will be called)
66
-     */
67
-    const req_type_activation_but_not_installed = 5;
68
-
69
-    /**
70
-     * option prefix for recording the activation history (like core's "espresso_db_update") of addons
71
-     */
72
-    const addon_activation_history_option_prefix = 'ee_addon_activation_history_';
73
-
74
-    /**
75
-     * @var AddonManager $addon_manager
76
-     */
77
-    private $addon_manager;
78
-
79
-    /**
80
-     * @var EE_System $_instance
81
-     */
82
-    private static $_instance;
83
-
84
-    /**
85
-     * @var EE_Registry $registry
86
-     */
87
-    private $registry;
88
-
89
-    /**
90
-     * @var LoaderInterface $loader
91
-     */
92
-    private $loader;
93
-
94
-    /**
95
-     * @var EE_Capabilities $capabilities
96
-     */
97
-    private $capabilities;
98
-
99
-    /**
100
-     * @var EE_Maintenance_Mode $maintenance_mode
101
-     */
102
-    private $maintenance_mode;
103
-
104
-    /**
105
-     * @var RequestInterface $request
106
-     */
107
-    private $request;
108
-
109
-    /**
110
-     * Stores which type of request this is, options being one of the constants on EE_System starting with req_type_*.
111
-     * It can be a brand-new activation, a reactivation, an upgrade, a downgrade, or a normal request.
112
-     *
113
-     * @var int $_req_type
114
-     */
115
-    private $_req_type;
116
-
117
-    /**
118
-     * Whether or not there was a non-micro version change in EE core version during this request
119
-     *
120
-     * @var boolean $_major_version_change
121
-     */
122
-    private $_major_version_change = false;
123
-
124
-    /**
125
-     * @var Router $router
126
-     */
127
-    private $router;
128
-
129
-    /**
130
-     * @param EventEspresso\core\domain\services\custom_post_types\RegisterCustomPostTypes
131
-     */
132
-    private $register_custom_post_types;
133
-
134
-    /**
135
-     * @param EventEspresso\core\domain\services\custom_post_types\RegisterCustomTaxonomies
136
-     */
137
-    private $register_custom_taxonomies;
138
-
139
-    /**
140
-     * @param EventEspresso\core\domain\services\custom_post_types\RegisterCustomTaxonomyTerms
141
-     */
142
-    private $register_custom_taxonomy_terms;
143
-
144
-
145
-    /**
146
-     * @singleton method used to instantiate class object
147
-     * @param LoaderInterface|null     $loader
148
-     * @param EE_Maintenance_Mode|null $maintenance_mode
149
-     * @param EE_Registry|null         $registry
150
-     * @param RequestInterface|null    $request
151
-     * @param Router|null              $router
152
-     * @return EE_System
153
-     */
154
-    public static function instance(
155
-        LoaderInterface $loader = null,
156
-        EE_Maintenance_Mode $maintenance_mode = null,
157
-        EE_Registry $registry = null,
158
-        RequestInterface $request = null,
159
-        Router $router = null
160
-    ): EE_System {
161
-        // check if class object is instantiated
162
-        if (! self::$_instance instanceof EE_System) {
163
-            self::$_instance = new self($loader, $maintenance_mode, $registry, $request, $router);
164
-        }
165
-        return self::$_instance;
166
-    }
167
-
168
-
169
-    /**
170
-     * resets the instance and returns it
171
-     *
172
-     * @return EE_System
173
-     */
174
-    public static function reset(): EE_System
175
-    {
176
-        self::$_instance->_req_type = null;
177
-        // make sure none of the old hooks are left hanging around
178
-        remove_all_actions('AHEE__EE_System__perform_activations_upgrades_and_migrations');
179
-        // we need to reset the migration manager in order for it to detect DMSs properly
180
-        EE_Data_Migration_Manager::reset();
181
-        self::instance()->detect_activations_or_upgrades();
182
-        self::instance()->perform_activations_upgrades_and_migrations();
183
-        return self::instance();
184
-    }
185
-
186
-
187
-    /**
188
-     * sets hooks for running rest of system
189
-     * provides "AHEE__EE_System__construct__complete" hook for EE Addons to use as their starting point
190
-     * starting EE Addons from any other point may lead to problems
191
-     *
192
-     * @param LoaderInterface     $loader
193
-     * @param EE_Maintenance_Mode $maintenance_mode
194
-     * @param EE_Registry         $registry
195
-     * @param RequestInterface    $request
196
-     * @param Router              $router
197
-     */
198
-    private function __construct(
199
-        LoaderInterface $loader,
200
-        EE_Maintenance_Mode $maintenance_mode,
201
-        EE_Registry $registry,
202
-        RequestInterface $request,
203
-        Router $router
204
-    ) {
205
-        $this->registry         = $registry;
206
-        $this->loader           = $loader;
207
-        $this->request          = $request;
208
-        $this->router           = $router;
209
-        $this->maintenance_mode = $maintenance_mode;
210
-        do_action('AHEE__EE_System__construct__begin', $this);
211
-        add_action(
212
-            'AHEE__EE_Bootstrap__load_espresso_addons',
213
-            [$this, 'loadWpGraphQL'],
214
-            3
215
-        );
216
-        add_action(
217
-            'AHEE__EE_Bootstrap__load_espresso_addons',
218
-            [$this, 'loadCapabilities'],
219
-            5
220
-        );
221
-        add_action(
222
-            'AHEE__EE_Bootstrap__load_espresso_addons',
223
-            [$this, 'loadCommandBus'],
224
-            7
225
-        );
226
-        add_action(
227
-            'AHEE__EE_Bootstrap__load_espresso_addons',
228
-            [$this, 'loadPluginApi'],
229
-            9
230
-        );
231
-        // give caff stuff a chance to play during the activation process too.
232
-        add_action(
233
-            'AHEE__EE_Bootstrap__load_espresso_addons',
234
-            [$this, 'brewCaffeinated'],
235
-            9
236
-        );
237
-        // allow addons to load first so that they can register autoloaders, set hooks for running DMS's, etc
238
-        add_action(
239
-            'AHEE__EE_Bootstrap__load_espresso_addons',
240
-            [$this, 'load_espresso_addons']
241
-        );
242
-        // when an ee addon is activated, we want to call the core hook(s) again
243
-        // because the newly-activated addon didn't get a chance to run at all
244
-        add_action('activate_plugin', [$this, 'load_espresso_addons'], 1);
245
-        // detect whether install or upgrade
246
-        add_action(
247
-            'AHEE__EE_Bootstrap__detect_activations_or_upgrades',
248
-            [$this, 'detect_activations_or_upgrades'],
249
-            3
250
-        );
251
-        // load EE_Config, EE_Textdomain, etc
252
-        add_action(
253
-            'AHEE__EE_Bootstrap__load_core_configuration',
254
-            [$this, 'load_core_configuration'],
255
-            5
256
-        );
257
-        // load specifications for matching routes to current request
258
-        add_action(
259
-            'AHEE__EE_Bootstrap__load_core_configuration',
260
-            [$this, 'loadRouteMatchSpecifications']
261
-        );
262
-        // load specifications for custom post types
263
-        add_action(
264
-            'AHEE__EE_Bootstrap__load_core_configuration',
265
-            [$this, 'loadCustomPostTypes']
266
-        );
267
-        // load specifications for custom post types
268
-        add_action(
269
-            'AHEE__EE_Bootstrap__load_core_configuration',
270
-            [$this, 'loadCustomPostTypes']
271
-        );
272
-        // load EE_Config, EE_Textdomain, etc
273
-        add_action(
274
-            'AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets',
275
-            [$this, 'register_shortcodes_modules_and_widgets'],
276
-            7
277
-        );
278
-        // you wanna get going? I wanna get going... let's get going!
279
-        add_action(
280
-            'AHEE__EE_Bootstrap__brew_espresso',
281
-            [$this, 'brew_espresso'],
282
-            9
283
-        );
284
-        // other housekeeping
285
-        // exclude EE critical pages from wp_list_pages
286
-        add_filter(
287
-            'wp_list_pages_excludes',
288
-            [$this, 'remove_pages_from_wp_list_pages'],
289
-            10
290
-        );
291
-        // ALL EE Addons should use the following hook point to attach their initial setup too
292
-        // it's extremely important for EE Addons to register any class autoloaders so that they can be available when the EE_Config loads
293
-        do_action('AHEE__EE_System__construct__complete', $this);
294
-    }
295
-
296
-
297
-    /**
298
-     * load and setup EE_Capabilities
299
-     *
300
-     * @return void
301
-     */
302
-    public function loadWpGraphQL()
303
-    {
304
-        espressoLoadWpGraphQL();
305
-    }
306
-
307
-
308
-    /**
309
-     * load and setup EE_Capabilities
310
-     *
311
-     * @return void
312
-     */
313
-    public function loadCapabilities()
314
-    {
315
-        $this->capabilities = $this->loader->getShared('EE_Capabilities');
316
-    }
317
-
318
-
319
-    /**
320
-     * create and cache the CommandBus, and also add middleware
321
-     * The CapChecker middleware requires the use of EE_Capabilities
322
-     * which is why we need to load the CommandBus after Caps are set up
323
-     * CommandBus middleware operate FIFO - First In First Out
324
-     * so LocateMovedCommands will run first in order to return any new commands
325
-     *
326
-     * @return void
327
-     */
328
-    public function loadCommandBus()
329
-    {
330
-        $this->loader->getShared(
331
-            'CommandBusInterface',
332
-            [
333
-                null,
334
-                apply_filters(
335
-                    'FHEE__EE_Load_Espresso_Core__handle_request__CommandBus_middleware',
336
-                    [
337
-                        $this->loader->getShared('EventEspresso\core\services\commands\middleware\LocateMovedCommands'),
338
-                        $this->loader->getShared('EventEspresso\core\services\commands\middleware\CapChecker'),
339
-                        $this->loader->getShared('EventEspresso\core\services\commands\middleware\AddActionHook'),
340
-                    ]
341
-                ),
342
-            ]
343
-        );
344
-    }
345
-
346
-
347
-    /**
348
-     * @return void
349
-     * @throws Exception
350
-     */
351
-    public function loadPluginApi()
352
-    {
353
-        $this->addon_manager = $this->loader->getShared(AddonManager::class);
354
-        $this->addon_manager->initialize();
355
-        $this->loader->getShared('EE_Request_Handler');
356
-    }
357
-
358
-
359
-    /**
360
-     * The purpose of this method is to simply check for a file named "caffeinated/brewing_regular.php" for any hooks
361
-     * that need to be setup before our EE_System launches.
362
-     *
363
-     * @return void
364
-     * @throws DomainException
365
-     * @throws InvalidArgumentException
366
-     * @throws InvalidDataTypeException
367
-     * @throws InvalidInterfaceException
368
-     * @throws InvalidClassException
369
-     * @throws InvalidFilePathException
370
-     * @throws EE_Error
371
-     */
372
-    public function brewCaffeinated()
373
-    {
374
-        static $brew;
375
-        /** @var Domain $domain */
376
-        $domain = DomainFactory::getEventEspressoCoreDomain();
377
-        if ($domain->isCaffeinated() && ! $brew instanceof EE_Brewing_Regular) {
378
-            require_once EE_CAFF_PATH . 'brewing_regular.php';
379
-            /** @var EE_Brewing_Regular $brew */
380
-            $brew = LoaderFactory::getLoader()->getShared(EE_Brewing_Regular::class);
381
-            $brew->initializePUE();
382
-            add_action(
383
-                'AHEE__EE_System__load_core_configuration__begin',
384
-                [$brew, 'caffeinated']
385
-            );
386
-        }
387
-    }
388
-
389
-
390
-    /**
391
-     * load_espresso_addons
392
-     * allow addons to load first so that they can set hooks for running DMS's, etc
393
-     * this is hooked into both:
394
-     *    'AHEE__EE_Bootstrap__load_core_configuration'
395
-     *        which runs during the WP 'plugins_loaded' action at priority 5
396
-     *    and the WP 'activate_plugin' hook point
397
-     *
398
-     * @return void
399
-     * @throws Exception
400
-     */
401
-    public function load_espresso_addons()
402
-    {
403
-        // looking for hooks? they've been moved into the AddonManager to maintain compatibility
404
-        $this->addon_manager->loadAddons();
405
-    }
406
-
407
-
408
-    /**
409
-     * detect_activations_or_upgrades
410
-     * Checks for activation or upgrade of core first;
411
-     * then also checks if any registered addons have been activated or upgraded
412
-     * This is hooked into 'AHEE__EE_Bootstrap__detect_activations_or_upgrades'
413
-     * which runs during the WP 'plugins_loaded' action at priority 3
414
-     *
415
-     * @access public
416
-     * @return void
417
-     */
418
-    public function detect_activations_or_upgrades()
419
-    {
420
-        // first off: let's make sure to handle core
421
-        $this->detect_if_activation_or_upgrade();
422
-        foreach ($this->registry->addons as $addon) {
423
-            if ($addon instanceof EE_Addon) {
424
-                // detect teh request type for that addon
425
-                $addon->detect_req_type();
426
-            }
427
-        }
428
-    }
429
-
430
-
431
-    /**
432
-     * detect_if_activation_or_upgrade
433
-     * Takes care of detecting whether this is a brand new install or code upgrade,
434
-     * and either setting up the DB or setting up maintenance mode etc.
435
-     *
436
-     * @access public
437
-     * @return void
438
-     */
439
-    public function detect_if_activation_or_upgrade()
440
-    {
441
-        do_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin');
442
-        // check if db has been updated, or if its a brand-new installation
443
-        $espresso_db_update = $this->fix_espresso_db_upgrade_option();
444
-        $request_type       = $this->detect_req_type($espresso_db_update);
445
-        switch ($request_type) {
446
-            case EE_System::req_type_new_activation:
447
-                do_action('AHEE__EE_System__detect_if_activation_or_upgrade__new_activation');
448
-                $this->_handle_core_version_change($espresso_db_update);
449
-                break;
450
-            case EE_System::req_type_reactivation:
451
-                do_action('AHEE__EE_System__detect_if_activation_or_upgrade__reactivation');
452
-                $this->_handle_core_version_change($espresso_db_update);
453
-                break;
454
-            case EE_System::req_type_upgrade:
455
-                do_action('AHEE__EE_System__detect_if_activation_or_upgrade__upgrade');
456
-                // migrations may be required now that we've upgraded
457
-                $this->maintenance_mode->set_maintenance_mode_if_db_old();
458
-                $this->_handle_core_version_change($espresso_db_update);
459
-                break;
460
-            case EE_System::req_type_downgrade:
461
-                do_action('AHEE__EE_System__detect_if_activation_or_upgrade__downgrade');
462
-                // its possible migrations are no longer required
463
-                $this->maintenance_mode->set_maintenance_mode_if_db_old();
464
-                $this->_handle_core_version_change($espresso_db_update);
465
-                break;
466
-            case EE_System::req_type_normal:
467
-            default:
468
-                break;
469
-        }
470
-        do_action('AHEE__EE_System__detect_if_activation_or_upgrade__complete');
471
-    }
472
-
473
-
474
-    /**
475
-     * Updates the list of installed versions and sets hooks for
476
-     * initializing the database later during the request
477
-     *
478
-     * @param array $espresso_db_update
479
-     */
480
-    private function _handle_core_version_change(array $espresso_db_update)
481
-    {
482
-        $this->update_list_of_installed_versions($espresso_db_update);
483
-        // get ready to verify the DB is ok (provided we aren't in maintenance mode, of course)
484
-        add_action(
485
-            'AHEE__EE_System__perform_activations_upgrades_and_migrations',
486
-            [$this, 'initialize_db_if_no_migrations_required']
487
-        );
488
-    }
489
-
490
-
491
-    /**
492
-     * standardizes the wp option 'espresso_db_upgrade' which actually stores
493
-     * information about what versions of EE have been installed and activated,
494
-     * NOT necessarily the state of the database
495
-     *
496
-     * @param mixed $espresso_db_update           the value of the WordPress option.
497
-     *                                            If not supplied, fetches it from the options table
498
-     * @return array the correct value of 'espresso_db_upgrade', after saving it, if it needed correction
499
-     */
500
-    private function fix_espresso_db_upgrade_option($espresso_db_update = null): array
501
-    {
502
-        do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__begin', $espresso_db_update);
503
-        if (! $espresso_db_update) {
504
-            $espresso_db_update = get_option('espresso_db_update');
505
-        }
506
-        // check that option is an array
507
-        if (! is_array($espresso_db_update)) {
508
-            // if option is FALSE, then it never existed
509
-            if ($espresso_db_update === false) {
510
-                // make $espresso_db_update an array and save option with autoload OFF
511
-                $espresso_db_update = [];
512
-                add_option('espresso_db_update', $espresso_db_update, '', 'no');
513
-            } else {
514
-                // option is NOT FALSE but also is NOT an array, so make it an array and save it
515
-                $espresso_db_update = [$espresso_db_update => []];
516
-                update_option('espresso_db_update', $espresso_db_update);
517
-            }
518
-        } else {
519
-            $corrected_db_update = [];
520
-            // if IS an array, but is it an array where KEYS are version numbers, and values are arrays?
521
-            foreach ($espresso_db_update as $should_be_version_string => $should_be_array) {
522
-                if (is_int($should_be_version_string) && ! is_array($should_be_array)) {
523
-                    // the key is an int, and the value IS NOT an array
524
-                    // so it must be numerically-indexed, where values are versions installed...
525
-                    // fix it!
526
-                    $version_string                         = $should_be_array;
527
-                    $corrected_db_update[ $version_string ] = ['unknown-date'];
528
-                } else {
529
-                    // ok it checks out
530
-                    $corrected_db_update[ $should_be_version_string ] = $should_be_array;
531
-                }
532
-            }
533
-            $espresso_db_update = $corrected_db_update;
534
-            update_option('espresso_db_update', $espresso_db_update);
535
-        }
536
-        do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__complete', $espresso_db_update);
537
-        return ! empty($espresso_db_update)
538
-            ? $espresso_db_update
539
-            : [];
540
-    }
541
-
542
-
543
-    /**
544
-     * Does the traditional work of setting up the plugin's database and adding default data.
545
-     * If migration script/process did not exist, this is what would happen on every activation/reactivation/upgrade.
546
-     * NOTE: if we're in maintenance mode (which would be the case if we detect there are data
547
-     * migration scripts that need to be run and a version change happens), enqueues core for database initialization,
548
-     * so that it will be done when migrations are finished
549
-     *
550
-     * @param boolean $initialize_addons_too if true, we double-check addons' database tables etc too;
551
-     * @param boolean $verify_schema         if true will re-check the database tables have the correct schema.
552
-     *                                       This is a resource-intensive job
553
-     *                                       so we prefer to only do it when necessary
554
-     * @return void
555
-     * @throws EE_Error
556
-     * @throws ReflectionException
557
-     */
558
-    public function initialize_db_if_no_migrations_required($initialize_addons_too = false, $verify_schema = true)
559
-    {
560
-        $request_type = $this->detect_req_type();
561
-        // only initialize system if we're not in maintenance mode.
562
-        if ($this->maintenance_mode->level() !== EE_Maintenance_Mode::level_2_complete_maintenance) {
563
-            /** @var EventEspresso\core\domain\services\custom_post_types\RewriteRules $rewrite_rules */
564
-            $rewrite_rules = $this->loader->getShared(
565
-                'EventEspresso\core\domain\services\custom_post_types\RewriteRules'
566
-            );
567
-            $rewrite_rules->flush();
568
-            if ($verify_schema) {
569
-                EEH_Activation::initialize_db_and_folders();
570
-            }
571
-            EEH_Activation::initialize_db_content();
572
-            EEH_Activation::system_initialization();
573
-            if ($initialize_addons_too) {
574
-                $this->initialize_addons();
575
-            }
576
-        } else {
577
-            EE_Data_Migration_Manager::instance()->enqueue_db_initialization_for('Core');
578
-        }
579
-        if (
580
-            $request_type === EE_System::req_type_new_activation
581
-            || $request_type === EE_System::req_type_reactivation
582
-            || (
583
-                $request_type === EE_System::req_type_upgrade
584
-                && $this->is_major_version_change()
585
-            )
586
-        ) {
587
-            add_action('AHEE__EE_System__initialize_last', [$this, 'redirect_to_about_ee'], 9);
588
-        }
589
-    }
590
-
591
-
592
-    /**
593
-     * Initializes the db for all registered addons
594
-     *
595
-     * @throws EE_Error
596
-     * @throws ReflectionException
597
-     */
598
-    public function initialize_addons()
599
-    {
600
-        // foreach registered addon, make sure its db is up-to-date too
601
-        foreach ($this->registry->addons as $addon) {
602
-            if ($addon instanceof EE_Addon) {
603
-                $addon->initialize_db_if_no_migrations_required();
604
-            }
605
-        }
606
-    }
607
-
608
-
609
-    /**
610
-     * Adds the current code version to the saved wp option which stores a list of all ee versions ever installed.
611
-     *
612
-     * @param array  $version_history
613
-     * @param string $current_version_to_add version to be added to the version history
614
-     * @return    boolean success as to whether or not this option was changed
615
-     */
616
-    public function update_list_of_installed_versions($version_history = null, $current_version_to_add = null): bool
617
-    {
618
-        if (! $version_history) {
619
-            $version_history = $this->fix_espresso_db_upgrade_option($version_history);
620
-        }
621
-        if ($current_version_to_add === null) {
622
-            $current_version_to_add = espresso_version();
623
-        }
624
-        $version_history[ $current_version_to_add ][] = date('Y-m-d H:i:s', time());
625
-        // re-save
626
-        return update_option('espresso_db_update', $version_history);
627
-    }
628
-
629
-
630
-    /**
631
-     * Detects if the current version indicated in the has existed in the list of
632
-     * previously-installed versions of EE (espresso_db_update). Does NOT modify it (ie, no side-effect)
633
-     *
634
-     * @param array|null $espresso_db_update array from the wp option stored under the name 'espresso_db_update'.
635
-     *                                       If not supplied, fetches it from the options table.
636
-     *                                       Also, caches its result so later parts of the code can also know whether
637
-     *                                       there's been an update or not. This way we can add the current version to
638
-     *                                       espresso_db_update, but still know if this is a new install or not
639
-     * @return int one of the constants on EE_System::req_type_
640
-     */
641
-    public function detect_req_type(?array $espresso_db_update = null): int
642
-    {
643
-        if ($this->_req_type === null) {
644
-            $espresso_db_update          = ! empty($espresso_db_update)
645
-                ? $espresso_db_update
646
-                : $this->fix_espresso_db_upgrade_option();
647
-            $this->_req_type             = EE_System::detect_req_type_given_activation_history(
648
-                $espresso_db_update,
649
-                'ee_espresso_activation',
650
-                espresso_version()
651
-            );
652
-            $this->_major_version_change = $this->_detect_major_version_change($espresso_db_update);
653
-            $this->request->setIsActivation($this->_req_type !== EE_System::req_type_normal);
654
-        }
655
-        return $this->_req_type;
656
-    }
657
-
658
-
659
-    /**
660
-     * Returns whether or not there was a non-micro version change (ie, change in either
661
-     * the first or second number in the version. Eg 4.9.0.rc.001 to 4.10.0.rc.000,
662
-     * but not 4.9.0.rc.0001 to 4.9.1.rc.0001
663
-     *
664
-     * @param $activation_history
665
-     * @return bool
666
-     */
667
-    private function _detect_major_version_change($activation_history): bool
668
-    {
669
-        $previous_version       = EE_System::getMostRecentlyActiveVersion($activation_history);
670
-        $previous_version_parts = explode('.', $previous_version);
671
-        $current_version_parts  = explode('.', espresso_version());
672
-        return isset(
673
-                   $previous_version_parts[0],
674
-                   $previous_version_parts[1],
675
-                   $current_version_parts[0],
676
-                   $current_version_parts[1]
677
-               ) && (
678
-                   $previous_version_parts[0] !== $current_version_parts[0]
679
-                   || $previous_version_parts[1] !== $current_version_parts[1]
680
-               );
681
-    }
682
-
683
-
684
-    /**
685
-     * Returns true if either the major or minor version of EE changed during this request.
686
-     * Eg 4.9.0.rc.001 to 4.10.0.rc.000, but not 4.9.0.rc.0001 to 4.9.1.rc.0001
687
-     *
688
-     * @return bool
689
-     */
690
-    public function is_major_version_change(): bool
691
-    {
692
-        return $this->_major_version_change;
693
-    }
694
-
695
-
696
-    /**
697
-     * Determines the request type for any ee addon, given three piece of info: the current array of activation
698
-     * histories (for core that' 'espresso_db_update' wp option); the name of the WordPress option which is temporarily
699
-     * set upon activation of the plugin (for core it's 'ee_espresso_activation'); and the version that this plugin was
700
-     * just activated to (for core that will always be espresso_version())
701
-     *
702
-     * @param array|null $activation_history               the option's value which stores the activation history for
703
-     *                                                     this
704
-     *                                                     ee plugin. for core that's 'espresso_db_update'
705
-     * @param string     $activation_indicator_option_name the name of the WordPress option that is temporarily set to
706
-     *                                                     indicate that this plugin was just activated
707
-     * @param string     $current_version                  the version that was just upgraded to (for core that will be
708
-     *                                                     espresso_version())
709
-     * @return int one of the constants on EE_System::req_type_
710
-     */
711
-    public static function detect_req_type_given_activation_history(
712
-        array $activation_history,
713
-        string $activation_indicator_option_name,
714
-        string $current_version
715
-    ): int {
716
-        $version_change = self::compareVersionWithPrevious($activation_history, $current_version);
717
-        $is_activation  = get_option($activation_indicator_option_name, false);
718
-        $req_type       = self::getRequestType($activation_history, $version_change, $is_activation);
719
-        if ($is_activation) {
720
-            // cleanup in aisle 6
721
-            delete_option($activation_indicator_option_name);
722
-        }
723
-        return $req_type;
724
-    }
725
-
726
-
727
-    /**
728
-     * @param array $activation_history
729
-     * @param int   $version_change
730
-     * @param bool  $is_activation
731
-     * @return int
732
-     * @since 5.0.0.p
733
-     */
734
-    private static function getRequestType(array $activation_history, int $version_change, bool $is_activation): int
735
-    {
736
-        // if no previous activation history exists, then this is a brand new install
737
-        if (empty($activation_history)) {
738
-            return EE_System::req_type_new_activation;
739
-        }
740
-        // current version is higher than previous version, so it's an upgrade
741
-        if ($version_change === 1) {
742
-            return EE_System::req_type_upgrade;
743
-        }
744
-        // current version is lower than previous version, so it's a downgrade
745
-        if ($version_change === -1) {
746
-            return EE_System::req_type_downgrade;
747
-        }
748
-        // version hasn't changed since last version so check if the activation indicator is set
749
-        // to determine if it's a reactivation, or just a normal request
750
-        return $is_activation
751
-            ? EE_System::req_type_reactivation
752
-            : EE_System::req_type_normal;
753
-    }
754
-
755
-
756
-    /**
757
-     * Detects if the $version_to_upgrade_to is higher than the most recent version in
758
-     * the $activation_history_for_addon
759
-     *
760
-     * @param array  $activation_history    array where keys are versions,
761
-     *                                      values are arrays of times activated (sometimes 'unknown-date')
762
-     * @param string $current_version
763
-     * @return int results of version_compare( $version_to_upgrade_to, $most_recently_active_version ).
764
-     *                                      -1 if $version_to_upgrade_to is LOWER (downgrade);
765
-     *                                      0 if $version_to_upgrade_to MATCHES (reactivation or normal request);
766
-     *                                      1 if $version_to_upgrade_to is HIGHER (upgrade) ;
767
-     */
768
-    private static function compareVersionWithPrevious(array $activation_history, string $current_version): int
769
-    {
770
-        // find the most recently-activated version
771
-        $most_recently_active_version = EE_System::getMostRecentlyActiveVersion($activation_history);
772
-        return version_compare($current_version, $most_recently_active_version);
773
-    }
774
-
775
-
776
-    /**
777
-     * Gets the most recently active version listed in the activation history,
778
-     * and if none are found (ie, it's a brand new install) returns '0.0.0.dev.000'.
779
-     *
780
-     * @param array|null $activation_history (keys are versions, values are arrays of times activated,
781
-     *                                       sometimes containing 'unknown-date'
782
-     * @return string
783
-     */
784
-    private static function getMostRecentlyActiveVersion(?array $activation_history): string
785
-    {
786
-        $most_recent_activation_date  = '1970-01-01 00:00:00';
787
-        $most_recently_active_version = '0.0.0.dev.000';
788
-        if (is_array($activation_history)) {
789
-            foreach ($activation_history as $version => $activation_dates) {
790
-                // check there is a record of when this version was activated.
791
-                // Otherwise, mark it as unknown
792
-                if (! $activation_dates) {
793
-                    $activation_dates = ['unknown-date'];
794
-                }
795
-                $activation_dates = is_string($activation_dates)
796
-                    ? [$activation_dates]
797
-                    : $activation_dates;
798
-                foreach ($activation_dates as $activation_date) {
799
-                    if ($activation_date !== 'unknown-date' && $activation_date > $most_recent_activation_date) {
800
-                        $most_recently_active_version = $version;
801
-                        $most_recent_activation_date  = $activation_date;
802
-                    }
803
-                }
804
-            }
805
-        }
806
-        return $most_recently_active_version;
807
-    }
808
-
809
-
810
-    /**
811
-     * This redirects to the about EE page after activation
812
-     *
813
-     * @return void
814
-     */
815
-    public function redirect_to_about_ee()
816
-    {
817
-        $notices = EE_Error::get_notices(false);
818
-        // if current user is an admin and it's not an ajax or rest request
819
-        if (
820
-            ! isset($notices['errors'])
821
-            && $this->request->isAdmin()
822
-            && apply_filters(
823
-                'FHEE__EE_System__redirect_to_about_ee__do_redirect',
824
-                $this->capabilities->current_user_can('manage_options', 'espresso_about_default')
825
-            )
826
-        ) {
827
-            $query_params = ['page' => 'espresso_about'];
828
-            if (EE_System::instance()->detect_req_type() === EE_System::req_type_new_activation) {
829
-                $query_params['new_activation'] = true;
830
-            }
831
-            if (EE_System::instance()->detect_req_type() === EE_System::req_type_reactivation) {
832
-                $query_params['reactivation'] = true;
833
-            }
834
-            $url = add_query_arg($query_params, admin_url('admin.php'));
835
-            EEH_URL::safeRedirectAndExit($url);
836
-        }
837
-    }
838
-
839
-
840
-    /**
841
-     * load_core_configuration
842
-     * this is hooked into 'AHEE__EE_Bootstrap__load_core_configuration'
843
-     * which runs during the WP 'plugins_loaded' action at priority 5
844
-     *
845
-     * @return void
846
-     * @throws ReflectionException
847
-     * @throws Exception
848
-     */
849
-    public function load_core_configuration()
850
-    {
851
-        do_action('AHEE__EE_System__load_core_configuration__begin', $this);
852
-        $this->loader->getShared('EE_Load_Textdomain');
853
-        // load textdomain
854
-        EE_Load_Textdomain::load_textdomain();
855
-        // load and setup EE_Config and EE_Network_Config
856
-        $config = $this->loader->getShared('EE_Config');
857
-        $this->loader->getShared('EE_Network_Config');
858
-        // setup autoloaders
859
-        // enable logging?
860
-        $this->loader->getShared('EventEspresso\core\services\orm\TrashLogger');
861
-        if ($config->admin->use_remote_logging) {
862
-            $this->loader->getShared('EE_Log');
863
-        }
864
-        // check for activation errors
865
-        $activation_errors = get_option('ee_plugin_activation_errors', false);
866
-        if ($activation_errors) {
867
-            EE_Error::add_error($activation_errors, __FILE__, __FUNCTION__, __LINE__);
868
-            update_option('ee_plugin_activation_errors', false);
869
-        }
870
-        // get model names
871
-        $this->_parse_model_names();
872
-        // configure custom post type definitions
873
-        $this->loader->getShared('EventEspresso\core\domain\entities\custom_post_types\CustomTaxonomyDefinitions');
874
-        $this->loader->getShared('EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions');
875
-        do_action('AHEE__EE_System__load_core_configuration__complete', $this);
876
-    }
877
-
878
-
879
-    /**
880
-     * cycles through all of the models/*.model.php files, and assembles an array of model names
881
-     *
882
-     * @return void
883
-     * @throws ReflectionException
884
-     */
885
-    private function _parse_model_names()
886
-    {
887
-        // get all the files in the EE_MODELS folder that end in .model.php
888
-        $models                 = glob(EE_MODELS . '*.model.php');
889
-        $model_names            = [];
890
-        $non_abstract_db_models = [];
891
-        foreach ($models as $model) {
892
-            // get model classname
893
-            $classname       = EEH_File::get_classname_from_filepath_with_standard_filename($model);
894
-            $short_name      = str_replace('EEM_', '', $classname);
895
-            $reflectionClass = new ReflectionClass($classname);
896
-            if ($reflectionClass->isSubclassOf('EEM_Base') && ! $reflectionClass->isAbstract()) {
897
-                $non_abstract_db_models[ $short_name ] = $classname;
898
-            }
899
-            $model_names[ $short_name ] = $classname;
900
-        }
901
-        $this->registry->models                 = apply_filters('FHEE__EE_System__parse_model_names', $model_names);
902
-        $this->registry->non_abstract_db_models = apply_filters(
903
-            'FHEE__EE_System__parse_implemented_model_names',
904
-            $non_abstract_db_models
905
-        );
906
-    }
907
-
908
-
909
-    /**
910
-     * @throws Exception
911
-     * @since 4.9.71.p
912
-     */
913
-    public function loadRouteMatchSpecifications()
914
-    {
915
-        try {
916
-            $this->loader->getShared('EventEspresso\core\services\routing\RouteMatchSpecificationManager');
917
-            $this->loader->getShared('EventEspresso\core\services\routing\RouteCollection');
918
-            $this->router->loadPrimaryRoutes();
919
-        } catch (Exception $exception) {
920
-            new ExceptionStackTraceDisplay($exception);
921
-        }
922
-        do_action('AHEE__EE_System__loadRouteMatchSpecifications');
923
-    }
924
-
925
-
926
-    /**
927
-     * loading CPT related classes earlier so that their definitions are available
928
-     * but not performing any actual registration with WP core until load_CPTs_and_session() is called
929
-     *
930
-     * @since   4.10.21.p
931
-     */
932
-    public function loadCustomPostTypes()
933
-    {
934
-        $this->register_custom_taxonomies     = $this->loader->getShared(
935
-            'EventEspresso\core\domain\services\custom_post_types\RegisterCustomTaxonomies'
936
-        );
937
-        $this->register_custom_post_types     = $this->loader->getShared(
938
-            'EventEspresso\core\domain\services\custom_post_types\RegisterCustomPostTypes'
939
-        );
940
-        $this->register_custom_taxonomy_terms = $this->loader->getShared(
941
-            'EventEspresso\core\domain\services\custom_post_types\RegisterCustomTaxonomyTerms'
942
-        );
943
-        // integrate WP_Query with the EE models
944
-        $this->loader->getShared('EE_CPT_Strategy');
945
-        // load legacy EE_Request_Handler in case add-ons still need it
946
-        $this->loader->getShared('EE_Request_Handler');
947
-    }
948
-
949
-
950
-    /**
951
-     * register_shortcodes_modules_and_widgets
952
-     * generate lists of shortcodes and modules, then verify paths and classes
953
-     * This is hooked into 'AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets'
954
-     * which runs during the WP 'plugins_loaded' action at priority 7
955
-     *
956
-     * @access public
957
-     * @return void
958
-     * @throws Exception
959
-     */
960
-    public function register_shortcodes_modules_and_widgets()
961
-    {
962
-        $this->router->registerShortcodesModulesAndWidgets();
963
-        do_action('AHEE__EE_System__register_shortcodes_modules_and_widgets');
964
-        // check for addons using old hook point
965
-        if (has_action('AHEE__EE_System__register_shortcodes_modules_and_addons')) {
966
-            $this->_incompatible_addon_error();
967
-        }
968
-    }
969
-
970
-
971
-    /**
972
-     * _incompatible_addon_error
973
-     *
974
-     * @access public
975
-     * @return void
976
-     */
977
-    private function _incompatible_addon_error()
978
-    {
979
-        // get array of classes hooking into here
980
-        $class_names = WordPressHooks::getClassNamesForAllCallbacksOnHook(
981
-            'AHEE__EE_System__register_shortcodes_modules_and_addons'
982
-        );
983
-        if (! empty($class_names)) {
984
-            $msg = esc_html__(
985
-                'The following plugins, addons, or modules appear to be incompatible with this version of Event Espresso and were automatically deactivated to avoid fatal errors:',
986
-                'event_espresso'
987
-            );
988
-            $msg .= '<ul>';
989
-            foreach ($class_names as $class_name) {
990
-                $msg .= '<li><b>Event Espresso - '
991
-                        . str_replace(
992
-                            ['EE_', 'EEM_', 'EED_', 'EES_', 'EEW_'],
993
-                            '',
994
-                            $class_name
995
-                        ) . '</b></li>';
996
-            }
997
-            $msg .= '</ul>';
998
-            $msg .= esc_html__(
999
-                'Compatibility issues can be avoided and/or resolved by keeping addons and plugins updated to the latest version.',
1000
-                'event_espresso'
1001
-            );
1002
-            // save list of incompatible addons to wp-options for later use
1003
-            add_option('ee_incompatible_addons', $class_names, '', 'no');
1004
-            if (is_admin()) {
1005
-                EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1006
-            }
1007
-        }
1008
-    }
1009
-
1010
-
1011
-    /**
1012
-     * brew_espresso
1013
-     * begins the process of setting hooks for initializing EE in the correct order
1014
-     * This is happening on the 'AHEE__EE_Bootstrap__brew_espresso' hook point
1015
-     * which runs during the WP 'plugins_loaded' action at priority 9
1016
-     *
1017
-     * @return void
1018
-     * @throws Exception
1019
-     */
1020
-    public function brew_espresso()
1021
-    {
1022
-        do_action('AHEE__EE_System__brew_espresso__begin', $this);
1023
-        // load some final core systems
1024
-        add_action('init', [$this, 'set_hooks_for_core'], 1);
1025
-        add_action('init', [$this, 'perform_activations_upgrades_and_migrations'], 3);
1026
-        add_action('init', [$this, 'load_CPTs_and_session'], 5);
1027
-        add_action('init', [$this, 'load_controllers'], 7);
1028
-        add_action('init', [$this, 'core_loaded_and_ready'], 9);
1029
-        add_action('init', [$this, 'initialize'], 10);
1030
-        add_action('init', [$this, 'initialize_last'], 100);
1031
-        $this->router->brewEspresso();
1032
-        $this->loader->getShared('EventEspresso\PaymentMethods\Manager');
1033
-        $this->loader->getShared('EE_Payment_Method_Manager');
1034
-        do_action('AHEE__EE_System__brew_espresso__complete', $this);
1035
-    }
1036
-
1037
-
1038
-    /**
1039
-    /**
1040
-     *    set_hooks_for_core
1041
-     *
1042
-     * @access public
1043
-     * @return    void
1044
-     * @throws EE_Error
1045
-     */
1046
-    public function set_hooks_for_core()
1047
-    {
1048
-        $this->_deactivate_incompatible_addons();
1049
-        do_action('AHEE__EE_System__set_hooks_for_core');
1050
-        $this->loader->getShared('EventEspresso\core\domain\values\session\SessionLifespan');
1051
-        // caps need to be initialized on every request so that capability maps are set.
1052
-        // @see https://events.codebasehq.com/projects/event-espresso/tickets/8674
1053
-        $this->capabilities->init_caps();
1054
-    }
1055
-
1056
-
1057
-    /**
1058
-     * Using the information gathered in EE_System::_incompatible_addon_error,
1059
-     * deactivates any addons considered incompatible with the current version of EE
1060
-     */
1061
-    private function _deactivate_incompatible_addons()
1062
-    {
1063
-        $incompatible_addons = get_option('ee_incompatible_addons', []);
1064
-        if (! empty($incompatible_addons)) {
1065
-            $active_plugins = get_option('active_plugins', []);
1066
-            foreach ($active_plugins as $active_plugin) {
1067
-                foreach ($incompatible_addons as $incompatible_addon) {
1068
-                    if (strpos($active_plugin, $incompatible_addon) !== false) {
1069
-                        $this->request->unSetRequestParams(['activate'], true);
1070
-                        espresso_deactivate_plugin($active_plugin);
1071
-                    }
1072
-                }
1073
-            }
1074
-        }
1075
-    }
1076
-
1077
-
1078
-    /**
1079
-     *    perform_activations_upgrades_and_migrations
1080
-     *
1081
-     * @access public
1082
-     * @return    void
1083
-     */
1084
-    public function perform_activations_upgrades_and_migrations()
1085
-    {
1086
-        do_action('AHEE__EE_System__perform_activations_upgrades_and_migrations');
1087
-    }
1088
-
1089
-
1090
-    /**
1091
-     * @return void
1092
-     * @throws DomainException
1093
-     */
1094
-    public function load_CPTs_and_session()
1095
-    {
1096
-        do_action('AHEE__EE_System__load_CPTs_and_session__start');
1097
-        $this->register_custom_taxonomies->registerCustomTaxonomies();
1098
-        $this->register_custom_post_types->registerCustomPostTypes();
1099
-        $this->register_custom_taxonomy_terms->registerCustomTaxonomyTerms();
1100
-        // load legacy Custom Post Types and Taxonomies
1101
-        $this->loader->getShared('EE_Register_CPTs');
1102
-        do_action('AHEE__EE_System__load_CPTs_and_session__complete');
1103
-    }
1104
-
1105
-
1106
-    /**
1107
-     * load_controllers
1108
-     * this is the best place to load any additional controllers that needs access to EE core.
1109
-     * it is expected that all basic core EE systems, that are not dependant on the current request are loaded at this
1110
-     * time
1111
-     *
1112
-     * @access public
1113
-     * @return void
1114
-     * @throws Exception
1115
-     */
1116
-    public function load_controllers()
1117
-    {
1118
-        do_action('AHEE__EE_System__load_controllers__start');
1119
-        $this->router->loadControllers();
1120
-        do_action('AHEE__EE_System__load_controllers__complete');
1121
-    }
1122
-
1123
-
1124
-    /**
1125
-     * core_loaded_and_ready
1126
-     * all of the basic EE core should be loaded at this point and available regardless of M-Mode
1127
-     *
1128
-     * @access public
1129
-     * @return void
1130
-     * @throws Exception
1131
-     */
1132
-    public function core_loaded_and_ready()
1133
-    {
1134
-        $this->router->coreLoadedAndReady();
1135
-        do_action('AHEE__EE_System__core_loaded_and_ready');
1136
-        // always load template tags, because it's faster than checking if it's a front-end request, and many page
1137
-        // builders require these even on the front-end
1138
-        require_once EE_PUBLIC . 'template_tags.php';
1139
-        do_action('AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons');
1140
-    }
1141
-
1142
-
1143
-    /**
1144
-     * initialize
1145
-     * this is the best place to begin initializing client code
1146
-     *
1147
-     * @access public
1148
-     * @return void
1149
-     */
1150
-    public function initialize()
1151
-    {
1152
-        do_action('AHEE__EE_System__initialize');
1153
-        add_filter(
1154
-            'safe_style_css',
1155
-            function ($styles) {
1156
-                $styles[] = 'display';
1157
-                $styles[] = 'visibility';
1158
-                $styles[] = 'position';
1159
-                $styles[] = 'top';
1160
-                $styles[] = 'right';
1161
-                $styles[] = 'bottom';
1162
-                $styles[] = 'left';
1163
-                $styles[] = 'resize';
1164
-                $styles[] = 'max-width';
1165
-                $styles[] = 'max-height';
1166
-                return $styles;
1167
-            }
1168
-        );
1169
-    }
1170
-
1171
-
1172
-    /**
1173
-     * initialize_last
1174
-     * this is run really late during the WP init hook point, and ensures that mostly everything else that needs to
1175
-     * initialize has done so
1176
-     *
1177
-     * @access public
1178
-     * @return void
1179
-     * @throws Exception
1180
-     */
1181
-    public function initialize_last()
1182
-    {
1183
-        $this->router->initializeLast();
1184
-        do_action('AHEE__EE_System__initialize_last');
1185
-        /** @var EventEspresso\core\domain\services\custom_post_types\RewriteRules $rewrite_rules */
1186
-        $rewrite_rules = $this->loader->getShared(
1187
-            'EventEspresso\core\domain\services\custom_post_types\RewriteRules'
1188
-        );
1189
-        $rewrite_rules->flushRewriteRules();
1190
-        add_action('admin_bar_init', [$this, 'addEspressoToolbar']);
1191
-    }
1192
-
1193
-
1194
-    /**
1195
-     * @return void
1196
-     */
1197
-    public function addEspressoToolbar()
1198
-    {
1199
-        $this->loader->getShared(
1200
-            'EventEspresso\core\domain\services\admin\AdminToolBar',
1201
-            [$this->capabilities]
1202
-        );
1203
-    }
1204
-
1205
-
1206
-    /**
1207
-     * do_not_cache
1208
-     * sets no cache headers and defines no cache constants for WP plugins
1209
-     *
1210
-     * @access public
1211
-     * @return void
1212
-     */
1213
-    public static function do_not_cache()
1214
-    {
1215
-        // set no cache constants
1216
-        if (! defined('DONOTCACHEPAGE')) {
1217
-            define('DONOTCACHEPAGE', true);
1218
-        }
1219
-        if (! defined('DONOTCACHCEOBJECT')) {
1220
-            define('DONOTCACHCEOBJECT', true);
1221
-        }
1222
-        if (! defined('DONOTCACHEDB')) {
1223
-            define('DONOTCACHEDB', true);
1224
-        }
1225
-        // add no cache headers
1226
-        add_action('send_headers', ['EE_System', 'nocache_headers'], 10);
1227
-        // plus a little extra for nginx and Google Chrome
1228
-        add_filter('nocache_headers', ['EE_System', 'extra_nocache_headers'], 10, 1);
1229
-        // prevent browsers from prefetching of the rel='next' link, because it may contain content that interferes with the registration process
1230
-        remove_action('wp_head', 'adjacent_posts_rel_link_wp_head');
1231
-    }
1232
-
1233
-
1234
-    /**
1235
-     *    extra_nocache_headers
1236
-     *
1237
-     * @access    public
1238
-     * @param $headers
1239
-     * @return    array
1240
-     */
1241
-    public static function extra_nocache_headers($headers): array
1242
-    {
1243
-        // for NGINX
1244
-        $headers['X-Accel-Expires'] = 0;
1245
-        // plus extra for Google Chrome since it doesn't seem to respect "no-cache", but WILL respect "no-store"
1246
-        $headers['Cache-Control'] = 'no-store, no-cache, must-revalidate, max-age=0';
1247
-        return $headers;
1248
-    }
1249
-
1250
-
1251
-    /**
1252
-     *    nocache_headers
1253
-     *
1254
-     * @access    public
1255
-     * @return    void
1256
-     */
1257
-    public static function nocache_headers()
1258
-    {
1259
-        nocache_headers();
1260
-    }
1261
-
1262
-
1263
-    /**
1264
-     * simply hooks into "wp_list_pages_exclude" filter (for wp_list_pages method) and makes sure EE critical pages are
1265
-     * never returned with the function.
1266
-     *
1267
-     * @param array $exclude_array any existing pages being excluded are in this array.
1268
-     * @return array
1269
-     */
1270
-    public function remove_pages_from_wp_list_pages(array $exclude_array): array
1271
-    {
1272
-        return array_merge($exclude_array, $this->registry->CFG->core->get_critical_pages_array());
1273
-    }
28
+	/**
29
+	 * indicates this is a 'normal' request. Ie, not activation, nor upgrade, nor activation.
30
+	 * So examples of this would be a normal GET request on the frontend or backend, or a POST, etc
31
+	 */
32
+	const req_type_normal = 0;
33
+
34
+	/**
35
+	 * Indicates this is a brand new installation of EE so we should install
36
+	 * tables and default data etc
37
+	 */
38
+	const req_type_new_activation = 1;
39
+
40
+	/**
41
+	 * we've detected that EE has been reactivated (or EE was activated during maintenance mode,
42
+	 * and we just exited maintenance mode). We MUST check the database is setup properly
43
+	 * and that default data is setup too
44
+	 */
45
+	const req_type_reactivation = 2;
46
+
47
+	/**
48
+	 * indicates that EE has been upgraded since its previous request.
49
+	 * We may have data migration scripts to call and will want to trigger maintenance mode
50
+	 */
51
+	const req_type_upgrade = 3;
52
+
53
+	/**
54
+	 * TODO  will detect that EE has been DOWNGRADED. We probably don't want to run in this case...
55
+	 */
56
+	const req_type_downgrade = 4;
57
+
58
+	/**
59
+	 * @deprecated since version 4.6.0.dev.006
60
+	 * Now whenever a new_activation is detected the request type is still just
61
+	 * new_activation (same for reactivation, upgrade, downgrade etc), but if we're in maintenance mode
62
+	 * EE_System::initialize_db_if_no_migrations_required and EE_Addon::initialize_db_if_no_migrations_required
63
+	 * will instead enqueue that EE plugin's db initialization for when we're taken out of maintenance mode.
64
+	 * (Specifically, when the migration manager indicates migrations are finished
65
+	 * EE_Data_Migration_Manager::initialize_db_for_enqueued_ee_plugins() will be called)
66
+	 */
67
+	const req_type_activation_but_not_installed = 5;
68
+
69
+	/**
70
+	 * option prefix for recording the activation history (like core's "espresso_db_update") of addons
71
+	 */
72
+	const addon_activation_history_option_prefix = 'ee_addon_activation_history_';
73
+
74
+	/**
75
+	 * @var AddonManager $addon_manager
76
+	 */
77
+	private $addon_manager;
78
+
79
+	/**
80
+	 * @var EE_System $_instance
81
+	 */
82
+	private static $_instance;
83
+
84
+	/**
85
+	 * @var EE_Registry $registry
86
+	 */
87
+	private $registry;
88
+
89
+	/**
90
+	 * @var LoaderInterface $loader
91
+	 */
92
+	private $loader;
93
+
94
+	/**
95
+	 * @var EE_Capabilities $capabilities
96
+	 */
97
+	private $capabilities;
98
+
99
+	/**
100
+	 * @var EE_Maintenance_Mode $maintenance_mode
101
+	 */
102
+	private $maintenance_mode;
103
+
104
+	/**
105
+	 * @var RequestInterface $request
106
+	 */
107
+	private $request;
108
+
109
+	/**
110
+	 * Stores which type of request this is, options being one of the constants on EE_System starting with req_type_*.
111
+	 * It can be a brand-new activation, a reactivation, an upgrade, a downgrade, or a normal request.
112
+	 *
113
+	 * @var int $_req_type
114
+	 */
115
+	private $_req_type;
116
+
117
+	/**
118
+	 * Whether or not there was a non-micro version change in EE core version during this request
119
+	 *
120
+	 * @var boolean $_major_version_change
121
+	 */
122
+	private $_major_version_change = false;
123
+
124
+	/**
125
+	 * @var Router $router
126
+	 */
127
+	private $router;
128
+
129
+	/**
130
+	 * @param EventEspresso\core\domain\services\custom_post_types\RegisterCustomPostTypes
131
+	 */
132
+	private $register_custom_post_types;
133
+
134
+	/**
135
+	 * @param EventEspresso\core\domain\services\custom_post_types\RegisterCustomTaxonomies
136
+	 */
137
+	private $register_custom_taxonomies;
138
+
139
+	/**
140
+	 * @param EventEspresso\core\domain\services\custom_post_types\RegisterCustomTaxonomyTerms
141
+	 */
142
+	private $register_custom_taxonomy_terms;
143
+
144
+
145
+	/**
146
+	 * @singleton method used to instantiate class object
147
+	 * @param LoaderInterface|null     $loader
148
+	 * @param EE_Maintenance_Mode|null $maintenance_mode
149
+	 * @param EE_Registry|null         $registry
150
+	 * @param RequestInterface|null    $request
151
+	 * @param Router|null              $router
152
+	 * @return EE_System
153
+	 */
154
+	public static function instance(
155
+		LoaderInterface $loader = null,
156
+		EE_Maintenance_Mode $maintenance_mode = null,
157
+		EE_Registry $registry = null,
158
+		RequestInterface $request = null,
159
+		Router $router = null
160
+	): EE_System {
161
+		// check if class object is instantiated
162
+		if (! self::$_instance instanceof EE_System) {
163
+			self::$_instance = new self($loader, $maintenance_mode, $registry, $request, $router);
164
+		}
165
+		return self::$_instance;
166
+	}
167
+
168
+
169
+	/**
170
+	 * resets the instance and returns it
171
+	 *
172
+	 * @return EE_System
173
+	 */
174
+	public static function reset(): EE_System
175
+	{
176
+		self::$_instance->_req_type = null;
177
+		// make sure none of the old hooks are left hanging around
178
+		remove_all_actions('AHEE__EE_System__perform_activations_upgrades_and_migrations');
179
+		// we need to reset the migration manager in order for it to detect DMSs properly
180
+		EE_Data_Migration_Manager::reset();
181
+		self::instance()->detect_activations_or_upgrades();
182
+		self::instance()->perform_activations_upgrades_and_migrations();
183
+		return self::instance();
184
+	}
185
+
186
+
187
+	/**
188
+	 * sets hooks for running rest of system
189
+	 * provides "AHEE__EE_System__construct__complete" hook for EE Addons to use as their starting point
190
+	 * starting EE Addons from any other point may lead to problems
191
+	 *
192
+	 * @param LoaderInterface     $loader
193
+	 * @param EE_Maintenance_Mode $maintenance_mode
194
+	 * @param EE_Registry         $registry
195
+	 * @param RequestInterface    $request
196
+	 * @param Router              $router
197
+	 */
198
+	private function __construct(
199
+		LoaderInterface $loader,
200
+		EE_Maintenance_Mode $maintenance_mode,
201
+		EE_Registry $registry,
202
+		RequestInterface $request,
203
+		Router $router
204
+	) {
205
+		$this->registry         = $registry;
206
+		$this->loader           = $loader;
207
+		$this->request          = $request;
208
+		$this->router           = $router;
209
+		$this->maintenance_mode = $maintenance_mode;
210
+		do_action('AHEE__EE_System__construct__begin', $this);
211
+		add_action(
212
+			'AHEE__EE_Bootstrap__load_espresso_addons',
213
+			[$this, 'loadWpGraphQL'],
214
+			3
215
+		);
216
+		add_action(
217
+			'AHEE__EE_Bootstrap__load_espresso_addons',
218
+			[$this, 'loadCapabilities'],
219
+			5
220
+		);
221
+		add_action(
222
+			'AHEE__EE_Bootstrap__load_espresso_addons',
223
+			[$this, 'loadCommandBus'],
224
+			7
225
+		);
226
+		add_action(
227
+			'AHEE__EE_Bootstrap__load_espresso_addons',
228
+			[$this, 'loadPluginApi'],
229
+			9
230
+		);
231
+		// give caff stuff a chance to play during the activation process too.
232
+		add_action(
233
+			'AHEE__EE_Bootstrap__load_espresso_addons',
234
+			[$this, 'brewCaffeinated'],
235
+			9
236
+		);
237
+		// allow addons to load first so that they can register autoloaders, set hooks for running DMS's, etc
238
+		add_action(
239
+			'AHEE__EE_Bootstrap__load_espresso_addons',
240
+			[$this, 'load_espresso_addons']
241
+		);
242
+		// when an ee addon is activated, we want to call the core hook(s) again
243
+		// because the newly-activated addon didn't get a chance to run at all
244
+		add_action('activate_plugin', [$this, 'load_espresso_addons'], 1);
245
+		// detect whether install or upgrade
246
+		add_action(
247
+			'AHEE__EE_Bootstrap__detect_activations_or_upgrades',
248
+			[$this, 'detect_activations_or_upgrades'],
249
+			3
250
+		);
251
+		// load EE_Config, EE_Textdomain, etc
252
+		add_action(
253
+			'AHEE__EE_Bootstrap__load_core_configuration',
254
+			[$this, 'load_core_configuration'],
255
+			5
256
+		);
257
+		// load specifications for matching routes to current request
258
+		add_action(
259
+			'AHEE__EE_Bootstrap__load_core_configuration',
260
+			[$this, 'loadRouteMatchSpecifications']
261
+		);
262
+		// load specifications for custom post types
263
+		add_action(
264
+			'AHEE__EE_Bootstrap__load_core_configuration',
265
+			[$this, 'loadCustomPostTypes']
266
+		);
267
+		// load specifications for custom post types
268
+		add_action(
269
+			'AHEE__EE_Bootstrap__load_core_configuration',
270
+			[$this, 'loadCustomPostTypes']
271
+		);
272
+		// load EE_Config, EE_Textdomain, etc
273
+		add_action(
274
+			'AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets',
275
+			[$this, 'register_shortcodes_modules_and_widgets'],
276
+			7
277
+		);
278
+		// you wanna get going? I wanna get going... let's get going!
279
+		add_action(
280
+			'AHEE__EE_Bootstrap__brew_espresso',
281
+			[$this, 'brew_espresso'],
282
+			9
283
+		);
284
+		// other housekeeping
285
+		// exclude EE critical pages from wp_list_pages
286
+		add_filter(
287
+			'wp_list_pages_excludes',
288
+			[$this, 'remove_pages_from_wp_list_pages'],
289
+			10
290
+		);
291
+		// ALL EE Addons should use the following hook point to attach their initial setup too
292
+		// it's extremely important for EE Addons to register any class autoloaders so that they can be available when the EE_Config loads
293
+		do_action('AHEE__EE_System__construct__complete', $this);
294
+	}
295
+
296
+
297
+	/**
298
+	 * load and setup EE_Capabilities
299
+	 *
300
+	 * @return void
301
+	 */
302
+	public function loadWpGraphQL()
303
+	{
304
+		espressoLoadWpGraphQL();
305
+	}
306
+
307
+
308
+	/**
309
+	 * load and setup EE_Capabilities
310
+	 *
311
+	 * @return void
312
+	 */
313
+	public function loadCapabilities()
314
+	{
315
+		$this->capabilities = $this->loader->getShared('EE_Capabilities');
316
+	}
317
+
318
+
319
+	/**
320
+	 * create and cache the CommandBus, and also add middleware
321
+	 * The CapChecker middleware requires the use of EE_Capabilities
322
+	 * which is why we need to load the CommandBus after Caps are set up
323
+	 * CommandBus middleware operate FIFO - First In First Out
324
+	 * so LocateMovedCommands will run first in order to return any new commands
325
+	 *
326
+	 * @return void
327
+	 */
328
+	public function loadCommandBus()
329
+	{
330
+		$this->loader->getShared(
331
+			'CommandBusInterface',
332
+			[
333
+				null,
334
+				apply_filters(
335
+					'FHEE__EE_Load_Espresso_Core__handle_request__CommandBus_middleware',
336
+					[
337
+						$this->loader->getShared('EventEspresso\core\services\commands\middleware\LocateMovedCommands'),
338
+						$this->loader->getShared('EventEspresso\core\services\commands\middleware\CapChecker'),
339
+						$this->loader->getShared('EventEspresso\core\services\commands\middleware\AddActionHook'),
340
+					]
341
+				),
342
+			]
343
+		);
344
+	}
345
+
346
+
347
+	/**
348
+	 * @return void
349
+	 * @throws Exception
350
+	 */
351
+	public function loadPluginApi()
352
+	{
353
+		$this->addon_manager = $this->loader->getShared(AddonManager::class);
354
+		$this->addon_manager->initialize();
355
+		$this->loader->getShared('EE_Request_Handler');
356
+	}
357
+
358
+
359
+	/**
360
+	 * The purpose of this method is to simply check for a file named "caffeinated/brewing_regular.php" for any hooks
361
+	 * that need to be setup before our EE_System launches.
362
+	 *
363
+	 * @return void
364
+	 * @throws DomainException
365
+	 * @throws InvalidArgumentException
366
+	 * @throws InvalidDataTypeException
367
+	 * @throws InvalidInterfaceException
368
+	 * @throws InvalidClassException
369
+	 * @throws InvalidFilePathException
370
+	 * @throws EE_Error
371
+	 */
372
+	public function brewCaffeinated()
373
+	{
374
+		static $brew;
375
+		/** @var Domain $domain */
376
+		$domain = DomainFactory::getEventEspressoCoreDomain();
377
+		if ($domain->isCaffeinated() && ! $brew instanceof EE_Brewing_Regular) {
378
+			require_once EE_CAFF_PATH . 'brewing_regular.php';
379
+			/** @var EE_Brewing_Regular $brew */
380
+			$brew = LoaderFactory::getLoader()->getShared(EE_Brewing_Regular::class);
381
+			$brew->initializePUE();
382
+			add_action(
383
+				'AHEE__EE_System__load_core_configuration__begin',
384
+				[$brew, 'caffeinated']
385
+			);
386
+		}
387
+	}
388
+
389
+
390
+	/**
391
+	 * load_espresso_addons
392
+	 * allow addons to load first so that they can set hooks for running DMS's, etc
393
+	 * this is hooked into both:
394
+	 *    'AHEE__EE_Bootstrap__load_core_configuration'
395
+	 *        which runs during the WP 'plugins_loaded' action at priority 5
396
+	 *    and the WP 'activate_plugin' hook point
397
+	 *
398
+	 * @return void
399
+	 * @throws Exception
400
+	 */
401
+	public function load_espresso_addons()
402
+	{
403
+		// looking for hooks? they've been moved into the AddonManager to maintain compatibility
404
+		$this->addon_manager->loadAddons();
405
+	}
406
+
407
+
408
+	/**
409
+	 * detect_activations_or_upgrades
410
+	 * Checks for activation or upgrade of core first;
411
+	 * then also checks if any registered addons have been activated or upgraded
412
+	 * This is hooked into 'AHEE__EE_Bootstrap__detect_activations_or_upgrades'
413
+	 * which runs during the WP 'plugins_loaded' action at priority 3
414
+	 *
415
+	 * @access public
416
+	 * @return void
417
+	 */
418
+	public function detect_activations_or_upgrades()
419
+	{
420
+		// first off: let's make sure to handle core
421
+		$this->detect_if_activation_or_upgrade();
422
+		foreach ($this->registry->addons as $addon) {
423
+			if ($addon instanceof EE_Addon) {
424
+				// detect teh request type for that addon
425
+				$addon->detect_req_type();
426
+			}
427
+		}
428
+	}
429
+
430
+
431
+	/**
432
+	 * detect_if_activation_or_upgrade
433
+	 * Takes care of detecting whether this is a brand new install or code upgrade,
434
+	 * and either setting up the DB or setting up maintenance mode etc.
435
+	 *
436
+	 * @access public
437
+	 * @return void
438
+	 */
439
+	public function detect_if_activation_or_upgrade()
440
+	{
441
+		do_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin');
442
+		// check if db has been updated, or if its a brand-new installation
443
+		$espresso_db_update = $this->fix_espresso_db_upgrade_option();
444
+		$request_type       = $this->detect_req_type($espresso_db_update);
445
+		switch ($request_type) {
446
+			case EE_System::req_type_new_activation:
447
+				do_action('AHEE__EE_System__detect_if_activation_or_upgrade__new_activation');
448
+				$this->_handle_core_version_change($espresso_db_update);
449
+				break;
450
+			case EE_System::req_type_reactivation:
451
+				do_action('AHEE__EE_System__detect_if_activation_or_upgrade__reactivation');
452
+				$this->_handle_core_version_change($espresso_db_update);
453
+				break;
454
+			case EE_System::req_type_upgrade:
455
+				do_action('AHEE__EE_System__detect_if_activation_or_upgrade__upgrade');
456
+				// migrations may be required now that we've upgraded
457
+				$this->maintenance_mode->set_maintenance_mode_if_db_old();
458
+				$this->_handle_core_version_change($espresso_db_update);
459
+				break;
460
+			case EE_System::req_type_downgrade:
461
+				do_action('AHEE__EE_System__detect_if_activation_or_upgrade__downgrade');
462
+				// its possible migrations are no longer required
463
+				$this->maintenance_mode->set_maintenance_mode_if_db_old();
464
+				$this->_handle_core_version_change($espresso_db_update);
465
+				break;
466
+			case EE_System::req_type_normal:
467
+			default:
468
+				break;
469
+		}
470
+		do_action('AHEE__EE_System__detect_if_activation_or_upgrade__complete');
471
+	}
472
+
473
+
474
+	/**
475
+	 * Updates the list of installed versions and sets hooks for
476
+	 * initializing the database later during the request
477
+	 *
478
+	 * @param array $espresso_db_update
479
+	 */
480
+	private function _handle_core_version_change(array $espresso_db_update)
481
+	{
482
+		$this->update_list_of_installed_versions($espresso_db_update);
483
+		// get ready to verify the DB is ok (provided we aren't in maintenance mode, of course)
484
+		add_action(
485
+			'AHEE__EE_System__perform_activations_upgrades_and_migrations',
486
+			[$this, 'initialize_db_if_no_migrations_required']
487
+		);
488
+	}
489
+
490
+
491
+	/**
492
+	 * standardizes the wp option 'espresso_db_upgrade' which actually stores
493
+	 * information about what versions of EE have been installed and activated,
494
+	 * NOT necessarily the state of the database
495
+	 *
496
+	 * @param mixed $espresso_db_update           the value of the WordPress option.
497
+	 *                                            If not supplied, fetches it from the options table
498
+	 * @return array the correct value of 'espresso_db_upgrade', after saving it, if it needed correction
499
+	 */
500
+	private function fix_espresso_db_upgrade_option($espresso_db_update = null): array
501
+	{
502
+		do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__begin', $espresso_db_update);
503
+		if (! $espresso_db_update) {
504
+			$espresso_db_update = get_option('espresso_db_update');
505
+		}
506
+		// check that option is an array
507
+		if (! is_array($espresso_db_update)) {
508
+			// if option is FALSE, then it never existed
509
+			if ($espresso_db_update === false) {
510
+				// make $espresso_db_update an array and save option with autoload OFF
511
+				$espresso_db_update = [];
512
+				add_option('espresso_db_update', $espresso_db_update, '', 'no');
513
+			} else {
514
+				// option is NOT FALSE but also is NOT an array, so make it an array and save it
515
+				$espresso_db_update = [$espresso_db_update => []];
516
+				update_option('espresso_db_update', $espresso_db_update);
517
+			}
518
+		} else {
519
+			$corrected_db_update = [];
520
+			// if IS an array, but is it an array where KEYS are version numbers, and values are arrays?
521
+			foreach ($espresso_db_update as $should_be_version_string => $should_be_array) {
522
+				if (is_int($should_be_version_string) && ! is_array($should_be_array)) {
523
+					// the key is an int, and the value IS NOT an array
524
+					// so it must be numerically-indexed, where values are versions installed...
525
+					// fix it!
526
+					$version_string                         = $should_be_array;
527
+					$corrected_db_update[ $version_string ] = ['unknown-date'];
528
+				} else {
529
+					// ok it checks out
530
+					$corrected_db_update[ $should_be_version_string ] = $should_be_array;
531
+				}
532
+			}
533
+			$espresso_db_update = $corrected_db_update;
534
+			update_option('espresso_db_update', $espresso_db_update);
535
+		}
536
+		do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__complete', $espresso_db_update);
537
+		return ! empty($espresso_db_update)
538
+			? $espresso_db_update
539
+			: [];
540
+	}
541
+
542
+
543
+	/**
544
+	 * Does the traditional work of setting up the plugin's database and adding default data.
545
+	 * If migration script/process did not exist, this is what would happen on every activation/reactivation/upgrade.
546
+	 * NOTE: if we're in maintenance mode (which would be the case if we detect there are data
547
+	 * migration scripts that need to be run and a version change happens), enqueues core for database initialization,
548
+	 * so that it will be done when migrations are finished
549
+	 *
550
+	 * @param boolean $initialize_addons_too if true, we double-check addons' database tables etc too;
551
+	 * @param boolean $verify_schema         if true will re-check the database tables have the correct schema.
552
+	 *                                       This is a resource-intensive job
553
+	 *                                       so we prefer to only do it when necessary
554
+	 * @return void
555
+	 * @throws EE_Error
556
+	 * @throws ReflectionException
557
+	 */
558
+	public function initialize_db_if_no_migrations_required($initialize_addons_too = false, $verify_schema = true)
559
+	{
560
+		$request_type = $this->detect_req_type();
561
+		// only initialize system if we're not in maintenance mode.
562
+		if ($this->maintenance_mode->level() !== EE_Maintenance_Mode::level_2_complete_maintenance) {
563
+			/** @var EventEspresso\core\domain\services\custom_post_types\RewriteRules $rewrite_rules */
564
+			$rewrite_rules = $this->loader->getShared(
565
+				'EventEspresso\core\domain\services\custom_post_types\RewriteRules'
566
+			);
567
+			$rewrite_rules->flush();
568
+			if ($verify_schema) {
569
+				EEH_Activation::initialize_db_and_folders();
570
+			}
571
+			EEH_Activation::initialize_db_content();
572
+			EEH_Activation::system_initialization();
573
+			if ($initialize_addons_too) {
574
+				$this->initialize_addons();
575
+			}
576
+		} else {
577
+			EE_Data_Migration_Manager::instance()->enqueue_db_initialization_for('Core');
578
+		}
579
+		if (
580
+			$request_type === EE_System::req_type_new_activation
581
+			|| $request_type === EE_System::req_type_reactivation
582
+			|| (
583
+				$request_type === EE_System::req_type_upgrade
584
+				&& $this->is_major_version_change()
585
+			)
586
+		) {
587
+			add_action('AHEE__EE_System__initialize_last', [$this, 'redirect_to_about_ee'], 9);
588
+		}
589
+	}
590
+
591
+
592
+	/**
593
+	 * Initializes the db for all registered addons
594
+	 *
595
+	 * @throws EE_Error
596
+	 * @throws ReflectionException
597
+	 */
598
+	public function initialize_addons()
599
+	{
600
+		// foreach registered addon, make sure its db is up-to-date too
601
+		foreach ($this->registry->addons as $addon) {
602
+			if ($addon instanceof EE_Addon) {
603
+				$addon->initialize_db_if_no_migrations_required();
604
+			}
605
+		}
606
+	}
607
+
608
+
609
+	/**
610
+	 * Adds the current code version to the saved wp option which stores a list of all ee versions ever installed.
611
+	 *
612
+	 * @param array  $version_history
613
+	 * @param string $current_version_to_add version to be added to the version history
614
+	 * @return    boolean success as to whether or not this option was changed
615
+	 */
616
+	public function update_list_of_installed_versions($version_history = null, $current_version_to_add = null): bool
617
+	{
618
+		if (! $version_history) {
619
+			$version_history = $this->fix_espresso_db_upgrade_option($version_history);
620
+		}
621
+		if ($current_version_to_add === null) {
622
+			$current_version_to_add = espresso_version();
623
+		}
624
+		$version_history[ $current_version_to_add ][] = date('Y-m-d H:i:s', time());
625
+		// re-save
626
+		return update_option('espresso_db_update', $version_history);
627
+	}
628
+
629
+
630
+	/**
631
+	 * Detects if the current version indicated in the has existed in the list of
632
+	 * previously-installed versions of EE (espresso_db_update). Does NOT modify it (ie, no side-effect)
633
+	 *
634
+	 * @param array|null $espresso_db_update array from the wp option stored under the name 'espresso_db_update'.
635
+	 *                                       If not supplied, fetches it from the options table.
636
+	 *                                       Also, caches its result so later parts of the code can also know whether
637
+	 *                                       there's been an update or not. This way we can add the current version to
638
+	 *                                       espresso_db_update, but still know if this is a new install or not
639
+	 * @return int one of the constants on EE_System::req_type_
640
+	 */
641
+	public function detect_req_type(?array $espresso_db_update = null): int
642
+	{
643
+		if ($this->_req_type === null) {
644
+			$espresso_db_update          = ! empty($espresso_db_update)
645
+				? $espresso_db_update
646
+				: $this->fix_espresso_db_upgrade_option();
647
+			$this->_req_type             = EE_System::detect_req_type_given_activation_history(
648
+				$espresso_db_update,
649
+				'ee_espresso_activation',
650
+				espresso_version()
651
+			);
652
+			$this->_major_version_change = $this->_detect_major_version_change($espresso_db_update);
653
+			$this->request->setIsActivation($this->_req_type !== EE_System::req_type_normal);
654
+		}
655
+		return $this->_req_type;
656
+	}
657
+
658
+
659
+	/**
660
+	 * Returns whether or not there was a non-micro version change (ie, change in either
661
+	 * the first or second number in the version. Eg 4.9.0.rc.001 to 4.10.0.rc.000,
662
+	 * but not 4.9.0.rc.0001 to 4.9.1.rc.0001
663
+	 *
664
+	 * @param $activation_history
665
+	 * @return bool
666
+	 */
667
+	private function _detect_major_version_change($activation_history): bool
668
+	{
669
+		$previous_version       = EE_System::getMostRecentlyActiveVersion($activation_history);
670
+		$previous_version_parts = explode('.', $previous_version);
671
+		$current_version_parts  = explode('.', espresso_version());
672
+		return isset(
673
+				   $previous_version_parts[0],
674
+				   $previous_version_parts[1],
675
+				   $current_version_parts[0],
676
+				   $current_version_parts[1]
677
+			   ) && (
678
+				   $previous_version_parts[0] !== $current_version_parts[0]
679
+				   || $previous_version_parts[1] !== $current_version_parts[1]
680
+			   );
681
+	}
682
+
683
+
684
+	/**
685
+	 * Returns true if either the major or minor version of EE changed during this request.
686
+	 * Eg 4.9.0.rc.001 to 4.10.0.rc.000, but not 4.9.0.rc.0001 to 4.9.1.rc.0001
687
+	 *
688
+	 * @return bool
689
+	 */
690
+	public function is_major_version_change(): bool
691
+	{
692
+		return $this->_major_version_change;
693
+	}
694
+
695
+
696
+	/**
697
+	 * Determines the request type for any ee addon, given three piece of info: the current array of activation
698
+	 * histories (for core that' 'espresso_db_update' wp option); the name of the WordPress option which is temporarily
699
+	 * set upon activation of the plugin (for core it's 'ee_espresso_activation'); and the version that this plugin was
700
+	 * just activated to (for core that will always be espresso_version())
701
+	 *
702
+	 * @param array|null $activation_history               the option's value which stores the activation history for
703
+	 *                                                     this
704
+	 *                                                     ee plugin. for core that's 'espresso_db_update'
705
+	 * @param string     $activation_indicator_option_name the name of the WordPress option that is temporarily set to
706
+	 *                                                     indicate that this plugin was just activated
707
+	 * @param string     $current_version                  the version that was just upgraded to (for core that will be
708
+	 *                                                     espresso_version())
709
+	 * @return int one of the constants on EE_System::req_type_
710
+	 */
711
+	public static function detect_req_type_given_activation_history(
712
+		array $activation_history,
713
+		string $activation_indicator_option_name,
714
+		string $current_version
715
+	): int {
716
+		$version_change = self::compareVersionWithPrevious($activation_history, $current_version);
717
+		$is_activation  = get_option($activation_indicator_option_name, false);
718
+		$req_type       = self::getRequestType($activation_history, $version_change, $is_activation);
719
+		if ($is_activation) {
720
+			// cleanup in aisle 6
721
+			delete_option($activation_indicator_option_name);
722
+		}
723
+		return $req_type;
724
+	}
725
+
726
+
727
+	/**
728
+	 * @param array $activation_history
729
+	 * @param int   $version_change
730
+	 * @param bool  $is_activation
731
+	 * @return int
732
+	 * @since 5.0.0.p
733
+	 */
734
+	private static function getRequestType(array $activation_history, int $version_change, bool $is_activation): int
735
+	{
736
+		// if no previous activation history exists, then this is a brand new install
737
+		if (empty($activation_history)) {
738
+			return EE_System::req_type_new_activation;
739
+		}
740
+		// current version is higher than previous version, so it's an upgrade
741
+		if ($version_change === 1) {
742
+			return EE_System::req_type_upgrade;
743
+		}
744
+		// current version is lower than previous version, so it's a downgrade
745
+		if ($version_change === -1) {
746
+			return EE_System::req_type_downgrade;
747
+		}
748
+		// version hasn't changed since last version so check if the activation indicator is set
749
+		// to determine if it's a reactivation, or just a normal request
750
+		return $is_activation
751
+			? EE_System::req_type_reactivation
752
+			: EE_System::req_type_normal;
753
+	}
754
+
755
+
756
+	/**
757
+	 * Detects if the $version_to_upgrade_to is higher than the most recent version in
758
+	 * the $activation_history_for_addon
759
+	 *
760
+	 * @param array  $activation_history    array where keys are versions,
761
+	 *                                      values are arrays of times activated (sometimes 'unknown-date')
762
+	 * @param string $current_version
763
+	 * @return int results of version_compare( $version_to_upgrade_to, $most_recently_active_version ).
764
+	 *                                      -1 if $version_to_upgrade_to is LOWER (downgrade);
765
+	 *                                      0 if $version_to_upgrade_to MATCHES (reactivation or normal request);
766
+	 *                                      1 if $version_to_upgrade_to is HIGHER (upgrade) ;
767
+	 */
768
+	private static function compareVersionWithPrevious(array $activation_history, string $current_version): int
769
+	{
770
+		// find the most recently-activated version
771
+		$most_recently_active_version = EE_System::getMostRecentlyActiveVersion($activation_history);
772
+		return version_compare($current_version, $most_recently_active_version);
773
+	}
774
+
775
+
776
+	/**
777
+	 * Gets the most recently active version listed in the activation history,
778
+	 * and if none are found (ie, it's a brand new install) returns '0.0.0.dev.000'.
779
+	 *
780
+	 * @param array|null $activation_history (keys are versions, values are arrays of times activated,
781
+	 *                                       sometimes containing 'unknown-date'
782
+	 * @return string
783
+	 */
784
+	private static function getMostRecentlyActiveVersion(?array $activation_history): string
785
+	{
786
+		$most_recent_activation_date  = '1970-01-01 00:00:00';
787
+		$most_recently_active_version = '0.0.0.dev.000';
788
+		if (is_array($activation_history)) {
789
+			foreach ($activation_history as $version => $activation_dates) {
790
+				// check there is a record of when this version was activated.
791
+				// Otherwise, mark it as unknown
792
+				if (! $activation_dates) {
793
+					$activation_dates = ['unknown-date'];
794
+				}
795
+				$activation_dates = is_string($activation_dates)
796
+					? [$activation_dates]
797
+					: $activation_dates;
798
+				foreach ($activation_dates as $activation_date) {
799
+					if ($activation_date !== 'unknown-date' && $activation_date > $most_recent_activation_date) {
800
+						$most_recently_active_version = $version;
801
+						$most_recent_activation_date  = $activation_date;
802
+					}
803
+				}
804
+			}
805
+		}
806
+		return $most_recently_active_version;
807
+	}
808
+
809
+
810
+	/**
811
+	 * This redirects to the about EE page after activation
812
+	 *
813
+	 * @return void
814
+	 */
815
+	public function redirect_to_about_ee()
816
+	{
817
+		$notices = EE_Error::get_notices(false);
818
+		// if current user is an admin and it's not an ajax or rest request
819
+		if (
820
+			! isset($notices['errors'])
821
+			&& $this->request->isAdmin()
822
+			&& apply_filters(
823
+				'FHEE__EE_System__redirect_to_about_ee__do_redirect',
824
+				$this->capabilities->current_user_can('manage_options', 'espresso_about_default')
825
+			)
826
+		) {
827
+			$query_params = ['page' => 'espresso_about'];
828
+			if (EE_System::instance()->detect_req_type() === EE_System::req_type_new_activation) {
829
+				$query_params['new_activation'] = true;
830
+			}
831
+			if (EE_System::instance()->detect_req_type() === EE_System::req_type_reactivation) {
832
+				$query_params['reactivation'] = true;
833
+			}
834
+			$url = add_query_arg($query_params, admin_url('admin.php'));
835
+			EEH_URL::safeRedirectAndExit($url);
836
+		}
837
+	}
838
+
839
+
840
+	/**
841
+	 * load_core_configuration
842
+	 * this is hooked into 'AHEE__EE_Bootstrap__load_core_configuration'
843
+	 * which runs during the WP 'plugins_loaded' action at priority 5
844
+	 *
845
+	 * @return void
846
+	 * @throws ReflectionException
847
+	 * @throws Exception
848
+	 */
849
+	public function load_core_configuration()
850
+	{
851
+		do_action('AHEE__EE_System__load_core_configuration__begin', $this);
852
+		$this->loader->getShared('EE_Load_Textdomain');
853
+		// load textdomain
854
+		EE_Load_Textdomain::load_textdomain();
855
+		// load and setup EE_Config and EE_Network_Config
856
+		$config = $this->loader->getShared('EE_Config');
857
+		$this->loader->getShared('EE_Network_Config');
858
+		// setup autoloaders
859
+		// enable logging?
860
+		$this->loader->getShared('EventEspresso\core\services\orm\TrashLogger');
861
+		if ($config->admin->use_remote_logging) {
862
+			$this->loader->getShared('EE_Log');
863
+		}
864
+		// check for activation errors
865
+		$activation_errors = get_option('ee_plugin_activation_errors', false);
866
+		if ($activation_errors) {
867
+			EE_Error::add_error($activation_errors, __FILE__, __FUNCTION__, __LINE__);
868
+			update_option('ee_plugin_activation_errors', false);
869
+		}
870
+		// get model names
871
+		$this->_parse_model_names();
872
+		// configure custom post type definitions
873
+		$this->loader->getShared('EventEspresso\core\domain\entities\custom_post_types\CustomTaxonomyDefinitions');
874
+		$this->loader->getShared('EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions');
875
+		do_action('AHEE__EE_System__load_core_configuration__complete', $this);
876
+	}
877
+
878
+
879
+	/**
880
+	 * cycles through all of the models/*.model.php files, and assembles an array of model names
881
+	 *
882
+	 * @return void
883
+	 * @throws ReflectionException
884
+	 */
885
+	private function _parse_model_names()
886
+	{
887
+		// get all the files in the EE_MODELS folder that end in .model.php
888
+		$models                 = glob(EE_MODELS . '*.model.php');
889
+		$model_names            = [];
890
+		$non_abstract_db_models = [];
891
+		foreach ($models as $model) {
892
+			// get model classname
893
+			$classname       = EEH_File::get_classname_from_filepath_with_standard_filename($model);
894
+			$short_name      = str_replace('EEM_', '', $classname);
895
+			$reflectionClass = new ReflectionClass($classname);
896
+			if ($reflectionClass->isSubclassOf('EEM_Base') && ! $reflectionClass->isAbstract()) {
897
+				$non_abstract_db_models[ $short_name ] = $classname;
898
+			}
899
+			$model_names[ $short_name ] = $classname;
900
+		}
901
+		$this->registry->models                 = apply_filters('FHEE__EE_System__parse_model_names', $model_names);
902
+		$this->registry->non_abstract_db_models = apply_filters(
903
+			'FHEE__EE_System__parse_implemented_model_names',
904
+			$non_abstract_db_models
905
+		);
906
+	}
907
+
908
+
909
+	/**
910
+	 * @throws Exception
911
+	 * @since 4.9.71.p
912
+	 */
913
+	public function loadRouteMatchSpecifications()
914
+	{
915
+		try {
916
+			$this->loader->getShared('EventEspresso\core\services\routing\RouteMatchSpecificationManager');
917
+			$this->loader->getShared('EventEspresso\core\services\routing\RouteCollection');
918
+			$this->router->loadPrimaryRoutes();
919
+		} catch (Exception $exception) {
920
+			new ExceptionStackTraceDisplay($exception);
921
+		}
922
+		do_action('AHEE__EE_System__loadRouteMatchSpecifications');
923
+	}
924
+
925
+
926
+	/**
927
+	 * loading CPT related classes earlier so that their definitions are available
928
+	 * but not performing any actual registration with WP core until load_CPTs_and_session() is called
929
+	 *
930
+	 * @since   4.10.21.p
931
+	 */
932
+	public function loadCustomPostTypes()
933
+	{
934
+		$this->register_custom_taxonomies     = $this->loader->getShared(
935
+			'EventEspresso\core\domain\services\custom_post_types\RegisterCustomTaxonomies'
936
+		);
937
+		$this->register_custom_post_types     = $this->loader->getShared(
938
+			'EventEspresso\core\domain\services\custom_post_types\RegisterCustomPostTypes'
939
+		);
940
+		$this->register_custom_taxonomy_terms = $this->loader->getShared(
941
+			'EventEspresso\core\domain\services\custom_post_types\RegisterCustomTaxonomyTerms'
942
+		);
943
+		// integrate WP_Query with the EE models
944
+		$this->loader->getShared('EE_CPT_Strategy');
945
+		// load legacy EE_Request_Handler in case add-ons still need it
946
+		$this->loader->getShared('EE_Request_Handler');
947
+	}
948
+
949
+
950
+	/**
951
+	 * register_shortcodes_modules_and_widgets
952
+	 * generate lists of shortcodes and modules, then verify paths and classes
953
+	 * This is hooked into 'AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets'
954
+	 * which runs during the WP 'plugins_loaded' action at priority 7
955
+	 *
956
+	 * @access public
957
+	 * @return void
958
+	 * @throws Exception
959
+	 */
960
+	public function register_shortcodes_modules_and_widgets()
961
+	{
962
+		$this->router->registerShortcodesModulesAndWidgets();
963
+		do_action('AHEE__EE_System__register_shortcodes_modules_and_widgets');
964
+		// check for addons using old hook point
965
+		if (has_action('AHEE__EE_System__register_shortcodes_modules_and_addons')) {
966
+			$this->_incompatible_addon_error();
967
+		}
968
+	}
969
+
970
+
971
+	/**
972
+	 * _incompatible_addon_error
973
+	 *
974
+	 * @access public
975
+	 * @return void
976
+	 */
977
+	private function _incompatible_addon_error()
978
+	{
979
+		// get array of classes hooking into here
980
+		$class_names = WordPressHooks::getClassNamesForAllCallbacksOnHook(
981
+			'AHEE__EE_System__register_shortcodes_modules_and_addons'
982
+		);
983
+		if (! empty($class_names)) {
984
+			$msg = esc_html__(
985
+				'The following plugins, addons, or modules appear to be incompatible with this version of Event Espresso and were automatically deactivated to avoid fatal errors:',
986
+				'event_espresso'
987
+			);
988
+			$msg .= '<ul>';
989
+			foreach ($class_names as $class_name) {
990
+				$msg .= '<li><b>Event Espresso - '
991
+						. str_replace(
992
+							['EE_', 'EEM_', 'EED_', 'EES_', 'EEW_'],
993
+							'',
994
+							$class_name
995
+						) . '</b></li>';
996
+			}
997
+			$msg .= '</ul>';
998
+			$msg .= esc_html__(
999
+				'Compatibility issues can be avoided and/or resolved by keeping addons and plugins updated to the latest version.',
1000
+				'event_espresso'
1001
+			);
1002
+			// save list of incompatible addons to wp-options for later use
1003
+			add_option('ee_incompatible_addons', $class_names, '', 'no');
1004
+			if (is_admin()) {
1005
+				EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1006
+			}
1007
+		}
1008
+	}
1009
+
1010
+
1011
+	/**
1012
+	 * brew_espresso
1013
+	 * begins the process of setting hooks for initializing EE in the correct order
1014
+	 * This is happening on the 'AHEE__EE_Bootstrap__brew_espresso' hook point
1015
+	 * which runs during the WP 'plugins_loaded' action at priority 9
1016
+	 *
1017
+	 * @return void
1018
+	 * @throws Exception
1019
+	 */
1020
+	public function brew_espresso()
1021
+	{
1022
+		do_action('AHEE__EE_System__brew_espresso__begin', $this);
1023
+		// load some final core systems
1024
+		add_action('init', [$this, 'set_hooks_for_core'], 1);
1025
+		add_action('init', [$this, 'perform_activations_upgrades_and_migrations'], 3);
1026
+		add_action('init', [$this, 'load_CPTs_and_session'], 5);
1027
+		add_action('init', [$this, 'load_controllers'], 7);
1028
+		add_action('init', [$this, 'core_loaded_and_ready'], 9);
1029
+		add_action('init', [$this, 'initialize'], 10);
1030
+		add_action('init', [$this, 'initialize_last'], 100);
1031
+		$this->router->brewEspresso();
1032
+		$this->loader->getShared('EventEspresso\PaymentMethods\Manager');
1033
+		$this->loader->getShared('EE_Payment_Method_Manager');
1034
+		do_action('AHEE__EE_System__brew_espresso__complete', $this);
1035
+	}
1036
+
1037
+
1038
+	/**
1039
+    /**
1040
+	 *    set_hooks_for_core
1041
+	 *
1042
+	 * @access public
1043
+	 * @return    void
1044
+	 * @throws EE_Error
1045
+	 */
1046
+	public function set_hooks_for_core()
1047
+	{
1048
+		$this->_deactivate_incompatible_addons();
1049
+		do_action('AHEE__EE_System__set_hooks_for_core');
1050
+		$this->loader->getShared('EventEspresso\core\domain\values\session\SessionLifespan');
1051
+		// caps need to be initialized on every request so that capability maps are set.
1052
+		// @see https://events.codebasehq.com/projects/event-espresso/tickets/8674
1053
+		$this->capabilities->init_caps();
1054
+	}
1055
+
1056
+
1057
+	/**
1058
+	 * Using the information gathered in EE_System::_incompatible_addon_error,
1059
+	 * deactivates any addons considered incompatible with the current version of EE
1060
+	 */
1061
+	private function _deactivate_incompatible_addons()
1062
+	{
1063
+		$incompatible_addons = get_option('ee_incompatible_addons', []);
1064
+		if (! empty($incompatible_addons)) {
1065
+			$active_plugins = get_option('active_plugins', []);
1066
+			foreach ($active_plugins as $active_plugin) {
1067
+				foreach ($incompatible_addons as $incompatible_addon) {
1068
+					if (strpos($active_plugin, $incompatible_addon) !== false) {
1069
+						$this->request->unSetRequestParams(['activate'], true);
1070
+						espresso_deactivate_plugin($active_plugin);
1071
+					}
1072
+				}
1073
+			}
1074
+		}
1075
+	}
1076
+
1077
+
1078
+	/**
1079
+	 *    perform_activations_upgrades_and_migrations
1080
+	 *
1081
+	 * @access public
1082
+	 * @return    void
1083
+	 */
1084
+	public function perform_activations_upgrades_and_migrations()
1085
+	{
1086
+		do_action('AHEE__EE_System__perform_activations_upgrades_and_migrations');
1087
+	}
1088
+
1089
+
1090
+	/**
1091
+	 * @return void
1092
+	 * @throws DomainException
1093
+	 */
1094
+	public function load_CPTs_and_session()
1095
+	{
1096
+		do_action('AHEE__EE_System__load_CPTs_and_session__start');
1097
+		$this->register_custom_taxonomies->registerCustomTaxonomies();
1098
+		$this->register_custom_post_types->registerCustomPostTypes();
1099
+		$this->register_custom_taxonomy_terms->registerCustomTaxonomyTerms();
1100
+		// load legacy Custom Post Types and Taxonomies
1101
+		$this->loader->getShared('EE_Register_CPTs');
1102
+		do_action('AHEE__EE_System__load_CPTs_and_session__complete');
1103
+	}
1104
+
1105
+
1106
+	/**
1107
+	 * load_controllers
1108
+	 * this is the best place to load any additional controllers that needs access to EE core.
1109
+	 * it is expected that all basic core EE systems, that are not dependant on the current request are loaded at this
1110
+	 * time
1111
+	 *
1112
+	 * @access public
1113
+	 * @return void
1114
+	 * @throws Exception
1115
+	 */
1116
+	public function load_controllers()
1117
+	{
1118
+		do_action('AHEE__EE_System__load_controllers__start');
1119
+		$this->router->loadControllers();
1120
+		do_action('AHEE__EE_System__load_controllers__complete');
1121
+	}
1122
+
1123
+
1124
+	/**
1125
+	 * core_loaded_and_ready
1126
+	 * all of the basic EE core should be loaded at this point and available regardless of M-Mode
1127
+	 *
1128
+	 * @access public
1129
+	 * @return void
1130
+	 * @throws Exception
1131
+	 */
1132
+	public function core_loaded_and_ready()
1133
+	{
1134
+		$this->router->coreLoadedAndReady();
1135
+		do_action('AHEE__EE_System__core_loaded_and_ready');
1136
+		// always load template tags, because it's faster than checking if it's a front-end request, and many page
1137
+		// builders require these even on the front-end
1138
+		require_once EE_PUBLIC . 'template_tags.php';
1139
+		do_action('AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons');
1140
+	}
1141
+
1142
+
1143
+	/**
1144
+	 * initialize
1145
+	 * this is the best place to begin initializing client code
1146
+	 *
1147
+	 * @access public
1148
+	 * @return void
1149
+	 */
1150
+	public function initialize()
1151
+	{
1152
+		do_action('AHEE__EE_System__initialize');
1153
+		add_filter(
1154
+			'safe_style_css',
1155
+			function ($styles) {
1156
+				$styles[] = 'display';
1157
+				$styles[] = 'visibility';
1158
+				$styles[] = 'position';
1159
+				$styles[] = 'top';
1160
+				$styles[] = 'right';
1161
+				$styles[] = 'bottom';
1162
+				$styles[] = 'left';
1163
+				$styles[] = 'resize';
1164
+				$styles[] = 'max-width';
1165
+				$styles[] = 'max-height';
1166
+				return $styles;
1167
+			}
1168
+		);
1169
+	}
1170
+
1171
+
1172
+	/**
1173
+	 * initialize_last
1174
+	 * this is run really late during the WP init hook point, and ensures that mostly everything else that needs to
1175
+	 * initialize has done so
1176
+	 *
1177
+	 * @access public
1178
+	 * @return void
1179
+	 * @throws Exception
1180
+	 */
1181
+	public function initialize_last()
1182
+	{
1183
+		$this->router->initializeLast();
1184
+		do_action('AHEE__EE_System__initialize_last');
1185
+		/** @var EventEspresso\core\domain\services\custom_post_types\RewriteRules $rewrite_rules */
1186
+		$rewrite_rules = $this->loader->getShared(
1187
+			'EventEspresso\core\domain\services\custom_post_types\RewriteRules'
1188
+		);
1189
+		$rewrite_rules->flushRewriteRules();
1190
+		add_action('admin_bar_init', [$this, 'addEspressoToolbar']);
1191
+	}
1192
+
1193
+
1194
+	/**
1195
+	 * @return void
1196
+	 */
1197
+	public function addEspressoToolbar()
1198
+	{
1199
+		$this->loader->getShared(
1200
+			'EventEspresso\core\domain\services\admin\AdminToolBar',
1201
+			[$this->capabilities]
1202
+		);
1203
+	}
1204
+
1205
+
1206
+	/**
1207
+	 * do_not_cache
1208
+	 * sets no cache headers and defines no cache constants for WP plugins
1209
+	 *
1210
+	 * @access public
1211
+	 * @return void
1212
+	 */
1213
+	public static function do_not_cache()
1214
+	{
1215
+		// set no cache constants
1216
+		if (! defined('DONOTCACHEPAGE')) {
1217
+			define('DONOTCACHEPAGE', true);
1218
+		}
1219
+		if (! defined('DONOTCACHCEOBJECT')) {
1220
+			define('DONOTCACHCEOBJECT', true);
1221
+		}
1222
+		if (! defined('DONOTCACHEDB')) {
1223
+			define('DONOTCACHEDB', true);
1224
+		}
1225
+		// add no cache headers
1226
+		add_action('send_headers', ['EE_System', 'nocache_headers'], 10);
1227
+		// plus a little extra for nginx and Google Chrome
1228
+		add_filter('nocache_headers', ['EE_System', 'extra_nocache_headers'], 10, 1);
1229
+		// prevent browsers from prefetching of the rel='next' link, because it may contain content that interferes with the registration process
1230
+		remove_action('wp_head', 'adjacent_posts_rel_link_wp_head');
1231
+	}
1232
+
1233
+
1234
+	/**
1235
+	 *    extra_nocache_headers
1236
+	 *
1237
+	 * @access    public
1238
+	 * @param $headers
1239
+	 * @return    array
1240
+	 */
1241
+	public static function extra_nocache_headers($headers): array
1242
+	{
1243
+		// for NGINX
1244
+		$headers['X-Accel-Expires'] = 0;
1245
+		// plus extra for Google Chrome since it doesn't seem to respect "no-cache", but WILL respect "no-store"
1246
+		$headers['Cache-Control'] = 'no-store, no-cache, must-revalidate, max-age=0';
1247
+		return $headers;
1248
+	}
1249
+
1250
+
1251
+	/**
1252
+	 *    nocache_headers
1253
+	 *
1254
+	 * @access    public
1255
+	 * @return    void
1256
+	 */
1257
+	public static function nocache_headers()
1258
+	{
1259
+		nocache_headers();
1260
+	}
1261
+
1262
+
1263
+	/**
1264
+	 * simply hooks into "wp_list_pages_exclude" filter (for wp_list_pages method) and makes sure EE critical pages are
1265
+	 * never returned with the function.
1266
+	 *
1267
+	 * @param array $exclude_array any existing pages being excluded are in this array.
1268
+	 * @return array
1269
+	 */
1270
+	public function remove_pages_from_wp_list_pages(array $exclude_array): array
1271
+	{
1272
+		return array_merge($exclude_array, $this->registry->CFG->core->get_critical_pages_array());
1273
+	}
1274 1274
 }
Please login to merge, or discard this patch.
Spacing   +20 added lines, -20 removed lines patch added patch discarded remove patch
@@ -159,7 +159,7 @@  discard block
 block discarded – undo
159 159
         Router $router = null
160 160
     ): EE_System {
161 161
         // check if class object is instantiated
162
-        if (! self::$_instance instanceof EE_System) {
162
+        if ( ! self::$_instance instanceof EE_System) {
163 163
             self::$_instance = new self($loader, $maintenance_mode, $registry, $request, $router);
164 164
         }
165 165
         return self::$_instance;
@@ -375,7 +375,7 @@  discard block
 block discarded – undo
375 375
         /** @var Domain $domain */
376 376
         $domain = DomainFactory::getEventEspressoCoreDomain();
377 377
         if ($domain->isCaffeinated() && ! $brew instanceof EE_Brewing_Regular) {
378
-            require_once EE_CAFF_PATH . 'brewing_regular.php';
378
+            require_once EE_CAFF_PATH.'brewing_regular.php';
379 379
             /** @var EE_Brewing_Regular $brew */
380 380
             $brew = LoaderFactory::getLoader()->getShared(EE_Brewing_Regular::class);
381 381
             $brew->initializePUE();
@@ -500,11 +500,11 @@  discard block
 block discarded – undo
500 500
     private function fix_espresso_db_upgrade_option($espresso_db_update = null): array
501 501
     {
502 502
         do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__begin', $espresso_db_update);
503
-        if (! $espresso_db_update) {
503
+        if ( ! $espresso_db_update) {
504 504
             $espresso_db_update = get_option('espresso_db_update');
505 505
         }
506 506
         // check that option is an array
507
-        if (! is_array($espresso_db_update)) {
507
+        if ( ! is_array($espresso_db_update)) {
508 508
             // if option is FALSE, then it never existed
509 509
             if ($espresso_db_update === false) {
510 510
                 // make $espresso_db_update an array and save option with autoload OFF
@@ -524,10 +524,10 @@  discard block
 block discarded – undo
524 524
                     // so it must be numerically-indexed, where values are versions installed...
525 525
                     // fix it!
526 526
                     $version_string                         = $should_be_array;
527
-                    $corrected_db_update[ $version_string ] = ['unknown-date'];
527
+                    $corrected_db_update[$version_string] = ['unknown-date'];
528 528
                 } else {
529 529
                     // ok it checks out
530
-                    $corrected_db_update[ $should_be_version_string ] = $should_be_array;
530
+                    $corrected_db_update[$should_be_version_string] = $should_be_array;
531 531
                 }
532 532
             }
533 533
             $espresso_db_update = $corrected_db_update;
@@ -615,13 +615,13 @@  discard block
 block discarded – undo
615 615
      */
616 616
     public function update_list_of_installed_versions($version_history = null, $current_version_to_add = null): bool
617 617
     {
618
-        if (! $version_history) {
618
+        if ( ! $version_history) {
619 619
             $version_history = $this->fix_espresso_db_upgrade_option($version_history);
620 620
         }
621 621
         if ($current_version_to_add === null) {
622 622
             $current_version_to_add = espresso_version();
623 623
         }
624
-        $version_history[ $current_version_to_add ][] = date('Y-m-d H:i:s', time());
624
+        $version_history[$current_version_to_add][] = date('Y-m-d H:i:s', time());
625 625
         // re-save
626 626
         return update_option('espresso_db_update', $version_history);
627 627
     }
@@ -789,7 +789,7 @@  discard block
 block discarded – undo
789 789
             foreach ($activation_history as $version => $activation_dates) {
790 790
                 // check there is a record of when this version was activated.
791 791
                 // Otherwise, mark it as unknown
792
-                if (! $activation_dates) {
792
+                if ( ! $activation_dates) {
793 793
                     $activation_dates = ['unknown-date'];
794 794
                 }
795 795
                 $activation_dates = is_string($activation_dates)
@@ -885,7 +885,7 @@  discard block
 block discarded – undo
885 885
     private function _parse_model_names()
886 886
     {
887 887
         // get all the files in the EE_MODELS folder that end in .model.php
888
-        $models                 = glob(EE_MODELS . '*.model.php');
888
+        $models                 = glob(EE_MODELS.'*.model.php');
889 889
         $model_names            = [];
890 890
         $non_abstract_db_models = [];
891 891
         foreach ($models as $model) {
@@ -894,9 +894,9 @@  discard block
 block discarded – undo
894 894
             $short_name      = str_replace('EEM_', '', $classname);
895 895
             $reflectionClass = new ReflectionClass($classname);
896 896
             if ($reflectionClass->isSubclassOf('EEM_Base') && ! $reflectionClass->isAbstract()) {
897
-                $non_abstract_db_models[ $short_name ] = $classname;
897
+                $non_abstract_db_models[$short_name] = $classname;
898 898
             }
899
-            $model_names[ $short_name ] = $classname;
899
+            $model_names[$short_name] = $classname;
900 900
         }
901 901
         $this->registry->models                 = apply_filters('FHEE__EE_System__parse_model_names', $model_names);
902 902
         $this->registry->non_abstract_db_models = apply_filters(
@@ -980,7 +980,7 @@  discard block
 block discarded – undo
980 980
         $class_names = WordPressHooks::getClassNamesForAllCallbacksOnHook(
981 981
             'AHEE__EE_System__register_shortcodes_modules_and_addons'
982 982
         );
983
-        if (! empty($class_names)) {
983
+        if ( ! empty($class_names)) {
984 984
             $msg = esc_html__(
985 985
                 'The following plugins, addons, or modules appear to be incompatible with this version of Event Espresso and were automatically deactivated to avoid fatal errors:',
986 986
                 'event_espresso'
@@ -992,7 +992,7 @@  discard block
 block discarded – undo
992 992
                             ['EE_', 'EEM_', 'EED_', 'EES_', 'EEW_'],
993 993
                             '',
994 994
                             $class_name
995
-                        ) . '</b></li>';
995
+                        ).'</b></li>';
996 996
             }
997 997
             $msg .= '</ul>';
998 998
             $msg .= esc_html__(
@@ -1061,7 +1061,7 @@  discard block
 block discarded – undo
1061 1061
     private function _deactivate_incompatible_addons()
1062 1062
     {
1063 1063
         $incompatible_addons = get_option('ee_incompatible_addons', []);
1064
-        if (! empty($incompatible_addons)) {
1064
+        if ( ! empty($incompatible_addons)) {
1065 1065
             $active_plugins = get_option('active_plugins', []);
1066 1066
             foreach ($active_plugins as $active_plugin) {
1067 1067
                 foreach ($incompatible_addons as $incompatible_addon) {
@@ -1135,7 +1135,7 @@  discard block
 block discarded – undo
1135 1135
         do_action('AHEE__EE_System__core_loaded_and_ready');
1136 1136
         // always load template tags, because it's faster than checking if it's a front-end request, and many page
1137 1137
         // builders require these even on the front-end
1138
-        require_once EE_PUBLIC . 'template_tags.php';
1138
+        require_once EE_PUBLIC.'template_tags.php';
1139 1139
         do_action('AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons');
1140 1140
     }
1141 1141
 
@@ -1152,7 +1152,7 @@  discard block
 block discarded – undo
1152 1152
         do_action('AHEE__EE_System__initialize');
1153 1153
         add_filter(
1154 1154
             'safe_style_css',
1155
-            function ($styles) {
1155
+            function($styles) {
1156 1156
                 $styles[] = 'display';
1157 1157
                 $styles[] = 'visibility';
1158 1158
                 $styles[] = 'position';
@@ -1213,13 +1213,13 @@  discard block
 block discarded – undo
1213 1213
     public static function do_not_cache()
1214 1214
     {
1215 1215
         // set no cache constants
1216
-        if (! defined('DONOTCACHEPAGE')) {
1216
+        if ( ! defined('DONOTCACHEPAGE')) {
1217 1217
             define('DONOTCACHEPAGE', true);
1218 1218
         }
1219
-        if (! defined('DONOTCACHCEOBJECT')) {
1219
+        if ( ! defined('DONOTCACHCEOBJECT')) {
1220 1220
             define('DONOTCACHCEOBJECT', true);
1221 1221
         }
1222
-        if (! defined('DONOTCACHEDB')) {
1222
+        if ( ! defined('DONOTCACHEDB')) {
1223 1223
             define('DONOTCACHEDB', true);
1224 1224
         }
1225 1225
         // add no cache headers
Please login to merge, or discard this patch.
core/EE_Psr4AutoloaderInit.core.php 2 patches
Indentation   +33 added lines, -33 removed lines patch added patch discarded remove patch
@@ -13,42 +13,42 @@
 block discarded – undo
13 13
  */
14 14
 class EE_Psr4AutoloaderInit
15 15
 {
16
-    protected static ?Psr4Autoloader $psr4_loader = null;
16
+	protected static ?Psr4Autoloader $psr4_loader = null;
17 17
 
18
-    private static bool              $initialized = false;
18
+	private static bool              $initialized = false;
19 19
 
20 20
 
21
-    /**
22
-     * @return void
23
-     * @throws EE_Error
24
-     */
25
-    public function initializeAutoloader()
26
-    {
27
-        if (! EE_Psr4AutoloaderInit::$initialized) {
28
-            // register the base directories for the namespace prefix
29
-            $psr4_loader = EE_Psr4AutoloaderInit::psr4_loader();
30
-            $psr4_loader->addNamespace('EventEspresso', EE_PLUGIN_DIR_PATH);
31
-            $psr4_loader->addNamespace('EventEspressoBatchRequest', EE_LIBRARIES . 'batch');
32
-            $psr4_loader->addNamespace('EventEspressoVendor', EE_THIRD_PARTY);
33
-            do_action('AHEE__EE_Psr4AutoloaderInit__initializeAutoloader', $psr4_loader);
34
-            EE_Psr4AutoloaderInit::$initialized = true;
35
-        }
36
-    }
21
+	/**
22
+	 * @return void
23
+	 * @throws EE_Error
24
+	 */
25
+	public function initializeAutoloader()
26
+	{
27
+		if (! EE_Psr4AutoloaderInit::$initialized) {
28
+			// register the base directories for the namespace prefix
29
+			$psr4_loader = EE_Psr4AutoloaderInit::psr4_loader();
30
+			$psr4_loader->addNamespace('EventEspresso', EE_PLUGIN_DIR_PATH);
31
+			$psr4_loader->addNamespace('EventEspressoBatchRequest', EE_LIBRARIES . 'batch');
32
+			$psr4_loader->addNamespace('EventEspressoVendor', EE_THIRD_PARTY);
33
+			do_action('AHEE__EE_Psr4AutoloaderInit__initializeAutoloader', $psr4_loader);
34
+			EE_Psr4AutoloaderInit::$initialized = true;
35
+		}
36
+	}
37 37
 
38 38
 
39
-    /**
40
-     * @return Psr4Autoloader
41
-     * @throws EE_Error
42
-     */
43
-    public static function psr4_loader(): Psr4Autoloader
44
-    {
45
-        if (! EE_Psr4AutoloaderInit::$psr4_loader instanceof Psr4Autoloader) {
46
-            // instantiate PSR4 autoloader
47
-            espresso_load_required('Psr4Autoloader', __DIR__ . '/Psr4Autoloader.php');
48
-            EE_Psr4AutoloaderInit::$psr4_loader = new Psr4Autoloader();
49
-            // register the autoloader
50
-            EE_Psr4AutoloaderInit::$psr4_loader->register();
51
-        }
52
-        return EE_Psr4AutoloaderInit::$psr4_loader;
53
-    }
39
+	/**
40
+	 * @return Psr4Autoloader
41
+	 * @throws EE_Error
42
+	 */
43
+	public static function psr4_loader(): Psr4Autoloader
44
+	{
45
+		if (! EE_Psr4AutoloaderInit::$psr4_loader instanceof Psr4Autoloader) {
46
+			// instantiate PSR4 autoloader
47
+			espresso_load_required('Psr4Autoloader', __DIR__ . '/Psr4Autoloader.php');
48
+			EE_Psr4AutoloaderInit::$psr4_loader = new Psr4Autoloader();
49
+			// register the autoloader
50
+			EE_Psr4AutoloaderInit::$psr4_loader->register();
51
+		}
52
+		return EE_Psr4AutoloaderInit::$psr4_loader;
53
+	}
54 54
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -24,11 +24,11 @@  discard block
 block discarded – undo
24 24
      */
25 25
     public function initializeAutoloader()
26 26
     {
27
-        if (! EE_Psr4AutoloaderInit::$initialized) {
27
+        if ( ! EE_Psr4AutoloaderInit::$initialized) {
28 28
             // register the base directories for the namespace prefix
29 29
             $psr4_loader = EE_Psr4AutoloaderInit::psr4_loader();
30 30
             $psr4_loader->addNamespace('EventEspresso', EE_PLUGIN_DIR_PATH);
31
-            $psr4_loader->addNamespace('EventEspressoBatchRequest', EE_LIBRARIES . 'batch');
31
+            $psr4_loader->addNamespace('EventEspressoBatchRequest', EE_LIBRARIES.'batch');
32 32
             $psr4_loader->addNamespace('EventEspressoVendor', EE_THIRD_PARTY);
33 33
             do_action('AHEE__EE_Psr4AutoloaderInit__initializeAutoloader', $psr4_loader);
34 34
             EE_Psr4AutoloaderInit::$initialized = true;
@@ -42,9 +42,9 @@  discard block
 block discarded – undo
42 42
      */
43 43
     public static function psr4_loader(): Psr4Autoloader
44 44
     {
45
-        if (! EE_Psr4AutoloaderInit::$psr4_loader instanceof Psr4Autoloader) {
45
+        if ( ! EE_Psr4AutoloaderInit::$psr4_loader instanceof Psr4Autoloader) {
46 46
             // instantiate PSR4 autoloader
47
-            espresso_load_required('Psr4Autoloader', __DIR__ . '/Psr4Autoloader.php');
47
+            espresso_load_required('Psr4Autoloader', __DIR__.'/Psr4Autoloader.php');
48 48
             EE_Psr4AutoloaderInit::$psr4_loader = new Psr4Autoloader();
49 49
             // register the autoloader
50 50
             EE_Psr4AutoloaderInit::$psr4_loader->register();
Please login to merge, or discard this patch.
core/data_migration_scripts/EE_DMS_Core_4_5_0.dms.php 2 patches
Indentation   +249 added lines, -249 removed lines patch added patch discarded remove patch
@@ -10,9 +10,9 @@  discard block
 block discarded – undo
10 10
 $stages            = glob(EE_CORE . 'data_migration_scripts/4_5_0_stages/*');
11 11
 $class_to_filepath = [];
12 12
 foreach ($stages as $filepath) {
13
-    $matches = [];
14
-    preg_match('~4_5_0_stages/(.*).dmsstage.php~', $filepath, $matches);
15
-    $class_to_filepath[ $matches[1] ] = $filepath;
13
+	$matches = [];
14
+	preg_match('~4_5_0_stages/(.*).dmsstage.php~', $filepath, $matches);
15
+	$class_to_filepath[ $matches[1] ] = $filepath;
16 16
 }
17 17
 // give addons a chance to autoload their stages too
18 18
 $class_to_filepath = apply_filters('FHEE__EE_DMS_4_5_0__autoloaded_stages', $class_to_filepath);
@@ -30,68 +30,68 @@  discard block
 block discarded – undo
30 30
  */
31 31
 class EE_DMS_Core_4_5_0 extends EE_Data_Migration_Script_Base
32 32
 {
33
-    /**
34
-     * EE_DMS_Core_4_5_0 constructor.
35
-     *
36
-     * @param TableManager  $table_manager
37
-     * @param TableAnalysis $table_analysis
38
-     */
39
-    public function __construct(TableManager $table_manager = null, TableAnalysis $table_analysis = null)
40
-    {
41
-        $this->_pretty_name      = esc_html__("Data Update to Event Espresso 4.5.0", "event_espresso");
42
-        $this->_priority         = 10;
43
-        $this->_migration_stages = [
44
-            new EE_DMS_4_5_0_update_wp_user_for_tickets(),
45
-            new EE_DMS_4_5_0_update_wp_user_for_prices(),
46
-            new EE_DMS_4_5_0_update_wp_user_for_price_types(),
47
-            new EE_DMS_4_5_0_update_wp_user_for_question_groups(),
48
-            new EE_DMS_4_5_0_invoice_settings(),
49
-        ];
50
-        parent::__construct($table_manager, $table_analysis);
51
-    }
33
+	/**
34
+	 * EE_DMS_Core_4_5_0 constructor.
35
+	 *
36
+	 * @param TableManager  $table_manager
37
+	 * @param TableAnalysis $table_analysis
38
+	 */
39
+	public function __construct(TableManager $table_manager = null, TableAnalysis $table_analysis = null)
40
+	{
41
+		$this->_pretty_name      = esc_html__("Data Update to Event Espresso 4.5.0", "event_espresso");
42
+		$this->_priority         = 10;
43
+		$this->_migration_stages = [
44
+			new EE_DMS_4_5_0_update_wp_user_for_tickets(),
45
+			new EE_DMS_4_5_0_update_wp_user_for_prices(),
46
+			new EE_DMS_4_5_0_update_wp_user_for_price_types(),
47
+			new EE_DMS_4_5_0_update_wp_user_for_question_groups(),
48
+			new EE_DMS_4_5_0_invoice_settings(),
49
+		];
50
+		parent::__construct($table_manager, $table_analysis);
51
+	}
52 52
 
53 53
 
54
-    public function can_migrate_from_version($version_array)
55
-    {
56
-        $version_string = $version_array['Core'];
57
-        if (
58
-            version_compare($version_string, '4.5.0.decaf', '<') && version_compare(
59
-                $version_string,
60
-                '4.3.0.decaf',
61
-                '>='
62
-            )
63
-        ) {
54
+	public function can_migrate_from_version($version_array)
55
+	{
56
+		$version_string = $version_array['Core'];
57
+		if (
58
+			version_compare($version_string, '4.5.0.decaf', '<') && version_compare(
59
+				$version_string,
60
+				'4.3.0.decaf',
61
+				'>='
62
+			)
63
+		) {
64 64
 //          echo "$version_string can be migrated from";
65
-            return true;
66
-        } elseif (! $version_string) {
65
+			return true;
66
+		} elseif (! $version_string) {
67 67
 //          echo "no version string provided: $version_string";
68
-            // no version string provided... this must be pre 4.3
69
-            return false;// changed mind. dont want people thinking they should migrate yet because they cant
70
-        } else {
68
+			// no version string provided... this must be pre 4.3
69
+			return false;// changed mind. dont want people thinking they should migrate yet because they cant
70
+		} else {
71 71
 //          echo "$version_string doesnt apply";
72
-            return false;
73
-        }
74
-    }
72
+			return false;
73
+		}
74
+	}
75 75
 
76 76
 
77
-    /**
78
-     * @return true
79
-     * @throws EE_Error
80
-     * @throws ReflectionException
81
-     */
82
-    public function schema_changes_before_migration()
83
-    {
84
-        // relies on 4.1's EEH_Activation::create_table
85
-        require_once(EE_HELPERS . 'EEH_Activation.helper.php');
86
-        $table_name = 'esp_answer';
87
-        $sql        = "ANS_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
77
+	/**
78
+	 * @return true
79
+	 * @throws EE_Error
80
+	 * @throws ReflectionException
81
+	 */
82
+	public function schema_changes_before_migration()
83
+	{
84
+		// relies on 4.1's EEH_Activation::create_table
85
+		require_once(EE_HELPERS . 'EEH_Activation.helper.php');
86
+		$table_name = 'esp_answer';
87
+		$sql        = "ANS_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
88 88
 					REG_ID int(10) unsigned NOT NULL,
89 89
 					QST_ID int(10) unsigned NOT NULL,
90 90
 					ANS_value text NOT NULL,
91 91
 					PRIMARY KEY  (ANS_ID)";
92
-        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
93
-        $table_name = 'esp_attendee_meta';
94
-        $sql        = "ATTM_ID int(10) unsigned NOT	NULL AUTO_INCREMENT,
92
+		$this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
93
+		$table_name = 'esp_attendee_meta';
94
+		$sql        = "ATTM_ID int(10) unsigned NOT	NULL AUTO_INCREMENT,
95 95
 						ATT_ID bigint(20) unsigned NOT NULL,
96 96
 						ATT_fname varchar(45) NOT NULL,
97 97
 						ATT_lname varchar(45) NOT	NULL,
@@ -107,9 +107,9 @@  discard block
 block discarded – undo
107 107
 								KEY ATT_fname (ATT_fname),
108 108
 								KEY ATT_lname (ATT_lname),
109 109
 								KEY ATT_email (ATT_email(191))";
110
-        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB ');
111
-        $table_name = 'esp_country';
112
-        $sql        = "CNT_ISO varchar(2) COLLATE utf8_bin NOT NULL,
110
+		$this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB ');
111
+		$table_name = 'esp_country';
112
+		$sql        = "CNT_ISO varchar(2) COLLATE utf8_bin NOT NULL,
113 113
 					  CNT_ISO3 varchar(3) COLLATE utf8_bin NOT NULL,
114 114
 					  RGN_ID tinyint(3) unsigned DEFAULT NULL,
115 115
 					  CNT_name varchar(45) COLLATE utf8_bin NOT NULL,
@@ -125,9 +125,9 @@  discard block
 block discarded – undo
125 125
 					  CNT_is_EU tinyint(1) DEFAULT '0',
126 126
 					  CNT_active tinyint(1) DEFAULT '0',
127 127
 					  PRIMARY KEY  (CNT_ISO)";
128
-        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
129
-        $table_name = 'esp_datetime';
130
-        $sql        = "DTT_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
128
+		$this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
129
+		$table_name = 'esp_datetime';
130
+		$sql        = "DTT_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
131 131
 				  EVT_ID bigint(20) unsigned NOT NULL,
132 132
 				  DTT_name varchar(255) NOT NULL DEFAULT '',
133 133
 				  DTT_description text NOT NULL,
@@ -142,9 +142,9 @@  discard block
 block discarded – undo
142 142
 						PRIMARY KEY  (DTT_ID),
143 143
 						KEY EVT_ID (EVT_ID),
144 144
 						KEY DTT_is_primary (DTT_is_primary)";
145
-        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
146
-        $table_name = 'esp_event_meta';
147
-        $sql        = "
145
+		$this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
146
+		$table_name = 'esp_event_meta';
147
+		$sql        = "
148 148
 			EVTM_ID int(10) NOT NULL AUTO_INCREMENT,
149 149
 			EVT_ID bigint(20) unsigned NOT NULL,
150 150
 			EVT_display_desc tinyint(1) unsigned NOT NULL DEFAULT 1,
@@ -159,31 +159,31 @@  discard block
 block discarded – undo
159 159
 			EVT_external_URL varchar(200) NULL,
160 160
 			EVT_donations tinyint(1) NULL,
161 161
 			PRIMARY KEY  (EVTM_ID)";
162
-        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
163
-        $table_name = 'esp_event_question_group';
164
-        $sql        = "EQG_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
162
+		$this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
163
+		$table_name = 'esp_event_question_group';
164
+		$sql        = "EQG_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
165 165
 					EVT_ID bigint(20) unsigned NOT NULL,
166 166
 					QSG_ID int(10) unsigned NOT NULL,
167 167
 					EQG_primary tinyint(1) unsigned NOT NULL DEFAULT 0,
168 168
 					PRIMARY KEY  (EQG_ID)";
169
-        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
170
-        $table_name = 'esp_event_venue';
171
-        $sql        = "EVV_ID int(11) NOT NULL AUTO_INCREMENT,
169
+		$this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
170
+		$table_name = 'esp_event_venue';
171
+		$sql        = "EVV_ID int(11) NOT NULL AUTO_INCREMENT,
172 172
 				EVT_ID bigint(20) unsigned NOT NULL,
173 173
 				VNU_ID bigint(20) unsigned NOT NULL,
174 174
 				EVV_primary tinyint(1) unsigned NOT NULL DEFAULT 0,
175 175
 				PRIMARY KEY  (EVV_ID)";
176
-        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
177
-        $table_name = 'esp_extra_meta';
178
-        $sql        = "EXM_ID int(11) NOT NULL AUTO_INCREMENT,
176
+		$this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
177
+		$table_name = 'esp_extra_meta';
178
+		$sql        = "EXM_ID int(11) NOT NULL AUTO_INCREMENT,
179 179
 				OBJ_ID int(11) DEFAULT NULL,
180 180
 				EXM_type varchar(45) DEFAULT NULL,
181 181
 				EXM_key varchar(45) DEFAULT NULL,
182 182
 				EXM_value text,
183 183
 				PRIMARY KEY  (EXM_ID)";
184
-        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
185
-        $table_name = 'esp_line_item';
186
-        $sql        = "LIN_ID int(11) NOT NULL AUTO_INCREMENT,
184
+		$this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
185
+		$table_name = 'esp_line_item';
186
+		$sql        = "LIN_ID int(11) NOT NULL AUTO_INCREMENT,
187 187
 				LIN_code varchar(245) NOT NULL DEFAULT '',
188 188
 				TXN_ID int(11) DEFAULT NULL,
189 189
 				LIN_name varchar(245) NOT NULL DEFAULT '',
@@ -199,19 +199,19 @@  discard block
 block discarded – undo
199 199
 				OBJ_ID int(11) DEFAULT NULL,
200 200
 				OBJ_type varchar(45)DEFAULT NULL,
201 201
 				PRIMARY KEY  (LIN_ID)";
202
-        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
203
-        $table_name = 'esp_message_template';
204
-        $sql        = "MTP_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
202
+		$this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
203
+		$table_name = 'esp_message_template';
204
+		$sql        = "MTP_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
205 205
 					GRP_ID int(10) unsigned NOT NULL,
206 206
 					MTP_context varchar(50) NOT NULL,
207 207
 					MTP_template_field varchar(30) NOT NULL,
208 208
 					MTP_content text NOT NULL,
209 209
 					PRIMARY KEY  (MTP_ID),
210 210
 					KEY GRP_ID (GRP_ID)";
211
-        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
212
-        $this->_get_table_manager()->dropIndex('esp_message_template_group', 'EVT_ID');
213
-        $table_name = 'esp_message_template_group';
214
-        $sql        = "GRP_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
211
+		$this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
212
+		$this->_get_table_manager()->dropIndex('esp_message_template_group', 'EVT_ID');
213
+		$table_name = 'esp_message_template_group';
214
+		$sql        = "GRP_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
215 215
 					MTP_user_id int(10) NOT NULL DEFAULT '1',
216 216
 					MTP_name varchar(245) NOT NULL DEFAULT '',
217 217
 					MTP_description varchar(245) NOT NULL DEFAULT '',
@@ -223,17 +223,17 @@  discard block
 block discarded – undo
223 223
 					MTP_is_active tinyint(1) NOT NULL DEFAULT '1',
224 224
 					PRIMARY KEY  (GRP_ID),
225 225
 					KEY MTP_user_id (MTP_user_id)";
226
-        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
227
-        $table_name = 'esp_event_message_template';
228
-        $sql        = "EMT_ID bigint(20) unsigned NOT NULL AUTO_INCREMENT,
226
+		$this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
227
+		$table_name = 'esp_event_message_template';
228
+		$sql        = "EMT_ID bigint(20) unsigned NOT NULL AUTO_INCREMENT,
229 229
 					EVT_ID bigint(20) unsigned NOT NULL DEFAULT 0,
230 230
 					GRP_ID int(10) unsigned NOT NULL DEFAULT 0,
231 231
 					PRIMARY KEY  (EMT_ID),
232 232
 					KEY EVT_ID (EVT_ID),
233 233
 					KEY GRP_ID (GRP_ID)";
234
-        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
235
-        $table_name = 'esp_payment';
236
-        $sql        = "PAY_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
234
+		$this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
235
+		$table_name = 'esp_payment';
236
+		$sql        = "PAY_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
237 237
 					TXN_ID int(10) unsigned DEFAULT NULL,
238 238
 					STS_ID varchar(3) COLLATE utf8_bin DEFAULT NULL,
239 239
 					PAY_timestamp datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
@@ -249,28 +249,28 @@  discard block
 block discarded – undo
249 249
 					PRIMARY KEY  (PAY_ID),
250 250
 					KEY TXN_ID (TXN_ID),
251 251
 					KEY PAY_timestamp (PAY_timestamp)";
252
-        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB ');
253
-        $table_name = "esp_ticket_price";
254
-        $sql        = "TKP_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
252
+		$this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB ');
253
+		$table_name = "esp_ticket_price";
254
+		$sql        = "TKP_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
255 255
 					  TKT_ID int(10) unsigned NOT NULL,
256 256
 					  PRC_ID int(10) unsigned NOT NULL,
257 257
 					  PRIMARY KEY  (TKP_ID)";
258
-        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
259
-        $table_name = "esp_datetime_ticket";
260
-        $sql        = "DTK_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
258
+		$this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
259
+		$table_name = "esp_datetime_ticket";
260
+		$sql        = "DTK_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
261 261
 					  DTT_ID int(10) unsigned NOT NULL,
262 262
 					  TKT_ID int(10) unsigned NOT NULL,
263 263
 					  PRIMARY KEY  (DTK_ID)";
264
-        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
265
-        $table_name = "esp_ticket_template";
266
-        $sql        = "TTM_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
264
+		$this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
265
+		$table_name = "esp_ticket_template";
266
+		$sql        = "TTM_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
267 267
 					  TTM_name varchar(45) NOT NULL,
268 268
 					  TTM_description text,
269 269
 					  TTM_file varchar(45),
270 270
 					  PRIMARY KEY  (TTM_ID)";
271
-        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
272
-        $table_name = 'esp_question';
273
-        $sql        = 'QST_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
271
+		$this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
272
+		$table_name = 'esp_question';
273
+		$sql        = 'QST_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
274 274
 					QST_display_text text NOT NULL,
275 275
 					QST_admin_label varchar(255) NOT NULL,
276 276
 					QST_system varchar(25) DEFAULT NULL,
@@ -282,25 +282,25 @@  discard block
 block discarded – undo
282 282
 					QST_wp_user bigint(20) unsigned NULL,
283 283
 					QST_deleted tinyint(1) unsigned NOT NULL DEFAULT 0,
284 284
 					PRIMARY KEY  (QST_ID)';
285
-        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
286
-        $table_name = 'esp_question_group_question';
287
-        $sql        = "QGQ_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
285
+		$this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
286
+		$table_name = 'esp_question_group_question';
287
+		$sql        = "QGQ_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
288 288
 					QSG_ID int(10) unsigned NOT NULL,
289 289
 					QST_ID int(10) unsigned NOT NULL,
290 290
 					QGQ_order int(10) unsigned NOT NULL DEFAULT 0,
291 291
 					PRIMARY KEY  (QGQ_ID) ";
292
-        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
293
-        $table_name = 'esp_question_option';
294
-        $sql        = "QSO_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
292
+		$this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
293
+		$table_name = 'esp_question_option';
294
+		$sql        = "QSO_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
295 295
 					QSO_value varchar(255) NOT NULL,
296 296
 					QSO_desc text NOT NULL,
297 297
 					QST_ID int(10) unsigned NOT NULL,
298 298
 					QSO_order int(10) unsigned NOT NULL DEFAULT 0,
299 299
 					QSO_deleted tinyint(1) unsigned NOT NULL DEFAULT 0,
300 300
 					PRIMARY KEY  (QSO_ID)";
301
-        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
302
-        $table_name = 'esp_registration';
303
-        $sql        = "REG_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
301
+		$this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
302
+		$table_name = 'esp_registration';
303
+		$sql        = "REG_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
304 304
 					  EVT_ID bigint(20) unsigned NOT NULL,
305 305
 					  ATT_ID bigint(20) unsigned NOT NULL,
306 306
 					  TXN_ID int(10) unsigned NOT NULL,
@@ -323,25 +323,25 @@  discard block
 block discarded – undo
323 323
 					  KEY STS_ID (STS_ID),
324 324
 					  KEY REG_url_link (REG_url_link),
325 325
 					  KEY REG_code (REG_code)";
326
-        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB ');
327
-        $table_name = 'esp_checkin';
328
-        $sql        = "CHK_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
326
+		$this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB ');
327
+		$table_name = 'esp_checkin';
328
+		$sql        = "CHK_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
329 329
 					REG_ID int(10) unsigned NOT NULL,
330 330
 					DTT_ID int(10) unsigned NOT NULL,
331 331
 					CHK_in tinyint(1) unsigned NOT NULL DEFAULT 1,
332 332
 					CHK_timestamp datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
333 333
 					PRIMARY KEY  (CHK_ID)";
334
-        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
335
-        $table_name = 'esp_state';
336
-        $sql        = "STA_ID smallint(5) unsigned NOT NULL AUTO_INCREMENT,
334
+		$this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
335
+		$table_name = 'esp_state';
336
+		$sql        = "STA_ID smallint(5) unsigned NOT NULL AUTO_INCREMENT,
337 337
 					  CNT_ISO varchar(2) COLLATE utf8_bin NOT NULL,
338 338
 					  STA_abbrev varchar(6) COLLATE utf8_bin NOT NULL,
339 339
 					  STA_name varchar(100) COLLATE utf8_bin NOT NULL,
340 340
 					  STA_active tinyint(1) DEFAULT '1',
341 341
 					  PRIMARY KEY  (STA_ID)";
342
-        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
343
-        $table_name = 'esp_status';
344
-        $sql        = "STS_ID varchar(3) COLLATE utf8_bin NOT NULL,
342
+		$this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
343
+		$table_name = 'esp_status';
344
+		$sql        = "STS_ID varchar(3) COLLATE utf8_bin NOT NULL,
345 345
 					  STS_code varchar(45) COLLATE utf8_bin NOT NULL,
346 346
 					  STS_type set('event','registration','transaction','payment','email') COLLATE utf8_bin NOT NULL,
347 347
 					  STS_can_edit tinyint(1) NOT NULL DEFAULT 0,
@@ -349,9 +349,9 @@  discard block
 block discarded – undo
349 349
 					  STS_open tinyint(1) NOT NULL DEFAULT 1,
350 350
 					  UNIQUE KEY STS_ID_UNIQUE (STS_ID),
351 351
 					  KEY STS_type (STS_type)";
352
-        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
353
-        $table_name = 'esp_transaction';
354
-        $sql        = "TXN_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
352
+		$this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
353
+		$table_name = 'esp_transaction';
354
+		$sql        = "TXN_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
355 355
 					  TXN_timestamp datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
356 356
 					  TXN_total decimal(10,3) DEFAULT '0.00',
357 357
 					  TXN_paid decimal(10,3) NOT NULL DEFAULT '0.00',
@@ -362,9 +362,9 @@  discard block
 block discarded – undo
362 362
 					  PRIMARY KEY  (TXN_ID),
363 363
 					  KEY TXN_timestamp (TXN_timestamp),
364 364
 					  KEY STS_ID (STS_ID)";
365
-        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
366
-        $table_name = 'esp_venue_meta';
367
-        $sql        = "VNUM_ID int(11) NOT NULL AUTO_INCREMENT,
365
+		$this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
366
+		$table_name = 'esp_venue_meta';
367
+		$sql        = "VNUM_ID int(11) NOT NULL AUTO_INCREMENT,
368 368
 			VNU_ID bigint(20) unsigned NOT NULL DEFAULT 0,
369 369
 			VNU_address varchar(255) DEFAULT NULL,
370 370
 			VNU_address2 varchar(255) DEFAULT NULL,
@@ -382,10 +382,10 @@  discard block
 block discarded – undo
382 382
 			PRIMARY KEY  (VNUM_ID),
383 383
 			KEY STA_ID (STA_ID),
384 384
 			KEY CNT_ISO (CNT_ISO)";
385
-        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
386
-        // modified tables
387
-        $table_name = "esp_price";
388
-        $sql        = "PRC_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
385
+		$this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
386
+		// modified tables
387
+		$table_name = "esp_price";
388
+		$sql        = "PRC_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
389 389
 					  PRT_ID tinyint(3) unsigned NOT NULL,
390 390
 					  PRC_amount decimal(10,3) NOT NULL DEFAULT '0.00',
391 391
 					  PRC_name varchar(245) NOT NULL,
@@ -397,9 +397,9 @@  discard block
 block discarded – undo
397 397
 					  PRC_wp_user bigint(20) unsigned NULL,
398 398
 					  PRC_parent int(10) unsigned DEFAULT 0,
399 399
 					  PRIMARY KEY  (PRC_ID)";
400
-        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
401
-        $table_name = "esp_price_type";
402
-        $sql        = "PRT_ID tinyint(3) unsigned NOT NULL AUTO_INCREMENT,
400
+		$this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
401
+		$table_name = "esp_price_type";
402
+		$sql        = "PRT_ID tinyint(3) unsigned NOT NULL AUTO_INCREMENT,
403 403
 				  PRT_name varchar(45) NOT NULL,
404 404
 				  PBT_ID tinyint(3) unsigned NOT NULL DEFAULT '1',
405 405
 				  PRT_is_percent tinyint(1) NOT NULL DEFAULT '0',
@@ -408,9 +408,9 @@  discard block
 block discarded – undo
408 408
 				  PRT_deleted tinyint(1) NOT NULL DEFAULT '0',
409 409
 				  UNIQUE KEY PRT_name_UNIQUE (PRT_name),
410 410
 				  PRIMARY KEY  (PRT_ID)";
411
-        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB ');
412
-        $table_name = "esp_ticket";
413
-        $sql        = "TKT_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
411
+		$this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB ');
412
+		$table_name = "esp_ticket";
413
+		$sql        = "TKT_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
414 414
 					  TTM_ID int(10) unsigned NOT NULL,
415 415
 					  TKT_name varchar(245) NOT NULL DEFAULT '',
416 416
 					  TKT_description text NOT NULL,
@@ -431,10 +431,10 @@  discard block
 block discarded – undo
431 431
 					  TKT_parent int(10) unsigned DEFAULT '0',
432 432
 					  TKT_deleted tinyint(1) NOT NULL DEFAULT '0',
433 433
 					  PRIMARY KEY  (TKT_ID)";
434
-        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
435
-        $this->_get_table_manager()->dropIndex('esp_question_group', 'QSG_identifier_UNIQUE');
436
-        $table_name = 'esp_question_group';
437
-        $sql        = 'QSG_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
434
+		$this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
435
+		$this->_get_table_manager()->dropIndex('esp_question_group', 'QSG_identifier_UNIQUE');
436
+		$table_name = 'esp_question_group';
437
+		$sql        = 'QSG_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
438 438
 					QSG_name varchar(255) NOT NULL,
439 439
 					QSG_identifier varchar(100) NOT NULL,
440 440
 					QSG_desc text NULL,
@@ -446,137 +446,137 @@  discard block
 block discarded – undo
446 446
 					QSG_wp_user bigint(20) unsigned NULL,
447 447
 					PRIMARY KEY  (QSG_ID),
448 448
 					UNIQUE KEY QSG_identifier_UNIQUE (QSG_identifier ASC)';
449
-        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
450
-        $script_4_1_defaults = EE_Registry::instance()->load_dms('Core_4_1_0');
451
-        // (because many need to convert old string states to foreign keys into the states table)
452
-        $script_4_1_defaults->insert_default_states();
453
-        $script_4_1_defaults->insert_default_countries();
454
-        // schema on price, price_types and tickets has changed so use the DEFAULT method in here instead of 4.1's and later.
455
-        $this->insert_default_price_types();
456
-        $this->insert_default_prices();
457
-        $this->insert_default_tickets();
458
-        // setting up the config wp option pretty well counts as a 'schema change', or at least should happen ehre
459
-        EE_Config::instance()->update_espresso_config(false, true);
460
-        return true;
461
-    }
449
+		$this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
450
+		$script_4_1_defaults = EE_Registry::instance()->load_dms('Core_4_1_0');
451
+		// (because many need to convert old string states to foreign keys into the states table)
452
+		$script_4_1_defaults->insert_default_states();
453
+		$script_4_1_defaults->insert_default_countries();
454
+		// schema on price, price_types and tickets has changed so use the DEFAULT method in here instead of 4.1's and later.
455
+		$this->insert_default_price_types();
456
+		$this->insert_default_prices();
457
+		$this->insert_default_tickets();
458
+		// setting up the config wp option pretty well counts as a 'schema change', or at least should happen ehre
459
+		EE_Config::instance()->update_espresso_config(false, true);
460
+		return true;
461
+	}
462 462
 
463 463
 
464
-    /**
465
-     * @return boolean
466
-     */
467
-    public function schema_changes_after_migration()
468
-    {
469
-        return true;
470
-    }
464
+	/**
465
+	 * @return boolean
466
+	 */
467
+	public function schema_changes_after_migration()
468
+	{
469
+		return true;
470
+	}
471 471
 
472 472
 
473
-    public function migration_page_hooks()
474
-    {
475
-    }
473
+	public function migration_page_hooks()
474
+	{
475
+	}
476 476
 
477 477
 
478
-    /**
479
-     * insert_default_price_types
480
-     *
481
-     * @return void
482
-     * @throws EE_Error
483
-     * @throws ReflectionException
484
-     * @since 4.5.0
485
-     */
486
-    public function insert_default_price_types()
487
-    {
488
-        global $wpdb;
489
-        $price_type_table = $wpdb->prefix . "esp_price_type";
490
-        if ($this->_get_table_analysis()->tableExists($price_type_table)) {
491
-            $SQL               = 'SELECT COUNT(PRT_ID) FROM ' . $price_type_table;
492
-            $price_types_exist = $wpdb->get_var($SQL);
493
-            if (! $price_types_exist) {
494
-                $user_id = EEH_Activation::get_default_creator_id();
495
-                $user_id = $user_id ?: 0;
496
-                $SQL     = "INSERT INTO $price_type_table ( PRT_ID, PRT_name, PBT_ID, PRT_is_percent, PRT_order, PRT_wp_user, PRT_deleted ) VALUES
478
+	/**
479
+	 * insert_default_price_types
480
+	 *
481
+	 * @return void
482
+	 * @throws EE_Error
483
+	 * @throws ReflectionException
484
+	 * @since 4.5.0
485
+	 */
486
+	public function insert_default_price_types()
487
+	{
488
+		global $wpdb;
489
+		$price_type_table = $wpdb->prefix . "esp_price_type";
490
+		if ($this->_get_table_analysis()->tableExists($price_type_table)) {
491
+			$SQL               = 'SELECT COUNT(PRT_ID) FROM ' . $price_type_table;
492
+			$price_types_exist = $wpdb->get_var($SQL);
493
+			if (! $price_types_exist) {
494
+				$user_id = EEH_Activation::get_default_creator_id();
495
+				$user_id = $user_id ?: 0;
496
+				$SQL     = "INSERT INTO $price_type_table ( PRT_ID, PRT_name, PBT_ID, PRT_is_percent, PRT_order, PRT_wp_user, PRT_deleted ) VALUES
497 497
 							(1, '" . esc_html__('Base Price', 'event_espresso') . "', 1,  0, 0, $user_id, 0),
498 498
 							(2, '" . esc_html__('Percent Discount', 'event_espresso') . "', 2,  1, 20, $user_id, 0),
499 499
 							(3, '" . esc_html__('Dollar Discount', 'event_espresso') . "', 2,  0, 30, $user_id, 0),
500 500
 							(4, '" . esc_html__('Percent Surcharge', 'event_espresso') . "', 3,  1, 40, $user_id,  0),
501 501
 							(5, '" . esc_html__('Dollar Surcharge', 'event_espresso') . "', 3,  0, 50, $user_id, 0);";
502
-                $SQL     = apply_filters('FHEE__EE_DMS_4_5_0__insert_default_price_types__SQL', $SQL);
503
-                $wpdb->query($SQL);
504
-            }
505
-        }
506
-    }
502
+				$SQL     = apply_filters('FHEE__EE_DMS_4_5_0__insert_default_price_types__SQL', $SQL);
503
+				$wpdb->query($SQL);
504
+			}
505
+		}
506
+	}
507 507
 
508 508
 
509
-    /**
510
-     * insert DEFAULT prices.
511
-     *  If we're INSTALLING 4.x CAF, then we add a few extra DEFAULT prices
512
-     * when EEH_Activaion's initialize_db_content is called via  ahook in
513
-     * EE_Brewing_regular
514
-     *
515
-     * @return void
516
-     * @throws EE_Error
517
-     * @throws ReflectionException
518
-     * @since 4.5.0
519
-     */
520
-    public function insert_default_prices()
521
-    {
522
-        global $wpdb;
523
-        $price_table = $wpdb->prefix . "esp_price";
524
-        if ($this->_get_table_analysis()->tableExists($price_table)) {
525
-            $SQL          = 'SELECT COUNT(PRC_ID) FROM ' . $price_table;
526
-            $prices_exist = $wpdb->get_var($SQL);
527
-            if (! $prices_exist) {
528
-                $user_id = EEH_Activation::get_default_creator_id();
529
-                $user_id = $user_id ?: 0;
530
-                $SQL     = "INSERT INTO $price_table
509
+	/**
510
+	 * insert DEFAULT prices.
511
+	 *  If we're INSTALLING 4.x CAF, then we add a few extra DEFAULT prices
512
+	 * when EEH_Activaion's initialize_db_content is called via  ahook in
513
+	 * EE_Brewing_regular
514
+	 *
515
+	 * @return void
516
+	 * @throws EE_Error
517
+	 * @throws ReflectionException
518
+	 * @since 4.5.0
519
+	 */
520
+	public function insert_default_prices()
521
+	{
522
+		global $wpdb;
523
+		$price_table = $wpdb->prefix . "esp_price";
524
+		if ($this->_get_table_analysis()->tableExists($price_table)) {
525
+			$SQL          = 'SELECT COUNT(PRC_ID) FROM ' . $price_table;
526
+			$prices_exist = $wpdb->get_var($SQL);
527
+			if (! $prices_exist) {
528
+				$user_id = EEH_Activation::get_default_creator_id();
529
+				$user_id = $user_id ?: 0;
530
+				$SQL     = "INSERT INTO $price_table
531 531
 							(PRC_ID, PRT_ID, PRC_amount, PRC_name, PRC_desc,  PRC_is_default, PRC_overrides, PRC_wp_user, PRC_order, PRC_deleted, PRC_parent ) VALUES
532 532
 							(1, 1, '0.00', 'Admission', '', 1, NULL, $user_id, 0, 0, 0);";
533
-                $SQL     = apply_filters('FHEE__EE_DMS_4_5_0__insert_default_prices__SQL', $SQL);
534
-                $wpdb->query($SQL);
535
-            }
536
-        }
537
-    }
533
+				$SQL     = apply_filters('FHEE__EE_DMS_4_5_0__insert_default_prices__SQL', $SQL);
534
+				$wpdb->query($SQL);
535
+			}
536
+		}
537
+	}
538 538
 
539 539
 
540
-    /**
541
-     * insert DEFAULT ticket
542
-     * Almost identical to EE_DMS_Core_4_3_0::insert_default_tickets, except is aware of the TKT_wp_user field
543
-     *
544
-     * @return void
545
-     * @throws EE_Error
546
-     * @throws ReflectionException
547
-     * @since 4.5.0
548
-     */
549
-    public function insert_default_tickets()
550
-    {
551
-        global $wpdb;
552
-        $ticket_table = $wpdb->prefix . "esp_ticket";
553
-        if ($this->_get_table_analysis()->tableExists($ticket_table)) {
554
-            $SQL           = 'SELECT COUNT(TKT_ID) FROM ' . $ticket_table;
555
-            $tickets_exist = $wpdb->get_var($SQL);
556
-            if (! $tickets_exist) {
557
-                $user_id = EEH_Activation::get_default_creator_id();
558
-                $user_id = $user_id ?: 0;
559
-                $SQL     = "INSERT INTO $ticket_table
540
+	/**
541
+	 * insert DEFAULT ticket
542
+	 * Almost identical to EE_DMS_Core_4_3_0::insert_default_tickets, except is aware of the TKT_wp_user field
543
+	 *
544
+	 * @return void
545
+	 * @throws EE_Error
546
+	 * @throws ReflectionException
547
+	 * @since 4.5.0
548
+	 */
549
+	public function insert_default_tickets()
550
+	{
551
+		global $wpdb;
552
+		$ticket_table = $wpdb->prefix . "esp_ticket";
553
+		if ($this->_get_table_analysis()->tableExists($ticket_table)) {
554
+			$SQL           = 'SELECT COUNT(TKT_ID) FROM ' . $ticket_table;
555
+			$tickets_exist = $wpdb->get_var($SQL);
556
+			if (! $tickets_exist) {
557
+				$user_id = EEH_Activation::get_default_creator_id();
558
+				$user_id = $user_id ?: 0;
559
+				$SQL     = "INSERT INTO $ticket_table
560 560
 					( TKT_ID, TTM_ID, TKT_name, TKT_description, TKT_qty, TKT_sold, TKT_uses, TKT_required, TKT_min, TKT_max, TKT_price, TKT_start_date, TKT_end_date, TKT_taxable, TKT_order, TKT_row, TKT_is_default, TKT_parent, TKT_wp_user, TKT_deleted ) VALUES
561 561
 					( 1, 0, '"
562
-                           . esc_html__("Free Ticket", "event_espresso")
563
-                           . "', '', 100, 0, -1, 0, 0, -1, 0.00, '0000-00-00 00:00:00', '0000-00-00 00:00:00', 0, 0, 1, 1, 0, $user_id, 0);";
564
-                $SQL     = apply_filters('FHEE__EE_DMS_4_5_0__insert_default_tickets__SQL', $SQL);
565
-                $wpdb->query($SQL);
566
-            }
567
-        }
568
-        $ticket_price_table = $wpdb->prefix . "esp_ticket_price";
569
-        if ($this->_get_table_analysis()->tableExists($ticket_price_table)) {
570
-            $SQL              = 'SELECT COUNT(TKP_ID) FROM ' . $ticket_price_table;
571
-            $ticket_prc_exist = $wpdb->get_var($SQL);
572
-            if (! $ticket_prc_exist) {
573
-                $SQL = "INSERT INTO $ticket_price_table
562
+						   . esc_html__("Free Ticket", "event_espresso")
563
+						   . "', '', 100, 0, -1, 0, 0, -1, 0.00, '0000-00-00 00:00:00', '0000-00-00 00:00:00', 0, 0, 1, 1, 0, $user_id, 0);";
564
+				$SQL     = apply_filters('FHEE__EE_DMS_4_5_0__insert_default_tickets__SQL', $SQL);
565
+				$wpdb->query($SQL);
566
+			}
567
+		}
568
+		$ticket_price_table = $wpdb->prefix . "esp_ticket_price";
569
+		if ($this->_get_table_analysis()->tableExists($ticket_price_table)) {
570
+			$SQL              = 'SELECT COUNT(TKP_ID) FROM ' . $ticket_price_table;
571
+			$ticket_prc_exist = $wpdb->get_var($SQL);
572
+			if (! $ticket_prc_exist) {
573
+				$SQL = "INSERT INTO $ticket_price_table
574 574
 				( TKP_ID, TKT_ID, PRC_ID ) VALUES
575 575
 				( 1, 1, 1 )
576 576
 				";
577
-                $SQL = apply_filters('FHEE__EE_DMS_4_5_0__insert_default_tickets__SQL__ticket_price', $SQL);
578
-                $wpdb->query($SQL);
579
-            }
580
-        }
581
-    }
577
+				$SQL = apply_filters('FHEE__EE_DMS_4_5_0__insert_default_tickets__SQL__ticket_price', $SQL);
578
+				$wpdb->query($SQL);
579
+			}
580
+		}
581
+	}
582 582
 }
Please login to merge, or discard this patch.
Spacing   +24 added lines, -24 removed lines patch added patch discarded remove patch
@@ -7,12 +7,12 @@  discard block
 block discarded – undo
7 7
 // unfortunately, this needs to be done upon INCLUSION of this file,
8 8
 // instead of construction, because it only gets constructed on first page load
9 9
 // (all other times it gets resurrected from a wordpress option)
10
-$stages            = glob(EE_CORE . 'data_migration_scripts/4_5_0_stages/*');
10
+$stages            = glob(EE_CORE.'data_migration_scripts/4_5_0_stages/*');
11 11
 $class_to_filepath = [];
12 12
 foreach ($stages as $filepath) {
13 13
     $matches = [];
14 14
     preg_match('~4_5_0_stages/(.*).dmsstage.php~', $filepath, $matches);
15
-    $class_to_filepath[ $matches[1] ] = $filepath;
15
+    $class_to_filepath[$matches[1]] = $filepath;
16 16
 }
17 17
 // give addons a chance to autoload their stages too
18 18
 $class_to_filepath = apply_filters('FHEE__EE_DMS_4_5_0__autoloaded_stages', $class_to_filepath);
@@ -63,10 +63,10 @@  discard block
 block discarded – undo
63 63
         ) {
64 64
 //          echo "$version_string can be migrated from";
65 65
             return true;
66
-        } elseif (! $version_string) {
66
+        } elseif ( ! $version_string) {
67 67
 //          echo "no version string provided: $version_string";
68 68
             // no version string provided... this must be pre 4.3
69
-            return false;// changed mind. dont want people thinking they should migrate yet because they cant
69
+            return false; // changed mind. dont want people thinking they should migrate yet because they cant
70 70
         } else {
71 71
 //          echo "$version_string doesnt apply";
72 72
             return false;
@@ -82,7 +82,7 @@  discard block
 block discarded – undo
82 82
     public function schema_changes_before_migration()
83 83
     {
84 84
         // relies on 4.1's EEH_Activation::create_table
85
-        require_once(EE_HELPERS . 'EEH_Activation.helper.php');
85
+        require_once(EE_HELPERS.'EEH_Activation.helper.php');
86 86
         $table_name = 'esp_answer';
87 87
         $sql        = "ANS_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
88 88
 					REG_ID int(10) unsigned NOT NULL,
@@ -486,20 +486,20 @@  discard block
 block discarded – undo
486 486
     public function insert_default_price_types()
487 487
     {
488 488
         global $wpdb;
489
-        $price_type_table = $wpdb->prefix . "esp_price_type";
489
+        $price_type_table = $wpdb->prefix."esp_price_type";
490 490
         if ($this->_get_table_analysis()->tableExists($price_type_table)) {
491
-            $SQL               = 'SELECT COUNT(PRT_ID) FROM ' . $price_type_table;
491
+            $SQL               = 'SELECT COUNT(PRT_ID) FROM '.$price_type_table;
492 492
             $price_types_exist = $wpdb->get_var($SQL);
493
-            if (! $price_types_exist) {
493
+            if ( ! $price_types_exist) {
494 494
                 $user_id = EEH_Activation::get_default_creator_id();
495 495
                 $user_id = $user_id ?: 0;
496 496
                 $SQL     = "INSERT INTO $price_type_table ( PRT_ID, PRT_name, PBT_ID, PRT_is_percent, PRT_order, PRT_wp_user, PRT_deleted ) VALUES
497
-							(1, '" . esc_html__('Base Price', 'event_espresso') . "', 1,  0, 0, $user_id, 0),
498
-							(2, '" . esc_html__('Percent Discount', 'event_espresso') . "', 2,  1, 20, $user_id, 0),
499
-							(3, '" . esc_html__('Dollar Discount', 'event_espresso') . "', 2,  0, 30, $user_id, 0),
500
-							(4, '" . esc_html__('Percent Surcharge', 'event_espresso') . "', 3,  1, 40, $user_id,  0),
501
-							(5, '" . esc_html__('Dollar Surcharge', 'event_espresso') . "', 3,  0, 50, $user_id, 0);";
502
-                $SQL     = apply_filters('FHEE__EE_DMS_4_5_0__insert_default_price_types__SQL', $SQL);
497
+							(1, '".esc_html__('Base Price', 'event_espresso')."', 1,  0, 0, $user_id, 0),
498
+							(2, '".esc_html__('Percent Discount', 'event_espresso')."', 2,  1, 20, $user_id, 0),
499
+							(3, '".esc_html__('Dollar Discount', 'event_espresso')."', 2,  0, 30, $user_id, 0),
500
+							(4, '".esc_html__('Percent Surcharge', 'event_espresso')."', 3,  1, 40, $user_id,  0),
501
+							(5, '".esc_html__('Dollar Surcharge', 'event_espresso')."', 3,  0, 50, $user_id, 0);";
502
+                $SQL = apply_filters('FHEE__EE_DMS_4_5_0__insert_default_price_types__SQL', $SQL);
503 503
                 $wpdb->query($SQL);
504 504
             }
505 505
         }
@@ -520,11 +520,11 @@  discard block
 block discarded – undo
520 520
     public function insert_default_prices()
521 521
     {
522 522
         global $wpdb;
523
-        $price_table = $wpdb->prefix . "esp_price";
523
+        $price_table = $wpdb->prefix."esp_price";
524 524
         if ($this->_get_table_analysis()->tableExists($price_table)) {
525
-            $SQL          = 'SELECT COUNT(PRC_ID) FROM ' . $price_table;
525
+            $SQL          = 'SELECT COUNT(PRC_ID) FROM '.$price_table;
526 526
             $prices_exist = $wpdb->get_var($SQL);
527
-            if (! $prices_exist) {
527
+            if ( ! $prices_exist) {
528 528
                 $user_id = EEH_Activation::get_default_creator_id();
529 529
                 $user_id = $user_id ?: 0;
530 530
                 $SQL     = "INSERT INTO $price_table
@@ -549,11 +549,11 @@  discard block
 block discarded – undo
549 549
     public function insert_default_tickets()
550 550
     {
551 551
         global $wpdb;
552
-        $ticket_table = $wpdb->prefix . "esp_ticket";
552
+        $ticket_table = $wpdb->prefix."esp_ticket";
553 553
         if ($this->_get_table_analysis()->tableExists($ticket_table)) {
554
-            $SQL           = 'SELECT COUNT(TKT_ID) FROM ' . $ticket_table;
554
+            $SQL           = 'SELECT COUNT(TKT_ID) FROM '.$ticket_table;
555 555
             $tickets_exist = $wpdb->get_var($SQL);
556
-            if (! $tickets_exist) {
556
+            if ( ! $tickets_exist) {
557 557
                 $user_id = EEH_Activation::get_default_creator_id();
558 558
                 $user_id = $user_id ?: 0;
559 559
                 $SQL     = "INSERT INTO $ticket_table
@@ -561,15 +561,15 @@  discard block
 block discarded – undo
561 561
 					( 1, 0, '"
562 562
                            . esc_html__("Free Ticket", "event_espresso")
563 563
                            . "', '', 100, 0, -1, 0, 0, -1, 0.00, '0000-00-00 00:00:00', '0000-00-00 00:00:00', 0, 0, 1, 1, 0, $user_id, 0);";
564
-                $SQL     = apply_filters('FHEE__EE_DMS_4_5_0__insert_default_tickets__SQL', $SQL);
564
+                $SQL = apply_filters('FHEE__EE_DMS_4_5_0__insert_default_tickets__SQL', $SQL);
565 565
                 $wpdb->query($SQL);
566 566
             }
567 567
         }
568
-        $ticket_price_table = $wpdb->prefix . "esp_ticket_price";
568
+        $ticket_price_table = $wpdb->prefix."esp_ticket_price";
569 569
         if ($this->_get_table_analysis()->tableExists($ticket_price_table)) {
570
-            $SQL              = 'SELECT COUNT(TKP_ID) FROM ' . $ticket_price_table;
570
+            $SQL              = 'SELECT COUNT(TKP_ID) FROM '.$ticket_price_table;
571 571
             $ticket_prc_exist = $wpdb->get_var($SQL);
572
-            if (! $ticket_prc_exist) {
572
+            if ( ! $ticket_prc_exist) {
573 573
                 $SQL = "INSERT INTO $ticket_price_table
574 574
 				( TKP_ID, TKT_ID, PRC_ID ) VALUES
575 575
 				( 1, 1, 1 )
Please login to merge, or discard this patch.
core/data_migration_scripts/EE_DMS_Core_4_6_0.dms.php 2 patches
Indentation   +283 added lines, -283 removed lines patch added patch discarded remove patch
@@ -10,9 +10,9 @@  discard block
 block discarded – undo
10 10
 $stages            = glob(EE_CORE . 'data_migration_scripts/4_6_0_stages/*');
11 11
 $class_to_filepath = [];
12 12
 foreach ($stages as $filepath) {
13
-    $matches = [];
14
-    preg_match('~4_6_0_stages/(.*).dmsstage.php~', $filepath, $matches);
15
-    $class_to_filepath[ $matches[1] ] = $filepath;
13
+	$matches = [];
14
+	preg_match('~4_6_0_stages/(.*).dmsstage.php~', $filepath, $matches);
15
+	$class_to_filepath[ $matches[1] ] = $filepath;
16 16
 }
17 17
 // give addons a chance to autoload their stages too
18 18
 $class_to_filepath = apply_filters('FHEE__EE_DMS_4_6_0__autoloaded_stages', $class_to_filepath);
@@ -32,73 +32,73 @@  discard block
 block discarded – undo
32 32
  */
33 33
 class EE_DMS_Core_4_6_0 extends EE_Data_Migration_Script_Base
34 34
 {
35
-    /**
36
-     * return EE_DMS_Core_4_6_0
37
-     *
38
-     * @param TableManager  $table_manager
39
-     * @param TableAnalysis $table_analysis
40
-     */
41
-    public function __construct(TableManager $table_manager = null, TableAnalysis $table_analysis = null)
42
-    {
43
-        $this->_pretty_name      = esc_html__("Data Update to Event Espresso 4.6.0", "event_espresso");
44
-        $this->_priority         = 10;
45
-        $this->_migration_stages = [
46
-            new EE_DMS_4_6_0_gateways(),
47
-            new EE_DMS_4_6_0_question_types(),
48
-            new EE_DMS_4_6_0_country_system_question(),
49
-            new EE_DMS_4_6_0_state_system_question(),
50
-            new EE_DMS_4_6_0_billing_info(),
51
-            new EE_DMS_4_6_0_transactions(),
52
-            new EE_DMS_4_6_0_payments(),
53
-            new EE_DMS_4_6_0_invoice_settings(),
54
-        ];
55
-        parent::__construct($table_manager, $table_analysis);
56
-    }
35
+	/**
36
+	 * return EE_DMS_Core_4_6_0
37
+	 *
38
+	 * @param TableManager  $table_manager
39
+	 * @param TableAnalysis $table_analysis
40
+	 */
41
+	public function __construct(TableManager $table_manager = null, TableAnalysis $table_analysis = null)
42
+	{
43
+		$this->_pretty_name      = esc_html__("Data Update to Event Espresso 4.6.0", "event_espresso");
44
+		$this->_priority         = 10;
45
+		$this->_migration_stages = [
46
+			new EE_DMS_4_6_0_gateways(),
47
+			new EE_DMS_4_6_0_question_types(),
48
+			new EE_DMS_4_6_0_country_system_question(),
49
+			new EE_DMS_4_6_0_state_system_question(),
50
+			new EE_DMS_4_6_0_billing_info(),
51
+			new EE_DMS_4_6_0_transactions(),
52
+			new EE_DMS_4_6_0_payments(),
53
+			new EE_DMS_4_6_0_invoice_settings(),
54
+		];
55
+		parent::__construct($table_manager, $table_analysis);
56
+	}
57 57
 
58 58
 
59
-    /**
60
-     * @param array $version_array
61
-     * @return bool
62
-     */
63
-    public function can_migrate_from_version($version_array)
64
-    {
65
-        $version_string = $version_array['Core'];
66
-        if (
67
-            version_compare($version_string, '4.6.0.decaf', '<') && version_compare(
68
-                $version_string,
69
-                '4.5.0.decaf',
70
-                '>='
71
-            )
72
-        ) {
59
+	/**
60
+	 * @param array $version_array
61
+	 * @return bool
62
+	 */
63
+	public function can_migrate_from_version($version_array)
64
+	{
65
+		$version_string = $version_array['Core'];
66
+		if (
67
+			version_compare($version_string, '4.6.0.decaf', '<') && version_compare(
68
+				$version_string,
69
+				'4.5.0.decaf',
70
+				'>='
71
+			)
72
+		) {
73 73
 //          echo "$version_string can be migrated from";
74
-            return true;
75
-        } elseif (! $version_string) {
74
+			return true;
75
+		} elseif (! $version_string) {
76 76
 //          echo "no version string provided: $version_string";
77
-            // no version string provided... this must be pre 4.3
78
-            return false;// changed mind. dont want people thinking they should migrate yet because they cant
79
-        } else {
77
+			// no version string provided... this must be pre 4.3
78
+			return false;// changed mind. dont want people thinking they should migrate yet because they cant
79
+		} else {
80 80
 //          echo "$version_string doesnt apply";
81
-            return false;
82
-        }
83
-    }
81
+			return false;
82
+		}
83
+	}
84 84
 
85 85
 
86
-    /**
87
-     * @return bool
88
-     */
89
-    public function schema_changes_before_migration()
90
-    {
91
-        // relies on 4.1's EEH_Activation::create_table
92
-        require_once(EE_HELPERS . 'EEH_Activation.helper.php');
93
-        $table_name = 'esp_answer';
94
-        $sql        = "ANS_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
86
+	/**
87
+	 * @return bool
88
+	 */
89
+	public function schema_changes_before_migration()
90
+	{
91
+		// relies on 4.1's EEH_Activation::create_table
92
+		require_once(EE_HELPERS . 'EEH_Activation.helper.php');
93
+		$table_name = 'esp_answer';
94
+		$sql        = "ANS_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
95 95
 					REG_ID int(10) unsigned NOT NULL,
96 96
 					QST_ID int(10) unsigned NOT NULL,
97 97
 					ANS_value text NOT NULL,
98 98
 					PRIMARY KEY  (ANS_ID)";
99
-        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
100
-        $table_name = 'esp_attendee_meta';
101
-        $sql        = "ATTM_ID int(10) unsigned NOT	NULL AUTO_INCREMENT,
99
+		$this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
100
+		$table_name = 'esp_attendee_meta';
101
+		$sql        = "ATTM_ID int(10) unsigned NOT	NULL AUTO_INCREMENT,
102 102
 						ATT_ID bigint(20) unsigned NOT NULL,
103 103
 						ATT_fname varchar(45) NOT NULL,
104 104
 						ATT_lname varchar(45) NOT	NULL,
@@ -114,9 +114,9 @@  discard block
 block discarded – undo
114 114
 								KEY ATT_fname (ATT_fname),
115 115
 								KEY ATT_lname (ATT_lname),
116 116
 								KEY ATT_email (ATT_email(191))";
117
-        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB ');
118
-        $table_name = 'esp_country';
119
-        $sql        = "CNT_ISO varchar(2) COLLATE utf8_bin NOT NULL,
117
+		$this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB ');
118
+		$table_name = 'esp_country';
119
+		$sql        = "CNT_ISO varchar(2) COLLATE utf8_bin NOT NULL,
120 120
 					  CNT_ISO3 varchar(3) COLLATE utf8_bin NOT NULL,
121 121
 					  RGN_ID tinyint(3) unsigned DEFAULT NULL,
122 122
 					  CNT_name varchar(45) COLLATE utf8_bin NOT NULL,
@@ -132,18 +132,18 @@  discard block
 block discarded – undo
132 132
 					  CNT_is_EU tinyint(1) DEFAULT '0',
133 133
 					  CNT_active tinyint(1) DEFAULT '0',
134 134
 					  PRIMARY KEY  (CNT_ISO)";
135
-        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
136
-        $table_name = 'esp_currency';
137
-        $sql        = "CUR_code varchar(6) COLLATE utf8_bin NOT NULL,
135
+		$this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
136
+		$table_name = 'esp_currency';
137
+		$sql        = "CUR_code varchar(6) COLLATE utf8_bin NOT NULL,
138 138
 				CUR_single varchar(45) COLLATE utf8_bin DEFAULT 'dollar',
139 139
 				CUR_plural varchar(45) COLLATE utf8_bin DEFAULT 'dollars',
140 140
 				CUR_sign varchar(45) COLLATE utf8_bin DEFAULT '$',
141 141
 				CUR_dec_plc varchar(1) COLLATE utf8_bin NOT NULL DEFAULT '2',
142 142
 				CUR_active tinyint(1) DEFAULT '0',
143 143
 				PRIMARY KEY  (CUR_code)";
144
-        $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
145
-        $table_name = 'esp_datetime';
146
-        $sql        = "DTT_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
144
+		$this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
145
+		$table_name = 'esp_datetime';
146
+		$sql        = "DTT_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
147 147
 				  EVT_ID bigint(20) unsigned NOT NULL,
148 148
 				  DTT_name varchar(255) NOT NULL DEFAULT '',
149 149
 				  DTT_description text NOT NULL,
@@ -158,9 +158,9 @@  discard block
 block discarded – undo
158 158
 						PRIMARY KEY  (DTT_ID),
159 159
 						KEY EVT_ID (EVT_ID),
160 160
 						KEY DTT_is_primary (DTT_is_primary)";
161
-        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
162
-        $table_name = 'esp_event_meta';
163
-        $sql        = "
161
+		$this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
162
+		$table_name = 'esp_event_meta';
163
+		$sql        = "
164 164
 			EVTM_ID int(10) NOT NULL AUTO_INCREMENT,
165 165
 			EVT_ID bigint(20) unsigned NOT NULL,
166 166
 			EVT_display_desc tinyint(1) unsigned NOT NULL DEFAULT 1,
@@ -175,31 +175,31 @@  discard block
 block discarded – undo
175 175
 			EVT_external_URL varchar(200) NULL,
176 176
 			EVT_donations tinyint(1) NULL,
177 177
 			PRIMARY KEY  (EVTM_ID)";
178
-        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
179
-        $table_name = 'esp_event_question_group';
180
-        $sql        = "EQG_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
178
+		$this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
179
+		$table_name = 'esp_event_question_group';
180
+		$sql        = "EQG_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
181 181
 					EVT_ID bigint(20) unsigned NOT NULL,
182 182
 					QSG_ID int(10) unsigned NOT NULL,
183 183
 					EQG_primary tinyint(1) unsigned NOT NULL DEFAULT 0,
184 184
 					PRIMARY KEY  (EQG_ID)";
185
-        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
186
-        $table_name = 'esp_event_venue';
187
-        $sql        = "EVV_ID int(11) NOT NULL AUTO_INCREMENT,
185
+		$this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
186
+		$table_name = 'esp_event_venue';
187
+		$sql        = "EVV_ID int(11) NOT NULL AUTO_INCREMENT,
188 188
 				EVT_ID bigint(20) unsigned NOT NULL,
189 189
 				VNU_ID bigint(20) unsigned NOT NULL,
190 190
 				EVV_primary tinyint(1) unsigned NOT NULL DEFAULT 0,
191 191
 				PRIMARY KEY  (EVV_ID)";
192
-        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
193
-        $table_name = 'esp_extra_meta';
194
-        $sql        = "EXM_ID int(11) NOT NULL AUTO_INCREMENT,
192
+		$this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
193
+		$table_name = 'esp_extra_meta';
194
+		$sql        = "EXM_ID int(11) NOT NULL AUTO_INCREMENT,
195 195
 				OBJ_ID int(11) DEFAULT NULL,
196 196
 				EXM_type varchar(45) DEFAULT NULL,
197 197
 				EXM_key varchar(45) DEFAULT NULL,
198 198
 				EXM_value text,
199 199
 				PRIMARY KEY  (EXM_ID)";
200
-        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
201
-        $table_name = 'esp_line_item';
202
-        $sql        = "LIN_ID int(11) NOT NULL AUTO_INCREMENT,
200
+		$this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
201
+		$table_name = 'esp_line_item';
202
+		$sql        = "LIN_ID int(11) NOT NULL AUTO_INCREMENT,
203 203
 				LIN_code varchar(245) NOT NULL DEFAULT '',
204 204
 				TXN_ID int(11) DEFAULT NULL,
205 205
 				LIN_name varchar(245) NOT NULL DEFAULT '',
@@ -215,9 +215,9 @@  discard block
 block discarded – undo
215 215
 				OBJ_ID int(11) DEFAULT NULL,
216 216
 				OBJ_type varchar(45)DEFAULT NULL,
217 217
 				PRIMARY KEY  (LIN_ID)";
218
-        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
219
-        $table_name = 'esp_log';
220
-        $sql        = "LOG_ID int(11) NOT NULL AUTO_INCREMENT,
218
+		$this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
219
+		$table_name = 'esp_log';
220
+		$sql        = "LOG_ID int(11) NOT NULL AUTO_INCREMENT,
221 221
 				LOG_time datetime DEFAULT NULL,
222 222
 				OBJ_ID varchar(45) DEFAULT NULL,
223 223
 				OBJ_type varchar(45) DEFAULT NULL,
@@ -225,19 +225,19 @@  discard block
 block discarded – undo
225 225
 				LOG_message text,
226 226
 				LOG_wp_user int(11) DEFAULT NULL,
227 227
 				PRIMARY KEY  (LOG_ID)";
228
-        $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
229
-        $table_name = 'esp_message_template';
230
-        $sql        = "MTP_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
228
+		$this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
229
+		$table_name = 'esp_message_template';
230
+		$sql        = "MTP_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
231 231
 					GRP_ID int(10) unsigned NOT NULL,
232 232
 					MTP_context varchar(50) NOT NULL,
233 233
 					MTP_template_field varchar(30) NOT NULL,
234 234
 					MTP_content text NOT NULL,
235 235
 					PRIMARY KEY  (MTP_ID),
236 236
 					KEY GRP_ID (GRP_ID)";
237
-        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
238
-        $this->_get_table_manager()->dropIndex('esp_message_template_group', 'EVT_ID');
239
-        $table_name = 'esp_message_template_group';
240
-        $sql        = "GRP_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
237
+		$this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
238
+		$this->_get_table_manager()->dropIndex('esp_message_template_group', 'EVT_ID');
239
+		$table_name = 'esp_message_template_group';
240
+		$sql        = "GRP_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
241 241
 					MTP_user_id int(10) NOT NULL DEFAULT '1',
242 242
 					MTP_name varchar(245) NOT NULL DEFAULT '',
243 243
 					MTP_description varchar(245) NOT NULL DEFAULT '',
@@ -249,17 +249,17 @@  discard block
 block discarded – undo
249 249
 					MTP_is_active tinyint(1) NOT NULL DEFAULT '1',
250 250
 					PRIMARY KEY  (GRP_ID),
251 251
 					KEY MTP_user_id (MTP_user_id)";
252
-        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
253
-        $table_name = 'esp_event_message_template';
254
-        $sql        = "EMT_ID bigint(20) unsigned NOT NULL AUTO_INCREMENT,
252
+		$this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
253
+		$table_name = 'esp_event_message_template';
254
+		$sql        = "EMT_ID bigint(20) unsigned NOT NULL AUTO_INCREMENT,
255 255
 					EVT_ID bigint(20) unsigned NOT NULL DEFAULT 0,
256 256
 					GRP_ID int(10) unsigned NOT NULL DEFAULT 0,
257 257
 					PRIMARY KEY  (EMT_ID),
258 258
 					KEY EVT_ID (EVT_ID),
259 259
 					KEY GRP_ID (GRP_ID)";
260
-        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
261
-        $table_name = 'esp_payment';
262
-        $sql        = "PAY_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
260
+		$this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
261
+		$table_name = 'esp_payment';
262
+		$sql        = "PAY_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
263 263
 					TXN_ID int(10) unsigned DEFAULT NULL,
264 264
 					STS_ID varchar(3) COLLATE utf8_bin DEFAULT NULL,
265 265
 					PAY_timestamp datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
@@ -276,9 +276,9 @@  discard block
 block discarded – undo
276 276
 					PRIMARY KEY  (PAY_ID),
277 277
 					KEY TXN_ID (TXN_ID),
278 278
 					KEY PAY_timestamp (PAY_timestamp)";
279
-        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB ');
280
-        $table_name = 'esp_payment_method';
281
-        $sql        = "PMD_ID int(11) NOT NULL AUTO_INCREMENT,
279
+		$this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB ');
280
+		$table_name = 'esp_payment_method';
281
+		$sql        = "PMD_ID int(11) NOT NULL AUTO_INCREMENT,
282 282
 				PMD_type varchar(124) DEFAULT NULL,
283 283
 				PMD_name varchar(255) DEFAULT NULL,
284 284
 				PMD_desc text,
@@ -293,28 +293,28 @@  discard block
 block discarded – undo
293 293
 				PMD_scope varchar(255) NULL DEFAULT 'frontend',
294 294
 				PRIMARY KEY  (PMD_ID),
295 295
 				UNIQUE KEY PMD_slug_UNIQUE (PMD_slug)";
296
-        $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB ');
297
-        $table_name = "esp_ticket_price";
298
-        $sql        = "TKP_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
296
+		$this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB ');
297
+		$table_name = "esp_ticket_price";
298
+		$sql        = "TKP_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
299 299
 					  TKT_ID int(10) unsigned NOT NULL,
300 300
 					  PRC_ID int(10) unsigned NOT NULL,
301 301
 					  PRIMARY KEY  (TKP_ID)";
302
-        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
303
-        $table_name = "esp_datetime_ticket";
304
-        $sql        = "DTK_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
302
+		$this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
303
+		$table_name = "esp_datetime_ticket";
304
+		$sql        = "DTK_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
305 305
 					  DTT_ID int(10) unsigned NOT NULL,
306 306
 					  TKT_ID int(10) unsigned NOT NULL,
307 307
 					  PRIMARY KEY  (DTK_ID)";
308
-        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
309
-        $table_name = "esp_ticket_template";
310
-        $sql        = "TTM_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
308
+		$this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
309
+		$table_name = "esp_ticket_template";
310
+		$sql        = "TTM_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
311 311
 					  TTM_name varchar(45) NOT NULL,
312 312
 					  TTM_description text,
313 313
 					  TTM_file varchar(45),
314 314
 					  PRIMARY KEY  (TTM_ID)";
315
-        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
316
-        $table_name = 'esp_question';
317
-        $sql        = 'QST_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
315
+		$this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
316
+		$table_name = 'esp_question';
317
+		$sql        = 'QST_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
318 318
 					QST_display_text text NOT NULL,
319 319
 					QST_admin_label varchar(255) NOT NULL,
320 320
 					QST_system varchar(25) DEFAULT NULL,
@@ -326,25 +326,25 @@  discard block
 block discarded – undo
326 326
 					QST_wp_user bigint(20) unsigned NULL,
327 327
 					QST_deleted tinyint(1) unsigned NOT NULL DEFAULT 0,
328 328
 					PRIMARY KEY  (QST_ID)';
329
-        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
330
-        $table_name = 'esp_question_group_question';
331
-        $sql        = "QGQ_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
329
+		$this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
330
+		$table_name = 'esp_question_group_question';
331
+		$sql        = "QGQ_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
332 332
 					QSG_ID int(10) unsigned NOT NULL,
333 333
 					QST_ID int(10) unsigned NOT NULL,
334 334
 					QGQ_order int(10) unsigned NOT NULL DEFAULT 0,
335 335
 					PRIMARY KEY  (QGQ_ID) ";
336
-        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
337
-        $table_name = 'esp_question_option';
338
-        $sql        = "QSO_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
336
+		$this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
337
+		$table_name = 'esp_question_option';
338
+		$sql        = "QSO_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
339 339
 					QSO_value varchar(255) NOT NULL,
340 340
 					QSO_desc text NOT NULL,
341 341
 					QST_ID int(10) unsigned NOT NULL,
342 342
 					QSO_order int(10) unsigned NOT NULL DEFAULT 0,
343 343
 					QSO_deleted tinyint(1) unsigned NOT NULL DEFAULT 0,
344 344
 					PRIMARY KEY  (QSO_ID)";
345
-        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
346
-        $table_name = 'esp_registration';
347
-        $sql        = "REG_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
345
+		$this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
346
+		$table_name = 'esp_registration';
347
+		$sql        = "REG_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
348 348
 					  EVT_ID bigint(20) unsigned NOT NULL,
349 349
 					  ATT_ID bigint(20) unsigned NOT NULL,
350 350
 					  TXN_ID int(10) unsigned NOT NULL,
@@ -367,25 +367,25 @@  discard block
 block discarded – undo
367 367
 					  KEY STS_ID (STS_ID),
368 368
 					  KEY REG_url_link (REG_url_link),
369 369
 					  KEY REG_code (REG_code)";
370
-        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB ');
371
-        $table_name = 'esp_checkin';
372
-        $sql        = "CHK_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
370
+		$this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB ');
371
+		$table_name = 'esp_checkin';
372
+		$sql        = "CHK_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
373 373
 					REG_ID int(10) unsigned NOT NULL,
374 374
 					DTT_ID int(10) unsigned NOT NULL,
375 375
 					CHK_in tinyint(1) unsigned NOT NULL DEFAULT 1,
376 376
 					CHK_timestamp datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
377 377
 					PRIMARY KEY  (CHK_ID)";
378
-        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
379
-        $table_name = 'esp_state';
380
-        $sql        = "STA_ID smallint(5) unsigned NOT NULL AUTO_INCREMENT,
378
+		$this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
379
+		$table_name = 'esp_state';
380
+		$sql        = "STA_ID smallint(5) unsigned NOT NULL AUTO_INCREMENT,
381 381
 					  CNT_ISO varchar(2) COLLATE utf8_bin NOT NULL,
382 382
 					  STA_abbrev varchar(24) COLLATE utf8_bin NOT NULL,
383 383
 					  STA_name varchar(100) COLLATE utf8_bin NOT NULL,
384 384
 					  STA_active tinyint(1) DEFAULT '1',
385 385
 					  PRIMARY KEY  (STA_ID)";
386
-        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
387
-        $table_name = 'esp_status';
388
-        $sql        = "STS_ID varchar(3) COLLATE utf8_bin NOT NULL,
386
+		$this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
387
+		$table_name = 'esp_status';
388
+		$sql        = "STS_ID varchar(3) COLLATE utf8_bin NOT NULL,
389 389
 					  STS_code varchar(45) COLLATE utf8_bin NOT NULL,
390 390
 					  STS_type set('event','registration','transaction','payment','email') COLLATE utf8_bin NOT NULL,
391 391
 					  STS_can_edit tinyint(1) NOT NULL DEFAULT 0,
@@ -393,9 +393,9 @@  discard block
 block discarded – undo
393 393
 					  STS_open tinyint(1) NOT NULL DEFAULT 1,
394 394
 					  UNIQUE KEY STS_ID_UNIQUE (STS_ID),
395 395
 					  KEY STS_type (STS_type)";
396
-        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
397
-        $table_name = 'esp_transaction';
398
-        $sql        = "TXN_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
396
+		$this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
397
+		$table_name = 'esp_transaction';
398
+		$sql        = "TXN_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
399 399
 					  TXN_timestamp datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
400 400
 					  TXN_total decimal(10,3) DEFAULT '0.00',
401 401
 					  TXN_paid decimal(10,3) NOT NULL DEFAULT '0.00',
@@ -407,9 +407,9 @@  discard block
 block discarded – undo
407 407
 					  PRIMARY KEY  (TXN_ID),
408 408
 					  KEY TXN_timestamp (TXN_timestamp),
409 409
 					  KEY STS_ID (STS_ID)";
410
-        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
411
-        $table_name = 'esp_venue_meta';
412
-        $sql        = "VNUM_ID int(11) NOT NULL AUTO_INCREMENT,
410
+		$this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
411
+		$table_name = 'esp_venue_meta';
412
+		$sql        = "VNUM_ID int(11) NOT NULL AUTO_INCREMENT,
413 413
 			VNU_ID bigint(20) unsigned NOT NULL DEFAULT 0,
414 414
 			VNU_address varchar(255) DEFAULT NULL,
415 415
 			VNU_address2 varchar(255) DEFAULT NULL,
@@ -427,10 +427,10 @@  discard block
 block discarded – undo
427 427
 			PRIMARY KEY  (VNUM_ID),
428 428
 			KEY STA_ID (STA_ID),
429 429
 			KEY CNT_ISO (CNT_ISO)";
430
-        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
431
-        // modified tables
432
-        $table_name = "esp_price";
433
-        $sql        = "PRC_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
430
+		$this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
431
+		// modified tables
432
+		$table_name = "esp_price";
433
+		$sql        = "PRC_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
434 434
 					  PRT_ID tinyint(3) unsigned NOT NULL,
435 435
 					  PRC_amount decimal(10,3) NOT NULL DEFAULT '0.00',
436 436
 					  PRC_name varchar(245) NOT NULL,
@@ -442,9 +442,9 @@  discard block
 block discarded – undo
442 442
 					  PRC_wp_user bigint(20) unsigned NULL,
443 443
 					  PRC_parent int(10) unsigned DEFAULT 0,
444 444
 					  PRIMARY KEY  (PRC_ID)";
445
-        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
446
-        $table_name = "esp_price_type";
447
-        $sql        = "PRT_ID tinyint(3) unsigned NOT NULL AUTO_INCREMENT,
445
+		$this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
446
+		$table_name = "esp_price_type";
447
+		$sql        = "PRT_ID tinyint(3) unsigned NOT NULL AUTO_INCREMENT,
448 448
 				  PRT_name varchar(45) NOT NULL,
449 449
 				  PBT_ID tinyint(3) unsigned NOT NULL DEFAULT '1',
450 450
 				  PRT_is_percent tinyint(1) NOT NULL DEFAULT '0',
@@ -453,9 +453,9 @@  discard block
 block discarded – undo
453 453
 				  PRT_deleted tinyint(1) NOT NULL DEFAULT '0',
454 454
 				  UNIQUE KEY PRT_name_UNIQUE (PRT_name),
455 455
 				  PRIMARY KEY  (PRT_ID)";
456
-        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB ');
457
-        $table_name = "esp_ticket";
458
-        $sql        = "TKT_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
456
+		$this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB ');
457
+		$table_name = "esp_ticket";
458
+		$sql        = "TKT_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
459 459
 					  TTM_ID int(10) unsigned NOT NULL,
460 460
 					  TKT_name varchar(245) NOT NULL DEFAULT '',
461 461
 					  TKT_description text NOT NULL,
@@ -476,10 +476,10 @@  discard block
 block discarded – undo
476 476
 					  TKT_parent int(10) unsigned DEFAULT '0',
477 477
 					  TKT_deleted tinyint(1) NOT NULL DEFAULT '0',
478 478
 					  PRIMARY KEY  (TKT_ID)";
479
-        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
480
-        $this->_get_table_manager()->dropIndex('esp_question_group', 'QSG_identifier_UNIQUE');
481
-        $table_name = 'esp_question_group';
482
-        $sql        = 'QSG_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
479
+		$this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
480
+		$this->_get_table_manager()->dropIndex('esp_question_group', 'QSG_identifier_UNIQUE');
481
+		$table_name = 'esp_question_group';
482
+		$sql        = 'QSG_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
483 483
 					QSG_name varchar(255) NOT NULL,
484 484
 					QSG_identifier varchar(100) NOT NULL,
485 485
 					QSG_desc text NULL,
@@ -491,141 +491,141 @@  discard block
 block discarded – undo
491 491
 					QSG_wp_user bigint(20) unsigned NULL,
492 492
 					PRIMARY KEY  (QSG_ID),
493 493
 					UNIQUE KEY QSG_identifier_UNIQUE (QSG_identifier ASC)';
494
-        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
495
-        /** @var EE_DMS_Core_4_1_0 $script_4_1_defaults */
496
-        $script_4_1_defaults = EE_Registry::instance()->load_dms('Core_4_1_0');
497
-        // (because many need to convert old string states to foreign keys into the states table)
498
-        $script_4_1_defaults->insert_default_states();
499
-        $script_4_1_defaults->insert_default_countries();
500
-        /** @var EE_DMS_Core_4_5_0 $script_4_5_defaults */
501
-        $script_4_5_defaults = EE_Registry::instance()->load_dms('Core_4_5_0');
502
-        $script_4_5_defaults->insert_default_price_types();
503
-        $script_4_5_defaults->insert_default_prices();
504
-        $script_4_5_defaults->insert_default_tickets();
505
-        // setting up the config wp option pretty well counts as a 'schema change', or at least should happen here
506
-        EE_Config::instance()->update_espresso_config(false, true);
507
-        $this->add_default_admin_only_payments();
508
-        $this->insert_default_currencies();
509
-        return true;
510
-    }
494
+		$this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
495
+		/** @var EE_DMS_Core_4_1_0 $script_4_1_defaults */
496
+		$script_4_1_defaults = EE_Registry::instance()->load_dms('Core_4_1_0');
497
+		// (because many need to convert old string states to foreign keys into the states table)
498
+		$script_4_1_defaults->insert_default_states();
499
+		$script_4_1_defaults->insert_default_countries();
500
+		/** @var EE_DMS_Core_4_5_0 $script_4_5_defaults */
501
+		$script_4_5_defaults = EE_Registry::instance()->load_dms('Core_4_5_0');
502
+		$script_4_5_defaults->insert_default_price_types();
503
+		$script_4_5_defaults->insert_default_prices();
504
+		$script_4_5_defaults->insert_default_tickets();
505
+		// setting up the config wp option pretty well counts as a 'schema change', or at least should happen here
506
+		EE_Config::instance()->update_espresso_config(false, true);
507
+		$this->add_default_admin_only_payments();
508
+		$this->insert_default_currencies();
509
+		return true;
510
+	}
511 511
 
512 512
 
513
-    /**
514
-     * @return boolean
515
-     */
516
-    public function schema_changes_after_migration()
517
-    {
518
-        return true;
519
-    }
513
+	/**
514
+	 * @return boolean
515
+	 */
516
+	public function schema_changes_after_migration()
517
+	{
518
+		return true;
519
+	}
520 520
 
521 521
 
522
-    public function migration_page_hooks()
523
-    {
524
-    }
522
+	public function migration_page_hooks()
523
+	{
524
+	}
525 525
 
526 526
 
527
-    public function add_default_admin_only_payments()
528
-    {
529
-        global $wpdb;
530
-        $table_name = $wpdb->prefix . "esp_payment_method";
531
-        $user_id    = EEH_Activation::get_default_creator_id();
532
-        $user_id    = $user_id ?: 0;
533
-        if ($this->_get_table_analysis()->tableExists($table_name)) {
534
-            $SQL                                = "SELECT COUNT( * ) FROM $table_name";
535
-            $existing_payment_methods           = $wpdb->get_var($SQL);
536
-            $default_admin_only_payment_methods = apply_filters(
537
-                'FHEE__EEH_Activation__add_default_admin_only_payments__default_admin_only_payment_methods',
538
-                [
539
-                    esc_html__("Bank", 'event_espresso')        => esc_html__("Bank Draft", 'event_espresso'),
540
-                    esc_html__("Cash", 'event_espresso')        => esc_html__(
541
-                        "Cash Delivered Physically",
542
-                        'event_espresso'
543
-                    ),
544
-                    esc_html__("Check", 'event_espresso')       => esc_html__("Paper Check", 'event_espresso'),
545
-                    esc_html__("Credit Card", 'event_espresso') => esc_html__(
546
-                        "Offline Credit Card Payment",
547
-                        'event_espresso'
548
-                    ),
549
-                    esc_html__("Debit Card", 'event_espresso')  => esc_html__(
550
-                        "Offline Debit Payment",
551
-                        'event_espresso'
552
-                    ),
553
-                    esc_html__("Invoice", 'event_espresso')     => esc_html__(
554
-                        "Invoice received with monies included",
555
-                        'event_espresso'
556
-                    ),
557
-                    esc_html__("Money Order", 'event_espresso') => '',
558
-                    esc_html__("Paypal", 'event_espresso')      => esc_html__(
559
-                        "Paypal eCheck, Invoice, etc",
560
-                        'event_espresso'
561
-                    ),
562
-                    esc_html__('Other', 'event_espresso')       => esc_html__(
563
-                        'Other method of payment',
564
-                        'event_espresso'
565
-                    ),
566
-                ]
567
-            );
568
-            // make sure we hae payment method records for the following
569
-            // so admins can record payments for them from the admin page
570
-            foreach ($default_admin_only_payment_methods as $nicename => $description) {
571
-                $slug = sanitize_key($nicename);
572
-                // check that such a payment method exists
573
-                $exists = $wpdb->get_var($wpdb->prepare("SELECT count(*) FROM $table_name WHERE PMD_slug = %s", $slug));
574
-                if (! $exists) {
575
-                    $values  = [
576
-                        'PMD_type'       => 'Admin_Only',
577
-                        'PMD_name'       => $nicename,
578
-                        'PMD_admin_name' => $nicename,
579
-                        'PMD_admin_desc' => $description,
580
-                        'PMD_slug'       => $slug,
581
-                        'PMD_wp_user'    => $user_id,
582
-                        'PMD_scope'      => serialize(['ADMIN']),
583
-                    ];
584
-                    $success = $wpdb->insert(
585
-                        $table_name,
586
-                        $values,
587
-                        [
588
-                            '%s',// PMD_type
589
-                            '%s',// PMD_name
590
-                            '%s',// PMD_admin_name
591
-                            '%s',// PMD_admin_desc
592
-                            '%s',// PMD_slug
593
-                            '%d',// PMD_wp_user
594
-                            '%s',// PMD_scope
595
-                        ]
596
-                    );
597
-                    if (! $success) {
598
-                        $this->add_error(
599
-                            sprintf(
600
-                                esc_html__(
601
-                                    "Could not insert new admin-only payment method with values %s during migration",
602
-                                    "event_espresso"
603
-                                ),
604
-                                $this->_json_encode($values)
605
-                            )
606
-                        );
607
-                    }
608
-                }
609
-            }
610
-        }
611
-    }
527
+	public function add_default_admin_only_payments()
528
+	{
529
+		global $wpdb;
530
+		$table_name = $wpdb->prefix . "esp_payment_method";
531
+		$user_id    = EEH_Activation::get_default_creator_id();
532
+		$user_id    = $user_id ?: 0;
533
+		if ($this->_get_table_analysis()->tableExists($table_name)) {
534
+			$SQL                                = "SELECT COUNT( * ) FROM $table_name";
535
+			$existing_payment_methods           = $wpdb->get_var($SQL);
536
+			$default_admin_only_payment_methods = apply_filters(
537
+				'FHEE__EEH_Activation__add_default_admin_only_payments__default_admin_only_payment_methods',
538
+				[
539
+					esc_html__("Bank", 'event_espresso')        => esc_html__("Bank Draft", 'event_espresso'),
540
+					esc_html__("Cash", 'event_espresso')        => esc_html__(
541
+						"Cash Delivered Physically",
542
+						'event_espresso'
543
+					),
544
+					esc_html__("Check", 'event_espresso')       => esc_html__("Paper Check", 'event_espresso'),
545
+					esc_html__("Credit Card", 'event_espresso') => esc_html__(
546
+						"Offline Credit Card Payment",
547
+						'event_espresso'
548
+					),
549
+					esc_html__("Debit Card", 'event_espresso')  => esc_html__(
550
+						"Offline Debit Payment",
551
+						'event_espresso'
552
+					),
553
+					esc_html__("Invoice", 'event_espresso')     => esc_html__(
554
+						"Invoice received with monies included",
555
+						'event_espresso'
556
+					),
557
+					esc_html__("Money Order", 'event_espresso') => '',
558
+					esc_html__("Paypal", 'event_espresso')      => esc_html__(
559
+						"Paypal eCheck, Invoice, etc",
560
+						'event_espresso'
561
+					),
562
+					esc_html__('Other', 'event_espresso')       => esc_html__(
563
+						'Other method of payment',
564
+						'event_espresso'
565
+					),
566
+				]
567
+			);
568
+			// make sure we hae payment method records for the following
569
+			// so admins can record payments for them from the admin page
570
+			foreach ($default_admin_only_payment_methods as $nicename => $description) {
571
+				$slug = sanitize_key($nicename);
572
+				// check that such a payment method exists
573
+				$exists = $wpdb->get_var($wpdb->prepare("SELECT count(*) FROM $table_name WHERE PMD_slug = %s", $slug));
574
+				if (! $exists) {
575
+					$values  = [
576
+						'PMD_type'       => 'Admin_Only',
577
+						'PMD_name'       => $nicename,
578
+						'PMD_admin_name' => $nicename,
579
+						'PMD_admin_desc' => $description,
580
+						'PMD_slug'       => $slug,
581
+						'PMD_wp_user'    => $user_id,
582
+						'PMD_scope'      => serialize(['ADMIN']),
583
+					];
584
+					$success = $wpdb->insert(
585
+						$table_name,
586
+						$values,
587
+						[
588
+							'%s',// PMD_type
589
+							'%s',// PMD_name
590
+							'%s',// PMD_admin_name
591
+							'%s',// PMD_admin_desc
592
+							'%s',// PMD_slug
593
+							'%d',// PMD_wp_user
594
+							'%s',// PMD_scope
595
+						]
596
+					);
597
+					if (! $success) {
598
+						$this->add_error(
599
+							sprintf(
600
+								esc_html__(
601
+									"Could not insert new admin-only payment method with values %s during migration",
602
+									"event_espresso"
603
+								),
604
+								$this->_json_encode($values)
605
+							)
606
+						);
607
+					}
608
+				}
609
+			}
610
+		}
611
+	}
612 612
 
613 613
 
614
-    /**
615
-     * insert_default_countries
616
-     *
617
-     * @static
618
-     * @return void
619
-     */
620
-    public function insert_default_currencies()
621
-    {
622
-        global $wpdb;
623
-        $currency_table = $wpdb->prefix . "esp_currency";
624
-        if ($this->_get_table_analysis()->tableExists($currency_table)) {
625
-            $SQL       = "SELECT COUNT('CUR_code') FROM $currency_table";
626
-            $countries = $wpdb->get_var($SQL);
627
-            if (! $countries) {
628
-                $SQL = "INSERT INTO $currency_table
614
+	/**
615
+	 * insert_default_countries
616
+	 *
617
+	 * @static
618
+	 * @return void
619
+	 */
620
+	public function insert_default_currencies()
621
+	{
622
+		global $wpdb;
623
+		$currency_table = $wpdb->prefix . "esp_currency";
624
+		if ($this->_get_table_analysis()->tableExists($currency_table)) {
625
+			$SQL       = "SELECT COUNT('CUR_code') FROM $currency_table";
626
+			$countries = $wpdb->get_var($SQL);
627
+			if (! $countries) {
628
+				$SQL = "INSERT INTO $currency_table
629 629
 				( CUR_code, CUR_single, CUR_plural, CUR_sign, CUR_dec_plc, CUR_active) VALUES
630 630
 				( 'EUR',  'Euro',  'Euros',  '€',  2,1),
631 631
 				( 'AED',  'Dirham',  'Dirhams', 'د.إ',2,1),
@@ -779,8 +779,8 @@  discard block
 block discarded – undo
779 779
 				( 'ZAR',  'Rand',  'Rands',  'R',  2,1),
780 780
 				( 'ZMK',  'Kwacha',  'Kwachas',  '',  2,1),
781 781
 				( 'ZWD', 'Dollar', 'Dollars', 'Z$', 2,1);";
782
-                $wpdb->query($SQL);
783
-            }
784
-        }
785
-    }
782
+				$wpdb->query($SQL);
783
+			}
784
+		}
785
+	}
786 786
 }
Please login to merge, or discard this patch.
Spacing   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -7,12 +7,12 @@  discard block
 block discarded – undo
7 7
 // unfortunately, this needs to be done upon INCLUSION of this file,
8 8
 // instead of construction, because it only gets constructed on first page load
9 9
 // (all other times it gets resurrected from a wordpress option)
10
-$stages            = glob(EE_CORE . 'data_migration_scripts/4_6_0_stages/*');
10
+$stages            = glob(EE_CORE.'data_migration_scripts/4_6_0_stages/*');
11 11
 $class_to_filepath = [];
12 12
 foreach ($stages as $filepath) {
13 13
     $matches = [];
14 14
     preg_match('~4_6_0_stages/(.*).dmsstage.php~', $filepath, $matches);
15
-    $class_to_filepath[ $matches[1] ] = $filepath;
15
+    $class_to_filepath[$matches[1]] = $filepath;
16 16
 }
17 17
 // give addons a chance to autoload their stages too
18 18
 $class_to_filepath = apply_filters('FHEE__EE_DMS_4_6_0__autoloaded_stages', $class_to_filepath);
@@ -72,10 +72,10 @@  discard block
 block discarded – undo
72 72
         ) {
73 73
 //          echo "$version_string can be migrated from";
74 74
             return true;
75
-        } elseif (! $version_string) {
75
+        } elseif ( ! $version_string) {
76 76
 //          echo "no version string provided: $version_string";
77 77
             // no version string provided... this must be pre 4.3
78
-            return false;// changed mind. dont want people thinking they should migrate yet because they cant
78
+            return false; // changed mind. dont want people thinking they should migrate yet because they cant
79 79
         } else {
80 80
 //          echo "$version_string doesnt apply";
81 81
             return false;
@@ -89,7 +89,7 @@  discard block
 block discarded – undo
89 89
     public function schema_changes_before_migration()
90 90
     {
91 91
         // relies on 4.1's EEH_Activation::create_table
92
-        require_once(EE_HELPERS . 'EEH_Activation.helper.php');
92
+        require_once(EE_HELPERS.'EEH_Activation.helper.php');
93 93
         $table_name = 'esp_answer';
94 94
         $sql        = "ANS_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
95 95
 					REG_ID int(10) unsigned NOT NULL,
@@ -527,7 +527,7 @@  discard block
 block discarded – undo
527 527
     public function add_default_admin_only_payments()
528 528
     {
529 529
         global $wpdb;
530
-        $table_name = $wpdb->prefix . "esp_payment_method";
530
+        $table_name = $wpdb->prefix."esp_payment_method";
531 531
         $user_id    = EEH_Activation::get_default_creator_id();
532 532
         $user_id    = $user_id ?: 0;
533 533
         if ($this->_get_table_analysis()->tableExists($table_name)) {
@@ -571,8 +571,8 @@  discard block
 block discarded – undo
571 571
                 $slug = sanitize_key($nicename);
572 572
                 // check that such a payment method exists
573 573
                 $exists = $wpdb->get_var($wpdb->prepare("SELECT count(*) FROM $table_name WHERE PMD_slug = %s", $slug));
574
-                if (! $exists) {
575
-                    $values  = [
574
+                if ( ! $exists) {
575
+                    $values = [
576 576
                         'PMD_type'       => 'Admin_Only',
577 577
                         'PMD_name'       => $nicename,
578 578
                         'PMD_admin_name' => $nicename,
@@ -585,16 +585,16 @@  discard block
 block discarded – undo
585 585
                         $table_name,
586 586
                         $values,
587 587
                         [
588
-                            '%s',// PMD_type
589
-                            '%s',// PMD_name
590
-                            '%s',// PMD_admin_name
591
-                            '%s',// PMD_admin_desc
592
-                            '%s',// PMD_slug
593
-                            '%d',// PMD_wp_user
594
-                            '%s',// PMD_scope
588
+                            '%s', // PMD_type
589
+                            '%s', // PMD_name
590
+                            '%s', // PMD_admin_name
591
+                            '%s', // PMD_admin_desc
592
+                            '%s', // PMD_slug
593
+                            '%d', // PMD_wp_user
594
+                            '%s', // PMD_scope
595 595
                         ]
596 596
                     );
597
-                    if (! $success) {
597
+                    if ( ! $success) {
598 598
                         $this->add_error(
599 599
                             sprintf(
600 600
                                 esc_html__(
@@ -620,11 +620,11 @@  discard block
 block discarded – undo
620 620
     public function insert_default_currencies()
621 621
     {
622 622
         global $wpdb;
623
-        $currency_table = $wpdb->prefix . "esp_currency";
623
+        $currency_table = $wpdb->prefix."esp_currency";
624 624
         if ($this->_get_table_analysis()->tableExists($currency_table)) {
625 625
             $SQL       = "SELECT COUNT('CUR_code') FROM $currency_table";
626 626
             $countries = $wpdb->get_var($SQL);
627
-            if (! $countries) {
627
+            if ( ! $countries) {
628 628
                 $SQL = "INSERT INTO $currency_table
629 629
 				( CUR_code, CUR_single, CUR_plural, CUR_sign, CUR_dec_plc, CUR_active) VALUES
630 630
 				( 'EUR',  'Euro',  'Euros',  '€',  2,1),
Please login to merge, or discard this patch.
4_5_0_stages/EE_DMS_4_5_0_update_wp_user_for_prices.dmsstage.php 2 patches
Indentation   +38 added lines, -38 removed lines patch added patch discarded remove patch
@@ -10,44 +10,44 @@
 block discarded – undo
10 10
  */
11 11
 class EE_DMS_4_5_0_update_wp_user_for_prices extends EE_Data_Migration_Script_Stage_Table
12 12
 {
13
-    public function __construct()
14
-    {
15
-        global $wpdb;
16
-        $this->_pretty_name = esc_html__("Prices", "event_espresso");
17
-        $this->_old_table   = $wpdb->prefix . "esp_price";
18
-        parent::__construct();
19
-    }
13
+	public function __construct()
14
+	{
15
+		global $wpdb;
16
+		$this->_pretty_name = esc_html__("Prices", "event_espresso");
17
+		$this->_old_table   = $wpdb->prefix . "esp_price";
18
+		parent::__construct();
19
+	}
20 20
 
21 21
 
22
-    protected function _migrate_old_row($old_row)
23
-    {
24
-        // foreach ticket row we add the id for the current logged in user.
25
-        global $wpdb;
26
-        $user_id = EEH_Activation::get_default_creator_id();
27
-        $user_id = $user_id ?: 0;
28
-        $updated = $wpdb->update(
29
-            $this->_old_table,
30
-            ['PRC_wp_user' => $user_id],
31
-            ['PRC_ID' => $old_row['PRC_ID']],
32
-            [
33
-                '%d',// PRC_wp_user
34
-            ],
35
-            [
36
-                '%d',// PRC_ID
37
-            ]
38
-        );
39
-        if (false === $updated) {
40
-            $this->add_error(
41
-                sprintf(
42
-                    esc_html__(
43
-                        "Error in updating table %s setting PRC_wp_user = %d where PRC_ID = %d",
44
-                        'event_espresso'
45
-                    ),
46
-                    $this->_old_table,
47
-                    $user_id,
48
-                    $old_row['PRC_ID']
49
-                )
50
-            );
51
-        }
52
-    }
22
+	protected function _migrate_old_row($old_row)
23
+	{
24
+		// foreach ticket row we add the id for the current logged in user.
25
+		global $wpdb;
26
+		$user_id = EEH_Activation::get_default_creator_id();
27
+		$user_id = $user_id ?: 0;
28
+		$updated = $wpdb->update(
29
+			$this->_old_table,
30
+			['PRC_wp_user' => $user_id],
31
+			['PRC_ID' => $old_row['PRC_ID']],
32
+			[
33
+				'%d',// PRC_wp_user
34
+			],
35
+			[
36
+				'%d',// PRC_ID
37
+			]
38
+		);
39
+		if (false === $updated) {
40
+			$this->add_error(
41
+				sprintf(
42
+					esc_html__(
43
+						"Error in updating table %s setting PRC_wp_user = %d where PRC_ID = %d",
44
+						'event_espresso'
45
+					),
46
+					$this->_old_table,
47
+					$user_id,
48
+					$old_row['PRC_ID']
49
+				)
50
+			);
51
+		}
52
+	}
53 53
 }
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -14,7 +14,7 @@  discard block
 block discarded – undo
14 14
     {
15 15
         global $wpdb;
16 16
         $this->_pretty_name = esc_html__("Prices", "event_espresso");
17
-        $this->_old_table   = $wpdb->prefix . "esp_price";
17
+        $this->_old_table   = $wpdb->prefix."esp_price";
18 18
         parent::__construct();
19 19
     }
20 20
 
@@ -30,10 +30,10 @@  discard block
 block discarded – undo
30 30
             ['PRC_wp_user' => $user_id],
31 31
             ['PRC_ID' => $old_row['PRC_ID']],
32 32
             [
33
-                '%d',// PRC_wp_user
33
+                '%d', // PRC_wp_user
34 34
             ],
35 35
             [
36
-                '%d',// PRC_ID
36
+                '%d', // PRC_ID
37 37
             ]
38 38
         );
39 39
         if (false === $updated) {
Please login to merge, or discard this patch.