Completed
Push — 1.9 ( 30c3e5...ca8b96 )
by
unknown
42:25
created

Contact::getSkype()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace OroCRM\Bundle\ContactBundle\Entity;
4
5
use BeSimple\SoapBundle\ServiceDefinition\Annotation as Soap;
6
7
use Doctrine\Common\Collections\ArrayCollection;
8
use Doctrine\Common\Collections\Collection;
9
use Doctrine\ORM\Mapping as ORM;
10
11
use Oro\Bundle\AddressBundle\Entity\AbstractAddress;
12
use Oro\Bundle\AddressBundle\Entity\AddressType;
13
use Oro\Bundle\BusinessEntitiesBundle\Entity\BasePerson;
14
use Oro\Bundle\DataAuditBundle\Metadata\Annotation as Oro;
15
use Oro\Bundle\EmailBundle\Entity\EmailOwnerInterface;
16
use Oro\Bundle\EntityConfigBundle\Metadata\Annotation\Config;
17
use Oro\Bundle\EntityConfigBundle\Metadata\Annotation\ConfigField;
18
use Oro\Bundle\OrganizationBundle\Entity\Organization;
19
use Oro\Bundle\UserBundle\Entity\User;
20
21
use OroCRM\Bundle\AccountBundle\Entity\Account;
22
use OroCRM\Bundle\ContactBundle\Model\ExtendContact;
23
24
/**
25
 * @SuppressWarnings(PHPMD.TooManyMethods)
26
 * @SuppressWarnings(PHPMD.ExcessivePublicCount)
27
 * @SuppressWarnings(PHPMD.ExcessiveClassComplexity)
28
 * @SuppressWarnings(PHPMD.ExcessiveClassLength)
29
 * @SuppressWarnings(PHPMD.TooManyFields)
30
 *
31
 * @ORM\Entity(repositoryClass="OroCRM\Bundle\ContactBundle\Entity\Repository\ContactRepository")
32
 * @ORM\Table(
33
 *      name="orocrm_contact",
34
 *      indexes={
35
 *          @ORM\Index(name="contact_name_idx",columns={"last_name", "first_name"}),
36
 *          @ORM\Index(name="contact_updated_at_idx",columns={"updatedAt"}),
37
 *      }
38
 * )
39
 * @ORM\HasLifecycleCallbacks()
40
 * @Oro\Loggable
41
 * @Config(
42
 *      routeName="orocrm_contact_index",
43
 *      routeView="orocrm_contact_view",
44
 *      defaultValues={
45
 *          "entity"={
46
 *              "icon"="icon-group",
47
 *              "contact_information"={
48
 *                  "email"={
49
 *                      {"fieldName"="primaryEmail"}
50
 *                  },
51
 *                  "phone"={
52
 *                      {"fieldName"="primaryPhone"}
53
 *                  }
54
 *              }
55
 *          },
56
 *          "ownership"={
57
 *              "owner_type"="USER",
58
 *              "owner_field_name"="owner",
59
 *              "owner_column_name"="user_owner_id",
60
 *              "organization_field_name"="organization",
61
 *              "organization_column_name"="organization_id"
62
 *          },
63
 *          "security"={
64
 *              "type"="ACL",
65
 *              "group_name"=""
66
 *          },
67
 *          "form"={
68
 *              "form_type"="orocrm_contact_select",
69
 *              "grid_name"="contacts-select-grid",
70
 *          },
71
 *          "dataaudit"={
72
 *              "auditable"=true
73
 *          },
74
 *          "grid"={
75
 *              "default"="contacts-grid",
76
 *              "context"="contacts-for-context-grid"
77
 *          },
78
 *          "tag"={
79
 *              "enabled"=true
80
 *          }
81
 *      }
82
 * )
83
 */
