本文整理汇总了PHP中Piwik\DataTable::getMetadata方法的典型用法代码示例。如果您正苦于以下问题:PHP DataTable::getMetadata方法的具体用法?PHP DataTable::getMetadata怎么用?PHP DataTable::getMetadata使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Piwik\DataTable
的用法示例。
在下文中一共展示了DataTable::getMetadata方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getMetricTotalValue
public function getMetricTotalValue(DataTable $currentReport, $metric)
{
$totals = $currentReport->getMetadata('totals');
if (!empty($totals[$metric])) {
$totalValue = (int) $totals[$metric];
} else {
$totalValue = 0;
}
return $totalValue;
}
示例2: sumTable
/**
* Sums a tables row with this one.
*
* @param DataTable $table
*/
private function sumTable($table)
{
$metadata = $table->getMetadata(DataTable::COLUMN_AGGREGATION_OPS_METADATA_NAME);
$enableCopyMetadata = false;
foreach ($table->getRowsWithoutSummaryRow() as $row) {
$this->sumRow($row, $enableCopyMetadata, $metadata);
}
$summaryRow = $table->getRowFromId(DataTable::ID_SUMMARY_ROW);
if ($summaryRow) {
$this->sumRow($summaryRow, $enableCopyMetadata, $metadata);
}
}
示例3: filter
/**
* See {@link ColumnCallbackAddColumn}.
*
* @param DataTable $table The table to filter.
*/
public function filter($table)
{
$columns = $this->columns;
$functionParams = $this->functionParameters;
$functionToApply = $this->functionToApply;
$extraProcessedMetrics = $table->getMetadata(DataTable::EXTRA_PROCESSED_METRICS_METADATA_NAME);
if (empty($extraProcessedMetrics)) {
$extraProcessedMetrics = array();
}
$metric = new CallableProcessedMetric($this->columnToAdd, function (DataTable\Row $row) use($columns, $functionParams, $functionToApply) {
$columnValues = array();
foreach ($columns as $column) {
$columnValues[] = $row->getColumn($column);
}
$parameters = array_merge($columnValues, $functionParams);
return call_user_func_array($functionToApply, $parameters);
}, $columns);
$extraProcessedMetrics[] = $metric;
$table->setMetadata(DataTable::EXTRA_PROCESSED_METRICS_METADATA_NAME, $extraProcessedMetrics);
foreach ($table->getRows() as $row) {
$row->setColumn($this->columnToAdd, $metric->compute($row));
$this->filterSubTable($row);
}
}
示例4: filter
/**
* See {@link GroupBy}.
*
* @param DataTable $table
*/
public function filter($table)
{
$groupByRows = array();
$nonGroupByRowIds = array();
foreach ($table->getRows() as $rowId => $row) {
// skip the summary row
if ($rowId == DataTable::ID_SUMMARY_ROW) {
continue;
}
// reduce the group by column of this row
$groupByColumnValue = $row->getColumn($this->groupByColumn);
$parameters = array_merge(array($groupByColumnValue), $this->parameters);
$groupByValue = call_user_func_array($this->reduceFunction, $parameters);
if (!isset($groupByRows[$groupByValue])) {
// if we haven't encountered this group by value before, we mark this row as a
// row to keep, and change the group by column to the reduced value.
$groupByRows[$groupByValue] = $row;
$row->setColumn($this->groupByColumn, $groupByValue);
} else {
// if we have already encountered this group by value, we add this row to the
// row that will be kept, and mark this one for deletion
$groupByRows[$groupByValue]->sumRow($row, $copyMeta = true, $table->getMetadata(DataTable::COLUMN_AGGREGATION_OPS_METADATA_NAME));
$nonGroupByRowIds[] = $rowId;
}
}
// delete the unneeded rows.
$table->deleteRows($nonGroupByRowIds);
}
示例5: createGroupSubtable
private function createGroupSubtable(DataTable $sites)
{
$table = new DataTable();
$processedMetrics = $sites->getMetadata(DataTable::EXTRA_PROCESSED_METRICS_METADATA_NAME);
$table->setMetadata(DataTable::EXTRA_PROCESSED_METRICS_METADATA_NAME, $processedMetrics);
return $table;
}
示例6: sumSubtable
/**
* Sums a DataTable to this row's subtable. If this row has no subtable a new
* one is created.
*
* See {@link Piwik\DataTable::addDataTable()} to learn how DataTables are summed.
*
* @param DataTable $subTable Table to sum to this row's subtable.
*/
public function sumSubtable(DataTable $subTable)
{
if ($this->isSubtableLoaded()) {
$thisSubTable = $this->getSubtable();
} else {
$thisSubTable = new DataTable();
$this->addSubtable($thisSubTable);
}
$columnOps = $subTable->getMetadata(DataTable::COLUMN_AGGREGATION_OPS_METADATA_NAME);
$thisSubTable->setMetadata(DataTable::COLUMN_AGGREGATION_OPS_METADATA_NAME, $columnOps);
$thisSubTable->addDataTable($subTable);
}
示例7: filterPageDatatable
/**
* Common filters for Page URLs and Page Titles
*
* @param DataTable|DataTable\Simple|DataTable\Map $dataTable
*/
protected function filterPageDatatable($dataTable)
{
$columnsToRemove = array('bounce_rate');
$dataTable->queueFilter('ColumnDelete', array($columnsToRemove));
// Average time on page = total time on page / number visits on that page
$dataTable->queueFilter('ColumnCallbackAddColumnQuotient', array('avg_time_on_page', 'sum_time_spent', 'nb_visits', 0));
// Bounce rate = single page visits on this page / visits started on this page
$dataTable->queueFilter('ColumnCallbackAddColumnPercentage', array('bounce_rate', 'entry_bounce_count', 'entry_nb_visits', 0));
// % Exit = Number of visits that finished on this page / visits on this page
$dataTable->queueFilter('ColumnCallbackAddColumnPercentage', array('exit_rate', 'exit_nb_visits', 'nb_visits', 0));
// Handle performance analytics
$hasTimeGeneration = array_sum($dataTable->getColumn(Metrics::INDEX_PAGE_SUM_TIME_GENERATION)) > 0;
if ($hasTimeGeneration) {
// Average generation time = total generation time / number of pageviews
$precisionAvgTimeGeneration = 3;
$dataTable->queueFilter('ColumnCallbackAddColumnQuotient', array('avg_time_generation', 'sum_time_generation', 'nb_hits_with_time_generation', $precisionAvgTimeGeneration));
$dataTable->queueFilter('ColumnDelete', array(array('sum_time_generation')));
} else {
// No generation time: remove it from the API output and add it to empty_columns metadata, so that
// the columns can also be removed from the view
$dataTable->filter('ColumnDelete', array(array(Metrics::INDEX_PAGE_SUM_TIME_GENERATION, Metrics::INDEX_PAGE_NB_HITS_WITH_TIME_GENERATION, Metrics::INDEX_PAGE_MIN_TIME_GENERATION, Metrics::INDEX_PAGE_MAX_TIME_GENERATION)));
if ($dataTable instanceof DataTable) {
$emptyColumns = $dataTable->getMetadata(DataTable::EMPTY_COLUMNS_METADATA_NAME);
if (!is_array($emptyColumns)) {
$emptyColumns = array();
}
$emptyColumns[] = 'sum_time_generation';
$emptyColumns[] = 'avg_time_generation';
$emptyColumns[] = 'min_time_generation';
$emptyColumns[] = 'max_time_generation';
$dataTable->setMetadata(DataTable::EMPTY_COLUMNS_METADATA_NAME, $emptyColumns);
}
}
}
示例8: sumTable
/**
* Sums a tables row with this one.
*
* @param DataTable $table
*/
private function sumTable($table)
{
foreach ($table->getRows() as $row) {
$this->sumRow($row, $enableCopyMetadata = false, $table->getMetadata(DataTable::COLUMN_AGGREGATION_OPS_METADATA_NAME));
}
}
示例9: addSummaryRow
/**
* @param DataTable $table
*/
private function addSummaryRow($table)
{
if ($table->getRowsCount() <= $this->truncateAfter + 1) {
return;
}
$table->filter('Sort', array($this->columnToSortByBeforeTruncating, 'desc', $naturalSort = true, $recursiveSort = false));
$rows = array_values($table->getRows());
$count = $table->getRowsCount();
$newRow = new Row(array(Row::COLUMNS => array('label' => DataTable::LABEL_SUMMARY_ROW)));
$aggregationOps = $table->getMetadata(DataTable::COLUMN_AGGREGATION_OPS_METADATA_NAME);
for ($i = $this->truncateAfter; $i < $count; $i++) {
if (!isset($rows[$i])) {
// case when the last row is a summary row, it is not indexed by $cout but by DataTable::ID_SUMMARY_ROW
$summaryRow = $table->getRowFromId(DataTable::ID_SUMMARY_ROW);
//FIXME: I'm not sure why it could return false, but it was reported in: http://forum.piwik.org/read.php?2,89324,page=1#msg-89442
if ($summaryRow) {
$newRow->sumRow($summaryRow, $enableCopyMetadata = false, $aggregationOps);
}
} else {
$newRow->sumRow($rows[$i], $enableCopyMetadata = false, $aggregationOps);
}
}
$table->filter('Limit', array(0, $this->truncateAfter));
$table->addSummaryRow($newRow);
unset($rows);
}
示例10: getSiteIdFromMetadata
/**
* Returns the ID of the site a table is related to based on the 'site' metadata entry,
* or null if there is none.
*
* @param DataTable $table
* @return int|null
*/
public static function getSiteIdFromMetadata(DataTable $table)
{
$site = $table->getMetadata('site');
if (empty($site)) {
return null;
} else {
return $site->getId();
}
}
示例11: computeProcessedMetrics
public function computeProcessedMetrics(DataTable $dataTable)
{
if ($dataTable->getMetadata(self::PROCESSED_METRICS_COMPUTED_FLAG)) {
return;
}
/** @var ProcessedMetric[] $processedMetrics */
$processedMetrics = Report::getProcessedMetricsForTable($dataTable, $this->report);
if (empty($processedMetrics)) {
return;
}
$dataTable->setMetadata(self::PROCESSED_METRICS_COMPUTED_FLAG, true);
foreach ($processedMetrics as $name => $processedMetric) {
if (!$processedMetric->beforeCompute($this->report, $dataTable)) {
continue;
}
foreach ($dataTable->getRows() as $row) {
if ($row->getColumn($name) === false) {
// only compute the metric if it has not been computed already
$computedValue = $processedMetric->compute($row);
if ($computedValue !== false) {
$row->addColumn($name, $computedValue);
}
$subtable = $row->getSubtable();
if (!empty($subtable)) {
$this->computeProcessedMetrics($subtable);
}
}
}
}
}
示例12: assertTableMetadataEquals
private function assertTableMetadataEquals($expectedPeriod, DataTable $dataTable)
{
$period = $dataTable->getMetadata(DataTableFactory::TABLE_METADATA_PERIOD_INDEX);
$this->assertFalse($dataTable->getMetadata(DataTableFactory::TABLE_METADATA_SITE_INDEX));
$this->assertTrue($period instanceof Period);
$this->assertSame($expectedPeriod, $period->toString());
}
示例13: markMoversAndShakers
/**
* Extends an already generated insight report by adding a column "isMoverAndShaker" whether a row is also a
* "Mover and Shaker" or not.
*
* Avoids the need to fetch all reports again when we already have the currentReport/lastReport
*/
public function markMoversAndShakers(DataTable $insight, $currentReport, $lastReport, $totalValue, $lastTotalValue)
{
if (!$insight->getRowsCount()) {
return;
}
$limitIncreaser = max($insight->getRowsCount(), 3);
$limitDecreaser = max($insight->getRowsCount(), 3);
$lastDate = $insight->getMetadata('lastDate');
$date = $insight->getMetadata('date');
$period = $insight->getMetadata('period');
$metric = $insight->getMetadata('metric');
$orderBy = $insight->getMetadata('orderBy');
$reportMetadata = $insight->getMetadata('report');
$shakers = $this->generateMoverAndShaker($reportMetadata, $period, $date, $lastDate, $metric, $currentReport, $lastReport, $totalValue, $lastTotalValue, $orderBy, $limitIncreaser, $limitDecreaser);
foreach ($insight->getRows() as $row) {
$label = $row->getColumn('label');
if ($shakers->getRowFromLabel($label)) {
$row->setColumn('isMoverAndShaker', true);
} else {
$row->setColumn('isMoverAndShaker', false);
}
}
$this->addMoversAndShakersMetadata($insight, $totalValue, $lastTotalValue);
}
示例14: getMetricsForTable
/**
* Returns the Metrics that are displayed by a DataTable of a certain Report type.
*
* Includes ProcessedMetrics and Metrics.
*
* @param DataTable $dataTable
* @param Report|null $report
* @param string $baseType The base type each metric class needs to be of.
* @return Metric[]
* @api
*/
public static function getMetricsForTable(DataTable $dataTable, Report $report = null, $baseType = 'Piwik\\Plugin\\Metric')
{
$metrics = $dataTable->getMetadata(DataTable::EXTRA_PROCESSED_METRICS_METADATA_NAME) ?: array();
if (!empty($report)) {
$metrics = array_merge($metrics, $report->getProcessedMetricsById());
}
$result = array();
/** @var Metric $metric */
foreach ($metrics as $metric) {
if (!$metric instanceof $baseType) {
continue;
}
$result[$metric->getName()] = $metric;
}
return $result;
}
示例15: loadSubtable
/**
* Load the subtable for a row.
* Returns null if none is found.
*
* @param DataTable $dataTable
* @param Row $row
*
* @return DataTable
*/
protected function loadSubtable($dataTable, $row)
{
if (!($this->apiModule && $this->apiMethod && count($this->request))) {
return null;
}
$request = $this->request;
$idSubTable = $row->getIdSubDataTable();
if ($idSubTable === null) {
return null;
}
$request['idSubtable'] = $idSubTable;
if ($dataTable) {
$period = $dataTable->getMetadata(DataTableFactory::TABLE_METADATA_PERIOD_INDEX);
if ($period instanceof Range) {
$request['date'] = $period->getDateStart() . ',' . $period->getDateEnd();
} else {
$request['date'] = $period->getDateStart()->toString();
}
}
$method = $this->getApiMethodForSubtable();
return $this->callApiAndReturnDataTable($this->apiModule, $method, $request);
}