1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Odiseo\SyliusReferralsPlugin\Entity; |
6
|
|
|
|
7
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
8
|
|
|
use Doctrine\Common\Collections\Collection; |
9
|
|
|
use Sylius\Component\Core\Model\ProductInterface; |
10
|
|
|
use Sylius\Component\Resource\Model\TimestampableTrait; |
11
|
|
|
|
12
|
|
|
class AffiliateReferral implements AffiliateReferralInterface |
13
|
|
|
{ |
14
|
|
|
use TimestampableTrait; |
15
|
|
|
|
16
|
|
|
protected ?int $id = null; |
17
|
|
|
protected ?string $tokenValue = null; |
18
|
|
|
protected ?string $rewardType = null; |
19
|
|
|
protected ?\DateTimeInterface $expiresAt = null; |
20
|
|
|
protected ?AffiliateInterface $affiliate = null; |
21
|
|
|
protected ?ProductInterface $product = null; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @psalm-var Collection<array-key, AffiliateReferralViewInterface> |
25
|
|
|
*/ |
26
|
|
|
protected Collection $views; |
27
|
|
|
|
28
|
|
|
public function __construct() |
29
|
|
|
{ |
30
|
|
|
$this->views = new ArrayCollection(); |
31
|
|
|
$this->createdAt = new \DateTime(); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
public function getId(): ?int |
35
|
|
|
{ |
36
|
|
|
return $this->id; |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
public function getTokenValue(): ?string |
40
|
|
|
{ |
41
|
|
|
return $this->tokenValue; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
public function setTokenValue(?string $tokenValue): void |
45
|
|
|
{ |
46
|
|
|
$this->tokenValue = $tokenValue; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
public function getRewardType(): ?string |
50
|
|
|
{ |
51
|
|
|
return $this->rewardType; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
public function setRewardType(?string $rewardType): void |
55
|
|
|
{ |
56
|
|
|
$this->rewardType = $rewardType; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
public function getExpiresAt(): ?\DateTimeInterface |
60
|
|
|
{ |
61
|
|
|
return $this->expiresAt; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
public function setExpiresAt(?\DateTimeInterface $expiresAt): void |
65
|
|
|
{ |
66
|
|
|
$this->expiresAt = $expiresAt; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
public function isExpired(): bool |
70
|
|
|
{ |
71
|
|
|
if ($this->expiresAt === null) { |
72
|
|
|
return false; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
$now = new \DateTime(); |
76
|
|
|
|
77
|
|
|
return $now > $this->expiresAt; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
public function getAffiliate(): ?AffiliateInterface |
81
|
|
|
{ |
82
|
|
|
return $this->affiliate; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
public function setAffiliate(?AffiliateInterface $affiliate): void |
86
|
|
|
{ |
87
|
|
|
$this->affiliate = $affiliate; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
public function getProduct(): ?ProductInterface |
91
|
|
|
{ |
92
|
|
|
return $this->product; |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
public function setProduct(?ProductInterface $product): void |
96
|
|
|
{ |
97
|
|
|
$this->product = $product; |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
public function getViews(): Collection |
101
|
|
|
{ |
102
|
|
|
return $this->views; |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
public function hasView(AffiliateReferralViewInterface $view): bool |
106
|
|
|
{ |
107
|
|
|
return $this->views->contains($view); |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
public function addView(AffiliateReferralViewInterface $view): void |
111
|
|
|
{ |
112
|
|
|
if (!$this->hasView($view)) { |
113
|
|
|
$this->views->add($view); |
114
|
|
|
$view->setAffiliateReferral($this); |
115
|
|
|
} |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
public function removeView(AffiliateReferralViewInterface $view): void |
119
|
|
|
{ |
120
|
|
|
if ($this->hasView($view)) { |
121
|
|
|
$this->views->removeElement($view); |
122
|
|
|
$view->setAffiliateReferral(null); |
123
|
|
|
} |
124
|
|
|
} |
125
|
|
|
} |
126
|
|
|
|