1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Application\Model; |
6
|
|
|
|
7
|
|
|
use Application\Traits\HasCode; |
8
|
|
|
use Application\Traits\HasProductType; |
9
|
|
|
use Application\Traits\HasRichTextDescription; |
10
|
|
|
use Doctrine\ORM\Mapping as ORM; |
11
|
|
|
use Ecodev\Felix\Model\Traits\HasInternalRemarks; |
12
|
|
|
use Ecodev\Felix\Model\Traits\HasName; |
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 HasCode; |
24
|
|
|
use HasInternalRemarks; |
25
|
|
|
use HasName; |
26
|
|
|
use HasProductType; |
27
|
|
|
use HasRichTextDescription; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @ORM\Column(type="CHF", options={"default" = "0"}) |
31
|
|
|
*/ |
32
|
|
|
private \Money\Money $pricePerUnitCHF; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @ORM\Column(type="EUR", options={"default" = "0"}) |
36
|
|
|
*/ |
37
|
|
|
private \Money\Money $pricePerUnitEUR; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @ORM\Column(type="boolean", options={"default" = 1}) |
41
|
|
|
*/ |
42
|
|
|
private bool $isActive = true; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @ORM\OneToOne(targetEntity="Image", orphanRemoval=true) |
46
|
|
|
* @ORM\JoinColumn(name="image_id", referencedColumnName="id", onDelete="CASCADE") |
47
|
|
|
*/ |
48
|
|
|
private ?\Application\Model\Image $image = null; |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @ORM\OneToOne(targetEntity="Image", orphanRemoval=true) |
52
|
|
|
* @ORM\JoinColumn(name="illustration_id", referencedColumnName="id", onDelete="CASCADE") |
53
|
|
|
*/ |
54
|
|
|
private ?\Application\Model\Image $illustration = null; |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Constructor. |
58
|
|
|
*/ |
59
|
28 |
|
public function __construct(string $name = '') |
60
|
|
|
{ |
61
|
28 |
|
$this->setName($name); |
62
|
28 |
|
$this->pricePerUnitCHF = Money::CHF(0); |
63
|
28 |
|
$this->pricePerUnitEUR = Money::EUR(0); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @API\Field(type="CHF") |
68
|
|
|
*/ |
69
|
11 |
|
public function getPricePerUnitCHF(): Money |
70
|
|
|
{ |
71
|
11 |
|
return $this->pricePerUnitCHF; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* @API\Input(type="CHF") |
76
|
|
|
*/ |
77
|
8 |
|
public function setPricePerUnitCHF(Money $pricePerUnitCHF): void |
78
|
|
|
{ |
79
|
8 |
|
$this->pricePerUnitCHF = $pricePerUnitCHF; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* @API\Field(type="EUR") |
84
|
|
|
*/ |
85
|
1 |
|
public function getPricePerUnitEUR(): Money |
86
|
|
|
{ |
87
|
1 |
|
return $this->pricePerUnitEUR; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* @API\Input(type="EUR") |
92
|
|
|
*/ |
93
|
8 |
|
public function setPricePerUnitEUR(Money $pricePerUnitEUR): void |
94
|
|
|
{ |
95
|
8 |
|
$this->pricePerUnitEUR = $pricePerUnitEUR; |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* Whether this product can be bought. |
100
|
|
|
*/ |
101
|
|
|
public function isActive(): bool |
102
|
|
|
{ |
103
|
|
|
return $this->isActive; |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* Whether this product can be bought. |
108
|
|
|
*/ |
109
|
|
|
public function setIsActive(bool $isActive): void |
110
|
|
|
{ |
111
|
|
|
$this->isActive = $isActive; |
112
|
|
|
} |
113
|
|
|
|
114
|
1 |
|
public function getImage(): ?Image |
115
|
|
|
{ |
116
|
1 |
|
return $this->image; |
117
|
|
|
} |
118
|
|
|
|
119
|
1 |
|
public function setImage(?Image $image): void |
120
|
|
|
{ |
121
|
|
|
// We must trigger lazy loading, otherwise Doctrine will seriously |
122
|
|
|
// mess up lifecycle callbacks and delete unrelated image on disk |
123
|
1 |
|
if ($this->image) { |
124
|
1 |
|
$this->image->getFilename(); |
125
|
|
|
} |
126
|
|
|
|
127
|
1 |
|
$this->image = $image; |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
public function getIllustration(): ?Image |
131
|
|
|
{ |
132
|
|
|
return $this->illustration; |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
public function setIllustration(?Image $illustration): void |
136
|
|
|
{ |
137
|
|
|
// We must trigger lazy loading, otherwise Doctrine will seriously |
138
|
|
|
// mess up lifecycle callbacks and delete unrelated illustration on disk |
139
|
|
|
if ($this->illustration) { |
140
|
|
|
$this->illustration->getFilename(); |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
$this->illustration = $illustration; |
144
|
|
|
} |
145
|
|
|
} |
146
|
|
|
|