PMCORE-3933 BE: Save the columns in the order defined in the drag and drop
This commit is contained in:
committed by
Fabio Guachalla
parent
343c78cacd
commit
4161dbbf0e
@@ -523,7 +523,7 @@ class CaseList extends Model
|
|||||||
//merge with stored information
|
//merge with stored information
|
||||||
$result = [];
|
$result = [];
|
||||||
foreach ($default as &$column) {
|
foreach ($default as &$column) {
|
||||||
foreach ($storedColumns as $storedColumn) {
|
foreach ($storedColumns as $keyStoredColumn => $storedColumn) {
|
||||||
if (!is_object($storedColumn)) {
|
if (!is_object($storedColumn)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -538,12 +538,25 @@ class CaseList extends Model
|
|||||||
if (isset($storedColumn['set'])) {
|
if (isset($storedColumn['set'])) {
|
||||||
$column['set'] = $storedColumn['set'];
|
$column['set'] = $storedColumn['set'];
|
||||||
}
|
}
|
||||||
|
//for column ordering, this will be removed later
|
||||||
|
$column['sortIndex'] = $keyStoredColumn;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$result[] = $column;
|
$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;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user