Permalink
Browse files

Options to send emails

  • Loading branch information...
aferrandini committed Feb 21, 2012
1 parent 2bc805c commit 377834abb4ba3483231b32182ad78b96f935f258
Showing with 100 additions and 75 deletions.
  1. +100 −75 src/PizzaNight/ManagementBundle/Command/MailAttendeesCommand.php
@@ -22,101 +22,126 @@ protected function configure()
->setName('events:send:emails')
->setDefinition(array(
new InputArgument('event_id', InputArgument::REQUIRED, 'Event id, get it from command events:list'),
+ new InputOption('send-all', null, InputArgument::OPTIONAL),
+ new InputOption('send-accepted', null, InputArgument::OPTIONAL),
+ new InputOption('send-rejected', null, InputArgument::OPTIONAL),
+ new InputOption('send-slug', null, InputArgument::OPTIONAL)
))
->setDescription('Generates and spools the emails.');
}
protected function execute(InputInterface $input, OutputInterface $output)
{
- $output->writeln('Accepted attendees');
- $output->writeln('----------------------------------------');
+ $send_all = $input->getOption('send-all') ? true : false;
+ $send_accepted = $input->getOption('send-accepted') ? true : false;
+ $send_rejected = $input->getOption('send-rejected') ? true : false;
+ $send_slug = $input->getOption('send-slug') ? true : false;
- $attendees = $this->getContainer()->get('doctrine')
- ->getRepository('PizzaNightManagementBundle:Attendee')
- ->findBy(array(
+ if($send_all || $send_accepted || $send_slug) {
+ $output->writeln('Accepted attendees');
+ $output->writeln('----------------------------------------');
+
+ $findBy = array(
'event_id' => $input->getArgument('event_id'),
'status' => Attendee::STATUS_ACCEPTED
- ));
-
- if(count($attendees)>0) {
- $host = 'http://manager.pizzanight.neosistec.com';
- $mailer = $this->getContainer()->get('mailer');
- $twig = $this->getContainer()->get('twig');
- $top_image_path = $this->getContainer()->get('kernel')->getRootDir() . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'templates' . DIRECTORY_SEPARATOR . 'MailTemplateImages' . DIRECTORY_SEPARATOR . 'top.gif';
- $bottom_image_path = $this->getContainer()->get('kernel')->getRootDir() . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'templates' . DIRECTORY_SEPARATOR . 'MailTemplateImages' . DIRECTORY_SEPARATOR . 'bottom.gif';
-
- foreach ($attendees as $attendee) {
- $output->writeln($attendee->getContact()->getName() . ' <' . $attendee->getContact()->getEmail() . '>');
-
- $qrcode_path = $this->getContainer()->get('kernel')->getRootDir() . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'qrcodes' . DIRECTORY_SEPARATOR . $attendee->getSlug();
- $message = \Swift_Message::newInstance();
- $message->setSubject('Ya eres un Pizza Nighter!')
- ->setFrom('pizzanight@neosistec.com')
- ->setTo($attendee->getContact()->getEmail())
- ->setBcc("aferrandini.neosistec@gmail.com")
- ->setBody($twig->render('PizzaNightManagementBundle:MailTemplates:Accepted/confirmation.html.twig', array(
+ );
+
+ if($send_slug) {
+ $findBy['slug'] = $input->getOption('send-slug');
+ }
+
+ $attendees = $this->getContainer()->get('doctrine')
+ ->getRepository('PizzaNightManagementBundle:Attendee')
+ ->findBy($findBy);
+
+ if(count($attendees)>0) {
+ $host = 'http://manager.pizzanight.neosistec.com';
+ $mailer = $this->getContainer()->get('mailer');
+ $twig = $this->getContainer()->get('twig');
+ $top_image_path = $this->getContainer()->get('kernel')->getRootDir() . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'templates' . DIRECTORY_SEPARATOR . 'MailTemplateImages' . DIRECTORY_SEPARATOR . 'top.gif';
+ $bottom_image_path = $this->getContainer()->get('kernel')->getRootDir() . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'templates' . DIRECTORY_SEPARATOR . 'MailTemplateImages' . DIRECTORY_SEPARATOR . 'bottom.gif';
+
+ foreach ($attendees as $attendee) {
+ $output->writeln($attendee->getContact()->getName() . ' <' . $attendee->getContact()->getEmail() . '>');
+
+ $qrcode_path = $this->getContainer()->get('kernel')->getRootDir() . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'qrcodes' . DIRECTORY_SEPARATOR . $attendee->getSlug();
+ $message = \Swift_Message::newInstance();
+ $message->setSubject('Ya eres un Pizza Nighter!')
+ ->setFrom('pizzanight@neosistec.com')
+ ->setTo($attendee->getContact()->getEmail())
+ ->setBcc("aferrandini.neosistec@gmail.com")
+ ->setBody($twig->render('PizzaNightManagementBundle:MailTemplates:Accepted/confirmation.html.twig', array(
+ 'attendee' => $attendee,
+ 'host' => $host,
+ 'top_image' => $message->embed(\Swift_Image::fromPath($top_image_path)),
+ 'bottom_image' => $message->embed(\Swift_Image::fromPath($bottom_image_path)),
+ 'qrcode' => $message->embed(\Swift_Image::fromPath($qrcode_path)),
+ )), "text/html")
+ ->addPart($twig->render('PizzaNightManagementBundle:MailTemplates:Accepted/confirmation.txt.twig', array(
+ 'attendee' => $attendee,
+ 'host' => $host,
+ )), "text/plain")
+ ->attach(\Swift_Attachment::fromPath($qrcode_path)->setFilename('entrada.png'))
+ ;
+
+ $mailer->send($message);
+ }
+ } else {
+ $output->writeln('No se encontraron asistentes al evento.');
+ }
+ }
+
+ if($send_all || $send_rejected || $send_slug) {
+ $output->writeln('');
+ $output->writeln('Rejected attendees');
+ $output->writeln('----------------------------------------');
+
+ $findBy = array(
+ 'event_id' => $input->getArgument('event_id'),
+ 'status' => Attendee::STATUS_REJECTED
+ );
+
+ if($send_slug) {
+ $findBy['slug'] = $input->getOption('send-slug');
+ }
+
+ $attendees = $this->getContainer()->get('doctrine')
+ ->getRepository('PizzaNightManagementBundle:Attendee')
+ ->findBy($findBy);
+
+ if(count($attendees)>0) {
+ $host = 'http://manager.pizzanight.neosistec.com';
+ $mailer = $this->getContainer()->get('mailer');
+ $twig = $this->getContainer()->get('twig');
+ $top_image_path = $this->getContainer()->get('kernel')->getRootDir() . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'templates' . DIRECTORY_SEPARATOR . 'MailTemplateImages' . DIRECTORY_SEPARATOR . 'top.gif';
+ $bottom_image_path = $this->getContainer()->get('kernel')->getRootDir() . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'templates' . DIRECTORY_SEPARATOR . 'MailTemplateImages' . DIRECTORY_SEPARATOR . 'bottom.gif';
+
+ foreach ($attendees as $attendee) {
+ $output->writeln($attendee->getContact()->getName() . ' <' . $attendee->getContact()->getEmail() . '>');
+
+ $message = \Swift_Message::newInstance();
+ $message->setSubject('PizzaNight 22-Febrero!')
+ ->setFrom('pizzanight@neosistec.com')
+ ->setTo($attendee->getContact()->getEmail())
+ ->setBcc("aferrandini.neosistec@gmail.com")
+ ->setBody($twig->render('PizzaNightManagementBundle:MailTemplates:Rejected/sorry.html.twig', array(
'attendee' => $attendee,
'host' => $host,
'top_image' => $message->embed(\Swift_Image::fromPath($top_image_path)),
'bottom_image' => $message->embed(\Swift_Image::fromPath($bottom_image_path)),
'qrcode' => $message->embed(\Swift_Image::fromPath($qrcode_path)),
)), "text/html")
- ->addPart($twig->render('PizzaNightManagementBundle:MailTemplates:Accepted/confirmation.txt.twig', array(
+ ->addPart($twig->render('PizzaNightManagementBundle:MailTemplates:Rejected/sorry.txt.twig', array(
'attendee' => $attendee,
'host' => $host,
)), "text/plain")
- ->attach(\Swift_Attachment::fromPath($qrcode_path)->setFilename('entrada.png'))
- ;
-
- $mailer->send($message);
- }
- } else {
- $output->writeln('No se encontraron asistentes al evento.');
- }
+ ;
- $output->writeln('');
- $output->writeln('Rejected attendees');
- $output->writeln('----------------------------------------');
-
- $attendees = $this->getContainer()->get('doctrine')
- ->getRepository('PizzaNightManagementBundle:Attendee')
- ->findBy(array(
- 'event_id' => $input->getArgument('event_id'),
- 'status' => Attendee::STATUS_REJECTED
- ));
-
- if(count($attendees)>0) {
- $host = 'http://manager.pizzanight.neosistec.com';
- $mailer = $this->getContainer()->get('mailer');
- $twig = $this->getContainer()->get('twig');
- $top_image_path = $this->getContainer()->get('kernel')->getRootDir() . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'templates' . DIRECTORY_SEPARATOR . 'MailTemplateImages' . DIRECTORY_SEPARATOR . 'top.gif';
- $bottom_image_path = $this->getContainer()->get('kernel')->getRootDir() . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'templates' . DIRECTORY_SEPARATOR . 'MailTemplateImages' . DIRECTORY_SEPARATOR . 'bottom.gif';
-
- foreach ($attendees as $attendee) {
- $output->writeln($attendee->getContact()->getName() . ' <' . $attendee->getContact()->getEmail() . '>');
-
- $message = \Swift_Message::newInstance();
- $message->setSubject('PizzaNight 22-Febrero!')
- ->setFrom('pizzanight@neosistec.com')
- ->setTo($attendee->getContact()->getEmail())
- ->setBcc("aferrandini.neosistec@gmail.com")
- ->setBody($twig->render('PizzaNightManagementBundle:MailTemplates:Rejected/sorry.html.twig', array(
- 'attendee' => $attendee,
- 'host' => $host,
- 'top_image' => $message->embed(\Swift_Image::fromPath($top_image_path)),
- 'bottom_image' => $message->embed(\Swift_Image::fromPath($bottom_image_path)),
- 'qrcode' => $message->embed(\Swift_Image::fromPath($qrcode_path)),
- )), "text/html")
- ->addPart($twig->render('PizzaNightManagementBundle:MailTemplates:Rejected/sorry.txt.twig', array(
- 'attendee' => $attendee,
- 'host' => $host,
- )), "text/plain")
- ;
-
- $mailer->send($message);
+ $mailer->send($message);
+ }
+ } else {
+ $output->writeln('No se encontraron asistentes al evento.');
}
- } else {
- $output->writeln('No se encontraron asistentes al evento.');
}
$output->writeln("");

0 comments on commit 377834a

Please sign in to comment.