1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Zenstruck\Foundry\Tests\Fixtures\Entity\Cascade; |
4
|
|
|
|
5
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
6
|
|
|
use Doctrine\Common\Collections\Collection; |
7
|
|
|
use Doctrine\ORM\Mapping as ORM; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* @ORM\Entity |
11
|
|
|
* @ORM\Table(name="product_cascade") |
12
|
|
|
* @ORM\HasLifecycleCallbacks |
13
|
|
|
*/ |
14
|
|
|
class Product |
15
|
|
|
{ |
16
|
|
|
/** |
17
|
|
|
* @ORM\Id |
18
|
|
|
* @ORM\GeneratedValue |
19
|
|
|
* @ORM\Column(type="integer") |
20
|
|
|
*/ |
21
|
|
|
private $id; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @ORM\Column(type="integer", nullable=true) |
25
|
|
|
*/ |
26
|
|
|
private $prePersistedId; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @ORM\Column(type="string", length=255) |
30
|
|
|
*/ |
31
|
|
|
private $name; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @ORM\ManyToOne(targetEntity=Brand::class, inversedBy="products", cascade={"persist"}) |
35
|
|
|
*/ |
36
|
|
|
private $brand; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @ORM\OneToMany(targetEntity=Variant::class, mappedBy="product", cascade={"persist"}) |
40
|
|
|
*/ |
41
|
|
|
private $variants; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @ORM\ManyToMany(targetEntity=Category::class, mappedBy="products", cascade={"persist"}) |
45
|
|
|
*/ |
46
|
|
|
private $categories; |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @ORM\ManyToMany(targetEntity=Tag::class, inversedBy="products", cascade={"persist"}) |
50
|
|
|
*/ |
51
|
|
|
private $tags; |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @ORM\OneToOne(targetEntity=Review::class, mappedBy="product", cascade={"persist"}) |
55
|
|
|
*/ |
56
|
|
|
private $review; |
57
|
|
|
|
58
|
|
|
public function __construct() |
59
|
|
|
{ |
60
|
|
|
$this->variants = new ArrayCollection(); |
61
|
|
|
$this->categories = new ArrayCollection(); |
62
|
|
|
$this->tags = new ArrayCollection(); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
public function getId(): ?int |
66
|
|
|
{ |
67
|
|
|
return $this->id; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
public function getPrePersistedId(): ?int |
71
|
|
|
{ |
72
|
|
|
return $this->prePersistedId; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
public function setPrePersistedId(?int $prePersistedId): void |
76
|
|
|
{ |
77
|
|
|
$this->prePersistedId = $prePersistedId; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
public function getName(): ?string |
81
|
|
|
{ |
82
|
|
|
return $this->name; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
public function setName(?string $name): void |
86
|
|
|
{ |
87
|
|
|
$this->name = $name; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
public function getBrand(): Brand |
91
|
|
|
{ |
92
|
|
|
return $this->brand; |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
public function setBrand(Brand $brand): void |
96
|
|
|
{ |
97
|
|
|
$this->brand = $brand; |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
public function getReview(): Review |
101
|
|
|
{ |
102
|
|
|
return $this->review; |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
public function setReview(Review $review): void |
106
|
|
|
{ |
107
|
|
|
$this->review = $review; |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
public function getVariants(): Collection |
111
|
|
|
{ |
112
|
|
|
return $this->variants; |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
public function addVariant(Variant $variant): void |
116
|
|
|
{ |
117
|
|
|
if (!$this->variants->contains($variant)) { |
118
|
|
|
$this->variants[] = $variant; |
119
|
|
|
$variant->setProduct($this); |
120
|
|
|
} |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
public function removeVariant(Variant $variant): void |
124
|
|
|
{ |
125
|
|
|
if ($this->variants->contains($variant)) { |
126
|
|
|
$this->variants->removeElement($variant); |
127
|
|
|
} |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
public function getCategories(): Collection |
131
|
|
|
{ |
132
|
|
|
return $this->categories; |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
public function addCategory(Category $category): void |
136
|
|
|
{ |
137
|
|
|
if (!$this->categories->contains($category)) { |
138
|
|
|
$this->categories[] = $category; |
139
|
|
|
} |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
public function removeCategory(Category $category): void |
143
|
|
|
{ |
144
|
|
|
if ($this->categories->contains($category)) { |
145
|
|
|
$this->categories->removeElement($category); |
146
|
|
|
} |
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
public function getTags(): Collection |
150
|
|
|
{ |
151
|
|
|
return $this->tags; |
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
public function addTag(Tag $tag): void |
155
|
|
|
{ |
156
|
|
|
if (!$this->tags->contains($tag)) { |
157
|
|
|
$this->tags[] = $tag; |
158
|
|
|
} |
159
|
|
|
} |
160
|
|
|
|
161
|
|
|
public function removeTag(Tag $tag): void |
162
|
|
|
{ |
163
|
|
|
if ($this->tags->contains($tag)) { |
164
|
|
|
$this->tags->removeElement($tag); |
165
|
|
|
} |
166
|
|
|
} |
167
|
|
|
|
168
|
|
|
// /** |
169
|
|
|
// * @ORM\PrePersist |
170
|
|
|
// */ |
171
|
|
|
// public function generatePrePersist() |
172
|
|
|
// { |
173
|
|
|
// if (null !== $this->brand) { |
174
|
|
|
// var_dump($this->getId(), $this->brand->getId()); |
175
|
|
|
// $this->brand->setPrePersistedId($this->brand->getId()); |
176
|
|
|
// } |
177
|
|
|
// |
178
|
|
|
// if (null !== $this->review) { |
179
|
|
|
// $this->review->setPrePersistedId($this->review->getId()); |
180
|
|
|
// } |
181
|
|
|
// |
182
|
|
|
// if (false === $this->variants->isEmpty()) { |
183
|
|
|
// $this->variants->map(function (Variant $variant) { |
184
|
|
|
// $variant->setPrePersistedId($variant->getId()); |
185
|
|
|
// }); |
186
|
|
|
// } |
187
|
|
|
// |
188
|
|
|
// if (false === $this->tags->isEmpty()) { |
189
|
|
|
// $this->tags->map(function (Tag $tag) { |
190
|
|
|
// $tag->setPrePersistedId($tag->getId()); |
191
|
|
|
// }); |
192
|
|
|
// } |
193
|
|
|
// |
194
|
|
|
// if (false === $this->categories->isEmpty()) { |
195
|
|
|
// $this->categories->map(function (Category $category) { |
196
|
|
|
// $category->setPrePersistedId($category->getId()); |
197
|
|
|
// }); |
198
|
|
|
// } |
199
|
|
|
// } |
200
|
|
|
} |
201
|
|
|
|