當前位置: 首頁>>代碼示例>>PHP>>正文


PHP DataTable\Map類代碼示例

本文整理匯總了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);
     }
 }
開發者ID:FluentDevelopment,項目名稱:piwik,代碼行數:34,代碼來源:MergeDataTables.php

示例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;
 }
開發者ID:FluentDevelopment,項目名稱:piwik,代碼行數:9,代碼來源:MapTest.php

示例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;
 }
開發者ID:TensorWrenchOSS,項目名稱:piwik,代碼行數:15,代碼來源:DataTableManipulator.php

示例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 . '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
     foreach ($map->getDataTables() as $descTable => $table) {
         $output .= $prefix . "<b>" . $descTable . "</b><br />";
         $output .= $prefix . $this->renderTable($table, $prefix . '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;');
         $output .= "<hr />";
     }
     return $output;
 }
開發者ID:FluentDevelopment,項目名稱:piwik,代碼行數:18,代碼來源:Console.php

示例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;
 }
開發者ID:brienomatty,項目名稱:elmsln,代碼行數:19,代碼來源:Evolution.php

示例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;
 }
開發者ID:piwik,項目名稱:piwik,代碼行數:29,代碼來源:Sparkline.php

示例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);
 }
開發者ID:Abine,項目名稱:piwik,代碼行數:13,代碼來源:PhpRendererTest.php

示例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);
 }
開發者ID:CaptainSharf,項目名稱:SSAD_Project,代碼行數:72,代碼來源:ProcessedReport.php

示例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;
 }
開發者ID:KiwiJuicer,項目名稱:handball-dachau,代碼行數:26,代碼來源:DataTableFactory.php

示例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);
    }
開發者ID:FluentDevelopment,項目名稱:piwik,代碼行數:33,代碼來源:HtmlRendererTest.php

示例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);
    }
開發者ID:a4tunado,項目名稱:piwik,代碼行數:26,代碼來源:XmlRendererTest.php

示例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;
 }
開發者ID:josl,項目名稱:CGE-File-Sharing,代碼行數:25,代碼來源:LabelFilter.php

示例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');
 }
開發者ID:a4tunado,項目名稱:piwik,代碼行數:14,代碼來源:API.php

示例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);
         }
     }
 }
開發者ID:KiwiJuicer,項目名稱:handball-dachau,代碼行數:20,代碼來源:API.php

示例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;
 }
開發者ID:FluentDevelopment,項目名稱:piwik,代碼行數:31,代碼來源:DataTableFactory.php


注:本文中的Piwik\DataTable\Map類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。