|
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
|
|
|
/** |
|
11
|
|
|
* @property \Spatie\MediaLibrary\HasMedia\HasMedia $resource |
|
12
|
|
|
* @property string $tabs |
|
13
|
|
|
* @property string $id |
|
14
|
|
|
* @property string $url |
|
15
|
|
|
*/ |
|
16
|
|
|
class MediaDataTable extends AbstractDataTable |
|
17
|
|
|
{ |
|
18
|
|
|
/** |
|
19
|
|
|
* {@inheritdoc} |
|
20
|
|
|
*/ |
|
21
|
|
|
protected $model = Media::class; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* {@inheritdoc} |
|
25
|
|
|
*/ |
|
26
|
|
|
protected $createButton = false; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* {@inheritdoc} |
|
30
|
|
|
*/ |
|
31
|
|
|
protected $builderParameters = [ |
|
32
|
|
|
'initComplete' => 'function (settings) { |
|
33
|
|
|
implicitForms.initialize(); |
|
34
|
|
|
}', |
|
35
|
|
|
]; |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* {@inheritdoc} |
|
39
|
|
|
*/ |
|
40
|
|
|
protected $transformer = MediaTransformer::class; |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* Get the query object to be processed by dataTables. |
|
44
|
|
|
* |
|
45
|
|
|
* @return \Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Query\Builder|\Illuminate\Support\Collection |
|
|
|
|
|
|
46
|
|
|
*/ |
|
47
|
|
|
public function query() |
|
48
|
|
|
{ |
|
49
|
|
|
$query = $this->resource->media()->orderBy('order_column', 'ASC'); |
|
50
|
|
|
|
|
51
|
|
|
return $this->applyScopes($query); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* Display ajax response. |
|
56
|
|
|
* |
|
57
|
|
|
* @return \Illuminate\Http\JsonResponse |
|
58
|
|
|
*/ |
|
59
|
|
|
public function ajax() |
|
60
|
|
|
{ |
|
61
|
|
|
return datatables($this->query()) |
|
|
|
|
|
|
62
|
|
|
->setTransformer(app($this->transformer)) |
|
63
|
|
|
->make(true); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* Get columns. |
|
68
|
|
|
* |
|
69
|
|
|
* @return array |
|
70
|
|
|
*/ |
|
71
|
|
|
protected function getColumns(): array |
|
72
|
|
|
{ |
|
73
|
|
|
return [ |
|
74
|
|
|
'name' => ['title' => trans('cortex/foundation::common.name'), 'responsivePriority' => 0], |
|
75
|
|
|
'file_name' => ['title' => trans('cortex/foundation::common.file_name')], |
|
76
|
|
|
'mime_type' => ['title' => trans('cortex/foundation::common.mime_type')], |
|
77
|
|
|
'size' => ['title' => trans('cortex/foundation::common.size')], |
|
78
|
|
|
'created_at' => ['title' => trans('cortex/foundation::common.created_at'), 'render' => "moment(data).format('YYYY-MM-DD, hh:mm:ss A')"], |
|
79
|
|
|
'updated_at' => ['title' => trans('cortex/foundation::common.updated_at'), 'render' => "moment(data).format('YYYY-MM-DD, hh:mm:ss A')"], |
|
80
|
|
|
'delete' => ['title' => trans('cortex/foundation::common.delete'), 'orderable' => false, 'searchable' => false, 'render' => '"<a href=\"#\" data-toggle=\"modal\" data-target=\"#delete-confirmation\" |
|
81
|
|
|
data-modal-action=\""+data+"\" |
|
82
|
|
|
data-modal-title=\"" + Lang.trans(\'cortex/foundation::messages.delete_confirmation_title\') + "\" |
|
83
|
|
|
data-modal-button=\"<a href=\'#\' class=\'btn btn-danger\' data-form=\'delete\' data-token=\''.csrf_token().'\'><i class=\'fa fa-trash-o\'></i> \"" + Lang.trans(\'cortex/foundation::common.delete\') + "\"</a>\" |
|
84
|
|
|
data-modal-body=\"" + Lang.trans(\'cortex/foundation::messages.delete_confirmation_body\', {type: \'media\', name: full.name}) + "\" |
|
85
|
|
|
title=\"" + Lang.trans(\'cortex/foundation::common.delete\') + "\"><i class=\"fa fa-trash text-danger\"></i></a>"'], |
|
86
|
|
|
]; |
|
87
|
|
|
} |
|
88
|
|
|
} |
|
89
|
|
|
|
This check looks for the generic type
arrayas a return type and suggests a more specific type. This type is inferred from the actual code.