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);
 }
 /**
  * Creates a form to create a Encuesta entity.
  *
  * @param Encuesta $entity The entity
  *
  * @return \Symfony\Component\Form\Form The form
  */
 private function createCreateForm(Encuesta $entity, $formType)
 {
     //Al entity le pongo la fecha actual - ojo con la fecha del servidor y la zona horaria de PHP:
     $entity->setFecha(new \DateTime());
     $entity->setHora(new \DateTime());
     //El objeto empleados es siempre 10 - en la vista se muestra o esconde según numDeEmpleados
     $empleados = array();
     for ($i = 1; $i <= 10; $i++) {
         $empleados['empleado_' . $i] = "";
     }
     $entity->setEmpleados($empleados);
     $form = $this->createForm($formType, $entity, array('action' => $this->generateUrl('encuestas_create_' . $entity->getKey()), 'method' => 'POST'));
     $role = false;
     if ($role) {
         //Do Nothing
     } else {
         $entities;
         $paises = array();
         foreach ($this->get('security.context')->getToken()->getUser()->getPais() as $pais) {
             $paises[$pais->getId()] = $pais->getId();
         }
     }
     $form->add('actividadDeEmpresa', 'entity', array('class' => 'BcTicCamIpalBundle:Actividad', 'label' => 'Actividad', 'query_builder' => function (EntityRepository $er) use($paises) {
         return $er->createQueryBuilder('a')->join('a.empresa', 'e')->join('e.pais', 'p')->where('e.visible = :visible AND a.visible = :visible')->andWhere('p.id IN (:paises)')->setParameters(array('visible' => 1, 'paises' => $paises))->orderBy('a.nombre', 'ASC')->addOrderBy('e.nombre', 'ASC');
     }));
     //Completo el número de trabajadores:
     $form->add('empleados', CollectionType::class, array('entry_type' => RutType::class, 'allow_add' => true, 'label' => 'empleado', 'entry_options' => array('attr' => array('label' => 'Rut'))));
     //Agrego la façade para supervisor
     $form->add('supervisorFacade', 'text', array('label' => 'Supervisor'));
     $form->add('submit', 'submit', array('label' => 'Guardar'));
     return $form;
 }