-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDataTableQuery.php
More file actions
69 lines (56 loc) · 1.78 KB
/
DataTableQuery.php
File metadata and controls
69 lines (56 loc) · 1.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<?php
/*
* This file is part of the Gesdinet MetronicDataTableBundle package.
*
* (c) Gesdinet <marcos@gesdinet.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Gesdinet\MetronicDataTableBundle;
/**
* A draw query from mDataTables plugin.
*
* @see https://keenthemes.com/metronic/documentation.html#sec14
*
* @property int $start Index of first row to return, zero-based.
* @property int $length Total number of rows to return (-1 to return all rows).
* @property Search $search Global search value.
* @property Order[] $order Columns ordering (zero-based column index and direction).
* @property array $customData Custom data from DataTables.
*/
class DataTableQuery extends ValueObject implements \JsonSerializable
{
protected $start;
protected $length;
protected $search;
protected $order;
protected $customData;
/**
* Initializing constructor.
*/
public function __construct(Parameters $params)
{
$this->start = (int) $params->start;
$this->length = (int) $params->length;
$this->search = new Search($params->search);
$this->order = array_map(fn (array $order) => new Order(
$order['field'],
$order['sort']
), $params->order);
$this->customData = $params->customData;
}
/**
* {@inheritdoc}
*/
public function jsonSerialize(): array
{
$callback = fn (\JsonSerializable $item) => $item->jsonSerialize();
return [
'start' => $this->start,
'length' => $this->length,
'search' => $this->search,
'order' => array_map($callback, $this->order),
];
}
}