本文整理汇总了PHP中Piwik\DataTable\Map类的典型用法代码示例。如果您正苦于以下问题:PHP Map类的具体用法?PHP Map怎么用?PHP Map使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Map类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: mergeDataTables
/**
* Merge the columns of two data tables.
* Manipulates the first table.
*
* @param DataTable|DataTable\Map $table1 The table to eventually filter.
* @param DataTable|DataTable\Map $table2 Whether to delete rows with no visits or not.
*/
public function mergeDataTables($table1, $table2)
{
// handle table arrays
if ($table1 instanceof DataTable\Map && $table2 instanceof DataTable\Map) {
$subTables2 = $table2->getDataTables();
foreach ($table1->getDataTables() as $index => $subTable1) {
if (!array_key_exists($index, $subTables2)) {
// occurs when archiving starts on dayN and continues into dayN+1, see https://github.com/piwik/piwik/issues/5168#issuecomment-50959925
continue;
}
$subTable2 = $subTables2[$index];
$this->mergeDataTables($subTable1, $subTable2);
}
return;
}
$firstRow2 = $table2->getFirstRow();
if (!$firstRow2 instanceof Row) {
return;
}
$firstRow1 = $table1->getFirstRow();
if (empty($firstRow1)) {
$firstRow1 = $table1->addRow(new Row());
}
foreach ($firstRow2->getColumns() as $metric => $value) {
$firstRow1->setColumn($metric, $value);
}
}
示例2: createInstanceWithDataTableMaps
private function createInstanceWithDataTableMaps()
{
$dataTable = new DataTable\Map();
$subDataTableMap1 = $this->createInstanceWithDataTables();
$dataTable->addTable($subDataTableMap1, 'subArray1');
$subDataTableMap2 = $this->createInstanceWithDataTables();
$dataTable->addTable($subDataTableMap2, 'subArray2');
return $dataTable;
}
示例3: manipulateDataTableMap
/**
* Manipulates child DataTables of a DataTable\Map. See @manipulate for more info.
*
* @param DataTable\Map $dataTable
* @return DataTable\Map
*/
protected function manipulateDataTableMap($dataTable)
{
$result = $dataTable->getEmptyClone();
foreach ($dataTable->getDataTables() as $tableLabel => $childTable) {
$newTable = $this->manipulate($childTable);
$result->addTable($newTable, $tableLabel);
}
return $result;
}
示例4: renderDataTableMap
/**
* Computes the output of the given array of data tables
*
* @param DataTable\Map $map data tables to render
* @param string $prefix prefix to output before table data
* @return string
*/
protected function renderDataTableMap(DataTable\Map $map, $prefix)
{
$output = "Set<hr />";
$prefix = $prefix . ' ';
foreach ($map->getDataTables() as $descTable => $table) {
$output .= $prefix . "<b>" . $descTable . "</b><br />";
$output .= $prefix . $this->renderTable($table, $prefix . ' ');
$output .= "<hr />";
}
return $output;
}
示例5: getSeriesData
private function getSeriesData($rowLabel, $columnName, DataTable\Map $dataTable)
{
$seriesData = array();
foreach ($dataTable->getDataTables() as $childTable) {
// get the row for this label (use the first if $rowLabel is false)
if ($rowLabel === false) {
$row = $childTable->getFirstRow();
} else {
$row = $childTable->getRowFromLabel($rowLabel);
}
// get series data point. defaults to 0 if no row or no column value.
if ($row === false) {
$seriesData[] = 0;
} else {
$seriesData[] = $row->getColumn($columnName) ?: 0;
}
}
return $seriesData;
}
示例6: getValuesFromDataTableMap
/**
* @param DataTable\Map $dataTableMap
* @param string $columnToPlot
*
* @return array
* @throws \Exception
*/
protected function getValuesFromDataTableMap($dataTableMap, $columnToPlot)
{
$dataTableMap->applyQueuedFilters();
$values = array();
foreach ($dataTableMap->getDataTables() as $table) {
if ($table->getRowsCount() > 1) {
throw new Exception("Expecting only one row per DataTable");
}
$value = 0;
$onlyRow = $table->getFirstRow();
if (false !== $onlyRow) {
if (!empty($columnToPlot)) {
$value = $onlyRow->getColumn($columnToPlot);
} else {
$columns = $onlyRow->getColumns();
$value = current($columns);
}
}
$values[] = $value;
}
return $values;
}
示例7: test_renderDataTable_shouldRenderDataTableMaps
public function test_renderDataTable_shouldRenderDataTableMaps()
{
$map = new DataTable\Map();
$dataTable = new DataTable();
$dataTable->addRowFromSimpleArray(array('nb_visits' => 5, 'nb_random' => 10));
$dataTable2 = new DataTable();
$dataTable2->addRowFromSimpleArray(array('nb_visits' => 3, 'nb_random' => 6));
$map->addTable($dataTable, 'table1');
$map->addTable($dataTable2, 'table2');
$response = $this->builder->renderDataTable($map);
$expected = array('table1' => array(array('nb_visits' => 5, 'nb_random' => 10)), 'table2' => array(array('nb_visits' => 3, 'nb_random' => 6)));
$this->assertEquals($expected, $response);
}
示例8: handleTableReport
/**
* 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);
}
示例9: createDataTableMapFromIndex
/**
* Creates a Set from an array index.
*
* @param array $index @see DataCollection
* @param array $resultIndices @see make
* @param array $keyMetadata The metadata to add to the table when it's created.
* @return DataTable\Map
*/
private function createDataTableMapFromIndex($index, $resultIndices, $keyMetadata = array())
{
$resultIndexLabel = reset($resultIndices);
$resultIndex = key($resultIndices);
array_shift($resultIndices);
$result = new DataTable\Map();
$result->setKeyName($resultIndexLabel);
foreach ($index as $label => $value) {
$keyMetadata[$resultIndex] = $label;
if (empty($resultIndices)) {
$newTable = $this->createDataTable($value, $keyMetadata);
} else {
$newTable = $this->createDataTableMapFromIndex($value, $resultIndices, $keyMetadata);
}
$result->addTable($newTable, $this->prettifyIndexLabel($resultIndex, $label));
}
return $result;
}
示例10: test_renderDataTable_shouldRenderDataTableMaps
public function test_renderDataTable_shouldRenderDataTableMaps()
{
$map = new DataTable\Map();
$dataTable = new DataTable();
$dataTable->addRowFromSimpleArray(array('nb_visits' => 5, 'nb_random' => 10));
$dataTable2 = new DataTable();
$dataTable2->addRowFromSimpleArray(array('nb_visits' => 3, 'nb_random' => 6));
$map->addTable($dataTable, 'table1');
$map->addTable($dataTable2, 'table2');
$response = $this->builder->renderDataTable($map);
$this->assertEquals('<table id="MultiSites_getAll" border="1">
<thead>
<tr>
<th>_defaultKeyName</th>
<th>nb_visits</th>
<th>nb_random</th>
</tr>
</thead>
<tbody>
<tr>
<td>table1</td>
<td>5</td>
<td>10</td>
</tr>
<tr>
<td>table2</td>
<td>3</td>
<td>6</td>
</tr>
</tbody>
</table>
', $response);
}
示例11: test_renderDataTable_shouldRenderDataTableMaps
public function test_renderDataTable_shouldRenderDataTableMaps()
{
$map = new DataTable\Map();
$dataTable = new DataTable();
$dataTable->addRowFromSimpleArray(array('nb_visits' => 5, 'nb_random' => 10));
$dataTable2 = new DataTable();
$dataTable2->addRowFromSimpleArray(array('nb_visits' => 3, 'nb_random' => 6));
$map->addTable($dataTable, 'table1');
$map->addTable($dataTable2, 'table2');
$response = $this->builder->renderDataTable($map);
$this->assertEquals('<?xml version="1.0" encoding="utf-8" ?>
<results>
<result defaultKeyName="table1">
<row>
<nb_visits>5</nb_visits>
<nb_random>10</nb_random>
</row>
</result>
<result defaultKeyName="table2">
<row>
<nb_visits>3</nb_visits>
<nb_random>6</nb_random>
</row>
</result>
</results>', $response);
}
示例12: manipulateDataTable
/**
* Filter a DataTable instance. See @filter for more info.
*
* @param DataTable\Simple|DataTable\Map $dataTable
* @return mixed
*/
protected function manipulateDataTable($dataTable)
{
$result = $dataTable->getEmptyClone();
foreach ($this->labels as $labelIndex => $label) {
$row = null;
foreach ($this->getLabelVariations($label) as $labelVariation) {
$labelVariation = explode(self::SEPARATOR_RECURSIVE_LABEL, $labelVariation);
$row = $this->doFilterRecursiveDescend($labelVariation, $dataTable);
if ($row) {
if ($this->addLabelIndex) {
$row->setMetadata(self::FLAG_IS_ROW_EVOLUTION, $labelIndex);
}
$result->addRow($row);
break;
}
}
}
return $result;
}
示例13: filterActionsDataTable
/**
* 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');
}
示例14: addMissingWebsites
/**
* @param DataTable|DataTable\Map $dataTable
* @param $fieldsToGet
* @param $sitesToProblablyAdd
*/
private function addMissingWebsites($dataTable, $fieldsToGet, $sitesToProblablyAdd)
{
$siteIdsInDataTable = array();
foreach ($dataTable->getRows() as $row) {
/** @var DataTable\Row $row */
$siteIdsInDataTable[] = $row->getColumn('label');
}
foreach ($sitesToProblablyAdd as $site) {
if (!in_array($site['idsite'], $siteIdsInDataTable)) {
$siteRow = array_combine($fieldsToGet, array_pad(array(), count($fieldsToGet), 0));
$siteRow['label'] = (int) $site['idsite'];
$dataTable->addRowFromSimpleArray($siteRow);
}
}
}
示例15: makeMergedTableWithPeriodAndSiteIndex
private function makeMergedTableWithPeriodAndSiteIndex($index, $resultIndices, $useSimpleDataTable, $isNumeric)
{
$map = new DataTable\Map();
$map->setKeyName($resultIndices[self::TABLE_METADATA_PERIOD_INDEX]);
// we save all tables of the map in this array to be able to add rows fast
$tables = array();
foreach ($this->periods as $range => $period) {
// as the resulting table is "merged", we do only set Period metedata and no metadata for site. Instead each
// row will have an idsite metadata entry.
$metadata = array(self::TABLE_METADATA_PERIOD_INDEX => $period);
if ($useSimpleDataTable) {
$table = new DataTable\Simple();
} else {
$table = new DataTable();
}
$table->setAllTableMetadata($metadata);
$map->addTable($table, $this->prettifyIndexLabel(self::TABLE_METADATA_PERIOD_INDEX, $range));
$tables[$range] = $table;
}
foreach ($index as $idsite => $table) {
$rowMeta = array('idsite' => $idsite);
foreach ($table as $range => $row) {
if (!empty($row)) {
$tables[$range]->addRow(new Row(array(Row::COLUMNS => $row, Row::METADATA => $rowMeta)));
} elseif ($isNumeric) {
$tables[$range]->addRow(new Row(array(Row::COLUMNS => $this->defaultRow, Row::METADATA => $rowMeta)));
}
}
}
return $map;
}