Completed
Push — master ( 935ca4...f651ab )
by
unknown
08:26
created

Contact::getDescription()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 4
rs 10
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
     */
688
    protected $defaultInAccounts;
689
690
    public function __construct()
691
    {
692
        parent::__construct();
693
694
        $this->groups   = new ArrayCollection();
695
        $this->accounts = new ArrayCollection();
696
        $this->emails   = new ArrayCollection();
697
        $this->phones   = new ArrayCollection();
698
        $this->defaultInAccounts = new ArrayCollection();
699
    }
700
701
    public function __clone()
702
    {
703
        parent::__clone();
704
705
        if ($this->groups) {
706
            $this->groups = clone $this->groups;
707
        }
708
        if ($this->accounts) {
709
            $this->accounts = clone $this->accounts;
710
        }
711
        if ($this->emails) {
712
            $this->emails = clone $this->emails;
713
        }
714
        if ($this->phones) {
715
            $this->phones = clone $this->phones;
716
        }
717
        if ($this->defaultInAccounts) {
718
            $this->defaultInAccounts = clone $this->defaultInAccounts;
719
        }
720
    }
721
722
    /**
723
     * Get entity class name.
724
     * TODO: Remove this temporary solution for get 'view' route in twig after EntityConfigBundle is finished
725
     * @return string
726
     */
727
    public function getClass()
728
    {
729
        return 'OroCRM\Bundle\ContactBundle\Entity\Contact';
730
    }
731
732
    /**
733
     * Get names of fields contain email addresses
734
     *
735
     * @return string[]|null
736
     */
737
    public function getEmailFields()
738
    {
739
        return null;
740
    }
741
742
    /**
743
     * @param User $assignedTo
744
     *
745
     * @return Contact
746
     */
747
    public function setAssignedTo($assignedTo)
748
    {
749
        $this->assignedTo = $assignedTo;
750
751
        return $this;
752
    }
753
754
    /**
755
     * @return User
756
     */
757
    public function getAssignedTo()
758
    {
759
        return $this->assignedTo;
760
    }
761
762
    /**
763
     * @param string $description
764
     *
765
     * @return Contact
766
     */
767
    public function setDescription($description)
768
    {
769
        $this->description = $description;
770
771
        return $this;
772
    }
773
774
    /**
775
     * @return string
776
     */
777
    public function getDescription()
778
    {
779
        return $this->description;
780
    }
781
782
    /**
783
     * @param Source $source
784
     *
785
     * @return Contact
786
     */
787
    public function setSource($source)
788
    {
789
        $this->source = $source;
790
791
        return $this;
792
    }
793
794
    /**
795
     * @return Source
796
     */
797
    public function getSource()
798
    {
799
        return $this->source;
800
    }
801
802
    /**
803
     * @param Method $method
804
     *
805
     * @return Contact
806
     */
807
    public function setMethod($method)
808
    {
809
        $this->method = $method;
810
811
        return $this;
812
    }
813
814
    /**
815
     * @return Method
816
     */
817
    public function getMethod()
818
    {
819
        return $this->method;
820
    }
821
822
    /**
823
     * @param User $owningUser
824
     *
825
     * @return Contact
826
     */
827
    public function setOwner($owningUser)
828
    {
829
        $this->owner = $owningUser;
830
831
        return $this;
832
    }
833
834
    /**
835
     * @return User
836
     */
837
    public function getOwner()
838
    {
839
        return $this->owner;
840
    }
841
842
    /**
843
     * @param Contact $reportsTo
844
     *
845
     * @return Contact
846
     */
847
    public function setReportsTo($reportsTo)
848
    {
849
        $this->reportsTo = $reportsTo;
850
851
        return $this;
852
    }
853
854
    /**
855
     * @return Contact
856
     */
857
    public function getReportsTo()
858
    {
859
        return $this->reportsTo;
860
    }
861
862
    /**
863
     * @param string $jobTitle
864
     *
865
     * @return Contact
866
     */
867
    public function setJobTitle($jobTitle)
868
    {
869
        $this->jobTitle = $jobTitle;
870
871
        return $this;
872
    }
873
874
    /**
875
     * @return string
876
     */
877
    public function getJobTitle()
878
    {
879
        return $this->jobTitle;
880
    }
881
882
    /**
883
     * @param string $fax
884
     *
885
     * @return Contact
886
     */
