/** * @Route("/job/cpf-reminder") * @Template() */ public function cpfCheckAction() { $mailType = 'cpf-reminder'; $translator = $this->get('translator'); $subject = $translator->trans('cpf_reminder.subject'); $from = $this->container->getParameter('mailer_sender_mail'); $em = $this->getDoctrine()->getManager(); $personRepo = $this->getDoctrine()->getRepository('PROCERGSLoginCidadaoCoreBundle:Person'); $emailRepo = $this->getDoctrine()->getRepository('PROCERGSLoginCidadaoCoreBundle:SentEmail'); $users = $personRepo->findAllPendingCPFUntilDate(new \DateTime()); $todayMail = $emailRepo->findAllSentInTheLast24h($mailType, true); $mailCount = 0; foreach ($users as $user) { $to = $user->getEmailCanonical(); if (array_key_exists($to, $todayMail)) { continue; } $email = new SentEmail(); $email->setType($mailType)->setSubject($subject)->setSender($from)->setReceiver($to)->setMessage($this->renderView('PROCERGSLoginCidadaoCoreBundle:Jobs:cpf_check.html.twig', compact('user'))); if ($this->get('mailer')->send($email->getSwiftMail())) { $em->persist($email); $em->flush(); $mailCount++; } } return compact('mailCount'); }
/** * @Route("/contact", name="lc_contact") * @Template() */ public function contactAction(Request $request) { $form = $this->createForm(new ContactFormType()); $form->handleRequest($request); $translator = $this->get('translator'); $message = $translator->trans('contact.form.sent'); if ($form->isValid()) { $email = new SentEmail(); $email->setType('contact-mail')->setSubject('Fale conosco - ' . $form->get('firstName')->getData())->setSender($form->get('email')->getData())->setReceiver($this->container->getParameter('mailer_receiver_mail'))->setMessage($form->get('message')->getData()); $mailer = $this->get('mailer'); $swiftMail = $email->getSwiftMail(); if ($mailer->send($swiftMail)) { $em = $this->getDoctrine()->getManager(); $em->persist($email); $em->flush(); $this->get('session')->getFlashBag()->add('success', $message); } $url = $this->generateUrl("lc_contact"); return $this->redirect($url); } return $this->render('PROCERGSLoginCidadaoCoreBundle:Info:contact.html.twig', array('form' => $form->createView())); }