Skip to content

Commit

Permalink
moved resolution and configuration reports to a new plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
sgiehl committed Dec 8, 2014
1 parent d974ea9 commit e7325c7
Show file tree
Hide file tree
Showing 30 changed files with 365 additions and 94 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ This is a changelog for Piwik platform developers. All changes for our HTTP API'
* The API method `UserSettings.getOS` is deprecated and will be removed from May 1st 2015. Use `DevicesDetection.getOsVersions` instead
* The API method `UserSettings.getMobileVsDesktop` is deprecated and will be removed from May 1st 2015. Use `DevicesDetection.getType` instead
* The API method `UserSettings.getBrowserType` is deprecated and will be removed from May 1st 2015. Use `DevicesDetection.getBrowserEngines` instead
* The API method `UserSettings.getResolution` is deprecated and will be removed from May 1st 2015. Use `Resolution.getResolution` instead
* The API method `UserSettings.getConfiguration` is deprecated and will be removed from May 1st 2015. Use `Resolution.getConfiguration` instead
* The API method `UserSettings.getWideScreen` has been removed

### Library updates
Expand Down
1 change: 1 addition & 0 deletions config/global.ini.php
Original file line number Diff line number Diff line change
Expand Up @@ -717,6 +717,7 @@
Plugins[] = Contents
Plugins[] = TestRunner
Plugins[] = BulkTracking
Plugins[] = Resolution

[PluginsInstalled]
PluginsInstalled[] = Login
Expand Down
2 changes: 1 addition & 1 deletion core/Plugin/Segment.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public function setCategory($category)

/**
* Set (overwrite) the segment display name. This name will be visible in the API and the UI. It should be a
* translation key such as 'Actions_ColumnEntryPageTitle' or 'UserSettings_ColumnResolution'.
* translation key such as 'Actions_ColumnEntryPageTitle' or 'Resolution_ColumnResolution'.
* @param string $name
* @api
*/
Expand Down
43 changes: 43 additions & 0 deletions core/Updates/2.10.0-b6.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php
/**
* Piwik - free/libre analytics platform
*
* @link http://piwik.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*
*/

namespace Piwik\Updates;

use Piwik\DataAccess\ArchiveTableCreator;
use Piwik\Updater;
use Piwik\Updates;

class Updates_2_10_0_b6 extends Updates
{

static function getSql()
{
$sqls = array();

$archiveTables = ArchiveTableCreator::getTablesArchivesInstalled();

$archiveBlobTables = array_filter($archiveTables, function($name) {
return ArchiveTableCreator::getTypeFromTableName($name) == ArchiveTableCreator::BLOB_TABLE;
});

foreach ($archiveBlobTables as $table) {

$sqls["UPDATE " . $table . " SET name = 'Resolution_resolution' WHERE name = 'UserSettings_resolution'"] = false;
$sqls["UPDATE " . $table . " SET name = 'Resolution_configuration' WHERE name = 'UserSettings_configuration'"] = false;
}

return $sqls;
}

static function update()
{
Updater::updateDatabase(__FILE__, self::getSql());
}

}
2 changes: 1 addition & 1 deletion core/Version.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ final class Version
* The current Piwik version.
* @var string
*/
const VERSION = '2.10.0-b5';
const VERSION = '2.10.0-b6';
}
2 changes: 1 addition & 1 deletion plugins/Live/templates/_dataTableViz_visitorLog.twig
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
{% endif %}
{% if visitor.getColumn('operatingSystemIcon') %}&nbsp;
<img src="{{ visitor.getColumn('operatingSystemIcon') }}"
title="{{ visitor.getColumn('operatingSystem') }}, {{ visitor.getColumn('resolution') }}"/>{% endif %}
title="{{ visitor.getColumn('operatingSystem') }}{% if visitor.getColumn('resolution') %}, {{ visitor.getColumn('resolution') }}{% endif %}"/>{% endif %}
{% if visitor.getColumn('visitorTypeIcon') %}
{% if visitor.getColumn('visitorTypeIcon') %}&nbsp;-
<img src="{{ visitor.getColumn('visitorTypeIcon') }}"
Expand Down
2 changes: 1 addition & 1 deletion plugins/Live/templates/getLastVisitsStart.twig
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
{{ visitor.serverDatePretty }} - {{ visitor.serverTimePretty }} {% if visitor.visitDuration > 0 %}<em>({{ visitor.visitDurationPretty|raw }})</em>{% endif %}
{% if visitor.countryFlag is defined %}&nbsp;<img src="{{ visitor.countryFlag }}" title="{{ visitor.location }}, {{ 'Provider_ColumnProvider'|translate }} {% if visitor.providerName is defined %}{{ visitor.providerName }}{% endif %}"/>{% endif %}
{% if visitor.browserIcon is defined %}&nbsp;<img src="{{ visitor.browserIcon }}" title="{{ visitor.browserName }}, {{ 'General_Plugins'|translate }}: {{ visitor.plugins }}"/>{% endif %}
{% if visitor.operatingSystemIcon is defined %}&nbsp;<img src="{{ visitor.operatingSystemIcon }}" title="{{ visitor.operatingSystem }}, {{ visitor.resolution }}"/>{% endif %}
{% if visitor.operatingSystemIcon is defined %}&nbsp;<img src="{{ visitor.operatingSystemIcon }}" title="{{ visitor.operatingSystem }}{% if visitor.resolution is defined %}, {{ visitor.resolution }}{% endif %}"/>{% endif %}
&nbsp;
{% if visitor.visitConverted %}
<span title="{{ 'General_VisitConvertedNGoals'|translate(visitor.goalConversions) }}" class='visitorRank'>
Expand Down
2 changes: 1 addition & 1 deletion plugins/Live/templates/getSingleVisitSummary.twig
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
{% if visitData.operatingSystemIcon is defined %}<img src="{{ visitData.operatingSystemIcon }}"/>{% endif %}{% if visitData.operatingSystem is defined %}<span>{{ visitData.operatingSystem }}</span>{% endif %}
</div>
</li>
{% if visitData.resolution is defined %}<li><span>{{ 'UserSettings_ColumnResolution'|translate }}</span><strong>{{ visitData.resolution }}</strong></li>{% endif %}
{% if visitData.resolution is defined %}<li><span>{{ 'Resolution_ColumnResolution'|translate }}</span><strong>{{ visitData.resolution }}</strong></li>{% endif %}
{% if visitData.userId is not empty %}<li><span>{{ 'General_UserId'|translate }}</span><strong>{{ visitData.userId|raw }}</strong></li>{% endif %}
{% if visitReferralSummary is defined %}
{%- set keywordNotDefined = 'General_NotDefined'|translate('General_ColumnKeyword'|translate) -%}
Expand Down
49 changes: 49 additions & 0 deletions plugins/Resolution/API.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php
/**
* Piwik - free/libre analytics platform
*
* @link http://piwik.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*
*/
namespace Piwik\Plugins\Resolution;

