From 4161dbbf0eb106da14b6b19d3af6ceed08c9dfaa Mon Sep 17 00:00:00 2001 From: Roly Gutierrez Date: Fri, 19 Aug 2022 12:03:14 -0400 Subject: [PATCH] PMCORE-3933 BE: Save the columns in the order defined in the drag and drop --- .../engine/src/ProcessMaker/Model/CaseList.php | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/workflow/engine/src/ProcessMaker/Model/CaseList.php b/workflow/engine/src/ProcessMaker/Model/CaseList.php index 818311e1c..e4b206bc7 100644 --- a/workflow/engine/src/ProcessMaker/Model/CaseList.php +++ b/workflow/engine/src/ProcessMaker/Model/CaseList.php @@ -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; }