setName('ticket-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) { $forum_inscriptions = new Inscriptions($GLOBALS['AFUP_DB']); $eventReposotory = $this->getContainer()->get('ting')->get(EventRepository::class); $ticketRepository = $this->getContainer()->get('ting')->get(TicketTypeRepository::class); $event = $this->getEventFilter($input); if (null === $event) { $event = $eventReposotory->getNextEvent(); } if (null === $event) { return; } $date = null; if ($input->getOption('display-diff')) { $date = new \DateTime(); $date->modify('- 1 day'); } $message = $this->getContainer()->get(\AppBundle\Slack\MessageFactory::class)->createMessageForTicketStats( $event, $forum_inscriptions, $ticketRepository, $date ); $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; } }