Beispiel #1
0
 /**
  *
  * @param Lead $proxy        	
  *
  * @return \Lead\Entity\Lead
  */
 private function _hydrate(Lead $proxy)
 {
     $lead = null;
     $reports = $this->getReports();
     $objectManager = $this->getObjectManager();
     if ($objectManager) {
         $leadRepo = $objectManager->getRepository('Lead\\Entity\\Lead');
         if ($proxy && $proxy->getProxy() && ($id = $proxy->getId()) == true) {
             $lead = $leadRepo->findLead($id);
             if ($lead) {
                 $lead->setProxy(false);
             }
         } elseif (!$proxy->getProxy()) {
             $lead = $proxy;
         }
     }
     return $lead;
 }
 protected function setReferrerLead($referrer, Lead $lead, $flush = false)
 {
     $em = $this->getEntityManager();
     $this->createServiceEvent()->setEntityId($lead->getId())->setEntityClass($this->getEntityClass())->setDescription("Lead Edited");
     try {
         $lead->setReferrer($referrer);
         $em->merge($lead);
         if ($flush) {
             $em->flush();
             $em->detach($lead);
         }
         $this->getServiceEvent()->setMessage("Referrer for Lead #{$lead->getId()} was edited.");
         $this->logEvent("EditAction.post");
     } catch (\Exception $e) {
         $this->logError($e);
         return false;
     }
     return true;
 }
 protected function isValid(Lead $lead)
 {
     $valid = true;
     $webworks = false;
     $options = false;
     $account = $lead->getAccount();
     $apis = $account->getApis();
     // Check WebWorks API
     if ($apis) {
         foreach ($apis as $api) {
             if ($api->getName() == 'WebWorks') {
                 $webworks = $api;
             }
         }
     }
     if ($webworks) {
         $options = [];
         $apiOptions = $webworks->getOptions();
         $values = array_map(function ($option) {
             return [$option->getOption() => $option->getValue()];
         }, array_filter($apiOptions, function ($option) {
             return $option->getApi()->getName() == 'WebWorks' && !empty($option->getValue()) && $option->getScope() == 'global';
         }));
         foreach ($values as $option) {
             foreach ($option as $key => $value) {
                 switch ($key) {
                     case 'AppReferrer':
                         if (!preg_match('/none/i', trim($value))) {
                             $options[$key] = preg_replace('/\\{lead\\}/i', "Lead #" . $lead->getId(), $value);
                         }
                         break;
                     default:
                         $options[$key] = $value;
                         break;
                 }
             }
         }
         foreach ($account->getApiSettings() as $apiSetting) {
             $option = $apiSetting->getApiOption();
             switch ($option->getOption()) {
                 case 'CompanyId':
                     $options['CompanyId'] = $apiSetting->getApiValue();
                     break;
                 case 'CompanyName':
                     $options['CompanyName'] = $apiSetting->getApiValue();
                     break;
                 case 'AppReferrer':
                     if (!preg_match('/none/i', trim($apiSetting->getApiValue()))) {
                         $options['AppReferrer'] = $apiSetting->getApiValue();
                     } else {
                         unset($options['AppReferrer']);
                     }
                     break;
             }
         }
         foreach (['Source', 'CompanyId'] as $option) {
             if (!in_array($option, array_keys($options))) {
                 $valid = false;
             }
         }
     } else {
         $valid = false;
     }
     return $valid ? $options : false;
 }
 /**
  * Set lead
  *
  * @param \Lead\Entity\Lead $lead        	
  *
  * @return LeadAttributeValue
  */
 public function setLead(\Lead\Entity\Lead $lead = null)
 {
     $this->lead = $lead;
     if ($this->lead instanceof Lead) {
         $this->setParent($this->lead->getId());
     }
     return $this;
 }