/** * Get the contat from request (ct/clickthrough) and handles auto merging of contact data from request parameters * * @param array $queryFields */ public function getContactFromRequest($queryFields = []) { $lead = null; // Check for a lead requested through clickthrough query parameter if (isset($queryFields['ct'])) { $clickthrough = $queryFields['ct']; } elseif ($clickthrough = $this->request->get('ct', [])) { $clickthrough = $this->decodeArrayFromUrl($clickthrough); } if (is_array($clickthrough) && !empty($clickthrough['lead'])) { $lead = $this->getEntity($clickthrough['lead']); $this->logger->addDebug("LEAD: Contact ID# {$clickthrough['lead']} tracked through clickthrough query."); } // First determine if this request is already tracked as a specific lead list($trackingId, $generated) = $this->getTrackingCookie(); if ($leadId = $this->request->cookies->get($trackingId)) { if ($lead = $this->getEntity($leadId)) { $this->logger->addDebug("LEAD: Contact ID# {$leadId} tracked through tracking ID ({$trackingId}}."); } } // Search for lead by request and/or update lead fields if some data were sent in the URL query $availableLeadFields = $this->leadFieldModel->getFieldList(false, false, ['isPublished' => true, 'isPubliclyUpdatable' => true]); $uniqueLeadFields = $this->leadFieldModel->getUniqueIdentiferFields(); $uniqueLeadFieldData = []; $inQuery = array_intersect_key($queryFields, $availableLeadFields); foreach ($inQuery as $k => $v) { if (empty($queryFields[$k])) { unset($inQuery[$k]); } if (array_key_exists($k, $uniqueLeadFields)) { $uniqueLeadFieldData[$k] = $v; } } if (count($inQuery)) { // Check for leads using unique identifier if (count($uniqueLeadFieldData)) { $existingLeads = $this->getRepository()->getLeadsByUniqueFields($uniqueLeadFieldData, $lead ? $lead->getId() : null); if (!empty($existingLeads)) { $this->logger->addDebug("LEAD: Existing contact ID# {$existingLeads[0]->getId()} found through query identifiers."); // Merge with existing lead or use the one found $lead = $lead ? $this->mergeLeads($lead, $existingLeads[0]) : $existingLeads[0]; } } } if (empty($lead)) { // No lead found so generate one $lead = $this->getCurrentLead(); } $leadIpAddresses = $lead->getIpAddresses(); $ipAddress = $this->ipLookupHelper->getIpAddress(); if (!$leadIpAddresses->contains($ipAddress)) { $lead->addIpAddress($ipAddress); } $this->setFieldValues($lead, $inQuery); if (isset($queryFields['tags'])) { $this->modifyTags($lead, $queryFields['tags']); } $this->setCurrentLead($lead); return $lead; }
/** * Get lead fields used in selects/matching */ public function getLeadFields() { return $this->leadFieldModel->getFieldList(); }