Conditions | 5 |
Paths | 4 |
Total Lines | 26 |
Code Lines | 13 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | <?php |
||
28 | public function wallAnswerCount(string $postIds): ?string |
||
29 | { |
||
30 | // set header |
||
31 | $this->setJsonHeader(); |
||
32 | // check query length |
||
33 | if (Any::isEmpty($postIds)) { |
||
34 | throw new NativeException('Wrong input count'); |
||
35 | } |
||
36 | |||
37 | $list = explode(',', $postIds); |
||
38 | $itemCount = count($list); |
||
39 | // empty or is biggest then limit? |
||
40 | if ($itemCount < 1 || $itemCount > self::ITEM_PER_PAGE) { |
||
|
|||
41 | throw new NativeException('Wrong input count'); |
||
42 | } |
||
43 | |||
44 | // prepare response |
||
45 | $response = []; |
||
46 | foreach ($list as $post) { |
||
47 | $response[$post] = WallAnswer::where('post_id', $post)->count(); |
||
48 | } |
||
49 | |||
50 | // display json data |
||
51 | return json_encode([ |
||
52 | 'status' => 1, |
||
53 | 'data' => $response |
||
54 | ]); |
||
57 |