コード例 #1
0
 /**
  * @group Core
  */
 public function testExcludeRows()
 {
     $query = new RankingQuery(20);
     $query->addLabelColumn('label');
     $query->setColumnToMarkExcludedRows('exclude_marker');
     $innerQuery = "SELECT label, 1 AS exclude_marker FROM myTable";
     $expected = "\n\t\t\tSELECT\n\t\t\t\tCASE\n\t\t\t\t\tWHEN counter = 21 THEN 'Others'\n\t\t\t\t\tELSE `label`\n\t\t\t\tEND AS `label`,\n\t\t\t\t`exclude_marker`\n\t\t\tFROM ( \n\t\t\t\tSELECT\n\t\t\t\t\t`label`,\n\t\t\t\t\tCASE\n\t\t\t\t\t\tWHEN exclude_marker != 0 THEN -1 * exclude_marker\n\t\t\t\t\t\tWHEN @counter = 21 THEN 21\n\t\t\t\t\t\tELSE @counter:=@counter+1\n\t\t\t\t\tEND AS counter,\n\t\t\t\t\t`exclude_marker`\n\t\t\t\tFROM\n\t\t\t\t\t( SELECT @counter:=0 ) initCounter,\n\t\t\t\t\t( SELECT label, 1 AS exclude_marker FROM myTable ) actualQuery\n\t\t\t) AS withCounter\n\t\t\tGROUP BY counter\n\t\t";
     $this->checkQuery($query, $innerQuery, $expected);
 }
コード例 #2
0
ファイル: API.php プロジェクト: a4tunado/piwik
 /**
  * Get information about internal referrers (previous pages & loops, i.e. page refreshes)
  *
  * @param $idaction
  * @param $actionType
  * @param LogAggregator $logAggregator
  * @param $limitBeforeGrouping
  * @return array(previousPages:DataTable, loops:integer)
  */
 protected function queryInternalReferrers($idaction, $actionType, $logAggregator, $limitBeforeGrouping = false)
 {
     $keyIsOther = 0;
     $keyIsPageUrlAction = 1;
     $keyIsSiteSearchAction = 2;
     $rankingQuery = new RankingQuery($limitBeforeGrouping ? $limitBeforeGrouping : $this->limitBeforeGrouping);
     $rankingQuery->addLabelColumn(array('name', 'url_prefix'));
     $rankingQuery->setColumnToMarkExcludedRows('is_self');
     $rankingQuery->partitionResultIntoMultipleGroups('action_partition', array($keyIsOther, $keyIsPageUrlAction, $keyIsSiteSearchAction));
     $type = $this->getColumnTypeSuffix($actionType);
     $mainActionType = Action::TYPE_PAGE_URL;
     $dimension = 'idaction_url_ref';
     if ($actionType == 'title') {
         $mainActionType = Action::TYPE_PAGE_TITLE;
         $dimension = 'idaction_name_ref';
     }
     $selects = array('log_action.name', 'log_action.url_prefix', 'CASE WHEN log_link_visit_action.idaction_' . $type . '_ref = ' . intval($idaction) . ' THEN 1 ELSE 0 END AS `is_self`', 'CASE
             WHEN log_action.type = ' . $mainActionType . ' THEN ' . $keyIsPageUrlAction . '
                     WHEN log_action.type = ' . Action::TYPE_SITE_SEARCH . ' THEN ' . $keyIsSiteSearchAction . '
                     ELSE ' . $keyIsOther . '
                 END AS `action_partition`');
     $where = ' log_link_visit_action.idaction_' . $type . ' = ' . intval($idaction);
     if ($dimension == 'idaction_url_ref') {
         // site search referrers are logged with url_ref=NULL
         // when we find one, we have to join on name_ref
         $dimension = 'IF( idaction_url_ref IS NULL, idaction_name_ref, idaction_url_ref )';
         $joinLogActionOn = $dimension;
     } else {
         $joinLogActionOn = $dimension;
     }
     $metrics = array(Metrics::INDEX_NB_ACTIONS);
     $data = $logAggregator->queryActionsByDimension(array($dimension), $where, $selects, $metrics, $rankingQuery, $joinLogActionOn);
     $loops = 0;
     $nbPageviews = 0;
     $previousPagesDataTable = new DataTable();
     if (isset($data['result'][$keyIsPageUrlAction])) {
         foreach ($data['result'][$keyIsPageUrlAction] as &$page) {
             $nbActions = intval($page[Metrics::INDEX_NB_ACTIONS]);
             $previousPagesDataTable->addRow(new Row(array(Row::COLUMNS => array('label' => $this->getPageLabel($page, Action::TYPE_PAGE_URL), Metrics::INDEX_NB_ACTIONS => $nbActions))));
             $nbPageviews += $nbActions;
         }
     }
     $previousSearchesDataTable = new DataTable();
     if (isset($data['result'][$keyIsSiteSearchAction])) {
         foreach ($data['result'][$keyIsSiteSearchAction] as &$search) {
             $nbActions = intval($search[Metrics::INDEX_NB_ACTIONS]);
             $previousSearchesDataTable->addRow(new Row(array(Row::COLUMNS => array('label' => $search['name'], Metrics::INDEX_NB_ACTIONS => $nbActions))));
             $nbPageviews += $nbActions;
         }
     }
     if (isset($data['result'][0])) {
         foreach ($data['result'][0] as &$referrer) {
             $nbPageviews += intval($referrer[Metrics::INDEX_NB_ACTIONS]);
         }
     }
     if (count($data['excludedFromLimit'])) {
         $loops += intval($data['excludedFromLimit'][0][Metrics::INDEX_NB_ACTIONS]);
         $nbPageviews += $loops;
     }
     return array('pageviews' => $nbPageviews, 'previousPages' => $previousPagesDataTable, 'previousSiteSearches' => $previousSearchesDataTable, 'loops' => $loops);
 }