/** * @Route("/operatore_campagne_attive", name="operatore_campagne_attive") */ public function operatore_campagne_attiveAction(Request $request) { //codice mailup QUI ! $username = '******'; $password = '******'; $client = new MailUpClient($username, $password); $recipients = $client->getGroupRecipients(26); foreach ($recipients->Items as $key => $value) { //controllo se i report scaricati esistono nel database $exist = false; $existingReports = $this->getDoctrine()->getRepository('AppBundle:Contatti')->findAll(); $name = NULL; $campaign = NULL; foreach ($value->Fields as $key => $field) { if ($field->Description == 'name') { $name = $field->Value; } if ($field->Description == 'Campagne') { $campaign = $field->Value; } } foreach ($existingReports as $n => $existingReport) { if ($existingReport->getEmailContatto() == $value->Email && $existingReport->getCampagnaContatto() == $campaign) { $exist = true; } } if (!$exist) { $counter = NULL; $operator = $this->getDoctrine()->getRepository('AppBundle:Utenti')->find(3); $newReport = new Contatti(); $newReport->setCampagnaContatto($campaign)->setNomeContatto($name)->setNumeroTelefonoContatto($value->MobileNumber)->setEmailContatto($value->Email)->setOperatoreContatto($operator); $em = $this->getDoctrine()->getManager(); $em->persist($newReport); $em->flush(); $em->clear(); //var_dump ($newReport);die; } } $listaCampagne = $this->getDoctrine()->getRepository('AppBundle:Contatti')->findAll(); if (!$listaCampagne) { throw $this->createNotFoundException('ops! non trovo campagne di mailup qui'); } return $this->render('AppBundle::operatore_campagne_attive.html.twig', ['listaCampagne' => $listaCampagne]); }