protected function notificar(Encuesta $entity, OutputInterface $output, $em) { //Avisar al usuario que creó la Encuesta $usuarios = $em->getRepository('BcTicCamIpalBundle:Usuario')->findBy(array('username' => $entity->getCreatedBy())); if (count($usuarios) == 0) { return; } $usuario = $usuarios[0]; //REDACTO EL EMAIL: $rendered = $this->getContainer()->get('templating')->render('BcTicCamIpalBundle:Encuesta:aviso-cierre-email.html.twig', array('entity' => $entity, 'usuario' => $usuario)); //SI NO TIENE EMAIL NO SE AVISA if (filter_var($usuario->getEmail(), FILTER_VALIDATE_EMAIL) === false) { $output->writeln("NO SE NOTIFICARÁ LA ENCUESTA #" . $entity->getId() . ' POR QUE NO TIENE EMAIL.'); return; } $destinatario = filter_var($usuario->getEmail(), FILTER_VALIDATE_EMAIL) === false ? '*****@*****.**' : $usuario->getEmail(); $output->writeln("SE NOTIFICARÁ LA ENCUESTA #" . $entity->getId() . ' AL EMAIL ' . $destinatario); $message = \Swift_Message::newInstance()->setSubject('IPAL #' . $entity->getId() . ' EN ESTADO ABIERTA')->setFrom(array('*****@*****.**' => 'SIOP CAM LA'))->setTo($destinatario)->setCharset('UTF-8')->setContentType('text/html')->setBody($rendered); $this->getContainer()->get('mailer')->send($message); }