diff options
author | mattab <matthieu.aubry@gmail.com> | 2013-10-22 01:59:17 +0400 |
---|---|---|
committer | mattab <matthieu.aubry@gmail.com> | 2013-10-22 01:59:17 +0400 |
commit | 3760ca1fd8fe6e62b9480bf88780e70c8e160b90 (patch) | |
tree | e42f7f431b95860284a546189f1388b7eea8f428 /plugins/Transitions | |
parent | b12d4b972d031ebf66d8cfc682757a606e4f06b8 (diff) |
Tracker refactor + fix bug in bulk authentication + Cleanup some of Transitions code refs #472
Diffstat (limited to 'plugins/Transitions')
-rw-r--r-- | plugins/Transitions/API.php | 109 |
1 files changed, 51 insertions, 58 deletions
diff --git a/plugins/Transitions/API.php b/plugins/Transitions/API.php index 793d46a150..618e50505c 100644 --- a/plugins/Transitions/API.php +++ b/plugins/Transitions/API.php @@ -58,12 +58,11 @@ class API extends \Piwik\Plugin\API * @param bool $segment * @param bool $limitBeforeGrouping * @param string $parts - * @param bool $returnNormalizedUrls * @return array * @throws Exception */ public function getTransitionsForAction($actionName, $actionType, $idSite, $period, $date, - $segment = false, $limitBeforeGrouping = false, $parts = 'all', $returnNormalizedUrls = false) + $segment = false, $limitBeforeGrouping = false, $parts = 'all') { Piwik::checkUserHasViewAccess($idSite); @@ -84,9 +83,6 @@ class API extends \Piwik\Plugin\API 'date' => Day::advancedFactory($period->getLabel(), $date)->getLocalizedShortString() ); - // add data to the report - $this->returnNormalizedUrls(); - $partsArray = explode(',', $parts); if ($parts == 'all' || in_array('internalReferrers', $partsArray)) { @@ -226,13 +222,12 @@ class API extends \Piwik\Plugin\API * @param $includeLoops * @return array(followingPages:DataTable, outlinks:DataTable, downloads:DataTable) */ - public function queryFollowingActions($idaction, $actionType, LogAggregator $logAggregator, + protected function queryFollowingActions($idaction, $actionType, LogAggregator $logAggregator, $limitBeforeGrouping = false, $includeLoops = false) { $types = array(); - $isTitle = ($actionType == 'title'); - if (!$isTitle) { + if ($actionType != 'title') { // specific setup for page urls $types[Action::TYPE_PAGE_URL] = 'followingPages'; $dimension = 'IF( idaction_url IS NULL, idaction_name, idaction_url )'; @@ -296,38 +291,12 @@ class API extends \Piwik\Plugin\API $metrics = array(Metrics::INDEX_NB_ACTIONS); $data = $logAggregator->queryActionsByDimension(array($dimension), $where, $selects, $metrics, $rankingQuery, $joinLogActionColumn); - $this->totalTransitionsToFollowingActions = 0; - $dataTables = array(); - foreach ($types as $type => $recordName) { - $dataTable = new DataTable; - if (isset($data[$type])) { - foreach ($data[$type] as &$record) { - $actions = intval($record[Metrics::INDEX_NB_ACTIONS]); - $dataTable->addRow(new Row(array( - Row::COLUMNS => array( - 'label' => $this->getPageLabel($record, $isTitle), - Metrics::INDEX_NB_ACTIONS => $actions - ) - ))); - $this->totalTransitionsToFollowingActions += $actions; - } - } - $dataTables[$recordName] = $dataTable; - } + $dataTables = $this->makeDataTablesFollowingActions($types, $data); return $dataTables; } /** - * After calling this method, the query*()-Methods will return urls in their - * normalized form (without the prefix reconstructed) - */ - public function returnNormalizedUrls() - { - $this->returnNormalizedUrls = true; - } - - /** * Get information about external referrers (i.e. search engines, websites & campaigns) * * @param $idaction @@ -336,7 +305,7 @@ class API extends \Piwik\Plugin\API * @param $limitBeforeGrouping * @return DataTable */ - public function queryExternalReferrers($idaction, $actionType, $logAggregator, $limitBeforeGrouping = false) + protected function queryExternalReferrers($idaction, $actionType, $logAggregator, $limitBeforeGrouping = false) { $rankingQuery = new RankingQuery($limitBeforeGrouping ? $limitBeforeGrouping : $this->limitBeforeGrouping); @@ -410,17 +379,20 @@ class API extends \Piwik\Plugin\API */ 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(0, 1, 2)); + $rankingQuery->partitionResultIntoMultipleGroups('action_partition', array($keyIsOther, $keyIsPageUrlAction, $keyIsSiteSearchAction)); $type = $this->getColumnTypeSuffix($actionType); $mainActionType = Action::TYPE_PAGE_URL; $dimension = 'idaction_url_ref'; - $isTitle = $actionType == 'title'; - if ($isTitle) { + if ($actionType == 'title') { $mainActionType = Action::TYPE_PAGE_TITLE; $dimension = 'idaction_name_ref'; } @@ -430,9 +402,9 @@ class API extends \Piwik\Plugin\API '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 1 - WHEN log_action.type = ' . Action::TYPE_SITE_SEARCH . ' THEN 2 - ELSE 0 + WHEN log_action.type = ' . $mainActionType . ' THEN ' . $keyIsPageUrlAction . ' + WHEN log_action.type = ' . Action::TYPE_SITE_SEARCH . ' THEN ' . $keyIsSiteSearchAction .' + ELSE ' . $keyIsOther . ' END AS `action_partition`' ); @@ -453,12 +425,12 @@ class API extends \Piwik\Plugin\API $loops = 0; $nbPageviews = 0; $previousPagesDataTable = new DataTable; - if (isset($data['result'][1])) { - foreach ($data['result'][1] as &$page) { + 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, $isTitle), + 'label' => $this->getPageLabel($page, Action::TYPE_PAGE_URL), Metrics::INDEX_NB_ACTIONS => $nbActions ) ))); @@ -467,8 +439,8 @@ class API extends \Piwik\Plugin\API } $previousSearchesDataTable = new DataTable; - if (isset($data['result'][2])) { - foreach ($data['result'][2] as &$search) { + 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( @@ -499,21 +471,21 @@ class API extends \Piwik\Plugin\API ); } - private function getPageLabel(&$pageRecord, $isTitle) + private function getPageLabel(&$pageRecord, $type) { - if ($isTitle) { + if ($type == Action::TYPE_PAGE_TITLE) { $label = $pageRecord['name']; if (empty($label)) { - $label = ArchivingHelper::getUnknownActionName( - Action::TYPE_PAGE_TITLE); + $label = ArchivingHelper::getUnknownActionName(Action::TYPE_PAGE_TITLE); } return $label; - } else if ($this->returnNormalizedUrls) { - return $pageRecord['name']; - } else { - return PageUrl::reconstructNormalizedUrl( - $pageRecord['name'], $pageRecord['url_prefix']); } + + if ($type == Action::TYPE_OUTLINK || $type == Action::TYPE_DOWNLOAD) { + return PageUrl::reconstructNormalizedUrl($pageRecord['name'], $pageRecord['url_prefix']); + } + + return $pageRecord['name']; } private function getColumnTypeSuffix($actionType) @@ -527,8 +499,6 @@ class API extends \Piwik\Plugin\API private $limitBeforeGrouping = 5; private $totalTransitionsToFollowingActions = 0; - private $returnNormalizedUrls = false; - /** * Get the sum of all transitions to following actions (pages, outlinks, downloads). * Only works if queryFollowingActions() has been used directly before. @@ -614,4 +584,27 @@ class API extends \Piwik\Plugin\API $controller = new Controller(); return $controller->getTranslations(); } + + protected function makeDataTablesFollowingActions($types, $data) + { + $this->totalTransitionsToFollowingActions = 0; + $dataTables = array(); + foreach ($types as $type => $recordName) { + $dataTable = new DataTable; + if (isset($data[$type])) { + foreach ($data[$type] as &$record) { + $actions = intval($record[Metrics::INDEX_NB_ACTIONS]); + $dataTable->addRow(new Row(array( + Row::COLUMNS => array( + 'label' => $this->getPageLabel($record, $type), + Metrics::INDEX_NB_ACTIONS => $actions + ) + ))); + $this->totalTransitionsToFollowingActions += $actions; + } + } + $dataTables[$recordName] = $dataTable; + } + return $dataTables; + } }
\ No newline at end of file |