public function saveImpressionsAction(Request $request)
 {
     $this->_throwUnsupportedMethodIfNotPost($request);
     $form = $this->createForm(new TrackerFormType());
     $form->bind($request);
     // invalid form
     if (!$form->isValid()) {
         $this->_throwHttpException(400, 'Invalid form');
     }
     $impressions = $request->get('impressions', array());
     if (!\count($impressions)) {
         return new Response('Empty impressions', 200);
         //$this->_throwHttpException(400, 'Empty impressions');
     }
     $trackerFactory = $this->get('factory.statistics.dailyTracker');
     $trackersUsed = array();
     // add impressions to daily trackers
     foreach ($impressions as $_encodedImpression) {
         $decodedImpression = StatisticParameters::decodeParameters($_encodedImpression);
         // no statisic type parameter, or invalid type
         if (!$decodedImpression->has(StatisticParameters::TYPE) || !StatisticTypes::isValidType($decodedImpression->get(StatisticParameters::TYPE))) {
             // lets skip this for now.
             continue;
         }
         if (!isset($trackersUsed[$decodedImpression->get(StatisticParameters::TYPE)])) {
             $trackersUsed[$decodedImpression->get(StatisticParameters::TYPE)] = $trackerFactory->getTrackerByType($decodedImpression->get(StatisticParameters::TYPE));
         }
         $tracker = $trackersUsed[$decodedImpression->get(StatisticParameters::TYPE)];
         if ($data = $tracker->createDataFromParameters($decodedImpression)) {
             //                 $em = $this->getDoctrine()->getEntityManager('statistics');
             //                 $em->persist($data);
             //                 $em->flush();
             //                 return $this->render('::base.ajaxDebugger.html.twig');
             //                 var_dump($data); exit;
             $tracker->add($data);
         }
     }
     // batch save the impressions
     foreach ($trackersUsed as $tracker) {
         try {
             $tracker->batchSave();
         } catch (\Exception $e) {
             // log this exception
         }
     }
     return new Response('Impressions saved', 200);
 }
 public function encode_search_result_item_impression_parameters($searchResultItem)
 {
     $encodedParameters = '';
     // only instances of InstitutionMedicalCenter and Institution will be accepted as searchResultItem
     if ($searchResultItem instanceof InstitutionMedicalCenter || $searchResultItem instanceof Institution) {
         $parameters = $this->_getCommonSearchResultItemStatisticsParameters($searchResultItem, $searchResultItem instanceof InstitutionMedicalCenter);
         $parameters[StatisticParameters::CATEGORY_ID] = StatisticCategories::SEARCH_RESULTS_PAGE_ITEM_IMPRESSIONS;
         $encodedParameters = StatisticParameters::encodeParameters($parameters);
     }
     return $encodedParameters;
 }