1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace OroCRM\Bundle\SalesBundle\ImportExport\TemplateFixture; |
4
|
|
|
|
5
|
|
|
use Oro\Bundle\EntityExtendBundle\Tools\ExtendHelper; |
6
|
|
|
use Oro\Bundle\ImportExportBundle\TemplateFixture\AbstractTemplateRepository; |
7
|
|
|
use Oro\Bundle\ImportExportBundle\TemplateFixture\TemplateFixtureInterface; |
8
|
|
|
use OroCRM\Bundle\SalesBundle\Entity\Lead; |
9
|
|
|
use OroCRM\Bundle\SalesBundle\Entity\LeadPhone; |
10
|
|
|
use OroCRM\Bundle\SalesBundle\Entity\LeadEmail; |
11
|
|
|
use OroCRM\Bundle\SalesBundle\Entity\LeadAddress; |
12
|
|
|
|
13
|
|
|
class LeadFixture extends AbstractTemplateRepository implements TemplateFixtureInterface |
14
|
|
|
{ |
15
|
|
|
/** |
16
|
|
|
* {@inheritdoc} |
17
|
|
|
*/ |
18
|
|
|
public function getEntityClass() |
19
|
|
|
{ |
20
|
|
|
return 'OroCRM\Bundle\SalesBundle\Entity\Lead'; |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* {@inheritdoc} |
25
|
|
|
*/ |
26
|
|
|
public function getData() |
27
|
|
|
{ |
28
|
|
|
return $this->getEntityData('Jerry Coleman'); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* {@inheritdoc} |
33
|
|
|
*/ |
34
|
|
|
protected function createEntity($key) |
35
|
|
|
{ |
36
|
|
|
return new Lead(); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @param string $key |
41
|
|
|
* @param Lead $entity |
42
|
|
|
*/ |
43
|
|
|
public function fillEntityData($key, $entity) |
44
|
|
|
{ |
45
|
|
|
$userRepo = $this->templateManager->getEntityRepository('Oro\Bundle\UserBundle\Entity\User'); |
46
|
|
|
$customerRepo = $this->templateManager->getEntityRepository('OroCRM\Bundle\SalesBundle\Entity\B2bCustomer'); |
47
|
|
|
$contactRepo = $this->templateManager->getEntityRepository('OroCRM\Bundle\ContactBundle\Entity\Contact'); |
48
|
|
|
$channelRepo = $this->templateManager->getEntityRepository('OroCRM\Bundle\ChannelBundle\Entity\Channel'); |
49
|
|
|
$organizationRepo = $this->templateManager |
50
|
|
|
->getEntityRepository('Oro\Bundle\OrganizationBundle\Entity\Organization'); |
51
|
|
|
|
52
|
|
|
switch ($key) { |
53
|
|
|
case 'Jerry Coleman': |
54
|
|
|
$entity->setName('Oro Inc. Lead Name'); |
55
|
|
|
$entity->setCompanyName('Oro Inc.'); |
56
|
|
|
$entity->setOwner($userRepo->getEntity('John Doo')); |
57
|
|
|
$entity->setOrganization($organizationRepo->getEntity('default')); |
58
|
|
|
$entity->setDataChannel($channelRepo->getEntity('Sales channel|b2b')); |
59
|
|
|
$entity->setCreatedAt(new \DateTime()); |
60
|
|
|
$entity->setUpdatedAt(new \DateTime()); |
61
|
|
|
$entity->setCustomer($customerRepo->getEntity('Jerry Coleman')); |
62
|
|
|
$entity->setContact($contactRepo->getEntity('Jerry Coleman')); |
63
|
|
|
$entity->addEmail(new LeadEmail('[email protected]')); |
64
|
|
|
$primaryAddress = $this->createLeadAddress(1); |
65
|
|
|
$entity->addAddress($primaryAddress); |
66
|
|
|
$entity->addAddress($this->createLeadAddress(2)); |
67
|
|
|
$entity->addAddress($this->createLeadAddress(3)); |
68
|
|
|
$entity->setPrimaryAddress($primaryAddress); |
69
|
|
|
$entity->setNamePrefix('Mr.'); |
70
|
|
|
$entity->setFirstName('Jerry'); |
71
|
|
|
$entity->setLastName('Coleman'); |
72
|
|
|
$entity->setNameSuffix('Jr.'); |
73
|
|
|
|
74
|
|
|
$statusName = 'New'; |
75
|
|
|
$className = ExtendHelper::buildEnumValueClassName(Lead::INTERNAL_STATUS_CODE); |
76
|
|
|
$id = ExtendHelper::buildEnumValueId($statusName); |
77
|
|
|
$entity->setStatus(new $className($id, $statusName)); |
|
|
|
|
78
|
|
|
|
79
|
|
|
$entity->setJobTitle('Manager'); |
80
|
|
|
$entity->addPhone(new LeadPhone('585-255-1127')); |
81
|
|
|
$entity->addPhone(new LeadPhone('978-242-1314')); |
82
|
|
|
$entity->setWebsite('http://orocrm.com'); |
83
|
|
|
$entity->setNumberOfEmployees(100); |
84
|
|
|
$entity->setIndustry('Internet'); |
85
|
|
|
|
86
|
|
|
return; |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
parent::fillEntityData($key, $entity); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* @param int $number |
94
|
|
|
* |
95
|
|
|
* @return LeadAddress |
96
|
|
|
* |
97
|
|
|
* @throws \LogicException |
98
|
|
|
*/ |
99
|
|
|
protected function createLeadAddress($number) |
100
|
|
|
{ |
101
|
|
|
$countryRepo = $this->templateManager |
102
|
|
|
->getEntityRepository('Oro\Bundle\AddressBundle\Entity\Country'); |
103
|
|
|
$regionRepo = $this->templateManager |
104
|
|
|
->getEntityRepository('Oro\Bundle\AddressBundle\Entity\Region'); |
105
|
|
|
|
106
|
|
|
$entity = new LeadAddress(); |
107
|
|
|
|
108
|
|
|
$entity |
109
|
|
|
->setFirstName('Jerry') |
110
|
|
|
->setLastName('Coleman'); |
111
|
|
|
|
112
|
|
View Code Duplication |
switch ($number) { |
|
|
|
|
113
|
|
|
case 1: |
114
|
|
|
$entity |
115
|
|
|
->setCity('Rochester') |
116
|
|
|
->setStreet('1215 Caldwell Road') |
117
|
|
|
->setPostalCode('14608') |
118
|
|
|
->setRegion($regionRepo->getEntity('NY')) |
119
|
|
|
->setCountry($countryRepo->getEntity('US')); |
120
|
|
|
break; |
121
|
|
|
case 2: |
122
|
|
|
$entity |
123
|
|
|
->setCity('New York') |
124
|
|
|
->setStreet('4677 Pallet Street') |
125
|
|
|
->setPostalCode('10011') |
126
|
|
|
->setRegion($regionRepo->getEntity('NY')) |
127
|
|
|
->setCountry($countryRepo->getEntity('US')); |
128
|
|
|
break; |
129
|
|
|
case 3: |
130
|
|
|
$entity |
131
|
|
|
->setCity('New York') |
132
|
|
|
->setStreet('52 Jarvisville Road') |
133
|
|
|
->setPostalCode('11590') |
134
|
|
|
->setRegion($regionRepo->getEntity('NY')) |
135
|
|
|
->setCountry($countryRepo->getEntity('US')); |
136
|
|
|
break; |
137
|
|
|
default: |
138
|
|
|
throw new \LogicException( |
139
|
|
|
sprintf( |
140
|
|
|
'Undefined lead address. Number: %d.', |
141
|
|
|
$number |
142
|
|
|
) |
143
|
|
|
); |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
return $entity; |
147
|
|
|
} |
148
|
|
|
} |
149
|
|
|
|
Let’s take a look at an example:
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.
Available Fixes
Change the type-hint for the parameter:
Add an additional type-check:
Add the method to the parent class: