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; }
/** * Set Attribute Order * * @param integer $order * * @return LeadAttributeValue */ public function setOrder($order) { $this->attribute->setAttributeOrder($order); return $this; }