Conditions | 5 |
Paths | 6 |
Total Lines | 31 |
Code Lines | 26 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
22 | private function transform($item) |
||
23 | { |
||
24 | $topic = new Topic(); |
||
25 | $topic->id = $item->tid; |
||
26 | $topic->title = $item->title; |
||
27 | $topic->contest_id = $item->cid; |
||
28 | $topic->problem_id = $item->pid; |
||
29 | if (! $topic->contest_id) { |
||
30 | $topic->contest_id = 0; |
||
31 | } |
||
32 | $user = app(UserService::class)->findByName($item->author_id); |
||
33 | $topic->user_id = $user->id; |
||
34 | $topic->save(); |
||
35 | |||
36 | $replies = $this->table('reply')->where('topic_id', $item->tid)->orderBy('rid', 'asc')->get(); |
||
37 | $isFirst = true; |
||
38 | foreach ($replies as $reply) { |
||
39 | if ($isFirst && $item->author_id === $reply->author_id) { |
||
40 | $topic->content = $reply->content; |
||
41 | $topic->created_at = $reply->time; |
||
42 | $topic->save(); |
||
43 | $isFirst = false; |
||
44 | continue; |
||
45 | } |
||
46 | $newReply = new Reply(); |
||
47 | $newReply->topic_id = $topic->id; |
||
48 | $newReply->created_at = $reply->time; |
||
49 | $newReply->content = $reply->content; |
||
50 | $author = app(UserService::class)->findByName($reply->author_id); |
||
51 | $newReply->user_id = $author->id; |
||
52 | $newReply->save(); |
||
53 | } |
||
56 |