1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
//---------------------------------------------------------------------- |
4
|
|
|
// |
5
|
|
|
// Copyright (C) 2015 Artem Rodygin |
6
|
|
|
// |
7
|
|
|
// This file is part of DataTables Symfony bundle. |
8
|
|
|
// |
9
|
|
|
// You should have received a copy of the MIT License along with |
10
|
|
|
// the bundle. If not, see <http://opensource.org/licenses/MIT>. |
11
|
|
|
// |
12
|
|
|
//---------------------------------------------------------------------- |
13
|
|
|
|
14
|
|
|
namespace DataTables; |
15
|
|
|
|
16
|
|
|
use Symfony\Component\Validator\Constraints as Assert; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Data to return to DataTables plugin. |
20
|
|
|
* |
21
|
|
|
* @see https://www.datatables.net/manual/server-side |
22
|
|
|
* |
23
|
|
|
* @property int $recordsTotal Total records, before filtering. |
24
|
|
|
* @property int $recordsFiltered Total records, after filtering. |
25
|
|
|
* @property array $data The data to be displayed in the table. |
26
|
|
|
*/ |
27
|
|
|
class DataTableResults implements \JsonSerializable |
28
|
|
|
{ |
29
|
|
|
const DT_ROW_ID = 'DT_RowId'; |
30
|
|
|
const DT_ROW_CLASS = 'DT_RowClass'; |
31
|
|
|
const DT_ROW_DATA = 'DT_RowData'; |
32
|
|
|
const DT_ROW_ATTR = 'DT_RowAttr'; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @Assert\NotNull() |
36
|
|
|
* @Assert\GreaterThanOrEqual(value = "0") |
37
|
|
|
*/ |
38
|
|
|
public $recordsTotal = 0; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @Assert\NotNull() |
42
|
|
|
* @Assert\GreaterThanOrEqual(value = "0") |
43
|
|
|
*/ |
44
|
|
|
public $recordsFiltered = 0; |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @Assert\NotNull() |
48
|
|
|
* @Assert\Type(type = "array") |
49
|
|
|
*/ |
50
|
|
|
public $data = []; |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @Assert\NotNull() |
54
|
|
|
* @Assert\GreaterThanOrEqual(value = "0") |
55
|
|
|
*/ |
56
|
|
|
private $draw = 0; |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* Convert results into array as expected by DataTables plugin. |
60
|
|
|
* |
61
|
|
|
* @return array |
62
|
|
|
*/ |
63
|
1 |
|
public function jsonSerialize() |
64
|
|
|
{ |
65
|
|
|
return [ |
66
|
1 |
|
'draw' => (int) $this->draw, |
67
|
1 |
|
'recordsTotal' => (int) $this->recordsTotal, |
68
|
1 |
|
'recordsFiltered' => (int) $this->recordsFiltered, |
69
|
1 |
|
'data' => $this->data, |
70
|
|
|
]; |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
|