PMCORE-3933 BE: Save the columns in the order defined in the drag and drop

This commit is contained in:
Roly Gutierrez
2022-08-19 12:03:14 -04:00
committed by Fabio Guachalla
parent 343c78cacd
commit 4161dbbf0e

View File

@@ -523,7 +523,7 @@ class CaseList extends Model
//merge with stored information
$result = [];
foreach ($default as &$column) {
foreach ($storedColumns as $storedColumn) {
foreach ($storedColumns as $keyStoredColumn => $storedColumn) {
if (!is_object($storedColumn)) {
continue;
}
@@ -538,12 +538,25 @@ class CaseList extends Model
if (isset($storedColumn['set'])) {
$column['set'] = $storedColumn['set'];
}
//for column ordering, this will be removed later
$column['sortIndex'] = $keyStoredColumn;
break;
}
}
$result[] = $column;
}
//sort columns by 'sortIndex', then 'sortIndex' will be removed.
$n = count($result);
usort($result, function ($a, $b) use ($n) {
$a1 = isset($a['sortIndex']) ? $a['sortIndex'] : $n;
$b1 = isset($b['sortIndex']) ? $b['sortIndex'] : $n;
return $a1 - $b1;
});
foreach ($result as &$value) {
unset($value['sortIndex']);
}
return $result;
}