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('country_code', function (Builder $builder, $keyword) { |
46
|
|
|
$countryCode = collect(countries())->search(function ($country) use ($keyword) { |
47
|
|
|
return mb_strpos($country['name'], $keyword) !== false || mb_strpos($country['emoji'], $keyword) !== false; |
48
|
|
|
}); |
49
|
|
|
|
50
|
|
|
! $countryCode || $builder->where('country_code', $countryCode); |
51
|
|
|
}) |
52
|
|
|
->filterColumn('language_code', function (Builder $builder, $keyword) { |
53
|
|
|
$languageCode = collect(languages())->search(function ($language) use ($keyword) { |
54
|
|
|
return mb_strpos($language['name'], $keyword) !== false; |
55
|
|
|
}); |
56
|
|
|
|
57
|
|
|
! $languageCode || $builder->where('language_code', $languageCode); |
58
|
|
|
}) |
59
|
|
|
->orderColumn('name', 'name->"$.'.app()->getLocale().'" $1') |
60
|
|
|
->make(true); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* Get columns. |
65
|
|
|
* |
66
|
|
|
* @return array |
67
|
|
|
*/ |
68
|
|
|
protected function getColumns(): array |
69
|
|
|
{ |
70
|
|
|
$link = config('cortex.foundation.route.locale_prefix') |
71
|
|
|
? '"<a href=\""+routes.route(\'adminarea.tenants.edit\', {tenant: full.id, locale: \''.$this->request->segment(1).'\'})+"\">"+data+"</a>"' |
72
|
|
|
: '"<a href=\""+routes.route(\'adminarea.tenants.edit\', {tenant: full.id})+"\">"+data+"</a>"'; |
73
|
|
|
|
74
|
|
|
return [ |
75
|
|
|
'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], |
76
|
|
|
'email' => ['title' => trans('cortex/tenants::common.email')], |
77
|
|
|
'phone' => ['title' => trans('cortex/tenants::common.phone')], |
78
|
|
|
'country_code' => ['title' => trans('cortex/tenants::common.country'), 'render' => 'full.country_emoji+" "+data'], |
79
|
|
|
'language_code' => ['title' => trans('cortex/tenants::common.language')], |
80
|
|
|
'created_at' => ['title' => trans('cortex/tenants::common.created_at'), 'render' => "moment(data).format('YYYY-MM-DD, hh:mm:ss A')"], |
81
|
|
|
'updated_at' => ['title' => trans('cortex/tenants::common.updated_at'), 'render' => "moment(data).format('YYYY-MM-DD, hh:mm:ss A')"], |
82
|
|
|
]; |
83
|
|
|
} |
84
|
|
|
} |
85
|
|
|
|
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.