use Piwik\Archive;
use Piwik\DataTable;
use Piwik\Metrics;
use Piwik\Piwik;

/**
* @see plugins/Resolution/functions.php
*/
require_once PIWIK_INCLUDE_PATH . '/plugins/Resolution/functions.php';

/**
* @method static \Piwik\Plugins\Resolution\API getInstance()
*/
class API extends \Piwik\Plugin\API
{
protected function getDataTable($name, $idSite, $period, $date, $segment)
{
Piwik::checkUserHasViewAccess($idSite);
$archive = Archive::build($idSite, $period, $date, $segment);
$dataTable = $archive->getDataTable($name);
$dataTable->filter('Sort', array(Metrics::INDEX_NB_VISITS));
$dataTable->queueFilter('ReplaceColumnNames');
$dataTable->queueFilter('ReplaceSummaryRowLabel');
return $dataTable;
}

public function getResolution($idSite, $period, $date, $segment = false)
{
$dataTable = $this->getDataTable(Archiver::RESOLUTION_RECORD_NAME, $idSite, $period, $date, $segment);
return $dataTable;
}

public function getConfiguration($idSite, $period, $date, $segment = false)
{
$dataTable = $this->getDataTable(Archiver::CONFIGURATION_RECORD_NAME, $idSite, $period, $date, $segment);
$dataTable->queueFilter('ColumnCallbackReplace', array('label', __NAMESPACE__ . '\getConfigurationLabel'));
return $dataTable;
}
}
68 changes: 68 additions & 0 deletions plugins/Resolution/Archiver.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?php
/**
* Piwik - free/libre analytics platform
*
* @link http://piwik.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*
*/

namespace Piwik\Plugins\Resolution;

use Piwik\DataTable;
use Piwik\Metrics;

/**
* Archiver for Resolution Plugin
*
* @see PluginsArchiver
*/
class Archiver extends \Piwik\Plugin\Archiver
{
const RESOLUTION_RECORD_NAME = 'Resolution_resolution';
const CONFIGURATION_RECORD_NAME = 'Resolution_configuration';
const RESOLUTION_DIMENSION = "log_visit.config_resolution";
const CONFIGURATION_DIMENSION = "CONCAT(log_visit.config_os, ';', log_visit.config_browser_name, ';', log_visit.config_resolution)";

public function aggregateDayReport()
{
$this->aggregateByResolution();
$this->aggregateByConfiguration();
}

/**
* Period archiving: simply sums up daily archives
*/
public function aggregateMultipleReports()
{
$dataTableRecords = array(
self::RESOLUTION_RECORD_NAME,
self::CONFIGURATION_RECORD_NAME,
);
$this->getProcessor()->aggregateDataTableRecords($dataTableRecords, $this->maximumRows);
}

protected function aggregateByConfiguration()
{
$metrics = $this->getLogAggregator()->getMetricsFromVisitByDimension(self::CONFIGURATION_DIMENSION)->asDataTable();
$this->insertTable(self::CONFIGURATION_RECORD_NAME, $metrics);
}

protected function aggregateByResolution()
{
$table = $this->getLogAggregator()->getMetricsFromVisitByDimension(self::RESOLUTION_DIMENSION)->asDataTable();
$table->filter('ColumnCallbackDeleteRow', array('label', function ($value) {
return strlen($value) <= 5;
}));
$this->insertTable(self::RESOLUTION_RECORD_NAME, $table);
return $table;
}

protected function insertTable($recordName, DataTable $table)
{
$report = $table->getSerialized($this->maximumRows, null, Metrics::INDEX_NB_VISITS);
return $this->getProcessor()->insertBlobRecord($recordName, $report);
}

}

Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*
*/
namespace Piwik\Plugins\UserSettings\Columns;
namespace Piwik\Plugins\Resolution\Columns;

