Completed
Branch BUG-10477-answer-cache-id (4bdd94)
by
unknown
36:00 queued 24:53
created

EE_Attendee::ATT_full_name()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 1
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
1
<?php if (! defined('EVENT_ESPRESSO_VERSION')) {
2
    exit('No direct script access allowed');
3
}
4
/**
5
 * Event Espresso
6
 * Event Registration and Management Plugin for WordPress
7
 * @ package            Event Espresso
8
 * @ author                Seth Shoultes
9
 * @ copyright        (c) 2008-2011 Event Espresso  All Rights Reserved.
10
 * @ license            {@link http://eventespresso.com/support/terms-conditions/}   * see Plugin Licensing *
11
 * @ link                    {@link http://www.eventespresso.com}
12
 * @ since                4.0
13
 */
14
15
16
/**
17
 * EE_Attendee class
18
 *
19
 * @package               Event Espresso
20
 * @subpackage            includes/classes/EE_Transaction.class.php
21
 * @author                Mike Nelson
22
 */
23
class EE_Attendee extends EE_CPT_Base implements EEI_Contact, EEI_Address, EEI_Admin_Links, EEI_Attendee
24
{
25
26
    /**
27
     * Sets some dynamic defaults
28
     *
29
     * @param array  $fieldValues
30
     * @param bool   $bydb
31
     * @param string $timezone
32
     * @param array  $date_formats
33
     */
34
    protected function __construct($fieldValues = null, $bydb = false, $timezone = null, $date_formats = array())
35
    {
36
        if (! isset($fieldValues['ATT_full_name'])) {
37
            $fname                        = isset($fieldValues['ATT_fname']) ? $fieldValues['ATT_fname'] . ' ' : '';
38
            $lname                        = isset($fieldValues['ATT_lname']) ? $fieldValues['ATT_lname'] : '';
39
            $fieldValues['ATT_full_name'] = $fname . $lname;
40
        }
41
        if (! isset($fieldValues['ATT_slug'])) {
42
            //			$fieldValues['ATT_slug'] = sanitize_key(wp_generate_password(20));
43
            $fieldValues['ATT_slug'] = sanitize_title($fieldValues['ATT_full_name']);
44
        }
45
        if (! isset($fieldValues['ATT_short_bio']) && isset($fieldValues['ATT_bio'])) {
46
            $fieldValues['ATT_short_bio'] = substr($fieldValues['ATT_bio'], 0, 50);
47
        }
48
        parent::__construct($fieldValues, $bydb, $timezone, $date_formats);
49
    }
50
51
52
    /**
53
     * @param array  $props_n_values          incoming values
54
     * @param string $timezone                incoming timezone (if not set the timezone set for the website will be
55
     *                                        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_Attendee
59
     */
60
    public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array())
61
    {
62
        $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats);
0 ignored issues
show
Bug introduced by
It seems like $timezone defined by parameter $timezone on line 60 can also be of type string; however, EE_Base_Class::_check_for_object() does only seem to accept null, maybe add an additional type check?

This check looks at variables that have been passed in as parameters and are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
Comprehensibility Bug introduced by
It seems like you call parent on a different method (_check_for_object() instead of new_instance()). Are you sure this is correct? If so, you might want to change this to $this->_check_for_object().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
63
        return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats);
64
    }
65
66
67
    /**
68
     * @param array  $props_n_values  incoming values from the database
69
     * @param string $timezone        incoming timezone as set by the model.  If not set the timezone for
70
     *                                the website will be used.
71
     * @return EE_Attendee
72
     */
73
    public static function new_instance_from_db($props_n_values = array(), $timezone = null)
74
    {
75
        return new self($props_n_values, true, $timezone);
76
    }
77
78
79
    /**
80
     *        Set Attendee First Name
81
     *
82
     * @access        public
83
     * @param string $fname
84
     */
85
    public function set_fname($fname = '')
