Exemplo n.º 1
0
 public function test_getProcessedMetrics_reportShouldUseDefaultProcessedMetrics()
 {
     $this->assertEquals(Metrics::getDefaultProcessedMetrics(), $this->basicReport->getProcessedMetrics());
 }
Exemplo n.º 2
0
 /**
  * Constructor.
  */
 public function __construct()
 {
     $this->export_limit = \Piwik\Config::getInstance()->General['API_datatable_default_limit'];
     $this->translations = array_merge(Metrics::getDefaultMetrics(), Metrics::getDefaultProcessedMetrics());
 }
Exemplo n.º 3
0
 /**
  * Enhance a $dataTable using metadata :
  *
  * - remove metrics based on $reportMetadata['metrics']
  * - add 0 valued metrics if $dataTable doesn't provide all $reportMetadata['metrics']
  * - format metric values to a 'human readable' format
  * - extract row metadata to a separate Simple|Set : $rowsMetadata
  * - translate metric names to a separate array : $columns
  *
  * @param int $idSite enables monetary value formatting based on site currency
  * @param \Piwik\DataTable\Map|\Piwik\DataTable\Simple $dataTable
  * @param array $reportMetadata
  * @param bool $showRawMetrics
  * @param bool|null $formatMetrics
  * @return array Simple|Set $newReport with human readable format & array $columns list of translated column names & Simple|Set $rowsMetadata
  */
 private function handleTableReport($idSite, $dataTable, &$reportMetadata, $showRawMetrics = false, $formatMetrics = null)
 {
     $hasDimension = isset($reportMetadata['dimension']);
     $columns = @$reportMetadata['metrics'] ?: array();
     if ($hasDimension) {
         $columns = array_merge(array('label' => $reportMetadata['dimension']), $columns);
     }
     if (isset($reportMetadata['processedMetrics']) && is_array($reportMetadata['processedMetrics'])) {
         $processedMetricsAdded = Metrics::getDefaultProcessedMetrics();
         foreach ($reportMetadata['processedMetrics'] as $processedMetricId => $processedMetricTranslation) {
             // this processed metric can be displayed for this report
             if ($processedMetricTranslation && $processedMetricId !== $processedMetricTranslation) {
                 $columns[$processedMetricId] = $processedMetricTranslation;
             } elseif (isset($processedMetricsAdded[$processedMetricId])) {
                 // for instance in case 'nb_visits' => 'nb_visits' we will translate it
                 $columns[$processedMetricId] = $processedMetricsAdded[$processedMetricId];
             }
         }
     }
     // Display the global Goal metrics
     if (isset($reportMetadata['metricsGoal'])) {
         $metricsGoalDisplay = array('revenue');
         // Add processed metrics to be displayed for this report
         foreach ($metricsGoalDisplay as $goalMetricId) {
             if (isset($reportMetadata['metricsGoal'][$goalMetricId])) {
                 $columns[$goalMetricId] = $reportMetadata['metricsGoal'][$goalMetricId];
             }
         }
     }
     $columns = $this->hideShowMetrics($columns);
     $totals = array();
     // $dataTable is an instance of Set when multiple periods requested
     if ($dataTable instanceof DataTable\Map) {
         // Need a new Set to store the 'human readable' values
         $newReport = new DataTable\Map();
         $newReport->setKeyName("prettyDate");
         // Need a new Set to store report metadata
         $rowsMetadata = new DataTable\Map();
         $rowsMetadata->setKeyName("prettyDate");
         // Process each Simple entry
         foreach ($dataTable->getDataTables() as $simpleDataTable) {
             $this->removeEmptyColumns($columns, $reportMetadata, $simpleDataTable);
             list($enhancedSimpleDataTable, $rowMetadata) = $this->handleSimpleDataTable($idSite, $simpleDataTable, $columns, $hasDimension, $showRawMetrics, $formatMetrics);
             $enhancedSimpleDataTable->setAllTableMetadata($simpleDataTable->getAllTableMetadata());
             $period = $simpleDataTable->getMetadata(DataTableFactory::TABLE_METADATA_PERIOD_INDEX)->getLocalizedLongString();
             $newReport->addTable($enhancedSimpleDataTable, $period);
             $rowsMetadata->addTable($rowMetadata, $period);
             $totals = $this->aggregateReportTotalValues($simpleDataTable, $totals);
         }
     } else {
         $this->removeEmptyColumns($columns, $reportMetadata, $dataTable);
         list($newReport, $rowsMetadata) = $this->handleSimpleDataTable($idSite, $dataTable, $columns, $hasDimension, $showRawMetrics, $formatMetrics);
         $totals = $this->aggregateReportTotalValues($dataTable, $totals);
     }
     return array($newReport, $columns, $rowsMetadata, $totals);
 }
Exemplo n.º 4
0
 /**
  * Constructor.
  */
 public function __construct()
 {
     $this->export_limit = \Piwik\Config::getInstance()->General['API_datatable_default_limit'];
     $this->translations = array_merge(Metrics::getDefaultMetrics(), Metrics::getDefaultProcessedMetrics());
     $this->show_title = (bool) Common::getRequestVar('showtitle', 0, 'int');
 }