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 | * @param \Yajra\Datatables\Datatables $datatables |
||
56 | * @param \Illuminate\Contracts\View\Factory $viewFactory |
||
57 | */ |
||
58 | public function __construct(Datatables $datatables, Factory $viewFactory) |
||
63 | |||
64 | /** |
||
65 | * Render view. |
||
66 | * |
||
67 | * @param $view |
||
68 | * @param array $data |
||
69 | * @param array $mergeData |
||
70 | * @return \Illuminate\Http\JsonResponse|\Illuminate\View\View |
||
71 | */ |
||
72 | public function render($view, $data = [], $mergeData = []) |
||
95 | |||
96 | /** |
||
97 | * Get Datatables Request instance. |
||
98 | * |
||
99 | * @return \Yajra\Datatables\Request |
||
100 | */ |
||
101 | public function request() |
||
105 | |||
106 | /** |
||
107 | * Export results to Excel file. |
||
108 | * |
||
109 | * @return mixed |
||
110 | */ |
||
111 | public function excel() |
||
115 | |||
116 | /** |
||
117 | * Build excel file and prepare for export. |
||
118 | * |
||
119 | * @return mixed |
||
120 | */ |
||
121 | protected function buildExcelFile() |
||
129 | |||
130 | /** |
||
131 | * Get filename for export. |
||
132 | * |
||
133 | * @return string |
||
134 | */ |
||
135 | protected function filename() |
||
139 | |||
140 | /** |
||
141 | * Get mapped columns versus final decorated output. |
||
142 | * |
||
143 | * @return array |
||
144 | */ |
||
145 | protected function getDataForExport() |
||
151 | |||
152 | /** |
||
153 | * Get export columns definition. |
||
154 | * |
||
155 | * @return array|string |
||
156 | */ |
||
157 | private function exportColumns() |
||
161 | |||
162 | /** |
||
163 | * Get columns definition from html builder. |
||
164 | * |
||
165 | * @return array |
||
166 | */ |
||
167 | protected function getColumnsFromBuilder() |
||
171 | |||
172 | /** |
||
173 | * Optional method if you want to use html builder. |
||
174 | * |
||
175 | * @return \Yajra\Datatables\Html\Builder |
||
176 | */ |
||
177 | public function html() |
||
181 | |||
182 | /** |
||
183 | * Get Datatables Html Builder instance. |
||
184 | * |
||
185 | * @return \Yajra\Datatables\Html\Builder |
||
186 | */ |
||
187 | public function builder() |
||
191 | |||
192 | /** |
||
193 | * Map ajax response to columns definition. |
||
194 | * |
||
195 | * @param mixed $columns |
||
196 | * @param string $type |
||
197 | * @return array |
||
198 | */ |
||
199 | protected function mapResponseToColumns($columns, $type) |
||
209 | |||
210 | /** |
||
211 | * Get decorated data as defined in datatables ajax response. |
||
212 | * |
||
213 | * @return mixed |
||
214 | */ |
||
215 | protected function getAjaxResponseData() |
||
224 | |||
225 | /** |
||
226 | * Export results to CSV file. |
||
227 | * |
||
228 | * @return mixed |
||
229 | */ |
||
230 | public function csv() |
||
234 | |||
235 | /** |
||
236 | * Export results to PDF file. |
||
237 | * |
||
238 | * @return mixed |
||
239 | */ |
||
240 | public function pdf() |
||
244 | |||
245 | /** |
||
246 | * Display printable view of datatables. |
||
247 | * |
||
248 | * @return \Illuminate\Contracts\View\View |
||
249 | */ |
||
250 | public function printPreview() |
||
257 | |||
258 | /** |
||
259 | * Get mapped columns versus final decorated output. |
||
260 | * |
||
261 | * @return array |
||
262 | */ |
||
263 | protected function getDataForPrint() |
||
269 | |||
270 | /** |
||
271 | * Get printable columns. |
||
272 | * |
||
273 | * @return array|string |
||
274 | */ |
||
275 | protected function printColumns() |
||
279 | |||
280 | /** |
||
281 | * Add basic array query scopes. |
||
282 | * |
||
283 | * @param \Yajra\Datatables\Contracts\DataTableScopeContract $scope |
||
284 | * @return $this |
||
285 | */ |
||
286 | public function addScope(DataTableScopeContract $scope) |
||
292 | |||
293 | /** |
||
294 | * Apply query scopes. |
||
295 | * |
||
296 | * @param \Illuminate\Database\Query\Builder|\Illuminate\Database\Eloquent\Builder $query |
||
297 | * @return mixed |
||
298 | */ |
||
299 | protected function applyScopes($query) |
||
307 | |||
308 | /** |
||
309 | * Get default builder parameters. |
||
310 | * |
||
311 | * @return array |
||
312 | */ |
||
313 | protected function getBuilderParameters() |
||
334 | } |
||
335 |