Files
afup/sources/AppBundle/Command/CfpNotificationCommand.php
Jean-Baptiste Nahan ab63791ce1 correction de la configuration (#767)
* correction de la configuration
* renommage des services pour preparer SF4
* remplacement des noms de service par les noms de classe
* ajout commentaire pour les services n'ayant pas de nom sous forme de nom de classe
2019-04-03 23:13:27 +02:00

91 lines
2.4 KiB
PHP

<?php
namespace AppBundle\Command;
use AppBundle\Event\Model\Repository\EventRepository;
use AppBundle\Event\Model\Repository\TalkRepository;
use AppBundle\Event\Model\Repository\TalkToSpeakersRepository;
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
class CfpNotificationCommand extends ContainerAwareCommand
{
/**
* @see Command
*/
protected function configure()
{
$this
->setName('cfp-stats-notification')
->addOption('display-diff', null, InputOption::VALUE_NONE)
->addOption('event-path', null, InputOption::VALUE_REQUIRED)
;
}
/**
* @see Command
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$ting = $this->getContainer()->get('ting');
$eventReposotory = $this->getContainer()->get('ting')->get(EventRepository::class);
$event = $this->getEventFilter($input);
if (null === $event) {
$event = $eventReposotory->getNextEvent();
}
if (null === $event) {
return;
}
$since = null;
if ($input->getOption('display-diff')) {
$since = new \DateTime();
$since->modify('- 1 day');
}
$currentDate = new \DateTime();
$message = $this->getContainer()->get(\AppBundle\Slack\MessageFactory::class)->createMessageForCfpStats(
$event,
$ting->get(TalkRepository::class),
$ting->get(TalkToSpeakersRepository::class),
$currentDate,
$since
);
$this->getContainer()->get(\AppBundle\Notifier\SlackNotifier::class)->sendMessage($message);
}
/**
* @param InputInterface $input
*
* @return null
*/
protected function getEventFilter(InputInterface $input)
{
if (null === ($eventPath = $input->getOption('event-path'))) {
return null;
}
$event = $this
->getContainer()
->get('ting')
->get(EventRepository::class)
->getByPath($eventPath)
;
if (null === $event) {
throw new \InvalidArgumentException("L'événement sur lequel filter n'a pas été trouvé");
}
return $event;
}
}