1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Cortex\Foundation\DataTables; |
6
|
|
|
|
7
|
|
|
use Spatie\MediaLibrary\Models\Media; |
8
|
|
|
use Cortex\Foundation\Transformers\MediaTransformer; |
9
|
|
|
|
10
|
|
|
class MediaDataTable extends AbstractDataTable |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* {@inheritdoc} |
14
|
|
|
*/ |
15
|
|
|
protected $model = Media::class; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* {@inheritdoc} |
19
|
|
|
*/ |
20
|
|
|
protected $transformer = MediaTransformer::class; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Get the query object to be processed by dataTables. |
24
|
|
|
* |
25
|
|
|
* @return \Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Query\Builder|\Illuminate\Support\Collection |
|
|
|
|
26
|
|
|
*/ |
27
|
|
|
public function query() |
28
|
|
|
{ |
29
|
|
|
$query = $this->resource->media()->orderBy('order_column', 'ASC'); |
|
|
|
|
30
|
|
|
|
31
|
|
|
return $this->applyScopes($query); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Get parameters. |
36
|
|
|
* |
37
|
|
|
* @return array |
|
|
|
|
38
|
|
|
*/ |
39
|
|
|
protected function getParameters() |
40
|
|
|
{ |
41
|
|
|
return [ |
42
|
|
|
'keys' => true, |
43
|
|
|
'autoWidth' => false, |
44
|
|
|
'dom' => "<'row'<'col-sm-6'B><'col-sm-6'f>> <'row'r><'row'<'col-sm-12't>> <'row'<'col-sm-5'i><'col-sm-7'p>>", |
|
|
|
|
45
|
|
|
'buttons' => [ |
46
|
|
|
'print', 'reset', 'reload', 'export', |
47
|
|
|
['extend' => 'colvis', 'text' => '<i class="fa fa-columns"></i> '.trans('cortex/foundation::common.columns').' <span class="caret"/>'], |
|
|
|
|
48
|
|
|
['extend' => 'pageLength', 'text' => '<i class="fa fa-list-ol"></i> '.trans('cortex/foundation::common.limit').' <span class="caret"/>'], |
|
|
|
|
49
|
|
|
], |
50
|
|
|
'initComplete' => 'function (settings) { |
51
|
|
|
implicitForms.initialize(); |
52
|
|
|
}', |
53
|
|
|
]; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Get columns. |
58
|
|
|
* |
59
|
|
|
* @return array |
|
|
|
|
60
|
|
|
*/ |
61
|
|
|
protected function getColumns() |
62
|
|
|
{ |
63
|
|
|
return [ |
64
|
|
|
'name' => ['title' => trans('cortex/foundation::common.name'), 'responsivePriority' => 0], |
65
|
|
|
'file_name' => ['title' => trans('cortex/foundation::common.file_name')], |
66
|
|
|
'mime_type' => ['title' => trans('cortex/foundation::common.mime_type')], |
67
|
|
|
'size' => ['title' => trans('cortex/foundation::common.size')], |
68
|
|
|
'created_at' => ['title' => trans('cortex/foundation::common.created_at'), 'render' => "moment(data).format('MMM Do, YYYY')"], |
|
|
|
|
69
|
|
|
'updated_at' => ['title' => trans('cortex/foundation::common.updated_at'), 'render' => "moment(data).format('MMM Do, YYYY')"], |
|
|
|
|
70
|
|
|
'delete' => ['title' => trans('cortex/foundation::common.delete'), 'searchable' => false, 'render' => '"<a href=\""+data+"\" data-method=\"delete\" data-token=\"'.csrf_token().'\" class=\"close\"><span class=\"text-danger fa fa-close\"></span></a>"'], |
|
|
|
|
71
|
|
|
]; |
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
|
This check looks for the generic type
array
as a return type and suggests a more specific type. This type is inferred from the actual code.