1 | <?php |
||
21 | abstract class DataTable implements DataTableContract, DataTableButtonsContract |
||
22 | { |
||
23 | /** |
||
24 | * @var \Yajra\Datatables\Datatables |
||
25 | */ |
||
26 | protected $datatables; |
||
27 | |||
28 | /** |
||
29 | * @var \Illuminate\Contracts\View\Factory |
||
30 | */ |
||
31 | protected $viewFactory; |
||
32 | |||
33 | /** |
||
34 | * Datatables print preview view. |
||
35 | * |
||
36 | * @var string |
||
37 | */ |
||
38 | protected $printPreview = 'datatables::print'; |
||
39 | |||
40 | /** |
||
41 | * List of columns to be exported. |
||
42 | * |
||
43 | * @var string|array |
||
44 | */ |
||
45 | protected $exportColumns = '*'; |
||
46 | |||
47 | /** |
||
48 | * List of columns to be printed. |
||
49 | * |
||
50 | * @var string|array |
||
51 | */ |
||
52 | protected $printColumns = '*'; |
||
53 | |||
54 | /** |
||
55 | * Query scopes. |
||
56 | * |
||
57 | * @var \Yajra\Datatables\Contracts\DataTableScopeContract[] |
||
58 | */ |
||
59 | protected $scopes = []; |
||
60 | |||
61 | /** |
||
62 | * Export filename. |
||
63 | * |
||
64 | * @var string |
||
65 | */ |
||
66 | protected $filename = ''; |
||
67 | |||
68 | /** |
||
69 | * DataTable constructor. |
||
70 | * |
||
71 | * @param \Yajra\Datatables\Datatables $datatables |
||
72 | * @param \Illuminate\Contracts\View\Factory $viewFactory |
||
73 | */ |
||
74 | public function __construct(Datatables $datatables, Factory $viewFactory) |
||
79 | |||
80 | /** |
||
81 | * Process dataTables needed render output. |
||
82 | * |
||
83 | * @param string $view |
||
84 | * @param array $data |
||
85 | * @param array $mergeData |
||
86 | * @return \Illuminate\Http\JsonResponse|\Illuminate\View\View |
||
87 | */ |
||
88 | public function render($view, $data = [], $mergeData = []) |
||
104 | |||
105 | /** |
||
106 | * Get Datatables Request instance. |
||
107 | * |
||
108 | * @return \Yajra\Datatables\Request |
||
109 | */ |
||
110 | public function request() |
||
114 | |||
115 | /** |
||
116 | * Display printable view of datatables. |
||
117 | * |
||
118 | * @return \Illuminate\Contracts\View\View |
||
119 | */ |
||
120 | public function printPreview() |
||
126 | |||
127 | /** |
||
128 | * Get mapped columns versus final decorated output. |
||
129 | * |
||
130 | * @return array |
||
131 | */ |
||
132 | protected function getDataForPrint() |
||
138 | |||
139 | /** |
||
140 | * Get printable columns. |
||
141 | * |
||
142 | * @return array|string |
||
143 | */ |
||
144 | protected function printColumns() |
||
148 | |||
149 | /** |
||
150 | * Get columns definition from html builder. |
||
151 | * |
||
152 | * @return array |
||
153 | */ |
||
154 | protected function getColumnsFromBuilder() |
||
158 | |||
159 | /** |
||
160 | * Optional method if you want to use html builder. |
||
161 | * |
||
162 | * @return \Yajra\Datatables\Html\Builder |
||
163 | */ |
||
164 | public function html() |
||
168 | |||
169 | /** |
||
170 | * Get Datatables Html Builder instance. |
||
171 | * |
||
172 | * @return \Yajra\Datatables\Html\Builder |
||
173 | */ |
||
174 | public function builder() |
||
178 | |||
179 | /** |
||
180 | * Map ajax response to columns definition. |
||
181 | * |
||
182 | * @param mixed $columns |
||
183 | * @param string $type |
||
184 | * @return array |
||
185 | */ |
||
186 | protected function mapResponseToColumns($columns, $type) |
||
196 | |||
197 | /** |
||
198 | * Get decorated data as defined in datatables ajax response. |
||
199 | * |
||
200 | * @return array |
||
201 | */ |
||
202 | protected function getAjaxResponseData() |
||
211 | |||
212 | /** |
||
213 | * Export results to Excel file. |
||
214 | * |
||
215 | * @return void |
||
216 | */ |
||
217 | public function excel() |
||
221 | |||
222 | /** |
||
223 | * Build excel file and prepare for export. |
||
224 | * |
||
225 | * @return \Maatwebsite\Excel\Writers\LaravelExcelWriter |
||
226 | */ |
||
227 | protected function buildExcelFile() |
||
238 | |||
239 | /** |
||
240 | * Get export filename. |
||
241 | * |
||
242 | * @return string |
||
243 | */ |
||
244 | public function getFilename() |
||
248 | |||
249 | /** |
||
250 | * Set export filename. |
||
251 | * |
||
252 | * @param string $filename |
||
253 | * @return DataTable |
||
254 | */ |
||
255 | public function setFilename($filename) |
||
261 | |||
262 | /** |
||
263 | * Get filename for export. |
||
264 | * |
||
265 | * @return string |
||
266 | */ |
||
267 | protected function filename() |
||
271 | |||
272 | /** |
||
273 | * Get mapped columns versus final decorated output. |
||
274 | * |
||
275 | * @return array |
||
276 | */ |
||
277 | protected function getDataForExport() |
||
283 | |||
284 | /** |
||
285 | * Get export columns definition. |
||
286 | * |
||
287 | * @return array|string |
||
288 | */ |
||
289 | private function exportColumns() |
||
293 | |||
294 | /** |
||
295 | * Export results to CSV file. |
||
296 | * |
||
297 | * @return void |
||
298 | */ |
||
299 | public function csv() |
||
303 | |||
304 | /** |
||
305 | * Export results to PDF file. |
||
306 | * |
||
307 | * @return mixed |
||
308 | */ |
||
309 | public function pdf() |
||
317 | |||
318 | /** |
||
319 | * PDF version of the table using print preview blade template. |
||
320 | * |
||
321 | * @return mixed |
||
322 | */ |
||
323 | public function snappyPdf() |
||
338 | |||
339 | /** |
||
340 | * Add basic array query scopes. |
||
341 | * |
||
342 | * @param \Yajra\Datatables\Contracts\DataTableScopeContract $scope |
||
343 | * @return $this |
||
344 | */ |
||
345 | public function addScope(DataTableScopeContract $scope) |
||
351 | |||
352 | /** |
||
353 | * Apply query scopes. |
||
354 | * |
||
355 | * @param \Illuminate\Database\Query\Builder|\Illuminate\Database\Eloquent\Builder $query |
||
356 | * @return mixed |
||
357 | */ |
||
358 | protected function applyScopes($query) |
||
366 | |||
367 | /** |
||
368 | * Get default builder parameters. |
||
369 | * |
||
370 | * @return array |
||
371 | */ |
||
372 | protected function getBuilderParameters() |
||
385 | } |
||
386 |
PHP has two types of connecting operators (logical operators, and boolean operators):
and
&&
or
||
The difference between these is the order in which they are executed. In most cases, you would want to use a boolean operator like
&&
, or||
.Let’s take a look at a few examples:
Logical Operators are used for Control-Flow
One case where you explicitly want to use logical operators is for control-flow such as this:
Since
die
introduces problems of its own, f.e. it makes our code hardly testable, and prevents any kind of more sophisticated error handling; you probably do not want to use this in real-world code. Unfortunately, logical operators cannot be combined withthrow
at this point:These limitations lead to logical operators rarely being of use in current PHP code.