|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Application\Model; |
|
6
|
|
|
|
|
7
|
|
|
use Application\DBAL\Types\ProductTypeType; |
|
8
|
|
|
use Application\Repository\UserRepository; |
|
9
|
|
|
use Application\Traits\HasBalance; |
|
10
|
|
|
use Application\Traits\HasBalanceInterface; |
|
11
|
|
|
use Application\Traits\HasProductType; |
|
12
|
|
|
use Application\Traits\HasQuantity; |
|
13
|
|
|
use Doctrine\ORM\Mapping as ORM; |
|
14
|
|
|
use Ecodev\Felix\Model\Traits\HasName; |
|
15
|
|
|
use GraphQL\Doctrine\Annotation as API; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* A single line in the shopping cart when making an order. |
|
19
|
|
|
* |
|
20
|
|
|
* @ORM\Entity(repositoryClass="Application\Repository\OrderLineRepository") |
|
21
|
|
|
*/ |
|
22
|
|
|
class OrderLine extends AbstractModel implements HasBalanceInterface |
|
23
|
|
|
{ |
|
24
|
|
|
use HasBalance; |
|
25
|
|
|
use HasName; |
|
26
|
|
|
use HasProductType; |
|
27
|
|
|
use HasQuantity; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* Additional emails for subscription for a company. |
|
31
|
|
|
* |
|
32
|
|
|
* @var string[] |
|
33
|
|
|
* @ORM\Column(type="json", options={"default" = "[]"}) |
|
34
|
|
|
*/ |
|
35
|
|
|
private array $additionalEmails = []; |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* @ORM\ManyToOne(targetEntity="Order", inversedBy="orderLines") |
|
39
|
|
|
* @ORM\JoinColumns({ |
|
40
|
|
|
* @ORM\JoinColumn(nullable=false, onDelete="CASCADE") |
|
41
|
|
|
* }) |
|
42
|
|
|
*/ |
|
43
|
|
|
private ?Order $order = null; |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* @ORM\ManyToOne(targetEntity="Product") |
|
47
|
|
|
* @ORM\JoinColumns({ |
|
48
|
|
|
* @ORM\JoinColumn(nullable=true, onDelete="SET NULL") |
|
49
|
|
|
* }) |
|
50
|
|
|
*/ |
|
51
|
|
|
private ?\Application\Model\Product $product = null; |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* @ORM\ManyToOne(targetEntity="Subscription") |
|
55
|
|
|
* @ORM\JoinColumns({ |
|
56
|
|
|
* @ORM\JoinColumn(nullable=true, onDelete="SET NULL") |
|
57
|
|
|
* }) |
|
58
|
|
|
*/ |
|
59
|
|
|
private ?\Application\Model\Subscription $subscription = null; |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* Constructor. |
|
63
|
|
|
*/ |
|
64
|
|
|
public function __construct() |
|
65
|
|
|
{ |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* @API\Exclude |
|
70
|
|
|
*/ |
|
71
|
17 |
|
public function setOrder(Order $order): void |
|
72
|
|
|
{ |
|
73
|
17 |
|
if ($this->order) { |
|
74
|
1 |
|
$this->order->orderLineRemoved($this); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
17 |
|
$this->order = $order; |
|
78
|
17 |
|
$order->orderLineAdded($this); |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
1 |
|
public function getOrder(): Order |
|
82
|
|
|
{ |
|
83
|
1 |
|
return $this->order; |
|
|
|
|
|
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
/** |
|
87
|
|
|
* Get related product, if it still exists in DB. |
|
88
|
|
|
*/ |
|
89
|
22 |
|
public function getProduct(): ?Product |
|
90
|
|
|
{ |
|
91
|
22 |
|
return $this->product; |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
/** |
|
95
|
|
|
* Set related product. |
|
96
|
|
|
*/ |
|
97
|
15 |
|
public function setProduct(?Product $product): void |
|
98
|
|
|
{ |
|
99
|
15 |
|
$this->product = $product; |
|
100
|
15 |
|
if ($product) { |
|
101
|
15 |
|
$this->subscription = null; |
|
102
|
15 |
|
$this->setName($product->getName()); |
|
103
|
|
|
} |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
/** |
|
107
|
|
|
* Get related subscription, if it still exists in DB. |
|
108
|
|
|
*/ |
|
109
|
16 |
|
public function getSubscription(): ?Subscription |
|
110
|
|
|
{ |
|
111
|
16 |
|
return $this->subscription; |
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
/** |
|
115
|
|
|
* Set related subscription. |
|
116
|
|
|
*/ |
|
117
|
9 |
|
public function setSubscription(?Subscription $subscription): void |
|
118
|
|
|
{ |
|
119
|
9 |
|
$this->subscription = $subscription; |
|
120
|
|
|
|
|
121
|
9 |
|
if ($subscription) { |
|
122
|
9 |
|
$this->product = null; |
|
123
|
9 |
|
$this->setName($subscription->getName()); |
|
124
|
|
|
} |
|
125
|
|
|
} |
|
126
|
|
|
|
|
127
|
3 |
|
public function setDonation(): void |
|
128
|
|
|
{ |
|
129
|
3 |
|
$this->product = null; |
|
130
|
3 |
|
$this->subscription = null; |
|
131
|
3 |
|
$this->setName('Don'); |
|
132
|
|
|
} |
|
133
|
|
|
|
|
134
|
|
|
/** |
|
135
|
|
|
* Additional emails for subscription for a company. |
|
136
|
|
|
* |
|
137
|
|
|
* @return string[] |
|
138
|
|
|
*/ |
|
139
|
13 |
|
public function getAdditionalEmails(): array |
|
140
|
|
|
{ |
|
141
|
13 |
|
return $this->additionalEmails; |
|
142
|
|
|
} |
|
143
|
|
|
|
|
144
|
|
|
/** |
|
145
|
|
|
* Additional emails for subscription for a company. |
|
146
|
|
|
* |
|
147
|
|
|
* @param string[] $additionalEmails |
|
148
|
|
|
*/ |
|
149
|
21 |
|
public function setAdditionalEmails(array $additionalEmails): void |
|
150
|
|
|
{ |
|
151
|
21 |
|
$this->additionalEmails = $additionalEmails; |
|
152
|
|
|
} |
|
153
|
|
|
|
|
154
|
|
|
/** |
|
155
|
|
|
* Create temporary users to give them immediate access to web, |
|
156
|
|
|
* until their access is confirmed permanently via a CSV import. |
|
157
|
|
|
*/ |
|
158
|
4 |
|
public function maybeGiveTemporaryAccess(): void |
|
159
|
|
|
{ |
|
160
|
4 |
|
$isDigital = $this->getSubscription() && ProductTypeType::includesDigital($this->getSubscription()->getType()); |
|
161
|
4 |
|
if (!$isDigital) { |
|
162
|
3 |
|
return; |
|
163
|
|
|
} |
|
164
|
|
|
|
|
165
|
2 |
|
foreach ($this->getAdditionalEmails() as $email) { |
|
166
|
|
|
/** @var UserRepository $userRepository */ |
|
167
|
1 |
|
$userRepository = _em()->getRepository(User::class); |
|
168
|
1 |
|
$user = $userRepository->getOrCreate($email); |
|
169
|
|
|
|
|
170
|
1 |
|
$user->setWebTemporaryAccess(true); |
|
171
|
|
|
} |
|
172
|
|
|
|
|
173
|
2 |
|
if ($this->getOwner()) { |
|
174
|
2 |
|
$this->getOwner()->setWebTemporaryAccess(true); |
|
175
|
|
|
} |
|
176
|
|
|
} |
|
177
|
|
|
} |
|
178
|
|
|
|