当前位置: 首页>>代码示例>>PHP>>正文


PHP DataTable::addRow方法代码示例

本文整理汇总了PHP中Piwik\DataTable::addRow方法的典型用法代码示例。如果您正苦于以下问题:PHP DataTable::addRow方法的具体用法?PHP DataTable::addRow怎么用?PHP DataTable::addRow使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Piwik\DataTable的用法示例。


在下文中一共展示了DataTable::addRow方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: addRowWithMetadata

 private function addRowWithMetadata($metadata)
 {
     $row = new Row(array(Row::COLUMNS => array('label' => 'val1')));
     foreach ($metadata as $name => $value) {
         $row->setMetadata($name, $value);
     }
     $this->table->addRow($row);
 }
开发者ID:FluentDevelopment,项目名称:piwik,代码行数:8,代码来源:PrependSegmentFilterTest.php

示例2: getDataTableCount5

 /**
  * Returns table used for the tests
  *
  * @return DataTable
  */
 protected function getDataTableCount5()
 {
     $table = new DataTable();
     $table->addRow($this->getRow0());
     $table->addRow($this->getRow1());
     $table->addRow($this->getRow2());
     $table->addRow($this->getRow3());
     $table->addRow($this->getRow4());
     return $table;
 }
开发者ID:FluentDevelopment,项目名称:piwik,代码行数:15,代码来源:AddSummaryRowTest.php

示例3: test_filter_shouldRemoveTheMetadataFromSubtables_IfOneIsSet

 public function test_filter_shouldRemoveTheMetadataFromSubtables_IfOneIsSet()
 {
     $row = $this->addRowWithMetadata(array('test' => '5', 'other' => 'value2'));
     $table = new DataTable();
     $table->addRow($this->buildRowWithMetadata(array('other' => 'value3')));
     $table->addRow($this->buildRowWithMetadata(array('test' => '6')));
     $table->addRow($this->buildRowWithMetadata(array('test' => '7', 'other' => 'value4')));
     $row->setSubtable($table);
     $this->table->filter($this->filter, array('other'));
     $this->assertFalse($row->getMetadata('other'));
     $metadata = $table->getRowsMetadata('other');
     $this->assertSame(array(false, false, false), $metadata);
 }
开发者ID:FluentDevelopment,项目名称:piwik,代码行数:13,代码来源:ColumnCallbackDeleteMetadataTest.php

示例4: processSummary

 /**
  * Helper function to display operation/cluster summary stats.
  *
  * @param $idSite
  * @param $period
  * @param $date
  * @param $settings
  *
  * @return \Piwik\DataTable
  */
 protected function processSummary($idSite, $period, $date, $settings, $addCountry = true)
 {
     $table = new DataTable();
     $segment = $settings['name'] . '==' . $settings['context'] . ';' . $settings['value'] . '=@' . $settings['id'];
     // Build an archive to retrieve the information from the records.
     $archive = Archive::build($idSite, $period, $date, $segment);
     /* @var \Piwik\DataTable $tdata */
     $data = $archive->getDataTableFromNumeric(array('nb_visits', 'Actions_nb_downloads'));
     // Add the downloads by type.
     $downloads = $this->attachDownloadByType($idSite, $period, $date, $segment);
     $data->getRowFromId(0)->addColumns($downloads);
     $table->addRow($data->getRowFromId(0));
     // Calculate the right label and load the content.
     if (empty($settings['label'])) {
         $base_url = 'https://www.humanitarianresponse.info/api/v1.0/';
         if ($content_raw = @file_get_contents($base_url . $settings['type'] . '/' . $settings['id'])) {
             $hrContent = json_decode($content_raw);
             $settings['label'] = $hrContent->data[0]->label;
         }
     }
     // Add the label to the row.
     $table->getRowFromId(0)->addColumn('label', $settings['label']);
     // Only add country stats on demand.
     if ($addCountry && !empty($hrContent)) {
         $dataByCountry = $this->attachStatsbyCountry($hrContent, $idSite, $period, $date, $segment);
         if ($row = $dataByCountry->getRowFromId(0)) {
             $table->addRow($row);
         }
     }
     return $table;
 }
开发者ID:humanitarianresponse,项目名称:piwik_plugin,代码行数:41,代码来源:API.php

示例5: 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

