79 lines
2.2 KiB
PHP
79 lines
2.2 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;
|
|
use Symfony\Component\Routing\RouterInterface;
|
|
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
|
|
|
|
class MailingListCommand extends Command
|
|
{
|
|
protected static $defaultName = 'mailing:list';
|
|
|
|
protected MailingRepository $repo;
|
|
|
|
protected RouterInterface $router;
|
|
|
|
public function __construct(MailingRepository $repo, RouterInterface $router)
|
|
{
|
|
parent::__construct();
|
|
|
|
$this->repo = $repo;
|
|
$this->router = $router;
|
|
}
|
|
|
|
protected function configure()
|
|
{
|
|
$this
|
|
->setDescription('List mailings')
|
|
->addOption('feed', null, InputOption::VALUE_NONE, 'Show URLs of feeds')
|
|
;
|
|
}
|
|
|
|
protected function execute(InputInterface $input, OutputInterface $output): int
|
|
{
|
|
$io = new SymfonyStyle($input, $output);
|
|
$showFeed = $input->getOption('feed');
|
|
|
|
$headers = ['Label', 'ID', 'Feed', 'Public', 'Created at', 'Updated at'];
|
|
$rows = [];
|
|
|
|
$entities = $this->repo->findAll([], ['createdAt' => 'DEC']);
|
|
|
|
foreach ($entities as $entity) {
|
|
$row = [
|
|
$entity->getLabel(),
|
|
$entity->getId(),
|
|
$this->router->generate(
|
|
'mailing_rss',
|
|
['mailing' => $entity->getId()],
|
|
UrlGeneratorInterface::ABSOLUTE_URL
|
|
),
|
|
$entity->getIsPublic() ? 'y' : 'n',
|
|
$entity->getCreatedAt()->format('Y-m-d H:i:s'),
|
|
$entity->getUpdatedAt()->format('Y-m-d H:i:s'),
|
|
];
|
|
|
|
if (!$showFeed) {
|
|
unset($row[2]);
|
|
}
|
|
|
|
$rows[] = $row;
|
|
}
|
|
|
|
if (!$showFeed) {
|
|
unset($headers[2]);
|
|
}
|
|
|
|
$io->table($headers, $rows);
|
|
|
|
return Command::SUCCESS;
|
|
}
|
|
}
|