diff options
author | Benaka Moorthi <benaka.moorthi@gmail.com> | 2013-09-12 06:31:23 +0400 |
---|---|---|
committer | Benaka Moorthi <benaka.moorthi@gmail.com> | 2013-09-12 06:31:23 +0400 |
commit | d989c794c832d40a66f7a56e6e0607a20e4a7af5 (patch) | |
tree | 2be381ef58115059aab81282da8a6b88489f7a19 | |
parent | d6f94510ca16b4f6b06d5113c97fa206f704b489 (diff) |
Refs #3089, tweaks to getVisitorProfile API output. Includes change that allows xml renderers to use special keys when rendering arrays.
4 files changed, 26 insertions, 17 deletions
diff --git a/core/DataTable/Renderer/Xml.php b/core/DataTable/Renderer/Xml.php index b3bba128cc..86cc9d8aa6 100644 --- a/core/DataTable/Renderer/Xml.php +++ b/core/DataTable/Renderer/Xml.php @@ -183,6 +183,12 @@ class Xml extends Renderer $prefix = "<row key=\"$key\">"; $suffix = "</row>"; $emptyNode = "<row key=\"$key\"/>"; + } else if (strpos($key, '=') !== false) { + list($keyAttributeName, $key) = explode('=', $key, 2); + + $prefix = "<row $keyAttributeName=\"$key\">"; + $suffix = "</row>"; + $emptyNode = "<row $keyAttributeName=\"$key\">"; } else { $prefix = "<$key>"; $suffix = "</$key>"; @@ -368,6 +374,7 @@ class Xml extends Renderer continue; } + // Handing case idgoal=7, creating a new array for that one $rowAttribute = ''; if (($equalFound = strstr($rowId, '=')) !== false) { diff --git a/plugins/Live/API.php b/plugins/Live/API.php index 85ac7c28cd..8cd7f37a3e 100644 --- a/plugins/Live/API.php +++ b/plugins/Live/API.php @@ -196,7 +196,7 @@ class API $result = array(); $result['totalVisits'] = 0; $result['totalVisitDuration'] = 0; - $result['totalActionCount'] = 0; + $result['totalActions'] = 0; $result['totalGoalConversions'] = 0; $result['totalConversionsByGoal'] = array(); @@ -217,24 +217,25 @@ class API ++$result['totalVisits']; $result['totalVisitDuration'] += $visit->getColumn('visitDuration'); - $result['totalActionCount'] += $visit->getColumn('actions'); + $result['totalActions'] += $visit->getColumn('actions'); $result['totalGoalConversions'] += $visit->getColumn('goalConversions'); // individual goal conversions are stored in action details foreach ($visit->getColumn('actionDetails') as $action) { if ($action['type'] == 'goal') { // handle goal conversion $idGoal = $action['goalId']; + $idGoalKey = 'idgoal=' . $idGoal; - if (!isset($result['totalConversionsByGoal'][$idGoal])) { - $result['totalConversionsByGoal'][$idGoal] = 0; + if (!isset($result['totalConversionsByGoal'][$idGoalKey])) { + $result['totalConversionsByGoal'][$idGoalKey] = 0; } - ++$result['totalConversionsByGoal'][$idGoal]; + ++$result['totalConversionsByGoal'][$idGoalKey]; if (!empty($action['revenue'])) { - if (!isset($result['totalRevenueByGoal'][$idGoal])) { - $result['totalRevenueByGoal'][$idGoal] = 0; + if (!isset($result['totalRevenueByGoal'][$idGoalKey])) { + $result['totalRevenueByGoal'][$idGoalKey] = 0; } - $result['totalRevenueByGoal'][$idGoal] += $action['revenue']; + $result['totalRevenueByGoal'][$idGoalKey] += $action['revenue']; } } else if ($action['type'] == Piwik::LABEL_ID_GOAL_IS_ECOMMERCE_ORDER // handle ecommerce order && $isEcommerceEnabled @@ -310,7 +311,7 @@ class API // looking at the popup. $latestVisitTime = reset($rows)->getColumn('lastActionDateTime'); $result['nextVisitorId'] = $this->getAdjacentVisitorId($idSite, $visitorId, $latestVisitTime, $segment, $getNext = true); - $result['prevVisitorId'] = $this->getAdjacentVisitorId($idSite, $visitorId, $latestVisitTime, $segment, $getNext = false); + $result['previousVisitorId'] = $this->getAdjacentVisitorId($idSite, $visitorId, $latestVisitTime, $segment, $getNext = false); Piwik_PostEvent(Live::GET_EXTRA_VISITOR_DETAILS_EVENT, array(&$result)); diff --git a/plugins/Live/templates/getVisitorProfilePopup.twig b/plugins/Live/templates/getVisitorProfilePopup.twig index 571f742be4..bba6323006 100644 --- a/plugins/Live/templates/getVisitorProfilePopup.twig +++ b/plugins/Live/templates/getVisitorProfilePopup.twig @@ -2,7 +2,7 @@ <div class="visitor-profile" data-visitor-id="{{ visitorData.lastVisits.getFirstRow().getColumn('visitorId') }}" data-next-visitor="{{ visitorData.nextVisitorId }}" - data-prev-visitor="{{ visitorData.prevVisitorId }}" + data-prev-visitor="{{ visitorData.previousVisitorId }}" tabindex="0"> <a href class="visitor-profile-close"></a> <div class="visitor-profile-info"> @@ -18,7 +18,7 @@ </div> <div> <div class="visitor-profile-header"> - {% if visitorData.prevVisitorId is not empty %}<a class="visitor-profile-prev-visitor" href="#" title="{{ 'Live_PreviousVisitor'|translate }}">←</a>{% endif %} + {% if visitorData.previousVisitorId is not empty %}<a class="visitor-profile-prev-visitor" href="#" title="{{ 'Live_PreviousVisitor'|translate }}">←</a>{% endif %} <h1>{{ 'Live_VisitorProfile'|translate }} <img class="loadingPiwik" style="display:none;" src="plugins/Zeitgeist/images/loading-blue.gif"/></h1> {% if visitorData.nextVisitorId is not empty %}<a class="visitor-profile-next-visitor" href="#" title="{{ 'Live_NextVisitor'|translate }}">→</a>{% endif %} </div> @@ -31,10 +31,11 @@ <div class="visitor-profile-summary"> <h1>{{ 'General_Summary'|translate }}</h1> <div> - <p>{{ 'Live_VisitSummary'|translate('<strong>', visitorData.totalVisitDurationPretty, '</strong>', '<strong>', visitorData.totalActionCount, visitorData.totalVisits, '</strong>')|raw }}</p> + <p>{{ 'Live_VisitSummary'|translate('<strong>', visitorData.totalVisitDurationPretty, '</strong>', '<strong>', visitorData.totalActions, visitorData.totalVisits, '</strong>')|raw }}</p> <p><strong>{{ 'Live_ConvertedNGoals'|translate(visitorData.totalGoalConversions) }}</strong> {%- if visitorData.totalGoalConversions %} ( {%- for idGoal, totalConversions in visitorData.totalConversionsByGoal -%} + {%- set idGoal = idGoal[7:] -%} {%- if not loop.first %}, {% endif -%}{{- totalConversions }} <span class="visitor-profile-goal-name">{{ goals[idGoal]['name'] -}}</span> {%- endfor -%} ){% endif %}.</p> diff --git a/tests/PHPUnit/Integration/expected/test_periodIsRange_dateIsLastN_MetadataAndNormalAPI__Live.getVisitorProfile.xml b/tests/PHPUnit/Integration/expected/test_periodIsRange_dateIsLastN_MetadataAndNormalAPI__Live.getVisitorProfile.xml index 3e9aa5413f..52f2f13e40 100644 --- a/tests/PHPUnit/Integration/expected/test_periodIsRange_dateIsLastN_MetadataAndNormalAPI__Live.getVisitorProfile.xml +++ b/tests/PHPUnit/Integration/expected/test_periodIsRange_dateIsLastN_MetadataAndNormalAPI__Live.getVisitorProfile.xml @@ -2,10 +2,10 @@ <result> <totalVisits>2</totalVisits> <totalVisitDuration>361</totalVisitDuration> - <totalActionCount>2</totalActionCount> + <totalActions>2</totalActions> <totalGoalConversions>1</totalGoalConversions> <totalConversionsByGoal> - <row key="1">1</row> + <row idgoal="1">1</row> </totalConversionsByGoal> <continents> <row> @@ -138,7 +138,7 @@ - <serverDateTimePrettyFirstAction>4 Sep 2013 16:55:17</serverDateTimePrettyFirstAction> + </row> <row> <idSite>1</idSite> @@ -252,9 +252,9 @@ - <serverDateTimePrettyFirstAction>4 Sep 2013 15:55:17</serverDateTimePrettyFirstAction> + </row> </lastVisits> - + <previousVisitorId>61e8cc2d51fea26d</previousVisitorId> </result>
\ No newline at end of file |