本文整理汇总了PHP中Piwik\DataTable\Map::setKeyName方法的典型用法代码示例。如果您正苦于以下问题:PHP Map::setKeyName方法的具体用法?PHP Map::setKeyName怎么用?PHP Map::setKeyName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Piwik\DataTable\Map
的用法示例。
在下文中一共展示了Map::setKeyName方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: test_renderDataTable_shouldRenderDataTableMaps_IfKeynameIsDate
public function test_renderDataTable_shouldRenderDataTableMaps_IfKeynameIsDate()
{
$map = new DataTable\Map();
$map->setKeyName('date');
$_GET['period'] = 'day';
$response = $this->builder->renderDataTable($map);
unset($_GET['period']);
$response = preg_replace(array('/<pubDate>(.*)<\\/pubDate>/', '/<lastBuildDate>(.*)<\\/lastBuildDate>/'), '', $response);
$this->assertEquals('<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
<channel>
<title>piwik statistics - RSS</title>
<link>http://piwik.org</link>
<description>Piwik RSS feed</description>
<generator>piwik</generator>
<language>en</language>
</channel>
</rss>', $response);
}
示例2: _getDataTableMap_containsDataTableMap_simpleOneRow
protected function _getDataTableMap_containsDataTableMap_simpleOneRow()
{
$table = new DataTable\Map();
$table->setKeyName('parentArrayKey');
$table->addTable($this->_getDataTableSimpleOneRowMapTest(), 'idSite');
return $table;
}
示例3: 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);
}
示例4: 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;
}
示例5: getEmptyClone
/**
* Returns a new DataTable\Map w/o any child DataTables, but with
* the same key name as this instance.
*
* @return Map
*/
public function getEmptyClone()
{
$dataTableMap = new Map();
$dataTableMap->setKeyName($this->getKeyName());
return $dataTableMap;
}
示例6: 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;
}