Completed
Branch models-cleanup/model-objects-a... (bcae63)
by
unknown
64:36 queued 54:24
created
core/db_classes/EE_Answer.class.php 2 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -64,7 +64,7 @@
 block discarded – undo
64 64
     /**
65 65
      * Set Answer value
66 66
      *
67
-     * @param mixed $ANS_value
67
+     * @param string $ANS_value
68 68
      * @throws EE_Error
69 69
      * @throws ReflectionException
70 70
      */
Please login to merge, or discard this patch.
Indentation   +149 added lines, -149 removed lines patch added patch discarded remove patch
@@ -10,153 +10,153 @@
 block discarded – undo
10 10
 class EE_Answer extends EE_Base_Class
11 11
 {
12 12
 
13
-    /**
14
-     * @param array $props_n_values
15
-     * @return EE_Answer
16
-     * @throws EE_Error
17
-     * @throws ReflectionException
18
-     */
19
-    public static function new_instance($props_n_values = [])
20
-    {
21
-        $has_object = parent::_check_for_object($props_n_values, __CLASS__);
22
-        return $has_object ? $has_object : new self($props_n_values);
23
-    }
24
-
25
-
26
-    /**
27
-     * @param array $props_n_values
28
-     * @return EE_Answer
29
-     * @throws EE_Error
30
-     * @throws ReflectionException
31
-     */
32
-    public static function new_instance_from_db($props_n_values = [])
33
-    {
34
-        return new self($props_n_values, true);
35
-    }
36
-
37
-
38
-    /**
39
-     * Set Question ID
40
-     *
41
-     * @param int $QST_ID
42
-     * @throws EE_Error
43
-     * @throws ReflectionException
44
-     */
45
-    public function set_question($QST_ID = 0)
46
-    {
47
-        $this->set('QST_ID', $QST_ID);
48
-    }
49
-
50
-
51
-    /**
52
-     * Set Registration ID
53
-     *
54
-     * @param int $REG_ID
55
-     * @throws EE_Error
56
-     * @throws ReflectionException
57
-     */
58
-    public function set_registration($REG_ID = 0)
59
-    {
60
-        $this->set('REG_ID', $REG_ID);
61
-    }
62
-
63
-
64
-    /**
65
-     * Set Answer value
66
-     *
67
-     * @param mixed $ANS_value
68
-     * @throws EE_Error
69
-     * @throws ReflectionException
70
-     */
71
-    public function set_value($ANS_value = '')
72
-    {
73
-        $this->set('ANS_value', $ANS_value);
74
-    }
75
-
76
-
77
-    /**
78
-     * get Attendee First Name
79
-     *
80
-     * @return        int
81
-     * @throws EE_Error
82
-     */
83
-    public function registration_ID()
84
-    {
85
-        return $this->get('REG_ID');
86
-    }
87
-
88
-
89
-    /**
90
-     * get Attendee Last Name
91
-     *
92
-     * @return        int
93
-     * @throws EE_Error
94
-     */
95
-    public function question_ID()
96
-    {
97
-        return $this->get('QST_ID');
98
-    }
99
-
100
-
101
-    /**
102
-     * get Attendee Address
103
-     *
104
-     * @return        string
105
-     * @throws EE_Error
106
-     */
107
-    public function value()
108
-    {
109
-        return $this->get('ANS_value');
110
-    }
111
-
112
-
113
-    /**
114
-     * Gets a pretty form of the value (mostly applies to answers that have multiple answers)
115
-     *
116
-     * @param null $schema
117
-     * @return string
118
-     * @throws EE_Error
119
-     */
120
-    public function pretty_value($schema = null)
121
-    {
122
-        return $this->get_pretty('ANS_value', $schema);
123
-    }
124
-
125
-
126
-    /**
127
-     * Echoes out a pretty value (even for multi-choice options)
128
-     *
129
-     * @param string $schema
130
-     * @throws EE_Error
131
-     */
132
-    public function e_value($schema = null)
133
-    {
134
-        $this->e('ANS_value', $schema);
135
-    }
136
-
137
-
138
-    /**
139
-     * Gets the related EE_Question to this EE_Answer
140
-     *
141
-     * @return EE_Base_Class|EE_Question
142
-     * @throws EE_Error
143
-     * @throws ReflectionException
144
-     */
145
-    public function question()
146
-    {
147
-        return $this->get_first_related('Question');
148
-    }
149
-
150
-
151
-    /**
152
-     * Gets the related EE_Registration to this EE_Answer
153
-     *
154
-     * @return EE_Base_Class|EE_Registration
155
-     * @throws EE_Error
156
-     * @throws ReflectionException
157
-     */
158
-    public function registration()
159
-    {
160
-        return $this->get_first_related('Registration');
161
-    }
13
+	/**
14
+	 * @param array $props_n_values
15
+	 * @return EE_Answer
16
+	 * @throws EE_Error
17
+	 * @throws ReflectionException
18
+	 */
19
+	public static function new_instance($props_n_values = [])
20
+	{
21
+		$has_object = parent::_check_for_object($props_n_values, __CLASS__);
22
+		return $has_object ? $has_object : new self($props_n_values);
23
+	}
24
+
25
+
26
+	/**
27
+	 * @param array $props_n_values
28
+	 * @return EE_Answer
29
+	 * @throws EE_Error
30
+	 * @throws ReflectionException
31
+	 */
32
+	public static function new_instance_from_db($props_n_values = [])
33
+	{
34
+		return new self($props_n_values, true);
35
+	}
36
+
37
+
38
+	/**
39
+	 * Set Question ID
40
+	 *
41
+	 * @param int $QST_ID
42
+	 * @throws EE_Error
43
+	 * @throws ReflectionException
44
+	 */
45
+	public function set_question($QST_ID = 0)
46
+	{
47
+		$this->set('QST_ID', $QST_ID);
48
+	}
49
+
50
+
51
+	/**
52
+	 * Set Registration ID
53
+	 *
54
+	 * @param int $REG_ID
55
+	 * @throws EE_Error
56
+	 * @throws ReflectionException
57
+	 */
58
+	public function set_registration($REG_ID = 0)
59
+	{
60
+		$this->set('REG_ID', $REG_ID);
61
+	}
62
+
63
+
64
+	/**
65
+	 * Set Answer value
66
+	 *
67
+	 * @param mixed $ANS_value
68
+	 * @throws EE_Error
69
+	 * @throws ReflectionException
70
+	 */
71
+	public function set_value($ANS_value = '')
72
+	{
73
+		$this->set('ANS_value', $ANS_value);
74
+	}
75
+
76
+
77
+	/**
78
+	 * get Attendee First Name
79
+	 *
80
+	 * @return        int
81
+	 * @throws EE_Error
82
+	 */
83
+	public function registration_ID()
84
+	{
85
+		return $this->get('REG_ID');
86
+	}
87
+
88
+
89
+	/**
90
+	 * get Attendee Last Name
91
+	 *
92
+	 * @return        int
93
+	 * @throws EE_Error
94
+	 */
95
+	public function question_ID()
96
+	{
97
+		return $this->get('QST_ID');
98
+	}
99
+
100
+
101
+	/**
102
+	 * get Attendee Address
103
+	 *
104
+	 * @return        string
105
+	 * @throws EE_Error
106
+	 */
107
+	public function value()
108
+	{
109
+		return $this->get('ANS_value');
110
+	}
111
+
112
+
113
+	/**
114
+	 * Gets a pretty form of the value (mostly applies to answers that have multiple answers)
115
+	 *
116
+	 * @param null $schema
117
+	 * @return string
118
+	 * @throws EE_Error
119
+	 */
120
+	public function pretty_value($schema = null)
121
+	{
122
+		return $this->get_pretty('ANS_value', $schema);
123
+	}
124
+
125
+
126
+	/**
127
+	 * Echoes out a pretty value (even for multi-choice options)
128
+	 *
129
+	 * @param string $schema
130
+	 * @throws EE_Error
131
+	 */
132
+	public function e_value($schema = null)
133
+	{
134
+		$this->e('ANS_value', $schema);
135
+	}
136
+
137
+
138
+	/**
139
+	 * Gets the related EE_Question to this EE_Answer
140
+	 *
141
+	 * @return EE_Base_Class|EE_Question
142
+	 * @throws EE_Error
143
+	 * @throws ReflectionException
144
+	 */
145
+	public function question()
146
+	{
147
+		return $this->get_first_related('Question');
148
+	}
149
+
150
+
151
+	/**
152
+	 * Gets the related EE_Registration to this EE_Answer
153
+	 *
154
+	 * @return EE_Base_Class|EE_Registration
155
+	 * @throws EE_Error
156
+	 * @throws ReflectionException
157
+	 */
158
+	public function registration()
159
+	{
160
+		return $this->get_first_related('Registration');
161
+	}
162 162
 }
Please login to merge, or discard this patch.
core/db_classes/EE_Attendee.class.php 3 patches
Doc Comments   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -451,7 +451,7 @@  discard block
 block discarded – undo
451 451
      * Gets registrations of this attendee
452 452
      *
453 453
      * @param array $query_params
454
-     * @return array[]|EE_Base_Class[]|EE_Registration[]
454
+     * @return EE_Base_Class[]
455 455
      * @throws EE_Error
456 456
      * @throws ReflectionException
457 457
      */
@@ -497,7 +497,7 @@  discard block
 block discarded – undo
497 497
     /**
498 498
      * returns any events attached to this attendee ($_Event property);
499 499
      *
500
-     * @return array
500
+     * @return EE_Base_Class[]
501 501
      * @throws EE_Error
502 502
      * @throws ReflectionException
503 503
      */
@@ -523,7 +523,7 @@  discard block
 block discarded – undo
523 523
      * and keys are their cleaned values.
524 524
      *
525 525
      * @param EE_Payment_Method $payment_method the _gateway_name property on the gateway class
526
-     * @return EE_Form_Section_Proper|null
526
+     * @return null|EE_Billing_Info_Form
527 527
      * @throws EE_Error
528 528
      * @see EE_Attendee::save_and_clean_billing_info_for_payment_method() which was
529 529
      *                                          used to save the billing info
Please login to merge, or discard this patch.
Indentation   +803 added lines, -803 removed lines patch added patch discarded remove patch
@@ -13,807 +13,807 @@
 block discarded – undo
13 13
 class EE_Attendee extends EE_CPT_Base implements EEI_Contact, EEI_Address, EEI_Admin_Links, EEI_Attendee
