Slot::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace Victoire\Bundle\WidgetMapBundle\Entity;
4
5
class Slot
0 ignored issues
show
introduced by
Missing class doc comment
Loading history...
6
{
7
    //the id
8
    protected $id = null;
9
    protected $widgetMaps = null;
10
11
    /**
12
     * Constructor.
13
     */
14
    public function __construct()
15
    {
16
        $this->widgetMaps = [];
17
    }
18
19
    /**
20
     * Get the id.
21
     *
22
     * @return string The id
23
     */
24
    public function getId()
25
    {
26
        return $this->id;
27
    }
28
29
    /**
30
     * Set the id.
31
     *
32
     * @param string $id
33
     */
34
    public function setId($id)
35
    {
36
        $this->id = $id;
37
    }
38
39
    /**
40
     * Set the widget maps for this slot.
41
     *
42
     * @param array $widgetMaps
43
     */
44
    public function setWidgetMaps($widgetMaps)
45
    {
46
        $this->widgetMaps = $widgetMaps;
47
    }
48
49
    /**
50
     * Get the widget maps.
51
     *
52
     * @return WidgetMap[] The widget maps
53
     */
54
    public function getWidgetMaps()
55
    {
56
        return $this->widgetMaps;
57
    }
58
59
    /**
60
     * Add a widget map to the list of widget maps.
61
     *
62
     * @param WidgetMap $widgetMap
63
     */
64
    public function addWidgetMap(WidgetMap $widgetMap)
65
    {
66
        $this->widgetMaps[] = $widgetMap;
67
    }
68
69
    /**
70
     * Update the given widgetMap.
71
     *
72
     * @param WidgetMap $widgetMap
73
     *
74
     * @return Slot
75
     */
76
    public function updateWidgetMap($widgetMap)
77
    {
78
        //parse all widfgetMaps
79
        foreach ($this->widgetMaps as $key => $_widgetMap) {
80
            //if this the widgetMap we are looking for
81
            if ($_widgetMap->getWidgetId() === $widgetMap->getWidgetId()) {
0 ignored issues
show
Bug introduced by
The method getWidgetId() does not exist on Victoire\Bundle\WidgetMapBundle\Entity\WidgetMap. Did you maybe mean getWidget()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
82
                $this->widgetMaps[$key] = $widgetMap;
83
                //there no need to continue, we found the slot
84
                break;
85
            }
86
        }
87
88
        return $this;
89
    }
90
91
    /**
92
     * Get the widget map by the widget id.
93
     *
94
     * @param int $widgetId
95
     *
96
     * @return WidgetMap
97
     */
98
    public function getWidgetMapByWidgetId($widgetId)
99
    {
100
        $widgetMap = null;
101
102
        $widgetMaps = $this->widgetMaps;
103
104
        //parse the widgets maps
105
        foreach ($widgetMaps as $wm) {
106
            if ($wm->getWidgetId() === $widgetId) {
107
                $widgetMap = $wm;
108
                //entity found, there is no need to continue
109
                break;
110
            }
111
        }
112
113
        return $widgetMap;
114
    }
115
116
    /**
117
     * Remove the widget map from the slot.
118
     *
119
     * @param WidgetMap $widgetMap
120
     */
121
    public function removeWidgetMap(WidgetMap $widgetMap)
122
    {
123
        $widgetMaps = $this->widgetMaps;
124
125
        //parse the widgets maps
126
        foreach ($widgetMaps as $index => $wm) {
127
            if ($wm->getWidgetId() === $widgetMap->getWidgetId()) {
0 ignored issues
show
Bug introduced by
The method getWidgetId() does not exist on Victoire\Bundle\WidgetMapBundle\Entity\WidgetMap. Did you maybe mean getWidget()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
128
                unset($this->widgetMaps[$index]);
129
                //entity found, there is no need to continue
130
                break;
131
            }
132
        }
133
    }
134
}
135