示例6: bannerStats

 private function bannerStats($bannerName, $params)
 {
     $contentPiece = false;
     if (strpos($bannerName, '_') !== false) {
         list($bannerName, $contentPiece) = explode('_', $bannerName);
     }
     $segment = 'contentName==' . $bannerName;
     $recordName = Dimensions::getRecordNameForAction('getContentPieces');
     $subTable = Archive::getDataTableFromArchive($recordName, $params['idSite'], $params['period'], $params['date'], $segment, true);
     //echo '<pre>';
     $bannerTable = new DataTable();
     if (!$contentPiece) {
         foreach ($subTable->getRows() as $row) {
             $ContentPieceId = Db::fetchOne("SELECT idaction FROM piwik_log_action WHERE TYPE = 14 and name = ?", array($row->getColumn('label')));
             $bannerRow = new Row(array(Row::COLUMNS => array('Label' => $row->getColumn('label'), 'Impressions' => $row->getColumn(41), 'Interactions' => $row->getColumn(42), 'Conversion rate' => $this->interactionRate($row->getColumn(41), $row->getColumn(42))), Row::DATATABLE_ASSOCIATED => implode('_', array($bannerName, $ContentPieceId))));
             $bannerTable->addRow($bannerRow);
         }
     } else {
         $orderColumn = str_replace(' ', '_', strtolower($params['filter_sort_column']));
         $orderOrder = in_array($params['filter_sort_order'], array('asc', 'desc')) ? $params['filter_sort_order'] : 'asc';
         $orderLimit = intval($params['filter_limit']);
         $where = '';
         /*
         TODO: filter_pattern is processed by piwik in some way. The results are good with this query, but piwik does some post-processing?
         if (isset($params['filter_pattern'])) {
              $where = 'and piwik_log_action.name like "%' .  $params['filter_pattern'] . '%"';
         }
         */
         $result = Db::fetchAll("\n                    SELECT \n                        trim(substring_index(piwik_log_action.name, '|', 1)) as referrer,\n                        trim(substring_index(piwik_log_action.name, '|', -1)) as target,\n                        sum(IF(idaction_content_interaction is null, 1, 0)) as impressions, \n                        sum(IF(idaction_content_interaction is null, 0, 1)) as interactions,\n                        ((100 / sum(IF(idaction_content_interaction is null, 1, 0))) * sum(IF(idaction_content_interaction is null, 0, 1))) as conversion_rate\n                    FROM piwik_log_link_visit_action \n                    left join piwik_log_action on piwik_log_action.idaction = idaction_content_target\n                    WHERE \n                        idaction_content_name in (SELECT idaction FROM piwik_log_action WHERE name = ?)\n                    and\n                        idaction_content_piece = ?\n                    \n                    {$where}\n\n                    group by piwik_log_action.name\n                    order by {$orderColumn} {$orderOrder}\n                    limit {$orderLimit}\n            ", array($bannerName, $contentPiece));
         foreach ($result as $row) {
             $bannerRow = new Row(array(Row::COLUMNS => array('Referrer' => $row['referrer'], 'Target' => $row['target'], 'Impressions' => $row['impressions'], 'Interactions' => $row['interactions'], 'Conversion rate' => round($row['conversion_rate']) . '%')));
             $bannerTable->addRow($bannerRow);
         }
     }
     return $bannerTable;
 }
开发者ID:ronaldbaltus,项目名称:VPSCashPiwikBannerPlugin,代码行数:36,代码来源:API.php

示例7: getFollowingPages

 /**
  * Get following pages of a url.
  * This is done on the logs - not the archives!
  *
  * Note: if you use this method via the regular API, the number of results will be limited.
  * Make sure, you set filter_limit=-1 in the request.
  */
 public function getFollowingPages($url, $idSite, $period, $date, $segment = false)
 {
     $this->authenticate($idSite);
     $url = PageUrl::excludeQueryParametersFromUrl($url, $idSite);
     // we don't unsanitize $url here. it will be done in the Transitions plugin.
     $resultDataTable = new DataTable();
     try {
         $limitBeforeGrouping = Config::getInstance()->General['overlay_following_pages_limit'];
         $transitionsReport = APITransitions::getInstance()->getTransitionsForAction($url, $type = 'url', $idSite, $period, $date, $segment, $limitBeforeGrouping, $part = 'followingActions', $returnNormalizedUrls = true);
     } catch (Exception $e) {
         return $resultDataTable;
     }
     $reports = array('followingPages', 'outlinks', 'downloads');
     foreach ($reports as $reportName) {
         if (!isset($transitionsReport[$reportName])) {
             continue;
         }
         foreach ($transitionsReport[$reportName]->getRows() as $row) {
             // don't touch the row at all for performance reasons
             $resultDataTable->addRow($row);
         }
     }
     return $resultDataTable;
 }
