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 | * DataTable constructor. |
||
63 | * |
||
64 | * @param \Yajra\Datatables\Datatables $datatables |
||
65 | * @param \Illuminate\Contracts\View\Factory $viewFactory |
||
66 | */ |
||
67 | public function __construct(Datatables $datatables, Factory $viewFactory) |
||
72 | |||
73 | /** |
||
74 | * Process dataTables needed render output. |
||
75 | * |
||
76 | * @param string $view |
||
77 | * @param array $data |
||
78 | * @param array $mergeData |
||
79 | * @return \Illuminate\Http\JsonResponse|\Illuminate\View\View |
||
80 | */ |
||
81 | public function render($view, $data = [], $mergeData = []) |
||
97 | |||
98 | /** |
||
99 | * Get Datatables Request instance. |
||
100 | * |
||
101 | * @return \Yajra\Datatables\Request |
||
102 | */ |
||
103 | public function request() |
||
107 | |||
108 | /** |
||
109 | * Display printable view of datatables. |
||
110 | * |
||
111 | * @return \Illuminate\Contracts\View\View |
||
112 | */ |
||
113 | public function printPreview() |
||
120 | |||
121 | /** |
||
122 | * Get mapped columns versus final decorated output. |
||
123 | * |
||
124 | * @return array |
||
125 | */ |
||
126 | protected function getDataForPrint() |
||
132 | |||
133 | /** |
||
134 | * Get printable columns. |
||
135 | * |
||
136 | * @return array|string |
||
137 | */ |
||
138 | protected function printColumns() |
||
142 | |||
143 | /** |
||
144 | * Get columns definition from html builder. |
||
145 | * |
||
146 | * @return array |
||
147 | */ |
||
148 | protected function getColumnsFromBuilder() |
||
152 | |||
153 | /** |
||
154 | * Optional method if you want to use html builder. |
||
155 | * |
||
156 | * @return \Yajra\Datatables\Html\Builder |
||
157 | */ |
||
158 | public function html() |
||
162 | |||
163 | /** |
||
164 | * Get Datatables Html Builder instance. |
||
165 | * |
||
166 | * @return \Yajra\Datatables\Html\Builder |
||
167 | */ |
||
168 | public function builder() |
||
172 | |||
173 | /** |
||
174 | * Map ajax response to columns definition. |
||
175 | * |
||
176 | * @param mixed $columns |
||
177 | * @param string $type |
||
178 | * @return array |
||
179 | */ |
||
180 | protected function mapResponseToColumns($columns, $type) |
||
190 | |||
191 | /** |
||
192 | * Get decorated data as defined in datatables ajax response. |
||
193 | * |
||
194 | * @return array |
||
195 | */ |
||
196 | protected function getAjaxResponseData() |
||
205 | |||
206 | /** |
||
207 | * Export results to Excel file. |
||
208 | * |
||
209 | * @return void |
||
210 | */ |
||
211 | public function excel() |
||
215 | |||
216 | /** |
||
217 | * Build excel file and prepare for export. |
||
218 | * |
||
219 | * @return \Maatwebsite\Excel\Writers\LaravelExcelWriter |
||
220 | */ |
||
221 | protected function buildExcelFile() |
||
232 | |||
233 | /** |
||
234 | * Get export filename. |
||
235 | * |
||
236 | * @return string |
||
237 | */ |
||
238 | public function getFilename() |
||
242 | |||
243 | /** |
||
244 | * Set export filename. |
||
245 | * |
||
246 | * @param string $filename |
||
247 | * @return DataTable |
||
248 | */ |
||
249 | public function setFilename($filename) |
||
255 | |||
256 | /** |
||
257 | * Get filename for export. |
||
258 | * |
||
259 | * @return string |
||
260 | */ |
||
261 | protected function filename() |
||
265 | |||
266 | /** |
||
267 | * Get mapped columns versus final decorated output. |
||
268 | * |
||
269 | * @return array |
||
270 | */ |
||
271 | protected function getDataForExport() |
||
277 | |||
278 | /** |
||
279 | * Get export columns definition. |
||
280 | * |
||
281 | * @return array|string |
||
282 | */ |
||
283 | private function exportColumns() |
||
287 | |||
288 | /** |
||
289 | * Export results to CSV file. |
||
290 | * |
||
291 | * @return void |
||
292 | */ |
||
293 | public function csv() |
||
297 | |||
298 | /** |
||
299 | * Export results to PDF file. |
||
300 | * |
||
301 | * @return void |
||
302 | */ |
||
303 | public function pdf() |
||
307 | |||
308 | /** |
||
309 | * Add basic array query scopes. |
||
310 | * |
||
311 | * @param \Yajra\Datatables\Contracts\DataTableScopeContract $scope |
||
312 | * @return $this |
||
313 | */ |
||
314 | public function addScope(DataTableScopeContract $scope) |
||
320 | |||
321 | /** |
||
322 | * Apply query scopes. |
||
323 | * |
||
324 | * @param \Illuminate\Database\Query\Builder|\Illuminate\Database\Eloquent\Builder $query |
||
325 | * @return mixed |
||
326 | */ |
||
327 | protected function applyScopes($query) |
||
335 | |||
336 | /** |
||
337 | * Get default builder parameters. |
||
338 | * |
||
339 | * @return array |
||
340 | */ |
||
341 | protected function getBuilderParameters() |
||
362 | } |
||
363 |