-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathResponse.php
148 lines (130 loc) · 2.88 KB
/
Response.php
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
<?php
/**
* Datatables PHP Model
*/
namespace Webinv\Datatables;
/**
* Class Response
*
* @package Webinv\Datatables
* @see https://datatables.net/manual/server-side
* @author Krzysztof Kardasz <[email protected]>
*/
class Response implements ResponseInterface
{
/** @var null|int */
private $draw;
/** @var int */
private $recordsTotal;
/** @var int */
private $recordsFiltered;
/** @var null|string */
private $error;
/** @var array */
private $data = [];
/**
* DataTableResponse constructor.
*
* @param array $data
* @param int $recordsTotal
* @param int $recordsFiltered
* @param int $draw
* @param string|null $error
*/
public function __construct(
?array $data,
?int $recordsTotal = 0,
?int $recordsFiltered = 0,
?int $draw = 1,
?string $error = null
) {
$this->data = $data ?? [];
$this->recordsTotal = $recordsTotal ?? 0;
$this->recordsFiltered = $recordsFiltered ?? 0;
$this->draw = $draw;
$this->error = $error;
}
/**
* @return null|int
*/
public function getDraw(): ?int
{
return $this->draw;
}
/**
* @param int $draw
*/
public function setDraw(int $draw): void
{
$this->draw = $draw;
}
/**
* @return int
*/
public function getRecordsTotal(): int
{
return $this->recordsTotal;
}
/**
* @param int $recordsTotal
*/
public function setRecordsTotal(int $recordsTotal): void
{
$this->recordsTotal = $recordsTotal;
}
/**
* @return int
*/
public function getRecordsFiltered(): int
{
return $this->recordsFiltered;
}
/**
* @param int $recordsFiltered
*/
public function setRecordsFiltered(int $recordsFiltered): void
{
$this->recordsFiltered = $recordsFiltered;
}
/**
* @return string|null
*/
public function getError(): ?string
{
return $this->error;
}
/**
* @param string|null $error
*/
public function setError(?string $error): void
{
$this->error = $error;
}
/**
* @return array
*/
public function getData(): array
{
return $this->data;
}
/**
* @param array $data
*/
public function setData(array $data): void
{
$this->data = $data;
}
/**
* {@inheritdoc}
*/
public function jsonSerialize()
{
return [
'draw' => $this->getDraw(),
'recordsTotal' => $this->getRecordsTotal(),
'recordsFiltered' => $this->getRecordsFiltered(),
'error' => $this->getError(),
'data' => $this->getData()
];
}
}