Piwik\Archive\DataTableFactory::makeMerged PHP Метод

makeMerged() публичный Метод

Whereas {@link make()} creates a Map for each result index (period and|or site), this will only create a Map for a period result index and move all site related indices into one dataTable. This is the same as doing $dataTableFactory->make()->mergeChildren() just much faster. It is mainly useful for reports across many sites eg MultiSites.getAll. Was done as part of https://github.com/piwik/piwik/issues/6809
public makeMerged ( array $index, array $resultIndices ) : DataTable | Piwik\DataTable\Map
$index array @see DataCollection
$resultIndices array an array mapping metadata names with pretty metadata labels.
Результат Piwik\DataTable | Piwik\DataTable\Map
    public function makeMerged($index, $resultIndices)
    {
        if (!$this->isNumericDataType()) {
            throw new \Exception('This method is supposed to work with non-numeric data types but it is not tested. To use it, remove this exception and write tests to be sure it works.');
        }
        $hasSiteIndex = isset($resultIndices[self::TABLE_METADATA_SITE_INDEX]);
        $hasPeriodIndex = isset($resultIndices[self::TABLE_METADATA_PERIOD_INDEX]);
        $isNumeric = $this->isNumericDataType();
        // to be backwards compatible use a Simple table if needed as it will be formatted differently
        $useSimpleDataTable = !$hasSiteIndex && $isNumeric;
        if (!$hasSiteIndex) {
            $firstIdSite = reset($this->sitesId);
            $index = array($firstIdSite => $index);
        }
        if ($hasPeriodIndex) {
            $dataTable = $this->makeMergedTableWithPeriodAndSiteIndex($index, $resultIndices, $useSimpleDataTable, $isNumeric);
        } else {
            $dataTable = $this->makeMergedWithSiteIndex($index, $useSimpleDataTable, $isNumeric);
        }
        return $dataTable;
    }

Usage Example

 /**
  * @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());
 }
All Usage Examples Of Piwik\Archive\DataTableFactory::makeMerged