Completed
Push — develop ( 6e7672...4f4759 )
by greg
02:18
created

TradingCardModel::getCreatedAt()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace PlaygroundGame\Entity;
4
5
use Doctrine\Common\Collections\ArrayCollection;
6
7
use Zend\InputFilter\Factory as InputFactory;
8
use Zend\InputFilter\InputFilter;
9
use Zend\InputFilter\InputFilterAwareInterface;
10
use Zend\InputFilter\InputFilterInterface;
11
12
/**
13
 * @ORM\Entity @HasLifecycleCallbacks
14
 * @ORM\Table(name="game_tradingcard_model")
15
 * @Gedmo\TranslationEntity(class="PlaygroundGame\Entity\GameTranslation")
16
 */
17
18
class TradingCardModel implements InputFilterAwareInterface, \JsonSerializable
19
{
20
    protected $inputFilter;
21
22
    /**
23
     * @ORM\Id
24
     * @ORM\Column(type="integer");
25
     * @ORM\GeneratedValue(strategy="AUTO")
26
     */
27
    protected $id;
28
29
    /**
30
     * @ORM\ManyToOne(targetEntity="TradingCard", inversedBy="models")
31
     * @ORM\JoinColumn(name="game_id", referencedColumnName="id", onDelete="CASCADE")
32
     */
33
    protected $game;
34
35
    /**
36
     * @ORM\OneToMany(targetEntity="TradingCardCard", mappedBy="model", cascade={"persist","remove"})
37
     */
38
    private $cards;
39
40
    /**
41
     * @Gedmo\Translatable
42
     * @ORM\Column(type="string", length=255, nullable=false)
43
     */
44
    protected $title;
45
46
    /**
47
     * @Gedmo\Translatable
48
     * @ORM\Column(type="text", nullable=true)
49
     */
50
    protected $description;
51
52
    /**
53
     * @Gedmo\Translatable
54
     * @ORM\Column(name="image", type="string", length=255, nullable=true)
55
     */
56
    protected $image;
57
58
    /**
59
     * The type of the card : collector, standard, ...
60
     * @Gedmo\Translatable
61
     * @ORM\Column(type="string", length=255, nullable=true)
62
     */
63
    protected $type;
64
65
    /**
66
     * a card can be part of a set of cards
67
     * @Gedmo\Translatable
68
     * @ORM\Column(type="string", length=255, nullable=true)
69
     */
70
    protected $family;
71
72
    /**
73
     * @ORM\Column(type="integer", nullable=true)
74
     */
75
    protected $points = 0;
76
77
    /**
78
     * @ORM\Column(type="float", nullable=false)
79
     */
80
    protected $distribution = 1;
81
82
    /**
83
     * datetime when this model will be available
84
     * @ORM\Column(type="datetime", nullable=true)
85
     */
86
    protected $availability;
87
88
    /**
89
     * @ORM\Column(name="json_data", type="text", nullable=true)
90
     */
91
    protected $jsonData;
92
93
    /**
94
     * @ORM\Column(name="created_at", type="datetime")
95
     */
96
    protected $createdAt;
97
98
    /**
99
     * @ORM\Column(name="updated_at",type="datetime")
100
     */
101
    protected $updatedAt;
102
103
    public function __construct()
104
    {
105
        $this->cards = new ArrayCollection();
106
    }
107
108
    /**
109
     * @PrePersist
110
     */
111
    public function createChrono()
112
    {
113
        $this->createdAt = new \DateTime("now");
114
        $this->updatedAt = new \DateTime("now");
115
    }
116
117
    /**
118
     * @PreUpdate
119
     */
120
    public function updateChrono()
121
    {
122
        $this->updatedAt = new \DateTime("now");
123
    }
124
125
    /**
126
     * Gets the value of id.
127
     *
128
     * @return mixed
129
     */
130
    public function getId()
131
    {
132
        return $this->id;
133
    }
134
135
    /**
136
     * Sets the value of id.
137
     *
138
     * @param mixed $id the id
139
     *
140
     * @return self
141
     */
142
    public function setId($id)
143
    {
144
        $this->id = $id;
145
146
        return $this;
147
    }
148
149
    /**
150
     * Gets the value of title.
151
     *
152
     * @return mixed
153
     */
154
    public function getTitle()
155
    {
156
        return $this->title;
157
    }
158
159
    /**
160
     * Sets the value of title.
161
     *
162
     * @param mixed $title the title
163
     *
164
     * @return self
165
     */
166
    public function setTitle($title)
167
    {
168
        $this->title = $title;
169
170
        return $this;
171
    }
172
173
    /**
174
     * Gets the value of description.
175
     *
176
     * @return mixed
177
     */
178
    public function getDescription()
179
    {
180
        return $this->description;
181
    }
182
183
    /**
184
     * Sets the value of description.
185
     *
186
     * @param mixed $description the description
187
     *
188
     * @return self
189
     */
190
    public function setDescription($description)
191
    {
192
        $this->description = $description;
193
194
        return $this;
195
    }
196
197
    /**
198
     * Gets the value of image.
199
     *
200
     * @return mixed
201
     */
202
    public function getImage()
203
    {
204
        return $this->image;
205
    }
206
207
    /**
208
     * Sets the value of image.
209
     *
210
     * @param mixed $image the image
211
     *
212
     * @return self
213
     */
214
    public function setImage($image)
215
    {
216
        $this->image = $image;
217
218
        return $this;
219
    }
220
221
    /**
222
     * Gets the value of type.
223
     *
224
     * @return mixed
225
     */
226
    public function getType()
227
    {
228
        return $this->type;
229
    }
230
231
    /**
232
     * Sets the value of type.
233
     *
234
     * @param mixed $type the type
235
     *
236
     * @return self
237
     */
238
    public function setType($type)
239
    {
240
        $this->type = $type;
241
242
        return $this;
243
    }
244
245
    /**
246
     * Gets the value of family.
247
     *
248
     * @return mixed
249
     */
250
    public function getFamily()
251
    {
252
        return $this->family;
253
    }
254
255
    /**
256
     * Sets the value of family.
257
     *
258
     * @param mixed $family the family
259
     *
260
     * @return self
261
     */
262
    public function setFamily($family)
263
    {
264
        $this->family = $family;
265
266
        return $this;
267
    }
268
269
    /**
270
     * Gets the value of points.
271
     *
272
     * @return mixed
273
     */
274
    public function getPoints()
275
    {
276
        return $this->points;
277
    }
278
279
    /**
280
     * Sets the value of points.
281
     *
282
     * @param mixed $points the points
283
     *
284
     * @return self
285
     */
286
    public function setPoints($points)
287
    {
288
        $this->points = $points;
289
290
        return $this;
291
    }
292
293
    /**
294
     * Gets the value of distribution.
295
     *
296
     * @return mixed
297
     */
298
    public function getDistribution()
299
    {
300
        return $this->distribution;
301
    }
302
303
    /**
304
     * Sets the value of distribution.
305
     *
306
     * @param mixed $distribution the distribution
307
     *
308
     * @return self
309
     */
310
    public function setDistribution($distribution)
311
    {
312
        $this->distribution = $distribution;
313
314
        return $this;
315
    }
316
317
    /**
318
     * Gets the value of availability.
319
     *
320
     * @return mixed
321
     */
322
    public function getAvailability()
323
    {
324
        return $this->availability;
325
    }
326
327
    /**
328
     * Sets the value of availability.
329
     *
330
     * @param mixed $availability the availability
331
     *
332
     * @return self
333
     */
334
    public function setAvailability($availability)
335
    {
336
        $this->availability = $availability;
337
338
        return $this;
339
    }
340
341
    /**
342
     * Gets the value of game.
343
     *
344
     * @return mixed
345
     */
346
    public function getGame()
347
    {
348
        return $this->game;
349
    }
350
351
    /**
352
     * Sets the value of game.
353
     *
354
     * @param mixed $game the game
355
     *
356
     * @return self
357
     */
358
    public function setGame($game)
359
    {
360
        $this->game = $game;
361
362
        return $this;
363
    }
364
365
    /**
366
     * Gets the value of jsonData.
367
     *
368
     * @return mixed
369
     */
370
    public function getJsonData()
371
    {
372
        return $this->jsonData;
373
    }
374
375
    /**
376
     * Sets the value of jsonData.
377
     *
378
     * @param mixed $jsonData the json data
379
     *
380
     * @return self
381
     */
382
    public function setJsonData($jsonData)
383
    {
384
        $this->jsonData = $jsonData;
385
386
        return $this;
387
    }
388
389
    /**
390
     * Gets the value of cards.
391
     *
392
     * @return mixed
393
     */
394
    public function getCards()
395
    {
396
        return $this->cards;
397
    }
398
399
    public function addCards(ArrayCollection $cards)
400
    {
401
        foreach ($cards as $card) {
402
            $card->setModel($this);
403
            $this->cards->add($card);
404
        }
405
    }
406
407
    public function removeCards(ArrayCollection $cards)
408
    {
409
        foreach ($cards as $card) {
410
            $card->setModel(null);
411
            $this->cards->removeElement($card);
412
        }
413
    }
414
415
    /**
416
     * Add an card to the Model.
417
     *
418
     * @param TradingCardModel $card
419
     *
420
     * @return void
421
     */
422
    public function addCard($card)
423
    {
424
        $this->cards[] = $card;
425
    }
426
427
    /**
428
     * Gets the value of createdAt.
429
     *
430
     * @return mixed
431
     */
432
    public function getCreatedAt()
433
    {
434
        return $this->createdAt;
435
    }
436
437
    /**
438
     * Sets the value of createdAt.
439
     *
440
     * @param mixed $createdAt the created at
441
     *
442
     * @return self
443
     */
444
    public function setCreatedAt($createdAt)
445
    {
446
        $this->createdAt = $createdAt;
447
448
        return $this;
449
    }
450
451
    /**
452
     * Gets the value of updatedAt.
453
     *
454
     * @return mixed
455
     */
456
    public function getUpdatedAt()
457
    {
458
        return $this->updatedAt;
459
    }
460
461
    /**
462
     * Sets the value of updatedAt.
463
     *
464
     * @param mixed $updatedAt the updated at
465
     *
466
     * @return self
467
     */
468
    public function setUpdatedAt($updatedAt)
469
    {
470
        $this->updatedAt = $updatedAt;
471
472
        return $this;
473
    }
474
475
    /**
476
     * Convert the object to an array.
477
     *
478
     * @return array
479
     */
480
    public function getArrayCopy()
481
    {
482
        $obj_vars = get_object_vars($this);
483
484
        return $obj_vars;
485
    }
486
487
    /**
488
     * Convert the object to json.
489
     *
490
     * @return array
491
     */
492
    public function jsonSerialize()
493
    {
494
        $jsonArray = $this->getArrayCopy();
495
        unset($jsonArray['inputFilter']);
496
        unset($jsonArray['__initializer__']);
497
        unset($jsonArray['__cloner__']);
498
        unset($jsonArray['__isInitialized__']);
499
        unset($jsonArray['game']);
500
        unset($jsonArray['cards']);
501
        unset($jsonArray['distribution']);
502
        unset($jsonArray['createdAt']);
503
        unset($jsonArray['updatedAt']);
504
505
        return $jsonArray;
506
    }
507
508
    /**
509
     * Populate from an array.
510
     *
511
     * @param array $data
512
     */
513
    public function populate($data = array())
514
    {
515 View Code Duplication
        if (isset($data['title']) && $data['title'] !== null) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
516
            $this->title = $data['title'];
517
        }
518
519 View Code Duplication
        if (isset($data['description']) && $data['description'] !== null) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
520
            $this->description = $data['description'];
521
        }
