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 }
/** * Returns archive data as a DataTable indexed by metadata. Indexed data will * be represented by Map instances. Each DataTable will have * its subtable IDs set. * * This function will only work if blob data was loaded and only one record * was loaded (not including subtables of the record). * * @param array $resultIndices An array mapping metadata names to pretty labels * for them. Each archive data row will be indexed * by the metadata specified here. * * Eg, array('site' => 'idSite', 'period' => 'Date') * @param int|null $idSubTable The subtable to return. * @param int|null $depth max depth for subtables. * @param bool $addMetadataSubTableId Whether to add the DB subtable ID as metadata * to each datatable, or not. * @throws Exception * @return DataTable|DataTable\Map */ public function getExpandedDataTable($resultIndices, $idSubTable = null, $depth = null, $addMetadataSubTableId = false) { if ($this->dataType != 'blob') { throw new Exception("DataCollection: cannot call getExpandedDataTable with " . "{$this->dataType} data types. Only works with blob data."); } if (count($this->dataNames) !== 1) { throw new Exception("DataCollection: cannot call getExpandedDataTable with " . "more than one record."); } $dataTableFactory = new DataTableFactory($this->dataNames, 'blob', $this->sitesId, $this->periods, $this->defaultRow); $dataTableFactory->expandDataTable($depth, $addMetadataSubTableId); $dataTableFactory->useSubtable($idSubTable); $index = $this->getIndexedArray($resultIndices); return $dataTableFactory->make($index, $resultIndices); }
/** * Adds the processed metrics. See {@link AddColumnsProcessedMetrics} for * more information. * * @param DataTable $table */ public function filter($table) { // Add standard processed metrics parent::filter($table); $goals = $this->getGoalsInTable($table); if (!empty($this->goalsToProcess)) { $goals = array_unique(array_merge($goals, $this->goalsToProcess)); sort($goals); } $idSite = DataTableFactory::getSiteIdFromMetadata($table); $extraProcessedMetrics = $table->getMetadata(DataTable::EXTRA_PROCESSED_METRICS_METADATA_NAME); $extraProcessedMetrics[] = new RevenuePerVisit(); if ($this->processOnlyIdGoal != self::GOALS_MINIMAL_REPORT) { foreach ($goals as $idGoal) { if (($this->processOnlyIdGoal > self::GOALS_FULL_TABLE || $this->isEcommerce) && $this->processOnlyIdGoal != $idGoal) { continue; } $extraProcessedMetrics[] = new ConversionRate($idSite, $idGoal); // PerGoal\ConversionRate // When the table is displayed by clicking on the flag icon, we only display the columns // Visits, Conversions, Per goal conversion rate, Revenue if ($this->processOnlyIdGoal == self::GOALS_OVERVIEW) { continue; } $extraProcessedMetrics[] = new Conversions($idSite, $idGoal); // PerGoal\Conversions or GoalSpecific\ $extraProcessedMetrics[] = new GoalSpecificRevenuePerVisit($idSite, $idGoal); // PerGoal\Revenue $extraProcessedMetrics[] = new Revenue($idSite, $idGoal); // PerGoal\Revenue if ($this->isEcommerce) { $extraProcessedMetrics[] = new AverageOrderRevenue($idSite, $idGoal); $extraProcessedMetrics[] = new ItemsCount($idSite, $idGoal); } } } $table->setMetadata(DataTable::EXTRA_PROCESSED_METRICS_METADATA_NAME, $extraProcessedMetrics); }
/** * @expectedException \Exception * @expectedExceptionMessage supposed to work with non-numeric data types but it is not tested */ public function test_makeMerged_shouldThrowAnException_IfANonNumericDataTypeIsGiven() { $dataType = 'blob'; $dataNames = array('nb_visits'); $factory = new DataTableFactory($dataNames, $dataType, array($this->site1), $periods = array(), $this->defaultRow); $factory->makeMerged(array(), array()); }