45 lines
1.4 KiB
PHP
Executable File
45 lines
1.4 KiB
PHP
Executable File
<?php
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
use Symfony\Component\Console\Command\Command;
|
|
use Symfony\Component\Console\Input\InputInterface;
|
|
use Symfony\Component\Console\Output\OutputInterface;
|
|
use Modules\Auth\Models\User;
|
|
use Symfony\Component\Console\Helper\Table;
|
|
|
|
class UserListCommand extends Command
|
|
{
|
|
protected static $defaultName = 'user:list';
|
|
protected static $defaultDescription = 'Lista todos os usuários cadastrados no sistema';
|
|
|
|
protected function execute(InputInterface $input, OutputInterface $output): int
|
|
{
|
|
$users = User::all();
|
|
|
|
if ($users->isEmpty()) {
|
|
$output->writeln('<info>Nenhum usuário encontrado.</info>');
|
|
return Command::SUCCESS;
|
|
}
|
|
|
|
$table = new Table($output);
|
|
$table->setHeaders(['ID', 'ID Bus', 'Nome', 'Email', 'Status', 'Criado em']);
|
|
|
|
foreach ($users as $user) {
|
|
$table->addRow([
|
|
$user->users_id,
|
|
$user->users_bus_id ?? '-',
|
|
$user->users_name,
|
|
$user->users_email,
|
|
($user->users_status === 'active') ? '<info>Ativo</info>' : '<comment>' . ucfirst($user->users_status) . '</comment>',
|
|
$user->created_at
|
|
]);
|
|
}
|
|
|
|
$table->render();
|
|
$output->writeln("<info>Total de usuários: " . $users->count() . "</info>");
|
|
|
|
return Command::SUCCESS;
|
|
}
|
|
}
|