use Piwik\Columns\Dimension;
use Piwik\Piwik;
Expand All @@ -15,6 +15,6 @@ class Configuration extends Dimension
{
public function getName()
{
return Piwik::translate('UserSettings_ColumnConfiguration');
return Piwik::translate('Resolution_ColumnConfiguration');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*
*/
namespace Piwik\Plugins\UserSettings\Columns;
namespace Piwik\Plugins\Resolution\Columns;

use Piwik\Piwik;
use Piwik\Plugin\Dimension\VisitDimension;
use Piwik\Plugins\UserSettings\Segment;
use Piwik\Plugins\Resolution\Segment;
use Piwik\Tracker\Action;
use Piwik\Tracker\Request;
use Piwik\Tracker\Visitor;
Expand All @@ -24,7 +24,7 @@ protected function configureSegments()
{
$segment = new Segment();
$segment->setSegment('resolution');
$segment->setName('UserSettings_ColumnResolution');
$segment->setName('Resolution_ColumnResolution');
$segment->setAcceptedValues('1280x1024, 800x600, etc.');
$this->addSegment($segment);
}
Expand All @@ -48,6 +48,6 @@ public function onNewVisit(Request $request, Visitor $visitor, $action)

public function getName()
{
return Piwik::translate('UserSettings_ColumnResolution');
return Piwik::translate('Resolution_ColumnResolution');
}
}
32 changes: 32 additions & 0 deletions plugins/Resolution/Reports/Base.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php
/**
* Piwik - free/libre analytics platform
*
* @link http://piwik.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*
*/
namespace Piwik\Plugins\Resolution\Reports;

use Piwik\Plugin\ViewDataTable;
use Piwik\Plugins\CoreVisualizations\Visualizations\Graph;

abstract class Base extends \Piwik\Plugin\Report
{
protected function init()
{
$this->category = 'UserSettings_VisitorSettings';
}

protected function getBasicResolutionDisplayProperties(ViewDataTable $view)
{
$view->config->show_search = false;
$view->config->show_exclude_low_population = false;

$view->requestConfig->filter_limit = 5;

if ($view->isViewDataTableId(Graph::ID)) {
$view->config->max_graph_elements = 5;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,27 @@
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*
*/
namespace Piwik\Plugins\UserSettings\Reports;
namespace Piwik\Plugins\Resolution\Reports;

use Piwik\Piwik;
use Piwik\Plugin\ViewDataTable;
use Piwik\Plugins\UserSettings\Columns\Configuration;
use Piwik\Plugins\Resolution\Columns\Configuration;

class GetConfiguration extends Base
{
protected function init()
{
parent::init();
$this->dimension = new Configuration();
$this->name = Piwik::translate('UserSettings_WidgetGlobalVisitors');
$this->documentation = Piwik::translate('UserSettings_WidgetGlobalVisitorsDocumentation', '<br />');
$this->name = Piwik::translate('Resolution_WidgetGlobalVisitors');
$this->documentation = Piwik::translate('Resolution_WidgetGlobalVisitorsDocumentation', '<br />');
$this->order = 7;
$this->widgetTitle = 'UserSettings_WidgetGlobalVisitors';
$this->widgetTitle = 'Resolution_WidgetGlobalVisitors';
}

public function configureView(ViewDataTable $view)
{
$this->getBasicUserSettingsDisplayProperties($view);
$this->getBasicResolutionDisplayProperties($view);

$view->config->addTranslation('label', $this->dimension->getName());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,27 @@
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*
*/
namespace Piwik\Plugins\UserSettings\Reports;
namespace Piwik\Plugins\Resolution\Reports;

use Piwik\Piwik;
use Piwik\Plugin\ViewDataTable;
use Piwik\Plugins\UserSettings\Columns\Resolution;
use Piwik\Plugins\Resolution\Columns\Resolution;

class GetResolution extends Base
{
protected function init()
{
parent::init();
$this->dimension = new Resolution();
$this->name = Piwik::translate('UserSettings_WidgetResolutions');
$this->name = Piwik::translate('Resolution_WidgetResolutions');
$this->documentation = ''; // TODO
$this->order = 0;
$this->widgetTitle = 'UserSettings_WidgetResolutions';
$this->widgetTitle = 'Resolution_WidgetResolutions';
}

public function configureView(ViewDataTable $view)
{
$this->getBasicUserSettingsDisplayProperties($view);
$this->getBasicResolutionDisplayProperties($view);

$view->config->addTranslation('label', $this->dimension->getName());
}
Expand Down
Loading

0 comments on commit e7325c7

Please sign in to comment.