|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the Sylius package. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Paweł Jędrzejewski |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace Sylius\Component\Core\Model; |
|
13
|
|
|
|
|
14
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
|
15
|
|
|
use Doctrine\Common\Collections\Collection; |
|
16
|
|
|
use Sylius\Component\Resource\Model\TimestampableTrait; |
|
17
|
|
|
use Sylius\Component\Taxonomy\Model\Taxon as BaseTaxon; |
|
18
|
|
|
use Sylius\Component\Taxonomy\Model\TaxonTranslation; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* @author Grzegorz Sadowski <[email protected]> |
|
22
|
|
|
*/ |
|
23
|
|
|
class Taxon extends BaseTaxon implements TaxonInterface |
|
24
|
|
|
{ |
|
25
|
|
|
use TimestampableTrait; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* @var Collection|ImageInterface[] |
|
29
|
|
|
*/ |
|
30
|
|
|
protected $images; |
|
31
|
|
|
|
|
32
|
|
|
public function __construct() |
|
33
|
|
|
{ |
|
34
|
|
|
parent::__construct(); |
|
35
|
|
|
|
|
36
|
|
|
$this->createdAt = new \DateTime(); |
|
37
|
|
|
$this->products = new ArrayCollection(); |
|
|
|
|
|
|
38
|
|
|
$this->images = new ArrayCollection(); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* {@inheritdoc} |
|
43
|
|
|
*/ |
|
44
|
|
|
public function getImages() |
|
45
|
|
|
{ |
|
46
|
|
|
return $this->images; |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* {@inheritdoc} |
|
51
|
|
|
*/ |
|
52
|
|
|
public function getImagesByType($type) |
|
53
|
|
|
{ |
|
54
|
|
|
return $this->images->filter(function (ImageInterface $image) use ($type) { |
|
55
|
|
|
return $type === $image->getType(); |
|
56
|
|
|
}); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* {@inheritdoc} |
|
61
|
|
|
*/ |
|
62
|
|
|
public function hasImages() |
|
63
|
|
|
{ |
|
64
|
|
|
return !$this->images->isEmpty(); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* {@inheritdoc} |
|
69
|
|
|
*/ |
|
70
|
|
|
public function hasImage(ImageInterface $image) |
|
71
|
|
|
{ |
|
72
|
|
|
return $this->images->contains($image); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* {@inheritdoc} |
|
77
|
|
|
*/ |
|
78
|
|
|
public function addImage(ImageInterface $image) |
|
79
|
|
|
{ |
|
80
|
|
|
$image->setOwner($this); |
|
81
|
|
|
$this->images->add($image); |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
/** |
|
85
|
|
|
* {@inheritdoc} |
|
86
|
|
|
*/ |
|
87
|
|
|
public function removeImage(ImageInterface $image) |
|
88
|
|
|
{ |
|
89
|
|
|
if ($this->hasImage($image)) { |
|
90
|
|
|
$image->setOwner(null); |
|
91
|
|
|
$this->images->removeElement($image); |
|
92
|
|
|
} |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
/** |
|
96
|
|
|
* {@inheritdoc} |
|
97
|
|
|
*/ |
|
98
|
|
|
public static function getTranslationClass() |
|
|
|
|
|
|
99
|
|
|
{ |
|
100
|
|
|
return TaxonTranslation::class; |
|
101
|
|
|
} |
|
102
|
|
|
} |
|
103
|
|
|
|
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: