1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Cortex\Attributes\DataTables\Adminarea; |
6
|
|
|
|
7
|
|
|
use Cortex\Attributes\Models\Attribute; |
8
|
|
|
use Cortex\Foundation\DataTables\AbstractDataTable; |
9
|
|
|
use Cortex\Attributes\Transformers\Adminarea\AttributeTransformer; |
10
|
|
|
|
11
|
|
|
class AttributesDataTable extends AbstractDataTable |
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* {@inheritdoc} |
15
|
|
|
*/ |
16
|
|
|
protected $model = Attribute::class; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* {@inheritdoc} |
20
|
|
|
*/ |
21
|
|
|
protected $transformer = AttributeTransformer::class; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* {@inheritdoc} |
25
|
|
|
*/ |
26
|
|
|
protected $builderParameters = [ |
27
|
|
|
'rowGroup' => '{ |
28
|
|
|
dataSrc: \'group\' |
29
|
|
|
}', |
30
|
|
|
]; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Get the query object to be processed by dataTables. |
34
|
|
|
* |
35
|
|
|
* @return \Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Query\Builder|\Illuminate\Support\Collection |
|
|
|
|
36
|
|
|
*/ |
37
|
|
|
public function query() |
38
|
|
|
{ |
39
|
|
|
$locale = app()->getLocale(); |
40
|
|
|
$query = app($this->model)->query()->orderBy('group', 'ASC')->orderBy('sort_order', 'ASC')->orderBy("name->\${$locale}", 'ASC'); |
|
|
|
|
41
|
|
|
|
42
|
|
|
return $this->applyScopes($query); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Get columns. |
47
|
|
|
* |
48
|
|
|
* @return array |
49
|
|
|
*/ |
50
|
|
|
protected function getColumns(): array |
51
|
|
|
{ |
52
|
|
|
$link = config('cortex.foundation.route.locale_prefix') |
53
|
|
|
? '"<a href=\""+routes.route(\'adminarea.attributes.edit\', {attribute: full.id, locale: \''.$this->request->segment(1).'\'})+"\">"+data+"</a>"' |
|
|
|
|
54
|
|
|
: '"<a href=\""+routes.route(\'adminarea.attributes.edit\', {attribute: full.id})+"\">"+data+"</a>"'; |
55
|
|
|
|
56
|
|
|
return [ |
57
|
|
|
'name' => ['title' => trans('cortex/attributes::common.name'), 'render' => $link, 'responsivePriority' => 0], |
|
|
|
|
58
|
|
|
'type' => ['title' => trans('cortex/attributes::common.type'), 'render' => 'Lang.trans(\'cortex/attributes::common.\'+data)'], |
|
|
|
|
59
|
|
|
'group' => ['title' => trans('cortex/attributes::common.group'), 'visible' => false], |
60
|
|
|
'is_collection' => ['title' => trans('cortex/attributes::common.is_collection')], |
61
|
|
|
'is_required' => ['title' => trans('cortex/attributes::common.is_required')], |
62
|
|
|
'created_at' => ['title' => trans('cortex/attributes::common.created_at'), 'render' => "moment(data).format('MMM Do, YYYY')"], |
|
|
|
|
63
|
|
|
'updated_at' => ['title' => trans('cortex/attributes::common.updated_at'), 'render' => "moment(data).format('MMM Do, YYYY')"], |
|
|
|
|
64
|
|
|
]; |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
|
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.