示例#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);
 }
 protected function getSources(array $results = [], $list = false)
 {
     $sources = [];
     if (!$results) {
         $results = $this->getReferrers();
     }
     foreach ($results as $record) {
         $referrer = Helper::add_protocol(strtolower($record['referrer']));
         $domain = $referrer ? parse_url($referrer, PHP_URL_HOST) : false;
         $count = $record['refcount'];
         if (!$domain) {
             $domain = 'unknown';
         }
         if (isset($sources[$domain])) {
             $sources[$domain]['referrers'][] = $record['referrer'];
             $sources[$domain]['count'] += $count;
         } else {
             $sources[$domain] = ['source' => $domain, 'count' => $count, 'referrers' => [$record['referrer']]];
         }
     }
     if ($list) {
         $sources = array_combine(array_keys($sources), array_keys($sources));
     }
     return $sources;
 }