/** * Method used to detect if recorded lead has been created by a test or not * @param Leads $lead * @return bool */ public function isTestLead(Leads $lead) { if (stristr($lead->getUserAgent(), 'phantomjs')) { return true; } return false; }
/** * @param Leads $lead */ protected function getInitialExportStatus($lead, $config) { $method_config = $config['method_config']; $methodObject = $this->getMethod($config['method']); if (array_key_exists('if_email_validated', $method_config) && $method_config['if_email_validated'] === true) { $email = $lead->getEmail(); $validated = $methodObject->isEmailValidated($lead, $email); if ($validated) { return ExportUtils::$_EXPORT_NOT_PROCESSED; } else { return ExportUtils::EXPORT_EMAIL_NOT_CONFIRMED; } } else { return ExportUtils::$_EXPORT_NOT_PROCESSED; } }
/** * Send email notification * * @param array $params * @param \Tellaw\LeadsFactoryBundle\Entity\Leads $leads */ protected function sendNotification($params, $leads) { $logger = $this->get('logger'); $exportUtils = $this->get('export_utils'); $data = json_decode($leads->getData(), true); if (!isset($params['to'])) { $logger->error('No recipient available, check JSON form config'); return; } $to = $params['to']; $from = isset($params['from']) ? $params['from'] : $exportUtils::NOTIFICATION_DEFAULT_FROM; $subject = isset($params['subject']) ? $params['subject'] : 'Nouvelle DI issue du formulaire ' . $leads->getForm()->getName(); $template = isset($params['template']) ? $params['template'] : $exportUtils::NOTIFICATION_DEFAULT_TEMPLATE; $message = Swift_Message::newInstance()->setSubject($subject)->setFrom($from)->setTo($to)->setBody($this->renderView('TellawLeadsFactoryBundle:' . $template, array('fields' => $data, 'intro' => 'Nouvelle DI issue du formulaire ' . $leads->getForm()->getName())), 'text/html'); try { $result = $this->get('mailer')->send($message); } catch (Exception $e) { $logger->error($e->getMessage()); } }
/** * Enregistre une DI * @Route("/lead/post") * @Method("POST") */ public function postLeadAction(Request $request) { $exportUtils = $this->get('export_utils'); $logger = $this->get('logger'); $searchUtils = $this->get('search.utils'); $logger->info('API post lead'); $data = $request->getcontent(); $logger->info($data); $data = json_decode($data, true); try { $form = $this->getDoctrine()->getRepository('TellawLeadsFactoryBundle:Form')->findOneByCode($data['formCode']); // Get the Json configuration of the form $config = $form->getConfig(); $data = $this->get('form_utils')->preProcessData($form->getId(), $data); $jsonContent = json_encode($data); $leads = new Leads(); $leads->setIpadress($this->get('request')->getClientIp()); $leads->setUserAgent($this->get('request')->server->get("HTTP_USER_AGENT")); $leads->setFirstname(@$data['firstName']); $leads->setLastname(@$data['lastName']); $leads->setData($jsonContent); $leads->setLog("leads importée le : " . date('Y-m-d h:s')); $leads->setUtmcampaign(@$data["utmcampaign"]); $leads->setForm($form); $leads->setTelephone(@$data["phone"]); $leads->setEmail(@$data['email']); // Assignation de la leads si la configuration est presente if (array_key_exists('configuration', $config)) { if (array_key_exists('assign', $config["configuration"])) { $assign = trim($config["configuration"]["assign"]); $user = $this->getDoctrine()->getRepository('TellawLeadsFactoryBundle:Users')->findOneByEmail($assign); if ($user != null) { $leads->setUser($user); } else { $logger->info("Frontcontroller : Assign tu a User that does not exists! " . $assign); } } if (array_key_exists('status', $config["configuration"])) { $status = trim($config["configuration"]["status"]); $leads->setWorkflowStatus($status); } if (array_key_exists('type', $config["configuration"])) { $type = trim($config["configuration"]["type"]); $leads->setWorkflowType($type); } if (array_key_exists('theme', $config["configuration"])) { $theme = trim($config["configuration"]["theme"]); $leads->setWorkflowTheme($theme); } } $status = $exportUtils->hasScheduledExport($form->getConfig()) ? $exportUtils::$_EXPORT_NOT_PROCESSED : $exportUtils::$_EXPORT_NOT_SCHEDULED; $leads->setStatus($status); $leads->setCreatedAt(new \DateTime()); $em = $this->getDoctrine()->getManager(); $em->persist($leads); $em->flush(); // Index leads on search engine $leads_array = $this->get('leadsfactory.leads_repository')->getLeadsArrayById($leads->getId()); $searchUtils->indexLeadObject($leads_array, $leads->getForm()->getScope()->getCode()); // Create export job(s) if ($status == $exportUtils::$_EXPORT_NOT_PROCESSED) { $exportUtils->createJob($leads); } if (array_key_exists('enableApiNotificationEmail', $config["configuration"]) && $config["configuration"]["enableApiNotificationEmail"] == true) { //Send notification if (isset($config['notification'])) { $this->sendNotification($config['notification'], $leads); $logger->info("API : Envoi de notifications"); } else { $logger->info("API : Le bloc de configuration de Notification n'existe pas en config"); } } else { $logger->info("API : Le formulaire refuse l'envoi de mail par notification"); } if (array_key_exists('enableApiConfirmationEmail', $config["configuration"]) && $config["configuration"]["enableApiConfirmationEmail"] == true) { //Send confirmation email if (isset($config['confirmation_email'])) { $this->sendConfirmationEmail($config['confirmation_email'], $leads); } } return new Response(1); } catch (Exception $e) { $logger->error($e->getMessage()); return new Response(0); } }
public function loadDemoData($formId = null) { echo "Loading demo data\r\n"; $em = $this->container->get('doctrine')->getManager(); if ($formId == null) { $forms = $this->container->get('leadsfactory.form_repository')->findAll(); } else { $forms = array($this->container->get('leadsfactory.form_repository')->find($formId)); } // Loop over forms foreach ($forms as $form) { $day = new \DateTime(); $dateInterval = new \DateInterval('P1D'); echo "Processing form (" . $form->getId() . " -> " . $form->getName() . ")\r\n"; echo "--> Deleting leads\r\n"; // Delete leads for form $query = $em->getConnection()->prepare('DELETE FROM Leads WHERE form_id = :form_id'); $query->bindValue('form_id', $form->getId()); $query->execute(); // Reload leads for two years for ($i = 0; $i < 365; $i++) { // Random a number of leads for that day beetween 0 and 20 $leadsNumberForDay = rand(0, 5); echo "--> Creating Lead DAY : " . $i . "/365 (form : " . $form->getId() . " / number of leads to create : " . $leadsNumberForDay . ")\r\n"; $day->sub($dateInterval); for ($j = 0; $j <= $leadsNumberForDay; $j++) { $lead = new Leads(); $lead->setFirstname("firstname-(" . $j . "/" . $leadsNumberForDay . ")-" . rand()); $lead->setLastname("lastname-" . rand()); $lead->setStatus(1); $lead->setFormType($form->getFormType()); $lead->setForm($form); $lead->setCreatedAt($day); $em->persist($lead); unset($lead); } // Ajout des listes $this->createPageViewsForDemo($leadsNumberForDay, $form, $day); } } $em->flush(); }
/** * * Method used to populate objects with search engine content. * * @param $json * @return SearchResult * @throws \Exception */ public function populateObjectFromSearch($json) { $em = $this->container->get("doctrine")->getManager(); $content = json_decode($json); $results = new SearchResult(); $results->setTook($content->took); $results->setMaxScore($content->hits->max_score); $results->setTotal($content->hits->total); foreach ($content->hits->hits as $hit) { if ($hit->_type == 'leads') { $object = new Leads(); } else { throw new \Exception("Type is not available for ORM mapping : " . $hit->_type); } $results->addResult($object->populateFromSearch($hit->_source, $em)); } return $results; }