Esempio n. 1
0
 /**
  * @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);
 }