86
    {
87
        $this->set('ATT_fname', $fname);
88
    }
89
90
91
    /**
92
     *        Set Attendee Last Name
93
     *
94
     * @access        public
95
     * @param string $lname
96
     */
97
    public function set_lname($lname = '')
98
    {
99
        $this->set('ATT_lname', $lname);
100
    }
101
102
103
    /**
104
     *        Set Attendee Address
105
     *
106
     * @access        public
107
     * @param string $address
108
     */
109
    public function set_address($address = '')
110
    {
111
        $this->set('ATT_address', $address);
112
    }
113
114
115
    /**
116
     *        Set Attendee Address2
117
     *
118
     * @access        public
119
     * @param        string $address2
120
     */
121
    public function set_address2($address2 = '')
122
    {
123
        $this->set('ATT_address2', $address2);
124
    }
125
126
127
    /**
128
     *        Set Attendee City
129
     *
130
     * @access        public
131
     * @param        string $city
132
     */
133
    public function set_city($city = '')
134
    {
135
        $this->set('ATT_city', $city);
136
    }
137
138
139
    /**
140
     *        Set Attendee State ID
141
     *
142
     * @access        public
143
     * @param        int $STA_ID
144
     */
145
    public function set_state($STA_ID = 0)
146
    {
147
        $this->set('STA_ID', $STA_ID);
148
    }
149
150
151
    /**
152
     *        Set Attendee Country ISO Code
153
     *
154
     * @access        public
155
     * @param        string $CNT_ISO
156
     */
157
    public function set_country($CNT_ISO = '')
158
    {
159
        $this->set('CNT_ISO', $CNT_ISO);
160
    }
161
162
163
    /**
164
     *        Set Attendee Zip/Postal Code
165
     *
166
     * @access        public
167
     * @param        string $zip
168
     */
169
    public function set_zip($zip = '')
170
    {
171
        $this->set('ATT_zip', $zip);
172
    }
173
174
175
    /**
176
     *        Set Attendee Email Address
177
     *
178
     * @access        public
179
     * @param        string $email
180
     */
181
    public function set_email($email = '')
182
    {
183
        $this->set('ATT_email', $email);
184
    }
185
186
187
    /**
188
     *        Set Attendee Phone
189
     *
190
     * @access        public
191
     * @param        string $phone
192
     */
193
    public function set_phone($phone = '')
194
    {
195
        $this->set('ATT_phone', $phone);
196
    }
197
198
199
    /**
200
     *        set deleted
201
     *
202
     * @access        public
203
     * @param        bool $ATT_deleted
204
     */
205
    public function set_deleted($ATT_deleted = false)
206
    {
207
        $this->set('ATT_deleted', $ATT_deleted);
208
    }
209
210
211
    /**
212
     * Returns the value for the post_author id saved with the cpt
213
     *
214
     * @since 4.5.0
215
     * @return int
216
     */
217
    public function wp_user()
218
    {
219
        return $this->get('ATT_author');
220
    }
221
222
223
    /**
224
     *        get Attendee First Name
225
     *
226
     * @access        public
227
     * @return string
228
     */
229
    public function fname()
230
    {
231
        return $this->get('ATT_fname');
232
    }
233
234
235
    /**
236
     * echoes out the attendee's first name
237
     *
238
     * @return void
239
     */
240
    public function e_full_name()
241
    {
242
        echo $this->full_name();
243
    }
244
245
246
    /**
247
     * Returns the first and last name concatenated together with a space.
248
     *
249
     * @param bool $apply_html_entities
250
     * @return string
251
     */
252
    public function full_name($apply_html_entities = false)
253
    {
254
        $full_name = $this->fname() . ' ' . $this->lname();
255
        return $apply_html_entities ? htmlentities($full_name, ENT_QUOTES, 'UTF-8') : $full_name;
256
    }
