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 integer |
29
|
|
|
* |
30
|
|
|
* @ORM\Column(name="id", type="integer") |
31
|
|
|
* @ORM\Id |
32
|
|
|
* @ORM\GeneratedValue(strategy="IDENTITY") |
33
|
|
|
*/ |
34
|
|
|
private $id; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @ORM\ManyToOne(targetEntity="Address") |
38
|
|
|
* @ORM\JoinColumn(name="address_id", referencedColumnName="id") |
39
|
|
|
*/ |
40
|
|
|
private $address; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @var string |
44
|
|
|
* |
45
|
|
|
* @ORM\Column(name="current_identifier", type="string", length=36, nullable=true, unique=true) |
46
|
|
|
*/ |
47
|
|
|
private $identifier; |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @var string |
51
|
|
|
* |
52
|
|
|
* @ORM\Column(name="previous_identifier", type="string", length=36, nullable=true, unique=true) |
53
|
|
|
*/ |
54
|
|
|
private $previousIdentifier; |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @var string |
58
|
|
|
* |
59
|
|
|
* @ORM\Column(name="address_type", type="string", length = 10) |
60
|
|
|
*/ |
61
|
|
|
private $addressType; |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* Date of last export |
65
|
|
|
* |
66
|
|
|
* No getter / setter needed -> read access is in AddressChange repo and update in exporter code |
67
|
|
|
* |
68
|
|
|
* @var \DateTime |
69
|
|
|
* |
70
|
|
|
* @ORM\Column(name="export_date", type="datetime", nullable=true) |
71
|
|
|
*/ |
72
|
|
|
private $exportDate; |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* When this was created |
76
|
|
|
* |
77
|
|
|
* No getter / setter needed, modification is in AddressChange repo |
78
|
|
|
* |
79
|
|
|
* @var \DateTime |
80
|
|
|
* @ORM\Column(type="datetime") |
81
|
|
|
*/ |
82
|
|
|
private $createdAt; |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* When this was last modified |
86
|
|
|
* |
87
|
|
|
* No getter / setter needed, modification is in AddressChange repo |
88
|
|
|
* |
89
|
|
|
* @var \DateTime |
90
|
|
|
* @ORM\Column(type="datetime") |
91
|
|
|
*/ |
92
|
|
|
private $modifiedAt; |
93
|
|
|
|
94
|
6 |
|
public function __construct( string $addressType ) { |
95
|
6 |
|
$this->createdAt = new \DateTime(); |
96
|
6 |
|
$this->modifiedAt = new \DateTime(); |
97
|
6 |
|
$this->addressType = $addressType; |
98
|
6 |
|
if ($this->identifier === null) { |
99
|
6 |
|
$this->generateUuid(); |
100
|
|
|
} |
101
|
6 |
|
} |
102
|
|
|
|
103
|
6 |
|
private function generateUuid(): void { |
104
|
6 |
|
$this->identifier = Uuid::uuid4()->toString(); |
105
|
6 |
|
} |
106
|
|
|
|
107
|
3 |
|
public function updateAddressIdentifier(): void { |
108
|
3 |
|
$this->previousIdentifier = $this->getCurrentIdentifier(); |
109
|
3 |
|
$this->generateUuid(); |
110
|
3 |
|
} |
111
|
|
|
|
112
|
6 |
|
public function getCurrentIdentifier(): string { |
113
|
6 |
|
if ($this->identifier === null) { |
114
|
|
|
$this->generateUuid(); |
115
|
|
|
} |
116
|
6 |
|
return $this->identifier; |
117
|
|
|
} |
118
|
|
|
|
119
|
3 |
|
public function getPreviousIdentifier(): ?string { |
120
|
3 |
|
return $this->previousIdentifier; |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
public function getAddress(): Address { |
124
|
|
|
return $this->address; |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
public function setAddress( Address $address ) { |
128
|
|
|
$this->address = $address; |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
public function getAddressType(): string { |
132
|
|
|
return $this->addressType; |
133
|
|
|
} |
134
|
|
|
} |
135
|
|
|
|