forked from pawellen/DataTablesListing
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ListingView.php
192 lines (155 loc) · 3.55 KB
/
ListingView.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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
<?php
/**
* Created by PhpStorm.
* User: pawel
* Date: 21.07.14
* Time: 11:29
*/
namespace PawelLen\DataTablesListing;
use PawelLen\DataTablesListing\Column\Columns;
use PawelLen\DataTablesListing\Column\Type\ListingColumn;
use PawelLen\DataTablesListing\Filter\Filters;
class ListingView
{
/**
* @var string
*/
protected $name;
/**
* @var Columns
*/
protected $columns;
/**
* @var Filters
*/
protected $filters;
/**
* @var array
*/
protected $options;
/**
* @var array
*/
protected $data;
/**
* @var string
*/
protected $templateReference;
/**
* @var int
*/
protected $allResultCount;
/**
* @param string $name
* @param Columns $columns
* @param Filters $filters
* @param array $options
* @param array $data
*/
public function __construct($name, Columns $columns, Filters $filters, array $options = array(), array $data = array(), $allResultCount = null)
{
$this->name = $name;
$this->columns = $columns;
$this->filters = $filters;
$this->options = $options;
$this->data = $data;
$this->templateReference = isset($options['template']) ? $options['template'] : null;
$this->allResultCount = (int)$allResultCount;
}
/**
* @return string
*/
public function getName()
{
return $this->name;
}
/**
* @return array
*/
public function getColumns()
{
return $this->columns->getColumns();
}
/**
* @return array
*/
public function getFilters()
{
return $this->filters->getFilters();
}
/**
* @return \Symfony\Component\Form\FormView
*/
public function getFiltersFormView()
{
return $this->filters->getForm()->createView();
}
/**
* @return string
*/
public function getSource()
{
return $this->options['data_source'];
}
/**
* @return bool
*/
public function hasFilters()
{
return $this->filters->count() > 0;
}
/**
* @return string
*/
public function getTemplateReference()
{
return $this->templateReference;
}
/**
* @return array
*/
public function getData()
{
return $this->data;
}
/**
* @return array
*/
public function getSettings()
{
// Columns:
$columns = array();
/** @var ListingColumn $column */
foreach ($this->columns as $column) {
$columns[] = array(
'searchable' => $column->isSearchable(),
'orderable' => $column->isSortable(),
);
}
$settings = array(
'pageLength' => $this->options['page_length'],
'columns' => $columns,
'deferLoading' => (!$this->options['defer_load'] && $this->options['page_length']) ? $this->allResultCount : null,
'lengthMenu' => $this->options['page_length_menu'],
'autoWidth' => $this->options['auto_width'],
'order' => $this->options['order_column'],
'stateSave' => $this->options['save_state'],
);
return $settings;
}
/**
* @return string
*/
public function getSettingsJson()
{
$settings = $this->getSettings();
return json_encode($settings);
}
/**
* @return array
*/
public function getOptions()
{
return $this->options;
}
}