mail-rss/src/Command/MailingListCommand.php

66 lines
1.8 KiB
PHP
Raw Normal View History

2020-11-11 14:14:48 +01:00
<?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;
2020-11-11 17:44:53 +01:00
use Symfony\Component\Routing\RouterInterface;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
2020-11-11 14:14:48 +01:00
class MailingListCommand extends Command
{
protected static $defaultName = 'mailing:list';
protected MailingRepository $repo;
2020-11-11 17:44:53 +01:00
protected RouterInterface $router;
public function __construct(MailingRepository $repo, RouterInterface $router)
2020-11-11 14:14:48 +01:00
{
parent::__construct();
$this->repo = $repo;
2020-11-11 17:44:53 +01:00
$this->router = $router;
2020-11-11 14:14:48 +01:00
}
protected function configure()
{
$this
->setDescription('List mailings')
;
}
protected function execute(InputInterface $input, OutputInterface $output): int
{
$io = new SymfonyStyle($input, $output);
$headers = ['Label', 'ID', 'Feed', 'Created at', 'Updated at'];
2020-11-11 14:14:48 +01:00
$rows = [];
$entities = $this->repo->findAll([], ['createdAt' => 'DEC']);
foreach ($entities as $entity) {
$rows[] = [
$entity->getLabel(),
$entity->getId(),
2020-11-11 17:44:53 +01:00
$this->router->generate(
'mailing_rss',
['mailing' => $entity->getId()],
2020-11-11 17:44:53 +01:00
UrlGeneratorInterface::ABSOLUTE_URL
),
2020-11-11 14:14:48 +01:00
$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;
}
}