1 | <?php |
||
2 | |||
3 | |||
4 | namespace Apps\Controller\Api\Profile; |
||
5 | |||
6 | use Apps\ActiveRecord\WallAnswer; |
||
7 | use Ffcms\Core\Exception\NativeException; |
||
8 | use Ffcms\Core\Helper\Type\Any; |
||
9 | use Ffcms\Core\Network\Request; |
||
10 | use Ffcms\Core\Network\Response; |
||
11 | |||
12 | /** |
||
13 | * Trait ActionWallAnswerCount |
||
14 | * @package Apps\Controller\Api\Profile |
||
15 | * @property Response $response |
||
16 | * @property Request $request |
||
17 | * @method void setJsonHeader() |
||
18 | */ |
||
19 | trait ActionWallAnswerCount |
||
20 | { |
||
21 | |||
22 | /** |
||
23 | * Get wall answer's count by post-ids list |
||
24 | * @param string $postIds |
||
25 | * @throws NativeException |
||
26 | * @return string |
||
27 | */ |
||
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) { |
||
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
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 | ]); |
||
55 | } |
||
56 | } |
||
57 |