|
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\ManyToMany(targetEntity=Category::class, mappedBy="products", cascade={"persist"}) |
|
39
|
|
|
*/ |
|
40
|
|
|
private $categories; |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* @ORM\ManyToMany(targetEntity=Tag::class, inversedBy="products", cascade={"persist"}) |
|
44
|
|
|
*/ |
|
45
|
|
|
private $tags; |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* @ORM\OneToOne(targetEntity=Review::class, mappedBy="product", cascade={"persist"}) |
|
49
|
|
|
*/ |
|
50
|
|
|
private $review; |
|
51
|
|
|
|
|
52
|
|
|
public function __construct() |
|
53
|
|
|
{ |
|
54
|
|
|
$this->variants = new ArrayCollection(); |
|
55
|
|
|
$this->categories = new ArrayCollection(); |
|
56
|
|
|
$this->tags = new ArrayCollection(); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
public function getId(): ?int |
|
60
|
|
|
{ |
|
61
|
|
|
return $this->id; |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
public function getName(): ?string |
|
65
|
|
|
{ |
|
66
|
|
|
return $this->name; |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
public function setName(?string $name): void |
|
70
|
|
|
{ |
|
71
|
|
|
$this->name = $name; |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
public function getBrand(): Brand |
|
75
|
|
|
{ |
|
76
|
|
|
return $this->brand; |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
public function setBrand(Brand $brand): void |
|
80
|
|
|
{ |
|
81
|
|
|
$this->brand = $brand; |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
public function getReview(): Review |
|
85
|
|
|
{ |
|
86
|
|
|
return $this->review; |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
public function setReview(Review $review): void |
|
90
|
|
|
{ |
|
91
|
|
|
$this->review = $review; |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
public function getVariants(): Collection |
|
95
|
|
|
{ |
|
96
|
|
|
return $this->variants; |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
public function addVariant(Variant $variant): void |
|
100
|
|
|
{ |
|
101
|
|
|
if (!$this->variants->contains($variant)) { |
|
102
|
|
|
$this->variants[] = $variant; |
|
103
|
|
|
$variant->setProduct($this); |
|
104
|
|
|
} |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
public function removeVariant(Variant $variant): void |
|
108
|
|
|
{ |
|
109
|
|
|
if ($this->variants->contains($variant)) { |
|
110
|
|
|
$this->variants->removeElement($variant); |
|
111
|
|
|
} |
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
public function getCategories(): Collection |
|
115
|
|
|
{ |
|
116
|
|
|
return $this->categories; |
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
|
|
public function addCategory(Category $category): void |
|
120
|
|
|
{ |
|
121
|
|
|
if (!$this->categories->contains($category)) { |
|
122
|
|
|
$this->categories[] = $category; |
|
123
|
|
|
} |
|
124
|
|
|
} |
|
125
|
|
|
|
|
126
|
|
|
public function removeCategory(Category $category): void |
|
127
|
|
|
{ |
|
128
|
|
|
if ($this->categories->contains($category)) { |
|
129
|
|
|
$this->categories->removeElement($category); |
|
130
|
|
|
} |
|
131
|
|
|
} |
|
132
|
|
|
|
|
133
|
|
|
public function getTags(): Collection |
|
134
|
|
|
{ |
|
135
|
|
|
return $this->tags; |
|
136
|
|
|
} |
|
137
|
|
|
|
|
138
|
|
|
public function addTag(Tag $tag): void |
|
139
|
|
|
{ |
|
140
|
|
|
if (!$this->tags->contains($tag)) { |
|
141
|
|
|
$this->tags[] = $tag; |
|
142
|
|
|
} |
|
143
|
|
|
} |
|
144
|
|
|
|
|
145
|
|
|
public function removeTag(Tag $tag): void |
|
146
|
|
|
{ |
|
147
|
|
|
if ($this->tags->contains($tag)) { |
|
148
|
|
|
$this->tags->removeElement($tag); |
|
149
|
|
|
} |
|
150
|
|
|
} |
|
151
|
|
|
} |
|
152
|
|
|
|