1 | <?php |
||
14 | class Feature |
||
15 | { |
||
16 | /** |
||
17 | * @var int |
||
18 | * |
||
19 | * @ORM\Column(type="integer") |
||
20 | * @ORM\Id |
||
21 | * @ORM\GeneratedValue(strategy="AUTO") |
||
22 | */ |
||
23 | private $id; |
||
24 | |||
25 | /** |
||
26 | * @var string |
||
27 | * |
||
28 | * @ORM\Column(length=250) |
||
29 | */ |
||
30 | private $name; |
||
31 | |||
32 | /** |
||
33 | * @var bool |
||
34 | * |
||
35 | * @ORM\Column(type="boolean") |
||
36 | */ |
||
37 | private $enabled = false; |
||
38 | |||
39 | /** |
||
40 | * @var string |
||
41 | * |
||
42 | * @ORM\Column(type="text", nullable=true) |
||
43 | */ |
||
44 | private $role; |
||
45 | |||
46 | /** |
||
47 | * @var ArrayCollection |
||
48 | * |
||
49 | * @ORM\OneToMany(targetEntity="Feature", mappedBy="parent") |
||
50 | */ |
||
51 | private $children; |
||
52 | |||
53 | /** |
||
54 | * @var Feature |
||
55 | * |
||
56 | * @ORM\ManyToOne(targetEntity="Feature", inversedBy="children", cascade={"persist", "remove"}) |
||
57 | */ |
||
58 | private $parent; |
||
59 | |||
60 | 8 | public function __construct() |
|
61 | { |
||
62 | 8 | $this->children = new ArrayCollection(); |
|
63 | 8 | } |
|
64 | |||
65 | public function __toString() |
||
66 | { |
||
67 | return $this->getName(); |
||
68 | } |
||
69 | |||
70 | /** |
||
71 | * Get id. |
||
72 | * |
||
73 | * @return int |
||
74 | */ |
||
75 | public function getId() |
||
76 | { |
||
77 | return $this->id; |
||
78 | } |
||
79 | |||
80 | /** |
||
81 | * Set parent. |
||
82 | * |
||
83 | * @param Feature $parent |
||
84 | */ |
||
85 | 4 | public function setParent(Feature $parent) |
|
86 | { |
||
87 | 4 | $this->parent = $parent; |
|
88 | 4 | } |
|
89 | |||
90 | /** |
||
91 | * Get parent. |
||
92 | * |
||
93 | * @return Feature |
||
94 | */ |
||
95 | 6 | public function getParent() |
|
96 | { |
||
97 | 6 | return $this->parent; |
|
98 | } |
||
99 | |||
100 | /** |
||
101 | * Set name. |
||
102 | * |
||
103 | * @param string $name |
||
104 | */ |
||
105 | public function setName($name) |
||
106 | { |
||
107 | $this->name = $name; |
||
108 | } |
||
109 | |||
110 | /** |
||
111 | * Get name. |
||
112 | * |
||
113 | * @return string |
||
114 | */ |
||
115 | public function getName() |
||
116 | { |
||
117 | return $this->name; |
||
118 | } |
||
119 | |||
120 | /** |
||
121 | * Set enabled. |
||
122 | * |
||
123 | * @param bool $enabled |
||
124 | */ |
||
125 | 3 | public function setEnabled($enabled) |
|
126 | { |
||
127 | 3 | $this->enabled = $enabled; |
|
128 | 3 | } |
|
129 | |||
130 | /** |
||
131 | * Get enabled. |
||
132 | * |
||
133 | * @return bool |
||
134 | */ |
||
135 | 4 | public function getEnabled() |
|
136 | { |
||
137 | 4 | return $this->enabled; |
|
138 | } |
||
139 | |||
140 | /** |
||
141 | * Set role. |
||
142 | * |
||
143 | * @param string $role |
||
144 | */ |
||
145 | 1 | public function setRole($role) |
|
146 | { |
||
147 | 1 | $this->role = $role; |
|
148 | 1 | } |
|
149 | |||
150 | /** |
||
151 | * Get role. |
||
152 | * |
||
153 | * @return string |
||
154 | */ |
||
155 | 1 | public function getRole() |
|
159 | |||
160 | 2 | public function getParentRole() |
|
161 | { |
||
162 | 2 | return $this->getParent() ? $this->getParent()->getRole() : null; |
|
163 | } |
||
164 | |||
165 | /** |
||
166 | * Add children. |
||
167 | * |
||
168 | * @param Feature $children |
||
169 | */ |
||
170 | 1 | public function addFeature(Feature $children) |
|
171 | { |
||
172 | 1 | $this->children[] = $children; |
|
173 | 1 | } |
|
174 | |||
175 | /** |
||
176 | * Get children. |
||
177 | * |
||
178 | * @return ArrayCollection |
||
179 | */ |
||
180 | 1 | public function getChildren() |
|
184 | |||
185 | 4 | public function isEnabled() |
|
186 | { |
||
187 | 4 | return $this->getEnabled() && ($this->getParent() ? $this->getParent()->getEnabled() : true); |
|
188 | } |
||
189 | } |
||
190 |