public function sendEticketsAction() { $request = $this->getRequest(); $long_real = (bool) $request->getParam('real', false); $short_real = (bool) $request->getParam('r', false); $isReal = $long_real | $short_real; #$long_count = (int) $request->getParam('count',false); #$short_count = (int) $request->getParam('c',false); #$ticket_count = $long_count + $short_count; $em = $this->getServiceLocator()->get('Doctrine\\ORM\\EntityManager'); # correct package ticket_status $qb = $em->getRepository("ErsBase\\Entity\\Package")->createQueryBuilder('p'); $qb->where('p.ticket_status IS NULL'); $qb->orWhere("p.ticket_status = 'not_send'"); $noStatusPackages = $qb->getQuery()->getResult(); echo count($noStatusPackages) . " packages need to be corrected." . PHP_EOL; foreach ($noStatusPackages as $package) { $productId = array('1' => 0); foreach ($package->getItems() as $item) { if ($item->getStatus() == 'cancelled') { continue; } if ($item->getStatus() == 'transferred') { continue; } if (!isset($productId[$item->getProductId()])) { $productId[$item->getProductId()] = 1; } else { $productId[$item->getProductId()]++; } } if ($productId[1] > 1) { $order = $package->getOrder(); echo "Found more than one week ticket in package " . $package->getCode()->getValue() . " (order: " . $order->getCode()->getValue() . ")." . PHP_EOL; } # if the package status is paid and # there is only one week ticket in this package # or this package doesn't contain no week ticket if ($package->getStatus() == 'paid') { if ($productId[1] == 1 || $productId[1] == 0) { $package->setTicketStatus('can_send'); } else { $package->setTicketStatus('block_send'); } # if the package is not paid } else { $package->setTicketStatus('not_send'); } $em->persist($package); } $em->flush(); $packages = $em->getRepository("ErsBase\\Entity\\Package")->findBy(array('ticket_status' => 'can_send'), array(), 100); echo "Can send out e-tickets for " . count($packages) . " packages." . PHP_EOL; if (!$isReal) { echo "Use -r parameter to really send out all etickets." . PHP_EOL; exit; } echo PHP_EOL; for ($i = 10; $i > 0; $i--) { echo "Really sending out e-tickets in... " . $i . " seconds (ctrl+c to abort) \r"; sleep(1); } echo PHP_EOL; foreach ($packages as $package) { # prepare email (participant, buyer) $emailService = new Service\EmailService(); $emailService->setFrom('*****@*****.**'); $order = $package->getOrder(); $participant = $package->getParticipant(); $buyer = $order->getBuyer(); if ($participant->getEmail() == '') { $emailService->addTo($buyer); } elseif ($participant->getEmail() == $buyer->getEmail()) { $emailService->addTo($buyer); } else { $emailService->addTo($participant); $emailService->addCc($buyer); } /*$user = new Entity\User(); $user->setEmail('*****@*****.**'); $emailService->addTo($user);*/ $bcc = new Entity\User(); $bcc->setEmail('*****@*****.**'); $emailService->addBcc($bcc); $subject = "[EJC 2015] e-Ticket for " . $participant->getFirstname() . " " . $participant->getSurname() . " (order " . $order->getCode()->getValue() . ")"; $emailService->setSubject($subject); $viewModel = new ViewModel(array('package' => $package)); $viewModel->setTemplate('email/eticket-participant.phtml'); $viewRenderer = $this->getServiceLocator()->get('ViewRenderer'); $html = $viewRenderer->render($viewModel); $emailService->setHtmlMessage($html); # generate e-ticket pdf $eticketService = $this->getServiceLocator()->get('ErsBase\\Service\\ETicketService'); $eticketService->setLanguage('en'); $eticketService->setPackage($package); $eticketFile = $eticketService->generatePdf(); echo ob_get_clean(); echo "generated e-ticket " . $eticketFile . "." . PHP_EOL; $emailService->addAttachment($eticketFile); #$terms1 = getcwd().'/public/Terms-and-Conditions-ERS-EN-v4.pdf'; #$terms2 = getcwd().'/public/Terms-and-Conditions-ORGA-EN-v2.pdf'; #$emailService->addAttachment($terms1); #$emailService->addAttachment($terms2); # send out email $emailService->send(); $package->setTicketStatus('send_out'); $em->persist($package); $em->flush(); } }
public function sendEticketsAction() { $logger = $this->getServiceLocator()->get('Logger'); $id = (int) $this->params()->fromRoute('id', 0); if (!$id) { $logger->info('there is no id'); return $this->redirect()->toRoute('admin/order', array()); } $em = $this->getServiceLocator()->get('Doctrine\\ORM\\EntityManager'); $order = $em->getRepository("ErsBase\\Entity\\Order")->findOneBy(array('id' => $id)); $forrest = new Service\BreadcrumbService(); if (!$forrest->exists('order')) { $forrest->set('order', 'admin/order'); } $request = $this->getRequest(); if ($request->isPost()) { $ret = $request->getPost('del', 'No'); if ($ret == 'Yes') { $id = (int) $request->getPost('id'); $order = $em->getRepository("ErsBase\\Entity\\Order")->findOneBy(array('id' => $id)); if ($order->getPaymentStatus() != 'paid') { return $this->redirect()->toRoute('admin/order', array('action' => 'send-eticket')); } $eticketService = $this->getServiceLocator()->get('ErsBase\\Service\\ETicketService'); foreach ($order->getPackages() as $package) { if ($package->getStatus() != 'paid') { continue; } # prepare email (participant, buyer) $emailService = new Service\EmailService(); $emailService->setFrom('*****@*****.**'); $order = $package->getOrder(); $participant = $package->getParticipant(); $buyer = $order->getBuyer(); $emailService->addTo($buyer); if ($participant->getEmail() != '') { $emailService->addTo($participant); } $bcc = new Entity\User(); $bcc->setEmail('*****@*****.**'); $emailService->addBcc($bcc); $subject = "Your registration for EJC 2015 (order " . $order->getCode()->getValue() . ")"; $subject = "[EJC 2015] e-Ticket for " . $participant->getFirstname() . " " . $participant->getSurname() . " (order " . $order->getCode()->getValue() . ")"; $emailService->setSubject($subject); $viewModel = new ViewModel(array('package' => $package)); $viewModel->setTemplate('email/eticket-participant.phtml'); $viewRender = $this->getServiceLocator()->get('ViewRenderer'); $html = $viewRender->render($viewModel); $emailService->setHtmlMessage($html); # generate e-ticket pdf $eticketService = $this->getServiceLocator()->get('ErsBase\\Service\\ETicketService'); $eticketService->setLanguage('en'); $eticketService->setPackage($package); $eticketFile = $eticketService->generatePdf(); # send out email $emailService->addAttachment($eticketFile); #$terms1 = getcwd().'/public/Terms-and-Conditions-ERS-EN-v4.pdf'; #$terms2 = getcwd().'/public/Terms-and-Conditions-ORGA-EN-v2.pdf'; #$emailService->addAttachment($terms1); #$emailService->addAttachment($terms2); $emailService->send(); $package->setTicketStatus('send_out'); $em->persist($package); $em->flush(); } $breadcrumb = $forrest->get('order'); return $this->redirect()->toRoute($breadcrumb->route, $breadcrumb->params, $breadcrumb->options); } } return new ViewModel(array('order' => $order, 'breadcrumb' => $forrest->get('order'))); }