|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Victoire\Bundle\WidgetBundle\Entity; |
|
4
|
|
|
|
|
5
|
|
|
use Doctrine\ORM\Mapping as ORM; |
|
6
|
|
|
use Victoire\Bundle\CoreBundle\Entity\View; |
|
7
|
|
|
use Victoire\Bundle\QueryBundle\Entity\Traits\QueryTrait; |
|
8
|
|
|
use Victoire\Bundle\WidgetBundle\Entity\Traits\StyleTrait; |
|
9
|
|
|
use Victoire\Bundle\WidgetBundle\Model\Widget as BaseWidget; |
|
10
|
|
|
use Victoire\Bundle\WidgetMapBundle\Entity\WidgetMap; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* Widget. |
|
14
|
|
|
* |
|
15
|
|
|
* @ORM\Table("vic_widget") |
|
16
|
|
|
* @ORM\Entity(repositoryClass="Victoire\Bundle\WidgetBundle\Repository\WidgetRepository") |
|
17
|
|
|
* @ORM\InheritanceType("JOINED") |
|
18
|
|
|
* @ORM\DiscriminatorColumn(name="type", type="string") |
|
19
|
|
|
*/ |
|
20
|
|
|
class Widget extends BaseWidget |
|
21
|
|
|
{ |
|
22
|
|
|
use StyleTrait; |
|
23
|
|
|
use QueryTrait; |
|
24
|
|
|
|
|
25
|
|
|
public function __construct() |
|
26
|
|
|
{ |
|
27
|
|
|
$this->childrenSlot = uniqid(); |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* @var int |
|
32
|
|
|
* |
|
33
|
|
|
* @ORM\Column(name="id", type="integer") |
|
34
|
|
|
* @ORM\Id |
|
35
|
|
|
* @ORM\GeneratedValue(strategy="AUTO") |
|
36
|
|
|
*/ |
|
37
|
|
|
protected $id; |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* @var string |
|
41
|
|
|
* |
|
42
|
|
|
* @ORM\Column(name="slot", type="string", length=255, nullable=true) |
|
43
|
|
|
*/ |
|
44
|
|
|
protected $slot; |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* @var string |
|
48
|
|
|
* |
|
49
|
|
|
* @ORM\Column(name="childrenSlot", type="string", length=100, nullable=true) |
|
50
|
|
|
*/ |
|
51
|
|
|
protected $childrenSlot; |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* @var string |
|
55
|
|
|
* |
|
56
|
|
|
* @ORM\Column(name="theme", type="string", length=255, nullable=true) |
|
57
|
|
|
*/ |
|
58
|
|
|
protected $theme; |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* @var string |
|
62
|
|
|
* |
|
63
|
|
|
* @ORM\Column(name="asynchronous", type="boolean", nullable=true) |
|
64
|
|
|
*/ |
|
65
|
|
|
protected $asynchronous; |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* @var string |
|
69
|
|
|
* |
|
70
|
|
|
* @ORM\Column(name="fields", type="array") |
|
71
|
|
|
*/ |
|
72
|
|
|
protected $fields = []; |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* @var string |
|
76
|
|
|
* |
|
77
|
|
|
* @ORM\Column(name="mode", type="string", length=255, nullable=false) |
|
78
|
|
|
*/ |
|
79
|
|
|
protected $mode = self::MODE_STATIC; |
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* Auto simple mode: joined entity. |
|
83
|
|
|
* |
|
84
|
|
|
* @var EntityProxy |
|
85
|
|
|
* |
|
86
|
|
|
* @ORM\ManyToOne(targetEntity="\Victoire\Bundle\CoreBundle\Entity\EntityProxy", inversedBy="widgets", cascade={"persist"}) |
|
87
|
|
|
* @ORM\JoinColumn(name="entityProxy_id", referencedColumnName="id", onDelete="CASCADE") |
|
88
|
|
|
*/ |
|
89
|
|
|
protected $entityProxy; |
|
90
|
|
|
|
|
91
|
|
|
/** |
|
92
|
|
|
* The entity linked to the widget. |
|
93
|
|
|
* |
|
94
|
|
|
* @var unknown |
|
95
|
|
|
*/ |
|
96
|
|
|
protected $entity; |
|
97
|
|
|
|
|
98
|
|
|
/** |
|
99
|
|
|
* @deprecated |
|
100
|
|
|
* |
|
101
|
|
|
* @var string |
|
102
|
|
|
* |
|
103
|
|
|
* @ORM\ManyToOne(targetEntity="\Victoire\Bundle\CoreBundle\Entity\View", inversedBy="widgets", cascade={"persist"}) |
|
104
|
|
|
* @ORM\JoinColumn(name="view_id", referencedColumnName="id", onDelete="CASCADE") |
|
105
|
|
|
*/ |
|
106
|
|
|
protected $view; |
|
107
|
|
|
/** |
|
108
|
|
|
* @deprecated |
|
109
|
|
|
* |
|
110
|
|
|
* @var [WidgetMap] |
|
111
|
|
|
* |
|
112
|
|
|
* @ORM\OneToMany(targetEntity="\Victoire\Bundle\WidgetMapBundle\Entity\WidgetMap", mappedBy="widget", orphanRemoval=true, cascade={"persist", "remove"}) |
|
113
|
|
|
*/ |
|
114
|
|
|
protected $widgetMaps; |
|
115
|
|
|
|
|
116
|
|
|
/** |
|
117
|
|
|
* @return string |
|
118
|
|
|
*/ |
|
119
|
|
|
public function isAsynchronous() |
|
120
|
|
|
{ |
|
121
|
|
|
return $this->asynchronous; |
|
122
|
|
|
} |
|
123
|
|
|
|
|
124
|
|
|
/** |
|
125
|
|
|
* @param string $asynchronous |
|
126
|
|
|
*/ |
|
127
|
|
|
public function setAsynchronous($asynchronous) |
|
128
|
|
|
{ |
|
129
|
|
|
$this->asynchronous = $asynchronous; |
|
130
|
|
|
} |
|
131
|
|
|
|
|
132
|
|
|
/** |
|
133
|
|
|
* Set the entity proxy. |
|
134
|
|
|
* |
|
135
|
|
|
* @param EntityProxy $entityProxy |
|
136
|
|
|
*/ |
|
137
|
|
|
public function setEntityProxy(EntityProxy $entityProxy) |
|
138
|
|
|
{ |
|
139
|
|
|
$this->entityProxy = $entityProxy; |
|
140
|
|
|
} |
|
141
|
|
|
|
|
142
|
|
|
/** |
|
143
|
|
|
* Get the entity proxy. |
|
144
|
|
|
* |
|
145
|
|
|
* @return EntityProxy |
|
146
|
|
|
*/ |
|
147
|
|
|
public function getEntityProxy() |
|
148
|
|
|
{ |
|
149
|
|
|
return $this->entityProxy; |
|
150
|
|
|
} |
|
151
|
|
|
|
|
152
|
|
|
/** |
|
153
|
|
|
* to string. |
|
154
|
|
|
* |
|
155
|
|
|
* @return string |
|
156
|
|
|
*/ |
|
157
|
|
|
public function __toString() |
|
158
|
|
|
{ |
|
159
|
|
|
return (string) $this->getId(); |
|
160
|
|
|
} |
|
161
|
|
|
|
|
162
|
|
|
/** |
|
163
|
|
|
* Get id. |
|
164
|
|
|
* |
|
165
|
|
|
* @return int |
|
166
|
|
|
*/ |
|
167
|
|
|
public function getId() |
|
168
|
|
|
{ |
|
169
|
|
|
return $this->id; |
|
170
|
|
|
} |
|
171
|
|
|
|
|
172
|
|
|
/** |
|
173
|
|
|
* Set fields. |
|
174
|
|
|
* |
|
175
|
|
|
* @param string $fields |
|
176
|
|
|
* |
|
177
|
|
|
* @return Widget |
|
178
|
|
|
*/ |
|
179
|
|
|
public function setFields($fields) |
|
180
|
|
|
{ |
|
181
|
|
|
$this->fields = $fields; |
|
182
|
|
|
|
|
183
|
|
|
return $this; |
|
184
|
|
|
} |
|
185
|
|
|
|
|
186
|
|
|
/** |
|
187
|
|
|
* Get fields. |
|
188
|
|
|
* |
|
189
|
|
|
* @return string |
|
190
|
|
|
*/ |
|
191
|
|
|
public function getFields() |
|
192
|
|
|
{ |
|
193
|
|
|
return $this->fields; |
|
194
|
|
|
} |
|
195
|
|
|
|
|
196
|
|
|
/** |
|
197
|
|
|
* Set The Id. |
|
198
|
|
|
* |
|
199
|
|
|
* @param int $id The id |
|
200
|
|
|
*/ |
|
201
|
|
|
public function setId($id) |
|
202
|
|
|
{ |
|
203
|
|
|
$this->id = $id; |
|
204
|
|
|
} |
|
205
|
|
|
|
|
206
|
|
|
/** |
|
207
|
|
|
* Set slot. |
|
208
|
|
|
* |
|
209
|
|
|
* @param string $slot |
|
210
|
|
|
* |
|
211
|
|
|
* @return Widget |
|
212
|
|
|
*/ |
|
213
|
|
|
public function setSlot($slot) |
|
214
|
|
|
{ |
|
215
|
|
|
$this->slot = $slot; |
|
216
|
|
|
|
|
217
|
|
|
return $this; |
|
218
|
|
|
} |
|
219
|
|
|
|
|
220
|
|
|
/** |
|
221
|
|
|
* Get slot. |
|
222
|
|
|
* |
|
223
|
|
|
* @return string |
|
224
|
|
|
*/ |
|
225
|
|
|
public function getSlot() |
|
226
|
|
|
{ |
|
227
|
|
|
return $this->slot; |
|
228
|
|
|
} |
|
229
|
|
|
|
|
230
|
|
|
/** |
|
231
|
|
|
* Set theme. |
|
232
|
|
|
* |
|
233
|
|
|
* @param string $theme |
|
234
|
|
|
* |
|
235
|
|
|
* @return Widget |
|
236
|
|
|
*/ |
|
237
|
|
|
public function setTheme($theme) |
|
238
|
|
|
{ |
|
239
|
|
|
$this->theme = $theme; |
|
240
|
|
|
|
|
241
|
|
|
return $this; |
|
242
|
|
|
} |
|
243
|
|
|
|
|
244
|
|
|
/** |
|
245
|
|
|
* Get theme. |
|
246
|
|
|
* |
|
247
|
|
|
* @return string |
|
248
|
|
|
*/ |
|
249
|
|
|
public function getTheme() |
|
250
|
|
|
{ |
|
251
|
|
|
return $this->theme; |
|
252
|
|
|
} |
|
253
|
|
|
|
|
254
|
|
|
/** |
|
255
|
|
|
* Get the content. |
|
256
|
|
|
* |
|
257
|
|
|
* @return unknown |
|
258
|
|
|
*/ |
|
259
|
|
|
public function getValue() |
|
260
|
|
|
{ |
|
261
|
|
|
//return $this->getContent(); |
|
|
|
|
|
|
262
|
|
|
return; |
|
263
|
|
|
} |
|
264
|
|
|
|
|
265
|
|
|
/** |
|
266
|
|
|
* Get the type of the object. |
|
267
|
|
|
* |
|
268
|
|
|
* @return string The type |
|
269
|
|
|
*/ |
|
270
|
|
|
public function getType() |
|
271
|
|
|
{ |
|
272
|
|
|
return $this->guessType(); |
|
273
|
|
|
} |
|
274
|
|
|
|
|
275
|
|
|
/** |
|
276
|
|
|
* Guess the type of this by exploding and getting the last item. |
|
277
|
|
|
* |
|
278
|
|
|
* @return string The guessed type |
|
279
|
|
|
*/ |
|
280
|
|
|
protected function guessType() |
|
281
|
|
|
{ |
|
282
|
|
|
$type = explode('\\', get_class($this)); |
|
283
|
|
|
|
|
284
|
|
|
return strtolower(preg_replace('/Widget/', '', end($type))); |
|
285
|
|
|
} |
|
286
|
|
|
|
|
287
|
|
|
/** |
|
288
|
|
|
* Set the mode. |
|
289
|
|
|
* |
|
290
|
|
|
* @param string $mode |
|
291
|
|
|
*/ |
|
292
|
|
|
public function setMode($mode) |
|
293
|
|
|
{ |
|
294
|
|
|
$this->mode = $mode; |
|
295
|
|
|
} |
|
296
|
|
|
|
|
297
|
|
|
/** |
|
298
|
|
|
* Get the mode. |
|
299
|
|
|
* |
|
300
|
|
|
* @return string |
|
301
|
|
|
*/ |
|
302
|
|
|
public function getMode() |
|
303
|
|
|
{ |
|
304
|
|
|
return $this->mode; |
|
305
|
|
|
} |
|
306
|
|
|
|
|
307
|
|
|
/** |
|
308
|
|
|
* Get the view id. |
|
309
|
|
|
* |
|
310
|
|
|
* @return int The view id |
|
311
|
|
|
*/ |
|
312
|
|
|
public function getViewId() |
|
313
|
|
|
{ |
|
314
|
|
|
$viewId = null; |
|
315
|
|
|
|
|
316
|
|
|
$view = $this->getView(); |
|
|
|
|
|
|
317
|
|
|
|
|
318
|
|
|
if ($view !== null) { |
|
319
|
|
|
$viewId = $view->getId(); |
|
|
|
|
|
|
320
|
|
|
} |
|
321
|
|
|
|
|
322
|
|
|
return $viewId; |
|
323
|
|
|
} |
|
324
|
|
|
|
|
325
|
|
|
/** |
|
326
|
|
|
* @return string |
|
327
|
|
|
*/ |
|
328
|
|
|
public function getChildrenSlot() |
|
329
|
|
|
{ |
|
330
|
|
|
return $this->childrenSlot ?: $this->getId(); |
|
331
|
|
|
} |
|
332
|
|
|
|
|
333
|
|
|
/** |
|
334
|
|
|
* @param string $childrenSlot |
|
335
|
|
|
*/ |
|
336
|
|
|
public function setChildrenSlot($childrenSlot) |
|
337
|
|
|
{ |
|
338
|
|
|
$this->childrenSlot = $childrenSlot; |
|
339
|
|
|
} |
|
340
|
|
|
|
|
341
|
|
|
/** |
|
342
|
|
|
* Set widgets. |
|
343
|
|
|
* |
|
344
|
|
|
* @param [WidgetMap] $widgetMaps |
|
|
|
|
|
|
345
|
|
|
* |
|
346
|
|
|
* @return Widget |
|
347
|
|
|
*/ |
|
348
|
|
|
public function setWidgetMaps($widgetMaps) |
|
349
|
|
|
{ |
|
350
|
|
|
$this->widgetMaps = $widgetMaps; |
|
|
|
|
|
|
351
|
|
|
|
|
352
|
|
|
foreach ($widgetMaps as $widgetMap) { |
|
353
|
|
|
$widgetMap->setWidget($this); |
|
354
|
|
|
} |
|
355
|
|
|
|
|
356
|
|
|
return $this; |
|
357
|
|
|
} |
|
358
|
|
|
|
|
359
|
|
|
/** |
|
360
|
|
|
* Get widgets. |
|
361
|
|
|
* |
|
362
|
|
|
* @return [WidgetMap] |
|
|
|
|
|
|
363
|
|
|
*/ |
|
364
|
|
|
public function getWidgetMaps() |
|
365
|
|
|
{ |
|
366
|
|
|
return $this->widgetMaps; |
|
|
|
|
|
|
367
|
|
|
} |
|
368
|
|
|
|
|
369
|
|
|
/** |
|
370
|
|
|
* Add widget. |
|
371
|
|
|
* |
|
372
|
|
|
* @param Widget $widgetMap |
|
373
|
|
|
*/ |
|
374
|
|
|
public function addWidgetMap(WidgetMap $widgetMap) |
|
375
|
|
|
{ |
|
376
|
|
|
$widgetMap->setWidget($this); |
|
377
|
|
|
$this->widgetMaps[] = $widgetMap; |
|
|
|
|
|
|
378
|
|
|
} |
|
379
|
|
|
|
|
380
|
|
|
/** |
|
381
|
|
|
* Remove a widgetMap. |
|
382
|
|
|
* |
|
383
|
|
|
* @param WidgetMap $widgetMap |
|
384
|
|
|
*/ |
|
385
|
|
|
public function removeWidgetMap(WidgetMap $widgetMap) |
|
386
|
|
|
{ |
|
387
|
|
|
$this->widgetMaps->removeElement($widgetMap); |
|
|
|
|
|
|
388
|
|
|
} |
|
389
|
|
|
|
|
390
|
|
|
/** |
|
391
|
|
|
* Set the entity. |
|
392
|
|
|
* |
|
393
|
|
|
* @param unknown $entity |
|
394
|
|
|
*/ |
|
395
|
|
|
public function setEntity($entity) |
|
396
|
|
|
{ |
|
397
|
|
|
$this->entity = $entity; |
|
398
|
|
|
} |
|
399
|
|
|
|
|
400
|
|
|
/** |
|
401
|
|
|
* Get the entity. |
|
402
|
|
|
* |
|
403
|
|
|
* @return number |
|
404
|
|
|
*/ |
|
405
|
|
|
public function getEntity() |
|
406
|
|
|
{ |
|
407
|
|
|
//if there is no entity |
|
408
|
|
|
if ($this->entity === null) { |
|
409
|
|
|
//we try to get one from the proxy |
|
410
|
|
|
$entityProxy = $this->getEntityProxy(); |
|
411
|
|
|
|
|
412
|
|
|
//if there is a proxy |
|
413
|
|
|
if ($entityProxy !== null) { |
|
414
|
|
|
$entity = $entityProxy->getEntity($this->getBusinessEntityId()); |
|
415
|
|
|
$this->entity = $entity; |
|
416
|
|
|
} |
|
417
|
|
|
} |
|
418
|
|
|
|
|
419
|
|
|
return $this->entity; |
|
420
|
|
|
} |
|
421
|
|
|
|
|
422
|
|
|
/** |
|
423
|
|
|
* Clone a widget. |
|
424
|
|
|
*/ |
|
425
|
|
|
public function __clone() |
|
426
|
|
|
{ |
|
427
|
|
|
// if there is a proxy |
|
428
|
|
|
if ($this->entityProxy) { |
|
429
|
|
|
// we clone this one |
|
430
|
|
|
$this->entityProxy = clone $this->entityProxy; |
|
431
|
|
|
} |
|
432
|
|
|
|
|
433
|
|
|
// This check should be in the __constructor, but Doctrine does not use __constructor to |
|
434
|
|
|
// instanciate entites but __clone method. |
|
435
|
|
|
if (property_exists(get_called_class(), 'widget')) { |
|
436
|
|
|
throw new \Exception(sprintf('A property $widget was found in %s object. |
|
437
|
|
|
The $widget property is reserved for Victoire. |
|
438
|
|
|
You should chose a different property name.', get_called_class())); |
|
439
|
|
|
} |
|
440
|
|
|
} |
|
441
|
|
|
|
|
442
|
|
|
/** |
|
443
|
|
|
* @deprecated |
|
444
|
|
|
* Get view. |
|
445
|
|
|
* |
|
446
|
|
|
* @return string |
|
447
|
|
|
*/ |
|
448
|
|
|
public function getView() |
|
449
|
|
|
{ |
|
450
|
|
|
return $this->view; |
|
|
|
|
|
|
451
|
|
|
} |
|
452
|
|
|
} |
|
453
|
|
|
|
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.