887
    public function setFax($fax)
888
    {
889
        $this->fax = $fax;
890
891
        return $this;
892
    }
893
894
    /**
895
     * @return string
896
     */
897
    public function getFax()
898
    {
899
        return $this->fax;
900
    }
901
902
    /**
903
     * @param string $skype
904
     *
905
     * @return Contact
906
     */
907
    public function setSkype($skype)
908
    {
909
        $this->skype = $skype;
910
911
        return $this;
912
    }
913
914
    /**
915
     * @return string
916
     */
917
    public function getSkype()
918
    {
919
        return $this->skype;
920
    }
921
922
    /**
923
     * @param string $facebookUrl
924
     *
925
     * @return Contact
926
     */
927
    public function setFacebook($facebookUrl)
928
    {
929
        $this->facebook = $facebookUrl;
930
931
        return $this;
932
    }
933
934
    /**
935
     * @return string
936
     */
937
    public function getFacebook()
938
    {
939
        return $this->facebook;
940
    }
941
942
    /**
943
     * @param string $googlePlusUrl
944
     *
945
     * @return Contact
946
     */
947
    public function setGooglePlus($googlePlusUrl)
948
    {
949
        $this->googlePlus = $googlePlusUrl;
950
951
        return $this;
952
    }
953
954
    /**
955
     * @return string
956
     */
957
    public function getGooglePlus()
958
    {
959
        return $this->googlePlus;
960
    }
961
962
    /**
963
     * @param string $linkedInUrl
964
     *
965
     * @return Contact
966
     */
967
    public function setLinkedIn($linkedInUrl)
968
    {
969
        $this->linkedIn = $linkedInUrl;
970
971
        return $this;
972
    }
973
974
    /**
975
     * @return string
976
     */
977
    public function getLinkedIn()
978
    {
979
        return $this->linkedIn;
980
    }
981
982
    /**
983
     * @param string $twitterUrl
984
     *
985
     * @return Contact
986
     */
987
    public function setTwitter($twitterUrl)
988
    {
989
        $this->twitter = $twitterUrl;
990
991
        return $this;
992
    }
993
994
    /**
995
     * @return string
996
     */
997
    public function getTwitter()
998
    {
999
        return $this->twitter;
1000
    }
1001
1002
    /**
1003
     * Set emails.
1004
     *
1005
     * This method could not be named setEmails because of bug CRM-253.
1006
     *
1007
     * @param Collection|ContactEmail[] $emails
1008
     *
1009
     * @return Contact
1010
     */
1011
    public function resetEmails($emails)
1012
    {
1013
        $this->emails->clear();
1014
1015
        foreach ($emails as $email) {
1016
            $this->addEmail($email);
1017
        }
1018
1019
        return $this;
1020
    }
1021
1022
    /**
1023
     * Add email
1024
     *
1025
     * @param ContactEmail $email
1026
     *
1027
     * @return Contact
1028
     */
1029
    public function addEmail(ContactEmail $email)
1030
    {
1031
        if (!$this->emails->contains($email)) {
1032
            $this->emails->add($email);
1033
            $email->setOwner($this);
1034
        }
1035
1036
        return $this;
1037
    }
1038
1039
    /**
1040
     * Remove email
1041
     *
1042
     * @param ContactEmail $email
1043
     *
1044
     * @return Contact
1045
     */
1046
    public function removeEmail(ContactEmail $email)
1047
    {
1048
        if ($this->emails->contains($email)) {
1049
            $this->emails->removeElement($email);
1050
        }
1051
1052
        return $this;
1053
    }
1054
1055
    /**
1056
     * Get emails
1057
     *
1058
     * @return Collection|ContactEmail[]
1059
     */
1060
    public function getEmails()
1061
    {
1062
        return $this->emails;
1063
    }
1064
1065
    /**
1066
     * {@inheritdoc}
1067
     */
1068
    public function getEmail()
1069
    {
1070
        $primaryEmail = $this->getPrimaryEmail();
1071
        if (!$primaryEmail) {
1072
            return null;
1073
        }
1074
1075
        return $primaryEmail->getEmail();
1076
    }
1077
1078
    /**
1079
     * @param ContactEmail $email
1080
     * @return bool
1081
     */
1082
    public function hasEmail(ContactEmail $email)
