1 | <?php |
||
18 | class Builder |
||
19 | { |
||
20 | /** |
||
21 | * @var Collection |
||
22 | */ |
||
23 | public $collection; |
||
24 | |||
25 | /** |
||
26 | * @var Repository |
||
27 | */ |
||
28 | public $config; |
||
29 | |||
30 | /** |
||
31 | * @var Factory |
||
32 | */ |
||
33 | public $view; |
||
34 | |||
35 | /** |
||
36 | * @var HtmlBuilder |
||
37 | */ |
||
38 | public $html; |
||
39 | |||
40 | /** |
||
41 | * @var UrlGenerator |
||
42 | */ |
||
43 | public $url; |
||
44 | |||
45 | /** |
||
46 | * @var FormBuilder |
||
47 | */ |
||
48 | public $form; |
||
49 | |||
50 | /** |
||
51 | * @var string|array |
||
52 | */ |
||
53 | protected $ajax = ''; |
||
54 | |||
55 | /** |
||
56 | * @var array |
||
57 | */ |
||
58 | protected $tableAttributes = ['class' => 'table', 'id' => 'dataTableBuilder']; |
||
59 | |||
60 | /** |
||
61 | * @var string |
||
62 | */ |
||
63 | protected $template = ''; |
||
64 | |||
65 | /** |
||
66 | * @var array |
||
67 | */ |
||
68 | protected $attributes = []; |
||
69 | |||
70 | /** |
||
71 | * Lists of valid DataTables Callbacks. |
||
72 | * |
||
73 | * @link https://datatables.net/reference/option/. |
||
74 | * @var array |
||
75 | */ |
||
76 | protected $validCallbacks = [ |
||
77 | 'createdRow', |
||
78 | 'drawCallback', |
||
79 | 'footerCallback', |
||
80 | 'formatNumber', |
||
81 | 'headerCallback', |
||
82 | 'infoCallback', |
||
83 | 'initComplete', |
||
84 | 'preDrawCallback', |
||
85 | 'rowCallback', |
||
86 | 'stateLoadCallback', |
||
87 | 'stateLoaded', |
||
88 | 'stateLoadParams', |
||
89 | 'stateSaveCallback', |
||
90 | 'stateSaveParams', |
||
91 | ]; |
||
92 | |||
93 | /** |
||
94 | * @param Repository $config |
||
95 | * @param Factory $view |
||
96 | * @param HtmlBuilder $html |
||
97 | * @param UrlGenerator $url |
||
98 | * @param FormBuilder $form |
||
99 | */ |
||
100 | public function __construct( |
||
114 | |||
115 | /** |
||
116 | * Generate DataTable javascript. |
||
117 | * |
||
118 | * @param null $script |
||
119 | * @param array $attributes |
||
120 | * @return string |
||
121 | */ |
||
122 | public function scripts($script = null, array $attributes = ['type' => 'text/javascript']) |
||
128 | |||
129 | /** |
||
130 | * Get generated raw scripts. |
||
131 | * |
||
132 | * @return string |
||
133 | */ |
||
134 | public function generateScripts() |
||
150 | |||
151 | /** |
||
152 | * Generate DataTables js parameters. |
||
153 | * |
||
154 | * @param array $attributes |
||
155 | * @return string |
||
156 | */ |
||
157 | public function parameterize($attributes = []) |
||
171 | |||
172 | /** |
||
173 | * Encode columns render function. |
||
174 | * |
||
175 | * @param array $parameters |
||
176 | * @return array |
||
177 | */ |
||
178 | protected function encodeColumnFunctions(array $parameters) |
||
193 | |||
194 | /** |
||
195 | * Encode DataTables callbacks function. |
||
196 | * |
||
197 | * @param array $parameters |
||
198 | * @return array |
||
199 | */ |
||
200 | protected function encodeCallbackFunctions(array $parameters) |
||
212 | |||
213 | /** |
||
214 | * Compile DataTable callback value. |
||
215 | * |
||
216 | * @param mixed $callback |
||
217 | * @return mixed|string |
||
218 | */ |
||
219 | private function compileCallback($callback) |
||
229 | |||
230 | /** |
||
231 | * Decode columns render functions. |
||
232 | * |
||
233 | * @param array $columnFunctions |
||
234 | * @param string $json |
||
235 | * @return string |
||
236 | */ |
||
237 | protected function decodeColumnFunctions(array $columnFunctions, $json) |
||
245 | |||
246 | /** |
||
247 | * Decode DataTables callbacks function. |
||
248 | * |
||
249 | * @param array $callbackFunctions |
||
250 | * @param string $json |
||
251 | * @return string |
||
252 | */ |
||
253 | protected function decodeCallbackFunctions(array $callbackFunctions, $json) |
||
261 | |||
262 | /** |
||
263 | * Get javascript template to use. |
||
264 | * |
||
265 | * @return string |
||
266 | */ |
||
267 | protected function template() |
||
273 | |||
274 | /** |
||
275 | * Add a column in collection using attributes. |
||
276 | * |
||
277 | * @param array $attributes |
||
278 | * @return $this |
||
279 | */ |
||
280 | public function addColumn(array $attributes) |
||
286 | |||
287 | /** |
||
288 | * Add a Column object in collection. |
||
289 | * |
||
290 | * @param \Yajra\Datatables\Html\Column $column |
||
291 | * @return $this |
||
292 | */ |
||
293 | public function add(Column $column) |
||
299 | |||
300 | /** |
||
301 | * Set datatables columns from array definition. |
||
302 | * |
||
303 | * @param array $columns |
||
304 | * @return $this |
||
305 | */ |
||
306 | public function columns(array $columns) |
||
324 | |||
325 | /** |
||
326 | * Set title attribute of an array if not set. |
||
327 | * |
||
328 | * @param string $title |
||
329 | * @param array $attributes |
||
330 | * @return array |
||
331 | */ |
||
332 | public function setTitle($title, array $attributes) |
||
340 | |||
341 | /** |
||
342 | * Convert string into a readable title. |
||
343 | * |
||
344 | * @param string $title |
||
345 | * @return string |
||
346 | */ |
||
347 | public function getQualifiedTitle($title) |
||
351 | |||
352 | /** |
||
353 | * Add a checkbox column. |
||
354 | * |
||
355 | * @param array $attributes |
||
356 | * @return $this |
||
357 | */ |
||
358 | public function addCheckbox(array $attributes = []) |
||
375 | |||
376 | /** |
||
377 | * Add a action column. |
||
378 | * |
||
379 | * @param array $attributes |
||
380 | * @return $this |
||
381 | */ |
||
382 | public function addAction(array $attributes = []) |
||
399 | |||
400 | /** |
||
401 | * Setup ajax parameter |
||
402 | * |
||
403 | * @param string|array $attributes |
||
404 | * @return $this |
||
405 | */ |
||
406 | public function ajax($attributes) |
||
412 | |||
413 | /** |
||
414 | * Generate DataTable's table html. |
||
415 | * |
||
416 | * @param array $attributes |
||
417 | * @return string |
||
418 | */ |
||
419 | public function table(array $attributes = []) |
||
425 | |||
426 | /** |
||
427 | * Configure DataTable's parameters. |
||
428 | * |
||
429 | * @param array $attributes |
||
430 | * @return $this |
||
431 | */ |
||
432 | public function parameters(array $attributes = []) |
||
438 | |||
439 | /** |
||
440 | * Set custom javascript template. |
||
441 | * |
||
442 | * @param string $template |
||
443 | * @return $this |
||
444 | */ |
||
445 | public function setTemplate($template) |
||
451 | |||
452 | /** |
||
453 | * Get collection of columns. |
||
454 | * |
||
455 | * @return Collection |
||
456 | */ |
||
457 | public function getColumns() |
||
461 | } |
||
462 |