84
class Contact extends ExtendContact implements EmailOwnerInterface
85
{
86
    /*
87
     * Fields have to be duplicated here to enable dataaudit and soap transformation only for contact
88
     */
89
    /**
90
     * @var int
91
     *
92
     * @ORM\Id
93
     * @ORM\Column(type="integer", name="id")
94
     * @ORM\GeneratedValue(strategy="AUTO")
95
     * @Soap\ComplexType("int", nillable=true)
96
     * @ConfigField(
97
     *      defaultValues={
98
     *          "importexport"={
99
     *              "order"=10
100
     *          }
101
     *      }
102
     * )
103
     */
104
    protected $id;
105
106
    /**
107
     * @var string
108
     *
109
     * @ORM\Column(name="name_prefix", type="string", length=255, nullable=true)
110
     * @Soap\ComplexType("string", nillable=true)
111
     * @Oro\Versioned
112
     * @ConfigField(
113
     *      defaultValues={
114
     *          "dataaudit"={
115
     *              "auditable"=true
116
     *          },
117
     *          "importexport"={
118
     *              "order"=20
119
     *          }
120
     *      }
121
     * )
122
     */
123
    protected $namePrefix;
124
125
    /**
126
     * @var string
127
     *
128
     * @ORM\Column(name="first_name", type="string", length=255)
129
     * @Soap\ComplexType("string")
130
     * @Oro\Versioned
131
     * @ConfigField(
132
     *      defaultValues={
133
     *          "dataaudit"={
134
     *              "auditable"=true
135
     *          },
136
     *          "importexport"={
137
     *              "identity"=true,
138
     *              "order"=30
139
     *          }
140
     *      }
141
     * )
142
     */
143
    protected $firstName;
144
145
    /**
146
     * @var string
147
     *
148
     * @ORM\Column(name="middle_name", type="string", length=255, nullable=true)
149
     * @Soap\ComplexType("string", nillable=true)
150
     * @Oro\Versioned
151
     * @ConfigField(
152
     *      defaultValues={
153
     *          "dataaudit"={
154
     *              "auditable"=true
155
     *          },
156
     *          "importexport"={
157
     *              "order"=40
158
     *          }
159
     *      }
160
     * )
161
     */
162
    protected $middleName;
163
164
    /**
165
     * @var string
166
     *
167
     * @ORM\Column(name="last_name", type="string", length=255)
168
     * @Soap\ComplexType("string")
169
     * @Oro\Versioned
170
     * @ConfigField(
171
     *      defaultValues={
172
     *          "dataaudit"={
173
     *              "auditable"=true
174
     *          },
175
     *          "importexport"={
176
     *              "identity"=true,
177
     *              "order"=50
178
     *          }
179
     *      }
180
     * )
181
     */
182
    protected $lastName;
183
184
    /**
185
     * @var string
186
     *
187
     * @ORM\Column(name="name_suffix", type="string", length=255, nullable=true)
188
     * @Soap\ComplexType("string", nillable=true)
189
     * @Oro\Versioned
190
     * @ConfigField(
191
     *      defaultValues={
192
     *          "dataaudit"={
193
     *              "auditable"=true
194
     *          },
195
     *          "importexport"={
196
     *              "order"=60
197
     *          }
198
     *      }
199
     * )
200
     */
201
    protected $nameSuffix;
202
203
    /**
204
     * @var string
205
     *
206
     * @ORM\Column(name="gender", type="string", length=8, nullable=true)
207
     * @Soap\ComplexType("string", nillable=true)
208
     * @Oro\Versioned
209
     * @ConfigField(
210
     *      defaultValues={
211
     *          "dataaudit"={
212
     *              "auditable"=true
213
     *          },
214
     *          "importexport"={
215
     *              "order"=70
216
     *          }
217
     *      }
218
     * )
219
     */
220
    protected $gender;
221
222
    /**
223
     * @var \DateTime
224
     *
225
     * @ORM\Column(name="birthday", type="date", nullable=true)
226
     * @Soap\ComplexType("date", nillable=true)
227
     * @Oro\Versioned
228
     * @ConfigField(
229
     *      defaultValues={
230
     *          "dataaudit"={
231
     *              "auditable"=true
232
     *          },
233
     *          "importexport"={
234
     *              "order"=160
235
     *          }
236
     *      }
237
     * )
238
     */
239
    protected $birthday;
240
241
    /**
242
     * @var string
243
     *
244
     * @ORM\Column(name="description", type="text", nullable=true)
245
     * @Soap\ComplexType("string", nillable=true)
246
     * @Oro\Versioned
247
     * @ConfigField(
248
     *      defaultValues={
249
     *          "dataaudit"={
250
     *              "auditable"=true
251
     *          },
252
     *          "importexport"={
253
     *              "order"=80
254
     *          }
255
     *      }
256
     * )
257
     */
258
    protected $description;
259
260
    /**
261
     * @var Source
262
     *
263
     * @ORM\ManyToOne(targetEntity="OroCRM\Bundle\ContactBundle\Entity\Source")
264
     * @ORM\JoinColumn(name="source_name", referencedColumnName="name")
265
     * @Oro\Versioned
266
     * @ConfigField(
267
     *      defaultValues={
268
     *          "dataaudit"={
269
     *              "auditable"=true
270
     *          },
271
     *          "importexport"={
272
     *              "order"=170
273
     *          }
274
     *      }
275
     * )
276
     **/
277
    protected $source;
278
279
    /**
280
     * @var Method
281
     *
282
     * @ORM\ManyToOne(targetEntity="OroCRM\Bundle\ContactBundle\Entity\Method")
283
     * @ORM\JoinColumn(name="method_name", referencedColumnName="name")
284
     * @Oro\Versioned
285
     * @ConfigField(
286
     *      defaultValues={
287
     *          "dataaudit"={
288
     *              "auditable"=true
289
     *          },
290
     *          "importexport"={
291
     *              "order"=180
292
     *          }
293
     *      }
294
     * )
295
     **/
296
    protected $method;
297
298
    /**
299
     * @var User
300
     *
301
     * @ORM\ManyToOne(targetEntity="Oro\Bundle\UserBundle\Entity\User")
302
     * @ORM\JoinColumn(name="user_owner_id", referencedColumnName="id", onDelete="SET NULL")
303
     * @Soap\ComplexType("string", nillable=true)
304
     * @Oro\Versioned
305
     * @ConfigField(
306
     *      defaultValues={
307
     *          "dataaudit"={
308
     *              "auditable"=true
309
     *          },
310
     *          "importexport"={
311
     *              "order"=190,
312
     *              "short"=true
313
     *          }
314
     *      }
315
     * )
316
     */
317
    protected $owner;
318
319
    /**
320
     * @var User
321
     *
322
     * @ORM\ManyToOne(targetEntity="Oro\Bundle\UserBundle\Entity\User")
323
     * @ORM\JoinColumn(name="assigned_to_user_id", referencedColumnName="id", onDelete="SET NULL")
324
     * @Oro\Versioned
325
     * @ConfigField(
326
     *      defaultValues={
327
     *          "dataaudit"={
328
     *              "auditable"=true
329
     *          },
330
     *          "importexport"={
331
     *              "order"=200,
332
     *              "short"=true
333
     *          }
334
     *      }
335
     * )
336
     */
337
    protected $assignedTo;
338
339
    /**
340
     * @var Contact
341
     *
342
     * @ORM\ManyToOne(targetEntity="OroCRM\Bundle\ContactBundle\Entity\Contact")
343
     * @ORM\JoinColumn(name="reports_to_contact_id", referencedColumnName="id", onDelete="SET NULL")
344
     * @Oro\Versioned
345
     * @ConfigField(
346
     *      defaultValues={
347
     *          "dataaudit"={
348
     *              "auditable"=true
349
     *          },
350
     *          "importexport"={
351
     *              "excluded"=true
352
     *          }
353
     *      }
354
     * )
355
     */
356
    protected $reportsTo;
357
358
    /**
359
     * @var string
360
     *
361
     * @ORM\Column(name="job_title", type="string", length=255, nullable=true)
362
     * @Soap\ComplexType("string", nillable=true)
363
     * @Oro\Versioned
364
     * @ConfigField(
365
     *      defaultValues={
366
     *          "dataaudit"={
367
     *              "auditable"=true
368
     *          },
369
     *          "importexport"={
370
     *              "order"=90
371
     *          }
372
     *      }
373
     * )
374
     */
375
    protected $jobTitle;
376
377
    /**
378
     * @var string
379
     *
380
     * @ORM\Column(name="email", type="string", length=255, nullable=true)
381
     * @Oro\Versioned
382
     * @ConfigField(
383
     *      defaultValues={
384
     *          "dataaudit"={
385
     *              "auditable"=true
386
     *          },
387
     *          "entity"={
388
     *              "contact_information"="email"
389
     *          }
390
     *      }
391
     * )
392
     */
393
    protected $email;
394
395
    /**
396
     * @var Collection
397
     *
398
     * @ORM\OneToMany(targetEntity="OroCRM\Bundle\ContactBundle\Entity\ContactEmail",
399
     *    mappedBy="owner", cascade={"all"}, orphanRemoval=true
400
     * )
401
     * @ORM\OrderBy({"primary" = "DESC"})
402
     * @Soap\ComplexType("OroCRM\Bundle\ContactBundle\Entity\ContactEmail[]", nillable=true)
403
     * @ConfigField(
404
     *      defaultValues={
405
     *          "importexport"={
406
     *              "order"=210
407
     *          },
408
     *          "dataaudit"={
409
     *              "auditable"=true
410
     *          }
411
     *      }
412
     * )
413
     */
414
    protected $emails;
415
416
    /**
417
     * @var Collection
418
     *
419
     * @ORM\OneToMany(targetEntity="OroCRM\Bundle\ContactBundle\Entity\ContactPhone", mappedBy="owner",
420
     *    mappedBy="owner", cascade={"all"}, orphanRemoval=true
421
     * ))
422
     * @ORM\OrderBy({"primary" = "DESC"})
423
     * @Soap\ComplexType("OroCRM\Bundle\ContactBundle\Entity\ContactPhone[]", nillable=true)
424
     * @ConfigField(
425
     *      defaultValues={
426
     *          "importexport"={
427
     *              "order"=220
428
     *          },
429
     *          "dataaudit"={
430
     *              "auditable"=true
431
     *          }
432
     *      }
433
     * )
434
     */
435
    protected $phones;
436
437
    /**
438
     * @var string
439
     *
440
     * @ORM\Column(name="fax", type="string", length=255, nullable=true)
441
     * @Soap\ComplexType("string", nillable=true)
442
     * @Oro\Versioned
443
     * @ConfigField(
444
     *      defaultValues={
445
     *          "dataaudit"={
446
     *              "auditable"=true
447
     *          },
448
     *          "importexport"={
449
     *              "order"=100
450
     *          }
451
     *      }
452
     * )
453
     */
454
    protected $fax;
455
456
    /**
457
     * @var string
458
     *
459
     * @ORM\Column(name="skype", type="string", length=255, nullable=true)
460
     * @Soap\ComplexType("string", nillable=true)
461
     * @Oro\Versioned
462
     * @ConfigField(
463
     *      defaultValues={
464
     *          "dataaudit"={
465
     *              "auditable"=true
466
     *          },
467
     *          "importexport"={
468
     *              "order"=110
469
     *          }
470
     *      }
471
     * )
472
     */
473
    protected $skype;
474
475
    /**
476
     * @var string
477
     *
478
     * @ORM\Column(name="twitter", type="string", length=255, nullable=true)
479
     * @Soap\ComplexType("string", nillable=true)
480
     * @Oro\Versioned
481
     * @ConfigField(
482
     *      defaultValues={
483
     *          "dataaudit"={
484
     *              "auditable"=true
485
     *          },
486
     *          "importexport"={
487
     *              "order"=120
488
     *          }
489
     *      }
490
     * )
491
     */
492
    protected $twitter;
493
494
    /**
495
     * @var string
496
     *
497
     * @ORM\Column(name="facebook", type="string", length=255, nullable=true)
498
     * @Soap\ComplexType("string", nillable=true)
499
     * @Oro\Versioned
500
     * @ConfigField(
501
     *      defaultValues={
502
     *          "dataaudit"={
503
     *              "auditable"=true
504
     *          },
505
     *          "importexport"={
506
     *              "order"=130
507
     *          }
508
     *      }
509
     * )
510
     */
511
    protected $facebook;
512
513
    /**
514
     * @var string
515
     *
516
     * @ORM\Column(name="google_plus", type="string", length=255, nullable=true)
517
     * @Soap\ComplexType("string", nillable=true)
518
     * @Oro\Versioned
519
     * @ConfigField(
520
     *      defaultValues={
521
     *          "dataaudit"={
522
     *              "auditable"=true
523
     *          },
524
     *          "importexport"={
525
     *              "order"=140
526
     *          }
527
     *      }
528
     * )
529
     */
530
    protected $googlePlus;
531
532
    /**
533
     * @var string
534
     *
535
     * @ORM\Column(name="linkedin", type="string", length=255, nullable=true)
536
     * @Soap\ComplexType("string", nillable=true)
537
     * @Oro\Versioned
538
     * @ConfigField(
539
     *      defaultValues={
540
     *          "dataaudit"={
541
     *              "auditable"=true
542
     *          },
543
     *          "importexport"={
544
     *              "order"=150
545
     *          }
546
     *      }
547
     * )
548
     */
549
    protected $linkedIn;
550
551
    /**
552
     * @var Collection
553
     *
554
     * @ORM\OneToMany(targetEntity="OroCRM\Bundle\ContactBundle\Entity\ContactAddress",
555
     *    mappedBy="owner", cascade={"all"}, orphanRemoval=true
556
     * )
557
     * @ORM\OrderBy({"primary" = "DESC"})
558
     * @ConfigField(
559
     *      defaultValues={
560
     *          "importexport"={
561
     *              "full"=true,
562
     *              "order"=250
563
     *          },
564
     *          "dataaudit"={
565
     *              "auditable"=true
566
     *          }
567
     *      }
568
     * )
569
     */
570
    protected $addresses;
571
572
    /**
573
     * @var Collection
574
     *
575
     * @ORM\ManyToMany(targetEntity="OroCRM\Bundle\ContactBundle\Entity\Group")
576
     * @ORM\JoinTable(name="orocrm_contact_to_contact_grp",
577
     *      joinColumns={@ORM\JoinColumn(name="contact_id", referencedColumnName="id", onDelete="CASCADE")},
578
     *      inverseJoinColumns={@ORM\JoinColumn(name="contact_group_id", referencedColumnName="id", onDelete="CASCADE")}
579
     * )
580
     * @ConfigField(
581
     *      defaultValues={
582
     *          "importexport"={
583
     *              "order"=230,
584
     *              "short"=true
585
     *          }
586
     *      }
587
     * )
588
     */
589
    protected $groups;
590
591
    /**
592
     * @var Collection
593
     *
594
     * @ORM\ManyToMany(targetEntity="OroCRM\Bundle\AccountBundle\Entity\Account", mappedBy="contacts")
595
     * @ORM\JoinTable(name="orocrm_account_to_contact")
596
     * @ConfigField(
597
     *      defaultValues={
598
     *          "importexport"={
599
     *              "order"=240,
600
     *              "short"=true
601
     *          }
602
     *      }
603
     * )
604
     */
605
    protected $accounts;
606
607
    /**
608
     * @var User
609
     *
610
     * @ORM\ManyToOne(targetEntity="Oro\Bundle\UserBundle\Entity\User")
611
     * @ORM\JoinColumn(name="created_by_user_id", referencedColumnName="id", onDelete="SET NULL")
612
     * @ConfigField(
613
     *      defaultValues={
614
     *          "importexport"={
615
     *              "excluded"=true
616
     *          }
617
     *      }
618
     * )
619
     */
620
    protected $createdBy;
621
622
    /**
623
     * @var User
624
     *
625
     * @ORM\ManyToOne(targetEntity="Oro\Bundle\UserBundle\Entity\User")
626
     * @ORM\JoinColumn(name="updated_by_user_id", referencedColumnName="id", onDelete="SET NULL")
627
     * @ConfigField(
628
     *      defaultValues={
629
     *          "importexport"={
630
     *              "excluded"=true
631
     *          }
632
     *      }
633
     * )
634
     */
635
    protected $updatedBy;
636
637
    /**
638
     * @var \DateTime $created
639
     *
640
     * @ORM\Column(type="datetime")
641
     * @Soap\ComplexType("dateTime", nillable=true)
642
     * @ConfigField(
643
     *      defaultValues={
644
     *          "entity"={
645
     *              "label"="oro.ui.created_at"
646
     *          },
647
     *          "importexport"={
648
     *              "excluded"=true
649
     *          }
650
     *      }
651
     * )
652
     */
653
    protected $createdAt;
654
655
    /**
656
     * @var \DateTime $updated
657
     *
658
     * @ORM\Column(type="datetime")
659
     * @Soap\ComplexType("dateTime", nillable=true)
660
     * @ConfigField(
661
     *      defaultValues={
662
     *          "entity"={
663
     *              "label"="oro.ui.updated_at"
664
     *          },
665
     *          "importexport"={
666
     *              "excluded"=true
667
     *          }
668
     *      }
669
     * )
670
     */
671
    protected $updatedAt;
672
673
    /**
674
     * @var Organization
675
     *
676
     * @ORM\ManyToOne(targetEntity="Oro\Bundle\OrganizationBundle\Entity\Organization")
677
     * @ORM\JoinColumn(name="organization_id", referencedColumnName="id", onDelete="SET NULL")
678
     */
679
    protected $organization;
680
681
    /**
682
     * @var Account[]|Collection
683
     *
684
     * @ORM\OneToMany(targetEntity="OroCRM\Bundle\AccountBundle\Entity\Account",
685
     *    mappedBy="defaultContact", cascade={"persist"}
686
     * )
687
     * @ConfigField(
688
     *      defaultValues={
689
     *          "importexport"={
690
     *              "order"=240
691
     *          }
692
     *      }
693
     * )
694
     */
695
    protected $defaultInAccounts;
696
697
    public function __construct()
698
    {
699
        parent::__construct();
700
701
        $this->groups   = new ArrayCollection();
702
        $this->accounts = new ArrayCollection();
703
        $this->emails   = new ArrayCollection();
704
        $this->phones   = new ArrayCollection();
705
        $this->defaultInAccounts = new ArrayCollection();
706
    }
707
708
    public function __clone()
709
    {
710
        parent::__clone();
711
712
        if ($this->groups) {
713
            $this->groups = clone $this->groups;
714
        }
715
        if ($this->accounts) {
716
            $this->accounts = clone $this->accounts;
717
        }
718
        if ($this->emails) {
719
            $this->emails = clone $this->emails;
720
        }
721
        if ($this->phones) {
722
            $this->phones = clone $this->phones;
723
        }
724
        if ($this->defaultInAccounts) {
725
            $this->defaultInAccounts = clone $this->defaultInAccounts;
726
        }
727
    }
728
729
    /**
730
     * Get entity class name.
731
     * TODO: Remove this temporary solution for get 'view' route in twig after EntityConfigBundle is finished
732
     * @return string
733
     */
734
    public function getClass()
735
    {
736
        return 'OroCRM\Bundle\ContactBundle\Entity\Contact';
737
    }
738
739
    /**
740
     * Get names of fields contain email addresses
741
     *
742
     * @return string[]|null
743
     */
744
    public function getEmailFields()
745
    {
746
        return null;
747
    }
748
749
    /**
750
     * @param User $assignedTo
751
     *
752
     * @return Contact
753
     */
754
    public function setAssignedTo($assignedTo)
755
    {
756
        $this->assignedTo = $assignedTo;
757
758
        return $this;
759
    }
760
761
    /**
762
     * @return User
763
     */
764
    public function getAssignedTo()
765
    {
766
        return $this->assignedTo;
767
    }
768
769
    /**
770
     * @param string $description
771
     *
772
     * @return Contact
773
     */
774
    public function setDescription($description)
775
    {
776
        $this->description = $description;
777
778
        return $this;
779
    }
780
781
    /**
782
     * @return string
783
     */
784
    public function getDescription()
785
    {
786
        return $this->description;
787
    }
788
789
    /**
790
     * @param Source $source
791
     *
792
     * @return Contact
793
     */
794
    public function setSource($source)
795
    {
796
        $this->source = $source;
797
798
        return $this;
799
    }
800
801
    /**
802
     * @return Source
803
     */
804
    public function getSource()
805
    {
806
        return $this->source;
807
    }
808
809
    /**
810
     * @param Method $method
811
     *
812
     * @return Contact
813
     */
814
    public function setMethod($method)
815
    {
816
        $this->method = $method;
817
818
        return $this;
819
    }
820
821
    /**
822
     * @return Method
823
     */
824
    public function getMethod()
825
    {
826
        return $this->method;
827
    }
828
829
    /**
830
     * @param User $owningUser
831
     *
832
     * @return Contact
833
     */
834
    public function setOwner($owningUser)
835
    {
836
        $this->owner = $owningUser;
837
838
        return $this;
839
    }
840
841
    /**
842
     * @return User
843
     */
844
    public function getOwner()
845
    {
846
        return $this->owner;
847
    }
848
849
    /**
850
     * @param Contact $reportsTo
851
     *
852
     * @return Contact
853
     */
854
    public function setReportsTo($reportsTo)
855
    {
856
        $this->reportsTo = $reportsTo;
857
858
        return $this;
859
    }
860
861
    /**
862
     * @return Contact
863
     */
864
    public function getReportsTo()
865
    {
866
        return $this->reportsTo;
867
    }
868
869
    /**
870
     * @param string $jobTitle
871
     *
872
     * @return Contact
873
     */
874
    public function setJobTitle($jobTitle)
875
    {
876
        $this->jobTitle = $jobTitle;
877
878
        return $this;
879
    }
880
881
    /**
882
     * @return string
883
     */
884
    public function getJobTitle()
885
    {
886
        return $this->jobTitle;
887
    }
888
889
    /**
890
     * @param string $fax
891
     *
892
     * @return Contact
893
     */
894
    public function setFax($fax)
895
    {
896
        $this->fax = $fax;
897
898
        return $this;
899
    }
900
901
    /**
902
     * @return string
903
     */
904
    public function getFax()
905
    {
906
        return $this->fax;
907
    }
908
909
    /**
910
     * @param string $skype
911
     *
912
     * @return Contact
913
     */
914
    public function setSkype($skype)
915
    {
916
        $this->skype = $skype;
917
918
        return $this;
919
    }
920
921
    /**
922
     * @return string
923
     */
924
    public function getSkype()
925
    {
926
        return $this->skype;
927
    }
928
929
    /**
930
     * @param string $facebookUrl
931
     *
932
     * @return Contact
933
     */
934
    public function setFacebook($facebookUrl)
935
    {
936
        $this->facebook = $facebookUrl;
937
938
        return $this;
939
    }
940
941
    /**
942
     * @return string
943
     */
944
    public function getFacebook()
945
    {
946
        return $this->facebook;
947
    }
948
949
    /**
950
     * @param string $googlePlusUrl
951
     *
952
     * @return Contact
953
     */
954
    public function setGooglePlus($googlePlusUrl)
955
    {
956
        $this->googlePlus = $googlePlusUrl;
957
958
        return $this;
959
    }
960
961
    /**
962
     * @return string
963
     */
964
    public function getGooglePlus()
965
    {
966
        return $this->googlePlus;
967
    }
968
969
    /**
970
     * @param string $linkedInUrl
971
     *
972
     * @return Contact
973
     */
974
    public function setLinkedIn($linkedInUrl)
975
    {
976
        $this->linkedIn = $linkedInUrl;
977
978
        return $this;
979
    }
980
981
    /**
982
     * @return string
983
     */
984
    public function getLinkedIn()
985
    {
986
        return $this->linkedIn;
987
    }
988
989
    /**
990
     * @param string $twitterUrl
991
     *
992
     * @return Contact
993
     */
994
    public function setTwitter($twitterUrl)
995
    {
996
        $this->twitter = $twitterUrl;
997
998
        return $this;
999
    }
1000
1001
    /**
1002
     * @return string
1003
     */
1004
    public function getTwitter()
1005
    {
1006
        return $this->twitter;
1007
    }
1008
1009
    /**
1010
     * Set emails.
1011
     *
1012
     * This method could not be named setEmails because of bug CRM-253.
1013
     *
1014
     * @param Collection|ContactEmail[] $emails
1015
     *
1016
     * @return Contact
1017
     */
1018
    public function resetEmails($emails)
1019
    {
1020
        $this->emails->clear();
1021
1022
        foreach ($emails as $email) {
1023
            $this->addEmail($email);
1024
        }
1025
1026
        return $this;
1027
    }
1028
1029
    /**
1030
     * Add email
1031
     *
1032
     * @param ContactEmail $email
1033
     *
1034
     * @return Contact
1035
     */
1036
    public function addEmail(ContactEmail $email)
1037
    {
1038
        if (!$this->emails->contains($email)) {
1039
            $this->emails->add($email);
1040
            $email->setOwner($this);
1041
        }
1042
1043
        return $this;
1044
    }
1045
1046
    /**
1047
     * Remove email
1048
     *
1049
     * @param ContactEmail $email
1050
     *
1051
     * @return Contact
1052
     */
1053
    public function removeEmail(ContactEmail $email)
1054
    {
1055
        if ($this->emails->contains($email)) {
1056
            $this->emails->removeElement($email);
1057
        }
1058
1059
        return $this;
1060
    }
1061
1062
    /**
1063
     * Get emails
1064
     *
1065
     * @return Collection|ContactEmail[]
1066
     */
1067
    public function getEmails()
1068
    {
1069
        return $this->emails;
1070
    }
1071
1072
    /**
1073
     * {@inheritdoc}
1074
     */
1075
    public function getEmail()
1076
    {
1077
        $primaryEmail = $this->getPrimaryEmail();
1078
        if (!$primaryEmail) {
1079
            return null;
1080
        }
1081
1082
        return $primaryEmail->getEmail();
1083
    }
1084
1085
    /**
1086
     * @param ContactEmail $email
1087
     * @return bool
1088
     */
1089
    public function hasEmail(ContactEmail $email)
1090
    {
1091
        return $this->getEmails()->contains($email);
1092
    }
1093
1094
    /**
1095
     * Gets primary email if it's available.
1096
     *
1097
     * @return ContactEmail|null
1098
     */
1099
    public function getPrimaryEmail()
1100
    {
1101
        $result = null;
1102
1103
        foreach ($this->getEmails() as $email) {
1104
            if ($email->isPrimary()) {
1105
                $result = $email;
1106
                break;
1107
            }
1108
        }
1109
1110
        return $result;
1111
    }
1112
1113
    /**
1114
     * @param ContactEmail $email
1115
     * @return Contact
1116
     */
1117
    public function setPrimaryEmail(ContactEmail $email)
1118
    {
1119
        if ($this->hasEmail($email)) {
1120
            $email->setPrimary(true);
1121
            foreach ($this->getEmails() as $otherEmail) {
1122
                if (!$email->isEqual($otherEmail)) {
1123
                    $otherEmail->setPrimary(false);
1124
                }
1125
            }
1126
        }
1127
1128
        return $this;
1129
    }
1130
1131
    /**
1132
     * Set phones.
1133
     *
1134
     * This method could not be named setPhones because of bug CRM-253.
1135
     *
1136
     * @param Collection|ContactPhone[] $phones
1137
     *
1138
     * @return Contact
1139
     */
1140
    public function resetPhones($phones)
1141
    {
1142
        $this->phones->clear();
1143
1144
        foreach ($phones as $phone) {
1145
            $this->addPhone($phone);
1146
        }
1147
1148
        return $this;
1149
    }
1150
1151
    /**
1152
     * Add phone
1153
     *
1154
     * @param ContactPhone $phone
1155
     *
1156
     * @return Contact
1157
     */
1158
    public function addPhone(ContactPhone $phone)
1159
    {
1160
        if (!$this->phones->contains($phone)) {
1161
            $this->phones->add($phone);
1162
            $phone->setOwner($this);
1163
        }
1164
1165
        return $this;
1166
    }
1167
1168
    /**
1169
     * Remove phone
1170
     *
1171
     * @param ContactPhone $phone
1172
     *
1173
     * @return Contact
1174
     */
1175
    public function removePhone(ContactPhone $phone)
1176
    {
1177
        if ($this->phones->contains($phone)) {
1178
            $this->phones->removeElement($phone);
1179
        }
1180
1181
        return $this;
1182
    }
1183
1184
    /**
1185
     * Get phones
1186
     *
1187
     * @return Collection|ContactPhone[]
1188
     */
1189
    public function getPhones()
1190
    {
1191
        return $this->phones;
1192
    }
1193
1194
    /**
1195
     * @param ContactPhone $phone
1196
     * @return bool
1197
     */
1198
    public function hasPhone(ContactPhone $phone)
1199
    {
1200
        return $this->getPhones()->contains($phone);
1201
    }
1202
1203
    /**
1204
     * Gets primary phone if it's available.
1205
     *
1206
     * @return ContactPhone|null
1207
     */
1208
    public function getPrimaryPhone()
1209
    {
1210
        $result = null;
1211
1212
        foreach ($this->getPhones() as $phone) {
1213
            if ($phone->isPrimary()) {
1214
                $result = $phone;
1215
                break;
1216
            }
1217
        }
1218
1219
        return $result;
1220
    }
1221
1222
    /**
1223
     * @param ContactPhone $phone
1224
     * @return Contact
1225
     */
1226
    public function setPrimaryPhone(ContactPhone $phone)
1227
    {
1228
        if ($this->hasPhone($phone)) {
1229
            $phone->setPrimary(true);
1230
            foreach ($this->getPhones() as $otherPhone) {
1231
                if (!$phone->isEqual($otherPhone)) {
1232
                    $otherPhone->setPrimary(false);
1233
                }
1234
            }
1235
        }
1236
1237
        return $this;
1238
    }
1239
1240
    /**
1241
     * Add address
1242
     *
1243
     * @param AbstractAddress $address
1244
     *
1245
     * @return BasePerson
1246
     */
1247 View Code Duplication
    public function addAddress(AbstractAddress $address)
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...
1248
    {
1249
        /** @var ContactAddress $address */
1250
        if (!$this->addresses->contains($address)) {
1251
            $this->addresses->add($address);
1252
            $address->setOwner($this);
1253
        }
1254
1255
        return $this;
1256
    }
1257
1258
    /**
1259
     * Gets primary address if it's available.
1260
     *
1261
     * @return ContactAddress|null
1262
     */
1263
    public function getPrimaryAddress()
1264
    {
1265
        $result = null;
1266
1267
        /** @var ContactAddress $address */
1268
        foreach ($this->getAddresses() as $address) {
1269
            if ($address->isPrimary()) {
1270
                $result = $address;
1271
                break;
1272
            }
1273
        }
1274
1275
        return $result;
1276
    }
1277
1278
    /**
1279
     * @param ContactAddress $address
1280
     *
1281
     * @return Contact
1282
     */
1283 View Code Duplication
    public function setPrimaryAddress(ContactAddress $address)
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...
1284
    {
1285
        if ($this->hasAddress($address)) {
1286
            $address->setPrimary(true);
1287
            /** @var ContactAddress $otherAddress */
1288
            foreach ($this->getAddresses() as $otherAddress) {
1289
                if (!$address->isEqual($otherAddress)) {
1290
                    $otherAddress->setPrimary(false);
1291
                }
1292
            }
1293
        }
1294
1295
        return $this;
1296
    }
1297
1298
    /**
1299
     * Gets address type if it's available.
1300
     *
1301
     * @param ContactAddress $address
1302
     * @param AddressType    $addressType
1303
     *
1304
     * @return Contact
1305
     */
1306 View Code Duplication
    public function setAddressType(ContactAddress $address, AddressType $addressType)
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...
1307
    {
1308
        if ($this->hasAddress($address)) {
1309
            $address->addType($addressType);
1310
            /** @var ContactAddress $otherAddress */
1311
            foreach ($this->getAddresses() as $otherAddress) {
1312
                if (!$address->isEqual($otherAddress)) {
1313
                    $otherAddress->removeType($addressType);
1314
                }
1315
            }
1316
        }
1317
1318
        return $this;
1319
    }
1320
1321
    /**
1322
     * Gets one address that has specified type.
1323
     *
1324
     * @param AddressType $type
1325
     *
1326
     * @return ContactAddress|null
1327
     */
1328
    public function getAddressByType(AddressType $type)
1329
    {
1330
        return $this->getAddressByTypeName($type->getName());
1331
    }
1332
1333
    /**
1334
     * Gets one address that has specified type name.
1335
     *
1336
     * @param string $typeName
1337
     *
1338
     * @return ContactAddress|null
1339
     */
1340
    public function getAddressByTypeName($typeName)
1341
    {
1342
        $result = null;
1343
1344
        /** @var ContactAddress $address */
1345
        foreach ($this->getAddresses() as $address) {
1346
            if ($address->hasTypeWithName($typeName)) {
1347
                $result = $address;
1348
                break;
1349
            }
1350
        }
1351
1352
        return $result;
1353
    }
1354
1355
    /**
1356
     * Get group labels separated with comma.
1357
     *
1358
     * @return string
1359
     */
1360
    public function getGroupLabelsAsString()
1361
    {
1362
        return implode(', ', $this->getGroupLabels());
1363
    }
1364
1365
    /**
1366
     * Get list of group labels
1367
     *
1368
     * @return array
1369
     */
1370
    public function getGroupLabels()
1371
    {
1372
        $result = [];
1373
1374
        /** @var Group $group */
1375
        foreach ($this->getGroups() as $group) {
1376
            $result[] = $group->getLabel();
1377
        }
1378
1379
        return $result;
1380
    }
1381
1382
    /**
1383
     * Gets the groups related to contact
1384
     *
1385
     * @return Group[]|Collection
1386
     */
1387
    public function getGroups()
1388
    {
1389
        return $this->groups;
1390
    }
1391
1392
    /**
1393
     * Add specified group
1394
     *
1395
     * @param Group $group
1396
     *
1397
     * @return Contact
1398
     */
1399
    public function addGroup(Group $group)
1400
    {
1401
        if (!$this->getGroups()->contains($group)) {
1402
            $this->getGroups()->add($group);
1403
        }
1404
1405
        return $this;
1406
    }
1407
1408
    /**
1409
     * Remove specified group
1410
     *
1411
     * @param Group $group
1412
     *
1413
     * @return Contact
1414
     */
1415
    public function removeGroup(Group $group)
1416
    {
1417
        if ($this->getGroups()->contains($group)) {
1418
            $this->getGroups()->removeElement($group);
1419
        }
1420
1421
        return $this;
1422
    }
1423
1424
    /**
1425
     * Get accounts collection
1426
     *
1427
     * @return Collection|Account[]
1428
     */
1429
    public function getAccounts()
1430
    {
1431
        return $this->accounts;
1432
    }
1433
1434
    /**
1435
     * Add specified account
1436
     *
1437
     * @param Account $account
1438
     *
1439
     * @return Contact
1440
     */
1441
    public function addAccount(Account $account)
1442
    {
1443
        if (!$this->getAccounts()->contains($account)) {
1444
            $this->getAccounts()->add($account);
1445
            $account->addContact($this);
1446
        }
1447
1448
        return $this;
1449
    }
1450
1451
    /**
1452
     * Remove specified account
1453
     *
1454
     * @param Account $account
1455
     *
1456
     * @return Contact
1457
     */
1458
    public function removeAccount(Account $account)
1459
    {
1460
        if ($this->getAccounts()->contains($account)) {
1461
            $this->getAccounts()->removeElement($account);
1462
            $account->removeContact($this);
1463
        }
1464
1465
        return $this;
1466
    }
1467
1468
    /**
1469
     * @return bool
1470
     */
1471
    public function hasAccounts()
1472
    {
1473
        return count($this->accounts) > 0;
1474
    }
1475
1476
    /**
1477
     * @param \Oro\Bundle\UserBundle\Entity\User $createdBy
1478
     *
1479
     * @return Contact
1480
     */
1481
    public function setCreatedBy($createdBy)
1482
    {
1483
        $this->createdBy = $createdBy;
1484
1485
        return $this;
1486
    }
1487
1488
    /**
1489
     * @return \Oro\Bundle\UserBundle\Entity\User
1490
     */
1491
    public function getCreatedBy()
1492
    {
1493
        return $this->createdBy;
1494
    }
1495
1496
    /**
1497
     * @param \Oro\Bundle\UserBundle\Entity\User $updatedBy
1498
     *
1499
     * @return Contact
1500
     */
1501
    public function setUpdatedBy($updatedBy)
1502
    {
1503
        $this->updatedBy = $updatedBy;
1504
1505
        return $this;
1506
    }
1507
1508
    /**
1509
     * @return \Oro\Bundle\UserBundle\Entity\User
1510
     */
1511
    public function getUpdatedBy()
1512
    {
1513
        return $this->updatedBy;
1514
    }
1515
1516
    /**
1517
     * @return string
1518
     */
1519
    public function __toString()
1520
    {
1521
        $name = $this->getNamePrefix() . ' '
1522
            . $this->getFirstName() . ' '
1523
            . $this->getMiddleName() . ' '
1524
            . $this->getLastName() . ' '
1525
            . $this->getNameSuffix();
1526
        $name = preg_replace('/ +/', ' ', $name);
1527
1528
        return (string)trim($name);
1529
    }
1530
1531
    /**
1532
     * Set organization
1533
     *
1534
     * @param Organization $organization
1535
     * @return Contact
1536
     */
1537
    public function setOrganization(Organization $organization = null)
1538
    {
1539
        $this->organization = $organization;
1540
1541
        return $this;
1542
    }
1543
1544
    /**
1545
     * Get organization
1546
     *
1547
     * @return Organization
1548
     */
1549
    public function getOrganization()
1550
    {
1551
        return $this->organization;
1552
    }
1553
1554
    /**
1555
     * @param Account $account
1556
     *
1557
     * @return $this
1558
     */
1559 View Code Duplication
    public function addDefaultInAccount(Account $account)
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...
1560
    {
1561
        if (!$this->defaultInAccounts->contains($account)) {
1562
            $this->defaultInAccounts->add($account);
1563
            $account->setDefaultContact($this);
1564
        }
1565
1566
        return $this;
1567
    }
1568
1569
    /**
1570
     * @param Account $account
1571
     *
1572
     * @return $this
1573
     */
1574 View Code Duplication
    public function removeDefaultInAccount(Account $account)
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...
1575
    {
1576
        $this->defaultInAccounts->removeElement($account);
1577
        if ($account->getDefaultContact() === $this) {
1578
            $account->setDefaultContact(null);
0 ignored issues
show
Documentation introduced by
null is of type null, but the function expects a object<OroCRM\Bundle\Con...tBundle\Entity\Contact>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
1579
        }
1580
1581
        return $this;
1582
    }
1583
1584
    /**
1585
     * @return Account[]|Collection
1586
     */
1587
    public function getDefaultInAccounts()
1588
    {
1589
        return $this->defaultInAccounts;
1590
    }
1591
}
1592