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 $createButton = false; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* {@inheritdoc} |
24
|
|
|
*/ |
25
|
|
|
protected $builderParameters = [ |
26
|
|
|
'initComplete' => 'function (settings) { |
27
|
|
|
implicitForms.initialize(); |
28
|
|
|
}', |
29
|
|
|
]; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* {@inheritdoc} |
33
|
|
|
*/ |
34
|
|
|
protected $transformer = MediaTransformer::class; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Get the query object to be processed by dataTables. |
38
|
|
|
* |
39
|
|
|
* @return \Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Query\Builder|\Illuminate\Support\Collection |
|
|
|
|
40
|
|
|
*/ |
41
|
|
|
public function query() |
42
|
|
|
{ |
43
|
|
|
$query = $this->resource->media()->orderBy('order_column', 'ASC'); |
|
|
|
|
44
|
|
|
|
45
|
|
|
return $this->applyScopes($query); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Display ajax response. |
50
|
|
|
* |
51
|
|
|
* @return \Illuminate\Http\JsonResponse |
52
|
|
|
*/ |
53
|
|
|
public function ajax() |
54
|
|
|
{ |
55
|
|
|
return datatables($this->query()) |
|
|
|
|
56
|
|
|
->setTransformer($this->transformer) |
57
|
|
|
->make(true); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* Get columns. |
62
|
|
|
* |
63
|
|
|
* @return array |
64
|
|
|
*/ |
65
|
|
|
protected function getColumns(): array |
66
|
|
|
{ |
67
|
|
|
return [ |
68
|
|
|
'name' => ['title' => trans('cortex/foundation::common.name'), 'responsivePriority' => 0], |
69
|
|
|
'file_name' => ['title' => trans('cortex/foundation::common.file_name')], |
70
|
|
|
'mime_type' => ['title' => trans('cortex/foundation::common.mime_type')], |
71
|
|
|
'size' => ['title' => trans('cortex/foundation::common.size')], |
72
|
|
|
'created_at' => ['title' => trans('cortex/foundation::common.created_at'), 'render' => "moment(data).format('MMM Do, YYYY')"], |
|
|
|
|
73
|
|
|
'updated_at' => ['title' => trans('cortex/foundation::common.updated_at'), 'render' => "moment(data).format('MMM Do, YYYY')"], |
|
|
|
|
74
|
|
|
'delete' => ['title' => trans('cortex/foundation::common.delete'), 'orderable' => false, 'searchable' => false, 'render' => '"<a href=\"#\" data-toggle=\"modal\" data-target=\"#delete-confirmation\" data-modal-action=\""+data+"\" data-modal-title=\"'.trans('cortex/foundation::messages.delete_confirmation_title').'\" data-modal-body=\"" + Lang.trans(\'cortex/foundation::messages.delete_confirmation_body\', {type: \'media\', name: full.name}) + "\" title=\"'.trans('cortex/foundation::common.delete').'\"><i class=\"fa fa-trash text-danger\"></i></a>"'], |
|
|
|
|
75
|
|
|
]; |
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
|
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.