Пример #1
0
 protected function hydrate(Lead $lead, $data = [])
 {
     $em = $this->getEntityManager();
     $leadAttributeRepository = $em->getRepository("Lead\\Entity\\LeadAttribute");
     $accountRepository = $em->getRepository("Account\\Entity\\Account");
     if (isset($data['attributes'], $data['lead'])) {
         $attribute_count = $leadAttributeRepository->getCount();
         foreach ($data as $section => $values) {
             switch ($section) {
                 case 'attributes':
                     foreach ($values as $attributeName => $attributeValue) {
                         $leadAttribute = $leadAttributeRepository->findOneBy(['attributeName' => $attributeName, 'active' => 1]);
                         if (!$leadAttribute) {
                             $leadAttribute = $leadAttributeRepository->findOneBy(['attributeDesc' => $attributeName, 'attributeName' => 'Question', 'active' => 1]);
                         }
                         if (!$leadAttribute) {
                             $leadAttribute = new LeadAttribute();
                             $leadAttribute->setAttributeName('Question');
                             $leadAttribute->setAttributeDesc($attributeName);
                             $leadAttribute->setAttributeOrder($attribute_count++);
                         }
                         if ($leadAttribute) {
                             $leadAttributeValue = new LeadAttributeValue();
                             $leadAttributeValue->setValue($attributeValue);
                             $leadAttributeValue->setAttribute($leadAttribute);
                             $lead->addAttribute($leadAttributeValue);
                         }
                     }
                     break;
                 case 'lead':
                     foreach ($values as $property => $value) {
                         switch ($property) {
                             case 'timecreated':
                             case 'referrer':
                             case 'ipaddress':
                                 if ($property == 'timecreated') {
                                     // $isvalid =
                                     // $this->validateDate($value);
                                     $value = new \DateTime("now");
                                 }
                                 if (method_exists($lead, 'set' . ucfirst($property))) {
                                     $lead->{'set' . ucfirst($property)}($value);
                                 }
                                 break;
                             case 'company':
                             case 'companyid':
                                 if (!$lead->getAccount()) {
                                     switch ($property) {
                                         case 'company':
                                             $criteria = ['name' => $value];
                                             break;
                                         case 'companyid':
                                             $criteria = ['id' => $value];
                                             break;
                                     }
                                     $account = $accountRepository->findOneBy($criteria);
                                     if ($account) {
                                         $lead->setAccount($account);
                                     }
                                 }
                                 break;
                         }
                     }
                     break;
             }
         }
         return $lead;
     }
     return false;
 }
Пример #2
0
 protected function hydrate(Lead $lead, $data = [])
 {
     $em = $this->getEntityManager();
     $leadAttributeRepository = $em->getRepository("Lead\\Entity\\LeadAttribute");
     foreach ($data as $attributeId => $csvRowItem) {
         if (is_array($csvRowItem)) {
             $csvHeading = key($csvRowItem);
             $csvValue = current($csvRowItem);
             if (is_numeric($attributeId)) {
                 $leadAttribute = $leadAttributeRepository->findOneBy(['id' => $attributeId, 'active' => 1]);
                 if ($leadAttribute) {
                     $leadAttributeValue = new LeadAttributeValue();
                     $leadAttributeValue->setValue($csvValue);
                     $leadAttributeValue->setAttribute($leadAttribute);
                     $lead->addAttribute($leadAttributeValue);
                 }
             } elseif ($attributeId == "Question") {
                 if (is_array($csvValue)) {
                     foreach ($csvRowItem as $csvHeading => $arrayValue) {
                         $csvValue = current($arrayValue);
                         $leadAttribute = $leadAttributeRepository->findOneBy(['attributeDesc' => $csvHeading, 'active' => 1]);
                         if (!$leadAttribute) {
                             $leadAttribute = new LeadAttribute();
                             $leadAttribute->setAttributeName($attributeId);
                             $leadAttribute->setAttributeDesc($csvHeading);
                         }
                         $leadAttributeValue = new LeadAttributeValue();
                         $leadAttributeValue->setValue($csvValue);
                         $leadAttributeValue->setAttribute($leadAttribute);
                         $lead->addAttribute($leadAttributeValue);
                     }
                 } else {
                     $leadAttribute = $leadAttributeRepository->findOneBy(['attributeDesc' => $csvHeading, 'active' => 1]);
                     if (!$leadAttribute) {
                         $leadAttribute = new LeadAttribute();
                         $leadAttribute->setAttributeName($attributeId);
                         $leadAttribute->setAttributeDesc($csvHeading);
                     }
                     $leadAttributeValue = new LeadAttributeValue();
                     $leadAttributeValue->setValue($csvValue);
                     $leadAttributeValue->setAttribute($leadAttribute);
                     $lead->addAttribute($leadAttributeValue);
                 }
             } elseif (in_array($attributeId, ['lastsubmitted', 'timecreated', 'referrer', 'ipaddress'])) {
                 if (in_array($attributeId, ['lastsubmitted', 'timecreated'])) {
                     $isvalid = $this->validateDate($csvValue);
                     $csvValue = $isvalid ? new \DateTime($csvValue) : new \DateTime("now");
                 }
                 $lead->{'set' . ucfirst($attributeId)}($csvValue);
             }
         }
     }
     return $lead;
 }
 /**
  * Set Attribute Order
  *
  * @param integer $order        	
  *
  * @return LeadAttributeValue
  */
 public function setOrder($order)
 {
     $this->attribute->setAttributeOrder($order);
     return $this;
 }