### The Basics DataTables consist of rows and each row consists of columns. A column value can be a numeric, a string or an array. Every row has an ID. The ID is either the index of the row or {@link ID_SUMMARY_ROW}. DataTables are hierarchical data structures. Each row can also contain an additional nested sub-DataTable (commonly referred to as a 'subtable'). Both DataTables and DataTable rows can hold **metadata**. _DataTable metadata_ is information regarding all the data, such as the site or period that the data is for. _Row metadata_ is information regarding that row, such as a browser logo or website URL. Finally, all DataTables contain a special _summary_ row. This row, if it exists, is always at the end of the DataTable. ### Populating DataTables Data can be added to DataTables in three different ways. You can either: 1. create rows one by one and add them through {@link addRow()} then truncate if desired, 2. create an array of DataTable\Row instances or an array of arrays and add them using {@link addRowsFromArray()} or {@link addRowsFromSimpleArray()} then truncate if desired, 3. or set the maximum number of allowed rows (with {@link setMaximumAllowedRows()}) and add rows one by one. If you want to eventually truncate your data (standard practice for all Piwik plugins), the third method is the most memory efficient. It is, unfortunately, not always possible to use since it requires that the data be sorted before adding. ### Manipulating DataTables There are two ways to manipulate a DataTable. You can either: 1. manually iterate through each row and manipulate the data, 2. or you can use predefined filters. A filter is a class that has a 'filter' method which will manipulate a DataTable in some way. There are several predefined Filters that allow you to do common things, such as, - add a new column to each row, - add new metadata to each row, - modify an existing column value for each row, - sort an entire DataTable, - and more. Using these filters instead of writing your own code will increase code clarity and reduce code redundancy. Additionally, filters have the advantage that they can be applied to DataTable\Map instances. So you can visit every DataTable in a {@link DataTable\Map} without having to write a recursive visiting function. All predefined filters exist in the **Piwik\DataTable\BaseFilter** namespace. _Note: For convenience, anonymous functions can be used as DataTable filters._ ### Applying Filters Filters can be applied now (via {@link filter()}), or they can be applied later (via {@link queueFilter()}). Filters that sort rows or manipulate the number of rows should be applied right away. Non-essential, presentation filters should be queued. ### Learn more - See **{@link ArchiveProcessor}** to learn how DataTables are persisted. ### Examples **Populating a DataTable** adding one row at a time $dataTable = new DataTable(); $dataTable->addRow(new Row(array( Row::COLUMNS => array('label' => 'thing1', 'nb_visits' => 1, 'nb_actions' => 1), Row::METADATA => array('url' => 'http://thing1.com') ))); $dataTable->addRow(new Row(array( Row::COLUMNS => array('label' => 'thing2', 'nb_visits' => 2, 'nb_actions' => 2), Row::METADATA => array('url' => 'http://thing2.com') ))); using an array of rows $dataTable = new DataTable(); $dataTable->addRowsFromArray(array( array( Row::COLUMNS => array('label' => 'thing1', 'nb_visits' => 1, 'nb_actions' => 1), Row::METADATA => array('url' => 'http://thing1.com') ), array( Row::COLUMNS => array('label' => 'thing2', 'nb_visits' => 2, 'nb_actions' => 2), Row::METADATA => array('url' => 'http://thing2.com') ) )); using a "simple" array $dataTable->addRowsFromSimpleArray(array( array('label' => 'thing1', 'nb_visits' => 1, 'nb_actions' => 1), array('label' => 'thing2', 'nb_visits' => 2, 'nb_actions' => 2) )); **Getting & setting metadata** $dataTable = \Piwik\Plugins\Referrers\API::getInstance()->getSearchEngines($idSite = 1, $period = 'day', $date = '2007-07-24'); $oldPeriod = $dataTable->metadata['period']; $dataTable->metadata['period'] = Period\Factory::build('week', Date::factory('2013-10-18')); **Serializing & unserializing** $maxRowsInTable = Config::getInstance()->General['datatable_archiving_maximum_rows_standard'];j $dataTable = // ... build by aggregating visits ... $serializedData = $dataTable->getSerialized($maxRowsInTable, $maxRowsInSubtable = $maxRowsInTable, $columnToSortBy = Metrics::INDEX_NB_VISITS); $serializedDataTable = $serializedData[0]; $serailizedSubTable = $serializedData[$idSubtable]; **Filtering for an API method** public function getMyReport($idSite, $period, $date, $segment = false, $expanded = false) { $dataTable = Archive::getDataTableFromArchive('MyPlugin_MyReport', $idSite, $period, $date, $segment, $expanded); $dataTable->filter('Sort', array(Metrics::INDEX_NB_VISITS, 'desc', $naturalSort = false, $expanded)); $dataTable->queueFilter('ReplaceColumnNames'); $dataTable->queueFilter('ColumnCallbackAddMetadata', array('label', 'url', __NAMESPACE__ . '\getUrlFromLabelForMyReport')); return $dataTable; }
Наследование: implements Piwik\DataTable\DataTableInterface, implements IteratorAggregate, implements ArrayAccess
Пример #1
0
 /**
  * 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();
 }
 /**
  * @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')));
     }
 }
Пример #3
0
 /**
  * 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);
     }
 }
 /**
  * @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;
     }));
 }
Пример #5
0
 /**
  * @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);
 }
Пример #6
0
 /**
  * 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);
 }
Пример #7
0
 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);
 }
Пример #8
0
 /**
  * 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);
 }
 /**
  * @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);
 }
Пример #10
0
 /**
  * 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);
         }
     }
 }
 /**
  * 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();
     }
 }
Пример #12
0
 /**
  * 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);
 }
Пример #13
0
 /**
  * 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);
 }
 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);
 }
Пример #15
0
 /**
  * @param DataTable $table
  */
 protected function filterTable($table)
 {
     foreach ($table->getRows() as $row) {
         $newColumns = $this->getRenamedColumns($row->getColumns());
         $row->setColumns($newColumns);
         $this->filterSubTable($row);
     }
 }
