Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormattpiwik <matthieu.aubry@gmail.com>2011-04-07 09:56:43 +0400
committermattpiwik <matthieu.aubry@gmail.com>2011-04-07 09:56:43 +0400
commit88fc021d09fa34fbcf24934c4a28df5074d4051d (patch)
tree34adaa6a988d0cd2dc69f36f296bc79596819434 /plugins/Live/Controller.php
parenta30e99c190a7c9fcdafc6ed5c1ea05eac77a31df (diff)
Refs #1839 Simplyfying Live! plugin, removing unused code, cleaned up API, only 3 useful functions left with proper names (and more performant too),
+ adding tests, this one dedicated to Anthon ;) Refs #1956 while Live! is not metadata compliant, I now consider the API stable (efficient + function names & parameters) and Piwik Mobile can start using it :) Let me know if you need any other api/ doc / info :) NB: build will fail since it's pending another change in tracking API which I'll commit asap git-svn-id: http://dev.piwik.org/svn/trunk@4349 59fd770c-687e-43c8-a1e3-f5a4ff64c105
Diffstat (limited to 'plugins/Live/Controller.php')
-rw-r--r--plugins/Live/Controller.php112
1 files changed, 43 insertions, 69 deletions
diff --git a/plugins/Live/Controller.php b/plugins/Live/Controller.php
index 401fc88236..24eba43d49 100644
--- a/plugins/Live/Controller.php
+++ b/plugins/Live/Controller.php
@@ -17,37 +17,53 @@ class Piwik_Live_Controller extends Piwik_Controller
{
function index()
{
- $this->widget(true);
+ return $this->widget(true);
}
public function widget($fetch = false)
{
$view = Piwik_View::factory('index');
$view->idSite = $this->idSite;
- $view->visitorsCountHalfHour = $this->getUsersInLastXMin(30);
- $view->visitorsCountToday = $this->getUsersInLastXDays(1);
- $view->pisHalfhour = $this->getPageImpressionsInLastXMin(30);
- $view->pisToday = $this->getPageImpressionsInLastXDays(1);
+
+ $view = $this->setCounters($view);
+
$view->visitors = $this->getLastVisitsStart($fetch = true);
$view->liveTokenAuth = Piwik::getCurrentUserTokenAuth();
- echo $view->render();
+ return $this->render($view, $fetch);
}
+ public function ajaxTotalVisitors($fetch = false)
+ {
+ $view = Piwik_View::factory('totalVisits');
+ $view = $this->setCounters($view);
+ $view->idSite = $this->idSite;
+ return $this->render($view, $fetch);
+ }
+
+ private function render($view, $fetch)
+ {
+ $rendered = $view->render();
+ if($fetch) {
+ return $rendered;
+ }
+ echo $rendered;
+ }
+
public function getVisitorLog($fetch = false)
{
+ // If previous=1 is set, user clicked previous
+ // we can't deal with previous so we force display of the first page
+ if(Piwik_Common::getRequestVar('previous', 0, 'int') == 1) {
+ $_GET['maxIdVisit'] = '';
+ }
+
$view = Piwik_ViewDataTable::factory();
$view->init( $this->pluginName,
__FUNCTION__,
'Live.getLastVisitsDetails'
);
- // All colomns in DB which could be shown
- //'ip', 'idVisit', 'countActions', 'isVisitorReturning', 'country', 'countryFlag', 'continent', 'provider', 'providerUrl', 'idSite',
- //'serverDate', 'visitLength', 'visitLengthPretty', 'firstActionTimestamp', 'lastActionTimestamp', 'referrerType', 'referrerName',
- //'keywords', 'referrerUrl', 'searchEngineUrl', 'searchEngineIcon', 'operatingSystem', 'operatingSystemShortName', 'operatingSystemIcon',
- //'browserFamily', 'browserFamilyDescription', 'browser', 'browserIcon', 'screen', 'resolution', 'screenIcon', 'plugins', 'lastActionDateTime',
- //'serverDatePretty', 'serverTimePretty', 'actionDetails'
$view->disableGenericFilters();
$view->disableSort();
$view->setTemplate("Live/templates/visitorLog.tpl");
@@ -55,15 +71,15 @@ class Piwik_Live_Controller extends Piwik_Controller
$view->disableSearchBox();
$view->setLimit(20);
$view->disableOffsetInformation();
- // "Include low population" link won't be displayed under this table
$view->disableExcludeLowPopulation();
+
// disable the tag cloud, pie charts, bar chart icons
$view->disableShowAllViewsIcons();
// disable the button "show more datas"
$view->disableShowAllColumns();
-
// disable the RSS feed
$view->disableShowExportAsRssFeed();
+
$view->setCustomParameter('pageUrlNotDefined', Zend_Registry::get('config')->General->action_default_url_when_not_defined);
return $this->renderView($view, $fetch);
}
@@ -73,66 +89,24 @@ class Piwik_Live_Controller extends Piwik_Controller
$view = Piwik_View::factory('lastVisits');
$view->idSite = $this->idSite;
- $api = new Piwik_API_Request("method=Live.getLastVisits&idSite=$this->idSite&limit=10&format=php&serialize=0&disable_generic_filters=1");
+ $api = new Piwik_API_Request("method=Live.getLastVisitsDetails&idSite=$this->idSite&filter_limit=10&format=php&serialize=0&disable_generic_filters=1");
$visitors = $api->process();
$view->visitors = $visitors;
- $rendered = $view->render($fetch);
-
- if($fetch)
- {
- return $rendered;
- }
- echo $rendered;
+ return $this->render($view, $fetch);
}
-
- public function getUsersInLastXMin($minutes = 30)
+
+ private function setCounters($view)
{
- $api = new Piwik_API_Request("method=Live.getUsersInLastXMin&idSite=".$this->idSite."&minutes=".$minutes."&format=php&serialize=0&disable_generic_filters=1");
- $visitors_halfhour = $api->process();
-
- return count($visitors_halfhour);
+ $last30min = Piwik_Live_API::getInstance()->getCounters($this->idSite, $lastMinutes = 30);
+ $last30min = $last30min[0];
+ $today = Piwik_Live_API::getInstance()->getCounters($this->idSite, $lastMinutes = 24*60);
+ $today = $today[0];
+ $view->visitorsCountHalfHour = $last30min['visits'];
+ $view->visitorsCountToday = $today['visits'];
+ $view->pisHalfhour = $last30min['actions'];
+ $view->pisToday = $today['actions'];
+ return $view;
}
- public function getUsersInLastXDays($days = 1)
- {
- $api = new Piwik_API_Request("method=Live.getUsersInLastXDays&idSite=$this->idSite&days=$days&format=php&serialize=0&disable_generic_filters=1");
- $visitors_today = $api->process();
-
- return count($visitors_today);
- }
-
- public function getPageImpressionsInLastXMin($minutes = 30)
- {
- $api = new Piwik_API_Request("method=Live.getPageImpressionsInLastXMin&idSite=$this->idSite&minutes=$minutes&format=php&serialize=0&disable_generic_filters=1");
- $pis_halfhour = $api->process();
-
- return count($pis_halfhour);
- }
-
- public function getPageImpressionsInLastXDays($days = 1)
- {
- $api = new Piwik_API_Request("method=Live.getPageImpressionsInLastXDays&idSite=$this->idSite&days=$days&format=php&serialize=0&disable_generic_filters=1");
- $pis_today = $api->process();
-
- return count($pis_today);
- }
-
- public function ajaxTotalVisitors($fetch = false)
- {
- $view = Piwik_View::factory('totalVisits');
- $view->idSite = $this->idSite;
- $view->visitorsCountHalfHour = $this->getUsersInLastXMin(30);
- $view->visitorsCountToday = $this->getUsersInLastXDays(1);
- $view->pisHalfhour = $this->getPageImpressionsInLastXMin(30);
- $view->pisToday = $this->getPageImpressionsInLastXDays(1);
-
- $rendered = $view->render($fetch);
-
- if($fetch)
- {
- return $rendered;
- }
- echo $rendered;
- }
}