private function processSort(array $table, Config $config)
{
if ($config['sort']) {
$cols = array_reverse($config['sort']);
foreach ($cols as $colName => $direction) {
Sort::mergeSort($table, function ($elementA, $elementB) use($colName, $direction) {
if ($elementA[$colName] == $elementB[$colName]) {
return 0;
}
if ($direction === 'asc') {
return $elementA[$colName] < $elementB[$colName] ? -1 : 1;
}
return $elementA[$colName] > $elementB[$colName] ? -1 : 1;
});
}
}
if ($config['break']) {
foreach ($config['break'] as $colName) {
Sort::mergeSort($table, function ($elementA, $elementB) use($colName) {
if ($elementA[$colName] == $elementB[$colName]) {
return 0;
}
return $elementA[$colName] < $elementB[$colName] ? -1 : 1;
});
}
}
return $table;
}