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:
authorsgiehl <stefan@piwik.org>2014-10-17 00:30:14 +0400
committersgiehl <stefan@piwik.org>2014-10-24 00:07:17 +0400
commite80331983a86c63577d49cea1e117915c2f9ffd8 (patch)
treee29df3b918fe51e7512fb72911c87260e3b6ba39 /plugins/DevicesDetection
parentf9ba2531a886548bc7db8666e4a408283bc293bd (diff)
ensure device type report always contain all device types
Diffstat (limited to 'plugins/DevicesDetection')
-rw-r--r--plugins/DevicesDetection/API.php26
1 files changed, 26 insertions, 0 deletions
diff --git a/plugins/DevicesDetection/API.php b/plugins/DevicesDetection/API.php
index 79369084ec..84141ebd27 100644
--- a/plugins/DevicesDetection/API.php
+++ b/plugins/DevicesDetection/API.php
@@ -9,6 +9,7 @@
namespace Piwik\Plugins\DevicesDetection;
+use DeviceDetector\Parser\Device\DeviceParserAbstract;
use Piwik\Archive;
use Piwik\DataTable;
use Piwik\Metrics;
@@ -50,11 +51,36 @@ class API extends \Piwik\Plugin\API
public function getType($idSite, $period, $date, $segment = false)
{
$dataTable = $this->getDataTable('DevicesDetection_types', $idSite, $period, $date, $segment);
+ // ensure all device types are in the list
+ $this->ensureDefaultRowsInTable($dataTable);
$dataTable->filter('ColumnCallbackAddMetadata', array('label', 'logo', __NAMESPACE__ . '\getDeviceTypeLogo'));
$dataTable->filter('ColumnCallbackReplace', array('label', __NAMESPACE__ . '\getDeviceTypeLabel'));
return $dataTable;
}
+ protected function ensureDefaultRowsInTable($dataTable)
+ {
+ $requiredRows = array_fill(0, count(DeviceParserAbstract::getAvailableDeviceTypes()), Metrics::INDEX_NB_VISITS);
+
+ $dataTables = array($dataTable);
+
+ if (!($dataTable instanceof DataTable\Map)) {
+ foreach ($dataTables as $table) {
+ if ($table->getRowsCount() == 0) {
+ continue;
+ }
+ foreach ($requiredRows as $requiredRow => $key) {
+ $row = $table->getRowFromLabel($requiredRow);
+ if (empty($row)) {
+ $table->addRowsFromSimpleArray(array(
+ array('label' => $requiredRow, $key => 0)
+ ));
+ }
+ }
+ }
+ }
+ }
+
/**
* Gets datatable displaying number of visits by device manufacturer name
* @param int $idSite