开发者ID:FluentDevelopment,项目名称:piwik,代码行数:31,代码来源:API.php

示例8: testGeneral

 /**
  * General tests that tries to test the normal behaviour of DataTable
  *
  * We create some tables, add rows, some of the rows link to sub tables
  *
  * Then we serialize everything, and we check that the unserialize give the same object back
  */
 public function testGeneral()
 {
     /*
      * create some fake tables to make sure that the serialized array of the first TABLE
      * does not take in consideration those tables
      */
     $useless1 = $this->createDataTable(array(array(13)));
     /*
      * end fake tables
      */
     /*
      * MAIN TABLE
      */
     $table = new DataTable();
     $subtable = new DataTable();
     $idtable = $table->getId();
     /*
      * create some fake tables to make sure that the serialized array of the first TABLE
      * does not take in consideration those tables
      * -> we check that the DataTable_Manager is not impacting DataTable
      */
     $useless1->addRowFromArray(array(Row::COLUMNS => array(8487)));
     $useless3 = $this->createDataTable(array(array(8487)));
     /*
      * end fake tables
      */
     $row = array(Row::COLUMNS => array(0 => 1554, 1 => 42, 2 => 657, 3 => 155744), Row::METADATA => array('logo' => 'test.png'));
     $row = new Row($row);
     $table->addRow($row);
     $table->addRowFromArray(array(Row::COLUMNS => array(0 => 1554, 1 => 42), Row::METADATA => array('url' => 'piwik.org')));
     $table->addRowFromArray(array(Row::COLUMNS => array(0 => 787877888787), Row::METADATA => array('url' => 'OUPLA ADDED'), Row::DATATABLE_ASSOCIATED => $subtable));
     /*
      * SUB TABLE
      */
     $row = array(Row::COLUMNS => array(0 => 1554), Row::METADATA => array('searchengine' => 'google'));
     $subtable->addRowFromArray($row);
     $row = array(Row::COLUMNS => array(0 => 84894), Row::METADATA => array('searchengine' => 'yahoo'));
     $subtable->addRowFromArray($row);
     $row = array(Row::COLUMNS => array(0 => 4898978989), Row::METADATA => array('searchengine' => 'ask'));
     $subtable->addRowFromArray($row);
     /*
      * SUB SUB TABLE
      */
     $subsubtable = new DataTable();
     $subsubtable->addRowFromArray(array(Row::COLUMNS => array(245), Row::METADATA => array('yes' => 'subsubmetadata1')));
     $subsubtable->addRowFromArray(array(Row::COLUMNS => array(13), Row::METADATA => array('yes' => 'subsubmetadata2')));
     $row = array(Row::COLUMNS => array(0 => 666666666666666), Row::METADATA => array('url' => 'NEW ROW ADDED'), Row::DATATABLE_ASSOCIATED => $subsubtable);
     $subtable->addRowFromArray($row);
     $idsubsubtable = $subsubtable->getId();
     $serialized = $table->getSerialized();
     $this->assertEquals(array_keys($serialized), array(2, 1, 0));
     // subtableIds are now consecutive
     // In the next test we compare an unserialized datatable with its original instance.
     // The unserialized datatable rows will have positive DATATABLE_ASSOCIATED ids.
     // Positive DATATABLE_ASSOCIATED ids mean that the associated sub-datatables are not loaded in memory.
     // In this case, this is NOT true: we know that the sub-datatable is loaded in memory.
     // HOWEVER, because of datatable id conflicts happening in the datatable manager, it is not yet
     // possible to know, after unserializing a datatable, if its sub-datatables are loaded in memory.
     $expectedTableRows = array();
     $i = 0;
     foreach ($table->getRows() as $currentRow) {
         $expectedTableRow = clone $currentRow;
         $currentRowAssociatedDatatableId = $currentRow->subtableId;
         if ($currentRowAssociatedDatatableId != null) {
             $expectedTableRow->setNonLoadedSubtableId(++$i);
             // subtableIds are consecutive
         }
         $expectedTableRows[] = $expectedTableRow;
     }
     $tableAfter = new DataTable();
     $tableAfter->addRowsFromSerializedArray($serialized[0]);
     $this->assertEquals($expectedTableRows, $tableAfter->getRows());
     $subsubtableAfter = new DataTable();
     $subsubtableAfter->addRowsFromSerializedArray($serialized[$consecutiveSubtableId = 2]);
     $this->assertEquals($subsubtable->getRows(), $subsubtableAfter->getRows());
     $this->assertEquals($subsubtable->getRows(), DataTable::fromSerializedArray($serialized[$consecutiveSubtableId = 2])->getRows());
     $this->assertTrue($subsubtable->getRowsCount() > 0);
     $this->assertEquals($table, Manager::getInstance()->getTable($idtable));
     $this->assertEquals($subsubtable, Manager::getInstance()->getTable($idsubsubtable));
 }
