1 | <?php |
||
19 | class Builder |
||
20 | { |
||
21 | /** |
||
22 | * @var Collection |
||
23 | */ |
||
24 | public $collection; |
||
25 | |||
26 | /** |
||
27 | * @var Repository |
||
28 | */ |
||
29 | public $config; |
||
30 | |||
31 | /** |
||
32 | * @var Factory |
||
33 | */ |
||
34 | public $view; |
||
35 | |||
36 | /** |
||
37 | * @var HtmlBuilder |
||
38 | */ |
||
39 | public $html; |
||
40 | |||
41 | /** |
||
42 | * @var UrlGenerator |
||
43 | */ |
||
44 | public $url; |
||
45 | |||
46 | /** |
||
47 | * @var FormBuilder |
||
48 | */ |
||
49 | public $form; |
||
50 | |||
51 | /** |
||
52 | * @var string|array |
||
53 | */ |
||
54 | protected $ajax = ''; |
||
55 | |||
56 | /** |
||
57 | * @var array |
||
58 | */ |
||
59 | protected $tableAttributes = ['class' => 'table', 'id' => 'dataTableBuilder']; |
||
60 | |||
61 | /** |
||
62 | * @var string |
||
63 | */ |
||
64 | protected $template = ''; |
||
65 | |||
66 | /** |
||
67 | * @var array |
||
68 | */ |
||
69 | protected $attributes = []; |
||
70 | |||
71 | /** |
||
72 | * Lists of valid DataTables Callbacks. |
||
73 | * |
||
74 | * @link https://datatables.net/reference/option/. |
||
75 | * @var array |
||
76 | */ |
||
77 | protected $validCallbacks = [ |
||
78 | 'createdRow', |
||
79 | 'drawCallback', |
||
80 | 'footerCallback', |
||
81 | 'formatNumber', |
||
82 | 'headerCallback', |
||
83 | 'infoCallback', |
||
84 | 'initComplete', |
||
85 | 'preDrawCallback', |
||
86 | 'rowCallback', |
||
87 | 'stateLoadCallback', |
||
88 | 'stateLoaded', |
||
89 | 'stateLoadParams', |
||
90 | 'stateSaveCallback', |
||
91 | 'stateSaveParams', |
||
92 | ]; |
||
93 | |||
94 | /** |
||
95 | * @param Repository $config |
||
96 | * @param Factory $view |
||
97 | * @param HtmlBuilder $html |
||
98 | * @param UrlGenerator $url |
||
99 | * @param FormBuilder $form |
||
100 | */ |
||
101 | public function __construct( |
||
115 | |||
116 | /** |
||
117 | * Generate DataTable javascript. |
||
118 | * |
||
119 | * @param null $script |
||
120 | * @param array $attributes |
||
121 | * @return string |
||
122 | */ |
||
123 | public function scripts($script = null, array $attributes = ['type' => 'text/javascript']) |
||
129 | |||
130 | /** |
||
131 | * Get generated raw scripts. |
||
132 | * |
||
133 | * @return string |
||
134 | */ |
||
135 | public function generateScripts() |
||
151 | |||
152 | /** |
||
153 | * Generate DataTables js parameters. |
||
154 | * |
||
155 | * @param array $attributes |
||
156 | * @return string |
||
157 | */ |
||
158 | public function parameterize($attributes = []) |
||
172 | |||
173 | /** |
||
174 | * Encode columns render function. |
||
175 | * |
||
176 | * @param array $parameters |
||
177 | * @return array |
||
178 | */ |
||
179 | protected function encodeColumnFunctions(array $parameters) |
||
194 | |||
195 | /** |
||
196 | * Encode DataTables callbacks function. |
||
197 | * |
||
198 | * @param array $parameters |
||
199 | * @return array |
||
200 | */ |
||
201 | protected function encodeCallbackFunctions(array $parameters) |
||
213 | |||
214 | /** |
||
215 | * Compile DataTable callback value. |
||
216 | * |
||
217 | * @param mixed $callback |
||
218 | * @return mixed|string |
||
219 | */ |
||
220 | private function compileCallback($callback) |
||
230 | |||
231 | /** |
||
232 | * Decode columns render functions. |
||
233 | * |
||
234 | * @param array $columnFunctions |
||
235 | * @param string $json |
||
236 | * @return string |
||
237 | */ |
||
238 | protected function decodeColumnFunctions(array $columnFunctions, $json) |
||
246 | |||
247 | /** |
||
248 | * Decode DataTables callbacks function. |
||
249 | * |
||
250 | * @param array $callbackFunctions |
||
251 | * @param string $json |
||
252 | * @return string |
||
253 | */ |
||
254 | protected function decodeCallbackFunctions(array $callbackFunctions, $json) |
||
262 | |||
263 | /** |
||
264 | * Get javascript template to use. |
||
265 | * |
||
266 | * @return string |
||
267 | */ |
||
268 | protected function template() |
||
274 | |||
275 | /** |
||
276 | * Add a column in collection using attributes. |
||
277 | * |
||
278 | * @param array $attributes |
||
279 | * @return $this |
||
280 | */ |
||
281 | public function addColumn(array $attributes) |
||
287 | |||
288 | /** |
||
289 | * Add a Column object in collection. |
||
290 | * |
||
291 | * @param \Yajra\Datatables\Html\Column $column |
||
292 | * @return $this |
||
293 | */ |
||
294 | public function add(Column $column) |
||
300 | |||
301 | /** |
||
302 | * Set datatables columns from array definition. |
||
303 | * |
||
304 | * @param array $columns |
||
305 | * @return $this |
||
306 | */ |
||
307 | public function columns(array $columns) |
||
329 | |||
330 | /** |
||
331 | * Set title attribute of an array if not set. |
||
332 | * |
||
333 | * @param string $title |
||
334 | * @param array $attributes |
||
335 | * @return array |
||
336 | */ |
||
337 | public function setTitle($title, array $attributes) |
||
345 | |||
346 | /** |
||
347 | * Convert string into a readable title. |
||
348 | * |
||
349 | * @param string $title |
||
350 | * @return string |
||
351 | */ |
||
352 | public function getQualifiedTitle($title) |
||
356 | |||
357 | /** |
||
358 | * Add a checkbox column. |
||
359 | * |
||
360 | * @param array $attributes |
||
361 | * @return $this |
||
362 | */ |
||
363 | public function addCheckbox(array $attributes = []) |
||
380 | |||
381 | /** |
||
382 | * Add a action column. |
||
383 | * |
||
384 | * @param array $attributes |
||
385 | * @return $this |
||
386 | */ |
||
387 | public function addAction(array $attributes = []) |
||
404 | |||
405 | /** |
||
406 | * Setup ajax parameter |
||
407 | * |
||
408 | * @param string|array $attributes |
||
409 | * @return $this |
||
410 | */ |
||
411 | public function ajax($attributes) |
||
417 | |||
418 | /** |
||
419 | * Generate DataTable's table html. |
||
420 | * |
||
421 | * @param array $attributes |
||
422 | * @return string |
||
423 | */ |
||
424 | public function table(array $attributes = []) |
||
430 | |||
431 | /** |
||
432 | * Configure DataTable's parameters. |
||
433 | * |
||
434 | * @param array $attributes |
||
435 | * @return $this |
||
436 | */ |
||
437 | public function parameters(array $attributes = []) |
||
443 | |||
444 | /** |
||
445 | * Set custom javascript template. |
||
446 | * |
||
447 | * @param string $template |
||
448 | * @return $this |
||
449 | */ |
||
450 | public function setTemplate($template) |
||
456 | |||
457 | /** |
||
458 | * Get collection of columns. |
||
459 | * |
||
460 | * @return Collection |
||
461 | */ |
||
462 | public function getColumns() |
||
466 | } |
||
467 |