1
|
|
|
<?php |
2
|
|
|
namespace WebServCo\Framework\DataTables; |
3
|
|
|
|
4
|
|
|
use WebServCo\Framework\ArrayObject\Items; |
5
|
|
|
|
6
|
|
|
class RequestHelper extends AbstractHelper |
7
|
|
|
{ |
8
|
|
|
public static function init($data, $required = []) |
9
|
|
|
{ |
10
|
|
|
parent::init($data, ['draw', 'columns', 'order', 'start', 'length', 'search']); |
11
|
|
|
|
12
|
|
|
foreach (['columns', 'order', 'search'] as $item) { |
13
|
|
|
if (!is_array($data[$item])) { |
14
|
|
|
throw new \InvalidArgumentException(sprintf('Invalid parameter: %s', $item)); |
15
|
|
|
} |
16
|
|
|
} |
17
|
|
|
|
18
|
|
|
$columns = new Items(new ColumnArrayObject()); |
19
|
|
|
foreach ($data['columns'] as $item) { |
20
|
|
|
$columnItem = new Column( |
21
|
|
|
isset($item['data']) ? $item['data'] : null, |
22
|
|
|
isset($item['name']) ? $item['name'] : null, |
23
|
|
|
isset($item['searchable']) ? $item['searchable'] : null, |
24
|
|
|
isset($item['orderable']) ? $item['orderable'] : null, |
25
|
|
|
SearchHelper::init($item['search']) |
26
|
|
|
); |
27
|
|
|
$columns->set(null, $columnItem); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
$order = new Items(new OrderArrayObject()); |
31
|
|
|
foreach ($data['order'] as $item) { |
32
|
|
|
$orderItem = new Order( |
33
|
|
|
isset($item['column']) ? $item['column'] : null, |
34
|
|
|
isset($item['dir']) ? $item['dir'] : null |
35
|
|
|
); |
36
|
|
|
$order->set(null, $orderItem); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
return new Request( |
40
|
|
|
$data['draw'], |
41
|
|
|
$columns, |
42
|
|
|
$order, |
43
|
|
|
$data['start'], |
44
|
|
|
$data['length'], |
45
|
|
|
SearchHelper::init($data['search']) |
46
|
|
|
); |
47
|
|
|
} |
48
|
|
|
} |
49
|
|
|
|