522
523 View Code Duplication
        if (isset($data['jsonData']) && $data['jsonData'] !== null) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
524
            $this->jsonData = $data['jsonData'];
525
        }
526
527
        if (isset($data['distribution']) && $data['distribution'] !== null) {
528
            $this->distribution = $data['distribution'];
529
        }
530
531 View Code Duplication
        if (isset($data['type']) && $data['type'] !== null) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
532
            $this->type = $data['type'];
533
        }
534
535
        if (isset($data['family']) && $data['family'] !== null) {
536
            $this->family = $data['family'];
537
        }
538
539
        $this->points = (!empty($data['points']))?
540
        $this->points = $data['points']:
541
        0;
542
543
        if (!empty($data['image'])) {
544
            $this->image = $data['image'];
545
        }
546
547
        $this->availability = (!empty($data['availability']))?
548
        \DateTime::createFromFormat('d/m/Y H:i:s', $data['availability']):
549
        null;
550
    }
551
552
    public function setInputFilter(InputFilterInterface $inputFilter)
553
    {
554
        throw new \Exception("Not used");
555
    }
556
557 View Code Duplication
    public function getInputFilter()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
558
    {
559
        if (!$this->inputFilter) {
560
            $inputFilter = new InputFilter();
561
            $factory     = new InputFactory();
562
563
            $inputFilter->add($factory->createInput(array(
564
                        'name'     => 'availability',
565
                        'required' => false,
566
                    )));
567
568
            $this->inputFilter = $inputFilter;
569
        }
570
571
        return $this->inputFilter;
572
    }
573
}
574