Пример #16
0
 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'));
 }
Пример #17
0
 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();
 }
 /**
  * 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);
     }
 }
 public function test_filter_shouldUrlEncodeValues()
 {
     $mapping = array(1 => 'Core tests', 3 => 'plugins tästs');
     $this->table->filter($this->filter, array('segmentName', $mapping));
     $metadata = $this->table->getRowsMetadata('segment');
     $expected = array('segmentName==Core+tests', false, 'segmentName==plugins+t%C3%A4sts', false, false, false);
     $this->assertSame($expected, $metadata);
 }
Пример #20
0
 /**
  * @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');
 }
Пример #21
0
 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);
 }
Пример #22
0
 /**
  * See {@link ExcludeLowPopulation}.
  *
  * @param DataTable $table
  */
 public function filter($table)
 {
     $minimumValue = $this->minimumValue;
     $isValueLowPopulation = function ($value) use($minimumValue) {
         return $value < $minimumValue;
     };
     $table->filter('ColumnCallbackDeleteRow', array($this->columnToFilter, $isValueLowPopulation));
 }
Пример #23
0
 /**
  * Template method called from self::manipulate.
  * Flatten each data table.
  *
  * @param DataTable $dataTable
  * @return DataTable
  */
 protected function manipulateDataTable($dataTable)
 {
     $newDataTable = $dataTable->getEmptyClone($keepFilters = true);
     // this recursive filter will be applied to subtables
     $dataTable->filter('ReplaceSummaryRowLabel');
     $this->flattenDataTableInto($dataTable, $newDataTable);
     return $newDataTable;
 }
 public function test_filter()
 {
     $dataTable = new DataTable();
     $dataTable->addRowsFromArray(array(array(Row::COLUMNS => array('label' => 'val1', 'nb_visits' => 120)), array(Row::COLUMNS => array('nb_visits' => 90)), array(Row::COLUMNS => array('label' => 'val2 5w ö?', 'nb_visits' => 99)), array(Row::COLUMNS => array('label' => Archiver::LABEL_CUSTOM_VALUE_NOT_DEFINED, 'nb_visits' => 99))));
     $dataTable->filter($this->filter, array($idDimension = 5));
     $metadata = $dataTable->getRowsMetadata('segment');
     $expected = array('dimension5==val1', false, 'dimension5==val2+5w+%C3%B6%3F', 'dimension5==');
     $this->assertSame($expected, $metadata);
 }
