Piwik\DataTable::isEqual PHP Method

isEqual() public static method

DataTables are equal if they have the same number of rows, if each row has a label that exists in the other table, and if each row is equal to the row in the other table with the same label. The order of rows is not important.
public static isEqual ( DataTable $table1, DataTable $table2 ) : boolean
$table1 DataTable
$table2 DataTable
return boolean
    public static function isEqual(DataTable $table1, DataTable $table2)
    {
        $table1->rebuildIndex();
        $table2->rebuildIndex();
        if ($table1->getRowsCount() != $table2->getRowsCount()) {
            return false;
        }
        $rows1 = $table1->getRows();
        foreach ($rows1 as $row1) {
            $row2 = $table2->getRowFromLabel($row1->getColumn('label'));
            if ($row2 === false || !Row::isEqual($row1, $row2)) {
                return false;
            }
        }
        return true;
    }

Usage Example

 /**
  * Test to exclude low population filter
  *
  * @group Core
  */
 public function testFilterLowpop1()
 {
     $idcol = Row::COLUMNS;
     $table = new DataTable();
     $rows = array(array($idcol => array('label' => 'google', 'nb_visits' => 897)), array($idcol => array('label' => 'ask', 'nb_visits' => -152)), array($idcol => array('label' => 'piwik', 'nb_visits' => 1.5)), array($idcol => array('label' => 'piwik2', 'nb_visits' => 1.4)), array($idcol => array('label' => 'yahoo', 'nb_visits' => 154)), array($idcol => array('label' => 'amazon', 'nb_visits' => 30)), array($idcol => array('label' => '238949', 'nb_visits' => 0)), array($idcol => array('label' => 'Q*(%&*', 'nb_visits' => 1)), array($idcol => array('label' => 'Q*(%&*2', 'nb_visits' => -1.5)));
     $table->addRowsFromArray($rows);
     $expectedtable = new DataTable();
     $rows = array(array($idcol => array('label' => 'google', 'nb_visits' => 897)), array($idcol => array('label' => 'piwik', 'nb_visits' => 1.5)), array($idcol => array('label' => 'piwik2', 'nb_visits' => 1.4)), array($idcol => array('label' => 'yahoo', 'nb_visits' => 154)), array($idcol => array('label' => 'amazon', 'nb_visits' => 30)));
     $expectedtable->addRowsFromArray($rows);
     $filter = new ExcludeLowPopulation($table, 'nb_visits', 1.4);
     $filter->filter($table);
     $this->assertTrue(DataTable::isEqual($table, $expectedtable));
 }
All Usage Examples Of Piwik\DataTable::isEqual