|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare( strict_types = 1 ); |
|
4
|
|
|
|
|
5
|
|
|
namespace WMDE\Fundraising\Entities; |
|
6
|
|
|
|
|
7
|
|
|
use Doctrine\ORM\Mapping as ORM; |
|
8
|
|
|
use Ramsey\Uuid\Uuid; |
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* @since 8.0 |
|
12
|
|
|
* |
|
13
|
|
|
* @ORM\Table( |
|
14
|
|
|
* name="address_change", |
|
15
|
|
|
* indexes={ |
|
16
|
|
|
* @ORM\Index(name="ac_export_date", columns={"export_date"}) |
|
17
|
|
|
* } |
|
18
|
|
|
* ) |
|
19
|
|
|
* @ORM\Entity |
|
20
|
|
|
*/ |
|
21
|
|
|
class AddressChange { |
|
22
|
|
|
|
|
23
|
|
|
public const ADDRESS_TYPE_PERSON = 'person'; |
|
24
|
|
|
|
|
25
|
|
|
public const ADDRESS_TYPE_COMPANY = 'company'; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* @var boolean |
|
29
|
|
|
* |
|
30
|
|
|
* @ORM\Column(name="donation_receipt", type="boolean", nullable=false) |
|
31
|
|
|
*/ |
|
32
|
|
|
private $donationReceipt = false; |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* @var integer |
|
36
|
|
|
* |
|
37
|
|
|
* @ORM\Column(name="id", type="integer") |
|
38
|
|
|
* @ORM\Id |
|
39
|
|
|
* @ORM\GeneratedValue(strategy="IDENTITY") |
|
40
|
|
|
*/ |
|
41
|
|
|
private $id; |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* @ORM\ManyToOne(targetEntity="Address") |
|
45
|
|
|
* @ORM\JoinColumn(name="address_id", referencedColumnName="id") |
|
46
|
|
|
*/ |
|
47
|
|
|
private $address; |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* @var string |
|
51
|
|
|
* |
|
52
|
|
|
* @ORM\Column(name="current_identifier", type="string", length=36, nullable=true, unique=true) |
|
53
|
|
|
*/ |
|
54
|
|
|
private $identifier; |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* @var string |
|
58
|
|
|
* |
|
59
|
|
|
* @ORM\Column(name="previous_identifier", type="string", length=36, nullable=true, unique=true) |
|
60
|
|
|
*/ |
|
61
|
|
|
private $previousIdentifier; |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* @var string |
|
65
|
|
|
* |
|
66
|
|
|
* @ORM\Column(name="address_type", type="string", length = 10) |
|
67
|
|
|
*/ |
|
68
|
|
|
private $addressType; |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* Date of last export |
|
72
|
|
|
* |
|
73
|
|
|
* No getter / setter needed -> read access is in AddressChange repo and update in exporter code |
|
74
|
|
|
* |
|
75
|
|
|
* @var \DateTime |
|
76
|
|
|
* |
|
77
|
|
|
* @ORM\Column(name="export_date", type="datetime", nullable=true) |
|
78
|
|
|
*/ |
|
79
|
|
|
private $exportDate; |
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* When this was created |
|
83
|
|
|
* |
|
84
|
|
|
* No getter / setter needed, modification is in AddressChange repo |
|
85
|
|
|
* |
|
86
|
|
|
* @var \DateTime |
|
87
|
|
|
* @ORM\Column(name="created_at", type="datetime") |
|
88
|
|
|
*/ |
|
89
|
|
|
private $createdAt; |
|
90
|
|
|
|
|
91
|
|
|
/** |
|
92
|
|
|
* When this was last modified |
|
93
|
|
|
* |
|
94
|
|
|
* No getter / setter needed, modification is in AddressChange repo |
|
95
|
|
|
* |
|
96
|
|
|
* @var \DateTime |
|
97
|
|
|
* @ORM\Column(name="modified_at", type="datetime") |
|
98
|
|
|
*/ |
|
99
|
|
|
private $modifiedAt; |
|
100
|
|
|
|
|
101
|
6 |
|
public function __construct( string $addressType ) { |
|
102
|
6 |
|
$this->createdAt = new \DateTime(); |
|
103
|
6 |
|
$this->modifiedAt = new \DateTime(); |
|
104
|
6 |
|
$this->addressType = $addressType; |
|
105
|
6 |
|
if ($this->identifier === null) { |
|
106
|
6 |
|
$this->generateUuid(); |
|
107
|
|
|
} |
|
108
|
6 |
|
} |
|
109
|
|
|
|
|
110
|
6 |
|
private function generateUuid(): void { |
|
111
|
6 |
|
$this->identifier = Uuid::uuid4()->toString(); |
|
112
|
6 |
|
} |
|
113
|
|
|
|
|
114
|
3 |
|
public function updateAddressIdentifier(): void { |
|
115
|
3 |
|
$this->previousIdentifier = $this->getCurrentIdentifier(); |
|
116
|
3 |
|
$this->generateUuid(); |
|
117
|
3 |
|
} |
|
118
|
|
|
|
|
119
|
6 |
|
public function getCurrentIdentifier(): string { |
|
120
|
6 |
|
if ($this->identifier === null) { |
|
121
|
|
|
$this->generateUuid(); |
|
122
|
|
|
} |
|
123
|
6 |
|
return $this->identifier; |
|
124
|
|
|
} |
|
125
|
|
|
|
|
126
|
3 |
|
public function getPreviousIdentifier(): ?string { |
|
127
|
3 |
|
return $this->previousIdentifier; |
|
128
|
|
|
} |
|
129
|
|
|
|
|
130
|
|
|
public function isOptedIntoDonationReceipt() { |
|
131
|
|
|
return $this->donationReceipt; |
|
132
|
|
|
} |
|
133
|
|
|
|
|
134
|
|
|
public function setDonationReceipt( $donationReceipt ) { |
|
135
|
|
|
$this->donationReceipt = $donationReceipt; |
|
136
|
|
|
} |
|
137
|
|
|
|
|
138
|
|
|
public function getAddress(): ?Address { |
|
139
|
|
|
return $this->address; |
|
140
|
|
|
} |
|
141
|
|
|
|
|
142
|
|
|
public function setAddress( Address $address ) { |
|
143
|
|
|
$this->address = $address; |
|
144
|
|
|
} |
|
145
|
|
|
|
|
146
|
|
|
public function getAddressType(): string { |
|
147
|
|
|
return $this->addressType; |
|
148
|
|
|
} |
|
149
|
|
|
} |
|
150
|
|
|
|