Completed
Pull Request — master (#325)
by Paul
08:40
created

Widget::setTheme()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 6
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
1
<?php
2
3
namespace Victoire\Bundle\WidgetBundle\Entity;
4
5
use Doctrine\ORM\Mapping as ORM;
6
use Victoire\Bundle\CoreBundle\Entity\BaseEntityProxy;
7
use Victoire\Bundle\CoreBundle\Entity\View;
8
use Victoire\Bundle\QueryBundle\Entity\Traits\QueryTrait;
9
use Victoire\Bundle\WidgetBundle\Entity\Traits\StyleTrait;
10
use Victoire\Bundle\WidgetBundle\Model\Widget as BaseWidget;
11
use Victoire\Bundle\WidgetMapBundle\Entity\WidgetMap;
12
13
/**
14
 * Widget.
15
 *
16
 * @ORM\Table("vic_widget")
17
 * @ORM\Entity(repositoryClass="Victoire\Bundle\WidgetBundle\Repository\WidgetRepository")
18
 * @ORM\InheritanceType("JOINED")
19
 * @ORM\DiscriminatorColumn(name="type", type="string")
20
 */
21
class Widget extends BaseWidget
22
{
23
    use StyleTrait;
24
    use QueryTrait;
25
26
    public function __construct()
27
    {
28
        $this->childrenSlot = uniqid();
29
    }
30
31
    /**
32
     * @var int
33
     *
34
     * @ORM\Column(name="id", type="integer")
35
     * @ORM\Id
36
     * @ORM\GeneratedValue(strategy="AUTO")
37
     */
38
    protected $id;
39
40
    /**
41
     * @var string
42
     *
43
     * @ORM\Column(name="slot", type="string", length=255, nullable=true)
44
     */
45
    protected $slot;
46
47
    /**
48
     * @var string
49
     *
50
     * @ORM\Column(name="childrenSlot", type="string", length=100, nullable=true)
51
     */
52
    protected $childrenSlot;
53
54
    /**
55
     * @var string
56
     *
57
     * @ORM\Column(name="theme", type="string", length=255, nullable=true)
58
     */
59
    protected $theme;
60
61
    /**
62
     * @var string
63
     *
64
     * @ORM\Column(name="asynchronous", type="boolean", nullable=true)
65
     */
66
    protected $asynchronous;
67
68
    /**
69
     * @var string
70
     *
71
     * @ORM\Column(name="fields", type="array")
72
     */
73
    protected $fields = [];
74
75
    /**
76
     * @var string
77
     *
78
     * @ORM\Column(name="mode", type="string", length=255, nullable=false)
79
     */
80
    protected $mode = self::MODE_STATIC;
81
82
    /**
83
     * Auto simple mode: joined entity.
84
     *
85
     * @var EntityProxy
86
     *
87
     * @ORM\ManyToOne(targetEntity="\Victoire\Bundle\CoreBundle\Entity\EntityProxy", inversedBy="widgets", cascade={"persist"})
88
     * @ORM\JoinColumn(name="entityProxy_id", referencedColumnName="id", onDelete="CASCADE")
89
     */
90
    protected $entityProxy;
91
92
    /**
93
     * The entity linked to the widget.
94
     *
95
     * @var unknown
96
     */
97
    protected $entity;
98
99
    /**
100
     * @deprecated
101
     *
102
     * @var string
103
     *
104
     * @ORM\ManyToOne(targetEntity="\Victoire\Bundle\CoreBundle\Entity\View", inversedBy="widgets", cascade={"persist"})
105
     * @ORM\JoinColumn(name="view_id", referencedColumnName="id", onDelete="CASCADE")
106
     */
107
    protected $view;
108
    /**
109
     * @deprecated
110
     *
111
     * @var [WidgetMap]
112
     *
113
     * @ORM\OneToMany(targetEntity="\Victoire\Bundle\WidgetMapBundle\Entity\WidgetMap", mappedBy="widget", orphanRemoval=true, cascade={"persist", "remove"})
114
     */
115
    protected $widgetMaps;
116
117
    /**
118
     * @return string
119
     */
120
    public function isAsynchronous()
121
    {
122
        return $this->asynchronous;
123
    }
124
125
    /**
126
     * @param string $asynchronous
127
     */
128
    public function setAsynchronous($asynchronous)
129
    {
130
        $this->asynchronous = $asynchronous;
131
    }
132
133
    /**
134
     * Set the entity proxy.
135
     *
136
     * @param BaseEntityProxy $entityProxy
137
     */
138
    public function setEntityProxy(BaseEntityProxy $entityProxy)
139
    {
140
        $this->entityProxy = $entityProxy;
0 ignored issues
show
Documentation Bug introduced by
It seems like $entityProxy of type object<Victoire\Bundle\C...Entity\BaseEntityProxy> is incompatible with the declared type object<Victoire\Bundle\W...dle\Entity\EntityProxy> of property $entityProxy.

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..

Loading history...
141
    }
142
143
    /**
144
     * Get the entity proxy.
145
     *
146
     * @return EntityProxy
147
     */
148
    public function getEntityProxy()
149
    {
150
        return $this->entityProxy;
151
    }
152
153
    /**
154
     * to string.
155
     *
156
     * @return string
157
     */
158
    public function __toString()
159
    {
160
        return (string) $this->getId();
161
    }
162
163
    /**
164
     * Get id.
165
     *
166
     * @return int
167
     */
168
    public function getId()
169
    {
170
        return $this->id;
171
    }
172
173
    /**
174
     * Set fields.
175
     *
176
     * @param string $fields
177
     *
178
     * @return Widget
179
     */
180
    public function setFields($fields)
181
    {
182
        $this->fields = $fields;
183
184
        return $this;
185
    }
186
187
    /**
188
     * Get fields.
189
     *
190
     * @return string
191
     */
192
    public function getFields()
193
    {
194
        return $this->fields;
195
    }
196
197
    /**
198
     * Set The Id.
199
     *
200
     * @param int $id The id
201
     */
202
    public function setId($id)
203
    {
204
        $this->id = $id;
205
    }
206
207
    /**
208
     * Set slot.
209
     *
210
     * @param string $slot
211
     *
212
     * @return Widget
213
     */
214
    public function setSlot($slot)
215
    {
216
        $this->slot = $slot;
217
218
        return $this;
219
    }
220
221
    /**
222
     * Get slot.
223
     *
224
     * @return string
225
     */
226
    public function getSlot()
227
    {
228
        return $this->slot;
229
    }
230
231
    /**
232
     * Set theme.
233
     *
234
     * @param string $theme
235
     *
236
     * @return Widget
237
     */
238
    public function setTheme($theme)
239
    {
240
        $this->theme = $theme;
241
242
        return $this;
243
    }
244
245
    /**
246
     * Get theme.
247
     *
248
     * @return string
249
     */
250
    public function getTheme()
251
    {
252
        return $this->theme;
253
    }
254
255
    /**
256
     * Get the content.
257
     *
258
     * @return unknown
259
     */
260
    public function getValue()
261
    {
262
        //return $this->getContent();
0 ignored issues
show
Unused Code Comprehensibility introduced by
75% of this comment could be valid code. Did you maybe forget this after debugging?

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.

Loading history...
263
        return;
264
    }
265
266
    /**
267
     * Get the type of the object.
268
     *
269
     * @return string The type
270
     */
271
    public function getType()
272
    {
273
        return $this->guessType();
274
    }
275
276
    /**
277
     * Guess the type of this by exploding and getting the last item.
278
     *
279
     * @return string The guessed type
280
     */
281
    protected function guessType()
282
    {
283
        $type = explode('\\', get_class($this));
284
285
        return strtolower(preg_replace('/Widget/', '', end($type)));
286
    }
287
288
    /**
289
     * Set the mode.
290
     *
291
     * @param string $mode
292
     */
293
    public function setMode($mode)
294
    {
295
        $this->mode = $mode;
296
    }
297
298
    /**
299
     * Get the mode.
300
     *
301
     * @return string
302
     */
303
    public function getMode()
304
    {
305
        return $this->mode;
306
    }
307
308
    /**
309
     * Get the view id.
310
     *
311
     * @return int The view id
312
     */
313
    public function getViewId()
314
    {
315
        $viewId = null;
316
317
        $view = $this->getView();
0 ignored issues
show
Deprecated Code introduced by
The method Victoire\Bundle\WidgetBu...ntity\Widget::getView() has been deprecated with message: Get view.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
318
319
        if ($view !== null) {
320
            $viewId = $view->getId();
0 ignored issues
show
Bug introduced by
The method getId cannot be called on $view (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
321
        }
322
323
        return $viewId;
324
    }
325
326
    /**
327
     * @return string
328
     */
329
    public function getChildrenSlot()
330
    {
331
        return $this->childrenSlot ?: $this->getId();
332
    }
333
334
    /**
335
     * @param string $childrenSlot
336
     */
337
    public function setChildrenSlot($childrenSlot)
338
    {
339
        $this->childrenSlot = $childrenSlot;
340
    }
341
342
    /**
343
     * Set widgets.
344
     *
345
     * @param [WidgetMap] $widgetMaps
0 ignored issues
show
Documentation introduced by
The doc-type [WidgetMap] could not be parsed: Unknown type name "" at position 0. [(view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
346
     *
347
     * @return Widget
348
     */
349
    public function setWidgetMaps($widgetMaps)
350
    {
351
        $this->widgetMaps = $widgetMaps;
0 ignored issues
show
Deprecated Code introduced by
The property Victoire\Bundle\WidgetBu...ity\Widget::$widgetMaps has been deprecated.

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
352
353
        foreach ($widgetMaps as $widgetMap) {
354
            $widgetMap->setWidget($this);
355
        }
356
357
        return $this;
358
    }
359
360
    /**
361
     * Get widgets.
362
     *
363
     * @return [WidgetMap]
0 ignored issues
show
Documentation introduced by
The doc-type [WidgetMap] could not be parsed: Unknown type name "" at position 0. [(view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
364
     */
365
    public function getWidgetMaps()
366
    {
367
        return $this->widgetMaps;
0 ignored issues
show
Deprecated Code introduced by
The property Victoire\Bundle\WidgetBu...ity\Widget::$widgetMaps has been deprecated.

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
368
    }
369
370
    /**
371
     * Add widget.
372
     *
373
     * @param Widget $widgetMap
374
     */
375
    public function addWidgetMap(WidgetMap $widgetMap)
376
    {
377
        $widgetMap->setWidget($this);
378
        $this->widgetMaps[] = $widgetMap;
0 ignored issues
show
Deprecated Code introduced by
The property Victoire\Bundle\WidgetBu...ity\Widget::$widgetMaps has been deprecated.

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
379
    }
380
381
    /**
382
     * Remove a widgetMap.
383
     *
384
     * @param WidgetMap $widgetMap
385
     */
386
    public function removeWidgetMap(WidgetMap $widgetMap)
387
    {
388
        $this->widgetMaps->removeElement($widgetMap);
0 ignored issues
show
Bug introduced by
The method removeElement cannot be called on $this->widgetMaps (of type array<integer,object<Vic...ndle\Entity\WidgetMap>>).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
Deprecated Code introduced by
The property Victoire\Bundle\WidgetBu...ity\Widget::$widgetMaps has been deprecated.

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
389
    }
390
391
    /**
392
     * Set the entity.
393
     *
394
     * @param unknown $entity
395
     */
396
    public function setEntity($entity)
397
    {
398
        $this->entity = $entity;
399
    }
400
401
    /**
402
     * Get the entity.
403
     *
404
     * @return number
405
     */
406
    public function getEntity()
407
    {
408
        //if there is no entity
409
        if ($this->entity === null) {
410
            //we try to get one from the proxy
411
            $entityProxy = $this->getEntityProxy();
412
413
            //if there is a proxy
414
            if ($entityProxy !== null) {
415
                $entity = $entityProxy->getEntity($this->getBusinessEntityId());
416
                $this->entity = $entity;
417
            }
418
        }
419
420
        return $this->entity;
421
    }
422
423
    /**
424
     * Clone a widget.
425
     */
426
    public function __clone()
427
    {
428
        // if there is a proxy
429
        if ($this->entityProxy) {
430
            // we clone this one
431
            $this->entityProxy = clone $this->entityProxy;
432
        }
433
434
        // This check should be in the __constructor, but Doctrine does not use __constructor to
435
        // instanciate entites but __clone method.
436
        if (property_exists(get_called_class(), 'widget')) {
437
            throw new \Exception(sprintf('A property $widget was found in %s object.
438
                The $widget property is reserved for Victoire.
439
                You should chose a different property name.', get_called_class()));
440
        }
441
    }
442
443
    /**
444
     * @deprecated
445
     * Get view.
446
     *
447
     * @return string
448
     */
449
    public function getView()
450
    {
451
        return $this->view;
0 ignored issues
show
Deprecated Code introduced by
The property Victoire\Bundle\WidgetBundle\Entity\Widget::$view has been deprecated.

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
452
    }
453
}
454