14 14
 {
15 15
 
16
-    /**
17
-     * Sets some dynamic defaults
18
-     *
19
-     * @param array  $fieldValues
20
-     * @param bool   $bydb
21
-     * @param string $timezone
22
-     * @param array  $date_formats
23
-     * @throws EE_Error
24
-     * @throws ReflectionException
25
-     */
26
-    protected function __construct($fieldValues = null, $bydb = false, $timezone = null, $date_formats = [])
27
-    {
28
-        if (! isset($fieldValues['ATT_full_name'])) {
29
-            $fname                        = isset($fieldValues['ATT_fname']) ? $fieldValues['ATT_fname'] . ' ' : '';
30
-            $lname                        = isset($fieldValues['ATT_lname']) ? $fieldValues['ATT_lname'] : '';
31
-            $fieldValues['ATT_full_name'] = $fname . $lname;
32
-        }
33
-        if (! isset($fieldValues['ATT_slug'])) {
34
-            // $fieldValues['ATT_slug'] = sanitize_key(wp_generate_password(20));
35
-            $fieldValues['ATT_slug'] = sanitize_title($fieldValues['ATT_full_name']);
36
-        }
37
-        if (! isset($fieldValues['ATT_short_bio']) && isset($fieldValues['ATT_bio'])) {
38
-            $fieldValues['ATT_short_bio'] = substr($fieldValues['ATT_bio'], 0, 50);
39
-        }
40
-        parent::__construct($fieldValues, $bydb, $timezone, $date_formats);
41
-    }
42
-
43
-
44
-    /**
45
-     * @param array  $props_n_values    incoming values
46
-     * @param string $timezone          incoming timezone
47
-     *                                  (if not set the timezone set for the website will be used.)
48
-     * @param array  $date_formats      incoming date_formats in an array where the first value is the
49
-     *                                  date_format and the second value is the time format
50
-     * @return EE_Attendee
51
-     * @throws EE_Error
52
-     * @throws ReflectionException
53
-     */
54
-    public static function new_instance($props_n_values = [], $timezone = null, $date_formats = [])
55
-    {
56
-        $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats);
57
-        return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats);
58
-    }
59
-
60
-
61
-    /**
62
-     * @param array  $props_n_values  incoming values from the database
63
-     * @param string $timezone        incoming timezone as set by the model.
64
-     *                                If not set the timezone for the website will be used.
65
-     * @return EE_Attendee
66
-     * @throws EE_Error
67
-     * @throws EE_Error
68
-     * @throws ReflectionException
69
-     */
70
-    public static function new_instance_from_db($props_n_values = [], $timezone = null)
71
-    {
72
-        return new self($props_n_values, true, $timezone);
73
-    }
74
-
75
-
76
-    /**
77
-     * Set Attendee First Name
78
-     *
79
-     * @param string $fname
80
-     * @throws EE_Error
81
-     * @throws ReflectionException
82
-     */
83
-    public function set_fname($fname = '')
84
-    {
85
-        $this->set('ATT_fname', $fname);
86
-    }
87
-
88
-
89
-    /**
90
-     * Set Attendee Last Name
91
-     *
92
-     * @param string $lname
93
-     * @throws EE_Error
94
-     * @throws ReflectionException
95
-     */
96
-    public function set_lname($lname = '')
97
-    {
98
-        $this->set('ATT_lname', $lname);
99
-    }
100
-
101
-
102
-    /**
103
-     * Set Attendee Address
104
-     *
105
-     * @param string $address
106
-     * @throws EE_Error
107
-     * @throws ReflectionException
108
-     */
109
-    public function set_address($address = '')
110
-    {
111
-        $this->set('ATT_address', $address);
112
-    }
113
-
114
-
115
-    /**
116
-     * Set Attendee Address2
117
-     *
118
-     * @param string $address2
119
-     * @throws EE_Error
120
-     * @throws ReflectionException
121
-     */
122
-    public function set_address2($address2 = '')
123
-    {
124
-        $this->set('ATT_address2', $address2);
125
-    }
126
-
127
-
128
-    /**
129
-     * Set Attendee City
130
-     *
131
-     * @param string $city
132
-     * @throws EE_Error
133
-     * @throws ReflectionException
134
-     */
135
-    public function set_city($city = '')
136
-    {
137
-        $this->set('ATT_city', $city);
138
-    }
139
-
140
-
141
-    /**
142
-     * Set Attendee State ID
143
-     *
144
-     * @param int $STA_ID
145
-     * @throws EE_Error
146
-     * @throws ReflectionException
147
-     */
148
-    public function set_state($STA_ID = 0)
149
-    {
150
-        $this->set('STA_ID', $STA_ID);
151
-    }
152
-
153
-
154
-    /**
155
-     * Set Attendee Country ISO Code
156
-     *
157
-     * @param string $CNT_ISO
158
-     * @throws EE_Error
159
-     * @throws ReflectionException
160
-     */
161
-    public function set_country($CNT_ISO = '')
162
-    {
163
-        $this->set('CNT_ISO', $CNT_ISO);
164
-    }
165
-
166
-
167
-    /**
168
-     * Set Attendee Zip/Postal Code
169
-     *
170
-     * @param string $zip
171
-     * @throws EE_Error
172
-     * @throws ReflectionException
173
-     */
174
-    public function set_zip($zip = '')
175
-    {
176
-        $this->set('ATT_zip', $zip);
177
-    }
178
-
179
-
180
-    /**
181
-     * Set Attendee Email Address
182
-     *
183
-     * @param string $email
184
-     * @throws EE_Error
185
-     * @throws ReflectionException
186
-     */
187
-    public function set_email($email = '')
188
-    {
189
-        $this->set('ATT_email', $email);
190
-    }
191
-
192
-
193
-    /**
194
-     * Set Attendee Phone
195
-     *
196
-     * @param string $phone
197
-     * @throws EE_Error
198
-     * @throws ReflectionException
199
-     */
200
-    public function set_phone($phone = '')
201
-    {
202
-        $this->set('ATT_phone', $phone);
203
-    }
204
-
205
-
206
-    /**
207
-     * set deleted
208
-     *
209
-     * @param bool $ATT_deleted
210
-     * @throws EE_Error
211
-     * @throws ReflectionException
212
-     */
213
-    public function set_deleted($ATT_deleted = false)
214
-    {
215
-        $this->set('ATT_deleted', $ATT_deleted);
216
-    }
217
-
218
-
219
-    /**
220
-     * Returns the value for the post_author id saved with the cpt
221
-     *
222
-     * @return int
223
-     * @throws EE_Error
224
-     * @since 4.5.0
225
-     */
226
-    public function wp_user()
227
-    {
228
-        return $this->get('ATT_author');
229
-    }
230
-
231
-
232
-    /**
233
-     * echoes out the attendee's first name
234
-     *
235
-     * @return void
236
-     * @throws EE_Error
237
-     */
238
-    public function e_full_name()
239
-    {
240
-        echo $this->full_name();
241
-    }
242
-
243
-
244
-    /**
245
-     * Returns the first and last name concatenated together with a space.
246
-     *
247
-     * @param bool $apply_html_entities
248
-     * @return string
249
-     * @throws EE_Error
250
-     */
251
-    public function full_name($apply_html_entities = false)
252
-    {
253
-        $full_name = [
254
-            $this->fname(),
255
-            $this->lname(),
256
-        ];
257
-        $full_name = array_filter($full_name);
258
-        $full_name = implode(' ', $full_name);
259
-        return $apply_html_entities
260
-            ? htmlentities($full_name, ENT_QUOTES, 'UTF-8')
261
-            : $full_name;
262
-    }
263
-
264
-
265
-    /**
266
-     * get Attendee First Name
267
-     *
268
-     * @return string
269
-     * @throws EE_Error
270
-     */
271
-    public function fname()
272
-    {
273
-        return $this->get('ATT_fname');
274
-    }
275
-
276
-
277
-    /**
278
-     * get Attendee Last Name
279
-     *
280
-     * @return string
281
-     * @throws EE_Error
282
-     */
283
-    public function lname()
284
-    {
285
-        return $this->get('ATT_lname');
286
-    }
287
-
288
-
289
-    /**
290
-     * get Attendee Email Address
291
-     *
292
-     * @return string
293
-     * @throws EE_Error
294
-     */
295
-    public function email()
296
-    {
297
-        return $this->get('ATT_email');
298
-    }
299
-
300
-
301
-    /**
302
-     * get Attendee Phone #
303
-     *
304
-     * @return string
305
-     * @throws EE_Error
306
-     */
307
-    public function phone()
308
-    {
309
-        return $this->get('ATT_phone');
310
-    }
311
-
312
-
313
-    /**
314
-     * This returns the value of the `ATT_full_name` field
315
-     * which is usually equivalent to calling `full_name()`
316
-     * unless the post_title field has been directly modified
317
-     * in the db for the post (espresso_attendees post type)
318
-     * for this attendee.
319
-     *
320
-     * @param bool $apply_html_entities
321
-     * @return string
322
-     * @throws EE_Error
323
-     */
324
-    public function ATT_full_name($apply_html_entities = false)
325
-    {
326
-        return $apply_html_entities
327
-            ? htmlentities(
328
-                $this->get('ATT_full_name'),
329
-                ENT_QUOTES,
330
-                'UTF-8'
331
-            )
332
-            : $this->get('ATT_full_name');
333
-    }
334
-
335
-
336
-    /**
337
-     * get Attendee bio
338
-     *
339
-     * @return string
340
-     * @throws EE_Error
341
-     */
342
-    public function bio()
343
-    {
344
-        return $this->get('ATT_bio');
345
-    }
346
-
347
-
348
-    /**
349
-     * get Attendee short bio
350
-     *
351
-     * @return string
352
-     * @throws EE_Error
353
-     */
354
-    public function short_bio()
355
-    {
356
-        return $this->get('ATT_short_bio');
357
-    }
358
-
359
-
360
-    /**
361
-     * Gets the attendee's full address as an array
362
-     * so client code can decide hwo to display it
363
-     *
364
-     * @return array numerically indexed,
365
-     *               with each part of the address that is known.
366
-     *               Eg, if the user only responded to state and country,
367
-     *               it would be array(0=>'Alabama',1=>'USA')
368
-     * @return array
369
-     * @throws EE_Error
370
-     * @throws ReflectionException
371
-     */
372
-    public function full_address_as_array()
373
-    {
374
-        $full_address_array     = [];
375
-        $initial_address_fields = ['ATT_address', 'ATT_address2', 'ATT_city',];
376
-        foreach ($initial_address_fields as $address_field_name) {
377
-            $address_fields_value = $this->get($address_field_name);
378
-            if (! empty($address_fields_value)) {
379
-                $full_address_array[] = $address_fields_value;
380
-            }
381
-        }
382
-        // now handle state and country
383
-        $state_obj = $this->state_obj();
384
-        if ($state_obj instanceof EE_State) {
385
-            $full_address_array[] = $state_obj->name();
386
-        }
387
-        $country_obj = $this->country_obj();
388
-        if ($country_obj instanceof EE_Country) {
389
-            $full_address_array[] = $country_obj->name();
390
-        }
391
-        // lastly get the xip
392
-        $zip_value = $this->zip();
393
-        if (! empty($zip_value)) {
394
-            $full_address_array[] = $zip_value;
395
-        }
396
-        return $full_address_array;
397
-    }
398
-
399
-
400
-    /**
401
-     * Gets the state set to this attendee
402
-     *
403
-     * @return EE_Base_Class|EE_State
404
-     * @throws EE_Error
405
-     * @throws ReflectionException
406
-     */
407
-    public function state_obj()
408
-    {
409
-        return $this->get_first_related('State');
410
-    }
411
-
412
-
413
-    /**
414
-     * Gets country set for this attendee
415
-     *
416
-     * @return EE_Base_Class|EE_Country
417
-     * @throws EE_Error
418
-     * @throws ReflectionException
419
-     */
420
-    public function country_obj()
421
-    {
422
-        return $this->get_first_related('Country');
423
-    }
424
-
425
-
426
-    /**
427
-     * get Attendee Zip/Postal Code
428
-     *
429
-     * @return string
430
-     * @throws EE_Error
431
-     */
432
-    public function zip()
433
-    {
434
-        return $this->get('ATT_zip');
435
-    }
436
-
437
-
438
-    /**
439
-     * get deleted
440
-     *
441
-     * @return        bool
442
-     * @throws EE_Error
443
-     */
444
-    public function deleted()
445
-    {
446
-        return $this->get('ATT_deleted');
447
-    }
448
-
449
-
450
-    /**
451
-     * Gets registrations of this attendee
452
-     *
453
-     * @param array $query_params
454
-     * @return array[]|EE_Base_Class[]|EE_Registration[]
455
-     * @throws EE_Error
456
-     * @throws ReflectionException
457
-     */
458
-    public function get_registrations($query_params = [])
459
-    {
460
-        return $this->get_many_related('Registration', $query_params);
461
-    }
462
-
463
-
464
-    /**
465
-     * Gets the most recent registration of this attendee
466
-     *
467
-     * @return EE_Base_Class|EE_Registration
468
-     * @throws EE_Error
469
-     * @throws ReflectionException
470
-     */
471
-    public function get_most_recent_registration()
472
-    {
473
-        return $this->get_first_related(
474
-            'Registration',
475
-            ['order_by' => ['REG_date' => 'DESC']]
476
-        ); // null, 'REG_date', 'DESC', '=', 'OBJECT_K');
477
-    }
478
-
479
-
480
-    /**
481
-     * Gets the most recent registration for this attend at this event
482
-     *
483
-     * @param int $event_id
484
-     * @return EE_Base_Class|EE_Registration
485
-     * @throws EE_Error
486
-     * @throws ReflectionException
487
-     */
488
-    public function get_most_recent_registration_for_event($event_id)
489
-    {
490
-        return $this->get_first_related(
491
-            'Registration',
492
-            [['EVT_ID' => $event_id], 'order_by' => ['REG_date' => 'DESC']]
493
-        );
494
-    }
495
-
496
-
497
-    /**
498
-     * returns any events attached to this attendee ($_Event property);
499
-     *
500
-     * @return array
501
-     * @throws EE_Error
502
-     * @throws ReflectionException
503
-     */
504
-    public function events()
505
-    {
506
-        return $this->get_many_related('Event');
507
-    }
508
-
509
-
510
-    /**
511
-     * @return string
512
-     * @throws EE_Error
513
-     * @throws ReflectionException
514
-     */
515
-    public function state_abbrev()
516
-    {
517
-        return $this->state_obj() instanceof EE_State ? $this->state_obj()->abbrev() : '';
518
-    }
519
-
520
-
521
-    /**
522
-     * Gets the billing info array where keys match espresso_reg_page_billing_inputs(),
523
-     * and keys are their cleaned values.
524
-     *
525
-     * @param EE_Payment_Method $payment_method the _gateway_name property on the gateway class
526
-     * @return EE_Form_Section_Proper|null
527
-     * @throws EE_Error
528
-     * @see EE_Attendee::save_and_clean_billing_info_for_payment_method() which was
529
-     *                                          used to save the billing info
530
-     */
531
-    public function billing_info_for_payment_method($payment_method)
532
-    {
533
-        $pm_type = $payment_method->type_obj();
534
-        if (! $pm_type instanceof EE_PMT_Base) {
535
-            return null;
536
-        }
537
-        $billing_info = $this->get_post_meta($this->get_billing_info_postmeta_name($payment_method), true);
538
-        if (! $billing_info) {
539
-            return null;
540
-        }
541
-        $billing_form = $pm_type->billing_form();
542
-        // double-check the form isn't totally hidden, in which case pretend there is no form
543
-        $form_totally_hidden = true;
544
-        foreach ($billing_form->inputs_in_subsections() as $input) {
545
-            if (! $input->get_display_strategy() instanceof EE_Hidden_Display_Strategy) {
546
-                $form_totally_hidden = false;
547
-                break;
548
-            }
549
-        }
550
-        if ($form_totally_hidden) {
551
-            return null;
552
-        }
553
-        if ($billing_form instanceof EE_Form_Section_Proper) {
554
-            $billing_form->receive_form_submission([$billing_form->name() => $billing_info], false);
555
-        }
556
-
557
-        return $billing_form;
558
-    }
559
-
560
-
561
-    /**
562
-     * Gets the postmeta key that holds this attendee's billing info for the
563
-     * specified payment method
564
-     *
565
-     * @param EE_Payment_Method $payment_method
566
-     * @return string
567
-     * @throws EE_Error
568
-     */
569
-    public function get_billing_info_postmeta_name($payment_method)
570
-    {
571
-        if ($payment_method->type_obj() instanceof EE_PMT_Base) {
572
-            return 'billing_info_' . $payment_method->type_obj()->system_name();
573
-        }
574
-        return null;
575
-    }
576
-
577
-
578
-    /**
579
-     * Saves the billing info to the attendee. @param EE_Billing_Attendee_Info_Form $billing_form
580
-     *
581
-     * @param EE_Payment_Method $payment_method
582
-     * @return boolean
583
-     * @throws EE_Error
584
-     * @see EE_Attendee::billing_info_for_payment_method() which is used to
585
-     *      retrieve it
586
-     */
587
-    public function save_and_clean_billing_info_for_payment_method($billing_form, $payment_method)
588
-    {
589
-        if (! $billing_form instanceof EE_Billing_Attendee_Info_Form) {
590
-            EE_Error::add_error(
591
-                __('Cannot save billing info because there is none.', 'event_espresso'),
592
-                __FILE__,
593
-                __FUNCTION__,
594
-                __LINE__
595
-            );
596
-            return false;
597
-        }
598
-        $billing_form->clean_sensitive_data();
599
-        return update_post_meta(
600
-            $this->ID(),
601
-            $this->get_billing_info_postmeta_name($payment_method),
602
-            $billing_form->input_values(true)
603
-        );
604
-    }
605
-
606
-
607
-    /**
608
-     * Return the link to the admin details for the object.
609
-     *
610
-     * @return string
611
-     * @throws EE_Error
612
-     * @throws InvalidArgumentException
613
-     * @throws InvalidDataTypeException
614
-     * @throws InvalidInterfaceException
615
-     * @throws ReflectionException
616
-     */
617
-    public function get_admin_details_link()
618
-    {
619
-        return $this->get_admin_edit_link();
620
-    }
621
-
622
-
623
-    /**
624
-     * Returns the link to the editor for the object.  Sometimes this is the same as the details.
625
-     *
626
-     * @return string
627
-     * @throws EE_Error
628
-     * @throws InvalidArgumentException
629
-     * @throws ReflectionException
630
-     * @throws InvalidDataTypeException
631
-     * @throws InvalidInterfaceException
632
-     */
633
-    public function get_admin_edit_link()
634
-    {
635
-        EE_Registry::instance()->load_helper('URL');
636
-        return EEH_URL::add_query_args_and_nonce(
637
-            [
638
-                'page'   => 'espresso_registrations',
639
-                'action' => 'edit_attendee',
640
-                'post'   => $this->ID(),
641
-            ],
642
-            admin_url('admin.php')
643
-        );
644
-    }
645
-
646
-
647
-    /**
648
-     * get Attendee Address
649
-     *
650
-     * @return string
651
-     * @throws EE_Error
652
-     */
653
-    public function address()
654
-    {
655
-        return $this->get('ATT_address');
656
-    }
657
-
658
-
659
-    /**
660
-     * Returns the link to a settings page for the object.
661
-     *
662
-     * @return string
663
-     * @throws EE_Error
664
-     * @throws InvalidArgumentException
665
-     * @throws InvalidDataTypeException
666
-     * @throws InvalidInterfaceException
667
-     * @throws ReflectionException
668
-     */
669
-    public function get_admin_settings_link()
670
-    {
671
-        return $this->get_admin_edit_link();
672
-    }
673
-
674
-
675
-    /**
676
-     * Returns the link to the "overview" for the object (typically the "list table" view).
677
-     *
678
-     * @return string
679
-     * @throws EE_Error
680
-     * @throws InvalidArgumentException
681
-     * @throws ReflectionException
682
-     * @throws InvalidDataTypeException
683
-     * @throws InvalidInterfaceException
684
-     */
685
-    public function get_admin_overview_link()
686
-    {
687
-        EE_Registry::instance()->load_helper('URL');
688
-        return EEH_URL::add_query_args_and_nonce(
689
-            [
690
-                'page'   => 'espresso_registrations',
691
-                'action' => 'contact_list',
692
-            ],
693
-            admin_url('admin.php')
694
-        );
695
-    }
696
-
697
-
698
-
699
-
700
-
701
-
702
-
703
-
704
-    /**
705
-     * get Attendee Address2
706
-     *
707
-     * @return string
708
-     * @throws EE_Error
709
-     */
710
-    public function address2()
711
-    {
712
-        return $this->get('ATT_address2');
713
-    }
714
-
715
-
716
-    /**
717
-     * Returns the state's name, otherwise 'Unknown'
718
-     *
719
-     * @return string
720
-     * @throws EE_Error
721
-     * @throws ReflectionException
722
-     */
723
-    public function state_name()
724
-    {
725
-        if ($this->state_obj()) {
726
-            return $this->state_obj()->name();
727
-        } else {
728
-            return '';
729
-        }
730
-    }
731
-
732
-
733
-    /**
734
-     * get Attendee City
735
-     *
736
-     * @return string
737
-     * @throws EE_Error
738
-     */
739
-    public function city()
740
-    {
741
-        return $this->get('ATT_city');
742
-    }
743
-
744
-
745
-    /**
746
-     * either displays the state abbreviation or the state name, as determined
747
-     * by the "FHEE__EEI_Address__state__use_abbreviation" filter.
748
-     * defaults to abbreviation
749
-     *
750
-     * @return string
751
-     * @throws EE_Error
752
-     * @throws ReflectionException
753
-     */
754
-    public function state()
755
-    {
756
-        if (apply_filters('FHEE__EEI_Address__state__use_abbreviation', true, $this->state_obj())) {
757
-            return $this->state_abbrev();
758
-        }
759
-        return $this->state_name();
760
-    }
761
-
762
-
763
-    /**
764
-     * get Attendee State ID
765
-     *
766
-     * @return string
767
-     * @throws EE_Error
768
-     */
769
-    public function state_ID()
770
-    {
771
-        return $this->get('STA_ID');
772
-    }
773
-
774
-
775
-    /**
776
-     * get Attendee Country ISO Code
777
-     *
778
-     * @return string
779
-     * @throws EE_Error
780
-     */
781
-    public function country_ID()
782
-    {
783
-        return $this->get('CNT_ISO');
784
-    }
785
-
786
-
787
-    /**
788
-     * Returns the country's name if known, otherwise 'Unknown'
789
-     *
790
-     * @return string
791
-     * @throws EE_Error
792
-     * @throws ReflectionException
793
-     */
794
-    public function country_name()
795
-    {
796
-        if ($this->country_obj()) {
797
-            return $this->country_obj()->name();
798
-        }
799
-        return '';
800
-    }
801
-
802
-
803
-    /**
804
-     * either displays the country ISO2 code or the country name, as determined
805
-     * by the "FHEE__EEI_Address__country__use_abbreviation" filter.
806
-     * defaults to abbreviation
807
-     *
808
-     * @return string
809
-     * @throws EE_Error
810
-     * @throws ReflectionException
811
-     */
812
-    public function country()
813
-    {
814
-        if (apply_filters('FHEE__EEI_Address__country__use_abbreviation', true, $this->country_obj())) {
815
-            return $this->country_ID();
816
-        }
817
-        return $this->country_name();
818
-    }
16
+	/**
17
+	 * Sets some dynamic defaults
18
+	 *
19
+	 * @param array  $fieldValues
20
+	 * @param bool   $bydb
21
+	 * @param string $timezone
22
+	 * @param array  $date_formats
23
+	 * @throws EE_Error
24
+	 * @throws ReflectionException
25
+	 */
26
+	protected function __construct($fieldValues = null, $bydb = false, $timezone = null, $date_formats = [])
27
+	{
28
+		if (! isset($fieldValues['ATT_full_name'])) {
29
+			$fname                        = isset($fieldValues['ATT_fname']) ? $fieldValues['ATT_fname'] . ' ' : '';
30
+			$lname                        = isset($fieldValues['ATT_lname']) ? $fieldValues['ATT_lname'] : '';
31
+			$fieldValues['ATT_full_name'] = $fname . $lname;
32
+		}
33
+		if (! isset($fieldValues['ATT_slug'])) {
34
+			// $fieldValues['ATT_slug'] = sanitize_key(wp_generate_password(20));
35
+			$fieldValues['ATT_slug'] = sanitize_title($fieldValues['ATT_full_name']);
36
+		}
37
+		if (! isset($fieldValues['ATT_short_bio']) && isset($fieldValues['ATT_bio'])) {
38
+			$fieldValues['ATT_short_bio'] = substr($fieldValues['ATT_bio'], 0, 50);
39
+		}
40
+		parent::__construct($fieldValues, $bydb, $timezone, $date_formats);
41
+	}
42
+
43
+
44
+	/**
45
+	 * @param array  $props_n_values    incoming values
46
+	 * @param string $timezone          incoming timezone
47
+	 *                                  (if not set the timezone set for the website will be used.)
48
+	 * @param array  $date_formats      incoming date_formats in an array where the first value is the
49
+	 *                                  date_format and the second value is the time format
50
+	 * @return EE_Attendee
51
+	 * @throws EE_Error
52
+	 * @throws ReflectionException
53
+	 */
54
+	public static function new_instance($props_n_values = [], $timezone = null, $date_formats = [])
55
+	{
56
+		$has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats);
57
+		return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats);
58
+	}
59
+
60
+
61
+	/**
62
+	 * @param array  $props_n_values  incoming values from the database
63
+	 * @param string $timezone        incoming timezone as set by the model.
64
+	 *                                If not set the timezone for the website will be used.
65
+	 * @return EE_Attendee
66
+	 * @throws EE_Error
67
+	 * @throws EE_Error
68
+	 * @throws ReflectionException
69
+	 */
70
+	public static function new_instance_from_db($props_n_values = [], $timezone = null)
71
+	{
72
+		return new self($props_n_values, true, $timezone);
73
+	}
74
+
75
+
76
+	/**
77
+	 * Set Attendee First Name
78
+	 *
79
+	 * @param string $fname
80
+	 * @throws EE_Error
81
+	 * @throws ReflectionException
82
+	 */
83
+	public function set_fname($fname = '')
84
+	{
85
+		$this->set('ATT_fname', $fname);
86
+	}
87
+
88
+
89
+	/**
90
+	 * Set Attendee Last Name
91
+	 *
92
+	 * @param string $lname
93
+	 * @throws EE_Error
94
+	 * @throws ReflectionException
95
+	 */
96
+	public function set_lname($lname = '')
97
+	{
98
+		$this->set('ATT_lname', $lname);
99
+	}
100
+
101
+
102
+	/**
103
+	 * Set Attendee Address
104
+	 *
105
+	 * @param string $address
106
+	 * @throws EE_Error
107
+	 * @throws ReflectionException
108
+	 */
109
+	public function set_address($address = '')
110
+	{
111
+		$this->set('ATT_address', $address);
112
+	}
113
+
114
+
115
+	/**
116
+	 * Set Attendee Address2
117
+	 *
118
+	 * @param string $address2
119
+	 * @throws EE_Error
120
+	 * @throws ReflectionException
121
+	 */
122
+	public function set_address2($address2 = '')
123
+	{
124
+		$this->set('ATT_address2', $address2);
125
+	}
126
+
127
+
128
+	/**
129
+	 * Set Attendee City
130
+	 *
131
+	 * @param string $city
132
+	 * @throws EE_Error
133
+	 * @throws ReflectionException
134
+	 */
135
+	public function set_city($city = '')
136
+	{
137
+		$this->set('ATT_city', $city);
138
+	}
139
+
140
+
141
+	/**
142
+	 * Set Attendee State ID
143
+	 *
144
+	 * @param int $STA_ID
145
+	 * @throws EE_Error
146
+	 * @throws ReflectionException
147
+	 */
148
+	public function set_state($STA_ID = 0)
149
+	{
150
+		$this->set('STA_ID', $STA_ID);
151
+	}
152
+
153
+
154
+	/**
155
+	 * Set Attendee Country ISO Code
156
+	 *
157
+	 * @param string $CNT_ISO
158
+	 * @throws EE_Error
159
+	 * @throws ReflectionException
160
+	 */
161
+	public function set_country($CNT_ISO = '')
162
+	{
163
+		$this->set('CNT_ISO', $CNT_ISO);
164
+	}
165
+
166
+
167
+	/**
168
+	 * Set Attendee Zip/Postal Code
169
+	 *
170
+	 * @param string $zip
171
+	 * @throws EE_Error
172
+	 * @throws ReflectionException
173
+	 */
174
+	public function set_zip($zip = '')
175
+	{
176
+		$this->set('ATT_zip', $zip);
177
+	}
178
+
179
+
180
+	/**
181
+	 * Set Attendee Email Address
182
+	 *
183
+	 * @param string $email
184
+	 * @throws EE_Error
185
+	 * @throws ReflectionException
186
+	 */
187
+	public function set_email($email = '')
188
+	{
189
+		$this->set('ATT_email', $email);
190
+	}
191
+
192
+
193
+	/**
194
+	 * Set Attendee Phone
195
+	 *
196
+	 * @param string $phone
197
+	 * @throws EE_Error
198
+	 * @throws ReflectionException
199
+	 */
200
+	public function set_phone($phone = '')
201
+	{
202
+		$this->set('ATT_phone', $phone);
203
+	}
204
+
205
+
206
+	/**
207
+	 * set deleted
208
+	 *
209
+	 * @param bool $ATT_deleted
210
+	 * @throws EE_Error
211
+	 * @throws ReflectionException
212
+	 */
213
+	public function set_deleted($ATT_deleted = false)
214
+	{
215
+		$this->set('ATT_deleted', $ATT_deleted);
216
+	}
217
+
218
+
219
+	/**
220
+	 * Returns the value for the post_author id saved with the cpt
221
+	 *
222
+	 * @return int
223
+	 * @throws EE_Error
224
+	 * @since 4.5.0
225
+	 */
226
+	public function wp_user()
227
+	{
228
+		return $this->get('ATT_author');
229
+	}
230
+
231
+
232
+	/**
233
+	 * echoes out the attendee's first name
234
+	 *
235
+	 * @return void
236
+	 * @throws EE_Error
237
+	 */
238
+	public function e_full_name()
239
+	{
240
+		echo $this->full_name();
241
+	}
242
+
243
+
244
+	/**
245
+	 * Returns the first and last name concatenated together with a space.
246
+	 *
247
+	 * @param bool $apply_html_entities
248
+	 * @return string
249
+	 * @throws EE_Error
250
+	 */
251
+	public function full_name($apply_html_entities = false)
252
+	{
253
+		$full_name = [
254
+			$this->fname(),
255
+			$this->lname(),
256
+		];
257
+		$full_name = array_filter($full_name);
258
+		$full_name = implode(' ', $full_name);
259
+		return $apply_html_entities
260
+			? htmlentities($full_name, ENT_QUOTES, 'UTF-8')
261
+			: $full_name;
262
+	}
263
+
264
+
265
+	/**
266
+	 * get Attendee First Name
267
+	 *
268
+	 * @return string
269
+	 * @throws EE_Error
270
+	 */
271
+	public function fname()
272
+	{
273
+		return $this->get('ATT_fname');
274
+	}
275
+
276
+
277
+	/**
278
+	 * get Attendee Last Name
279
+	 *
280
+	 * @return string
281
+	 * @throws EE_Error
282
+	 */
283
+	public function lname()
284
+	{
285
+		return $this->get('ATT_lname');
286
+	}
287
+
288
+
289
+	/**
290
+	 * get Attendee Email Address
291
+	 *
292
+	 * @return string
293
+	 * @throws EE_Error
294
+	 */
295
+	public function email()
296
+	{
297
+		return $this->get('ATT_email');
298
+	}
299
+
300
+
301
+	/**
302
+	 * get Attendee Phone #
303
+	 *
304
+	 * @return string
305
+	 * @throws EE_Error
306
+	 */
307
+	public function phone()
308
+	{
309
+		return $this->get('ATT_phone');
310
+	}
311
+
312
+
313
+	/**
314
+	 * This returns the value of the `ATT_full_name` field
315
+	 * which is usually equivalent to calling `full_name()`
316
+	 * unless the post_title field has been directly modified
317
+	 * in the db for the post (espresso_attendees post type)
318
+	 * for this attendee.
319
+	 *
320
+	 * @param bool $apply_html_entities
321
+	 * @return string
322
+	 * @throws EE_Error
323
+	 */
324
+	public function ATT_full_name($apply_html_entities = false)
325
+	{
326
+		return $apply_html_entities
327
+			? htmlentities(
328
+				$this->get('ATT_full_name'),
329
+				ENT_QUOTES,
330
+				'UTF-8'
331
+			)
332
+			: $this->get('ATT_full_name');
333
+	}
334
+
335
+
336
+	/**
337
+	 * get Attendee bio
338
+	 *
339
+	 * @return string
340
+	 * @throws EE_Error
341
+	 */
342
+	public function bio()
343
+	{
344
+		return $this->get('ATT_bio');
345
+	}
346
+
347
+
348
+	/**
349
+	 * get Attendee short bio
350
+	 *
351
+	 * @return string
352
+	 * @throws EE_Error
353
+	 */
354
+	public function short_bio()
355
+	{
356
+		return $this->get('ATT_short_bio');
357
+	}
358
+
359
+
360
+	/**
361
+	 * Gets the attendee's full address as an array
362
+	 * so client code can decide hwo to display it
363
+	 *
364
+	 * @return array numerically indexed,
365
+	 *               with each part of the address that is known.
366
+	 *               Eg, if the user only responded to state and country,
367
+	 *               it would be array(0=>'Alabama',1=>'USA')
368
+	 * @return array
369
+	 * @throws EE_Error
370
+	 * @throws ReflectionException
371
+	 */
372
+	public function full_address_as_array()
373
+	{
374
+		$full_address_array     = [];
375
+		$initial_address_fields = ['ATT_address', 'ATT_address2', 'ATT_city',];
376
+		foreach ($initial_address_fields as $address_field_name) {
377
+			$address_fields_value = $this->get($address_field_name);
378
+			if (! empty($address_fields_value)) {
379
+				$full_address_array[] = $address_fields_value;
380
+			}
381
+		}
382
+		// now handle state and country
383
+		$state_obj = $this->state_obj();
384
+		if ($state_obj instanceof EE_State) {
385
+			$full_address_array[] = $state_obj->name();
386
+		}
387
+		$country_obj = $this->country_obj();
388
+		if ($country_obj instanceof EE_Country) {
389
+			$full_address_array[] = $country_obj->name();
390
+		}
391
+		// lastly get the xip
392
+		$zip_value = $this->zip();
393
+		if (! empty($zip_value)) {
394
+			$full_address_array[] = $zip_value;
395
+		}
396
+		return $full_address_array;
397
+	}
398
+
399
+
400
+	/**
401
+	 * Gets the state set to this attendee
402
+	 *
403
+	 * @return EE_Base_Class|EE_State
404
+	 * @throws EE_Error
405
+	 * @throws ReflectionException
406
+	 */
407
+	public function state_obj()
408
+	{
409
+		return $this->get_first_related('State');
410
+	}
411
+
412
+
413
+	/**
414
+	 * Gets country set for this attendee
415
+	 *
416
+	 * @return EE_Base_Class|EE_Country
417
+	 * @throws EE_Error
418
+	 * @throws ReflectionException
419
+	 */
420
+	public function country_obj()
421
+	{
422
+		return $this->get_first_related('Country');
423
+	}
424
+
425
+
426
+	/**
427
+	 * get Attendee Zip/Postal Code
428
+	 *
429
+	 * @return string
430
+	 * @throws EE_Error
431
+	 */
432
+	public function zip()
433
+	{
434
+		return $this->get('ATT_zip');
435
+	}
436
+
437
+
438
+	/**
439
+	 * get deleted
440
+	 *
441
+	 * @return        bool
442
+	 * @throws EE_Error
443
+	 */
444
+	public function deleted()
445
+	{
446
+		return $this->get('ATT_deleted');
447
+	}
448
+
449
+
450
+	/**
451
+	 * Gets registrations of this attendee
452
+	 *
453
+	 * @param array $query_params
454
+	 * @return array[]|EE_Base_Class[]|EE_Registration[]
455
+	 * @throws EE_Error
456
+	 * @throws ReflectionException
457
+	 */
458
+	public function get_registrations($query_params = [])
459
+	{
460
+		return $this->get_many_related('Registration', $query_params);
461
+	}
462
+
463
+
464
+	/**
465
+	 * Gets the most recent registration of this attendee
466
+	 *
467
+	 * @return EE_Base_Class|EE_Registration
468
+	 * @throws EE_Error
469
+	 * @throws ReflectionException
470
+	 */
471
+	public function get_most_recent_registration()
472
+	{
473
+		return $this->get_first_related(
474
+			'Registration',
475
+			['order_by' => ['REG_date' => 'DESC']]
476
+		); // null, 'REG_date', 'DESC', '=', 'OBJECT_K');
477
+	}
478
+
479
+
480
+	/**
481
+	 * Gets the most recent registration for this attend at this event
482
+	 *
483
+	 * @param int $event_id
484
+	 * @return EE_Base_Class|EE_Registration
485
+	 * @throws EE_Error
486
+	 * @throws ReflectionException
487
+	 */
488
+	public function get_most_recent_registration_for_event($event_id)
489
+	{
490
+		return $this->get_first_related(
491
+			'Registration',
492
+			[['EVT_ID' => $event_id], 'order_by' => ['REG_date' => 'DESC']]
493
+		);
494
+	}
495
+
496
+
497
+	/**
498
+	 * returns any events attached to this attendee ($_Event property);
499
+	 *
500
+	 * @return array
501
+	 * @throws EE_Error
502
+	 * @throws ReflectionException
503
+	 */
504
+	public function events()
505
+	{
506
+		return $this->get_many_related('Event');
507
+	}
508
+
509
+
510
+	/**
511
+	 * @return string
512
+	 * @throws EE_Error
513
+	 * @throws ReflectionException
514
+	 */
515
+	public function state_abbrev()
516
+	{
517
+		return $this->state_obj() instanceof EE_State ? $this->state_obj()->abbrev() : '';
518
+	}
519
+
520
+
521
+	/**
522
+	 * Gets the billing info array where keys match espresso_reg_page_billing_inputs(),
523
+	 * and keys are their cleaned values.
524
+	 *
525
+	 * @param EE_Payment_Method $payment_method the _gateway_name property on the gateway class
526
+	 * @return EE_Form_Section_Proper|null
527
+	 * @throws EE_Error
528
+	 * @see EE_Attendee::save_and_clean_billing_info_for_payment_method() which was
529
+	 *                                          used to save the billing info
530
+	 */
531
+	public function billing_info_for_payment_method($payment_method)
532
+	{
533
+		$pm_type = $payment_method->type_obj();
534
+		if (! $pm_type instanceof EE_PMT_Base) {
535
+			return null;
536
+		}
537
+		$billing_info = $this->get_post_meta($this->get_billing_info_postmeta_name($payment_method), true);
538
+		if (! $billing_info) {
539
+			return null;
540
+		}
541
+		$billing_form = $pm_type->billing_form();
542
+		// double-check the form isn't totally hidden, in which case pretend there is no form
543
+		$form_totally_hidden = true;
544
+		foreach ($billing_form->inputs_in_subsections() as $input) {
545
+			if (! $input->get_display_strategy() instanceof EE_Hidden_Display_Strategy) {
546
+				$form_totally_hidden = false;
547
+				break;
548
+			}
549
+		}
550
+		if ($form_totally_hidden) {
551
+			return null;
552
+		}
553
+		if ($billing_form instanceof EE_Form_Section_Proper) {
554
+			$billing_form->receive_form_submission([$billing_form->name() => $billing_info], false);
555
+		}
556
+
557
+		return $billing_form;
558
+	}
559
+
560
+
561
+	/**
562
+	 * Gets the postmeta key that holds this attendee's billing info for the
563
+	 * specified payment method
564
+	 *
565
+	 * @param EE_Payment_Method $payment_method
566
+	 * @return string
567
+	 * @throws EE_Error
568
+	 */
569
+	public function get_billing_info_postmeta_name($payment_method)
570
+	{
571
+		if ($payment_method->type_obj() instanceof EE_PMT_Base) {
572
+			return 'billing_info_' . $payment_method->type_obj()->system_name();
573
+		}
574
+		return null;
575
+	}
576
+
577
+
578
+	/**
579
+	 * Saves the billing info to the attendee. @param EE_Billing_Attendee_Info_Form $billing_form
580
+	 *
581
+	 * @param EE_Payment_Method $payment_method
582
+	 * @return boolean
583
+	 * @throws EE_Error
584
+	 * @see EE_Attendee::billing_info_for_payment_method() which is used to
585
+	 *      retrieve it
586
+	 */
587
+	public function save_and_clean_billing_info_for_payment_method($billing_form, $payment_method)
588
+	{
589
+		if (! $billing_form instanceof EE_Billing_Attendee_Info_Form) {
590
+			EE_Error::add_error(
591
+				__('Cannot save billing info because there is none.', 'event_espresso'),
592
+				__FILE__,
593
+				__FUNCTION__,
594
+				__LINE__
595
+			);
596
+			return false;
597
+		}
598
+		$billing_form->clean_sensitive_data();
599
+		return update_post_meta(
600
+			$this->ID(),
601
+			$this->get_billing_info_postmeta_name($payment_method),
602
+			$billing_form->input_values(true)
603
+		);
604
+	}
605
+
606
+
607
+	/**
608
+	 * Return the link to the admin details for the object.
609
+	 *
610
+	 * @return string
611
+	 * @throws EE_Error
612
+	 * @throws InvalidArgumentException
613
+	 * @throws InvalidDataTypeException
614
+	 * @throws InvalidInterfaceException
615
+	 * @throws ReflectionException
616
+	 */
617
+	public function get_admin_details_link()
618
+	{
619
+		return $this->get_admin_edit_link();
620
+	}
621
+
622
+
623
+	/**
624
+	 * Returns the link to the editor for the object.  Sometimes this is the same as the details.
625
+	 *
626
+	 * @return string
627
+	 * @throws EE_Error
628
+	 * @throws InvalidArgumentException
629
+	 * @throws ReflectionException
630
+	 * @throws InvalidDataTypeException
631
+	 * @throws InvalidInterfaceException
632
+	 */
633
+	public function get_admin_edit_link()
634
+	{
635
+		EE_Registry::instance()->load_helper('URL');
636
+		return EEH_URL::add_query_args_and_nonce(
637
+			[
638
+				'page'   => 'espresso_registrations',
639
+				'action' => 'edit_attendee',
640
+				'post'   => $this->ID(),
641
+			],
642
+			admin_url('admin.php')
643
+		);
644
+	}
645
+
646
+
647
+	/**
648
+	 * get Attendee Address
649
+	 *
650
+	 * @return string
651
+	 * @throws EE_Error
652
+	 */
653
+	public function address()
654
+	{
655
+		return $this->get('ATT_address');
656
+	}
657
+
658
+
659
+	/**
660
+	 * Returns the link to a settings page for the object.
661
+	 *
662
+	 * @return string
663
+	 * @throws EE_Error
664
+	 * @throws InvalidArgumentException
665
+	 * @throws InvalidDataTypeException
666
+	 * @throws InvalidInterfaceException
667
+	 * @throws ReflectionException
668
+	 */
669
+	public function get_admin_settings_link()
670
+	{
671
+		return $this->get_admin_edit_link();
672
+	}
673
+
674
+
675
+	/**
676
+	 * Returns the link to the "overview" for the object (typically the "list table" view).
677
+	 *
678
+	 * @return string
679
+	 * @throws EE_Error
680
+	 * @throws InvalidArgumentException
681
+	 * @throws ReflectionException
682
+	 * @throws InvalidDataTypeException
683
+	 * @throws InvalidInterfaceException
684
+	 */
685
+	public function get_admin_overview_link()
686
+	{
687
+		EE_Registry::instance()->load_helper('URL');
688
+		return EEH_URL::add_query_args_and_nonce(
689
+			[
690
+				'page'   => 'espresso_registrations',
691
+				'action' => 'contact_list',
692
+			],
693
+			admin_url('admin.php')
694
+		);
695
+	}
696
+
697
+
698
+
699
+
700
+
701
+
702
+
703
+
704
+	/**
705
+	 * get Attendee Address2
706
+	 *
707
+	 * @return string
708
+	 * @throws EE_Error
709
+	 */
710
+	public function address2()
711
+	{
712
+		return $this->get('ATT_address2');
713
+	}
714
+
715
+
716
+	/**
717
+	 * Returns the state's name, otherwise 'Unknown'
718
+	 *
719
+	 * @return string
720
+	 * @throws EE_Error
721
+	 * @throws ReflectionException
722
+	 */
723
+	public function state_name()
724
+	{
725
+		if ($this->state_obj()) {
726
+			return $this->state_obj()->name();
727
+		} else {
728
+			return '';
729
+		}
730
+	}
731
+
732
+
733
+	/**
734
+	 * get Attendee City
735
+	 *
736
+	 * @return string
737
+	 * @throws EE_Error
738
+	 */
739
+	public function city()
740
+	{
741
+		return $this->get('ATT_city');
742
+	}
743
+
744
+
745
+	/**
746
+	 * either displays the state abbreviation or the state name, as determined
747
+	 * by the "FHEE__EEI_Address__state__use_abbreviation" filter.
748
+	 * defaults to abbreviation
749
+	 *
750
+	 * @return string
751
+	 * @throws EE_Error
752
+	 * @throws ReflectionException
753
+	 */
754
+	public function state()
755
+	{
756
+		if (apply_filters('FHEE__EEI_Address__state__use_abbreviation', true, $this->state_obj())) {
757
+			return $this->state_abbrev();
758
+		}
759
+		return $this->state_name();
760
+	}
761
+
762
+
763
+	/**
764
+	 * get Attendee State ID
765
+	 *
766
+	 * @return string
767
+	 * @throws EE_Error
768
+	 */
769
+	public function state_ID()
770
+	{
771
+		return $this->get('STA_ID');
772
+	}
773
+
774
+
775
+	/**
776
+	 * get Attendee Country ISO Code
777
+	 *
778
+	 * @return string
779
+	 * @throws EE_Error
780
+	 */
781
+	public function country_ID()
782
+	{
783
+		return $this->get('CNT_ISO');
784
+	}
785
+
786
+
787
+	/**
788
+	 * Returns the country's name if known, otherwise 'Unknown'
789
+	 *
790
+	 * @return string
791
+	 * @throws EE_Error
792
+	 * @throws ReflectionException
793
+	 */
794
+	public function country_name()
795
+	{
796
+		if ($this->country_obj()) {
797
+			return $this->country_obj()->name();
798
+		}
799
+		return '';
800
+	}
801
+
802
+
803
+	/**
804
+	 * either displays the country ISO2 code or the country name, as determined
805
+	 * by the "FHEE__EEI_Address__country__use_abbreviation" filter.
806
+	 * defaults to abbreviation
807
+	 *
808
+	 * @return string
809
+	 * @throws EE_Error
810
+	 * @throws ReflectionException
811
+	 */
812
+	public function country()
813
+	{
814
+		if (apply_filters('FHEE__EEI_Address__country__use_abbreviation', true, $this->country_obj())) {
815
+			return $this->country_ID();
816
+		}
817
+		return $this->country_name();
818
+	}
819 819
 }
