Total Complexity | 5 |
Total Lines | 52 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | <?php |
||
5 | class HandleListAction |
||
6 | { |
||
7 | /** |
||
8 | * @param $table |
||
9 | * @param $data |
||
10 | * @param $responsesFields |
||
11 | * @param $ctrl |
||
12 | * @return array |
||
13 | */ |
||
14 | public static function handle($table, $data, $responsesFields, $ctrl) |
||
15 | { |
||
16 | $rows = self::sortRows($table, $data); |
||
17 | if ($rows) { |
||
18 | return self::handleRows($responsesFields, $rows); |
||
19 | } |
||
20 | $result = ApiResponder::makeResult(0, 'No data found !'); |
||
21 | $result['data'] = []; |
||
22 | ApiResponder::send($result, request()->all(), $ctrl); |
||
23 | } |
||
24 | |||
25 | /** |
||
26 | * @param $responsesFields |
||
27 | * @param $rows |
||
28 | * @return array |
||
29 | */ |
||
30 | private static function handleRows($responsesFields, $rows) |
||
31 | { |
||
32 | foreach ($rows as &$row) { |
||
33 | HandleDetailsAction::handleFile($row, $responsesFields); |
||
34 | } |
||
35 | |||
36 | $result = ApiResponder::makeResult(1, 'success'); |
||
37 | $result['data'] = $rows; |
||
38 | |||
39 | return $result; |
||
40 | } |
||
41 | |||
42 | |||
43 | /** |
||
44 | * @param $table |
||
45 | * @param $data |
||
46 | * @return mixed |
||
47 | */ |
||
48 | private static function sortRows($table, $data) |
||
57 | } |
||
58 | |||
59 | } |