1
0
قرینه از https://github.com/matomo-org/matomo.git synced 2025-08-22 15:07:44 +00:00
Files
matomo/plugins/Goals/Columns/Metrics/AverageOrderRevenue.php
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

70 خطوط
1.6 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\Goals\Columns\Metrics;
use Piwik\Archive\DataTableFactory;
use Piwik\Columns\Dimension;
use Piwik\DataTable;
use Piwik\DataTable\Row;
use Piwik\Metrics\Formatter;
use Piwik\Piwik;
use Piwik\Plugin\ProcessedMetric;
/**
* The average value for each order. Calculated as:
*
* revenue / nb_conversions
*
* revenue & nb_conversions are calculated by the Goals archiver.
*/
class AverageOrderRevenue extends ProcessedMetric
{
private $idSite;
public function getName()
{
return 'avg_order_revenue';
}
public function compute(Row $row)
{
$revenue = $this->getMetric($row, 'revenue');
$conversions = $this->getMetric($row, 'nb_conversions');
return Piwik::getQuotientSafe($revenue, $conversions, $precision = 2);
}
public function getTranslatedName()
{
return Piwik::translate('General_AverageOrderValue');
}
public function getDependentMetrics()
{
return array('revenue', 'nb_conversions');
}
public function format($value, Formatter $formatter)
{
return $formatter->getPrettyMoney($value, $this->idSite);
}
public function beforeFormat($report, DataTable $table)
{
$this->idSite = DataTableFactory::getSiteIdFromMetadata($table);
return !empty($this->idSite); // skip formatting if there is no site to get currency info from
}
public function getSemanticType(): ?string
{
return Dimension::TYPE_MONEY;
}
}