1
0
قرینه از https://github.com/matomo-org/matomo.git synced 2025-08-22 15:07:44 +00:00
Files
Michal Kleiner 9a3ef94df6 [Coding Style] Enable rule PSR12.Files.FileHeader + unify file headers (#22132)
* [Coding Style] Enable rule PSR12.Files.FileHeader

* Apply CS

* Replace Piwik with Matomo in file headers

* Unify file headers (position, no. of lines, https links)

* Rebuild dist files

* Apply CS

* Fix system test that relies on line numbers in a file that had the file header updated

---------

Co-authored-by: Stefan Giehl <stefan@matomo.org>
2024-04-20 20:50:47 +02:00

101 خطوط
3.2 KiB
PHP

<?php
/**
* Matomo - free/libre analytics platform
*
* @link https://matomo.org
* @license https://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*/
namespace Piwik\Plugins\DevicesDetection\RecordBuilders;
use Piwik\ArchiveProcessor;
use Piwik\ArchiveProcessor\Record;
use Piwik\ArchiveProcessor\RecordBuilder;
use Piwik\Config as PiwikConfig;
use Piwik\DataTable;
use Piwik\Metrics;
abstract class Base extends RecordBuilder
{
/**
* @var string
*/
private $recordName;
/**
* @var string
*/
private $labelSql;
/**
* @var bool
*/
private $enrichWithConversionMetrics;
public function __construct(string $recordName, string $labelSql, bool $enrichWithConversionMetrics = false)
{
parent::__construct();
$this->recordName = $recordName;
$this->labelSql = $labelSql;
$this->maxRowsInTable = PiwikConfig::getInstance()->General['datatable_archiving_maximum_rows_standard'];
$this->maxRowsInSubtable = $this->maxRowsInTable;
$this->columnToSortByBeforeTruncation = Metrics::INDEX_NB_VISITS;
$this->enrichWithConversionMetrics = $enrichWithConversionMetrics;
}
public function getRecordMetadata(ArchiveProcessor $archiveProcessor): array
{
return [
Record::make(Record::TYPE_BLOB, $this->recordName),
];
}
protected function aggregate(ArchiveProcessor $archiveProcessor): array
{
$logAggregator = $archiveProcessor->getLogAggregator();
$report = new DataTable();
$query = $logAggregator->queryVisitsByDimension(['label' => $this->labelSql]);
while ($row = $query->fetch()) {
$columns = [
Metrics::INDEX_NB_UNIQ_VISITORS => $row[Metrics::INDEX_NB_UNIQ_VISITORS],
Metrics::INDEX_NB_VISITS => $row[Metrics::INDEX_NB_VISITS],
Metrics::INDEX_NB_ACTIONS => $row[Metrics::INDEX_NB_ACTIONS],
Metrics::INDEX_NB_USERS => $row[Metrics::INDEX_NB_USERS],
Metrics::INDEX_MAX_ACTIONS => $row[Metrics::INDEX_MAX_ACTIONS],
Metrics::INDEX_SUM_VISIT_LENGTH => $row[Metrics::INDEX_SUM_VISIT_LENGTH],
Metrics::INDEX_BOUNCE_COUNT => $row[Metrics::INDEX_BOUNCE_COUNT],
Metrics::INDEX_NB_VISITS_CONVERTED => $row[Metrics::INDEX_NB_VISITS_CONVERTED],
];
$report->sumRowWithLabel($row['label'] ?? '', $columns);
}
if ($this->enrichWithConversionMetrics) {
$labelSql = str_replace('log_visit.', 'log_conversion.', $this->labelSql);
$query = $logAggregator->queryConversionsByDimension(['label' => $labelSql]);
while ($conversionRow = $query->fetch()) {
$label = $conversionRow['label'] ?? '';
$idGoal = (int) $conversionRow['idgoal'];
$columns = [
Metrics::INDEX_GOALS => [
$idGoal => Metrics::makeGoalColumnsRow($idGoal, $conversionRow),
],
];
$report->sumRowWithLabel($label, $columns);
}
$report->filter(DataTable\Filter\EnrichRecordWithGoalMetricSums::class);
}
return [$this->recordName => $report];
}
}