| @@ 41-67 (lines=27) @@ | ||
| 38 | ||
| 39 | // build output json data as array |
|
| 40 | $data = []; |
|
| 41 | foreach ($records->get() as $comment) { |
|
| 42 | // comment can be passed from registered user (with unique ID) or from guest (without ID) |
|
| 43 | $userName = __('Unknown'); |
|
| 44 | $userAvatar = App::$Alias->scriptUrl . '/upload/user/avatar/small/default.jpg'; |
|
| 45 | $userObject = $comment->getUser(); |
|
| 46 | if ($userObject !== null) { |
|
| 47 | $userName = $userObject->getProfile()->nick; |
|
| 48 | $userAvatar = $userObject->getProfile()->getAvatarUrl('small'); |
|
| 49 | } else { |
|
| 50 | if (!Str::likeEmpty($comment->guest_name)) { |
|
| 51 | $userName = App::$Security->strip_tags($comment->guest_name); |
|
| 52 | } |
|
| 53 | } |
|
| 54 | ||
| 55 | // build output json data |
|
| 56 | $data[] = [ |
|
| 57 | 'id' => $comment->id, |
|
| 58 | 'text' => $comment->message, |
|
| 59 | 'date' => Date::convertToDatetime($comment->created_at, Date::FORMAT_TO_HOUR), |
|
| 60 | 'user' => [ |
|
| 61 | 'id' => $comment->user_id, |
|
| 62 | 'name' => $userName, |
|
| 63 | 'avatar' => $userAvatar |
|
| 64 | ], |
|
| 65 | 'answers' => $comment->getAnswerCount() |
|
| 66 | ]; |
|
| 67 | } |
|
| 68 | ||
| 69 | $this->response = json_encode([ |
|
| 70 | 'status' => 1, |
|
| @@ 90-115 (lines=26) @@ | ||
| 87 | ||
| 88 | // prepare output |
|
| 89 | $response = []; |
|
| 90 | foreach ($records->get() as $row) { |
|
| 91 | $userInstance = $row->getUser(); |
|
| 92 | $userName = __('Unknown'); |
|
| 93 | $userAvatar = App::$Alias->scriptUrl . '/upload/user/avatar/small/default.jpg'; |
|
| 94 | if ($userInstance !== null) { |
|
| 95 | if (!Str::likeEmpty($userInstance->getProfile()->nick)) { |
|
| 96 | $userName = $userInstance->getProfile()->nick; |
|
| 97 | } |
|
| 98 | $userAvatar = $userInstance->getProfile()->getAvatarUrl('small'); |
|
| 99 | } else { |
|
| 100 | if (!Str::likeEmpty($row->guest_name)) { |
|
| 101 | $userName = App::$Security->strip_tags($row->guest_name); |
|
| 102 | } |
|
| 103 | } |
|
| 104 | ||
| 105 | $response[] = [ |
|
| 106 | 'id' => $row->id, |
|
| 107 | 'text' => $row->message, |
|
| 108 | 'date' => Date::convertToDatetime($row->created_at, Date::FORMAT_TO_HOUR), |
|
| 109 | 'user' => [ |
|
| 110 | 'id' => $row->user_id, |
|
| 111 | 'name' => $userName, |
|
| 112 | 'avatar' => $userAvatar |
|
| 113 | ] |
|
| 114 | ]; |
|
| 115 | } |
|
| 116 | ||
| 117 | $this->response = json_encode([ |
|
| 118 | 'status' => 1, |
|