2023-10-20 00:29:37 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Livewire;
|
|
|
|
|
|
|
|
use App\Http\Livewire;
|
|
|
|
use Rappasoft\LaravelLivewireTables\DataTableComponent;
|
|
|
|
use Rappasoft\LaravelLivewireTables\Views\Column;
|
|
|
|
use App\Models\User;
|
|
|
|
use App\Models\Link;
|
|
|
|
|
|
|
|
class UserTable extends DataTableComponent
|
|
|
|
{
|
|
|
|
protected $model = User::class;
|
|
|
|
|
|
|
|
public function configure(): void
|
|
|
|
{
|
|
|
|
$this->setPrimaryKey('id');
|
2023-12-01 14:02:20 +01:00
|
|
|
$this->setDefaultSort('created_at', 'asc');
|
2023-10-20 01:21:30 +02:00
|
|
|
$this->setPerPageAccepted([50, 100, 250, 500, 1000, -1]);
|
2023-10-23 23:55:19 +02:00
|
|
|
$this->setColumnSelectEnabled();
|
2023-10-20 00:29:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function columns(): array
|
|
|
|
{
|
|
|
|
return [
|
2024-01-04 17:11:30 +01:00
|
|
|
// Column::make("", "id")
|
|
|
|
// ->format(function ($value, $row, Column $column) {
|
|
|
|
// return view('components.table-components.select', ['user' => $row]);
|
|
|
|
// }),
|
2023-10-23 23:55:19 +02:00
|
|
|
Column::make(__('messages.ID'), "id")
|
2023-10-20 00:29:37 +02:00
|
|
|
->sortable()
|
|
|
|
->searchable(),
|
2023-10-23 23:55:19 +02:00
|
|
|
Column::make(__('messages.Name'), "name")
|
2023-10-20 00:29:37 +02:00
|
|
|
->sortable()
|
|
|
|
->searchable(),
|
2023-10-23 23:55:19 +02:00
|
|
|
Column::make(__('messages.E-Mail'), "email")
|
2023-10-20 00:29:37 +02:00
|
|
|
->sortable()
|
|
|
|
->searchable(),
|
2023-10-23 23:55:19 +02:00
|
|
|
Column::make(__('messages.Page'), "littlelink_name")
|
2023-10-20 00:29:37 +02:00
|
|
|
->sortable()
|
|
|
|
->searchable()
|
|
|
|
->format(function ($value, $row, Column $column) {
|
|
|
|
if (!$row->littlelink_name == NULL) {
|
2024-01-02 17:48:33 +01:00
|
|
|
return "<a href='" . url('') . "/@" . htmlspecialchars($row->littlelink_name) . "' target='_blank' class='text-info'><i class='bi bi-box-arrow-up-right'></i> " . $row->littlelink_name . " </a>";
|
2023-10-20 00:29:37 +02:00
|
|
|
} else {
|
|
|
|
return 'N/A';
|
|
|
|
}
|
|
|
|
})
|
|
|
|
->html(),
|
2023-10-23 23:55:19 +02:00
|
|
|
Column::make(__('messages.Role'), "role")
|
2023-10-20 00:29:37 +02:00
|
|
|
->sortable()
|
|
|
|
->searchable(),
|
2023-10-23 23:55:19 +02:00
|
|
|
Column::make(__('messages.Links'), "id")
|
2023-10-20 00:29:37 +02:00
|
|
|
->format(function ($value, $row) {
|
|
|
|
$linkCount = Link::where('user_id', $row->id)->count();
|
|
|
|
return $linkCount;
|
|
|
|
}),
|
2023-10-23 23:55:19 +02:00
|
|
|
Column::make(__('messages.Clicks'), "id")
|
2023-10-20 00:29:37 +02:00
|
|
|
->format(function ($value, $row) {
|
|
|
|
$clicksSum = Link::where('user_id', $row->id)->sum('click_number');
|
|
|
|
return $clicksSum;
|
|
|
|
}),
|
2023-10-23 23:55:19 +02:00
|
|
|
Column::make(__('messages.E-Mail'), "email_verified_at")
|
2023-10-20 00:29:37 +02:00
|
|
|
->sortable()
|
|
|
|
->format(function ($value, $row, Column $column) {
|
|
|
|
if (env('REGISTER_AUTH') !== 'auth') {
|
|
|
|
if ($row->role == 'admin' && $row->email_verified_at != '') {
|
2024-01-02 22:42:57 +01:00
|
|
|
return '<div class="text-center">-</div>';
|
2023-10-20 00:29:37 +02:00
|
|
|
} else {
|
2024-01-04 18:14:59 +01:00
|
|
|
if($row->email_verified_at == ''){
|
|
|
|
$verifyLinkBool = 'true';
|
|
|
|
} else {
|
|
|
|
$verifyLinkBool = 'false';
|
|
|
|
}
|
2023-10-20 00:29:37 +02:00
|
|
|
$verifyLink = route('verifyUser', [
|
2024-01-04 18:14:59 +01:00
|
|
|
'verify' => $verifyLinkBool,
|
2023-10-20 00:29:37 +02:00
|
|
|
'id' => $row->id
|
|
|
|
]);
|
|
|
|
if ($row->email_verified_at == '') {
|
2024-01-02 22:42:57 +01:00
|
|
|
return '<div class="text-center"><a style="cursor:pointer" data-id="'.$verifyLink.'" class="user-email text-danger"><span class="badge bg-danger">' . __('messages.Pending') . '</span></a></div>';
|
2023-10-20 00:29:37 +02:00
|
|
|
} else {
|
2024-01-02 22:42:57 +01:00
|
|
|
return '<div class="text-center"><a style="cursor:pointer" data-id="'.$verifyLink.'" class="user-email text-danger"><span class="badge bg-success">' . __('messages.Verified') . '</span></a></div>';
|
2023-10-20 00:29:37 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2024-01-02 22:42:57 +01:00
|
|
|
return '<div class="text-center">-</div>';
|
2023-10-20 00:29:37 +02:00
|
|
|
}
|
|
|
|
return '';
|
|
|
|
})->html(),
|
2023-10-23 23:55:19 +02:00
|
|
|
Column::make(__('messages.Status'), "block")
|
2023-10-20 00:29:37 +02:00
|
|
|
->sortable()
|
|
|
|
->format(function ($value, $row, Column $column) {
|
|
|
|
if ($row->role === 'admin' && $row->id === 1) {
|
2024-01-02 22:42:57 +01:00
|
|
|
return '<div class="text-center">-</div>';
|
2023-10-20 00:29:37 +02:00
|
|
|
} else {
|
|
|
|
$route = route('blockUser', ['block' => $row->block, 'id' => $row->id]);
|
|
|
|
if ($row->block === 'yes') {
|
2024-01-02 22:42:57 +01:00
|
|
|
$badge = '<div class="text-center"><a style="cursor:pointer" data-id="'.$route.'" class="user-block text-danger"><span class="badge bg-danger">'.__('messages.Pending').'</span></a></div>';
|
2023-10-20 00:29:37 +02:00
|
|
|
} elseif ($row->block === 'no') {
|
2024-01-02 22:42:57 +01:00
|
|
|
$badge = '<div class="text-center"><a style="cursor:pointer" data-id="'.$route.'" class="user-block text-danger"><span class="badge bg-success">'.__('messages.Approved').'</span></a></div>';
|
2023-10-20 00:29:37 +02:00
|
|
|
}
|
|
|
|
return "<a href=\"$route\">$badge</a>";
|
|
|
|
}
|
|
|
|
})
|
|
|
|
->html(),
|
2023-10-23 23:55:19 +02:00
|
|
|
Column::make(__('messages.Created at'), "created_at")
|
2023-10-20 00:29:37 +02:00
|
|
|
->sortable()
|
|
|
|
->format(function ($value) {
|
|
|
|
if ($value) {
|
|
|
|
return $value->format('d/m/y');
|
|
|
|
} else {
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
}),
|
2023-10-23 23:55:19 +02:00
|
|
|
Column::make(__('messages.Last seen'), "updated_at")
|
2023-10-20 00:29:37 +02:00
|
|
|
->sortable()
|
|
|
|
->format(function ($value) {
|
|
|
|
$now = now();
|
|
|
|
$diff = $now->diff($value);
|
|
|
|
|
|
|
|
if ($diff->d < 1 && $diff->h < 1) {
|
|
|
|
return 'Now';
|
|
|
|
} elseif ($diff->d < 1 && $diff->h < 24) {
|
|
|
|
return $diff->h . ' hours ago';
|
|
|
|
} elseif ($diff->d < 365) {
|
|
|
|
return $diff->d . ' days ago';
|
|
|
|
} else {
|
|
|
|
return $diff->y . ' years ago';
|
|
|
|
}
|
|
|
|
}),
|
2023-10-23 23:55:19 +02:00
|
|
|
Column::make(__('messages.Action'), "id")
|
2023-10-20 00:29:37 +02:00
|
|
|
->format(function ($value, $row, Column $column) {
|
|
|
|
return view('components.table-components.action', ['user' => $row]);
|
|
|
|
}),
|
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|