1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Cortex\Tenants\DataTables\Adminarea; |
6
|
|
|
|
7
|
|
|
use Cortex\Tenants\Models\Tenant; |
8
|
|
|
use Illuminate\Database\Eloquent\Builder; |
9
|
|
|
use Cortex\Foundation\DataTables\AbstractDataTable; |
10
|
|
|
use Cortex\Tenants\Transformers\Adminarea\TenantTransformer; |
11
|
|
|
|
12
|
|
|
class TenantsDataTable extends AbstractDataTable |
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* {@inheritdoc} |
16
|
|
|
*/ |
17
|
|
|
protected $model = Tenant::class; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* {@inheritdoc} |
21
|
|
|
*/ |
22
|
|
|
protected $transformer = TenantTransformer::class; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Get the query object to be processed by dataTables. |
26
|
|
|
* |
27
|
|
|
* @return \Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Query\Builder|\Illuminate\Support\Collection |
|
|
|
|
28
|
|
|
*/ |
29
|
|
|
public function query() |
30
|
|
|
{ |
31
|
|
|
$query = app($this->model)->query(); |
32
|
|
|
|
33
|
|
|
return $this->applyScopes($query); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Display ajax response. |
38
|
|
|
* |
39
|
|
|
* @return \Illuminate\Http\JsonResponse |
40
|
|
|
*/ |
41
|
|
|
public function ajax() |
42
|
|
|
{ |
43
|
|
|
return datatables($this->query()) |
|
|
|
|
44
|
|
|
->setTransformer(app($this->transformer)) |
45
|
|
|
->filterColumn('owner.username', function (Builder $builder, $keyword) { |
46
|
|
|
$builder->whereHas('owner', function (Builder $builder) use ($keyword) { |
47
|
|
|
$builder->where('username', 'like', "%{$keyword}%"); |
48
|
|
|
}); |
49
|
|
|
}) |
50
|
|
|
->filterColumn('country_code', function (Builder $builder, $keyword) { |
51
|
|
|
$countryCode = collect(countries())->search(function ($country) use ($keyword) { |
52
|
|
|
return mb_strpos($country['name'], $keyword) !== false || mb_strpos($country['emoji'], $keyword) !== false; |
|
|
|
|
53
|
|
|
}); |
54
|
|
|
|
55
|
|
|
! $countryCode || $builder->where('country_code', $countryCode); |
56
|
|
|
}) |
57
|
|
|
->filterColumn('language_code', function (Builder $builder, $keyword) { |
58
|
|
|
$languageCode = collect(languages())->search(function ($language) use ($keyword) { |
59
|
|
|
return mb_strpos($language['name'], $keyword) !== false; |
60
|
|
|
}); |
61
|
|
|
|
62
|
|
|
! $languageCode || $builder->where('language_code', $languageCode); |
63
|
|
|
}) |
64
|
|
|
->orderColumn('name', 'name->"$.'.app()->getLocale().'" $1') |
65
|
|
|
->make(true); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* Get columns. |
70
|
|
|
* |
71
|
|
|
* @return array |
72
|
|
|
*/ |
73
|
|
|
protected function getColumns(): array |
74
|
|
|
{ |
75
|
|
|
$link = config('cortex.foundation.route.locale_prefix') |
76
|
|
|
? '"<a href=\""+routes.route(\'adminarea.tenants.edit\', {tenant: full.id, locale: \''.$this->request->segment(1).'\'})+"\">"+data+"</a>"' |
|
|
|
|
77
|
|
|
: '"<a href=\""+routes.route(\'adminarea.tenants.edit\', {tenant: full.id})+"\">"+data+"</a>"'; |
78
|
|
|
|
79
|
|
|
return [ |
80
|
|
|
'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], |
|
|
|
|
81
|
|
|
'email' => ['title' => trans('cortex/tenants::common.email')], |
82
|
|
|
'phone' => ['title' => trans('cortex/tenants::common.phone')], |
83
|
|
|
'owner' => ['title' => trans('cortex/tenants::common.owner'), 'data' => 'owner.username'], |
84
|
|
|
'country_code' => ['title' => trans('cortex/tenants::common.country'), 'render' => 'full.country_emoji+" "+data'], |
|
|
|
|
85
|
|
|
'language_code' => ['title' => trans('cortex/tenants::common.language')], |
86
|
|
|
'created_at' => ['title' => trans('cortex/tenants::common.created_at'), 'render' => "moment(data).format('MMMM Do YYYY, hh:mm:ss A')"], |
|
|
|
|
87
|
|
|
'updated_at' => ['title' => trans('cortex/tenants::common.updated_at'), 'render' => "moment(data).format('MMMM Do YYYY, hh:mm:ss A')"], |
|
|
|
|
88
|
|
|
]; |
89
|
|
|
} |
90
|
|
|
} |
91
|
|
|
|
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.