56 lines
1.4 KiB
PHP
56 lines
1.4 KiB
PHP
|
<?php
|
||
|
|
||
|
namespace App\Command;
|
||
|
|
||
|
use Symfony\Component\Console\Command\Command;
|
||
|
use Symfony\Component\Console\Input\InputArgument;
|
||
|
use Symfony\Component\Console\Input\InputInterface;
|
||
|
use Symfony\Component\Console\Input\InputOption;
|
||
|
use Symfony\Component\Console\Output\OutputInterface;
|
||
|
use Symfony\Component\Console\Style\SymfonyStyle;
|
||
|
use App\Repository\MailingRepository;
|
||
|
|
||
|
class MailingListCommand extends Command
|
||
|
{
|
||
|
protected static $defaultName = 'mailing:list';
|
||
|
|
||
|
protected MailingRepository $repo;
|
||
|
|
||
|
public function __construct(MailingRepository $repo)
|
||
|
{
|
||
|
parent::__construct();
|
||
|
|
||
|
$this->repo = $repo;
|
||
|
}
|
||
|
|
||
|
protected function configure()
|
||
|
{
|
||
|
$this
|
||
|
->setDescription('List mailings')
|
||
|
;
|
||
|
}
|
||
|
|
||
|
protected function execute(InputInterface $input, OutputInterface $output): int
|
||
|
{
|
||
|
$io = new SymfonyStyle($input, $output);
|
||
|
|
||
|
$headers = ['Label', 'ID', 'Created at', 'Updated at'];
|
||
|
$rows = [];
|
||
|
|
||
|
$entities = $this->repo->findAll([], ['createdAt' => 'DEC']);
|
||
|
|
||
|
foreach ($entities as $entity) {
|
||
|
$rows[] = [
|
||
|
$entity->getLabel(),
|
||
|
$entity->getId(),
|
||
|
$entity->getCreatedAt()->format('Y-m-d H:i:s'),
|
||
|
$entity->getUpdatedAt()->format('Y-m-d H:i:s'),
|
||
|
];
|
||
|
}
|
||
|
|
||
|
$io->table($headers, $rows);
|
||
|
|
||
|
return Command::SUCCESS;
|
||
|
}
|
||
|
}
|