/** * @ORM\PostLoad * * @param Lead $lead * @param LifecycleEventArgs $event */ public function postLoad(Lead $lead, LifecycleEventArgs $event) { // Get the values for the ArrayCollection and sort it using the function $attributes = $lead->getAttributes(); // Filter by active LeadAttribute if ($attributes) { $attributes = array_filter($attributes, function ($leadAttributeValue) { $attribute = $leadAttributeValue->getAttribute(); return $attribute ? $attribute->getActive() : false; }); } // sort as you like usort($attributes, function ($a, $b) { $aOrder = $bOrder = 0; $aAttribute = $a->getAttribute(); if ($aAttribute) { $aOrder = $aAttribute->getAttributeOrder(); } $bAttribute = $b->getAttribute(); if ($bAttribute) { $bOrder = $bAttribute->getAttributeOrder(); } return $aOrder - $bOrder; }); // Clear the current collection values and reintroduce in new order. $lead->setAttributes(new ArrayCollection($attributes)); $default_ip = "0.0.0.0"; $ip = $lead->getIpaddress(); $ip_filtered = Helper::validate_ipv4($ip, false) ? $ip : $default_ip; $lead->setIpv4address($ip_filtered); $referrer = $lead->getReferrer(); $referrer_filtered = $referrer ? Helper::add_protocol(strtolower($referrer)) : null; $lead->setReferrer($referrer_filtered); }
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; }