İlk temizlik tamamlandı bir önceki projeden
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
<?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;
|
||||
}
|
||||
|
||||
?>
|
||||
Reference in New Issue
Block a user