static function mergeField($fieldName, $existingValue, $newValue) { if ($newValue === null) { return $existingValue; } elseif ($existingValue === null) { return $newValue; } elseif ($existingValue === $newValue) { return $existingValue; } $appendWithNewlineFields = array('summary', 'notes'); $appendWithSpaceFields = array('name_suffix', 'name_prefix'); $dateFields = array('start_date', 'end_date'); $nameFields = array('name_first', 'name_middle'); $numberFields = array('employees', 'revenue', 'endowment'); if (in_array($fieldName, $appendWithNewlineFields)) { return $existingValue . "\n\n" . $newValue; } elseif (in_array($fieldName, $appendWithSpaceFields)) { return $existingValue . ' ' . $newValue; } elseif (in_array($fieldName, $dateFields)) { $existingDate = new LsDate($existingValue); $newDate = new LsDate($newValue); if ($existingDate->howSpecific() > $newDate->howSpecific()) { return $existingDate->format(); } elseif ($existingDate->howSpecific() < $newDate->howSpecific()) { return $newDate->format(); } else { if ($existingDate->howSpecific() == LsDate::YEAR_SPECIFIC) { return LsDate::lessOrEqual($existingDate, $newDate) ? $existingDate : $newDate; } else { return $existingDate; } } } elseif (in_array($fieldName, $nameFields)) { return strlen($existingValue) >= strlen($newValue) || strlen($existingValue) !== 1 ? $existingValue : $newValue; } elseif (in_array($fieldName, $numberFields)) { return $existingValue == 0 ? $newValue : $existingValue; } else { return $existingValue; } }