1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Cortex\Tenants\DataTables\Adminarea; |
6
|
|
|
|
7
|
|
|
use Cortex\Tenants\Models\Tenant; |
8
|
|
|
use Cortex\Foundation\DataTables\AbstractDataTable; |
9
|
|
|
use Cortex\Tenants\Transformers\Adminarea\TenantTransformer; |
10
|
|
|
|
11
|
|
|
class TenantsDataTable extends AbstractDataTable |
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* {@inheritdoc} |
15
|
|
|
*/ |
16
|
|
|
protected $model = Tenant::class; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* {@inheritdoc} |
20
|
|
|
*/ |
21
|
|
|
protected $transformer = TenantTransformer::class; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Get the query object to be processed by dataTables. |
25
|
|
|
* |
26
|
|
|
* @return \Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Query\Builder|\Illuminate\Support\Collection |
|
|
|
|
27
|
|
|
*/ |
28
|
|
|
public function query() |
29
|
|
|
{ |
30
|
|
|
$query = app($this->model)->query(); |
31
|
|
|
|
32
|
|
|
return $this->applyScopes($query); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Display ajax response. |
37
|
|
|
* |
38
|
|
|
* @return \Illuminate\Http\JsonResponse |
39
|
|
|
*/ |
40
|
|
|
public function ajax() |
41
|
|
|
{ |
42
|
|
|
return datatables($this->query()) |
|
|
|
|
43
|
|
|
->setTransformer($this->transformer) |
44
|
|
|
->orderColumn('name', 'name->"$.'.app()->getLocale().'" $1') |
45
|
|
|
->make(true); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Get columns. |
50
|
|
|
* |
51
|
|
|
* @return array |
52
|
|
|
*/ |
53
|
|
|
protected function getColumns(): array |
54
|
|
|
{ |
55
|
|
|
$link = config('cortex.foundation.route.locale_prefix') |
56
|
|
|
? '"<a href=\""+routes.route(\'adminarea.tenants.edit\', {tenant: full.id, locale: \''.$this->request->segment(1).'\'})+"\">"+data+"</a>"' |
|
|
|
|
57
|
|
|
: '"<a href=\""+routes.route(\'adminarea.tenants.edit\', {tenant: full.id})+"\">"+data+"</a>"'; |
58
|
|
|
|
59
|
|
|
return [ |
60
|
|
|
'name' => ['title' => trans('cortex/tenants::common.name'), 'render' => $link.'+(full.is_active ? " <i class=\"text-success fa fa-check\"></i>" : " <i class=\"text-danger fa fa-close\"></i>")', 'responsivePriority' => 0], |
|
|
|
|
61
|
|
|
'email' => ['title' => trans('cortex/tenants::common.email')], |
62
|
|
|
'phone' => ['title' => trans('cortex/tenants::common.phone')], |
63
|
|
|
'owner' => ['title' => trans('cortex/tenants::common.owner'), 'searchable' => false, 'orderable' => false], |
64
|
|
|
'country_code' => ['title' => trans('cortex/tenants::common.country')], |
65
|
|
|
'language_code' => ['title' => trans('cortex/tenants::common.language')], |
66
|
|
|
'created_at' => ['title' => trans('cortex/tenants::common.created_at'), 'render' => "moment(data).format('MMM Do, YYYY')"], |
|
|
|
|
67
|
|
|
'updated_at' => ['title' => trans('cortex/tenants::common.updated_at'), 'render' => "moment(data).format('MMM Do, YYYY')"], |
|
|
|
|
68
|
|
|
]; |
69
|
|
|
} |
70
|
|
|
} |
71
|
|
|
|
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.