php Piwik-DataTable类(方法)实例源码

下面列出了php Piwik-DataTable 类(方法)源码代码实例,从而了解它的用法。

作者:brienomatt    项目:elmsl   
/**
  * See {@link PatternRecursive}.
  * 
  * @param DataTable $table
  * @return int The number of deleted rows.
  */
 public function filter($table)
 {
     $rows = $table->getRows();
     foreach ($rows as $key => $row) {
         // A row is deleted if
         // 1 - its label doesnt contain the pattern
         // AND 2 - the label is not found in the children
         $patternNotFoundInChildren = false;
         try {
             $idSubTable = $row->getIdSubDataTable();
             $subTable = Manager::getInstance()->getTable($idSubTable);
             // we delete the row if we couldn't find the pattern in any row in the
             // children hierarchy
             if ($this->filter($subTable) == 0) {
                 $patternNotFoundInChildren = true;
             }
         } catch (Exception $e) {
             // there is no subtable loaded for example
             $patternNotFoundInChildren = true;
         }
         if ($patternNotFoundInChildren && !Pattern::match($this->patternToSearchQuoted, $row->getColumn($this->columnToFilter), $invertedMatch = false)) {
             $table->deleteRow($key);
         }
     }
     return $table->getRowsCount();
 }

作者:FluentDevelopmen    项目:piwi   
/**
  * @param DataTable $table
  */
 public function filter($table)
 {
     $row = $table->getRowFromLabel(Archiver::EVENT_NAME_NOT_SET);
     if ($row) {
         $row->setColumn('label', Piwik::translate('General_NotDefined', Piwik::translate('Events_EventName')));
     }
 }

作者:FluentDevelopmen    项目:piwi   
/**
  * 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);
     }
 }

作者:FluentDevelopmen    项目:piwi   
/**
  * @param DataTable $table
  */
 public function filter($table)
 {
     $notDefinedLabel = Piwik::translate('General_NotDefined', Piwik::translate('CustomVariables_ColumnCustomVariableValue'));
     $table->queueFilter('ColumnCallbackReplace', array('label', function ($label) use($notDefinedLabel) {
         return $label == \Piwik\Plugins\CustomVariables\Archiver::LABEL_CUSTOM_VALUE_NOT_DEFINED ? $notDefinedLabel : $label;
     }));
 }

作者:FluentDevelopmen    项目:piwi   
/**
  * @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);
 }

作者:carriercom    项目:piwi   
/**
  * 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);
 }

作者:a4tunad    项目:piwi   
public function test_renderDataTable_shouldReturnResult()
 {
     $dataTable = new DataTable();
     $dataTable->addRowFromSimpleArray(array('nb_visits' => 5, 'nb_random' => 10));
     $response = $this->builder->renderDataTable($dataTable);
     $this->assertSame("- 1 ['nb_visits' => 5, 'nb_random' => 10] [] [idsubtable = ]<br />\n", $response);
 }

作者:piwi    项目:piwi   
/**
  * See {@link Sort}.
  *
  * @param DataTable $table
  * @return mixed
  */
 public function filter($table)
 {
     if ($table instanceof Simple) {
         return;
     }
     if (empty($this->columnToSort)) {
         return;
     }
     if (!$table->getRowsCountWithoutSummaryRow()) {
         return;
     }
     $row = $table->getFirstRow();
     if ($row === false) {
         return;
     }
     $config = new Sorter\Config();
     $sorter = new Sorter($config);
     $config->naturalSort = $this->naturalSort;
     $config->primaryColumnToSort = $sorter->getPrimaryColumnToSort($table, $this->columnToSort);
     $config->primarySortOrder = $sorter->getPrimarySortOrder($this->order);
     $config->primarySortFlags = $sorter->getBestSortFlags($table, $config->primaryColumnToSort);
     $config->secondaryColumnToSort = $sorter->getSecondaryColumnToSort($row, $config->primaryColumnToSort);
     $config->secondarySortOrder = $sorter->getSecondarySortOrder($this->order, $config->secondaryColumnToSort);
     $config->secondarySortFlags = $sorter->getBestSortFlags($table, $config->secondaryColumnToSort);
     // secondary sort should not be needed for all other sort flags (eg string/natural sort) as label is unique and would make it slower
     $isSecondaryColumnSortNeeded = $config->primarySortFlags === SORT_NUMERIC;
     $config->isSecondaryColumnSortEnabled = $this->isSecondaryColumnSortEnabled && $isSecondaryColumnSortNeeded;
     $this->sort($sorter, $table);
 }

作者:FluentDevelopmen    项目:piwi   
/**
  * @param DataTable $table
  */
 public function filter($table)
 {
     $numRows = 0;
     $lastGroupFromPreviousPage = null;
     foreach ($table->getRows() as $row) {
         $this->addRowIfNeeded($row, $numRows);
         $numRows++;
         $subtable = $row->getSubtable();
         if ($subtable) {
             if (!$this->hasRows()) {
                 $lastGroupFromPreviousPage = $row;
             }
             foreach ($subtable->getRows() as $subRow) {
                 $this->addRowIfNeeded($subRow, $numRows);
                 $numRows++;
             }
             $row->removeSubtable();
         }
         if ($this->hasNumberOfRequestedRowsFound()) {
             break;
         }
     }
     $this->prependGroupIfFirstSiteBelongsToAGroupButGroupIsMissingInRows($lastGroupFromPreviousPage);
     $table->setRows($this->rows);
 }

作者:bossrabbi    项目:piwi   
/**
  * See {@link ColumnCallbackAddMetadata}.
  *
  * @param DataTable $table
  */
 public function filter($table)
 {
     if ($this->applyToSummaryRow) {
         $rows = $table->getRows();
     } else {
         $rows = $table->getRowsWithoutSummaryRow();
     }
     foreach ($rows as $key => $row) {
         $parameters = array();
         foreach ($this->columnsToRead as $columnsToRead) {
             $parameters[] = $row->getColumn($columnsToRead);
         }
         if (!is_null($this->functionParameters)) {
             $parameters = array_merge($parameters, $this->functionParameters);
         }
         if (!is_null($this->functionToApply)) {
             $newValue = call_user_func_array($this->functionToApply, $parameters);
         } else {
             $newValue = $parameters[0];
         }
         if ($newValue !== false) {
             $row->addMetadata($this->metadataToAdd, $newValue);
         }
     }
 }

作者:FluentDevelopmen    项目:piwi   
/**
  * See {@link ColumnCallbackReplace}.
  *
  * @param DataTable $table
  */
 public function filter($table)
 {
     foreach ($table->getRows() as $row) {
         $extraColumnParameters = array();
         foreach ($this->extraColumnParameters as $columnName) {
             $extraColumnParameters[] = $row->getColumn($columnName);
         }
         foreach ($this->columnsToFilter as $column) {
             // when a value is not defined, we set it to zero by default (rather than displaying '-')
             $value = $this->getElementToReplace($row, $column);
             if ($value === false) {
                 $value = 0;
             }
             $parameters = array_merge(array($value), $extraColumnParameters);
             if (!is_null($this->functionParameters)) {
                 $parameters = array_merge($parameters, $this->functionParameters);
             }
             $newValue = call_user_func_array($this->functionToApply, $parameters);
             $this->setElementToReplace($row, $column, $newValue);
             $this->filterSubTable($row);
         }
     }
     if (in_array('label', $this->columnsToFilter)) {
         // we need to force rebuilding the index
         $table->setLabelsHaveChanged();
     }
 }

作者:FluentDevelopmen    项目:piwi   
/**
  * Method for the recursive descend
  *
  * @param array $labelParts
  * @param DataTable $dataTable
  * @return Row|bool
  */
 private function doFilterRecursiveDescend($labelParts, $dataTable)
 {
     // we need to make sure to rebuild the index as some filters change the label column directly via
     // $row->setColumn('label', '') which would not be noticed in the label index otherwise.
     $dataTable->rebuildIndex();
     // search for the first part of the tree search
     $labelPart = array_shift($labelParts);
     $row = false;
     foreach ($this->getLabelVariations($labelPart) as $labelPart) {
         $row = $dataTable->getRowFromLabel($labelPart);
         if ($row !== false) {
             break;
         }
     }
     if ($row === false) {
         // not found
         return false;
     }
     // end of tree search reached
     if (count($labelParts) == 0) {
         return $row;
     }
     $subTable = $this->loadSubtable($dataTable, $row);
     if ($subTable === null) {
         // no more subtables but label parts left => no match found
         return false;
     }
     return $this->doFilterRecursiveDescend($labelParts, $subTable);
 }

作者:jos    项目:CGE-File-Sharin   
/**
  * Method for the recursive descend
  *
  * @param array $labelParts
  * @param DataTable $dataTable
  * @return Row|bool
  */
 private function doFilterRecursiveDescend($labelParts, $dataTable)
 {
     // search for the first part of the tree search
     $labelPart = array_shift($labelParts);
     $row = false;
     foreach ($this->getLabelVariations($labelPart) as $labelPart) {
         $row = $dataTable->getRowFromLabel($labelPart);
         if ($row !== false) {
             break;
         }
     }
     if ($row === false) {
         // not found
         return false;
     }
     // end of tree search reached
     if (count($labelParts) == 0) {
         return $row;
     }
     $subTable = $this->loadSubtable($dataTable, $row);
     if ($subTable === null) {
         // no more subtables but label parts left => no match found
         return false;
     }
     return $this->doFilterRecursiveDescend($labelParts, $subTable);
 }