Please login to merge, or discard this patch.
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -25,16 +25,16 @@  discard block
 block discarded – undo
25 25
      */
26 26
     protected function __construct($fieldValues = null, $bydb = false, $timezone = null, $date_formats = [])
27 27
     {
28
-        if (! isset($fieldValues['ATT_full_name'])) {
29
-            $fname                        = isset($fieldValues['ATT_fname']) ? $fieldValues['ATT_fname'] . ' ' : '';
28
+        if ( ! isset($fieldValues['ATT_full_name'])) {
29
+            $fname                        = isset($fieldValues['ATT_fname']) ? $fieldValues['ATT_fname'].' ' : '';
30 30
             $lname                        = isset($fieldValues['ATT_lname']) ? $fieldValues['ATT_lname'] : '';
31
-            $fieldValues['ATT_full_name'] = $fname . $lname;
31
+            $fieldValues['ATT_full_name'] = $fname.$lname;
32 32
         }
33
-        if (! isset($fieldValues['ATT_slug'])) {
33
+        if ( ! isset($fieldValues['ATT_slug'])) {
34 34
             // $fieldValues['ATT_slug'] = sanitize_key(wp_generate_password(20));
35 35
             $fieldValues['ATT_slug'] = sanitize_title($fieldValues['ATT_full_name']);
36 36
         }
37
-        if (! isset($fieldValues['ATT_short_bio']) && isset($fieldValues['ATT_bio'])) {
37
+        if ( ! isset($fieldValues['ATT_short_bio']) && isset($fieldValues['ATT_bio'])) {
38 38
             $fieldValues['ATT_short_bio'] = substr($fieldValues['ATT_bio'], 0, 50);
39 39
         }
40 40
         parent::__construct($fieldValues, $bydb, $timezone, $date_formats);
@@ -372,10 +372,10 @@  discard block
 block discarded – undo
372 372
     public function full_address_as_array()
373 373
     {
374 374
         $full_address_array     = [];
375
-        $initial_address_fields = ['ATT_address', 'ATT_address2', 'ATT_city',];
375
+        $initial_address_fields = ['ATT_address', 'ATT_address2', 'ATT_city', ];
376 376
         foreach ($initial_address_fields as $address_field_name) {
377 377
             $address_fields_value = $this->get($address_field_name);
378
-            if (! empty($address_fields_value)) {
378
+            if ( ! empty($address_fields_value)) {
379 379
                 $full_address_array[] = $address_fields_value;
380 380
             }
381 381
         }
@@ -390,7 +390,7 @@  discard block
 block discarded – undo
390 390
         }
391 391
         // lastly get the xip
392 392
         $zip_value = $this->zip();
393
-        if (! empty($zip_value)) {
393
+        if ( ! empty($zip_value)) {
394 394
             $full_address_array[] = $zip_value;
395 395
         }
396 396
         return $full_address_array;
@@ -531,18 +531,18 @@  discard block
 block discarded – undo
531 531
     public function billing_info_for_payment_method($payment_method)
532 532
     {
533 533
         $pm_type = $payment_method->type_obj();
534
-        if (! $pm_type instanceof EE_PMT_Base) {
534
+        if ( ! $pm_type instanceof EE_PMT_Base) {
535 535
             return null;
536 536
         }
537 537
         $billing_info = $this->get_post_meta($this->get_billing_info_postmeta_name($payment_method), true);
538
-        if (! $billing_info) {
538
+        if ( ! $billing_info) {
539 539
             return null;
540 540
         }
541 541
         $billing_form = $pm_type->billing_form();
542 542
         // double-check the form isn't totally hidden, in which case pretend there is no form
543 543
         $form_totally_hidden = true;
544 544
         foreach ($billing_form->inputs_in_subsections() as $input) {
545
-            if (! $input->get_display_strategy() instanceof EE_Hidden_Display_Strategy) {
545
+            if ( ! $input->get_display_strategy() instanceof EE_Hidden_Display_Strategy) {
546 546
                 $form_totally_hidden = false;
547 547
                 break;
548 548
             }
@@ -569,7 +569,7 @@  discard block
 block discarded – undo
569 569
     public function get_billing_info_postmeta_name($payment_method)
570 570
     {
571 571
         if ($payment_method->type_obj() instanceof EE_PMT_Base) {
572
-            return 'billing_info_' . $payment_method->type_obj()->system_name();
572
+            return 'billing_info_'.$payment_method->type_obj()->system_name();
573 573
         }
574 574
         return null;
575 575
     }
@@ -586,7 +586,7 @@  discard block
 block discarded – undo
586 586
      */
587 587
     public function save_and_clean_billing_info_for_payment_method($billing_form, $payment_method)
588 588
     {
589
-        if (! $billing_form instanceof EE_Billing_Attendee_Info_Form) {
589
+        if ( ! $billing_form instanceof EE_Billing_Attendee_Info_Form) {
590 590
             EE_Error::add_error(
591 591
                 __('Cannot save billing info because there is none.', 'event_espresso'),
592 592
                 __FILE__,
Please login to merge, or discard this patch.
core/db_classes/EE_CPT_Base.class.php 3 patches
Doc Comments   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -167,7 +167,7 @@  discard block
 block discarded – undo
167 167
      *
168 168
      * @link   http://codex.wordpress.org/Function_Reference/get_the_post_thumbnail
169 169
      * @access protected
170
-     * @param string|array $size (optional) Image size. Defaults to 'post-thumbnail' but can also be a 2-item array
170
+     * @param string $size (optional) Image size. Defaults to 'post-thumbnail' but can also be a 2-item array
171 171
      *                           representing width and height in pixels (i.e. array(32,32) ).
172 172
      * @param string|array $attr Optional. Query string or array of attributes.
173 173
      * @return string HTML image element
@@ -211,7 +211,7 @@  discard block
 block discarded – undo
211 211
      * This is a method for restoring this_obj using details from the given $revision_id
212 212
      *
213 213
      * @param int   $revision_id       ID of the revision we're getting data from
214
-     * @param array $related_obj_names if included this will be used to restore for related obj
214
+     * @param string[] $related_obj_names if included this will be used to restore for related obj
215 215
      *                                 if not included then we just do restore on the meta.
216 216
      *                                 We will accept an array of related_obj_names for restoration here.
217 217
      * @param array $where_query       You can optionally include an array of key=>value pairs
@@ -277,7 +277,7 @@  discard block
 block discarded – undo
277 277
      *
278 278
      * @param string  $meta_key
279 279
      * @param boolean $single
280
-     * @return mixed
280
+     * @return string|null
281 281
      * @throws EE_Error
282 282
      */
283 283
     public function get_post_meta($meta_key = null, $single = false)
@@ -312,8 +312,8 @@  discard block
 block discarded – undo
312 312
     /**
313 313
      * Wrapper for add_post_meta, http://codex.wordpress.org/Function_Reference/add_post_meta
314 314
      *
315
-     * @param mixed $meta_key
316
-     * @param mixed $meta_value
315
+     * @param string $meta_key
316
+     * @param string $meta_value
317 317
      * @param bool  $unique     If postmeta for this $meta_key already exists,
318 318
      *                          whether to add an additional item or not
319 319
      * @return boolean          Boolean true, except if the $unique argument was set to true
@@ -334,7 +334,7 @@  discard block
 block discarded – undo
334 334
     /**
335 335
      * Wrapper for delete_post_meta, http://codex.wordpress.org/Function_Reference/delete_post_meta
336 336
      *
337
-     * @param mixed $meta_key
337
+     * @param string $meta_key
338 338
      * @param mixed $meta_value
339 339
      * @return boolean False for failure. True for success.
340 340
      * @throws EE_Error
Please login to merge, or discard this patch.
Indentation   +483 added lines, -483 removed lines patch added patch discarded remove patch
@@ -12,487 +12,487 @@
 block discarded – undo
12 12
 abstract class EE_CPT_Base extends EE_Soft_Delete_Base_Class
13 13
 {
14 14
 
15
-    /**
16
-     * This is a property for holding cached feature images on CPT objects.
17
-     * Cache's are set on the first "feature_image()" method call.
18
-     * Each key in the array corresponds to the requested size.
19
-     *
20
-     * @var array
21
-     */
22
-    protected $_feature_image = [];
23
-
24
-    /**
25
-     * @var WP_Post the WP_Post that corresponds with this CPT model object
26
-     */
27
-    protected $_wp_post;
28
-
29
-
30
-    abstract public function wp_user();
31
-
32
-
33
-    /**
34
-     * Adds to the specified event category. If it category doesn't exist, creates it.
35
-     *
36
-     * @param string $category_name
37
-     * @param string $category_description    optional
38
-     * @param int    $parent_term_taxonomy_id optional
39
-     * @return EE_Term_Taxonomy
40
-     * @throws EE_Error
41
-     * @throws ReflectionException
42
-     */
43
-    public function add_event_category($category_name, $category_description = null, $parent_term_taxonomy_id = null)
44
-    {
45
-        return $this->get_model()->add_event_category(
46
-            $this,
47
-            $category_name,
48
-            $category_description,
49
-            $parent_term_taxonomy_id
50
-        );
51
-    }
52
-
53
-
54
-    /**
55
-     * Removes the event category by specified name from being related ot this event
56
-     *
57
-     * @param string $category_name
58
-     * @return bool
59
-     * @throws EE_Error
60
-     * @throws ReflectionException
61
-     */
62
-    public function remove_event_category($category_name)
63
-    {
64
-        return $this->get_model()->remove_event_category($this, $category_name);
65
-    }
66
-
67
-
68
-    /**
69
-     * Removes the relation to the specified term taxonomy, and maintains the
70
-     * data integrity of the term taxonomy provided
71
-     *
72
-     * @param EE_Term_Taxonomy $term_taxonomy
73
-     * @return EE_Base_Class the relation was removed from
74
-     * @throws EE_Error
75
-     * @throws ReflectionException
76
-     */
77
-    public function remove_relation_to_term_taxonomy($term_taxonomy)
78
-    {
79
-        if (! $term_taxonomy) {
80
-            EE_Error::add_error(
81
-                sprintf(
82
-                    esc_html__(
83
-                        "No Term_Taxonomy provided which to remove from model object of type %s and id %d",
84
-                        "event_espresso"
85
-                    ),
86
-                    get_class($this),
87
-                    $this->ID()
88
-                ),
89
-                __FILE__,
90
-                __FUNCTION__,
91
-                __LINE__
92
-            );
93
-            return null;
94
-        }
95
-        $term_taxonomy->set_count($term_taxonomy->count() - 1);
96
-        $term_taxonomy->save();
97
-        return $this->_remove_relation_to($term_taxonomy, 'Term_Taxonomy');
98
-    }
99
-
100
-
101
-    /**
102
-     * The main purpose of this method is to return the post type for the model object
103
-     *
104
-     * @return string
105
-     * @throws EE_Error
106
-     * @throws ReflectionException
107
-     */
108
-    public function post_type()
109
-    {
110
-        return $this->get_model()->post_type();
111
-    }
112
-
113
-
114
-    /**
115
-     * The main purpose of this method is to return the parent for the model object
116
-     *
117
-     * @return int
118
-     * @throws EE_Error
119
-     */
120
-    public function parent()
121
-    {
122
-        return $this->get('parent');
123
-    }
124
-
125
-
126
-    /**
127
-     * return the _status property
128
-     *
129
-     * @return string
130
-     * @throws EE_Error
131
-     */
132
-    public function status()
133
-    {
134
-        return $this->get('status');
135
-    }
136
-
137
-
138
-    /**
139
-     * @param string $status
140
-     * @throws EE_Error
141
-     * @throws ReflectionException
142
-     */
143
-    public function set_status($status)
144
-    {
145
-        $this->set('status', $status);
146
-    }
147
-
148
-
149
-    /**
150
-     * See _get_feature_image. Returns the HTML to display a featured image
151
-     *
152
-     * @param string       $size
153
-     * @param string|array $attr
154
-     * @return string of html
155
-     * @throws EE_Error
156
-     * @throws ReflectionException
157
-     */
158
-    public function feature_image($size = 'thumbnail', $attr = '')
159
-    {
160
-        return $this->_get_feature_image($size, $attr);
161
-    }
162
-
163
-
164
-    /**
165
-     * This calls the equivalent model method for retrieving the feature image
166
-     * which in turn is a wrapper for WordPress' get_the_post_thumbnail() function.
167
-     *
168
-     * @link   http://codex.wordpress.org/Function_Reference/get_the_post_thumbnail
169
-     * @access protected
170
-     * @param string|array $size (optional) Image size. Defaults to 'post-thumbnail' but can also be a 2-item array
171
-     *                           representing width and height in pixels (i.e. array(32,32) ).
172
-     * @param string|array $attr Optional. Query string or array of attributes.
173
-     * @return string HTML image element
174
-     * @throws EE_Error
175
-     * @throws ReflectionException
176
-     */
177
-    protected function _get_feature_image($size, $attr)
178
-    {
179
-        // first let's see if we already have the _feature_image property set
180
-        // AND if it has a cached element on it FOR the given size
181
-        $attr_key                           = is_array($attr)
182
-            ? implode('_', $attr)
183
-            : $attr;
184
-        $cache_key                          = is_array($size)
185
-            ? implode('_', $size) . $attr_key
186
-            : $size . $attr_key;
187
-        $this->_feature_image[ $cache_key ] = isset($this->_feature_image[ $cache_key ])
188
-            ? $this->_feature_image[ $cache_key ]
189
-            : $this->get_model()->get_feature_image($this->ID(), $size, $attr);
190
-        return $this->_feature_image[ $cache_key ];
191
-    }
192
-
193
-
194
-    /**
195
-     * This uses the wp "wp_get_attachment_image_src()" function to return the feature image for the current class
196
-     * using the given size params.
197
-     *
198
-     * @param string|array $size  can either be a string: 'thumbnail', 'medium', 'large', 'full' OR 2-item array
199
-     *                            representing width and height in pixels eg. array(32,32).
200
-     * @return string|boolean          the url of the image or false if not found
201
-     * @throws EE_Error
202
-     */
203
-    public function feature_image_url($size = 'thumbnail')
204
-    {
205
-        $attachment = wp_get_attachment_image_src(get_post_thumbnail_id($this->ID()), $size);
206
-        return ! empty($attachment) ? $attachment[0] : false;
207
-    }
208
-
209
-
210
-    /**
211
-     * This is a method for restoring this_obj using details from the given $revision_id
212
-     *
213
-     * @param int   $revision_id       ID of the revision we're getting data from
214
-     * @param array $related_obj_names if included this will be used to restore for related obj
215
-     *                                 if not included then we just do restore on the meta.
216
-     *                                 We will accept an array of related_obj_names for restoration here.
217
-     * @param array $where_query       You can optionally include an array of key=>value pairs
218
-     *                                 that allow you to further constrict the relation to being added.
219
-     *                                 However, keep in mind that the columns (keys) given
220
-     *                                 must match a column on the JOIN table and currently
221
-     *                                 only the HABTM models accept these additional conditions.
222
-     *                                 Also remember that if an exact match isn't found for these extra cols/val pairs,
223
-     *                                 then a NEW row is created in the join table.
224
-     *                                 This array is INDEXED by RELATED OBJ NAME (so it corresponds with the obj_names
225
-     *                                 sent);
226
-     * @return void
227
-     * @throws EE_Error
228
-     * @throws ReflectionException
229
-     */
230
-    public function restore_revision($revision_id, $related_obj_names = [], $where_query = [])
231
-    {
232
-        // get revision object
233
-        $revision_obj = $this->get_model()->get_one_by_ID($revision_id);
234
-        if ($revision_obj instanceof EE_CPT_Base) {
235
-            // no related_obj_name so we assume we're saving a revision on this object.
236
-            if (empty($related_obj_names)) {
237
-                $fields = $this->get_model()->get_meta_table_fields();
238
-                foreach ($fields as $field) {
239
-                    $this->set($field, $revision_obj->get($field));
240
-                }
241
-                $this->save();
242
-            }
243
-            $related_obj_names = (array) $related_obj_names;
244
-            foreach ($related_obj_names as $related_name) {
245
-                // related_obj_name so we're saving a revision on an object related to this object
246
-                // do we have $where_query params for this related object?  If we do then we include that.
247
-                $cols_n_values         = isset($where_query[ $related_name ])
248
-                    ? $where_query[ $related_name ]
249
-                    : [];
250
-                $where_params          = ! empty($cols_n_values) ? [$cols_n_values] : [];
251
-                $related_objs          = $this->get_many_related($related_name, $where_params);
252
-                $revision_related_objs = $revision_obj->get_many_related($related_name, $where_params);
253
-                // load helper
254
-                // remove related objs from this object that are not in revision
255
-                // array_diff *should* work cause I think objects are indexed by ID?
256
-                $related_to_remove = EEH_Array::object_array_diff($related_objs, $revision_related_objs);
257
-                foreach ($related_to_remove as $rr) {
258
-                    $this->_remove_relation_to($rr, $related_name, $cols_n_values);
259
-                }
260
-                // add all related objs attached to revision to this object
261
-                foreach ($revision_related_objs as $r_obj) {
262
-                    $this->_add_relation_to($r_obj, $related_name, $cols_n_values);
263
-                }
264
-            }
265
-        }
266
-    }
267
-
268
-
269
-    /**
270
-     * Wrapper for get_post_meta, http://codex.wordpress.org/Function_Reference/get_post_meta
271
-     * If only $id is set:
272
-     *  it will return all meta values in an associative array.
273
-     * If $single is set to false, or left blank:
274
-     *  the function returns an array containing all values of the specified key.
275
-     * If $single is set to true:
276
-     *  the function returns the first value of the specified key (not in an array)
277
-     *
278
-     * @param string  $meta_key
279
-     * @param boolean $single
280
-     * @return mixed
281
-     * @throws EE_Error
282
-     */
283
-    public function get_post_meta($meta_key = null, $single = false)
284
-    {
285
-        return get_post_meta($this->ID(), $meta_key, $single);
286
-    }
287
-
288
-
289
-    /**
290
-     * Wrapper for update_post_meta, http://codex.wordpress.org/Function_Reference/update_post_meta
291
-     * Returns meta_id if the meta doesn't exist,
292
-     * otherwise returns true on success and false on failure.
293
-     * NOTE: If the meta_value passed to this function is the same
294
-     * as the value that is already in the database, this function returns false.
295
-     *
296
-     * @param string $meta_key
297
-     * @param mixed  $meta_value
298
-     * @param mixed  $prev_value
299
-     * @return mixed
300
-     * @throws EE_Error
301
-     * @throws ReflectionException
302
-     */
303
-    public function update_post_meta($meta_key, $meta_value, $prev_value = null)
304
-    {
305
-        if (! $this->ID()) {
306
-            $this->save();
307
-        }
308
-        return update_post_meta($this->ID(), $meta_key, $meta_value, $prev_value);
309
-    }
310
-
311
-
312
-    /**
313
-     * Wrapper for add_post_meta, http://codex.wordpress.org/Function_Reference/add_post_meta
314
-     *
315
-     * @param mixed $meta_key
316
-     * @param mixed $meta_value
317
-     * @param bool  $unique     If postmeta for this $meta_key already exists,
318
-     *                          whether to add an additional item or not
319
-     * @return boolean          Boolean true, except if the $unique argument was set to true
320
-     *                          and a custom field with the given key already exists,
321
-     *                          in which case false is returned.
322
-     * @throws EE_Error
323
-     * @throws ReflectionException
324
-     */
325
-    public function add_post_meta($meta_key, $meta_value, $unique = false)
326
-    {
327
-        if ($this->ID()) {
328
-            $this->save();
329
-        }
330
-        return add_post_meta($this->ID(), $meta_key, $meta_value, $unique);
331
-    }
332
-
333
-
334
-    /**
335
-     * Wrapper for delete_post_meta, http://codex.wordpress.org/Function_Reference/delete_post_meta
336
-     *
337
-     * @param mixed $meta_key
338
-     * @param mixed $meta_value
339
-     * @return boolean False for failure. True for success.
340
-     * @throws EE_Error
341
-     */
342
-    public function delete_post_meta($meta_key, $meta_value = '')
343
-    {
344
-        if (! $this->ID()) {
345
-            // there is obviously no postmeta for this if it's not saved
346
-            // so let's just report this as a success
347
-            return true;
348
-        }
349
-        return delete_post_meta($this->ID(), $meta_key, $meta_value);
350
-    }
351
-
352
-
353
-    /**
354
-     * Gets the URL for viewing this event on the front-end
355
-     *
356
-     * @return string
357
-     * @throws EE_Error
358
-     */
359
-    public function get_permalink()
360
-    {
361
-        return get_permalink($this->ID());
362
-    }
363
-
364
-
365
-    /**
366
-     * Gets all the term-taxonomies for this CPT
367
-     *
368
-     * @param array $query_params
369
-     * @return array[]|EE_Base_Class[]|EE_Term_Taxonomy
370
-     * @throws EE_Error
371
-     * @throws ReflectionException
372
-     */
373
-    public function term_taxonomies($query_params = [])
374
-    {
375
-        return $this->get_many_related('Term_Taxonomy', $query_params);
376
-    }
377
-
378
-
379
-    /**
380
-     * @return mixed
381
-     * @throws EE_Error
382
-     * @throws ReflectionException
383
-     */
384
-    public function get_custom_post_statuses()
385
-    {
386
-        return $this->get_model()->get_custom_post_statuses();
387
-    }
388
-
389
-
390
-    /**
391
-     * @return mixed
392
-     * @throws EE_Error
393
-     * @throws ReflectionException
394
-     */
395
-    public function get_all_post_statuses()
396
-    {
397
-        return $this->get_model()->get_status_array();
398
-    }
399
-
400
-
401
-    /**
402
-     * When fetching a new value for a post field that uses the global $post for rendering,
403
-     * set the global $post temporarily to be this model object; and afterwards restore it
404
-     *
405
-     * @param string $field_name
406
-     * @param bool   $pretty
407
-     * @param string $extra_cache_ref
408
-     * @return mixed
409
-     * @throws EE_Error
410
-     * @throws ReflectionException
411
-     */
412
-    protected function _get_fresh_property($field_name, $pretty = false, $extra_cache_ref = null)
413
-    {
414
-        global $post;
415
-
416
-        if (
417
-            $pretty
418
-            && (
419
-                ! (
420
-                    $post instanceof WP_Post
421
-                    && $post->ID
422
-                )
423
-                || (int) $post->ID !== $this->ID()
424
-            )
425
-            && $this->get_model()->field_settings_for($field_name) instanceof EE_Post_Content_Field
426
-        ) {
427
-            $old_post     = $post;
428
-            $post         = $this->wp_post();
429
-            $return_value = parent::_get_fresh_property($field_name, $pretty, $extra_cache_ref);
430
-            $post         = $old_post;
431
-        } else {
432
-            $return_value = parent::_get_fresh_property($field_name, $pretty, $extra_cache_ref);
433
-        }
434
-        return $return_value;
435
-    }
436
-
437
-
438
-    /**
439
-     * Returns the WP post associated with this CPT model object.
440
-     * If this CPT is saved, fetches it from the DB.
441
-     * Otherwise, create an unsaved WP_POst object. Caches the post internally.
442
-     *
443
-     * @return WP_Post
444
-     * @throws EE_Error
445
-     * @throws ReflectionException
446
-     */
447
-    public function wp_post()
448
-    {
449
-        global $wpdb;
450
-        if (! $this->_wp_post instanceof WP_Post) {
451
-            if ($this->ID()) {
452
-                $this->_wp_post = get_post($this->ID());
453
-            } else {
454
-                $simulated_db_result = new stdClass();
455
-                $field_settings      = $this->get_model()->field_settings(true);
456
-                foreach ($field_settings as $field_name => $field_obj) {
457
-                    if (
458
-                        $this->get_model()->get_table_obj_by_alias($field_obj->get_table_alias())
459
-                             ->get_table_name() === $wpdb->posts
460
-                    ) {
461
-                        $column = $field_obj->get_table_column();
462
-
463
-                        if ($field_obj instanceof EE_Datetime_Field) {
464
-                            $value_on_model_obj = $this->get_DateTime_object($field_name);
465
-                        } elseif ($field_obj->is_db_only_field()) {
466
-                            $value_on_model_obj = $field_obj->get_default_value();
467
-                        } else {
468
-                            $value_on_model_obj = $this->get_raw($field_name);
469
-                        }
470
-                        $simulated_db_result->{$column} = $field_obj->prepare_for_use_in_db($value_on_model_obj);
471
-                    }
472
-                }
473
-                $this->_wp_post = new WP_Post($simulated_db_result);
474
-            }
475
-            // and let's make retrieving the EE CPT object easy too
476
-            $classname = get_class($this);
477
-            if (! isset($this->_wp_post->{$classname})) {
478
-                $this->_wp_post->{$classname} = $this;
479
-            }
480
-        }
481
-        return $this->_wp_post;
482
-    }
483
-
484
-
485
-    /**
486
-     * Don't serialize the WP Post. That's just duplicate data and we want to avoid recursion
487
-     *
488
-     * @return array
489
-     * @throws EE_Error
490
-     * @throws ReflectionException
491
-     */
492
-    public function __sleep()
493
-    {
494
-        $properties_to_serialize = parent::__sleep();
495
-        $properties_to_serialize = array_diff($properties_to_serialize, ['_wp_post']);
496
-        return $properties_to_serialize;
497
-    }
15
+	/**
16
+	 * This is a property for holding cached feature images on CPT objects.
17
+	 * Cache's are set on the first "feature_image()" method call.
18
+	 * Each key in the array corresponds to the requested size.
19
+	 *
20
+	 * @var array
21
+	 */
22
+	protected $_feature_image = [];
23
+
24
+	/**
25
+	 * @var WP_Post the WP_Post that corresponds with this CPT model object
26
+	 */
27
+	protected $_wp_post;
28
+
29
+
30
+	abstract public function wp_user();
31
+
32
+
33
+	/**
34
+	 * Adds to the specified event category. If it category doesn't exist, creates it.
35
+	 *
36
+	 * @param string $category_name
37
+	 * @param string $category_description    optional
38
+	 * @param int    $parent_term_taxonomy_id optional
39
+	 * @return EE_Term_Taxonomy
40
+	 * @throws EE_Error
41
+	 * @throws ReflectionException
42
+	 */
43
+	public function add_event_category($category_name, $category_description = null, $parent_term_taxonomy_id = null)
44
+	{
45
+		return $this->get_model()->add_event_category(
46
+			$this,
47
+			$category_name,
48
+			$category_description,
49
+			$parent_term_taxonomy_id
50
+		);
51
+	}
52
+
53
+
54
+	/**
55
+	 * Removes the event category by specified name from being related ot this event
56
+	 *
57
+	 * @param string $category_name
58
+	 * @return bool
59
+	 * @throws EE_Error
60
+	 * @throws ReflectionException
61
+	 */
62
+	public function remove_event_category($category_name)
63
+	{
64
+		return $this->get_model()->remove_event_category($this, $category_name);
65
+	}
66
+
67
+
68
+	/**
69
+	 * Removes the relation to the specified term taxonomy, and maintains the
70
+	 * data integrity of the term taxonomy provided
71
+	 *
72
+	 * @param EE_Term_Taxonomy $term_taxonomy
73
+	 * @return EE_Base_Class the relation was removed from
74
+	 * @throws EE_Error
75
+	 * @throws ReflectionException
76
+	 */
77
+	public function remove_relation_to_term_taxonomy($term_taxonomy)
78
+	{
79
+		if (! $term_taxonomy) {
80
+			EE_Error::add_error(
81
+				sprintf(
82
+					esc_html__(
83
+						"No Term_Taxonomy provided which to remove from model object of type %s and id %d",
84
+						"event_espresso"
85
+					),
86
+					get_class($this),
87
+					$this->ID()
88
+				),
89
+				__FILE__,
90
+				__FUNCTION__,
91
+				__LINE__
92
+			);
93
+			return null;
94
+		}
95
+		$term_taxonomy->set_count($term_taxonomy->count() - 1);
96
+		$term_taxonomy->save();
97
+		return $this->_remove_relation_to($term_taxonomy, 'Term_Taxonomy');
98
+	}
99
+
100
+
101
+	/**
102
+	 * The main purpose of this method is to return the post type for the model object
103
+	 *
104
+	 * @return string
105
+	 * @throws EE_Error
106
+	 * @throws ReflectionException
107
+	 */
108
+	public function post_type()
109
+	{
110
+		return $this->get_model()->post_type();
111
+	}
112
+
113
+
114
+	/**
115
+	 * The main purpose of this method is to return the parent for the model object
116
+	 *
117
+	 * @return int
118
+	 * @throws EE_Error
119
+	 */
120
+	public function parent()
121
+	{
122
+		return $this->get('parent');
123
+	}
124
+
125
+
126
+	/**
127
+	 * return the _status property
128
+	 *
129
+	 * @return string
130
+	 * @throws EE_Error
131
+	 */
132
+	public function status()
133
+	{
134
+		return $this->get('status');
135
+	}
136
+
137
+
138
+	/**
139
+	 * @param string $status
140
+	 * @throws EE_Error
141
+	 * @throws ReflectionException
142
+	 */
143
+	public function set_status($status)
144
+	{
145
+		$this->set('status', $status);
146
+	}
147
+
148
+
149
+	/**
150
+	 * See _get_feature_image. Returns the HTML to display a featured image
151
+	 *
152
+	 * @param string       $size
153
+	 * @param string|array $attr
154
+	 * @return string of html
155
+	 * @throws EE_Error
156
+	 * @throws ReflectionException
157
+	 */
158
+	public function feature_image($size = 'thumbnail', $attr = '')
159
+	{
160
+		return $this->_get_feature_image($size, $attr);
161
+	}
162
+
163
+
164
+	/**
165
+	 * This calls the equivalent model method for retrieving the feature image
166
+	 * which in turn is a wrapper for WordPress' get_the_post_thumbnail() function.
167
+	 *
168
+	 * @link   http://codex.wordpress.org/Function_Reference/get_the_post_thumbnail
169
+	 * @access protected
170
+	 * @param string|array $size (optional) Image size. Defaults to 'post-thumbnail' but can also be a 2-item array
171
+	 *                           representing width and height in pixels (i.e. array(32,32) ).
172
+	 * @param string|array $attr Optional. Query string or array of attributes.
173
+	 * @return string HTML image element
174
+	 * @throws EE_Error
175
+	 * @throws ReflectionException
176
+	 */
177
+	protected function _get_feature_image($size, $attr)
178
+	{
179
+		// first let's see if we already have the _feature_image property set
180
+		// AND if it has a cached element on it FOR the given size
181
+		$attr_key                           = is_array($attr)
182
+			? implode('_', $attr)
183
+			: $attr;
184
+		$cache_key                          = is_array($size)
185
+			? implode('_', $size) . $attr_key
186
+			: $size . $attr_key;
187
+		$this->_feature_image[ $cache_key ] = isset($this->_feature_image[ $cache_key ])
188
+			? $this->_feature_image[ $cache_key ]
189
+			: $this->get_model()->get_feature_image($this->ID(), $size, $attr);
190
+		return $this->_feature_image[ $cache_key ];
191
+	}
192
+
193
+
194
+	/**
195
+	 * This uses the wp "wp_get_attachment_image_src()" function to return the feature image for the current class
196
+	 * using the given size params.
197
+	 *
198
+	 * @param string|array $size  can either be a string: 'thumbnail', 'medium', 'large', 'full' OR 2-item array
199
+	 *                            representing width and height in pixels eg. array(32,32).
200
+	 * @return string|boolean          the url of the image or false if not found
201
+	 * @throws EE_Error
202
+	 */
203
+	public function feature_image_url($size = 'thumbnail')
204
+	{
205
+		$attachment = wp_get_attachment_image_src(get_post_thumbnail_id($this->ID()), $size);
206
+		return ! empty($attachment) ? $attachment[0] : false;
207
+	}
208
+
209
+
210
+	/**
211
+	 * This is a method for restoring this_obj using details from the given $revision_id
212
+	 *
213
+	 * @param int   $revision_id       ID of the revision we're getting data from
214
+	 * @param array $related_obj_names if included this will be used to restore for related obj
215
+	 *                                 if not included then we just do restore on the meta.
216
+	 *                                 We will accept an array of related_obj_names for restoration here.
217
+	 * @param array $where_query       You can optionally include an array of key=>value pairs
218
+	 *                                 that allow you to further constrict the relation to being added.
219
+	 *                                 However, keep in mind that the columns (keys) given
220
+	 *                                 must match a column on the JOIN table and currently
221
+	 *                                 only the HABTM models accept these additional conditions.
222
+	 *                                 Also remember that if an exact match isn't found for these extra cols/val pairs,
223
+	 *                                 then a NEW row is created in the join table.
224
+	 *                                 This array is INDEXED by RELATED OBJ NAME (so it corresponds with the obj_names
225
+	 *                                 sent);
226
+	 * @return void
227
+	 * @throws EE_Error
228
+	 * @throws ReflectionException
229
+	 */
230
+	public function restore_revision($revision_id, $related_obj_names = [], $where_query = [])
231
+	{
232
+		// get revision object
233
+		$revision_obj = $this->get_model()->get_one_by_ID($revision_id);
234
+		if ($revision_obj instanceof EE_CPT_Base) {
235
+			// no related_obj_name so we assume we're saving a revision on this object.
236
+			if (empty($related_obj_names)) {
237
+				$fields = $this->get_model()->get_meta_table_fields();
238
+				foreach ($fields as $field) {
239
+					$this->set($field, $revision_obj->get($field));
240
+				}
241
+				$this->save();
242
+			}
243
+			$related_obj_names = (array) $related_obj_names;
244
+			foreach ($related_obj_names as $related_name) {
245
+				// related_obj_name so we're saving a revision on an object related to this object
246
+				// do we have $where_query params for this related object?  If we do then we include that.
247
+				$cols_n_values         = isset($where_query[ $related_name ])
248
+					? $where_query[ $related_name ]
249
+					: [];
250
+				$where_params          = ! empty($cols_n_values) ? [$cols_n_values] : [];
251
+				$related_objs          = $this->get_many_related($related_name, $where_params);
252
+				$revision_related_objs = $revision_obj->get_many_related($related_name, $where_params);
253
+				// load helper
254
+				// remove related objs from this object that are not in revision
255
+				// array_diff *should* work cause I think objects are indexed by ID?
256
+				$related_to_remove = EEH_Array::object_array_diff($related_objs, $revision_related_objs);
257
+				foreach ($related_to_remove as $rr) {
258
+					$this->_remove_relation_to($rr, $related_name, $cols_n_values);
259
+				}
260
+				// add all related objs attached to revision to this object
261
+				foreach ($revision_related_objs as $r_obj) {
262
+					$this->_add_relation_to($r_obj, $related_name, $cols_n_values);
263
+				}
264
+			}
265
+		}
266
+	}
267
+
268
+
269
+	/**
270
+	 * Wrapper for get_post_meta, http://codex.wordpress.org/Function_Reference/get_post_meta
271
+	 * If only $id is set:
272
+	 *  it will return all meta values in an associative array.
273
+	 * If $single is set to false, or left blank:
274
+	 *  the function returns an array containing all values of the specified key.
275
+	 * If $single is set to true:
276
+	 *  the function returns the first value of the specified key (not in an array)
277
+	 *
278
+	 * @param string  $meta_key
279
+	 * @param boolean $single
280
+	 * @return mixed
281
+	 * @throws EE_Error
282
+	 */
283
+	public function get_post_meta($meta_key = null, $single = false)
284
+	{
285
+		return get_post_meta($this->ID(), $meta_key, $single);
286
+	}
287
+
288
+
289
+	/**
290
+	 * Wrapper for update_post_meta, http://codex.wordpress.org/Function_Reference/update_post_meta
291
+	 * Returns meta_id if the meta doesn't exist,
292
+	 * otherwise returns true on success and false on failure.
293
+	 * NOTE: If the meta_value passed to this function is the same
294
+	 * as the value that is already in the database, this function returns false.
295
+	 *
296
+	 * @param string $meta_key
297
+	 * @param mixed  $meta_value
298
+	 * @param mixed  $prev_value
299
+	 * @return mixed
300
+	 * @throws EE_Error
301
+	 * @throws ReflectionException
302
+	 */
303
+	public function update_post_meta($meta_key, $meta_value, $prev_value = null)
304
+	{
305
+		if (! $this->ID()) {
306
+			$this->save();
307
+		}
308
+		return update_post_meta($this->ID(), $meta_key, $meta_value, $prev_value);
309
+	}
310
+
311
+
312
+	/**
313
+	 * Wrapper for add_post_meta, http://codex.wordpress.org/Function_Reference/add_post_meta
314
+	 *
315
+	 * @param mixed $meta_key
316
+	 * @param mixed $meta_value
317
+	 * @param bool  $unique     If postmeta for this $meta_key already exists,
318
+	 *                          whether to add an additional item or not
319
+	 * @return boolean          Boolean true, except if the $unique argument was set to true
320
+	 *                          and a custom field with the given key already exists,
321
+	 *                          in which case false is returned.
322
+	 * @throws EE_Error
323
+	 * @throws ReflectionException
324
+	 */
325
+	public function add_post_meta($meta_key, $meta_value, $unique = false)
326
+	{
327
+		if ($this->ID()) {
328
+			$this->save();
329
+		}
330
+		return add_post_meta($this->ID(), $meta_key, $meta_value, $unique);
331
+	}
332
+
333
+
334
+	/**
335
+	 * Wrapper for delete_post_meta, http://codex.wordpress.org/Function_Reference/delete_post_meta
336
+	 *
337
+	 * @param mixed $meta_key
338
+	 * @param mixed $meta_value
339
+	 * @return boolean False for failure. True for success.
340
+	 * @throws EE_Error
341
+	 */
342
+	public function delete_post_meta($meta_key, $meta_value = '')
343
+	{
344
+		if (! $this->ID()) {
345
+			// there is obviously no postmeta for this if it's not saved
346
+			// so let's just report this as a success
347
+			return true;
348
+		}
349
+		return delete_post_meta($this->ID(), $meta_key, $meta_value);
350
+	}
351
+
352
+
353
+	/**
354
+	 * Gets the URL for viewing this event on the front-end
355
+	 *
356
+	 * @return string
357
+	 * @throws EE_Error
358
+	 */
359
+	public function get_permalink()
360
+	{
361
+		return get_permalink($this->ID());
362
+	}
363
+
364
+
365
+	/**
366
+	 * Gets all the term-taxonomies for this CPT
367
+	 *
368
+	 * @param array $query_params
369
+	 * @return array[]|EE_Base_Class[]|EE_Term_Taxonomy
370
+	 * @throws EE_Error
371
+	 * @throws ReflectionException
372
+	 */
373
+	public function term_taxonomies($query_params = [])
374
+	{
375
+		return $this->get_many_related('Term_Taxonomy', $query_params);
376
+	}
377
+
378
+
379
+	/**
380
+	 * @return mixed
381
+	 * @throws EE_Error
382
+	 * @throws ReflectionException
383
+	 */
384
+	public function get_custom_post_statuses()
385
+	{
386
+		return $this->get_model()->get_custom_post_statuses();
387
+	}
388
+
389
+
390
+	/**
391
+	 * @return mixed
392
+	 * @throws EE_Error
393
+	 * @throws ReflectionException
394
+	 */
395
+	public function get_all_post_statuses()
396
+	{
397
+		return $this->get_model()->get_status_array();
398
+	}
399
+
400
+
401
+	/**
402
+	 * When fetching a new value for a post field that uses the global $post for rendering,
403
+	 * set the global $post temporarily to be this model object; and afterwards restore it
404
+	 *
405
+	 * @param string $field_name
406
+	 * @param bool   $pretty
407
+	 * @param string $extra_cache_ref
408
+	 * @return mixed
409
+	 * @throws EE_Error
410
+	 * @throws ReflectionException
411
+	 */
412
+	protected function _get_fresh_property($field_name, $pretty = false, $extra_cache_ref = null)
413
+	{
414
+		global $post;
415
+
416
+		if (
417
+			$pretty
418
+			&& (
419
+				! (
420
+					$post instanceof WP_Post
421
+					&& $post->ID
422
+				)
423
+				|| (int) $post->ID !== $this->ID()
424
+			)
425
+			&& $this->get_model()->field_settings_for($field_name) instanceof EE_Post_Content_Field
426
+		) {
427
+			$old_post     = $post;
428
+			$post         = $this->wp_post();
429
+			$return_value = parent::_get_fresh_property($field_name, $pretty, $extra_cache_ref);
430
+			$post         = $old_post;
431
+		} else {
432
+			$return_value = parent::_get_fresh_property($field_name, $pretty, $extra_cache_ref);
433
+		}
434
+		return $return_value;
435
+	}
436
+
437
+
438
+	/**
439
+	 * Returns the WP post associated with this CPT model object.
440
+	 * If this CPT is saved, fetches it from the DB.
441
+	 * Otherwise, create an unsaved WP_POst object. Caches the post internally.
442
+	 *
443
+	 * @return WP_Post
444
+	 * @throws EE_Error
445
+	 * @throws ReflectionException
446
+	 */
447
+	public function wp_post()
448
+	{
449
+		global $wpdb;
450
+		if (! $this->_wp_post instanceof WP_Post) {
451
+			if ($this->ID()) {
452
+				$this->_wp_post = get_post($this->ID());
453
+			} else {
454
+				$simulated_db_result = new stdClass();
455
+				$field_settings      = $this->get_model()->field_settings(true);
456
+				foreach ($field_settings as $field_name => $field_obj) {
457
+					if (
458
+						$this->get_model()->get_table_obj_by_alias($field_obj->get_table_alias())
459
+							 ->get_table_name() === $wpdb->posts
460
+					) {
461
+						$column = $field_obj->get_table_column();
462
+
463
+						if ($field_obj instanceof EE_Datetime_Field) {
464
+							$value_on_model_obj = $this->get_DateTime_object($field_name);
465
+						} elseif ($field_obj->is_db_only_field()) {
466
+							$value_on_model_obj = $field_obj->get_default_value();
467
+						} else {
468
+							$value_on_model_obj = $this->get_raw($field_name);
469
+						}
470
+						$simulated_db_result->{$column} = $field_obj->prepare_for_use_in_db($value_on_model_obj);
471
+					}
472
+				}
473
+				$this->_wp_post = new WP_Post($simulated_db_result);
474
+			}
475
+			// and let's make retrieving the EE CPT object easy too
476
+			$classname = get_class($this);
477
+			if (! isset($this->_wp_post->{$classname})) {
478
+				$this->_wp_post->{$classname} = $this;
479
+			}
480
+		}
481
+		return $this->_wp_post;
482
+	}
483
+
484
+
485
+	/**
486
+	 * Don't serialize the WP Post. That's just duplicate data and we want to avoid recursion
487
+	 *
488
+	 * @return array
489
+	 * @throws EE_Error
490
+	 * @throws ReflectionException
491
+	 */
492
+	public function __sleep()
493
+	{
494
+		$properties_to_serialize = parent::__sleep();
495
+		$properties_to_serialize = array_diff($properties_to_serialize, ['_wp_post']);
496
+		return $properties_to_serialize;
497
+	}
498 498
 }
Please login to merge, or discard this patch.
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -76,7 +76,7 @@  discard block
 block discarded – undo
76 76
      */
77 77
     public function remove_relation_to_term_taxonomy($term_taxonomy)
78 78
     {
79
-        if (! $term_taxonomy) {
79
+        if ( ! $term_taxonomy) {
80 80
             EE_Error::add_error(
81 81
                 sprintf(
82 82
                     esc_html__(
@@ -182,12 +182,12 @@  discard block
 block discarded – undo
182 182
             ? implode('_', $attr)
183 183
             : $attr;
184 184
         $cache_key                          = is_array($size)
185
-            ? implode('_', $size) . $attr_key
186
-            : $size . $attr_key;
187
-        $this->_feature_image[ $cache_key ] = isset($this->_feature_image[ $cache_key ])
188
-            ? $this->_feature_image[ $cache_key ]
185
+            ? implode('_', $size).$attr_key
186
+            : $size.$attr_key;
187
+        $this->_feature_image[$cache_key] = isset($this->_feature_image[$cache_key])
188
+            ? $this->_feature_image[$cache_key]
189 189
             : $this->get_model()->get_feature_image($this->ID(), $size, $attr);
190
-        return $this->_feature_image[ $cache_key ];
190
+        return $this->_feature_image[$cache_key];
191 191
     }
192 192
 
193 193
 
@@ -244,8 +244,8 @@  discard block
 block discarded – undo
244 244
             foreach ($related_obj_names as $related_name) {
245 245
                 // related_obj_name so we're saving a revision on an object related to this object
246 246
                 // do we have $where_query params for this related object?  If we do then we include that.
247
-                $cols_n_values         = isset($where_query[ $related_name ])
248
-                    ? $where_query[ $related_name ]
247
+                $cols_n_values         = isset($where_query[$related_name])
248
+                    ? $where_query[$related_name]
249 249
                     : [];
250 250
                 $where_params          = ! empty($cols_n_values) ? [$cols_n_values] : [];
251 251
                 $related_objs          = $this->get_many_related($related_name, $where_params);
@@ -302,7 +302,7 @@  discard block
 block discarded – undo
302 302
      */
303 303
     public function update_post_meta($meta_key, $meta_value, $prev_value = null)
304 304
     {
305
-        if (! $this->ID()) {
305
+        if ( ! $this->ID()) {
306 306
             $this->save();
307 307
         }
308 308
         return update_post_meta($this->ID(), $meta_key, $meta_value, $prev_value);
@@ -341,7 +341,7 @@  discard block
 block discarded – undo
341 341
      */
342 342
     public function delete_post_meta($meta_key, $meta_value = '')
343 343
     {
344
-        if (! $this->ID()) {
344
+        if ( ! $this->ID()) {
345 345
             // there is obviously no postmeta for this if it's not saved
346 346
             // so let's just report this as a success
347 347
             return true;
@@ -447,7 +447,7 @@  discard block
 block discarded – undo
447 447
     public function wp_post()
448 448
     {
449 449
         global $wpdb;
450
-        if (! $this->_wp_post instanceof WP_Post) {
450
+        if ( ! $this->_wp_post instanceof WP_Post) {
451 451
             if ($this->ID()) {
452 452
                 $this->_wp_post = get_post($this->ID());
453 453
             } else {
@@ -474,7 +474,7 @@  discard block
 block discarded – undo
474 474
             }
475 475
             // and let's make retrieving the EE CPT object easy too
476 476
             $classname = get_class($this);
477
-            if (! isset($this->_wp_post->{$classname})) {
477
+            if ( ! isset($this->_wp_post->{$classname})) {
478 478
                 $this->_wp_post->{$classname} = $this;
479 479
             }
480 480
         }
Please login to merge, or discard this patch.
core/db_classes/EE_CSV.class.php 3 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -339,8 +339,8 @@
 block discarded – undo
339 339
      * and dies (in order to avoid other plugins from messing up the csv output)
340 340
      *
341 341
      * @param string $filename         the filename you want to give the file
342
-     * @param array  $model_data_array 3d array, as described in EE_CSV::write_model_data_to_csv()
343
-     * @return bool | void writes CSV file to output and dies
342
+     * @param boolean  $model_data_array 3d array, as described in EE_CSV::write_model_data_to_csv()
343
+     * @return boolean|null | void writes CSV file to output and dies
344 344
      * @throws EE_Error
345 345
      * @throws ReflectionException
346 346
      */
Please login to merge, or discard this patch.
Indentation   +621 added lines, -621 removed lines patch added patch discarded remove patch
@@ -13,625 +13,625 @@
 block discarded – undo
13 13
 class EE_CSV
14 14
 {
15 15
 
16
-    /**
17
-     * string used for 1st cell in exports,
18
-     * which indicates that the following 2 rows will be metadata keys and values
19
-     */
20
-    const metadata_header = 'Event Espresso Export Meta Data';
21
-
22
-
23
-    /**
24
-     * instance of the EE_CSV object
25
-     *
26
-     * @var EE_CSV
27
-     */
28
-    private static $_instance;
29
-
30
-    /**
31
-     * @var array
32
-     */
33
-    private $_primary_keys;
34
-
35
-
36
-    /**
37
-     * private constructor to prevent direct creation
38
-     *
39
-     * @return void
40
-     */
41
-    private function __construct()
42
-    {
43
-        global $wpdb;
44
-
45
-        $this->_primary_keys = [
46
-            $wpdb->prefix . 'esp_answer'                  => ['ANS_ID'],
47
-            $wpdb->prefix . 'esp_attendee'                => ['ATT_ID'],
48
-            $wpdb->prefix . 'esp_datetime'                => ['DTT_ID'],
49
-            $wpdb->prefix . 'esp_event_question_group'    => ['EQG_ID'],
50
-            $wpdb->prefix . 'esp_message_template'        => ['MTP_ID'],
51
-            $wpdb->prefix . 'esp_payment'                 => ['PAY_ID'],
52
-            $wpdb->prefix . 'esp_price'                   => ['PRC_ID'],
53
-            $wpdb->prefix . 'esp_price_type'              => ['PRT_ID'],
54
-            $wpdb->prefix . 'esp_question'                => ['QST_ID'],
55
-            $wpdb->prefix . 'esp_question_group'          => ['QSG_ID'],
56
-            $wpdb->prefix . 'esp_question_group_question' => ['QGQ_ID'],
57
-            $wpdb->prefix . 'esp_question_option'         => ['QSO_ID'],
58
-            $wpdb->prefix . 'esp_registration'            => ['REG_ID'],
59
-            $wpdb->prefix . 'esp_status'                  => ['STS_ID'],
60
-            $wpdb->prefix . 'esp_transaction'             => ['TXN_ID'],
61
-            $wpdb->prefix . 'esp_transaction'             => ['TXN_ID'],
62
-            $wpdb->prefix . 'events_detail'               => ['id'],
63
-            $wpdb->prefix . 'events_category_detail'      => ['id'],
64
-            $wpdb->prefix . 'events_category_rel'         => ['id'],
65
-            $wpdb->prefix . 'events_venue'                => ['id'],
66
-            $wpdb->prefix . 'events_venue_rel'            => ['emeta_id'],
67
-            $wpdb->prefix . 'events_locale'               => ['id'],
68
-            $wpdb->prefix . 'events_locale_rel'           => ['id'],
69
-            $wpdb->prefix . 'events_personnel'            => ['id'],
70
-            $wpdb->prefix . 'events_personnel_rel'        => ['id'],
71
-        ];
72
-    }
73
-
74
-
75
-    /**
76
-     *        @ singleton method used to instantiate class object
77
-     *        @ access public
78
-     *
79
-     * @return EE_CSV
80
-     */
81
-    public static function instance()
82
-    {
83
-        // check if class object is instantiated
84
-        if (! self::$_instance instanceof EE_CSV) {
85
-            self::$_instance = new self();
86
-        }
87
-        return self::$_instance;
88
-    }
89
-
90
-
91
-    /**
92
-     * @Import contents of csv file and store values in an array to be manipulated by other functions
93
-     * @access public
94
-     * @param string  $path_to_file         - the csv file to be imported including the path to it's location.
95
-     *                                      If $model_name is provided, assumes that each row in the CSV represents a
96
-     *                                      model object for that model If $model_name ISN'T provided, assumes that
97
-     *                                      before model object data, there is a row where the first entry is simply
98
-     *                                      'MODEL', and next entry is the model's name, (untranslated) like Event, and
99
-     *                                      then maybe a row of headers, and then the model data. Eg.
100
-     *                                      '<br>MODEL,Event,<br>EVT_ID,EVT_name,...<br>1,Monkey
101
-     *                                      Party,...<br>2,Llamarama,...<br>MODEL,Venue,<br>VNU_ID,VNU_name<br>1,The
102
-     *                                      Forest
103
-     * @param string  $model_name           model name if we know what model we're importing
104
-     * @param boolean $first_row_is_headers - whether the first row of data is headers or not - TRUE = headers, FALSE =
105
-     *                                      data
106
-     * @return mixed - array on success - multi dimensional with headers as keys (if headers exist) OR string on fail -
107
-     *                                      error message like the following array('Event'=>array(
108
-     *                                      array('EVT_ID'=>1,'EVT_name'=>'bob party',...),
109
-     *                                      array('EVT_ID'=>2,'EVT_name'=>'llamarama',...),
110
-     *                                      ...
111
-     *                                      )
112
-     *                                      'Venue'=>array(
113
-     *                                      array('VNU_ID'=>1,'VNU_name'=>'the shack',...),
114
-     *                                      array('VNU_ID'=>2,'VNU_name'=>'tree house',...),
115
-     *                                      ...
116
-     *                                      )
117
-     *                                      ...
118
-     *                                      )
119
-     * @throws EE_Error
120
-     */
121
-    public function import_csv_to_model_data_array($path_to_file, $model_name = false, $first_row_is_headers = true)
122
-    {
123
-        $multi_dimensional_array = $this->import_csv_to_multi_dimensional_array($path_to_file);
124
-        if (empty($multi_dimensional_array)) {
125
-            return false;
126
-        }
127
-        // gotta start somewhere
128
-        $row = 1;
129
-        // array to store csv data in
130
-        $ee_formatted_data = [];
131
-        // array to store headers (column names)
132
-        $headers = [];
133
-        foreach ($multi_dimensional_array as $data) {
134
-            // if first cell is MODEL, then second cell is the MODEL name
135
-            if ($data[0] == 'MODEL') {
136
-                $model_name = $data[1];
137
-                // don't bother looking for model data in this row.
138
-                // The rest of this row should be blank
139
-                // AND pretend this is the first row again
140
-                $row = 1;
141
-                // reset headers
142
-                $headers = [];
143
-                continue;
144
-            }
145
-            if (strpos($data[0], EE_CSV::metadata_header) !== false) {
146
-                $model_name = EE_CSV::metadata_header;
147
-                // store like model data, we just won't try importing it etc.
148
-                $row = 1;
149
-                continue;
150
-            }
151
-
152
-
153
-            // how many columns are there?
154
-            $columns = count($data);
155
-
156
-            $model_entry = [];
157
-            // loop through each column
158
-            for ($i = 0; $i < $columns; $i++) {
159
-                // replace csv_enclosures with backslashed quotes
160
-                $data[ $i ] = str_replace('"""', '\\"', $data[ $i ]);
161
-                // do we need to grab the column names?
162
-                if ($row === 1) {
163
-                    if ($first_row_is_headers) {
164
-                        // store the column names to use for keys
165
-                        $column_name = $data[ $i ];
166
-                        // check it's not blank... sometimes CSV editing programs
167
-                        // add a bunch of empty columns onto the end...
168
-                        if (! $column_name) {
169
-                            continue;
170
-                        }
171
-                        $matches = [];
172
-                        if ($model_name == EE_CSV::metadata_header) {
173
-                            $headers[ $i ] = $column_name;
174
-                        } else {
175
-                            // now get the db table name from it (the part between square brackets)
176
-                            $success = preg_match('~(.*)\[(.*)\]~', $column_name, $matches);
177
-                            if (! $success) {
178
-                                EE_Error::add_error(
179
-                                    sprintf(
180
-                                        esc_html__(
181
-                                            "The column titled %s is invalid for importing. It must be be in the format of 'Nice Name[model_field_name]' in row %s",
182
-                                            "event_espresso"
183
-                                        ),
184
-                                        $column_name,
185
-                                        implode(",", $data)
186
-                                    ),
187
-                                    __FILE__,
188
-                                    __FUNCTION__,
189
-                                    __LINE__
190
-                                );
191
-                                return false;
192
-                            }
193
-                            $headers[ $i ] = $matches[2];
194
-                        }
195
-                    } else {
196
-                        // no column names means our final array will just use counters for keys
197
-                        $model_entry[ $headers[ $i ] ] = $data[ $i ];
198
-                        $headers[ $i ]                 = $i;
199
-                    }
200
-                    // and we need to store csv data
201
-                } else {
202
-                    // this column isn' ta header, store it if there is a header for it
203
-                    if (isset($headers[ $i ])) {
204
-                        $model_entry[ $headers[ $i ] ] = $data[ $i ];
205
-                    }
206
-                }
207
-            }
208
-            // save the row's data IF it's a non-header-row
209
-            if (! $first_row_is_headers || $row > 1) {
210
-                $ee_formatted_data[ $model_name ][] = $model_entry;
211
-            }
212
-            // advance to next row
213
-            $row++;
214
-        }
215
-
216
-        // delete the uploaded file
217
-        unlink($path_to_file);
218
-
219
-        // it's good to give back
220
-        return $ee_formatted_data;
221
-    }
222
-
223
-
224
-    /**
225
-     * Generic CSV-functionality to turn an entire CSV file into a single array that's
226
-     * NOT in a specific format to EE. It's just a 2-level array, with top-level arrays
227
-     * representing each row in the CSV file, and the second-level arrays being each column in that row
228
-     *
229
-     * @param string $path_to_file
230
-     * @return array of arrays. Top-level array has rows, second-level array has each item
231
-     * @throws EE_Error
232
-     */
233
-    public function import_csv_to_multi_dimensional_array($path_to_file)
234
-    {
235
-        // needed to deal with Mac line endings
236
-        ini_set('auto_detect_line_endings', true);
237
-        // because fgetcsv does not correctly deal with backslashed quotes such as \"
238
-        // we'll read the file into a string
239
-        $file_contents = $this->read_unicode_file($path_to_file);
240
-        // replace backslashed quotes with CSV enclosures
241
-        $file_contents = str_replace('\\"', '"""', $file_contents);
242
-        // HEY YOU! PUT THAT FILE BACK!!!
243
-        file_put_contents($path_to_file, $file_contents);
244
-
245
-        if (($file_handle = fopen($path_to_file, "r")) !== false) {
246
-            $csv_array = [];
247
-            // in PHP 5.3 fgetcsv accepts a 5th parameter, but the pre 5.3 versions
248
-            // of fgetcsv choke if passed more than 4 - is that crazy or what?
249
-            if (version_compare(PHP_VERSION, '5.3.0') < 0) {
250
-                //  PHP 5.2- version
251
-                // loop through each row of the file
252
-                while (($data = fgetcsv($file_handle)) !== false) {
253
-                    $csv_array[] = $data;
254
-                }
255
-            } else {
256
-                // loop through each row of the file
257
-                while (($data = fgetcsv($file_handle)) !== false) {
258
-                    $csv_array[] = $data;
259
-                }
260
-            }
261
-            # Close the File.
262
-            fclose($file_handle);
263
-            return $csv_array;
264
-        }
265
-        EE_Error::add_error(
266
-            sprintf(
267
-                esc_html__(
268
-                    "An error occurred - the file: %s could not opened.",
269
-                    "event_espresso"
270
-                ),
271
-                $path_to_file
272
-            ),
273
-            __FILE__,
274
-            __FUNCTION__,
275
-            __LINE__
276
-        );
277
-        return [];
278
-    }
279
-
280
-
281
-    /**
282
-     * Opens a unicode or utf file
283
-     * (normal file_get_contents has difficulty reading a unicode file)
284
-     *
285
-     * @param string $file_path
286
-     * @return string
287
-     * @throws EE_Error
288
-     * @see http://stackoverflow.com/questions/15092764/how-to-read-unicode-text-file-in-php
289
-     */
290
-    private function read_unicode_file($file_path)
291
-    {
292
-        $fc = "";
293
-        $fh = fopen($file_path, "rb");
294
-        if (! $fh) {
295
-            throw new EE_Error(
296
-                sprintf(
297
-                    esc_html__("Cannot open file for read: %s<br>\n", 'event_espresso'),
298
-                    $file_path
299
-                )
300
-            );
301
-        }
302
-        $file_length = filesize($file_path);
303
-        $bc          = fread($fh, $file_length);
304
-        for ($i = 0; $i < $file_length; $i++) {
305
-            $c = substr($bc, $i, 1);
306
-            if ((ord($c) != 0) && (ord($c) != 13)) {
307
-                $fc = $fc . $c;
308
-            }
309
-        }
310
-        if ((ord(substr($fc, 0, 1)) == 255) && (ord(substr($fc, 1, 1)) == 254)) {
311
-            $fc = substr($fc, 2);
312
-        }
313
-        return ($fc);
314
-    }
315
-
316
-
317
-    /**
318
-     * @param       $csv_data_array
319
-     * @param false $model_name
320
-     * @return bool
321
-     * @throws EE_Error
322
-     */
323
-    public function save_csv_to_db($csv_data_array, $model_name = false)
324
-    {
325
-        EE_Error::doing_it_wrong(
326
-            'save_csv_to_db',
327
-            esc_html__(
328
-                'Function moved to EE_Import and renamed to save_csv_data_array_to_db',
329
-                'event_espresso'
330
-            ),
331
-            '4.6.7'
332
-        );
333
-        return EE_Import::instance()->save_csv_data_array_to_db($csv_data_array, $model_name);
334
-    }
335
-
336
-
337
-    /**
338
-     * Writes the CSV file to the output buffer, with rows corresponding to $model_data_array,
339
-     * and dies (in order to avoid other plugins from messing up the csv output)
340
-     *
341
-     * @param string $filename         the filename you want to give the file
342
-     * @param array  $model_data_array 3d array, as described in EE_CSV::write_model_data_to_csv()
343
-     * @return bool | void writes CSV file to output and dies
344
-     * @throws EE_Error
345
-     * @throws ReflectionException
346
-     */
347
-    public function export_multiple_model_data_to_csv($filename, $model_data_array)
348
-    {
349
-        $file_handle = $this->begin_sending_csv($filename);
350
-        $this->write_model_data_to_csv($file_handle, $model_data_array);
351
-        $this->end_sending_csv($file_handle);
352
-    }
353
-
354
-
355
-    /**
356
-     * Sends HTTP headers to indicate that the browser should download a file,
357
-     * and starts writing the file to PHP's output. Returns the file handle so other functions can
358
-     * also write to it
359
-     *
360
-     * @param string $filename the name of the file that the user will download
361
-     * @return resource, like the results of fopen(), which can be used for fwrite, fputcsv2, etc.
362
-     */
363
-    public function begin_sending_csv($filename)
364
-    {
365
-        // grab file extension
366
-        $ext = substr(strrchr($filename, '.'), 1);
367
-        if ($ext == '.csv' or $ext == '.xls') {
368
-            str_replace($ext, '', $filename);
369
-        }
370
-        $filename .= '.csv';
371
-
372
-        // if somebody's been naughty and already started outputting stuff, trash it
373
-        // and start writing our stuff.
374
-        if (ob_get_length()) {
375
-            @ob_flush();
376
-            @flush();
377
-            @ob_end_flush();
378
-        }
379
-        @ob_start();
380
-        header("Pragma: public");
381
-        header("Expires: 0");
382
-        header("Pragma: no-cache");
383
-        header("Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0");
384
-        // header("Content-Type: application/force-download");
385
-        // header("Content-Type: application/octet-stream");
386
-        // header("Content-Type: application/download");
387
-        header('Content-disposition: attachment; filename=' . $filename);
388
-        header("Content-Type: text/csv; charset=utf-8");
389
-        do_action('AHEE__EE_CSV__begin_sending_csv__headers');
390
-        echo apply_filters(
391
-            'FHEE__EE_CSV__begin_sending_csv__start_writing',
392
-            "\xEF\xBB\xBF"
393
-        ); // makes excel open it as UTF-8. UTF-8 BOM, see http://stackoverflow.com/a/4440143/2773835
394
-        return fopen('php://output', 'w');
395
-    }
396
-
397
-
398
-    /**
399
-     * Given an open file, writes all the model data to it in the format the importer expects.
400
-     * Usually preceded by begin_sending_csv($filename), and followed by end_sending_csv($file_handle).
401
-     *
402
-     * @param resource $file_handle
403
-     * @param array    $model_data_array is assumed to be a 3d array: 1st layer has keys of model names (eg 'Event'),
404
-     *                                   next layer is numerically indexed to represent each model object (eg, each
405
-     *                                   individual event), and the last layer has all the attributes of that model
406
-     *                                   object (eg, the event's id, name, etc)
407
-     * @return void
408
-     * @throws EE_Error
409
-     * @throws ReflectionException
410
-     */
411
-    public function write_model_data_to_csv($file_handle, $model_data_array)
412
-    {
413
-        $this->write_metadata_to_csv($file_handle);
414
-        foreach ($model_data_array as $model_name => $model_instance_arrays) {
415
-            // first: output a special row stating the model
416
-            $this->fputcsv2($file_handle, ['MODEL', $model_name]);
417
-            // if we have items to put in the CSV, do it normally
418
-
419
-            if (! empty($model_instance_arrays)) {
420
-                $this->write_data_array_to_csv($file_handle, $model_instance_arrays);
421
-            } else {
422
-                // echo "no data to write... so just write the headers";
423
-                // so there's actually NO model objects for that model.
424
-                // probably still want to show the columns
425
-                $model        = EE_Registry::instance()->load_model($model_name);
426
-                $column_names = [];
427
-                foreach ($model->field_settings() as $field) {
428
-                    $column_names[ $field->get_nicename() . "[" . $field->get_name() . "]" ] = null;
429
-                }
430
-                $this->write_data_array_to_csv($file_handle, [$column_names]);
431
-            }
432
-        }
433
-    }
434
-
435
-
436
-    /**
437
-     * Writes some meta data to the CSV as a bunch of columns. Initially we're only
438
-     * mentioning the version and timezone
439
-     *
440
-     * @param resource $file_handle
441
-     * @throws EE_Error
442
-     * @throws EE_Error
443
-     */
444
-    public function write_metadata_to_csv($file_handle)
445
-    {
446
-        $data_row = [EE_CSV::metadata_header];// do NOT translate because this exact string is used when importing
447
-        $this->fputcsv2($file_handle, $data_row);
448
-        $meta_data = [
449
-            0 => [
450
-                'version'        => espresso_version(),
451
-                'timezone'       => EEH_DTT_Helper::get_timezone(),
452
-                'time_of_export' => current_time('mysql'),
453
-                'site_url'       => site_url(),
454
-            ],
455
-        ];
456
-        $this->write_data_array_to_csv($file_handle, $meta_data);
457
-    }
458
-
459
-
460
-    /**
461
-     * @Drop   in replacement for PHP's fputcsv function - but this one works!!!
462
-     * @access private
463
-     * @param resource $fh         - file handle - what we are writing to
464
-     * @param array    $row        - individual row of csv data
465
-     * @param string   $delimiter  - csv delimiter
466
-     * @param string   $enclosure  - csv enclosure
467
-     * @param string   $mysql_null - allows php NULL to be overridden with MySQl's insertable NULL value
468
-     * @return void
469
-     */
470
-    private function fputcsv2($fh, array $row, $delimiter = ',', $enclosure = '"', $mysql_null = false)
471
-    {
472
-        // Allow user to filter the csv delimiter and enclosure for other countries csv standards
473
-        $delimiter = apply_filters('FHEE__EE_CSV__fputcsv2__delimiter', $delimiter);
474
-        $enclosure = apply_filters('FHEE__EE_CSV__fputcsv2__enclosure', $enclosure);
475
-
476
-        $delimiter_esc = preg_quote($delimiter, '/');
477
-        $enclosure_esc = preg_quote($enclosure, '/');
478
-
479
-        $output = [];
480
-        foreach ($row as $field_value) {
481
-            if (is_object($field_value) || is_array($field_value)) {
482
-                $field_value = serialize($field_value);
483
-            }
484
-            if ($field_value === null && $mysql_null) {
485
-                $output[] = 'NULL';
486
-                continue;
487
-            }
488
-
489
-            $output[] = preg_match("/(?:${delimiter_esc}|${enclosure_esc}|\s)/", $field_value)
490
-                ? ($enclosure . str_replace($enclosure, $enclosure . $enclosure, $field_value) . $enclosure)
491
-                : $field_value;
492
-        }
493
-
494
-        fwrite($fh, join($delimiter, $output) . PHP_EOL);
495
-    }
496
-
497
-
498
-    /**
499
-     * Writes $data to the csv file open in $file_handle. uses the array indices of $data for column headers
500
-     *
501
-     * @param resource $file_handle
502
-     * @param array    $data        2D array, first numerically-indexed,
503
-     *                              and next-level-down preferably indexed by string
504
-     * @return boolean              if we successfully wrote to the CSV or not.
505
-     *                              If there's no $data, we consider that a success
506
-     *                              (because we wrote everything there was...nothing)
507
-     * @throws EE_Error
508
-     * @throws EE_Error
509
-     */
510
-    public function write_data_array_to_csv($file_handle, $data)
511
-    {
512
-        // determine if $data is actually a 2d array
513
-        if ($data && is_array($data) && is_array(EEH_Array::get_one_item_from_array($data))) {
514
-            // make sure top level is numerically indexed,
515
-
516
-            if (EEH_Array::is_associative_array($data)) {
517
-                throw new EE_Error(
518
-                    sprintf(
519
-                        esc_html__(
520
-                            "top-level array must be numerically indexed. Does these look like numbers to you? %s",
521
-                            "event_espresso"
522
-                        ),
523
-                        implode(",", array_keys($data))
524
-                    )
525
-                );
526
-            }
527
-            $item_in_top_level_array = EEH_Array::get_one_item_from_array($data);
528
-            // now, is the last item in the top-level array of $data an associative or numeric array?
529
-            if (EEH_Array::is_associative_array($item_in_top_level_array)) {
530
-                // its associative, so we want to output its keys as column headers
531
-                $keys = array_keys($item_in_top_level_array);
532
-                $this->fputcsv2($file_handle, $keys);
533
-            }
534
-            // start writing data
535
-            foreach ($data as $data_row) {
536
-                $this->fputcsv2($file_handle, $data_row);
537
-            }
538
-            return true;
539
-        }
540
-        // no data TO write... so we can assume that's a success
541
-        return true;
542
-    }
543
-
544
-
545
-    /**
546
-     * Should be called after begin_sending_csv(), and one or more write_data_array_to_csv()s.
547
-     * Calls exit to prevent polluting the CSV file with other junk
548
-     *
549
-     * @param resource $fh file_handle where we're writing the CSV to
550
-     */
551
-    public function end_sending_csv($fh)
552
-    {
553
-        fclose($fh);
554
-        exit(0);
555
-    }
556
-
557
-
558
-    /**
559
-     * @Export contents of an array to csv file
560
-     * @access public
561
-     * @param array  $data     - the array of data to be converted to csv and exported
562
-     * @param string $filename - name for newly created csv file
563
-     * @return bool TRUE on success, FALSE on fail
564
-     */
565
-    public function export_array_to_csv($data = false, $filename = false)
566
-    {
567
-        // no data file?? get outta here
568
-        if (! $data or ! is_array($data) or empty($data)) {
569
-            return false;
570
-        }
571
-
572
-        // no filename?? get outta here
573
-        if (! $filename) {
574
-            return false;
575
-        }
576
-        $fh = $this->begin_sending_csv($filename);
577
-        $this->end_sending_csv($fh);
578
-        return true;
579
-    }
580
-
581
-
582
-    /**
583
-     * @Determine the maximum upload file size based on php.ini settings
584
-     * @access    public
585
-     * @param int $percent_of_max - desired percentage of the max upload_mb
586
-     * @return int KB
587
-     */
588
-    public function get_max_upload_size($percent_of_max = false)
589
-    {
590
-        $max_upload   = (int) (ini_get('upload_max_filesize'));
591
-        $max_post     = (int) (ini_get('post_max_size'));
592
-        $memory_limit = (int) (ini_get('memory_limit'));
593
-
594
-        // determine the smallest of the three values from above
595
-        $upload_mb = min($max_upload, $max_post, $memory_limit);
596
-
597
-        // convert MB to KB
598
-        $upload_mb = $upload_mb * 1024;
599
-
600
-        // don't want the full monty? then reduce the max upload size
601
-        if ($percent_of_max) {
602
-            // is percent_of_max like this -> 50 or like this -> 0.50 ?
603
-            if ($percent_of_max > 1) {
604
-                // changes 50 to 0.50
605
-                $percent_of_max = $percent_of_max / 100;
606
-            }
607
-            // make upload_mb a percentage of the max upload_mb
608
-            $upload_mb = $upload_mb * $percent_of_max;
609
-        }
610
-
611
-        return $upload_mb;
612
-    }
613
-
614
-
615
-    /**
616
-     * Gets the date format to use in teh csv. filterable
617
-     *
618
-     * @param string $current_format
619
-     * @return string
620
-     */
621
-    public function get_date_format_for_csv($current_format = null)
622
-    {
623
-        return apply_filters('FHEE__EE_CSV__get_date_format_for_csv__format', 'Y-m-d', $current_format);
624
-    }
625
-
626
-
627
-    /**
628
-     * Gets the time format we want to use in CSV reports. Filterable
629
-     *
630
-     * @param string $current_format
631
-     * @return string
632
-     */
633
-    public function get_time_format_for_csv($current_format = null)
634
-    {
635
-        return apply_filters('FHEE__EE_CSV__get_time_format_for_csv__format', 'H:i:s', $current_format);
636
-    }
16
+	/**
17
+	 * string used for 1st cell in exports,
18
+	 * which indicates that the following 2 rows will be metadata keys and values
19
+	 */
20
+	const metadata_header = 'Event Espresso Export Meta Data';
21
+
22
+
23
+	/**
24
+	 * instance of the EE_CSV object
25
+	 *
26
+	 * @var EE_CSV
27
+	 */
28
+	private static $_instance;
29
+
30
+	/**
31
+	 * @var array
32
+	 */
33
+	private $_primary_keys;
34
+
35
+
36
+	/**
37
+	 * private constructor to prevent direct creation
38
+	 *
39
+	 * @return void
40
+	 */
41
+	private function __construct()
42
+	{
43
+		global $wpdb;
44
+
45
+		$this->_primary_keys = [
46
+			$wpdb->prefix . 'esp_answer'                  => ['ANS_ID'],
47
+			$wpdb->prefix . 'esp_attendee'                => ['ATT_ID'],
48
+			$wpdb->prefix . 'esp_datetime'                => ['DTT_ID'],
49
+			$wpdb->prefix . 'esp_event_question_group'    => ['EQG_ID'],
50
+			$wpdb->prefix . 'esp_message_template'        => ['MTP_ID'],
51
+			$wpdb->prefix . 'esp_payment'                 => ['PAY_ID'],
52
+			$wpdb->prefix . 'esp_price'                   => ['PRC_ID'],
53
+			$wpdb->prefix . 'esp_price_type'              => ['PRT_ID'],
54
+			$wpdb->prefix . 'esp_question'                => ['QST_ID'],
55
+			$wpdb->prefix . 'esp_question_group'          => ['QSG_ID'],
56
+			$wpdb->prefix . 'esp_question_group_question' => ['QGQ_ID'],
57
+			$wpdb->prefix . 'esp_question_option'         => ['QSO_ID'],
58
+			$wpdb->prefix . 'esp_registration'            => ['REG_ID'],
59
+			$wpdb->prefix . 'esp_status'                  => ['STS_ID'],
60
+			$wpdb->prefix . 'esp_transaction'             => ['TXN_ID'],
61
+			$wpdb->prefix . 'esp_transaction'             => ['TXN_ID'],
62
+			$wpdb->prefix . 'events_detail'               => ['id'],
63
+			$wpdb->prefix . 'events_category_detail'      => ['id'],
64
+			$wpdb->prefix . 'events_category_rel'         => ['id'],
65
+			$wpdb->prefix . 'events_venue'                => ['id'],
66
+			$wpdb->prefix . 'events_venue_rel'            => ['emeta_id'],
67
+			$wpdb->prefix . 'events_locale'               => ['id'],
68
+			$wpdb->prefix . 'events_locale_rel'           => ['id'],
69
+			$wpdb->prefix . 'events_personnel'            => ['id'],
70
+			$wpdb->prefix . 'events_personnel_rel'        => ['id'],
71
+		];
72
+	}
73
+
74
+
75
+	/**
76
+	 *        @ singleton method used to instantiate class object
77
+	 *        @ access public
78
+	 *
79
+	 * @return EE_CSV
80
+	 */
81
+	public static function instance()
82
+	{
83
+		// check if class object is instantiated
84
+		if (! self::$_instance instanceof EE_CSV) {
85
+			self::$_instance = new self();
86
+		}
87
+		return self::$_instance;
88
+	}
89
+
90
+
91
+	/**
92
+	 * @Import contents of csv file and store values in an array to be manipulated by other functions
93
+	 * @access public
94
+	 * @param string  $path_to_file         - the csv file to be imported including the path to it's location.
95
+	 *                                      If $model_name is provided, assumes that each row in the CSV represents a
96
+	 *                                      model object for that model If $model_name ISN'T provided, assumes that
97
+	 *                                      before model object data, there is a row where the first entry is simply
98
+	 *                                      'MODEL', and next entry is the model's name, (untranslated) like Event, and
99
+	 *                                      then maybe a row of headers, and then the model data. Eg.
100
+	 *                                      '<br>MODEL,Event,<br>EVT_ID,EVT_name,...<br>1,Monkey
101
+	 *                                      Party,...<br>2,Llamarama,...<br>MODEL,Venue,<br>VNU_ID,VNU_name<br>1,The
102
+	 *                                      Forest
103
+	 * @param string  $model_name           model name if we know what model we're importing
104
+	 * @param boolean $first_row_is_headers - whether the first row of data is headers or not - TRUE = headers, FALSE =
105
+	 *                                      data
106
+	 * @return mixed - array on success - multi dimensional with headers as keys (if headers exist) OR string on fail -
107
+	 *                                      error message like the following array('Event'=>array(
108
+	 *                                      array('EVT_ID'=>1,'EVT_name'=>'bob party',...),
109
+	 *                                      array('EVT_ID'=>2,'EVT_name'=>'llamarama',...),
110
+	 *                                      ...
111
+	 *                                      )
112
+	 *                                      'Venue'=>array(
113
+	 *                                      array('VNU_ID'=>1,'VNU_name'=>'the shack',...),
114
+	 *                                      array('VNU_ID'=>2,'VNU_name'=>'tree house',...),
115
+	 *                                      ...
116
+	 *                                      )
117
+	 *                                      ...
118
+	 *                                      )
119
+	 * @throws EE_Error
120
+	 */
121
+	public function import_csv_to_model_data_array($path_to_file, $model_name = false, $first_row_is_headers = true)
122
+	{
123
+		$multi_dimensional_array = $this->import_csv_to_multi_dimensional_array($path_to_file);
124
+		if (empty($multi_dimensional_array)) {
125
+			return false;
126
+		}
127
+		// gotta start somewhere
128
+		$row = 1;
129
+		// array to store csv data in
130
+		$ee_formatted_data = [];
131
+		// array to store headers (column names)
132
+		$headers = [];
133
+		foreach ($multi_dimensional_array as $data) {
134
+			// if first cell is MODEL, then second cell is the MODEL name
135
+			if ($data[0] == 'MODEL') {
136
+				$model_name = $data[1];
137
+				// don't bother looking for model data in this row.
138
+				// The rest of this row should be blank
139
+				// AND pretend this is the first row again
140
+				$row = 1;
141
+				// reset headers
142
+				$headers = [];
143
+				continue;
144
+			}
145
+			if (strpos($data[0], EE_CSV::metadata_header) !== false) {
146
+				$model_name = EE_CSV::metadata_header;
147
+				// store like model data, we just won't try importing it etc.
148
+				$row = 1;
149
+				continue;
150
+			}
151
+
152
+
153
+			// how many columns are there?
154
+			$columns = count($data);
155
+
156
+			$model_entry = [];
157
+			// loop through each column
158
+			for ($i = 0; $i < $columns; $i++) {
159
+				// replace csv_enclosures with backslashed quotes
160
+				$data[ $i ] = str_replace('"""', '\\"', $data[ $i ]);
161
+				// do we need to grab the column names?
162
+				if ($row === 1) {
163
+					if ($first_row_is_headers) {
164
+						// store the column names to use for keys
165
+						$column_name = $data[ $i ];
166
+						// check it's not blank... sometimes CSV editing programs
167
+						// add a bunch of empty columns onto the end...
168
+						if (! $column_name) {
169
+							continue;
170
+						}
171
+						$matches = [];
172
+						if ($model_name == EE_CSV::metadata_header) {
173
+							$headers[ $i ] = $column_name;
174
+						} else {
175
+							// now get the db table name from it (the part between square brackets)
176
+							$success = preg_match('~(.*)\[(.*)\]~', $column_name, $matches);
177
+							if (! $success) {
178
+								EE_Error::add_error(
179
+									sprintf(
180
+										esc_html__(
181
+											"The column titled %s is invalid for importing. It must be be in the format of 'Nice Name[model_field_name]' in row %s",
182
+											"event_espresso"
183
+										),
184
+										$column_name,
185
+										implode(",", $data)
186
+									),
187
+									__FILE__,
188
+									__FUNCTION__,
189
+									__LINE__
190
+								);
191
+								return false;
192
+							}
193
+							$headers[ $i ] = $matches[2];
194
+						}
195
+					} else {
196
+						// no column names means our final array will just use counters for keys
197
+						$model_entry[ $headers[ $i ] ] = $data[ $i ];
198
+						$headers[ $i ]                 = $i;
199
+					}
200
+					// and we need to store csv data
201
+				} else {
202
+					// this column isn' ta header, store it if there is a header for it
203
+					if (isset($headers[ $i ])) {
204
+						$model_entry[ $headers[ $i ] ] = $data[ $i ];
205
+					}
206
+				}
207
+			}
208
+			// save the row's data IF it's a non-header-row
209
+			if (! $first_row_is_headers || $row > 1) {
210
+				$ee_formatted_data[ $model_name ][] = $model_entry;
211
+			}
212
+			// advance to next row
213
+			$row++;
214
+		}
215
+
216
+		// delete the uploaded file
217
+		unlink($path_to_file);
218
+
219
+		// it's good to give back
220
+		return $ee_formatted_data;
221
+	}
222
+
223
+
224
+	/**
225
+	 * Generic CSV-functionality to turn an entire CSV file into a single array that's
226
+	 * NOT in a specific format to EE. It's just a 2-level array, with top-level arrays
227
+	 * representing each row in the CSV file, and the second-level arrays being each column in that row
228
+	 *
229
+	 * @param string $path_to_file
230
+	 * @return array of arrays. Top-level array has rows, second-level array has each item
231
+	 * @throws EE_Error
232
+	 */
233
+	public function import_csv_to_multi_dimensional_array($path_to_file)
234
+	{
235
+		// needed to deal with Mac line endings
236
+		ini_set('auto_detect_line_endings', true);
237
+		// because fgetcsv does not correctly deal with backslashed quotes such as \"
238
+		// we'll read the file into a string
239
+		$file_contents = $this->read_unicode_file($path_to_file);
240
+		// replace backslashed quotes with CSV enclosures
241
+		$file_contents = str_replace('\\"', '"""', $file_contents);
242
+		// HEY YOU! PUT THAT FILE BACK!!!
243
+		file_put_contents($path_to_file, $file_contents);
244
+
245
+		if (($file_handle = fopen($path_to_file, "r")) !== false) {
246
+			$csv_array = [];
247
+			// in PHP 5.3 fgetcsv accepts a 5th parameter, but the pre 5.3 versions
248
+			// of fgetcsv choke if passed more than 4 - is that crazy or what?
249
+			if (version_compare(PHP_VERSION, '5.3.0') < 0) {
250
+				//  PHP 5.2- version
251
+				// loop through each row of the file
252
+				while (($data = fgetcsv($file_handle)) !== false) {
253
+					$csv_array[] = $data;
254
+				}
255
+			} else {
256
+				// loop through each row of the file
257
+				while (($data = fgetcsv($file_handle)) !== false) {
258
+					$csv_array[] = $data;
259
+				}
260
+			}
261
+			# Close the File.
262
+			fclose($file_handle);
263
+			return $csv_array;
264
+		}
265
+		EE_Error::add_error(
266
+			sprintf(
267
+				esc_html__(
268
+					"An error occurred - the file: %s could not opened.",
269
+					"event_espresso"
270
+				),
271
+				$path_to_file
272
+			),
273
+			__FILE__,
274
+			__FUNCTION__,
275
+			__LINE__
276
+		);
277
+		return [];
278
+	}
279
+
280
+
281
+	/**
282
+	 * Opens a unicode or utf file
283
+	 * (normal file_get_contents has difficulty reading a unicode file)
284
+	 *
285
+	 * @param string $file_path
286
+	 * @return string
287
+	 * @throws EE_Error
288
+	 * @see http://stackoverflow.com/questions/15092764/how-to-read-unicode-text-file-in-php
289
+	 */
290
+	private function read_unicode_file($file_path)
291
+	{
292
+		$fc = "";
293
+		$fh = fopen($file_path, "rb");
294
+		if (! $fh) {
295
+			throw new EE_Error(
296
+				sprintf(
297
+					esc_html__("Cannot open file for read: %s<br>\n", 'event_espresso'),
298
+					$file_path
299
+				)
300
+			);
301
+		}
302
+		$file_length = filesize($file_path);
303
+		$bc          = fread($fh, $file_length);
304
+		for ($i = 0; $i < $file_length; $i++) {
305
+			$c = substr($bc, $i, 1);
306
+			if ((ord($c) != 0) && (ord($c) != 13)) {
307
+				$fc = $fc . $c;
308
+			}
309
+		}
310
+		if ((ord(substr($fc, 0, 1)) == 255) && (ord(substr($fc, 1, 1)) == 254)) {
311
+			$fc = substr($fc, 2);
312
+		}
313
+		return ($fc);
314
+	}
315
+
316
+
317
+	/**
318
+	 * @param       $csv_data_array
319
+	 * @param false $model_name
320
+	 * @return bool
321
+	 * @throws EE_Error
322
+	 */
323
+	public function save_csv_to_db($csv_data_array, $model_name = false)
324
+	{
325
+		EE_Error::doing_it_wrong(
326
+			'save_csv_to_db',
327
+			esc_html__(
328
+				'Function moved to EE_Import and renamed to save_csv_data_array_to_db',
329
+				'event_espresso'
330
+			),
331
+			'4.6.7'
332
+		);
333
+		return EE_Import::instance()->save_csv_data_array_to_db($csv_data_array, $model_name);
334
+	}
335
+
336
+
337
+	/**
338
+	 * Writes the CSV file to the output buffer, with rows corresponding to $model_data_array,
339
+	 * and dies (in order to avoid other plugins from messing up the csv output)
340
+	 *
341
+	 * @param string $filename         the filename you want to give the file
342
+	 * @param array  $model_data_array 3d array, as described in EE_CSV::write_model_data_to_csv()
343
+	 * @return bool | void writes CSV file to output and dies
344
+	 * @throws EE_Error
345
+	 * @throws ReflectionException
346
+	 */
347
+	public function export_multiple_model_data_to_csv($filename, $model_data_array)
348
+	{
349
+		$file_handle = $this->begin_sending_csv($filename);
350
+		$this->write_model_data_to_csv($file_handle, $model_data_array);
351
+		$this->end_sending_csv($file_handle);
352
+	}
353
+
354
+
355
+	/**
356
+	 * Sends HTTP headers to indicate that the browser should download a file,
357
+	 * and starts writing the file to PHP's output. Returns the file handle so other functions can
358
+	 * also write to it
359
+	 *
360
+	 * @param string $filename the name of the file that the user will download
361
+	 * @return resource, like the results of fopen(), which can be used for fwrite, fputcsv2, etc.
362
+	 */
363
+	public function begin_sending_csv($filename)
364
+	{
365
+		// grab file extension
366
+		$ext = substr(strrchr($filename, '.'), 1);
367
+		if ($ext == '.csv' or $ext == '.xls') {
368
+			str_replace($ext, '', $filename);
369
+		}
370
+		$filename .= '.csv';
371
+
372
+		// if somebody's been naughty and already started outputting stuff, trash it
373
+		// and start writing our stuff.
374
+		if (ob_get_length()) {
375
+			@ob_flush();
376
+			@flush();
377
+			@ob_end_flush();
378
+		}
379
+		@ob_start();
380
+		header("Pragma: public");
381
+		header("Expires: 0");
382
+		header("Pragma: no-cache");
383
+		header("Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0");
384
+		// header("Content-Type: application/force-download");
385
+		// header("Content-Type: application/octet-stream");
386
+		// header("Content-Type: application/download");
387
+		header('Content-disposition: attachment; filename=' . $filename);
388
+		header("Content-Type: text/csv; charset=utf-8");
389
+		do_action('AHEE__EE_CSV__begin_sending_csv__headers');
390
+		echo apply_filters(
391
+			'FHEE__EE_CSV__begin_sending_csv__start_writing',
392
+			"\xEF\xBB\xBF"
393
+		); // makes excel open it as UTF-8. UTF-8 BOM, see http://stackoverflow.com/a/4440143/2773835
394
+		return fopen('php://output', 'w');
395
+	}
396
+
397
+
398
+	/**
399
+	 * Given an open file, writes all the model data to it in the format the importer expects.
400
+	 * Usually preceded by begin_sending_csv($filename), and followed by end_sending_csv($file_handle).
401
+	 *
402
+	 * @param resource $file_handle
403
+	 * @param array    $model_data_array is assumed to be a 3d array: 1st layer has keys of model names (eg 'Event'),
404
+	 *                                   next layer is numerically indexed to represent each model object (eg, each
405
+	 *                                   individual event), and the last layer has all the attributes of that model
406
+	 *                                   object (eg, the event's id, name, etc)
407
+	 * @return void
408
+	 * @throws EE_Error
409
+	 * @throws ReflectionException
410
+	 */
411
+	public function write_model_data_to_csv($file_handle, $model_data_array)
412
+	{
413
+		$this->write_metadata_to_csv($file_handle);
414
+		foreach ($model_data_array as $model_name => $model_instance_arrays) {
415
+			// first: output a special row stating the model
416
+			$this->fputcsv2($file_handle, ['MODEL', $model_name]);
417
+			// if we have items to put in the CSV, do it normally
418
+
419
+			if (! empty($model_instance_arrays)) {
420
+				$this->write_data_array_to_csv($file_handle, $model_instance_arrays);
421
+			} else {
422
+				// echo "no data to write... so just write the headers";
423
+				// so there's actually NO model objects for that model.
424
+				// probably still want to show the columns
425
+				$model        = EE_Registry::instance()->load_model($model_name);
426
+				$column_names = [];
427
+				foreach ($model->field_settings() as $field) {
428
+					$column_names[ $field->get_nicename() . "[" . $field->get_name() . "]" ] = null;
429
+				}
430
+				$this->write_data_array_to_csv($file_handle, [$column_names]);
431
+			}
432
+		}
433
+	}
434
+
435
+
436
+	/**
437
+	 * Writes some meta data to the CSV as a bunch of columns. Initially we're only
438
+	 * mentioning the version and timezone
439
+	 *
440
+	 * @param resource $file_handle
441
+	 * @throws EE_Error
442
+	 * @throws EE_Error
443
+	 */
444
+	public function write_metadata_to_csv($file_handle)
445
+	{
446
+		$data_row = [EE_CSV::metadata_header];// do NOT translate because this exact string is used when importing
447
+		$this->fputcsv2($file_handle, $data_row);
448
+		$meta_data = [
449
+			0 => [
450
+				'version'        => espresso_version(),
451
+				'timezone'       => EEH_DTT_Helper::get_timezone(),
452
+				'time_of_export' => current_time('mysql'),
453
+				'site_url'       => site_url(),
454
+			],
455
+		];
456
+		$this->write_data_array_to_csv($file_handle, $meta_data);
457
+	}
458
+
459
+
460
+	/**
461
+	 * @Drop   in replacement for PHP's fputcsv function - but this one works!!!
462
+	 * @access private
463
+	 * @param resource $fh         - file handle - what we are writing to
464
+	 * @param array    $row        - individual row of csv data
465
+	 * @param string   $delimiter  - csv delimiter
466
+	 * @param string   $enclosure  - csv enclosure
467
+	 * @param string   $mysql_null - allows php NULL to be overridden with MySQl's insertable NULL value
468
+	 * @return void
469
+	 */
470
+	private function fputcsv2($fh, array $row, $delimiter = ',', $enclosure = '"', $mysql_null = false)
471
+	{
472
+		// Allow user to filter the csv delimiter and enclosure for other countries csv standards
473
+		$delimiter = apply_filters('FHEE__EE_CSV__fputcsv2__delimiter', $delimiter);
474
+		$enclosure = apply_filters('FHEE__EE_CSV__fputcsv2__enclosure', $enclosure);
475
+
476
+		$delimiter_esc = preg_quote($delimiter, '/');
477
+		$enclosure_esc = preg_quote($enclosure, '/');
478
+
479
+		$output = [];
480
+		foreach ($row as $field_value) {
481
+			if (is_object($field_value) || is_array($field_value)) {
482
+				$field_value = serialize($field_value);
483
+			}
484
+			if ($field_value === null && $mysql_null) {
485
+				$output[] = 'NULL';
486
+				continue;
487
+			}
488
+
489
+			$output[] = preg_match("/(?:${delimiter_esc}|${enclosure_esc}|\s)/", $field_value)
490
+				? ($enclosure . str_replace($enclosure, $enclosure . $enclosure, $field_value) . $enclosure)
491
+				: $field_value;
492
+		}
493
+
494
+		fwrite($fh, join($delimiter, $output) . PHP_EOL);
495
+	}
496
+
497
+
498
+	/**
499
+	 * Writes $data to the csv file open in $file_handle. uses the array indices of $data for column headers
500
+	 *
501
+	 * @param resource $file_handle
502
+	 * @param array    $data        2D array, first numerically-indexed,
503
+	 *                              and next-level-down preferably indexed by string
504
+	 * @return boolean              if we successfully wrote to the CSV or not.
505
+	 *                              If there's no $data, we consider that a success
506
+	 *                              (because we wrote everything there was...nothing)
507
+	 * @throws EE_Error
508
+	 * @throws EE_Error
509
+	 */
510
+	public function write_data_array_to_csv($file_handle, $data)
511
+	{
512
+		// determine if $data is actually a 2d array
513
+		if ($data && is_array($data) && is_array(EEH_Array::get_one_item_from_array($data))) {
514
+			// make sure top level is numerically indexed,
515
+
516
+			if (EEH_Array::is_associative_array($data)) {
517
+				throw new EE_Error(
518
+					sprintf(
519
+						esc_html__(
520
+							"top-level array must be numerically indexed. Does these look like numbers to you? %s",
521
+							"event_espresso"
522
+						),
523
+						implode(",", array_keys($data))
524
+					)
525
+				);
526
+			}
527
+			$item_in_top_level_array = EEH_Array::get_one_item_from_array($data);
528
+			// now, is the last item in the top-level array of $data an associative or numeric array?
529
+			if (EEH_Array::is_associative_array($item_in_top_level_array)) {
530
+				// its associative, so we want to output its keys as column headers
531
+				$keys = array_keys($item_in_top_level_array);
532
+				$this->fputcsv2($file_handle, $keys);
533
+			}
534
+			// start writing data
535
+			foreach ($data as $data_row) {
536
+				$this->fputcsv2($file_handle, $data_row);
537
+			}
538
+			return true;
539
+		}
540
+		// no data TO write... so we can assume that's a success
541
+		return true;
542
+	}
543
+
544
+
545
+	/**
546
+	 * Should be called after begin_sending_csv(), and one or more write_data_array_to_csv()s.
547
+	 * Calls exit to prevent polluting the CSV file with other junk
548
+	 *
549
+	 * @param resource $fh file_handle where we're writing the CSV to
550
+	 */
551
+	public function end_sending_csv($fh)
552
+	{
553
+		fclose($fh);
554
+		exit(0);
555
+	}
556
+
557
+
558
+	/**
559
+	 * @Export contents of an array to csv file
560
+	 * @access public
561
+	 * @param array  $data     - the array of data to be converted to csv and exported
562
+	 * @param string $filename - name for newly created csv file
563
+	 * @return bool TRUE on success, FALSE on fail
564
+	 */
565
+	public function export_array_to_csv($data = false, $filename = false)
566
+	{
567
+		// no data file?? get outta here
568
+		if (! $data or ! is_array($data) or empty($data)) {
569
+			return false;
570
+		}
571
+
572
+		// no filename?? get outta here
573
+		if (! $filename) {
574
+			return false;
575
+		}
576
+		$fh = $this->begin_sending_csv($filename);
577
+		$this->end_sending_csv($fh);
578
+		return true;
579
+	}
580
+
581
+
582
+	/**
583
+	 * @Determine the maximum upload file size based on php.ini settings
584
+	 * @access    public
585
+	 * @param int $percent_of_max - desired percentage of the max upload_mb
586
+	 * @return int KB
587
+	 */
588
+	public function get_max_upload_size($percent_of_max = false)
589
+	{
590
+		$max_upload   = (int) (ini_get('upload_max_filesize'));
591
+		$max_post     = (int) (ini_get('post_max_size'));
592
+		$memory_limit = (int) (ini_get('memory_limit'));
593
+
594
+		// determine the smallest of the three values from above
595
+		$upload_mb = min($max_upload, $max_post, $memory_limit);
596
+
597
+		// convert MB to KB
598
+		$upload_mb = $upload_mb * 1024;
599
+
600
+		// don't want the full monty? then reduce the max upload size
601
+		if ($percent_of_max) {
602
+			// is percent_of_max like this -> 50 or like this -> 0.50 ?
603
+			if ($percent_of_max > 1) {
604
+				// changes 50 to 0.50
605
+				$percent_of_max = $percent_of_max / 100;
606
+			}
607
+			// make upload_mb a percentage of the max upload_mb
608
+			$upload_mb = $upload_mb * $percent_of_max;
609
+		}
610
+
611
+		return $upload_mb;
612
+	}
613
+
614
+
615
+	/**
616
+	 * Gets the date format to use in teh csv. filterable
617
+	 *
618
+	 * @param string $current_format
619
+	 * @return string
620
+	 */
621
+	public function get_date_format_for_csv($current_format = null)
622
+	{
623
+		return apply_filters('FHEE__EE_CSV__get_date_format_for_csv__format', 'Y-m-d', $current_format);
624
+	}
625
+
626
+
627
+	/**
628
+	 * Gets the time format we want to use in CSV reports. Filterable
629
+	 *
630
+	 * @param string $current_format
631
+	 * @return string
632
+	 */
633
+	public function get_time_format_for_csv($current_format = null)
634
+	{
635
+		return apply_filters('FHEE__EE_CSV__get_time_format_for_csv__format', 'H:i:s', $current_format);
636
+	}
637 637
 }
Please login to merge, or discard this patch.
Spacing   +48 added lines, -48 removed lines patch added patch discarded remove patch
@@ -43,31 +43,31 @@  discard block
 block discarded – undo
43 43
         global $wpdb;
44 44
 
45 45
         $this->_primary_keys = [
46
-            $wpdb->prefix . 'esp_answer'                  => ['ANS_ID'],
47
-            $wpdb->prefix . 'esp_attendee'                => ['ATT_ID'],
48
-            $wpdb->prefix . 'esp_datetime'                => ['DTT_ID'],
49
-            $wpdb->prefix . 'esp_event_question_group'    => ['EQG_ID'],
50
-            $wpdb->prefix . 'esp_message_template'        => ['MTP_ID'],
51
-            $wpdb->prefix . 'esp_payment'                 => ['PAY_ID'],
52
-            $wpdb->prefix . 'esp_price'                   => ['PRC_ID'],
53
-            $wpdb->prefix . 'esp_price_type'              => ['PRT_ID'],
54
-            $wpdb->prefix . 'esp_question'                => ['QST_ID'],
55
-            $wpdb->prefix . 'esp_question_group'          => ['QSG_ID'],
56
-            $wpdb->prefix . 'esp_question_group_question' => ['QGQ_ID'],
57
-            $wpdb->prefix . 'esp_question_option'         => ['QSO_ID'],
58
-            $wpdb->prefix . 'esp_registration'            => ['REG_ID'],
59
-            $wpdb->prefix . 'esp_status'                  => ['STS_ID'],
60
-            $wpdb->prefix . 'esp_transaction'             => ['TXN_ID'],
61
-            $wpdb->prefix . 'esp_transaction'             => ['TXN_ID'],
62
-            $wpdb->prefix . 'events_detail'               => ['id'],
63
-            $wpdb->prefix . 'events_category_detail'      => ['id'],
64
-            $wpdb->prefix . 'events_category_rel'         => ['id'],
65
-            $wpdb->prefix . 'events_venue'                => ['id'],
66
-            $wpdb->prefix . 'events_venue_rel'            => ['emeta_id'],
67
-            $wpdb->prefix . 'events_locale'               => ['id'],
68
-            $wpdb->prefix . 'events_locale_rel'           => ['id'],
69
-            $wpdb->prefix . 'events_personnel'            => ['id'],
70
-            $wpdb->prefix . 'events_personnel_rel'        => ['id'],
46
+            $wpdb->prefix.'esp_answer'                  => ['ANS_ID'],
47
+            $wpdb->prefix.'esp_attendee'                => ['ATT_ID'],
48
+            $wpdb->prefix.'esp_datetime'                => ['DTT_ID'],
49
+            $wpdb->prefix.'esp_event_question_group'    => ['EQG_ID'],
50
+            $wpdb->prefix.'esp_message_template'        => ['MTP_ID'],
51
+            $wpdb->prefix.'esp_payment'                 => ['PAY_ID'],
52
+            $wpdb->prefix.'esp_price'                   => ['PRC_ID'],
53
+            $wpdb->prefix.'esp_price_type'              => ['PRT_ID'],
54
+            $wpdb->prefix.'esp_question'                => ['QST_ID'],
55
+            $wpdb->prefix.'esp_question_group'          => ['QSG_ID'],
56
+            $wpdb->prefix.'esp_question_group_question' => ['QGQ_ID'],
57
+            $wpdb->prefix.'esp_question_option'         => ['QSO_ID'],
58
+            $wpdb->prefix.'esp_registration'            => ['REG_ID'],
59
+            $wpdb->prefix.'esp_status'                  => ['STS_ID'],
60
+            $wpdb->prefix.'esp_transaction'             => ['TXN_ID'],
61
+            $wpdb->prefix.'esp_transaction'             => ['TXN_ID'],
62
+            $wpdb->prefix.'events_detail'               => ['id'],
63
+            $wpdb->prefix.'events_category_detail'      => ['id'],
64
+            $wpdb->prefix.'events_category_rel'         => ['id'],
65
+            $wpdb->prefix.'events_venue'                => ['id'],
66
+            $wpdb->prefix.'events_venue_rel'            => ['emeta_id'],
67
+            $wpdb->prefix.'events_locale'               => ['id'],
68
+            $wpdb->prefix.'events_locale_rel'           => ['id'],
69
+            $wpdb->prefix.'events_personnel'            => ['id'],
70
+            $wpdb->prefix.'events_personnel_rel'        => ['id'],
71 71
         ];
72 72
     }
73 73
 
@@ -81,7 +81,7 @@  discard block
 block discarded – undo
81 81
     public static function instance()
82 82
     {
83 83
         // check if class object is instantiated
84
-        if (! self::$_instance instanceof EE_CSV) {
84
+        if ( ! self::$_instance instanceof EE_CSV) {
85 85
             self::$_instance = new self();
86 86
         }
87 87
         return self::$_instance;
@@ -157,24 +157,24 @@  discard block
 block discarded – undo
157 157
             // loop through each column
158 158
             for ($i = 0; $i < $columns; $i++) {
159 159
                 // replace csv_enclosures with backslashed quotes
160
-                $data[ $i ] = str_replace('"""', '\\"', $data[ $i ]);
160
+                $data[$i] = str_replace('"""', '\\"', $data[$i]);
161 161
                 // do we need to grab the column names?
162 162
                 if ($row === 1) {
163 163
                     if ($first_row_is_headers) {
164 164
                         // store the column names to use for keys
165
-                        $column_name = $data[ $i ];
165
+                        $column_name = $data[$i];
166 166
                         // check it's not blank... sometimes CSV editing programs
167 167
                         // add a bunch of empty columns onto the end...
168
-                        if (! $column_name) {
168
+                        if ( ! $column_name) {
169 169
                             continue;
170 170
                         }
171 171
                         $matches = [];
172 172
                         if ($model_name == EE_CSV::metadata_header) {
173
-                            $headers[ $i ] = $column_name;
173
+                            $headers[$i] = $column_name;
174 174
                         } else {
175 175
                             // now get the db table name from it (the part between square brackets)
176 176
                             $success = preg_match('~(.*)\[(.*)\]~', $column_name, $matches);
177
-                            if (! $success) {
177
+                            if ( ! $success) {
178 178
                                 EE_Error::add_error(
179 179
                                     sprintf(
180 180
                                         esc_html__(
@@ -190,24 +190,24 @@  discard block
 block discarded – undo
190 190
                                 );
191 191
                                 return false;
192 192
                             }
193
-                            $headers[ $i ] = $matches[2];
193
+                            $headers[$i] = $matches[2];
194 194
                         }
195 195
                     } else {
196 196
                         // no column names means our final array will just use counters for keys
197
-                        $model_entry[ $headers[ $i ] ] = $data[ $i ];
198
-                        $headers[ $i ]                 = $i;
197
+                        $model_entry[$headers[$i]] = $data[$i];
198
+                        $headers[$i]                 = $i;
199 199
                     }
200 200
                     // and we need to store csv data
201 201
                 } else {
202 202
                     // this column isn' ta header, store it if there is a header for it
203
-                    if (isset($headers[ $i ])) {
204
-                        $model_entry[ $headers[ $i ] ] = $data[ $i ];
203
+                    if (isset($headers[$i])) {
204
+                        $model_entry[$headers[$i]] = $data[$i];
205 205
                     }
206 206
                 }
207 207
             }
208 208
             // save the row's data IF it's a non-header-row
209
-            if (! $first_row_is_headers || $row > 1) {
210
-                $ee_formatted_data[ $model_name ][] = $model_entry;
209
+            if ( ! $first_row_is_headers || $row > 1) {
210
+                $ee_formatted_data[$model_name][] = $model_entry;
211 211
             }
212 212
             // advance to next row
213 213
             $row++;
@@ -291,7 +291,7 @@  discard block
 block discarded – undo
291 291
     {
292 292
         $fc = "";
293 293
         $fh = fopen($file_path, "rb");
294
-        if (! $fh) {
294
+        if ( ! $fh) {
295 295
             throw new EE_Error(
296 296
                 sprintf(
297 297
                     esc_html__("Cannot open file for read: %s<br>\n", 'event_espresso'),
@@ -304,7 +304,7 @@  discard block
 block discarded – undo
304 304
         for ($i = 0; $i < $file_length; $i++) {
305 305
             $c = substr($bc, $i, 1);
306 306
             if ((ord($c) != 0) && (ord($c) != 13)) {
307
-                $fc = $fc . $c;
307
+                $fc = $fc.$c;
308 308
             }
309 309
         }
310 310
         if ((ord(substr($fc, 0, 1)) == 255) && (ord(substr($fc, 1, 1)) == 254)) {
@@ -384,7 +384,7 @@  discard block
 block discarded – undo
384 384
         // header("Content-Type: application/force-download");
385 385
         // header("Content-Type: application/octet-stream");
386 386
         // header("Content-Type: application/download");
387
-        header('Content-disposition: attachment; filename=' . $filename);
387
+        header('Content-disposition: attachment; filename='.$filename);
388 388
         header("Content-Type: text/csv; charset=utf-8");
389 389
         do_action('AHEE__EE_CSV__begin_sending_csv__headers');
390 390
         echo apply_filters(
@@ -416,7 +416,7 @@  discard block
 block discarded – undo
416 416
             $this->fputcsv2($file_handle, ['MODEL', $model_name]);
417 417
             // if we have items to put in the CSV, do it normally
418 418
 
419
-            if (! empty($model_instance_arrays)) {
419
+            if ( ! empty($model_instance_arrays)) {
420 420
                 $this->write_data_array_to_csv($file_handle, $model_instance_arrays);
421 421
             } else {
422 422
                 // echo "no data to write... so just write the headers";
@@ -425,7 +425,7 @@  discard block
 block discarded – undo
425 425
                 $model        = EE_Registry::instance()->load_model($model_name);
426 426
                 $column_names = [];
427 427
                 foreach ($model->field_settings() as $field) {
428
-                    $column_names[ $field->get_nicename() . "[" . $field->get_name() . "]" ] = null;
428
+                    $column_names[$field->get_nicename()."[".$field->get_name()."]"] = null;
429 429
                 }
430 430
                 $this->write_data_array_to_csv($file_handle, [$column_names]);
431 431
             }
@@ -443,7 +443,7 @@  discard block
 block discarded – undo
443 443
      */
444 444
     public function write_metadata_to_csv($file_handle)
445 445
     {
446
-        $data_row = [EE_CSV::metadata_header];// do NOT translate because this exact string is used when importing
446
+        $data_row = [EE_CSV::metadata_header]; // do NOT translate because this exact string is used when importing
447 447
         $this->fputcsv2($file_handle, $data_row);
448 448
         $meta_data = [
449 449
             0 => [
@@ -487,11 +487,11 @@  discard block
 block discarded – undo
487 487
             }
488 488
 
489 489
             $output[] = preg_match("/(?:${delimiter_esc}|${enclosure_esc}|\s)/", $field_value)
490
-                ? ($enclosure . str_replace($enclosure, $enclosure . $enclosure, $field_value) . $enclosure)
490
+                ? ($enclosure.str_replace($enclosure, $enclosure.$enclosure, $field_value).$enclosure)
491 491
                 : $field_value;
492 492
         }
493 493
 
494
-        fwrite($fh, join($delimiter, $output) . PHP_EOL);
494
+        fwrite($fh, join($delimiter, $output).PHP_EOL);
495 495
     }
496 496
 
497 497
 
@@ -565,12 +565,12 @@  discard block
 block discarded – undo
565 565
     public function export_array_to_csv($data = false, $filename = false)
566 566
     {
567 567
         // no data file?? get outta here
568
-        if (! $data or ! is_array($data) or empty($data)) {
568
+        if ( ! $data or ! is_array($data) or empty($data)) {
569 569
             return false;
570 570
         }
571 571
 
572 572
         // no filename?? get outta here
573
-        if (! $filename) {
573
+        if ( ! $filename) {
574 574
             return false;
575 575
         }
576 576
         $fh = $this->begin_sending_csv($filename);
Please login to merge, or discard this patch.
core/db_classes/EE_Currency.class.php 1 patch
Indentation   +234 added lines, -234 removed lines patch added patch discarded remove patch
@@ -10,238 +10,238 @@
 block discarded – undo
10 10
 class EE_Currency extends EE_Base_Class
11 11
 {
12 12
 
13
-    /** Currency COde
14
-     *
15
-     * @var CUR_code
16
-     */
17
-    protected $_CUR_code = null;
18
-
19
-    /** Currency Name Singular
20
-     *
21
-     * @var CUR_single
22
-     */
23
-    protected $_CUR_single = null;
24
-
25
-    /** Currency Name Plural
26
-     *
27
-     * @var CUR_plural
28
-     */
29
-    protected $_CUR_plural = null;
30
-
31
-    /** Currency Sign
32
-     *
33
-     * @var CUR_sign
34
-     */
35
-    protected $_CUR_sign = null;
36
-
37
-    /** Currency Decimal Places
38
-     *
39
-     * @var CUR_dec_plc
40
-     */
41
-    protected $_CUR_dec_plc = null;
42
-
43
-    /** Active?
44
-     *
45
-     * @var CUR_active
46
-     */
47
-    protected $_CUR_active = null;
48
-
49
-    protected $_Payment_Method;
50
-
51
-
52
-    /**
53
-     * @param array  $props_n_values          incoming values
54
-     * @param string $timezone                incoming timezone
55
-     *                                        (if not set the timezone set for the website will be used.)
56
-     * @param array  $date_formats            incoming date_formats in an array where the first value is the
57
-     *                                        date_format and the second value is the time format
58
-     * @return EE_Currency
59
-     * @throws EE_Error
60
-     * @throws ReflectionException
61
-     */
62
-    public static function new_instance($props_n_values = [], $timezone = null, $date_formats = [])
63
-    {
64
-        $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats);
65
-        return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats);
66
-    }
67
-
68
-
69
-    /**
70
-     * @param array  $props_n_values  incoming values from the database
71
-     * @param string $timezone        incoming timezone as set by the model.
72
-     *                                If not set the timezone for the website will be used.
73
-     * @return EE_Currency
74
-     * @throws EE_Error
75
-     * @throws ReflectionException
76
-     */
77
-    public static function new_instance_from_db($props_n_values = [], $timezone = null)
78
-    {
79
-        return new self($props_n_values, true, $timezone);
80
-    }
81
-
82
-
83
-    /**
84
-     * Sets code
85
-     *
86
-     * @param string $code
87
-     * @throws EE_Error
88
-     * @throws ReflectionException
89
-     */
90
-    public function set_code($code)
91
-    {
92
-        $this->set('CUR_code', $code);
93
-    }
94
-
95
-
96
-    /**
97
-     * Gets active
98
-     *
99
-     * @return boolean
100
-     * @throws EE_Error
101
-     */
102
-    public function active()
103
-    {
104
-        return $this->get('CUR_active');
105
-    }
106
-
107
-
108
-    /**
109
-     * Sets active
110
-     *
111
-     * @param boolean $active
112
-     * @throws EE_Error
113
-     * @throws ReflectionException
114
-     */
115
-    public function set_active($active)
116
-    {
117
-        $this->set('CUR_active', $active);
118
-    }
119
-
120
-
121
-    /**
122
-     * Gets dec_plc
123
-     *
124
-     * @return int
125
-     * @throws EE_Error
126
-     */
127
-    public function dec_plc()
128
-    {
129
-        return $this->get('CUR_dec_plc');
130
-    }
131
-
132
-
133
-    /**
134
-     * Sets dec_plc
135
-     *
136
-     * @param int $dec_plc
137
-     * @throws EE_Error
138
-     * @throws ReflectionException
139
-     */
140
-    public function set_dec_plc($dec_plc)
141
-    {
142
-        $this->set('CUR_dec_plc', $dec_plc);
143
-    }
144
-
145
-
146
-    /**
147
-     * Sets plural
148
-     *
149
-     * @param string $plural
150
-     * @throws EE_Error
151
-     * @throws ReflectionException
152
-     */
153
-    public function set_plural_name($plural)
154
-    {
155
-        $this->set('CUR_plural', $plural);
156
-    }
157
-
158
-
159
-    /**
160
-     * Gets sign
161
-     *
162
-     * @return string
163
-     * @throws EE_Error
164
-     */
165
-    public function sign()
166
-    {
167
-        return $this->get('CUR_sign');
168
-    }
169
-
170
-
171
-    /**
172
-     * Sets sign
173
-     *
174
-     * @param string $sign
175
-     * @throws EE_Error
176
-     * @throws ReflectionException
177
-     */
178
-    public function set_sign($sign)
179
-    {
180
-        $this->set('CUR_sign', $sign);
181
-    }
182
-
183
-
184
-    /**
185
-     * Gets single
186
-     *
187
-     * @return string
188
-     * @throws EE_Error
189
-     */
190
-    public function singular_name()
191
-    {
192
-        return $this->get('CUR_single');
193
-    }
194
-
195
-
196
-    /**
197
-     * Sets single
198
-     *
199
-     * @param string $single
200
-     * @throws EE_Error
201
-     * @throws ReflectionException
202
-     */
203
-    public function set_singular_name($single)
204
-    {
205
-        $this->set('CUR_single', $single);
206
-    }
207
-
208
-
209
-    /**
210
-     * Gets a prettier name
211
-     *
212
-     * @return string
213
-     * @throws EE_Error
214
-     */
215
-    public function name()
216
-    {
217
-        return sprintf(
218
-            esc_html__("%s (%s)", "event_espresso"),
219
-            $this->code(),
220
-            $this->plural_name()
221
-        );
222
-    }
223
-
224
-
225
-    /**
226
-     * Gets code
227
-     *
228
-     * @return string
229
-     * @throws EE_Error
230
-     */
231
-    public function code()
232
-    {
233
-        return $this->get('CUR_code');
234
-    }
235
-
236
-
237
-    /**
238
-     * Gets plural
239
-     *
240
-     * @return string
241
-     * @throws EE_Error
242
-     */
243
-    public function plural_name()
244
-    {
245
-        return $this->get('CUR_plural');
246
-    }
13
+	/** Currency COde
14
+	 *
15
+	 * @var CUR_code
16
+	 */
17
+	protected $_CUR_code = null;
18
+
19
+	/** Currency Name Singular
20
+	 *
21
+	 * @var CUR_single
22
+	 */
23
+	protected $_CUR_single = null;
24
+
25
+	/** Currency Name Plural
26
+	 *
27
+	 * @var CUR_plural
28
+	 */
29
+	protected $_CUR_plural = null;
30
+
31
+	/** Currency Sign
32
+	 *
33
+	 * @var CUR_sign
34
+	 */
35
+	protected $_CUR_sign = null;
36
+
37
+	/** Currency Decimal Places
38
+	 *
39
+	 * @var CUR_dec_plc
40
+	 */
41
+	protected $_CUR_dec_plc = null;
42
+
43
+	/** Active?
44
+	 *
45
+	 * @var CUR_active
46
+	 */
47
+	protected $_CUR_active = null;
48
+
49
+	protected $_Payment_Method;
50
+
51
+
52
+	/**
53
+	 * @param array  $props_n_values          incoming values
54
+	 * @param string $timezone                incoming timezone
55
+	 *                                        (if not set the timezone set for the website will be used.)
56
+	 * @param array  $date_formats            incoming date_formats in an array where the first value is the
57
+	 *                                        date_format and the second value is the time format
58
+	 * @return EE_Currency
59
+	 * @throws EE_Error
60
+	 * @throws ReflectionException
61
+	 */
62
+	public static function new_instance($props_n_values = [], $timezone = null, $date_formats = [])
63
+	{
64
+		$has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats);
65
+		return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats);
66
+	}
67
+
68
+
69
+	/**
70
+	 * @param array  $props_n_values  incoming values from the database
71
+	 * @param string $timezone        incoming timezone as set by the model.
72
+	 *                                If not set the timezone for the website will be used.
73
+	 * @return EE_Currency
74
+	 * @throws EE_Error
75
+	 * @throws ReflectionException
76
+	 */
77
+	public static function new_instance_from_db($props_n_values = [], $timezone = null)
78
+	{
79
+		return new self($props_n_values, true, $timezone);
80
+	}
81
+
82
+
83
+	/**
84
+	 * Sets code
85
+	 *
86
+	 * @param string $code
87
+	 * @throws EE_Error
88
+	 * @throws ReflectionException
89
+	 */
90
+	public function set_code($code)
91
+	{
92
+		$this->set('CUR_code', $code);
93
+	}
94
+
95
+
96
+	/**
97
+	 * Gets active
98
+	 *
99
+	 * @return boolean
100
+	 * @throws EE_Error
101
+	 */
102
+	public function active()
103
+	{
104
+		return $this->get('CUR_active');
105
+	}
106
+
107
+
108
+	/**
109
+	 * Sets active
110
+	 *
111
+	 * @param boolean $active
112
+	 * @throws EE_Error
113
+	 * @throws ReflectionException
114
+	 */
115
+	public function set_active($active)
116
+	{
117
+		$this->set('CUR_active', $active);
118
+	}
119
+
120
+
121
+	/**
122
+	 * Gets dec_plc
123
+	 *
124
+	 * @return int
125
+	 * @throws EE_Error
126
+	 */
127
+	public function dec_plc()
128
+	{
129
+		return $this->get('CUR_dec_plc');
130
+	}
131
+
132
+
133
+	/**
134
+	 * Sets dec_plc
135
+	 *
136
+	 * @param int $dec_plc
137
+	 * @throws EE_Error
138
+	 * @throws ReflectionException
139
+	 */
140
+	public function set_dec_plc($dec_plc)
141
+	{
142
+		$this->set('CUR_dec_plc', $dec_plc);
143
+	}
144
+
145
+
146
+	/**
147
+	 * Sets plural
148
+	 *
149
+	 * @param string $plural
150
+	 * @throws EE_Error
151
+	 * @throws ReflectionException
152
+	 */
153
+	public function set_plural_name($plural)
154
+	{
155
+		$this->set('CUR_plural', $plural);
156
+	}
157
+
158
+
159
+	/**
160
+	 * Gets sign
161
+	 *
162
+	 * @return string
163
+	 * @throws EE_Error
164
+	 */
165
+	public function sign()
166
+	{
167
+		return $this->get('CUR_sign');
168
+	}
169
+
170
+
171
+	/**
172
+	 * Sets sign
173
+	 *
174
+	 * @param string $sign
175
+	 * @throws EE_Error
176
+	 * @throws ReflectionException
177
+	 */
178
+	public function set_sign($sign)
179
+	{
180
+		$this->set('CUR_sign', $sign);
181
+	}
182
+
183
+
184
+	/**
185
+	 * Gets single
186
+	 *
187
+	 * @return string
188
+	 * @throws EE_Error
189
+	 */
190
+	public function singular_name()
191
+	{
192
+		return $this->get('CUR_single');
193
+	}
194
+
195
+
196
+	/**
197
+	 * Sets single
198
+	 *
199
+	 * @param string $single
200
+	 * @throws EE_Error
201
+	 * @throws ReflectionException
202
+	 */
203
+	public function set_singular_name($single)
204
+	{
205
+		$this->set('CUR_single', $single);
206
+	}
207
+
208
+
209
+	/**
210
+	 * Gets a prettier name
211
+	 *
212
+	 * @return string
213
+	 * @throws EE_Error
214
+	 */
215
+	public function name()
216
+	{
217
+		return sprintf(
218
+			esc_html__("%s (%s)", "event_espresso"),
219
+			$this->code(),
220
+			$this->plural_name()
221
+		);
222
+	}
223
+
224
+
225
+	/**
226
+	 * Gets code
227
+	 *
228
+	 * @return string
229
+	 * @throws EE_Error
230
+	 */
231
+	public function code()
232
+	{
233
+		return $this->get('CUR_code');
234
+	}
235
+
236
+
237
+	/**
238
+	 * Gets plural
239
+	 *
240
+	 * @return string
241
+	 * @throws EE_Error
242
+	 */
243
+	public function plural_name()
244
+	{
245
+		return $this->get('CUR_plural');
246
+	}
247 247
 }
Please login to merge, or discard this patch.
core/db_classes/EE_Country.class.php 1 patch
Indentation   +132 added lines, -132 removed lines patch added patch discarded remove patch
@@ -10,136 +10,136 @@
 block discarded – undo
10 10
 class EE_Country extends EE_Base_Class
11 11
 {
12 12
 
13
-    /**
14
-     * @param array $props_n_values
15
-     * @return EE_Country|mixed
16
-     * @throws EE_Error
17
-     * @throws ReflectionException
18
-     */
19
-    public static function new_instance($props_n_values = [])
20
-    {
21
-        $has_object = parent::_check_for_object($props_n_values, __CLASS__);
22
-        return $has_object ? $has_object : new self($props_n_values);
23
-    }
24
-
25
-
26
-    /**
27
-     * @param array $props_n_values
28
-     * @return EE_Country
29
-     * @throws EE_Error
30
-     * @throws ReflectionException
31
-     */
32
-    public static function new_instance_from_db($props_n_values = [])
33
-    {
34
-        return new self($props_n_values, true);
35
-    }
36
-
37
-
38
-    /**
39
-     * Gets the country name
40
-     *
41
-     * @return string
42
-     * @throws EE_Error
43
-     */
44
-    public function name()
45
-    {
46
-        return $this->get('CNT_name');
47
-    }
48
-
49
-
50
-    /**
51
-     * gets the country's currency code
52
-     *
53
-     * @return string
54
-     * @throws EE_Error
55
-     */
56
-    public function currency_code()
57
-    {
58
-        return $this->get('CNT_cur_code');
59
-    }
60
-
61
-
62
-    /**
63
-     * gets the country's currency sign/symbol
64
-     *
65
-     * @return string
66
-     * @throws EE_Error
67
-     */
68
-    public function currency_sign()
69
-    {
70
-        $CNT_cur_sign = $this->get('CNT_cur_sign');
71
-        return $CNT_cur_sign ? $CNT_cur_sign : '';
72
-    }
73
-
74
-
75
-    /**
76
-     * Currency name singular
77
-     *
78
-     * @return string
79
-     * @throws EE_Error
80
-     */
81
-    public function currency_name_single()
82
-    {
83
-        return $this->get('CNT_cur_single');
84
-    }
85
-
86
-
87
-    /**
88
-     * Currency name plural
89
-     *
90
-     * @return string
91
-     * @throws EE_Error
92
-     */
93
-    public function currency_name_plural()
94
-    {
95
-        return $this->get('CNT_cur_plural');
96
-    }
97
-
98
-
99
-    /**
100
-     * currency_sign_before - ie: $TRUE  or  FALSE$
101
-     *
102
-     * @return boolean
103
-     * @throws EE_Error
104
-     */
105
-    public function currency_sign_before()
106
-    {
107
-        return $this->get('CNT_cur_sign_b4');
108
-    }
109
-
110
-
111
-    /**
112
-     * currency_decimal_places : 2 = 0.00   3 = 0.000
113
-     *
114
-     * @return integer
115
-     * @throws EE_Error
116
-     */
117
-    public function currency_decimal_places()
118
-    {
119
-        return $this->get('CNT_cur_dec_plc');
120
-    }
121
-
122
-
123
-    /**
124
-     * currency_decimal_mark :   (comma) ',' = 0,01   or   (decimal) '.' = 0.01
125
-     *
126
-     * @return string
127
-     * @throws EE_Error
128
-     */
129
-    public function currency_decimal_mark()
130
-    {
131
-        return $this->get('CNT_cur_dec_mrk');
132
-    }
133
-
134
-
135
-    /**
136
-     * currency thousands separator:   (comma) ',' = 1,000   or   (decimal) '.' = 1.000
137
-     *
138
-     * @return string
139
-     * @throws EE_Error
140
-     */
141
-    public function currency_thousands_separator()
142
-    {
143
-        return $this->get('CNT_cur_thsnds');
144
-    }
13
+	/**
14
+	 * @param array $props_n_values
15
+	 * @return EE_Country|mixed
16
+	 * @throws EE_Error
17
+	 * @throws ReflectionException
18
+	 */
19
+	public static function new_instance($props_n_values = [])
20
+	{
21
+		$has_object = parent::_check_for_object($props_n_values, __CLASS__);
22
+		return $has_object ? $has_object : new self($props_n_values);
23
+	}
24
+
25
+
26
+	/**
27
+	 * @param array $props_n_values
28
+	 * @return EE_Country
29
+	 * @throws EE_Error
30
+	 * @throws ReflectionException
31
+	 */
32
+	public static function new_instance_from_db($props_n_values = [])
33
+	{
34
+		return new self($props_n_values, true);
35
+	}
36
+
37
+
38
+	/**
39
+	 * Gets the country name
40
+	 *
41
+	 * @return string
42
+	 * @throws EE_Error
43
+	 */
44
+	public function name()
45
+	{
46
+		return $this->get('CNT_name');
47
+	}
48
+
49
+
50
+	/**
51
+	 * gets the country's currency code
52
+	 *
53
+	 * @return string
54
+	 * @throws EE_Error
55
+	 */
56
+	public function currency_code()
57
+	{
58
+		return $this->get('CNT_cur_code');
59
+	}
60
+
61
+
62
+	/**
63
+	 * gets the country's currency sign/symbol
64
+	 *
65
+	 * @return string
66
+	 * @throws EE_Error
67
+	 */
68
+	public function currency_sign()
69
+	{
70
+		$CNT_cur_sign = $this->get('CNT_cur_sign');
71
+		return $CNT_cur_sign ? $CNT_cur_sign : '';
72
+	}
73
+
74
+
75
+	/**
76
+	 * Currency name singular
77
+	 *
78
+	 * @return string
79
+	 * @throws EE_Error
80
+	 */
81
+	public function currency_name_single()
82
+	{
83
+		return $this->get('CNT_cur_single');
84
+	}
85
+
86
+
87
+	/**
88
+	 * Currency name plural
89
+	 *
90
+	 * @return string
91
+	 * @throws EE_Error
92
+	 */
93
+	public function currency_name_plural()
94
+	{
95
+		return $this->get('CNT_cur_plural');
96
+	}
97
+
98
+
99
+	/**
100
+	 * currency_sign_before - ie: $TRUE  or  FALSE$
101
+	 *
102
+	 * @return boolean
103
+	 * @throws EE_Error
104
+	 */
105
+	public function currency_sign_before()
106
+	{
107
+		return $this->get('CNT_cur_sign_b4');
108
+	}
109
+
110
+
111
+	/**
112
+	 * currency_decimal_places : 2 = 0.00   3 = 0.000
113
+	 *
114
+	 * @return integer
115
+	 * @throws EE_Error
116
+	 */
117
+	public function currency_decimal_places()
118
+	{
119
+		return $this->get('CNT_cur_dec_plc');
120
+	}
121
+
122
+
123
+	/**
124
+	 * currency_decimal_mark :   (comma) ',' = 0,01   or   (decimal) '.' = 0.01
125
+	 *
126
+	 * @return string
127
+	 * @throws EE_Error
128
+	 */
129
+	public function currency_decimal_mark()
130
+	{
131
+		return $this->get('CNT_cur_dec_mrk');
132
+	}
133
+
134
+
135
+	/**
136
+	 * currency thousands separator:   (comma) ',' = 1,000   or   (decimal) '.' = 1.000
137
+	 *
138
+	 * @return string
139
+	 * @throws EE_Error
140
+	 */
141
+	public function currency_thousands_separator()
142
+	{
143
+		return $this->get('CNT_cur_thsnds');
144
+	}
145 145
 }
Please login to merge, or discard this patch.
core/db_classes/EE_Change_Log.class.php 2 patches
Indentation   +236 added lines, -236 removed lines patch added patch discarded remove patch
@@ -10,240 +10,240 @@
 block discarded – undo
10 10
 class EE_Change_Log extends EE_Base_Class
11 11
 {
12 12
 
13
-    /**
14
-     * @param array  $props_n_values    incoming values
15
-     * @param string $timezone          incoming timezone
16
-     *                                  If not set the timezone for the website will be 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
-     * @throws ReflectionException
22
-     */
23
-    public static function new_instance($props_n_values = [], $timezone = null, $date_formats = [])
24
-    {
25
-        $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats);
26
-        return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats);
27
-    }
28
-
29
-
30
-    /**
31
-     * @param array  $props_n_values  incoming values from the database
32
-     * @param string $timezone        incoming timezone as set by the model.
33
-     *                                If not set the timezone for the website will be used.
34
-     * @return EE_Change_Log
35
-     * @throws EE_Error
36
-     * @throws ReflectionException
37
-     */
38
-    public static function new_instance_from_db($props_n_values = [], $timezone = null)
39
-    {
40
-        return new self($props_n_values, true, $timezone);
41
-    }
42
-
43
-
44
-    /**
45
-     * Gets message
46
-     *
47
-     * @return mixed
48
-     * @throws EE_Error
49
-     */
50
-    public function message()
51
-    {
52
-        return $this->get('LOG_message');
53
-    }
54
-
55
-
56
-    /**
57
-     * Sets message
58
-     *
59
-     * @param mixed $message
60
-     * @throws EE_Error
61
-     * @throws ReflectionException
62
-     */
63
-    public function set_message($message)
64
-    {
65
-        $this->set('LOG_message', $message);
66
-    }
67
-
68
-
69
-    /**
70
-     * Gets time
71
-     *
72
-     * @return string
73
-     * @throws EE_Error
74
-     */
75
-    public function time()
76
-    {
77
-        return $this->get('LOG_time');
78
-    }
79
-
80
-
81
-    /**
82
-     * Sets time
83
-     *
84
-     * @param string $time
85
-     * @throws EE_Error
86
-     * @throws ReflectionException
87
-     */
88
-    public function set_time($time)
89
-    {
90
-        $this->set('LOG_time', $time);
91
-    }
92
-
93
-
94
-    /**
95
-     * Return the localized log type label.
96
-     *
97
-     * @return string
98
-     * @throws EE_Error
99
-     */
100
-    public function log_type_label()
101
-    {
102
-        return EEM_Change_Log::get_pretty_label_for_type($this->log_type());
103
-    }
104
-
105
-
106
-    /**
107
-     * Gets log_type
108
-     *
109
-     * @return string
110
-     * @throws EE_Error
111
-     */
112
-    public function log_type()
113
-    {
114
-        return $this->get('LOG_type');
115
-    }
116
-
117
-
118
-    /**
119
-     * Sets log_type
120
-     *
121
-     * @param string $log_type
122
-     * @throws EE_Error
123
-     * @throws ReflectionException
124
-     */
125
-    public function set_log_type($log_type)
126
-    {
127
-        $this->set('LOG_type', $log_type);
128
-    }
129
-
130
-
131
-    /**
132
-     * Gets OBJ_ID (the ID of the item related to this log)
133
-     *
134
-     * @return mixed
135
-     * @throws EE_Error
136
-     */
137
-    public function OBJ_ID()
138
-    {
139
-        return $this->get('OBJ_ID');
140
-    }
141
-
142
-
143
-    /**
144
-     * Gets wp_user
145
-     *
146
-     * @return int
147
-     * @throws EE_Error
148
-     */
149
-    public function wp_user()
150
-    {
151
-        return $this->get('LOG_wp_user');
152
-    }
153
-
154
-
155
-    /**
156
-     * Sets wp_user
157
-     *
158
-     * @param int $wp_user_id
159
-     * @throws EE_Error
160
-     * @throws ReflectionException
161
-     */
162
-    public function set_wp_user($wp_user_id)
163
-    {
164
-        $this->set('LOG_wp_user', $wp_user_id);
165
-    }
166
-
167
-
168
-    /**
169
-     * Gets the model object attached to this log
170
-     *
171
-     * @return EE_Base_Class
172
-     * @throws EE_Error
173
-     * @throws ReflectionException
174
-     */
175
-    public function object()
176
-    {
177
-        $model_name_of_related_obj = $this->OBJ_type();
178
-        $is_model_name             = EE_Registry::instance()->is_model_name($model_name_of_related_obj);
179
-        if (! $is_model_name) {
180
-            return null;
181
-        }
182
-        return $this->get_first_related($model_name_of_related_obj);
183
-    }
184
-
185
-
186
-    /**
187
-     * Gets type of the model object related to this log
188
-     *
189
-     * @return string
190
-     * @throws EE_Error
191
-     */
192
-    public function OBJ_type()
193
-    {
194
-        return $this->get('OBJ_type');
195
-    }
196
-
197
-
198
-    /**
199
-     * Shorthand for setting the OBJ_ID and OBJ_type. Slightly handier than using
200
-     * _add_relation_to because you don't have to specify what type of model you're
201
-     * associating it with
202
-     *
203
-     * @param EE_Base_Class $object
204
-     * @param boolean       $save
205
-     * @return bool if $save=true, NULL is $save=false
206
-     * @throws EE_Error
207
-     * @throws ReflectionException
208
-     */
209
-    public function set_object($object, $save = true)
210
-    {
211
-        if ($object instanceof EE_Base_Class) {
212
-            $this->set_OBJ_type($object->get_model()->get_this_model_name());
213
-            $this->set_OBJ_ID($object->ID());
214
-        } else {
215
-            $this->set_OBJ_type(null);
216
-            $this->set_OBJ_ID(null);
217
-        }
218
-        if ($save) {
219
-            return $this->save();
220
-        }
221
-        return null;
222
-    }
223
-
224
-
225
-    /**
226
-     * Sets type
227
-     *
228
-     * @param string $type
229
-     * @throws EE_Error
230
-     * @throws ReflectionException
231
-     */
232
-    public function set_OBJ_type($type)
233
-    {
234
-        $this->set('OBJ_type', $type);
235
-    }
236
-
237
-
238
-    /**
239
-     * Sets OBJ_ID
240
-     *
241
-     * @param mixed $OBJ_ID
242
-     * @throws EE_Error
243
-     * @throws ReflectionException
244
-     */
245
-    public function set_OBJ_ID($OBJ_ID)
246
-    {
247
-        $this->set('OBJ_ID', $OBJ_ID);
248
-    }
13
+	/**
14
+	 * @param array  $props_n_values    incoming values
15
+	 * @param string $timezone          incoming timezone
16
+	 *                                  If not set the timezone for the website will be 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
+	 * @throws ReflectionException
22
+	 */
23
+	public static function new_instance($props_n_values = [], $timezone = null, $date_formats = [])
24
+	{
25
+		$has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats);
26
+		return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats);
27
+	}
28
+
29
+
30
+	/**
31
+	 * @param array  $props_n_values  incoming values from the database
32
+	 * @param string $timezone        incoming timezone as set by the model.
33
+	 *                                If not set the timezone for the website will be used.
34
+	 * @return EE_Change_Log
35
+	 * @throws EE_Error
36
+	 * @throws ReflectionException
37
+	 */
38
+	public static function new_instance_from_db($props_n_values = [], $timezone = null)
39
+	{
40
+		return new self($props_n_values, true, $timezone);
41
+	}
42
+
43
+
44
+	/**
45
+	 * Gets message
46
+	 *
47
+	 * @return mixed
48
+	 * @throws EE_Error
49
+	 */
50
+	public function message()
51
+	{
52
+		return $this->get('LOG_message');
53
+	}
54
+
55
+
56
+	/**
57
+	 * Sets message
58
+	 *
59
+	 * @param mixed $message
60
+	 * @throws EE_Error
61
+	 * @throws ReflectionException
62
+	 */
63
+	public function set_message($message)
64
+	{
65
+		$this->set('LOG_message', $message);
66
+	}
67
+
68
+
69
+	/**
70
+	 * Gets time
71
+	 *
72
+	 * @return string
73
+	 * @throws EE_Error
74
+	 */
75
+	public function time()
76
+	{
77
+		return $this->get('LOG_time');
78
+	}
79
+
80
+
81
+	/**
82
+	 * Sets time
83
+	 *
84
+	 * @param string $time
85
+	 * @throws EE_Error
86
+	 * @throws ReflectionException
87
+	 */
88
+	public function set_time($time)
89
+	{
90
+		$this->set('LOG_time', $time);
91
+	}
92
+
93
+
94
+	/**
95
+	 * Return the localized log type label.
96
+	 *
97
+	 * @return string
98
+	 * @throws EE_Error
99
+	 */
100
+	public function log_type_label()
101
+	{
102
+		return EEM_Change_Log::get_pretty_label_for_type($this->log_type());
103
+	}
104
+
105
+
106
+	/**
107
+	 * Gets log_type
108
+	 *
109
+	 * @return string
110
+	 * @throws EE_Error
111
+	 */
112
+	public function log_type()
113
+	{
114
+		return $this->get('LOG_type');
115
+	}
116
+
117
+
118
+	/**
119
+	 * Sets log_type
120
+	 *
121
+	 * @param string $log_type
122
+	 * @throws EE_Error
123
+	 * @throws ReflectionException
124
+	 */
125
+	public function set_log_type($log_type)
126
+	{
127
+		$this->set('LOG_type', $log_type);
128
+	}
129
+
130
+
131
+	/**
132
+	 * Gets OBJ_ID (the ID of the item related to this log)
133
+	 *
134
+	 * @return mixed
135
+	 * @throws EE_Error
136
+	 */
137
+	public function OBJ_ID()
138
+	{
139
+		return $this->get('OBJ_ID');
140
+	}
141
+
142
+
143
+	/**
144
+	 * Gets wp_user
145
+	 *
146
+	 * @return int
147
+	 * @throws EE_Error
148
+	 */
149
+	public function wp_user()
150
+	{
151
+		return $this->get('LOG_wp_user');
152
+	}
153
+
154
+
155
+	/**
156
+	 * Sets wp_user
157
+	 *
158
+	 * @param int $wp_user_id
159
+	 * @throws EE_Error
160
+	 * @throws ReflectionException
161
+	 */
162
+	public function set_wp_user($wp_user_id)
163
+	{
164
+		$this->set('LOG_wp_user', $wp_user_id);
165
+	}
166
+
167
+
168
+	/**
169
+	 * Gets the model object attached to this log
170
+	 *
171
+	 * @return EE_Base_Class
172
+	 * @throws EE_Error
173
+	 * @throws ReflectionException
174
+	 */
175
+	public function object()
176
+	{
177
+		$model_name_of_related_obj = $this->OBJ_type();
178
+		$is_model_name             = EE_Registry::instance()->is_model_name($model_name_of_related_obj);
179
+		if (! $is_model_name) {
180
+			return null;
181
+		}
182
+		return $this->get_first_related($model_name_of_related_obj);
183
+	}
184
+
185
+
186
+	/**
187
+	 * Gets type of the model object related to this log
188
+	 *
189
+	 * @return string
190
+	 * @throws EE_Error
191
+	 */
192
+	public function OBJ_type()
193
+	{
194
+		return $this->get('OBJ_type');
195
+	}
196
+
197
+
198
+	/**
199
+	 * Shorthand for setting the OBJ_ID and OBJ_type. Slightly handier than using
200
+	 * _add_relation_to because you don't have to specify what type of model you're
201
+	 * associating it with
202
+	 *
203
+	 * @param EE_Base_Class $object
204
+	 * @param boolean       $save
205
+	 * @return bool if $save=true, NULL is $save=false
206
+	 * @throws EE_Error
207
+	 * @throws ReflectionException
208
+	 */
209
+	public function set_object($object, $save = true)
210
+	{
211
+		if ($object instanceof EE_Base_Class) {
212
+			$this->set_OBJ_type($object->get_model()->get_this_model_name());
213
+			$this->set_OBJ_ID($object->ID());
214
+		} else {
215
+			$this->set_OBJ_type(null);
216
+			$this->set_OBJ_ID(null);
217
+		}
218
+		if ($save) {
219
+			return $this->save();
220
+		}
221
+		return null;
222
+	}
223
+
224
+
225
+	/**
226
+	 * Sets type
227
+	 *
228
+	 * @param string $type
229
+	 * @throws EE_Error
230
+	 * @throws ReflectionException
231
+	 */
232
+	public function set_OBJ_type($type)
233
+	{
234
+		$this->set('OBJ_type', $type);
235
+	}
236
+
237
+
238
+	/**
239
+	 * Sets OBJ_ID
240
+	 *
241
+	 * @param mixed $OBJ_ID
242
+	 * @throws EE_Error
243
+	 * @throws ReflectionException
244
+	 */
245
+	public function set_OBJ_ID($OBJ_ID)
246
+	{
247
+		$this->set('OBJ_ID', $OBJ_ID);
248
+	}
249 249
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -176,7 +176,7 @@
 block discarded – undo
176 176
     {
177 177
         $model_name_of_related_obj = $this->OBJ_type();
178 178
         $is_model_name             = EE_Registry::instance()->is_model_name($model_name_of_related_obj);
179
-        if (! $is_model_name) {
179
+        if ( ! $is_model_name) {
180 180
             return null;
181 181
         }
182 182
         return $this->get_first_related($model_name_of_related_obj);
Please login to merge, or discard this patch.
core/db_classes/EE_Checkin.class.php 1 patch
Indentation   +103 added lines, -103 removed lines patch added patch discarded remove patch
@@ -11,107 +11,107 @@
 block discarded – undo
11 11
 {
12 12
 
13 13
 
14
-    /**
15
-     * Used to reference when a registration has been checked out.
16
-     *
17
-     * @type int
18
-     */
19
-    const status_checked_out = 0;
20
-
21
-    /**
22
-     * Used to reference when a registration has been checked in.
23
-     *
24
-     * @type int
25
-     */
26
-    const status_checked_in = 1;
27
-
28
-    /**
29
-     * Used to reference when a registration has never been checked in.
30
-     *
31
-     * @type int
32
-     */
33
-    const status_checked_never = 2;
34
-
35
-
36
-    /**
37
-     * @param array  $props_n_values    incoming values
38
-     * @param string $timezone          incoming timezone (if not set the timezone set for the website will be used.)
39
-     * @param array  $date_formats      incoming date_formats in an array
40
-     *                                  where the first value is the date_format
41
-     *                                  and the second value is the time format
42
-     * @return EE_Checkin
43
-     * @throws EE_Error
44
-     * @throws ReflectionException
45
-     */
46
-    public static function new_instance($props_n_values = [], $timezone = null, $date_formats = [])
47
-    {
48
-        $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats);
49
-        return $has_object
50
-            ? $has_object
51
-            : new self($props_n_values, false, $timezone, $date_formats);
52
-    }
53
-
54
-
55
-    /**
56
-     * @param array  $props_n_values  incoming values from the database
57
-     * @param string $timezone        incoming timezone as set by the model.  If not set the timezone for
58
-     *                                the website will be used.
59
-     * @return EE_Checkin
60
-     * @throws EE_Error
61
-     * @throws ReflectionException
62
-     */
63
-    public static function new_instance_from_db($props_n_values = [], $timezone = null)
64
-    {
65
-        return new self($props_n_values, true, $timezone);
66
-    }
67
-
68
-
69
-    /**
70
-     * @return mixed
71
-     * @throws EE_Error
72
-     */
73
-    public function ID()
74
-    {
75
-        return $this->get('CHK_ID');
76
-    }
77
-
78
-
79
-    /**
80
-     * @return mixed
81
-     * @throws EE_Error
82
-     */
83
-    public function registration_id()
84
-    {
85
-        return $this->get('REG_ID');
86
-    }
87
-
88
-
89
-    /**
90
-     * @return mixed
91
-     * @throws EE_Error
92
-     */
93
-    public function datetime_id()
94
-    {
95
-        return $this->get('DTT_ID');
96
-    }
97
-
98
-
99
-    /**
100
-     * @return mixed
101
-     * @throws EE_Error
102
-     */
103
-    public function status()
104
-    {
105
-        return $this->get('CHK_in');
106
-    }
107
-
108
-
109
-    /**
110
-     * @return mixed
111
-     * @throws EE_Error
112
-     */
113
-    public function timestamp()
114
-    {
115
-        return $this->get('CHK_timestamp');
116
-    }
14
+	/**
15
+	 * Used to reference when a registration has been checked out.
16
+	 *
17
+	 * @type int
18
+	 */
19
+	const status_checked_out = 0;
20
+
21
+	/**
22
+	 * Used to reference when a registration has been checked in.
23
+	 *
24
+	 * @type int
25
+	 */
26
+	const status_checked_in = 1;
27
+
28
+	/**
29
+	 * Used to reference when a registration has never been checked in.
30
+	 *
31
+	 * @type int
32
+	 */
33
+	const status_checked_never = 2;
34
+
35
+
36
+	/**
37
+	 * @param array  $props_n_values    incoming values
38
+	 * @param string $timezone          incoming timezone (if not set the timezone set for the website will be used.)
39
+	 * @param array  $date_formats      incoming date_formats in an array
40
+	 *                                  where the first value is the date_format
41
+	 *                                  and the second value is the time format
42
+	 * @return EE_Checkin
43
+	 * @throws EE_Error
44
+	 * @throws ReflectionException
45
+	 */
46
+	public static function new_instance($props_n_values = [], $timezone = null, $date_formats = [])
47
+	{
48
+		$has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats);
49
+		return $has_object
50
+			? $has_object
51
+			: new self($props_n_values, false, $timezone, $date_formats);
52
+	}
53
+
54
+
55
+	/**
56
+	 * @param array  $props_n_values  incoming values from the database
57
+	 * @param string $timezone        incoming timezone as set by the model.  If not set the timezone for
58
+	 *                                the website will be used.
59
+	 * @return EE_Checkin
60
+	 * @throws EE_Error
61
+	 * @throws ReflectionException
62
+	 */
63
+	public static function new_instance_from_db($props_n_values = [], $timezone = null)
64
+	{
65
+		return new self($props_n_values, true, $timezone);
66
+	}
67
+
68
+
69
+	/**
70
+	 * @return mixed
71
+	 * @throws EE_Error
72
+	 */
73
+	public function ID()
74
+	{
75
+		return $this->get('CHK_ID');
76
+	}
77
+
78
+
79
+	/**
80
+	 * @return mixed
81
+	 * @throws EE_Error
82
+	 */
83
+	public function registration_id()
84
+	{
85
+		return $this->get('REG_ID');
86
+	}
87
+
88
+
89
+	/**
90
+	 * @return mixed
91
+	 * @throws EE_Error
92
+	 */
93
+	public function datetime_id()
94
+	{
95
+		return $this->get('DTT_ID');
96
+	}
97
+
98
+
99
+	/**
100
+	 * @return mixed
101
+	 * @throws EE_Error
102
+	 */
103
+	public function status()
104
+	{
105
+		return $this->get('CHK_in');
106
+	}
107
+
108
+
109
+	/**
110
+	 * @return mixed
111
+	 * @throws EE_Error
112
+	 */
113
+	public function timestamp()
114
+	{
115
+		return $this->get('CHK_timestamp');
116
+	}
117 117
 }
Please login to merge, or discard this patch.