开发者ID:FluentDevelopment,项目名称:piwik,代码行数:87,代码来源:DataTableTest.php

示例9: doFilterPageDatatableSearch

 /**
  * This looks very similar to LabelFilter.php should it be refactored somehow? FIXME
  */
 protected function doFilterPageDatatableSearch($callBackParameters, $table, $searchTree)
 {
     // filter a data table array
     if ($table instanceof DataTable\Map) {
         foreach ($table->getDataTables() as $subTable) {
             $filteredSubTable = $this->doFilterPageDatatableSearch($callBackParameters, $subTable, $searchTree);
             if ($filteredSubTable->getRowsCount() > 0) {
                 // match found in a sub table, return and stop searching the others
                 return $filteredSubTable;
             }
         }
         // nothing found in all sub tables
         return new DataTable();
     }
     // filter regular data table
     if ($table instanceof DataTable) {
         // search for the first part of the tree search
         $search = array_shift($searchTree);
         $row = $table->getRowFromLabel($search);
         if ($row === false) {
             // not found
             $result = new DataTable();
             $result->setAllTableMetadata($table->getAllTableMetadata());
             return $result;
         }
         // end of tree search reached
         if (count($searchTree) == 0) {
             $result = new DataTable();
             $result->addRow($row);
             $result->setAllTableMetadata($table->getAllTableMetadata());
             return $result;
         }
         // match found on this level and more levels remaining: go deeper
         $idSubTable = $row->getIdSubDataTable();
         $callBackParameters[6] = $idSubTable;
         /**
          * @var \Piwik\Period $period
          */
         $period = $table->getMetadata('period');
         if (!empty($period)) {
             $callBackParameters[3] = $period->getDateStart() . ',' . $period->getDateEnd();
         }
         $table = call_user_func_array(array($this, 'getDataTableFromArchive'), $callBackParameters);
         return $this->doFilterPageDatatableSearch($callBackParameters, $table, $searchTree);
     }
     throw new Exception("For this API function, DataTable " . get_class($table) . " is not supported");
 }
开发者ID:a4tunado,项目名称:piwik,代码行数:50,代码来源:API.php

示例10: makeDataTablesFollowingActions

 protected function makeDataTablesFollowingActions($types, $data)
 {
     $this->totalTransitionsToFollowingActions = 0;
     $dataTables = array();
     foreach ($types as $type => $recordName) {
         $dataTable = new DataTable();
         if (isset($data[$type])) {
             foreach ($data[$type] as &$record) {
                 $actions = intval($record[Metrics::INDEX_NB_ACTIONS]);
                 $dataTable->addRow(new Row(array(Row::COLUMNS => array('label' => $this->getPageLabel($record, $type), Metrics::INDEX_NB_ACTIONS => $actions))));
                 $this->totalTransitionsToFollowingActions += $actions;
             }
         }
         $dataTables[$recordName] = $dataTable;
     }
     return $dataTables;
 }
开发者ID:a4tunado,项目名称:piwik,代码行数:17,代码来源:API.php

示例11: copyRowsAndSetLabel

 /**
  * Utility function used by mergeChildren. Copies the rows from one table,
  * sets their 'label' columns to a value and adds them to another table.
  *
  * @param DataTable $toTable The table to copy rows to.
  * @param DataTable $fromTable The table to copy rows from.
  * @param string $label The value to set the 'label' column of every copied row.
  */
 private function copyRowsAndSetLabel($toTable, $fromTable, $label)
 {
     foreach ($fromTable->getRows() as $fromRow) {
         $oldColumns = $fromRow->getColumns();
         unset($oldColumns['label']);
         $columns = array_merge(array('label' => $label), $oldColumns);
         $row = new Row(array(Row::COLUMNS => $columns, Row::METADATA => $fromRow->getMetadata(), Row::DATATABLE_ASSOCIATED => $fromRow->getIdSubDataTable()));
         $toTable->addRow($row);
     }
 }
