1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Victoire\Bundle\BusinessEntityBundle\Entity; |
4
|
|
|
|
5
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
6
|
|
|
use Doctrine\ORM\Mapping as ORM; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* The business Entity. |
10
|
|
|
* |
11
|
|
|
* @ORM\Entity(repositoryClass="Victoire\Bundle\BusinessEntityBundle\Entity\BusinessEntityRepository") |
12
|
|
|
* @ORM\Table("vic_business_entity") |
13
|
|
|
* @ORM\InheritanceType("SINGLE_TABLE") |
14
|
|
|
* @ORM\DiscriminatorColumn(name="type", type="string") |
15
|
|
|
*/ |
16
|
|
|
abstract class BusinessEntity |
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* @var int |
20
|
|
|
* |
21
|
|
|
* @ORM\Column(name="id", type="integer") |
22
|
|
|
* @ORM\Id |
23
|
|
|
* @ORM\GeneratedValue(strategy="AUTO") |
24
|
|
|
*/ |
25
|
|
|
protected $id; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @var string |
29
|
|
|
* |
30
|
|
|
* @ORM\Column(name="name", type="string", length=255) |
31
|
|
|
*/ |
32
|
|
|
protected $name; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @var BusinessProperty[] |
36
|
|
|
* |
37
|
|
|
* @ORM\OneToMany(targetEntity="Victoire\Bundle\BusinessEntityBundle\Entity\BusinessProperty", mappedBy="businessEntity", cascade={"persist", "remove"}) |
38
|
|
|
*/ |
39
|
|
|
protected $businessProperties; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @var array |
43
|
|
|
* |
44
|
|
|
* @ORM\Column(name="availableWidgets", type="text") |
45
|
|
|
*/ |
46
|
|
|
protected $availableWidgets; |
47
|
|
|
|
48
|
|
|
protected $disable = false; |
49
|
|
|
|
50
|
|
|
public function __construct() |
51
|
|
|
{ |
52
|
|
|
$this->businessProperties = new ArrayCollection(); |
|
|
|
|
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Get the id. |
57
|
|
|
* |
58
|
|
|
* @return string The id |
59
|
|
|
*/ |
60
|
|
|
public function getId() |
61
|
|
|
{ |
62
|
|
|
return $this->id; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* Get the name. |
67
|
|
|
* |
68
|
|
|
* @return string The name |
69
|
|
|
*/ |
70
|
|
|
public function getName() |
71
|
|
|
{ |
72
|
|
|
return $this->name; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* Set the name. |
77
|
|
|
* |
78
|
|
|
* @param string $name |
79
|
|
|
*/ |
80
|
|
|
public function setName($name) |
81
|
|
|
{ |
82
|
|
|
$this->name = $name; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* Add a business property. |
87
|
|
|
* |
88
|
|
|
* @param BusinessProperty $businessProperty |
89
|
|
|
*/ |
90
|
|
|
public function addBusinessProperty(BusinessProperty $businessProperty) |
91
|
|
|
{ |
92
|
|
|
$this->businessProperties->add($businessProperty); |
|
|
|
|
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* Get the business properties. |
97
|
|
|
* |
98
|
|
|
* @return array The business properties |
99
|
|
|
*/ |
100
|
|
|
public function getBusinessProperties() |
101
|
|
|
{ |
102
|
|
|
return $this->businessProperties; |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* Get a business property by name. |
107
|
|
|
* |
108
|
|
|
* @return BusinessProperty|null The business property |
109
|
|
|
*/ |
110
|
|
|
public function getBusinessPropertyByName($name) |
111
|
|
|
{ |
112
|
|
|
foreach ($this->businessProperties as $businessProperty) { |
113
|
|
|
if ($businessProperty->getName() == $name) { |
114
|
|
|
return $businessProperty; |
115
|
|
|
} |
116
|
|
|
} |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* Get the business properties. |
121
|
|
|
* |
122
|
|
|
* @return array The business properties |
123
|
|
|
*/ |
124
|
|
|
public function setBusinessProperties($businessProperties) |
125
|
|
|
{ |
126
|
|
|
return $this->businessProperties = $businessProperties; |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
/** |
130
|
|
|
* Get the business properties by type. |
131
|
|
|
* |
132
|
|
|
* @param string $type |
133
|
|
|
* |
134
|
|
|
* @return BusinessProperty[] The businnes properties |
135
|
|
|
*/ |
136
|
|
|
public function getBusinessPropertiesByType($type) |
137
|
|
|
{ |
138
|
|
|
if (!is_array($type)) { |
139
|
|
|
$type = [$type]; |
140
|
|
|
} |
141
|
|
|
$bp = new ArrayCollection(); |
142
|
|
|
foreach ($this->getBusinessProperties() as $property) { |
143
|
|
|
if (count(array_diff($type, $property->getTypes())) == 0) { |
144
|
|
|
$bp->add($property); |
145
|
|
|
} |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
return $bp; |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
/** |
152
|
|
|
* Get the business properties names by type. |
153
|
|
|
* |
154
|
|
|
* @param string $type |
|
|
|
|
155
|
|
|
* |
156
|
|
|
* @return ArrayCollection The businnes properties |
157
|
|
|
*/ |
158
|
|
|
public function getBusinessParameters() |
159
|
|
|
{ |
160
|
|
|
$bp = new ArrayCollection(); |
161
|
|
|
/** @var BusinessProperty $property */ |
162
|
|
|
foreach ($this->getBusinessProperties() as $property) { |
163
|
|
|
if ($property->hasType('businessParameter')) { |
164
|
|
|
$bp->add($property); |
165
|
|
|
} |
166
|
|
|
} |
167
|
|
|
|
168
|
|
|
return $bp; |
169
|
|
|
} |
170
|
|
|
|
171
|
|
|
/** |
172
|
|
|
* Get the business identifiers. |
173
|
|
|
* |
174
|
|
|
* @param string $type |
|
|
|
|
175
|
|
|
* |
176
|
|
|
* @return ArrayCollection The businnes properties |
177
|
|
|
*/ |
178
|
|
|
public function getBusinessIdentifiers() |
179
|
|
|
{ |
180
|
|
|
$bp = new ArrayCollection(); |
181
|
|
|
/** @var BusinessProperty $property */ |
182
|
|
|
foreach ($this->getBusinessProperties() as $property) { |
183
|
|
|
if ($property->hasType('businessIdentifier')) { |
184
|
|
|
$bp->add($property); |
185
|
|
|
} |
186
|
|
|
} |
187
|
|
|
if ($bp->count() < 1) { |
188
|
|
|
throw new \Exception(sprintf('The businessEntity %s must have at lease one businessIdentifier property', $this->name)); |
189
|
|
|
} |
190
|
|
|
|
191
|
|
|
return $bp; |
192
|
|
|
} |
193
|
|
|
|
194
|
|
|
/** |
195
|
|
|
* @return array |
196
|
|
|
*/ |
197
|
|
|
public function getAvailableWidgets() |
198
|
|
|
{ |
199
|
|
|
return unserialize($this->availableWidgets); |
200
|
|
|
} |
201
|
|
|
|
202
|
|
|
/** |
203
|
|
|
* @param array $availableWidgets |
204
|
|
|
*/ |
205
|
|
|
public function setAvailableWidgets($availableWidgets) |
206
|
|
|
{ |
207
|
|
|
$this->availableWidgets = serialize($availableWidgets); |
|
|
|
|
208
|
|
|
} |
209
|
|
|
|
210
|
|
|
/** |
211
|
|
|
* @return bool |
212
|
|
|
*/ |
213
|
|
|
public function isDisable() |
214
|
|
|
{ |
215
|
|
|
return $this->disable; |
216
|
|
|
} |
217
|
|
|
|
218
|
|
|
/** |
219
|
|
|
* @param bool $disable |
220
|
|
|
*/ |
221
|
|
|
public function setDisable($disable) |
222
|
|
|
{ |
223
|
|
|
$this->disable = $disable; |
224
|
|
|
} |
225
|
|
|
|
226
|
|
|
public function __toString() |
227
|
|
|
{ |
228
|
|
|
return $this->name; |
229
|
|
|
} |
230
|
|
|
} |
231
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..