/** * Create 3 users and one group. * * @Route("/crea-utenti", name="crea_utenti") * @Method("GET") * @Template("AppBundle:Main:crea-utenti.html.twig") */ public function createUsersAndGroupAction() { $gruppo = new Gruppo(); $gruppo->setNome('Developer'); $utente_1 = new Utenti(); $utente_1->setNome('foo'); $utente_1->setCognome('lorem'); $utente_1->setEmail('*****@*****.**'); // relate user to the group $utente_1->setGruppo($gruppo); $utente_2 = new Utenti(); $utente_2->setNome('foo2'); $utente_2->setCognome('lorem2'); $utente_2->setEmail('*****@*****.**'); // relate user to the group $utente_2->setGruppo($gruppo); $utente_3 = new Utenti(); $utente_3->setNome('foo3'); $utente_3->setCognome('lorem3'); $utente_3->setEmail('*****@*****.**'); // relate user to the group $utente_3->setGruppo($gruppo); $em = $this->getDoctrine()->getManager(); $em->persist($gruppo); $em->persist($utente_1); $em->persist($utente_2); $em->persist($utente_3); $em->flush(); return array('return' => "ok"); }
/** * @Route("/", name="index") */ public function indexshowAction() { if ($this->container->get('security.context')->isGranted('ROLE_ADMIN')) { return $this->redirectToRoute('admin'); } /* $joinChiamateUtenti = $this->getDoctrine()->getEntityManager()->getRepository('AppBundle:Chiamate'); $matchChiamateUtenti = $joinChiamateUtenti->createQueryBuilder('c') ->add('select', 'c, u') ->add('from', 'AppBundle:Chiamate c') ->innerJoin('AppBundle:Utenti', 'u') ->where('c.utente=u.id') ->getQuery() ->getArrayResult(); /*foreach ($matchChiamateUtenti as $matchChiamateUtente) { foreach ($matchChiamateUtente as $matchChiamateUtente) { if($matchChiamateUtente instanceof DateTime){ $string = $matchChiamateUtente->getTimestamp(); } else { //$inizioChiamata = strtotime($matchChiamateUtente['inizioChiamata']); $obj= $matchChiamateUtente['inizioChiamata']; } //$statusUtente =$matchChiamateUtente['statusUtente']; //echo $statusUtente; } }*/ $username = '******'; $password = '******'; // Create a new mailup client $client = new MailUpClient($username, $password); $elencoUtenti = $client->getListRecipients(3, 'Subscribed'); foreach ($elencoUtenti->Items as $Items) { $nuovoUtente = new Utenti(); $email = $Items->Email; $nuovoUtente->setEmail($email); foreach ($Items->Fields as $Fields) { $description = $Fields->Description; switch ($description) { case 'surname': $surname = $Fields->Value; $nuovoUtente->setSurname($surname); break; case 'name': $name = $Fields->Value; $nuovoUtente->setName($name); break; case 'phone': $phone = $Fields->Value; $nuovoUtente->setPhone($phone); break; case 'Campagne': $campagna = $Fields->Value; $nuovoUtente->setCampagna($campagna); } } $em = $this->getDoctrine()->getManager(); $utenteCheck = $em->getRepository('AppBundle:Utenti')->findOneByEmail($email); if (!$utenteCheck) { $em = $this->getDoctrine()->getManager(); $em->persist($nuovoUtente); $em->flush(); } } $em = $this->getDoctrine()->getEntityManager(); $Chiamate = $em->getRepository('AppBundle:Chiamate')->findAll(); $utenti = $em->getRepository('AppBundle:Utenti')->findAll(); if (!$utenti) { throw $this->createNotFoundException('Unable to find lista Utenti .'); } return $this->render('AppBundle::default/index-user.html.twig', array('utenti' => $utenti, 'chiamate' => $Chiamate)); }