开发者ID:brienomatty,项目名称:elmsln,代码行数:18,代码来源:Map.php

示例12: handleSimpleDataTable

 /**
  * Enhance $simpleDataTable using metadata :
  *
  * - remove metrics based on $reportMetadata['metrics']
  * - add 0 valued metrics if $simpleDataTable doesn't provide all $reportMetadata['metrics']
  * - format metric values to a 'human readable' format
  * - extract row metadata to a separate Simple $rowsMetadata
  *
  * @param int $idSite enables monetary value formatting based on site currency
  * @param Simple $simpleDataTable
  * @param array $metadataColumns
  * @param boolean $hasDimension
  * @param bool $returnRawMetrics If set to true, the original metrics will be returned
  * @param bool|null $formatMetrics
  * @return array DataTable $enhancedDataTable filtered metrics with human readable format & Simple $rowsMetadata
  */
 private function handleSimpleDataTable($idSite, $simpleDataTable, $metadataColumns, $hasDimension, $returnRawMetrics = false, $formatMetrics = null)
 {
     // new DataTable to store metadata
     $rowsMetadata = new DataTable();
     // new DataTable to store 'human readable' values
     if ($hasDimension) {
         $enhancedDataTable = new DataTable();
     } else {
         $enhancedDataTable = new Simple();
     }
     $formatter = new Formatter();
     foreach ($simpleDataTable->getRows() as $row) {
         $rowMetrics = $row->getColumns();
         // add missing metrics
         foreach ($metadataColumns as $id => $name) {
             if (!isset($rowMetrics[$id])) {
                 $row->setColumn($id, 0);
                 $rowMetrics[$id] = 0;
             }
         }
         $enhancedRow = new Row();
         $enhancedDataTable->addRow($enhancedRow);
         foreach ($rowMetrics as $columnName => $columnValue) {
             // filter metrics according to metadata definition
             if (isset($metadataColumns[$columnName])) {
                 // generate 'human readable' metric values
                 // if we handle MultiSites.getAll we do not always have the same idSite but different ones for
                 // each site, see https://github.com/piwik/piwik/issues/5006
                 $idSiteForRow = $idSite;
                 $idSiteMetadata = $row->getMetadata('idsite');
                 if ($idSiteMetadata && is_numeric($idSiteMetadata)) {
                     $idSiteForRow = (int) $idSiteMetadata;
                 }
                 // format metrics manually here to maintain API.getProcessedReport BC if format_metrics query parameter is
                 // not supplied. TODO: should be removed for 3.0. should only rely on format_metrics query parameter.
                 if ($formatMetrics === null || $formatMetrics == 'bc') {
                     $prettyValue = self::getPrettyValue($formatter, $idSiteForRow, $columnName, $columnValue, $htmlAllowed = false);
                 } else {
                     $prettyValue = $columnValue;
                 }
                 $enhancedRow->addColumn($columnName, $prettyValue);
             } else {
                 if ($returnRawMetrics) {
                     if (!isset($columnValue)) {
                         $columnValue = 0;
                     }
                     $enhancedRow->addColumn($columnName, $columnValue);
                 }
             }
         }
         // If report has a dimension, extract metadata into a distinct DataTable
         if ($hasDimension) {
             $rowMetadata = $row->getMetadata();
             $idSubDataTable = $row->getIdSubDataTable();
             // Create a row metadata only if there are metadata to insert
             if (count($rowMetadata) > 0 || !is_null($idSubDataTable)) {
                 $metadataRow = new Row();
                 $rowsMetadata->addRow($metadataRow);
                 foreach ($rowMetadata as $metadataKey => $metadataValue) {
                     $metadataRow->addColumn($metadataKey, $metadataValue);
                 }
                 if (!is_null($idSubDataTable)) {
                     $metadataRow->addColumn('idsubdatatable', $idSubDataTable);
                 }
             }
         }
     }
     return array($enhancedDataTable, $rowsMetadata);
 }
开发者ID:CaptainSharf,项目名称:SSAD_Project,代码行数:85,代码来源:ProcessedReport.php

