1 | <?php |
||
14 | abstract class DataTable implements DataTableContract, DataTableButtonsContract |
||
15 | { |
||
16 | /** |
||
17 | * @var \Yajra\Datatables\Datatables |
||
18 | */ |
||
19 | protected $datatables; |
||
20 | |||
21 | /** |
||
22 | * @var \Illuminate\Contracts\View\Factory |
||
23 | */ |
||
24 | protected $viewFactory; |
||
25 | |||
26 | /** |
||
27 | * Datatables print preview view. |
||
28 | * |
||
29 | * @var string |
||
30 | */ |
||
31 | protected $printPreview; |
||
32 | |||
33 | /** |
||
34 | * List of columns to be exported. |
||
35 | * |
||
36 | * @var string|array |
||
37 | */ |
||
38 | protected $exportColumns = '*'; |
||
39 | |||
40 | /** |
||
41 | * List of columns to be printed. |
||
42 | * |
||
43 | * @var string|array |
||
44 | */ |
||
45 | protected $printColumns = '*'; |
||
46 | |||
47 | /** |
||
48 | * Query scopes. |
||
49 | * |
||
50 | * @var \Yajra\Datatables\Contracts\DataTableScopeContract[] |
||
51 | */ |
||
52 | protected $scopes = []; |
||
53 | |||
54 | /** |
||
55 | * Export filename. |
||
56 | * |
||
57 | * @var string |
||
58 | */ |
||
59 | protected $filename = ''; |
||
60 | |||
61 | /** |
||
62 | * @param \Yajra\Datatables\Datatables $datatables |
||
63 | * @param \Illuminate\Contracts\View\Factory $viewFactory |
||
64 | */ |
||
65 | public function __construct(Datatables $datatables, Factory $viewFactory) |
||
70 | |||
71 | /** |
||
72 | * Render view. |
||
73 | * |
||
74 | * @param $view |
||
75 | * @param array $data |
||
76 | * @param array $mergeData |
||
77 | * @return \Illuminate\Http\JsonResponse|\Illuminate\View\View |
||
78 | */ |
||
79 | public function render($view, $data = [], $mergeData = []) |
||
102 | |||
103 | /** |
||
104 | * Get Datatables Request instance. |
||
105 | * |
||
106 | * @return \Yajra\Datatables\Request |
||
107 | */ |
||
108 | public function request() |
||
112 | |||
113 | /** |
||
114 | * Export results to Excel file. |
||
115 | * |
||
116 | * @return mixed |
||
117 | */ |
||
118 | public function excel() |
||
122 | |||
123 | /** |
||
124 | * Build excel file and prepare for export. |
||
125 | * |
||
126 | * @return mixed |
||
127 | */ |
||
128 | protected function buildExcelFile() |
||
136 | |||
137 | /** |
||
138 | * Get filename for export. |
||
139 | * |
||
140 | * @return string |
||
141 | */ |
||
142 | protected function filename() |
||
146 | |||
147 | /** |
||
148 | * Get mapped columns versus final decorated output. |
||
149 | * |
||
150 | * @return array |
||
151 | */ |
||
152 | protected function getDataForExport() |
||
158 | |||
159 | /** |
||
160 | * Get export columns definition. |
||
161 | * |
||
162 | * @return array|string |
||
163 | */ |
||
164 | private function exportColumns() |
||
168 | |||
169 | /** |
||
170 | * Get columns definition from html builder. |
||
171 | * |
||
172 | * @return array |
||
173 | */ |
||
174 | protected function getColumnsFromBuilder() |
||
178 | |||
179 | /** |
||
180 | * Optional method if you want to use html builder. |
||
181 | * |
||
182 | * @return \Yajra\Datatables\Html\Builder |
||
183 | */ |
||
184 | public function html() |
||
188 | |||
189 | /** |
||
190 | * Get Datatables Html Builder instance. |
||
191 | * |
||
192 | * @return \Yajra\Datatables\Html\Builder |
||
193 | */ |
||
194 | public function builder() |
||
198 | |||
199 | /** |
||
200 | * Map ajax response to columns definition. |
||
201 | * |
||
202 | * @param mixed $columns |
||
203 | * @param string $type |
||
204 | * @return array |
||
205 | */ |
||
206 | protected function mapResponseToColumns($columns, $type) |
||
216 | |||
217 | /** |
||
218 | * Get decorated data as defined in datatables ajax response. |
||
219 | * |
||
220 | * @return mixed |
||
221 | */ |
||
222 | protected function getAjaxResponseData() |
||
231 | |||
232 | /** |
||
233 | * Export results to CSV file. |
||
234 | * |
||
235 | * @return mixed |
||
236 | */ |
||
237 | public function csv() |
||
241 | |||
242 | /** |
||
243 | * Export results to PDF file. |
||
244 | * |
||
245 | * @return mixed |
||
246 | */ |
||
247 | public function pdf() |
||
251 | |||
252 | /** |
||
253 | * Display printable view of datatables. |
||
254 | * |
||
255 | * @return \Illuminate\Contracts\View\View |
||
256 | */ |
||
257 | public function printPreview() |
||
264 | |||
265 | /** |
||
266 | * Get mapped columns versus final decorated output. |
||
267 | * |
||
268 | * @return array |
||
269 | */ |
||
270 | protected function getDataForPrint() |
||
276 | |||
277 | /** |
||
278 | * Get printable columns. |
||
279 | * |
||
280 | * @return array|string |
||
281 | */ |
||
282 | protected function printColumns() |
||
286 | |||
287 | /** |
||
288 | * Add basic array query scopes. |
||
289 | * |
||
290 | * @param \Yajra\Datatables\Contracts\DataTableScopeContract $scope |
||
291 | * @return $this |
||
292 | */ |
||
293 | public function addScope(DataTableScopeContract $scope) |
||
299 | |||
300 | /** |
||
301 | * Get export filename. |
||
302 | * |
||
303 | * @return string |
||
304 | */ |
||
305 | public function getFilename() |
||
309 | |||
310 | /** |
||
311 | * Set export filename. |
||
312 | * |
||
313 | * @param string $filename |
||
314 | * @return DataTable |
||
315 | */ |
||
316 | public function setFilename($filename) |
||
322 | |||
323 | /** |
||
324 | * Apply query scopes. |
||
325 | * |
||
326 | * @param \Illuminate\Database\Query\Builder|\Illuminate\Database\Eloquent\Builder $query |
||
327 | * @return mixed |
||
328 | */ |
||
329 | protected function applyScopes($query) |
||
337 | |||
338 | /** |
||
339 | * Get default builder parameters. |
||
340 | * |
||
341 | * @return array |
||
342 | */ |
||
343 | protected function getBuilderParameters() |
||
364 | } |
||
365 |