Skip to content

Commit

Permalink
[7-6] 未処理お問い合わせ一覧通知コマンド
Browse files Browse the repository at this point in the history
  • Loading branch information
hidenorigoto committed Dec 28, 2015
1 parent 3a001ab commit a79af42
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 0 deletions.
50 changes: 50 additions & 0 deletions docs/lists/ch07/07-06.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php
namespace AppBundle\Command;

use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;

class NotifyUnprocessedInquiryCommand extends ContainerAwareCommand
{
protected function configure()
{
$this
->setName('cs:inquiry:notify-unprocessed')
->setDescription('未処理お問い合わせ一覧を通知')
;
}

protected function execute(InputInterface $input, OutputInterface $output)
{
$container = $this->getContainer();

$em = $container->get('doctrine')->getManager();
$inquiryRepository = $em->getRepository('AppBundle:Inquiry');

$inquiryList = $inquiryRepository->findUnprocessed();

if (count($inquiryList) > 0) {
$templating = $container->get('templating');

$message = \Swift_Message::newInstance()
->setSubject('[CS] 未処理お問い合わせ通知')
->setFrom('[email protected]')
->setTo('[email protected]')
->setBody(
$templating->render(
'mail/admin_unprocessedInquiryList.txt.twig',
['inquiryList' => $inquiryList]
)
);

$container->get('mailer')->send($message);

$output->writeln(count($inquiryList) . "件の未処理を通知");
} else {
$output->writeln("未処理なし");
}
}
}
50 changes: 50 additions & 0 deletions src/AppBundle/Command/NotifyUnprocessedInquiryCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php
namespace AppBundle\Command;

use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;

class NotifyUnprocessedInquiryCommand extends ContainerAwareCommand
{
protected function configure()
{
$this
->setName('cs:inquiry:notify-unprocessed')
->setDescription('未処理お問い合わせ一覧を通知')
;
}

protected function execute(InputInterface $input, OutputInterface $output)
{
$container = $this->getContainer();

$em = $container->get('doctrine')->getManager();
$inquiryRepository = $em->getRepository('AppBundle:Inquiry');

$inquiryList = $inquiryRepository->findUnprocessed();

if (count($inquiryList) > 0) {
$templating = $container->get('templating');

$message = \Swift_Message::newInstance()
->setSubject('[CS] 未処理お問い合わせ通知')
->setFrom('[email protected]')
->setTo('[email protected]')
->setBody(
$templating->render(
'mail/admin_unprocessedInquiryList.txt.twig',
['inquiryList' => $inquiryList]
)
);

$container->get('mailer')->send($message);

$output->writeln(count($inquiryList) . "件の未処理を通知");
} else {
$output->writeln("未処理なし");
}
}
}

0 comments on commit a79af42

Please sign in to comment.