1 | <?php |
||
2 | |||
3 | /* |
||
4 | * @copyright 2014 Mautic Contributors. All rights reserved |
||
5 | * @author Mautic |
||
6 | * |
||
7 | * @link http://mautic.org |
||
8 | * |
||
9 | * @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html |
||
10 | */ |
||
11 | |||
12 | namespace Mautic\StageBundle\Entity; |
||
13 | |||
14 | use Doctrine\Common\Collections\ArrayCollection; |
||
15 | use Doctrine\ORM\Mapping as ORM; |
||
16 | use Mautic\ApiBundle\Serializer\Driver\ApiMetadataDriver; |
||
17 | use Mautic\CoreBundle\Doctrine\Mapping\ClassMetadataBuilder; |
||
18 | use Mautic\CoreBundle\Entity\FormEntity; |
||
19 | use Symfony\Component\Validator\Constraints as Assert; |
||
20 | use Symfony\Component\Validator\Mapping\ClassMetadata; |
||
21 | |||
22 | /** |
||
23 | * Class Stage. |
||
24 | */ |
||
25 | class Stage extends FormEntity |
||
26 | { |
||
27 | /** |
||
28 | * @var int |
||
29 | */ |
||
30 | private $id; |
||
31 | |||
32 | /** |
||
33 | * @var string |
||
34 | */ |
||
35 | private $name; |
||
36 | |||
37 | /** |
||
38 | * @var string |
||
39 | */ |
||
40 | private $description; |
||
41 | |||
42 | /** |
||
43 | * @var int |
||
44 | */ |
||
45 | private $weight = 0; |
||
46 | |||
47 | /** |
||
48 | * @var \DateTime |
||
49 | */ |
||
50 | private $publishUp; |
||
51 | |||
52 | /** |
||
53 | * @var \DateTime |
||
54 | */ |
||
55 | private $publishDown; |
||
56 | |||
57 | /** |
||
58 | * @var ArrayCollection |
||
59 | */ |
||
60 | private $log; |
||
61 | |||
62 | /** |
||
63 | * @var \Mautic\CategoryBundle\Entity\Category |
||
64 | **/ |
||
65 | private $category; |
||
66 | |||
67 | public function __clone() |
||
68 | { |
||
69 | $this->id = null; |
||
70 | |||
71 | parent::__clone(); |
||
72 | } |
||
73 | |||
74 | /** |
||
75 | * Construct. |
||
76 | */ |
||
77 | public function __construct() |
||
78 | { |
||
79 | $this->log = new ArrayCollection(); |
||
80 | } |
||
81 | |||
82 | public static function loadMetadata(ORM\ClassMetadata $metadata) |
||
83 | { |
||
84 | $builder = new ClassMetadataBuilder($metadata); |
||
85 | $builder->setTable('stages') |
||
86 | ->setCustomRepositoryClass('Mautic\StageBundle\Entity\StageRepository'); |
||
87 | |||
88 | $builder->addIdColumns(); |
||
89 | |||
90 | $builder->createField('weight', 'integer') |
||
91 | ->build(); |
||
92 | |||
93 | $builder->addPublishDates(); |
||
94 | |||
95 | $builder->createOneToMany('log', 'LeadStageLog') |
||
96 | ->mappedBy('stage') |
||
97 | ->cascadePersist() |
||
98 | ->cascadeRemove() |
||
99 | ->fetchExtraLazy() |
||
100 | ->build(); |
||
101 | |||
102 | $builder->addCategory(); |
||
103 | } |
||
104 | |||
105 | public static function loadValidatorMetadata(ClassMetadata $metadata) |
||
106 | { |
||
107 | $metadata->addPropertyConstraint('name', new Assert\NotBlank([ |
||
108 | 'message' => 'mautic.core.name.required', |
||
109 | ])); |
||
110 | } |
||
111 | |||
112 | /** |
||
113 | * Prepares the metadata for API usage. |
||
114 | * |
||
115 | * @param $metadata |
||
116 | */ |
||
117 | public static function loadApiMetadata(ApiMetadataDriver $metadata) |
||
118 | { |
||
119 | $metadata->setGroupPrefix('stage') |
||
120 | ->addListProperties( |
||
121 | [ |
||
122 | 'id', |
||
123 | 'name', |
||
124 | 'category', |
||
125 | 'weight', |
||
126 | 'description', |
||
127 | ] |
||
128 | ) |
||
129 | ->addProperties( |
||
130 | [ |
||
131 | 'publishUp', |
||
132 | 'publishDown', |
||
133 | ] |
||
134 | ) |
||
135 | ->build(); |
||
136 | } |
||
137 | |||
138 | /** |
||
139 | * Get id. |
||
140 | * |
||
141 | * @return int |
||
142 | */ |
||
143 | public function getId() |
||
144 | { |
||
145 | return $this->id; |
||
146 | } |
||
147 | |||
148 | /** |
||
149 | * Set weight. |
||
150 | * |
||
151 | * @return int |
||
152 | */ |
||
153 | public function setWeight($type) |
||
154 | { |
||
155 | $this->weight = (int) $type; |
||
156 | |||
157 | return $this; |
||
0 ignored issues
–
show
Bug
Best Practice
introduced
by
Loading history...
|
|||
158 | } |
||
159 | |||
160 | /** |
||
161 | * Get weight. |
||
162 | * |
||
163 | * @return int |
||
164 | */ |
||
165 | public function getWeight() |
||
166 | { |
||
167 | return $this->weight; |
||
168 | } |
||
169 | |||
170 | /** |
||
171 | * @return array |
||
172 | */ |
||
173 | public function convertToArray() |
||
174 | { |
||
175 | return get_object_vars($this); |
||
176 | } |
||
177 | |||
178 | /** |
||
179 | * Set description. |
||
180 | * |
||
181 | * @param string $description |
||
182 | * |
||
183 | * @return string |
||
184 | */ |
||
185 | public function setDescription($description) |
||
186 | { |
||
187 | $this->isChanged('description', $description); |
||
188 | $this->description = $description; |
||
189 | |||
190 | return $this; |
||
191 | } |
||
192 | |||
193 | /** |
||
194 | * Get description. |
||
195 | * |
||
196 | * @return string |
||
197 | */ |
||
198 | public function getDescription() |
||
199 | { |
||
200 | return $this->description; |
||
201 | } |
||
202 | |||
203 | /** |
||
204 | * Set name. |
||
205 | * |
||
206 | * @param string $name |
||
207 | * |
||
208 | * @return string |
||
209 | */ |
||
210 | public function setName($name) |
||
211 | { |
||
212 | $this->isChanged('name', $name); |
||
213 | $this->name = $name; |
||
214 | |||
215 | return $this; |
||
216 | } |
||
217 | |||
218 | /** |
||
219 | * Get name. |
||
220 | * |
||
221 | * @return string |
||
222 | */ |
||
223 | public function getName() |
||
224 | { |
||
225 | return $this->name; |
||
226 | } |
||
227 | |||
228 | /** |
||
229 | * Add log. |
||
230 | * |
||
231 | * @return Log |
||
0 ignored issues
–
show
The type
Mautic\StageBundle\Entity\Log was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths
Loading history...
|
|||
232 | */ |
||
233 | public function addLog(LeadStageLog $log) |
||
234 | { |
||
235 | $this->log[] = $log; |
||
236 | |||
237 | return $this; |
||
0 ignored issues
–
show
|
|||
238 | } |
||
239 | |||
240 | /** |
||
241 | * Remove log. |
||
242 | */ |
||
243 | public function removeLog(LeadStageLog $log) |
||
244 | { |
||
245 | $this->log->removeElement($log); |
||
246 | } |
||
247 | |||
248 | /** |
||
249 | * Get log. |
||
250 | * |
||
251 | * @return \Doctrine\Common\Collections\Collection |
||
252 | */ |
||
253 | public function getLog() |
||
254 | { |
||
255 | return $this->log; |
||
256 | } |
||
257 | |||
258 | /** |
||
259 | * Set publishUp. |
||
260 | * |
||
261 | * @param \DateTime $publishUp |
||
262 | * |
||
263 | * @return Stage |
||
264 | */ |
||
265 | public function setPublishUp($publishUp) |
||
266 | { |
||
267 | $this->isChanged('publishUp', $publishUp); |
||
268 | $this->publishUp = $publishUp; |
||
269 | |||
270 | return $this; |
||
271 | } |
||
272 | |||
273 | /** |
||
274 | * Get publishUp. |
||
275 | * |
||
276 | * @return \DateTime |
||
277 | */ |
||
278 | public function getPublishUp() |
||
279 | { |
||
280 | return $this->publishUp; |
||
281 | } |
||
282 | |||
283 | /** |
||
284 | * Set publishDown. |
||
285 | * |
||
286 | * @param \DateTime $publishDown |
||
287 | * |
||
288 | * @return Stage |
||
289 | */ |
||
290 | public function setPublishDown($publishDown) |
||
291 | { |
||
292 | $this->isChanged('publishDown', $publishDown); |
||
293 | $this->publishDown = $publishDown; |
||
294 | |||
295 | return $this; |
||
296 | } |
||
297 | |||
298 | /** |
||
299 | * Get publishDown. |
||
300 | * |
||
301 | * @return \DateTime |
||
302 | */ |
||
303 | public function getPublishDown() |
||
304 | { |
||
305 | return $this->publishDown; |
||
306 | } |
||
307 | |||
308 | /** |
||
309 | * @return mixed |
||
310 | */ |
||
311 | public function getCategory() |
||
312 | { |
||
313 | return $this->category; |
||
314 | } |
||
315 | |||
316 | /** |
||
317 | * @param mixed $category |
||
318 | */ |
||
319 | public function setCategory($category) |
||
320 | { |
||
321 | $this->category = $category; |
||
322 | } |
||
323 | } |
||
324 |