示例13: getSummaryStats

 /**
  * Another example method that returns a data table.
  * @param int    $idSite
  * @param string $period
  * @param string $date
  * @param bool|string $segment
  * @return DataTable
  */
 public function getSummaryStats($idSite, $period, $date, $segment = false)
 {
     set_time_limit(600);
     $table = new DataTable();
     $operations_url = 'http://www.humanitarianresponse.info/api/v1.0/operations/?fields=id';
     if ($operations_raw = @file_get_contents($operations_url)) {
         $operations_json = json_decode($operations_raw);
         foreach ($operations_json->data as $op_id) {
             $temp = $this->getSpaceSummary($idSite, $period, $date, $op_id->id, 'operation');
             $table->addRow($temp->getRowFromId(0));
         }
     }
     $spaces_url = 'http://www.humanitarianresponse.info/api/v1.0/spaces/?fields=id';
     if ($spaces_raw = @file_get_contents($spaces_url)) {
         $spaces_json = json_decode($spaces_raw);
         foreach ($spaces_json->data as $space_id) {
             $temp = $this->getSpaceSummary($idSite, $period, $date, $space_id->id, 'space');
             $table->addRow($temp->getRowFromId(0));
         }
     }
     return $table;
 }
开发者ID:pcambra,项目名称:piwik_plugin,代码行数:30,代码来源:API.php

示例14: getCompetitionDatatable

 /**
  * Returns a custom data table.
  * This data table will be converted to all available formats
  * when requested in the API request.
  *
  * @return DataTable
  */
 public function getCompetitionDatatable()
 {
     $dataTable = new DataTable();
     $row1 = new Row();
     $row1->setColumns(array('name' => 'piwik', 'license' => 'GPL'));
     // Rows Metadata is useful to store non stats data for example (logos, urls, etc.)
     // When printed out, they are simply merged with columns
     $row1->setMetadata('logo', 'logo.png');
     $dataTable->addRow($row1);
     $dataTable->addRowFromSimpleArray(array('name' => 'google analytics', 'license' => 'commercial'));
     return $dataTable;
 }
开发者ID:KiwiJuicer,项目名称:handball-dachau,代码行数:19,代码来源:API.php

示例15: mergeSubtables

 /**
  * Returns a new DataTable in which the rows of this table are replaced with the aggregatated rows of all its subtables.
  *
  * @param string|bool $labelColumn If supplied the label of the parent row will be added to
  *                                 a new column in each subtable row.
  *
  *                                 If set to, `'label'` each subtable row's label will be prepended
  *                                 w/ the parent row's label. So `'child_label'` becomes
  *                                 `'parent_label - child_label'`.
  * @param bool $useMetadataColumn If true and if `$labelColumn` is supplied, the parent row's
  *                                label will be added as metadata and not a new column.
  * @return \Piwik\DataTable
  */
 public function mergeSubtables($labelColumn = false, $useMetadataColumn = false)
 {
     $result = new DataTable();
     $result->setAllTableMetadata($this->getAllTableMetadata());
     foreach ($this->getRowsWithoutSummaryRow() as $row) {
         $subtable = $row->getSubtable();
         if ($subtable !== false) {
             $parentLabel = $row->getColumn('label');
             // add a copy of each subtable row to the new datatable
             foreach ($subtable->getRows() as $id => $subRow) {
                 $copy = clone $subRow;
                 // if the summary row, add it to the existing summary row (or add a new one)
                 if ($id == self::ID_SUMMARY_ROW) {
                     $existing = $result->getRowFromId(self::ID_SUMMARY_ROW);
                     if ($existing === false) {
                         $result->addSummaryRow($copy);
                     } else {
                         $existing->sumRow($copy, $copyMeta = true, $this->getMetadata(self::COLUMN_AGGREGATION_OPS_METADATA_NAME));
                     }
                 } else {
                     if ($labelColumn !== false) {
                         // if we're modifying the subtable's rows' label column, then we make
                         // sure to prepend the existing label w/ the parent row's label. otherwise
                         // we're just adding the parent row's label as a new column/metadata.
                         $newLabel = $parentLabel;
                         if ($labelColumn == 'label') {
                             $newLabel .= ' - ' . $copy->getColumn('label');
                         }
                         // modify the child row's label or add new column/metadata
                         if ($useMetadataColumn) {
                             $copy->setMetadata($labelColumn, $newLabel);
                         } else {
                             $copy->setColumn($labelColumn, $newLabel);
                         }
                     }
                     $result->addRow($copy);
                 }
             }
         }
     }
     return $result;
 }
开发者ID:piwik,项目名称:piwik,代码行数:55,代码来源:DataTable.php


注:本文中的Piwik\DataTable::addRow方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。