1083
    {
1084
        return $this->getEmails()->contains($email);
1085
    }
1086
1087
    /**
1088
     * Gets primary email if it's available.
1089
     *
1090
     * @return ContactEmail|null
1091
     */
1092
    public function getPrimaryEmail()
1093
    {
1094
        $result = null;
1095
1096
        foreach ($this->getEmails() as $email) {
1097
            if ($email->isPrimary()) {
1098
                $result = $email;
1099
                break;
1100
            }
1101
        }
1102
1103
        return $result;
1104
    }
1105
1106
    /**
1107
     * @param ContactEmail $email
1108
     * @return Contact
1109
     */
1110
    public function setPrimaryEmail(ContactEmail $email)
1111
    {
1112
        if ($this->hasEmail($email)) {
1113
            $email->setPrimary(true);
1114
            foreach ($this->getEmails() as $otherEmail) {
1115
                if (!$email->isEqual($otherEmail)) {
1116
                    $otherEmail->setPrimary(false);
1117
                }
1118
            }
1119
        }
1120
1121
        return $this;
1122
    }
1123
1124
    /**
1125
     * Set phones.
1126
     *
1127
     * This method could not be named setPhones because of bug CRM-253.
1128
     *
1129
     * @param Collection|ContactPhone[] $phones
1130
     *
1131
     * @return Contact
1132
     */
1133
    public function resetPhones($phones)
1134
    {
1135
        $this->phones->clear();
1136
1137
        foreach ($phones as $phone) {
1138
            $this->addPhone($phone);
1139
        }
1140
1141
        return $this;
1142
    }
1143
1144
    /**
1145
     * Add phone
1146
     *
1147
     * @param ContactPhone $phone
1148
     *
1149
     * @return Contact
1150
     */
1151
    public function addPhone(ContactPhone $phone)
1152
    {
1153
        if (!$this->phones->contains($phone)) {
1154
            $this->phones->add($phone);
1155
            $phone->setOwner($this);
1156
        }
1157
1158
        return $this;
1159
    }
1160
1161
    /**
1162
     * Remove phone
1163
     *
1164
     * @param ContactPhone $phone
1165
     *
1166
     * @return Contact
1167
     */
1168
    public function removePhone(ContactPhone $phone)
1169
    {
1170
        if ($this->phones->contains($phone)) {
1171
            $this->phones->removeElement($phone);
1172
        }
1173
1174
        return $this;
1175
    }
1176
1177
    /**
1178
     * Get phones
1179
     *
1180
     * @return Collection|ContactPhone[]
1181
     */
1182
    public function getPhones()
1183
    {
1184
        return $this->phones;
1185
    }
1186
1187
    /**
1188
     * @param ContactPhone $phone
1189
     * @return bool
1190
     */
1191
    public function hasPhone(ContactPhone $phone)
1192
    {
1193
        return $this->getPhones()->contains($phone);
1194
    }
1195
1196
    /**
1197
     * Gets primary phone if it's available.
1198
     *
1199
     * @return ContactPhone|null
1200
     */
1201
    public function getPrimaryPhone()
1202
    {
1203
        $result = null;
1204
1205
        foreach ($this->getPhones() as $phone) {
1206
            if ($phone->isPrimary()) {
1207
                $result = $phone;
1208
                break;
1209
            }
1210
        }
1211
1212
        return $result;
1213
    }
1214
1215
    /**
1216
     * @param ContactPhone $phone
1217
     * @return Contact
1218
     */
1219
    public function setPrimaryPhone(ContactPhone $phone)
1220
    {
1221
        if ($this->hasPhone($phone)) {
1222
            $phone->setPrimary(true);
1223
            foreach ($this->getPhones() as $otherPhone) {
1224
                if (!$phone->isEqual($otherPhone)) {
1225
                    $otherPhone->setPrimary(false);
1226
                }
1227
            }
1228
        }
1229
1230
        return $this;
1231
    }
1232
1233
    /**
1234
     * Add address
1235
     *
1236
     * @param AbstractAddress $address
1237
     *
1238
     * @return BasePerson
1239
     */
1240 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...
1241
    {
1242
        /** @var ContactAddress $address */
1243
        if (!$this->addresses->contains($address)) {
1244
            $this->addresses->add($address);
1245
            $address->setOwner($this);
1246
        }
1247
1248
        return $this;
1249
    }
