/** * Sets the column to be used for Excluding low population * * @param DataTable\Row $row * @return int */ private function selectColumnToExclude($columnToFilter, $row) { if ($row->hasColumn($columnToFilter)) { return $columnToFilter; } // filter_excludelowpop=nb_visits but the column name is still Metrics::INDEX_NB_VISITS in the table $columnIdToName = Metrics::getMappingFromNameToId(); if (isset($columnIdToName[$columnToFilter])) { $column = $columnIdToName[$columnToFilter]; if ($row->hasColumn($column)) { return $column; } } return $columnToFilter; }
/** * Sets the column to be used for sorting * * @param Row $row * @return int */ protected function selectColumnToSort($row) { $value = $row->hasColumn($this->columnToSort); if ($value) { return $this->columnToSort; } $columnIdToName = Metrics::getMappingFromNameToId(); // sorting by "nb_visits" but the index is Metrics::INDEX_NB_VISITS in the table if (isset($columnIdToName[$this->columnToSort])) { $column = $columnIdToName[$this->columnToSort]; $value = $row->hasColumn($column); if ($value) { return $column; } } // eg. was previously sorted by revenue_per_visit, but this table // doesn't have this column; defaults with nb_visits $column = Metrics::INDEX_NB_VISITS; $value = $row->hasColumn($column); if ($value) { return $column; } // even though this column is not set properly in the table, // we select it for the sort, so that the table's internal state is set properly return $this->columnToSort; }
/** * Detect the secondary sort column to be used for sorting * * @param Row $row * @param int|string $primaryColumnToSort * @return int */ public function getSecondaryColumnToSort(Row $row, $primaryColumnToSort) { $defaultSecondaryColumn = array(Metrics::INDEX_NB_VISITS, 'nb_visits'); if (in_array($primaryColumnToSort, $defaultSecondaryColumn)) { // if sorted by visits, then sort by label as a secondary column $column = 'label'; $value = $row->hasColumn($column); if ($value !== false) { return $column; } return null; } if ($primaryColumnToSort !== 'label') { // we do not add this by default to make sure we do not sort by label as a first and secondary column $defaultSecondaryColumn[] = 'label'; } foreach ($defaultSecondaryColumn as $column) { $value = $row->hasColumn($column); if ($value !== false) { return $column; } } }
public function test_hasColumn_shouldReturnTrueEvenIfColumnValueIsNull() { $this->assertFalse($this->row->hasColumn('test')); $this->row->setColumn('test', null); $this->assertTrue($this->row->hasColumn('test')); }