1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace VSV\GVQ_API\Question\Repositories\Entities; |
4
|
|
|
use Doctrine\ORM\Mapping as ORM; |
5
|
|
|
use Ramsey\Uuid\Uuid; |
6
|
|
|
use VSV\GVQ_API\Question\Models\Answer; |
7
|
|
|
use VSV\GVQ_API\Question\ValueObjects\NotEmptyString; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* @ORM\Entity() |
11
|
|
|
* @ORM\Table(name="answer") |
12
|
|
|
*/ |
13
|
|
|
class AnswerEntity extends Entity |
14
|
|
|
{ |
15
|
|
|
/** |
16
|
|
|
* @var string |
17
|
|
|
* |
18
|
|
|
* @ORM\Column(type="string", length=1024, nullable=false) |
19
|
|
|
*/ |
20
|
|
|
private $text; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @var bool |
24
|
|
|
* |
25
|
|
|
* @ORM\Column(type="boolean", nullable=false) |
26
|
|
|
*/ |
27
|
|
|
private $correct; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @var QuestionEntity |
31
|
|
|
* |
32
|
|
|
* @ORM\ManyToOne(targetEntity="QuestionEntity", inversedBy="answerEntities") |
33
|
|
|
* @ORM\JoinColumn(name="question_id", referencedColumnName="id") |
34
|
|
|
*/ |
35
|
|
|
private $questionEntity; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @param string $id |
39
|
|
|
* @param string $text |
40
|
|
|
* @param bool $correct |
41
|
|
|
*/ |
42
|
|
|
private function __construct( |
43
|
|
|
string $id, |
44
|
|
|
string $text, |
45
|
|
|
bool $correct |
46
|
|
|
) { |
47
|
|
|
parent::__construct($id); |
48
|
|
|
|
49
|
|
|
$this->text = $text; |
50
|
|
|
$this->correct = $correct; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @param Answer $answer |
55
|
|
|
* @return AnswerEntity |
56
|
|
|
*/ |
57
|
|
|
public static function fromAnswer(Answer $answer): AnswerEntity |
58
|
|
|
{ |
59
|
|
|
return new AnswerEntity( |
60
|
|
|
$answer->getId()->toString(), |
61
|
|
|
$answer->getText()->toNative(), |
62
|
|
|
$answer->isCorrect() |
63
|
|
|
); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @return Answer |
68
|
|
|
*/ |
69
|
|
|
public function toAnswer(): Answer |
70
|
|
|
{ |
71
|
|
|
return new Answer( |
72
|
|
|
Uuid::fromString($this->getId()), |
73
|
|
|
new NotEmptyString($this->getText()), |
74
|
|
|
$this->isCorrect() |
75
|
|
|
); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* @return string |
80
|
|
|
*/ |
81
|
|
|
public function getText(): string |
82
|
|
|
{ |
83
|
|
|
return $this->text; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* @param string $text |
88
|
|
|
*/ |
89
|
|
|
public function setText(string $text): void |
90
|
|
|
{ |
91
|
|
|
$this->text = $text; |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* @return bool |
96
|
|
|
*/ |
97
|
|
|
public function isCorrect(): bool |
98
|
|
|
{ |
99
|
|
|
return $this->correct; |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* @param bool $correct |
104
|
|
|
*/ |
105
|
|
|
public function setCorrect(bool $correct): void |
106
|
|
|
{ |
107
|
|
|
$this->correct = $correct; |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* @return QuestionEntity |
112
|
|
|
*/ |
113
|
|
|
public function getQuestionEntity(): QuestionEntity |
114
|
|
|
{ |
115
|
|
|
return $this->questionEntity; |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* @param QuestionEntity $questionEntity |
120
|
|
|
*/ |
121
|
|
|
public function setQuestionEntity(QuestionEntity $questionEntity): void |
122
|
|
|
{ |
123
|
|
|
$this->questionEntity = $questionEntity; |
124
|
|
|
} |
125
|
|
|
} |
126
|
|
|
|