Пример #1
0
 public function extractLead(Lead $lead)
 {
     $headings = $this->exportHeadings;
     $entityManager = $this->getEntityManager();
     $hydrator = new DoctrineHydrator($entityManager);
     $leadArray = $hydrator->extract($lead);
     $output = array_combine($headings, array_pad([], count($headings), ""));
     foreach ($headings as $heading) {
         switch ($heading) {
             case "Account":
                 $account = $lead->getAccount();
                 $output[$heading] = $account ? $account->getName() : "N/A";
                 break;
             case "Time Created":
                 $time = $lead->getTimecreated();
                 if ($time instanceof \DateTime) {
                     $time = date_format($time, 'Y-m-d H:i:s');
                 }
                 $output[$heading] = $time;
                 break;
             case "Referrer":
                 $output[$heading] = $lead->getReferrer();
                 break;
             case "IP Address":
                 $output[$heading] = $lead->getIpaddress();
                 break;
             default:
                 $attribute = $lead->findAttribute($heading);
                 if (!$attribute) {
                     $attributes = $lead->getAttributes(true)->filter(function ($attribute) use($heading) {
                         $real_attribute = false;
                         $attribute_desc = false;
                         if ($attribute) {
                             $real_attribute = $attribute->getAttribute();
                         }
                         if ($real_attribute) {
                             $attribute_desc = $real_attribute->getAttributeDesc();
                         }
                         return $attribute_desc == $heading;
                     });
                     if ($attributes->count() > 0) {
                         $attribute = $attributes->first();
                     }
                 }
                 if ($attribute) {
                     $output[$heading] = $attribute->getValue();
                 }
                 break;
         }
     }
     return $output;
 }
Пример #2
0
 protected function extract(Lead $lead)
 {
     $entityClass = get_class($lead);
     $hydrator = new DoctrineHydrator($this->getEntityManager(), $entityClass);
     $hydrator->addStrategy('timecreated', new DateTimeStrategy());
     $hydrator->addStrategy('lastsubmitted', new DateTimeStrategy());
     return $hydrator->extract($lead);
 }
 protected function getLead($id, $extract = true)
 {
     $em = $this->getEntityManager();
     $lead = $this->lead;
     if (!$lead || $lead instanceof Lead && $lead->getId() != $id) {
         $leadRepository = $em->getRepository("Lead\\Entity\\Lead");
         $lead = $leadRepository->findOneBy(['id' => $id]);
         $this->setLead($lead);
     }
     if ($lead) {
         if ($extract) {
             $hydrator = new DoctrineHydrator($em);
             return $hydrator->extract($lead);
         }
         return $lead;
     }
     return false;
 }
Пример #4
0
 public function exportAction()
 {
     set_time_limit(0);
     $results = array();
     $labels = array();
     $headings = array();
     $limit = $this->getLimit($this->defaultPageSize);
     $page = $this->getRequest()->getQuery('page', 0);
     $sort = $this->getRequest()->getQuery('sort', $this->defaultSort);
     $order = $this->getRequest()->getQuery('order', $this->defaultOrder);
     if (empty($sort)) {
         $sort = $this->defaultSort;
     }
     /* @var $qb \Doctrine\ORM\QueryBuilder */
     $qb = $this->getEntityManager()->createQueryBuilder();
     $qb->add('select', 'e')->add('from', $this->getEntityClass() . ' e')->orderBy('e.' . $sort, $order);
     $qb = $this->handleSearch($qb);
     $entityManager = $this->getEntityManager();
     $hydrator = new DoctrineHydrator($entityManager);
     $eventPrototype = new Event();
     $eventArray = $hydrator->extract($eventPrototype);
     $eventArray = array_map('ucwords', array_keys($eventArray));
     $leadArray = ['id', 'Full Name', 'Account'];
     $leadArray = array_map('ucwords', $leadArray);
     $headings = ['event' => $eventArray, 'lead' => $leadArray];
     foreach ($headings as $entity => $array) {
         foreach ($array as $heading) {
             $mergedArray[] = ucwords($entity . ' ' . $heading);
         }
     }
     $this->exportHeadings = $mergedArray;
     $results = $qb->getQuery()->getResult();
     return $this->csvExport('Event Log (' . date('Y-m-d') . ').csv', $this->exportHeadings, $results, array($this, 'extractEvent'));
 }