예제 #1
0
파일: API.php 프로젝트: nnnnathann/piwik
 /**
  * Add transitions data to the report.
  * Fake ArchiveProcessing to do the queries live.
  */
 private function addLiveTransitionsDataToReport(&$report, $pageUrl, $idSite, $period, $date, $segment, $limitBeforeGrouping)
 {
     // get idaction of page url
     $actionsPlugin = new Piwik_Actions();
     $idaction = $actionsPlugin->getIdActionFromSegment($pageUrl, 'idaction');
     // prepare archive processing that can be reused by the archiving code
     $archiveProcessing = new Piwik_ArchiveProcessing_Day();
     $archiveProcessing->setSite(new Piwik_Site($idSite));
     $archiveProcessing->setPeriod(Piwik_Period::advancedFactory($period, $date));
     $archiveProcessing->setSegment(new Piwik_Segment($segment, $idSite));
     $archiveProcessing->initForLiveUsage();
     // launch the archiving code - but live
     $transitionsArchiving = new Piwik_Transitions();
     $data = $transitionsArchiving->queryInternalReferrers($idaction, $archiveProcessing, $limitBeforeGrouping);
     $report['previousPages'] =& $data['previousPages'];
     $report['pageMetrics']['loops'] = intval($data['loops']);
     $data = $transitionsArchiving->queryFollowingActions($idaction, $archiveProcessing, $limitBeforeGrouping);
     foreach ($data as $tableName => $table) {
         $report[$tableName] = $table;
     }
     $data = $transitionsArchiving->queryExternalReferrers($idaction, $archiveProcessing, $limitBeforeGrouping);
     $report['pageMetrics']['entries'] = 0;
     $report['referrers'] = array();
     foreach ($data->getRows() as $row) {
         $referrerId = $row->getColumn('label');
         $visits = $row->getColumn(Piwik_Archive::INDEX_NB_VISITS);
         if ($visits) {
             // load details (i.e. subtables)
             $details = array();
             if ($idSubTable = $row->getIdSubDataTable()) {
                 $subTable = Piwik_DataTable_Manager::getInstance()->getTable($idSubTable);
                 foreach ($subTable->getRows() as $subRow) {
                     $details[] = array('label' => $subRow->getColumn('label'), 'referrals' => $subRow->getColumn(Piwik_Archive::INDEX_NB_VISITS));
                 }
             }
             $report['referrers'][] = array('label' => $this->getReferrerLabel($referrerId), 'shortName' => Piwik_getRefererTypeFromShortName($referrerId), 'visits' => $visits, 'details' => $details);
             $report['pageMetrics']['entries'] += $visits;
         }
     }
     // if there's no data for referrers, Piwik_API_ResponseBuilder::handleMultiDimensionalArray
     // does not detect the multi dimensional array and the data is rendered differently, which
     // causes an exception.
     if (count($report['referrers']) == 0) {
         $report['referrers'][] = array('label' => $this->getReferrerLabel(Piwik_Common::REFERER_TYPE_DIRECT_ENTRY), 'shortName' => Piwik_getRefererTypeLabel(Piwik_Common::REFERER_TYPE_DIRECT_ENTRY), 'visits' => 0);
     }
 }
예제 #2
0
 /**
  * Add the external referrers to the report:
  * direct entries, websites, campaigns, search engines
  * 
  * @param Piwik_Transitions $transitionsArchiving 
  * @param $archiveProcessing
  * @param $report
  * @param $idaction
  * @param string $actionType
  * @param $limitBeforeGrouping
  */
 private function addExternalReferrers($transitionsArchiving, $archiveProcessing, &$report, $idaction, $actionType, $limitBeforeGrouping)
 {
     $data = $transitionsArchiving->queryExternalReferrers($idaction, $actionType, $archiveProcessing, $limitBeforeGrouping);
     $report['pageMetrics']['entries'] = 0;
     $report['referrers'] = array();
     foreach ($data->getRows() as $row) {
         $referrerId = $row->getColumn('label');
         $visits = $row->getColumn(Piwik_Archive::INDEX_NB_VISITS);
         if ($visits) {
             // load details (i.e. subtables)
             $details = array();
             if ($idSubTable = $row->getIdSubDataTable()) {
                 $subTable = Piwik_DataTable_Manager::getInstance()->getTable($idSubTable);
                 foreach ($subTable->getRows() as $subRow) {
                     $details[] = array('label' => $subRow->getColumn('label'), 'referrals' => $subRow->getColumn(Piwik_Archive::INDEX_NB_VISITS));
                 }
             }
             $report['referrers'][] = array('label' => $this->getReferrerLabel($referrerId), 'shortName' => Piwik_getRefererTypeFromShortName($referrerId), 'visits' => $visits, 'details' => $details);
             $report['pageMetrics']['entries'] += $visits;
         }
     }
     // if there's no data for referrers, Piwik_API_ResponseBuilder::handleMultiDimensionalArray
     // does not detect the multi dimensional array and the data is rendered differently, which
     // causes an exception.
     if (count($report['referrers']) == 0) {
         $report['referrers'][] = array('label' => $this->getReferrerLabel(Piwik_Common::REFERER_TYPE_DIRECT_ENTRY), 'shortName' => Piwik_getRefererTypeLabel(Piwik_Common::REFERER_TYPE_DIRECT_ENTRY), 'visits' => 0);
     }
 }