1 | <?php |
||
16 | class Survey |
||
17 | { |
||
18 | use ORMBehaviors\Timestampable\Timestampable; |
||
19 | |||
20 | /** |
||
21 | * @var int |
||
22 | * |
||
23 | * @ORM\Column(type="integer") |
||
24 | * @ORM\Id |
||
25 | * @ORM\GeneratedValue(strategy="AUTO") |
||
26 | * @Groups({"group1"}) |
||
27 | */ |
||
28 | private $id; |
||
29 | |||
30 | /** |
||
31 | * @var SurveyType |
||
32 | * @Assert\Type("object") |
||
33 | * @Assert\Valid |
||
34 | * @ORM\ManyToOne(targetEntity="SurveyType", inversedBy="surveys") |
||
35 | * @Groups({"group1"}) |
||
36 | */ |
||
37 | private $type; |
||
38 | |||
39 | /** |
||
40 | * @var string |
||
41 | * @Assert\NotBlank() |
||
42 | * @Assert\Type("string") |
||
43 | * @Assert\Length( |
||
44 | * max = 500 |
||
45 | * ) |
||
46 | * @ORM\Column(type="string") |
||
47 | * @Groups({"group1"}) |
||
48 | */ |
||
49 | private $status = 'current'; |
||
50 | |||
51 | /** |
||
52 | * @var User |
||
53 | * @Assert\Type("object") |
||
54 | * @Assert\Valid |
||
55 | * @ORM\ManyToOne(targetEntity="User", inversedBy="surveys") |
||
56 | */ |
||
57 | private $user; |
||
58 | |||
59 | /** |
||
60 | * @var ArrayCollection[SurveyQuestion] |
||
61 | * @ORM\ManyToMany(targetEntity="SurveyQuestion", mappedBy="surveys") |
||
62 | */ |
||
63 | private $questions; |
||
64 | |||
65 | /** |
||
66 | * @var ArrayCollection[SurveyAnswer] |
||
67 | * @ORM\OneToMany(targetEntity="SurveyAnswer", mappedBy="survey") |
||
68 | * @Groups({"group2"}) |
||
69 | */ |
||
70 | private $answers; |
||
71 | |||
72 | 1 | public function __construct() |
|
73 | { |
||
74 | 1 | $this->questions = new ArrayCollection(); |
|
75 | 1 | $this->answers = new ArrayCollection(); |
|
76 | 1 | } |
|
77 | |||
78 | /** |
||
79 | * Get id. |
||
80 | * |
||
81 | * @return int |
||
82 | */ |
||
83 | 3 | public function getId() |
|
84 | { |
||
85 | 3 | return $this->id; |
|
86 | } |
||
87 | |||
88 | /** |
||
89 | * Set type. |
||
90 | * |
||
91 | * @param SurveyType $type |
||
92 | * |
||
93 | * @return Survey |
||
94 | */ |
||
95 | 1 | public function setType(SurveyType $type) |
|
96 | { |
||
97 | 1 | $this->type = $type; |
|
98 | 1 | $questions = $type->getQuestions(); |
|
99 | 1 | foreach ($questions as $question) { |
|
100 | 1 | $this->addQuestion($question); |
|
101 | } |
||
102 | |||
103 | 1 | return $this; |
|
104 | } |
||
105 | |||
106 | /** |
||
107 | * Get type. |
||
108 | * |
||
109 | * @return SurveyType |
||
110 | */ |
||
111 | 6 | public function getType() |
|
112 | { |
||
113 | 6 | return $this->type; |
|
114 | } |
||
115 | |||
116 | /** |
||
117 | * Set status. |
||
118 | * |
||
119 | * @param string $status |
||
120 | * |
||
121 | * @return Survey |
||
122 | */ |
||
123 | 1 | public function setStatus($status) |
|
124 | { |
||
125 | 1 | $this->status = $status; |
|
126 | |||
127 | 1 | return $this; |
|
128 | } |
||
129 | |||
130 | /** |
||
131 | * Get status. |
||
132 | * |
||
133 | * @return string |
||
134 | */ |
||
135 | 5 | public function getStatus() |
|
136 | { |
||
137 | 5 | return $this->status; |
|
138 | } |
||
139 | |||
140 | /** |
||
141 | * Set user. |
||
142 | * |
||
143 | * @param User $user |
||
144 | * |
||
145 | * @return Survey |
||
146 | */ |
||
147 | 1 | public function setUser(User $user) |
|
148 | { |
||
149 | 1 | $this->user = $user; |
|
150 | |||
151 | 1 | return $this; |
|
152 | } |
||
153 | |||
154 | /** |
||
155 | * Get user. |
||
156 | * |
||
157 | * @return User |
||
158 | */ |
||
159 | 4 | public function getUser() |
|
160 | { |
||
161 | 4 | return $this->user; |
|
162 | } |
||
163 | |||
164 | /** |
||
165 | * @param SurveyQuestion $question |
||
166 | * |
||
167 | * @return Survey |
||
168 | */ |
||
169 | 1 | public function addQuestion(SurveyQuestion $question) |
|
170 | { |
||
171 | 1 | if (!$this->questions->contains($question)) { |
|
172 | 1 | $this->questions->add($question); |
|
173 | 1 | $question->addSurvey($this); |
|
174 | } |
||
175 | |||
176 | 1 | return $this; |
|
177 | } |
||
178 | |||
179 | /** |
||
180 | * Get Questions. |
||
181 | * |
||
182 | * @return ArrayCollection |
||
183 | */ |
||
184 | public function getQuestions() |
||
188 | |||
189 | /** |
||
190 | * Get Questions. |
||
191 | * |
||
192 | * @return ArrayCollection |
||
193 | */ |
||
194 | public function getAnswers() |
||
195 | { |
||
196 | return $this->answers; |
||
197 | } |
||
198 | |||
199 | /** |
||
200 | * Get DateTime. |
||
201 | * |
||
202 | * @return \DateTime |
||
203 | * @Groups({"group1", "group2"}) |
||
204 | */ |
||
205 | 3 | public function getCreatedAt() |
|
209 | |||
210 | /** |
||
211 | * Get DateTime. |
||
212 | * |
||
213 | * @return \DateTime |
||
214 | * @Groups({"group1", "group2"}) |
||
215 | */ |
||
216 | 4 | public function getUpdatedAt() |
|
220 | } |
||
221 |