1: <?php
2:
3: namespace Yajra\Datatables\Html;
4:
5: use Illuminate\Support\Fluent;
6:
7: 8: 9: 10: 11: 12: 13:
14: class Column extends Fluent
15: {
16: 17: 18:
19: public function __construct($attributes = [])
20: {
21: $attributes['orderable'] = isset($attributes['orderable']) ? $attributes['orderable'] : true;
22: $attributes['searchable'] = isset($attributes['searchable']) ? $attributes['searchable'] : true;
23: $attributes['exportable'] = isset($attributes['exportable']) ? $attributes['exportable'] : true;
24: $attributes['printable'] = isset($attributes['printable']) ? $attributes['printable'] : true;
25: $attributes['footer'] = isset($attributes['footer']) ? $attributes['footer'] : '';
26:
27:
28: foreach ($attributes as $attribute => $value) {
29: $method = 'parse' . ucfirst(strtolower($attribute));
30: if (method_exists($this, $method)) {
31: $attributes[$attribute] = $this->$method($value);
32: }
33: }
34:
35: parent::__construct($attributes);
36: }
37:
38: 39: 40: 41: 42: 43:
44: public function parseRender($value)
45: {
46:
47: $view = app('view');
48: $parameters = [];
49:
50: if (is_array($value)) {
51: $parameters = array_except($value, 0);
52: $value = $value[0];
53: }
54:
55: if (is_callable($value)) {
56: return $value($parameters);
57: } elseif ($view->exists($value)) {
58: return $view->make($value)->with($parameters)->render();
59: }
60:
61: return $value ? $this->parseRenderAsString($value) : null;
62: }
63:
64: 65: 66: 67: 68: 69:
70: private function parseRenderAsString($value)
71: {
72: return "function(data,type,full,meta){return $value;}";
73: }
74: }
75: