$value ) { if ( ! empty( $value['url'] ) ) { $oldEmpty = false; $old[] = array( 'website_type_id' => $value['website_type_id'], 'url' => $value['url'] ); } } foreach ( $newWebsiteValues as $idx => $value ) { if ( ! empty( $value['url'] ) ) { $newEmpty = false; $new[] = array( 'website_type_id' => $value['website_type_id'], 'url' => $value['url'] ); } } // if both old and new are empty, we can delete new and avoid a write if ( $oldEmpty && $newEmpty ) { unset( $newValues['website'] ); } // if different number of non-empty entries, return if ( count( $new ) != count( $old ) ) { return; } // same number of entries, check if they are exactly the same foreach ( $old as $oldID => $oldValues ) { $found = false; foreach ( $new as $newID => $newValues ) { if ( $old['website_type_id'] == $new['website_type_id'] && $old['url'] == $new['url'] ) { $found = true; unset( $new[$newID] ); break; } if ( ! $found ) { return; } } } // if we've come here, this means old and new are the same // we can skip saving new and return unset( $newValues['website'] ); } static function email( &$newValues, &$oldValues ) { $oldEmailValues = CRM_Utils_Array::value( 'email', $oldValues ); $newEmailValues = CRM_Utils_Array::value( 'email', $newValues ); if ( $oldEmailValues == null || $newEmailValues == null ) { return; } // check if we had a value in the old $oldEmpty = $newEmpty = true; $old = $new = array( ); foreach ( $oldEmailValues as $idx => $value ) { if ( ! empty( $value['email'] ) ) { $oldEmpty = false; $old[] = array( 'email' => $value['email'], 'location_type_id' => $value['location_type_id'], 'on_hold' => $value['on_hold'] ? 1 : 0, 'is_primary' => $value['is_primary'] ? 1 : 0, 'is_bulkmail' => $value['is_bulkmail'] ? 1 : 0, 'signature_text' => $value['signature_text'] ? $value['signature_text'] : '', 'signature_html' => $value['signature_html'] ? $value['signature_html'] : '', ); } } foreach ( $newEmailValues as $idx => $value ) { if ( ! empty( $value['email'] ) ) { $newEmpty = false; $new[] = array( 'email' => $value['email'], 'location_type_id' => $value['location_type_id'], 'on_hold' => $value['on_hold'] ? 1 : 0, 'is_primary' => $value['is_primary'] ? 1 : 0, 'is_bulkmail' => $value['is_bulkmail'] ? 1 : 0, 'signature_text' => $value['signature_text'] ? $value['signature_text'] : '', 'signature_html' => $value['signature_html'] ? $value['signature_html'] : '', ); } } // if both old and new are empty, we can delete new and avoid a write if ( $oldEmpty && $newEmpty ) { unset( $newValues['email'] ); } // if different number of non-empty entries, return if ( count( $new ) != count( $old ) ) { return; } // same number of entries, check if they are exactly the same foreach ( $old as $oldID => $oldValues ) { $found = false; foreach ( $new as $newID => $newValues ) { if ( $old['email_type_id'] == $new['email_type_id'] && $old['url'] == $new['url'] ) { $found = true; unset( $new[$newID] ); break; } if ( ! $found ) { return; } } } // if we've come here, this means old and new are the same // we can skip saving new and return unset( $newValues['email'] ); } }