|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace ElfSundae\Laravel\Support\Datatables\Services; |
|
4
|
|
|
|
|
5
|
|
|
use Yajra\Datatables\Services\DataTable as BaseDataTable; |
|
6
|
|
|
|
|
7
|
|
|
abstract class DataTable extends BaseDataTable |
|
8
|
|
|
{ |
|
9
|
|
|
/** |
|
10
|
|
|
* Get attributes for a "static" column that can not be |
|
11
|
|
|
* ordered, searched, nor exported. |
|
12
|
|
|
* |
|
13
|
|
|
* @param string $name |
|
14
|
|
|
* @param array $attributes |
|
15
|
|
|
* @return $this |
|
16
|
|
|
*/ |
|
17
|
|
|
protected function staticColumn($name, array $attributes = []) |
|
18
|
|
|
{ |
|
19
|
|
|
return array_merge([ |
|
20
|
|
|
'data' => $name, |
|
21
|
|
|
'name' => $name, |
|
22
|
|
|
'title' => $this->builder()->getQualifiedTitle($name), |
|
23
|
|
|
'defaultContent' => '', |
|
24
|
|
|
'render' => null, |
|
25
|
|
|
'orderable' => false, |
|
26
|
|
|
'searchable' => false, |
|
27
|
|
|
'exportable' => false, |
|
28
|
|
|
'printable' => true, |
|
29
|
|
|
'footer' => '', |
|
30
|
|
|
], $attributes); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* Return a render Closure for link. |
|
35
|
|
|
* |
|
36
|
|
|
* @param string $prefix |
|
37
|
|
|
* @param string $suffix |
|
38
|
|
|
* @param string $data |
|
39
|
|
|
* @param string $content |
|
40
|
|
|
* @return Closure |
|
41
|
|
|
*/ |
|
42
|
|
|
protected function linkRender($prefix = '', $suffix = '', $data = 'data', $content = 'data') |
|
43
|
|
|
{ |
|
44
|
|
|
$prefix = trim($prefix, '/'); |
|
45
|
|
|
$prefix = $prefix ? '/'.$prefix.'/' : '/'; |
|
46
|
|
|
$suffix = $suffix ? '/'.$suffix : ''; |
|
47
|
|
|
|
|
48
|
|
|
return function () use ($prefix, $suffix, $data, $content) { |
|
49
|
|
|
return <<<JS |
|
50
|
|
|
function (data, type, row, meta) { |
|
51
|
|
|
if (type == 'display' && data) { |
|
52
|
|
|
return '<a href=\"{$prefix}' + {$data} + '{$suffix}\">' + {$content} + '</a>'; |
|
53
|
|
|
} |
|
54
|
|
|
return data; |
|
55
|
|
|
} |
|
56
|
|
|
JS; |
|
57
|
|
|
}; |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* Get the avatar column data. |
|
62
|
|
|
* |
|
63
|
|
|
* @param string $avatar |
|
64
|
|
|
* @param string $originalAvatar |
|
65
|
|
|
* @param string $id |
|
66
|
|
|
* @param string $class |
|
67
|
|
|
* @param string $style |
|
68
|
|
|
* @return string |
|
69
|
|
|
*/ |
|
70
|
|
|
protected function avatarColumnData($avatar, $originalAvatar = null, $id = null, $class = 'img-circle', $style = 'width:28px') |
|
71
|
|
|
{ |
|
72
|
|
|
$originalAvatar = $originalAvatar ?: $avatar; |
|
73
|
|
|
|
|
74
|
|
|
if ($avatar) { |
|
75
|
|
|
return <<<HTML |
|
76
|
|
|
<a href='{$originalAvatar}' data-lightbox='avatar-{$id}'> |
|
77
|
|
|
<img src='{$avatar}' class='{$class}' style='{$style}'> |
|
78
|
|
|
</a> |
|
79
|
|
|
HTML; |
|
80
|
|
|
} |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
/** |
|
84
|
|
|
* Get filename for export. |
|
85
|
|
|
* |
|
86
|
|
|
* @return string |
|
87
|
|
|
*/ |
|
88
|
|
|
protected function filename() |
|
89
|
|
|
{ |
|
90
|
|
|
return preg_replace('#datatable$#i', '', class_basename($this)).'-'.date('Ymdhis'); |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
/** |
|
94
|
|
|
* Get default builder parameters. |
|
95
|
|
|
* |
|
96
|
|
|
* @return array |
|
97
|
|
|
*/ |
|
98
|
|
|
protected function getBuilderParameters() |
|
99
|
|
|
{ |
|
100
|
|
|
return [ |
|
101
|
|
|
'order' => [[0, 'desc']], |
|
102
|
|
|
]; |
|
103
|
|
|
} |
|
104
|
|
|
} |
|
105
|
|
|
|