257
258
259
    /**
260
     * This returns the value of the `ATT_full_name` field which is usually equivalent to calling `full_name()` unless
261
     * the post_title field has been directly modified in the db for the post (espresso_attendees post type) for this
262
     * attendee.
263
     *
264
     * @param bool $apply_html_entities
265
     * @return string
266
     */
267
    public function ATT_full_name($apply_html_entities = false)
268
    {
269
        return $apply_html_entities
270
            ? htmlentities($this->get('ATT_full_name'), ENT_QUOTES, 'UTF-8')
271
            : $this->get('ATT_full_name');
272
    }
273
274
275
    /**
276
     *        get Attendee Last Name
277
     *
278
     * @access        public
279
     * @return string
280
     */
281
    public function lname()
282
    {
283
        return $this->get('ATT_lname');
284
    }
285
286
287
    /**
288
     * Gets the attendee's full address as an array so client code can decide hwo to display it
289
     *
290
     * @return array numerically indexed, with each part of the address that is known.
291
     * Eg, if the user only responded to state and country,
292
     * it would be array(0=>'Alabama',1=>'USA')
293
     * @return array
294
     */
295
    public function full_address_as_array()
296
    {
297
        $full_address_array     = array();
298
        $initial_address_fields = array('ATT_address', 'ATT_address2', 'ATT_city',);
299
        foreach ($initial_address_fields as $address_field_name) {
300
            $address_fields_value = $this->get($address_field_name);
301
            if (! empty($address_fields_value)) {
302
                $full_address_array[] = $address_fields_value;
303
            }
304
        }
305
        //now handle state and country
306
        $state_obj = $this->state_obj();
307
        if (! empty($state_obj)) {
308
            $full_address_array[] = $state_obj->name();
309
        }
310
        $country_obj = $this->country_obj();
311
        if (! empty($country_obj)) {
312
            $full_address_array[] = $country_obj->name();
313
        }
314
        //lastly get the xip
315
        $zip_value = $this->zip();
316
        if (! empty($zip_value)) {
317
            $full_address_array[] = $zip_value;
318
        }
319
        return $full_address_array;
320
    }
321
322
323
    /**
324
     *        get Attendee Address
325
     *
326
     * @return string
327
     */
328
    public function address()
329
    {
330
        return $this->get('ATT_address');
331
    }
332
333
334
    /**
335
     *        get Attendee Address2
336
     *
337
     * @return string
338
     */
339
    public function address2()
340
    {
341
        return $this->get('ATT_address2');
342
    }
343
344
345
    /**
346
     *        get Attendee City
347
     *
348
     * @return string
349
     */
350
    public function city()
351
    {
352
        return $this->get('ATT_city');
353
    }
354
355
356
    /**
357
     *        get Attendee State ID
358
     *
359
     * @return string
360
     */
361
    public function state_ID()
362
    {
363
        return $this->get('STA_ID');
364
    }
365
366
367
    /**
368
     * @return string
369
     */
370
    public function state_abbrev()
371
    {
372
        return $this->state_obj() instanceof EE_State ? $this->state_obj()->abbrev() : '';
373
    }
374
375
376
    /**
377
     * Gets the state set to this attendee
378
     *
379
     * @return EE_State
380
     */
381
    public function state_obj()
382
    {
383
        return $this->get_first_related('State');
384
    }
385
386
387
    /**
388
     * Returns the state's name, otherwise 'Unknown'
389
     *
390
     * @return string
391
     */
392
    public function state_name()
393
    {
394
        if ($this->state_obj()) {
395
            return $this->state_obj()->name();
396
        } else {
397
            return '';
398
        }
399
    }
400
401
402
    /**
403
     * either displays the state abbreviation or the state name, as determined
404
     * by the "FHEE__EEI_Address__state__use_abbreviation" filter.
405
     * defaults to abbreviation
406
     *
407
     * @return string
408
     */
409
    public function state()
410
    {
411
        if (apply_filters('FHEE__EEI_Address__state__use_abbreviation', true, $this->state_obj())) {
412
            return $this->state_abbrev();
413
        } else {
414
            return $this->state_name();
415
        }
416
    }
417
418
419
    /**
420
     *    get Attendee Country ISO Code
421
     *
422
     * @return string
423
     */
424
    public function country_ID()
425
    {
426
        return $this->get('CNT_ISO');
427
    }
428
429
430
    /**
431
     * Gets country set for this attendee
432
     *
433
     * @return EE_Country
434
     */
435
    public function country_obj()
436
    {
437
        return $this->get_first_related('Country');
438
    }
439
440
441
    /**
442
     * Returns the country's name if known, otherwise 'Unknown'
443
     *
444
     * @return string
445
     */
446
    public function country_name()
447
    {
448
        if ($this->country_obj()) {
449
            return $this->country_obj()->name();
450
        } else {
451
            return '';
452
        }
453
    }
454
455
456
    /**
457
     * either displays the country ISO2 code or the country name, as determined
458
     * by the "FHEE__EEI_Address__country__use_abbreviation" filter.
459
     * defaults to abbreviation
460
     *
461
     * @return string
462
     */
463
    public function country()
464
    {
465
        if (apply_filters('FHEE__EEI_Address__country__use_abbreviation', true, $this->country_obj())) {
466
            return $this->country_ID();
467
        } else {
468
            return $this->country_name();
469
        }
470
    }
471
472
473
    /**
474
     *        get Attendee Zip/Postal Code
475
     *
476
     * @return string
477
     */
478
    public function zip()
479
    {
480
        return $this->get('ATT_zip');
481
    }
482
483
484
    /**
485
     *        get Attendee Email Address
486
     *
487
     * @return string
488
     */
489
    public function email()
490
    {
491
        return $this->get('ATT_email');
492
    }
493
494
495
    /**
496
     *        get Attendee Phone #
497
     *
498
     * @return string
499
     */
500
    public function phone()
501
    {
502
        return $this->get('ATT_phone');
503
    }
504
505
506
    /**
507
     *    get deleted
508
     *
509
     * @return        bool
510
     */
511
    public function deleted()
512
    {
513
        return $this->get('ATT_deleted');
514
    }
515
516
517
    /**
518
     * Gets registrations of this attendee
519
     *
520
     * @param array $query_params
521
     * @return EE_Registration[]
522
     */
523
    public function get_registrations($query_params = array())
524
    {
525
        return $this->get_many_related('Registration', $query_params);
526
    }
527
528
529
    /**
530
     * Gets the most recent registration of this attendee
531
     *
532
     * @return EE_Registration
533
     */
534
    public function get_most_recent_registration()
535
    {
536
        return $this->get_first_related('Registration',
537
            array('order_by' => array('REG_date' => 'DESC'))); //null, 'REG_date', 'DESC', '=', 'OBJECT_K');
538
    }
539
540
541
    /**
542
     * Gets the most recent registration for this attend at this event
543
     *
544
     * @param int $event_id
545
     * @return EE_Registration
546
     */
547
    public function get_most_recent_registration_for_event($event_id)
548
    {
549
        return $this->get_first_related('Registration',
550
            array(array('EVT_ID' => $event_id), 'order_by' => array('REG_date' => 'DESC')));//, '=', 'OBJECT_K' );
551
    }
552
553
554
    /**
555
     * returns any events attached to this attendee ($_Event property);
556
     *
557
     * @return array
558
     */
559
    public function events()
560
    {
561
        return $this->get_many_related('Event');
562
    }
563
564
565
    /**
566
     * Gets the billing info array where keys match espresso_reg_page_billing_inputs(),
567
     * and keys are their cleaned values. @see EE_Attendee::save_and_clean_billing_info_for_payment_method() which was
568
     * used to save the billing info
569
     *
570
     * @param EE_Payment_Method $payment_method the _gateway_name property on the gateway class
571
     * @return EE_Form_Section_Proper|null
572
     */