作者:ep12    项目:plugin-CustomDimension   
private function filterTable($withUser = 5)
 {
     $dataTable = new DataTable();
     $dataTable->addRowsFromArray(array(array(Row::COLUMNS => array('label' => 'val1', Metrics::INDEX_NB_USERS => 0)), array(Row::COLUMNS => array('label' => 'val2')), array(Row::COLUMNS => array('label' => 'val2 5w ö?', Metrics::INDEX_NB_USERS => $withUser))));
     $dataTable->filter($this->filter, array($idSite = 1, $period = 'day', $date = 'today'));
     return $dataTable->getColumn(Metrics::INDEX_NB_USERS);
 }

作者:piwi    项目:piwi   
/**
  * @param DataTable $table
  */
 protected function filterTable($table)
 {
     foreach ($table->getRows() as $row) {
         $newColumns = $this->getRenamedColumns($row->getColumns());
         $row->setColumns($newColumns);
         $this->filterSubTable($row);
     }
 }

作者:FluentDevelopmen    项目:piwi   
public function testRangeCheckOnMetadata()
 {
     $table = new DataTable();
     $table->addRowsFromArray(array(array(Row::COLUMNS => array('label' => 'foo'), Row::METADATA => array('count' => 5)), array(Row::COLUMNS => array('label' => 'bar'), Row::METADATA => array('count' => 10)), array(Row::COLUMNS => array('label' => 'bar'), Row::METADATA => array('count' => 15))));
     $filter = new RangeCheck($table, 'count', 0, 10);
     $filter->filter($table);
     $this->assertEquals(array(5, 10, 10), $table->getRowsMetadata('count'));
 }

作者:carriercom    项目:piwi   
public function setUp()
 {
     $this->currentTable = new DataTable();
     $this->currentTable->addRowsFromArray(array(array(Row::COLUMNS => array('label' => 'val1', 'nb_visits' => 120)), array(Row::COLUMNS => array('label' => 'val2', 'nb_visits' => 70)), array(Row::COLUMNS => array('label' => 'val3', 'nb_visits' => 90)), array(Row::COLUMNS => array('label' => 'val4', 'nb_visits' => 99)), array(Row::COLUMNS => array('label' => 'val5', 'nb_visits' => 0)), array(Row::COLUMNS => array('label' => 'val6', 'nb_visits' => 0)), array(Row::COLUMNS => array('label' => 'val7', 'nb_visits' => 134)), array(Row::COLUMNS => array('label' => 'val8', 'nb_visits' => 100)), array(Row::COLUMNS => array('label' => 'val9', 'nb_visits' => 7)), array(Row::COLUMNS => array('label' => 'val10', 'nb_visits' => 89))));
     $this->pastTable = new DataTable();
     $this->pastTable->addRowsFromArray(array(array(Row::COLUMNS => array('label' => 'val1', 'nb_visits' => 102)), array(Row::COLUMNS => array('label' => 'val102', 'nb_visits' => 29)), array(Row::COLUMNS => array('label' => 'val4', 'nb_visits' => 120)), array(Row::COLUMNS => array('label' => 'val6', 'nb_visits' => 313)), array(Row::COLUMNS => array('label' => 'val109', 'nb_visits' => 0)), array(Row::COLUMNS => array('label' => 'val8', 'nb_visits' => 140)), array(Row::COLUMNS => array('label' => 'val9', 'nb_visits' => 72)), array(Row::COLUMNS => array('label' => 'val107', 'nb_visits' => 415)), array(Row::COLUMNS => array('label' => 'val10', 'nb_visits' => 0))));
     $this->table = new DataTable();
 }

作者:FluentDevelopmen    项目:piwi   
/**
  * See {@link ColumnCallbackDeleteMetadata}.
  *
  * @param DataTable $table
  */
 public function filter($table)
 {
     $this->enableRecursive(true);
     foreach ($table->getRows() as $row) {
         $row->deleteMetadata($this->metadataToRemove);
         $this->filterSubTable($row);
     }
 }

作者:FluentDevelopmen    项目:piwi   
/**
  * @param DataTable $table
  */
 public function filter($table)
 {
     // make url labels clickable
     $table->filter('ColumnCallbackAddMetadata', array('label', 'url'));
     // prettify the DataTable
     $table->filter('ColumnCallbackReplace', array('label', 'Piwik\\Plugins\\Referrers\\removeUrlProtocol'));
     $table->queueFilter('ReplaceColumnNames');
 }

作者:TensorWrenchOS    项目:piwi   
public function test_renderDataTable_shouldSerializeIfEnabled()
 {
     $dataTable = new DataTable();
     $dataTable->addRowFromSimpleArray(array('nb_visits' => 5, 'nb_random' => 10));
     $builder = $this->makeBuilder(array('serialize' => 1));
     $response = $builder->renderDataTable($dataTable);
     $this->assertSame('O:15:"Piwik\\DataTable":2:{s:7:"*rows";a:1:{i:0;O:19:"Piwik\\DataTable\\Row":1:{s:1:"c";a:3:{i:0;a:2:{s:9:"nb_visits";i:5;s:9:"nb_random";i:10;}i:1;a:0:{}i:3;N;}}}s:13:"*summaryRow";N;}', $response);
 }


问题


面经


文章

微信
公众号

扫码关注公众号