Esempio n. 1
0
 /**
  * Common filters for all Actions API
  *
  * @param DataTable|DataTable\Simple|DataTable\Map $dataTable
  * @param bool $expanded
  */
 protected function filterActionsDataTable($dataTable, $expanded = false)
 {
     // Must be applied before Sort in this case, since the DataTable can contain both int and strings indexes
     // (in the transition period between pre 1.2 and post 1.2 datatable structure)
     $dataTable->filter('ReplaceColumnNames');
     $dataTable->filter('Sort', array('nb_visits', 'desc', $naturalSort = false, $expanded));
     $dataTable->queueFilter('ReplaceSummaryRowLabel');
 }
 /**
  * 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
  * @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)
 {
     $hasDimension = isset($reportMetadata['dimension']);
     $columns = $reportMetadata['metrics'];
     if ($hasDimension) {
         $columns = array_merge(array('label' => $reportMetadata['dimension']), $columns);
         if (isset($reportMetadata['processedMetrics'])) {
             $processedMetricsAdded = Metrics::getDefaultProcessedMetrics();
             foreach ($processedMetricsAdded as $processedMetricId => $processedMetricTranslation) {
                 // this processed metric can be displayed for this report
                 if (isset($reportMetadata['processedMetrics'][$processedMetricId])) {
                     $columns[$processedMetricId] = $processedMetricTranslation;
                 }
             }
         }
         // 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];
                 }
             }
         }
         if (isset($reportMetadata['processedMetrics'])) {
             // Add processed metrics
             $dataTable->filter('AddColumnsProcessedMetrics', array($deleteRowsWithNoVisit = false));
         }
     }
     $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 $label => $simpleDataTable) {
             $this->removeEmptyColumns($columns, $reportMetadata, $simpleDataTable);
             list($enhancedSimpleDataTable, $rowMetadata) = $this->handleSimpleDataTable($idSite, $simpleDataTable, $columns, $hasDimension, $showRawMetrics);
             $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);
         $totals = $this->aggregateReportTotalValues($dataTable, $totals);
     }
     return array($newReport, $columns, $rowsMetadata, $totals);
 }
 /**
  * @param DataTable|DataTable\Map $dataTable
  * @param $visualization
  */
 protected function initChartObjectData($dataTable, $visualization)
 {
     // We apply a filter to the DataTable, decoding the label column (useful for keywords for example)
     $dataTable->filter('ColumnCallbackReplace', array('label', 'urldecode'));
     $xLabels = $dataTable->getColumn('label');
     $columnNames = $this->properties['columns_to_display'];
     if (($labelColumnIndex = array_search('label', $columnNames)) !== false) {
         unset($columnNames[$labelColumnIndex]);
     }
     $columnNameToTranslation = $columnNameToValue = array();
     foreach ($columnNames as $columnName) {
         $columnNameToTranslation[$columnName] = @$this->properties['translations'][$columnName];
         $columnNameToValue[$columnName] = $dataTable->getColumn($columnName);
     }
     $visualization->dataTable = $dataTable;
     $visualization->properties = $this->properties;
     $visualization->setAxisXLabels($xLabels);
     $visualization->setAxisYValues($columnNameToValue);
     $visualization->setAxisYLabels($columnNameToTranslation);
     $units = $this->getUnitsForColumnsToDisplay();
     $visualization->setAxisYUnits($units);
 }
Esempio n. 4
0
 /**
  * Common filters for all Actions API
  *
  * @param DataTable|DataTable\Simple|DataTable\Map $dataTable
  */
 private function filterActionsDataTable($dataTable)
 {
     // Must be applied before Sort in this case, since the DataTable can contain both int and strings indexes
     // (in the transition period between pre 1.2 and post 1.2 datatable structure)
     $dataTable->filter('Piwik\\Plugins\\Actions\\DataTable\\Filter\\Actions');
     return $dataTable;
 }