1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
|
3
|
|
|
namespace VSV\GVQ_API\Registration\Repositories\Entities; |
4
|
|
|
|
5
|
|
|
use Doctrine\ORM\Mapping as ORM; |
6
|
|
|
use Ramsey\Uuid\Uuid; |
7
|
|
|
use VSV\GVQ_API\Common\Repositories\Entities\Entity; |
8
|
|
|
use VSV\GVQ_API\Registration\Models\Registration; |
9
|
|
|
use VSV\GVQ_API\User\Repositories\Entities\UserEntity; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* @ORM\Entity() |
13
|
|
|
* @ORM\Table(name="registration") |
14
|
|
|
*/ |
15
|
|
|
class RegistrationEntity extends Entity |
16
|
|
|
{ |
17
|
|
|
/** |
18
|
|
|
* @var string |
19
|
|
|
* |
20
|
|
|
* @ORM\Column(type="string", name="hash_code", length=22, nullable=false) |
21
|
|
|
*/ |
22
|
|
|
private $hashCode; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @var UserEntity |
26
|
|
|
* |
27
|
|
|
* @ORM\OneToOne(targetEntity="VSV\GVQ_API\User\Repositories\Entities\UserEntity", fetch="EAGER") |
28
|
|
|
* @ORM\JoinColumn(name="user_id", referencedColumnName="id", nullable=false) |
29
|
|
|
*/ |
30
|
|
|
private $userEntity; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @var \DateTimeImmutable |
34
|
|
|
* |
35
|
|
|
* @ORM\Column(type="datetime",name="created_on", nullable=false) |
36
|
|
|
*/ |
37
|
|
|
private $createdOn; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @var bool |
41
|
|
|
* @ORM\Column(type="boolean", name="password_reset", nullable=false) |
42
|
|
|
*/ |
43
|
|
|
private $passwordReset; |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @param string $id |
47
|
|
|
* @param string $hashCode |
48
|
|
|
* @param UserEntity $userEntity |
49
|
|
|
* @param \DateTimeImmutable $createdOn |
50
|
|
|
* @param bool $passwordReset |
51
|
|
|
*/ |
52
|
|
|
public function __construct( |
53
|
|
|
string $id, |
54
|
|
|
string $hashCode, |
55
|
|
|
UserEntity $userEntity, |
56
|
|
|
\DateTimeImmutable $createdOn, |
57
|
|
|
bool $passwordReset |
58
|
|
|
) { |
59
|
|
|
parent::__construct($id); |
60
|
|
|
$this->hashCode = $hashCode; |
61
|
|
|
$this->userEntity = $userEntity; |
62
|
|
|
$this->createdOn = $createdOn; |
63
|
|
|
$this->passwordReset = $passwordReset; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @param Registration $registration |
69
|
|
|
* @return RegistrationEntity |
70
|
|
|
*/ |
71
|
|
|
public static function fromRegistration(Registration $registration): RegistrationEntity |
72
|
|
|
{ |
73
|
|
|
return new RegistrationEntity( |
74
|
|
|
$registration->getId()->toString(), |
75
|
|
|
$registration->getHashCode(), |
76
|
|
|
UserEntity::fromUser($registration->getUser()), |
77
|
|
|
$registration->getCreatedOn(), |
78
|
|
|
$registration->isPasswordReset() |
79
|
|
|
); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* @return Registration |
84
|
|
|
*/ |
85
|
|
|
public function toRegistration(): Registration |
86
|
|
|
{ |
87
|
|
|
return new Registration( |
88
|
|
|
Uuid::fromString($this->getId()), |
89
|
|
|
$this->getHashCode(), |
90
|
|
|
$this->getUserEntity()->toUser(), |
91
|
|
|
$this->getCreatedOn(), |
92
|
|
|
$this->isPasswordReset() |
93
|
|
|
); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* @return string |
98
|
|
|
*/ |
99
|
|
|
public function getHashCode(): string |
100
|
|
|
{ |
101
|
|
|
return $this->hashCode; |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* @return UserEntity |
106
|
|
|
*/ |
107
|
|
|
public function getUserEntity(): UserEntity |
108
|
|
|
{ |
109
|
|
|
return $this->userEntity; |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* @param UserEntity $userEntity |
114
|
|
|
*/ |
115
|
|
|
public function setUserEntity(UserEntity $userEntity): void |
116
|
|
|
{ |
117
|
|
|
$this->userEntity = $userEntity; |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* @return \DateTimeImmutable |
122
|
|
|
*/ |
123
|
|
|
public function getCreatedOn(): \DateTimeImmutable |
124
|
|
|
{ |
125
|
|
|
return $this->createdOn; |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
/** |
129
|
|
|
* @return bool |
130
|
|
|
*/ |
131
|
|
|
public function isPasswordReset(): bool |
132
|
|
|
{ |
133
|
|
|
return $this->passwordReset; |
134
|
|
|
} |
135
|
|
|
} |
136
|
|
|
|