Skip to content

Commit

Permalink
Merge pull request #15 from MightyMCoder/develop
Browse files Browse the repository at this point in the history
fix overwritten field order
  • Loading branch information
MightyMCoder authored Jan 3, 2025
2 parents de7d8ab + 12c628e commit 8b65d24
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 10 deletions.
42 changes: 34 additions & 8 deletions classes/configtable.php
Original file line number Diff line number Diff line change
Expand Up @@ -245,14 +245,23 @@ private function initializeDefaultFields()
$pimFields = array();
$customFields = array();

foreach ($existingFields as $fieldName => $fieldData) {
// Sort the array by imf_sequence to get the imf_name and imf_sequence for custom fields of the previous field
$existingFieldsOrdered = $existingFields;
usort($existingFieldsOrdered, function($a, $b) {
return $a['imf_sequence'] <=> $b['imf_sequence'];
});

foreach ($existingFields as $fieldName => $fieldData) {
if (strpos($fieldName, 'PIM_') === 0) {
$pimFields[$fieldName] = $fieldData;
}
else {
$customFields[$fieldName] = $fieldData;
$customFields[$fieldName]['previous_imf_name'] = $existingFieldsOrdered[$fieldData['imf_sequence'] - 1]['imf_name'];
$customFields[$fieldName]['previous_sequence'] = $existingFieldsOrdered[$fieldData['imf_sequence'] - 1]['imf_sequence'];
}
}

// Adjust pimFields to match the defaultData
foreach ($defaultData as $defaultField) {
$defaultFieldName = $defaultField['imf_name'];
Expand Down Expand Up @@ -283,16 +292,33 @@ private function initializeDefaultFields()
unset($pimFields[$fieldName]);
}
}

// Append customFields to pimFields
$allFields = array_merge($pimFields, $customFields);
$allFields = $pimFields;

// Update the imf_sequence based on the index in the array
$sequence = 0;
foreach ($allFields as &$field) {
$field['imf_sequence'] = $sequence++;
}
unset($field); // Break reference to the last element
// Adjust the sequence of pimFields based on customFields
foreach ($customFields as $customField) {
if (isset($customField['previous_imf_name']) && isset($allFields[$customField['previous_imf_name']])) {
$customSequence = $allFields[$customField['previous_imf_name']]['imf_sequence'] + 1;
$customField['imf_sequence'] = $customSequence;
}
else {
//old previous item doesnt exist anymore
$customSequence = $customField['previous_sequence'] - 1;
}

foreach ($allFields as &$pimField) {
if ($pimField['imf_sequence'] >= $customSequence) {
$pimField['imf_sequence']++;
}
}

unset($pimField); // Break reference to the last element

if (isset($customField['imf_name'])) {
$allFields[$customField['imf_name']] = $customField;
}
}
// Now $allFields contains the combined and updated fields

// Clear the table and reset the AUTO_INCREMENT
Expand Down
4 changes: 2 additions & 2 deletions version.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
*/

class CPluginInfoPIM {
protected const PLUGIN_VERSION = '1.0.4';
protected const PLUGIN_VERSION = '1.0.5';
protected const PLUGIN_VERSION_BETA = 'n/a';
protected const PLUGIN_STAND = '29.12.2024';
protected const PLUGIN_STAND = '03.01.2025';

/**
* Current version of plugin InventoryManager
Expand Down

0 comments on commit 8b65d24

Please sign in to comment.