| Server IP : 213.186.33.4 / Your IP : 216.73.216.193 Web Server : Apache System : Linux webm006.cluster103.gra.hosting.ovh.net 5.15.206-ovh-vps-grsec-zfs-classid #1 SMP Fri May 15 02:41:25 UTC 2026 x86_64 User : awebpaca ( 35430) PHP Version : 8.5.0 Disable Function : _dyuweyrj4,_dyuweyrj4r,dl MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : OFF | Pkexec : OFF Directory : /home/awebpaca/piwik/plugins/Insights/DataTable/Filter/ |
Upload File : |
<?php
/**
* Matomo - free/libre analytics platform
*
* @link https://matomo.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*
*/
namespace Piwik\Plugins\Insights\DataTable\Filter;
use Piwik\DataTable;
class Insight extends DataTable\Filter\CalculateEvolutionFilter
{
private $considerMovers;
private $considerNew;
private $considerDisappeared;
private $currentDataTable;
public function __construct($table, $currentDataTable, $pastDataTable, $columnToRead,
$considerMovers, $considerNew, $considerDisappeared)
{
parent::__construct($table, $pastDataTable, 'growth', $columnToRead, $quotientPrecision = 1);
$this->currentDataTable = $currentDataTable;
$this->considerMovers = $considerMovers;
$this->considerNew = $considerNew;
$this->considerDisappeared = $considerDisappeared;
}
public function filter($table)
{
foreach ($this->currentDataTable->getRows() as $row) {
$this->addRowIfNewOrMover($table, $row);
}
if ($this->considerDisappeared) {
foreach ($this->pastDataTable->getRows() as $row) {
$this->addRowIfDisappeared($table, $row);
}
}
}
private function addRowIfDisappeared(DataTable $table, DataTable\Row $row)
{
if ($this->getRowFromTable($this->currentDataTable, $row)) {
return;
}
$newValue = 0;
$oldValue = $row->getColumn($this->columnValueToRead);
$difference = $newValue - $oldValue;
if ($oldValue == 0 && $newValue == 0) {
$growthPercentage = '0%';
} else {
$growthPercentage = '-100%';
}
$this->addRow($table, $row, $growthPercentage, $newValue, $oldValue, $difference, $isDisappeared = true);
}
private function addRowIfNewOrMover(DataTable $table, DataTable\Row $row)
{
$pastRow = $this->getPastRowFromCurrent($row);
if (!$pastRow && !$this->considerNew) {
return;
} elseif ($pastRow && !$this->considerMovers) {
return;
}
$isNew = false;
$isMover = false;
$isDisappeared = false;
if (!$pastRow) {
$isNew = true;
$oldValue = 0;
} else {
$isMover = true;
$oldValue = $pastRow->getColumn($this->columnValueToRead);
}
$difference = $this->getDividend($row);
if ($difference === false) {
return;
}
$newValue = $row->getColumn($this->columnValueToRead);
$divisor = $this->getDivisor($row);
$growthPercentage = $this->formatValue($difference, $divisor);
$this->addRow($table, $row, $growthPercentage, $newValue, $oldValue, $difference, $isDisappeared, $isNew, $isMover);
}
private function getRowFromTable(DataTable $table, DataTable\Row $row)
{
return $table->getRowFromLabel($row->getColumn('label'));
}
private function addRow(DataTable $table, DataTable\Row $row, $growthPercentage, $newValue, $oldValue, $difference, $disappeared = false, $isNew = false, $isMover = false)
{
$columns = $row->getColumns();
$columns['growth_percent'] = $growthPercentage;
$columns['growth_percent_numeric'] = str_replace('%', '', $growthPercentage);
$columns['grown'] = '-' != substr($growthPercentage, 0 , 1);
$columns['value_old'] = $oldValue;
$columns['value_new'] = $newValue;
$columns['difference'] = $difference;
$columns['importance'] = abs($difference);
$columns['isDisappeared'] = $disappeared;
$columns['isNew'] = $isNew;
$columns['isMover'] = $isMover;
$table->addRowFromArray(array(DataTable\Row::COLUMNS => $columns));
}
}