1250
1251
    /**
1252
     * Gets primary address if it's available.
1253
     *
1254
     * @return ContactAddress|null
1255
     */
1256
    public function getPrimaryAddress()
1257
    {
1258
        $result = null;
1259
1260
        /** @var ContactAddress $address */
1261
        foreach ($this->getAddresses() as $address) {
1262
            if ($address->isPrimary()) {
1263
                $result = $address;
1264
                break;
1265
            }
1266
        }
1267
1268
        return $result;
1269
    }
1270
1271
    /**
1272
     * @param ContactAddress $address
1273
     *
1274
     * @return Contact
1275
     */
1276 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...
1277
    {
1278
        if ($this->hasAddress($address)) {
1279
            $address->setPrimary(true);
1280
            /** @var ContactAddress $otherAddress */
1281
            foreach ($this->getAddresses() as $otherAddress) {
1282
                if (!$address->isEqual($otherAddress)) {
1283
                    $otherAddress->setPrimary(false);
1284
                }
1285
            }
1286
        }
1287
1288
        return $this;
1289
    }
1290
1291
    /**
1292
     * Gets address type if it's available.
1293
     *
1294
     * @param ContactAddress $address
1295
     * @param AddressType    $addressType
1296
     *
1297
     * @return Contact
1298
     */
1299 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...
1300
    {
1301
        if ($this->hasAddress($address)) {
1302
            $address->addType($addressType);
1303
            /** @var ContactAddress $otherAddress */
1304
            foreach ($this->getAddresses() as $otherAddress) {
1305
                if (!$address->isEqual($otherAddress)) {
1306
                    $otherAddress->removeType($addressType);
1307
                }
1308
            }
1309
        }
1310
1311
        return $this;
1312
    }
1313
1314
    /**
1315
     * Gets one address that has specified type.
1316
     *
1317
     * @param AddressType $type
1318
     *
1319
     * @return ContactAddress|null
1320
     */
1321
    public function getAddressByType(AddressType $type)
1322
    {
1323
        return $this->getAddressByTypeName($type->getName());
1324
    }
1325
1326
    /**
1327
     * Gets one address that has specified type name.
1328
     *
1329
     * @param string $typeName
1330
     *
1331
     * @return ContactAddress|null
1332
     */
1333
    public function getAddressByTypeName($typeName)
1334
    {
1335
        $result = null;
1336
1337
        /** @var ContactAddress $address */
1338
        foreach ($this->getAddresses() as $address) {
1339
            if ($address->hasTypeWithName($typeName)) {
1340
                $result = $address;
1341
                break;
1342
            }
1343
        }
1344
1345
        return $result;
1346
    }
1347
1348
    /**
1349
     * Get group labels separated with comma.
1350
     *
1351
     * @return string
1352
     */
1353
    public function getGroupLabelsAsString()
1354
    {
1355
        return implode(', ', $this->getGroupLabels());
1356
    }
1357
1358
    /**
1359
     * Get list of group labels
1360
     *
1361
     * @return array
1362
     */
1363
    public function getGroupLabels()
1364
    {
1365
        $result = [];
1366
1367
        /** @var Group $group */
1368
        foreach ($this->getGroups() as $group) {
1369
            $result[] = $group->getLabel();
1370
        }
1371
1372
        return $result;
1373
    }
1374
1375
    /**
1376
     * Gets the groups related to contact
1377
     *
1378
     * @return Group[]|Collection
1379
     */
1380
    public function getGroups()
1381
    {
1382
        return $this->groups;
1383
    }
1384
1385
    /**
1386
     * Add specified group
1387
     *
1388
     * @param Group $group
1389
     *
1390
     * @return Contact
1391
     */
1392
    public function addGroup(Group $group)
1393
    {
1394
        if (!$this->getGroups()->contains($group)) {
1395
            $this->getGroups()->add($group);
1396
        }
1397
1398
        return $this;
1399
    }
1400
1401
    /**
1402
     * Remove specified group
1403
     *
1404
     * @param Group $group
1405
     *
1406
     * @return Contact
1407
     */
1408
    public function removeGroup(Group $group)
1409
    {
1410
        if ($this->getGroups()->contains($group)) {
1411
            $this->getGroups()->removeElement($group);
1412
        }
1413
1414
        return $this;
1415
    }
