Returns the array containing all the columns.
public getColumns ( ) : array | ||
return | array | Example: array( 'column1' => VALUE, 'label' => 'www.php.net' 'nb_visits' => 15894, ) |
public function test_getColumns_shouldNotConvertNullValuesToFalse() { $this->row->setColumns(array('nb_visits' => null, 'label' => 'Test', 'closure' => function () { return null; }, 'boolean' => false)); $expected = array('nb_visits' => null, 'label' => 'Test', 'closure' => null, 'boolean' => false); $this->assertSame($expected, $this->row->getColumns()); }
public function test_getColumns_setColumns_shouldReturnAllColumns() { $this->row->setColumns(array('nb_visits' => 4, 'label' => 'Test', 'goals' => array(1 => array()))); $expected = array('nb_visits' => 4, 'label' => 'Test', 'goals' => array(1 => array())); $this->assertEquals($expected, $this->row->getColumns()); $this->assertEquals('Test', $this->row->getColumn('label')); $this->assertEquals(4, $this->row->getColumn('nb_visits')); }
private function addRow(DataTable $table, DataTable\Row $row, $growthPercentage, $newValue, $oldValue, $difference, $disappeared = false, $isNew = false, $isMover = false) { $columns = $row->getColumns(); $columns['growth_percent'] = $growthPercentage; $columns['growth_percent_numeric'] = str_replace('%', '', $growthPercentage); $columns['grown'] = '-' != substr($growthPercentage, 0, 1); $columns['value_old'] = $oldValue; $columns['value_new'] = $newValue; $columns['difference'] = $difference; $columns['importance'] = abs($difference); $columns['isDisappeared'] = $disappeared; $columns['isNew'] = $isNew; $columns['isMover'] = $isMover; $table->addRowFromArray(array(DataTable\Row::COLUMNS => $columns)); }
/** * Adds a row to this table. * * If {@link setMaximumAllowedRows()} was called and the current row count is * at the maximum, the new row will be summed to the summary row. If there is no summary row, * this row is set as the summary row. * * @param Row $row * @return Row `$row` or the summary row if we're at the maximum number of rows. */ public function addRow(Row $row) { // if there is a upper limit on the number of allowed rows and the table is full, // add the new row to the summary row if ($this->maximumAllowedRows > 0 && $this->getRowsCount() >= $this->maximumAllowedRows - 1) { if ($this->summaryRow === null) { // create the summary row if necessary $columns = array('label' => self::LABEL_SUMMARY_ROW) + $row->getColumns(); $this->addSummaryRow(new Row(array(Row::COLUMNS => $columns))); } else { $this->summaryRow->sumRow($row, $enableCopyMetadata = false, $this->getMetadata(self::COLUMN_AGGREGATION_OPS_METADATA_NAME)); } return $this->summaryRow; } $this->rows[] = $row; if (!$this->indexNotUpToDate && $this->rebuildIndexContinuously) { $label = $row->getColumn('label'); if ($label !== false) { $this->rowsIndexByLabel[$label] = count($this->rows) - 1; } } return $row; }
/** * Simple test of the DataTable_Row */ public function testRow() { $columns = array('test_column' => 145, 92582495 => new Timer(), 'super' => array('this column has an array value, amazing')); $metadata = array('logo' => 'piwik.png', 'super' => array('this column has an array value, amazing')); $arrayRow = array(Row::COLUMNS => $columns, Row::METADATA => $metadata, 'fake useless key' => 38959, 43905724897 => 'value'); $row = new Row($arrayRow); $this->assertEquals($columns, $row->getColumns()); $this->assertEquals($metadata, $row->getMetadata()); $this->assertNull($row->getIdSubDataTable()); }
/** * Helper function that tests if two rows are equal. * * Two rows are equal if: * * - they have exactly the same columns / metadata * - they have a subDataTable associated, then we check that both of them are the same. * * Column order is not important. * * @param \Piwik\DataTable\Row $row1 first to compare * @param \Piwik\DataTable\Row $row2 second to compare * @return bool */ public static function isEqual(Row $row1, Row $row2) { //same columns $cols1 = $row1->getColumns(); $cols2 = $row2->getColumns(); $diff1 = array_udiff($cols1, $cols2, array(__CLASS__, 'compareElements')); $diff2 = array_udiff($cols2, $cols1, array(__CLASS__, 'compareElements')); if ($diff1 != $diff2) { return false; } $dets1 = $row1->getMetadata(); $dets2 = $row2->getMetadata(); ksort($dets1); ksort($dets2); if ($dets1 != $dets2) { return false; } // either both are null // or both have a value if (!(is_null($row1->getIdSubDataTable()) && is_null($row2->getIdSubDataTable()))) { $subtable1 = $row1->getSubtable(); $subtable2 = $row2->getSubtable(); if (!DataTable::isEqual($subtable1, $subtable2)) { return false; } } return true; }
private function assertRowEquals($expectedColumns, $expectedSiteIdInMetadata, Row $row) { $this->assertEquals($expectedColumns, $row->getColumns()); $this->assertEquals(array('idsite' => $expectedSiteIdInMetadata), $row->getMetadata()); }