Пример #25
0
 /**
  * @group Core
  */
 public function testRangeCheckNormalDataTableNonIntegerValues()
 {
     $table = new DataTable();
     $table->addRowsFromArray(array(array(Row::COLUMNS => array('label' => 'ask', 'count' => '3')), array(Row::COLUMNS => array('label' => 'nintendo', 'count' => 'test')), array(Row::COLUMNS => array('label' => 'test', 'count' => 0x1232)), array(Row::COLUMNS => array('label' => 'piwik', 'count' => 0x5)), array(Row::COLUMNS => array('label' => 'google', 'count' => '9test')), array(Row::COLUMNS => array('label' => 'yahoo', 'count' => 'test4'))));
     $filter = new RangeCheck($table, 'count', 3.97, 10);
     $filter->filter($table);
     $expectedOrder = array(3.97, 3.97, 10, 5, '9test', 3.97);
     $this->assertEquals($expectedOrder, $table->getColumn('count'));
 }
 public function test_filter_shouldOnlyPrependIfAMetadataNameIsSet()
 {
     $this->table->filter($this->filter, array('other', 'prependme'));
     $metadata = $this->table->getRowsMetadata('other');
     $this->assertSame(array(false, 'prependmevalue', false, 'prependmevalue', 'prependme'), $metadata);
     // should still be the same
     $metadata = $this->table->getRowsMetadata('test');
     $this->assertSame(array('1', '2', '3', '1', '4'), $metadata);
 }
 public function test_filter_shouldRemoveAllMetadataEntriesHavingTheGivenName()
 {
     $prepend = 'city=test;';
     $this->table->filter($this->filter, array($prepend));
     $metadata = $this->table->getRowsMetadata('segment');
     $this->assertSame(array(false, $prepend . 'country=NZ', false, $prepend . 'country=AU', $prepend), $metadata);
     // should be still the same
     $metadata = $this->table->getRowsMetadata('test');
     $this->assertSame(array('1', '2', '3', '1', '4'), $metadata);
 }
Пример #28
0
 /**
  *  test with a row without child
  *
  * @group Core
  */
 public function testConsoleSimple()
 {
     $table = new DataTable();
     $table->addRowFromArray(array(Row::COLUMNS => array('visits' => 245, 'visitors' => 245), Row::METADATA => array('logo' => 'test.png')));
     $expected = "- 1 ['visits' => 245, 'visitors' => 245] ['logo' => 'test.png'] [idsubtable = ]<br />\n";
     $render = new Console();
     $render->setTable($table);
     $rendered = $render->render();
     $this->assertEquals($expected, $rendered);
 }
Пример #29
0
 public function getMetricTotalValue(DataTable $currentReport, $metric)
 {
     $totals = $currentReport->getMetadata('totals');
     if (!empty($totals[$metric])) {
         $totalValue = (int) $totals[$metric];
     } else {
         $totalValue = 0;
     }
     return $totalValue;
 }
Пример #30
0
 /**
  * Returns a data table for testing
  * @return DataTable
  */
 protected function getTable()
 {
     $subtableAskPath1 = new DataTable();
     $subtableAskPath1->addRowsFromArray(array(array(Row::COLUMNS => array('label' => 'path1-index-page.html')), array(Row::COLUMNS => array('label' => 'another-page'))));
     $subtableAsk = new DataTable();
     $subtableAsk->addRowsFromArray(array(array(Row::COLUMNS => array('label' => 'path1'), Row::DATATABLE_ASSOCIATED => $subtableAskPath1), array(Row::COLUMNS => array('label' => 'index.html'))));
     $table = new DataTable();
     $rows = array(array(Row::COLUMNS => array('label' => 'http://www.ask.com'), Row::DATATABLE_ASSOCIATED => $subtableAsk), array(Row::COLUMNS => array('label' => 'yahoo')));
     $table->addRowsFromArray($rows);
     return $table;
 }