@@ 159-179 (lines=21) @@ | ||
156 | * |
|
157 | * @throws \Exception |
|
158 | */ |
|
159 | private function mapComment($data, $topic) |
|
160 | { |
|
161 | $comment = new Comment(); |
|
162 | $comment->setId($data->getField('id')); |
|
163 | $comment->setMessage($data->getField('message')); |
|
164 | $comment->setReactionsCount($data->getField('reactions')->getMetaData()['summary']['total_count']); |
|
165 | $comment->setCreatedTime($data->getField('created_time')); |
|
166 | $comment->setTopicId($topic->getField('id')); |
|
167 | ||
168 | $dataArray = $data->asArray(); |
|
169 | if (array_key_exists('from', $dataArray)) { |
|
170 | $user = $this->mapUser($dataArray['from']); |
|
171 | $user->addComment($comment); |
|
172 | ||
173 | $comment->setUser($user); |
|
174 | } |
|
175 | ||
176 | $this->comments->add($comment, $comment->getId()); |
|
177 | ||
178 | return $comment; |
|
179 | } |
|
180 | ||
181 | /** |
|
182 | * Map reply data from API feed to Reply object. |
|
@@ 190-211 (lines=22) @@ | ||
187 | * |
|
188 | * @throws \Exception |
|
189 | */ |
|
190 | private function mapReply($data, $topic, $comment) |
|
191 | { |
|
192 | $reply = new Reply(); |
|
193 | $reply->setId($data->getField('id')); |
|
194 | $reply->setMessage($data->getField('message')); |
|
195 | $reply->setReactionsCount($data->getField('reactions')->getMetaData()['summary']['total_count']); |
|
196 | $reply->setCreatedTime($data->getField('created_time')); |
|
197 | $reply->setTopicId($topic->getField('id')); |
|
198 | $reply->setCommentId($comment->getField('id')); |
|
199 | ||
200 | $dataArray = $data->asArray(); |
|
201 | if (array_key_exists('from', $dataArray)) { |
|
202 | $user = $this->mapUser($dataArray['from']); |
|
203 | $user->addReply($reply); |
|
204 | ||
205 | $reply->setUser($user); |
|
206 | } |
|
207 | ||
208 | $this->replies->add($reply, $reply->getId()); |
|
209 | ||
210 | return $reply; |
|
211 | } |
|
212 | ||
213 | /** |
|
214 | * Map user's data from API feed to User object. |