|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Application\Model; |
|
6
|
|
|
|
|
7
|
|
|
use Application\Traits\HasCode; |
|
8
|
|
|
use Application\Traits\HasDescription; |
|
9
|
|
|
use Application\Traits\HasInternalRemarks; |
|
10
|
|
|
use Application\Traits\HasName; |
|
11
|
|
|
use Application\Traits\HasProductType; |
|
12
|
|
|
use Doctrine\ORM\Mapping as ORM; |
|
13
|
|
|
use GraphQL\Doctrine\Annotation as API; |
|
14
|
|
|
use Money\Money; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* An item that can be booked by a user |
|
18
|
|
|
* |
|
19
|
|
|
* @ORM\MappedSuperclass |
|
20
|
|
|
*/ |
|
21
|
|
|
abstract class AbstractProduct extends AbstractModel |
|
22
|
|
|
{ |
|
23
|
|
|
use HasName; |
|
24
|
|
|
use HasDescription; |
|
25
|
|
|
use HasCode; |
|
26
|
|
|
use HasInternalRemarks; |
|
27
|
|
|
use HasProductType; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* @var Money |
|
31
|
|
|
* |
|
32
|
|
|
* @ORM\Column(type="CHF", options={"default" = "0.00"}) |
|
33
|
|
|
*/ |
|
34
|
|
|
private $pricePerUnitCHF; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* @var Money |
|
38
|
|
|
* |
|
39
|
|
|
* @ORM\Column(type="EUR", options={"default" = "0.00"}) |
|
40
|
|
|
*/ |
|
41
|
|
|
private $pricePerUnitEUR; |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* @var bool |
|
45
|
|
|
* |
|
46
|
|
|
* @ORM\Column(type="boolean", options={"default" = 1}) |
|
47
|
|
|
*/ |
|
48
|
|
|
private $isActive = true; |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* @var null|Image |
|
52
|
|
|
* @ORM\OneToOne(targetEntity="Image", orphanRemoval=true) |
|
53
|
|
|
* @ORM\JoinColumn(name="image_id", referencedColumnName="id", onDelete="CASCADE") |
|
54
|
|
|
*/ |
|
55
|
|
|
private $image; |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* @var null|Image |
|
59
|
|
|
* @ORM\OneToOne(targetEntity="Image", orphanRemoval=true) |
|
60
|
|
|
* @ORM\JoinColumn(name="illustration_id", referencedColumnName="id", onDelete="CASCADE") |
|
61
|
|
|
*/ |
|
62
|
|
|
private $illustration; |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* @var string |
|
66
|
|
|
* |
|
67
|
|
|
* @ORM\Column(type="text", length=65535) |
|
68
|
|
|
*/ |
|
69
|
|
|
private $shortDescription = ''; |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* Constructor |
|
73
|
|
|
* |
|
74
|
|
|
* @param string $name |
|
75
|
|
|
*/ |
|
76
|
18 |
|
public function __construct(string $name = '') |
|
77
|
|
|
{ |
|
78
|
18 |
|
$this->setName($name); |
|
79
|
18 |
|
$this->pricePerUnitCHF = Money::CHF(0); |
|
80
|
18 |
|
$this->pricePerUnitEUR = Money::EUR(0); |
|
81
|
18 |
|
} |
|
82
|
|
|
|
|
83
|
|
|
/** |
|
84
|
|
|
* @API\Field(type="CHF") |
|
85
|
|
|
* |
|
86
|
|
|
* @return Money |
|
87
|
|
|
*/ |
|
88
|
9 |
|
public function getPricePerUnitCHF(): Money |
|
89
|
|
|
{ |
|
90
|
9 |
|
return $this->pricePerUnitCHF; |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
/** |
|
94
|
|
|
* @API\Input(type="CHF") |
|
95
|
|
|
* |
|
96
|
|
|
* @param Money $pricePerUnitCHF |
|
97
|
|
|
*/ |
|
98
|
7 |
|
public function setPricePerUnitCHF(Money $pricePerUnitCHF): void |
|
99
|
|
|
{ |
|
100
|
7 |
|
$this->pricePerUnitCHF = $pricePerUnitCHF; |
|
101
|
7 |
|
} |
|
102
|
|
|
|
|
103
|
|
|
/** |
|
104
|
|
|
* @API\Field(type="EUR") |
|
105
|
|
|
* |
|
106
|
|
|
* @return Money |
|
107
|
|
|
*/ |
|
108
|
1 |
|
public function getPricePerUnitEUR(): Money |
|
109
|
|
|
{ |
|
110
|
1 |
|
return $this->pricePerUnitEUR; |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
/** |
|
114
|
|
|
* @API\Input(type="EUR") |
|
115
|
|
|
* |
|
116
|
|
|
* @param Money $pricePerUnitEUR |
|
117
|
|
|
*/ |
|
118
|
7 |
|
public function setPricePerUnitEUR(Money $pricePerUnitEUR): void |
|
119
|
|
|
{ |
|
120
|
7 |
|
$this->pricePerUnitEUR = $pricePerUnitEUR; |
|
121
|
7 |
|
} |
|
122
|
|
|
|
|
123
|
|
|
/** |
|
124
|
|
|
* Whether this product can be bought |
|
125
|
|
|
* |
|
126
|
|
|
* @return bool |
|
127
|
|
|
*/ |
|
128
|
|
|
public function isActive(): bool |
|
129
|
|
|
{ |
|
130
|
|
|
return $this->isActive; |
|
131
|
|
|
} |
|
132
|
|
|
|
|
133
|
|
|
/** |
|
134
|
|
|
* Whether this product can be bought |
|
135
|
|
|
* |
|
136
|
|
|
* @param bool $isActive |
|
137
|
|
|
*/ |
|
138
|
|
|
public function setIsActive(bool $isActive): void |
|
139
|
|
|
{ |
|
140
|
|
|
$this->isActive = $isActive; |
|
141
|
|
|
} |
|
142
|
|
|
|
|
143
|
|
|
/** |
|
144
|
|
|
* @return null|Image |
|
145
|
|
|
*/ |
|
146
|
1 |
|
public function getImage(): ?Image |
|
147
|
|
|
{ |
|
148
|
1 |
|
return $this->image; |
|
149
|
|
|
} |
|
150
|
|
|
|
|
151
|
|
|
/** |
|
152
|
|
|
* @param null|Image $image |
|
153
|
|
|
*/ |
|
154
|
1 |
|
public function setImage(?Image $image): void |
|
155
|
|
|
{ |
|
156
|
|
|
// We must trigger lazy loading, otherwise Doctrine will seriously |
|
157
|
|
|
// mess up lifecycle callbacks and delete unrelated image on disk |
|
158
|
1 |
|
if ($this->image) { |
|
159
|
1 |
|
$this->image->getFilename(); |
|
160
|
|
|
} |
|
161
|
|
|
|
|
162
|
1 |
|
$this->image = $image; |
|
163
|
1 |
|
} |
|
164
|
|
|
|
|
165
|
|
|
/** |
|
166
|
|
|
* @return null|Image |
|
167
|
|
|
*/ |
|
168
|
|
|
public function getIllustration(): ?Image |
|
169
|
|
|
{ |
|
170
|
|
|
return $this->illustration; |
|
171
|
|
|
} |
|
172
|
|
|
|
|
173
|
|
|
/** |
|
174
|
|
|
* @param null|Image $illustration |
|
175
|
|
|
*/ |
|
176
|
|
|
public function setIllustration(?Image $illustration): void |
|
177
|
|
|
{ |
|
178
|
|
|
// We must trigger lazy loading, otherwise Doctrine will seriously |
|
179
|
|
|
// mess up lifecycle callbacks and delete unrelated illustration on disk |
|
180
|
|
|
if ($this->illustration) { |
|
181
|
|
|
$this->illustration->getFilename(); |
|
182
|
|
|
} |
|
183
|
|
|
|
|
184
|
|
|
$this->illustration = $illustration; |
|
185
|
|
|
} |
|
186
|
|
|
|
|
187
|
|
|
/** |
|
188
|
|
|
* Set shortDescription |
|
189
|
|
|
* |
|
190
|
|
|
* @param string $shortDescription |
|
191
|
|
|
*/ |
|
192
|
|
|
public function setShortDescription(string $shortDescription): void |
|
193
|
|
|
{ |
|
194
|
|
|
$this->shortDescription = $shortDescription; |
|
195
|
|
|
} |
|
196
|
|
|
|
|
197
|
|
|
/** |
|
198
|
|
|
* Get shortDescription |
|
199
|
|
|
* |
|
200
|
|
|
* @return string |
|
201
|
|
|
*/ |
|
202
|
|
|
public function getShortDescription(): string |
|
203
|
|
|
{ |
|
204
|
|
|
return $this->shortDescription; |
|
205
|
|
|
} |
|
206
|
|
|
} |
|
207
|
|
|
|