35 lines
894 B
PHP
35 lines
894 B
PHP
<?php
|
|
|
|
/**
|
|
* Helper function to detect changed fields
|
|
*
|
|
* Compares current data with previous data to identify which fields changed
|
|
*
|
|
* @param mixed $data Current data
|
|
* @param mixed $beforeData Previous data (null for new records)
|
|
* @return array Array of changed field names
|
|
*/
|
|
function detectChangedFields($data, $beforeData): array
|
|
{
|
|
if (is_null($beforeData)) {
|
|
// New record - all fields are "changed"
|
|
return array_keys((array) $data);
|
|
}
|
|
|
|
$changedFields = [];
|
|
$dataArray = (array) $data;
|
|
$beforeDataArray = (array) $beforeData;
|
|
|
|
foreach ($dataArray as $key => $value) {
|
|
$oldValue = $beforeDataArray[$key] ?? null;
|
|
|
|
// Compare values - consider both strict and loose equality for type changes
|
|
if ($oldValue !== $value) {
|
|
$changedFields[] = $key;
|
|
}
|
|
}
|
|
|
|
return $changedFields;
|
|
}
|
|
|
|
?>
|