573
    public function billing_info_for_payment_method($payment_method)
574
    {
575
        $pm_type = $payment_method->type_obj();
576
        if (! $pm_type instanceof EE_PMT_Base) {
577
            return null;
578
        }
579
        $billing_info = $this->get_post_meta($this->get_billing_info_postmeta_name($payment_method), true);
580
        if (! $billing_info) {
581
            return null;
582
        }
583
        $billing_form = $pm_type->billing_form();
584
        if ($billing_form instanceof EE_Form_Section_Proper) {
585
            $billing_form->receive_form_submission(array($billing_form->name() => $billing_info), false);
586
        }
587
        return $billing_form;
588
    }
589
590
591
    /**
592
     * Gets the postmeta key that holds this attendee's billing info for the
593
     * specified payment method
594
     *
595
     * @param EE_Payment_Method $payment_method
596
     * @return string
597
     */
598
    public function get_billing_info_postmeta_name($payment_method)
599
    {
600
        if ($payment_method->type_obj() instanceof EE_PMT_Base) {
601
            return 'billing_info_' . $payment_method->type_obj()->system_name();
602
        } else {
603
            return null;
604
        }
605
    }
606
607
608
    /**
609
     * Saves the billing info to the attendee. @see EE_Attendee::billing_info_for_payment_method() which is used to
610
     * retrieve it
611
     *
612
     * @param EE_Billing_Attendee_Info_Form $billing_form
613
     * @param EE_Payment_Method             $payment_method
614
     * @return boolean
615
     */
616
    public function save_and_clean_billing_info_for_payment_method($billing_form, $payment_method)
617
    {
618
        if (! $billing_form instanceof EE_Billing_Attendee_Info_Form) {
619
            EE_Error::add_error(__('Cannot save billing info because there is none.', 'event_espresso'));
620
            return false;
621
        }
622
        $billing_form->clean_sensitive_data();
623
        return update_post_meta($this->ID(), $this->get_billing_info_postmeta_name($payment_method),
624
            $billing_form->input_values(true));
625
    }
626
627
628
    /**
629
     * Return the link to the admin details for the object.
630
     *
631
     * @return string
632
     */
633
    public function get_admin_details_link()
634
    {
635
        return $this->get_admin_edit_link();
636
    }
637
638
639
    /**
640
     * Returns the link to the editor for the object.  Sometimes this is the same as the details.
641
     *
642
     * @return string
643
     */
644 View Code Duplication
    public function get_admin_edit_link()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
645
    {
646
        EE_Registry::instance()->load_helper('URL');
647
        return EEH_URL::add_query_args_and_nonce(
648
            array(
649
                'page'   => 'espresso_registrations',
650
                'action' => 'edit_attendee',
651
                'post'   => $this->ID(),
652
            ),
653
            admin_url('admin.php')
654
        );
655
    }
656
657
658
    /**
659
     * Returns the link to a settings page for the object.
660
     *
661
     * @return string
662
     */
663
    public function get_admin_settings_link()
664
    {
665
        return $this->get_admin_edit_link();
666
    }
667
668
669
    /**
670
     * Returns the link to the "overview" for the object (typically the "list table" view).
671
     *
672
     * @return string
673
     */
674 View Code Duplication
    public function get_admin_overview_link()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
675
    {
676
        EE_Registry::instance()->load_helper('URL');
677
        return EEH_URL::add_query_args_and_nonce(
678
            array(
679
                'page'   => 'espresso_registrations',
680
                'action' => 'contact_list',
681
            ),
682
            admin_url('admin.php')
683
        );
684
    }
685
686
687
}
688
689
/* End of file EE_Attendee.class.php */
690
/* Location: /includes/classes/EE_Attendee.class.php */
691