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
|
|
|
*/ |
13
|
|
|
class Product |
14
|
|
|
{ |
15
|
|
|
/** |
16
|
|
|
* @ORM\Id |
17
|
|
|
* @ORM\GeneratedValue |
18
|
|
|
* @ORM\Column(type="integer") |
19
|
|
|
*/ |
20
|
|
|
private $id; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @ORM\Column(type="string", length=255) |
24
|
|
|
*/ |
25
|
|
|
private $name; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @ORM\ManyToOne(targetEntity=Brand::class, inversedBy="products", cascade={"persist"}) |
29
|
|
|
*/ |
30
|
|
|
private $brand; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @ORM\OneToMany(targetEntity=Variant::class, mappedBy="product", cascade={"persist"}) |
34
|
|
|
*/ |
35
|
|
|
private $variants; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @ORM\OneToMany(targetEntity=ProductComment::class, mappedBy="product", cascade={"persist"}) |
39
|
|
|
*/ |
40
|
|
|
private $comments; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @ORM\ManyToMany(targetEntity=Category::class, mappedBy="products", cascade={"persist"}) |
44
|
|
|
*/ |
45
|
|
|
private $categories; |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @ORM\ManyToMany(targetEntity=Tag::class, inversedBy="products", cascade={"persist"}) |
49
|
|
|
*/ |
50
|
|
|
private $tags; |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @ORM\OneToOne(targetEntity=Review::class, mappedBy="product", cascade={"persist"}) |
54
|
|
|
*/ |
55
|
|
|
private $review; |
56
|
|
|
|
57
|
|
|
public function __construct() |
58
|
|
|
{ |
59
|
|
|
$this->variants = new ArrayCollection(); |
60
|
|
|
$this->categories = new ArrayCollection(); |
61
|
|
|
$this->tags = new ArrayCollection(); |
62
|
|
|
$this->comments = new ArrayCollection(); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
public function getId(): ?int |
66
|
|
|
{ |
67
|
|
|
return $this->id; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
public function getName(): ?string |
71
|
|
|
{ |
72
|
|
|
return $this->name; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
public function setName(?string $name): void |
76
|
|
|
{ |
77
|
|
|
$this->name = $name; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
public function getBrand(): Brand |
81
|
|
|
{ |
82
|
|
|
return $this->brand; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
public function setBrand(Brand $brand): void |
86
|
|
|
{ |
87
|
|
|
$this->brand = $brand; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
public function getReview(): Review |
91
|
|
|
{ |
92
|
|
|
return $this->review; |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
public function setReview(Review $review): void |
96
|
|
|
{ |
97
|
|
|
$this->review = $review; |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
public function getVariants(): Collection |
101
|
|
|
{ |
102
|
|
|
return $this->variants; |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
public function addVariant(Variant $variant): void |
106
|
|
|
{ |
107
|
|
|
if (!$this->variants->contains($variant)) { |
108
|
|
|
$this->variants[] = $variant; |
109
|
|
|
$variant->setProduct($this); |
110
|
|
|
} |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
public function removeVariant(Variant $variant): void |
114
|
|
|
{ |
115
|
|
|
if ($this->variants->contains($variant)) { |
116
|
|
|
$this->variants->removeElement($variant); |
117
|
|
|
} |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
public function getComments(): Collection |
121
|
|
|
{ |
122
|
|
|
return $this->comments; |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
public function addComment(ProductComment $comment): void |
126
|
|
|
{ |
127
|
|
|
if (!$this->comments->contains($comment)) { |
128
|
|
|
$this->comments[] = $comment; |
129
|
|
|
} |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
public function removeComment(ProductComment $comment): void |
133
|
|
|
{ |
134
|
|
|
if ($this->comments->contains($comment)) { |
135
|
|
|
$this->comments->removeElement($comment); |
136
|
|
|
} |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
public function getCategories(): Collection |
140
|
|
|
{ |
141
|
|
|
return $this->categories; |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
public function addCategory(Category $category): void |
145
|
|
|
{ |
146
|
|
|
if (!$this->categories->contains($category)) { |
147
|
|
|
$this->categories[] = $category; |
148
|
|
|
} |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
public function removeCategory(Category $category): void |
152
|
|
|
{ |
153
|
|
|
if ($this->categories->contains($category)) { |
154
|
|
|
$this->categories->removeElement($category); |
155
|
|
|
} |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
public function getTags(): Collection |
159
|
|
|
{ |
160
|
|
|
return $this->tags; |
161
|
|
|
} |
162
|
|
|
|
163
|
|
|
public function addTag(Tag $tag): void |
164
|
|
|
{ |
165
|
|
|
if (!$this->tags->contains($tag)) { |
166
|
|
|
$this->tags[] = $tag; |
167
|
|
|
} |
168
|
|
|
} |
169
|
|
|
|
170
|
|
|
public function removeTag(Tag $tag): void |
171
|
|
|
{ |
172
|
|
|
if ($this->tags->contains($tag)) { |
173
|
|
|
$this->tags->removeElement($tag); |
174
|
|
|
} |
175
|
|
|
} |
176
|
|
|
} |
177
|
|
|
|