1416
1417
    /**
1418
     * Get accounts collection
1419
     *
1420
     * @return Collection|Account[]
1421
     */
1422
    public function getAccounts()
1423
    {
1424
        return $this->accounts;
1425
    }
1426
1427
    /**
1428
     * Add specified account
1429
     *
1430
     * @param Account $account
1431
     *
1432
     * @return Contact
1433
     */
1434
    public function addAccount(Account $account)
1435
    {
1436
        if (!$this->getAccounts()->contains($account)) {
1437
            $this->getAccounts()->add($account);
1438
            $account->addContact($this);
1439
        }
1440
1441
        return $this;
1442
    }
1443
1444
    /**
1445
     * Remove specified account
1446
     *
1447
     * @param Account $account
1448
     *
1449
     * @return Contact
1450
     */
1451
    public function removeAccount(Account $account)
1452
    {
1453
        if ($this->getAccounts()->contains($account)) {
1454
            $this->getAccounts()->removeElement($account);
1455
            $account->removeContact($this);
1456
        }
1457
1458
        return $this;
1459
    }
1460
1461
    /**
1462
     * @return bool
1463
     */
1464
    public function hasAccounts()
1465
    {
1466
        return count($this->accounts) > 0;
1467
    }
1468
1469
    /**
1470
     * @param \Oro\Bundle\UserBundle\Entity\User $createdBy
1471
     *
1472
     * @return Contact
1473
     */
1474
    public function setCreatedBy($createdBy)
1475
    {
1476
        $this->createdBy = $createdBy;
1477
1478
        return $this;
1479
    }
1480
1481
    /**
1482
     * @return \Oro\Bundle\UserBundle\Entity\User
1483
     */
1484
    public function getCreatedBy()
1485
    {
1486
        return $this->createdBy;
1487
    }
1488
1489
    /**
1490
     * @param \Oro\Bundle\UserBundle\Entity\User $updatedBy
1491
     *
1492
     * @return Contact
1493
     */
1494
    public function setUpdatedBy($updatedBy)
1495
    {
1496
        $this->updatedBy = $updatedBy;
1497
1498
        return $this;
1499
    }
1500
1501
    /**
1502
     * @return \Oro\Bundle\UserBundle\Entity\User
1503
     */
1504
    public function getUpdatedBy()
1505
    {
1506
        return $this->updatedBy;
1507
    }
1508
1509
    /**
1510
     * @return string
1511
     */
1512
    public function __toString()
1513
    {
1514
        $name = $this->getNamePrefix() . ' '
1515
            . $this->getFirstName() . ' '
1516
            . $this->getMiddleName() . ' '
1517
            . $this->getLastName() . ' '
1518
            . $this->getNameSuffix();
1519
        $name = preg_replace('/ +/', ' ', $name);
1520
1521
        return (string)trim($name);
1522
    }
1523
1524
    /**
1525
     * Set organization
1526
     *
1527
     * @param Organization $organization
1528
     * @return Contact
1529
     */
1530
    public function setOrganization(Organization $organization = null)
1531
    {
1532
        $this->organization = $organization;
1533
1534
        return $this;
1535
    }
1536
1537
    /**
1538
     * Get organization
1539
     *
1540
     * @return Organization
1541
     */
1542
    public function getOrganization()
1543
    {
1544
        return $this->organization;
1545
    }
1546
1547
    /**
1548
     * @param Account $account
1549
     *
1550
     * @return $this
1551
     */
1552 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...
1553
    {
1554
        if (!$this->defaultInAccounts->contains($account)) {
1555
            $this->defaultInAccounts->add($account);
1556
            $account->setDefaultContact($this);
1557
        }
1558
1559
        return $this;
1560
    }
1561
1562
    /**
1563
     * @param Account $account
1564
     *
1565
     * @return $this
1566
     */
1567 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...
1568
    {
1569
        $this->defaultInAccounts->removeElement($account);
1570
        if ($account->getDefaultContact() === $this) {
1571
            $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...
1572
        }
1573
1574
        return $this;
1575
    }
1576
1577
    /**
1578
     * @return Account[]|Collection
1579
     */
1580
    public function getDefaultInAccounts()
1581
    {
1582
        return $this->defaultInAccounts;
1583
    }
1584
}
1585